@arcium-hq/client 0.1.46 → 0.1.47
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 +15 -8
- package/build/index.cjs +695 -83
- package/build/index.d.ts +432 -23
- package/build/index.mjs +685 -77
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,12 +9,10 @@ npm install @arcium-hq/client
|
|
|
9
9
|
|
|
10
10
|
or
|
|
11
11
|
|
|
12
|
-
```bash
|
|
13
12
|
yarn add @arcium-hq/client
|
|
14
13
|
|
|
15
14
|
or
|
|
16
15
|
|
|
17
|
-
```bash
|
|
18
16
|
pnpm add @arcium-hq/client
|
|
19
17
|
```
|
|
20
18
|
|
|
@@ -23,6 +21,7 @@ pnpm add @arcium-hq/client
|
|
|
23
21
|
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. The client SDK provides utilities for this using X25519 key exchange and the Rescue cipher.
|
|
24
22
|
|
|
25
23
|
1. **Generate a client keypair:**
|
|
24
|
+
|
|
26
25
|
```typescript
|
|
27
26
|
import { x25519 } from "@arcium-hq/client";
|
|
28
27
|
|
|
@@ -31,7 +30,8 @@ To send private data for computation within Arcium, you need to encrypt it using
|
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
2. **Obtain the MXE's public key:**
|
|
34
|
-
|
|
33
|
+
_This key is typically specific to the Arcium cluster you are interacting with. You might obtain it through configuration or environment variables._
|
|
34
|
+
|
|
35
35
|
```typescript
|
|
36
36
|
// Example public key (replace with the actual key)
|
|
37
37
|
const mxePublicKey = new Uint8Array([
|
|
@@ -40,11 +40,13 @@ To send private data for computation within Arcium, you need to encrypt it using
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
3. **Compute the shared secret:**
|
|
43
|
+
|
|
43
44
|
```typescript
|
|
44
45
|
const sharedSecret = x25519.getSharedSecret(privateKey, mxePublicKey);
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
4. **Initialize the Rescue cipher:**
|
|
49
|
+
|
|
48
50
|
```typescript
|
|
49
51
|
import { RescueCipher } from "@arcium-hq/client";
|
|
50
52
|
|
|
@@ -52,7 +54,8 @@ To send private data for computation within Arcium, you need to encrypt it using
|
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
5. **Prepare plaintext and encrypt:**
|
|
55
|
-
|
|
57
|
+
_The plaintext should be an array of BigInts._
|
|
58
|
+
|
|
56
59
|
```typescript
|
|
57
60
|
import { randomBytes } from "crypto";
|
|
58
61
|
|
|
@@ -68,7 +71,8 @@ To send private data for computation within Arcium, you need to encrypt it using
|
|
|
68
71
|
```
|
|
69
72
|
|
|
70
73
|
6. **Send data to Arcium:**
|
|
71
|
-
|
|
74
|
+
_You typically send the `ciphertext`, your `publicKey`, and the `nonce` (often converted to a `BN`) when calling an Arcium program instruction that requires encrypted inputs._
|
|
75
|
+
|
|
72
76
|
```typescript
|
|
73
77
|
// Example structure (actual usage depends on the specific program)
|
|
74
78
|
// await program.methods.yourInstruction(
|
|
@@ -81,15 +85,18 @@ To send private data for computation within Arcium, you need to encrypt it using
|
|
|
81
85
|
```
|
|
82
86
|
|
|
83
87
|
7. **Decrypting results:**
|
|
84
|
-
|
|
88
|
+
_When your program receives results from Arcium (e.g., via an event), they will likely be encrypted. Use the same `cipher` instance and the `nonce` provided in the result/event to decrypt._
|
|
89
|
+
|
|
85
90
|
```typescript
|
|
86
91
|
// Assuming `event.encryptedResult` is a Uint8Array or number[]
|
|
87
92
|
// and `event.resultNonce` is a Uint8Array or number[] from the Arcium callback
|
|
88
93
|
const resultCiphertextArray = [event.encryptedResult];
|
|
89
94
|
const resultNonceArray = new Uint8Array(event.resultNonce);
|
|
90
95
|
|
|
91
|
-
const decryptedResult = cipher.decrypt(
|
|
96
|
+
const decryptedResult = cipher.decrypt(
|
|
97
|
+
resultCiphertextArray,
|
|
98
|
+
resultNonceArray
|
|
99
|
+
);
|
|
92
100
|
// decryptedResult will be an array of bigints
|
|
93
101
|
const resultValue = decryptedResult[0];
|
|
94
102
|
```
|
|
95
|
-
|