applesauce-wallet 0.0.0-next-20251209200210 → 0.0.0-next-20251231055351

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 (91) 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 +3 -2
  4. package/dist/actions/index.js +3 -2
  5. package/dist/actions/mint-recomendation.d.ts +30 -0
  6. package/dist/actions/mint-recomendation.js +96 -0
  7. package/dist/actions/{zap-info.d.ts → nutzap-info.d.ts} +20 -3
  8. package/dist/actions/nutzap-info.js +117 -0
  9. package/dist/actions/nutzaps.d.ts +24 -0
  10. package/dist/actions/nutzaps.js +154 -0
  11. package/dist/actions/tokens.d.ts +77 -7
  12. package/dist/actions/tokens.js +332 -69
  13. package/dist/actions/wallet.d.ts +18 -3
  14. package/dist/actions/wallet.js +74 -32
  15. package/dist/blueprints/history.d.ts +1 -1
  16. package/dist/blueprints/history.js +1 -1
  17. package/dist/blueprints/index.d.ts +1 -0
  18. package/dist/blueprints/index.js +1 -0
  19. package/dist/blueprints/mint-recommendation.d.ts +16 -0
  20. package/dist/blueprints/mint-recommendation.js +11 -0
  21. package/dist/blueprints/wallet.d.ts +5 -1
  22. package/dist/blueprints/wallet.js +6 -3
  23. package/dist/casts/__register__.d.ts +22 -0
  24. package/dist/casts/__register__.js +52 -0
  25. package/dist/casts/index.d.ts +8 -0
  26. package/dist/casts/index.js +8 -0
  27. package/dist/casts/mint-info.d.ts +18 -0
  28. package/dist/casts/mint-info.js +42 -0
  29. package/dist/casts/mint-recommendation.d.ts +16 -0
  30. package/dist/casts/mint-recommendation.js +29 -0
  31. package/dist/casts/nutzap-info.d.ts +14 -0
  32. package/dist/casts/nutzap-info.js +22 -0
  33. package/dist/casts/nutzap.d.ts +16 -0
  34. package/dist/casts/nutzap.js +37 -0
  35. package/dist/casts/wallet-history.d.ts +16 -0
  36. package/dist/casts/wallet-history.js +40 -0
  37. package/dist/casts/wallet-token.d.ts +29 -0
  38. package/dist/casts/wallet-token.js +52 -0
  39. package/dist/casts/wallet.d.ts +27 -0
  40. package/dist/casts/wallet.js +62 -0
  41. package/dist/helpers/cashu.d.ts +21 -0
  42. package/dist/helpers/cashu.js +105 -0
  43. package/dist/helpers/couch.d.ts +11 -0
  44. package/dist/helpers/couch.js +1 -0
  45. package/dist/helpers/history.d.ts +5 -1
  46. package/dist/helpers/history.js +13 -4
  47. package/dist/helpers/index.d.ts +7 -1
  48. package/dist/helpers/index.js +7 -1
  49. package/dist/helpers/indexed-db-couch.d.ts +34 -0
  50. package/dist/helpers/indexed-db-couch.js +119 -0
  51. package/dist/helpers/local-storage-couch.d.ts +29 -0
  52. package/dist/helpers/local-storage-couch.js +78 -0
  53. package/dist/helpers/mint-info.d.ts +40 -0
  54. package/dist/helpers/mint-info.js +80 -0
  55. package/dist/helpers/mint-recommendation.d.ts +41 -0
  56. package/dist/helpers/mint-recommendation.js +54 -0
  57. package/dist/helpers/{zap-info.d.ts → nutzap-info.d.ts} +10 -1
  58. package/dist/helpers/{zap-info.js → nutzap-info.js} +22 -10
  59. package/dist/helpers/nutzap.d.ts +15 -0
  60. package/dist/helpers/nutzap.js +57 -3
  61. package/dist/helpers/tokens.d.ts +9 -18
  62. package/dist/helpers/tokens.js +64 -94
  63. package/dist/helpers/wallet.d.ts +16 -6
  64. package/dist/helpers/wallet.js +40 -14
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.js +1 -0
  67. package/dist/models/history.d.ts +1 -1
  68. package/dist/models/history.js +7 -10
  69. package/dist/models/index.d.ts +0 -1
  70. package/dist/models/index.js +0 -1
  71. package/dist/models/nutzap.d.ts +2 -0
  72. package/dist/models/nutzap.js +8 -0
  73. package/dist/models/tokens.d.ts +2 -2
  74. package/dist/models/tokens.js +14 -17
  75. package/dist/operations/history.js +1 -1
  76. package/dist/operations/index.d.ts +2 -1
  77. package/dist/operations/index.js +2 -1
  78. package/dist/operations/mint-recommendation.d.ts +13 -0
  79. package/dist/operations/mint-recommendation.js +26 -0
  80. package/dist/operations/nutzap-info.d.ts +21 -0
  81. package/dist/operations/nutzap-info.js +71 -0
  82. package/dist/operations/wallet.d.ts +10 -1
  83. package/dist/operations/wallet.js +33 -3
  84. package/package.json +37 -28
  85. package/dist/actions/zap-info.js +0 -83
  86. package/dist/actions/zaps.d.ts +0 -8
  87. package/dist/actions/zaps.js +0 -30
  88. package/dist/models/wallet.d.ts +0 -13
  89. package/dist/models/wallet.js +0 -21
  90. package/dist/operations/zap-info.d.ts +0 -10
  91. package/dist/operations/zap-info.js +0 -17
@@ -0,0 +1,16 @@
1
+ import { EventBlueprint } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ /** Options for creating a mint recommendation */
5
+ export type MintRecommendationOptions = {
6
+ /** The mint's pubkey (from the kind:38172 event's `d` tag) - required */
7
+ mintPubkey: string;
8
+ /** Optional URL to connect to the cashu mint */
9
+ url?: string;
10
+ /** Optional address pointer to the kind:38172 event */
11
+ addressPointer?: AddressPointer | NostrEvent | string;
12
+ /** Optional review/comment content */
13
+ comment?: string;
14
+ };
15
+ /** A blueprint to create a kind:38000 mint recommendation event */
16
+ export declare function MintRecommendationBlueprint(options: MintRecommendationOptions): EventBlueprint;
@@ -0,0 +1,11 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { skip } from "applesauce-core/helpers";
3
+ import { MINT_RECOMMENDATION_KIND } from "../helpers/mint-recommendation.js";
4
+ import { CASHU_MINT_INFO_KIND } from "../helpers/mint-info.js";
5
+ import { setAddressPointer, setComment, setKind, setMintPubkey, setURL } from "../operations/mint-recommendation.js";
6
+ /** A blueprint to create a kind:38000 mint recommendation event */
7
+ export function MintRecommendationBlueprint(options) {
8
+ const { mintPubkey, url, addressPointer, comment } = options;
9
+ return blueprint(MINT_RECOMMENDATION_KIND, setKind(CASHU_MINT_INFO_KIND), // Always 38172 for cashu mints
10
+ setMintPubkey(mintPubkey), url ? setURL(url) : skip(), addressPointer ? setAddressPointer(addressPointer) : skip(), comment ? setComment(comment) : skip());
11
+ }
@@ -1,5 +1,9 @@
1
1
  import { NostrEvent } from "applesauce-core/helpers/event";
2
2
  /** A blueprint to create a new 17375 wallet */
3
- export declare function WalletBlueprint(mints: string[], privateKey?: Uint8Array): import("applesauce-core").EventBlueprint;
3
+ export declare function WalletBlueprint({ mints, privateKey, relays, }: {
4
+ mints: string[];
5
+ privateKey?: Uint8Array;
6
+ relays?: string[];
7
+ }): import("applesauce-core").EventBlueprint;
4
8
  /** A blueprint that creates a new 375 wallet backup event */
5
9
  export declare function WalletBackupBlueprint(wallet: NostrEvent): import("applesauce-core").EventBlueprint;
@@ -1,9 +1,12 @@
1
1
  import { blueprint } from "applesauce-core";
2
+ import { modifyHiddenTags } from "applesauce-core/operations";
2
3
  import { WALLET_BACKUP_KIND, WALLET_KIND } from "../helpers/wallet.js";
3
- import { setBackupContent, setMints, setPrivateKey } from "../operations/wallet.js";
4
+ import { setBackupContent, setMintTags, setPrivateKeyTag, setRelayTags } from "../operations/wallet.js";
4
5
  /** A blueprint to create a new 17375 wallet */
5
- export function WalletBlueprint(mints, privateKey) {
6
- return blueprint(WALLET_KIND, setMints(mints), privateKey ? setPrivateKey(privateKey) : undefined);
6
+ export function WalletBlueprint({ mints, privateKey, relays, }) {
7
+ return blueprint(WALLET_KIND,
8
+ // Use top level modifyHiddenTags to avoid multiple encryption operations
9
+ modifyHiddenTags(setMintTags(mints), privateKey ? setPrivateKeyTag(privateKey) : undefined, relays ? setRelayTags(relays) : undefined));
7
10
  }
8
11
  /** A blueprint that creates a new 375 wallet backup event */
9
12
  export function WalletBackupBlueprint(wallet) {
@@ -0,0 +1,22 @@
1
+ import { ChainableObservable } from "applesauce-common/observable";
2
+ import { NutzapInfo } from "./nutzap-info.js";
3
+ import { Nutzap } from "./nutzap.js";
4
+ import { Wallet } from "./wallet.js";
5
+ import { MintRecommendation } from "./mint-recommendation.js";
6
+ declare module "applesauce-common/casts/user" {
7
+ interface User {
8
+ readonly wallet$: ChainableObservable<Wallet | undefined>;
9
+ readonly nutzap$: ChainableObservable<NutzapInfo | undefined>;
10
+ readonly mintRecommendation$: ChainableObservable<MintRecommendation | undefined>;
11
+ }
12
+ }
13
+ declare module "applesauce-common/casts/stream" {
14
+ interface Stream {
15
+ readonly nutzaps$: ChainableObservable<Nutzap[]>;
16
+ }
17
+ }
18
+ declare module "applesauce-common/casts/note" {
19
+ interface Note {
20
+ nutzaps$(): ChainableObservable<Nutzap[]>;
21
+ }
22
+ }
@@ -0,0 +1,52 @@
1
+ import { Note, Stream } from "applesauce-common/casts";
2
+ import { User } from "applesauce-common/casts/user";
3
+ import { castEventStream, castTimelineStream } from "applesauce-common/observable";
4
+ import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
5
+ import { switchMap } from "rxjs";
6
+ import { NUTZAP_KIND } from "../helpers/nutzap.js";
7
+ import { WALLET_KIND } from "../helpers/wallet.js";
8
+ import { NUTZAP_INFO_KIND } from "../helpers/nutzap-info.js";
9
+ import { NutzapInfo } from "./nutzap-info.js";
10
+ import { Nutzap } from "./nutzap.js";
11
+ import { Wallet } from "./wallet.js";
12
+ import { MintRecommendation } from "./mint-recommendation.js";
13
+ import { MINT_RECOMMENDATION_KIND } from "../helpers/mint-recommendation.js";
14
+ Object.defineProperty(User.prototype, "wallet$", {
15
+ get: function () {
16
+ return this.$$ref("wallet$", (store) => this.outboxes$.pipe(switchMap((outboxes) => store
17
+ .replaceable({ kind: WALLET_KIND, pubkey: this.pubkey, relays: outboxes })
18
+ .pipe(castEventStream(Wallet, store)))));
19
+ },
20
+ enumerable: true,
21
+ configurable: false,
22
+ });
23
+ Object.defineProperty(User.prototype, "nutzap$", {
24
+ get: function () {
25
+ return this.$$ref("nutzap$", (store) => store.replaceable(NUTZAP_INFO_KIND, this.pubkey).pipe(castEventStream(NutzapInfo, store)));
26
+ },
27
+ enumerable: true,
28
+ configurable: false,
29
+ });
30
+ Object.defineProperty(User.prototype, "mintRecommendation$", {
31
+ get: function () {
32
+ return this.$$ref("mintRecommendation$", (store) => store
33
+ .timeline({ kinds: [MINT_RECOMMENDATION_KIND], authors: [this.pubkey] })
34
+ .pipe(castTimelineStream(MintRecommendation, store)));
35
+ },
36
+ enumerable: true,
37
+ configurable: false,
38
+ });
39
+ Note.prototype.nutzaps$ = function () {
40
+ return this.$$ref("nutzaps$", (store) => store
41
+ .timeline(buildCommonEventRelationFilters({ kinds: [NUTZAP_KIND] }, this.event))
42
+ .pipe(castTimelineStream(Nutzap, store)));
43
+ };
44
+ Object.defineProperty(Stream.prototype, "nutzaps$", {
45
+ get: function () {
46
+ return this.$$ref("nutzaps$", (store) => store
47
+ .timeline(buildCommonEventRelationFilters({ kinds: [NUTZAP_KIND] }, this.event))
48
+ .pipe(castTimelineStream(Nutzap, store)));
49
+ },
50
+ enumerable: true,
51
+ configurable: false,
52
+ });
@@ -0,0 +1,8 @@
1
+ export * from "./mint-info.js";
2
+ export * from "./mint-recommendation.js";
3
+ export * from "./nutzap-info.js";
4
+ export * from "./nutzap.js";
5
+ export * from "./wallet-history.js";
6
+ export * from "./wallet-token.js";
7
+ export * from "./wallet.js";
8
+ import "./__register__.js";
@@ -0,0 +1,8 @@
1
+ export * from "./mint-info.js";
2
+ export * from "./mint-recommendation.js";
3
+ export * from "./nutzap-info.js";
4
+ export * from "./nutzap.js";
5
+ export * from "./wallet-history.js";
6
+ export * from "./wallet-token.js";
7
+ export * from "./wallet.js";
8
+ import "./__register__.js";
@@ -0,0 +1,18 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { CashuMintInfoEvent } from "../helpers/mint-info.js";
4
+ import { MintRecommendation } from "./mint-recommendation.js";
5
+ export declare class MintInfo extends EventCast<CashuMintInfoEvent> {
6
+ constructor(event: NostrEvent, store: CastRefEventStore);
7
+ /** The mint's pubkey (from the `d` tag) */
8
+ get mintPubkey(): string | undefined;
9
+ /** The URL to the cashu mint (from the `u` tag) */
10
+ get url(): string;
11
+ /** The supported nuts (comma-separated list of nut numbers) */
12
+ get nuts(): number[];
13
+ /** The network type (mainnet, testnet, signet, or regtest) */
14
+ get network(): import("../helpers/mint-info.js").NetworkType | undefined;
15
+ /** Optional metadata content (kind:0-style JSON object) */
16
+ get metadata(): Record<string, any> | undefined;
17
+ get recomendations$(): import("applesauce-common/observable").ChainableObservable<MintRecommendation[]>;
18
+ }
@@ -0,0 +1,42 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { castTimelineStream } from "applesauce-common/observable";
3
+ import { getCashuMintMetadata, getCashuMintNetwork, getCashuMintNuts, getCashuMintPubkey, getCashuMintURL, isValidCashuMintInfo, } from "../helpers/mint-info.js";
4
+ import { MINT_RECOMMENDATION_KIND } from "../helpers/mint-recommendation.js";
5
+ import { MintRecommendation } from "./mint-recommendation.js";
6
+ export class MintInfo extends EventCast {
7
+ constructor(event, store) {
8
+ if (!isValidCashuMintInfo(event))
9
+ throw new Error("Invalid cashu mint info event");
10
+ super(event, store);
11
+ }
12
+ /** The mint's pubkey (from the `d` tag) */
13
+ get mintPubkey() {
14
+ return getCashuMintPubkey(this.event);
15
+ }
16
+ /** The URL to the cashu mint (from the `u` tag) */
17
+ get url() {
18
+ return getCashuMintURL(this.event);
19
+ }
20
+ /** The supported nuts (comma-separated list of nut numbers) */
21
+ get nuts() {
22
+ return getCashuMintNuts(this.event);
23
+ }
24
+ /** The network type (mainnet, testnet, signet, or regtest) */
25
+ get network() {
26
+ return getCashuMintNetwork(this.event);
27
+ }
28
+ /** Optional metadata content (kind:0-style JSON object) */
29
+ get metadata() {
30
+ return getCashuMintMetadata(this.event);
31
+ }
32
+ get recomendations$() {
33
+ return this.$$ref("recomendations$", (store) => store
34
+ .timeline([
35
+ // Based on the mint URL
36
+ { kinds: [MINT_RECOMMENDATION_KIND], "#u": [this.url] },
37
+ // Based on the mint pubkey
38
+ this.mintPubkey ? { kinds: [MINT_RECOMMENDATION_KIND], "#d": [this.mintPubkey] } : undefined,
39
+ ].filter((f) => !!f))
40
+ .pipe(castTimelineStream(MintRecommendation, store)));
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { MintRecommendationEvent } from "../helpers/mint-recommendation.js";
4
+ export declare class MintRecommendation extends EventCast<MintRecommendationEvent> {
5
+ constructor(event: NostrEvent, store: CastRefEventStore);
6
+ /** The recommended event kind (should be 38172 for cashu mints) */
7
+ get kind(): number;
8
+ /** The mint's pubkey (from the `d` tag) */
9
+ get mintPubkey(): string | undefined;
10
+ /** Optional URL to connect to the cashu mint (from the `u` tag) */
11
+ get url(): string | undefined;
12
+ /** Optional address pointer to the kind:38172 event (from the `a` tag) */
13
+ get addressPointer(): import("nostr-tools/nip19").AddressPointer | undefined;
14
+ /** Optional review content */
15
+ get comment(): string;
16
+ }
@@ -0,0 +1,29 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { getRecommendationAddressPointer, getRecommendationMintPubkey, getRecommendationKind, getRecommendationURL, isValidMintRecommendation, } from "../helpers/mint-recommendation.js";
3
+ export class MintRecommendation extends EventCast {
4
+ constructor(event, store) {
5
+ if (!isValidMintRecommendation(event))
6
+ throw new Error("Invalid mint recommendation event");
7
+ super(event, store);
8
+ }
9
+ /** The recommended event kind (should be 38172 for cashu mints) */
10
+ get kind() {
11
+ return getRecommendationKind(this.event);
12
+ }
13
+ /** The mint's pubkey (from the `d` tag) */
14
+ get mintPubkey() {
15
+ return getRecommendationMintPubkey(this.event);
16
+ }
17
+ /** Optional URL to connect to the cashu mint (from the `u` tag) */
18
+ get url() {
19
+ return getRecommendationURL(this.event);
20
+ }
21
+ /** Optional address pointer to the kind:38172 event (from the `a` tag) */
22
+ get addressPointer() {
23
+ return getRecommendationAddressPointer(this.event);
24
+ }
25
+ /** Optional review content */
26
+ get comment() {
27
+ return this.event.content;
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { NutzapInfoEvent } from "../helpers/nutzap-info.js";
4
+ export declare class NutzapInfo extends EventCast<NutzapInfoEvent> {
5
+ constructor(event: NostrEvent, store: CastRefEventStore);
6
+ get relays(): string[];
7
+ get mints(): {
8
+ mint: string;
9
+ units?: string[];
10
+ }[];
11
+ /** The p2pk public key to use when zapping */
12
+ get publicKey(): string | undefined;
13
+ get p2pk(): string | undefined;
14
+ }
@@ -0,0 +1,22 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { getNutzapInfoMints, getNutzapInfoPubkey, getNutzapInfoRelays, isValidNutzapInfo, } from "../helpers/nutzap-info.js";
3
+ export class NutzapInfo extends EventCast {
4
+ constructor(event, store) {
5
+ if (!isValidNutzapInfo(event))
6
+ throw new Error("Invalid nutzap info");
7
+ super(event, store);
8
+ }
9
+ get relays() {
10
+ return getNutzapInfoRelays(this.event);
11
+ }
12
+ get mints() {
13
+ return getNutzapInfoMints(this.event);
14
+ }
15
+ /** The p2pk public key to use when zapping */
16
+ get publicKey() {
17
+ return getNutzapInfoPubkey(this.event);
18
+ }
19
+ get p2pk() {
20
+ return this.publicKey;
21
+ }
22
+ }
@@ -0,0 +1,16 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { NutzapEvent } from "../helpers/nutzap.js";
4
+ export declare class Nutzap extends EventCast<NutzapEvent> {
5
+ constructor(event: NostrEvent, store: CastRefEventStore);
6
+ get proofs(): import("@cashu/cashu-ts").Proof[];
7
+ get mint(): string;
8
+ get amount(): number;
9
+ get recipient(): import("applesauce-common/casts").User;
10
+ get sender(): import("applesauce-common/casts").User;
11
+ get comment(): string | undefined;
12
+ /** The pointer to the event that was zapped */
13
+ get pointer(): import("nostr-tools/nip19").EventPointer | import("nostr-tools/nip19").AddressPointer | undefined;
14
+ /** The event that was zapped */
15
+ get zapped$(): import("applesauce-common/observable").ChainableObservable<import("nostr-tools").Event | undefined>;
16
+ }
@@ -0,0 +1,37 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { castUser } from "applesauce-common/casts/user";
3
+ import { of } from "rxjs";
4
+ import { getNutzapAddressPointer, getNutzapAmount, getNutzapComment, getNutzapEventPointer, getNutzapMint, getNutzapProofs, getNutzapRecipient, isValidNutzap, } from "../helpers/nutzap.js";
5
+ export class Nutzap extends EventCast {
6
+ constructor(event, store) {
7
+ if (!isValidNutzap(event))
8
+ throw new Error("Invalid nutzap");
9
+ super(event, store);
10
+ }
11
+ get proofs() {
12
+ return getNutzapProofs(this.event);
13
+ }
14
+ get mint() {
15
+ return getNutzapMint(this.event);
16
+ }
17
+ get amount() {
18
+ return getNutzapAmount(this.event);
19
+ }
20
+ get recipient() {
21
+ return castUser(getNutzapRecipient(this.event), this.store);
22
+ }
23
+ get sender() {
24
+ return this.author;
25
+ }
26
+ get comment() {
27
+ return getNutzapComment(this.event);
28
+ }
29
+ /** The pointer to the event that was zapped */
30
+ get pointer() {
31
+ return getNutzapAddressPointer(this.event) ?? getNutzapEventPointer(this.event);
32
+ }
33
+ /** The event that was zapped */
34
+ get zapped$() {
35
+ return this.$$ref("zapped$", (store) => (this.pointer ? store.event(this.pointer) : of(undefined)));
36
+ }
37
+ }
@@ -0,0 +1,16 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { HiddenContentSigner } from "applesauce-core/helpers";
3
+ import { NostrEvent } from "applesauce-core/helpers/event";
4
+ import { WalletHistoryEvent } from "../helpers/history.js";
5
+ export declare class WalletHistory extends EventCast<WalletHistoryEvent> {
6
+ constructor(event: NostrEvent, store: CastRefEventStore);
7
+ /** The embedded history metadata */
8
+ get meta(): import("../helpers/history.js").HistoryContent | undefined;
9
+ get direction(): import("../helpers/history.js").HistoryDirection | undefined;
10
+ get amount(): number | undefined;
11
+ get redeemed(): string[];
12
+ get unlocked(): boolean;
13
+ unlock(signer: HiddenContentSigner): Promise<import("../helpers/history.js").HistoryContent>;
14
+ get meta$(): import("applesauce-common/observable").ChainableObservable<import("../helpers/history.js").HistoryContent | undefined>;
15
+ get amount$(): import("applesauce-common/observable").ChainableObservable<number | undefined>;
16
+ }
@@ -0,0 +1,40 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { watchEventUpdates } from "applesauce-core/observable";
3
+ import { of } from "rxjs";
4
+ import { map } from "rxjs/operators";
5
+ import { getHistoryContent, getHistoryRedeemed, isHistoryContentUnlocked, isValidWalletHistory, unlockHistoryContent, } from "../helpers/history.js";
6
+ export class WalletHistory extends EventCast {
7
+ constructor(event, store) {
8
+ if (!isValidWalletHistory(event))
9
+ throw new Error("Invalid wallet history");
10
+ super(event, store);
11
+ }
12
+ /** The embedded history metadata */
13
+ get meta() {
14
+ return getHistoryContent(this.event);
15
+ }
16
+ // Direct getters (return undefined if locked)
17
+ get direction() {
18
+ return this.meta?.direction;
19
+ }
20
+ get amount() {
21
+ return this.meta?.amount;
22
+ }
23
+ get redeemed() {
24
+ return getHistoryRedeemed(this.event);
25
+ }
26
+ // Unlocking pattern
27
+ get unlocked() {
28
+ return isHistoryContentUnlocked(this.event);
29
+ }
30
+ async unlock(signer) {
31
+ return unlockHistoryContent(this.event, signer);
32
+ }
33
+ // Observable that emits when history is unlocked
34
+ get meta$() {
35
+ return this.$$ref("meta$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => event && getHistoryContent(event))));
36
+ }
37
+ get amount$() {
38
+ return this.$$ref("amount$", () => this.meta$.pipe(map((meta) => meta?.amount)));
39
+ }
40
+ }
@@ -0,0 +1,29 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { HiddenContentSigner } from "applesauce-core/helpers";
3
+ import { NostrEvent } from "applesauce-core/helpers/event";
4
+ import { WalletTokenEvent } from "../helpers/tokens.js";
5
+ export declare class WalletToken extends EventCast<WalletTokenEvent> {
6
+ constructor(event: NostrEvent, store: CastRefEventStore);
7
+ get meta(): import("../helpers/tokens.js").TokenContent | undefined;
8
+ get proofs(): {
9
+ amount: number;
10
+ secret: string;
11
+ C: string;
12
+ id: string;
13
+ }[] | undefined;
14
+ get mint(): string | undefined;
15
+ get amount(): number | undefined;
16
+ get deleted(): string[] | undefined;
17
+ get unlocked(): boolean;
18
+ unlock(signer: HiddenContentSigner): Promise<import("../helpers/tokens.js").TokenContent>;
19
+ get meta$(): import("applesauce-common/observable").ChainableObservable<import("../helpers/tokens.js").TokenContent>;
20
+ get mint$(): import("applesauce-common/observable").ChainableObservable<string>;
21
+ get proofs$(): import("applesauce-common/observable").ChainableObservable<{
22
+ amount: number;
23
+ secret: string;
24
+ C: string;
25
+ id: string;
26
+ }[]>;
27
+ get amount$(): import("applesauce-common/observable").ChainableObservable<number>;
28
+ get deleted$(): import("applesauce-common/observable").ChainableObservable<string[]>;
29
+ }
@@ -0,0 +1,52 @@
1
+ import { sumProofs } from "@cashu/cashu-ts";
2
+ import { EventCast } from "applesauce-common/casts";
3
+ import { defined, watchEventUpdates } from "applesauce-core/observable";
4
+ import { of } from "rxjs";
5
+ import { map } from "rxjs/operators";
6
+ import { getTokenContent, isTokenContentUnlocked, isValidWalletToken, unlockTokenContent, } from "../helpers/tokens.js";
7
+ export class WalletToken extends EventCast {
8
+ constructor(event, store) {
9
+ if (!isValidWalletToken(event))
10
+ throw new Error("Invalid wallet token");
11
+ super(event, store);
12
+ }
13
+ get meta() {
14
+ return getTokenContent(this.event);
15
+ }
16
+ // Direct getters (return undefined if locked)
17
+ get proofs() {
18
+ return this.meta?.proofs;
19
+ }
20
+ get mint() {
21
+ return this.meta?.mint;
22
+ }
23
+ get amount() {
24
+ return this.proofs && sumProofs(this.proofs);
25
+ }
26
+ get deleted() {
27
+ return this.meta?.del;
28
+ }
29
+ // Unlocking pattern
30
+ get unlocked() {
31
+ return isTokenContentUnlocked(this.event);
32
+ }
33
+ async unlock(signer) {
34
+ return unlockTokenContent(this.event, signer);
35
+ }
36
+ // Observable that emits when token is unlocked
37
+ get meta$() {
38
+ return this.$$ref("meta$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => event && getTokenContent(event)), defined()));
39
+ }
40
+ get mint$() {
41
+ return this.$$ref("mint$", () => this.meta$.pipe(map((meta) => meta?.mint)));
42
+ }
43
+ get proofs$() {
44
+ return this.$$ref("proofs$", () => this.meta$.pipe(map((meta) => meta?.proofs)));
45
+ }
46
+ get amount$() {
47
+ return this.$$ref("amount$", () => this.proofs$.pipe(map(sumProofs)));
48
+ }
49
+ get deleted$() {
50
+ return this.$$ref("deleted$", () => this.meta$.pipe(map((meta) => meta?.del)));
51
+ }
52
+ }
@@ -0,0 +1,27 @@
1
+ import { CastRefEventStore, EventCast } from "applesauce-common/casts";
2
+ import { HiddenContentSigner } from "applesauce-core/helpers";
3
+ import { NostrEvent } from "applesauce-core/helpers/event";
4
+ import { WalletEvent } from "../helpers/wallet.js";
5
+ import { WalletHistory } from "./wallet-history.js";
6
+ import { WalletToken } from "./wallet-token.js";
7
+ export declare class Wallet extends EventCast<WalletEvent> {
8
+ constructor(event: NostrEvent, store: CastRefEventStore);
9
+ get mints(): string[];
10
+ get relays(): string[] | undefined;
11
+ get privateKey(): Uint8Array<ArrayBufferLike> | null | undefined;
12
+ get unlocked(): boolean;
13
+ unlock(signer: HiddenContentSigner): Promise<{
14
+ mints: string[];
15
+ privateKey: Uint8Array | null;
16
+ relays: string[];
17
+ }>;
18
+ get mints$(): import("applesauce-common/observable").ChainableObservable<string[] | undefined>;
19
+ get relays$(): import("applesauce-common/observable").ChainableObservable<string[] | undefined>;
20
+ get balance$(): import("applesauce-common/observable").ChainableObservable<Record<string, number>>;
21
+ /** The p2pk locking private key for this wallet */
22
+ get privateKey$(): import("applesauce-common/observable").ChainableObservable<Uint8Array<ArrayBufferLike> | null | undefined>;
23
+ get tokens$(): import("applesauce-common/observable").ChainableObservable<WalletToken[]>;
24
+ get history$(): import("applesauce-common/observable").ChainableObservable<WalletHistory[]>;
25
+ get backups$(): import("applesauce-common/observable").ChainableObservable<import("nostr-tools").Event[]>;
26
+ get received$(): import("applesauce-common/observable").ChainableObservable<string[]>;
27
+ }
@@ -0,0 +1,62 @@
1
+ import { EventCast } from "applesauce-common/casts";
2
+ import { castTimelineStream } from "applesauce-common/observable";
3
+ import { watchEventUpdates } from "applesauce-core/observable";
4
+ import { of } from "rxjs";
5
+ import { map } from "rxjs/operators";
6
+ import { getWalletMints, getWalletPrivateKey, getWalletRelays, isValidWallet, isWalletUnlocked, unlockWallet, WALLET_BACKUP_KIND, } from "../helpers/wallet.js";
7
+ import { WalletHistoryModel } from "../models/history.js";
8
+ import { WalletBalanceModel, WalletTokensModel } from "../models/tokens.js";
9
+ import { WalletHistory } from "./wallet-history.js";
10
+ import { WalletToken } from "./wallet-token.js";
11
+ import { ReceivedNutzapsModel } from "../models/nutzap.js";
12
+ export class Wallet extends EventCast {
13
+ constructor(event, store) {
14
+ if (!isValidWallet(event))
15
+ throw new Error("Invalid wallet event");
16
+ super(event, store);
17
+ }
18
+ // Direct getters (return undefined if locked)
19
+ get mints() {
20
+ return getWalletMints(this.event);
21
+ }
22
+ get relays() {
23
+ return getWalletRelays(this.event);
24
+ }
25
+ get privateKey() {
26
+ return getWalletPrivateKey(this.event);
27
+ }
28
+ // Unlocking pattern
29
+ get unlocked() {
30
+ return isWalletUnlocked(this.event);
31
+ }
32
+ async unlock(signer) {
33
+ return unlockWallet(this.event, signer);
34
+ }
35
+ // Observable that emits when wallet is unlocked
36
+ get mints$() {
37
+ return this.$$ref("mints$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => event && getWalletMints(event))));
38
+ }
39
+ get relays$() {
40
+ return this.$$ref("relays$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => event && getWalletRelays(event))));
41
+ }
42
+ get balance$() {
43
+ return this.$$ref("balance$", (store) => store.model(WalletBalanceModel, this.event.pubkey));
44
+ }
45
+ /** The p2pk locking private key for this wallet */
46
+ get privateKey$() {
47
+ return this.$$ref("privateKey$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => event && getWalletPrivateKey(event))));
48
+ }
49
+ // Observables for related events
50
+ get tokens$() {
51
+ return this.$$ref("tokens$", (store) => store.model(WalletTokensModel, this.event.pubkey).pipe(castTimelineStream(WalletToken, store)));
52
+ }
53
+ get history$() {
54
+ return this.$$ref("history$", (store) => store.model(WalletHistoryModel, this.event.pubkey).pipe(castTimelineStream(WalletHistory, store)));
55
+ }
56
+ get backups$() {
57
+ return this.$$ref("backups$", (store) => store.timeline({ kinds: [WALLET_BACKUP_KIND], authors: [this.event.pubkey] }));
58
+ }
59
+ get received$() {
60
+ return this.$$ref("received$", (store) => store.model(ReceivedNutzapsModel, this.event.pubkey));
61
+ }
62
+ }
@@ -0,0 +1,21 @@
1
+ import { Proof, Token } from "@cashu/cashu-ts";
2
+ /** Internal method for creating a unique id for each proof */
3
+ export declare function getProofUID(proof: Proof): string;
4
+ /**
5
+ * Extracts the P2PK locking pubkey from a proof's secret
6
+ * @param proof the cashu proof to extract the pubkey from
7
+ * @returns the pubkey, or undefined if not P2PK locked
8
+ */
9
+ export declare function getProofP2PKPubkey(proof: Proof): string | undefined;
10
+ /** Internal method to filter out duplicate proofs */
11
+ export declare function ignoreDuplicateProofs(seen?: Set<string>): (proof: Proof) => boolean;
12
+ /**
13
+ * Returns a decoded cashu token inside an unicode emoji
14
+ * @see https://github.com/cashubtc/cashu.me/blob/1194a7b9ee2f43305e38304de7bef8839601ff4d/src/components/ReceiveTokenDialog.vue#L387
15
+ */
16
+ export declare function decodeTokenFromEmojiString(str: string): Token | undefined;
17
+ /**
18
+ * Encodes a token into an emoji char
19
+ * @see https://github.com/cashubtc/cashu.me/blob/1194a7b9ee2f43305e38304de7bef8839601ff4d/src/components/SendTokenDialog.vue#L710
20
+ */
21
+ export declare function encodeTokenToEmoji(token: Token | string, emoji?: string): string;