applesauce-wallet 0.0.0-next-20250723224513 → 0.0.0-next-20250725170333

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 (75) hide show
  1. package/dist/actions/zap-info.js +2 -2
  2. package/dist/blueprints/history.js +1 -1
  3. package/dist/blueprints/tokens.js +2 -2
  4. package/dist/blueprints/wallet.js +3 -5
  5. package/dist/blueprints/zaps.js +3 -3
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/operations/{event/history.d.ts → history.d.ts} +2 -2
  9. package/dist/operations/history.js +34 -0
  10. package/dist/operations/index.d.ts +5 -2
  11. package/dist/operations/index.js +5 -2
  12. package/dist/operations/{event/zaps.d.ts → nut-zap.d.ts} +5 -5
  13. package/dist/operations/{event/zaps.js → nut-zap.js} +8 -7
  14. package/dist/operations/{event/tokens.d.ts → tokens.d.ts} +1 -1
  15. package/dist/operations/{event/tokens.js → tokens.js} +2 -2
  16. package/dist/operations/wallet.d.ts +8 -0
  17. package/dist/operations/wallet.js +30 -0
  18. package/dist/operations/{event/zap-info.js → zap-info.js} +1 -1
  19. package/package.json +5 -5
  20. package/dist/__tests__/exports.test.d.ts +0 -1
  21. package/dist/__tests__/exports.test.js +0 -16
  22. package/dist/__tests__/fake-user.d.ts +0 -10
  23. package/dist/__tests__/fake-user.js +0 -31
  24. package/dist/actions/__tests__/exports.test.d.ts +0 -1
  25. package/dist/actions/__tests__/exports.test.js +0 -17
  26. package/dist/actions/__tests__/tokens.test.d.ts +0 -1
  27. package/dist/actions/__tests__/tokens.test.js +0 -139
  28. package/dist/actions/__tests__/wallet.test.d.ts +0 -1
  29. package/dist/actions/__tests__/wallet.test.js +0 -56
  30. package/dist/blueprints/__tests__/exports.test.d.ts +0 -1
  31. package/dist/blueprints/__tests__/exports.test.js +0 -13
  32. package/dist/helpers/__tests__/animated-qr.test.d.ts +0 -1
  33. package/dist/helpers/__tests__/animated-qr.test.js +0 -44
  34. package/dist/helpers/__tests__/exports.test.d.ts +0 -1
  35. package/dist/helpers/__tests__/exports.test.js +0 -42
  36. package/dist/helpers/__tests__/tokens.test.d.ts +0 -1
  37. package/dist/helpers/__tests__/tokens.test.js +0 -127
  38. package/dist/models/__tests__/exports.test.d.ts +0 -1
  39. package/dist/models/__tests__/exports.test.js +0 -15
  40. package/dist/models/__tests__/wallet.test.d.ts +0 -1
  41. package/dist/models/__tests__/wallet.test.js +0 -28
  42. package/dist/operations/__tests__/exports.test.d.ts +0 -1
  43. package/dist/operations/__tests__/exports.test.js +0 -12
  44. package/dist/operations/event/__tests__/exports.test.d.ts +0 -1
  45. package/dist/operations/event/__tests__/exports.test.js +0 -14
  46. package/dist/operations/event/__tests__/wallet.test.d.ts +0 -1
  47. package/dist/operations/event/__tests__/wallet.test.js +0 -25
  48. package/dist/operations/event/history.js +0 -19
  49. package/dist/operations/event/index.d.ts +0 -5
  50. package/dist/operations/event/index.js +0 -5
  51. package/dist/operations/event/wallet.d.ts +0 -4
  52. package/dist/operations/event/wallet.js +0 -14
  53. package/dist/operations/tag/__tests__/exports.test.d.ts +0 -1
  54. package/dist/operations/tag/__tests__/exports.test.js +0 -18
  55. package/dist/operations/tag/__tests__/wallet.test.d.ts +0 -1
  56. package/dist/operations/tag/__tests__/wallet.test.js +0 -16
  57. package/dist/operations/tag/history.d.ts +0 -14
  58. package/dist/operations/tag/history.js +0 -34
  59. package/dist/operations/tag/index.d.ts +0 -2
  60. package/dist/operations/tag/index.js +0 -2
  61. package/dist/operations/tag/wallet.d.ts +0 -5
  62. package/dist/operations/tag/wallet.js +0 -15
  63. package/dist/queries/__tests__/exports.test.d.ts +0 -1
  64. package/dist/queries/__tests__/exports.test.js +0 -15
  65. package/dist/queries/__tests__/wallet.test.d.ts +0 -1
  66. package/dist/queries/__tests__/wallet.test.js +0 -30
  67. package/dist/queries/history.d.ts +0 -6
  68. package/dist/queries/history.js +0 -21
  69. package/dist/queries/index.d.ts +0 -3
  70. package/dist/queries/index.js +0 -3
  71. package/dist/queries/tokens.d.ts +0 -6
  72. package/dist/queries/tokens.js +0 -58
  73. package/dist/queries/wallet.d.ts +0 -13
  74. package/dist/queries/wallet.js +0 -18
  75. /package/dist/operations/{event/zap-info.d.ts → zap-info.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
- import { modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addNameValueTag, removeNameValueTag, setSingletonTag } from "applesauce-factory/operations/tag";
3
3
  import { NUTZAP_INFO_KIND } from "../helpers/zap-info.js";
4
- import { setNutzapInfoMints, setNutzapInfoPubkey, setNutzapInfoRelays } from "../operations/event/zap-info.js";
4
+ import { setNutzapInfoMints, setNutzapInfoPubkey, setNutzapInfoRelays } from "../operations/zap-info.js";
5
5
  /** An action to add a relay to the kind 10019 nutzap info event */
6
6
  export function AddNutzapInfoRelay(relay) {
7
7
  return async function* ({ events, factory, self }) {
@@ -1,6 +1,6 @@
1
1
  import { blueprint } from "applesauce-factory";
2
2
  import { WALLET_HISTORY_KIND } from "../helpers/history.js";
3
- import { setHistoryContent, setHistoryRedeemed } from "../operations/event/history.js";
3
+ import { setHistoryContent, setHistoryRedeemed } from "../operations/history.js";
4
4
  /** A blueprint that creates a wallet history event */
5
5
  export function WalletHistoryBlueprint(content, redeemed) {
6
6
  return blueprint(WALLET_HISTORY_KIND,
@@ -1,11 +1,11 @@
1
1
  import { blueprint } from "applesauce-factory";
2
2
  import { WALLET_TOKEN_KIND } from "../helpers/tokens.js";
3
- import { setTokenContent } from "../operations/event/tokens.js";
3
+ import { setToken } from "../operations/tokens.js";
4
4
  /**
5
5
  * A blueprint for a wallet token event, takes a cashu token and previous deleted token event ids
6
6
  * @param token the cashu token to store
7
7
  * @param [del=[]] an array of previous token event ids that are deleted
8
8
  */
9
9
  export function WalletTokenBlueprint(token, del = []) {
10
- return blueprint(WALLET_TOKEN_KIND, setTokenContent(token, del));
10
+ return blueprint(WALLET_TOKEN_KIND, setToken(token, del));
11
11
  }
@@ -1,13 +1,11 @@
1
1
  import { blueprint } from "applesauce-factory";
2
- import { modifyHiddenTags } from "applesauce-factory/operations/event";
3
2
  import { WALLET_BACKUP_KIND, WALLET_KIND } from "../helpers/wallet.js";
4
- import { setWalletBackupContent } from "../operations/event/wallet.js";
5
- import { setMintTags, setPrivateKeyTag } from "../operations/tag/wallet.js";
3
+ import { setBackupContent, setMints, setPrivateKey } from "../operations/wallet.js";
6
4
  /** A blueprint to create a new 17375 wallet */
7
5
  export function WalletBlueprint(mints, privateKey) {
8
- return blueprint(WALLET_KIND, modifyHiddenTags(privateKey ? setPrivateKeyTag(privateKey) : undefined, setMintTags(mints)));
6
+ return blueprint(WALLET_KIND, setMints(mints), privateKey ? setPrivateKey(privateKey) : undefined);
9
7
  }
10
8
  /** A blueprint that creates a new 375 wallet backup event */
11
9
  export function WalletBackupBlueprint(wallet) {
12
- return blueprint(WALLET_BACKUP_KIND, setWalletBackupContent(wallet));
10
+ return blueprint(WALLET_BACKUP_KIND, setBackupContent(wallet));
13
11
  }
@@ -1,12 +1,12 @@
1
1
  import { blueprint } from "applesauce-factory";
2
2
  import { skip } from "applesauce-factory/helpers";
3
3
  import { NUTZAP_KIND } from "../helpers/zaps.js";
4
- import { setNutzapComment, setNutzapEvent, setNutzapMint, setNutzapProofs, setNutzapRecipient, } from "../operations/event/zaps.js";
4
+ import { setComment, setEvent, setMint, setProofs, setRecipient } from "../operations/nut-zap.js";
5
5
  /** A blueprint to create a NIP-61 nutzap event for an event */
6
6
  export function NutzapBlueprint(event, token, comment) {
7
- return blueprint(NUTZAP_KIND, setNutzapProofs(token.proofs), setNutzapMint(token.mint), setNutzapEvent(event), setNutzapRecipient(event.pubkey), comment ? setNutzapComment(comment) : skip());
7
+ return blueprint(NUTZAP_KIND, setProofs(token.proofs), setMint(token.mint), setEvent(event), setRecipient(event.pubkey), comment ? setComment(comment) : skip());
8
8
  }
9
9
  /** A blueprint to create a NIP-61 nutzap event for a user instead of an event */
10
10
  export function ProfileNutzapBlueprint(user, token, comment) {
11
- return blueprint(NUTZAP_KIND, setNutzapProofs(token.proofs), setNutzapMint(token.mint), setNutzapRecipient(user), comment ? setNutzapComment(comment) : skip());
11
+ return blueprint(NUTZAP_KIND, setProofs(token.proofs), setMint(token.mint), setRecipient(user), comment ? setComment(comment) : skip());
12
12
  }
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export * as Actions from "./actions/index.js";
2
2
  export * as Blueprints from "./blueprints/index.js";
3
3
  export * as Helpers from "./helpers/index.js";
4
4
  export * as Models from "./models/index.js";
5
- export * from "./operations/index.js";
5
+ export * as Operations from "./operations/index.js";
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ export * as Actions from "./actions/index.js";
2
2
  export * as Blueprints from "./blueprints/index.js";
3
3
  export * as Helpers from "./helpers/index.js";
4
4
  export * as Models from "./models/index.js";
5
- export * from "./operations/index.js";
5
+ export * as Operations from "./operations/index.js";
@@ -1,7 +1,7 @@
1
1
  import { EventOperation } from "applesauce-factory";
2
- import { HistoryContent } from "../../helpers/history.js";
3
2
  import { EventPointer } from "nostr-tools/nip19";
3
+ import { HistoryContent } from "../helpers/history.js";
4
4
  /** Sets the encrypted tags of a wallet history event */
5
5
  export declare function setHistoryContent(content: HistoryContent): EventOperation;
6
- /** Sets the "redeemed" tags on a wallet history event */
6
+ /** Sets the "e" "redeemed" tags on a wallet history event */
7
7
  export declare function setHistoryRedeemed(redeemed: (string | EventPointer)[]): EventOperation;
@@ -0,0 +1,34 @@
1
+ import { ensureMarkedEventPointerTag } from "applesauce-factory/helpers";
2
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
3
+ import { setSingletonTag } from "applesauce-factory/operations/tag";
4
+ /** Includes "e" "created" tags in wallet history tags */
5
+ function includeHistoryCreatedTags(created) {
6
+ return (tags) => {
7
+ for (const id of created) {
8
+ tags = ensureMarkedEventPointerTag(tags, typeof id === "string" ? { id } : id, "created");
9
+ }
10
+ return tags;
11
+ };
12
+ }
13
+ /** Sets the encrypted tags of a wallet history event */
14
+ export function setHistoryContent(content) {
15
+ const operations = [
16
+ setSingletonTag(["direction", content.direction], true),
17
+ setSingletonTag(["amount", String(content.amount)], true),
18
+ includeHistoryCreatedTags(content.created),
19
+ ];
20
+ if (content.fee !== undefined)
21
+ operations.push(setSingletonTag(["fee", String(content.fee)], true));
22
+ if (content.mint !== undefined)
23
+ operations.push(setSingletonTag(["mint", content.mint], true));
24
+ return modifyHiddenTags(...operations);
25
+ }
26
+ /** Sets the "e" "redeemed" tags on a wallet history event */
27
+ export function setHistoryRedeemed(redeemed) {
28
+ return modifyPublicTags((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 +1,5 @@
1
- export * as TagOperations from "./tag/index.js";
2
- export * as EventOperations from "./event/index.js";
1
+ export * as History from "./history.js";
2
+ export * as Tokens from "./tokens.js";
3
+ export * as Wallet from "./wallet.js";
4
+ export * as ZapInfo from "./zap-info.js";
5
+ export * as NutZap from "./nut-zap.js";
@@ -1,2 +1,5 @@
1
- export * as TagOperations from "./tag/index.js";
2
- export * as EventOperations from "./event/index.js";
1
+ export * as History from "./history.js";
2
+ export * as Tokens from "./tokens.js";
3
+ export * as Wallet from "./wallet.js";
4
+ export * as ZapInfo from "./zap-info.js";
5
+ export * as NutZap from "./nut-zap.js";
@@ -3,12 +3,12 @@ import { EventOperation } from "applesauce-factory";
3
3
  import { NostrEvent } from "nostr-tools";
4
4
  import { AddressPointer, EventPointer, ProfilePointer } from "nostr-tools/nip19";
5
5
  /** Sets the cashu proofs for a nutzap event */
6
- export declare function setNutzapProofs(proofs: Proof[]): EventOperation;
6
+ export declare function setProofs(proofs: Proof[]): EventOperation;
7
7
  /** Sets the mint URL for a nutzap event */
8
- export declare function setNutzapMint(mint: string): EventOperation;
8
+ export declare function setMint(mint: string): EventOperation;
9
9
  /** Sets the recipient of a nutzap event */
10
- export declare function setNutzapRecipient(recipient: string | ProfilePointer): EventOperation;
10
+ export declare function setRecipient(recipient: string | ProfilePointer): EventOperation;
11
11
  /** Sets the event that is being nutzapped */
12
- export declare function setNutzapEvent(event: EventPointer | AddressPointer | NostrEvent): EventOperation;
12
+ export declare function setEvent(event: EventPointer | AddressPointer | NostrEvent): EventOperation;
13
13
  /** Sets the comment content for a nutzap event */
14
- export declare function setNutzapComment(comment: string): EventOperation;
14
+ export declare function setComment(comment: string): EventOperation;
@@ -1,22 +1,23 @@
1
1
  import { getReplaceableAddress, isAddressPointer, isEvent, isReplaceable } from "applesauce-core/helpers";
2
- import { modifyPublicTags } from "applesauce-factory/operations/event";
2
+ import { modifyPublicTags } from "applesauce-factory/operations";
3
+ import { setContent } from "applesauce-factory/operations/content";
3
4
  import { addAddressTag, addEventTag, addPubkeyTag, setSingletonTag } from "applesauce-factory/operations/tag";
4
5
  /** Sets the cashu proofs for a nutzap event */
5
- export function setNutzapProofs(proofs) {
6
+ export function setProofs(proofs) {
6
7
  // Create an operation to append proof tags
7
8
  const operation = (tags) => [...tags, ...proofs.map((proof) => ["proof", JSON.stringify(proof)])];
8
9
  return modifyPublicTags(operation);
9
10
  }
10
11
  /** Sets the mint URL for a nutzap event */
11
- export function setNutzapMint(mint) {
12
+ export function setMint(mint) {
12
13
  return modifyPublicTags(setSingletonTag(["u", mint]));
13
14
  }
14
15
  /** Sets the recipient of a nutzap event */
15
- export function setNutzapRecipient(recipient) {
16
+ export function setRecipient(recipient) {
16
17
  return modifyPublicTags(addPubkeyTag(recipient, true));
17
18
  }
18
19
  /** Sets the event that is being nutzapped */
19
- export function setNutzapEvent(event) {
20
+ export function setEvent(event) {
20
21
  let operation;
21
22
  if (isEvent(event))
22
23
  operation = isReplaceable(event.kind) ? addEventTag(event.id) : addAddressTag(getReplaceableAddress(event));
@@ -27,6 +28,6 @@ export function setNutzapEvent(event) {
27
28
  return modifyPublicTags(operation);
28
29
  }
29
30
  /** Sets the comment content for a nutzap event */
30
- export function setNutzapComment(comment) {
31
- return (draft) => ({ ...draft, content: comment });
31
+ export function setComment(comment) {
32
+ return setContent(comment);
32
33
  }
@@ -1,4 +1,4 @@
1
1
  import { Token } from "@cashu/cashu-ts";
2
2
  import { EventOperation } from "applesauce-factory";
3
3
  /** Sets the content of a 7375 token event */
4
- export declare function setTokenContent(token: Token, del?: string[]): EventOperation;
4
+ export declare function setToken(token: Token, del?: string[]): EventOperation;
@@ -1,7 +1,7 @@
1
1
  import { EventContentEncryptionMethod } from "applesauce-core/helpers";
2
- import { setEncryptedContent } from "applesauce-factory/operations/event";
2
+ import { setEncryptedContent } from "applesauce-factory/operations/content";
3
3
  /** Sets the content of a 7375 token event */
4
- export function setTokenContent(token, del = []) {
4
+ export function setToken(token, del = []) {
5
5
  return async (draft, ctx) => {
6
6
  if (!ctx.signer)
7
7
  throw new Error(`Missing signer`);
@@ -0,0 +1,8 @@
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 setBackupContent(wallet: NostrEvent): EventOperation;
5
+ /** Sets the "mint" tags in a wallet event */
6
+ export declare function setMints(mints: string[]): EventOperation;
7
+ /** Sets the "privkey" tag on a wallet event */
8
+ export declare function setPrivateKey(privateKey: Uint8Array): EventOperation;
@@ -0,0 +1,30 @@
1
+ import { bytesToHex } from "@noble/hashes/utils";
2
+ import { modifyHiddenTags } from "applesauce-factory/operations";
3
+ import { setSingletonTag } from "applesauce-factory/operations/tag";
4
+ import { WALLET_KIND } from "../helpers/wallet.js";
5
+ /** Sets the content of a kind 375 wallet backup event */
6
+ export function setBackupContent(wallet) {
7
+ return async (draft, ctx) => {
8
+ if (wallet.kind !== WALLET_KIND)
9
+ throw new Error(`Cant create a wallet backup from kind ${wallet.kind}`);
10
+ if (!wallet.content)
11
+ throw new Error("Wallet missing content");
12
+ const pubkey = await ctx.signer?.getPublicKey();
13
+ if (wallet.pubkey !== pubkey)
14
+ throw new Error("Wallet pubkey dose not match signer pubkey");
15
+ return { ...draft, content: wallet.content };
16
+ };
17
+ }
18
+ /** Sets the "mint" tags in a wallet event */
19
+ export function setMints(mints) {
20
+ return modifyHiddenTags((tags) => [
21
+ // remove all existing mint tags
22
+ ...tags.filter((t) => t[0] !== "mint"),
23
+ // add new mint tags
24
+ ...mints.map((mint) => ["mint", mint]),
25
+ ]);
26
+ }
27
+ /** Sets the "privkey" tag on a wallet event */
28
+ export function setPrivateKey(privateKey) {
29
+ return modifyHiddenTags(setSingletonTag(["privkey", bytesToHex(privateKey)], true));
30
+ }
@@ -1,4 +1,4 @@
1
- import { modifyPublicTags } from "applesauce-factory/operations/event";
1
+ import { modifyPublicTags } from "applesauce-factory/operations";
2
2
  import { addNameValueTag, setSingletonTag } from "applesauce-factory/operations/tag";
3
3
  /** Sets the relays for a nutzap info event */
4
4
  export function setNutzapInfoRelays(relays) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20250723224513",
3
+ "version": "0.0.0-next-20250725170333",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -80,16 +80,16 @@
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.0.0-next-20250723224513",
84
- "applesauce-core": "0.0.0-next-20250723224513",
85
- "applesauce-factory": "0.0.0-next-20250723224513",
83
+ "applesauce-actions": "0.0.0-next-20250725170333",
84
+ "applesauce-core": "0.0.0-next-20250725170333",
85
+ "applesauce-factory": "0.0.0-next-20250725170333",
86
86
  "nostr-tools": "^2.13",
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.0.0-next-20250723224513",
92
+ "applesauce-signers": "0.0.0-next-20250725170333",
93
93
  "typescript": "^5.8.3",
94
94
  "vitest": "^3.2.3"
95
95
  },
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import * as exports from "../index.js";
3
- describe("exports", () => {
4
- it("should export the expected functions", () => {
5
- expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
6
- [
7
- "Actions",
8
- "Blueprints",
9
- "EventOperations",
10
- "Helpers",
11
- "Queries",
12
- "TagOperations",
13
- ]
14
- `);
15
- });
16
- });
@@ -1,10 +0,0 @@
1
- import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
2
- import type { NostrEvent } from "nostr-tools";
3
- export declare class FakeUser extends SimpleSigner {
4
- pubkey: string;
5
- event(data?: Partial<NostrEvent>): NostrEvent;
6
- note(content?: string, extra?: Partial<NostrEvent>): import("nostr-tools").Event;
7
- profile(profile: any, extra?: Partial<NostrEvent>): import("nostr-tools").Event;
8
- contacts(pubkeys?: string[]): import("nostr-tools").Event;
9
- list(tags?: string[][], extra?: Partial<NostrEvent>): import("nostr-tools").Event;
10
- }
@@ -1,31 +0,0 @@
1
- import { unixNow } from "applesauce-core/helpers";
2
- import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
3
- import { finalizeEvent, getPublicKey, kinds } from "nostr-tools";
4
- export class FakeUser extends SimpleSigner {
5
- pubkey = getPublicKey(this.key);
6
- event(data) {
7
- return finalizeEvent({
8
- kind: data?.kind ?? kinds.ShortTextNote,
9
- content: data?.content || "",
10
- created_at: data?.created_at ?? unixNow(),
11
- tags: data?.tags || [],
12
- }, this.key);
13
- }
14
- note(content = "Hello World", extra) {
15
- return this.event({ kind: kinds.ShortTextNote, content, ...extra });
16
- }
17
- profile(profile, extra) {
18
- return this.event({ kind: kinds.Metadata, content: JSON.stringify({ ...profile }), ...extra });
19
- }
20
- contacts(pubkeys = []) {
21
- return this.event({ kind: kinds.Contacts, tags: pubkeys.map((p) => ["p", p]) });
22
- }
23
- list(tags = [], extra) {
24
- return this.event({
25
- kind: kinds.Bookmarksets,
26
- content: "",
27
- tags: [["d", String(Math.round(Math.random() * 10000))], ...tags],
28
- ...extra,
29
- });
30
- }
31
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import * as exports from "../index.js";
3
- describe("exports", () => {
4
- it("should export the expected functions", () => {
5
- expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
6
- [
7
- "CompleteSpend",
8
- "ConsolidateTokens",
9
- "CreateWallet",
10
- "ReceiveToken",
11
- "RolloverTokens",
12
- "UnlockWallet",
13
- "WalletAddPrivateKey",
14
- ]
15
- `);
16
- });
17
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,139 +0,0 @@
1
- import { describe, it, expect, beforeEach, vitest } from "vitest";
2
- import { EventStore } from "applesauce-core";
3
- import { EventFactory } from "applesauce-factory";
4
- import { ActionHub } from "applesauce-actions";
5
- import { CheckStateEnum } from "@cashu/cashu-ts";
6
- import { subscribeSpyTo } from "@hirez_io/observer-spy";
7
- import { FakeUser } from "../../__tests__/fake-user.js";
8
- import { ConsolidateTokens } from "../tokens.js";
9
- import { WalletTokenBlueprint } from "../../blueprints/tokens.js";
10
- import { unlockTokenContent, WALLET_TOKEN_KIND } from "../../helpers/tokens.js";
11
- // Update the mock to allow controlling the states
12
- const mockCheckProofsStates = vitest.fn();
13
- vitest.mock("@cashu/cashu-ts", () => ({
14
- CashuMint: vitest.fn(),
15
- CashuWallet: vitest.fn().mockImplementation(() => ({
16
- checkProofsStates: mockCheckProofsStates,
17
- })),
18
- CheckStateEnum: { UNSPENT: "UNSPENT", SPENT: "SPENT" },
19
- }));
20
- const user = new FakeUser();
21
- const testMint = "https://mint.test.com";
22
- let events;
23
- let factory;
24
- let hub;
25
- beforeEach(() => {
26
- events = new EventStore();
27
- factory = new EventFactory({ signer: user });
28
- hub = new ActionHub(events, factory);
29
- // Reset the mock before each test
30
- mockCheckProofsStates.mockReset();
31
- });
32
- describe("ConsolidateTokens", () => {
33
- it("should combine multiple token events into a single event", async () => {
34
- // Set all proofs to be unspent
35
- mockCheckProofsStates.mockResolvedValue([{ state: CheckStateEnum.UNSPENT }, { state: CheckStateEnum.UNSPENT }]);
36
- // Create two token events with different proofs
37
- const token1 = await factory.sign(await factory.create(WalletTokenBlueprint, {
38
- mint: testMint,
39
- proofs: [{ amount: 10, secret: "secret1", C: "C", id: "id" }],
40
- }));
41
- const token2 = await factory.sign(await factory.create(WalletTokenBlueprint, {
42
- mint: testMint,
43
- proofs: [{ amount: 20, secret: "secret2", C: "C", id: "id" }],
44
- }));
45
- // Add tokens to event store
46
- events.add(token1);
47
- events.add(token2);
48
- // Run consolidate action
49
- const spy = subscribeSpyTo(hub.exec(ConsolidateTokens));
50
- await spy.onComplete();
51
- // First event should be the new consolidated token
52
- expect(spy.getValueAt(0).kind).toBe(WALLET_TOKEN_KIND);
53
- // Extract token content and verify proofs were combined
54
- const content = await unlockTokenContent(spy.getValueAt(0), user);
55
- expect(content.proofs).toHaveLength(2);
56
- expect(content.proofs).toEqual(expect.arrayContaining([
57
- expect.objectContaining({ amount: 10, secret: "secret1" }),
58
- expect.objectContaining({ amount: 20, secret: "secret2" }),
59
- ]));
60
- expect(content.mint).toBe(testMint);
61
- });
62
- it("should handle duplicate proofs", async () => {
63
- // Set all proofs to be unspent
64
- mockCheckProofsStates.mockResolvedValue([{ state: CheckStateEnum.UNSPENT }, { state: CheckStateEnum.UNSPENT }]);
65
- // Create two token events with different proofs
66
- const token1 = await factory.sign(await factory.create(WalletTokenBlueprint, {
67
- mint: testMint,
68
- proofs: [{ amount: 10, secret: "secret1", C: "C", id: "id" }],
69
- }));
70
- const token2 = await factory.sign(await factory.create(WalletTokenBlueprint, {
71
- mint: testMint,
72
- proofs: [
73
- { amount: 20, secret: "secret2", C: "C", id: "id" },
74
- { amount: 10, secret: "secret1", C: "C", id: "id" },
75
- ],
76
- }));
77
- // Add tokens to event store
78
- events.add(token1);
79
- events.add(token2);
80
- // Run consolidate action
81
- const spy = subscribeSpyTo(hub.exec(ConsolidateTokens));
82
- await spy.onComplete();
83
- // First event should be the new consolidated token
84
- expect(spy.getValueAt(0).kind).toBe(WALLET_TOKEN_KIND);
85
- // Extract token content and verify proofs were combined
86
- const content = await unlockTokenContent(spy.getValueAt(0), user);
87
- expect(content.proofs).toHaveLength(2);
88
- expect(content.proofs).toEqual(expect.arrayContaining([
89
- expect.objectContaining({ amount: 10, secret: "secret1" }),
90
- expect.objectContaining({ amount: 20, secret: "secret2" }),
91
- ]));
92
- expect(content.mint).toBe(testMint);
93
- });
94
- it("should filter out spent proofs", async () => {
95
- // Create token events with multiple proofs
96
- const token1 = await factory.sign(await factory.create(WalletTokenBlueprint, {
97
- mint: testMint,
98
- proofs: [
99
- { amount: 10, secret: "secret1", C: "C", id: "id" },
100
- { amount: 20, secret: "secret2", C: "C", id: "id" },
101
- ],
102
- }, []));
103
- const token2 = await factory.sign(await factory.create(WalletTokenBlueprint, {
104
- mint: testMint,
105
- proofs: [
106
- { amount: 30, secret: "secret3", C: "C", id: "id" },
107
- { amount: 40, secret: "secret4", C: "C", id: "id" },
108
- ],
109
- }, []));
110
- // Add tokens to event store
111
- events.add(token1);
112
- events.add(token2);
113
- // Mock some proofs as spent
114
- mockCheckProofsStates.mockResolvedValue([
115
- { state: CheckStateEnum.UNSPENT }, // secret1
116
- { state: CheckStateEnum.SPENT }, // secret2
117
- { state: CheckStateEnum.SPENT }, // secret3
118
- { state: CheckStateEnum.UNSPENT }, // secret4
119
- ]);
120
- // Run consolidate action
121
- const spy = subscribeSpyTo(hub.exec(ConsolidateTokens));
122
- await spy.onComplete();
123
- // Verify the consolidated token only contains unspent proofs
124
- const content = await unlockTokenContent(spy.getValueAt(0), user);
125
- expect(content.proofs).toHaveLength(2);
126
- expect(content.proofs).toEqual(expect.arrayContaining([
127
- expect.objectContaining({ amount: 10, secret: "secret1" }),
128
- expect.objectContaining({ amount: 40, secret: "secret4" }),
129
- ]));
130
- expect(content.mint).toBe(testMint);
131
- // Verify checkProofsStates was called with all proofs
132
- expect(mockCheckProofsStates).toHaveBeenCalledWith(expect.arrayContaining([
133
- expect.objectContaining({ amount: 10, secret: "secret1" }),
134
- expect.objectContaining({ amount: 20, secret: "secret2" }),
135
- expect.objectContaining({ amount: 30, secret: "secret3" }),
136
- expect.objectContaining({ amount: 40, secret: "secret4" }),
137
- ]));
138
- });
139
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- import { describe, it, expect, beforeEach, vitest } from "vitest";
2
- import { unlockHiddenTags } from "applesauce-core/helpers";
3
- import { lastValueFrom } from "rxjs";
4
- import { generateSecretKey } from "nostr-tools";
5
- import { EventStore } from "applesauce-core";
6
- import { EventFactory } from "applesauce-factory";
7
- import { ActionHub } from "applesauce-actions";
8
- import { bytesToHex } from "@noble/hashes/utils";
9
- import { FakeUser } from "../../__tests__/fake-user.js";
10
- import { WalletAddPrivateKey, CreateWallet } from "../wallet.js";
11
- import { getWalletPrivateKey, unlockWallet, WALLET_BACKUP_KIND } from "../../helpers/wallet.js";
12
- import { WalletBlueprint } from "../../blueprints/wallet.js";
13
- const user = new FakeUser();
14
- let events;
15
- let factory;
16
- let publish;
17
- let hub;
18
- beforeEach(() => {
19
- events = new EventStore();
20
- factory = new EventFactory({ signer: user });
21
- publish = vitest.fn().mockResolvedValue(undefined);
22
- hub = new ActionHub(events, factory, publish);
23
- });
24
- describe("CreateWallet", () => {
25
- it("should publish a wallet backup event", async () => {
26
- await hub.run(CreateWallet, ["https://mint.money.com"]);
27
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({ kind: WALLET_BACKUP_KIND }));
28
- });
29
- it("should publish a wallet event with mints", async () => {
30
- const event = await lastValueFrom(hub.exec(CreateWallet, ["https://mint.money.com"]));
31
- const hiddenTags = await unlockHiddenTags(event, user);
32
- // the second call should be the wallet event
33
- expect(hiddenTags).toEqual(expect.arrayContaining([["mint", "https://mint.money.com"]]));
34
- });
35
- });
36
- describe("WalletAddPrivateKey", () => {
37
- it("should add a private key to an existing wallet event without a private key", async () => {
38
- const walletEvent = await factory.sign(await factory.create(WalletBlueprint, ["https://mint.money.com"]));
39
- await events.add(walletEvent);
40
- const privateKey = generateSecretKey();
41
- const updatedWallet = await lastValueFrom(hub.exec(WalletAddPrivateKey, privateKey));
42
- await unlockWallet(updatedWallet, user);
43
- const key = getWalletPrivateKey(updatedWallet);
44
- expect(key).toBeDefined();
45
- expect(bytesToHex(key)).toEqual(bytesToHex(privateKey));
46
- });
47
- it("should throw an error if a wallet event already has a private key", async () => {
48
- const walletEvent = await factory.sign(await factory.create(WalletBlueprint, ["https://mint.money.com"], generateSecretKey()));
49
- await events.add(walletEvent);
50
- await expect(hub.run(WalletAddPrivateKey, generateSecretKey())).rejects.toThrow("Wallet already has a private key");
51
- });
52
- it("should throw an error if the wallet event does not exist", async () => {
53
- const privateKey = generateSecretKey();
54
- await expect(hub.run(WalletAddPrivateKey, privateKey)).rejects.toThrow("Wallet does not exist");
55
- });
56
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import * as exports from "../index.js";
3
- describe("exports", () => {
4
- it("should export the expected functions", () => {
5
- expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
6
- [
7
- "WalletBackupBlueprint",
8
- "WalletBlueprint",
9
- "WalletTokenBlueprint",
10
- ]
11
- `);
12
- });
13
- });
@@ -1 +0,0 @@
1
- export {};