diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts new file mode 100644 index 0000000..fba6f82 --- /dev/null +++ b/src/brizo/Brizo.ts @@ -0,0 +1,18 @@ +import Config from "../models/Config" + +export default class Brizo { + private url: string + + constructor(config: Config) { + + this.url = config.brizoUri + } + + public getPurchaseEndpoint() { + return `${this.url}/api/v1/brizo/services/access/purchase?` + } + + public getServiceEndpoint(pubKey: string, serviceId: string, url: string) { + return `${this.url}/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` + } +} diff --git a/src/brizo/BrizoProvider.ts b/src/brizo/BrizoProvider.ts new file mode 100644 index 0000000..f8e5c3d --- /dev/null +++ b/src/brizo/BrizoProvider.ts @@ -0,0 +1,20 @@ +import ConfigProvider from "../ConfigProvider" +import Brizo from "./Brizo" + +export default class BrizoProvider { + + public static setBrizo(brizo: Brizo) { + + BrizoProvider.brizo = brizo + } + + public static getBrizo() { + + if (!BrizoProvider.brizo) { + BrizoProvider.brizo = new Brizo(ConfigProvider.getConfig()) + } + return BrizoProvider.brizo + } + + private static brizo: Brizo = null +} diff --git a/src/examples/Register.ts b/src/examples/Register.ts index 9f36bc0..ce08f85 100644 --- a/src/examples/Register.ts +++ b/src/examples/Register.ts @@ -6,6 +6,7 @@ import {Account, Logger, Ocean} from "../squid" const ocean: Ocean = await Ocean.getInstance({ nodeUri: "http://localhost:8545", aquariusUri: "http://localhost:5000", + brizoUri: "https://localhost:8030", parityUri: "http://localhost:9545", secretStoreUri: "https://secret-store.dev-ocean.com", threshold: 2, diff --git a/src/models/Config.ts b/src/models/Config.ts index 7b8cc71..2b97483 100644 --- a/src/models/Config.ts +++ b/src/models/Config.ts @@ -3,6 +3,10 @@ export default class Config { // the url to the aquarius public aquariusUri: string + /* Brizo Config */ + // the url to the brizo + public brizoUri: string + /* Keeper Config */ // the uri to the node we want to connect to, not need if web3Provider is set public nodeUri?: string diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 6d99bea..e857842 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -1,7 +1,10 @@ import Aquarius from "../aquarius/Aquarius" import AquariusProvider from "../aquarius/AquariusProvider" import SearchQuery from "../aquarius/query/SearchQuery" +import Brizo from "../brizo/Brizo" +import BrizoProvider from "../brizo/BrizoProvider" import ConfigProvider from "../ConfigProvider" +import Authentication from "../ddo/Authentication" import DDOCondition from "../ddo/Condition" import DDO from "../ddo/DDO" import MetaData from "../ddo/MetaData" @@ -12,7 +15,7 @@ import Web3Provider from "../keeper/Web3Provider" import Config from "../models/Config" import ValuePair from "../models/ValuePair" import ValueType from "../models/ValueType" -import Logger from "../utils/Logger" +import SecretStoreProvider from "../secretstore/SecretStoreProvider" import Account from "./Account" import IdGenerator from "./IdGenerator" import Condition from "./ServiceAgreements/Condition" @@ -29,6 +32,7 @@ export default class Ocean { Ocean.instance = new Ocean() Ocean.instance.keeper = await Keeper.getInstance() Ocean.instance.aquarius = await AquariusProvider.getAquarius() + Ocean.instance.brizo = await BrizoProvider.getBrizo() } return Ocean.instance @@ -38,6 +42,7 @@ export default class Ocean { private keeper: Keeper private aquarius: Aquarius + private brizo: Brizo private constructor() { } @@ -58,12 +63,12 @@ export default class Ocean { const did: string = `did:op:${id}` const serviceDefinitionId: string = IdGenerator.generatePrefixedId() - metadata.base.contentUrls = metadata.base.contentUrls.map((contentUrl) => { + metadata.base.contentUrls = await Promise.all(metadata.base.contentUrls.map(async (contentUrl) => { - // todo encrypt url in secret store - Logger.log(contentUrl) - return "0x00000" - }) + const encryptedUrl: string = await SecretStoreProvider.getSecretStore().encryptDocument(id, contentUrl) + + return encryptedUrl + })) const template = new Access() const serviceAgreementTemplate = new ServiceAgreementTemplate(template) @@ -91,12 +96,16 @@ export default class Ocean { // create ddo itself const ddo: DDO = new DDO({ id: did, + authentication: [{ + publicKey: publisher.getId(), + } as Authentication], service: [ { type: template.templateName, // tslint:disable-next-line - serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}", - purchaseEndpoint: "http://mybrizo.org/api/v1/brizo/services/access/purchase?", + serviceEndpoint: this.brizo.getServiceEndpoint(publisher.getId(), + serviceDefinitionId, metadata.base.contentUrls[0]), + purchaseEndpoint: this.brizo.getPurchaseEndpoint(), // the id of the service agreement? serviceDefinitionId, // the id of the service agreement template @@ -110,6 +119,8 @@ export default class Ocean { ], }) + // Logger.log(JSON.stringify(ddo, null, 2)) + const storedDdo = await this.aquarius.storeDDO(ddo) await didRegistry.registerAttribute(id, ValueType.DID, "Metadata", serviceEndpoint,