@sig-net/midnight 0.0.2 → 0.0.4
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 +137 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +1 -1
- package/dist/managed/compiler/contract-manifest.json +5 -5
- package/dist/managed/contract/index.js +169 -169
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +21 -22
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +24 -20
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-state-reading.d.ts +21 -6
- package/dist/signature-state-reading.d.ts.map +1 -1
- package/dist/signature-state-reading.js +42 -10
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +9 -2
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +6 -6
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +2 -1
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +4 -4
- package/dist/signet-requests.js.map +1 -1
- package/package.json +10 -5
- package/src/Schnorr.compact +1 -1
- package/src/Signet.compact +11 -11
- package/src/circuits.compact +1 -1
- package/src/constants.ts +0 -97
- package/src/epsilon-derivation.ts +0 -62
- package/src/index.ts +0 -29
- package/src/managed/compiler/contract-info.json +0 -222
- package/src/managed/compiler/contract-manifest.json +0 -32
- package/src/managed/contract/index.d.ts +0 -78
- package/src/managed/contract/index.js +0 -676
- package/src/managed/contract/index.js.map +0 -8
- package/src/schnorr.ts +0 -210
- package/src/signature-requests-state-reader.ts +0 -223
- package/src/signature-response-verification.ts +0 -64
- package/src/signature-state-reading.ts +0 -87
- package/src/signet-contract-state-reader.ts +0 -587
- package/src/signet-request-feed.ts +0 -208
- package/src/signet-request-resolver.ts +0 -116
- package/src/signet-request-response-reader.ts +0 -324
- package/src/signet-requests.ts +0 -762
package/README.md
CHANGED
|
@@ -1,20 +1,139 @@
|
|
|
1
1
|
# @sig-net/midnight
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
The client-agnostic [Sig Network](https://sig.network) protocol library for the [Midnight blockchain](https://midnight.network), and the seed of a future signet.js Midnight adapter. It carries everything a Midnight contract or off-chain client needs to speak the signet protocol (the MPC's [sign bidirectional flow](https://docs.sig.network/architecture/sign-bidirectional)) without binding to any particular contract.
|
|
4
|
+
|
|
5
|
+
## What is in it
|
|
6
|
+
|
|
7
|
+
- **Shared Compact modules**: the package ships its `.compact` sources, so contracts import them directly:
|
|
8
|
+
```compact
|
|
9
|
+
import "@sig-net/midnight/src/Signet";
|
|
10
|
+
```
|
|
11
|
+
- **Compiled pure circuits** (`pureCircuits`): the executable reference implementation of the client-agnostic circuits (path/identity checks, the attestation message, the sign-bidirectional notification packer, the Schnorr challenge). Off-chain code calls these compiled artefacts instead of re-porting the algorithms, so it always agrees with what the contracts prove.
|
|
12
|
+
- **TypeScript twins of the wire structs** and signet request-id computation.
|
|
13
|
+
- **State readers, request feed and resolver**: poll the signet contract for pending requests and their signature / remote-execution responses.
|
|
14
|
+
- **Crypto helpers**: epsilon derivation and Jubjub Schnorr response verification.
|
|
15
|
+
|
|
16
|
+
Where signet.js already covers something (for example EVM transaction preparation or address derivation), import it from there; only what is Midnight-specific lives here.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @sig-net/midnight
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How a client contract integrates
|
|
25
|
+
|
|
26
|
+
A signet-compliant client contract does four things:
|
|
27
|
+
|
|
28
|
+
1. **Stores requests in a public index**: a `SignBidirectionalRequestIndex` map in its ledger. The index can sit at ANY ledger field: each notification the contract registers names the field position holding it, and the MPC reads the authenticated request from there. A contract-local `SignetNonce` counter is a convenient source of request nonces (identical requests must hash to distinct ids); nothing off-chain reads it.
|
|
29
|
+
2. **Pins its counterparties at deploy time**: the central signet contract it notifies, and the MPC attestation key its verify circuit accepts.
|
|
30
|
+
3. **Submits signature requests**: builds the transaction decomposition in-circuit, constructs the canonical request record, stores it in its own index under the request id, and registers a notification in the central registry (which the MPC polls; the MPC then reads the authenticated request back from the ledger field the notification names).
|
|
31
|
+
4. **Verifies the execution response**: checks the attestation key, verifies the MPC's Schnorr attestation in-circuit over (request id, output), and consumes the request.
|
|
32
|
+
|
|
33
|
+
```compact
|
|
34
|
+
pragma language_version >= 0.25;
|
|
35
|
+
|
|
36
|
+
import CompactStandardLibrary;
|
|
37
|
+
import "@sig-net/midnight/src/Signet";
|
|
38
|
+
|
|
39
|
+
// (1) The request index: the public map the MPC reads requests back from.
|
|
40
|
+
// It can sit at any ledger field; the notification in submitSignatureRequest
|
|
41
|
+
// names its position (0 in this contract). The counter is contract-local
|
|
42
|
+
// (it sources each request's nonce so identical requests get distinct ids);
|
|
43
|
+
// the MPC never reads it. The generic size parameters cap the EVM calldata
|
|
44
|
+
// words, access list entries and storage keys your requests may carry.
|
|
45
|
+
export ledger signetRequestsIndex: SignBidirectionalRequestIndex<EVMType2TxParams<1, 0, 0>>;
|
|
46
|
+
export ledger signetNonce: SignetNonce;
|
|
47
|
+
|
|
48
|
+
// (2) Pinned at deploy time.
|
|
49
|
+
export sealed ledger mpcPubKeyHash: Bytes<32>;
|
|
50
|
+
sealed ledger signetNotifier: SignetNotifier;
|
|
51
|
+
|
|
52
|
+
constructor(mpcPk: JubjubPoint, signetContract: SignetNotifier) {
|
|
53
|
+
mpcPubKeyHash = disclose(persistentHash<JubjubPoint>(mpcPk));
|
|
54
|
+
signetNotifier = disclose(signetContract);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// (3) Construct, store and announce a signature request.
|
|
58
|
+
export circuit submitSignatureRequest(evmNonce: Uint<64>, keyVersion: Uint<32>): [] {
|
|
59
|
+
// Decompose the EVM transaction to be signed. Build (or overwrite) every
|
|
60
|
+
// part your contract enforces in-circuit, calldata above all; never pass
|
|
61
|
+
// caller input through unchecked.
|
|
62
|
+
const txParams = EVMType2TxParams<1, 0, 0> {
|
|
63
|
+
to: pad(20, "recipient"),
|
|
64
|
+
chainId: 31337 as Uint<64>,
|
|
65
|
+
nonce: evmNonce,
|
|
66
|
+
gasLimit: 100000 as Uint<64>,
|
|
67
|
+
maxFeePerGas: 30000000000 as Uint<128>,
|
|
68
|
+
maxPriorityFeePerGas: 1000000000 as Uint<128>,
|
|
69
|
+
value: 0 as Uint<128>,
|
|
70
|
+
accessListEntryCount: 0,
|
|
71
|
+
accessList: [],
|
|
72
|
+
calldata: none<EVMCalldata<1>>()
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// The canonical request record. This variant signs with the CONTRACT's own
|
|
76
|
+
// derived account (a path literal the contract fixes); use
|
|
77
|
+
// constructSignBidirectionalRequest instead for caller-identity requests,
|
|
78
|
+
// where the path is bound to the caller's identity commitment.
|
|
79
|
+
const schema = pad(128, "[{\"name\":\"success\",\"type\":\"bool\"}]");
|
|
80
|
+
const request = constructContractPathSignBidirectionalRequest<EVMType2TxParams<1, 0, 0>>(
|
|
81
|
+
signetNonce as Uint<64>, // contract-local request nonce
|
|
82
|
+
TxParamType.evmType2,
|
|
83
|
+
txParams,
|
|
84
|
+
pad(32, "eip155:31337"), // target chain (CAIP-2)
|
|
85
|
+
keyVersion, // MPC root-key version (>= 1)
|
|
86
|
+
pad(256, "my-treasury"), // contract-owned derivation path
|
|
87
|
+
pad(32, "ecdsa"),
|
|
88
|
+
pad(32, "ethereum"),
|
|
89
|
+
pad(64, ""),
|
|
90
|
+
schema,
|
|
91
|
+
schema
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Store the request in YOUR ledger under its id, then register the
|
|
95
|
+
// notification in the central signet contract's registry. The final
|
|
96
|
+
// argument is the ledger field position of signetRequestsIndex, which is
|
|
97
|
+
// how the MPC finds the index to read the request back from.
|
|
98
|
+
const requestId = disclose(calculateRequestId<EVMType2TxParams<1, 0, 0>>(request));
|
|
99
|
+
assert(!signetRequestsIndex.member(requestId), "Request already exists");
|
|
100
|
+
signetNonce.increment(1);
|
|
101
|
+
signetRequestsIndex.insert(requestId, disclose(request));
|
|
102
|
+
signetNotifier.notifyBidirectionalSignatureRequest(requestId,
|
|
103
|
+
constructSignBidirectionalNotificationV1(kernel.self(), requestId as Bytes<32>, 0 as Uint<8>));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// (4) Verify the MPC's Schnorr-signed attestation of the remote execution
|
|
107
|
+
// and consume the request (double-verify protection).
|
|
108
|
+
export circuit verifyResponse(requestId: RequestId, respondBidirectional: RespondBidirectional): [] {
|
|
109
|
+
const rid = disclose(requestId);
|
|
110
|
+
assert(
|
|
111
|
+
persistentHash<JubjubPoint>(respondBidirectional.pk) == mpcPubKeyHash,
|
|
112
|
+
"Unauthorized: attestation pk is not the MPC key"
|
|
113
|
+
);
|
|
114
|
+
assert(
|
|
115
|
+
jubjubSchnorrVerify<4>(
|
|
116
|
+
signetAttestationMessage(rid, respondBidirectional.serializedOutput, respondBidirectional.outputLen),
|
|
117
|
+
JubjubSchnorrSignature {
|
|
118
|
+
announcement: respondBidirectional.announcement,
|
|
119
|
+
response: respondBidirectional.response,
|
|
120
|
+
},
|
|
121
|
+
respondBidirectional.pk
|
|
122
|
+
),
|
|
123
|
+
"Invalid attestation signature"
|
|
124
|
+
);
|
|
125
|
+
assert(signetRequestsIndex.member(rid), "Request not found");
|
|
126
|
+
signetRequestsIndex.remove(rid);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Between the two circuits sit the off-chain steps, which this package also covers: poll the central signet contract with `SignetRequestResponseReader` (configured with both contract addresses and the ledger field position of your request index) to collect and verify the MPC's secp256k1 signature (then broadcast the signed transaction to the destination chain), and later the Schnorr-attested execution output to feed back into `verifyResponse`.
|
|
131
|
+
|
|
132
|
+
The [signet-caller contract](https://github.com/sig-net/midnight-integration/blob/main/packages/caller-contract/src/signet-caller.compact) is the complete, runnable version of this skeleton, exercised end to end by the repository's integration suite; a fuller application (an ERC20 cross-chain vault) lives in [sig-net/midnight-examples](https://github.com/sig-net/midnight-examples).
|
|
133
|
+
|
|
134
|
+
## Related packages
|
|
135
|
+
|
|
136
|
+
- [`@sig-net/midnight-contract`](https://www.npmjs.com/package/@sig-net/midnight-contract): the central signet contract this library reads from.
|
|
137
|
+
- [`@sig-net/midnight-contract-deploy`](https://www.npmjs.com/package/@sig-net/midnight-contract-deploy): deploy tooling for that contract plus generic Midnight deploy/wallet plumbing.
|
|
138
|
+
|
|
139
|
+
Developed in [sig-net/midnight-integration](https://github.com/sig-net/midnight-integration); example applications live in [sig-net/midnight-examples](https://github.com/sig-net/midnight-examples).
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,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,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// Midnight-side sig-net integration
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// boilerplate/contract-cli/src/signet/.
|
|
1
|
+
// Midnight-side sig-net integration: the client-agnostic signet protocol
|
|
2
|
+
// library (wire structs, state readers, request feed/resolver, crypto) plus
|
|
3
|
+
// the compiled pure circuits of the shared Compact module.
|
|
5
4
|
export * from "./signet-requests.js";
|
|
6
5
|
export * from "./signature-state-reading.js";
|
|
7
6
|
export * from "./signature-requests-state-reader.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,2DAA2D;AAE3D,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,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC"}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"manifest-version": "1",
|
|
3
3
|
"compiler-version": "0.33.0",
|
|
4
4
|
"language-version": "0.25.0",
|
|
5
|
-
"runtime-version": "0.18.0-rc.
|
|
5
|
+
"runtime-version": "0.18.0-rc.1",
|
|
6
6
|
"compiler": {
|
|
7
7
|
"type": "directory",
|
|
8
8
|
"contract-info.json": {
|
|
9
9
|
"type": "file",
|
|
10
10
|
"size": 4406,
|
|
11
|
-
"hash": "
|
|
11
|
+
"hash": "1318a883cafbc6340a7aa9623524eb941d37b5b4080ea79dff8948a63e092e47"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"contract": {
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"index.js": {
|
|
22
22
|
"type": "file",
|
|
23
|
-
"size":
|
|
24
|
-
"hash": "
|
|
23
|
+
"size": 42552,
|
|
24
|
+
"hash": "729bf0bd029c64471406cef2c9da38eaa62c4a88808c9a5d80f566f457c06a6c"
|
|
25
25
|
},
|
|
26
26
|
"index.js.map": {
|
|
27
27
|
"type": "file",
|
|
28
28
|
"size": 3115,
|
|
29
|
-
"hash": "
|
|
29
|
+
"hash": "2bc6ceb4c0492981f7bf539948c96408f98134c967e04e7c83d9289437481d43"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|