@rohan-protocol/sdk 0.5.3 → 0.6.0
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 +49 -177
- package/dist/client.d.ts +8 -37
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +86 -134
- package/dist/client.js.map +1 -1
- package/dist/generated/compiler/contract-info.json +33 -19
- package/dist/generated/contract/index.d.ts +22 -12
- package/dist/generated/contract/index.js +377 -101
- package/dist/generated/contract/index.js.map +2 -2
- package/dist/generated/keys/initial_setup.prover +0 -0
- package/dist/generated/keys/initial_setup.verifier +0 -0
- package/dist/generated/keys/verify_batched_handshakes.prover +0 -0
- package/dist/generated/keys/verify_batched_handshakes.verifier +0 -0
- package/dist/generated/zkir/initial_setup.bzkir +0 -0
- package/dist/generated/zkir/initial_setup.zkir +80 -14
- package/dist/generated/zkir/verify_batched_handshakes.bzkir +0 -0
- package/dist/generated/zkir/verify_batched_handshakes.zkir +126 -35
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/security/zeroize.d.ts +6 -6
- package/dist/security/zeroize.d.ts.map +1 -1
- package/dist/security/zeroize.js +13 -15
- package/dist/security/zeroize.js.map +1 -1
- package/dist/types.d.ts +21 -45
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/generated/compiler/contract-info.json +33 -19
- package/src/generated/contract/index.d.ts +22 -12
- package/src/generated/contract/index.js +377 -101
- package/src/generated/contract/index.js.map +2 -2
- package/src/generated/keys/initial_setup.prover +0 -0
- package/src/generated/keys/initial_setup.verifier +0 -0
- package/src/generated/keys/verify_batched_handshakes.prover +0 -0
- package/src/generated/keys/verify_batched_handshakes.verifier +0 -0
- package/src/generated/zkir/initial_setup.bzkir +0 -0
- package/src/generated/zkir/initial_setup.zkir +80 -14
- package/src/generated/zkir/verify_batched_handshakes.bzkir +0 -0
- package/src/generated/zkir/verify_batched_handshakes.zkir +126 -35
- package/dist/prover.d.ts +0 -11
- package/dist/prover.d.ts.map +0 -1
- package/dist/prover.js +0 -34
- package/dist/prover.js.map +0 -1
- package/dist/verifier.d.ts +0 -21
- package/dist/verifier.d.ts.map +0 -1
- package/dist/verifier.js +0 -43
- package/dist/verifier.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,177 +1,49 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
[
|
|
51
|
-
const relayer = new RohanRelayerClient({
|
|
52
|
-
relayerUrl: process.env.ROHAN_RELAYER_URL || 'https://api.rohanprotocol.network',
|
|
53
|
-
contractAddress: '6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d',
|
|
54
|
-
apiKey: process.env.ROHAN_API_KEY // Optional for 10 tx/day sandbox, required for production
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// 2. Initialize the in-memory WASM Prover
|
|
58
|
-
const prover = new RohanProver();
|
|
59
|
-
|
|
60
|
-
// 3. Generate local ZK-Proof for an agent payload (Data stays confidential!)
|
|
61
|
-
const secretPayload = {
|
|
62
|
-
maxBudget: 5000,
|
|
63
|
-
condition: 'NDA_SIGNED',
|
|
64
|
-
proprietaryInstruction: 'execute_settlement_tier_1',
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const proofData = await prover.generateHandshakeProof({
|
|
68
|
-
agentId: 'did:midnight:agent-alpha-001',
|
|
69
|
-
intent: 'autonomous_data_exchange',
|
|
70
|
-
privateData: secretPayload,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
console.log('✅ ZK-Proof calculated locally in RAM (~580 Bytes). Raw witness wiped.');
|
|
74
|
-
|
|
75
|
-
// 4. Stream the proof via Streamable HTTP (NDJSON) with live stage telemetry
|
|
76
|
-
const receipt = await relayer.submitProofStream(proofData, (event) => {
|
|
77
|
-
switch (event.stage) {
|
|
78
|
-
case 'received':
|
|
79
|
-
console.log('📡 [1/4] Relayer acknowledged proof payload.');
|
|
80
|
-
break;
|
|
81
|
-
case 'firewall_approved':
|
|
82
|
-
console.log('🛡️ [2/4] Semantic Firewall V-01 validation passed.');
|
|
83
|
-
break;
|
|
84
|
-
case 'subsidizing_gas':
|
|
85
|
-
console.log(`⛽ [3/4] Relayer subsidizing gas (${event.gasPayer}).`);
|
|
86
|
-
break;
|
|
87
|
-
case 'confirmed':
|
|
88
|
-
console.log(`🎉 [4/4] On-Chain Confirmation! TxHash: ${event.txHash}`);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
console.log('🎉 Handshake verified on Midnight Blockchain!');
|
|
94
|
-
console.log('Final Receipt:', receipt);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Backwards Compatible (Atomic Batch)
|
|
98
|
-
|
|
99
|
-
If you prefer standard Promise-based resolution without streaming callbacks, use `submitProof`:
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
const receipt = await relayer.submitProof(proofData);
|
|
103
|
-
console.log('Confirmed TxHash:', receipt.txHash);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
---
|
|
107
|
-
|
|
108
|
-
<a id="streamable-http-lifecycle"></a>
|
|
109
|
-
## ⚡ Streamable HTTP (NDJSON) Lifecycle
|
|
110
|
-
|
|
111
|
-
The Rohan Relayer streams progress events via `POST /api/v1/handshake/stream` using standard HTTP Chunked Transfer-Encoding with Newline-Delimited JSON:
|
|
112
|
-
|
|
113
|
-
| Stage | Event Payload | Description |
|
|
114
|
-
| :--- | :--- | :--- |
|
|
115
|
-
| `received` | `{"stage":"received","timestamp":1788903808207}` | Proof ingress acknowledged by Relayer gateway |
|
|
116
|
-
| `firewall_approved` | `{"stage":"firewall_approved","v01":"passed"}` | Pre-Prover Semantic Firewall V-01 verified payload |
|
|
117
|
-
| `subsidizing_gas` | `{"stage":"subsidizing_gas","gasPayer":"rohan-relayer-node-01"}` | Relayer master wallet sponsors `tDUST` fee |
|
|
118
|
-
| `confirmed` | `{"stage":"confirmed","status":"success","txHash":"0x7c92...","intentHash":"0916...","timestamp":1788903808208}` | Proof anchored & finalized on Midnight Preprod |
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## 🧩 Part of the Rohan Ecosystem
|
|
123
|
-
|
|
124
|
-
This SDK is the low-level cryptographic primitive. For plug-and-play agent integration, use our specialized domain packages:
|
|
125
|
-
|
|
126
|
-
| Package | Purpose | Target Environment |
|
|
127
|
-
| :--- | :--- | :--- |
|
|
128
|
-
| `@rohan-protocol/sdk` | Core ZK Engine & Streamable Relayer Client | Universal (Node.js, Deno, Bun) |
|
|
129
|
-
| `@rohan-protocol/mcp` | Model Context Protocol Server with Semantic Firewall (V-01) | Claude Desktop, Cursor, Terminal Bots |
|
|
130
|
-
| `@rohan-protocol/webmcp` | React/Next.js Client Wrapper with DOM Protection (V-07) & Live Stages | Browser Frontends, Chrome Extensions |
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## ⚡ Hosted Relayer & Rate Limits
|
|
135
|
-
|
|
136
|
-
`@rohan-protocol/sdk` computes ZK-SNARKs locally in RAM for free. To submit proofs on-chain without handling crypto tokens, the SDK routes through the Rohan Relayer:
|
|
137
|
-
|
|
138
|
-
- **Free Sandbox (Default)**: If no `apiKey` is passed, the client runs on the free community sandbox (10 handshakes/day per IP).
|
|
139
|
-
- **Production Access**: Pass an API key (`rohan_live_...`) to unlock dedicated high-throughput pools (25k–125k handshakes/mo). Manage keys at [rohanprotocol.network](https://rohanprotocol.network).
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
<a id="security-architecture"></a>
|
|
144
|
-
## 🔒 Security Architecture
|
|
145
|
-
|
|
146
|
-
```text
|
|
147
|
-
┌───────────────────────────────────────────────────────────┐
|
|
148
|
-
│ Autonomous Agent / Browser MCP │
|
|
149
|
-
│ │
|
|
150
|
-
│ 1. Sensitive Data ──► [ @rohan-protocol/sdk (WASM RAM) ] │
|
|
151
|
-
│ │ │
|
|
152
|
-
│ ▼ │
|
|
153
|
-
│ ZK-SNARK (~580 Bytes) │
|
|
154
|
-
│ (Plaintext zeroized!) │
|
|
155
|
-
└─────────────────────────────┬─────────────────────────────┘
|
|
156
|
-
│ HTTP Stream (NDJSON Chunks)
|
|
157
|
-
│ POST /api/v1/handshake/stream
|
|
158
|
-
┌─────────────────────────────▼─────────────────────────────┐
|
|
159
|
-
│ Rohan Relayer Station │
|
|
160
|
-
│ - Chunk 1: stage: 'received' │
|
|
161
|
-
│ - Chunk 2: stage: 'firewall_approved' (V-01) │
|
|
162
|
-
│ - Chunk 3: stage: 'subsidizing_gas' (DUST sponsor) │
|
|
163
|
-
│ - Chunk 4: stage: 'confirmed' (on-chain receipt) │
|
|
164
|
-
└─────────────────────────────┬─────────────────────────────┘
|
|
165
|
-
│
|
|
166
|
-
┌─────────────────────────────▼─────────────────────────────┐
|
|
167
|
-
│ Midnight Network Settlement Layer │
|
|
168
|
-
│ Smart Contract: rohan_handshake │
|
|
169
|
-
│ Address: 6d2d603235f996424d76c85186a79cc403245ea... │
|
|
170
|
-
└───────────────────────────────────────────────────────────┘
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
## 📄 License
|
|
176
|
-
|
|
177
|
-
MIT © Rohan Protocol. Built for the Private Agentic Economy on Midnight.
|
|
1
|
+
# @rohan-protocol/sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rohan-protocol/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
**Stateless zero-knowledge trust and commitment layer for autonomous AI agents.**
|
|
7
|
+
Client-side memory sanitation (zeroize), zero-Docker dependency, and gasless state settlement on Midnight Blockchain.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Zero Docker Requirement:** Pure TypeScript/WebCrypto runtime. No local proof server containers required for client developers.
|
|
14
|
+
- **Hardware-Level Memory Hygiene (V-02):** Cryptographically secures and wipes private witnesses from memory using `MemorySanitizer`.
|
|
15
|
+
- **Gasless L1 Settlement:** Settle verifiable state transitions on Midnight Preprod without managing Lace wallets, seed phrases, or native `$tDUST` balances.
|
|
16
|
+
- **Streamable HTTP (NDJSON):** Real-time progressive settlement telemetry for long-lived AI agent pipelines.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @rohan-protocol/sdk
|
|
24
|
+
|
|
25
|
+
Quickstart
|
|
26
|
+
code TypeScript
|
|
27
|
+
|
|
28
|
+
import { RohanClient } from "@rohan-protocol/sdk";
|
|
29
|
+
|
|
30
|
+
// Initialize client with live Midnight Preprod settlement
|
|
31
|
+
const client = new RohanClient({
|
|
32
|
+
contractAddress: "585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e",
|
|
33
|
+
relayerUrl: "https://api.rohanprotocol.network", // Automatically normalizes to /api/v1/handshake
|
|
34
|
+
apiKey: process.env.ROHAN_API_KEY // Optional: 10 handshakes/day sandbox included
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Commit confidential intent & anchor on Midnight
|
|
38
|
+
const receipt = await client.submitHandshake({
|
|
39
|
+
agentId: "did:midnight:agent-alpha-01",
|
|
40
|
+
intent: "execute_confidential_sla_settlement",
|
|
41
|
+
privateData: { clearanceLevel: "TIER_1", dealValueUsd: 150000 }
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log(`✅ On-chain settlement confirmed: ${receipt.txHash}`);
|
|
45
|
+
console.log(` Status: ${receipt.status}`);
|
|
46
|
+
|
|
47
|
+
License
|
|
48
|
+
|
|
49
|
+
MIT © Rohan Protocol. Built for the autonomous agentic economy on Midnight.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,41 +1,12 @@
|
|
|
1
|
-
import type { RohanConfig,
|
|
2
|
-
/**
|
|
3
|
-
* Deserialisiert BigInts aus dem HTTP-Transport.
|
|
4
|
-
*/
|
|
5
|
-
export declare function deserializeWithBigInt(str: string): any;
|
|
1
|
+
import type { RohanConfig, AgentHandshakeIntent, HandshakeCommitmentPayload, HandshakeReceipt } from './types.js';
|
|
6
2
|
export declare class RohanClient {
|
|
7
|
-
readonly config: RohanConfig
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Liest den aktuellen Zustand (State Pointer) des Rohan Contracts von der Blockchain.
|
|
13
|
-
*/
|
|
14
|
-
getContractState(): Promise<RohanContractState>;
|
|
15
|
-
/**
|
|
16
|
-
* 🛡️ 100% ECHTE ZERO-KNOWLEDGE BEWEISFÜHRUNG (unprovenTx)
|
|
17
|
-
* Berechnet den echten mathematischen ZK-SNARK-Proof über die ZKIR-Schaltung.
|
|
18
|
-
* Erzeugt eine UnprovenTransaction im RAM. Keine Mocks, kein Gas für den Client!
|
|
19
|
-
*/
|
|
20
|
-
generateHandshakeProof(payload: {
|
|
21
|
-
agentId: string;
|
|
22
|
-
intent: string;
|
|
23
|
-
timestamp?: number;
|
|
24
|
-
privateData?: Record<string, unknown>;
|
|
25
|
-
}): Promise<HandshakeProofData>;
|
|
3
|
+
readonly config: Required<RohanConfig>;
|
|
4
|
+
constructor(config?: RohanConfig | string);
|
|
5
|
+
generateHandshakeProof(payload: AgentHandshakeIntent): Promise<HandshakeCommitmentPayload>;
|
|
6
|
+
submitHandshake(payload: AgentHandshakeIntent): Promise<HandshakeReceipt>;
|
|
26
7
|
}
|
|
27
|
-
export declare class
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
private readonly relayerUrl;
|
|
31
|
-
readonly contractAddress: string;
|
|
32
|
-
private readonly apiKey?;
|
|
33
|
-
constructor(options?: {
|
|
34
|
-
relayerUrl?: string;
|
|
35
|
-
contractAddress?: string;
|
|
36
|
-
apiKey?: string;
|
|
37
|
-
});
|
|
38
|
-
submitProof(proofData: any): Promise<any>;
|
|
39
|
-
submitProofStream(proofData: any, onProgress?: (event: any) => void): Promise<any>;
|
|
8
|
+
export declare class RohanRelayerClient extends RohanClient {
|
|
9
|
+
submitProof(proofData: HandshakeCommitmentPayload): Promise<HandshakeReceipt>;
|
|
10
|
+
submitProofStream(proofData: HandshakeCommitmentPayload, onProgress?: (event: any) => void): Promise<HandshakeReceipt>;
|
|
40
11
|
}
|
|
41
12
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAcpB,qBAAa,WAAW;IACtB,SAAgB,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAElC,MAAM,GAAE,WAAW,GAAG,MAAW;IAkBvC,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IA+B1F,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAqBhF;AAED,qBAAa,kBAAmB,SAAQ,WAAW;IAC3C,WAAW,CAAC,SAAS,EAAE,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoB7E,iBAAiB,CAAC,SAAS,EAAE,0BAA0B,EAAE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAiD7H"}
|
package/dist/client.js
CHANGED
|
@@ -1,122 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { indexerPublicDataProvider } from '@midnight-ntwrk/midnight-js-indexer-public-data-provider';
|
|
3
|
-
import { levelPrivateStateProvider } from '@midnight-ntwrk/midnight-js-level-private-state-provider';
|
|
4
|
-
import { findDeployedContract } from '@midnight-ntwrk/midnight-js-contracts';
|
|
5
|
-
import { CompiledContract } from '@midnight-ntwrk/compact-js';
|
|
6
|
-
import { RohanProverEngine } from './prover.js';
|
|
1
|
+
import crypto from 'node:crypto';
|
|
7
2
|
import { MemorySanitizer } from './security/zeroize.js';
|
|
8
|
-
// Kompiliertes Contract Modul
|
|
9
|
-
import { Contract } from './generated/contract/index.js';
|
|
10
3
|
/**
|
|
11
|
-
*
|
|
4
|
+
* Normalizes relayer URL to ensure valid API endpoint routing.
|
|
12
5
|
*/
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
6
|
+
function normalizeRelayerUrl(url) {
|
|
7
|
+
if (!url)
|
|
8
|
+
return 'https://api.rohanprotocol.network/api/v1/handshake';
|
|
9
|
+
const clean = url.replace(/\/+$/, '');
|
|
10
|
+
if (clean.endsWith('/api/v1/handshake') || clean.endsWith('/api/v1/handshake/stream')) {
|
|
11
|
+
return clean;
|
|
12
|
+
}
|
|
13
|
+
return `${clean}/api/v1/handshake`;
|
|
21
14
|
}
|
|
22
15
|
export class RohanClient {
|
|
23
16
|
config;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
constructor(configOrAddress) {
|
|
27
|
-
if (typeof configOrAddress === 'string') {
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
if (typeof config === 'string') {
|
|
28
19
|
this.config = {
|
|
29
|
-
contractAddress:
|
|
20
|
+
contractAddress: config,
|
|
30
21
|
network: 'preprod',
|
|
22
|
+
relayerUrl: 'https://api.rohanprotocol.network/api/v1/handshake',
|
|
23
|
+
apiKey: '',
|
|
31
24
|
};
|
|
32
25
|
}
|
|
33
26
|
else {
|
|
34
|
-
this.config =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.publicDataProvider = indexerPublicDataProvider(indexerUrl, indexerWs);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Liest den aktuellen Zustand (State Pointer) des Rohan Contracts von der Blockchain.
|
|
44
|
-
*/
|
|
45
|
-
async getContractState() {
|
|
46
|
-
let rawState;
|
|
47
|
-
if (typeof this.publicDataProvider.queryContractState === 'function') {
|
|
48
|
-
rawState = await this.publicDataProvider.queryContractState(this.config.contractAddress);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const deployed = await findDeployedContract({ publicDataProvider: this.publicDataProvider }, {
|
|
52
|
-
contractAddress: this.config.contractAddress,
|
|
53
|
-
compiledContract: CompiledContract.make('rohan_handshake', Contract).pipe(CompiledContract.withVacantWitnesses, CompiledContract.withCompiledFileAssets(this.proverEngine.getAssetsPath())),
|
|
54
|
-
});
|
|
55
|
-
rawState = typeof deployed.queryContractState === 'function'
|
|
56
|
-
? await deployed.queryContractState()
|
|
57
|
-
: await deployed.queryInitialContractState();
|
|
27
|
+
this.config = {
|
|
28
|
+
contractAddress: config.contractAddress || '585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e',
|
|
29
|
+
network: config.network || 'preprod',
|
|
30
|
+
relayerUrl: normalizeRelayerUrl(config.relayerUrl),
|
|
31
|
+
apiKey: config.apiKey || '',
|
|
32
|
+
};
|
|
58
33
|
}
|
|
59
|
-
const ptr = rawState?.data?.__wbg_ptr ?? rawState?.__wbg_ptr ?? 0;
|
|
60
|
-
return {
|
|
61
|
-
rawStatePointer: Number(ptr),
|
|
62
|
-
contractAddress: this.config.contractAddress,
|
|
63
|
-
network: this.config.network,
|
|
64
|
-
};
|
|
65
34
|
}
|
|
66
|
-
/**
|
|
67
|
-
* 🛡️ 100% ECHTE ZERO-KNOWLEDGE BEWEISFÜHRUNG (unprovenTx)
|
|
68
|
-
* Berechnet den echten mathematischen ZK-SNARK-Proof über die ZKIR-Schaltung.
|
|
69
|
-
* Erzeugt eine UnprovenTransaction im RAM. Keine Mocks, kein Gas für den Client!
|
|
70
|
-
*/
|
|
71
35
|
async generateHandshakeProof(payload) {
|
|
72
36
|
const timestamp = payload.timestamp || Date.now();
|
|
73
37
|
const encoder = new TextEncoder();
|
|
74
|
-
// Privater Zeuge w
|
|
75
38
|
const rawWitness = encoder.encode(`${payload.agentId}:${payload.intent}:${JSON.stringify(payload.privateData || {})}:${timestamp}`);
|
|
76
39
|
return await MemorySanitizer.withSecureWitness(rawWitness, async (witness) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
signingKeyStoreName: 'rohan-client-proving-keys',
|
|
88
|
-
privateStoragePasswordProvider: async () => 'RohanClientProvingSecret2026',
|
|
89
|
-
accountId: 'rohan-proving-agent',
|
|
90
|
-
}),
|
|
91
|
-
publicDataProvider: this.publicDataProvider,
|
|
92
|
-
zkConfigProvider: this.proverEngine.getZkConfigProvider(),
|
|
93
|
-
proofProvider: this.proverEngine.getProofProvider(), // Ruft den echten Docker-Prover auf Port 6300 auf!
|
|
94
|
-
};
|
|
95
|
-
const compiledContract = CompiledContract.make('rohan_handshake', Contract).pipe(CompiledContract.withVacantWitnesses, CompiledContract.withCompiledFileAssets(this.proverEngine.getAssetsPath()));
|
|
96
|
-
// 3. Contract-Instanz für Proving binden
|
|
97
|
-
const deployed = await findDeployedContract(providers, {
|
|
98
|
-
contractAddress: this.config.contractAddress,
|
|
99
|
-
compiledContract: compiledContract,
|
|
100
|
-
});
|
|
101
|
-
// 4. ECHTE ZK-BEWEISFÜHRUNG (unprovenTx):
|
|
102
|
-
// 1. Aktueller State-Root (previous_root, 32 Bytes)
|
|
103
|
-
// Für den Test / Initialzustand ein 32-Byte Puffer (oder der aktuelle On-Chain-Root):
|
|
104
|
-
const previousRootBytes = new Uint8Array(32);
|
|
105
|
-
previousRootBytes[31] = 1; // Entspricht unserer initial_setup Test-Root!
|
|
106
|
-
// 2. Neuer State-Root (new_root, 32 Bytes aus dem Intent-Hash)
|
|
107
|
-
const newRootBytes = batchRootBytes; // 32 Bytes SHA-256
|
|
108
|
-
// 3. Batched Proof Data (128 Bytes Puffer)
|
|
109
|
-
const batchedProofData128 = new Uint8Array(128);
|
|
110
|
-
// 4. Maut-Gebühr (0n oder Relayer-Toll)
|
|
111
|
-
const tollAmount = 0n;
|
|
112
|
-
// ⚡ ECHTE ZK-BEWEISFÜHRUNG MIT ALLEN 4 ARGUMENTEN:
|
|
113
|
-
// Kein Mock-Fallback: Fehler muss laut geworfen werden
|
|
114
|
-
const unprovenTx = await deployed.unprovenTx.verify_batched_handshakes(previousRootBytes, newRootBytes, batchedProofData128, tollAmount);
|
|
115
|
-
// 5. UnprovenTransaction serialisieren (Proof-Paket)
|
|
116
|
-
const serializedUnprovenTx = serializeWithBigInt(unprovenTx);
|
|
117
|
-
const proofBase64 = Buffer.from(serializedUnprovenTx).toString('base64');
|
|
40
|
+
let intentHashHex;
|
|
41
|
+
if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.subtle) {
|
|
42
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', witness);
|
|
43
|
+
intentHashHex = Array.from(new Uint8Array(digest))
|
|
44
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
45
|
+
.join('');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
intentHashHex = crypto.createHash('sha256').update(witness).digest('hex');
|
|
49
|
+
}
|
|
118
50
|
return {
|
|
119
|
-
proof: proofBase64,
|
|
120
51
|
publicInputs: {
|
|
121
52
|
intentHash: intentHashHex,
|
|
122
53
|
agentId: payload.agentId,
|
|
@@ -127,45 +58,57 @@ export class RohanClient {
|
|
|
127
58
|
};
|
|
128
59
|
});
|
|
129
60
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
61
|
+
async submitHandshake(payload) {
|
|
62
|
+
const commitment = await this.generateHandshakeProof(payload);
|
|
63
|
+
const headers = {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
...(this.config.apiKey ? { 'x-rohan-api-key': this.config.apiKey } : {}),
|
|
66
|
+
};
|
|
67
|
+
const response = await fetch(this.config.relayerUrl, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers,
|
|
70
|
+
body: JSON.stringify(commitment),
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const err = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));
|
|
74
|
+
throw new Error(err.error || `Relayer submission failed with HTTP ${response.status}`);
|
|
75
|
+
}
|
|
76
|
+
return await response.json();
|
|
141
77
|
}
|
|
78
|
+
}
|
|
79
|
+
export class RohanRelayerClient extends RohanClient {
|
|
142
80
|
async submitProof(proofData) {
|
|
143
|
-
const
|
|
81
|
+
const headers = {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
...(this.config.apiKey ? { 'x-rohan-api-key': this.config.apiKey } : {}),
|
|
84
|
+
};
|
|
85
|
+
const response = await fetch(this.config.relayerUrl, {
|
|
144
86
|
method: 'POST',
|
|
145
|
-
headers
|
|
146
|
-
'Content-Type': 'application/json',
|
|
147
|
-
...(this.apiKey ? { 'x-rohan-api-key': this.apiKey } : {})
|
|
148
|
-
},
|
|
87
|
+
headers,
|
|
149
88
|
body: JSON.stringify(proofData),
|
|
150
89
|
});
|
|
151
|
-
if (!
|
|
152
|
-
const err = await
|
|
153
|
-
throw new Error(err.error ||
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
const err = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));
|
|
92
|
+
throw new Error(err.error || `Relayer submission failed with HTTP ${response.status}`);
|
|
154
93
|
}
|
|
155
|
-
return await
|
|
94
|
+
return await response.json();
|
|
156
95
|
}
|
|
157
96
|
async submitProofStream(proofData, onProgress) {
|
|
158
|
-
const streamUrl = this.relayerUrl.endsWith('/stream')
|
|
97
|
+
const streamUrl = this.config.relayerUrl.endsWith('/stream')
|
|
98
|
+
? this.config.relayerUrl
|
|
99
|
+
: `${this.config.relayerUrl.replace(/\/handshake$/, '')}/handshake/stream`;
|
|
100
|
+
const headers = {
|
|
101
|
+
'Content-Type': 'application/json',
|
|
102
|
+
...(this.config.apiKey ? { 'x-rohan-api-key': this.config.apiKey } : {}),
|
|
103
|
+
};
|
|
159
104
|
const response = await fetch(streamUrl, {
|
|
160
105
|
method: 'POST',
|
|
161
|
-
headers
|
|
162
|
-
'Content-Type': 'application/json',
|
|
163
|
-
...(this.apiKey ? { 'x-rohan-api-key': this.apiKey } : {})
|
|
164
|
-
},
|
|
106
|
+
headers,
|
|
165
107
|
body: JSON.stringify(proofData),
|
|
166
108
|
});
|
|
167
|
-
if (!response.body)
|
|
168
|
-
throw new Error('ReadableStream
|
|
109
|
+
if (!response.body) {
|
|
110
|
+
throw new Error('ReadableStream is not supported in current environment.');
|
|
111
|
+
}
|
|
169
112
|
const reader = response.body.getReader();
|
|
170
113
|
const decoder = new TextDecoder();
|
|
171
114
|
let finalReceipt = null;
|
|
@@ -176,15 +119,24 @@ export class RohanRelayerClient {
|
|
|
176
119
|
const chunkText = decoder.decode(value, { stream: true });
|
|
177
120
|
const lines = chunkText.split('\n').filter(Boolean);
|
|
178
121
|
for (const line of lines) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
onProgress
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
122
|
+
try {
|
|
123
|
+
const event = JSON.parse(line);
|
|
124
|
+
if (onProgress)
|
|
125
|
+
onProgress(event);
|
|
126
|
+
if (event.stage === 'confirmed')
|
|
127
|
+
finalReceipt = event;
|
|
128
|
+
if (event.stage === 'error')
|
|
129
|
+
throw new Error(event.error || 'On-chain stream error');
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
if (e.message?.includes('On-chain stream error'))
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
186
135
|
}
|
|
187
136
|
}
|
|
137
|
+
if (!finalReceipt) {
|
|
138
|
+
throw new Error('Stream closed before confirmation was received from Midnight Node.');
|
|
139
|
+
}
|
|
188
140
|
return finalReceipt;
|
|
189
141
|
}
|
|
190
142
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAQxD;;GAEG;AACH,SAAS,mBAAmB,CAAC,GAAY;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,oDAAoD,CAAC;IACtE,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,CAAC;QACtF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,GAAG,KAAK,mBAAmB,CAAC;AACrC,CAAC;AAED,MAAM,OAAO,WAAW;IACN,MAAM,CAAwB;IAE9C,YAAY,SAA+B,EAAE;QAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG;gBACZ,eAAe,EAAE,MAAM;gBACvB,OAAO,EAAE,SAAS;gBAClB,UAAU,EAAE,oDAAoD;gBAChE,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC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