From c63230764620a63f7c624770f8491bbdcbd6a91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 1 Apr 2019 12:40:45 +0200 Subject: [PATCH] Upgrade to Keeper 0.9.0 and Secret Store access way. --- integration/config.ts | 10 +++- integration/config/config.json | 12 ----- integration/ocean/ConsumeAsset.test.ts | 22 ++++---- integration/ocean/ConsumeAssetBrizo.test.ts | 16 ++---- integration/ocean/SecretStore.test.ts | 12 +---- integration/ocean/Signature.test.ts | 15 ++---- package-lock.json | 22 ++++---- package.json | 4 +- ...k-spree-accounts.sh => unlock-accounts.sh} | 0 src/aquarius/Aquarius.ts | 9 +++- src/aquarius/query/SearchQuery.ts | 7 --- src/brizo/Brizo.ts | 43 ++++++++++++++-- src/models/Config.ts | 9 ---- src/ocean/OceanAssets.ts | 20 ++------ src/ocean/OceanSecretStore.ts | 34 ++----------- src/secretstore/SecretStoreProvider.ts | 22 -------- test/keeper/DIDRegistry.test.ts | 51 ++++++------------- test/ocean/OceanSecretStore.test.ts | 24 ++------- 18 files changed, 119 insertions(+), 213 deletions(-) delete mode 100644 integration/config/config.json rename scripts/{unlock-spree-accounts.sh => unlock-accounts.sh} (100%) delete mode 100644 src/aquarius/query/SearchQuery.ts delete mode 100644 src/secretstore/SecretStoreProvider.ts diff --git a/integration/config.ts b/integration/config.ts index b6cd14b..cd2e3ef 100644 --- a/integration/config.ts +++ b/integration/config.ts @@ -1,6 +1,14 @@ import * as HDWalletProvider from "truffle-hdwallet-provider" import { Config } from "../src" -import * as configJson from "./config/config.json" + +const configJson: Config = { + "nodeUri": "http://localhost:8545", + "aquariusUri": "http://172.15.0.15:5000", + "brizoUri": "http://localhost:8030", //"https://brizo-ha.dev-ocean.com", + "brizoAddress": "0x00bd138abd70e2f00903268f3db08f2d25677c9e", // "0x413c9ba0a05b8a600899b41b0c62dd661e689354", + "secretStoreUri": "https://secret-store.dev-ocean.com/", + "verbose": false +} if (process.env.SEED_WORDS) { const seedphrase = process.env.SEED_WORDS diff --git a/integration/config/config.json b/integration/config/config.json deleted file mode 100644 index c5a349c..0000000 --- a/integration/config/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nodeUri": "http://localhost:8545", - "aquariusUri": "http://172.15.0.15:5000", - "brizoUri": "http://localhost:8030", - "brizoAddress": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", - "parityUri": "http://localhost:9545", - "secretStoreUri": "http://localhost:12001", - "threshold": 0, - "password": "secret", - "address": "0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", - "verbose": false -} diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index c8f61d2..7812fec 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -19,18 +19,11 @@ describe("Consume Asset", () => { let serviceAgreementSignatureResult: {agreementId: string, signature: string} before(async () => { - ocean = await Ocean.getInstance({ - ...config, - web3Provider: new Web3.providers - .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), - }) + ocean = await Ocean.getInstance(config) // Accounts - const instanceConfig = (ocean as any).instanceConfig - publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", instanceConfig) - publisher.setPassword("node0") - consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", instanceConfig) - consumer.setPassword("secret") + publisher = (await ocean.accounts.list())[0] + consumer = (await ocean.accounts.list())[1] }) it("should regiester a asset", async () => { @@ -90,6 +83,12 @@ describe("Consume Asset", () => { .grantAccess(serviceAgreementSignatureResult.agreementId, ddo.id, consumer.getId(), publisher) assert.isTrue(granted, "The asset has not been granted correctly") + + const accessGranted = await ocean.keeper.conditions + .accessSecretStoreCondition + .checkPermissions(consumer.getId(), ddo.id) + + assert.isTrue(accessGranted, "Consumer has been granted.") }) it("should consume and store the assets", async () => { @@ -112,6 +111,7 @@ describe("Consume Asset", () => { }) }) - assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.") + assert.deepEqual(files, ["file-0", "file-1"], "Stored files are not correct.") + // assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.") }) }) diff --git a/integration/ocean/ConsumeAssetBrizo.test.ts b/integration/ocean/ConsumeAssetBrizo.test.ts index a12fe71..daa3c3a 100644 --- a/integration/ocean/ConsumeAssetBrizo.test.ts +++ b/integration/ocean/ConsumeAssetBrizo.test.ts @@ -19,18 +19,11 @@ describe("Consume Asset (Brizo)", () => { const metadata = getMetadata() before(async () => { - ocean = await Ocean.getInstance({ - ...config, - web3Provider: new Web3.providers - .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), - }) + ocean = await Ocean.getInstance(config) // Accounts - const instanceConfig = (ocean as any).instanceConfig - publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", instanceConfig) - publisher.setPassword("node0") - consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", instanceConfig) - consumer.setPassword("secret") + publisher = (await ocean.accounts.list())[0] + consumer = (await ocean.accounts.list())[1] }) it("should regiester an asset", async () => { @@ -63,6 +56,7 @@ describe("Consume Asset (Brizo)", () => { }) }) - assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.") + assert.deepEqual(files, ["file-0", "file-1"], "Stored files are not correct.") + // assert.deepEqual(files, ["README.md", "package.json"], "Stored files are not correct.") }) }) diff --git a/integration/ocean/SecretStore.test.ts b/integration/ocean/SecretStore.test.ts index b00bb5c..5e5fb52 100644 --- a/integration/ocean/SecretStore.test.ts +++ b/integration/ocean/SecretStore.test.ts @@ -17,21 +17,13 @@ describe("Secret Store", () => { ocean = await Ocean.getInstance(config) // Accounts - account = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0") - account.setPassword("secret") + account = (await ocean.accounts.list())[0] }) it("should encrypt a text", async () => { encryptedContent = await ocean.secretStore.encrypt(did.getId(), content, account) assert.isDefined(encryptedContent) - assert.match(encryptedContent, /^0x[a-f0-9]{86}$/i) - }) - - // Only works running Barge with `--no-acl-contract` - xit("should decrypt a text", async () => { - const decryptedContent = await ocean.secretStore.decrypt(did.getId(), encryptedContent, account) - - assert.deepEqual(decryptedContent, content) + assert.match(encryptedContent, /^0x[a-f0-9]{76}$/i) }) }) diff --git a/integration/ocean/Signature.test.ts b/integration/ocean/Signature.test.ts index 0d70a48..389417e 100644 --- a/integration/ocean/Signature.test.ts +++ b/integration/ocean/Signature.test.ts @@ -1,5 +1,4 @@ import { assert } from "chai" -import * as Web3 from "web3" import { config } from "../config" @@ -13,15 +12,10 @@ describe("Signature", () => { let consumer: Account before(async () => { - ocean = await Ocean.getInstance({ - ...config, - web3Provider: new (Web3 as any).providers - .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), - }) + ocean = await Ocean.getInstance(config) // Accounts - consumer = new Account("0x00bd138abd70e2f00903268f3db08f2d25677c9e") - consumer.setPassword("node0") + consumer = (await ocean.accounts.list())[0] }) it("should generate the correct signature", async () => { @@ -75,9 +69,6 @@ describe("Signature", () => { ], }) - const agreementConditionIds = await templates.escrowAccessSecretStoreTemplate - .getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId()) - const signature = await ocean.utils.agreements.signServiceAgreement( ddo, serviceDefinitionId, @@ -89,7 +80,7 @@ describe("Signature", () => { assert.equal( signature, // tslint:disable-next-line - "0xc12b8773a330fd01c7fc057e31475e5fc849eba1896cffb102881a6a45aac5fd7342069e578bbe0e1c8c95aa33a53451ac03ae1433f96928cd614c986742578e1b", + "0x3aa8a1c48b8e582d694bbd4ba3a29fde573b78da9720dc48baeb831b2163e1fa6e10e983882ebf8a00f4124de2505136354fd146934053f0d58bba4eced5f8d000", "The signatuere is not correct.", ) }) diff --git a/package-lock.json b/package-lock.json index 082413a..a43b08e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -129,17 +129,9 @@ } }, "@oceanprotocol/keeper-contracts": { - "version": "0.8.7", - "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.8.7.tgz", - "integrity": "sha512-lrX7isgUYHspQ0/xUtQzugZyZYRncT/TWLom30RGBoHNgy9ZWXYupXULHQdCXq19Hjy7EMYV2sm4HVddB5hz3w==" - }, - "@oceanprotocol/secret-store-client": { - "version": "0.0.14", - "resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.14.tgz", - "integrity": "sha512-Yo2/9MJC1vlWXGIaU+35naYHWWYGbtzTu2t5dW4Ro1JuIRkzxfM3TSNzPUAgsCrUBUxsCsu9pd/RjvPuE45SGw==", - "requires": { - "node-fetch": "^2.3.0" - } + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.9.0.tgz", + "integrity": "sha512-QrTCQNiQa9KszH6/dTAS0a8AoW/SIEkZazXTwA2aoePBS0X8fNpsKvT3N2OuR1YPAjCU3rGWzYdV4TNnMNbsSw==" }, "@types/chai": { "version": "4.1.7", @@ -6415,6 +6407,14 @@ "safe-buffer": "^5.1.0" } }, + "secretstore": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/secretstore/-/secretstore-0.1.0.tgz", + "integrity": "sha512-Ue4Pg5cfQBJEUu8XEMfQ2NAFyz8w0/Dqb7MiwDSN0+4JhTRy1iO48nDLb9XvETPCdbq92gWhEK0RbXfop6VoPw==", + "requires": { + "web3": "^1.0.0-beta.37" + } + }, "seek-bzip": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.5.tgz", diff --git a/package.json b/package.json index 88c7754..9938a52 100644 --- a/package.json +++ b/package.json @@ -59,13 +59,13 @@ }, "homepage": "https://github.com/oceanprotocol/squid-js#readme", "dependencies": { - "@oceanprotocol/keeper-contracts": "^0.8.7", - "@oceanprotocol/secret-store-client": "~0.0.14", + "@oceanprotocol/keeper-contracts": "^0.9.0", "bignumber.js": "^8.0.1", "deprecated-decorator": "^0.1.6", "ethereumjs-util": "^6.0.0", "node-fetch": "^2.3.0", "save-file": "^2.3.1", + "secretstore": "^0.1.0", "uuid": "^3.3.2", "web3": "1.0.0-beta.37", "whatwg-url": "^7.0.0" diff --git a/scripts/unlock-spree-accounts.sh b/scripts/unlock-accounts.sh similarity index 100% rename from scripts/unlock-spree-accounts.sh rename to scripts/unlock-accounts.sh diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index 48d00ed..602e99c 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -2,11 +2,18 @@ import { URL } from "whatwg-url" import { DDO } from "../ddo/DDO" import DID from "../ocean/DID" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" -import { SearchQuery } from "./query/SearchQuery" import { Instantiable, InstantiableConfig } from "../Instantiable.abstract" const apiPath = "/api/v1/aquarius/assets/ddo" +export interface SearchQuery { + text?: string + offset: number + page: number + query: {[property: string]: string | number | string[] | number[]} + sort: {[jsonPath: string]: number} +} + /** * Provides a interface with Aquarius. * Aquarius provides an off-chain database store for metadata about data assets. diff --git a/src/aquarius/query/SearchQuery.ts b/src/aquarius/query/SearchQuery.ts deleted file mode 100644 index 55d5f0a..0000000 --- a/src/aquarius/query/SearchQuery.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface SearchQuery { - text?: string - offset: number - page: number - query: {[property: string]: string | number | string[] | number[]} - sort: {[jsonPath: string]: number} -} diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 7b06150..b8c6ca2 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -28,6 +28,10 @@ export class Brizo extends Instantiable { return `${this.url}${apiPath}/consume` } + public getEncryptEndpoint() { + return `${this.url}${apiPath}/publish` + } + public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) { // tslint:disable-next-line return `${this.url}${apiPath}/compute` @@ -69,17 +73,19 @@ export class Brizo extends Instantiable { files: File[], destination: string, ): Promise { + const agreementIdSignature = await this.ocean.utils.signature.signText(agreementId, account.getId()) const filesPromises = files - .map(async ({url}, i) => { + .map(async ({}, i) => { let consumeUrl = serviceEndpoint - consumeUrl += `?url=${url}` + consumeUrl += `?index=${i}` consumeUrl += `&serviceAgreementId=${agreementId}` consumeUrl += `&consumerAddress=${account.getId()}` + consumeUrl += `&signature=${agreementIdSignature}` try { await this.downloadFile( consumeUrl, - url.split("/").pop() || `file-${i}`, + `file-${i}`, destination, ) } catch (e) { @@ -100,4 +106,35 @@ export class Brizo extends Instantiable { await save(await response.arrayBuffer(), path) return path } + + public async encrypt( + did: string, + signedDid: string, + document: any, + publisher: string, + ): Promise { + + const args = { + documentId: did, + signedDocumentId: signedDid, + document: JSON.stringify(document), + publisherAddress: publisher, + } + + try { + const response = await WebServiceConnectorProvider + .getConnector() + .post( + this.getEncryptEndpoint(), + decodeURI(JSON.stringify(args)), + ) + if (!response.ok) { + throw new Error("HTTP request failed") + } + return await response.text() + } catch (e) { + this.logger.error(e) + throw new Error("HTTP request failed") + } + } } diff --git a/src/models/Config.ts b/src/models/Config.ts index 9704fa1..a662785 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -18,17 +18,8 @@ export class Config { // from outside eg. metamask public web3Provider?: any - /* Secret Store Config */ // the uri of the secret store to connect to public secretStoreUri: string - // the uri of the parity node to connect to - public parityUri: string - // the password of the account in the local parity node to sign the serverKeyId - public password: string - // the address of the account in the local parity node to sign the serverKeyId - public address: string - // the number of nodes in the secret store that have to agree on changes - public threshold: number /* Squid config */ public verbose: boolean | LogLevel diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index c217359..68b7932 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -1,7 +1,7 @@ -import { SearchQuery } from "../aquarius/query/SearchQuery" +import { SearchQuery } from "../aquarius/Aquarius" import { DDO } from "../ddo/DDO" import { MetaData } from "../ddo/MetaData" -import { Service, ServiceAuthorization } from "../ddo/Service" +import { Service } from "../ddo/Service" import Account from "./Account" import DID from "./DID" import { fillConditionsWithDDO } from "../utils" @@ -45,10 +45,8 @@ export class OceanAssets extends Instantiable { const did: DID = DID.generate() - const authorizationService = (services.find(({type}) => type === "Authorization") || {}) as ServiceAuthorization - const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint - const encryptedFiles = await this.ocean.secretStore.encrypt(did.getId(), metadata.base.files, null, secretStoreUrl) + const encryptedFiles = await this.ocean.secretStore.encrypt(did.getId(), metadata.base.files, publisher) const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() @@ -163,10 +161,9 @@ export class OceanAssets extends Instantiable { const ddo = await this.resolve(did) const {metadata} = ddo.findServiceByType("Metadata") - const authorizationService = ddo.findServiceByType("Authorization") const accessService = ddo.findServiceById(serviceDefinitionId) - const files = metadata.base.encryptedFiles + const files = metadata.base.files const {serviceEndpoint} = accessService @@ -174,13 +171,6 @@ export class OceanAssets extends Instantiable { throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.") } - const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint - - this.logger.log("Decrypting files") - const decryptedFiles = await this.ocean.secretStore - .decrypt(did, files, consumerAccount, secretStoreUrl) - this.logger.log("Files decrypted") - this.logger.log("Consuming files") resultPath = resultPath ? `${resultPath}/datafile.${ddo.shortId()}.${agreementId}/` : undefined @@ -188,7 +178,7 @@ export class OceanAssets extends Instantiable { agreementId, serviceEndpoint, consumerAccount, - decryptedFiles, + files, resultPath, ) this.logger.log("Files consumed") diff --git a/src/ocean/OceanSecretStore.ts b/src/ocean/OceanSecretStore.ts index faca9e5..7fb5607 100644 --- a/src/ocean/OceanSecretStore.ts +++ b/src/ocean/OceanSecretStore.ts @@ -1,6 +1,6 @@ -import SecretStoreProvider from "../secretstore/SecretStoreProvider" import Account from "./Account" import { noDidPrefixed } from "../utils" +import { File } from "../ddo/MetaData" import { Instantiable, InstantiableConfig } from "../Instantiable.abstract" /** @@ -27,35 +27,9 @@ export class OceanSecretStore extends Instantiable { * @param {string} publisher Publisher account. * @return {Promise} Encrypted text. */ - public async encrypt(did: string, content: any, publisher?: Account, secretStoreUrl?: string): Promise { - return await this.getSecretStoreByAccount(publisher, secretStoreUrl) - .encryptDocument(noDidPrefixed(did), content) - } + public async encrypt(did: string, document: any, publisher: Account): Promise { + const signedDid = await this.ocean.utils.signature.signText(noDidPrefixed(did), publisher.getId(), publisher.getPassword()) - /** - * Decrypt an encrypted text using the stored encryption keys associated with the `did`. - * Decryption requires that the account owner has access permissions for this `did` - * @param {string} did Decentralized ID. - * @param {string} content Content to be encrypted. - * @param {string} consumer cONSUMER account. - * @return {Promise} Encrypted text. - */ - public async decrypt(did: string, content: string, consumer?: Account, secretStoreUrl?: string): Promise { - return await this.getSecretStoreByAccount(consumer, secretStoreUrl) - .decryptDocument(noDidPrefixed(did), content) - } - - private getSecretStoreByAccount(account: Account, secretStoreUrl?: string) { - const config: any = {...this.config} - if (account) { - config.address = account.getId() - } - if (account && account.getPassword()) { - config.password = account.getPassword() - } - if (secretStoreUrl) { - config.secretStoreUri = secretStoreUrl - } - return SecretStoreProvider.getSecretStore(config) + return await this.ocean.brizo.encrypt(noDidPrefixed(did), signedDid, document, publisher.getId()) } } diff --git a/src/secretstore/SecretStoreProvider.ts b/src/secretstore/SecretStoreProvider.ts deleted file mode 100644 index 656f442..0000000 --- a/src/secretstore/SecretStoreProvider.ts +++ /dev/null @@ -1,22 +0,0 @@ -import SecretStore from "@oceanprotocol/secret-store-client" -import SecretStoreConfig from "@oceanprotocol/secret-store-client/dist/models/SecretStoreConfig" - -export default class SecretStoreProvider { - - public static getSecretStore(config: SecretStoreConfig): SecretStore { - const {secretStoreUri, parityUri, password, address, threshold} = config - config = {secretStoreUri, parityUri, password, address, threshold} - // Cleaning undefined parameters - Object.keys(config) - .forEach((key) => config[key] || config[key] === 0 || delete config[key]) - - const configRef = JSON.stringify(config) - if (!SecretStoreProvider.secretStoreWithConfig.get(configRef)) { - SecretStoreProvider.secretStoreWithConfig.set(configRef, new SecretStore({...config})) - } - - return SecretStoreProvider.secretStoreWithConfig.get(configRef) - } - - private static secretStoreWithConfig = new Map() -} diff --git a/test/keeper/DIDRegistry.test.ts b/test/keeper/DIDRegistry.test.ts index 2c33ddb..14204eb 100644 --- a/test/keeper/DIDRegistry.test.ts +++ b/test/keeper/DIDRegistry.test.ts @@ -40,47 +40,28 @@ describe("DIDRegistry", () => { // register the second attribute with the same did const data = "asdsad" const receipt = await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId()) - assert(receipt.status) - assert(receipt.events.DIDAttributeRegistered) + assert.isTrue(receipt.status) + assert.isDefined(receipt.events.DIDAttributeRegistered) } }) }) - // describe("#getOwner()", () => { + describe("#getDIDOwner()", () => { + it("should get the owner of a did properly", async () => { + const ownerAccount: Account = (await ocean.accounts.list())[0] + const did = generateId() + const data = "my nice provider, is nice" + await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId()) - // it("should get the owner of a did properly", async () => { - // const ownerAccount: Account = (await ocean.accounts.list())[0] - // const did = generateId() - // const data = "my nice provider, is nice" - // await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId()) + const owner = await didRegistry.getDIDOwner(did) - // const owner = await didRegistry.getOwner(did) - - // assert(owner === ownerAccount.getId(), `Got ${owner} but expected ${ownerAccount.getId()}`) - // }) - - // it("should get 0x00.. for a not registered did", async () => { - // const owner = await didRegistry.getOwner("1234") - // assert(owner === "0x0000000000000000000000000000000000000000") - // }) - - // }) - - // describe("#getUpdateAt()", () => { - - // it("should the block number of the last update of the did attribute", async () => { - // const ownerAccount: Account = (await ocean.accounts.list())[0] - // const did = generateId() - // const data = "my nice provider, is nice" - // await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId()) - - // const updatedAt: number = await didRegistry.getUpdateAt(did) - - // assert(updatedAt > 0) - // Logger.log(typeof updatedAt) - // }) - - // }) + assert.equal(owner, ownerAccount.getId(), `Got ${owner} but expected ${ownerAccount.getId()}`) + }) + it("should get 0x0 for a not registered did", async () => { + const owner = await didRegistry.getDIDOwner("1234") + assert.equal(owner, `0x${"0".repeat(40)}`) + }) + }) }) diff --git a/test/ocean/OceanSecretStore.test.ts b/test/ocean/OceanSecretStore.test.ts index 6bcd42a..00204aa 100644 --- a/test/ocean/OceanSecretStore.test.ts +++ b/test/ocean/OceanSecretStore.test.ts @@ -4,7 +4,6 @@ import * as spies from "chai-spies" import Account from "../../src/ocean/Account" import { Ocean } from "../../src/ocean/Ocean" import { OceanSecretStore } from "../../src/ocean/OceanSecretStore" -import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider" import config from "../config" use(spies) @@ -14,10 +13,11 @@ describe("OceanSecretStore", () => { let oceanSecretStore: OceanSecretStore let accounts: Account[] + let ocean: Ocean const did = "a".repeat(64) before(async () => { - const ocean = await Ocean.getInstance(config) + ocean = await Ocean.getInstance(config) oceanSecretStore = ocean.secretStore accounts = await ocean.accounts.list() }) @@ -28,31 +28,13 @@ describe("OceanSecretStore", () => { describe("#encrypt()", () => { it("should encrypt a content", async () => { - const secretStoreToSpy = SecretStoreProvider.getSecretStore({...config, address: accounts[0].getId()}) - const secretStoreEncryptSpy = spy.on(secretStoreToSpy, "encryptDocument", () => "encryptedResult") - const secretStoreProviderGetInstanceSpy = spy.on(SecretStoreProvider, "getSecretStore", () => secretStoreToSpy) + const secretStoreEncryptSpy = spy.on(ocean.brizo, "encrypt", () => "encryptedResult") const result = await oceanSecretStore.encrypt(did, "test", accounts[0]) - expect(secretStoreProviderGetInstanceSpy).to.have.been.called.with({...config, address: accounts[0].getId()}) expect(secretStoreEncryptSpy).to.have.been.called.with(did, "test") assert.equal(result, "encryptedResult", "Result doesn't match") }) }) - - describe("#decrypt()", () => { - it("should decrypt a content", async () => { - const secretStoreToSpy = SecretStoreProvider.getSecretStore({...config, address: accounts[0].getId()}) - const secretStoreEncryptSpy = spy.on(secretStoreToSpy, "decryptDocument", () => "decryptedResult") - const secretStoreProviderGetInstanceSpy = spy.on(SecretStoreProvider, "getSecretStore", () => secretStoreToSpy) - - const result = await oceanSecretStore.decrypt(did, "encryptedContent", accounts[0]) - - expect(secretStoreProviderGetInstanceSpy).to.have.been.called.with({...config, address: accounts[0].getId()}) - expect(secretStoreEncryptSpy).to.have.been.called.with(did, "encryptedContent") - - assert.equal(result, "decryptedResult", "Result doesn't match") - }) - }) })