Skip to content

Commit ec3ec2f

Browse files
authored
Merge pull request #24 from b-open-io/add-identity-key-to-key-deriver
feat: add identity key and identity key hex to KeyDeriver
2 parents a6ea0e8 + c579319 commit ec3ec2f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

wallet/key_deriver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ type KeyDeriver struct {
2525
rootKey *ec.PrivateKey
2626
}
2727

28+
func (kd *KeyDeriver) IdentityKey() *ec.PublicKey {
29+
return kd.rootKey.PubKey()
30+
}
31+
32+
func (kd *KeyDeriver) IdentityKeyHex() string {
33+
return kd.IdentityKey().ToDERHex()
34+
}
35+
2836
// NewKeyDeriver creates a new KeyDeriver instance with a root private key.
2937
// The root key can be either a specific private key or the special 'anyone' key.
3038
func NewKeyDeriver(privateKey *ec.PrivateKey) *KeyDeriver {

wallet/key_deriver_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ func TestKeyDeriver(t *testing.T) {
2727

2828
keyDeriver := NewKeyDeriver(rootPrivateKey)
2929

30+
t.Run("should return public key for root key as identity key", func(t *testing.T) {
31+
identityKey := keyDeriver.IdentityKey()
32+
assert.Equalf(t, rootPublicKey, identityKey, "identity key should match root public key")
33+
})
34+
35+
t.Run("should return DER HEX from public key for root key as identity key hex", func(t *testing.T) {
36+
identityKey := keyDeriver.IdentityKeyHex()
37+
assert.Equalf(t, rootPublicKey.ToDERHex(), identityKey, "identity key hex should match root public key hex")
38+
})
39+
3040
t.Run("should compute the correct invoice number", func(t *testing.T) {
3141
invoiceNumber, err := keyDeriver.computeInvoiceNumber(protocolID, keyID)
3242
assert.NoError(t, err, "computing invoice number should not error")

0 commit comments

Comments
 (0)