@cogcoin/client 1.1.8 → 1.1.9

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 (266) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/commands/mining-read.js +1 -1
  3. package/dist/cli/commands/wallet-mutation/anchor.d.ts +2 -0
  4. package/dist/cli/commands/wallet-mutation/anchor.js +33 -0
  5. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.d.ts +2 -0
  6. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.js +32 -0
  7. package/dist/cli/commands/wallet-mutation/cog.d.ts +2 -0
  8. package/dist/cli/commands/wallet-mutation/cog.js +131 -0
  9. package/dist/cli/commands/wallet-mutation/context.d.ts +3 -0
  10. package/dist/cli/commands/wallet-mutation/context.js +18 -0
  11. package/dist/cli/commands/wallet-mutation/domain-admin.d.ts +2 -0
  12. package/dist/cli/commands/wallet-mutation/domain-admin.js +173 -0
  13. package/dist/cli/commands/wallet-mutation/domain-market.d.ts +2 -0
  14. package/dist/cli/commands/wallet-mutation/domain-market.js +107 -0
  15. package/dist/cli/commands/wallet-mutation/field.d.ts +2 -0
  16. package/dist/cli/commands/wallet-mutation/field.js +125 -0
  17. package/dist/cli/commands/wallet-mutation/register.d.ts +2 -0
  18. package/dist/cli/commands/wallet-mutation/register.js +38 -0
  19. package/dist/cli/commands/wallet-mutation/registry.d.ts +3 -0
  20. package/dist/cli/commands/wallet-mutation/registry.js +39 -0
  21. package/dist/cli/commands/wallet-mutation/reputation.d.ts +2 -0
  22. package/dist/cli/commands/wallet-mutation/reputation.js +57 -0
  23. package/dist/cli/commands/wallet-mutation/types.d.ts +32 -0
  24. package/dist/cli/commands/wallet-mutation/types.js +1 -0
  25. package/dist/cli/commands/wallet-mutation.js +13 -765
  26. package/dist/cli/commands/wallet-read.js +4 -4
  27. package/dist/cli/mutation-success.d.ts +0 -2
  28. package/dist/cli/output/classify.d.ts +7 -0
  29. package/dist/cli/output/classify.js +94 -0
  30. package/dist/cli/output/render.d.ts +2 -0
  31. package/dist/cli/output/render.js +13 -0
  32. package/dist/cli/output/rules/cli-surface.d.ts +2 -0
  33. package/dist/cli/output/rules/cli-surface.js +110 -0
  34. package/dist/cli/output/rules/generic.d.ts +2 -0
  35. package/dist/cli/output/rules/generic.js +13 -0
  36. package/dist/cli/output/rules/index.d.ts +2 -0
  37. package/dist/cli/output/rules/index.js +24 -0
  38. package/dist/cli/output/rules/mining-update.d.ts +2 -0
  39. package/dist/cli/output/rules/mining-update.js +68 -0
  40. package/dist/cli/output/rules/services.d.ts +2 -0
  41. package/dist/cli/output/rules/services.js +110 -0
  42. package/dist/cli/output/rules/wallet-admin.d.ts +2 -0
  43. package/dist/cli/output/rules/wallet-admin.js +224 -0
  44. package/dist/cli/output/rules/wallet-mutations.d.ts +2 -0
  45. package/dist/cli/output/rules/wallet-mutations.js +274 -0
  46. package/dist/cli/output/types.d.ts +16 -0
  47. package/dist/cli/output/types.js +1 -0
  48. package/dist/cli/output.d.ts +2 -168
  49. package/dist/cli/output.js +6 -989
  50. package/dist/cli/pagination.d.ts +15 -0
  51. package/dist/cli/pagination.js +16 -0
  52. package/dist/cli/recommendations.d.ts +4 -0
  53. package/dist/cli/recommendations.js +108 -0
  54. package/dist/cli/wallet-format/availability.d.ts +5 -0
  55. package/dist/cli/wallet-format/availability.js +96 -0
  56. package/dist/cli/wallet-format/balance.d.ts +2 -0
  57. package/dist/cli/wallet-format/balance.js +162 -0
  58. package/dist/cli/wallet-format/domains.d.ts +8 -0
  59. package/dist/cli/wallet-format/domains.js +84 -0
  60. package/dist/cli/wallet-format/fields.d.ts +6 -0
  61. package/dist/cli/wallet-format/fields.js +61 -0
  62. package/dist/cli/wallet-format/identity.d.ts +5 -0
  63. package/dist/cli/wallet-format/identity.js +19 -0
  64. package/dist/cli/wallet-format/locks.d.ts +7 -0
  65. package/dist/cli/wallet-format/locks.js +52 -0
  66. package/dist/cli/wallet-format/overview.d.ts +2 -0
  67. package/dist/cli/wallet-format/overview.js +122 -0
  68. package/dist/cli/wallet-format/pending.d.ts +13 -0
  69. package/dist/cli/wallet-format/pending.js +101 -0
  70. package/dist/cli/wallet-format/shared.d.ts +7 -0
  71. package/dist/cli/wallet-format/shared.js +31 -0
  72. package/dist/cli/wallet-format/status.d.ts +3 -0
  73. package/dist/cli/wallet-format/status.js +27 -0
  74. package/dist/cli/wallet-format.d.ts +8 -30
  75. package/dist/cli/wallet-format.js +8 -830
  76. package/dist/cli/wallet-read-helpers.d.ts +6 -0
  77. package/dist/cli/wallet-read-helpers.js +17 -0
  78. package/dist/wallet/mining/candidate.d.ts +1 -1
  79. package/dist/wallet/mining/candidate.js +3 -3
  80. package/dist/wallet/mining/constants.d.ts +2 -2
  81. package/dist/wallet/mining/constants.js +2 -2
  82. package/dist/wallet/mining/sentence-protocol.d.ts +2 -2
  83. package/dist/wallet/mining/sentences.js +8 -8
  84. package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
  85. package/dist/wallet/tx/anchor/confirm.js +60 -0
  86. package/dist/wallet/tx/anchor/draft.d.ts +39 -0
  87. package/dist/wallet/tx/anchor/draft.js +167 -0
  88. package/dist/wallet/tx/anchor/index.d.ts +5 -0
  89. package/dist/wallet/tx/anchor/index.js +148 -0
  90. package/dist/wallet/tx/anchor/intent.d.ts +61 -0
  91. package/dist/wallet/tx/anchor/intent.js +101 -0
  92. package/dist/wallet/tx/anchor/plan.d.ts +3 -0
  93. package/dist/wallet/tx/anchor/plan.js +18 -0
  94. package/dist/wallet/tx/anchor/result.d.ts +25 -0
  95. package/dist/wallet/tx/anchor/result.js +20 -0
  96. package/dist/wallet/tx/anchor.d.ts +1 -39
  97. package/dist/wallet/tx/anchor.js +1 -494
  98. package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
  99. package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
  100. package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
  101. package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
  102. package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
  103. package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
  104. package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
  105. package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
  106. package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
  107. package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
  108. package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
  109. package/dist/wallet/tx/bitcoin-transfer.js +1 -200
  110. package/dist/wallet/tx/cog/confirm.d.ts +13 -0
  111. package/dist/wallet/tx/cog/confirm.js +59 -0
  112. package/dist/wallet/tx/cog/draft.d.ts +20 -0
  113. package/dist/wallet/tx/cog/draft.js +114 -0
  114. package/dist/wallet/tx/cog/index.d.ts +6 -0
  115. package/dist/wallet/tx/cog/index.js +117 -0
  116. package/dist/wallet/tx/cog/intent.d.ts +30 -0
  117. package/dist/wallet/tx/cog/intent.js +169 -0
  118. package/dist/wallet/tx/cog/plan.d.ts +19 -0
  119. package/dist/wallet/tx/cog/plan.js +65 -0
  120. package/dist/wallet/tx/cog/result.d.ts +27 -0
  121. package/dist/wallet/tx/cog/result.js +28 -0
  122. package/dist/wallet/tx/cog/types.d.ts +186 -0
  123. package/dist/wallet/tx/cog/types.js +2 -0
  124. package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
  125. package/dist/wallet/tx/cog/variants/claim.js +92 -0
  126. package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
  127. package/dist/wallet/tx/cog/variants/lock.js +102 -0
  128. package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
  129. package/dist/wallet/tx/cog/variants/send.js +77 -0
  130. package/dist/wallet/tx/cog.d.ts +1 -96
  131. package/dist/wallet/tx/cog.js +1 -824
  132. package/dist/wallet/tx/common.d.ts +14 -199
  133. package/dist/wallet/tx/common.js +10 -493
  134. package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
  135. package/dist/wallet/tx/domain-admin/confirm.js +58 -0
  136. package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
  137. package/dist/wallet/tx/domain-admin/draft.js +161 -0
  138. package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
  139. package/dist/wallet/tx/domain-admin/index.js +150 -0
  140. package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
  141. package/dist/wallet/tx/domain-admin/intent.js +61 -0
  142. package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
  143. package/dist/wallet/tx/domain-admin/plan.js +64 -0
  144. package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
  145. package/dist/wallet/tx/domain-admin/result.js +33 -0
  146. package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
  147. package/dist/wallet/tx/domain-admin/types.js +1 -0
  148. package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
  149. package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
  150. package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
  151. package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
  152. package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
  153. package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
  154. package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
  155. package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
  156. package/dist/wallet/tx/domain-admin.d.ts +1 -107
  157. package/dist/wallet/tx/domain-admin.js +1 -729
  158. package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
  159. package/dist/wallet/tx/domain-market/confirm.js +52 -0
  160. package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
  161. package/dist/wallet/tx/domain-market/draft.js +286 -0
  162. package/dist/wallet/tx/domain-market/index.d.ts +6 -0
  163. package/dist/wallet/tx/domain-market/index.js +145 -0
  164. package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
  165. package/dist/wallet/tx/domain-market/intent.js +131 -0
  166. package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
  167. package/dist/wallet/tx/domain-market/plan.js +98 -0
  168. package/dist/wallet/tx/domain-market/result.d.ts +45 -0
  169. package/dist/wallet/tx/domain-market/result.js +88 -0
  170. package/dist/wallet/tx/domain-market/types.d.ts +221 -0
  171. package/dist/wallet/tx/domain-market/types.js +1 -0
  172. package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
  173. package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
  174. package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
  175. package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
  176. package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
  177. package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
  178. package/dist/wallet/tx/domain-market.d.ts +1 -116
  179. package/dist/wallet/tx/domain-market.js +1 -1078
  180. package/dist/wallet/tx/draft-build.d.ts +60 -0
  181. package/dist/wallet/tx/draft-build.js +127 -0
  182. package/dist/wallet/tx/executor.d.ts +6 -40
  183. package/dist/wallet/tx/executor.js +6 -100
  184. package/dist/wallet/tx/fee.d.ts +30 -0
  185. package/dist/wallet/tx/fee.js +98 -0
  186. package/dist/wallet/tx/field/confirm.d.ts +11 -0
  187. package/dist/wallet/tx/field/confirm.js +19 -0
  188. package/dist/wallet/tx/field/draft.d.ts +23 -0
  189. package/dist/wallet/tx/field/draft.js +202 -0
  190. package/dist/wallet/tx/field/index.d.ts +5 -0
  191. package/dist/wallet/tx/field/index.js +140 -0
  192. package/dist/wallet/tx/field/intent.d.ts +5 -0
  193. package/dist/wallet/tx/field/intent.js +50 -0
  194. package/dist/wallet/tx/field/plan.d.ts +20 -0
  195. package/dist/wallet/tx/field/plan.js +65 -0
  196. package/dist/wallet/tx/field/result.d.ts +29 -0
  197. package/dist/wallet/tx/field/result.js +103 -0
  198. package/dist/wallet/tx/field/types.d.ts +163 -0
  199. package/dist/wallet/tx/field/types.js +1 -0
  200. package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
  201. package/dist/wallet/tx/field/variants/clear.js +60 -0
  202. package/dist/wallet/tx/field/variants/create.d.ts +2 -0
  203. package/dist/wallet/tx/field/variants/create.js +67 -0
  204. package/dist/wallet/tx/field/variants/set.d.ts +2 -0
  205. package/dist/wallet/tx/field/variants/set.js +195 -0
  206. package/dist/wallet/tx/field.d.ts +1 -95
  207. package/dist/wallet/tx/field.js +1 -920
  208. package/dist/wallet/tx/mining-preemption.d.ts +6 -0
  209. package/dist/wallet/tx/mining-preemption.js +7 -0
  210. package/dist/wallet/tx/primitives.d.ts +13 -0
  211. package/dist/wallet/tx/primitives.js +42 -0
  212. package/dist/wallet/tx/psbt-assert.d.ts +14 -0
  213. package/dist/wallet/tx/psbt-assert.js +39 -0
  214. package/dist/wallet/tx/publish.d.ts +37 -0
  215. package/dist/wallet/tx/publish.js +88 -0
  216. package/dist/wallet/tx/readiness.d.ts +7 -0
  217. package/dist/wallet/tx/readiness.js +61 -0
  218. package/dist/wallet/tx/reconcile.d.ts +24 -0
  219. package/dist/wallet/tx/reconcile.js +72 -0
  220. package/dist/wallet/tx/register/confirm.d.ts +6 -0
  221. package/dist/wallet/tx/register/confirm.js +66 -0
  222. package/dist/wallet/tx/register/draft.d.ts +42 -0
  223. package/dist/wallet/tx/register/draft.js +181 -0
  224. package/dist/wallet/tx/register/index.d.ts +6 -0
  225. package/dist/wallet/tx/register/index.js +158 -0
  226. package/dist/wallet/tx/register/intent.d.ts +74 -0
  227. package/dist/wallet/tx/register/intent.js +119 -0
  228. package/dist/wallet/tx/register/plan.d.ts +43 -0
  229. package/dist/wallet/tx/register/plan.js +168 -0
  230. package/dist/wallet/tx/register/result.d.ts +78 -0
  231. package/dist/wallet/tx/register/result.js +41 -0
  232. package/dist/wallet/tx/register.d.ts +1 -70
  233. package/dist/wallet/tx/register.js +1 -681
  234. package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
  235. package/dist/wallet/tx/reputation/confirm.js +51 -0
  236. package/dist/wallet/tx/reputation/draft.d.ts +20 -0
  237. package/dist/wallet/tx/reputation/draft.js +130 -0
  238. package/dist/wallet/tx/reputation/index.d.ts +4 -0
  239. package/dist/wallet/tx/reputation/index.js +162 -0
  240. package/dist/wallet/tx/reputation/intent.d.ts +36 -0
  241. package/dist/wallet/tx/reputation/intent.js +157 -0
  242. package/dist/wallet/tx/reputation/plan.d.ts +19 -0
  243. package/dist/wallet/tx/reputation/plan.js +64 -0
  244. package/dist/wallet/tx/reputation/result.d.ts +21 -0
  245. package/dist/wallet/tx/reputation/result.js +31 -0
  246. package/dist/wallet/tx/reputation/types.d.ts +130 -0
  247. package/dist/wallet/tx/reputation/types.js +1 -0
  248. package/dist/wallet/tx/reputation.d.ts +1 -74
  249. package/dist/wallet/tx/reputation.js +1 -556
  250. package/dist/wallet/tx/signing.d.ts +18 -0
  251. package/dist/wallet/tx/signing.js +31 -0
  252. package/dist/wallet/tx/state-persist.d.ts +27 -0
  253. package/dist/wallet/tx/state-persist.js +54 -0
  254. package/dist/wallet/tx/types.d.ts +44 -0
  255. package/dist/wallet/tx/types.js +1 -0
  256. package/package.json +1 -1
  257. package/dist/cli/mining-json.d.ts +0 -20
  258. package/dist/cli/mining-json.js +0 -46
  259. package/dist/cli/mutation-json.d.ts +0 -325
  260. package/dist/cli/mutation-json.js +0 -269
  261. package/dist/cli/mutation-resolved-json.d.ts +0 -117
  262. package/dist/cli/mutation-resolved-json.js +0 -123
  263. package/dist/cli/preview-json.d.ts +0 -319
  264. package/dist/cli/preview-json.js +0 -254
  265. package/dist/cli/read-json.d.ts +0 -190
  266. package/dist/cli/read-json.js +0 -627
@@ -1,298 +1,14 @@
1
- import { saveWalletState } from "../state/storage.js";
2
- import { createWalletSecretReference, } from "../state/provider.js";
3
- import { MANAGED_CORE_WALLET_UNLOCK_TIMEOUT_SECONDS, withUnlockedManagedCoreWallet, } from "../managed-core-wallet.js";
4
1
  import { reconcilePersistentPolicyLocks as reconcileWalletCoinControlLocks } from "../coin-control.js";
5
- import { requestMiningGenerationPreemption } from "../mining/coordination.js";
6
- export const DEFAULT_WALLET_MUTATION_FEE_RATE_SAT_VB = 10;
7
- export const NEXT_BLOCK_FEE_CONFIRM_TARGET = 1;
8
- export function isLocalWalletScript(state, scriptPubKeyHex) {
9
- if (typeof scriptPubKeyHex !== "string" || scriptPubKeyHex.length === 0) {
10
- return false;
11
- }
12
- return scriptPubKeyHex === state.funding.scriptPubKeyHex
13
- || (state.localScriptPubKeyHexes ?? []).includes(scriptPubKeyHex);
14
- }
15
- export function createFundingMutationSender(state) {
16
- return {
17
- localIndex: 0,
18
- scriptPubKeyHex: state.funding.scriptPubKeyHex,
19
- address: state.funding.address,
20
- };
21
- }
22
- function btcNumberToSats(value) {
23
- return BigInt(Math.round(value * 100_000_000));
24
- }
25
- function normalizeSatVb(value) {
26
- return Number.parseFloat(value.toFixed(8));
27
- }
28
- function satVbFromBtcPerKvB(value) {
29
- return normalizeSatVb((value * 100_000_000) / 1_000);
30
- }
31
- function valueToSats(value) {
32
- return typeof value === "string"
33
- ? BigInt(Math.round(Number(value) * 100_000_000))
34
- : btcNumberToSats(value);
35
- }
36
- function feeRateFromMempoolEntry(entry) {
37
- if (!Number.isFinite(entry.vsize) || entry.vsize <= 0) {
38
- return null;
39
- }
40
- const feeSats = Number(btcNumberToSats(entry.fees.base));
41
- if (!Number.isFinite(feeSats) || feeSats <= 0) {
42
- return null;
43
- }
44
- return normalizeSatVb(feeSats / entry.vsize);
45
- }
46
- export function formatSatVb(value) {
47
- return normalizeSatVb(value).toString();
48
- }
49
- export function createWalletMutationFeeMetadata(selection) {
50
- return {
51
- selectedFeeRateSatVb: selection.feeRateSatVb,
52
- feeSelectionSource: selection.source,
53
- };
54
- }
55
- export async function resolveWalletMutationFeeSelection(options) {
56
- if (typeof options.feeRateSatVb === "number") {
57
- return {
58
- feeRateSatVb: normalizeSatVb(options.feeRateSatVb),
59
- source: "custom-satvb",
60
- };
61
- }
62
- if (options.rpc.estimateSmartFee !== undefined) {
63
- try {
64
- const estimate = await options.rpc.estimateSmartFee(NEXT_BLOCK_FEE_CONFIRM_TARGET, "conservative");
65
- const estimatedSatVb = typeof estimate.feerate === "number"
66
- ? satVbFromBtcPerKvB(estimate.feerate)
67
- : null;
68
- if (estimatedSatVb !== null && Number.isFinite(estimatedSatVb) && estimatedSatVb > 0) {
69
- return {
70
- feeRateSatVb: normalizeSatVb(estimatedSatVb + 1),
71
- source: "estimated-next-block-plus-one",
72
- };
73
- }
74
- }
75
- catch {
76
- // Fall through to the compatibility default.
77
- }
78
- }
79
- return {
80
- feeRateSatVb: DEFAULT_WALLET_MUTATION_FEE_RATE_SAT_VB,
81
- source: "fallback-default",
82
- };
83
- }
84
- export function createWalletMutationFeeSummary(selection, feeSats) {
85
- return {
86
- feeRateSatVb: selection.feeRateSatVb,
87
- feeSats,
88
- source: selection.source,
89
- };
90
- }
91
- export function createBuiltWalletMutationFeeSummary(options) {
92
- return createWalletMutationFeeSummary(options.selection, btcNumberToSats(options.built.funded.fee).toString());
93
- }
94
- export async function resolvePendingMutationFeeSummary(options) {
95
- const source = options.mutation.feeSelectionSource ?? "fallback-default";
96
- const selectedFeeRateSatVb = typeof options.mutation.selectedFeeRateSatVb === "number"
97
- && Number.isFinite(options.mutation.selectedFeeRateSatVb)
98
- && options.mutation.selectedFeeRateSatVb > 0
99
- ? normalizeSatVb(options.mutation.selectedFeeRateSatVb)
100
- : DEFAULT_WALLET_MUTATION_FEE_RATE_SAT_VB;
101
- if (options.mutation.attemptedTxid !== null && options.rpc.getMempoolEntry !== undefined) {
102
- try {
103
- const entry = await options.rpc.getMempoolEntry(options.mutation.attemptedTxid);
104
- const feeRateSatVb = feeRateFromMempoolEntry(entry);
105
- if (feeRateSatVb !== null) {
106
- return {
107
- feeRateSatVb,
108
- feeSats: btcNumberToSats(entry.fees.base).toString(),
109
- source,
110
- };
111
- }
112
- }
113
- catch {
114
- // Fall back to stored metadata or the historical default.
115
- }
116
- }
117
- return {
118
- feeRateSatVb: selectedFeeRateSatVb,
119
- feeSats: null,
120
- source,
121
- };
122
- }
123
- export async function loadAttemptedMutationFixedInputs(options) {
124
- if (options.mutation.attemptedTxid === null) {
125
- return null;
126
- }
127
- const txid = options.mutation.attemptedTxid;
128
- let decoded = null;
129
- if (options.rpc.getTransaction !== undefined) {
130
- try {
131
- decoded = (await options.rpc.getTransaction(options.walletName, txid)).decoded ?? null;
132
- }
133
- catch {
134
- decoded = null;
135
- }
136
- }
137
- if (decoded === null && options.rpc.getRawTransaction !== undefined) {
138
- try {
139
- decoded = await options.rpc.getRawTransaction(txid, true);
140
- }
141
- catch {
142
- decoded = null;
143
- }
144
- }
145
- if (decoded === null) {
146
- return null;
147
- }
148
- const fixedInputs = decoded.vin
149
- .filter((input) => typeof input.txid === "string" && typeof input.vout === "number")
150
- .map((input) => ({
151
- txid: input.txid,
152
- vout: input.vout,
153
- }));
154
- return fixedInputs.length > 0 ? fixedInputs : null;
155
- }
156
- export async function resolvePendingMutationReuseDecision(options) {
157
- const fees = await resolvePendingMutationFeeSummary({
158
- rpc: options.rpc,
159
- mutation: options.mutation,
160
- });
161
- if (options.mutation.status === "confirmed"
162
- || options.nextFeeSelection.feeRateSatVb <= fees.feeRateSatVb) {
163
- return {
164
- reuseExisting: true,
165
- fees,
166
- replacementFixedInputs: null,
167
- };
168
- }
169
- return {
170
- reuseExisting: false,
171
- fees,
172
- replacementFixedInputs: await loadAttemptedMutationFixedInputs({
173
- rpc: options.rpc,
174
- walletName: options.walletName,
175
- mutation: options.mutation,
176
- }),
177
- };
178
- }
179
- export function mergeFixedWalletInputs(fixedInputs, replacementInputs) {
180
- if (replacementInputs === null || replacementInputs.length === 0) {
181
- return [...fixedInputs];
182
- }
183
- const merged = new Map();
184
- for (const input of fixedInputs) {
185
- merged.set(outpointKey(input), { txid: input.txid, vout: input.vout });
186
- }
187
- for (const input of replacementInputs) {
188
- merged.set(outpointKey(input), { txid: input.txid, vout: input.vout });
189
- }
190
- return [...merged.values()];
191
- }
192
- export async function saveWalletStatePreservingUnlock(options) {
193
- const secretReference = createWalletSecretReference(options.state.walletRootId);
194
- await saveWalletState({
195
- primaryPath: options.paths.walletStatePath,
196
- backupPath: options.paths.walletStateBackupPath,
197
- }, options.state, {
198
- provider: options.provider,
199
- secretReference,
200
- });
201
- }
202
- export function formatCogAmount(value) {
203
- const sign = value < 0n ? "-" : "";
204
- const absolute = value < 0n ? -value : value;
205
- const whole = absolute / 100000000n;
206
- const fraction = absolute % 100000000n;
207
- return `${sign}${whole.toString()}.${fraction.toString().padStart(8, "0")} COG`;
208
- }
209
- export function outpointKey(outpoint) {
210
- return `${outpoint.txid}:${outpoint.vout}`;
211
- }
212
- function isSpendableFundingUtxo(entry, fundingScriptPubKeyHex, minConf) {
213
- return entry.scriptPubKey === fundingScriptPubKeyHex
214
- && entry.confirmations >= minConf
215
- && entry.spendable !== false
216
- && entry.safe !== false;
217
- }
218
- export function findSpendableFundingInputsFromTransaction(options) {
219
- const minConf = options.minConf ?? 0;
220
- return options.allUtxos
221
- .filter((entry) => entry.txid === options.txid
222
- && isSpendableFundingUtxo(entry, options.fundingScriptPubKeyHex, minConf))
223
- .sort((left, right) => left.vout - right.vout
224
- || left.txid.localeCompare(right.txid))
225
- .map((entry) => ({
226
- txid: entry.txid,
227
- vout: entry.vout,
228
- }));
229
- }
230
- export function updateMutationRecord(mutation, status, nowUnixMs, options = {}) {
231
- return {
232
- ...mutation,
233
- status,
234
- lastUpdatedAtUnixMs: nowUnixMs,
235
- attemptedTxid: options.attemptedTxid ?? mutation.attemptedTxid,
236
- attemptedWtxid: options.attemptedWtxid ?? mutation.attemptedWtxid,
237
- temporaryBuilderLockedOutpoints: options.temporaryBuilderLockedOutpoints ?? mutation.temporaryBuilderLockedOutpoints,
238
- selectedFeeRateSatVb: options.selectedFeeRateSatVb ?? mutation.selectedFeeRateSatVb,
239
- feeSelectionSource: options.feeSelectionSource ?? mutation.feeSelectionSource,
240
- };
241
- }
242
- export async function unlockTemporaryBuilderLocks(rpc, walletName, outpoints) {
243
- if (outpoints.length === 0 || rpc.lockUnspent === undefined) {
244
- return;
245
- }
246
- await rpc.lockUnspent(walletName, true, outpoints).catch(() => undefined);
247
- }
248
- export function diffTemporaryLockedOutpoints(before, after) {
249
- const beforeKeys = new Set(before.map((entry) => outpointKey(entry)));
250
- return after
251
- .filter((entry) => !beforeKeys.has(outpointKey(entry)))
252
- .map((entry) => ({
253
- txid: entry.txid,
254
- vout: entry.vout,
255
- }));
256
- }
257
- export function getDecodedInputVout(input) {
258
- return typeof input.vout === "number" ? input.vout : null;
259
- }
260
- export function getDecodedInputScriptPubKeyHex(decoded, inputIndex) {
261
- const input = decoded.tx.vin[inputIndex];
262
- if (input === undefined) {
263
- return null;
264
- }
265
- const prevoutScriptPubKeyHex = input.prevout?.scriptPubKey?.hex;
266
- if (typeof prevoutScriptPubKeyHex === "string" && prevoutScriptPubKeyHex.length > 0) {
267
- return prevoutScriptPubKeyHex;
268
- }
269
- const psbtInput = decoded.inputs?.[inputIndex];
270
- const witnessScriptPubKeyHex = psbtInput?.witness_utxo?.scriptPubKey?.hex;
271
- if (typeof witnessScriptPubKeyHex === "string" && witnessScriptPubKeyHex.length > 0) {
272
- return witnessScriptPubKeyHex;
273
- }
274
- const vout = getDecodedInputVout(input);
275
- if (vout === null) {
276
- return null;
277
- }
278
- const nonWitnessScriptPubKeyHex = psbtInput?.non_witness_utxo?.vout
279
- .find((output) => output.n === vout)
280
- ?.scriptPubKey?.hex;
281
- return typeof nonWitnessScriptPubKeyHex === "string" && nonWitnessScriptPubKeyHex.length > 0
282
- ? nonWitnessScriptPubKeyHex
283
- : null;
284
- }
285
- export function inputMatchesOutpoint(input, outpoint) {
286
- return input.txid === outpoint.txid && getDecodedInputVout(input) === outpoint.vout;
287
- }
288
- export function assertFixedInputPrefixMatches(inputs, fixedInputs, errorCode) {
289
- void inputs;
290
- void fixedInputs;
291
- void errorCode;
292
- }
293
- export function assertFundingInputsAfterFixedPrefix(options) {
294
- void options;
295
- }
2
+ export * from "./types.js";
3
+ export * from "./primitives.js";
4
+ export * from "./fee.js";
5
+ export * from "./reconcile.js";
6
+ export * from "./state-persist.js";
7
+ export * from "./psbt-assert.js";
8
+ export * from "./readiness.js";
9
+ export * from "./mining-preemption.js";
10
+ export * from "./signing.js";
11
+ export * from "./draft-build.js";
296
12
  export async function reconcilePersistentPolicyLocks(options) {
297
13
  await reconcileWalletCoinControlLocks({
298
14
  rpc: options.rpc,
@@ -320,202 +36,3 @@ export function isInsufficientFundsError(error) {
320
36
  const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
321
37
  return message.includes("insufficient funds");
322
38
  }
323
- function isReserveFloorFundingError(error) {
324
- void error;
325
- return false;
326
- }
327
- function computeRemainingFundingValueSats(options) {
328
- let remaining = 0n;
329
- for (const value of options.availableFundingValueByKey.values()) {
330
- remaining += value;
331
- }
332
- for (const [index, input] of options.decoded.tx.vin.entries()) {
333
- const scriptPubKeyHex = getDecodedInputScriptPubKeyHex(options.decoded, index);
334
- const vout = getDecodedInputVout(input);
335
- if (scriptPubKeyHex !== options.fundingScriptPubKeyHex || vout === null || typeof input.txid !== "string") {
336
- continue;
337
- }
338
- remaining -= options.availableFundingValueByKey.get(outpointKey({
339
- txid: input.txid,
340
- vout,
341
- })) ?? 0n;
342
- }
343
- for (const output of options.decoded.tx.vout) {
344
- if (output.scriptPubKey?.hex !== options.fundingScriptPubKeyHex) {
345
- continue;
346
- }
347
- remaining += valueToSats(output.value);
348
- }
349
- return remaining;
350
- }
351
- export function assertWalletMutationContextReady(context, errorPrefix) {
352
- if (context.localState.availability === "uninitialized") {
353
- throw new Error("wallet_uninitialized");
354
- }
355
- if (context.localState.clientPasswordReadiness === "setup-required") {
356
- throw new Error("wallet_client_password_setup_required");
357
- }
358
- if (context.localState.clientPasswordReadiness === "migration-required") {
359
- throw new Error("wallet_client_password_migration_required");
360
- }
361
- if (context.localState.unlockRequired) {
362
- throw new Error("wallet_client_password_locked");
363
- }
364
- if (context.localState.availability === "local-state-corrupt") {
365
- throw new Error("local-state-corrupt");
366
- }
367
- if (context.localState.availability !== "ready" || context.localState.state === null) {
368
- throw new Error("wallet_secret_provider_unavailable");
369
- }
370
- if (context.bitcoind.health !== "ready") {
371
- throw new Error(`${errorPrefix}_bitcoind_${context.bitcoind.health.replaceAll("-", "_")}`);
372
- }
373
- if (context.nodeHealth !== "synced") {
374
- throw new Error(`${errorPrefix}_node_${context.nodeHealth.replaceAll("-", "_")}`);
375
- }
376
- if (context.indexer.health !== "synced" || context.snapshot === null || context.model === null) {
377
- throw new Error(`${errorPrefix}_indexer_${context.indexer.health.replaceAll("-", "_")}`);
378
- }
379
- if (context.nodeStatus?.walletReplica?.proofStatus !== "ready") {
380
- throw new Error(`${errorPrefix}_core_replica_not_ready`);
381
- }
382
- }
383
- export function assertWalletBitcoinTransferContextReady(context, errorPrefix) {
384
- if (context.localState.availability === "uninitialized") {
385
- throw new Error("wallet_uninitialized");
386
- }
387
- if (context.localState.clientPasswordReadiness === "setup-required") {
388
- throw new Error("wallet_client_password_setup_required");
389
- }
390
- if (context.localState.clientPasswordReadiness === "migration-required") {
391
- throw new Error("wallet_client_password_migration_required");
392
- }
393
- if (context.localState.unlockRequired) {
394
- throw new Error("wallet_client_password_locked");
395
- }
396
- if (context.localState.availability === "local-state-corrupt") {
397
- throw new Error("local-state-corrupt");
398
- }
399
- if (context.localState.availability !== "ready" || context.localState.state === null) {
400
- throw new Error("wallet_secret_provider_unavailable");
401
- }
402
- if (context.bitcoind.health !== "ready") {
403
- throw new Error(`${errorPrefix}_bitcoind_${context.bitcoind.health.replaceAll("-", "_")}`);
404
- }
405
- if (context.nodeHealth !== "synced") {
406
- throw new Error(`${errorPrefix}_node_${context.nodeHealth.replaceAll("-", "_")}`);
407
- }
408
- if (context.nodeStatus?.walletReplica?.proofStatus !== "ready") {
409
- throw new Error(`${errorPrefix}_core_replica_not_ready`);
410
- }
411
- }
412
- export async function pauseMiningForWalletMutation(options) {
413
- return requestMiningGenerationPreemption({
414
- paths: options.paths,
415
- reason: options.reason,
416
- });
417
- }
418
- export async function buildWalletMutationTransaction(options) {
419
- const temporaryBuilderLockedOutpoints = [];
420
- try {
421
- const { funded, decoded } = await fundAndValidateWalletMutationDraft({
422
- rpc: options.rpc,
423
- walletName: options.walletName,
424
- plan: options.plan,
425
- validateFundedDraft: options.validateFundedDraft,
426
- feeRate: options.feeRate,
427
- availableFundingMinConf: options.availableFundingMinConf,
428
- });
429
- let signed;
430
- let finalized;
431
- let rawHex;
432
- let decodedRaw;
433
- ({ signed, finalized, rawHex, decodedRaw } = await withUnlockedManagedCoreWallet({
434
- rpc: options.rpc,
435
- walletName: options.walletName,
436
- internalPassphrase: options.state.managedCoreWallet.internalPassphrase,
437
- timeoutSeconds: MANAGED_CORE_WALLET_UNLOCK_TIMEOUT_SECONDS,
438
- recoverLockedWalletOnce: options.recoverManagedCoreWalletLockedOnce,
439
- onLockedWalletRecoveryOutcome: options.onManagedCoreWalletLockedRecoveryOutcome,
440
- run: async () => {
441
- const signed = await options.rpc.walletProcessPsbt(options.walletName, funded.psbt, true, "DEFAULT");
442
- const finalized = await options.rpc.finalizePsbt(signed.psbt, true);
443
- if (!finalized.complete || finalized.hex == null) {
444
- throw new Error(options.finalizeErrorCode);
445
- }
446
- const rawHex = finalized.hex;
447
- const decodedRaw = await options.rpc.decodeRawTransaction(rawHex);
448
- const mempoolResult = await options.rpc.testMempoolAccept([rawHex]);
449
- const accepted = mempoolResult[0];
450
- if (accepted == null || !accepted.allowed) {
451
- throw new Error(`${options.mempoolRejectPrefix}_${accepted?.["reject-reason"] ?? "unknown"}`);
452
- }
453
- return {
454
- signed,
455
- finalized,
456
- rawHex,
457
- decodedRaw,
458
- };
459
- },
460
- }));
461
- return {
462
- funded,
463
- decoded,
464
- psbt: signed.psbt,
465
- rawHex,
466
- txid: decodedRaw.txid,
467
- wtxid: decodedRaw.hash ?? null,
468
- temporaryBuilderLockedOutpoints,
469
- };
470
- }
471
- catch (error) {
472
- await unlockTemporaryBuilderLocks(options.rpc, options.walletName, temporaryBuilderLockedOutpoints);
473
- throw error;
474
- }
475
- }
476
- export async function fundAndValidateWalletMutationDraft(options) {
477
- const availableFundingMinConf = options.availableFundingMinConf ?? 1;
478
- const availableFundingUtxos = (await options.rpc.listUnspent(options.walletName, availableFundingMinConf))
479
- .filter((entry) => isSpendableFundingUtxo(entry, options.plan.allowedFundingScriptPubKeyHex, availableFundingMinConf));
480
- const availableFundingValueByKey = new Map(availableFundingUtxos.map((entry) => [
481
- outpointKey({ txid: entry.txid, vout: entry.vout }),
482
- btcNumberToSats(entry.amount),
483
- ]));
484
- const validationPlan = {
485
- ...options.plan,
486
- eligibleFundingOutpointKeys: new Set([
487
- ...options.plan.eligibleFundingOutpointKeys,
488
- ...availableFundingUtxos.map((entry) => outpointKey({ txid: entry.txid, vout: entry.vout })),
489
- ]),
490
- };
491
- const funded = await options.rpc.walletCreateFundedPsbt(options.walletName, options.plan.fixedInputs, options.plan.outputs, 0, {
492
- add_inputs: true,
493
- include_unsafe: false,
494
- minconf: availableFundingMinConf,
495
- changeAddress: options.plan.changeAddress,
496
- ...(options.plan.changePosition == null ? {} : { changePosition: options.plan.changePosition }),
497
- lockUnspents: false,
498
- fee_rate: options.feeRate ?? DEFAULT_WALLET_MUTATION_FEE_RATE_SAT_VB,
499
- replaceable: true,
500
- subtractFeeFromOutputs: [],
501
- });
502
- const decoded = await options.rpc.decodePsbt(funded.psbt);
503
- options.validateFundedDraft(decoded, funded, validationPlan);
504
- return {
505
- funded,
506
- decoded,
507
- };
508
- }
509
- export async function buildWalletMutationTransactionWithReserveFallback(options) {
510
- return buildWalletMutationTransaction({
511
- rpc: options.rpc,
512
- walletName: options.walletName,
513
- state: options.state,
514
- plan: options.plan,
515
- validateFundedDraft: options.validateFundedDraft,
516
- finalizeErrorCode: options.finalizeErrorCode,
517
- mempoolRejectPrefix: options.mempoolRejectPrefix,
518
- feeRate: options.feeRate,
519
- availableFundingMinConf: options.availableFundingMinConf,
520
- });
521
- }
@@ -0,0 +1,17 @@
1
+ import type { WalletPrompter } from "../../lifecycle.js";
2
+ import type { DomainAdminResolvedSenderSummary } from "./types.js";
3
+ import { normalizeBtcTarget } from "../targets.js";
4
+ export declare function confirmEndpointMutation(prompter: WalletPrompter, domainName: string, payload: Uint8Array, options: {
5
+ clear: boolean;
6
+ sender: DomainAdminResolvedSenderSummary;
7
+ sourceKind?: "text" | "json" | "bytes";
8
+ assumeYes?: boolean;
9
+ }): Promise<void>;
10
+ export declare function confirmTargetMutation(prompter: WalletPrompter, options: {
11
+ kind: "delegate" | "miner";
12
+ domainName: string;
13
+ target: ReturnType<typeof normalizeBtcTarget> | null;
14
+ sender: DomainAdminResolvedSenderSummary;
15
+ assumeYes?: boolean;
16
+ }): Promise<void>;
17
+ export declare function confirmCanonicalMutation(prompter: WalletPrompter, domainName: string, sender: DomainAdminResolvedSenderSummary, assumeYes?: boolean): Promise<void>;
@@ -0,0 +1,58 @@
1
+ import { confirmYesNo } from "../confirm.js";
2
+ import { normalizeBtcTarget } from "../targets.js";
3
+ export async function confirmEndpointMutation(prompter, domainName, payload, options) {
4
+ prompter.writeLine(`${options.clear ? "Clearing" : "Updating"} endpoint for "${domainName}".`);
5
+ prompter.writeLine(`Resolved sender: ${options.sender.selector} (${options.sender.address})`);
6
+ prompter.writeLine(options.clear
7
+ ? "Effect: clear the endpoint payload."
8
+ : `Effect: set the endpoint payload to ${payload.length} bytes.`);
9
+ if (!options.clear) {
10
+ prompter.writeLine(`Payload bytes: ${payload.length}`);
11
+ if (options.sourceKind !== undefined) {
12
+ prompter.writeLine(`Payload source: ${options.sourceKind}`);
13
+ }
14
+ prompter.writeLine("Warning: endpoint data is public in the mempool and on-chain.");
15
+ }
16
+ await confirmYesNo(prompter, options.clear
17
+ ? "This publishes a standalone anchored endpoint clear."
18
+ : "This publishes a standalone anchored endpoint update.", {
19
+ assumeYes: options.assumeYes,
20
+ errorCode: "wallet_domain_endpoint_confirmation_rejected",
21
+ requiresTtyErrorCode: "wallet_domain_endpoint_requires_tty",
22
+ });
23
+ }
24
+ export async function confirmTargetMutation(prompter, options) {
25
+ prompter.writeLine(`${options.target === null ? "Clearing" : "Updating"} ${options.kind} for "${options.domainName}".`);
26
+ prompter.writeLine(`Resolved sender: ${options.sender.selector} (${options.sender.address})`);
27
+ if (options.target === null) {
28
+ prompter.writeLine(`Effect: clear the ${options.kind === "delegate" ? "delegate" : "designated miner"} target.`);
29
+ await confirmYesNo(prompter, `This clears the current ${options.kind} target.`, {
30
+ assumeYes: options.assumeYes,
31
+ errorCode: `wallet_domain_${options.kind}_confirmation_rejected`,
32
+ requiresTtyErrorCode: `wallet_domain_${options.kind}_requires_tty`,
33
+ });
34
+ return;
35
+ }
36
+ prompter.writeLine(`Resolved target: ${options.target.address ?? `spk:${options.target.scriptPubKeyHex}`}`);
37
+ prompter.writeLine(`Effect: set the ${options.kind === "delegate" ? "delegate" : "designated miner"} target.`);
38
+ if (options.kind === "miner" && options.target.scriptPubKeyHex === options.sender.scriptPubKeyHex) {
39
+ prompter.writeLine("Warning: setting the designated miner to the current owner is usually redundant.");
40
+ }
41
+ await confirmYesNo(prompter, options.kind === "delegate"
42
+ ? "This changes who may act for the domain as delegate."
43
+ : "This changes who may mine for the domain as designated miner.", {
44
+ assumeYes: options.assumeYes,
45
+ errorCode: `wallet_domain_${options.kind}_confirmation_rejected`,
46
+ requiresTtyErrorCode: `wallet_domain_${options.kind}_requires_tty`,
47
+ });
48
+ }
49
+ export async function confirmCanonicalMutation(prompter, domainName, sender, assumeYes = false) {
50
+ prompter.writeLine(`Canonicalizing "${domainName}" as the anchored owner.`);
51
+ prompter.writeLine(`Resolved sender: ${sender.selector} (${sender.address})`);
52
+ prompter.writeLine("Effect: canonicalize the current anchored owner.");
53
+ await confirmYesNo(prompter, "This publishes a standalone SET_CANONICAL operation.", {
54
+ assumeYes,
55
+ errorCode: "wallet_domain_canonical_confirmation_rejected",
56
+ requiresTtyErrorCode: "wallet_domain_canonical_requires_tty",
57
+ });
58
+ }
@@ -0,0 +1,20 @@
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 { DomainAdminDraftMutationOptions, DomainAdminRpcClient } from "./types.js";
6
+ export declare function createDomainAdminDraftMutation(options: DomainAdminDraftMutationOptions): PendingMutationRecord;
7
+ export declare function reconcilePendingAdminMutation(options: {
8
+ state: WalletStateV1;
9
+ mutation: PendingMutationRecord;
10
+ provider: WalletSecretProvider;
11
+ nowUnixMs: number;
12
+ paths: WalletRuntimePaths;
13
+ rpc: DomainAdminRpcClient;
14
+ walletName: string;
15
+ context: WalletReadContext;
16
+ }): Promise<{
17
+ state: WalletStateV1;
18
+ mutation: PendingMutationRecord;
19
+ resolution: "confirmed" | "live" | "repair-required" | "not-seen" | "continue";
20
+ }>;