mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix ddo encrypt for browsers (#822)
* fix ddo encrypt for browsers Warning: needs aquarius >= 2.2.12
This commit is contained in:
parent
9df93b71cb
commit
6ce02ec17c
@ -146,12 +146,12 @@ export class MetadataCache {
|
||||
* @return {Promise<String>} Hex encoded encrypted DDO.
|
||||
*/
|
||||
public async encryptDDO(ddo: any): Promise<any> {
|
||||
const fullUrl = `${this.url}/api/v1/aquarius/assets/ddo/encrypt`
|
||||
const fullUrl = `${this.url}/api/v1/aquarius/assets/ddo/encryptashex `
|
||||
const result = await this.fetch
|
||||
.postWithOctet(fullUrl, ddo)
|
||||
.then((response: Response) => {
|
||||
if (response.ok) {
|
||||
return response.blob()
|
||||
return response.text()
|
||||
}
|
||||
this.logger.error('encryptDDO failed:', response.status, response.statusText, ddo)
|
||||
return null
|
||||
|
@ -75,7 +75,10 @@ export class OnChainMetadata {
|
||||
encrypt: boolean = false
|
||||
): Promise<TransactionReceipt> {
|
||||
const rawData = await this.prepareRawData(ddo, encrypt)
|
||||
return this.publishRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||
if (!rawData) {
|
||||
throw new Error(`Could not prepare raw data for publish`)
|
||||
} else
|
||||
return this.publishRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +95,10 @@ export class OnChainMetadata {
|
||||
encrypt: boolean = false
|
||||
): Promise<TransactionReceipt> {
|
||||
const rawData = await this.prepareRawData(ddo, encrypt)
|
||||
return this.updateRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||
if (!rawData) {
|
||||
throw new Error(`Could not prepare raw data for udate`)
|
||||
} else
|
||||
return this.updateRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,17 +115,7 @@ export class OnChainMetadata {
|
||||
flags = flags | 1
|
||||
data = this.getHex(data)
|
||||
} else {
|
||||
const blob = await this.metadataCache.encryptDDO(data)
|
||||
try {
|
||||
const rawBuffer = (await new Response(blob).arrayBuffer()) as any
|
||||
data =
|
||||
'0x' +
|
||||
Array.prototype.map
|
||||
.call(new Uint8Array(rawBuffer), (x) => ('00' + x.toString(16)).slice(-2))
|
||||
.join('')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
data = await this.metadataCache.encryptDDO(data)
|
||||
if (!data) return null
|
||||
flags = flags | 2
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user