Skip to content

Commit

Permalink
feat: hard code weight to 1000.0 and limit the algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
btspoony committed Oct 23, 2024
1 parent 3b43836 commit ea8630c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cadence/transactions/evm/create_new_account_with_coa.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@ import Crypto

import "EVM"

/// Creates a new Flow Address and EVM account with a Cadence Owned Account (COA) stored in the account's storage.
/// Creates a new Flow Address with a single full-weight key and its EVM account, which is
/// a Cadence Owned Account (COA) stored in the account's storage.
///
transaction(
key: String, // key to be used for the account
signatureAlgorithm: UInt8, // signature algorithm to be used for the account
hashAlgorithm: UInt8, // hash algorithm to be used for the account
weight: UFix64, // weight to be used for the account
) {
let auth: auth(Storage, Keys, Capabilities) &Account

prepare(signer: auth(Storage, Keys, Capabilities) &Account) {
pre {
signatureAlgorithm >= 1 && signatureAlgorithm <= 3:
signatureAlgorithm == 1 || signatureAlgorithm == 2:
"Cannot add Key: Must provide a signature algorithm raw value that corresponds to "
.concat("one of the available signature algorithms for Flow keys.")
.concat("You provided ").concat(signatureAlgorithm.toString())
.concat(" but the options are either 1 (ECDSA_P256), 2 (ECDSA_secp256k1), or 3 (BLS_BLS12_381).")
hashAlgorithm >= 1 && hashAlgorithm <= 6:
.concat(" but the options are either 1 (ECDSA_P256), 2 (ECDSA_secp256k1).")
hashAlgorithm == 1 || hashAlgorithm == 3:
"Cannot add Key: Must provide a hash algorithm raw value that corresponds to "
.concat("one of of the available hash algorithms for Flow keys.")
.concat("You provided ").concat(hashAlgorithm.toString())
.concat(" but the options are 1 (SHA2_256), 2 (SHA2_384), 3 (SHA3_256), ")
.concat("4 (SHA3_384), 5 (KMAC128_BLS_BLS12_381), or 6 (KECCAK_256).")
weight <= 1000.0:
"Cannot add Key: The key weight must be between 0 and 1000."
.concat(" You provided ").concat(weight.toString()).concat(" which is invalid.")
.concat(" but the options are 1 (SHA2_256), 3 (SHA3_256), ")
}

self.auth = signer
Expand All @@ -47,7 +43,7 @@ transaction(
account.keys.add(
publicKey: publicKey,
hashAlgorithm: HashAlgorithm(rawValue: hashAlgorithm)!,
weight: weight
weight: 1000.0
)

// Create a new COA
Expand Down

0 comments on commit ea8630c

Please sign in to comment.