Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move zkEVM in DID from blockchain level to network level. Add Linea #464

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ var chainIDs = map[chainIDKey]ChainID{
{Polygon, Main}: 137,
{Polygon, Mumbai}: 80001,
{Polygon, Amoy}: 80002,
{ZkEVM, Main}: 1101,
{ZkEVM, Test}: 1442,
{Polygon, Zkevm}: 1101,
{Polygon, Cardona}: 1442,
{Privado, Main}: 21000,
{Privado, Test}: 21001,
{Linea, Main}: 59144,
{Linea, Sepolia}: 59141,
}

// ChainIDfromDID returns chain name from w3c.DID
Expand Down
51 changes: 34 additions & 17 deletions did.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ const (
Ethereum Blockchain = "eth"
// Polygon is polygon blockchain network
Polygon Blockchain = "polygon"
// ZkEVM is zkEVM blockchain network
ZkEVM Blockchain = "zkevm"
// Privado is Privado blockchain network
Privado Blockchain = "privado"
// Linea is Linea blockchain network
Linea Blockchain = "linea"
// UnknownChain is used when it's not possible to retrieve blockchain type from identifier
UnknownChain Blockchain = "unknown"
// ReadOnly should be used for readonly identity to build readonly flag
Expand All @@ -77,8 +77,8 @@ const (
var blockchains = map[Blockchain]Blockchain{
Ethereum: Ethereum,
Polygon: Polygon,
ZkEVM: ZkEVM,
Privado: Privado,
Linea: Linea,
UnknownChain: UnknownChain,
ReadOnly: ReadOnly,
NoChain: NoChain,
Expand All @@ -102,17 +102,10 @@ func RegisterBlockchain(b Blockchain) error {
// NetworkID is method specific network identifier
type NetworkID string

// Generic NetworkIDs
const (
// Main is main network
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
Sepolia NetworkID = "sepolia"
// Test is test network
Test NetworkID = "test"
// UnknownNetwork is used when it's not possible to retrieve network from identifier
Expand All @@ -121,10 +114,32 @@ const (
NoNetwork NetworkID = ""
)

// Ethereum-specific NetworkIDs
const (
// Goerli is Ethereum goerli test network
Goerli NetworkID = "goerli"
// Sepolia is Ethereum Sepolia test network
Sepolia NetworkID = "sepolia"
)

// Polygon-specific NetworkIDs
const (
// Mumbai is Polygon mumbai test network
Mumbai NetworkID = "mumbai"
// Amoy is Polygon amoy test network
Amoy NetworkID = "amoy"
// Zkevm is zkEVM network in Polygon and potentially other blockchains
Zkevm NetworkID = "zkevm"
// Cardona is Polygon zkEVM Cardona test network
Cardona NetworkID = "cardona"
)

var networks = map[NetworkID]NetworkID{
Main: Main,
Mumbai: Mumbai,
Amoy: Amoy,
Zkevm: Zkevm,
Cardona: Cardona,
Goerli: Goerli,
Sepolia: Sepolia,
Test: Test,
Expand Down Expand Up @@ -188,19 +203,21 @@ type DIDNetworkFlag struct {
var blockchainNetworkMap = map[DIDNetworkFlag]byte{
{Blockchain: ReadOnly, NetworkID: NoNetwork}: 0b0000_0000,

{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}: 0b0001_0000 | 0b0000_0001,
{Blockchain: Polygon, NetworkID: Mumbai}: 0b0001_0000 | 0b0000_0010,
{Blockchain: Polygon, NetworkID: Amoy}: 0b0001_0000 | 0b0000_0011,
{Blockchain: Polygon, NetworkID: Zkevm}: 0b0001_0000 | 0b0000_0100,
{Blockchain: Polygon, NetworkID: Cardona}: 0b0001_0000 | 0b0000_0101,

{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,

{Blockchain: Privado, NetworkID: Main}: 0b1010_0000 | 0b0000_0001,
{Blockchain: Privado, NetworkID: Test}: 0b1010_0000 | 0b0000_0010,

{Blockchain: Linea, NetworkID: Main}: 0b0100_0000 | 0b0000_1001,
{Blockchain: Linea, NetworkID: Sepolia}: 0b0100_0000 | 0b0000_1000,
}

// DIDMethodNetwork is map for did methods and their blockchain networks
Expand Down
34 changes: 24 additions & 10 deletions did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,18 @@ func TestDID_Build_From_Types(t *testing.T) {
wantDID: "did:polygonid:polygon:amoy:2qQ68JkRcf3xrHPQPWZei3YeVzHPP58wYNxx2mEouR",
},
{
title: "Polygon | zkEVM chain, main",
method: DIDMethodPolygonID,
chain: ZkEVM,
net: Main,
wantDID: "did:polygonid:zkevm:main:2wQjmkL1SsgqC7AuZdUcaXsUVfEi1i58VEhm3r2r8F",
title: "Iden3 | Polygon chain, zkEVM chain, main",
method: DIDMethodIden3,
chain: Polygon,
net: Zkevm,
wantDID: "did:iden3:polygon:zkevm:xJa94Ky3oeawnDdQVoTotncYnBA1fCLW6C4NZVpRu",
},
{
title: "Polygon | zkEVM chain, test",
method: DIDMethodPolygonID,
chain: ZkEVM,
net: Test,
wantDID: "did:polygonid:zkevm:test:2wcMpvr8NgWTfqN6ChaFEx1qRnLREXhjeoJ45pFyw5",
title: "Iden3 | Polygon chain, zkEVM Cardona test",
method: DIDMethodIden3,
chain: Polygon,
net: Cardona,
wantDID: "did:iden3:polygon:cardona:xWCCEr5ycUDRWQp3Zu6UJvyUuGsEUpwfenMQXixEj",
},
{
title: "Iden3 | Privado chain, main",
Expand All @@ -215,6 +215,20 @@ func TestDID_Build_From_Types(t *testing.T) {
net: Test,
wantDID: "did:iden3:privado:test:2Skqvp4vnSFtq5bgAXbDs1Fs4AA5QGpRut9mCDew5R",
},
{
title: "Iden3 | Linea, Main",
method: DIDMethodIden3,
chain: Linea,
net: Main,
wantDID: "did:iden3:linea:main:28vX3frJDbAvHLSMHEwxuxRk1GPpjBeUEsXdAwVxDm",
},
{
title: "Iden3 | Linea, Sepolia",
method: DIDMethodIden3,
chain: Linea,
net: Sepolia,
wantDID: "did:iden3:linea:sepolia:28itzVLBHnMHocFAeArLFYHP59J7WN1s5JwL8yGpQw",
},
}

for i := range testCases {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/iden3/go-iden3-core/v2
go 1.18

require (
github.com/iden3/go-iden3-crypto v0.0.15
github.com/iden3/go-iden3-crypto v0.0.17
github.com/mr-tron/base58 v1.2.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
15 changes: 4 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4=
github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/iden3/go-iden3-crypto v0.0.17 h1:NdkceRLJo/pI4UpcjVah4lN/a3yzxRUGXqxbWcYh9mY=
github.com/iden3/go-iden3-crypto v0.0.17/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading