@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.
Files changed (50) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +97 -9
  3. package/dist/bwalletx-connect.global.js +97 -25
  4. package/dist/bwalletx-connect.global.js.map +1 -1
  5. package/dist/choice-B97AjqF4.d.cts +442 -0
  6. package/dist/choice-B97AjqF4.d.ts +442 -0
  7. package/dist/chunk-6EFFOIHK.js +2441 -0
  8. package/dist/chunk-6EFFOIHK.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-DIKJFKND.js +239 -0
  12. package/dist/chunk-DIKJFKND.js.map +1 -0
  13. package/dist/chunk-TNRI7ARM.js +206 -0
  14. package/dist/chunk-TNRI7ARM.js.map +1 -0
  15. package/dist/element-BXEoOdXY.d.cts +53 -0
  16. package/dist/element-BXEoOdXY.d.ts +53 -0
  17. package/dist/element.cjs +1576 -60
  18. package/dist/element.cjs.map +1 -1
  19. package/dist/element.d.cts +26 -26
  20. package/dist/element.d.ts +26 -26
  21. package/dist/element.js +35 -2
  22. package/dist/element.js.map +1 -1
  23. package/dist/index.cjs +2046 -454
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +323 -16
  26. package/dist/index.d.ts +323 -16
  27. package/dist/index.js +186 -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 +1601 -210
  33. package/dist/react.cjs.map +1 -1
  34. package/dist/react.d.cts +115 -9
  35. package/dist/react.d.ts +115 -9
  36. package/dist/react.js +262 -46
  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/package.json +10 -9
  44. package/dist/chunk-EXRQJTXF.js +0 -910
  45. package/dist/chunk-EXRQJTXF.js.map +0 -1
  46. package/dist/chunk-QRXFL66W.js.map +0 -1
  47. package/dist/chunk-RIOHG5JH.js +0 -459
  48. package/dist/chunk-RIOHG5JH.js.map +0 -1
  49. package/dist/wallets-CbzMtxrf.d.cts +0 -250
  50. package/dist/wallets-CbzMtxrf.d.ts +0 -250
@@ -0,0 +1,206 @@
1
+ // src/pay.ts
2
+ import { P2PKH, PublicKey, Transaction, Utils } from "@bsv/sdk";
3
+ var BRC29_PROTOCOL = [2, "3241645161d8"];
4
+ var NO_COINS_TEXT = "Your wallet doesn't have enough to cover this payment and its small network fee. Add a little and try again.";
5
+ function isInsufficientFunds(e) {
6
+ const err = e;
7
+ if (!err) return false;
8
+ if (err.name === "WERR_INSUFFICIENT_FUNDS" || err.code === "WERR_INSUFFICIENT_FUNDS" || err.code === "ERR_INSUFFICIENT_FUNDS") return true;
9
+ if (err.isError === true && err.code === 7) return true;
10
+ const msg = typeof err.message === "string" ? err.message : String(e);
11
+ return /insufficient (funds|balance)|not enough (funds|coins|satoshis|sats)|more satoshis are needed/i.test(msg);
12
+ }
13
+ var PaymentError = class extends Error {
14
+ constructor(code, message, maybeSent = false, cause) {
15
+ super(message);
16
+ this.code = code;
17
+ this.maybeSent = maybeSent;
18
+ this.cause = cause;
19
+ this.name = "PaymentError";
20
+ }
21
+ code;
22
+ maybeSent;
23
+ cause;
24
+ };
25
+ var isLegacy = (s) => typeof s.pay === "function" && typeof s.createAction !== "function";
26
+ var isIdentityKeyHex = (s) => /^0[23][0-9a-fA-F]{64}$/.test(s);
27
+ var isPaymail = (s) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s);
28
+ function randomB64(n) {
29
+ const b = new Uint8Array(n);
30
+ globalThis.crypto.getRandomValues(b);
31
+ return Utils.toBase64(Array.from(b));
32
+ }
33
+ function opReturn(text) {
34
+ const d = Utils.toArray(text, "utf8");
35
+ const len = d.length;
36
+ const push = len < 76 ? [len] : len <= 255 ? [76, len] : [77, len & 255, len >> 8];
37
+ return Utils.toHex([0, 106, ...push, ...d]);
38
+ }
39
+ var clip = (s, n) => s.length > n ? s.slice(0, n - 1) + "\u2026" : s;
40
+ var describe = (s) => clip(s.length < 5 ? `${s} payment`.trim() : s, 50);
41
+ async function usdRate(o) {
42
+ if (typeof o.usdPerBsv === "number") return o.usdPerBsv;
43
+ try {
44
+ if (typeof o.usdPerBsv === "function") return await o.usdPerBsv();
45
+ const r = await (o.fetch ?? fetch)("https://api.whatsonchain.com/v1/bsv/main/exchangerate");
46
+ const j = await r.json();
47
+ if (!r.ok || !(Number(j.rate) > 0)) throw new Error(`status ${r.status}`);
48
+ return Number(j.rate);
49
+ } catch (e) {
50
+ throw new PaymentError("RATE_FAILED", `Could not get the BSV/USD rate: ${e.message}`, false, e);
51
+ }
52
+ }
53
+ async function amountInSats(req, o = {}) {
54
+ if (req.sats != null) {
55
+ if (!Number.isSafeInteger(req.sats) || req.sats <= 0) throw new PaymentError("BAD_REQUEST", "sats must be a positive integer");
56
+ return req.sats;
57
+ }
58
+ if (req.usd != null) {
59
+ if (!(req.usd > 0)) throw new PaymentError("BAD_REQUEST", "usd must be positive");
60
+ return Math.max(1, Math.ceil(req.usd / await usdRate(o) * 1e8));
61
+ }
62
+ throw new PaymentError("BAD_REQUEST", "Give sats or usd");
63
+ }
64
+ async function resolvePaymailP2P(paymail, sats, f = fetch) {
65
+ const [alias, domain] = paymail.split("@");
66
+ const fail = (m, e) => new PaymentError("RESOLVE_FAILED", `Could not resolve ${paymail}: ${m}`, false, e);
67
+ let caps;
68
+ try {
69
+ const r = await f(`https://${domain}/.well-known/bsvalias`);
70
+ caps = (await r.json()).capabilities;
71
+ } catch (e) {
72
+ throw fail("no bsvalias document (or CORS blocked it; resolve on your server and pass resolvePaymail)", e);
73
+ }
74
+ const fill = (u) => u.replace("{alias}", encodeURIComponent(alias)).replace("{domain.tld}", domain);
75
+ const dest = caps?.["2a40af698840"];
76
+ if (!dest) throw fail("it does not offer P2P payment destinations");
77
+ let body;
78
+ try {
79
+ const r = await f(fill(dest), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ satoshis: sats }) });
80
+ if (!r.ok) throw new Error(`status ${r.status}`);
81
+ body = await r.json();
82
+ } catch (e) {
83
+ throw fail(e.message, e);
84
+ }
85
+ if (!body.outputs?.length) throw fail("no outputs returned");
86
+ const receive = caps["5f1323cddf31"];
87
+ return {
88
+ outputs: body.outputs.map((o) => ({ script: o.script, satoshis: o.satoshis })),
89
+ reference: body.reference,
90
+ submit: receive ? async (hex) => {
91
+ await f(fill(receive), {
92
+ method: "POST",
93
+ headers: { "content-type": "application/json" },
94
+ body: JSON.stringify({ hex, reference: body.reference, metadata: {} })
95
+ });
96
+ } : void 0
97
+ };
98
+ }
99
+ async function runAction(wallet, description, outputs, labels) {
100
+ try {
101
+ return await wallet.createAction({
102
+ description: describe(description),
103
+ outputs: outputs.map((o) => ({ lockingScript: o.script, satoshis: o.satoshis, outputDescription: describe(o.description ?? "payment") })),
104
+ labels: labels?.length ? labels : void 0,
105
+ options: { randomizeOutputs: false }
106
+ });
107
+ } catch (e) {
108
+ if (isInsufficientFunds(e)) throw new PaymentError("INSUFFICIENT_FUNDS", NO_COINS_TEXT, false, e);
109
+ const msg = e?.message ?? String(e);
110
+ const rejected = /denied|reject|cancel|abort|user/i.test(msg) || e?.code === 4001;
111
+ throw new PaymentError(rejected ? "WALLET_REJECTED" : "WALLET_ERROR", rejected ? "The payment was declined in the wallet." : `The wallet could not make the payment: ${msg}`, !rejected, e);
112
+ }
113
+ }
114
+ async function pay(source, req, o = {}) {
115
+ const to = (req.to ?? "").trim();
116
+ if (!to) throw new PaymentError("BAD_REQUEST", "Give a recipient (to)");
117
+ if (req.memo && req.memo.length > 1e3) throw new PaymentError("BAD_REQUEST", "memo is too long");
118
+ const sats = await amountInSats(req, o);
119
+ if (isLegacy(source)) return source.pay({ ...req, to, sats });
120
+ let outputs;
121
+ let remittance;
122
+ let submit;
123
+ if (isIdentityKeyHex(to)) {
124
+ const derivationPrefix = randomB64(8);
125
+ const derivationSuffix = randomB64(8);
126
+ let pk;
127
+ let me;
128
+ try {
129
+ ({ publicKey: pk } = await source.getPublicKey({ protocolID: BRC29_PROTOCOL, keyID: `${derivationPrefix} ${derivationSuffix}`, counterparty: to.toLowerCase() }));
130
+ ({ publicKey: me } = await source.getPublicKey({ identityKey: true }));
131
+ } catch (e) {
132
+ throw new PaymentError("WALLET_ERROR", `The wallet could not derive the payment key: ${e.message}`, false, e);
133
+ }
134
+ outputs = [{ script: new P2PKH().lock(PublicKey.fromString(pk).toHash()).toHex(), satoshis: sats, description: "payment" }];
135
+ remittance = { senderIdentityKey: me, derivationPrefix, derivationSuffix, outputIndex: 0 };
136
+ } else if (isPaymail(to)) {
137
+ const r2 = await (o.resolvePaymail ?? ((p, s) => resolvePaymailP2P(p, s, o.fetch ?? fetch)))(to, sats);
138
+ outputs = r2.outputs;
139
+ submit = r2.submit;
140
+ } else {
141
+ try {
142
+ outputs = [{ script: new P2PKH().lock(to).toHex(), satoshis: sats, description: "payment" }];
143
+ } catch {
144
+ throw new PaymentError("BAD_REQUEST", `Not a paymail, address or identity key: ${to}`);
145
+ }
146
+ }
147
+ if (req.memo && req.memoOnChain) outputs = [...outputs, { script: opReturn(req.memo), satoshis: 0, description: "memo" }];
148
+ const r = await runAction(source, req.memo || `Pay ${clip(to, 30)}`, outputs, req.labels);
149
+ if (!r.txid) throw new PaymentError("WALLET_ERROR", "The wallet did not return a txid", true);
150
+ const tx = r.tx ? Array.from(r.tx) : void 0;
151
+ if (submit && tx) {
152
+ await submit(Transaction.fromAtomicBEEF(tx).toHex()).catch(() => {
153
+ });
154
+ }
155
+ return { txid: r.txid, tx, sats, outputs, remittance };
156
+ }
157
+ function tip(source, req, o = {}) {
158
+ return pay(source, { memo: "Tip", ...req, labels: [...req.labels ?? [], "tip"] }, o);
159
+ }
160
+ async function buyToken(source, req) {
161
+ if (isLegacy(source)) throw new PaymentError("NOT_SUPPORTED", "This wallet cannot buy tokens. Use a BRC-100 wallet such as bWalletX.");
162
+ const q = await req.quote({ token: req.token, amount: req.amount });
163
+ if (!q?.outputs?.length) throw new PaymentError("BAD_REQUEST", "The quote returned no outputs");
164
+ const sats = q.outputs.reduce((n, x) => n + x.satoshis, 0);
165
+ const r = await runAction(source, q.description ?? `Buy ${clip(req.token, 30)}`, q.outputs, [...req.labels ?? [], "token-buy"]);
166
+ if (!r.txid) throw new PaymentError("WALLET_ERROR", "The wallet did not return a txid", true);
167
+ const res = { txid: r.txid, tx: r.tx ? Array.from(r.tx) : void 0, sats, outputs: q.outputs };
168
+ await q.onPaid?.(res);
169
+ return res;
170
+ }
171
+
172
+ // src/theme.ts
173
+ var WALLET_THEME_META = "bwalletx-theme";
174
+ var ID = /^[a-z0-9-]{1,32}$/;
175
+ function declareWalletTheme(theme) {
176
+ if (typeof document === "undefined") return;
177
+ const id = (theme ?? "").trim().toLowerCase();
178
+ let meta = document.head.querySelector(`meta[name="${WALLET_THEME_META}"]`);
179
+ if (!id || !ID.test(id)) {
180
+ meta?.remove();
181
+ return;
182
+ }
183
+ if (!meta) {
184
+ meta = document.createElement("meta");
185
+ meta.name = WALLET_THEME_META;
186
+ document.head.appendChild(meta);
187
+ }
188
+ if (meta.content !== id) meta.content = id;
189
+ }
190
+
191
+ export {
192
+ BRC29_PROTOCOL,
193
+ NO_COINS_TEXT,
194
+ isInsufficientFunds,
195
+ PaymentError,
196
+ isIdentityKeyHex,
197
+ isPaymail,
198
+ amountInSats,
199
+ resolvePaymailP2P,
200
+ pay,
201
+ tip,
202
+ buyToken,
203
+ WALLET_THEME_META,
204
+ declareWalletTheme
205
+ };
206
+ //# sourceMappingURL=chunk-TNRI7ARM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pay.ts","../src/theme.ts"],"sourcesContent":["/**\n * Browser-side payment helpers on top of the BRC-100 wallet's createAction. Works with any\n * BRC-100 wallet. Each helper asks the wallet once; it never retries a spend. If a call fails\n * the error says whether the wallet may have sent anything (`maybeSent`).\n */\nimport { P2PKH, PublicKey, Transaction, Utils, type WalletInterface } from '@bsv/sdk';\n\n/** BRC-29 payment protocol id. */\nexport const BRC29_PROTOCOL: [2, string] = [2, '3241645161d8'];\n\nexport type PayTo = string; // paymail (name@domain), P2PKH address, or 66-hex identity key\n\nexport interface PayOutput {\n /** Locking script hex. */\n script: string;\n satoshis: number;\n description?: string;\n}\n\nexport interface PayRequest {\n to: PayTo;\n /** Amount in satoshis. Give this or `usd`. */\n sats?: number;\n /** Amount in US dollars, converted at `usdPerBsv` (or the live WhatsOnChain rate). */\n usd?: number;\n /** Shown in the wallet and, with `memoOnChain`, written in an OP_RETURN output. */\n memo?: string;\n memoOnChain?: boolean;\n /** Labels for the wallet's history. */\n labels?: string[];\n}\n\nexport interface PayOptions {\n /** Fixed rate for `usd`. Otherwise fetched from WhatsOnChain. */\n usdPerBsv?: number | (() => Promise<number>);\n /** Resolve a paymail to outputs. Default: bsvalias P2P payment destination (needs CORS on the paymail host). */\n resolvePaymail?: (paymail: string, sats: number) => Promise<{ outputs: PayOutput[]; reference?: string; submit?: (rawTxHex: string) => Promise<void> }>;\n fetch?: typeof fetch;\n}\n\nexport interface Brc29Remittance {\n senderIdentityKey: string;\n derivationPrefix: string;\n derivationSuffix: string;\n outputIndex: number;\n}\n\nexport interface PayResult {\n txid: string;\n /** Atomic BEEF (BRC-95) if the wallet returned it. Send it to your server's verifyPayment. */\n tx?: number[];\n sats: number;\n outputs: PayOutput[];\n /** For an identity-key payment: what the recipient needs to internalize the output (BRC-29). Deliver it to them. */\n remittance?: Brc29Remittance;\n}\n\nexport type PaymentErrorCode = 'BAD_REQUEST' | 'RESOLVE_FAILED' | 'RATE_FAILED' | 'WALLET_REJECTED' | 'WALLET_ERROR' | 'NOT_SUPPORTED' | 'INSUFFICIENT_FUNDS';\n\n/** (0.7.0) The plain message for a wallet with no coins for the network fee (PaymentError code INSUFFICIENT_FUNDS). */\nexport 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.\";\n\n/**\n * True when createAction failed because the wallet has no coins (or too few) to fund it: the SDK's\n * WERR_INSUFFICIENT_FUNDS (code 7, also as it arrives from Metanet Desktop over the JSON API), or a wallet's own\n * \"insufficient funds\" text. Nothing was sent in that case.\n */\nexport function isInsufficientFunds(e: unknown): boolean {\n const err = e as { name?: unknown; code?: unknown; isError?: unknown; message?: unknown } | null;\n if (!err) return false;\n if (err.name === 'WERR_INSUFFICIENT_FUNDS' || err.code === 'WERR_INSUFFICIENT_FUNDS' || err.code === 'ERR_INSUFFICIENT_FUNDS') return true;\n if (err.isError === true && err.code === 7) return true;\n const msg = typeof err.message === 'string' ? err.message : String(e);\n return /insufficient (funds|balance)|not enough (funds|coins|satoshis|sats)|more satoshis are needed/i.test(msg);\n}\n\nexport class PaymentError extends Error {\n constructor(\n readonly code: PaymentErrorCode,\n message: string,\n /** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */\n readonly maybeSent = false,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = 'PaymentError';\n }\n}\n\n/** A wallet that is not BRC-100 (the HandCash transitional adapter) can still pay through this. */\nexport interface LegacyPayer {\n pay(req: PayRequest & { sats: number }): Promise<PayResult>;\n}\nexport type PaySource = WalletInterface | LegacyPayer;\n\nconst isLegacy = (s: PaySource): s is LegacyPayer => typeof (s as LegacyPayer).pay === 'function' && typeof (s as WalletInterface).createAction !== 'function';\n\nexport const isIdentityKeyHex = (s: string) => /^0[23][0-9a-fA-F]{64}$/.test(s);\nexport const isPaymail = (s: string) => /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(s);\n\nfunction randomB64(n: number) {\n const b = new Uint8Array(n);\n globalThis.crypto.getRandomValues(b);\n return Utils.toBase64(Array.from(b));\n}\n\nfunction opReturn(text: string): string {\n const d = Utils.toArray(text, 'utf8');\n const len = d.length;\n const push = len < 0x4c ? [len] : len <= 0xff ? [0x4c, len] : [0x4d, len & 0xff, len >> 8];\n return Utils.toHex([0x00, 0x6a, ...push, ...d]);\n}\n\nconst clip = (s: string, n: number) => (s.length > n ? s.slice(0, n - 1) + '…' : s);\n/** createAction descriptions must be 5–50 bytes. */\nconst describe = (s: string) => clip(s.length < 5 ? `${s} payment`.trim() : s, 50);\n\nasync function usdRate(o: PayOptions): Promise<number> {\n if (typeof o.usdPerBsv === 'number') return o.usdPerBsv;\n try {\n if (typeof o.usdPerBsv === 'function') return await o.usdPerBsv();\n const r = await (o.fetch ?? fetch)('https://api.whatsonchain.com/v1/bsv/main/exchangerate');\n const j = (await r.json()) as { rate?: number };\n if (!r.ok || !(Number(j.rate) > 0)) throw new Error(`status ${r.status}`);\n return Number(j.rate);\n } catch (e) {\n throw new PaymentError('RATE_FAILED', `Could not get the BSV/USD rate: ${(e as Error).message}`, false, e);\n }\n}\n\n/** Satoshis for a request (sats as given, or usd converted, rounded up). */\nexport async function amountInSats(req: Pick<PayRequest, 'sats' | 'usd'>, o: PayOptions = {}): Promise<number> {\n if (req.sats != null) {\n if (!Number.isSafeInteger(req.sats) || req.sats <= 0) throw new PaymentError('BAD_REQUEST', 'sats must be a positive integer');\n return req.sats;\n }\n if (req.usd != null) {\n if (!(req.usd > 0)) throw new PaymentError('BAD_REQUEST', 'usd must be positive');\n return Math.max(1, Math.ceil((req.usd / (await usdRate(o))) * 1e8));\n }\n throw new PaymentError('BAD_REQUEST', 'Give sats or usd');\n}\n\n/** Default paymail resolver: bsvalias P2P Payment Destination (BRC-? / capability 2a40af698840). */\nexport async function resolvePaymailP2P(paymail: string, sats: number, f: typeof fetch = fetch) {\n const [alias, domain] = paymail.split('@');\n const fail = (m: string, e?: unknown) => new PaymentError('RESOLVE_FAILED', `Could not resolve ${paymail}: ${m}`, false, e);\n let caps: Record<string, string>;\n try {\n const r = await f(`https://${domain}/.well-known/bsvalias`);\n caps = ((await r.json()) as { capabilities: Record<string, string> }).capabilities;\n } catch (e) {\n throw fail('no bsvalias document (or CORS blocked it; resolve on your server and pass resolvePaymail)', e);\n }\n const fill = (u: string) => u.replace('{alias}', encodeURIComponent(alias)).replace('{domain.tld}', domain);\n const dest = caps?.['2a40af698840'];\n if (!dest) throw fail('it does not offer P2P payment destinations');\n let body: { outputs?: { script: string; satoshis: number }[]; reference?: string };\n try {\n const r = await f(fill(dest), { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ satoshis: sats }) });\n if (!r.ok) throw new Error(`status ${r.status}`);\n body = await r.json();\n } catch (e) {\n throw fail((e as Error).message, e);\n }\n if (!body.outputs?.length) throw fail('no outputs returned');\n const receive = caps['5f1323cddf31'];\n return {\n outputs: body.outputs.map((o) => ({ script: o.script, satoshis: o.satoshis })),\n reference: body.reference,\n submit: receive\n ? async (hex: string) => {\n await f(fill(receive), {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ hex, reference: body.reference, metadata: {} }),\n });\n }\n : undefined,\n };\n}\n\nasync function runAction(wallet: WalletInterface, description: string, outputs: PayOutput[], labels?: string[]) {\n try {\n return await wallet.createAction({\n description: describe(description),\n outputs: outputs.map((o) => ({ lockingScript: o.script, satoshis: o.satoshis, outputDescription: describe(o.description ?? 'payment') })),\n labels: labels?.length ? labels : undefined,\n options: { randomizeOutputs: false },\n });\n } catch (e) {\n // No coins for the fee: one plain line, and nothing was sent (maybeSent false).\n if (isInsufficientFunds(e)) throw new PaymentError('INSUFFICIENT_FUNDS', NO_COINS_TEXT, false, e);\n const msg = (e as Error)?.message ?? String(e);\n const rejected = /denied|reject|cancel|abort|user/i.test(msg) || (e as { code?: unknown })?.code === 4001;\n // Not retried: a lost reply could mean the wallet already broadcast it.\n throw new PaymentError(rejected ? 'WALLET_REJECTED' : 'WALLET_ERROR', rejected ? 'The payment was declined in the wallet.' : `The wallet could not make the payment: ${msg}`, !rejected, e);\n }\n}\n\n/** Pay a paymail, address or identity key. One wallet prompt; never retried. */\nexport async function pay(source: PaySource, req: PayRequest, o: PayOptions = {}): Promise<PayResult> {\n const to = (req.to ?? '').trim();\n if (!to) throw new PaymentError('BAD_REQUEST', 'Give a recipient (to)');\n if (req.memo && req.memo.length > 1000) throw new PaymentError('BAD_REQUEST', 'memo is too long');\n const sats = await amountInSats(req, o);\n if (isLegacy(source)) return source.pay({ ...req, to, sats });\n\n let outputs: PayOutput[];\n let remittance: Brc29Remittance | undefined;\n let submit: ((hex: string) => Promise<void>) | undefined;\n if (isIdentityKeyHex(to)) {\n const derivationPrefix = randomB64(8);\n const derivationSuffix = randomB64(8);\n let pk: string;\n let me: string;\n try {\n ({ publicKey: pk } = await source.getPublicKey({ protocolID: BRC29_PROTOCOL, keyID: `${derivationPrefix} ${derivationSuffix}`, counterparty: to.toLowerCase() }));\n ({ publicKey: me } = await source.getPublicKey({ identityKey: true }));\n } catch (e) {\n throw new PaymentError('WALLET_ERROR', `The wallet could not derive the payment key: ${(e as Error).message}`, false, e);\n }\n outputs = [{ script: new P2PKH().lock(PublicKey.fromString(pk).toHash() as number[]).toHex(), satoshis: sats, description: 'payment' }];\n remittance = { senderIdentityKey: me, derivationPrefix, derivationSuffix, outputIndex: 0 };\n } else if (isPaymail(to)) {\n const r = await (o.resolvePaymail ?? ((p, s) => resolvePaymailP2P(p, s, o.fetch ?? fetch)))(to, sats);\n outputs = r.outputs;\n submit = r.submit;\n } else {\n try {\n outputs = [{ script: new P2PKH().lock(to).toHex(), satoshis: sats, description: 'payment' }];\n } catch {\n throw new PaymentError('BAD_REQUEST', `Not a paymail, address or identity key: ${to}`);\n }\n }\n if (req.memo && req.memoOnChain) outputs = [...outputs, { script: opReturn(req.memo), satoshis: 0, description: 'memo' }];\n\n const r = await runAction(source, req.memo || `Pay ${clip(to, 30)}`, outputs, req.labels);\n if (!r.txid) throw new PaymentError('WALLET_ERROR', 'The wallet did not return a txid', true);\n const tx = r.tx ? Array.from(r.tx) : undefined;\n if (submit && tx) {\n // Tell the paymail host about the tx. Best effort: the payment itself is already made.\n await submit(Transaction.fromAtomicBEEF(tx).toHex()).catch(() => {});\n }\n return { txid: r.txid, tx, sats, outputs, remittance };\n}\n\n/** pay() labelled as a tip. */\nexport function tip(source: PaySource, req: PayRequest, o: PayOptions = {}): Promise<PayResult> {\n return pay(source, { memo: 'Tip', ...req, labels: [...(req.labels ?? []), 'tip'] }, o);\n}\n\nexport interface TokenQuote {\n /** Outputs to fund, as your server priced them (e.g. payment to the seller + fee). */\n outputs: PayOutput[];\n description?: string;\n /** Called with the result after the wallet signs; e.g. POST txid + tx to your server for verifyPayment. */\n onPaid?: (r: PayResult) => Promise<void> | void;\n}\n\nexport interface BuyTokenRequest {\n token: string;\n amount: number | string;\n /** The hook point: return the outputs for this purchase (usually from your server). */\n quote: (req: { token: string; amount: number | string }) => Promise<TokenQuote>;\n labels?: string[];\n}\n\n/** Buy a token: your `quote` hook prices it, the wallet pays once, `onPaid` delivers it. */\nexport async function buyToken(source: PaySource, req: BuyTokenRequest): Promise<PayResult> {\n if (isLegacy(source)) throw new PaymentError('NOT_SUPPORTED', 'This wallet cannot buy tokens. Use a BRC-100 wallet such as bWalletX.');\n const q = await req.quote({ token: req.token, amount: req.amount });\n if (!q?.outputs?.length) throw new PaymentError('BAD_REQUEST', 'The quote returned no outputs');\n const sats = q.outputs.reduce((n, x) => n + x.satoshis, 0);\n const r = await runAction(source, q.description ?? `Buy ${clip(req.token, 30)}`, q.outputs, [...(req.labels ?? []), 'token-buy']);\n if (!r.txid) throw new PaymentError('WALLET_ERROR', 'The wallet did not return a txid', true);\n const res: PayResult = { txid: r.txid, tx: r.tx ? Array.from(r.tx) : undefined, sats, outputs: q.outputs };\n await q.onPaid?.(res);\n return res;\n}\n","/**\n * Site theme for the wallet. A site may ask bWalletX to wear one of the themes the wallet already bundles\n * (e.g. 'npgx') while the site is connected and is the active tab; the wallet puts the user's own theme back on\n * any other site or when this declaration is removed. Only an id is declared: the wallet decides whether this\n * origin may wear it (brand editions are locked to their own sites) and never loads colours, CSS or URLs from here.\n */\nexport const WALLET_THEME_META = 'bwalletx-theme';\n\nconst ID = /^[a-z0-9-]{1,32}$/;\n\n/** Declare (or with null, withdraw) the theme the wallet should wear for this page. No-op outside a browser. */\nexport function declareWalletTheme(theme: string | null | undefined): void {\n if (typeof document === 'undefined') return;\n const id = (theme ?? '').trim().toLowerCase();\n let meta = document.head.querySelector<HTMLMetaElement>(`meta[name=\"${WALLET_THEME_META}\"]`);\n if (!id || !ID.test(id)) {\n meta?.remove();\n return;\n }\n if (!meta) {\n meta = document.createElement('meta');\n meta.name = WALLET_THEME_META;\n document.head.appendChild(meta);\n }\n if (meta.content !== id) meta.content = id;\n}\n"],"mappings":";AAKA,SAAS,OAAO,WAAW,aAAa,aAAmC;AAGpE,IAAM,iBAA8B,CAAC,GAAG,cAAc;AAoDtD,IAAM,gBAAgB;AAOtB,SAAS,oBAAoB,GAAqB;AACvD,QAAM,MAAM;AACZ,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,SAAS,6BAA6B,IAAI,SAAS,6BAA6B,IAAI,SAAS,yBAA0B,QAAO;AACtI,MAAI,IAAI,YAAY,QAAQ,IAAI,SAAS,EAAG,QAAO;AACnD,QAAM,MAAM,OAAO,IAAI,YAAY,WAAW,IAAI,UAAU,OAAO,CAAC;AACpE,SAAO,gGAAgG,KAAK,GAAG;AACjH;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACW,MACT,SAES,YAAY,OACZ,OACT;AACA,UAAM,OAAO;AANJ;AAGA;AACA;AAGT,SAAK,OAAO;AAAA,EACd;AAAA,EARW;AAAA,EAGA;AAAA,EACA;AAKb;AAQA,IAAM,WAAW,CAAC,MAAmC,OAAQ,EAAkB,QAAQ,cAAc,OAAQ,EAAsB,iBAAiB;AAE7I,IAAM,mBAAmB,CAAC,MAAc,yBAAyB,KAAK,CAAC;AACvE,IAAM,YAAY,CAAC,MAAc,6BAA6B,K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,QAAQ,OAAO,CAAC,GAAG,MAAM,IAAI,EAAE,UAAU,CAAC;AACzD,QAAM,IAAI,MAAM,UAAU,QAAQ,EAAE,eAAe,OAAO,KAAK,IAAI,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,GAAI,IAAI,UAAU,CAAC,GAAI,WAAW,CAAC;AAChI,MAAI,CAAC,EAAE,KAAM,OAAM,IAAI,aAAa,gBAAgB,oCAAoC,IAAI;AAC5F,QAAM,MAAiB,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE,KAAK,MAAM,KAAK,EAAE,EAAE,IAAI,QAAW,MAAM,SAAS,EAAE,QAAQ;AACzG,QAAM,EAAE,SAAS,GAAG;AACpB,SAAO;AACT;;;ACjRO,IAAM,oBAAoB;AAEjC,IAAM,KAAK;AAGJ,SAAS,mBAAmB,OAAwC;AACzE,MAAI,OAAO,aAAa,YAAa;AACrC,QAAM,MAAM,SAAS,IAAI,KAAK,EAAE,YAAY;AAC5C,MAAI,OAAO,SAAS,KAAK,cAA+B,cAAc,iBAAiB,IAAI;AAC3F,MAAI,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,GAAG;AACvB,UAAM,OAAO;AACb;AAAA,EACF;AACA,MAAI,CAAC,MAAM;AACT,WAAO,SAAS,cAAc,MAAM;AACpC,SAAK,OAAO;AACZ,aAAS,KAAK,YAAY,IAAI;AAAA,EAChC;AACA,MAAI,KAAK,YAAY,GAAI,MAAK,UAAU;AAC1C;","names":["r"]}
@@ -0,0 +1,53 @@
1
+ declare const SIGNIN_TAG = "bwalletx-signin";
2
+ declare const GET_URL = "https://bwalletx.com/get";
3
+ declare const WEB_WALLET_URL = "https://web.bwalletx.com";
4
+ type SigninSize = 'lg' | 'md' | 'sm' | 'icon';
5
+ type SigninTheme = 'gold' | 'dark' | 'light';
6
+ type SigninLabel = 'signin' | 'continue' | 'connect' | 'get' | 'play';
7
+ type SigninBrand = 'bWalletX' | 'bWallet';
8
+ /** The visible label for a label/brand pair, e.g. "Sign in with bWalletX". */
9
+ declare function signinText(label?: SigninLabel, brand?: SigninBrand): string;
10
+ /** The gold "b" (bwalletx-site/logo.svg). Ids are unique per copy so several marks can share a page. */
11
+ declare function markSvg(px?: number): string;
12
+ declare const SIGNIN_CSS = "\n:host{display:inline-block;vertical-align:middle;font-family:Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n:host([full-width]){display:block;width:100%}\n:host([hidden]){display:none}\nbutton{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:12px;width:100%;cursor:pointer;\n padding:16px 20px;border-radius:12px;font-size:16px;font-weight:700;line-height:1.2;text-align:left;\n background:linear-gradient(180deg,#fcd34d,#f59e0b);color:#000;\n box-shadow:0 10px 15px -3px rgba(245,158,11,.2),0 4px 6px -4px rgba(245,158,11,.2);\n transition:background .15s,transform .1s,box-shadow .15s,border-color .15s;-webkit-tap-highlight-color:transparent}\nbutton:hover{background:linear-gradient(180deg,#fde68a,#fbbf24)}\nbutton:active{transform:translateY(1px);background:linear-gradient(180deg,#fbbf24,#d97706)}\nbutton:focus-visible{outline:2px solid #b45309;outline-offset:3px}\nbutton:disabled{opacity:.6;cursor:not-allowed;transform:none}\nbutton[aria-busy=true]{cursor:wait}\n.mark{display:inline-flex;align-items:center;justify-content:center;flex:none;width:28px;height:28px;border-radius:50%;background:#000}\n.txt{display:flex;flex-direction:column;align-items:flex-start;min-width:0}\n.txt b{font-weight:700;white-space:nowrap}\n.txt small{font-size:11px;font-weight:500;color:rgba(0,0,0,.65);white-space:nowrap}\n.spin{width:16px;height:16px;border-radius:50%;border:2px solid rgba(255,210,77,.35);border-top-color:#ffd24d;animation:r .8s linear infinite}\n@keyframes r{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){button{transition:none}button:active{transform:none}.spin{animation:none;border-color:#ffd24d;border-right-color:transparent}}\n/* sizes */\n:host([size=md]) button{padding:10px 16px;border-radius:10px;font-size:15px;gap:10px}\n:host([size=md]) .mark{width:24px;height:24px}\n:host([size=md]) .txt small{font-size:10.5px}\n:host([size=sm]) button{padding:6px 12px 6px 6px;border-radius:8px;font-size:13px;gap:8px;min-height:36px}\n:host([size=sm]) .mark{width:22px;height:22px}\n:host([size=icon]) button{width:48px;height:48px;padding:0;border-radius:50%;gap:0}\n:host([size=icon]) .mark{width:34px;height:34px}\n/* themes */\n:host([theme=dark]) button{background:#0a0a0a;color:#fafafa;border:1px solid #3f3f46;box-shadow:none}\n:host([theme=dark]) button:hover{background:#18181b;border-color:rgba(251,191,36,.6)}\n:host([theme=dark]) button:active{background:#000}\n:host([theme=dark]) button:focus-visible{outline-color:#fcd34d}\n:host([theme=dark]) .mark{box-shadow:inset 0 0 0 1px #3f3f46}\n:host([theme=dark]) .txt small{color:rgba(255,255,255,.65)}\n:host([theme=light]) button{background:#fff;color:#09090b;border:1px solid #d4d4d8;box-shadow:0 1px 2px rgba(0,0,0,.06)}\n:host([theme=light]) button:hover{background:#fafafa;border-color:#f59e0b}\n:host([theme=light]) button:active{background:#f4f4f5}\n:host([theme=light]) .txt small{color:#52525b}\n/* not found */\n.nf{margin-top:8px;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n.nf a{color:inherit;font-weight:600;text-decoration:underline;text-underline-offset:2px}\n.nf a:focus-visible{outline:2px solid #b45309;outline-offset:2px;border-radius:2px}\n:host([theme=dark]) .nf,:host-context(.dark) .nf{color:#a1a1aa}\n.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}\n/* pending: one plain line under the button */\n.note{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center;overflow-wrap:break-word}\n:host([theme=dark]) .note,:host-context(.dark) .note{color:#a1a1aa}\n/* \"Other wallets\" (0.5.6): one small link under the button */\n.ow{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n:host([theme=dark]) .ow,:host-context(.dark) .ow{color:#a1a1aa}\n.sw{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#a16207;text-align:center}\n:host([theme=dark]) .sw,:host-context(.dark) .sw{color:#fcd34d}\n.mn{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n.mn small{display:block;font-size:11px;opacity:.85}\n:host([theme=dark]) .mn,:host-context(.dark) .mn{color:#a1a1aa}\n.lnk{all:unset;cursor:pointer;color:inherit;font-weight:600;text-decoration:underline;text-underline-offset:2px}\n.lnk:focus-visible{outline:2px solid #b45309;outline-offset:2px;border-radius:2px}\n/* error: one line plus Retry */\n.err{margin:0 0 8px;width:0;min-width:100%;font-size:13px;font-weight:600;line-height:1.4;color:#b91c1c;text-align:center;overflow-wrap:anywhere}\n:host([theme=dark]) .err,:host-context(.dark) .err{color:#fca5a5}\n/* signed in: the badge */\nbutton.chip{display:inline-flex;align-items:center;justify-content:flex-start;gap:10px;width:auto;max-width:100%;padding:5px 14px 5px 5px;border-radius:999px;\n background:#0b0b0c;color:#ffd24d;border:1px solid rgba(255,210,77,.55);box-shadow:none;font-size:15px}\nbutton.chip:hover{background:#151517;border-color:#ffd24d}\nbutton.chip:active{background:#000;transform:none}\nbutton.chip:focus-visible{outline:2px solid #ffd24d;outline-offset:3px}\n:host([theme=light]) button.chip{background:#fff;color:#09090b;border-color:#f59e0b}\n:host([theme=light]) button.chip:hover{background:#fffbeb}\n:host([full-width]) button.chip{width:100%}\n.av{position:relative;flex:none;display:inline-grid;place-items:center;width:30px;height:30px;border-radius:50%;overflow:hidden;\n background:radial-gradient(circle at 30% 30%,#ffe27a,#f5b800 55%,#b88600);color:#000;font-weight:800;font-size:14px}\n.av img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover}\n.name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:min(52vw,260px)}\n.dot{flex:none;width:8px;height:8px;border-radius:50%;background:#ffd24d;box-shadow:0 0 0 3px rgba(255,210,77,.22)}\n:host([size=sm]) button.chip{font-size:13px;padding:3px 12px 3px 3px;gap:8px}\n:host([size=sm]) .av{width:26px;height:26px}\n:host([size=icon]) button.chip{width:48px;height:48px;padding:0;justify-content:center}\n:host([size=icon]) .name,:host([size=icon]) .dot{display:none}\n:host([size=icon]) .av{width:40px;height:40px}\n";
13
+ /** The badge menu. Rendered in a body-level portal (position: fixed), so overflow:hidden parents never clip it. */
14
+ declare const MENU_CSS = "\n:host{all:initial}\n.menu{position:fixed;z-index:2147483600;box-sizing:border-box;min-width:200px;padding:6px;border-radius:14px;background:#0b0b0c;color:#ffd24d;\n border:1px solid rgba(255,210,77,.55);box-shadow:0 12px 32px rgba(0,0,0,.45);font:600 14px/1.3 Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n.who{padding:8px 10px 10px;font-size:12px;font-weight:500;color:#e7d9a8;overflow-wrap:anywhere;border-bottom:1px solid rgba(255,210,77,.3);margin-bottom:4px}\n.item{all:unset;box-sizing:border-box;display:block;width:100%;padding:11px 10px;border-radius:10px;cursor:pointer;color:#ffd24d}\n.item:hover,.item:focus-visible{background:#ffd24d;color:#000;outline:none}\n.tip{position:fixed;z-index:2147483600;box-sizing:border-box;padding:8px 12px;border-radius:10px;background:#0b0b0c;color:#e7d9a8;\n border:1px solid rgba(255,210,77,.4);box-shadow:0 8px 24px rgba(0,0,0,.35);font:500 12px/1.4 Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n";
15
+ type SigninState = 'signed-out' | 'restoring' | 'pending' | 'signed-in' | 'error';
16
+ /** The account the badge shows. */
17
+ interface SigninAccount {
18
+ identityKey: string;
19
+ paymail?: string | null;
20
+ handle?: string | null;
21
+ avatarUrl?: string | null;
22
+ }
23
+ /** The one plain line shown while the wallet sheet is up. */
24
+ declare const PENDING_NOTE = "Sign in: shares only your public identity key, moves no money";
25
+ declare const PENDING_LABEL = "Approve in bWalletX\u2026";
26
+ /** The pending label when the user picked a wallet other than bWalletX. */
27
+ declare const PENDING_LABEL_OTHER = "Approve in your wallet\u2026";
28
+ /**
29
+ * What started a sign-in: the button ('signin'), "Other wallets" ('chooser'), "Switch" ('bwalletx', 0.6.0) or "Use
30
+ * Metanet Desktop or another BRC-100 wallet" ('metanet', 0.7.0).
31
+ */
32
+ type SigninMode = 'signin' | 'chooser' | 'bwalletx' | 'metanet';
33
+ /** (0.6.0) The note shown when the remembered or connected wallet isn't bWalletX. */
34
+ declare const SWITCH_NOTE = "Some features need bWalletX";
35
+ /** (0.6.0) The button's label when the tap goes to a remembered wallet that isn't bWalletX. */
36
+ declare const CONTINUE_OTHER_LABEL = "Continue with your wallet";
37
+ /** Optional OAuth parameters for authorize-url mode. auth.bwalletx.com is planned, not live. */
38
+ interface AuthorizeParams {
39
+ authorizeUrl: string;
40
+ clientId?: string | null;
41
+ redirectUri?: string | null;
42
+ scope?: string | null;
43
+ }
44
+ /**
45
+ * Build an OAuth 2.1 authorization-code + S256 PKCE redirect URL, and keep the verifier, state and
46
+ * nonce in sessionStorage under "bwalletx:oauth" for your callback page. Matches the plan in
47
+ * bit-sign docs/SIGN-IN-WITH-BWALLETX.md. The provider is not live yet.
48
+ */
49
+ declare function buildAuthorizeUrl(p: AuthorizeParams): Promise<string>;
50
+ /** Register <bwalletx-signin> (once). Safe to call on a server: it does nothing there. */
51
+ declare function defineBwalletxSignin(tag?: string): CustomElementConstructor | undefined;
52
+
53
+ export { type AuthorizeParams as A, CONTINUE_OTHER_LABEL as C, GET_URL as G, MENU_CSS as M, PENDING_LABEL as P, type SigninSize as S, WEB_WALLET_URL as W, type SigninTheme as a, type SigninLabel as b, type SigninBrand as c, type SigninState as d, PENDING_LABEL_OTHER as e, PENDING_NOTE as f, SIGNIN_CSS as g, SIGNIN_TAG as h, SWITCH_NOTE as i, type SigninAccount as j, type SigninMode as k, buildAuthorizeUrl as l, defineBwalletxSignin as m, markSvg as n, signinText as s };
@@ -0,0 +1,53 @@
1
+ declare const SIGNIN_TAG = "bwalletx-signin";
2
+ declare const GET_URL = "https://bwalletx.com/get";
3
+ declare const WEB_WALLET_URL = "https://web.bwalletx.com";
4
+ type SigninSize = 'lg' | 'md' | 'sm' | 'icon';
5
+ type SigninTheme = 'gold' | 'dark' | 'light';
6
+ type SigninLabel = 'signin' | 'continue' | 'connect' | 'get' | 'play';
7
+ type SigninBrand = 'bWalletX' | 'bWallet';
8
+ /** The visible label for a label/brand pair, e.g. "Sign in with bWalletX". */
9
+ declare function signinText(label?: SigninLabel, brand?: SigninBrand): string;
10
+ /** The gold "b" (bwalletx-site/logo.svg). Ids are unique per copy so several marks can share a page. */
11
+ declare function markSvg(px?: number): string;
12
+ declare const SIGNIN_CSS = "\n:host{display:inline-block;vertical-align:middle;font-family:Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n:host([full-width]){display:block;width:100%}\n:host([hidden]){display:none}\nbutton{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:12px;width:100%;cursor:pointer;\n padding:16px 20px;border-radius:12px;font-size:16px;font-weight:700;line-height:1.2;text-align:left;\n background:linear-gradient(180deg,#fcd34d,#f59e0b);color:#000;\n box-shadow:0 10px 15px -3px rgba(245,158,11,.2),0 4px 6px -4px rgba(245,158,11,.2);\n transition:background .15s,transform .1s,box-shadow .15s,border-color .15s;-webkit-tap-highlight-color:transparent}\nbutton:hover{background:linear-gradient(180deg,#fde68a,#fbbf24)}\nbutton:active{transform:translateY(1px);background:linear-gradient(180deg,#fbbf24,#d97706)}\nbutton:focus-visible{outline:2px solid #b45309;outline-offset:3px}\nbutton:disabled{opacity:.6;cursor:not-allowed;transform:none}\nbutton[aria-busy=true]{cursor:wait}\n.mark{display:inline-flex;align-items:center;justify-content:center;flex:none;width:28px;height:28px;border-radius:50%;background:#000}\n.txt{display:flex;flex-direction:column;align-items:flex-start;min-width:0}\n.txt b{font-weight:700;white-space:nowrap}\n.txt small{font-size:11px;font-weight:500;color:rgba(0,0,0,.65);white-space:nowrap}\n.spin{width:16px;height:16px;border-radius:50%;border:2px solid rgba(255,210,77,.35);border-top-color:#ffd24d;animation:r .8s linear infinite}\n@keyframes r{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){button{transition:none}button:active{transform:none}.spin{animation:none;border-color:#ffd24d;border-right-color:transparent}}\n/* sizes */\n:host([size=md]) button{padding:10px 16px;border-radius:10px;font-size:15px;gap:10px}\n:host([size=md]) .mark{width:24px;height:24px}\n:host([size=md]) .txt small{font-size:10.5px}\n:host([size=sm]) button{padding:6px 12px 6px 6px;border-radius:8px;font-size:13px;gap:8px;min-height:36px}\n:host([size=sm]) .mark{width:22px;height:22px}\n:host([size=icon]) button{width:48px;height:48px;padding:0;border-radius:50%;gap:0}\n:host([size=icon]) .mark{width:34px;height:34px}\n/* themes */\n:host([theme=dark]) button{background:#0a0a0a;color:#fafafa;border:1px solid #3f3f46;box-shadow:none}\n:host([theme=dark]) button:hover{background:#18181b;border-color:rgba(251,191,36,.6)}\n:host([theme=dark]) button:active{background:#000}\n:host([theme=dark]) button:focus-visible{outline-color:#fcd34d}\n:host([theme=dark]) .mark{box-shadow:inset 0 0 0 1px #3f3f46}\n:host([theme=dark]) .txt small{color:rgba(255,255,255,.65)}\n:host([theme=light]) button{background:#fff;color:#09090b;border:1px solid #d4d4d8;box-shadow:0 1px 2px rgba(0,0,0,.06)}\n:host([theme=light]) button:hover{background:#fafafa;border-color:#f59e0b}\n:host([theme=light]) button:active{background:#f4f4f5}\n:host([theme=light]) .txt small{color:#52525b}\n/* not found */\n.nf{margin-top:8px;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n.nf a{color:inherit;font-weight:600;text-decoration:underline;text-underline-offset:2px}\n.nf a:focus-visible{outline:2px solid #b45309;outline-offset:2px;border-radius:2px}\n:host([theme=dark]) .nf,:host-context(.dark) .nf{color:#a1a1aa}\n.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}\n/* pending: one plain line under the button */\n.note{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center;overflow-wrap:break-word}\n:host([theme=dark]) .note,:host-context(.dark) .note{color:#a1a1aa}\n/* \"Other wallets\" (0.5.6): one small link under the button */\n.ow{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n:host([theme=dark]) .ow,:host-context(.dark) .ow{color:#a1a1aa}\n.sw{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#a16207;text-align:center}\n:host([theme=dark]) .sw,:host-context(.dark) .sw{color:#fcd34d}\n.mn{margin:8px 0 0;width:0;min-width:100%;font-size:12px;line-height:1.4;color:#71717a;text-align:center}\n.mn small{display:block;font-size:11px;opacity:.85}\n:host([theme=dark]) .mn,:host-context(.dark) .mn{color:#a1a1aa}\n.lnk{all:unset;cursor:pointer;color:inherit;font-weight:600;text-decoration:underline;text-underline-offset:2px}\n.lnk:focus-visible{outline:2px solid #b45309;outline-offset:2px;border-radius:2px}\n/* error: one line plus Retry */\n.err{margin:0 0 8px;width:0;min-width:100%;font-size:13px;font-weight:600;line-height:1.4;color:#b91c1c;text-align:center;overflow-wrap:anywhere}\n:host([theme=dark]) .err,:host-context(.dark) .err{color:#fca5a5}\n/* signed in: the badge */\nbutton.chip{display:inline-flex;align-items:center;justify-content:flex-start;gap:10px;width:auto;max-width:100%;padding:5px 14px 5px 5px;border-radius:999px;\n background:#0b0b0c;color:#ffd24d;border:1px solid rgba(255,210,77,.55);box-shadow:none;font-size:15px}\nbutton.chip:hover{background:#151517;border-color:#ffd24d}\nbutton.chip:active{background:#000;transform:none}\nbutton.chip:focus-visible{outline:2px solid #ffd24d;outline-offset:3px}\n:host([theme=light]) button.chip{background:#fff;color:#09090b;border-color:#f59e0b}\n:host([theme=light]) button.chip:hover{background:#fffbeb}\n:host([full-width]) button.chip{width:100%}\n.av{position:relative;flex:none;display:inline-grid;place-items:center;width:30px;height:30px;border-radius:50%;overflow:hidden;\n background:radial-gradient(circle at 30% 30%,#ffe27a,#f5b800 55%,#b88600);color:#000;font-weight:800;font-size:14px}\n.av img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover}\n.name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:min(52vw,260px)}\n.dot{flex:none;width:8px;height:8px;border-radius:50%;background:#ffd24d;box-shadow:0 0 0 3px rgba(255,210,77,.22)}\n:host([size=sm]) button.chip{font-size:13px;padding:3px 12px 3px 3px;gap:8px}\n:host([size=sm]) .av{width:26px;height:26px}\n:host([size=icon]) button.chip{width:48px;height:48px;padding:0;justify-content:center}\n:host([size=icon]) .name,:host([size=icon]) .dot{display:none}\n:host([size=icon]) .av{width:40px;height:40px}\n";
13
+ /** The badge menu. Rendered in a body-level portal (position: fixed), so overflow:hidden parents never clip it. */
14
+ declare const MENU_CSS = "\n:host{all:initial}\n.menu{position:fixed;z-index:2147483600;box-sizing:border-box;min-width:200px;padding:6px;border-radius:14px;background:#0b0b0c;color:#ffd24d;\n border:1px solid rgba(255,210,77,.55);box-shadow:0 12px 32px rgba(0,0,0,.45);font:600 14px/1.3 Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n.who{padding:8px 10px 10px;font-size:12px;font-weight:500;color:#e7d9a8;overflow-wrap:anywhere;border-bottom:1px solid rgba(255,210,77,.3);margin-bottom:4px}\n.item{all:unset;box-sizing:border-box;display:block;width:100%;padding:11px 10px;border-radius:10px;cursor:pointer;color:#ffd24d}\n.item:hover,.item:focus-visible{background:#ffd24d;color:#000;outline:none}\n.tip{position:fixed;z-index:2147483600;box-sizing:border-box;padding:8px 12px;border-radius:10px;background:#0b0b0c;color:#e7d9a8;\n border:1px solid rgba(255,210,77,.4);box-shadow:0 8px 24px rgba(0,0,0,.35);font:500 12px/1.4 Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif}\n";
15
+ type SigninState = 'signed-out' | 'restoring' | 'pending' | 'signed-in' | 'error';
16
+ /** The account the badge shows. */
17
+ interface SigninAccount {
18
+ identityKey: string;
19
+ paymail?: string | null;
20
+ handle?: string | null;
21
+ avatarUrl?: string | null;
22
+ }
23
+ /** The one plain line shown while the wallet sheet is up. */
24
+ declare const PENDING_NOTE = "Sign in: shares only your public identity key, moves no money";
25
+ declare const PENDING_LABEL = "Approve in bWalletX\u2026";
26
+ /** The pending label when the user picked a wallet other than bWalletX. */
27
+ declare const PENDING_LABEL_OTHER = "Approve in your wallet\u2026";
28
+ /**
29
+ * What started a sign-in: the button ('signin'), "Other wallets" ('chooser'), "Switch" ('bwalletx', 0.6.0) or "Use
30
+ * Metanet Desktop or another BRC-100 wallet" ('metanet', 0.7.0).
31
+ */
32
+ type SigninMode = 'signin' | 'chooser' | 'bwalletx' | 'metanet';
33
+ /** (0.6.0) The note shown when the remembered or connected wallet isn't bWalletX. */
34
+ declare const SWITCH_NOTE = "Some features need bWalletX";
35
+ /** (0.6.0) The button's label when the tap goes to a remembered wallet that isn't bWalletX. */
36
+ declare const CONTINUE_OTHER_LABEL = "Continue with your wallet";
37
+ /** Optional OAuth parameters for authorize-url mode. auth.bwalletx.com is planned, not live. */
38
+ interface AuthorizeParams {
39
+ authorizeUrl: string;
40
+ clientId?: string | null;
41
+ redirectUri?: string | null;
42
+ scope?: string | null;
43
+ }
44
+ /**
45
+ * Build an OAuth 2.1 authorization-code + S256 PKCE redirect URL, and keep the verifier, state and
46
+ * nonce in sessionStorage under "bwalletx:oauth" for your callback page. Matches the plan in
47
+ * bit-sign docs/SIGN-IN-WITH-BWALLETX.md. The provider is not live yet.
48
+ */
49
+ declare function buildAuthorizeUrl(p: AuthorizeParams): Promise<string>;
50
+ /** Register <bwalletx-signin> (once). Safe to call on a server: it does nothing there. */
51
+ declare function defineBwalletxSignin(tag?: string): CustomElementConstructor | undefined;
52
+
53
+ export { type AuthorizeParams as A, CONTINUE_OTHER_LABEL as C, GET_URL as G, MENU_CSS as M, PENDING_LABEL as P, type SigninSize as S, WEB_WALLET_URL as W, type SigninTheme as a, type SigninLabel as b, type SigninBrand as c, type SigninState as d, PENDING_LABEL_OTHER as e, PENDING_NOTE as f, SIGNIN_CSS as g, SIGNIN_TAG as h, SWITCH_NOTE as i, type SigninAccount as j, type SigninMode as k, buildAuthorizeUrl as l, defineBwalletxSignin as m, markSvg as n, signinText as s };