applesauce-wallet 0.0.0-next-20250312162115 → 0.0.0-next-20250312201602

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.
@@ -7,5 +7,7 @@ import { NostrEvent } from "nostr-tools";
7
7
  * @param redeemed an array of nutzap event ids to mark as redeemed
8
8
  */
9
9
  export declare function ReceiveToken(token: Token, redeemed?: string[]): Action;
10
+ /** An action that deletes old tokens and creates a new one but does not add a history event */
11
+ export declare function RolloverTokens(tokens: NostrEvent[], token: Token): Action;
10
12
  /** An action that deletes old token events and adds a spend history item */
11
13
  export declare function CompleteSpend(spent: NostrEvent[], change: Token): Action;
@@ -16,6 +16,21 @@ export function ReceiveToken(token, redeemed) {
16
16
  await publish("Save transaction", history);
17
17
  };
18
18
  }
19
+ /** An action that deletes old tokens and creates a new one but does not add a history event */
20
+ export function RolloverTokens(tokens, token) {
21
+ return async ({ factory, publish }) => {
22
+ // create a delete event for old tokens
23
+ const deleteDraft = await factory.create(DeleteBlueprint, tokens);
24
+ // create a new token event
25
+ const tokenDraft = await factory.create(WalletTokenBlueprint, token, tokens.map((e) => e.id));
26
+ // sign events
27
+ const signedDelete = await factory.sign(deleteDraft);
28
+ const signedToken = await factory.sign(tokenDraft);
29
+ // publish events
30
+ await publish("Delete old tokens", signedDelete);
31
+ await publish("Save new token", signedToken);
32
+ };
33
+ }
19
34
  /** An action that deletes old token events and adds a spend history item */
20
35
  export function CompleteSpend(spent, change) {
21
36
  return async ({ factory, publish }) => {
@@ -1,8 +1,8 @@
1
1
  import { generateSecretKey } from "nostr-tools";
2
2
  import { isWalletLocked, unlockWallet, WALLET_KIND } from "../helpers/wallet.js";
3
3
  import { WalletBackupBlueprint, WalletBlueprint } from "../blueprints/wallet.js";
4
- import { unlockTokenContent, WALLET_TOKEN_KIND } from "../helpers/tokens.js";
5
- import { unlockHistoryContent, WALLET_HISTORY_KIND } from "../helpers/history.js";
4
+ import { isTokenContentLocked, unlockTokenContent, WALLET_TOKEN_KIND } from "../helpers/tokens.js";
5
+ import { isHistoryContentLocked, unlockHistoryContent, WALLET_HISTORY_KIND } from "../helpers/history.js";
6
6
  /** An action that creates a new 17375 wallet event and 375 wallet backup */
7
7
  export function CreateWallet(mints, privateKey = generateSecretKey()) {
8
8
  return async ({ events, factory, self, publish }) => {
@@ -24,17 +24,19 @@ export function UnlockWallet(unlock) {
24
24
  const wallet = events.getReplaceable(WALLET_KIND, self);
25
25
  if (!wallet)
26
26
  throw new Error("Wallet does not exist");
27
- if (!isWalletLocked(wallet))
27
+ if (isWalletLocked(wallet))
28
28
  await unlockWallet(wallet, signer);
29
29
  if (unlock?.tokens) {
30
30
  const tokens = events.getTimeline({ kinds: [WALLET_TOKEN_KIND], authors: [self] });
31
31
  for (const token of tokens)
32
- await unlockTokenContent(token, signer);
32
+ if (isTokenContentLocked(token))
33
+ await unlockTokenContent(token, signer);
33
34
  }
34
35
  if (unlock?.history) {
35
36
  const history = events.getTimeline({ kinds: [WALLET_HISTORY_KIND], authors: [self] });
36
37
  for (const entry of history)
37
- await unlockHistoryContent(entry, signer);
38
+ if (isHistoryContentLocked(entry))
39
+ await unlockHistoryContent(entry, signer);
38
40
  }
39
41
  };
40
42
  }
@@ -3,6 +3,7 @@ import { EventFactory } from "applesauce-factory";
3
3
  import { FakeUser } from "../../__tests__/fake-user.js";
4
4
  import { WalletTokenBlueprint } from "../../blueprints/tokens.js";
5
5
  import { dumbTokenSelection, unlockTokenContent } from "../tokens.js";
6
+ import { HiddenContentSymbol } from "applesauce-core/helpers";
6
7
  const user = new FakeUser();
7
8
  const factory = new EventFactory({ signer: user });
8
9
  describe("dumbTokenSelection", () => {
@@ -49,6 +50,8 @@ describe("dumbTokenSelection", () => {
49
50
  mint: "https://money.com",
50
51
  proofs: [{ secret: "A", C: "A", id: "A", amount: 100 }],
51
52
  }));
53
+ // manually remove the hidden content to lock it again
54
+ Reflect.deleteProperty(a, HiddenContentSymbol);
52
55
  expect(() => dumbTokenSelection([a], 20)).toThrow();
53
56
  });
54
57
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20250312162115",
3
+ "version": "0.0.0-next-20250312201602",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -79,16 +79,16 @@
79
79
  "dependencies": {
80
80
  "@cashu/cashu-ts": "2.0.0-rc1",
81
81
  "@noble/hashes": "^1.7.1",
82
- "applesauce-actions": "0.0.0-next-20250312162115",
83
- "applesauce-core": "0.0.0-next-20250312162115",
84
- "applesauce-factory": "0.0.0-next-20250312162115",
82
+ "applesauce-actions": "0.0.0-next-20250312201602",
83
+ "applesauce-core": "0.0.0-next-20250312201602",
84
+ "applesauce-factory": "0.0.0-next-20250312201602",
85
85
  "nostr-tools": "^2.10.4",
86
86
  "rxjs": "^7.8.1"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@hirez_io/observer-spy": "^2.2.0",
90
90
  "@types/debug": "^4.1.12",
91
- "applesauce-signers": "0.0.0-next-20250312162115",
91
+ "applesauce-signers": "0.0.0-next-20250312201602",
92
92
  "typescript": "^5.7.3",
93
93
  "vitest": "^3.0.5"
94
94
  },