@inco/js 0.9.0-devnet-test-4 → 0.10.0-devnet-1

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.
Files changed (226) hide show
  1. package/README.md +503 -47
  2. package/dist/cjs/advancedacl/session-key.d.ts +5 -5
  3. package/dist/cjs/advancedacl/session-key.js +33 -9
  4. package/dist/cjs/attestedcompute/attested-compute.d.ts +1 -2
  5. package/dist/cjs/attestedcompute/attested-compute.js +15 -7
  6. package/dist/cjs/attesteddecrypt/attested-decrypt.d.ts +5 -43
  7. package/dist/cjs/attesteddecrypt/attested-decrypt.js +33 -96
  8. package/dist/cjs/attestedreveal/attested-reveal.d.ts +21 -0
  9. package/dist/cjs/attestedreveal/attested-reveal.js +31 -0
  10. package/dist/cjs/attestedreveal/index.d.ts +2 -0
  11. package/dist/cjs/attestedreveal/index.js +21 -0
  12. package/dist/cjs/attestedreveal/types.d.ts +4 -0
  13. package/dist/cjs/attestedreveal/types.js +13 -0
  14. package/dist/cjs/binary.d.ts +82 -0
  15. package/dist/cjs/binary.js +87 -5
  16. package/dist/cjs/chain.d.ts +29 -4
  17. package/dist/cjs/chain.js +34 -6
  18. package/dist/cjs/eip712/eip712.d.ts +18 -0
  19. package/dist/cjs/eip712/eip712.js +51 -0
  20. package/dist/cjs/eip712/index.d.ts +1 -0
  21. package/dist/cjs/eip712/index.js +8 -0
  22. package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.d.ts +49 -0
  23. package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.js +94 -0
  24. package/dist/cjs/elistattesteddecrypt/index.d.ts +2 -0
  25. package/dist/cjs/elistattesteddecrypt/index.js +22 -0
  26. package/dist/cjs/elistattesteddecrypt/types.d.ts +31 -0
  27. package/dist/cjs/elistattesteddecrypt/types.js +16 -0
  28. package/dist/cjs/encryption/encryption.d.ts +115 -0
  29. package/dist/cjs/encryption/encryption.js +98 -7
  30. package/dist/cjs/encryption/index.d.ts +1 -1
  31. package/dist/cjs/encryption/index.js +17 -16
  32. package/dist/cjs/generated/abis/lightning.d.ts +1119 -107
  33. package/dist/cjs/generated/abis/lightning.js +762 -52
  34. package/dist/cjs/generated/abis/test-elist.d.ts +20 -2
  35. package/dist/cjs/generated/abis/test-elist.js +16 -3
  36. package/dist/cjs/generated/abis/verifier.d.ts +118 -15
  37. package/dist/cjs/generated/abis/verifier.js +71 -19
  38. package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +23 -37
  39. package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.js +36 -41
  40. package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.js +1 -1
  41. package/dist/cjs/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +1 -1
  42. package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +16 -0
  43. package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.js +3 -3
  44. package/dist/cjs/generated/es/inco/kms/lite/v1/types_pb.js +1 -1
  45. package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +7 -0
  46. package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +3 -3
  47. package/dist/cjs/generated/lightning.d.ts +150 -0
  48. package/dist/cjs/generated/lightning.js +157 -1
  49. package/dist/cjs/generated/local-node.d.ts +9 -9
  50. package/dist/cjs/generated/local-node.js +37 -10
  51. package/dist/cjs/handle.d.ts +72 -0
  52. package/dist/cjs/handle.js +113 -9
  53. package/dist/cjs/index.d.ts +1 -1
  54. package/dist/cjs/index.js +11 -2
  55. package/dist/cjs/kms/client.d.ts +1 -1
  56. package/dist/cjs/kms/client.js +4 -3
  57. package/dist/cjs/kms/quorumClient.d.ts +18 -12
  58. package/dist/cjs/kms/quorumClient.js +212 -231
  59. package/dist/cjs/kms/quorumConsistency.d.ts +82 -0
  60. package/dist/cjs/kms/quorumConsistency.js +269 -0
  61. package/dist/cjs/kms/signatureVerification.d.ts +35 -0
  62. package/dist/cjs/kms/signatureVerification.js +88 -0
  63. package/dist/cjs/kms/thresholdPromises.d.ts +4 -3
  64. package/dist/cjs/kms/thresholdPromises.js +25 -15
  65. package/dist/cjs/lite/attested-compute.d.ts +2 -2
  66. package/dist/cjs/lite/attested-compute.js +2 -3
  67. package/dist/cjs/lite/attested-decrypt.d.ts +2 -2
  68. package/dist/cjs/lite/attested-decrypt.js +2 -3
  69. package/dist/cjs/lite/hadu.d.ts +1 -1
  70. package/dist/cjs/lite/hadu.js +3 -3
  71. package/dist/cjs/lite/index.d.ts +6 -2
  72. package/dist/cjs/lite/index.js +8 -14
  73. package/dist/cjs/lite/lightning.d.ts +96 -47
  74. package/dist/cjs/lite/lightning.js +221 -267
  75. package/dist/cjs/lite/types.d.ts +47 -0
  76. package/dist/cjs/lite/types.js +3 -0
  77. package/dist/cjs/lite/xwing.d.ts +33 -2
  78. package/dist/cjs/lite/xwing.js +62 -7
  79. package/dist/cjs/local/local-node.d.ts +18 -0
  80. package/dist/cjs/local/local-node.js +18 -3
  81. package/dist/cjs/reencryption/eip712.d.ts +27 -0
  82. package/dist/cjs/reencryption/eip712.js +20 -7
  83. package/dist/cjs/reencryption/types.d.ts +24 -0
  84. package/dist/cjs/retry.d.ts +14 -0
  85. package/dist/cjs/retry.js +58 -2
  86. package/dist/cjs/test/mocks.d.ts +6 -1
  87. package/dist/cjs/test/mocks.js +31 -6
  88. package/dist/cjs/viem.d.ts +361 -1
  89. package/dist/cjs/viem.js +14 -1
  90. package/dist/esm/advancedacl/session-key.d.ts +5 -5
  91. package/dist/esm/advancedacl/session-key.js +33 -9
  92. package/dist/esm/attestedcompute/attested-compute.d.ts +1 -2
  93. package/dist/esm/attestedcompute/attested-compute.js +13 -5
  94. package/dist/esm/attesteddecrypt/attested-decrypt.d.ts +5 -43
  95. package/dist/esm/attesteddecrypt/attested-decrypt.js +34 -96
  96. package/dist/esm/attestedreveal/attested-reveal.d.ts +21 -0
  97. package/dist/esm/attestedreveal/attested-reveal.js +28 -0
  98. package/dist/esm/attestedreveal/index.d.ts +2 -0
  99. package/dist/esm/attestedreveal/index.js +3 -0
  100. package/dist/esm/attestedreveal/types.d.ts +4 -0
  101. package/dist/esm/attestedreveal/types.js +9 -0
  102. package/dist/esm/binary.d.ts +82 -0
  103. package/dist/esm/binary.js +87 -5
  104. package/dist/esm/chain.d.ts +29 -4
  105. package/dist/esm/chain.js +33 -5
  106. package/dist/esm/eip712/eip712.d.ts +18 -0
  107. package/dist/esm/eip712/eip712.js +46 -0
  108. package/dist/esm/eip712/index.d.ts +1 -0
  109. package/dist/esm/eip712/index.js +2 -0
  110. package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.d.ts +49 -0
  111. package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.js +89 -0
  112. package/dist/esm/elistattesteddecrypt/index.d.ts +2 -0
  113. package/dist/esm/elistattesteddecrypt/index.js +3 -0
  114. package/dist/esm/elistattesteddecrypt/types.d.ts +31 -0
  115. package/dist/esm/elistattesteddecrypt/types.js +12 -0
  116. package/dist/esm/encryption/encryption.d.ts +115 -0
  117. package/dist/esm/encryption/encryption.js +98 -7
  118. package/dist/esm/encryption/index.d.ts +1 -1
  119. package/dist/esm/encryption/index.js +2 -2
  120. package/dist/esm/generated/abis/lightning.d.ts +1119 -107
  121. package/dist/esm/generated/abis/lightning.js +761 -51
  122. package/dist/esm/generated/abis/test-elist.d.ts +20 -2
  123. package/dist/esm/generated/abis/test-elist.js +16 -3
  124. package/dist/esm/generated/abis/verifier.d.ts +118 -15
  125. package/dist/esm/generated/abis/verifier.js +71 -19
  126. package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +23 -37
  127. package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.js +35 -40
  128. package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.js +1 -1
  129. package/dist/esm/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +1 -1
  130. package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +16 -0
  131. package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.js +3 -3
  132. package/dist/esm/generated/es/inco/kms/lite/v1/types_pb.js +1 -1
  133. package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +7 -0
  134. package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +3 -3
  135. package/dist/esm/generated/lightning.d.ts +150 -0
  136. package/dist/esm/generated/lightning.js +157 -1
  137. package/dist/esm/generated/local-node.d.ts +9 -9
  138. package/dist/esm/generated/local-node.js +37 -10
  139. package/dist/esm/handle.d.ts +72 -0
  140. package/dist/esm/handle.js +110 -8
  141. package/dist/esm/index.d.ts +1 -1
  142. package/dist/esm/index.js +2 -2
  143. package/dist/esm/kms/client.d.ts +1 -1
  144. package/dist/esm/kms/client.js +3 -2
  145. package/dist/esm/kms/quorumClient.d.ts +18 -12
  146. package/dist/esm/kms/quorumClient.js +213 -232
  147. package/dist/esm/kms/quorumConsistency.d.ts +82 -0
  148. package/dist/esm/kms/quorumConsistency.js +260 -0
  149. package/dist/esm/kms/signatureVerification.d.ts +35 -0
  150. package/dist/esm/kms/signatureVerification.js +84 -0
  151. package/dist/esm/kms/thresholdPromises.d.ts +4 -3
  152. package/dist/esm/kms/thresholdPromises.js +25 -15
  153. package/dist/esm/lite/attested-compute.d.ts +2 -2
  154. package/dist/esm/lite/attested-compute.js +3 -3
  155. package/dist/esm/lite/attested-decrypt.d.ts +2 -2
  156. package/dist/esm/lite/attested-decrypt.js +3 -3
  157. package/dist/esm/lite/hadu.d.ts +1 -1
  158. package/dist/esm/lite/hadu.js +2 -2
  159. package/dist/esm/lite/index.d.ts +6 -2
  160. package/dist/esm/lite/index.js +5 -3
  161. package/dist/esm/lite/lightning.d.ts +96 -47
  162. package/dist/esm/lite/lightning.js +217 -263
  163. package/dist/esm/lite/types.d.ts +47 -0
  164. package/dist/esm/lite/types.js +2 -0
  165. package/dist/esm/lite/xwing.d.ts +33 -2
  166. package/dist/esm/lite/xwing.js +59 -7
  167. package/dist/esm/local/local-node.d.ts +18 -0
  168. package/dist/esm/local/local-node.js +18 -3
  169. package/dist/esm/reencryption/eip712.d.ts +27 -0
  170. package/dist/esm/reencryption/eip712.js +20 -7
  171. package/dist/esm/reencryption/types.d.ts +24 -0
  172. package/dist/esm/retry.d.ts +14 -0
  173. package/dist/esm/retry.js +56 -2
  174. package/dist/esm/test/mocks.d.ts +6 -1
  175. package/dist/esm/test/mocks.js +31 -8
  176. package/dist/esm/viem.d.ts +361 -1
  177. package/dist/esm/viem.js +15 -2
  178. package/dist/types/advancedacl/session-key.d.ts +5 -5
  179. package/dist/types/attestedcompute/attested-compute.d.ts +1 -2
  180. package/dist/types/attesteddecrypt/attested-decrypt.d.ts +5 -43
  181. package/dist/types/attestedreveal/attested-reveal.d.ts +21 -0
  182. package/dist/types/attestedreveal/index.d.ts +2 -0
  183. package/dist/types/attestedreveal/types.d.ts +4 -0
  184. package/dist/types/binary.d.ts +82 -0
  185. package/dist/types/chain.d.ts +29 -4
  186. package/dist/types/eip712/eip712.d.ts +18 -0
  187. package/dist/types/eip712/index.d.ts +1 -0
  188. package/dist/types/elistattesteddecrypt/elist-attested-decrypt.d.ts +49 -0
  189. package/dist/types/elistattesteddecrypt/index.d.ts +2 -0
  190. package/dist/types/elistattesteddecrypt/types.d.ts +31 -0
  191. package/dist/types/encryption/encryption.d.ts +115 -0
  192. package/dist/types/encryption/index.d.ts +1 -1
  193. package/dist/types/generated/abis/lightning.d.ts +1119 -107
  194. package/dist/types/generated/abis/test-elist.d.ts +20 -2
  195. package/dist/types/generated/abis/verifier.d.ts +118 -15
  196. package/dist/types/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +23 -37
  197. package/dist/types/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +16 -0
  198. package/dist/types/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +7 -0
  199. package/dist/types/generated/lightning.d.ts +150 -0
  200. package/dist/types/generated/local-node.d.ts +9 -9
  201. package/dist/types/handle.d.ts +72 -0
  202. package/dist/types/index.d.ts +1 -1
  203. package/dist/types/kms/client.d.ts +1 -1
  204. package/dist/types/kms/quorumClient.d.ts +18 -12
  205. package/dist/types/kms/quorumConsistency.d.ts +82 -0
  206. package/dist/types/kms/signatureVerification.d.ts +35 -0
  207. package/dist/types/kms/thresholdPromises.d.ts +4 -3
  208. package/dist/types/lite/attested-compute.d.ts +2 -2
  209. package/dist/types/lite/attested-decrypt.d.ts +2 -2
  210. package/dist/types/lite/hadu.d.ts +1 -1
  211. package/dist/types/lite/index.d.ts +6 -2
  212. package/dist/types/lite/lightning.d.ts +96 -47
  213. package/dist/types/lite/types.d.ts +47 -0
  214. package/dist/types/lite/xwing.d.ts +33 -2
  215. package/dist/types/local/local-node.d.ts +18 -0
  216. package/dist/types/reencryption/eip712.d.ts +27 -0
  217. package/dist/types/reencryption/types.d.ts +24 -0
  218. package/dist/types/retry.d.ts +14 -0
  219. package/dist/types/test/mocks.d.ts +6 -1
  220. package/dist/types/viem.d.ts +361 -1
  221. package/package.json +19 -21
  222. package/dist/cjs/generated/abis/lightning-preview.d.ts +0 -1385
  223. package/dist/cjs/generated/abis/lightning-preview.js +0 -857
  224. package/dist/esm/generated/abis/lightning-preview.d.ts +0 -1385
  225. package/dist/esm/generated/abis/lightning-preview.js +0 -854
  226. package/dist/types/generated/abis/lightning-preview.d.ts +0 -1385
package/README.md CHANGED
@@ -1,100 +1,556 @@
1
1
  # @inco/js
2
2
 
3
- The @inco/js package contains the TypeScript SDK for creating dapps built on Inco.
3
+ TypeScript SDK for building privacy-preserving dapps on [Inco Lightning](https://docs.inco.org). Encrypt values client-side, post ciphertexts to smart contracts for confidential computation, and retrieve attested decryptions — all with post-quantum hybrid encryption (X-Wing KEM).
4
4
 
5
5
  ## Current Status: Active Development
6
6
 
7
- The SDK is currently going through active development, to support all new features that Inco offers. As such, do expect breaking changes in subsequent releases, which will be documented in the [CHANGELOG](./CHANGELOG.md).
7
+ The SDK is under active development. Expect breaking changes in subsequent releases, documented in the [CHANGELOG](./CHANGELOG.md).
8
8
 
9
- ## Install
10
-
11
- Choose your favorite package manager:
9
+ ## Installation
12
10
 
13
11
  ```bash
14
12
  npm install @inco/js
15
13
  # or
16
- bun install @inco/js
17
- # or
18
14
  yarn add @inco/js
15
+ # or
16
+ bun add @inco/js
19
17
  ```
20
18
 
21
- ## Usage
19
+ **Peer dependency:** [viem](https://viem.sh) `^2.39.3` is used for Ethereum interactions.
22
20
 
23
- A typical usage of `@inco/js` includes 3 steps:
21
+ > **Note:** The library has currently only been tested with Webpack and Next.js. If you encounter issues with Rollup or Vite, please open an issue.
24
22
 
25
- 1. Encrypting a value.
26
- 2. Posting the ciphertext to the contract, which will perform confidential computes on it.
27
- 3. Requesting an attested decryption of the result of the computation.
23
+ ## Quick Start
28
24
 
29
- ### 1. Encrypt a value
25
+ A typical workflow has three steps:
26
+
27
+ 1. **Encrypt** a value client-side
28
+ 2. **Submit** the ciphertext to a smart contract for confidential computation
29
+ 3. **Decrypt** the result via attested decryption
30
30
 
31
31
  ```ts
32
- import { getViemChain, supportedChains } from '@inco/js';
32
+ import { getViemChain, supportedChains, handleTypes } from '@inco/js';
33
33
  import { Lightning } from '@inco/js/lite';
34
34
  import { createWalletClient } from 'viem';
35
35
 
36
- // Setup: do it once at initialization
36
+ // 1. Setup
37
37
  const chainId = supportedChains.baseSepolia;
38
- const zap = Lightning.latest('testnet', chainId); // Connect to Inco's latest public testnet
38
+ const zap = await Lightning.latest('testnet', chainId);
39
39
  const walletClient = createWalletClient({
40
40
  chain: getViemChain(chainId),
41
- account: /* Choose your account, e.g. from window.ethereum */,
42
- transport: /* Choose your transport, e.g. from Alchemy */,
41
+ account: /* your account */,
42
+ transport: /* your transport */,
43
43
  });
44
- const dappAddress = '0x00000000000000000000000000000000deadbeef'; // Put your contract address here
44
+ const dappAddress = '0x...'; // Your contract address
45
45
 
46
- // Encrypt the plaintext value
47
- const plaintext = 42;
48
- const ciphertext = await zap.encrypt(plaintext, {
46
+ // 2. Encrypt
47
+ const ciphertext = await zap.encrypt(42n, {
49
48
  accountAddress: walletClient.account.address,
50
49
  dappAddress,
50
+ handleType: handleTypes.euint256,
51
51
  });
52
52
 
53
- console.log(ciphertext); // A long hex string representing the encrypted value
53
+ // 3. Submit ciphertext to contract via viem writeContract (not SDK-specific)
54
+
55
+ // 4. Decrypt the result
56
+ const resultHandle = '0x...'; // Retrieved from the contract
57
+ const [attestation] = await zap.attestedDecrypt(walletClient, [resultHandle]);
58
+ console.log(attestation.plaintext.value);
54
59
  ```
55
60
 
56
- ### 2. Post the ciphertext to the contract
61
+ ---
62
+
63
+ ## Package Exports
64
+
65
+ | Import Path | Description |
66
+ | ----------------------- | --------------------------------------------------------------------------------- |
67
+ | `@inco/js` | Core utilities: binary helpers, chain definitions, handle types, viem integration |
68
+ | `@inco/js/lite` | Main SDK: `Lightning` class, encryption, attested decrypt/compute, session keys |
69
+ | `@inco/js/encryption` | Encryption types, plaintext/ciphertext conversions, scheme constants |
70
+ | `@inco/js/reencryption` | Reencryption types, EIP-712 payload creation |
71
+ | `@inco/js/abis` | Generated smart contract ABIs (Lightning, Verifier) |
72
+ | `@inco/js/local` | Local node environment parsing for development |
73
+
74
+ ---
75
+
76
+ ## API Reference
77
+
78
+ ### `Lightning` Class
79
+
80
+ **Import:** `import { Lightning } from '@inco/js/lite'`
57
81
 
58
- This step does not require any specific `@inco/js` functionality. We recommend using [viem](https://viem.sh) to interact with the blockchain. Specifically, use the [`writeContract`](https://viem.sh/docs/contract/writeContract) method to submit transactions. Pass the `ciphertext` from the previous encryption step as the input ciphertext parameter of type `bytes`.
82
+ The primary entry point for all SDK operations. Binds to a specific Inco Lightning deployment and provides encryption, attested decryption, attested compute, and session key management.
59
83
 
60
- ### 3. Request a reencryption
84
+ #### Factory Methods
61
85
 
62
- Following transaction submission, the Inco covalidator processes the computation request. The contract stores the computation result as a handle on-chain. This handle, referenced below as `resultHandle`, is a hexadecimal string of type `Handle` that serves as a reference to the encrypted computation output.
86
+ The constructor is private. Use one of the static factory methods:
63
87
 
64
88
  ```ts
65
- import { Hex } from "viem";
89
+ // Connect to the latest deployment for a given pepper and chain
90
+ const zap = await Lightning.latest("testnet", supportedChains.baseSepolia);
91
+ // Connect with custom configuration
92
+ const zap = await Lightning.custom({
93
+ executorAddress: "0x...",
94
+ chainId: 84532,
95
+ covalidatorUrls: ["https://..."],
96
+ });
97
+
98
+ // Connect to a local development node
99
+ const zap = await Lightning.localNode(); // default testnet pepper
100
+ const zap = await Lightning.localNodeFromEnv(".env"); // from env file
101
+ ```
102
+
103
+ | Method | Returns | Description |
104
+ | --------------------------------------------- | -------------------- | ----------------------------------------------- |
105
+ | `Lightning.baseSepoliaTestnet()` | `Promise<Lightning>` | Latest testnet deployment on Base Sepolia |
106
+ | `Lightning.latest(pepper, chainId)` | `Promise<Lightning>` | Latest deployment for a given pepper and chain |
107
+ | `Lightning.latestDeployment(pepper, chainId)` | `Deployment` | Synchronous deployment lookup (no network call) |
108
+ | `Lightning.at(id)` | `Promise<Lightning>` | Deployment by name or executor address |
109
+ | `Lightning.custom(config)` | `Promise<Lightning>` | Custom deployment configuration |
110
+ | `Lightning.localNode(env?)` | `Promise<Lightning>` | Local development node |
111
+ | `Lightning.localNodeFromEnv(source?)` | `Promise<Lightning>` | Local node from dotenv file or buffer |
112
+
113
+ #### Properties
66
114
 
67
- // Request a re-encryption of the result ciphertext
68
- const resultHandle = "0x..." as Hex; // Retrieve the handle from the contract, e.g. using viem
69
- // Use same walletClient as previous step
70
- const resultPlaintext = await zap.attestedDecrypt(walletClient, [resultHandle]);
115
+ | Property | Type | Description |
116
+ | ----------------- | --------- | -------------------------------------------- |
117
+ | `executorAddress` | `Address` | The executor contract address |
118
+ | `chainId` | `bigint` | The host chain ID |
119
+ | `deployment` | `T` | Shallow copy of the deployment configuration |
71
120
 
72
- console.log(resultPlaintext[0].plaintext.value); // The decrypted value
121
+ #### `encrypt(value, context)`
122
+
123
+ Encrypts a plaintext value using the network's public key.
124
+
125
+ ```ts
126
+ async encrypt<T extends boolean | bigint | number>(
127
+ value: T,
128
+ context: {
129
+ accountAddress: string; // EOA interacting with the dapp
130
+ dappAddress: string; // Contract address
131
+ handleType?: FheType; // Optional, defaults based on value type
132
+ }
133
+ ): Promise<HexString>
73
134
  ```
74
135
 
75
- Handles are processed asynchronously so you may need to wait for our covalidators to catch and compute the value. If you request an attested decryption before it has been processed you will get an error. To help ameliorate this the `attestedDecrypt` has built-in retries, you can further customise by passing a `BackoffConfig` as an extra argument:
136
+ **Supported types and default handle mappings:**
137
+
138
+ | Value Type | Default Handle Type | Example |
139
+ | ------------------- | ---------------------- | ------------------------------------------------------------------------- |
140
+ | `boolean` | `handleTypes.ebool` | `zap.encrypt(true, ctx)` |
141
+ | `bigint` / `number` | `handleTypes.euint256` | `zap.encrypt(42n, ctx)` |
142
+ | `bigint` (address) | `handleTypes.euint160` | `zap.encrypt(BigInt(addr), { ...ctx, handleType: handleTypes.euint160 })` |
143
+
144
+ Returns a hex string ciphertext to pass to your contract as `bytes`.
145
+
146
+ #### `attestedDecrypt(walletClient, handles, ...)`
147
+
148
+ Requests attested decryption of one or more handles. Only handles approved via `e.allow()` can be decrypted.
149
+
150
+ **Three calling modes:**
76
151
 
77
152
  ```ts
78
- type BackoffConfig = {
79
- maxRetries: number;
80
- baseDelayInMs: number;
81
- backoffFactor: number;
82
- };
153
+ import { generateXwingKeypair } from "@inco/js/lite";
154
+
155
+ // Mode 1: Plaintext result (auto-generates ephemeral keypair internally)
156
+ const attestations = await zap.attestedDecrypt(walletClient, [handle]);
157
+ attestations[0].plaintext.value; // The decrypted value
158
+
159
+ // Mode 2: Reencrypt for a delegate (returns encrypted result)
160
+ const encrypted = await zap.attestedDecrypt(
161
+ walletClient,
162
+ [handle],
163
+ delegatePubKey,
164
+ );
165
+ encrypted[0].encryptedPlaintext.ciphertext.value;
166
+
167
+ // Mode 3: Reencrypt and decrypt locally
168
+ const keypair = await generateXwingKeypair();
169
+ const decrypted = await zap.attestedDecrypt(walletClient, [handle], {
170
+ reencryptPubKey: keypair.encodePublicKey(),
171
+ reencryptKeypair: keypair,
172
+ });
173
+ decrypted[0].plaintext.value;
174
+ ```
175
+
176
+ All modes accept an optional `BackoffConfig` as the last argument for retry tuning:
83
177
 
84
- const resultHandle = "0x..." as Hex;
85
- // Default backoff config shown for reference
86
- const backoffConfig: BackoffConfig = {
178
+ ```ts
179
+ const attestations = await zap.attestedDecrypt(walletClient, [handle], {
87
180
  maxRetries: 10,
88
181
  baseDelayInMs: 1000,
89
182
  backoffFactor: 1.5,
90
- };
91
- const resultPlaintext = await zap.attestedDecrypt(
183
+ });
184
+ ```
185
+
186
+ **Return types:**
187
+
188
+ | Mode | Return Type |
189
+ | ------------------------- | ----------------------------------------------------------------------------------------------------------------- |
190
+ | Plaintext | `DecryptionAttestation[]` — `{ handle, plaintext, covalidatorSignatures }` |
191
+ | Reencrypt | `EncryptedDecryptionAttestation[]` — `{ handle, encryptedPlaintext, encryptedSignatures, covalidatorSignatures }` |
192
+ | Reencrypt + local decrypt | `DecryptionAttestation[]` |
193
+
194
+ #### `attestedReveal(handles, backoffConfig?)`
195
+
196
+ Decrypts publicly revealed handles (those marked with `e.reveal()`). Does not require a wallet — anyone can call this.
197
+
198
+ ```ts
199
+ const attestations = await zap.attestedReveal([handle]);
200
+ attestations[0].plaintext.value;
201
+ ```
202
+
203
+ > **Warning:** Once `e.reveal()` is called on-chain, the ciphertext is considered public and can be accessed by anyone. This cannot be undone.
204
+
205
+ #### `attestedCompute(walletClient, lhsHandle, op, rhsPlaintext, ...)`
206
+
207
+ Performs an off-chain comparison operation on an encrypted handle against a plaintext scalar, returning an attested result.
208
+
209
+ ```ts
210
+ import { AttestedComputeSupportedOps } from "@inco/js/lite";
211
+
212
+ // Plaintext result
213
+ const result = await zap.attestedCompute(
92
214
  walletClient,
93
- [resultHandle],
94
- backoffConfig,
215
+ handle,
216
+ AttestedComputeSupportedOps.Ge,
217
+ 700n,
218
+ );
219
+ console.log(result.plaintext.value); // true or false
220
+ ```
221
+
222
+ **Supported operations:**
223
+
224
+ | Operation | Description |
225
+ | -------------------------------- | --------------------- |
226
+ | `AttestedComputeSupportedOps.Eq` | Equal |
227
+ | `AttestedComputeSupportedOps.Ne` | Not equal |
228
+ | `AttestedComputeSupportedOps.Ge` | Greater than or equal |
229
+ | `AttestedComputeSupportedOps.Gt` | Greater than |
230
+ | `AttestedComputeSupportedOps.Le` | Less than or equal |
231
+ | `AttestedComputeSupportedOps.Lt` | Less than |
232
+
233
+ Supports the same three calling modes as `attestedDecrypt` (plaintext, reencrypt, reencrypt + local decrypt).
234
+
235
+ #### Session Key Methods
236
+
237
+ Session keys (allowance vouchers) enable delegated decryption without requiring the data owner's wallet signature for each request.
238
+
239
+ ```ts
240
+ // Owner grants a session key to a delegate
241
+ const voucher = await zap.grantSessionKeyAllowanceVoucher(
242
+ walletClient, // Owner's wallet
243
+ granteeAddress, // Delegate's address
244
+ expiresAt, // Expiration Date
245
+ sessionVerifierAddr, // Session verifier contract
246
+ );
247
+
248
+ // Delegate decrypts using the voucher
249
+ const attestations = await zap.attestedDecryptWithVoucher(
250
+ ephemeralAccount,
251
+ voucher,
252
+ ethClient,
253
+ [handle],
95
254
  );
255
+
256
+ // Delegate computes using the voucher
257
+ const result = await zap.attestedComputeWithVoucher(
258
+ ephemeralAccount,
259
+ voucher,
260
+ ethClient,
261
+ handle,
262
+ AttestedComputeSupportedOps.Eq,
263
+ 42n,
264
+ );
265
+
266
+ // Owner revokes all active vouchers
267
+ const txHash = await zap.updateActiveVouchersSessionNonce(walletClient);
268
+ ```
269
+
270
+ | Method | Description |
271
+ | ------------------------------------------------------------------------------ | ------------------------------------ |
272
+ | `grantSessionKeyAllowanceVoucher(walletClient, grantee, expiresAt, verifier)` | Grant a time-limited session key |
273
+ | `grantCustomSessionKeyAllowanceVoucher(walletClient, verifier, sharerArgData)` | Grant with custom verifier arguments |
274
+ | `attestedDecryptWithVoucher(account, voucher, client, handles, ...)` | Decrypt using a session key |
275
+ | `attestedComputeWithVoucher(account, voucher, client, handle, op, rhs, ...)` | Compute using a session key |
276
+ | `updateActiveVouchersSessionNonce(walletClient)` | Revoke all active vouchers |
277
+
278
+ #### Static Helpers
279
+
280
+ ```ts
281
+ // Read network public key from on-chain verifier
282
+ const pubkey = await Lightning.getNetworkPubkey(publicClient, executorAddress);
283
+
284
+ // Get the IncoVerifier contract instance
285
+ const verifier = await Lightning.getIncoVerifierContract(
286
+ publicClient,
287
+ executorAddress,
288
+ );
289
+
290
+ // Get covalidator URLs for a deployment
291
+ const urls = Lightning.getCovalidatorUrls(deployment, threshold);
292
+ ```
293
+
294
+ ---
295
+
296
+ ### Core Utilities (`@inco/js`)
297
+
298
+ #### Chain Support
299
+
300
+ ```ts
301
+ import { supportedChains, getSupportedChain, getViemChain } from "@inco/js";
302
+
303
+ // Supported chains
304
+ supportedChains.baseSepolia; // 84532
305
+ supportedChains.sepolia; // 11155111
306
+ supportedChains.monadTestnet; // 10143
307
+ supportedChains.plasmaTestnet; // 9746
308
+ supportedChains.worldchainSepolia; // 4801
309
+ supportedChains.anvil; // 31337
310
+
311
+ // Resolve chain from ID, name, or object
312
+ const chain = getSupportedChain(84532);
313
+ const chain = getSupportedChain("baseSepolia");
314
+ const chain = getSupportedChain({ id: 84532 });
315
+
316
+ // Get viem Chain object
317
+ const viemChain = getViemChain(84532);
96
318
  ```
97
319
 
320
+ #### Handle Types
321
+
322
+ ```ts
323
+ import {
324
+ handleTypes,
325
+ isFheType,
326
+ validateHandle,
327
+ getHandleType,
328
+ } from "@inco/js";
329
+
330
+ // FHE type identifiers
331
+ handleTypes.ebool; // 0
332
+ handleTypes.euint4; // 1
333
+ handleTypes.euint8; // 2
334
+ handleTypes.euint16; // 3
335
+ handleTypes.euint32; // 4
336
+ handleTypes.euint64; // 5
337
+ handleTypes.euint128; // 6
338
+ handleTypes.euint160; // 7
339
+ handleTypes.euint256; // 8
340
+ handleTypes.ebytes64; // 9
341
+ handleTypes.ebytes128; // 10
342
+ handleTypes.ebytes256; // 11
343
+
344
+ // Validate and inspect handles
345
+ validateHandle("0x..."); // throws if malformed
346
+ const fheType = getHandleType("0x..."); // extracts FheType from handle
347
+ isFheType(5); // true (euint64)
348
+ ```
349
+
350
+ #### Binary Utilities
351
+
352
+ ```ts
353
+ import {
354
+ bytesToBigInt,
355
+ bigintToBytes,
356
+ bigintToBytes32,
357
+ bytes32ToBigint,
358
+ bytesFromHexString,
359
+ bytesToHex,
360
+ mustBeHex,
361
+ normaliseToHex,
362
+ padLeft,
363
+ asBytes32,
364
+ parseAddress,
365
+ parseHex,
366
+ } from "@inco/js";
367
+
368
+ // Conversions
369
+ bytesToBigInt(new Uint8Array([1, 0])); // 256n
370
+ bigintToBytes(42n); // 32-byte Buffer
371
+ bigintToBytes32(42n); // '0x000...002a' (Bytes32)
372
+
373
+ // Hex helpers
374
+ mustBeHex("0xdead"); // returns typed Hex, throws if invalid
375
+ normaliseToHex("dead"); // '0xdead'
376
+ bytesToHex(new Uint8Array()); // '0x'
377
+
378
+ // Parsing with validation
379
+ parseAddress("0x1234...5678"); // validated Address (20 bytes)
380
+ parseHex("0xabcd"); // validated HexString
381
+ asBytes32("0x00...00"); // validated Bytes32 (32 bytes)
382
+ ```
383
+
384
+ ---
385
+
386
+ ### Encryption Module (`@inco/js/encryption`)
387
+
388
+ Types and conversion utilities for plaintexts and ciphertexts.
389
+
390
+ ```ts
391
+ import {
392
+ // Constants
393
+ encryptionSchemes, // { xwing: 2 }
394
+ supportedFheTypes, // { euint64: 5, euint160: 7, euint256: 8, ebool: 0 }
395
+
396
+ // Conversions
397
+ bigintToPlaintext, // (scheme, type, bigint) => Plaintext
398
+ plaintextToBigint, // (plaintext) => bigint
399
+ plaintextToBytes32, // (plaintext) => Bytes32
400
+ plaintextToBytes, // (plaintext) => Buffer
401
+ bytes32ToPlaintext, // (bytes32, scheme, type) => Plaintext
402
+ bytesToPlaintext, // (bytes, scheme, type) => Plaintext
403
+
404
+ // Helpers
405
+ getEncryptionSchemeName, // (scheme) => 'X-Wing'
406
+ } from "@inco/js/encryption";
407
+ ```
408
+
409
+ **Key types:**
410
+
411
+ | Type | Description |
412
+ | ------------------ | -------------------------------------------------------------------------------------- |
413
+ | `Plaintext` | `{ scheme, type, value }` — value is `bigint` for integer types, `boolean` for `ebool` |
414
+ | `Ciphertext` | `{ scheme, type, value }` — value is a hex string |
415
+ | `EncryptionScheme` | Currently only `2` (X-Wing) |
416
+ | `SupportedFheType` | `0`, `5`, `7`, `8` (ebool, euint64, euint160, euint256) |
417
+
418
+ ---
419
+
420
+ ### Deployment Utilities (`@inco/js/lite`)
421
+
422
+ ```ts
423
+ import {
424
+ getActiveLightningDeployment,
425
+ getLightningDeployments,
426
+ } from "@inco/js/lite";
427
+
428
+ // Get the latest active deployment for a chain
429
+ const deployment = getActiveLightningDeployment("baseSepolia");
430
+
431
+ // Get all deployments for a chain
432
+ const deployments = getLightningDeployments(84532);
433
+ ```
434
+
435
+ #### X-Wing Keypair (`@inco/js/lite`)
436
+
437
+ Generate an ephemeral X-Wing keypair for local reencryption (Mode 3 of `attestedDecrypt` and `attestedCompute`):
438
+
439
+ ```ts
440
+ import { generateXwingKeypair, type XwingKeypair } from "@inco/js/lite";
441
+
442
+ const keypair: XwingKeypair = await generateXwingKeypair();
443
+
444
+ // Pass the public key to the attested call and the keypair for local decryption
445
+ const decrypted = await zap.attestedDecrypt(walletClient, [handle], {
446
+ reencryptPubKey: keypair.encodePublicKey(),
447
+ reencryptKeypair: keypair,
448
+ });
449
+ decrypted[0].plaintext.value;
450
+ ```
451
+
452
+ X-Wing is a post-quantum hybrid KEM combining ML-KEM-768 and X25519. The generated keypair is ephemeral — generate a fresh one per request.
453
+
454
+ ---
455
+
456
+ ### Reencryption Module (`@inco/js/reencryption`)
457
+
458
+ EIP-712 typed data utilities for signing reencryption requests.
459
+
460
+ ```ts
461
+ import { createEIP712Payload } from "@inco/js/reencryption";
462
+
463
+ const payload = createEIP712Payload({
464
+ chainId: 84532n,
465
+ primaryType: "Reencrypt",
466
+ primaryTypeFields: [{ name: "publicKey", type: "bytes" }],
467
+ message: { publicKey: "0x..." },
468
+ domainName: "IncoLite",
469
+ domainVersion: "1",
470
+ verifyingContract: "0x...",
471
+ });
472
+ ```
473
+
474
+ **Key types:**
475
+
476
+ | Type | Description |
477
+ | ----------------- | ---------------------------------------------- |
478
+ | `Reencryptor<S>` | `(args, backoffConfig?) => Promise<Plaintext>` |
479
+ | `PubKeyEncodable` | `{ encodePublicKey(): Uint8Array }` |
480
+ | `EIP712<Message>` | Full EIP-712 typed data payload |
481
+
482
+ ---
483
+
484
+ ### Local Development (`@inco/js/local`)
485
+
486
+ Tools for connecting to a local Anvil + Covalidator development node.
487
+
488
+ ```ts
489
+ import { parseLocalEnv } from "@inco/js/local";
490
+
491
+ // Parse from dotenv string/buffer
492
+ const env = parseLocalEnv(fs.readFileSync(".env"));
493
+
494
+ // Parse from process.env
495
+ const env = parseLocalEnv();
496
+
497
+ // Use with Lightning
498
+ const zap = await Lightning.localNode(env);
499
+ ```
500
+
501
+ Docker images for local development:
502
+
503
+ - `inconetwork/local-node-anvil`
504
+ - `inconetwork/local-node-covalidator`
505
+
506
+ ---
507
+
508
+ ### ABIs (`@inco/js/abis`)
509
+
510
+ Generated contract ABIs for direct contract interaction with viem.
511
+
512
+ ```ts
513
+ import { incoLightningAbi } from "@inco/js/abis/lightning";
514
+ import { incoVerifierAbi } from "@inco/js/abis/verifier";
515
+ ```
516
+
517
+ ---
518
+
519
+ ## Supported Chains
520
+
521
+ | Chain | Chain ID | Name |
522
+ | -------------- | -------- | --------------- |
523
+ | Base Sepolia | `84532` | `baseSepolia` |
524
+ | Plasma Testnet | `9746` | `plasmaTestnet` |
525
+
526
+ ---
527
+
528
+ ## BackoffConfig
529
+
530
+ All attested decrypt/compute methods support optional retry configuration:
531
+
532
+ ```ts
533
+ type BackoffConfig = {
534
+ maxRetries: number; // Default: 5
535
+ baseDelayInMs: number; // Default: 1000
536
+ backoffFactor: number; // Default: 1.5
537
+ errHandler?: (error: Error, attempt: number) => "stop" | "continue";
538
+ };
539
+ ```
540
+
541
+ Only transient errors (timeouts, connection issues, 503s) are retried. Security-critical errors (auth failures, invalid signatures) fail immediately.
542
+
543
+ ---
544
+
545
+ ## Further Reading
546
+
547
+ - [Inco Documentation](https://docs.inco.org)
548
+ - [Encryption Guide](https://docs.inco.org/js-sdk/encryption)
549
+ - [Attested Decrypt](https://docs.inco.org/js-sdk/attestations/attested-decrypt)
550
+ - [Attested Compute](https://docs.inco.org/js-sdk/attestations/attested-compute)
551
+ - [Attested Reveal](https://docs.inco.org/js-sdk/attestations/attested-reveal)
552
+ - [Allowance Vouchers](https://docs.inco.org/js-sdk/voucher/allowance-voucher)
553
+
98
554
  ## License
99
555
 
100
- See the [LICENSE](./LICENSE) file.
556
+ [Apache-2.0](./LICENSE)
@@ -4,7 +4,7 @@ import { DecryptionAttestation, EncryptedDecryptionAttestation } from '../attest
4
4
  import { SupportedChainId } from '../chain.js';
5
5
  import { EncryptionScheme, SupportedFheType } from '../encryption/encryption.js';
6
6
  import { HexString } from '../index.js';
7
- import type { XwingKeypair } from '../lite/index.js';
7
+ import { type XwingKeypair } from '../lite/xwing.js';
8
8
  import { BackoffConfig } from '../retry.js';
9
9
  import type { AllowanceVoucher, AllowanceVoucherWithSig } from './types.js';
10
10
  import { AttestedComputeOP } from '../attestedcompute/types.js';
@@ -42,8 +42,8 @@ export interface SessionKeyAttestedComputeArgs {
42
42
  rhsPlaintext: bigint | boolean;
43
43
  requesterArgData?: Hex | undefined;
44
44
  backoffConfig?: Partial<BackoffConfig> | undefined;
45
- ethClient?: PublicClient<Transport, Chain> | WalletClient<Transport, Chain, Account> | undefined;
46
- executorAddress?: HexString | undefined;
45
+ ethClient: PublicClient<Transport, Chain>;
46
+ executorAddress: HexString;
47
47
  reencryptPubKey?: Uint8Array | undefined;
48
48
  reencryptKeypair?: XwingKeypair | undefined;
49
49
  }
@@ -58,8 +58,8 @@ export interface SessionKeyAttestedDecryptArgs {
58
58
  backoffConfig?: Partial<BackoffConfig> | undefined;
59
59
  reencryptPubKey?: Uint8Array | undefined;
60
60
  reencryptKeypair?: XwingKeypair | undefined;
61
- ethClient?: PublicClient<Transport, Chain> | WalletClient<Transport, Chain, Account> | undefined;
62
- executorAddress?: HexString | undefined;
61
+ ethClient: PublicClient<Transport, Chain>;
62
+ executorAddress: HexString;
63
63
  }
64
64
  /**
65
65
  * Performs attested decrypts using a voucher-backed session key.