@sig-net/midnight-contract 0.0.2 → 0.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sig-net/midnight-contract",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "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
6
  "exports": {
@@ -11,9 +11,7 @@
11
11
  "./managed/*": "./dist/managed/*"
12
12
  },
13
13
  "files": [
14
- "dist",
15
- "src",
16
- "!src/managed"
14
+ "dist"
17
15
  ],
18
16
  "scripts": {
19
17
  "compile": "COMPACT_PATH=../../node_modules compact compile --skip-zk src/signet-contract.compact src/managed",
@@ -39,7 +37,7 @@
39
37
  "@midnight-ntwrk/midnight-js": "5.0.0-beta.3"
40
38
  },
41
39
  "devDependencies": {
42
- "@sig-net/midnight": "^0.0.2",
40
+ "@sig-net/midnight": "^0.0.3",
43
41
  "@types/node": "^26.1.0",
44
42
  "typescript": "^6.0.3",
45
43
  "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> = {};