@sig-net/midnight 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -17
- package/dist/abi-serde.d.ts +89 -0
- package/dist/abi-serde.d.ts.map +1 -0
- package/dist/abi-serde.js +393 -0
- package/dist/abi-serde.js.map +1 -0
- package/dist/constants.d.ts +23 -14
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +28 -20
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +81 -9
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +137 -18
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +8 -8
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +16 -18
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +180 -104
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +38 -24
- package/dist/managed/contract/index.js +363 -154
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +15 -15
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +51 -34
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +2 -2
- package/dist/signature-response-verification.js +8 -8
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-state-reader.d.ts +74 -58
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +76 -58
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-evtype2tx-requests.d.ts +62 -59
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +58 -90
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +26 -26
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +37 -37
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +30 -30
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +29 -30
- package/dist/signet-requests.js.map +1 -1
- package/package.json +3 -2
- package/src/Signet.compact +137 -88
- package/src/circuits.compact +45 -2
package/dist/constants.d.ts
CHANGED
|
@@ -2,42 +2,51 @@
|
|
|
2
2
|
export declare const CAIP2_ID_BYTES = 32;
|
|
3
3
|
/** Width of `SignBidirectionalEvent.params` (`Bytes<64>`). */
|
|
4
4
|
export declare const MPC_PARAMS_BYTES = 64;
|
|
5
|
-
/** Width of `
|
|
5
|
+
/** Width of `EvmCalldata.selector` (`Bytes<4>`): the literal first 4 calldata bytes. */
|
|
6
6
|
export declare const SELECTOR_BYTES = 4;
|
|
7
|
-
/** Width of `RespondBidirectionalEvent.serializedOutput` (`Bytes<128>`). */
|
|
8
|
-
export declare const SERIALIZED_OUTPUT_BYTES = 128;
|
|
9
7
|
/**
|
|
10
|
-
* The MPC's error sentinel:
|
|
8
|
+
* The MPC's error sentinel: a serialised output beginning with these four
|
|
11
9
|
* bytes marks a failed/absent remote execution (mirrors the sig-net MPC's
|
|
12
10
|
* MAGIC_ERROR_PREFIX).
|
|
13
11
|
*/
|
|
14
12
|
export declare const MPC_ERROR_SENTINEL: Uint8Array<ArrayBuffer>;
|
|
15
13
|
/**
|
|
16
|
-
*
|
|
17
|
-
* execution
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* The complete serialised output the MPC attests for a FAILED remote
|
|
15
|
+
* execution (reverted or replaced transaction): the error sentinel followed
|
|
16
|
+
* by one `0x01` byte. Schema-independent by design, mirroring the canonical
|
|
17
|
+
* MPC's Borsh-format failure payload (sig-net/mpc,
|
|
18
|
+
* node/src/respond_bidirectional.rs), so every respond schema shares one
|
|
19
|
+
* fixed 5-byte failure width. Clients recompute their failure candidate from
|
|
20
|
+
* this constant alone: no receipt or schema needed.
|
|
21
|
+
*/
|
|
22
|
+
export declare const MPC_FAILURE_OUTPUT: Uint8Array<ArrayBuffer>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether an attested serialised output reports a successful remote
|
|
25
|
+
* execution: the first byte is 1, the packed little-endian encoding of a
|
|
26
|
+
* leading boolean success flag. The output is the exact unpadded respond
|
|
27
|
+
* payload (see `serializeRespondOutput`), so its length follows from the
|
|
28
|
+
* request's respond schema.
|
|
20
29
|
*
|
|
21
|
-
* @param serializedOutput - The
|
|
30
|
+
* @param serializedOutput - The attested serialised output.
|
|
22
31
|
* @returns `true` when the remote call succeeded.
|
|
23
32
|
*/
|
|
24
33
|
export declare function executionSucceeded(serializedOutput: Uint8Array): boolean;
|
|
25
34
|
/**
|
|
26
|
-
* Whether an
|
|
27
|
-
* (see {@link MPC_ERROR_SENTINEL})
|
|
35
|
+
* Whether an attested serialised output is the MPC's error sentinel
|
|
36
|
+
* (see {@link MPC_ERROR_SENTINEL}).
|
|
28
37
|
*
|
|
29
|
-
* @param serializedOutput - The
|
|
38
|
+
* @param serializedOutput - The attested serialised output.
|
|
30
39
|
* @returns `true` when the MPC reported an execution error.
|
|
31
40
|
*/
|
|
32
41
|
export declare function isExecutionError(serializedOutput: Uint8Array): boolean;
|
|
33
42
|
/**
|
|
34
43
|
* Default MPC key version (`keyVersion` field value). Version 0 is the
|
|
35
|
-
* unsupported legacy format
|
|
44
|
+
* unsupported legacy format: the canonical MPC (and
|
|
36
45
|
* `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
|
|
37
46
|
*/
|
|
38
47
|
export declare const SIGNET_DEFAULT_KEY_VERSION = 1n;
|
|
39
48
|
/**
|
|
40
|
-
* Encode text as zero-padded ASCII bytes
|
|
49
|
+
* Encode text as zero-padded ASCII bytes, the Compact `pad(N, "text")`
|
|
41
50
|
* convention every string-ish field of the request structs uses (consumers
|
|
42
51
|
* NUL-trim on decode).
|
|
43
52
|
*
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
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;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,yBAA2C,CAAC;AAE3E;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,yBAAiD,CAAC;AAEjF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAExE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAEtE;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAQpE"}
|
package/dist/constants.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
// MPC routing constants + the padded-ASCII codec for the signet request
|
|
2
|
-
// structs. Field widths mirror Signet.compact (the wire format
|
|
3
|
-
//
|
|
2
|
+
// structs. Field widths mirror Signet.compact (the wire format: keep in
|
|
3
|
+
// lockstep), and the string constants are the values the MPC network
|
|
4
4
|
// routes on. Ported from the MVP's contract-cli signet/constants.ts, adapted
|
|
5
|
-
// to the refactor's zero-padded convention (Compact `pad(N, "text")`)
|
|
6
|
-
// MVP's 2-byte length-prefixed codec is gone with the old layout.
|
|
5
|
+
// to the refactor's zero-padded convention (Compact `pad(N, "text")`).
|
|
7
6
|
//
|
|
8
|
-
// The routing constants belong in github.com/sig-net/signet.js
|
|
7
|
+
// The routing constants belong in github.com/sig-net/signet.js, kept here
|
|
9
8
|
// until upstreamed.
|
|
10
9
|
/** Width of `SignBidirectionalEvent.caip2Id` (`Bytes<32>`). */
|
|
11
10
|
export const CAIP2_ID_BYTES = 32;
|
|
12
11
|
/** Width of `SignBidirectionalEvent.params` (`Bytes<64>`). */
|
|
13
12
|
export const MPC_PARAMS_BYTES = 64;
|
|
14
|
-
/** Width of `
|
|
13
|
+
/** Width of `EvmCalldata.selector` (`Bytes<4>`): the literal first 4 calldata bytes. */
|
|
15
14
|
export const SELECTOR_BYTES = 4;
|
|
16
|
-
/** Width of `RespondBidirectionalEvent.serializedOutput` (`Bytes<128>`). */
|
|
17
|
-
export const SERIALIZED_OUTPUT_BYTES = 128;
|
|
18
15
|
/**
|
|
19
|
-
* The MPC's error sentinel:
|
|
16
|
+
* The MPC's error sentinel: a serialised output beginning with these four
|
|
20
17
|
* bytes marks a failed/absent remote execution (mirrors the sig-net MPC's
|
|
21
18
|
* MAGIC_ERROR_PREFIX).
|
|
22
19
|
*/
|
|
23
20
|
export const MPC_ERROR_SENTINEL = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
|
|
24
21
|
/**
|
|
25
|
-
*
|
|
26
|
-
* execution
|
|
27
|
-
*
|
|
28
|
-
*
|
|
22
|
+
* The complete serialised output the MPC attests for a FAILED remote
|
|
23
|
+
* execution (reverted or replaced transaction): the error sentinel followed
|
|
24
|
+
* by one `0x01` byte. Schema-independent by design, mirroring the canonical
|
|
25
|
+
* MPC's Borsh-format failure payload (sig-net/mpc,
|
|
26
|
+
* node/src/respond_bidirectional.rs), so every respond schema shares one
|
|
27
|
+
* fixed 5-byte failure width. Clients recompute their failure candidate from
|
|
28
|
+
* this constant alone: no receipt or schema needed.
|
|
29
|
+
*/
|
|
30
|
+
export const MPC_FAILURE_OUTPUT = new Uint8Array([0xde, 0xad, 0xbe, 0xef, 0x01]);
|
|
31
|
+
/**
|
|
32
|
+
* Whether an attested serialised output reports a successful remote
|
|
33
|
+
* execution: the first byte is 1, the packed little-endian encoding of a
|
|
34
|
+
* leading boolean success flag. The output is the exact unpadded respond
|
|
35
|
+
* payload (see `serializeRespondOutput`), so its length follows from the
|
|
36
|
+
* request's respond schema.
|
|
29
37
|
*
|
|
30
|
-
* @param serializedOutput - The
|
|
38
|
+
* @param serializedOutput - The attested serialised output.
|
|
31
39
|
* @returns `true` when the remote call succeeded.
|
|
32
40
|
*/
|
|
33
41
|
export function executionSucceeded(serializedOutput) {
|
|
34
42
|
return serializedOutput[0] === 1;
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
|
-
* Whether an
|
|
38
|
-
* (see {@link MPC_ERROR_SENTINEL})
|
|
45
|
+
* Whether an attested serialised output is the MPC's error sentinel
|
|
46
|
+
* (see {@link MPC_ERROR_SENTINEL}).
|
|
39
47
|
*
|
|
40
|
-
* @param serializedOutput - The
|
|
48
|
+
* @param serializedOutput - The attested serialised output.
|
|
41
49
|
* @returns `true` when the MPC reported an execution error.
|
|
42
50
|
*/
|
|
43
51
|
export function isExecutionError(serializedOutput) {
|
|
@@ -45,12 +53,12 @@ export function isExecutionError(serializedOutput) {
|
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
47
55
|
* Default MPC key version (`keyVersion` field value). Version 0 is the
|
|
48
|
-
* unsupported legacy format
|
|
56
|
+
* unsupported legacy format: the canonical MPC (and
|
|
49
57
|
* `constructSignBidirectionalEvent`) requires `keyVersion >= 1`.
|
|
50
58
|
*/
|
|
51
59
|
export const SIGNET_DEFAULT_KEY_VERSION = 1n;
|
|
52
60
|
/**
|
|
53
|
-
* Encode text as zero-padded ASCII bytes
|
|
61
|
+
* Encode text as zero-padded ASCII bytes, the Compact `pad(N, "text")`
|
|
54
62
|
* convention every string-ish field of the request structs uses (consumers
|
|
55
63
|
* NUL-trim on decode).
|
|
56
64
|
*
|
|
@@ -62,7 +70,7 @@ export const SIGNET_DEFAULT_KEY_VERSION = 1n;
|
|
|
62
70
|
export function asciiPadded(text, length) {
|
|
63
71
|
const encoded = new TextEncoder().encode(text);
|
|
64
72
|
if (encoded.length > length) {
|
|
65
|
-
throw new Error(`"${text}" is ${encoded.length} bytes
|
|
73
|
+
throw new Error(`"${text}" is ${encoded.length} bytes: does not fit the ${length}-byte field`);
|
|
66
74
|
}
|
|
67
75
|
const out = new Uint8Array(length);
|
|
68
76
|
out.set(encoded);
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wEAAwE;AACxE,qEAAqE;AACrE,6EAA6E;AAC7E,uEAAuE;AACvE,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;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE3E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,gBAA4B;IAC7D,OAAO,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,gBAA4B;IAC3D,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AACrF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAE7C;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAc;IACtD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,QAAQ,OAAO,CAAC,MAAM,4BAA4B,MAAM,aAAa,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
+
import type { RequestId } from "./signet-requests.ts";
|
|
3
|
+
import type { MpcSignature } from "./signet-contract-state-reader.ts";
|
|
2
4
|
export type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
|
|
3
5
|
/** secp256k1 curve (group) order n. */
|
|
4
6
|
export declare const SECP256K1_ORDER: bigint;
|
|
@@ -16,18 +18,37 @@ export declare function bytesToBigint(bytes: Uint8Array): bigint;
|
|
|
16
18
|
/**
|
|
17
19
|
* Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
|
|
18
20
|
* `Field as Bytes<32>` / `Secp256k1Scalar as Bytes<32>` encoding (the inverse
|
|
19
|
-
* of {@link bytesToBigint})
|
|
21
|
+
* of {@link bytesToBigint}). Negative inputs are interpreted in the BLS
|
|
20
22
|
* scalar field.
|
|
21
23
|
*
|
|
22
24
|
* @param n - The integer to encode.
|
|
23
25
|
* @returns The 32-byte little-endian encoding.
|
|
24
26
|
*/
|
|
25
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;
|
|
26
46
|
/**
|
|
27
47
|
* An ECDSA signature over the attestation digest, in the MPC's canonical
|
|
28
48
|
* `Signature { big_r, s, recovery_id }` spirit with `r` already reduced to
|
|
29
|
-
* the scalar `big_r.x mod n
|
|
30
|
-
* takes.
|
|
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}.
|
|
31
52
|
*/
|
|
32
53
|
export interface EcdsaSignature {
|
|
33
54
|
/** Signature scalar r (= R.x mod n). */
|
|
@@ -40,18 +61,48 @@ export interface EcdsaSignature {
|
|
|
40
61
|
/**
|
|
41
62
|
* ECDSA-sign a 32-byte digest with a secp256k1 secret key, exactly as the
|
|
42
63
|
* MPC signs the attestation digest: RFC 6979 deterministic, low-s, the digest
|
|
43
|
-
* interpreted big-endian with NO extra hashing (`prehash: false`)
|
|
64
|
+
* interpreted big-endian with NO extra hashing (`prehash: false`), the same
|
|
44
65
|
* convention `secp256k1EcdsaVerify` checks in-circuit.
|
|
45
66
|
*
|
|
46
|
-
* @param digest - The 32-byte digest to sign (e.g. the
|
|
47
|
-
*
|
|
67
|
+
* @param digest - The 32-byte digest to sign (e.g. the
|
|
68
|
+
* {@link calculateSignetAttestationDigest} output).
|
|
48
69
|
* @param secretKey - The 32-byte secp256k1 secret key.
|
|
49
70
|
* @returns The signature with its recovery id.
|
|
50
71
|
*/
|
|
51
72
|
export declare function signAttestationDigest(digest: Uint8Array, secretKey: Uint8Array): EcdsaSignature;
|
|
73
|
+
/**
|
|
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.
|
|
81
|
+
*
|
|
82
|
+
* @param signature - The scalar-form signature (the signer's output shape).
|
|
83
|
+
* @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
|
|
85
|
+
* coordinate of a secp256k1 point.
|
|
86
|
+
*/
|
|
87
|
+
export declare function ecdsaSignatureToMpcSignature(signature: EcdsaSignature): MpcSignature;
|
|
88
|
+
/**
|
|
89
|
+
* Read a stored-form signature back into scalar form: the inverse of
|
|
90
|
+
* {@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.
|
|
96
|
+
*
|
|
97
|
+
* @param signature - The stored-form signature as posted.
|
|
98
|
+
* @returns The scalar-form signature.
|
|
99
|
+
* @throws Error if a component has the wrong byte length or the recovery id
|
|
100
|
+
* is not 0 or 1.
|
|
101
|
+
*/
|
|
102
|
+
export declare function mpcSignatureToEcdsaSignature(signature: MpcSignature): EcdsaSignature;
|
|
52
103
|
/**
|
|
53
104
|
* Parse a secp256k1 public key from SEC1 hex (compressed or uncompressed,
|
|
54
|
-
* optional `0x` prefix) into the Compact runtime's `Secp256k1Point` shape
|
|
105
|
+
* optional `0x` prefix) into the Compact runtime's `Secp256k1Point` shape:
|
|
55
106
|
* how deploys receive the MPC response key to pin.
|
|
56
107
|
*
|
|
57
108
|
* @param value - The SEC1 hex public key.
|
|
@@ -61,7 +112,7 @@ export declare function signAttestationDigest(digest: Uint8Array, secretKey: Uin
|
|
|
61
112
|
export declare function parseSecp256k1PublicKey(value: string): Secp256k1Point;
|
|
62
113
|
/**
|
|
63
114
|
* Format a secp256k1 public key point as uncompressed SEC1 hex (with `0x`
|
|
64
|
-
* prefix)
|
|
115
|
+
* prefix): the round-trip inverse of {@link parseSecp256k1PublicKey}, for
|
|
65
116
|
* handing a response key to deploys via env/config.
|
|
66
117
|
*
|
|
67
118
|
* @param point - The point to format.
|
|
@@ -69,11 +120,32 @@ export declare function parseSecp256k1PublicKey(value: string): Secp256k1Point;
|
|
|
69
120
|
*/
|
|
70
121
|
export declare function formatSecp256k1PublicKey(point: Secp256k1Point): string;
|
|
71
122
|
/**
|
|
72
|
-
* Derive the `Secp256k1Point` of a secret key
|
|
123
|
+
* Derive the `Secp256k1Point` of a secret key: a convenience for tests and
|
|
73
124
|
* signers that hold key material as raw bytes.
|
|
74
125
|
*
|
|
75
126
|
* @param secretKey - The 32-byte secp256k1 secret key.
|
|
76
127
|
* @returns The public key point.
|
|
77
128
|
*/
|
|
78
129
|
export declare function secp256k1PublicKeyOf(secretKey: Uint8Array): Secp256k1Point;
|
|
130
|
+
/**
|
|
131
|
+
* The attestation digest of a respond-bidirectional response:
|
|
132
|
+
* `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.
|
|
145
|
+
*
|
|
146
|
+
* @param requestId - The 32-byte request id the response answers.
|
|
147
|
+
* @param serializedOutput - The serialised execution output, exact unpadded bytes.
|
|
148
|
+
* @returns The 32-byte attestation digest.
|
|
149
|
+
*/
|
|
150
|
+
export declare function calculateSignetAttestationDigest(requestId: RequestId, serializedOutput: Uint8Array): Uint8Array;
|
|
79
151
|
//# sourceMappingURL=ecdsa-attestation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa-attestation.d.ts","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ecdsa-attestation.d.ts","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"m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OG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc,CAO1E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gCAAgC,CAC9C,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,UAAU,GAC3B,UAAU,CAIZ"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
// secp256k1 ECDSA helpers: the TS side of the respond-bidirectional
|
|
2
|
-
// attestation flow in Signet.compact
|
|
3
|
-
// scalar, so it cannot be a circuit), key parsing/formatting,
|
|
4
|
-
// byte-order conversions between noble's bigints and the
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// verification is `
|
|
8
|
-
//
|
|
9
|
-
//
|
|
2
|
+
// attestation flow in Signet.compact: SIGNING (which needs the secret
|
|
3
|
+
// scalar, so it cannot be a circuit), key parsing/formatting, the
|
|
4
|
+
// byte-order conversions between noble's bigints and the little-endian
|
|
5
|
+
// scalar bytes Compact's casts read, and the attestation digest's TS twin.
|
|
6
|
+
// Everything provable stays in Compact where possible: in-circuit
|
|
7
|
+
// verification is `verifyRespondBidirectionalEvent`, the deploy-time key pin
|
|
8
|
+
// is `pureCircuits.signetKeyHash`. The digest circuit is size-generic and the
|
|
9
|
+
// compiler cannot export size-generic circuits top-level, so the digest is
|
|
10
|
+
// the ONE sanctioned TS twin here, pinned byte-for-byte against the
|
|
11
|
+
// fixed-width oracle circuits circuits.compact exports (see
|
|
12
|
+
// tests/ecdsa-attestation.test.ts).
|
|
10
13
|
//
|
|
11
|
-
// This belongs in github.com/sig-net/signet.js as its Midnight adapter
|
|
14
|
+
// This belongs in github.com/sig-net/signet.js as its Midnight adapter,
|
|
12
15
|
// kept here until upstreamed.
|
|
16
|
+
import { ethers } from "ethers";
|
|
13
17
|
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
14
18
|
/** secp256k1 curve (group) order n. */
|
|
15
19
|
export const SECP256K1_ORDER = secp256k1.Point.Fn.ORDER;
|
|
@@ -26,6 +30,8 @@ export const BLS_ORDER = 5243587517512619047944774050818596583769055250052763782
|
|
|
26
30
|
export function bytesToBigint(bytes) {
|
|
27
31
|
let result = 0n;
|
|
28
32
|
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
33
|
+
// The index is in range by construction: the assertion satisfies
|
|
34
|
+
// consumers compiling with noUncheckedIndexedAccess.
|
|
29
35
|
result = (result << 8n) | BigInt(bytes[i]);
|
|
30
36
|
}
|
|
31
37
|
return result;
|
|
@@ -33,7 +39,7 @@ export function bytesToBigint(bytes) {
|
|
|
33
39
|
/**
|
|
34
40
|
* Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
|
|
35
41
|
* `Field as Bytes<32>` / `Secp256k1Scalar as Bytes<32>` encoding (the inverse
|
|
36
|
-
* of {@link bytesToBigint})
|
|
42
|
+
* of {@link bytesToBigint}). Negative inputs are interpreted in the BLS
|
|
37
43
|
* scalar field.
|
|
38
44
|
*
|
|
39
45
|
* @param n - The integer to encode.
|
|
@@ -48,22 +54,49 @@ export function bigintToBytes32(n) {
|
|
|
48
54
|
}
|
|
49
55
|
return buf;
|
|
50
56
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Convert big-endian bytes to a bigint (SEC1 coordinate order, the byte
|
|
59
|
+
* order the respond events' stored signature uses).
|
|
60
|
+
*
|
|
61
|
+
* @param bytes - Big-endian byte array.
|
|
62
|
+
* @returns The decoded non-negative integer.
|
|
63
|
+
*/
|
|
64
|
+
export function bytesToBigintBE(bytes) {
|
|
53
65
|
let value = 0n;
|
|
54
66
|
for (const byte of bytes) {
|
|
55
67
|
value = (value << 8n) | BigInt(byte);
|
|
56
68
|
}
|
|
57
69
|
return value;
|
|
58
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert a bigint to exactly 32 BIG-endian bytes (SEC1 scalar/coordinate
|
|
73
|
+
* order, also the ABI word encoding): the big-endian counterpart of
|
|
74
|
+
* {@link bigintToBytes32} and the inverse of {@link bytesToBigintBE}.
|
|
75
|
+
*
|
|
76
|
+
* @param value - The non-negative integer to encode.
|
|
77
|
+
* @returns The 32-byte big-endian encoding.
|
|
78
|
+
* @throws Error if the value is negative or does not fit 32 bytes.
|
|
79
|
+
*/
|
|
80
|
+
export function bigintToBytes32BE(value) {
|
|
81
|
+
if (value < 0n || value >= 1n << 256n) {
|
|
82
|
+
throw new Error(`value does not fit 32 big-endian bytes: ${value}`);
|
|
83
|
+
}
|
|
84
|
+
const out = new Uint8Array(32);
|
|
85
|
+
let v = value;
|
|
86
|
+
for (let i = 31; i >= 0; i--) {
|
|
87
|
+
out[i] = Number(v & 0xffn);
|
|
88
|
+
v >>= 8n;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
59
92
|
/**
|
|
60
93
|
* ECDSA-sign a 32-byte digest with a secp256k1 secret key, exactly as the
|
|
61
94
|
* MPC signs the attestation digest: RFC 6979 deterministic, low-s, the digest
|
|
62
|
-
* interpreted big-endian with NO extra hashing (`prehash: false`)
|
|
95
|
+
* interpreted big-endian with NO extra hashing (`prehash: false`), the same
|
|
63
96
|
* convention `secp256k1EcdsaVerify` checks in-circuit.
|
|
64
97
|
*
|
|
65
|
-
* @param digest - The 32-byte digest to sign (e.g. the
|
|
66
|
-
*
|
|
98
|
+
* @param digest - The 32-byte digest to sign (e.g. the
|
|
99
|
+
* {@link calculateSignetAttestationDigest} output).
|
|
67
100
|
* @param secretKey - The 32-byte secp256k1 secret key.
|
|
68
101
|
* @returns The signature with its recovery id.
|
|
69
102
|
*/
|
|
@@ -85,9 +118,72 @@ export function signAttestationDigest(digest, secretKey) {
|
|
|
85
118
|
/* v8 ignore next: unreachable for a signature this function just produced */
|
|
86
119
|
throw new Error("signature does not recover to its own public key");
|
|
87
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Build the stored-form signature both respond events carry from a
|
|
123
|
+
* scalar-form one: R is reconstructed by decompressing the curve point with
|
|
124
|
+
* x = `r` and the parity `recoveryId` names, undoing the compression an
|
|
125
|
+
* `r || s || v` signature performs. For MPC-side posters (the fakenet
|
|
126
|
+
* signer, tests). The negligible caveat: an R.x that overflowed the curve
|
|
127
|
+
* order cannot be told apart from its reduced twin, so reconstruction picks
|
|
128
|
+
* the x equal to `r` itself.
|
|
129
|
+
*
|
|
130
|
+
* @param signature - The scalar-form signature (the signer's output shape).
|
|
131
|
+
* @returns The stored-form signature: R as a full point, big-endian bytes.
|
|
132
|
+
* @throws Error if the recovery id is not 0 or 1, or `r` is not the x
|
|
133
|
+
* coordinate of a secp256k1 point.
|
|
134
|
+
*/
|
|
135
|
+
export function ecdsaSignatureToMpcSignature(signature) {
|
|
136
|
+
if (signature.recoveryId !== 0 && signature.recoveryId !== 1) {
|
|
137
|
+
throw new Error(`expected a recovery id of 0 or 1, got ${signature.recoveryId}`);
|
|
138
|
+
}
|
|
139
|
+
// SEC1 compressed form: parity prefix (02 even, 03 odd) || x big-endian.
|
|
140
|
+
const parityPrefix = signature.recoveryId === 0 ? "02" : "03";
|
|
141
|
+
const xHex = signature.r.toString(16).padStart(64, "0");
|
|
142
|
+
let point;
|
|
143
|
+
try {
|
|
144
|
+
point = secp256k1.Point.fromHex(`${parityPrefix}${xHex}`);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new Error(`signature r is not the x coordinate of a secp256k1 point (${String(error)})`);
|
|
148
|
+
}
|
|
149
|
+
const uncompressed = point.toBytes(false); // 0x04 || x || y
|
|
150
|
+
return {
|
|
151
|
+
bigR: { x: uncompressed.slice(1, 33), y: uncompressed.slice(33, 65) },
|
|
152
|
+
s: bigintToBytes32BE(signature.s),
|
|
153
|
+
recoveryId: BigInt(signature.recoveryId),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Read a stored-form signature back into scalar form: the inverse of
|
|
158
|
+
* {@link ecdsaSignatureToMpcSignature}, for off-chain consumers building a
|
|
159
|
+
* transaction from the response. `r` comes out as `bigR.x` reduced mod the
|
|
160
|
+
* curve order. Rejects records that do not even hold the shape, since posts
|
|
161
|
+
* are unauthenticated and a malformed record is garbage. `bigR.y` is NOT
|
|
162
|
+
* checked against the curve or the recovery id: signature verification is
|
|
163
|
+
* the authority, not this decoder.
|
|
164
|
+
*
|
|
165
|
+
* @param signature - The stored-form signature as posted.
|
|
166
|
+
* @returns The scalar-form signature.
|
|
167
|
+
* @throws Error if a component has the wrong byte length or the recovery id
|
|
168
|
+
* is not 0 or 1.
|
|
169
|
+
*/
|
|
170
|
+
export function mpcSignatureToEcdsaSignature(signature) {
|
|
171
|
+
const { bigR, s, recoveryId } = signature;
|
|
172
|
+
if (bigR.x.length !== 32 || bigR.y.length !== 32 || s.length !== 32) {
|
|
173
|
+
throw new Error("expected 32-byte bigR.x/bigR.y/s in a stored signature");
|
|
174
|
+
}
|
|
175
|
+
if (recoveryId !== 0n && recoveryId !== 1n) {
|
|
176
|
+
throw new Error(`expected a recovery id of 0 or 1, got ${recoveryId}`);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
r: bytesToBigintBE(bigR.x) % SECP256K1_ORDER,
|
|
180
|
+
s: bytesToBigintBE(s),
|
|
181
|
+
recoveryId: Number(recoveryId),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
88
184
|
/**
|
|
89
185
|
* Parse a secp256k1 public key from SEC1 hex (compressed or uncompressed,
|
|
90
|
-
* optional `0x` prefix) into the Compact runtime's `Secp256k1Point` shape
|
|
186
|
+
* optional `0x` prefix) into the Compact runtime's `Secp256k1Point` shape:
|
|
91
187
|
* how deploys receive the MPC response key to pin.
|
|
92
188
|
*
|
|
93
189
|
* @param value - The SEC1 hex public key.
|
|
@@ -112,7 +208,7 @@ export function parseSecp256k1PublicKey(value) {
|
|
|
112
208
|
}
|
|
113
209
|
/**
|
|
114
210
|
* Format a secp256k1 public key point as uncompressed SEC1 hex (with `0x`
|
|
115
|
-
* prefix)
|
|
211
|
+
* prefix): the round-trip inverse of {@link parseSecp256k1PublicKey}, for
|
|
116
212
|
* handing a response key to deploys via env/config.
|
|
117
213
|
*
|
|
118
214
|
* @param point - The point to format.
|
|
@@ -123,7 +219,7 @@ export function formatSecp256k1PublicKey(point) {
|
|
|
123
219
|
return `0x04${toBE32(point.x)}${toBE32(point.y)}`;
|
|
124
220
|
}
|
|
125
221
|
/**
|
|
126
|
-
* Derive the `Secp256k1Point` of a secret key
|
|
222
|
+
* Derive the `Secp256k1Point` of a secret key: a convenience for tests and
|
|
127
223
|
* signers that hold key material as raw bytes.
|
|
128
224
|
*
|
|
129
225
|
* @param secretKey - The 32-byte secp256k1 secret key.
|
|
@@ -137,4 +233,27 @@ export function secp256k1PublicKeyOf(secretKey) {
|
|
|
137
233
|
identity: false,
|
|
138
234
|
};
|
|
139
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* The attestation digest of a respond-bidirectional response:
|
|
238
|
+
* `keccak256(requestId || serializedOutput)`, the 32-byte digest the MPC
|
|
239
|
+
* ECDSA-signs to attest a remote execution.
|
|
240
|
+
*
|
|
241
|
+
* TS twin of the size-generic Compact circuit
|
|
242
|
+
* `calculateSignetAttestationDigest` (which the compiler cannot export
|
|
243
|
+
* compiled, so this is the one sanctioned re-implementation, pinned
|
|
244
|
+
* byte-for-byte against the fixed-width oracle circuits in
|
|
245
|
+
* circuits.compact). The constructions agree because the circuit's keccak
|
|
246
|
+
* preimage of the `[RequestId, Bytes<N>]` pair is the raw concatenated
|
|
247
|
+
* bytes, and it matches the MPC's respond-bidirectional hash
|
|
248
|
+
* (`hash(request_id || serialized_output)`: one flat concatenation, one
|
|
249
|
+
* hash). The output is hashed AS GIVEN, at its exact length: no padding and
|
|
250
|
+
* no length binding.
|
|
251
|
+
*
|
|
252
|
+
* @param requestId - The 32-byte request id the response answers.
|
|
253
|
+
* @param serializedOutput - The serialised execution output, exact unpadded bytes.
|
|
254
|
+
* @returns The 32-byte attestation digest.
|
|
255
|
+
*/
|
|
256
|
+
export function calculateSignetAttestationDigest(requestId, serializedOutput) {
|
|
257
|
+
return ethers.getBytes(ethers.keccak256(ethers.concat([requestId, serializedOutput])));
|
|
258
|
+
}
|
|
140
259
|
//# sourceMappingURL=ecdsa-attestation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa-attestation.js","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,
|
|
1
|
+
{"version":3,"file":"ecdsa-attestation.js","sourceRoot":"","sources":["../src/ecdsa-attestation.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,sEAAsE;AACtE,kEAAkE;AAClE,uEAAuE;AACvE,2EAA2E;AAC3E,kEAAkE;AAClE,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,oEAAoE;AACpE,4DAA4D;AAC5D,oCAAoC;AACpC,EAAE;AACF,wEAAwE;AACxE,8BAA8B;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAUvD,uCAAuC;AACvC,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC;AAExD,uEAAuE;AACvE,MAAM,CAAC,MAAM,SAAS,GAAG,8EAA8E,CAAC;AAExG;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,iEAAiE;QACjE,qDAAqD;QACrD,MAAM,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAA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;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAqB;IAC5D,MAAM,MAAM,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACvE,OAAO,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAqB;IACxD,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO;QACL,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7C,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gCAAgC,CAC9C,SAAoB,EACpB,gBAA4B;IAE5B,OAAO,MAAM,CAAC,QAAQ,CACpB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Secp256k1Point } from "./ecdsa-attestation.ts";
|
|
2
2
|
/**
|
|
3
|
-
* Domain prefix of the sig-net
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Domain prefix of the sig-net v2.0.0 epsilon derivation scheme. The full
|
|
4
|
+
* derivation string is `<prefix>:<chainId>:<requester>:<path>` (colon-separated),
|
|
5
|
+
* matching `caip2_derivation_path` in the MPC's `crypto/src/kdf.rs`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const EPSILON_DERIVATION_PREFIX = "sig.network
|
|
7
|
+
export declare const EPSILON_DERIVATION_PREFIX = "sig.network v2.0.0 epsilon derivation";
|
|
8
8
|
/**
|
|
9
9
|
* CAIP-2 chain id under which the MPC derives keys for requests originating
|
|
10
10
|
* from Midnight contracts.
|
|
@@ -29,8 +29,8 @@ export declare const MIDNIGHT_TESTNET_CHAIN_ID = "midnight:testnet";
|
|
|
29
29
|
export declare const MIDNIGHT_RESPOND_BIDIRECTIONAL_PATH = "midnight response key";
|
|
30
30
|
/**
|
|
31
31
|
* Derive the EVM address the MPC network signs from for a given Midnight
|
|
32
|
-
* contract and derivation path, using the sig-net
|
|
33
|
-
* `epsilon = keccak256("<prefix
|
|
32
|
+
* contract and derivation path, using the sig-net v2.0.0 epsilon scheme:
|
|
33
|
+
* `epsilon = keccak256("<prefix>:<chainId>:<contractAddress>:<path>")` and
|
|
34
34
|
* `derivedPubKey = mpcRootPubKey + epsilon * G` on secp256k1.
|
|
35
35
|
*
|
|
36
36
|
* The MPC treats `path` as an opaque string: the vault's own account uses the
|
|
@@ -48,8 +48,8 @@ export declare const MIDNIGHT_RESPOND_BIDIRECTIONAL_PATH = "midnight response ke
|
|
|
48
48
|
*/
|
|
49
49
|
export declare function deriveEvmAddress(mpcSecp256k1PubkeyHex: string, contractAddress: string, path: string, chainId?: string): string;
|
|
50
50
|
/**
|
|
51
|
-
* The epsilon scalar of the sig-net
|
|
52
|
-
* `keccak256("<prefix
|
|
51
|
+
* The epsilon scalar of the sig-net v2.0.0 derivation scheme:
|
|
52
|
+
* `keccak256("<prefix>:<chainId>:<requester>:<path>")` reduced mod the
|
|
53
53
|
* secp256k1 curve order. Child keys are `root + epsilon` (secret side) and
|
|
54
54
|
* `rootPubKey + epsilon * G` (public side).
|
|
55
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epsilon-derivation.d.ts","sourceRoot":"","sources":["../src/epsilon-derivation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"epsilon-derivation.d.ts","sourceRoot":"","sources":["../src/epsilon-derivation.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,0CAA0C,CAAC;AAEjF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mCAAmC,0BAA0B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,qBAAqB,EAAE,MAAM,EAC7B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAkC,GAC1C,MAAM,CAGR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAkC,GAC1C,MAAM,CAKR;AA6BD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,qBAAqB,EAAE,MAAM,EAC7B,qBAAqB,EAAE,MAAM,GAC5B,cAAc,CAQhB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAC7C,gBAAgB,EAAE,UAAU,EAC5B,qBAAqB,EAAE,MAAM,GAC5B,UAAU,CAwBZ"}
|