Skip to content

Commit ef05d92

Browse files
committed
Switch to stdlib
1 parent 28c6e37 commit ef05d92

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

keystore/kms/asn1.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,3 @@ func padTo32Bytes(buffer []byte) []byte {
240240

241241
return buffer
242242
}
243-
244-
// ASN1ToEd25519PublicKey extracts an Ed25519 public key from AWS KMS ASN.1 DER-encoded SPKI format.
245-
//
246-
// AWS KMS returns Ed25519 public keys in ASN.1 DER-encoded SubjectPublicKeyInfo (SPKI) format.
247-
// The actual Ed25519 public key is 32 bytes and is contained in the SubjectPublicKey BitString.
248-
func ASN1ToEd25519PublicKey(asn1PublicKey []byte) ([]byte, error) {
249-
var spki SPKI
250-
if _, err := asn1.Unmarshal(asn1PublicKey, &spki); err != nil {
251-
return nil, fmt.Errorf("failed to unmarshal ASN.1 public key: %w", err)
252-
}
253-
254-
// Ed25519 public keys are 32 bytes raw in the BitString
255-
pubKeyBytes := spki.SubjectPublicKey.Bytes
256-
if len(pubKeyBytes) != 32 {
257-
return nil, fmt.Errorf("invalid Ed25519 public key length in BitString: expected 32 bytes, got %d", len(pubKeyBytes))
258-
}
259-
260-
return pubKeyBytes, nil
261-
}

keystore/kms/keystore.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"github.com/aws/aws-sdk-go-v2/service/kms"
99
kmstypes "github.com/aws/aws-sdk-go-v2/service/kms/types"
1010

11+
"crypto/ed25519"
12+
"crypto/x509"
13+
1114
"github.com/smartcontractkit/chainlink-common/keystore"
1215
)
1316

@@ -89,10 +92,16 @@ func (k *keystoreSignerReader) GetKeys(ctx context.Context, req keystore.GetKeys
8992
return keystore.GetKeysResponse{}, fmt.Errorf("failed to convert public key for key %s: %w", keyID, err)
9093
}
9194
case keystore.Ed25519:
92-
publicKeyBytes, err = ASN1ToEd25519PublicKey(key.PublicKey)
95+
// ed25519 supported by standard libraries unlike secp256k1.
96+
pubKey, err := x509.ParsePKIXPublicKey(key.PublicKey)
9397
if err != nil {
9498
return keystore.GetKeysResponse{}, fmt.Errorf("failed to convert Ed25519 public key for key %s: %w", keyID, err)
9599
}
100+
ed25519PubKey, ok := pubKey.(ed25519.PublicKey)
101+
if !ok {
102+
return keystore.GetKeysResponse{}, fmt.Errorf("failed to convert Ed25519 public key for key %s to ed25519.PublicKey: %w", keyID, err)
103+
}
104+
publicKeyBytes = ed25519PubKey
96105
default:
97106
return keystore.GetKeysResponse{}, fmt.Errorf("unsupported key type: %s", keyType)
98107
}

0 commit comments

Comments
 (0)