@sig-net/midnight 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,63 +0,0 @@
1
- // ============================================================================
2
- // Schnorr — shared Compact library: the off-chain-callable challenge circuit
3
- // for Schnorr signatures on the Jubjub curve embedded in BLS12-381.
4
- // ============================================================================
5
- // Verification itself is CompactStandardLibrary's `jubjubSchnorrVerify`
6
- // (contracts call it directly). The standard library keeps its challenge
7
- // hashing internal, but off-chain SIGNERS need the same challenge value to
8
- // compute the response scalar, so this module exports it as a pure circuit
9
- // (compiled via circuits.compact) — never a TS re-implementation.
10
- //
11
- // `SchnorrHashInput` mirrors the standard library's internal
12
- // `JubjubSchnorrHashInput` field-for-field; the signet-midnight sign→verify
13
- // round-trip test (schnorrSign + contract-side jubjubSchnorrVerify) keeps the
14
- // two in agreement.
15
- //
16
- // The sig-net MPC attests remote EVM execution by Schnorr-signing a message
17
- // on Jubjub (see signetAttestationMessage in Signet.compact); contracts
18
- // verify that signature in-circuit — the signet contract at post time, the
19
- // requester again at settle time. The challenge is Poseidon (transientHash), so
20
- // off-chain signers MUST compute it through the COMPILED schnorrChallenge
21
- // pure circuit (re-exported via circuits.compact).
22
- //
23
- // Import from a contract (resolved through node_modules via COMPACT_PATH —
24
- // see the consuming package's compile script):
25
- // import "@sig-net/midnight/src/Schnorr" prefix Schnorr_;
26
- //
27
- // This file must contain ONLY this module (plus comments) so the compiler
28
- // accepts it as an external module import.
29
-
30
- module Schnorr {
31
- import CompactStandardLibrary;
32
-
33
- // The tuple Poseidon-hashed into the challenge: both points' coordinates
34
- // then the message limbs, in exactly this order — the wire format the MPC
35
- // signs against (identical to the standard library's internal
36
- // JubjubSchnorrHashInput). Never reorder.
37
- struct SchnorrHashInput<#n> {
38
- ann_x: Field;
39
- ann_y: Field;
40
- pk_x: Field;
41
- pk_y: Field;
42
- msg: Vector<n, Field>;
43
- }
44
-
45
- // The Schnorr challenge as `jubjubSchnorrVerify` computes it: the Poseidon
46
- // transientHash of (R, pk, msg), reduced into Jubjub's scalar field (the
47
- // `as JubjubScalar` cast reduces mod the Jubjub subgroup order; the cast
48
- // back to Field is exact). Off-chain signers use the returned value
49
- // directly: s = (k + c * sk) mod JUBJUB_ORDER.
50
- export pure circuit schnorrChallenge(
51
- ann_x: Field,
52
- ann_y: Field,
53
- pk_x: Field,
54
- pk_y: Field,
55
- msg: Vector<4, Field>
56
- ): Field {
57
- const cFull: Field =
58
- transientHash<SchnorrHashInput<4>>(
59
- SchnorrHashInput<4> { ann_x: ann_x, ann_y: ann_y, pk_x: pk_x, pk_y: pk_y, msg: msg }
60
- );
61
- return (cFull as JubjubScalar) as Field;
62
- }
63
- }