@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,92 @@
1
+ import { confirmClaim } from "../confirm.js";
2
+ import { createClaimCogOpReturnData, createCogIntentFingerprint, resolveClaimSender, ZERO_PREIMAGE_HEX, } from "../intent.js";
3
+ import { createCogDraftMutation } from "../draft.js";
4
+ import { createCogResult, createCogReuseResult, } from "../result.js";
5
+ function createClaimLikeVariant(options, reclaim) {
6
+ const preimageHex = reclaim ? ZERO_PREIMAGE_HEX : options.preimageHex;
7
+ const errorPrefix = reclaim ? "wallet_reclaim" : "wallet_claim";
8
+ return {
9
+ controlLockPurpose: reclaim ? "wallet-reclaim" : "wallet-claim",
10
+ preemptionReason: reclaim ? "wallet-reclaim" : "wallet-claim",
11
+ errorPrefix,
12
+ repairRequiredErrorCode: `${errorPrefix}_repair_required`,
13
+ resolveOperation(readContext) {
14
+ return {
15
+ ...resolveClaimSender(readContext, options.lockId, preimageHex, reclaim),
16
+ preimageHex,
17
+ errorPrefix,
18
+ };
19
+ },
20
+ createIntentFingerprint(operation) {
21
+ return createCogIntentFingerprint([
22
+ reclaim ? "reclaim" : "claim",
23
+ operation.state.walletRootId,
24
+ operation.sender.scriptPubKeyHex,
25
+ operation.lockId,
26
+ operation.preimageHex,
27
+ ]);
28
+ },
29
+ confirm(operation) {
30
+ return confirmClaim(options.prompter, {
31
+ kind: reclaim ? "reclaim" : "claim",
32
+ lockId: operation.lockId,
33
+ recipientDomainName: operation.recipientDomainName,
34
+ amountCogtoshi: operation.amountCogtoshi,
35
+ resolved: operation.resolved,
36
+ assumeYes: options.assumeYes,
37
+ });
38
+ },
39
+ createDraftMutation({ operation, existingMutation, feeSelection, intentFingerprintHex, nowUnixMs }) {
40
+ return createCogDraftMutation({
41
+ kind: "claim",
42
+ sender: operation.sender,
43
+ amountCogtoshi: operation.amountCogtoshi,
44
+ recipientDomainName: operation.recipientDomainName,
45
+ lockId: operation.lockId,
46
+ preimageHex: operation.preimageHex,
47
+ intentFingerprintHex,
48
+ nowUnixMs,
49
+ feeSelection,
50
+ existing: existingMutation,
51
+ });
52
+ },
53
+ createOpReturnData(operation) {
54
+ return createClaimCogOpReturnData(operation);
55
+ },
56
+ createReuseResult({ operation, mutation, resolution, fees }) {
57
+ return createCogReuseResult({
58
+ kind: "claim",
59
+ mutation,
60
+ resolution,
61
+ fees,
62
+ amountCogtoshi: operation.amountCogtoshi,
63
+ recipientDomainName: operation.recipientDomainName,
64
+ lockId: operation.lockId,
65
+ resolved: operation.resolved,
66
+ });
67
+ },
68
+ createResult({ operation, mutation, builtTxid, status, reusedExisting, fees }) {
69
+ return createCogResult({
70
+ kind: "claim",
71
+ mutation,
72
+ builtTxid,
73
+ status,
74
+ reusedExisting,
75
+ fees,
76
+ amountCogtoshi: operation.amountCogtoshi,
77
+ recipientDomainName: operation.recipientDomainName,
78
+ lockId: operation.lockId,
79
+ resolved: operation.resolved,
80
+ });
81
+ },
82
+ };
83
+ }
84
+ export function createClaimCogVariant(options) {
85
+ return createClaimLikeVariant(options, false);
86
+ }
87
+ export function createReclaimCogVariant(options) {
88
+ return createClaimLikeVariant({
89
+ ...options,
90
+ preimageHex: ZERO_PREIMAGE_HEX,
91
+ }, true);
92
+ }
@@ -0,0 +1,2 @@
1
+ import type { CogMutationVariant, LockCogMutationOperation, LockCogToDomainOptions } from "../types.js";
2
+ export declare function createLockCogVariant(options: LockCogToDomainOptions): CogMutationVariant<LockCogMutationOperation>;
@@ -0,0 +1,102 @@
1
+ import { lookupDomain } from "@cogcoin/indexer/queries";
2
+ import { confirmLock } from "../confirm.js";
3
+ import { createCogIntentFingerprint, createLockCogOpReturnData, MAX_LOCK_DURATION_BLOCKS, normalizeCogDomainName, normalizePositiveCogAmount, parseHex32, parseTimeoutHeight, resolveIdentitySender, } from "../intent.js";
4
+ import { createCogDraftMutation } from "../draft.js";
5
+ import { createCogResult, createCogReuseResult, } from "../result.js";
6
+ export function createLockCogVariant(options) {
7
+ const amountCogtoshi = normalizePositiveCogAmount(options.amountCogtoshi, "wallet_lock_invalid_amount");
8
+ const normalizedRecipientDomainName = normalizeCogDomainName(options.recipientDomainName);
9
+ const condition = parseHex32(options.conditionHex, "wallet_lock_invalid_condition");
10
+ if (condition.equals(Buffer.alloc(32))) {
11
+ throw new Error("wallet_lock_invalid_condition");
12
+ }
13
+ return {
14
+ controlLockPurpose: "wallet-lock-cog",
15
+ preemptionReason: "wallet-cog-lock",
16
+ errorPrefix: "wallet_lock",
17
+ repairRequiredErrorCode: "wallet_lock_repair_required",
18
+ resolveOperation(readContext) {
19
+ const currentHeight = readContext.snapshot?.state.history.currentHeight ?? null;
20
+ if (currentHeight === null) {
21
+ throw new Error("wallet_lock_current_height_unavailable");
22
+ }
23
+ const timeoutHeight = parseTimeoutHeight(currentHeight, options.timeoutBlocksOrDuration, options.timeoutHeight ?? null);
24
+ if (timeoutHeight <= currentHeight || timeoutHeight > currentHeight + MAX_LOCK_DURATION_BLOCKS) {
25
+ throw new Error("wallet_lock_invalid_timeout_height");
26
+ }
27
+ const recipientDomain = lookupDomain(readContext.snapshot.state, normalizedRecipientDomainName);
28
+ if (recipientDomain === null) {
29
+ throw new Error("wallet_lock_domain_not_found");
30
+ }
31
+ if (!recipientDomain.anchored) {
32
+ throw new Error("wallet_lock_domain_not_anchored");
33
+ }
34
+ if (readContext.snapshot.state.consensus.nextLockId === 0xffff_ffff) {
35
+ throw new Error("wallet_lock_id_space_exhausted");
36
+ }
37
+ return {
38
+ ...resolveIdentitySender(readContext, "wallet_lock", amountCogtoshi, options.fromIdentity),
39
+ amountCogtoshi,
40
+ normalizedRecipientDomainName,
41
+ recipientDomain,
42
+ timeoutHeight,
43
+ conditionHex: Buffer.from(condition).toString("hex"),
44
+ };
45
+ },
46
+ createIntentFingerprint(operation) {
47
+ return createCogIntentFingerprint([
48
+ "lock",
49
+ operation.state.walletRootId,
50
+ operation.sender.scriptPubKeyHex,
51
+ operation.normalizedRecipientDomainName,
52
+ operation.amountCogtoshi,
53
+ operation.timeoutHeight,
54
+ operation.conditionHex,
55
+ ]);
56
+ },
57
+ confirm(operation) {
58
+ return confirmLock(options.prompter, operation.resolved, operation.amountCogtoshi, operation.normalizedRecipientDomainName, operation.timeoutHeight, options.assumeYes);
59
+ },
60
+ createDraftMutation({ operation, existingMutation, feeSelection, intentFingerprintHex, nowUnixMs }) {
61
+ return createCogDraftMutation({
62
+ kind: "lock",
63
+ sender: operation.sender,
64
+ amountCogtoshi: operation.amountCogtoshi,
65
+ recipientDomainName: operation.normalizedRecipientDomainName,
66
+ timeoutHeight: operation.timeoutHeight,
67
+ conditionHex: operation.conditionHex,
68
+ intentFingerprintHex,
69
+ nowUnixMs,
70
+ feeSelection,
71
+ existing: existingMutation,
72
+ });
73
+ },
74
+ createOpReturnData(operation) {
75
+ return createLockCogOpReturnData(operation);
76
+ },
77
+ createReuseResult({ operation, mutation, resolution, fees }) {
78
+ return createCogReuseResult({
79
+ kind: "lock",
80
+ mutation,
81
+ resolution,
82
+ fees,
83
+ amountCogtoshi: operation.amountCogtoshi,
84
+ recipientDomainName: operation.normalizedRecipientDomainName,
85
+ resolved: operation.resolved,
86
+ });
87
+ },
88
+ createResult({ operation, mutation, builtTxid, status, reusedExisting, fees }) {
89
+ return createCogResult({
90
+ kind: "lock",
91
+ mutation,
92
+ builtTxid,
93
+ status,
94
+ reusedExisting,
95
+ fees,
96
+ amountCogtoshi: operation.amountCogtoshi,
97
+ recipientDomainName: operation.normalizedRecipientDomainName,
98
+ resolved: operation.resolved,
99
+ });
100
+ },
101
+ };
102
+ }
@@ -0,0 +1,2 @@
1
+ import type { CogMutationVariant, SendCogOperation, SendCogOptions } from "../types.js";
2
+ export declare function createSendCogVariant(options: SendCogOptions): CogMutationVariant<SendCogOperation>;
@@ -0,0 +1,77 @@
1
+ import { normalizeBtcTarget } from "../../targets.js";
2
+ import { confirmSend } from "../confirm.js";
3
+ import { createCogIntentFingerprint, createSendCogOpReturnData, normalizePositiveCogAmount, resolveIdentitySender, } from "../intent.js";
4
+ import { createCogDraftMutation } from "../draft.js";
5
+ import { createCogResult, createCogReuseResult, } from "../result.js";
6
+ export function createSendCogVariant(options) {
7
+ const amountCogtoshi = normalizePositiveCogAmount(options.amountCogtoshi, "wallet_send_invalid_amount");
8
+ const recipient = normalizeBtcTarget(options.target);
9
+ return {
10
+ controlLockPurpose: "wallet-send",
11
+ preemptionReason: "wallet-send",
12
+ errorPrefix: "wallet_send",
13
+ repairRequiredErrorCode: "wallet_send_repair_required",
14
+ resolveOperation(readContext) {
15
+ const operation = resolveIdentitySender(readContext, "wallet_send", amountCogtoshi, options.fromIdentity);
16
+ if (operation.sender.scriptPubKeyHex === recipient.scriptPubKeyHex) {
17
+ throw new Error("wallet_send_self_transfer");
18
+ }
19
+ return {
20
+ ...operation,
21
+ amountCogtoshi,
22
+ recipient,
23
+ };
24
+ },
25
+ createIntentFingerprint(operation) {
26
+ return createCogIntentFingerprint([
27
+ "send",
28
+ operation.state.walletRootId,
29
+ operation.sender.scriptPubKeyHex,
30
+ operation.recipient.scriptPubKeyHex,
31
+ operation.amountCogtoshi,
32
+ ]);
33
+ },
34
+ confirm(operation) {
35
+ return confirmSend(options.prompter, operation.resolved, options.target, operation.recipient, operation.amountCogtoshi, options.assumeYes);
36
+ },
37
+ createDraftMutation({ operation, existingMutation, feeSelection, intentFingerprintHex, nowUnixMs }) {
38
+ return createCogDraftMutation({
39
+ kind: "send",
40
+ sender: operation.sender,
41
+ recipientScriptPubKeyHex: operation.recipient.scriptPubKeyHex,
42
+ amountCogtoshi: operation.amountCogtoshi,
43
+ intentFingerprintHex,
44
+ nowUnixMs,
45
+ feeSelection,
46
+ existing: existingMutation,
47
+ });
48
+ },
49
+ createOpReturnData(operation) {
50
+ return createSendCogOpReturnData(operation);
51
+ },
52
+ createReuseResult({ operation, mutation, resolution, fees }) {
53
+ return createCogReuseResult({
54
+ kind: "send",
55
+ mutation,
56
+ resolution,
57
+ fees,
58
+ amountCogtoshi: operation.amountCogtoshi,
59
+ recipientScriptPubKeyHex: operation.recipient.scriptPubKeyHex,
60
+ resolved: operation.resolved,
61
+ });
62
+ },
63
+ createResult({ operation, mutation, builtTxid, status, reusedExisting, fees }) {
64
+ return createCogResult({
65
+ kind: "send",
66
+ mutation,
67
+ builtTxid,
68
+ status,
69
+ reusedExisting,
70
+ fees,
71
+ amountCogtoshi: operation.amountCogtoshi,
72
+ recipientScriptPubKeyHex: operation.recipient.scriptPubKeyHex,
73
+ resolved: operation.resolved,
74
+ });
75
+ },
76
+ };
77
+ }
@@ -1,96 +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 CogMutationKind = "send" | "lock" | "claim";
10
- interface WalletCogRpcClient extends WalletMutationRpcClient {
11
- getBlockchainInfo(): Promise<{
12
- blocks: number;
13
- }>;
14
- sendRawTransaction(hex: string): Promise<string>;
15
- getRawTransaction(txid: string, verbose?: boolean): Promise<RpcTransaction>;
16
- }
17
- export type CogResolvedClaimPath = "recipient-claim" | "timeout-reclaim";
18
- export interface CogResolvedSenderSummary {
19
- selector: string;
20
- localIndex: number;
21
- scriptPubKeyHex: string;
22
- address: string;
23
- }
24
- export interface CogResolvedSummary {
25
- sender: CogResolvedSenderSummary;
26
- claimPath: CogResolvedClaimPath | null;
27
- }
28
- export interface CogMutationResult {
29
- kind: CogMutationKind;
30
- txid: string;
31
- status: "live" | "confirmed";
32
- reusedExisting: boolean;
33
- amountCogtoshi?: bigint;
34
- recipientScriptPubKeyHex?: string | null;
35
- recipientDomainName?: string | null;
36
- lockId?: number | null;
37
- resolved: CogResolvedSummary;
38
- fees: WalletMutationFeeSummary;
39
- }
40
- export interface SendCogOptions {
41
- amountCogtoshi: bigint;
42
- target: string;
43
- fromIdentity?: string | null;
44
- feeRateSatVb?: number | null;
45
- dataDir: string;
46
- databasePath: string;
47
- provider?: WalletSecretProvider;
48
- prompter: WalletPrompter;
49
- assumeYes?: boolean;
50
- nowUnixMs?: number;
51
- paths?: WalletRuntimePaths;
52
- openReadContext?: typeof openWalletReadContext;
53
- attachService?: typeof attachOrStartManagedBitcoindService;
54
- rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => WalletCogRpcClient;
55
- }
56
- export interface LockCogToDomainOptions {
57
- amountCogtoshi: bigint;
58
- recipientDomainName: string;
59
- fromIdentity?: string | null;
60
- feeRateSatVb?: number | null;
61
- timeoutHeight?: number | null;
62
- timeoutBlocksOrDuration?: string | null;
63
- conditionHex: string;
64
- dataDir: string;
65
- databasePath: string;
66
- provider?: WalletSecretProvider;
67
- prompter: WalletPrompter;
68
- assumeYes?: boolean;
69
- nowUnixMs?: number;
70
- paths?: WalletRuntimePaths;
71
- openReadContext?: typeof openWalletReadContext;
72
- attachService?: typeof attachOrStartManagedBitcoindService;
73
- rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => WalletCogRpcClient;
74
- }
75
- export interface ClaimCogLockOptions {
76
- lockId: number;
77
- preimageHex: string;
78
- feeRateSatVb?: number | null;
79
- dataDir: string;
80
- databasePath: string;
81
- provider?: WalletSecretProvider;
82
- prompter: WalletPrompter;
83
- assumeYes?: boolean;
84
- nowUnixMs?: number;
85
- paths?: WalletRuntimePaths;
86
- openReadContext?: typeof openWalletReadContext;
87
- attachService?: typeof attachOrStartManagedBitcoindService;
88
- rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => WalletCogRpcClient;
89
- }
90
- export interface ReclaimCogLockOptions extends Omit<ClaimCogLockOptions, "preimageHex"> {
91
- }
92
- export declare function sendCog(options: SendCogOptions): Promise<CogMutationResult>;
93
- export declare function lockCogToDomain(options: LockCogToDomainOptions): Promise<CogMutationResult>;
94
- export declare function claimCogLock(options: ClaimCogLockOptions): Promise<CogMutationResult>;
95
- export declare function reclaimCogLock(options: ReclaimCogLockOptions): Promise<CogMutationResult>;
96
- export {};
1
+ export * from "./cog/index.js";