Skip to content

Commit 0271dd9

Browse files
committed
example
1 parent d6c46b0 commit 0271dd9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/examples/crypto/ecdsa/ecdsa.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createForeignCurve,
66
Bool,
77
Bytes,
8+
Hash,
89
} from 'o1js';
910

1011
export { keccakAndEcdsa, ecdsa, Secp256k1, Ecdsa, Bytes32, ecdsaEthers };
@@ -62,3 +63,24 @@ const ecdsaEthers = ZkProgram({
6263
},
6364
},
6465
});
66+
67+
/**
68+
* We can also use a different hash function with ECDSA, like SHA-256.
69+
*/
70+
const sha256AndEcdsa = ZkProgram({
71+
name: 'ecdsa',
72+
publicInput: Bytes32,
73+
publicOutput: Bool,
74+
75+
methods: {
76+
verifyEcdsa: {
77+
privateInputs: [Ecdsa, Secp256k1],
78+
async method(message: Bytes32, signature: Ecdsa, publicKey: Secp256k1) {
79+
let messageHash = Hash.SHA2_256.hash(message);
80+
return {
81+
publicOutput: signature.verifySignedHash(messageHash, publicKey),
82+
};
83+
},
84+
},
85+
},
86+
});

0 commit comments

Comments
 (0)