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:
parent
f5ab0e6d05
commit
0a0786a835
@ -78,7 +78,7 @@ export class DDO {
|
||||
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>
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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[]>[
|
||||
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()
|
||||
|
@ -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<string, SecretStore>()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user