@sig-net/midnight 0.10.0 → 0.12.0
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 +17 -17
- package/dist/abi-serde.d.ts +89 -0
- package/dist/abi-serde.d.ts.map +1 -0
- package/dist/abi-serde.js +393 -0
- package/dist/abi-serde.js.map +1 -0
- package/dist/constants.d.ts +23 -14
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +28 -20
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +81 -9
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +137 -18
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +8 -8
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +16 -18
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +180 -104
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +38 -24
- package/dist/managed/contract/index.js +363 -154
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +15 -15
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +51 -34
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +2 -2
- package/dist/signature-response-verification.js +8 -8
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-state-reader.d.ts +74 -58
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +76 -58
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-evtype2tx-requests.d.ts +62 -59
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +58 -90
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +26 -26
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +37 -37
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +30 -30
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +29 -30
- package/dist/signet-requests.js.map +1 -1
- package/package.json +3 -2
- package/src/Signet.compact +137 -88
- package/src/circuits.compact +45 -2
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
// the signet contract's signature response log, and verify each candidate
|
|
4
4
|
// against the request.
|
|
5
5
|
// This is the helper the Signet.compact "Response Ledger Layout" comment
|
|
6
|
-
// promises
|
|
7
|
-
// and take the first valid one
|
|
6
|
+
// promises: the log is UNAUTHENTICATED, so a client must verify every post
|
|
7
|
+
// and take the first valid one. This class packages that flow so every
|
|
8
8
|
// consumer (CLI poller, integration tests, a future UI) shares one
|
|
9
|
-
// implementation. Single-shot by design: each call queries state once
|
|
10
|
-
// caller owns any poll loop.
|
|
9
|
+
// implementation. Single-shot by design: each call queries state once, and
|
|
10
|
+
// the caller owns any poll loop.
|
|
11
11
|
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
12
12
|
import { readSignetContractLedgerFromState, signetMapEntryKey, } from "./signet-contract-state-reader.js";
|
|
13
13
|
import { recoverSignatureResponseSigner } from "./signature-response-verification.js";
|
|
14
|
-
import {
|
|
14
|
+
import { signBidirectionalEventToSignedEvmTransaction, signBidirectionalEventToUnsignedEvmTransaction, } from "./signet-evtype2tx-requests.js";
|
|
15
15
|
/**
|
|
16
16
|
* Reader over one requester contract / signet contract pair.
|
|
17
17
|
* Construct once per pair and reuse: fetched request records are cached (they
|
|
18
|
-
* are immutable
|
|
18
|
+
* are immutable, the ledger key is their hash), so repeated verification
|
|
19
19
|
* calls cost one responses-contract query each.
|
|
20
20
|
*/
|
|
21
21
|
export class SignetRequestResponseReader {
|
|
22
22
|
config;
|
|
23
|
-
// Request records never change once stored
|
|
23
|
+
// Request records never change once stored, so cache them across calls.
|
|
24
24
|
requestCache = new Map();
|
|
25
25
|
/**
|
|
26
26
|
* @param config - The contract pair and state source to read through.
|
|
@@ -39,7 +39,7 @@ export class SignetRequestResponseReader {
|
|
|
39
39
|
async queryRawState(contractAddress, role) {
|
|
40
40
|
const state = await this.config.publicDataProvider.queryContractState(contractAddress);
|
|
41
41
|
if (!state?.data) {
|
|
42
|
-
throw new Error(`no state data found for ${role} contract '${contractAddress}'
|
|
42
|
+
throw new Error(`no state data found for ${role} contract '${contractAddress}' (is it deployed?)`);
|
|
43
43
|
}
|
|
44
44
|
return state.data;
|
|
45
45
|
}
|
|
@@ -62,31 +62,31 @@ export class SignetRequestResponseReader {
|
|
|
62
62
|
const request = lookupSignetRequestAt(raw, this.config.requesterRequestsIndexField, requestId);
|
|
63
63
|
if (request === undefined) {
|
|
64
64
|
throw new Error(`request ${requestId} is not on the requester contract's ledger ` +
|
|
65
|
-
`(request index at field ${this.config.requesterRequestsIndexField})
|
|
65
|
+
`(request index at field ${this.config.requesterRequestsIndexField}): was it submitted?`);
|
|
66
66
|
}
|
|
67
67
|
this.requestCache.set(requestId, request);
|
|
68
68
|
return request;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Fetch every response posted for `requestId`, in post (count) order.
|
|
72
|
-
* UNVERIFIED
|
|
73
|
-
* {@link getVerifiedSignatureRespondedEvent}.
|
|
72
|
+
* UNVERIFIED: any of them may be garbage (see
|
|
73
|
+
* {@link getVerifiedSignatureRespondedEvent}).
|
|
74
74
|
*
|
|
75
75
|
* @param requestId - The request id whose posts to enumerate.
|
|
76
|
-
* @returns The posted payloads, index = count
|
|
76
|
+
* @returns The posted payloads, index = count, empty when none yet.
|
|
77
77
|
* @throws Error when the responses contract has no state, or its counter
|
|
78
78
|
* disagrees with the log (inconsistent ledger).
|
|
79
79
|
*/
|
|
80
80
|
async getSignatureResponses(requestId) {
|
|
81
81
|
const raw = await this.queryRawState(this.config.signetContractAddress, "signet contract");
|
|
82
|
-
const {
|
|
83
|
-
const totalPosts =
|
|
82
|
+
const { respondCounterMap, respondMap } = readSignetContractLedgerFromState(raw);
|
|
83
|
+
const totalPosts = respondCounterMap.get(requestId) ?? 0n;
|
|
84
84
|
const responses = [];
|
|
85
85
|
for (let count = 0n; count < totalPosts; count++) {
|
|
86
|
-
const response =
|
|
86
|
+
const response = respondMap.get(signetMapEntryKey(requestId, count));
|
|
87
87
|
if (response === undefined) {
|
|
88
88
|
throw new Error(`response log has no entry ${count} for request ${requestId} ` +
|
|
89
|
-
`despite its counter reading ${totalPosts}
|
|
89
|
+
`despite its counter reading ${totalPosts}: ledger state is inconsistent`);
|
|
90
90
|
}
|
|
91
91
|
responses.push(response);
|
|
92
92
|
}
|
|
@@ -94,14 +94,14 @@ export class SignetRequestResponseReader {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Fetch and verify the responses posted for `requestId`: each post's
|
|
97
|
-
*
|
|
97
|
+
* signature must recover to `expectedSigner`
|
|
98
98
|
* (compared case-insensitively) over the signing hash of the transaction
|
|
99
|
-
* the request record describes. The first valid post wins
|
|
100
|
-
* a verdict so callers can report the noise.
|
|
99
|
+
* the request record describes. The first valid post wins, and every post
|
|
100
|
+
* gets a verdict so callers can report the noise.
|
|
101
101
|
*
|
|
102
102
|
* @param requestId - The request id to fetch a verified response for.
|
|
103
103
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
104
|
-
* response must be signed by
|
|
104
|
+
* response must be signed by: the requester's MPC-derived address.
|
|
105
105
|
* @returns The first valid response (if any) plus per-post verdicts.
|
|
106
106
|
* @throws Error when either contract has no state, the request is not on
|
|
107
107
|
* the requester's ledger, or the responses ledger is inconsistent.
|
|
@@ -138,7 +138,7 @@ export class SignetRequestResponseReader {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Rebuild the unsigned EIP-1559 transaction for `requestId
|
|
141
|
+
* Rebuild the unsigned EIP-1559 transaction for `requestId`: the exact
|
|
142
142
|
* transaction the MPC signs, assembled from the request record's decomposed
|
|
143
143
|
* fields. No responses-contract query: this needs only the request record
|
|
144
144
|
* (fetched via {@link getSignatureRequest}, cached).
|
|
@@ -149,45 +149,45 @@ export class SignetRequestResponseReader {
|
|
|
149
149
|
* @throws Error when the requester contract has no state or holds no
|
|
150
150
|
* request under `requestId`.
|
|
151
151
|
*/
|
|
152
|
-
async
|
|
153
|
-
return
|
|
152
|
+
async getUnsignedEvmTransaction(requestId) {
|
|
153
|
+
return signBidirectionalEventToUnsignedEvmTransaction(await this.getSignatureRequest(requestId));
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Assemble the broadcast-ready signed EIP-1559 transaction for `requestId`:
|
|
157
157
|
* rebuild the request's transaction and attach the first VERIFIED response
|
|
158
|
-
* signed by `expectedSigner` (see {@link getVerifiedSignatureRespondedEvent}
|
|
159
|
-
* response log is unauthenticated, so an `expectedSigner` is required
|
|
160
|
-
* unverified posts are never attached).
|
|
158
|
+
* signed by `expectedSigner` (see {@link getVerifiedSignatureRespondedEvent}:
|
|
159
|
+
* the response log is unauthenticated, so an `expectedSigner` is required
|
|
160
|
+
* and unverified posts are never attached).
|
|
161
161
|
*
|
|
162
162
|
* @param requestId - The request id to produce a signed transaction for.
|
|
163
163
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
164
|
-
* response must be signed by
|
|
164
|
+
* response must be signed by: the requester's MPC-derived address.
|
|
165
165
|
* @returns The signed ethers transaction (`serialized` is the payload for
|
|
166
166
|
* `eth_sendRawTransaction`), or `undefined` when no valid response has
|
|
167
|
-
* been posted yet
|
|
167
|
+
* been posted yet: poll again.
|
|
168
168
|
* @throws Error when either contract has no state, the request is not on the
|
|
169
169
|
* requester's ledger, or the responses ledger is inconsistent.
|
|
170
170
|
*/
|
|
171
|
-
async
|
|
171
|
+
async getSignedEvmTransaction(requestId, expectedSigner) {
|
|
172
172
|
const { verified } = await this.getVerifiedSignatureRespondedEvent(requestId, expectedSigner);
|
|
173
173
|
if (verified === undefined) {
|
|
174
174
|
return undefined;
|
|
175
175
|
}
|
|
176
|
-
// getSignatureRequest is cached
|
|
177
|
-
// fetched it, so this is a free lookup
|
|
176
|
+
// getSignatureRequest is cached: getVerifiedSignatureRespondedEvent already
|
|
177
|
+
// fetched it, so this is a free lookup.
|
|
178
178
|
const request = await this.getSignatureRequest(requestId);
|
|
179
|
-
return
|
|
179
|
+
return signBidirectionalEventToSignedEvmTransaction(request, verified);
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Fetch every respond-bidirectional response posted for `requestId`, in
|
|
183
|
-
* post (count) order. UNVERIFIED
|
|
184
|
-
* checking them, so any entry may be garbage
|
|
183
|
+
* post (count) order. UNVERIFIED: the signet contract stores posts without
|
|
184
|
+
* checking them, so any entry may be garbage. Verify each candidate before
|
|
185
185
|
* trusting it (in-circuit at claim time, or off-chain via the compiled
|
|
186
186
|
* `pureCircuits.verifyRespondBidirectionalEvent` against the MPC derived
|
|
187
|
-
* key you expect). An empty array simply means none posted yet
|
|
187
|
+
* key you expect). An empty array simply means none posted yet: poll again.
|
|
188
188
|
*
|
|
189
189
|
* @param requestId - The request id whose responses to enumerate.
|
|
190
|
-
* @returns The posted records, index = count
|
|
190
|
+
* @returns The posted records, index = count, empty when none yet.
|
|
191
191
|
* @throws Error when the signet contract has no state, or its counter
|
|
192
192
|
* disagrees with the log (inconsistent ledger).
|
|
193
193
|
*/
|
|
@@ -200,7 +200,7 @@ export class SignetRequestResponseReader {
|
|
|
200
200
|
const response = respondBidirectionalMap.get(signetMapEntryKey(requestId, count));
|
|
201
201
|
if (response === undefined) {
|
|
202
202
|
throw new Error(`respond-bidirectional log has no entry ${count} for request ${requestId} ` +
|
|
203
|
-
`despite its counter reading ${totalPosts}
|
|
203
|
+
`despite its counter reading ${totalPosts}: ledger state is inconsistent`);
|
|
204
204
|
}
|
|
205
205
|
responses.push(response);
|
|
206
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,uBAAuB;AACvB,yEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,uBAAuB;AACvB,yEAAyE;AACzE,2EAA2E;AAC3E,uEAAuE;AACvE,mEAAmE;AACnE,2EAA2E;AAC3E,iCAAiC;AAKjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EACL,iCAAiC,EACjC,iBAAiB,GAGlB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EACL,4CAA4C,EAC5C,8CAA8C,GAC/C,MAAM,gCAAgC,CAAC;AAoExC;;;;;GAKG;AACH,MAAM,OAAO,2BAA2B;IACrB,MAAM,CAAoC;IAE3D,wEAAwE;IACvD,YAAY,GAAG,IAAI,GAAG,EAGpC,CAAC;IAEJ;;OAEG;IACH,YAAY,MAAyC;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,aAAa,CACzB,eAAuB,EACvB,IAAY;QAEZ,MAAM,KAAK,GACT,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,2BAA2B,IAAI,cAAc,eAAe,qBAAqB,CAClF,CAAC;QACJ,CAAC;QACD,OAA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GAAG,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,GAAG,CAC1C,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,CACpC,CAAC;YACF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,0CAA0C,KAAK,gBAAgB,SAAS,GAAG;oBACzE,+BAA+B,UAAU,gCAAgC,CAC5E,CAAC;YACJ,CAAC;YACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
import type {
|
|
2
|
+
import type { EvmType2TxParams } from "./signet-evtype2tx-requests.ts";
|
|
3
3
|
/**
|
|
4
4
|
* 32-byte signet request id (Compact: `new type RequestId = Bytes<32>`).
|
|
5
5
|
* Chain-agnostic: downstream consumers treat it as an opaque key. Ids are
|
|
6
|
-
* minted by `calculateRequestId` in Signet.compact
|
|
6
|
+
* minted by `calculateRequestId` in Signet.compact: the persistent hash of
|
|
7
7
|
* the full {@link SignBidirectionalEvent} record (which includes the sender
|
|
8
8
|
* contract address, scoping ids per contract).
|
|
9
9
|
*/
|
|
@@ -19,14 +19,14 @@ export interface ContractAddress {
|
|
|
19
19
|
/**
|
|
20
20
|
* Which transaction-param decomposition a request carries (Compact:
|
|
21
21
|
* `enum TxParamType`), as the generated code represents enums: a `number`
|
|
22
|
-
* holding the 0-based variant index. Exported as a `const` object
|
|
23
|
-
*
|
|
22
|
+
* holding the 0-based variant index. Exported as a `const` object so the
|
|
23
|
+
* values stay structurally `number`.
|
|
24
24
|
*/
|
|
25
25
|
export declare const TxParamType: {
|
|
26
|
-
/** `
|
|
26
|
+
/** `EvmType2TxParams` (signet-evtype2tx-requests.ts): an EIP-1559 EVM transaction. */
|
|
27
27
|
readonly evmType2: 0;
|
|
28
28
|
/**
|
|
29
|
-
* Never emitted
|
|
29
|
+
* Never emitted: mirrors the Compact-side padding variant that keeps the
|
|
30
30
|
* enum at >= 2 variants (a 1-variant enum is a zero-byte value the proof
|
|
31
31
|
* server cannot parse inside persistentHash preimages).
|
|
32
32
|
*/
|
|
@@ -39,7 +39,7 @@ export declare const TxParamType: {
|
|
|
39
39
|
export declare const MPCSignatureAlgorithm: {
|
|
40
40
|
/** ECDSA over secp256k1. */
|
|
41
41
|
readonly ecdsa: 0;
|
|
42
|
-
/** Never emitted
|
|
42
|
+
/** Never emitted: the >= 2 variants padding (see {@link TxParamType}). */
|
|
43
43
|
readonly reserved: 1;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
@@ -49,7 +49,7 @@ export declare const MPCSignatureAlgorithm: {
|
|
|
49
49
|
export declare const MPCDestination: {
|
|
50
50
|
/** The only currently-valid value. */
|
|
51
51
|
readonly unused: 0;
|
|
52
|
-
/** Never emitted
|
|
52
|
+
/** Never emitted: the >= 2 variants padding (see {@link TxParamType}). */
|
|
53
53
|
readonly reserved: 1;
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
@@ -66,14 +66,14 @@ export interface Maybe<T> {
|
|
|
66
66
|
* `SignBidirectionalEvent<TxParams, #LenOutputDeserialization,
|
|
67
67
|
* #LenRespondSerialization>`), stored per {@link RequestId} in a requesting
|
|
68
68
|
* contract's `SignBidirectionalEventMap` (at whichever ledger field the
|
|
69
|
-
* contract declares it
|
|
70
|
-
* the tx-params decomposition, exactly like the Compact struct
|
|
71
|
-
* instantiation is {@link
|
|
69
|
+
* contract declares it: its notifications name the position). Generic over
|
|
70
|
+
* the tx-params decomposition, exactly like the Compact struct. The default
|
|
71
|
+
* instantiation is {@link EvmType2TxParams}, the only decomposition so far:
|
|
72
72
|
* new tx kinds supply their own type argument alongside their Compact struct.
|
|
73
73
|
* The schema fields carry their contract-declared byte widths in their array
|
|
74
74
|
* lengths.
|
|
75
75
|
*/
|
|
76
|
-
export interface SignBidirectionalEvent<TxParams =
|
|
76
|
+
export interface SignBidirectionalEvent<TxParams = EvmType2TxParams> {
|
|
77
77
|
/** Address of the client contract that stores this event (`kernel.self()`). */
|
|
78
78
|
sender: ContractAddress;
|
|
79
79
|
/** Contract-local nonce captured when the request was created. */
|
|
@@ -86,25 +86,25 @@ export interface SignBidirectionalEvent<TxParams = EVMType2TxParams> {
|
|
|
86
86
|
algo: number;
|
|
87
87
|
/** An {@link MPCDestination} value. */
|
|
88
88
|
dest: number;
|
|
89
|
-
/** Extra MPC parameters, reserved
|
|
89
|
+
/** Extra MPC parameters, reserved, 64 bytes. */
|
|
90
90
|
params: Uint8Array;
|
|
91
91
|
/** A {@link TxParamType} value tagging the txParams decomposition. */
|
|
92
92
|
txParamType: number;
|
|
93
93
|
/** The transaction decomposition. */
|
|
94
94
|
txParams: TxParams;
|
|
95
|
-
/** Target chain in CAIP-2 form (https://chainagnostic.org/CAIPs/caip-2), zero-padded
|
|
95
|
+
/** Target chain in CAIP-2 form (https://chainagnostic.org/CAIPs/caip-2), zero-padded, 32 bytes. */
|
|
96
96
|
caip2Id: Uint8Array;
|
|
97
|
-
/** MPC output_deserialization_schema (destination chain -> MPC)
|
|
97
|
+
/** MPC output_deserialization_schema (destination chain -> MPC), contract-declared width. */
|
|
98
98
|
outputDeserializationSchema: Uint8Array;
|
|
99
|
-
/** MPC respond_serialization_schema (MPC -> Midnight)
|
|
99
|
+
/** MPC respond_serialization_schema (MPC -> Midnight), contract-declared width. */
|
|
100
100
|
respondSerializationSchema: Uint8Array;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Build the runtime descriptor of a Compact struct from its per-field
|
|
104
|
-
* descriptors
|
|
104
|
+
* descriptors: the generic form of the struct descriptor classes the
|
|
105
105
|
* compiler generates (field-by-field concatenation of alignments and values).
|
|
106
106
|
*
|
|
107
|
-
* Field ORDER must match the Compact struct declaration order
|
|
107
|
+
* Field ORDER must match the Compact struct declaration order. Object
|
|
108
108
|
* literals preserve insertion order for string keys, so pass fields in
|
|
109
109
|
* declaration order.
|
|
110
110
|
*
|
|
@@ -115,7 +115,7 @@ export declare function compactStructDescriptor<T extends object>(fields: {
|
|
|
115
115
|
readonly [K in keyof T]-?: CompactType<T[K]>;
|
|
116
116
|
}): CompactType<T>;
|
|
117
117
|
/**
|
|
118
|
-
* Descriptor of Compact's standard-library `Maybe<T
|
|
118
|
+
* Descriptor of Compact's standard-library `Maybe<T>`: the compiler
|
|
119
119
|
* generates it as the struct `{ is_some: Boolean, value: T }`.
|
|
120
120
|
*
|
|
121
121
|
* @param inner - Descriptor of the wrapped type.
|
|
@@ -124,10 +124,10 @@ export declare function compactStructDescriptor<T extends object>(fields: {
|
|
|
124
124
|
export declare function compactMaybeDescriptor<T>(inner: CompactType<T>): CompactType<Maybe<T>>;
|
|
125
125
|
/**
|
|
126
126
|
* Descriptor of {@link SignBidirectionalEvent} over ANY tx-params
|
|
127
|
-
* decomposition
|
|
127
|
+
* decomposition: the TS analogue of Compact's generic
|
|
128
128
|
* `SignBidirectionalEvent<TxParams, #LenOutputDeserialization,
|
|
129
129
|
* #LenRespondSerialization>`. Each decomposition wraps this with its own
|
|
130
|
-
* capacity-
|
|
130
|
+
* capacity-parameterised convenience (see `signBidirectionalEventDescriptor`
|
|
131
131
|
* in signet-evtype2tx-requests.ts for the EVM Type-2 one).
|
|
132
132
|
*
|
|
133
133
|
* @param txParams - Descriptor of the tx-params decomposition, already at
|
|
@@ -156,17 +156,17 @@ export interface SignBidirectionalEventLedgerMap extends Iterable<[RequestId, Si
|
|
|
156
156
|
member(requestId: RequestId): boolean;
|
|
157
157
|
/**
|
|
158
158
|
* @param requestId - 32-byte request id to fetch.
|
|
159
|
-
* @returns The stored request record
|
|
159
|
+
* @returns The stored request record. Throws when absent: guard with
|
|
160
160
|
* {@link member} first.
|
|
161
161
|
*/
|
|
162
162
|
lookup(requestId: RequestId): SignBidirectionalEvent;
|
|
163
163
|
}
|
|
164
164
|
declare const requestIdHexBrand: unique symbol;
|
|
165
165
|
/**
|
|
166
|
-
* 64-char lowercase hex rendering of a {@link RequestId}
|
|
166
|
+
* 64-char lowercase hex rendering of a {@link RequestId}: THE
|
|
167
167
|
* representation of a request id everywhere in TypeScript. Raw
|
|
168
168
|
* {@link RequestId} bytes appear only at the Compact boundary (state
|
|
169
|
-
* readers, compiled-circuit calls)
|
|
169
|
+
* readers, compiled-circuit calls). The moment an id crosses that boundary it
|
|
170
170
|
* becomes this type. Branded (the TS analogue of Compact's `new type`) so an
|
|
171
171
|
* arbitrary string cannot pose as a request id: mint one with
|
|
172
172
|
* {@link requestIdHex} (from ledger bytes) or {@link parseRequestIdHex}
|
|
@@ -192,7 +192,7 @@ export declare function bytesToHex(bytes: Uint8Array): string;
|
|
|
192
192
|
*/
|
|
193
193
|
export declare function stripHexPrefix(hex: string): string;
|
|
194
194
|
/**
|
|
195
|
-
* Decode a hex string into bytes
|
|
195
|
+
* Decode a hex string into bytes: the inverse of {@link bytesToHex}.
|
|
196
196
|
*
|
|
197
197
|
* @param hex - Hex digits, with or without a `0x` prefix.
|
|
198
198
|
* @returns The decoded bytes.
|
|
@@ -200,7 +200,7 @@ export declare function stripHexPrefix(hex: string): string;
|
|
|
200
200
|
export declare function hexToBytes(hex: string): Uint8Array;
|
|
201
201
|
/**
|
|
202
202
|
* Render a request id in its canonical TS form (see
|
|
203
|
-
* {@link RequestIdHex})
|
|
203
|
+
* {@link RequestIdHex}), also usable as a JS `Map` key, which raw
|
|
204
204
|
* `Uint8Array` ids are not (they compare by reference).
|
|
205
205
|
*
|
|
206
206
|
* @param requestId - 32-byte request id.
|
|
@@ -208,13 +208,13 @@ export declare function hexToBytes(hex: string): Uint8Array;
|
|
|
208
208
|
*/
|
|
209
209
|
export declare function requestIdHex(requestId: RequestId): RequestIdHex;
|
|
210
210
|
/**
|
|
211
|
-
* Validate and
|
|
211
|
+
* Validate and normalise an untrusted string (CLI argument, config value)
|
|
212
212
|
* into a {@link RequestIdHex}: an optional `0x` prefix is stripped and
|
|
213
213
|
* the digits lowercased before validation.
|
|
214
214
|
*
|
|
215
215
|
* @param value - The candidate request id string.
|
|
216
|
-
* @returns The branded,
|
|
217
|
-
* @throws Error if the value is not 64 hex chars after
|
|
216
|
+
* @returns The branded, normalised request id hex.
|
|
217
|
+
* @throws Error if the value is not 64 hex chars after normalisation.
|
|
218
218
|
*/
|
|
219
219
|
export declare function parseRequestIdHex(value: string): RequestIdHex;
|
|
220
220
|
/**
|
|
@@ -236,7 +236,7 @@ export declare const PATH_BYTES = 32;
|
|
|
236
236
|
* Parse the on-ledger request map into a plain-JS index keyed by hex
|
|
237
237
|
* request id.
|
|
238
238
|
*
|
|
239
|
-
* @param ledgerIndex - Iterable of `[requestId, request]` entries
|
|
239
|
+
* @param ledgerIndex - Iterable of `[requestId, request]` entries, e.g. a
|
|
240
240
|
* contract's `ledger(state).signBidirectionalEventMap` (any
|
|
241
241
|
* {@link SignBidirectionalEventLedgerMap}).
|
|
242
242
|
* @returns A new `Map` from {@link requestIdHex} key to request record.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-requests.d.ts","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC;AAEnC;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW;IACtB,sFAAsF;;IAEtF;;;;OAIG;;CAEK,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,qBAAqB;IAChC,4BAA4B;;IAE5B,
|
|
1
|
+
{"version":3,"file":"signet-requests.d.ts","sourceRoot":"","sources":["../src/signet-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,sBAAsB,CACvB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAOlD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAM7D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,SAAS,CAM1D;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,QAAQ,CAAC,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,GACzD,2BAA2B,CAM7B"}
|
package/dist/signet-requests.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// The lockstep is enforced by each consuming contract's simulator tests: the
|
|
13
13
|
// "test-caller-contract ledger shape" test in packages/test-caller-contract/tests/
|
|
14
14
|
// contract.test.ts assigns the generated `ledger().signBidirectionalEventMap`
|
|
15
|
-
// to the named SignBidirectionalEventLedgerMap type
|
|
15
|
+
// to the named SignBidirectionalEventLedgerMap type: the assignment itself is
|
|
16
16
|
// the assertion, so any structural drift between the generated managed types
|
|
17
17
|
// and these twins fails that package's `yarn build` / `yarn test`.
|
|
18
18
|
//
|
|
@@ -22,14 +22,14 @@ import { CompactTypeBoolean, CompactTypeBytes, CompactTypeEnum, CompactTypeUnsig
|
|
|
22
22
|
/**
|
|
23
23
|
* Which transaction-param decomposition a request carries (Compact:
|
|
24
24
|
* `enum TxParamType`), as the generated code represents enums: a `number`
|
|
25
|
-
* holding the 0-based variant index. Exported as a `const` object
|
|
26
|
-
*
|
|
25
|
+
* holding the 0-based variant index. Exported as a `const` object so the
|
|
26
|
+
* values stay structurally `number`.
|
|
27
27
|
*/
|
|
28
28
|
export const TxParamType = {
|
|
29
|
-
/** `
|
|
29
|
+
/** `EvmType2TxParams` (signet-evtype2tx-requests.ts): an EIP-1559 EVM transaction. */
|
|
30
30
|
evmType2: 0,
|
|
31
31
|
/**
|
|
32
|
-
* Never emitted
|
|
32
|
+
* Never emitted: mirrors the Compact-side padding variant that keeps the
|
|
33
33
|
* enum at >= 2 variants (a 1-variant enum is a zero-byte value the proof
|
|
34
34
|
* server cannot parse inside persistentHash preimages).
|
|
35
35
|
*/
|
|
@@ -42,7 +42,7 @@ export const TxParamType = {
|
|
|
42
42
|
export const MPCSignatureAlgorithm = {
|
|
43
43
|
/** ECDSA over secp256k1. */
|
|
44
44
|
ecdsa: 0,
|
|
45
|
-
/** Never emitted
|
|
45
|
+
/** Never emitted: the >= 2 variants padding (see {@link TxParamType}). */
|
|
46
46
|
reserved: 1,
|
|
47
47
|
};
|
|
48
48
|
/**
|
|
@@ -52,7 +52,7 @@ export const MPCSignatureAlgorithm = {
|
|
|
52
52
|
export const MPCDestination = {
|
|
53
53
|
/** The only currently-valid value. */
|
|
54
54
|
unused: 0,
|
|
55
|
-
/** Never emitted
|
|
55
|
+
/** Never emitted: the >= 2 variants padding (see {@link TxParamType}). */
|
|
56
56
|
reserved: 1,
|
|
57
57
|
};
|
|
58
58
|
// ---- Runtime descriptor toolkit (TS twin of the compiled struct codecs) ----
|
|
@@ -60,26 +60,25 @@ export const MPCDestination = {
|
|
|
60
60
|
// DEVIATION from the "pure circuits are compiled, never re-written in TS"
|
|
61
61
|
// rule (see circuits.compact): the request-id circuit is generic over the
|
|
62
62
|
// tx-params type and schema lengths, the Compact compiler cannot export
|
|
63
|
-
// type-
|
|
64
|
-
// have to be
|
|
63
|
+
// type-parameterised circuits from the top level, and a compiled copy would
|
|
64
|
+
// have to be monomorphised at ONE capacity instantiation: a client
|
|
65
65
|
// contract's choice that never belongs in this client-agnostic package. So
|
|
66
66
|
// the record descriptor (and the per-decomposition `calculateRequestId`
|
|
67
67
|
// built on it, see signet-evtype2tx-requests.ts) alone gets a TS twin here.
|
|
68
68
|
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
// field by field, in declaration order. Enforced by test-caller-contract's
|
|
69
|
+
// Ids still come from the very `persistentHash` runtime builtin that
|
|
70
|
+
// compiled circuits call, over runtime type descriptors mirroring the ones
|
|
71
|
+
// the compiler generates (compare `_calculateRequestId_0` in any consuming
|
|
72
|
+
// contract's managed/contract/index.js). What must stay in lockstep with
|
|
73
|
+
// Signet.compact is exactly what this file already keeps in lockstep: the
|
|
74
|
+
// struct shapes, field by field, in declaration order. Enforced by test-caller-contract's
|
|
76
75
|
// "submitSignatureRequest round-trip" test, which asserts the id computed
|
|
77
76
|
// here equals the ledger map key minted by the REAL compiled contract.
|
|
78
77
|
// Runtime descriptors of the Compact base types the generic record fields
|
|
79
|
-
// use. CompactTypeUnsignedInteger takes (maxValue, byte length)
|
|
78
|
+
// use. CompactTypeUnsignedInteger takes (maxValue, byte length), the same
|
|
80
79
|
// literals the compiler emits for Uint<8/64>. CompactTypeEnum takes
|
|
81
|
-
// (variantCount - 1, byte length)
|
|
82
|
-
// `CompactTypeEnum(0, 0)
|
|
80
|
+
// (variantCount - 1, byte length). NOTE: a 1-variant enum would compile to
|
|
81
|
+
// `CompactTypeEnum(0, 0)`, zero bytes, which the proof server cannot parse
|
|
83
82
|
// inside persistentHash preimages. Every enum therefore carries a padding
|
|
84
83
|
// `reserved` variant so it stays at (1, 1).
|
|
85
84
|
const BYTES_32 = new CompactTypeBytes(32);
|
|
@@ -100,10 +99,10 @@ const CONTRACT_ADDRESS = {
|
|
|
100
99
|
};
|
|
101
100
|
/**
|
|
102
101
|
* Build the runtime descriptor of a Compact struct from its per-field
|
|
103
|
-
* descriptors
|
|
102
|
+
* descriptors: the generic form of the struct descriptor classes the
|
|
104
103
|
* compiler generates (field-by-field concatenation of alignments and values).
|
|
105
104
|
*
|
|
106
|
-
* Field ORDER must match the Compact struct declaration order
|
|
105
|
+
* Field ORDER must match the Compact struct declaration order. Object
|
|
107
106
|
* literals preserve insertion order for string keys, so pass fields in
|
|
108
107
|
* declaration order.
|
|
109
108
|
*
|
|
@@ -125,7 +124,7 @@ export function compactStructDescriptor(fields) {
|
|
|
125
124
|
};
|
|
126
125
|
}
|
|
127
126
|
/**
|
|
128
|
-
* Descriptor of Compact's standard-library `Maybe<T
|
|
127
|
+
* Descriptor of Compact's standard-library `Maybe<T>`: the compiler
|
|
129
128
|
* generates it as the struct `{ is_some: Boolean, value: T }`.
|
|
130
129
|
*
|
|
131
130
|
* @param inner - Descriptor of the wrapped type.
|
|
@@ -139,10 +138,10 @@ export function compactMaybeDescriptor(inner) {
|
|
|
139
138
|
}
|
|
140
139
|
/**
|
|
141
140
|
* Descriptor of {@link SignBidirectionalEvent} over ANY tx-params
|
|
142
|
-
* decomposition
|
|
141
|
+
* decomposition: the TS analogue of Compact's generic
|
|
143
142
|
* `SignBidirectionalEvent<TxParams, #LenOutputDeserialization,
|
|
144
143
|
* #LenRespondSerialization>`. Each decomposition wraps this with its own
|
|
145
|
-
* capacity-
|
|
144
|
+
* capacity-parameterised convenience (see `signBidirectionalEventDescriptor`
|
|
146
145
|
* in signet-evtype2tx-requests.ts for the EVM Type-2 one).
|
|
147
146
|
*
|
|
148
147
|
* @param txParams - Descriptor of the tx-params decomposition, already at
|
|
@@ -188,7 +187,7 @@ export function stripHexPrefix(hex) {
|
|
|
188
187
|
return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
189
188
|
}
|
|
190
189
|
/**
|
|
191
|
-
* Decode a hex string into bytes
|
|
190
|
+
* Decode a hex string into bytes: the inverse of {@link bytesToHex}.
|
|
192
191
|
*
|
|
193
192
|
* @param hex - Hex digits, with or without a `0x` prefix.
|
|
194
193
|
* @returns The decoded bytes.
|
|
@@ -203,7 +202,7 @@ export function hexToBytes(hex) {
|
|
|
203
202
|
}
|
|
204
203
|
/**
|
|
205
204
|
* Render a request id in its canonical TS form (see
|
|
206
|
-
* {@link RequestIdHex})
|
|
205
|
+
* {@link RequestIdHex}), also usable as a JS `Map` key, which raw
|
|
207
206
|
* `Uint8Array` ids are not (they compare by reference).
|
|
208
207
|
*
|
|
209
208
|
* @param requestId - 32-byte request id.
|
|
@@ -213,13 +212,13 @@ export function requestIdHex(requestId) {
|
|
|
213
212
|
return bytesToHex(requestId);
|
|
214
213
|
}
|
|
215
214
|
/**
|
|
216
|
-
* Validate and
|
|
215
|
+
* Validate and normalise an untrusted string (CLI argument, config value)
|
|
217
216
|
* into a {@link RequestIdHex}: an optional `0x` prefix is stripped and
|
|
218
217
|
* the digits lowercased before validation.
|
|
219
218
|
*
|
|
220
219
|
* @param value - The candidate request id string.
|
|
221
|
-
* @returns The branded,
|
|
222
|
-
* @throws Error if the value is not 64 hex chars after
|
|
220
|
+
* @returns The branded, normalised request id hex.
|
|
221
|
+
* @throws Error if the value is not 64 hex chars after normalisation.
|
|
223
222
|
*/
|
|
224
223
|
export function parseRequestIdHex(value) {
|
|
225
224
|
const hex = value.replace(/^0x/i, "").toLowerCase();
|
|
@@ -253,7 +252,7 @@ export const PATH_BYTES = 32;
|
|
|
253
252
|
* Parse the on-ledger request map into a plain-JS index keyed by hex
|
|
254
253
|
* request id.
|
|
255
254
|
*
|
|
256
|
-
* @param ledgerIndex - Iterable of `[requestId, request]` entries
|
|
255
|
+
* @param ledgerIndex - Iterable of `[requestId, request]` entries, e.g. a
|
|
257
256
|
* contract's `ledger(state).signBidirectionalEventMap` (any
|
|
258
257
|
* {@link SignBidirectionalEventLedgerMap}).
|
|
259
258
|
* @returns A new `Map` from {@link requestIdHex} key to request record.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-requests.js","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,sEAAsE;AACtE,EAAE;AACF,iEAAiE;AACjE,2EAA2E;AAC3E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E
|
|
1
|
+
{"version":3,"file":"signet-requests.js","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,sEAAsE;AACtE,EAAE;AACF,iEAAiE;AACjE,2EAA2E;AAC3E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,mEAAmE;AACnE,EAAE;AACF,wEAAwE;AACxE,yDAAyD;AAEzD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAsBzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,sFAAsF;IACtF,QAAQ,EAAE,CAAC;IACX;;;;OAIG;IACH,QAAQ,EAAE,CAAC;CACH,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,4BAA4B;IAC5B,KAAK,EAAE,CAAC;IACR,0EAA0E;IAC1E,QAAQ,EAAE,CAAC;CACH,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,sCAAsC;IACtC,MAAM,EAAE,CAAC;IACT,0EAA0E;IAC1E,QAAQ,EAAE,CAAC;CACH,CAAC;AAmDX,+EAA+E;AAC/E,EAAE;AACF,0EAA0E;AAC1E,0EA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GED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sig-net/midnight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sig-net/midnight-integration",
|
|
7
7
|
"directory": "packages/signet-midnight"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"description": "Midnight-side sig-net integration
|
|
10
|
+
"description": "Midnight-side sig-net integration: the seed of a future signet.js Midnight adapter.",
|
|
11
11
|
"//exports": "Local dev consumes raw TS source. `publishConfig.exports` below swaps this to the emitted ./dist at publish time, so npm consumers get JS + .d.ts while the monorepo keeps resolving to src.",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@midnight-ntwrk/compact-runtime": "0.18.0-rc.1",
|
|
41
41
|
"@midnight-ntwrk/midnight-js-types": "5.0.0-beta.4",
|
|
42
42
|
"@noble/curves": "^2.2.0",
|
|
43
|
+
"@sig-net/midnight-serde": "^0.12.0",
|
|
43
44
|
"ethers": "^6.17.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|