@arcium-hq/client 0.9.6 → 0.10.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 +44 -188
- package/build/index.cjs +1987 -1217
- package/build/index.mjs +1989 -1214
- package/build/types/callback.d.ts +1 -1
- package/build/types/idl/arcium.d.ts +4045 -3137
- package/build/types/idl/arcium.d.ts.map +1 -1
- package/build/types/idl/arcium_staking.d.ts +1 -14
- package/build/types/idl/arcium_staking.d.ts.map +1 -1
- package/build/types/onchain.d.ts +3 -57
- package/build/types/onchain.d.ts.map +1 -1
- package/build/types/pda.d.ts +1 -1
- package/build/types/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/callback.ts +1 -1
- package/src/idl/arcium.json +4091 -3183
- package/src/idl/arcium.ts +4175 -3267
- package/src/idl/arcium_staking.json +1 -14
- package/src/idl/arcium_staking.ts +1 -14
- package/src/onchain.ts +6 -187
- package/src/pda.ts +1 -1
- package/src/utils.ts +1 -1
package/README.md
CHANGED
|
@@ -1,215 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/arcium-hq/.github/refs/heads/main/profile/arcium.svg" alt="Arcium" width="200"/>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
<h1>@arcium-hq/client</h1>
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @arcium-hq/client
|
|
9
|
-
# or
|
|
10
|
-
yarn add @arcium-hq/client
|
|
11
|
-
# or
|
|
12
|
-
pnpm add @arcium-hq/client
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
### 1. Setup and Environment
|
|
6
|
+
<p>TypeScript SDK for encryption, PDA helpers, and Arcium computation flows.</p>
|
|
18
7
|
|
|
19
|
-
|
|
20
|
-
import { getArciumEnv } from "@arcium-hq/client";
|
|
21
|
-
import * as anchor from "@coral-xyz/anchor";
|
|
8
|
+
[](https://www.npmjs.com/package/@arcium-hq/client)
|
|
22
9
|
|
|
23
|
-
|
|
24
|
-
const arciumEnv = getArciumEnv();
|
|
10
|
+
**[API Docs](https://ts.arcium.com/api)** | **[Developer Docs](https://docs.arcium.com/developers/js-client-library)**
|
|
25
11
|
|
|
26
|
-
|
|
27
|
-
anchor.setProvider(anchor.AnchorProvider.env());
|
|
28
|
-
const provider = anchor.getProvider();
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### 2. Encryption Setup
|
|
32
|
-
|
|
33
|
-
To send private data for computation within Arcium, you need to encrypt it using a shared secret derived from your keypair and the Arcium MXE's public key.
|
|
34
|
-
|
|
35
|
-
#### Generate a client keypair:
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { x25519 } from "@arcium-hq/client";
|
|
39
|
-
|
|
40
|
-
const privateKey = x25519.utils.randomSecretKey();
|
|
41
|
-
const publicKey = x25519.getPublicKey(privateKey);
|
|
42
|
-
```
|
|
12
|
+
</div>
|
|
43
13
|
|
|
44
|
-
|
|
14
|
+
## When To Use
|
|
45
15
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// Fetch the MXE public key (handles the complex extraction logic internally)
|
|
50
|
-
const mxePublicKey = await getMXEPublicKey(provider, program.programId);
|
|
51
|
-
|
|
52
|
-
if (!mxePublicKey) {
|
|
53
|
-
throw new Error("MXE public key not set");
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
#### Compute the shared secret and initialize cipher:
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { RescueCipher } from "@arcium-hq/client";
|
|
61
|
-
|
|
62
|
-
const sharedSecret = x25519.getSharedSecret(privateKey, mxePublicKey);
|
|
63
|
-
const cipher = new RescueCipher(sharedSecret);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### 3. Encrypt and Submit Data
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { randomBytes } from "crypto";
|
|
70
|
-
import { deserializeLE } from "@arcium-hq/client";
|
|
71
|
-
|
|
72
|
-
// Prepare your data as BigInts
|
|
73
|
-
const val1 = BigInt(123);
|
|
74
|
-
const val2 = BigInt(456);
|
|
75
|
-
const plaintext = [val1, val2];
|
|
76
|
-
|
|
77
|
-
// Generate a random nonce (16 bytes)
|
|
78
|
-
const nonce = randomBytes(16);
|
|
79
|
-
|
|
80
|
-
// Encrypt the data
|
|
81
|
-
const ciphertext = cipher.encrypt(plaintext, nonce);
|
|
82
|
-
|
|
83
|
-
// Submit to your program
|
|
84
|
-
const computationOffset = new anchor.BN(randomBytes(8), "hex");
|
|
85
|
-
|
|
86
|
-
const sig = await program.methods
|
|
87
|
-
.yourComputationMethod(
|
|
88
|
-
computationOffset,
|
|
89
|
-
Array.from(ciphertext[0]),
|
|
90
|
-
Array.from(ciphertext[1]),
|
|
91
|
-
Array.from(publicKey),
|
|
92
|
-
new anchor.BN(deserializeLE(nonce).toString())
|
|
93
|
-
)
|
|
94
|
-
.accountsPartial({
|
|
95
|
-
// Account setup - see Account Helpers section
|
|
96
|
-
})
|
|
97
|
-
.rpc({ skipPreflight: true, commitment: "confirmed" });
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### 4. Track and Finalize Computation
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { awaitComputationFinalization } from "@arcium-hq/client";
|
|
104
|
-
|
|
105
|
-
// Wait for computation to complete
|
|
106
|
-
const finalizeSig = await awaitComputationFinalization(
|
|
107
|
-
provider as anchor.AnchorProvider,
|
|
108
|
-
computationOffset,
|
|
109
|
-
program.programId,
|
|
110
|
-
"confirmed"
|
|
111
|
-
);
|
|
16
|
+
- Encrypting inputs for Arcium computations
|
|
17
|
+
- Deriving Arcium PDAs from TypeScript
|
|
18
|
+
- Waiting for computation finalization and interacting with Arcium account state
|
|
112
19
|
|
|
113
|
-
|
|
114
|
-
```
|
|
20
|
+
## Requirements
|
|
115
21
|
|
|
116
|
-
|
|
22
|
+
- Node.js `>=20.18.0`
|
|
23
|
+
- `@anchor-lang/core` `0.32.1`
|
|
117
24
|
|
|
118
|
-
|
|
119
|
-
// After finalization, fetch your program's result account
|
|
120
|
-
const resultAccount = await program.account.yourResultAccount.fetch(resultAddress);
|
|
25
|
+
## Installation
|
|
121
26
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
resultAccount.encryptedResult,
|
|
125
|
-
nonce,
|
|
126
|
-
);
|
|
127
|
-
console.log("Decrypted result:", decrypted);
|
|
27
|
+
```bash
|
|
28
|
+
npm install @arcium-hq/client @anchor-lang/core
|
|
128
29
|
```
|
|
129
30
|
|
|
130
|
-
##
|
|
131
|
-
|
|
132
|
-
The SDK provides helper functions to derive all necessary Arcium PDAs:
|
|
31
|
+
## Quick Start
|
|
133
32
|
|
|
134
|
-
```
|
|
33
|
+
```ts
|
|
34
|
+
import * as anchor from "@anchor-lang/core";
|
|
135
35
|
import {
|
|
36
|
+
awaitComputationFinalization,
|
|
136
37
|
getArciumEnv,
|
|
137
|
-
getMXEAccAddress,
|
|
138
|
-
getMempoolAccAddress,
|
|
139
|
-
getCompDefAccAddress,
|
|
140
|
-
getExecutingPoolAccAddress,
|
|
141
|
-
getComputationAccAddress,
|
|
142
38
|
getCompDefAccOffset,
|
|
143
|
-
|
|
144
|
-
|
|
39
|
+
getComputationAccAddress,
|
|
40
|
+
getMempoolAccAddress,
|
|
41
|
+
getMXEAccAddress,
|
|
145
42
|
} from "@arcium-hq/client";
|
|
146
43
|
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const mxeAccount = getMXEAccAddress(program.programId);
|
|
152
|
-
|
|
153
|
-
// Get pool addresses (use cluster offset, not program ID)
|
|
154
|
-
const mempoolAccount = getMempoolAccAddress(arciumEnv.arciumClusterOffset);
|
|
155
|
-
const executingPool = getExecutingPoolAccAddress(arciumEnv.arciumClusterOffset);
|
|
156
|
-
|
|
157
|
-
// Get computation definition address
|
|
158
|
-
const compDefOffset = getCompDefAccOffset("your_computation_name");
|
|
159
|
-
const compDefAccount = getCompDefAccAddress(
|
|
160
|
-
program.programId,
|
|
161
|
-
Buffer.from(compDefOffset).readUInt32LE()
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// Get computation account for a specific offset (uses cluster offset)
|
|
165
|
-
const computationAccount = getComputationAccAddress(
|
|
166
|
-
arciumEnv.arciumClusterOffset,
|
|
167
|
-
computationOffset
|
|
44
|
+
const env = getArciumEnv();
|
|
45
|
+
const computationAddress = getComputationAccAddress(
|
|
46
|
+
env.arciumClusterOffset,
|
|
47
|
+
new anchor.BN(1),
|
|
168
48
|
);
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Circuit Management
|
|
172
|
-
|
|
173
|
-
### Upload a Circuit
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
import { uploadCircuit } from "@arcium-hq/client";
|
|
177
|
-
import * as fs from "fs";
|
|
178
49
|
|
|
179
|
-
const
|
|
50
|
+
const compDefOffset = getCompDefAccOffset("my_circuit");
|
|
51
|
+
const mempool = getMempoolAccAddress(env.arciumClusterOffset);
|
|
180
52
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
"your_circuit_name",
|
|
184
|
-
program.programId,
|
|
185
|
-
rawCircuit,
|
|
186
|
-
true // enable logging
|
|
187
|
-
);
|
|
53
|
+
// `mxeProgramId` is the PublicKey of your Anchor program that hosts the MXE.
|
|
54
|
+
const mxe = getMXEAccAddress(mxeProgramId);
|
|
188
55
|
```
|
|
189
56
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
import { buildFinalizeCompDefTx } from "@arcium-hq/client";
|
|
194
|
-
|
|
195
|
-
const finalizeTx = await buildFinalizeCompDefTx(
|
|
196
|
-
provider as anchor.AnchorProvider,
|
|
197
|
-
Buffer.from(compDefOffset).readUInt32LE(),
|
|
198
|
-
program.programId
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
// Set blockhash and sign
|
|
202
|
-
const latestBlockhash = await provider.connection.getLatestBlockhash();
|
|
203
|
-
finalizeTx.recentBlockhash = latestBlockhash.blockhash;
|
|
204
|
-
finalizeTx.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
205
|
-
finalizeTx.sign(owner);
|
|
57
|
+
## Main Exports
|
|
206
58
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
59
|
+
| Area | Description |
|
|
60
|
+
|------|-------------|
|
|
61
|
+
| Cryptography | Rescue/AES helpers, hashing, and X25519 utilities. |
|
|
62
|
+
| `createPacker()` | Pack and unpack circuit inputs and outputs. |
|
|
63
|
+
| PDA helpers | Derive computation, mempool, MXE, cluster, and comp-def addresses. |
|
|
64
|
+
| `awaitComputationFinalization()` | Poll for finalized computations. |
|
|
65
|
+
| IDL exports | Generated Arcium program types and constants. |
|
|
210
66
|
|
|
211
|
-
##
|
|
67
|
+
## See Also
|
|
212
68
|
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
69
|
+
- [`@arcium-hq/reader`](https://www.npmjs.com/package/@arcium-hq/reader)
|
|
70
|
+
- [API Docs](https://ts.arcium.com/api)
|
|
71
|
+
- [Developer Docs](https://docs.arcium.com/developers/js-client-library)
|