@kheopskit/core 6.0.0-rc.3 → 6.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/MIGRATING_TO_V6.md +78 -17
  3. package/README.md +138 -34
  4. package/dist/ethereum.d.mts +2 -2
  5. package/dist/ethereum.d.ts +2 -2
  6. package/dist/ethereum.js +4 -4
  7. package/dist/ethereum.js.map +1 -1
  8. package/dist/ethereum.mjs +4 -4
  9. package/dist/ethereum.mjs.map +1 -1
  10. package/dist/index.d.mts +12 -27
  11. package/dist/index.d.ts +12 -27
  12. package/dist/index.js +9 -921
  13. package/dist/index.mjs +4 -916
  14. package/dist/{injectedWallets-BQBgS-f0.js → injectedWallets-D7wzBr_f.js} +2 -2
  15. package/dist/{injectedWallets-BQBgS-f0.js.map → injectedWallets-D7wzBr_f.js.map} +1 -1
  16. package/dist/{injectedWallets-5GL1Jder.mjs → injectedWallets-DHf2lYVb.mjs} +2 -2
  17. package/dist/{injectedWallets-5GL1Jder.mjs.map → injectedWallets-DHf2lYVb.mjs.map} +1 -1
  18. package/dist/instance-1BgEld17.d.ts +109 -0
  19. package/dist/instance-BPAvq0v7.mjs +1457 -0
  20. package/dist/instance-BPAvq0v7.mjs.map +1 -0
  21. package/dist/instance-CCP7uJV3.js +1528 -0
  22. package/dist/instance-CCP7uJV3.js.map +1 -0
  23. package/dist/instance-DDvZiq1L.d.mts +109 -0
  24. package/dist/internal.d.mts +3 -3
  25. package/dist/internal.d.ts +3 -3
  26. package/dist/internal.js +8 -6
  27. package/dist/internal.mjs +3 -3
  28. package/dist/{platformAccounts-yyRUrnel.mjs → platformAccounts-BeMDbmUT.mjs} +2 -2
  29. package/dist/{platformAccounts-yyRUrnel.mjs.map → platformAccounts-BeMDbmUT.mjs.map} +1 -1
  30. package/dist/{platformAccounts-BjIeRcFN.js → platformAccounts-FE7oA3-Y.js} +2 -2
  31. package/dist/{platformAccounts-BjIeRcFN.js.map → platformAccounts-FE7oA3-Y.js.map} +1 -1
  32. package/dist/polkadot.d.mts +2 -2
  33. package/dist/polkadot.d.ts +2 -2
  34. package/dist/polkadot.js +6 -7
  35. package/dist/polkadot.js.map +1 -1
  36. package/dist/polkadot.mjs +5 -6
  37. package/dist/polkadot.mjs.map +1 -1
  38. package/dist/{polkadotExtensions-BoVKhNU_.mjs → registryReads-30CCkmHe.js} +43 -2
  39. package/dist/registryReads-30CCkmHe.js.map +1 -0
  40. package/dist/{polkadotExtensions-y4J9UzYl.js → registryReads-HvSaXRWX.mjs} +30 -5
  41. package/dist/registryReads-HvSaXRWX.mjs.map +1 -0
  42. package/dist/solana.d.mts +2 -2
  43. package/dist/solana.d.ts +2 -2
  44. package/dist/solana.js +4 -4
  45. package/dist/solana.js.map +1 -1
  46. package/dist/solana.mjs +4 -4
  47. package/dist/solana.mjs.map +1 -1
  48. package/dist/testing.d.mts +1 -1
  49. package/dist/testing.d.ts +1 -1
  50. package/dist/{types-C3I3w0jb.d.ts → types-BGeGUtxz.d.mts} +14 -4
  51. package/dist/{types-C3I3w0jb.d.mts → types-BGeGUtxz.d.ts} +14 -4
  52. package/dist/{types-BWHvNFlN.js → types-BrMtrjs9.js} +8 -1
  53. package/dist/types-BrMtrjs9.js.map +1 -0
  54. package/dist/{types-Yor672md.mjs → types-D7OWi0Td.mjs} +3 -2
  55. package/dist/types-D7OWi0Td.mjs.map +1 -0
  56. package/dist/walletconnect.d.mts +13 -2
  57. package/dist/walletconnect.d.ts +13 -2
  58. package/dist/walletconnect.js +19 -13
  59. package/dist/walletconnect.js.map +1 -1
  60. package/dist/walletconnect.mjs +19 -13
  61. package/dist/walletconnect.mjs.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/getCachedObservable-LUq9IfEx.d.mts +0 -23
  64. package/dist/getCachedObservable-LUq9IfEx.d.ts +0 -23
  65. package/dist/iconCache-C-U3IEbP.mjs +0 -324
  66. package/dist/iconCache-C-U3IEbP.mjs.map +0 -1
  67. package/dist/iconCache-FR4iy6go.js +0 -377
  68. package/dist/iconCache-FR4iy6go.js.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/index.mjs.map +0 -1
  71. package/dist/polkadotExtensions-BoVKhNU_.mjs.map +0 -1
  72. package/dist/polkadotExtensions-y4J9UzYl.js.map +0 -1
  73. package/dist/registryReads-BpHsWLd7.js +0 -38
  74. package/dist/registryReads-BpHsWLd7.js.map +0 -1
  75. package/dist/registryReads-BvtznSo3.mjs +0 -33
  76. package/dist/registryReads-BvtznSo3.mjs.map +0 -1
  77. package/dist/types-BWHvNFlN.js.map +0 -1
  78. package/dist/types-Yor672md.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @kheopskit/core
2
2
 
3
+ ## 6.0.0-rc.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#168](https://github.com/kheopskit/kheopskit/pull/168) [`0f58896`](https://github.com/kheopskit/kheopskit/commit/0f58896af3fcf1ba2bd8d17bed40c74a60adb8be) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: with `walletConnect`, `wallets` lists the injected wallets without waiting for Reown AppKit to download and start. The WalletConnect wallet joins the list once AppKit loads, and `isDiscovering` still stays `true` until then.
8
+
9
+ - [#168](https://github.com/kheopskit/kheopskit/pull/168) [`0f58896`](https://github.com/kheopskit/kheopskit/commit/0f58896af3fcf1ba2bd8d17bed40c74a60adb8be) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: `walletConnect()` asks AppKit for Polkadot and Solana methods only when `networks` includes a network of that namespace. Before, a Polkadot-only dapp sent an empty Solana namespace, and Reown rejected the pairing, so the modal closed without a QR code.
10
+
11
+ ## 6.0.0-rc.4
12
+
13
+ ### Minor Changes
14
+
15
+ - [#166](https://github.com/kheopskit/kheopskit/pull/166) [`3c2bad1`](https://github.com/kheopskit/kheopskit/commit/3c2bad12e121cede1e95d93d7967d7bb96192180) Thanks [@0xKheops](https://github.com/0xKheops)! - Breaking: `getKheopskit$` and its `GetKheopskitOptions` type are removed from `@kheopskit/core`; create one instance with `createKheopskit(config, options)` and subscribe its `kheopskit$` once at app start. A `@kheopskit/react` provider that receives `ssrCookies` needs an instance created with `createKheopskit(config, { ssr: true })`; without it, `ssrCookies` is a type error. On the server, a store that `createKheopskit` creates ignores `rememberWallet`, `forgetWallet` and `setCachedState`, so module code shared by every request cannot change it.
16
+
17
+ Added: `createKheopskit` in `@kheopskit/core` returns `kheopskit$` and `store`. Every subscriber of `kheopskit$` shares one pipeline, which runs while something subscribes, and a wallet's `connect()` and `disconnect()` act on the pipeline running when they are called. `@kheopskit/react`'s `createKheopskit` is built on it. `@kheopskit/core/internal` gains the instance plumbing that `@kheopskit/react` uses; it is not public API.
18
+
19
+ - [#167](https://github.com/kheopskit/kheopskit/pull/167) [`4817131`](https://github.com/kheopskit/kheopskit/commit/4817131306f04ec74d81f95e8727a24c37f1acdb) Thanks [@0xKheops](https://github.com/0xKheops)! - Added: `createKheopskit` returns `waitForAccount(accountId, { signal })`, which resolves with the live account once the running instance lists it, rejects `ACCOUNT_UNAVAILABLE` when the account's wallet settled listing other accounts but not this one or is not connected (a connected wallet that lists no accounts keeps the wait open until `signal` fires), and rejects `ABORTED` like a wallet's `connect()`. `@kheopskit/react`'s `createKheopskit` returns it too.
20
+
21
+ - [#162](https://github.com/kheopskit/kheopskit/pull/162) [`da040e1`](https://github.com/kheopskit/kheopskit/commit/da040e1f1e8e84a21e7abd4481111ff077c0efdb) Thanks [@0xKheops](https://github.com/0xKheops)! - Added: `walletConnect({ appKitOptions })` forwards any other Reown `createAppKit` option to AppKit, such as `featuredWalletIds`, `features` or `allWallets`. The keys kheopskit sets (`projectId`, `metadata`, `networks`, `themeMode`, `themeVariables`, `universalProviderConfigOverride`) are rejected by the type and keep their kheopskit values.
22
+
23
+ ### Patch Changes
24
+
25
+ - [#164](https://github.com/kheopskit/kheopskit/pull/164) [`0e03c4b`](https://github.com/kheopskit/kheopskit/commit/0e03c4bdc7aafa1d2c5649b3673e41da44d3052e) Thanks [@0xKheops](https://github.com/0xKheops)! - Docs: SSR examples and snippets forward only the `kheopskit` cookie as `ssrCookies`, never the whole cookie header. The core README adds a "Knowing when wallets have settled" recipe and states what the cookie and `localStorage` hold.
26
+
27
+ - [#163](https://github.com/kheopskit/kheopskit/pull/163) [`1cc653d`](https://github.com/kheopskit/kheopskit/commit/1cc653d954f02b670f05639fd83b34da29ded5d6) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: wallets and accounts cached for a platform missing from `platforms` no longer show on the first frame, in the SSR markup or as hydration placeholders. The cached WalletConnect row and its accounts likewise need `walletConnect` in the config, and a WalletConnect account needs its platform in `platforms`. Remembered wallets of a removed platform are not reconnected and stay remembered, so adding the platform back restores their reconnect.
28
+
3
29
  ## 6.0.0-rc.3
4
30
 
5
31
  ### Patch Changes
@@ -52,6 +52,8 @@ This guide grows with each v6 change. Each section covers one area.
52
52
  | Discovery at page load | the Polkadot registry was read at 0, 100, 300, 600 and 1100 ms after subscribe only | read at subscribe and at `load`, then 100, 300, 600 and 1100 ms after each; `state.isDiscovering` is `true` until the last read, 1100 ms after `load` or after subscribe, whichever is later, and while a WalletConnect connector loads | [8](#8-discovery-hydration-end-and-persistence) |
53
53
  | Cache during a slow reconnect | a reconnect slower than the persistence debounce wrote `isConnected: false` and no accounts | a wallet still `connecting` keeps its previous cached entry and accounts | [8](#8-discovery-hydration-end-and-persistence) |
54
54
  | React instance and hooks | `createKheopskit` returns a provider and `useWallets`/`useAccounts`; reaching one wallet means reading the whole state; unmounting the provider leaves the pipeline running | `createKheopskit` also returns `kheopskit$` and `store`; `useWallet`, `useAccount` and `useConnect` read one item; unmounting the provider stops the pipeline | [9](#9-kheopskitreact-one-shared-instance-and-wallet-hooks) |
55
+ | Core stream | `getKheopskit$(config, options)`: each call a separate pipeline; its wallets' actions bound to that pipeline | `createKheopskit(config, options)` returns `kheopskit$` and `store`; every subscriber shares one pipeline; a wallet's actions act on the pipeline running when they are called | [10](#10-one-shared-instance-in-core-createkheopskit) |
56
+ | SSR persistence | `getKheopskit$(config, { ssrCookies })`, or `ssrCookies` on any provider | `createKheopskit(config, { ssr: true })`; the React provider's `ssrCookies` requires it | [10](#10-one-shared-instance-in-core-createkheopskit) |
55
57
 
56
58
  ---
57
59
 
@@ -75,8 +77,10 @@ Each section ends with the app code it makes redundant. In short:
75
77
  - A second `enable()` call made to reach `signer.signRaw`. Call
76
78
  `account.signRaw(message)` (section 3).
77
79
  - A hand-built `ecdsa` tx creator for ethereum-format accounts (section 3).
78
- - A second `getKheopskit$` subscription next to the React provider. Subscribe
79
- to the `kheopskit$` that `createKheopskit` returns (section 9).
80
+ - The `getKheopskit$` subscription next to the React provider, and a
81
+ `defer(...)` + `shareReplay(...)` wrapper that shares one `getKheopskit$`
82
+ pipeline. Subscribe to the `kheopskit$` that `createKheopskit` returns
83
+ (sections 9 and 10).
80
84
  - Test seeds that write the persisted shape to raw storage. Use
81
85
  `store.rememberWallet` and `store.setCachedState` with the test kit's
82
86
  builders (section 6).
@@ -105,11 +109,10 @@ Each section ends with the app code it makes redundant. In short:
105
109
  - `ABORTED`: this `connect()` or `disconnect()` call was abandoned. For
106
110
  `connect()`, its `signal` fired before the platform answered, `disconnect()`
107
111
  was called while it pended, or the last `kheopskit$` subscriber
108
- unsubscribed. For either call on an injected wallet, the wallet object came
109
- from a subscription that had already ended; the call then rejects without
110
- asking the platform and without changing the remembered list. A
111
- placeholder's `connect()` rejects the same way and its `disconnect()`
112
- resolves. The WalletConnect connector is not wrapped and still calls AppKit.
112
+ unsubscribed. Either call also rejects `ABORTED` when nothing subscribes
113
+ `kheopskit$` at the time of the call. It then asks no platform, leaves the
114
+ remembered list as it is and starts no pipeline. This holds for every
115
+ wallet, placeholders and the WalletConnect connector included (section 10).
113
116
  - `USER_REJECTED`: the user refused the wallet prompt. `cause` holds the
114
117
  platform error. It is an EIP-1193 error with `code: 4001` on Ethereum; on
115
118
  Polkadot the extension's own `Error`, for Talisman
@@ -119,7 +122,7 @@ Each section ends with the app code it makes redundant. In short:
119
122
  user.`, for SubWallet `Rejected` or `Cancelled`.
120
123
  - `CONNECT_FAILED`: any other platform failure. `cause` holds the platform
121
124
  error.
122
- - `INVALID_CONFIG`: `getKheopskit$` throws it synchronously when
125
+ - `INVALID_CONFIG`: `createKheopskit` throws it synchronously when
123
126
  `config.walletConnect` is not a plugin created by `walletConnect()` from
124
127
  `@kheopskit/core/walletconnect` (see section 5). It is not a rejection and
125
128
  carries no `walletId`.
@@ -552,10 +555,10 @@ getKheopskit$({
552
555
  });
553
556
 
554
557
  // v6
555
- import { getKheopskit$ } from "@kheopskit/core";
558
+ import { createKheopskit } from "@kheopskit/core";
556
559
  import { walletConnect } from "@kheopskit/core/walletconnect";
557
560
 
558
- getKheopskit$({
561
+ createKheopskit({
559
562
  platforms: [polkadot()],
560
563
  walletConnect: walletConnect({ projectId, metadata, networks }),
561
564
  });
@@ -563,7 +566,7 @@ getKheopskit$({
563
566
 
564
567
  | v5 | v6 |
565
568
  |----|----|
566
- | `walletConnect: { projectId, metadata, networks, ... }` | `walletConnect: walletConnect({ projectId, metadata, networks, ... })`. A raw object is a type error, and `getKheopskit$` throws a `KheopskitError` with the new code `INVALID_CONFIG` |
569
+ | `walletConnect: { projectId, metadata, networks, ... }` | `walletConnect: walletConnect({ projectId, metadata, networks, ... })`. A raw object is a type error, and `createKheopskit` throws a `KheopskitError` with the new code `INVALID_CONFIG` |
567
570
  | `import { resetAppKitCache } from "@kheopskit/core"` | `import { resetAppKitCache } from "@kheopskit/core/walletconnect"` |
568
571
  | `WalletConnectConfig` from `@kheopskit/core` | `WalletConnectOptions` from `@kheopskit/core/walletconnect` |
569
572
  | `relayUrl` option | removed. It was never passed to AppKit |
@@ -603,16 +606,17 @@ signet and talisman-web keep in `domains/extension/fakeInjectedWeb3.ts`.
603
606
  | `refusingWallet()` (talisman-web) | `{ enable: "reject" }` |
604
607
  | `enableDelay.ms` (signet) | `{ enable: "hold" }`, then `resolveEnable()` after advancing the timers |
605
608
  | `localStorage.setItem("kheopskit", JSON.stringify(cache))` (signet's `load`) | `store.rememberWallet(id)` and `store.setCachedState([cachedWalletOf(id, name)], [cachedAccountOf(wallet, address, name)])` |
606
- | `vi.doMock("@kheopskit/core")` wrapping `getKheopskit$` in `takeUntil(disposed$)` (signet's `load`) | unsubscribe from `getKheopskit$` and `store.destroy()`; unsubscribing stops kheopskit's timers |
609
+ | `vi.doMock("@kheopskit/core")` wrapping `getKheopskit$` in `takeUntil(disposed$)` (signet's `load`) | unsubscribe from `kheopskit$` and `store.destroy()`; unsubscribing stops kheopskit's timers |
607
610
  | `vi.unstubAllGlobals()` | `uninstall()` on each fake |
608
611
 
609
612
  Two things stay in the apps. The kit has no hook to make `disconnect` fail,
610
- so signet's `disconnectFailure` keeps its `getKheopskit$` wrapper. An extension
613
+ so signet's `disconnectFailure` keeps a wrapper, now around the `kheopskit$`
614
+ that `createKheopskit` returns. An extension
611
615
  that returns a broken `enable()` result, such as signet's
612
616
  `broken.enable.mockResolvedValue(...)`, stays a hand-written entry next to the
613
617
  fakes on `window.injectedWeb3`.
614
618
 
615
- An app that calls `getKheopskit$` without a `store` persists to
619
+ An app that creates its instance without a `store` persists to
616
620
  `localStorage`. Seed it with `createKheopskitStore()`, then call `destroy()` on
617
621
  that seeding store. The seeded data uses `remembered`, not v5's `autoReconnect`.
618
622
 
@@ -834,7 +838,7 @@ subscriber is left.
834
838
 
835
839
  | Addition | What it does |
836
840
  |----------|--------------|
837
- | `createKheopskit(config, { store? })` returns `kheopskit$` and `store` | the stream its provider subscribes to and the store that stream persists into; code outside React subscribes to the same pipeline |
841
+ | `createKheopskit(config, { store } \| { ssr: true })` returns `kheopskit$` and `store` | the stream its provider subscribes to and the store that stream persists into; code outside React subscribes to the same pipeline |
838
842
  | `useWallet(walletId)`, `useAccount(accountId)` | one item or `undefined`; re-render only when that item changes; also returned by `createKheopskit`, typed to its platforms |
839
843
  | `useConnect(walletId)` | `{ connect, disconnect, status, error }`; aborts a pending `connect()` on unmount or when `walletId` changes; rejects `ABORTED` a `connect()` that starts after either |
840
844
  | wallet actions act on the instance's pipeline | `connect` and `disconnect` from `useWallet` and `useWallets`, and `disconnect` from `useConnect`, act on the instance's pipeline when they are called, while any provider of the instance or any `kheopskit$` subscriber holds it, and wait for its first emission after an `<Activity>` reveal restarts it; called once nothing holds the pipeline, they reject `ABORTED` without restarting it. `useConnect`'s `connect` is component-scoped. It rejects `ABORTED` once its component has unmounted or been hidden by `<Activity>`, even while something else holds the pipeline |
@@ -844,9 +848,66 @@ See the [React README](../react/README.md#one-instance-for-react-and-rxjs-code).
844
848
 
845
849
  ### What downstream apps delete
846
850
 
847
- - A second `getKheopskit$` call next to the provider for RxJS code. Subscribe
848
- to the `kheopskit$` returned by `createKheopskit`.
851
+ - The `getKheopskit$` call next to the provider for RxJS code. Subscribe to
852
+ the `kheopskit$` returned by `createKheopskit`.
849
853
  - Components that read `useWallets()` only to find one wallet or account. Use
850
854
  `useWallet` or `useAccount`.
851
855
  - An `AbortController` kept in a ref to cancel `connect()` on unmount. Use
852
856
  `useConnect`.
857
+
858
+ ---
859
+
860
+ ## 10. One shared instance in core: `createKheopskit`
861
+
862
+ `@kheopskit/core` exports `createKheopskit`, and `@kheopskit/react`'s
863
+ `createKheopskit` is built on it. It replaces `getKheopskit$`.
864
+
865
+ - `getKheopskit$` and its `GetKheopskitOptions` type are removed. Create one
866
+ instance per app and use its stream:
867
+ `export const { kheopskit$, store } = createKheopskit(config, { store })`.
868
+ Every subscriber shares one pipeline. Delete your `defer(...)` +
869
+ `shareReplay(...)` wrapper. `platforms` must be a non-empty tuple, such as
870
+ `[polkadot()]` written inline; a value typed `KheopskitPlatform[]` no longer
871
+ compiles.
872
+ - The pipeline runs while something subscribes `kheopskit$`. To keep it
873
+ running for the page's lifetime, subscribe once at startup, or merge
874
+ `kheopskit$` into a stream you already keep subscribed. Unsubscribing the
875
+ last subscriber stops every timer, as before.
876
+ - `getKheopskit$(config, { ssrCookies })` on the client becomes
877
+ `createKheopskit(config, { ssr: true })`. On the server, read the request's
878
+ state with
879
+ `getHydratedSnapshot(createKheopskitStore({ ssrCookies }), resolveConfig(config))`.
880
+ - A wallet's `connect` and `disconnect`, read from any emission, act on the
881
+ pipeline that is running when you call them. While nothing subscribes
882
+ `kheopskit$`, they reject `ABORTED` and start nothing.
883
+ - New: `waitForAccount(accountId, { signal })` resolves with the live account
884
+ once the running instance lists it. Use it instead of polling `kheopskit$`
885
+ until a placeholder account turns live.
886
+ - On the server, a store that `createKheopskit` creates (no `store` option)
887
+ ignores `rememberWallet`, `forgetWallet` and `setCachedState`. A
888
+ module-level instance serves every request there, so no request may change
889
+ what its store holds. A store passed as `{ store }` is used as it is.
890
+ - `@kheopskit/react`: `createKheopskit(config, { ssr: true })` is required when
891
+ the provider receives `ssrCookies`. Without it, `ssrCookies` is a type error.
892
+ `createKheopskitStore({ ssrCookies: "" })` passed as `store` is no longer
893
+ needed. The `ABORTED` message for "nothing holds the pipeline" changed, so
894
+ match on `error.code`.
895
+
896
+ ```diff
897
+ - import { getKheopskit$ } from "@kheopskit/core";
898
+ - const store = createKheopskitStore();
899
+ - export const kheopskit$ = defer(() => getKheopskit$(config, { store })).pipe(
900
+ - shareReplay({ bufferSize: 1, refCount: false }),
901
+ - );
902
+ + import { createKheopskit } from "@kheopskit/core";
903
+ + export const { kheopskit$, store } = createKheopskit(config);
904
+ + kheopskit$.subscribe(); // once, at app start
905
+ ```
906
+
907
+ ```diff
908
+ // kheopskit.ts, React with SSR
909
+ - export const { KheopskitProvider } = createKheopskit(config, {
910
+ - store: createKheopskitStore({ ssrCookies: "" }),
911
+ - });
912
+ + export const { KheopskitProvider } = createKheopskit(config, { ssr: true });
913
+ ```
package/README.md CHANGED
@@ -16,7 +16,8 @@ https://github.com/kheopskit/kheopskit.
16
16
 
17
17
  > **Upgrading from v5?** v6 makes `connect()` shared, idempotent and
18
18
  > abortable, types its rejections, adds `status`, `isDiscovering`,
19
- > `isPlaceholder` and `signRaw`, and moves WalletConnect to a plugin. See
19
+ > `isPlaceholder` and `signRaw`, moves WalletConnect to a plugin, and shares
20
+ > one pipeline per app through `createKheopskit`. See
20
21
  > [MIGRATING_TO_V6.md](./MIGRATING_TO_V6.md).
21
22
 
22
23
  ## Install
@@ -40,7 +41,7 @@ WalletConnect is a plugin from its own entry point, so only a dapp that imports
40
41
  `@kheopskit/core/walletconnect` bundles AppKit:
41
42
 
42
43
  ```ts
43
- import { getKheopskit$ } from "@kheopskit/core";
44
+ import { createKheopskit } from "@kheopskit/core";
44
45
  import { polkadot } from "@kheopskit/core/polkadot";
45
46
  import { walletConnect } from "@kheopskit/core/walletconnect";
46
47
  import { defineChain } from "@reown/appkit/networks";
@@ -54,7 +55,7 @@ const polkadotNetwork = defineChain({
54
55
  caipNetworkId: "polkadot:91b171bb158e2d3848fa23a9f1c25182",
55
56
  });
56
57
 
57
- const kheopskit$ = getKheopskit$({
58
+ export const { kheopskit$ } = createKheopskit({
58
59
  platforms: [polkadot()],
59
60
  walletConnect: walletConnect({
60
61
  projectId: "<your Reown project id>",
@@ -64,18 +65,43 @@ const kheopskit$ = getKheopskit$({
64
65
  });
65
66
  ```
66
67
 
68
+ `appKitOptions` passes any other
69
+ [`createAppKit` option](https://docs.reown.com/appkit/javascript/core/options)
70
+ to AppKit as-is. For example, to feature wallets that Reown's registry does not
71
+ list for your chain and turn analytics off:
72
+
73
+ ```ts
74
+ walletConnect({
75
+ projectId,
76
+ metadata,
77
+ networks,
78
+ appKitOptions: {
79
+ featuredWalletIds: ["<wallet id>"],
80
+ features: { analytics: false },
81
+ },
82
+ });
83
+ ```
84
+
85
+ kheopskit sets `projectId`, `metadata`, `networks`, `themeMode`,
86
+ `themeVariables` and `universalProviderConfigOverride` itself. `appKitOptions`
87
+ does not accept those keys, and kheopskit's values win if one gets through
88
+ untyped. `allWallets` defaults to `"HIDE"`,
89
+ and `appKitOptions` can override it.
90
+
67
91
  ## Usage
68
92
 
69
- Platforms are enabled by passing **plugins** (imported from their entry points)
70
- to `config.platforms`:
93
+ Create one kheopskit instance per app with `createKheopskit`. Platforms are
94
+ enabled by passing **plugins** (imported from their entry points) to
95
+ `config.platforms`:
71
96
 
72
97
  ```ts
73
- import { getKheopskit$ } from "@kheopskit/core";
98
+ // kheopskit.ts
99
+ import { createKheopskit } from "@kheopskit/core";
74
100
  import { polkadot } from "@kheopskit/core/polkadot";
75
101
  import { ethereum } from "@kheopskit/core/ethereum";
76
102
  import { solana } from "@kheopskit/core/solana";
77
103
 
78
- const kheopskit$ = getKheopskit$({
104
+ export const { kheopskit$, store } = createKheopskit({
79
105
  platforms: [
80
106
  polkadot({ accountTypes: ["sr25519", "ed25519", "ecdsa"] }),
81
107
  ethereum(),
@@ -84,12 +110,55 @@ const kheopskit$ = getKheopskit$({
84
110
  appName: "My Dapp", // shown by Polkadot extensions; defaults to the WalletConnect metadata name, then the hostname
85
111
  autoReconnect: true,
86
112
  });
113
+ ```
87
114
 
115
+ ```ts
116
+ // main.ts
88
117
  kheopskit$.subscribe(({ wallets, accounts, isHydrating, isDiscovering }) => {
89
118
  // ...
90
119
  });
91
120
  ```
92
121
 
122
+ Subscribe `kheopskit$` once at app start, or merge it into a stream the app
123
+ keeps subscribed. The pipeline runs while something subscribes, and every
124
+ subscriber shares that one run.
125
+
126
+ When the last subscriber unsubscribes, the pipeline stops every timer. The
127
+ next subscriber starts a new run, which reads the cache again. A wallet's
128
+ `connect()` and `disconnect()`, read from any emission, act on the run that is
129
+ live when they are called (see [Connect and disconnect](#connect-and-disconnect)).
130
+
131
+ `createKheopskit` also returns `waitForAccount`. Use it to sign right after a
132
+ reload. A cached account is a placeholder until its wallet reconnects, so wait
133
+ for the live account instead of reading it from the first emission:
134
+
135
+ ```ts
136
+ const account = await waitForAccount(accountId, { signal });
137
+ ```
138
+
139
+ It has three outcomes:
140
+
141
+ - It resolves with the live account once the running instance lists it, at
142
+ once when it already does. It waits while `isHydrating` is `true`, while
143
+ `isDiscovering` is `true` and the account's wallet is not listed yet, while
144
+ that wallet is `connecting`, and while it is connected but lists no account
145
+ yet (an Ethereum wallet shows `connected` before `eth_accounts` answers).
146
+ - It rejects `ACCOUNT_UNAVAILABLE` when none of these holds and the wallet does
147
+ not list the account.
148
+ - It rejects `ABORTED` when nothing subscribes `kheopskit$` by the end of the
149
+ calling task, when the last subscriber leaves, or when `signal` fires.
150
+
151
+ Like `connect()`, it never starts the pipeline, and it has no timeout. A
152
+ connected wallet that lists no accounts, such as a locked Ethereum wallet,
153
+ keeps the wait open until `signal` fires or the last subscriber leaves.
154
+
155
+ `createKheopskit(config, options)` persists to `localStorage` by default.
156
+ Pass `{ ssr: true }` to persist in a cookie that a server render can read, or
157
+ `{ store }` to use a store you created (see [Persistence](#persistence)).
158
+ `store` is created on first use, so `createKheopskit` at module scope touches
159
+ no storage. A `config` that kheopskit cannot use throws `INVALID_CONFIG` from
160
+ `createKheopskit` itself.
161
+
93
162
  [Wallet lifecycle](#wallet-lifecycle) explains what each field means over a
94
163
  page load, with every default and delay.
95
164
 
@@ -124,7 +193,7 @@ event, so kheopskit reads that registry on a fixed schedule:
124
193
 
125
194
  The read window ends 1100 ms after `load` or after subscribe, whichever is
126
195
  later. Nothing reads the registry after that, so a wallet that injects later
127
- is not listed until the next subscription, usually the next page load.
196
+ is not listed until the next run, usually on the next page load.
128
197
  Kheopskit has no `refreshWallets()` and does not read again on focus or on
129
198
  connect. On the server it reads once and sets no timer.
130
199
 
@@ -157,6 +226,10 @@ Source: [`api/kheopskit.ts`](https://github.com/kheopskit/kheopskit/blob/main/pa
157
226
  On a reload, the first emission shows the wallets and accounts of the previous
158
227
  visit from the cache, so the list does not flash empty while the extensions
159
228
  inject and the wallets reconnect. `state.isHydrating` is `true` while it does.
229
+ `getHydratedSnapshot` builds this first emission from the config it is given
230
+ and leaves out what that config does not enable: the wallets and accounts of a
231
+ platform missing from `platforms`, the WalletConnect connector when
232
+ `walletConnect` is unset, and every account whose wallet is left out.
160
233
  With nothing cached, or with `hydrationGracePeriod: 0`, `isHydrating` is
161
234
  `false` from the first emission.
162
235
 
@@ -235,6 +308,19 @@ accounts, so a slow reconnect never writes an empty cache. Every other wallet is
235
308
  written as it is, with the accounts of connected wallets only. See
236
309
  [Persistence](#persistence) for the format.
237
310
 
311
+ #### Knowing when wallets have settled
312
+
313
+ ```ts
314
+ const settled =
315
+ !isHydrating && wallets.every((wallet) => wallet.status !== "connecting");
316
+ ```
317
+
318
+ Use it to hold a splash screen or a "welcome back" gate until the reconnects
319
+ are over, including a reconnect still pending when `hydrationTimeout` ended
320
+ hydration. Kheopskit has no flag for it, for the same reason it has no
321
+ `walletsReady` promise ([Design choices](#design-choices)): the state already
322
+ carries the fact.
323
+
238
324
  ### Reconnect
239
325
 
240
326
  Source: [`api/wallets.ts`](https://github.com/kheopskit/kheopskit/blob/main/packages/core/src/api/wallets.ts),
@@ -256,7 +342,7 @@ on later. On the next load it reconnects the remembered injected wallets that
256
342
  markup diverges. It receives the `BaseWallet` fields only, so key on `id`.
257
343
 
258
344
  ```ts
259
- getKheopskit$({
345
+ createKheopskit({
260
346
  platforms: [polkadot()],
261
347
  autoReconnect: (wallet) => wallet.id === "polkadot:talisman",
262
348
  });
@@ -350,16 +436,19 @@ code:
350
436
  subscription ended. During a pending `connect()` that the platform has not
351
437
  granted, `disconnect()` aborts it and resolves without waiting for the
352
438
  prompt.
353
- - **After the subscription.** Once the last `kheopskit$` subscriber has
354
- unsubscribed, `connect()` and `disconnect()` on an injected wallet object
355
- from that subscription reject with `ABORTED` without asking the platform. A
356
- placeholder's `connect()` rejects the same way, and its `disconnect()` still
357
- resolves at once. The live WalletConnect connector is not wrapped, so its
358
- `connect()` still opens the AppKit modal and its `disconnect()` still ends a
359
- live session.
439
+ - **Acts on the live run.** A wallet object read from any emission acts on
440
+ the run that is live when you call it, even when it was read from an earlier
441
+ run. When a new subscriber restarts the pipeline, the call waits for the new
442
+ run's first emission. While nothing subscribes `kheopskit$`, `connect()` and
443
+ `disconnect()` reject with `ABORTED`, ask no platform and start no run. This
444
+ holds for every wallet, placeholders and the WalletConnect connector
445
+ included. When the live run lists no wallet with the object's id, the call
446
+ rejects with a plain `Error`. A call pending when the pipeline errors or
447
+ completes rejects with `ABORTED`.
360
448
 
361
449
  Every rejection of `connect()` is a `KheopskitError` with a stable `code` and
362
- the `walletId`, and so is an `ABORTED` `disconnect()`. A `disconnect()` whose
450
+ the `walletId`, and so are an `ABORTED` `disconnect()` and every rejection of
451
+ `waitForAccount()` for a well-formed account id. A `disconnect()` whose
363
452
  platform call fails (Solana, the WalletConnect connector) rejects with the
364
453
  platform's own error.
365
454
 
@@ -367,7 +456,8 @@ platform's own error.
367
456
  |------|------|
368
457
  | `USER_REJECTED` | The user refused the prompt. `cause` holds the platform error. |
369
458
  | `CONNECT_FAILED` | Any other platform failure, including a Polkadot extension whose `enable()` result lacks `accounts.get`, `accounts.subscribe`, `signer.signPayload` or `signer.signRaw`, or whose `accounts.get()` rejects. `cause` holds the platform error. |
370
- | `ABORTED` | The call was abandoned, as listed above. The message reads `connect of wallet <id> was aborted` or `disconnect of wallet <id> was aborted`. |
459
+ | `ABORTED` | The call was abandoned, as listed above and in [Usage](#usage) for `waitForAccount()`. The message starts with `connect of wallet <id>`, `disconnect of wallet <id>` or `waitForAccount of account <id>` and names the reason, such as `was aborted`. |
460
+ | `ACCOUNT_UNAVAILABLE` | `waitForAccount()` stopped waiting and the account is not live: its wallet settled without listing it, is not connected, or was not discovered. |
371
461
  | `FEATURE_NOT_SUPPORTED` | A Solana Wallet Standard wallet that lacks `standard:connect`. |
372
462
  | `WALLET_PENDING` | `connect()` on a placeholder whose live wallet was not discovered before hydration ended, and always on a `getHydratedSnapshot` placeholder. |
373
463
 
@@ -446,8 +536,9 @@ goes to `localStorage` as JSON:
446
536
  - Wallet icons go to a separate `localStorage` key, `kheopskit-icons`, to keep
447
537
  the main entry small.
448
538
 
449
- With `ssrCookies`, the same data goes to a `kheopskit` cookie in a compact
450
- form, to stay under the cookie size limit:
539
+ With `ssrCookies` (`createKheopskitStore({ ssrCookies })`, or
540
+ `createKheopskit(config, { ssr: true })`), the same data goes to a `kheopskit`
541
+ cookie in a compact form, to stay under the cookie size limit:
451
542
 
452
543
  ```json
453
544
  { "v": 1, "r": ["polkadot:talisman"], "w": [["polkadot:talisman", "Talisman", 1, 0]], "a": [["polkadot:talisman", "5Grw…", "Alice", null, 0, 0]] }
@@ -457,7 +548,16 @@ form, to stay under the cookie size limit:
457
548
  `a` holds `[walletId, address, name, chainId, polkadotType, platform]` per
458
549
  account. The cookie is URI-encoded, lasts one year, and is set with `path=/`,
459
550
  `SameSite=Lax`, and `Secure` on HTTPS. Kheopskit warns in the console when the
460
- encoded value exceeds 3072 bytes.
551
+ encoded value exceeds 3072 bytes. On the server, pass only this cookie as
552
+ `ssrCookies`, never the whole cookie header: a value handed to a client
553
+ component ends up in the HTML, httpOnly session cookies included.
554
+
555
+ The `kheopskit` entry, in the cookie or in `localStorage`, holds only the ids of
556
+ the wallets the user connected, each cached wallet's id, name, type and
557
+ connected flag, and each cached account's address, name, wallet, chain id,
558
+ Polkadot key type and platform. Apart from the wallet icons in
559
+ `kheopskit-icons`, kheopskit stores nothing else. With the `walletConnect()`
560
+ plugin, Reown AppKit keeps its own session data in the browser.
461
561
 
462
562
  Data written before v6 stored `remembered` as `autoReconnect`. The store reads
463
563
  that field as `remembered` and drops it on the next write. A storage write that
@@ -465,15 +565,20 @@ throws (`QuotaExceededError`, a denied write) keeps the in-memory state while
465
565
  the store is observed, and
466
566
  neither `connect()` nor `disconnect()` rejects because of it.
467
567
 
568
+ On the server, a store that `createKheopskit` creates ignores
569
+ `rememberWallet`, `forgetWallet` and `setCachedState`. A module-level
570
+ instance serves every request there, so no request may change what its store
571
+ holds. A store passed as `{ store }` is used as it is.
572
+
468
573
  #### Custom storage
469
574
 
470
575
  `createKheopskitStore` accepts a `storage` option, which takes precedence over
471
- `ssrCookies` and `localStorage`. Pass the store to `getKheopskit$`:
576
+ `ssrCookies` and `localStorage`. Pass the store to `createKheopskit`:
472
577
 
473
578
  ```ts
474
579
  import {
580
+ createKheopskit,
475
581
  createKheopskitStore,
476
- getKheopskit$,
477
582
  type SyncableStorage,
478
583
  } from "@kheopskit/core";
479
584
 
@@ -485,7 +590,7 @@ const storage: SyncableStorage = {
485
590
  };
486
591
 
487
592
  const store = createKheopskitStore({ storage });
488
- const kheopskit$ = getKheopskit$(config, { store });
593
+ export const { kheopskit$ } = createKheopskit(config, { store });
489
594
 
490
595
  // When done with the store
491
596
  store.destroy();
@@ -585,8 +690,8 @@ A vitest test that seeds a remembered wallet and checks that it reconnects:
585
690
 
586
691
  ```ts
587
692
  import {
693
+ createKheopskit,
588
694
  createKheopskitStore,
589
- getKheopskit$,
590
695
  type KheopskitState,
591
696
  type KheopskitStore,
592
697
  } from "@kheopskit/core";
@@ -629,12 +734,11 @@ it("reconnects the wallet the user connected last time", async () => {
629
734
  store.rememberWallet(talisman.walletId);
630
735
  store.setCachedState([wallet], [cachedAccountOf(wallet, alice.address, alice.name)]);
631
736
 
737
+ const { kheopskit$ } = createKheopskit({ platforms: [polkadot()] }, { store });
632
738
  let state: KheopskitState | undefined;
633
- subscription = getKheopskit$({ platforms: [polkadot()] }, { store }).subscribe(
634
- (next) => {
635
- state = next;
636
- },
637
- );
739
+ subscription = kheopskit$.subscribe((next) => {
740
+ state = next;
741
+ });
638
742
  await vi.advanceTimersByTimeAsync(1000);
639
743
 
640
744
  expect(talisman.enableCalls()).toHaveLength(1);
@@ -653,9 +757,9 @@ subscription.unsubscribe();
653
757
  store.destroy();
654
758
  ```
655
759
 
656
- Unsubscribing from `getKheopskit$` stops every timer it started, among them
657
- the discovery reads, the hydration timers and the 1 second persistence
658
- debounce. Without it, a persist can write to storage after the test ended.
760
+ When the last subscriber of `kheopskit$` unsubscribes, kheopskit stops every
761
+ timer it started, among them the discovery reads, the hydration timers and the
762
+ 1 second persistence debounce. Without it, a persist can write to storage after the test ended.
659
763
  `store.destroy()` ends the store's storage subscription. `uninstall()` removes
660
764
  the fake from `window.injectedWeb3`, and removes `window.injectedWeb3` once it
661
765
  is empty.
@@ -665,7 +769,7 @@ With fake timers, advance time with `vi.advanceTimersByTimeAsync` (jest:
665
769
  promises, and the async variants run those microtasks between timers. The
666
770
  synchronous variants leave them pending.
667
771
 
668
- When the code under test calls `getKheopskit$` without a `store`, it uses
772
+ When the code under test creates its instance without a `store`, it uses
669
773
  `localStorage`. Seed it through a store on the same storage, then destroy that
670
774
  store:
671
775
 
@@ -1,4 +1,4 @@
1
- import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C3I3w0jb.mjs";
1
+ import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-BGeGUtxz.mjs";
2
2
  import { Account, CustomTransport, EIP1193Provider, WalletClient } from "viem";
3
3
  //#region src/utils/isEthereumAddress.d.ts
4
4
  /**
@@ -55,7 +55,7 @@ type EthereumAccount = LiveEthereumAccount | Placeholder<LiveEthereumAccount, "c
55
55
  //#endregion
56
56
  //#region src/api/ethereum/plugin.d.ts
57
57
  /**
58
- * Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
58
+ * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.
59
59
  *
60
60
  * @example
61
61
  * ```ts
@@ -1,4 +1,4 @@
1
- import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C3I3w0jb.js";
1
+ import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-BGeGUtxz.js";
2
2
  import { Account, CustomTransport, EIP1193Provider, WalletClient } from "viem";
3
3
  //#region src/utils/isEthereumAddress.d.ts
4
4
  /**
@@ -55,7 +55,7 @@ type EthereumAccount = LiveEthereumAccount | Placeholder<LiveEthereumAccount, "c
55
55
  //#endregion
56
56
  //#region src/api/ethereum/plugin.d.ts
57
57
  /**
58
- * Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
58
+ * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.
59
59
  *
60
60
  * @example
61
61
  * ```ts
package/dist/ethereum.js CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("./types-BWHvNFlN.js");
3
- const require_platformAccounts = require("./platformAccounts-BjIeRcFN.js");
4
- const require_injectedWallets = require("./injectedWallets-BQBgS-f0.js");
2
+ const require_types = require("./types-BrMtrjs9.js");
3
+ const require_platformAccounts = require("./platformAccounts-FE7oA3-Y.js");
4
+ const require_injectedWallets = require("./injectedWallets-D7wzBr_f.js");
5
5
  let rxjs = require("rxjs");
6
6
  let viem = require("viem");
7
7
  let mipd = require("mipd");
@@ -205,7 +205,7 @@ const getEthereumWallets$ = (store) => require_injectedWallets.createInjectedWal
205
205
  //#endregion
206
206
  //#region src/api/ethereum/plugin.ts
207
207
  /**
208
- * Ethereum platform plugin. Pass to `getKheopskit$({ platforms: [ethereum()] })`.
208
+ * Ethereum platform plugin. Pass to `createKheopskit({ platforms: [ethereum()] })`.
209
209
  *
210
210
  * @example
211
211
  * ```ts