How to sign Ethereum EIP-1559 transactions using AWS KMS
Last updated
Last updated
func main() {
accessKey := "<access-key>"
secretKey := "<secret-key>"
sess, err := session.NewSession(&aws.Config{
Region: aws.String("<region>"),
Credentials: credentials.NewStaticCredentialsFromCreds(credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
}),
})
if err != nil {
panic(err)
}
svc := kms.New(sess)
}key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}import "encoding/asn1"
type asn1EcPublicKey struct {
EcPublicKeyInfo asn1EcPublicKeyInfo
PublicKey asn1.BitString
}
type asn1EcPublicKeyInfo struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.ObjectIdentifier
}
func main() {
// ...
key, err := svc.GetPublicKey(&kms.GetPublicKeyInput{
KeyId: aws.String("<key-id>"),
})
if err != nil {
panic(err)
}
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
}import "github.com/ethereum/go-ethereum/crypto"
var asn1Key asn1EcPublicKey
if _, err := asn1.Unmarshal(key.PublicKey, &asn1Key); err != nil {
panic(err)
}
log.Println(string(asn1Key.PublicKey.Bytes))
pubKey, err := crypto.UnmarshalPubkey(asn1Key.PublicKey.Bytes)
if err != nil {
panic(err)
}
log.Println(pubKey)
keyAddr := crypto.PubkeyToAddress(*pubKey)
log.Println(keyAddr.Hex())