@usebutr/svm 2.0.0 → 2.0.2

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,246 @@
1
+ # @usebutr/svm
2
+
3
+ ## 2.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`bc5b58c`](https://github.com/pedroapfilho/usebutr/commit/bc5b58cd87601be38dbb77a14e16eaaa36e8f012), [`bc5b58c`](https://github.com/pedroapfilho/usebutr/commit/bc5b58cd87601be38dbb77a14e16eaaa36e8f012)]:
8
+ - @usebutr/wallet-standard-shared@1.0.0
9
+ - @usebutr/core@2.0.1
10
+
11
+ ## 2.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [302ae4a]
16
+ - @usebutr/wallet-standard-shared@0.5.1
17
+
18
+ ## 2.0.0
19
+
20
+ ### Major Changes
21
+
22
+ - 9b1caa2: Correctness pass across the storage, hydration and connector layers. Several of
23
+ these change observable behaviour; the ones worth knowing about before upgrading:
24
+
25
+ **Breaking**
26
+
27
+ - `SuiWallet.signTransaction` now returns `{ bytes, signature }` instead of
28
+ `Uint8Array`. Sui's `executeTransactionBlock` needs both, and each connector
29
+ previously returned a different half, so the old value could not be broadcast
30
+ and a consumer could not tell which half they held. SVM and Bitcoin keep their
31
+ single-`Uint8Array` shape.
32
+ - `@usebutr/svm`'s `sendTx` returns the signature base58-encoded, matching the
33
+ WalletConnect namespace, the Ledger app, Solana explorers and
34
+ `getSignatureStatuses`. It previously returned base64.
35
+ - `@usebutr/sui`'s feature input types drop the `string` arm from
36
+ `transaction`; wallets only ever accepted the `toJSON()` form. Strings and BCS
37
+ bytes are now wrapped for you, so `sendTx` accepts strictly more than before.
38
+
39
+ **Behaviour fixes**
40
+
41
+ - `WalletStorage.setPool` and `removePoolEntry` could self-deadlock on a corrupt
42
+ pool payload, leaving `connectWallet` unresolved and every later pool write
43
+ jammed for the page's life. Both are fixed, and `readWalletSnapshot` now shares
44
+ one codec with `WalletStorage` so the server and client decodes cannot drift.
45
+ - A seeded (SSR) entry whose silent reconnect failed used to stay in the pool
46
+ backed by a placeholder connector forever, so `useSigner`/`useBalance`
47
+ reported an error and `useConnectionStatus` reported `"reconnecting"`
48
+ permanently. Those entries are now dropped.
49
+ - `useSigner` and `useBalance` stay `idle` for a wallet that is still
50
+ reconnecting instead of surfacing a placeholder rejection as `status: "error"`.
51
+ - `useConnectionStatus` lets a live `"connecting"`/`"error"` take precedence over
52
+ the derived `"reconnecting"`, so an in-flight attempt and a connection error
53
+ are no longer hidden. New `useIsReconnecting(connectorId?)` answers the
54
+ per-wallet question directly.
55
+ - A background restore no longer writes the connect-attempt status or steals
56
+ `activeConnectorId`, and a superseded `CONNECT_FAILED` no longer overwrites the
57
+ current attempt.
58
+ - An externally-disconnected connector is now torn down, not just dropped from
59
+ the pool, so a cached adapter is not reused while still holding a session.
60
+ - EVM: a malformed provider response is treated as absent rather than `""`, which
61
+ previously produced chain `eip155:0`, zero-length signatures, empty transaction
62
+ hashes and a confident `0 ETH`. `switchChain` gained the same-chain
63
+ short-circuit `sendTxToChain` already had.
64
+ - WalletConnect: accounts carry their own chain instead of all being stamped with
65
+ the active one, so a multi-chain session no longer returns a wrong-chain
66
+ address. One pairing now covers every configured namespace, the pairing URI
67
+ survives a reconnect, and concurrent connects share one pairing.
68
+ - Bitcoin: the sats-connect (Xverse) adapter honours `silent`, so a reload no
69
+ longer triggers an unsolicited approval prompt, and exposes the payment address
70
+ as its single account instead of also presenting the ordinals address as
71
+ spendable.
72
+ - Polkadot: the injected adapter actually delivers events to subscribers,
73
+ `switchChain` notifies like its Wallet Standard sibling, and chain resolution
74
+ prefers the mainnets rather than whatever the wallet listed first.
75
+ - Ledger: the device session is committed atomically, so a locked device no
76
+ longer leaves an open transport that reports itself connected, and concurrent
77
+ connects open one transport.
78
+ - SVM: `sendTxToChain` submits to the chain you asked for instead of the
79
+ adapter's current one, and rejects a chain the wallet does not advertise.
80
+ - `@usebutr/svm`'s `switchChain` capability now counts only `solana:` chains, so
81
+ a multi-namespace wallet no longer advertises a method that always throws.
82
+
83
+ **Testing**
84
+
85
+ - `createFakePersistence` is now the real `WalletStorage` over memory drivers
86
+ rather than a parallel implementation, so it inherits upsert semantics,
87
+ validation and JSON round-tripping. Two divergences are fixed as a result:
88
+ `setPool` upserts rather than replaces, and `clearAll` leaves the
89
+ user-disconnected flag alone.
90
+ - `createFakeConnectedWallet` rejects being given both an `adapter` and explicit
91
+ `addresses`/`accounts`, a combination whose halves could disagree.
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies [9b1caa2]
96
+ - @usebutr/wallet-standard-shared@0.5.0
97
+ - @usebutr/core@2.0.0
98
+
99
+ ## 1.0.1
100
+
101
+ ### Patch Changes
102
+
103
+ - 8ecaf89: Close five gaps that made multi-chain integration harder than it needed to be.
104
+
105
+ **Group wallets by platform without writing the loop yourself.**
106
+ `groupByPlatform(items, getPlatform)` in `@usebutr/core` buckets any list into
107
+ a `Map<ChainPlatform, T[]>` keyed in `CHAIN_PLATFORMS` order with empty
108
+ platforms omitted, and `@usebutr/react` adds
109
+ `useDiscoveredWalletsByPlatform()` / `useConnectedWalletsByPlatform()` on top.
110
+ A multi-chain wallet announces one adapter per platform, so every app hitting
111
+ more than one chain was writing this bucketing by hand.
112
+
113
+ **`autoDiscovery` takes an allowlist array, and says something when it's empty.**
114
+ `autoDiscovery(["evm", "svm"])` now works alongside the object form and reads
115
+ as the allowlist it is. An options value that enables no platforms logs a
116
+ warning instead of silently discovering nothing: a list built at runtime that
117
+ comes back empty was otherwise indistinguishable from "no wallets installed".
118
+ The bare `autoDiscovery()` everything-path is unchanged and stays silent.
119
+
120
+ **`createFakeConnectedWallet` in `@usebutr/testing`.** Builds the
121
+ `{ account, accounts, connector }` pool entry that UI tests actually render,
122
+ with accounts constructed through `buildAccount` so the `<chain>:<address>` id
123
+ format is never restated in a fixture. Defaults to the platform's mainnet chain
124
+ and a deterministic address; pass `adapter` to wrap a connector you already
125
+ built.
126
+
127
+ **The icon sanitization contract is now on the type.** `Connector.icon` is
128
+ already run through `sanitizeIcon` at discovery, so it is a trimmed non-empty
129
+ string or `undefined`, safe to hand to `next/image` with no second call and no
130
+ `icon !== ""` guard. `ConnectorMeta.icon` documents the opposite: it is
131
+ consumer-supplied and not sanitized.
132
+
133
+ **`createSignInFlow` in `@usebutr/core`.** Wraps the nonce, capability gate,
134
+ signature, base64 encoding, and verification handshake that every wallet-auth
135
+ app writes identically. Solana wallets advertising `solana:signIn` take the
136
+ SIWS path automatically. It deliberately does not define a message format: pass
137
+ `buildMessage` to match your backend. Also re-exports the SVM SIWS types
138
+ (`SolanaSignInFeature`, `SolanaSignInInput`, `SolanaSignInOutput`) from
139
+ `@usebutr/svm`, which were defined but not exported.
140
+
141
+ - Updated dependencies [8ecaf89]
142
+ - @usebutr/core@1.1.0
143
+ - @usebutr/wallet-standard-shared@0.4.1
144
+
145
+ ## 1.0.0
146
+
147
+ ### Major Changes
148
+
149
+ - 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.
150
+
151
+ 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.
152
+
153
+ - 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.
154
+
155
+ 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.
156
+
157
+ ### Patch Changes
158
+
159
+ - 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.
160
+ - 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.
161
+ - Updated dependencies [7887cf0]
162
+ - Updated dependencies [7887cf0]
163
+ - Updated dependencies [f0a5116]
164
+ - Updated dependencies [f0a5116]
165
+ - Updated dependencies [7887cf0]
166
+ - @usebutr/core@1.0.0
167
+ - @usebutr/wallet-standard-shared@0.4.0
168
+
169
+ ## 0.2.7
170
+
171
+ ### Patch Changes
172
+
173
+ - 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:`.
174
+ - Updated dependencies [efe4550]
175
+ - Updated dependencies [4467a5e]
176
+ - @usebutr/wallet-standard-shared@0.3.0
177
+ - @usebutr/core@0.5.0
178
+
179
+ ## 0.2.6
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [c1309ee]
184
+ - @usebutr/core@0.4.2
185
+ - @usebutr/wallet-standard-shared@0.2.6
186
+
187
+ ## 0.2.5
188
+
189
+ ### Patch Changes
190
+
191
+ - 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.
192
+ - Updated dependencies [937dfae]
193
+ - @usebutr/core@0.4.1
194
+ - @usebutr/wallet-standard-shared@0.2.5
195
+
196
+ ## 0.2.4
197
+
198
+ ### Patch Changes
199
+
200
+ - 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.
201
+ - Updated dependencies [b5322ae]
202
+ - Updated dependencies [d5f32c7]
203
+ - Updated dependencies [a46eecd]
204
+ - Updated dependencies [3f26776]
205
+ - @usebutr/core@0.4.0
206
+ - @usebutr/wallet-standard-shared@0.2.4
207
+
208
+ ## 0.2.3
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies [886ee1d]
213
+ - @usebutr/core@0.3.0
214
+ - @usebutr/wallet-standard-shared@0.2.3
215
+
216
+ ## 0.2.2
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies [db5d7e9]
221
+ - @usebutr/core@0.2.2
222
+ - @usebutr/wallet-standard-shared@0.2.2
223
+
224
+ ## 0.2.1
225
+
226
+ ### Patch Changes
227
+
228
+ - 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.
229
+ - Updated dependencies [f846e77]
230
+ - @usebutr/core@0.2.1
231
+ - @usebutr/wallet-standard-shared@0.2.1
232
+
233
+ ## 0.2.0
234
+
235
+ ### Minor Changes
236
+
237
+ - 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.
238
+
239
+ `@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.
240
+
241
+ ### Patch Changes
242
+
243
+ - Updated dependencies [b77a477]
244
+ - Updated dependencies [b77a477]
245
+ - @usebutr/core@0.2.0
246
+ - @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,39 @@
1
+ # @usebutr/svm
2
+
3
+ Wallet Standard adapter for butr (Solana / SVM).
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/svm zustand @wallet-standard/app
12
+ ```
13
+
14
+ React 18+ 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 { createWalletSource } from "@usebutr/core";
21
+ import { discoverSvmAdapters } from "@usebutr/svm";
22
+ import { WalletManagerProvider } from "@usebutr/react";
23
+
24
+ const discovery = createWalletSource(discoverSvmAdapters);
25
+ export const WalletProvider = ({ children }: { children: ReactNode }) => (
26
+ <WalletManagerProvider discovery={discovery}>{children}</WalletManagerProvider>
27
+ );
28
+ ```
29
+
30
+ ## Documentation
31
+
32
+ - [Package reference](https://docs.usebutr.com/api/svm)
33
+ - [Getting started](https://docs.usebutr.com/getting-started/quickstart)
34
+ - [Examples and source](https://github.com/pedroapfilho/usebutr)
35
+ - [Report an issue](https://github.com/pedroapfilho/usebutr/issues)
36
+
37
+ ## License
38
+
39
+ [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 { ChainBase, PlatformDiscoverer, SignInInput, WalletAdapter, WalletCapabilities } from "@usebutr/core";
2
+ import { WalletStandardFeature, WalletStandardModuleLoader, WalletStandardWallet, WalletStandardWalletAccount } from "@usebutr/wallet-standard-shared";
3
3
  //#region src/wallet-standard-types.d.ts
4
4
  type SolanaSignMessageInput = {
5
5
  account: WalletStandardWalletAccount;
@@ -11,6 +11,7 @@ type SolanaSignMessageOutput = {
11
11
  };
12
12
  type SolanaSignMessageFeature = {
13
13
  signMessage: (...inputs: ReadonlyArray<SolanaSignMessageInput>) => Promise<ReadonlyArray<SolanaSignMessageOutput>>;
14
+ version?: string;
14
15
  };
15
16
  type SolanaSignAndSendTransactionInput = {
16
17
  account: WalletStandardWalletAccount;
@@ -22,9 +23,21 @@ type SolanaSignAndSendTransactionOutput = {
22
23
  };
23
24
  type SolanaSignAndSendTransactionFeature = {
24
25
  signAndSendTransaction: (...inputs: ReadonlyArray<SolanaSignAndSendTransactionInput>) => Promise<ReadonlyArray<SolanaSignAndSendTransactionOutput>>;
26
+ version?: string;
25
27
  };
26
- /** SIWS message fields, all optional; the wallet fills defaults. */
27
- type SolanaSignInInput = Record<string, unknown>;
28
+ type SolanaSignTransactionInput = {
29
+ account: WalletStandardWalletAccount;
30
+ chain?: string;
31
+ transaction: Uint8Array;
32
+ };
33
+ type SolanaSignTransactionOutput = {
34
+ signedTransaction: Uint8Array;
35
+ };
36
+ type SolanaSignTransactionFeature = {
37
+ signTransaction: (...inputs: ReadonlyArray<SolanaSignTransactionInput>) => Promise<ReadonlyArray<SolanaSignTransactionOutput>>;
38
+ version?: string;
39
+ };
40
+ type SolanaSignInInput = SignInInput;
28
41
  type SolanaSignInOutput = {
29
42
  account: WalletStandardWalletAccount;
30
43
  signature: Uint8Array;
@@ -32,9 +45,14 @@ type SolanaSignInOutput = {
32
45
  };
33
46
  type SolanaSignInFeature = {
34
47
  signIn: (input?: SolanaSignInInput) => Promise<ReadonlyArray<SolanaSignInOutput>>;
48
+ version?: string;
35
49
  };
36
50
  //#endregion
37
51
  //#region src/wallet-standard-adapter.d.ts
52
+ declare const isSolanaSignMessageFeature: (feature: WalletStandardFeature) => feature is WalletStandardFeature & SolanaSignMessageFeature;
53
+ declare const isSolanaSignAndSendTransactionFeature: (feature: WalletStandardFeature) => feature is WalletStandardFeature & SolanaSignAndSendTransactionFeature;
54
+ declare const isSolanaSignTransactionFeature: (feature: WalletStandardFeature) => feature is WalletStandardFeature & SolanaSignTransactionFeature;
55
+ declare const isSolanaSignInFeature: (feature: WalletStandardFeature) => feature is WalletStandardFeature & SolanaSignInFeature;
38
56
  /**
39
57
  * Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's
40
58
  * view only, and `signAndSendTransaction` takes the chain per call.
@@ -51,7 +69,7 @@ registerDisconnector?: (emit: () => void) => void) => WalletAdapter | null;
51
69
  * discovery silently does nothing. The returned unsubscribe is safe to call
52
70
  * before the dynamic import has resolved.
53
71
  */
54
- declare const discoverSvmAdapters: (onAdapter: (adapter: WalletAdapter) => void) => (() => void);
72
+ declare const discoverSvmAdapters: (onAdapter: (adapter: WalletAdapter) => void, loadModule?: WalletStandardModuleLoader) => (() => void);
55
73
  //#endregion
56
74
  //#region src/chains.d.ts
57
75
  declare const SVM_CHAINS: {
@@ -112,5 +130,5 @@ declare module "@usebutr/core" {
112
130
  }
113
131
  }
114
132
  //#endregion
115
- export { SVM_CHAINS, SVM_CHAINS_LIST, type SolanaSignAndSendTransactionFeature, type SolanaSignAndSendTransactionInput, type SolanaSignAndSendTransactionOutput, type SolanaSignInFeature, type SolanaSignInInput, type SolanaSignInOutput, type SolanaSignMessageFeature, type SolanaSignMessageInput, type SolanaSignMessageOutput, type WalletStandardCapabilityInput, buildSvmAdapter, discoverSvmAdapters, resolveWalletStandardCapabilities, svmDiscoverer };
133
+ export { SVM_CHAINS, SVM_CHAINS_LIST, type SolanaSignAndSendTransactionFeature, type SolanaSignAndSendTransactionInput, type SolanaSignAndSendTransactionOutput, type SolanaSignInFeature, type SolanaSignInInput, type SolanaSignInOutput, type SolanaSignMessageFeature, type SolanaSignMessageInput, type SolanaSignMessageOutput, type WalletStandardCapabilityInput, buildSvmAdapter, discoverSvmAdapters, isSolanaSignAndSendTransactionFeature, isSolanaSignInFeature, isSolanaSignMessageFeature, isSolanaSignTransactionFeature, resolveWalletStandardCapabilities, svmDiscoverer };
116
134
  //# 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,WAAW;EACX,eAAe;;KAGZ;EACH,iBACK,QAAQ,cAAc,4BACtB,QAAQ,cAAc;;KAGxB;EACH,SAAS;EACT;EACA,aAAa;;KAGV;EACH,WAAW;;KAGR;EACH,4BACK,QAAQ,cAAc,uCACtB,QAAQ,cAAc;;;KAoBxB,oBAAoB;KAEpB;EACH,SAAS;EACT,WAAW;EACX,eAAe;;KAGZ;EACH,SAAS,QAAQ,sBAAsB,QAAQ,cAAc;;;;;;;;;cCtCzD,kBACJ,QAAQ,sBAKR;;;;;AAAA,wBAAwB,8BACvB;;;;;;cAsKG,sBAAuB,YAAY,SAAS;;;cCtM5C;;;;;;;;;;;;;;;;;;;;cAgBA,iBAAiB,cAAc;;;KCfhC;EACH;EACA;IACE;IACA;IACA;IACA;IACA;;;;;;;cAQE,oCACJ,OAAO,kCACN;;;;;;;cCZG,eAAe;;;;;;;;;YCCT;IACR,KAAK"}
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":";;;KAQK;EACH,SAAS;EACT,SAAS;;KAGN;EACH,WAAW;EACX,eAAe;;KAGZ;EACH,iBACK,QAAQ,cAAc,4BACtB,QAAQ,cAAc;EAC3B;;KAGG;EACH,SAAS;EACT;EACA,aAAa;;KAGV;EACH,WAAW;;KAGR;EACH,4BACK,QAAQ,cAAc,uCACtB,QAAQ,cAAc;EAC3B;;KAGG;EACH,SAAS;EACT;EACA,aAAa;;KAGV;EACH,mBAAmB;;KAGhB;EACH,qBACK,QAAQ,cAAc,gCACtB,QAAQ,cAAc;EAC3B;;KAGG,oBAAoB;KAEpB;EACH,SAAS;EACT,WAAW;EACX,eAAe;;KAGZ;EACH,SAAS,QAAQ,sBAAsB,QAAQ,cAAc;EAC7D;;;;cC3CI,6BAA0B,SACrB,0BACR,WAAW,wBAAwB;cAGhC,wCAAqC,SAChC,0BACR,WAAW,wBAAwB;cAGhC,iCAA8B,SACzB,0BACR,WAAW,wBAAwB;cAGhC,wBAAqB,SAChB,0BACR,WAAW,wBAAwB;;;;;;cAQhC,kBAAe,QACX,sBAKe;;;;;AAAA,wBAAC,8BACvB;;;;;;cA+JG,sBAAmB,YACX,SAAS,wBAAsB,aAC9B;;;cCzNT;;aACM;aAAqB;aAAuB;aAAqB;;;aAEzE;aACA;aACA;aACA;;;aAGA;aACA;aACA;aACA;;;cAIE,iBAAiB,cAAc;;;KCfhC;EACH;EACA;IACE;IACA;IACA;IACA;IACA;;;;;;;cAQE,oCAAiC,OAC9B,kCACN;;;;;;;cCZG,eAAe;;;;;;;;;YCCT;IACR,KAAK"}
package/dist/index.js CHANGED
@@ -20,6 +20,10 @@ const resolveWalletStandardCapabilities = (input) => buildWalletCapabilities({
20
20
  const SOLANA_PREFIX = "solana:";
21
21
  const SOLANA_DECIMALS = 9;
22
22
  const SOLANA_MAINNETS = ["solana:mainnet", "solana:mainnet-beta"];
23
+ const isSolanaSignMessageFeature = (feature) => "signMessage" in feature && typeof feature.signMessage === "function";
24
+ const isSolanaSignAndSendTransactionFeature = (feature) => "signAndSendTransaction" in feature && typeof feature.signAndSendTransaction === "function";
25
+ const isSolanaSignTransactionFeature = (feature) => "signTransaction" in feature && typeof feature.signTransaction === "function";
26
+ const isSolanaSignInFeature = (feature) => "signIn" in feature && typeof feature.signIn === "function";
23
27
  /**
24
28
  * Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's
25
29
  * view only, and `signAndSendTransaction` takes the chain per call.
@@ -38,10 +42,10 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
38
42
  wallet
39
43
  });
40
44
  if (core === null) return null;
41
- const signMessage = getFeature(wallet, "solana:signMessage");
42
- const signAndSendTx = getFeature(wallet, "solana:signAndSendTransaction");
43
- const signTx = getFeature(wallet, "solana:signTransaction");
44
- const signIn = getFeature(wallet, "solana:signIn");
45
+ const signMessage = getFeature(wallet, "solana:signMessage", isSolanaSignMessageFeature);
46
+ const signAndSendTx = getFeature(wallet, "solana:signAndSendTransaction", isSolanaSignAndSendTransactionFeature);
47
+ const signTx = getFeature(wallet, "solana:signTransaction", isSolanaSignTransactionFeature);
48
+ const signIn = getFeature(wallet, "solana:signIn", isSolanaSignInFeature);
45
49
  /**
46
50
  * Resolve a caller-supplied target into a chain the wallet advertises.
47
51
  * Accepts both the full CAIP-2 id (`solana:devnet`) and a bare reference
@@ -64,7 +68,7 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
64
68
  if (output === void 0) throw new Error("signAndSendTransaction returned no outputs");
65
69
  return bytesToBase58(output.signature);
66
70
  };
67
- return {
71
+ const adapter = {
68
72
  ...core,
69
73
  capabilities: resolveWalletStandardCapabilities({
70
74
  chainCount: core.chainCount,
@@ -104,35 +108,36 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
104
108
  signature: output.signature,
105
109
  signedMessage: output.signedMessage
106
110
  };
107
- },
108
- ...signTx === void 0 ? {} : { async signTransaction(tx, account) {
109
- const wsAccount = core.resolveAccount(account);
110
- if (!(tx instanceof Uint8Array)) throw new TypeError("SVM signTransaction expects a serialized transaction (Uint8Array)");
111
- const [output] = await signTx.signTransaction({
112
- account: wsAccount,
113
- chain: core.currentChainId(),
114
- transaction: tx
115
- });
116
- if (output === void 0) throw new Error("signTransaction returned no outputs");
117
- return output.signedTransaction;
118
- } },
119
- ...signIn === void 0 ? {} : { async signIn(input) {
120
- const [output] = await signIn.signIn(input);
121
- if (output === void 0) throw new Error("signIn returned no outputs");
122
- return {
123
- account: buildAccount(output.account.address, core.toChain()),
124
- signature: output.signature,
125
- signedMessage: output.signedMessage
126
- };
127
- } }
111
+ }
112
+ };
113
+ if (signTx !== void 0) adapter.signTransaction = async (tx, account) => {
114
+ const wsAccount = core.resolveAccount(account);
115
+ if (!(tx instanceof Uint8Array)) throw new TypeError("SVM signTransaction expects a serialized transaction (Uint8Array)");
116
+ const [output] = await signTx.signTransaction({
117
+ account: wsAccount,
118
+ chain: core.currentChainId(),
119
+ transaction: tx
120
+ });
121
+ if (output === void 0) throw new Error("signTransaction returned no outputs");
122
+ return output.signedTransaction;
123
+ };
124
+ if (signIn !== void 0) adapter.signIn = async (input) => {
125
+ const [output] = await signIn.signIn(input);
126
+ if (output === void 0) throw new Error("signIn returned no outputs");
127
+ return {
128
+ account: buildAccount(output.account.address, core.toChain()),
129
+ signature: output.signature,
130
+ signedMessage: output.signedMessage
131
+ };
128
132
  };
133
+ return adapter;
129
134
  };
130
135
  /**
131
136
  * Requires the optional `@wallet-standard/app` peer dep; without it SVM
132
137
  * discovery silently does nothing. The returned unsubscribe is safe to call
133
138
  * before the dynamic import has resolved.
134
139
  */
135
- const discoverSvmAdapters = (onAdapter) => discoverWalletStandard(onAdapter, (wallet, registerDisconnector) => buildSvmAdapter(wallet, registerDisconnector));
140
+ const discoverSvmAdapters = (onAdapter, loadModule) => discoverWalletStandard(onAdapter, (wallet, registerDisconnector) => buildSvmAdapter(wallet, registerDisconnector), loadModule);
136
141
 
137
142
  //#endregion
138
143
  //#region src/chains.ts
@@ -167,5 +172,5 @@ const SVM_CHAINS_LIST = Object.values(SVM_CHAINS);
167
172
  const svmDiscoverer = { subscribe: discoverSvmAdapters };
168
173
 
169
174
  //#endregion
170
- export { SVM_CHAINS, SVM_CHAINS_LIST, buildSvmAdapter, discoverSvmAdapters, resolveWalletStandardCapabilities, svmDiscoverer };
175
+ export { SVM_CHAINS, SVM_CHAINS_LIST, buildSvmAdapter, discoverSvmAdapters, isSolanaSignAndSendTransactionFeature, isSolanaSignInFeature, isSolanaSignMessageFeature, isSolanaSignTransactionFeature, resolveWalletStandardCapabilities, svmDiscoverer };
171
176
  //# 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 signAndSendTransaction: boolean;\n signIn: boolean;\n signMessage: boolean;\n signTransaction: boolean;\n };\n};\n\n/**\n * Solana Wallet Standard feature → butr capability mapping. The flags that\n * hold for every namespace are documented on `buildWalletCapabilities`.\n */\nconst resolveWalletStandardCapabilities = (\n input: WalletStandardCapabilityInput,\n): WalletCapabilities =>\n buildWalletCapabilities({\n chainCount: input.chainCount,\n events: input.features.events,\n sendTransaction: input.features.signAndSendTransaction,\n signIn: input.features.signIn,\n signMessage: input.features.signMessage,\n signTransaction: input.features.signTransaction,\n });\n\nexport type { WalletStandardCapabilityInput };\nexport { resolveWalletStandardCapabilities };\n","import type { WalletAdapter } from \"@usebutr/core\";\nimport { buildAccount, bytesToBase58 } 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 { resolveWalletStandardCapabilities } from \"./capabilities\";\nimport type {\n SolanaSignAndSendTransactionFeature,\n SolanaSignInFeature,\n SolanaSignMessageFeature,\n SolanaSignTransactionFeature,\n} from \"./wallet-standard-types\";\n\nconst SOLANA_PREFIX = \"solana:\";\nconst SOLANA_DECIMALS = 9;\nconst SOLANA_MAINNETS: ReadonlyArray<string> = [\"solana:mainnet\", \"solana:mainnet-beta\"];\n\n/**\n * Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's\n * view only, and `signAndSendTransaction` takes the chain per call.\n * `requestAccounts` re-runs `standard:connect`; some wallets answer silently.\n */\nconst buildSvmAdapter = (\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` so a connected\n * pool entry tears down when its extension is removed. */\n registerDisconnector?: (emit: () => void) => void,\n): WalletAdapter | null => {\n const core = createWalletStandardCore({\n chainPrefix: SOLANA_PREFIX,\n id: slugify(\"svm\", wallet.name),\n label: \"SVM\",\n namespace: \"solana\",\n platform: \"Solana\",\n preferredChainIds: SOLANA_MAINNETS,\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signMessage = getFeature<SolanaSignMessageFeature>(wallet, \"solana:signMessage\");\n const signAndSendTx = getFeature<SolanaSignAndSendTransactionFeature>(\n wallet,\n \"solana:signAndSendTransaction\",\n );\n const signTx = getFeature<SolanaSignTransactionFeature>(wallet, \"solana:signTransaction\");\n const signIn = getFeature<SolanaSignInFeature>(wallet, \"solana:signIn\");\n\n /**\n * Resolve a caller-supplied target into a chain the wallet advertises.\n * Accepts both the full CAIP-2 id (`solana:devnet`) and a bare reference\n * (`devnet`), since consumers reasonably reach for either.\n */\n const resolveTargetChain = (targetChainId: string): string => {\n const candidate = targetChainId.startsWith(SOLANA_PREFIX)\n ? targetChainId\n : `${SOLANA_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 signAndSend = async (\n tx: unknown,\n account?: { walletAddress: string },\n chain?: string,\n ): Promise<string> => {\n if (signAndSendTx === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise solana:signAndSendTransaction`);\n }\n const wsAccount = core.resolveAccount(account);\n if (!(tx instanceof Uint8Array)) {\n throw new TypeError(\"SVM sendTx expects a serialized transaction (Uint8Array)\");\n }\n const [output] = await signAndSendTx.signAndSendTransaction({\n account: wsAccount,\n chain: chain ?? core.currentChainId(),\n transaction: tx,\n });\n if (output === undefined) {\n throw new Error(\"signAndSendTransaction returned no outputs\");\n }\n // Base58 is the encoding every Solana explorer, `getSignatureStatuses`,\n // and the WalletConnect SVM namespace use for a transaction signature.\n return bytesToBase58(output.signature);\n };\n\n return {\n ...core,\n capabilities: resolveWalletStandardCapabilities({\n chainCount: core.chainCount,\n features: {\n events: core.hasEvents,\n signAndSendTransaction: Boolean(signAndSendTx),\n signIn: Boolean(signIn),\n signMessage: Boolean(signMessage),\n signTransaction: Boolean(signTx),\n },\n }),\n chainPlatform: \"svm\",\n\n getBalance: () =>\n Promise.resolve({\n decimals: SOLANA_DECIMALS,\n formatted: \"0\",\n symbol: \"SOL\",\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) => signAndSend(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 signature = await signAndSend(tx, account, target);\n return signature;\n },\n\n async signMessage(msg, account) {\n if (signMessage === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise solana:signMessage`);\n }\n const [output] = await signMessage.signMessage({\n account: core.resolveAccount(account),\n message: msg,\n });\n if (output === undefined) {\n throw new Error(\"signMessage returned no outputs\");\n }\n return { signature: output.signature, signedMessage: output.signedMessage };\n },\n\n ...(signTx === undefined\n ? {}\n : {\n async signTransaction(tx, account) {\n const wsAccount = core.resolveAccount(account);\n if (!(tx instanceof Uint8Array)) {\n throw new TypeError(\n \"SVM signTransaction expects a serialized transaction (Uint8Array)\",\n );\n }\n const [output] = await signTx.signTransaction({\n account: wsAccount,\n chain: core.currentChainId(),\n transaction: tx,\n });\n if (output === undefined) {\n throw new Error(\"signTransaction returned no outputs\");\n }\n return output.signedTransaction;\n },\n }),\n\n ...(signIn === undefined\n ? {}\n : {\n async signIn(input) {\n const [output] = await signIn.signIn(input);\n if (output === undefined) {\n throw new Error(\"signIn returned no outputs\");\n }\n return {\n account: buildAccount(output.account.address, core.toChain()),\n signature: output.signature,\n signedMessage: output.signedMessage,\n };\n },\n }),\n };\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep; without it SVM\n * discovery silently does nothing. The returned unsubscribe is safe to call\n * before the dynamic import has resolved.\n */\nconst discoverSvmAdapters = (onAdapter: (adapter: WalletAdapter) => void): (() => void) =>\n discoverWalletStandard(onAdapter, (wallet, registerDisconnector) =>\n buildSvmAdapter(wallet, registerDisconnector),\n );\n\nexport { buildSvmAdapter, discoverSvmAdapters };\n","import type { ChainBase } from \"@usebutr/core\";\n\nconst SVM_CHAINS = {\n devnet: { id: \"solana:devnet\", name: \"Solana Devnet\", namespace: \"solana\", reference: \"devnet\" },\n mainnet: {\n id: \"solana:mainnet\",\n name: \"Solana Mainnet\",\n namespace: \"solana\",\n reference: \"mainnet\",\n },\n testnet: {\n id: \"solana:testnet\",\n name: \"Solana Testnet\",\n namespace: \"solana\",\n reference: \"testnet\",\n },\n} as const satisfies Record<string, ChainBase>;\n\nconst SVM_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(SVM_CHAINS);\n\nexport { SVM_CHAINS, SVM_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSvmAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * No legacy fallback: Solana wallets standardised on Wallet Standard before\n * butr existed, so there's no `window.solana` injected path worth shimming.\n */\nconst svmDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSvmAdapters,\n};\n\nexport { svmDiscoverer };\n"],"mappings":";;;;;;;;AAkBA,MAAM,qCACJ,UAEA,wBAAwB;CACtB,YAAY,MAAM;CAClB,QAAQ,MAAM,SAAS;CACvB,iBAAiB,MAAM,SAAS;CAChC,QAAQ,MAAM,SAAS;CACvB,aAAa,MAAM,SAAS;CAC5B,iBAAiB,M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AAM,OAAO,OAAO;GAClB,MAAM,CAAC,UAAU,MAAM,OAAO,OAAO,KAAK;GAC1C,IAAI,WAAW,QACb,MAAM,IAAI,MAAM,4BAA4B;GAE9C,OAAO;IACL,SAAS,aAAa,OAAO,QAAQ,SAAS,KAAK,QAAQ,CAAC;IAC5D,WAAW,OAAO;IAClB,eAAe,OAAO;GACxB;EACF,EACF;CACN;AACF;;;;;;AAOA,MAAM,uBAAuB,cAC3B,uBAAuB,YAAY,QAAQ,yBACzC,gBAAgB,QAAQ,oBAAoB,CAC9C;;;;ACzMF,MAAM,aAAa;CACjB,QAAQ;EAAE,IAAI;EAAiB,MAAM;EAAiB,WAAW;EAAU,WAAW;CAAS;CAC/F,SAAS;EACP,IAAI;EACJ,MAAM;EACN,WAAW;EACX,WAAW;CACb;CACA,SAAS;EACP,IAAI;EACJ,MAAM;EACN,WAAW;EACX,WAAW;CACb;AACF;AAEA,MAAM,kBAA4C,OAAO,OAAO,UAAU;;;;;;;;ACV1E,MAAM,gBAAoC,EACxC,WAAW,oBACb"}
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 signAndSendTransaction: boolean;\n signIn: boolean;\n signMessage: boolean;\n signTransaction: boolean;\n };\n};\n\n/**\n * Solana Wallet Standard feature → butr capability mapping. The flags that\n * hold for every namespace are documented on `buildWalletCapabilities`.\n */\nconst resolveWalletStandardCapabilities = (\n input: WalletStandardCapabilityInput,\n): WalletCapabilities =>\n buildWalletCapabilities({\n chainCount: input.chainCount,\n events: input.features.events,\n sendTransaction: input.features.signAndSendTransaction,\n signIn: input.features.signIn,\n signMessage: input.features.signMessage,\n signTransaction: input.features.signTransaction,\n });\n\nexport type { WalletStandardCapabilityInput };\nexport { resolveWalletStandardCapabilities };\n","import type { TransactionInput, WalletAdapter } from \"@usebutr/core\";\nimport { buildAccount, bytesToBase58 } from \"@usebutr/core\";\nimport {\n createWalletStandardCore,\n discoverWalletStandard,\n getFeature,\n slugify,\n} from \"@usebutr/wallet-standard-shared\";\nimport type {\n WalletStandardFeature,\n WalletStandardModuleLoader,\n WalletStandardWallet,\n} from \"@usebutr/wallet-standard-shared\";\n\nimport { resolveWalletStandardCapabilities } from \"./capabilities\";\nimport type {\n SolanaSignAndSendTransactionFeature,\n SolanaSignInFeature,\n SolanaSignMessageFeature,\n SolanaSignTransactionFeature,\n} from \"./wallet-standard-types\";\n\nconst SOLANA_PREFIX = \"solana:\";\nconst SOLANA_DECIMALS = 9;\nconst SOLANA_MAINNETS: ReadonlyArray<string> = [\"solana:mainnet\", \"solana:mainnet-beta\"];\n\nconst isSolanaSignMessageFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SolanaSignMessageFeature =>\n \"signMessage\" in feature && typeof feature.signMessage === \"function\";\n\nconst isSolanaSignAndSendTransactionFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SolanaSignAndSendTransactionFeature =>\n \"signAndSendTransaction\" in feature && typeof feature.signAndSendTransaction === \"function\";\n\nconst isSolanaSignTransactionFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SolanaSignTransactionFeature =>\n \"signTransaction\" in feature && typeof feature.signTransaction === \"function\";\n\nconst isSolanaSignInFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SolanaSignInFeature =>\n \"signIn\" in feature && typeof feature.signIn === \"function\";\n\n/**\n * Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's\n * view only, and `signAndSendTransaction` takes the chain per call.\n * `requestAccounts` re-runs `standard:connect`; some wallets answer silently.\n */\nconst buildSvmAdapter = (\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` so a connected\n * pool entry tears down when its extension is removed. */\n registerDisconnector?: (emit: () => void) => void,\n): WalletAdapter | null => {\n const core = createWalletStandardCore({\n chainPrefix: SOLANA_PREFIX,\n id: slugify(\"svm\", wallet.name),\n label: \"SVM\",\n namespace: \"solana\",\n platform: \"Solana\",\n preferredChainIds: SOLANA_MAINNETS,\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signMessage = getFeature(wallet, \"solana:signMessage\", isSolanaSignMessageFeature);\n const signAndSendTx = getFeature(\n wallet,\n \"solana:signAndSendTransaction\",\n isSolanaSignAndSendTransactionFeature,\n );\n const signTx = getFeature(wallet, \"solana:signTransaction\", isSolanaSignTransactionFeature);\n const signIn = getFeature(wallet, \"solana:signIn\", isSolanaSignInFeature);\n\n /**\n * Resolve a caller-supplied target into a chain the wallet advertises.\n * Accepts both the full CAIP-2 id (`solana:devnet`) and a bare reference\n * (`devnet`), since consumers reasonably reach for either.\n */\n const resolveTargetChain = (targetChainId: string): string => {\n const candidate = targetChainId.startsWith(SOLANA_PREFIX)\n ? targetChainId\n : `${SOLANA_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 signAndSend = async (\n tx: TransactionInput,\n account?: { walletAddress: string },\n chain?: string,\n ): Promise<string> => {\n if (signAndSendTx === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise solana:signAndSendTransaction`);\n }\n const wsAccount = core.resolveAccount(account);\n if (!(tx instanceof Uint8Array)) {\n throw new TypeError(\"SVM sendTx expects a serialized transaction (Uint8Array)\");\n }\n const [output] = await signAndSendTx.signAndSendTransaction({\n account: wsAccount,\n chain: chain ?? core.currentChainId(),\n transaction: tx,\n });\n if (output === undefined) {\n throw new Error(\"signAndSendTransaction returned no outputs\");\n }\n return bytesToBase58(output.signature);\n };\n\n const adapter: WalletAdapter = {\n ...core,\n capabilities: resolveWalletStandardCapabilities({\n chainCount: core.chainCount,\n features: {\n events: core.hasEvents,\n signAndSendTransaction: Boolean(signAndSendTx),\n signIn: Boolean(signIn),\n signMessage: Boolean(signMessage),\n signTransaction: Boolean(signTx),\n },\n }),\n chainPlatform: \"svm\",\n\n getBalance: () =>\n Promise.resolve({\n decimals: SOLANA_DECIMALS,\n formatted: \"0\",\n symbol: \"SOL\",\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) => signAndSend(tx, account),\n\n async sendTxToChain(tx, targetChainId, account, cb) {\n const target = resolveTargetChain(targetChainId);\n if (target !== core.currentChainId()) {\n cb?.();\n }\n const signature = await signAndSend(tx, account, target);\n return signature;\n },\n\n async signMessage(msg, account) {\n if (signMessage === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise solana:signMessage`);\n }\n const [output] = await signMessage.signMessage({\n account: core.resolveAccount(account),\n message: msg,\n });\n if (output === undefined) {\n throw new Error(\"signMessage returned no outputs\");\n }\n return { signature: output.signature, signedMessage: output.signedMessage };\n },\n };\n\n if (signTx !== undefined) {\n adapter.signTransaction = async (tx, account) => {\n const wsAccount = core.resolveAccount(account);\n if (!(tx instanceof Uint8Array)) {\n throw new TypeError(\"SVM signTransaction expects a serialized transaction (Uint8Array)\");\n }\n const [output] = await signTx.signTransaction({\n account: wsAccount,\n chain: core.currentChainId(),\n transaction: tx,\n });\n if (output === undefined) {\n throw new Error(\"signTransaction returned no outputs\");\n }\n return output.signedTransaction;\n };\n }\n\n if (signIn !== undefined) {\n adapter.signIn = async (input) => {\n const [output] = await signIn.signIn(input);\n if (output === undefined) {\n throw new Error(\"signIn returned no outputs\");\n }\n return {\n account: buildAccount(output.account.address, core.toChain()),\n signature: output.signature,\n signedMessage: output.signedMessage,\n };\n };\n }\n\n return adapter;\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep; without it SVM\n * discovery silently does nothing. The returned unsubscribe is safe to call\n * before the dynamic import has resolved.\n */\nconst discoverSvmAdapters = (\n onAdapter: (adapter: WalletAdapter) => void,\n loadModule?: WalletStandardModuleLoader,\n): (() => void) =>\n discoverWalletStandard(\n onAdapter,\n (wallet, registerDisconnector) => buildSvmAdapter(wallet, registerDisconnector),\n loadModule,\n );\n\nexport {\n buildSvmAdapter,\n discoverSvmAdapters,\n isSolanaSignAndSendTransactionFeature,\n isSolanaSignInFeature,\n isSolanaSignMessageFeature,\n isSolanaSignTransactionFeature,\n};\n","import type { ChainBase } from \"@usebutr/core\";\n\nconst SVM_CHAINS = {\n devnet: { id: \"solana:devnet\", name: \"Solana Devnet\", namespace: \"solana\", reference: \"devnet\" },\n mainnet: {\n id: \"solana:mainnet\",\n name: \"Solana Mainnet\",\n namespace: \"solana\",\n reference: \"mainnet\",\n },\n testnet: {\n id: \"solana:testnet\",\n name: \"Solana Testnet\",\n namespace: \"solana\",\n reference: \"testnet\",\n },\n} as const satisfies Record<string, ChainBase>;\n\nconst SVM_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(SVM_CHAINS);\n\nexport { SVM_CHAINS, SVM_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSvmAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * No legacy fallback: Solana wallets standardised on Wallet Standard before\n * butr existed, so there's no `window.solana` injected path worth shimming.\n */\nconst svmDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSvmAdapters,\n};\n\nexport { svmDiscoverer };\n"],"mappings":";;;;;;;;AAkBA,MAAM,qCACJ,UAEA,wBAAwB;CACtB,YAAY,MAAM;CAClB,QAAQ,MAAM,SAAS;CACvB,iBAAiB,MAAM,SAAS;CAChC,QAAQ,MAAM,SAAS;CACvB,aAAa,MAAM,SAAS;CAC5B,iBAAiB,MAAM,SAAS;AAClC,CAAC;;;;ACN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aAClB,MAAM,IAAI,UAAU,mEAAmE;EAEzF,MAAM,CAAC,UAAU,MAAM,OAAO,gBAAgB;GAC5C,SAAS;GACT,OAAO,KAAK,eAAe;GAC3B,aAAa;EACf,CAAC;EACD,IAAI,WAAW,QACb,MAAM,IAAI,MAAM,qCAAqC;EAEvD,OAAO,OAAO;CAChB;CAGF,IAAI,WAAW,QACb,QAAQ,SAAS,OAAO,UAAU;EAChC,MAAM,CAAC,UAAU,MAAM,OAAO,OAAO,KAAK;EAC1C,IAAI,WAAW,QACb,MAAM,IAAI,MAAM,4BAA4B;EAE9C,OAAO;GACL,SAAS,aAAa,OAAO,QAAQ,SAAS,KAAK,QAAQ,CAAC;GAC5D,WAAW,OAAO;GAClB,eAAe,OAAO;EACxB;CACF;CAGF,OAAO;AACT;;;;;;AAOA,MAAM,uBACJ,WACA,eAEA,uBACE,YACC,QAAQ,yBAAyB,gBAAgB,QAAQ,oBAAoB,GAC9E,UACF;;;;AC/NF,MAAM,aAAa;CACjB,QAAQ;EAAE,IAAI;EAAiB,MAAM;EAAiB,WAAW;EAAU,WAAW;CAAS;CAC/F,SAAS;EACP,IAAI;EACJ,MAAM;EACN,WAAW;EACX,WAAW;CACb;CACA,SAAS;EACP,IAAI;EACJ,MAAM;EACN,WAAW;EACX,WAAW;CACb;AACF;AAEA,MAAM,kBAA4C,OAAO,OAAO,UAAU;;;;;;;;ACV1E,MAAM,gBAAoC,EACxC,WAAW,oBACb"}
package/package.json CHANGED
@@ -1,7 +1,22 @@
1
1
  {
2
2
  "name": "@usebutr/svm",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Wallet Standard adapter for butr (Solana / SVM).",
5
+ "keywords": [
6
+ "butr",
7
+ "dapp",
8
+ "phantom",
9
+ "react",
10
+ "solana",
11
+ "typescript",
12
+ "wallet",
13
+ "wallet-standard",
14
+ "web3"
15
+ ],
16
+ "homepage": "https://docs.usebutr.com/api/svm",
17
+ "bugs": {
18
+ "url": "https://github.com/pedroapfilho/usebutr/issues"
19
+ },
5
20
  "license": "MIT",
6
21
  "author": "Pedro Filho <pedro@filho.me>",
7
22
  "repository": {
@@ -10,7 +25,8 @@
10
25
  "directory": "packages/svm"
11
26
  },
12
27
  "files": [
13
- "dist"
28
+ "dist",
29
+ "CHANGELOG.md"
14
30
  ],
15
31
  "type": "module",
16
32
  "sideEffects": false,
@@ -25,12 +41,12 @@
25
41
  "access": "public"
26
42
  },
27
43
  "dependencies": {
28
- "@usebutr/core": "2.0.0",
29
- "@usebutr/wallet-standard-shared": "0.5.0"
44
+ "@usebutr/core": "2.0.1",
45
+ "@usebutr/wallet-standard-shared": "1.0.0"
30
46
  },
31
47
  "devDependencies": {
32
48
  "@wallet-standard/app": "^1.1.1",
33
- "typescript": "^6.0.3",
49
+ "typescript": "^7.0.2",
34
50
  "vitest": "^4.1.10",
35
51
  "@repo/config-vitest": "0.0.0",
36
52
  "@repo/typescript-config": "0.0.0"