@sig-net/midnight 0.19.0 → 0.21.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 +66 -96
  19. package/dist/ecdsa-attestation.d.ts.map +1 -1
  20. package/dist/ecdsa-attestation.js +115 -140
  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 +102 -225
  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 +67 -66
  48. package/dist/signet-contract-events.d.ts.map +1 -1
  49. package/dist/signet-contract-events.js +57 -52
  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 +149 -198
  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
package/dist/constants.js CHANGED
@@ -2,9 +2,7 @@
2
2
  // structs, and the published per-network counterparty values (the MPC root
3
3
  // public key and the signet contract address). Field widths mirror
4
4
  // Signet.compact (the wire format: keep in lockstep), and the string
5
- // constants are the values the MPC network routes on. Ported from the MVP's
6
- // contract-cli signet/constants.ts, adapted to the refactor's zero-padded
7
- // convention (Compact `pad(N, "text")`).
5
+ // constants are the values the MPC network routes on.
8
6
  //
9
7
  // The routing constants belong in github.com/sig-net/signet.js, kept here
10
8
  // until upstreamed.
@@ -17,32 +15,17 @@ export const SELECTOR_BYTES = 4;
17
15
  /**
18
16
  * The complete serialised output the MPC attests for a FAILED remote
19
17
  * execution (reverted or replaced transaction): the 4-byte error marker
20
- * `0xdeadbeef` followed by one `0x01` byte. Schema-independent by design,
21
- * mirroring the canonical MPC's Borsh-format failure payload (sig-net/mpc,
22
- * node/src/respond_bidirectional.rs), so every respond schema shares one
23
- * fixed 5-byte failure width. Clients recompute their failure candidate from
24
- * this constant alone: no receipt or schema needed.
25
- *
26
- * The exact-equality check ({@link isMpcFailureOutput}) is unambiguous for
27
- * every respond schema whose packed width differs from 5 bytes. A schema
28
- * whose packed width is exactly 5 could in principle produce a legitimate
29
- * output equal to this sentinel, and such clients must route settlement by
30
- * digest-candidate matching (recompute both the real-output candidate and
31
- * the failure candidate, and see which digest the MPC attested), never by
32
- * inspecting output bytes.
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}.
33
24
  */
34
25
  export const MPC_FAILURE_OUTPUT = new Uint8Array([0xde, 0xad, 0xbe, 0xef, 0x01]);
35
26
  /**
36
27
  * Whether an attested serialised output IS the MPC's fixed failure payload:
37
- * exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT} (the length
38
- * must be exactly 5 and every byte must match). A prefix check would be
39
- * unsafe, as a legitimate packed output can begin with the same bytes.
40
- *
41
- * Unambiguous for every respond schema whose packed width differs from 5
42
- * bytes. A schema whose packed width is exactly 5 could in principle produce
43
- * a legitimate output equal to the sentinel: such clients must route
44
- * settlement by digest-candidate matching instead of inspecting output
45
- * bytes (see {@link MPC_FAILURE_OUTPUT}).
28
+ * exact byte equality with the 5-byte {@link MPC_FAILURE_OUTPUT}.
46
29
  *
47
30
  * @param serializedOutput - The attested serialised output.
48
31
  * @returns `true` when the output equals the MPC failure payload exactly.
@@ -52,9 +35,8 @@ export function isMpcFailureOutput(serializedOutput) {
52
35
  MPC_FAILURE_OUTPUT.every((byte, index) => serializedOutput[index] === byte));
53
36
  }
54
37
  /**
55
- * Default MPC key version (`keyVersion` field value). Version 0 is the
56
- * unsupported legacy format: the canonical MPC (and
57
- * `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
38
+ * Default MPC key version (`keyVersion` field value). The canonical MPC
39
+ * (and `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
58
40
  */
59
41
  export const SIGNET_DEFAULT_KEY_VERSION = 1n;
60
42
  /**
@@ -65,12 +47,12 @@ export const SIGNET_DEFAULT_KEY_VERSION = 1n;
65
47
  * @param text - The ASCII text to encode.
66
48
  * @param length - The fixed field width in bytes.
67
49
  * @returns `text`'s bytes followed by zero padding to exactly `length`.
68
- * @throws If the encoded text does not fit in `length` bytes.
50
+ * @throws {Error} If the encoded text does not fit in `length` bytes.
69
51
  */
70
52
  export function asciiPadded(text, length) {
71
53
  const encoded = new TextEncoder().encode(text);
72
54
  if (encoded.length > length) {
73
- throw new Error(`"${text}" is ${encoded.length} bytes: does not fit the ${length}-byte field`);
55
+ throw new Error(`"${text}" is ${String(encoded.length)} bytes: does not fit the ${String(length)}-byte field`);
74
56
  }
75
57
  const out = new Uint8Array(length);
76
58
  out.set(encoded);
@@ -78,10 +60,7 @@ export function asciiPadded(text, length) {
78
60
  }
79
61
  /**
80
62
  * A named Midnight network: the single source of the network names shared
81
- * across the `@sig-net/midnight*` packages. midnight-js types a network id
82
- * as a bare `string` with no companion enum, so the names live here, and
83
- * `@sig-net/midnight-contract-deploy`'s network-id plumbing widens this
84
- * enum back to the SDK's string type for its deploy config.
63
+ * across the `@sig-net/midnight*` packages.
85
64
  */
86
65
  export var MidnightNetwork;
87
66
  (function (MidnightNetwork) {
@@ -108,14 +87,12 @@ const mpcRootPublicKeys = {
108
87
  /**
109
88
  * The MPC root public key of a deployed Midnight network, as hex: the
110
89
  * `mpcRootPublicKey` every client key derivation starts from (see
111
- * `deriveEvmAddress`). Only the {@link DeployedNetwork} networks have a
112
- * fixed key. A local standalone stack has none: its setup generates a fresh
113
- * `MPC_ROOT_KEY` per stack (the integration-test setup prints it and
114
- * appends it to the repo-root `.env`).
90
+ * `deriveEvmAddress`). A local standalone stack has no fixed key: its setup
91
+ * generates a fresh `MPC_ROOT_KEY` per stack.
115
92
  *
116
93
  * @param networkId - The deployed network to look up.
117
94
  * @returns The network's MPC root public key.
118
- * @throws Error when the network's key is not yet published in this package.
95
+ * @throws {Error} When the network's key is not yet published in this package.
119
96
  */
120
97
  export function getMpcRootPublicKey(networkId) {
121
98
  const publicKey = mpcRootPublicKeys[networkId];
@@ -136,15 +113,12 @@ const signetContractAddresses = {
136
113
  /**
137
114
  * The address of the central signet singleton contract on a deployed
138
115
  * Midnight network: the `signetContractAddress` a
139
- * `SignetRequestResponseReader` polls. Only the {@link DeployedNetwork}
140
- * networks have a fixed address. A local standalone stack has none: each
141
- * stack deploys its own singleton (the integration-test setup prints the
142
- * address as `MIDNIGHT_SIGNET_CONTRACT_ADDRESS` and appends it to the
143
- * repo-root `.env`).
116
+ * `SignetRequestResponseReader` polls. A local standalone stack has no
117
+ * fixed address: each stack deploys its own singleton.
144
118
  *
145
119
  * @param networkId - The deployed network to look up.
146
120
  * @returns The network's signet contract address.
147
- * @throws Error when the singleton's address is not yet published in this
121
+ * @throws {Error} When the singleton's address is not yet published in this
148
122
  * package.
149
123
  */
150
124
  export function getSignetContractAddress(networkId) {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,2EAA2E;AAC3E,mEAAmE;AACnE,qEAAqE;AACrE,4EAA4E;AAC5E,0EAA0E;AAC1E,yCAAyC;AACzC,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;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjF;;;;;;;;;;;;;;GAcG;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;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC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E,EAAE;IAC7B,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAA0B;IAC5D,MAAM,SAAS,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,6CAA6C,SAAS,eAAe,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,qEAAqE;AACrE,0EAA0E;AAC1E,wEAAwE;AACxE,MAAM,uBAAuB,GAAoC;IAC/D,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,EAAE;IAC9B,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE;IAC7B,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE;IAC7B,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE;CAC9B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAA0B;IACjE,MAAM,eAAe,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC3D,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,SAAS,eAAe,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -1,54 +1,14 @@
1
1
  import type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
2
+ import { Signature } from "ethers";
3
+ import type { MpcSignature, RespondBidirectionalEvent, SignatureRespondedEvent } from "./signet-contract-events.ts";
2
4
  import type { RequestId } from "./signet-requests.ts";
3
- import type { MpcSignature, RespondBidirectionalEvent } from "./signet-contract-events.ts";
4
5
  export type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
5
6
  /** secp256k1 curve (group) order n. */
6
7
  export declare const SECP256K1_ORDER: bigint;
7
- /** BLS12-381 scalar field order (the Compact `Field` type modulus). */
8
- export declare const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
9
8
  /**
10
- * Convert little-endian bytes to a bigint. Matches Compact's
11
- * `Bytes<32> as Field` / `Bytes<32> as Secp256k1Scalar` interpretation (both
12
- * casts are little-endian).
13
- *
14
- * @param bytes - Little-endian byte array.
15
- * @returns The decoded non-negative integer.
16
- */
17
- export declare function bytesToBigint(bytes: Uint8Array): bigint;
18
- /**
19
- * Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
20
- * `Field as Bytes<32>` / `Secp256k1Scalar as Bytes<32>` encoding (the inverse
21
- * of {@link bytesToBigint}). Negative inputs are interpreted in the BLS
22
- * scalar field.
23
- *
24
- * @param n - The integer to encode.
25
- * @returns The 32-byte little-endian encoding.
26
- */
27
- export declare function bigintToBytes32(n: bigint): Uint8Array;
28
- /**
29
- * Convert big-endian bytes to a bigint (SEC1 coordinate order, the byte
30
- * order the respond events' stored signature uses).
31
- *
32
- * @param bytes - Big-endian byte array.
33
- * @returns The decoded non-negative integer.
34
- */
35
- export declare function bytesToBigintBE(bytes: Uint8Array): bigint;
36
- /**
37
- * Convert a bigint to exactly 32 BIG-endian bytes (SEC1 scalar/coordinate
38
- * order, also the ABI word encoding): the big-endian counterpart of
39
- * {@link bigintToBytes32} and the inverse of {@link bytesToBigintBE}.
40
- *
41
- * @param value - The non-negative integer to encode.
42
- * @returns The 32-byte big-endian encoding.
43
- * @throws Error if the value is negative or does not fit 32 bytes.
44
- */
45
- export declare function bigintToBytes32BE(value: bigint): Uint8Array;
46
- /**
47
- * An ECDSA signature over the attestation digest, in the MPC's canonical
48
- * `Signature { big_r, s, recovery_id }` spirit with `r` already reduced to
49
- * the scalar `big_r.x mod n`, the form Compact's `Secp256k1EcdsaSignature`
50
- * takes. Build the stored form for posting in a respond event with
51
- * {@link ecdsaSignatureToMpcSignature}.
9
+ * An ECDSA signature in scalar form: what {@link signAttestationDigest}
10
+ * produces, and what {@link ecdsaSignatureToMpcSignature} encodes into the
11
+ * stored form respond events carry.
52
12
  */
53
13
  export interface EcdsaSignature {
54
14
  /** Signature scalar r (= R.x mod n). */
@@ -60,46 +20,60 @@ export interface EcdsaSignature {
60
20
  }
61
21
  /**
62
22
  * ECDSA-sign a 32-byte digest with a secp256k1 secret key, exactly as the
63
- * MPC signs the attestation digest: RFC 6979 deterministic, low-s, the digest
64
- * interpreted big-endian with NO extra hashing (`prehash: false`), the same
65
- * convention `secp256k1EcdsaVerify` checks in-circuit.
23
+ * MPC signs the attestation digest: the result verifies in-circuit against
24
+ * the matching public key. For posters and test fixtures.
66
25
  *
67
26
  * @param digest - The 32-byte digest to sign (e.g. the
68
27
  * {@link calculateSignetAttestationDigest} output).
69
28
  * @param secretKey - The 32-byte secp256k1 secret key.
70
29
  * @returns The signature with its recovery id.
30
+ * @throws {Error} If no recovery id reproduces the signer's own public key.
71
31
  */
72
32
  export declare function signAttestationDigest(digest: Uint8Array, secretKey: Uint8Array): EcdsaSignature;
73
33
  /**
74
- * Build the stored-form signature both respond events carry from a
75
- * scalar-form one: R is reconstructed by decompressing the curve point with
76
- * x = `r` and the parity `recoveryId` names, undoing the compression an
77
- * `r || s || v` signature performs. For MPC-side posters (the fakenet
78
- * signer, tests). The negligible caveat: an R.x that overflowed the curve
79
- * order cannot be told apart from its reduced twin, so reconstruction picks
80
- * the x equal to `r` itself.
34
+ * Encode a scalar-form signature as the stored-form record both respond
35
+ * events carry. For MPC-side posters (the fakenet signer) and test fixtures.
81
36
  *
82
37
  * @param signature - The scalar-form signature (the signer's output shape).
83
38
  * @returns The stored-form signature: R as a full point, big-endian bytes.
84
- * @throws Error if the recovery id is not 0 or 1, or `r` is not the x
39
+ * @throws {Error} If the recovery id is not 0 or 1, or `r` is not the x
85
40
  * coordinate of a secp256k1 point.
86
41
  */
87
42
  export declare function ecdsaSignatureToMpcSignature(signature: EcdsaSignature): MpcSignature;
88
43
  /**
89
- * Read a stored-form signature back into scalar form: the inverse of
44
+ * Decode a stored-form signature back to scalar form: the inverse of
90
45
  * {@link ecdsaSignatureToMpcSignature}, for off-chain consumers building a
91
- * transaction from the response. `r` comes out as `bigR.x` reduced mod the
92
- * curve order. Rejects records that do not even hold the shape, since posts
93
- * are unauthenticated and a malformed record is garbage. `bigR.y` is NOT
94
- * checked against the curve or the recovery id: signature verification is
95
- * the authority, not this decoder.
46
+ * transaction from the response. Checks shape only: acceptance does not mean
47
+ * the signature verifies.
96
48
  *
97
49
  * @param signature - The stored-form signature as posted.
98
50
  * @returns The scalar-form signature.
99
- * @throws Error if a component has the wrong byte length or the recovery id
51
+ * @throws {Error} If a component has the wrong byte length or the recovery id
100
52
  * is not 0 or 1.
101
53
  */
102
54
  export declare function mpcSignatureToEcdsaSignature(signature: MpcSignature): EcdsaSignature;
55
+ /**
56
+ * Decode a posted response signature record into an ethers
57
+ * {@link Signature}. Ethers' `r` is the ECDSA scalar (`bigR.x` reduced mod
58
+ * the curve order), not the raw coordinate.
59
+ *
60
+ * @param response - The posted signature record.
61
+ * @returns The ethers signature.
62
+ * @throws {Error} If the record is malformed (see {@link mpcSignatureToEcdsaSignature}).
63
+ */
64
+ export declare function signatureRespondedEventToSignature(response: SignatureRespondedEvent): Signature;
65
+ /**
66
+ * Encode an ethers signature as the {@link SignatureRespondedEvent} record a
67
+ * responder posts: the inverse of {@link signatureRespondedEventToSignature}.
68
+ * Responder-side (the fakenet posts through this; clients only verify), so
69
+ * it is exported through the `./testing` entry point with the other
70
+ * posting-side helpers.
71
+ *
72
+ * @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
73
+ * @returns The response record, ready to post.
74
+ * @throws {Error} If `r` is not the x coordinate of a secp256k1 point.
75
+ */
76
+ export declare function signatureToSignatureRespondedEvent(signature: Pick<Signature, "r" | "s" | "yParity">): SignatureRespondedEvent;
103
77
  /**
104
78
  * Parse a secp256k1 public key from SEC1 hex (compressed or uncompressed,
105
79
  * optional `0x` prefix) into the Compact runtime's `Secp256k1Point` shape:
@@ -107,7 +81,7 @@ export declare function mpcSignatureToEcdsaSignature(signature: MpcSignature): E
107
81
  *
108
82
  * @param value - The SEC1 hex public key.
109
83
  * @returns The parsed point.
110
- * @throws Error if the value is not a valid secp256k1 public key.
84
+ * @throws {Error} If the value is not a valid secp256k1 public key.
111
85
  */
112
86
  export declare function parseSecp256k1PublicKey(value: string): Secp256k1Point;
113
87
  /**
@@ -130,18 +104,10 @@ export declare function secp256k1PublicKeyOf(secretKey: Uint8Array): Secp256k1Po
130
104
  /**
131
105
  * The attestation digest of a respond-bidirectional response:
132
106
  * `keccak256(requestId || serializedOutput)`, the 32-byte digest the MPC
133
- * ECDSA-signs to attest a remote execution.
134
- *
135
- * TS twin of the size-generic Compact circuit
136
- * `calculateSignetAttestationDigest` (which the compiler cannot export
137
- * compiled, so this is the one sanctioned re-implementation, pinned
138
- * byte-for-byte against the fixed-width oracle circuits in
139
- * circuits.compact). The constructions agree because the circuit's keccak
140
- * preimage of the `[RequestId, Bytes<N>]` pair is the raw concatenated
141
- * bytes, and it matches the MPC's respond-bidirectional hash
142
- * (`hash(request_id || serialized_output)`: one flat concatenation, one
143
- * hash). The output is hashed AS GIVEN, at its exact length: no padding and
144
- * no length binding.
107
+ * ECDSA-signs to attest a remote execution. TS twin of the size-generic
108
+ * Compact circuit of the same name, pinned against its fixed-width oracle
109
+ * circuits in tests. The output is hashed as given, at its exact length:
110
+ * no padding, no length prefix.
145
111
  *
146
112
  * @param requestId - The 32-byte request id the response answers.
147
113
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
@@ -149,31 +115,35 @@ export declare function secp256k1PublicKeyOf(secretKey: Uint8Array): Secp256k1Po
149
115
  */
150
116
  export declare function calculateSignetAttestationDigest(requestId: RequestId, serializedOutput: Uint8Array): Uint8Array;
151
117
  /**
152
- * Off-chain check of a posted respond-bidirectional attestation: recompute
153
- * the attestation digest of `(requestId, serializedOutput)` and verify the
154
- * event's ECDSA signature over it against `mpcResponseKey`.
155
- *
156
- * The event's declared request id is unauthenticated routing data, so this
157
- * check is the ONLY way to tell a genuine post from garbage: the signet
158
- * contract's event log is unauthenticated and every post is emitted
159
- * unverified. Use it to sift the candidates
160
- * {@link SignetRequestResponseReader.getRespondBidirectionalEvents}
161
- * returns before handing one to a contract. It is the off-chain counterpart
162
- * of the in-circuit `verifyRespondBidirectionalEvent` and answers the same
163
- * question, so a post this accepts is the post that proves at claim time.
118
+ * Produce the circuit-input form of a posted respond-bidirectional
119
+ * attestation: `signature.bigR.x` and `signature.s` byte-reversed into
120
+ * little-endian, everything else verbatim. The in-circuit
121
+ * `verifyRespondBidirectionalEvent` reads those two scalars through
122
+ * little-endian casts (the reversal is free off-chain and costly
123
+ * in-circuit), while the wire and ledger records stay big-endian: pass every
124
+ * event through this exactly once, at the circuit call. A record passed
125
+ * without the flip fails verification, never falsely accepts.
164
126
  *
165
- * Malformed records are garbage, not faults: a signature whose components
166
- * have the wrong width, whose `r` is off-curve, or which simply does not
167
- * verify all return `false` rather than throwing. High-`s` signatures are
168
- * accepted, matching the in-circuit verification (which enforces no low-`s`
169
- * policy) rather than the signer's own normalisation.
127
+ * @param event - The posted record as read off the ledger (big-endian).
128
+ * @returns The record in circuit-input form.
129
+ * @throws {Error} If a signature component is not exactly 32 bytes.
130
+ */
131
+ export declare function respondBidirectionalEventToCircuitInput(event: RespondBidirectionalEvent): RespondBidirectionalEvent;
132
+ /**
133
+ * Off-chain twin of the in-circuit `verifyRespondBidirectionalEvent`: checks
134
+ * a posted respond-bidirectional attestation against the execution output
135
+ * and the contract's pinned MPC response key. Clients run it to sift
136
+ * candidate posts before calling a contract: a post this accepts verifies
137
+ * in-circuit (once flipped to circuit-input form, see
138
+ * {@link respondBidirectionalEventToCircuitInput}). Takes the record as read
139
+ * off the ledger (big-endian). Malformed records return `false` rather than
140
+ * throwing.
170
141
  *
171
142
  * @param requestId - The 32-byte request id the response answers.
172
143
  * @param serializedOutput - The serialised execution output, exact unpadded bytes.
173
144
  * @param event - The posted record to check, as read off the ledger.
174
- * @param mpcResponseKey - The response key the requesting contract pinned:
175
- * the MPC key derived for its address and the fixed "midnight response key"
176
- * path (see {@link deriveMidnightResponseKey}).
145
+ * @param mpcResponseKey - The response key the requesting contract pinned
146
+ * (see {@link deriveMidnightResponseKey}).
177
147
  * @returns Whether the post is a genuine attestation of that output.
178
148
  */
179
149
  export declare function verifyRespondBidirectionalSignature(requestId: RequestId, serializedOutput: Uint8Array, event: RespondBidirectionalEvent, mpcResponseKey: Secp256k1Point): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa-attestation.d.ts","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EAC1B,MAAM,6BAA6B,CAAC;AAIrC,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,uCAAuC;AACvC,eAAO,MAAM,eAAe,QAA2B,CAAC;AAExD,uEAAuE;AACvE,eAAO,MAAM,SAAS,iFAAiF,CAAC;AAExG;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAQrD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAW3D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,CAAC,EAAE,MAAM,CAAC;IACV,2CAA2C;I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