applesauce-wallet-connect 6.0.0 → 6.2.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/dist/wallet-connect.d.ts +8 -1
- package/dist/wallet-connect.js +43 -2
- package/dist/wallet-service.js +1 -1
- package/package.json +5 -5
package/dist/wallet-connect.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EventSigner } from "applesauce-core";
|
|
|
3
3
|
import { NostrEvent } from "applesauce-core/helpers";
|
|
4
4
|
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
|
5
5
|
import { NotificationType, WalletAuthURI, WalletConnectEncryptionMethod, WalletConnectURI, WalletNotification, WalletNotificationEvent, WalletResponseEvent, WalletSupport } from "./helpers/index.js";
|
|
6
|
-
import { CommonWalletMethods, GetBalanceMethod, GetInfoMethod, ListTransactionsMethod, LookupInvoiceMethod, MakeInvoiceMethod, MultiPayInvoiceMethod, MultiPayKeysendMethod, PayInvoiceMethod, PayKeysendMethod, TWalletMethod } from "./helpers/methods.js";
|
|
6
|
+
import { CommonWalletMethods, GetBalanceMethod, GetInfoMethod, ListTransactionsMethod, LookupInvoiceMethod, MakeInvoiceMethod, MultiPayInvoiceMethod, MultiPayKeysendMethod, PayInvoiceMethod, PayKeysendMethod, Transaction, TWalletMethod } from "./helpers/methods.js";
|
|
7
7
|
import { NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "./interop.js";
|
|
8
8
|
export type SerializedWalletConnect = WalletConnectURI;
|
|
9
9
|
export type WalletConnectOptions = NostrConnectionMethodsOptions & {
|
|
@@ -18,6 +18,11 @@ export type WalletConnectOptions = NostrConnectionMethodsOptions & {
|
|
|
18
18
|
/** Whether to accept the relay hint from the wallet service */
|
|
19
19
|
acceptRelayHint?: boolean;
|
|
20
20
|
};
|
|
21
|
+
export type WaitForPaidInvoice = MakeInvoiceMethod["response"]["result"] | LookupInvoiceMethod["request"]["params"];
|
|
22
|
+
export type WaitForPaidOptions = {
|
|
23
|
+
/** Polling interval in milliseconds when payment_received notifications are not supported */
|
|
24
|
+
pollInterval?: number;
|
|
25
|
+
};
|
|
21
26
|
export declare class WalletConnect<Methods extends TWalletMethod = CommonWalletMethods> {
|
|
22
27
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
|
23
28
|
static subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
@@ -128,6 +133,8 @@ export declare class WalletConnect<Methods extends TWalletMethod = CommonWalletM
|
|
|
128
133
|
}>): Promise<MultiPayKeysendMethod["response"]["result"][]>;
|
|
129
134
|
/** Create a new invoice */
|
|
130
135
|
makeInvoice(amount: number, options?: Omit<MakeInvoiceMethod["request"]["params"], "amount">): Promise<MakeInvoiceMethod["response"]["result"]>;
|
|
136
|
+
/** Wait for an invoice to be paid, or reject when it expires */
|
|
137
|
+
waitForPaid(invoice: WaitForPaidInvoice, options?: WaitForPaidOptions): Promise<Transaction>;
|
|
131
138
|
/** Look up an invoice by payment hash or invoice string */
|
|
132
139
|
lookupInvoice(payment_hash?: string, invoice?: string): Promise<LookupInvoiceMethod["response"]["result"]>;
|
|
133
140
|
/** List transactions */
|
package/dist/wallet-connect.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
1
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
2
2
|
import { simpleTimeout } from "applesauce-core";
|
|
3
3
|
import { finalizeEvent, getPublicKey, verifyEvent } from "applesauce-core/helpers";
|
|
4
4
|
import { nip04, nip44 } from "applesauce-core/helpers/encryption";
|
|
5
|
-
import { BehaviorSubject, combineLatest, defer, filter, firstValueFrom, from, fromEvent, identity, ignoreElements, lastValueFrom, map, merge, mergeMap, of, repeat, ReplaySubject, retry, share, switchMap, take, takeUntil, tap, timer, toArray, } from "rxjs";
|
|
5
|
+
import { BehaviorSubject, combineLatest, defer, filter, firstValueFrom, from, fromEvent, identity, ignoreElements, interval, lastValueFrom, map, merge, mergeMap, of, repeat, ReplaySubject, retry, share, switchMap, take, takeUntil, tap, timer, toArray, } from "rxjs";
|
|
6
6
|
import { WalletRequestFactory } from "./factories/index.js";
|
|
7
7
|
import { createWalletError } from "./helpers/error.js";
|
|
8
8
|
import { createWalletAuthURI, createWalletConnectURI, getPreferredEncryption, getWalletRequestEncryption, getWalletResponseRequestId, getWalletSupport, isValidWalletNotification, isValidWalletResponse, parseWalletConnectURI, supportsMethod, supportsNotifications, supportsNotificationType, unlockWalletNotification, unlockWalletResponse, WALLET_INFO_KIND, WALLET_LEGACY_NOTIFICATION_KIND, WALLET_NOTIFICATION_KIND, WALLET_RESPONSE_KIND, } from "./helpers/index.js";
|
|
@@ -280,6 +280,47 @@ export class WalletConnect {
|
|
|
280
280
|
async makeInvoice(amount, options) {
|
|
281
281
|
return await this.genericRequest("make_invoice", { amount, ...options });
|
|
282
282
|
}
|
|
283
|
+
/** Wait for an invoice to be paid, or reject when it expires */
|
|
284
|
+
async waitForPaid(invoice, options = {}) {
|
|
285
|
+
const transaction = "state" in invoice ? invoice : await this.lookupInvoice(invoice.payment_hash, invoice.invoice);
|
|
286
|
+
if (transaction.state === "settled")
|
|
287
|
+
return Promise.resolve(transaction);
|
|
288
|
+
if (!transaction.payment_hash)
|
|
289
|
+
return Promise.reject(new Error("Invoice is missing payment hash"));
|
|
290
|
+
const expiresAt = transaction.expires_at ? transaction.expires_at * 1000 : undefined;
|
|
291
|
+
const now = Date.now();
|
|
292
|
+
if (expiresAt && expiresAt <= now)
|
|
293
|
+
return Promise.reject(new Error("Invoice expired"));
|
|
294
|
+
const supportsNotifications = await this.supportsNotificationType("payment_received");
|
|
295
|
+
if (!supportsNotifications) {
|
|
296
|
+
return await firstValueFrom(interval(options.pollInterval ?? 5000).pipe(switchMap(() => this.lookupInvoice(transaction.payment_hash, transaction.invoice)), mergeMap((result) => {
|
|
297
|
+
if (result.state === "settled")
|
|
298
|
+
return of(result);
|
|
299
|
+
if (result.state === "expired")
|
|
300
|
+
throw new Error("Invoice expired");
|
|
301
|
+
return [];
|
|
302
|
+
}), simpleTimeout(expiresAt ? expiresAt - now : Infinity)));
|
|
303
|
+
}
|
|
304
|
+
return new Promise((resolve, reject) => {
|
|
305
|
+
const subscription = this.notification("payment_received", (payment) => {
|
|
306
|
+
if (payment.payment_hash !== transaction.payment_hash)
|
|
307
|
+
return;
|
|
308
|
+
cleanup();
|
|
309
|
+
resolve(payment);
|
|
310
|
+
});
|
|
311
|
+
const timeout = expiresAt
|
|
312
|
+
? setTimeout(() => {
|
|
313
|
+
cleanup();
|
|
314
|
+
reject(new Error("Invoice expired"));
|
|
315
|
+
}, expiresAt - now)
|
|
316
|
+
: undefined;
|
|
317
|
+
function cleanup() {
|
|
318
|
+
subscription.unsubscribe();
|
|
319
|
+
if (timeout)
|
|
320
|
+
clearTimeout(timeout);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
283
324
|
/** Look up an invoice by payment hash or invoice string */
|
|
284
325
|
async lookupInvoice(payment_hash, invoice) {
|
|
285
326
|
return await this.genericRequest("lookup_invoice", { payment_hash, invoice });
|
package/dist/wallet-service.js
CHANGED
|
@@ -2,7 +2,7 @@ import { logger } from "applesauce-core";
|
|
|
2
2
|
import { verifyEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { generateSecretKey, getPublicKey } from "applesauce-core/helpers/keys";
|
|
4
4
|
import { filter, from, mergeMap, repeat, retry, share, tap } from "rxjs";
|
|
5
|
-
import { bytesToHex } from "@noble/hashes/utils";
|
|
5
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
6
6
|
import { WalletLegacyNotificationFactory, WalletNotificationFactory } from "./factories/notification.js";
|
|
7
7
|
import { WalletResponseFactory } from "./factories/response.js";
|
|
8
8
|
import { WalletInfoFactory } from "./factories/support.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-wallet-connect",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@noble/hashes": "^
|
|
62
|
-
"applesauce-common": "^6.
|
|
63
|
-
"applesauce-core": "^6.
|
|
61
|
+
"@noble/hashes": "^2.2.0",
|
|
62
|
+
"applesauce-common": "^6.2.0",
|
|
63
|
+
"applesauce-core": "^6.2.0",
|
|
64
64
|
"rxjs": "^7.8.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
68
|
-
"applesauce-signers": "^6.0.0",
|
|
69
68
|
"@types/debug": "^4.1.12",
|
|
69
|
+
"applesauce-signers": "^6.2.0",
|
|
70
70
|
"rimraf": "^6.0.1",
|
|
71
71
|
"typescript": "^5.8.3",
|
|
72
72
|
"vitest": "^4.0.15"
|