1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

be able to use a SecretStore URL defined on the DDO ocean#247

This commit is contained in:
Pedro Gutiérrez 2019-02-07 14:21:16 +01:00 committed by Pedro Gutiérrez
parent f5ab0e6d05
commit 0a0786a835
3 changed files with 30 additions and 12 deletions

View File

@ -78,7 +78,7 @@ export class DDO {
throw new Error("serviceType not set") throw new Error("serviceType not set")
} }
return <Service<T>>this.service.find((s) => s.type === serviceType) return this.service.find((s) => s.type === serviceType) as Service<T>
} }
/** /**

View File

@ -4,7 +4,7 @@ import BrizoProvider from "../brizo/BrizoProvider"
import { Condition } from "../ddo/Condition" import { Condition } from "../ddo/Condition"
import { DDO } from "../ddo/DDO" import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData" import { MetaData } from "../ddo/MetaData"
import { Service } from "../ddo/Service" import { Service, ServiceAuthorization } from "../ddo/Service"
import ContractEvent from "../keeper/Event" import ContractEvent from "../keeper/Event"
import EventListener from "../keeper/EventListener" import EventListener from "../keeper/EventListener"
import Keeper from "../keeper/Keeper" import Keeper from "../keeper/Keeper"
@ -62,8 +62,10 @@ export default class OceanAssets {
const did: DID = DID.generate() const did: DID = DID.generate()
metadata.base.encryptedFiles = await SecretStoreProvider.getSecretStore() const authorizationService = (services.find(({type}) => type === "Authorization") || {}) as ServiceAuthorization
.encryptDocument(did.getId(), metadata.base.files) const secretStoreUrl = authorizationService.service === "SecretStore" && authorizationService.serviceEndpoint
const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreUrl).encryptDocument(did.getId(), metadata.base.files)
const template = new Access() const template = new Access()
const serviceAgreementTemplate = new ServiceAgreementTemplate(template) const serviceAgreementTemplate = new ServiceAgreementTemplate(template)
@ -88,7 +90,7 @@ export default class OceanAssets {
publicKeyBase58: await publisher.getPublicKey(), publicKeyBase58: await publisher.getPublicKey(),
}, },
], ],
service: <Service[]>[ service: [
{ {
type: template.templateName, type: template.templateName,
purchaseEndpoint: brizo.getPurchaseEndpoint(), purchaseEndpoint: brizo.getPurchaseEndpoint(),
@ -138,12 +140,15 @@ export default class OceanAssets {
// Cleaning not needed information // Cleaning not needed information
base: { base: {
...metadata.base, ...metadata.base,
contentUrls: [],
encryptedFiles,
files: undefined, files: undefined,
} as any, } as any,
}, },
}, },
...services, ...services
], .map((_) => ({..._, serviceDefinitionId: String(serviceDefinitionIdCount++)})),
] as Service[],
}) })
ddo.addChecksum() ddo.addChecksum()

View File

@ -8,14 +8,27 @@ export default class SecretStoreProvider {
SecretStoreProvider.secretStore = secretStore 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) { return SecretStoreProvider.secretStore
SecretStoreProvider.secretStore = new SecretStore(ConfigProvider.getConfig()) } 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 secretStore: SecretStore
private static secretStoreByUrl = new Map<string, SecretStore>()
} }