From 482d12fe19ee9335bfb1a4f0c47491f17eea500a Mon Sep 17 00:00:00 2001 From: volodymyr-basiuk <31999965+volodymyr-basiuk@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:47:58 +0300 Subject: [PATCH] Add Amoy network as a part of a core library (#461) --- chain.go | 1 + did.go | 44 +++++++++++++++++++------------------------- did_test.go | 7 +++++++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/chain.go b/chain.go index ee938b3..cc885e4 100644 --- a/chain.go +++ b/chain.go @@ -29,6 +29,7 @@ var chainIDs = map[chainIDKey]ChainID{ {Ethereum, Sepolia}: 11155111, {Polygon, Main}: 137, {Polygon, Mumbai}: 80001, + {Polygon, Amoy}: 80002, {ZkEVM, Main}: 1101, {ZkEVM, Test}: 1442, } diff --git a/did.go b/did.go index ffb4e55..8d81c03 100644 --- a/did.go +++ b/did.go @@ -104,6 +104,8 @@ const ( Main NetworkID = "main" // Mumbai is polygon mumbai test network Mumbai NetworkID = "mumbai" + // Amoy is polygon amoy test network + Amoy NetworkID = "amoy" // Goerli is ethereum goerli test network Goerli NetworkID = "goerli" // goerli // Sepolia is ethereum Sepolia test network @@ -119,6 +121,7 @@ const ( var networks = map[NetworkID]NetworkID{ Main: Main, Mumbai: Mumbai, + Amoy: Amoy, Goerli: Goerli, Sepolia: Sepolia, Test: Test, @@ -179,36 +182,27 @@ type DIDNetworkFlag struct { NetworkID NetworkID } -// DIDMethodNetwork is map for did methods and their blockchain networks -var DIDMethodNetwork = map[DIDMethod]map[DIDNetworkFlag]byte{ - DIDMethodIden3: { - {Blockchain: ReadOnly, NetworkID: NoNetwork}: 0b00000000, - - {Blockchain: Polygon, NetworkID: Main}: 0b00010000 | 0b00000001, - {Blockchain: Polygon, NetworkID: Mumbai}: 0b00010000 | 0b00000010, +var blockchainNetworkMap = map[DIDNetworkFlag]byte{ + {Blockchain: ReadOnly, NetworkID: NoNetwork}: 0b0000_0000, - {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, - }, - DIDMethodPolygonID: { - {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: Polygon, NetworkID: Main}: 0b00010000 | 0b00000001, - {Blockchain: Polygon, NetworkID: Mumbai}: 0b00010000 | 0b00000010, + {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: Ethereum, NetworkID: Main}: 0b00100000 | 0b00000001, - {Blockchain: Ethereum, NetworkID: Goerli}: 0b00100000 | 0b00000010, - {Blockchain: Ethereum, NetworkID: Sepolia}: 0b00100000 | 0b00000011, + {Blockchain: ZkEVM, NetworkID: Main}: 0b0011_0000 | 0b0000_0001, + {Blockchain: ZkEVM, NetworkID: Test}: 0b0011_0000 | 0b0000_0010, +} - {Blockchain: ZkEVM, NetworkID: Main}: 0b00110000 | 0b00000001, - {Blockchain: ZkEVM, NetworkID: Test}: 0b00110000 | 0b00000010, - }, +// DIDMethodNetwork is map for did methods and their blockchain networks +var DIDMethodNetwork = map[DIDMethod]map[DIDNetworkFlag]byte{ + DIDMethodIden3: blockchainNetworkMap, + DIDMethodPolygonID: blockchainNetworkMap, DIDMethodOther: { - {Blockchain: UnknownChain, NetworkID: UnknownNetwork}: 0b11111111, + {Blockchain: UnknownChain, NetworkID: UnknownNetwork}: 0b1111_1111, }, } diff --git a/did_test.go b/did_test.go index 8bf6ded..95d7108 100644 --- a/did_test.go +++ b/did_test.go @@ -180,6 +180,13 @@ func TestDID_PolygonID_Types(t *testing.T) { net: Mumbai, wantDID: "did:polygonid:polygon:mumbai:2qCU58EJgrELNZCDkSU23dQHZsBgAFWLNpNezo1g6b", }, + { + title: "Polygon | Polygon chain, Amoy", + method: DIDMethodPolygonID, + chain: Polygon, + net: Amoy, + wantDID: "did:polygonid:polygon:amoy:2qQ68JkRcf3xrHPQPWZei3YeVzHPP58wYNxx2mEouR", + }, { title: "Polygon | zkEVM chain, main", method: DIDMethodPolygonID,