From d2955e4689cb3b5f5cf4319b7487dcd307cffeaa Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 16 Sep 2024 17:40:57 +0200 Subject: [PATCH 1/2] use crypto/rand; add function get ChainID by core.ID (#466) --- chain.go | 6 +++++- claim_test.go | 16 +++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/chain.go b/chain.go index 9348786..37c4260 100644 --- a/chain.go +++ b/chain.go @@ -40,12 +40,16 @@ var chainIDs = map[chainIDKey]ChainID{ // ChainIDfromDID returns chain name from w3c.DID func ChainIDfromDID(did w3c.DID) (ChainID, error) { - id, err := IDFromDID(did) if err != nil { return 0, err } + return ChainIDfromID(id) +} + +// ChainIDfromID(id ID) returns chain name from ID +func ChainIDfromID(id ID) (ChainID, error) { blockchain, err := BlockchainFromID(id) if err != nil { return 0, err diff --git a/claim_test.go b/claim_test.go index 1ee64cd..7dcf1b0 100644 --- a/claim_test.go +++ b/claim_test.go @@ -2,12 +2,12 @@ package core import ( "bytes" + "crypto/rand" "encoding/hex" "encoding/json" "fmt" "math" "math/big" - "math/rand" "strings" "testing" "time" @@ -109,24 +109,24 @@ func TestClaim_GetFlagUpdatable(t *testing.T) { func TestClaim_GetVersion(t *testing.T) { var sc SchemaHash - ver := uint32(rand.Int63n(math.MaxUint32)) + ver := uint32(getRandomNumber(t, big.NewInt(math.MaxUint32))) claim, err := NewClaim(sc, WithVersion(ver)) require.NoError(t, err) require.Equal(t, ver, claim.GetVersion()) - ver2 := uint32(rand.Int63n(math.MaxUint32)) + ver2 := uint32(getRandomNumber(t, big.NewInt(math.MaxUint32))) claim.SetVersion(ver2) require.Equal(t, ver2, claim.GetVersion()) } func TestClaim_GetRevocationNonce(t *testing.T) { var sc SchemaHash - nonce := uint64(rand.Int63()) + nonce := uint64(getRandomNumber(t, big.NewInt(math.MaxInt64))) claim, err := NewClaim(sc, WithRevocationNonce(nonce)) require.NoError(t, err) require.Equal(t, nonce, claim.GetRevocationNonce()) - nonce2 := uint64(rand.Int63()) + nonce2 := uint64(getRandomNumber(t, big.NewInt(math.MaxInt64))) claim.SetRevocationNonce(nonce2) require.Equal(t, nonce2, claim.GetRevocationNonce()) } @@ -731,3 +731,9 @@ func TestNewSchemaHashFromInt(t *testing.T) { }) } } + +func getRandomNumber(t *testing.T, max *big.Int) int64 { + n, err := rand.Int(rand.Reader, max) + require.NoError(t, err) + return n.Int64() +} From 65e3ead5557ed81fef6ee4a3672e382e40732a91 Mon Sep 17 00:00:00 2001 From: David Rodriguez <70919589+daveroga@users.noreply.github.com> Date: Fri, 25 Apr 2025 14:01:59 +0200 Subject: [PATCH 2/2] Add Billions networks (#467) * add billions networks * update ubuntu version * update billions main chainid --- .github/workflows/lint.yaml | 2 +- .github/workflows/test.yaml | 2 +- chain.go | 2 ++ did.go | 6 ++++++ did_test.go | 14 ++++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 0226065..28fe214 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -8,7 +8,7 @@ on: jobs: lint: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c10f84..66efcb2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,7 +15,7 @@ jobs: - 1.19.13-bullseye - 1.20.13-bullseye - 1.21.6-bookworm - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest container: golang:${{matrix.containers}} steps: - uses: actions/checkout@v3 diff --git a/chain.go b/chain.go index 37c4260..838e30a 100644 --- a/chain.go +++ b/chain.go @@ -34,6 +34,8 @@ var chainIDs = map[chainIDKey]ChainID{ {Polygon, Cardona}: 2442, {Privado, Main}: 21000, {Privado, Test}: 21001, + {Billions, Main}: 45056, + {Billions, Test}: 6913, {Linea, Main}: 59144, {Linea, Sepolia}: 59141, } diff --git a/did.go b/did.go index ecbd53d..af02fd9 100644 --- a/did.go +++ b/did.go @@ -64,6 +64,8 @@ const ( Polygon Blockchain = "polygon" // Privado is Privado blockchain network Privado Blockchain = "privado" + // Billions is Billions blockchain network + Billions Blockchain = "billions" // Linea is Linea blockchain network Linea Blockchain = "linea" // UnknownChain is used when it's not possible to retrieve blockchain type from identifier @@ -78,6 +80,7 @@ var blockchains = map[Blockchain]Blockchain{ Ethereum: Ethereum, Polygon: Polygon, Privado: Privado, + Billions: Billions, Linea: Linea, UnknownChain: UnknownChain, ReadOnly: ReadOnly, @@ -216,6 +219,9 @@ var blockchainNetworkMap = map[DIDNetworkFlag]byte{ {Blockchain: Privado, NetworkID: Main}: 0b1010_0000 | 0b0000_0001, {Blockchain: Privado, NetworkID: Test}: 0b1010_0000 | 0b0000_0010, + {Blockchain: Billions, NetworkID: Main}: 0b1011_0000 | 0b0000_0001, + {Blockchain: Billions, NetworkID: Test}: 0b1011_0000 | 0b0000_0010, + {Blockchain: Linea, NetworkID: Main}: 0b0100_0000 | 0b0000_1001, {Blockchain: Linea, NetworkID: Sepolia}: 0b0100_0000 | 0b0000_1000, } diff --git a/did_test.go b/did_test.go index da9cae4..6d20ccc 100644 --- a/did_test.go +++ b/did_test.go @@ -215,6 +215,20 @@ func TestDID_Build_From_Types(t *testing.T) { net: Test, wantDID: "did:iden3:privado:test:2Skqvp4vnSFtq5bgAXbDs1Fs4AA5QGpRut9mCDew5R", }, + { + title: "Iden3 | Billions chain, main", + method: DIDMethodIden3, + chain: Billions, + net: Main, + wantDID: "did:iden3:billions:main:2VmAkXrihYaKzzVRkb3hoFRH3zdjibHXPK2Ahm3xBq", + }, + { + title: "Iden3 | Billions chain, test", + method: DIDMethodIden3, + chain: Billions, + net: Test, + wantDID: "did:iden3:billions:test:2VxnoiNqdMPxUigcPf9LTfZdz7jSwQv8YscTjjH5zf", + }, { title: "Iden3 | Linea, Main", method: DIDMethodIden3,