@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
|
@@ -1,250 +0,0 @@
|
|
|
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';
|
|
118
|
-
declare class PaymentError extends Error {
|
|
119
|
-
readonly code: PaymentErrorCode;
|
|
120
|
-
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
121
|
-
readonly maybeSent: boolean;
|
|
122
|
-
readonly cause?: unknown | undefined;
|
|
123
|
-
constructor(code: PaymentErrorCode, message: string,
|
|
124
|
-
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
125
|
-
maybeSent?: boolean, cause?: unknown | undefined);
|
|
126
|
-
}
|
|
127
|
-
/** A wallet that is not BRC-100 (the HandCash transitional adapter) can still pay through this. */
|
|
128
|
-
interface LegacyPayer {
|
|
129
|
-
pay(req: PayRequest & {
|
|
130
|
-
sats: number;
|
|
131
|
-
}): Promise<PayResult>;
|
|
132
|
-
}
|
|
133
|
-
type PaySource = WalletInterface | LegacyPayer;
|
|
134
|
-
declare const isIdentityKeyHex: (s: string) => boolean;
|
|
135
|
-
declare const isPaymail: (s: string) => boolean;
|
|
136
|
-
/** Satoshis for a request (sats as given, or usd converted, rounded up). */
|
|
137
|
-
declare function amountInSats(req: Pick<PayRequest, 'sats' | 'usd'>, o?: PayOptions): Promise<number>;
|
|
138
|
-
/** Default paymail resolver: bsvalias P2P Payment Destination (BRC-? / capability 2a40af698840). */
|
|
139
|
-
declare function resolvePaymailP2P(paymail: string, sats: number, f?: typeof fetch): Promise<{
|
|
140
|
-
outputs: {
|
|
141
|
-
script: string;
|
|
142
|
-
satoshis: number;
|
|
143
|
-
}[];
|
|
144
|
-
reference: string | undefined;
|
|
145
|
-
submit: ((hex: string) => Promise<void>) | undefined;
|
|
146
|
-
}>;
|
|
147
|
-
/** Pay a paymail, address or identity key. One wallet prompt; never retried. */
|
|
148
|
-
declare function pay(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
149
|
-
/** pay() labelled as a tip. */
|
|
150
|
-
declare function tip(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
151
|
-
interface TokenQuote {
|
|
152
|
-
/** Outputs to fund, as your server priced them (e.g. payment to the seller + fee). */
|
|
153
|
-
outputs: PayOutput[];
|
|
154
|
-
description?: string;
|
|
155
|
-
/** Called with the result after the wallet signs; e.g. POST txid + tx to your server for verifyPayment. */
|
|
156
|
-
onPaid?: (r: PayResult) => Promise<void> | void;
|
|
157
|
-
}
|
|
158
|
-
interface BuyTokenRequest {
|
|
159
|
-
token: string;
|
|
160
|
-
amount: number | string;
|
|
161
|
-
/** The hook point: return the outputs for this purchase (usually from your server). */
|
|
162
|
-
quote: (req: {
|
|
163
|
-
token: string;
|
|
164
|
-
amount: number | string;
|
|
165
|
-
}) => Promise<TokenQuote>;
|
|
166
|
-
labels?: string[];
|
|
167
|
-
}
|
|
168
|
-
/** Buy a token: your `quote` hook prices it, the wallet pays once, `onPaid` delivers it. */
|
|
169
|
-
declare function buyToken(source: PaySource, req: BuyTokenRequest): Promise<PayResult>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Every wallet the user could connect with, behind one interface. BRC-100 first: bWalletX, then any
|
|
173
|
-
* other wallet that announces itself (Yours, Metanet, ...), the in-app browser, optional localhost
|
|
174
|
-
* desktop wallets, phone pairing, and app-supplied adapters (e.g. the transitional HandCash one).
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
type WalletKind = 'brc100' | 'pairing' | 'handcash' | 'custom';
|
|
178
|
-
interface ConnectedWallet {
|
|
179
|
-
/** The BRC-100 wallet. null for a non-BRC-100 adapter (HandCash today). */
|
|
180
|
-
wallet: WalletInterface | null;
|
|
181
|
-
/** What pay/tip use: the BRC-100 wallet, or the adapter's own payer. */
|
|
182
|
-
payer: PaySource | null;
|
|
183
|
-
/** The identity public key (hex) when the wallet has one. */
|
|
184
|
-
identityKey: string | null;
|
|
185
|
-
handle?: string;
|
|
186
|
-
paymail?: string;
|
|
187
|
-
/** Which option connected. */
|
|
188
|
-
optionId: string;
|
|
189
|
-
kind: WalletKind;
|
|
190
|
-
/** True for adapters kept only until the vendor ships BRC-100. */
|
|
191
|
-
transitional?: boolean;
|
|
192
|
-
}
|
|
193
|
-
interface WalletOption {
|
|
194
|
-
id: string;
|
|
195
|
-
name: string;
|
|
196
|
-
icon?: string;
|
|
197
|
-
kind: WalletKind;
|
|
198
|
-
rdns?: string;
|
|
199
|
-
/** True for bWalletX (extension, in-app or paired). */
|
|
200
|
-
isBwalletX: boolean;
|
|
201
|
-
connect(): Promise<ConnectedWallet>;
|
|
202
|
-
}
|
|
203
|
-
/** Wrap any BRC-100 wallet as a picker option. */
|
|
204
|
-
declare function brc100Option(wallet: WalletInterface, info: {
|
|
205
|
-
id: string;
|
|
206
|
-
name: string;
|
|
207
|
-
icon?: string;
|
|
208
|
-
rdns?: string;
|
|
209
|
-
isBwalletX?: boolean;
|
|
210
|
-
}): WalletOption;
|
|
211
|
-
/** Phone / web.bwalletx.com pairing as an option (shows a QR through `pairing`). Reuses a stored pairing first. */
|
|
212
|
-
declare function pairingOption(pairing: PairingOptions | (() => PairingOptions)): WalletOption;
|
|
213
|
-
interface HandCashAdapterOptions {
|
|
214
|
-
/**
|
|
215
|
-
* Your existing HandCash Connect login (redirect/popup + your server route). Resolve with the
|
|
216
|
-
* profile once the user is signed in. This package does not import any HandCash SDK.
|
|
217
|
-
*/
|
|
218
|
-
login(): Promise<{
|
|
219
|
-
handle: string;
|
|
220
|
-
paymail?: string;
|
|
221
|
-
identityKey?: string;
|
|
222
|
-
}>;
|
|
223
|
-
/** Your existing HandCash pay call (usually a server route using the auth token). Optional. */
|
|
224
|
-
pay?: Extract<PaySource, {
|
|
225
|
-
pay: unknown;
|
|
226
|
-
}>['pay'];
|
|
227
|
-
icon?: string;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* TRANSITIONAL. Keeps existing HandCash users working behind the same picker until HandCash's
|
|
231
|
-
* BRC-100 support ships; then remove this and HandCash appears as an ordinary BRC-100 wallet.
|
|
232
|
-
*/
|
|
233
|
-
declare function handcashAdapter(o: HandCashAdapterOptions): WalletOption;
|
|
234
|
-
interface DiscoverWalletsOptions {
|
|
235
|
-
/** Longest wait for BRC-100 announcements, ms. Default 300; ends early once a wallet has announced. */
|
|
236
|
-
ms?: number;
|
|
237
|
-
/**
|
|
238
|
-
* Also probe desktop wallets on localhost (Metanet / json-api on 3321, Cicada on 3301).
|
|
239
|
-
* Off by default: some browsers prompt for local-network access.
|
|
240
|
-
*/
|
|
241
|
-
probeLocal?: boolean;
|
|
242
|
-
/** Add the phone pairing option (needs a way to show the QR, e.g. pairingModal()). */
|
|
243
|
-
pairing?: PairingOptions | (() => PairingOptions);
|
|
244
|
-
/** App-supplied options appended at the end (e.g. handcashAdapter(...)). */
|
|
245
|
-
extra?: WalletOption[];
|
|
246
|
-
}
|
|
247
|
-
/** All wallets we can see, bWalletX first. SSR-safe: resolves [] (plus `extra`) outside a browser. */
|
|
248
|
-
declare function discoverWallets(o?: DiscoverWalletsOptions): Promise<WalletOption[]>;
|
|
249
|
-
|
|
250
|
-
export { restorePairing as A, type BuyTokenRequest as B, type ConnectedWallet as C, type DiscoverWalletsOptions as D, tip as E, type HandCashAdapterOptions as H, type LegacyPayer as L, type PayRequest as P, type SocketFactory as S, type TokenQuote as T, type WalletOption as W, type PayResult as a, type PayOptions as b, PaymentError as c, brc100Option as d, discoverWallets as e, type PairingOptions as f, BRC29_PROTOCOL as g, handcashAdapter as h, type Brc29Remittance as i, type PairConnectionOptions as j, type PairStorage as k, type PairedWallet as l, type PayOutput as m, type PaySource as n, type PaymentErrorCode as o, pairingOption as p, type SocketLike as q, type WalletKind as r, amountInSats as s, buyToken as t, clearPairing as u, isIdentityKeyHex as v, isPaymail as w, pairBwalletX as x, pay as y, resolvePaymailP2P as z };
|
|
@@ -1,250 +0,0 @@
|
|
|
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';
|
|
118
|
-
declare class PaymentError extends Error {
|
|
119
|
-
readonly code: PaymentErrorCode;
|
|
120
|
-
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
121
|
-
readonly maybeSent: boolean;
|
|
122
|
-
readonly cause?: unknown | undefined;
|
|
123
|
-
constructor(code: PaymentErrorCode, message: string,
|
|
124
|
-
/** true when the wallet was asked to spend and the outcome is unknown. Check before trying again. */
|
|
125
|
-
maybeSent?: boolean, cause?: unknown | undefined);
|
|
126
|
-
}
|
|
127
|
-
/** A wallet that is not BRC-100 (the HandCash transitional adapter) can still pay through this. */
|
|
128
|
-
interface LegacyPayer {
|
|
129
|
-
pay(req: PayRequest & {
|
|
130
|
-
sats: number;
|
|
131
|
-
}): Promise<PayResult>;
|
|
132
|
-
}
|
|
133
|
-
type PaySource = WalletInterface | LegacyPayer;
|
|
134
|
-
declare const isIdentityKeyHex: (s: string) => boolean;
|
|
135
|
-
declare const isPaymail: (s: string) => boolean;
|
|
136
|
-
/** Satoshis for a request (sats as given, or usd converted, rounded up). */
|
|
137
|
-
declare function amountInSats(req: Pick<PayRequest, 'sats' | 'usd'>, o?: PayOptions): Promise<number>;
|
|
138
|
-
/** Default paymail resolver: bsvalias P2P Payment Destination (BRC-? / capability 2a40af698840). */
|
|
139
|
-
declare function resolvePaymailP2P(paymail: string, sats: number, f?: typeof fetch): Promise<{
|
|
140
|
-
outputs: {
|
|
141
|
-
script: string;
|
|
142
|
-
satoshis: number;
|
|
143
|
-
}[];
|
|
144
|
-
reference: string | undefined;
|
|
145
|
-
submit: ((hex: string) => Promise<void>) | undefined;
|
|
146
|
-
}>;
|
|
147
|
-
/** Pay a paymail, address or identity key. One wallet prompt; never retried. */
|
|
148
|
-
declare function pay(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
149
|
-
/** pay() labelled as a tip. */
|
|
150
|
-
declare function tip(source: PaySource, req: PayRequest, o?: PayOptions): Promise<PayResult>;
|
|
151
|
-
interface TokenQuote {
|
|
152
|
-
/** Outputs to fund, as your server priced them (e.g. payment to the seller + fee). */
|
|
153
|
-
outputs: PayOutput[];
|
|
154
|
-
description?: string;
|
|
155
|
-
/** Called with the result after the wallet signs; e.g. POST txid + tx to your server for verifyPayment. */
|
|
156
|
-
onPaid?: (r: PayResult) => Promise<void> | void;
|
|
157
|
-
}
|
|
158
|
-
interface BuyTokenRequest {
|
|
159
|
-
token: string;
|
|
160
|
-
amount: number | string;
|
|
161
|
-
/** The hook point: return the outputs for this purchase (usually from your server). */
|
|
162
|
-
quote: (req: {
|
|
163
|
-
token: string;
|
|
164
|
-
amount: number | string;
|
|
165
|
-
}) => Promise<TokenQuote>;
|
|
166
|
-
labels?: string[];
|
|
167
|
-
}
|
|
168
|
-
/** Buy a token: your `quote` hook prices it, the wallet pays once, `onPaid` delivers it. */
|
|
169
|
-
declare function buyToken(source: PaySource, req: BuyTokenRequest): Promise<PayResult>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Every wallet the user could connect with, behind one interface. BRC-100 first: bWalletX, then any
|
|
173
|
-
* other wallet that announces itself (Yours, Metanet, ...), the in-app browser, optional localhost
|
|
174
|
-
* desktop wallets, phone pairing, and app-supplied adapters (e.g. the transitional HandCash one).
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
type WalletKind = 'brc100' | 'pairing' | 'handcash' | 'custom';
|
|
178
|
-
interface ConnectedWallet {
|
|
179
|
-
/** The BRC-100 wallet. null for a non-BRC-100 adapter (HandCash today). */
|
|
180
|
-
wallet: WalletInterface | null;
|
|
181
|
-
/** What pay/tip use: the BRC-100 wallet, or the adapter's own payer. */
|
|
182
|
-
payer: PaySource | null;
|
|
183
|
-
/** The identity public key (hex) when the wallet has one. */
|
|
184
|
-
identityKey: string | null;
|
|
185
|
-
handle?: string;
|
|
186
|
-
paymail?: string;
|
|
187
|
-
/** Which option connected. */
|
|
188
|
-
optionId: string;
|
|
189
|
-
kind: WalletKind;
|
|
190
|
-
/** True for adapters kept only until the vendor ships BRC-100. */
|
|
191
|
-
transitional?: boolean;
|
|
192
|
-
}
|
|
193
|
-
interface WalletOption {
|
|
194
|
-
id: string;
|
|
195
|
-
name: string;
|
|
196
|
-
icon?: string;
|
|
197
|
-
kind: WalletKind;
|
|
198
|
-
rdns?: string;
|
|
199
|
-
/** True for bWalletX (extension, in-app or paired). */
|
|
200
|
-
isBwalletX: boolean;
|
|
201
|
-
connect(): Promise<ConnectedWallet>;
|
|
202
|
-
}
|
|
203
|
-
/** Wrap any BRC-100 wallet as a picker option. */
|
|
204
|
-
declare function brc100Option(wallet: WalletInterface, info: {
|
|
205
|
-
id: string;
|
|
206
|
-
name: string;
|
|
207
|
-
icon?: string;
|
|
208
|
-
rdns?: string;
|
|
209
|
-
isBwalletX?: boolean;
|
|
210
|
-
}): WalletOption;
|
|
211
|
-
/** Phone / web.bwalletx.com pairing as an option (shows a QR through `pairing`). Reuses a stored pairing first. */
|
|
212
|
-
declare function pairingOption(pairing: PairingOptions | (() => PairingOptions)): WalletOption;
|
|
213
|
-
interface HandCashAdapterOptions {
|
|
214
|
-
/**
|
|
215
|
-
* Your existing HandCash Connect login (redirect/popup + your server route). Resolve with the
|
|
216
|
-
* profile once the user is signed in. This package does not import any HandCash SDK.
|
|
217
|
-
*/
|
|
218
|
-
login(): Promise<{
|
|
219
|
-
handle: string;
|
|
220
|
-
paymail?: string;
|
|
221
|
-
identityKey?: string;
|
|
222
|
-
}>;
|
|
223
|
-
/** Your existing HandCash pay call (usually a server route using the auth token). Optional. */
|
|
224
|
-
pay?: Extract<PaySource, {
|
|
225
|
-
pay: unknown;
|
|
226
|
-
}>['pay'];
|
|
227
|
-
icon?: string;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* TRANSITIONAL. Keeps existing HandCash users working behind the same picker until HandCash's
|
|
231
|
-
* BRC-100 support ships; then remove this and HandCash appears as an ordinary BRC-100 wallet.
|
|
232
|
-
*/
|
|
233
|
-
declare function handcashAdapter(o: HandCashAdapterOptions): WalletOption;
|
|
234
|
-
interface DiscoverWalletsOptions {
|
|
235
|
-
/** Longest wait for BRC-100 announcements, ms. Default 300; ends early once a wallet has announced. */
|
|
236
|
-
ms?: number;
|
|
237
|
-
/**
|
|
238
|
-
* Also probe desktop wallets on localhost (Metanet / json-api on 3321, Cicada on 3301).
|
|
239
|
-
* Off by default: some browsers prompt for local-network access.
|
|
240
|
-
*/
|
|
241
|
-
probeLocal?: boolean;
|
|
242
|
-
/** Add the phone pairing option (needs a way to show the QR, e.g. pairingModal()). */
|
|
243
|
-
pairing?: PairingOptions | (() => PairingOptions);
|
|
244
|
-
/** App-supplied options appended at the end (e.g. handcashAdapter(...)). */
|
|
245
|
-
extra?: WalletOption[];
|
|
246
|
-
}
|
|
247
|
-
/** All wallets we can see, bWalletX first. SSR-safe: resolves [] (plus `extra`) outside a browser. */
|
|
248
|
-
declare function discoverWallets(o?: DiscoverWalletsOptions): Promise<WalletOption[]>;
|
|
249
|
-
|
|
250
|
-
export { restorePairing as A, type BuyTokenRequest as B, type ConnectedWallet as C, type DiscoverWalletsOptions as D, tip as E, type HandCashAdapterOptions as H, type LegacyPayer as L, type PayRequest as P, type SocketFactory as S, type TokenQuote as T, type WalletOption as W, type PayResult as a, type PayOptions as b, PaymentError as c, brc100Option as d, discoverWallets as e, type PairingOptions as f, BRC29_PROTOCOL as g, handcashAdapter as h, type Brc29Remittance as i, type PairConnectionOptions as j, type PairStorage as k, type PairedWallet as l, type PayOutput as m, type PaySource as n, type PaymentErrorCode as o, pairingOption as p, type SocketLike as q, type WalletKind as r, amountInSats as s, buyToken as t, clearPairing as u, isIdentityKeyHex as v, isPaymail as w, pairBwalletX as x, pay as y, resolvePaymailP2P as z };
|