@sig-net/midnight 0.24.0-rc.1 → 0.24.0-rc.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.
Files changed (58) hide show
  1. package/README.md +19 -24
  2. package/dist/compact-descriptors.d.ts +22 -7
  3. package/dist/compact-descriptors.d.ts.map +1 -1
  4. package/dist/compact-descriptors.js +39 -28
  5. package/dist/compact-descriptors.js.map +1 -1
  6. package/dist/constants.d.ts +3 -22
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +3 -25
  9. package/dist/constants.js.map +1 -1
  10. package/dist/ecdsa-attestation.d.ts +43 -15
  11. package/dist/ecdsa-attestation.d.ts.map +1 -1
  12. package/dist/ecdsa-attestation.js +47 -17
  13. package/dist/ecdsa-attestation.js.map +1 -1
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +5 -5
  17. package/dist/index.js.map +1 -1
  18. package/dist/managed/compiler/contract-info.json +1212 -13
  19. package/dist/managed/compiler/contract-manifest.json +8 -8
  20. package/dist/managed/contract/index.d.ts +282 -7
  21. package/dist/managed/contract/index.js +1072 -161
  22. package/dist/managed/contract/index.js.map +1 -1
  23. package/dist/mpc-output-cache.d.ts +5 -29
  24. package/dist/mpc-output-cache.d.ts.map +1 -1
  25. package/dist/mpc-output-cache.js +8 -42
  26. package/dist/mpc-output-cache.js.map +1 -1
  27. package/dist/signature-requests-state-reader.js +3 -3
  28. package/dist/signature-requests-state-reader.js.map +1 -1
  29. package/dist/signet-contract-events.d.ts +40 -10
  30. package/dist/signet-contract-events.d.ts.map +1 -1
  31. package/dist/signet-contract-events.js +79 -29
  32. package/dist/signet-contract-events.js.map +1 -1
  33. package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -1
  34. package/dist/signet-evtype2tx-record-decoding.js +6 -5
  35. package/dist/signet-evtype2tx-record-decoding.js.map +1 -1
  36. package/dist/signet-evtype2tx-requests.d.ts +17 -12
  37. package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
  38. package/dist/signet-evtype2tx-requests.js +85 -16
  39. package/dist/signet-evtype2tx-requests.js.map +1 -1
  40. package/dist/signet-request-id.d.ts +5 -2
  41. package/dist/signet-request-id.d.ts.map +1 -1
  42. package/dist/signet-request-id.js +21 -9
  43. package/dist/signet-request-id.js.map +1 -1
  44. package/dist/signet-request-response-reader.d.ts +2 -4
  45. package/dist/signet-request-response-reader.d.ts.map +1 -1
  46. package/dist/signet-request-response-reader.js +7 -11
  47. package/dist/signet-request-response-reader.js.map +1 -1
  48. package/dist/signet-requests.d.ts +48 -17
  49. package/dist/signet-requests.d.ts.map +1 -1
  50. package/dist/signet-requests.js +18 -6
  51. package/dist/signet-requests.js.map +1 -1
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.d.ts.map +1 -1
  54. package/dist/testing.js +3 -8
  55. package/dist/testing.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/Signet.compact +258 -80
  58. package/src/circuits.compact +68 -13
package/README.md CHANGED
@@ -35,7 +35,7 @@ The protocol and integration documentation lives in the [sig-net/midnight-integr
35
35
 
36
36
  - [Sign Bidirectional Flow](https://github.com/sig-net/midnight-integration/blob/main/README.md#sign-bidirectional-protocol-flow): the 5-step protocol this package speaks, with diagram, failure handling and output recovery.
37
37
  - [Derived keys](https://github.com/sig-net/midnight-integration/blob/main/README.md#derived-keys): the request signing key and the response key, and how the MPC derives them.
38
- - [Handling Failure](https://github.com/sig-net/midnight-integration/blob/main/README.md#handling-failure): the fixed 5-byte failure payload the MPC attests for a failed foreign transaction, how a contract tells it apart from a success, and which respond schemas cannot.
38
+ - [Handling Failure](https://github.com/sig-net/midnight-integration/blob/main/README.md#handling-failure): the empty output and failure output kind the MPC attests for a failed foreign transaction, and how a contract routes on the verified kind.
39
39
  - [Integrator Guide](https://github.com/sig-net/midnight-integration/blob/main/README.md#integrator-guide): the once-off setup and the per-request runtime steps, built on this package's exports.
40
40
  - [EVM Type 2 transactions and ABI calldata words](https://github.com/sig-net/midnight-integration/blob/main/README.md#evm-type-2-transactions-and-abi-calldata-words): building calldata words in-circuit and deserialising respond payloads.
41
41
 
@@ -51,11 +51,11 @@ What your contract imports with `import "@sig-net/midnight/src/Signet"`:
51
51
 
52
52
  | Task | Exports |
53
53
  |---|---|
54
- | Declare the protocol ledger state (setup step 3) | `SignBidirectionalEventMap` (the request map the MPC reads) and `SignetSigner` (the Signet singleton's cross-contract-call interface, pinned at deploy). |
55
- | Build and store a signature request (runtime step 1) | `constructSignBidirectionalEvent` and `calculateRequestId`, over the request structs `EvmType2TxParams`, `EvmCalldata` and `EvmAccessListEntry`. |
54
+ | Declare the protocol ledger state (setup step 3) | `SignBidirectionalEventMapV1` (the request map the MPC reads) and `SignetSigner` (the Signet singleton's cross-contract-call interface, pinned at deploy). |
55
+ | Build and store a signature request (runtime step 1) | `constructSignBidirectionalEventV1` and `calculateEvmType2RequestIdV1`, over the request structs `EvmType2TxParams`, `EvmCalldata` and `EvmAccessListEntry`. The id hashes `calculateEvmType2TxParamsDigestV1`, a digest over the transaction's used entries only, so it ignores your struct's capacities and unused slots. |
56
56
  | Notify the MPC of the request (runtime step 1) | `constructSignBidirectionalEventNotificationV1`: packs your contract's address and the request map's ledger-tree path. |
57
57
  | Build and read calldata words in-circuit | The builders `evmAddressAbiWord`, `numericAbiWord` and `boolAbiWord`, and the readers `abiWordToUint128` and `abiWordToBool` (see [EVM Type 2 transactions and ABI calldata words](https://github.com/sig-net/midnight-integration/blob/main/README.md#evm-type-2-transactions-and-abi-calldata-words)). |
58
- | Verify the execution attestation (runtime step 5) | `verifyRespondBidirectionalEvent`: recomputes the attestation digest from the output bytes and checks the MPC's signature against your pinned response key. |
58
+ | Verify the execution attestation (runtime step 5) | `verifyRespondBidirectionalEventV1`: recomputes the attestation digest from the output bytes and the posted request id, output kind and block height, and checks the MPC's signature against your pinned response key. |
59
59
 
60
60
  ### TypeScript library
61
61
 
@@ -69,12 +69,14 @@ What clients import from `@sig-net/midnight`:
69
69
  | Derive the response key your deploy pins | `deriveMidnightResponseKey`: the key `initialise` stores (setup step 4), derived from your contract's address. |
70
70
  | Look up published counterparty values | `MidnightNetwork`, `getMpcRootPublicKey` and `getSignetContractAddress`: the fixed per-network values (see the notes in [Runtime](https://github.com/sig-net/midnight-integration/blob/main/README.md#runtime)). |
71
71
  | Accept an MPC public key in any published spelling | `parseSecp256k1PublicKey` (to a Compact `Secp256k1Point`) and `normaliseSecp256k1PublicKey` (to the canonical `0x04…` uncompressed SEC1 hex): both take SEC1 hex, compressed or uncompressed with an optional `0x`, and NEAR's `secp256k1:<base58>`. |
72
- | Read a text field of a request record | `asciiUnpadded`: the inverse of `asciiPadded`, for the zero-padded text fields (`caip2Id`, the two schemas). |
72
+ | Read a text field of a request record | `asciiUnpadded`: the inverse of `asciiPadded`, for the zero-padded text fields (`executionDest`, the two schemas). |
73
73
  | Compute a request id off chain | `calculateRequestId`: the TS twin of the on-chain circuit, plus `requestIdHex` and `parseRequestIdHex` for the hex form. |
74
74
  | Compose expected calldata words off chain (UIs, expected-record builders, tests) | The builders `numericAbiWord`, `evmAddressAbiWord` and `boolAbiWord`, and the readers `abiWordToUint128` and `abiWordToBool`: TS twins of the circuits under identical names. |
75
+ | Digest a transaction decomposition off chain | `calculateEvmType2TxParamsDigest`: the TS twin of the circuit, what `calculateRequestId` hashes in place of the parameters. |
75
76
  | Convert a foreign execution output into respond bytes | `deserializeEvmOutput` (raw EVM return data to named values) and `serializeRespondOutput` (named values to the packed respond payload the MPC attests): together they rebuild the `serializedOutput` of steps 4 and 5. |
76
- | Recognise a failed remote execution | `MPC_FAILURE_OUTPUT` and `isMpcFailureOutput`: the MPC's fixed 5-byte failure payload for reverted or replaced transactions (see [Handling Failure](https://github.com/sig-net/midnight-integration/blob/main/README.md#handling-failure)). |
77
- | Read the attested output from the MPC's output cache | `MpcOutputCacheReader` (`fetchAttestedOutput` returns the block height and the output; `encodeAttestedOutput` / `decodeAttestedOutput` are the object format): one reader per network and Signet singleton pair, over the public bucket an MPC configured with output storage writes each request's exact attested bytes to before posting, defaulting to the bucket `getMpcOutputCacheUrl` publishes for the network. `fetchSerializedOutput` yields the bytes step 5 verifies, `undefined` while the object is not written yet. |
77
+ | Recognise a failed remote execution | `OutputKind` on the verified `RespondBidirectionalEvent`: `failed` or `unviable` beside an empty output (see [Handling Failure](https://github.com/sig-net/midnight-integration/blob/main/README.md#handling-failure)). |
78
+ | Read the attested output bytes from the MPC's output cache | `MpcOutputCacheReader`: one reader per network and Signet singleton pair, over the public bucket an MPC configured with output storage writes each request's exact attested bytes to before posting, defaulting to the bucket `getMpcOutputCacheUrl` publishes for the network. `fetchSerializedOutput` yields the bytes step 5 verifies, `undefined` while the object is not written yet. |
79
+ | Hand a verified attestation to your verify circuit (runtime step 5) | `respondBidirectionalEventToCircuitInput`: flips the wire event's big-endian `bigR.x` and `s` into the little-endian record `verifyRespondBidirectionalEventV1` reads. |
78
80
  | Verify attestations without the reader | `verifyRespondBidirectionalSignature`: the check the reader runs internally, exposed for custom pipelines. |
79
81
  | Mint attestations in your contract's unit tests | The `@sig-net/midnight/testing` entry point, see [Testing entry point](#testing-entry-point). |
80
82
  | Discover requests MPC-side (responders, background workers) | The discovery primitives: decode the signet contract's emitted notification events with `decodeSignetEventNamed(event, SignetEventName.SignBidirectionalEvent)` (or every kind at once with `decodeSignetEvent`, which throws on an undecodable payload anyone can emit, or its non-throwing sibling `tryDecodeSignetEvent`), then resolve each pointer against the named caller's own request map with `lookupSignetRequestAt` (the authenticated read). The polling loop belongs to the responder. |
@@ -96,23 +98,16 @@ stack and no MPC:
96
98
 
97
99
  ```ts
98
100
  import { verifyRespondBidirectionalSignature } from "@sig-net/midnight"; // runtime
99
- import {
100
- calculateSignetAttestationDigest,
101
- ecdsaSignatureToMpcSignature,
102
- secp256k1PublicKeyOf,
103
- signAttestationDigest,
104
- } from "@sig-net/midnight/testing"; // tests only
105
-
106
- // A real RespondBidirectionalEvent for (requestId, output), signed by secretKey.
107
- // It verifies, in-circuit and off chain, against secp256k1PublicKeyOf(secretKey).
108
- const event = {
109
- signature: ecdsaSignatureToMpcSignature(
110
- signAttestationDigest(
111
- calculateSignetAttestationDigest(requestId, serializedOutput),
112
- secretKey,
113
- ),
114
- ),
115
- };
101
+ import { attestRespondBidirectional, secp256k1PublicKeyOf } from "@sig-net/midnight/testing"; // tests only
102
+
103
+ // A real RespondBidirectionalEvent for (requestId, blockHeight, outputKind,
104
+ // serializedOutput), signed by secretKey: the request id, block height, kind,
105
+ // output width, attestation digest and signature the MPC would post. It
106
+ // verifies, in-circuit and off chain, against secp256k1PublicKeyOf(secretKey).
107
+ const event = attestRespondBidirectional(
108
+ { requestId, blockHeight, outputKind, serializedOutput },
109
+ secretKey,
110
+ );
116
111
  ```
117
112
 
118
113
  ## Related packages
@@ -1,5 +1,9 @@
1
1
  import { type AlignedValue, type CompactType, CompactTypeBytes, CompactTypeUnsignedInteger } from "@midnight-ntwrk/compact-runtime";
2
- /** Descriptor of a Compact `Bytes<4>`. */
2
+ /** `Boolean`. */
3
+ export declare const BOOLEAN: CompactType<boolean>;
4
+ /** `Field`: the accumulator of the transaction digest folds. */
5
+ export declare const FIELD: CompactType<bigint>;
6
+ /** `Bytes<4>`. */
3
7
  export declare const BYTES_4: CompactTypeBytes;
4
8
  /** Descriptor of a Compact `Bytes<20>`. */
5
9
  export declare const BYTES_20: CompactTypeBytes;
@@ -87,13 +91,24 @@ export declare function decodeExactly<T>(type: CompactType<T>, atoms: readonly U
87
91
  */
88
92
  export declare function declaredWidths(cell: AlignedValue, what: string): number[];
89
93
  /**
90
- * Descriptor of the Compact tuple `[RequestId, Uint<64>, Uint<64>, Bytes<serializedOutputLength>]`
91
- * the attestation digest hashes, composed the way the compiler composes a
92
- * tuple: the elements' alignments and values concatenated in order. The output
93
- * width enters the descriptor, so it is fixed per call rather than a constant.
94
+ * Descriptor of a Compact tuple, composed the way the compiler composes one:
95
+ * the elements' alignments and values concatenated in order.
96
+ *
97
+ * @param elements - One descriptor per tuple element, in order.
98
+ * @returns The tuple's descriptor.
99
+ */
100
+ export declare function compactTupleDescriptor<T extends unknown[]>(elements: {
101
+ [K in keyof T]: CompactType<T[K]>;
102
+ }): CompactType<T>;
103
+ /**
104
+ * Descriptor of the Compact tuple
105
+ * `[RequestId, Uint<64>, OutputKind, Uint<64>, Bytes<serializedOutputLength>]`
106
+ * the attestation digest hashes (request id, block height, output kind,
107
+ * output length, output). The output width enters the descriptor, so it is
108
+ * built per call.
94
109
  *
95
110
  * @param serializedOutputLength - Declared width of the output element, in bytes.
96
- * @returns The triple descriptor for {@link calculateSignetAttestationDigest}.
111
+ * @returns The tuple descriptor for {@link calculateSignetAttestationDigest}.
97
112
  */
98
- export declare function attestationPreimageDescriptor(serializedOutputLength: number): CompactType<[Uint8Array, bigint, bigint, Uint8Array]>;
113
+ export declare function attestationPreimageDescriptor(serializedOutputLength: number): CompactType<[Uint8Array, bigint, number, bigint, Uint8Array]>;
99
114
  //# sourceMappingURL=compact-descriptors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compact-descriptors.d.ts","sourceRoot":"","sources":["../src/compact-descriptors.ts"],"names":[],"mappings":"AA4BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AAKzC,0CAA0C;AAC1C,eAAO,MAAM,OAAO,kBAA0B,CAAC;AAC/C,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,2CAA2C;AAC3C,eAAO,MAAM,QAAQ,kBAA2B,CAAC;AACjD,yCAAyC;AACzC,eAAO,MAAM,MAAM,4BAAmD,CAAC;AACvE,0CAA0C;AAC1C,eAAO,MAAM,OAAO,4BAAoD,CAAC;AACzE,0CAA0C;AAC1C,eAAO,MAAM,OAAO,4BAAoD,CAAC;AACzE,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CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAKtF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,IAAI,EAAE,MAAM,GACX,CAAC,CASH;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAoBzE;AASD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,QAAQ,EAAE;KACnE,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,GAAG,WAAW,CAAC,CAAC,CAAC,CAOjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,EAAE,MAAM,GAC7B,WAAW,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAQ/D"}
@@ -25,10 +25,14 @@
25
25
  // (that package describes the `serialize<T, N>` wire format, a different
26
26
  // layer). Package-internal: consumers use the reader/request functions built
27
27
  // on top, never these directly.
28
- import { CompactTypeBoolean, CompactTypeBytes, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
28
+ import { CompactTypeBoolean, CompactTypeBytes, CompactTypeEnum, CompactTypeField, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
29
29
  // Runtime descriptors of the Compact base types, at the same literals the
30
30
  // compiler emits.
31
- /** Descriptor of a Compact `Bytes<4>`. */
31
+ /** `Boolean`. */
32
+ export const BOOLEAN = CompactTypeBoolean;
33
+ /** `Field`: the accumulator of the transaction digest folds. */
34
+ export const FIELD = CompactTypeField;
35
+ /** `Bytes<4>`. */
32
36
  export const BYTES_4 = new CompactTypeBytes(4);
33
37
  /** Descriptor of a Compact `Bytes<20>`. */
34
38
  export const BYTES_20 = new CompactTypeBytes(20);
@@ -140,35 +144,42 @@ export function declaredWidths(cell, what) {
140
144
  });
141
145
  }
142
146
  /**
143
- * Descriptor of the Compact tuple `[RequestId, Uint<64>, Uint<64>, Bytes<serializedOutputLength>]`
144
- * the attestation digest hashes, composed the way the compiler composes a
145
- * tuple: the elements' alignments and values concatenated in order. The output
146
- * width enters the descriptor, so it is fixed per call rather than a constant.
147
+ * Descriptor of Signet.compact's three-variant `OutputKind` enum, at the
148
+ * literal the compiler emits (highest variant index 2, one byte). Adding a
149
+ * variant to the Compact enum means raising the index here in lockstep.
150
+ */
151
+ const OUTPUT_KIND = new CompactTypeEnum(2, 1);
152
+ /**
153
+ * Descriptor of a Compact tuple, composed the way the compiler composes one:
154
+ * the elements' alignments and values concatenated in order.
147
155
  *
148
- * @param serializedOutputLength - Declared width of the output element, in bytes.
149
- * @returns The triple descriptor for {@link calculateSignetAttestationDigest}.
156
+ * @param elements - One descriptor per tuple element, in order.
157
+ * @returns The tuple's descriptor.
150
158
  */
151
- export function attestationPreimageDescriptor(serializedOutputLength) {
152
- const output = new CompactTypeBytes(serializedOutputLength);
159
+ export function compactTupleDescriptor(elements) {
153
160
  return {
154
- alignment: () => [
155
- ...BYTES_32.alignment(),
156
- ...UINT_64.alignment(),
157
- ...UINT_64.alignment(),
158
- ...output.alignment(),
159
- ],
160
- toValue: ([requestId, blockHeight, outputLength, serializedOutput]) => [
161
- ...BYTES_32.toValue(requestId),
162
- ...UINT_64.toValue(blockHeight),
163
- ...UINT_64.toValue(outputLength),
164
- ...output.toValue(serializedOutput),
165
- ],
166
- fromValue: (value) => [
167
- BYTES_32.fromValue(value),
168
- UINT_64.fromValue(value),
169
- UINT_64.fromValue(value),
170
- output.fromValue(value),
171
- ],
161
+ alignment: () => elements.flatMap((element) => element.alignment()),
162
+ toValue: (values) => elements.flatMap((element, index) => element.toValue(values[index])),
163
+ fromValue: (value) => elements.map((element) => element.fromValue(value)),
172
164
  };
173
165
  }
166
+ /**
167
+ * Descriptor of the Compact tuple
168
+ * `[RequestId, Uint<64>, OutputKind, Uint<64>, Bytes<serializedOutputLength>]`
169
+ * the attestation digest hashes (request id, block height, output kind,
170
+ * output length, output). The output width enters the descriptor, so it is
171
+ * built per call.
172
+ *
173
+ * @param serializedOutputLength - Declared width of the output element, in bytes.
174
+ * @returns The tuple descriptor for {@link calculateSignetAttestationDigest}.
175
+ */
176
+ export function attestationPreimageDescriptor(serializedOutputLength) {
177
+ return compactTupleDescriptor([
178
+ BYTES_32,
179
+ UINT_64,
180
+ OUTPUT_KIND,
181
+ UINT_64,
182
+ new CompactTypeBytes(serializedOutputLength),
183
+ ]);
184
+ }
174
185
  //# sourceMappingURL=compact-descriptors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compact-descriptors.js","sourceRoot":"","sources":["../src/compact-descriptors.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,6EAA6E;AAC7E,0CAA0C;AAC1C,mFAAmF;AACnF,gFAAgF;AAChF,oFAAoF;AACpF,eAAe;AACf,uFAAuF;AACvF,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,8BAA8B;AAC9B,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,4CAA4C;AAC5C,EAAE;AACF,sEAAsE;AACtE,wBAAwB;AACxB,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,gCAAgC;AAEhC,OAAO,EAGL,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AAEzC,0EAA0E;AAC1E,kBAAkB;AAElB,0CAA0C;AAC1C,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC/C,2CAA2C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AAM,UAAU,sBAAsB,CAAsB,QAE3D;IACC,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACnE,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAClB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAA6B,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5F,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM;KAC/E,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAC3C,sBAA8B;IAE9B,OAAO,sBAAsB,CAAmD;QAC9E,QAAQ;QACR,OAAO;QACP,WAAW;QACX,OAAO;QACP,IAAI,gBAAgB,CAAC,sBAAsB,CAAC;KAC7C,CAAC,CAAC;AACL,CAAC"}
@@ -1,31 +1,12 @@
1
- /** Width of `SignBidirectionalEvent.caip2Id` (`Bytes<32>`). */
2
- export declare const CAIP2_ID_BYTES = 32;
1
+ /** Width of `SignBidirectionalEvent.executionDest` (`Bytes<32>`): a zero-padded CAIP-2 id. */
2
+ export declare const EXECUTION_DEST_BYTES = 32;
3
3
  /** Width of `SignBidirectionalEvent.params` (`Bytes<64>`). */
4
4
  export declare const MPC_PARAMS_BYTES = 64;
5
5
  /** Width of `EvmCalldata.selector` (`Bytes<4>`): the literal first 4 calldata bytes. */
6
6
  export declare const SELECTOR_BYTES = 4;
7
- /**
8
- * The complete serialised output the MPC attests for a FAILED remote
9
- * execution (reverted or replaced transaction): the 4-byte error marker
10
- * `0xdeadbeef` followed by one `0x01` byte, mirroring the canonical MPC's
11
- * failure payload (sig-net/mpc, node/src/respond_bidirectional.rs). A
12
- * respond schema whose packed width is exactly 5 bytes could produce a
13
- * legitimate output equal to this sentinel: such clients must route
14
- * settlement by digest-candidate matching, never by inspecting output
15
- * bytes. See {@link isMpcFailureOutput}.
16
- */
17
- export declare const MPC_FAILURE_OUTPUT: Uint8Array<ArrayBuffer>;
18
- /**
19
- * Whether an attested serialised output IS the MPC's fixed failure payload:
20
- * exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT}.
21
- *
22
- * @param serializedOutput - The attested serialised output.
23
- * @returns `true` when the output equals the MPC failure payload exactly.
24
- */
25
- export declare function isMpcFailureOutput(serializedOutput: Uint8Array): boolean;
26
7
  /**
27
8
  * Default MPC key version (`keyVersion` field value). The canonical MPC
28
- * (and `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
9
+ * (and `constructSignBidirectionalEventV1`) requires `keyVersion >= 1`.
29
10
  */
30
11
  export declare const SIGNET_DEFAULT_KEY_VERSION = 1n;
31
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AASA,+DAA+D;AAC/D,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,wFAAwF;AACxF,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,yBAAiD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAKxE;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAUpE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;A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YAAY;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;AAgBnF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAMtE;AAYD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAM3E;AAcD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAMvE"}
package/dist/constants.js CHANGED
@@ -6,37 +6,15 @@
6
6
  //
7
7
  // The routing constants belong in github.com/sig-net/signet.js, kept here
8
8
  // until upstreamed.
9
- /** Width of `SignBidirectionalEvent.caip2Id` (`Bytes<32>`). */
10
- export const CAIP2_ID_BYTES = 32;
9
+ /** Width of `SignBidirectionalEvent.executionDest` (`Bytes<32>`): a zero-padded CAIP-2 id. */
10
+ export const EXECUTION_DEST_BYTES = 32;
11
11
  /** Width of `SignBidirectionalEvent.params` (`Bytes<64>`). */
12
12
  export const MPC_PARAMS_BYTES = 64;
13
13
  /** Width of `EvmCalldata.selector` (`Bytes<4>`): the literal first 4 calldata bytes. */
14
14
  export const SELECTOR_BYTES = 4;
15
- /**
16
- * The complete serialised output the MPC attests for a FAILED remote
17
- * execution (reverted or replaced transaction): the 4-byte error marker
18
- * `0xdeadbeef` followed by one `0x01` byte, mirroring the canonical MPC's
19
- * failure payload (sig-net/mpc, node/src/respond_bidirectional.rs). A
20
- * respond schema whose packed width is exactly 5 bytes could produce a
21
- * legitimate output equal to this sentinel: such clients must route
22
- * settlement by digest-candidate matching, never by inspecting output
23
- * bytes. See {@link isMpcFailureOutput}.
24
- */
25
- export const MPC_FAILURE_OUTPUT = new Uint8Array([0xde, 0xad, 0xbe, 0xef, 0x01]);
26
- /**
27
- * Whether an attested serialised output IS the MPC's fixed failure payload:
28
- * exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT}.
29
- *
30
- * @param serializedOutput - The attested serialised output.
31
- * @returns `true` when the output equals the MPC failure payload exactly.
32
- */
33
- export function isMpcFailureOutput(serializedOutput) {
34
- return (serializedOutput.length === MPC_FAILURE_OUTPUT.length &&
35
- MPC_FAILURE_OUTPUT.every((byte, index) => serializedOutput[index] === byte));
36
- }
37
15
  /**
38
16
  * Default MPC key version (`keyVersion` field value). The canonical MPC
39
- * (and `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
17
+ * (and `constructSignBidirectionalEventV1`) requires `keyVersion >= 1`.
40
18
  */
41
19
  export const SIGNET_DEFAULT_KEY_VERSION = 1n;
42
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,2EAA2E;AAC3E,mEAAmE;AACnE,qEAAqE;AACrE,sDAAsD;AACtD,EAAE;AACF,0EAA0E;AAC1E,oBAAoB;AAEpB,+DAA+D;AAC/D,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,gBAA4B;IAC7D,OAAO,CACL,gBAAgB,CAAC,MAAM,KAAK,kBAAkB,CAAC,MAAM;QACrD,kBAAkB,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAC5E,CAAC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,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { type Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
2
2
  import { secp256k1 } from "@noble/curves/secp256k1.js";
3
3
  import { Signature } from "ethers";
4
+ import type { OutputKind } from "./managed/contract/index.js";
4
5
  import type { MpcSignature, RespondBidirectionalEvent, SignatureRespondedEvent } from "./signet-contract-events.ts";
5
6
  import type { RequestId } from "./signet-requests.ts";
6
7
  export type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
@@ -70,11 +71,12 @@ export declare function signatureRespondedEventToSignature(response: SignatureRe
70
71
  * it is exported through the `./testing` entry point with the other
71
72
  * posting-side helpers.
72
73
  *
74
+ * @param requestId - The 32-byte request id the signature answers.
73
75
  * @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
74
76
  * @returns The response record, ready to post.
75
77
  * @throws {Error} If `r` is not the x coordinate of a secp256k1 point.
76
78
  */
77
- export declare function signatureToSignatureRespondedEvent(signature: Pick<Signature, "r" | "s" | "yParity">): SignatureRespondedEvent;
79
+ export declare function signatureToSignatureRespondedEvent(requestId: RequestId, signature: Pick<Signature, "r" | "s" | "yParity">): SignatureRespondedEvent;
78
80
  /** A point in noble's own representation, for curve arithmetic. */
79
81
  type NobleSecp256k1Point = ReturnType<typeof secp256k1.Point.fromHex>;
80
82
  /**
@@ -132,21 +134,47 @@ export declare function normaliseSecp256k1PublicKey(value: string): string;
132
134
  export declare function secp256k1PublicKeyOf(secretKey: Uint8Array): Secp256k1Point;
133
135
  /**
134
136
  * The attestation digest of a respond-bidirectional response:
135
- * `upgradeFromTransient(transientHash([requestId, blockHeight, outputLength, serializedOutput]))`,
136
- * the 32-byte digest the MPC ECDSA-signs to attest a remote execution. TS twin of
137
- * the size-generic Compact circuit of the same name.
137
+ * `upgradeFromTransient(transientHash([requestId, blockHeight, outputKind, outputLength, serializedOutput]))`,
138
+ * the 32-byte digest the MPC ECDSA-signs to attest a remote execution. TS
139
+ * twin of the size-generic Compact circuit `calculateSignetAttestationDigestV1`.
138
140
  *
139
141
  * @param requestId - The 32-byte request id the response answers.
140
- * @param blockHeight - The destination block height the outcome is final at.
142
+ * @param blockHeight - Height of the finalised destination block holding the
143
+ * attested transaction, in the destination chain's own numbering.
144
+ * @param outputKind - The MPC's verdict on the execution.
141
145
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
142
146
  * @returns The 32-byte attestation digest.
143
147
  */
144
- export declare function calculateSignetAttestationDigest(requestId: RequestId, blockHeight: bigint, serializedOutput: Uint8Array): Uint8Array;
148
+ export declare function calculateSignetAttestationDigest(requestId: RequestId, blockHeight: bigint, outputKind: OutputKind, serializedOutput: Uint8Array): Uint8Array;
149
+ /** What a respond-bidirectional attestation commits to: the digest's inputs. */
150
+ export interface RespondBidirectionalAttestation {
151
+ /** The 32-byte request id the response answers. */
152
+ requestId: RequestId;
153
+ /** Height of the finalised destination block holding the attested transaction. */
154
+ blockHeight: bigint;
155
+ /** The MPC's verdict on the execution. */
156
+ outputKind: OutputKind;
157
+ /** The serialised execution output, exact unpadded bytes (empty for a failure). */
158
+ serializedOutput: Uint8Array;
159
+ }
160
+ /**
161
+ * Mint the record the MPC posts for an outcome: the attestation digest over
162
+ * `attestation`, ECDSA-signed with `secretKey`, in the ledger shape the
163
+ * singleton emits (big-endian signature bytes). Responder-side and
164
+ * test-fixture side (the fakenet posts through this), so it is exported
165
+ * through the `./testing` entry point.
166
+ *
167
+ * @param attestation - What the attestation commits to.
168
+ * @param secretKey - The 32-byte secp256k1 response secret key of the requesting contract.
169
+ * @returns The record, ready to post or to serve as a fixture.
170
+ * @throws {Error} If no recovery id reproduces the signer's own public key.
171
+ */
172
+ export declare function attestRespondBidirectional(attestation: RespondBidirectionalAttestation, secretKey: Uint8Array): RespondBidirectionalEvent;
145
173
  /**
146
174
  * Produce the circuit-input form of a posted respond-bidirectional
147
175
  * attestation: `signature.bigR.x` and `signature.s` byte-reversed into
148
176
  * little-endian, everything else verbatim. The in-circuit
149
- * `verifyRespondBidirectionalEvent` reads those two scalars through
177
+ * `verifyRespondBidirectionalEventV1` reads those two scalars through
150
178
  * little-endian casts (the reversal is free off-chain and costly
151
179
  * in-circuit), while the wire and ledger records stay big-endian: pass every
152
180
  * event through this exactly once, at the circuit call. A record passed
@@ -158,22 +186,22 @@ export declare function calculateSignetAttestationDigest(requestId: RequestId, b
158
186
  */
159
187
  export declare function respondBidirectionalEventToCircuitInput(event: RespondBidirectionalEvent): RespondBidirectionalEvent;
160
188
  /**
161
- * Off-chain twin of the in-circuit `verifyRespondBidirectionalEvent`: checks
189
+ * Off-chain twin of the in-circuit `verifyRespondBidirectionalEventV1`: checks
162
190
  * a posted respond-bidirectional attestation against the execution output
163
- * and the contract's pinned MPC response key. Clients run it to sift
164
- * candidate posts before calling a contract: a post this accepts verifies
165
- * in-circuit (once flipped to circuit-input form, see
191
+ * and the contract's pinned MPC response key, over the request id, block
192
+ * height and output kind the post declares. Clients run it to sift candidate posts
193
+ * before calling a contract: a post this accepts verifies in-circuit (once
194
+ * flipped to circuit-input form, see
166
195
  * {@link respondBidirectionalEventToCircuitInput}). Takes the record as read
167
196
  * off the ledger (big-endian). Malformed records return `false` rather than
168
197
  * throwing.
169
198
  *
170
- * @param requestId - The 32-byte request id the response answers.
171
- * @param blockHeight - The destination block height the attestation names.
172
199
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
173
200
  * @param event - The posted record to check, as read off the ledger.
174
201
  * @param mpcResponseKey - The response key the requesting contract pinned
175
202
  * (see {@link deriveMidnightResponseKey}).
176
- * @returns Whether the post is a genuine attestation of that output.
203
+ * @returns Whether the post is a genuine attestation of that output for the
204
+ * request it names.
177
205
  */
178
- export declare function verifyRespondBidirectionalSignature(requestId: RequestId, blockHeight: bigint, serializedOutput: Uint8Array, event: RespondBidirectionalEvent, mpcResponseKey: Secp256k1Point): boolean;
206
+ export declare function verifyRespondBidirectionalSignature(serializedOutput: Uint8Array, event: RespondBidirectionalEvent, mpcResponseKey: Secp256k1Point): boolean;
179
207
  //# sourceMappingURL=ecdsa-attestation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa-attestation.d.ts","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAgB,SAAS,EAAW,MAAM,QAAQ,CAAC;AAI1D,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAItD,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,uCAAuC;AACvC,eAAO,MAAM,eAAe,QAA2B,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,CAAC,EAAE,MAAM,CAAC;IACV,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,cAAc,CAc/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,cAAc,GAAG,YAAY,CAqBpF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,YAAY,GAAG,cAAc,CAapF;AAED;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAAC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,CAO/F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,IAAI,CAAC,SAAS,EAA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G,mBAAmB,CAWtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAOrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAGtE;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc,CAO1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gCAAgC,CAC9C,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,UAAU,GAC3B,UAAU,CAUZ;AAED,gFAAgF;AAChF,MAAM,WAAW,+BAA+B;IAC9C,mDAAmD;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,UAAU,EAAE,UAAU,CAAC;IACvB,mFAAmF;IACnF,gBAAgB,EAAE,UAAU,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,+BAA+B,EAC5C,SAAS,EAAE,UAAU,GACpB,yBAAyB,CAgB3B;AAgBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uCAAuC,CACrD,KAAK,EAAE,yBAAyB,GAC/B,yBAAyB,CAS3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,UAAU,EAC5B,KAAK,EAAE,yBAAyB,EAChC,cAAc,EAAE,cAAc,GAC7B,OAAO,CA8BT"}
@@ -3,7 +3,7 @@
3
3
  // parsing/formatting, the signature-record codecs both respond events
4
4
  // share, and the attestation digest's TS twin.
5
5
  // Everything provable stays in Compact where possible: in-circuit
6
- // verification is `verifyRespondBidirectionalEvent`. The digest circuit is
6
+ // verification is `verifyRespondBidirectionalEventV1`. The digest circuit is
7
7
  // size-generic and the compiler cannot export size-generic circuits
8
8
  // top-level, so the digest is
9
9
  // the ONE sanctioned TS twin here, pinned byte-for-byte against the
@@ -126,12 +126,14 @@ export function signatureRespondedEventToSignature(response) {
126
126
  * it is exported through the `./testing` entry point with the other
127
127
  * posting-side helpers.
128
128
  *
129
+ * @param requestId - The 32-byte request id the signature answers.
129
130
  * @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
130
131
  * @returns The response record, ready to post.
131
132
  * @throws {Error} If `r` is not the x coordinate of a secp256k1 point.
132
133
  */
133
- export function signatureToSignatureRespondedEvent(signature) {
134
+ export function signatureToSignatureRespondedEvent(requestId, signature) {
134
135
  return {
136
+ requestId,
135
137
  signature: ecdsaSignatureToMpcSignature({
136
138
  r: BigInt(signature.r),
137
139
  s: BigInt(signature.s),
@@ -268,23 +270,50 @@ export function secp256k1PublicKeyOf(secretKey) {
268
270
  }
269
271
  /**
270
272
  * The attestation digest of a respond-bidirectional response:
271
- * `upgradeFromTransient(transientHash([requestId, blockHeight, outputLength, serializedOutput]))`,
272
- * the 32-byte digest the MPC ECDSA-signs to attest a remote execution. TS twin of
273
- * the size-generic Compact circuit of the same name.
273
+ * `upgradeFromTransient(transientHash([requestId, blockHeight, outputKind, outputLength, serializedOutput]))`,
274
+ * the 32-byte digest the MPC ECDSA-signs to attest a remote execution. TS
275
+ * twin of the size-generic Compact circuit `calculateSignetAttestationDigestV1`.
274
276
  *
275
277
  * @param requestId - The 32-byte request id the response answers.
276
- * @param blockHeight - The destination block height the outcome is final at.
278
+ * @param blockHeight - Height of the finalised destination block holding the
279
+ * attested transaction, in the destination chain's own numbering.
280
+ * @param outputKind - The MPC's verdict on the execution.
277
281
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
278
282
  * @returns The 32-byte attestation digest.
279
283
  */
280
- export function calculateSignetAttestationDigest(requestId, blockHeight, serializedOutput) {
284
+ export function calculateSignetAttestationDigest(requestId, blockHeight, outputKind, serializedOutput) {
281
285
  return upgradeFromTransient(transientHash(attestationPreimageDescriptor(serializedOutput.length), [
282
286
  requestId,
283
287
  blockHeight,
288
+ outputKind,
284
289
  BigInt(serializedOutput.length),
285
290
  serializedOutput,
286
291
  ]));
287
292
  }
293
+ /**
294
+ * Mint the record the MPC posts for an outcome: the attestation digest over
295
+ * `attestation`, ECDSA-signed with `secretKey`, in the ledger shape the
296
+ * singleton emits (big-endian signature bytes). Responder-side and
297
+ * test-fixture side (the fakenet posts through this), so it is exported
298
+ * through the `./testing` entry point.
299
+ *
300
+ * @param attestation - What the attestation commits to.
301
+ * @param secretKey - The 32-byte secp256k1 response secret key of the requesting contract.
302
+ * @returns The record, ready to post or to serve as a fixture.
303
+ * @throws {Error} If no recovery id reproduces the signer's own public key.
304
+ */
305
+ export function attestRespondBidirectional(attestation, secretKey) {
306
+ const { requestId, blockHeight, outputKind, serializedOutput } = attestation;
307
+ const digest = calculateSignetAttestationDigest(requestId, blockHeight, outputKind, serializedOutput);
308
+ return {
309
+ requestId,
310
+ blockHeight,
311
+ outputKind,
312
+ serializedOutputLength: BigInt(serializedOutput.length),
313
+ digest,
314
+ signature: ecdsaSignatureToMpcSignature(signAttestationDigest(digest, secretKey)),
315
+ };
316
+ }
288
317
  /**
289
318
  * Reverse a 32-byte value between big- and little-endian byte order.
290
319
  *
@@ -302,7 +331,7 @@ function reverseBytes32(bytes) {
302
331
  * Produce the circuit-input form of a posted respond-bidirectional
303
332
  * attestation: `signature.bigR.x` and `signature.s` byte-reversed into
304
333
  * little-endian, everything else verbatim. The in-circuit
305
- * `verifyRespondBidirectionalEvent` reads those two scalars through
334
+ * `verifyRespondBidirectionalEventV1` reads those two scalars through
306
335
  * little-endian casts (the reversal is free off-chain and costly
307
336
  * in-circuit), while the wire and ledger records stay big-endian: pass every
308
337
  * event through this exactly once, at the circuit call. A record passed
@@ -314,6 +343,7 @@ function reverseBytes32(bytes) {
314
343
  */
315
344
  export function respondBidirectionalEventToCircuitInput(event) {
316
345
  return {
346
+ ...event,
317
347
  signature: {
318
348
  ...event.signature,
319
349
  bigR: { ...event.signature.bigR, x: reverseBytes32(event.signature.bigR.x) },
@@ -322,24 +352,24 @@ export function respondBidirectionalEventToCircuitInput(event) {
322
352
  };
323
353
  }
324
354
  /**
325
- * Off-chain twin of the in-circuit `verifyRespondBidirectionalEvent`: checks
355
+ * Off-chain twin of the in-circuit `verifyRespondBidirectionalEventV1`: checks
326
356
  * a posted respond-bidirectional attestation against the execution output
327
- * and the contract's pinned MPC response key. Clients run it to sift
328
- * candidate posts before calling a contract: a post this accepts verifies
329
- * in-circuit (once flipped to circuit-input form, see
357
+ * and the contract's pinned MPC response key, over the request id, block
358
+ * height and output kind the post declares. Clients run it to sift candidate posts
359
+ * before calling a contract: a post this accepts verifies in-circuit (once
360
+ * flipped to circuit-input form, see
330
361
  * {@link respondBidirectionalEventToCircuitInput}). Takes the record as read
331
362
  * off the ledger (big-endian). Malformed records return `false` rather than
332
363
  * throwing.
333
364
  *
334
- * @param requestId - The 32-byte request id the response answers.
335
- * @param blockHeight - The destination block height the attestation names.
336
365
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
337
366
  * @param event - The posted record to check, as read off the ledger.
338
367
  * @param mpcResponseKey - The response key the requesting contract pinned
339
368
  * (see {@link deriveMidnightResponseKey}).
340
- * @returns Whether the post is a genuine attestation of that output.
369
+ * @returns Whether the post is a genuine attestation of that output for the
370
+ * request it names.
341
371
  */
342
- export function verifyRespondBidirectionalSignature(requestId, blockHeight, serializedOutput, event, mpcResponseKey) {
372
+ export function verifyRespondBidirectionalSignature(serializedOutput, event, mpcResponseKey) {
343
373
  let signature;
344
374
  try {
345
375
  signature = mpcSignatureToEcdsaSignature(event.signature);
@@ -347,7 +377,7 @@ export function verifyRespondBidirectionalSignature(requestId, blockHeight, seri
347
377
  catch {
348
378
  return false;
349
379
  }
350
- const digest = calculateSignetAttestationDigest(requestId, blockHeight, serializedOutput);
380
+ const digest = calculateSignetAttestationDigest(event.requestId, event.blockHeight, event.outputKind, serializedOutput);
351
381
  // Compact form the verifier takes: r || s big-endian, and the key as
352
382
  // uncompressed SEC1 (0x04 || x || y).
353
383
  const compactSignature = new Uint8Array(64);