@cogcoin/client 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bitcoind/managed-bitcoind-service-config.d.ts +13 -0
- package/dist/bitcoind/managed-bitcoind-service-config.js +165 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.d.ts +28 -0
- package/dist/bitcoind/managed-bitcoind-service-lifecycle.js +290 -0
- package/dist/bitcoind/managed-bitcoind-service-process.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-process.js +48 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.d.ts +8 -0
- package/dist/bitcoind/managed-bitcoind-service-replica.js +142 -0
- package/dist/bitcoind/managed-bitcoind-service-status.d.ts +42 -0
- package/dist/bitcoind/managed-bitcoind-service-status.js +178 -0
- package/dist/bitcoind/managed-bitcoind-service-types.d.ts +36 -0
- package/dist/bitcoind/managed-bitcoind-service-types.js +1 -0
- package/dist/bitcoind/service.d.ts +7 -63
- package/dist/bitcoind/service.js +7 -797
- package/dist/cli/commands/mining-read.js +1 -1
- package/dist/cli/commands/wallet-mutation/anchor.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/anchor.js +33 -0
- package/dist/cli/commands/wallet-mutation/bitcoin-transfer.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/bitcoin-transfer.js +32 -0
- package/dist/cli/commands/wallet-mutation/cog.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/cog.js +131 -0
- package/dist/cli/commands/wallet-mutation/context.d.ts +3 -0
- package/dist/cli/commands/wallet-mutation/context.js +18 -0
- package/dist/cli/commands/wallet-mutation/domain-admin.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/domain-admin.js +173 -0
- package/dist/cli/commands/wallet-mutation/domain-market.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/domain-market.js +107 -0
- package/dist/cli/commands/wallet-mutation/field.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/field.js +125 -0
- package/dist/cli/commands/wallet-mutation/register.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/register.js +38 -0
- package/dist/cli/commands/wallet-mutation/registry.d.ts +3 -0
- package/dist/cli/commands/wallet-mutation/registry.js +39 -0
- package/dist/cli/commands/wallet-mutation/reputation.d.ts +2 -0
- package/dist/cli/commands/wallet-mutation/reputation.js +57 -0
- package/dist/cli/commands/wallet-mutation/types.d.ts +32 -0
- package/dist/cli/commands/wallet-mutation/types.js +1 -0
- package/dist/cli/commands/wallet-mutation.js +13 -765
- package/dist/cli/commands/wallet-read.js +4 -4
- package/dist/cli/mutation-success.d.ts +0 -2
- package/dist/cli/output/classify.d.ts +7 -0
- package/dist/cli/output/classify.js +94 -0
- package/dist/cli/output/render.d.ts +2 -0
- package/dist/cli/output/render.js +13 -0
- package/dist/cli/output/rules/cli-surface.d.ts +2 -0
- package/dist/cli/output/rules/cli-surface.js +110 -0
- package/dist/cli/output/rules/generic.d.ts +2 -0
- package/dist/cli/output/rules/generic.js +13 -0
- package/dist/cli/output/rules/index.d.ts +2 -0
- package/dist/cli/output/rules/index.js +24 -0
- package/dist/cli/output/rules/mining-update.d.ts +2 -0
- package/dist/cli/output/rules/mining-update.js +68 -0
- package/dist/cli/output/rules/services.d.ts +2 -0
- package/dist/cli/output/rules/services.js +110 -0
- package/dist/cli/output/rules/wallet-admin.d.ts +2 -0
- package/dist/cli/output/rules/wallet-admin.js +224 -0
- package/dist/cli/output/rules/wallet-mutations.d.ts +2 -0
- package/dist/cli/output/rules/wallet-mutations.js +274 -0
- package/dist/cli/output/types.d.ts +16 -0
- package/dist/cli/output/types.js +1 -0
- package/dist/cli/output.d.ts +2 -168
- package/dist/cli/output.js +6 -989
- package/dist/cli/pagination.d.ts +15 -0
- package/dist/cli/pagination.js +16 -0
- package/dist/cli/recommendations.d.ts +4 -0
- package/dist/cli/recommendations.js +108 -0
- package/dist/cli/wallet-format/availability.d.ts +5 -0
- package/dist/cli/wallet-format/availability.js +96 -0
- package/dist/cli/wallet-format/balance.d.ts +2 -0
- package/dist/cli/wallet-format/balance.js +162 -0
- package/dist/cli/wallet-format/domains.d.ts +8 -0
- package/dist/cli/wallet-format/domains.js +84 -0
- package/dist/cli/wallet-format/fields.d.ts +6 -0
- package/dist/cli/wallet-format/fields.js +61 -0
- package/dist/cli/wallet-format/identity.d.ts +5 -0
- package/dist/cli/wallet-format/identity.js +19 -0
- package/dist/cli/wallet-format/locks.d.ts +7 -0
- package/dist/cli/wallet-format/locks.js +52 -0
- package/dist/cli/wallet-format/overview.d.ts +2 -0
- package/dist/cli/wallet-format/overview.js +122 -0
- package/dist/cli/wallet-format/pending.d.ts +13 -0
- package/dist/cli/wallet-format/pending.js +101 -0
- package/dist/cli/wallet-format/shared.d.ts +7 -0
- package/dist/cli/wallet-format/shared.js +31 -0
- package/dist/cli/wallet-format/status.d.ts +3 -0
- package/dist/cli/wallet-format/status.js +27 -0
- package/dist/cli/wallet-format.d.ts +8 -30
- package/dist/cli/wallet-format.js +8 -830
- package/dist/cli/wallet-read-helpers.d.ts +6 -0
- package/dist/cli/wallet-read-helpers.js +17 -0
- package/dist/wallet/mining/candidate.d.ts +1 -1
- package/dist/wallet/mining/candidate.js +3 -3
- package/dist/wallet/mining/constants.d.ts +2 -2
- package/dist/wallet/mining/constants.js +2 -2
- package/dist/wallet/mining/engine-types.d.ts +1 -0
- package/dist/wallet/mining/engine-types.js +9 -1
- package/dist/wallet/mining/publish.js +3 -6
- package/dist/wallet/mining/runner.js +30 -18
- package/dist/wallet/mining/sentence-protocol.d.ts +2 -2
- package/dist/wallet/mining/sentences.js +8 -8
- package/dist/wallet/mining/visualizer.js +7 -6
- package/dist/wallet/read/context.d.ts +4 -10
- package/dist/wallet/read/context.js +4 -227
- package/dist/wallet/read/local-state.d.ts +28 -0
- package/dist/wallet/read/local-state.js +233 -0
- package/dist/wallet/read/managed-bitcoind.d.ts +30 -0
- package/dist/wallet/read/managed-bitcoind.js +138 -0
- package/dist/wallet/read/managed-indexer.d.ts +23 -0
- package/dist/wallet/read/managed-indexer.js +87 -0
- package/dist/wallet/read/managed-services.d.ts +6 -21
- package/dist/wallet/read/managed-services.js +23 -196
- package/dist/wallet/tx/anchor/confirm.d.ts +15 -0
- package/dist/wallet/tx/anchor/confirm.js +60 -0
- package/dist/wallet/tx/anchor/draft.d.ts +39 -0
- package/dist/wallet/tx/anchor/draft.js +167 -0
- package/dist/wallet/tx/anchor/index.d.ts +5 -0
- package/dist/wallet/tx/anchor/index.js +148 -0
- package/dist/wallet/tx/anchor/intent.d.ts +61 -0
- package/dist/wallet/tx/anchor/intent.js +101 -0
- package/dist/wallet/tx/anchor/plan.d.ts +3 -0
- package/dist/wallet/tx/anchor/plan.js +18 -0
- package/dist/wallet/tx/anchor/result.d.ts +25 -0
- package/dist/wallet/tx/anchor/result.js +20 -0
- package/dist/wallet/tx/anchor.d.ts +1 -39
- package/dist/wallet/tx/anchor.js +1 -494
- package/dist/wallet/tx/bitcoin-transfer/confirm.d.ts +7 -0
- package/dist/wallet/tx/bitcoin-transfer/confirm.js +11 -0
- package/dist/wallet/tx/bitcoin-transfer/index.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/index.js +112 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.d.ts +52 -0
- package/dist/wallet/tx/bitcoin-transfer/intent.js +74 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.d.ts +5 -0
- package/dist/wallet/tx/bitcoin-transfer/plan.js +21 -0
- package/dist/wallet/tx/bitcoin-transfer/result.d.ts +19 -0
- package/dist/wallet/tx/bitcoin-transfer/result.js +16 -0
- package/dist/wallet/tx/bitcoin-transfer.d.ts +1 -35
- package/dist/wallet/tx/bitcoin-transfer.js +1 -200
- package/dist/wallet/tx/cog/confirm.d.ts +13 -0
- package/dist/wallet/tx/cog/confirm.js +59 -0
- package/dist/wallet/tx/cog/draft.d.ts +20 -0
- package/dist/wallet/tx/cog/draft.js +114 -0
- package/dist/wallet/tx/cog/index.d.ts +6 -0
- package/dist/wallet/tx/cog/index.js +117 -0
- package/dist/wallet/tx/cog/intent.d.ts +30 -0
- package/dist/wallet/tx/cog/intent.js +169 -0
- package/dist/wallet/tx/cog/plan.d.ts +19 -0
- package/dist/wallet/tx/cog/plan.js +65 -0
- package/dist/wallet/tx/cog/result.d.ts +27 -0
- package/dist/wallet/tx/cog/result.js +28 -0
- package/dist/wallet/tx/cog/types.d.ts +186 -0
- package/dist/wallet/tx/cog/types.js +2 -0
- package/dist/wallet/tx/cog/variants/claim.d.ts +3 -0
- package/dist/wallet/tx/cog/variants/claim.js +92 -0
- package/dist/wallet/tx/cog/variants/lock.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/lock.js +102 -0
- package/dist/wallet/tx/cog/variants/send.d.ts +2 -0
- package/dist/wallet/tx/cog/variants/send.js +77 -0
- package/dist/wallet/tx/cog.d.ts +1 -96
- package/dist/wallet/tx/cog.js +1 -824
- package/dist/wallet/tx/common.d.ts +14 -199
- package/dist/wallet/tx/common.js +10 -493
- package/dist/wallet/tx/domain-admin/confirm.d.ts +17 -0
- package/dist/wallet/tx/domain-admin/confirm.js +58 -0
- package/dist/wallet/tx/domain-admin/draft.d.ts +20 -0
- package/dist/wallet/tx/domain-admin/draft.js +161 -0
- package/dist/wallet/tx/domain-admin/index.d.ts +9 -0
- package/dist/wallet/tx/domain-admin/index.js +150 -0
- package/dist/wallet/tx/domain-admin/intent.d.ts +12 -0
- package/dist/wallet/tx/domain-admin/intent.js +61 -0
- package/dist/wallet/tx/domain-admin/plan.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/plan.js +64 -0
- package/dist/wallet/tx/domain-admin/result.d.ts +19 -0
- package/dist/wallet/tx/domain-admin/result.js +33 -0
- package/dist/wallet/tx/domain-admin/types.d.ts +162 -0
- package/dist/wallet/tx/domain-admin/types.js +1 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.d.ts +2 -0
- package/dist/wallet/tx/domain-admin/variants/canonical.js +22 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/delegate.js +60 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/endpoint.js +102 -0
- package/dist/wallet/tx/domain-admin/variants/miner.d.ts +3 -0
- package/dist/wallet/tx/domain-admin/variants/miner.js +59 -0
- package/dist/wallet/tx/domain-admin.d.ts +1 -107
- package/dist/wallet/tx/domain-admin.js +1 -729
- package/dist/wallet/tx/domain-market/confirm.d.ts +6 -0
- package/dist/wallet/tx/domain-market/confirm.js +52 -0
- package/dist/wallet/tx/domain-market/draft.d.ts +43 -0
- package/dist/wallet/tx/domain-market/draft.js +286 -0
- package/dist/wallet/tx/domain-market/index.d.ts +6 -0
- package/dist/wallet/tx/domain-market/index.js +145 -0
- package/dist/wallet/tx/domain-market/intent.d.ts +15 -0
- package/dist/wallet/tx/domain-market/intent.js +131 -0
- package/dist/wallet/tx/domain-market/plan.d.ts +31 -0
- package/dist/wallet/tx/domain-market/plan.js +98 -0
- package/dist/wallet/tx/domain-market/result.d.ts +45 -0
- package/dist/wallet/tx/domain-market/result.js +88 -0
- package/dist/wallet/tx/domain-market/types.d.ts +221 -0
- package/dist/wallet/tx/domain-market/types.js +1 -0
- package/dist/wallet/tx/domain-market/variants/buy.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/buy.js +103 -0
- package/dist/wallet/tx/domain-market/variants/sell.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/sell.js +91 -0
- package/dist/wallet/tx/domain-market/variants/transfer.d.ts +2 -0
- package/dist/wallet/tx/domain-market/variants/transfer.js +105 -0
- package/dist/wallet/tx/domain-market.d.ts +1 -116
- package/dist/wallet/tx/domain-market.js +1 -1078
- package/dist/wallet/tx/draft-build.d.ts +60 -0
- package/dist/wallet/tx/draft-build.js +127 -0
- package/dist/wallet/tx/executor.d.ts +6 -40
- package/dist/wallet/tx/executor.js +6 -100
- package/dist/wallet/tx/fee.d.ts +30 -0
- package/dist/wallet/tx/fee.js +98 -0
- package/dist/wallet/tx/field/confirm.d.ts +11 -0
- package/dist/wallet/tx/field/confirm.js +19 -0
- package/dist/wallet/tx/field/draft.d.ts +23 -0
- package/dist/wallet/tx/field/draft.js +202 -0
- package/dist/wallet/tx/field/index.d.ts +5 -0
- package/dist/wallet/tx/field/index.js +140 -0
- package/dist/wallet/tx/field/intent.d.ts +5 -0
- package/dist/wallet/tx/field/intent.js +50 -0
- package/dist/wallet/tx/field/plan.d.ts +20 -0
- package/dist/wallet/tx/field/plan.js +65 -0
- package/dist/wallet/tx/field/result.d.ts +29 -0
- package/dist/wallet/tx/field/result.js +103 -0
- package/dist/wallet/tx/field/types.d.ts +163 -0
- package/dist/wallet/tx/field/types.js +1 -0
- package/dist/wallet/tx/field/variants/clear.d.ts +2 -0
- package/dist/wallet/tx/field/variants/clear.js +60 -0
- package/dist/wallet/tx/field/variants/create.d.ts +2 -0
- package/dist/wallet/tx/field/variants/create.js +67 -0
- package/dist/wallet/tx/field/variants/set.d.ts +2 -0
- package/dist/wallet/tx/field/variants/set.js +195 -0
- package/dist/wallet/tx/field.d.ts +1 -95
- package/dist/wallet/tx/field.js +1 -920
- package/dist/wallet/tx/mining-preemption.d.ts +6 -0
- package/dist/wallet/tx/mining-preemption.js +7 -0
- package/dist/wallet/tx/primitives.d.ts +13 -0
- package/dist/wallet/tx/primitives.js +42 -0
- package/dist/wallet/tx/psbt-assert.d.ts +14 -0
- package/dist/wallet/tx/psbt-assert.js +39 -0
- package/dist/wallet/tx/publish.d.ts +37 -0
- package/dist/wallet/tx/publish.js +88 -0
- package/dist/wallet/tx/readiness.d.ts +7 -0
- package/dist/wallet/tx/readiness.js +61 -0
- package/dist/wallet/tx/reconcile.d.ts +24 -0
- package/dist/wallet/tx/reconcile.js +72 -0
- package/dist/wallet/tx/register/confirm.d.ts +6 -0
- package/dist/wallet/tx/register/confirm.js +66 -0
- package/dist/wallet/tx/register/draft.d.ts +42 -0
- package/dist/wallet/tx/register/draft.js +181 -0
- package/dist/wallet/tx/register/index.d.ts +6 -0
- package/dist/wallet/tx/register/index.js +158 -0
- package/dist/wallet/tx/register/intent.d.ts +74 -0
- package/dist/wallet/tx/register/intent.js +119 -0
- package/dist/wallet/tx/register/plan.d.ts +43 -0
- package/dist/wallet/tx/register/plan.js +168 -0
- package/dist/wallet/tx/register/result.d.ts +78 -0
- package/dist/wallet/tx/register/result.js +41 -0
- package/dist/wallet/tx/register.d.ts +1 -70
- package/dist/wallet/tx/register.js +1 -681
- package/dist/wallet/tx/reputation/confirm.d.ts +11 -0
- package/dist/wallet/tx/reputation/confirm.js +51 -0
- package/dist/wallet/tx/reputation/draft.d.ts +20 -0
- package/dist/wallet/tx/reputation/draft.js +130 -0
- package/dist/wallet/tx/reputation/index.d.ts +4 -0
- package/dist/wallet/tx/reputation/index.js +162 -0
- package/dist/wallet/tx/reputation/intent.d.ts +36 -0
- package/dist/wallet/tx/reputation/intent.js +157 -0
- package/dist/wallet/tx/reputation/plan.d.ts +19 -0
- package/dist/wallet/tx/reputation/plan.js +64 -0
- package/dist/wallet/tx/reputation/result.d.ts +21 -0
- package/dist/wallet/tx/reputation/result.js +31 -0
- package/dist/wallet/tx/reputation/types.d.ts +130 -0
- package/dist/wallet/tx/reputation/types.js +1 -0
- package/dist/wallet/tx/reputation.d.ts +1 -74
- package/dist/wallet/tx/reputation.js +1 -556
- package/dist/wallet/tx/signing.d.ts +18 -0
- package/dist/wallet/tx/signing.js +31 -0
- package/dist/wallet/tx/state-persist.d.ts +27 -0
- package/dist/wallet/tx/state-persist.js +54 -0
- package/dist/wallet/tx/types.d.ts +44 -0
- package/dist/wallet/tx/types.js +1 -0
- package/package.json +1 -1
- package/dist/cli/mining-json.d.ts +0 -20
- package/dist/cli/mining-json.js +0 -46
- package/dist/cli/mutation-json.d.ts +0 -325
- package/dist/cli/mutation-json.js +0 -269
- package/dist/cli/mutation-resolved-json.d.ts +0 -117
- package/dist/cli/mutation-resolved-json.js +0 -123
- package/dist/cli/preview-json.d.ts +0 -319
- package/dist/cli/preview-json.js +0 -254
- package/dist/cli/read-json.d.ts +0 -190
- package/dist/cli/read-json.js +0 -627
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { buildWalletMutationTransactionWithReserveFallback, outpointKey, } from "../common.js";
|
|
2
|
+
function satsToBtcNumber(value) {
|
|
3
|
+
return Number(value) / 100_000_000;
|
|
4
|
+
}
|
|
5
|
+
function valueToSats(value) {
|
|
6
|
+
const text = typeof value === "number" ? value.toFixed(8) : value;
|
|
7
|
+
const match = /^(-?)(\d+)(?:\.(\d{0,8}))?$/.exec(text.trim());
|
|
8
|
+
if (match == null) {
|
|
9
|
+
throw new Error(`wallet_register_invalid_amount_${text}`);
|
|
10
|
+
}
|
|
11
|
+
const sign = match[1] === "-" ? -1n : 1n;
|
|
12
|
+
const whole = BigInt(match[2] ?? "0");
|
|
13
|
+
const fraction = BigInt((match[3] ?? "").padEnd(8, "0"));
|
|
14
|
+
return sign * ((whole * 100000000n) + fraction);
|
|
15
|
+
}
|
|
16
|
+
function encodeOpReturnScript(payload) {
|
|
17
|
+
if (payload.length <= 75) {
|
|
18
|
+
return Buffer.concat([
|
|
19
|
+
Buffer.from([0x6a, payload.length]),
|
|
20
|
+
Buffer.from(payload),
|
|
21
|
+
]).toString("hex");
|
|
22
|
+
}
|
|
23
|
+
return Buffer.concat([
|
|
24
|
+
Buffer.from([0x6a, 0x4c, payload.length]),
|
|
25
|
+
Buffer.from(payload),
|
|
26
|
+
]).toString("hex");
|
|
27
|
+
}
|
|
28
|
+
export function extractOpReturnPayloadFromScriptHex(scriptHex) {
|
|
29
|
+
const bytes = Buffer.from(scriptHex, "hex");
|
|
30
|
+
if (bytes.length < 2 || bytes[0] !== 0x6a) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const opcode = bytes[1];
|
|
34
|
+
if (opcode <= 75) {
|
|
35
|
+
const end = 2 + opcode;
|
|
36
|
+
return end === bytes.length ? bytes.subarray(2, end) : null;
|
|
37
|
+
}
|
|
38
|
+
if (opcode === 0x4c && bytes.length >= 3) {
|
|
39
|
+
const length = bytes[2];
|
|
40
|
+
const end = 3 + length;
|
|
41
|
+
return end === bytes.length ? bytes.subarray(3, end) : null;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function isSpendableConfirmedUtxo(entry) {
|
|
46
|
+
return entry.confirmations >= 1
|
|
47
|
+
&& entry.spendable !== false
|
|
48
|
+
&& entry.safe !== false;
|
|
49
|
+
}
|
|
50
|
+
function sortUtxos(entries) {
|
|
51
|
+
return entries
|
|
52
|
+
.slice()
|
|
53
|
+
.sort((left, right) => right.amount - left.amount
|
|
54
|
+
|| left.txid.localeCompare(right.txid)
|
|
55
|
+
|| left.vout - right.vout);
|
|
56
|
+
}
|
|
57
|
+
function listFundingUtxos(entries, fundingScriptPubKeyHex) {
|
|
58
|
+
return sortUtxos(entries.filter((entry) => isSpendableConfirmedUtxo(entry) && entry.scriptPubKey === fundingScriptPubKeyHex));
|
|
59
|
+
}
|
|
60
|
+
function buildRootRegisterOutputs(options) {
|
|
61
|
+
const payload = options.serializeDomainReg(options.domainName).opReturnData;
|
|
62
|
+
const outputs = [
|
|
63
|
+
{ data: Buffer.from(payload).toString("hex") },
|
|
64
|
+
{ [options.treasuryAddress]: satsToBtcNumber(options.priceSats) },
|
|
65
|
+
];
|
|
66
|
+
return {
|
|
67
|
+
outputs,
|
|
68
|
+
changePosition: outputs.length,
|
|
69
|
+
expectedOpReturnScriptHex: encodeOpReturnScript(payload),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function buildSubdomainRegisterOutputs(options) {
|
|
73
|
+
const payload = options.serializeDomainReg(options.domainName).opReturnData;
|
|
74
|
+
return {
|
|
75
|
+
outputs: [{ data: Buffer.from(payload).toString("hex") }],
|
|
76
|
+
changePosition: 1,
|
|
77
|
+
expectedOpReturnScriptHex: encodeOpReturnScript(payload),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function validateFundedDraft(decoded, funded, plan) {
|
|
81
|
+
const inputs = decoded.tx.vin;
|
|
82
|
+
const outputs = decoded.tx.vout;
|
|
83
|
+
if (inputs.length === 0) {
|
|
84
|
+
throw new Error("wallet_register_missing_sender_input");
|
|
85
|
+
}
|
|
86
|
+
if (outputs[0]?.scriptPubKey?.hex !== plan.expectedOpReturnScriptHex) {
|
|
87
|
+
throw new Error("wallet_register_opreturn_mismatch");
|
|
88
|
+
}
|
|
89
|
+
if (plan.expectedTreasuryScriptHex !== null && plan.expectedTreasuryOutputIndex !== null) {
|
|
90
|
+
if (outputs[plan.expectedTreasuryOutputIndex]?.scriptPubKey?.hex !== plan.expectedTreasuryScriptHex) {
|
|
91
|
+
throw new Error("wallet_register_treasury_output_mismatch");
|
|
92
|
+
}
|
|
93
|
+
if (valueToSats(outputs[plan.expectedTreasuryOutputIndex]?.value ?? 0) < (plan.expectedTreasuryValueSats ?? 0n)) {
|
|
94
|
+
throw new Error("wallet_register_treasury_value_too_small");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const expectedWithoutChange = 1 + Number(plan.expectedTreasuryOutputIndex !== null);
|
|
98
|
+
if (funded.changepos === -1) {
|
|
99
|
+
if (outputs.length !== expectedWithoutChange) {
|
|
100
|
+
throw new Error("wallet_register_unexpected_output_count");
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (funded.changepos !== plan.changePosition || outputs.length !== expectedWithoutChange + 1) {
|
|
105
|
+
throw new Error("wallet_register_change_position_mismatch");
|
|
106
|
+
}
|
|
107
|
+
if (outputs[funded.changepos]?.scriptPubKey?.hex !== plan.allowedFundingScriptPubKeyHex) {
|
|
108
|
+
throw new Error("wallet_register_change_output_mismatch");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function buildRegisterPlan(options) {
|
|
112
|
+
void options.context;
|
|
113
|
+
void options.parentDomainName;
|
|
114
|
+
const fundingUtxos = listFundingUtxos(options.allUtxos, options.state.funding.scriptPubKeyHex);
|
|
115
|
+
if (options.registerKind === "root") {
|
|
116
|
+
const rootOutputs = buildRootRegisterOutputs({
|
|
117
|
+
domainName: options.domainName,
|
|
118
|
+
treasuryAddress: options.treasuryAddress,
|
|
119
|
+
treasuryScriptPubKeyHex: options.treasuryScriptPubKeyHex,
|
|
120
|
+
priceSats: options.rootPriceSats,
|
|
121
|
+
serializeDomainReg: options.serializeDomainReg,
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
registerKind: "root",
|
|
125
|
+
sender: options.sender,
|
|
126
|
+
changeAddress: options.state.funding.address,
|
|
127
|
+
fixedInputs: [],
|
|
128
|
+
outputs: rootOutputs.outputs,
|
|
129
|
+
changePosition: rootOutputs.changePosition,
|
|
130
|
+
expectedOpReturnScriptHex: rootOutputs.expectedOpReturnScriptHex,
|
|
131
|
+
expectedTreasuryOutputIndex: 1,
|
|
132
|
+
expectedTreasuryScriptHex: options.treasuryScriptPubKeyHex,
|
|
133
|
+
expectedTreasuryValueSats: options.rootPriceSats,
|
|
134
|
+
allowedFundingScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
135
|
+
eligibleFundingOutpointKeys: new Set(fundingUtxos.map((entry) => outpointKey(entry))),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const subdomainOutputs = buildSubdomainRegisterOutputs({
|
|
139
|
+
domainName: options.domainName,
|
|
140
|
+
serializeDomainReg: options.serializeDomainReg,
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
registerKind: "subdomain",
|
|
144
|
+
sender: options.sender,
|
|
145
|
+
changeAddress: options.state.funding.address,
|
|
146
|
+
fixedInputs: [],
|
|
147
|
+
outputs: subdomainOutputs.outputs,
|
|
148
|
+
changePosition: subdomainOutputs.changePosition,
|
|
149
|
+
expectedOpReturnScriptHex: subdomainOutputs.expectedOpReturnScriptHex,
|
|
150
|
+
expectedTreasuryOutputIndex: null,
|
|
151
|
+
expectedTreasuryScriptHex: null,
|
|
152
|
+
expectedTreasuryValueSats: null,
|
|
153
|
+
allowedFundingScriptPubKeyHex: options.state.funding.scriptPubKeyHex,
|
|
154
|
+
eligibleFundingOutpointKeys: new Set(fundingUtxos.map((entry) => outpointKey(entry))),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export async function buildRegisterTransaction(options) {
|
|
158
|
+
return buildWalletMutationTransactionWithReserveFallback({
|
|
159
|
+
rpc: options.rpc,
|
|
160
|
+
walletName: options.walletName,
|
|
161
|
+
state: options.state,
|
|
162
|
+
plan: options.plan,
|
|
163
|
+
validateFundedDraft,
|
|
164
|
+
finalizeErrorCode: "wallet_register_finalize_failed",
|
|
165
|
+
mempoolRejectPrefix: "wallet_register_mempool_rejected",
|
|
166
|
+
feeRate: options.feeRateSatVb,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { PendingMutationRecord } from "../../types.js";
|
|
2
|
+
import type { WalletMutationFeeSummary } from "../common.js";
|
|
3
|
+
export declare const SUBDOMAIN_REGISTRATION_FEE_COGTOSHI = 100n;
|
|
4
|
+
export type RegisterEconomicEffectKind = "treasury-payment" | "cog-burn";
|
|
5
|
+
export interface RegisterResolvedSenderSummary {
|
|
6
|
+
selector: string;
|
|
7
|
+
localIndex: number;
|
|
8
|
+
scriptPubKeyHex: string;
|
|
9
|
+
address: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RegisterResolvedEconomicEffectSummary {
|
|
12
|
+
kind: RegisterEconomicEffectKind;
|
|
13
|
+
amount: bigint;
|
|
14
|
+
}
|
|
15
|
+
export interface RegisterResolvedSummary {
|
|
16
|
+
path: "root" | "subdomain";
|
|
17
|
+
parentDomainName: string | null;
|
|
18
|
+
sender: RegisterResolvedSenderSummary;
|
|
19
|
+
economicEffect: RegisterResolvedEconomicEffectSummary;
|
|
20
|
+
}
|
|
21
|
+
export interface RegisterDomainResult {
|
|
22
|
+
domainName: string;
|
|
23
|
+
registerKind: "root" | "subdomain";
|
|
24
|
+
parentDomainName: string | null;
|
|
25
|
+
senderSelector: string;
|
|
26
|
+
senderLocalIndex: number;
|
|
27
|
+
senderScriptPubKeyHex: string;
|
|
28
|
+
senderAddress: string;
|
|
29
|
+
economicEffectKind: RegisterEconomicEffectKind;
|
|
30
|
+
economicEffectAmount: bigint;
|
|
31
|
+
resolved: RegisterResolvedSummary;
|
|
32
|
+
txid: string;
|
|
33
|
+
status: "live" | "confirmed";
|
|
34
|
+
reusedExisting: boolean;
|
|
35
|
+
fees: WalletMutationFeeSummary;
|
|
36
|
+
}
|
|
37
|
+
export declare function createRegisterReuseResult(options: {
|
|
38
|
+
operation: {
|
|
39
|
+
normalizedDomainName: string;
|
|
40
|
+
senderResolution: {
|
|
41
|
+
registerKind: "root" | "subdomain";
|
|
42
|
+
parentDomainName: string | null;
|
|
43
|
+
senderSelector: string;
|
|
44
|
+
sender: {
|
|
45
|
+
localIndex: number;
|
|
46
|
+
scriptPubKeyHex: string;
|
|
47
|
+
address: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
rootPriceSats: bigint;
|
|
51
|
+
resolvedSummary: RegisterResolvedSummary;
|
|
52
|
+
};
|
|
53
|
+
mutation: PendingMutationRecord;
|
|
54
|
+
resolution: "confirmed" | "live";
|
|
55
|
+
fees: WalletMutationFeeSummary;
|
|
56
|
+
}): RegisterDomainResult;
|
|
57
|
+
export declare function createRegisterResult(options: {
|
|
58
|
+
operation: {
|
|
59
|
+
normalizedDomainName: string;
|
|
60
|
+
senderResolution: {
|
|
61
|
+
registerKind: "root" | "subdomain";
|
|
62
|
+
parentDomainName: string | null;
|
|
63
|
+
senderSelector: string;
|
|
64
|
+
sender: {
|
|
65
|
+
localIndex: number;
|
|
66
|
+
scriptPubKeyHex: string;
|
|
67
|
+
address: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
rootPriceSats: bigint;
|
|
71
|
+
resolvedSummary: RegisterResolvedSummary;
|
|
72
|
+
};
|
|
73
|
+
mutation: PendingMutationRecord;
|
|
74
|
+
builtTxid: string | null;
|
|
75
|
+
status: "live" | "confirmed";
|
|
76
|
+
reusedExisting: boolean;
|
|
77
|
+
fees: WalletMutationFeeSummary;
|
|
78
|
+
}): RegisterDomainResult;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const SUBDOMAIN_REGISTRATION_FEE_COGTOSHI = 100n;
|
|
2
|
+
export function createRegisterReuseResult(options) {
|
|
3
|
+
return {
|
|
4
|
+
domainName: options.operation.normalizedDomainName,
|
|
5
|
+
registerKind: options.operation.senderResolution.registerKind,
|
|
6
|
+
parentDomainName: options.operation.senderResolution.parentDomainName,
|
|
7
|
+
senderSelector: options.operation.senderResolution.senderSelector,
|
|
8
|
+
senderLocalIndex: options.operation.senderResolution.sender.localIndex,
|
|
9
|
+
senderScriptPubKeyHex: options.operation.senderResolution.sender.scriptPubKeyHex,
|
|
10
|
+
senderAddress: options.operation.senderResolution.sender.address,
|
|
11
|
+
economicEffectKind: options.operation.senderResolution.registerKind === "root" ? "treasury-payment" : "cog-burn",
|
|
12
|
+
economicEffectAmount: options.operation.senderResolution.registerKind === "root"
|
|
13
|
+
? options.operation.rootPriceSats
|
|
14
|
+
: SUBDOMAIN_REGISTRATION_FEE_COGTOSHI,
|
|
15
|
+
resolved: options.operation.resolvedSummary,
|
|
16
|
+
txid: options.mutation.attemptedTxid ?? "unknown",
|
|
17
|
+
status: options.resolution,
|
|
18
|
+
reusedExisting: true,
|
|
19
|
+
fees: options.fees,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function createRegisterResult(options) {
|
|
23
|
+
return {
|
|
24
|
+
domainName: options.operation.normalizedDomainName,
|
|
25
|
+
registerKind: options.operation.senderResolution.registerKind,
|
|
26
|
+
parentDomainName: options.operation.senderResolution.parentDomainName,
|
|
27
|
+
senderSelector: options.operation.senderResolution.senderSelector,
|
|
28
|
+
senderLocalIndex: options.operation.senderResolution.sender.localIndex,
|
|
29
|
+
senderScriptPubKeyHex: options.operation.senderResolution.sender.scriptPubKeyHex,
|
|
30
|
+
senderAddress: options.operation.senderResolution.sender.address,
|
|
31
|
+
economicEffectKind: options.operation.senderResolution.registerKind === "root" ? "treasury-payment" : "cog-burn",
|
|
32
|
+
economicEffectAmount: options.operation.senderResolution.registerKind === "root"
|
|
33
|
+
? options.operation.rootPriceSats
|
|
34
|
+
: SUBDOMAIN_REGISTRATION_FEE_COGTOSHI,
|
|
35
|
+
resolved: options.operation.resolvedSummary,
|
|
36
|
+
txid: options.mutation.attemptedTxid ?? options.builtTxid ?? "unknown",
|
|
37
|
+
status: options.status,
|
|
38
|
+
reusedExisting: options.reusedExisting,
|
|
39
|
+
fees: options.fees,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { attachOrStartManagedBitcoindService } from "../../bitcoind/service.js";
|
|
3
|
-
import { createRpcClient } from "../../bitcoind/node.js";
|
|
4
|
-
import type { RpcTransaction } from "../../bitcoind/types.js";
|
|
5
|
-
import type { WalletPrompter } from "../lifecycle.js";
|
|
6
|
-
import { type WalletRuntimePaths } from "../runtime.js";
|
|
7
|
-
import { type WalletSecretProvider } from "../state/provider.js";
|
|
8
|
-
import { openWalletReadContext } from "../read/index.js";
|
|
9
|
-
import { type WalletMutationFeeSummary, type WalletMutationRpcClient } from "./common.js";
|
|
10
|
-
interface WalletRegisterRpcClient extends WalletMutationRpcClient {
|
|
11
|
-
getBlockchainInfo(): Promise<{
|
|
12
|
-
blocks: number;
|
|
13
|
-
}>;
|
|
14
|
-
sendRawTransaction(hex: string): Promise<string>;
|
|
15
|
-
getRawMempool(): Promise<string[]>;
|
|
16
|
-
getRawTransaction(txid: string, verbose?: boolean): Promise<RpcTransaction>;
|
|
17
|
-
}
|
|
18
|
-
type RegisterEconomicEffectKind = "treasury-payment" | "cog-burn";
|
|
19
|
-
export interface RegisterResolvedSenderSummary {
|
|
20
|
-
selector: string;
|
|
21
|
-
localIndex: number;
|
|
22
|
-
scriptPubKeyHex: string;
|
|
23
|
-
address: string;
|
|
24
|
-
}
|
|
25
|
-
export interface RegisterResolvedEconomicEffectSummary {
|
|
26
|
-
kind: RegisterEconomicEffectKind;
|
|
27
|
-
amount: bigint;
|
|
28
|
-
}
|
|
29
|
-
export interface RegisterResolvedSummary {
|
|
30
|
-
path: "root" | "subdomain";
|
|
31
|
-
parentDomainName: string | null;
|
|
32
|
-
sender: RegisterResolvedSenderSummary;
|
|
33
|
-
economicEffect: RegisterResolvedEconomicEffectSummary;
|
|
34
|
-
}
|
|
35
|
-
export interface RegisterDomainResult {
|
|
36
|
-
domainName: string;
|
|
37
|
-
registerKind: "root" | "subdomain";
|
|
38
|
-
parentDomainName: string | null;
|
|
39
|
-
senderSelector: string;
|
|
40
|
-
senderLocalIndex: number;
|
|
41
|
-
senderScriptPubKeyHex: string;
|
|
42
|
-
senderAddress: string;
|
|
43
|
-
economicEffectKind: RegisterEconomicEffectKind;
|
|
44
|
-
economicEffectAmount: bigint;
|
|
45
|
-
resolved: RegisterResolvedSummary;
|
|
46
|
-
txid: string;
|
|
47
|
-
status: "live" | "confirmed";
|
|
48
|
-
reusedExisting: boolean;
|
|
49
|
-
fees: WalletMutationFeeSummary;
|
|
50
|
-
}
|
|
51
|
-
export interface RegisterDomainOptions {
|
|
52
|
-
domainName: string;
|
|
53
|
-
fromIdentity?: string | null;
|
|
54
|
-
feeRateSatVb?: number | null;
|
|
55
|
-
dataDir: string;
|
|
56
|
-
databasePath: string;
|
|
57
|
-
forceRace?: boolean;
|
|
58
|
-
provider?: WalletSecretProvider;
|
|
59
|
-
prompter: WalletPrompter;
|
|
60
|
-
assumeYes?: boolean;
|
|
61
|
-
nowUnixMs?: number;
|
|
62
|
-
paths?: WalletRuntimePaths;
|
|
63
|
-
openReadContext?: typeof openWalletReadContext;
|
|
64
|
-
attachService?: typeof attachOrStartManagedBitcoindService;
|
|
65
|
-
rpcFactory?: (config: Parameters<typeof createRpcClient>[0]) => WalletRegisterRpcClient;
|
|
66
|
-
loadGenesisParameters?: typeof loadBundledGenesisParameters;
|
|
67
|
-
}
|
|
68
|
-
export declare function extractOpReturnPayloadFromScriptHex(scriptHex: string): Uint8Array | null;
|
|
69
|
-
export declare function registerDomain(options: RegisterDomainOptions): Promise<RegisterDomainResult>;
|
|
70
|
-
export {};
|
|
1
|
+
export * from "./register/index.js";
|