From 1e94e27f81b47066a310ae6563ba0a72e9e2a3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 15 Apr 2019 17:45:06 +0200 Subject: [PATCH] Fix wrong prepare output. --- integration/ocean/ConsumeAsset.test.ts | 2 +- src/brizo/Brizo.ts | 5 +++-- src/ocean/OceanAgreements.ts | 2 +- src/ocean/OceanAssets.ts | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index 7bbc4ca..410e12f 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -47,7 +47,7 @@ describe("Consume Asset", () => { serviceAgreementSignatureResult = await ocean.agreements.prepare(ddo.id, accessService.serviceDefinitionId, consumer) const {agreementId, signature} = serviceAgreementSignatureResult - assert.match(agreementId, /^[a-f0-9]{64}$/, "Service agreement ID seems not valid") + assert.match(agreementId, /^0x[a-f0-9]{64}$/, "Service agreement ID seems not valid") assert.match(signature, /^0x[a-f0-9]{130}$/, "Service agreement signature seems not valid") }) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index a78e140..287be0e 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -3,6 +3,7 @@ import save = require("save-file") import { File } from "../ddo/MetaData" import Account from "../ocean/Account" +import { noZeroX } from "../utils" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" import { Instantiable, InstantiableConfig } from "../Instantiable.abstract" @@ -76,13 +77,13 @@ export class Brizo extends Instantiable { destination: string, index: number = -1, ): Promise { - const agreementIdSignature = await this.ocean.utils.signature.signText(agreementId, account.getId()) + const agreementIdSignature = await this.ocean.utils.signature.signText(noZeroX(agreementId), account.getId()) const filesPromises = files .filter(({}, i) => index === -1 || i === index) .map(async ({index: i}) => { let consumeUrl = serviceEndpoint consumeUrl += `?index=${i}` - consumeUrl += `&serviceAgreementId=${agreementId}` + consumeUrl += `&serviceAgreementId=${noZeroX(agreementId)}` consumeUrl += `&consumerAddress=${account.getId()}` consumeUrl += `&signature=${agreementIdSignature}` diff --git a/src/ocean/OceanAgreements.ts b/src/ocean/OceanAgreements.ts index d3dd405..5edcb38 100644 --- a/src/ocean/OceanAgreements.ts +++ b/src/ocean/OceanAgreements.ts @@ -49,7 +49,7 @@ export class OceanAgreements extends Instantiable { const d: DID = DID.parse(did as string) const ddo = await this.ocean.aquarius.retrieveDDO(d) - const agreementId: string = generateId() + const agreementId: string = zeroX(generateId()) const templateName = ddo.findServiceByType("Access").serviceAgreementTemplate.contractName const agreementConditionsIds = await this.ocean.keeper diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 05a07bc..ad047a2 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -4,7 +4,7 @@ import { MetaData } from "../ddo/MetaData" import { Service } from "../ddo/Service" import Account from "./Account" import DID from "./DID" -import { fillConditionsWithDDO } from "../utils" +import { fillConditionsWithDDO, noZeroX } from "../utils" import { Instantiable, InstantiableConfig } from "../Instantiable.abstract" /** @@ -174,7 +174,7 @@ export class OceanAssets extends Instantiable { this.logger.log("Consuming files") - resultPath = resultPath ? `${resultPath}/datafile.${ddo.shortId()}.${agreementId}/` : undefined + resultPath = resultPath ? `${resultPath}/datafile.${ddo.shortId()}.${noZeroX(agreementId)}/` : undefined await this.ocean.brizo.consumeService( agreementId, serviceEndpoint,