@usebutr/core 2.0.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @usebutr/core
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#208](https://github.com/pedroapfilho/usebutr/pull/208) [`488fe13`](https://github.com/pedroapfilho/usebutr/commit/488fe13fe9cddb99ff6c5d60f798140e6ac4076f) Thanks [@pedroapfilho](https://github.com/pedroapfilho)! - Bump runtime dependency ranges to the current non-major line.
8
+
9
+ ## 3.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#203](https://github.com/pedroapfilho/usebutr/pull/203) [`1263f86`](https://github.com/pedroapfilho/usebutr/commit/1263f8666afd43b4f7dbf8df1763709c3edf09d9) Thanks [@pedroapfilho](https://github.com/pedroapfilho)! - Adapters now say what they can do by having the method: `capabilities` is gone, and an optional method (`sendTx`, `signMessage`, `getBalance`, `switchChain`, …) exists only when it works for that wallet. No adapter returns a placeholder balance or a receipt that stays pending anymore.
14
+
15
+ - `sendTx(tx, { account, chain })` replaces `sendTx` and `sendTxToChain`, and `signMessage`, `signTransaction` and `getBalance` take options objects. `chain` is a `ChainBase`. An adapter either routes the call to that chain, switches the wallet to it, or rejects; none ignores it.
16
+ - An `account` the wallet does not expose now rejects instead of signing with the first account. `chain.name` is the chain's name, never the wallet's.
17
+ - `getAccounts()` resolves the active account first. `getAccount` and `switchAccount` are removed.
18
+ - `getSigner()` resolves a tagged `WalletSigner` (`eip1193`, `wallet-standard`, `walletconnect`, `ledger-*`, …), so it can be narrowed with `switch (signer.kind)` instead of cast.
19
+ - `createWalletManager(config, { initialState })` owns discovery, hydration and persistence, and works without React. `config.sources` replaces the `discovery`, `connectors` and `createConnector` props. `fromAdapters` registers WalletConnect, Ledger and hand-built adapters, which now also appear in `useDiscoveredWallets()`.
20
+ - `WalletManagerProvider` takes `config` and `initialState`. `useSigner(wallet)` and `useBalance(wallet, { token, account })` take the wallet entry itself, and id-taking hooks read the active wallet only when the id is omitted (`null` reads none). The hooks are `useWalletManager`, `useWalletState`, `useConnect`, `useWallet`, `useSelectedWallet` (now typed per platform), `useAccounts`, `useConnectionStatus`, `useIsHydrated`, `useIsReconnecting`, `useDiscoveredWallets`, `useConnectedWallets`, the `…ByPlatform` groupings, `useBalance` and `useSigner`.
21
+ - `manager.connect()` and `useConnect().connectAsync()` resolve the `ConnectedWallet` and reject with a `ConnectionError`, now an `Error` subclass with a `kind` and a new `WalletNotFound` kind. `useConnect().connect()` never rejects: the failure lands in its `error`.
22
+ - `WalletPersistence` is `load()` / `save(state)`, and `createWalletStorage` replaces `new WalletStorage`. Storage keys are unchanged.
23
+ - Chain registries (`EVM_CHAINS`, `SVM_CHAINS`, …, `CHAINS_BY_PLATFORM`) move to `@usebutr/core`, and `BITCOIN_CHAINS` gains `testnet4`. `@usebutr/wallets` loads every platform's signer kinds, so an app that imports only it can narrow `signer.kind`.
24
+ - `@usebutr/react` requires React 19, which its `use()` call already needed.
25
+ - WalletConnect requests on Solana, Sui and Bitcoin now carry their chain, so they no longer fall through to the first namespace in a multi-namespace session. Solana takes `SVM_CHAINS` chains and maps them to the genesis-hash ids WalletConnect sessions use.
26
+ - Ledger's Solana `signTransaction` returns the full signed transaction, Sui signs the intent message, and Bitcoin `signMessage` returns a BIP-137 signature.
27
+ - `@usebutr/testing`'s fake adapter resolves a `signer` you pass instead of registering a test-only signer kind.
28
+ - `setAccount` selects an exposed account without changing any account's chain. Unknown accounts are ignored; chain changes come from the adapter.
29
+ - WalletConnect EVM events use the namespace in `session_event`, including empty account lists that end the connection. Local chain switches still update the manager.
30
+ - Failed persistence saves wait for every key write to finish before reporting failure, so delayed writes cannot overwrite a later disconnect.
31
+ - `@usebutr/svm/transaction` provides the shared legacy/v0 signing codec used by Ledger and WalletConnect, with consistent layout and signature validation.
32
+
33
+ See the migration guide at https://docs.usebutr.com/migration.
34
+
35
+ ### Patch Changes
36
+
37
+ - [#199](https://github.com/pedroapfilho/usebutr/pull/199) [`5d1f234`](https://github.com/pedroapfilho/usebutr/commit/5d1f23403263f7a1f8a48be061727972fe749b5f) Thanks [@pedroapfilho](https://github.com/pedroapfilho)! - Raise the zod dependency floor to 4.6.1.
38
+
3
39
  ## 2.0.1
4
40
 
5
41
  ### Patch Changes
package/README.md CHANGED
@@ -11,23 +11,69 @@ connection-state library. Your application owns the picker UI and chain client.
11
11
  npm install @usebutr/core zustand
12
12
  ```
13
13
 
14
- The store works outside React. Add a discovery source or your own connector factory when wiring real wallets.
14
+ The wallet manager works outside React. Pair it with `@usebutr/wallets` (or one
15
+ platform's `discover*Adapters`) to find real wallets, or use `@usebutr/react`
16
+ for the provider and hooks.
15
17
 
16
18
  ## Usage
17
19
 
18
- ```tsx
19
- import { createWalletStore } from "@usebutr/core";
20
+ ```ts
21
+ import { createWalletManager, fromAdapters } from "@usebutr/core";
22
+ import { autoDiscovery } from "@usebutr/wallets";
20
23
 
21
- export const store = createWalletStore({
22
- connectors: [],
23
- createConnector: () => null,
24
+ const manager = createWalletManager({
25
+ onConnectError: (error, connectorId) => console.warn(connectorId, error.kind),
26
+ sources: [autoDiscovery()],
24
27
  });
25
28
 
26
- // Read state from a non-React host.
27
- const wallets = store.getState().pool;
28
- console.log(wallets.size);
29
+ // Creating a manager has no side effects; start() subscribes the sources,
30
+ // restores persisted connections once, and bridges wallet events.
31
+ const stop = manager.start();
32
+
33
+ const wallet = await manager.connect("io.metamask");
34
+
35
+ // A method exists only when it works for this wallet.
36
+ if (wallet.connector.signMessage) {
37
+ await wallet.connector.signMessage(new TextEncoder().encode("hello"), {
38
+ account: wallet.account,
39
+ });
40
+ }
41
+
42
+ manager.subscribe((state) => console.log(state.pool.size, state.activeConnectorId));
29
43
  ```
30
44
 
45
+ - **Sources.** A `WalletSource` is `(onAdapter) => unsubscribe`, so every
46
+ `discover*Adapters` export goes into `sources` as-is. `fromAdapters(adapters)`
47
+ wraps an array or a promise of built adapters (WalletConnect, Ledger,
48
+ hand-rolled ones). The first adapter announced for an id wins.
49
+ - **State.** `getState()` holds the discovered `adapters`, the live `pool`,
50
+ the `selection` per platform, `activeConnectorId`, `reconnectingIds`, and the
51
+ latest attempt's `connectionStatus` / `connectionError`.
52
+ - **Actions.** `connect`, `disconnect`, `disconnectAll`, `requestAccounts`,
53
+ `setAccount`, `setActive`, `setSelection`, `clearConnectionError`. `connect`
54
+ resolves the `ConnectedWallet` and rejects with a `ConnectionError` whose
55
+ `kind` is `UserRejected`, `RequestPending`, `WalletLocked`, `ChainMismatch`,
56
+ `NotConnected`, `Timeout`, `WalletNotFound` or `Unknown`.
57
+ - **Signers.** `connector.getSigner()` resolves a tagged `WalletSigner`; narrow
58
+ it with `switch (signer.kind)`. Each transport package registers its kind.
59
+ - **Chains and accounts.** Every registry lives here (`EVM_CHAINS`,
60
+ `SVM_CHAINS`, `SUI_CHAINS`, `BITCOIN_CHAINS`, `POLKADOT_CHAINS`, their
61
+ `*_LIST`, `CHAINS_BY_PLATFORM`). Adapters build chains with
62
+ `resolveChain(id, list)` and accounts with `buildAccount(address, chain)`.
63
+
64
+ ## Persistence
65
+
66
+ Connections persist to localStorage and sessionStorage by default, written
67
+ after every change once start-up hydration has read what was there. Swap the
68
+ drivers with `createWalletStorage({ persistent, session })` (for example
69
+ `createCookieStorageDriver()` so a server can read them), or pass any
70
+ `WalletPersistence`: an object with `load()` and `save(state)`.
71
+
72
+ To render connections on the server, read the cookies with
73
+ `readWalletSnapshot(cookies)` and pass the snapshot as
74
+ `createWalletManager(config, { initialState })`. Seeded wallets render at
75
+ once and stay in `reconnectingIds` until their silent reconnect lands.
76
+
31
77
  ## Documentation
32
78
 
33
79
  - [Package reference](https://docs.usebutr.com/api/core)