From 5e4a33f4e24bbfec3e9031705d7679984511bed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 22 Jan 2019 14:14:49 +0100 Subject: [PATCH 1/3] added better DID verification --- src/ocean/DID.ts | 9 ++++----- test/ocean/DID.test.ts | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ocean/DID.ts b/src/ocean/DID.ts index ef3d13f..ed5e99c 100644 --- a/src/ocean/DID.ts +++ b/src/ocean/DID.ts @@ -14,11 +14,10 @@ export default class DID { */ public static parse(didString: string): DID { let did: DID - if (didString.startsWith(prefix)) { - const id = didString.split(prefix)[1] - if (!id.startsWith("0x")) { - did = new DID(id) - } + const didMatch = didString.match(/^did:op:([a-f0-9]{64})$/i) + + if (didMatch) { + did = new DID(didMatch[1]) } if (!did) { diff --git a/test/ocean/DID.test.ts b/test/ocean/DID.test.ts index 9fb7bfa..75d98b1 100644 --- a/test/ocean/DID.test.ts +++ b/test/ocean/DID.test.ts @@ -13,7 +13,7 @@ describe("DID", () => { describe("#parse()", () => { it("should parse a valid did", () => { - const id = "1234" + const id = "a".repeat(64) const did: DID = DID.parse(`did:op:${id}`) assert(did) @@ -33,7 +33,7 @@ describe("DID", () => { it("should throw if id does not match", (done) => { - const id = "0x1234" + const id = "xyz" try { const did: DID = DID.parse(`did:op:${id}`) assert(!did) @@ -56,7 +56,7 @@ describe("DID", () => { describe("#getDid()", () => { it("should return only the id part of the did", () => { - const id = "1234" + const id = "a".repeat(64) const did: DID = DID.parse(`did:op:${id}`) assert(did) From f71e7e345a610d5adca4998aed680c787827663f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 22 Jan 2019 14:18:58 +0100 Subject: [PATCH 2/3] linter fixes --- src/ocean/DID.ts | 2 +- src/ocean/Ocean.ts | 13 ++++++------- src/utils/WebServiceConnector.ts | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ocean/DID.ts b/src/ocean/DID.ts index ed5e99c..65f6de9 100644 --- a/src/ocean/DID.ts +++ b/src/ocean/DID.ts @@ -15,7 +15,7 @@ export default class DID { public static parse(didString: string): DID { let did: DID const didMatch = didString.match(/^did:op:([a-f0-9]{64})$/i) - + if (didMatch) { did = new DID(didMatch[1]) } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 5869cc5..c06d592 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -1,4 +1,4 @@ -import deprecated from 'deprecated-decorator'; +import deprecated from "deprecated-decorator" import AquariusProvider from "../aquarius/AquariusProvider" import SearchQuery from "../aquarius/query/SearchQuery" @@ -82,9 +82,9 @@ export default class Ocean { * @param {string} did Decentralized ID. * @return {Promise} */ - @deprecated('resolveAssetDID') + @deprecated("resolveAssetDID") public async resolveDID(did: string): Promise { - return await this.resolveAssetDID(did); + return await this.resolveAssetDID(did) } /** @@ -201,15 +201,15 @@ export default class Ocean { * @param {string} serviceDefinitionId Service definition ID. * @param {Account} consumer Consumer account. * @return {Promise} - * + * */ - @deprecated('purchaseAssetService') + @deprecated("purchaseAssetService") public async signServiceAgreement( did: string, serviceDefinitionId: string, consumer: Account, ): Promise { - return await this.purchaseAssetService(did, serviceDefinitionId, consumer); + return await this.purchaseAssetService(did, serviceDefinitionId, consumer) } /** @@ -369,7 +369,6 @@ export default class Ocean { return AquariusProvider.getAquarius().queryMetadata(query) } - /** * Search over the assets using a keyword. * @param {SearchQuery} text Text to filter the assets. diff --git a/src/utils/WebServiceConnector.ts b/src/utils/WebServiceConnector.ts index 8449e17..ae73194 100644 --- a/src/utils/WebServiceConnector.ts +++ b/src/utils/WebServiceConnector.ts @@ -1,4 +1,4 @@ -import fetch, { Response, RequestInit, BodyInit } from "node-fetch" +import fetch, { BodyInit, RequestInit, Response } from "node-fetch" /** * Provides a common interface to web services. From 04165747a031c802cd7541676cd62fb035ceb6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 22 Jan 2019 23:56:52 +0100 Subject: [PATCH 3/3] exporting source map to do debugging easier --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4908e0c..9dab4c7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'", "start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch", "build": "npm run clean && npm run build:tsc && npm run build:dist", - "build:tsc": "tsc", + "build:tsc": "tsc --sourceMap", "build:dist": "cross-env NODE_ENV=production webpack", "build:watch": "tsc -w", "doc": "typedoc --mode modules --out ./doc/ ./src/",