diff --git a/src/registration.ts b/src/registration.ts index 71e488c..23dd2e5 100644 --- a/src/registration.ts +++ b/src/registration.ts @@ -150,16 +150,23 @@ export const registerDidMethodNetwork = ({ const key = `${blockchain}:${network}`; const existedFlag = DidMethodNetwork[method][key]; - if (typeof existedFlag === 'number' && existedFlag !== networkFlag) { - throw new Error( - `DID method network '${method}' with blockchain '${blockchain}' and network '${network}' already registered with another flag '${existedFlag.toString( - 2 - )}'` - ); - } - - if (Object.values(DidMethodNetwork[method]).includes(networkFlag)) { - throw new Error(`DID network flag ${DidMethodNetwork[method][key]} is already registered`); + if (typeof existedFlag === 'number') { + const isSameFlag = existedFlag === networkFlag; + if (!isSameFlag) { + throw new Error( + `DID method network '${method}' with blockchain '${blockchain}' and network '${network}' already registered with another flag '${existedFlag.toString( + 2 + )}'` + ); + } + } else { + if (Object.values(DidMethodNetwork[method]).includes(networkFlag)) { + throw new Error( + `DID network flag ${networkFlag.toString( + 2 + )} is already registered for the another for '${method}'` + ); + } } DidMethodNetwork[method][key] = networkFlag; }; diff --git a/tests/did.test.ts b/tests/did.test.ts index 580dd45..ab46e5f 100644 --- a/tests/did.test.ts +++ b/tests/did.test.ts @@ -317,7 +317,7 @@ describe('DID tests', () => { method: DidMethod.Iden3, blockchain: Blockchain.ReadOnly, network: 'network', - networkFlag: 0b01000000 | 0b00000011, + networkFlag: 0b11000000 | 0b00000011, chainId: 104 } }, @@ -436,7 +436,7 @@ describe('DID tests', () => { network: 'supa_net', networkFlag: 0b00010000 | 0b00000001 }, - err: 'DID network flag undefined is already registered' + err: `DID network flag 10001 is already registered for the another for 'iden3'` } ]; for (let i = 0; i < testCases.length; i++) {