@sig-net/midnight-contract 0.0.2 → 0.0.4

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.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @sig-net/midnight-contract
2
+
3
+ The central [Sig Network](https://sig.network) signet contract on the [Midnight blockchain](https://midnight.network): the singleton that exposes the MPC's [sign bidirectional flow](https://docs.sig.network/architecture/sign-bidirectional) to other Midnight contracts. The MPC posts back to it and clients poll it:
4
+
5
+ - **Signature responses**: an unauthenticated counted log; callers verify the signatures off-chain or in their own circuits.
6
+ - **Remote execution responses**: Schnorr attestations by the MPC's Jubjub key, verified in-circuit at post time.
7
+ - **Request-notification registry**: how the MPC discovers new signature requests.
8
+
9
+ ## What is in it
10
+
11
+ - The curated export surface (package root): the generated contract module (`Contract`, the `ledger` state decoder, `pureCircuits`), the handwritten witnesses, and the platform-agnostic contract surface (circuit ids and the provider type).
12
+ - The `./managed/*` subpath export: the compiled contract assets (compiler output, `zkir/`, prover/verifier `keys/`) so runtimes can fetch them as files. The published package always carries the proving keys.
13
+
14
+ Consumers import the package root; the `./managed/*` paths exist only for runtimes that load zk assets.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ npm install @sig-net/midnight-contract
20
+ ```
21
+
22
+ ## Related packages
23
+
24
+ - [`@sig-net/midnight-contract-deploy`](https://www.npmjs.com/package/@sig-net/midnight-contract-deploy): deploys this contract (constructor argument: the MPC attestation key).
25
+ - [`@sig-net/midnight`](https://www.npmjs.com/package/@sig-net/midnight): the client-agnostic protocol library for reading this contract's state and verifying responses.
26
+
27
+ Developed in [sig-net/midnight-integration](https://github.com/sig-net/midnight-integration); example applications live in [sig-net/midnight-examples](https://github.com/sig-net/midnight-examples).
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compiler-version": "0.33.0",
3
3
  "language-version": "0.25.0",
4
- "runtime-version": "0.18.0-rc.0",
4
+ "runtime-version": "0.18.0-rc.1",
5
5
  "circuits": [
6
6
  {
7
7
  "name": "notifyBidirectionalSignatureRequest",
@@ -2,13 +2,13 @@
2
2
  "manifest-version": "1",
3
3
  "compiler-version": "0.33.0",
4
4
  "language-version": "0.25.0",
5
- "runtime-version": "0.18.0-rc.0",
5
+ "runtime-version": "0.18.0-rc.1",
6
6
  "compiler": {
7
7
  "type": "directory",
8
8
  "contract-info.json": {
9
9
  "type": "file",
10
10
  "size": 8633,
11
- "hash": "6c9b7bfed4149ef2b9adb72c039a32c881f385f437640fe3dff7b7ba2f4768c1"
11
+ "hash": "72d03046b056dd7fb01af5b97b9992b95d952cef1fbbc7a600d5d5ea29c361c5"
12
12
  }
13
13
  },
14
14
  "contract": {
@@ -20,13 +20,13 @@
20
20
  },
21
21
  "index.js": {
22
22
  "type": "file",
23
- "size": 84531,
24
- "hash": "8ae44bde9e25000d76e25a663cda7b1cedc7bdf4e5978cac096f9ae7a5525397"
23
+ "size": 84363,
24
+ "hash": "45747bcf588a8fb96a9413ca532e578f6e9023c9198f7c97ad25e3f2de31790d"
25
25
  },
26
26
  "index.js.map": {
27
27
  "type": "file",
28
- "size": 3258,
29
- "hash": "40d1f39539d07d1e011d8dac46bd89b0de547ea4307e7489bc8ac5b9e4d80581"
28
+ "size": 3251,
29
+ "hash": "8d82e5ba5aced9fc8dc821154cc513a3064e4f8bf40228fcebf157fbcb884996"
30
30
  }
31
31
  },
32
32
  "zkir": {
@@ -1,5 +1,5 @@
1
1
  import * as __compactRuntime from '@midnight-ntwrk/compact-runtime';
2
- __compactRuntime.checkRuntimeVersion('0.18.0-rc.0');
2
+ __compactRuntime.checkRuntimeVersion('0.18.0-rc.1');
3
3
 
4
4
  const _descriptor_0 = new __compactRuntime.CompactTypeBytes(32);
5
5
 
@@ -498,30 +498,30 @@ export class Contract {
498
498
  __compactRuntime.convertBigintToBytes(32,
499
499
  outputLen_0,
500
500
  'Signet.compact line 369 char 7')]);
501
- return [__compactRuntime.convertBytesToBigint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
502
- 16,
503
- ((e, i) => e.slice(i, i+16))(rid_0,
504
- Number(0n)),
505
- 'Field',
506
- 'Signet.compact line 372 char 7'),
507
- __compactRuntime.convertBytesToBigint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
508
- 16,
509
- ((e, i) => e.slice(i, i+16))(rid_0,
510
- Number(16n)),
511
- 'Field',
512
- 'Signet.compact line 373 char 7'),
513
- __compactRuntime.convertBytesToBigint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
514
- 16,
515
- ((e, i) => e.slice(i, i+16))(outHash_0,
516
- Number(0n)),
517
- 'Field',
518
- 'Signet.compact line 374 char 7'),
519
- __compactRuntime.convertBytesToBigint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
520
- 16,
521
- ((e, i) => e.slice(i, i+16))(outHash_0,
522
- Number(16n)),
523
- 'Field',
524
- 'Signet.compact line 375 char 7')];
501
+ return [__compactRuntime.convertBytesToUint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
502
+ 16,
503
+ ((e, i) => e.slice(i, i+16))(rid_0,
504
+ Number(0n)),
505
+ 'Field',
506
+ 'Signet.compact line 372 char 7'),
507
+ __compactRuntime.convertBytesToUint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
508
+ 16,
509
+ ((e, i) => e.slice(i, i+16))(rid_0,
510
+ Number(16n)),
511
+ 'Field',
512
+ 'Signet.compact line 373 char 7'),
513
+ __compactRuntime.convertBytesToUint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
514
+ 16,
515
+ ((e, i) => e.slice(i, i+16))(outHash_0,
516
+ Number(0n)),
517
+ 'Field',
518
+ 'Signet.compact line 374 char 7'),
519
+ __compactRuntime.convertBytesToUint(52435875175126190479447740508185965837690552500527637822603658699938581184512n,
520
+ 16,
521
+ ((e, i) => e.slice(i, i+16))(outHash_0,
522
+ Number(16n)),
523
+ 'Field',
524
+ 'Signet.compact line 375 char 7')];
525
525
  }
526
526
  async _notifyBidirectionalSignatureRequest_0(context,
527
527
  partialProofData,
@@ -712,15 +712,8 @@ export class Contract {
712
712
  }
713
713
  }
714
714
  _equal_0(x0, y0) {
715
- {
716
- let x1 = x0.x;
717
- let y1 = y0.x;
718
- if (x1 !== y1) { return false; }
719
- }
720
- {
721
- let x1 = x0.y;
722
- let y1 = y0.y;
723
- if (x1 !== y1) { return false; }
715
+ if (x0.x != y0.x || x0.y != y0.y) {
716
+ return false;
724
717
  }
725
718
  return true;
726
719
  }
@@ -4,5 +4,5 @@
4
4
  "sourceRoot": "../../../",
5
5
  "sources": ["src/signet-contract.compact", "compiler/standard-library.compact", "compiler/zkir-v3-library.compact", "../../node_modules/@sig-net/midnight/src/Signet.compact"],
6
6
  "names": [],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BA;;;;;;;;;;MAWA,AAAA,mCAQC;;;;;cAPG,WAAoB;cACpB,cAA2C;;;;;;;;;;;;;;;;;;;;;;;;;yCAD3C,WAAoB,gCACpB,cAA2C;;;;;;;;;2EAD3C,WAAoB;2EACpB,cAA2C;;;;OAM9C;MAQD,AAAA,qBAsBC;;;;;cAtBoC,WAAoB;cAAE,mBAAoC;;;;;;;;;;;;;;;;;;;;;;;;;yCAA1D,WAAoB,+BAAE,mBAAoC;;;;;;;;;6DAA1D,WAAoB;6DAAE,mBAAoC;;;;OAsB9F;MAQD,AAAA,wBAyCC;;;;;cAxCG,WAAoB;cACpB,sBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;yCAD1C,WAAoB,gCACpB,sBAA0C;;;;;;;;;gEAD1C,WAAoB;gEACpB,sBAA0C;;;;OAuC7C;;;;;;;;;;;;GAhGA;EAFD;;;;;UAAY,OAAkB;;;;;;;;;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;;;;;4GAAqF;;;;;;;;;;;;;;uCAArF;;;;;;;;;;;;;;;4GAAqF;;;;;;;;;;;;;;wCAArF;;;;;;;;;;;;;;;;;6GAAqF;;;;;;;;;KAAA;;;;;;;;;;;;;;;;"
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@sig-net/midnight-contract",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/sig-net/midnight-integration",
7
+ "directory": "packages/signet-contract"
8
+ },
4
9
  "type": "module",
5
10
  "description": "The central signet Compact contract on Midnight: the MPC posts signature responses (unauthenticated counted log, verified off-chain) and remote execution responses (Schnorr attestations, verified in-circuit at post time) here; clients poll it. src/index.ts is the curated export surface.",
6
11
  "exports": {
@@ -11,9 +16,7 @@
11
16
  "./managed/*": "./dist/managed/*"
12
17
  },
13
18
  "files": [
14
- "dist",
15
- "src",
16
- "!src/managed"
19
+ "dist"
17
20
  ],
18
21
  "scripts": {
19
22
  "compile": "COMPACT_PATH=../../node_modules compact compile --skip-zk src/signet-contract.compact src/managed",
@@ -35,11 +38,11 @@
35
38
  }
36
39
  },
37
40
  "dependencies": {
38
- "@midnight-ntwrk/compact-runtime": "0.18.0-rc.0",
39
- "@midnight-ntwrk/midnight-js": "5.0.0-beta.3"
41
+ "@midnight-ntwrk/compact-runtime": "0.18.0-rc.1",
42
+ "@midnight-ntwrk/midnight-js": "5.0.0-beta.4"
40
43
  },
41
44
  "devDependencies": {
42
- "@sig-net/midnight": "^0.0.2",
45
+ "@sig-net/midnight": "^0.0.4",
43
46
  "@types/node": "^26.1.0",
44
47
  "typescript": "^6.0.3",
45
48
  "vitest": "^4.1.9"
@@ -1,40 +0,0 @@
1
- // The contract's platform-agnostic client surface: the circuit-id union, the
2
- // private-state store key, and the provider-set TYPE. Deliberately nothing
3
- // runnable — no wallet flavor, no zk-config source, no state store, no proof
4
- // provider. Composing a live midnight-js provider set is CONSUMER territory
5
- // (it differs per environment: Node fs vs browser fetch, LevelDB vs
6
- // IndexedDB, WalletFacade vs a connector API), so each consumer declares its
7
- // own — see this monorepo's signet-contract-deploy package for the Node
8
- // operator composition, and the fakenet response server for a consumer's.
9
-
10
- import type { MidnightProviders } from "@midnight-ntwrk/midnight-js/types";
11
-
12
- import { Contract } from "./managed/contract/index.js";
13
- import { type SignetContractPrivateState } from "./witnesses.ts";
14
-
15
- /** The contract's provable circuit ids, straight from the generated contract. */
16
- export type SignetContractCircuitId = keyof InstanceType<typeof Contract>["provableCircuits"] & string;
17
-
18
- /**
19
- * Literal of the private-state storage key. Just a string, but a single-value
20
- * union so the providers/`findDeployedContract` pairing is enforced by the
21
- * type system.
22
- */
23
- export type SignetContractPrivateStateId = "signet-contract";
24
-
25
- /**
26
- * Key under which midnight-js persists this contract's private state locally
27
- * (in whatever private-state store the consumer's provider set uses).
28
- * Distinct per contract so two clients don't share an entry.
29
- */
30
- export const SIGNET_CONTRACT_PRIVATE_STATE_ID: SignetContractPrivateStateId = "signet-contract";
31
-
32
- /** The full midnight-js provider set, typed to the signet contract. */
33
- export type SignetContractProviders = MidnightProviders<
34
- // PCK: the union of the contract's provable circuit names.
35
- SignetContractCircuitId,
36
- // PSI: the private-state storage key literal.
37
- SignetContractPrivateStateId,
38
- // PS: the shape of the contract's (empty) private state object.
39
- SignetContractPrivateState
40
- >;
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- // Curated export surface — this IS the "sdk" face of the package.
2
- // Everything the compiler emitted, the handwritten witnesses, and the
3
- // platform-agnostic contract surface (ids + provider TYPE). Environment
4
- // bindings (zk-config source, state store, wallet adapter) deliberately
5
- // live with each consumer, not here.
6
-
7
- export * from "./managed/contract/index.js";
8
- export * from "./witnesses.ts";
9
- export * from "./contract-surface.ts";
@@ -1,128 +0,0 @@
1
- pragma language_version >= 0.25;
2
-
3
- import CompactStandardLibrary;
4
-
5
- // Shared signet library: request/response structs, request-id hashing,
6
- // path<->identity binding, and the attestation message. See the module header
7
- // in Signet.compact and https://docs.sig.network/ for the protocol.
8
- import "@sig-net/midnight/src/Signet";
9
-
10
- // The CENTRAL signet contract: clients register their signature-request
11
- // notifications here, the MPC delivers all its responses here, and both sides
12
- // poll it — there is deliberately no push/websocket channel. Ledger layout per
13
- // "Signet Contract Ledger Layout" in Signet.compact, so pollers need only this
14
- // contract's address.
15
- export ledger signatureResponseCounterIndex: SignatureResponseCounterIndex;
16
-
17
- export ledger signatureResponseIndex: SignatureResponseIndex;
18
-
19
- export ledger respondBidirectionalIndex: RespondBidirectionalIndex;
20
-
21
- // The MPC attestation key, pinned at deploy time: postRespondBidirectional
22
- // accepts only responses signed by this key.
23
- export sealed ledger mpcPubKeyHash: Bytes<32>;
24
-
25
- // The notification registry (field 4): clients register "a request was stored
26
- // in MY ledger at THIS index field" pointers here; the MPC polls by
27
- // enumerating the map. Append-only, idempotent overwrite, no removal.
28
- export ledger signBidirectionalNotificationIndex: SignBidirectionalNotificationIndex;
29
-
30
- constructor(mpcPk: JubjubPoint) {
31
- mpcPubKeyHash = disclose(persistentHash<JubjubPoint>(mpcPk));
32
- }
33
-
34
- // notifyBidirectionalSignatureRequest should be called (cross-contract) by
35
- // clients after (or within) a transaction that writes a
36
- // SignBidirectionalRequest to their canonical SignBidirectionalRequestIndex
37
- // state map. Registers the notification in the registry the MPC polls; a
38
- // repeat call for the same request id overwrites idempotently. Unauthenticated
39
- // by design: the notification is a pointer, and the MPC trusts only what it
40
- // reads back from the named caller's own ledger.
41
- export circuit notifyBidirectionalSignatureRequest(
42
- requestId: RequestId,
43
- notification: SignBidirectionalNotification
44
- ): [] {
45
- signBidirectionalNotificationIndex.insert(
46
- disclose(requestId),
47
- disclose(notification),
48
- );
49
- }
50
-
51
- // postSignatureResponse appends a signature response for requestId.
52
- // Unauthenticated by NECESSITY (secp256k1 ECDSA cannot be verified
53
- // in-circuit): anyone may post, and nothing is ever overwritten — each post
54
- // lands under the next (requestId, count) key. Callers poll the log by
55
- // request id and verify the posted signatures off-chain to pick out the
56
- // genuine one.
57
- export circuit postSignatureResponse(requestId: RequestId, signatureResponse: SignatureResponse): [] {
58
- // Everything stored here is public by construction.
59
- const disclosedRequestId = disclose(requestId);
60
-
61
- // Ensure the request's counter exists (a fresh Counter reads 0).
62
- if (!signatureResponseCounterIndex.member(disclosedRequestId)) {
63
- signatureResponseCounterIndex.insertDefault(disclosedRequestId);
64
- }
65
-
66
- // Posts so far == this post's 0-based count. Read ONCE into a local so
67
- // the stored key and the counter update cannot disagree.
68
- const count = signatureResponseCounterIndex.lookup(disclosedRequestId).read();
69
- signatureResponseCounterIndex.lookup(disclosedRequestId).increment(1);
70
-
71
- // Store the response under (requestId, count).
72
- signatureResponseIndex.insert(
73
- SignetResponseKey{
74
- requestId: disclosedRequestId,
75
- count: count,
76
- },
77
- disclose(signatureResponse),
78
- );
79
- }
80
-
81
- // postRespondBidirectional records the MPC's attestation of requestId's
82
- // remote execution. Anyone may POST, but nothing unauthentic can LAND: the
83
- // Schnorr signature over (requestId, hash(serializedOutput, outputLen)) is
84
- // verified in-circuit against the sealed MPC key, so the stored record is
85
- // authentic by construction and one slot per request suffices — clients read
86
- // it without re-verifying.
87
- export circuit postRespondBidirectional(
88
- requestId: RequestId,
89
- respondBidirectional: RespondBidirectional
90
- ): [] {
91
- // Everything stored here is public by construction.
92
- const disclosedRequestId = disclose(requestId);
93
- const disclosedResponse = disclose(respondBidirectional);
94
-
95
- // Only the pinned MPC key may attest.
96
- assert(
97
- persistentHash<JubjubPoint>(disclosedResponse.pk) == mpcPubKeyHash,
98
- "unauthorized: attestation pk is not the MPC key"
99
- );
100
-
101
- // The attestation must sign THIS request and THIS output.
102
- assert(
103
- jubjubSchnorrVerify<4>(
104
- signetAttestationMessage(
105
- disclosedRequestId,
106
- disclosedResponse.serializedOutput,
107
- disclosedResponse.outputLen
108
- ),
109
- JubjubSchnorrSignature {
110
- announcement: disclosedResponse.announcement,
111
- response: disclosedResponse.response,
112
- },
113
- disclosedResponse.pk
114
- ),
115
- "Invalid attestation signature"
116
- );
117
-
118
- // First valid write wins. A re-post is a no-op, never an overwrite —
119
- // Schnorr is randomized, so even the MPC re-signing the same output
120
- // yields bytewise-different records; asserting equality would misfire.
121
- // The no-op leaves the single authenticated slot untouched. Clients poll
122
- // the index by request id; no off-chain verification follows — the
123
- // in-circuit checks above already authenticated the stored record.
124
- if (respondBidirectionalIndex.member(disclosedRequestId)) {
125
- return [];
126
- }
127
- respondBidirectionalIndex.insert(disclosedRequestId, disclosedResponse);
128
- }
package/src/witnesses.ts DELETED
@@ -1,22 +0,0 @@
1
- // The signet contract has no witnesses: Schnorr verification is
2
- // CompactStandardLibrary's `jubjubSchnorrVerify` (fully in-circuit), and
3
- // there is no private state — posting carries no caller secrets.
4
-
5
- import type { Witnesses } from "./managed/contract/index.js";
6
-
7
- /** Private state carried through signet-contract circuit calls: none. */
8
- export type SignetContractPrivateState = Record<string, never>;
9
-
10
- /**
11
- * Build the contract's (empty) private state.
12
- *
13
- * @returns A fresh, empty private state.
14
- */
15
- export const createSignetContractPrivateState =
16
- (): SignetContractPrivateState => ({});
17
-
18
- /**
19
- * Witness implementations, typed against the generated `Witnesses` shape:
20
- * the contract declares none.
21
- */
22
- export const witnesses: Witnesses<SignetContractPrivateState> = {};