applesauce-wallet 0.0.0-next-20251209200210 → 0.0.0-next-20251220152312

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/common.d.ts +4 -0
  2. package/dist/actions/common.js +15 -0
  3. package/dist/actions/index.d.ts +2 -2
  4. package/dist/actions/index.js +2 -2
  5. package/dist/actions/{zap-info.d.ts → nutzap-info.d.ts} +20 -3
  6. package/dist/actions/nutzap-info.js +117 -0
  7. package/dist/actions/nutzaps.d.ts +24 -0
  8. package/dist/actions/nutzaps.js +154 -0
  9. package/dist/actions/tokens.d.ts +77 -7
  10. package/dist/actions/tokens.js +332 -69
  11. package/dist/actions/wallet.d.ts +18 -3
  12. package/dist/actions/wallet.js +74 -32
  13. package/dist/blueprints/history.d.ts +1 -1
  14. package/dist/blueprints/history.js +1 -1
  15. package/dist/blueprints/wallet.d.ts +5 -1
  16. package/dist/blueprints/wallet.js +6 -3
  17. package/dist/casts/__register__.d.ts +20 -0
  18. package/dist/casts/__register__.js +41 -0
  19. package/dist/casts/index.d.ts +6 -0
  20. package/dist/casts/index.js +6 -0
  21. package/dist/casts/nutzap-info.d.ts +14 -0
  22. package/dist/casts/nutzap-info.js +22 -0
  23. package/dist/casts/nutzap.d.ts +16 -0
  24. package/dist/casts/nutzap.js +37 -0
  25. package/dist/casts/wallet-history.d.ts +16 -0
  26. package/dist/casts/wallet-history.js +40 -0
  27. package/dist/casts/wallet-token.d.ts +29 -0
  28. package/dist/casts/wallet-token.js +52 -0
  29. package/dist/casts/wallet.d.ts +27 -0
  30. package/dist/casts/wallet.js +62 -0
  31. package/dist/helpers/cashu.d.ts +21 -0
  32. package/dist/helpers/cashu.js +105 -0
  33. package/dist/helpers/couch.d.ts +11 -0
  34. package/dist/helpers/couch.js +1 -0
  35. package/dist/helpers/history.d.ts +5 -1
  36. package/dist/helpers/history.js +13 -4
  37. package/dist/helpers/index.d.ts +5 -1
  38. package/dist/helpers/index.js +5 -1
  39. package/dist/helpers/indexed-db-couch.d.ts +34 -0
  40. package/dist/helpers/indexed-db-couch.js +119 -0
  41. package/dist/helpers/local-storage-couch.d.ts +29 -0
  42. package/dist/helpers/local-storage-couch.js +78 -0
  43. package/dist/helpers/{zap-info.d.ts → nutzap-info.d.ts} +10 -1
  44. package/dist/helpers/{zap-info.js → nutzap-info.js} +22 -10
  45. package/dist/helpers/nutzap.d.ts +15 -0
  46. package/dist/helpers/nutzap.js +57 -3
  47. package/dist/helpers/tokens.d.ts +9 -18
  48. package/dist/helpers/tokens.js +64 -94
  49. package/dist/helpers/wallet.d.ts +16 -6
  50. package/dist/helpers/wallet.js +40 -14
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/models/history.d.ts +1 -1
  54. package/dist/models/history.js +7 -10
  55. package/dist/models/index.d.ts +0 -1
  56. package/dist/models/index.js +0 -1
  57. package/dist/models/nutzap.d.ts +2 -0
  58. package/dist/models/nutzap.js +8 -0
  59. package/dist/models/tokens.d.ts +2 -2
  60. package/dist/models/tokens.js +14 -17
  61. package/dist/operations/history.js +1 -1
  62. package/dist/operations/index.d.ts +1 -1
  63. package/dist/operations/index.js +1 -1
  64. package/dist/operations/nutzap-info.d.ts +21 -0
  65. package/dist/operations/nutzap-info.js +71 -0
  66. package/dist/operations/wallet.d.ts +10 -1
  67. package/dist/operations/wallet.js +33 -3
  68. package/package.json +15 -6
  69. package/dist/actions/zap-info.js +0 -83
  70. package/dist/actions/zaps.d.ts +0 -8
  71. package/dist/actions/zaps.js +0 -30
  72. package/dist/models/wallet.d.ts +0 -13
  73. package/dist/models/wallet.js +0 -21
  74. package/dist/operations/zap-info.d.ts +0 -10
  75. package/dist/operations/zap-info.js +0 -17
@@ -1,5 +1,7 @@
1
1
  import { bytesToHex } from "applesauce-core/helpers/event";
2
+ import { normalizeURL } from "applesauce-core/helpers/url";
2
3
  import { setSingletonTag } from "applesauce-core/operations/tag/common";
4
+ import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
3
5
  import { modifyHiddenTags } from "applesauce-core/operations/tags";
4
6
  import { WALLET_KIND } from "../helpers/wallet.js";
5
7
  /** Sets the content of a kind 375 wallet backup event */
@@ -16,15 +18,43 @@ export function setBackupContent(wallet) {
16
18
  };
17
19
  }
18
20
  /** Sets the "mint" tags in a wallet event */
19
- export function setMints(mints) {
20
- return modifyHiddenTags((tags) => [
21
+ export function setMintTags(mints) {
22
+ return (tags) => [
21
23
  // remove all existing mint tags
22
24
  ...tags.filter((t) => t[0] !== "mint"),
23
25
  // add new mint tags
24
26
  ...mints.map((mint) => ["mint", mint]),
25
- ]);
27
+ ];
28
+ }
29
+ export function setMints(mints) {
30
+ return modifyHiddenTags(setMintTags(mints));
26
31
  }
27
32
  /** Sets the "privkey" tag on a wallet event */
33
+ export function setPrivateKeyTag(privateKey) {
34
+ return setSingletonTag(["privkey", bytesToHex(privateKey)]);
35
+ }
28
36
  export function setPrivateKey(privateKey) {
29
37
  return modifyHiddenTags(setSingletonTag(["privkey", bytesToHex(privateKey)], true));
30
38
  }
39
+ /** Adds a relay tag to a wallet event */
40
+ export function addWalletRelay(url) {
41
+ url = normalizeURL(url).toString();
42
+ return modifyHiddenTags(addRelayTag(url, "relay", true));
43
+ }
44
+ /** Removes a relay tag from a wallet event */
45
+ export function removeWalletRelay(url) {
46
+ url = normalizeURL(url).toString();
47
+ return modifyHiddenTags(removeRelayTag(url, "relay"));
48
+ }
49
+ /** Sets the relay tags on a wallet event, replacing all existing relay tags */
50
+ export function setRelayTags(relays) {
51
+ return (tags) => [
52
+ // remove all existing relay tags
53
+ ...tags.filter((t) => t[0] !== "relay"),
54
+ // add new relay tags
55
+ ...relays.map((relay) => ["relay", normalizeURL(relay).toString()]),
56
+ ];
57
+ }
58
+ export function setRelays(relays) {
59
+ return modifyHiddenTags(setRelayTags(relays));
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-wallet",
3
- "version": "0.0.0-next-20251209200210",
3
+ "version": "0.0.0-next-20251220152312",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,6 +40,16 @@
40
40
  "require": "./dist/models/*.js",
41
41
  "types": "./dist/models/*.d.ts"
42
42
  },
43
+ "./casts": {
44
+ "import": "./dist/casts/index.js",
45
+ "require": "./dist/casts/index.js",
46
+ "types": "./dist/casts/index.d.ts"
47
+ },
48
+ "./casts/*": {
49
+ "import": "./dist/casts/*.js",
50
+ "require": "./dist/casts/*.js",
51
+ "types": "./dist/casts/*.d.ts"
52
+ },
43
53
  "./blueprints": {
44
54
  "import": "./dist/blueprints/index.js",
45
55
  "require": "./dist/blueprints/index.js",
@@ -74,16 +84,15 @@
74
84
  "dependencies": {
75
85
  "@cashu/cashu-ts": "^3.1.1",
76
86
  "@gandlaf21/bc-ur": "^1.1.12",
77
- "@noble/hashes": "^1.7.1",
78
- "applesauce-actions": "0.0.0-next-20251209200210",
79
- "applesauce-common": "0.0.0-next-20251209200210",
80
- "applesauce-core": "0.0.0-next-20251209200210",
87
+ "applesauce-actions": "0.0.0-next-20251220152312",
88
+ "applesauce-common": "0.0.0-next-20251220152312",
89
+ "applesauce-core": "0.0.0-next-20251220152312",
81
90
  "rxjs": "^7.8.1"
82
91
  },
83
92
  "devDependencies": {
84
93
  "@hirez_io/observer-spy": "^2.2.0",
85
94
  "@types/debug": "^4.1.12",
86
- "applesauce-signers": "0.0.0-next-20251209200210",
95
+ "applesauce-signers": "0.0.0-next-20251220152312",
87
96
  "rimraf": "^6.0.1",
88
97
  "typescript": "^5.8.3",
89
98
  "vitest": "^4.0.15"
@@ -1,83 +0,0 @@
1
- import { modifyPublicTags } from "applesauce-core/operations/tags";
2
- import { addNameValueTag, removeNameValueTag, setSingletonTag } from "applesauce-core/operations/tag/common";
3
- import { NUTZAP_INFO_KIND } from "../helpers/zap-info.js";
4
- import { setNutzapInfoMints, setNutzapInfoPubkey, setNutzapInfoRelays } from "../operations/zap-info.js";
5
- /** An action to add a relay to the kind 10019 nutzap info event */
6
- export function AddNutzapInfoRelay(relay) {
7
- return async function* ({ events, factory, self }) {
8
- if (typeof relay === "string")
9
- relay = [relay];
10
- const operations = relay.map((r) => addNameValueTag(["relay", r], false));
11
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
12
- const draft = nutzapInfo
13
- ? await factory.modifyTags(nutzapInfo, ...operations)
14
- : await factory.build({ kind: NUTZAP_INFO_KIND }, modifyPublicTags(...operations));
15
- const signed = await factory.sign(draft);
16
- yield signed;
17
- };
18
- }
19
- /** An action to remove a relay from the kind 10019 nutzap info event */
20
- export function RemoveNutzapInfoRelay(relay) {
21
- return async function* ({ events, factory, self }) {
22
- if (typeof relay === "string")
23
- relay = [relay];
24
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
25
- if (!nutzapInfo)
26
- return;
27
- const draft = await factory.modifyTags(nutzapInfo, ...relay.map((r) => removeNameValueTag(["relay", r])));
28
- const signed = await factory.sign(draft);
29
- yield signed;
30
- };
31
- }
32
- /** An action to add a mint to the kind 10019 nutzap info event */
33
- export function AddNutzapInfoMint(mint) {
34
- return async function* ({ events, factory, self }) {
35
- const mints = Array.isArray(mint) ? mint : [mint];
36
- const operations = mints.map((m) => {
37
- const tag = m.units ? ["mint", m.url, ...m.units] : ["mint", m.url];
38
- return addNameValueTag(tag, false);
39
- });
40
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
41
- const draft = nutzapInfo
42
- ? await factory.modifyTags(nutzapInfo, ...operations)
43
- : await factory.build({ kind: NUTZAP_INFO_KIND }, modifyPublicTags(...operations));
44
- const signed = await factory.sign(draft);
45
- yield signed;
46
- };
47
- }
48
- /** An action to remove a mint from the kind 10019 nutzap info event */
49
- export function RemoveNutzapInfoMint(mint) {
50
- return async function* ({ events, factory, self }) {
51
- if (typeof mint === "string")
52
- mint = [mint];
53
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
54
- if (!nutzapInfo)
55
- return;
56
- const draft = await factory.modifyTags(nutzapInfo, ...mint.map((m) => removeNameValueTag(["mint", m])));
57
- const signed = await factory.sign(draft);
58
- yield signed;
59
- };
60
- }
61
- /** An action to set the pubkey for the kind 10019 nutzap info event */
62
- export function SetNutzapInfoPubkey(pubkey) {
63
- return async function* ({ events, factory, self }) {
64
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
65
- const draft = nutzapInfo
66
- ? await factory.modifyTags(nutzapInfo, setSingletonTag(["pubkey", pubkey], true))
67
- : await factory.build({ kind: NUTZAP_INFO_KIND }, modifyPublicTags(setSingletonTag(["pubkey", pubkey], true)));
68
- const signed = await factory.sign(draft);
69
- yield signed;
70
- };
71
- }
72
- /** An action to update the entire nutzap info event */
73
- export function UpdateNutzapInfo(relays, mints, pubkey) {
74
- return async function* ({ events, factory, self }) {
75
- const operations = [setNutzapInfoRelays(relays), setNutzapInfoMints(mints), setNutzapInfoPubkey(pubkey)];
76
- const nutzapInfo = events.getReplaceable(NUTZAP_INFO_KIND, self);
77
- const draft = nutzapInfo
78
- ? await factory.modify(nutzapInfo, ...operations)
79
- : await factory.build({ kind: NUTZAP_INFO_KIND }, ...operations);
80
- const signed = await factory.sign(draft);
81
- yield signed;
82
- };
83
- }
@@ -1,8 +0,0 @@
1
- import { Token } from "@cashu/cashu-ts";
2
- import { Action } from "applesauce-actions";
3
- import { NostrEvent } from "applesauce-core/helpers/event";
4
- import { ProfilePointer } from "applesauce-core/helpers/pointers";
5
- /** Creates a NIP-61 nutzap event for an event with a token */
6
- export declare function NutzapEvent(event: NostrEvent, token: Token, comment?: string): Action;
7
- /** Creates a NIP-61 nutzap event to a users profile */
8
- export declare function NutzapProfile(user: string | ProfilePointer, token: Token, comment?: string): Action;
@@ -1,30 +0,0 @@
1
- import { NutzapBlueprint, ProfileNutzapBlueprint } from "../blueprints/zaps.js";
2
- import { NUTZAP_INFO_KIND, verifyProofsLocked } from "../helpers/zap-info.js";
3
- /** Creates a NIP-61 nutzap event for an event with a token */
4
- export function NutzapEvent(event, token, comment) {
5
- return async function* ({ events, factory }) {
6
- const recipient = event.pubkey;
7
- const info = events.getReplaceable(NUTZAP_INFO_KIND, recipient);
8
- if (!info)
9
- throw new Error("Nutzap info not found");
10
- // Verify all tokens are p2pk locked
11
- verifyProofsLocked(token.proofs, info);
12
- // NOTE: Disabled because mints and units should be checked by the app before
13
- // const mints = getNutzapInfoMints(info);
14
- // if (!mints.some((m) => m.mint === token.mint)) throw new Error("Token mint not found in nutzap info");
15
- const nutzap = await factory.sign(await factory.create(NutzapBlueprint, event, token, comment || token.memo));
16
- yield nutzap;
17
- };
18
- }
19
- /** Creates a NIP-61 nutzap event to a users profile */
20
- export function NutzapProfile(user, token, comment) {
21
- return async function* ({ events, factory }) {
22
- const info = events.getReplaceable(NUTZAP_INFO_KIND, typeof user === "string" ? user : user.pubkey);
23
- if (!info)
24
- throw new Error("Nutzap info not found");
25
- // Verify all tokens are p2pk locked
26
- verifyProofsLocked(token.proofs, info);
27
- const nutzap = await factory.sign(await factory.create(ProfileNutzapBlueprint, user, token, comment || token.memo));
28
- yield nutzap;
29
- };
30
- }
@@ -1,13 +0,0 @@
1
- import { Model } from "applesauce-core";
2
- import { NostrEvent } from "applesauce-core/helpers/event";
3
- export type WalletInfo = {
4
- locked: true;
5
- event: NostrEvent;
6
- } | {
7
- locked: false;
8
- event: NostrEvent;
9
- privateKey?: Uint8Array;
10
- mints: string[];
11
- };
12
- /** A model to get the state of a NIP-60 wallet */
13
- export declare function WalletModel(pubkey: string): Model<WalletInfo | undefined>;
@@ -1,21 +0,0 @@
1
- import { filter, map, merge } from "rxjs";
2
- import { getWalletMints, getWalletPrivateKey, isWalletUnlocked, WALLET_KIND } from "../helpers/wallet.js";
3
- /** A model to get the state of a NIP-60 wallet */
4
- export function WalletModel(pubkey) {
5
- return (events) => merge(
6
- // get the latest replaceable event
7
- events.replaceable(WALLET_KIND, pubkey),
8
- // and listen for any updates to matching events
9
- events.update$.pipe(filter((e) => e.kind === WALLET_KIND && e.pubkey === pubkey))).pipe(map((wallet) => {
10
- if (!wallet)
11
- return;
12
- if (isWalletUnlocked(wallet)) {
13
- const mints = getWalletMints(wallet);
14
- const privateKey = getWalletPrivateKey(wallet);
15
- return { locked: false, mints, privateKey, event: wallet };
16
- }
17
- else {
18
- return { locked: true, event: wallet };
19
- }
20
- }));
21
- }
@@ -1,10 +0,0 @@
1
- import { EventOperation } from "applesauce-core";
2
- /** Sets the relays for a nutzap info event */
3
- export declare function setNutzapInfoRelays(relays: string[]): EventOperation;
4
- /** Sets the mints for a nutzap info event */
5
- export declare function setNutzapInfoMints(mints: Array<{
6
- url: string;
7
- units?: string[];
8
- }>): EventOperation;
9
- /** Sets the pubkey for a nutzap info event */
10
- export declare function setNutzapInfoPubkey(pubkey: string): EventOperation;
@@ -1,17 +0,0 @@
1
- import { modifyPublicTags } from "applesauce-core/operations";
2
- import { addNameValueTag, setSingletonTag } from "applesauce-core/operations/tag/common";
3
- /** Sets the relays for a nutzap info event */
4
- export function setNutzapInfoRelays(relays) {
5
- return modifyPublicTags(...relays.map((relay) => addNameValueTag(["relay", relay], false)));
6
- }
7
- /** Sets the mints for a nutzap info event */
8
- export function setNutzapInfoMints(mints) {
9
- return modifyPublicTags(...mints.map((mint) => {
10
- const tag = mint.units ? ["mint", mint.url, ...mint.units] : ["mint", mint.url];
11
- return addNameValueTag(tag, false);
12
- }));
13
- }
14
- /** Sets the pubkey for a nutzap info event */
15
- export function setNutzapInfoPubkey(pubkey) {
16
- return modifyPublicTags(setSingletonTag(["pubkey", pubkey], true));
17
- }