@usebutr/svm 1.0.1 → 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 +246 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/index.d.ts +31 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -95
- package/dist/index.js.map +1 -1
- package/package.json +21 -6
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
|
-
|
|
27
|
-
|
|
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,48 +45,18 @@ 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
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* for butr to do anything useful with it.
|
|
43
|
-
*
|
|
44
|
-
* **Capability gating**
|
|
45
|
-
*
|
|
46
|
-
* - `signMessage` is only present if the wallet advertises
|
|
47
|
-
* `solana:signMessage`. Without it, calling `adapter.signMessage`
|
|
48
|
-
* rejects with a clear error.
|
|
49
|
-
* - `sendTx` / `sendTxToChain` use `solana:signAndSendTransaction`.
|
|
50
|
-
* Without it, those methods reject.
|
|
51
|
-
* - `subscribe` is wired through `standard:events`. Wallets that
|
|
52
|
-
* don't expose events get a no-op unsubscribe.
|
|
53
|
-
*
|
|
54
|
-
* **Known limitations**
|
|
55
|
-
*
|
|
56
|
-
* - `getBalance` returns `{ value: 0n, formatted: "0", … }`. Solana
|
|
57
|
-
* balance reads require an RPC connection that's outside butr's
|
|
58
|
-
* scope; consumers wrap their own RPC client.
|
|
59
|
-
* - `getTransactionReceipt` returns `{ status: "Pending" }`. Same
|
|
60
|
-
* reason; needs an RPC.
|
|
61
|
-
* - `switchChain` updates butr's view of the current Solana cluster
|
|
62
|
-
* locally and routes subsequent `signAndSendTransaction` calls
|
|
63
|
-
* through the new chain. Wallet Standard has no "tell the wallet
|
|
64
|
-
* to switch cluster" RPC; the wallet's own UI controls its global
|
|
65
|
-
* cluster setting, and `signAndSendTransaction` accepts the chain
|
|
66
|
-
* per-call. The chain must be one the wallet advertises in
|
|
67
|
-
* `wallet.chains`; otherwise the call rejects.
|
|
68
|
-
* - `requestAccounts` re-runs `standard:connect`. Some wallets show
|
|
69
|
-
* their account picker again; others (those that "remember"
|
|
70
|
-
* authorisations) silently return the existing accounts. butr
|
|
71
|
-
* refreshes the pool entry's `accounts` array either way.
|
|
72
|
-
* - `switchAccount` is intentionally unimplemented. Wallet Standard
|
|
73
|
-
* has no silent "use address X" feature; the user picks the active
|
|
74
|
-
* account through the wallet's own UI. `signAndSendTransaction`
|
|
75
|
-
* accepts an `account` input, so consumers needing per-tx address
|
|
76
|
-
* selection can pick one from `accounts` at call time.
|
|
57
|
+
* Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's
|
|
58
|
+
* view only, and `signAndSendTransaction` takes the chain per call.
|
|
59
|
+
* `requestAccounts` re-runs `standard:connect`; some wallets answer silently.
|
|
77
60
|
*/
|
|
78
61
|
declare const buildSvmAdapter: (wallet: WalletStandardWallet,
|
|
79
62
|
/** Optional. Called with a function that pushes a synthetic
|
|
@@ -82,26 +65,11 @@ declare const buildSvmAdapter: (wallet: WalletStandardWallet,
|
|
|
82
65
|
* pool entry tears down when its extension is removed. */
|
|
83
66
|
registerDisconnector?: (emit: () => void) => void) => WalletAdapter | null;
|
|
84
67
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Runtime requires the `@wallet-standard/app` package, which is an
|
|
89
|
-
* **optional peer dependency** of butr. EVM-only consumers don't need
|
|
90
|
-
* to install it; discovery will silently skip the SVM side if the
|
|
91
|
-
* module isn't resolvable.
|
|
92
|
-
*
|
|
93
|
-
* Install for SVM auto-discovery:
|
|
94
|
-
*
|
|
95
|
-
* npm install @wallet-standard/app
|
|
96
|
-
*
|
|
97
|
-
* The function returns a synchronous unsubscribe that's safe to call
|
|
68
|
+
* Requires the optional `@wallet-standard/app` peer dep; without it SVM
|
|
69
|
+
* discovery silently does nothing. The returned unsubscribe is safe to call
|
|
98
70
|
* before the dynamic import has resolved.
|
|
99
|
-
*
|
|
100
|
-
* Implementation: the discovery loop (dynamic import, dedupe, register
|
|
101
|
-
* / unregister bridge) lives in `@usebutr/wallet-standard-shared`. This
|
|
102
|
-
* file's only job is to hand the kit a per-wallet builder.
|
|
103
71
|
*/
|
|
104
|
-
declare const discoverSvmAdapters: (onAdapter: (adapter: WalletAdapter) => void) => (() => void);
|
|
72
|
+
declare const discoverSvmAdapters: (onAdapter: (adapter: WalletAdapter) => void, loadModule?: WalletStandardModuleLoader) => (() => void);
|
|
105
73
|
//#endregion
|
|
106
74
|
//#region src/chains.d.ts
|
|
107
75
|
declare const SVM_CHAINS: {
|
|
@@ -145,10 +113,8 @@ declare const resolveWalletStandardCapabilities: (input: WalletStandardCapabilit
|
|
|
145
113
|
//#endregion
|
|
146
114
|
//#region src/discoverer.d.ts
|
|
147
115
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* before butr existed, so there's no `window.solana` injected path
|
|
151
|
-
* worth shimming.
|
|
116
|
+
* No legacy fallback: Solana wallets standardised on Wallet Standard before
|
|
117
|
+
* butr existed, so there's no `window.solana` injected path worth shimming.
|
|
152
118
|
*/
|
|
153
119
|
declare const svmDiscoverer: PlatformDiscoverer;
|
|
154
120
|
//#endregion
|
|
@@ -164,5 +130,5 @@ declare module "@usebutr/core" {
|
|
|
164
130
|
}
|
|
165
131
|
}
|
|
166
132
|
//#endregion
|
|
167
|
-
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 };
|
|
168
134
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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":";;;
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildAccount,
|
|
1
|
+
import { buildAccount, bytesToBase58 } from "@usebutr/core";
|
|
2
2
|
import { buildWalletCapabilities, createWalletStandardCore, discoverWalletStandard, getFeature, slugify } from "@usebutr/wallet-standard-shared";
|
|
3
3
|
|
|
4
4
|
//#region src/capabilities.ts
|
|
@@ -20,45 +20,14 @@ 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
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* for butr to do anything useful with it.
|
|
28
|
-
*
|
|
29
|
-
* **Capability gating**
|
|
30
|
-
*
|
|
31
|
-
* - `signMessage` is only present if the wallet advertises
|
|
32
|
-
* `solana:signMessage`. Without it, calling `adapter.signMessage`
|
|
33
|
-
* rejects with a clear error.
|
|
34
|
-
* - `sendTx` / `sendTxToChain` use `solana:signAndSendTransaction`.
|
|
35
|
-
* Without it, those methods reject.
|
|
36
|
-
* - `subscribe` is wired through `standard:events`. Wallets that
|
|
37
|
-
* don't expose events get a no-op unsubscribe.
|
|
38
|
-
*
|
|
39
|
-
* **Known limitations**
|
|
40
|
-
*
|
|
41
|
-
* - `getBalance` returns `{ value: 0n, formatted: "0", … }`. Solana
|
|
42
|
-
* balance reads require an RPC connection that's outside butr's
|
|
43
|
-
* scope; consumers wrap their own RPC client.
|
|
44
|
-
* - `getTransactionReceipt` returns `{ status: "Pending" }`. Same
|
|
45
|
-
* reason; needs an RPC.
|
|
46
|
-
* - `switchChain` updates butr's view of the current Solana cluster
|
|
47
|
-
* locally and routes subsequent `signAndSendTransaction` calls
|
|
48
|
-
* through the new chain. Wallet Standard has no "tell the wallet
|
|
49
|
-
* to switch cluster" RPC; the wallet's own UI controls its global
|
|
50
|
-
* cluster setting, and `signAndSendTransaction` accepts the chain
|
|
51
|
-
* per-call. The chain must be one the wallet advertises in
|
|
52
|
-
* `wallet.chains`; otherwise the call rejects.
|
|
53
|
-
* - `requestAccounts` re-runs `standard:connect`. Some wallets show
|
|
54
|
-
* their account picker again; others (those that "remember"
|
|
55
|
-
* authorisations) silently return the existing accounts. butr
|
|
56
|
-
* refreshes the pool entry's `accounts` array either way.
|
|
57
|
-
* - `switchAccount` is intentionally unimplemented. Wallet Standard
|
|
58
|
-
* has no silent "use address X" feature; the user picks the active
|
|
59
|
-
* account through the wallet's own UI. `signAndSendTransaction`
|
|
60
|
-
* accepts an `account` input, so consumers needing per-tx address
|
|
61
|
-
* selection can pick one from `accounts` at call time.
|
|
28
|
+
* Wallet Standard has no switch-cluster RPC: `switchChain` re-points butr's
|
|
29
|
+
* view only, and `signAndSendTransaction` takes the chain per call.
|
|
30
|
+
* `requestAccounts` re-runs `standard:connect`; some wallets answer silently.
|
|
62
31
|
*/
|
|
63
32
|
const buildSvmAdapter = (wallet, registerDisconnector) => {
|
|
64
33
|
const core = createWalletStandardCore({
|
|
@@ -73,26 +42,36 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
|
|
|
73
42
|
wallet
|
|
74
43
|
});
|
|
75
44
|
if (core === null) return null;
|
|
76
|
-
const signMessage = getFeature(wallet, "solana:signMessage");
|
|
77
|
-
const signAndSendTx = getFeature(wallet, "solana:signAndSendTransaction");
|
|
78
|
-
const signTx = getFeature(wallet, "solana:signTransaction");
|
|
79
|
-
const signIn = getFeature(wallet, "solana:signIn");
|
|
80
|
-
|
|
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);
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a caller-supplied target into a chain the wallet advertises.
|
|
51
|
+
* Accepts both the full CAIP-2 id (`solana:devnet`) and a bare reference
|
|
52
|
+
* (`devnet`), since consumers reasonably reach for either.
|
|
53
|
+
*/
|
|
54
|
+
const resolveTargetChain = (targetChainId) => {
|
|
55
|
+
const candidate = targetChainId.startsWith(SOLANA_PREFIX) ? targetChainId : `${SOLANA_PREFIX}${targetChainId}`;
|
|
56
|
+
if (!wallet.chains.includes(candidate)) throw new Error(`Wallet ${wallet.name} does not advertise chain "${candidate}". Available: ${wallet.chains.join(", ")}`);
|
|
57
|
+
return candidate;
|
|
58
|
+
};
|
|
59
|
+
const signAndSend = async (tx, account, chain) => {
|
|
81
60
|
if (signAndSendTx === void 0) throw new Error(`Wallet ${wallet.name} does not advertise solana:signAndSendTransaction`);
|
|
82
61
|
const wsAccount = core.resolveAccount(account);
|
|
83
62
|
if (!(tx instanceof Uint8Array)) throw new TypeError("SVM sendTx expects a serialized transaction (Uint8Array)");
|
|
84
63
|
const [output] = await signAndSendTx.signAndSendTransaction({
|
|
85
64
|
account: wsAccount,
|
|
86
|
-
chain: core.currentChainId(),
|
|
65
|
+
chain: chain ?? core.currentChainId(),
|
|
87
66
|
transaction: tx
|
|
88
67
|
});
|
|
89
68
|
if (output === void 0) throw new Error("signAndSendTransaction returned no outputs");
|
|
90
|
-
return
|
|
69
|
+
return bytesToBase58(output.signature);
|
|
91
70
|
};
|
|
92
|
-
|
|
71
|
+
const adapter = {
|
|
93
72
|
...core,
|
|
94
73
|
capabilities: resolveWalletStandardCapabilities({
|
|
95
|
-
chainCount:
|
|
74
|
+
chainCount: core.chainCount,
|
|
96
75
|
features: {
|
|
97
76
|
events: core.hasEvents,
|
|
98
77
|
signAndSendTransaction: Boolean(signAndSendTx),
|
|
@@ -113,9 +92,10 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
|
|
|
113
92
|
await core.connect();
|
|
114
93
|
},
|
|
115
94
|
sendTx: (tx, account) => signAndSend(tx, account),
|
|
116
|
-
sendTxToChain
|
|
117
|
-
|
|
118
|
-
|
|
95
|
+
async sendTxToChain(tx, targetChainId, account, cb) {
|
|
96
|
+
const target = resolveTargetChain(targetChainId);
|
|
97
|
+
if (target !== core.currentChainId()) cb?.();
|
|
98
|
+
return await signAndSend(tx, account, target);
|
|
119
99
|
},
|
|
120
100
|
async signMessage(msg, account) {
|
|
121
101
|
if (signMessage === void 0) throw new Error(`Wallet ${wallet.name} does not advertise solana:signMessage`);
|
|
@@ -128,50 +108,36 @@ const buildSvmAdapter = (wallet, registerDisconnector) => {
|
|
|
128
108
|
signature: output.signature,
|
|
129
109
|
signedMessage: output.signedMessage
|
|
130
110
|
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
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
|
+
};
|
|
152
132
|
};
|
|
133
|
+
return adapter;
|
|
153
134
|
};
|
|
154
135
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* Runtime requires the `@wallet-standard/app` package, which is an
|
|
159
|
-
* **optional peer dependency** of butr. EVM-only consumers don't need
|
|
160
|
-
* to install it; discovery will silently skip the SVM side if the
|
|
161
|
-
* module isn't resolvable.
|
|
162
|
-
*
|
|
163
|
-
* Install for SVM auto-discovery:
|
|
164
|
-
*
|
|
165
|
-
* npm install @wallet-standard/app
|
|
166
|
-
*
|
|
167
|
-
* The function returns a synchronous unsubscribe that's safe to call
|
|
136
|
+
* Requires the optional `@wallet-standard/app` peer dep; without it SVM
|
|
137
|
+
* discovery silently does nothing. The returned unsubscribe is safe to call
|
|
168
138
|
* before the dynamic import has resolved.
|
|
169
|
-
*
|
|
170
|
-
* Implementation: the discovery loop (dynamic import, dedupe, register
|
|
171
|
-
* / unregister bridge) lives in `@usebutr/wallet-standard-shared`. This
|
|
172
|
-
* file's only job is to hand the kit a per-wallet builder.
|
|
173
139
|
*/
|
|
174
|
-
const discoverSvmAdapters = (onAdapter) => discoverWalletStandard(onAdapter, (wallet, registerDisconnector) => buildSvmAdapter(wallet, registerDisconnector));
|
|
140
|
+
const discoverSvmAdapters = (onAdapter, loadModule) => discoverWalletStandard(onAdapter, (wallet, registerDisconnector) => buildSvmAdapter(wallet, registerDisconnector), loadModule);
|
|
175
141
|
|
|
176
142
|
//#endregion
|
|
177
143
|
//#region src/chains.ts
|
|
@@ -200,13 +166,11 @@ const SVM_CHAINS_LIST = Object.values(SVM_CHAINS);
|
|
|
200
166
|
//#endregion
|
|
201
167
|
//#region src/discoverer.ts
|
|
202
168
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* before butr existed, so there's no `window.solana` injected path
|
|
206
|
-
* worth shimming.
|
|
169
|
+
* No legacy fallback: Solana wallets standardised on Wallet Standard before
|
|
170
|
+
* butr existed, so there's no `window.solana` injected path worth shimming.
|
|
207
171
|
*/
|
|
208
172
|
const svmDiscoverer = { subscribe: discoverSvmAdapters };
|
|
209
173
|
|
|
210
174
|
//#endregion
|
|
211
|
-
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 };
|
|
212
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, 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 { 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 * Adapt a Solana Wallet Standard `Wallet` object into a butr\n * `WalletAdapter`. Returns `null` if the wallet doesn't advertise any\n * Solana chain or doesn't expose `standard:connect`; both required\n * for butr to do anything useful with it.\n *\n * **Capability gating**\n *\n * - `signMessage` is only present if the wallet advertises\n * `solana:signMessage`. Without it, calling `adapter.signMessage`\n * rejects with a clear error.\n * - `sendTx` / `sendTxToChain` use `solana:signAndSendTransaction`.\n * Without it, those methods reject.\n * - `subscribe` is wired through `standard:events`. Wallets that\n * don't expose events get a no-op unsubscribe.\n *\n * **Known limitations**\n *\n * - `getBalance` returns `{ value: 0n, formatted: \"0\", … }`. Solana\n * balance reads require an RPC connection that's outside butr's\n * scope; consumers wrap their own RPC client.\n * - `getTransactionReceipt` returns `{ status: \"Pending\" }`. Same\n * reason; needs an RPC.\n * - `switchChain` updates butr's view of the current Solana cluster\n * locally and routes subsequent `signAndSendTransaction` calls\n * through the new chain. Wallet Standard has no \"tell the wallet\n * to switch cluster\" RPC; the wallet's own UI controls its global\n * cluster setting, and `signAndSendTransaction` accepts the chain\n * per-call. The chain must be one the wallet advertises in\n * `wallet.chains`; otherwise the call rejects.\n * - `requestAccounts` re-runs `standard:connect`. Some wallets show\n * their account picker again; others (those that \"remember\"\n * authorisations) silently return the existing accounts. butr\n * refreshes the pool entry's `accounts` array either way.\n * - `switchAccount` is intentionally unimplemented. Wallet Standard\n * has no silent \"use address X\" feature; the user picks the active\n * account through the wallet's own UI. `signAndSendTransaction`\n * accepts an `account` input, so consumers needing per-tx address\n * selection can pick one from `accounts` at call time.\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 const signAndSend = async (tx: unknown, account?: { walletAddress: string }): 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: core.currentChainId(),\n transaction: tx,\n });\n if (output === undefined) {\n throw new Error(\"signAndSendTransaction returned no outputs\");\n }\n return bytesToBase64(output.signature);\n };\n\n return {\n ...core,\n capabilities: resolveWalletStandardCapabilities({\n // Deliberately the wallet's whole chain list, not the Solana-only\n // slice: a wallet advertising a single `solana:` cluster alongside\n // other namespaces can still switch clusters from butr's side.\n chainCount: wallet.chains.length,\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 // Wallet Standard exposes no balance feature. Consumers wrap their\n // own RPC client; this default keeps the type signature honoured\n // without lying about a value we don't have.\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 // Wallet Standard has no equivalent of EIP-2255's\n // `wallet_requestPermissions`. The closest we can do is re-run\n // `standard:connect`, which prompts the user on wallets that\n // surface their picker each time and silently returns the\n // existing list on wallets that remember authorisations.\n // butr's runtime calls `getAccounts()` afterwards to refresh\n // the pool entry, so newly-exposed addresses appear either way.\n await core.connect();\n },\n\n sendTx: (tx, account) => signAndSend(tx, account),\n\n sendTxToChain: (tx, _targetChainId, account, cb) => {\n // Solana Wallet Standard's signAndSendTransaction takes the\n // target chain directly. `targetChainId` is the decimal-string\n // form butr uses, but the wallet expects a CAIP-2 chain string.\n // For now we honour the connector's current chain and let\n // consumers route per-chain at a higher level if they need\n // multi-cluster support.\n cb?.();\n return signAndSend(tx, account);\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 * Subscribe to Solana Wallet Standard announcements.\n * Spec: https://github.com/wallet-standard/wallet-standard\n *\n * Runtime requires the `@wallet-standard/app` package, which is an\n * **optional peer dependency** of butr. EVM-only consumers don't need\n * to install it; discovery will silently skip the SVM side if the\n * module isn't resolvable.\n *\n * Install for SVM auto-discovery:\n *\n * npm install @wallet-standard/app\n *\n * The function returns a synchronous unsubscribe that's safe to call\n * before the dynamic import has resolved.\n *\n * Implementation: the discovery loop (dynamic import, dedupe, register\n * / unregister bridge) lives in `@usebutr/wallet-standard-shared`. This\n * file's only job is to hand the kit a per-wallet builder.\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\n// Solana chain identifiers follow the Wallet Standard convention\n// (`solana:mainnet` / `solana:devnet` / `solana:testnet`) rather than\n// the strict CAIP-2 genesis-hash form (`solana:5eykt…`). Phantom,\n// Solflare, Backpack and the rest of the Wallet Standard ecosystem\n// advertise these shortnames in `wallet.chains`, and the SVM adapter's\n// `switchChain` rejects anything not in that set. The genesis-hash form\n// remains valid CAIP-2 but isn't what real wallets exchange.\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 * SVM's `PlatformDiscoverer`: Solana Wallet Standard announcements. No\n * legacy fallback; Solana wallets standardised on Wallet Standard\n * before butr existed, so there's no `window.solana` injected path\n * 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;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AO;GACxB;EACF,EACF;CACN;AACF;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,uBAAuB,cAC3B,uBAAuB,YAAY,QAAQ,yBACzC,gBAAgB,QAAQ,oBAAoB,CAC9C;;;;AC1OF,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;;;;;;;;;;ACf1E,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;;;;ACNH,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AACxB,MAAM,kBAAyC,CAAC,kBAAkB,qBAAqB;AAEvF,MAAM,8BACJ,YAEA,iBAAiB,WAAW,OAAO,QAAQ,gBAAgB;AAE7D,MAAM,yCACJ,YAEA,4BAA4B,WAAW,OAAO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EvD,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": "
|
|
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": "
|
|
29
|
-
"@usebutr/wallet-standard-shared": "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": "^
|
|
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"
|
|
@@ -47,7 +63,6 @@
|
|
|
47
63
|
"build": "tsdown",
|
|
48
64
|
"clean": "rm -rf dist",
|
|
49
65
|
"dev": "tsdown --watch",
|
|
50
|
-
"lint": "oxlint src",
|
|
51
66
|
"test": "vitest run --passWithNoTests",
|
|
52
67
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
53
68
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|