@cogcoin/client 1.1.8 → 1.1.10

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 (295) hide show
  1. package/README.md +1 -1
  2. package/dist/bitcoind/managed-bitcoind-service-config.d.ts +13 -0
  3. package/dist/bitcoind/managed-bitcoind-service-config.js +165 -0
  4. package/dist/bitcoind/managed-bitcoind-service-lifecycle.d.ts +28 -0
  5. package/dist/bitcoind/managed-bitcoind-service-lifecycle.js +290 -0
  6. package/dist/bitcoind/managed-bitcoind-service-process.d.ts +8 -0
  7. package/dist/bitcoind/managed-bitcoind-service-process.js +48 -0
  8. package/dist/bitcoind/managed-bitcoind-service-replica.d.ts +8 -0
  9. package/dist/bitcoind/managed-bitcoind-service-replica.js +142 -0
  10. package/dist/bitcoind/managed-bitcoind-service-status.d.ts +42 -0
  11. package/dist/bitcoind/managed-bitcoind-service-status.js +178 -0
  12. package/dist/bitcoind/managed-bitcoind-service-types.d.ts +36 -0
  13. package/dist/bitcoind/managed-bitcoind-service-types.js +1 -0
  14. package/dist/bitcoind/service.d.ts +7 -63
  15. package/dist/bitcoind/service.js +7 -797
  16. package/dist/cli/commands/mining-read.js +1 -1
  17. package/dist/cli/commands/wallet-mutation/anchor.d.ts +2 -0
  18. package/dist/cli/commands/wallet-mutation/anchor.js +33 -0
  19. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.d.ts +2 -0
  20. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.js +32 -0
  21. package/dist/cli/commands/wallet-mutation/cog.d.ts +2 -0
  22. package/dist/cli/commands/wallet-mutation/cog.js +131 -0
  23. package/dist/cli/commands/wallet-mutation/context.d.ts +3 -0
  24. package/dist/cli/commands/wallet-mutation/context.js +18 -0
  25. package/dist/cli/commands/wallet-mutation/domain-admin.d.ts +2 -0
  26. package/dist/cli/commands/wallet-mutation/domain-admin.js +173 -0
  27. package/dist/cli/commands/wallet-mutation/domain-market.d.ts +2 -0
  28. package/dist/cli/commands/wallet-mutation/domain-market.js +107 -0
  29. package/dist/cli/commands/wallet-mutation/field.d.ts +2 -0
  30. package/dist/cli/commands/wallet-mutation/field.js +125 -0
  31. package/dist/cli/commands/wallet-mutation/register.d.ts +2 -0
  32. package/dist/cli/commands/wallet-mutation/register.js +38 -0
  33. package/dist/cli/commands/wallet-mutation/registry.d.ts +3 -0
  34. package/dist/cli/commands/wallet-mutation/registry.js +39 -0
  35. package/dist/cli/commands/wallet-mutation/reputation.d.ts +2 -0
  36. package/dist/cli/commands/wallet-mutation/reputation.js +57 -0
  37. package/dist/cli/commands/wallet-mutation/types.d.ts +32 -0
  38. package/dist/cli/commands/wallet-mutation/types.js +1 -0
  39. package/dist/cli/commands/wallet-mutation.js +13 -765
  40. package/dist/cli/commands/wallet-read.js +4 -4
  41. package/dist/cli/mutation-success.d.ts +0 -2
  42. package/dist/cli/output/classify.d.ts +7 -0
  43. package/dist/cli/output/classify.js +94 -0
  44. package/dist/cli/output/render.d.ts +2 -0
  45. package/dist/cli/output/render.js +13 -0
  46. package/dist/cli/output/rules/cli-surface.d.ts +2 -0
  47. package/dist/cli/output/rules/cli-surface.js +110 -0
  48. package/dist/cli/output/rules/generic.d.ts +2 -0
  49. package/dist/cli/output/rules/generic.js +13 -0
  50. package/dist/cli/output/rules/index.d.ts +2 -0
  51. package/dist/cli/output/rules/index.js +24 -0
  52. package/dist/cli/output/rules/mining-update.d.ts +2 -0
  53. package/dist/cli/output/rules/mining-update.js +68 -0
  54. package/dist/cli/output/rules/services.d.ts +2 -0
  55. package/dist/cli/output/rules/services.js +110 -0
  56. package/dist/cli/output/rules/wallet-admin.d.ts +2 -0
  57. package/dist/cli/output/rules/wallet-admin.js +224 -0
  58. package/dist/cli/output/rules/wallet-mutations.d.ts +2 -0
  59. package/dist/cli/output/rules/wallet-mutations.js +274 -0
  60. package/dist/cli/output/types.d.ts +16 -0
  61. package/dist/cli/output/types.js +1 -0
  62. package/dist/cli/output.d.ts +2 -168
  63. package/dist/cli/output.js +6 -989
  64. package/dist/cli/pagination.d.ts +15 -0
  65. package/dist/cli/pagination.js +16 -0
  66. package/dist/cli/recommendations.d.ts +4 -0
  67. package/dist/cli/recommendations.js +108 -0
  68. package/dist/cli/wallet-format/availability.d.ts +5 -0
  69. package/dist/cli/wallet-format/availability.js +96 -0
  70. package/dist/cli/wallet-format/balance.d.ts +2 -0
  71. package/dist/cli/wallet-format/balance.js +162 -0
  72. package/dist/cli/wallet-format/domains.d.ts +8 -0
  73. package/dist/cli/wallet-format/domains.js +84 -0
  74. package/dist/cli/wallet-format/fields.d.ts +6 -0
  75. package/dist/cli/wallet-format/fields.js +61 -0
  76. package/dist/cli/wallet-format/identity.d.ts +5 -0
  77. package/dist/cli/wallet-format/identity.js +19 -0
  78. package/dist/cli/wallet-format/locks.d.ts +7 -0
  79. package/dist/cli/wallet-format/locks.js +52 -0
  80. package/dist/cli/wallet-format/overview.d.ts +2 -0
  81. package/dist/cli/wallet-format/overview.js +122 -0
  82. package/dist/cli/wallet-format/pending.d.ts +13 -0
  83. package/dist/cli/wallet-format/pending.js +101 -0
  84. package/dist/cli/wallet-format/shared.d.ts +7 -0
  85. package/dist/cli/wallet-format/shared.js +31 -0
  86. package/dist/cli/wallet-format/status.d.ts +3 -0
  87. package/dist/cli/wallet-format/status.js +27 -0
  88. package/dist/cli/wallet-format.d.ts +8 -30
  89. package/dist/cli/wallet-format.js +8 -830
  90. package/dist/cli/wallet-read-helpers.d.ts +6 -0
  91. package/dist/cli/wallet-read-helpers.js +17 -0
  92. package/dist/wallet/mining/candidate.d.ts +1 -1
  93. package/dist/wallet/mining/candidate.js +3 -3
  94. package/dist/wallet/mining/constants.d.ts +2 -2
  95. package/dist/wallet/mining/constants.js +2 -2
  96. package/dist/wallet/mining/engine-types.d.ts +1 -0
  97. package/dist/wallet/mining/engine-types.js +9 -1
  98. package/dist/wallet/mining/publish.js +3 -6
  99. package/dist/wallet/mining/runner.js +30 -18
  100. package/dist/wallet/mining/sentence-protocol.d.ts +2 -2
  101. package/dist/wallet/mining/sentences.js +8 -8
  102. package/dist/wallet/mining/visualizer.js +7 -6
  103. package/dist/wallet/read/context.d.ts +4 -10
  104. package/dist/wallet/read/context.js +4 -227
  105. package/dist/wallet/read/local-state.d.ts +28 -0
  106. package/dist/wallet/read/local-state.js +233 -0
  107. package/dist/wallet/read/managed-bitcoind.d.ts +30 -0
  108. package/dist/wallet/read/managed-bitcoind.js +138 -0
  109. package/dist/wallet/read/managed-indexer.d.ts +23 -0
  110. package/dist/wallet/read/managed-indexer.js +87 -0
  111. package/dist/wallet/read/managed-services.d.ts +6 -21
  112. package/dist/wallet/read/managed-services.js +23 -196
  113. package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
  114. package/dist/wallet/tx/anchor/confirm.js +60 -0
  115. package/dist/wallet/tx/anchor/draft.d.ts +39 -0
  116. package/dist/wallet/tx/anchor/draft.js +167 -0
  117. package/dist/wallet/tx/anchor/index.d.ts +5 -0
  118. package/dist/wallet/tx/anchor/index.js +148 -0
  119. package/dist/wallet/tx/anchor/intent.d.ts +61 -0
  120. package/dist/wallet/tx/anchor/intent.js +101 -0
  121. package/dist/wallet/tx/anchor/plan.d.ts +3 -0
  122. package/dist/wallet/tx/anchor/plan.js +18 -0
  123. package/dist/wallet/tx/anchor/result.d.ts +25 -0
  124. package/dist/wallet/tx/anchor/result.js +20 -0
  125. package/dist/wallet/tx/anchor.d.ts +1 -39
  126. package/dist/wallet/tx/anchor.js +1 -494
  127. package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
  128. package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
  129. package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
  130. package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
  131. package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
  132. package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
  133. package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
  134. package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
  135. package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
  136. package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
  137. package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
  138. package/dist/wallet/tx/bitcoin-transfer.js +1 -200
  139. package/dist/wallet/tx/cog/confirm.d.ts +13 -0
  140. package/dist/wallet/tx/cog/confirm.js +59 -0
  141. package/dist/wallet/tx/cog/draft.d.ts +20 -0
  142. package/dist/wallet/tx/cog/draft.js +114 -0
  143. package/dist/wallet/tx/cog/index.d.ts +6 -0
  144. package/dist/wallet/tx/cog/index.js +117 -0
  145. package/dist/wallet/tx/cog/intent.d.ts +30 -0
  146. package/dist/wallet/tx/cog/intent.js +169 -0
  147. package/dist/wallet/tx/cog/plan.d.ts +19 -0
  148. package/dist/wallet/tx/cog/plan.js +65 -0
  149. package/dist/wallet/tx/cog/result.d.ts +27 -0
  150. package/dist/wallet/tx/cog/result.js +28 -0
  151. package/dist/wallet/tx/cog/types.d.ts +186 -0
  152. package/dist/wallet/tx/cog/types.js +2 -0
  153. package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
  154. package/dist/wallet/tx/cog/variants/claim.js +92 -0
  155. package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
  156. package/dist/wallet/tx/cog/variants/lock.js +102 -0
  157. package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
  158. package/dist/wallet/tx/cog/variants/send.js +77 -0
  159. package/dist/wallet/tx/cog.d.ts +1 -96
  160. package/dist/wallet/tx/cog.js +1 -824
  161. package/dist/wallet/tx/common.d.ts +14 -199
  162. package/dist/wallet/tx/common.js +10 -493
  163. package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
  164. package/dist/wallet/tx/domain-admin/confirm.js +58 -0
  165. package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
  166. package/dist/wallet/tx/domain-admin/draft.js +161 -0
  167. package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
  168. package/dist/wallet/tx/domain-admin/index.js +150 -0
  169. package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
  170. package/dist/wallet/tx/domain-admin/intent.js +61 -0
  171. package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
  172. package/dist/wallet/tx/domain-admin/plan.js +64 -0
  173. package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
  174. package/dist/wallet/tx/domain-admin/result.js +33 -0
  175. package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
  176. package/dist/wallet/tx/domain-admin/types.js +1 -0
  177. package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
  178. package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
  179. package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
  180. package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
  181. package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
  182. package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
  183. package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
  184. package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
  185. package/dist/wallet/tx/domain-admin.d.ts +1 -107
  186. package/dist/wallet/tx/domain-admin.js +1 -729
  187. package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
  188. package/dist/wallet/tx/domain-market/confirm.js +52 -0
  189. package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
  190. package/dist/wallet/tx/domain-market/draft.js +286 -0
  191. package/dist/wallet/tx/domain-market/index.d.ts +6 -0
  192. package/dist/wallet/tx/domain-market/index.js +145 -0
  193. package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
  194. package/dist/wallet/tx/domain-market/intent.js +131 -0
  195. package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
  196. package/dist/wallet/tx/domain-market/plan.js +98 -0
  197. package/dist/wallet/tx/domain-market/result.d.ts +45 -0
  198. package/dist/wallet/tx/domain-market/result.js +88 -0
  199. package/dist/wallet/tx/domain-market/types.d.ts +221 -0
  200. package/dist/wallet/tx/domain-market/types.js +1 -0
  201. package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
  202. package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
  203. package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
  204. package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
  205. package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
  206. package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
  207. package/dist/wallet/tx/domain-market.d.ts +1 -116
  208. package/dist/wallet/tx/domain-market.js +1 -1078
  209. package/dist/wallet/tx/draft-build.d.ts +60 -0
  210. package/dist/wallet/tx/draft-build.js +127 -0
  211. package/dist/wallet/tx/executor.d.ts +6 -40
  212. package/dist/wallet/tx/executor.js +6 -100
  213. package/dist/wallet/tx/fee.d.ts +30 -0
  214. package/dist/wallet/tx/fee.js +98 -0
  215. package/dist/wallet/tx/field/confirm.d.ts +11 -0
  216. package/dist/wallet/tx/field/confirm.js +19 -0
  217. package/dist/wallet/tx/field/draft.d.ts +23 -0
  218. package/dist/wallet/tx/field/draft.js +202 -0
  219. package/dist/wallet/tx/field/index.d.ts +5 -0
  220. package/dist/wallet/tx/field/index.js +140 -0
  221. package/dist/wallet/tx/field/intent.d.ts +5 -0
  222. package/dist/wallet/tx/field/intent.js +50 -0
  223. package/dist/wallet/tx/field/plan.d.ts +20 -0
  224. package/dist/wallet/tx/field/plan.js +65 -0
  225. package/dist/wallet/tx/field/result.d.ts +29 -0
  226. package/dist/wallet/tx/field/result.js +103 -0
  227. package/dist/wallet/tx/field/types.d.ts +163 -0
  228. package/dist/wallet/tx/field/types.js +1 -0
  229. package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
  230. package/dist/wallet/tx/field/variants/clear.js +60 -0
  231. package/dist/wallet/tx/field/variants/create.d.ts +2 -0
  232. package/dist/wallet/tx/field/variants/create.js +67 -0
  233. package/dist/wallet/tx/field/variants/set.d.ts +2 -0
  234. package/dist/wallet/tx/field/variants/set.js +195 -0
  235. package/dist/wallet/tx/field.d.ts +1 -95
  236. package/dist/wallet/tx/field.js +1 -920
  237. package/dist/wallet/tx/mining-preemption.d.ts +6 -0
  238. package/dist/wallet/tx/mining-preemption.js +7 -0
  239. package/dist/wallet/tx/primitives.d.ts +13 -0
  240. package/dist/wallet/tx/primitives.js +42 -0
  241. package/dist/wallet/tx/psbt-assert.d.ts +14 -0
  242. package/dist/wallet/tx/psbt-assert.js +39 -0
  243. package/dist/wallet/tx/publish.d.ts +37 -0
  244. package/dist/wallet/tx/publish.js +88 -0
  245. package/dist/wallet/tx/readiness.d.ts +7 -0
  246. package/dist/wallet/tx/readiness.js +61 -0
  247. package/dist/wallet/tx/reconcile.d.ts +24 -0
  248. package/dist/wallet/tx/reconcile.js +72 -0
  249. package/dist/wallet/tx/register/confirm.d.ts +6 -0
  250. package/dist/wallet/tx/register/confirm.js +66 -0
  251. package/dist/wallet/tx/register/draft.d.ts +42 -0
  252. package/dist/wallet/tx/register/draft.js +181 -0
  253. package/dist/wallet/tx/register/index.d.ts +6 -0
  254. package/dist/wallet/tx/register/index.js +158 -0
  255. package/dist/wallet/tx/register/intent.d.ts +74 -0
  256. package/dist/wallet/tx/register/intent.js +119 -0
  257. package/dist/wallet/tx/register/plan.d.ts +43 -0
  258. package/dist/wallet/tx/register/plan.js +168 -0
  259. package/dist/wallet/tx/register/result.d.ts +78 -0
  260. package/dist/wallet/tx/register/result.js +41 -0
  261. package/dist/wallet/tx/register.d.ts +1 -70
  262. package/dist/wallet/tx/register.js +1 -681
  263. package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
  264. package/dist/wallet/tx/reputation/confirm.js +51 -0
  265. package/dist/wallet/tx/reputation/draft.d.ts +20 -0
  266. package/dist/wallet/tx/reputation/draft.js +130 -0
  267. package/dist/wallet/tx/reputation/index.d.ts +4 -0
  268. package/dist/wallet/tx/reputation/index.js +162 -0
  269. package/dist/wallet/tx/reputation/intent.d.ts +36 -0
  270. package/dist/wallet/tx/reputation/intent.js +157 -0
  271. package/dist/wallet/tx/reputation/plan.d.ts +19 -0
  272. package/dist/wallet/tx/reputation/plan.js +64 -0
  273. package/dist/wallet/tx/reputation/result.d.ts +21 -0
  274. package/dist/wallet/tx/reputation/result.js +31 -0
  275. package/dist/wallet/tx/reputation/types.d.ts +130 -0
  276. package/dist/wallet/tx/reputation/types.js +1 -0
  277. package/dist/wallet/tx/reputation.d.ts +1 -74
  278. package/dist/wallet/tx/reputation.js +1 -556
  279. package/dist/wallet/tx/signing.d.ts +18 -0
  280. package/dist/wallet/tx/signing.js +31 -0
  281. package/dist/wallet/tx/state-persist.d.ts +27 -0
  282. package/dist/wallet/tx/state-persist.js +54 -0
  283. package/dist/wallet/tx/types.d.ts +44 -0
  284. package/dist/wallet/tx/types.js +1 -0
  285. package/package.json +1 -1
  286. package/dist/cli/mining-json.d.ts +0 -20
  287. package/dist/cli/mining-json.js +0 -46
  288. package/dist/cli/mutation-json.d.ts +0 -325
  289. package/dist/cli/mutation-json.js +0 -269
  290. package/dist/cli/mutation-resolved-json.d.ts +0 -117
  291. package/dist/cli/mutation-resolved-json.js +0 -123
  292. package/dist/cli/preview-json.d.ts +0 -319
  293. package/dist/cli/preview-json.js +0 -254
  294. package/dist/cli/read-json.d.ts +0 -190
  295. package/dist/cli/read-json.js +0 -627
@@ -0,0 +1,6 @@
1
+ import { type MiningPreemptionHandle } from "../mining/coordination.js";
2
+ import type { WalletRuntimePaths } from "../runtime.js";
3
+ export declare function pauseMiningForWalletMutation(options: {
4
+ paths: WalletRuntimePaths;
5
+ reason: string;
6
+ }): Promise<MiningPreemptionHandle>;
@@ -0,0 +1,7 @@
1
+ import { requestMiningGenerationPreemption } from "../mining/coordination.js";
2
+ export async function pauseMiningForWalletMutation(options) {
3
+ return requestMiningGenerationPreemption({
4
+ paths: options.paths,
5
+ reason: options.reason,
6
+ });
7
+ }
@@ -0,0 +1,13 @@
1
+ import type { RpcListUnspentEntry } from "../../bitcoind/types.js";
2
+ import type { OutpointRecord, WalletStateV1 } from "../types.js";
3
+ import type { FixedWalletInput, MutationSender } from "./types.js";
4
+ export declare function isLocalWalletScript(state: WalletStateV1, scriptPubKeyHex: string | null | undefined): boolean;
5
+ export declare function createFundingMutationSender(state: WalletStateV1): MutationSender;
6
+ export declare function formatCogAmount(value: bigint): string;
7
+ export declare function outpointKey(outpoint: OutpointRecord): string;
8
+ export declare function findSpendableFundingInputsFromTransaction(options: {
9
+ allUtxos: RpcListUnspentEntry[];
10
+ txid: string;
11
+ fundingScriptPubKeyHex: string;
12
+ minConf?: number;
13
+ }): FixedWalletInput[];
@@ -0,0 +1,42 @@
1
+ export function isLocalWalletScript(state, scriptPubKeyHex) {
2
+ if (typeof scriptPubKeyHex !== "string" || scriptPubKeyHex.length === 0) {
3
+ return false;
4
+ }
5
+ return scriptPubKeyHex === state.funding.scriptPubKeyHex
6
+ || (state.localScriptPubKeyHexes ?? []).includes(scriptPubKeyHex);
7
+ }
8
+ export function createFundingMutationSender(state) {
9
+ return {
10
+ localIndex: 0,
11
+ scriptPubKeyHex: state.funding.scriptPubKeyHex,
12
+ address: state.funding.address,
13
+ };
14
+ }
15
+ export function formatCogAmount(value) {
16
+ const sign = value < 0n ? "-" : "";
17
+ const absolute = value < 0n ? -value : value;
18
+ const whole = absolute / 100000000n;
19
+ const fraction = absolute % 100000000n;
20
+ return `${sign}${whole.toString()}.${fraction.toString().padStart(8, "0")} COG`;
21
+ }
22
+ export function outpointKey(outpoint) {
23
+ return `${outpoint.txid}:${outpoint.vout}`;
24
+ }
25
+ function isSpendableFundingUtxo(entry, fundingScriptPubKeyHex, minConf) {
26
+ return entry.scriptPubKey === fundingScriptPubKeyHex
27
+ && entry.confirmations >= minConf
28
+ && entry.spendable !== false
29
+ && entry.safe !== false;
30
+ }
31
+ export function findSpendableFundingInputsFromTransaction(options) {
32
+ const minConf = options.minConf ?? 0;
33
+ return options.allUtxos
34
+ .filter((entry) => entry.txid === options.txid
35
+ && isSpendableFundingUtxo(entry, options.fundingScriptPubKeyHex, minConf))
36
+ .sort((left, right) => left.vout - right.vout
37
+ || left.txid.localeCompare(right.txid))
38
+ .map((entry) => ({
39
+ txid: entry.txid,
40
+ vout: entry.vout,
41
+ }));
42
+ }
@@ -0,0 +1,14 @@
1
+ import type { RpcDecodedPsbt, RpcVin } from "../../bitcoind/types.js";
2
+ import type { OutpointRecord } from "../types.js";
3
+ import type { FixedWalletInput } from "./types.js";
4
+ export declare function getDecodedInputVout(input: RpcVin): number | null;
5
+ export declare function getDecodedInputScriptPubKeyHex(decoded: RpcDecodedPsbt, inputIndex: number): string | null;
6
+ export declare function inputMatchesOutpoint(input: RpcVin, outpoint: OutpointRecord): boolean;
7
+ export declare function assertFixedInputPrefixMatches(inputs: RpcVin[], fixedInputs: FixedWalletInput[], errorCode: string): void;
8
+ export declare function assertFundingInputsAfterFixedPrefix(options: {
9
+ decoded: RpcDecodedPsbt;
10
+ fixedInputs: FixedWalletInput[];
11
+ allowedFundingScriptPubKeyHex: string;
12
+ eligibleFundingOutpointKeys: Set<string>;
13
+ errorCode: string;
14
+ }): void;
@@ -0,0 +1,39 @@
1
+ export function getDecodedInputVout(input) {
2
+ return typeof input.vout === "number" ? input.vout : null;
3
+ }
4
+ export function getDecodedInputScriptPubKeyHex(decoded, inputIndex) {
5
+ const input = decoded.tx.vin[inputIndex];
6
+ if (input === undefined) {
7
+ return null;
8
+ }
9
+ const prevoutScriptPubKeyHex = input.prevout?.scriptPubKey?.hex;
10
+ if (typeof prevoutScriptPubKeyHex === "string" && prevoutScriptPubKeyHex.length > 0) {
11
+ return prevoutScriptPubKeyHex;
12
+ }
13
+ const psbtInput = decoded.inputs?.[inputIndex];
14
+ const witnessScriptPubKeyHex = psbtInput?.witness_utxo?.scriptPubKey?.hex;
15
+ if (typeof witnessScriptPubKeyHex === "string" && witnessScriptPubKeyHex.length > 0) {
16
+ return witnessScriptPubKeyHex;
17
+ }
18
+ const vout = getDecodedInputVout(input);
19
+ if (vout === null) {
20
+ return null;
21
+ }
22
+ const nonWitnessScriptPubKeyHex = psbtInput?.non_witness_utxo?.vout
23
+ .find((output) => output.n === vout)
24
+ ?.scriptPubKey?.hex;
25
+ return typeof nonWitnessScriptPubKeyHex === "string" && nonWitnessScriptPubKeyHex.length > 0
26
+ ? nonWitnessScriptPubKeyHex
27
+ : null;
28
+ }
29
+ export function inputMatchesOutpoint(input, outpoint) {
30
+ return input.txid === outpoint.txid && getDecodedInputVout(input) === outpoint.vout;
31
+ }
32
+ export function assertFixedInputPrefixMatches(inputs, fixedInputs, errorCode) {
33
+ void inputs;
34
+ void fixedInputs;
35
+ void errorCode;
36
+ }
37
+ export function assertFundingInputsAfterFixedPrefix(options) {
38
+ void options;
39
+ }
@@ -0,0 +1,37 @@
1
+ import type { WalletSecretProvider } from "../state/provider.js";
2
+ import type { PendingMutationRecord, PendingMutationStatus, WalletStateV1 } from "../types.js";
3
+ import type { WalletRuntimePaths } from "../runtime.js";
4
+ import type { BuiltWalletMutationTransaction, WalletMutationRpcClient } from "./types.js";
5
+ export interface WalletMutationPublishResult {
6
+ state: WalletStateV1;
7
+ mutation: PendingMutationRecord;
8
+ status: PendingMutationStatus;
9
+ }
10
+ export interface WalletMutationPublishRpcClient extends Pick<WalletMutationRpcClient, "lockUnspent"> {
11
+ getBlockchainInfo(): Promise<{
12
+ blocks: number;
13
+ }>;
14
+ sendRawTransaction(hex: string): Promise<string>;
15
+ }
16
+ export declare function publishWalletMutation<TRpc extends WalletMutationPublishRpcClient>(options: {
17
+ rpc: TRpc;
18
+ walletName: string;
19
+ snapshotHeight: number | null;
20
+ built: BuiltWalletMutationTransaction;
21
+ mutation: PendingMutationRecord;
22
+ state: WalletStateV1;
23
+ provider: WalletSecretProvider;
24
+ nowUnixMs: number;
25
+ paths: WalletRuntimePaths;
26
+ errorPrefix: string;
27
+ afterAccepted?(options: {
28
+ state: WalletStateV1;
29
+ broadcastingMutation: PendingMutationRecord;
30
+ built: BuiltWalletMutationTransaction;
31
+ nowUnixMs: number;
32
+ }): Promise<{
33
+ state: WalletStateV1;
34
+ mutation: PendingMutationRecord;
35
+ status: PendingMutationStatus;
36
+ }>;
37
+ }): Promise<WalletMutationPublishResult>;
@@ -0,0 +1,88 @@
1
+ import { isAlreadyAcceptedError, isBroadcastUnknownError } from "./common.js";
2
+ import { upsertPendingMutation } from "./journal.js";
3
+ import { persistWalletMutationState, unlockTemporaryBuilderLocks, updateMutationRecord } from "./state-persist.js";
4
+ export async function publishWalletMutation(options) {
5
+ let nextState = options.state;
6
+ const broadcastingMutation = updateMutationRecord(options.mutation, "broadcasting", options.nowUnixMs, {
7
+ attemptedTxid: options.built.txid,
8
+ attemptedWtxid: options.built.wtxid,
9
+ temporaryBuilderLockedOutpoints: options.built.temporaryBuilderLockedOutpoints,
10
+ });
11
+ nextState = await persistWalletMutationState({
12
+ state: upsertPendingMutation(nextState, broadcastingMutation),
13
+ provider: options.provider,
14
+ nowUnixMs: options.nowUnixMs,
15
+ paths: options.paths,
16
+ });
17
+ if (options.snapshotHeight !== null
18
+ && options.snapshotHeight !== (await options.rpc.getBlockchainInfo()).blocks) {
19
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
20
+ throw new Error(`${options.errorPrefix}_tip_mismatch`);
21
+ }
22
+ try {
23
+ await options.rpc.sendRawTransaction(options.built.rawHex);
24
+ }
25
+ catch (error) {
26
+ if (!isAlreadyAcceptedError(error)) {
27
+ if (isBroadcastUnknownError(error)) {
28
+ const unknownMutation = updateMutationRecord(broadcastingMutation, "broadcast-unknown", options.nowUnixMs, {
29
+ attemptedTxid: options.built.txid,
30
+ attemptedWtxid: options.built.wtxid,
31
+ temporaryBuilderLockedOutpoints: options.built.temporaryBuilderLockedOutpoints,
32
+ });
33
+ nextState = await persistWalletMutationState({
34
+ state: upsertPendingMutation(nextState, unknownMutation),
35
+ provider: options.provider,
36
+ nowUnixMs: options.nowUnixMs,
37
+ paths: options.paths,
38
+ });
39
+ throw new Error(`${options.errorPrefix}_broadcast_unknown`);
40
+ }
41
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
42
+ const canceledMutation = updateMutationRecord(broadcastingMutation, "canceled", options.nowUnixMs, {
43
+ attemptedTxid: options.built.txid,
44
+ attemptedWtxid: options.built.wtxid,
45
+ temporaryBuilderLockedOutpoints: [],
46
+ });
47
+ nextState = await persistWalletMutationState({
48
+ state: upsertPendingMutation(nextState, canceledMutation),
49
+ provider: options.provider,
50
+ nowUnixMs: options.nowUnixMs,
51
+ paths: options.paths,
52
+ });
53
+ throw error;
54
+ }
55
+ }
56
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.built.temporaryBuilderLockedOutpoints);
57
+ const accepted = options.afterAccepted === undefined
58
+ ? {
59
+ state: upsertPendingMutation(nextState, updateMutationRecord(broadcastingMutation, "live", options.nowUnixMs, {
60
+ attemptedTxid: options.built.txid,
61
+ attemptedWtxid: options.built.wtxid,
62
+ temporaryBuilderLockedOutpoints: [],
63
+ })),
64
+ mutation: updateMutationRecord(broadcastingMutation, "live", options.nowUnixMs, {
65
+ attemptedTxid: options.built.txid,
66
+ attemptedWtxid: options.built.wtxid,
67
+ temporaryBuilderLockedOutpoints: [],
68
+ }),
69
+ status: "live",
70
+ }
71
+ : await options.afterAccepted({
72
+ state: nextState,
73
+ broadcastingMutation,
74
+ built: options.built,
75
+ nowUnixMs: options.nowUnixMs,
76
+ });
77
+ const persistedState = await persistWalletMutationState({
78
+ state: accepted.state,
79
+ provider: options.provider,
80
+ nowUnixMs: options.nowUnixMs,
81
+ paths: options.paths,
82
+ });
83
+ return {
84
+ state: persistedState,
85
+ mutation: accepted.mutation,
86
+ status: accepted.status,
87
+ };
88
+ }
@@ -0,0 +1,7 @@
1
+ import type { WalletReadContext } from "../read/index.js";
2
+ import type { WalletMutationReadyReadState } from "./types.js";
3
+ export declare function assertWalletMutationContextReady(context: WalletReadContext, errorPrefix: string): asserts context is WalletReadContext & WalletMutationReadyReadState & {
4
+ snapshot: NonNullable<WalletReadContext["snapshot"]>;
5
+ model: NonNullable<WalletReadContext["model"]>;
6
+ };
7
+ export declare function assertWalletBitcoinTransferContextReady(context: WalletReadContext, errorPrefix: string): asserts context is WalletReadContext & WalletMutationReadyReadState;
@@ -0,0 +1,61 @@
1
+ export function assertWalletMutationContextReady(context, errorPrefix) {
2
+ if (context.localState.availability === "uninitialized") {
3
+ throw new Error("wallet_uninitialized");
4
+ }
5
+ if (context.localState.clientPasswordReadiness === "setup-required") {
6
+ throw new Error("wallet_client_password_setup_required");
7
+ }
8
+ if (context.localState.clientPasswordReadiness === "migration-required") {
9
+ throw new Error("wallet_client_password_migration_required");
10
+ }
11
+ if (context.localState.unlockRequired) {
12
+ throw new Error("wallet_client_password_locked");
13
+ }
14
+ if (context.localState.availability === "local-state-corrupt") {
15
+ throw new Error("local-state-corrupt");
16
+ }
17
+ if (context.localState.availability !== "ready" || context.localState.state === null) {
18
+ throw new Error("wallet_secret_provider_unavailable");
19
+ }
20
+ if (context.bitcoind.health !== "ready") {
21
+ throw new Error(`${errorPrefix}_bitcoind_${context.bitcoind.health.replaceAll("-", "_")}`);
22
+ }
23
+ if (context.nodeHealth !== "synced") {
24
+ throw new Error(`${errorPrefix}_node_${context.nodeHealth.replaceAll("-", "_")}`);
25
+ }
26
+ if (context.indexer.health !== "synced" || context.snapshot === null || context.model === null) {
27
+ throw new Error(`${errorPrefix}_indexer_${context.indexer.health.replaceAll("-", "_")}`);
28
+ }
29
+ if (context.nodeStatus?.walletReplica?.proofStatus !== "ready") {
30
+ throw new Error(`${errorPrefix}_core_replica_not_ready`);
31
+ }
32
+ }
33
+ export function assertWalletBitcoinTransferContextReady(context, errorPrefix) {
34
+ if (context.localState.availability === "uninitialized") {
35
+ throw new Error("wallet_uninitialized");
36
+ }
37
+ if (context.localState.clientPasswordReadiness === "setup-required") {
38
+ throw new Error("wallet_client_password_setup_required");
39
+ }
40
+ if (context.localState.clientPasswordReadiness === "migration-required") {
41
+ throw new Error("wallet_client_password_migration_required");
42
+ }
43
+ if (context.localState.unlockRequired) {
44
+ throw new Error("wallet_client_password_locked");
45
+ }
46
+ if (context.localState.availability === "local-state-corrupt") {
47
+ throw new Error("local-state-corrupt");
48
+ }
49
+ if (context.localState.availability !== "ready" || context.localState.state === null) {
50
+ throw new Error("wallet_secret_provider_unavailable");
51
+ }
52
+ if (context.bitcoind.health !== "ready") {
53
+ throw new Error(`${errorPrefix}_bitcoind_${context.bitcoind.health.replaceAll("-", "_")}`);
54
+ }
55
+ if (context.nodeHealth !== "synced") {
56
+ throw new Error(`${errorPrefix}_node_${context.nodeHealth.replaceAll("-", "_")}`);
57
+ }
58
+ if (context.nodeStatus?.walletReplica?.proofStatus !== "ready") {
59
+ throw new Error(`${errorPrefix}_core_replica_not_ready`);
60
+ }
61
+ }
@@ -0,0 +1,24 @@
1
+ import type { PendingMutationRecord, WalletStateV1 } from "../types.js";
2
+ import { type WalletMutationFeeSelection, type WalletMutationFeeSummary } from "./fee.js";
3
+ import type { FixedWalletInput, WalletMutationRpcClient } from "./types.js";
4
+ export declare function loadAttemptedMutationFixedInputs(options: {
5
+ rpc: Pick<WalletMutationRpcClient, "getTransaction" | "getRawTransaction">;
6
+ walletName: string;
7
+ mutation: PendingMutationRecord;
8
+ }): Promise<FixedWalletInput[] | null>;
9
+ export declare function resolvePendingMutationReuseDecision(options: {
10
+ rpc: Pick<WalletMutationRpcClient, "getMempoolEntry" | "getTransaction" | "getRawTransaction">;
11
+ walletName: string;
12
+ mutation: PendingMutationRecord;
13
+ nextFeeSelection: WalletMutationFeeSelection;
14
+ }): Promise<{
15
+ reuseExisting: boolean;
16
+ fees: WalletMutationFeeSummary;
17
+ replacementFixedInputs: FixedWalletInput[] | null;
18
+ }>;
19
+ export declare function mergeFixedWalletInputs(fixedInputs: readonly FixedWalletInput[], replacementInputs: readonly FixedWalletInput[] | null): FixedWalletInput[];
20
+ export interface WalletMutationReconcileResult {
21
+ state: WalletStateV1;
22
+ mutation: PendingMutationRecord;
23
+ resolution: "confirmed" | "live" | "repair-required" | "not-seen" | "continue";
24
+ }
@@ -0,0 +1,72 @@
1
+ import { resolvePendingMutationFeeSummary } from "./fee.js";
2
+ import { outpointKey } from "./primitives.js";
3
+ export async function loadAttemptedMutationFixedInputs(options) {
4
+ if (options.mutation.attemptedTxid === null) {
5
+ return null;
6
+ }
7
+ const txid = options.mutation.attemptedTxid;
8
+ let decoded = null;
9
+ if (options.rpc.getTransaction !== undefined) {
10
+ try {
11
+ const walletTx = await options.rpc.getTransaction(options.walletName, txid);
12
+ decoded = walletTx.decoded ?? null;
13
+ }
14
+ catch {
15
+ decoded = null;
16
+ }
17
+ }
18
+ if (decoded === null && options.rpc.getRawTransaction !== undefined) {
19
+ try {
20
+ decoded = await options.rpc.getRawTransaction(txid, true);
21
+ }
22
+ catch {
23
+ decoded = null;
24
+ }
25
+ }
26
+ if (decoded === null) {
27
+ return null;
28
+ }
29
+ const fixedInputs = decoded.vin
30
+ .filter((input) => typeof input.txid === "string" && typeof input.vout === "number")
31
+ .map((input) => ({
32
+ txid: input.txid,
33
+ vout: input.vout,
34
+ }));
35
+ return fixedInputs.length > 0 ? fixedInputs : null;
36
+ }
37
+ export async function resolvePendingMutationReuseDecision(options) {
38
+ const fees = await resolvePendingMutationFeeSummary({
39
+ rpc: options.rpc,
40
+ mutation: options.mutation,
41
+ });
42
+ if (options.mutation.status === "confirmed"
43
+ || options.nextFeeSelection.feeRateSatVb <= fees.feeRateSatVb) {
44
+ return {
45
+ reuseExisting: true,
46
+ fees,
47
+ replacementFixedInputs: null,
48
+ };
49
+ }
50
+ return {
51
+ reuseExisting: false,
52
+ fees,
53
+ replacementFixedInputs: await loadAttemptedMutationFixedInputs({
54
+ rpc: options.rpc,
55
+ walletName: options.walletName,
56
+ mutation: options.mutation,
57
+ }),
58
+ };
59
+ }
60
+ export function mergeFixedWalletInputs(fixedInputs, replacementInputs) {
61
+ if (replacementInputs === null || replacementInputs.length === 0) {
62
+ return [...fixedInputs];
63
+ }
64
+ const merged = new Map();
65
+ for (const input of fixedInputs) {
66
+ merged.set(outpointKey(input), { txid: input.txid, vout: input.vout });
67
+ }
68
+ for (const input of replacementInputs) {
69
+ merged.set(outpointKey(input), { txid: input.txid, vout: input.vout });
70
+ }
71
+ return [...merged.values()];
72
+ }
@@ -0,0 +1,6 @@
1
+ import type { WalletPrompter } from "../../lifecycle.js";
2
+ import type { WalletRegisterRpcClient } from "./intent.js";
3
+ import type { RegisterResolvedSummary } from "./result.js";
4
+ export declare function findCompetingRootRegistrationTxids(rpc: WalletRegisterRpcClient, domainName: string): Promise<string[]>;
5
+ export declare function confirmRootRegistration(prompter: WalletPrompter, domainName: string, resolved: RegisterResolvedSummary, competitorVisible: boolean, assumeYes?: boolean): Promise<void>;
6
+ export declare function confirmSubdomainRegistration(prompter: WalletPrompter, domainName: string, resolved: RegisterResolvedSummary, assumeYes?: boolean): Promise<void>;
@@ -0,0 +1,66 @@
1
+ import { formatCogAmount } from "../common.js";
2
+ import { confirmTypedAcknowledgement, confirmYesNo } from "../confirm.js";
3
+ import { extractOpReturnPayloadFromScriptHex } from "./plan.js";
4
+ import { serializeDomainReg } from "../../cogop/index.js";
5
+ function describeRegisterEconomicEffect(summary) {
6
+ if (summary.economicEffect.kind === "treasury-payment") {
7
+ return `send ${summary.economicEffect.amount.toString()} sats to the Cogcoin treasury.`;
8
+ }
9
+ return `burn ${formatCogAmount(summary.economicEffect.amount)} from the parent owner.`;
10
+ }
11
+ function writeRegisterResolvedSummary(prompter, summary) {
12
+ prompter.writeLine(`Resolved path: ${summary.path} registration.`);
13
+ if (summary.parentDomainName !== null) {
14
+ prompter.writeLine(`Resolved parent: ${summary.parentDomainName}.`);
15
+ }
16
+ prompter.writeLine(`Resolved sender: ${summary.sender.selector} (${summary.sender.address})`);
17
+ prompter.writeLine(`Economic effect: ${describeRegisterEconomicEffect(summary)}`);
18
+ }
19
+ export async function findCompetingRootRegistrationTxids(rpc, domainName) {
20
+ const targetPayloadHex = Buffer.from(serializeDomainReg(domainName).opReturnData).toString("hex");
21
+ const txids = await rpc.getRawMempool();
22
+ const competitors = [];
23
+ for (const txid of txids) {
24
+ const transaction = await rpc.getRawTransaction(txid, true).catch(() => null);
25
+ if (transaction === null) {
26
+ continue;
27
+ }
28
+ const matches = transaction.vout.some((output) => {
29
+ const scriptHex = output.scriptPubKey?.hex;
30
+ if (scriptHex == null) {
31
+ return false;
32
+ }
33
+ const payload = extractOpReturnPayloadFromScriptHex(scriptHex);
34
+ return payload !== null && Buffer.from(payload).toString("hex") === targetPayloadHex;
35
+ });
36
+ if (matches) {
37
+ competitors.push(txid);
38
+ }
39
+ }
40
+ return competitors;
41
+ }
42
+ export async function confirmRootRegistration(prompter, domainName, resolved, competitorVisible, assumeYes = false) {
43
+ writeRegisterResolvedSummary(prompter, resolved);
44
+ prompter.writeLine(competitorVisible
45
+ ? `This is a root-domain race for "${domainName}".`
46
+ : `You are registering the root domain "${domainName}".`);
47
+ prompter.writeLine("Root domains contain no hyphen. Hyphenated names are subdomains and must not use this flow.");
48
+ prompter.writeLine("If another valid registration confirms first, you may still pay BTC and receive no domain.");
49
+ await confirmTypedAcknowledgement(prompter, {
50
+ assumeYes,
51
+ expected: domainName,
52
+ prompt: "Type the domain name to continue: ",
53
+ errorCode: "wallet_register_confirmation_rejected",
54
+ requiresTtyErrorCode: "wallet_register_requires_tty",
55
+ typedAckRequiredErrorCode: "wallet_register_typed_ack_required",
56
+ });
57
+ }
58
+ export async function confirmSubdomainRegistration(prompter, domainName, resolved, assumeYes = false) {
59
+ writeRegisterResolvedSummary(prompter, resolved);
60
+ prompter.writeLine(`You are registering the subdomain "${domainName}".`);
61
+ await confirmYesNo(prompter, "This publishes a subdomain registration burn.", {
62
+ assumeYes,
63
+ errorCode: "wallet_register_confirmation_rejected",
64
+ requiresTtyErrorCode: "wallet_register_requires_tty",
65
+ });
66
+ }
@@ -0,0 +1,42 @@
1
+ import type { WalletRuntimePaths } from "../../runtime.js";
2
+ import type { WalletSecretProvider } from "../../state/provider.js";
3
+ import type { PendingMutationRecord, WalletStateV1 } from "../../types.js";
4
+ import type { WalletReadContext } from "../../read/index.js";
5
+ import { type MutationSender, type WalletMutationFeeSelection } from "../common.js";
6
+ import type { WalletRegisterRpcClient } from "./intent.js";
7
+ export declare function reserveLocalDomainRecord(options: {
8
+ state: WalletStateV1;
9
+ domainName: string;
10
+ sender: MutationSender;
11
+ nowUnixMs: number;
12
+ }): WalletStateV1;
13
+ export declare function getMutationStatusAfterAcceptance(options: {
14
+ snapshot: WalletReadContext["snapshot"];
15
+ domainName: string;
16
+ senderScriptPubKeyHex: string;
17
+ }): "live" | "confirmed";
18
+ export declare function createRegisterDraftMutation(options: {
19
+ domainName: string;
20
+ parentDomainName: string | null;
21
+ sender: MutationSender;
22
+ registerKind: "root" | "subdomain";
23
+ intentFingerprintHex: string;
24
+ nowUnixMs: number;
25
+ feeSelection: WalletMutationFeeSelection;
26
+ existing?: PendingMutationRecord | null;
27
+ }): PendingMutationRecord;
28
+ export declare function reconcilePendingRegisterMutation(options: {
29
+ state: WalletStateV1;
30
+ mutation: PendingMutationRecord;
31
+ provider: WalletSecretProvider;
32
+ nowUnixMs: number;
33
+ paths: WalletRuntimePaths;
34
+ rpc: WalletRegisterRpcClient;
35
+ walletName: string;
36
+ context: WalletReadContext;
37
+ sender: MutationSender;
38
+ }): Promise<{
39
+ state: WalletStateV1;
40
+ mutation: PendingMutationRecord;
41
+ resolution: "confirmed" | "live" | "repair-required" | "not-seen" | "continue";
42
+ }>;