1
0
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:
Sebastian Gerske 2018-10-25 17:18:57 +02:00
parent 28fe11e671
commit 7eae00014e
4 changed files with 47 additions and 7 deletions

8
package-lock.json generated
View File

@ -125,9 +125,9 @@
"integrity": "sha512-UVt9m9WmFm4mTDWmMekT8lhBh2hWr2baEVnF0dEN3OL5BDAWoynFQeeKtUqTepVuOVgNy5bHYKLiHkCWzbOEqA=="
},
"@oceanprotocol/secret-store-client": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.3.tgz",
"integrity": "sha512-B1rJ7zk24qP1HW+L3MkgietEWDy2aEuXUagFYfsGBt3iilixc8qTm8U+nphsuVDp1Lgf7BQpIpXED81S7HAwOA==",
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.4.tgz",
"integrity": "sha512-VHzcBkZ5ZKVdLKERshvT48jlWeZTX1x1tDgbqhc1x0nH8H6HC8SZ+Ak834S2t8XTswgTVWygxn8g51jtPy5+BQ==",
"requires": {
"jayson": "^2.0.6",
"node-fetch": "^2.2.0"
@ -1802,7 +1802,7 @@
},
"es6-promisify": {
"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=",
"requires": {
"es6-promise": "^4.0.3"

View File

@ -50,7 +50,7 @@
},
"dependencies": {
"@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",
"eth-crypto": "^1.2.4",
"eth-ecies": "^1.0.3",

View File

@ -1,8 +1,10 @@
import ConfigProvider from "../ConfigProvider"
import Keeper from "../keeper/Keeper"
import Web3Provider from "../keeper/Web3Provider"
import Config from "../models/Config"
import Provider from "../provider/Provider"
import ProviderProvider from "../provider/ProviderProvider"
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
import Logger from "../utils/Logger"
import Account from "./Account"
import Asset from "./Asset"
@ -10,10 +12,11 @@ import Order from "./Order"
export default class Ocean {
public static async getInstance(config) {
public static async getInstance(config: Config) {
if (!Ocean.instance) {
ConfigProvider.configure(config)
SecretStoreProvider.configure(config)
ProviderProvider.setProvider(Provider)
Ocean.instance = new Ocean(await Keeper.getInstance())
}
@ -39,8 +42,21 @@ export default class Ocean {
public async register(asset: Asset): Promise<string> {
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
const assetId = await market.generateId(asset.name + asset.description)
Logger.log(`Registering: ${assetId} with price ${asset.price} for ${asset.publisher.getId()}`)
asset.setId(assetId)
const isAssetActive = await market.isAssetActive(assetId)

View 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
}