|
| 1 | +import { arc4, bytes, Ecdsa, ensureBudget, op, OpUpFeeSource, uint64, VrfVerify } from '@algorandfoundation/algorand-typescript' |
| 2 | + |
| 3 | +export class CryptoOpsContract extends arc4.Contract { |
| 4 | + @arc4.abimethod() |
| 5 | + public verify_sha256(a: bytes, pad_size: uint64): bytes { |
| 6 | + const paddedA = op.bzero(pad_size).concat(a) |
| 7 | + const result = op.sha256(paddedA) |
| 8 | + return result |
| 9 | + } |
| 10 | + |
| 11 | + @arc4.abimethod() |
| 12 | + public verify_sha3_256(a: bytes, pad_size: uint64): bytes { |
| 13 | + const paddedA = op.bzero(pad_size).concat(a) |
| 14 | + const result = op.sha3_256(paddedA) |
| 15 | + return result |
| 16 | + } |
| 17 | + |
| 18 | + @arc4.abimethod() |
| 19 | + public verify_keccak_256(a: bytes, pad_size: uint64): bytes { |
| 20 | + const paddedA = op.bzero(pad_size).concat(a) |
| 21 | + const result = op.keccak256(paddedA) |
| 22 | + return result |
| 23 | + } |
| 24 | + |
| 25 | + @arc4.abimethod() |
| 26 | + public verify_sha512_256(a: bytes, pad_size: uint64): bytes { |
| 27 | + const paddedA = op.bzero(pad_size).concat(a) |
| 28 | + const result = op.sha512_256(paddedA) |
| 29 | + return result |
| 30 | + } |
| 31 | + |
| 32 | + // TODO: return arc4.Bool to match python version when arc4 types are available |
| 33 | + @arc4.abimethod() |
| 34 | + public verify_ed25519verify(a: bytes, b: bytes, c: bytes): boolean { |
| 35 | + ensureBudget(1900, OpUpFeeSource.GroupCredit) |
| 36 | + const result = op.ed25519verify(a, b, c) |
| 37 | + return result |
| 38 | + } |
| 39 | + |
| 40 | + // TODO: return arc4.Bool to match python version when arc4 types are available |
| 41 | + @arc4.abimethod() |
| 42 | + public verify_ed25519verify_bare(a: bytes, b: bytes, c: bytes): boolean { |
| 43 | + ensureBudget(1900, OpUpFeeSource.GroupCredit) |
| 44 | + const result = op.ed25519verifyBare(a, b, c) |
| 45 | + return result |
| 46 | + } |
| 47 | + |
| 48 | + @arc4.abimethod() |
| 49 | + public verify_ecdsa_verify_k1(a: bytes, b: bytes, c: bytes, d: bytes, e: bytes): boolean { |
| 50 | + ensureBudget(3000, OpUpFeeSource.GroupCredit) |
| 51 | + const result_k1 = op.ecdsaVerify(Ecdsa.Secp256k1, a, b, c, d, e) |
| 52 | + return result_k1 |
| 53 | + } |
| 54 | + |
| 55 | + @arc4.abimethod() |
| 56 | + public verify_ecdsa_verify_r1(a: bytes, b: bytes, c: bytes, d: bytes, e: bytes): boolean { |
| 57 | + ensureBudget(3000, OpUpFeeSource.GroupCredit) |
| 58 | + const result_r1 = op.ecdsaVerify(Ecdsa.Secp256r1, a, b, c, d, e) |
| 59 | + return result_r1 |
| 60 | + } |
| 61 | + |
| 62 | + @arc4.abimethod() |
| 63 | + public verify_ecdsa_recover_k1(a: bytes, b: uint64, c: bytes, d: bytes): readonly [bytes, bytes] { |
| 64 | + ensureBudget(3000, OpUpFeeSource.GroupCredit) |
| 65 | + return op.ecdsaPkRecover(Ecdsa.Secp256k1, a, b, c, d) |
| 66 | + } |
| 67 | + |
| 68 | + @arc4.abimethod() |
| 69 | + public verify_ecdsa_recover_r1(a: bytes, b: uint64, c: bytes, d: bytes): readonly [bytes, bytes] { |
| 70 | + /** |
| 71 | + * Must fail, AVM does not support Secp256r1 for recover |
| 72 | + */ |
| 73 | + ensureBudget(3000, OpUpFeeSource.GroupCredit) |
| 74 | + return op.ecdsaPkRecover(Ecdsa.Secp256r1, a, b, c, d) |
| 75 | + } |
| 76 | + |
| 77 | + @arc4.abimethod() |
| 78 | + public verify_ecdsa_decompress_k1(a: bytes): readonly [bytes, bytes] { |
| 79 | + ensureBudget(700, OpUpFeeSource.GroupCredit) |
| 80 | + return op.ecdsaPkDecompress(Ecdsa.Secp256k1, a) |
| 81 | + } |
| 82 | + |
| 83 | + @arc4.abimethod() |
| 84 | + public verify_ecdsa_decompress_r1(a: bytes): readonly [bytes, bytes] { |
| 85 | + ensureBudget(700, OpUpFeeSource.GroupCredit) |
| 86 | + return op.ecdsaPkDecompress(Ecdsa.Secp256r1, a) |
| 87 | + } |
| 88 | + |
| 89 | + @arc4.abimethod() |
| 90 | + public verify_vrf_verify(a: bytes, b: bytes, c: bytes): readonly [bytes, boolean] { |
| 91 | + ensureBudget(5700, OpUpFeeSource.GroupCredit) |
| 92 | + const result = op.vrfVerify(VrfVerify.VrfAlgorand, a, b, c) |
| 93 | + return result |
| 94 | + } |
| 95 | +} |
0 commit comments