@usebutr/sui 2.0.0 → 3.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,240 @@
1
+ # @usebutr/sui
2
+
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#203](https://github.com/pedroapfilho/usebutr/pull/203) [`1263f86`](https://github.com/pedroapfilho/usebutr/commit/1263f8666afd43b4f7dbf8df1763709c3edf09d9) Thanks [@pedroapfilho](https://github.com/pedroapfilho)! - Adapters now say what they can do by having the method: `capabilities` is gone, and an optional method (`sendTx`, `signMessage`, `getBalance`, `switchChain`, …) exists only when it works for that wallet. No adapter returns a placeholder balance or a receipt that stays pending anymore.
8
+
9
+ - `sendTx(tx, { account, chain })` replaces `sendTx` and `sendTxToChain`, and `signMessage`, `signTransaction` and `getBalance` take options objects. `chain` is a `ChainBase`. An adapter either routes the call to that chain, switches the wallet to it, or rejects; none ignores it.
10
+ - An `account` the wallet does not expose now rejects instead of signing with the first account. `chain.name` is the chain's name, never the wallet's.
11
+ - `getAccounts()` resolves the active account first. `getAccount` and `switchAccount` are removed.
12
+ - `getSigner()` resolves a tagged `WalletSigner` (`eip1193`, `wallet-standard`, `walletconnect`, `ledger-*`, …), so it can be narrowed with `switch (signer.kind)` instead of cast.
13
+ - `createWalletManager(config, { initialState })` owns discovery, hydration and persistence, and works without React. `config.sources` replaces the `discovery`, `connectors` and `createConnector` props. `fromAdapters` registers WalletConnect, Ledger and hand-built adapters, which now also appear in `useDiscoveredWallets()`.
14
+ - `WalletManagerProvider` takes `config` and `initialState`. `useSigner(wallet)` and `useBalance(wallet, { token, account })` take the wallet entry itself, and id-taking hooks read the active wallet only when the id is omitted (`null` reads none). The hooks are `useWalletManager`, `useWalletState`, `useConnect`, `useWallet`, `useSelectedWallet` (now typed per platform), `useAccounts`, `useConnectionStatus`, `useIsHydrated`, `useIsReconnecting`, `useDiscoveredWallets`, `useConnectedWallets`, the `…ByPlatform` groupings, `useBalance` and `useSigner`.
15
+ - `manager.connect()` and `useConnect().connectAsync()` resolve the `ConnectedWallet` and reject with a `ConnectionError`, now an `Error` subclass with a `kind` and a new `WalletNotFound` kind. `useConnect().connect()` never rejects: the failure lands in its `error`.
16
+ - `WalletPersistence` is `load()` / `save(state)`, and `createWalletStorage` replaces `new WalletStorage`. Storage keys are unchanged.
17
+ - Chain registries (`EVM_CHAINS`, `SVM_CHAINS`, …, `CHAINS_BY_PLATFORM`) move to `@usebutr/core`, and `BITCOIN_CHAINS` gains `testnet4`. `@usebutr/wallets` loads every platform's signer kinds, so an app that imports only it can narrow `signer.kind`.
18
+ - `@usebutr/react` requires React 19, which its `use()` call already needed.
19
+ - WalletConnect requests on Solana, Sui and Bitcoin now carry their chain, so they no longer fall through to the first namespace in a multi-namespace session. Solana takes `SVM_CHAINS` chains and maps them to the genesis-hash ids WalletConnect sessions use.
20
+ - Ledger's Solana `signTransaction` returns the full signed transaction, Sui signs the intent message, and Bitcoin `signMessage` returns a BIP-137 signature.
21
+ - `@usebutr/testing`'s fake adapter resolves a `signer` you pass instead of registering a test-only signer kind.
22
+ - `setAccount` selects an exposed account without changing any account's chain. Unknown accounts are ignored; chain changes come from the adapter.
23
+ - WalletConnect EVM events use the namespace in `session_event`, including empty account lists that end the connection. Local chain switches still update the manager.
24
+ - Failed persistence saves wait for every key write to finish before reporting failure, so delayed writes cannot overwrite a later disconnect.
25
+ - `@usebutr/svm/transaction` provides the shared legacy/v0 signing codec used by Ledger and WalletConnect, with consistent layout and signature validation.
26
+
27
+ See the migration guide at https://docs.usebutr.com/migration.
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [[`1263f86`](https://github.com/pedroapfilho/usebutr/commit/1263f8666afd43b4f7dbf8df1763709c3edf09d9), [`5d1f234`](https://github.com/pedroapfilho/usebutr/commit/5d1f23403263f7a1f8a48be061727972fe749b5f)]:
32
+ - @usebutr/core@3.0.0
33
+ - @usebutr/wallet-standard-shared@2.0.0
34
+
35
+ ## 2.0.2
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [[`bc5b58c`](https://github.com/pedroapfilho/usebutr/commit/bc5b58cd87601be38dbb77a14e16eaaa36e8f012), [`bc5b58c`](https://github.com/pedroapfilho/usebutr/commit/bc5b58cd87601be38dbb77a14e16eaaa36e8f012)]:
40
+ - @usebutr/wallet-standard-shared@1.0.0
41
+ - @usebutr/core@2.0.1
42
+
43
+ ## 2.0.1
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [302ae4a]
48
+ - @usebutr/wallet-standard-shared@0.5.1
49
+
50
+ ## 2.0.0
51
+
52
+ ### Major Changes
53
+
54
+ - 9b1caa2: Correctness pass across the storage, hydration and connector layers. Several of
55
+ these change observable behaviour; the ones worth knowing about before upgrading:
56
+
57
+ **Breaking**
58
+
59
+ - `SuiWallet.signTransaction` now returns `{ bytes, signature }` instead of
60
+ `Uint8Array`. Sui's `executeTransactionBlock` needs both, and each connector
61
+ previously returned a different half, so the old value could not be broadcast
62
+ and a consumer could not tell which half they held. SVM and Bitcoin keep their
63
+ single-`Uint8Array` shape.
64
+ - `@usebutr/svm`'s `sendTx` returns the signature base58-encoded, matching the
65
+ WalletConnect namespace, the Ledger app, Solana explorers and
66
+ `getSignatureStatuses`. It previously returned base64.
67
+ - `@usebutr/sui`'s feature input types drop the `string` arm from
68
+ `transaction`; wallets only ever accepted the `toJSON()` form. Strings and BCS
69
+ bytes are now wrapped for you, so `sendTx` accepts strictly more than before.
70
+
71
+ **Behaviour fixes**
72
+
73
+ - `WalletStorage.setPool` and `removePoolEntry` could self-deadlock on a corrupt
74
+ pool payload, leaving `connectWallet` unresolved and every later pool write
75
+ jammed for the page's life. Both are fixed, and `readWalletSnapshot` now shares
76
+ one codec with `WalletStorage` so the server and client decodes cannot drift.
77
+ - A seeded (SSR) entry whose silent reconnect failed used to stay in the pool
78
+ backed by a placeholder connector forever, so `useSigner`/`useBalance`
79
+ reported an error and `useConnectionStatus` reported `"reconnecting"`
80
+ permanently. Those entries are now dropped.
81
+ - `useSigner` and `useBalance` stay `idle` for a wallet that is still
82
+ reconnecting instead of surfacing a placeholder rejection as `status: "error"`.
83
+ - `useConnectionStatus` lets a live `"connecting"`/`"error"` take precedence over
84
+ the derived `"reconnecting"`, so an in-flight attempt and a connection error
85
+ are no longer hidden. New `useIsReconnecting(connectorId?)` answers the
86
+ per-wallet question directly.
87
+ - A background restore no longer writes the connect-attempt status or steals
88
+ `activeConnectorId`, and a superseded `CONNECT_FAILED` no longer overwrites the
89
+ current attempt.
90
+ - An externally-disconnected connector is now torn down, not just dropped from
91
+ the pool, so a cached adapter is not reused while still holding a session.
92
+ - EVM: a malformed provider response is treated as absent rather than `""`, which
93
+ previously produced chain `eip155:0`, zero-length signatures, empty transaction
94
+ hashes and a confident `0 ETH`. `switchChain` gained the same-chain
95
+ short-circuit `sendTxToChain` already had.
96
+ - WalletConnect: accounts carry their own chain instead of all being stamped with
97
+ the active one, so a multi-chain session no longer returns a wrong-chain
98
+ address. One pairing now covers every configured namespace, the pairing URI
99
+ survives a reconnect, and concurrent connects share one pairing.
100
+ - Bitcoin: the sats-connect (Xverse) adapter honours `silent`, so a reload no
101
+ longer triggers an unsolicited approval prompt, and exposes the payment address
102
+ as its single account instead of also presenting the ordinals address as
103
+ spendable.
104
+ - Polkadot: the injected adapter actually delivers events to subscribers,
105
+ `switchChain` notifies like its Wallet Standard sibling, and chain resolution
106
+ prefers the mainnets rather than whatever the wallet listed first.
107
+ - Ledger: the device session is committed atomically, so a locked device no
108
+ longer leaves an open transport that reports itself connected, and concurrent
109
+ connects open one transport.
110
+ - SVM: `sendTxToChain` submits to the chain you asked for instead of the
111
+ adapter's current one, and rejects a chain the wallet does not advertise.
112
+ - `@usebutr/svm`'s `switchChain` capability now counts only `solana:` chains, so
113
+ a multi-namespace wallet no longer advertises a method that always throws.
114
+
115
+ **Testing**
116
+
117
+ - `createFakePersistence` is now the real `WalletStorage` over memory drivers
118
+ rather than a parallel implementation, so it inherits upsert semantics,
119
+ validation and JSON round-tripping. Two divergences are fixed as a result:
120
+ `setPool` upserts rather than replaces, and `clearAll` leaves the
121
+ user-disconnected flag alone.
122
+ - `createFakeConnectedWallet` rejects being given both an `adapter` and explicit
123
+ `addresses`/`accounts`, a combination whose halves could disagree.
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [9b1caa2]
128
+ - @usebutr/wallet-standard-shared@0.5.0
129
+ - @usebutr/core@2.0.0
130
+
131
+ ## 1.0.1
132
+
133
+ ### Patch Changes
134
+
135
+ - Updated dependencies [8ecaf89]
136
+ - @usebutr/core@1.1.0
137
+ - @usebutr/wallet-standard-shared@0.4.1
138
+
139
+ ## 1.0.0
140
+
141
+ ### Major Changes
142
+
143
+ - f0a5116: **Breaking:** the `platform` field is gone from the `PlatformDiscoverer` type in `@usebutr/core`, and from the `evmDiscoverer`, `svmDiscoverer`, `suiDiscoverer`, `bitcoinDiscoverer` and `polkadotDiscoverer` objects that implement it. Nothing read it: the aggregator keys discoverers by `ChainPlatform` in its own registry, so the field only restated the key.
144
+
145
+ Migration: read the platform from the `KNOWN_DISCOVERERS` key in `@usebutr/wallets` (`Object.entries(KNOWN_DISCOVERERS)`), or from `adapter.chainPlatform` on a discovered adapter. Custom `PlatformDiscoverer` implementations must drop the `platform` property; keeping it is now an excess-property error.
146
+
147
+ - f0a5116: **Breaking:** `slugify` is no longer exported from `@usebutr/svm`, `@usebutr/sui` or `@usebutr/bitcoin`. Each package exported a one-argument wrapper that only bound a platform prefix onto the canonical two-argument helper, so three names shadowed one implementation.
148
+
149
+ Migration: import `slugify` from `@usebutr/wallet-standard-shared` and pass the platform prefix as the first argument. `slugify(name)` from `@usebutr/svm` becomes `slugify("svm", name)`; the `@usebutr/sui` prefix is `"sui"` and the `@usebutr/bitcoin` prefix is `"btc"`. Adapter ids are byte-for-byte the same.
150
+
151
+ ### Patch Changes
152
+
153
+ - 7887cf0: Resolve capabilities through `buildWalletCapabilities` from `@usebutr/wallet-standard-shared` instead of a per-package copy of the same object literal. Resolver names, input types and returned flags are unchanged. The injected Polkadot profile now derives its chain count from `POLKADOT_CHAINS_LIST` rather than asserting `switchChain: true` directly; the result is the same.
154
+ - 7887cf0: Move each package's `discover*Adapters` function next to the adapter builder it wraps and drop the single-function `wallet-standard.ts` module. The functions are still exported from the package root under the same names; only an internal file boundary went away.
155
+ - Updated dependencies [7887cf0]
156
+ - Updated dependencies [7887cf0]
157
+ - Updated dependencies [f0a5116]
158
+ - Updated dependencies [f0a5116]
159
+ - Updated dependencies [7887cf0]
160
+ - @usebutr/core@1.0.0
161
+ - @usebutr/wallet-standard-shared@0.4.0
162
+
163
+ ## 0.2.7
164
+
165
+ ### Patch Changes
166
+
167
+ - efe4550: Share the session plumbing behind the Wallet Standard and WalletConnect CAIP adapters. `@usebutr/wallet-standard-shared` now exports `createWalletStandardCore`, which the Bitcoin, Polkadot, Sui and SVM adapters build on; the WalletConnect Bitcoin, Sui and SVM namespaces share an equivalent CAIP core. Every package's public API is unchanged. The one visible difference is a dev-console warning: a failed SVM disconnect now logs `[butr] SVM Wallet Standard disconnect threw:` instead of `[butr] Wallet Standard disconnect threw:`.
168
+ - Updated dependencies [efe4550]
169
+ - Updated dependencies [4467a5e]
170
+ - @usebutr/wallet-standard-shared@0.3.0
171
+ - @usebutr/core@0.5.0
172
+
173
+ ## 0.2.6
174
+
175
+ ### Patch Changes
176
+
177
+ - Updated dependencies [c1309ee]
178
+ - @usebutr/core@0.4.2
179
+ - @usebutr/wallet-standard-shared@0.2.6
180
+
181
+ ## 0.2.5
182
+
183
+ ### Patch Changes
184
+
185
+ - 937dfae: Bump runtime dependency floors (`@wallet-standard/app` 1.1.1, `@ledgerhq/*` latest minors, `@walletconnect/universal-provider` 2.23.10) and modernize public type declarations from method signatures to property function types (oxlint `method-signature-style`). Type-level only — no runtime behavior change.
186
+ - Updated dependencies [937dfae]
187
+ - @usebutr/core@0.4.1
188
+ - @usebutr/wallet-standard-shared@0.2.5
189
+
190
+ ## 0.2.4
191
+
192
+ ### Patch Changes
193
+
194
+ - a46eecd: Ship unminified ESM so downstream bundlers (Vite/esbuild dep pre-bundling) process the package correctly; fixes a ReferenceError in consumer dev servers. The consuming app minifies once at its own build.
195
+ - Updated dependencies [b5322ae]
196
+ - Updated dependencies [d5f32c7]
197
+ - Updated dependencies [a46eecd]
198
+ - Updated dependencies [3f26776]
199
+ - @usebutr/core@0.4.0
200
+ - @usebutr/wallet-standard-shared@0.2.4
201
+
202
+ ## 0.2.3
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies [886ee1d]
207
+ - @usebutr/core@0.3.0
208
+ - @usebutr/wallet-standard-shared@0.2.3
209
+
210
+ ## 0.2.2
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [db5d7e9]
215
+ - @usebutr/core@0.2.2
216
+ - @usebutr/wallet-standard-shared@0.2.2
217
+
218
+ ## 0.2.1
219
+
220
+ ### Patch Changes
221
+
222
+ - f846e77: Wallet-announced icons are trimmed of surrounding whitespace on ingestion. Some wallets ship data-URI icons with a leading newline, which strict consumers reject — Next.js's `<Image>` throws because `src` must not start with a control character. `@usebutr/core` exports a `sanitizeIcon` helper; the EIP-6963 and Wallet Standard adapters apply it, and an all-whitespace icon now resolves to `undefined` rather than a blank string.
223
+ - Updated dependencies [f846e77]
224
+ - @usebutr/core@0.2.1
225
+ - @usebutr/wallet-standard-shared@0.2.1
226
+
227
+ ## 0.2.0
228
+
229
+ ### Minor Changes
230
+
231
+ - b77a477: Shared Wallet Standard protocol types (`WalletStandardWallet`, `WalletStandardWalletAccount`, `WalletStandardAppModule`, `WalletsApp`, `StandardConnectFeature`, `StandardDisconnectFeature`, `StandardEventsFeature`, `StandardEventsListener`) are imported from `@usebutr/wallet-standard-shared` directly — they are no longer re-exported from `@usebutr/svm`, `@usebutr/sui`, or `@usebutr/bitcoin`. Platform-specific feature shapes still ship from their own packages.
232
+
233
+ `@usebutr/svm` adapter ids are now platform-prefixed (`wallet-standard:svm-<slug>`), consistent with the `sui-` and `btc-` prefixes. `slugify` in `@usebutr/wallet-standard-shared` requires a non-empty platform prefix.
234
+
235
+ ### Patch Changes
236
+
237
+ - Updated dependencies [b77a477]
238
+ - Updated dependencies [b77a477]
239
+ - @usebutr/core@0.2.0
240
+ - @usebutr/wallet-standard-shared@0.2.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pedro Filho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @usebutr/sui
2
+
3
+ Wallet Standard adapter for butr (Sui).
4
+
5
+ Part of [butr](https://www.usebutr.com), a multi-chain wallet discovery and
6
+ connection-state library. Your application owns the picker UI and chain client.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @usebutr/react @usebutr/core @usebutr/sui zustand @wallet-standard/app
12
+ ```
13
+
14
+ React 19 is a peer dependency of the provider. Discovery does not render a connect modal; add your picker as the provider child. `@wallet-standard/app` is required for Wallet Standard discovery.
15
+
16
+ ## Usage
17
+
18
+ ```tsx
19
+ import type { ReactNode } from "react";
20
+ import type { WalletManagerConfig } from "@usebutr/core";
21
+ import { discoverSuiAdapters } from "@usebutr/sui";
22
+ import { WalletManagerProvider } from "@usebutr/react";
23
+
24
+ // Every `discover*Adapters` export is a wallet source as-is.
25
+ const config: WalletManagerConfig = { sources: [discoverSuiAdapters] };
26
+
27
+ export const WalletProvider = ({ children }: { children: ReactNode }) => (
28
+ <WalletManagerProvider config={config}>{children}</WalletManagerProvider>
29
+ );
30
+ ```
31
+
32
+ Each adapter defines `sendTx` (`sui:signAndExecuteTransaction`, resolves the digest), `signMessage` (`sui:signPersonalMessage`) and `signTransaction` (resolves `{ bytes, signature }` for `executeTransactionBlock`) only when the wallet advertises the matching feature, and `switchChain` only when it advertises more than one Sui network. Transactions are a `@mysten/sui` `Transaction`, its JSON string, or BCS bytes. Wallet Standard carries the chain per call, so `options.chain` routes one transaction without moving the wallet. Balances and receipts need your own `SuiClient`. Check a method's presence before calling it:
33
+
34
+ ```ts
35
+ import type { ConnectedWallet, SuiTransactionInput } from "@usebutr/core";
36
+ import { SUI_CHAINS } from "@usebutr/core";
37
+
38
+ export const send = async (wallet: ConnectedWallet<"sui">, transaction: SuiTransactionInput) => {
39
+ if (!wallet.connector.sendTx) {
40
+ throw new Error(`${wallet.connector.name} cannot send Sui transactions`);
41
+ }
42
+ return wallet.connector.sendTx(transaction, {
43
+ account: wallet.account,
44
+ chain: SUI_CHAINS.testnet,
45
+ });
46
+ };
47
+ ```
48
+
49
+ An `account` the wallet does not expose, or a chain it does not advertise, rejects. `getSigner()` resolves `{ kind: "wallet-standard", wallet }`: reach any other feature with `getFeature` from `@usebutr/wallet-standard-shared` and the feature types this package exports. Chain registries (`SUI_CHAINS`, `SUI_CHAINS_LIST`) come from `@usebutr/core`.
50
+
51
+ ## Documentation
52
+
53
+ - [Package reference](https://docs.usebutr.com/api/sui)
54
+ - [Getting started](https://docs.usebutr.com/getting-started/quickstart)
55
+ - [Examples and source](https://github.com/pedroapfilho/usebutr)
56
+ - [Report an issue](https://github.com/pedroapfilho/usebutr/issues)
57
+
58
+ ## License
59
+
60
+ [MIT](./LICENSE), copyright 2026 Pedro Filho.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ChainBase, PlatformDiscoverer, WalletAdapter, WalletCapabilities } from "@usebutr/core";
2
- import { WalletStandardWallet, WalletStandardWalletAccount } from "@usebutr/wallet-standard-shared";
1
+ import { PlatformDiscoverer, SuiAdapter, WalletAdapter } from "@usebutr/core";
2
+ import { WalletStandardModuleLoader, WalletStandardWallet, WalletStandardWalletAccount } from "@usebutr/wallet-standard-shared";
3
3
  //#region src/wallet-standard-types.d.ts
4
4
  type SuiSignPersonalMessageInput = {
5
5
  account: WalletStandardWalletAccount;
@@ -11,6 +11,7 @@ type SuiSignPersonalMessageOutput = {
11
11
  };
12
12
  type SuiSignPersonalMessageFeature = {
13
13
  signPersonalMessage: (input: SuiSignPersonalMessageInput) => Promise<SuiSignPersonalMessageOutput>;
14
+ version?: string;
14
15
  };
15
16
  type SuiSignTransactionInput = {
16
17
  account: WalletStandardWalletAccount;
@@ -25,6 +26,7 @@ type SuiSignTransactionOutput = {
25
26
  };
26
27
  type SuiSignTransactionFeature = {
27
28
  signTransaction: (input: SuiSignTransactionInput) => Promise<SuiSignTransactionOutput>;
29
+ version?: string;
28
30
  };
29
31
  type SuiSignAndExecuteTransactionInput = {
30
32
  account: WalletStandardWalletAccount;
@@ -41,70 +43,25 @@ type SuiSignAndExecuteTransactionOutput = {
41
43
  };
42
44
  type SuiSignAndExecuteTransactionFeature = {
43
45
  signAndExecuteTransaction: (input: SuiSignAndExecuteTransactionInput) => Promise<SuiSignAndExecuteTransactionOutput>;
46
+ version?: string;
44
47
  };
45
48
  //#endregion
46
49
  //#region src/wallet-standard-adapter.d.ts
47
50
  /**
48
- * Sui Wallet Standard has no "switch network" RPC, so `switchChain` moves
49
- * butr's view only and the wallet's own UI owns its cluster. Balance and
50
- * receipt reads need `@mysten/sui`'s `SuiClient`, which butr doesn't ship.
51
+ * Wallet Standard carries the chain per call, so `sendTx` and
52
+ * `signTransaction` route `options.chain` without moving the wallet. Balance
53
+ * and receipt reads need a `SuiClient`, which butr does not ship.
51
54
  */
52
55
  declare const buildSuiAdapter: (wallet: WalletStandardWallet,
53
- /** Optional. Called with a function that pushes a synthetic
54
- * `disconnected` event to all current subscribers. The discovery
55
- * layer invokes it on Wallet Standard `unregister`. */
56
- registerDisconnector?: (emit: () => void) => void) => WalletAdapter | null;
56
+ /** Discovery passes this so a Wallet Standard `unregister` tears down the
57
+ * connected pool entry. */
58
+ registerDisconnector?: (emit: () => void) => void) => SuiAdapter | null;
57
59
  /**
58
- * Requires the optional `@wallet-standard/app` peer dep.
60
+ * Requires the optional `@wallet-standard/app` peer dep; without it Sui
61
+ * discovery silently does nothing.
59
62
  * Spec: https://docs.sui.io/standards/wallet-standard
60
63
  */
61
- declare const discoverSuiAdapters: (onAdapter: (adapter: WalletAdapter) => void) => (() => void);
62
- //#endregion
63
- //#region src/chains.d.ts
64
- declare const SUI_CHAINS: {
65
- readonly devnet: {
66
- readonly id: "sui:devnet";
67
- readonly name: "Sui Devnet";
68
- readonly namespace: "sui";
69
- readonly reference: "devnet";
70
- };
71
- readonly localnet: {
72
- readonly id: "sui:localnet";
73
- readonly name: "Sui Localnet";
74
- readonly namespace: "sui";
75
- readonly reference: "localnet";
76
- };
77
- readonly mainnet: {
78
- readonly id: "sui:mainnet";
79
- readonly name: "Sui Mainnet";
80
- readonly namespace: "sui";
81
- readonly reference: "mainnet";
82
- };
83
- readonly testnet: {
84
- readonly id: "sui:testnet";
85
- readonly name: "Sui Testnet";
86
- readonly namespace: "sui";
87
- readonly reference: "testnet";
88
- };
89
- };
90
- declare const SUI_CHAINS_LIST: ReadonlyArray<ChainBase>;
91
- //#endregion
92
- //#region src/capabilities.d.ts
93
- type WalletStandardCapabilityInput = {
94
- chainCount: number;
95
- features: {
96
- events: boolean;
97
- signAndExecuteTransaction: boolean;
98
- signMessage: boolean;
99
- signTransaction: boolean;
100
- };
101
- };
102
- /**
103
- * `signIn` is false: Sui Wallet Standard has no Sign-In-With-Sui feature.
104
- * `signAndExecuteTransaction` means the wallet broadcasts, while
105
- * `signTransaction` is sign-only and leaves the broadcast to the consumer.
106
- */
107
- declare const resolveSuiCapabilities: (input: WalletStandardCapabilityInput) => WalletCapabilities;
64
+ declare const discoverSuiAdapters: (onAdapter: (adapter: WalletAdapter) => void, loadModule?: WalletStandardModuleLoader) => (() => void);
108
65
  //#endregion
109
66
  //#region src/discoverer.d.ts
110
67
  /**
@@ -113,16 +70,5 @@ declare const resolveSuiCapabilities: (input: WalletStandardCapabilityInput) =>
113
70
  */
114
71
  declare const suiDiscoverer: PlatformDiscoverer;
115
72
  //#endregion
116
- //#region src/signer-augmentation.d.ts
117
- /**
118
- * Sui's `getSigner()` hands back the Wallet Standard wallet, which consumers
119
- * narrow through its `features` map.
120
- */
121
- declare module "@usebutr/core" {
122
- interface SignerForPlatform {
123
- sui: WalletStandardWallet;
124
- }
125
- }
126
- //#endregion
127
- export { SUI_CHAINS, SUI_CHAINS_LIST, type SuiSignAndExecuteTransactionFeature, type SuiSignAndExecuteTransactionInput, type SuiSignAndExecuteTransactionOutput, type SuiSignPersonalMessageFeature, type SuiSignPersonalMessageInput, type SuiSignPersonalMessageOutput, type SuiSignTransactionFeature, type SuiSignTransactionInput, type SuiSignTransactionOutput, type WalletStandardCapabilityInput, buildSuiAdapter, discoverSuiAdapters, resolveSuiCapabilities, suiDiscoverer };
73
+ export { type SuiSignAndExecuteTransactionFeature, type SuiSignAndExecuteTransactionInput, type SuiSignAndExecuteTransactionOutput, type SuiSignPersonalMessageFeature, type SuiSignPersonalMessageInput, type SuiSignPersonalMessageOutput, type SuiSignTransactionFeature, type SuiSignTransactionInput, type SuiSignTransactionOutput, buildSuiAdapter, discoverSuiAdapters, suiDiscoverer };
128
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/wallet-standard-types.ts","../src/wallet-standard-adapter.ts","../src/chains.ts","../src/capabilities.ts","../src/discoverer.ts","../src/signer-augmentation.ts"],"mappings":";;;KAOK;EACH,SAAS;EACT,SAAS;;KAGN;EACH;EACA;;KAGG;EACH,sBACE,OAAO,gCACJ,QAAQ;;KAGV;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;;KAGG;EACH,kBAAkB,OAAO,4BAA4B,QAAQ;;KAG1D;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;EACA;EACA;;KAGG;EACH,4BACE,OAAO,sCACJ,QAAQ;;;;;;;;;cCPT,kBACJ,QAAQ,sBAIR;;;;AAAA,wBAAwB,8BACvB;;;;;cAqIG,sBAAuB,YAAY,SAAS;;;cCxL5C;;;;;;;;;;;;;;;;;;;;;;;;;;cAiBA,iBAAiB,cAAc;;;KChBhC;EACH;EACA;IACE;IACA;IACA;IACA;;;;;;;;cASE,yBAA0B,OAAO,kCAAgC;;;;;;;cCVjE,eAAe;;;;;;;;YCAT;IACR,KAAK"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/wallet-standard-types.ts","../src/wallet-standard-adapter.ts","../src/discoverer.ts"],"mappings":";;;KAOK;EACH,SAAS;EACT,SAAS;;KAGN;EACH;EACA;;KAGG;EACH,sBACE,OAAO,gCACJ,QAAQ;EACb;;KAGG;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;;KAGG;EACH,kBAAkB,OAAO,4BAA4B,QAAQ;EAC7D;;KAGG;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;EACA;EACA;;KAGG;EACH,4BACE,OAAO,sCACJ,QAAQ;EACb;;;;;;;;;cCdI,kBAAe,QACX,sBAGe;;;AAAA,wBAAC,8BACvB;;;;;;cA0EG,sBAAmB,YACX,SAAS,wBAAsB,aAC9B;;;;;;;cCpHT,eAAe"}
package/dist/index.js CHANGED
@@ -1,123 +1,65 @@
1
- import { base64ToBytes, bytesToBase64 } from "@usebutr/core";
2
- import { buildWalletCapabilities, createWalletStandardCore, discoverWalletStandard, getFeature, slugify } from "@usebutr/wallet-standard-shared";
1
+ import { SUI_CHAINS_LIST, base64ToBytes, bytesToBase64 } from "@usebutr/core";
2
+ import { createWalletStandardCore, discoverWalletStandard, getFeature, slugify } from "@usebutr/wallet-standard-shared";
3
3
 
4
- //#region src/capabilities.ts
4
+ //#region src/wallet-standard-adapter.ts
5
5
  /**
6
- * `signIn` is false: Sui Wallet Standard has no Sign-In-With-Sui feature.
7
- * `signAndExecuteTransaction` means the wallet broadcasts, while
8
- * `signTransaction` is sign-only and leaves the broadcast to the consumer.
6
+ * Sui wallets accept only the `toJSON()` form, so a JSON or base64 string and
7
+ * BCS bytes are wrapped. A `Transaction` passes through untouched: its
8
+ * `toJSON` reads `this`, which a copied method would lose.
9
9
  */
10
- const resolveSuiCapabilities = (input) => buildWalletCapabilities({
11
- chainCount: input.chainCount,
12
- events: input.features.events,
13
- sendTransaction: input.features.signAndExecuteTransaction,
14
- signIn: false,
15
- signMessage: input.features.signMessage,
16
- signTransaction: input.features.signTransaction
17
- });
18
-
19
- //#endregion
20
- //#region src/wallet-standard-adapter.ts
21
- const SUI_PREFIX = "sui:";
22
- const SUI_DECIMALS = 9;
23
- const SUI_MAINNET = "sui:mainnet";
24
- /** Coerce butr's `unknown` tx into the shape the Sui Wallet Standard features
25
- * expect: an object with `toJSON()` returning a Promise<string>. A raw string
26
- * or BCS byte array is wrapped, because wallets accept only the `toJSON()`
27
- * form and a bare string reaches them as a shape they cannot consume. */
28
10
  const coerceSuiTransaction = (tx) => {
29
11
  if (typeof tx === "string") return { toJSON: () => Promise.resolve(tx) };
30
12
  if (tx instanceof Uint8Array) {
31
13
  const encoded = bytesToBase64(tx);
32
14
  return { toJSON: () => Promise.resolve(encoded) };
33
15
  }
34
- if (typeof tx === "object" && tx !== null && "toJSON" in tx && typeof tx.toJSON === "function") return tx;
35
- throw new TypeError("Sui sendTx/signTransaction expects a @mysten/sui Transaction (with toJSON()), a base64-encoded string, or BCS bytes");
16
+ return tx;
36
17
  };
37
18
  /**
38
- * Sui Wallet Standard has no "switch network" RPC, so `switchChain` moves
39
- * butr's view only and the wallet's own UI owns its cluster. Balance and
40
- * receipt reads need `@mysten/sui`'s `SuiClient`, which butr doesn't ship.
19
+ * Wallet Standard carries the chain per call, so `sendTx` and
20
+ * `signTransaction` route `options.chain` without moving the wallet. Balance
21
+ * and receipt reads need a `SuiClient`, which butr does not ship.
41
22
  */
42
23
  const buildSuiAdapter = (wallet, registerDisconnector) => {
43
24
  const core = createWalletStandardCore({
44
- chainPrefix: SUI_PREFIX,
25
+ chains: SUI_CHAINS_LIST,
45
26
  id: slugify("sui", wallet.name),
46
27
  label: "Sui",
47
28
  namespace: "sui",
48
- platform: "Sui",
49
- preferredChainIds: [SUI_MAINNET],
29
+ preferredChainIds: ["sui:mainnet"],
50
30
  registerDisconnector,
51
31
  trackChainChanges: true,
52
32
  wallet
53
33
  });
54
34
  if (core === null) return null;
55
- const signMessage = getFeature(wallet, "sui:signPersonalMessage");
56
- const signAndExecute = getFeature(wallet, "sui:signAndExecuteTransaction");
57
- const signTx = getFeature(wallet, "sui:signTransaction");
58
- /** Resolve a caller-supplied target into a chain the wallet advertises,
59
- * accepting either a full CAIP-2 id (`sui:testnet`) or a bare reference. */
60
- const resolveTargetChain = (targetChainId) => {
61
- const candidate = targetChainId.startsWith(SUI_PREFIX) ? targetChainId : `${SUI_PREFIX}${targetChainId}`;
62
- if (!wallet.chains.includes(candidate)) throw new Error(`Wallet ${wallet.name} does not advertise chain "${candidate}". Available: ${wallet.chains.join(", ")}`);
63
- return candidate;
64
- };
65
- const executeTx = async (tx, account, chain) => {
66
- if (signAndExecute === void 0) throw new Error(`Wallet ${wallet.name} does not advertise sui:signAndExecuteTransaction`);
67
- const wsAccount = core.resolveAccount(account);
68
- const transaction = coerceSuiTransaction(tx);
69
- return (await signAndExecute.signAndExecuteTransaction({
70
- account: wsAccount,
71
- chain: chain ?? core.currentChainId(),
72
- transaction
73
- })).digest;
74
- };
35
+ const signAndExecute = getFeature(wallet, "sui:signAndExecuteTransaction", "signAndExecuteTransaction");
36
+ const signPersonalMessage = getFeature(wallet, "sui:signPersonalMessage", "signPersonalMessage");
37
+ const signTransaction = getFeature(wallet, "sui:signTransaction", "signTransaction");
75
38
  return {
76
- ...core,
77
- capabilities: resolveSuiCapabilities({
78
- chainCount: core.chainCount,
79
- features: {
80
- events: core.hasEvents,
81
- signAndExecuteTransaction: Boolean(signAndExecute),
82
- signMessage: Boolean(signMessage),
83
- signTransaction: Boolean(signTx)
84
- }
85
- }),
39
+ ...core.base,
86
40
  chainPlatform: "sui",
87
- getBalance: () => Promise.resolve({
88
- decimals: SUI_DECIMALS,
89
- formatted: "0",
90
- symbol: "SUI",
91
- value: 0n
92
- }),
93
- getTransactionReceipt: () => Promise.resolve({ status: "Pending" }),
94
- async requestAccounts() {
95
- await core.connect();
96
- },
97
- sendTx: (tx, account) => executeTx(tx, account),
98
- async sendTxToChain(tx, targetChainId, account, cb) {
99
- const target = resolveTargetChain(targetChainId);
100
- if (target !== core.currentChainId()) cb?.();
101
- return await executeTx(tx, account, target);
102
- },
103
- async signMessage(msg, account) {
104
- if (signMessage === void 0) throw new Error(`Wallet ${wallet.name} does not advertise sui:signPersonalMessage`);
105
- const output = await signMessage.signPersonalMessage({
106
- account: core.resolveAccount(account),
107
- message: msg
41
+ ...signAndExecute !== void 0 && { async sendTx(tx, options) {
42
+ return (await signAndExecute.signAndExecuteTransaction({
43
+ account: core.resolveAccount(options?.account),
44
+ chain: core.resolveChainId(options?.chain),
45
+ transaction: coerceSuiTransaction(tx)
46
+ })).digest;
47
+ } },
48
+ ...signPersonalMessage !== void 0 && { async signMessage(message, options) {
49
+ const output = await signPersonalMessage.signPersonalMessage({
50
+ account: core.resolveAccount(options?.account),
51
+ message
108
52
  });
109
53
  return {
110
54
  signature: base64ToBytes(output.signature),
111
55
  signedMessage: base64ToBytes(output.bytes)
112
56
  };
113
- },
114
- ...signTx === void 0 ? {} : { async signTransaction(tx, account) {
115
- const wsAccount = core.resolveAccount(account);
116
- const transaction = coerceSuiTransaction(tx);
117
- const output = await signTx.signTransaction({
118
- account: wsAccount,
119
- chain: core.currentChainId(),
120
- transaction
57
+ } },
58
+ ...signTransaction !== void 0 && { async signTransaction(tx, options) {
59
+ const output = await signTransaction.signTransaction({
60
+ account: core.resolveAccount(options?.account),
61
+ chain: core.resolveChainId(options?.chain),
62
+ transaction: coerceSuiTransaction(tx)
121
63
  });
122
64
  return {
123
65
  bytes: base64ToBytes(output.bytes),
@@ -127,40 +69,11 @@ const buildSuiAdapter = (wallet, registerDisconnector) => {
127
69
  };
128
70
  };
129
71
  /**
130
- * Requires the optional `@wallet-standard/app` peer dep.
72
+ * Requires the optional `@wallet-standard/app` peer dep; without it Sui
73
+ * discovery silently does nothing.
131
74
  * Spec: https://docs.sui.io/standards/wallet-standard
132
75
  */
133
- const discoverSuiAdapters = (onAdapter) => discoverWalletStandard(onAdapter, (wallet, registerDisconnector) => buildSuiAdapter(wallet, registerDisconnector));
134
-
135
- //#endregion
136
- //#region src/chains.ts
137
- const SUI_CHAINS = {
138
- devnet: {
139
- id: "sui:devnet",
140
- name: "Sui Devnet",
141
- namespace: "sui",
142
- reference: "devnet"
143
- },
144
- localnet: {
145
- id: "sui:localnet",
146
- name: "Sui Localnet",
147
- namespace: "sui",
148
- reference: "localnet"
149
- },
150
- mainnet: {
151
- id: "sui:mainnet",
152
- name: "Sui Mainnet",
153
- namespace: "sui",
154
- reference: "mainnet"
155
- },
156
- testnet: {
157
- id: "sui:testnet",
158
- name: "Sui Testnet",
159
- namespace: "sui",
160
- reference: "testnet"
161
- }
162
- };
163
- const SUI_CHAINS_LIST = Object.values(SUI_CHAINS);
76
+ const discoverSuiAdapters = (onAdapter, loadModule) => discoverWalletStandard(onAdapter, buildSuiAdapter, loadModule);
164
77
 
165
78
  //#endregion
166
79
  //#region src/discoverer.ts
@@ -171,5 +84,5 @@ const SUI_CHAINS_LIST = Object.values(SUI_CHAINS);
171
84
  const suiDiscoverer = { subscribe: discoverSuiAdapters };
172
85
 
173
86
  //#endregion
174
- export { SUI_CHAINS, SUI_CHAINS_LIST, buildSuiAdapter, discoverSuiAdapters, resolveSuiCapabilities, suiDiscoverer };
87
+ export { buildSuiAdapter, discoverSuiAdapters, suiDiscoverer };
175
88
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/capabilities.ts","../src/wallet-standard-adapter.ts","../src/chains.ts","../src/discoverer.ts"],"sourcesContent":["import type { WalletCapabilities } from \"@usebutr/core\";\nimport { buildWalletCapabilities } from \"@usebutr/wallet-standard-shared\";\n\ntype WalletStandardCapabilityInput = {\n chainCount: number;\n features: {\n events: boolean;\n signAndExecuteTransaction: boolean;\n signMessage: boolean;\n signTransaction: boolean;\n };\n};\n\n/**\n * `signIn` is false: Sui Wallet Standard has no Sign-In-With-Sui feature.\n * `signAndExecuteTransaction` means the wallet broadcasts, while\n * `signTransaction` is sign-only and leaves the broadcast to the consumer.\n */\nconst resolveSuiCapabilities = (input: WalletStandardCapabilityInput): WalletCapabilities =>\n buildWalletCapabilities({\n chainCount: input.chainCount,\n events: input.features.events,\n sendTransaction: input.features.signAndExecuteTransaction,\n signIn: false,\n signMessage: input.features.signMessage,\n signTransaction: input.features.signTransaction,\n });\n\nexport type { WalletStandardCapabilityInput };\nexport { resolveSuiCapabilities };\n","import type { WalletAdapter } from \"@usebutr/core\";\nimport { base64ToBytes, bytesToBase64 } from \"@usebutr/core\";\nimport {\n createWalletStandardCore,\n discoverWalletStandard,\n getFeature,\n slugify,\n} from \"@usebutr/wallet-standard-shared\";\nimport type { WalletStandardWallet } from \"@usebutr/wallet-standard-shared\";\n\nimport { resolveSuiCapabilities } from \"./capabilities\";\nimport type {\n SuiSignAndExecuteTransactionFeature,\n SuiSignPersonalMessageFeature,\n SuiSignTransactionFeature,\n} from \"./wallet-standard-types\";\n\nconst SUI_PREFIX = \"sui:\";\nconst SUI_DECIMALS = 9;\nconst SUI_MAINNET = \"sui:mainnet\";\n\n/** Coerce butr's `unknown` tx into the shape the Sui Wallet Standard features\n * expect: an object with `toJSON()` returning a Promise<string>. A raw string\n * or BCS byte array is wrapped, because wallets accept only the `toJSON()`\n * form and a bare string reaches them as a shape they cannot consume. */\nconst coerceSuiTransaction = (tx: unknown): { toJSON: () => Promise<string> } => {\n if (typeof tx === \"string\") {\n return { toJSON: () => Promise.resolve(tx) };\n }\n if (tx instanceof Uint8Array) {\n const encoded = bytesToBase64(tx);\n return { toJSON: () => Promise.resolve(encoded) };\n }\n if (typeof tx === \"object\" && tx !== null && \"toJSON\" in tx && typeof tx.toJSON === \"function\") {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- validated toJSON() above; @mysten/sui Transaction is otherwise untyped here\n return tx as { toJSON: () => Promise<string> };\n }\n throw new TypeError(\n \"Sui sendTx/signTransaction expects a @mysten/sui Transaction (with toJSON()), a base64-encoded string, or BCS bytes\",\n );\n};\n\n/**\n * Sui Wallet Standard has no \"switch network\" RPC, so `switchChain` moves\n * butr's view only and the wallet's own UI owns its cluster. Balance and\n * receipt reads need `@mysten/sui`'s `SuiClient`, which butr doesn't ship.\n */\nconst buildSuiAdapter = (\n wallet: WalletStandardWallet,\n /** Optional. Called with a function that pushes a synthetic\n * `disconnected` event to all current subscribers. The discovery\n * layer invokes it on Wallet Standard `unregister`. */\n registerDisconnector?: (emit: () => void) => void,\n): WalletAdapter | null => {\n const core = createWalletStandardCore({\n chainPrefix: SUI_PREFIX,\n id: slugify(\"sui\", wallet.name),\n label: \"Sui\",\n namespace: \"sui\",\n platform: \"Sui\",\n preferredChainIds: [SUI_MAINNET],\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signMessage = getFeature<SuiSignPersonalMessageFeature>(wallet, \"sui:signPersonalMessage\");\n const signAndExecute = getFeature<SuiSignAndExecuteTransactionFeature>(\n wallet,\n \"sui:signAndExecuteTransaction\",\n );\n const signTx = getFeature<SuiSignTransactionFeature>(wallet, \"sui:signTransaction\");\n\n /** Resolve a caller-supplied target into a chain the wallet advertises,\n * accepting either a full CAIP-2 id (`sui:testnet`) or a bare reference. */\n const resolveTargetChain = (targetChainId: string): string => {\n const candidate = targetChainId.startsWith(SUI_PREFIX)\n ? targetChainId\n : `${SUI_PREFIX}${targetChainId}`;\n if (!wallet.chains.includes(candidate)) {\n throw new Error(\n `Wallet ${wallet.name} does not advertise chain \"${candidate}\". Available: ${wallet.chains.join(\", \")}`,\n );\n }\n return candidate;\n };\n\n const executeTx = async (\n tx: unknown,\n account?: { walletAddress: string },\n chain?: string,\n ): Promise<string> => {\n if (signAndExecute === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise sui:signAndExecuteTransaction`);\n }\n const wsAccount = core.resolveAccount(account);\n const transaction = coerceSuiTransaction(tx);\n const output = await signAndExecute.signAndExecuteTransaction({\n account: wsAccount,\n chain: chain ?? core.currentChainId(),\n transaction,\n });\n return output.digest;\n };\n\n return {\n ...core,\n capabilities: resolveSuiCapabilities({\n chainCount: core.chainCount,\n features: {\n events: core.hasEvents,\n signAndExecuteTransaction: Boolean(signAndExecute),\n signMessage: Boolean(signMessage),\n signTransaction: Boolean(signTx),\n },\n }),\n chainPlatform: \"sui\",\n\n getBalance: () =>\n Promise.resolve({\n decimals: SUI_DECIMALS,\n formatted: \"0\",\n symbol: \"SUI\",\n value: 0n,\n }),\n\n getTransactionReceipt: () => Promise.resolve({ status: \"Pending\" as const }),\n\n async requestAccounts() {\n await core.connect();\n },\n\n sendTx: (tx, account) => executeTx(tx, account),\n\n // Async so an unadvertised chain surfaces as a rejection rather than a\n // synchronous throw; the declared return type is a promise either way.\n async sendTxToChain(tx, targetChainId, account, cb) {\n const target = resolveTargetChain(targetChainId);\n if (target !== core.currentChainId()) {\n cb?.();\n }\n const digest = await executeTx(tx, account, target);\n return digest;\n },\n\n async signMessage(msg, account) {\n if (signMessage === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise sui:signPersonalMessage`);\n }\n const output = await signMessage.signPersonalMessage({\n account: core.resolveAccount(account),\n message: msg,\n });\n return {\n signature: base64ToBytes(output.signature),\n signedMessage: base64ToBytes(output.bytes),\n };\n },\n\n ...(signTx === undefined\n ? {}\n : {\n async signTransaction(tx, account) {\n const wsAccount = core.resolveAccount(account);\n const transaction = coerceSuiTransaction(tx);\n const output = await signTx.signTransaction({\n account: wsAccount,\n chain: core.currentChainId(),\n transaction,\n });\n return {\n bytes: base64ToBytes(output.bytes),\n signature: base64ToBytes(output.signature),\n };\n },\n }),\n };\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep.\n * Spec: https://docs.sui.io/standards/wallet-standard\n */\nconst discoverSuiAdapters = (onAdapter: (adapter: WalletAdapter) => void): (() => void) =>\n discoverWalletStandard(onAdapter, (wallet, registerDisconnector) =>\n buildSuiAdapter(wallet, registerDisconnector),\n );\n\nexport { buildSuiAdapter, discoverSuiAdapters };\n","import type { ChainBase } from \"@usebutr/core\";\n\nconst SUI_CHAINS = {\n devnet: { id: \"sui:devnet\", name: \"Sui Devnet\", namespace: \"sui\", reference: \"devnet\" },\n localnet: {\n id: \"sui:localnet\",\n name: \"Sui Localnet\",\n namespace: \"sui\",\n reference: \"localnet\",\n },\n mainnet: {\n id: \"sui:mainnet\",\n name: \"Sui Mainnet\",\n namespace: \"sui\",\n reference: \"mainnet\",\n },\n testnet: { id: \"sui:testnet\", name: \"Sui Testnet\", namespace: \"sui\", reference: \"testnet\" },\n} as const satisfies Record<string, ChainBase>;\n\nconst SUI_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(SUI_CHAINS);\n\nexport { SUI_CHAINS, SUI_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSuiAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * Sui's `PlatformDiscoverer`: Sui Wallet Standard announcements. No\n * legacy fallback; Sui standardised on Wallet Standard from launch.\n */\nconst suiDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSuiAdapters,\n};\n\nexport { suiDiscoverer };\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/wallet-standard-adapter.ts","../src/discoverer.ts"],"sourcesContent":["import type { SuiAdapter, SuiTransactionInput, WalletAdapter } from \"@usebutr/core\";\nimport { base64ToBytes, bytesToBase64, SUI_CHAINS_LIST } from \"@usebutr/core\";\nimport {\n createWalletStandardCore,\n discoverWalletStandard,\n getFeature,\n slugify,\n} from \"@usebutr/wallet-standard-shared\";\nimport type {\n WalletStandardModuleLoader,\n WalletStandardWallet,\n} from \"@usebutr/wallet-standard-shared\";\n\nimport type {\n SuiSignAndExecuteTransactionFeature,\n SuiSignPersonalMessageFeature,\n SuiSignTransactionFeature,\n SuiSignTransactionInput,\n} from \"./wallet-standard-types\";\n\ntype WalletTransaction = SuiSignTransactionInput[\"transaction\"];\n\n/**\n * Sui wallets accept only the `toJSON()` form, so a JSON or base64 string and\n * BCS bytes are wrapped. A `Transaction` passes through untouched: its\n * `toJSON` reads `this`, which a copied method would lose.\n */\nconst coerceSuiTransaction = (tx: SuiTransactionInput): WalletTransaction => {\n if (typeof tx === \"string\") {\n return { toJSON: () => Promise.resolve(tx) };\n }\n if (tx instanceof Uint8Array) {\n const encoded = bytesToBase64(tx);\n return { toJSON: () => Promise.resolve(encoded) };\n }\n return tx;\n};\n\n/**\n * Wallet Standard carries the chain per call, so `sendTx` and\n * `signTransaction` route `options.chain` without moving the wallet. Balance\n * and receipt reads need a `SuiClient`, which butr does not ship.\n */\nconst buildSuiAdapter = (\n wallet: WalletStandardWallet,\n /** Discovery passes this so a Wallet Standard `unregister` tears down the\n * connected pool entry. */\n registerDisconnector?: (emit: () => void) => void,\n): SuiAdapter | null => {\n const core = createWalletStandardCore({\n chains: SUI_CHAINS_LIST,\n id: slugify(\"sui\", wallet.name),\n label: \"Sui\",\n namespace: \"sui\",\n preferredChainIds: [\"sui:mainnet\"],\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signAndExecute = getFeature<SuiSignAndExecuteTransactionFeature>(\n wallet,\n \"sui:signAndExecuteTransaction\",\n \"signAndExecuteTransaction\",\n );\n const signPersonalMessage = getFeature<SuiSignPersonalMessageFeature>(\n wallet,\n \"sui:signPersonalMessage\",\n \"signPersonalMessage\",\n );\n const signTransaction = getFeature<SuiSignTransactionFeature>(\n wallet,\n \"sui:signTransaction\",\n \"signTransaction\",\n );\n\n return {\n ...core.base,\n chainPlatform: \"sui\",\n ...(signAndExecute !== undefined && {\n async sendTx(tx, options) {\n const output = await signAndExecute.signAndExecuteTransaction({\n account: core.resolveAccount(options?.account),\n chain: core.resolveChainId(options?.chain),\n transaction: coerceSuiTransaction(tx),\n });\n return output.digest;\n },\n }),\n ...(signPersonalMessage !== undefined && {\n async signMessage(message, options) {\n const output = await signPersonalMessage.signPersonalMessage({\n account: core.resolveAccount(options?.account),\n message,\n });\n return {\n signature: base64ToBytes(output.signature),\n signedMessage: base64ToBytes(output.bytes),\n };\n },\n }),\n ...(signTransaction !== undefined && {\n async signTransaction(tx, options) {\n const output = await signTransaction.signTransaction({\n account: core.resolveAccount(options?.account),\n chain: core.resolveChainId(options?.chain),\n transaction: coerceSuiTransaction(tx),\n });\n return { bytes: base64ToBytes(output.bytes), signature: base64ToBytes(output.signature) };\n },\n }),\n };\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep; without it Sui\n * discovery silently does nothing.\n * Spec: https://docs.sui.io/standards/wallet-standard\n */\nconst discoverSuiAdapters = (\n onAdapter: (adapter: WalletAdapter) => void,\n loadModule?: WalletStandardModuleLoader,\n): (() => void) => discoverWalletStandard(onAdapter, buildSuiAdapter, loadModule);\n\nexport { buildSuiAdapter, discoverSuiAdapters };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSuiAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * Sui's `PlatformDiscoverer`: Sui Wallet Standard announcements. No\n * legacy fallback; Sui standardised on Wallet Standard from launch.\n */\nconst suiDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSuiAdapters,\n};\n\nexport { suiDiscoverer };\n"],"mappings":";;;;;;;;;AA2BA,MAAM,wBAAwB,OAA+C;CAC3E,IAAI,OAAO,OAAO,UAChB,OAAO,EAAE,cAAc,QAAQ,QAAQ,EAAE,EAAE;CAE7C,IAAI,cAAc,YAAY;EAC5B,MAAM,UAAU,cAAc,EAAE;EAChC,OAAO,EAAE,cAAc,QAAQ,QAAQ,OAAO,EAAE;CAClD;CACA,OAAO;AACT;;;;;;AAOA,MAAM,mBACJ,QAGA,yBACsB;CACtB,MAAM,OAAO,yBAAyB;EACpC,QAAQ;EACR,IAAI,QAAQ,OAAO,OAAO,IAAI;EAC9B,OAAO;EACP,WAAW;EACX,mBAAmB,CAAC,aAAa;EACjC;EACA,mBAAmB;EACnB;CACF,CAAC;CACD,IAAI,SAAS,MACX,OAAO;CAGT,MAAM,iBAAiB,WACrB,QACA,iCACA,2BACF;CACA,MAAM,sBAAsB,WAC1B,QACA,2BACA,qBACF;CACA,MAAM,kBAAkB,WACtB,QACA,uBACA,iBACF;CAEA,OAAO;EACL,GAAG,KAAK;EACR,eAAe;EACf,GAAI,mBAAmB,UAAa,EAClC,MAAM,OAAO,IAAI,SAAS;GAMxB,QAAO,MALc,eAAe,0BAA0B;IAC5D,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C,OAAO,KAAK,eAAe,SAAS,KAAK;IACzC,aAAa,qBAAqB,EAAE;GACtC,CAAC,EACY,CAAC;EAChB,EACF;EACA,GAAI,wBAAwB,UAAa,EACvC,MAAM,YAAY,SAAS,SAAS;GAClC,MAAM,SAAS,MAAM,oBAAoB,oBAAoB;IAC3D,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C;GACF,CAAC;GACD,OAAO;IACL,WAAW,cAAc,OAAO,SAAS;IACzC,eAAe,cAAc,OAAO,KAAK;GAC3C;EACF,EACF;EACA,GAAI,oBAAoB,UAAa,EACnC,MAAM,gBAAgB,IAAI,SAAS;GACjC,MAAM,SAAS,MAAM,gBAAgB,gBAAgB;IACnD,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C,OAAO,KAAK,eAAe,SAAS,KAAK;IACzC,aAAa,qBAAqB,EAAE;GACtC,CAAC;GACD,OAAO;IAAE,OAAO,cAAc,OAAO,KAAK;IAAG,WAAW,cAAc,OAAO,SAAS;GAAE;EAC1F,EACF;CACF;AACF;;;;;;AAOA,MAAM,uBACJ,WACA,eACiB,uBAAuB,WAAW,iBAAiB,UAAU;;;;;;;;ACrHhF,MAAM,gBAAoC,EACxC,WAAW,oBACb"}
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "@usebutr/sui",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Wallet Standard adapter for butr (Sui).",
5
+ "keywords": [
6
+ "butr",
7
+ "dapp",
8
+ "react",
9
+ "sui",
10
+ "typescript",
11
+ "wallet",
12
+ "wallet-standard",
13
+ "web3"
14
+ ],
15
+ "homepage": "https://docs.usebutr.com/api/sui",
16
+ "bugs": {
17
+ "url": "https://github.com/pedroapfilho/usebutr/issues"
18
+ },
5
19
  "license": "MIT",
6
20
  "author": "Pedro Filho <pedro@filho.me>",
7
21
  "repository": {
@@ -10,7 +24,8 @@
10
24
  "directory": "packages/sui"
11
25
  },
12
26
  "files": [
13
- "dist"
27
+ "dist",
28
+ "CHANGELOG.md"
14
29
  ],
15
30
  "type": "module",
16
31
  "sideEffects": false,
@@ -25,13 +40,13 @@
25
40
  "access": "public"
26
41
  },
27
42
  "dependencies": {
28
- "@usebutr/core": "2.0.0",
29
- "@usebutr/wallet-standard-shared": "0.5.0"
43
+ "@usebutr/core": "3.0.0",
44
+ "@usebutr/wallet-standard-shared": "2.0.0"
30
45
  },
31
46
  "devDependencies": {
32
47
  "@wallet-standard/app": "^1.1.1",
33
- "typescript": "^6.0.3",
34
- "vitest": "^4.1.10",
48
+ "typescript": "^7.0.2",
49
+ "vitest": "^5.0.0",
35
50
  "@repo/config-vitest": "0.0.0",
36
51
  "@repo/typescript-config": "0.0.0"
37
52
  },