mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
add in chain resolving
This commit is contained in:
parent
21fac92a88
commit
ec955060a2
@ -46,7 +46,17 @@ export default class DIDResolver {
|
||||
data = null
|
||||
break
|
||||
} else {
|
||||
didId = Web3.utils.toHex(data.value).substring(2)
|
||||
if ( data.value.match(/^[0-9a-fA-Fx]+/) ) {
|
||||
// get the hex value of the chain
|
||||
didId = Web3.utils.toHex("0x" + data.value.replace(/^0x/, "")).substring(2)
|
||||
} else if ( data.value.match(/^did:op/) ) {
|
||||
// if the DID value is another Ocean DID then get the id
|
||||
didId = DIDTools.didToId(data.value)
|
||||
} else {
|
||||
// check for unusall values in the 'DID' record, http, ftp, {xxx
|
||||
data = null
|
||||
break
|
||||
}
|
||||
data = await this.getDID(didId)
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,41 @@ describe("DIDResolver", () => {
|
||||
const didResolved = await didResolver.resolve(did)
|
||||
assert(didResolved)
|
||||
assert(didResolved.isURL())
|
||||
assert(didResolved.getValue() == testURL)
|
||||
|
||||
})
|
||||
it("should register chain of attributes and resolve", async () => {
|
||||
const didList: string[] = []
|
||||
const chainLength = 10
|
||||
const testURL = "http://localhost:5000"
|
||||
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
|
||||
|
||||
for ( let index = 0; index < chainLength; index ++ ) {
|
||||
let did = DIDTools.idToDID(IdGenerator.generateId())
|
||||
didList.push(did)
|
||||
}
|
||||
|
||||
for ( let index = 0; index < chainLength - 1; index ++ ) {
|
||||
let didId = DIDTools.didToId(didList[index])
|
||||
let nextDIDId = DIDTools.didToId(didList[index + 1])
|
||||
let receipt = await didRegistry.registerAttribute(didId, ValueType.DID, providerKey,
|
||||
nextDIDId, ownerAccount.getId())
|
||||
assert(receipt)
|
||||
}
|
||||
const didId = DIDTools.didToId(didList[didList.length - 1])
|
||||
const receipt = await didRegistry.registerAttribute(didId, ValueType.URL, providerKey,
|
||||
testURL, ownerAccount.getId())
|
||||
assert(receipt)
|
||||
|
||||
const didResolver = new DIDResolver(didRegistry)
|
||||
assert(didResolver)
|
||||
|
||||
// resolve from the first DID in the chain
|
||||
const didResolved = await didResolver.resolve(didList[0])
|
||||
assert(didResolved)
|
||||
assert(didResolved.isURL())
|
||||
assert(didResolved.getValue() == testURL)
|
||||
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user