diff --git a/Makefile b/Makefile index 83a42a4..5cc4f82 100755 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ run: clean ## test: runs unit and component tests test: @echo "Running unit tests..." - @go test -v -count=1 -race ./... $(go list ./... | grep -v internal/test) + @find . -name go.mod -execdir go test -v -count=1 -race ./... $(go list ./... | grep -v internal/test) \; ## vet: code analysis vet: diff --git a/go.mod b/go.mod index c74c672..15024b2 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,11 @@ module github.com/ark-network/ark go 1.21.0 +replace github.com/ark-network/ark/common => ./pkg/common + require github.com/sirupsen/logrus v1.9.3 -require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +require ( + github.com/stretchr/testify v1.8.0 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +) diff --git a/go.sum b/go.sum index 21f9bfb..199d0b8 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,14 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 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= diff --git a/pkg/common/bip68.go b/pkg/common/bip68.go index 94e656a..c5e496e 100644 --- a/pkg/common/bip68.go +++ b/pkg/common/bip68.go @@ -18,8 +18,8 @@ func closerToModulo512(x uint) uint { return x - (x % 512) } -// BIP68 returns the encoded sequence locktime for the given number of seconds. -func BIP68(seconds uint) ([]byte, error) { +// BIP68Encode returns the encoded sequence locktime for the given number of seconds. +func BIP68Encode(seconds uint) ([]byte, error) { seconds = closerToModulo512(seconds) if seconds > SECONDS_MAX { return nil, fmt.Errorf("seconds too large, max is %d", SECONDS_MAX) @@ -40,8 +40,7 @@ func BIP68(seconds uint) ([]byte, error) { return reversed, nil } -func DecodeBIP68(sequence []byte) (uint, error) { - // sequence to int +func BIP68Decode(sequence []byte) (uint, error) { var asNumber int64 for i := len(sequence) - 1; i >= 0; i-- { asNumber = asNumber<<8 | int64(sequence[i]) diff --git a/pkg/common/bip68_test.go b/pkg/common/bip68_test.go index 209ed25..1a4d63d 100644 --- a/pkg/common/bip68_test.go +++ b/pkg/common/bip68_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - sdk "github.com/ark-network/common" + sdk "github.com/ark-network/ark/common" "github.com/stretchr/testify/require" ) @@ -24,7 +24,7 @@ func TestBIP68(t *testing.T) { for _, tc := range testCases { t.Run(tc.Desc, func(t *testing.T) { - actual, err := sdk.BIP68(tc.Input) + actual, err := sdk.BIP68Encode(tc.Input) require.NoError(t, err) var asNumber int64 @@ -34,7 +34,7 @@ func TestBIP68(t *testing.T) { require.Equal(t, tc.Expected, asNumber) - decoded, err := sdk.DecodeBIP68(actual) + decoded, err := sdk.BIP68Decode(actual) require.NoError(t, err) require.Equal(t, tc.Input, decoded) diff --git a/pkg/common/encoding.go b/pkg/common/encoding.go index 56809c1..6e0d2a7 100644 --- a/pkg/common/encoding.go +++ b/pkg/common/encoding.go @@ -2,44 +2,235 @@ package common import ( "fmt" + "net/url" + "strings" "github.com/btcsuite/btcd/btcutil/bech32" "github.com/decred/dcrd/dcrec/secp256k1/v4" ) const ( - PubKeyPrefix = "arkpub" - SecKeyPrefix = "arksec" + ProtoKey = "ark" + RelayKey = "relays" + RelaySep = "-" ) -func EncodeSecKey(key *secp256k1.PrivateKey) (string, error) { - return bech32.Encode(SecKeyPrefix, key.Serialize()) -} - -func DecodeSecKey(key string) (*secp256k1.PrivateKey, error) { - prefix, buf, err := bech32.Decode(key) +func EncodeSecKey(hrp string, key *secp256k1.PrivateKey) (seckey string, err error) { + if key == nil { + return "", fmt.Errorf("missing secret key") + } + if hrp != MainNet.SecKey && hrp != TestNet.SecKey { + return "", fmt.Errorf("invalid prefix") + } + grp, err := bech32.ConvertBits(key.Serialize(), 8, 5, true) if err != nil { - return nil, err + return "", err } - if prefix != SecKeyPrefix { - return nil, fmt.Errorf("invalid prefix") - } - - return secp256k1.PrivKeyFromBytes(buf), nil + seckey, err = bech32.EncodeM(hrp, grp) + return } -func EncodePubKey(key *secp256k1.PublicKey) (string, error) { - return bech32.Encode(PubKeyPrefix, key.SerializeCompressed()) -} - -func DecodePubKey(key string) (*secp256k1.PublicKey, error) { - prefix, buf, err := bech32.Decode(key) +func DecodeSecKey(key string) (hrp string, seckey *secp256k1.PrivateKey, err error) { + prefix, buf, err := bech32.DecodeNoLimit(key) if err != nil { - return nil, err + err = fmt.Errorf("invalid secret key: %s", err) + return } - if prefix != PubKeyPrefix { - return nil, fmt.Errorf("invalid prefix") + if prefix != MainNet.SecKey && prefix != TestNet.SecKey { + err = fmt.Errorf("invalid prefix") + return } - - return secp256k1.ParsePubKey(buf) + grp, err := bech32.ConvertBits(buf, 5, 8, false) + if err != nil { + return + } + hrp = prefix + seckey = secp256k1.PrivKeyFromBytes(grp) + return +} + +func EncodePubKey(hrp string, key *secp256k1.PublicKey) (pubkey string, err error) { + if key == nil { + err = fmt.Errorf("missing public key") + return + } + if hrp != MainNet.PubKey && hrp != TestNet.PubKey { + err = fmt.Errorf("invalid prefix") + return + } + grp, err := bech32.ConvertBits(key.SerializeCompressed(), 8, 5, true) + if err != nil { + return + } + pubkey, err = bech32.EncodeM(hrp, grp) + return +} + +func DecodePubKey(key string) (hrp string, pubkey *secp256k1.PublicKey, err error) { + prefix, buf, err := bech32.DecodeNoLimit(key) + if err != nil { + return + } + if prefix != MainNet.PubKey && prefix != TestNet.PubKey { + err = fmt.Errorf("invalid prefix") + return + } + grp, err := bech32.ConvertBits(buf, 5, 8, false) + if err != nil { + return + } + if len(grp) < 32 { + err = fmt.Errorf("invalid public key length") + return + } + pubkey, err = secp256k1.ParsePubKey(grp) + if err != nil { + return + } + hrp = prefix + return +} + +func EncodeAddress(hrp string, userKey, aspKey *secp256k1.PublicKey) (addr string, err error) { + if userKey == nil { + err = fmt.Errorf("missing public key") + return + } + if aspKey == nil { + err = fmt.Errorf("missing asp public key") + return + } + if hrp != MainNet.Addr && hrp != TestNet.Addr { + err = fmt.Errorf("invalid prefix") + return + } + combinedKey := append(aspKey.SerializeCompressed(), userKey.SerializeCompressed()...) + grp, err := bech32.ConvertBits(combinedKey, 8, 5, true) + if err != nil { + return + } + addr, err = bech32.EncodeM(hrp, grp) + return +} + +func DecodeAddress(addr string) (hrp string, userKey *secp256k1.PublicKey, aspKey *secp256k1.PublicKey, err error) { + prefix, buf, err := bech32.DecodeNoLimit(addr) + if err != nil { + return + } + if prefix != MainNet.Addr && prefix != TestNet.Addr { + err = fmt.Errorf("invalid prefix") + return + } + grp, err := bech32.ConvertBits(buf, 5, 8, false) + if err != nil { + return + } + aKey, err := secp256k1.ParsePubKey(grp[:33]) + if err != nil { + err = fmt.Errorf("failed to parse public key: %s", err) + return + } + uKey, err := secp256k1.ParsePubKey(grp[33:]) + if err != nil { + err = fmt.Errorf("failed to parse asp public key: %s", err) + return + } + hrp = prefix + userKey = uKey + aspKey = aKey + return +} + +func EncodeRelayKey(hrp string, key *secp256k1.PublicKey) (pubkey string, err error) { + if key == nil { + err = fmt.Errorf("missing relay key") + return + } + if hrp != MainNet.RelayKey && hrp != TestNet.RelayKey { + err = fmt.Errorf("invalid prefix") + return + } + grp, err := bech32.ConvertBits(key.SerializeCompressed(), 8, 5, true) + if err != nil { + return + } + pubkey, err = bech32.EncodeM(hrp, grp) + return +} + +func DecodeRelayKey(key string) (hrp string, pubkey *secp256k1.PublicKey, err error) { + prefix, buf, err := bech32.DecodeNoLimit(key) + if err != nil { + return + } + if prefix != MainNet.RelayKey && prefix != TestNet.RelayKey { + err = fmt.Errorf("invalid prefix") + return + } + grp, err := bech32.ConvertBits(buf, 5, 8, false) + if err != nil { + return + } + if len(grp) < 32 { + err = fmt.Errorf("invalid public key length") + return + } + pubkey, err = secp256k1.ParsePubKey(grp) + if err != nil { + return + } + hrp = prefix + return +} + +func EncodeUrl(host string, relays ...string) (arkurl string, err error) { + _, _, err = DecodePubKey(host) + if err != nil { + err = fmt.Errorf("invalid public key: %s", err) + return + } + for _, r := range relays { + _, _, err = DecodeRelayKey(r) + if err != nil { + err = fmt.Errorf("invalid relay public key: %s", err) + return + } + } + u := url.URL{Scheme: ProtoKey, Host: host} + q := u.Query() + if len(relays) > 0 { + q.Add(RelayKey, strings.Join(relays, RelaySep)) + } + u.RawQuery = q.Encode() + arkurl = u.String() + return +} + +func DecodeUrl(arkurl string) (host string, relays []string, err error) { + u, err := url.Parse(arkurl) + if err != nil { + return + } + if u.Scheme != ProtoKey { + err = fmt.Errorf("invalid proto") + return + } + _, _, err = DecodePubKey(u.Host) + if err != nil { + err = fmt.Errorf("invalid public key: %s", err) + return + } + list := strings.Split(u.Query().Get(RelayKey), RelaySep) + for _, r := range list { + _, _, err = DecodeRelayKey(r) + if err != nil { + err = fmt.Errorf("invalid relay public key: %s", err) + return + } + } + host = u.Host + relays = make([]string, len(list)) + copy(relays, list) + return } diff --git a/pkg/common/encoding_test.go b/pkg/common/encoding_test.go new file mode 100644 index 0000000..295f0ef --- /dev/null +++ b/pkg/common/encoding_test.go @@ -0,0 +1,242 @@ +package common_test + +import ( + "encoding/hex" + "encoding/json" + "log" + "os" + "testing" + + common "github.com/ark-network/ark/common" + "github.com/stretchr/testify/require" +) + +var f []byte + +func init() { + var err error + f, err = os.ReadFile("fixtures/encoding.json") + if err != nil { + log.Fatal(err) + } +} + +func TestSecretKeyEncoding(t *testing.T) { + fixtures := struct { + SecretKey struct { + Valid []struct { + Key string `json:"key"` + Expected string `json:"expected"` + } `json:"valid"` + Invalid []struct { + Key string `json:"key"` + ExpectedError string `json:"expectedError"` + } `json:"invalid"` + } `json:"secretKey"` + }{} + err := json.Unmarshal(f, &fixtures) + require.NoError(t, err) + + t.Run("valid", func(t *testing.T) { + for _, f := range fixtures.SecretKey.Valid { + hrp, key, err := common.DecodeSecKey(f.Key) + require.NoError(t, err) + require.NotEmpty(t, hrp) + require.NotNil(t, key) + + keyHex := hex.EncodeToString(key.Serialize()) + require.Equal(t, f.Expected, keyHex) + + keyStr, err := common.EncodeSecKey(hrp, key) + require.NoError(t, err) + require.Equal(t, f.Key, keyStr) + } + }) + + t.Run("invalid", func(t *testing.T) { + for _, f := range fixtures.SecretKey.Invalid { + hrp, key, err := common.DecodeSecKey(f.Key) + require.EqualError(t, err, f.ExpectedError) + require.Empty(t, hrp) + require.Nil(t, key) + } + }) +} + +func TestPublicKeyEncoding(t *testing.T) { + fixtures := struct { + PublicKey struct { + Valid []struct { + Key string `json:"key"` + Expected string `json:"expected"` + } `json:"valid"` + Invalid []struct { + Key string `json:"key"` + ExpectedError string `json:"expectedError"` + } `json:"invalid"` + } `json:"publicKey"` + }{} + err := json.Unmarshal(f, &fixtures) + require.NoError(t, err) + + t.Run("valid", func(t *testing.T) { + for _, f := range fixtures.PublicKey.Valid { + hrp, key, err := common.DecodePubKey(f.Key) + require.NoError(t, err) + require.NotEmpty(t, hrp) + require.NotNil(t, key) + + keyHex := hex.EncodeToString(key.SerializeCompressed()) + require.Equal(t, f.Expected, keyHex) + + keyStr, err := common.EncodePubKey(hrp, key) + require.NoError(t, err) + require.Equal(t, f.Key, keyStr) + } + }) + + t.Run("invalid", func(t *testing.T) { + for _, f := range fixtures.PublicKey.Invalid { + hrp, key, err := common.DecodePubKey(f.Key) + require.EqualError(t, err, f.ExpectedError) + require.Empty(t, hrp) + require.Nil(t, key) + } + }) +} + +func TestAddressEncoding(t *testing.T) { + fixtures := struct { + Address struct { + Valid []struct { + Addr string `json:"addr"` + ExpectedUserKey string `json:"expectedUserKey"` + ExpectedAspKey string `json:"expectedAspKey"` + } `json:"valid"` + Invalid []struct { + Addr string `json:"addr"` + ExpectedError string `json:"expectedError"` + } `json:"invalid"` + } `json:"address"` + }{} + err := json.Unmarshal(f, &fixtures) + require.NoError(t, err) + + t.Run("valid", func(t *testing.T) { + for _, f := range fixtures.Address.Valid { + hrp, userKey, aspKey, err := common.DecodeAddress(f.Addr) + require.NoError(t, err) + require.NotEmpty(t, hrp) + require.NotNil(t, userKey) + require.NotNil(t, aspKey) + + userKeyStr, err := common.EncodePubKey(common.MainNet.PubKey, userKey) + require.NoError(t, err) + require.Equal(t, f.ExpectedUserKey, userKeyStr) + + aspKeyStr, err := common.EncodePubKey(common.MainNet.PubKey, aspKey) + require.NoError(t, err) + require.Equal(t, f.ExpectedAspKey, aspKeyStr) + + addr, err := common.EncodeAddress(hrp, userKey, aspKey) + require.NoError(t, err) + require.Equal(t, f.Addr, addr) + } + }) + + t.Run("invalid", func(t *testing.T) { + for _, f := range fixtures.Address.Invalid { + hrp, userKey, aspKey, err := common.DecodeAddress(f.Addr) + require.EqualError(t, err, f.ExpectedError) + require.Empty(t, hrp) + require.Nil(t, userKey) + require.Nil(t, aspKey) + } + }) +} + +func TestRelayKeyEncoding(t *testing.T) { + fixtures := struct { + RelayKey struct { + Valid []struct { + Key string `json:"key"` + Expected string `json:"expected"` + } `json:"valid"` + Invalid []struct { + Key string `json:"key"` + ExpectedError string `json:"expectedError"` + } `json:"invalid"` + } `json:"relayKey"` + }{} + err := json.Unmarshal(f, &fixtures) + require.NoError(t, err) + + t.Run("valid", func(t *testing.T) { + for _, f := range fixtures.RelayKey.Valid { + hrp, key, err := common.DecodeRelayKey(f.Key) + require.NoError(t, err) + require.NotEmpty(t, hrp) + require.NotNil(t, key) + + keyHex := hex.EncodeToString(key.SerializeCompressed()) + require.Equal(t, f.Expected, keyHex) + + keyStr, err := common.EncodeRelayKey(hrp, key) + require.NoError(t, err) + require.Equal(t, f.Key, keyStr) + } + }) + + t.Run("invalid", func(t *testing.T) { + for _, f := range fixtures.RelayKey.Invalid { + hrp, key, err := common.DecodeRelayKey(f.Key) + require.EqualError(t, err, f.ExpectedError) + require.Empty(t, hrp) + require.Nil(t, key) + } + }) +} + +func TestUrlEncoding(t *testing.T) { + fixtures := struct { + Url struct { + Valid []struct { + Url string `json:"url"` + ExpectedPubkey string `json:"expectedPubkey"` + ExpectedRelays []string `json:"expectedRelays"` + } `json:"valid"` + Invalid []struct { + Url string `json:"url"` + ExpectedError string `json:"expectedError"` + } `json:"invalid"` + } `json:"url"` + }{} + err := json.Unmarshal(f, &fixtures) + require.NoError(t, err) + + t.Run("valid", func(t *testing.T) { + for _, f := range fixtures.Url.Valid { + pubkey, relays, err := common.DecodeUrl(f.Url) + require.NoError(t, err) + require.NotEmpty(t, pubkey) + require.NotNil(t, relays) + + require.Equal(t, f.ExpectedPubkey, pubkey) + require.Exactly(t, relays, f.ExpectedRelays) + + url, err := common.EncodeUrl(pubkey, relays...) + require.NoError(t, err) + require.Equal(t, f.Url, url) + } + }) + + t.Run("invalid", func(t *testing.T) { + for _, f := range fixtures.Url.Invalid { + pubkey, relays, err := common.DecodeUrl(f.Url) + require.Error(t, err) + require.Contains(t, err.Error(), f.ExpectedError) + require.Empty(t, pubkey) + require.Nil(t, relays) + } + }) +} diff --git a/pkg/common/fixtures/encoding.json b/pkg/common/fixtures/encoding.json new file mode 100644 index 0000000..006e907 --- /dev/null +++ b/pkg/common/fixtures/encoding.json @@ -0,0 +1,85 @@ +{ + "secretKey": { + "valid": [ + { + "key": "asec1n9grggypds323l5fkw4t6kpf6trz26an8wv44qqr8ctp4t3dp52q5zkzz4", + "expected": "99503420816c22a8fe89b3aabd5829d2c6256bb33b995a80033e161aae2d0d14" + } + ], + "invalid": [ + { + "key": "wrongprefix1c02kjhr4egxvh0ajua0ylv9vl3kyegxmrl2djh4pn63m948ecs4qchx9zx", + "expectedError": "invalid prefix" + } + ] + }, + "publicKey": { + "valid": [ + { + "key": "apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x", + "expected": "0218d5ca8b58797b7dbd65c075dd7ba7784b3f38ab71b1a5a8e3f94ba0257654a6" + } + ], + "invalid": [ + { + "key": "wrongprefix1q0yn8cskp7lv0lxq3unfynmju68smh69lu90yyv37wzetu6upp76vg4ef6n", + "expectedError": "invalid prefix" + } + ] + }, + "address": { + "valid": [ + { + "addr": "ark1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22vqa7mdkrrulzu48law4zzvzz8k59hul0ayl2urt905we5wf6gee68sfrfj35", + "expectedUserKey": "apub1qwldkmp3703w2nl7h23pxpprm2zm70h7j04wp4jh68v68yayvuarcc28uv5", + "expectedAspKey": "apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x" + } + ], + "invalid": [ + { + "addr": "wrongprefix1qt9tfh7c09hlsstzq5y9tzuwyaesrwr8gpy8cn29cxv0flp64958s0n0yd0", + "expectedError": "invalid prefix" + } + ] + }, + "relayKey": { + "valid": [ + { + "key": "arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l", + "expected": "02f49387d7a274bdf92c50a8e4155011543995b9826eda7a31866bfb0c2b02da30" + } + ], + "invalid": [ + { + "key": "wrongprefix1q2g64uehct5zdkhdull6ultevfmuu62nzwucec6q8su85eqpezxdvsf2mfd", + "expectedError": "invalid prefix" + } + ] + }, + "url": { + "valid": [ + { + "url": "ark://apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x?relays=arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l-arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l", + "expectedPubkey": "apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x", + "expectedRelays": [ + "arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l", + "arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l" + ] + } + ], + "invalid": [ + { + "url": "wrong://apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x?relays=arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l-arelay1qt6f8p7h5f6tm7fv2z5wg92sz92rn9desfhd5733se4lkrptqtdrq65987l", + "expectedError": "invalid proto" + }, + { + "url": "ark://asec1n9grggypds323l5fkw4t6kpf6trz26an8wv44qqr8ctp4t3dp52qun9kjh", + "expectedError": "invalid public key" + }, + { + "url": "ark://apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x?relays=apub1qgvdtj5ttpuhkldavhq8thtm5auyk0ec4dcmrfdgu0u5hgp9we22v3hrs4x", + "expectedError": "invalid relay public key" + } + ] + } +} \ No newline at end of file diff --git a/pkg/common/go.mod b/pkg/common/go.mod index a039016..36b6497 100644 --- a/pkg/common/go.mod +++ b/pkg/common/go.mod @@ -1,4 +1,4 @@ -module github.com/ark-network/common +module github.com/ark-network/ark/common go 1.21.0 diff --git a/pkg/common/network.go b/pkg/common/network.go new file mode 100644 index 0000000..c79be78 --- /dev/null +++ b/pkg/common/network.go @@ -0,0 +1,25 @@ +package common + +type Network struct { + Name string + SecKey string + PubKey string + RelayKey string + Addr string +} + +var MainNet = Network{ + Name: "mainnet", + SecKey: "asec", + PubKey: "apub", + RelayKey: "arelay", + Addr: "ark", +} + +var TestNet = Network{ + Name: "testnet", + SecKey: "tasec", + PubKey: "tapub", + RelayKey: "tarelay", + Addr: "tark", +}