@sig-net/midnight 0.0.6 → 0.0.7
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 +23 -20
- package/dist/constants.d.ts +4 -16
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -16
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +79 -0
- package/dist/ecdsa-attestation.d.ts.map +1 -0
- package/dist/ecdsa-attestation.js +140 -0
- package/dist/ecdsa-attestation.js.map +1 -0
- package/dist/epsilon-derivation.d.ts +60 -0
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +106 -5
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +74 -52
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +38 -31
- package/dist/managed/contract/index.js +232 -382
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +14 -13
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +31 -20
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +5 -5
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +4 -4
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-state-reader.d.ts +101 -112
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +123 -115
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-request-feed.d.ts +4 -3
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +9 -8
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-resolver.d.ts +6 -4
- package/dist/signet-request-resolver.d.ts.map +1 -1
- package/dist/signet-request-resolver.js +8 -6
- package/dist/signet-request-resolver.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +21 -20
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +35 -23
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +93 -59
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +84 -67
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +277 -425
- package/src/circuits.compact +22 -21
- package/dist/ecdsa.d.ts +0 -114
- package/dist/ecdsa.d.ts.map +0 -1
- package/dist/ecdsa.js +0 -145
- package/dist/ecdsa.js.map +0 -1
package/src/circuits.compact
CHANGED
|
@@ -3,35 +3,36 @@ pragma language_version >= 0.25;
|
|
|
3
3
|
// Compiled export surface of the Signet module.
|
|
4
4
|
//
|
|
5
5
|
// Signet.compact must stay a module-only file (that is what lets contracts
|
|
6
|
-
// import it), but a bare module compiles to nothing. This
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
6
|
+
// import it), but a bare module compiles to nothing. This contract-less
|
|
7
|
+
// program re-exports the module's pure circuits so the compiler emits them as
|
|
8
|
+
// pureCircuits in managed/contract/index.js, giving the package an
|
|
9
|
+
// in-process, provable-logic-identical reference implementation: unit tests
|
|
10
|
+
// exercise the REAL circuits, and off-chain code (the attestation digest,
|
|
11
|
+
// response verification, key-pin hashing, notification packing) reuses them
|
|
12
12
|
// instead of hand-porting the algorithms. Off-chain code only ever DECODES a
|
|
13
|
-
//
|
|
14
|
-
// fixtures with the compiled packer to pin the pack<->decode lockstep.
|
|
13
|
+
// SignBidirectionalEventNotification (fixed-offset byte reads), but tests
|
|
14
|
+
// build fixtures with the compiled packer to pin the pack<->decode lockstep.
|
|
15
15
|
//
|
|
16
16
|
// ONLY the non-generic circuits are exported here. The request circuits
|
|
17
|
-
// (calculateRequestId,
|
|
18
|
-
// tx-params type, the compiler cannot export
|
|
19
|
-
// the top level, and this package is
|
|
20
|
-
// instantiation is a CLIENT contract's choice and
|
|
21
|
-
//
|
|
22
|
-
// copy
|
|
23
|
-
// keys), so it alone has a documented-deviation TS twin
|
|
24
|
-
// kept honest by caller-contract's
|
|
17
|
+
// (calculateRequestId, constructSignBidirectionalEvent) are generic over the
|
|
18
|
+
// tx-params type and schema lengths, the compiler cannot export
|
|
19
|
+
// type-parameterized circuits from the top level, and this package is
|
|
20
|
+
// client-agnostic: a capacity instantiation is a CLIENT contract's choice and
|
|
21
|
+
// never belongs here. constructSignBidirectionalEvent is contract-only, so it
|
|
22
|
+
// needs no off-chain copy. calculateRequestId IS needed off-chain (clients
|
|
23
|
+
// recompute ledger map keys), so it alone has a documented-deviation TS twin
|
|
24
|
+
// in signet-requests.ts, kept honest by caller-contract's
|
|
25
|
+
// submitSignatureRequest round-trip test.
|
|
25
26
|
//
|
|
26
27
|
// Compile with --skip-zk only: pure circuits run in TS without proving keys.
|
|
28
|
+
// The secp256k1 types require the --feature-zkir-v3 compiler flag.
|
|
27
29
|
|
|
28
30
|
import CompactStandardLibrary;
|
|
29
31
|
import "./Signet";
|
|
30
32
|
|
|
31
33
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
evmAddressAbiValue
|
|
34
|
+
signetAttestationDigest,
|
|
35
|
+
verifyRespondBidirectionalEvent,
|
|
36
|
+
signetKeyHash,
|
|
37
|
+
constructSignBidirectionalEventNotificationV1
|
|
37
38
|
};
|
package/dist/ecdsa.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { type Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
export type { Secp256k1Point } from "@midnight-ntwrk/compact-runtime";
|
|
3
|
-
/** secp256k1 curve (group) order n — the scalar field the signature r, s live in. */
|
|
4
|
-
export declare const SECP256K1_ORDER: bigint;
|
|
5
|
-
/**
|
|
6
|
-
* BLS12-381 scalar field order (the Compact `Field` type modulus). Retained
|
|
7
|
-
* because {@link bigintToBytes32} interprets negative `Field` values in it and
|
|
8
|
-
* signet-requests.ts imports the byte helpers below.
|
|
9
|
-
*/
|
|
10
|
-
export declare const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
|
|
11
|
-
/**
|
|
12
|
-
* Convert little-endian bytes to a bigint. Matches Compact's
|
|
13
|
-
* `Bytes<32> as Field` / `Bytes<32> as Secp256k1Scalar` interpretation (and
|
|
14
|
-
* the MPC monitor's ABI-word decoding convention).
|
|
15
|
-
*
|
|
16
|
-
* @param bytes - Little-endian byte array.
|
|
17
|
-
* @returns The decoded non-negative integer.
|
|
18
|
-
*/
|
|
19
|
-
export declare function bytesToBigint(bytes: Uint8Array): bigint;
|
|
20
|
-
/**
|
|
21
|
-
* Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
|
|
22
|
-
* `Field as Bytes<32>` / `Secp256k1Scalar as Bytes<32>` encoding (the inverse
|
|
23
|
-
* of {@link bytesToBigint}); negative inputs are interpreted in the BLS scalar
|
|
24
|
-
* field.
|
|
25
|
-
*
|
|
26
|
-
* @param n - The integer to encode.
|
|
27
|
-
* @returns The 32-byte little-endian encoding.
|
|
28
|
-
*/
|
|
29
|
-
export declare function bigintToBytes32(n: bigint): Uint8Array;
|
|
30
|
-
/**
|
|
31
|
-
* An ECDSA signature over the attestation digest (TS twin of
|
|
32
|
-
* CompactStandardLibrary's `Secp256k1EcdsaSignature`). Both scalars are plain
|
|
33
|
-
* bigints mod {@link SECP256K1_ORDER}; convert to the ledger form with
|
|
34
|
-
* {@link ecdsaSignatureToLeBytes}.
|
|
35
|
-
*/
|
|
36
|
-
export interface EcdsaSignature {
|
|
37
|
-
/** Signature scalar r. */
|
|
38
|
-
r: bigint;
|
|
39
|
-
/** Signature scalar s (low-s normalized by {@link signAttestation}). */
|
|
40
|
-
s: bigint;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* The little-endian 32-byte scalar encoding of an {@link EcdsaSignature} — the
|
|
44
|
-
* exact `sigR`/`sigS` bytes the Compact `RespondBidirectional` struct stores
|
|
45
|
-
* (the byte order the `Secp256k1Scalar as Bytes<32>` cast produces).
|
|
46
|
-
*/
|
|
47
|
-
export interface EcdsaSignatureBytes {
|
|
48
|
-
/** Signature scalar r as 32 little-endian bytes. */
|
|
49
|
-
sigR: Uint8Array;
|
|
50
|
-
/** Signature scalar s as 32 little-endian bytes. */
|
|
51
|
-
sigS: Uint8Array;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Sign a 32-byte attestation digest with secp256k1 ECDSA, matching
|
|
55
|
-
* CompactStandardLibrary's `secp256k1EcdsaVerify`: the digest IS the message
|
|
56
|
-
* hash (interpreted big-endian, RFC 6979), so signing is `prehash: false` —
|
|
57
|
-
* noble must not re-hash it. The digest is the compiled
|
|
58
|
-
* `pureCircuits.signetAttestationMessage(requestId, serializedOutput,
|
|
59
|
-
* outputLen)`. noble normalizes to low-s by default; the verifier accepts
|
|
60
|
-
* either s, so this is a convention, not a requirement.
|
|
61
|
-
*
|
|
62
|
-
* @param digest - The 32-byte attestation digest to sign.
|
|
63
|
-
* @param secretKey - The 32-byte secp256k1 private key (the MPC root key).
|
|
64
|
-
* @returns The signature `{ r, s }`.
|
|
65
|
-
*/
|
|
66
|
-
export declare function signAttestation(digest: Uint8Array, secretKey: Uint8Array): EcdsaSignature;
|
|
67
|
-
/**
|
|
68
|
-
* Encode an {@link EcdsaSignature}'s scalars as the little-endian 32-byte
|
|
69
|
-
* `sigR`/`sigS` the Compact `RespondBidirectional` struct stores — the form
|
|
70
|
-
* the verifying circuits cast back with `as Secp256k1Scalar`.
|
|
71
|
-
*
|
|
72
|
-
* @param signature - The signature to encode.
|
|
73
|
-
* @returns The `{ sigR, sigS }` little-endian scalar bytes.
|
|
74
|
-
*/
|
|
75
|
-
export declare function ecdsaSignatureToLeBytes(signature: EcdsaSignature): EcdsaSignatureBytes;
|
|
76
|
-
/**
|
|
77
|
-
* Derive the secp256k1 public key point from a private key — the MPC
|
|
78
|
-
* attestation key, which is the MPC root key used directly as the secp256k1
|
|
79
|
-
* private key (the same key the EVM signing accounts epsilon-derive from).
|
|
80
|
-
*
|
|
81
|
-
* @param secretKey - The 32-byte secp256k1 private key (the MPC root key).
|
|
82
|
-
* @returns The public key as a {@link Secp256k1Point}.
|
|
83
|
-
*/
|
|
84
|
-
export declare function secp256k1PublicKeyFromSecretKey(secretKey: Uint8Array): Secp256k1Point;
|
|
85
|
-
/**
|
|
86
|
-
* Parse a secp256k1 public key from its 0x-hex config/env form (compressed
|
|
87
|
-
* 33-byte or uncompressed 65-byte) into the runtime's point shape — how
|
|
88
|
-
* deploys receive `MPC_SECP256K1_PUBKEY`.
|
|
89
|
-
*
|
|
90
|
-
* @param value - The 0x-hex public key (0x prefix optional).
|
|
91
|
-
* @returns The parsed point.
|
|
92
|
-
* @throws Error if the value is not a valid secp256k1 point encoding.
|
|
93
|
-
*/
|
|
94
|
-
export declare function parseSecp256k1PublicKey(value: string): Secp256k1Point;
|
|
95
|
-
/**
|
|
96
|
-
* Format a secp256k1 public key as the compressed 0x-hex config/env form that
|
|
97
|
-
* {@link parseSecp256k1PublicKey} accepts — the round-trip inverse, for
|
|
98
|
-
* handing a derived key to deploys as `MPC_SECP256K1_PUBKEY`.
|
|
99
|
-
*
|
|
100
|
-
* @param point - The point to format.
|
|
101
|
-
* @returns The compressed public key as 0x-prefixed hex.
|
|
102
|
-
* @throws Error if the point is the identity (has no compressed encoding).
|
|
103
|
-
*/
|
|
104
|
-
export declare function formatSecp256k1PublicKey(point: Secp256k1Point): string;
|
|
105
|
-
/**
|
|
106
|
-
* Hash a secp256k1 point exactly as the circuits do
|
|
107
|
-
* (`persistentHash<Secp256k1Point>`) — the form the signet contract and caller
|
|
108
|
-
* seal as `mpcPubKeyHash`.
|
|
109
|
-
*
|
|
110
|
-
* @param point - The point to hash.
|
|
111
|
-
* @returns The 32-byte hash.
|
|
112
|
-
*/
|
|
113
|
-
export declare function hashSecp256k1Point(point: Secp256k1Point): Uint8Array;
|
|
114
|
-
//# sourceMappingURL=ecdsa.d.ts.map
|
package/dist/ecdsa.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../src/ecdsa.ts"],"names":[],"mappings":"AAgBA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AAKzC,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,qFAAqF;AACrF,eAAO,MAAM,eAAe,QAA2B,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,SAAS,iFAAiF,CAAC;AAExG;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAQrD;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,0BAA0B;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,wEAAwE;IACxE,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,IAAI,EAAE,UAAU,CAAC;IACjB,oDAAoD;IACpD,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,UAAU,GACpB,cAAc,CAMhB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,cAAc,GACxB,mBAAmB,CAKrB;AAED;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,UAAU,GACpB,cAAc,CAGhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAUrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAKtE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,UAAU,CAEpE"}
|
package/dist/ecdsa.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// secp256k1 ECDSA helpers — the TS side of the shared attestation flow:
|
|
2
|
-
// SIGNING (which needs the secret scalar, so it cannot be a circuit), key
|
|
3
|
-
// parsing/formatting/hashing, and the little-endian scalar-byte plumbing the
|
|
4
|
-
// ledger struct stores. Everything provable stays in Compact: the attestation
|
|
5
|
-
// message is the COMPILED `pureCircuits.signetAttestationMessage` (this file
|
|
6
|
-
// never re-implements it) and verification is CompactStandardLibrary's
|
|
7
|
-
// `secp256k1EcdsaVerify`, run by the signet contract at post time and by the
|
|
8
|
-
// caller at settle time.
|
|
9
|
-
//
|
|
10
|
-
// This belongs in github.com/sig-net/signet.js as its Midnight adapter —
|
|
11
|
-
// kept here until upstreamed. It is Midnight-specific only in the point-hash
|
|
12
|
-
// form (`persistentHash<Secp256k1Point>` via @midnight-ntwrk/compact-runtime),
|
|
13
|
-
// which is exactly the deploy-time key pin the contracts seal.
|
|
14
|
-
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
15
|
-
import { CompactTypeSecp256k1Point, persistentHash, } from "@midnight-ntwrk/compact-runtime";
|
|
16
|
-
/** secp256k1 curve (group) order n — the scalar field the signature r, s live in. */
|
|
17
|
-
export const SECP256K1_ORDER = secp256k1.Point.Fn.ORDER;
|
|
18
|
-
/**
|
|
19
|
-
* BLS12-381 scalar field order (the Compact `Field` type modulus). Retained
|
|
20
|
-
* because {@link bigintToBytes32} interprets negative `Field` values in it and
|
|
21
|
-
* signet-requests.ts imports the byte helpers below.
|
|
22
|
-
*/
|
|
23
|
-
export const BLS_ORDER = 52435875175126190479447740508185965837690552500527637822603658699938581184513n;
|
|
24
|
-
/**
|
|
25
|
-
* Convert little-endian bytes to a bigint. Matches Compact's
|
|
26
|
-
* `Bytes<32> as Field` / `Bytes<32> as Secp256k1Scalar` interpretation (and
|
|
27
|
-
* the MPC monitor's ABI-word decoding convention).
|
|
28
|
-
*
|
|
29
|
-
* @param bytes - Little-endian byte array.
|
|
30
|
-
* @returns The decoded non-negative integer.
|
|
31
|
-
*/
|
|
32
|
-
export function bytesToBigint(bytes) {
|
|
33
|
-
let result = 0n;
|
|
34
|
-
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
35
|
-
result = (result << 8n) | BigInt(bytes[i]);
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Convert a bigint to exactly 32 little-endian bytes. Matches Compact's
|
|
41
|
-
* `Field as Bytes<32>` / `Secp256k1Scalar as Bytes<32>` encoding (the inverse
|
|
42
|
-
* of {@link bytesToBigint}); negative inputs are interpreted in the BLS scalar
|
|
43
|
-
* field.
|
|
44
|
-
*
|
|
45
|
-
* @param n - The integer to encode.
|
|
46
|
-
* @returns The 32-byte little-endian encoding.
|
|
47
|
-
*/
|
|
48
|
-
export function bigintToBytes32(n) {
|
|
49
|
-
const buf = new Uint8Array(32);
|
|
50
|
-
let v = n < 0n ? n + BLS_ORDER : n;
|
|
51
|
-
for (let i = 0; i < 32; i++) {
|
|
52
|
-
buf[i] = Number(v & 0xffn);
|
|
53
|
-
v >>= 8n;
|
|
54
|
-
}
|
|
55
|
-
return buf;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Sign a 32-byte attestation digest with secp256k1 ECDSA, matching
|
|
59
|
-
* CompactStandardLibrary's `secp256k1EcdsaVerify`: the digest IS the message
|
|
60
|
-
* hash (interpreted big-endian, RFC 6979), so signing is `prehash: false` —
|
|
61
|
-
* noble must not re-hash it. The digest is the compiled
|
|
62
|
-
* `pureCircuits.signetAttestationMessage(requestId, serializedOutput,
|
|
63
|
-
* outputLen)`. noble normalizes to low-s by default; the verifier accepts
|
|
64
|
-
* either s, so this is a convention, not a requirement.
|
|
65
|
-
*
|
|
66
|
-
* @param digest - The 32-byte attestation digest to sign.
|
|
67
|
-
* @param secretKey - The 32-byte secp256k1 private key (the MPC root key).
|
|
68
|
-
* @returns The signature `{ r, s }`.
|
|
69
|
-
*/
|
|
70
|
-
export function signAttestation(digest, secretKey) {
|
|
71
|
-
const signature = secp256k1.Signature.fromBytes(secp256k1.sign(digest, secretKey, { prehash: false }), "compact");
|
|
72
|
-
return { r: signature.r, s: signature.s };
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Encode an {@link EcdsaSignature}'s scalars as the little-endian 32-byte
|
|
76
|
-
* `sigR`/`sigS` the Compact `RespondBidirectional` struct stores — the form
|
|
77
|
-
* the verifying circuits cast back with `as Secp256k1Scalar`.
|
|
78
|
-
*
|
|
79
|
-
* @param signature - The signature to encode.
|
|
80
|
-
* @returns The `{ sigR, sigS }` little-endian scalar bytes.
|
|
81
|
-
*/
|
|
82
|
-
export function ecdsaSignatureToLeBytes(signature) {
|
|
83
|
-
return {
|
|
84
|
-
sigR: bigintToBytes32(signature.r),
|
|
85
|
-
sigS: bigintToBytes32(signature.s),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Derive the secp256k1 public key point from a private key — the MPC
|
|
90
|
-
* attestation key, which is the MPC root key used directly as the secp256k1
|
|
91
|
-
* private key (the same key the EVM signing accounts epsilon-derive from).
|
|
92
|
-
*
|
|
93
|
-
* @param secretKey - The 32-byte secp256k1 private key (the MPC root key).
|
|
94
|
-
* @returns The public key as a {@link Secp256k1Point}.
|
|
95
|
-
*/
|
|
96
|
-
export function secp256k1PublicKeyFromSecretKey(secretKey) {
|
|
97
|
-
const point = secp256k1.Point.fromBytes(secp256k1.getPublicKey(secretKey, false));
|
|
98
|
-
return { x: point.x, y: point.y, identity: false };
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Parse a secp256k1 public key from its 0x-hex config/env form (compressed
|
|
102
|
-
* 33-byte or uncompressed 65-byte) into the runtime's point shape — how
|
|
103
|
-
* deploys receive `MPC_SECP256K1_PUBKEY`.
|
|
104
|
-
*
|
|
105
|
-
* @param value - The 0x-hex public key (0x prefix optional).
|
|
106
|
-
* @returns The parsed point.
|
|
107
|
-
* @throws Error if the value is not a valid secp256k1 point encoding.
|
|
108
|
-
*/
|
|
109
|
-
export function parseSecp256k1PublicKey(value) {
|
|
110
|
-
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
111
|
-
try {
|
|
112
|
-
const point = secp256k1.Point.fromHex(hex);
|
|
113
|
-
return { x: point.x, y: point.y, identity: false };
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
throw new Error(`expected a secp256k1 public key as compressed/uncompressed 0x-hex; got "${value}"`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Format a secp256k1 public key as the compressed 0x-hex config/env form that
|
|
121
|
-
* {@link parseSecp256k1PublicKey} accepts — the round-trip inverse, for
|
|
122
|
-
* handing a derived key to deploys as `MPC_SECP256K1_PUBKEY`.
|
|
123
|
-
*
|
|
124
|
-
* @param point - The point to format.
|
|
125
|
-
* @returns The compressed public key as 0x-prefixed hex.
|
|
126
|
-
* @throws Error if the point is the identity (has no compressed encoding).
|
|
127
|
-
*/
|
|
128
|
-
export function formatSecp256k1PublicKey(point) {
|
|
129
|
-
if (point.identity) {
|
|
130
|
-
throw new Error("cannot format the identity point as a public key");
|
|
131
|
-
}
|
|
132
|
-
return `0x${secp256k1.Point.fromAffine({ x: point.x, y: point.y }).toHex(true)}`;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Hash a secp256k1 point exactly as the circuits do
|
|
136
|
-
* (`persistentHash<Secp256k1Point>`) — the form the signet contract and caller
|
|
137
|
-
* seal as `mpcPubKeyHash`.
|
|
138
|
-
*
|
|
139
|
-
* @param point - The point to hash.
|
|
140
|
-
* @returns The 32-byte hash.
|
|
141
|
-
*/
|
|
142
|
-
export function hashSecp256k1Point(point) {
|
|
143
|
-
return persistentHash(CompactTypeSecp256k1Point, point);
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=ecdsa.js.map
|
package/dist/ecdsa.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.js","sourceRoot":"","sources":["../src/ecdsa.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,yBAAyB;AACzB,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,+EAA+E;AAC/E,+DAA+D;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EACL,yBAAyB,EACzB,cAAc,GAEf,MAAM,iCAAiC,CAAC;AAOzC,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC;AAExD;;;;GAIG;AACH,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,MAAM,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,CAAS;IACvC,MAAM,GAAG,GAAG,IAAI,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