applesauce-wallet 0.12.0 → 1.0.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/dist/queries/history.js +12 -18
- package/dist/queries/tokens.js +29 -35
- package/dist/queries/wallet.js +13 -16
- package/package.json +7 -7
package/dist/queries/history.js
CHANGED
|
@@ -2,26 +2,20 @@ import { combineLatest, filter, map, scan, startWith } from "rxjs";
|
|
|
2
2
|
import { getHistoryRedeemed, isHistoryContentLocked, WALLET_HISTORY_KIND } from "../helpers/history.js";
|
|
3
3
|
/** Query that returns an array of redeemed event ids for a wallet */
|
|
4
4
|
export function WalletRedeemedQuery(pubkey) {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.filters({ kinds: [WALLET_HISTORY_KIND], authors: [pubkey] })
|
|
9
|
-
.pipe(scan((ids, history) => [...ids, ...getHistoryRedeemed(history)], [])),
|
|
10
|
-
};
|
|
5
|
+
return (events) => events
|
|
6
|
+
.filters({ kinds: [WALLET_HISTORY_KIND], authors: [pubkey] })
|
|
7
|
+
.pipe(scan((ids, history) => [...ids, ...getHistoryRedeemed(history)], []));
|
|
11
8
|
}
|
|
12
9
|
/** A query that returns a timeline of wallet history events */
|
|
13
10
|
export function WalletHistoryQuery(pubkey, locked) {
|
|
14
|
-
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return history.filter((entry) => isHistoryContentLocked(entry) === locked);
|
|
24
|
-
}));
|
|
25
|
-
},
|
|
11
|
+
return (events) => {
|
|
12
|
+
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_HISTORY_KIND && e.pubkey === pubkey), startWith(undefined));
|
|
13
|
+
const timeline = events.timeline({ kinds: [WALLET_HISTORY_KIND], authors: [pubkey] });
|
|
14
|
+
return combineLatest([updates, timeline]).pipe(map(([_, history]) => {
|
|
15
|
+
if (locked === undefined)
|
|
16
|
+
return history;
|
|
17
|
+
else
|
|
18
|
+
return history.filter((entry) => isHistoryContentLocked(entry) === locked);
|
|
19
|
+
}));
|
|
26
20
|
};
|
|
27
21
|
}
|
package/dist/queries/tokens.js
CHANGED
|
@@ -21,44 +21,38 @@ function filterDeleted(tokens) {
|
|
|
21
21
|
}
|
|
22
22
|
/** A query that subscribes to all token events for a wallet, passing locked will filter by token locked status */
|
|
23
23
|
export function WalletTokensQuery(pubkey, locked) {
|
|
24
|
-
return {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// remove deleted events
|
|
38
|
-
map(filterDeleted));
|
|
39
|
-
},
|
|
24
|
+
return (events) => {
|
|
25
|
+
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
|
|
26
|
+
const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
|
|
27
|
+
return combineLatest([updates, timeline]).pipe(
|
|
28
|
+
// filter out locked tokens
|
|
29
|
+
map(([_, tokens]) => {
|
|
30
|
+
if (locked === undefined)
|
|
31
|
+
return tokens;
|
|
32
|
+
else
|
|
33
|
+
return tokens.filter((t) => isTokenContentLocked(t) === locked);
|
|
34
|
+
}),
|
|
35
|
+
// remove deleted events
|
|
36
|
+
map(filterDeleted));
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
39
|
/** A query that returns the visible balance of a wallet for each mint */
|
|
43
40
|
export function WalletBalanceQuery(pubkey) {
|
|
44
|
-
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, {});
|
|
61
|
-
}));
|
|
62
|
-
},
|
|
41
|
+
return (events) => {
|
|
42
|
+
const updates = events.updates.pipe(filter((e) => e.kind === WALLET_TOKEN_KIND && e.pubkey === pubkey), startWith(undefined));
|
|
43
|
+
const timeline = events.timeline({ kinds: [WALLET_TOKEN_KIND], authors: [pubkey] });
|
|
44
|
+
return combineLatest([updates, timeline]).pipe(map(([_, tokens]) => tokens.filter((t) => !isTokenContentLocked(t))),
|
|
45
|
+
// filter out deleted tokens
|
|
46
|
+
map(filterDeleted),
|
|
47
|
+
// map tokens to totals
|
|
48
|
+
map((tokens) => {
|
|
49
|
+
// ignore duplicate proofs
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
return tokens.reduce((totals, token) => {
|
|
52
|
+
const details = getTokenContent(token);
|
|
53
|
+
const total = details.proofs.filter(ignoreDuplicateProofs(seen)).reduce((t, p) => t + p.amount, 0);
|
|
54
|
+
return { ...totals, [details.mint]: (totals[details.mint] ?? 0) + total };
|
|
55
|
+
}, {});
|
|
56
|
+
}));
|
|
63
57
|
};
|
|
64
58
|
}
|
package/dist/queries/wallet.js
CHANGED
|
@@ -2,20 +2,17 @@ import { filter, map, merge } from "rxjs";
|
|
|
2
2
|
import { getWalletMints, getWalletPrivateKey, isWalletLocked, WALLET_KIND } from "../helpers/wallet.js";
|
|
3
3
|
/** A query to get the state of a NIP-60 wallet */
|
|
4
4
|
export function WalletQuery(pubkey) {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return { locked: false, mints, privateKey, event: wallet };
|
|
19
|
-
})),
|
|
20
|
-
};
|
|
5
|
+
return (events) => merge(
|
|
6
|
+
// get the latest replaceable event
|
|
7
|
+
events.replaceable(WALLET_KIND, pubkey),
|
|
8
|
+
// and listen for any updates to matching events
|
|
9
|
+
events.updates.pipe(filter((e) => e.kind === WALLET_KIND && e.pubkey === pubkey))).pipe(map((wallet) => {
|
|
10
|
+
if (!wallet)
|
|
11
|
+
return;
|
|
12
|
+
if (isWalletLocked(wallet))
|
|
13
|
+
return { locked: true, event: wallet };
|
|
14
|
+
const mints = getWalletMints(wallet);
|
|
15
|
+
const privateKey = getWalletPrivateKey(wallet);
|
|
16
|
+
return { locked: false, mints, privateKey, event: wallet };
|
|
17
|
+
}));
|
|
21
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -80,18 +80,18 @@
|
|
|
80
80
|
"@cashu/cashu-ts": "2.0.0-rc1",
|
|
81
81
|
"@gandlaf21/bc-ur": "^1.1.12",
|
|
82
82
|
"@noble/hashes": "^1.7.1",
|
|
83
|
-
"applesauce-actions": "^0.
|
|
84
|
-
"applesauce-core": "^0.
|
|
85
|
-
"applesauce-factory": "^0.
|
|
83
|
+
"applesauce-actions": "^1.0.0",
|
|
84
|
+
"applesauce-core": "^1.0.0",
|
|
85
|
+
"applesauce-factory": "^1.0.0",
|
|
86
86
|
"nostr-tools": "^2.10.4",
|
|
87
87
|
"rxjs": "^7.8.1"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
91
91
|
"@types/debug": "^4.1.12",
|
|
92
|
-
"applesauce-signers": "^0.
|
|
93
|
-
"typescript": "^5.
|
|
94
|
-
"vitest": "^3.
|
|
92
|
+
"applesauce-signers": "^1.0.0",
|
|
93
|
+
"typescript": "^5.8.3",
|
|
94
|
+
"vitest": "^3.1.1"
|
|
95
95
|
},
|
|
96
96
|
"funding": {
|
|
97
97
|
"type": "lightning",
|