applesauce-wallet 0.0.0-next-20250310121307 → 0.0.0-next-20250310173615
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 */
|
package/dist/helpers/history.js
CHANGED
|
@@ -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[]>;
|
package/dist/queries/history.js
CHANGED
|
@@ -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
|
+
}
|
package/dist/queries/tokens.d.ts
CHANGED
|
@@ -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
|
|
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>>;
|
package/dist/queries/tokens.js
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
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
|
+
/** removes deleted events from sorted array */
|
|
4
|
+
function filterDeleted(tokens) {
|
|
5
|
+
const deleted = new Set();
|
|
6
|
+
return Array.from(tokens)
|
|
7
|
+
.reverse()
|
|
8
|
+
.filter((token) => {
|
|
9
|
+
// skip this event if it a newer event says its deleted
|
|
10
|
+
if (deleted.has(token.id))
|
|
11
|
+
return false;
|
|
12
|
+
// skip if token is locked
|
|
13
|
+
if (isTokenDetailsLocked(token))
|
|
14
|
+
return false;
|
|
15
|
+
else {
|
|
16
|
+
// add ids to deleted array
|
|
17
|
+
const details = getTokenDetails(token);
|
|
18
|
+
for (const id of details.del)
|
|
19
|
+
deleted.add(id);
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
})
|
|
23
|
+
.reverse();
|
|
24
|
+
}
|
|
3
25
|
/** A query that subscribes to all token events for a wallet, passing locked will filter by token locked status */
|
|
4
26
|
export function WalletTokensQuery(pubkey, locked) {
|
|
5
27
|
return {
|
|
6
28
|
key: pubkey + locked,
|
|
7
29
|
run: (events) => {
|
|
8
|
-
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey));
|
|
30
|
+
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
|
|
9
31
|
const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
|
|
10
|
-
return combineLatest([updates, timeline]).pipe(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
32
|
+
return combineLatest([updates, timeline]).pipe(
|
|
33
|
+
// filter out locked tokens
|
|
34
|
+
map(([_, tokens]) => {
|
|
35
|
+
if (locked === undefined)
|
|
14
36
|
return tokens;
|
|
15
|
-
|
|
37
|
+
else
|
|
38
|
+
return tokens.filter((t) => isTokenDetailsLocked(t) === locked);
|
|
39
|
+
}),
|
|
40
|
+
// remove deleted events
|
|
41
|
+
map(filterDeleted));
|
|
16
42
|
},
|
|
17
43
|
};
|
|
18
44
|
}
|
|
@@ -21,30 +47,17 @@ export function WalletBalanceQuery(pubkey) {
|
|
|
21
47
|
return {
|
|
22
48
|
key: pubkey,
|
|
23
49
|
run: (events) => {
|
|
24
|
-
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey));
|
|
50
|
+
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
|
|
25
51
|
const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
|
|
26
|
-
return combineLatest([updates, timeline]).pipe(map(([_, tokens]) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// skip if token is locked
|
|
36
|
-
if (isTokenDetailsLocked(token))
|
|
37
|
-
return totals;
|
|
38
|
-
const details = getTokenDetails(token);
|
|
39
|
-
if (!details)
|
|
40
|
-
return totals;
|
|
41
|
-
// add deleted ids
|
|
42
|
-
for (const id of details.del)
|
|
43
|
-
deleted.add(id);
|
|
44
|
-
const total = details.proofs.reduce((t, p) => t + p.amount, 0);
|
|
45
|
-
return { ...totals, [details.mint]: (totals[details.mint] ?? 0) + total };
|
|
46
|
-
}, {}));
|
|
47
|
-
}));
|
|
52
|
+
return combineLatest([updates, timeline]).pipe(map(([_, tokens]) => tokens),
|
|
53
|
+
// filter out deleted tokens
|
|
54
|
+
map(filterDeleted),
|
|
55
|
+
// map tokens to totals
|
|
56
|
+
map((tokens) => tokens.reduce((totals, token) => {
|
|
57
|
+
const details = getTokenDetails(token);
|
|
58
|
+
const total = details.proofs.reduce((t, p) => t + p.amount, 0);
|
|
59
|
+
return { ...totals, [details.mint]: (totals[details.mint] ?? 0) + total };
|
|
60
|
+
}, {})));
|
|
48
61
|
},
|
|
49
62
|
};
|
|
50
63
|
}
|
package/dist/queries/wallet.js
CHANGED
|
@@ -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.
|
|
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-
|
|
3
|
+
"version": "0.0.0-next-20250310173615",
|
|
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-
|
|
45
|
+
"applesauce-core": "0.0.0-next-20250310173615",
|
|
46
46
|
"nostr-tools": "^2.10.4",
|
|
47
47
|
"rxjs": "^7.8.1"
|
|
48
48
|
},
|