From 757e6884c34d8311306bd33c4661fd86df4f06e8 Mon Sep 17 00:00:00 2001 From: Bill Barman Date: Thu, 22 Nov 2018 19:01:36 +0800 Subject: [PATCH] better resolver logic --- src/utils/DIDResolver.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/DIDResolver.ts b/src/utils/DIDResolver.ts index 391972a..3734c4d 100644 --- a/src/utils/DIDResolver.ts +++ b/src/utils/DIDResolver.ts @@ -38,22 +38,25 @@ export default class DIDResolver { let data: DIDRecord = await this.getDID(didId) while ( data && (maxHopCount === 0 || resolved.hopCount() < maxHopCount) ) { resolved.addData(data) + didId = null if (data.valueType === "URL" || data.valueType === "DDO" ) { data = null break } else { - if ( data.value.match(/^[0-9a-fA-Fx]+/) ) { + if ( data.value.match(/^[0-9a-fA-FxX]+/) ) { // 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 + // somethings wrong with this value, so stop break } - data = await this.getDID(didId) + // only look if we have another id to find + if ( didId ) { + data = await this.getDID(didId) + } } } return resolved