applesauce-wallet 0.0.0-next-20250311175838 → 0.0.0-next-20250312111321

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.
@@ -0,0 +1,5 @@
1
+ import { EventPointer } from "nostr-tools/nip19";
2
+ import { HistoryContent } from "../helpers/history.js";
3
+ import { EventBlueprint } from "applesauce-factory";
4
+ /** A blueprint that creates a wallet history event */
5
+ export declare function WalletHistoryBlueprint(content: HistoryContent, redeemed: (string | EventPointer)[]): EventBlueprint;
@@ -0,0 +1,11 @@
1
+ import { WALLET_HISTORY_KIND } from "../helpers/history.js";
2
+ import { EventFactory } from "applesauce-factory";
3
+ import { setHistoryContent, setHistoryRedeemed } from "../operations/event/history.js";
4
+ /** A blueprint that creates a wallet history event */
5
+ export function WalletHistoryBlueprint(content, redeemed) {
6
+ return (ctx) => EventFactory.runProcess({ kind: WALLET_HISTORY_KIND }, ctx,
7
+ // set the encrypted tags on the event
8
+ setHistoryContent(content),
9
+ // set the public redeemed tags
10
+ setHistoryRedeemed(redeemed));
11
+ }
@@ -1 +1,2 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./tokens.js";
@@ -1 +1,2 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./tokens.js";
@@ -0,0 +1,8 @@
1
+ import { Token } from "@cashu/cashu-ts";
2
+ import { EventBlueprint } from "applesauce-factory";
3
+ /**
4
+ * A blueprint for a wallet token event, takes a cashu token and previous deleted token event ids
5
+ * @param token the cashu token to store
6
+ * @param [del=[]] an array of previous token event ids that are deleted
7
+ */
8
+ export declare function WalletTokenBlueprint(token: Token, del?: string[]): EventBlueprint;
@@ -0,0 +1,11 @@
1
+ import { EventFactory } from "applesauce-factory";
2
+ import { WALLET_TOKEN_KIND } from "../helpers/tokens.js";
3
+ import { setTokenContent } from "../operations/event/tokens.js";
4
+ /**
5
+ * A blueprint for a wallet token event, takes a cashu token and previous deleted token event ids
6
+ * @param token the cashu token to store
7
+ * @param [del=[]] an array of previous token event ids that are deleted
8
+ */
9
+ export function WalletTokenBlueprint(token, del = []) {
10
+ return (ctx) => EventFactory.runProcess({ kind: WALLET_TOKEN_KIND }, ctx, setTokenContent(token, del));
11
+ }
@@ -1,9 +1,10 @@
1
1
  import { HiddenContentSigner } from "applesauce-core/helpers";
2
2
  import { NostrEvent } from "nostr-tools";
3
3
  export declare const WALLET_HISTORY_KIND = 7376;
4
+ export type HistoryDirection = "in" | "out";
4
5
  export type HistoryContent = {
5
6
  /** The direction of the transaction, in = received, out = sent */
6
- direction: "in" | "out";
7
+ direction: HistoryDirection;
7
8
  /** The amount of the transaction */
8
9
  amount: number;
9
10
  /** An array of token event ids created */
@@ -11,6 +11,8 @@ export type TokenContent = {
11
11
  C: string;
12
12
  id: string;
13
13
  }[];
14
+ /** The cashu unit */
15
+ unit?: string;
14
16
  /** tokens that were destroyed in the creation of this token (helps on wallet state transitions) */
15
17
  del: string[];
16
18
  };
@@ -11,7 +11,7 @@ export function getTokenContent(token) {
11
11
  if (!details.mint)
12
12
  throw new Error("Token missing mint");
13
13
  if (!details.proofs)
14
- details.proofs = [];
14
+ throw new Error("Token missing proofs");
15
15
  if (!details.del)
16
16
  details.del = [];
17
17
  return details;
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-factory";
2
+ import { HistoryContent } from "../../helpers/history.js";
3
+ import { EventPointer } from "nostr-tools/nip19";
4
+ /** Sets the encrypted tags of a wallet history event */
5
+ export declare function setHistoryContent(content: HistoryContent): EventOperation;
6
+ /** Sets the "redeemed" tags on a wallet history event */
7
+ export declare function setHistoryRedeemed(redeemed: (string | EventPointer)[]): EventOperation;
@@ -0,0 +1,19 @@
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 +1,3 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./tokens.js";
3
+ export * from "./history.js";
@@ -1 +1,3 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./tokens.js";
3
+ export * from "./history.js";
@@ -0,0 +1,4 @@
1
+ import { Token } from "@cashu/cashu-ts";
2
+ import { EventOperation } from "applesauce-factory";
3
+ /** Sets the content of a 7375 token event */
4
+ export declare function setTokenContent(token: Token, del?: string[]): EventOperation;
@@ -0,0 +1,20 @@
1
+ import { EventContentEncryptionMethod } from "applesauce-core/helpers";
2
+ import { setEncryptedContent } from "applesauce-factory/operations/event";
3
+ /** Sets the content of a 7375 token event */
4
+ export function setTokenContent(token, del = []) {
5
+ return async (draft, ctx) => {
6
+ if (!ctx.signer)
7
+ throw new Error(`Missing signer`);
8
+ const pubkey = await ctx.signer.getPublicKey();
9
+ const method = EventContentEncryptionMethod[draft.kind];
10
+ if (!method)
11
+ throw new Error("Failed to find encryption method");
12
+ const content = {
13
+ mint: token.mint,
14
+ proofs: token.proofs,
15
+ unit: token.unit,
16
+ del,
17
+ };
18
+ return await setEncryptedContent(pubkey, JSON.stringify(content), method)(draft, ctx);
19
+ };
20
+ }
@@ -0,0 +1,14 @@
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;
@@ -0,0 +1,34 @@
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 +1,2 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./history.js";
@@ -1 +1,2 @@
1
1
  export * from "./wallet.js";
2
+ export * from "./history.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20250311175838",
3
+ "version": "0.0.0-next-20250312111321",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -77,17 +77,18 @@
77
77
  }
78
78
  },
79
79
  "dependencies": {
80
+ "@cashu/cashu-ts": "2.0.0-rc1",
80
81
  "@noble/hashes": "^1.7.1",
81
- "applesauce-actions": "0.0.0-next-20250311175838",
82
- "applesauce-core": "0.0.0-next-20250311175838",
83
- "applesauce-factory": "0.0.0-next-20250311175838",
82
+ "applesauce-actions": "0.0.0-next-20250312111321",
83
+ "applesauce-core": "0.0.0-next-20250312111321",
84
+ "applesauce-factory": "0.0.0-next-20250312111321",
84
85
  "nostr-tools": "^2.10.4",
85
86
  "rxjs": "^7.8.1"
86
87
  },
87
88
  "devDependencies": {
88
89
  "@hirez_io/observer-spy": "^2.2.0",
89
90
  "@types/debug": "^4.1.12",
90
- "applesauce-signers": "0.0.0-next-20250311175838",
91
+ "applesauce-signers": "0.0.0-next-20250312111321",
91
92
  "typescript": "^5.7.3",
92
93
  "vitest": "^3.0.5"
93
94
  },