@opendatalabs/vana-sdk 0.1.0-alpha.276ea01 → 0.1.0-alpha.2b6935d

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 (680) hide show
  1. package/dist/__tests__/waitForTransactionEvents.test.d.ts +1 -0
  2. package/dist/browser.d.ts +4 -2
  3. package/dist/chains/definitions.cjs +9 -6
  4. package/dist/chains/definitions.cjs.map +1 -1
  5. package/dist/chains/definitions.d.ts +9 -11
  6. package/dist/chains/definitions.js +9 -6
  7. package/dist/chains/definitions.js.map +1 -1
  8. package/dist/chains/index.d.ts +5 -2
  9. package/dist/chains.browser.d.ts +8 -2
  10. package/dist/chains.d.ts +8 -2
  11. package/dist/chains.node.d.ts +8 -2
  12. package/dist/config/addresses.d.ts +8 -24
  13. package/dist/config/chains.d.ts +9 -13
  14. package/dist/config/default-services.cjs +60 -0
  15. package/dist/config/default-services.cjs.map +1 -0
  16. package/dist/config/default-services.d.ts +46 -0
  17. package/dist/config/default-services.js +33 -0
  18. package/dist/config/default-services.js.map +1 -0
  19. package/dist/config/default-services.test.d.ts +1 -0
  20. package/dist/config/features.d.ts +1 -3
  21. package/dist/config/tests/addresses.test.d.ts +1 -0
  22. package/dist/contracts/contractController.cjs +3 -3
  23. package/dist/contracts/contractController.cjs.map +1 -1
  24. package/dist/contracts/contractController.d.ts +11 -28
  25. package/dist/contracts/contractController.js +4 -7
  26. package/dist/contracts/contractController.js.map +1 -1
  27. package/dist/contracts/tests/contractController.test.d.ts +1 -0
  28. package/dist/controllers/__tests__/schemas-edge-cases.test.d.ts +1 -0
  29. package/dist/controllers/base.cjs +83 -0
  30. package/dist/controllers/base.cjs.map +1 -0
  31. package/dist/controllers/base.d.ts +84 -0
  32. package/dist/controllers/base.js +59 -0
  33. package/dist/controllers/base.js.map +1 -0
  34. package/dist/controllers/data-error-handling.test.d.ts +1 -0
  35. package/dist/controllers/data.cjs +444 -191
  36. package/dist/controllers/data.cjs.map +1 -1
  37. package/dist/controllers/data.d.ts +149 -76
  38. package/dist/controllers/data.js +444 -191
  39. package/dist/controllers/data.js.map +1 -1
  40. package/dist/controllers/permissions.cjs +551 -395
  41. package/dist/controllers/permissions.cjs.map +1 -1
  42. package/dist/controllers/permissions.d.ts +1283 -25
  43. package/dist/controllers/permissions.js +551 -395
  44. package/dist/controllers/permissions.js.map +1 -1
  45. package/dist/controllers/protocol.cjs +15 -11
  46. package/dist/controllers/protocol.cjs.map +1 -1
  47. package/dist/controllers/protocol.d.ts +7 -35
  48. package/dist/controllers/protocol.js +15 -14
  49. package/dist/controllers/protocol.js.map +1 -1
  50. package/dist/controllers/schemas.cjs +69 -54
  51. package/dist/controllers/schemas.cjs.map +1 -1
  52. package/dist/controllers/schemas.d.ts +9 -36
  53. package/dist/controllers/schemas.js +69 -54
  54. package/dist/controllers/schemas.js.map +1 -1
  55. package/dist/controllers/server-additional.test.d.ts +1 -0
  56. package/dist/controllers/server.cjs +15 -10
  57. package/dist/controllers/server.cjs.map +1 -1
  58. package/dist/controllers/server.d.ts +7 -33
  59. package/dist/controllers/server.js +15 -10
  60. package/dist/controllers/server.js.map +1 -1
  61. package/dist/core/apiClient.cjs +15 -12
  62. package/dist/core/apiClient.cjs.map +1 -1
  63. package/dist/core/apiClient.d.ts +5 -9
  64. package/dist/core/apiClient.js +19 -19
  65. package/dist/core/apiClient.js.map +1 -1
  66. package/dist/core/client.cjs +7 -7
  67. package/dist/core/client.cjs.map +1 -1
  68. package/dist/core/client.d.ts +6 -9
  69. package/dist/core/client.js +7 -7
  70. package/dist/core/client.js.map +1 -1
  71. package/dist/core/core.test.d.ts +1 -0
  72. package/dist/core/generics.cjs +11 -9
  73. package/dist/core/generics.cjs.map +1 -1
  74. package/dist/core/generics.d.ts +9 -13
  75. package/dist/core/generics.js +22 -29
  76. package/dist/core/generics.js.map +1 -1
  77. package/dist/core/tests/apiClient.test.d.ts +1 -0
  78. package/dist/core/tests/client.test.d.ts +1 -0
  79. package/dist/core/tests/generics.test.d.ts +1 -0
  80. package/dist/core.cjs +143 -60
  81. package/dist/core.cjs.map +1 -1
  82. package/dist/core.d.ts +42 -66
  83. package/dist/core.js +155 -85
  84. package/dist/core.js.map +1 -1
  85. package/dist/crypto/ecies/__tests__/base.test.d.ts +4 -0
  86. package/dist/crypto/ecies/__tests__/compatibility.test.d.ts +8 -0
  87. package/dist/crypto/ecies/__tests__/constants.test.d.ts +4 -0
  88. package/dist/crypto/ecies/__tests__/native-parity.test.d.ts +7 -0
  89. package/dist/crypto/ecies/__tests__/normalization.test.d.ts +1 -0
  90. package/dist/crypto/ecies/__tests__/test-vectors.d.ts +2 -4
  91. package/dist/crypto/ecies/base.cjs +4 -3
  92. package/dist/crypto/ecies/base.cjs.map +1 -1
  93. package/dist/crypto/ecies/base.d.ts +2 -5
  94. package/dist/crypto/ecies/base.js +12 -15
  95. package/dist/crypto/ecies/base.js.map +1 -1
  96. package/dist/crypto/ecies/browser.cjs +2 -1
  97. package/dist/crypto/ecies/browser.cjs.map +1 -1
  98. package/dist/crypto/ecies/browser.d.ts +2 -7
  99. package/dist/crypto/ecies/browser.js +2 -1
  100. package/dist/crypto/ecies/browser.js.map +1 -1
  101. package/dist/crypto/ecies/constants.d.ts +7 -9
  102. package/dist/crypto/ecies/index.d.ts +8 -1
  103. package/dist/crypto/ecies/interface.cjs +4 -5
  104. package/dist/crypto/ecies/interface.cjs.map +1 -1
  105. package/dist/crypto/ecies/interface.d.ts +9 -11
  106. package/dist/crypto/ecies/interface.js +4 -5
  107. package/dist/crypto/ecies/interface.js.map +1 -1
  108. package/dist/crypto/ecies/node.cjs +3 -2
  109. package/dist/crypto/ecies/node.cjs.map +1 -1
  110. package/dist/crypto/ecies/node.d.ts +2 -7
  111. package/dist/crypto/ecies/node.js +11 -16
  112. package/dist/crypto/ecies/node.js.map +1 -1
  113. package/dist/crypto/ecies/utils.cjs +2 -41
  114. package/dist/crypto/ecies/utils.cjs.map +1 -1
  115. package/dist/crypto/ecies/utils.d.ts +3 -40
  116. package/dist/crypto/ecies/utils.js +1 -35
  117. package/dist/crypto/ecies/utils.js.map +1 -1
  118. package/dist/crypto/services/WalletKeyEncryptionService.cjs +2 -2
  119. package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -1
  120. package/dist/crypto/services/WalletKeyEncryptionService.d.ts +3 -7
  121. package/dist/crypto/services/WalletKeyEncryptionService.js +5 -9
  122. package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -1
  123. package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
  124. package/dist/diagnostics.d.ts +1 -3
  125. package/dist/diagnostics.test.d.ts +1 -0
  126. package/dist/errors.cjs +16 -0
  127. package/dist/errors.cjs.map +1 -1
  128. package/dist/errors.d.ts +53 -15
  129. package/dist/errors.js +18 -6
  130. package/dist/errors.js.map +1 -1
  131. package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
  132. package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
  133. package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
  134. package/dist/generated/abi/DATImplementation.d.ts +2 -3
  135. package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
  136. package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
  137. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
  138. package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
  139. package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
  140. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
  141. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
  142. package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
  143. package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
  144. package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
  145. package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
  146. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
  147. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
  148. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
  149. package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
  150. package/dist/generated/abi/DataRegistryImplementation.cjs +13 -0
  151. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
  152. package/dist/generated/abi/DataRegistryImplementation.d.ts +12 -3
  153. package/dist/generated/abi/DataRegistryImplementation.js +13 -0
  154. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
  155. package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
  156. package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
  157. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
  158. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
  159. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
  160. package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
  161. package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
  162. package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
  163. package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
  164. package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
  165. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
  166. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
  167. package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
  168. package/dist/generated/abi/index.cjs +42 -0
  169. package/dist/generated/abi/index.cjs.map +1 -1
  170. package/dist/generated/abi/index.d.ts +47 -18
  171. package/dist/generated/abi/index.js +21 -0
  172. package/dist/generated/abi/index.js.map +1 -1
  173. package/dist/generated/event-types.cjs +17 -0
  174. package/dist/generated/event-types.cjs.map +1 -0
  175. package/dist/generated/event-types.d.ts +854 -0
  176. package/dist/generated/event-types.js +1 -0
  177. package/dist/generated/event-types.js.map +1 -0
  178. package/dist/generated/eventRegistry.cjs +3351 -0
  179. package/dist/generated/eventRegistry.cjs.map +1 -0
  180. package/dist/generated/eventRegistry.d.ts +14 -0
  181. package/dist/generated/eventRegistry.js +3326 -0
  182. package/dist/generated/eventRegistry.js.map +1 -0
  183. package/dist/generated/server/server-exports.d.ts +19 -21
  184. package/dist/generated/server/server.cjs.map +1 -1
  185. package/dist/generated/server/server.d.ts +113 -87
  186. package/dist/generated/subgraph.d.ts +329 -332
  187. package/dist/index.browser.d.ts +48 -73
  188. package/dist/index.browser.js +12 -0
  189. package/dist/index.browser.js.map +1 -1
  190. package/dist/index.cjs +3 -1
  191. package/dist/index.cjs.map +1 -1
  192. package/dist/index.d.ts +0 -2
  193. package/dist/index.js +3 -1
  194. package/dist/index.js.map +1 -1
  195. package/dist/index.node.cjs +12 -0
  196. package/dist/index.node.cjs.map +1 -1
  197. package/dist/index.node.d.ts +183 -64
  198. package/dist/index.node.js +12 -0
  199. package/dist/index.node.js.map +1 -1
  200. package/dist/node.d.ts +4 -2
  201. package/dist/platform/browser-only.d.ts +5 -8
  202. package/dist/platform/browser-only.test.d.ts +1 -0
  203. package/dist/platform/browser-safe.d.ts +6 -9
  204. package/dist/platform/browser-safe.test.d.ts +1 -0
  205. package/dist/platform/browser.cjs +7 -6
  206. package/dist/platform/browser.cjs.map +1 -1
  207. package/dist/platform/browser.d.ts +3 -6
  208. package/dist/platform/browser.js +19 -27
  209. package/dist/platform/browser.js.map +1 -1
  210. package/dist/platform/browser.test.d.ts +1 -0
  211. package/dist/platform/index.d.ts +11 -5
  212. package/dist/platform/interface.d.ts +6 -8
  213. package/dist/platform/node.d.ts +3 -7
  214. package/dist/platform/node.js +12 -19
  215. package/dist/platform/node.js.map +1 -1
  216. package/dist/platform/ports/openpgp-port.cjs +74 -0
  217. package/dist/platform/ports/openpgp-port.cjs.map +1 -0
  218. package/dist/platform/ports/openpgp-port.d.ts +13 -0
  219. package/dist/platform/ports/openpgp-port.js +59 -0
  220. package/dist/platform/ports/openpgp-port.js.map +1 -0
  221. package/dist/platform/ports/pgp-port.cjs +17 -0
  222. package/dist/platform/ports/pgp-port.cjs.map +1 -0
  223. package/dist/platform/ports/pgp-port.d.ts +35 -0
  224. package/dist/platform/ports/pgp-port.js +1 -0
  225. package/dist/platform/ports/pgp-port.js.map +1 -0
  226. package/dist/platform/shared/error-utils.d.ts +2 -4
  227. package/dist/platform/shared/pgp-utils.cjs +2 -2
  228. package/dist/platform/shared/pgp-utils.cjs.map +1 -1
  229. package/dist/platform/shared/pgp-utils.d.ts +3 -5
  230. package/dist/platform/shared/pgp-utils.js +2 -2
  231. package/dist/platform/shared/pgp-utils.js.map +1 -1
  232. package/dist/platform/shared/stream-utils.d.ts +1 -3
  233. package/dist/platform/utils.d.ts +6 -10
  234. package/dist/platform/utils.test.d.ts +1 -0
  235. package/dist/platform.browser.d.ts +9 -4
  236. package/dist/platform.d.ts +11 -5
  237. package/dist/platform.node.d.ts +10 -5
  238. package/dist/server/handler.cjs +7 -5
  239. package/dist/server/handler.cjs.map +1 -1
  240. package/dist/server/handler.d.ts +17 -204
  241. package/dist/server/handler.js +7 -5
  242. package/dist/server/handler.js.map +1 -1
  243. package/dist/server/relayerHandler.cjs +220 -0
  244. package/dist/server/relayerHandler.cjs.map +1 -0
  245. package/dist/server/relayerHandler.d.ts +37 -0
  246. package/dist/server/relayerHandler.js +195 -0
  247. package/dist/server/relayerHandler.js.map +1 -0
  248. package/dist/storage/index.d.ts +56 -10
  249. package/dist/storage/manager.cjs +2 -2
  250. package/dist/storage/manager.cjs.map +1 -1
  251. package/dist/storage/manager.d.ts +2 -5
  252. package/dist/storage/manager.js +5 -12
  253. package/dist/storage/manager.js.map +1 -1
  254. package/dist/storage/providers/callback-storage.cjs +3 -3
  255. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  256. package/dist/storage/providers/callback-storage.d.ts +3 -9
  257. package/dist/storage/providers/callback-storage.js +3 -3
  258. package/dist/storage/providers/callback-storage.js.map +1 -1
  259. package/dist/storage/providers/google-drive.cjs +2 -2
  260. package/dist/storage/providers/google-drive.cjs.map +1 -1
  261. package/dist/storage/providers/google-drive.d.ts +3 -7
  262. package/dist/storage/providers/google-drive.js +4 -7
  263. package/dist/storage/providers/google-drive.js.map +1 -1
  264. package/dist/storage/providers/google-drive.test.d.ts +1 -0
  265. package/dist/storage/providers/ipfs.cjs +5 -5
  266. package/dist/storage/providers/ipfs.cjs.map +1 -1
  267. package/dist/storage/providers/ipfs.d.ts +3 -6
  268. package/dist/storage/providers/ipfs.js +7 -10
  269. package/dist/storage/providers/ipfs.js.map +1 -1
  270. package/dist/storage/providers/pinata.cjs +6 -6
  271. package/dist/storage/providers/pinata.cjs.map +1 -1
  272. package/dist/storage/providers/pinata.d.ts +5 -8
  273. package/dist/storage/providers/pinata.js +8 -11
  274. package/dist/storage/providers/pinata.js.map +1 -1
  275. package/dist/storage/tests/callbackStorage.test.d.ts +1 -0
  276. package/dist/storage/tests/googleDriveStorage.test.d.ts +1 -0
  277. package/dist/storage/tests/ipfsStorage.test.d.ts +1 -0
  278. package/dist/storage/tests/pinataStorage.test.d.ts +1 -0
  279. package/dist/storage/tests/storageManager.test.d.ts +1 -0
  280. package/dist/tests/abi.test.d.ts +1 -0
  281. package/dist/tests/chains-definitions.test.d.ts +1 -0
  282. package/dist/tests/core-encryption.test.d.ts +1 -0
  283. package/dist/tests/core-extended.test.d.ts +1 -0
  284. package/dist/tests/core-generics-coverage.test.d.ts +1 -0
  285. package/dist/tests/coverage-boost.test.d.ts +1 -0
  286. package/dist/tests/crypto-cross-platform-compatibility.test.d.ts +1 -0
  287. package/dist/tests/data-addfile-permissions-schema.test.d.ts +1 -0
  288. package/dist/tests/data-additional-methods.test.d.ts +1 -0
  289. package/dist/tests/data-controller-edge-cases.test.d.ts +1 -0
  290. package/dist/tests/data-ipfs-gateways.test.d.ts +1 -0
  291. package/dist/tests/data-relayer.test.d.ts +1 -0
  292. package/dist/tests/data-schema-validation.test.d.ts +1 -0
  293. package/dist/tests/data-simple-methods.test.d.ts +1 -0
  294. package/dist/tests/data.test.d.ts +1 -0
  295. package/dist/tests/demo-integration.test.d.ts +1 -0
  296. package/dist/tests/demo-trusted-server-integration.test.d.ts +1 -0
  297. package/dist/tests/download-relayer.test.d.ts +1 -0
  298. package/dist/tests/dual-mode-permissions.test.d.ts +1 -0
  299. package/dist/tests/dual-mode-trusted-servers.test.d.ts +1 -0
  300. package/dist/tests/encryption-correct-implementation.test.d.ts +1 -0
  301. package/dist/tests/encryption-coverage.test.d.ts +1 -0
  302. package/dist/tests/encryption-edge-cases.test.d.ts +1 -0
  303. package/dist/tests/encryption-utils-updated.test.d.ts +1 -0
  304. package/dist/tests/errors-coverage.test.d.ts +1 -0
  305. package/dist/tests/errors.test.d.ts +1 -0
  306. package/dist/tests/factories/mockFactory.d.ts +316 -0
  307. package/dist/tests/fakes/FakeStorageManager.d.ts +200 -0
  308. package/dist/tests/fakes/FakeStorageManager.test.d.ts +1 -0
  309. package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +170 -0
  310. package/dist/tests/fakes/FakeWaitForTransactionEvents.test.d.ts +1 -0
  311. package/dist/tests/fakes/fake-pgp-port.d.ts +13 -0
  312. package/dist/tests/grantValidation-edge-cases.test.d.ts +1 -0
  313. package/dist/tests/grantValidation-unreachable-branch.test.d.ts +1 -0
  314. package/dist/tests/helper-methods.test.d.ts +1 -0
  315. package/dist/tests/helpers/platformTestHelpers.d.ts +106 -0
  316. package/dist/tests/helpers/typedMocks.d.ts +64 -0
  317. package/dist/tests/index-browser.test.d.ts +1 -0
  318. package/dist/tests/index-node.test.d.ts +1 -0
  319. package/dist/tests/index.test.d.ts +1 -0
  320. package/dist/tests/mocks/platformAdapter.d.ts +12 -0
  321. package/dist/tests/new-permissions-methods.test.d.ts +1 -0
  322. package/dist/tests/no-buffer-browser.test.d.ts +1 -0
  323. package/dist/tests/permissions-grantee.test.d.ts +1 -0
  324. package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
  325. package/dist/tests/permissions-schema-validation.test.d.ts +1 -0
  326. package/dist/tests/permissions-server-files.test.d.ts +1 -0
  327. package/dist/tests/permissions-trust-servers.test.d.ts +1 -0
  328. package/dist/tests/permissions.test.d.ts +1 -0
  329. package/dist/tests/personal.test.d.ts +1 -0
  330. package/dist/tests/platform-browser.test.d.ts +1 -0
  331. package/dist/tests/platform-crypto-expanded.test.d.ts +1 -0
  332. package/dist/tests/platform-crypto.test.d.ts +1 -0
  333. package/dist/tests/platform-index.test.d.ts +1 -0
  334. package/dist/tests/platform-node.test.d.ts +1 -0
  335. package/dist/tests/platform-shared-utils.test.d.ts +1 -0
  336. package/dist/tests/platform-updated.test.d.ts +1 -0
  337. package/dist/tests/protocol-additional-methods.test.d.ts +1 -0
  338. package/dist/tests/protocol.test.d.ts +1 -0
  339. package/dist/tests/read-only-mode.test.d.ts +1 -0
  340. package/dist/tests/relayer-integration.test.d.ts +1 -0
  341. package/dist/tests/relayer-unified.test.d.ts +1 -0
  342. package/dist/tests/schemas.test.d.ts +1 -0
  343. package/dist/tests/server-handler.test.d.ts +1 -0
  344. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  345. package/dist/tests/setup.d.ts +7 -0
  346. package/dist/tests/signatureFormatter.test.d.ts +1 -0
  347. package/dist/tests/trusted-server-queries.test.d.ts +1 -0
  348. package/dist/tests/typedDataConverter.test.d.ts +1 -0
  349. package/dist/tests/types-contracts.test.d.ts +1 -0
  350. package/dist/tests/types-data.test.d.ts +1 -0
  351. package/dist/tests/types-external-apis.test.d.ts +1 -0
  352. package/dist/tests/types-generics.test.d.ts +1 -0
  353. package/dist/tests/types-permissions.test.d.ts +1 -0
  354. package/dist/tests/types-upload-params.test.d.ts +1 -0
  355. package/dist/tests/types.test.d.ts +1 -0
  356. package/dist/tests/utils-formatters.test.d.ts +1 -0
  357. package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +1 -0
  358. package/dist/tests/utils-grantFiles-validation.test.d.ts +1 -0
  359. package/dist/tests/utils-grantFiles.test.d.ts +1 -0
  360. package/dist/tests/utils-grantValidation-consolidated.test.d.ts +1 -0
  361. package/dist/tests/utils-grants.test.d.ts +1 -0
  362. package/dist/tests/utils-ipfs-additional.test.d.ts +1 -0
  363. package/dist/tests/utils-ipfs.test.d.ts +4 -0
  364. package/dist/tests/utils-schemaValidation.test.d.ts +1 -0
  365. package/dist/tests/vana.test.d.ts +1 -0
  366. package/dist/tests/wallet-crypto-compatibility.test.d.ts +1 -0
  367. package/dist/types/blockchain.cjs +17 -0
  368. package/dist/types/blockchain.cjs.map +1 -0
  369. package/dist/types/blockchain.d.ts +57 -0
  370. package/dist/types/blockchain.js +1 -0
  371. package/dist/types/blockchain.js.map +1 -0
  372. package/dist/types/chains-additional.test.d.ts +1 -0
  373. package/dist/types/chains.d.ts +6 -9
  374. package/dist/types/config.cjs +10 -0
  375. package/dist/types/config.cjs.map +1 -1
  376. package/dist/types/config.d.ts +198 -238
  377. package/dist/types/config.js +8 -0
  378. package/dist/types/config.js.map +1 -1
  379. package/dist/types/contracts.cjs.map +1 -1
  380. package/dist/types/contracts.d.ts +8 -11
  381. package/dist/types/controller-context.cjs +17 -0
  382. package/dist/types/controller-context.cjs.map +1 -0
  383. package/dist/types/controller-context.d.ts +65 -0
  384. package/dist/types/controller-context.js +1 -0
  385. package/dist/types/controller-context.js.map +1 -0
  386. package/dist/types/data.cjs.map +1 -1
  387. package/dist/types/data.d.ts +107 -39
  388. package/dist/types/external-apis.d.ts +10 -12
  389. package/dist/types/generics.d.ts +35 -38
  390. package/dist/types/index.cjs +5 -4
  391. package/dist/types/index.cjs.map +1 -1
  392. package/dist/types/index.d.ts +20 -34
  393. package/dist/types/index.js +9 -2
  394. package/dist/types/index.js.map +1 -1
  395. package/dist/types/operations.cjs +2 -2
  396. package/dist/types/operations.cjs.map +1 -1
  397. package/dist/types/operations.d.ts +32 -28
  398. package/dist/types/operations.js +2 -2
  399. package/dist/types/operations.js.map +1 -1
  400. package/dist/types/permissions.d.ts +55 -58
  401. package/dist/types/personal.cjs.map +1 -1
  402. package/dist/types/personal.d.ts +6 -8
  403. package/dist/types/relayer.cjs.map +1 -1
  404. package/dist/types/relayer.d.ts +186 -39
  405. package/dist/types/storage.d.ts +6 -8
  406. package/dist/types/storage.js +2 -5
  407. package/dist/types/storage.js.map +1 -1
  408. package/dist/types/transactionResults.cjs.map +1 -1
  409. package/dist/types/transactionResults.d.ts +193 -25
  410. package/dist/types/utils.d.ts +21 -24
  411. package/dist/types.d.ts +4 -40
  412. package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
  413. package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
  414. package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
  415. package/dist/utils/__tests__/transaction-edge-cases.test.d.ts +1 -0
  416. package/dist/utils/__tests__/transactionHelpers.test.d.ts +1 -0
  417. package/dist/utils/__tests__/urlResolver.test.d.ts +4 -0
  418. package/dist/utils/blockchain/registry.cjs +2 -2
  419. package/dist/utils/blockchain/registry.cjs.map +1 -1
  420. package/dist/utils/blockchain/registry.d.ts +6 -8
  421. package/dist/utils/blockchain/registry.js +2 -2
  422. package/dist/utils/blockchain/registry.js.map +1 -1
  423. package/dist/utils/blockchain/registry.test.d.ts +1 -0
  424. package/dist/utils/crypto-utils.cjs +0 -12
  425. package/dist/utils/crypto-utils.cjs.map +1 -1
  426. package/dist/utils/crypto-utils.d.ts +9 -27
  427. package/dist/utils/crypto-utils.js +0 -11
  428. package/dist/utils/crypto-utils.js.map +1 -1
  429. package/dist/utils/crypto-utils.test.d.ts +1 -0
  430. package/dist/utils/download.cjs +3 -3
  431. package/dist/utils/download.cjs.map +1 -1
  432. package/dist/utils/download.d.ts +13 -14
  433. package/dist/utils/download.js +2 -2
  434. package/dist/utils/download.js.map +1 -1
  435. package/dist/utils/encoding.cjs +1 -1
  436. package/dist/utils/encoding.cjs.map +1 -1
  437. package/dist/utils/encoding.d.ts +4 -6
  438. package/dist/utils/encoding.js +1 -1
  439. package/dist/utils/encoding.js.map +1 -1
  440. package/dist/utils/encoding.test.d.ts +1 -0
  441. package/dist/utils/encryption.cjs +16 -10
  442. package/dist/utils/encryption.cjs.map +1 -1
  443. package/dist/utils/encryption.d.ts +13 -17
  444. package/dist/utils/encryption.js +16 -10
  445. package/dist/utils/encryption.js.map +1 -1
  446. package/dist/utils/formatters.cjs +4 -2
  447. package/dist/utils/formatters.cjs.map +1 -1
  448. package/dist/utils/formatters.d.ts +4 -6
  449. package/dist/utils/formatters.js +4 -2
  450. package/dist/utils/formatters.js.map +1 -1
  451. package/dist/utils/grantFiles.cjs +7 -4
  452. package/dist/utils/grantFiles.cjs.map +1 -1
  453. package/dist/utils/grantFiles.d.ts +6 -10
  454. package/dist/utils/grantFiles.js +7 -4
  455. package/dist/utils/grantFiles.js.map +1 -1
  456. package/dist/utils/grantValidation.cjs +1 -1
  457. package/dist/utils/grantValidation.cjs.map +1 -1
  458. package/dist/utils/grantValidation.d.ts +14 -17
  459. package/dist/utils/grantValidation.js +1 -1
  460. package/dist/utils/grantValidation.js.map +1 -1
  461. package/dist/utils/grants.cjs +1 -1
  462. package/dist/utils/grants.cjs.map +1 -1
  463. package/dist/utils/grants.d.ts +10 -13
  464. package/dist/utils/grants.js +1 -1
  465. package/dist/utils/grants.js.map +1 -1
  466. package/dist/utils/ipfs.d.ts +8 -10
  467. package/dist/utils/lazy-import.cjs +4 -6
  468. package/dist/utils/lazy-import.cjs.map +1 -1
  469. package/dist/utils/lazy-import.d.ts +1 -3
  470. package/dist/utils/lazy-import.js +4 -6
  471. package/dist/utils/lazy-import.js.map +1 -1
  472. package/dist/utils/multicall.cjs +4 -2
  473. package/dist/utils/multicall.cjs.map +1 -1
  474. package/dist/utils/multicall.d.ts +5 -8
  475. package/dist/utils/multicall.js +4 -2
  476. package/dist/utils/multicall.js.map +1 -1
  477. package/dist/utils/parseTransactionPojo.cjs +87 -0
  478. package/dist/utils/parseTransactionPojo.cjs.map +1 -0
  479. package/dist/utils/parseTransactionPojo.d.ts +31 -0
  480. package/dist/utils/parseTransactionPojo.js +63 -0
  481. package/dist/utils/parseTransactionPojo.js.map +1 -0
  482. package/dist/utils/schemaValidation.cjs +5 -5
  483. package/dist/utils/schemaValidation.cjs.map +1 -1
  484. package/dist/utils/schemaValidation.d.ts +8 -12
  485. package/dist/utils/schemaValidation.js +7 -10
  486. package/dist/utils/schemaValidation.js.map +1 -1
  487. package/dist/utils/signatureCache.cjs +1 -2
  488. package/dist/utils/signatureCache.cjs.map +1 -1
  489. package/dist/utils/signatureCache.d.ts +4 -7
  490. package/dist/utils/signatureCache.js +4 -8
  491. package/dist/utils/signatureCache.js.map +1 -1
  492. package/dist/utils/signatureFormatter.cjs +6 -9
  493. package/dist/utils/signatureFormatter.cjs.map +1 -1
  494. package/dist/utils/signatureFormatter.d.ts +2 -5
  495. package/dist/utils/signatureFormatter.js +6 -9
  496. package/dist/utils/signatureFormatter.js.map +1 -1
  497. package/dist/utils/tests/multicall.test.d.ts +1 -0
  498. package/dist/utils/transactionHelpers.cjs +54 -0
  499. package/dist/utils/transactionHelpers.cjs.map +1 -0
  500. package/dist/utils/transactionHelpers.d.ts +80 -0
  501. package/dist/utils/transactionHelpers.js +29 -0
  502. package/dist/utils/transactionHelpers.js.map +1 -0
  503. package/dist/utils/typeGuards.cjs +109 -0
  504. package/dist/utils/typeGuards.cjs.map +1 -0
  505. package/dist/utils/typeGuards.d.ts +138 -0
  506. package/dist/utils/typeGuards.js +74 -0
  507. package/dist/utils/typeGuards.js.map +1 -0
  508. package/dist/utils/typedDataConverter.d.ts +3 -6
  509. package/dist/utils/urlResolver.cjs +1 -1
  510. package/dist/utils/urlResolver.cjs.map +1 -1
  511. package/dist/utils/urlResolver.d.ts +2 -4
  512. package/dist/utils/urlResolver.js +2 -2
  513. package/dist/utils/urlResolver.js.map +1 -1
  514. package/dist/utils/wallet.cjs +63 -0
  515. package/dist/utils/wallet.cjs.map +1 -0
  516. package/dist/utils/wallet.d.ts +32 -0
  517. package/dist/utils/wallet.js +37 -0
  518. package/dist/utils/wallet.js.map +1 -0
  519. package/dist/{chains.browser.cjs → utils/withEvents.cjs} +22 -15
  520. package/dist/utils/withEvents.cjs.map +1 -0
  521. package/dist/utils/withEvents.d.ts +56 -0
  522. package/dist/utils/withEvents.js +18 -0
  523. package/dist/utils/withEvents.js.map +1 -0
  524. package/package.json +23 -14
  525. package/dist/browser.d.cts +0 -2
  526. package/dist/chains/definitions.d.cts +0 -53
  527. package/dist/chains/index.d.cts +0 -2
  528. package/dist/chains.browser.cjs.map +0 -1
  529. package/dist/chains.browser.d.cts +0 -2
  530. package/dist/chains.d.cts +0 -2
  531. package/dist/chains.node.d.cts +0 -2
  532. package/dist/config/addresses.d.cts +0 -380
  533. package/dist/config/chains.d.cts +0 -85
  534. package/dist/config/eventMappings.cjs +0 -114
  535. package/dist/config/eventMappings.cjs.map +0 -1
  536. package/dist/config/eventMappings.d.cts +0 -108
  537. package/dist/config/eventMappings.d.ts +0 -108
  538. package/dist/config/eventMappings.js +0 -90
  539. package/dist/config/eventMappings.js.map +0 -1
  540. package/dist/config/features.d.cts +0 -64
  541. package/dist/contracts/contractController.d.cts +0 -96
  542. package/dist/controllers/data.d.cts +0 -941
  543. package/dist/controllers/permissions.d.cts +0 -25
  544. package/dist/controllers/protocol.d.cts +0 -167
  545. package/dist/controllers/schemas.d.cts +0 -272
  546. package/dist/controllers/server.d.cts +0 -243
  547. package/dist/core/apiClient.d.cts +0 -165
  548. package/dist/core/client.d.cts +0 -92
  549. package/dist/core/generics.d.cts +0 -120
  550. package/dist/core.d.cts +0 -466
  551. package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
  552. package/dist/crypto/ecies/base.d.cts +0 -143
  553. package/dist/crypto/ecies/browser.d.cts +0 -48
  554. package/dist/crypto/ecies/constants.d.cts +0 -122
  555. package/dist/crypto/ecies/index.d.cts +0 -1
  556. package/dist/crypto/ecies/interface.d.cts +0 -176
  557. package/dist/crypto/ecies/node.d.cts +0 -50
  558. package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.cts +0 -76
  559. package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.ts +0 -76
  560. package/dist/crypto/ecies/utils.d.cts +0 -67
  561. package/dist/crypto/services/WalletKeyEncryptionService.d.cts +0 -92
  562. package/dist/diagnostics.d.cts +0 -26
  563. package/dist/errors.d.cts +0 -350
  564. package/dist/generated/abi/ComputeEngineImplementation.d.cts +0 -996
  565. package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +0 -545
  566. package/dist/generated/abi/DATFactoryImplementation.d.cts +0 -661
  567. package/dist/generated/abi/DATImplementation.d.cts +0 -693
  568. package/dist/generated/abi/DATPausableImplementation.d.cts +0 -1145
  569. package/dist/generated/abi/DATVotesImplementation.d.cts +0 -1095
  570. package/dist/generated/abi/DLPPerformanceImplementation.d.cts +0 -883
  571. package/dist/generated/abi/DLPRegistryImplementation.d.cts +0 -1123
  572. package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +0 -452
  573. package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +0 -714
  574. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +0 -452
  575. package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +0 -706
  576. package/dist/generated/abi/DLPRootImplementation.d.cts +0 -1248
  577. package/dist/generated/abi/DLPTreasuryImplementation.d.cts +0 -452
  578. package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +0 -737
  579. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +0 -661
  580. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +0 -989
  581. package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +0 -1086
  582. package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +0 -737
  583. package/dist/generated/abi/DataRegistryImplementation.d.cts +0 -1004
  584. package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
  585. package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
  586. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
  587. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
  588. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
  589. package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
  590. package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
  591. package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
  592. package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
  593. package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
  594. package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
  595. package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
  596. package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
  597. package/dist/generated/abi/index.d.cts +0 -26516
  598. package/dist/generated/server/server-exports.d.cts +0 -21
  599. package/dist/generated/server/server.d.cts +0 -512
  600. package/dist/generated/subgraph.d.cts +0 -5981
  601. package/dist/index.browser.cjs +0 -151
  602. package/dist/index.browser.cjs.map +0 -1
  603. package/dist/index.browser.d.cts +0 -177
  604. package/dist/index.d.cts +0 -2
  605. package/dist/index.node.d.cts +0 -64
  606. package/dist/node.d.cts +0 -2
  607. package/dist/permissions-DNKPu_G0.d.cts +0 -1666
  608. package/dist/permissions-eo8YeLGf.d.ts +0 -1666
  609. package/dist/platform/browser-only.d.cts +0 -25
  610. package/dist/platform/browser-safe.d.cts +0 -32
  611. package/dist/platform/browser.d.cts +0 -74
  612. package/dist/platform/index.d.cts +0 -5
  613. package/dist/platform/interface.d.cts +0 -218
  614. package/dist/platform/node.d.cts +0 -27
  615. package/dist/platform/shared/error-utils.d.cts +0 -25
  616. package/dist/platform/shared/pgp-utils.d.cts +0 -61
  617. package/dist/platform/shared/stream-utils.d.cts +0 -16
  618. package/dist/platform/utils.d.cts +0 -53
  619. package/dist/platform.browser.cjs +0 -41
  620. package/dist/platform.browser.cjs.map +0 -1
  621. package/dist/platform.browser.d.cts +0 -4
  622. package/dist/platform.d.cts +0 -5
  623. package/dist/platform.node.d.cts +0 -5
  624. package/dist/schemas/dataSchema.schema.d.cts +0 -88
  625. package/dist/schemas/dataSchema.schema.d.ts +0 -88
  626. package/dist/schemas/grantFile.schema.d.cts +0 -57
  627. package/dist/schemas/grantFile.schema.d.ts +0 -57
  628. package/dist/server/handler.d.cts +0 -282
  629. package/dist/storage/index.d.cts +0 -10
  630. package/dist/storage/manager.d.cts +0 -150
  631. package/dist/storage/providers/callback-storage.d.cts +0 -100
  632. package/dist/storage/providers/google-drive.d.cts +0 -156
  633. package/dist/storage/providers/ipfs.d.cts +0 -163
  634. package/dist/storage/providers/pinata.d.cts +0 -173
  635. package/dist/types/chains.d.cts +0 -34
  636. package/dist/types/config.d.cts +0 -726
  637. package/dist/types/contracts.d.cts +0 -68
  638. package/dist/types/data.d.cts +0 -694
  639. package/dist/types/eccrypto-js.d.d.cts +0 -13
  640. package/dist/types/eccrypto-js.d.d.ts +0 -13
  641. package/dist/types/external-apis.d.cts +0 -186
  642. package/dist/types/generics.d.cts +0 -450
  643. package/dist/types/index.d.cts +0 -34
  644. package/dist/types/operations.d.cts +0 -108
  645. package/dist/types/permissions.d.cts +0 -957
  646. package/dist/types/personal.d.cts +0 -40
  647. package/dist/types/relayer.d.cts +0 -284
  648. package/dist/types/storage.d.cts +0 -131
  649. package/dist/types/transactionResults.d.cts +0 -25
  650. package/dist/types/utils.d.cts +0 -819
  651. package/dist/types.d.cts +0 -66
  652. package/dist/utils/blockchain/registry.d.cts +0 -34
  653. package/dist/utils/crypto-utils.d.cts +0 -118
  654. package/dist/utils/download.d.cts +0 -41
  655. package/dist/utils/encoding.d.cts +0 -54
  656. package/dist/utils/encryption.d.cts +0 -275
  657. package/dist/utils/eventParsing.cjs +0 -111
  658. package/dist/utils/eventParsing.cjs.map +0 -1
  659. package/dist/utils/eventParsing.d.cts +0 -60
  660. package/dist/utils/eventParsing.d.ts +0 -60
  661. package/dist/utils/eventParsing.js +0 -86
  662. package/dist/utils/eventParsing.js.map +0 -1
  663. package/dist/utils/formatters.d.cts +0 -120
  664. package/dist/utils/grantFiles.d.cts +0 -186
  665. package/dist/utils/grantValidation.d.cts +0 -150
  666. package/dist/utils/grants.d.cts +0 -70
  667. package/dist/utils/ipfs.d.cts +0 -90
  668. package/dist/utils/lazy-import.d.cts +0 -20
  669. package/dist/utils/multicall.d.cts +0 -129
  670. package/dist/utils/schemaValidation.d.cts +0 -172
  671. package/dist/utils/signatureCache.d.cts +0 -134
  672. package/dist/utils/signatureFormatter.d.cts +0 -39
  673. package/dist/utils/transactionParsing.cjs +0 -84
  674. package/dist/utils/transactionParsing.cjs.map +0 -1
  675. package/dist/utils/transactionParsing.d.cts +0 -25
  676. package/dist/utils/transactionParsing.d.ts +0 -25
  677. package/dist/utils/transactionParsing.js +0 -62
  678. package/dist/utils/transactionParsing.js.map +0 -1
  679. package/dist/utils/typedDataConverter.d.cts +0 -13
  680. package/dist/utils/urlResolver.d.cts +0 -40
@@ -1,12 +1,10 @@
1
- import { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaCacheAdapter } from './interface.js';
2
-
3
1
  /**
4
2
  * Browser implementation of the Vana Platform Adapter using Uint8Array
5
3
  *
6
4
  * This implementation uses browser-compatible libraries and native APIs
7
5
  * without requiring Buffer or other Node.js polyfills.
8
6
  */
9
-
7
+ import type { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaCacheAdapter } from "./interface";
10
8
  /**
11
9
  * Browser implementation of crypto operations using Uint8Array
12
10
  * Supports both eccrypto-js (default) and custom ECIES implementation
@@ -63,12 +61,11 @@ declare class BrowserCacheAdapter implements VanaCacheAdapter {
63
61
  * This adapter provides all platform-specific functionality for browser environments
64
62
  * without requiring any Node.js polyfills.
65
63
  */
66
- declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
64
+ export declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
67
65
  readonly crypto: BrowserCryptoAdapter;
68
66
  readonly pgp: BrowserPGPAdapter;
69
67
  readonly http: BrowserHttpAdapter;
70
68
  readonly cache: BrowserCacheAdapter;
71
69
  readonly platform: "browser";
72
70
  }
73
-
74
- export { BrowserPlatformAdapter };
71
+ export {};
@@ -1,26 +1,20 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import { getPGPKeyGenParams } from "./shared/pgp-utils";
5
2
  import { wrapCryptoError } from "./shared/error-utils";
6
3
  import { lazyImport } from "../utils/lazy-import";
7
4
  import { WalletKeyEncryptionService } from "../crypto/services/WalletKeyEncryptionService";
8
5
  import { parseEncryptedDataBuffer } from "../utils/crypto-utils";
9
- import { toHex, fromHex, stringToBytes, bytesToString } from "viem";
10
- import { concatBytes } from "../crypto/ecies/utils";
6
+ import { toHex, fromHex, stringToBytes, bytesToString, concat } from "viem";
11
7
  import * as secp256k1 from "@noble/secp256k1";
12
8
  import { features } from "../config/features";
13
9
  import { BrowserECIESUint8Provider } from "../crypto/ecies/browser";
14
10
  const getOpenPGP = lazyImport(() => import("openpgp"));
15
11
  const getEccryptoJS = lazyImport(() => import("eccrypto-js"));
16
12
  class BrowserCryptoAdapter {
17
- constructor() {
18
- // Initialize both providers - only one will be used based on feature flag
19
- __publicField(this, "customEciesProvider", new BrowserECIESUint8Provider());
20
- __publicField(this, "customWalletService", new WalletKeyEncryptionService({
21
- eciesProvider: this.customEciesProvider
22
- }));
23
- }
13
+ // Initialize both providers - only one will be used based on feature flag
14
+ customEciesProvider = new BrowserECIESUint8Provider();
15
+ customWalletService = new WalletKeyEncryptionService({
16
+ eciesProvider: this.customEciesProvider
17
+ });
24
18
  async encryptWithPublicKey(data, publicKeyHex) {
25
19
  try {
26
20
  if (features.useCustomECIES) {
@@ -30,12 +24,12 @@ class BrowserCryptoAdapter {
30
24
  publicKeyBytes,
31
25
  stringToBytes(data)
32
26
  );
33
- const result = concatBytes(
27
+ const result = concat([
34
28
  encrypted.iv,
35
29
  encrypted.ephemPublicKey,
36
30
  encrypted.ciphertext,
37
31
  encrypted.mac
38
- );
32
+ ]);
39
33
  return toHex(result).slice(2);
40
34
  } else {
41
35
  const eccryptojs = await getEccryptoJS();
@@ -203,7 +197,7 @@ class BrowserPGPAdapter {
203
197
  });
204
198
  return encrypted;
205
199
  } catch (error) {
206
- throw new Error(`PGP encryption failed: ${error}`);
200
+ throw new Error(`PGP encryption failed: ${String(error)}`);
207
201
  }
208
202
  }
209
203
  async decrypt(encryptedData, privateKeyArmored) {
@@ -221,7 +215,7 @@ class BrowserPGPAdapter {
221
215
  });
222
216
  return decrypted;
223
217
  } catch (error) {
224
- throw new Error(`PGP decryption failed: ${error}`);
218
+ throw new Error(`PGP decryption failed: ${String(error)}`);
225
219
  }
226
220
  }
227
221
  async generateKeyPair(options) {
@@ -241,9 +235,7 @@ class BrowserHttpAdapter {
241
235
  }
242
236
  }
243
237
  class BrowserCacheAdapter {
244
- constructor() {
245
- __publicField(this, "prefix", "vana_cache_");
246
- }
238
+ prefix = "vana_cache_";
247
239
  get(key) {
248
240
  try {
249
241
  if (typeof sessionStorage === "undefined") {
@@ -284,19 +276,19 @@ class BrowserCacheAdapter {
284
276
  keysToRemove.push(key);
285
277
  }
286
278
  }
287
- keysToRemove.forEach((key) => sessionStorage.removeItem(key));
279
+ keysToRemove.forEach((key) => {
280
+ sessionStorage.removeItem(key);
281
+ });
288
282
  } catch {
289
283
  }
290
284
  }
291
285
  }
292
286
  class BrowserPlatformAdapter {
293
- constructor() {
294
- __publicField(this, "crypto", new BrowserCryptoAdapter());
295
- __publicField(this, "pgp", new BrowserPGPAdapter());
296
- __publicField(this, "http", new BrowserHttpAdapter());
297
- __publicField(this, "cache", new BrowserCacheAdapter());
298
- __publicField(this, "platform", "browser");
299
- }
287
+ crypto = new BrowserCryptoAdapter();
288
+ pgp = new BrowserPGPAdapter();
289
+ http = new BrowserHttpAdapter();
290
+ cache = new BrowserCacheAdapter();
291
+ platform = "browser";
300
292
  }
301
293
  export {
302
294
  BrowserPlatformAdapter
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/platform/browser.ts"],"sourcesContent":["/**\n * Browser implementation of the Vana Platform Adapter using Uint8Array\n *\n * This implementation uses browser-compatible libraries and native APIs\n * without requiring Buffer or other Node.js polyfills.\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport { parseEncryptedDataBuffer } from \"../utils/crypto-utils\";\nimport { toHex, fromHex, stringToBytes, bytesToString } from \"viem\";\nimport { concatBytes } from \"../crypto/ecies/utils\";\nimport * as secp256k1 from \"@noble/secp256k1\";\nimport { features } from \"../config/features\";\n\n// Import browser ECIES provider\nimport { BrowserECIESUint8Provider } from \"../crypto/ecies/browser\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccryptoJS = lazyImport(() => import(\"eccrypto-js\"));\n\n/**\n * Browser implementation of crypto operations using Uint8Array\n * Supports both eccrypto-js (default) and custom ECIES implementation\n */\nclass BrowserCryptoAdapter implements VanaCryptoAdapter {\n // Initialize both providers - only one will be used based on feature flag\n private customEciesProvider = new BrowserECIESUint8Provider();\n private customWalletService = new WalletKeyEncryptionService({\n eciesProvider: this.customEciesProvider,\n });\n\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const prefixedHex = publicKeyHex.startsWith(\"0x\")\n ? publicKeyHex\n : `0x${publicKeyHex}`;\n const publicKeyBytes = fromHex(prefixedHex as `0x${string}`, \"bytes\");\n\n // Encrypt data using ECIES\n const encrypted = await this.customEciesProvider.encrypt(\n publicKeyBytes,\n stringToBytes(data),\n );\n\n // Concatenate all components and return as hex string\n const result = concatBytes(\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n );\n\n return toHex(result).slice(2); // Remove '0x' prefix for backward compatibility\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n\n // Remove 0x prefix if present\n const cleanKey = publicKeyHex.startsWith(\"0x\")\n ? publicKeyHex.slice(2)\n : publicKeyHex;\n const publicKeyBytes = Buffer.from(cleanKey, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n const publicKeyBuffer =\n publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPublicKey\", error);\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const encryptedHex = encryptedData.startsWith(\"0x\")\n ? encryptedData\n : `0x${encryptedData}`;\n const privateHex = privateKeyHex.startsWith(\"0x\")\n ? privateKeyHex\n : `0x${privateKeyHex}`;\n const encryptedBytes = fromHex(encryptedHex as `0x${string}`, \"bytes\");\n const privateKeyBytes = fromHex(privateHex as `0x${string}`, \"bytes\");\n\n // Parse the encrypted data into components\n const encrypted = parseEncryptedDataBuffer(encryptedBytes);\n\n // Decrypt using ECIES\n const decrypted = await this.customEciesProvider.decrypt(\n privateKeyBytes,\n encrypted,\n );\n\n return bytesToString(decrypted);\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = Buffer.from(privateKeyHex, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKey, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPrivateKey\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.encryptWithWalletPublicKey(\n data,\n publicKey,\n );\n } else {\n // Use eccrypto-js directly for wallet encryption\n const eccryptojs = await getEccryptoJS();\n\n // Remove 0x prefix if present\n const cleanKey = publicKey.startsWith(\"0x\")\n ? publicKey.slice(2)\n : publicKey;\n const publicKeyBytes = Buffer.from(cleanKey, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n const publicKeyBuffer =\n publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encryptWithWalletPublicKey\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.decryptWithWalletPrivateKey(\n encryptedData,\n privateKey,\n );\n } else {\n // Use eccrypto-js directly for wallet decryption\n const eccryptojs = await getEccryptoJS();\n const privateKeyBuffer = Buffer.from(privateKey, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKeyBuffer, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decryptWithWalletPrivateKey\", error);\n }\n }\n\n async generateKeyPair(): Promise<{\n privateKey: string;\n publicKey: string;\n }> {\n try {\n if (features.useCustomECIES) {\n // Use custom implementation with @noble/secp256k1\n // Generate random private key\n const privateKeyBytes = secp256k1.utils.randomPrivateKey();\n\n // Generate public key (compressed for consistency with Node implementation)\n const publicKeyBytes = secp256k1.getPublicKey(privateKeyBytes, true);\n\n return {\n privateKey: toHex(privateKeyBytes).slice(2),\n publicKey: toHex(publicKeyBytes).slice(2),\n };\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = eccryptojs.generatePrivate();\n const publicKey = eccryptojs.getPublic(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n }\n } catch (error) {\n throw wrapCryptoError(\"generateKeyPair\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n\n // Create a message from the data\n const message = await openpgp.createMessage({ binary: data });\n\n // Encrypt with password\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(encrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPassword\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n\n // Read the encrypted message\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Decrypt with password\n const { data } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(data as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPassword\", error);\n }\n }\n}\n\n/**\n * Browser implementation of PGP operations\n */\nclass BrowserPGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw new Error(`PGP encryption failed: ${error}`);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw new Error(`PGP decryption failed: ${error}`);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const openpgp = await getOpenPGP();\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Browser implementation of HTTP operations using Fetch API\n */\nclass BrowserHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n return fetch(url, options);\n }\n}\n\n/**\n * Browser implementation of caching using sessionStorage for security\n * SessionStorage is cleared when the tab closes, making it more secure for signature caching\n */\nclass BrowserCacheAdapter implements VanaCacheAdapter {\n private readonly prefix = \"vana_cache_\";\n\n get(key: string): string | null {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return null;\n }\n return sessionStorage.getItem(this.prefix + key);\n } catch {\n return null;\n }\n }\n\n set(key: string, value: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.setItem(this.prefix + key, value);\n } catch {\n // Ignore storage errors (quota exceeded, etc.)\n }\n }\n\n delete(key: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.removeItem(this.prefix + key);\n } catch {\n // Ignore storage errors\n }\n }\n\n clear(): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n // Only clear our prefixed keys to avoid affecting other data\n const keysToRemove: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n if (key?.startsWith(this.prefix)) {\n keysToRemove.push(key);\n }\n }\n keysToRemove.forEach((key) => sessionStorage.removeItem(key));\n } catch {\n // Ignore storage errors\n }\n }\n}\n\n/**\n * Browser implementation of the Vana Platform Adapter\n *\n * This adapter provides all platform-specific functionality for browser environments\n * without requiring any Node.js polyfills.\n */\nexport class BrowserPlatformAdapter implements VanaPlatformAdapter {\n public readonly crypto = new BrowserCryptoAdapter();\n public readonly pgp = new BrowserPGPAdapter();\n public readonly http = new BrowserHttpAdapter();\n public readonly cache = new BrowserCacheAdapter();\n public readonly platform = \"browser\" as const;\n}\n"],"mappings":";;;AAcA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,OAAO,SAAS,eAAe,qBAAqB;AAC7D,SAAS,mBAAmB;AAC5B,YAAY,eAAe;AAC3B,SAAS,gBAAgB;AAGzB,SAAS,iCAAiC;AAG1C,MAAM,aAAa,WAAW,MAAM,OAAO,SAAS,CAAC;AACrD,MAAM,gBAAgB,WAAW,MAAM,OAAO,aAAa,CAAC;AAM5D,MAAM,qBAAkD;AAAA,EAAxD;AAEE;AAAA,wBAAQ,uBAAsB,IAAI,0BAA0B;AAC5D,wBAAQ,uBAAsB,IAAI,2BAA2B;AAAA,MAC3D,eAAe,KAAK;AAAA,IACtB,CAAC;AAAA;AAAA,EAED,MAAM,qBACJ,MACA,cACiB;AACjB,QAAI;AACF,UAAI,SAAS,gBAAgB;AAE3B,cAAM,cAAc,aAAa,WAAW,IAAI,IAC5C,eACA,KAAK,YAAY;AACrB,cAAM,iBAAiB,QAAQ,aAA8B,OAAO;AAGpE,cAAM,YAAY,MAAM,KAAK,oBAAoB;AAAA,UAC/C;AAAA,UACA,cAAc,IAAI;AAAA,QACpB;AAGA,cAAM,SAAS;AAAA,UACb,UAAU;AAAA,UACV,UAAU;AAAA,UACV,UAAU;AAAA,UACV,UAAU;AAAA,QACZ;AAEA,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC;AAAA,MAC9B,OAAO;AAEL,cAAM,aAAa,MAAM,cAAc;AAGvC,cAAM,WAAW,aAAa,WAAW,IAAI,IACzC,aAAa,MAAM,CAAC,IACpB;AACJ,cAAM,iBAAiB,OAAO,KAAK,UAAU,KAAK;AAIlD,c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IAAI,eAAe,QAAQ,KAAK;AAC9C,cAAM,MAAM,eAAe,IAAI,CAAC;AAChC,YAAI,KAAK,WAAW,KAAK,MAAM,GAAG;AAChC,uBAAa,KAAK,GAAG;AAAA,QACvB;AAAA,MACF;AACA,mBAAa,QAAQ,CAAC,QAAQ,eAAe,WAAW,GAAG,CAAC;AAAA,IAC9D,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAQO,MAAM,uBAAsD;AAAA,EAA5D;AACL,wBAAgB,UAAS,IAAI,qBAAqB;AAClD,wBAAgB,OAAM,IAAI,kBAAkB;AAC5C,wBAAgB,QAAO,IAAI,mBAAmB;AAC9C,wBAAgB,SAAQ,IAAI,oBAAoB;AAChD,wBAAgB,YAAW;AAAA;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../../src/platform/browser.ts"],"sourcesContent":["/**\n * Browser implementation of the Vana Platform Adapter using Uint8Array\n *\n * This implementation uses browser-compatible libraries and native APIs\n * without requiring Buffer or other Node.js polyfills.\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport { parseEncryptedDataBuffer } from \"../utils/crypto-utils\";\nimport { toHex, fromHex, stringToBytes, bytesToString, concat } from \"viem\";\nimport * as secp256k1 from \"@noble/secp256k1\";\nimport { features } from \"../config/features\";\n\n// Import browser ECIES provider\nimport { BrowserECIESUint8Provider } from \"../crypto/ecies/browser\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccryptoJS = lazyImport(() => import(\"eccrypto-js\"));\n\n/**\n * Browser implementation of crypto operations using Uint8Array\n * Supports both eccrypto-js (default) and custom ECIES implementation\n */\nclass BrowserCryptoAdapter implements VanaCryptoAdapter {\n // Initialize both providers - only one will be used based on feature flag\n private customEciesProvider = new BrowserECIESUint8Provider();\n private customWalletService = new WalletKeyEncryptionService({\n eciesProvider: this.customEciesProvider,\n });\n\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const prefixedHex = publicKeyHex.startsWith(\"0x\")\n ? publicKeyHex\n : `0x${publicKeyHex}`;\n const publicKeyBytes = fromHex(prefixedHex as `0x${string}`, \"bytes\");\n\n // Encrypt data using ECIES\n const encrypted = await this.customEciesProvider.encrypt(\n publicKeyBytes,\n stringToBytes(data),\n );\n\n // Concatenate all components and return as hex string\n const result = concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return toHex(result).slice(2); // Remove '0x' prefix for backward compatibility\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n\n // Remove 0x prefix if present\n const cleanKey = publicKeyHex.startsWith(\"0x\")\n ? publicKeyHex.slice(2)\n : publicKeyHex;\n const publicKeyBytes = Buffer.from(cleanKey, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n const publicKeyBuffer =\n publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPublicKey\", error);\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const encryptedHex = encryptedData.startsWith(\"0x\")\n ? encryptedData\n : `0x${encryptedData}`;\n const privateHex = privateKeyHex.startsWith(\"0x\")\n ? privateKeyHex\n : `0x${privateKeyHex}`;\n const encryptedBytes = fromHex(encryptedHex as `0x${string}`, \"bytes\");\n const privateKeyBytes = fromHex(privateHex as `0x${string}`, \"bytes\");\n\n // Parse the encrypted data into components\n const encrypted = parseEncryptedDataBuffer(encryptedBytes);\n\n // Decrypt using ECIES\n const decrypted = await this.customEciesProvider.decrypt(\n privateKeyBytes,\n encrypted,\n );\n\n return bytesToString(decrypted);\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = Buffer.from(privateKeyHex, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKey, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPrivateKey\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.encryptWithWalletPublicKey(\n data,\n publicKey,\n );\n } else {\n // Use eccrypto-js directly for wallet encryption\n const eccryptojs = await getEccryptoJS();\n\n // Remove 0x prefix if present\n const cleanKey = publicKey.startsWith(\"0x\")\n ? publicKey.slice(2)\n : publicKey;\n const publicKeyBytes = Buffer.from(cleanKey, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n const publicKeyBuffer =\n publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encryptWithWalletPublicKey\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.decryptWithWalletPrivateKey(\n encryptedData,\n privateKey,\n );\n } else {\n // Use eccrypto-js directly for wallet decryption\n const eccryptojs = await getEccryptoJS();\n const privateKeyBuffer = Buffer.from(privateKey, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKeyBuffer, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decryptWithWalletPrivateKey\", error);\n }\n }\n\n async generateKeyPair(): Promise<{\n privateKey: string;\n publicKey: string;\n }> {\n try {\n if (features.useCustomECIES) {\n // Use custom implementation with @noble/secp256k1\n // Generate random private key\n const privateKeyBytes = secp256k1.utils.randomPrivateKey();\n\n // Generate public key (compressed for consistency with Node implementation)\n const publicKeyBytes = secp256k1.getPublicKey(privateKeyBytes, true);\n\n return {\n privateKey: toHex(privateKeyBytes).slice(2),\n publicKey: toHex(publicKeyBytes).slice(2),\n };\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = eccryptojs.generatePrivate();\n const publicKey = eccryptojs.getPublic(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n }\n } catch (error) {\n throw wrapCryptoError(\"generateKeyPair\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n\n // Create a message from the data\n const message = await openpgp.createMessage({ binary: data });\n\n // Encrypt with password\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(encrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPassword\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n\n // Read the encrypted message\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Decrypt with password\n const { data } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(data as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPassword\", error);\n }\n }\n}\n\n/**\n * Browser implementation of PGP operations\n */\nclass BrowserPGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw new Error(`PGP encryption failed: ${String(error)}`);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw new Error(`PGP decryption failed: ${String(error)}`);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const openpgp = await getOpenPGP();\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Browser implementation of HTTP operations using Fetch API\n */\nclass BrowserHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n return fetch(url, options);\n }\n}\n\n/**\n * Browser implementation of caching using sessionStorage for security\n * SessionStorage is cleared when the tab closes, making it more secure for signature caching\n */\nclass BrowserCacheAdapter implements VanaCacheAdapter {\n private readonly prefix = \"vana_cache_\";\n\n get(key: string): string | null {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return null;\n }\n return sessionStorage.getItem(this.prefix + key);\n } catch {\n return null;\n }\n }\n\n set(key: string, value: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.setItem(this.prefix + key, value);\n } catch {\n // Ignore storage errors (quota exceeded, etc.)\n }\n }\n\n delete(key: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.removeItem(this.prefix + key);\n } catch {\n // Ignore storage errors\n }\n }\n\n clear(): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n // Only clear our prefixed keys to avoid affecting other data\n const keysToRemove: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n if (key?.startsWith(this.prefix)) {\n keysToRemove.push(key);\n }\n }\n keysToRemove.forEach((key) => {\n sessionStorage.removeItem(key);\n });\n } catch {\n // Ignore storage errors\n }\n }\n}\n\n/**\n * Browser implementation of the Vana Platform Adapter\n *\n * This adapter provides all platform-specific functionality for browser environments\n * without requiring any Node.js polyfills.\n */\nexport class BrowserPlatformAdapter implements VanaPlatformAdapter {\n public readonly crypto = new BrowserCryptoAdapter();\n public readonly pgp = new BrowserPGPAdapter();\n public readonly http = new BrowserHttpAdapter();\n public readonly cache = new BrowserCacheAdapter();\n public readonly platform = \"browser\" as const;\n}\n"],"mappings":"AAcA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,OAAO,SAAS,eAAe,eAAe,cAAc;AACrE,YAAY,eAAe;AAC3B,SAAS,gBAAgB;AAGzB,SAAS,iCAAiC;AAG1C,MAAM,aAAa,WAAW,MAAM,OAAO,SAAS,CAAC;AACrD,MAAM,gBAAgB,WAAW,MAAM,OAAO,aAAa,CAAC;AAM5D,MAAM,qBAAkD;AAAA;AAAA,EAE9C,sBAAsB,IAAI,0BAA0B;AAAA,EACpD,sBAAsB,IAAI,2BAA2B;AAAA,IAC3D,eAAe,KAAK;AAAA,EACtB,CAAC;AAAA,EAED,MAAM,qBACJ,MACA,cACiB;AACjB,QAAI;AACF,UAAI,SAAS,gBAAgB;AAE3B,cAAM,cAAc,aAAa,WAAW,IAAI,IAC5C,eACA,KAAK,YAAY;AACrB,cAAM,iBAAiB,QAAQ,aAA8B,OAAO;AAGpE,cAAM,YAAY,MAAM,KAAK,oBAAoB;AAAA,UAC/C;AAAA,UACA,cAAc,IAAI;AAAA,QACpB;AAGA,cAAM,SAAS,OAAO;AAAA,UACpB,UAAU;AAAA,UACV,UAAU;AAAA,UACV,UAAU;AAAA,UACV,UAAU;AAAA,QACZ,CAAC;AAED,eAAO,MAAM,MAAM,EAAE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,KAAK,SAAS,GAAG;AAAA,IAC7C,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,QAAI;AACF,UAAI,OAAO,mBAAmB,aAAa;AACzC;AAAA,MACF;AAEA,YAAM,eAAyB,CAAC;AAChC,eAAS,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;AAC9C,cAAM,MAAM,eAAe,IAAI,CAAC;AAChC,YAAI,KAAK,WAAW,KAAK,MAAM,GAAG;AAChC,uBAAa,KAAK,GAAG;AAAA,QACvB;AAAA,MACF;AACA,mBAAa,QAAQ,CAAC,QAAQ;AAC5B,uBAAe,WAAW,GAAG;AAAA,MAC/B,CAAC;AAAA,IACH,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAQO,MAAM,uBAAsD;AAAA,EACjD,SAAS,IAAI,qBAAqB;AAAA,EAClC,MAAM,IAAI,kBAAkB;AAAA,EAC5B,OAAO,IAAI,mBAAmB;AAAA,EAC9B,QAAQ,IAAI,oBAAoB;AAAA,EAChC,WAAW;AAC7B;","names":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,11 @@
1
- export { PlatformType, VanaCryptoAdapter, VanaHttpAdapter, VanaPGPAdapter, VanaPlatformAdapter } from './interface.js';
2
- export { NodePlatformAdapter } from './node.js';
3
- export { BrowserPlatformAdapter } from './browser.js';
4
- export { createPlatformAdapter, createPlatformAdapterFor, detectPlatform, getPlatformCapabilities, isPlatformSupported } from './utils.js';
5
- export { createBrowserPlatformAdapter, createNodePlatformAdapter, createPlatformAdapterSafe } from './browser-safe.js';
1
+ /**
2
+ * Platform adapter types and implementations
3
+ *
4
+ * This module exports the platform-specific adapters and interfaces
5
+ * along with utilities for platform detection and adapter creation.
6
+ */
7
+ export type { VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaPlatformAdapter, PlatformType, } from "./interface";
8
+ export { NodePlatformAdapter } from "./node";
9
+ export { BrowserPlatformAdapter } from "./browser";
10
+ export { detectPlatform, createPlatformAdapter, createPlatformAdapterFor, isPlatformSupported, getPlatformCapabilities, } from "./utils";
11
+ export { createNodePlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, } from "./browser-safe";
@@ -16,11 +16,11 @@
16
16
  /**
17
17
  * Platform type identifier
18
18
  */
19
- type PlatformType = "node" | "browser";
19
+ export type PlatformType = "node" | "browser";
20
20
  /**
21
21
  * Encryption operations that require different implementations per platform
22
22
  */
23
- interface VanaCryptoAdapter {
23
+ export interface VanaCryptoAdapter {
24
24
  /**
25
25
  * Encrypt data with a public key using asymmetric cryptography
26
26
  *
@@ -96,7 +96,7 @@ interface VanaCryptoAdapter {
96
96
  /**
97
97
  * PGP operations that require different configurations per platform
98
98
  */
99
- interface VanaPGPAdapter {
99
+ export interface VanaPGPAdapter {
100
100
  /**
101
101
  * Encrypt data using PGP with proper platform configuration
102
102
  *
@@ -134,7 +134,7 @@ interface VanaPGPAdapter {
134
134
  /**
135
135
  * HTTP operations that need consistent API across platforms
136
136
  */
137
- interface VanaHttpAdapter {
137
+ export interface VanaHttpAdapter {
138
138
  /**
139
139
  * Perform HTTP request with platform-appropriate fetch implementation
140
140
  *
@@ -147,7 +147,7 @@ interface VanaHttpAdapter {
147
147
  /**
148
148
  * Simple cache operations that work across platforms
149
149
  */
150
- interface VanaCacheAdapter {
150
+ export interface VanaCacheAdapter {
151
151
  /**
152
152
  * Get a value from the cache
153
153
  *
@@ -192,7 +192,7 @@ interface VanaCacheAdapter {
192
192
  * }
193
193
  * ```
194
194
  */
195
- interface VanaPlatformAdapter {
195
+ export interface VanaPlatformAdapter {
196
196
  /**
197
197
  * Crypto operations adapter
198
198
  */
@@ -214,5 +214,3 @@ interface VanaPlatformAdapter {
214
214
  */
215
215
  readonly platform: PlatformType;
216
216
  }
217
-
218
- export type { PlatformType, VanaCacheAdapter, VanaCryptoAdapter, VanaHttpAdapter, VanaPGPAdapter, VanaPlatformAdapter };
@@ -1,5 +1,3 @@
1
- import { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaCacheAdapter } from './interface.js';
2
-
3
1
  /**
4
2
  * Node.js implementation of the Vana Platform Adapter
5
3
  *
@@ -7,11 +5,11 @@ import { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter
7
5
  * MUST be dynamically imported to support Turbopack.
8
6
  * See: https://github.com/vercel/next.js/issues/82632
9
7
  */
10
-
8
+ import type { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaCacheAdapter } from "./interface";
11
9
  /**
12
10
  * Complete Node.js platform adapter implementation
13
11
  */
14
- declare class NodePlatformAdapter implements VanaPlatformAdapter {
12
+ export declare class NodePlatformAdapter implements VanaPlatformAdapter {
15
13
  crypto: VanaCryptoAdapter;
16
14
  pgp: VanaPGPAdapter;
17
15
  http: VanaHttpAdapter;
@@ -22,6 +20,4 @@ declare class NodePlatformAdapter implements VanaPlatformAdapter {
22
20
  /**
23
21
  * Default instance export for backwards compatibility
24
22
  */
25
- declare const nodePlatformAdapter: VanaPlatformAdapter;
26
-
27
- export { NodePlatformAdapter, nodePlatformAdapter };
23
+ export declare const nodePlatformAdapter: VanaPlatformAdapter;
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import { getPGPKeyGenParams } from "./shared/pgp-utils";
5
2
  import { wrapCryptoError } from "./shared/error-utils";
6
3
  import { streamToUint8Array } from "./shared/stream-utils";
@@ -19,13 +16,11 @@ import { ECIESError } from "../crypto/ecies/interface";
19
16
  import { randomBytes } from "crypto";
20
17
  import secp256k1Import from "secp256k1";
21
18
  class NodeCryptoAdapter {
22
- constructor() {
23
- // Initialize both providers - only one will be used based on feature flag
24
- __publicField(this, "customEciesProvider", new NodeECIESUint8Provider());
25
- __publicField(this, "customWalletService", new WalletKeyEncryptionService({
26
- eciesProvider: this.customEciesProvider
27
- }));
28
- }
19
+ // Initialize both providers - only one will be used based on feature flag
20
+ customEciesProvider = new NodeECIESUint8Provider();
21
+ customWalletService = new WalletKeyEncryptionService({
22
+ eciesProvider: this.customEciesProvider
23
+ });
29
24
  async encryptWithPublicKey(data, publicKeyHex) {
30
25
  try {
31
26
  if (features.useCustomECIES) {
@@ -277,10 +272,8 @@ class NodeHttpAdapter {
277
272
  }
278
273
  }
279
274
  class NodeCacheAdapter {
280
- constructor() {
281
- __publicField(this, "cache", /* @__PURE__ */ new Map());
282
- __publicField(this, "defaultTtl", 2 * 60 * 60 * 1e3);
283
- }
275
+ cache = /* @__PURE__ */ new Map();
276
+ defaultTtl = 2 * 60 * 60 * 1e3;
284
277
  // 2 hours in milliseconds
285
278
  get(key) {
286
279
  const entry = this.cache.get(key);
@@ -307,12 +300,12 @@ class NodeCacheAdapter {
307
300
  }
308
301
  }
309
302
  class NodePlatformAdapter {
303
+ crypto;
304
+ pgp;
305
+ http;
306
+ cache;
307
+ platform = "node";
310
308
  constructor() {
311
- __publicField(this, "crypto");
312
- __publicField(this, "pgp");
313
- __publicField(this, "http");
314
- __publicField(this, "cache");
315
- __publicField(this, "platform", "node");
316
309
  this.crypto = new NodeCryptoAdapter();
317
310
  this.pgp = new NodePGPAdapter();
318
311
  this.http = new NodeHttpAdapter();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/platform/node.ts"],"sourcesContent":["/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * WARNING: Dependencies that access globals during init\n * MUST be dynamically imported to support Turbopack.\n * See: https://github.com/vercel/next.js/issues/82632\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\nimport { features } from \"../config/features\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport {\n processWalletPrivateKey,\n parseEncryptedDataBuffer,\n processWalletPublicKey,\n} from \"../utils/crypto-utils\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccryptoJS = lazyImport(() => import(\"eccrypto-js\"));\n\n// Import both ECIES implementations statically\nimport { NodeECIESUint8Provider } from \"../crypto/ecies/node\";\nimport { ECIESError } from \"../crypto/ecies/interface\";\nimport type { ECIESEncrypted } from \"../crypto/ecies\";\nimport { randomBytes } from \"crypto\";\nimport secp256k1Import from \"secp256k1\";\n\n// Type definition for secp256k1 module\ninterface Secp256k1Module {\n privateKeyVerify(privateKey: Buffer): boolean;\n publicKeyCreate(privateKey: Buffer, compressed: boolean): Buffer;\n publicKeyVerify(publicKey: Buffer): boolean;\n publicKeyConvert(publicKey: Buffer, compressed: boolean): Buffer;\n ecdh(\n publicKey: Buffer,\n privateKey: Buffer,\n options: {\n hashfn: (x: Uint8Array, y: Uint8Array, output?: Uint8Array) => Uint8Array;\n },\n output: Buffer,\n ): Buffer;\n}\n\n/**\n * Node.js implementation of crypto operations\n * Supports both eccrypto (default) and custom ECIES implementation\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n // Initialize both providers - only one will be used based on feature flag\n private customEciesProvider = new NodeECIESUint8Provider();\n private customWalletService = new WalletKeyEncryptionService({\n eciesProvider: this.customEciesProvider,\n });\n\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await this.customEciesProvider.encrypt(\n publicKey,\n message,\n );\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKey, message);\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n if (features.useCustomECIES && error instanceof ECIESError) {\n throw error;\n }\n throw new Error(\n `Encryption failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure\n const encryptedObj: ECIESEncrypted = {\n iv,\n ephemPublicKey,\n ciphertext,\n mac,\n };\n\n const decrypted = await this.customEciesProvider.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n return new TextDecoder().decode(decrypted);\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = Buffer.from(privateKeyHex, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKey, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n if (features.useCustomECIES && error instanceof ECIESError) {\n throw error;\n }\n throw new Error(\n `Decryption failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n try {\n if (features.useCustomECIES) {\n // Use custom implementation with secp256k1\n const secp256k1 = secp256k1Import as unknown as Secp256k1Module;\n\n // Generate private key\n let privateKey: Buffer;\n do {\n privateKey = randomBytes(32);\n } while (!secp256k1.privateKeyVerify(privateKey));\n\n // Get compressed public key\n const publicKey = Buffer.from(\n secp256k1.publicKeyCreate(privateKey, true),\n );\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = eccryptojs.generatePrivate();\n const publicKey = eccryptojs.getPublic(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n }\n } catch (error) {\n throw wrapCryptoError(\"key generation\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.encryptWithWalletPublicKey(\n data,\n publicKey,\n );\n } else {\n // Use eccrypto-js directly for wallet encryption\n const eccryptojs = await getEccryptoJS();\n const publicKeyBuffer = Buffer.from(processWalletPublicKey(publicKey));\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encrypt with wallet public key\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.decryptWithWalletPrivateKey(\n encryptedData,\n privateKey,\n );\n } else {\n // Use eccrypto-js directly for wallet decryption\n const eccryptojs = await getEccryptoJS();\n const privateKeyBuffer = Buffer.from(\n processWalletPrivateKey(privateKey),\n );\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKeyBuffer, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decrypt with wallet private key\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.createMessage({\n binary: data,\n });\n\n // Use password-based encryption with wallet signature as password\n // Note: For deterministic encryption, we would need to control the salt\n // This implementation is secure but not deterministic due to OpenPGP's design\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Use password-based decryption with wallet signature as password\n const { data: decrypted } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert decrypted data back to Uint8Array\n return new Uint8Array(decrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP encryption\", error);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP decryption\", error);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const openpgp = await getOpenPGP();\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n"],"mappings":";;;AAeA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,aAAa,WAAW,MAAM,OAAO,SAAS,CAAC;AACrD,MAAM,gBAAgB,WAAW,MAAM,OAAO,aAAa,CAAC;AAG5D,SAAS,8BAA8B;AACvC,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;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,gBAAgB,sBAAsB,KAAK;AAAA,IACnD;AAAA,EACF;AACF;AAKA,MAAM,gBAA2C;AAAA,EAC/C,MAAM,MAAM,KAAa,SAA0C;AACjE,QAAI,OAAO,WAAW,UAAU,aAAa;AAC3C,aAAO,WAAW,MAAM,KAAK,OAAO;AAAA,IACtC;AAEA,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AACF;AAKA,MAAM,iBAA6C;AAAA,EAAnD;AACE,wBAAQ,SAAQ,oBAAI,IAAgD;AACpE,wBAAiB,cAAa,IAAI,KAAK,KAAK;AAAA;AAAA;AAAA,EAE5C,IAAI,KAA4B;AAC9B,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAChC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAGA,QAAI,KAAK,IAAI,IAAI,MAAM,SAAS;AAC9B,WAAK,MAAM,OAAO,GAAG;AACrB,aAAO;AAAA,IACT;AAEA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,IAAI,KAAa,OAAqB;AACpC,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB;AAAA,MACA,SAAS,KAAK,IAAI,IAAI,KAAK;AAAA,IAC7B,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;AAKO,MAAM,oBAAmD;AAAA,EAO9D,cAAc;AANd;AACA;AACA;AACA;AACA,oCAAmB;AAGjB,SAAK,SAAS,IAAI,kBAAkB;AACpC,SAAK,MAAM,IAAI,eAAe;AAC9B,SAAK,OAAO,IAAI,gBAAgB;AAChC,SAAK,QAAQ,IAAI,iBAAiB;AAAA,EACpC;AACF;AAKO,MAAM,sBACX,IAAI,oBAAoB;","names":[]}
1
+ {"version":3,"sources":["../../src/platform/node.ts"],"sourcesContent":["/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * WARNING: Dependencies that access globals during init\n * MUST be dynamically imported to support Turbopack.\n * See: https://github.com/vercel/next.js/issues/82632\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\nimport { features } from \"../config/features\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport {\n processWalletPrivateKey,\n parseEncryptedDataBuffer,\n processWalletPublicKey,\n} from \"../utils/crypto-utils\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccryptoJS = lazyImport(() => import(\"eccrypto-js\"));\n\n// Import both ECIES implementations statically\nimport { NodeECIESUint8Provider } from \"../crypto/ecies/node\";\nimport { ECIESError } from \"../crypto/ecies/interface\";\nimport type { ECIESEncrypted } from \"../crypto/ecies\";\nimport { randomBytes } from \"crypto\";\nimport secp256k1Import from \"secp256k1\";\n\n// Type definition for secp256k1 module\ninterface Secp256k1Module {\n privateKeyVerify(privateKey: Buffer): boolean;\n publicKeyCreate(privateKey: Buffer, compressed: boolean): Buffer;\n publicKeyVerify(publicKey: Buffer): boolean;\n publicKeyConvert(publicKey: Buffer, compressed: boolean): Buffer;\n ecdh(\n publicKey: Buffer,\n privateKey: Buffer,\n options: {\n hashfn: (x: Uint8Array, y: Uint8Array, output?: Uint8Array) => Uint8Array;\n },\n output: Buffer,\n ): Buffer;\n}\n\n/**\n * Node.js implementation of crypto operations\n * Supports both eccrypto (default) and custom ECIES implementation\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n // Initialize both providers - only one will be used based on feature flag\n private customEciesProvider = new NodeECIESUint8Provider();\n private customWalletService = new WalletKeyEncryptionService({\n eciesProvider: this.customEciesProvider,\n });\n\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await this.customEciesProvider.encrypt(\n publicKey,\n message,\n );\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKey, message);\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n if (features.useCustomECIES && error instanceof ECIESError) {\n throw error;\n }\n throw new Error(\n `Encryption failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation\n const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure\n const encryptedObj: ECIESEncrypted = {\n iv,\n ephemPublicKey,\n ciphertext,\n mac,\n };\n\n const decrypted = await this.customEciesProvider.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n return new TextDecoder().decode(decrypted);\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = Buffer.from(privateKeyHex, \"hex\");\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKey, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n if (features.useCustomECIES && error instanceof ECIESError) {\n throw error;\n }\n throw new Error(\n `Decryption failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n try {\n if (features.useCustomECIES) {\n // Use custom implementation with secp256k1\n const secp256k1 = secp256k1Import as unknown as Secp256k1Module;\n\n // Generate private key\n let privateKey: Buffer;\n do {\n privateKey = randomBytes(32);\n } while (!secp256k1.privateKeyVerify(privateKey));\n\n // Get compressed public key\n const publicKey = Buffer.from(\n secp256k1.publicKeyCreate(privateKey, true),\n );\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n } else {\n // Use eccrypto-js (default)\n const eccryptojs = await getEccryptoJS();\n const privateKey = eccryptojs.generatePrivate();\n const publicKey = eccryptojs.getPublic(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n }\n } catch (error) {\n throw wrapCryptoError(\"key generation\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.encryptWithWalletPublicKey(\n data,\n publicKey,\n );\n } else {\n // Use eccrypto-js directly for wallet encryption\n const eccryptojs = await getEccryptoJS();\n const publicKeyBuffer = Buffer.from(processWalletPublicKey(publicKey));\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptojs.encrypt(publicKeyBuffer, message);\n\n // Concatenate all components and return as hex string\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n }\n } catch (error) {\n throw wrapCryptoError(\"encrypt with wallet public key\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n if (features.useCustomECIES) {\n // Use custom ECIES implementation via WalletKeyEncryptionService\n return await this.customWalletService.decryptWithWalletPrivateKey(\n encryptedData,\n privateKey,\n );\n } else {\n // Use eccrypto-js directly for wallet decryption\n const eccryptojs = await getEccryptoJS();\n const privateKeyBuffer = Buffer.from(\n processWalletPrivateKey(privateKey),\n );\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n\n // Parse the encrypted data\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n const decrypted = await eccryptojs.decrypt(privateKeyBuffer, {\n iv: Buffer.from(iv),\n ephemPublicKey: Buffer.from(ephemPublicKey),\n ciphertext: Buffer.from(ciphertext),\n mac: Buffer.from(mac),\n });\n\n return decrypted.toString(\"utf8\");\n }\n } catch (error) {\n throw wrapCryptoError(\"decrypt with wallet private key\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.createMessage({\n binary: data,\n });\n\n // Use password-based encryption with wallet signature as password\n // Note: For deterministic encryption, we would need to control the salt\n // This implementation is secure but not deterministic due to OpenPGP's design\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Use password-based decryption with wallet signature as password\n const { data: decrypted } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert decrypted data back to Uint8Array\n return new Uint8Array(decrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP encryption\", error);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP decryption\", error);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const openpgp = await getOpenPGP();\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n"],"mappings":"AAeA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,SAAS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AK,OAAO,IAAI,gBAAgB;AAChC,SAAK,QAAQ,IAAI,iBAAiB;AAAA,EACpC;AACF;AAKO,MAAM,sBACX,IAAI,oBAAoB;","names":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var openpgp_port_exports = {};
20
+ __export(openpgp_port_exports, {
21
+ OpenPgpPort: () => OpenPgpPort,
22
+ openPgpPort: () => openPgpPort
23
+ });
24
+ module.exports = __toCommonJS(openpgp_port_exports);
25
+ var import_openpgp = require("openpgp");
26
+ class OpenPgpPort {
27
+ async encrypt(input) {
28
+ const publicKey = await (0, import_openpgp.readKey)({ armoredKey: input.publicKeyArmored });
29
+ const message = await (0, import_openpgp.createMessage)({ text: input.text });
30
+ const encrypted = await (0, import_openpgp.encrypt)({
31
+ message,
32
+ encryptionKeys: publicKey,
33
+ config: {
34
+ preferredCompressionAlgorithm: import_openpgp.enums.compression.zlib
35
+ }
36
+ });
37
+ return { data: encrypted };
38
+ }
39
+ async decrypt(input) {
40
+ const privateKey = await (0, import_openpgp.readPrivateKey)({
41
+ armoredKey: input.privateKeyArmored
42
+ });
43
+ const decryptedKey = input.passphrase ? await (0, import_openpgp.decryptKey)({ privateKey, passphrase: input.passphrase }) : privateKey;
44
+ const message = await (0, import_openpgp.readMessage)({ armoredMessage: input.messageArmored });
45
+ const { data } = await (0, import_openpgp.decrypt)({
46
+ message,
47
+ decryptionKeys: decryptedKey
48
+ });
49
+ return { data };
50
+ }
51
+ async generateKeyPair(options = {}) {
52
+ const { name = "Vana User", email = "user@vana.org", passphrase } = options;
53
+ const { publicKey, privateKey } = await (0, import_openpgp.generateKey)({
54
+ type: "rsa",
55
+ rsaBits: 2048,
56
+ userIDs: [{ name, email }],
57
+ passphrase,
58
+ config: {
59
+ preferredCompressionAlgorithm: 2,
60
+ // zlib
61
+ preferredSymmetricAlgorithm: 7
62
+ // aes256
63
+ }
64
+ });
65
+ return { publicKey, privateKey };
66
+ }
67
+ }
68
+ const openPgpPort = new OpenPgpPort();
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ OpenPgpPort,
72
+ openPgpPort
73
+ });
74
+ //# sourceMappingURL=openpgp-port.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform/ports/openpgp-port.ts"],"sourcesContent":["/**\n * OpenPGP implementation of PgpPort\n *\n * This adapter wraps the openpgp library and maps its complex API\n * to our simpler, testable port interface.\n */\n\nimport {\n readKey,\n readPrivateKey,\n decryptKey,\n readMessage,\n createMessage,\n encrypt,\n decrypt,\n generateKey,\n enums,\n} from \"openpgp\";\n\nimport type {\n PgpPort,\n PgpEncryptInput,\n PgpDecryptInput,\n PgpResult,\n PgpKeyPair,\n PgpKeyPairOptions,\n} from \"./pgp-port\";\n\nexport class OpenPgpPort implements PgpPort {\n async encrypt(input: PgpEncryptInput): Promise<PgpResult> {\n const publicKey = await readKey({ armoredKey: input.publicKeyArmored });\n const message = await createMessage({ text: input.text });\n\n const encrypted = await encrypt({\n message,\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: enums.compression.zlib,\n },\n });\n\n return { data: encrypted as string };\n }\n\n async decrypt(input: PgpDecryptInput): Promise<PgpResult> {\n const privateKey = await readPrivateKey({\n armoredKey: input.privateKeyArmored,\n });\n const decryptedKey = input.passphrase\n ? await decryptKey({ privateKey, passphrase: input.passphrase })\n : privateKey;\n const message = await readMessage({ armoredMessage: input.messageArmored });\n\n const { data } = await decrypt({\n message,\n decryptionKeys: decryptedKey,\n });\n\n return { data: data as string };\n }\n\n async generateKeyPair(options: PgpKeyPairOptions = {}): Promise<PgpKeyPair> {\n const { name = \"Vana User\", email = \"user@vana.org\", passphrase } = options;\n\n const { publicKey, privateKey } = await generateKey({\n type: \"rsa\",\n rsaBits: 2048,\n userIDs: [{ name, email }],\n passphrase,\n config: {\n preferredCompressionAlgorithm: 2, // zlib\n preferredSymmetricAlgorithm: 7, // aes256\n },\n });\n\n return { publicKey, privateKey };\n }\n}\n\n// Default instance for production use\nexport const openPgpPort = new OpenPgpPort();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qBAUO;AAWA,MAAM,YAA+B;AAAA,EAC1C,MAAM,QAAQ,OAA4C;AACxD,UAAM,YAAY,UAAM,wBAAQ,EAAE,YAAY,MAAM,iBAAiB,CAAC;AACtE,UAAM,UAAU,UAAM,8BAAc,EAAE,MAAM,MAAM,KAAK,CAAC;AAExD,UAAM,YAAY,UAAM,wBAAQ;AAAA,MAC9B;AAAA,MACA,gBAAgB;AAAA,MAChB,QAAQ;AAAA,QACN,+BAA+B,qBAAM,YAAY;AAAA,MACnD;AAAA,IACF,CAAC;AAED,WAAO,EAAE,MAAM,UAAoB;AAAA,EACrC;AAAA,EAEA,MAAM,QAAQ,OAA4C;AACxD,UAAM,aAAa,UAAM,+BAAe;AAAA,MACtC,YAAY,MAAM;AAAA,IACpB,CAAC;AACD,UAAM,eAAe,MAAM,aACvB,UAAM,2BAAW,EAAE,YAAY,YAAY,MAAM,WAAW,CAAC,IAC7D;AACJ,UAAM,UAAU,UAAM,4BAAY,EAAE,gBAAgB,MAAM,eAAe,CAAC;AAE1E,UAAM,EAAE,KAAK,IAAI,UAAM,wBAAQ;AAAA,MAC7B;AAAA,MACA,gBAAgB;AAAA,IAClB,CAAC;AAED,WAAO,EAAE,KAAqB;AAAA,EAChC;AAAA,EAEA,MAAM,gBAAgB,UAA6B,CAAC,GAAwB;AAC1E,UAAM,EAAE,OAAO,aAAa,QAAQ,iBAAiB,WAAW,IAAI;AAEpE,UAAM,EAAE,WAAW,WAAW,IAAI,UAAM,4BAAY;AAAA,MAClD,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,MACzB;AAAA,MACA,QAAQ;AAAA,QACN,+BAA+B;AAAA;AAAA,QAC/B,6BAA6B;AAAA;AAAA,MAC/B;AAAA,IACF,CAAC;AAED,WAAO,EAAE,WAAW,WAAW;AAAA,EACjC;AACF;AAGO,MAAM,cAAc,IAAI,YAAY;","names":[]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * OpenPGP implementation of PgpPort
3
+ *
4
+ * This adapter wraps the openpgp library and maps its complex API
5
+ * to our simpler, testable port interface.
6
+ */
7
+ import type { PgpPort, PgpEncryptInput, PgpDecryptInput, PgpResult, PgpKeyPair, PgpKeyPairOptions } from "./pgp-port";
8
+ export declare class OpenPgpPort implements PgpPort {
9
+ encrypt(input: PgpEncryptInput): Promise<PgpResult>;
10
+ decrypt(input: PgpDecryptInput): Promise<PgpResult>;
11
+ generateKeyPair(options?: PgpKeyPairOptions): Promise<PgpKeyPair>;
12
+ }
13
+ export declare const openPgpPort: OpenPgpPort;