mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Allow using Secret Store to decrypt the files that are going to be downloaded.
This commit is contained in:
parent
ccbd0daead
commit
88b8eb06c6
@ -207,7 +207,8 @@ export class OceanAssets extends Instantiable {
|
|||||||
serviceDefinitionId: string,
|
serviceDefinitionId: string,
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
resultPath: string,
|
resultPath: string,
|
||||||
index?: number
|
index?: number,
|
||||||
|
useSecretStore?: boolean
|
||||||
): Promise<string>
|
): Promise<string>
|
||||||
|
|
||||||
public async consume(
|
public async consume(
|
||||||
@ -216,7 +217,8 @@ export class OceanAssets extends Instantiable {
|
|||||||
serviceDefinitionId: string,
|
serviceDefinitionId: string,
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
resultPath?: undefined | null,
|
resultPath?: undefined | null,
|
||||||
index?: number
|
index?: number,
|
||||||
|
useSecretStore?: boolean
|
||||||
): Promise<true>
|
): Promise<true>
|
||||||
|
|
||||||
public async consume(
|
public async consume(
|
||||||
@ -225,7 +227,8 @@ export class OceanAssets extends Instantiable {
|
|||||||
serviceDefinitionId: string,
|
serviceDefinitionId: string,
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
resultPath?: string,
|
resultPath?: string,
|
||||||
index: number = -1
|
index: number = -1,
|
||||||
|
useSecretStore?: boolean
|
||||||
): Promise<string | true> {
|
): Promise<string | true> {
|
||||||
const ddo = await this.resolve(did)
|
const ddo = await this.resolve(did)
|
||||||
const { metadata } = ddo.findServiceByType('Metadata')
|
const { metadata } = ddo.findServiceByType('Metadata')
|
||||||
@ -247,14 +250,28 @@ export class OceanAssets extends Instantiable {
|
|||||||
resultPath = resultPath
|
resultPath = resultPath
|
||||||
? `${resultPath}/datafile.${ddo.shortId()}.${serviceDefinitionId}/`
|
? `${resultPath}/datafile.${ddo.shortId()}.${serviceDefinitionId}/`
|
||||||
: undefined
|
: undefined
|
||||||
await this.ocean.brizo.consumeService(
|
|
||||||
agreementId,
|
if (!useSecretStore) {
|
||||||
serviceEndpoint,
|
await this.ocean.brizo.consumeService(
|
||||||
consumerAccount,
|
agreementId,
|
||||||
files,
|
serviceEndpoint,
|
||||||
resultPath,
|
consumerAccount,
|
||||||
index
|
files,
|
||||||
)
|
resultPath,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
const files = await this.ocean.secretStore.decrypt(
|
||||||
|
did,
|
||||||
|
ddo.findServiceByType('Metadata').metadata.base.encryptedFiles,
|
||||||
|
consumerAccount,
|
||||||
|
ddo.findServiceByType('Authorization').serviceEndpoint
|
||||||
|
)
|
||||||
|
const downloads = files
|
||||||
|
.filter(({index: i}) => index === -1 || index === i)
|
||||||
|
.map(({url, index: i}) => this.ocean.utils.fetch.downloadFile(url, resultPath, i))
|
||||||
|
await Promise.all(downloads)
|
||||||
|
}
|
||||||
this.logger.log('Files consumed')
|
this.logger.log('Files consumed')
|
||||||
|
|
||||||
if (resultPath) {
|
if (resultPath) {
|
||||||
|
Loading…
Reference in New Issue
Block a user