@cogcoin/client 1.1.7 → 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 (284) hide show
  1. package/README.md +1 -1
  2. package/dist/bitcoind/service.js +1 -1
  3. package/dist/cli/commands/mining-read.js +1 -1
  4. package/dist/cli/commands/wallet-mutation/anchor.d.ts +2 -0
  5. package/dist/cli/commands/wallet-mutation/anchor.js +33 -0
  6. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.d.ts +2 -0
  7. package/dist/cli/commands/wallet-mutation/bitcoin-transfer.js +32 -0
  8. package/dist/cli/commands/wallet-mutation/cog.d.ts +2 -0
  9. package/dist/cli/commands/wallet-mutation/cog.js +131 -0
  10. package/dist/cli/commands/wallet-mutation/context.d.ts +3 -0
  11. package/dist/cli/commands/wallet-mutation/context.js +18 -0
  12. package/dist/cli/commands/wallet-mutation/domain-admin.d.ts +2 -0
  13. package/dist/cli/commands/wallet-mutation/domain-admin.js +173 -0
  14. package/dist/cli/commands/wallet-mutation/domain-market.d.ts +2 -0
  15. package/dist/cli/commands/wallet-mutation/domain-market.js +107 -0
  16. package/dist/cli/commands/wallet-mutation/field.d.ts +2 -0
  17. package/dist/cli/commands/wallet-mutation/field.js +125 -0
  18. package/dist/cli/commands/wallet-mutation/register.d.ts +2 -0
  19. package/dist/cli/commands/wallet-mutation/register.js +38 -0
  20. package/dist/cli/commands/wallet-mutation/registry.d.ts +3 -0
  21. package/dist/cli/commands/wallet-mutation/registry.js +39 -0
  22. package/dist/cli/commands/wallet-mutation/reputation.d.ts +2 -0
  23. package/dist/cli/commands/wallet-mutation/reputation.js +57 -0
  24. package/dist/cli/commands/wallet-mutation/types.d.ts +32 -0
  25. package/dist/cli/commands/wallet-mutation/types.js +1 -0
  26. package/dist/cli/commands/wallet-mutation.js +13 -765
  27. package/dist/cli/commands/wallet-read.js +4 -4
  28. package/dist/cli/mutation-success.d.ts +0 -2
  29. package/dist/cli/output/classify.d.ts +7 -0
  30. package/dist/cli/output/classify.js +94 -0
  31. package/dist/cli/output/render.d.ts +2 -0
  32. package/dist/cli/output/render.js +13 -0
  33. package/dist/cli/output/rules/cli-surface.d.ts +2 -0
  34. package/dist/cli/output/rules/cli-surface.js +110 -0
  35. package/dist/cli/output/rules/generic.d.ts +2 -0
  36. package/dist/cli/output/rules/generic.js +13 -0
  37. package/dist/cli/output/rules/index.d.ts +2 -0
  38. package/dist/cli/output/rules/index.js +24 -0
  39. package/dist/cli/output/rules/mining-update.d.ts +2 -0
  40. package/dist/cli/output/rules/mining-update.js +68 -0
  41. package/dist/cli/output/rules/services.d.ts +2 -0
  42. package/dist/cli/output/rules/services.js +110 -0
  43. package/dist/cli/output/rules/wallet-admin.d.ts +2 -0
  44. package/dist/cli/output/rules/wallet-admin.js +224 -0
  45. package/dist/cli/output/rules/wallet-mutations.d.ts +2 -0
  46. package/dist/cli/output/rules/wallet-mutations.js +274 -0
  47. package/dist/cli/output/types.d.ts +16 -0
  48. package/dist/cli/output/types.js +1 -0
  49. package/dist/cli/output.d.ts +2 -168
  50. package/dist/cli/output.js +6 -989
  51. package/dist/cli/pagination.d.ts +15 -0
  52. package/dist/cli/pagination.js +16 -0
  53. package/dist/cli/recommendations.d.ts +4 -0
  54. package/dist/cli/recommendations.js +108 -0
  55. package/dist/cli/wallet-format/availability.d.ts +5 -0
  56. package/dist/cli/wallet-format/availability.js +96 -0
  57. package/dist/cli/wallet-format/balance.d.ts +2 -0
  58. package/dist/cli/wallet-format/balance.js +162 -0
  59. package/dist/cli/wallet-format/domains.d.ts +8 -0
  60. package/dist/cli/wallet-format/domains.js +84 -0
  61. package/dist/cli/wallet-format/fields.d.ts +6 -0
  62. package/dist/cli/wallet-format/fields.js +61 -0
  63. package/dist/cli/wallet-format/identity.d.ts +5 -0
  64. package/dist/cli/wallet-format/identity.js +19 -0
  65. package/dist/cli/wallet-format/locks.d.ts +7 -0
  66. package/dist/cli/wallet-format/locks.js +52 -0
  67. package/dist/cli/wallet-format/overview.d.ts +2 -0
  68. package/dist/cli/wallet-format/overview.js +122 -0
  69. package/dist/cli/wallet-format/pending.d.ts +13 -0
  70. package/dist/cli/wallet-format/pending.js +101 -0
  71. package/dist/cli/wallet-format/shared.d.ts +7 -0
  72. package/dist/cli/wallet-format/shared.js +31 -0
  73. package/dist/cli/wallet-format/status.d.ts +3 -0
  74. package/dist/cli/wallet-format/status.js +27 -0
  75. package/dist/cli/wallet-format.d.ts +8 -30
  76. package/dist/cli/wallet-format.js +8 -830
  77. package/dist/cli/wallet-read-helpers.d.ts +6 -0
  78. package/dist/cli/wallet-read-helpers.js +17 -0
  79. package/dist/wallet/mining/candidate.d.ts +1 -1
  80. package/dist/wallet/mining/candidate.js +3 -3
  81. package/dist/wallet/mining/constants.d.ts +2 -2
  82. package/dist/wallet/mining/constants.js +2 -2
  83. package/dist/wallet/mining/engine-state.js +10 -0
  84. package/dist/wallet/mining/sentence-protocol.d.ts +2 -2
  85. package/dist/wallet/mining/sentences.js +8 -8
  86. package/dist/wallet/mining/visualizer-sync.js +79 -15
  87. package/dist/wallet/read/context.js +1 -1
  88. package/dist/wallet/reset/artifacts.d.ts +16 -0
  89. package/dist/wallet/reset/artifacts.js +141 -0
  90. package/dist/wallet/reset/execution.d.ts +38 -0
  91. package/dist/wallet/reset/execution.js +458 -0
  92. package/dist/wallet/reset/preflight.d.ts +7 -0
  93. package/dist/wallet/reset/preflight.js +116 -0
  94. package/dist/wallet/reset/preview.d.ts +2 -0
  95. package/dist/wallet/reset/preview.js +50 -0
  96. package/dist/wallet/reset/process-cleanup.d.ts +12 -0
  97. package/dist/wallet/reset/process-cleanup.js +179 -0
  98. package/dist/wallet/reset/types.d.ts +189 -0
  99. package/dist/wallet/reset/types.js +1 -0
  100. package/dist/wallet/reset.d.ts +4 -119
  101. package/dist/wallet/reset.js +4 -882
  102. package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
  103. package/dist/wallet/tx/anchor/confirm.js +60 -0
  104. package/dist/wallet/tx/anchor/draft.d.ts +39 -0
  105. package/dist/wallet/tx/anchor/draft.js +167 -0
  106. package/dist/wallet/tx/anchor/index.d.ts +5 -0
  107. package/dist/wallet/tx/anchor/index.js +148 -0
  108. package/dist/wallet/tx/anchor/intent.d.ts +61 -0
  109. package/dist/wallet/tx/anchor/intent.js +101 -0
  110. package/dist/wallet/tx/anchor/plan.d.ts +3 -0
  111. package/dist/wallet/tx/anchor/plan.js +18 -0
  112. package/dist/wallet/tx/anchor/result.d.ts +25 -0
  113. package/dist/wallet/tx/anchor/result.js +20 -0
  114. package/dist/wallet/tx/anchor.d.ts +1 -39
  115. package/dist/wallet/tx/anchor.js +1 -494
  116. package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
  117. package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
  118. package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
  119. package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
  120. package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
  121. package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
  122. package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
  123. package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
  124. package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
  125. package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
  126. package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
  127. package/dist/wallet/tx/bitcoin-transfer.js +1 -200
  128. package/dist/wallet/tx/cog/confirm.d.ts +13 -0
  129. package/dist/wallet/tx/cog/confirm.js +59 -0
  130. package/dist/wallet/tx/cog/draft.d.ts +20 -0
  131. package/dist/wallet/tx/cog/draft.js +114 -0
  132. package/dist/wallet/tx/cog/index.d.ts +6 -0
  133. package/dist/wallet/tx/cog/index.js +117 -0
  134. package/dist/wallet/tx/cog/intent.d.ts +30 -0
  135. package/dist/wallet/tx/cog/intent.js +169 -0
  136. package/dist/wallet/tx/cog/plan.d.ts +19 -0
  137. package/dist/wallet/tx/cog/plan.js +65 -0
  138. package/dist/wallet/tx/cog/result.d.ts +27 -0
  139. package/dist/wallet/tx/cog/result.js +28 -0
  140. package/dist/wallet/tx/cog/types.d.ts +186 -0
  141. package/dist/wallet/tx/cog/types.js +2 -0
  142. package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
  143. package/dist/wallet/tx/cog/variants/claim.js +92 -0
  144. package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
  145. package/dist/wallet/tx/cog/variants/lock.js +102 -0
  146. package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
  147. package/dist/wallet/tx/cog/variants/send.js +77 -0
  148. package/dist/wallet/tx/cog.d.ts +1 -96
  149. package/dist/wallet/tx/cog.js +1 -824
  150. package/dist/wallet/tx/common.d.ts +14 -199
  151. package/dist/wallet/tx/common.js +10 -493
  152. package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
  153. package/dist/wallet/tx/domain-admin/confirm.js +58 -0
  154. package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
  155. package/dist/wallet/tx/domain-admin/draft.js +161 -0
  156. package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
  157. package/dist/wallet/tx/domain-admin/index.js +150 -0
  158. package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
  159. package/dist/wallet/tx/domain-admin/intent.js +61 -0
  160. package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
  161. package/dist/wallet/tx/domain-admin/plan.js +64 -0
  162. package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
  163. package/dist/wallet/tx/domain-admin/result.js +33 -0
  164. package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
  165. package/dist/wallet/tx/domain-admin/types.js +1 -0
  166. package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
  167. package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
  168. package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
  169. package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
  170. package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
  171. package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
  172. package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
  173. package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
  174. package/dist/wallet/tx/domain-admin.d.ts +1 -107
  175. package/dist/wallet/tx/domain-admin.js +1 -729
  176. package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
  177. package/dist/wallet/tx/domain-market/confirm.js +52 -0
  178. package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
  179. package/dist/wallet/tx/domain-market/draft.js +286 -0
  180. package/dist/wallet/tx/domain-market/index.d.ts +6 -0
  181. package/dist/wallet/tx/domain-market/index.js +145 -0
  182. package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
  183. package/dist/wallet/tx/domain-market/intent.js +131 -0
  184. package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
  185. package/dist/wallet/tx/domain-market/plan.js +98 -0
  186. package/dist/wallet/tx/domain-market/result.d.ts +45 -0
  187. package/dist/wallet/tx/domain-market/result.js +88 -0
  188. package/dist/wallet/tx/domain-market/types.d.ts +221 -0
  189. package/dist/wallet/tx/domain-market/types.js +1 -0
  190. package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
  191. package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
  192. package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
  193. package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
  194. package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
  195. package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
  196. package/dist/wallet/tx/domain-market.d.ts +1 -116
  197. package/dist/wallet/tx/domain-market.js +1 -1078
  198. package/dist/wallet/tx/draft-build.d.ts +60 -0
  199. package/dist/wallet/tx/draft-build.js +127 -0
  200. package/dist/wallet/tx/executor.d.ts +6 -40
  201. package/dist/wallet/tx/executor.js +6 -100
  202. package/dist/wallet/tx/fee.d.ts +30 -0
  203. package/dist/wallet/tx/fee.js +98 -0
  204. package/dist/wallet/tx/field/confirm.d.ts +11 -0
  205. package/dist/wallet/tx/field/confirm.js +19 -0
  206. package/dist/wallet/tx/field/draft.d.ts +23 -0
  207. package/dist/wallet/tx/field/draft.js +202 -0
  208. package/dist/wallet/tx/field/index.d.ts +5 -0
  209. package/dist/wallet/tx/field/index.js +140 -0
  210. package/dist/wallet/tx/field/intent.d.ts +5 -0
  211. package/dist/wallet/tx/field/intent.js +50 -0
  212. package/dist/wallet/tx/field/plan.d.ts +20 -0
  213. package/dist/wallet/tx/field/plan.js +65 -0
  214. package/dist/wallet/tx/field/result.d.ts +29 -0
  215. package/dist/wallet/tx/field/result.js +103 -0
  216. package/dist/wallet/tx/field/types.d.ts +163 -0
  217. package/dist/wallet/tx/field/types.js +1 -0
  218. package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
  219. package/dist/wallet/tx/field/variants/clear.js +60 -0
  220. package/dist/wallet/tx/field/variants/create.d.ts +2 -0
  221. package/dist/wallet/tx/field/variants/create.js +67 -0
  222. package/dist/wallet/tx/field/variants/set.d.ts +2 -0
  223. package/dist/wallet/tx/field/variants/set.js +195 -0
  224. package/dist/wallet/tx/field.d.ts +1 -95
  225. package/dist/wallet/tx/field.js +1 -920
  226. package/dist/wallet/tx/mining-preemption.d.ts +6 -0
  227. package/dist/wallet/tx/mining-preemption.js +7 -0
  228. package/dist/wallet/tx/primitives.d.ts +13 -0
  229. package/dist/wallet/tx/primitives.js +42 -0
  230. package/dist/wallet/tx/psbt-assert.d.ts +14 -0
  231. package/dist/wallet/tx/psbt-assert.js +39 -0
  232. package/dist/wallet/tx/publish.d.ts +37 -0
  233. package/dist/wallet/tx/publish.js +88 -0
  234. package/dist/wallet/tx/readiness.d.ts +7 -0
  235. package/dist/wallet/tx/readiness.js +61 -0
  236. package/dist/wallet/tx/reconcile.d.ts +24 -0
  237. package/dist/wallet/tx/reconcile.js +72 -0
  238. package/dist/wallet/tx/register/confirm.d.ts +6 -0
  239. package/dist/wallet/tx/register/confirm.js +66 -0
  240. package/dist/wallet/tx/register/draft.d.ts +42 -0
  241. package/dist/wallet/tx/register/draft.js +181 -0
  242. package/dist/wallet/tx/register/index.d.ts +6 -0
  243. package/dist/wallet/tx/register/index.js +158 -0
  244. package/dist/wallet/tx/register/intent.d.ts +74 -0
  245. package/dist/wallet/tx/register/intent.js +119 -0
  246. package/dist/wallet/tx/register/plan.d.ts +43 -0
  247. package/dist/wallet/tx/register/plan.js +168 -0
  248. package/dist/wallet/tx/register/result.d.ts +78 -0
  249. package/dist/wallet/tx/register/result.js +41 -0
  250. package/dist/wallet/tx/register.d.ts +1 -70
  251. package/dist/wallet/tx/register.js +1 -681
  252. package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
  253. package/dist/wallet/tx/reputation/confirm.js +51 -0
  254. package/dist/wallet/tx/reputation/draft.d.ts +20 -0
  255. package/dist/wallet/tx/reputation/draft.js +130 -0
  256. package/dist/wallet/tx/reputation/index.d.ts +4 -0
  257. package/dist/wallet/tx/reputation/index.js +162 -0
  258. package/dist/wallet/tx/reputation/intent.d.ts +36 -0
  259. package/dist/wallet/tx/reputation/intent.js +157 -0
  260. package/dist/wallet/tx/reputation/plan.d.ts +19 -0
  261. package/dist/wallet/tx/reputation/plan.js +64 -0
  262. package/dist/wallet/tx/reputation/result.d.ts +21 -0
  263. package/dist/wallet/tx/reputation/result.js +31 -0
  264. package/dist/wallet/tx/reputation/types.d.ts +130 -0
  265. package/dist/wallet/tx/reputation/types.js +1 -0
  266. package/dist/wallet/tx/reputation.d.ts +1 -74
  267. package/dist/wallet/tx/reputation.js +1 -556
  268. package/dist/wallet/tx/signing.d.ts +18 -0
  269. package/dist/wallet/tx/signing.js +31 -0
  270. package/dist/wallet/tx/state-persist.d.ts +27 -0
  271. package/dist/wallet/tx/state-persist.js +54 -0
  272. package/dist/wallet/tx/types.d.ts +44 -0
  273. package/dist/wallet/tx/types.js +1 -0
  274. package/package.json +1 -1
  275. package/dist/cli/mining-json.d.ts +0 -20
  276. package/dist/cli/mining-json.js +0 -46
  277. package/dist/cli/mutation-json.d.ts +0 -325
  278. package/dist/cli/mutation-json.js +0 -269
  279. package/dist/cli/mutation-resolved-json.d.ts +0 -117
  280. package/dist/cli/mutation-resolved-json.js +0 -123
  281. package/dist/cli/preview-json.d.ts +0 -319
  282. package/dist/cli/preview-json.js +0 -254
  283. package/dist/cli/read-json.d.ts +0 -190
  284. package/dist/cli/read-json.js +0 -627
@@ -0,0 +1,161 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { lookupDomain, resolveCanonical, } from "@cogcoin/indexer/queries";
3
+ import { createWalletMutationFeeMetadata, unlockTemporaryBuilderLocks, updateMutationRecord, } from "../common.js";
4
+ import { persistWalletMutationState } from "../executor.js";
5
+ import { upsertPendingMutation } from "../journal.js";
6
+ import { bytesToHex } from "./intent.js";
7
+ export function createDomainAdminDraftMutation(options) {
8
+ if (options.existing !== null && options.existing !== undefined) {
9
+ return {
10
+ ...options.existing,
11
+ kind: options.kind,
12
+ domainName: options.domainName,
13
+ senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
14
+ senderLocalIndex: options.sender.localIndex,
15
+ recipientScriptPubKeyHex: options.recipientScriptPubKeyHex ?? null,
16
+ endpointValueHex: options.endpointValueHex ?? null,
17
+ status: "draft",
18
+ lastUpdatedAtUnixMs: options.nowUnixMs,
19
+ attemptedTxid: null,
20
+ attemptedWtxid: null,
21
+ ...createWalletMutationFeeMetadata(options.feeSelection),
22
+ temporaryBuilderLockedOutpoints: [],
23
+ };
24
+ }
25
+ return {
26
+ mutationId: randomBytes(12).toString("hex"),
27
+ kind: options.kind,
28
+ domainName: options.domainName,
29
+ parentDomainName: null,
30
+ senderScriptPubKeyHex: options.sender.scriptPubKeyHex,
31
+ senderLocalIndex: options.sender.localIndex,
32
+ recipientScriptPubKeyHex: options.recipientScriptPubKeyHex ?? null,
33
+ endpointValueHex: options.endpointValueHex ?? null,
34
+ intentFingerprintHex: options.intentFingerprintHex,
35
+ status: "draft",
36
+ createdAtUnixMs: options.nowUnixMs,
37
+ lastUpdatedAtUnixMs: options.nowUnixMs,
38
+ attemptedTxid: null,
39
+ attemptedWtxid: null,
40
+ ...createWalletMutationFeeMetadata(options.feeSelection),
41
+ temporaryBuilderLockedOutpoints: [],
42
+ };
43
+ }
44
+ function mutationConfirmedOnChain(mutation, context) {
45
+ if (context.snapshot === null) {
46
+ return false;
47
+ }
48
+ const chainDomain = lookupDomain(context.snapshot.state, mutation.domainName);
49
+ if (chainDomain === null || !chainDomain.anchored) {
50
+ return false;
51
+ }
52
+ const ownerHex = Buffer.from(chainDomain.ownerScriptPubKey).toString("hex");
53
+ if (ownerHex !== mutation.senderScriptPubKeyHex) {
54
+ return false;
55
+ }
56
+ if (mutation.kind === "endpoint") {
57
+ return bytesToHex(chainDomain.endpoint) === (mutation.endpointValueHex ?? "");
58
+ }
59
+ if (mutation.kind === "delegate") {
60
+ return bytesToHex(chainDomain.delegate) === (mutation.recipientScriptPubKeyHex ?? "");
61
+ }
62
+ if (mutation.kind === "miner") {
63
+ return bytesToHex(chainDomain.miner) === (mutation.recipientScriptPubKeyHex ?? "");
64
+ }
65
+ if (chainDomain.domainId === null) {
66
+ return false;
67
+ }
68
+ return resolveCanonical(context.snapshot.state, Buffer.from(mutation.senderScriptPubKeyHex, "hex")) === chainDomain.domainId;
69
+ }
70
+ function mutationNeedsRepair(mutation, context) {
71
+ if (context.snapshot === null) {
72
+ return false;
73
+ }
74
+ const chainDomain = lookupDomain(context.snapshot.state, mutation.domainName);
75
+ if (chainDomain === null) {
76
+ return false;
77
+ }
78
+ return !chainDomain.anchored || Buffer.from(chainDomain.ownerScriptPubKey).toString("hex") !== mutation.senderScriptPubKeyHex;
79
+ }
80
+ export async function reconcilePendingAdminMutation(options) {
81
+ if (options.mutation.status === "confirmed" || options.mutation.status === "live") {
82
+ return {
83
+ state: options.state,
84
+ mutation: options.mutation,
85
+ resolution: options.mutation.status,
86
+ };
87
+ }
88
+ if (options.mutation.status === "repair-required") {
89
+ return {
90
+ state: options.state,
91
+ mutation: options.mutation,
92
+ resolution: "repair-required",
93
+ };
94
+ }
95
+ if (mutationConfirmedOnChain(options.mutation, options.context)) {
96
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
97
+ const confirmed = updateMutationRecord(options.mutation, "confirmed", options.nowUnixMs, {
98
+ temporaryBuilderLockedOutpoints: [],
99
+ });
100
+ let nextState = upsertPendingMutation(options.state, confirmed);
101
+ nextState = await persistWalletMutationState({
102
+ state: nextState,
103
+ provider: options.provider,
104
+ nowUnixMs: options.nowUnixMs,
105
+ paths: options.paths,
106
+ });
107
+ return { state: nextState, mutation: confirmed, resolution: "confirmed" };
108
+ }
109
+ if (mutationNeedsRepair(options.mutation, options.context)) {
110
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
111
+ const repair = updateMutationRecord(options.mutation, "repair-required", options.nowUnixMs, {
112
+ temporaryBuilderLockedOutpoints: [],
113
+ });
114
+ let nextState = upsertPendingMutation(options.state, repair);
115
+ nextState = await persistWalletMutationState({
116
+ state: nextState,
117
+ provider: options.provider,
118
+ nowUnixMs: options.nowUnixMs,
119
+ paths: options.paths,
120
+ });
121
+ return { state: nextState, mutation: repair, resolution: "repair-required" };
122
+ }
123
+ const known = options.mutation.attemptedTxid === null
124
+ ? false
125
+ : await options.rpc.getRawTransaction(options.mutation.attemptedTxid, true).then(() => true).catch(() => false);
126
+ if (known) {
127
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
128
+ const live = updateMutationRecord(options.mutation, "live", options.nowUnixMs, {
129
+ temporaryBuilderLockedOutpoints: [],
130
+ });
131
+ let nextState = upsertPendingMutation(options.state, live);
132
+ nextState = await persistWalletMutationState({
133
+ state: nextState,
134
+ provider: options.provider,
135
+ nowUnixMs: options.nowUnixMs,
136
+ paths: options.paths,
137
+ });
138
+ return { state: nextState, mutation: live, resolution: "live" };
139
+ }
140
+ if (options.mutation.status === "broadcast-unknown"
141
+ || options.mutation.status === "draft"
142
+ || options.mutation.status === "broadcasting") {
143
+ await unlockTemporaryBuilderLocks(options.rpc, options.walletName, options.mutation.temporaryBuilderLockedOutpoints);
144
+ const canceled = updateMutationRecord(options.mutation, "canceled", options.nowUnixMs, {
145
+ temporaryBuilderLockedOutpoints: [],
146
+ });
147
+ let nextState = upsertPendingMutation(options.state, canceled);
148
+ nextState = await persistWalletMutationState({
149
+ state: nextState,
150
+ provider: options.provider,
151
+ nowUnixMs: options.nowUnixMs,
152
+ paths: options.paths,
153
+ });
154
+ return { state: nextState, mutation: canceled, resolution: "not-seen" };
155
+ }
156
+ return {
157
+ state: options.state,
158
+ mutation: options.mutation,
159
+ resolution: "continue",
160
+ };
161
+ }
@@ -0,0 +1,9 @@
1
+ import type { ClearDomainDelegateOptions, ClearDomainEndpointOptions, ClearDomainMinerOptions, DomainAdminMutationResult, SetDomainCanonicalOptions, SetDomainDelegateOptions, SetDomainEndpointOptions, SetDomainMinerOptions } from "./types.js";
2
+ export type { ClearDomainDelegateOptions, ClearDomainEndpointOptions, ClearDomainMinerOptions, DomainAdminMutationResult, DomainAdminResolvedEffect, DomainAdminResolvedSenderSummary, DomainAdminResolvedSummary, DomainAdminResolvedTargetSummary, SetDomainCanonicalOptions, SetDomainDelegateOptions, SetDomainEndpointOptions, SetDomainMinerOptions, } from "./types.js";
3
+ export declare function setDomainEndpoint(options: SetDomainEndpointOptions): Promise<DomainAdminMutationResult>;
4
+ export declare function clearDomainEndpoint(options: ClearDomainEndpointOptions): Promise<DomainAdminMutationResult>;
5
+ export declare function setDomainDelegate(options: SetDomainDelegateOptions): Promise<DomainAdminMutationResult>;
6
+ export declare function clearDomainDelegate(options: ClearDomainDelegateOptions): Promise<DomainAdminMutationResult>;
7
+ export declare function setDomainMiner(options: SetDomainMinerOptions): Promise<DomainAdminMutationResult>;
8
+ export declare function clearDomainMiner(options: ClearDomainMinerOptions): Promise<DomainAdminMutationResult>;
9
+ export declare function setDomainCanonical(options: SetDomainCanonicalOptions): Promise<DomainAdminMutationResult>;
@@ -0,0 +1,150 @@
1
+ import { mergeFixedWalletInputs } from "../common.js";
2
+ import { executeWalletMutationOperation, publishWalletMutation, resolveExistingWalletMutation, } from "../executor.js";
3
+ import { createDomainAdminDraftMutation, reconcilePendingAdminMutation, } from "./draft.js";
4
+ import { createResolvedDomainAdminSenderSummary, createDomainAdminIntentFingerprint, normalizeDomainAdminDomainName, resolveAnchoredDomainOperation, } from "./intent.js";
5
+ import { buildPlanForDomainAdminOperation, buildDomainAdminTransaction, } from "./plan.js";
6
+ import { createDomainAdminResult, createDomainAdminReuseResult, } from "./result.js";
7
+ import { createCanonicalVariant } from "./variants/canonical.js";
8
+ import { createClearDelegateVariant, createSetDelegateVariant, } from "./variants/delegate.js";
9
+ import { createClearEndpointVariant, createSetEndpointVariant, } from "./variants/endpoint.js";
10
+ import { createClearMinerVariant, createSetMinerVariant, } from "./variants/miner.js";
11
+ async function submitDomainAdminMutation(options, variant) {
12
+ const execution = await executeWalletMutationOperation({
13
+ ...options,
14
+ controlLockPurpose: variant.errorPrefix,
15
+ preemptionReason: variant.errorPrefix,
16
+ async resolveOperation(readContext) {
17
+ const normalizedDomainName = normalizeDomainAdminDomainName(options.domainName);
18
+ const operation = resolveAnchoredDomainOperation(readContext, normalizedDomainName, variant.errorPrefix, { requireRoot: variant.requireRoot });
19
+ return {
20
+ ...operation,
21
+ normalizedDomainName,
22
+ resolvedSender: createResolvedDomainAdminSenderSummary(operation.sender, operation.senderSelector),
23
+ payload: await variant.createPayload(operation),
24
+ };
25
+ },
26
+ createIntentFingerprint(operation) {
27
+ return createDomainAdminIntentFingerprint([
28
+ variant.kind,
29
+ operation.state.walletRootId,
30
+ ...variant.intentParts(operation),
31
+ ]);
32
+ },
33
+ async resolveExistingMutation({ operation, existingMutation, execution }) {
34
+ if (existingMutation === null) {
35
+ return {
36
+ state: operation.state,
37
+ replacementFixedInputs: null,
38
+ result: null,
39
+ };
40
+ }
41
+ return resolveExistingWalletMutation({
42
+ existingMutation,
43
+ execution,
44
+ repairRequiredErrorCode: `${variant.errorPrefix}_repair_required`,
45
+ reconcileExistingMutation: (mutation) => reconcilePendingAdminMutation({
46
+ state: operation.state,
47
+ mutation,
48
+ provider: execution.provider,
49
+ nowUnixMs: execution.nowUnixMs,
50
+ paths: execution.paths,
51
+ rpc: execution.rpc,
52
+ walletName: execution.walletName,
53
+ context: execution.readContext,
54
+ }),
55
+ createReuseResult: ({ mutation, resolution, fees }) => createDomainAdminReuseResult({
56
+ variant,
57
+ operation,
58
+ mutation,
59
+ resolution,
60
+ fees,
61
+ }),
62
+ });
63
+ },
64
+ confirm({ operation }) {
65
+ return variant.confirm(operation);
66
+ },
67
+ createDraftMutation({ operation, existingMutation, execution, intentFingerprintHex }) {
68
+ return {
69
+ mutation: createDomainAdminDraftMutation({
70
+ kind: variant.kind,
71
+ domainName: operation.normalizedDomainName,
72
+ sender: operation.sender,
73
+ intentFingerprintHex,
74
+ nowUnixMs: execution.nowUnixMs,
75
+ feeSelection: execution.feeSelection,
76
+ recipientScriptPubKeyHex: operation.payload.recipientScriptPubKeyHex ?? null,
77
+ endpointValueHex: operation.payload.endpointValueHex ?? null,
78
+ existing: existingMutation,
79
+ }),
80
+ prepared: null,
81
+ };
82
+ },
83
+ async build({ operation, state, execution, replacementFixedInputs }) {
84
+ const adminPlan = buildPlanForDomainAdminOperation({
85
+ state,
86
+ allUtxos: await execution.rpc.listUnspent(execution.walletName, 1),
87
+ sender: operation.sender,
88
+ opReturnData: operation.payload.opReturnData,
89
+ errorPrefix: variant.errorPrefix,
90
+ });
91
+ return buildDomainAdminTransaction({
92
+ rpc: execution.rpc,
93
+ walletName: execution.walletName,
94
+ state,
95
+ plan: {
96
+ ...adminPlan,
97
+ fixedInputs: mergeFixedWalletInputs(adminPlan.fixedInputs, replacementFixedInputs),
98
+ },
99
+ feeRateSatVb: execution.feeSelection.feeRateSatVb,
100
+ });
101
+ },
102
+ publish({ state, execution, built, mutation }) {
103
+ return publishWalletMutation({
104
+ rpc: execution.rpc,
105
+ walletName: execution.walletName,
106
+ snapshotHeight: execution.readContext.snapshot?.tip?.height ?? null,
107
+ built,
108
+ mutation,
109
+ state,
110
+ provider: execution.provider,
111
+ nowUnixMs: execution.nowUnixMs,
112
+ paths: execution.paths,
113
+ errorPrefix: variant.errorPrefix,
114
+ });
115
+ },
116
+ createResult({ operation, mutation, built, status, reusedExisting, fees }) {
117
+ return createDomainAdminResult({
118
+ variant,
119
+ operation,
120
+ mutation,
121
+ builtTxid: built?.txid ?? null,
122
+ status: status,
123
+ reusedExisting,
124
+ fees,
125
+ });
126
+ },
127
+ });
128
+ return execution.result;
129
+ }
130
+ export async function setDomainEndpoint(options) {
131
+ return submitDomainAdminMutation(options, await createSetEndpointVariant(options));
132
+ }
133
+ export async function clearDomainEndpoint(options) {
134
+ return submitDomainAdminMutation(options, createClearEndpointVariant(options));
135
+ }
136
+ export async function setDomainDelegate(options) {
137
+ return submitDomainAdminMutation(options, createSetDelegateVariant(options));
138
+ }
139
+ export async function clearDomainDelegate(options) {
140
+ return submitDomainAdminMutation(options, createClearDelegateVariant(options));
141
+ }
142
+ export async function setDomainMiner(options) {
143
+ return submitDomainAdminMutation(options, createSetMinerVariant(options));
144
+ }
145
+ export async function clearDomainMiner(options) {
146
+ return submitDomainAdminMutation(options, createClearMinerVariant(options));
147
+ }
148
+ export async function setDomainCanonical(options) {
149
+ return submitDomainAdminMutation(options, createCanonicalVariant(options));
150
+ }
@@ -0,0 +1,12 @@
1
+ import { type MutationSender } from "../common.js";
2
+ import { normalizeBtcTarget } from "../targets.js";
3
+ import type { DomainAdminOperation, DomainAdminResolvedSenderSummary, DomainAdminResolvedTargetSummary, ReadyWalletReadContext } from "./types.js";
4
+ export declare function normalizeDomainAdminDomainName(domainName: string): string;
5
+ export declare function bytesToHex(value: Uint8Array | null | undefined): string;
6
+ export declare function createDomainAdminIntentFingerprint(parts: Array<string | number | bigint>): string;
7
+ export declare function createResolvedDomainAdminSenderSummary(sender: MutationSender, selector: string): DomainAdminResolvedSenderSummary;
8
+ export declare function createResolvedDomainAdminTargetSummary(target: ReturnType<typeof normalizeBtcTarget>): DomainAdminResolvedTargetSummary;
9
+ export declare function resolveAnchoredDomainOperation(context: ReadyWalletReadContext, domainName: string, errorPrefix: string, options?: {
10
+ requireRoot?: boolean;
11
+ rejectReadOnly?: boolean;
12
+ }): DomainAdminOperation;
@@ -0,0 +1,61 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lookupDomain } from "@cogcoin/indexer/queries";
3
+ import { validateDomainName } from "../../cogop/index.js";
4
+ import { assertWalletMutationContextReady, createFundingMutationSender, } from "../common.js";
5
+ import { normalizeBtcTarget } from "../targets.js";
6
+ export function normalizeDomainAdminDomainName(domainName) {
7
+ const normalized = domainName.trim().toLowerCase();
8
+ if (normalized.length === 0) {
9
+ throw new Error("wallet_domain_admin_missing_domain");
10
+ }
11
+ validateDomainName(normalized);
12
+ return normalized;
13
+ }
14
+ export function bytesToHex(value) {
15
+ return Buffer.from(value ?? new Uint8Array()).toString("hex");
16
+ }
17
+ export function createDomainAdminIntentFingerprint(parts) {
18
+ return createHash("sha256")
19
+ .update(parts.map((part) => String(part)).join("\n"))
20
+ .digest("hex");
21
+ }
22
+ export function createResolvedDomainAdminSenderSummary(sender, selector) {
23
+ return {
24
+ selector,
25
+ localIndex: sender.localIndex,
26
+ scriptPubKeyHex: sender.scriptPubKeyHex,
27
+ address: sender.address,
28
+ };
29
+ }
30
+ export function createResolvedDomainAdminTargetSummary(target) {
31
+ return {
32
+ scriptPubKeyHex: target.scriptPubKeyHex,
33
+ address: target.address,
34
+ opaque: target.opaque,
35
+ };
36
+ }
37
+ export function resolveAnchoredDomainOperation(context, domainName, errorPrefix, options = {}) {
38
+ void options.rejectReadOnly;
39
+ assertWalletMutationContextReady(context, errorPrefix);
40
+ const chainDomain = lookupDomain(context.snapshot.state, domainName);
41
+ if (chainDomain === null) {
42
+ throw new Error(`${errorPrefix}_domain_not_found`);
43
+ }
44
+ if (!chainDomain.anchored) {
45
+ throw new Error(`${errorPrefix}_domain_not_anchored`);
46
+ }
47
+ if (options.requireRoot && domainName.includes("-")) {
48
+ throw new Error(`${errorPrefix}_root_domain_required`);
49
+ }
50
+ const ownerHex = Buffer.from(chainDomain.ownerScriptPubKey).toString("hex");
51
+ if (ownerHex !== context.localState.state.funding.scriptPubKeyHex || context.model.walletAddress == null) {
52
+ throw new Error(`${errorPrefix}_owner_not_locally_controlled`);
53
+ }
54
+ return {
55
+ readContext: context,
56
+ state: context.localState.state,
57
+ sender: createFundingMutationSender(context.localState.state),
58
+ senderSelector: context.model.walletAddress,
59
+ chainDomain,
60
+ };
61
+ }
@@ -0,0 +1,19 @@
1
+ import type { RpcDecodedPsbt, RpcListUnspentEntry } from "../../../bitcoind/types.js";
2
+ import { type MutationSender } from "../common.js";
3
+ import type { BuiltDomainAdminTransaction, DomainAdminPlan, DomainAdminRpcClient } from "./types.js";
4
+ import type { WalletStateV1 } from "../../types.js";
5
+ export declare function buildPlanForDomainAdminOperation(options: {
6
+ state: WalletStateV1;
7
+ allUtxos: RpcListUnspentEntry[];
8
+ sender: MutationSender;
9
+ opReturnData: Uint8Array;
10
+ errorPrefix: string;
11
+ }): DomainAdminPlan;
12
+ export declare function validateFundedDomainAdminDraft(decoded: RpcDecodedPsbt, funded: BuiltDomainAdminTransaction["funded"], plan: DomainAdminPlan): void;
13
+ export declare function buildDomainAdminTransaction(options: {
14
+ rpc: DomainAdminRpcClient;
15
+ walletName: string;
16
+ state: WalletStateV1;
17
+ plan: DomainAdminPlan;
18
+ feeRateSatVb: number;
19
+ }): Promise<BuiltDomainAdminTransaction>;
@@ -0,0 +1,64 @@
1
+ import { buildWalletMutationTransactionWithReserveFallback, outpointKey, } from "../common.js";
2
+ function encodeOpReturnScript(payload) {
3
+ if (payload.length <= 75) {
4
+ return Buffer.concat([
5
+ Buffer.from([0x6a, payload.length]),
6
+ Buffer.from(payload),
7
+ ]).toString("hex");
8
+ }
9
+ return Buffer.concat([
10
+ Buffer.from([0x6a, 0x4c, payload.length]),
11
+ Buffer.from(payload),
12
+ ]).toString("hex");
13
+ }
14
+ export function buildPlanForDomainAdminOperation(options) {
15
+ const fundingUtxos = options.allUtxos.filter((entry) => entry.scriptPubKey === options.state.funding.scriptPubKeyHex
16
+ && entry.confirmations >= 1
17
+ && entry.spendable !== false
18
+ && entry.safe !== false);
19
+ return {
20
+ sender: options.sender,
21
+ changeAddress: options.state.funding.address,
22
+ fixedInputs: [],
23
+ outputs: [{ data: Buffer.from(options.opReturnData).toString("hex") }],
24
+ changePosition: 1,
25
+ expectedOpReturnScriptHex: encodeOpReturnScript(options.opReturnData),
26
+ allowedFundingScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
27
+ eligibleFundingOutpointKeys: new Set(fundingUtxos.map((entry) => outpointKey({ txid: entry.txid, vout: entry.vout }))),
28
+ errorPrefix: options.errorPrefix,
29
+ };
30
+ }
31
+ export function validateFundedDomainAdminDraft(decoded, funded, plan) {
32
+ const inputs = decoded.tx.vin;
33
+ const outputs = decoded.tx.vout;
34
+ if (inputs.length === 0) {
35
+ throw new Error(`${plan.errorPrefix}_missing_sender_input`);
36
+ }
37
+ if (outputs[0]?.scriptPubKey?.hex !== plan.expectedOpReturnScriptHex) {
38
+ throw new Error(`${plan.errorPrefix}_opreturn_mismatch`);
39
+ }
40
+ if (funded.changepos === -1) {
41
+ if (outputs.length !== 1) {
42
+ throw new Error(`${plan.errorPrefix}_unexpected_output_count`);
43
+ }
44
+ return;
45
+ }
46
+ if (funded.changepos !== plan.changePosition || outputs.length !== 2) {
47
+ throw new Error(`${plan.errorPrefix}_change_position_mismatch`);
48
+ }
49
+ if (outputs[funded.changepos]?.scriptPubKey?.hex !== plan.allowedFundingScriptPubKeyHex) {
50
+ throw new Error(`${plan.errorPrefix}_change_output_mismatch`);
51
+ }
52
+ }
53
+ export async function buildDomainAdminTransaction(options) {
54
+ return buildWalletMutationTransactionWithReserveFallback({
55
+ rpc: options.rpc,
56
+ walletName: options.walletName,
57
+ state: options.state,
58
+ plan: options.plan,
59
+ validateFundedDraft: validateFundedDomainAdminDraft,
60
+ finalizeErrorCode: `${options.plan.errorPrefix}_finalize_failed`,
61
+ mempoolRejectPrefix: `${options.plan.errorPrefix}_mempool_rejected`,
62
+ feeRate: options.feeRateSatVb,
63
+ });
64
+ }
@@ -0,0 +1,19 @@
1
+ import type { PendingMutationRecord } from "../../types.js";
2
+ import type { WalletMutationFeeSummary } from "../common.js";
3
+ import type { DomainAdminMutationResult, DomainAdminVariant, StandaloneDomainAdminOperation } from "./types.js";
4
+ export declare function createDomainAdminReuseResult(options: {
5
+ variant: DomainAdminVariant;
6
+ operation: StandaloneDomainAdminOperation;
7
+ mutation: PendingMutationRecord;
8
+ resolution: "confirmed" | "live";
9
+ fees: WalletMutationFeeSummary;
10
+ }): DomainAdminMutationResult;
11
+ export declare function createDomainAdminResult(options: {
12
+ variant: DomainAdminVariant;
13
+ operation: StandaloneDomainAdminOperation;
14
+ mutation: PendingMutationRecord;
15
+ builtTxid: string | null;
16
+ status: "live" | "confirmed";
17
+ reusedExisting: boolean;
18
+ fees: WalletMutationFeeSummary;
19
+ }): DomainAdminMutationResult;
@@ -0,0 +1,33 @@
1
+ function createResolvedSummary(operation) {
2
+ return {
3
+ sender: operation.resolvedSender,
4
+ target: operation.payload.resolvedTarget,
5
+ effect: operation.payload.resolvedEffect,
6
+ };
7
+ }
8
+ export function createDomainAdminReuseResult(options) {
9
+ return {
10
+ kind: options.variant.kind,
11
+ domainName: options.operation.normalizedDomainName,
12
+ txid: options.mutation.attemptedTxid ?? "unknown",
13
+ status: options.resolution,
14
+ reusedExisting: true,
15
+ recipientScriptPubKeyHex: options.operation.payload.recipientScriptPubKeyHex ?? null,
16
+ endpointValueHex: options.operation.payload.endpointValueHex ?? null,
17
+ resolved: createResolvedSummary(options.operation),
18
+ fees: options.fees,
19
+ };
20
+ }
21
+ export function createDomainAdminResult(options) {
22
+ return {
23
+ kind: options.variant.kind,
24
+ domainName: options.operation.normalizedDomainName,
25
+ txid: options.mutation.attemptedTxid ?? options.builtTxid ?? "unknown",
26
+ status: options.status,
27
+ reusedExisting: options.reusedExisting,
28
+ recipientScriptPubKeyHex: options.operation.payload.recipientScriptPubKeyHex ?? null,
29
+ endpointValueHex: options.operation.payload.endpointValueHex ?? null,
30
+ resolved: createResolvedSummary(options.operation),
31
+ fees: options.fees,
32
+ };
33
+ }