mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Resolve the DDO using the service endpoint on registration event.
This commit is contained in:
parent
df0ced1f1a
commit
a9ba23d2c3
@ -178,11 +178,16 @@ export class Aquarius extends Instantiable {
|
||||
|
||||
/**
|
||||
* Retrieves a DDO by DID.
|
||||
* @param {DID} did DID of the asset.
|
||||
* @param {DID | string} did DID of the asset.
|
||||
* @return {Promise<DDO>} DDO of the asset.
|
||||
*/
|
||||
public async retrieveDDO(did: DID): Promise<DDO> {
|
||||
const fullUrl = `${this.url}${apiPath}/${did.getDid()}`
|
||||
public async retrieveDDO(
|
||||
did: DID | string,
|
||||
metadataServiceEndpoint?: string
|
||||
): Promise<DDO> {
|
||||
did = did && DID.parse(did)
|
||||
const fullUrl =
|
||||
metadataServiceEndpoint || `${this.url}${apiPath}/${did.getDid()}`
|
||||
const result = await this.ocean.utils.fetch
|
||||
.get(fullUrl)
|
||||
.then((response: any) => {
|
||||
@ -208,6 +213,10 @@ export class Aquarius extends Instantiable {
|
||||
return result
|
||||
}
|
||||
|
||||
public async retrieveDDOByUrl(metadataServiceEndpoint?: string) {
|
||||
return this.retrieveDDO(undefined, metadataServiceEndpoint)
|
||||
}
|
||||
|
||||
public getServiceEndpoint(did: DID) {
|
||||
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Web3Provider from '../Web3Provider'
|
||||
import ContractBase from './ContractBase'
|
||||
import { zeroX, didPrefixed } from '../../utils'
|
||||
import { zeroX, didPrefixed, didZeroX } from '../../utils'
|
||||
import { InstantiableConfig } from '../../Instantiable.abstract'
|
||||
|
||||
export default class DIDRegistry extends ContractBase {
|
||||
@ -42,4 +42,24 @@ export default class DIDRegistry extends ContractBase {
|
||||
.map(({ returnValues }) => returnValues._did)
|
||||
.map(didPrefixed)
|
||||
}
|
||||
|
||||
public async getAttributesByDid(
|
||||
did: string
|
||||
): Promise<{ did: string; serviceEndpoint: string; checksum: string }> {
|
||||
return (await this.getPastEvents('DIDAttributeRegistered', {
|
||||
_did: didZeroX(did)
|
||||
})).map(
|
||||
({
|
||||
returnValues: {
|
||||
_did,
|
||||
_checksum: checksum,
|
||||
_value: serviceEndpoint
|
||||
}
|
||||
}) => ({
|
||||
did: didPrefixed(_did),
|
||||
serviceEndpoint,
|
||||
checksum
|
||||
})
|
||||
)[0]
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,10 @@ export default class DID {
|
||||
* @param {string} didString DID in string.
|
||||
* @return {DID}
|
||||
*/
|
||||
public static parse(didString: string): DID {
|
||||
public static parse(didString: string | DID): DID {
|
||||
if (didString instanceof DID) {
|
||||
didString = didString.getDid()
|
||||
}
|
||||
let did: DID
|
||||
const didMatch = didString.match(/^did:op:([a-f0-9]{64})$/i)
|
||||
|
||||
|
@ -53,8 +53,10 @@ export class OceanAssets extends Instantiable {
|
||||
* @return {Promise<DDO>}
|
||||
*/
|
||||
public async resolve(did: string): Promise<DDO> {
|
||||
const d: DID = DID.parse(did)
|
||||
return this.ocean.aquarius.retrieveDDO(d)
|
||||
const {
|
||||
serviceEndpoint
|
||||
} = await this.ocean.keeper.didRegistry.getAttributesByDid(did)
|
||||
return this.ocean.aquarius.retrieveDDOByUrl(serviceEndpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user