diff --git a/src/constants.ts b/src/constants.ts index 2eb4df7..e49eae7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -54,6 +54,7 @@ export const Blockchain: { [k: string]: string } = { export const NetworkId: { [k: string]: string } = { Main: 'main', Mumbai: 'mumbai', + Amoy: 'amoy', Goerli: 'goerli', Sepolia: 'sepolia', Test: 'test', @@ -77,6 +78,7 @@ export const ChainIds: { [key: string]: number } = { [`${Blockchain.Ethereum}:${NetworkId.Sepolia}`]: 11155111, [`${Blockchain.Polygon}:${NetworkId.Main}`]: 137, [`${Blockchain.Polygon}:${NetworkId.Mumbai}`]: 80001, + [`${Blockchain.Polygon}:${NetworkId.Amoy}`]: 80002, [`${Blockchain.ZkEVM}:${NetworkId.Main}`]: 1101, [`${Blockchain.ZkEVM}:${NetworkId.Test}`]: 1442 }; @@ -87,31 +89,29 @@ export const DidMethodByte: { [key: string]: number } = { [DidMethod.Other]: 0b11111111 }; +const blockchainNetworkMap = { + [`${Blockchain.ReadOnly}:${NetworkId.NoNetwork}`]: 0b00000000, + [`${Blockchain.Polygon}:${NetworkId.Main}`]: 0b0001_0000 | 0b0000_0001, + [`${Blockchain.Polygon}:${NetworkId.Mumbai}`]: 0b0001_0000 | 0b0000_0010, + [`${Blockchain.Polygon}:${NetworkId.Amoy}`]: 0b0001_0000 | 0b0000_0011, + [`${Blockchain.Ethereum}:${NetworkId.Main}`]: 0b0010_0000 | 0b0000_0001, + [`${Blockchain.Ethereum}:${NetworkId.Goerli}`]: 0b0010_0000 | 0b0000_0010, + [`${Blockchain.Ethereum}:${NetworkId.Sepolia}`]: 0b0010_0000 | 0b0000_0011, + [`${Blockchain.ZkEVM}:${NetworkId.Main}`]: 0b0011_0000 | 0b0000_0001, + [`${Blockchain.ZkEVM}:${NetworkId.Test}`]: 0b0011_0000 | 0b0000_0010 +}; + // DIDMethodNetwork is map for did methods and their blockchain networks export const DidMethodNetwork: { [k: string]: { [k: string]: number }; } = { [DidMethod.Iden3]: { - [`${Blockchain.ReadOnly}:${NetworkId.NoNetwork}`]: 0b00000000, - [`${Blockchain.Polygon}:${NetworkId.Main}`]: 0b00010000 | 0b00000001, - [`${Blockchain.Polygon}:${NetworkId.Mumbai}`]: 0b00010000 | 0b00000010, - [`${Blockchain.Ethereum}:${NetworkId.Main}`]: 0b00100000 | 0b00000001, - [`${Blockchain.Ethereum}:${NetworkId.Goerli}`]: 0b00100000 | 0b00000010, - [`${Blockchain.Ethereum}:${NetworkId.Sepolia}`]: 0b00100000 | 0b00000011, - [`${Blockchain.ZkEVM}:${NetworkId.Main}`]: 0b00110000 | 0b00000001, - [`${Blockchain.ZkEVM}:${NetworkId.Test}`]: 0b00110000 | 0b00000010 + ...blockchainNetworkMap }, [DidMethod.PolygonId]: { - [`${Blockchain.ReadOnly}:${NetworkId.NoNetwork}`]: 0b00000000, - [`${Blockchain.Polygon}:${NetworkId.Main}`]: 0b00010000 | 0b00000001, - [`${Blockchain.Polygon}:${NetworkId.Mumbai}`]: 0b00010000 | 0b00000010, - [`${Blockchain.Ethereum}:${NetworkId.Main}`]: 0b00100000 | 0b00000001, - [`${Blockchain.Ethereum}:${NetworkId.Goerli}`]: 0b00100000 | 0b00000010, - [`${Blockchain.Ethereum}:${NetworkId.Sepolia}`]: 0b00100000 | 0b00000011, - [`${Blockchain.ZkEVM}:${NetworkId.Main}`]: 0b00110000 | 0b00000001, - [`${Blockchain.ZkEVM}:${NetworkId.Test}`]: 0b00110000 | 0b00000010 + ...blockchainNetworkMap }, [DidMethod.Other]: { - [`${Blockchain.Unknown}:${NetworkId.Unknown}`]: 0b11111111 + [`${Blockchain.Unknown}:${NetworkId.Unknown}`]: 0b1111_1111 } }; diff --git a/tests/did.test.ts b/tests/did.test.ts index 7b6c4c7..195830d 100644 --- a/tests/did.test.ts +++ b/tests/did.test.ts @@ -133,6 +133,13 @@ describe('DID tests', () => { chain: Blockchain.ZkEVM, net: NetworkId.Test, wantDID: 'did:polygonid:zkevm:test:2wcMpvr8NgWTfqN6ChaFEx1qRnLREXhjeoJ45pFyw5' + }, + { + title: 'Polygon | zkEVM chain, test', + method: DidMethod.PolygonId, + chain: Blockchain.Polygon, + net: NetworkId.Amoy, + wantDID: 'did:polygonid:polygon:amoy:2qQ68JkRcf3xrHPQPWZei3YeVzHPP58wYNxx2mEouR' } ]; @@ -149,6 +156,9 @@ describe('DID tests', () => { const networkID = DID.networkIdFromId(id); expect(tc.net).toEqual(networkID); expect(tc.wantDID).toEqual(did.string()); + expect(DID.idFromDID(DID.parse(tc.wantDID)).string()).toEqual( + did.string().split(':').pop() + ); }); } });