@cogcoin/client 0.5.1 → 0.5.3

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.
@@ -1,5 +1,5 @@
1
- import * as crypto from "node:crypto";
2
- const { createCipheriv, createDecipheriv, randomBytes, } = crypto;
1
+ import { argon2id } from "hash-wasm";
2
+ import { createCipheriv, createDecipheriv, randomBytes, } from "node:crypto";
3
3
  const DEFAULT_ARGON2_MEMORY_KIB = 65_536;
4
4
  const DEFAULT_ARGON2_ITERATIONS = 3;
5
5
  const DEFAULT_ARGON2_PARALLELISM = 1;
@@ -7,12 +7,6 @@ const DERIVED_KEY_LENGTH = 32;
7
7
  const GCM_NONCE_BYTES = 12;
8
8
  const ARGON2_SALT_BYTES = 16;
9
9
  const BIGINT_JSON_TAG = "$cogcoinBigInt";
10
- function requireArgon2() {
11
- if (typeof crypto.argon2 !== "function") {
12
- throw new Error("Node.js 24.7.0 or newer is required because node:crypto argon2 is unavailable.");
13
- }
14
- return crypto.argon2;
15
- }
16
10
  function jsonReplacer(_key, value) {
17
11
  if (typeof value === "bigint") {
18
12
  return {
@@ -30,23 +24,17 @@ function jsonReviver(_key, value) {
30
24
  }
31
25
  return value;
32
26
  }
33
- function deriveArgon2Key(message, nonce, memoryKib, iterations, parallelism) {
34
- return new Promise((resolve, reject) => {
35
- requireArgon2()("argon2id", {
36
- message,
37
- nonce,
38
- memory: memoryKib,
39
- passes: iterations,
40
- parallelism,
41
- tagLength: DERIVED_KEY_LENGTH,
42
- }, (error, derivedKey) => {
43
- if (error) {
44
- reject(error);
45
- return;
46
- }
47
- resolve(Buffer.from(derivedKey));
48
- });
27
+ async function deriveArgon2Key(message, nonce, memoryKib, iterations, parallelism) {
28
+ const derivedKey = await argon2id({
29
+ password: message,
30
+ salt: nonce,
31
+ memorySize: memoryKib,
32
+ iterations,
33
+ parallelism,
34
+ hashLength: DERIVED_KEY_LENGTH,
35
+ outputType: "binary",
49
36
  });
37
+ return Buffer.from(derivedKey);
50
38
  }
51
39
  export async function deriveKeyFromPassphrase(passphrase, options = {}) {
52
40
  const salt = Buffer.from(options.salt ?? randomBytes(ARGON2_SALT_BYTES));
@@ -0,0 +1,4 @@
1
+ import type { WalletExplicitLockStateV1 } from "../types.js";
2
+ export declare function loadWalletExplicitLock(lockPath: string): Promise<WalletExplicitLockStateV1 | null>;
3
+ export declare function saveWalletExplicitLock(lockPath: string, state: WalletExplicitLockStateV1): Promise<void>;
4
+ export declare function clearWalletExplicitLock(lockPath: string): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { readFile, rm } from "node:fs/promises";
2
+ import { writeJsonFileAtomic } from "../fs/atomic.js";
3
+ export async function loadWalletExplicitLock(lockPath) {
4
+ try {
5
+ return JSON.parse(await readFile(lockPath, "utf8"));
6
+ }
7
+ catch (error) {
8
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
9
+ return null;
10
+ }
11
+ throw error;
12
+ }
13
+ }
14
+ export async function saveWalletExplicitLock(lockPath, state) {
15
+ await writeJsonFileAtomic(lockPath, state, { mode: 0o600 });
16
+ }
17
+ export async function clearWalletExplicitLock(lockPath) {
18
+ await rm(lockPath, { force: true });
19
+ }
@@ -996,6 +996,7 @@ export async function anchorDomain(options) {
996
996
  dataDir: options.dataDir,
997
997
  databasePath: options.databasePath,
998
998
  secretProvider: provider,
999
+ walletControlLockHeld: true,
999
1000
  paths,
1000
1001
  });
1001
1002
  try {
@@ -623,6 +623,7 @@ export async function sendCog(options) {
623
623
  dataDir: options.dataDir,
624
624
  databasePath: options.databasePath,
625
625
  secretProvider: provider,
626
+ walletControlLockHeld: true,
626
627
  paths,
627
628
  });
628
629
  try {
@@ -763,6 +764,7 @@ export async function lockCogToDomain(options) {
763
764
  dataDir: options.dataDir,
764
765
  databasePath: options.databasePath,
765
766
  secretProvider: provider,
767
+ walletControlLockHeld: true,
766
768
  paths,
767
769
  });
768
770
  try {
@@ -918,6 +920,7 @@ async function runClaimLikeMutation(options, reclaim) {
918
920
  dataDir: options.dataDir,
919
921
  databasePath: options.databasePath,
920
922
  secretProvider: provider,
923
+ walletControlLockHeld: true,
921
924
  paths,
922
925
  });
923
926
  try {
@@ -557,6 +557,7 @@ async function submitDomainAdminMutation(options) {
557
557
  dataDir: options.dataDir,
558
558
  databasePath: options.databasePath,
559
559
  secretProvider: provider,
560
+ walletControlLockHeld: true,
560
561
  paths,
561
562
  });
562
563
  try {
@@ -683,6 +683,7 @@ export async function transferDomain(options) {
683
683
  dataDir: options.dataDir,
684
684
  databasePath: options.databasePath,
685
685
  secretProvider: provider,
686
+ walletControlLockHeld: true,
686
687
  paths,
687
688
  });
688
689
  try {
@@ -916,6 +917,7 @@ async function runSellMutation(options) {
916
917
  dataDir: options.dataDir,
917
918
  databasePath: options.databasePath,
918
919
  secretProvider: provider,
920
+ walletControlLockHeld: true,
919
921
  paths,
920
922
  });
921
923
  try {
@@ -1143,6 +1145,7 @@ export async function buyDomain(options) {
1143
1145
  dataDir: options.dataDir,
1144
1146
  databasePath: options.databasePath,
1145
1147
  secretProvider: provider,
1148
+ walletControlLockHeld: true,
1146
1149
  paths,
1147
1150
  });
1148
1151
  try {
@@ -1267,6 +1267,7 @@ async function submitStandaloneFieldMutation(options) {
1267
1267
  dataDir: options.dataDir,
1268
1268
  databasePath: options.databasePath,
1269
1269
  secretProvider: provider,
1270
+ walletControlLockHeld: true,
1270
1271
  paths,
1271
1272
  });
1272
1273
  try {
@@ -1418,6 +1419,7 @@ async function submitFieldCreateFamily(options) {
1418
1419
  dataDir: options.dataDir,
1419
1420
  databasePath: options.databasePath,
1420
1421
  secretProvider: provider,
1422
+ walletControlLockHeld: true,
1421
1423
  paths,
1422
1424
  });
1423
1425
  try {
@@ -686,6 +686,7 @@ export async function registerDomain(options) {
686
686
  dataDir: options.dataDir,
687
687
  databasePath: options.databasePath,
688
688
  secretProvider: provider,
689
+ walletControlLockHeld: true,
689
690
  paths,
690
691
  });
691
692
  try {
@@ -528,6 +528,7 @@ async function submitReputationMutation(options) {
528
528
  dataDir: options.dataDir,
529
529
  databasePath: options.databasePath,
530
530
  secretProvider: provider,
531
+ walletControlLockHeld: true,
531
532
  paths,
532
533
  });
533
534
  try {
@@ -247,3 +247,8 @@ export interface UnlockSessionStateV1 {
247
247
  sourceStateRevision: number;
248
248
  wrappedSessionKeyMaterial: string;
249
249
  }
250
+ export interface WalletExplicitLockStateV1 {
251
+ schemaVersion: 1;
252
+ walletRootId: string;
253
+ lockedAtUnixMs: number;
254
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@cogcoin/client",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Store-backed Cogcoin client with wallet flows, SQLite persistence, and managed Bitcoin Core integration.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=24.7.0"
8
+ "node": ">=22.0.0"
9
9
  },
10
10
  "homepage": "https://cogcoin.org",
11
11
  "repository": {
@@ -68,6 +68,7 @@
68
68
  "@scure/bip32": "^2.0.1",
69
69
  "@scure/bip39": "^2.0.1",
70
70
  "better-sqlite3": "12.8.0",
71
+ "hash-wasm": "^4.12.0",
71
72
  "zeromq": "6.5.0"
72
73
  },
73
74
  "devDependencies": {