@bwalletx/connect 0.5.3 → 0.5.6

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 (50) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +80 -8
  3. package/dist/bwalletx-connect.global.js +92 -25
  4. package/dist/bwalletx-connect.global.js.map +1 -1
  5. package/dist/{wallets-VOKIKBbO.d.ts → choice-DCh-tgpT.d.cts} +113 -5
  6. package/dist/{wallets-VOKIKBbO.d.cts → choice-DCh-tgpT.d.ts} +113 -5
  7. package/dist/chunk-34DKBQNN.js +222 -0
  8. package/dist/chunk-34DKBQNN.js.map +1 -0
  9. package/dist/{chunk-QRXFL66W.js → chunk-A2WLGS25.js} +6 -4
  10. package/dist/chunk-A2WLGS25.js.map +1 -0
  11. package/dist/chunk-IFGOAROM.js +255 -0
  12. package/dist/chunk-IFGOAROM.js.map +1 -0
  13. package/dist/chunk-LS6AYEBO.js +1886 -0
  14. package/dist/chunk-LS6AYEBO.js.map +1 -0
  15. package/dist/element-D9Zl-x12.d.cts +46 -0
  16. package/dist/element-D9Zl-x12.d.ts +46 -0
  17. package/dist/element.cjs +1221 -67
  18. package/dist/element.cjs.map +1 -1
  19. package/dist/element.d.cts +23 -28
  20. package/dist/element.d.ts +23 -28
  21. package/dist/element.js +29 -2
  22. package/dist/element.js.map +1 -1
  23. package/dist/index.cjs +1539 -449
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +185 -12
  26. package/dist/index.d.ts +185 -12
  27. package/dist/index.js +106 -12
  28. package/dist/index.js.map +1 -1
  29. package/dist/next.cjs +5 -3
  30. package/dist/next.cjs.map +1 -1
  31. package/dist/next.js +1 -1
  32. package/dist/react.cjs +1073 -194
  33. package/dist/react.cjs.map +1 -1
  34. package/dist/react.d.cts +75 -8
  35. package/dist/react.d.ts +75 -8
  36. package/dist/react.js +121 -40
  37. package/dist/react.js.map +1 -1
  38. package/dist/server.cjs +5 -3
  39. package/dist/server.cjs.map +1 -1
  40. package/dist/server.d.cts +8 -3
  41. package/dist/server.d.ts +8 -3
  42. package/dist/server.js +1 -1
  43. package/dist/shell-react.cjs.map +1 -1
  44. package/dist/shell-react.js.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/chunk-IUDD7YTQ.js +0 -839
  47. package/dist/chunk-IUDD7YTQ.js.map +0 -1
  48. package/dist/chunk-PI42H3XY.js +0 -459
  49. package/dist/chunk-PI42H3XY.js.map +0 -1
  50. package/dist/chunk-QRXFL66W.js.map +0 -1
package/dist/react.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ReactNode, ReactElement, CSSProperties } from 'react';
2
2
  import { WalletInterface } from '@bsv/sdk';
3
- import { C as ConnectedWallet, W as WalletOption, P as PayRequest, a as PayResult, B as BuyTokenRequest, b as PayOptions } from './wallets-VOKIKBbO.cjs';
4
- export { H as HandCashAdapterOptions, c as PaymentError, d as brc100Option, e as discoverWallets, h as handcashAdapter, p as pairingOption } from './wallets-VOKIKBbO.cjs';
5
- import { SigninSize, SigninTheme, SigninLabel, SigninBrand } from './element.cjs';
3
+ import { C as ConnectedWallet, W as WalletOption, P as PayRequest, a as PayResult, B as BuyTokenRequest, A as AttemptHook, b as PayOptions } from './choice-DCh-tgpT.cjs';
4
+ export { H as HandCashAdapterOptions, c as PaymentError, d as autoChoice, e as brc100Option, f as discoverWallets, h as handcashAdapter, p as pairingOption } from './choice-DCh-tgpT.cjs';
5
+ import { S as SigninSize, a as SigninTheme, b as SigninLabel, c as SigninBrand, d as SigninState } from './element-D9Zl-x12.cjs';
6
6
 
7
7
  /**
8
8
  * React wrapper for <bwalletx-signin>. React is an optional peer dependency; the button itself is
@@ -40,6 +40,20 @@ interface BwalletxSigninProps {
40
40
  redirectUri?: string;
41
41
  scope?: string;
42
42
  discoverMs?: number;
43
+ /** "Other wallets" link under the button: 'auto' (default: lg/md), 'on' or 'off'. */
44
+ otherWallets?: 'auto' | 'on' | 'off';
45
+ /** Without a provider: GET → { identityKey, handle?, paymail? } restores the signed-in badge on load. */
46
+ sessionUrl?: string;
47
+ /** Without a provider: POST on Disconnect. */
48
+ logoutUrl?: string;
49
+ /** Paymail lookup for the badge; 'off' to skip. */
50
+ lookupUrl?: string;
51
+ /**
52
+ * Show the signed-in badge and the pending / error states (default true). Inside <BwalletXProvider> the button
53
+ * follows the provider: click → connect() (one wallet sheet), badge when signed in, Disconnect → disconnect()
54
+ * (logoutUrl). Set false for the pre-0.5.5 plain button.
55
+ */
56
+ stateful?: boolean;
43
57
  'aria-label'?: string;
44
58
  className?: string;
45
59
  style?: CSSProperties;
@@ -51,7 +65,11 @@ interface BwalletxSigninProps {
51
65
  onSignedIn?: (d: SignedInDetail) => void;
52
66
  onNotFound?: () => void;
53
67
  onError?: (error: unknown) => void;
68
+ /** After Disconnect in the badge menu. */
69
+ onSignedOut?: () => void;
54
70
  }
71
+ /** The element state for the provider's state. */
72
+ declare function signinStateFor(v: Pick<BwalletXState, 'status' | 'identityKey'>): SigninState;
55
73
  declare function BwalletxSignin(props: BwalletxSigninProps): ReactElement;
56
74
 
57
75
  type BwalletXStatus = 'idle' | 'restoring' | 'connecting' | 'connected' | 'error';
@@ -64,6 +82,8 @@ interface BwalletXState {
64
82
  wallet: WalletInterface | null;
65
83
  /** Which option connected (e.g. 'com.bwalletx.extension', 'bwalletx-pairing', 'handcash'). */
66
84
  walletId: string | null;
85
+ /** 'bwalletx' for any bWalletX, else the wallet's rdns / option id (0.5.6). null until connect(). */
86
+ walletType: string | null;
67
87
  /** True while the transitional HandCash adapter is in use. */
68
88
  transitional: boolean;
69
89
  /** The server session (verifyUrl/sessionUrl) is in place. */
@@ -71,9 +91,14 @@ interface BwalletXState {
71
91
  error: Error | null;
72
92
  }
73
93
  interface BwalletXContextValue extends BwalletXState {
74
- /** Find wallets, show the picker if there is a choice, connect, and sign in if verifyUrl is set. */
94
+ /**
95
+ * Find wallets, connect, and sign in if verifyUrl is set. bWalletX in this browser is used straight away (0.5.6);
96
+ * without it the chooser opens with "Get bWalletX" first. `chooser: true` is the "Other wallets" link: the chooser
97
+ * even when bWalletX is here.
98
+ */
75
99
  connect(opts?: {
76
100
  walletId?: string;
101
+ chooser?: boolean;
77
102
  }): Promise<ConnectedWallet | null>;
78
103
  disconnect(): Promise<void>;
79
104
  /** The wallets found on the last connect() (or listWallets()). */
@@ -85,7 +110,7 @@ interface BwalletXContextValue extends BwalletXState {
85
110
  }
86
111
  interface BwalletXProviderProps {
87
112
  children?: ReactNode;
88
- /** POST { identityKey } → challenge. With verifyUrl, connect() also signs in. */
113
+ /** POST {} (or { identityKey }) → challenge. With verifyUrl, connect() also signs in, in ONE wallet sheet. */
89
114
  challengeUrl?: string;
90
115
  /** POST { identityKey, nonce, signature } → { identityKey, handle?, paymail? } and sets the cookie. */
91
116
  verifyUrl?: string;
@@ -95,12 +120,33 @@ interface BwalletXProviderProps {
95
120
  sessionUrl?: string;
96
121
  /** Offer phone pairing with the built-in QR modal. Default true. */
97
122
  pairing?: boolean;
98
- /** Show the built-in picker when more than one wallet is available. Default true. */
123
+ /**
124
+ * Show the built-in picker when there is a real choice. Default true. One wallet found in this browser (and no
125
+ * app-supplied option such as HandCash) is used straight away, with no picker; phone pairing is then not offered.
126
+ */
99
127
  picker?: boolean;
128
+ /**
129
+ * Your challenge route is older than 0.5.5 and needs the identity key first (two wallet sheets). Normally not
130
+ * needed: such a server is detected and retried. Upgrade the server to @bwalletx/connect 0.5.5 for one sheet.
131
+ */
132
+ challengeNeedsIdentityKey?: boolean;
133
+ /** Paymail lookup by identity key for the signed-in badge (best effort). Default pay.bwallet.space; 'off' to skip. */
134
+ lookupUrl?: string;
100
135
  /** Extra options, e.g. [handcashAdapter({ login })]. */
101
136
  extraWallets?: WalletOption[];
102
- /** Probe desktop wallets on localhost. Default false. */
137
+ /**
138
+ * Probe desktop wallets on localhost while listing. Default false, and best left off (Chrome's Local Network Access
139
+ * prompt): the chooser offers "Desktop wallet", which probes only when tapped.
140
+ */
103
141
  probeLocal?: boolean;
142
+ /**
143
+ * bWalletX first (0.5.6, default true): with bWalletX in this browser connect() goes straight to its sheet, no
144
+ * chooser; without it the chooser opens, "Get bWalletX" first, and another wallet is connected only when picked.
145
+ * false: the 0.5.5 picker rule (one detected wallet of any brand was used without asking).
146
+ */
147
+ fastPath?: boolean;
148
+ /** Called once per connect attempt with { walletType, substrate, outcome, ms }. No keys, addresses or identity data. */
149
+ onAttempt?: AttemptHook;
104
150
  /**
105
151
  * A theme the wallet already bundles (e.g. 'npgx') for bWalletX to wear while this site is connected and is the
106
152
  * active tab. Declared only while connecting or connected; withdrawn on disconnect. See declareWalletTheme.
@@ -114,8 +160,29 @@ interface BwalletXProviderProps {
114
160
  declare function BwalletXProvider(p: BwalletXProviderProps): ReactElement;
115
161
  /** The wallet + session state. Must be inside <BwalletXProvider>. */
116
162
  declare function useBwalletX(): BwalletXContextValue;
163
+ type BwalletXAccountStatus = 'restoring' | 'signed-out' | 'pending' | 'signed-in' | 'error';
164
+ interface BwalletXAccount {
165
+ status: BwalletXAccountStatus;
166
+ identityKey: string | null;
167
+ paymail: string | null;
168
+ handle: string | null;
169
+ /** $alice, a site handle, the paymail, or a short key: what the badge shows. */
170
+ label: string | null;
171
+ /** The bAvatar picture for the identity key (gold by default), or null when signed out. */
172
+ avatarUrl: string | null;
173
+ /** One plain line for the last error ("Sign-in cancelled" for a no in the wallet), or null. */
174
+ error: string | null;
175
+ /** Sign in (the provider's connect(): one wallet sheet). Never throws; failures show in `status`/`error`. */
176
+ login(): Promise<void>;
177
+ /** Sign out: the provider's disconnect() (posts logoutUrl). */
178
+ logout(): Promise<void>;
179
+ }
180
+ /** The account view of a provider state (what useBwalletXAccount returns). */
181
+ declare function accountFor(v: BwalletXContextValue): BwalletXAccount;
182
+ /** The signed-in account for your own UI: { status, identityKey, paymail, handle, avatarUrl, logout, … }. Inside <BwalletXProvider>. */
183
+ declare function useBwalletXAccount(): BwalletXAccount;
117
184
 
118
185
  /** Alias with the casing used by <BwalletxSignin>. */
119
186
  declare const BwalletxProvider: typeof BwalletXProvider;
120
187
 
121
- export { BuyTokenRequest, type BwalletXContextValue, BwalletXProvider, type BwalletXProviderProps, type BwalletXState, type BwalletXStatus, BwalletxProvider, BwalletxSignin, type BwalletxSigninProps, ConnectedWallet, PayOptions, PayRequest, PayResult, type SignedInDetail, WalletOption, BwalletxSignin as default, useBwalletX };
188
+ export { BuyTokenRequest, type BwalletXAccount, type BwalletXAccountStatus, type BwalletXContextValue, BwalletXProvider, type BwalletXProviderProps, type BwalletXState, type BwalletXStatus, BwalletxProvider, BwalletxSignin, type BwalletxSigninProps, ConnectedWallet, PayOptions, PayRequest, PayResult, type SignedInDetail, WalletOption, accountFor, BwalletxSignin as default, signinStateFor, useBwalletX, useBwalletXAccount };
package/dist/react.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ReactNode, ReactElement, CSSProperties } from 'react';
2
2
  import { WalletInterface } from '@bsv/sdk';
3
- import { C as ConnectedWallet, W as WalletOption, P as PayRequest, a as PayResult, B as BuyTokenRequest, b as PayOptions } from './wallets-VOKIKBbO.js';
4
- export { H as HandCashAdapterOptions, c as PaymentError, d as brc100Option, e as discoverWallets, h as handcashAdapter, p as pairingOption } from './wallets-VOKIKBbO.js';
5
- import { SigninSize, SigninTheme, SigninLabel, SigninBrand } from './element.js';
3
+ import { C as ConnectedWallet, W as WalletOption, P as PayRequest, a as PayResult, B as BuyTokenRequest, A as AttemptHook, b as PayOptions } from './choice-DCh-tgpT.js';
4
+ export { H as HandCashAdapterOptions, c as PaymentError, d as autoChoice, e as brc100Option, f as discoverWallets, h as handcashAdapter, p as pairingOption } from './choice-DCh-tgpT.js';
5
+ import { S as SigninSize, a as SigninTheme, b as SigninLabel, c as SigninBrand, d as SigninState } from './element-D9Zl-x12.js';
6
6
 
7
7
  /**
8
8
  * React wrapper for <bwalletx-signin>. React is an optional peer dependency; the button itself is
@@ -40,6 +40,20 @@ interface BwalletxSigninProps {
40
40
  redirectUri?: string;
41
41
  scope?: string;
42
42
  discoverMs?: number;
43
+ /** "Other wallets" link under the button: 'auto' (default: lg/md), 'on' or 'off'. */
44
+ otherWallets?: 'auto' | 'on' | 'off';
45
+ /** Without a provider: GET → { identityKey, handle?, paymail? } restores the signed-in badge on load. */
46
+ sessionUrl?: string;
47
+ /** Without a provider: POST on Disconnect. */
48
+ logoutUrl?: string;
49
+ /** Paymail lookup for the badge; 'off' to skip. */
50
+ lookupUrl?: string;
51
+ /**
52
+ * Show the signed-in badge and the pending / error states (default true). Inside <BwalletXProvider> the button
53
+ * follows the provider: click → connect() (one wallet sheet), badge when signed in, Disconnect → disconnect()
54
+ * (logoutUrl). Set false for the pre-0.5.5 plain button.
55
+ */
56
+ stateful?: boolean;
43
57
  'aria-label'?: string;
44
58
  className?: string;
45
59
  style?: CSSProperties;
@@ -51,7 +65,11 @@ interface BwalletxSigninProps {
51
65
  onSignedIn?: (d: SignedInDetail) => void;
52
66
  onNotFound?: () => void;
53
67
  onError?: (error: unknown) => void;
68
+ /** After Disconnect in the badge menu. */
69
+ onSignedOut?: () => void;
54
70
  }
71
+ /** The element state for the provider's state. */
72
+ declare function signinStateFor(v: Pick<BwalletXState, 'status' | 'identityKey'>): SigninState;
55
73
  declare function BwalletxSignin(props: BwalletxSigninProps): ReactElement;
56
74
 
57
75
  type BwalletXStatus = 'idle' | 'restoring' | 'connecting' | 'connected' | 'error';
@@ -64,6 +82,8 @@ interface BwalletXState {
64
82
  wallet: WalletInterface | null;
65
83
  /** Which option connected (e.g. 'com.bwalletx.extension', 'bwalletx-pairing', 'handcash'). */
66
84
  walletId: string | null;
85
+ /** 'bwalletx' for any bWalletX, else the wallet's rdns / option id (0.5.6). null until connect(). */
86
+ walletType: string | null;
67
87
  /** True while the transitional HandCash adapter is in use. */
68
88
  transitional: boolean;
69
89
  /** The server session (verifyUrl/sessionUrl) is in place. */
@@ -71,9 +91,14 @@ interface BwalletXState {
71
91
  error: Error | null;
72
92
  }
73
93
  interface BwalletXContextValue extends BwalletXState {
74
- /** Find wallets, show the picker if there is a choice, connect, and sign in if verifyUrl is set. */
94
+ /**
95
+ * Find wallets, connect, and sign in if verifyUrl is set. bWalletX in this browser is used straight away (0.5.6);
96
+ * without it the chooser opens with "Get bWalletX" first. `chooser: true` is the "Other wallets" link: the chooser
97
+ * even when bWalletX is here.
98
+ */
75
99
  connect(opts?: {
76
100
  walletId?: string;
101
+ chooser?: boolean;
77
102
  }): Promise<ConnectedWallet | null>;
78
103
  disconnect(): Promise<void>;
79
104
  /** The wallets found on the last connect() (or listWallets()). */
@@ -85,7 +110,7 @@ interface BwalletXContextValue extends BwalletXState {
85
110
  }
86
111
  interface BwalletXProviderProps {
87
112
  children?: ReactNode;
88
- /** POST { identityKey } → challenge. With verifyUrl, connect() also signs in. */
113
+ /** POST {} (or { identityKey }) → challenge. With verifyUrl, connect() also signs in, in ONE wallet sheet. */
89
114
  challengeUrl?: string;
90
115
  /** POST { identityKey, nonce, signature } → { identityKey, handle?, paymail? } and sets the cookie. */
91
116
  verifyUrl?: string;
@@ -95,12 +120,33 @@ interface BwalletXProviderProps {
95
120
  sessionUrl?: string;
96
121
  /** Offer phone pairing with the built-in QR modal. Default true. */
97
122
  pairing?: boolean;
98
- /** Show the built-in picker when more than one wallet is available. Default true. */
123
+ /**
124
+ * Show the built-in picker when there is a real choice. Default true. One wallet found in this browser (and no
125
+ * app-supplied option such as HandCash) is used straight away, with no picker; phone pairing is then not offered.
126
+ */
99
127
  picker?: boolean;
128
+ /**
129
+ * Your challenge route is older than 0.5.5 and needs the identity key first (two wallet sheets). Normally not
130
+ * needed: such a server is detected and retried. Upgrade the server to @bwalletx/connect 0.5.5 for one sheet.
131
+ */
132
+ challengeNeedsIdentityKey?: boolean;
133
+ /** Paymail lookup by identity key for the signed-in badge (best effort). Default pay.bwallet.space; 'off' to skip. */
134
+ lookupUrl?: string;
100
135
  /** Extra options, e.g. [handcashAdapter({ login })]. */
101
136
  extraWallets?: WalletOption[];
102
- /** Probe desktop wallets on localhost. Default false. */
137
+ /**
138
+ * Probe desktop wallets on localhost while listing. Default false, and best left off (Chrome's Local Network Access
139
+ * prompt): the chooser offers "Desktop wallet", which probes only when tapped.
140
+ */
103
141
  probeLocal?: boolean;
142
+ /**
143
+ * bWalletX first (0.5.6, default true): with bWalletX in this browser connect() goes straight to its sheet, no
144
+ * chooser; without it the chooser opens, "Get bWalletX" first, and another wallet is connected only when picked.
145
+ * false: the 0.5.5 picker rule (one detected wallet of any brand was used without asking).
146
+ */
147
+ fastPath?: boolean;
148
+ /** Called once per connect attempt with { walletType, substrate, outcome, ms }. No keys, addresses or identity data. */
149
+ onAttempt?: AttemptHook;
104
150
  /**
105
151
  * A theme the wallet already bundles (e.g. 'npgx') for bWalletX to wear while this site is connected and is the
106
152
  * active tab. Declared only while connecting or connected; withdrawn on disconnect. See declareWalletTheme.
@@ -114,8 +160,29 @@ interface BwalletXProviderProps {
114
160
  declare function BwalletXProvider(p: BwalletXProviderProps): ReactElement;
115
161
  /** The wallet + session state. Must be inside <BwalletXProvider>. */
116
162
  declare function useBwalletX(): BwalletXContextValue;
163
+ type BwalletXAccountStatus = 'restoring' | 'signed-out' | 'pending' | 'signed-in' | 'error';
164
+ interface BwalletXAccount {
165
+ status: BwalletXAccountStatus;
166
+ identityKey: string | null;
167
+ paymail: string | null;
168
+ handle: string | null;
169
+ /** $alice, a site handle, the paymail, or a short key: what the badge shows. */
170
+ label: string | null;
171
+ /** The bAvatar picture for the identity key (gold by default), or null when signed out. */
172
+ avatarUrl: string | null;
173
+ /** One plain line for the last error ("Sign-in cancelled" for a no in the wallet), or null. */
174
+ error: string | null;
175
+ /** Sign in (the provider's connect(): one wallet sheet). Never throws; failures show in `status`/`error`. */
176
+ login(): Promise<void>;
177
+ /** Sign out: the provider's disconnect() (posts logoutUrl). */
178
+ logout(): Promise<void>;
179
+ }
180
+ /** The account view of a provider state (what useBwalletXAccount returns). */
181
+ declare function accountFor(v: BwalletXContextValue): BwalletXAccount;
182
+ /** The signed-in account for your own UI: { status, identityKey, paymail, handle, avatarUrl, logout, … }. Inside <BwalletXProvider>. */
183
+ declare function useBwalletXAccount(): BwalletXAccount;
117
184
 
118
185
  /** Alias with the casing used by <BwalletxSignin>. */
119
186
  declare const BwalletxProvider: typeof BwalletXProvider;
120
187
 
121
- export { BuyTokenRequest, type BwalletXContextValue, BwalletXProvider, type BwalletXProviderProps, type BwalletXState, type BwalletXStatus, BwalletxProvider, BwalletxSignin, type BwalletxSigninProps, ConnectedWallet, PayOptions, PayRequest, PayResult, type SignedInDetail, WalletOption, BwalletxSignin as default, useBwalletX };
188
+ export { BuyTokenRequest, type BwalletXAccount, type BwalletXAccountStatus, type BwalletXContextValue, BwalletXProvider, type BwalletXProviderProps, type BwalletXState, type BwalletXStatus, BwalletxProvider, BwalletxSignin, type BwalletxSigninProps, ConnectedWallet, PayOptions, PayRequest, PayResult, type SignedInDetail, WalletOption, accountFor, BwalletxSignin as default, signinStateFor, useBwalletX, useBwalletXAccount };
package/dist/react.js CHANGED
@@ -1,22 +1,27 @@
1
1
  import {
2
2
  PaymentError,
3
- brc100Option,
4
3
  buyToken,
5
4
  declareWalletTheme,
6
- discoverWallets,
7
- handcashAdapter,
8
- pairingModal,
9
- pairingOption,
10
5
  pay,
11
- pickWallet,
6
+ runConnect,
12
7
  tip
13
- } from "./chunk-PI42H3XY.js";
8
+ } from "./chunk-IFGOAROM.js";
14
9
  import {
15
- atStage,
10
+ accountLabel,
11
+ autoChoice,
12
+ avatarUrlFor,
13
+ brc100Option,
14
+ chooseWallet,
16
15
  clearPairing,
17
16
  defineBwalletxSignin,
18
- signInWithBwalletX
19
- } from "./chunk-IUDD7YTQ.js";
17
+ discoverWallets,
18
+ handcashAdapter,
19
+ lookupPaymail,
20
+ pairingModal,
21
+ pairingOption,
22
+ pickWallet,
23
+ signInErrorText
24
+ } from "./chunk-LS6AYEBO.js";
20
25
  import "./chunk-MWD4BCO5.js";
21
26
 
22
27
  // src/react.ts
@@ -30,19 +35,52 @@ import {
30
35
  useRef,
31
36
  useState
32
37
  } from "react";
38
+ function signinStateFor(v) {
39
+ if (v.status === "restoring") return "restoring";
40
+ if (v.status === "connecting") return "pending";
41
+ if (v.status === "error") return "error";
42
+ if (v.status === "connected" && v.identityKey) return "signed-in";
43
+ return "signed-out";
44
+ }
33
45
  function BwalletxSignin(props) {
34
46
  const ref = useRef(null);
35
47
  const cb = useRef(props);
36
48
  cb.current = props;
49
+ const ctx = useContext(Ctx);
50
+ const ctxRef = useRef(ctx);
51
+ ctxRef.current = ctx;
52
+ const driven = !!ctx && props.stateful !== false;
37
53
  useEffect(() => {
38
54
  defineBwalletxSignin();
39
55
  const el = ref.current;
40
56
  if (!el) return;
41
57
  const on = [
42
- ["bwalletx-signin", (e) => cb.current.onClick?.(e)],
58
+ [
59
+ "bwalletx-signin",
60
+ (e) => {
61
+ cb.current.onClick?.(e);
62
+ const c = ctxRef.current;
63
+ if (!e.defaultPrevented && c && cb.current.stateful !== false) {
64
+ e.preventDefault();
65
+ const mode = e.detail?.mode;
66
+ c.connect(mode === "chooser" ? { chooser: true } : {}).catch(() => void 0);
67
+ }
68
+ }
69
+ ],
43
70
  ["bwalletx-signed-in", (e) => cb.current.onSignedIn?.(e.detail)],
44
71
  ["bwalletx-not-found", () => cb.current.onNotFound?.()],
45
- ["bwalletx-error", (e) => cb.current.onError?.(e.detail.error)]
72
+ ["bwalletx-error", (e) => cb.current.onError?.(e.detail.error)],
73
+ [
74
+ "bwalletx-disconnect",
75
+ (e) => {
76
+ const c = ctxRef.current;
77
+ if (c && cb.current.stateful !== false) {
78
+ e.preventDefault();
79
+ void c.disconnect().then(() => cb.current.onSignedOut?.());
80
+ }
81
+ }
82
+ ],
83
+ ["bwalletx-signed-out", () => cb.current.onSignedOut?.()]
46
84
  ];
47
85
  for (const [t, f] of on) el.addEventListener(t, f);
48
86
  return () => {
@@ -51,6 +89,7 @@ function BwalletxSignin(props) {
51
89
  }, []);
52
90
  const p = props;
53
91
  const flag = (v) => v ? "" : void 0;
92
+ const state = driven ? signinStateFor(ctx) : void 0;
54
93
  return createElement("bwalletx-signin", {
55
94
  ref,
56
95
  id: p.id,
@@ -66,6 +105,16 @@ function BwalletxSignin(props) {
66
105
  disabled: flag(p.disabled),
67
106
  "challenge-url": p.challengeUrl,
68
107
  "verify-url": p.verifyUrl,
108
+ "session-url": driven ? void 0 : p.sessionUrl,
109
+ "logout-url": driven ? void 0 : p.logoutUrl,
110
+ "lookup-url": p.lookupUrl,
111
+ stateless: p.stateful === false ? "" : void 0,
112
+ state,
113
+ "identity-key": driven ? ctx.identityKey ?? void 0 : void 0,
114
+ paymail: driven ? ctx.paymail ?? void 0 : void 0,
115
+ handle: driven ? ctx.handle ?? void 0 : void 0,
116
+ "avatar-url": driven ? avatarUrlFor(ctx.identityKey) ?? void 0 : void 0,
117
+ error: driven && ctx.status === "error" ? signInErrorText(ctx.error) : void 0,
69
118
  "get-url": p.getUrl,
70
119
  "web-url": p.webUrl,
71
120
  href: p.href,
@@ -74,6 +123,7 @@ function BwalletxSignin(props) {
74
123
  "redirect-uri": p.redirectUri,
75
124
  scope: p.scope,
76
125
  "discover-ms": p.discoverMs,
126
+ "other-wallets": p.otherWallets,
77
127
  "aria-label": p["aria-label"]
78
128
  });
79
129
  }
@@ -85,6 +135,7 @@ var empty = {
85
135
  paymail: null,
86
136
  wallet: null,
87
137
  walletId: null,
138
+ walletType: null,
88
139
  transitional: false,
89
140
  signedIn: false,
90
141
  error: null
@@ -146,45 +197,42 @@ function BwalletXProvider(p) {
146
197
  setState((s) => ({ ...s, status: "connecting", error: null }));
147
198
  try {
148
199
  const list = await listWallets();
149
- let choice = opts.walletId ? list.find((w) => w.id === opts.walletId) : void 0;
150
- if (!choice) {
151
- const direct = list.filter((w) => w.kind !== "pairing");
152
- choice = c.picker !== false && list.length > 1 ? await pickWallet(list) : direct[0] ?? list[0] ?? null;
153
- }
154
- if (!choice) {
155
- if (!list.length) throw Object.assign(new Error("No wallet found. Get bWalletX at bwalletx.com."), { code: "NOT_FOUND" });
156
- setState((s) => ({ ...s, status: s.identityKey ? "connected" : "idle" }));
200
+ const fast = c.fastPath !== false;
201
+ const r = await runConnect({
202
+ list,
203
+ walletId: opts.walletId,
204
+ chooser: opts.chooser,
205
+ picker: c.picker,
206
+ fastPath: fast,
207
+ pick: fast ? (l) => chooseWallet(l) : pickWallet,
208
+ onAttempt: c.onAttempt,
209
+ challengeUrl: c.challengeUrl,
210
+ verifyUrl: c.verifyUrl,
211
+ challengeNeedsIdentityKey: c.challengeNeedsIdentityKey,
212
+ post: postJson
213
+ });
214
+ if (!r) {
215
+ setState((s) => ({ ...s, status: s.identityKey && s.signedIn ? "connected" : "idle" }));
157
216
  return null;
158
217
  }
159
- const cw = await choice.connect();
160
- let { handle = null, paymail = null } = cw;
161
- let signedIn = false;
162
- if (cw.wallet && c.challengeUrl && c.verifyUrl) {
163
- const r = await signInWithBwalletX({
164
- wallet: cw.wallet,
165
- challenge: (identityKey) => postJson(c.challengeUrl, { identityKey })
166
- });
167
- const v = await atStage("verify", () => postJson(c.verifyUrl, { identityKey: r.identityKey, nonce: r.nonce, signature: r.signature }));
168
- handle = v.handle ?? handle;
169
- paymail = v.paymail ?? paymail;
170
- signedIn = true;
171
- }
218
+ const cw = r.connected;
172
219
  payer.current = cw.payer;
173
220
  setState({
174
221
  status: "connected",
175
- identityKey: cw.identityKey,
176
- handle,
177
- paymail,
222
+ identityKey: r.identityKey,
223
+ handle: r.handle,
224
+ paymail: r.paymail,
178
225
  wallet: cw.wallet,
179
226
  walletId: cw.optionId,
227
+ walletType: r.walletType,
180
228
  transitional: !!cw.transitional,
181
- signedIn,
229
+ signedIn: r.signedIn,
182
230
  error: null
183
231
  });
184
- return cw;
232
+ return { ...cw, identityKey: r.identityKey, handle: r.handle ?? void 0, paymail: r.paymail ?? void 0 };
185
233
  } catch (e) {
186
234
  if (e?.message === "cancelled") {
187
- setState((s) => ({ ...s, status: s.identityKey ? "connected" : "idle" }));
235
+ setState((s) => ({ ...s, status: s.identityKey && s.signedIn ? "connected" : "idle" }));
188
236
  return null;
189
237
  }
190
238
  throw fail(e);
@@ -200,6 +248,17 @@ function BwalletXProvider(p) {
200
248
  payer.current = null;
201
249
  setState(empty);
202
250
  }, [state.walletId]);
251
+ useEffect(() => {
252
+ const key = state.identityKey;
253
+ if (!key || state.paymail || p.lookupUrl === "off") return;
254
+ let live = true;
255
+ void lookupPaymail(key, p.lookupUrl).then((pm) => {
256
+ if (live && pm) setState((s) => s.identityKey === key && !s.paymail ? { ...s, paymail: pm } : s);
257
+ });
258
+ return () => {
259
+ live = false;
260
+ };
261
+ }, [state.identityKey, state.paymail, p.lookupUrl]);
203
262
  const need = () => {
204
263
  if (!payer.current) throw new PaymentError("NOT_SUPPORTED", "Connect a wallet first (connect()).");
205
264
  return payer.current;
@@ -224,17 +283,39 @@ function useBwalletX() {
224
283
  if (!v) throw new Error("useBwalletX() must be used inside <BwalletXProvider>");
225
284
  return v;
226
285
  }
286
+ function accountFor(v) {
287
+ const status = signinStateFor(v);
288
+ const signedIn = status === "signed-in";
289
+ return {
290
+ status,
291
+ identityKey: signedIn ? v.identityKey : null,
292
+ paymail: signedIn ? v.paymail : null,
293
+ handle: signedIn ? v.handle : null,
294
+ label: signedIn ? accountLabel(v) : null,
295
+ avatarUrl: signedIn ? avatarUrlFor(v.identityKey) : null,
296
+ error: status === "error" ? signInErrorText(v.error) : null,
297
+ login: () => v.connect().then(() => void 0, () => void 0),
298
+ logout: () => v.disconnect()
299
+ };
300
+ }
301
+ function useBwalletXAccount() {
302
+ return accountFor(useBwalletX());
303
+ }
227
304
  var BwalletxProvider = BwalletXProvider;
228
305
  export {
229
306
  BwalletXProvider,
230
307
  BwalletxProvider,
231
308
  BwalletxSignin,
232
309
  PaymentError,
310
+ accountFor,
311
+ autoChoice,
233
312
  brc100Option,
234
313
  react_default as default,
235
314
  discoverWallets,
236
315
  handcashAdapter,
237
316
  pairingOption,
238
- useBwalletX
317
+ signinStateFor,
318
+ useBwalletX,
319
+ useBwalletXAccount
239
320
  };
240
321
  //# sourceMappingURL=react.js.map