UNPKG

applesauce-wallet-connect

Version:

NIP-47 Nostr Wallet Connect implementation for both clients and services.

39 lines (38 loc) 1.66 kB
import { EventFactory, blankEventTemplate } from "applesauce-core/factories"; import { includeSingletonTag } from "applesauce-core/operations/tags"; import { setEncryptedContent } from "applesauce-core/operations/encrypted-content"; import { WALLET_NOTIFICATION_KIND, WALLET_LEGACY_NOTIFICATION_KIND, } from "../helpers/notification.js"; export class WalletNotificationFactory extends EventFactory { static create(client, notification) { return new WalletNotificationFactory((res) => res(blankEventTemplate(WALLET_NOTIFICATION_KIND))) .client(client) .notification(notification, client); } client(pubkey) { return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft)); } notification(notification, client) { let result; result = this.chain(async (draft) => { return setEncryptedContent(client, JSON.stringify(notification), result.signer)(draft); }); return result; } } export class WalletLegacyNotificationFactory extends EventFactory { static create(client, notification) { return new WalletLegacyNotificationFactory((res) => res(blankEventTemplate(WALLET_LEGACY_NOTIFICATION_KIND))) .client(client) .notification(notification, client); } client(pubkey) { return this.chain((draft) => includeSingletonTag(["p", pubkey])(draft)); } notification(notification, client) { let result; result = this.chain(async (draft) => { return setEncryptedContent(client, JSON.stringify(notification), result.signer)(draft); }); return result; } }