applesauce-wallet 0.0.0-next-20250309231023

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 hzrd149
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1,13 @@
1
+ import { HiddenContentSigner } from "applesauce-core/helpers";
2
+ import { NostrEvent } from "nostr-tools";
3
+ export declare const WALLET_KIND = 17375;
4
+ export declare const WalletPrivateKeySymbol: unique symbol;
5
+ export declare const WalletMintsSymbol: unique symbol;
6
+ /** Returns if a wallet is locked */
7
+ export declare function isWalletLocked(wallet: NostrEvent): boolean;
8
+ /** Unlocks a wallet and returns the hidden tags */
9
+ export declare function unlockWallet(wallet: NostrEvent, signer: HiddenContentSigner): Promise<string[][]>;
10
+ /** Returns the wallets mints */
11
+ export declare function getWalletMints(wallet: NostrEvent): string[];
12
+ /** Returns the wallets private key as a string */
13
+ export declare function getWalletPrivateKey(wallet: NostrEvent): string;
@@ -0,0 +1,33 @@
1
+ import { getHiddenTags, getOrComputeCachedValue, isHiddenTagsLocked, unlockHiddenTags, } from "applesauce-core/helpers";
2
+ export const WALLET_KIND = 17375;
3
+ export const WalletPrivateKeySymbol = Symbol.for("wallet-private-key");
4
+ export const WalletMintsSymbol = Symbol.for("wallet-mints");
5
+ /** Returns if a wallet is locked */
6
+ export function isWalletLocked(wallet) {
7
+ return isHiddenTagsLocked(wallet);
8
+ }
9
+ /** Unlocks a wallet and returns the hidden tags */
10
+ export async function unlockWallet(wallet, signer) {
11
+ return await unlockHiddenTags(wallet, signer);
12
+ }
13
+ /** Returns the wallets mints */
14
+ export function getWalletMints(wallet) {
15
+ return getOrComputeCachedValue(wallet, WalletMintsSymbol, () => {
16
+ const tags = getHiddenTags(wallet);
17
+ if (!tags)
18
+ throw new Error("Wallet is locked");
19
+ return tags.filter((t) => t[0] === "mint").map((t) => t[1]);
20
+ });
21
+ }
22
+ /** Returns the wallets private key as a string */
23
+ export function getWalletPrivateKey(wallet) {
24
+ return getOrComputeCachedValue(wallet, WalletPrivateKeySymbol, () => {
25
+ const tags = getHiddenTags(wallet);
26
+ if (!tags)
27
+ throw new Error("Wallet is locked");
28
+ const key = tags.find((t) => t[0] === "privkey" && t[1])?.[1];
29
+ if (!key)
30
+ throw new Error("Wallet missing private key");
31
+ return key;
32
+ });
33
+ }
@@ -0,0 +1,2 @@
1
+ export * as Queries from "./queries/index.js";
2
+ export * as Helpers from "./helpers/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * as Queries from "./queries/index.js";
2
+ export * as Helpers from "./helpers/index.js";
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1 @@
1
+ export * from "./wallet.js";
@@ -0,0 +1,10 @@
1
+ import { Query } from "applesauce-core";
2
+ export type WalletInfo = {
3
+ locked: true;
4
+ } | {
5
+ locked: false;
6
+ privateKey: string;
7
+ mints: string[];
8
+ };
9
+ /** A query to get the state of a NIP-60 wallet */
10
+ export declare function WalletQuery(pubkey: string): Query<WalletInfo | undefined>;
@@ -0,0 +1,21 @@
1
+ import { filter, map, merge } from "rxjs";
2
+ import { getWalletMints, getWalletPrivateKey, isWalletLocked, WALLET_KIND } from "../helpers/wallet.js";
3
+ /** A query to get the state of a NIP-60 wallet */
4
+ export function WalletQuery(pubkey) {
5
+ return {
6
+ key: pubkey,
7
+ run: (events) => merge(
8
+ // get the latest replaceable event
9
+ events.replaceable(WALLET_KIND, pubkey),
10
+ // and listen for any updates to matching events
11
+ events.database.updated.pipe(filter((e) => e.kind === WALLET_KIND && e.pubkey === pubkey))).pipe(map((wallet) => {
12
+ if (!wallet)
13
+ return;
14
+ if (isWalletLocked(wallet))
15
+ return { locked: true };
16
+ const mints = getWalletMints(wallet);
17
+ const privateKey = getWalletPrivateKey(wallet);
18
+ return { locked: false, mints, privateKey };
19
+ })),
20
+ };
21
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "applesauce-wallet",
3
+ "version": "0.0.0-next-20250309231023",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "keywords": [
9
+ "nostr",
10
+ "applesauce"
11
+ ],
12
+ "author": "hzrd149",
13
+ "license": "MIT",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ },
23
+ "./helpers": {
24
+ "import": "./dist/helpers/index.js",
25
+ "require": "./dist/helpers/index.js",
26
+ "types": "./dist/helpers/index.d.ts"
27
+ },
28
+ "./helpers/*": {
29
+ "import": "./dist/helpers/*.js",
30
+ "require": "./dist/helpers/*.js",
31
+ "types": "./dist/helpers/*.d.ts"
32
+ },
33
+ "./queries": {
34
+ "import": "./dist/queries/index.js",
35
+ "require": "./dist/queries/index.js",
36
+ "types": "./dist/queries/index.d.ts"
37
+ },
38
+ "./queries/*": {
39
+ "import": "./dist/queries/*.js",
40
+ "require": "./dist/queries/*.js",
41
+ "types": "./dist/queries/*.d.ts"
42
+ }
43
+ },
44
+ "dependencies": {
45
+ "applesauce-core": "0.0.0-next-20250309231023",
46
+ "nostr-tools": "^2.10.4",
47
+ "rxjs": "^7.8.1"
48
+ },
49
+ "devDependencies": {
50
+ "@hirez_io/observer-spy": "^2.2.0",
51
+ "@types/debug": "^4.1.12",
52
+ "typescript": "^5.7.3",
53
+ "vitest": "^3.0.5"
54
+ },
55
+ "funding": {
56
+ "type": "lightning",
57
+ "url": "lightning:nostrudel@geyser.fund"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc",
61
+ "watch:build": "tsc --watch > /dev/null",
62
+ "test": "vitest run --passWithNoTests",
63
+ "watch:test": "vitest"
64
+ }
65
+ }