-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/pickles-custom-gate-soundness
- Loading branch information
Showing
6 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
Circuit, | ||
circuitMain, | ||
public_, | ||
Crypto, | ||
createEcdsa, | ||
createForeignCurve, | ||
Bytes, | ||
assert, | ||
} from 'o1js'; | ||
|
||
export { Secp256k1, Ecdsa, Bytes32, Reserves }; | ||
|
||
class Secp256k1 extends createForeignCurve(Crypto.CurveParams.Secp256k1) {} | ||
class Ecdsa extends createEcdsa(Secp256k1) {} | ||
class Bytes32 extends Bytes(32) {} | ||
|
||
class Reserves extends Circuit { | ||
@circuitMain | ||
static main( | ||
@public_ message: Bytes32, | ||
signature: Ecdsa, | ||
publicKey: Secp256k1 | ||
) { | ||
assert(signature.verify(message, publicKey)); | ||
} | ||
} | ||
|
||
console.time('generateKeypair'); | ||
let kp = await Reserves.generateKeypair(); | ||
console.timeEnd('generateKeypair'); | ||
|
||
let message = Bytes32.random(); | ||
let privateKey = Secp256k1.Scalar.random(); | ||
let publicKey = Secp256k1.generator.scale(privateKey); | ||
let signature = Ecdsa.sign(message.toBytes(), privateKey.toBigInt()); | ||
|
||
console.time('prove'); | ||
let proof = await Reserves.prove([signature, publicKey], [message], kp); | ||
console.timeEnd('prove'); | ||
|
||
console.time('verify'); | ||
let isValid = await Reserves.verify([message], kp.verificationKey(), proof); | ||
assert(isValid, 'verifies'); | ||
console.timeEnd('verify'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters