From 2c73c6e06df69c2773404a1138800b8a8e7803bd Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 13 Oct 2020 06:34:57 -0700 Subject: [PATCH 1/4] remove ddo prof --- src/ddo/DDO.ts | 23 +++++++++++++++++++++++ src/ocean/Assets.ts | 10 +++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 04dfc516..3e5ee1cb 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -157,4 +157,27 @@ export class DDO { } this.proof = await this.generateProof(ocean, publicKey, password) } + + /** + * Generates and adds a simple proof + * @param {Ocean} ocean Ocean instance. + * @param {string} publicKey Public key to be used on personal sign. + * @param {string} password Password if it's required. + * @return {Promise} Proof object. + */ + public async addSimpleProof(ocean: Ocean, publicKey: string): Promise { + if (this.proof) { + throw new Error('Proof already exists') + } + + this.proof = { + created: new Date().toISOString().replace(/\.[0-9]{3}/, ''), + creator: publicKey, + type: 'AddressHash', + signatureValue: Web3Provider.getWeb3() + .utils.sha3(publicKey) + // TODO: security/detect-unsafe-regex + .replace(/^0x([a-f0-9]{64})(:!.+)?$/i, '0x$1') + } + } } diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index 6f936911..b90d7bb5 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -188,11 +188,11 @@ export class Assets extends Instantiable { index: indexCount++ })) as Service[] }) - this.logger.log('Generating proof') - observer.next(CreateProgressStep.GeneratingProof) - await ddo.addProof(this.ocean, publisher.getId(), publisher.getPassword()) - this.logger.log('Proof generated') - observer.next(CreateProgressStep.ProofGenerated) + // this.logger.log('Generating proof') + // observer.next(CreateProgressStep.GeneratingProof) + await ddo.addSimpleProof(this.ocean, publisher.getId()) + // this.logger.log('Proof generated') + // observer.next(CreateProgressStep.ProofGenerated) this.logger.log('Storing DDO') observer.next(CreateProgressStep.StoringDdo) // const storedDdo = await this.ocean.metadatastore.storeDDO(ddo) From 0088e94c01a22c4a91007e9962f6e979a813896e Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 13 Oct 2020 06:40:41 -0700 Subject: [PATCH 2/4] fix doc typo --- src/ddo/DDO.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 3e5ee1cb..375000cb 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -159,10 +159,9 @@ export class DDO { } /** - * Generates and adds a simple proof + * Generates and adds a simple hash proof * @param {Ocean} ocean Ocean instance. * @param {string} publicKey Public key to be used on personal sign. - * @param {string} password Password if it's required. * @return {Promise} Proof object. */ public async addSimpleProof(ocean: Ocean, publicKey: string): Promise { From e68c6d8c72ad424388816e31973369d1716b256e Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 13 Oct 2020 06:54:37 -0700 Subject: [PATCH 3/4] proof refactor --- src/ddo/DDO.ts | 43 ++----------------------------------------- src/ocean/Assets.ts | 2 +- 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 375000cb..cdace66f 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -117,35 +117,10 @@ export class DDO { } /** - * Generates proof using personal sing. + * Generates and adds a simple hash proof on publicKey * @param {Ocean} ocean Ocean instance. * @param {string} publicKey Public key to be used on personal sign. - * @param {string} password Password if it's required. - * @return {Promise} Proof object. - */ - public async generateProof( - ocean: Ocean, - publicKey: string, - password?: string - ): Promise { - const checksum = this.getChecksum() - - const signature = await ocean.utils.signature.signText(checksum, publicKey, password) - - return { - created: new Date().toISOString().replace(/\.[0-9]{3}/, ''), - creator: publicKey, - type: 'DDOIntegritySignature', - signatureValue: signature - } - } - - /** - * Generates and adds a proof using personal sing on the DDO. - * @param {Ocean} ocean Ocean instance. - * @param {string} publicKey Public key to be used on personal sign. - * @param {string} password Password if it's required. - * @return {Promise} Proof object. + * @return {Promise} */ public async addProof( ocean: Ocean, @@ -155,20 +130,6 @@ export class DDO { if (this.proof) { throw new Error('Proof already exists') } - this.proof = await this.generateProof(ocean, publicKey, password) - } - - /** - * Generates and adds a simple hash proof - * @param {Ocean} ocean Ocean instance. - * @param {string} publicKey Public key to be used on personal sign. - * @return {Promise} Proof object. - */ - public async addSimpleProof(ocean: Ocean, publicKey: string): Promise { - if (this.proof) { - throw new Error('Proof already exists') - } - this.proof = { created: new Date().toISOString().replace(/\.[0-9]{3}/, ''), creator: publicKey, diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index b90d7bb5..e2231b28 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -190,7 +190,7 @@ export class Assets extends Instantiable { }) // this.logger.log('Generating proof') // observer.next(CreateProgressStep.GeneratingProof) - await ddo.addSimpleProof(this.ocean, publisher.getId()) + await ddo.addProof(this.ocean, publisher.getId()) // this.logger.log('Proof generated') // observer.next(CreateProgressStep.ProofGenerated) this.logger.log('Storing DDO') From b35e0296ff8bd2687e1649c0c9028dd12eaeda4b Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 13 Oct 2020 07:14:54 -0700 Subject: [PATCH 4/4] remove unused ProgressSteps --- src/ocean/Assets.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index e2231b28..2dd8fa5d 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -18,8 +18,6 @@ export enum CreateProgressStep { DataTokenCreated, EncryptingFiles, FilesEncrypted, - GeneratingProof, - ProofGenerated, StoringDdo, DdoStored } @@ -188,11 +186,7 @@ export class Assets extends Instantiable { index: indexCount++ })) as Service[] }) - // this.logger.log('Generating proof') - // observer.next(CreateProgressStep.GeneratingProof) await ddo.addProof(this.ocean, publisher.getId()) - // this.logger.log('Proof generated') - // observer.next(CreateProgressStep.ProofGenerated) this.logger.log('Storing DDO') observer.next(CreateProgressStep.StoringDdo) // const storedDdo = await this.ocean.metadatastore.storeDDO(ddo)