+
Skip to content

feat: Add redbelly chains natively #468

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var chainIDs = map[chainIDKey]ChainID{
{Billions, Test}: 6913,
{Linea, Main}: 59144,
{Linea, Sepolia}: 59141,
{Redbelly, Mainnet}: 151,
{Redbelly, Testnet}: 153,
}

// ChainIDfromDID returns chain name from w3c.DID
Expand Down
21 changes: 21 additions & 0 deletions did.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ const (
DIDMethodIden3 DIDMethod = "iden3"
// DIDMethodPolygonID
DIDMethodPolygonID DIDMethod = "polygonid"
// DIDMethodReceptor
DIDMethodReceptor DIDMethod = "receptor"
// DIDMethodOther any other method not listed before
DIDMethodOther DIDMethod = ""
)

var didMethods = map[DIDMethod]DIDMethod{
DIDMethodIden3: DIDMethodIden3,
DIDMethodPolygonID: DIDMethodPolygonID,
DIDMethodReceptor: DIDMethodReceptor,
DIDMethodOther: DIDMethodOther,
}

Expand Down Expand Up @@ -68,6 +71,8 @@ const (
Billions Blockchain = "billions"
// Linea is Linea blockchain network
Linea Blockchain = "linea"
// Redbelly is Redbelly blockchain network
Redbelly Blockchain = "redbelly"
// 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 @@ -82,6 +87,7 @@ var blockchains = map[Blockchain]Blockchain{
Privado: Privado,
Billions: Billions,
Linea: Linea,
Redbelly: Redbelly,
UnknownChain: UnknownChain,
ReadOnly: ReadOnly,
NoChain: NoChain,
Expand Down Expand Up @@ -137,6 +143,14 @@ const (
Cardona NetworkID = "cardona"
)

// Redbelly-specific NetworkIDs
const (
// Mainnet is Redbelly mainnet
Mainnet NetworkID = "mainnet"
// Testnet is Redbelly testnet
Testnet NetworkID = "testnet"
)

var networks = map[NetworkID]NetworkID{
Main: Main,
Mumbai: Mumbai,
Expand All @@ -146,6 +160,8 @@ var networks = map[NetworkID]NetworkID{
Goerli: Goerli,
Sepolia: Sepolia,
Test: Test,
Mainnet: Mainnet,
Testnet: Testnet,
UnknownNetwork: UnknownNetwork,
NoNetwork: NoNetwork,
}
Expand All @@ -169,6 +185,7 @@ func RegisterNetwork(n NetworkID) error {
var DIDMethodByte = map[DIDMethod]byte{
DIDMethodIden3: 0b00000001,
DIDMethodPolygonID: 0b00000010,
DIDMethodReceptor: 0b10000011,
DIDMethodOther: 0b11111111,
}

Expand Down Expand Up @@ -224,12 +241,16 @@ var blockchainNetworkMap = map[DIDNetworkFlag]byte{

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

{Blockchain: Redbelly, NetworkID: Mainnet}: 0b01010111,
{Blockchain: Redbelly, NetworkID: Testnet}: 0b10000011,
}

// DIDMethodNetwork is map for did methods and their blockchain networks
var DIDMethodNetwork = map[DIDMethod]map[DIDNetworkFlag]byte{
DIDMethodIden3: blockchainNetworkMap,
DIDMethodPolygonID: blockchainNetworkMap,
DIDMethodReceptor: blockchainNetworkMap,
DIDMethodOther: {
{Blockchain: UnknownChain, NetworkID: UnknownNetwork}: 0b1111_1111,
},
Expand Down
14 changes: 14 additions & 0 deletions did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ func TestDID_Build_From_Types(t *testing.T) {
net: Sepolia,
wantDID: "did:iden3:linea:sepolia:28itzVLBHnMHocFAeArLFYHP59J7WN1s5JwL8yGpQw",
},
{
title: "Receptor | Redbelly, mainnet",
method: DIDMethodReceptor,
chain: Redbelly,
net: Mainnet,
wantDID: "did:receptor:redbelly:mainnet:31A9FG7T3SZpaoU7b77yRBXt682Y8Z6vK7PHhgrUAAB",
},
{
title: "Receptor | Redbelly, testnet",
method: DIDMethodReceptor,
chain: Redbelly,
net: Testnet,
wantDID: "did:receptor:redbelly:testnet:31Jxbg6JJG5xFqUbfEEFEKrDyBQsQHEgzN7JdBWRkCg",
},
}

for i := range testCases {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载