templates: Add RemoveAccountKey template
@@ -88,7 +88,7 @@ transaction(publicKey: [UInt8]) {
}
`
-// AddAccountKey generates a transactions that adds a public key to an account.
+// AddAccountKey generates a transaction that adds a public key to an account.
func AddAccountKey(address flow.Address, accountKey *flow.AccountKey) *flow.Transaction {
cadencePublicKey := bytesToCadenceArray(accountKey.Encode())
@@ -98,6 +98,25 @@ func AddAccountKey(address flow.Address, accountKey *flow.AccountKey) *flow.Tran
AddAuthorizer(address)
}
+const removeAccountKey = `
+transaction(keyID: Int) {
+ prepare(signer: AuthAccount) {
+ signer.removePublicKey(keyID)
+ }
+}
+
+`
+
+// RemoveAccountKey generates a transaction that removes a key from an account.
+func RemoveAccountKey(address flow.Address, keyID int) *flow.Transaction {
+ cadenceKeyID := cadence.NewInt(keyID)
+
+ return flow.NewTransaction().
+ SetScript([]byte(addAccountKeyTemplate)).
+ AddRawArgument(jsoncdc.MustEncode(cadenceKeyID)).
+ AddAuthorizer(address)
+}
+
func bytesToCadenceArray(b []byte) cadence.Array {
values := make([]cadence.Value, len(b))
