@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
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { WalletInterface, WalletProtocol } from '@bsv/sdk';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { AuthorizeParams, GET_URL, SIGNIN_CSS, SIGNIN_TAG, SigninBrand, SigninLabel, SigninSize, SigninTheme, WEB_WALLET_URL, buildAuthorizeUrl, defineBwalletxSignin, markSvg, signinText } from './element.js';
|
|
2
|
+
import { g as PairingOptions, W as WalletOption, R as RememberedWallet, A as AttemptHook, C as ConnectedWallet, S as Substrate, i as ChoiceReason } from './choice-B97AjqF4.js';
|
|
3
|
+
export { j as AttemptOutcome, k as AutoConnectAction, l as AutoConnectPlan, m as BRC29_PROTOCOL, n as BWALLETX_TYPE, o as Brc29Remittance, B as BuyTokenRequest, q as ConnectAttempt, r as ConnectOptions, D as DESKTOP_OPTION_ID, s as DecideWalletOptions, t as DiscoverWalletsOptions, H as HandCashAdapterOptions, L as LegacyPayer, N as NO_COINS_TEXT, u as PairConnectionOptions, v as PairStorage, w as PairedWallet, b as PayOptions, x as PayOutput, P as PayRequest, a as PayResult, y as PaySource, c as PaymentError, z as PaymentErrorCode, E as SocketFactory, F as SocketLike, T as TokenQuote, G as WALLET_CHOICE_KEY, I as WalletChoice, J as WalletKind, K as amountInSats, M as attachRemembered, O as attemptFor, d as autoChoice, e as brc100Option, Q as buyToken, U as chooserOrder, V as clearPairing, X as cwiIsAnnounced, Y as decideWallet, Z as desktopOption, f as discoverWallets, _ as forgetWalletChoice, h as handcashAdapter, $ as hasBwalletX, a0 as isExplicitPick, a1 as isIdentityKeyHex, a2 as isInsufficientFunds, a3 as isLocalDesktop, a4 as isLocalDesktopType, a5 as isPaymail, a6 as isPresentBwalletX, a7 as isRememberable, a8 as matchRemembered, a9 as needsBwalletX, aa as otherDetected, ab as outcomeOf, ac as pairBwalletX, p as pairingOption, ad as pay, ae as planAutoConnect, af as rememberWalletChoice, ag as rememberedWalletChoice, ah as reportAttempt, ai as resolvePaymailP2P, aj as restorePairing, ak as substrateOf, al as tapGoesElsewhere, am as tip, an as walletTypeOf } from './choice-B97AjqF4.js';
|
|
4
|
+
export { A as AuthorizeParams, C as CONTINUE_OTHER_LABEL, G as GET_URL, M as MENU_CSS, P as PENDING_LABEL, e as PENDING_LABEL_OTHER, f as PENDING_NOTE, g as SIGNIN_CSS, h as SIGNIN_TAG, i as SWITCH_NOTE, j as SigninAccount, c as SigninBrand, b as SigninLabel, k as SigninMode, S as SigninSize, d as SigninState, a as SigninTheme, W as WEB_WALLET_URL, l as buildAuthorizeUrl, m as defineBwalletxSignin, n as markSvg, s as signinText } from './element-BXEoOdXY.js';
|
|
5
|
+
export { BUTTON_TAG, ButtonState, CONNECTED_KEY, defineBwalletxButton, dropLegacyConnectedKey, getUrlFor, handleLabel, migrateConnectedKey, stateFor } from './element.js';
|
|
5
6
|
import { b as AccessResponse, H as HoldingProof, A as AccessError } from './access-Dp0eKIOc.js';
|
|
6
7
|
export { f as ACCESS_ERROR_STATUS, d as ACCESS_PROTOCOL, g as ACCESS_VERSION, h as AccessChallenge, i as AccessErrorBody, j as AccessErrorCode, c as AccessKind, a as AccessRequirement, P as PROTOCOL_MEDIA, T as TokenRequirement, k as accessErrorMessage, m as canonicalJson, r as protocolMediaUrl } from './access-Dp0eKIOc.js';
|
|
7
8
|
|
|
@@ -17,16 +18,21 @@ interface FoundWallet {
|
|
|
17
18
|
rdns: string | null;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
* Default wait for a wallet that has not answered yet, ms. bWalletX for Chrome
|
|
21
|
-
*
|
|
21
|
+
* Default wait for a wallet that has not answered yet, ms. bWalletX for Chrome and the in-app browser both answer
|
|
22
|
+
* `brc100:requestWallet` synchronously, so a found wallet resolves at once;
|
|
22
23
|
* this is only how long "nothing here" takes before the pairing QR shows. Was 1200 (0.5.3 and earlier).
|
|
23
24
|
*/
|
|
24
25
|
declare const DEFAULT_DISCOVER_MS = 300;
|
|
25
26
|
/**
|
|
26
27
|
* Like findBwalletX, but also says which bWalletX answered.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
*
|
|
29
|
+
* bWalletX is recognised ONLY by its own markers: a BRC-100 announcement carrying a bWalletX rdns
|
|
30
|
+
* (`com.bwalletx.extension` from the Chrome extension, `space.bwallet.mobile` from the in-app browser; both answer
|
|
31
|
+
* `brc100:requestWallet` at once), or, only when framed, the XDM answer of a parent on BWALLETX_PARENT_ORIGINS.
|
|
32
|
+
*
|
|
33
|
+
* Never by `window.CWI` (0.5.6): another wallet (Metanet / BSV Desktop, Yours) can set or overwrite it, and treating
|
|
34
|
+
* whoever holds it as bWalletX handed our sign-in to that wallet. Every bWalletX build since 3 Oct 2026 announces.
|
|
35
|
+
* Resolves null after `ms` when no bWalletX announced (other wallets: discoverWallets).
|
|
30
36
|
*/
|
|
31
37
|
declare function discoverBwalletX(ms?: number): Promise<FoundWallet | null>;
|
|
32
38
|
/**
|
|
@@ -34,6 +40,8 @@ declare function discoverBwalletX(ms?: number): Promise<FoundWallet | null>;
|
|
|
34
40
|
* open in bWalletX's in-app browser. Resolves null if nothing answered within `ms`.
|
|
35
41
|
*/
|
|
36
42
|
declare function findBwalletX(ms?: number): Promise<WalletInterface | null>;
|
|
43
|
+
/** True inside a frame (or when the parent can't be read). */
|
|
44
|
+
declare const isFramed: () => boolean;
|
|
37
45
|
/**
|
|
38
46
|
* Wake the wallet before the click (call on pointerenter / focus / touchstart of your Connect button). Chrome stops an
|
|
39
47
|
* idle extension worker after ~30 s, and a cold worker needs 1-3 s to reopen the wallet; this sends a liveness call
|
|
@@ -57,12 +65,32 @@ type SignInMethod = 'extension' | 'in-app' | 'pairing' | 'wallet';
|
|
|
57
65
|
/**
|
|
58
66
|
* Progress for the button label. 'finding': looking for a wallet (sub-second); 'opening': a wallet was found and its
|
|
59
67
|
* approval is on the way ("Opening your wallet…"); 'pairing': no wallet in this browser, the QR is showing;
|
|
60
|
-
* 'signing': the
|
|
68
|
+
* 'signing': the challenge arrived, the wallet's sign-in approval is being asked for.
|
|
61
69
|
*/
|
|
62
70
|
type SignInStatus = 'finding' | 'opening' | 'pairing' | 'signing';
|
|
63
71
|
interface SignInOptions {
|
|
64
|
-
/**
|
|
65
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Ask your server for a challenge. Since 0.5.5 it is called BEFORE the wallet is asked anything, and gets an identity
|
|
74
|
+
* key only when you pass `identityKey` (an identity you already connected) or set `challengeNeedsIdentityKey`;
|
|
75
|
+
* otherwise undefined. The 0.5.5 server helpers (createChallenge) accept no key, and verifySignIn binds the key the
|
|
76
|
+
* browser then claims to the signature. A pre-0.5.5 server that refuses a keyless challenge is detected and retried
|
|
77
|
+
* in the old order automatically.
|
|
78
|
+
*/
|
|
79
|
+
challenge(identityKey?: string): Promise<Challenge>;
|
|
80
|
+
/**
|
|
81
|
+
* The identity key you already have from an earlier connect (reuse the connected identity): the wallet is then asked
|
|
82
|
+
* for the signature only. Without it, getPublicKey({ identityKey: true }) and createSignature go to the wallet
|
|
83
|
+
* together (Promise.all), so the wallet shows ONE sheet, not three.
|
|
84
|
+
*/
|
|
85
|
+
identityKey?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Servers older than 0.5.5 refuse a challenge without an identity key. Set true to use the old order straight away
|
|
88
|
+
* (identity key, then the challenge, then the signature: two wallet calls). Without it, the old order is used only
|
|
89
|
+
* after such a server has refused a keyless challenge.
|
|
90
|
+
*/
|
|
91
|
+
challengeNeedsIdentityKey?: boolean;
|
|
92
|
+
/** Skip waitForAuthentication before signing (the provider already waited). Default false. */
|
|
93
|
+
skipWaitForAuthentication?: boolean;
|
|
66
94
|
/** Use this wallet instead of looking for one. `method` is then 'wallet'. */
|
|
67
95
|
wallet?: WalletInterface;
|
|
68
96
|
/** How to show the QR and code if pairing is needed. Without it, pairing is not tried. */
|
|
@@ -89,10 +117,41 @@ declare function connectBwalletX(opts?: Pick<SignInOptions, 'wallet' | 'pairing'
|
|
|
89
117
|
method: SignInMethod;
|
|
90
118
|
}>;
|
|
91
119
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
120
|
+
* Wait for the user to unlock only when the wallet says it is locked. isAuthenticated never shows anything; an
|
|
121
|
+
* unconditional waitForAuthentication is not free: bWalletX answers it by fetching the site's manifest.json and, when
|
|
122
|
+
* that asks for permissions, shows a separate sheet, once per call.
|
|
123
|
+
*/
|
|
124
|
+
declare function waitIfLocked(wallet: WalletInterface): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* True when a server refused a challenge because it wanted an identity key (createChallenge before 0.5.5 answers 400
|
|
127
|
+
* "identityKey must be a compressed public key (66 hex chars)").
|
|
128
|
+
*/
|
|
129
|
+
declare function challengeWantsIdentityKey(e: unknown): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Sign the server's challenge with the user's bWalletX identity key. Post the result's identityKey, nonce and
|
|
132
|
+
* signature to your verify route.
|
|
133
|
+
*
|
|
134
|
+
* Wallet calls, in order:
|
|
135
|
+
* 1. the challenge comes from your server first (no wallet call);
|
|
136
|
+
* 2. getPublicKey({ identityKey: true }) and createSignature go to the wallet TOGETHER, so the wallet merges them
|
|
137
|
+
* into one approval. With `identityKey` (already connected) only createSignature is asked for.
|
|
94
138
|
*/
|
|
95
139
|
declare function signInWithBwalletX(opts: SignInOptions): Promise<SignInResult>;
|
|
140
|
+
interface SignInAndVerifyOptions extends SignInOptions {
|
|
141
|
+
/** POST the result to your verify route; resolve with its JSON. A 401 (status on the error) means "sign-in failed". */
|
|
142
|
+
verify: (r: SignInResult) => Promise<Record<string, unknown>>;
|
|
143
|
+
/**
|
|
144
|
+
* A remembered identity key (rememberedIdentity()). Used like `identityKey` (one wallet call: the signature only),
|
|
145
|
+
* but if the server rejects the signature (another account is active now), it is dropped and the sign-in is retried
|
|
146
|
+
* with the key asked for.
|
|
147
|
+
*/
|
|
148
|
+
identityKeyHint?: string;
|
|
149
|
+
}
|
|
150
|
+
/** signInWithBwalletX + your verify route, with the identity-hint fallback. */
|
|
151
|
+
declare function signInAndVerify(opts: SignInAndVerifyOptions): Promise<{
|
|
152
|
+
result: SignInResult;
|
|
153
|
+
verified: Record<string, unknown>;
|
|
154
|
+
}>;
|
|
96
155
|
/** Where a sign-in failed: the wallet's identity prompt, the site's challenge endpoint, or the wallet's signature. */
|
|
97
156
|
type SignInStage = 'identity' | 'challenge' | 'signature' | 'verify';
|
|
98
157
|
|
|
@@ -115,8 +174,39 @@ declare function renderButton(el: HTMLElement | string, opts?: ButtonOptions): H
|
|
|
115
174
|
*/
|
|
116
175
|
declare function inOrder<T>(handle: (frame: T) => Promise<void> | void, onError?: (e: unknown) => void): (frame: T) => Promise<void>;
|
|
117
176
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
177
|
+
/**
|
|
178
|
+
* The signed-in account as the badge shows it: paymail (best-effort lookup by identity key), a $handle label, a short
|
|
179
|
+
* key when there is no paymail, and the bAvatar picture (gold by default, generated for any key).
|
|
180
|
+
*/
|
|
181
|
+
declare const PAYMAIL_LOOKUP_URL = "https://pay.bwallet.space/api/paymail/lookup?key=";
|
|
182
|
+
declare const BAVATAR_URL = "https://chat.bwalletx.com/api/bavatar/";
|
|
183
|
+
/** 0266c1…7c83 */
|
|
184
|
+
declare function shortKey(key: string): string;
|
|
185
|
+
/** $alice for alice@bwalletx.com, a site handle as given, other paymails in full, else a short key. */
|
|
186
|
+
declare function accountLabel(a: {
|
|
187
|
+
identityKey?: string | null;
|
|
188
|
+
paymail?: string | null;
|
|
189
|
+
handle?: string | null;
|
|
190
|
+
}): string;
|
|
191
|
+
/** The bAvatar for an identity key (a generated gold avatar when the user has not set one). */
|
|
192
|
+
declare function avatarUrlFor(identityKey: string | null | undefined): string | null;
|
|
193
|
+
/** The paymail for an identity key, or null. Best effort: never throws, one request per key per page. */
|
|
194
|
+
declare function lookupPaymail(identityKey: string, url?: string): Promise<string | null>;
|
|
195
|
+
/** True when the user said no in the wallet (BRC-100 denial, or a picker / sheet closed). */
|
|
196
|
+
declare function isUserRejection(e: unknown): boolean;
|
|
197
|
+
/** One plain line for an error: "Sign-in cancelled" for a no in the wallet, otherwise the gist. */
|
|
198
|
+
declare function signInErrorText(e: unknown): string;
|
|
199
|
+
/** localStorage key for the identity key that last signed in on this site (public data; a hint, never trusted). */
|
|
200
|
+
declare const IDENTITY_HINT_KEY = "bwx:identityKey";
|
|
201
|
+
/**
|
|
202
|
+
* The identity key that last signed in on this site, if any. Passing it to signInWithBwalletX makes a repeat sign-in
|
|
203
|
+
* ONE wallet call (createSignature only). It is only a hint: the server still checks the signature against it, and a
|
|
204
|
+
* wrong hint (another account) fails verification and is retried with the key asked for.
|
|
205
|
+
*/
|
|
206
|
+
declare function rememberedIdentity(): string | undefined;
|
|
207
|
+
declare function rememberIdentity(key: string | null): void;
|
|
208
|
+
|
|
209
|
+
/** Device checks shared by the modal and the Metanet Desktop option (no DOM created here). */
|
|
120
210
|
/**
|
|
121
211
|
* True on a phone or tablet: a coarse pointer with no hover, or a mobile user agent (iPadOS reports
|
|
122
212
|
* a Mac UA, so touch points count too). Scanning a QR shown on the same screen is impossible there.
|
|
@@ -125,6 +215,9 @@ declare function isTouchDevice(env?: {
|
|
|
125
215
|
navigator?: Navigator;
|
|
126
216
|
matchMedia?: (q: string) => MediaQueryList;
|
|
127
217
|
}): boolean;
|
|
218
|
+
|
|
219
|
+
/** An SVG QR code for `text` (error correction M). */
|
|
220
|
+
declare function qrSvg(text: string): string;
|
|
128
221
|
interface PairingModalOptions {
|
|
129
222
|
title?: string;
|
|
130
223
|
/**
|
|
@@ -149,6 +242,25 @@ declare function pairingModal(o?: PairingModalOptions): PairingOptions & {
|
|
|
149
242
|
declare function pickWallet(options: WalletOption[], o?: {
|
|
150
243
|
title?: string;
|
|
151
244
|
}): Promise<WalletOption | null>;
|
|
245
|
+
interface ChooseWalletOptions {
|
|
246
|
+
/** Default "Choose a wallet". */
|
|
247
|
+
title?: string;
|
|
248
|
+
/** Where "Get bWalletX" points. Default https://bwalletx.com/get */
|
|
249
|
+
getUrl?: string;
|
|
250
|
+
/**
|
|
251
|
+
* Offer "Use Metanet Desktop or another BRC-100 wallet" (0.7.0; was "Desktop wallet"). Default true. It calls
|
|
252
|
+
* localhost:3321 only when tapped (metanetOption), never while the chooser opens, and is never shown on a phone or
|
|
253
|
+
* inside a frame.
|
|
254
|
+
*/
|
|
255
|
+
desktop?: boolean;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* The wallet chooser (0.5.6). Without bWalletX in this browser, "Get bWalletX" comes first; then bWalletX on the
|
|
259
|
+
* phone, the other wallets that were detected, "Use Metanet Desktop or another BRC-100 wallet" (0.7.0: localhost:3321
|
|
260
|
+
* only when tapped; computers only) and app-supplied options. Opened from "Other wallets" while bWalletX is here, bWalletX is the first, gold row.
|
|
261
|
+
* Resolves with the chosen option, or null when closed. "Get bWalletX" is a link and leaves the chooser open.
|
|
262
|
+
*/
|
|
263
|
+
declare function chooseWallet(options: readonly WalletOption[], o?: ChooseWalletOptions): Promise<WalletOption | null>;
|
|
152
264
|
|
|
153
265
|
/**
|
|
154
266
|
* Browser side of the access protocol: ask the wallet to sign the site's challenge and prove the
|
|
@@ -201,4 +313,199 @@ declare const WALLET_THEME_META = "bwalletx-theme";
|
|
|
201
313
|
/** Declare (or with null, withdraw) the theme the wallet should wear for this page. No-op outside a browser. */
|
|
202
314
|
declare function declareWalletTheme(theme: string | null | undefined): void;
|
|
203
315
|
|
|
204
|
-
|
|
316
|
+
/**
|
|
317
|
+
* 0.7.0: "Use Metanet Desktop or another BRC-100 wallet" (owner, 6 Nov 2026: "ship a new one now with the metanet
|
|
318
|
+
* option"). The same rules as the live bChatX door (bit-sign src/lib/metanet-door.ts):
|
|
319
|
+
*
|
|
320
|
+
* 1. bWalletX stays the default. It is found by its own announcement only, never by window.CWI, and the gold
|
|
321
|
+
* button's discovery NEVER picks Metanet (matchRemembered returns null for it).
|
|
322
|
+
* 2. A visible, explicit choice. PINNED to WalletClient('json-api') on localhost:3321, never 'auto': 'auto' races
|
|
323
|
+
* the substrates starting with window.CWI, so the bWalletX extension would silently win and this would be a
|
|
324
|
+
* label, not a choice. On a first visit it connects ONLY on its own tap; nothing calls :3321 on page load.
|
|
325
|
+
* 3. After a successful connect: the wallet TYPE for this origin (bwx:wallet = { type: 'metanet', substrate:
|
|
326
|
+
* 'json-api' }) plus the identity keys known on this origin (bwx:known-keys). Public keys only; never a secret.
|
|
327
|
+
* 4. Back with Metanet remembered: at most ONE silent attempt per page load, a 2 s window, and it goes on only if the
|
|
328
|
+
* identity key Metanet returns is already known here. Whatever answers on :3321 could be another profile, our own
|
|
329
|
+
* `bwalletx serve` agent wallet or any local process; letting an unknown key sign in silently would land the
|
|
330
|
+
* person in THAT key's account (login CSRF). Any failure is silent: no banner, no retry.
|
|
331
|
+
* 5. "Not you? Use another wallet" and Disconnect forget the choice.
|
|
332
|
+
* 6. Offered only on a computer and outside any frame (Metanet Desktop is a desktop app).
|
|
333
|
+
* 7. The minimum asked: getVersion (is it running?), isAuthenticated (never prompts), the identity public key, then
|
|
334
|
+
* whatever the site's own call needs (the sign-in signature). No protocol permission requests at connect, and the
|
|
335
|
+
* calls go one at a time: two prompts at once is how Metanet Desktop froze on a "Trust" sheet (6 Nov 2026).
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
/** The wallet type remembered for Metanet Desktop (and any BRC-100 wallet serving the JSON API on :3321). */
|
|
339
|
+
declare const METANET_TYPE = "metanet";
|
|
340
|
+
/** WalletOption.id of the Metanet option. */
|
|
341
|
+
declare const METANET_OPTION_ID = "metanet";
|
|
342
|
+
/** Where Metanet Desktop serves the BRC-100 JSON API. */
|
|
343
|
+
declare const METANET_JSON_API = "http://localhost:3321";
|
|
344
|
+
declare const METANET_LABEL = "Use Metanet Desktop or another BRC-100 wallet";
|
|
345
|
+
declare const METANET_NOTE = "Metanet Desktop must be running on this computer";
|
|
346
|
+
/** Shown when Metanet is the wallet remembered on this site. */
|
|
347
|
+
declare const METANET_REMEMBERED_NOTE = "Signs in with Metanet Desktop on this computer.";
|
|
348
|
+
declare const NOT_YOU_LABEL = "Not you? Use another wallet";
|
|
349
|
+
declare const METANET_UNREACHABLE = "We couldn\u2019t reach Metanet Desktop. Open it, then try again.";
|
|
350
|
+
/** How long Metanet Desktop has to answer getVersion after a tap. */
|
|
351
|
+
declare const METANET_ANSWER_MS = 4000;
|
|
352
|
+
/** The silent attempt's whole window (reachable, unlocked, identity key): short, since nobody asked for it. */
|
|
353
|
+
declare const METANET_SILENT_MS = 2000;
|
|
354
|
+
/** Nothing answered on localhost:3321 in time. `code` is NOT_FOUND, like every "no wallet here". */
|
|
355
|
+
declare class MetanetUnreachableError extends Error {
|
|
356
|
+
readonly code = "NOT_FOUND";
|
|
357
|
+
constructor();
|
|
358
|
+
}
|
|
359
|
+
/** Inside any frame at all (bWalletX's or anyone's), or the top can't be read. */
|
|
360
|
+
/** The two window fields the frame check reads. */
|
|
361
|
+
type FrameWindow = {
|
|
362
|
+
readonly self: unknown;
|
|
363
|
+
readonly top: unknown;
|
|
364
|
+
};
|
|
365
|
+
declare function inAnyFrame(win?: FrameWindow | undefined): boolean;
|
|
366
|
+
/** Where the Metanet option is offered at all: a browser on a computer (not a phone or tablet), outside any frame. */
|
|
367
|
+
declare function metanetOffered(env?: {
|
|
368
|
+
navigator?: Navigator;
|
|
369
|
+
matchMedia?: (q: string) => MediaQueryList;
|
|
370
|
+
window?: FrameWindow;
|
|
371
|
+
}): boolean;
|
|
372
|
+
interface MetanetOptions {
|
|
373
|
+
/** This site's host, as WalletClient's originator (the browser sets the real Origin header). Default location.host. */
|
|
374
|
+
originator?: string;
|
|
375
|
+
/** How long Metanet has to answer getVersion. Default METANET_ANSWER_MS. */
|
|
376
|
+
timeoutMs?: number;
|
|
377
|
+
/** Tests and custom hosts: stands in for `new WalletClient('json-api', originator)`. */
|
|
378
|
+
make?: () => WalletInterface;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The wallet on localhost:3321 once it has answered getVersion; MetanetUnreachableError if nothing does in time.
|
|
382
|
+
* ⚠ WalletClient builds a pinned substrate in its constructor, so connectToSubstrate proves nothing: this asks.
|
|
383
|
+
*/
|
|
384
|
+
declare function connectMetanetDesktop(o?: MetanetOptions): Promise<WalletInterface>;
|
|
385
|
+
/**
|
|
386
|
+
* "Use Metanet Desktop or another BRC-100 wallet" as a WalletOption. Nothing touches localhost until connect() runs,
|
|
387
|
+
* i.e. after the tap. connect() always asks for the identity key first, on its own (also with `{ identity: false }`):
|
|
388
|
+
* the sign-in then asks for the signature alone, so Metanet never gets two requests at once.
|
|
389
|
+
*/
|
|
390
|
+
declare function metanetOption(o?: MetanetOptions): WalletOption;
|
|
391
|
+
/** localStorage key (per origin) for the identity keys that connected or signed in here. Public keys only. */
|
|
392
|
+
declare const KNOWN_KEYS_KEY = "bwx:known-keys";
|
|
393
|
+
/** The identity keys known on this origin, newest first. */
|
|
394
|
+
declare function knownIdentityKeys(): string[];
|
|
395
|
+
/** True when this identity key connected or signed in on this origin before (or is the last sign-in's key). */
|
|
396
|
+
declare function isKnownIdentityKey(key: string | null | undefined): boolean;
|
|
397
|
+
/** Add an identity key to this origin's known keys (after a successful connect or sign-in). */
|
|
398
|
+
declare function rememberKnownIdentityKey(key: string | null | undefined): void;
|
|
399
|
+
/** True once this page load's one silent attempt has been used (however many buttons or providers mount). */
|
|
400
|
+
declare function silentAttemptUsed(): boolean;
|
|
401
|
+
/** Claim this page load's one silent attempt. False if it was already used. */
|
|
402
|
+
declare function claimSilentAttempt(): boolean;
|
|
403
|
+
/** Tests only (and a single-page app that wants a fresh "page load"). */
|
|
404
|
+
declare function resetSilentAttempt(): void;
|
|
405
|
+
/** Why a silent attempt stopped. Every one of them is silent: the normal choice stays on screen. */
|
|
406
|
+
type SilentStop = 'used' | 'not-here' | 'unreachable' | 'locked' | 'slow' | 'unknown-key';
|
|
407
|
+
type SilentMetanetResult = {
|
|
408
|
+
ok: true;
|
|
409
|
+
wallet: WalletInterface;
|
|
410
|
+
identityKey: string;
|
|
411
|
+
} | {
|
|
412
|
+
ok: false;
|
|
413
|
+
stop: SilentStop;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* The silent part of a return visit: claim the page load's one attempt, then, within `windowMs` (2 s) in all,
|
|
417
|
+
* Metanet must answer getVersion, say it is unlocked (isAuthenticated, which never prompts) and return an identity
|
|
418
|
+
* key already known on this origin. Never waits for an unlock, never asks for anything else, never throws.
|
|
419
|
+
*/
|
|
420
|
+
declare function trySilentMetanet(o?: MetanetOptions & {
|
|
421
|
+
windowMs?: number;
|
|
422
|
+
}): Promise<SilentMetanetResult>;
|
|
423
|
+
/**
|
|
424
|
+
* (0.7.0) A sign-in with a verify route and no logout route: "Not you?" (and Disconnect) cannot end a session the
|
|
425
|
+
* verify route already set, so the person stays signed in as the key they just rejected. Warns once per page, in
|
|
426
|
+
* development only. Returns true when it warned.
|
|
427
|
+
*/
|
|
428
|
+
declare function warnIfNoLogout(o: {
|
|
429
|
+
verifyUrl?: string | null;
|
|
430
|
+
logoutUrl?: string | null;
|
|
431
|
+
where: string;
|
|
432
|
+
}): boolean;
|
|
433
|
+
|
|
434
|
+
interface ConnectFlowOptions {
|
|
435
|
+
/** The wallets found (discoverWallets). */
|
|
436
|
+
list: WalletOption[];
|
|
437
|
+
/** Connect this option without asking. */
|
|
438
|
+
walletId?: string;
|
|
439
|
+
/** false: never show the chooser (bWalletX, else the phone; never another wallet unasked). Default true. */
|
|
440
|
+
picker?: boolean;
|
|
441
|
+
/** "Other wallets": show the chooser even when bWalletX is here. */
|
|
442
|
+
chooser?: boolean;
|
|
443
|
+
/**
|
|
444
|
+
* bWalletX first (0.5.6, default true): bWalletX in this browser is connected with no chooser; without it the
|
|
445
|
+
* chooser opens ("Get bWalletX" first) and no other wallet is connected unless picked. false: the 0.5.5 rule.
|
|
446
|
+
*/
|
|
447
|
+
fastPath?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* (0.6.0) The wallet picked on this origin before (rememberedWalletChoice()). When it is here, the tap goes straight
|
|
450
|
+
* to it, with no chooser, even when it isn't bWalletX (the user chose it).
|
|
451
|
+
*/
|
|
452
|
+
remembered?: RememberedWallet | null;
|
|
453
|
+
/** (0.6.0) After a successful connect the user explicitly picked, remember the wallet type for this origin. */
|
|
454
|
+
remember?: boolean;
|
|
455
|
+
/** (0.6.0) "Switch" to bWalletX: ignore a remembered other wallet (bWalletX here, else the chooser). */
|
|
456
|
+
preferBwalletX?: boolean;
|
|
457
|
+
/**
|
|
458
|
+
* (0.7.0) The user tapped "Use Metanet Desktop or another BRC-100 wallet": connect to localhost:3321 (pinned
|
|
459
|
+
* 'json-api', never 'auto'), with no chooser. Rejects NOT_SUPPORTED on a phone or inside a frame.
|
|
460
|
+
*/
|
|
461
|
+
metanet?: boolean | MetanetOptions;
|
|
462
|
+
/** Show the chooser; resolves null when closed. chooseWallet (modal.ts) or your own UI. */
|
|
463
|
+
pick: (list: WalletOption[]) => Promise<WalletOption | null>;
|
|
464
|
+
/** With verifyUrl: sign in after connecting. */
|
|
465
|
+
challengeUrl?: string;
|
|
466
|
+
verifyUrl?: string;
|
|
467
|
+
challengeNeedsIdentityKey?: boolean;
|
|
468
|
+
/** POST JSON; throws with `status` on a non-2xx answer. */
|
|
469
|
+
post: (url: string, body: unknown) => Promise<Record<string, unknown>>;
|
|
470
|
+
/** Called once per attempt with { walletType, substrate, outcome, ms }. No keys, addresses or identity data. */
|
|
471
|
+
onAttempt?: AttemptHook;
|
|
472
|
+
}
|
|
473
|
+
interface ConnectFlowResult {
|
|
474
|
+
connected: ConnectedWallet;
|
|
475
|
+
identityKey: string | null;
|
|
476
|
+
handle: string | null;
|
|
477
|
+
paymail: string | null;
|
|
478
|
+
signedIn: boolean;
|
|
479
|
+
/** 'bwalletx' for bWalletX, else the wallet's rdns / option id. */
|
|
480
|
+
walletType: string;
|
|
481
|
+
substrate: Substrate;
|
|
482
|
+
/** Why this wallet: 'bwalletx' (fast path), 'chooser' (picked), 'requested' (walletId), … */
|
|
483
|
+
reason: ChoiceReason;
|
|
484
|
+
}
|
|
485
|
+
/** Resolves null when the user closed the chooser. Throws NOT_FOUND when there is nothing to connect. */
|
|
486
|
+
declare function runConnect(o: ConnectFlowOptions): Promise<ConnectFlowResult | null>;
|
|
487
|
+
interface SilentMetanetOptions extends MetanetOptions {
|
|
488
|
+
/** With verifyUrl: sign in once the known key is confirmed (the signature alone; the key is already in hand). */
|
|
489
|
+
challengeUrl?: string;
|
|
490
|
+
verifyUrl?: string;
|
|
491
|
+
post?: (url: string, body: unknown) => Promise<Record<string, unknown>>;
|
|
492
|
+
/** A server session is already in place for this identity key: attach the wallet only if it is the same key. */
|
|
493
|
+
sessionKey?: string | null;
|
|
494
|
+
/** The silent window, ms. Default METANET_SILENT_MS (2 s). */
|
|
495
|
+
windowMs?: number;
|
|
496
|
+
/** Called when the known key is confirmed and the sign-in signature is about to be asked for. */
|
|
497
|
+
onSignIn?: () => void;
|
|
498
|
+
/** "Not you?" was pressed meanwhile: land nobody (and end a session the verify route already set, via `logout`). */
|
|
499
|
+
isAbandoned?: () => boolean;
|
|
500
|
+
logout?: () => Promise<unknown>;
|
|
501
|
+
onAttempt?: AttemptHook;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* (0.7.0) The return visit with Metanet remembered: ONE silent attempt per page load (trySilentMetanet: 2 s, known
|
|
505
|
+
* identity keys only), then, with a session already there, attach the wallet when it is the session's key; without
|
|
506
|
+
* one, sign in with the signature alone. Resolves null on any stop or failure, and never throws: the caller shows
|
|
507
|
+
* the normal choice and waits for a tap, with no error.
|
|
508
|
+
*/
|
|
509
|
+
declare function runSilentMetanet(o?: SilentMetanetOptions): Promise<ConnectFlowResult | null>;
|
|
510
|
+
|
|
511
|
+
export { type AccessChallengeLike, AccessError, AccessResponse, AttemptHook, BAVATAR_URL, BWALLETX_RDNS, type ButtonOptions, type Challenge, ChoiceReason, type ChooseWalletOptions, type ConnectFlowOptions, type ConnectFlowResult, ConnectedWallet, DEFAULT_DISCOVER_MS, type FoundBy, type FoundWallet, type FrameWindow, HoldingProof, IDENTITY_HINT_KEY, KNOWN_KEYS_KEY, LOGIN_PROTOCOL, LOGO_URL, METANET_ANSWER_MS, METANET_JSON_API, METANET_LABEL, METANET_NOTE, METANET_OPTION_ID, METANET_REMEMBERED_NOTE, METANET_SILENT_MS, METANET_TYPE, METANET_UNREACHABLE, type MetanetOptions, MetanetUnreachableError, NOT_YOU_LABEL, PAYMAIL_LOOKUP_URL, type PairingModalOptions, PairingOptions, RDNS_EXTENSION, RDNS_MOBILE, RememberedWallet, type RequestAccessOptions, type RequestAccessResult, type SignInAndVerifyOptions, type SignInMethod, type SignInOptions, type SignInResult, type SignInStage, type SignInStatus, type SilentMetanetOptions, type SilentMetanetResult, type SilentStop, Substrate, WALLET_THEME_META, WalletOption, accountLabel, avatarUrlFor, bindPrewarm, challengeWantsIdentityKey, chooseWallet, claimSilentAttempt, connectBwalletX, connectMetanetDesktop, declareWalletTheme, discoverBwalletX, findBwalletX, inAnyFrame, inOrder, isFramed, isKnownIdentityKey, isTouchDevice, isUserRejection, knownIdentityKeys, lookupPaymail, metanetOffered, metanetOption, pairingModal, pickWallet, prewarmBwalletX, proveHoldings, qrSvg, rememberIdentity, rememberKnownIdentityKey, rememberedIdentity, renderButton, requestAccess, resetSilentAttempt, runConnect, runSilentMetanet, shortKey, signInAndVerify, signInErrorText, signInWithBwalletX, silentAttemptUsed, throwIfAccessError, toAccessError, trySilentMetanet, waitIfLocked, warnIfNoLogout };
|