@sig-net/midnight 0.0.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 (90) hide show
  1. package/README.md +20 -0
  2. package/dist/constants.d.ts +62 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +83 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/epsilon-derivation.d.ts +32 -0
  7. package/dist/epsilon-derivation.d.ts.map +1 -0
  8. package/dist/epsilon-derivation.js +54 -0
  9. package/dist/epsilon-derivation.js.map +1 -0
  10. package/dist/index.d.ts +26 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +30 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/managed/compiler/contract-info.json +165 -0
  15. package/dist/managed/compiler/contract-manifest.json +32 -0
  16. package/dist/managed/contract/index.d.ts +65 -0
  17. package/dist/managed/contract/index.js +611 -0
  18. package/dist/managed/contract/index.js.map +8 -0
  19. package/dist/schnorr.d.ts +100 -0
  20. package/dist/schnorr.d.ts.map +1 -0
  21. package/dist/schnorr.js +144 -0
  22. package/dist/schnorr.js.map +1 -0
  23. package/dist/signature-requests-state-reader.d.ts +74 -0
  24. package/dist/signature-requests-state-reader.d.ts.map +1 -0
  25. package/dist/signature-requests-state-reader.js +167 -0
  26. package/dist/signature-requests-state-reader.js.map +1 -0
  27. package/dist/signature-response-verification.d.ts +27 -0
  28. package/dist/signature-response-verification.d.ts.map +1 -0
  29. package/dist/signature-response-verification.js +45 -0
  30. package/dist/signature-response-verification.js.map +1 -0
  31. package/dist/signature-state-reading.d.ts +36 -0
  32. package/dist/signature-state-reading.d.ts.map +1 -0
  33. package/dist/signature-state-reading.js +62 -0
  34. package/dist/signature-state-reading.js.map +1 -0
  35. package/dist/signet-contract-state-reader.d.ts +146 -0
  36. package/dist/signet-contract-state-reader.d.ts.map +1 -0
  37. package/dist/signet-contract-state-reader.js +226 -0
  38. package/dist/signet-contract-state-reader.js.map +1 -0
  39. package/dist/signet-event-observer.d.ts +102 -0
  40. package/dist/signet-event-observer.d.ts.map +1 -0
  41. package/dist/signet-event-observer.js +127 -0
  42. package/dist/signet-event-observer.js.map +1 -0
  43. package/dist/signet-events.d.ts +175 -0
  44. package/dist/signet-events.d.ts.map +1 -0
  45. package/dist/signet-events.js +210 -0
  46. package/dist/signet-events.js.map +1 -0
  47. package/dist/signet-request-feed.d.ts +78 -0
  48. package/dist/signet-request-feed.d.ts.map +1 -0
  49. package/dist/signet-request-feed.js +116 -0
  50. package/dist/signet-request-feed.js.map +1 -0
  51. package/dist/signet-request-resolver.d.ts +58 -0
  52. package/dist/signet-request-resolver.d.ts.map +1 -0
  53. package/dist/signet-request-resolver.js +76 -0
  54. package/dist/signet-request-resolver.js.map +1 -0
  55. package/dist/signet-request-response-reader.d.ts +160 -0
  56. package/dist/signet-request-response-reader.d.ts.map +1 -0
  57. package/dist/signet-request-response-reader.js +198 -0
  58. package/dist/signet-request-response-reader.js.map +1 -0
  59. package/dist/signet-requests.d.ts +363 -0
  60. package/dist/signet-requests.d.ts.map +1 -0
  61. package/dist/signet-requests.js +497 -0
  62. package/dist/signet-requests.js.map +1 -0
  63. package/dist/signet-response-feed.d.ts +161 -0
  64. package/dist/signet-response-feed.d.ts.map +1 -0
  65. package/dist/signet-response-feed.js +234 -0
  66. package/dist/signet-response-feed.js.map +1 -0
  67. package/package.json +47 -0
  68. package/src/Schnorr.compact +63 -0
  69. package/src/Signet.compact +529 -0
  70. package/src/circuits.compact +36 -0
  71. package/src/constants.ts +97 -0
  72. package/src/epsilon-derivation.ts +62 -0
  73. package/src/index.ts +31 -0
  74. package/src/managed/compiler/contract-info.json +165 -0
  75. package/src/managed/compiler/contract-manifest.json +32 -0
  76. package/src/managed/contract/index.d.ts +65 -0
  77. package/src/managed/contract/index.js +611 -0
  78. package/src/managed/contract/index.js.map +8 -0
  79. package/src/schnorr.ts +210 -0
  80. package/src/signature-requests-state-reader.ts +223 -0
  81. package/src/signature-response-verification.ts +64 -0
  82. package/src/signature-state-reading.ts +87 -0
  83. package/src/signet-contract-state-reader.ts +391 -0
  84. package/src/signet-event-observer.ts +186 -0
  85. package/src/signet-events.ts +337 -0
  86. package/src/signet-request-feed.ts +158 -0
  87. package/src/signet-request-resolver.ts +116 -0
  88. package/src/signet-request-response-reader.ts +324 -0
  89. package/src/signet-requests.ts +737 -0
  90. package/src/signet-response-feed.ts +325 -0
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @sig-net/midnight
2
+
3
+ THE point of the repo: the Midnight-side sig-net integration. Midnight is not
4
+ yet a signet.js chain — this package is the seed of that future adapter.
5
+
6
+ Where signet.js already covers something (e.g. EVM tx preparation, address
7
+ derivation), import it rather than re-implement. Only what is Midnight-specific
8
+ belongs here.
9
+
10
+ Planned modules (ported from the old repo's `boilerplate/contract-cli/src/signet/`):
11
+
12
+ - `request-id.ts` — signet request-id computation
13
+ - `calldata-builder.ts` — EVM calldata construction
14
+ - `tx-builder.ts` — EIP-1559 transaction building
15
+ - `codec.ts` — byte/hex codecs
16
+ - `constants.ts`
17
+ - `schnorr.ts` — Jubjub response verification (Midnight-specific, not in signet.js)
18
+ - `state-reader.ts` — read pending requests/responses from the Midnight indexer
19
+ - `signet-request-response-reader.ts` — read/poll the signet contract for results
20
+ (replaces the old websocket subscription — purged, no fallback)
@@ -0,0 +1,62 @@
1
+ /** Width of `SignBidirectionalRequest.caip2Id` (`Bytes<32>`). */
2
+ export declare const CAIP2_ID_BYTES = 32;
3
+ /** Width of `SignBidirectionalRequest.algo` (`Bytes<32>`). */
4
+ export declare const ALGO_BYTES = 32;
5
+ /** Width of `SignBidirectionalRequest.dest` (`Bytes<32>`). */
6
+ export declare const DEST_BYTES = 32;
7
+ /** Width of `SignBidirectionalRequest.params` (`Bytes<64>`). */
8
+ export declare const MPC_PARAMS_BYTES = 64;
9
+ /** Width of `SignBidirectionalRequest.outputDeserializationSchema` (`Bytes<128>`). */
10
+ export declare const OUTPUT_DESERIALIZATION_SCHEMA_BYTES = 128;
11
+ /** Width of `SignBidirectionalRequest.respondSerializationSchema` (`Bytes<128>`). */
12
+ export declare const RESPOND_SERIALIZATION_SCHEMA_BYTES = 128;
13
+ /** Width of `EVMCalldata.selector` (`Bytes<4>`) — the literal first 4 calldata bytes. */
14
+ export declare const SELECTOR_BYTES = 4;
15
+ /** Width of `RespondBidirectional.serializedOutput` (`Bytes<128>`). */
16
+ export declare const SERIALIZED_OUTPUT_BYTES = 128;
17
+ /**
18
+ * The MPC's error sentinel: `serializedOutput` beginning with these four
19
+ * bytes marks a failed/absent remote execution (mirrors the sig-net MPC's
20
+ * MAGIC_ERROR_PREFIX).
21
+ */
22
+ export declare const MPC_ERROR_SENTINEL: Uint8Array<ArrayBuffer>;
23
+ /**
24
+ * Whether an attestation's serialized output reports a successful remote
25
+ * execution: the first byte is 1 — the little-endian encoding of the
26
+ * ABI-decoded success flag, matching the circuits'
27
+ * `serializedOutput as Field == 1` check.
28
+ *
29
+ * @param serializedOutput - The attestation's serialized output.
30
+ * @returns `true` when the remote call succeeded.
31
+ */
32
+ export declare function executionSucceeded(serializedOutput: Uint8Array): boolean;
33
+ /**
34
+ * Whether an attestation's serialized output is the MPC's error sentinel
35
+ * (see {@link MPC_ERROR_SENTINEL}) rather than a call result.
36
+ *
37
+ * @param serializedOutput - The attestation's serialized output.
38
+ * @returns `true` when the MPC reported an execution error.
39
+ */
40
+ export declare function isExecutionError(serializedOutput: Uint8Array): boolean;
41
+ /** Signature algorithm the MPC uses for EVM chains (`algo` field value). */
42
+ export declare const SIGNET_ALGO_ECDSA = "ecdsa";
43
+ /** Destination chain family for EVM requests (`dest` field value). */
44
+ export declare const SIGNET_DEST_ETHEREUM = "ethereum";
45
+ /**
46
+ * Default MPC key version (`keyVersion` field value). Version 0 is the
47
+ * unsupported legacy format — the canonical MPC (and
48
+ * `constructSignBidirectionalRequest`) requires `keyVersion >= 1`.
49
+ */
50
+ export declare const SIGNET_DEFAULT_KEY_VERSION = 1n;
51
+ /**
52
+ * Encode text as zero-padded ASCII bytes — the Compact `pad(N, "text")`
53
+ * convention every string-ish field of the request structs uses (consumers
54
+ * NUL-trim on decode).
55
+ *
56
+ * @param text - The ASCII text to encode.
57
+ * @param length - The fixed field width in bytes.
58
+ * @returns `text`'s bytes followed by zero padding to exactly `length`.
59
+ * @throws If the encoded text does not fit in `length` bytes.
60
+ */
61
+ export declare function asciiPadded(text: string, length: number): Uint8Array;
62
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAUA,iEAAiE;AACjE,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,8DAA8D;AAC9D,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,8DAA8D;AAC9D,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,sFAAsF;AACtF,eAAO,MAAM,mCAAmC,MAAM,CAAC;AAEvD,qFAAqF;AACrF,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAEtD,yFAAyF;AACzF,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,uEAAuE;AACvE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,yBAA2C,CAAC;AAE3E;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAExE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,UAAU,GAAG,OAAO,CAEtE;AAED,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAQpE"}
@@ -0,0 +1,83 @@
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
+ /** Width of `SignBidirectionalRequest.caip2Id` (`Bytes<32>`). */
11
+ export const CAIP2_ID_BYTES = 32;
12
+ /** Width of `SignBidirectionalRequest.algo` (`Bytes<32>`). */
13
+ export const ALGO_BYTES = 32;
14
+ /** Width of `SignBidirectionalRequest.dest` (`Bytes<32>`). */
15
+ export const DEST_BYTES = 32;
16
+ /** Width of `SignBidirectionalRequest.params` (`Bytes<64>`). */
17
+ export const MPC_PARAMS_BYTES = 64;
18
+ /** Width of `SignBidirectionalRequest.outputDeserializationSchema` (`Bytes<128>`). */
19
+ export const OUTPUT_DESERIALIZATION_SCHEMA_BYTES = 128;
20
+ /** Width of `SignBidirectionalRequest.respondSerializationSchema` (`Bytes<128>`). */
21
+ export const RESPOND_SERIALIZATION_SCHEMA_BYTES = 128;
22
+ /** Width of `EVMCalldata.selector` (`Bytes<4>`) — the literal first 4 calldata bytes. */
23
+ export const SELECTOR_BYTES = 4;
24
+ /** Width of `RespondBidirectional.serializedOutput` (`Bytes<128>`). */
25
+ export const SERIALIZED_OUTPUT_BYTES = 128;
26
+ /**
27
+ * The MPC's error sentinel: `serializedOutput` beginning with these four
28
+ * bytes marks a failed/absent remote execution (mirrors the sig-net MPC's
29
+ * MAGIC_ERROR_PREFIX).
30
+ */
31
+ export const MPC_ERROR_SENTINEL = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
32
+ /**
33
+ * Whether an attestation's serialized output reports a successful remote
34
+ * execution: the first byte is 1 — the little-endian encoding of the
35
+ * ABI-decoded success flag, matching the circuits'
36
+ * `serializedOutput as Field == 1` check.
37
+ *
38
+ * @param serializedOutput - The attestation's serialized output.
39
+ * @returns `true` when the remote call succeeded.
40
+ */
41
+ export function executionSucceeded(serializedOutput) {
42
+ return serializedOutput[0] === 1;
43
+ }
44
+ /**
45
+ * Whether an attestation's serialized output is the MPC's error sentinel
46
+ * (see {@link MPC_ERROR_SENTINEL}) rather than a call result.
47
+ *
48
+ * @param serializedOutput - The attestation's serialized output.
49
+ * @returns `true` when the MPC reported an execution error.
50
+ */
51
+ export function isExecutionError(serializedOutput) {
52
+ return MPC_ERROR_SENTINEL.every((byte, index) => serializedOutput[index] === byte);
53
+ }
54
+ /** Signature algorithm the MPC uses for EVM chains (`algo` field value). */
55
+ export const SIGNET_ALGO_ECDSA = "ecdsa";
56
+ /** Destination chain family for EVM requests (`dest` field value). */
57
+ export const SIGNET_DEST_ETHEREUM = "ethereum";
58
+ /**
59
+ * Default MPC key version (`keyVersion` field value). Version 0 is the
60
+ * unsupported legacy format — the canonical MPC (and
61
+ * `constructSignBidirectionalRequest`) requires `keyVersion >= 1`.
62
+ */
63
+ export const SIGNET_DEFAULT_KEY_VERSION = 1n;
64
+ /**
65
+ * Encode text as zero-padded ASCII bytes — the Compact `pad(N, "text")`
66
+ * convention every string-ish field of the request structs uses (consumers
67
+ * NUL-trim on decode).
68
+ *
69
+ * @param text - The ASCII text to encode.
70
+ * @param length - The fixed field width in bytes.
71
+ * @returns `text`'s bytes followed by zero padding to exactly `length`.
72
+ * @throws If the encoded text does not fit in `length` bytes.
73
+ */
74
+ export function asciiPadded(text, length) {
75
+ const encoded = new TextEncoder().encode(text);
76
+ if (encoded.length > length) {
77
+ throw new Error(`"${text}" is ${encoded.length} bytes — does not fit the ${length}-byte field`);
78
+ }
79
+ const out = new Uint8Array(length);
80
+ out.set(encoded);
81
+ return out;
82
+ }
83
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,iEAAiE;AACjE,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,kEAAkE;AAClE,EAAE;AACF,2EAA2E;AAC3E,oBAAoB;AAEpB,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B,gEAAgE;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,sFAAsF;AACtF,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,CAAC;AAEvD,qFAAqF;AACrF,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAEtD,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,uEAAuE;AACvE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C;;;;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,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,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE/C;;;;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,6BAA6B,MAAM,aAAa,CAAC,CAAC;IAClG,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"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Domain prefix of the sig-net v1.0.0 epsilon derivation scheme, as used by
3
+ * the live response server. The full derivation string is
4
+ * `<prefix>,<chainId>,<requester>,<path>` (comma-separated).
5
+ */
6
+ export declare const EPSILON_DERIVATION_PREFIX = "sig.network v1.0.0 epsilon derivation";
7
+ /**
8
+ * CAIP-2 chain id under which the MPC derives keys for requests originating
9
+ * from Midnight contracts.
10
+ */
11
+ export declare const MIDNIGHT_TESTNET_CHAIN_ID = "midnight:testnet";
12
+ /**
13
+ * Derive the EVM address the MPC network signs from for a given Midnight
14
+ * contract and derivation path, using the sig-net v1.0.0 epsilon scheme:
15
+ * `epsilon = keccak256("<prefix>,<chainId>,<contractAddress>,<path>")` and
16
+ * `derivedPubKey = mpcRootPubKey + epsilon * G` on secp256k1.
17
+ *
18
+ * The MPC treats `path` as an opaque string: the vault's own account uses the
19
+ * literal path `"vault"`, a user's account uses the lowercase hex of their
20
+ * identity commitment.
21
+ *
22
+ * @param mpcSecp256k1PubkeyHex - The MPC root secp256k1 public key as 0x-hex
23
+ * (compressed or uncompressed; normalized internally).
24
+ * @param contractAddress - The Midnight contract address the request
25
+ * originates from (the "requester" in the derivation string).
26
+ * @param path - The derivation path string (e.g. `"vault"` or a commitment
27
+ * hex).
28
+ * @param chainId - CAIP-2 chain id component of the derivation string.
29
+ * @returns The derived EVM address as a 0x-prefixed EIP-55 checksummed string.
30
+ */
31
+ export declare function deriveEvmAddress(mpcSecp256k1PubkeyHex: string, contractAddress: string, path: string, chainId?: string): string;
32
+ //# sourceMappingURL=epsilon-derivation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"epsilon-derivation.d.ts","sourceRoot":"","sources":["../src/epsilon-derivation.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,0CAA0C,CAAC;AAEjF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,qBAAqB,EAAE,MAAM,EAC7B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAkC,GAC1C,MAAM,CASR"}
@@ -0,0 +1,54 @@
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
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
13
+ import { computeAddress, keccak256, SigningKey, toUtf8Bytes } from "ethers";
14
+ /**
15
+ * Domain prefix of the sig-net v1.0.0 epsilon derivation scheme, as used by
16
+ * the live response server. The full derivation string is
17
+ * `<prefix>,<chainId>,<requester>,<path>` (comma-separated).
18
+ */
19
+ export const EPSILON_DERIVATION_PREFIX = "sig.network v1.0.0 epsilon derivation";
20
+ /**
21
+ * CAIP-2 chain id under which the MPC derives keys for requests originating
22
+ * from Midnight contracts.
23
+ */
24
+ export const MIDNIGHT_TESTNET_CHAIN_ID = "midnight:testnet";
25
+ /**
26
+ * Derive the EVM address the MPC network signs from for a given Midnight
27
+ * contract and derivation path, using the sig-net v1.0.0 epsilon scheme:
28
+ * `epsilon = keccak256("<prefix>,<chainId>,<contractAddress>,<path>")` and
29
+ * `derivedPubKey = mpcRootPubKey + epsilon * G` on secp256k1.
30
+ *
31
+ * The MPC treats `path` as an opaque string: the vault's own account uses the
32
+ * literal path `"vault"`, a user's account uses the lowercase hex of their
33
+ * identity commitment.
34
+ *
35
+ * @param mpcSecp256k1PubkeyHex - The MPC root secp256k1 public key as 0x-hex
36
+ * (compressed or uncompressed; normalized internally).
37
+ * @param contractAddress - The Midnight contract address the request
38
+ * originates from (the "requester" in the derivation string).
39
+ * @param path - The derivation path string (e.g. `"vault"` or a commitment
40
+ * hex).
41
+ * @param chainId - CAIP-2 chain id component of the derivation string.
42
+ * @returns The derived EVM address as a 0x-prefixed EIP-55 checksummed string.
43
+ */
44
+ export function deriveEvmAddress(mpcSecp256k1PubkeyHex, contractAddress, path, chainId = MIDNIGHT_TESTNET_CHAIN_ID) {
45
+ const fullPath = `${EPSILON_DERIVATION_PREFIX},${chainId},${contractAddress},${path}`;
46
+ // Reduce mod n before multiplying: noble throws on scalars >= n, whereas the
47
+ // server's scalar arithmetic reduces implicitly.
48
+ const epsilon = BigInt(keccak256(toUtf8Bytes(fullPath))) % secp256k1.Point.Fn.ORDER;
49
+ const rootPubKeyHex = SigningKey.computePublicKey(mpcSecp256k1PubkeyHex, false);
50
+ const rootPoint = secp256k1.Point.fromHex(rootPubKeyHex.slice(2));
51
+ const derivedPoint = epsilon === 0n ? rootPoint : rootPoint.add(secp256k1.Point.BASE.multiply(epsilon));
52
+ return computeAddress(`0x${derivedPoint.toHex(false)}`);
53
+ }
54
+ //# sourceMappingURL=epsilon-derivation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"epsilon-derivation.js","sourceRoot":"","sources":["../src/epsilon-derivation.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,uDAAuD;AACvD,0EAA0E;AAC1E,uEAAuE;AACvE,oDAAoD;AACpD,4EAA4E;AAC5E,yEAAyE;AACzE,sBAAsB;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,uCAAuC,CAAC;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,qBAA6B,EAC7B,eAAuB,EACvB,IAAY,EACZ,UAAkB,yBAAyB;IAE3C,MAAM,QAAQ,GAAG,GAAG,yBAAyB,IAAI,OAAO,IAAI,eAAe,IAAI,IAAI,EAAE,CAAC;IACtF,6EAA6E;IAC7E,iDAAiD;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC;IACpF,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAChF,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACxG,OAAO,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,26 @@
1
+ export * from "./signet-requests.ts";
2
+ export * from "./signature-state-reading.ts";
3
+ export * from "./signature-requests-state-reader.ts";
4
+ export * from "./signet-contract-state-reader.ts";
5
+ export * from "./signature-response-verification.ts";
6
+ export * from "./signet-request-response-reader.ts";
7
+ export * from "./signet-events.ts";
8
+ export * from "./signet-event-observer.ts";
9
+ export * from "./signet-request-resolver.ts";
10
+ export * from "./signet-request-feed.ts";
11
+ export * from "./signet-response-feed.ts";
12
+ export * from "./constants.ts";
13
+ export * from "./epsilon-derivation.ts";
14
+ export * from "./schnorr.ts";
15
+ /**
16
+ * Compiled pure circuits of Signet.compact (run `yarn compile` first): the
17
+ * executable reference implementation of the client-agnostic circuits —
18
+ * path<->identity checks, the attestation message, and the Schnorr challenge.
19
+ * Off-chain code MUST use these instead of re-porting the algorithms — they
20
+ * are the same compiled logic the contracts prove. The generic request
21
+ * circuits cannot be compiled here (type-parameterized): request construction
22
+ * is contract-only, and request-id hashing has a documented-deviation TS twin
23
+ * (`calculateRequestId` in signet-requests.ts).
24
+ */
25
+ export { pureCircuits, type PureCircuits } from "./managed/contract/index.js";
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAE7B;;;;;;;;;GASG;AACH,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
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
+ export * from "./signet-requests.js";
6
+ export * from "./signature-state-reading.js";
7
+ export * from "./signature-requests-state-reader.js";
8
+ export * from "./signet-contract-state-reader.js";
9
+ export * from "./signature-response-verification.js";
10
+ export * from "./signet-request-response-reader.js";
11
+ export * from "./signet-events.js";
12
+ export * from "./signet-event-observer.js";
13
+ export * from "./signet-request-resolver.js";
14
+ export * from "./signet-request-feed.js";
15
+ export * from "./signet-response-feed.js";
16
+ export * from "./constants.js";
17
+ export * from "./epsilon-derivation.js";
18
+ export * from "./schnorr.js";
19
+ /**
20
+ * Compiled pure circuits of Signet.compact (run `yarn compile` first): the
21
+ * executable reference implementation of the client-agnostic circuits —
22
+ * path<->identity checks, the attestation message, 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 } from "./managed/contract/index.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,wCAAwC;AAExC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAE7B;;;;;;;;;GASG;AACH,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,165 @@
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": "evmAddressAbiValue",
8
+ "pure": true,
9
+ "proof": false,
10
+ "arguments": [
11
+ {
12
+ "name": "addr",
13
+ "type": {
14
+ "type-name": "Bytes",
15
+ "length": 20
16
+ }
17
+ }
18
+ ],
19
+ "result-type": {
20
+ "type-name": "Field"
21
+ }
22
+ },
23
+ {
24
+ "name": "signetAttestationMessage",
25
+ "pure": true,
26
+ "proof": false,
27
+ "arguments": [
28
+ {
29
+ "name": "requestId",
30
+ "type": {
31
+ "type-name": "Alias",
32
+ "name": "RequestId",
33
+ "type": {
34
+ "type-name": "Bytes",
35
+ "length": 32
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "name": "serializedOutput",
41
+ "type": {
42
+ "type-name": "Bytes",
43
+ "length": 128
44
+ }
45
+ },
46
+ {
47
+ "name": "outputLen",
48
+ "type": {
49
+ "type-name": "Uint",
50
+ "maxval": 255
51
+ }
52
+ }
53
+ ],
54
+ "result-type": {
55
+ "type-name": "Vector",
56
+ "length": 4,
57
+ "type": {
58
+ "type-name": "Field"
59
+ }
60
+ }
61
+ },
62
+ {
63
+ "name": "assertHexOf",
64
+ "pure": true,
65
+ "proof": false,
66
+ "arguments": [
67
+ {
68
+ "name": "commitment",
69
+ "type": {
70
+ "type-name": "Bytes",
71
+ "length": 32
72
+ }
73
+ },
74
+ {
75
+ "name": "hexStr",
76
+ "type": {
77
+ "type-name": "Bytes",
78
+ "length": 64
79
+ }
80
+ }
81
+ ],
82
+ "result-type": {
83
+ "type-name": "Tuple",
84
+ "types": [
85
+ ]
86
+ }
87
+ },
88
+ {
89
+ "name": "assertPathCommitment",
90
+ "pure": true,
91
+ "proof": false,
92
+ "arguments": [
93
+ {
94
+ "name": "commitment",
95
+ "type": {
96
+ "type-name": "Bytes",
97
+ "length": 32
98
+ }
99
+ },
100
+ {
101
+ "name": "path",
102
+ "type": {
103
+ "type-name": "Bytes",
104
+ "length": 256
105
+ }
106
+ }
107
+ ],
108
+ "result-type": {
109
+ "type-name": "Tuple",
110
+ "types": [
111
+ ]
112
+ }
113
+ },
114
+ {
115
+ "name": "schnorrChallenge",
116
+ "pure": true,
117
+ "proof": false,
118
+ "arguments": [
119
+ {
120
+ "name": "ann_x",
121
+ "type": {
122
+ "type-name": "Field"
123
+ }
124
+ },
125
+ {
126
+ "name": "ann_y",
127
+ "type": {
128
+ "type-name": "Field"
129
+ }
130
+ },
131
+ {
132
+ "name": "pk_x",
133
+ "type": {
134
+ "type-name": "Field"
135
+ }
136
+ },
137
+ {
138
+ "name": "pk_y",
139
+ "type": {
140
+ "type-name": "Field"
141
+ }
142
+ },
143
+ {
144
+ "name": "msg",
145
+ "type": {
146
+ "type-name": "Vector",
147
+ "length": 4,
148
+ "type": {
149
+ "type-name": "Field"
150
+ }
151
+ }
152
+ }
153
+ ],
154
+ "result-type": {
155
+ "type-name": "Field"
156
+ }
157
+ }
158
+ ],
159
+ "witnesses": [
160
+ ],
161
+ "contracts": [
162
+ ],
163
+ "ledger": [
164
+ ]
165
+ }
@@ -0,0 +1,32 @@
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": 3135,
11
+ "hash": "9d2395e0039bbce65bda3e89eaa3832b8cc9e9b00ed39a40ed0f69bf599d96be"
12
+ }
13
+ },
14
+ "contract": {
15
+ "type": "directory",
16
+ "index.d.ts": {
17
+ "type": "file",
18
+ "size": 2665,
19
+ "hash": "88892cc8a7682b384a9cbce21339f382916a978777853f81350e55f9510e223c"
20
+ },
21
+ "index.js": {
22
+ "type": "file",
23
+ "size": 39675,
24
+ "hash": "6de3c60def5fa9eff08b822b79070f3005ec94972d09b90fbdef95d6443e61b3"
25
+ },
26
+ "index.js.map": {
27
+ "type": "file",
28
+ "size": 2850,
29
+ "hash": "ce08afea972941a9da6f6291389381be8ae956f5477b5281d3cbc0ba749fe196"
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,65 @@
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
+ evmAddressAbiValue(addr_0: Uint8Array): bigint;
14
+ signetAttestationMessage(requestId_0: Uint8Array,
15
+ serializedOutput_0: Uint8Array,
16
+ outputLen_0: bigint): bigint[];
17
+ assertHexOf(commitment_0: Uint8Array, hexStr_0: Uint8Array): [];
18
+ assertPathCommitment(commitment_0: Uint8Array, path_0: Uint8Array): [];
19
+ schnorrChallenge(ann_x_0: bigint,
20
+ ann_y_0: bigint,
21
+ pk_x_0: bigint,
22
+ pk_y_0: bigint,
23
+ msg_0: bigint[]): bigint;
24
+ }
25
+
26
+ export type Circuits<PS> = {
27
+ evmAddressAbiValue(context: __compactRuntime.CircuitContext<PS>,
28
+ addr_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, bigint>>;
29
+ signetAttestationMessage(context: __compactRuntime.CircuitContext<PS>,
30
+ requestId_0: Uint8Array,
31
+ serializedOutput_0: Uint8Array,
32
+ outputLen_0: bigint): Promise<__compactRuntime.CircuitResults<PS, bigint[]>>;
33
+ assertHexOf(context: __compactRuntime.CircuitContext<PS>,
34
+ commitment_0: Uint8Array,
35
+ hexStr_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, []>>;
36
+ assertPathCommitment(context: __compactRuntime.CircuitContext<PS>,
37
+ commitment_0: Uint8Array,
38
+ path_0: Uint8Array): Promise<__compactRuntime.CircuitResults<PS, []>>;
39
+ schnorrChallenge(context: __compactRuntime.CircuitContext<PS>,
40
+ ann_x_0: bigint,
41
+ ann_y_0: bigint,
42
+ pk_x_0: bigint,
43
+ pk_y_0: bigint,
44
+ msg_0: bigint[]): Promise<__compactRuntime.CircuitResults<PS, bigint>>;
45
+ }
46
+
47
+ export type Ledger = {
48
+ }
49
+
50
+ export type ContractReferenceLocations = any;
51
+
52
+ export declare const contractReferenceLocations : ContractReferenceLocations;
53
+
54
+ export declare class Contract<PS = any, W extends Witnesses<PS> = Witnesses<PS>> {
55
+ witnesses: W;
56
+ circuits: Circuits<PS>;
57
+ impureCircuits: ImpureCircuits<PS>;
58
+ provableCircuits: ProvableCircuits<PS>;
59
+ constructor(witnesses: W);
60
+ initialState(context: __compactRuntime.ConstructorContext<PS>): Promise<__compactRuntime.ConstructorResult<PS>>;
61
+ }
62
+
63
+ export declare function ledger(state: __compactRuntime.StateValue | __compactRuntime.ChargedState): Ledger;
64
+ export declare const pureCircuits: PureCircuits;
65
+ export declare const expectedVk: Record<string, string>;