Skip to content

Commit

Permalink
rm libp2p peer & crypto uses
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Dec 11, 2023
1 parent bf600dd commit 56fa023
Show file tree
Hide file tree
Showing 36 changed files with 160 additions and 271 deletions.
4 changes: 1 addition & 3 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/uuid"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
p2ppeer "github.com/libp2p/go-libp2p/core/peer"
"github.com/manyminds/api2go/jsonapi"
"github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -141,11 +140,10 @@ func init() {
fmt.Printf("[gin] %-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
}

defaultP2PPeerID, err := p2ppeer.Decode(configtest.DefaultPeerID)
err := DefaultP2PPeerID.UnmarshalString(configtest.DefaultPeerID)
if err != nil {
panic(err)
}
DefaultP2PPeerID = p2pkey.PeerID(defaultP2PPeerID)
}

func NewRandomPositiveInt64() int64 {
Expand Down
6 changes: 3 additions & 3 deletions core/internal/cltest/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
p2ppeer "github.com/libp2p/go-libp2p/core/peer"
ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types"
"github.com/stretchr/testify/require"
"github.com/urfave/cli"
"gopkg.in/guregu/null.v4"
Expand Down Expand Up @@ -55,8 +55,8 @@ func NewEIP55Address() ethkey.EIP55Address {
return e
}

func NewPeerID() p2ppeer.ID {
id, err := p2ppeer.Decode("12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw")
func NewPeerID() (id ragep2ptypes.PeerID) {
err := id.UnmarshalText([]byte("12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw"))
if err != nil {
panic(err)
}
Expand Down
12 changes: 0 additions & 12 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ require (
github.com/huandu/skiplist v1.2.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -195,15 +194,13 @@ require (
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.32.1 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -212,13 +209,6 @@ require (
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.12.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down Expand Up @@ -256,7 +246,6 @@ require (
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/wsrpc v0.7.2 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down Expand Up @@ -322,7 +311,6 @@ require (
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Expand Down
22 changes: 0 additions & 22 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
github.com/iris-contrib/jade v1.1.3/go.mod h1:H/geBymxJhShH5kecoiOCSssPX7QWYH7UaeZTSWddIk=
Expand Down Expand Up @@ -887,8 +885,6 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-libp2p v0.32.1 h1:wy1J4kZIZxOaej6NveTWCZmHiJ/kY7GoAqXgqNCnPps=
github.com/libp2p/go-libp2p v0.32.1/go.mod h1:hXXC3kXPlBZ1eu8Q2hptGrMB4mZ3048JUoS4EKaHW5c=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
Expand Down Expand Up @@ -940,8 +936,6 @@ github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 h1:QRUSJEgZn2Snx0Em
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand Down Expand Up @@ -977,20 +971,6 @@ 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/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs=
github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns=
github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE=
github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI=
github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0=
github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
github.com/multiformats/go-multiaddr v0.12.0 h1:1QlibTFkoXJuDjjYsMHhE73TnzJQl8FSWatk/0gxGzE=
github.com/multiformats/go-multiaddr v0.12.0/go.mod h1:WmZXgObOQOYp9r3cslLlppkrz1FYSHmE834dfz/lWu8=
github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg=
github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
Expand Down Expand Up @@ -1945,8 +1925,6 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo=
lukechampine.com/uint128 v1.3.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.41.0 h1:QoR1Sn3YWlmA1T4vLaKZfawdVtSiGx8H+cEojbC7v1Q=
Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/cosmoskey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (key Key) ToEncryptedJSON(password string, scryptParams utils.ScryptParams)
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
func(id string, key Key, cryptoJSON keystore.CryptoJSON) keys.EncryptedKeyExport {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: hex.EncodeToString(key.PublicKey().Bytes()),
Crypto: cryptoJSON,
}, nil
}
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/csakey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (k KeyV2) ToEncryptedJSON(password string, scryptParams utils.ScryptParams)
password,
scryptParams,
adulteratedPassword,
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) keys.EncryptedKeyExport {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.PublicKeyString(),
Crypto: cryptoJSON,
}, nil
}
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/dkgencryptkey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func (k Key) ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
func(id string, key Key, cryptoJSON keystore.CryptoJSON) keys.EncryptedKeyExport {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.PublicKeyString(),
Crypto: cryptoJSON,
}, nil
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/dkgsignkey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func (key Key) ToEncryptedJSON(password string, scryptParams utils.ScryptParams)
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
func(id string, key Key, cryptoJSON keystore.CryptoJSON) keys.EncryptedKeyExport {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.PublicKeyString(),
Crypto: cryptoJSON,
}, nil
}
},
)
}
Expand Down
9 changes: 3 additions & 6 deletions core/services/keystore/keys/exportutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keys
import (
"encoding/json"

keystore "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand Down Expand Up @@ -62,7 +62,7 @@ func ToEncryptedJSON[E Encrypted, K any](
password string,
scryptParams utils.ScryptParams,
passwordFunc func(string) string,
buildExport func(id string, key K, cryptoJSON keystore.CryptoJSON) (E, error),
buildExport func(id string, key K, cryptoJSON keystore.CryptoJSON) E,
) (export []byte, err error) {

// encrypt data using prefixed password
Expand All @@ -77,10 +77,7 @@ func ToEncryptedJSON[E Encrypted, K any](
}

// build [E] export struct using encrypted key, identifier, and original key [K]
encryptedKeyExport, err := buildExport(identifier, key, cryptoJSON)
if err != nil {
return nil, errors.Wrapf(err, "could not build encrypted export for %s key", identifier)
}
encryptedKeyExport := buildExport(identifier, key, cryptoJSON)

return json.Marshal(encryptedKeyExport)
}
4 changes: 2 additions & 2 deletions core/services/keystore/keys/ocr2key/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ToEncryptedJSON(key KeyBundle, password string, scryptParams utils.ScryptPa
password,
scryptParams,
adulteratedPassword,
func(id string, key KeyBundle, cryptoJSON keystore.CryptoJSON) (EncryptedOCRKeyExport, error) {
func(id string, key KeyBundle, cryptoJSON keystore.CryptoJSON) EncryptedOCRKeyExport {
pubKeyConfig := key.ConfigEncryptionPublicKey()
pubKey := key.OffchainPublicKey()
return EncryptedOCRKeyExport{
Expand All @@ -77,7 +77,7 @@ func ToEncryptedJSON(key KeyBundle, password string, scryptParams utils.ScryptPa
OffChainPublicKey: hex.EncodeToString(pubKey[:]),
ConfigPublicKey: hex.EncodeToString(pubKeyConfig[:]),
Crypto: cryptoJSON,
}, nil
}
},
)
}
4 changes: 2 additions & 2 deletions core/services/keystore/keys/ocrkey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (key KeyV2) ToEncryptedJSON(password string, scryptParams utils.ScryptParam
password,
scryptParams,
adulteratedPassword,
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) (EncryptedOCRKeyExport, error) {
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) EncryptedOCRKeyExport {
return EncryptedOCRKeyExport{
KeyType: id,
ID: key.ID(),
OnChainSigningAddress: key.OnChainSigning.Address(),
OffChainPublicKey: key.OffChainSigning.PublicKey(),
ConfigPublicKey: key.PublicKeyConfig(),
Crypto: cryptoJSON,
}, nil
}
},
)
}
Expand Down
12 changes: 3 additions & 9 deletions core/services/keystore/keys/p2pkey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package p2pkey

import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys"
"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand Down Expand Up @@ -42,17 +40,13 @@ func (key KeyV2) ToEncryptedJSON(password string, scryptParams utils.ScryptParam
password,
scryptParams,
adulteratedPassword,
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) (EncryptedP2PKeyExport, error) {
rawPubKey, err := key.GetPublic().Raw()
if err != nil {
return EncryptedP2PKeyExport{}, errors.Wrapf(err, "could not get raw public key")
}
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) EncryptedP2PKeyExport {
return EncryptedP2PKeyExport{
KeyType: id,
PublicKey: hexutil.Encode(rawPubKey),
PublicKey: key.PublicKeyHex(),
PeerID: key.PeerID(),
Crypto: cryptoJSON,
}, nil
}
},
)
}
Expand Down
24 changes: 13 additions & 11 deletions core/services/keystore/keys/p2pkey/key.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package p2pkey

import (
"crypto/ed25519"
"database/sql/driver"
"encoding/hex"
"encoding/json"
"strconv"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
cryptop2p "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"

ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types"
)

// Key represents a libp2p private key
// Key represents a p2p private key
type Key struct {
cryptop2p.PrivKey
PrivKey ed25519.PrivateKey
}

func (k Key) ToV2() KeyV2 {
Expand All @@ -25,7 +26,7 @@ func (k Key) ToV2() KeyV2 {
}
}

// PublicKeyBytes is generated using cryptop2p.PubKey.Raw()
// PublicKeyBytes is a [ed25519.PublicKey]
type PublicKeyBytes []byte

func (pkb PublicKeyBytes) String() string {
Expand All @@ -47,7 +48,7 @@ func (pkb *PublicKeyBytes) UnmarshalJSON(input []byte) error {
return err
}

*pkb = PublicKeyBytes(result)
*pkb = result
return nil
}

Expand All @@ -66,19 +67,19 @@ func (pkb PublicKeyBytes) Value() (driver.Value, error) {
}

func (k Key) GetPeerID() (PeerID, error) {
peerID, err := peer.IDFromPrivateKey(k)
peerID, err := ragep2ptypes.PeerIDFromPrivateKey(k.PrivKey)
if err != nil {
return "", errors.WithStack(err)
return PeerID{}, errors.WithStack(err)
}
return PeerID(peerID), err
}

func (k Key) PeerID() PeerID {
peerID, err := peer.IDFromPrivateKey(k)
peerID, err := k.GetPeerID()
if err != nil {
panic(err)
}
return PeerID(peerID)
return peerID
}

type EncryptedP2PKey struct {
Expand Down Expand Up @@ -113,7 +114,8 @@ func (ep2pk EncryptedP2PKey) Decrypt(auth string) (k Key, err error) {
if err != nil {
return k, errors.Wrapf(err, "could not decrypt P2P key %s (0x%x)", ep2pk.PeerID.String(), ep2pk.PubKey)
}
privK, err := cryptop2p.UnmarshalPrivateKey(marshalledPrivK)

privK, err := UnmarshalPrivateKey(marshalledPrivK)
if err != nil {
return k, errors.Wrapf(err, "could not unmarshal P2P private key for %s (0x%x)", ep2pk.PeerID.String(), ep2pk.PubKey)
}
Expand Down
Loading

0 comments on commit 56fa023

Please sign in to comment.