applesauce-wallet 0.0.0-next-20250723224513 → 0.0.0-next-20250726160247
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/actions/zap-info.js +2 -2
- package/dist/blueprints/history.js +1 -1
- package/dist/blueprints/tokens.js +2 -2
- package/dist/blueprints/wallet.js +3 -5
- package/dist/blueprints/zaps.js +4 -4
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/{zaps.d.ts → nutzap.d.ts} +1 -0
- package/dist/helpers/{zaps.js → nutzap.js} +7 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/{zaps.js → nutzap.js} +1 -1
- package/dist/operations/{event/history.d.ts → history.d.ts} +2 -2
- package/dist/operations/history.js +34 -0
- package/dist/operations/index.d.ts +5 -2
- package/dist/operations/index.js +5 -2
- package/dist/operations/{event/zaps.d.ts → nutzap.d.ts} +5 -5
- package/dist/operations/{event/zaps.js → nutzap.js} +8 -7
- package/dist/operations/{event/tokens.d.ts → tokens.d.ts} +1 -1
- package/dist/operations/{event/tokens.js → tokens.js} +2 -2
- package/dist/operations/wallet.d.ts +8 -0
- package/dist/operations/wallet.js +30 -0
- package/dist/operations/{event/zap-info.js → zap-info.js} +1 -1
- package/package.json +5 -5
- package/dist/__tests__/exports.test.d.ts +0 -1
- package/dist/__tests__/exports.test.js +0 -16
- package/dist/__tests__/fake-user.d.ts +0 -10
- package/dist/__tests__/fake-user.js +0 -31
- package/dist/actions/__tests__/exports.test.d.ts +0 -1
- package/dist/actions/__tests__/exports.test.js +0 -17
- package/dist/actions/__tests__/tokens.test.d.ts +0 -1
- package/dist/actions/__tests__/tokens.test.js +0 -139
- package/dist/actions/__tests__/wallet.test.d.ts +0 -1
- package/dist/actions/__tests__/wallet.test.js +0 -56
- package/dist/blueprints/__tests__/exports.test.d.ts +0 -1
- package/dist/blueprints/__tests__/exports.test.js +0 -13
- package/dist/helpers/__tests__/animated-qr.test.d.ts +0 -1
- package/dist/helpers/__tests__/animated-qr.test.js +0 -44
- package/dist/helpers/__tests__/exports.test.d.ts +0 -1
- package/dist/helpers/__tests__/exports.test.js +0 -42
- package/dist/helpers/__tests__/tokens.test.d.ts +0 -1
- package/dist/helpers/__tests__/tokens.test.js +0 -127
- package/dist/models/__tests__/exports.test.d.ts +0 -1
- package/dist/models/__tests__/exports.test.js +0 -15
- package/dist/models/__tests__/wallet.test.d.ts +0 -1
- package/dist/models/__tests__/wallet.test.js +0 -28
- package/dist/operations/__tests__/exports.test.d.ts +0 -1
- package/dist/operations/__tests__/exports.test.js +0 -12
- package/dist/operations/event/__tests__/exports.test.d.ts +0 -1
- package/dist/operations/event/__tests__/exports.test.js +0 -14
- package/dist/operations/event/__tests__/wallet.test.d.ts +0 -1
- package/dist/operations/event/__tests__/wallet.test.js +0 -25
- package/dist/operations/event/history.js +0 -19
- package/dist/operations/event/index.d.ts +0 -5
- package/dist/operations/event/index.js +0 -5
- package/dist/operations/event/wallet.d.ts +0 -4
- package/dist/operations/event/wallet.js +0 -14
- package/dist/operations/tag/__tests__/exports.test.d.ts +0 -1
- package/dist/operations/tag/__tests__/exports.test.js +0 -18
- package/dist/operations/tag/__tests__/wallet.test.d.ts +0 -1
- package/dist/operations/tag/__tests__/wallet.test.js +0 -16
- package/dist/operations/tag/history.d.ts +0 -14
- package/dist/operations/tag/history.js +0 -34
- package/dist/operations/tag/index.d.ts +0 -2
- package/dist/operations/tag/index.js +0 -2
- package/dist/operations/tag/wallet.d.ts +0 -5
- package/dist/operations/tag/wallet.js +0 -15
- package/dist/queries/__tests__/exports.test.d.ts +0 -1
- package/dist/queries/__tests__/exports.test.js +0 -15
- package/dist/queries/__tests__/wallet.test.d.ts +0 -1
- package/dist/queries/__tests__/wallet.test.js +0 -30
- package/dist/queries/history.d.ts +0 -6
- package/dist/queries/history.js +0 -21
- package/dist/queries/index.d.ts +0 -3
- package/dist/queries/index.js +0 -3
- package/dist/queries/tokens.d.ts +0 -6
- package/dist/queries/tokens.js +0 -58
- package/dist/queries/wallet.d.ts +0 -13
- package/dist/queries/wallet.js +0 -18
- /package/dist/models/{zaps.d.ts → nutzap.d.ts} +0 -0
- /package/dist/operations/{event/zap-info.d.ts → zap-info.d.ts} +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { EventStore, QueryStore } from "applesauce-core";
|
|
2
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
|
-
import { EventFactory } from "applesauce-factory";
|
|
4
|
-
import { generateSecretKey } from "nostr-tools";
|
|
5
|
-
import { subscribeSpyTo } from "@hirez_io/observer-spy";
|
|
6
|
-
import { FakeUser } from "../../__tests__/fake-user.js";
|
|
7
|
-
import { WalletBlueprint } from "../../blueprints/wallet.js";
|
|
8
|
-
import { WalletQuery } from "../wallet.js";
|
|
9
|
-
import { lockWallet, unlockWallet } from "../../helpers/wallet.js";
|
|
10
|
-
const user = new FakeUser();
|
|
11
|
-
const factory = new EventFactory({ signer: user });
|
|
12
|
-
let events;
|
|
13
|
-
let queries;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
events = new EventStore();
|
|
16
|
-
queries = new QueryStore(events);
|
|
17
|
-
});
|
|
18
|
-
describe("WalletQuery", () => {
|
|
19
|
-
it("it should update when event is unlocked", async () => {
|
|
20
|
-
const wallet = await user.signEvent(await factory.create(WalletBlueprint, [], generateSecretKey()));
|
|
21
|
-
lockWallet(wallet);
|
|
22
|
-
events.add(wallet);
|
|
23
|
-
const spy = subscribeSpyTo(queries.createQuery(WalletQuery, await user.getPublicKey()));
|
|
24
|
-
await unlockWallet(wallet, user);
|
|
25
|
-
expect(spy.getValues()).toEqual([
|
|
26
|
-
expect.objectContaining({ locked: true }),
|
|
27
|
-
expect.objectContaining({ locked: false }),
|
|
28
|
-
]);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Query } from "applesauce-core";
|
|
2
|
-
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
/** Query that returns an array of redeemed event ids for a wallet */
|
|
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
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { combineLatest, filter, map, scan, startWith } from "rxjs";
|
|
2
|
-
import { getHistoryRedeemed, isHistoryContentLocked, WALLET_HISTORY_KIND } from "../helpers/history.js";
|
|
3
|
-
/** Query that returns an array of redeemed event ids for a wallet */
|
|
4
|
-
export function WalletRedeemedQuery(pubkey) {
|
|
5
|
-
return (events) => events
|
|
6
|
-
.filters({ kinds: [WALLET_HISTORY_KIND], authors: [pubkey] })
|
|
7
|
-
.pipe(scan((ids, history) => [...ids, ...getHistoryRedeemed(history)], []));
|
|
8
|
-
}
|
|
9
|
-
/** A query that returns a timeline of wallet history events */
|
|
10
|
-
export function WalletHistoryQuery(pubkey, locked) {
|
|
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
|
-
}));
|
|
20
|
-
};
|
|
21
|
-
}
|
package/dist/queries/index.d.ts
DELETED
package/dist/queries/index.js
DELETED
package/dist/queries/tokens.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Query } from "applesauce-core";
|
|
2
|
-
import { NostrEvent } from "nostr-tools";
|
|
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[]>;
|
|
5
|
-
/** A query that returns the visible balance of a wallet for each mint */
|
|
6
|
-
export declare function WalletBalanceQuery(pubkey: string): Query<Record<string, number>>;
|
package/dist/queries/tokens.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { combineLatest, filter, map, startWith } from "rxjs";
|
|
2
|
-
import { getTokenContent, ignoreDuplicateProofs, isTokenContentLocked, 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
|
-
// add ids to deleted array
|
|
13
|
-
if (!isTokenContentLocked(token)) {
|
|
14
|
-
const details = getTokenContent(token);
|
|
15
|
-
for (const id of details.del)
|
|
16
|
-
deleted.add(id);
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
})
|
|
20
|
-
.reverse();
|
|
21
|
-
}
|
|
22
|
-
/** A query that subscribes to all token events for a wallet, passing locked will filter by token locked status */
|
|
23
|
-
export function WalletTokensQuery(pubkey, locked) {
|
|
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));
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** A query that returns the visible balance of a wallet for each mint */
|
|
40
|
-
export function WalletBalanceQuery(pubkey) {
|
|
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
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
}
|
package/dist/queries/wallet.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Query } from "applesauce-core";
|
|
2
|
-
import { NostrEvent } from "nostr-tools";
|
|
3
|
-
export type WalletInfo = {
|
|
4
|
-
locked: true;
|
|
5
|
-
event: NostrEvent;
|
|
6
|
-
} | {
|
|
7
|
-
locked: false;
|
|
8
|
-
event: NostrEvent;
|
|
9
|
-
privateKey?: Uint8Array;
|
|
10
|
-
mints: string[];
|
|
11
|
-
};
|
|
12
|
-
/** A query to get the state of a NIP-60 wallet */
|
|
13
|
-
export declare function WalletQuery(pubkey: string): Query<WalletInfo | undefined>;
|
package/dist/queries/wallet.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { filter, map, merge } from "rxjs";
|
|
2
|
-
import { getWalletMints, getWalletPrivateKey, isWalletLocked, WALLET_KIND } from "../helpers/wallet.js";
|
|
3
|
-
/** A query to get the state of a NIP-60 wallet */
|
|
4
|
-
export function WalletQuery(pubkey) {
|
|
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
|
-
}));
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|