@useragent-kit/sdk 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +61 -3
  3. package/dist/adapters.d.ts +94 -0
  4. package/dist/adapters.d.ts.map +1 -0
  5. package/dist/adapters.js +188 -0
  6. package/dist/adapters.js.map +1 -0
  7. package/dist/api-protocol.d.ts +9 -0
  8. package/dist/api-protocol.d.ts.map +1 -0
  9. package/dist/api-protocol.js +9 -0
  10. package/dist/api-protocol.js.map +1 -0
  11. package/dist/bridge/contract.d.ts +66 -0
  12. package/dist/bridge/contract.d.ts.map +1 -0
  13. package/dist/bridge/contract.js +160 -0
  14. package/dist/bridge/contract.js.map +1 -0
  15. package/dist/bridge/index.d.ts +53 -0
  16. package/dist/bridge/index.d.ts.map +1 -0
  17. package/dist/bridge/index.js +302 -0
  18. package/dist/bridge/index.js.map +1 -0
  19. package/dist/bridge/types.d.ts +93 -0
  20. package/dist/bridge/types.d.ts.map +1 -0
  21. package/dist/bridge/types.js +9 -0
  22. package/dist/bridge/types.js.map +1 -0
  23. package/dist/chain.d.ts +198 -0
  24. package/dist/chain.d.ts.map +1 -0
  25. package/dist/chain.js +424 -0
  26. package/dist/chain.js.map +1 -0
  27. package/dist/errors.d.ts +22 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +41 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/events.d.ts +252 -0
  32. package/dist/events.d.ts.map +1 -0
  33. package/dist/events.js +54 -0
  34. package/dist/events.js.map +1 -0
  35. package/dist/experimental/file-transfer.d.ts +97 -0
  36. package/dist/experimental/file-transfer.d.ts.map +1 -0
  37. package/dist/experimental/file-transfer.js +1377 -0
  38. package/dist/experimental/file-transfer.js.map +1 -0
  39. package/dist/experimental/index.d.ts +7 -0
  40. package/dist/experimental/index.d.ts.map +1 -0
  41. package/dist/experimental/index.js +4 -0
  42. package/dist/experimental/index.js.map +1 -0
  43. package/dist/experimental/logger.d.ts +5 -0
  44. package/dist/experimental/logger.d.ts.map +1 -0
  45. package/dist/experimental/logger.js +74 -0
  46. package/dist/experimental/logger.js.map +1 -0
  47. package/dist/experimental/transport.d.ts +34 -0
  48. package/dist/experimental/transport.d.ts.map +1 -0
  49. package/dist/experimental/transport.js +43 -0
  50. package/dist/experimental/transport.js.map +1 -0
  51. package/dist/guest/claw.d.ts +10 -0
  52. package/dist/guest/claw.d.ts.map +1 -0
  53. package/dist/guest/claw.js +21 -0
  54. package/dist/guest/claw.js.map +1 -0
  55. package/dist/guest/crdt.d.ts +19 -0
  56. package/dist/guest/crdt.d.ts.map +1 -0
  57. package/dist/guest/crdt.js +64 -0
  58. package/dist/guest/crdt.js.map +1 -0
  59. package/dist/guest/data.d.ts +27 -0
  60. package/dist/guest/data.d.ts.map +1 -0
  61. package/dist/guest/data.js +61 -0
  62. package/dist/guest/data.js.map +1 -0
  63. package/dist/guest/files.d.ts +15 -0
  64. package/dist/guest/files.d.ts.map +1 -0
  65. package/dist/guest/files.js +24 -0
  66. package/dist/guest/files.js.map +1 -0
  67. package/dist/guest/index.d.ts +43 -0
  68. package/dist/guest/index.d.ts.map +1 -0
  69. package/dist/guest/index.js +44 -0
  70. package/dist/guest/index.js.map +1 -0
  71. package/dist/guest/media.d.ts +44 -0
  72. package/dist/guest/media.d.ts.map +1 -0
  73. package/dist/guest/media.js +97 -0
  74. package/dist/guest/media.js.map +1 -0
  75. package/dist/guest/mesh.d.ts +79 -0
  76. package/dist/guest/mesh.d.ts.map +1 -0
  77. package/dist/guest/mesh.js +153 -0
  78. package/dist/guest/mesh.js.map +1 -0
  79. package/dist/guest/navigate.d.ts +17 -0
  80. package/dist/guest/navigate.d.ts.map +1 -0
  81. package/dist/guest/navigate.js +169 -0
  82. package/dist/guest/navigate.js.map +1 -0
  83. package/dist/guest/statements.d.ts +18 -0
  84. package/dist/guest/statements.d.ts.map +1 -0
  85. package/dist/guest/statements.js +26 -0
  86. package/dist/guest/statements.js.map +1 -0
  87. package/dist/guest/telemetry.d.ts +88 -0
  88. package/dist/guest/telemetry.d.ts.map +1 -0
  89. package/dist/guest/telemetry.js +184 -0
  90. package/dist/guest/telemetry.js.map +1 -0
  91. package/dist/guest/types.d.ts +255 -0
  92. package/dist/guest/types.d.ts.map +1 -0
  93. package/dist/guest/types.js +9 -0
  94. package/dist/guest/types.js.map +1 -0
  95. package/dist/host-runtime-contract.d.ts +19 -0
  96. package/dist/host-runtime-contract.d.ts.map +1 -0
  97. package/dist/host-runtime-contract.js +80 -0
  98. package/dist/host-runtime-contract.js.map +1 -0
  99. package/dist/host-runtime-frame.d.ts +128 -0
  100. package/dist/host-runtime-frame.d.ts.map +1 -0
  101. package/dist/host-runtime-frame.js +881 -0
  102. package/dist/host-runtime-frame.js.map +1 -0
  103. package/dist/host-runtime-registry.d.ts +16 -0
  104. package/dist/host-runtime-registry.d.ts.map +1 -0
  105. package/dist/host-runtime-registry.js +53 -0
  106. package/dist/host-runtime-registry.js.map +1 -0
  107. package/dist/host-runtime.d.ts +106 -0
  108. package/dist/host-runtime.d.ts.map +1 -0
  109. package/dist/host-runtime.js +290 -0
  110. package/dist/host-runtime.js.map +1 -0
  111. package/dist/identity-adapter.d.ts +42 -0
  112. package/dist/identity-adapter.d.ts.map +1 -0
  113. package/dist/identity-adapter.js +43 -0
  114. package/dist/identity-adapter.js.map +1 -0
  115. package/dist/identity.d.ts +86 -0
  116. package/dist/identity.d.ts.map +1 -0
  117. package/dist/identity.js +223 -0
  118. package/dist/identity.js.map +1 -0
  119. package/dist/index.d.ts +91 -0
  120. package/dist/index.d.ts.map +1 -0
  121. package/dist/index.js +356 -0
  122. package/dist/index.js.map +1 -0
  123. package/dist/internal/api-protocol/api/protocol.d.ts +1402 -0
  124. package/dist/internal/api-protocol/api/protocol.d.ts.map +1 -0
  125. package/dist/internal/api-protocol/api/protocol.js +311 -0
  126. package/dist/internal/api-protocol/api/protocol.js.map +1 -0
  127. package/dist/internal/api-protocol/api/types.d.ts +24 -0
  128. package/dist/internal/api-protocol/api/types.d.ts.map +1 -0
  129. package/dist/internal/api-protocol/api/types.js +9 -0
  130. package/dist/internal/api-protocol/api/types.js.map +1 -0
  131. package/dist/internal/api-protocol/host-facade/connectionManager.d.ts +44 -0
  132. package/dist/internal/api-protocol/host-facade/connectionManager.d.ts.map +1 -0
  133. package/dist/internal/api-protocol/host-facade/connectionManager.js +349 -0
  134. package/dist/internal/api-protocol/host-facade/connectionManager.js.map +1 -0
  135. package/dist/internal/api-protocol/host-facade/protocolHandler.d.ts +24 -0
  136. package/dist/internal/api-protocol/host-facade/protocolHandler.d.ts.map +1 -0
  137. package/dist/internal/api-protocol/host-facade/protocolHandler.js +505 -0
  138. package/dist/internal/api-protocol/host-facade/protocolHandler.js.map +1 -0
  139. package/dist/internal/api-protocol/host-facade/types.d.ts +82 -0
  140. package/dist/internal/api-protocol/host-facade/types.d.ts.map +1 -0
  141. package/dist/internal/api-protocol/host-facade/types.js +14 -0
  142. package/dist/internal/api-protocol/host-facade/types.js.map +1 -0
  143. package/dist/internal/api-protocol/index.d.ts +39 -0
  144. package/dist/internal/api-protocol/index.d.ts.map +1 -0
  145. package/dist/internal/api-protocol/index.js +41 -0
  146. package/dist/internal/api-protocol/index.js.map +1 -0
  147. package/dist/internal/api-protocol/product-facade/hostApi.d.ts +392 -0
  148. package/dist/internal/api-protocol/product-facade/hostApi.d.ts.map +1 -0
  149. package/dist/internal/api-protocol/product-facade/hostApi.js +241 -0
  150. package/dist/internal/api-protocol/product-facade/hostApi.js.map +1 -0
  151. package/dist/internal/api-protocol/shared/codec/adapter.d.ts +41 -0
  152. package/dist/internal/api-protocol/shared/codec/adapter.d.ts.map +1 -0
  153. package/dist/internal/api-protocol/shared/codec/adapter.js +10 -0
  154. package/dist/internal/api-protocol/shared/codec/adapter.js.map +1 -0
  155. package/dist/internal/api-protocol/shared/codec/negotiation.d.ts +80 -0
  156. package/dist/internal/api-protocol/shared/codec/negotiation.d.ts.map +1 -0
  157. package/dist/internal/api-protocol/shared/codec/negotiation.js +129 -0
  158. package/dist/internal/api-protocol/shared/codec/negotiation.js.map +1 -0
  159. package/dist/internal/api-protocol/shared/codec/scale/adapter.d.ts +18 -0
  160. package/dist/internal/api-protocol/shared/codec/scale/adapter.d.ts.map +1 -0
  161. package/dist/internal/api-protocol/shared/codec/scale/adapter.js +23 -0
  162. package/dist/internal/api-protocol/shared/codec/scale/adapter.js.map +1 -0
  163. package/dist/internal/api-protocol/shared/codec/scale/primitives.d.ts +35 -0
  164. package/dist/internal/api-protocol/shared/codec/scale/primitives.d.ts.map +1 -0
  165. package/dist/internal/api-protocol/shared/codec/scale/primitives.js +96 -0
  166. package/dist/internal/api-protocol/shared/codec/scale/primitives.js.map +1 -0
  167. package/dist/internal/api-protocol/shared/codec/scale/v1/accounts.d.ts +65 -0
  168. package/dist/internal/api-protocol/shared/codec/scale/v1/accounts.d.ts.map +1 -0
  169. package/dist/internal/api-protocol/shared/codec/scale/v1/accounts.js +43 -0
  170. package/dist/internal/api-protocol/shared/codec/scale/v1/accounts.js.map +1 -0
  171. package/dist/internal/api-protocol/shared/codec/scale/v1/chainInteraction.d.ts +162 -0
  172. package/dist/internal/api-protocol/shared/codec/scale/v1/chainInteraction.d.ts.map +1 -0
  173. package/dist/internal/api-protocol/shared/codec/scale/v1/chainInteraction.js +81 -0
  174. package/dist/internal/api-protocol/shared/codec/scale/v1/chainInteraction.js.map +1 -0
  175. package/dist/internal/api-protocol/shared/codec/scale/v1/chat.d.ts +307 -0
  176. package/dist/internal/api-protocol/shared/codec/scale/v1/chat.d.ts.map +1 -0
  177. package/dist/internal/api-protocol/shared/codec/scale/v1/chat.js +105 -0
  178. package/dist/internal/api-protocol/shared/codec/scale/v1/chat.js.map +1 -0
  179. package/dist/internal/api-protocol/shared/codec/scale/v1/commonCodecs.d.ts +5 -0
  180. package/dist/internal/api-protocol/shared/codec/scale/v1/commonCodecs.d.ts.map +1 -0
  181. package/dist/internal/api-protocol/shared/codec/scale/v1/commonCodecs.js +6 -0
  182. package/dist/internal/api-protocol/shared/codec/scale/v1/commonCodecs.js.map +1 -0
  183. package/dist/internal/api-protocol/shared/codec/scale/v1/createTransaction.d.ts +71 -0
  184. package/dist/internal/api-protocol/shared/codec/scale/v1/createTransaction.d.ts.map +1 -0
  185. package/dist/internal/api-protocol/shared/codec/scale/v1/createTransaction.js +34 -0
  186. package/dist/internal/api-protocol/shared/codec/scale/v1/createTransaction.js.map +1 -0
  187. package/dist/internal/api-protocol/shared/codec/scale/v1/customRenderer.d.ts +106 -0
  188. package/dist/internal/api-protocol/shared/codec/scale/v1/customRenderer.d.ts.map +1 -0
  189. package/dist/internal/api-protocol/shared/codec/scale/v1/customRenderer.js +84 -0
  190. package/dist/internal/api-protocol/shared/codec/scale/v1/customRenderer.js.map +1 -0
  191. package/dist/internal/api-protocol/shared/codec/scale/v1/devicePermission.d.ts +4 -0
  192. package/dist/internal/api-protocol/shared/codec/scale/v1/devicePermission.d.ts.map +1 -0
  193. package/dist/internal/api-protocol/shared/codec/scale/v1/devicePermission.js +4 -0
  194. package/dist/internal/api-protocol/shared/codec/scale/v1/devicePermission.js.map +1 -0
  195. package/dist/internal/api-protocol/shared/codec/scale/v1/feature.d.ts +7 -0
  196. package/dist/internal/api-protocol/shared/codec/scale/v1/feature.d.ts.map +1 -0
  197. package/dist/internal/api-protocol/shared/codec/scale/v1/feature.js +7 -0
  198. package/dist/internal/api-protocol/shared/codec/scale/v1/feature.js.map +1 -0
  199. package/dist/internal/api-protocol/shared/codec/scale/v1/handshake.d.ts +13 -0
  200. package/dist/internal/api-protocol/shared/codec/scale/v1/handshake.d.ts.map +1 -0
  201. package/dist/internal/api-protocol/shared/codec/scale/v1/handshake.js +10 -0
  202. package/dist/internal/api-protocol/shared/codec/scale/v1/handshake.js.map +1 -0
  203. package/dist/internal/api-protocol/shared/codec/scale/v1/localStorage.d.ts +15 -0
  204. package/dist/internal/api-protocol/shared/codec/scale/v1/localStorage.d.ts.map +1 -0
  205. package/dist/internal/api-protocol/shared/codec/scale/v1/localStorage.js +12 -0
  206. package/dist/internal/api-protocol/shared/codec/scale/v1/localStorage.js.map +1 -0
  207. package/dist/internal/api-protocol/shared/codec/scale/v1/navigation.d.ts +10 -0
  208. package/dist/internal/api-protocol/shared/codec/scale/v1/navigation.d.ts.map +1 -0
  209. package/dist/internal/api-protocol/shared/codec/scale/v1/navigation.js +10 -0
  210. package/dist/internal/api-protocol/shared/codec/scale/v1/navigation.js.map +1 -0
  211. package/dist/internal/api-protocol/shared/codec/scale/v1/notification.d.ts +7 -0
  212. package/dist/internal/api-protocol/shared/codec/scale/v1/notification.d.ts.map +1 -0
  213. package/dist/internal/api-protocol/shared/codec/scale/v1/notification.js +7 -0
  214. package/dist/internal/api-protocol/shared/codec/scale/v1/notification.js.map +1 -0
  215. package/dist/internal/api-protocol/shared/codec/scale/v1/payment.d.ts +74 -0
  216. package/dist/internal/api-protocol/shared/codec/scale/v1/payment.d.ts.map +1 -0
  217. package/dist/internal/api-protocol/shared/codec/scale/v1/payment.js +38 -0
  218. package/dist/internal/api-protocol/shared/codec/scale/v1/payment.js.map +1 -0
  219. package/dist/internal/api-protocol/shared/codec/scale/v1/preimage.d.ts +12 -0
  220. package/dist/internal/api-protocol/shared/codec/scale/v1/preimage.d.ts.map +1 -0
  221. package/dist/internal/api-protocol/shared/codec/scale/v1/preimage.js +11 -0
  222. package/dist/internal/api-protocol/shared/codec/scale/v1/preimage.js.map +1 -0
  223. package/dist/internal/api-protocol/shared/codec/scale/v1/remotePermission.d.ts +10 -0
  224. package/dist/internal/api-protocol/shared/codec/scale/v1/remotePermission.d.ts.map +1 -0
  225. package/dist/internal/api-protocol/shared/codec/scale/v1/remotePermission.js +8 -0
  226. package/dist/internal/api-protocol/shared/codec/scale/v1/remotePermission.js.map +1 -0
  227. package/dist/internal/api-protocol/shared/codec/scale/v1/sign.d.ts +61 -0
  228. package/dist/internal/api-protocol/shared/codec/scale/v1/sign.d.ts.map +1 -0
  229. package/dist/internal/api-protocol/shared/codec/scale/v1/sign.js +42 -0
  230. package/dist/internal/api-protocol/shared/codec/scale/v1/sign.js.map +1 -0
  231. package/dist/internal/api-protocol/shared/codec/scale/v1/statementStore.d.ts +137 -0
  232. package/dist/internal/api-protocol/shared/codec/scale/v1/statementStore.d.ts.map +1 -0
  233. package/dist/internal/api-protocol/shared/codec/scale/v1/statementStore.js +55 -0
  234. package/dist/internal/api-protocol/shared/codec/scale/v1/statementStore.js.map +1 -0
  235. package/dist/internal/api-protocol/shared/codec/structured/index.d.ts +10 -0
  236. package/dist/internal/api-protocol/shared/codec/structured/index.d.ts.map +1 -0
  237. package/dist/internal/api-protocol/shared/codec/structured/index.js +19 -0
  238. package/dist/internal/api-protocol/shared/codec/structured/index.js.map +1 -0
  239. package/dist/internal/api-protocol/shared/transport/messagePortProvider.d.ts +18 -0
  240. package/dist/internal/api-protocol/shared/transport/messagePortProvider.d.ts.map +1 -0
  241. package/dist/internal/api-protocol/shared/transport/messagePortProvider.js +98 -0
  242. package/dist/internal/api-protocol/shared/transport/messagePortProvider.js.map +1 -0
  243. package/dist/internal/api-protocol/shared/transport/provider.d.ts +42 -0
  244. package/dist/internal/api-protocol/shared/transport/provider.d.ts.map +1 -0
  245. package/dist/internal/api-protocol/shared/transport/provider.js +13 -0
  246. package/dist/internal/api-protocol/shared/transport/provider.js.map +1 -0
  247. package/dist/internal/api-protocol/shared/transport/transport.d.ts +72 -0
  248. package/dist/internal/api-protocol/shared/transport/transport.d.ts.map +1 -0
  249. package/dist/internal/api-protocol/shared/transport/transport.js +420 -0
  250. package/dist/internal/api-protocol/shared/transport/transport.js.map +1 -0
  251. package/dist/internal/api-protocol/shared/transport/windowProvider.d.ts +13 -0
  252. package/dist/internal/api-protocol/shared/transport/windowProvider.d.ts.map +1 -0
  253. package/dist/internal/api-protocol/shared/transport/windowProvider.js +85 -0
  254. package/dist/internal/api-protocol/shared/transport/windowProvider.js.map +1 -0
  255. package/dist/internal/api-protocol/shared/util/helpers.d.ts +27 -0
  256. package/dist/internal/api-protocol/shared/util/helpers.d.ts.map +1 -0
  257. package/dist/internal/api-protocol/shared/util/helpers.js +43 -0
  258. package/dist/internal/api-protocol/shared/util/helpers.js.map +1 -0
  259. package/dist/internal/api-protocol/shared/util/idFactory.d.ts +9 -0
  260. package/dist/internal/api-protocol/shared/util/idFactory.d.ts.map +1 -0
  261. package/dist/internal/api-protocol/shared/util/idFactory.js +12 -0
  262. package/dist/internal/api-protocol/shared/util/idFactory.js.map +1 -0
  263. package/dist/internal/api-protocol/shared/util/logger.d.ts +15 -0
  264. package/dist/internal/api-protocol/shared/util/logger.d.ts.map +1 -0
  265. package/dist/internal/api-protocol/shared/util/logger.js +20 -0
  266. package/dist/internal/api-protocol/shared/util/logger.js.map +1 -0
  267. package/dist/mesh-attachment.d.ts +19 -0
  268. package/dist/mesh-attachment.d.ts.map +1 -0
  269. package/dist/mesh-attachment.js +43 -0
  270. package/dist/mesh-attachment.js.map +1 -0
  271. package/dist/mesh-chat.d.ts +48 -0
  272. package/dist/mesh-chat.d.ts.map +1 -0
  273. package/dist/mesh-chat.js +84 -0
  274. package/dist/mesh-chat.js.map +1 -0
  275. package/dist/mesh-delivery-diagnostics.d.ts +12 -0
  276. package/dist/mesh-delivery-diagnostics.d.ts.map +1 -0
  277. package/dist/mesh-delivery-diagnostics.js +45 -0
  278. package/dist/mesh-delivery-diagnostics.js.map +1 -0
  279. package/dist/mesh-notification.d.ts +29 -0
  280. package/dist/mesh-notification.d.ts.map +1 -0
  281. package/dist/mesh-notification.js +52 -0
  282. package/dist/mesh-notification.js.map +1 -0
  283. package/dist/mesh-pairing.d.ts +40 -0
  284. package/dist/mesh-pairing.d.ts.map +1 -0
  285. package/dist/mesh-pairing.js +78 -0
  286. package/dist/mesh-pairing.js.map +1 -0
  287. package/dist/product-host-runtime.d.ts +59 -0
  288. package/dist/product-host-runtime.d.ts.map +1 -0
  289. package/dist/product-host-runtime.js +150 -0
  290. package/dist/product-host-runtime.js.map +1 -0
  291. package/dist/product-protocol.d.ts +49 -0
  292. package/dist/product-protocol.d.ts.map +1 -0
  293. package/dist/product-protocol.js +389 -0
  294. package/dist/product-protocol.js.map +1 -0
  295. package/dist/product-view-hosted.d.ts +63 -0
  296. package/dist/product-view-hosted.d.ts.map +1 -0
  297. package/dist/product-view-hosted.js +272 -0
  298. package/dist/product-view-hosted.js.map +1 -0
  299. package/dist/product-view-service-worker.d.ts +6 -0
  300. package/dist/product-view-service-worker.d.ts.map +1 -0
  301. package/dist/product-view-service-worker.js +57 -0
  302. package/dist/product-view-service-worker.js.map +1 -0
  303. package/dist/product-view.d.ts +459 -0
  304. package/dist/product-view.d.ts.map +1 -0
  305. package/dist/product-view.js +2671 -0
  306. package/dist/product-view.js.map +1 -0
  307. package/dist/protocol.d.ts +39 -0
  308. package/dist/protocol.d.ts.map +1 -0
  309. package/dist/protocol.js +25 -0
  310. package/dist/protocol.js.map +1 -0
  311. package/dist/remote-runtime-provider.d.ts +9 -0
  312. package/dist/remote-runtime-provider.d.ts.map +1 -0
  313. package/dist/remote-runtime-provider.js +1002 -0
  314. package/dist/remote-runtime-provider.js.map +1 -0
  315. package/dist/runtime-chain-service.d.ts +109 -0
  316. package/dist/runtime-chain-service.d.ts.map +1 -0
  317. package/dist/runtime-chain-service.js +846 -0
  318. package/dist/runtime-chain-service.js.map +1 -0
  319. package/dist/runtime-chain.d.ts +8 -0
  320. package/dist/runtime-chain.d.ts.map +1 -0
  321. package/dist/runtime-chain.js +4 -0
  322. package/dist/runtime-chain.js.map +1 -0
  323. package/dist/runtime-storage-access.d.ts +39 -0
  324. package/dist/runtime-storage-access.d.ts.map +1 -0
  325. package/dist/runtime-storage-access.js +209 -0
  326. package/dist/runtime-storage-access.js.map +1 -0
  327. package/dist/scoped-frame.d.ts +55 -0
  328. package/dist/scoped-frame.d.ts.map +1 -0
  329. package/dist/scoped-frame.js +234 -0
  330. package/dist/scoped-frame.js.map +1 -0
  331. package/dist/sdk-interfaces.d.ts +159 -0
  332. package/dist/sdk-interfaces.d.ts.map +1 -0
  333. package/dist/sdk-interfaces.js +2 -0
  334. package/dist/sdk-interfaces.js.map +1 -0
  335. package/dist/statement-store.d.ts +166 -0
  336. package/dist/statement-store.d.ts.map +1 -0
  337. package/dist/statement-store.js +627 -0
  338. package/dist/statement-store.js.map +1 -0
  339. package/dist/telemetry.d.ts +218 -0
  340. package/dist/telemetry.d.ts.map +1 -0
  341. package/dist/telemetry.js +162 -0
  342. package/dist/telemetry.js.map +1 -0
  343. package/dist/types.d.ts +255 -0
  344. package/dist/types.d.ts.map +1 -0
  345. package/dist/types.js +77 -0
  346. package/dist/types.js.map +1 -0
  347. package/dist/wallet-session.d.ts +89 -0
  348. package/dist/wallet-session.d.ts.map +1 -0
  349. package/dist/wallet-session.js +135 -0
  350. package/dist/wallet-session.js.map +1 -0
  351. package/package.json +86 -5
  352. package/index.js +0 -1
@@ -0,0 +1,881 @@
1
+ import { HostRuntime } from "./host-runtime.js";
2
+ import { defaultHostRuntimeRegistry, } from "./host-runtime-registry.js";
3
+ import { installScopedFrame, mountScopedFrame, } from "./scoped-frame.js";
4
+ import { isHostRuntimePortMethodName, } from "./host-runtime-contract.js";
5
+ const HOST_RUNTIME_FRAME_INIT = "host-runtime-frame:init";
6
+ const HOST_RUNTIME_FRAME_READY = "host-runtime-frame:ready";
7
+ const HOST_RUNTIME_FRAME_SOURCE = "host-sdk-frame";
8
+ const HOST_RUNTIME_FRAME_SERVICE_IDS = ["runtime"];
9
+ function startPort(port) {
10
+ port.start?.();
11
+ }
12
+ function closePort(port) {
13
+ port.close?.();
14
+ }
15
+ function toErrorMessage(error) {
16
+ if (error instanceof Error) {
17
+ return error.message;
18
+ }
19
+ return String(error);
20
+ }
21
+ class PortRemoteHostRuntime {
22
+ constructor(port, hasChainService = false) {
23
+ this.port = port;
24
+ this.nextId = 1;
25
+ this.pending = new Map();
26
+ this.sessions = new Map();
27
+ this.chainSubscriptions = new Map();
28
+ this.pendingChainEvents = new Map();
29
+ this.destroyed = false;
30
+ this.chainService = hasChainService ? new PortRemoteRuntimeChainService(this) : null;
31
+ startPort(port);
32
+ port.onmessage = (event) => {
33
+ const message = event.data;
34
+ if (typeof message !== "object" || message == null) {
35
+ return;
36
+ }
37
+ if ("id" in message) {
38
+ const pending = this.pending.get(message.id);
39
+ if (pending == null) {
40
+ return;
41
+ }
42
+ this.pending.delete(message.id);
43
+ if (message.ok) {
44
+ pending.resolve(message.result);
45
+ }
46
+ else {
47
+ pending.reject(new Error(message.error));
48
+ }
49
+ return;
50
+ }
51
+ if (message.type === "chain.subscriptionMessage") {
52
+ const callbacks = this.chainSubscriptions.get(message.subscriptionId);
53
+ if (callbacks != null) {
54
+ callbacks.onMessage(message.jsonRpcMessage);
55
+ }
56
+ else {
57
+ const pending = this.pendingChainEvents.get(message.subscriptionId) ?? [];
58
+ pending.push(message);
59
+ this.pendingChainEvents.set(message.subscriptionId, pending);
60
+ }
61
+ }
62
+ else if (message.type === "chain.subscriptionAbort") {
63
+ const callbacks = this.chainSubscriptions.get(message.subscriptionId);
64
+ if (callbacks) {
65
+ callbacks.onAbort(message.reason);
66
+ this.chainSubscriptions.delete(message.subscriptionId);
67
+ }
68
+ else {
69
+ const pending = this.pendingChainEvents.get(message.subscriptionId) ?? [];
70
+ pending.push(message);
71
+ this.pendingChainEvents.set(message.subscriptionId, pending);
72
+ }
73
+ }
74
+ };
75
+ }
76
+ async setAccounts(accounts) {
77
+ await this.call({ method: "setAccounts", accounts });
78
+ }
79
+ async clearAccounts() {
80
+ await this.call({ method: "clearAccounts" });
81
+ }
82
+ async setSupportedChains(chains) {
83
+ await this.call({ method: "setSupportedChains", chains });
84
+ }
85
+ session(productId) {
86
+ let session = this.sessions.get(productId);
87
+ if (session == null) {
88
+ session = new PortRemoteHostRuntimeSession(this, productId);
89
+ this.sessions.set(productId, session);
90
+ }
91
+ return session;
92
+ }
93
+ async destroySession(productId) {
94
+ this.sessions.delete(productId);
95
+ await this.call({ method: "destroySession", productId });
96
+ }
97
+ async reset() {
98
+ this.sessions.clear();
99
+ await this.call({ method: "resetRuntime" });
100
+ }
101
+ destroy() {
102
+ if (this.destroyed) {
103
+ return;
104
+ }
105
+ this.destroyed = true;
106
+ for (const pending of this.pending.values()) {
107
+ pending.reject(new Error("Host runtime port closed"));
108
+ }
109
+ this.pending.clear();
110
+ this.sessions.clear();
111
+ for (const [subscriptionId, callbacks] of this.chainSubscriptions) {
112
+ callbacks.onAbort("Host runtime port closed");
113
+ this.chainSubscriptions.delete(subscriptionId);
114
+ }
115
+ this.port.onmessage = null;
116
+ closePort(this.port);
117
+ }
118
+ call(request) {
119
+ if (this.destroyed) {
120
+ return Promise.reject(new Error("Host runtime port closed"));
121
+ }
122
+ const id = this.nextId++;
123
+ return new Promise((resolve, reject) => {
124
+ this.pending.set(id, { resolve, reject });
125
+ this.port.postMessage({ id, ...request });
126
+ });
127
+ }
128
+ setChainSubscription(subscriptionId, callbacks) {
129
+ this.chainSubscriptions.set(subscriptionId, callbacks);
130
+ const pending = this.pendingChainEvents.get(subscriptionId);
131
+ if (pending == null) {
132
+ return;
133
+ }
134
+ this.pendingChainEvents.delete(subscriptionId);
135
+ for (const event of pending) {
136
+ if (event.type === "chain.subscriptionMessage") {
137
+ callbacks.onMessage(event.jsonRpcMessage);
138
+ }
139
+ else {
140
+ callbacks.onAbort(event.reason);
141
+ this.chainSubscriptions.delete(subscriptionId);
142
+ break;
143
+ }
144
+ }
145
+ }
146
+ clearChainSubscription(subscriptionId) {
147
+ this.chainSubscriptions.delete(subscriptionId);
148
+ this.pendingChainEvents.delete(subscriptionId);
149
+ }
150
+ }
151
+ class PortRemoteRuntimeChainService {
152
+ constructor(runtime) {
153
+ this.runtime = runtime;
154
+ }
155
+ async statuses() {
156
+ return this.runtime.call({ method: "chain.statuses" });
157
+ }
158
+ async connect(chainName) {
159
+ await this.runtime.call({ method: "chain.connect", chainName });
160
+ }
161
+ async disconnect(chainName) {
162
+ await this.runtime.call({ method: "chain.disconnect", chainName });
163
+ }
164
+ async refreshRouting(chainNames) {
165
+ const entries = (await this.runtime.call({
166
+ method: "chain.refreshRouting",
167
+ chainNames,
168
+ }));
169
+ return new Map(entries);
170
+ }
171
+ async routingTable() {
172
+ const entries = (await this.runtime.call({ method: "chain.routingTable" }));
173
+ return new Map(entries);
174
+ }
175
+ async supportedGenesisHashes() {
176
+ return this.runtime.call({ method: "chain.supportedGenesisHashes" });
177
+ }
178
+ async routeChainByGenesisHash(genesisHash) {
179
+ return this.runtime.call({
180
+ method: "chain.routeChainByGenesisHash",
181
+ genesisHash,
182
+ });
183
+ }
184
+ async sendRpc(chainName, method, paramsJson) {
185
+ return this.runtime.call({
186
+ method: "chain.sendRpc",
187
+ chainName,
188
+ jsonRpcMethod: method,
189
+ paramsJson,
190
+ });
191
+ }
192
+ async startSubscription(chainName, method, paramsJson, onMessage, onAbort) {
193
+ const { subscriptionId } = (await this.runtime.call({
194
+ method: "chain.startSubscription",
195
+ chainName,
196
+ jsonRpcMethod: method,
197
+ paramsJson,
198
+ }));
199
+ this.runtime.setChainSubscription(subscriptionId, { onMessage, onAbort });
200
+ return async () => {
201
+ this.runtime.clearChainSubscription(subscriptionId);
202
+ await this.runtime.call({ method: "chain.stopSubscription", subscriptionId });
203
+ };
204
+ }
205
+ async destroy() {
206
+ await this.runtime.call({ method: "chain.stopAllSubscriptions" });
207
+ }
208
+ }
209
+ class PortRemoteHostRuntimeSession {
210
+ constructor(runtime, productId) {
211
+ this.runtime = runtime;
212
+ this.productId = productId;
213
+ }
214
+ async handleMessage(raw) {
215
+ return this.runtime.call({
216
+ method: "session.handleMessage",
217
+ productId: this.productId,
218
+ raw,
219
+ });
220
+ }
221
+ async reset() {
222
+ await this.runtime.call({ method: "session.reset", productId: this.productId });
223
+ }
224
+ async forgetRequest(requestId) {
225
+ await this.runtime.call({
226
+ method: "session.forgetRequest",
227
+ productId: this.productId,
228
+ requestId,
229
+ });
230
+ }
231
+ async isFollowRequest(requestId) {
232
+ return this.runtime.call({
233
+ method: "session.isFollowRequest",
234
+ productId: this.productId,
235
+ requestId,
236
+ });
237
+ }
238
+ async encodeSignResponse(requestId, requestTag, signature) {
239
+ return this.runtime.call({
240
+ method: "session.encodeSignResponse",
241
+ productId: this.productId,
242
+ requestId,
243
+ requestTag,
244
+ signature,
245
+ });
246
+ }
247
+ async encodeSignError(requestId, requestTag) {
248
+ return this.runtime.call({
249
+ method: "session.encodeSignError",
250
+ productId: this.productId,
251
+ requestId,
252
+ requestTag,
253
+ });
254
+ }
255
+ async encodeAccountGetResponse(requestId, publicKey, name) {
256
+ return this.runtime.call({
257
+ method: "session.encodeAccountGetResponse",
258
+ productId: this.productId,
259
+ requestId,
260
+ publicKey,
261
+ name,
262
+ });
263
+ }
264
+ async encodeAccountGetError(requestId, errorKind, reason) {
265
+ return this.runtime.call({
266
+ method: "session.encodeAccountGetError",
267
+ productId: this.productId,
268
+ requestId,
269
+ errorKind,
270
+ reason,
271
+ });
272
+ }
273
+ async encodeAccountGetAliasResponse(requestId, context, alias) {
274
+ return this.runtime.call({
275
+ method: "session.encodeAccountGetAliasResponse",
276
+ productId: this.productId,
277
+ requestId,
278
+ context,
279
+ alias,
280
+ });
281
+ }
282
+ async encodeAccountGetAliasError(requestId, errorKind, reason) {
283
+ return this.runtime.call({
284
+ method: "session.encodeAccountGetAliasError",
285
+ productId: this.productId,
286
+ requestId,
287
+ errorKind,
288
+ reason,
289
+ });
290
+ }
291
+ async encodeAccountCreateProofResponse(requestId, proof) {
292
+ return this.runtime.call({
293
+ method: "session.encodeAccountCreateProofResponse",
294
+ productId: this.productId,
295
+ requestId,
296
+ proof,
297
+ });
298
+ }
299
+ async encodeAccountCreateProofError(requestId, errorKind, reason) {
300
+ return this.runtime.call({
301
+ method: "session.encodeAccountCreateProofError",
302
+ productId: this.productId,
303
+ requestId,
304
+ errorKind,
305
+ reason,
306
+ });
307
+ }
308
+ async encodeDevicePermissionResponse(requestId, granted) {
309
+ return this.runtime.call({
310
+ method: "session.encodeDevicePermissionResponse",
311
+ productId: this.productId,
312
+ requestId,
313
+ granted,
314
+ });
315
+ }
316
+ async encodeDevicePermissionError(requestId) {
317
+ return this.runtime.call({
318
+ method: "session.encodeDevicePermissionError",
319
+ productId: this.productId,
320
+ requestId,
321
+ });
322
+ }
323
+ async encodeRemotePermissionResponse(requestId, granted) {
324
+ return this.runtime.call({
325
+ method: "session.encodeRemotePermissionResponse",
326
+ productId: this.productId,
327
+ requestId,
328
+ granted,
329
+ });
330
+ }
331
+ async encodeRemotePermissionError(requestId) {
332
+ return this.runtime.call({
333
+ method: "session.encodeRemotePermissionError",
334
+ productId: this.productId,
335
+ requestId,
336
+ });
337
+ }
338
+ async encodeCreateTransactionResponse(requestId, signedTxBytes) {
339
+ return this.runtime.call({
340
+ method: "session.encodeCreateTransactionResponse",
341
+ productId: this.productId,
342
+ requestId,
343
+ signedTxBytes,
344
+ });
345
+ }
346
+ async encodeCreateTransactionError(requestId) {
347
+ return this.runtime.call({
348
+ method: "session.encodeCreateTransactionError",
349
+ productId: this.productId,
350
+ requestId,
351
+ });
352
+ }
353
+ async encodeCreateTxNonProductResponse(requestId, signedTxBytes) {
354
+ return this.runtime.call({
355
+ method: "session.encodeCreateTxNonProductResponse",
356
+ productId: this.productId,
357
+ requestId,
358
+ signedTxBytes,
359
+ });
360
+ }
361
+ async encodeCreateTxNonProductError(requestId) {
362
+ return this.runtime.call({
363
+ method: "session.encodeCreateTxNonProductError",
364
+ productId: this.productId,
365
+ requestId,
366
+ });
367
+ }
368
+ async encodePaymentBalance(requestId, balance) {
369
+ return this.runtime.call({
370
+ method: "session.encodePaymentBalance",
371
+ productId: this.productId,
372
+ requestId,
373
+ balance,
374
+ });
375
+ }
376
+ async encodePaymentBalanceInterrupt(requestId) {
377
+ return this.runtime.call({
378
+ method: "session.encodePaymentBalanceInterrupt",
379
+ productId: this.productId,
380
+ requestId,
381
+ });
382
+ }
383
+ async encodePaymentTopUpResponse(requestId) {
384
+ return this.runtime.call({
385
+ method: "session.encodePaymentTopUpResponse",
386
+ productId: this.productId,
387
+ requestId,
388
+ });
389
+ }
390
+ async encodePaymentTopUpError(requestId, reason) {
391
+ return this.runtime.call({
392
+ method: "session.encodePaymentTopUpError",
393
+ productId: this.productId,
394
+ requestId,
395
+ reason,
396
+ });
397
+ }
398
+ async encodePaymentRequestResponse(requestId, receiptId) {
399
+ return this.runtime.call({
400
+ method: "session.encodePaymentRequestResponse",
401
+ productId: this.productId,
402
+ requestId,
403
+ receiptId,
404
+ });
405
+ }
406
+ async encodePaymentRequestError(requestId, reason) {
407
+ return this.runtime.call({
408
+ method: "session.encodePaymentRequestError",
409
+ productId: this.productId,
410
+ requestId,
411
+ reason,
412
+ });
413
+ }
414
+ async encodePaymentStatus(requestId, status) {
415
+ return this.runtime.call({
416
+ method: "session.encodePaymentStatus",
417
+ productId: this.productId,
418
+ requestId,
419
+ status,
420
+ });
421
+ }
422
+ async encodePaymentStatusInterrupt(requestId) {
423
+ return this.runtime.call({
424
+ method: "session.encodePaymentStatusInterrupt",
425
+ productId: this.productId,
426
+ requestId,
427
+ });
428
+ }
429
+ async encodeChainQueryResponse(requestId, jsonRpcResult) {
430
+ return this.runtime.call({
431
+ method: "session.encodeChainQueryResponse",
432
+ productId: this.productId,
433
+ requestId,
434
+ jsonRpcResult,
435
+ });
436
+ }
437
+ async encodeChainQueryError(requestId) {
438
+ return this.runtime.call({
439
+ method: "session.encodeChainQueryError",
440
+ productId: this.productId,
441
+ requestId,
442
+ });
443
+ }
444
+ async encodeChainRpcResponse(requestId, requestTag, jsonRpcMessage) {
445
+ return this.runtime.call({
446
+ method: "session.encodeChainRpcResponse",
447
+ productId: this.productId,
448
+ requestId,
449
+ requestTag,
450
+ jsonRpcMessage,
451
+ });
452
+ }
453
+ async encodeChainRpcError(requestId, requestTag, reason) {
454
+ return this.runtime.call({
455
+ method: "session.encodeChainRpcError",
456
+ productId: this.productId,
457
+ requestId,
458
+ requestTag,
459
+ reason,
460
+ });
461
+ }
462
+ async encodeNavigateResponse(requestId) {
463
+ return this.runtime.call({
464
+ method: "session.encodeNavigateResponse",
465
+ productId: this.productId,
466
+ requestId,
467
+ });
468
+ }
469
+ async encodePushNotificationResponse(requestId) {
470
+ return this.runtime.call({
471
+ method: "session.encodePushNotificationResponse",
472
+ productId: this.productId,
473
+ requestId,
474
+ });
475
+ }
476
+ async encodeChainFollowStop(requestId) {
477
+ return this.runtime.call({
478
+ method: "session.encodeChainFollowStop",
479
+ productId: this.productId,
480
+ requestId,
481
+ });
482
+ }
483
+ async encodeChainNotification(requestId, jsonRpcMessage) {
484
+ return this.runtime.call({
485
+ method: "session.encodeChainNotification",
486
+ productId: this.productId,
487
+ requestId,
488
+ jsonRpcMessage,
489
+ });
490
+ }
491
+ async encodeStorageReadResponse(requestId, value) {
492
+ return this.runtime.call({
493
+ method: "session.encodeStorageReadResponse",
494
+ productId: this.productId,
495
+ requestId,
496
+ value,
497
+ });
498
+ }
499
+ async encodeStorageWriteResponse(requestId) {
500
+ return this.runtime.call({
501
+ method: "session.encodeStorageWriteResponse",
502
+ productId: this.productId,
503
+ requestId,
504
+ });
505
+ }
506
+ async encodeStorageClearResponse(requestId) {
507
+ return this.runtime.call({
508
+ method: "session.encodeStorageClearResponse",
509
+ productId: this.productId,
510
+ requestId,
511
+ });
512
+ }
513
+ }
514
+ async function dispatchRuntimeRequest(runtime, chainService, request, subscriptionState, port) {
515
+ switch (request.method) {
516
+ case "setAccounts":
517
+ runtime.setAccounts(request.accounts);
518
+ return undefined;
519
+ case "clearAccounts":
520
+ runtime.clearAccounts();
521
+ return undefined;
522
+ case "setSupportedChains":
523
+ runtime.setSupportedChains(request.chains);
524
+ return undefined;
525
+ case "destroySession":
526
+ runtime.destroySession(request.productId);
527
+ return undefined;
528
+ case "resetRuntime":
529
+ runtime.reset();
530
+ return undefined;
531
+ case "chain.statuses":
532
+ return chainService?.statuses() ?? [];
533
+ case "chain.connect":
534
+ if (chainService == null)
535
+ throw new Error("Runtime chain service unavailable");
536
+ await chainService.connect(request.chainName);
537
+ return undefined;
538
+ case "chain.disconnect":
539
+ if (chainService == null)
540
+ throw new Error("Runtime chain service unavailable");
541
+ chainService.disconnect(request.chainName);
542
+ return undefined;
543
+ case "chain.refreshRouting":
544
+ if (chainService == null)
545
+ throw new Error("Runtime chain service unavailable");
546
+ return [...(await chainService.refreshRouting(request.chainNames)).entries()];
547
+ case "chain.routingTable":
548
+ if (chainService == null)
549
+ throw new Error("Runtime chain service unavailable");
550
+ return [...chainService.routingTable().entries()];
551
+ case "chain.supportedGenesisHashes":
552
+ if (chainService == null)
553
+ throw new Error("Runtime chain service unavailable");
554
+ return chainService.supportedGenesisHashes();
555
+ case "chain.routeChainByGenesisHash":
556
+ if (chainService == null)
557
+ throw new Error("Runtime chain service unavailable");
558
+ return chainService.routeChainByGenesisHash(request.genesisHash);
559
+ case "chain.sendRpc":
560
+ if (chainService == null)
561
+ throw new Error("Runtime chain service unavailable");
562
+ return chainService.sendRpc(request.chainName, request.jsonRpcMethod, request.paramsJson);
563
+ case "chain.startSubscription": {
564
+ if (chainService == null)
565
+ throw new Error("Runtime chain service unavailable");
566
+ const subscriptionId = subscriptionState.allocateChainSubscriptionId();
567
+ console.info(`[runtime-frame] start subscription ${request.chainName} ${request.jsonRpcMethod} local=${subscriptionId}`);
568
+ const queuedEvents = [];
569
+ let responsePosted = false;
570
+ const sendChainEvent = (message) => {
571
+ if (responsePosted) {
572
+ console.info(`[runtime-frame] forwarding subscription event local=${subscriptionId} type=${message.type}`);
573
+ port.postMessage(message);
574
+ }
575
+ else {
576
+ console.info(`[runtime-frame] queueing subscription event local=${subscriptionId} type=${message.type}`);
577
+ queuedEvents.push(message);
578
+ }
579
+ };
580
+ const stop = chainService.startSubscription(request.chainName, request.jsonRpcMethod, request.paramsJson, (jsonRpcMessage) => {
581
+ sendChainEvent({
582
+ type: "chain.subscriptionMessage",
583
+ subscriptionId,
584
+ jsonRpcMessage,
585
+ });
586
+ }, (reason) => {
587
+ sendChainEvent({
588
+ type: "chain.subscriptionAbort",
589
+ subscriptionId,
590
+ reason,
591
+ });
592
+ subscriptionState.stopChainSubscription(subscriptionId);
593
+ });
594
+ subscriptionState.stopChainSubscription(subscriptionId);
595
+ subscriptionState.setChainSubscriptionStop(subscriptionId, stop);
596
+ return {
597
+ subscriptionId,
598
+ __queuedChainEvents: queuedEvents,
599
+ __markResponsePosted() {
600
+ console.info(`[runtime-frame] subscription response posted local=${subscriptionId} queued=${queuedEvents.length}`);
601
+ responsePosted = true;
602
+ },
603
+ };
604
+ }
605
+ case "chain.stopSubscription":
606
+ subscriptionState.stopChainSubscription(request.subscriptionId);
607
+ return undefined;
608
+ case "chain.stopAllSubscriptions":
609
+ subscriptionState.stopAllChainSubscriptions();
610
+ return undefined;
611
+ default:
612
+ return dispatchSessionRequest(runtime.session(request.productId), request);
613
+ }
614
+ }
615
+ function dispatchSessionRequest(session, request) {
616
+ switch (request.method) {
617
+ case "session.handleMessage":
618
+ return session.handleMessage(request.raw);
619
+ case "session.reset":
620
+ session.reset();
621
+ return undefined;
622
+ case "session.forgetRequest":
623
+ session.forgetRequest(request.requestId);
624
+ return undefined;
625
+ case "session.isFollowRequest":
626
+ return session.isFollowRequest(request.requestId);
627
+ case "session.encodeSignResponse":
628
+ return session.encodeSignResponse(request.requestId, request.requestTag, request.signature);
629
+ case "session.encodeSignError":
630
+ return session.encodeSignError(request.requestId, request.requestTag);
631
+ case "session.encodeAccountGetResponse":
632
+ return session.encodeAccountGetResponse(request.requestId, request.publicKey, request.name);
633
+ case "session.encodeAccountGetError":
634
+ return session.encodeAccountGetError(request.requestId, request.errorKind, request.reason);
635
+ case "session.encodeAccountGetAliasResponse":
636
+ return session.encodeAccountGetAliasResponse(request.requestId, request.context, request.alias);
637
+ case "session.encodeAccountGetAliasError":
638
+ return session.encodeAccountGetAliasError(request.requestId, request.errorKind, request.reason);
639
+ case "session.encodeAccountCreateProofResponse":
640
+ return session.encodeAccountCreateProofResponse(request.requestId, request.proof);
641
+ case "session.encodeAccountCreateProofError":
642
+ return session.encodeAccountCreateProofError(request.requestId, request.errorKind, request.reason);
643
+ case "session.encodeDevicePermissionResponse":
644
+ return session.encodeDevicePermissionResponse(request.requestId, request.granted);
645
+ case "session.encodeDevicePermissionError":
646
+ return session.encodeDevicePermissionError(request.requestId);
647
+ case "session.encodeRemotePermissionResponse":
648
+ return session.encodeRemotePermissionResponse(request.requestId, request.granted);
649
+ case "session.encodeRemotePermissionError":
650
+ return session.encodeRemotePermissionError(request.requestId);
651
+ case "session.encodeCreateTransactionResponse":
652
+ return session.encodeCreateTransactionResponse(request.requestId, request.signedTxBytes);
653
+ case "session.encodeCreateTransactionError":
654
+ return session.encodeCreateTransactionError(request.requestId);
655
+ case "session.encodeCreateTxNonProductResponse":
656
+ return session.encodeCreateTxNonProductResponse(request.requestId, request.signedTxBytes);
657
+ case "session.encodeCreateTxNonProductError":
658
+ return session.encodeCreateTxNonProductError(request.requestId);
659
+ case "session.encodePaymentBalance":
660
+ return session.encodePaymentBalance(request.requestId, request.balance);
661
+ case "session.encodePaymentBalanceInterrupt":
662
+ return session.encodePaymentBalanceInterrupt(request.requestId);
663
+ case "session.encodePaymentTopUpResponse":
664
+ return session.encodePaymentTopUpResponse(request.requestId);
665
+ case "session.encodePaymentTopUpError":
666
+ return session.encodePaymentTopUpError(request.requestId, request.reason);
667
+ case "session.encodePaymentRequestResponse":
668
+ return session.encodePaymentRequestResponse(request.requestId, request.receiptId);
669
+ case "session.encodePaymentRequestError":
670
+ return session.encodePaymentRequestError(request.requestId, request.reason);
671
+ case "session.encodePaymentStatus":
672
+ return session.encodePaymentStatus(request.requestId, request.status);
673
+ case "session.encodePaymentStatusInterrupt":
674
+ return session.encodePaymentStatusInterrupt(request.requestId);
675
+ case "session.encodeChainQueryResponse":
676
+ return session.encodeChainQueryResponse(request.requestId, request.jsonRpcResult);
677
+ case "session.encodeChainQueryError":
678
+ return session.encodeChainQueryError(request.requestId);
679
+ case "session.encodeChainRpcResponse":
680
+ return session.encodeChainRpcResponse(request.requestId, request.requestTag, request.jsonRpcMessage);
681
+ case "session.encodeChainRpcError":
682
+ return session.encodeChainRpcError(request.requestId, request.requestTag, request.reason);
683
+ case "session.encodeNavigateResponse":
684
+ return session.encodeNavigateResponse(request.requestId);
685
+ case "session.encodePushNotificationResponse":
686
+ return session.encodePushNotificationResponse(request.requestId);
687
+ case "session.encodeChainFollowStop":
688
+ return session.encodeChainFollowStop(request.requestId);
689
+ case "session.encodeChainNotification":
690
+ return session.encodeChainNotification(request.requestId, request.jsonRpcMessage);
691
+ case "session.encodeStorageReadResponse":
692
+ return session.encodeStorageReadResponse(request.requestId, request.value);
693
+ case "session.encodeStorageWriteResponse":
694
+ return session.encodeStorageWriteResponse(request.requestId);
695
+ case "session.encodeStorageClearResponse":
696
+ return session.encodeStorageClearResponse(request.requestId);
697
+ }
698
+ }
699
+ /**
700
+ * Serve a HostRuntime over a MessagePort-compatible transport.
701
+ *
702
+ * This is the runtime-frame side of the common-origin iframe pattern.
703
+ */
704
+ export function serveHostRuntimePort(port, runtime, chainService = null) {
705
+ const subscriptionStops = new Map();
706
+ let nextChainSubscriptionId = 1;
707
+ const stopChainSubscription = (subscriptionId) => {
708
+ const stop = subscriptionStops.get(subscriptionId);
709
+ if (stop) {
710
+ subscriptionStops.delete(subscriptionId);
711
+ stop();
712
+ }
713
+ };
714
+ const stopAllChainSubscriptions = () => {
715
+ for (const subscriptionId of [...subscriptionStops.keys()]) {
716
+ stopChainSubscription(subscriptionId);
717
+ }
718
+ };
719
+ startPort(port);
720
+ port.onmessage = async (event) => {
721
+ const request = event.data;
722
+ if (typeof request !== "object" ||
723
+ request == null ||
724
+ !("id" in request) ||
725
+ !("method" in request) ||
726
+ typeof request.method !== "string" ||
727
+ !isHostRuntimePortMethodName(request.method)) {
728
+ return;
729
+ }
730
+ try {
731
+ const result = await dispatchRuntimeRequest(runtime, chainService, request, {
732
+ allocateChainSubscriptionId() {
733
+ const subscriptionId = nextChainSubscriptionId;
734
+ nextChainSubscriptionId += 1;
735
+ return subscriptionId;
736
+ },
737
+ setChainSubscriptionStop(subscriptionId, stop) {
738
+ subscriptionStops.set(subscriptionId, stop);
739
+ },
740
+ stopChainSubscription,
741
+ stopAllChainSubscriptions,
742
+ }, port);
743
+ if (typeof result === "object" &&
744
+ result != null &&
745
+ "__queuedChainEvents" in result &&
746
+ "__markResponsePosted" in result) {
747
+ const queuedResult = result;
748
+ console.info(`[runtime-frame] returning subscription handle local=${queuedResult.subscriptionId} queued=${queuedResult.__queuedChainEvents.length}`);
749
+ port.postMessage({
750
+ id: request.id,
751
+ ok: true,
752
+ result: { subscriptionId: queuedResult.subscriptionId },
753
+ });
754
+ queuedResult.__markResponsePosted();
755
+ for (const queuedEvent of queuedResult.__queuedChainEvents) {
756
+ port.postMessage(queuedEvent);
757
+ }
758
+ }
759
+ else {
760
+ port.postMessage({ id: request.id, ok: true, result });
761
+ }
762
+ }
763
+ catch (error) {
764
+ port.postMessage({
765
+ id: request.id,
766
+ ok: false,
767
+ error: toErrorMessage(error),
768
+ });
769
+ }
770
+ };
771
+ return () => {
772
+ stopAllChainSubscriptions();
773
+ port.onmessage = null;
774
+ closePort(port);
775
+ };
776
+ }
777
+ /**
778
+ * Connect to a HostRuntime that is already exposed over a MessagePort.
779
+ */
780
+ export function connectHostRuntimePort(port) {
781
+ return new PortRemoteHostRuntime(port);
782
+ }
783
+ export function connectHostRuntimeFramePort(port, hasChainService) {
784
+ const remote = new PortRemoteHostRuntime(port, hasChainService);
785
+ return {
786
+ runtime: remote,
787
+ chainService: remote.chainService,
788
+ };
789
+ }
790
+ /**
791
+ * Install the runtime-frame server inside a trusted common-origin iframe page.
792
+ *
793
+ * The host page should create the iframe, then call `mountHostRuntimeFrame()`
794
+ * to transfer a MessagePort into it. Instantiate host-owned browser services
795
+ * like SmoldotDriver in this page to keep cache/storage scoped to the shared
796
+ * runtime origin.
797
+ */
798
+ export function installHostRuntimeFrame(options) {
799
+ const registry = options.registry ?? defaultHostRuntimeRegistry;
800
+ const scopeId = options.scopeId ?? "default";
801
+ let lease = null;
802
+ let chainService = null;
803
+ return installScopedFrame({
804
+ source: HOST_RUNTIME_FRAME_SOURCE,
805
+ initType: HOST_RUNTIME_FRAME_INIT,
806
+ readyType: HOST_RUNTIME_FRAME_READY,
807
+ scopeId,
808
+ serviceIds: HOST_RUNTIME_FRAME_SERVICE_IDS,
809
+ readyTransport: "first-port",
810
+ trustedParentOrigin: options.trustedParentOrigin,
811
+ async onConnect({ runtime }) {
812
+ lease?.release();
813
+ const nextLease = registry.acquire(scopeId, () => options.createRuntime?.() ?? new HostRuntime(options.sdk));
814
+ const previousChainService = chainService;
815
+ let nextChainService = null;
816
+ try {
817
+ nextChainService = (await options.createChainService?.()) ?? null;
818
+ }
819
+ catch (error) {
820
+ nextLease.release();
821
+ throw error;
822
+ }
823
+ lease = nextLease;
824
+ chainService = nextChainService;
825
+ const stopServing = serveHostRuntimePort(runtime, nextLease.runtime, nextChainService);
826
+ void previousChainService?.destroy();
827
+ return {
828
+ payload: {
829
+ chainService: nextChainService != null,
830
+ },
831
+ dispose: () => {
832
+ stopServing();
833
+ nextLease.release();
834
+ void nextChainService?.destroy();
835
+ if (lease === nextLease) {
836
+ lease = null;
837
+ }
838
+ if (chainService === nextChainService) {
839
+ chainService = null;
840
+ }
841
+ },
842
+ };
843
+ },
844
+ });
845
+ }
846
+ /**
847
+ * Mount a hidden trusted runtime iframe and connect to its HostRuntime server.
848
+ *
849
+ * The iframe should be served from a common host-controlled origin, such as
850
+ * `https://host.dot.li/runtime-frame.html`, so host-owned browser services can
851
+ * live behind one trusted runtime boundary. Note that modern browsers may still
852
+ * partition iframe storage by top-level site; hosts that need unpartitioned
853
+ * durable cache reuse across pages must account for those browser policies.
854
+ */
855
+ export async function mountHostRuntimeFrame(options) {
856
+ const frame = await mountScopedFrame({
857
+ source: HOST_RUNTIME_FRAME_SOURCE,
858
+ initType: HOST_RUNTIME_FRAME_INIT,
859
+ readyType: HOST_RUNTIME_FRAME_READY,
860
+ scopeId: options.scopeId ?? "default",
861
+ serviceIds: HOST_RUNTIME_FRAME_SERVICE_IDS,
862
+ readyTransport: "first-port",
863
+ frameUrl: options.runtimeUrl,
864
+ frameOrigin: options.runtimeOrigin,
865
+ parent: options.parent,
866
+ timeoutMs: options.timeoutMs,
867
+ iframeAttributes: options.iframeAttributes,
868
+ });
869
+ const remoteFrame = connectHostRuntimeFramePort(frame.ports.runtime, frame.payload.chainService);
870
+ return {
871
+ iframe: frame.iframe,
872
+ runtime: remoteFrame.runtime,
873
+ chainService: remoteFrame.chainService,
874
+ destroy() {
875
+ void remoteFrame.chainService?.destroy();
876
+ remoteFrame.runtime.destroy();
877
+ frame.destroy();
878
+ },
879
+ };
880
+ }
881
+ //# sourceMappingURL=host-runtime-frame.js.map