@arcium-hq/reader 0.1.47 → 0.2.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,136 +1,293 @@
1
1
  # Arcium Reader SDK
2
2
 
3
- The Arcium Reader SDK is a TypeScript library designed for passively observing and querying the state of the Arcium program on Solana. It allows you to fetch information about Arcium accounts and track the status of computations without requiring a signer.
3
+ The Arcium Reader SDK is a TypeScript library for passively observing and querying the Arcium network state. It provides read-only access to account data, computation tracking, and event monitoring without requiring a wallet or signer.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @arcium-hq/reader
9
+ # or
10
+ yarn add @arcium-hq/reader
11
+ # or
12
+ pnpm add @arcium-hq/reader
13
+ ```
9
14
 
10
- or
15
+ ## Quick Start
11
16
 
12
- yarn add @arcium-hq/reader
17
+ ### 1. Setup
13
18
 
14
- or
19
+ ```typescript
20
+ import * as anchor from "@coral-xyz/anchor";
21
+ import { getArciumProgramReadonly } from "@arcium-hq/reader";
15
22
 
16
- pnpm add @arcium-hq/reader
23
+ // Setup connection (no wallet required)
24
+ const connection = new anchor.web3.Connection("https://api.mainnet-beta.solana.com");
25
+ const provider = new anchor.AnchorProvider(connection, null, {});
26
+ const arciumProgram = getArciumProgramReadonly(provider);
17
27
  ```
18
28
 
19
- ## Usage
29
+ ### 2. Query Account Information
20
30
 
21
- ### Getting the Read-only Program
31
+ ```typescript
32
+ import {
33
+ getMXEAccAddresses,
34
+ getMXEAccInfo,
35
+ getClusterAccAddresses,
36
+ getClusterAccInfo,
37
+ } from "@arcium-hq/reader";
38
+
39
+ // Get all MXE accounts
40
+ const mxeAddresses = await getMXEAccAddresses(connection);
41
+ console.log(`Found ${mxeAddresses.length} MXE accounts`);
42
+
43
+ // Get detailed information for first MXE
44
+ if (mxeAddresses.length > 0) {
45
+ const mxeInfo = await getMXEAccInfo(arciumProgram, mxeAddresses[0]);
46
+ console.log("MXE Info:", {
47
+ authority: mxeInfo.authority,
48
+ cluster: mxeInfo.cluster,
49
+ computationDefinitions: mxeInfo.computationDefinitions.length,
50
+ });
51
+ }
52
+ ```
22
53
 
23
- To interact with the reader functions, you first need a read-only instance of the Arcium Anchor program. This doesn't require a wallet or signer.
54
+ ### 3. Monitor Computations
24
55
 
25
56
  ```typescript
26
- import * as anchor from "@coral-xyz/anchor";
27
- import { getArciumProgramReadonly } from "@arcium-hq/reader";
57
+ import { subscribeComputations } from "@arcium-hq/reader";
28
58
 
29
- // Assuming you have an AnchorProvider configured (e.g., from anchor.AnchorProvider.env())
30
- const provider = anchor.getProvider();
31
- const arciumProgram = getArciumProgramReadonly(
32
- provider as anchor.AnchorProvider
59
+ // Subscribe to computation events for an MXE program
60
+ const mxeProgramId = new anchor.web3.PublicKey("YOUR_MXE_PROGRAM_ID");
61
+
62
+ const subscriptionId = await subscribeComputations(
63
+ connection,
64
+ mxeProgramId,
65
+ (eventData, eventName) => {
66
+ console.log(`Event: ${eventName}`, eventData);
67
+ }
33
68
  );
34
69
  ```
35
70
 
36
- ### Fetching Account Information
71
+ ## Account Types and Queries
37
72
 
38
- The reader SDK provides functions to fetch and deserialize various Arcium account types.
73
+ ### MXE (Multi-party eXecution Environment) Accounts
39
74
 
40
- **1. Fetching MXE Accounts:**
75
+ MXE accounts represent execution environments for secure computations.
41
76
 
42
77
  ```typescript
43
78
  import { getMXEAccAddresses, getMXEAccInfo } from "@arcium-hq/reader";
44
79
 
45
- // Get all MXE account public keys
46
- const mxeAccPubkeys = await getMXEAccAddresses(provider.connection);
47
-
48
- // Get detailed info for a specific MXE account
49
- if (mxeAccPubkeys.length > 0) {
50
- const mxeAccInfo = await getMXEAccInfo(arciumProgram, mxeAccPubkeys[0]);
51
- console.log("MXE Account Info:", mxeAccInfo);
52
- // Access fields like mxeAccInfo.computationDefinitions, mxeAccInfo.cluster, etc.
80
+ // Get all MXE account addresses
81
+ const mxeAddresses = await getMXEAccAddresses(connection);
82
+
83
+ // Fetch detailed MXE information
84
+ for (const address of mxeAddresses) {
85
+ const mxeInfo = await getMXEAccInfo(arciumProgram, address);
86
+
87
+ console.log("MXE Account:", {
88
+ address: address.toBase58(),
89
+ authority: mxeInfo.authority?.toBase58(),
90
+ cluster: mxeInfo.cluster,
91
+ x25519KeySet: 'set' in mxeInfo.x25519Pubkey,
92
+ computationDefinitions: mxeInfo.computationDefinitions,
93
+ fallbackClusters: mxeInfo.fallbackClusters,
94
+ });
53
95
  }
54
96
  ```
55
97
 
56
- **2. Fetching Cluster Accounts:**
98
+ ### Cluster Accounts
99
+
100
+ Cluster accounts manage collections of ARX nodes that execute computations.
57
101
 
58
102
  ```typescript
59
103
  import { getClusterAccAddresses, getClusterAccInfo } from "@arcium-hq/reader";
60
104
 
61
- // Get all Cluster account public keys
62
- const clusterAccPubkeys = await getClusterAccAddresses(provider.connection);
63
-
64
- // Get detailed info for a specific Cluster account
65
- if (clusterAccPubkeys.length > 0) {
66
- const clusterInfo = await getClusterAccInfo(
67
- arciumProgram,
68
- clusterAccPubkeys[0]
69
- );
70
- console.log("Cluster Account Info:", clusterInfo);
71
- // Access fields like clusterInfo.mxes, clusterInfo.nodes, etc.
105
+ // Get all cluster addresses
106
+ const clusterAddresses = await getClusterAccAddresses(connection);
107
+
108
+ // Analyze cluster information
109
+ for (const address of clusterAddresses) {
110
+ const clusterInfo = await getClusterAccInfo(arciumProgram, address);
111
+
112
+ console.log("Cluster:", {
113
+ address: address.toBase58(),
114
+ nodeCount: clusterInfo.nodes.length,
115
+ mxeCount: clusterInfo.mxes.length,
116
+ threshold: clusterInfo.threshold,
117
+ state: clusterInfo.state,
118
+ });
72
119
  }
73
120
  ```
74
121
 
75
- **3. Fetching ArxNode Accounts:**
122
+ ### ArxNode Accounts
123
+
124
+ ArxNode accounts represent individual computation nodes in the network.
76
125
 
77
126
  ```typescript
78
127
  import { getArxNodeAccAddresses, getArxNodeAccInfo } from "@arcium-hq/reader";
79
128
 
80
- // Get all ArxNode account public keys
81
- const arxNodeAccPubkeys = await getArxNodeAccAddresses(provider.connection);
82
-
83
- // Get detailed info for a specific ArxNode account
84
- if (arxNodeAccPubkeys.length > 0) {
85
- const arxNodeInfo = await getArxNodeAccInfo(
86
- arciumProgram,
87
- arxNodeAccPubkeys[0]
88
- );
89
- console.log("ArxNode Account Info:", arxNodeInfo);
90
- // Access fields like arxNodeInfo.clusterMemberships, etc.
129
+ // Get all ARX node addresses
130
+ const arxNodeAddresses = await getArxNodeAccAddresses(connection);
131
+
132
+ // Get node information
133
+ for (const address of arxNodeAddresses) {
134
+ const nodeInfo = await getArxNodeAccInfo(arciumProgram, address);
135
+
136
+ console.log("ARX Node:", {
137
+ address: address.toBase58(),
138
+ authority: nodeInfo.authority?.toBase58(),
139
+ clusterMemberships: nodeInfo.clusterMemberships,
140
+ encryptionPubkey: Buffer.from(nodeInfo.encryptionPubkey).toString('hex'),
141
+ });
91
142
  }
92
143
  ```
93
144
 
94
- ### Tracking Computation Status
145
+ ### Computation Definition Accounts
95
146
 
96
- You can subscribe to events related to a specific MXE (identified by its program ID) to track the lifecycle of computations it processes.
147
+ Track available computation definitions and their configurations.
97
148
 
98
149
  ```typescript
99
- import {
150
+ import { getCompDefAccInfo } from "@arcium-hq/reader";
151
+ import { getCompDefAccAddress } from "@arcium-hq/reader";
152
+
153
+ // Get computation definition for a specific circuit
154
+ const circuitName = "your_circuit_name";
155
+ const mxeProgramId = new anchor.web3.PublicKey("YOUR_MXE_PROGRAM_ID");
156
+
157
+ const compDefAddress = getCompDefAccAddress(mxeProgramId, /* offset */);
158
+ const compDefInfo = await getCompDefAccInfo(arciumProgram, compDefAddress);
159
+
160
+ console.log("Computation Definition:", {
161
+ finalizationAuthority: compDefInfo.finalizationAuthority?.toBase58(),
162
+ finalizesDuringCallback: compDefInfo.finalizeDuringCallback,
163
+ cuAmount: compDefInfo.cuAmount.toString(),
164
+ circuitSource: compDefInfo.circuitSource,
165
+ });
166
+ ```
167
+
168
+ ### Computation Accounts
169
+
170
+ Monitor individual computation instances and their status.
171
+
172
+ ```typescript
173
+ import { getComputationAccInfo } from "@arcium-hq/reader";
174
+ import { getComputationAccAddress } from "@arcium-hq/reader";
175
+
176
+ // Get computation account info
177
+ const computationOffset = new anchor.BN("123456789");
178
+ const computationAddress = getComputationAccAddress(mxeProgramId, computationOffset);
179
+ const computationInfo = await getComputationAccInfo(arciumProgram, computationAddress);
180
+
181
+ console.log("Computation:", {
182
+ status: computationInfo.status,
183
+ arguments: computationInfo.arguments,
184
+ results: computationInfo.results,
185
+ submitter: computationInfo.submitter.toBase58(),
186
+ });
187
+ ```
188
+
189
+ ## Mempool Analysis
190
+
191
+ Analyze pending computations in the network's memory pools.
192
+
193
+ ```typescript
194
+ import {
195
+ getComputationsInMempool,
196
+ getMempoolAccAddress
197
+ } from "@arcium-hq/reader";
198
+
199
+ // Get mempool for an MXE
200
+ const mempoolAddress = getMempoolAccAddress(mxeProgramId);
201
+ const pendingComputations = await getComputationsInMempool(arciumProgram, mempoolAddress);
202
+
203
+ console.log(`Found ${pendingComputations.length} pending computations:`);
204
+
205
+ for (const compRef of pendingComputations) {
206
+ console.log("Pending Computation:", {
207
+ computationOffset: compRef.computationOffset.toString(),
208
+ priorityFee: compRef.priorityFee.toString(),
209
+ computationDefinitionOffset: compRef.computationDefinitionOffset,
210
+ });
211
+ }
212
+ ```
213
+
214
+ ## Event Monitoring
215
+
216
+ ### Real-time Event Subscription
217
+
218
+ Monitor computation lifecycle events in real-time:
219
+
220
+ ```typescript
221
+ import {
100
222
  subscribeComputations,
101
223
  unsubscribeComputations,
102
224
  ArciumEventData,
103
- ArciumEventName,
225
+ ArciumEventName
104
226
  } from "@arcium-hq/reader";
105
- import { PublicKey } from "@solana/web3.js";
106
-
107
- // Assuming `mxeProgramId` is the PublicKey of the MXE program you want to monitor
108
- const mxeProgramId = new PublicKey("YOUR_MXE_PROGRAM_ID");
109
227
 
110
- const eventLog = [];
228
+ const eventLog: Array<{event: ArciumEventData, name: ArciumEventName, timestamp: Date}> = [];
111
229
 
112
- // Define a callback function to handle events
113
- const eventCallback = (
114
- eventData: ArciumEventData,
115
- eventName: ArciumEventName
116
- ) => {
117
- console.log(`Received event: ${eventName}`, eventData);
118
- eventLog.push({ event: eventData, name: eventName });
119
- };
120
-
121
- // Start subscribing
122
- console.log(`Subscribing to computation events for ${mxeProgramId.toBase58()}`);
230
+ // Subscribe to events
123
231
  const subscriptionId = await subscribeComputations(
124
232
  connection,
125
233
  mxeProgramId,
126
- eventCallback
234
+ (eventData, eventName) => {
235
+ eventLog.push({
236
+ event: eventData,
237
+ name: eventName,
238
+ timestamp: new Date()
239
+ });
240
+
241
+ console.log(`[${eventName}] Computation ${eventData.computationOffset.toString()}`);
242
+
243
+ // Handle specific event types
244
+ switch (eventName) {
245
+ case 'QueueComputationEvent':
246
+ console.log(" → Computation queued for execution");
247
+ break;
248
+ case 'InitComputationEvent':
249
+ console.log(" → Computation execution started");
250
+ break;
251
+ case 'CallbackComputationEvent':
252
+ console.log(" → Computation callback received");
253
+ break;
254
+ case 'FinalizeComputationEvent':
255
+ console.log(" → Computation finalized");
256
+ break;
257
+ }
258
+ }
127
259
  );
128
260
 
129
- console.log(`Subscription active with ID: ${subscriptionId}`);
261
+ console.log(`Subscribed to events with ID: ${subscriptionId}`);
262
+
263
+ // Later, unsubscribe
264
+ // await unsubscribeComputations(connection, subscriptionId);
265
+ ```
130
266
 
131
- // ... later, when you want to stop listening ...
267
+ ### Transaction Analysis
132
268
 
133
- // Unsubscribe
134
- await unsubscribeComputations(connection, subscriptionId);
135
- console.log(`Unsubscribed from computation events.`);
269
+ Extract computation events from transaction logs:
270
+
271
+ ```typescript
272
+ import { getComputationOffset } from "@arcium-hq/reader";
273
+
274
+ // Analyze a specific transaction
275
+ const txSignature = "YOUR_TRANSACTION_SIGNATURE";
276
+ const tx = await connection.getTransaction(txSignature, {
277
+ commitment: "confirmed",
278
+ maxSupportedTransactionVersion: 0
279
+ });
280
+
281
+ if (tx) {
282
+ const computationOffset = getComputationOffset(tx);
283
+ if (computationOffset) {
284
+ console.log(`Transaction contains computation: ${computationOffset.toString()}`);
285
+ }
286
+ }
136
287
  ```
288
+
289
+ ## API Reference
290
+
291
+ <!-- TODO: Add API reference url -->
292
+
293
+ For detailed API documentation, please refer to the [Arcium TypeScript SDK API reference](https://github.com/arcium-hq).
package/build/index.cjs CHANGED
@@ -32,9 +32,9 @@ const ARX_NODE_ACC_DISCRIMINATOR = [2, 207, 122, 223, 93, 97, 231, 199];
32
32
  */
33
33
  const CLUSTER_ACC_DISCRIMINATOR = [236, 225, 118, 228, 173, 106, 18, 60];
34
34
  /**
35
- * Discriminator for the MXE account type. Used to filter and identify persistent MXE accounts on-chain.
35
+ * Discriminator for the MXE account type. Used to filter and identify MXE accounts on-chain.
36
36
  */
37
- const MXE_ACC_DISCRIMINATOR = [32, 115, 16, 240, 209, 25, 92, 165];
37
+ const MXE_ACC_DISCRIMINATOR = [103, 26, 85, 250, 179, 159, 17, 117];
38
38
  /**
39
39
  * The public key of the deployed Arcium program on Solana.
40
40
  */
@@ -80,7 +80,7 @@ async function getArxNodeAccAddresses(conn) {
80
80
  * @returns The MXEAccount object.
81
81
  */
82
82
  async function getMXEAccInfo(arciumProgram, address, commitment) {
83
- return arciumProgram.account.persistentMxeAccount.fetch(address, commitment);
83
+ return arciumProgram.account.mxeAccount.fetch(address, commitment);
84
84
  }
85
85
  /**
86
86
  * Fetches and parses a given Cluster account.
package/build/index.d.ts CHANGED
@@ -23,15 +23,15 @@ type ArciumEventName = Capitalize<keyof ArciumEvent>;
23
23
  * Data structure for any Arcium event, as parsed from logs.
24
24
  */
25
25
  type ArciumEventData = ArciumEvent[keyof ArciumEvent];
26
- type MXEAccount = ArciumTypes['persistentMxeAccount'];
26
+ type MXEAccount = ArciumTypes['mxeAccount'];
27
27
  type ClusterAccount = ArciumTypes['cluster'];
28
28
  type ArxNodeAccount = ArciumTypes['arxNode'];
29
29
  type ComputationAccount = ArciumTypes['computationAccount'];
30
30
  type ComputationReference = ArciumTypes['computationReference'];
31
31
  type ComputationDefinitionAccount = ArciumTypes['computationDefinitionAccount'];
32
- type QueueComputationIx = ArciumIdlType['instructions']['37'];
33
- type CallbackComputationIx = ArciumIdlType['instructions']['4'];
34
- type FinalizeComputationIx = ArciumIdlType['instructions']['17'];
32
+ type QueueComputationIx = ArciumIdlType['instructions']['23'];
33
+ type CallbackComputationIx = ArciumIdlType['instructions']['3'];
34
+ type FinalizeComputationIx = ArciumIdlType['instructions']['8'];
35
35
  /**
36
36
  * Status values for a computation, as defined by the Arcium protocol.
37
37
  */
@@ -126,4 +126,5 @@ declare function unsubscribeComputations(conn: Connection, subscriptionId: numbe
126
126
  */
127
127
  declare function getComputationOffset(tx: anchor.web3.VersionedTransactionResponse): anchor.BN | undefined;
128
128
 
129
- export { type ArciumEvent, type ArciumEventData, type ArciumEventName, type ArciumTypes, type ArxNodeAccount, type CallbackComputationIx, type ClusterAccount, type ComputationAccount, type ComputationDefinitionAccount, type ComputationReference, type ComputationStatus, type Connection, type FinalizeComputationIx, type MXEAccount, type Program, type PublicKey, type QueueComputationIx, getArxNodeAccAddresses, getArxNodeAccInfo, getClusterAccAddresses, getClusterAccInfo, getCompDefAccInfo, getComputationAccInfo, getComputationOffset, getComputationsInMempool, getMXEAccAddresses, getMXEAccInfo, subscribeComputations, unsubscribeComputations };
129
+ export { getArxNodeAccAddresses, getArxNodeAccInfo, getClusterAccAddresses, getClusterAccInfo, getCompDefAccInfo, getComputationAccInfo, getComputationOffset, getComputationsInMempool, getMXEAccAddresses, getMXEAccInfo, subscribeComputations, unsubscribeComputations };
130
+ export type { ArciumEvent, ArciumEventData, ArciumEventName, ArciumTypes, ArxNodeAccount, CallbackComputationIx, ClusterAccount, ComputationAccount, ComputationDefinitionAccount, ComputationReference, ComputationStatus, Connection, FinalizeComputationIx, MXEAccount, Program, PublicKey, QueueComputationIx };
package/build/index.mjs CHANGED
@@ -12,9 +12,9 @@ const ARX_NODE_ACC_DISCRIMINATOR = [2, 207, 122, 223, 93, 97, 231, 199];
12
12
  */
13
13
  const CLUSTER_ACC_DISCRIMINATOR = [236, 225, 118, 228, 173, 106, 18, 60];
14
14
  /**
15
- * Discriminator for the MXE account type. Used to filter and identify persistent MXE accounts on-chain.
15
+ * Discriminator for the MXE account type. Used to filter and identify MXE accounts on-chain.
16
16
  */
17
- const MXE_ACC_DISCRIMINATOR = [32, 115, 16, 240, 209, 25, 92, 165];
17
+ const MXE_ACC_DISCRIMINATOR = [103, 26, 85, 250, 179, 159, 17, 117];
18
18
  /**
19
19
  * The public key of the deployed Arcium program on Solana.
20
20
  */
@@ -60,7 +60,7 @@ async function getArxNodeAccAddresses(conn) {
60
60
  * @returns The MXEAccount object.
61
61
  */
62
62
  async function getMXEAccInfo(arciumProgram, address, commitment) {
63
- return arciumProgram.account.persistentMxeAccount.fetch(address, commitment);
63
+ return arciumProgram.account.mxeAccount.fetch(address, commitment);
64
64
  }
65
65
  /**
66
66
  * Fetches and parses a given Cluster account.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcium-hq/reader",
3
- "version": "0.1.47",
3
+ "version": "0.2.0",
4
4
  "description": "Reader SDK for fetching onchain data for Arcium network programs",
5
5
  "author": "Arcium",
6
6
  "license": "GPL-3.0-only",
@@ -41,24 +41,26 @@
41
41
  "@types/bn.js": "^5.1.6",
42
42
  "@types/chai": "^5.0.0",
43
43
  "@types/mocha": "^10.0.9",
44
+ "@types/node": "^22.10.2",
44
45
  "@types/snarkjs": "^0.7.8",
45
- "@typescript-eslint/eslint-plugin": "6.12.0",
46
- "@typescript-eslint/parser": "6.12.0",
46
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
47
+ "@typescript-eslint/parser": "^8.15.0",
47
48
  "chai": "^5.1.2",
48
- "eslint": "8.54.0",
49
- "eslint-config-airbnb-base": "15.0.0",
50
- "eslint-plugin-import": "2.29.0",
49
+ "eslint": "^9.15.0",
50
+ "eslint-config-airbnb-base": "^15.0.0",
51
+ "eslint-plugin-import": "^2.31.0",
51
52
  "mocha": "^10.8.2",
52
53
  "rollup": "^4.24.0",
53
54
  "rollup-plugin-dts": "^6.1.1",
54
55
  "ts-node": "^10.9.2",
55
- "typescript": "^4.5.2"
56
+ "typescript": "^5.6.3",
57
+ "typescript-eslint": "^8.15.0"
56
58
  },
57
59
  "dependencies": {
58
60
  "@coral-xyz/anchor": "^0.31.1",
59
61
  "@noble/curves": "^1.8.1",
60
62
  "@noble/hashes": "^1.7.1",
61
- "@arcium-hq/client": "0.1.47"
63
+ "@arcium-hq/client": "0.2.0"
62
64
  },
63
65
  "keywords": [
64
66
  "Cryptography",