@sig-net/midnight 0.0.5 → 0.0.7

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.
Files changed (58) hide show
  1. package/README.md +8 -0
  2. package/dist/constants.d.ts +4 -16
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +4 -16
  5. package/dist/constants.js.map +1 -1
  6. package/dist/ecdsa-attestation.d.ts +79 -0
  7. package/dist/ecdsa-attestation.d.ts.map +1 -0
  8. package/dist/ecdsa-attestation.js +140 -0
  9. package/dist/ecdsa-attestation.js.map +1 -0
  10. package/dist/epsilon-derivation.d.ts +60 -0
  11. package/dist/epsilon-derivation.d.ts.map +1 -1
  12. package/dist/epsilon-derivation.js +106 -5
  13. package/dist/epsilon-derivation.js.map +1 -1
  14. package/dist/index.d.ts +9 -7
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +9 -7
  17. package/dist/index.js.map +1 -1
  18. package/dist/managed/compiler/contract-info.json +70 -95
  19. package/dist/managed/compiler/contract-manifest.json +8 -8
  20. package/dist/managed/contract/index.d.ts +38 -42
  21. package/dist/managed/contract/index.js +225 -478
  22. package/dist/managed/contract/index.js.map +2 -2
  23. package/dist/signature-requests-state-reader.d.ts +14 -13
  24. package/dist/signature-requests-state-reader.d.ts.map +1 -1
  25. package/dist/signature-requests-state-reader.js +31 -20
  26. package/dist/signature-requests-state-reader.js.map +1 -1
  27. package/dist/signature-response-verification.d.ts +5 -5
  28. package/dist/signature-response-verification.d.ts.map +1 -1
  29. package/dist/signature-response-verification.js +4 -4
  30. package/dist/signature-response-verification.js.map +1 -1
  31. package/dist/signet-contract-state-reader.d.ts +102 -109
  32. package/dist/signet-contract-state-reader.d.ts.map +1 -1
  33. package/dist/signet-contract-state-reader.js +125 -119
  34. package/dist/signet-contract-state-reader.js.map +1 -1
  35. package/dist/signet-request-feed.d.ts +4 -3
  36. package/dist/signet-request-feed.d.ts.map +1 -1
  37. package/dist/signet-request-feed.js +9 -8
  38. package/dist/signet-request-feed.js.map +1 -1
  39. package/dist/signet-request-resolver.d.ts +6 -4
  40. package/dist/signet-request-resolver.d.ts.map +1 -1
  41. package/dist/signet-request-resolver.js +8 -6
  42. package/dist/signet-request-resolver.js.map +1 -1
  43. package/dist/signet-request-response-reader.d.ts +21 -20
  44. package/dist/signet-request-response-reader.d.ts.map +1 -1
  45. package/dist/signet-request-response-reader.js +35 -23
  46. package/dist/signet-request-response-reader.js.map +1 -1
  47. package/dist/signet-requests.d.ts +93 -59
  48. package/dist/signet-requests.d.ts.map +1 -1
  49. package/dist/signet-requests.js +84 -67
  50. package/dist/signet-requests.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/Signet.compact +275 -413
  53. package/src/circuits.compact +24 -25
  54. package/dist/schnorr.d.ts +0 -100
  55. package/dist/schnorr.d.ts.map +0 -1
  56. package/dist/schnorr.js +0 -144
  57. package/dist/schnorr.js.map +0 -1
  58. package/src/Schnorr.compact +0 -63
@@ -1,39 +1,38 @@
1
1
  pragma language_version >= 0.25;
2
2
 
3
- // Compiled export surface of the Signet and Schnorr modules.
3
+ // Compiled export surface of the Signet module.
4
4
  //
5
- // Signet.compact / Schnorr.compact must stay module-only files (that is what
6
- // lets contracts import them), but a bare module compiles to nothing. This
7
- // contract-less program re-exports the modules' pure circuits so the compiler
8
- // emits them as pureCircuits in managed/contract/index.js — giving the
9
- // package an in-process, provable-logic-identical reference implementation:
10
- // unit tests exercise the REAL circuits, and off-chain code (path checks,
11
- // Schnorr challenges, attestation messages, notification packing) reuses them
5
+ // Signet.compact must stay a module-only file (that is what lets contracts
6
+ // import it), but a bare module compiles to nothing. This contract-less
7
+ // program re-exports the module's pure circuits so the compiler emits them as
8
+ // pureCircuits in managed/contract/index.js, giving the package an
9
+ // in-process, provable-logic-identical reference implementation: unit tests
10
+ // exercise the REAL circuits, and off-chain code (the attestation digest,
11
+ // response verification, key-pin hashing, notification packing) reuses them
12
12
  // instead of hand-porting the algorithms. Off-chain code only ever DECODES a
13
- // SignBidirectionalNotification (fixed-offset byte reads), but tests build
14
- // fixtures with the compiled packer to pin the pack<->decode lockstep.
13
+ // SignBidirectionalEventNotification (fixed-offset byte reads), but tests
14
+ // build fixtures with the compiled packer to pin the pack<->decode lockstep.
15
15
  //
16
16
  // ONLY the non-generic circuits are exported here. The request circuits
17
- // (calculateRequestId, constructSignBidirectionalRequest) are generic over the
18
- // tx-params type, the compiler cannot export type-parameterized circuits from
19
- // the top level, and this package is client-agnostic — a capacity
20
- // instantiation is a CLIENT contract's choice and never belongs here.
21
- // constructSignBidirectionalRequest is contract-only, so it needs no off-chain
22
- // copy; calculateRequestId IS needed off-chain (clients recompute ledger map
23
- // keys), so it alone has a documented-deviation TS twin in signet-requests.ts,
24
- // kept honest by caller-contract's submitSignatureRequest round-trip test.
17
+ // (calculateRequestId, constructSignBidirectionalEvent) are generic over the
18
+ // tx-params type and schema lengths, the compiler cannot export
19
+ // type-parameterized circuits from the top level, and this package is
20
+ // client-agnostic: a capacity instantiation is a CLIENT contract's choice and
21
+ // never belongs here. constructSignBidirectionalEvent is contract-only, so it
22
+ // needs no off-chain copy. calculateRequestId IS needed off-chain (clients
23
+ // recompute ledger map keys), so it alone has a documented-deviation TS twin
24
+ // in signet-requests.ts, kept honest by caller-contract's
25
+ // submitSignatureRequest round-trip test.
25
26
  //
26
27
  // Compile with --skip-zk only: pure circuits run in TS without proving keys.
28
+ // The secp256k1 types require the --feature-zkir-v3 compiler flag.
27
29
 
28
30
  import CompactStandardLibrary;
29
31
  import "./Signet";
30
- import "./Schnorr";
31
32
 
32
33
  export {
33
- signetAttestationMessage,
34
- assertHexOf,
35
- assertPathCommitment,
36
- constructSignBidirectionalNotificationV1,
37
- evmAddressAbiValue,
38
- schnorrChallenge
34
+ signetAttestationDigest,
35
+ verifyRespondBidirectionalEvent,
36
+ signetKeyHash,
37
+ constructSignBidirectionalEventNotificationV1
39
38
  };
package/dist/schnorr.d.ts DELETED
@@ -1,100 +0,0 @@
1
- import { type JubjubPoint } from "@midnight-ntwrk/compact-runtime";
2
- export type { JubjubPoint } from "@midnight-ntwrk/compact-runtime";
3
- /** Jubjub curve scalar field order (group order of the generator). */
4
- export declare const JUBJUB_ORDER = 6554484396890773809930967563523245729705921265872317281365359162392183254199n;
5
- /** BLS12-381 scalar field order (the Compact `Field` type modulus). */
6
- export declare const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
7
- /**
8
- * Convert little-endian bytes to a bigint. Matches Compact's
9
- * `Bytes<32> as Field` interpretation (and the MPC monitor's ABI-word
10
- * decoding convention).
11
- *
12
- * @param bytes - Little-endian byte array.
13
- * @returns The decoded non-negative integer.
14
- */
15
- export declare function bytesToBigint(bytes: Uint8Array): bigint;
16
- /**
17
- * Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
18
- * `Field as Bytes<32>` encoding (the inverse of {@link bytesToBigint});
19
- * negative inputs are interpreted in the BLS scalar field.
20
- *
21
- * @param n - The integer to encode.
22
- * @returns The 32-byte little-endian encoding.
23
- */
24
- export declare function bigintToBytes32(n: bigint): Uint8Array;
25
- /** A Jubjub keypair: the secret scalar and its public curve point. */
26
- export interface JubjubKeypair {
27
- /** Secret scalar in `[1, JUBJUB_ORDER - 1]`. */
28
- sk: bigint;
29
- /** Public key: `sk * G` on Jubjub. */
30
- pk: JubjubPoint;
31
- }
32
- /**
33
- * Derive a Jubjub keypair from a seed — the same derivation the MPC server
34
- * performs on its root key, so this MUST stay bit-identical to it:
35
- * `sk = (persistentHash([pad32("jubjub:auth:"), seed]) mod (order - 1)) + 1`,
36
- * `pk = sk * G`.
37
- *
38
- * @param seed - Seed bytes (e.g. the 32-byte MPC root key).
39
- * @returns The derived {@link JubjubKeypair}.
40
- */
41
- export declare function deriveJubjubKeypair(seed: Uint8Array): JubjubKeypair;
42
- /**
43
- * A Schnorr signature (TS twin of CompactStandardLibrary's
44
- * `JubjubSchnorrSignature`).
45
- */
46
- export interface SchnorrSignature {
47
- /** Nonce commitment R = k * G. */
48
- announcement: JubjubPoint;
49
- /** Signature scalar s = (k + c * sk) mod JUBJUB_ORDER. */
50
- response: bigint;
51
- }
52
- /**
53
- * Computes the Schnorr challenge (the Poseidon transientHash output reduced
54
- * into Jubjub's scalar field, exactly as `jubjubSchnorrVerify` computes it).
55
- * ALWAYS inject the compiled circuit — signet-midnight's own
56
- * `pureCircuits.schnorrChallenge` — never a TS re-implementation; keeping it
57
- * injected keeps this signer decoupled from any one compiled artifact.
58
- */
59
- export type SchnorrChallengeFn = (annX: bigint, annY: bigint, pkX: bigint, pkY: bigint, msg: bigint[]) => bigint;
60
- /**
61
- * Sign a message with Schnorr on Jubjub, matching CompactStandardLibrary's
62
- * `jubjubSchnorrVerify`: `c = challenge` (already reduced into Jubjub's
63
- * scalar field by the compiled circuit), `s = (k + c * sk) mod JUBJUB_ORDER`.
64
- * For signet attestations the message is the compiled
65
- * `pureCircuits.signetAttestationMessage(requestId, outputData)`.
66
- *
67
- * @param sk - Jubjub private key scalar.
68
- * @param msg - Message field limbs.
69
- * @param schnorrChallenge - The compiled `pureCircuits.schnorrChallenge`.
70
- * @returns The signature (announcement R, response s).
71
- * @throws Error if `sk` reduces to zero mod the Jubjub order.
72
- */
73
- export declare function schnorrSign(sk: bigint, msg: bigint[], schnorrChallenge: SchnorrChallengeFn): SchnorrSignature;
74
- /**
75
- * Hash a Jubjub point exactly as the circuits do (`persistentHash<JubjubPoint>`)
76
- * — the form the signet contract seals as `mpcPubKeyHash`.
77
- *
78
- * @param point - The point to hash.
79
- * @returns The 32-byte hash.
80
- */
81
- export declare function hashJubjubPoint(point: JubjubPoint): Uint8Array;
82
- /**
83
- * Parse a Jubjub public key from its `"x,y"` config/env form (decimal or
84
- * 0x-hex field coordinates) — how deploys receive `MPC_JUBJUB_PK`.
85
- *
86
- * @param value - The `"x,y"` string.
87
- * @returns The parsed point.
88
- * @throws Error if the value is not two comma-separated field coordinates.
89
- */
90
- export declare function parseJubjubPublicKey(value: string): JubjubPoint;
91
- /**
92
- * Format a Jubjub public key as the `"x,y"` decimal config/env form that
93
- * {@link parseJubjubPublicKey} accepts — the round-trip inverse, for handing
94
- * a derived key to deploys as `MPC_JUBJUB_PK`.
95
- *
96
- * @param point - The point to format.
97
- * @returns The `"x,y"` string with decimal coordinates.
98
- */
99
- export declare function formatJubjubPublicKey(point: JubjubPoint): string;
100
- //# sourceMappingURL=schnorr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schnorr.d.ts","sourceRoot":"","sources":["../src/schnorr.ts"],"names":[],"mappings":"AAiBA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AAKzC,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,sEAAsE;AACtE,eAAO,MAAM,YAAY,gFAAgF,CAAC;AAE1G,uEAAuE;AACvE,eAAO,MAAM,SAAS,iFAAiF,CAAC;AAKxG;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAQrD;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,EAAE,EAAE,WAAW,CAAC;CACjB;AASD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAKnE;AAID;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,YAAY,EAAE,WAAW,CAAC;IAC1B,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EAAE,KACV,MAAM,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EAAE,EACb,gBAAgB,EAAE,kBAAkB,GACnC,gBAAgB,CAgBlB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAE9D;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAU/D;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAEhE"}
package/dist/schnorr.js DELETED
@@ -1,144 +0,0 @@
1
- // Jubjub Schnorr helpers — the TS side of the shared Schnorr.compact module:
2
- // key derivation, SIGNING (which needs the secret scalar, so it cannot be a
3
- // circuit), and key parsing/hashing. Everything provable stays in Compact:
4
- // the challenge is the COMPILED `pureCircuits.schnorrChallenge`, injected by
5
- // callers (see SchnorrChallengeFn), and the attestation message is the
6
- // compiled `pureCircuits.signetAttestationMessage` — this file never
7
- // re-implements either. Verification lives in circuits only
8
- // (CompactStandardLibrary's jubjubSchnorrVerify, run by the signet contract
9
- // at post time).
10
- //
11
- // This belongs in github.com/sig-net/signet.js as its Midnight adapter —
12
- // kept here until upstreamed. The math is Midnight-specific (Jubjub embedded
13
- // in BLS12-381 via @midnight-ntwrk/compact-runtime EC ops), which is exactly
14
- // why signet.js does not cover it today.
15
- import { randomBytes } from "node:crypto";
16
- import { CompactTypeBytes, CompactTypeJubjubPoint, CompactTypeVector, ecMulGenerator, persistentHash, } from "@midnight-ntwrk/compact-runtime";
17
- /** Jubjub curve scalar field order (group order of the generator). */
18
- export const JUBJUB_ORDER = 6554484396890773809930967563523245729705921265872317281365359162392183254199n;
19
- /** BLS12-381 scalar field order (the Compact `Field` type modulus). */
20
- export const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
21
- const bytes32Type = new CompactTypeBytes(32);
22
- const vec2x32Type = new CompactTypeVector(2, bytes32Type);
23
- /**
24
- * Convert little-endian bytes to a bigint. Matches Compact's
25
- * `Bytes<32> as Field` interpretation (and the MPC monitor's ABI-word
26
- * decoding convention).
27
- *
28
- * @param bytes - Little-endian byte array.
29
- * @returns The decoded non-negative integer.
30
- */
31
- export function bytesToBigint(bytes) {
32
- let result = 0n;
33
- for (let i = bytes.length - 1; i >= 0; i--) {
34
- result = (result << 8n) | BigInt(bytes[i]);
35
- }
36
- return result;
37
- }
38
- /**
39
- * Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
40
- * `Field as Bytes<32>` encoding (the inverse of {@link bytesToBigint});
41
- * negative inputs are interpreted in the BLS scalar field.
42
- *
43
- * @param n - The integer to encode.
44
- * @returns The 32-byte little-endian encoding.
45
- */
46
- export function bigintToBytes32(n) {
47
- const buf = new Uint8Array(32);
48
- let v = n < 0n ? n + BLS_ORDER : n;
49
- for (let i = 0; i < 32; i++) {
50
- buf[i] = Number(v & 0xffn);
51
- v >>= 8n;
52
- }
53
- return buf;
54
- }
55
- /** Zero-pad an ASCII domain tag to 32 bytes (Compact `pad(32, ...)`). */
56
- function pad32(tag) {
57
- const padded = new Uint8Array(32);
58
- new TextEncoder().encodeInto(tag, padded);
59
- return padded;
60
- }
61
- /**
62
- * Derive a Jubjub keypair from a seed — the same derivation the MPC server
63
- * performs on its root key, so this MUST stay bit-identical to it:
64
- * `sk = (persistentHash([pad32("jubjub:auth:"), seed]) mod (order - 1)) + 1`,
65
- * `pk = sk * G`.
66
- *
67
- * @param seed - Seed bytes (e.g. the 32-byte MPC root key).
68
- * @returns The derived {@link JubjubKeypair}.
69
- */
70
- export function deriveJubjubKeypair(seed) {
71
- const skBytes = persistentHash(vec2x32Type, [pad32("jubjub:auth:"), seed]);
72
- const sk = (bytesToBigint(skBytes) % (JUBJUB_ORDER - 1n)) + 1n;
73
- const pk = ecMulGenerator(sk);
74
- return { sk, pk };
75
- }
76
- /**
77
- * Sign a message with Schnorr on Jubjub, matching CompactStandardLibrary's
78
- * `jubjubSchnorrVerify`: `c = challenge` (already reduced into Jubjub's
79
- * scalar field by the compiled circuit), `s = (k + c * sk) mod JUBJUB_ORDER`.
80
- * For signet attestations the message is the compiled
81
- * `pureCircuits.signetAttestationMessage(requestId, outputData)`.
82
- *
83
- * @param sk - Jubjub private key scalar.
84
- * @param msg - Message field limbs.
85
- * @param schnorrChallenge - The compiled `pureCircuits.schnorrChallenge`.
86
- * @returns The signature (announcement R, response s).
87
- * @throws Error if `sk` reduces to zero mod the Jubjub order.
88
- */
89
- export function schnorrSign(sk, msg, schnorrChallenge) {
90
- const skReduced = ((sk % JUBJUB_ORDER) + JUBJUB_ORDER) % JUBJUB_ORDER;
91
- if (skReduced === 0n) {
92
- throw new Error("Private key must be non-zero mod JUBJUB_ORDER");
93
- }
94
- const pk = ecMulGenerator(skReduced);
95
- const k = (bytesToBigint(randomBytes(32)) % JUBJUB_ORDER) || 1n;
96
- const announcement = ecMulGenerator(k);
97
- // schnorrChallenge returns the challenge already reduced into Jubjub's
98
- // scalar field — use it as-is.
99
- const c = schnorrChallenge(announcement.x, announcement.y, pk.x, pk.y, msg);
100
- const response = (((k + c * skReduced) % JUBJUB_ORDER) + JUBJUB_ORDER) % JUBJUB_ORDER;
101
- return { announcement, response };
102
- }
103
- /**
104
- * Hash a Jubjub point exactly as the circuits do (`persistentHash<JubjubPoint>`)
105
- * — the form the signet contract seals as `mpcPubKeyHash`.
106
- *
107
- * @param point - The point to hash.
108
- * @returns The 32-byte hash.
109
- */
110
- export function hashJubjubPoint(point) {
111
- return persistentHash(CompactTypeJubjubPoint, point);
112
- }
113
- /**
114
- * Parse a Jubjub public key from its `"x,y"` config/env form (decimal or
115
- * 0x-hex field coordinates) — how deploys receive `MPC_JUBJUB_PK`.
116
- *
117
- * @param value - The `"x,y"` string.
118
- * @returns The parsed point.
119
- * @throws Error if the value is not two comma-separated field coordinates.
120
- */
121
- export function parseJubjubPublicKey(value) {
122
- const parts = value.split(",").map((part) => part.trim());
123
- if (parts.length !== 2 || parts.some((part) => part === "")) {
124
- throw new Error(`expected a Jubjub public key as "x,y"; got "${value}"`);
125
- }
126
- try {
127
- return { x: BigInt(parts[0]), y: BigInt(parts[1]) };
128
- }
129
- catch {
130
- throw new Error(`Jubjub public key coordinates must be decimal or 0x-hex integers; got "${value}"`);
131
- }
132
- }
133
- /**
134
- * Format a Jubjub public key as the `"x,y"` decimal config/env form that
135
- * {@link parseJubjubPublicKey} accepts — the round-trip inverse, for handing
136
- * a derived key to deploys as `MPC_JUBJUB_PK`.
137
- *
138
- * @param point - The point to format.
139
- * @returns The `"x,y"` string with decimal coordinates.
140
- */
141
- export function formatJubjubPublicKey(point) {
142
- return `${point.x},${point.y}`;
143
- }
144
- //# sourceMappingURL=schnorr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schnorr.js","sourceRoot":"","sources":["../src/schnorr.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,uEAAuE;AACvE,qEAAqE;AACrE,4DAA4D;AAC5D,4EAA4E;AAC5E,iBAAiB;AACjB,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,6EAA6E;AAC7E,yCAAyC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,cAAc,GAEf,MAAM,iCAAiC,CAAC;AAOzC,sEAAsE;AACtE,MAAM,CAAC,MAAM,YAAY,GAAG,6EAA6E,CAAC;AAE1G,uEAAuE;AACvE,MAAM,CAAC,MAAM,SAAS,GAAG,8EAA8E,CAAC;AAExG,MAAM,WAAW,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAC7C,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE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AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,+CAA+C,KAAK,GAAG,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,0EAA0E,KAAK,GAAG,CAAC,CAAC;IACtG,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAkB;IACtD,OAAO,GAAG,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC"}
@@ -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
- }