applesauce-wallet-connect 0.0.0-next-20250828144630 → 3.0.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/wallet-connect.d.ts +8 -2
- package/dist/wallet-connect.js +13 -14
- package/dist/wallet-service.d.ts +9 -3
- package/dist/wallet-service.js +14 -11
- package/package.json +4 -4
- package/dist/interop.d.ts +0 -35
- package/dist/interop.js +0 -19
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/wallet-connect.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { EventSigner } from "applesauce-factory";
|
|
|
3
3
|
import { NostrEvent } from "nostr-tools";
|
|
4
4
|
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
|
5
5
|
import { GetBalanceResult, GetInfoResult, ListTransactionsResult, LookupInvoiceResult, MakeInvoiceParams, MakeInvoiceResult, NotificationType, PayInvoiceResult, PayKeysendResult, WalletAuthURI, WalletConnectEncryptionMethod, WalletConnectURI, WalletMethod, WalletNotification, WalletRequest, WalletResponse, WalletSupport } from "./helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "./types.js";
|
|
7
7
|
export type SerializedWalletConnect = WalletConnectURI;
|
|
8
|
-
export type WalletConnectOptions =
|
|
8
|
+
export type WalletConnectOptions = {
|
|
9
9
|
/** The secret to use for the connection */
|
|
10
10
|
secret: Uint8Array;
|
|
11
11
|
/** The relays to use for the connection */
|
|
@@ -14,6 +14,12 @@ export type WalletConnectOptions = NostrConnectionMethodsOptions & {
|
|
|
14
14
|
service?: string;
|
|
15
15
|
/** Default timeout for RPC requests in milliseconds */
|
|
16
16
|
timeout?: number;
|
|
17
|
+
/** A method for subscribing to relays */
|
|
18
|
+
subscriptionMethod?: NostrSubscriptionMethod;
|
|
19
|
+
/** A method for publishing events */
|
|
20
|
+
publishMethod?: NostrPublishMethod;
|
|
21
|
+
/** An optional pool for connection methods */
|
|
22
|
+
pool?: NostrPool;
|
|
17
23
|
};
|
|
18
24
|
export declare class WalletConnect {
|
|
19
25
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
package/dist/wallet-connect.js
CHANGED
|
@@ -2,11 +2,10 @@ import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
|
2
2
|
import { simpleTimeout } from "applesauce-core";
|
|
3
3
|
import { create } from "applesauce-factory";
|
|
4
4
|
import { finalizeEvent, getPublicKey, nip04, nip44, verifyEvent } from "nostr-tools";
|
|
5
|
-
import { BehaviorSubject, defer, filter, firstValueFrom, from, fromEvent, identity, ignoreElements, lastValueFrom, map, merge, mergeMap,
|
|
5
|
+
import { BehaviorSubject, defer, filter, firstValueFrom, from, fromEvent, identity, ignoreElements, lastValueFrom, map, merge, mergeMap, ReplaySubject, share, switchMap, takeUntil, tap, timer, toArray, } from "rxjs";
|
|
6
6
|
import { WalletRequestBlueprint } from "./blueprints/index.js";
|
|
7
7
|
import { createWalletError } from "./helpers/error.js";
|
|
8
8
|
import { createWalletAuthURI, getPreferredEncryption, getWalletNotification, getWalletRequestEncryption, getWalletResponse, getWalletResponseRequestId, getWalletSupport, isWalletNotificationLocked, isWalletResponseLocked, parseWalletConnectURI, supportsMethod, supportsNotifications, supportsNotificationType, unlockWalletNotification, unlockWalletResponse, WALLET_INFO_KIND, WALLET_LEGACY_NOTIFICATION_KIND, WALLET_NOTIFICATION_KIND, WALLET_RESPONSE_KIND, } from "./helpers/index.js";
|
|
9
|
-
import { getConnectionMethods, } from "./interop.js";
|
|
10
9
|
export class WalletConnect {
|
|
11
10
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
|
12
11
|
static subscriptionMethod = undefined;
|
|
@@ -59,7 +58,15 @@ export class WalletConnect {
|
|
|
59
58
|
},
|
|
60
59
|
};
|
|
61
60
|
// Get the subscription and publish methods
|
|
62
|
-
const
|
|
61
|
+
const subscriptionMethod = options.subscriptionMethod ||
|
|
62
|
+
options.pool?.subscription ||
|
|
63
|
+
WalletConnect.subscriptionMethod ||
|
|
64
|
+
WalletConnect.pool?.subscription;
|
|
65
|
+
if (!subscriptionMethod)
|
|
66
|
+
throw new Error("Missing subscriptionMethod, either pass a method or set WalletConnect.subscriptionMethod");
|
|
67
|
+
const publishMethod = options.publishMethod || options.pool?.publish || WalletConnect.publishMethod || WalletConnect.pool?.publish;
|
|
68
|
+
if (!publishMethod)
|
|
69
|
+
throw new Error("Missing publishMethod, either pass a method or set WalletConnect.publishMethod");
|
|
63
70
|
// Use arrow functions so "this" isn't bound to the signer
|
|
64
71
|
this.subscriptionMethod = (relays, filters) => subscriptionMethod(relays, filters);
|
|
65
72
|
this.publishMethod = (relays, event) => publishMethod(relays, event);
|
|
@@ -68,14 +75,10 @@ export class WalletConnect {
|
|
|
68
75
|
const client = getPublicKey(this.secret);
|
|
69
76
|
// If the service is not known yet, subscribe to a wallet info event tagging the client
|
|
70
77
|
if (!service)
|
|
71
|
-
return
|
|
72
|
-
// Keep the connection open indefinitely
|
|
73
|
-
repeat(),
|
|
74
|
-
// Retry on connection failure
|
|
75
|
-
retry(),
|
|
78
|
+
return this.subscriptionMethod(this.relays, [{ kinds: [WALLET_INFO_KIND], "#p": [client] }]).pipe(
|
|
76
79
|
// Ignore strings (support for applesauce-relay)
|
|
77
80
|
filter((event) => typeof event !== "string"));
|
|
78
|
-
return
|
|
81
|
+
return this.subscriptionMethod(this.relays, [
|
|
79
82
|
// Subscribe to response events
|
|
80
83
|
{
|
|
81
84
|
kinds: [WALLET_RESPONSE_KIND, WALLET_NOTIFICATION_KIND, WALLET_LEGACY_NOTIFICATION_KIND],
|
|
@@ -84,11 +87,7 @@ export class WalletConnect {
|
|
|
84
87
|
},
|
|
85
88
|
// Subscribe to wallet info events
|
|
86
89
|
{ kinds: [WALLET_INFO_KIND], authors: [service] },
|
|
87
|
-
])
|
|
88
|
-
// Keep the connection open indefinitely
|
|
89
|
-
repeat(),
|
|
90
|
-
// Retry on connection failure
|
|
91
|
-
retry(),
|
|
90
|
+
]).pipe(
|
|
92
91
|
// Ignore strings (support for applesauce-relay)
|
|
93
92
|
filter((event) => typeof event !== "string"),
|
|
94
93
|
// Only include events from the wallet service
|
package/dist/wallet-service.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EventSigner } from "applesauce-factory";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
3
|
import { Observable, Subscription } from "rxjs";
|
|
4
|
-
import { WalletAuthURI } from "./helpers/auth-uri.js";
|
|
5
4
|
import { WalletErrorCode } from "./helpers/error.js";
|
|
6
5
|
import { NotificationType, WalletNotification } from "./helpers/notification.js";
|
|
7
6
|
import { GetBalanceParams, GetInfoParams, ListTransactionsParams, LookupInvoiceParams, MakeInvoiceParams, MultiPayInvoiceParams, MultiPayKeysendParams, PayInvoiceParams, PayKeysendParams, WalletRequest } from "./helpers/request.js";
|
|
8
7
|
import { GetBalanceResult, GetInfoResult, ListTransactionsResult, LookupInvoiceResult, MakeInvoiceResult, MultiPayInvoiceResult, MultiPayKeysendResult, PayInvoiceResult, PayKeysendResult, WalletResponse } from "./helpers/response.js";
|
|
9
8
|
import { WalletSupport } from "./helpers/support.js";
|
|
10
|
-
import {
|
|
9
|
+
import { NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "./types.js";
|
|
10
|
+
import { WalletAuthURI } from "./helpers/auth-uri.js";
|
|
11
11
|
/** Handler function for pay_invoice method */
|
|
12
12
|
export type PayInvoiceHandler = (params: PayInvoiceParams) => Promise<PayInvoiceResult>;
|
|
13
13
|
/** Handler function for multi_pay_invoice method */
|
|
@@ -45,7 +45,7 @@ export type SerializedWalletService = {
|
|
|
45
45
|
relays: string[];
|
|
46
46
|
};
|
|
47
47
|
/** Options for creating a WalletService */
|
|
48
|
-
export interface WalletServiceOptions
|
|
48
|
+
export interface WalletServiceOptions {
|
|
49
49
|
/** The relays to use for the service */
|
|
50
50
|
relays: string[];
|
|
51
51
|
/** The signer to use for creating and unlocking events */
|
|
@@ -58,6 +58,12 @@ export interface WalletServiceOptions extends NostrConnectionMethodsOptions {
|
|
|
58
58
|
handlers: WalletServiceHandlers;
|
|
59
59
|
/** An array of notifications this wallet supports */
|
|
60
60
|
notifications?: NotificationType[];
|
|
61
|
+
/** An optional method for subscribing to relays */
|
|
62
|
+
subscriptionMethod?: NostrSubscriptionMethod;
|
|
63
|
+
/** An optional method for publishing events */
|
|
64
|
+
publishMethod?: NostrPublishMethod;
|
|
65
|
+
/** An optional pool for connection methods */
|
|
66
|
+
pool?: NostrPool;
|
|
61
67
|
}
|
|
62
68
|
/** NIP-47 Wallet Service implementation */
|
|
63
69
|
export declare class WalletService {
|
package/dist/wallet-service.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
2
|
import { create } from "applesauce-factory";
|
|
3
3
|
import { generateSecretKey, getPublicKey, verifyEvent } from "nostr-tools";
|
|
4
|
-
import { filter,
|
|
5
|
-
import { bytesToHex } from "@noble/hashes/utils";
|
|
4
|
+
import { filter, mergeMap, share } from "rxjs";
|
|
6
5
|
import { WalletLegacyNotificationBlueprint, WalletNotificationBlueprint } from "./blueprints/notification.js";
|
|
7
6
|
import { WalletResponseBlueprint } from "./blueprints/response.js";
|
|
8
7
|
import { WalletSupportBlueprint } from "./blueprints/support.js";
|
|
9
|
-
import { parseWalletAuthURI } from "./helpers/auth-uri.js";
|
|
10
8
|
import { WalletBaseError } from "./helpers/error.js";
|
|
11
9
|
import { getWalletRequest, isWalletRequestExpired, isWalletRequestLocked, unlockWalletRequest, WALLET_REQUEST_KIND, } from "./helpers/request.js";
|
|
12
|
-
import {
|
|
10
|
+
import { bytesToHex } from "@noble/hashes/utils";
|
|
11
|
+
import { parseWalletAuthURI } from "./helpers/auth-uri.js";
|
|
13
12
|
/** NIP-47 Wallet Service implementation */
|
|
14
13
|
export class WalletService {
|
|
15
14
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
|
@@ -57,7 +56,15 @@ export class WalletService {
|
|
|
57
56
|
this.client = getPublicKey(this.secret);
|
|
58
57
|
}
|
|
59
58
|
// Get the subscription and publish methods
|
|
60
|
-
const
|
|
59
|
+
const subscriptionMethod = options.subscriptionMethod ||
|
|
60
|
+
options.pool?.subscription ||
|
|
61
|
+
WalletService.subscriptionMethod ||
|
|
62
|
+
WalletService.pool?.subscription;
|
|
63
|
+
if (!subscriptionMethod)
|
|
64
|
+
throw new Error("Missing subscriptionMethod, either pass a method or set WalletService.subscriptionMethod");
|
|
65
|
+
const publishMethod = options.publishMethod || options.pool?.publish || WalletService.publishMethod || WalletService.pool?.publish;
|
|
66
|
+
if (!publishMethod)
|
|
67
|
+
throw new Error("Missing publishMethod, either pass a method or set WalletService.publishMethod");
|
|
61
68
|
// Use arrow functions so "this" isn't bound to the signer
|
|
62
69
|
this.subscriptionMethod = (relays, filters) => subscriptionMethod(relays, filters);
|
|
63
70
|
this.publishMethod = (relays, event) => publishMethod(relays, event);
|
|
@@ -84,17 +91,13 @@ export class WalletService {
|
|
|
84
91
|
// Get our public key
|
|
85
92
|
this.pubkey = await this.signer.getPublicKey();
|
|
86
93
|
// Create shared request observable with ref counting and timer
|
|
87
|
-
this.events$ =
|
|
94
|
+
this.events$ = this.subscriptionMethod(this.relays, [
|
|
88
95
|
{
|
|
89
96
|
kinds: [WALLET_REQUEST_KIND],
|
|
90
97
|
"#p": [this.pubkey], // Only requests directed to us
|
|
91
98
|
authors: [this.client], // Only requests from the client
|
|
92
99
|
},
|
|
93
|
-
])
|
|
94
|
-
// Keep the connection open indefinitely
|
|
95
|
-
repeat(),
|
|
96
|
-
// Retry on connection failure
|
|
97
|
-
retry(),
|
|
100
|
+
]).pipe(
|
|
98
101
|
// Ignore strings (support for applesauce-relay)
|
|
99
102
|
filter((event) => typeof event !== "string"),
|
|
100
103
|
// Only include valid wallet request events
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-wallet-connect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"applesauce-core": "
|
|
62
|
-
"applesauce-factory": "
|
|
63
|
-
"nostr-tools": "
|
|
61
|
+
"applesauce-core": "^3.0.0",
|
|
62
|
+
"applesauce-factory": "^3.0.0",
|
|
63
|
+
"nostr-tools": "^2.13",
|
|
64
64
|
"@noble/hashes": "^1.7.1",
|
|
65
65
|
"rxjs": "^7.8.1"
|
|
66
66
|
},
|
package/dist/interop.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Filter, NostrEvent } from "nostr-tools";
|
|
2
|
-
import { ObservableInput } from "rxjs";
|
|
3
|
-
/** A method used to subscribe to events on a set of relays */
|
|
4
|
-
export type NostrSubscriptionMethod = (relays: string[], filters: Filter[]) => ObservableInput<NostrEvent | string>;
|
|
5
|
-
/** A method used for publishing an event, can return a Promise that completes when published or an Observable that completes when published*/
|
|
6
|
-
export type NostrPublishMethod = (relays: string[], event: NostrEvent) => Promise<any> | ObservableInput<any>;
|
|
7
|
-
/** A simple pool type that combines the subscription and publish methods */
|
|
8
|
-
export type NostrPool = {
|
|
9
|
-
subscription: NostrSubscriptionMethod;
|
|
10
|
-
publish: NostrPublishMethod;
|
|
11
|
-
};
|
|
12
|
-
/** Options for setting the subscription and publish methods */
|
|
13
|
-
export type NostrConnectionMethodsOptions = {
|
|
14
|
-
/** An optional method for subscribing to relays */
|
|
15
|
-
subscriptionMethod?: NostrSubscriptionMethod;
|
|
16
|
-
/** An optional method for publishing events */
|
|
17
|
-
publishMethod?: NostrPublishMethod;
|
|
18
|
-
/** An optional pool for connection methods */
|
|
19
|
-
pool?: NostrPool;
|
|
20
|
-
};
|
|
21
|
-
/** A class that implements has global fallback methods for subscription and publish methods */
|
|
22
|
-
export interface NostrConnectionClassMethods {
|
|
23
|
-
new (...args: any[]): any;
|
|
24
|
-
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
|
25
|
-
subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
26
|
-
/** A fallback method to use for publishMethod if none is passed in when creating the client */
|
|
27
|
-
publishMethod: NostrPublishMethod | undefined;
|
|
28
|
-
/** A fallback pool to use if none is pass in when creating the signer */
|
|
29
|
-
pool: NostrPool | undefined;
|
|
30
|
-
}
|
|
31
|
-
/** Get the subscription and publish methods for a NostrConnect class */
|
|
32
|
-
export declare function getConnectionMethods(options: NostrConnectionMethodsOptions, cls?: NostrConnectionClassMethods): {
|
|
33
|
-
subscriptionMethod: NostrSubscriptionMethod;
|
|
34
|
-
publishMethod: NostrPublishMethod;
|
|
35
|
-
};
|
package/dist/interop.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** Get the subscription and publish methods for a NostrConnect class */
|
|
2
|
-
export function getConnectionMethods(options, cls) {
|
|
3
|
-
const subscriptionMethod = options.subscriptionMethod ||
|
|
4
|
-
options.pool?.subscription.bind(options.pool) ||
|
|
5
|
-
cls?.subscriptionMethod ||
|
|
6
|
-
cls?.pool?.subscription.bind(cls.pool);
|
|
7
|
-
if (!subscriptionMethod)
|
|
8
|
-
throw new Error("Missing subscriptionMethod, either pass a method or set subscriptionMethod globally on the class");
|
|
9
|
-
const publishMethod = options.publishMethod ||
|
|
10
|
-
options.pool?.publish.bind(options.pool) ||
|
|
11
|
-
cls?.publishMethod ||
|
|
12
|
-
cls?.pool?.publish.bind(cls.pool);
|
|
13
|
-
if (!publishMethod)
|
|
14
|
-
throw new Error("Missing publishMethod, either pass a method or set publishMethod globally on the class");
|
|
15
|
-
return {
|
|
16
|
-
subscriptionMethod,
|
|
17
|
-
publishMethod,
|
|
18
|
-
};
|
|
19
|
-
}
|