applesauce-wallet 0.0.0-next-20250310121307 → 0.0.0-next-20250310162525

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.
@@ -12,6 +12,8 @@ export type HistoryDetails = {
12
12
  export declare const HistoryDetailsSymbol: unique symbol;
13
13
  /** returns an array of redeemed event ids in a history event */
14
14
  export declare function getHistoryRedeemed(history: NostrEvent): string[];
15
+ /** Checks if the history details are locked */
16
+ export declare function isHistoryDetailsLocked(history: NostrEvent): boolean;
15
17
  /** Returns the parsed details of a 7376 history event */
16
18
  export declare function getHistoryDetails(history: NostrEvent): HistoryDetails;
17
19
  /** Decrypts a wallet history event */
@@ -1,10 +1,14 @@
1
- import { getHiddenTags, getOrComputeCachedValue, isETag, unlockHiddenTags, } from "applesauce-core/helpers";
1
+ import { getHiddenTags, getOrComputeCachedValue, isETag, isHiddenTagsLocked, unlockHiddenTags, } from "applesauce-core/helpers";
2
2
  export const WALLET_HISTORY_KIND = 7376;
3
3
  export const HistoryDetailsSymbol = Symbol.for("history-details");
4
4
  /** returns an array of redeemed event ids in a history event */
5
5
  export function getHistoryRedeemed(history) {
6
6
  return history.tags.filter((t) => isETag(t) && t[3] === "redeemed").map((t) => t[1]);
7
7
  }
8
+ /** Checks if the history details are locked */
9
+ export function isHistoryDetailsLocked(history) {
10
+ return isHiddenTagsLocked(history);
11
+ }
8
12
  /** Returns the parsed details of a 7376 history event */
9
13
  export function getHistoryDetails(history) {
10
14
  return getOrComputeCachedValue(history, HistoryDetailsSymbol, () => {
@@ -1,3 +1,6 @@
1
1
  import { Query } from "applesauce-core";
2
+ import { NostrEvent } from "nostr-tools";
2
3
  /** Query that returns an array of redeemed event ids for a wallet */
3
4
  export declare function WalletRedeemedQuery(pubkey: string): Query<string[]>;
5
+ /** A query that returns a timeline of wallet history events */
6
+ export declare function WalletHistoryQuery(pubkey: string, locked?: boolean | undefined): Query<NostrEvent[]>;
@@ -1,5 +1,5 @@
1
- import { getHistoryRedeemed, WALLET_HISTORY_KIND } from "../helpers/history.js";
2
- import { scan } from "rxjs";
1
+ import { getHistoryRedeemed, isHistoryDetailsLocked, WALLET_HISTORY_KIND } from "../helpers/history.js";
2
+ import { combineLatest, filter, map, scan, startWith } from "rxjs";
3
3
  /** Query that returns an array of redeemed event ids for a wallet */
4
4
  export function WalletRedeemedQuery(pubkey) {
5
5
  return {
@@ -9,3 +9,19 @@ export function WalletRedeemedQuery(pubkey) {
9
9
  .pipe(scan((ids, history) => [...ids, ...getHistoryRedeemed(history)], [])),
10
10
  };
11
11
  }
12
+ /** A query that returns a timeline of wallet history events */
13
+ export function WalletHistoryQuery(pubkey, locked) {
14
+ return {
15
+ key: pubkey,
16
+ run: (events) => {
17
+ const updates = events.updates.pipe(filter((e) => e.kind === WALLET_HISTORY_KIND && e.pubkey === pubkey), startWith(undefined));
18
+ const timeline = events.timeline({ kinds: [WALLET_HISTORY_KIND], authors: [pubkey] });
19
+ return combineLatest([updates, timeline]).pipe(map(([_, history]) => {
20
+ if (locked === undefined)
21
+ return history;
22
+ else
23
+ return history.filter((entry) => isHistoryDetailsLocked(entry) === locked);
24
+ }));
25
+ },
26
+ };
27
+ }
@@ -1,6 +1,6 @@
1
1
  import { Query } from "applesauce-core";
2
2
  import { NostrEvent } from "nostr-tools";
3
3
  /** A query that subscribes to all token events for a wallet, passing locked will filter by token locked status */
4
- export declare function WalletTokensQuery(pubkey: string, locked: boolean | undefined): Query<NostrEvent[]>;
4
+ export declare function WalletTokensQuery(pubkey: string, locked?: boolean | undefined): Query<NostrEvent[]>;
5
5
  /** A query that returns the visible balance of a wallet for each mint */
6
6
  export declare function WalletBalanceQuery(pubkey: string): Query<Record<string, number>>;
@@ -1,17 +1,17 @@
1
- import { combineLatest, filter, map } from "rxjs";
1
+ import { combineLatest, filter, map, startWith } from "rxjs";
2
2
  import { getTokenDetails, isTokenDetailsLocked, WALLET_TOKEN_KIND } from "../helpers/tokens.js";
3
3
  /** A query that subscribes to all token events for a wallet, passing locked will filter by token locked status */
4
4
  export function WalletTokensQuery(pubkey, locked) {
5
5
  return {
6
6
  key: pubkey + locked,
7
7
  run: (events) => {
8
- const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey));
8
+ const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
9
9
  const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
10
10
  return combineLatest([updates, timeline]).pipe(map(([_, tokens]) => {
11
- if (locked !== undefined)
12
- return tokens.filter((t) => isTokenDetailsLocked(t) === locked);
13
- else
11
+ if (locked === undefined)
14
12
  return tokens;
13
+ else
14
+ return tokens.filter((t) => isTokenDetailsLocked(t) === locked);
15
15
  }));
16
16
  },
17
17
  };
@@ -21,7 +21,7 @@ export function WalletBalanceQuery(pubkey) {
21
21
  return {
22
22
  key: pubkey,
23
23
  run: (events) => {
24
- const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey));
24
+ const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
25
25
  const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
26
26
  return combineLatest([updates, timeline]).pipe(map(([_, tokens]) => {
27
27
  const deleted = new Set();
@@ -8,7 +8,7 @@ export function WalletQuery(pubkey) {
8
8
  // get the latest replaceable event
9
9
  events.replaceable(WALLET_KIND, pubkey),
10
10
  // and listen for any updates to matching events
11
- events.database.updated.pipe(filter((e) => e.kind === WALLET_KIND && e.pubkey === pubkey))).pipe(map((wallet) => {
11
+ events.updates.pipe(filter((e) => e.kind === WALLET_KIND && e.pubkey === pubkey))).pipe(map((wallet) => {
12
12
  if (!wallet)
13
13
  return;
14
14
  if (isWalletLocked(wallet))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20250310121307",
3
+ "version": "0.0.0-next-20250310162525",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,7 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "applesauce-core": "0.0.0-next-20250310121307",
45
+ "applesauce-core": "0.0.0-next-20250310162525",
46
46
  "nostr-tools": "^2.10.4",
47
47
  "rxjs": "^7.8.1"
48
48
  },