routstrd 0.3.11 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routstrd",
3
- "version": "0.3.11",
3
+ "version": "0.4.0",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "private": false,
@@ -12,7 +12,7 @@
12
12
  "monitor": "bun src/index.ts monitor",
13
13
  "lint": "tsc --noEmit",
14
14
  "test": "bun test",
15
- "build": "mkdir -p dist/daemon && bun build src/index.ts --target=bun --outfile=dist/index.js && bun build src/daemon/index.ts --target=bun --outfile=dist/daemon/index.js",
15
+ "build": "bun build src/index.ts --target=bun --outfile=dist/index.js --external better-sqlite3 && bun build src/daemon/index.ts --target=bun --outfile=dist/daemon/index.js --external better-sqlite3",
16
16
  "prepublishOnly": "bun run build"
17
17
  },
18
18
  "devDependencies": {
@@ -24,10 +24,15 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@cashu/cashu-ts": "^4.3.0",
27
- "@routstr/sdk": "^0.3.18",
27
+ "@cashu/coco-core": "^1.0.1",
28
+ "@cashu/coco-sqlite-bun": "^1.0.1",
29
+ "@routstr/sdk": "^0.4.0",
30
+ "@scure/bip39": "^2.2.0",
28
31
  "applesauce-core": "^5.1.0",
29
32
  "applesauce-relay": "^5.1.0",
30
33
  "applesauce-wallet-connect": "^6.0.0",
34
+ "coco-cashu-core": "1.1.2-rc.50",
35
+ "coco-cashu-plugin-npc": "2.4.1",
31
36
  "commander": "^14.0.2",
32
37
  "nostr-tools": "^2.12.0",
33
38
  "qrcode": "^1.5.4",
@@ -0,0 +1,55 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import { mkdtempSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
3
+ import { tmpdir } from "os";
4
+ import { join } from "path";
5
+ import { initializeWallet } from "./cli";
6
+
7
+ const tempDirs: string[] = [];
8
+
9
+ function makeTempDir(): string {
10
+ const dir = mkdtempSync(join(tmpdir(), "routstrd-wallet-test-"));
11
+ tempDirs.push(dir);
12
+ return dir;
13
+ }
14
+
15
+ function permissions(path: string): number {
16
+ return statSync(path).mode & 0o777;
17
+ }
18
+
19
+ afterEach(() => {
20
+ for (const dir of tempDirs.splice(0)) {
21
+ rmSync(dir, { recursive: true, force: true });
22
+ }
23
+ });
24
+
25
+ describe("initializeWallet", () => {
26
+ test("creates the wallet directory and config with restrictive permissions", () => {
27
+ const walletDir = join(makeTempDir(), "wallet");
28
+
29
+ initializeWallet(walletDir);
30
+
31
+ const walletConfig = join(walletDir, "config.json");
32
+ expect(permissions(walletDir)).toBe(0o700);
33
+ expect(permissions(walletConfig)).toBe(0o600);
34
+
35
+ const config = JSON.parse(readFileSync(walletConfig, "utf8"));
36
+ expect(config.encrypted).toBe(false);
37
+ expect(typeof config.mnemonic).toBe("string");
38
+ expect(config.mnemonic.length).toBeGreaterThan(0);
39
+ });
40
+
41
+ test("repairs permissions without replacing an existing wallet", () => {
42
+ const walletDir = join(makeTempDir(), "wallet");
43
+ const walletConfig = join(walletDir, "config.json");
44
+ const existingConfig = JSON.stringify({ mnemonic: "existing seed" });
45
+
46
+ mkdirSync(walletDir, { mode: 0o755 });
47
+ writeFileSync(walletConfig, existingConfig, { mode: 0o644 });
48
+
49
+ initializeWallet(walletDir);
50
+
51
+ expect(readFileSync(walletConfig, "utf8")).toBe(existingConfig);
52
+ expect(permissions(walletDir)).toBe(0o700);
53
+ expect(permissions(walletConfig)).toBe(0o600);
54
+ });
55
+ });