mirror of
https://github.com/aljazceru/ark.git
synced 2026-01-28 07:44:20 +01:00
Ark encoding (#6)
* Fix naming * Fix Ark key encoding & Add new encoding for address, relay and url * Fix submodule name * Fix test target * Update go deps * Fix prefixes && Use bech32m && Encode asp and user keys in address * Fix tests * Parametrize ark prefix && Add network params * Named return values
This commit is contained in:
committed by
GitHub
parent
13ff7c2d55
commit
19cbaeba40
@@ -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])
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
242
pkg/common/encoding_test.go
Normal file
242
pkg/common/encoding_test.go
Normal file
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
85
pkg/common/fixtures/encoding.json
Normal file
85
pkg/common/fixtures/encoding.json
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
module github.com/ark-network/common
|
||||
module github.com/ark-network/ark/common
|
||||
|
||||
go 1.21.0
|
||||
|
||||
|
||||
25
pkg/common/network.go
Normal file
25
pkg/common/network.go
Normal file
@@ -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",
|
||||
}
|
||||
Reference in New Issue
Block a user