@inco/js 0.1.29 → 0.1.31-alpha

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 (181) hide show
  1. package/dist/binary.js +67 -0
  2. package/dist/binary.js.map +1 -0
  3. package/dist/chain.js +24 -0
  4. package/dist/chain.js.map +1 -0
  5. package/dist/encryption/encryption.js +98 -0
  6. package/dist/encryption/encryption.js.map +1 -0
  7. package/dist/encryption/index.js +2 -0
  8. package/dist/encryption/index.js.map +1 -0
  9. package/dist/fhevm/fhe-environment.js +8 -0
  10. package/dist/fhevm/fhe-environment.js.map +1 -0
  11. package/dist/fhevm/fhevm.js +139 -0
  12. package/dist/fhevm/fhevm.js.map +1 -0
  13. package/dist/fhevm/index.js +2 -0
  14. package/dist/fhevm/index.js.map +1 -0
  15. package/dist/fhevm/reencrypt.js +123 -0
  16. package/dist/fhevm/reencrypt.js.map +1 -0
  17. package/dist/fhevm/tfhe.js +324 -0
  18. package/dist/fhevm/tfhe.js.map +1 -0
  19. package/dist/fhevm/types.js +26 -0
  20. package/dist/fhevm/types.js.map +1 -0
  21. package/dist/generated/abis/addTwo.js +59 -0
  22. package/dist/generated/abis/addTwo.js.map +1 -0
  23. package/dist/generated/abis/inco-fhevm.js +6242 -0
  24. package/dist/generated/abis/inco-fhevm.js.map +1 -0
  25. package/dist/generated/abis/index.js +3 -0
  26. package/dist/generated/abis/index.js.map +1 -0
  27. package/dist/generated/abis/lightning.js +12489 -0
  28. package/dist/generated/abis/lightning.js.map +1 -0
  29. package/dist/generated/es/cosmos/ics23/v1/proofs_pb.js +198 -0
  30. package/dist/generated/es/cosmos/ics23/v1/proofs_pb.js.map +1 -0
  31. package/dist/generated/es/cosmos/msg/v1/msg_pb.js +33 -0
  32. package/dist/generated/es/cosmos/msg/v1/msg_pb.js.map +1 -0
  33. package/dist/generated/es/cosmos_proto/cosmos_pb.js +115 -0
  34. package/dist/generated/es/cosmos_proto/cosmos_pb.js.map +1 -0
  35. package/dist/generated/es/google/api/annotations_pb.js +27 -0
  36. package/dist/generated/es/google/api/annotations_pb.js.map +1 -0
  37. package/dist/generated/es/google/api/http_pb.js +34 -0
  38. package/dist/generated/es/google/api/http_pb.js.map +1 -0
  39. package/dist/generated/es/inco/fhe/v1/events_pb.js +21 -0
  40. package/dist/generated/es/inco/fhe/v1/events_pb.js.map +1 -0
  41. package/dist/generated/es/inco/fhe/v1/genesis_pb.js +46 -0
  42. package/dist/generated/es/inco/fhe/v1/genesis_pb.js.map +1 -0
  43. package/dist/generated/es/inco/fhe/v1/query_pb.js +108 -0
  44. package/dist/generated/es/inco/fhe/v1/query_pb.js.map +1 -0
  45. package/dist/generated/es/inco/fhe/v1/tx_pb.js +108 -0
  46. package/dist/generated/es/inco/fhe/v1/tx_pb.js.map +1 -0
  47. package/dist/generated/es/inco/fhe/v1/types_pb.js +133 -0
  48. package/dist/generated/es/inco/fhe/v1/types_pb.js.map +1 -0
  49. package/dist/generated/es/inco/kms/lite/v1/kms_service_pb.js +43 -0
  50. package/dist/generated/es/inco/kms/lite/v1/kms_service_pb.js.map +1 -0
  51. package/dist/generated/es/inco/kms/lite/v1/types_pb.js +44 -0
  52. package/dist/generated/es/inco/kms/lite/v1/types_pb.js.map +1 -0
  53. package/dist/generated/es/inco/preflight/v1/genesis_pb.js +20 -0
  54. package/dist/generated/es/inco/preflight/v1/genesis_pb.js.map +1 -0
  55. package/dist/generated/es/inco/preflight/v1/query_pb.js +38 -0
  56. package/dist/generated/es/inco/preflight/v1/query_pb.js.map +1 -0
  57. package/dist/generated/es/inco/preflight/v1/tx_pb.js +48 -0
  58. package/dist/generated/es/inco/preflight/v1/tx_pb.js.map +1 -0
  59. package/dist/generated/es/inco/preflight/v1/types_pb.js +34 -0
  60. package/dist/generated/es/inco/preflight/v1/types_pb.js.map +1 -0
  61. package/dist/generated/es/kms/base_pb.js +238 -0
  62. package/dist/generated/es/kms/base_pb.js.map +1 -0
  63. package/dist/generated/es/sf/ethereum/type/v2/type_pb.js +571 -0
  64. package/dist/generated/es/sf/ethereum/type/v2/type_pb.js.map +1 -0
  65. package/dist/generated/fhe-environments.js +15 -0
  66. package/dist/generated/fhe-environments.js.map +1 -0
  67. package/dist/generated/lightning.js +399 -0
  68. package/dist/generated/lightning.js.map +1 -0
  69. package/dist/generated/local-node.d.ts +1 -0
  70. package/dist/generated/local-node.js +8 -0
  71. package/dist/generated/local-node.js.map +1 -0
  72. package/dist/generated/ts/amino/amino.js +8 -0
  73. package/dist/generated/ts/amino/amino.js.map +1 -0
  74. package/dist/generated/ts/cometbft/abci/v1/types.js +5063 -0
  75. package/dist/generated/ts/cometbft/abci/v1/types.js.map +1 -0
  76. package/dist/generated/ts/cometbft/crypto/v1/keys.js +105 -0
  77. package/dist/generated/ts/cometbft/crypto/v1/keys.js.map +1 -0
  78. package/dist/generated/ts/cometbft/crypto/v1/proof.js +430 -0
  79. package/dist/generated/ts/cometbft/crypto/v1/proof.js.map +1 -0
  80. package/dist/generated/ts/cometbft/types/v1/params.js +713 -0
  81. package/dist/generated/ts/cometbft/types/v1/params.js.map +1 -0
  82. package/dist/generated/ts/cometbft/types/v1/validator.js +353 -0
  83. package/dist/generated/ts/cometbft/types/v1/validator.js.map +1 -0
  84. package/dist/generated/ts/cosmos/app/v1alpha1/module.js +218 -0
  85. package/dist/generated/ts/cosmos/app/v1alpha1/module.js.map +1 -0
  86. package/dist/generated/ts/cosmos/msg/v1/msg.js +8 -0
  87. package/dist/generated/ts/cosmos/msg/v1/msg.js.map +1 -0
  88. package/dist/generated/ts/cosmos_proto/cosmos.js +211 -0
  89. package/dist/generated/ts/cosmos_proto/cosmos.js.map +1 -0
  90. package/dist/generated/ts/gogoproto/gogo.js +8 -0
  91. package/dist/generated/ts/gogoproto/gogo.js.map +1 -0
  92. package/dist/generated/ts/google/api/annotations.js +8 -0
  93. package/dist/generated/ts/google/api/annotations.js.map +1 -0
  94. package/dist/generated/ts/google/api/http.js +353 -0
  95. package/dist/generated/ts/google/api/http.js.map +1 -0
  96. package/dist/generated/ts/google/protobuf/descriptor.js +5070 -0
  97. package/dist/generated/ts/google/protobuf/descriptor.js.map +1 -0
  98. package/dist/generated/ts/google/protobuf/duration.js +90 -0
  99. package/dist/generated/ts/google/protobuf/duration.js.map +1 -0
  100. package/dist/generated/ts/google/protobuf/timestamp.js +90 -0
  101. package/dist/generated/ts/google/protobuf/timestamp.js.map +1 -0
  102. package/dist/generated/ts/google/protobuf/wrappers.js +506 -0
  103. package/dist/generated/ts/google/protobuf/wrappers.js.map +1 -0
  104. package/dist/generated/ts/inco/abci/v1/types.js +70 -0
  105. package/dist/generated/ts/inco/abci/v1/types.js.map +1 -0
  106. package/dist/generated/ts/inco/fhe/module/v1/module.js +63 -0
  107. package/dist/generated/ts/inco/fhe/module/v1/module.js.map +1 -0
  108. package/dist/generated/ts/inco/fhe/v1/events.js +187 -0
  109. package/dist/generated/ts/inco/fhe/v1/events.js.map +1 -0
  110. package/dist/generated/ts/inco/fhe/v1/genesis.js +711 -0
  111. package/dist/generated/ts/inco/fhe/v1/genesis.js.map +1 -0
  112. package/dist/generated/ts/inco/fhe/v1/query.js +1391 -0
  113. package/dist/generated/ts/inco/fhe/v1/query.js.map +1 -0
  114. package/dist/generated/ts/inco/fhe/v1/tx.js +1233 -0
  115. package/dist/generated/ts/inco/fhe/v1/tx.js.map +1 -0
  116. package/dist/generated/ts/inco/fhe/v1/types.js +985 -0
  117. package/dist/generated/ts/inco/fhe/v1/types.js.map +1 -0
  118. package/dist/generated/ts/inco/originchain/module/v1/module.js +63 -0
  119. package/dist/generated/ts/inco/originchain/module/v1/module.js.map +1 -0
  120. package/dist/generated/ts/inco/originchain/v1/abci.js +328 -0
  121. package/dist/generated/ts/inco/originchain/v1/abci.js.map +1 -0
  122. package/dist/generated/ts/inco/originchain/v1/events.js +213 -0
  123. package/dist/generated/ts/inco/originchain/v1/events.js.map +1 -0
  124. package/dist/generated/ts/inco/originchain/v1/genesis.js +66 -0
  125. package/dist/generated/ts/inco/originchain/v1/genesis.js.map +1 -0
  126. package/dist/generated/ts/inco/originchain/v1/query.js +277 -0
  127. package/dist/generated/ts/inco/originchain/v1/query.js.map +1 -0
  128. package/dist/generated/ts/inco/originchain/v1/tx.js +137 -0
  129. package/dist/generated/ts/inco/originchain/v1/tx.js.map +1 -0
  130. package/dist/generated/ts/inco/originchain/v1/types.js +200 -0
  131. package/dist/generated/ts/inco/originchain/v1/types.js.map +1 -0
  132. package/dist/generated/ts/inco/preflight/module/v1/module.js +63 -0
  133. package/dist/generated/ts/inco/preflight/module/v1/module.js.map +1 -0
  134. package/dist/generated/ts/inco/preflight/v1/genesis.js +182 -0
  135. package/dist/generated/ts/inco/preflight/v1/genesis.js.map +1 -0
  136. package/dist/generated/ts/inco/preflight/v1/query.js +256 -0
  137. package/dist/generated/ts/inco/preflight/v1/query.js.map +1 -0
  138. package/dist/generated/ts/inco/preflight/v1/tx.js +445 -0
  139. package/dist/generated/ts/inco/preflight/v1/tx.js.map +1 -0
  140. package/dist/generated/ts/inco/preflight/v1/types.js +395 -0
  141. package/dist/generated/ts/inco/preflight/v1/types.js.map +1 -0
  142. package/dist/handle.js +94 -0
  143. package/dist/handle.js.map +1 -0
  144. package/dist/index.js +6 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/l1/client.js +93 -0
  147. package/dist/l1/client.js.map +1 -0
  148. package/dist/l1/index.js +3 -0
  149. package/dist/l1/index.js.map +1 -0
  150. package/dist/l1/preflight.js +39 -0
  151. package/dist/l1/preflight.js.map +1 -0
  152. package/dist/lite/deployments.js +17 -0
  153. package/dist/lite/deployments.js.map +1 -0
  154. package/dist/lite/ecies.js +124 -0
  155. package/dist/lite/ecies.js.map +1 -0
  156. package/dist/lite/hadu.js +36 -0
  157. package/dist/lite/hadu.js.map +1 -0
  158. package/dist/lite/index.cjs +4 -7
  159. package/dist/lite/index.js +7 -0
  160. package/dist/lite/index.js.map +1 -0
  161. package/dist/lite/index.mjs +4 -7
  162. package/dist/lite/lightning.d.ts +6 -6
  163. package/dist/lite/lightning.js +179 -0
  164. package/dist/lite/lightning.js.map +1 -0
  165. package/dist/lite/reencrypt.js +129 -0
  166. package/dist/lite/reencrypt.js.map +1 -0
  167. package/dist/local/index.js +2 -0
  168. package/dist/local/index.js.map +1 -0
  169. package/dist/local/local-node.js +24 -0
  170. package/dist/local/local-node.js.map +1 -0
  171. package/dist/reencryption/eip712.js +81 -0
  172. package/dist/reencryption/eip712.js.map +1 -0
  173. package/dist/reencryption/index.js +3 -0
  174. package/dist/reencryption/index.js.map +1 -0
  175. package/dist/reencryption/types.js +2 -0
  176. package/dist/reencryption/types.js.map +1 -0
  177. package/dist/schema.js +15 -0
  178. package/dist/schema.js.map +1 -0
  179. package/dist/viem.js +8 -0
  180. package/dist/viem.js.map +1 -0
  181. package/package.json +10 -44
@@ -0,0 +1,39 @@
1
+ import { Schema } from 'effect';
2
+ import { Bytes32, bytesFromHexString } from '../binary';
3
+ import { MsgRegisterInput } from '../generated/ts/inco/preflight/v1/tx';
4
+ import { computeHandle } from '../handle';
5
+ import { parse } from '../schema';
6
+ import { createL1Client } from './client';
7
+ // Do not export this value, only allow parsing of Handle to happen here
8
+ const Handle = Bytes32.pipe(Schema.brand('Handle'));
9
+ // Sends a preflight input to the Cosmos L1 chain using CosmJS.
10
+ export async function cosmJSPreflight({ cometRpcEndpoint, grpcEndpoint, wallet, signerAddress, }) {
11
+ const l1Client = await createL1Client({ cometRpcEndpoint, wallet, grpcEndpoint });
12
+ return {
13
+ async send({ prehandle, ciphertext, context }) {
14
+ const msg = MsgRegisterInput.create({
15
+ prehandle: Buffer.from(prehandle.replace(/^0x/, ''), 'hex'),
16
+ signer: signerAddress,
17
+ ciphertext: Buffer.from(ciphertext.value, 'hex'),
18
+ context: {
19
+ ownerAddr: context.userAddress.replace(/^0x/, ''),
20
+ contractAddr: context.contractAddress.replace(/^0x/, ''),
21
+ // We decided to put the ACL address in the keyset ID field.
22
+ keysetId: context.aclAddress.replace(/^0x/, ''),
23
+ hostChainId: 'evm/' + context.hostChainId,
24
+ },
25
+ });
26
+ // There are some hidden dependencies needed to make the following line work:
27
+ //
28
+ // 1. The signer must have an account on the chain. In Cosmos, this is
29
+ // usually done by sending some tokens to the account. However, since the
30
+ // fees are 0, this account doesn't need to have any tokens.
31
+ // 2. The FheEnv must have been created in the on-chain registry. Only the
32
+ // council can add new FheEnvs to the registry.
33
+ const result = await l1Client.sendTx(signerAddress, '/inco.preflight.v1.MsgRegisterInput', msg);
34
+ const handle = computeHandle({ prehandle: bytesFromHexString(prehandle), context });
35
+ return { transactionHash: result.transactionHash, handle: parse(Handle, handle) };
36
+ },
37
+ };
38
+ }
39
+ //# sourceMappingURL=preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/l1/preflight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAqB,MAAM,UAAU,CAAC;AAE7D,wEAAwE;AACxE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AAsBpD,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EACpC,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,aAAa,GAC4B;IACzC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAElF,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAoB;YAC7D,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC;gBAClC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC;gBAC3D,MAAM,EAAE,aAAa;gBACrB,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC;gBAChD,OAAO,EAAE;oBACP,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oBACjD,YAAY,EAAE,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oBACxD,4DAA4D;oBAC5D,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oBAC/C,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW;iBAC1C;aACF,CAAC,CAAC;YAEH,6EAA6E;YAC7E,EAAE;YACF,sEAAsE;YACtE,yEAAyE;YACzE,4DAA4D;YAC5D,0EAA0E;YAC1E,+CAA+C;YAC/C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,qCAAqC,EAAE,GAAG,CAAC,CAAC;YAEhG,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;YACpF,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QACpF,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ // Avoid inporting any other dependencies in this file to avoid serialisation issues downstream in infracto
2
+ import { getSupportedChain } from '../chain';
3
+ import { lightningDeployments } from '../generated/lightning';
4
+ export function getActiveLightningDeployment(chain) {
5
+ const supportedChain = getSupportedChain(chain);
6
+ const deployments = lightningDeployments.filter((d) => d.chainId === supportedChain.id);
7
+ if (!deployments?.length) {
8
+ throw new Error(`No deployments found for chain ${chain}`);
9
+ }
10
+ return deployments[0];
11
+ }
12
+ export function getLightningDeployments(chainId) {
13
+ const supportedChain = getSupportedChain(chainId);
14
+ const deployments = lightningDeployments.filter((d) => d.chainId === supportedChain.id);
15
+ return deployments ?? [];
16
+ }
17
+ //# sourceMappingURL=deployments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployments.js","sourceRoot":"","sources":["../../src/lite/deployments.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,OAAO,EAAY,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAO9D,MAAM,UAAU,4BAA4B,CAAC,KAAe;IAC1D,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,cAAc,CAAC,EAAE,CAAC,CAAC;IACxF,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAiB;IACvD,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,cAAc,CAAC,EAAE,CAAC,CAAC;IACxF,OAAO,WAAW,IAAI,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,124 @@
1
+ import { decrypt as eciesDecrypt, encrypt as eciesEncrypt } from 'ecies-geth';
2
+ import { ec } from 'elliptic';
3
+ import { asBytes32, bytes32ToBigint, bytesFromHexString, bytesToHex } from '../binary';
4
+ import { bigintToPlaintext, ciphertextEnvelopes, encryptionSchemes, getEncryptionSchemeName, } from '../encryption/encryption';
5
+ import { computeHandle, computePrehandle } from '../handle';
6
+ import { decodeInput, encodeInput } from './hadu';
7
+ const secp256k1 = new ec('secp256k1');
8
+ // Convert an ec.KeyPair from the 'elliptic' package (assumed to have geen generated
9
+ // with the secp256k1 curve) to our Secp256k1Keypair type.
10
+ export function toSecp256k1Keypair(kp) {
11
+ return {
12
+ scheme: encryptionSchemes.ecies,
13
+ kp,
14
+ encodePublicKey() {
15
+ return new Uint8Array(kp.getPublic().encode('array', false));
16
+ },
17
+ };
18
+ }
19
+ // Generate a new ephemeral keypair for reencryption.
20
+ export function generateSecp256k1Keypair() {
21
+ return toSecp256k1Keypair(secp256k1.genKeyPair());
22
+ }
23
+ // EncodePublicKey encodes an ECIES public key it's 33-byte compressed form.
24
+ export function encodeSecp256k1PublicKey(pub) {
25
+ return new Uint8Array(pub.encodeCompressed('array'));
26
+ }
27
+ // DecodeSecp256k1PublicKey decodes a 33-byte compressed ECIES public key.
28
+ export function decodeSecp256k1PublicKey(pubKeyCompressed) {
29
+ return secp256k1.keyFromPublic(pubKeyCompressed, 'array').getPublic();
30
+ }
31
+ // DecodeSecp256k1PrivateKey returns a ECIES secp256k1 private key based on the provided byte slice which is
32
+ // interpreted as an unsigned 256-bit big-endian integer in the range [0, N-1],
33
+ // where N is the order of the curve.
34
+ // where N is the order of the curve.
35
+ //
36
+ // WARNING: This means passing a slice with more than 32 bytes is truncated and
37
+ // that truncated value is reduced modulo N. Further, 0 is not a valid private
38
+ // key. It is up to the caller to provide a value in the appropriate range of
39
+ // [1, N-1]. Failure to do so will either result in an invalid private key or
40
+ // potentially weak private keys that have bias that could be exploited.
41
+ //
42
+ // This function primarily exists to provide a mechanism for converting
43
+ // serialized private keys that are already known to be good.
44
+ //
45
+ // For more info, refer to the decred/dcrd documentation:
46
+ // ref: https://pkg.go.dev/github.com/decred/dcrd/dcrec/secp256k1/v4@v4.2.0#PrivKeyFromBytes
47
+ //
48
+ // We don't include any curve parameters or ECIES params, as they are assumed to
49
+ // be the ones in ecies.ECIES_AES128_SHA256 from go-ethereum.
50
+ // ref: https://github.com/ethereum/go-ethereum/blob/v1.15.0/crypto/ecies/params.go#L76-L82
51
+ export function decodeSecp256k1PrivateKey(privKey) {
52
+ return toSecp256k1Keypair(secp256k1.keyFromPrivate(privKey, 'array'));
53
+ }
54
+ // Given a (usually 3rd-party known) public key, called `pubKeyA`, and an ephemeral
55
+ // private key (usually generated locally), called `privKeyB`, encrypt the `msg`
56
+ // using ECIES, with geth's parameters:
57
+ // ref: https://github.com/ethereum/go-ethereum/blob/v1.15.2/crypto/ecies/ecies.go
58
+ export async function encrypt(pubKeyA, plaintext, privKeyB) {
59
+ const pubKeyABuffer = Buffer.from(pubKeyA.encode('array', false));
60
+ const privKeyBBuffer = privKeyB.kp.getPrivate().toArrayLike(Buffer, 'be', 32);
61
+ const ct = await eciesEncrypt(pubKeyABuffer, Buffer.from(plaintext), {
62
+ ephemPrivateKey: privKeyBBuffer,
63
+ });
64
+ return new Uint8Array(ct);
65
+ }
66
+ export function getEciesEncryptor({ pubKeyA, privKeyB }) {
67
+ const pubKeyABuffer = Buffer.from(pubKeyA.encode('array', false));
68
+ const privKeyBBuffer = privKeyB.kp.getPrivate().toArrayLike(Buffer, 'be', 32);
69
+ return async ({ plaintext, context, }) => {
70
+ if (plaintext.scheme !== encryptionSchemes.ecies) {
71
+ throw new Error(`Plaintext with scheme ${getEncryptionSchemeName(plaintext.scheme)} cannot be encrypted with ECIES`);
72
+ }
73
+ const ptBuf = Buffer.from(encodeInput({ plaintext, context }));
74
+ const ct = await eciesEncrypt(pubKeyABuffer, ptBuf, {
75
+ ephemPrivateKey: privKeyBBuffer,
76
+ });
77
+ const prehandle = computePrehandle({
78
+ ciphertext: ct,
79
+ handleType: plaintext.type,
80
+ indexHandle: 0,
81
+ handleVersion: 0,
82
+ });
83
+ const handle = computeHandle({
84
+ prehandle,
85
+ context: context,
86
+ });
87
+ return {
88
+ prehandle: asBytes32(prehandle),
89
+ handle: asBytes32(handle),
90
+ context,
91
+ ciphertext: {
92
+ scheme: encryptionSchemes.ecies,
93
+ type: plaintext.type,
94
+ value: bytesToHex(ct),
95
+ },
96
+ };
97
+ };
98
+ }
99
+ // Given an ephemeral private key, called `privKeyA`, and a ciphertext `ct`,
100
+ // decrypt the ciphertext using ECIES, with geth's parameters:
101
+ // ref: https://github.com/ethereum/go-ethereum/blob/v1.15.2/crypto/ecies/ecies.go
102
+ export async function decrypt(privKeyA, ciphertext) {
103
+ const privKeyABuffer = privKeyA.kp.getPrivate().toArrayLike(Buffer, 'be', 32);
104
+ const pt = await eciesDecrypt(privKeyABuffer, Buffer.from(ciphertext));
105
+ return new Uint8Array(pt);
106
+ }
107
+ export function getEciesDecryptor({ privKeyA }) {
108
+ const privKeyABuffer = privKeyA.kp.getPrivate().toArrayLike(Buffer, 'be', 32);
109
+ return async ({ scheme, type, value, envelope, }) => {
110
+ if (scheme !== encryptionSchemes.ecies) {
111
+ throw new Error(`Ciphertext with scheme ${getEncryptionSchemeName(scheme)} cannot be decrypted with ECIES`);
112
+ }
113
+ const ptBuf = await eciesDecrypt(privKeyABuffer, bytesFromHexString(value));
114
+ // If envelope field is omitted then assume HADU, only with an explicit none envelope do we assume a raw byte
115
+ // encoding as would be performed by the compute server
116
+ if (envelope === ciphertextEnvelopes.none) {
117
+ const bigPt = bytes32ToBigint(Buffer.from(ptBuf).toString('hex'));
118
+ return bigintToPlaintext(scheme, type, bigPt);
119
+ }
120
+ const { plaintext } = decodeInput(ptBuf.toString());
121
+ return plaintext;
122
+ };
123
+ }
124
+ //# sourceMappingURL=ecies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecies.js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{ parseJson } from 'effect/Schema';
3
+ import { Bytes32 } from '../binary';
4
+ import { bytes32ToPlaintext, EncryptionScheme, plaintextToBytes32, SupportedFheType, } from '../encryption';
5
+ import { InputContext } from '../handle';
6
+ // HADU stands for "Host Chain, ACL, DApp, and User" it maps to the InputContext type where the aclAddress
7
+ // may actually be the singular IncoLite contract which embeds its own ACL
8
+ export const encryptionEnvelopes = {
9
+ none: 0,
10
+ hadu: 1,
11
+ };
12
+ export const EncryptionEnvelope = Schema.Literal(...Object.values(encryptionEnvelopes));
13
+ export const HaduInput = parseJson(Schema.Struct({
14
+ envelope: Schema.Literal(encryptionEnvelopes.hadu),
15
+ scheme: EncryptionScheme,
16
+ context: InputContext,
17
+ plaintext: Bytes32,
18
+ type: SupportedFheType,
19
+ }));
20
+ export function encodeInput({ plaintext, context }) {
21
+ return Schema.encodeSync(HaduInput)({
22
+ envelope: encryptionEnvelopes.hadu,
23
+ scheme: plaintext.scheme,
24
+ type: plaintext.type,
25
+ plaintext: plaintextToBytes32(plaintext),
26
+ context,
27
+ });
28
+ }
29
+ export function decodeInput(json) {
30
+ const { scheme, context, plaintext, type } = Schema.decodeSync(HaduInput)(json);
31
+ return {
32
+ plaintext: bytes32ToPlaintext(plaintext, scheme, type),
33
+ context,
34
+ };
35
+ }
36
+ //# sourceMappingURL=hadu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hadu.js","sourceRoot":"","sources":["../../src/lite/hadu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAElB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,0GAA0G;AAC1G,0EAA0E;AAE1E,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACC,CAAC;AAKX,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAChC,MAAM,CAAC,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;IAClD,MAAM,EAAE,gBAAgB;IACxB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,OAAO;IAClB,IAAI,EAAE,gBAAgB;CACvB,CAAC,CACH,CAAC;AAIF,MAAM,UAAU,WAAW,CAAC,EAAE,SAAS,EAAE,OAAO,EAAwB;IACtE,OAAO,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClC,QAAQ,EAAE,mBAAmB,CAAC,IAAI;QAClC,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC;QACxC,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;IAChF,OAAO;QACL,SAAS,EAAE,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC;QACtD,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -47303,7 +47303,8 @@ var localNodeLightningConfig = {
47303
47303
  executorAddress: "0x63D8135aF4D393B1dB43B649010c8D3EE19FC9fd",
47304
47304
  eciesPublicKey: "0x026812a7776af85b464bbcffb2227f8859338c4726f896cf47a12406467f9dc8ab",
47305
47305
  chainId: 31337,
47306
- covalidatorUrl: "http://localhost:50055"
47306
+ covalidatorUrl: "http://localhost:50055",
47307
+ senderPrivateKey: "0x5e537a659b227da26561c436c9b8b9e286fe99a6f462b0a282bfbec9595dee26"
47307
47308
  };
47308
47309
 
47309
47310
  // ../node_modules/@connectrpc/connect/dist/esm/code.js
@@ -52725,12 +52726,8 @@ class Lightning {
52725
52726
  }
52726
52727
  return new Lightning(deployment, Lightning.getCovalidatorUrl(deployment));
52727
52728
  }
52728
- static custom({ executorAddress, eciesPublicKey, chainId, covalidatorUrl }) {
52729
- return new Lightning({
52730
- chainId,
52731
- executorAddress,
52732
- eciesPublicKey
52733
- }, covalidatorUrl);
52729
+ static custom(config2) {
52730
+ return new Lightning(config2, config2.covalidatorUrl);
52734
52731
  }
52735
52732
  static latestDeployment(pepper, chainId) {
52736
52733
  const latestByPepper = lightningDeployments.find((d) => d.pepper === pepper && d.chainId === chainId);
@@ -0,0 +1,7 @@
1
+ export * from '../generated/abis/lightning';
2
+ export * from './deployments';
3
+ export * from './ecies';
4
+ export * from './hadu';
5
+ export * from './lightning';
6
+ export * from './reencrypt';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAE5C,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -66127,7 +66127,8 @@ var localNodeLightningConfig = {
66127
66127
  executorAddress: "0x63D8135aF4D393B1dB43B649010c8D3EE19FC9fd",
66128
66128
  eciesPublicKey: "0x026812a7776af85b464bbcffb2227f8859338c4726f896cf47a12406467f9dc8ab",
66129
66129
  chainId: 31337,
66130
- covalidatorUrl: "http://localhost:50055"
66130
+ covalidatorUrl: "http://localhost:50055",
66131
+ senderPrivateKey: "0x5e537a659b227da26561c436c9b8b9e286fe99a6f462b0a282bfbec9595dee26"
66131
66132
  };
66132
66133
 
66133
66134
  // ../node_modules/@connectrpc/connect/dist/esm/code.js
@@ -71549,12 +71550,8 @@ class Lightning {
71549
71550
  }
71550
71551
  return new Lightning(deployment, Lightning.getCovalidatorUrl(deployment));
71551
71552
  }
71552
- static custom({ executorAddress, eciesPublicKey, chainId, covalidatorUrl }) {
71553
- return new Lightning({
71554
- chainId,
71555
- executorAddress,
71556
- eciesPublicKey
71557
- }, covalidatorUrl);
71553
+ static custom(config2) {
71554
+ return new Lightning(config2, config2.covalidatorUrl);
71558
71555
  }
71559
71556
  static latestDeployment(pepper, chainId) {
71560
71557
  const latestByPepper = lightningDeployments.find((d) => d.pepper === pepper && d.chainId === chainId);
@@ -2,6 +2,7 @@ import { Account, Chain, Transport, WalletClient } from 'viem';
2
2
  import { Address, HexString } from '../binary';
3
3
  import { EciesScheme } from '../encryption';
4
4
  import { lightningDeployments } from '../generated/lightning';
5
+ import { localNodeLightningConfig } from '../generated/local-node';
5
6
  import type { Reencryptor } from '../reencryption';
6
7
  type TupleToUnion<T> = T extends readonly unknown[] ? T[number] : never;
7
8
  type Deployment = TupleToUnion<typeof lightningDeployments>;
@@ -26,6 +27,7 @@ export type CustomConfig = {
26
27
  eciesPublicKey: string;
27
28
  chainId: number;
28
29
  covalidatorUrl: string;
30
+ senderPrivateKey?: HexString;
29
31
  };
30
32
  /**
31
33
  * The Lightning class provides a convenient way to interact with the Inco Lightning contract by binding to a specific
@@ -55,7 +57,7 @@ export declare class Lightning<T extends DeploymentSlice = DeploymentSlice> {
55
57
  * See the sample docker-compose file here: https://github.com/Inco-fhevm/lightning-rod/blob/main/docker-compose.yaml
56
58
  *
57
59
  */
58
- static localNode(): Lightning;
60
+ static localNode(): Lightning<DeploymentSlice & typeof localNodeLightningConfig>;
59
61
  /**
60
62
  * Get a Lightning deployment by name or executor address on a particular chain.
61
63
  *
@@ -65,12 +67,10 @@ export declare class Lightning<T extends DeploymentSlice = DeploymentSlice> {
65
67
  /**
66
68
  * Get a Lightning deployment for a local or custom node
67
69
  *
68
- * @param executorAddress the address of the executor contract on the host chain
69
- * @param eciesPublicKey the public ECIES key of the Lightning deployment used for encryption
70
- * @param chainId the chainId of the host chain
71
- * @param covalidatorUrl the gRPC endpoint of the covalidator
70
+ * @param config this is an object containing the executorAddress, eciesPublicKey, chainId and covalidatorUrl.
71
+ * additional fields past will be made available as part of the `deployment` property.
72
72
  */
73
- static custom({ executorAddress, eciesPublicKey, chainId, covalidatorUrl }: CustomConfig): Lightning;
73
+ static custom<T extends CustomConfig>(config: T): Lightning<DeploymentSlice & T>;
74
74
  /**
75
75
  * Get the latest deployment for a given pepper, which usually denotes a family of deployments distinct from their
76
76
  * version such as 'devnet', 'testnet', 'mainnet', etc.
@@ -0,0 +1,179 @@
1
+ import { hexToBytes } from 'viem';
2
+ import { baseSepolia } from 'viem/chains';
3
+ import { HexString, parseAddress } from '../binary';
4
+ import { encryptionSchemes } from '../encryption';
5
+ import { lightningDeployments } from '../generated/lightning';
6
+ import { localNodeLightningConfig } from '../generated/local-node';
7
+ import { handleTypes } from '../handle';
8
+ import { parse } from '../schema';
9
+ import { decodeSecp256k1PublicKey, generateSecp256k1Keypair, getEciesEncryptor } from './ecies';
10
+ import { getKmsClient, incoLiteReencryptor } from './reencrypt';
11
+ /**
12
+ * The Lightning class provides a convenient way to interact with the Inco Lightning contract by binding to a specific
13
+ * deployment.
14
+ */
15
+ export class Lightning {
16
+ _deployment;
17
+ covalidatorUrl;
18
+ executorAddress;
19
+ eciesPublicKey;
20
+ chainId;
21
+ encryptor;
22
+ ephemeralKeypair;
23
+ kmsClient;
24
+ constructor(_deployment, covalidatorUrl) {
25
+ this._deployment = _deployment;
26
+ this.covalidatorUrl = covalidatorUrl;
27
+ this.executorAddress = parseAddress(_deployment.executorAddress);
28
+ this.eciesPublicKey = parse(HexString, _deployment.eciesPublicKey);
29
+ this.chainId = BigInt(_deployment.chainId);
30
+ this.ephemeralKeypair = generateSecp256k1Keypair();
31
+ this.kmsClient = getKmsClient(covalidatorUrl);
32
+ this.encryptor = getEciesEncryptor({
33
+ scheme: encryptionSchemes.ecies,
34
+ pubKeyA: decodeSecp256k1PublicKey(hexToBytes(parse(HexString, _deployment.eciesPublicKey))),
35
+ privKeyB: this.ephemeralKeypair,
36
+ });
37
+ }
38
+ /**
39
+ * Get a Lightning instance bound to the latest Lightning deployment for the Base Sepolia testnet.
40
+ */
41
+ static baseSepoliaTestnet() {
42
+ return Lightning.latest('testnet', baseSepolia.id);
43
+ }
44
+ /**
45
+ * Get a Lightning instance bound to our canonical Anvil-based test node and test Covalidator node
46
+ *
47
+ * These can be run in docker-compose using images pushed to dockerhub as:
48
+ * - inconetwork/local-node-anvil
49
+ * - inconetwork/local-node-covalidator
50
+ *
51
+ * See the sample docker-compose file here: https://github.com/Inco-fhevm/lightning-rod/blob/main/docker-compose.yaml
52
+ *
53
+ */
54
+ static localNode() {
55
+ return Lightning.custom(localNodeLightningConfig);
56
+ }
57
+ /**
58
+ * Get a Lightning deployment by name or executor address on a particular chain.
59
+ *
60
+ * @param id this is an object containing either the pair of name and chainId or the executorAddress and chainId
61
+ */
62
+ static at(id) {
63
+ const deployment = this.isIdByName(id)
64
+ ? lightningDeployments.find((d) => d.name === id.name && d.chainId === id.chainId)
65
+ : lightningDeployments.find((d) => d.executorAddress === id.executorAddress && d.chainId === id.chainId);
66
+ if (!deployment) {
67
+ throw new Error(`No deployment found for ${JSON.stringify(id)}`);
68
+ }
69
+ return new Lightning(deployment, Lightning.getCovalidatorUrl(deployment));
70
+ }
71
+ /**
72
+ * Get a Lightning deployment for a local or custom node
73
+ *
74
+ * @param config this is an object containing the executorAddress, eciesPublicKey, chainId and covalidatorUrl.
75
+ * additional fields past will be made available as part of the `deployment` property.
76
+ */
77
+ static custom(config) {
78
+ return new Lightning(config, config.covalidatorUrl);
79
+ }
80
+ /**
81
+ * Get the latest deployment for a given pepper, which usually denotes a family of deployments distinct from their
82
+ * version such as 'devnet', 'testnet', 'mainnet', etc.
83
+ *
84
+ * @param pepper the pepper to use to filter the deployments
85
+ * @param chainId the chainId to use to filter the deployments
86
+ */
87
+ static latestDeployment(pepper, chainId) {
88
+ // Deployments are sorted so we are guaranteed to get the latest first
89
+ const latestByPepper = lightningDeployments.find((d) => d.pepper === pepper && d.chainId === chainId);
90
+ if (!latestByPepper) {
91
+ // This should not actually happen provided this file compiles since we are extracting the available peppers
92
+ // from the const itself
93
+ throw new Error(`No deployment found for pepper ${pepper}`);
94
+ }
95
+ return latestByPepper;
96
+ }
97
+ /**
98
+ * Get the latest Lightning deployment for a given pepper amd chainId unconditionally.
99
+ * Note that if you upgrade the library the latest deployment may change and contracts deployed to a previous version
100
+ * will not be compatible with the new version.
101
+ *
102
+ * @param pepper the pepper to use to filter the deployments
103
+ * @param chainId the chainId to use to filter the deployments
104
+ */
105
+ static latest(pepper, chainId) {
106
+ return Lightning.at(Lightning.latestDeployment(pepper, chainId));
107
+ }
108
+ /*
109
+ * Get the latest deployment for a given pepper, which usually denotes a family of deployments distinct from their
110
+ * version such as 'devnet', 'testnet', 'mainnet', etc.
111
+ */
112
+ get deployment() {
113
+ return { ...this._deployment };
114
+ }
115
+ /**
116
+ * Encrypt a value using the public ECIES key of the Lightning deployment.
117
+ *
118
+ * @param value a boolean or numeric value to encrypt
119
+ * @param accountAddress the address of the account interacting with the dapp contract, normally an Externally Owned Account (EOA)
120
+ * @param dappAddress the address of the dapp contract that interacts with the Inco Lightning contract or library
121
+ */
122
+ async encrypt(value, { accountAddress, dappAddress }) {
123
+ const { ciphertext } = await this.encryptor({
124
+ plaintext: Lightning.plaintextFromValue(value),
125
+ context: {
126
+ hostChainId: this.chainId,
127
+ aclAddress: this.executorAddress,
128
+ userAddress: parseAddress(accountAddress),
129
+ contractAddress: parseAddress(dappAddress),
130
+ },
131
+ });
132
+ return ciphertext.value;
133
+ }
134
+ /**
135
+ * Obtain a reencryptor for a particular Externally Owned Account (EOA) to request decrypted values.
136
+ * The account associated with the walletClient must have permissions to decrypt the handle or ciphertext passed
137
+ * to the reencryptor function.
138
+ *
139
+ * @param walletClient the wallet client to use for signing the reencrypt request.
140
+ */
141
+ getReencryptor(walletClient) {
142
+ return incoLiteReencryptor({
143
+ walletClient,
144
+ kmsConnectRpcEndpointOrClient: this.kmsClient,
145
+ chainId: this.chainId,
146
+ ephemeralKeypair: this.ephemeralKeypair,
147
+ });
148
+ }
149
+ /**
150
+ * Get the GRPC endpoint for the covalidator that services this deployment.
151
+ */
152
+ static getCovalidatorUrl(deployment) {
153
+ const { executorAddress, chainId, pepper } = deployment;
154
+ return `https://${executorAddress.toLowerCase()}.${chainId}.${pepper}.inco.org`;
155
+ }
156
+ static isIdByName(id) {
157
+ return id.name !== undefined;
158
+ }
159
+ static plaintextFromValue(value) {
160
+ if (typeof value === 'boolean') {
161
+ return {
162
+ scheme: encryptionSchemes.ecies,
163
+ type: handleTypes.ebool,
164
+ value: value,
165
+ };
166
+ }
167
+ else if (typeof value === 'bigint' || typeof value === 'number') {
168
+ return {
169
+ scheme: encryptionSchemes.ecies,
170
+ type: handleTypes.euint256,
171
+ value: BigInt(value),
172
+ };
173
+ }
174
+ else {
175
+ throw new Error(`Unsupported type ${typeof value}`);
176
+ }
177
+ }
178
+ }
179
+ //# sourceMappingURL=lightning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightning.js","sourceRoot":"","sources":["../../src/lite/lightning.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,UAAU,EAA2B,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAW,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAe,iBAAiB,EAA0B,MAAM,eAAe,CAAC;AAEvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAA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