Skip to content

Commit

Permalink
Add Amoy network as a part a core library
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Mar 28, 2024
1 parent 132cb2a commit 3cbcc94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
};
Expand All @@ -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
}
};
10 changes: 10 additions & 0 deletions tests/did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
];

Expand All @@ -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()
);
});
}
});
Expand Down

0 comments on commit 3cbcc94

Please sign in to comment.