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/dist/wallet-service.js
CHANGED
|
@@ -7,7 +7,7 @@ import { WalletLegacyNotificationBlueprint, WalletNotificationBlueprint } from "
|
|
|
7
7
|
import { WalletResponseBlueprint } from "./blueprints/response.js";
|
|
8
8
|
import { WalletSupportBlueprint } from "./blueprints/support.js";
|
|
9
9
|
import { parseWalletAuthURI } from "./helpers/auth-uri.js";
|
|
10
|
-
import { WalletBaseError } from "./helpers/error.js";
|
|
10
|
+
import { NotImplementedError, WalletBaseError } from "./helpers/error.js";
|
|
11
11
|
import { getWalletRequest, isValidWalletRequest, isWalletRequestExpired, unlockWalletRequest, WALLET_REQUEST_KIND, } from "./helpers/request.js";
|
|
12
12
|
import { getConnectionMethods, } from "./interop.js";
|
|
13
13
|
/** NIP-47 Wallet Service implementation */
|
|
@@ -23,6 +23,8 @@ export class WalletService {
|
|
|
23
23
|
/** A method for publishing events */
|
|
24
24
|
publishMethod;
|
|
25
25
|
log = logger.extend("WalletService");
|
|
26
|
+
/** A special method for getting the generic wallet information */
|
|
27
|
+
getInfo;
|
|
26
28
|
/** The relays to use for the service */
|
|
27
29
|
relays;
|
|
28
30
|
/** The signer used for creating and unlocking events */
|
|
@@ -162,7 +164,9 @@ export class WalletService {
|
|
|
162
164
|
/** Publish the wallet support event */
|
|
163
165
|
async publishSupportEvent() {
|
|
164
166
|
try {
|
|
165
|
-
|
|
167
|
+
// Tell the client which relay to use if there is only one (for nostr+walletauth URI connections)
|
|
168
|
+
const overrideRelay = this.relays.length === 1 ? this.relays[0] : undefined;
|
|
169
|
+
const draft = await create({ signer: this.signer }, (WalletSupportBlueprint), this.support, this.client, overrideRelay);
|
|
166
170
|
const event = await this.signer.signEvent(draft);
|
|
167
171
|
await this.publishMethod(this.relays, event);
|
|
168
172
|
}
|
|
@@ -192,44 +196,27 @@ export class WalletService {
|
|
|
192
196
|
/** Process a decrypted wallet request */
|
|
193
197
|
async processRequest(requestEvent, request) {
|
|
194
198
|
const handler = this.handlers[request.method];
|
|
195
|
-
if (!handler) {
|
|
196
|
-
await this.sendErrorResponse(requestEvent, "NOT_IMPLEMENTED", `Method ${request.method} not supported`);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
199
|
try {
|
|
200
|
-
let result;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
break;
|
|
212
|
-
case "multi_pay_keysend":
|
|
213
|
-
result = await handler(request.params);
|
|
214
|
-
break;
|
|
215
|
-
case "make_invoice":
|
|
216
|
-
result = await handler(request.params);
|
|
217
|
-
break;
|
|
218
|
-
case "lookup_invoice":
|
|
219
|
-
result = await handler(request.params);
|
|
220
|
-
break;
|
|
221
|
-
case "list_transactions":
|
|
222
|
-
result = await handler(request.params);
|
|
223
|
-
break;
|
|
224
|
-
case "get_balance":
|
|
225
|
-
result = await handler(request.params);
|
|
226
|
-
break;
|
|
227
|
-
case "get_info":
|
|
228
|
-
result = await handler(request.params);
|
|
229
|
-
break;
|
|
200
|
+
let result = undefined;
|
|
201
|
+
// If the user has not implemented the method
|
|
202
|
+
if (!handler) {
|
|
203
|
+
// If its the get_info try to use the builtin getInfo method
|
|
204
|
+
if (request.method === "get_info") {
|
|
205
|
+
result = { ...(this.getInfo?.() ?? {}), ...this.support };
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// Else throw not supported error
|
|
209
|
+
throw new NotImplementedError(`Method ${request.method} not supported`);
|
|
210
|
+
}
|
|
230
211
|
}
|
|
212
|
+
// Otherwise use the user provided handler
|
|
213
|
+
if (!result && handler)
|
|
214
|
+
result = await handler(request.params);
|
|
215
|
+
// Throw if failed to get result
|
|
216
|
+
if (!result)
|
|
217
|
+
throw new NotImplementedError(`Method ${request.method} not supported`);
|
|
231
218
|
// Send success response
|
|
232
|
-
await this.sendSuccessResponse(requestEvent, method, result);
|
|
219
|
+
await this.sendSuccessResponse(requestEvent, request.method, result);
|
|
233
220
|
}
|
|
234
221
|
catch (error) {
|
|
235
222
|
this.log(`Error executing ${request.method}:`, error);
|
|
@@ -273,7 +260,7 @@ export class WalletService {
|
|
|
273
260
|
/** Send a response event */
|
|
274
261
|
async sendResponse(requestEvent, response) {
|
|
275
262
|
try {
|
|
276
|
-
const draft = await create({ signer: this.signer }, WalletResponseBlueprint
|
|
263
|
+
const draft = await create({ signer: this.signer }, WalletResponseBlueprint(requestEvent, response));
|
|
277
264
|
const event = await this.signer.signEvent(draft);
|
|
278
265
|
await this.publishMethod(this.relays, event);
|
|
279
266
|
}
|
|
@@ -284,10 +271,13 @@ export class WalletService {
|
|
|
284
271
|
}
|
|
285
272
|
/** Creates a service for a nostr+walletauth URI */
|
|
286
273
|
static fromAuthURI(uri, options) {
|
|
287
|
-
const
|
|
274
|
+
const authURI = typeof uri === "string" ? parseWalletAuthURI(uri) : uri;
|
|
275
|
+
const relays = options.overrideRelay
|
|
276
|
+
? [typeof options.overrideRelay === "function" ? options.overrideRelay(authURI.relays) : options.overrideRelay]
|
|
277
|
+
: authURI.relays;
|
|
288
278
|
return new WalletService({
|
|
289
279
|
...options,
|
|
290
|
-
client,
|
|
280
|
+
client: authURI.client,
|
|
291
281
|
relays,
|
|
292
282
|
});
|
|
293
283
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-wallet-connect",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@noble/hashes": "^1.7.1",
|
|
62
|
-
"applesauce-core": "^4.
|
|
62
|
+
"applesauce-core": "^4.1.0",
|
|
63
63
|
"applesauce-factory": "^4.0.0",
|
|
64
64
|
"nostr-tools": "~2.17",
|
|
65
65
|
"rxjs": "^7.8.1"
|