@multiplatform.one/web3 7.18.0 → 7.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +60 -0
  2. package/dist/cjs/clients/adapter.cjs +33 -0
  3. package/dist/cjs/clients/adapter.native.js +36 -0
  4. package/dist/cjs/clients/adapter.native.js.map +1 -0
  5. package/dist/cjs/clients/bitcoin.cjs +46 -0
  6. package/dist/cjs/clients/bitcoin.native.js +51 -0
  7. package/dist/cjs/clients/bitcoin.native.js.map +1 -0
  8. package/dist/cjs/clients/connector.cjs +45 -0
  9. package/dist/cjs/clients/connector.native.js +49 -0
  10. package/dist/cjs/clients/connector.native.js.map +1 -0
  11. package/dist/cjs/clients/evm.cjs +171 -0
  12. package/dist/cjs/clients/evm.native.js +198 -0
  13. package/dist/cjs/clients/evm.native.js.map +1 -0
  14. package/dist/cjs/clients/gpg.cjs +31 -0
  15. package/dist/cjs/clients/gpg.native.js +34 -0
  16. package/dist/cjs/clients/gpg.native.js.map +1 -0
  17. package/dist/cjs/clients/hooks.cjs +78 -0
  18. package/dist/cjs/clients/hooks.native.js +85 -0
  19. package/dist/cjs/clients/hooks.native.js.map +1 -0
  20. package/dist/cjs/clients/index.cjs +49 -0
  21. package/dist/cjs/clients/index.native.js +52 -0
  22. package/dist/cjs/clients/index.native.js.map +1 -0
  23. package/dist/cjs/clients/solana.cjs +322 -0
  24. package/dist/cjs/clients/solana.native.js +511 -0
  25. package/dist/cjs/clients/solana.native.js.map +1 -0
  26. package/dist/cjs/clients/solanaMessage.cjs +38 -0
  27. package/dist/cjs/clients/solanaMessage.native.js +44 -0
  28. package/dist/cjs/clients/solanaMessage.native.js.map +1 -0
  29. package/dist/cjs/clients/sui.cjs +46 -0
  30. package/dist/cjs/clients/sui.native.js +51 -0
  31. package/dist/cjs/clients/sui.native.js.map +1 -0
  32. package/dist/cjs/clients/types.cjs +37 -0
  33. package/dist/cjs/clients/types.native.js +160 -0
  34. package/dist/cjs/clients/types.native.js.map +1 -0
  35. package/dist/cjs/clients/useSolanaClient.cjs +50 -0
  36. package/dist/cjs/clients/useSolanaClient.native.js +57 -0
  37. package/dist/cjs/clients/useSolanaClient.native.js.map +1 -0
  38. package/dist/cjs/clients/walletStandard.cjs +63 -0
  39. package/dist/cjs/clients/walletStandard.native.js +71 -0
  40. package/dist/cjs/clients/walletStandard.native.js.map +1 -0
  41. package/dist/cjs/connectkit/connectors/walletAdapterConnector.cjs +2 -0
  42. package/dist/cjs/connectkit/connectors/walletAdapterConnector.native.js +2 -0
  43. package/dist/cjs/connectkit/connectors/walletAdapterConnector.native.js.map +1 -1
  44. package/dist/cjs/connectkit/siwe/SIWEProvider.cjs +4 -5
  45. package/dist/cjs/connectkit/siwe/SIWEProvider.native.js +4 -5
  46. package/dist/cjs/connectkit/siwe/SIWEProvider.native.js.map +1 -1
  47. package/dist/cjs/index.cjs +2 -1
  48. package/dist/cjs/index.native.js +1 -0
  49. package/dist/cjs/index.native.js.map +1 -1
  50. package/dist/cjs/solana.cjs +41 -0
  51. package/dist/cjs/solana.native.js +44 -0
  52. package/dist/cjs/solana.native.js.map +1 -0
  53. package/dist/esm/clients/adapter.mjs +8 -0
  54. package/dist/esm/clients/adapter.mjs.map +1 -0
  55. package/dist/esm/clients/adapter.native.js +8 -0
  56. package/dist/esm/clients/adapter.native.js.map +1 -0
  57. package/dist/esm/clients/bitcoin.mjs +21 -0
  58. package/dist/esm/clients/bitcoin.mjs.map +1 -0
  59. package/dist/esm/clients/bitcoin.native.js +23 -0
  60. package/dist/esm/clients/bitcoin.native.js.map +1 -0
  61. package/dist/esm/clients/connector.mjs +20 -0
  62. package/dist/esm/clients/connector.mjs.map +1 -0
  63. package/dist/esm/clients/connector.native.js +21 -0
  64. package/dist/esm/clients/connector.native.js.map +1 -0
  65. package/dist/esm/clients/evm.mjs +146 -0
  66. package/dist/esm/clients/evm.mjs.map +1 -0
  67. package/dist/esm/clients/evm.native.js +170 -0
  68. package/dist/esm/clients/evm.native.js.map +1 -0
  69. package/dist/esm/clients/gpg.mjs +3 -0
  70. package/dist/esm/clients/gpg.mjs.map +1 -0
  71. package/dist/esm/clients/gpg.native.js +3 -0
  72. package/dist/esm/clients/gpg.native.js.map +1 -0
  73. package/dist/esm/clients/hooks.mjs +51 -0
  74. package/dist/esm/clients/hooks.mjs.map +1 -0
  75. package/dist/esm/clients/hooks.native.js +55 -0
  76. package/dist/esm/clients/hooks.native.js.map +1 -0
  77. package/dist/esm/clients/index.mjs +11 -0
  78. package/dist/esm/clients/index.mjs.map +1 -0
  79. package/dist/esm/clients/index.native.js +11 -0
  80. package/dist/esm/clients/index.native.js.map +1 -0
  81. package/dist/esm/clients/solana.mjs +289 -0
  82. package/dist/esm/clients/solana.mjs.map +1 -0
  83. package/dist/esm/clients/solana.native.js +475 -0
  84. package/dist/esm/clients/solana.native.js.map +1 -0
  85. package/dist/esm/clients/solanaMessage.mjs +13 -0
  86. package/dist/esm/clients/solanaMessage.mjs.map +1 -0
  87. package/dist/esm/clients/solanaMessage.native.js +16 -0
  88. package/dist/esm/clients/solanaMessage.native.js.map +1 -0
  89. package/dist/esm/clients/sui.mjs +21 -0
  90. package/dist/esm/clients/sui.mjs.map +1 -0
  91. package/dist/esm/clients/sui.native.js +23 -0
  92. package/dist/esm/clients/sui.native.js.map +1 -0
  93. package/dist/esm/clients/types.mjs +12 -0
  94. package/dist/esm/clients/types.mjs.map +1 -0
  95. package/dist/esm/clients/types.native.js +132 -0
  96. package/dist/esm/clients/types.native.js.map +1 -0
  97. package/dist/esm/clients/useSolanaClient.mjs +25 -0
  98. package/dist/esm/clients/useSolanaClient.mjs.map +1 -0
  99. package/dist/esm/clients/useSolanaClient.native.js +29 -0
  100. package/dist/esm/clients/useSolanaClient.native.js.map +1 -0
  101. package/dist/esm/clients/walletStandard.mjs +33 -0
  102. package/dist/esm/clients/walletStandard.mjs.map +1 -0
  103. package/dist/esm/clients/walletStandard.native.js +38 -0
  104. package/dist/esm/clients/walletStandard.native.js.map +1 -0
  105. package/dist/esm/connectkit/connectors/walletAdapterConnector.mjs +2 -0
  106. package/dist/esm/connectkit/connectors/walletAdapterConnector.mjs.map +1 -1
  107. package/dist/esm/connectkit/connectors/walletAdapterConnector.native.js +2 -0
  108. package/dist/esm/connectkit/connectors/walletAdapterConnector.native.js.map +1 -1
  109. package/dist/esm/connectkit/siwe/SIWEProvider.mjs +4 -5
  110. package/dist/esm/connectkit/siwe/SIWEProvider.mjs.map +1 -1
  111. package/dist/esm/connectkit/siwe/SIWEProvider.native.js +4 -5
  112. package/dist/esm/connectkit/siwe/SIWEProvider.native.js.map +1 -1
  113. package/dist/esm/index.mjs +1 -0
  114. package/dist/esm/index.mjs.map +1 -1
  115. package/dist/esm/index.native.js +1 -0
  116. package/dist/esm/index.native.js.map +1 -1
  117. package/dist/esm/solana.mjs +5 -0
  118. package/dist/esm/solana.mjs.map +1 -0
  119. package/dist/esm/solana.native.js +5 -0
  120. package/dist/esm/solana.native.js.map +1 -0
  121. package/dist/jsx/clients/adapter.mjs +8 -0
  122. package/dist/jsx/clients/adapter.mjs.map +1 -0
  123. package/dist/jsx/clients/adapter.native.js +36 -0
  124. package/dist/jsx/clients/adapter.native.js.map +1 -0
  125. package/dist/jsx/clients/bitcoin.mjs +21 -0
  126. package/dist/jsx/clients/bitcoin.mjs.map +1 -0
  127. package/dist/jsx/clients/bitcoin.native.js +51 -0
  128. package/dist/jsx/clients/bitcoin.native.js.map +1 -0
  129. package/dist/jsx/clients/connector.mjs +20 -0
  130. package/dist/jsx/clients/connector.mjs.map +1 -0
  131. package/dist/jsx/clients/connector.native.js +49 -0
  132. package/dist/jsx/clients/connector.native.js.map +1 -0
  133. package/dist/jsx/clients/evm.mjs +146 -0
  134. package/dist/jsx/clients/evm.mjs.map +1 -0
  135. package/dist/jsx/clients/evm.native.js +198 -0
  136. package/dist/jsx/clients/evm.native.js.map +1 -0
  137. package/dist/jsx/clients/gpg.mjs +3 -0
  138. package/dist/jsx/clients/gpg.mjs.map +1 -0
  139. package/dist/jsx/clients/gpg.native.js +34 -0
  140. package/dist/jsx/clients/gpg.native.js.map +1 -0
  141. package/dist/jsx/clients/hooks.mjs +51 -0
  142. package/dist/jsx/clients/hooks.mjs.map +1 -0
  143. package/dist/jsx/clients/hooks.native.js +85 -0
  144. package/dist/jsx/clients/hooks.native.js.map +1 -0
  145. package/dist/jsx/clients/index.mjs +11 -0
  146. package/dist/jsx/clients/index.mjs.map +1 -0
  147. package/dist/jsx/clients/index.native.js +52 -0
  148. package/dist/jsx/clients/index.native.js.map +1 -0
  149. package/dist/jsx/clients/solana.mjs +289 -0
  150. package/dist/jsx/clients/solana.mjs.map +1 -0
  151. package/dist/jsx/clients/solana.native.js +511 -0
  152. package/dist/jsx/clients/solana.native.js.map +1 -0
  153. package/dist/jsx/clients/solanaMessage.mjs +13 -0
  154. package/dist/jsx/clients/solanaMessage.mjs.map +1 -0
  155. package/dist/jsx/clients/solanaMessage.native.js +44 -0
  156. package/dist/jsx/clients/solanaMessage.native.js.map +1 -0
  157. package/dist/jsx/clients/sui.mjs +21 -0
  158. package/dist/jsx/clients/sui.mjs.map +1 -0
  159. package/dist/jsx/clients/sui.native.js +51 -0
  160. package/dist/jsx/clients/sui.native.js.map +1 -0
  161. package/dist/jsx/clients/types.mjs +12 -0
  162. package/dist/jsx/clients/types.mjs.map +1 -0
  163. package/dist/jsx/clients/types.native.js +160 -0
  164. package/dist/jsx/clients/types.native.js.map +1 -0
  165. package/dist/jsx/clients/useSolanaClient.mjs +25 -0
  166. package/dist/jsx/clients/useSolanaClient.mjs.map +1 -0
  167. package/dist/jsx/clients/useSolanaClient.native.js +57 -0
  168. package/dist/jsx/clients/useSolanaClient.native.js.map +1 -0
  169. package/dist/jsx/clients/walletStandard.mjs +33 -0
  170. package/dist/jsx/clients/walletStandard.mjs.map +1 -0
  171. package/dist/jsx/clients/walletStandard.native.js +71 -0
  172. package/dist/jsx/clients/walletStandard.native.js.map +1 -0
  173. package/dist/jsx/connectkit/connectors/walletAdapterConnector.mjs +2 -0
  174. package/dist/jsx/connectkit/connectors/walletAdapterConnector.mjs.map +1 -1
  175. package/dist/jsx/connectkit/connectors/walletAdapterConnector.native.js +2 -0
  176. package/dist/jsx/connectkit/connectors/walletAdapterConnector.native.js.map +1 -1
  177. package/dist/jsx/connectkit/siwe/SIWEProvider.mjs +4 -5
  178. package/dist/jsx/connectkit/siwe/SIWEProvider.mjs.map +1 -1
  179. package/dist/jsx/connectkit/siwe/SIWEProvider.native.js +4 -5
  180. package/dist/jsx/connectkit/siwe/SIWEProvider.native.js.map +1 -1
  181. package/dist/jsx/index.js +1 -0
  182. package/dist/jsx/index.js.map +1 -1
  183. package/dist/jsx/index.mjs +1 -0
  184. package/dist/jsx/index.mjs.map +1 -1
  185. package/dist/jsx/index.native.js +1 -0
  186. package/dist/jsx/index.native.js.map +1 -1
  187. package/dist/jsx/solana.mjs +5 -0
  188. package/dist/jsx/solana.mjs.map +1 -0
  189. package/dist/jsx/solana.native.js +44 -0
  190. package/dist/jsx/solana.native.js.map +1 -0
  191. package/package.json +13 -6
  192. package/src/clients/adapter.ts +13 -0
  193. package/src/clients/bitcoin.ts +42 -0
  194. package/src/clients/connector.spec.ts +78 -0
  195. package/src/clients/connector.ts +36 -0
  196. package/src/clients/evm.spec.ts +265 -0
  197. package/src/clients/evm.ts +223 -0
  198. package/src/clients/gpg.spec.ts +169 -0
  199. package/src/clients/gpg.ts +8 -0
  200. package/src/clients/hooks.spec.tsx +113 -0
  201. package/src/clients/hooks.ts +51 -0
  202. package/src/clients/index.ts +40 -0
  203. package/src/clients/solana.spec.ts +444 -0
  204. package/src/clients/solana.ts +465 -0
  205. package/src/clients/solanaMessage.ts +34 -0
  206. package/src/clients/sui.ts +42 -0
  207. package/src/clients/types.ts +40 -0
  208. package/src/clients/useSolanaClient.ts +31 -0
  209. package/src/clients/walletStandard.ts +87 -0
  210. package/src/connectkit/connectors/walletAdapterConnector.ts +2 -0
  211. package/src/connectkit/siwe/SIWEProvider.spec.tsx +112 -0
  212. package/src/connectkit/siwe/SIWEProvider.tsx +6 -10
  213. package/src/index.ts +4 -0
  214. package/src/solana.ts +30 -0
  215. package/types/clients/adapter.d.ts +5 -0
  216. package/types/clients/adapter.d.ts.map +1 -0
  217. package/types/clients/bitcoin.d.ts +21 -0
  218. package/types/clients/bitcoin.d.ts.map +1 -0
  219. package/types/clients/connector.d.ts +14 -0
  220. package/types/clients/connector.d.ts.map +1 -0
  221. package/types/clients/evm.d.ts +68 -0
  222. package/types/clients/evm.d.ts.map +1 -0
  223. package/types/clients/gpg.d.ts +2 -0
  224. package/types/clients/gpg.d.ts.map +1 -0
  225. package/types/clients/hooks.d.ts +16 -0
  226. package/types/clients/hooks.d.ts.map +1 -0
  227. package/types/clients/index.d.ts +10 -0
  228. package/types/clients/index.d.ts.map +1 -0
  229. package/types/clients/solana.d.ts +111 -0
  230. package/types/clients/solana.d.ts.map +1 -0
  231. package/types/clients/solanaMessage.d.ts +18 -0
  232. package/types/clients/solanaMessage.d.ts.map +1 -0
  233. package/types/clients/sui.d.ts +21 -0
  234. package/types/clients/sui.d.ts.map +1 -0
  235. package/types/clients/types.d.ts +27 -0
  236. package/types/clients/types.d.ts.map +1 -0
  237. package/types/clients/useSolanaClient.d.ts +11 -0
  238. package/types/clients/useSolanaClient.d.ts.map +1 -0
  239. package/types/clients/walletStandard.d.ts +63 -0
  240. package/types/clients/walletStandard.d.ts.map +1 -0
  241. package/types/connectkit/connectors/walletAdapterConnector.d.ts.map +1 -1
  242. package/types/connectkit/siwe/SIWEProvider.d.ts.map +1 -1
  243. package/types/index.d.ts +1 -0
  244. package/types/index.d.ts.map +1 -1
  245. package/types/solana.d.ts +4 -0
  246. package/types/solana.d.ts.map +1 -0
package/README.md CHANGED
@@ -24,6 +24,66 @@ Peers: `react`, `@tanstack/react-query`.
24
24
  `WalletStatus`, `NetworkSwitcher`
25
25
  - **Subpaths** — `./native` (WebView wallet bridge), `./connectkit`
26
26
 
27
+ ## Per-chain clients
28
+
29
+ Apps talk to a chain through a client, never through wagmi, `window.ethereum`
30
+ or a provider's `request`. Every client shares
31
+ `{ family, address, chainId?, capabilities, signMessage(message) }`, and
32
+ `signMessage` returns the family's native signature, the one the Keycloak
33
+ verifiers take: EVM 0x hex, Solana base58, Sui base64, Bitcoin base64 BIP-322,
34
+ GPG the armored signature plus the armored public key.
35
+
36
+ | Hook / factory | What it adds |
37
+ | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38
+ | `useEvmClient()` / `evmClient({ walletClient } \| { provider, account, chain })` | viem `walletClient` + `publicClient`, `sendTransaction`, `writeContract`, `waitForTransactionReceipt`, `erc20.{transfer, approve, ensureAllowance, balanceOf, allowance, decimals}`, safe for tokens like USDT that return nothing or refuse a non-zero to non-zero approve |
39
+ | `useSolanaClient()` / `solanaClient({ signer, rpcUrl?, chain? })` from `./solana` | web only: `@solana/kit` `rpc`, `signTransaction`, `signAndSendTransaction`, `sendTransaction`, `confirmTransaction`, `getBalance`, `transferSol` |
40
+ | `useGpgSigner()` / `createGpgSigner()` | the copy/paste GPG signer: `signMessage` parks a request with its terminal `command`; `submit(pasted, request)` resolves it only while `request` is still the pending one and the pasted signature covers its message |
41
+ | `useSuiClient()`, `useBitcoinClient()` | message signing only; `signTransaction` / `signPsbt` reject with `UnsupportedClientMethodError` until transactions land |
42
+
43
+ ```tsx
44
+ import { useEvmClient } from "@multiplatform.one/web3";
45
+ import { useSolanaClient } from "@multiplatform.one/web3/solana";
46
+
47
+ const evm = useEvmClient();
48
+ await evm?.erc20.ensureAllowance({ token: qcc, spender: store, amount });
49
+ await evm?.writeContract({ address: store, abi, functionName: "buy", args: [packageId] });
50
+
51
+ const sol = useSolanaClient();
52
+ const sent = await sol?.transferSol({ to, lamports: 1_000_000n });
53
+ await sol?.confirmTransaction(sent!);
54
+ ```
55
+
56
+ `transferSol` returns the signature with the blockhash's `lastValidBlockHeight`,
57
+ and `confirmTransaction` waits until the chain passes that height before it
58
+ gives up. Its `SolanaConfirmationError` has `mayStillLand`: `false` means the
59
+ transaction failed or expired and a retry is safe; `true` (only when there was
60
+ no `lastValidBlockHeight` to judge by) means resending can pay twice.
61
+
62
+ A Solana client runs over a byte-level `SolanaSigner`: `standardSolanaSigner`
63
+ (Wallet Standard: Phantom, Solflare, Backpack), `injectedSolanaSigner` (what the
64
+ modal connected), or `connectSolanaWallet()` without the modal. RPC defaults to
65
+ `Web3Config.solanaRpcUrl`.
66
+
67
+ The Solana client is the web-only `@multiplatform.one/web3/solana` subpath, with
68
+ no `react-native` condition. The root is also the native entry, and a native app
69
+ signs Solana through the WebView bridge, so the root never imports
70
+ `@solana/kit`. Sign-in does not need it either: `SIWEProvider` signs Solana
71
+ through `solanaMessageClient`, so a login page carries no kit.
72
+ `tests/clients/importGraph.spec.ts` holds both lines, for native and web.
73
+
74
+ ### Solana on mobile (follow-up)
75
+
76
+ The web path is done. A native app cannot reach Phantom through the WebView
77
+ bridge alone: the WebView has no injected Phantom, and a dapp opened inside
78
+ Phantom's in-app browser can never hand control back to the calling app. The
79
+ chosen direction is Phantom's deeplink protocol (Solflare speaks the same one),
80
+ bridged to the WebView like every other native signer and never a native module: an X25519 keypair per session, `connect`,
81
+ `signMessage`, `signTransaction` and `signAndSendTransaction` sent to
82
+ `https://phantom.app/ul/v1/<method>` with a `redirect_link` back into the app,
83
+ payloads sealed with NaCl box, and the session token kept for later calls. The
84
+ native host owns `Linking`; the client, the modal and login stay unchanged.
85
+ Android can later add Solana Mobile Wallet Adapter as a second signer.
86
+
27
87
  ## What it must not do
28
88
 
29
89
  - No modal shell — the modal UI lives in `@multiplatform.one/connectkit`;
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var adapter_exports = {};
24
+ __export(adapter_exports, {
25
+ connectorAdapter: () => connectorAdapter
26
+ });
27
+ module.exports = __toCommonJS(adapter_exports);
28
+ function connectorAdapter(connector, ecosystem) {
29
+ const c = connector;
30
+ if (!c?.adapter || !c.ecosystem || c.ecosystem === "evm") return null;
31
+ if (ecosystem && c.ecosystem !== ecosystem) return null;
32
+ return c.adapter;
33
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var adapter_exports = {};
26
+ __export(adapter_exports, {
27
+ connectorAdapter: () => connectorAdapter
28
+ });
29
+ module.exports = __toCommonJS(adapter_exports);
30
+ function connectorAdapter(connector, ecosystem) {
31
+ var c = connector;
32
+ if (!(c === null || c === void 0 ? void 0 : c.adapter) || !c.ecosystem || c.ecosystem === "evm") return null;
33
+ if (ecosystem && c.ecosystem !== ecosystem) return null;
34
+ return c.adapter;
35
+ }
36
+ //# sourceMappingURL=adapter.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","adapter_exports","__export","connectorAdapter","module","exports","connector","ecosystem","c","adapter"],"sources":["../../../src/clients/adapter.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAA;AAAA;AAIOC,MAAA,CAAAC,OAAS,GAAAT,YACd,CAAAK,eACA;AAEA,SAAME,gBAAIA,CAAAG,SAAA,EAAAC,SAAA;EACV,IAAIC,CAAC,GAAGF,SAAA;EACR,IAAI,EAAAE,CAAA,aAAeA,CAAA,cAAc,SAAWA,CAAA,CAAAC,OAAO,MAAAD,CAAA,CAAAD,SAAA,IAAAC,CAAA,CAAAD,SAAA;EACnD,IAAAA,SAAS,IAAAC,CAAA,CAAAD,SAAA,KAAAA,SAAA;EACX,OAAAC,CAAA,CAAAC,OAAA","ignoreList":[]}
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var bitcoin_exports = {};
24
+ __export(bitcoin_exports, {
25
+ bitcoinClient: () => bitcoinClient
26
+ });
27
+ module.exports = __toCommonJS(bitcoin_exports);
28
+ var import_types = require("./types.cjs");
29
+ const txTodo = "needs PSBT signing through the wallet (Unisat/OKX signPsbt, Phantom's bitcoin signPSBT) and a broadcast endpoint";
30
+ const capabilities = ["signMessage"];
31
+ function bitcoinClient(adapter) {
32
+ if (!adapter.address) throw new Error("bitcoinClient: connect a Bitcoin wallet first");
33
+ return {
34
+ family: "bitcoin",
35
+ address: adapter.address,
36
+ chainId: "bitcoin",
37
+ capabilities,
38
+ signMessage: message => adapter.signMessage(message),
39
+ signPsbt: async () => {
40
+ throw new import_types.UnsupportedClientMethodError("bitcoin", "signPsbt", txTodo);
41
+ },
42
+ sendBitcoin: async () => {
43
+ throw new import_types.UnsupportedClientMethodError("bitcoin", "sendBitcoin", txTodo);
44
+ }
45
+ };
46
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var bitcoin_exports = {};
26
+ __export(bitcoin_exports, {
27
+ bitcoinClient: () => bitcoinClient
28
+ });
29
+ module.exports = __toCommonJS(bitcoin_exports);
30
+ var import_types = require("./types.native.js");
31
+ var txTodo = "needs PSBT signing through the wallet (Unisat/OKX signPsbt, Phantom's bitcoin signPSBT) and a broadcast endpoint";
32
+ var capabilities = ["signMessage"];
33
+ function bitcoinClient(adapter) {
34
+ if (!adapter.address) throw new Error("bitcoinClient: connect a Bitcoin wallet first");
35
+ return {
36
+ family: "bitcoin",
37
+ address: adapter.address,
38
+ chainId: "bitcoin",
39
+ capabilities,
40
+ signMessage: function signMessage(message) {
41
+ return adapter.signMessage(message);
42
+ },
43
+ signPsbt: async function signPsbt() {
44
+ throw new import_types.UnsupportedClientMethodError("bitcoin", "signPsbt", txTodo);
45
+ },
46
+ sendBitcoin: async function sendBitcoin() {
47
+ throw new import_types.UnsupportedClientMethodError("bitcoin", "sendBitcoin", txTodo);
48
+ }
49
+ };
50
+ }
51
+ //# sourceMappingURL=bitcoin.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","bitcoin_exports","__export","bitcoinClient","module","exports","import_types","require","txTodo","capabilities","adapter","address","Error","family","chainId","signMessage","message","signPsbt","UnsupportedClientMethodError"],"sources":["../../../src/clients/bitcoin.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAT,YAAsF,CAAAK,eAAA;AAItF,IAAAK,YACE,GAAAC,OAAA;AAkBF,IAAAC,MAAM,qHAA0D;AAEzD,IAAAC,YAAS,IACd,aAAa,CACb;AAAO,SACLN,aAAQA,CAAAO,OAAA;EAAA,IACR,CAAAA,OAAS,CAAAC,OAAQ,YAAAC,KAAA;EAAA,OACjB;IACAC,MAAA;IACAF,OAAA,EAAAD,OAAc,CAAAC,OAAA;IACdG,OAAA,WAAU;IACRL,YAAU;IACZM,WAAA,WAAAA,YAAAC,OAAA;MACA,OAAAN,OAAa,CAAAK,WAAY,CAAAC,OAAA;IACvB;IACFC,QAAA,iBAAAA,SAAA;MACF,UAAAX,YAAA,CAAAY,4BAAA,wBAAAV,MAAA;IACF","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var connector_exports = {};
24
+ __export(connector_exports, {
25
+ clientForConnector: () => clientForConnector
26
+ });
27
+ module.exports = __toCommonJS(connector_exports);
28
+ var import_adapter = require("./adapter.cjs");
29
+ var import_bitcoin = require("./bitcoin.cjs");
30
+ var import_solanaMessage = require("./solanaMessage.cjs");
31
+ var import_sui = require("./sui.cjs");
32
+ function clientForConnector(connector, options = {}) {
33
+ const adapter = (0, import_adapter.connectorAdapter)(connector);
34
+ if (!adapter?.address) return null;
35
+ switch (connector.ecosystem) {
36
+ case "solana":
37
+ return (0, import_solanaMessage.solanaMessageClient)(adapter, options.solanaChain);
38
+ case "sui":
39
+ return (0, import_sui.suiClient)(adapter);
40
+ case "bitcoin":
41
+ return (0, import_bitcoin.bitcoinClient)(adapter);
42
+ default:
43
+ return null;
44
+ }
45
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var connector_exports = {};
26
+ __export(connector_exports, {
27
+ clientForConnector: () => clientForConnector
28
+ });
29
+ module.exports = __toCommonJS(connector_exports);
30
+ var import_adapter = require("./adapter.native.js");
31
+ var import_bitcoin = require("./bitcoin.native.js");
32
+ var import_solanaMessage = require("./solanaMessage.native.js");
33
+ var import_sui = require("./sui.native.js");
34
+ function clientForConnector(connector) {
35
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
36
+ var adapter = (0, import_adapter.connectorAdapter)(connector);
37
+ if (!(adapter === null || adapter === void 0 ? void 0 : adapter.address)) return null;
38
+ switch (connector.ecosystem) {
39
+ case "solana":
40
+ return (0, import_solanaMessage.solanaMessageClient)(adapter, options.solanaChain);
41
+ case "sui":
42
+ return (0, import_sui.suiClient)(adapter);
43
+ case "bitcoin":
44
+ return (0, import_bitcoin.bitcoinClient)(adapter);
45
+ default:
46
+ return null;
47
+ }
48
+ }
49
+ //# sourceMappingURL=connector.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","connector_exports","__export","clientForConnector","module","exports","import_adapter","require","import_bitcoin","import_solanaMessage","import_sui","connector","options","arguments","length","adapter","connectorAdapter","address","ecosystem","solanaMessageClient","solanaChain","suiClient","bitcoinClient"],"sources":["../../../src/clients/connector.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,iBAAA;AAAAC,QAAA,CAAAD,iBAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAT,YAAiC,CAAAK,iBAAA;AACjC,IAAAK,cAAA,GAAkDC,OAAA;AAClD,IAAAC,cAAA,GAAAD,OAAgF;AAChF,IAAAE,oBAA0C,GAAAF,OAAA;AAenC,IAAAG,UAAS,GAAAH,OAAA,kBACd;AAGA,SAAMJ,kBAAUA,CAAAQ,SAAA;EAChB,IAAIC,OAAC,GAASC,SAAS,CAAAC,MAAO,QAAAD,SAAA,iBAAAA,SAAA;EAC9B,IAAAE,OAAS,OAAoCT,cAAW,CAAAU,gBAAA,EAAAL,SAAA;EAAA,IACtD,EAAAI,OAAK,aAAAA,OAAA,uBAAAA,OAAA,CAAAE,OAAA;EACH,QAAAN,SAAO,CAAAO,SAAA;IACT,KAAK;MACH,WAAOT,oBAAA,CAAAU,mBAAiB,EAAAJ,OAAA,EAAAH,OAAA,CAAAQ,WAAA;IAC1B,KAAK;MACH,WAAOV,UAAA,CAAAW,SAAA,EAAAN,OAAA,CAAc;IACvB;MACE,OAAO,IAAAP,cAAA,CAAAc,aAAA,EAAAP,OAAA;IACX;MACF","ignoreList":[]}
@@ -0,0 +1,171 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var evm_exports = {};
24
+ __export(evm_exports, {
25
+ evmClient: () => evmClient
26
+ });
27
+ module.exports = __toCommonJS(evm_exports);
28
+ var import_viem = require("viem");
29
+ const erc20WriteAbi = [{
30
+ type: "function",
31
+ name: "transfer",
32
+ stateMutability: "nonpayable",
33
+ inputs: [{
34
+ name: "to",
35
+ type: "address"
36
+ }, {
37
+ name: "amount",
38
+ type: "uint256"
39
+ }],
40
+ outputs: []
41
+ }, {
42
+ type: "function",
43
+ name: "approve",
44
+ stateMutability: "nonpayable",
45
+ inputs: [{
46
+ name: "spender",
47
+ type: "address"
48
+ }, {
49
+ name: "amount",
50
+ type: "uint256"
51
+ }],
52
+ outputs: []
53
+ }];
54
+ const capabilities = ["signMessage", "sendTransaction", "writeContract"];
55
+ function evmClient(config) {
56
+ const walletClient = "walletClient" in config ? config.walletClient : (0, import_viem.createWalletClient)({
57
+ account: config.account,
58
+ chain: config.chain,
59
+ transport: (0, import_viem.custom)(config.provider)
60
+ });
61
+ const chain = walletClient.chain;
62
+ if (!chain) throw new Error("evmClient: the wallet client has no chain");
63
+ const publicClient = config.publicClient ?? (0, import_viem.createPublicClient)({
64
+ chain,
65
+ transport: (0, import_viem.http)(config.rpcUrl)
66
+ });
67
+ const account = walletClient.account;
68
+ const writeContract = parameters => walletClient.writeContract({
69
+ account,
70
+ chain,
71
+ ...parameters
72
+ });
73
+ const simulateAndWrite = async parameters => {
74
+ const {
75
+ request
76
+ } = await publicClient.simulateContract({
77
+ account,
78
+ address: parameters.address,
79
+ abi: erc20WriteAbi,
80
+ functionName: parameters.functionName,
81
+ args: parameters.args
82
+ });
83
+ return walletClient.writeContract({
84
+ ...request,
85
+ account,
86
+ chain
87
+ });
88
+ };
89
+ const approveAndWait = async (token, spender, amount) => {
90
+ const hash = await erc20.approve({
91
+ token,
92
+ spender,
93
+ amount
94
+ });
95
+ const receipt = await publicClient.waitForTransactionReceipt({
96
+ hash
97
+ });
98
+ if (receipt.status !== "success") throw new Error(`approve ${hash} reverted`);
99
+ return hash;
100
+ };
101
+ const erc20 = {
102
+ balanceOf: (token, owner = account.address) => publicClient.readContract({
103
+ address: token,
104
+ abi: import_viem.erc20Abi,
105
+ functionName: "balanceOf",
106
+ args: [owner]
107
+ }),
108
+ allowance: (token, spender, owner = account.address) => publicClient.readContract({
109
+ address: token,
110
+ abi: import_viem.erc20Abi,
111
+ functionName: "allowance",
112
+ args: [owner, spender]
113
+ }),
114
+ decimals: token => publicClient.readContract({
115
+ address: token,
116
+ abi: import_viem.erc20Abi,
117
+ functionName: "decimals"
118
+ }),
119
+ transfer: ({
120
+ token,
121
+ to,
122
+ amount
123
+ }) => simulateAndWrite({
124
+ address: token,
125
+ functionName: "transfer",
126
+ args: [to, amount]
127
+ }),
128
+ approve: ({
129
+ token,
130
+ spender,
131
+ amount
132
+ }) => simulateAndWrite({
133
+ address: token,
134
+ functionName: "approve",
135
+ args: [spender, amount]
136
+ }),
137
+ async ensureAllowance({
138
+ token,
139
+ spender,
140
+ amount
141
+ }) {
142
+ const current = await erc20.allowance(token, spender);
143
+ if (current >= amount) return null;
144
+ if (current > 0n) await approveAndWait(token, spender, 0n);
145
+ return approveAndWait(token, spender, amount);
146
+ }
147
+ };
148
+ return {
149
+ family: "evm",
150
+ address: account.address,
151
+ chainId: chain.id,
152
+ chain,
153
+ capabilities,
154
+ walletClient,
155
+ publicClient,
156
+ signMessage: message => walletClient.signMessage({
157
+ account,
158
+ message
159
+ }),
160
+ sendTransaction: parameters => walletClient.sendTransaction({
161
+ account,
162
+ chain,
163
+ ...parameters
164
+ }),
165
+ writeContract,
166
+ waitForTransactionReceipt: hash => publicClient.waitForTransactionReceipt({
167
+ hash
168
+ }),
169
+ erc20
170
+ };
171
+ }