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.
|
* @return {Promise<String>} Hex encoded encrypted DDO.
|
||||||
*/
|
*/
|
||||||
public async encryptDDO(ddo: any): Promise<any> {
|
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
|
const result = await this.fetch
|
||||||
.postWithOctet(fullUrl, ddo)
|
.postWithOctet(fullUrl, ddo)
|
||||||
.then((response: Response) => {
|
.then((response: Response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.blob()
|
return response.text()
|
||||||
}
|
}
|
||||||
this.logger.error('encryptDDO failed:', response.status, response.statusText, ddo)
|
this.logger.error('encryptDDO failed:', response.status, response.statusText, ddo)
|
||||||
return null
|
return null
|
||||||
|
@ -75,6 +75,9 @@ export class OnChainMetadata {
|
|||||||
encrypt: boolean = false
|
encrypt: boolean = false
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const rawData = await this.prepareRawData(ddo, encrypt)
|
const rawData = await this.prepareRawData(ddo, encrypt)
|
||||||
|
if (!rawData) {
|
||||||
|
throw new Error(`Could not prepare raw data for publish`)
|
||||||
|
} else
|
||||||
return this.publishRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
return this.publishRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +95,9 @@ export class OnChainMetadata {
|
|||||||
encrypt: boolean = false
|
encrypt: boolean = false
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const rawData = await this.prepareRawData(ddo, encrypt)
|
const rawData = await this.prepareRawData(ddo, encrypt)
|
||||||
|
if (!rawData) {
|
||||||
|
throw new Error(`Could not prepare raw data for udate`)
|
||||||
|
} else
|
||||||
return this.updateRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
return this.updateRaw(didZeroX(did), rawData.flags, rawData.data, consumerAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,17 +115,7 @@ export class OnChainMetadata {
|
|||||||
flags = flags | 1
|
flags = flags | 1
|
||||||
data = this.getHex(data)
|
data = this.getHex(data)
|
||||||
} else {
|
} else {
|
||||||
const blob = await this.metadataCache.encryptDDO(data)
|
data = 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)
|
|
||||||
}
|
|
||||||
if (!data) return null
|
if (!data) return null
|
||||||
flags = flags | 2
|
flags = flags | 2
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user