@sig-net/midnight 0.19.0 → 0.20.0-rc.1

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 (85) hide show
  1. package/README.md +42 -2
  2. package/dist/abi-serde.d.ts +32 -30
  3. package/dist/abi-serde.d.ts.map +1 -1
  4. package/dist/abi-serde.js +139 -75
  5. package/dist/abi-serde.js.map +1 -1
  6. package/dist/byte-codecs.d.ts +62 -0
  7. package/dist/byte-codecs.d.ts.map +1 -0
  8. package/dist/byte-codecs.js +116 -0
  9. package/dist/byte-codecs.js.map +1 -0
  10. package/dist/compact-descriptors.d.ts +89 -0
  11. package/dist/compact-descriptors.d.ts.map +1 -0
  12. package/dist/compact-descriptors.js +139 -0
  13. package/dist/compact-descriptors.js.map +1 -0
  14. package/dist/constants.d.ts +18 -43
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js +19 -45
  17. package/dist/constants.js.map +1 -1
  18. package/dist/ecdsa-attestation.d.ts +49 -97
  19. package/dist/ecdsa-attestation.d.ts.map +1 -1
  20. package/dist/ecdsa-attestation.js +78 -142
  21. package/dist/ecdsa-attestation.js.map +1 -1
  22. package/dist/epsilon-derivation.d.ts +24 -31
  23. package/dist/epsilon-derivation.d.ts.map +1 -1
  24. package/dist/epsilon-derivation.js +52 -62
  25. package/dist/epsilon-derivation.js.map +1 -1
  26. package/dist/index.d.ts +10 -9
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +17 -8
  29. package/dist/index.js.map +1 -1
  30. package/dist/managed/compiler/contract-info.json +0 -22
  31. package/dist/managed/compiler/contract-manifest.json +8 -8
  32. package/dist/managed/contract/index.d.ts +0 -3
  33. package/dist/managed/contract/index.js +65 -80
  34. package/dist/managed/contract/index.js.map +1 -1
  35. package/dist/raw-contract-state.d.ts +25 -0
  36. package/dist/raw-contract-state.d.ts.map +1 -0
  37. package/dist/raw-contract-state.js +52 -0
  38. package/dist/raw-contract-state.js.map +1 -0
  39. package/dist/signature-requests-state-reader.d.ts +18 -44
  40. package/dist/signature-requests-state-reader.d.ts.map +1 -1
  41. package/dist/signature-requests-state-reader.js +82 -146
  42. package/dist/signature-requests-state-reader.js.map +1 -1
  43. package/dist/signature-response-verification.d.ts +9 -8
  44. package/dist/signature-response-verification.d.ts.map +1 -1
  45. package/dist/signature-response-verification.js +20 -17
  46. package/dist/signature-response-verification.js.map +1 -1
  47. package/dist/signet-contract-events.d.ts +56 -64
  48. package/dist/signet-contract-events.d.ts.map +1 -1
  49. package/dist/signet-contract-events.js +46 -48
  50. package/dist/signet-contract-events.js.map +1 -1
  51. package/dist/signet-evtype2tx-record-decoding.d.ts +18 -0
  52. package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -0
  53. package/dist/signet-evtype2tx-record-decoding.js +97 -0
  54. package/dist/signet-evtype2tx-record-decoding.js.map +1 -0
  55. package/dist/signet-evtype2tx-requests.d.ts +43 -87
  56. package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
  57. package/dist/signet-evtype2tx-requests.js +59 -130
  58. package/dist/signet-evtype2tx-requests.js.map +1 -1
  59. package/dist/signet-request-id.d.ts +14 -0
  60. package/dist/signet-request-id.d.ts.map +1 -0
  61. package/dist/signet-request-id.js +27 -0
  62. package/dist/signet-request-id.js.map +1 -0
  63. package/dist/signet-request-response-reader.d.ts +34 -56
  64. package/dist/signet-request-response-reader.d.ts.map +1 -1
  65. package/dist/signet-request-response-reader.js +56 -68
  66. package/dist/signet-request-response-reader.js.map +1 -1
  67. package/dist/signet-requests.d.ts +28 -92
  68. package/dist/signet-requests.d.ts.map +1 -1
  69. package/dist/signet-requests.js +39 -141
  70. package/dist/signet-requests.js.map +1 -1
  71. package/dist/testing.d.ts +3 -0
  72. package/dist/testing.d.ts.map +1 -0
  73. package/dist/testing.js +20 -0
  74. package/dist/testing.js.map +1 -0
  75. package/package.json +12 -3
  76. package/src/Signet.compact +110 -171
  77. package/src/circuits.compact +9 -16
  78. package/dist/signature-state-reading.d.ts +0 -43
  79. package/dist/signature-state-reading.d.ts.map +0 -1
  80. package/dist/signature-state-reading.js +0 -74
  81. package/dist/signature-state-reading.js.map +0 -1
  82. package/dist/signet-request-feed.d.ts +0 -126
  83. package/dist/signet-request-feed.d.ts.map +0 -1
  84. package/dist/signet-request-feed.js +0 -216
  85. package/dist/signet-request-feed.js.map +0 -1
@@ -1,25 +1,9 @@
1
+ import { type RawContractState } from "./raw-contract-state.ts";
1
2
  import { type RequestIdHex, type SignBidirectionalEvent, type SignBidirectionalEventIndex } from "./signet-requests.ts";
2
- import { type RawContractState } from "./signature-state-reading.ts";
3
- /**
4
- * Aligned-value entry count of an event record EXCLUDING the capacity-scaled
5
- * vectors: sender (1) + requestNonce (1) + keyVersion (1) + path (1) +
6
- * algo (1) + dest (1) + params (1) + txParamType (1, enums are one atom
7
- * whatever their byte width) + the EvmType2TxParams fixed fields
8
- * (chainId..value = 7, accessListEntryCount = 1) + the calldata Maybe's
9
- * is_some (1), selector (1) and noWords (1) + caip2Id (1) + the two schema
10
- * fields (1 each). A stored event cell therefore holds
11
- * `REQUEST_FIXED_VALUE_ATOMS + maxCalldataWords
12
- * + maxAccessListEntries·(2 + maxStorageKeysPerEntry)`
13
- * entries (each calldata word is one Bytes<32> atom, and each access-list
14
- * entry is address + storageKeyCount + its keys).
15
- */
16
- export declare const REQUEST_FIXED_VALUE_ATOMS = 22;
17
3
  /**
18
4
  * The decoded signet ledger fields of a requesting contract: its request
19
5
  * index and its contract-local request counter (Compact `Counter`), the
20
- * source of each request's `requestNonce`. Nothing off-chain depends on the
21
- * counter: it is decoded here only because both fields travel together in
22
- * tests and diagnostics.
6
+ * source of each request's `requestNonce`.
23
7
  */
24
8
  export interface SignetRequestsLedger {
25
9
  /** The request counter (`Counter`). */
@@ -29,47 +13,37 @@ export interface SignetRequestsLedger {
29
13
  }
30
14
  /**
31
15
  * MPC-style read: parse the signet ledger fields out of raw contract state
32
- * by field position alone, with no compiled contract and no generated
33
- * `ledger()`, only the caller-supplied field positions and the canonical descriptors
34
- * from signet-requests.ts. A contract chooses its own layout, so the caller
35
- * must know where the fields sit (the caller contract in this repo uses
36
- * index 0 / counter 1, and a notification names the index position of the
37
- * contract it points at).
16
+ * by caller-supplied field positions. A contract chooses its own layout, so
17
+ * the caller must know where the fields sit.
18
+ *
19
+ * Records are decoded, not verified against the ids they are filed under:
20
+ * {@link lookupSignetRequestAt} is the verified lookup.
38
21
  *
39
22
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`
40
23
  * from the indexer or `ctx.currentQueryContext.state` from the simulator.
41
24
  * @param requestsIndexPath - Resolved ledger-tree path of the request index.
42
25
  * @param noncePath - Resolved ledger-tree path of the request counter.
43
26
  * @returns The decoded {@link SignetRequestsLedger}.
44
- * @throws Error if a field is missing, has the wrong state-value shape, or a
45
- * record matches no capacity split.
27
+ * @throws {Error} If a field is missing, has the wrong state-value shape, or a
28
+ * record is not a decodable evmType2 request record.
46
29
  */
47
30
  export declare function readSignetRequestsLedgerFromState(raw: RawContractState, requestsIndexPath: readonly number[], noncePath: readonly number[]): SignetRequestsLedger;
48
31
  /**
49
32
  * Look up ONE request by id in a contract's request index at an arbitrary
50
- * ledger field, the single-record sibling of
51
- * {@link readSignetRequestsLedgerFromState}: the discovery primitive of the
52
- * event-based feed and what a point verification uses. A notification
53
- * declares the stored request's id and names both the requester contract
54
- * AND which field holds its index.
55
- *
56
- * `undefined` means the id is NOT a member of the index at `requestsPath`
57
- * (the pointer is forged, stale, points at the wrong field, or the request is
58
- * not yet indexed) and the caller MUST drop it.
59
- * Every non-membership case (field out of range, field is not a Map, id absent,
60
- * a cell that fails to decode) returns `undefined` rather than throwing, so a
61
- * malformed or adversarial notification can never crash the reader.
62
- *
63
- * Only the matched record is decoded, and it is decoded
64
- * by the same {@link decodeSignBidirectionalEvent} the full reader uses, so
65
- * the result is `toEqual` to `readSignetRequestsLedgerFromState(raw,
66
- * fieldIndex, …).requestsIndex.get(requestId)`.
33
+ * ledger field: the single-record sibling of
34
+ * {@link readSignetRequestsLedgerFromState} and the discovery primitive of
35
+ * the event-based feed. The recompute-and-drop gate: the decode never sees
36
+ * the id, so the final recompute is the only thing binding a record's
37
+ * contents to the key it was filed under, and a mismatch (a spoofed or
38
+ * wrongly filed record) is dropped. Every non-membership case returns
39
+ * `undefined` rather than throwing, and the caller MUST drop such a pointer.
67
40
  *
68
41
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
69
42
  * @param requestsPath - Resolved ledger-tree path of the request index in
70
43
  * `raw`, as the notification carries it.
71
44
  * @param requestId - The request id to look up.
72
- * @returns The stored request record, or `undefined` when it is not a member.
45
+ * @returns The stored, id-verified request record, or `undefined` when it is
46
+ * not a member.
73
47
  */
74
48
  export declare function lookupSignetRequestAt(raw: RawContractState, requestsPath: readonly number[], requestId: RequestIdHex): SignBidirectionalEvent | undefined;
75
49
  //# sourceMappingURL=signature-requests-state-reader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signature-requests-state-reader.d.ts","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EACjC,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AA6F5C;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,EAAE,2BAA2B,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,SAAS,MAAM,EAAE,EACpC,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,CAqBtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,SAAS,EAAE,YAAY,GACtB,sBAAsB,GAAG,SAAS,CA2BpC"}
1
+ {"version":3,"file":"signature-requests-state-reader.d.ts","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,gBAAgB,EAAyB,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EAEL,KAAK,YAAY,EAGjB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAEjC,MAAM,sBAAsB,CAAC;AAwC9B;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,EAAE,2BAA2B,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,SAAS,MAAM,EAAE,EACpC,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,CAoBtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,SAAS,EAAE,YAAY,GACtB,sBAAsB,GAAG,SAAS,CA+BpC"}
@@ -1,125 +1,67 @@
1
- // MPC-style raw state reader for the signature-REQUESTS side: decode the signet
2
- // request ledger fields out of a contract's raw state WITHOUT the compiled
3
- // contract. This is how the MPC monitor consumes signet contracts: it has only
4
- // a contract address, queries raw state from the indexer
5
- // (queryContractState(address).data), and decodes by ledger-tree PATH.
6
- // A contract is free to place its request index at any field: the caller
7
- // supplies the resolved path, which the discovery path learns from the
8
- // notification's requestsPath (sourced from the caller's contract-info.json).
9
- // The compiled contract's generated ledger() follows exactly this path internally.
10
- // The record descriptors themselves are the parameterised twins in
11
- // signet-requests.ts. The generic tree walk and shared base descriptors live
12
- // in signature-state-reading.ts.
13
- import { calculateRequestId, signBidirectionalEventDescriptor, } from "./signet-evtype2tx-requests.js";
14
- import { requestIdHex, } from "./signet-requests.js";
15
- import { requestIdType, signetFieldNodeByPath, u64, } from "./signature-state-reading.js";
1
+ // MPC-style raw state reader for the signature-REQUESTS side: read the
2
+ // signet request ledger fields out of a contract's raw state by resolved
3
+ // ledger-tree path, as the MPC monitor and the event feed consume signet
4
+ // contracts. The generic tree walk lives in raw-contract-state.ts and the
5
+ // per-decomposition record decoding in signet-evtype2tx-record-decoding.ts.
6
+ //
7
+ // The read algorithm is the TS twin of the MPC's Rust reader
8
+ // (chain-signatures/chain-midnight/src/reader.rs) and must stay in lockstep
9
+ // with it: each record is decoded once, and id verification is a separate
10
+ // recompute-and-drop gate ({@link lookupSignetRequestAt}).
11
+ import { decodeExactly, UINT_64 } from "./compact-descriptors.js";
12
+ import { signetFieldNodeByPath } from "./raw-contract-state.js";
13
+ import { decodeEvmType2SignBidirectionalEvent } from "./signet-evtype2tx-record-decoding.js";
14
+ import { calculateRequestId } from "./signet-request-id.js";
15
+ import { requestIdBytes, requestIdHex, requestIdType, TxParamType, } from "./signet-requests.js";
16
+ // Atom position of `txParamType` in a stored record: the chain-agnostic head
17
+ // of SignBidirectionalEvent (sender through txParamType) occupies the first
18
+ // 8 atoms whatever the decomposition, so the tag sits at the same index in
19
+ // every record.
20
+ const TX_PARAM_TYPE_ATOM = 7;
16
21
  /**
17
- * Aligned-value entry count of an event record EXCLUDING the capacity-scaled
18
- * vectors: sender (1) + requestNonce (1) + keyVersion (1) + path (1) +
19
- * algo (1) + dest (1) + params (1) + txParamType (1, enums are one atom
20
- * whatever their byte width) + the EvmType2TxParams fixed fields
21
- * (chainId..value = 7, accessListEntryCount = 1) + the calldata Maybe's
22
- * is_some (1), selector (1) and noWords (1) + caip2Id (1) + the two schema
23
- * fields (1 each). A stored event cell therefore holds
24
- * `REQUEST_FIXED_VALUE_ATOMS + maxCalldataWords
25
- * + maxAccessListEntries·(2 + maxStorageKeysPerEntry)`
26
- * entries (each calldata word is one Bytes<32> atom, and each access-list
27
- * entry is address + storageKeyCount + its keys).
28
- */
29
- export const REQUEST_FIXED_VALUE_ATOMS = 22;
30
- /**
31
- * Recover a record's capacity instantiation (maxCalldataWords,
32
- * maxAccessListEntries, maxStorageKeysPerEntry) from its aligned-value atom
33
- * count and decode it. One atom count does not determine the capacities
34
- * uniquely, so candidates are enumerated, access-list-free first (today's
35
- * producers, the caller contract <1, 0, 0> and the erc20-vault example
36
- * <2, 0, 0>, are all access-list-free), and validated by the decode itself:
37
- * the descriptors' Bytes length checks and the enum range check reject wrong
38
- * splits, and a decode that leaves atoms unconsumed is rejected here.
22
+ * Decode a stored request record: read the `txParamType` tag and hand the
23
+ * cell to that decomposition's decoder, so a foreign param type fails by
24
+ * name rather than as capacity arithmetic. Does NOT verify the record
25
+ * against the id it is filed under.
39
26
  *
40
- * The schema byte widths (`#LenOutputDeserialization`,
41
- * `#LenRespondSerialization`) are read from the LAST TWO atoms' actual byte
42
- * lengths. That works because the state layer stores atoms with trailing
43
- * zeros trimmed and schemas are exact-length by protocol convention (JSON
44
- * schema strings sized to fit, never NUL-padded, never ending in a zero
45
- * byte), so stored length == declared length. A contract that padded its
46
- * schema capacity with trailing zeros would decode to the trimmed width and
47
- * fail the request-id recompute, which is the authoritative check anyway.
48
- *
49
- * @param atoms - The record cell's aligned value (a fresh copy per attempt).
50
- * @param expectedRequestId - The id the record is stored under, used to pick
51
- * between splits when more than one decodes cleanly.
27
+ * @param cell - The record cell as stored (value atoms plus alignment).
52
28
  * @returns The decoded record.
53
- * @throws Error if no capacity split decodes the value cleanly.
29
+ * @throws {Error} If the cell is not a decodable request record of a known
30
+ * decomposition.
54
31
  */
55
- function decodeSignBidirectionalEvent(atoms, expectedRequestId) {
56
- const variable = atoms.length - REQUEST_FIXED_VALUE_ATOMS;
57
- if (variable < 0) {
58
- throw new Error(`request record has ${atoms.length} value entries: fewer than the ` +
59
- `${REQUEST_FIXED_VALUE_ATOMS} its fixed fields need`);
32
+ function decodeSignBidirectionalEvent(cell) {
33
+ const what = "request record";
34
+ const atom = cell.value[TX_PARAM_TYPE_ATOM];
35
+ if (atom === undefined) {
36
+ throw new Error(`${what} ends before txParamType`);
60
37
  }
61
- const lenOutputDeserialization = atoms[atoms.length - 2].length;
62
- const lenRespondSerialization = atoms[atoms.length - 1].length;
63
- const attempt = (maxWords, maxEntries, maxKeys) => {
64
- const cursor = [...atoms];
65
- try {
66
- const record = signBidirectionalEventDescriptor(maxWords, maxEntries, maxKeys, lenOutputDeserialization, lenRespondSerialization).fromValue(cursor);
67
- // A clean decode consumes the record exactly.
68
- return cursor.length === 0 ? record : undefined;
69
- }
70
- catch {
71
- return undefined;
72
- }
73
- };
74
- // Several splits can decode cleanly (an access-list entry's 20-byte address atom
75
- // re-pads into a 32-byte calldata word just as well), so only the id the record is
76
- // filed under separates them. This disambiguates but does not authenticate (the MPC
77
- // recomputes against the sender-bound id before signing).
78
- //
79
- // First match wins, so the common access-list-free case stays at one decode.
80
- // `fallback` preserves the pre-recompute behaviour when no split matches the id.
81
- let fallback;
82
- const take = (record) => {
83
- if (record === undefined)
84
- return false;
85
- fallback ??= record;
86
- return requestIdHex(calculateRequestId(record)) === expectedRequestId;
87
- };
88
- // No access list: variable atoms are calldata words alone (one atom each).
89
- const accessListFree = attempt(variable, 0, 0);
90
- if (take(accessListFree))
91
- return accessListFree;
92
- // With an access list: E entries of (2 + K) atoms, the rest words.
93
- for (let entries = 1; entries * 2 <= variable; entries++) {
94
- for (let keys = 0; entries * (2 + keys) <= variable; keys++) {
95
- const words = variable - entries * (2 + keys);
96
- const record = attempt(words, entries, keys);
97
- if (take(record))
98
- return record;
99
- }
38
+ if (atom.length > 1) {
39
+ throw new Error(`${what} txParamType atom holds ${String(atom.length)} bytes, expected at most 1`);
100
40
  }
101
- if (fallback === undefined) {
102
- throw new Error(`request record with ${atoms.length} value entries matches no ` +
103
- `(calldata words, access-list entries, storage keys) capacity split`);
41
+ // The state layer trims trailing zeros, so evmType2 (0) arrives empty.
42
+ const paramType = atom[0] ?? 0;
43
+ switch (paramType) {
44
+ case TxParamType.evmType2:
45
+ return decodeEvmType2SignBidirectionalEvent(cell, what);
46
+ default:
47
+ throw new Error(`unsupported txParamType ${String(paramType)}`);
104
48
  }
105
- return fallback;
106
49
  }
107
50
  /**
108
51
  * MPC-style read: parse the signet ledger fields out of raw contract state
109
- * by field position alone, with no compiled contract and no generated
110
- * `ledger()`, only the caller-supplied field positions and the canonical descriptors
111
- * from signet-requests.ts. A contract chooses its own layout, so the caller
112
- * must know where the fields sit (the caller contract in this repo uses
113
- * index 0 / counter 1, and a notification names the index position of the
114
- * contract it points at).
52
+ * by caller-supplied field positions. A contract chooses its own layout, so
53
+ * the caller must know where the fields sit.
54
+ *
55
+ * Records are decoded, not verified against the ids they are filed under:
56
+ * {@link lookupSignetRequestAt} is the verified lookup.
115
57
  *
116
58
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`
117
59
  * from the indexer or `ctx.currentQueryContext.state` from the simulator.
118
60
  * @param requestsIndexPath - Resolved ledger-tree path of the request index.
119
61
  * @param noncePath - Resolved ledger-tree path of the request counter.
120
62
  * @returns The decoded {@link SignetRequestsLedger}.
121
- * @throws Error if a field is missing, has the wrong state-value shape, or a
122
- * record matches no capacity split.
63
+ * @throws {Error} If a field is missing, has the wrong state-value shape, or a
64
+ * record is not a decodable evmType2 request record.
123
65
  */
124
66
  export function readSignetRequestsLedgerFromState(raw, requestsIndexPath, noncePath) {
125
67
  const map = signetFieldNodeByPath(raw, requestsIndexPath).asMap();
@@ -128,45 +70,35 @@ export function readSignetRequestsLedgerFromState(raw, requestsIndexPath, nonceP
128
70
  }
129
71
  const requestsIndex = new Map();
130
72
  for (const key of map.keys()) {
131
- // fromValue consumes its input, so hand each descriptor a copy.
132
- const requestId = requestIdHex(requestIdType.fromValue([...key.value]));
73
+ const requestId = requestIdHex(decodeExactly(requestIdType, key.value, "request index key"));
133
74
  const cell = map.get(key)?.asCell();
134
75
  if (cell === undefined)
135
76
  continue;
136
- requestsIndex.set(requestId, decodeSignBidirectionalEvent(cell.value, requestId));
77
+ requestsIndex.set(requestId, decodeSignBidirectionalEvent(cell));
137
78
  }
138
- const nonceCell = signetFieldNodeByPath(raw, noncePath).asCell();
139
- if (nonceCell === undefined) {
79
+ const nonceField = signetFieldNodeByPath(raw, noncePath);
80
+ if (nonceField.type() !== "cell") {
140
81
  throw new Error(`Ledger field at path ${JSON.stringify(noncePath)} is not a Cell`);
141
82
  }
142
- const nonce = u64.fromValue([...nonceCell.value]);
83
+ const nonce = decodeExactly(UINT_64, nonceField.asCell().value, "request counter");
143
84
  return { nonce, requestsIndex };
144
85
  }
145
86
  /**
146
87
  * Look up ONE request by id in a contract's request index at an arbitrary
147
- * ledger field, the single-record sibling of
148
- * {@link readSignetRequestsLedgerFromState}: the discovery primitive of the
149
- * event-based feed and what a point verification uses. A notification
150
- * declares the stored request's id and names both the requester contract
151
- * AND which field holds its index.
152
- *
153
- * `undefined` means the id is NOT a member of the index at `requestsPath`
154
- * (the pointer is forged, stale, points at the wrong field, or the request is
155
- * not yet indexed) and the caller MUST drop it.
156
- * Every non-membership case (field out of range, field is not a Map, id absent,
157
- * a cell that fails to decode) returns `undefined` rather than throwing, so a
158
- * malformed or adversarial notification can never crash the reader.
159
- *
160
- * Only the matched record is decoded, and it is decoded
161
- * by the same {@link decodeSignBidirectionalEvent} the full reader uses, so
162
- * the result is `toEqual` to `readSignetRequestsLedgerFromState(raw,
163
- * fieldIndex, …).requestsIndex.get(requestId)`.
88
+ * ledger field: the single-record sibling of
89
+ * {@link readSignetRequestsLedgerFromState} and the discovery primitive of
90
+ * the event-based feed. The recompute-and-drop gate: the decode never sees
91
+ * the id, so the final recompute is the only thing binding a record's
92
+ * contents to the key it was filed under, and a mismatch (a spoofed or
93
+ * wrongly filed record) is dropped. Every non-membership case returns
94
+ * `undefined` rather than throwing, and the caller MUST drop such a pointer.
164
95
  *
165
96
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
166
97
  * @param requestsPath - Resolved ledger-tree path of the request index in
167
98
  * `raw`, as the notification carries it.
168
99
  * @param requestId - The request id to look up.
169
- * @returns The stored request record, or `undefined` when it is not a member.
100
+ * @returns The stored, id-verified request record, or `undefined` when it is
101
+ * not a member.
170
102
  */
171
103
  export function lookupSignetRequestAt(raw, requestsPath, requestId) {
172
104
  let node;
@@ -180,22 +112,26 @@ export function lookupSignetRequestAt(raw, requestsPath, requestId) {
180
112
  if (map === undefined) {
181
113
  return undefined; // the named field is not a request index
182
114
  }
183
- for (const key of map.keys()) {
184
- // fromValue consumes its input, so hand each descriptor a copy.
185
- if (requestIdHex(requestIdType.fromValue([...key.value])) !== requestId) {
186
- continue;
187
- }
188
- const cell = map.get(key)?.asCell();
189
- if (cell === undefined) {
190
- return undefined;
191
- }
192
- try {
193
- return decodeSignBidirectionalEvent(cell.value, requestId);
194
- }
195
- catch {
196
- return undefined; // a cell that is not a decodable request record
197
- }
115
+ // The ledger's own keyed lookup on the ledger's own key type: toValue
116
+ // produces the canonical (zero-trimmed) key form the map stores.
117
+ const entry = map.get({
118
+ value: requestIdType.toValue(requestIdBytes(requestId)),
119
+ alignment: requestIdType.alignment(),
120
+ });
121
+ const cell = entry?.asCell();
122
+ if (cell === undefined) {
123
+ return undefined; // id absent, or its entry is not a cell
124
+ }
125
+ let record;
126
+ try {
127
+ record = decodeSignBidirectionalEvent(cell);
128
+ }
129
+ catch {
130
+ return undefined; // a cell that is not a decodable request record
131
+ }
132
+ if (requestIdHex(calculateRequestId(record)) !== requestId) {
133
+ return undefined; // spoofed or wrongly filed record
198
134
  }
199
- return undefined; // id absent from the index
135
+ return record;
200
136
  }
201
137
  //# sourceMappingURL=signature-requests-state-reader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signature-requests-state-reader.js","sourceRoot":"","sources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
+ {"version":3,"file":"signature-requests-state-reader.js","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,EAAE;AACF,6DAA6D;AAC7D,4EAA4E;AAC5E,0EAA0E;AAC1E,2DAA2D;AAI3D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAyB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,oCAAoC,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,cAAc,EAEd,YAAY,EACZ,aAAa,EAGb,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAE9B,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,gBAAgB;AAChB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,SAAS,4BAA4B,CAAC,IAAkB;IACtD,MAAM,IAAI,GAAG,gBAAgB,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC5C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,0BAA0B,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,2BAA2B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAClF,CAAC;IACJ,CAAC;IACD,uEAAuE;IACvE,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,WAAW,CAAC,Q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,CAAC;AAChB,CAAC"}
@@ -1,22 +1,23 @@
1
- import type { SignBidirectionalEvent } from "./signet-requests.ts";
2
1
  import type { SignatureRespondedEvent } from "./signet-contract-events.ts";
2
+ import { type SignBidirectionalEvent } from "./signet-requests.ts";
3
3
  /**
4
- * Recover the EVM address that produced a response signature, over the
5
- * signing hash of the transaction the request describes.
4
+ * Recover the address that produced a response signature, over the signing
5
+ * digest of the transaction the request describes: the response-side
6
+ * dispatch on the request's `txParamType`.
6
7
  *
7
8
  * @param request - The on-ledger request record the response answers.
8
9
  * @param response - The posted signature record answering it.
9
10
  * @returns The checksummed recovered signer address.
10
- * @throws Error if the response is not a decodable signature or the request
11
- * record is malformed (see
11
+ * @throws {Error} If the request's `txParamType` names a decomposition this
12
+ * library does not sign-verify, the response is not a decodable signature,
13
+ * or the request record is malformed (see
12
14
  * {@link signBidirectionalEventToUnsignedEvmTransaction}).
13
15
  */
14
16
  export declare function recoverSignatureResponseSigner(request: SignBidirectionalEvent, response: SignatureRespondedEvent): string;
15
17
  /**
16
18
  * Verify a posted response against its request: does the signature recover
17
- * to `expectedSigner`? Never throws: a response that is malformed or signed
18
- * by anyone else is simply not valid, which is the expected state of affairs
19
- * on an unauthenticated log.
19
+ * to `expectedSigner`? Never throws: a malformed or wrongly-signed response
20
+ * is simply not valid.
20
21
  *
21
22
  * @param request - The on-ledger request record the response answers.
22
23
  * @param response - The posted signature record answering it.
@@ -1 +1 @@
1
- {"version":3,"file":"signature-response-verification.d.ts","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,GAChC,MAAM,CAKR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,EACjC,cAAc,EAAE,MAAM,GACrB,OAAO,CAST"}
1
+ {"version":3,"file":"signature-response-verification.d.ts","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,EAAE,KAAK,sBAAsB,EAAe,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,GAChC,MAAM,CAUR;AAED;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,EACjC,cAAc,EAAE,MAAM,GACrB,OAAO,CAMT"}
@@ -1,32 +1,36 @@
1
1
  // Client-side verification of MPC signature responses. The signet contract
2
2
  // emits signature responses UNAUTHENTICATED (see the module header in
3
- // Signet.compact), so a poller must verify every posted response
4
- // before trusting it: rebuild the unsigned EVM transaction from the on-ledger
5
- // request record, assembled exactly as the MPC assembles it (sig-net/mpc
6
- // response server, managed/erc20-vault/signet/calldata-builder.ts), and
7
- // check that the posted signature record recovers to the requester's derived
8
- // EVM address over that transaction's signing hash.
3
+ // Signet.compact), so a poller must verify every posted response before
4
+ // trusting it.
9
5
  import { getAddress, recoverAddress } from "ethers";
10
- import { signBidirectionalEventToUnsignedEvmTransaction, signatureRespondedEventToSignature, } from "./signet-evtype2tx-requests.js";
6
+ import { signatureRespondedEventToSignature } from "./ecdsa-attestation.js";
7
+ import { signBidirectionalEventToUnsignedEvmTransaction } from "./signet-evtype2tx-requests.js";
8
+ import { TxParamType } from "./signet-requests.js";
11
9
  /**
12
- * Recover the EVM address that produced a response signature, over the
13
- * signing hash of the transaction the request describes.
10
+ * Recover the address that produced a response signature, over the signing
11
+ * digest of the transaction the request describes: the response-side
12
+ * dispatch on the request's `txParamType`.
14
13
  *
15
14
  * @param request - The on-ledger request record the response answers.
16
15
  * @param response - The posted signature record answering it.
17
16
  * @returns The checksummed recovered signer address.
18
- * @throws Error if the response is not a decodable signature or the request
19
- * record is malformed (see
17
+ * @throws {Error} If the request's `txParamType` names a decomposition this
18
+ * library does not sign-verify, the response is not a decodable signature,
19
+ * or the request record is malformed (see
20
20
  * {@link signBidirectionalEventToUnsignedEvmTransaction}).
21
21
  */
22
22
  export function recoverSignatureResponseSigner(request, response) {
23
- return recoverAddress(signBidirectionalEventToUnsignedEvmTransaction(request).unsignedHash, signatureRespondedEventToSignature(response));
23
+ switch (request.txParamType) {
24
+ case TxParamType.evmType2:
25
+ return recoverAddress(signBidirectionalEventToUnsignedEvmTransaction(request).unsignedHash, signatureRespondedEventToSignature(response));
26
+ default:
27
+ throw new Error(`unsupported txParamType ${String(request.txParamType)}`);
28
+ }
24
29
  }
25
30
  /**
26
31
  * Verify a posted response against its request: does the signature recover
27
- * to `expectedSigner`? Never throws: a response that is malformed or signed
28
- * by anyone else is simply not valid, which is the expected state of affairs
29
- * on an unauthenticated log.
32
+ * to `expectedSigner`? Never throws: a malformed or wrongly-signed response
33
+ * is simply not valid.
30
34
  *
31
35
  * @param request - The on-ledger request record the response answers.
32
36
  * @param response - The posted signature record answering it.
@@ -35,8 +39,7 @@ export function recoverSignatureResponseSigner(request, response) {
35
39
  */
36
40
  export function verifySignatureRespondedEvent(request, response, expectedSigner) {
37
41
  try {
38
- return (recoverSignatureResponseSigner(request, response) ===
39
- getAddress(expectedSigner));
42
+ return recoverSignatureResponseSigner(request, response) === getAddress(expectedSigner);
40
43
  }
41
44
  catch {
42
45
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEAAsE;AACtE,iEAAiE;AACjE,8EAA8E;AAC9E,yEAAyE;AACzE,wEAAwE;AACxE,6EAA6E;AAC7E,oDAAoD;AAEpD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EACL,8CAA8C,EAC9C,kCAAkC,GACnC,MAAM,gCAAgC,CAAC;AAIxC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B,EAC/B,QAAiC;IAEjC,OAAO,cAAc,CACnB,8CAA8C,CAAC,OAAO,CAAC,CAAC,YAAY,EACpE,kCAAkC,CAAC,QAAQ,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAA+B,EAC/B,QAAiC,EACjC,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,CACL,8BAA8B,CAAC,OAAO,EAAE,QAAQ,CAAC;YACjD,UAAU,CAAC,cAAc,CAAC,CAC3B,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,eAAe;AAEf,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,8CAA8C,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAA+B,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B,EAC/B,QAAiC;IAEjC,QAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;QAC5B,KAAK,WAAW,CAAC,QAAQ;YACvB,OAAO,cAAc,CACnB,8CAA8C,CAAC,OAAO,CAAC,CAAC,YAAY,EACpE,kCAAkC,CAAC,QAAQ,CAAC,CAC7C,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAA+B,EAC/B,QAAiC,EACjC,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,8BAA8B,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,UAAU,CAAC,cAAc,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}