applesauce-wallet-connect 3.1.0 → 4.1.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/README.md +2 -2
- package/dist/blueprints/request.d.ts +2 -2
- package/dist/blueprints/response.d.ts +2 -2
- package/dist/blueprints/support.d.ts +8 -2
- package/dist/blueprints/support.js +8 -3
- package/dist/helpers/auth-uri.d.ts +7 -9
- package/dist/helpers/auth-uri.js +1 -3
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/methods.d.ts +234 -0
- package/dist/helpers/methods.js +1 -0
- package/dist/helpers/notification.d.ts +13 -5
- package/dist/helpers/notification.js +18 -12
- package/dist/helpers/request.d.ts +13 -115
- package/dist/helpers/request.js +19 -14
- package/dist/helpers/response.d.ts +14 -126
- package/dist/helpers/response.js +20 -14
- package/dist/helpers/support.d.ts +7 -7
- package/dist/helpers/support.js +1 -14
- package/dist/wallet-connect.d.ts +48 -20
- package/dist/wallet-connect.js +71 -79
- package/dist/wallet-service.d.ts +34 -47
- package/dist/wallet-service.js +43 -49
- package/package.json +7 -5
|
@@ -1,138 +1,26 @@
|
|
|
1
|
-
import { EncryptionMethod, HiddenContentSigner } from "applesauce-core/helpers";
|
|
1
|
+
import { EncryptionMethod, HiddenContentSigner, KnownEvent, UnlockedHiddenContent } from "applesauce-core/helpers";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
import {
|
|
4
|
-
import { WalletMethod } from "./support.js";
|
|
5
|
-
import { NotificationType } from "./notification.js";
|
|
3
|
+
import { TWalletMethod } from "./methods.js";
|
|
6
4
|
export declare const WALLET_RESPONSE_KIND = 23195;
|
|
7
5
|
/** A symbol used to cache the wallet response on the event */
|
|
8
6
|
export declare const WalletResponseSymbol: unique symbol;
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
message: string;
|
|
13
|
-
}
|
|
14
|
-
/** Base response structure for all NIP-47 responses */
|
|
15
|
-
export type BaseWalletResponse<TResultType extends WalletMethod, TResult> = {
|
|
16
|
-
/** Indicates the structure of the result field */
|
|
17
|
-
result_type: TResultType;
|
|
18
|
-
/** Error object, non-null in case of error */
|
|
19
|
-
error: WalletResponseError;
|
|
20
|
-
result: null;
|
|
21
|
-
} | {
|
|
22
|
-
/** Indicates the structure of the result field */
|
|
23
|
-
result_type: TResultType;
|
|
24
|
-
error: null;
|
|
25
|
-
/** Result object, null in case of error */
|
|
26
|
-
result: TResult;
|
|
7
|
+
/** Type for events with unlocked hidden content */
|
|
8
|
+
export type UnlockedWalletResponse<Method extends TWalletMethod = TWalletMethod> = UnlockedHiddenContent & {
|
|
9
|
+
[WalletResponseSymbol]: Method["response"];
|
|
27
10
|
};
|
|
28
|
-
/**
|
|
29
|
-
export
|
|
30
|
-
/** Type of transaction */
|
|
31
|
-
type: "incoming" | "outgoing";
|
|
32
|
-
/** State of the transaction */
|
|
33
|
-
state: "pending" | "settled" | "expired" | "failed";
|
|
34
|
-
/** Value in msats */
|
|
35
|
-
amount: number;
|
|
36
|
-
/** Value in msats */
|
|
37
|
-
fees_paid: number;
|
|
38
|
-
/** Invoice/payment creation unix timestamp */
|
|
39
|
-
created_at: number;
|
|
40
|
-
/** Encoded invoice, optional */
|
|
41
|
-
invoice?: string;
|
|
42
|
-
/** Invoice's description, optional */
|
|
43
|
-
description?: string;
|
|
44
|
-
/** Invoice's description hash, optional */
|
|
45
|
-
description_hash?: string;
|
|
46
|
-
/** Payment's preimage, optional if unpaid */
|
|
47
|
-
preimage?: string;
|
|
48
|
-
/** Payment hash for the payment, optional */
|
|
49
|
-
payment_hash?: string;
|
|
50
|
-
/** Invoice expiration unix timestamp, optional if not applicable */
|
|
51
|
-
expires_at?: number;
|
|
52
|
-
/** Invoice/payment settlement unix timestamp, optional if unpaid */
|
|
53
|
-
settled_at?: number;
|
|
54
|
-
/** Generic metadata that can be used to add things like zap/boostagram details */
|
|
55
|
-
metadata?: Record<string, any>;
|
|
56
|
-
}
|
|
57
|
-
/** Response for pay_invoice method */
|
|
58
|
-
export interface PayInvoiceResult {
|
|
59
|
-
/** Preimage of the payment */
|
|
60
|
-
preimage: string;
|
|
61
|
-
/** Value in msats, optional */
|
|
62
|
-
fees_paid?: number;
|
|
63
|
-
}
|
|
64
|
-
export type PayInvoiceResponse = BaseWalletResponse<"pay_invoice", PayInvoiceResult>;
|
|
65
|
-
/** Response for multi_pay_invoice method */
|
|
66
|
-
export interface MultiPayInvoiceResult {
|
|
67
|
-
/** Preimage of the payment */
|
|
68
|
-
preimage: string;
|
|
69
|
-
/** Value in msats, optional */
|
|
70
|
-
fees_paid?: number;
|
|
71
|
-
}
|
|
72
|
-
export type MultiPayInvoiceResponse = BaseWalletResponse<"multi_pay_invoice", MultiPayInvoiceResult>;
|
|
73
|
-
/** Response for pay_keysend method */
|
|
74
|
-
export interface PayKeysendResult {
|
|
75
|
-
/** Preimage of the payment */
|
|
76
|
-
preimage: string;
|
|
77
|
-
/** Value in msats, optional */
|
|
78
|
-
fees_paid?: number;
|
|
79
|
-
}
|
|
80
|
-
export type PayKeysendResponse = BaseWalletResponse<"pay_keysend", PayKeysendResult>;
|
|
81
|
-
/** Response for multi_pay_keysend method */
|
|
82
|
-
export interface MultiPayKeysendResult {
|
|
83
|
-
/** Preimage of the payment */
|
|
84
|
-
preimage: string;
|
|
85
|
-
/** Value in msats, optional */
|
|
86
|
-
fees_paid?: number;
|
|
87
|
-
}
|
|
88
|
-
export type MultiPayKeysendResponse = BaseWalletResponse<"multi_pay_keysend", MultiPayKeysendResult>;
|
|
89
|
-
/** Response for make_invoice method */
|
|
90
|
-
export type MakeInvoiceResult = Transaction;
|
|
91
|
-
export type MakeInvoiceResponse = BaseWalletResponse<"make_invoice", MakeInvoiceResult>;
|
|
92
|
-
/** Response for lookup_invoice method */
|
|
93
|
-
export type LookupInvoiceResult = Transaction;
|
|
94
|
-
export type LookupInvoiceResponse = BaseWalletResponse<"lookup_invoice", LookupInvoiceResult>;
|
|
95
|
-
/** Response for list_transactions method */
|
|
96
|
-
export interface ListTransactionsResult {
|
|
97
|
-
/** Array of transactions */
|
|
98
|
-
transactions: Transaction[];
|
|
99
|
-
}
|
|
100
|
-
export type ListTransactionsResponse = BaseWalletResponse<"list_transactions", ListTransactionsResult>;
|
|
101
|
-
/** Response for get_balance method */
|
|
102
|
-
export interface GetBalanceResult {
|
|
103
|
-
/** User's balance in msats */
|
|
104
|
-
balance: number;
|
|
105
|
-
}
|
|
106
|
-
export type GetBalanceResponse = BaseWalletResponse<"get_balance", GetBalanceResult>;
|
|
107
|
-
/** Response for get_info method */
|
|
108
|
-
export interface GetInfoResult {
|
|
109
|
-
/** Node alias */
|
|
110
|
-
alias: string;
|
|
111
|
-
/** Node color as hex string */
|
|
112
|
-
color: string;
|
|
113
|
-
/** Node public key as hex string */
|
|
114
|
-
pubkey: string;
|
|
115
|
-
/** Network type */
|
|
116
|
-
network: "mainnet" | "testnet" | "signet" | "regtest";
|
|
117
|
-
/** Current block height */
|
|
118
|
-
block_height: number;
|
|
119
|
-
/** Current block hash as hex string */
|
|
120
|
-
block_hash: string;
|
|
121
|
-
/** List of supported methods for this connection */
|
|
122
|
-
methods: WalletMethod[];
|
|
123
|
-
/** List of supported notifications for this connection, optional */
|
|
124
|
-
notifications?: NotificationType[];
|
|
125
|
-
}
|
|
126
|
-
export type GetInfoResponse = BaseWalletResponse<"get_info", GetInfoResult>;
|
|
127
|
-
/** Union type for all NIP-47 response types */
|
|
128
|
-
export type WalletResponse = PayInvoiceResponse | MultiPayInvoiceResponse | PayKeysendResponse | MultiPayKeysendResponse | MakeInvoiceResponse | LookupInvoiceResponse | ListTransactionsResponse | GetBalanceResponse | GetInfoResponse;
|
|
11
|
+
/** Type for validated wallet response events */
|
|
12
|
+
export type WalletResponseEvent = KnownEvent<typeof WALLET_RESPONSE_KIND>;
|
|
129
13
|
/** Checks if a kind 23195 event is locked */
|
|
130
|
-
export declare function
|
|
14
|
+
export declare function isWalletResponseUnlocked<Method extends TWalletMethod = TWalletMethod>(response: any): response is UnlockedWalletResponse<Method>;
|
|
131
15
|
/** Unlocks a kind 23195 event */
|
|
132
|
-
export declare function unlockWalletResponse(response: NostrEvent, signer: HiddenContentSigner, override?: EncryptionMethod): Promise<
|
|
16
|
+
export declare function unlockWalletResponse<Method extends TWalletMethod = TWalletMethod>(response: NostrEvent, signer: HiddenContentSigner, override?: EncryptionMethod): Promise<Method["response"] | undefined>;
|
|
133
17
|
/** Gets the wallet response from a kind 23195 event */
|
|
134
|
-
export declare function getWalletResponse(response: NostrEvent):
|
|
18
|
+
export declare function getWalletResponse<Method extends TWalletMethod = TWalletMethod>(response: NostrEvent): Method["response"] | undefined;
|
|
135
19
|
/** Returns the client pubkey of client this response is for */
|
|
20
|
+
export declare function getWalletResponseClientPubkey(response: WalletResponseEvent): string;
|
|
136
21
|
export declare function getWalletResponseClientPubkey(response: NostrEvent): string | undefined;
|
|
137
22
|
/** Returns the request id of the request this response is for */
|
|
23
|
+
export declare function getWalletResponseRequestId(response: WalletResponseEvent): string;
|
|
138
24
|
export declare function getWalletResponseRequestId(response: NostrEvent): string | undefined;
|
|
25
|
+
/** Checks if event is a valid wallet response event */
|
|
26
|
+
export declare function isValidWalletResponse(response: NostrEvent): response is WalletResponseEvent;
|
package/dist/helpers/response.js
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTagValue, isHiddenContentUnlocked, isNIP04Encrypted, notifyEventUpdate, setHiddenContentEncryptionMethod, unlockHiddenContent, } from "applesauce-core/helpers";
|
|
2
2
|
export const WALLET_RESPONSE_KIND = 23195;
|
|
3
3
|
// Set the encryption method to use for response kind
|
|
4
4
|
setHiddenContentEncryptionMethod(WALLET_RESPONSE_KIND, "nip04");
|
|
5
5
|
/** A symbol used to cache the wallet response on the event */
|
|
6
6
|
export const WalletResponseSymbol = Symbol("wallet-response");
|
|
7
7
|
/** Checks if a kind 23195 event is locked */
|
|
8
|
-
export function
|
|
9
|
-
return
|
|
8
|
+
export function isWalletResponseUnlocked(response) {
|
|
9
|
+
return isHiddenContentUnlocked(response) && Reflect.has(response, WalletResponseSymbol) === true;
|
|
10
10
|
}
|
|
11
11
|
/** Unlocks a kind 23195 event */
|
|
12
12
|
export async function unlockWalletResponse(response, signer, override) {
|
|
13
|
+
if (isWalletResponseUnlocked(response))
|
|
14
|
+
return response[WalletResponseSymbol];
|
|
13
15
|
const encryption = override ?? (!isNIP04Encrypted(response.content) ? "nip44" : "nip04");
|
|
14
|
-
await unlockHiddenContent(response, signer, encryption);
|
|
15
|
-
|
|
16
|
+
const content = await unlockHiddenContent(response, signer, encryption);
|
|
17
|
+
const parsed = JSON.parse(content);
|
|
18
|
+
// Save the parsed content
|
|
19
|
+
Reflect.set(response, WalletResponseSymbol, parsed);
|
|
20
|
+
notifyEventUpdate(response);
|
|
21
|
+
return parsed;
|
|
16
22
|
}
|
|
17
23
|
/** Gets the wallet response from a kind 23195 event */
|
|
18
24
|
export function getWalletResponse(response) {
|
|
19
|
-
if (
|
|
25
|
+
if (isWalletResponseUnlocked(response))
|
|
26
|
+
return response[WalletResponseSymbol];
|
|
27
|
+
else
|
|
20
28
|
return undefined;
|
|
21
|
-
return getOrComputeCachedValue(response, WalletResponseSymbol, () => {
|
|
22
|
-
const content = getHiddenContent(response);
|
|
23
|
-
if (!content)
|
|
24
|
-
return null;
|
|
25
|
-
return JSON.parse(content);
|
|
26
|
-
});
|
|
27
29
|
}
|
|
28
|
-
/** Returns the client pubkey of client this response is for */
|
|
29
30
|
export function getWalletResponseClientPubkey(response) {
|
|
30
31
|
return getTagValue(response, "p");
|
|
31
32
|
}
|
|
32
|
-
/** Returns the request id of the request this response is for */
|
|
33
33
|
export function getWalletResponseRequestId(response) {
|
|
34
34
|
return getTagValue(response, "e");
|
|
35
35
|
}
|
|
36
|
+
/** Checks if event is a valid wallet response event */
|
|
37
|
+
export function isValidWalletResponse(response) {
|
|
38
|
+
return (response.kind === WALLET_RESPONSE_KIND &&
|
|
39
|
+
getWalletResponseRequestId(response) !== undefined &&
|
|
40
|
+
getWalletResponseClientPubkey(response) !== undefined);
|
|
41
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { NostrEvent } from "nostr-tools";
|
|
2
2
|
import { WalletConnectEncryptionMethod } from "./encryption.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TWalletMethod } from "./methods.js";
|
|
4
|
+
import { NotificationType } from "./notification.js";
|
|
4
5
|
export declare const WALLET_INFO_KIND = 13194;
|
|
5
6
|
/** A symbol used to cache the wallet info on the event */
|
|
6
7
|
export declare const WalletInfoSymbol: unique symbol;
|
|
7
|
-
export type WalletMethod = "pay_invoice" | "multi_pay_invoice" | "pay_keysend" | "multi_pay_keysend" | "make_invoice" | "lookup_invoice" | "list_transactions" | "get_balance" | "get_info";
|
|
8
8
|
/** Wallet service capabilities and information */
|
|
9
|
-
export interface WalletSupport {
|
|
9
|
+
export interface WalletSupport<Methods extends TWalletMethod = TWalletMethod> {
|
|
10
10
|
/** List of supported methods for this wallet service */
|
|
11
|
-
methods:
|
|
11
|
+
methods: Array<Methods["method"]>;
|
|
12
12
|
/** List of supported encryption methods */
|
|
13
13
|
encryption: WalletConnectEncryptionMethod[];
|
|
14
14
|
/** List of supported notifications, optional */
|
|
15
15
|
notifications?: NotificationType[];
|
|
16
16
|
}
|
|
17
17
|
/** Gets the wallet info from a kind 13194 event */
|
|
18
|
-
export declare function getWalletSupport(info: NostrEvent): WalletSupport | null;
|
|
18
|
+
export declare function getWalletSupport<Methods extends TWalletMethod = TWalletMethod>(info: NostrEvent): WalletSupport<Methods> | null;
|
|
19
19
|
/** Gets the encryption methods from a wallet info event */
|
|
20
20
|
export declare function getEncryptionMethods(info: NostrEvent | WalletSupport): WalletConnectEncryptionMethod[];
|
|
21
21
|
/** Checks if the wallet service supports a specific encryption method */
|
|
@@ -23,12 +23,12 @@ export declare function supportsEncryption(info: NostrEvent | WalletSupport, enc
|
|
|
23
23
|
/** Gets the preferred encryption method (nip44_v2 preferred over nip04) */
|
|
24
24
|
export declare function getPreferredEncryption(info: NostrEvent | WalletSupport): WalletConnectEncryptionMethod;
|
|
25
25
|
/** Checks if the wallet service supports a specific method */
|
|
26
|
-
export declare function supportsMethod(info: NostrEvent | WalletSupport, method:
|
|
26
|
+
export declare function supportsMethod(info: NostrEvent | WalletSupport, method: string): boolean;
|
|
27
27
|
/** Checks if the wallet service supports notifications */
|
|
28
28
|
export declare function supportsNotifications(info: NostrEvent | WalletSupport): boolean;
|
|
29
29
|
/** Checks if the wallet service supports a specific notification type */
|
|
30
30
|
export declare function supportsNotificationType(info: NostrEvent | WalletSupport, notificationType: NotificationType): boolean;
|
|
31
31
|
/** Gets all supported methods from the wallet info */
|
|
32
|
-
export declare function getSupportedMethods(info: NostrEvent | WalletSupport):
|
|
32
|
+
export declare function getSupportedMethods(info: NostrEvent | WalletSupport): string[];
|
|
33
33
|
/** Gets all supported notifications from the wallet info */
|
|
34
34
|
export declare function getSupportedNotifications(info: NostrEvent | WalletSupport): NotificationType[];
|
package/dist/helpers/support.js
CHANGED
|
@@ -12,20 +12,7 @@ export function getWalletSupport(info) {
|
|
|
12
12
|
return null;
|
|
13
13
|
// Parse methods from content (space-separated)
|
|
14
14
|
const contentParts = content.split(/\s+/);
|
|
15
|
-
const methods = contentParts
|
|
16
|
-
.filter((part) => [
|
|
17
|
-
"pay_invoice",
|
|
18
|
-
"multi_pay_invoice",
|
|
19
|
-
"pay_keysend",
|
|
20
|
-
"multi_pay_keysend",
|
|
21
|
-
"make_invoice",
|
|
22
|
-
"lookup_invoice",
|
|
23
|
-
"list_transactions",
|
|
24
|
-
"get_balance",
|
|
25
|
-
"get_info",
|
|
26
|
-
"notifications",
|
|
27
|
-
].includes(part))
|
|
28
|
-
.filter((part) => part !== "notifications");
|
|
15
|
+
const methods = contentParts.filter((part) => part !== "notifications");
|
|
29
16
|
// Parse encryption methods from encryption tag
|
|
30
17
|
const encryptionTag = getTagValue(info, "encryption");
|
|
31
18
|
const encryption = encryptionTag
|
package/dist/wallet-connect.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { EncryptionMethod } from "applesauce-core/helpers";
|
|
|
2
2
|
import { EventSigner } from "applesauce-factory";
|
|
3
3
|
import { NostrEvent } from "nostr-tools";
|
|
4
4
|
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
|
5
|
-
import {
|
|
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
7
|
import { NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "./interop.js";
|
|
7
8
|
export type SerializedWalletConnect = WalletConnectURI;
|
|
8
9
|
export type WalletConnectOptions = NostrConnectionMethodsOptions & {
|
|
@@ -14,8 +15,10 @@ export type WalletConnectOptions = NostrConnectionMethodsOptions & {
|
|
|
14
15
|
service?: string;
|
|
15
16
|
/** Default timeout for RPC requests in milliseconds */
|
|
16
17
|
timeout?: number;
|
|
18
|
+
/** Whether to accept the relay hint from the wallet service */
|
|
19
|
+
acceptRelayHint?: boolean;
|
|
17
20
|
};
|
|
18
|
-
export declare class WalletConnect {
|
|
21
|
+
export declare class WalletConnect<Methods extends TWalletMethod = CommonWalletMethods> {
|
|
19
22
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
|
|
20
23
|
static subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
21
24
|
/** A fallback method to use for publishMethod if none is passed in when creating the client */
|
|
@@ -30,7 +33,10 @@ export declare class WalletConnect {
|
|
|
30
33
|
readonly secret: Uint8Array;
|
|
31
34
|
protected readonly signer: EventSigner;
|
|
32
35
|
/** The relays to use for the connection */
|
|
33
|
-
|
|
36
|
+
protected relays$: BehaviorSubject<string[]>;
|
|
37
|
+
get relays(): string[];
|
|
38
|
+
/** Whether to accept the relay hint from the wallet service */
|
|
39
|
+
acceptRelayHint: boolean;
|
|
34
40
|
/** The wallet service public key ( unset if waiting for service ) */
|
|
35
41
|
service$: BehaviorSubject<string | undefined>;
|
|
36
42
|
get service(): string | undefined;
|
|
@@ -48,43 +54,65 @@ export declare class WalletConnect {
|
|
|
48
54
|
protected waitForService$: Observable<string>;
|
|
49
55
|
constructor(options: WalletConnectOptions);
|
|
50
56
|
/** Process response events and return WalletResponse or throw error */
|
|
51
|
-
protected handleResponseEvent(event:
|
|
57
|
+
protected handleResponseEvent<Method extends Methods>(event: WalletResponseEvent, encryption?: EncryptionMethod): Promise<Method["response"]>;
|
|
52
58
|
/** Handle notification events */
|
|
53
|
-
protected handleNotificationEvent(event:
|
|
54
|
-
/**
|
|
55
|
-
|
|
59
|
+
protected handleNotificationEvent(event: WalletNotificationEvent): Promise<WalletNotification>;
|
|
60
|
+
/** Generic call method with generic type */
|
|
61
|
+
genericCall<Method extends TWalletMethod>(method: Method["method"], params: Method["request"]["params"], options?: {
|
|
56
62
|
timeout?: number;
|
|
57
|
-
}): Observable<
|
|
63
|
+
}): Observable<Method["response"] | Method["error"]>;
|
|
64
|
+
/** Request method with generic type */
|
|
65
|
+
genericRequest<Method extends TWalletMethod>(method: Method["method"], params: Method["request"]["params"], options?: {
|
|
66
|
+
timeout?: number;
|
|
67
|
+
}): Promise<Method["response"]["result"]>;
|
|
68
|
+
/** Call a method and return an observable of results */
|
|
69
|
+
call<K extends Methods["method"]>(method: K, params: Extract<Methods, {
|
|
70
|
+
method: K;
|
|
71
|
+
}>["request"]["params"], options?: {
|
|
72
|
+
timeout?: number;
|
|
73
|
+
}): Observable<Extract<Methods, {
|
|
74
|
+
method: K;
|
|
75
|
+
}>["response"] | Extract<Methods, {
|
|
76
|
+
method: K;
|
|
77
|
+
}>["error"]>;
|
|
78
|
+
/** Typed request method, returns the result or throws and error */
|
|
79
|
+
request<K extends Methods["method"]>(method: K, params: Extract<Methods, {
|
|
80
|
+
method: K;
|
|
81
|
+
}>["request"]["params"], options?: {
|
|
82
|
+
timeout?: number;
|
|
83
|
+
}): Promise<Extract<Methods, {
|
|
84
|
+
method: K;
|
|
85
|
+
}>["response"]["result"]>;
|
|
58
86
|
/**
|
|
59
87
|
* Listen for a type of notification
|
|
60
88
|
* @returns a method to unsubscribe the listener
|
|
61
89
|
*/
|
|
62
90
|
notification<T extends WalletNotification>(type: T["notification_type"], listener: (notification: T["notification"]) => any): Subscription;
|
|
63
91
|
/** Gets the nostr+walletauth URI for the connection */
|
|
64
|
-
getAuthURI(parts?: Omit<WalletAuthURI
|
|
92
|
+
getAuthURI(parts?: Omit<WalletAuthURI<Methods>, "client" | "relays">): string;
|
|
65
93
|
/** Wait for the wallet service to connect */
|
|
66
94
|
waitForService(abortSignal?: AbortSignal): Promise<string>;
|
|
67
95
|
/** Get the wallet support info */
|
|
68
96
|
getSupport(): Promise<WalletSupport | null>;
|
|
69
97
|
/** Check if the wallet supports a method */
|
|
70
|
-
supportsMethod(method:
|
|
98
|
+
supportsMethod(method: string): Promise<boolean>;
|
|
71
99
|
/** Check if the wallet supports notifications */
|
|
72
100
|
supportsNotifications(): Promise<boolean>;
|
|
73
101
|
/** Check if the wallet supports a notification type */
|
|
74
102
|
supportsNotificationType(type: NotificationType): Promise<boolean>;
|
|
75
103
|
/** Pay a lightning invoice */
|
|
76
|
-
payInvoice(invoice: string, amount?: number): Promise<
|
|
104
|
+
payInvoice(invoice: string, amount?: number): Promise<PayInvoiceMethod["response"]["result"]>;
|
|
77
105
|
/** Pay multiple lightning invoices */
|
|
78
106
|
payMultipleInvoices(invoices: Array<{
|
|
79
107
|
id?: string;
|
|
80
108
|
invoice: string;
|
|
81
109
|
amount?: number;
|
|
82
|
-
}>): Promise<
|
|
110
|
+
}>): Promise<MultiPayInvoiceMethod["response"]["result"][]>;
|
|
83
111
|
/** Send a keysend payment */
|
|
84
112
|
payKeysend(pubkey: string, amount: number, preimage?: string, tlv_records?: Array<{
|
|
85
113
|
type: number;
|
|
86
114
|
value: string;
|
|
87
|
-
}>): Promise<
|
|
115
|
+
}>): Promise<PayKeysendMethod["response"]["result"]>;
|
|
88
116
|
/** Send multiple keysend payments */
|
|
89
117
|
payMultipleKeysend(keysends: Array<{
|
|
90
118
|
id?: string;
|
|
@@ -95,11 +123,11 @@ export declare class WalletConnect {
|
|
|
95
123
|
type: number;
|
|
96
124
|
value: string;
|
|
97
125
|
}>;
|
|
98
|
-
}>): Promise<
|
|
126
|
+
}>): Promise<MultiPayKeysendMethod["response"]["result"][]>;
|
|
99
127
|
/** Create a new invoice */
|
|
100
|
-
makeInvoice(amount: number, options?: Omit<
|
|
128
|
+
makeInvoice(amount: number, options?: Omit<MakeInvoiceMethod["request"]["params"], "amount">): Promise<MakeInvoiceMethod["response"]["result"]>;
|
|
101
129
|
/** Look up an invoice by payment hash or invoice string */
|
|
102
|
-
lookupInvoice(payment_hash?: string, invoice?: string): Promise<
|
|
130
|
+
lookupInvoice(payment_hash?: string, invoice?: string): Promise<LookupInvoiceMethod["response"]["result"]>;
|
|
103
131
|
/** List transactions */
|
|
104
132
|
listTransactions(params?: {
|
|
105
133
|
from?: number;
|
|
@@ -108,15 +136,15 @@ export declare class WalletConnect {
|
|
|
108
136
|
offset?: number;
|
|
109
137
|
unpaid?: boolean;
|
|
110
138
|
type?: "incoming" | "outgoing";
|
|
111
|
-
}): Promise<
|
|
139
|
+
}): Promise<ListTransactionsMethod["response"]["result"]>;
|
|
112
140
|
/** Get wallet balance */
|
|
113
|
-
getBalance(): Promise<
|
|
141
|
+
getBalance(): Promise<GetBalanceMethod["response"]["result"]>;
|
|
114
142
|
/** Get wallet info */
|
|
115
|
-
getInfo(): Promise<
|
|
143
|
+
getInfo(): Promise<GetInfoMethod["response"]["result"]>;
|
|
116
144
|
/** Serialize the WalletConnect instance */
|
|
117
145
|
toJSON(): SerializedWalletConnect;
|
|
118
146
|
/** Create a new WalletConnect instance from a serialized object */
|
|
119
147
|
static fromJSON(json: SerializedWalletConnect, options?: Omit<WalletConnectOptions, "secret" | "relays" | "service">): WalletConnect;
|
|
120
148
|
/** Create a new WalletConnect instance from a connection string */
|
|
121
|
-
static fromConnectURI(connectionString: string, options?: Omit<WalletConnectOptions, "secret" | "relays" | "service">): WalletConnect
|
|
149
|
+
static fromConnectURI<Methods extends TWalletMethod = CommonWalletMethods>(connectionString: string, options?: Omit<WalletConnectOptions, "secret" | "relays" | "service">): WalletConnect<Methods>;
|
|
122
150
|
}
|