@arcium-hq/client 0.9.7 → 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 CHANGED
@@ -1,215 +1,71 @@
1
- # Arcium Client SDK
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
- The Arcium Client SDK is a TypeScript library for interacting with the Arcium Solana program, enabling secure multi-party computation on encrypted data.
4
+ <h1>@arcium-hq/client</h1>
4
5
 
5
- ## Installation
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
- ```typescript
20
- import { getArciumEnv } from "@arcium-hq/client";
21
- import * as anchor from "@coral-xyz/anchor";
8
+ [![npm](https://img.shields.io/npm/v/@arcium-hq/client)](https://www.npmjs.com/package/@arcium-hq/client)
22
9
 
23
- // Get Arcium environment configuration
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
- // Setup Anchor provider
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
- #### Obtain the MXE's public key:
14
+ ## When To Use
45
15
 
46
- ```typescript
47
- import { getMXEPublicKey } from "@arcium-hq/client";
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
- console.log("Computation finalized:", finalizeSig);
114
- ```
20
+ ## Requirements
115
21
 
116
- ### 5. Decrypt Results
22
+ - Node.js `>=20.18.0`
23
+ - `@anchor-lang/core` `0.32.1`
117
24
 
118
- ```typescript
119
- // After finalization, fetch your program's result account
120
- const resultAccount = await program.account.yourResultAccount.fetch(resultAddress);
25
+ ## Installation
121
26
 
122
- // Decrypt the result using the same cipher and nonce
123
- const decrypted = cipher.decrypt(
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
- ## Account Helpers
131
-
132
- The SDK provides helper functions to derive all necessary Arcium PDAs:
31
+ ## Quick Start
133
32
 
134
- ```typescript
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
- getArciumAccountBaseSeed,
144
- getArciumProgramId,
39
+ getComputationAccAddress,
40
+ getMempoolAccAddress,
41
+ getMXEAccAddress,
145
42
  } from "@arcium-hq/client";
146
43
 
147
- // Get cluster offset from environment
148
- const arciumEnv = getArciumEnv();
149
-
150
- // Get MXE account address (uses MXE program ID)
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 rawCircuit = fs.readFileSync("build/your_circuit.arcis");
50
+ const compDefOffset = getCompDefAccOffset("my_circuit");
51
+ const mempool = getMempoolAccAddress(env.arciumClusterOffset);
180
52
 
181
- await uploadCircuit(
182
- provider as anchor.AnchorProvider,
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
- ### Finalize Computation Definition
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
- // Send transaction
208
- await provider.sendAndConfirm(finalizeTx);
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
- ## API Reference
67
+ ## See Also
212
68
 
213
- - **[API Reference](https://ts.arcium.com/api)** - Complete API documentation
214
- - **[Developer Docs](https://docs.arcium.com/developers/js-client-library)** - Guides and tutorials
215
- - **[Examples](https://github.com/arcium-hq/examples)** - Code examples
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)