diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index f86079e..62b24a3 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -78,7 +78,7 @@ export class DDO { throw new Error("serviceType not set") } - return >this.service.find((s) => s.type === serviceType) + return this.service.find((s) => s.type === serviceType) as Service } /** diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index e9ff943..254a54d 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -4,7 +4,7 @@ import BrizoProvider from "../brizo/BrizoProvider" import { Condition } from "../ddo/Condition" import { DDO } from "../ddo/DDO" import { MetaData } from "../ddo/MetaData" -import { Service } from "../ddo/Service" +import { Service, ServiceAuthorization } from "../ddo/Service" import ContractEvent from "../keeper/Event" import EventListener from "../keeper/EventListener" import Keeper from "../keeper/Keeper" @@ -62,8 +62,10 @@ export default class OceanAssets { const did: DID = DID.generate() - metadata.base.encryptedFiles = await SecretStoreProvider.getSecretStore() - .encryptDocument(did.getId(), metadata.base.files) + const authorizationService = (services.find(({type}) => type === "Authorization") || {}) as ServiceAuthorization + const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint + + const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreUrl).encryptDocument(did.getId(), metadata.base.files) const template = new Access() const serviceAgreementTemplate = new ServiceAgreementTemplate(template) @@ -88,7 +90,7 @@ export default class OceanAssets { publicKeyBase58: await publisher.getPublicKey(), }, ], - service: [ + service: [ { type: template.templateName, purchaseEndpoint: brizo.getPurchaseEndpoint(), @@ -138,12 +140,15 @@ export default class OceanAssets { // Cleaning not needed information base: { ...metadata.base, + contentUrls: [], + encryptedFiles, files: undefined, } as any, }, }, - ...services, - ], + ...services + .map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})), + ] as Service[], }) ddo.addChecksum() diff --git a/src/secretstore/SecretStoreProvider.ts b/src/secretstore/SecretStoreProvider.ts index da3d103..51043b1 100644 --- a/src/secretstore/SecretStoreProvider.ts +++ b/src/secretstore/SecretStoreProvider.ts @@ -8,14 +8,27 @@ export default class SecretStoreProvider { SecretStoreProvider.secretStore = secretStore } - public static getSecretStore(): SecretStore { + public static getSecretStore(url?: string): SecretStore { + if (!url) { + if (!SecretStoreProvider.secretStore) { + SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig()) + } - if (!SecretStoreProvider.secretStore) { - SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig()) + return SecretStoreProvider.secretStore + } else { + if (!SecretStoreProvider.secretStoreByUrl.get(url)) { + SecretStoreProvider.secretStoreByUrl.set(url, + new SecretStore({ + ...ConfigProvider.getConfig(), + secretStoreUri: url, + }), + ) + } + + return SecretStoreProvider.secretStoreByUrl.get(url) } - - return SecretStoreProvider.secretStore } private static secretStore: SecretStore + private static secretStoreByUrl = new Map() }