@cogcoin/client 1.1.3 → 1.1.5

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 (88) hide show
  1. package/README.md +4 -5
  2. package/dist/bitcoind/node.js +2 -1
  3. package/dist/bitcoind/progress/tty-renderer.js +3 -2
  4. package/dist/bitcoind/service.js +6 -24
  5. package/dist/bitcoind/types.d.ts +1 -0
  6. package/dist/bitcoind/types.js +1 -0
  7. package/dist/cli/command-registry.d.ts +39 -0
  8. package/dist/cli/command-registry.js +1132 -0
  9. package/dist/cli/commands/client-admin.js +6 -56
  10. package/dist/cli/commands/mining-admin.js +9 -32
  11. package/dist/cli/commands/mining-read.js +15 -56
  12. package/dist/cli/commands/mining-runtime.js +258 -57
  13. package/dist/cli/commands/service-runtime.js +1 -64
  14. package/dist/cli/commands/status.js +2 -15
  15. package/dist/cli/commands/update.js +6 -21
  16. package/dist/cli/commands/wallet-admin.js +18 -120
  17. package/dist/cli/commands/wallet-mutation.js +4 -7
  18. package/dist/cli/commands/wallet-read.js +31 -138
  19. package/dist/cli/context.js +2 -4
  20. package/dist/cli/mining-format.js +8 -2
  21. package/dist/cli/mutation-command-groups.d.ts +11 -11
  22. package/dist/cli/mutation-command-groups.js +9 -18
  23. package/dist/cli/mutation-json.d.ts +1 -17
  24. package/dist/cli/mutation-json.js +1 -28
  25. package/dist/cli/mutation-success.d.ts +0 -1
  26. package/dist/cli/mutation-success.js +0 -19
  27. package/dist/cli/output.d.ts +1 -10
  28. package/dist/cli/output.js +52 -481
  29. package/dist/cli/parse.d.ts +1 -1
  30. package/dist/cli/parse.js +38 -695
  31. package/dist/cli/runner.js +28 -113
  32. package/dist/cli/types.d.ts +7 -8
  33. package/dist/cli/update-notifier.js +1 -1
  34. package/dist/cli/wallet-format.js +1 -1
  35. package/dist/wallet/lifecycle/managed-core.d.ts +23 -0
  36. package/dist/wallet/lifecycle/managed-core.js +257 -0
  37. package/dist/wallet/lifecycle/repair-mining.d.ts +49 -0
  38. package/dist/wallet/lifecycle/repair-mining.js +304 -0
  39. package/dist/wallet/lifecycle/repair-runtime.d.ts +36 -0
  40. package/dist/wallet/lifecycle/repair-runtime.js +206 -0
  41. package/dist/wallet/lifecycle/repair.d.ts +11 -0
  42. package/dist/wallet/lifecycle/repair.js +368 -0
  43. package/dist/wallet/lifecycle/setup.d.ts +16 -0
  44. package/dist/wallet/lifecycle/setup.js +430 -0
  45. package/dist/wallet/lifecycle/types.d.ts +125 -0
  46. package/dist/wallet/lifecycle/types.js +1 -0
  47. package/dist/wallet/lifecycle.d.ts +4 -165
  48. package/dist/wallet/lifecycle.js +3 -1656
  49. package/dist/wallet/mining/candidate.d.ts +60 -0
  50. package/dist/wallet/mining/candidate.js +290 -0
  51. package/dist/wallet/mining/competitiveness.d.ts +22 -0
  52. package/dist/wallet/mining/competitiveness.js +640 -0
  53. package/dist/wallet/mining/control.js +7 -251
  54. package/dist/wallet/mining/cycle.d.ts +39 -0
  55. package/dist/wallet/mining/cycle.js +542 -0
  56. package/dist/wallet/mining/engine-state.d.ts +66 -0
  57. package/dist/wallet/mining/engine-state.js +211 -0
  58. package/dist/wallet/mining/engine-types.d.ts +173 -0
  59. package/dist/wallet/mining/engine-types.js +1 -0
  60. package/dist/wallet/mining/engine-utils.d.ts +7 -0
  61. package/dist/wallet/mining/engine-utils.js +75 -0
  62. package/dist/wallet/mining/events.d.ts +2 -0
  63. package/dist/wallet/mining/events.js +19 -0
  64. package/dist/wallet/mining/lifecycle.d.ts +71 -0
  65. package/dist/wallet/mining/lifecycle.js +355 -0
  66. package/dist/wallet/mining/projection.d.ts +61 -0
  67. package/dist/wallet/mining/projection.js +319 -0
  68. package/dist/wallet/mining/publish.d.ts +79 -0
  69. package/dist/wallet/mining/publish.js +614 -0
  70. package/dist/wallet/mining/runner.d.ts +12 -418
  71. package/dist/wallet/mining/runner.js +274 -3433
  72. package/dist/wallet/mining/supervisor.d.ts +134 -0
  73. package/dist/wallet/mining/supervisor.js +558 -0
  74. package/dist/wallet/mining/visualizer-sync.d.ts +42 -0
  75. package/dist/wallet/mining/visualizer-sync.js +166 -0
  76. package/dist/wallet/mining/visualizer.d.ts +1 -0
  77. package/dist/wallet/mining/visualizer.js +33 -18
  78. package/dist/wallet/read/context.d.ts +5 -1
  79. package/dist/wallet/read/context.js +19 -4
  80. package/dist/wallet/reset.d.ts +1 -1
  81. package/dist/wallet/reset.js +35 -11
  82. package/dist/wallet/runtime.d.ts +0 -6
  83. package/dist/wallet/runtime.js +2 -38
  84. package/dist/wallet/tx/common.d.ts +18 -0
  85. package/dist/wallet/tx/common.js +40 -26
  86. package/package.json +1 -1
  87. package/dist/wallet/state/seed-index.d.ts +0 -43
  88. package/dist/wallet/state/seed-index.js +0 -151
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@cogcoin/client`
2
2
 
3
- `@cogcoin/client@1.1.0` is the reference Cogcoin client package for applications that want a local wallet, durable SQLite-backed state, and a managed Bitcoin Core integration around `@cogcoin/indexer`. It publishes the reusable client APIs, the SQLite adapter, the managed `bitcoind` integration, and the first-party `cogcoin` CLI in one package.
3
+ `@cogcoin/client@1.1.5` is the reference Cogcoin client package for applications that want a local wallet, durable SQLite-backed state, and a managed Bitcoin Core integration around `@cogcoin/indexer`. It publishes the reusable client APIs, the SQLite adapter, the managed `bitcoind` integration, and the first-party `cogcoin` CLI in one package.
4
4
 
5
5
  Use Node 22 or newer.
6
6
 
@@ -131,21 +131,20 @@ Managed node subpath:
131
131
  The installed `cogcoin` command covers the first-party local wallet and node workflow:
132
132
 
133
133
  - update commands such as `update` to compare the current CLI version with the latest npm release and install it
134
- - wallet lifecycle commands such as `init`, `restore`, `wallet delete`, `wallet show-mnemonic`, and `repair`
134
+ - wallet lifecycle commands such as `init`, `reset`, `wallet show-mnemonic`, and `repair`
135
135
  - sync and service commands such as `status`, `sync`, `follow`, `bitcoin start`, `bitcoin stop`, `bitcoin status`, `indexer start`, `indexer stop`, and `indexer status`
136
136
  - domain and field commands such as `register`, `anchor`, `show`, `domains`, `fields`, `buy`, `sell`, and `transfer`
137
137
  - COG and reputation commands such as `send`, `cog lock`, `claim`, `reclaim`, `rep give`, and `rep revoke`
138
138
  - mining commands such as `mine`, `mine start`, `mine stop`, `mine status`, `mine log`, `mine setup`, `mine prompt`, and `mine prompt list`
139
139
 
140
- The CLI also supports stable `--output json` and `--output preview-json` envelopes on the commands that advertise machine-readable output.
141
140
  Use `cogcoin mine prompt <domain>` to set or clear a per-domain mining prompt override for one anchored root domain, and `cogcoin mine prompt list` to inspect the current per-domain prompt state alongside the global fallback prompt.
142
141
  Interactive text invocations periodically check the npm registry for newer `@cogcoin/client` releases and print `npm install -g @cogcoin/client` when a newer version is available.
143
142
  Set `COGCOIN_DISABLE_UPDATE_CHECK=1` to disable the CLI update notice entirely.
144
143
  Ordinary `sync`, `follow`, and wallet-aware read/status flows detach from the managed Bitcoin and indexer services on exit instead of stopping them.
145
144
  Use the explicit `bitcoin ...` and `indexer ...` commands when you want direct service inspection or start/stop control.
146
145
  For provider-backed local wallets, normal reads, mutations, and mining setup flows load local wallet state on demand whenever the local secret provider is available.
147
- `cogcoin restore` and `cogcoin wallet restore` rebuild a fresh local wallet from a 24-word English BIP39 mnemonic and recreate the managed Core wallet replica.
148
- Run `cogcoin sync` afterward to bootstrap the managed Bitcoin/indexer state.
146
+ When no wallet exists yet, `cogcoin init` interactively lets you either create a new wallet or restore an existing one from a 24-word English BIP39 mnemonic, then continues into sync.
147
+ To replace an existing wallet with a different mnemonic, run `cogcoin reset`, choose `clear wallet entropy`, and then rerun `cogcoin init`.
149
148
 
150
149
  ## SQLite Store
151
150
 
@@ -5,6 +5,7 @@ import { promisify } from "node:util";
5
5
  import net from "node:net";
6
6
  import { getBitcoindPath } from "@cogcoin/bitcoin";
7
7
  import { resolveDefaultBitcoindDataDirForTesting } from "../app-paths.js";
8
+ import { DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS } from "./types.js";
8
9
  import { BitcoinRpcClient } from "./rpc.js";
9
10
  const execFileAsync = promisify(execFile);
10
11
  const SUPPORTED_BITCOIND_VERSION = "30.2.0";
@@ -156,7 +157,7 @@ export async function launchManagedBitcoindNode(options) {
156
157
  endpoint: zmqEndpoint,
157
158
  topic: "hashblock",
158
159
  port: zmqPort,
159
- pollIntervalMs: options.pollIntervalMs ?? 15_000,
160
+ pollIntervalMs: options.pollIntervalMs ?? DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS,
160
161
  };
161
162
  const child = spawn(bitcoindPath, buildBitcoindArgsForTesting(resolvedOptions, rpcPort, zmqPort, p2pPort), {
162
163
  stdio: ["ignore", "pipe", "pipe"],
@@ -90,14 +90,15 @@ export class TtyProgressRenderer {
90
90
  const width = Math.max(20, this.#stream.columns ?? 120);
91
91
  const progressLine = formatProgressLine(progress, cogcoinSyncHeight, cogcoinSyncTargetHeight, width, now);
92
92
  const extraLines = (renderOptions.extraLines ?? []).map((line) => truncateLine(line, width));
93
+ const renderedExtraLines = extraLines.length > 0 ? ["", ...extraLines] : [""];
93
94
  const lines = width >= ART_WIDTH
94
95
  ? [...renderFollowFrame(followScene, statusFieldText, now, {
95
96
  artworkCogText: renderOptions.artworkCogText ?? null,
96
97
  artworkSatText: renderOptions.artworkSatText ?? null,
97
98
  artworkStatusLeftText: renderOptions.artworkStatusLeftText ?? null,
98
99
  artworkStatusRightText: renderOptions.artworkStatusRightText ?? null,
99
- }), "", progressLine, "", ...extraLines]
100
- : [truncateLine(NEUTRAL_MESSAGE_TITLE, width), progressLine, "", ...extraLines];
100
+ }), "", progressLine, ...renderedExtraLines]
101
+ : [truncateLine(NEUTRAL_MESSAGE_TITLE, width), progressLine, ...renderedExtraLines];
101
102
  const frame = lines.join("\n");
102
103
  this.#resetFrameIfExternalWritesDetected();
103
104
  if (!this.#rendered) {
@@ -2,7 +2,6 @@ import { randomBytes } from "node:crypto";
2
2
  import { execFile, spawn } from "node:child_process";
3
3
  import { access, constants, mkdir, readFile, readdir, rm } from "node:fs/promises";
4
4
  import { dirname, join } from "node:path";
5
- import { totalmem } from "node:os";
6
5
  import { promisify } from "node:util";
7
6
  import net from "node:net";
8
7
  import { getBitcoindPath } from "@cogcoin/bitcoin";
@@ -12,37 +11,20 @@ import { writeRuntimeStatusFile } from "../wallet/fs/status-file.js";
12
11
  import { stopIndexerDaemonServiceWithLockHeld } from "./indexer-daemon.js";
13
12
  import { createRpcClient, validateNodeConfigForTesting } from "./node.js";
14
13
  import { resolveManagedServicePaths, UNINITIALIZED_WALLET_ROOT_ID } from "./service-paths.js";
15
- import { MANAGED_BITCOIND_SERVICE_API_VERSION as MANAGED_BITCOIND_SERVICE_API_VERSION_VALUE } from "./types.js";
14
+ import { DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS, MANAGED_BITCOIND_SERVICE_API_VERSION as MANAGED_BITCOIND_SERVICE_API_VERSION_VALUE, } from "./types.js";
16
15
  const execFileAsync = promisify(execFile);
17
16
  const LOCAL_HOST = "127.0.0.1";
18
17
  const SUPPORTED_BITCOIND_VERSION = "30.2.0";
19
18
  const DEFAULT_STARTUP_TIMEOUT_MS = 30_000;
20
19
  const DEFAULT_SHUTDOWN_TIMEOUT_MS = 15_000;
21
- const DEFAULT_DBCACHE_MIB = 450;
20
+ const DEFAULT_DBCACHE_MIB = 2048;
22
21
  const claimedUninitializedRuntimeKeys = new Set();
23
- const GIB = 1024 ** 3;
24
22
  export function resolveManagedBitcoindDbcacheMiB(totalRamBytes) {
25
- if (!Number.isFinite(totalRamBytes) || totalRamBytes <= 0) {
26
- return DEFAULT_DBCACHE_MIB;
27
- }
28
- if (totalRamBytes < 8 * GIB) {
29
- return 450;
30
- }
31
- if (totalRamBytes < 16 * GIB) {
32
- return 768;
33
- }
34
- if (totalRamBytes < 32 * GIB) {
35
- return 1024;
36
- }
37
- return 2048;
23
+ void totalRamBytes;
24
+ return DEFAULT_DBCACHE_MIB;
38
25
  }
39
26
  function detectManagedBitcoindDbcacheMiB() {
40
- try {
41
- return resolveManagedBitcoindDbcacheMiB(totalmem());
42
- }
43
- catch {
44
- return DEFAULT_DBCACHE_MIB;
45
- }
27
+ return DEFAULT_DBCACHE_MIB;
46
28
  }
47
29
  function sleep(ms) {
48
30
  return new Promise((resolve) => {
@@ -826,7 +808,7 @@ export async function attachOrStartManagedBitcoindService(options) {
826
808
  endpoint: `tcp://${LOCAL_HOST}:${runtimeConfig.zmqPort}`,
827
809
  topic: "hashblock",
828
810
  port: runtimeConfig.zmqPort,
829
- pollIntervalMs: startOptions.pollIntervalMs ?? 15_000,
811
+ pollIntervalMs: startOptions.pollIntervalMs ?? DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS,
830
812
  };
831
813
  const spawnOptions = startOptions.serviceLifetime === "ephemeral"
832
814
  ? {
@@ -87,6 +87,7 @@ export interface ManagedBitcoindRuntimeConfig {
87
87
  getblockArchiveEndHeight?: number | null;
88
88
  getblockArchiveSha256?: string | null;
89
89
  }
90
+ export declare const DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS = 2000;
90
91
  export declare const MANAGED_BITCOIND_SERVICE_API_VERSION = "cogcoin/bitcoind-service/v1";
91
92
  export type ManagedBitcoindServiceState = "starting" | "ready" | "stopping" | "failed";
92
93
  export interface ManagedBitcoindServiceStatus {
@@ -1,3 +1,4 @@
1
+ export const DEFAULT_MANAGED_BITCOIND_FOLLOW_POLL_INTERVAL_MS = 2_000;
1
2
  export const MANAGED_BITCOIND_SERVICE_API_VERSION = "cogcoin/bitcoind-service/v1";
2
3
  export const INDEXER_DAEMON_SERVICE_API_VERSION = "cogcoin/indexer-ipc/v1";
3
4
  export const INDEXER_DAEMON_SCHEMA_VERSION = "cogcoin/indexer-db/v1";
@@ -0,0 +1,39 @@
1
+ export type CommandHandlerFamily = "status" | "update" | "sync" | "follow" | "client-admin" | "service-runtime" | "wallet-admin" | "wallet-read" | "wallet-mutation" | "mining-admin" | "mining-runtime" | "mining-read";
2
+ export type CommandName = "init" | "reset" | "repair" | "update" | "sync" | "status" | "client-lock" | "client-change-password" | "client-unlock" | "follow" | "bitcoin-start" | "bitcoin-stop" | "bitcoin-status" | "bitcoin-transfer" | "indexer-start" | "indexer-stop" | "indexer-status" | "anchor" | "register" | "transfer" | "sell" | "unsell" | "buy" | "domain-endpoint-set" | "domain-endpoint-clear" | "domain-delegate-set" | "domain-delegate-clear" | "domain-miner-set" | "domain-miner-clear" | "domain-canonical" | "fields" | "field" | "field-create" | "field-set" | "field-clear" | "send" | "claim" | "reclaim" | "cog-lock" | "rep-give" | "rep-revoke" | "mine" | "mine-start" | "mine-stop" | "mine-setup" | "mine-prompt" | "mine-prompt-list" | "mine-status" | "mine-log" | "wallet-show-mnemonic" | "wallet-status" | "address" | "ids" | "balance" | "locks" | "domains" | "show";
3
+ type AliasMatchMode = "always" | "requires-arg" | "end-or-flag";
4
+ interface HelpEntry {
5
+ usage: string;
6
+ description: string;
7
+ }
8
+ interface CommandAlias {
9
+ tokens: readonly string[];
10
+ matchMode?: AliasMatchMode;
11
+ }
12
+ export interface CommandSpec {
13
+ id: CommandName;
14
+ handlerFamily: CommandHandlerFamily;
15
+ supportsYes: boolean;
16
+ supportsSatvb: boolean;
17
+ aliases: readonly CommandAlias[];
18
+ helpEntries: readonly HelpEntry[];
19
+ describeCommand(args: readonly string[], options: {
20
+ follow: boolean;
21
+ }): string;
22
+ }
23
+ export interface CommandMatch {
24
+ command: CommandName;
25
+ consumedTokens: number;
26
+ invokedTokens: readonly string[];
27
+ }
28
+ export declare function getCommandSpec(command: CommandName | null): CommandSpec | null;
29
+ export declare function resolveCommandMatch(argv: readonly string[], startIndex: number): CommandMatch | null;
30
+ export declare function resolveUnknownCommandError(argv: readonly string[], startIndex: number): string;
31
+ export declare function getCommandHandlerFamily(command: CommandName | null): CommandHandlerFamily | null;
32
+ export declare function commandSupportsYesFlag(command: CommandName | null): boolean;
33
+ export declare function commandSupportsSatvb(command: CommandName | null): boolean;
34
+ export declare function describeCanonicalCommandFromArgs(command: CommandName | null, args: readonly string[], options?: {
35
+ follow: boolean;
36
+ }): string;
37
+ export declare function renderHelpText(): string;
38
+ export declare function listCommandSpecsForTesting(): readonly CommandSpec[];
39
+ export {};