applesauce-wallet-connect 5.0.1 → 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/README.md CHANGED
@@ -109,4 +109,4 @@ Both WalletConnect and WalletService support all NIP-47 methods:
109
109
 
110
110
  ## Documentation
111
111
 
112
- For more detailed documentation, visit [the docs](https://hzrd149.github.io/applesauce/).
112
+ For more detailed documentation, visit [the docs](https://applesauce.build/).
@@ -0,0 +1,15 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { WALLET_NOTIFICATION_KIND, WALLET_LEGACY_NOTIFICATION_KIND, WalletNotification } from "../helpers/notification.js";
4
+ export type WalletNotificationTemplate = KnownEventTemplate<typeof WALLET_NOTIFICATION_KIND>;
5
+ export type WalletLegacyNotificationTemplate = KnownEventTemplate<typeof WALLET_LEGACY_NOTIFICATION_KIND>;
6
+ export declare class WalletNotificationFactory extends EventFactory<typeof WALLET_NOTIFICATION_KIND, WalletNotificationTemplate> {
7
+ static create(client: string, notification: WalletNotification): WalletNotificationFactory;
8
+ client(pubkey: string): this;
9
+ notification(notification: WalletNotification, client: string): this;
10
+ }
11
+ export declare class WalletLegacyNotificationFactory extends EventFactory<typeof WALLET_LEGACY_NOTIFICATION_KIND, WalletLegacyNotificationTemplate> {
12
+ static create(client: string, notification: WalletNotification): WalletLegacyNotificationFactory;
13
+ client(pubkey: string): this;
14
+ notification(notification: WalletNotification, client: string): this;
15
+ }
@@ -0,0 +1,38 @@
1
+ import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
+ import { WALLET_NOTIFICATION_KIND, WALLET_LEGACY_NOTIFICATION_KIND, } from "../helpers/notification.js";
5
+ export class WalletNotificationFactory extends EventFactory {
6
+ static create(client, notification) {
7
+ return new WalletNotificationFactory((res) => res(blankEventTemplate(WALLET_NOTIFICATION_KIND)))
8
+ .client(client)
9
+ .notification(notification, client);
10
+ }
11
+ client(pubkey) {
12
+ return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft));
13
+ }
14
+ notification(notification, client) {
15
+ let result;
16
+ result = this.chain(async (draft) => {
17
+ return setEncryptedContent(client, JSON.stringify(notification), result.signer)(draft);
18
+ });
19
+ return result;
20
+ }
21
+ }
22
+ export class WalletLegacyNotificationFactory extends EventFactory {
23
+ static create(client, notification) {
24
+ return new WalletLegacyNotificationFactory((res) => res(blankEventTemplate(WALLET_LEGACY_NOTIFICATION_KIND)))
25
+ .client(client)
26
+ .notification(notification, client);
27
+ }
28
+ client(pubkey) {
29
+ return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft));
30
+ }
31
+ notification(notification, client) {
32
+ let result;
33
+ result = this.chain(async (draft) => {
34
+ return setEncryptedContent(client, JSON.stringify(notification), result.signer)(draft);
35
+ });
36
+ return result;
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { WALLET_REQUEST_KIND } from "../helpers/request.js";
4
+ import { WalletConnectEncryptionMethod } from "../helpers/encryption.js";
5
+ import { TWalletMethod } from "../helpers/methods.js";
6
+ export type WalletRequestTemplate = KnownEventTemplate<typeof WALLET_REQUEST_KIND>;
7
+ export declare class WalletRequestFactory extends EventFactory<typeof WALLET_REQUEST_KIND, WalletRequestTemplate> {
8
+ static create<Method extends TWalletMethod>(service: string, request: Method["request"], encryption?: WalletConnectEncryptionMethod): WalletRequestFactory;
9
+ service(pubkey: string): this;
10
+ request<T>(request: T, encryption?: WalletConnectEncryptionMethod): this;
11
+ }
@@ -0,0 +1,22 @@
1
+ import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
+ import { WALLET_REQUEST_KIND } from "../helpers/request.js";
5
+ export class WalletRequestFactory extends EventFactory {
6
+ static create(service, request, encryption = "nip44_v2") {
7
+ return new WalletRequestFactory((res) => res(blankEventTemplate(WALLET_REQUEST_KIND)))
8
+ .service(service)
9
+ .request(request, encryption);
10
+ }
11
+ service(pubkey) {
12
+ return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft));
13
+ }
14
+ request(request, encryption = "nip44_v2") {
15
+ let result;
16
+ result = this.chain(async (draft) => {
17
+ const encrypted = await setEncryptedContent(draft.tags.find((t) => t[0] === "p")?.[1] || "", JSON.stringify(request), result.signer, encryption === "nip44_v2" ? "nip44" : "nip04")(draft);
18
+ return includeSingletonTag(["encryption", encryption])(encrypted);
19
+ });
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,11 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
+ import { TWalletMethod } from "../helpers/methods.js";
4
+ import { WALLET_RESPONSE_KIND } from "../helpers/response.js";
5
+ export type WalletResponseTemplate = KnownEventTemplate<typeof WALLET_RESPONSE_KIND>;
6
+ export declare class WalletResponseFactory extends EventFactory<typeof WALLET_RESPONSE_KIND, WalletResponseTemplate> {
7
+ static create<Method extends TWalletMethod>(request: NostrEvent, response: Method["response"] | Method["error"]): WalletResponseFactory;
8
+ requestEvent(eventId: string): this;
9
+ client(pubkey: string): this;
10
+ response<T>(response: T, recipient: string, encryption?: "nip44" | "nip04"): this;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
+ import { getWalletRequestEncryption } from "../helpers/request.js";
5
+ import { WALLET_RESPONSE_KIND } from "../helpers/response.js";
6
+ export class WalletResponseFactory extends EventFactory {
7
+ static create(request, response) {
8
+ const encryption = getWalletRequestEncryption(request);
9
+ return new WalletResponseFactory((res) => res(blankEventTemplate(WALLET_RESPONSE_KIND)))
10
+ .requestEvent(request.id)
11
+ .client(request.pubkey)
12
+ .response(response, request.pubkey, encryption === "nip44_v2" ? "nip44" : "nip04");
13
+ }
14
+ requestEvent(eventId) {
15
+ return this.chain((draft) => includeSingletonTag(["e", eventId])(draft));
16
+ }
17
+ client(pubkey) {
18
+ return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft));
19
+ }
20
+ response(response, recipient, encryption = "nip44") {
21
+ let result;
22
+ result = this.chain(async (draft) => {
23
+ return setEncryptedContent(recipient, JSON.stringify(response), result.signer, encryption)(draft);
24
+ });
25
+ return result;
26
+ }
27
+ }
@@ -0,0 +1,12 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { WALLET_INFO_KIND, WalletSupport } from "../helpers/support.js";
4
+ import { TWalletMethod } from "../helpers/methods.js";
5
+ export type WalletInfoTemplate = KnownEventTemplate<typeof WALLET_INFO_KIND>;
6
+ export declare class WalletInfoFactory extends EventFactory<typeof WALLET_INFO_KIND, WalletInfoTemplate> {
7
+ static create<Methods extends TWalletMethod>(info: WalletSupport<Methods>, client?: string, overrideRelay?: string): WalletInfoFactory;
8
+ methods(methods: string[]): this;
9
+ encryption(methods: string[]): this;
10
+ notifications(types: string[]): this;
11
+ client(pubkey: string, relay?: string): this;
12
+ }
@@ -0,0 +1,28 @@
1
+ import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { setContent } from "applesauce-core/operations/content";
4
+ import { WALLET_INFO_KIND } from "../helpers/support.js";
5
+ export class WalletInfoFactory extends EventFactory {
6
+ static create(info, client, overrideRelay) {
7
+ const factory = new WalletInfoFactory((res) => res(blankEventTemplate(WALLET_INFO_KIND))).methods(info.methods);
8
+ if (info.encryption)
9
+ factory.encryption(info.encryption);
10
+ if (info.notifications)
11
+ factory.notifications(info.notifications);
12
+ if (client)
13
+ factory.client(client, overrideRelay);
14
+ return factory;
15
+ }
16
+ methods(methods) {
17
+ return this.chain((draft) => setContent(methods.join(" "))(draft));
18
+ }
19
+ encryption(methods) {
20
+ return this.chain((draft) => includeSingletonTag(["encryption", methods.join(" ")])(draft));
21
+ }
22
+ notifications(types) {
23
+ return this.chain((draft) => includeSingletonTag(["notifications", types.join(" ")])(draft));
24
+ }
25
+ client(pubkey, relay) {
26
+ return this.chain((draft) => includeSingletonTag(relay ? ["p", pubkey, relay] : ["p", pubkey])(draft));
27
+ }
28
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * as Blueprints from "./blueprints/index.js";
1
+ export * as Factories from "./factories/index.js";
2
2
  export * as Helpers from "./helpers/index.js";
3
3
  export * from "./wallet-connect.js";
4
4
  export * from "./wallet-service.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * as Blueprints from "./blueprints/index.js";
1
+ export * as Factories from "./factories/index.js";
2
2
  export * as Helpers from "./helpers/index.js";
3
3
  export * from "./wallet-connect.js";
4
4
  export * from "./wallet-service.js";
@@ -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;
@@ -40,6 +45,8 @@ export declare class WalletConnect<Methods extends TWalletMethod = CommonWalletM
40
45
  /** The wallet service public key ( unset if waiting for service ) */
41
46
  service$: BehaviorSubject<string | undefined>;
42
47
  get service(): string | undefined;
48
+ /** The wallet connect URI for this connection, or undefined if the service pubkey is not yet known */
49
+ get connectURI(): string | undefined;
43
50
  /** Default timeout for requests */
44
51
  defaultTimeout: number;
45
52
  /** Observable for wallet info updates */
@@ -126,6 +133,8 @@ export declare class WalletConnect<Methods extends TWalletMethod = CommonWalletM
126
133
  }>): Promise<MultiPayKeysendMethod["response"]["result"][]>;
127
134
  /** Create a new invoice */
128
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>;
129
138
  /** Look up an invoice by payment hash or invoice string */
130
139
  lookupInvoice(payment_hash?: string, invoice?: string): Promise<LookupInvoiceMethod["response"]["result"]>;
131
140
  /** List transactions */
@@ -1,12 +1,11 @@
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
- import { createEvent } from "applesauce-core";
4
3
  import { finalizeEvent, getPublicKey, verifyEvent } from "applesauce-core/helpers";
5
4
  import { nip04, nip44 } from "applesauce-core/helpers/encryption";
6
- 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";
7
- import { WalletRequestBlueprint } from "./blueprints/index.js";
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
+ import { WalletRequestFactory } from "./factories/index.js";
8
7
  import { createWalletError } from "./helpers/error.js";
9
- import { createWalletAuthURI, 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";
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";
10
9
  import { getConnectionMethods, } from "./interop.js";
11
10
  export class WalletConnect {
12
11
  /** A fallback method to use for subscriptionMethod if none is passed in when creating the client */
@@ -34,6 +33,12 @@ export class WalletConnect {
34
33
  get service() {
35
34
  return this.service$.value;
36
35
  }
36
+ /** The wallet connect URI for this connection, or undefined if the service pubkey is not yet known */
37
+ get connectURI() {
38
+ if (!this.service)
39
+ return undefined;
40
+ return createWalletConnectURI({ service: this.service, relays: this.relays, secret: bytesToHex(this.secret) });
41
+ }
37
42
  /** Default timeout for requests */
38
43
  defaultTimeout;
39
44
  /** Observable for wallet info updates */
@@ -166,10 +171,8 @@ export class WalletConnect {
166
171
  return defer(async () => {
167
172
  // Get the preferred encryption method for the wallet
168
173
  const encryption = await firstValueFrom(this.encryption$);
169
- // Create the request event
170
- const draft = await createEvent({ signer: this.signer }, WalletRequestBlueprint, this.service, { method, params }, encryption);
171
- // Sign the request event
172
- return await this.signer.signEvent(draft);
174
+ // Create and sign the request event
175
+ return await WalletRequestFactory.create(this.service, { method, params }, encryption).as(this.signer).sign();
173
176
  }).pipe(
174
177
  // Then switch to the request observable
175
178
  switchMap((requestEvent) => {
@@ -277,6 +280,47 @@ export class WalletConnect {
277
280
  async makeInvoice(amount, options) {
278
281
  return await this.genericRequest("make_invoice", { amount, ...options });
279
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
+ }
280
324
  /** Look up an invoice by payment hash or invoice string */
281
325
  async lookupInvoice(payment_hash, invoice) {
282
326
  return await this.genericRequest("lookup_invoice", { payment_hash, invoice });
@@ -1,4 +1,4 @@
1
- import { EventSigner } from "applesauce-core/event-factory";
1
+ import { EventSigner } from "applesauce-core";
2
2
  import { Observable, Subscription } from "rxjs";
3
3
  import { WalletAuthURI } from "./helpers/auth-uri.js";
4
4
  import { WalletErrorCode } from "./helpers/error.js";
@@ -1,12 +1,11 @@
1
1
  import { logger } from "applesauce-core";
2
- import { createEvent } from "applesauce-core/event-factory";
3
2
  import { verifyEvent } from "applesauce-core/helpers/event";
4
3
  import { generateSecretKey, getPublicKey } from "applesauce-core/helpers/keys";
5
4
  import { filter, from, mergeMap, repeat, retry, share, tap } from "rxjs";
6
- import { bytesToHex } from "@noble/hashes/utils";
7
- import { WalletLegacyNotificationBlueprint, WalletNotificationBlueprint } from "./blueprints/notification.js";
8
- import { WalletResponseBlueprint } from "./blueprints/response.js";
9
- import { WalletSupportBlueprint } from "./blueprints/support.js";
5
+ import { bytesToHex } from "@noble/hashes/utils.js";
6
+ import { WalletLegacyNotificationFactory, WalletNotificationFactory } from "./factories/notification.js";
7
+ import { WalletResponseFactory } from "./factories/response.js";
8
+ import { WalletInfoFactory } from "./factories/support.js";
10
9
  import { parseWalletAuthURI } from "./helpers/auth-uri.js";
11
10
  import { NotImplementedError, WalletBaseError } from "./helpers/error.js";
12
11
  import { getWalletRequest, isValidWalletRequest, isWalletRequestExpired, unlockWalletRequest, WALLET_REQUEST_KIND, } from "./helpers/request.js";
@@ -155,11 +154,13 @@ export class WalletService {
155
154
  }
156
155
  /** Send a notification to the client */
157
156
  async notify(type, notification, legacy = false) {
158
- const draft = await createEvent({ signer: this.signer }, legacy ? WalletLegacyNotificationBlueprint : WalletNotificationBlueprint, this.client, {
157
+ const NotificationFactory = legacy ? WalletLegacyNotificationFactory : WalletNotificationFactory;
158
+ const event = await NotificationFactory.create(this.client, {
159
159
  notification_type: type,
160
160
  notification,
161
- });
162
- const event = await this.signer.signEvent(draft);
161
+ })
162
+ .as(this.signer)
163
+ .sign();
163
164
  await this.publishMethod(this.relays, event);
164
165
  }
165
166
  /** Publish the wallet support event */
@@ -167,8 +168,9 @@ export class WalletService {
167
168
  try {
168
169
  // Tell the client which relay to use if there is only one (for nostr+walletauth URI connections)
169
170
  const overrideRelay = this.relays.length === 1 ? this.relays[0] : undefined;
170
- const draft = await createEvent({ signer: this.signer }, (WalletSupportBlueprint), this.support, this.client, overrideRelay);
171
- const event = await this.signer.signEvent(draft);
171
+ const event = await WalletInfoFactory.create(this.support, this.client, overrideRelay)
172
+ .as(this.signer)
173
+ .sign();
172
174
  await this.publishMethod(this.relays, event);
173
175
  }
174
176
  catch (error) {
@@ -261,8 +263,7 @@ export class WalletService {
261
263
  /** Send a response event */
262
264
  async sendResponse(requestEvent, response) {
263
265
  try {
264
- const draft = await createEvent({ signer: this.signer }, WalletResponseBlueprint(requestEvent, response));
265
- const event = await this.signer.signEvent(draft);
266
+ const event = await WalletResponseFactory.create(requestEvent, response).as(this.signer).sign();
266
267
  await this.publishMethod(this.relays, event);
267
268
  }
268
269
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet-connect",
3
- "version": "5.0.1",
3
+ "version": "6.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,27 +46,27 @@
46
46
  "require": "./dist/helpers/*.js",
47
47
  "types": "./dist/helpers/*.d.ts"
48
48
  },
49
- "./blueprints": {
50
- "import": "./dist/blueprints/index.js",
51
- "require": "./dist/blueprints/index.js",
52
- "types": "./dist/blueprints/index.d.ts"
49
+ "./factories": {
50
+ "import": "./dist/factories/index.js",
51
+ "require": "./dist/factories/index.js",
52
+ "types": "./dist/factories/index.d.ts"
53
53
  },
54
- "./blueprints/*": {
55
- "import": "./dist/blueprints/*.js",
56
- "require": "./dist/blueprints/*.js",
57
- "types": "./dist/blueprints/*.d.ts"
54
+ "./factories/*": {
55
+ "import": "./dist/factories/*.js",
56
+ "require": "./dist/factories/*.js",
57
+ "types": "./dist/factories/*.d.ts"
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
- "@noble/hashes": "^1.7.1",
62
- "applesauce-common": "^5.0.0",
63
- "applesauce-core": "^5.0.0",
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": "^5.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"
@@ -1,15 +0,0 @@
1
- import { EventBlueprint } from "applesauce-core/event-factory";
2
- import { WalletNotification } from "../helpers/notification.js";
3
- /**
4
- * Creates a wallet notification event (kind 23197)
5
- * @param client - The service pubkey
6
- * @param notification - The notification to create an event for
7
- * @param encryption - The encryption method to use (defaults to nip44_v2)
8
- */
9
- export declare function WalletNotificationBlueprint(client: string, notification: WalletNotification): EventBlueprint;
10
- /**
11
- * Creates a legacy wallet notification event (kind 23196)
12
- * @param client - The service pubkey
13
- * @param notification - The notification to create an event for
14
- */
15
- export declare function WalletLegacyNotificationBlueprint(client: string, notification: WalletNotification): EventBlueprint;
@@ -1,21 +0,0 @@
1
- import { blueprint } from "applesauce-core/event-factory";
2
- import { includeSingletonTag } from "applesauce-core/operations/tags";
3
- import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
- import { WALLET_NOTIFICATION_KIND, WALLET_LEGACY_NOTIFICATION_KIND, } from "../helpers/notification.js";
5
- /**
6
- * Creates a wallet notification event (kind 23197)
7
- * @param client - The service pubkey
8
- * @param notification - The notification to create an event for
9
- * @param encryption - The encryption method to use (defaults to nip44_v2)
10
- */
11
- export function WalletNotificationBlueprint(client, notification) {
12
- return blueprint(WALLET_NOTIFICATION_KIND, setEncryptedContent(client, JSON.stringify(notification)), includeSingletonTag(["p", client]));
13
- }
14
- /**
15
- * Creates a legacy wallet notification event (kind 23196)
16
- * @param client - The service pubkey
17
- * @param notification - The notification to create an event for
18
- */
19
- export function WalletLegacyNotificationBlueprint(client, notification) {
20
- return blueprint(WALLET_LEGACY_NOTIFICATION_KIND, setEncryptedContent(client, JSON.stringify(notification)), includeSingletonTag(["p", client]));
21
- }
@@ -1,9 +0,0 @@
1
- import { EventBlueprint } from "applesauce-core";
2
- import { WalletConnectEncryptionMethod } from "../helpers/encryption.js";
3
- import { TWalletMethod } from "../helpers/methods.js";
4
- /**
5
- * Creates a walelt request event
6
- * @param service - The service pubkey
7
- * @param request - The request to create an event for
8
- */
9
- export declare function WalletRequestBlueprint<Method extends TWalletMethod>(service: string, request: Method["request"], encryption?: WalletConnectEncryptionMethod): EventBlueprint;
@@ -1,12 +0,0 @@
1
- import { blueprint } from "applesauce-core";
2
- import { includeSingletonTag } from "applesauce-core/operations/tags";
3
- import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
- import { WALLET_REQUEST_KIND } from "../helpers/request.js";
5
- /**
6
- * Creates a walelt request event
7
- * @param service - The service pubkey
8
- * @param request - The request to create an event for
9
- */
10
- export function WalletRequestBlueprint(service, request, encryption = "nip44_v2") {
11
- return blueprint(WALLET_REQUEST_KIND, setEncryptedContent(service, JSON.stringify(request), encryption === "nip44_v2" ? "nip44" : "nip04"), includeSingletonTag(["p", service]), includeSingletonTag(["encryption", encryption]));
12
- }
@@ -1,5 +0,0 @@
1
- import { EventBlueprint } from "applesauce-core";
2
- import { NostrEvent } from "applesauce-core/helpers/event";
3
- import { TWalletMethod } from "../helpers/methods.js";
4
- /** Creates a wallet response event */
5
- export declare function WalletResponseBlueprint<Method extends TWalletMethod>(request: NostrEvent, response: Method["response"] | Method["error"]): EventBlueprint;
@@ -1,10 +0,0 @@
1
- import { blueprint } from "applesauce-core";
2
- import { includeSingletonTag } from "applesauce-core/operations/tags";
3
- import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
- import { getWalletRequestEncryption } from "../helpers/request.js";
5
- import { WALLET_RESPONSE_KIND } from "../helpers/response.js";
6
- /** Creates a wallet response event */
7
- export function WalletResponseBlueprint(request, response) {
8
- const encryption = getWalletRequestEncryption(request);
9
- return blueprint(WALLET_RESPONSE_KIND, setEncryptedContent(request.pubkey, JSON.stringify(response), encryption === "nip44_v2" ? "nip44" : "nip04"), includeSingletonTag(["e", request.id]), includeSingletonTag(["p", request.pubkey]));
10
- }
@@ -1,10 +0,0 @@
1
- import { EventBlueprint } from "applesauce-core";
2
- import { WalletSupport } from "../helpers/support.js";
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;
@@ -1,15 +0,0 @@
1
- import { blueprint } from "applesauce-core";
2
- import { setContent } from "applesauce-core/operations/content";
3
- import { includeSingletonTag } from "applesauce-core/operations/tags";
4
- import { WALLET_INFO_KIND } from "../helpers/support.js";
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) {
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,
13
- // An optional client pubkey to notify the service is created (used for nostr+walletauth URI connections)
14
- client ? includeSingletonTag(overrideRelay ? ["p", client, overrideRelay] : ["p", client]) : undefined);
15
- }
@@ -1,4 +1,4 @@
1
- export * from "./support.js";
2
1
  export * from "./request.js";
3
2
  export * from "./response.js";
4
3
  export * from "./notification.js";
4
+ export * from "./support.js";
@@ -1,4 +1,4 @@
1
- export * from "./support.js";
2
1
  export * from "./request.js";
3
2
  export * from "./response.js";
4
3
  export * from "./notification.js";
4
+ export * from "./support.js";