applesauce-wallet-connect
Version:
NIP-47 Nostr Wallet Connect implementation for both clients and services.
29 lines (28 loc) • 1.42 kB
JavaScript
import { getHiddenContent, getOrComputeCachedValue, isHiddenContentLocked, setHiddenContentEncryptionMethod, unlockHiddenContent, } from "applesauce-core/helpers";
export const WALLET_NOTIFICATION_KIND = 23197;
export const WALLET_LEGACY_NOTIFICATION_KIND = 23196;
/** A symbol used to cache the wallet notification on the event */
export const WalletNotificationSymbol = Symbol("wallet-notification");
// Setup the encryption method to use for notification kinds
setHiddenContentEncryptionMethod(WALLET_NOTIFICATION_KIND, "nip44");
setHiddenContentEncryptionMethod(WALLET_LEGACY_NOTIFICATION_KIND, "nip04");
/** Checks if a kind 23196 or 23197 event is locked */
export function isWalletNotificationLocked(notification) {
return isHiddenContentLocked(notification);
}
/** Unlocks a kind 23196 or 23197 event */
export async function unlockWalletNotification(notification, signer) {
await unlockHiddenContent(notification, signer);
return getWalletNotification(notification);
}
/** Gets the wallet notification from a kind 23196 or 23197 event */
export function getWalletNotification(notification) {
if (isWalletNotificationLocked(notification))
return undefined;
return getOrComputeCachedValue(notification, WalletNotificationSymbol, () => {
const content = getHiddenContent(notification);
if (!content)
return null;
return JSON.parse(content);
});
}