@sig-net/midnight 0.0.2 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sig-net/midnight",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Midnight-side sig-net integration — the seed of a future signet.js Midnight adapter.",
6
6
  "//exports": "Local dev consumes raw TS source. `publishConfig.exports` below swaps this to the emitted ./dist at publish time, so npm consumers get JS + .d.ts while the monorepo keeps resolving to src.",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "files": [
14
14
  "dist",
15
- "src"
15
+ "src/*.compact"
16
16
  ],
17
17
  "scripts": {
18
18
  "compile": "compact compile --skip-zk src/circuits.compact src/managed",
package/src/constants.ts DELETED
@@ -1,97 +0,0 @@
1
- // MPC routing constants + the padded-ASCII codec for the signet request
2
- // structs. Field widths mirror Signet.compact (the wire format —
3
- // keep in lockstep); the string constants are the values the MPC network
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")`) — the
6
- // MVP's 2-byte length-prefixed codec is gone with the old layout.
7
- //
8
- // The routing constants belong in github.com/sig-net/signet.js — kept here
9
- // until upstreamed.
10
-
11
- /** Width of `SignBidirectionalRequest.caip2Id` (`Bytes<32>`). */
12
- export const CAIP2_ID_BYTES = 32;
13
-
14
- /** Width of `SignBidirectionalRequest.algo` (`Bytes<32>`). */
15
- export const ALGO_BYTES = 32;
16
-
17
- /** Width of `SignBidirectionalRequest.dest` (`Bytes<32>`). */
18
- export const DEST_BYTES = 32;
19
-
20
- /** Width of `SignBidirectionalRequest.params` (`Bytes<64>`). */
21
- export const MPC_PARAMS_BYTES = 64;
22
-
23
- /** Width of `SignBidirectionalRequest.outputDeserializationSchema` (`Bytes<128>`). */
24
- export const OUTPUT_DESERIALIZATION_SCHEMA_BYTES = 128;
25
-
26
- /** Width of `SignBidirectionalRequest.respondSerializationSchema` (`Bytes<128>`). */
27
- export const RESPOND_SERIALIZATION_SCHEMA_BYTES = 128;
28
-
29
- /** Width of `EVMCalldata.selector` (`Bytes<4>`) — the literal first 4 calldata bytes. */
30
- export const SELECTOR_BYTES = 4;
31
-
32
- /** Width of `RespondBidirectional.serializedOutput` (`Bytes<128>`). */
33
- export const SERIALIZED_OUTPUT_BYTES = 128;
34
-
35
- /**
36
- * The MPC's error sentinel: `serializedOutput` beginning with these four
37
- * bytes marks a failed/absent remote execution (mirrors the sig-net MPC's
38
- * MAGIC_ERROR_PREFIX).
39
- */
40
- export const MPC_ERROR_SENTINEL = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
41
-
42
- /**
43
- * Whether an attestation's serialized output reports a successful remote
44
- * execution: the first byte is 1 — the little-endian encoding of the
45
- * ABI-decoded success flag, matching the circuits'
46
- * `serializedOutput as Field == 1` check.
47
- *
48
- * @param serializedOutput - The attestation's serialized output.
49
- * @returns `true` when the remote call succeeded.
50
- */
51
- export function executionSucceeded(serializedOutput: Uint8Array): boolean {
52
- return serializedOutput[0] === 1;
53
- }
54
-
55
- /**
56
- * Whether an attestation's serialized output is the MPC's error sentinel
57
- * (see {@link MPC_ERROR_SENTINEL}) rather than a call result.
58
- *
59
- * @param serializedOutput - The attestation's serialized output.
60
- * @returns `true` when the MPC reported an execution error.
61
- */
62
- export function isExecutionError(serializedOutput: Uint8Array): boolean {
63
- return MPC_ERROR_SENTINEL.every((byte, index) => serializedOutput[index] === byte);
64
- }
65
-
66
- /** Signature algorithm the MPC uses for EVM chains (`algo` field value). */
67
- export const SIGNET_ALGO_ECDSA = "ecdsa";
68
-
69
- /** Destination chain family for EVM requests (`dest` field value). */
70
- export const SIGNET_DEST_ETHEREUM = "ethereum";
71
-
72
- /**
73
- * Default MPC key version (`keyVersion` field value). Version 0 is the
74
- * unsupported legacy format — the canonical MPC (and
75
- * `constructSignBidirectionalRequest`) requires `keyVersion >= 1`.
76
- */
77
- export const SIGNET_DEFAULT_KEY_VERSION = 1n;
78
-
79
- /**
80
- * Encode text as zero-padded ASCII bytes — the Compact `pad(N, "text")`
81
- * convention every string-ish field of the request structs uses (consumers
82
- * NUL-trim on decode).
83
- *
84
- * @param text - The ASCII text to encode.
85
- * @param length - The fixed field width in bytes.
86
- * @returns `text`'s bytes followed by zero padding to exactly `length`.
87
- * @throws If the encoded text does not fit in `length` bytes.
88
- */
89
- export function asciiPadded(text: string, length: number): Uint8Array {
90
- const encoded = new TextEncoder().encode(text);
91
- if (encoded.length > length) {
92
- throw new Error(`"${text}" is ${encoded.length} bytes — does not fit the ${length}-byte field`);
93
- }
94
- const out = new Uint8Array(length);
95
- out.set(encoded);
96
- return out;
97
- }
@@ -1,62 +0,0 @@
1
- // Epsilon key derivation: contract address + path -> derived EVM account.
2
- //
3
- // This belongs in github.com/sig-net/signet.js — kept here until upstreamed.
4
- // It is NOT imported from signet.js because signet.js's `deriveChildPublicKey`
5
- // implements the v2.0.0 COLON-separated epsilon format
6
- // (`sig.network v2.0.0 epsilon derivation:<chainId>:<requester>:<path>`),
7
- // which is incompatible with the live sig-net response server's v1.0.0
8
- // COMMA-separated format (see solana-signet-program
9
- // clients/response-server/src/modules/CryptoUtils.ts). The two schemes hash
10
- // different strings and therefore derive different accounts; this module
11
- // matches the server.
12
-
13
- import { secp256k1 } from "@noble/curves/secp256k1.js";
14
- import { computeAddress, keccak256, SigningKey, toUtf8Bytes } from "ethers";
15
-
16
- /**
17
- * Domain prefix of the sig-net v1.0.0 epsilon derivation scheme, as used by
18
- * the live response server. The full derivation string is
19
- * `<prefix>,<chainId>,<requester>,<path>` (comma-separated).
20
- */
21
- export const EPSILON_DERIVATION_PREFIX = "sig.network v1.0.0 epsilon derivation";
22
-
23
- /**
24
- * CAIP-2 chain id under which the MPC derives keys for requests originating
25
- * from Midnight contracts.
26
- */
27
- export const MIDNIGHT_TESTNET_CHAIN_ID = "midnight:testnet";
28
-
29
- /**
30
- * Derive the EVM address the MPC network signs from for a given Midnight
31
- * contract and derivation path, using the sig-net v1.0.0 epsilon scheme:
32
- * `epsilon = keccak256("<prefix>,<chainId>,<contractAddress>,<path>")` and
33
- * `derivedPubKey = mpcRootPubKey + epsilon * G` on secp256k1.
34
- *
35
- * The MPC treats `path` as an opaque string: the vault's own account uses the
36
- * literal path `"vault"`, a user's account uses the lowercase hex of their
37
- * identity commitment.
38
- *
39
- * @param mpcSecp256k1PubkeyHex - The MPC root secp256k1 public key as 0x-hex
40
- * (compressed or uncompressed; normalized internally).
41
- * @param contractAddress - The Midnight contract address the request
42
- * originates from (the "requester" in the derivation string).
43
- * @param path - The derivation path string (e.g. `"vault"` or a commitment
44
- * hex).
45
- * @param chainId - CAIP-2 chain id component of the derivation string.
46
- * @returns The derived EVM address as a 0x-prefixed EIP-55 checksummed string.
47
- */
48
- export function deriveEvmAddress(
49
- mpcSecp256k1PubkeyHex: string,
50
- contractAddress: string,
51
- path: string,
52
- chainId: string = MIDNIGHT_TESTNET_CHAIN_ID,
53
- ): string {
54
- const fullPath = `${EPSILON_DERIVATION_PREFIX},${chainId},${contractAddress},${path}`;
55
- // Reduce mod n before multiplying: noble throws on scalars >= n, whereas the
56
- // server's scalar arithmetic reduces implicitly.
57
- const epsilon = BigInt(keccak256(toUtf8Bytes(fullPath))) % secp256k1.Point.Fn.ORDER;
58
- const rootPubKeyHex = SigningKey.computePublicKey(mpcSecp256k1PubkeyHex, false);
59
- const rootPoint = secp256k1.Point.fromHex(rootPubKeyHex.slice(2));
60
- const derivedPoint = epsilon === 0n ? rootPoint : rootPoint.add(secp256k1.Point.BASE.multiply(epsilon));
61
- return computeAddress(`0x${derivedPoint.toHex(false)}`);
62
- }
package/src/index.ts DELETED
@@ -1,29 +0,0 @@
1
- // Midnight-side sig-net integration. See README.md for the module plan:
2
- // request-id, calldata-builder, tx-builder, codec, constants, schnorr,
3
- // state-reader, response-poller — ported bit by bit from the old repo's
4
- // boilerplate/contract-cli/src/signet/.
5
-
6
- export * from "./signet-requests.ts";
7
- export * from "./signature-state-reading.ts";
8
- export * from "./signature-requests-state-reader.ts";
9
- export * from "./signet-contract-state-reader.ts";
10
- export * from "./signature-response-verification.ts";
11
- export * from "./signet-request-response-reader.ts";
12
- export * from "./signet-request-resolver.ts";
13
- export * from "./signet-request-feed.ts";
14
- export * from "./constants.ts";
15
- export * from "./epsilon-derivation.ts";
16
- export * from "./schnorr.ts";
17
-
18
- /**
19
- * Compiled pure circuits of Signet.compact (run `yarn compile` first): the
20
- * executable reference implementation of the client-agnostic circuits —
21
- * path<->identity checks, the attestation message, the notification packer
22
- * (`constructSignBidirectionalNotificationV1`), and the Schnorr challenge.
23
- * Off-chain code MUST use these instead of re-porting the algorithms — they
24
- * are the same compiled logic the contracts prove. The generic request
25
- * circuits cannot be compiled here (type-parameterized): request construction
26
- * is contract-only, and request-id hashing has a documented-deviation TS twin
27
- * (`calculateRequestId` in signet-requests.ts).
28
- */
29
- export { pureCircuits, type PureCircuits } from "./managed/contract/index.js";
@@ -1,222 +0,0 @@
1
- {
2
- "compiler-version": "0.33.0",
3
- "language-version": "0.25.0",
4
- "runtime-version": "0.18.0-rc.0",
5
- "circuits": [
6
- {
7
- "name": "constructSignBidirectionalNotificationV1",
8
- "pure": true,
9
- "proof": false,
10
- "arguments": [
11
- {
12
- "name": "callerAddress",
13
- "type": {
14
- "type-name": "Struct",
15
- "name": "ContractAddress",
16
- "elements": [
17
- {
18
- "name": "bytes",
19
- "type": {
20
- "type-name": "Bytes",
21
- "length": 32
22
- }
23
- }
24
- ]
25
- }
26
- },
27
- {
28
- "name": "requestId",
29
- "type": {
30
- "type-name": "Bytes",
31
- "length": 32
32
- }
33
- },
34
- {
35
- "name": "requestsIndexField",
36
- "type": {
37
- "type-name": "Uint",
38
- "maxval": 255
39
- }
40
- }
41
- ],
42
- "result-type": {
43
- "type-name": "Struct",
44
- "name": "SignBidirectionalNotification",
45
- "elements": [
46
- {
47
- "name": "version",
48
- "type": {
49
- "type-name": "Uint",
50
- "maxval": 255
51
- }
52
- },
53
- {
54
- "name": "payload",
55
- "type": {
56
- "type-name": "Bytes",
57
- "length": 65
58
- }
59
- }
60
- ]
61
- }
62
- },
63
- {
64
- "name": "evmAddressAbiValue",
65
- "pure": true,
66
- "proof": false,
67
- "arguments": [
68
- {
69
- "name": "addr",
70
- "type": {
71
- "type-name": "Bytes",
72
- "length": 20
73
- }
74
- }
75
- ],
76
- "result-type": {
77
- "type-name": "Field"
78
- }
79
- },
80
- {
81
- "name": "signetAttestationMessage",
82
- "pure": true,
83
- "proof": false,
84
- "arguments": [
85
- {
86
- "name": "requestId",
87
- "type": {
88
- "type-name": "Alias",
89
- "name": "RequestId",
90
- "type": {
91
- "type-name": "Bytes",
92
- "length": 32
93
- }
94
- }
95
- },
96
- {
97
- "name": "serializedOutput",
98
- "type": {
99
- "type-name": "Bytes",
100
- "length": 128
101
- }
102
- },
103
- {
104
- "name": "outputLen",
105
- "type": {
106
- "type-name": "Uint",
107
- "maxval": 255
108
- }
109
- }
110
- ],
111
- "result-type": {
112
- "type-name": "Vector",
113
- "length": 4,
114
- "type": {
115
- "type-name": "Field"
116
- }
117
- }
118
- },
119
- {
120
- "name": "assertHexOf",
121
- "pure": true,
122
- "proof": false,
123
- "arguments": [
124
- {
125
- "name": "commitment",
126
- "type": {
127
- "type-name": "Bytes",
128
- "length": 32
129
- }
130
- },
131
- {
132
- "name": "hexStr",
133
- "type": {
134
- "type-name": "Bytes",
135
- "length": 64
136
- }
137
- }
138
- ],
139
- "result-type": {
140
- "type-name": "Tuple",
141
- "types": [
142
- ]
143
- }
144
- },
145
- {
146
- "name": "assertPathCommitment",
147
- "pure": true,
148
- "proof": false,
149
- "arguments": [
150
- {
151
- "name": "commitment",
152
- "type": {
153
- "type-name": "Bytes",
154
- "length": 32
155
- }
156
- },
157
- {
158
- "name": "path",
159
- "type": {
160
- "type-name": "Bytes",
161
- "length": 256
162
- }
163
- }
164
- ],
165
- "result-type": {
166
- "type-name": "Tuple",
167
- "types": [
168
- ]
169
- }
170
- },
171
- {
172
- "name": "schnorrChallenge",
173
- "pure": true,
174
- "proof": false,
175
- "arguments": [
176
- {
177
- "name": "ann_x",
178
- "type": {
179
- "type-name": "Field"
180
- }
181
- },
182
- {
183
- "name": "ann_y",
184
- "type": {
185
- "type-name": "Field"
186
- }
187
- },
188
- {
189
- "name": "pk_x",
190
- "type": {
191
- "type-name": "Field"
192
- }
193
- },
194
- {
195
- "name": "pk_y",
196
- "type": {
197
- "type-name": "Field"
198
- }
199
- },
200
- {
201
- "name": "msg",
202
- "type": {
203
- "type-name": "Vector",
204
- "length": 4,
205
- "type": {
206
- "type-name": "Field"
207
- }
208
- }
209
- }
210
- ],
211
- "result-type": {
212
- "type-name": "Field"
213
- }
214
- }
215
- ],
216
- "witnesses": [
217
- ],
218
- "contracts": [
219
- ],
220
- "ledger": [
221
- ]
222
- }
@@ -1,32 +0,0 @@
1
- {
2
- "manifest-version": "1",
3
- "compiler-version": "0.33.0",
4
- "language-version": "0.25.0",
5
- "runtime-version": "0.18.0-rc.0",
6
- "compiler": {
7
- "type": "directory",
8
- "contract-info.json": {
9
- "type": "file",
10
- "size": 4406,
11
- "hash": "d0757fe6d320a0d3162ab00faf3ebb74d28fa678f588b83957212086eb4b3080"
12
- }
13
- },
14
- "contract": {
15
- "type": "directory",
16
- "index.d.ts": {
17
- "type": "file",
18
- "size": 3842,
19
- "hash": "4edb5966c4b41a810691af9a12abcd359a517d95dcf6bb91faedef4da2d23019"
20
- },
21
- "index.js": {
22
- "type": "file",
23
- "size": 42888,
24
- "hash": "de719f4711b4def77673f55b0b54c2b96a9039fdd001358d1be9a400a19aeb61"
25
- },
26
- "index.js.map": {
27
- "type": "file",
28
- "size": 3115,
29
- "hash": "42d40aaf65da98f7b9df2e329b13fca3c0526418eb9697f64b6a562b12ed8b82"
30
- }
31
- }
32
- }
@@ -1,78 +0,0 @@
1
- import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime';
2
-
3
- export type Witnesses<PS> = {
4
- }
5
-
6
- export type ImpureCircuits<PS> = {
7
- }
8
-
9
- export type ProvableCircuits<PS> = {
10
- }
11
-
12
- export type PureCircuits = {
13
- constructSignBidirectionalNotificationV1(callerAddress_0: { bytes: Uint8Array
14
- },
15
- requestId_0: Uint8Array,
16
- requestsIndexField_0: bigint): { version: bigint,
17
- payload: Uint8Array
18
- };
19
- evmAddressAbiValue(addr_0: Uint8Array): bigint;
20
- signetAttestationMessage(requestId_0: Uint8Array,
21
- serializedOutput_0: Uint8Array,
22
- outputLen_0: bigint): bigint[];
23
- assertHexOf(commitment_0: Uint8Array, hexStr_0: Uint8Array): [];
24
- assertPathCommitment(commitment_0: Uint8Array, path_0: Uint8Array): [];
25
- schnorrChallenge(ann_x_0: bigint,
26
- ann_y_0: bigint,
27
- pk_x_0: bigint,
28
- pk_y_0: bigint,
29
- msg_0: bigint[]): bigint;
30
- }
31
-
32
- export type Circuits<PS> = {
33
- constructSignBidirectionalNotificationV1(context: __compactRuntime.CircuitContext<PS>,
34
- callerAddress_0: { bytes: Uint8Array
35
- },
36
- requestId_0: Uint8Array,
37
- requestsIndexField_0: bigint): Promise<__compactRuntime.CircuitResults<PS, { version: bigint,
38
- payload: Uint8Array
39
- }>>;
40
- evmAddressAbiValue(context: __compactRuntime.CircuitContext<PS>,
41
- addr_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, bigint>>;
42
- signetAttestationMessage(context: __compactRuntime.CircuitContext<PS>,
43
- requestId_0: Uint8Array,
44
- serializedOutput_0: Uint8Array,
45
- outputLen_0: bigint): Promise<__compactRuntime.CircuitResults<PS, bigint[]>>;
46
- assertHexOf(context: __compactRuntime.CircuitContext<PS>,
47
- commitment_0: Uint8Array,
48
- hexStr_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, []>>;
49
- assertPathCommitment(context: __compactRuntime.CircuitContext<PS>,
50
- commitment_0: Uint8Array,
51
- path_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, []>>;
52
- schnorrChallenge(context: __compactRuntime.CircuitContext<PS>,
53
- ann_x_0: bigint,
54
- ann_y_0: bigint,
55
- pk_x_0: bigint,
56
- pk_y_0: bigint,
57
- msg_0: bigint[]): Promise<__compactRuntime.CircuitResults<PS, bigint>>;
58
- }
59
-
60
- export type Ledger = {
61
- }
62
-
63
- export type ContractReferenceLocations = any;
64
-
65
- export declare const contractReferenceLocations : ContractReferenceLocations;
66
-
67
- export declare class Contract<PS = any, W extends Witnesses<PS> = Witnesses<PS>> {
68
- witnesses: W;
69
- circuits: Circuits<PS>;
70
- impureCircuits: ImpureCircuits<PS>;
71
- provableCircuits: ProvableCircuits<PS>;
72
- constructor(witnesses: W);
73
- initialState(context: __compactRuntime.ConstructorContext<PS>): Promise<__compactRuntime.ConstructorResult<PS>>;
74
- }
75
-
76
- export declare function ledger(state: __compactRuntime.StateValue | __compactRuntime.ChargedState): Ledger;
77
- export declare const pureCircuits: PureCircuits;
78
- export declare const expectedVk: Record<string, string>;