applesauce-wallet-connect 4.0.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 +1 -1
- package/dist/helpers/request.d.ts +6 -116
- package/dist/helpers/response.d.ts +6 -128
- package/dist/helpers/support.d.ts +7 -7
- package/dist/helpers/support.js +1 -14
- package/dist/wallet-connect.d.ts +47 -19
- package/dist/wallet-connect.js +49 -54
- package/dist/wallet-service.d.ts +31 -43
- package/dist/wallet-service.js +30 -40
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,10 +41,10 @@ Create a wallet service that handles NIP-47 requests:
|
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
import { WalletService } from "applesauce-wallet-connect";
|
|
44
|
-
import {
|
|
44
|
+
import { PrivateKeySigner } from "applesauce-signers";
|
|
45
45
|
|
|
46
46
|
// Create a signer for the service
|
|
47
|
-
const signer = new
|
|
47
|
+
const signer = new PrivateKeySigner();
|
|
48
48
|
|
|
49
49
|
// Define method handlers
|
|
50
50
|
const handlers = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventBlueprint } from "applesauce-factory";
|
|
2
|
-
import { WalletRequest } from "../helpers/request.js";
|
|
3
2
|
import { WalletConnectEncryptionMethod } from "../helpers/encryption.js";
|
|
3
|
+
import { TWalletMethod } from "../helpers/methods.js";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a walelt request event
|
|
6
6
|
* @param service - The service pubkey
|
|
7
7
|
* @param request - The request to create an event for
|
|
8
8
|
*/
|
|
9
|
-
export declare function WalletRequestBlueprint<
|
|
9
|
+
export declare function WalletRequestBlueprint<Method extends TWalletMethod>(service: string, request: Method["request"], encryption?: WalletConnectEncryptionMethod): EventBlueprint;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventBlueprint } from "applesauce-factory";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
import {
|
|
3
|
+
import { TWalletMethod } from "../helpers/methods.js";
|
|
4
4
|
/** Creates a wallet response event */
|
|
5
|
-
export declare function WalletResponseBlueprint(request: NostrEvent, response:
|
|
5
|
+
export declare function WalletResponseBlueprint<Method extends TWalletMethod>(request: NostrEvent, response: Method["response"] | Method["error"]): EventBlueprint;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { EventBlueprint } from "applesauce-factory";
|
|
2
2
|
import { WalletSupport } from "../helpers/support.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { TWalletMethod } from "../helpers/methods.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a wallet info event
|
|
6
|
+
* @param info - The wallet support information
|
|
7
|
+
* @param client - The client pubkey
|
|
8
|
+
* @param overrideRelay - An optional relay to tell the client which relay to use (for nostr+walletauth URI connections)
|
|
9
|
+
*/
|
|
10
|
+
export declare function WalletSupportBlueprint<Methods extends TWalletMethod>(info: WalletSupport<Methods>, client?: string, overrideRelay?: string): EventBlueprint;
|
|
@@ -2,9 +2,14 @@ import { blueprint } from "applesauce-factory";
|
|
|
2
2
|
import { setContent } from "applesauce-factory/operations/content";
|
|
3
3
|
import { includeSingletonTag } from "applesauce-factory/operations";
|
|
4
4
|
import { WALLET_INFO_KIND } from "../helpers/support.js";
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Creates a wallet info event
|
|
7
|
+
* @param info - The wallet support information
|
|
8
|
+
* @param client - The client pubkey
|
|
9
|
+
* @param overrideRelay - An optional relay to tell the client which relay to use (for nostr+walletauth URI connections)
|
|
10
|
+
*/
|
|
11
|
+
export function WalletSupportBlueprint(info, client, overrideRelay) {
|
|
7
12
|
return blueprint(WALLET_INFO_KIND, setContent(info.methods.join(" ")), info.encryption ? includeSingletonTag(["encryption", info.encryption.join(" ")]) : undefined, info.notifications ? includeSingletonTag(["notifications", info.notifications.join(" ")]) : undefined,
|
|
8
13
|
// An optional client pubkey to notify the service is created (used for nostr+walletauth URI connections)
|
|
9
|
-
client ? includeSingletonTag(["p", client]) : undefined);
|
|
14
|
+
client ? includeSingletonTag(overrideRelay ? ["p", client, overrideRelay] : ["p", client]) : undefined);
|
|
10
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NotificationType } from "./notification.js";
|
|
2
|
-
import {
|
|
3
|
-
export interface WalletAuthURI {
|
|
2
|
+
import { CommonWalletMethods, TWalletMethod } from "./methods.js";
|
|
3
|
+
export interface WalletAuthURI<Methods extends TWalletMethod = CommonWalletMethods> {
|
|
4
4
|
/** The public key of the client requesting authorization */
|
|
5
5
|
client: string;
|
|
6
6
|
/** Required. URL of the relay where the client intends to communicate with the wallet service */
|
|
@@ -18,7 +18,7 @@ export interface WalletAuthURI {
|
|
|
18
18
|
/** The reset the budget at the end of the given budget renewal. Can be never (default), daily, weekly, monthly, yearly (optional) */
|
|
19
19
|
budgetRenewal?: "never" | "daily" | "weekly" | "monthly" | "yearly";
|
|
20
20
|
/** List of request types that you need permission for (optional) */
|
|
21
|
-
methods?:
|
|
21
|
+
methods?: Methods["method"][];
|
|
22
22
|
/** List of notification types that you need permission for (optional) */
|
|
23
23
|
notifications?: NotificationType[];
|
|
24
24
|
/** The makes an isolated app connection / sub-wallet with its own balance and only access to its own transaction list (optional) */
|
|
@@ -32,13 +32,11 @@ export interface WalletAuthURI {
|
|
|
32
32
|
* Parses a nostr+walletauth URI
|
|
33
33
|
* @throws {Error} if the authorization URI is invalid
|
|
34
34
|
*/
|
|
35
|
-
export declare function parseWalletAuthURI(authURI: string): WalletAuthURI
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
*/
|
|
39
|
-
export declare function createWalletAuthURI(parts: WalletAuthURI): string;
|
|
35
|
+
export declare function parseWalletAuthURI<Methods extends TWalletMethod = CommonWalletMethods>(authURI: string): WalletAuthURI<Methods>;
|
|
36
|
+
/** Creates a nostr+walletauth URI from a WalletAuthURI object */
|
|
37
|
+
export declare function createWalletAuthURI<Methods extends TWalletMethod = CommonWalletMethods>(parts: WalletAuthURI<Methods>): string;
|
|
40
38
|
/**
|
|
41
39
|
* Validates a WalletAuthURI object
|
|
42
40
|
* @returns true if valid, throws Error if invalid
|
|
43
41
|
*/
|
|
44
|
-
export declare function validateWalletAuthURI(parts: WalletAuthURI): boolean;
|
|
42
|
+
export declare function validateWalletAuthURI(parts: WalletAuthURI<TWalletMethod>): boolean;
|
package/dist/helpers/auth-uri.js
CHANGED
|
@@ -60,9 +60,7 @@ export function parseWalletAuthURI(authURI) {
|
|
|
60
60
|
walletName,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Creates a nostr+walletauth URI from a WalletAuthURI object
|
|
65
|
-
*/
|
|
63
|
+
/** Creates a nostr+walletauth URI from a WalletAuthURI object */
|
|
66
64
|
export function createWalletAuthURI(parts) {
|
|
67
65
|
validateWalletAuthURI(parts);
|
|
68
66
|
// Determine the protocol based on whether wallet name is specified
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { WalletErrorCode } from "./error.js";
|
|
2
|
+
import { WalletSupport } from "./support.js";
|
|
3
|
+
/** Base request structure for all NIP-47 requests */
|
|
4
|
+
export interface TWalletRequest<Method extends string, Params> {
|
|
5
|
+
/** The method to call */
|
|
6
|
+
method: Method;
|
|
7
|
+
/** Parameters for the method */
|
|
8
|
+
params: Params;
|
|
9
|
+
}
|
|
10
|
+
/** Error object for wallet responses */
|
|
11
|
+
export interface TWalletResponseError {
|
|
12
|
+
type: WalletErrorCode;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
/** Base response structure for all NIP-47 responses */
|
|
16
|
+
export type TWalletErrorResponse<Method extends string> = {
|
|
17
|
+
/** Indicates the structure of the result field */
|
|
18
|
+
result_type: Method;
|
|
19
|
+
/** Error object, non-null in case of error */
|
|
20
|
+
error: TWalletResponseError;
|
|
21
|
+
result: null;
|
|
22
|
+
};
|
|
23
|
+
export type TWalletSuccessResponse<Method extends string, Result> = {
|
|
24
|
+
/** Indicates the structure of the result field */
|
|
25
|
+
result_type: Method;
|
|
26
|
+
error: null;
|
|
27
|
+
/** Result object, null in case of error */
|
|
28
|
+
result: Result;
|
|
29
|
+
};
|
|
30
|
+
/** Merged wallet response and request types, this is designed to only be used with typescript */
|
|
31
|
+
export type TWalletMethod<Method extends string = string, Params extends any = any, Result extends any = any> = {
|
|
32
|
+
/** Method string */
|
|
33
|
+
method: Method;
|
|
34
|
+
/** Request type */
|
|
35
|
+
request: TWalletRequest<Method, Params>;
|
|
36
|
+
/** Response success type */
|
|
37
|
+
response: TWalletSuccessResponse<Method, Result>;
|
|
38
|
+
/** Response error type */
|
|
39
|
+
error: TWalletErrorResponse<Method>;
|
|
40
|
+
};
|
|
41
|
+
/** TLV record for keysend payments */
|
|
42
|
+
export interface TLVRecord {
|
|
43
|
+
/** TLV type */
|
|
44
|
+
type: number;
|
|
45
|
+
/** Hex encoded TLV value */
|
|
46
|
+
value: string;
|
|
47
|
+
}
|
|
48
|
+
/** Transaction object used in multiple response types */
|
|
49
|
+
export interface Transaction {
|
|
50
|
+
/** Type of transaction */
|
|
51
|
+
type: "incoming" | "outgoing";
|
|
52
|
+
/** State of the transaction */
|
|
53
|
+
state: "pending" | "settled" | "expired" | "failed";
|
|
54
|
+
/** Value in msats */
|
|
55
|
+
amount: number;
|
|
56
|
+
/** Value in msats */
|
|
57
|
+
fees_paid: number;
|
|
58
|
+
/** Invoice/payment creation unix timestamp */
|
|
59
|
+
created_at: number;
|
|
60
|
+
/** Encoded invoice, optional */
|
|
61
|
+
invoice?: string;
|
|
62
|
+
/** Invoice's description, optional */
|
|
63
|
+
description?: string;
|
|
64
|
+
/** Invoice's description hash, optional */
|
|
65
|
+
description_hash?: string;
|
|
66
|
+
/** Payment's preimage, optional if unpaid */
|
|
67
|
+
preimage?: string;
|
|
68
|
+
/** Payment hash for the payment, optional */
|
|
69
|
+
payment_hash?: string;
|
|
70
|
+
/** Invoice expiration unix timestamp, optional if not applicable */
|
|
71
|
+
expires_at?: number;
|
|
72
|
+
/** Invoice/payment settlement unix timestamp, optional if unpaid */
|
|
73
|
+
settled_at?: number;
|
|
74
|
+
/** Generic metadata that can be used to add things like zap/boostagram details */
|
|
75
|
+
metadata?: Record<string, any>;
|
|
76
|
+
}
|
|
77
|
+
export type PayInvoiceMethod = TWalletMethod<"pay_invoice", {
|
|
78
|
+
/** BOLT11 invoice */
|
|
79
|
+
invoice: string;
|
|
80
|
+
/** Invoice amount in msats, optional */
|
|
81
|
+
amount?: number;
|
|
82
|
+
}, {
|
|
83
|
+
/** Preimage of the payment */
|
|
84
|
+
preimage: string;
|
|
85
|
+
/** Value in msats, optional */
|
|
86
|
+
fees_paid?: number;
|
|
87
|
+
}>;
|
|
88
|
+
export type MultiPayInvoiceMethod = TWalletMethod<"multi_pay_invoice", {
|
|
89
|
+
/** Array of invoices to pay */
|
|
90
|
+
invoices: Array<{
|
|
91
|
+
/** ID to identify this invoice in the response */
|
|
92
|
+
id?: string;
|
|
93
|
+
/** BOLT11 invoice */
|
|
94
|
+
invoice: string;
|
|
95
|
+
/** Invoice amount in msats, optional */
|
|
96
|
+
amount?: number;
|
|
97
|
+
}>;
|
|
98
|
+
}, {
|
|
99
|
+
/** Preimage of the payment */
|
|
100
|
+
preimage: string;
|
|
101
|
+
/** Value in msats, optional */
|
|
102
|
+
fees_paid?: number;
|
|
103
|
+
}>;
|
|
104
|
+
export type PayKeysendMethod = TWalletMethod<"pay_keysend", {
|
|
105
|
+
/** Amount in msats, required */
|
|
106
|
+
amount: number;
|
|
107
|
+
/** Payee pubkey, required */
|
|
108
|
+
pubkey: string;
|
|
109
|
+
/** Preimage of the payment, optional */
|
|
110
|
+
preimage?: string;
|
|
111
|
+
/** TLV records, optional */
|
|
112
|
+
tlv_records?: TLVRecord[];
|
|
113
|
+
}, {
|
|
114
|
+
/** Preimage of the payment */
|
|
115
|
+
preimage: string;
|
|
116
|
+
/** Value in msats, optional */
|
|
117
|
+
fees_paid?: number;
|
|
118
|
+
}>;
|
|
119
|
+
export type MultiPayKeysendMethod = TWalletMethod<"multi_pay_keysend", {
|
|
120
|
+
/** Array of keysend payments */
|
|
121
|
+
keysends: Array<{
|
|
122
|
+
/** ID to identify this keysend in the response */
|
|
123
|
+
id?: string;
|
|
124
|
+
/** Payee pubkey, required */
|
|
125
|
+
pubkey: string;
|
|
126
|
+
/** Amount in msats, required */
|
|
127
|
+
amount: number;
|
|
128
|
+
/** Preimage of the payment, optional */
|
|
129
|
+
preimage?: string;
|
|
130
|
+
/** TLV records, optional */
|
|
131
|
+
tlv_records?: TLVRecord[];
|
|
132
|
+
}>;
|
|
133
|
+
}, {
|
|
134
|
+
/** Preimage of the payment */
|
|
135
|
+
preimage: string;
|
|
136
|
+
/** Value in msats, optional */
|
|
137
|
+
fees_paid?: number;
|
|
138
|
+
}>;
|
|
139
|
+
export type MakeInvoiceMethod = TWalletMethod<"make_invoice", {
|
|
140
|
+
/** Value in msats */
|
|
141
|
+
amount: number;
|
|
142
|
+
/** Invoice's description, optional */
|
|
143
|
+
description?: string;
|
|
144
|
+
/** Invoice's description hash, optional */
|
|
145
|
+
description_hash?: string;
|
|
146
|
+
/** Expiry in seconds from time invoice is created, optional */
|
|
147
|
+
expiry?: number;
|
|
148
|
+
}, Transaction>;
|
|
149
|
+
export type LookupInvoiceMethod = TWalletMethod<"lookup_invoice", {
|
|
150
|
+
/** Payment hash of the invoice, one of payment_hash or invoice is required */
|
|
151
|
+
payment_hash?: string;
|
|
152
|
+
/** Invoice to lookup */
|
|
153
|
+
invoice?: string;
|
|
154
|
+
}, Transaction>;
|
|
155
|
+
export type ListTransactionsMethod = TWalletMethod<"list_transactions", {
|
|
156
|
+
/** Starting timestamp in seconds since epoch (inclusive), optional */
|
|
157
|
+
from?: number;
|
|
158
|
+
/** Ending timestamp in seconds since epoch (inclusive), optional */
|
|
159
|
+
until?: number;
|
|
160
|
+
/** Maximum number of invoices to return, optional */
|
|
161
|
+
limit?: number;
|
|
162
|
+
/** Offset of the first invoice to return, optional */
|
|
163
|
+
offset?: number;
|
|
164
|
+
/** Include unpaid invoices, optional, default false */
|
|
165
|
+
unpaid?: boolean;
|
|
166
|
+
/** "incoming" for invoices, "outgoing" for payments, undefined for both */
|
|
167
|
+
type?: "incoming" | "outgoing";
|
|
168
|
+
}, {
|
|
169
|
+
/** Array of transactions */
|
|
170
|
+
transactions: Transaction[];
|
|
171
|
+
}>;
|
|
172
|
+
export type GetBalanceMethod = TWalletMethod<"get_balance", {}, {
|
|
173
|
+
/** User's balance in msats */
|
|
174
|
+
balance: number;
|
|
175
|
+
}>;
|
|
176
|
+
/** Type for wallet get_info */
|
|
177
|
+
export type WalletInfo = Omit<WalletSupport, "encryption"> & {
|
|
178
|
+
/** Node alias */
|
|
179
|
+
alias?: string;
|
|
180
|
+
/** Node color as hex string */
|
|
181
|
+
color?: string;
|
|
182
|
+
/** Node public key as hex string */
|
|
183
|
+
pubkey?: string;
|
|
184
|
+
/** Network type */
|
|
185
|
+
network?: "mainnet" | "testnet" | "signet" | "regtest";
|
|
186
|
+
/** Current block height */
|
|
187
|
+
block_height?: number;
|
|
188
|
+
/** Current block hash as hex string */
|
|
189
|
+
block_hash?: string;
|
|
190
|
+
};
|
|
191
|
+
export type GetInfoMethod = TWalletMethod<"get_info", {}, WalletInfo>;
|
|
192
|
+
/** Union type for all wallet method definitions */
|
|
193
|
+
export type CommonWalletMethods = PayInvoiceMethod | MultiPayInvoiceMethod | PayKeysendMethod | MultiPayKeysendMethod | MakeInvoiceMethod | LookupInvoiceMethod | ListTransactionsMethod | GetBalanceMethod | GetInfoMethod;
|
|
194
|
+
/** Withdraw a token from the wallet */
|
|
195
|
+
export type CashuWithdrawMethod = TWalletMethod<"cashu_withdraw", {
|
|
196
|
+
/** Token amount */
|
|
197
|
+
amount: number;
|
|
198
|
+
/** required token unit */
|
|
199
|
+
unit: string;
|
|
200
|
+
/** Optional array of mints, if provided token MUST be from one */
|
|
201
|
+
mints?: string[];
|
|
202
|
+
/** Size of proofs (optional) */
|
|
203
|
+
proofs?: number[];
|
|
204
|
+
/** Lock to pubkey (optional) */
|
|
205
|
+
p2pk?: string;
|
|
206
|
+
}, {
|
|
207
|
+
token: string;
|
|
208
|
+
}>;
|
|
209
|
+
/** Deposit a token into the wallet */
|
|
210
|
+
export type CashuDepositMethod = TWalletMethod<"cashu_deposit", {
|
|
211
|
+
/** Token to deposit */
|
|
212
|
+
token: string;
|
|
213
|
+
}, {
|
|
214
|
+
success: true;
|
|
215
|
+
}>;
|
|
216
|
+
export type CashuPayRequestMethod = TWalletMethod<"cashu_pay_request", {
|
|
217
|
+
/** Cashu payment request. if request originally does not contain an amount they client may add one and re-encode */
|
|
218
|
+
request: string;
|
|
219
|
+
}, {
|
|
220
|
+
success: true;
|
|
221
|
+
}>;
|
|
222
|
+
/** Info for a single mint used in the wallet service */
|
|
223
|
+
export type CashuMintInfo = {
|
|
224
|
+
/** Mint URL */
|
|
225
|
+
url: string;
|
|
226
|
+
/** Units and balances */
|
|
227
|
+
balances: Record<string, number>;
|
|
228
|
+
};
|
|
229
|
+
/** Get the list of mints that are used in the wallet and their balances */
|
|
230
|
+
export type CashuListMintsMethod = TWalletMethod<"cashu_list_mints", {}, {
|
|
231
|
+
mints: CashuMintInfo[];
|
|
232
|
+
}>;
|
|
233
|
+
/** Union of all cashu methods */
|
|
234
|
+
export type CashuWalletMethods = CashuWithdrawMethod | CashuDepositMethod | CashuPayRequestMethod | CashuListMintsMethod;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HiddenContentSigner, KnownEvent, UnlockedHiddenContent } from "applesauce-core/helpers";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
import { Transaction } from "./
|
|
3
|
+
import { Transaction } from "./methods.js";
|
|
4
4
|
export declare const WALLET_NOTIFICATION_KIND = 23197;
|
|
5
5
|
export declare const WALLET_LEGACY_NOTIFICATION_KIND = 23196;
|
|
6
6
|
/** A type for validated wallet notification events */
|
|
@@ -1,131 +1,21 @@
|
|
|
1
1
|
import { HiddenContentSigner, KnownEvent, UnlockedHiddenContent } from "applesauce-core/helpers";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
3
|
import { WalletConnectEncryptionMethod } from "./encryption.js";
|
|
4
|
-
import {
|
|
4
|
+
import { TWalletMethod } from "./methods.js";
|
|
5
5
|
export declare const WALLET_REQUEST_KIND = 23194;
|
|
6
6
|
export type WalletRequestEvent = KnownEvent<typeof WALLET_REQUEST_KIND>;
|
|
7
7
|
/** A symbol used to cache the wallet request on the event */
|
|
8
8
|
export declare const WalletRequestSymbol: unique symbol;
|
|
9
9
|
/** Type for events with unlocked hidden content */
|
|
10
|
-
export type UnlockedWalletRequest = UnlockedHiddenContent & {
|
|
11
|
-
[WalletRequestSymbol]:
|
|
10
|
+
export type UnlockedWalletRequest<Method extends TWalletMethod = TWalletMethod> = UnlockedHiddenContent & {
|
|
11
|
+
[WalletRequestSymbol]: Method["request"];
|
|
12
12
|
};
|
|
13
|
-
/** TLV record for keysend payments */
|
|
14
|
-
export interface TLVRecord {
|
|
15
|
-
/** TLV type */
|
|
16
|
-
type: number;
|
|
17
|
-
/** Hex encoded TLV value */
|
|
18
|
-
value: string;
|
|
19
|
-
}
|
|
20
|
-
/** Base request structure for all NIP-47 requests */
|
|
21
|
-
export interface BaseWalletRequest<TMethod extends WalletMethod, TParams> {
|
|
22
|
-
/** The method to call */
|
|
23
|
-
method: TMethod;
|
|
24
|
-
/** Parameters for the method */
|
|
25
|
-
params: TParams;
|
|
26
|
-
}
|
|
27
|
-
/** Parameters for pay_invoice method */
|
|
28
|
-
export interface PayInvoiceParams {
|
|
29
|
-
/** BOLT11 invoice */
|
|
30
|
-
invoice: string;
|
|
31
|
-
/** Invoice amount in msats, optional */
|
|
32
|
-
amount?: number;
|
|
33
|
-
}
|
|
34
|
-
export type PayInvoiceRequest = BaseWalletRequest<"pay_invoice", PayInvoiceParams>;
|
|
35
|
-
/** Parameters for multi_pay_invoice method */
|
|
36
|
-
export interface MultiPayInvoiceParams {
|
|
37
|
-
/** Array of invoices to pay */
|
|
38
|
-
invoices: Array<{
|
|
39
|
-
/** ID to identify this invoice in the response */
|
|
40
|
-
id?: string;
|
|
41
|
-
/** BOLT11 invoice */
|
|
42
|
-
invoice: string;
|
|
43
|
-
/** Invoice amount in msats, optional */
|
|
44
|
-
amount?: number;
|
|
45
|
-
}>;
|
|
46
|
-
}
|
|
47
|
-
export type MultiPayInvoiceRequest = BaseWalletRequest<"multi_pay_invoice", MultiPayInvoiceParams>;
|
|
48
|
-
/** Parameters for pay_keysend method */
|
|
49
|
-
export interface PayKeysendParams {
|
|
50
|
-
/** Amount in msats, required */
|
|
51
|
-
amount: number;
|
|
52
|
-
/** Payee pubkey, required */
|
|
53
|
-
pubkey: string;
|
|
54
|
-
/** Preimage of the payment, optional */
|
|
55
|
-
preimage?: string;
|
|
56
|
-
/** TLV records, optional */
|
|
57
|
-
tlv_records?: TLVRecord[];
|
|
58
|
-
}
|
|
59
|
-
export type PayKeysendRequest = BaseWalletRequest<"pay_keysend", PayKeysendParams>;
|
|
60
|
-
/** Parameters for multi_pay_keysend method */
|
|
61
|
-
export interface MultiPayKeysendParams {
|
|
62
|
-
/** Array of keysend payments */
|
|
63
|
-
keysends: Array<{
|
|
64
|
-
/** ID to identify this keysend in the response */
|
|
65
|
-
id?: string;
|
|
66
|
-
/** Payee pubkey, required */
|
|
67
|
-
pubkey: string;
|
|
68
|
-
/** Amount in msats, required */
|
|
69
|
-
amount: number;
|
|
70
|
-
/** Preimage of the payment, optional */
|
|
71
|
-
preimage?: string;
|
|
72
|
-
/** TLV records, optional */
|
|
73
|
-
tlv_records?: TLVRecord[];
|
|
74
|
-
}>;
|
|
75
|
-
}
|
|
76
|
-
export type MultiPayKeysendRequest = BaseWalletRequest<"multi_pay_keysend", MultiPayKeysendParams>;
|
|
77
|
-
/** Parameters for make_invoice method */
|
|
78
|
-
export interface MakeInvoiceParams {
|
|
79
|
-
/** Value in msats */
|
|
80
|
-
amount: number;
|
|
81
|
-
/** Invoice's description, optional */
|
|
82
|
-
description?: string;
|
|
83
|
-
/** Invoice's description hash, optional */
|
|
84
|
-
description_hash?: string;
|
|
85
|
-
/** Expiry in seconds from time invoice is created, optional */
|
|
86
|
-
expiry?: number;
|
|
87
|
-
}
|
|
88
|
-
export type MakeInvoiceRequest = BaseWalletRequest<"make_invoice", MakeInvoiceParams>;
|
|
89
|
-
/** Parameters for lookup_invoice method */
|
|
90
|
-
export interface LookupInvoiceParams {
|
|
91
|
-
/** Payment hash of the invoice, one of payment_hash or invoice is required */
|
|
92
|
-
payment_hash?: string;
|
|
93
|
-
/** Invoice to lookup */
|
|
94
|
-
invoice?: string;
|
|
95
|
-
}
|
|
96
|
-
export type LookupInvoiceRequest = BaseWalletRequest<"lookup_invoice", LookupInvoiceParams>;
|
|
97
|
-
/** Parameters for list_transactions method */
|
|
98
|
-
export interface ListTransactionsParams {
|
|
99
|
-
/** Starting timestamp in seconds since epoch (inclusive), optional */
|
|
100
|
-
from?: number;
|
|
101
|
-
/** Ending timestamp in seconds since epoch (inclusive), optional */
|
|
102
|
-
until?: number;
|
|
103
|
-
/** Maximum number of invoices to return, optional */
|
|
104
|
-
limit?: number;
|
|
105
|
-
/** Offset of the first invoice to return, optional */
|
|
106
|
-
offset?: number;
|
|
107
|
-
/** Include unpaid invoices, optional, default false */
|
|
108
|
-
unpaid?: boolean;
|
|
109
|
-
/** "incoming" for invoices, "outgoing" for payments, undefined for both */
|
|
110
|
-
type?: "incoming" | "outgoing";
|
|
111
|
-
}
|
|
112
|
-
export type ListTransactionsRequest = BaseWalletRequest<"list_transactions", ListTransactionsParams>;
|
|
113
|
-
/** Parameters for get_balance method */
|
|
114
|
-
export interface GetBalanceParams {
|
|
115
|
-
}
|
|
116
|
-
export type GetBalanceRequest = BaseWalletRequest<"get_balance", GetBalanceParams>;
|
|
117
|
-
/** Parameters for get_info method */
|
|
118
|
-
export interface GetInfoParams {
|
|
119
|
-
}
|
|
120
|
-
export type GetInfoRequest = BaseWalletRequest<"get_info", GetInfoParams>;
|
|
121
|
-
/** Union type for all NIP-47 request types */
|
|
122
|
-
export type WalletRequest = PayInvoiceRequest | MultiPayInvoiceRequest | PayKeysendRequest | MultiPayKeysendRequest | MakeInvoiceRequest | LookupInvoiceRequest | ListTransactionsRequest | GetBalanceRequest | GetInfoRequest;
|
|
123
13
|
/** Checks if a kind 23194 event is locked */
|
|
124
|
-
export declare function isWalletRequestUnlocked(request: any): request is UnlockedWalletRequest
|
|
14
|
+
export declare function isWalletRequestUnlocked<Method extends TWalletMethod = TWalletMethod>(request: any): request is UnlockedWalletRequest<Method>;
|
|
125
15
|
/** Unlocks a kind 23194 event */
|
|
126
|
-
export declare function unlockWalletRequest(request: NostrEvent, signer: HiddenContentSigner): Promise<
|
|
16
|
+
export declare function unlockWalletRequest<Method extends TWalletMethod = TWalletMethod>(request: NostrEvent, signer: HiddenContentSigner): Promise<Method["request"] | undefined>;
|
|
127
17
|
/** Gets the wallet request from a kind 23194 event */
|
|
128
|
-
export declare function getWalletRequest(request: NostrEvent):
|
|
18
|
+
export declare function getWalletRequest<Method extends TWalletMethod = TWalletMethod>(request: NostrEvent): Method["request"] | undefined;
|
|
129
19
|
/** Returns the wallet service pubkey from a request */
|
|
130
20
|
export declare function getWalletRequestServicePubkey(request: WalletRequestEvent): string;
|
|
131
21
|
export declare function getWalletRequestServicePubkey(request: NostrEvent): string | undefined;
|
|
@@ -1,143 +1,21 @@
|
|
|
1
1
|
import { EncryptionMethod, HiddenContentSigner, KnownEvent, UnlockedHiddenContent } from "applesauce-core/helpers";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
import {
|
|
4
|
-
import { NotificationType } from "./notification.js";
|
|
5
|
-
import { WalletMethod } from "./support.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
7
|
/** Type for events with unlocked hidden content */
|
|
10
|
-
export type UnlockedWalletResponse = UnlockedHiddenContent & {
|
|
11
|
-
[WalletResponseSymbol]:
|
|
8
|
+
export type UnlockedWalletResponse<Method extends TWalletMethod = TWalletMethod> = UnlockedHiddenContent & {
|
|
9
|
+
[WalletResponseSymbol]: Method["response"];
|
|
12
10
|
};
|
|
13
11
|
/** Type for validated wallet response events */
|
|
14
12
|
export type WalletResponseEvent = KnownEvent<typeof WALLET_RESPONSE_KIND>;
|
|
15
|
-
/** Error object for wallet responses */
|
|
16
|
-
export interface WalletResponseError {
|
|
17
|
-
type: WalletErrorCode;
|
|
18
|
-
message: string;
|
|
19
|
-
}
|
|
20
|
-
/** Base response structure for all NIP-47 responses */
|
|
21
|
-
export type BaseWalletResponse<TResultType extends WalletMethod, TResult> = {
|
|
22
|
-
/** Indicates the structure of the result field */
|
|
23
|
-
result_type: TResultType;
|
|
24
|
-
/** Error object, non-null in case of error */
|
|
25
|
-
error: WalletResponseError;
|
|
26
|
-
result: null;
|
|
27
|
-
} | {
|
|
28
|
-
/** Indicates the structure of the result field */
|
|
29
|
-
result_type: TResultType;
|
|
30
|
-
error: null;
|
|
31
|
-
/** Result object, null in case of error */
|
|
32
|
-
result: TResult;
|
|
33
|
-
};
|
|
34
|
-
/** Transaction object used in multiple response types */
|
|
35
|
-
export interface Transaction {
|
|
36
|
-
/** Type of transaction */
|
|
37
|
-
type: "incoming" | "outgoing";
|
|
38
|
-
/** State of the transaction */
|
|
39
|
-
state: "pending" | "settled" | "expired" | "failed";
|
|
40
|
-
/** Value in msats */
|
|
41
|
-
amount: number;
|
|
42
|
-
/** Value in msats */
|
|
43
|
-
fees_paid: number;
|
|
44
|
-
/** Invoice/payment creation unix timestamp */
|
|
45
|
-
created_at: number;
|
|
46
|
-
/** Encoded invoice, optional */
|
|
47
|
-
invoice?: string;
|
|
48
|
-
/** Invoice's description, optional */
|
|
49
|
-
description?: string;
|
|
50
|
-
/** Invoice's description hash, optional */
|
|
51
|
-
description_hash?: string;
|
|
52
|
-
/** Payment's preimage, optional if unpaid */
|
|
53
|
-
preimage?: string;
|
|
54
|
-
/** Payment hash for the payment, optional */
|
|
55
|
-
payment_hash?: string;
|
|
56
|
-
/** Invoice expiration unix timestamp, optional if not applicable */
|
|
57
|
-
expires_at?: number;
|
|
58
|
-
/** Invoice/payment settlement unix timestamp, optional if unpaid */
|
|
59
|
-
settled_at?: number;
|
|
60
|
-
/** Generic metadata that can be used to add things like zap/boostagram details */
|
|
61
|
-
metadata?: Record<string, any>;
|
|
62
|
-
}
|
|
63
|
-
/** Response for pay_invoice method */
|
|
64
|
-
export interface PayInvoiceResult {
|
|
65
|
-
/** Preimage of the payment */
|
|
66
|
-
preimage: string;
|
|
67
|
-
/** Value in msats, optional */
|
|
68
|
-
fees_paid?: number;
|
|
69
|
-
}
|
|
70
|
-
export type PayInvoiceResponse = BaseWalletResponse<"pay_invoice", PayInvoiceResult>;
|
|
71
|
-
/** Response for multi_pay_invoice method */
|
|
72
|
-
export interface MultiPayInvoiceResult {
|
|
73
|
-
/** Preimage of the payment */
|
|
74
|
-
preimage: string;
|
|
75
|
-
/** Value in msats, optional */
|
|
76
|
-
fees_paid?: number;
|
|
77
|
-
}
|
|
78
|
-
export type MultiPayInvoiceResponse = BaseWalletResponse<"multi_pay_invoice", MultiPayInvoiceResult>;
|
|
79
|
-
/** Response for pay_keysend method */
|
|
80
|
-
export interface PayKeysendResult {
|
|
81
|
-
/** Preimage of the payment */
|
|
82
|
-
preimage: string;
|
|
83
|
-
/** Value in msats, optional */
|
|
84
|
-
fees_paid?: number;
|
|
85
|
-
}
|
|
86
|
-
export type PayKeysendResponse = BaseWalletResponse<"pay_keysend", PayKeysendResult>;
|
|
87
|
-
/** Response for multi_pay_keysend method */
|
|
88
|
-
export interface MultiPayKeysendResult {
|
|
89
|
-
/** Preimage of the payment */
|
|
90
|
-
preimage: string;
|
|
91
|
-
/** Value in msats, optional */
|
|
92
|
-
fees_paid?: number;
|
|
93
|
-
}
|
|
94
|
-
export type MultiPayKeysendResponse = BaseWalletResponse<"multi_pay_keysend", MultiPayKeysendResult>;
|
|
95
|
-
/** Response for make_invoice method */
|
|
96
|
-
export type MakeInvoiceResult = Transaction;
|
|
97
|
-
export type MakeInvoiceResponse = BaseWalletResponse<"make_invoice", MakeInvoiceResult>;
|
|
98
|
-
/** Response for lookup_invoice method */
|
|
99
|
-
export type LookupInvoiceResult = Transaction;
|
|
100
|
-
export type LookupInvoiceResponse = BaseWalletResponse<"lookup_invoice", LookupInvoiceResult>;
|
|
101
|
-
/** Response for list_transactions method */
|
|
102
|
-
export interface ListTransactionsResult {
|
|
103
|
-
/** Array of transactions */
|
|
104
|
-
transactions: Transaction[];
|
|
105
|
-
}
|
|
106
|
-
export type ListTransactionsResponse = BaseWalletResponse<"list_transactions", ListTransactionsResult>;
|
|
107
|
-
/** Response for get_balance method */
|
|
108
|
-
export interface GetBalanceResult {
|
|
109
|
-
/** User's balance in msats */
|
|
110
|
-
balance: number;
|
|
111
|
-
}
|
|
112
|
-
export type GetBalanceResponse = BaseWalletResponse<"get_balance", GetBalanceResult>;
|
|
113
|
-
/** Response for get_info method */
|
|
114
|
-
export interface GetInfoResult {
|
|
115
|
-
/** Node alias */
|
|
116
|
-
alias: string;
|
|
117
|
-
/** Node color as hex string */
|
|
118
|
-
color: string;
|
|
119
|
-
/** Node public key as hex string */
|
|
120
|
-
pubkey: string;
|
|
121
|
-
/** Network type */
|
|
122
|
-
network: "mainnet" | "testnet" | "signet" | "regtest";
|
|
123
|
-
/** Current block height */
|
|
124
|
-
block_height: number;
|
|
125
|
-
/** Current block hash as hex string */
|
|
126
|
-
block_hash: string;
|
|
127
|
-
/** List of supported methods for this connection */
|
|
128
|
-
methods: WalletMethod[];
|
|
129
|
-
/** List of supported notifications for this connection, optional */
|
|
130
|
-
notifications?: NotificationType[];
|
|
131
|
-
}
|
|
132
|
-
export type GetInfoResponse = BaseWalletResponse<"get_info", GetInfoResult>;
|
|
133
|
-
/** Union type for all NIP-47 response types */
|
|
134
|
-
export type WalletResponse = PayInvoiceResponse | MultiPayInvoiceResponse | PayKeysendResponse | MultiPayKeysendResponse | MakeInvoiceResponse | LookupInvoiceResponse | ListTransactionsResponse | GetBalanceResponse | GetInfoResponse;
|
|
135
13
|
/** Checks if a kind 23195 event is locked */
|
|
136
|
-
export declare function isWalletResponseUnlocked(response: any): response is UnlockedWalletResponse
|
|
14
|
+
export declare function isWalletResponseUnlocked<Method extends TWalletMethod = TWalletMethod>(response: any): response is UnlockedWalletResponse<Method>;
|
|
137
15
|
/** Unlocks a kind 23195 event */
|
|
138
|
-
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>;
|
|
139
17
|
/** Gets the wallet response from a kind 23195 event */
|
|
140
|
-
export declare function getWalletResponse(response: NostrEvent):
|
|
18
|
+
export declare function getWalletResponse<Method extends TWalletMethod = TWalletMethod>(response: NostrEvent): Method["response"] | undefined;
|
|
141
19
|
/** Returns the client pubkey of client this response is for */
|
|
142
20
|
export declare function getWalletResponseClientPubkey(response: WalletResponseEvent): string;
|
|
143
21
|
export declare function getWalletResponseClientPubkey(response: NostrEvent): string | undefined;
|