applesauce-wallet 0.0.0-next-20250312111321 → 0.0.0-next-20250312152821

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 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { setWalletBackupContent } from "../wallet.js";
3
+ import { FakeUser } from "../../__tests__/fake-user.js";
4
+ import { EventFactory } from "applesauce-factory";
5
+ import { WalletBlueprint } from "../../blueprints/wallet.js";
6
+ import { generateSecretKey } from "nostr-tools";
7
+ import { WALLET_BACKUP_KIND } from "../../helpers/wallet.js";
8
+ import { unixNow } from "applesauce-core/helpers";
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
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
+ });
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
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
+ });
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
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 { 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
+ events.add(wallet);
22
+ const spy = subscribeSpyTo(queries.createQuery(WalletQuery, await user.getPublicKey()));
23
+ await unlockWallet(wallet, user);
24
+ expect(spy.getValues()).toEqual([
25
+ expect.objectContaining({ locked: true }),
26
+ expect.objectContaining({ locked: false }),
27
+ ]);
28
+ });
29
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20250312111321",
3
+ "version": "0.0.0-next-20250312152821",
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-20250312111321",
83
- "applesauce-core": "0.0.0-next-20250312111321",
84
- "applesauce-factory": "0.0.0-next-20250312111321",
82
+ "applesauce-actions": "0.0.0-next-20250312152821",
83
+ "applesauce-core": "0.0.0-next-20250312152821",
84
+ "applesauce-factory": "0.0.0-next-20250312152821",
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-20250312111321",
91
+ "applesauce-signers": "0.0.0-next-20250312152821",
92
92
  "typescript": "^5.7.3",
93
93
  "vitest": "^3.0.5"
94
94
  },