Skip to content
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
8 changes: 3 additions & 5 deletions address-codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ func EncodeSeed(entropy []byte, encodingType interfaces.CryptoImplementation) (s
return "", &EncodeLengthError{Instance: "Entropy", Input: len(entropy), Expected: FamilySeedLength}
}

if encodingType == crypto.ED25519() {
prefix := []byte{0x01, 0xe1, 0x4b}
return Encode(entropy, prefix, FamilySeedLength)
if ed25519 := crypto.ED25519(); encodingType == ed25519 {
return Encode(entropy, ed25519.FamilySeedPrefix(), FamilySeedLength)
} else if secp256k1 := crypto.SECP256K1(); encodingType == secp256k1 {
prefix := []byte{secp256k1.FamilySeedPrefix()}
return Encode(entropy, prefix, FamilySeedLength)
return Encode(entropy, secp256k1.FamilySeedPrefix(), FamilySeedLength)
}
return "", errors.New("encoding type must be `ed25519` or `secp256k1`")

Expand Down
10 changes: 5 additions & 5 deletions pkg/crypto/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const (
)

var (
_ Algorithm = &ED25519CryptoAlgorithm{}
_ Algorithm = &ED25519CryptoAlgorithm{}
ed25519FamilySeedPrefix = []byte{0x01, 0xe1, 0x4b}
)

// ED25519CryptoAlgorithm is the implementation of the ED25519 cryptographic algorithm.
type ED25519CryptoAlgorithm struct {
prefix byte
familySeedPrefix byte
prefix byte
}

// ED25519 returns the ED25519 cryptographic algorithm.
Expand All @@ -35,8 +35,8 @@ func (c ED25519CryptoAlgorithm) Prefix() byte {
}

// FamilySeedPrefix returns the family seed prefix for the ED25519 cryptographic algorithm.
func (c ED25519CryptoAlgorithm) FamilySeedPrefix() byte {
return c.familySeedPrefix
func (c ED25519CryptoAlgorithm) FamilySeedPrefix() []byte {
return ed25519FamilySeedPrefix
}

// DeriveKeypair derives a keypair from a seed.
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestED25519_Prefix(t *testing.T) {
}

func TestED25519_FamilySeedPrefix(t *testing.T) {
require.Zero(t, ED25519().FamilySeedPrefix())
require.Equal(t, ed25519FamilySeedPrefix, ED25519().FamilySeedPrefix())
}

func TestED25519DeriveKeypair(t *testing.T) {
Expand Down
14 changes: 6 additions & 8 deletions pkg/crypto/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ import (
const (
// SECP256K1 prefix - value is 0
secp256K1Prefix byte = 0x00
// SECP256K1 family seed prefix - value is 33
secp256K1FamilySeedPrefix byte = 0x21
)

var (
_ Algorithm = SECP256K1CryptoAlgorithm{}
// SECP256K1 family seed prefix - value is 33
secp256K1FamilySeedPrefix = []byte{0x21}
)

// SECP256K1CryptoAlgorithm is the implementation of the SECP256K1 algorithm.
type SECP256K1CryptoAlgorithm struct {
prefix byte
familySeedPrefix byte
prefix byte
}

// SECP256K1 returns a new SECP256K1CryptoAlgorithm instance.
func SECP256K1() SECP256K1CryptoAlgorithm {
return SECP256K1CryptoAlgorithm{
prefix: secp256K1Prefix,
familySeedPrefix: secp256K1FamilySeedPrefix,
prefix: secp256K1Prefix,
}
}

Expand All @@ -42,8 +40,8 @@ func (c SECP256K1CryptoAlgorithm) Prefix() byte {
}

// FamilySeedPrefix returns the family seed prefix for the SECP256K1 algorithm.
func (c SECP256K1CryptoAlgorithm) FamilySeedPrefix() byte {
return c.familySeedPrefix
func (c SECP256K1CryptoAlgorithm) FamilySeedPrefix() []byte {
return secp256K1FamilySeedPrefix
}

// deriveScalar derives a scalar from a seed.
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package crypto
// Algorithm defines the interface for cryptographic algorithms used in XRPL key generation and signing.
type Algorithm interface {
Prefix() byte
FamilySeedPrefix() byte
FamilySeedPrefix() []byte
}