@inco/lightning-js 0.0.0-bootstrap.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.
Files changed (283) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +587 -0
  3. package/dist/cjs/advancedacl/index.d.ts +2 -0
  4. package/dist/cjs/advancedacl/index.js +19 -0
  5. package/dist/cjs/advancedacl/session-key.d.ts +95 -0
  6. package/dist/cjs/advancedacl/session-key.js +376 -0
  7. package/dist/cjs/advancedacl/types.d.ts +16 -0
  8. package/dist/cjs/advancedacl/types.js +3 -0
  9. package/dist/cjs/attestedcompute/attested-compute.d.ts +65 -0
  10. package/dist/cjs/attestedcompute/attested-compute.js +80 -0
  11. package/dist/cjs/attestedcompute/types.d.ts +35 -0
  12. package/dist/cjs/attestedcompute/types.js +46 -0
  13. package/dist/cjs/attesteddecrypt/attested-decrypt.d.ts +61 -0
  14. package/dist/cjs/attesteddecrypt/attested-decrypt.js +118 -0
  15. package/dist/cjs/attesteddecrypt/index.d.ts +1 -0
  16. package/dist/cjs/attesteddecrypt/index.js +18 -0
  17. package/dist/cjs/attesteddecrypt/types.d.ts +27 -0
  18. package/dist/cjs/attesteddecrypt/types.js +16 -0
  19. package/dist/cjs/attestedreveal/attested-reveal.d.ts +21 -0
  20. package/dist/cjs/attestedreveal/attested-reveal.js +31 -0
  21. package/dist/cjs/attestedreveal/index.d.ts +2 -0
  22. package/dist/cjs/attestedreveal/index.js +21 -0
  23. package/dist/cjs/attestedreveal/types.d.ts +4 -0
  24. package/dist/cjs/attestedreveal/types.js +13 -0
  25. package/dist/cjs/binary.d.ts +104 -0
  26. package/dist/cjs/binary.js +171 -0
  27. package/dist/cjs/chain.d.ts +50 -0
  28. package/dist/cjs/chain.js +62 -0
  29. package/dist/cjs/eip712/eip712.d.ts +18 -0
  30. package/dist/cjs/eip712/eip712.js +51 -0
  31. package/dist/cjs/eip712/index.d.ts +1 -0
  32. package/dist/cjs/eip712/index.js +8 -0
  33. package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
  34. package/dist/cjs/elistattesteddecrypt/elist-attested-decrypt.js +94 -0
  35. package/dist/cjs/elistattesteddecrypt/index.d.ts +2 -0
  36. package/dist/cjs/elistattesteddecrypt/index.js +22 -0
  37. package/dist/cjs/elistattesteddecrypt/types.d.ts +31 -0
  38. package/dist/cjs/elistattesteddecrypt/types.js +16 -0
  39. package/dist/cjs/encryption/encryption.d.ts +235 -0
  40. package/dist/cjs/encryption/encryption.js +226 -0
  41. package/dist/cjs/encryption/index.d.ts +1 -0
  42. package/dist/cjs/encryption/index.js +19 -0
  43. package/dist/cjs/generated/abis/add-two.d.ts +117 -0
  44. package/dist/cjs/generated/abis/add-two.js +80 -0
  45. package/dist/cjs/generated/abis/lightning.d.ts +3362 -0
  46. package/dist/cjs/generated/abis/lightning.js +2445 -0
  47. package/dist/cjs/generated/abis/test-elist.d.ts +276 -0
  48. package/dist/cjs/generated/abis/test-elist.js +168 -0
  49. package/dist/cjs/generated/abis/verifier.d.ts +1353 -0
  50. package/dist/cjs/generated/abis/verifier.js +954 -0
  51. package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
  52. package/dist/cjs/generated/es/inco/covalidator/compute/v1/server_pb.js +395 -0
  53. package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
  54. package/dist/cjs/generated/es/inco/covalidator/compute/v1/types_pb.js +80 -0
  55. package/dist/cjs/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
  56. package/dist/cjs/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +28 -0
  57. package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
  58. package/dist/cjs/generated/es/inco/kms/lite/v1/kms_service_pb.js +100 -0
  59. package/dist/cjs/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
  60. package/dist/cjs/generated/es/inco/kms/lite/v1/types_pb.js +136 -0
  61. package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
  62. package/dist/cjs/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +88 -0
  63. package/dist/cjs/generated/lightning.d.ts +830 -0
  64. package/dist/cjs/generated/lightning.js +872 -0
  65. package/dist/cjs/generated/local-node.d.ts +50 -0
  66. package/dist/cjs/generated/local-node.js +107 -0
  67. package/dist/cjs/handle.d.ts +123 -0
  68. package/dist/cjs/handle.js +221 -0
  69. package/dist/cjs/index.d.ts +5 -0
  70. package/dist/cjs/index.js +31 -0
  71. package/dist/cjs/kms/client.d.ts +12 -0
  72. package/dist/cjs/kms/client.js +47 -0
  73. package/dist/cjs/kms/quorumClient.d.ts +65 -0
  74. package/dist/cjs/kms/quorumClient.js +463 -0
  75. package/dist/cjs/kms/quorumConsistency.d.ts +82 -0
  76. package/dist/cjs/kms/quorumConsistency.js +269 -0
  77. package/dist/cjs/kms/signatureVerification.d.ts +35 -0
  78. package/dist/cjs/kms/signatureVerification.js +88 -0
  79. package/dist/cjs/kms/thresholdPromises.d.ts +8 -0
  80. package/dist/cjs/kms/thresholdPromises.js +62 -0
  81. package/dist/cjs/lite/attested-compute.d.ts +6 -0
  82. package/dist/cjs/lite/attested-compute.js +8 -0
  83. package/dist/cjs/lite/attested-decrypt.d.ts +4 -0
  84. package/dist/cjs/lite/attested-decrypt.js +6 -0
  85. package/dist/cjs/lite/deployments.d.ts +24 -0
  86. package/dist/cjs/lite/deployments.js +21 -0
  87. package/dist/cjs/lite/hadu.d.ts +4 -0
  88. package/dist/cjs/lite/hadu.js +28 -0
  89. package/dist/cjs/lite/index.d.ts +13 -0
  90. package/dist/cjs/lite/index.js +31 -0
  91. package/dist/cjs/lite/lightning.d.ts +459 -0
  92. package/dist/cjs/lite/lightning.js +696 -0
  93. package/dist/cjs/lite/types.d.ts +47 -0
  94. package/dist/cjs/lite/types.js +3 -0
  95. package/dist/cjs/lite/xwing.d.ts +154 -0
  96. package/dist/cjs/lite/xwing.js +326 -0
  97. package/dist/cjs/local/index.d.ts +1 -0
  98. package/dist/cjs/local/index.js +18 -0
  99. package/dist/cjs/local/local-node.d.ts +37 -0
  100. package/dist/cjs/local/local-node.js +80 -0
  101. package/dist/cjs/reencryption/eip712.d.ts +56 -0
  102. package/dist/cjs/reencryption/eip712.js +90 -0
  103. package/dist/cjs/reencryption/index.d.ts +2 -0
  104. package/dist/cjs/reencryption/index.js +19 -0
  105. package/dist/cjs/reencryption/types.d.ts +48 -0
  106. package/dist/cjs/reencryption/types.js +3 -0
  107. package/dist/cjs/retry.d.ts +30 -0
  108. package/dist/cjs/retry.js +87 -0
  109. package/dist/cjs/schema.d.ts +4 -0
  110. package/dist/cjs/schema.js +19 -0
  111. package/dist/cjs/test/mocks.d.ts +20 -0
  112. package/dist/cjs/test/mocks.js +72 -0
  113. package/dist/cjs/viem.d.ts +1141 -0
  114. package/dist/cjs/viem.js +36 -0
  115. package/dist/esm/advancedacl/index.d.ts +2 -0
  116. package/dist/esm/advancedacl/index.js +3 -0
  117. package/dist/esm/advancedacl/session-key.d.ts +95 -0
  118. package/dist/esm/advancedacl/session-key.js +367 -0
  119. package/dist/esm/advancedacl/types.d.ts +16 -0
  120. package/dist/esm/advancedacl/types.js +2 -0
  121. package/dist/esm/attestedcompute/attested-compute.d.ts +65 -0
  122. package/dist/esm/attestedcompute/attested-compute.js +76 -0
  123. package/dist/esm/attestedcompute/types.d.ts +35 -0
  124. package/dist/esm/attestedcompute/types.js +42 -0
  125. package/dist/esm/attesteddecrypt/attested-decrypt.d.ts +61 -0
  126. package/dist/esm/attesteddecrypt/attested-decrypt.js +112 -0
  127. package/dist/esm/attesteddecrypt/index.d.ts +1 -0
  128. package/dist/esm/attesteddecrypt/index.js +2 -0
  129. package/dist/esm/attesteddecrypt/types.d.ts +27 -0
  130. package/dist/esm/attesteddecrypt/types.js +12 -0
  131. package/dist/esm/attestedreveal/attested-reveal.d.ts +21 -0
  132. package/dist/esm/attestedreveal/attested-reveal.js +28 -0
  133. package/dist/esm/attestedreveal/index.d.ts +2 -0
  134. package/dist/esm/attestedreveal/index.js +3 -0
  135. package/dist/esm/attestedreveal/types.d.ts +4 -0
  136. package/dist/esm/attestedreveal/types.js +9 -0
  137. package/dist/esm/binary.d.ts +104 -0
  138. package/dist/esm/binary.js +155 -0
  139. package/dist/esm/chain.d.ts +50 -0
  140. package/dist/esm/chain.js +58 -0
  141. package/dist/esm/eip712/eip712.d.ts +18 -0
  142. package/dist/esm/eip712/eip712.js +46 -0
  143. package/dist/esm/eip712/index.d.ts +1 -0
  144. package/dist/esm/eip712/index.js +2 -0
  145. package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
  146. package/dist/esm/elistattesteddecrypt/elist-attested-decrypt.js +89 -0
  147. package/dist/esm/elistattesteddecrypt/index.d.ts +2 -0
  148. package/dist/esm/elistattesteddecrypt/index.js +3 -0
  149. package/dist/esm/elistattesteddecrypt/types.d.ts +31 -0
  150. package/dist/esm/elistattesteddecrypt/types.js +12 -0
  151. package/dist/esm/encryption/encryption.d.ts +235 -0
  152. package/dist/esm/encryption/encryption.js +214 -0
  153. package/dist/esm/encryption/index.d.ts +1 -0
  154. package/dist/esm/encryption/index.js +2 -0
  155. package/dist/esm/generated/abis/add-two.d.ts +117 -0
  156. package/dist/esm/generated/abis/add-two.js +77 -0
  157. package/dist/esm/generated/abis/lightning.d.ts +3362 -0
  158. package/dist/esm/generated/abis/lightning.js +2442 -0
  159. package/dist/esm/generated/abis/test-elist.d.ts +276 -0
  160. package/dist/esm/generated/abis/test-elist.js +165 -0
  161. package/dist/esm/generated/abis/verifier.d.ts +1353 -0
  162. package/dist/esm/generated/abis/verifier.js +951 -0
  163. package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
  164. package/dist/esm/generated/es/inco/covalidator/compute/v1/server_pb.js +392 -0
  165. package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
  166. package/dist/esm/generated/es/inco/covalidator/compute/v1/types_pb.js +77 -0
  167. package/dist/esm/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
  168. package/dist/esm/generated/es/inco/helioswrapper/v1/helioswrapper_pb.js +25 -0
  169. package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
  170. package/dist/esm/generated/es/inco/kms/lite/v1/kms_service_pb.js +97 -0
  171. package/dist/esm/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
  172. package/dist/esm/generated/es/inco/kms/lite/v1/types_pb.js +133 -0
  173. package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
  174. package/dist/esm/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.js +85 -0
  175. package/dist/esm/generated/lightning.d.ts +830 -0
  176. package/dist/esm/generated/lightning.js +869 -0
  177. package/dist/esm/generated/local-node.d.ts +50 -0
  178. package/dist/esm/generated/local-node.js +104 -0
  179. package/dist/esm/handle.d.ts +123 -0
  180. package/dist/esm/handle.js +212 -0
  181. package/dist/esm/index.d.ts +5 -0
  182. package/dist/esm/index.js +6 -0
  183. package/dist/esm/kms/client.d.ts +12 -0
  184. package/dist/esm/kms/client.js +40 -0
  185. package/dist/esm/kms/quorumClient.d.ts +65 -0
  186. package/dist/esm/kms/quorumClient.js +459 -0
  187. package/dist/esm/kms/quorumConsistency.d.ts +82 -0
  188. package/dist/esm/kms/quorumConsistency.js +260 -0
  189. package/dist/esm/kms/signatureVerification.d.ts +35 -0
  190. package/dist/esm/kms/signatureVerification.js +84 -0
  191. package/dist/esm/kms/thresholdPromises.d.ts +8 -0
  192. package/dist/esm/kms/thresholdPromises.js +59 -0
  193. package/dist/esm/lite/attested-compute.d.ts +6 -0
  194. package/dist/esm/lite/attested-compute.js +4 -0
  195. package/dist/esm/lite/attested-decrypt.d.ts +4 -0
  196. package/dist/esm/lite/attested-decrypt.js +3 -0
  197. package/dist/esm/lite/deployments.d.ts +24 -0
  198. package/dist/esm/lite/deployments.js +17 -0
  199. package/dist/esm/lite/hadu.d.ts +4 -0
  200. package/dist/esm/lite/hadu.js +24 -0
  201. package/dist/esm/lite/index.d.ts +13 -0
  202. package/dist/esm/lite/index.js +10 -0
  203. package/dist/esm/lite/lightning.d.ts +459 -0
  204. package/dist/esm/lite/lightning.js +692 -0
  205. package/dist/esm/lite/types.d.ts +47 -0
  206. package/dist/esm/lite/types.js +2 -0
  207. package/dist/esm/lite/xwing.d.ts +154 -0
  208. package/dist/esm/lite/xwing.js +311 -0
  209. package/dist/esm/local/index.d.ts +1 -0
  210. package/dist/esm/local/index.js +2 -0
  211. package/dist/esm/local/local-node.d.ts +37 -0
  212. package/dist/esm/local/local-node.js +76 -0
  213. package/dist/esm/reencryption/eip712.d.ts +56 -0
  214. package/dist/esm/reencryption/eip712.js +87 -0
  215. package/dist/esm/reencryption/index.d.ts +2 -0
  216. package/dist/esm/reencryption/index.js +3 -0
  217. package/dist/esm/reencryption/types.d.ts +48 -0
  218. package/dist/esm/reencryption/types.js +2 -0
  219. package/dist/esm/retry.d.ts +30 -0
  220. package/dist/esm/retry.js +82 -0
  221. package/dist/esm/schema.d.ts +4 -0
  222. package/dist/esm/schema.js +15 -0
  223. package/dist/esm/test/mocks.d.ts +20 -0
  224. package/dist/esm/test/mocks.js +64 -0
  225. package/dist/esm/viem.d.ts +1141 -0
  226. package/dist/esm/viem.js +32 -0
  227. package/dist/types/advancedacl/index.d.ts +2 -0
  228. package/dist/types/advancedacl/session-key.d.ts +95 -0
  229. package/dist/types/advancedacl/types.d.ts +16 -0
  230. package/dist/types/attestedcompute/attested-compute.d.ts +65 -0
  231. package/dist/types/attestedcompute/types.d.ts +35 -0
  232. package/dist/types/attesteddecrypt/attested-decrypt.d.ts +61 -0
  233. package/dist/types/attesteddecrypt/index.d.ts +1 -0
  234. package/dist/types/attesteddecrypt/types.d.ts +27 -0
  235. package/dist/types/attestedreveal/attested-reveal.d.ts +21 -0
  236. package/dist/types/attestedreveal/index.d.ts +2 -0
  237. package/dist/types/attestedreveal/types.d.ts +4 -0
  238. package/dist/types/binary.d.ts +104 -0
  239. package/dist/types/chain.d.ts +50 -0
  240. package/dist/types/eip712/eip712.d.ts +18 -0
  241. package/dist/types/eip712/index.d.ts +1 -0
  242. package/dist/types/elistattesteddecrypt/elist-attested-decrypt.d.ts +51 -0
  243. package/dist/types/elistattesteddecrypt/index.d.ts +2 -0
  244. package/dist/types/elistattesteddecrypt/types.d.ts +31 -0
  245. package/dist/types/encryption/encryption.d.ts +235 -0
  246. package/dist/types/encryption/index.d.ts +1 -0
  247. package/dist/types/generated/abis/add-two.d.ts +117 -0
  248. package/dist/types/generated/abis/lightning.d.ts +3362 -0
  249. package/dist/types/generated/abis/test-elist.d.ts +276 -0
  250. package/dist/types/generated/abis/verifier.d.ts +1353 -0
  251. package/dist/types/generated/es/inco/covalidator/compute/v1/server_pb.d.ts +1494 -0
  252. package/dist/types/generated/es/inco/covalidator/compute/v1/types_pb.d.ts +247 -0
  253. package/dist/types/generated/es/inco/helioswrapper/v1/helioswrapper_pb.d.ts +77 -0
  254. package/dist/types/generated/es/inco/kms/lite/v1/kms_service_pb.d.ts +685 -0
  255. package/dist/types/generated/es/inco/kms/lite/v1/types_pb.d.ts +289 -0
  256. package/dist/types/generated/es/inco/sealingfetcher/v1/sealingfetcher_pb.d.ts +371 -0
  257. package/dist/types/generated/lightning.d.ts +830 -0
  258. package/dist/types/generated/local-node.d.ts +50 -0
  259. package/dist/types/handle.d.ts +123 -0
  260. package/dist/types/index.d.ts +5 -0
  261. package/dist/types/kms/client.d.ts +12 -0
  262. package/dist/types/kms/quorumClient.d.ts +65 -0
  263. package/dist/types/kms/quorumConsistency.d.ts +82 -0
  264. package/dist/types/kms/signatureVerification.d.ts +35 -0
  265. package/dist/types/kms/thresholdPromises.d.ts +8 -0
  266. package/dist/types/lite/attested-compute.d.ts +6 -0
  267. package/dist/types/lite/attested-decrypt.d.ts +4 -0
  268. package/dist/types/lite/deployments.d.ts +24 -0
  269. package/dist/types/lite/hadu.d.ts +4 -0
  270. package/dist/types/lite/index.d.ts +13 -0
  271. package/dist/types/lite/lightning.d.ts +459 -0
  272. package/dist/types/lite/types.d.ts +47 -0
  273. package/dist/types/lite/xwing.d.ts +154 -0
  274. package/dist/types/local/index.d.ts +1 -0
  275. package/dist/types/local/local-node.d.ts +37 -0
  276. package/dist/types/reencryption/eip712.d.ts +56 -0
  277. package/dist/types/reencryption/index.d.ts +2 -0
  278. package/dist/types/reencryption/types.d.ts +48 -0
  279. package/dist/types/retry.d.ts +30 -0
  280. package/dist/types/schema.d.ts +4 -0
  281. package/dist/types/test/mocks.d.ts +20 -0
  282. package/dist/types/viem.d.ts +1141 -0
  283. package/package.json +129 -0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ATTESTED_COMPUTE_DOMAIN_NAME = void 0;
4
+ exports.attestedCompute = attestedCompute;
5
+ const protobuf_1 = require("@bufbuild/protobuf");
6
+ const viem_1 = require("viem");
7
+ const attested_decrypt_js_1 = require("../attesteddecrypt/attested-decrypt.js");
8
+ const binary_js_1 = require("../binary.js");
9
+ const eip712_js_1 = require("../eip712/eip712.js");
10
+ const kms_service_pb_js_1 = require("../generated/es/inco/kms/lite/v1/kms_service_pb.js");
11
+ const xwing_js_1 = require("../lite/xwing.js");
12
+ const eip712_js_2 = require("../reencryption/eip712.js");
13
+ const types_js_1 = require("./types.js");
14
+ exports.ATTESTED_COMPUTE_DOMAIN_NAME = 'IncoAttestedCompute';
15
+ async function attestedCompute({ executorAddress, lhsHandle, op, rhsPlaintext, backoffConfig, walletClient, kmsQuorumClient, chainId, reencryptPubKey, reencryptKeypair, }) {
16
+ try {
17
+ (0, attested_decrypt_js_1.validateHandle)(lhsHandle);
18
+ if (reencryptPubKey &&
19
+ reencryptKeypair &&
20
+ !(0, xwing_js_1.reencryptPublicKeysMatch)(reencryptPubKey, reencryptKeypair)) {
21
+ throw new types_js_1.AttestedComputeError('reencryptPubKey does not match reencryptKeypair public key');
22
+ }
23
+ const rhsPlaintextBig = typeof rhsPlaintext === 'boolean'
24
+ ? rhsPlaintext
25
+ ? 1n
26
+ : 0n
27
+ : BigInt(rhsPlaintext);
28
+ const eip712DomainVersion = await (0, eip712_js_1.fetchEip712DomainVersion)(executorAddress, walletClient);
29
+ // Create the EIP712 payload for the handles to decrypt
30
+ const eip712Payload = (0, eip712_js_2.createEIP712Payload)({
31
+ chainId: BigInt(chainId),
32
+ primaryType: 'AttestedComputeRequest',
33
+ primaryTypeFields: [
34
+ { name: 'op', type: 'uint8' },
35
+ { name: 'lhsHandle', type: 'bytes32' },
36
+ { name: 'rhsPlaintext', type: 'bytes32' },
37
+ { name: 'publicKey', type: 'bytes' },
38
+ ],
39
+ message: {
40
+ op: op,
41
+ lhsHandle: lhsHandle,
42
+ rhsPlaintext: (0, binary_js_1.bigintToBytes32)(rhsPlaintextBig),
43
+ publicKey: (0, viem_1.bytesToHex)(reencryptPubKey ? reencryptPubKey : new Uint8Array()),
44
+ },
45
+ domainName: exports.ATTESTED_COMPUTE_DOMAIN_NAME,
46
+ domainVersion: eip712DomainVersion,
47
+ });
48
+ // Sign the EIP712 message
49
+ const eip712Signature = await walletClient.signTypedData(eip712Payload);
50
+ const attestedComputeRequest = (0, protobuf_1.create)(kms_service_pb_js_1.AttestedComputeRequestSchema, {
51
+ userAddress: walletClient.account.address,
52
+ reencryptPubKey: reencryptPubKey ? reencryptPubKey : new Uint8Array(),
53
+ op: op,
54
+ lhsHandle: lhsHandle,
55
+ rhsPlaintext: rhsPlaintextBig.toString(16),
56
+ eip712Signature: (0, viem_1.hexToBytes)(eip712Signature),
57
+ aclProof: {
58
+ proof: {
59
+ case: 'incoLiteBasicAclProof',
60
+ value: {},
61
+ },
62
+ },
63
+ });
64
+ // Envelope signatures are verified against the on-chain authorized signer set
65
+ let decryptionAttestation = await kmsQuorumClient.attestedCompute(attestedComputeRequest, executorAddress, walletClient, backoffConfig, reencryptKeypair);
66
+ // Decrypt encrypted attestations and verify inner DecryptionAttestation signatures
67
+ if (reencryptPubKey && reencryptKeypair) {
68
+ const [decryptedAttestation] = await (0, attested_decrypt_js_1.decryptEncryptedAttestations)([decryptionAttestation], reencryptKeypair);
69
+ return decryptedAttestation;
70
+ }
71
+ return decryptionAttestation;
72
+ }
73
+ catch (error) {
74
+ if (error instanceof types_js_1.AttestedComputeError) {
75
+ throw error;
76
+ }
77
+ throw new types_js_1.AttestedComputeError('Failed to perform attested compute', error);
78
+ }
79
+ }
80
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWQtY29tcHV0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hdHRlc3RlZGNvbXB1dGUvYXR0ZXN0ZWQtY29tcHV0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUEwSEEsMENBeUhDO0FBblBELGlEQUE0QztBQUU1QywrQkFBOEM7QUFDOUMsZ0ZBR2dEO0FBS2hELDRDQUEwRDtBQUUxRCxtREFBK0Q7QUFLL0QsMEZBRzREO0FBRTVELCtDQUErRTtBQUMvRSx5REFBZ0U7QUFFaEUseUNBQXFFO0FBRXhELFFBQUEsNEJBQTRCLEdBQUcscUJBQXFCLENBQUM7QUE4RjNELEtBQUssVUFBVSxlQUFlLENBQTZCLEVBQ2hFLGVBQWUsRUFDZixTQUFTLEVBQ1QsRUFBRSxFQUNGLFlBQVksRUFDWixhQUFhLEVBQ2IsWUFBWSxFQUNaLGVBQWUsRUFDZixPQUFPLEVBQ1AsZUFBZSxFQUNmLGdCQUFnQixHQVlqQjtJQUlDLElBQUksQ0FBQztRQUNILElBQUEsb0NBQWMsRUFBQyxTQUFTLENBQUMsQ0FBQztRQUUxQixJQUNFLGVBQWU7WUFDZixnQkFBZ0I7WUFDaEIsQ0FBQyx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sRUFBRSxDQUFDO1lBQ3hDLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxHQUFHLE1BQU0sSUFBQSxrREFBNEIsRUFDL0QsQ0FBQyxxQkFBcUIsQ0FBQyxFQUN2QixnQkFBZ0IsQ0FDakIsQ0FBQztZQUNGLE9BQU8sb0JBQWtFLENBQUM7UUFDNUUsQ0FBQztRQUVELE9BQU8scUJBRWdELENBQUM7SUFDMUQsQ0FBQztJQUFDLE9BQU8sS0FBSyxFQUFFLENBQUM7UUFDZixJQUFJLEtBQUssWUFBWSwrQkFBb0IsRUFBRSxDQUFDO1lBQzFDLE1BQU0sS0FBSyxDQUFDO1FBQ2QsQ0FBQztRQUNELE1BQU0sSUFBSSwrQkFBb0IsQ0FBQyxvQ0FBb0MsRUFBRSxLQUFLLENBQUMsQ0FBQztJQUM5RSxDQUFDO0FBQ0gsQ0FBQyJ9
@@ -0,0 +1,35 @@
1
+ import type { DecryptionAttestation } from '../attesteddecrypt/types.js';
2
+ import { HexString } from '../binary.js';
3
+ import { EncryptionScheme, SupportedTeeType } from '../encryption/encryption.js';
4
+ import { SupportedScalarBinaryOp } from '../generated/es/inco/kms/lite/v1/types_pb.js';
5
+ import type { BackoffConfig } from '../retry.js';
6
+ /**
7
+ * Supported attested compute operations.
8
+ */
9
+ export declare const AttestedComputeSupportedOps: {
10
+ readonly Eq: SupportedScalarBinaryOp.TEE_EQ;
11
+ readonly Ne: SupportedScalarBinaryOp.TEE_NE;
12
+ readonly Ge: SupportedScalarBinaryOp.TEE_GE;
13
+ readonly Gt: SupportedScalarBinaryOp.TEE_GT;
14
+ readonly Le: SupportedScalarBinaryOp.TEE_LE;
15
+ readonly Lt: SupportedScalarBinaryOp.TEE_LT;
16
+ };
17
+ /**
18
+ * This type represents all the supported operations for attested compute.
19
+ */
20
+ export type AttestedComputeOP = (typeof AttestedComputeSupportedOps)[keyof typeof AttestedComputeSupportedOps];
21
+ /**
22
+ * Custom error class for attested compute operations.
23
+ */
24
+ export declare class AttestedComputeError extends Error {
25
+ readonly cause?: unknown | undefined;
26
+ constructor(message: string, cause?: unknown | undefined);
27
+ }
28
+ export type AttestedCompute<S extends EncryptionScheme> = <T extends SupportedTeeType>(args: AttestedComputeFnArgs<S, T>) => Promise<DecryptionAttestation<S, T>>;
29
+ export type AttestedComputeFnArgs<S extends EncryptionScheme, T extends SupportedTeeType> = {
30
+ /** The handle to compute on */
31
+ lhsHandle: HexString;
32
+ op: AttestedComputeOP;
33
+ rhsPlaintext: bigint | boolean;
34
+ backoffConfig?: Partial<BackoffConfig>;
35
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttestedComputeError = exports.AttestedComputeSupportedOps = void 0;
4
+ const types_pb_js_1 = require("../generated/es/inco/kms/lite/v1/types_pb.js");
5
+ /**
6
+ * Supported attested compute operations.
7
+ */
8
+ exports.AttestedComputeSupportedOps = {
9
+ /*
10
+ Add: SupportedScalarBinaryOp.TEE_ADD,
11
+ Sub: SupportedScalarBinaryOp.TEE_SUB,
12
+ Mul: SupportedScalarBinaryOp.TEE_MUL,
13
+ Div: SupportedScalarBinaryOp.TEE_DIV,
14
+ Rem: SupportedScalarBinaryOp.TEE_REM,
15
+ BitAnd: SupportedScalarBinaryOp.TEE_BIT_AND,
16
+ BitOr: SupportedScalarBinaryOp.TEE_BIT_OR,
17
+ BitXor: SupportedScalarBinaryOp.TEE_BIT_XOR,
18
+ Shl: SupportedScalarBinaryOp.TEE_SHL,
19
+ Shr: SupportedScalarBinaryOp.TEE_SHR,
20
+ Rotl: SupportedScalarBinaryOp.TEE_ROTL,
21
+ Rotr: SupportedScalarBinaryOp.TEE_ROTR,
22
+ */
23
+ Eq: types_pb_js_1.SupportedScalarBinaryOp.TEE_EQ,
24
+ Ne: types_pb_js_1.SupportedScalarBinaryOp.TEE_NE,
25
+ Ge: types_pb_js_1.SupportedScalarBinaryOp.TEE_GE,
26
+ Gt: types_pb_js_1.SupportedScalarBinaryOp.TEE_GT,
27
+ Le: types_pb_js_1.SupportedScalarBinaryOp.TEE_LE,
28
+ Lt: types_pb_js_1.SupportedScalarBinaryOp.TEE_LT,
29
+ /*
30
+ Min: SupportedScalarBinaryOp.TEE_MIN,
31
+ Max: SupportedScalarBinaryOp.TEE_MAX,
32
+ */
33
+ };
34
+ /**
35
+ * Custom error class for attested compute operations.
36
+ */
37
+ class AttestedComputeError extends Error {
38
+ cause;
39
+ constructor(message, cause) {
40
+ super(message);
41
+ this.cause = cause;
42
+ this.name = 'AttestedComputeError';
43
+ }
44
+ }
45
+ exports.AttestedComputeError = AttestedComputeError;
46
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRjb21wdXRlL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQU1BLDhFQUF1RjtBQUd2Rjs7R0FFRztBQUNVLFFBQUEsMkJBQTJCLEdBQUc7SUFDekM7Ozs7Ozs7Ozs7Ozs7TUFhRTtJQUNGLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDLEVBQUUsRUFBRSxxQ0FBdUIsQ0FBQyxNQUFNO0lBQ2xDOzs7TUFHRTtDQUNNLENBQUM7QUFRWDs7R0FFRztBQUNILE1BQWEsb0JBQXFCLFNBQVEsS0FBSztJQUczQjtJQUZsQixZQUNFLE9BQWUsRUFDQyxLQUFlO1FBRS9CLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUZDLFVBQUssR0FBTCxLQUFLLENBQVU7UUFHL0IsSUFBSSxDQUFDLElBQUksR0FBRyxzQkFBc0IsQ0FBQztJQUNyQyxDQUFDO0NBQ0Y7QUFSRCxvREFRQyJ9
@@ -0,0 +1,61 @@
1
+ import type { Account, Chain, Transport, WalletClient } from 'viem';
2
+ import { type HexString } from '../binary.js';
3
+ import { type SupportedChainId } from '../chain.js';
4
+ import { EncryptionScheme, type SupportedTeeType } from '../encryption/encryption.js';
5
+ import { type HandleWithProof } from '../generated/es/inco/kms/lite/v1/types_pb.js';
6
+ import { validateHandle } from '../handle.js';
7
+ import { KmsQuorumClient } from '../kms/quorumClient.js';
8
+ import type { XwingKeypair } from '../lite/xwing.js';
9
+ import type { BackoffConfig } from '../retry.js';
10
+ import { type DecryptionAttestation, type EncryptedDecryptionAttestation } from './types.js';
11
+ export { validateHandle };
12
+ export declare const ATTESTED_DECRYPT_DOMAIN_NAME = "IncoAttestedDecrypt";
13
+ /**
14
+ * Arguments for creating an attested decrypt request.
15
+ */
16
+ export interface IncoLiteAttestedDecryptorArgs {
17
+ /** The wallet used to interact with the blockchain and sign the decrypt request */
18
+ walletClient: WalletClient<Transport, Chain, Account>;
19
+ /** The KMS quorum client instance */
20
+ kmsQuorumClient: KmsQuorumClient;
21
+ /** The chain ID to use */
22
+ chainId: SupportedChainId;
23
+ }
24
+ /**
25
+ * Decrypt multiple handles in a single attested request.
26
+ * Returns an array of attestations aligned with the response ordering.
27
+ *
28
+ * @param args - The arguments for creating the attested decrypt function
29
+ * @returns A function that can decrypt handles and return an attestation
30
+ * @throws {AttestedDecryptError} If the creation fails
31
+ */
32
+ export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, executorAddress, }: {
33
+ handles: HexString[];
34
+ backoffConfig?: Partial<BackoffConfig> | undefined;
35
+ walletClient: WalletClient<Transport, Chain, Account>;
36
+ chainId: SupportedChainId;
37
+ reencryptPubKey: Uint8Array;
38
+ reencryptKeypair: XwingKeypair;
39
+ kmsQuorumClient: KmsQuorumClient;
40
+ executorAddress: HexString;
41
+ }): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
42
+ /**
43
+ * Decrypt multiple handles in a single attested request.
44
+ * Returns an array of attestations aligned with the response ordering.
45
+ *
46
+ * @param args - The arguments for creating the attested decrypt function
47
+ * @returns A function that can decrypt handles and return an attestation
48
+ * @throws {AttestedDecryptError} If the creation fails
49
+ */
50
+ export declare function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, kmsQuorumClient, executorAddress, }: {
51
+ handles: HexString[];
52
+ backoffConfig?: Partial<BackoffConfig> | undefined;
53
+ walletClient: WalletClient<Transport, Chain, Account>;
54
+ chainId: SupportedChainId;
55
+ reencryptPubKey: Uint8Array;
56
+ reencryptKeypair?: never;
57
+ kmsQuorumClient: KmsQuorumClient;
58
+ executorAddress: HexString;
59
+ }): Promise<Array<EncryptedDecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
60
+ export declare function buildHandlesWithProofs(handles: HexString[]): Array<HandleWithProof>;
61
+ export declare function decryptEncryptedAttestations(attestations: Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType> | EncryptedDecryptionAttestation<EncryptionScheme, SupportedTeeType>>, reencryptKeypair: XwingKeypair): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ATTESTED_DECRYPT_DOMAIN_NAME = exports.validateHandle = void 0;
4
+ exports.attestedDecrypt = attestedDecrypt;
5
+ exports.buildHandlesWithProofs = buildHandlesWithProofs;
6
+ exports.decryptEncryptedAttestations = decryptEncryptedAttestations;
7
+ const protobuf_1 = require("@bufbuild/protobuf");
8
+ const viem_1 = require("viem");
9
+ const binary_js_1 = require("../binary.js");
10
+ const eip712_js_1 = require("../eip712/eip712.js");
11
+ const encryption_js_1 = require("../encryption/encryption.js");
12
+ const kms_service_pb_js_1 = require("../generated/es/inco/kms/lite/v1/kms_service_pb.js");
13
+ const types_pb_js_1 = require("../generated/es/inco/kms/lite/v1/types_pb.js");
14
+ const handle_js_1 = require("../handle.js");
15
+ Object.defineProperty(exports, "validateHandle", { enumerable: true, get: function () { return handle_js_1.validateHandle; } });
16
+ const xwing_js_1 = require("../lite/xwing.js");
17
+ const types_js_1 = require("./types.js");
18
+ exports.ATTESTED_DECRYPT_DOMAIN_NAME = 'IncoAttestedDecrypt';
19
+ /**
20
+ * Decrypt multiple handles in a single attested request.
21
+ * Returns an array of attestations aligned with the response ordering.
22
+ *
23
+ * @param args - The arguments for creating the attested decrypt function
24
+ * @returns A function that can decrypt handles and return an attestation
25
+ * @throws {AttestedDecryptError} If the creation fails
26
+ */
27
+ async function attestedDecrypt({ handles, backoffConfig, walletClient, chainId, reencryptPubKey, reencryptKeypair, kmsQuorumClient, executorAddress, }) {
28
+ try {
29
+ handles.forEach(handle_js_1.validateHandle);
30
+ if (!reencryptPubKey) {
31
+ throw new types_js_1.AttestedDecryptError('Reencrypt public key is required');
32
+ }
33
+ if (reencryptKeypair &&
34
+ !(0, xwing_js_1.reencryptPublicKeysMatch)(reencryptPubKey, reencryptKeypair)) {
35
+ throw new types_js_1.AttestedDecryptError('reencryptPubKey does not match reencryptKeypair public key');
36
+ }
37
+ const eip712Payload = await (0, eip712_js_1.buildEip712Payload)({
38
+ executorAddress,
39
+ ethClient: walletClient,
40
+ chainId,
41
+ handles,
42
+ reencryptPubKey,
43
+ });
44
+ const eip712SignatureHex = await (0, eip712_js_1.signEip712)(walletClient, eip712Payload);
45
+ const handlesWithProofs = buildHandlesWithProofs(handles);
46
+ const attestedDecryptRequest = buildAttestedDecryptRequest({
47
+ userAddress: walletClient.account.address,
48
+ handlesWithProofs,
49
+ eip712Signature: (0, viem_1.hexToBytes)(eip712SignatureHex),
50
+ reencryptPubKey,
51
+ });
52
+ // Call quorum client which returns aggregated attestations directly
53
+ // The quorum client handles retry logic internally for each KMS client
54
+ // Envelope signatures are verified against the on-chain authorized signer set
55
+ const response = await kmsQuorumClient.attestedDecrypt(attestedDecryptRequest, executorAddress, walletClient, backoffConfig, reencryptKeypair);
56
+ // If reencryptPubKey is provided with a keypair, decrypt the encrypted attestations
57
+ // and verify the inner DecryptionAttestation signatures
58
+ if (reencryptPubKey !== undefined && reencryptKeypair) {
59
+ return decryptEncryptedAttestations(response, reencryptKeypair);
60
+ }
61
+ return response;
62
+ }
63
+ catch (error) {
64
+ if (error instanceof types_js_1.AttestedDecryptError) {
65
+ throw error;
66
+ }
67
+ throw new types_js_1.AttestedDecryptError('Failed to decrypt handles', error);
68
+ }
69
+ }
70
+ function buildHandlesWithProofs(handles) {
71
+ return handles.map((handle) => {
72
+ return (0, protobuf_1.create)(types_pb_js_1.HandleWithProofSchema, {
73
+ handle: handle,
74
+ aclProof: {
75
+ proof: {
76
+ case: 'incoLiteBasicAclProof',
77
+ value: {},
78
+ },
79
+ },
80
+ });
81
+ });
82
+ }
83
+ function buildAttestedDecryptRequest(params) {
84
+ return (0, protobuf_1.create)(kms_service_pb_js_1.AttestedDecryptRequestSchema, {
85
+ userAddress: params.userAddress,
86
+ handlesWithProofs: params.handlesWithProofs,
87
+ eip712Signature: params.eip712Signature,
88
+ reencryptPubKey: params.reencryptPubKey ?? new Uint8Array(),
89
+ });
90
+ }
91
+ async function decryptEncryptedAttestations(attestations, reencryptKeypair) {
92
+ return Promise.all(attestations.map(async (att) => {
93
+ // If already a plaintext attestation, return as-is
94
+ if ('plaintext' in att && att.plaintext !== undefined) {
95
+ return att;
96
+ }
97
+ // Otherwise, decrypt the encrypted attestation
98
+ if ('encryptedPlaintext' in att && att.encryptedPlaintext !== undefined) {
99
+ const encryptedAtt = att;
100
+ const ct = (0, viem_1.hexToBytes)(encryptedAtt.encryptedPlaintext.ciphertext.value);
101
+ const plaintextBytes = await (0, xwing_js_1.decrypt)(reencryptKeypair, ct);
102
+ const bigIntValue = (0, binary_js_1.bytesToBigInt)(plaintextBytes);
103
+ const handleType = (0, handle_js_1.getHandleType)(encryptedAtt.handle);
104
+ // Decrypt the encrypted signatures (which are signatures for the original plaintext)
105
+ // The covalidatorSignatures are for the reencryption struct, not the plaintext
106
+ const decryptedSignatures = await Promise.all(encryptedAtt.encryptedSignatures.map(async (encryptedSig) => {
107
+ return await (0, xwing_js_1.decrypt)(reencryptKeypair, encryptedSig);
108
+ }));
109
+ return {
110
+ handle: encryptedAtt.handle,
111
+ plaintext: (0, encryption_js_1.bigintToPlaintext)(encryption_js_1.encryptionSchemes.xwing, handleType, bigIntValue),
112
+ covalidatorSignatures: decryptedSignatures,
113
+ };
114
+ }
115
+ throw new types_js_1.AttestedDecryptError('Attestation is neither plaintext nor encrypted');
116
+ }));
117
+ }
118
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWQtZGVjcnlwdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hdHRlc3RlZGRlY3J5cHQvYXR0ZXN0ZWQtZGVjcnlwdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFpSEEsMENBbUZDO0FBRUQsd0RBY0M7QUFnQkQsb0VBa0RDO0FBdFJELGlEQUE0QztBQUU1QywrQkFBa0M7QUFDbEMsNENBQTZEO0FBRTdELG1EQUFxRTtBQUNyRSwrREFLcUM7QUFDckMsMEZBRzREO0FBQzVELDhFQUdzRDtBQUN0RCw0Q0FBNkQ7QUFVcEQsK0ZBVmUsMEJBQWMsT0FVZjtBQVB2QiwrQ0FBcUU7QUFFckUseUNBSW9CO0FBR1AsUUFBQSw0QkFBNEIsR0FBRyxxQkFBcUIsQ0FBQztBQXlFbEU7Ozs7Ozs7R0FPRztBQUNJLEtBQUssVUFBVSxlQUFlLENBQUMsRUFDcEMsT0FBTyxFQUNQL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0FBQyxDQUFDO1lBRXRELHFGQUFxRjtZQUNyRiwrRUFBK0U7WUFDL0UsTUFBTSxtQkFBbUIsR0FBRyxNQUFNLE9BQU8sQ0FBQyxHQUFHLENBQzNDLFlBQVksQ0FBQyxtQkFBbUIsQ0FBQyxHQUFHLENBQUMsS0FBSyxFQUFFLFlBQVksRUFBRSxFQUFFO2dCQUMxRCxPQUFPLE1BQU0sSUFBQSxrQkFBTyxFQUFDLGdCQUFnQixFQUFFLFlBQVksQ0FBQyxDQUFDO1lBQ3ZELENBQUMsQ0FBQyxDQUNILENBQUM7WUFFRixPQUFPO2dCQUNMLE1BQU0sRUFBRSxZQUFZLENBQUMsTUFBTTtnQkFDM0IsU0FBUyxFQUFFLElBQUEsaUNBQWlCLEVBQzFCLGlDQUFpQixDQUFDLEtBQUssRUFDdkIsVUFBOEIsRUFDOUIsV0FBVyxDQUNaO2dCQUNELHFCQUFxQixFQUFFLG1CQUFtQjthQUNrQixDQUFDO1FBQ2pFLENBQUM7UUFFRCxNQUFNLElBQUksK0JBQW9CLENBQzVCLGdEQUFnRCxDQUNqRCxDQUFDO0lBQ0osQ0FBQyxDQUFDLENBQ0gsQ0FBQztBQUNKLENBQUMifQ==
@@ -0,0 +1 @@
1
+ export * from './types.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types.js"), exports);
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRkZWNyeXB0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSw2Q0FBMkIifQ==
@@ -0,0 +1,27 @@
1
+ import type { HexString } from '../binary.js';
2
+ import type { EncryptionScheme, EncryptResultOf, PlaintextOf, SupportedTeeType } from '../encryption/encryption.js';
3
+ import type { BackoffConfig } from '../retry.js';
4
+ /**
5
+ * Custom error class for attested decrypt operations.
6
+ */
7
+ export declare class AttestedDecryptError extends Error {
8
+ readonly cause?: unknown | undefined;
9
+ constructor(message: string, cause?: unknown | undefined);
10
+ }
11
+ export type DecryptionAttestation<S extends EncryptionScheme, T extends SupportedTeeType> = {
12
+ handle: HexString;
13
+ plaintext: PlaintextOf<S, T>;
14
+ covalidatorSignatures: Uint8Array[];
15
+ };
16
+ export type EncryptedDecryptionAttestation<S extends EncryptionScheme, T extends SupportedTeeType> = {
17
+ handle: HexString;
18
+ encryptedPlaintext: EncryptResultOf<S, T>;
19
+ encryptedSignatures: Uint8Array[];
20
+ covalidatorSignatures: Uint8Array[];
21
+ };
22
+ export type AttestedDecryptor<S extends EncryptionScheme> = <T extends SupportedTeeType>(args: AttestedDecryptFnArgs<S, T>) => Promise<DecryptionAttestation<S, T>>;
23
+ export type AttestedDecryptFnArgs<S extends EncryptionScheme, T extends SupportedTeeType> = {
24
+ /** The handle to decrypt */
25
+ handle: HexString;
26
+ backoffConfig?: Partial<BackoffConfig>;
27
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttestedDecryptError = void 0;
4
+ /**
5
+ * Custom error class for attested decrypt operations.
6
+ */
7
+ class AttestedDecryptError extends Error {
8
+ cause;
9
+ constructor(message, cause) {
10
+ super(message);
11
+ this.cause = cause;
12
+ this.name = 'AttestedDecryptError';
13
+ }
14
+ }
15
+ exports.AttestedDecryptError = AttestedDecryptError;
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRkZWNyeXB0L3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQVNBOztHQUVHO0FBQ0gsTUFBYSxvQkFBcUIsU0FBUSxLQUFLO0lBRzNCO0lBRmxCLFlBQ0UsT0FBZSxFQUNDLEtBQWU7UUFFL0IsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBRkMsVUFBSyxHQUFMLEtBQUssQ0FBVTtRQUcvQixJQUFJLENBQUMsSUFBSSxHQUFHLHNCQUFzQixDQUFDO0lBQ3JDLENBQUM7Q0FDRjtBQVJELG9EQVFDIn0=
@@ -0,0 +1,21 @@
1
+ import type { Chain, PublicClient, Transport } from 'viem';
2
+ import type { DecryptionAttestation } from '../attesteddecrypt/types.js';
3
+ import type { HexString } from '../binary.js';
4
+ import type { EncryptionScheme, SupportedTeeType } from '../encryption/encryption.js';
5
+ import type { KmsQuorumClient } from '../kms/quorumClient.js';
6
+ import type { BackoffConfig } from '../retry.js';
7
+ /**
8
+ * Reveal multiple handles in a single attested request without wallet authentication.
9
+ * Returns an array of plaintext attestations aligned with the response ordering.
10
+ *
11
+ * @param args - The arguments for the attested reveal request
12
+ * @returns An array of decryption attestations
13
+ * @throws {AttestedRevealError} If the reveal fails
14
+ */
15
+ export declare function attestedReveal({ handles, kmsQuorumClient, executorAddress, publicClient, backoffConfig, }: {
16
+ handles: HexString[];
17
+ kmsQuorumClient: KmsQuorumClient;
18
+ executorAddress: HexString;
19
+ publicClient: PublicClient<Transport, Chain>;
20
+ backoffConfig?: Partial<BackoffConfig> | undefined;
21
+ }): Promise<Array<DecryptionAttestation<EncryptionScheme, SupportedTeeType>>>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attestedReveal = attestedReveal;
4
+ const protobuf_1 = require("@bufbuild/protobuf");
5
+ const kms_service_pb_js_1 = require("../generated/es/inco/kms/lite/v1/kms_service_pb.js");
6
+ const handle_js_1 = require("../handle.js");
7
+ const types_js_1 = require("./types.js");
8
+ /**
9
+ * Reveal multiple handles in a single attested request without wallet authentication.
10
+ * Returns an array of plaintext attestations aligned with the response ordering.
11
+ *
12
+ * @param args - The arguments for the attested reveal request
13
+ * @returns An array of decryption attestations
14
+ * @throws {AttestedRevealError} If the reveal fails
15
+ */
16
+ async function attestedReveal({ handles, kmsQuorumClient, executorAddress, publicClient, backoffConfig, }) {
17
+ try {
18
+ handles.forEach(handle_js_1.validateHandle);
19
+ const attestedRevealRequest = (0, protobuf_1.create)(kms_service_pb_js_1.AttestedRevealRequestSchema, {
20
+ handles,
21
+ });
22
+ return (await kmsQuorumClient.attestedReveal(attestedRevealRequest, executorAddress, publicClient, backoffConfig));
23
+ }
24
+ catch (error) {
25
+ if (error instanceof types_js_1.AttestedRevealError) {
26
+ throw error;
27
+ }
28
+ throw new types_js_1.AttestedRevealError('Failed to reveal handles', error);
29
+ }
30
+ }
31
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWQtcmV2ZWFsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2F0dGVzdGVkcmV2ZWFsL2F0dGVzdGVkLXJldmVhbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQXNCQSx3Q0FnQ0M7QUF0REQsaURBQTRDO0FBUTVDLDBGQUFpRztBQUNqRyw0Q0FBOEM7QUFHOUMseUNBQWlEO0FBRWpEOzs7Ozs7O0dBT0c7QUFDSSxLQUFLLFVBQVUsY0FBYyxDQUFDLEVBQ25DLE9BQU8sRUFDUCxlQUFlLEVBQ2YsZUFBZSxFQUNmLFlBQVksRUFDWixhQUFhLEdBT2Q7SUFDQyxJQUFJLENBQUM7UUFDSCxPQUFPLENBQUMsT0FBTyxDQUFDLDBCQUFjLENBQUMsQ0FBQztRQUVoQyxNQUFNLHFCQUFxQixHQUFHLElBQUEsaUJBQU0sRUFBQywrQ0FBMkIsRUFBRTtZQUNoRSxPQUFPO1NBQ1IsQ0FBQyxDQUFDO1FBRUgsT0FBTyxDQUFDLE1BQU0sZUFBZSxDQUFDLGNBQWMsQ0FDMUMscUJBQXFCLEVBQ3JCLGVBQWUsRUFDZixZQUFZLEVBQ1osYUFBYSxDQUNkLENBQXFFLENBQUM7SUFDekUsQ0FBQztJQUFDLE9BQU8sS0FBSyxFQUFFLENBQUM7UUFDZixJQUFJLEtBQUssWUFBWSw4QkFBbUIsRUFBRSxDQUFDO1lBQ3pDLE1BQU0sS0FBSyxDQUFDO1FBQ2QsQ0FBQztRQUNELE1BQU0sSUFBSSw4QkFBbUIsQ0FBQywwQkFBMEIsRUFBRSxLQUFLLENBQUMsQ0FBQztJQUNuRSxDQUFDO0FBQ0gsQ0FBQyJ9
@@ -0,0 +1,2 @@
1
+ export { attestedReveal } from './attested-reveal.js';
2
+ export * from './types.js';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.attestedReveal = void 0;
18
+ var attested_reveal_js_1 = require("./attested-reveal.js");
19
+ Object.defineProperty(exports, "attestedReveal", { enumerable: true, get: function () { return attested_reveal_js_1.attestedReveal; } });
20
+ __exportStar(require("./types.js"), exports);
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRyZXZlYWwvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSwyREFBc0Q7QUFBN0Msb0hBQUEsY0FBYyxPQUFBO0FBQ3ZCLDZDQUEyQiJ9
@@ -0,0 +1,4 @@
1
+ export declare class AttestedRevealError extends Error {
2
+ readonly cause?: unknown | undefined;
3
+ constructor(message: string, cause?: unknown | undefined);
4
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttestedRevealError = void 0;
4
+ class AttestedRevealError extends Error {
5
+ cause;
6
+ constructor(message, cause) {
7
+ super(message);
8
+ this.cause = cause;
9
+ this.name = 'AttestedRevealError';
10
+ }
11
+ }
12
+ exports.AttestedRevealError = AttestedRevealError;
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXR0ZXN0ZWRyZXZlYWwvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsTUFBYSxtQkFBb0IsU0FBUSxLQUFLO0lBRzFCO0lBRmxCLFlBQ0UsT0FBZSxFQUNDLEtBQWU7UUFFL0IsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBRkMsVUFBSyxHQUFMLEtBQUssQ0FBVTtRQUcvQixJQUFJLENBQUMsSUFBSSxHQUFHLHFCQUFxQixDQUFDO0lBQ3BDLENBQUM7Q0FDRjtBQVJELGtEQVFDIn0=
@@ -0,0 +1,104 @@
1
+ import { Schema } from 'effect';
2
+ import { Hex } from 'viem';
3
+ /** Schema for a `0x`-prefixed hex string. */
4
+ export declare const HexString: Schema.TemplateLiteral<`0x${string}`>;
5
+ /** A `0x`-prefixed hex-encoded string (e.g. `"0xdeadbeef"`). */
6
+ export type HexString = typeof HexString.Type;
7
+ /** A value that can represent raw bytes — either a hex string or a `Uint8Array`. */
8
+ export type BytesIsh = string | Uint8Array;
9
+ /**
10
+ * Converts a `Uint8Array` to a `bigint`. Returns `0n` for empty arrays.
11
+ * @param byteArray - The byte array to convert.
12
+ * @returns The unsigned big-endian integer representation of the bytes.
13
+ */
14
+ export declare function bytesToBigInt(byteArray: Uint8Array): bigint;
15
+ /**
16
+ * Converts a `Buffer` to a `bigint`.
17
+ * @param buffer - The buffer to convert.
18
+ * @returns The unsigned big-endian integer representation of the buffer.
19
+ */
20
+ export declare function bufferToBigInt(buffer: Buffer): bigint;
21
+ /**
22
+ * Converts a `bigint` to a 32-byte `Buffer`, zero-padded on the left.
23
+ * @param value - The bigint to convert.
24
+ * @returns A 32-byte big-endian buffer.
25
+ * @throws If the bigint is negative or too large to fit in 32 bytes.
26
+ */
27
+ export declare function bigintToBytes(value: bigint): Buffer;
28
+ /**
29
+ * Converts a `bigint` to a {@link Bytes32} hex string, left-padded to 32 bytes.
30
+ * @param value - The bigint to convert.
31
+ * @returns A `Bytes32` hex string.
32
+ * @throws If the bigint is negative or too large to fit in 32 bytes.
33
+ */
34
+ export declare function bigintToBytes32(value: bigint): Bytes32;
35
+ /**
36
+ * Left-pads a byte array with zeros to the specified length.
37
+ * @param bs - The byte array to pad.
38
+ * @param n - The desired total length in bytes.
39
+ * @returns A new `Buffer` of length `n` with `bs` right-aligned.
40
+ * @throws If `bs` is longer than `n` (would require truncation).
41
+ */
42
+ export declare function padLeft(bs: Uint8Array, n: number): Buffer;
43
+ /**
44
+ * Parses a {@link BytesIsh} value as a 32-byte value and converts it to a `bigint`.
45
+ * @param bs - A hex string or `Uint8Array` representing exactly 32 bytes.
46
+ * @returns The `bigint` representation of the 32-byte value.
47
+ * @throws If the input is not exactly 32 bytes.
48
+ */
49
+ export declare function bytes32ToBigint(bs: BytesIsh): bigint;
50
+ /**
51
+ * Decodes a hex string into a `Buffer`. Handles both `0x`-prefixed and bare hex strings.
52
+ * @param hexString - The hex string to decode.
53
+ * @returns A `Buffer` containing the decoded bytes.
54
+ */
55
+ export declare function bytesFromHexString(hexString: string): Buffer;
56
+ /**
57
+ * Asserts that a string is a valid `0x`-prefixed hex string and narrows its type to `Hex`.
58
+ * @param value - The string to validate.
59
+ * @returns The input typed as `Hex`.
60
+ * @throws If `value` is not a valid hex string.
61
+ */
62
+ export declare function mustBeHex(value: string): Hex;
63
+ /**
64
+ * Normalises a string to a `0x`-prefixed `Hex` value, adding the prefix if missing.
65
+ * @param value - A hex string, with or without a `0x` prefix.
66
+ * @returns The `0x`-prefixed `Hex` string.
67
+ * @throws If the resulting string is not valid hex.
68
+ */
69
+ export declare function normaliseToHex(value: string): Hex;
70
+ /**
71
+ * Encodes a `Uint8Array` as a `0x`-prefixed hex string.
72
+ * @param bs - The byte array to encode.
73
+ * @returns A `Hex` string representation of the bytes.
74
+ */
75
+ export declare function bytesToHex(bs: Uint8Array): Hex;
76
+ /** Schema for a 32-byte (66-character with `0x` prefix) hex string, branded as `Bytes32`. Accepts both hex strings and `Uint8Array` inputs. */
77
+ export declare const Bytes32: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
78
+ /**
79
+ * Parses and validates a {@link BytesIsh} value as a {@link Bytes32}.
80
+ * @param x - A hex string or `Uint8Array` to parse.
81
+ * @returns A validated `Bytes32` value.
82
+ * @throws If the input is not exactly 32 bytes.
83
+ */
84
+ export declare function asBytes32(x: BytesIsh): Bytes32;
85
+ /** A branded 32-byte hex string type (`0x` + 64 hex characters). */
86
+ export type Bytes32 = typeof Bytes32.Type;
87
+ /** A branded 20-byte Ethereum address type (`0x` + 40 hex characters). */
88
+ export type Address = typeof Address.Type;
89
+ /** Schema for a 20-byte `0x`-prefixed Ethereum address, branded as `Address`. */
90
+ export declare const Address: Schema.brand<Schema.filter<Schema.TemplateLiteral<`0x${string}`>>, "Address">;
91
+ /**
92
+ * Parses and validates a string as an Ethereum {@link Address} (20-byte, `0x`-prefixed).
93
+ * @param address - The string to parse.
94
+ * @returns A validated `Address` value.
95
+ * @throws If the input is not a valid 20-byte hex address.
96
+ */
97
+ export declare function parseAddress(address: string): Address;
98
+ /**
99
+ * Parses and validates a string as a {@link HexString} (`0x`-prefixed).
100
+ * @param hex - The string to parse.
101
+ * @returns A validated `HexString` value.
102
+ * @throws If the input is not a valid `0x`-prefixed hex string.
103
+ */
104
+ export declare function parseHex(hex: string): HexString;