@cogcoin/client 0.5.15 → 1.0.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.
Files changed (172) hide show
  1. package/README.md +80 -25
  2. package/dist/app-paths.d.ts +5 -6
  3. package/dist/app-paths.js +8 -16
  4. package/dist/art/balance.txt +10 -0
  5. package/dist/art/welcome.txt +16 -0
  6. package/dist/bitcoind/bootstrap/controller.d.ts +1 -0
  7. package/dist/bitcoind/bootstrap/controller.js +53 -1
  8. package/dist/bitcoind/client/follow-block-times.d.ts +1 -0
  9. package/dist/bitcoind/client/follow-block-times.js +1 -1
  10. package/dist/bitcoind/client/internal-types.d.ts +7 -3
  11. package/dist/bitcoind/client/managed-client.d.ts +4 -2
  12. package/dist/bitcoind/client/managed-client.js +14 -0
  13. package/dist/bitcoind/client/sync-engine.js +72 -11
  14. package/dist/bitcoind/hash-order.d.ts +4 -0
  15. package/dist/bitcoind/hash-order.js +13 -0
  16. package/dist/bitcoind/indexer-daemon-main.js +11 -3
  17. package/dist/bitcoind/normalize.js +3 -2
  18. package/dist/bitcoind/processing-start-height.d.ts +5 -0
  19. package/dist/bitcoind/processing-start-height.js +7 -0
  20. package/dist/bitcoind/progress/constants.d.ts +4 -0
  21. package/dist/bitcoind/progress/constants.js +4 -0
  22. package/dist/bitcoind/progress/controller.d.ts +2 -1
  23. package/dist/bitcoind/progress/controller.js +3 -3
  24. package/dist/bitcoind/progress/follow-scene.d.ts +6 -2
  25. package/dist/bitcoind/progress/follow-scene.js +29 -6
  26. package/dist/bitcoind/progress/formatting.d.ts +1 -0
  27. package/dist/bitcoind/progress/formatting.js +6 -0
  28. package/dist/bitcoind/progress/train-scene.js +37 -18
  29. package/dist/bitcoind/progress/tty-renderer.d.ts +6 -1
  30. package/dist/bitcoind/progress/tty-renderer.js +8 -4
  31. package/dist/bitcoind/rpc.d.ts +2 -1
  32. package/dist/bitcoind/rpc.js +3 -0
  33. package/dist/bitcoind/types.d.ts +6 -0
  34. package/dist/bytes.d.ts +1 -0
  35. package/dist/bytes.js +3 -0
  36. package/dist/cli/art.d.ts +2 -0
  37. package/dist/cli/art.js +37 -0
  38. package/dist/cli/commands/client-admin.d.ts +2 -0
  39. package/dist/cli/commands/client-admin.js +91 -0
  40. package/dist/cli/commands/follow.js +0 -2
  41. package/dist/cli/commands/mining-admin.js +6 -47
  42. package/dist/cli/commands/mining-read.js +11 -50
  43. package/dist/cli/commands/mining-runtime.js +38 -3
  44. package/dist/cli/commands/service-runtime.js +0 -2
  45. package/dist/cli/commands/status.js +8 -2
  46. package/dist/cli/commands/sync.js +51 -4
  47. package/dist/cli/commands/wallet-admin.js +142 -136
  48. package/dist/cli/commands/wallet-mutation.js +91 -79
  49. package/dist/cli/commands/wallet-read.js +15 -18
  50. package/dist/cli/context.js +4 -14
  51. package/dist/cli/mining-format.d.ts +0 -1
  52. package/dist/cli/mining-format.js +5 -37
  53. package/dist/cli/mining-json.d.ts +0 -18
  54. package/dist/cli/mining-json.js +0 -35
  55. package/dist/cli/mutation-command-groups.d.ts +1 -2
  56. package/dist/cli/mutation-command-groups.js +0 -5
  57. package/dist/cli/mutation-json.d.ts +24 -145
  58. package/dist/cli/mutation-json.js +30 -136
  59. package/dist/cli/mutation-resolved-json.d.ts +0 -7
  60. package/dist/cli/mutation-resolved-json.js +4 -10
  61. package/dist/cli/mutation-success.d.ts +2 -0
  62. package/dist/cli/mutation-success.js +11 -1
  63. package/dist/cli/mutation-text-format.js +1 -3
  64. package/dist/cli/output.d.ts +1 -1
  65. package/dist/cli/output.js +254 -231
  66. package/dist/cli/parse.d.ts +1 -1
  67. package/dist/cli/parse.js +93 -122
  68. package/dist/cli/preview-json.d.ts +17 -120
  69. package/dist/cli/preview-json.js +14 -97
  70. package/dist/cli/prompt.js +8 -13
  71. package/dist/cli/read-json.d.ts +15 -37
  72. package/dist/cli/read-json.js +44 -140
  73. package/dist/cli/runner.js +10 -13
  74. package/dist/cli/types.d.ts +8 -17
  75. package/dist/cli/types.js +0 -2
  76. package/dist/cli/wallet-format.d.ts +1 -0
  77. package/dist/cli/wallet-format.js +205 -144
  78. package/dist/cli/workflow-hints.d.ts +3 -3
  79. package/dist/cli/workflow-hints.js +11 -8
  80. package/dist/client/default-client.d.ts +3 -1
  81. package/dist/client/default-client.js +45 -2
  82. package/dist/client/factory.js +1 -1
  83. package/dist/client/initialization.js +23 -0
  84. package/dist/client/persistence.js +5 -5
  85. package/dist/client/store-adapter.js +1 -0
  86. package/dist/sqlite/checkpoints.d.ts +1 -0
  87. package/dist/sqlite/checkpoints.js +7 -0
  88. package/dist/sqlite/store.js +14 -1
  89. package/dist/types.d.ts +1 -0
  90. package/dist/wallet/coin-control.d.ts +41 -12
  91. package/dist/wallet/coin-control.js +100 -428
  92. package/dist/wallet/descriptor-normalization.d.ts +1 -3
  93. package/dist/wallet/descriptor-normalization.js +0 -16
  94. package/dist/wallet/lifecycle.d.ts +7 -99
  95. package/dist/wallet/lifecycle.js +513 -968
  96. package/dist/wallet/managed-core-wallet.d.ts +13 -0
  97. package/dist/wallet/managed-core-wallet.js +20 -0
  98. package/dist/wallet/mining/constants.d.ts +5 -12
  99. package/dist/wallet/mining/constants.js +5 -12
  100. package/dist/wallet/mining/control.d.ts +1 -13
  101. package/dist/wallet/mining/control.js +45 -349
  102. package/dist/wallet/mining/index.d.ts +3 -4
  103. package/dist/wallet/mining/index.js +1 -2
  104. package/dist/wallet/mining/runner.d.ts +116 -13
  105. package/dist/wallet/mining/runner.js +885 -501
  106. package/dist/wallet/mining/runtime-artifacts.js +23 -3
  107. package/dist/wallet/mining/sentence-protocol.d.ts +44 -0
  108. package/dist/wallet/mining/sentence-protocol.js +123 -0
  109. package/dist/wallet/mining/sentences.d.ts +4 -8
  110. package/dist/wallet/mining/sentences.js +3 -52
  111. package/dist/wallet/mining/state.d.ts +11 -6
  112. package/dist/wallet/mining/state.js +7 -6
  113. package/dist/wallet/mining/types.d.ts +2 -30
  114. package/dist/wallet/mining/visualizer.d.ts +31 -3
  115. package/dist/wallet/mining/visualizer.js +135 -13
  116. package/dist/wallet/read/context.d.ts +0 -2
  117. package/dist/wallet/read/context.js +119 -140
  118. package/dist/wallet/read/filter.js +2 -11
  119. package/dist/wallet/read/index.d.ts +1 -1
  120. package/dist/wallet/read/project.js +24 -77
  121. package/dist/wallet/read/types.d.ts +10 -25
  122. package/dist/wallet/reset.d.ts +0 -1
  123. package/dist/wallet/reset.js +60 -138
  124. package/dist/wallet/root-resolution.d.ts +1 -5
  125. package/dist/wallet/root-resolution.js +0 -18
  126. package/dist/wallet/runtime.d.ts +0 -6
  127. package/dist/wallet/runtime.js +0 -8
  128. package/dist/wallet/state/client-password-agent.js +208 -0
  129. package/dist/wallet/state/client-password.d.ts +65 -0
  130. package/dist/wallet/state/client-password.js +952 -0
  131. package/dist/wallet/state/crypto.d.ts +1 -20
  132. package/dist/wallet/state/crypto.js +0 -63
  133. package/dist/wallet/state/provider.d.ts +23 -11
  134. package/dist/wallet/state/provider.js +248 -290
  135. package/dist/wallet/state/storage.d.ts +2 -2
  136. package/dist/wallet/state/storage.js +48 -16
  137. package/dist/wallet/tx/anchor.d.ts +3 -28
  138. package/dist/wallet/tx/anchor.js +349 -1250
  139. package/dist/wallet/tx/bitcoin-transfer.d.ts +35 -0
  140. package/dist/wallet/tx/bitcoin-transfer.js +200 -0
  141. package/dist/wallet/tx/cog.d.ts +5 -1
  142. package/dist/wallet/tx/cog.js +149 -185
  143. package/dist/wallet/tx/common.d.ts +61 -8
  144. package/dist/wallet/tx/common.js +266 -146
  145. package/dist/wallet/tx/domain-admin.d.ts +3 -1
  146. package/dist/wallet/tx/domain-admin.js +61 -99
  147. package/dist/wallet/tx/domain-market.d.ts +5 -1
  148. package/dist/wallet/tx/domain-market.js +221 -228
  149. package/dist/wallet/tx/field.d.ts +4 -10
  150. package/dist/wallet/tx/field.js +83 -924
  151. package/dist/wallet/tx/identity-selector.d.ts +9 -3
  152. package/dist/wallet/tx/identity-selector.js +17 -35
  153. package/dist/wallet/tx/index.d.ts +3 -1
  154. package/dist/wallet/tx/index.js +2 -1
  155. package/dist/wallet/tx/register.d.ts +3 -1
  156. package/dist/wallet/tx/register.js +62 -220
  157. package/dist/wallet/tx/reputation.d.ts +3 -1
  158. package/dist/wallet/tx/reputation.js +58 -95
  159. package/dist/wallet/types.d.ts +8 -122
  160. package/package.json +5 -5
  161. package/dist/wallet/archive.d.ts +0 -4
  162. package/dist/wallet/archive.js +0 -41
  163. package/dist/wallet/mining/hook-protocol.d.ts +0 -47
  164. package/dist/wallet/mining/hook-protocol.js +0 -161
  165. package/dist/wallet/mining/hook-runner.js +0 -52
  166. package/dist/wallet/mining/hooks.d.ts +0 -38
  167. package/dist/wallet/mining/hooks.js +0 -520
  168. package/dist/wallet/state/explicit-lock.d.ts +0 -4
  169. package/dist/wallet/state/explicit-lock.js +0 -19
  170. package/dist/wallet/state/session.d.ts +0 -12
  171. package/dist/wallet/state/session.js +0 -23
  172. /package/dist/wallet/{mining/hook-runner.d.ts → state/client-password-agent.d.ts} +0 -0
@@ -1,34 +1,15 @@
1
- import type { Argon2EnvelopeParams, EncryptedEnvelopeV1 } from "../types.js";
1
+ import type { EncryptedEnvelopeV1 } from "../types.js";
2
2
  import type { WalletSecretProvider, WalletSecretReference } from "./provider.js";
3
- export interface DeriveKeyOptions {
4
- memoryKib?: number;
5
- iterations?: number;
6
- parallelism?: number;
7
- salt?: Uint8Array;
8
- }
9
- export interface DerivedKeyMaterial {
10
- readonly key: Buffer;
11
- readonly params: Argon2EnvelopeParams;
12
- }
13
- export declare function deriveKeyFromPassphrase(passphrase: Uint8Array | string, options?: DeriveKeyOptions): Promise<DerivedKeyMaterial>;
14
- export declare function rederiveKeyFromEnvelope(passphrase: Uint8Array | string, envelope: EncryptedEnvelopeV1): Promise<Buffer>;
15
3
  export declare function encryptBytesWithKey(plaintext: Uint8Array, key: Uint8Array, metadata: {
16
4
  format: string;
17
5
  wrappedBy: string;
18
6
  walletRootIdHint?: string | null;
19
- argon2id?: Argon2EnvelopeParams | null;
20
7
  secretProvider?: WalletSecretReference | null;
21
8
  }): EncryptedEnvelopeV1;
22
9
  export declare function decryptBytesWithKey(envelope: EncryptedEnvelopeV1, key: Uint8Array): Buffer;
23
- export declare function encryptJsonWithPassphrase<T>(value: T, passphrase: Uint8Array | string, metadata: {
24
- format: string;
25
- wrappedBy?: string;
26
- walletRootIdHint?: string | null;
27
- }): Promise<EncryptedEnvelopeV1>;
28
10
  export declare function encryptJsonWithSecretProvider<T>(value: T, provider: WalletSecretProvider, secretReference: WalletSecretReference, metadata: {
29
11
  format: string;
30
12
  wrappedBy?: string;
31
13
  walletRootIdHint?: string | null;
32
14
  }): Promise<EncryptedEnvelopeV1>;
33
- export declare function decryptJsonWithPassphrase<T>(envelope: EncryptedEnvelopeV1, passphrase: Uint8Array | string): Promise<T>;
34
15
  export declare function decryptJsonWithSecretProvider<T>(envelope: EncryptedEnvelopeV1, provider: WalletSecretProvider): Promise<T>;
@@ -1,11 +1,5 @@
1
- import { argon2id } from "hash-wasm";
2
1
  import { createCipheriv, createDecipheriv, randomBytes, } from "node:crypto";
3
- const DEFAULT_ARGON2_MEMORY_KIB = 65_536;
4
- const DEFAULT_ARGON2_ITERATIONS = 3;
5
- const DEFAULT_ARGON2_PARALLELISM = 1;
6
- const DERIVED_KEY_LENGTH = 32;
7
2
  const GCM_NONCE_BYTES = 12;
8
- const ARGON2_SALT_BYTES = 16;
9
3
  const BIGINT_JSON_TAG = "$cogcoinBigInt";
10
4
  function jsonReplacer(_key, value) {
11
5
  if (typeof value === "bigint") {
@@ -24,48 +18,6 @@ function jsonReviver(_key, value) {
24
18
  }
25
19
  return value;
26
20
  }
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",
36
- });
37
- return Buffer.from(derivedKey);
38
- }
39
- export async function deriveKeyFromPassphrase(passphrase, options = {}) {
40
- const salt = Buffer.from(options.salt ?? randomBytes(ARGON2_SALT_BYTES));
41
- const passphraseBytes = typeof passphrase === "string"
42
- ? Buffer.from(passphrase, "utf8")
43
- : Buffer.from(passphrase);
44
- const memoryKib = options.memoryKib ?? DEFAULT_ARGON2_MEMORY_KIB;
45
- const iterations = options.iterations ?? DEFAULT_ARGON2_ITERATIONS;
46
- const parallelism = options.parallelism ?? DEFAULT_ARGON2_PARALLELISM;
47
- const key = await deriveArgon2Key(passphraseBytes, salt, memoryKib, iterations, parallelism);
48
- return {
49
- key,
50
- params: {
51
- name: "argon2id",
52
- memoryKib,
53
- iterations,
54
- parallelism,
55
- salt: salt.toString("base64"),
56
- },
57
- };
58
- }
59
- export async function rederiveKeyFromEnvelope(passphrase, envelope) {
60
- if (envelope.argon2id == null) {
61
- throw new Error("wallet_envelope_not_passphrase_wrapped");
62
- }
63
- const passphraseBytes = typeof passphrase === "string"
64
- ? Buffer.from(passphrase, "utf8")
65
- : Buffer.from(passphrase);
66
- const salt = Buffer.from(envelope.argon2id.salt, "base64");
67
- return deriveArgon2Key(passphraseBytes, salt, envelope.argon2id.memoryKib, envelope.argon2id.iterations, envelope.argon2id.parallelism);
68
- }
69
21
  export function encryptBytesWithKey(plaintext, key, metadata) {
70
22
  const nonce = randomBytes(GCM_NONCE_BYTES);
71
23
  const cipher = createCipheriv("aes-256-gcm", Buffer.from(key), nonce);
@@ -77,7 +29,6 @@ export function encryptBytesWithKey(plaintext, key, metadata) {
77
29
  cipher: "aes-256-gcm",
78
30
  wrappedBy: metadata.wrappedBy,
79
31
  walletRootIdHint: metadata.walletRootIdHint ?? null,
80
- argon2id: metadata.argon2id ?? null,
81
32
  secretProvider: metadata.secretProvider ?? null,
82
33
  nonce: nonce.toString("base64"),
83
34
  tag: tag.toString("base64"),
@@ -92,15 +43,6 @@ export function decryptBytesWithKey(envelope, key) {
92
43
  decipher.final(),
93
44
  ]);
94
45
  }
95
- export async function encryptJsonWithPassphrase(value, passphrase, metadata) {
96
- const derived = await deriveKeyFromPassphrase(passphrase);
97
- return encryptBytesWithKey(Buffer.from(JSON.stringify(value, jsonReplacer)), derived.key, {
98
- format: metadata.format,
99
- wrappedBy: metadata.wrappedBy ?? "passphrase",
100
- walletRootIdHint: metadata.walletRootIdHint ?? null,
101
- argon2id: derived.params,
102
- });
103
- }
104
46
  export async function encryptJsonWithSecretProvider(value, provider, secretReference, metadata) {
105
47
  const key = await provider.loadSecret(secretReference.keyId);
106
48
  return encryptBytesWithKey(Buffer.from(JSON.stringify(value, jsonReplacer)), key, {
@@ -110,11 +52,6 @@ export async function encryptJsonWithSecretProvider(value, provider, secretRefer
110
52
  secretProvider: secretReference,
111
53
  });
112
54
  }
113
- export async function decryptJsonWithPassphrase(envelope, passphrase) {
114
- const key = await rederiveKeyFromEnvelope(passphrase, envelope);
115
- const plaintext = decryptBytesWithKey(envelope, key);
116
- return JSON.parse(plaintext.toString("utf8"), jsonReviver);
117
- }
118
55
  export async function decryptJsonWithSecretProvider(envelope, provider) {
119
56
  if (envelope.secretProvider == null) {
120
57
  throw new Error("wallet_envelope_missing_secret_provider");
@@ -1,17 +1,8 @@
1
- export interface LinuxSecretToolResult {
2
- stdout: string;
3
- stderr: string;
4
- exitCode: number | null;
5
- signal: NodeJS.Signals | null;
6
- }
7
- export interface LinuxSecretToolInvocationOptions {
8
- stdin?: string;
9
- }
10
- export type LinuxSecretToolRunner = (args: readonly string[], options?: LinuxSecretToolInvocationOptions) => Promise<LinuxSecretToolResult>;
1
+ import { type ClientPasswordPrompt, type ClientPasswordReadiness, type ClientPasswordSessionStatus, type ClientPasswordSetupAction } from "./client-password.js";
11
2
  export interface DefaultWalletSecretProviderFactoryOptions {
12
3
  platform?: NodeJS.Platform;
13
- linuxSecretToolRunner?: LinuxSecretToolRunner;
14
4
  stateRoot?: string;
5
+ runtimeRoot?: string;
15
6
  }
16
7
  export interface WalletSecretReference {
17
8
  kind: string;
@@ -22,6 +13,13 @@ export interface WalletSecretProvider {
22
13
  loadSecret(keyId: string): Promise<Uint8Array>;
23
14
  storeSecret(keyId: string, secret: Uint8Array): Promise<void>;
24
15
  deleteSecret(keyId: string): Promise<void>;
16
+ withPrompter?(prompter: ClientPasswordPrompt): WalletSecretProvider;
17
+ inspectClientPasswordReadiness?(): Promise<ClientPasswordReadiness>;
18
+ ensureClientPasswordConfigured?(prompter: ClientPasswordPrompt): Promise<ClientPasswordSetupAction>;
19
+ changeClientPassword?(prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
20
+ unlockClientPasswordSession?(prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
21
+ lockClientPasswordSession?(): Promise<ClientPasswordSessionStatus>;
22
+ readClientPasswordSessionStatus?(): Promise<ClientPasswordSessionStatus>;
25
23
  }
26
24
  export declare function createWalletSecretReference(walletRootId: string): WalletSecretReference;
27
25
  export declare function createWalletPendingInitSecretReference(stateRoot: string): WalletSecretReference;
@@ -31,9 +29,23 @@ export declare class MemoryWalletSecretProvider implements WalletSecretProvider
31
29
  loadSecret(keyId: string): Promise<Uint8Array>;
32
30
  storeSecret(keyId: string, secret: Uint8Array): Promise<void>;
33
31
  deleteSecret(keyId: string): Promise<void>;
32
+ withPrompter(_prompter: ClientPasswordPrompt): WalletSecretProvider;
33
+ inspectClientPasswordReadiness(): Promise<ClientPasswordReadiness>;
34
+ ensureClientPasswordConfigured(_prompter: ClientPasswordPrompt): Promise<ClientPasswordSetupAction>;
35
+ unlockClientPasswordSession(_prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
36
+ changeClientPassword(_prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
37
+ lockClientPasswordSession(): Promise<ClientPasswordSessionStatus>;
38
+ readClientPasswordSessionStatus(): Promise<ClientPasswordSessionStatus>;
34
39
  }
35
40
  export declare function createDefaultWalletSecretProvider(): WalletSecretProvider;
36
41
  export declare function createDefaultWalletSecretProviderForTesting(options?: DefaultWalletSecretProviderFactoryOptions): WalletSecretProvider;
37
42
  export declare function createLazyDefaultWalletSecretProvider(): WalletSecretProvider;
38
43
  export declare function createMemoryWalletSecretProviderForTesting(): WalletSecretProvider;
44
+ export declare function withInteractiveWalletSecretProvider(provider: WalletSecretProvider, prompter: ClientPasswordPrompt): WalletSecretProvider;
45
+ export declare function ensureClientPasswordConfigured(provider: WalletSecretProvider, prompter: ClientPasswordPrompt): Promise<ClientPasswordSetupAction>;
46
+ export declare function inspectClientPasswordSetupReadiness(provider: WalletSecretProvider): Promise<ClientPasswordReadiness>;
47
+ export declare function unlockClientPassword(provider: WalletSecretProvider, prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
48
+ export declare function changeClientPassword(provider: WalletSecretProvider, prompter: ClientPasswordPrompt): Promise<ClientPasswordSessionStatus>;
49
+ export declare function lockClientPassword(provider: WalletSecretProvider): Promise<ClientPasswordSessionStatus>;
50
+ export declare function readClientPasswordStatus(provider: WalletSecretProvider): Promise<ClientPasswordSessionStatus>;
39
51
  export declare function createWalletRootId(): string;