@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.
- package/README.md +20 -0
- package/dist/constants.d.ts +62 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +83 -0
- package/dist/constants.js.map +1 -0
- package/dist/epsilon-derivation.d.ts +32 -0
- package/dist/epsilon-derivation.d.ts.map +1 -0
- package/dist/epsilon-derivation.js +54 -0
- package/dist/epsilon-derivation.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/managed/compiler/contract-info.json +165 -0
- package/dist/managed/compiler/contract-manifest.json +32 -0
- package/dist/managed/contract/index.d.ts +65 -0
- package/dist/managed/contract/index.js +611 -0
- package/dist/managed/contract/index.js.map +8 -0
- package/dist/schnorr.d.ts +100 -0
- package/dist/schnorr.d.ts.map +1 -0
- package/dist/schnorr.js +144 -0
- package/dist/schnorr.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +74 -0
- package/dist/signature-requests-state-reader.d.ts.map +1 -0
- package/dist/signature-requests-state-reader.js +167 -0
- package/dist/signature-requests-state-reader.js.map +1 -0
- package/dist/signature-response-verification.d.ts +27 -0
- package/dist/signature-response-verification.d.ts.map +1 -0
- package/dist/signature-response-verification.js +45 -0
- package/dist/signature-response-verification.js.map +1 -0
- package/dist/signature-state-reading.d.ts +36 -0
- package/dist/signature-state-reading.d.ts.map +1 -0
- package/dist/signature-state-reading.js +62 -0
- package/dist/signature-state-reading.js.map +1 -0
- package/dist/signet-contract-state-reader.d.ts +146 -0
- package/dist/signet-contract-state-reader.d.ts.map +1 -0
- package/dist/signet-contract-state-reader.js +226 -0
- package/dist/signet-contract-state-reader.js.map +1 -0
- package/dist/signet-event-observer.d.ts +102 -0
- package/dist/signet-event-observer.d.ts.map +1 -0
- package/dist/signet-event-observer.js +127 -0
- package/dist/signet-event-observer.js.map +1 -0
- package/dist/signet-events.d.ts +175 -0
- package/dist/signet-events.d.ts.map +1 -0
- package/dist/signet-events.js +210 -0
- package/dist/signet-events.js.map +1 -0
- package/dist/signet-request-feed.d.ts +78 -0
- package/dist/signet-request-feed.d.ts.map +1 -0
- package/dist/signet-request-feed.js +116 -0
- package/dist/signet-request-feed.js.map +1 -0
- package/dist/signet-request-resolver.d.ts +58 -0
- package/dist/signet-request-resolver.d.ts.map +1 -0
- package/dist/signet-request-resolver.js +76 -0
- package/dist/signet-request-resolver.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +160 -0
- package/dist/signet-request-response-reader.d.ts.map +1 -0
- package/dist/signet-request-response-reader.js +198 -0
- package/dist/signet-request-response-reader.js.map +1 -0
- package/dist/signet-requests.d.ts +363 -0
- package/dist/signet-requests.d.ts.map +1 -0
- package/dist/signet-requests.js +497 -0
- package/dist/signet-requests.js.map +1 -0
- package/dist/signet-response-feed.d.ts +161 -0
- package/dist/signet-response-feed.d.ts.map +1 -0
- package/dist/signet-response-feed.js +234 -0
- package/dist/signet-response-feed.js.map +1 -0
- package/package.json +47 -0
- package/src/Schnorr.compact +63 -0
- package/src/Signet.compact +529 -0
- package/src/circuits.compact +36 -0
- package/src/constants.ts +97 -0
- package/src/epsilon-derivation.ts +62 -0
- package/src/index.ts +31 -0
- package/src/managed/compiler/contract-info.json +165 -0
- package/src/managed/compiler/contract-manifest.json +32 -0
- package/src/managed/contract/index.d.ts +65 -0
- package/src/managed/contract/index.js +611 -0
- package/src/managed/contract/index.js.map +8 -0
- package/src/schnorr.ts +210 -0
- package/src/signature-requests-state-reader.ts +223 -0
- package/src/signature-response-verification.ts +64 -0
- package/src/signature-state-reading.ts +87 -0
- package/src/signet-contract-state-reader.ts +391 -0
- package/src/signet-event-observer.ts +186 -0
- package/src/signet-events.ts +337 -0
- package/src/signet-request-feed.ts +158 -0
- package/src/signet-request-resolver.ts +116 -0
- package/src/signet-request-response-reader.ts +324 -0
- package/src/signet-requests.ts +737 -0
- package/src/signet-response-feed.ts +325 -0
|
@@ -0,0 +1,62 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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-events.ts";
|
|
13
|
+
export * from "./signet-event-observer.ts";
|
|
14
|
+
export * from "./signet-request-resolver.ts";
|
|
15
|
+
export * from "./signet-request-feed.ts";
|
|
16
|
+
export * from "./signet-response-feed.ts";
|
|
17
|
+
export * from "./constants.ts";
|
|
18
|
+
export * from "./epsilon-derivation.ts";
|
|
19
|
+
export * from "./schnorr.ts";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Compiled pure circuits of Signet.compact (run `yarn compile` first): the
|
|
23
|
+
* executable reference implementation of the client-agnostic circuits —
|
|
24
|
+
* path<->identity checks, the attestation message, and the Schnorr challenge.
|
|
25
|
+
* Off-chain code MUST use these instead of re-porting the algorithms — they
|
|
26
|
+
* are the same compiled logic the contracts prove. The generic request
|
|
27
|
+
* circuits cannot be compiled here (type-parameterized): request construction
|
|
28
|
+
* is contract-only, and request-id hashing has a documented-deviation TS twin
|
|
29
|
+
* (`calculateRequestId` in signet-requests.ts).
|
|
30
|
+
*/
|
|
31
|
+
export { pureCircuits, type PureCircuits } from "./managed/contract/index.js";
|
|
@@ -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>;
|