@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
@@ -0,0 +1,163 @@
1
+ import type { lookupDomain } from "@cogcoin/indexer/queries";
2
+ import type { RpcTransaction } from "../../../bitcoind/types.js";
3
+ import type { WalletPrompter } from "../../lifecycle.js";
4
+ import type { WalletReadContext } from "../../read/index.js";
5
+ import type { WalletRuntimePaths } from "../../runtime.js";
6
+ import type { WalletSecretProvider } from "../../state/provider.js";
7
+ import type { PendingMutationRecord, WalletStateV1 } from "../../types.js";
8
+ import type { FixedWalletInput, MutationSender, WalletMutationFeeSummary, WalletMutationRpcClient } from "../common.js";
9
+ export type FieldMutationKind = "field-create" | "field-set" | "field-clear";
10
+ export type FieldValueInputSource = {
11
+ kind: "text";
12
+ value: string;
13
+ } | {
14
+ kind: "json";
15
+ value: string;
16
+ } | {
17
+ kind: "bytes";
18
+ value: string;
19
+ } | {
20
+ kind: "raw";
21
+ format: string;
22
+ value: string;
23
+ };
24
+ export interface FieldRpcClient extends WalletMutationRpcClient {
25
+ getBlockchainInfo(): Promise<{
26
+ blocks: number;
27
+ }>;
28
+ sendRawTransaction(hex: string): Promise<string>;
29
+ getRawTransaction(txid: string, verbose?: boolean): Promise<RpcTransaction>;
30
+ }
31
+ export interface FieldPlan {
32
+ sender: MutationSender;
33
+ changeAddress: string;
34
+ fixedInputs: FixedWalletInput[];
35
+ outputs: unknown[];
36
+ changePosition: number;
37
+ expectedOpReturnScriptHex: string;
38
+ allowedFundingScriptPubKeyHex: string;
39
+ eligibleFundingOutpointKeys: Set<string>;
40
+ errorPrefix: string;
41
+ }
42
+ export type ReadyWalletReadContext = WalletReadContext & {
43
+ localState: {
44
+ availability: "ready";
45
+ state: WalletStateV1;
46
+ };
47
+ snapshot: NonNullable<WalletReadContext["snapshot"]>;
48
+ model: NonNullable<WalletReadContext["model"]>;
49
+ };
50
+ export interface FieldOperation {
51
+ readContext: ReadyWalletReadContext;
52
+ state: WalletStateV1;
53
+ sender: MutationSender;
54
+ senderSelector: string;
55
+ chainDomain: NonNullable<ReturnType<typeof lookupDomain>>;
56
+ }
57
+ export interface StandaloneFieldMutationOperation extends FieldOperation {
58
+ normalizedDomainName: string;
59
+ normalizedFieldName: string;
60
+ existingObservedField: ReturnType<typeof import("../../read/index.js").findDomainField>;
61
+ }
62
+ export interface NormalizedFieldValue {
63
+ format: number;
64
+ formatLabel: string;
65
+ value: Uint8Array;
66
+ valueHex: string;
67
+ }
68
+ export interface CreateFieldOptions {
69
+ domainName: string;
70
+ fieldName: string;
71
+ permanent?: boolean;
72
+ feeRateSatVb?: number | null;
73
+ dataDir: string;
74
+ databasePath: string;
75
+ provider?: WalletSecretProvider;
76
+ prompter: WalletPrompter;
77
+ assumeYes?: boolean;
78
+ nowUnixMs?: number;
79
+ paths?: WalletRuntimePaths;
80
+ openReadContext?: typeof import("../../read/index.js").openWalletReadContext;
81
+ attachService?: typeof import("../../../bitcoind/service.js").attachOrStartManagedBitcoindService;
82
+ rpcFactory?: (config: Parameters<typeof import("../../../bitcoind/node.js").createRpcClient>[0]) => FieldRpcClient;
83
+ }
84
+ export interface SetFieldOptions extends Omit<CreateFieldOptions, "permanent"> {
85
+ source: FieldValueInputSource;
86
+ }
87
+ export interface ClearFieldOptions extends Omit<CreateFieldOptions, "permanent" | "source"> {
88
+ }
89
+ export interface FieldMutationResult {
90
+ kind: FieldMutationKind;
91
+ domainName: string;
92
+ fieldName: string;
93
+ fieldId: number | null;
94
+ txid: string;
95
+ permanent: boolean | null;
96
+ format: number | null;
97
+ status: "live" | "confirmed";
98
+ reusedExisting: boolean;
99
+ resolved?: FieldResolvedSummary | null;
100
+ fees: WalletMutationFeeSummary;
101
+ }
102
+ export interface FieldResolvedSenderSummary {
103
+ selector: string;
104
+ localIndex: number;
105
+ scriptPubKeyHex: string;
106
+ address: string;
107
+ }
108
+ export type FieldResolvedPath = "standalone-field-reg" | "standalone-data-update" | "standalone-data-clear";
109
+ export interface FieldResolvedValueSummary {
110
+ format: number;
111
+ byteLength: number;
112
+ }
113
+ export type FieldResolvedEffect = {
114
+ kind: "create-empty-field";
115
+ burnCogtoshi: "100";
116
+ } | {
117
+ kind: "write-field-value";
118
+ burnCogtoshi: "1";
119
+ } | {
120
+ kind: "clear-field-value";
121
+ burnCogtoshi: "0";
122
+ };
123
+ export interface FieldResolvedSummary {
124
+ sender: FieldResolvedSenderSummary;
125
+ path: FieldResolvedPath;
126
+ value: FieldResolvedValueSummary | null;
127
+ effect: FieldResolvedEffect;
128
+ }
129
+ export interface FieldDraftMutationOptions {
130
+ kind: FieldMutationKind;
131
+ domainName: string;
132
+ fieldName: string;
133
+ sender: MutationSender;
134
+ intentFingerprintHex: string;
135
+ nowUnixMs: number;
136
+ feeSelection: {
137
+ feeRateSatVb: number;
138
+ source: "custom-satvb" | "estimated-next-block-plus-one" | "fallback-default";
139
+ };
140
+ existing?: PendingMutationRecord | null;
141
+ fieldId?: number | null;
142
+ fieldPermanent?: boolean | null;
143
+ fieldFormat?: number | null;
144
+ fieldValueHex?: string | null;
145
+ }
146
+ export interface PreparedFieldMutation {
147
+ opReturnData: Uint8Array;
148
+ mutation: PendingMutationRecord;
149
+ }
150
+ export interface FieldMutationVariant {
151
+ kind: FieldMutationKind;
152
+ errorPrefix: string;
153
+ createMutation(options: {
154
+ operation: FieldOperation;
155
+ existing: PendingMutationRecord | null;
156
+ feeSelection: {
157
+ feeRateSatVb: number;
158
+ source: "custom-satvb" | "estimated-next-block-plus-one" | "fallback-default";
159
+ };
160
+ nowUnixMs: number;
161
+ }): Promise<PreparedFieldMutation>;
162
+ confirm(operation: FieldOperation): Promise<void>;
163
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { ClearFieldOptions, FieldMutationVariant } from "../types.js";
2
+ export declare function createClearFieldVariant(options: ClearFieldOptions): FieldMutationVariant;
@@ -0,0 +1,60 @@
1
+ import { FIELD_FORMAT_BYTES, serializeDataUpdate } from "../../../cogop/index.js";
2
+ import { createFieldIntentFingerprint, normalizeFieldDomainName, normalizeFieldNameInput, } from "../intent.js";
3
+ import { createStandaloneFieldMutation, getObservedFieldState, } from "../draft.js";
4
+ import { describeFieldEffect } from "../result.js";
5
+ export function createClearFieldVariant(options) {
6
+ return {
7
+ kind: "field-clear",
8
+ errorPrefix: "wallet_field_clear",
9
+ async createMutation({ operation, existing, feeSelection, nowUnixMs }) {
10
+ const normalizedDomainName = normalizeFieldDomainName(options.domainName);
11
+ const normalizedFieldName = normalizeFieldNameInput(options.fieldName);
12
+ const observedField = getObservedFieldState(operation.readContext, normalizedDomainName, normalizedFieldName);
13
+ if (observedField === null) {
14
+ throw new Error("wallet_field_clear_field_not_found");
15
+ }
16
+ if (observedField.permanent && !observedField.hasValue) {
17
+ throw new Error("wallet_field_clear_noop_permanent_clear");
18
+ }
19
+ const intentFingerprintHex = createFieldIntentFingerprint([
20
+ "field-clear",
21
+ operation.state.walletRootId,
22
+ normalizedDomainName,
23
+ observedField.fieldId,
24
+ ]);
25
+ return {
26
+ opReturnData: serializeDataUpdate(operation.chainDomain.domainId, observedField.fieldId, FIELD_FORMAT_BYTES.clear).opReturnData,
27
+ mutation: createStandaloneFieldMutation({
28
+ kind: "field-clear",
29
+ domainName: normalizedDomainName,
30
+ fieldName: normalizedFieldName,
31
+ sender: operation.sender,
32
+ intentFingerprintHex,
33
+ nowUnixMs,
34
+ feeSelection,
35
+ existing,
36
+ fieldId: observedField.fieldId,
37
+ fieldPermanent: observedField.permanent,
38
+ fieldFormat: FIELD_FORMAT_BYTES.clear,
39
+ fieldValueHex: "",
40
+ }),
41
+ };
42
+ },
43
+ async confirm(operation) {
44
+ const normalizedDomainName = normalizeFieldDomainName(options.domainName);
45
+ const normalizedFieldName = normalizeFieldNameInput(options.fieldName);
46
+ const observedField = getObservedFieldState(operation.readContext, normalizedDomainName, normalizedFieldName);
47
+ if (observedField === null) {
48
+ throw new Error("wallet_field_clear_field_not_found");
49
+ }
50
+ if (observedField.permanent && !observedField.hasValue) {
51
+ throw new Error("wallet_field_clear_noop_permanent_clear");
52
+ }
53
+ options.prompter.writeLine(`Clearing field "${normalizedDomainName}:${normalizedFieldName}".`);
54
+ options.prompter.writeLine(`Resolved sender: ${operation.senderSelector} (${operation.sender.address})`);
55
+ options.prompter.writeLine("Path: standalone-data-clear");
56
+ options.prompter.writeLine(`Effect: ${describeFieldEffect({ kind: "clear-field-value", burnCogtoshi: "0" })}.`);
57
+ options.prompter.writeLine("This publishes a standalone DATA_UPDATE clear.");
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,2 @@
1
+ import type { CreateFieldOptions, FieldMutationVariant } from "../types.js";
2
+ export declare function createFieldCreateVariant(options: CreateFieldOptions): FieldMutationVariant;
@@ -0,0 +1,67 @@
1
+ import { getBalance } from "@cogcoin/indexer/queries";
2
+ import { serializeFieldReg } from "../../../cogop/index.js";
3
+ import { confirmYesNo } from "../confirm.js";
4
+ import { createFieldIntentFingerprint, normalizeFieldDomainName, normalizeFieldNameInput, } from "../intent.js";
5
+ import { createStandaloneFieldMutation, findActiveFieldCreateMutationByDomain, getObservedFieldState, } from "../draft.js";
6
+ import { createResolvedFieldSenderSummary, describeFieldEffect, } from "../result.js";
7
+ export function createFieldCreateVariant(options) {
8
+ const permanent = options.permanent ?? false;
9
+ return {
10
+ kind: "field-create",
11
+ errorPrefix: "wallet_field_create",
12
+ async createMutation({ operation, existing, feeSelection, nowUnixMs }) {
13
+ const normalizedDomainName = normalizeFieldDomainName(options.domainName);
14
+ const normalizedFieldName = normalizeFieldNameInput(options.fieldName);
15
+ const existingField = getObservedFieldState(operation.readContext, normalizedDomainName, normalizedFieldName);
16
+ if (existingField !== null) {
17
+ throw new Error("wallet_field_create_field_exists");
18
+ }
19
+ if (operation.chainDomain.nextFieldId === 0xffff_ffff) {
20
+ throw new Error("wallet_field_create_field_id_exhausted");
21
+ }
22
+ const senderBalance = getBalance(operation.readContext.snapshot.state, Buffer.from(operation.sender.scriptPubKeyHex, "hex"));
23
+ if (senderBalance < 100n) {
24
+ throw new Error("wallet_field_create_insufficient_cog");
25
+ }
26
+ const intentFingerprintHex = createFieldIntentFingerprint([
27
+ "field-create",
28
+ operation.state.walletRootId,
29
+ normalizedDomainName,
30
+ normalizedFieldName,
31
+ permanent ? 1 : 0,
32
+ ]);
33
+ const conflictCreate = findActiveFieldCreateMutationByDomain(operation.state, normalizedDomainName, intentFingerprintHex);
34
+ if (conflictCreate !== null) {
35
+ throw new Error("wallet_field_create_registration_already_pending");
36
+ }
37
+ return {
38
+ opReturnData: serializeFieldReg(operation.chainDomain.domainId, permanent, normalizedFieldName).opReturnData,
39
+ mutation: createStandaloneFieldMutation({
40
+ kind: "field-create",
41
+ domainName: normalizedDomainName,
42
+ fieldName: normalizedFieldName,
43
+ sender: operation.sender,
44
+ intentFingerprintHex,
45
+ nowUnixMs,
46
+ feeSelection,
47
+ existing,
48
+ fieldId: operation.chainDomain.nextFieldId,
49
+ fieldPermanent: permanent,
50
+ }),
51
+ };
52
+ },
53
+ async confirm(operation) {
54
+ const fieldRef = `${normalizeFieldDomainName(options.domainName)}:${normalizeFieldNameInput(options.fieldName)}`;
55
+ options.prompter.writeLine(`Creating field "${fieldRef}" as ${permanent ? "permanent" : "mutable"}.`);
56
+ options.prompter.writeLine(`Resolved sender: ${operation.senderSelector} (${operation.sender.address})`);
57
+ options.prompter.writeLine("Path: standalone-field-reg");
58
+ options.prompter.writeLine(`Effect: ${describeFieldEffect({ kind: "create-empty-field", burnCogtoshi: "100" })}.`);
59
+ options.prompter.writeLine("This publishes a standalone FIELD_REG and burns 0.00000100 COG.");
60
+ await confirmYesNo(options.prompter, "The field will be created empty and the burn is not reversible.", "wallet_field_create_confirmation_rejected", {
61
+ assumeYes: options.assumeYes,
62
+ requiresTtyErrorCode: "wallet_field_create_requires_tty",
63
+ });
64
+ void createResolvedFieldSenderSummary;
65
+ },
66
+ };
67
+ }
@@ -0,0 +1,2 @@
1
+ import type { FieldMutationVariant, SetFieldOptions } from "../types.js";
2
+ export declare function createSetFieldVariant(options: SetFieldOptions): Promise<FieldMutationVariant>;
@@ -0,0 +1,195 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { resolve as resolvePath } from "node:path";
3
+ import { FIELD_FORMAT_BYTES, serializeDataUpdate, } from "../../../cogop/index.js";
4
+ import { getBalance } from "@cogcoin/indexer/queries";
5
+ import { confirmTyped, confirmYesNo, } from "../confirm.js";
6
+ import { createFieldIntentFingerprint, normalizeFieldDomainName, normalizeFieldNameInput, } from "../intent.js";
7
+ import { createStandaloneFieldMutation, getObservedFieldState, } from "../draft.js";
8
+ import { describeFieldEffect, } from "../result.js";
9
+ function describeRawFormat(format) {
10
+ if (format === FIELD_FORMAT_BYTES.bytes) {
11
+ return "bytes (0x01)";
12
+ }
13
+ if (format === FIELD_FORMAT_BYTES.text) {
14
+ return "text (0x02)";
15
+ }
16
+ if (format === FIELD_FORMAT_BYTES.json) {
17
+ return "json (0x09)";
18
+ }
19
+ return `raw (0x${format.toString(16).padStart(2, "0")})`;
20
+ }
21
+ async function loadFieldValue(source) {
22
+ if (source.kind === "text") {
23
+ if (source.value.length === 0) {
24
+ throw new Error("wallet_field_value_missing");
25
+ }
26
+ const value = new TextEncoder().encode(source.value);
27
+ return {
28
+ format: FIELD_FORMAT_BYTES.text,
29
+ formatLabel: "text (0x02)",
30
+ value,
31
+ valueHex: Buffer.from(value).toString("hex"),
32
+ };
33
+ }
34
+ if (source.kind === "json") {
35
+ if (source.value.length === 0) {
36
+ throw new Error("wallet_field_value_missing");
37
+ }
38
+ try {
39
+ JSON.parse(source.value);
40
+ }
41
+ catch {
42
+ throw new Error("wallet_field_invalid_json");
43
+ }
44
+ const value = new TextEncoder().encode(source.value);
45
+ return {
46
+ format: FIELD_FORMAT_BYTES.json,
47
+ formatLabel: "json (0x09)",
48
+ value,
49
+ valueHex: Buffer.from(value).toString("hex"),
50
+ };
51
+ }
52
+ if (source.kind === "bytes") {
53
+ let value;
54
+ if (source.value.startsWith("hex:")) {
55
+ const payload = source.value.slice(4);
56
+ if (!/^[0-9a-f]+$/.test(payload) || payload.length % 2 !== 0) {
57
+ throw new Error("wallet_field_invalid_bytes");
58
+ }
59
+ value = Buffer.from(payload, "hex");
60
+ }
61
+ else if (source.value.startsWith("@")) {
62
+ const filePath = source.value.slice(1);
63
+ if (filePath.trim() === "") {
64
+ throw new Error("wallet_field_invalid_bytes");
65
+ }
66
+ value = await readFile(resolvePath(process.cwd(), filePath));
67
+ }
68
+ else {
69
+ throw new Error("wallet_field_invalid_bytes");
70
+ }
71
+ if (value.length === 0) {
72
+ throw new Error("wallet_field_value_missing");
73
+ }
74
+ return {
75
+ format: FIELD_FORMAT_BYTES.bytes,
76
+ formatLabel: "bytes (0x01)",
77
+ value,
78
+ valueHex: value.toString("hex"),
79
+ };
80
+ }
81
+ const match = /^raw:(\d{1,3})$/.exec(source.format);
82
+ if (match == null) {
83
+ throw new Error("wallet_field_invalid_raw_format");
84
+ }
85
+ const format = Number.parseInt(match[1], 10);
86
+ if (!Number.isInteger(format) || format < 0 || format > 0xff || format === FIELD_FORMAT_BYTES.clear) {
87
+ throw new Error("wallet_field_invalid_raw_format");
88
+ }
89
+ let value;
90
+ if (source.value.startsWith("hex:")) {
91
+ const payload = source.value.slice(4);
92
+ if (!/^[0-9a-f]+$/.test(payload) || payload.length % 2 !== 0) {
93
+ throw new Error("wallet_field_invalid_value");
94
+ }
95
+ value = Buffer.from(payload, "hex");
96
+ }
97
+ else if (source.value.startsWith("@")) {
98
+ const filePath = source.value.slice(1);
99
+ if (filePath.trim() === "") {
100
+ throw new Error("wallet_field_invalid_value");
101
+ }
102
+ value = await readFile(resolvePath(process.cwd(), filePath));
103
+ }
104
+ else if (source.value.startsWith("utf8:")) {
105
+ value = new TextEncoder().encode(source.value.slice(5));
106
+ }
107
+ else {
108
+ throw new Error("wallet_field_invalid_value");
109
+ }
110
+ if (value.length === 0) {
111
+ throw new Error("wallet_field_value_missing");
112
+ }
113
+ return {
114
+ format,
115
+ formatLabel: describeRawFormat(format),
116
+ value,
117
+ valueHex: Buffer.from(value).toString("hex"),
118
+ };
119
+ }
120
+ export async function createSetFieldVariant(options) {
121
+ const value = await loadFieldValue(options.source);
122
+ return {
123
+ kind: "field-set",
124
+ errorPrefix: "wallet_field_set",
125
+ async createMutation({ operation, existing, feeSelection, nowUnixMs }) {
126
+ const normalizedDomainName = normalizeFieldDomainName(options.domainName);
127
+ const normalizedFieldName = normalizeFieldNameInput(options.fieldName);
128
+ const observedField = getObservedFieldState(operation.readContext, normalizedDomainName, normalizedFieldName);
129
+ if (observedField === null) {
130
+ throw new Error("wallet_field_set_field_not_found");
131
+ }
132
+ if (observedField.permanent && observedField.hasValue) {
133
+ throw new Error("wallet_field_set_permanent_field_frozen");
134
+ }
135
+ const senderBalance = getBalance(operation.readContext.snapshot.state, Buffer.from(operation.sender.scriptPubKeyHex, "hex"));
136
+ if (senderBalance < 1n) {
137
+ throw new Error("wallet_field_set_insufficient_cog");
138
+ }
139
+ const intentFingerprintHex = createFieldIntentFingerprint([
140
+ "field-set",
141
+ operation.state.walletRootId,
142
+ normalizedDomainName,
143
+ observedField.fieldId,
144
+ value.format,
145
+ value.valueHex,
146
+ ]);
147
+ return {
148
+ opReturnData: serializeDataUpdate(operation.chainDomain.domainId, observedField.fieldId, value.format, value.value).opReturnData,
149
+ mutation: createStandaloneFieldMutation({
150
+ kind: "field-set",
151
+ domainName: normalizedDomainName,
152
+ fieldName: normalizedFieldName,
153
+ sender: operation.sender,
154
+ intentFingerprintHex,
155
+ nowUnixMs,
156
+ feeSelection,
157
+ existing,
158
+ fieldId: observedField.fieldId,
159
+ fieldPermanent: observedField.permanent,
160
+ fieldFormat: value.format,
161
+ fieldValueHex: value.valueHex,
162
+ }),
163
+ };
164
+ },
165
+ async confirm(operation) {
166
+ const normalizedDomainName = normalizeFieldDomainName(options.domainName);
167
+ const normalizedFieldName = normalizeFieldNameInput(options.fieldName);
168
+ const observedField = getObservedFieldState(operation.readContext, normalizedDomainName, normalizedFieldName);
169
+ if (observedField === null) {
170
+ throw new Error("wallet_field_set_field_not_found");
171
+ }
172
+ const fieldRef = `${normalizedDomainName}:${normalizedFieldName}`;
173
+ options.prompter.writeLine(`Updating field "${fieldRef}".`);
174
+ options.prompter.writeLine(`Resolved sender: ${operation.senderSelector} (${operation.sender.address})`);
175
+ options.prompter.writeLine("Path: standalone-data-update");
176
+ options.prompter.writeLine(`Effect: ${describeFieldEffect({ kind: "write-field-value", burnCogtoshi: "1" })}.`);
177
+ options.prompter.writeLine(`Format: ${value.formatLabel}`);
178
+ options.prompter.writeLine(`Value bytes: ${value.value.length}`);
179
+ options.prompter.writeLine("Warning: the field value is public in the mempool and on-chain.");
180
+ if (observedField.permanent && !observedField.hasValue) {
181
+ options.prompter.writeLine("This is the first non-clear value write to a permanent field.");
182
+ await confirmTyped(options.prompter, fieldRef, `Type ${fieldRef} to continue: `, "wallet_field_set_confirmation_rejected", {
183
+ assumeYes: options.assumeYes,
184
+ requiresTtyErrorCode: "wallet_field_set_requires_tty",
185
+ typedAckRequiredErrorCode: "wallet_field_set_typed_ack_required",
186
+ });
187
+ return;
188
+ }
189
+ await confirmYesNo(options.prompter, "This publishes a standalone DATA_UPDATE.", "wallet_field_set_confirmation_rejected", {
190
+ assumeYes: options.assumeYes,
191
+ requiresTtyErrorCode: "wallet_field_set_requires_tty",
192
+ });
193
+ },
194
+ };
195
+ }
@@ -1,95 +1 @@
1
- import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
2
- import { createRpcClient } from "../../bitcoind/node.js";
3
- import type { RpcTransaction } from "../../bitcoind/types.js";
4
- import type { WalletPrompter } from "../lifecycle.js";
5
- import { type WalletRuntimePaths } from "../runtime.js";
6
- import { type WalletSecretProvider } from "../state/provider.js";
7
- import { openWalletReadContext } from "../read/index.js";
8
- import { type WalletMutationFeeSummary, type WalletMutationRpcClient } from "./common.js";
9
- type FieldMutationKind = "field-create" | "field-set" | "field-clear";
10
- export type FieldValueInputSource = {
11
- kind: "text";
12
- value: string;
13
- } | {
14
- kind: "json";
15
- value: string;
16
- } | {
17
- kind: "bytes";
18
- value: string;
19
- } | {
20
- kind: "raw";
21
- format: string;
22
- value: string;
23
- };
24
- interface FieldRpcClient extends WalletMutationRpcClient {
25
- getBlockchainInfo(): Promise<{
26
- blocks: number;
27
- }>;
28
- sendRawTransaction(hex: string): Promise<string>;
29
- getRawTransaction(txid: string, verbose?: boolean): Promise<RpcTransaction>;
30
- }
31
- export interface CreateFieldOptions {
32
- domainName: string;
33
- fieldName: string;
34
- permanent?: boolean;
35
- feeRateSatVb?: number | null;
36
- dataDir: string;
37
- databasePath: string;
38
- provider?: WalletSecretProvider;
39
- prompter: WalletPrompter;
40
- assumeYes?: boolean;
41
- nowUnixMs?: number;
42
- paths?: WalletRuntimePaths;
43
- openReadContext?: typeof openWalletReadContext;
44
- attachService?: typeof attachOrStartManagedBitcoindService;
45
- rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => FieldRpcClient;
46
- }
47
- export interface SetFieldOptions extends Omit<CreateFieldOptions, "permanent"> {
48
- source: FieldValueInputSource;
49
- }
50
- export interface ClearFieldOptions extends Omit<CreateFieldOptions, "permanent" | "source"> {
51
- }
52
- export interface FieldMutationResult {
53
- kind: FieldMutationKind;
54
- domainName: string;
55
- fieldName: string;
56
- fieldId: number | null;
57
- txid: string;
58
- permanent: boolean | null;
59
- format: number | null;
60
- status: "live" | "confirmed";
61
- reusedExisting: boolean;
62
- resolved?: FieldResolvedSummary | null;
63
- fees: WalletMutationFeeSummary;
64
- }
65
- export interface FieldResolvedSenderSummary {
66
- selector: string;
67
- localIndex: number;
68
- scriptPubKeyHex: string;
69
- address: string;
70
- }
71
- export type FieldResolvedPath = "standalone-field-reg" | "standalone-data-update" | "standalone-data-clear";
72
- export interface FieldResolvedValueSummary {
73
- format: number;
74
- byteLength: number;
75
- }
76
- export type FieldResolvedEffect = {
77
- kind: "create-empty-field";
78
- burnCogtoshi: "100";
79
- } | {
80
- kind: "write-field-value";
81
- burnCogtoshi: "1";
82
- } | {
83
- kind: "clear-field-value";
84
- burnCogtoshi: "0";
85
- };
86
- export interface FieldResolvedSummary {
87
- sender: FieldResolvedSenderSummary;
88
- path: FieldResolvedPath;
89
- value: FieldResolvedValueSummary | null;
90
- effect: FieldResolvedEffect;
91
- }
92
- export declare function createField(options: CreateFieldOptions): Promise<FieldMutationResult>;
93
- export declare function setField(options: SetFieldOptions): Promise<FieldMutationResult>;
94
- export declare function clearField(options: ClearFieldOptions): Promise<FieldMutationResult>;
95
- export {};
1
+ export * from "./field/index.js";