@primuslabs/fhetransform-sdk 0.4.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 (302) hide show
  1. package/README.md +198 -0
  2. package/dist/abis/acl.abi.d.ts +379 -0
  3. package/dist/abis/acl.abi.js +495 -0
  4. package/dist/abis/acl.abi.js.map +1 -0
  5. package/dist/abis/alphatrion_reward.abi.d.ts +407 -0
  6. package/dist/abis/alphatrion_reward.abi.js +532 -0
  7. package/dist/abis/alphatrion_reward.abi.js.map +1 -0
  8. package/dist/abis/ciphertext_digests.abi.d.ts +336 -0
  9. package/dist/abis/ciphertext_digests.abi.js +444 -0
  10. package/dist/abis/ciphertext_digests.abi.js.map +1 -0
  11. package/dist/abis/ciphertext_verification.abi.d.ts +637 -0
  12. package/dist/abis/ciphertext_verification.abi.js +830 -0
  13. package/dist/abis/ciphertext_verification.abi.js.map +1 -0
  14. package/dist/abis/convert_token.abi.d.ts +922 -0
  15. package/dist/abis/convert_token.abi.js +1208 -0
  16. package/dist/abis/convert_token.abi.js.map +1 -0
  17. package/dist/abis/decryption.abi.d.ts +956 -0
  18. package/dist/abis/decryption.abi.js +1244 -0
  19. package/dist/abis/decryption.abi.js.map +1 -0
  20. package/dist/abis/erc20.abi.d.ts +265 -0
  21. package/dist/abis/erc20.abi.js +350 -0
  22. package/dist/abis/erc20.abi.js.map +1 -0
  23. package/dist/abis/fhe_executor.abi.d.ts +1535 -0
  24. package/dist/abis/fhe_executor.abi.js +1962 -0
  25. package/dist/abis/fhe_executor.abi.js.map +1 -0
  26. package/dist/abis/space_bridge_config.abi.d.ts +792 -0
  27. package/dist/abis/space_bridge_config.abi.js +1032 -0
  28. package/dist/abis/space_bridge_config.abi.js.map +1 -0
  29. package/dist/abis/token.abi.d.ts +630 -0
  30. package/dist/abis/token.abi.js +828 -0
  31. package/dist/abis/token.abi.js.map +1 -0
  32. package/dist/cli/eusdc.d.ts +2 -0
  33. package/dist/cli/eusdc.js +41 -0
  34. package/dist/cli/eusdc.js.map +1 -0
  35. package/dist/contract/callbacks.d.ts +59 -0
  36. package/dist/contract/callbacks.js +2 -0
  37. package/dist/contract/callbacks.js.map +1 -0
  38. package/dist/contract/convert-token.d.ts +107 -0
  39. package/dist/contract/convert-token.js +249 -0
  40. package/dist/contract/convert-token.js.map +1 -0
  41. package/dist/contract/token.d.ts +167 -0
  42. package/dist/contract/token.js +404 -0
  43. package/dist/contract/token.js.map +1 -0
  44. package/dist/contract/transaction.d.ts +29 -0
  45. package/dist/contract/transaction.js +2 -0
  46. package/dist/contract/transaction.js.map +1 -0
  47. package/dist/core/address.d.ts +118 -0
  48. package/dist/core/address.js +200 -0
  49. package/dist/core/address.js.map +1 -0
  50. package/dist/core/auth.d.ts +68 -0
  51. package/dist/core/auth.js +58 -0
  52. package/dist/core/auth.js.map +1 -0
  53. package/dist/core/bytes.d.ts +48 -0
  54. package/dist/core/bytes.js +117 -0
  55. package/dist/core/bytes.js.map +1 -0
  56. package/dist/core/cache-manager.d.ts +138 -0
  57. package/dist/core/cache-manager.js +440 -0
  58. package/dist/core/cache-manager.js.map +1 -0
  59. package/dist/core/chain.d.ts +41 -0
  60. package/dist/core/chain.js +59 -0
  61. package/dist/core/chain.js.map +1 -0
  62. package/dist/core/constants.d.ts +24 -0
  63. package/dist/core/constants.js +25 -0
  64. package/dist/core/constants.js.map +1 -0
  65. package/dist/core/error.d.ts +2 -0
  66. package/dist/core/error.js +14 -0
  67. package/dist/core/error.js.map +1 -0
  68. package/dist/core/errors/error-catalog.d.ts +29 -0
  69. package/dist/core/errors/error-catalog.js +84 -0
  70. package/dist/core/errors/error-catalog.js.map +1 -0
  71. package/dist/core/errors/error-codes.d.ts +52 -0
  72. package/dist/core/errors/error-codes.js +61 -0
  73. package/dist/core/errors/error-codes.js.map +1 -0
  74. package/dist/core/errors/error-utils.d.ts +27 -0
  75. package/dist/core/errors/error-utils.js +110 -0
  76. package/dist/core/errors/error-utils.js.map +1 -0
  77. package/dist/core/errors/fhe-error.d.ts +98 -0
  78. package/dist/core/errors/fhe-error.js +190 -0
  79. package/dist/core/errors/fhe-error.js.map +1 -0
  80. package/dist/core/errors/index.d.ts +4 -0
  81. package/dist/core/errors/index.js +5 -0
  82. package/dist/core/errors/index.js.map +1 -0
  83. package/dist/core/estimate.d.ts +39 -0
  84. package/dist/core/estimate.js +111 -0
  85. package/dist/core/estimate.js.map +1 -0
  86. package/dist/core/event.d.ts +212 -0
  87. package/dist/core/event.js +42 -0
  88. package/dist/core/event.js.map +1 -0
  89. package/dist/core/fhe-type.d.ts +75 -0
  90. package/dist/core/fhe-type.js +115 -0
  91. package/dist/core/fhe-type.js.map +1 -0
  92. package/dist/core/fhe.d.ts +11 -0
  93. package/dist/core/fhe.js +23 -0
  94. package/dist/core/fhe.js.map +1 -0
  95. package/dist/core/handle.d.ts +42 -0
  96. package/dist/core/handle.js +99 -0
  97. package/dist/core/handle.js.map +1 -0
  98. package/dist/core/json-utils.d.ts +18 -0
  99. package/dist/core/json-utils.js +37 -0
  100. package/dist/core/json-utils.js.map +1 -0
  101. package/dist/core/kms.d.ts +42 -0
  102. package/dist/core/kms.js +70 -0
  103. package/dist/core/kms.js.map +1 -0
  104. package/dist/core/logger.d.ts +3 -0
  105. package/dist/core/logger.js +11 -0
  106. package/dist/core/logger.js.map +1 -0
  107. package/dist/core/pretty-print.d.ts +18 -0
  108. package/dist/core/pretty-print.js +84 -0
  109. package/dist/core/pretty-print.js.map +1 -0
  110. package/dist/core/primitives.d.ts +22 -0
  111. package/dist/core/primitives.js +2 -0
  112. package/dist/core/primitives.js.map +1 -0
  113. package/dist/core/retryable-handler.d.ts +74 -0
  114. package/dist/core/retryable-handler.js +227 -0
  115. package/dist/core/retryable-handler.js.map +1 -0
  116. package/dist/core/signer-address-info.d.ts +15 -0
  117. package/dist/core/signer-address-info.js +33 -0
  118. package/dist/core/signer-address-info.js.map +1 -0
  119. package/dist/core/string.d.ts +28 -0
  120. package/dist/core/string.js +33 -0
  121. package/dist/core/string.js.map +1 -0
  122. package/dist/core/swallow.d.ts +23 -0
  123. package/dist/core/swallow.js +37 -0
  124. package/dist/core/swallow.js.map +1 -0
  125. package/dist/core/system-contract-info.d.ts +17 -0
  126. package/dist/core/system-contract-info.js +41 -0
  127. package/dist/core/system-contract-info.js.map +1 -0
  128. package/dist/core/ttl-cache.d.ts +81 -0
  129. package/dist/core/ttl-cache.js +113 -0
  130. package/dist/core/ttl-cache.js.map +1 -0
  131. package/dist/core/tx-error-parser.d.ts +40 -0
  132. package/dist/core/tx-error-parser.js +83 -0
  133. package/dist/core/tx-error-parser.js.map +1 -0
  134. package/dist/core/utils.d.ts +62 -0
  135. package/dist/core/utils.js +143 -0
  136. package/dist/core/utils.js.map +1 -0
  137. package/dist/index.d.ts +40 -0
  138. package/dist/index.js +48 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/jazz/encrypt-key-p.d.ts +65 -0
  141. package/dist/jazz/encrypt-key-p.js +283 -0
  142. package/dist/jazz/encrypt-key-p.js.map +1 -0
  143. package/dist/jazz/encrypt-p.d.ts +82 -0
  144. package/dist/jazz/encrypt-p.js +139 -0
  145. package/dist/jazz/encrypt-p.js.map +1 -0
  146. package/dist/jazz/encrypt.d.ts +58 -0
  147. package/dist/jazz/encrypt.js +155 -0
  148. package/dist/jazz/encrypt.js.map +1 -0
  149. package/dist/jazz/input-proof-p.d.ts +122 -0
  150. package/dist/jazz/input-proof-p.js +265 -0
  151. package/dist/jazz/input-proof-p.js.map +1 -0
  152. package/dist/jazz/jazz-client-i.d.ts +16 -0
  153. package/dist/jazz/jazz-client-i.js +2 -0
  154. package/dist/jazz/jazz-client-i.js.map +1 -0
  155. package/dist/jazz/jazz-client.d.ts +18 -0
  156. package/dist/jazz/jazz-client.js +24 -0
  157. package/dist/jazz/jazz-client.js.map +1 -0
  158. package/dist/jazz/key-pair.d.ts +50 -0
  159. package/dist/jazz/key-pair.js +166 -0
  160. package/dist/jazz/key-pair.js.map +1 -0
  161. package/dist/jazz/mock/fake.d.ts +3 -0
  162. package/dist/jazz/mock/fake.js +23 -0
  163. package/dist/jazz/mock/fake.js.map +1 -0
  164. package/dist/jazz/mock/fetch-input-proof.d.ts +4 -0
  165. package/dist/jazz/mock/fetch-input-proof.js +63 -0
  166. package/dist/jazz/mock/fetch-input-proof.js.map +1 -0
  167. package/dist/jazz/mock/fetch-key-url.d.ts +3 -0
  168. package/dist/jazz/mock/fetch-key-url.js +15 -0
  169. package/dist/jazz/mock/fetch-key-url.js.map +1 -0
  170. package/dist/jazz/mock/fetch-public-decrypt.d.ts +3 -0
  171. package/dist/jazz/mock/fetch-public-decrypt.js +81 -0
  172. package/dist/jazz/mock/fetch-public-decrypt.js.map +1 -0
  173. package/dist/jazz/mock/fetch-user-decrypt.d.ts +4 -0
  174. package/dist/jazz/mock/fetch-user-decrypt.js +174 -0
  175. package/dist/jazz/mock/fetch-user-decrypt.js.map +1 -0
  176. package/dist/jazz/module/fetch-input-proof.d.ts +19 -0
  177. package/dist/jazz/module/fetch-input-proof.js +72 -0
  178. package/dist/jazz/module/fetch-input-proof.js.map +1 -0
  179. package/dist/jazz/module/fetch-key-url.d.ts +17 -0
  180. package/dist/jazz/module/fetch-key-url.js +46 -0
  181. package/dist/jazz/module/fetch-key-url.js.map +1 -0
  182. package/dist/jazz/module/fetch-public-decrypt.d.ts +19 -0
  183. package/dist/jazz/module/fetch-public-decrypt.js +65 -0
  184. package/dist/jazz/module/fetch-public-decrypt.js.map +1 -0
  185. package/dist/jazz/module/fetch-user-decrypt.d.ts +19 -0
  186. package/dist/jazz/module/fetch-user-decrypt.js +109 -0
  187. package/dist/jazz/module/fetch-user-decrypt.js.map +1 -0
  188. package/dist/jazz/module/jazz-async-request.d.ts +102 -0
  189. package/dist/jazz/module/jazz-async-request.js +515 -0
  190. package/dist/jazz/module/jazz-async-request.js.map +1 -0
  191. package/dist/jazz/module/jazz-p.d.ts +61 -0
  192. package/dist/jazz/module/jazz-p.js +33 -0
  193. package/dist/jazz/module/jazz-p.js.map +1 -0
  194. package/dist/jazz/module/s3-download.d.ts +85 -0
  195. package/dist/jazz/module/s3-download.js +293 -0
  196. package/dist/jazz/module/s3-download.js.map +1 -0
  197. package/dist/jazz/permit.d.ts +200 -0
  198. package/dist/jazz/permit.js +319 -0
  199. package/dist/jazz/permit.js.map +1 -0
  200. package/dist/jazz/public-decrypt-p.d.ts +96 -0
  201. package/dist/jazz/public-decrypt-p.js +258 -0
  202. package/dist/jazz/public-decrypt-p.js.map +1 -0
  203. package/dist/jazz/public-decrypt.d.ts +48 -0
  204. package/dist/jazz/public-decrypt.js +156 -0
  205. package/dist/jazz/public-decrypt.js.map +1 -0
  206. package/dist/jazz/read-contract.d.ts +81 -0
  207. package/dist/jazz/read-contract.js +125 -0
  208. package/dist/jazz/read-contract.js.map +1 -0
  209. package/dist/jazz/types/common.d.ts +17 -0
  210. package/dist/jazz/types/common.js +2 -0
  211. package/dist/jazz/types/common.js.map +1 -0
  212. package/dist/jazz/types/input-proof.d.ts +76 -0
  213. package/dist/jazz/types/input-proof.js +2 -0
  214. package/dist/jazz/types/input-proof.js.map +1 -0
  215. package/dist/jazz/types/key-url.d.ts +68 -0
  216. package/dist/jazz/types/key-url.js +5 -0
  217. package/dist/jazz/types/key-url.js.map +1 -0
  218. package/dist/jazz/types/public-decrypt.d.ts +61 -0
  219. package/dist/jazz/types/public-decrypt.js +2 -0
  220. package/dist/jazz/types/public-decrypt.js.map +1 -0
  221. package/dist/jazz/types/user-decrypt.d.ts +123 -0
  222. package/dist/jazz/types/user-decrypt.js +2 -0
  223. package/dist/jazz/types/user-decrypt.js.map +1 -0
  224. package/dist/jazz/user-decrypt-p.d.ts +111 -0
  225. package/dist/jazz/user-decrypt-p.js +280 -0
  226. package/dist/jazz/user-decrypt-p.js.map +1 -0
  227. package/dist/jazz/user-decrypt.d.ts +74 -0
  228. package/dist/jazz/user-decrypt.js +143 -0
  229. package/dist/jazz/user-decrypt.js.map +1 -0
  230. package/dist/native/fhe-api.js +5959 -0
  231. package/dist/native/fhe-api.node.cjs +6167 -0
  232. package/dist/native/fhe-api.node.worker.cjs +210 -0
  233. package/dist/native/fhe-api.wasm +0 -0
  234. package/dist/native/fhe-api.worker.js +164 -0
  235. package/dist/native/kms/node/kms_lib.d.ts +38 -0
  236. package/dist/native/kms/node/kms_lib.js +356 -0
  237. package/dist/native/kms/node/kms_lib_bg.wasm +0 -0
  238. package/dist/native/kms/node/kms_lib_bg.wasm.d.ts +21 -0
  239. package/dist/native/kms/node/package.json +11 -0
  240. package/dist/native/kms/web/kms_lib.d.ts +84 -0
  241. package/dist/native/kms/web/kms_lib.js +443 -0
  242. package/dist/native/kms/web/kms_lib_bg.wasm +0 -0
  243. package/dist/native/kms/web/kms_lib_bg.wasm.d.ts +21 -0
  244. package/dist/native/kms/web/package.json +15 -0
  245. package/dist/runtime/browser.d.ts +36 -0
  246. package/dist/runtime/browser.js +115 -0
  247. package/dist/runtime/browser.js.map +1 -0
  248. package/dist/runtime/node.d.ts +30 -0
  249. package/dist/runtime/node.js +95 -0
  250. package/dist/runtime/node.js.map +1 -0
  251. package/dist/sdk/fhetransform-sdk-b.d.ts +102 -0
  252. package/dist/sdk/fhetransform-sdk-b.js +294 -0
  253. package/dist/sdk/fhetransform-sdk-b.js.map +1 -0
  254. package/dist/sdk/fhetransform-sdk.d.ts +87 -0
  255. package/dist/sdk/fhetransform-sdk.js +135 -0
  256. package/dist/sdk/fhetransform-sdk.js.map +1 -0
  257. package/dist/sdk/jazz-service.d.ts +13 -0
  258. package/dist/sdk/jazz-service.js +58 -0
  259. package/dist/sdk/jazz-service.js.map +1 -0
  260. package/dist/sdk/permit-service.d.ts +45 -0
  261. package/dist/sdk/permit-service.js +144 -0
  262. package/dist/sdk/permit-service.js.map +1 -0
  263. package/dist/wasm/fhe-wasm-client.d.ts +19 -0
  264. package/dist/wasm/fhe-wasm-client.js +23 -0
  265. package/dist/wasm/fhe-wasm-client.js.map +1 -0
  266. package/dist/wasm/fhe-wasm-module.d.ts +24 -0
  267. package/dist/wasm/fhe-wasm-module.js +141 -0
  268. package/dist/wasm/fhe-wasm-module.js.map +1 -0
  269. package/dist/wasm/fhe-wasm-type.d.ts +59 -0
  270. package/dist/wasm/fhe-wasm-type.js +244 -0
  271. package/dist/wasm/fhe-wasm-type.js.map +1 -0
  272. package/dist/wasm/wasm-loader.browser.d.ts +21 -0
  273. package/dist/wasm/wasm-loader.browser.js +143 -0
  274. package/dist/wasm/wasm-loader.browser.js.map +1 -0
  275. package/dist/wasm/wasm-loader.node.d.ts +24 -0
  276. package/dist/wasm/wasm-loader.node.js +114 -0
  277. package/dist/wasm/wasm-loader.node.js.map +1 -0
  278. package/dist/wasm/worker-client.browser.d.ts +6 -0
  279. package/dist/wasm/worker-client.browser.js +21 -0
  280. package/dist/wasm/worker-client.browser.js.map +1 -0
  281. package/dist/wasm/worker-client.d.ts +34 -0
  282. package/dist/wasm/worker-client.js +160 -0
  283. package/dist/wasm/worker-client.js.map +1 -0
  284. package/dist/wasm/worker-client.node.d.ts +6 -0
  285. package/dist/wasm/worker-client.node.js +20 -0
  286. package/dist/wasm/worker-client.node.js.map +1 -0
  287. package/dist/wasm/worker-message.d.ts +61 -0
  288. package/dist/wasm/worker-message.js +2 -0
  289. package/dist/wasm/worker-message.js.map +1 -0
  290. package/dist/wasm/worker-transport.browser.d.ts +15 -0
  291. package/dist/wasm/worker-transport.browser.js +35 -0
  292. package/dist/wasm/worker-transport.browser.js.map +1 -0
  293. package/dist/wasm/worker-transport.d.ts +6 -0
  294. package/dist/wasm/worker-transport.js +2 -0
  295. package/dist/wasm/worker-transport.js.map +1 -0
  296. package/dist/wasm/worker-transport.node.d.ts +17 -0
  297. package/dist/wasm/worker-transport.node.js +39 -0
  298. package/dist/wasm/worker-transport.node.js.map +1 -0
  299. package/dist/wasm/worker.d.ts +1 -0
  300. package/dist/wasm/worker.js +69 -0
  301. package/dist/wasm/worker.js.map +1 -0
  302. package/package.json +81 -0
@@ -0,0 +1,200 @@
1
+ import { ethers } from "ethers";
2
+ import { Address, Bytes65Hex, BytesHex } from "../core/primitives.js";
3
+ import { TransportKeyPair } from "./key-pair.js";
4
+ import { FheTransformSDK } from "../sdk/fhetransform-sdk.js";
5
+ /**
6
+ * Native signer type (ethers.Signer or compatible).
7
+ */
8
+ export type NativeSigner = unknown;
9
+ /**
10
+ * Parameters for signing a decryption permit.
11
+ */
12
+ export type SignDecryptionPermitParameters = {
13
+ /** List of contract addresses covered by this permit */
14
+ readonly contractAddresses: readonly BytesHex[];
15
+ /** Start timestamp (Unix timestamp in seconds) */
16
+ readonly startTimestamp: number;
17
+ /** Duration in days */
18
+ readonly durationDays: number;
19
+ /** Address of the signer */
20
+ readonly signerAddress: Address;
21
+ /** ethers.Signer instance for signing */
22
+ readonly signer: ethers.Signer;
23
+ /** Transport key pair for E2E encryption */
24
+ readonly transportKeyPair: TransportKeyPair;
25
+ };
26
+ /**
27
+ * Base structure for a signed decryption permit.
28
+ */
29
+ export type SignedDecryptionPermitBase = {
30
+ /** The EIP-712 signature as 65-byte hex with 0x prefix */
31
+ readonly signature: Bytes65Hex;
32
+ /** The account that signed the permit */
33
+ readonly signerAddress: Address;
34
+ /**
35
+ * The account that owns the encrypted data this permit covers.
36
+ *
37
+ * - **Self permit:** equals `signerAddress` — the signer authorizes decryption
38
+ * of their own data.
39
+ *
40
+ * - **Delegated permit:** differs from `signerAddress`. Step by step:
41
+ * 1. Alice owns encrypted values on-chain (ebool, euint8, etc.).
42
+ * 2. Alice calls the ACL contract to grant Bob permission to decrypt her data.
43
+ * 3. Bob signs an EIP-712 delegated decryption permit referencing Alice as the
44
+ * `encryptedDataOwnerAddress` (= `delegatorAddress` in the EIP-712 message).
45
+ * 4. The KMS verifies Bob's signature (`signerAddress`) and that Alice
46
+ * (`encryptedDataOwnerAddress`) has granted him on-chain permission.
47
+ * 5. Bob can now decrypt Alice's encrypted values using this permit.
48
+ */
49
+ readonly encryptedDataOwnerAddress: Address;
50
+ /** The E2E transport public key embedded in the EIP-712 message */
51
+ readonly transportPublicKey: BytesHex;
52
+ };
53
+ /**
54
+ * EIP-712 domain for KMS decryption.
55
+ */
56
+ export type KmsEip712Domain = Readonly<{
57
+ name: 'Decryption';
58
+ version: '1';
59
+ chainId: bigint;
60
+ verifyingContract: Address;
61
+ }>;
62
+ /**
63
+ * EIP-712 type definitions for KMS user decryption.
64
+ */
65
+ export type KmsUserDecryptEip712Types = {
66
+ readonly EIP712Domain: readonly [
67
+ {
68
+ readonly name: 'name';
69
+ readonly type: 'string';
70
+ },
71
+ {
72
+ readonly name: 'version';
73
+ readonly type: 'string';
74
+ },
75
+ {
76
+ readonly name: 'chainId';
77
+ readonly type: 'uint256';
78
+ },
79
+ {
80
+ readonly name: 'verifyingContract';
81
+ readonly type: 'address';
82
+ }
83
+ ];
84
+ readonly RequestUserDecryptSignData: readonly [
85
+ {
86
+ readonly name: 'publicKey';
87
+ readonly type: 'bytes';
88
+ },
89
+ {
90
+ readonly name: 'contractAddresses';
91
+ readonly type: 'address[]';
92
+ },
93
+ {
94
+ readonly name: 'startTimestamp';
95
+ readonly type: 'uint256';
96
+ },
97
+ {
98
+ readonly name: 'durationDays';
99
+ readonly type: 'uint256';
100
+ },
101
+ {
102
+ readonly name: 'extraData';
103
+ readonly type: 'bytes';
104
+ }
105
+ ];
106
+ };
107
+ /**
108
+ * EIP-712 message for KMS user decryption.
109
+ */
110
+ export type KmsUserDecryptEip712Message = Readonly<{
111
+ publicKey: BytesHex;
112
+ contractAddresses: readonly Address[];
113
+ startTimestamp: string;
114
+ durationDays: string;
115
+ extraData: BytesHex;
116
+ }>;
117
+ /**
118
+ * Complete EIP-712 structure for KMS user decryption.
119
+ */
120
+ export type KmsUserDecryptEip712 = {
121
+ readonly domain: KmsEip712Domain;
122
+ readonly types: KmsUserDecryptEip712Types;
123
+ readonly primaryType: 'RequestUserDecryptSignData';
124
+ readonly message: KmsUserDecryptEip712Message;
125
+ };
126
+ /**
127
+ * Signed decryption permit with EIP-712 data.
128
+ */
129
+ export type SignedDecryptionPermit = SignedDecryptionPermitBase & {
130
+ readonly eip712: KmsUserDecryptEip712;
131
+ };
132
+ /**
133
+ * Result of signing a decryption permit.
134
+ */
135
+ export type SignedDecryptionPermitResult = SignedDecryptionPermit;
136
+ /**
137
+ * EIP-712 type definitions for KMS user decryption.
138
+ *
139
+ * CRITICAL: Field order is authoritative — it determines the EIP-712 type hash.
140
+ * Changing the order will produce a different signature and break on-chain verification.
141
+ * Must match the Solidity struct definition exactly.
142
+ */
143
+ export declare const kmsUserDecryptEip712Types: KmsUserDecryptEip712Types;
144
+ /**
145
+ * Parameters for creating a KMS user decrypt EIP-712 structure.
146
+ */
147
+ export type CreateKmsUserDecryptEip712Parameters = {
148
+ /** Contract address that verifies decryption permits */
149
+ readonly verifyingContractAddressDecryption: BytesHex;
150
+ /** Chain ID */
151
+ readonly chainId: bigint;
152
+ /** Public key for E2E encryption */
153
+ readonly publicKey: BytesHex;
154
+ /** List of contract addresses covered by this permit */
155
+ readonly contractAddresses: readonly BytesHex[];
156
+ /** Start timestamp (Unix timestamp in seconds) */
157
+ readonly startTimestamp: number;
158
+ /** Duration in days */
159
+ readonly durationDays: number;
160
+ /** Additional contextual data */
161
+ readonly extraData: BytesHex;
162
+ };
163
+ /**
164
+ * Creates a KMS user decrypt EIP-712 structure.
165
+ *
166
+ * @param parameters - Parameters for creating the EIP-712 structure
167
+ * @returns Frozen KmsUserDecryptEip712 object
168
+ */
169
+ export declare function createKmsUserDecryptEip712(parameters: CreateKmsUserDecryptEip712Parameters): KmsUserDecryptEip712;
170
+ /**
171
+ * Signs a decryption permit using EIP-712.
172
+ *
173
+ * @param parameters - Signing parameters
174
+ * @returns SignedDecryptionPermitResult containing signature and EIP-712 data
175
+ * @throws Error if signing fails
176
+ */
177
+ export declare function signDecryptionPermit(sdk: FheTransformSDK, parameters: SignDecryptionPermitParameters): Promise<SignedDecryptionPermitResult>;
178
+ /**
179
+ * Container for transport key pair with its associated permit.
180
+ */
181
+ export interface TransportKeyPairWithPermits {
182
+ /** The transport key pair */
183
+ readonly keypair: TransportKeyPair;
184
+ /** The signed decryption permit */
185
+ readonly permit: SignedDecryptionPermit;
186
+ }
187
+ /**
188
+ * Gets an existing permit from cache, or creates a new one.
189
+ *
190
+ * This function implements a caching strategy:
191
+ * 1. Checks if a valid permit exists in cache for the signer+chain
192
+ * 2. Validates the cached permit (same public key, contract subset, not expired, etc.)
193
+ * 3. If valid, returns the cached permit
194
+ * 4. If not valid or missing, signs a new permit and caches it
195
+ *
196
+ * @param contractAddresses - List of contract addresses to include in the permit
197
+ * @returns TransportKeyPairWithPermits containing keypair and permit
198
+ * @throws Error if signing fails
199
+ */
200
+ export declare function getOrCreateTKeyPairWithPermit(sdk: FheTransformSDK, contractAddresses: readonly BytesHex[]): Promise<TransportKeyPairWithPermits>;
@@ -0,0 +1,319 @@
1
+ import { getOrCreateKeyPair } from "./key-pair.js";
2
+ import { formatValue } from "../core/pretty-print.js";
3
+ import { DEFAULT_PERMIT_TTL_DAYS, SECONDS_PER_DAY } from "../core/constants.js";
4
+ import { JSONWithBigInt } from "../core/json-utils.js";
5
+ import { logger } from "../core/logger.js";
6
+ import { assertChecksumAddress } from "../core/address.js";
7
+ import { FheErrorCode } from "../core/errors/error-codes.js";
8
+ import { FheError } from "../core/errors/fhe-error.js";
9
+ // ============================================================================
10
+ // EIP-712 Constants
11
+ // ============================================================================
12
+ /**
13
+ * EIP-712 type definitions for KMS user decryption.
14
+ *
15
+ * CRITICAL: Field order is authoritative — it determines the EIP-712 type hash.
16
+ * Changing the order will produce a different signature and break on-chain verification.
17
+ * Must match the Solidity struct definition exactly.
18
+ */
19
+ export const kmsUserDecryptEip712Types = {
20
+ EIP712Domain: [
21
+ { name: 'name', type: 'string' },
22
+ { name: 'version', type: 'string' },
23
+ { name: 'chainId', type: 'uint256' },
24
+ { name: 'verifyingContract', type: 'address' },
25
+ ],
26
+ // CRITICAL: Field order is authoritative — it determines the EIP-712 type hash.
27
+ // Changing the order will produce a different signature and break on-chain verification.
28
+ // Must match the Solidity struct definition exactly.
29
+ RequestUserDecryptSignData: [
30
+ { name: 'publicKey', type: 'bytes' },
31
+ { name: 'contractAddresses', type: 'address[]' },
32
+ { name: 'startTimestamp', type: 'uint256' },
33
+ { name: 'durationDays', type: 'uint256' },
34
+ { name: 'extraData', type: 'bytes' },
35
+ ],
36
+ };
37
+ /**
38
+ * Creates a KMS user decrypt EIP-712 structure.
39
+ *
40
+ * @param parameters - Parameters for creating the EIP-712 structure
41
+ * @returns Frozen KmsUserDecryptEip712 object
42
+ */
43
+ export function createKmsUserDecryptEip712(parameters) {
44
+ // Enter method
45
+ const { verifyingContractAddressDecryption, chainId, publicKey, contractAddresses, startTimestamp, durationDays, extraData, } = parameters;
46
+ logger.debug('[createKmsUserDecryptEip712] Enter', {
47
+ verifyingContract: verifyingContractAddressDecryption,
48
+ chainId: chainId.toString(),
49
+ publicKeyLength: publicKey.length,
50
+ contractAddressesCount: contractAddresses.length,
51
+ startTimestamp,
52
+ durationDays,
53
+ });
54
+ const primaryType = 'RequestUserDecryptSignData';
55
+ const domain = {
56
+ name: 'Decryption',
57
+ version: '1',
58
+ chainId: chainId,
59
+ verifyingContract: verifyingContractAddressDecryption,
60
+ };
61
+ const eip712 = {
62
+ domain,
63
+ types: kmsUserDecryptEip712Types,
64
+ primaryType,
65
+ message: {
66
+ publicKey: publicKey,
67
+ contractAddresses: contractAddresses,
68
+ startTimestamp: startTimestamp.toString(),
69
+ durationDays: durationDays.toString(),
70
+ extraData,
71
+ },
72
+ };
73
+ // Freeze all objects for immutability
74
+ Object.freeze(eip712);
75
+ Object.freeze(eip712.domain);
76
+ Object.freeze(eip712.types);
77
+ Object.freeze(eip712.types.EIP712Domain);
78
+ Object.freeze(eip712.types.RequestUserDecryptSignData);
79
+ Object.freeze(eip712.message);
80
+ Object.freeze(eip712.message.contractAddresses);
81
+ logger.trace('[createKmsUserDecryptEip712] EIP-712 structure created and frozen');
82
+ return eip712;
83
+ }
84
+ // ============================================================================
85
+ // Permit Signing
86
+ // ============================================================================
87
+ /**
88
+ * Signs a decryption permit using EIP-712.
89
+ *
90
+ * @param parameters - Signing parameters
91
+ * @returns SignedDecryptionPermitResult containing signature and EIP-712 data
92
+ * @throws Error if signing fails
93
+ */
94
+ export async function signDecryptionPermit(sdk, parameters) {
95
+ // Enter method
96
+ logger.debug('[signDecryptionPermit] Enter', {
97
+ contractAddressesCount: parameters.contractAddresses.length,
98
+ startTimestamp: parameters.startTimestamp,
99
+ durationDays: parameters.durationDays,
100
+ signerAddress: parameters.signerAddress,
101
+ });
102
+ // ============================================================================
103
+ // Step 1: Fetch Chain and Contract Info
104
+ // ============================================================================
105
+ const chainId = await sdk.getChainID();
106
+ const sysContractInfo = await sdk.getSystemContractInfo();
107
+ const extraData = "0x00";
108
+ logger.trace('[signDecryptionPermit] Chain and contract info fetched', {
109
+ chainId: chainId.toString(),
110
+ decryptionContract: sysContractInfo.decryptionContractAddress,
111
+ });
112
+ // ============================================================================
113
+ // Step 2: Build EIP-712 Structure
114
+ // ============================================================================
115
+ const { contractAddresses, startTimestamp, durationDays, signerAddress, transportKeyPair, signer } = parameters;
116
+ const commonMessage = {
117
+ verifyingContractAddressDecryption: sysContractInfo.decryptionContractAddress,
118
+ chainId: chainId,
119
+ contractAddresses,
120
+ durationDays,
121
+ startTimestamp,
122
+ extraData,
123
+ publicKey: transportKeyPair.publicKey,
124
+ };
125
+ const eip712 = createKmsUserDecryptEip712(commonMessage);
126
+ logger.debug(() => ['[signDecryptionPermit] EIP-712 structure created', formatValue({ eip712 })]);
127
+ // ============================================================================
128
+ // Step 3: Sign the EIP-712 Message
129
+ // ============================================================================
130
+ const primaryTypeFields = eip712.types[eip712.primaryType];
131
+ if (primaryTypeFields === undefined) {
132
+ logger.error('[signDecryptionPermit] Primary type not found', {
133
+ primaryType: eip712.primaryType,
134
+ });
135
+ throw new FheError({ code: FheErrorCode.Internal, message: `Primary type "${eip712.primaryType}" not found in types` });
136
+ }
137
+ const typesToSign = {
138
+ [eip712.primaryType]: [...primaryTypeFields],
139
+ };
140
+ logger.debug('[signDecryptionPermit] Signing EIP-712 message');
141
+ const signature = await signer.signTypedData(eip712.domain, typesToSign, eip712.message);
142
+ logger.debug('[signDecryptionPermit] Signature generated', {
143
+ signatureLength: signature.length,
144
+ });
145
+ // ============================================================================
146
+ // Step 4: Build Result
147
+ // ============================================================================
148
+ const result = {
149
+ signature: signature,
150
+ signerAddress: signerAddress,
151
+ encryptedDataOwnerAddress: "0x0000000000000000000000000000000000000000", // not used
152
+ transportPublicKey: transportKeyPair.publicKey,
153
+ eip712
154
+ };
155
+ logger.info('[signDecryptionPermit] Decryption permit signed successfully', {
156
+ signerAddress,
157
+ contractAddressesCount: contractAddresses.length,
158
+ durationDays,
159
+ });
160
+ return result;
161
+ }
162
+ /**
163
+ * Gets an existing permit from cache, or creates a new one.
164
+ *
165
+ * This function implements a caching strategy:
166
+ * 1. Checks if a valid permit exists in cache for the signer+chain
167
+ * 2. Validates the cached permit (same public key, contract subset, not expired, etc.)
168
+ * 3. If valid, returns the cached permit
169
+ * 4. If not valid or missing, signs a new permit and caches it
170
+ *
171
+ * @param contractAddresses - List of contract addresses to include in the permit
172
+ * @returns TransportKeyPairWithPermits containing keypair and permit
173
+ * @throws Error if signing fails
174
+ */
175
+ export async function getOrCreateTKeyPairWithPermit(sdk, contractAddresses) {
176
+ // Enter method
177
+ logger.debug('[getOrCreateTKeyPairWithPermit] Enter', { contractAddresses });
178
+ contractAddresses.forEach(item => { assertChecksumAddress(item, "contractAddresses"); });
179
+ // ============================================================================
180
+ // Step 1: Fetch Chain and Signer Info
181
+ // ============================================================================
182
+ const chainId = await sdk.getChainID();
183
+ const sysContractInfo = await sdk.getSystemContractInfo();
184
+ const signer = await sdk.requireSigner();
185
+ const signerAddress = await signer.getAddress();
186
+ const extraData = "0x00";
187
+ logger.debug('[getOrCreateTKeyPairWithPermit] Context fetched', {
188
+ chainId: chainId.toString(),
189
+ signerAddress,
190
+ decryptionContract: sysContractInfo.decryptionContractAddress,
191
+ extraData,
192
+ });
193
+ // ============================================================================
194
+ // Step 2: Get or Create Key Pair
195
+ // ============================================================================
196
+ const keypair = await getOrCreateKeyPair(sdk, signerAddress);
197
+ logger.debug('[getOrCreateTKeyPairWithPermit] Key pair ready', {
198
+ publicKeyLength: keypair.publicKey.length,
199
+ });
200
+ // ============================================================================
201
+ // Step 3: Check Cache for Existing Permit
202
+ // ============================================================================
203
+ /**
204
+ * ### Permit Update Mechanism
205
+ *
206
+ * **Scope Key:** `signerAddress + chainId`
207
+ *
208
+ * **Delete Policy (scope key mismatch):**
209
+ * - Old `signerAddress` != new `signerAddress`
210
+ * - Old `chainId` != new `chainId`
211
+ *
212
+ * **New Permit:** Create if scope key not found
213
+ *
214
+ * **Replace Policy (cache invalidation) — trigger on ANY of:**
215
+ * - Old `publicKey` != new `publicKey`
216
+ * - `now` >= `old.startTimestamp + old.durationDays` (expired)
217
+ * - New `contractAddresses` not subset of old `contractAddresses`
218
+ * - new set = deduplicated union of old and new contract addresses
219
+ * - Example: old=[A,B], new=[B,C] => new is not subset of old ([C] is new),
220
+ * - so replace is triggered. The stored new set becomes [A,B,C] (deduplicated union).
221
+ * - Old `extraData` != new `extraData`
222
+ */
223
+ const permitKey = `permit:${signerAddress}:${chainId}`;
224
+ logger.trace('[getOrCreateTKeyPairWithPermit] Permit cache key', { permitKey });
225
+ // List existing permits and clean up old ones
226
+ const permitKeys = await sdk.cacheManager.listKeys("permit:");
227
+ const exists = permitKeys.includes(permitKey);
228
+ if (!exists) {
229
+ logger.debug('[getOrCreateTKeyPairWithPermit] No existing permit found, clearing old cache');
230
+ // delete all, since permit scope key: (`signerAddress + chainId`) not match
231
+ await sdk.cacheManager.clear("permit:");
232
+ }
233
+ // ============================================================================
234
+ // Step 4: Load and Validate Cached Permit
235
+ // ============================================================================
236
+ let oldPermit;
237
+ const data = await sdk.cacheManager.loadString(permitKey);
238
+ logger.trace('[getOrCreateTKeyPairWithPermit] Cache load result', {
239
+ hasData: !!data,
240
+ dataLength: data?.length,
241
+ });
242
+ let uniqueContractAddresses = [...new Set([...contractAddresses])];
243
+ if (data) {
244
+ try {
245
+ const parsed = JSONWithBigInt.parse(data);
246
+ oldPermit = parsed;
247
+ // Validate cached permit against current state
248
+ const old = oldPermit.eip712.message;
249
+ const isSamePublicKey = old.publicKey === keypair.publicKey;
250
+ const isContractSubset = contractAddresses.every(item => old.contractAddresses.includes(item));
251
+ const isExpired = Math.floor(Date.now() / 1000) >=
252
+ Number(old.startTimestamp) + Number(old.durationDays) * SECONDS_PER_DAY;
253
+ const isSameExtraData = old.extraData === extraData;
254
+ const isSameVerifyContract = oldPermit.eip712.domain.verifyingContract === sysContractInfo.decryptionContractAddress;
255
+ const isValid = isSamePublicKey && isContractSubset && !isExpired && isSameExtraData && isSameVerifyContract;
256
+ logger.debug('[getOrCreateTKeyPairWithPermit] Cache validation results', {
257
+ isSamePublicKey,
258
+ isContractSubset,
259
+ isExpired,
260
+ isSameExtraData,
261
+ isSameVerifyContract,
262
+ isValid,
263
+ });
264
+ // Return cached permit if all validations pass
265
+ if (isValid) {
266
+ logger.debug('[getOrCreateTKeyPairWithPermit] Valid permit found in cache');
267
+ return {
268
+ keypair,
269
+ permit: oldPermit,
270
+ };
271
+ }
272
+ uniqueContractAddresses = [...new Set([...old.contractAddresses, ...contractAddresses])];
273
+ logger.debug('[getOrCreateTKeyPairWithPermit] Cached permit invalid, generating new one.', {
274
+ contractAddresses: uniqueContractAddresses,
275
+ });
276
+ }
277
+ catch (error) {
278
+ logger.warn('[getOrCreateTKeyPairWithPermit] Failed to parse cached permit', {
279
+ error: error.message,
280
+ });
281
+ }
282
+ }
283
+ else {
284
+ logger.debug('[getOrCreateTKeyPairWithPermit] No cached permit found');
285
+ }
286
+ // ============================================================================
287
+ // Step 5: Sign New Permit
288
+ // ============================================================================
289
+ const now = Math.floor(Date.now() / 1000);
290
+ const PERMIT_TTL_DAYS = sdk.config.permitTTL ?? DEFAULT_PERMIT_TTL_DAYS;
291
+ logger.debug('[getOrCreateTKeyPairWithPermit] Signing new permit', {
292
+ contractAddresses: uniqueContractAddresses,
293
+ startTimestamp: now,
294
+ durationDays: PERMIT_TTL_DAYS,
295
+ signerAddress,
296
+ });
297
+ const permit = await signDecryptionPermit(sdk, {
298
+ contractAddresses: uniqueContractAddresses,
299
+ startTimestamp: now,
300
+ durationDays: PERMIT_TTL_DAYS,
301
+ signerAddress,
302
+ transportKeyPair: keypair,
303
+ signer
304
+ });
305
+ // ============================================================================
306
+ // Step 6: Save New Permit to Cache
307
+ // ============================================================================
308
+ await sdk.cacheManager.save(permitKey, JSONWithBigInt.stringify(permit));
309
+ logger.debug('[getOrCreateTKeyPairWithPermit] New permit signed and cached', {
310
+ permitKey,
311
+ startTimestamp: now,
312
+ durationDays: PERMIT_TTL_DAYS,
313
+ });
314
+ return {
315
+ keypair,
316
+ permit,
317
+ };
318
+ }
319
+ //# sourceMappingURL=permit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/jazz/permit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAoB,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AA4HvD,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAA8B;IAClE,YA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AuB;QAC1C,cAAc,EAAE,GAAG;QACnB,YAAY,EAAE,eAAe;QAC7B,aAAa;QACb,gBAAgB,EAAE,OAAO;QACzB,MAAM;KACP,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mCAAmC;IACnC,+EAA+E;IAE/E,MAAM,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzE,MAAM,CAAC,KAAK,CAAC,8DAA8D,EAAE;QAC3E,SAAS;QACT,cAAc,EAAE,GAAG;QACnB,YAAY,EAAE,eAAe;KAC9B,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { Address, Bytes32Hex, BytesHex } from "../core/primitives.js";
2
+ import { FetchPublicDecryptResult } from "./types/public-decrypt.js";
3
+ import type { IJazzClient } from "./jazz-client-i.js";
4
+ /**
5
+ * EIP-712 message for KMS public decryption.
6
+ */
7
+ export type KmsPublicDecryptEip712Message = Readonly<{
8
+ /** List of ciphertext handles (32-byte hex with 0x prefix) */
9
+ ctHandles: readonly Bytes32Hex[];
10
+ /** Decrypted result as hex with 0x prefix */
11
+ decryptedResult: BytesHex;
12
+ /** Additional contextual data as hex with 0x prefix */
13
+ extraData: BytesHex;
14
+ }>;
15
+ /**
16
+ * EIP-712 type definitions for KMS public decryption.
17
+ */
18
+ export type KmsPublicDecryptEip712Types = {
19
+ readonly EIP712Domain: readonly [
20
+ {
21
+ readonly name: 'name';
22
+ readonly type: 'string';
23
+ },
24
+ {
25
+ readonly name: 'version';
26
+ readonly type: 'string';
27
+ },
28
+ {
29
+ readonly name: 'chainId';
30
+ readonly type: 'uint256';
31
+ },
32
+ {
33
+ readonly name: 'verifyingContract';
34
+ readonly type: 'address';
35
+ }
36
+ ];
37
+ readonly PublicDecryptSignData: readonly [
38
+ {
39
+ readonly name: 'ctHandles';
40
+ readonly type: 'bytes32[]';
41
+ },
42
+ {
43
+ readonly name: 'decryptedResult';
44
+ readonly type: 'bytes';
45
+ },
46
+ {
47
+ readonly name: 'extraData';
48
+ readonly type: 'bytes';
49
+ }
50
+ ];
51
+ };
52
+ /**
53
+ * EIP-712 type definitions for KMS public decryption.
54
+ *
55
+ * CRITICAL: Field order is authoritative — it determines the EIP-712 type hash.
56
+ * Changing the order will produce a different signature and break on-chain verification.
57
+ * Must match the Solidity struct definition exactly.
58
+ */
59
+ export declare const kmsPublicDecryptEip712Types: KmsPublicDecryptEip712Types;
60
+ /**
61
+ * Verifies KMS public decryption EIP-712 signatures.
62
+ *
63
+ * This function:
64
+ * 1. Reconstructs the EIP-712 message from the result
65
+ * 2. Recovers the signer addresses from each signature
66
+ * 3. Verifies all recovered addresses are in the KMS signer set
67
+ * 4. Verifies the threshold is met
68
+ *
69
+ * @param client - The Jazz client instance
70
+ * @param params - Verification parameters (chainId, verifyingContract, handles)
71
+ * @param result - Public decryption result containing signatures and decrypted data
72
+ * @throws Error if verification fails (unknown signer, threshold not met, invalid signature)
73
+ */
74
+ export declare function verifyPublicDecryptionSignatures(client: IJazzClient, params: {
75
+ chainId: bigint;
76
+ verifyingContract: Address;
77
+ handles: BytesHex[];
78
+ }, result: FetchPublicDecryptResult): Promise<void>;
79
+ /**
80
+ * Creates a public decryption proof by encoding signatures and extra data.
81
+ *
82
+ * Format:
83
+ * Byte 0 : numSigners (uint8)
84
+ * Bytes 1 .. 65*N : N × 65-byte ECDSA signatures
85
+ * Bytes 65*N+1 .. end: extraData
86
+ *
87
+ * @param signatures - Array of signatures (hex strings with 0x prefix)
88
+ * @param extraData - Additional contextual data as Uint8Array
89
+ * @returns Encoded proof as Uint8Array
90
+ * @throws Error if numSigners exceeds 255 or signature length is invalid
91
+ */
92
+ export declare function createPublicDecryptionProof(signatures: string[], extraData: Uint8Array): Uint8Array;
93
+ export declare function checkPublicDecryptPermission(client: IJazzClient, params: {
94
+ aclContractAddress: Address;
95
+ ctHandles: BytesHex[];
96
+ }): Promise<void>;