@bwalletx/connect 0.5.4 → 0.7.0
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 +56 -0
- package/README.md +97 -9
- package/dist/bwalletx-connect.global.js +97 -25
- package/dist/bwalletx-connect.global.js.map +1 -1
- package/dist/choice-B97AjqF4.d.cts +442 -0
- package/dist/choice-B97AjqF4.d.ts +442 -0
- package/dist/chunk-6EFFOIHK.js +2441 -0
- package/dist/chunk-6EFFOIHK.js.map +1 -0
- package/dist/{chunk-QRXFL66W.js → chunk-A2WLGS25.js} +6 -4
- package/dist/chunk-A2WLGS25.js.map +1 -0
- package/dist/chunk-DIKJFKND.js +239 -0
- package/dist/chunk-DIKJFKND.js.map +1 -0
- package/dist/chunk-TNRI7ARM.js +206 -0
- package/dist/chunk-TNRI7ARM.js.map +1 -0
- package/dist/element-BXEoOdXY.d.cts +53 -0
- package/dist/element-BXEoOdXY.d.ts +53 -0
- package/dist/element.cjs +1576 -60
- package/dist/element.cjs.map +1 -1
- package/dist/element.d.cts +26 -26
- package/dist/element.d.ts +26 -26
- package/dist/element.js +35 -2
- package/dist/element.js.map +1 -1
- package/dist/index.cjs +2046 -454
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +323 -16
- package/dist/index.d.ts +323 -16
- package/dist/index.js +186 -12
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +5 -3
- package/dist/next.cjs.map +1 -1
- package/dist/next.js +1 -1
- package/dist/react.cjs +1601 -210
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +115 -9
- package/dist/react.d.ts +115 -9
- package/dist/react.js +262 -46
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +5 -3
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +8 -3
- package/dist/server.d.ts +8 -3
- package/dist/server.js +1 -1
- package/package.json +10 -9
- package/dist/chunk-EXRQJTXF.js +0 -910
- package/dist/chunk-EXRQJTXF.js.map +0 -1
- package/dist/chunk-QRXFL66W.js.map +0 -1
- package/dist/chunk-RIOHG5JH.js +0 -459
- package/dist/chunk-RIOHG5JH.js.map +0 -1
- package/dist/wallets-CbzMtxrf.d.cts +0 -250
- package/dist/wallets-CbzMtxrf.d.ts +0 -250
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { WalletInterface } from '@bsv/sdk';
|
|
2
|
+
|
|
3
|
+
/** localStorage-shaped storage. Methods may be sync or async. */
|
|
4
|
+
interface PairStorage {
|
|
5
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
6
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
7
|
+
removeItem(key: string): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/** The minimum of the browser WebSocket API this package uses (the `ws` package also fits). */
|
|
10
|
+
interface SocketLike {
|
|
11
|
+
readonly readyState: number;
|
|
12
|
+
onopen: ((ev: unknown) => void) | null;
|
|
13
|
+
onmessage: ((ev: {
|
|
14
|
+
data: unknown;
|
|
15
|
+
}) => void) | null;
|
|
16
|
+
onerror: ((ev: unknown) => void) | null;
|
|
17
|
+
onclose: ((ev: unknown) => void) | null;
|
|
18
|
+
send(data: string): void;
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
21
|
+
type SocketFactory = (url: string) => SocketLike;
|
|
22
|
+
interface PairConnectionOptions {
|
|
23
|
+
/** Where the pairing is kept so it survives a reload. Default: localStorage, else memory only. */
|
|
24
|
+
storage?: PairStorage | null;
|
|
25
|
+
/** Storage key. Default 'bwalletx.connect.pairing.v1'. */
|
|
26
|
+
storageKey?: string;
|
|
27
|
+
/** Opens a socket. Default: the global WebSocket. Pass one to run in Node or to test. */
|
|
28
|
+
socket?: SocketFactory;
|
|
29
|
+
/** Per-call timeout in ms. Default 120000. */
|
|
30
|
+
callTimeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
interface PairingOptions extends PairConnectionOptions {
|
|
33
|
+
/** Show this link as a QR code, and as text to copy (web.bwalletx.com takes it pasted). */
|
|
34
|
+
onLink: (link: string) => void;
|
|
35
|
+
/** Show this 4-digit code. The wallet shows the same one; the user checks they match. */
|
|
36
|
+
onCode: (code: string) => void;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/** Relay host. Default relay.bwallet.space. */
|
|
39
|
+
relay?: string;
|
|
40
|
+
/** This page's origin, as the relay will see it. Default location.origin. */
|
|
41
|
+
origin?: string;
|
|
42
|
+
}
|
|
43
|
+
/** A BRC-100 wallet whose every call goes, end-to-end encrypted, to the paired phone or web wallet. */
|
|
44
|
+
type PairedWallet = WalletInterface & {
|
|
45
|
+
/** Close the relay connection. The pairing stays stored; the next call reconnects. */
|
|
46
|
+
close(): void;
|
|
47
|
+
/** Tell the wallet to unpair, close, and delete the stored pairing. */
|
|
48
|
+
forget(): Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Pair with bWalletX on a phone (scan the QR) or web.bwalletx.com (paste the link).
|
|
52
|
+
* Resolves with a wallet once the user taps Connect. The pairing is stored (see `storage`) so
|
|
53
|
+
* `restorePairing()` can reconnect after a reload without a new QR.
|
|
54
|
+
*/
|
|
55
|
+
declare function pairBwalletX(opts: PairingOptions): Promise<PairedWallet>;
|
|
56
|
+
/**
|
|
57
|
+
* The wallet from a pairing stored by an earlier `pairBwalletX`, or null if there is none.
|
|
58
|
+
* It connects on the first call. The wallet must still have this site paired.
|
|
59
|
+
*/
|
|
60
|
+
declare function restorePairing(opts?: PairConnectionOptions): Promise<PairedWallet | null>;
|
|
61
|
+
/** Delete the stored pairing without telling the wallet. */
|
|
62
|
+
declare function clearPairing(opts?: Pick<PairConnectionOptions, 'storage' | 'storageKey'>): Promise<void>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Browser-side payment helpers on top of the BRC-100 wallet's createAction. Works with any
|
|
66
|
+
* BRC-100 wallet. Each helper asks the wallet once; it never retries a spend. If a call fails
|
|
67
|
+
* the error says whether the wallet may have sent anything (`maybeSent`).
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/** BRC-29 payment protocol id. */
|
|
71
|
+
declare const BRC29_PROTOCOL: [2, string];
|
|
72
|
+
type PayTo = string;
|
|
73
|
+
interface PayOutput {
|
|
74
|
+
/** Locking script hex. */
|
|
75
|
+
script: string;
|
|
76
|
+
satoshis: number;
|
|
77
|
+
description?: string;
|
|
78
|
+
}
|
|
79
|
+
interface PayRequest {
|
|
80
|
+
to: PayTo;
|
|
81
|
+
/** Amount in satoshis. Give this or `usd`. */
|
|
82
|
+
sats?: number;
|
|
83
|
+
/** Amount in US dollars, converted at `usdPerBsv` (or the live WhatsOnChain rate). */
|
|
84
|
+
usd?: number;
|
|
85
|
+
/** Shown in the wallet and, with `memoOnChain`, written in an OP_RETURN output. */
|
|
86
|
+
memo?: string;
|
|
87
|
+
memoOnChain?: boolean;
|
|
88
|
+
/** Labels for the wallet's history. */
|
|
89
|
+
labels?: string[];
|
|
90
|
+
}
|
|
91
|
+
interface PayOptions {
|
|
92
|
+
/** Fixed rate for `usd`. Otherwise fetched from WhatsOnChain. */
|
|
93
|
+
usdPerBsv?: number | (() => Promise<number>);
|
|
94
|
+
/** Resolve a paymail to outputs. Default: bsvalias P2P payment destination (needs CORS on the paymail host). */
|
|
95
|
+
resolvePaymail?: (paymail: string, sats: number) => Promise<{
|
|
96
|
+
outputs: PayOutput[];
|
|
97
|
+
reference?: string;
|
|
98
|
+
submit?: (rawTxHex: string) => Promise<void>;
|
|
99
|
+
}>;
|
|
100
|
+
fetch?: typeof fetch;
|
|
101
|
+
}
|
|
102
|
+
interface Brc29Remittance {
|
|
103
|
+
senderIdentityKey: string;
|
|
104
|
+
derivationPrefix: string;
|
|
105
|
+
derivationSuffix: string;
|
|
106
|
+
outputIndex: number;
|
|
107
|
+
}
|
|
108
|
+
interface PayResult {
|
|
109
|
+
txid: string;
|
|
110
|
+
/** Atomic BEEF (BRC-95) if the wallet returned it. Send it to your server's verifyPayment. */
|
|
111
|
+
tx?: number[];
|
|
112
|
+
sats: number;
|
|
113
|
+
outputs: PayOutput[];
|
|
114
|
+
/** For an identity-key payment: what the recipient needs to internalize the output (BRC-29). Deliver it to them. */
|
|
115
|
+
remittance?: Brc29Remittance;
|
|
116
|
+
}
|
|
117
|
+
type PaymentErrorCode = 'BAD_REQUEST' | 'RESOLVE_FAILED' | 'RATE_FAILED' | 'WALLET_REJECTED' | 'WALLET_ERROR' | 'NOT_SUPPORTED' | 'INSUFFICIENT_FUNDS';
|
|
118
|
+
/** (0.7.0) The plain message for a wallet with no coins for the network fee (PaymentError code INSUFFICIENT_FUNDS). */
|
|
119
|
+
declare const NO_COINS_TEXT = "Your wallet doesn't have enough to cover this payment and its small network fee. Add a little and try again.";
|
|
120
|
+
/**
|
|
121
|
+
* True when createAction failed because the wallet has no coins (or too few) to fund it: the SDK's
|
|
122
|
+
* WERR_INSUFFICIENT_FUNDS (code 7, also as it arrives from Metanet Desktop over the JSON API), or a wallet's own
|
|
123
|
+
* "insufficient funds" text. Nothing was sent in that case.
|
|
124
|
+
*/
|
|
125
|
+
declare function isInsufficientFunds(e: unknown): boolean;
|
|
126
|
+
declare class PaymentError extends Error {
|
|
127
|
+
readonly code: PaymentErrorCode;
|
|
128
|
+
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
129
|
+
readonly maybeSent: boolean;
|
|
130
|
+
readonly cause?: unknown | undefined;
|
|
131
|
+
constructor(code: PaymentErrorCode, message: string,
|
|
132
|
+
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
133
|
+
maybeSent?: boolean, cause?: unknown | undefined);
|
|
134
|
+
}
|
|
135
|
+
/** A wallet that is not BRC-100 (the HandCash transitional adapter) can still pay through this. */
|
|
136
|
+
interface LegacyPayer {
|
|
137
|
+
pay(req: PayRequest & {
|
|
138
|
+
sats: number;
|
|
139
|
+
}): Promise<PayResult>;
|
|
140
|
+
}
|
|
141
|
+
type PaySource = WalletInterface | LegacyPayer;
|
|
142
|
+
declare const isIdentityKeyHex: (s: string) => boolean;
|
|
143
|
+
declare const isPaymail: (s: string) => boolean;
|
|
144
|
+
/** Satoshis for a request (sats as given, or usd converted, rounded up). */
|
|
145
|
+
declare function amountInSats(req: Pick<PayRequest, 'sats' | 'usd'>, o?: PayOptions): Promise<number>;
|
|
146
|
+
/** Default paymail resolver: bsvalias P2P Payment Destination (BRC-? / capability 2a40af698840). */
|
|
147
|
+
declare function resolvePaymailP2P(paymail: string, sats: number, f?: typeof fetch): Promise<{
|
|
148
|
+
outputs: {
|
|
149
|
+
script: string;
|
|
150
|
+
satoshis: number;
|
|
151
|
+
}[];
|
|
152
|
+
reference: string | undefined;
|
|
153
|
+
submit: ((hex: string) => Promise<void>) | undefined;
|
|
154
|
+
}>;
|
|
155
|
+
/** Pay a paymail, address or identity key. One wallet prompt; never retried. */
|
|
156
|
+
declare function pay(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
157
|
+
/** pay() labelled as a tip. */
|
|
158
|
+
declare function tip(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
159
|
+
interface TokenQuote {
|
|
160
|
+
/** Outputs to fund, as your server priced them (e.g. payment to the seller + fee). */
|
|
161
|
+
outputs: PayOutput[];
|
|
162
|
+
description?: string;
|
|
163
|
+
/** Called with the result after the wallet signs; e.g. POST txid + tx to your server for verifyPayment. */
|
|
164
|
+
onPaid?: (r: PayResult) => Promise<void> | void;
|
|
165
|
+
}
|
|
166
|
+
interface BuyTokenRequest {
|
|
167
|
+
token: string;
|
|
168
|
+
amount: number | string;
|
|
169
|
+
/** The hook point: return the outputs for this purchase (usually from your server). */
|
|
170
|
+
quote: (req: {
|
|
171
|
+
token: string;
|
|
172
|
+
amount: number | string;
|
|
173
|
+
}) => Promise<TokenQuote>;
|
|
174
|
+
labels?: string[];
|
|
175
|
+
}
|
|
176
|
+
/** Buy a token: your `quote` hook prices it, the wallet pays once, `onPaid` delivers it. */
|
|
177
|
+
declare function buyToken(source: PaySource, req: BuyTokenRequest): Promise<PayResult>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Every wallet the user could connect with, behind one interface. BRC-100 first: bWalletX, then any
|
|
181
|
+
* other wallet that announces itself (Yours, Metanet, ...), the in-app browser, optional localhost
|
|
182
|
+
* desktop wallets, phone pairing, and app-supplied adapters (e.g. the transitional HandCash one).
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
type WalletKind = 'brc100' | 'pairing' | 'handcash' | 'custom';
|
|
186
|
+
/**
|
|
187
|
+
* How a wallet reaches the page. 'extension' / 'in-app': bWalletX announced itself (its own rdns); 'xdm': the bWalletX
|
|
188
|
+
* app frame around the page; 'injected': another wallet that announced itself; 'window.CWI': something set window.CWI
|
|
189
|
+
* without announcing (it can't be told apart from any other wallet); 'json-api' / 'cicada': a desktop wallet on
|
|
190
|
+
* localhost (Metanet / BSV Desktop on 3321, Cicada on 3301); 'pairing': bWalletX on a phone over the relay;
|
|
191
|
+
* 'adapter': an app-supplied option (HandCash today).
|
|
192
|
+
*/
|
|
193
|
+
type Substrate = 'extension' | 'in-app' | 'xdm' | 'injected' | 'window.CWI' | 'json-api' | 'cicada' | 'pairing' | 'adapter';
|
|
194
|
+
interface ConnectedWallet {
|
|
195
|
+
/** The BRC-100 wallet. null for a non-BRC-100 adapter (HandCash today). */
|
|
196
|
+
wallet: WalletInterface | null;
|
|
197
|
+
/** What pay/tip use: the BRC-100 wallet, or the adapter's own payer. */
|
|
198
|
+
payer: PaySource | null;
|
|
199
|
+
/** The identity public key (hex) when the wallet has one. */
|
|
200
|
+
identityKey: string | null;
|
|
201
|
+
handle?: string;
|
|
202
|
+
paymail?: string;
|
|
203
|
+
/** Which option connected. */
|
|
204
|
+
optionId: string;
|
|
205
|
+
kind: WalletKind;
|
|
206
|
+
/** True for adapters kept only until the vendor ships BRC-100. */
|
|
207
|
+
transitional?: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface WalletOption {
|
|
210
|
+
id: string;
|
|
211
|
+
name: string;
|
|
212
|
+
icon?: string;
|
|
213
|
+
kind: WalletKind;
|
|
214
|
+
rdns?: string;
|
|
215
|
+
/** True for bWalletX (extension, in-app or paired). */
|
|
216
|
+
isBwalletX: boolean;
|
|
217
|
+
/** How it reaches the page (0.5.6). Options built by this package always set it. */
|
|
218
|
+
substrate?: Substrate;
|
|
219
|
+
/** The BRC-100 wallet behind a detected option (brc100 kind), when known before connecting. */
|
|
220
|
+
wallet?: WalletInterface;
|
|
221
|
+
/**
|
|
222
|
+
* Open the wallet. By default it also asks for the identity key (one wallet call). Pass `{ identity: false }` when
|
|
223
|
+
* you sign in straight after (BwalletXProvider does): the key then comes with the sign-in signature, in ONE sheet,
|
|
224
|
+
* and `identityKey` is null here.
|
|
225
|
+
*/
|
|
226
|
+
connect(opts?: ConnectOptions): Promise<ConnectedWallet>;
|
|
227
|
+
}
|
|
228
|
+
interface ConnectOptions {
|
|
229
|
+
/** Ask for the identity key now. Default true. */
|
|
230
|
+
identity?: boolean;
|
|
231
|
+
}
|
|
232
|
+
/** Wrap any BRC-100 wallet as a picker option. */
|
|
233
|
+
declare function brc100Option(wallet: WalletInterface, info: {
|
|
234
|
+
id: string;
|
|
235
|
+
name: string;
|
|
236
|
+
icon?: string;
|
|
237
|
+
rdns?: string;
|
|
238
|
+
isBwalletX?: boolean;
|
|
239
|
+
substrate?: Substrate;
|
|
240
|
+
}): WalletOption;
|
|
241
|
+
/** Phone / web.bwalletx.com pairing as an option (shows a QR through `pairing`). Reuses a stored pairing first. */
|
|
242
|
+
declare function pairingOption(pairing: PairingOptions | (() => PairingOptions)): WalletOption;
|
|
243
|
+
interface HandCashAdapterOptions {
|
|
244
|
+
/**
|
|
245
|
+
* Your existing HandCash Connect login (redirect/popup + your server route). Resolve with the
|
|
246
|
+
* profile once the user is signed in. This package does not import any HandCash SDK.
|
|
247
|
+
*/
|
|
248
|
+
login(): Promise<{
|
|
249
|
+
handle: string;
|
|
250
|
+
paymail?: string;
|
|
251
|
+
identityKey?: string;
|
|
252
|
+
}>;
|
|
253
|
+
/** Your existing HandCash pay call (usually a server route using the auth token). Optional. */
|
|
254
|
+
pay?: Extract<PaySource, {
|
|
255
|
+
pay: unknown;
|
|
256
|
+
}>['pay'];
|
|
257
|
+
icon?: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* TRANSITIONAL. Keeps existing HandCash users working behind the same picker until HandCash's
|
|
261
|
+
* BRC-100 support ships; then remove this and HandCash appears as an ordinary BRC-100 wallet.
|
|
262
|
+
*/
|
|
263
|
+
declare function handcashAdapter(o: HandCashAdapterOptions): WalletOption;
|
|
264
|
+
interface DiscoverWalletsOptions {
|
|
265
|
+
/** Longest wait for BRC-100 announcements, ms. Default 300; ends early once a wallet has announced. */
|
|
266
|
+
ms?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Also probe desktop wallets on localhost (Metanet / json-api on 3321, Cicada on 3301) while listing.
|
|
269
|
+
* Off by default, and best left off: Chrome asks for Local Network Access on the first probe. The chooser
|
|
270
|
+
* (chooseWallet) offers "Desktop wallet" instead, which probes only when the user taps it (desktopOption).
|
|
271
|
+
*/
|
|
272
|
+
probeLocal?: boolean;
|
|
273
|
+
/** Add the phone pairing option (needs a way to show the QR, e.g. pairingModal()). */
|
|
274
|
+
pairing?: PairingOptions | (() => PairingOptions);
|
|
275
|
+
/** App-supplied options appended at the end (e.g. handcashAdapter(...)). */
|
|
276
|
+
extra?: WalletOption[];
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* True when window.CWI is a wallet that already announced itself, so the picker must not list it twice. bWalletX
|
|
280
|
+
* (extension and in-app) sets window.CWI to the very object it announces; the in-app browser is matched by rdns too.
|
|
281
|
+
*/
|
|
282
|
+
declare function cwiIsAnnounced(cwi: WalletInterface, announced: WalletOption[]): boolean;
|
|
283
|
+
/** All wallets we can see, bWalletX first. SSR-safe: resolves [] (plus `extra`) outside a browser. */
|
|
284
|
+
declare function discoverWallets(o?: DiscoverWalletsOptions): Promise<WalletOption[]>;
|
|
285
|
+
/** Id of the "Desktop wallet" option (desktopOption). */
|
|
286
|
+
declare const DESKTOP_OPTION_ID = "desktop";
|
|
287
|
+
/**
|
|
288
|
+
* "Desktop wallet" (Metanet / BSV Desktop on localhost:3321, Cicada on 3301) as an option that looks for the wallet
|
|
289
|
+
* only when connect() runs, i.e. after the user picked it. Nothing touches localhost before that: the first request
|
|
290
|
+
* makes Chrome ask for Local Network Access, which must follow a tap, never a page load. connect() rejects with
|
|
291
|
+
* code NOT_FOUND when neither port answers within `ms`.
|
|
292
|
+
*/
|
|
293
|
+
declare function desktopOption(ms?: number): WalletOption;
|
|
294
|
+
/**
|
|
295
|
+
* The 0.5.5 rule, kept for `fastPath: false` (0.5.6 sites use decideWallet, which never picks another wallet unasked).
|
|
296
|
+
* Which option to use without showing the picker, or undefined when the user has a real choice.
|
|
297
|
+
* - nothing found → null;
|
|
298
|
+
* - one option → it;
|
|
299
|
+
* - exactly one wallet detected in this browser and no app-supplied option (HandCash, custom) → that wallet, with no
|
|
300
|
+
* picker: phone pairing is a fallback for "no wallet here", not a second choice;
|
|
301
|
+
* - only phone pairing → pairing.
|
|
302
|
+
* `force` (picker off): the first detected wallet, else the first non-pairing option, else pairing.
|
|
303
|
+
*/
|
|
304
|
+
declare function autoChoice(list: WalletOption[], force?: boolean): WalletOption | null | undefined;
|
|
305
|
+
/**
|
|
306
|
+
* (0.7.0) A desktop wallet reached over localhost (json-api on 3321 = Metanet Desktop, Cicada on 3301): never picked
|
|
307
|
+
* by the button, the fast path or a remembered choice; only by its own tap ("Use Metanet Desktop…").
|
|
308
|
+
*/
|
|
309
|
+
declare function isLocalDesktop(w: Pick<WalletOption, 'id' | 'substrate'>): boolean;
|
|
310
|
+
|
|
311
|
+
/** The wallet type every bWalletX (extension, in-app, app frame, phone) reports. */
|
|
312
|
+
declare const BWALLETX_TYPE = "bwalletx";
|
|
313
|
+
/** How the option reaches the page (WalletOption.substrate, inferred for options built elsewhere). */
|
|
314
|
+
declare function substrateOf(o: WalletOption): Substrate;
|
|
315
|
+
/** 'bwalletx' for any bWalletX; otherwise the wallet's rdns, else its option id ('desktop', 'window.CWI', 'handcash'). */
|
|
316
|
+
declare function walletTypeOf(o: WalletOption): string;
|
|
317
|
+
/**
|
|
318
|
+
* bWalletX found in this browser by its own marker (announcement or app frame). A wallet that only sits on
|
|
319
|
+
* window.CWI never counts, whatever it claims to be.
|
|
320
|
+
*/
|
|
321
|
+
declare function isPresentBwalletX(o: WalletOption): boolean;
|
|
322
|
+
/** True when bWalletX itself is in this browser (not just phone pairing). */
|
|
323
|
+
declare function hasBwalletX(list: readonly WalletOption[]): boolean;
|
|
324
|
+
/** Wallets other than bWalletX that are actually in this browser (announced, window.CWI, or a probed desktop wallet). */
|
|
325
|
+
declare function otherDetected(list: readonly WalletOption[]): WalletOption[];
|
|
326
|
+
/** The chooser's order: bWalletX here, phone pairing, other detected wallets, app-supplied options last. */
|
|
327
|
+
declare function chooserOrder(list: readonly WalletOption[]): WalletOption[];
|
|
328
|
+
/**
|
|
329
|
+
* Why decideWallet chose what it did. 'requested': walletId; 'bwalletx': bWalletX is here (fast path);
|
|
330
|
+
* 'bwalletx-phone': picker off and no bWalletX here, so the phone; 'legacy': fastPath false (0.5.5 autoChoice);
|
|
331
|
+
* 'chooser': show the chooser; 'none': nothing to offer.
|
|
332
|
+
*/
|
|
333
|
+
type ChoiceReason = 'requested' | 'remembered' | 'bwalletx' | 'bwalletx-phone' | 'legacy' | 'chooser' | 'none';
|
|
334
|
+
interface WalletChoice {
|
|
335
|
+
option: WalletOption | null;
|
|
336
|
+
reason: ChoiceReason;
|
|
337
|
+
}
|
|
338
|
+
interface DecideWalletOptions {
|
|
339
|
+
/** Use this option (an explicit choice the site already has). */
|
|
340
|
+
walletId?: string;
|
|
341
|
+
/** "Other wallets": the user asked for the chooser, so show it even with bWalletX here. */
|
|
342
|
+
chooser?: boolean;
|
|
343
|
+
/** false: never show the chooser (bWalletX, else the phone, else nothing; never another wallet). */
|
|
344
|
+
picker?: boolean;
|
|
345
|
+
/** The bWalletX-first rule. Default true; false restores the 0.5.5 behaviour (autoChoice). */
|
|
346
|
+
fastPath?: boolean;
|
|
347
|
+
/** (0.6.0) The wallet the user picked on this origin before (rememberedWalletChoice()). Used when it is here. */
|
|
348
|
+
remembered?: RememberedWallet | null;
|
|
349
|
+
/** (0.6.0) "Switch" to bWalletX: ignore a remembered other wallet. */
|
|
350
|
+
preferBwalletX?: boolean;
|
|
351
|
+
}
|
|
352
|
+
/** The wallet to connect now, or the chooser ({ option: null, reason: 'chooser' }). */
|
|
353
|
+
declare function decideWallet(list: readonly WalletOption[], o?: DecideWalletOptions): WalletChoice;
|
|
354
|
+
/** How a connect attempt ended. */
|
|
355
|
+
type AttemptOutcome = 'signed-in' | 'connected' | 'cancelled' | 'rejected' | 'not-found' | 'error';
|
|
356
|
+
/**
|
|
357
|
+
* One connect attempt, for your metrics. Deliberately nothing else: no identity key, address, paymail, handle,
|
|
358
|
+
* origin or error text. `walletType`/`substrate` are null when no wallet was chosen (chooser closed, nothing found).
|
|
359
|
+
*/
|
|
360
|
+
interface ConnectAttempt {
|
|
361
|
+
walletType: string | null;
|
|
362
|
+
substrate: Substrate | null;
|
|
363
|
+
outcome: AttemptOutcome;
|
|
364
|
+
/** From the tap to the outcome, rounded to whole ms. */
|
|
365
|
+
ms: number;
|
|
366
|
+
}
|
|
367
|
+
type AttemptHook = (attempt: ConnectAttempt) => void;
|
|
368
|
+
/** The outcome for an error thrown by a connect attempt. */
|
|
369
|
+
declare function outcomeOf(e: unknown): AttemptOutcome;
|
|
370
|
+
/** Build the attempt record for `option` (or none). */
|
|
371
|
+
declare function attemptFor(option: WalletOption | null | undefined, outcome: AttemptOutcome, startedAt: number, now?: number): ConnectAttempt;
|
|
372
|
+
/** Call the hook with exactly the four fields; a throwing hook never breaks sign-in. */
|
|
373
|
+
declare function reportAttempt(hook: AttemptHook | undefined, a: ConnectAttempt): void;
|
|
374
|
+
/** localStorage key (per origin, like all localStorage) for the wallet type picked here. Never holds a key. */
|
|
375
|
+
declare const WALLET_CHOICE_KEY = "bwx:wallet";
|
|
376
|
+
/** What is remembered: the wallet type and how it reached the page. Nothing that identifies the user. */
|
|
377
|
+
interface RememberedWallet {
|
|
378
|
+
type: string;
|
|
379
|
+
substrate: Substrate;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* True when the same wallet can be found again next time: bWalletX, an announced wallet (by its rdns), a desktop
|
|
383
|
+
* wallet, an app adapter. A bare window.CWI cannot (whoever holds it next time may be another wallet), so it is
|
|
384
|
+
* never remembered.
|
|
385
|
+
*/
|
|
386
|
+
declare function isRememberable(o: WalletOption): boolean;
|
|
387
|
+
/** Whether a successful connect counts as the user's explicit pick: bWalletX (they tapped its button), or chosen. */
|
|
388
|
+
declare function isExplicitPick(o: WalletOption, reason: ChoiceReason): boolean;
|
|
389
|
+
/** Remember the wallet type picked on this origin (or forget with null). Silently skips what can't be remembered. */
|
|
390
|
+
declare function rememberWalletChoice(o: WalletOption | null): void;
|
|
391
|
+
/** The wallet type picked on this origin before, or null. Anything malformed or key-like is ignored. */
|
|
392
|
+
declare function rememberedWalletChoice(): RememberedWallet | null;
|
|
393
|
+
/** Forget the remembered wallet (Disconnect does this). */
|
|
394
|
+
declare function forgetWalletChoice(): void;
|
|
395
|
+
/** True when this wallet type is not bWalletX: show "Some features need bWalletX · Switch". */
|
|
396
|
+
declare function needsBwalletX(type: string | null | undefined): boolean;
|
|
397
|
+
/**
|
|
398
|
+
* (0.7.0) True when the signed-out button's tap goes to this remembered wallet instead of bWalletX ("Continue with your
|
|
399
|
+
* wallet", the Switch note). Never for Metanet: the button never picks it (it has its own link and "Not you?").
|
|
400
|
+
*/
|
|
401
|
+
declare function tapGoesElsewhere(type: string | null | undefined): boolean;
|
|
402
|
+
/** (0.7.0) A remembered desktop wallet on localhost (Metanet, 'desktop', json-api, cicada): never the button's pick. */
|
|
403
|
+
declare function isLocalDesktopType(r: RememberedWallet): boolean;
|
|
404
|
+
/**
|
|
405
|
+
* The option in `list` for a remembered wallet, or null when it isn't here. bWalletX counts only by its own marker
|
|
406
|
+
* (or the phone, when the phone was picked). A remembered desktop wallet on localhost (Metanet / 'desktop') gives null
|
|
407
|
+
* (0.7.0): the button never picks it; its own link does.
|
|
408
|
+
*/
|
|
409
|
+
declare function matchRemembered(list: readonly WalletOption[], r: RememberedWallet): WalletOption | null;
|
|
410
|
+
/**
|
|
411
|
+
* What to do on page load for a returning visitor (0.6.0).
|
|
412
|
+
* 'attach' signed in already (a server session) and the remembered wallet is in the page: pick it up by
|
|
413
|
+
* discovery alone (no wallet call, so no prompt) so pay/tip work without another tap;
|
|
414
|
+
* 'wait-for-tap' anything else a wallet would have to answer (a key, a signature, a localhost probe, a relay
|
|
415
|
+
* reconnect): nothing fires; the next tap goes straight to the remembered wallet;
|
|
416
|
+
* 'silent-metanet' (0.7.0) Metanet Desktop remembered, on a computer outside any frame: ONE silent attempt this page
|
|
417
|
+
* load (trySilentMetanet: 2 s, known identity keys only), else the normal choice;
|
|
418
|
+
* 'none' nothing remembered, or auto-connect off (or Metanet remembered where it isn't offered).
|
|
419
|
+
*/
|
|
420
|
+
type AutoConnectAction = 'attach' | 'wait-for-tap' | 'silent-metanet' | 'none';
|
|
421
|
+
interface AutoConnectPlan {
|
|
422
|
+
action: AutoConnectAction;
|
|
423
|
+
remembered: RememberedWallet | null;
|
|
424
|
+
/** The remembered wallet isn't bWalletX: show "Some features need bWalletX · Switch". */
|
|
425
|
+
needsBwalletX: boolean;
|
|
426
|
+
}
|
|
427
|
+
declare function planAutoConnect(o: {
|
|
428
|
+
remembered: RememberedWallet | null;
|
|
429
|
+
signedIn: boolean;
|
|
430
|
+
enabled?: boolean;
|
|
431
|
+
/** (0.7.0) Metanet is offered here (a computer, outside any frame). Default metanetOffered(). */
|
|
432
|
+
metanetHere?: boolean;
|
|
433
|
+
}): AutoConnectPlan;
|
|
434
|
+
/**
|
|
435
|
+
* Find the remembered wallet in the page by discovery alone: no wallet method is called, nothing touches localhost,
|
|
436
|
+
* no relay is opened. null when it isn't here (or it isn't something that can be attached silently).
|
|
437
|
+
*/
|
|
438
|
+
declare function attachRemembered(r: RememberedWallet, o?: {
|
|
439
|
+
ms?: number;
|
|
440
|
+
}): Promise<WalletOption | null>;
|
|
441
|
+
|
|
442
|
+
export { hasBwalletX as $, type AttemptHook as A, type BuyTokenRequest as B, type ConnectedWallet as C, DESKTOP_OPTION_ID as D, type SocketFactory as E, type SocketLike as F, WALLET_CHOICE_KEY as G, type HandCashAdapterOptions as H, type WalletChoice as I, type WalletKind as J, amountInSats as K, type LegacyPayer as L, attachRemembered as M, NO_COINS_TEXT as N, attemptFor as O, type PayRequest as P, buyToken as Q, type RememberedWallet as R, type Substrate as S, type TokenQuote as T, chooserOrder as U, clearPairing as V, type WalletOption as W, cwiIsAnnounced as X, decideWallet as Y, desktopOption as Z, forgetWalletChoice as _, type PayResult as a, isExplicitPick as a0, isIdentityKeyHex as a1, isInsufficientFunds as a2, isLocalDesktop as a3, isLocalDesktopType as a4, isPaymail as a5, isPresentBwalletX as a6, isRememberable as a7, matchRemembered as a8, needsBwalletX as a9, otherDetected as aa, outcomeOf as ab, pairBwalletX as ac, pay as ad, planAutoConnect as ae, rememberWalletChoice as af, rememberedWalletChoice as ag, reportAttempt as ah, resolvePaymailP2P as ai, restorePairing as aj, substrateOf as ak, tapGoesElsewhere as al, tip as am, walletTypeOf as an, type PayOptions as b, PaymentError as c, autoChoice as d, brc100Option as e, discoverWallets as f, type PairingOptions as g, handcashAdapter as h, type ChoiceReason as i, type AttemptOutcome as j, type AutoConnectAction as k, type AutoConnectPlan as l, BRC29_PROTOCOL as m, BWALLETX_TYPE as n, type Brc29Remittance as o, pairingOption as p, type ConnectAttempt as q, type ConnectOptions as r, type DecideWalletOptions as s, type DiscoverWalletsOptions as t, type PairConnectionOptions as u, type PairStorage as v, type PairedWallet as w, type PayOutput as x, type PaySource as y, type PaymentErrorCode as z };
|