applesauce-wallet 1.0.0 → 3.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.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/actions/index.d.ts +2 -0
  3. package/dist/actions/index.js +2 -0
  4. package/dist/actions/tokens.js +1 -1
  5. package/dist/actions/zap-info.d.ts +22 -0
  6. package/dist/actions/zap-info.js +83 -0
  7. package/dist/actions/zaps.d.ts +8 -0
  8. package/dist/actions/zaps.js +30 -0
  9. package/dist/blueprints/history.d.ts +1 -2
  10. package/dist/blueprints/history.js +3 -3
  11. package/dist/blueprints/index.d.ts +3 -1
  12. package/dist/blueprints/index.js +3 -1
  13. package/dist/blueprints/tokens.d.ts +1 -2
  14. package/dist/blueprints/tokens.js +3 -3
  15. package/dist/blueprints/wallet.d.ts +2 -3
  16. package/dist/blueprints/wallet.js +4 -6
  17. package/dist/blueprints/zaps.d.ts +8 -0
  18. package/dist/blueprints/zaps.js +12 -0
  19. package/dist/helpers/history.js +3 -1
  20. package/dist/helpers/index.d.ts +5 -3
  21. package/dist/helpers/index.js +5 -3
  22. package/dist/helpers/nutzap.d.ts +27 -0
  23. package/dist/helpers/nutzap.js +66 -0
  24. package/dist/helpers/tokens.d.ts +1 -1
  25. package/dist/helpers/tokens.js +4 -2
  26. package/dist/helpers/wallet.js +4 -1
  27. package/dist/helpers/zap-info.d.ts +19 -0
  28. package/dist/helpers/zap-info.js +42 -0
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +2 -2
  31. package/dist/models/history.d.ts +6 -0
  32. package/dist/{queries → models}/history.js +5 -5
  33. package/dist/{operations/event → models}/index.d.ts +3 -2
  34. package/dist/{operations/event → models}/index.js +3 -2
  35. package/dist/models/nutzap.d.ts +6 -0
  36. package/dist/models/nutzap.js +16 -0
  37. package/dist/models/tokens.d.ts +6 -0
  38. package/dist/{queries → models}/tokens.js +6 -6
  39. package/dist/{queries → models}/wallet.d.ts +3 -3
  40. package/dist/{queries → models}/wallet.js +3 -3
  41. package/dist/operations/{event/history.d.ts → history.d.ts} +2 -2
  42. package/dist/operations/history.js +34 -0
  43. package/dist/operations/index.d.ts +5 -2
  44. package/dist/operations/index.js +5 -2
  45. package/dist/operations/nutzap.d.ts +14 -0
  46. package/dist/operations/nutzap.js +33 -0
  47. package/dist/operations/{event/tokens.d.ts → tokens.d.ts} +1 -1
  48. package/dist/operations/{event/tokens.js → tokens.js} +2 -2
  49. package/dist/operations/wallet.d.ts +8 -0
  50. package/dist/operations/wallet.js +30 -0
  51. package/dist/operations/zap-info.d.ts +10 -0
  52. package/dist/operations/zap-info.js +17 -0
  53. package/package.json +19 -24
  54. package/dist/__tests__/fake-user.d.ts +0 -10
  55. package/dist/__tests__/fake-user.js +0 -31
  56. package/dist/actions/__tests__/tokens.test.d.ts +0 -1
  57. package/dist/actions/__tests__/tokens.test.js +0 -139
  58. package/dist/actions/__tests__/wallet.test.d.ts +0 -1
  59. package/dist/actions/__tests__/wallet.test.js +0 -56
  60. package/dist/helpers/__tests__/animated-qr.test.d.ts +0 -1
  61. package/dist/helpers/__tests__/animated-qr.test.js +0 -44
  62. package/dist/helpers/__tests__/tokens.test.d.ts +0 -1
  63. package/dist/helpers/__tests__/tokens.test.js +0 -127
  64. package/dist/operations/event/__tests__/wallet.test.d.ts +0 -1
  65. package/dist/operations/event/__tests__/wallet.test.js +0 -25
  66. package/dist/operations/event/history.js +0 -19
  67. package/dist/operations/event/wallet.d.ts +0 -4
  68. package/dist/operations/event/wallet.js +0 -14
  69. package/dist/operations/tag/__tests__/wallet.test.d.ts +0 -1
  70. package/dist/operations/tag/__tests__/wallet.test.js +0 -16
  71. package/dist/operations/tag/history.d.ts +0 -14
  72. package/dist/operations/tag/history.js +0 -34
  73. package/dist/operations/tag/index.d.ts +0 -2
  74. package/dist/operations/tag/index.js +0 -2
  75. package/dist/operations/tag/wallet.d.ts +0 -5
  76. package/dist/operations/tag/wallet.js +0 -15
  77. package/dist/queries/__tests__/wallet.test.d.ts +0 -1
  78. package/dist/queries/__tests__/wallet.test.js +0 -30
  79. package/dist/queries/history.d.ts +0 -6
  80. package/dist/queries/index.d.ts +0 -3
  81. package/dist/queries/index.js +0 -3
  82. package/dist/queries/tokens.d.ts +0 -6
@@ -1,127 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { EventFactory } from "applesauce-factory";
3
- import { FakeUser } from "../../__tests__/fake-user.js";
4
- import { WalletTokenBlueprint } from "../../blueprints/tokens.js";
5
- import { decodeTokenFromEmojiString, dumbTokenSelection, encodeTokenToEmoji, unlockTokenContent } from "../tokens.js";
6
- import { HiddenContentSymbol, unixNow } from "applesauce-core/helpers";
7
- const user = new FakeUser();
8
- const factory = new EventFactory({ signer: user });
9
- describe("dumbTokenSelection", () => {
10
- it("should select old tokens first", async () => {
11
- const a = await user.signEvent(await factory.create(WalletTokenBlueprint, {
12
- mint: "https://money.com",
13
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
14
- }));
15
- await unlockTokenContent(a, user);
16
- const bDraft = await factory.create(WalletTokenBlueprint, {
17
- mint: "https://money.com",
18
- proofs: [{ secret: "B", C: "B", id: "B", amount: 50 }],
19
- });
20
- bDraft.created_at -= 60 * 60 * 7;
21
- const b = await user.signEvent(bDraft);
22
- await unlockTokenContent(b, user);
23
- expect(dumbTokenSelection([a, b], 40).events).toEqual([b]);
24
- });
25
- it("should select enough tokens to total min amount", async () => {
26
- const a = await user.signEvent(await factory.create(WalletTokenBlueprint, {
27
- mint: "https://money.com",
28
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
29
- }));
30
- await unlockTokenContent(a, user);
31
- const bDraft = await factory.create(WalletTokenBlueprint, {
32
- mint: "https://money.com",
33
- proofs: [{ secret: "B", C: "B", id: "B", amount: 50 }],
34
- });
35
- bDraft.created_at -= 60 * 60 * 7;
36
- const b = await user.signEvent(bDraft);
37
- await unlockTokenContent(b, user);
38
- expect(dumbTokenSelection([a, b], 120).events).toEqual(expect.arrayContaining([a, b]));
39
- });
40
- it("should throw if not enough funds", async () => {
41
- const a = await user.signEvent(await factory.create(WalletTokenBlueprint, {
42
- mint: "https://money.com",
43
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
44
- }));
45
- await unlockTokenContent(a, user);
46
- expect(() => dumbTokenSelection([a], 120)).toThrow();
47
- });
48
- it("should ignore locked tokens", async () => {
49
- const a = await user.signEvent(await factory.create(WalletTokenBlueprint, {
50
- mint: "https://money.com",
51
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
52
- }));
53
- await unlockTokenContent(a, user);
54
- const bDraft = await factory.create(WalletTokenBlueprint, {
55
- mint: "https://money.com",
56
- proofs: [{ secret: "B", C: "B", id: "B", amount: 50 }],
57
- });
58
- bDraft.created_at -= 60 * 60 * 7;
59
- const b = await user.signEvent(bDraft);
60
- // manually remove the hidden content to lock it again
61
- Reflect.deleteProperty(b, HiddenContentSymbol);
62
- expect(dumbTokenSelection([a, b], 20).events).toEqual([a]);
63
- });
64
- it("should ignore duplicate proofs", async () => {
65
- const a = await user.signEvent(await factory.create(WalletTokenBlueprint, {
66
- mint: "https://money.com",
67
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
68
- }));
69
- // create a second event with the same proofs
70
- const b = await user.signEvent(await factory.create(WalletTokenBlueprint, {
71
- mint: "https://money.com",
72
- proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
73
- }));
74
- expect(() => dumbTokenSelection([a, b], 150)).toThrow();
75
- });
76
- it("should include duplicate token events and ignore duplicate proofs", async () => {
77
- const A = { secret: "A", C: "A", id: "A", amount: 100 };
78
- const a = await user.signEvent({
79
- ...(await factory.create(WalletTokenBlueprint, {
80
- mint: "https://money.com",
81
- proofs: [A],
82
- })),
83
- // make event older
84
- created_at: unixNow() - 100,
85
- });
86
- // create a second event with the same proofs
87
- const a2 = await user.signEvent({
88
- ...(await factory.create(WalletTokenBlueprint, {
89
- mint: "https://money.com",
90
- proofs: [A],
91
- })),
92
- // make event older
93
- created_at: a.created_at - 200,
94
- });
95
- const B = { secret: "B", C: "B", id: "B", amount: 50 };
96
- const b = await user.signEvent(await factory.create(WalletTokenBlueprint, {
97
- mint: "https://money.com",
98
- proofs: [B],
99
- }));
100
- const result = dumbTokenSelection([a, a2, b], 150);
101
- expect(result.events.map((e) => e.id)).toEqual(expect.arrayContaining([a.id, a2.id, b.id]));
102
- expect(result.proofs).toEqual([A, B]);
103
- });
104
- });
105
- describe("encodeTokenToEmoji", () => {
106
- it("should encode token into emoji string", () => {
107
- const token = "cashuBo2FteBtodHRwczovL3Rlc3RudXQuY2FzaHUuc3BhY2VhdWNzYXRhdIGiYWlIAJofKTJT5B5hcIGkYWEBYXN4QDdlZDBkMzk3NGQ5ZWM2OTc2YTAzYmZmYjdkMTA4NzIzZTBiMDRjMzRhNDc3MjlmNjMwOGJlODc3OTA2NTY0NDVhY1ghA36iYyOHCe4CnTxzORbcXFVeAbkMUFE6FqPWInujnAOcYWSjYWVYIJmHRwCQ0Uopkd3P5xb0MdcWQEaZz9hXWtcn-FMhZj8LYXNYIF4X9ybXxg5Pp0KSowfu4y_Aovo9iy3TXlLSaKyVJzz2YXJYIC_UFkoC5U9BpSgBTGUQgsjfz_emv5xykDiavZUfRN8E";
108
- expect(encodeTokenToEmoji(token).length).toBeGreaterThan(token.length);
109
- });
110
- });
111
- const emoji = "🥜󠅓󠅑󠅣󠅘󠅥󠄲󠅟󠄢󠄶󠅤󠅕󠄲󠅤󠅟󠅔󠄸󠅂󠅧󠅓󠅪󠅟󠅦󠄼󠄣󠅂󠅜󠅓󠄣󠅂󠅥󠅔󠅈󠅁󠅥󠅉󠄢󠄶󠅪󠅑󠄸󠅅󠅥󠅓󠄣󠄲󠅘󠅉󠄢󠅆󠅘󠅔󠅇󠄾󠅪󠅉󠅈󠅂󠅘󠅔󠄹󠄷󠅙󠅉󠅇󠅜󠄹󠄱󠄺󠅟󠅖󠄻󠅄󠄺󠅄󠄥󠄲󠄥󠅘󠅓󠄹󠄷󠅛󠅉󠅇󠄵󠄲󠅉󠅈󠄾󠄤󠅁󠄴󠅔󠅜󠅊󠄴󠄲󠅛󠄽󠅪󠅛󠄣󠄾󠄷󠅁󠄥󠅊󠅇󠄽󠄢󠄿󠅄󠅓󠄢󠅉󠅄󠄱󠅪󠅉󠅝󠅊󠅝󠅉󠅚󠅔󠅛󠄽󠅄󠄱󠄤󠄾󠅪󠄹󠅪󠅊󠅄󠄲󠅙󠄽󠄴󠅂󠅚󠄽󠅪󠅂󠅘󠄾󠄴󠅓󠄣󠄽󠅚󠅜󠅝󠄾󠅚󠄽󠅧󠄿󠄷󠄺󠅜󠄿󠄴󠅓󠄣󠄿󠅄󠄱󠄢󠄾󠅄󠅉󠄠󠄾󠄴󠅆󠅘󠅉󠄡󠅗󠅘󠄱󠄣󠄦󠅙󠅉󠅩󠄿󠄸󠄳󠅕󠄤󠄳󠅞󠅄󠅨󠅪󠄿󠅂󠅒󠅓󠅈󠄶󠅆󠅕󠄱󠅒󠅛󠄽󠅅󠄶󠄵󠄦󠄶󠅡󠅀󠅇󠄹󠅞󠅥󠅚󠅞󠄱󠄿󠅓󠅉󠅇󠅃󠅚󠅉󠅇󠅆󠅉󠄹󠄺󠅝󠄸󠅂󠅧󠄳󠅁󠄠󠅅󠅟󠅠󠅛󠅔󠄣󠅀󠄥󠅨󠅒󠄠󠄽󠅔󠅓󠅇󠅁󠄵󠅑󠅊󠅪󠄩󠅘󠅈󠅇󠅤󠅓󠅞󠄝󠄶󠄽󠅘󠅊󠅚󠄨󠄼󠅉󠅈󠄾󠅉󠄹󠄶󠄤󠅈󠄩󠅩󠅒󠅈󠅨󠅗󠄥󠅀󠅠󠄠󠄻󠅃󠅟󠅧󠅖󠅥󠄤󠅩󠅏󠄱󠅟󠅦󠅟󠄩󠅙󠅩󠄣󠅄󠅈󠅜󠄼󠅃󠅑󠄻󠅩󠅆󠄺󠅪󠅪󠄢󠅉󠅈󠄺󠅉󠄹󠄳󠅏󠅅󠄶󠅛󠅟󠄳󠄥󠅅󠄩󠄲󠅠󠅃󠅗󠄲󠅄󠄷󠅅󠅁󠅗󠅣󠅚󠅖󠅪󠅏󠅕󠅝󠅦󠄥󠅨󠅩󠅛󠄴󠅙󠅑󠅦󠅊󠅅󠅖󠅂󠄾󠄨󠄵";
112
- describe("decodeTokenFromEmojiString", () => {
113
- it("should decode single emoji", () => {
114
- expect(decodeTokenFromEmojiString(emoji)).toEqual(expect.objectContaining({
115
- mint: "https://testnut.cashu.space",
116
- proofs: [expect.any(Object)],
117
- unit: "sat",
118
- }));
119
- });
120
- it("should decode an emoji in text", () => {
121
- expect(decodeTokenFromEmojiString("the money is in the emoji, " + emoji + " you can redeem it using cashu.me")).toEqual(expect.objectContaining({
122
- mint: "https://testnut.cashu.space",
123
- proofs: [expect.any(Object)],
124
- unit: "sat",
125
- }));
126
- });
127
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { setWalletBackupContent } from "../wallet.js";
3
- import { EventFactory } from "applesauce-factory";
4
- import { generateSecretKey } from "nostr-tools";
5
- import { unixNow } from "applesauce-core/helpers";
6
- import { WALLET_BACKUP_KIND } from "../../../helpers/wallet.js";
7
- import { FakeUser } from "../../../__tests__/fake-user.js";
8
- import { WalletBlueprint } from "../../../blueprints/wallet.js";
9
- const user = new FakeUser();
10
- const factory = new EventFactory({ signer: user });
11
- describe("setWalletBackupContent", () => {
12
- it("should throw if kind is not wallet kind", async () => {
13
- const note = user.note();
14
- await expect(setWalletBackupContent(note)({ kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, factory.context)).rejects.toThrow();
15
- });
16
- it("should throw if pubkey does not match", async () => {
17
- const wallet = await factory.sign(await factory.create(WalletBlueprint, [], generateSecretKey()));
18
- const user2 = new FakeUser();
19
- await expect(setWalletBackupContent(wallet)({ kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, { signer: user2 })).rejects.toThrow();
20
- });
21
- it("should copy the content of the wallet event", async () => {
22
- const wallet = await factory.sign(await factory.create(WalletBlueprint, [], generateSecretKey()));
23
- expect(await setWalletBackupContent(wallet)({ kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, factory.context)).toEqual(expect.objectContaining({ content: wallet.content }));
24
- });
25
- });
@@ -1,19 +0,0 @@
1
- import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations/event";
2
- import { includeHistoryCreatedTags, includeHistoryRedeemedTags, setHistoryAmountTag, setHistoryDirectionTag, setHistoryFeeTag, setHistoryMintTag, } from "../tag/history.js";
3
- /** Sets the encrypted tags of a wallet history event */
4
- export function setHistoryContent(content) {
5
- const operations = [
6
- setHistoryDirectionTag(content.direction),
7
- setHistoryAmountTag(content.amount),
8
- includeHistoryCreatedTags(content.created),
9
- ];
10
- if (content.fee !== undefined)
11
- operations.push(setHistoryFeeTag(content.fee));
12
- if (content.mint !== undefined)
13
- operations.push(setHistoryMintTag(content.mint));
14
- return modifyHiddenTags(...operations);
15
- }
16
- /** Sets the "redeemed" tags on a wallet history event */
17
- export function setHistoryRedeemed(redeemed) {
18
- return modifyPublicTags(includeHistoryRedeemedTags(redeemed));
19
- }
@@ -1,4 +0,0 @@
1
- import { EventOperation } from "applesauce-factory";
2
- import { NostrEvent } from "nostr-tools";
3
- /** Sets the content of a kind 375 wallet backup event */
4
- export declare function setWalletBackupContent(wallet: NostrEvent): EventOperation;
@@ -1,14 +0,0 @@
1
- import { WALLET_KIND } from "../../helpers/wallet.js";
2
- /** Sets the content of a kind 375 wallet backup event */
3
- export function setWalletBackupContent(wallet) {
4
- return async (draft, ctx) => {
5
- if (wallet.kind !== WALLET_KIND)
6
- throw new Error(`Cant create a wallet backup from kind ${wallet.kind}`);
7
- if (!wallet.content)
8
- throw new Error("Wallet missing content");
9
- const pubkey = await ctx.signer?.getPublicKey();
10
- if (wallet.pubkey !== pubkey)
11
- throw new Error("Wallet pubkey dose not match signer pubkey");
12
- return { ...draft, content: wallet.content };
13
- };
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { setMintTags } from "../wallet.js";
3
- describe("setMintTags", () => {
4
- it("should replace existing mint tags", () => {
5
- expect(setMintTags(["https://mint.com"])([["mint", "https://other.mint.com"]], {})).toEqual(expect.arrayContaining([["mint", "https://mint.com"]]));
6
- });
7
- it("should ignore other tags", () => {
8
- expect(setMintTags(["https://mint.com"])([
9
- ["mint", "https://other.mint.com"],
10
- ["privkey", "00000000"],
11
- ], {})).toEqual(expect.arrayContaining([
12
- ["mint", "https://mint.com"],
13
- ["privkey", "00000000"],
14
- ]));
15
- });
16
- });
@@ -1,14 +0,0 @@
1
- import { TagOperation } from "applesauce-factory";
2
- import { EventPointer } from "nostr-tools/nip19";
3
- import { HistoryDirection } from "../../helpers/history.js";
4
- /** Sets the "direction" tag on wallet history tags */
5
- export declare function setHistoryDirectionTag(direction: HistoryDirection): TagOperation;
6
- /** Sets the "amount" tag on wallet history tags */
7
- export declare function setHistoryAmountTag(amount: number): TagOperation;
8
- /** Sets the "fee" tag in wallet history tags */
9
- export declare function setHistoryFeeTag(fee: number): TagOperation;
10
- export declare function setHistoryMintTag(mint: string): TagOperation;
11
- /** Includes "created" "e" tags in wallet history tags */
12
- export declare function includeHistoryCreatedTags(created: (string | EventPointer)[]): TagOperation;
13
- /** Includes the "redeemed" tags in wallet history tags */
14
- export declare function includeHistoryRedeemedTags(redeemed: (string | EventPointer)[]): TagOperation;
@@ -1,34 +0,0 @@
1
- import { ensureMarkedEventPointerTag, ensureSingletonTag } from "applesauce-factory/helpers";
2
- /** Sets the "direction" tag on wallet history tags */
3
- export function setHistoryDirectionTag(direction) {
4
- return (tags) => ensureSingletonTag(tags, ["direction", direction], true);
5
- }
6
- /** Sets the "amount" tag on wallet history tags */
7
- export function setHistoryAmountTag(amount) {
8
- return (tags) => ensureSingletonTag(tags, ["amount", String(amount)], true);
9
- }
10
- /** Sets the "fee" tag in wallet history tags */
11
- export function setHistoryFeeTag(fee) {
12
- return (tags) => ensureSingletonTag(tags, ["fee", String(fee)], true);
13
- }
14
- export function setHistoryMintTag(mint) {
15
- return (tags) => ensureSingletonTag(tags, ["mint", mint], true);
16
- }
17
- /** Includes "created" "e" tags in wallet history tags */
18
- export function includeHistoryCreatedTags(created) {
19
- return (tags) => {
20
- for (const id of created) {
21
- tags = ensureMarkedEventPointerTag(tags, typeof id === "string" ? { id } : id, "created");
22
- }
23
- return tags;
24
- };
25
- }
26
- /** Includes the "redeemed" tags in wallet history tags */
27
- export function includeHistoryRedeemedTags(redeemed) {
28
- return (tags) => {
29
- for (const id of redeemed) {
30
- tags = ensureMarkedEventPointerTag(tags, typeof id === "string" ? { id } : id, "redeemed");
31
- }
32
- return tags;
33
- };
34
- }
@@ -1,2 +0,0 @@
1
- export * from "./wallet.js";
2
- export * from "./history.js";
@@ -1,2 +0,0 @@
1
- export * from "./wallet.js";
2
- export * from "./history.js";
@@ -1,5 +0,0 @@
1
- import { TagOperation } from "applesauce-factory";
2
- /** Sets the "mint" tags in a wallet event */
3
- export declare function setMintTags(mints: string[]): TagOperation;
4
- /** Sets the "privkey" tag on a wallet event */
5
- export declare function setPrivateKeyTag(privateKey: Uint8Array): TagOperation;
@@ -1,15 +0,0 @@
1
- import { bytesToHex } from "@noble/hashes/utils";
2
- import { ensureSingletonTag } from "applesauce-factory/helpers";
3
- /** Sets the "mint" tags in a wallet event */
4
- export function setMintTags(mints) {
5
- return (tags) => [
6
- // remove all existing mint tags
7
- ...tags.filter((t) => t[0] !== "mint"),
8
- // add new mint tags
9
- ...mints.map((mint) => ["mint", mint]),
10
- ];
11
- }
12
- /** Sets the "privkey" tag on a wallet event */
13
- export function setPrivateKeyTag(privateKey) {
14
- return (tags) => ensureSingletonTag(tags, ["privkey", bytesToHex(privateKey)], true);
15
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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[]>;
@@ -1,3 +0,0 @@
1
- export * from "./wallet.js";
2
- export * from "./history.js";
3
- export * from "./tokens.js";
@@ -1,3 +0,0 @@
1
- export * from "./wallet.js";
2
- export * from "./history.js";
3
- export * from "./tokens.js";
@@ -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>>;