github.com/DapperCollectives/CAST/backend@v0.0.0-20230921221157-1350c8be7c96/main/cadence/scripts/validate_signature.cdc (about) 1 import Crypto 2 3 pub fun main( 4 address: Address, 5 keyIds: [Int], 6 signatures: [String], 7 message: String, 8 domainSeparationTag: String 9 ): Bool { 10 let keyList = Crypto.KeyList() 11 12 let account = getAccount(address) 13 let keys = account.keys 14 let messageBytes = message.decodeHex() 15 var i = 0 16 var totalWeight = 0.0 17 while i < keyIds.length { 18 if let key = keys.get(keyIndex: keyIds[i]) { 19 let signature = signatures[i] 20 let signatureBytes = signature.decodeHex() 21 if key.isRevoked { 22 // do not check revoked keys 23 i = i + 1 24 continue 25 } 26 let pk = PublicKey( 27 publicKey: key.publicKey.publicKey, 28 signatureAlgorithm: key.publicKey.signatureAlgorithm 29 ) 30 if pk.verify( 31 signature: signatureBytes, 32 signedData: messageBytes, 33 domainSeparationTag: domainSeparationTag, 34 hashAlgorithm: key.hashAlgorithm 35 ) { 36 // this key is good, add weight to total weight 37 totalWeight = totalWeight + key.weight 38 if totalWeight >= 999.0 { 39 return true 40 } 41 } 42 } else { 43 // checked all the keys, none of them match 44 return false 45 } 46 i = i + 1 47 } 48 return false 49 }