mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added secret store
This commit is contained in:
parent
28fe11e671
commit
7eae00014e
8
package-lock.json
generated
8
package-lock.json
generated
@ -125,9 +125,9 @@
|
|||||||
"integrity": "sha512-UVt9m9WmFm4mTDWmMekT8lhBh2hWr2baEVnF0dEN3OL5BDAWoynFQeeKtUqTepVuOVgNy5bHYKLiHkCWzbOEqA=="
|
"integrity": "sha512-UVt9m9WmFm4mTDWmMekT8lhBh2hWr2baEVnF0dEN3OL5BDAWoynFQeeKtUqTepVuOVgNy5bHYKLiHkCWzbOEqA=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/secret-store-client": {
|
"@oceanprotocol/secret-store-client": {
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.4.tgz",
|
||||||
"integrity": "sha512-B1rJ7zk24qP1HW+L3MkgietEWDy2aEuXUagFYfsGBt3iilixc8qTm8U+nphsuVDp1Lgf7BQpIpXED81S7HAwOA==",
|
"integrity": "sha512-VHzcBkZ5ZKVdLKERshvT48jlWeZTX1x1tDgbqhc1x0nH8H6HC8SZ+Ak834S2t8XTswgTVWygxn8g51jtPy5+BQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"jayson": "^2.0.6",
|
"jayson": "^2.0.6",
|
||||||
"node-fetch": "^2.2.0"
|
"node-fetch": "^2.2.0"
|
||||||
@ -1802,7 +1802,7 @@
|
|||||||
},
|
},
|
||||||
"es6-promisify": {
|
"es6-promisify": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
|
"resolved": "http://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
|
||||||
"integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
|
"integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"es6-promise": "^4.0.3"
|
"es6-promise": "^4.0.3"
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/keeper-contracts": "^0.3.3",
|
"@oceanprotocol/keeper-contracts": "^0.3.3",
|
||||||
"@oceanprotocol/secret-store-client": "^0.0.3",
|
"@oceanprotocol/secret-store-client": "^0.0.4",
|
||||||
"bignumber.js": "^7.2.1",
|
"bignumber.js": "^7.2.1",
|
||||||
"eth-crypto": "^1.2.4",
|
"eth-crypto": "^1.2.4",
|
||||||
"eth-ecies": "^1.0.3",
|
"eth-ecies": "^1.0.3",
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import ConfigProvider from "../ConfigProvider"
|
import ConfigProvider from "../ConfigProvider"
|
||||||
import Keeper from "../keeper/Keeper"
|
import Keeper from "../keeper/Keeper"
|
||||||
import Web3Provider from "../keeper/Web3Provider"
|
import Web3Provider from "../keeper/Web3Provider"
|
||||||
|
import Config from "../models/Config"
|
||||||
import Provider from "../provider/Provider"
|
import Provider from "../provider/Provider"
|
||||||
import ProviderProvider from "../provider/ProviderProvider"
|
import ProviderProvider from "../provider/ProviderProvider"
|
||||||
|
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||||
import Logger from "../utils/Logger"
|
import Logger from "../utils/Logger"
|
||||||
import Account from "./Account"
|
import Account from "./Account"
|
||||||
import Asset from "./Asset"
|
import Asset from "./Asset"
|
||||||
@ -10,10 +12,11 @@ import Order from "./Order"
|
|||||||
|
|
||||||
export default class Ocean {
|
export default class Ocean {
|
||||||
|
|
||||||
public static async getInstance(config) {
|
public static async getInstance(config: Config) {
|
||||||
|
|
||||||
if (!Ocean.instance) {
|
if (!Ocean.instance) {
|
||||||
ConfigProvider.configure(config)
|
ConfigProvider.configure(config)
|
||||||
|
SecretStoreProvider.configure(config)
|
||||||
ProviderProvider.setProvider(Provider)
|
ProviderProvider.setProvider(Provider)
|
||||||
Ocean.instance = new Ocean(await Keeper.getInstance())
|
Ocean.instance = new Ocean(await Keeper.getInstance())
|
||||||
}
|
}
|
||||||
@ -39,8 +42,21 @@ export default class Ocean {
|
|||||||
public async register(asset: Asset): Promise<string> {
|
public async register(asset: Asset): Promise<string> {
|
||||||
const {market} = this.keeper
|
const {market} = this.keeper
|
||||||
|
|
||||||
|
const secretStore = SecretStoreProvider.getSecretStore()
|
||||||
|
|
||||||
|
const id = Math.random().toString(10)
|
||||||
|
Logger.log("id", id)
|
||||||
|
|
||||||
|
const assetId = (await market.generateId(id)).replace("0x", "")
|
||||||
|
|
||||||
|
Logger.log(assetId.length)
|
||||||
|
const encryptedDocument = await secretStore.encryptDocument(assetId, asset)
|
||||||
|
|
||||||
|
const decryptedDocument = await secretStore.decryptDocument(assetId, encryptedDocument)
|
||||||
|
|
||||||
|
Logger.log(decryptedDocument, encryptedDocument)
|
||||||
|
|
||||||
// generate an id
|
// generate an id
|
||||||
const assetId = await market.generateId(asset.name + asset.description)
|
|
||||||
Logger.log(`Registering: ${assetId} with price ${asset.price} for ${asset.publisher.getId()}`)
|
Logger.log(`Registering: ${assetId} with price ${asset.price} for ${asset.publisher.getId()}`)
|
||||||
asset.setId(assetId)
|
asset.setId(assetId)
|
||||||
const isAssetActive = await market.isAssetActive(assetId)
|
const isAssetActive = await market.isAssetActive(assetId)
|
||||||
|
24
src/secretstore/SecretStoreProvider.ts
Normal file
24
src/secretstore/SecretStoreProvider.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import SecretStore from "@oceanprotocol/secret-store-client"
|
||||||
|
|
||||||
|
export default class SecretStoreProvider {
|
||||||
|
|
||||||
|
public static getSecretStore() {
|
||||||
|
|
||||||
|
if (!SecretStoreProvider.secretStore) {
|
||||||
|
SecretStoreProvider.secretStore = new SecretStore(SecretStoreProvider.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
return SecretStoreProvider.secretStore
|
||||||
|
}
|
||||||
|
|
||||||
|
public static configure(config: {
|
||||||
|
secretStoreUri: string, parityUri: string,
|
||||||
|
address: string, password: string, threshold?: number,
|
||||||
|
}) {
|
||||||
|
|
||||||
|
SecretStoreProvider.config = config
|
||||||
|
}
|
||||||
|
|
||||||
|
private static config: any
|
||||||
|
private static secretStore: SecretStore
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user