@swapkit/toolboxes 4.0.0-beta.50 → 4.0.0-beta.52
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/dist/src/cosmos/index.cjs +2 -2
- package/dist/src/cosmos/index.cjs.map +10 -6
- package/dist/src/cosmos/index.js +2 -2
- package/dist/src/cosmos/index.js.map +10 -6
- package/dist/src/evm/index.cjs +2 -2
- package/dist/src/evm/index.cjs.map +10 -8
- package/dist/src/evm/index.js +2 -2
- package/dist/src/evm/index.js.map +10 -8
- package/dist/src/index.cjs +4 -2
- package/dist/src/index.cjs.map +54 -4
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +54 -4
- package/dist/src/near/index.cjs +2 -2
- package/dist/src/near/index.cjs.map +7 -5
- package/dist/src/near/index.js +2 -2
- package/dist/src/near/index.js.map +7 -5
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +2 -2
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +2 -2
- package/dist/src/ripple/index.cjs +2 -2
- package/dist/src/ripple/index.cjs.map +2 -2
- package/dist/src/ripple/index.js +2 -2
- package/dist/src/ripple/index.js.map +2 -2
- package/dist/src/solana/index.cjs +2 -2
- package/dist/src/solana/index.cjs.map +5 -4
- package/dist/src/solana/index.js +2 -2
- package/dist/src/solana/index.js.map +5 -4
- package/dist/src/substrate/index.cjs +2 -2
- package/dist/src/substrate/index.cjs.map +6 -5
- package/dist/src/substrate/index.js +2 -2
- package/dist/src/substrate/index.js.map +6 -5
- package/dist/src/tron/index.cjs +2 -2
- package/dist/src/tron/index.cjs.map +6 -5
- package/dist/src/tron/index.js +2 -2
- package/dist/src/tron/index.js.map +6 -5
- package/dist/src/utxo/index.cjs +4 -4
- package/dist/src/utxo/index.cjs.map +10 -7
- package/dist/src/utxo/index.js +4 -4
- package/dist/src/utxo/index.js.map +10 -7
- package/{src/cosmos/index.ts → dist/types/cosmos/index.d.ts} +1 -0
- package/dist/types/cosmos/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +5 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -0
- package/{src/cosmos/thorchainUtils/index.ts → dist/types/cosmos/thorchainUtils/index.d.ts} +1 -0
- package/dist/types/cosmos/thorchainUtils/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts +208 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts +4 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +66 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts +93 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/index.d.ts +14 -0
- package/dist/types/cosmos/toolbox/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts +158 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -0
- package/{src/cosmos/types.ts → dist/types/cosmos/types.d.ts} +24 -29
- package/dist/types/cosmos/types.d.ts.map +1 -0
- package/dist/types/cosmos/util.d.ts +68 -0
- package/dist/types/cosmos/util.d.ts.map +1 -0
- package/dist/types/evm/api.d.ts +8 -0
- package/dist/types/evm/api.d.ts.map +1 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts +36 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts.map +1 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts +40 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts.map +1 -0
- package/dist/types/evm/helpers.d.ts +20 -0
- package/dist/types/evm/helpers.d.ts.map +1 -0
- package/{src/evm/index.ts → dist/types/evm/index.d.ts} +1 -0
- package/dist/types/evm/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +82 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -0
- package/dist/types/evm/toolbox/evm.d.ts +367 -0
- package/dist/types/evm/toolbox/evm.d.ts.map +1 -0
- package/dist/types/evm/toolbox/index.d.ts +89 -0
- package/dist/types/evm/toolbox/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/op.d.ts +62 -0
- package/dist/types/evm/toolbox/op.d.ts.map +1 -0
- package/dist/types/evm/types.d.ts +98 -0
- package/dist/types/evm/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/near/helpers/core.d.ts +15 -0
- package/dist/types/near/helpers/core.d.ts.map +1 -0
- package/dist/types/near/helpers/gasEstimation.d.ts +41 -0
- package/dist/types/near/helpers/gasEstimation.d.ts.map +1 -0
- package/dist/types/near/helpers/nep141.d.ts +72 -0
- package/dist/types/near/helpers/nep141.d.ts.map +1 -0
- package/dist/types/near/index.d.ts +10 -0
- package/dist/types/near/index.d.ts.map +1 -0
- package/dist/types/near/toolbox.d.ts +4 -0
- package/dist/types/near/toolbox.d.ts.map +1 -0
- package/dist/types/near/types/contract.d.ts +38 -0
- package/dist/types/near/types/contract.d.ts.map +1 -0
- package/dist/types/near/types/nep141.d.ts +56 -0
- package/dist/types/near/types/nep141.d.ts.map +1 -0
- package/dist/types/near/types/toolbox.d.ts +57 -0
- package/dist/types/near/types/toolbox.d.ts.map +1 -0
- package/dist/types/near/types.d.ts +44 -0
- package/dist/types/near/types.d.ts.map +1 -0
- package/dist/types/radix/index.d.ts +14 -0
- package/dist/types/radix/index.d.ts.map +1 -0
- package/dist/types/ripple/index.d.ts +43 -0
- package/dist/types/ripple/index.d.ts.map +1 -0
- package/dist/types/solana/index.d.ts +37 -0
- package/dist/types/solana/index.d.ts.map +1 -0
- package/dist/types/solana/toolbox.d.ts +41 -0
- package/dist/types/solana/toolbox.d.ts.map +1 -0
- package/dist/types/substrate/balance.d.ts +17 -0
- package/dist/types/substrate/balance.d.ts.map +1 -0
- package/{src/substrate/index.ts → dist/types/substrate/index.d.ts} +1 -0
- package/dist/types/substrate/index.d.ts.map +1 -0
- package/dist/types/substrate/substrate.d.ts +148 -0
- package/dist/types/substrate/substrate.d.ts.map +1 -0
- package/dist/types/substrate/types.d.ts +100 -0
- package/dist/types/substrate/types.d.ts.map +1 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts +156 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts.map +1 -0
- package/dist/types/tron/helpers/trongrid.d.ts +8 -0
- package/dist/types/tron/helpers/trongrid.d.ts.map +1 -0
- package/dist/types/tron/index.d.ts +6 -0
- package/dist/types/tron/index.d.ts.map +1 -0
- package/dist/types/tron/toolbox.d.ts +26 -0
- package/dist/types/tron/toolbox.d.ts.map +1 -0
- package/dist/types/tron/types.d.ts +101 -0
- package/dist/types/tron/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +18 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utxo/helpers/api.d.ts +133 -0
- package/dist/types/utxo/helpers/api.d.ts.map +1 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +10 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -0
- package/dist/types/utxo/helpers/coinselect.d.ts +16 -0
- package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -0
- package/{src/utxo/helpers/index.ts → dist/types/utxo/helpers/index.d.ts} +1 -0
- package/dist/types/utxo/helpers/index.d.ts.map +1 -0
- package/dist/types/utxo/helpers/txSize.d.ts +21 -0
- package/dist/types/utxo/helpers/txSize.d.ts.map +1 -0
- package/{src/utxo/index.ts → dist/types/utxo/index.d.ts} +1 -0
- package/dist/types/utxo/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +104 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/index.d.ts +50 -0
- package/dist/types/utxo/toolbox/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/utxo.d.ts +102 -0
- package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/zcash.d.ts +83 -0
- package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -0
- package/dist/types/utxo/types.d.ts +46 -0
- package/dist/types/utxo/types.d.ts.map +1 -0
- package/package.json +15 -18
- package/dist/chunk-0h4xdrwz.js +0 -5
- package/dist/chunk-0h4xdrwz.js.map +0 -10
- package/dist/chunk-4yap1fvd.js +0 -4
- package/dist/chunk-4yap1fvd.js.map +0 -10
- package/dist/chunk-9bqegm61.js +0 -4
- package/dist/chunk-9bqegm61.js.map +0 -10
- package/dist/chunk-fazw0jvt.js +0 -4
- package/dist/chunk-fazw0jvt.js.map +0 -9
- package/dist/chunk-fjfxga2v.js +0 -4
- package/dist/chunk-fjfxga2v.js.map +0 -10
- package/dist/chunk-s47y8512.js +0 -5
- package/dist/chunk-s47y8512.js.map +0 -9
- package/dist/chunk-vtd17cje.js +0 -4
- package/dist/chunk-vtd17cje.js.map +0 -10
- package/dist/chunk-zcdeg6h9.js +0 -5
- package/dist/chunk-zcdeg6h9.js.map +0 -10
- package/src/cosmos/thorchainUtils/addressFormat.ts +0 -26
- package/src/cosmos/thorchainUtils/messages.ts +0 -262
- package/src/cosmos/thorchainUtils/registry.ts +0 -44
- package/src/cosmos/thorchainUtils/types/MsgCompiled.ts +0 -2800
- package/src/cosmos/thorchainUtils/types/client-types.ts +0 -73
- package/src/cosmos/thorchainUtils/types/index.ts +0 -1
- package/src/cosmos/toolbox/cosmos.ts +0 -375
- package/src/cosmos/toolbox/index.ts +0 -33
- package/src/cosmos/toolbox/thorchain.ts +0 -313
- package/src/cosmos/util.ts +0 -266
- package/src/evm/__tests__/address-validation.test.ts +0 -86
- package/src/evm/__tests__/ethereum.test.ts +0 -141
- package/src/evm/api.ts +0 -21
- package/src/evm/contracts/eth/multicall.ts +0 -165
- package/src/evm/contracts/op/gasOracle.ts +0 -151
- package/src/evm/helpers.ts +0 -194
- package/src/evm/toolbox/baseEVMToolbox.ts +0 -762
- package/src/evm/toolbox/evm.ts +0 -66
- package/src/evm/toolbox/index.ts +0 -52
- package/src/evm/toolbox/op.ts +0 -131
- package/src/evm/types.ts +0 -146
- package/src/index.ts +0 -263
- package/src/near/__tests__/core.test.ts +0 -80
- package/src/near/helpers/contractFactory.ts +0 -22
- package/src/near/helpers/core.ts +0 -91
- package/src/near/helpers/gasEstimation.ts +0 -110
- package/src/near/helpers/index.ts +0 -5
- package/src/near/helpers/nep141.ts +0 -110
- package/src/near/index.ts +0 -24
- package/src/near/toolbox.ts +0 -509
- package/src/near/types/contract.ts +0 -48
- package/src/near/types/nep141.ts +0 -66
- package/src/near/types.ts +0 -57
- package/src/radix/index.ts +0 -156
- package/src/ripple/index.ts +0 -192
- package/src/solana/index.ts +0 -55
- package/src/solana/toolbox.ts +0 -433
- package/src/substrate/balance.ts +0 -92
- package/src/substrate/substrate.ts +0 -320
- package/src/substrate/types.ts +0 -120
- package/src/tron/__tests__/toolbox.test.ts +0 -147
- package/src/tron/helpers/trc20.abi.ts +0 -107
- package/src/tron/helpers/trongrid.ts +0 -54
- package/src/tron/index.ts +0 -17
- package/src/tron/toolbox.ts +0 -650
- package/src/tron/types.ts +0 -120
- package/src/utils.ts +0 -27
- package/src/utxo/__tests__/zcash-integration.test.ts +0 -114
- package/src/utxo/helpers/api.ts +0 -560
- package/src/utxo/helpers/bchaddrjs.ts +0 -183
- package/src/utxo/helpers/coinselect.ts +0 -98
- package/src/utxo/helpers/txSize.ts +0 -104
- package/src/utxo/toolbox/bitcoinCash.ts +0 -320
- package/src/utxo/toolbox/index.ts +0 -90
- package/src/utxo/toolbox/utxo.ts +0 -525
- package/src/utxo/toolbox/zcash.ts +0 -208
- package/src/utxo/types.ts +0 -57
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import secp256k1 from "@bitcoinerlab/secp256k1";
|
|
2
|
-
import { HDKey } from "@scure/bip32";
|
|
3
|
-
import { mnemonicToSeedSync } from "@scure/bip39";
|
|
4
|
-
import {
|
|
5
|
-
Chain,
|
|
6
|
-
type ChainSigner,
|
|
7
|
-
type DerivationPathArray,
|
|
8
|
-
FeeOption,
|
|
9
|
-
NetworkDerivationPath,
|
|
10
|
-
SKConfig,
|
|
11
|
-
SwapKitError,
|
|
12
|
-
derivationPathToString,
|
|
13
|
-
updateDerivationPath,
|
|
14
|
-
} from "@swapkit/helpers";
|
|
15
|
-
import type { Psbt } from "bitcoinjs-lib";
|
|
16
|
-
import { hash160 } from "bitcoinjs-lib/src/crypto";
|
|
17
|
-
import bs58check from "bs58check";
|
|
18
|
-
import { ECPairFactory } from "ecpair";
|
|
19
|
-
import { P, match } from "ts-pattern";
|
|
20
|
-
import { getUtxoNetwork } from "../helpers";
|
|
21
|
-
import type { UTXOBuildTxParams, UTXOTransferParams } from "../types";
|
|
22
|
-
import { createUTXOToolbox } from "./utxo";
|
|
23
|
-
|
|
24
|
-
const chain = Chain.Zcash;
|
|
25
|
-
const network = getUtxoNetwork()(chain);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Custom Zcash address generation that handles 2-byte prefixes
|
|
29
|
-
*
|
|
30
|
-
* Zcash transparent addresses use 2-byte version prefixes, unlike Bitcoin's single byte.
|
|
31
|
-
* This is incompatible with bitcoinjs-lib's payment methods which expect UInt8 values.
|
|
32
|
-
*
|
|
33
|
-
* @param publicKey - The public key buffer to generate address from
|
|
34
|
-
* @param isTestnet - Whether to generate testnet or mainnet address
|
|
35
|
-
* @returns A valid Zcash transparent address (t1... for mainnet, tm... for testnet)
|
|
36
|
-
*/
|
|
37
|
-
function generateZcashAddress(publicKey: Buffer, isTestnet = false): string {
|
|
38
|
-
// Hash the public key using RIPEMD160(SHA256(pubkey))
|
|
39
|
-
const publicKeyHash = hash160(publicKey);
|
|
40
|
-
|
|
41
|
-
// Zcash uses 2-byte prefixes for transparent addresses
|
|
42
|
-
// These prefixes ensure addresses start with expected characters when base58 encoded
|
|
43
|
-
const prefix = isTestnet
|
|
44
|
-
? Buffer.from([0x1c, 0xba]) // testnet prefix (results in tm... addresses)
|
|
45
|
-
: Buffer.from([0x1c, 0xb8]); // mainnet prefix (results in t1... addresses)
|
|
46
|
-
|
|
47
|
-
// Combine prefix + hash (22 bytes total: 2 byte prefix + 20 byte hash)
|
|
48
|
-
const payload = Buffer.concat([prefix, publicKeyHash]);
|
|
49
|
-
|
|
50
|
-
// Encode with base58check for final address
|
|
51
|
-
return bs58check.encode(payload);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function validateZcashAddress(address: string) {
|
|
55
|
-
try {
|
|
56
|
-
// Shielded addresses are not supported
|
|
57
|
-
if (address.startsWith("z")) {
|
|
58
|
-
console.warn(
|
|
59
|
-
"Shielded Zcash addresses (z-addresses) are not supported. Use transparent addresses (t1/t3) only.",
|
|
60
|
-
);
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const isMainnet = address.startsWith("t1");
|
|
65
|
-
const isTestnet = address.startsWith("t3");
|
|
66
|
-
|
|
67
|
-
if (!(isMainnet || isTestnet)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Verify network matches address type
|
|
72
|
-
const { isStagenet } = SKConfig.get("envs");
|
|
73
|
-
if ((isMainnet && isStagenet) || (isTestnet && !isStagenet)) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return validateBase58Check(address, network);
|
|
78
|
-
} catch {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function validateBase58Check(
|
|
84
|
-
address: string,
|
|
85
|
-
network: ReturnType<ReturnType<typeof getUtxoNetwork>>,
|
|
86
|
-
) {
|
|
87
|
-
try {
|
|
88
|
-
const decoded = bs58check.decode(address);
|
|
89
|
-
|
|
90
|
-
if (decoded.length < 21) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const version = decoded[0];
|
|
95
|
-
return version === network.pubKeyHash || version === network.scriptHash;
|
|
96
|
-
} catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const ECPair = ECPairFactory(secp256k1);
|
|
102
|
-
|
|
103
|
-
type ZcashSigner = ChainSigner<Psbt, Psbt>;
|
|
104
|
-
|
|
105
|
-
async function createZcashSignerFromPhrase({
|
|
106
|
-
phrase,
|
|
107
|
-
derivationPathString,
|
|
108
|
-
}: {
|
|
109
|
-
phrase: string;
|
|
110
|
-
derivationPathString: string;
|
|
111
|
-
}) {
|
|
112
|
-
const seed = mnemonicToSeedSync(phrase);
|
|
113
|
-
const root = HDKey.fromMasterSeed(seed);
|
|
114
|
-
|
|
115
|
-
const node = root.derive(derivationPathString);
|
|
116
|
-
|
|
117
|
-
if (!node.privateKey) {
|
|
118
|
-
throw new Error("Unable to derive private key");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const keyPair = ECPair.fromPrivateKey(Buffer.from(node.privateKey), { network });
|
|
122
|
-
|
|
123
|
-
const { isStagenet } = SKConfig.get("envs");
|
|
124
|
-
const address = generateZcashAddress(keyPair.publicKey, isStagenet);
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
getAddress() {
|
|
128
|
-
return Promise.resolve(address);
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
signTransaction(psbt: Psbt) {
|
|
132
|
-
for (let i = 0; i < psbt.inputCount; i++) {
|
|
133
|
-
psbt.signInput(i, keyPair);
|
|
134
|
-
}
|
|
135
|
-
return Promise.resolve(psbt);
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export async function createZcashToolbox(
|
|
141
|
-
toolboxParams:
|
|
142
|
-
| {
|
|
143
|
-
signer?: ZcashSigner;
|
|
144
|
-
}
|
|
145
|
-
| {
|
|
146
|
-
phrase?: string;
|
|
147
|
-
derivationPath?: DerivationPathArray;
|
|
148
|
-
index?: number;
|
|
149
|
-
},
|
|
150
|
-
) {
|
|
151
|
-
const signer = await match(toolboxParams)
|
|
152
|
-
.with({ signer: P.not(P.nullish) }, ({ signer }) => Promise.resolve(signer))
|
|
153
|
-
.with({ phrase: P.string }, ({ phrase, derivationPath, index = 0 }) => {
|
|
154
|
-
// Handle derivation path processing at toolbox level
|
|
155
|
-
const baseDerivationPath = derivationPath ||
|
|
156
|
-
NetworkDerivationPath[Chain.Zcash] || [44, 133, 0, 0, 0];
|
|
157
|
-
const updatedDerivationPath = updateDerivationPath(baseDerivationPath, { index });
|
|
158
|
-
const derivationPathString = derivationPathToString(updatedDerivationPath);
|
|
159
|
-
|
|
160
|
-
return createZcashSignerFromPhrase({ phrase, derivationPathString });
|
|
161
|
-
})
|
|
162
|
-
.otherwise(() => Promise.resolve(undefined));
|
|
163
|
-
|
|
164
|
-
const { getFeeRates, broadcastTx, ...toolbox } = await createUTXOToolbox({
|
|
165
|
-
chain: Chain.Zcash,
|
|
166
|
-
signer,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
function getAddressFromKeys(keys: { getAddress: () => string }) {
|
|
170
|
-
return keys.getAddress();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function transfer({
|
|
174
|
-
recipient,
|
|
175
|
-
assetValue,
|
|
176
|
-
feeOptionKey = FeeOption.Fast,
|
|
177
|
-
...rest
|
|
178
|
-
}: UTXOTransferParams) {
|
|
179
|
-
const from = await signer?.getAddress();
|
|
180
|
-
if (!(signer && from)) throw new SwapKitError("toolbox_utxo_no_signer");
|
|
181
|
-
|
|
182
|
-
const feeRate = rest.feeRate || (await getFeeRates())[feeOptionKey];
|
|
183
|
-
|
|
184
|
-
const buildTxParams: UTXOBuildTxParams = {
|
|
185
|
-
...rest,
|
|
186
|
-
assetValue,
|
|
187
|
-
feeRate,
|
|
188
|
-
recipient,
|
|
189
|
-
sender: from,
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const { psbt } = await toolbox.createTransaction(buildTxParams);
|
|
193
|
-
const signedPsbt = await signer.signTransaction(psbt);
|
|
194
|
-
signedPsbt.finalizeAllInputs();
|
|
195
|
-
const txHex = signedPsbt.extractTransaction().toHex();
|
|
196
|
-
|
|
197
|
-
return broadcastTx(txHex);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
...toolbox,
|
|
202
|
-
broadcastTx,
|
|
203
|
-
getFeeRates,
|
|
204
|
-
transfer,
|
|
205
|
-
getAddressFromKeys,
|
|
206
|
-
validateAddress: validateZcashAddress,
|
|
207
|
-
};
|
|
208
|
-
}
|
package/src/utxo/types.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GenericCreateTransactionParams,
|
|
3
|
-
GenericTransferParams,
|
|
4
|
-
Witness,
|
|
5
|
-
} from "@swapkit/helpers";
|
|
6
|
-
|
|
7
|
-
import type { UTXOScriptType } from "./helpers";
|
|
8
|
-
|
|
9
|
-
export type TransactionType = {
|
|
10
|
-
toHex(): string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type TargetOutput =
|
|
14
|
-
| { address: string; script?: Buffer; value: number }
|
|
15
|
-
| { script: Buffer; value: number };
|
|
16
|
-
|
|
17
|
-
export type UTXOType = {
|
|
18
|
-
hash: string;
|
|
19
|
-
index: number;
|
|
20
|
-
value: number;
|
|
21
|
-
txHex?: string;
|
|
22
|
-
witnessUtxo?: Witness;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type UTXOInputWithScriptType = UTXOType & { type: UTXOScriptType; address: string };
|
|
26
|
-
|
|
27
|
-
export type UTXOCalculateTxSizeParams = {
|
|
28
|
-
inputs: (UTXOInputWithScriptType | UTXOType)[];
|
|
29
|
-
outputs?: TargetOutput[];
|
|
30
|
-
feeRate: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type UTXOBuildTxParams = GenericCreateTransactionParams & { fetchTxHex?: boolean };
|
|
34
|
-
|
|
35
|
-
export type UTXOTransferParams = GenericTransferParams;
|
|
36
|
-
|
|
37
|
-
export type BchECPair = {
|
|
38
|
-
getAddress: (index?: number) => string;
|
|
39
|
-
publicKey: Buffer;
|
|
40
|
-
toWIF: () => string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type TransactionBuilderType = {
|
|
44
|
-
inputs: any[];
|
|
45
|
-
sign(
|
|
46
|
-
vin: number,
|
|
47
|
-
keyPair: BchECPair,
|
|
48
|
-
redeemScript?: Buffer,
|
|
49
|
-
hashType?: number,
|
|
50
|
-
witnessValue?: number,
|
|
51
|
-
witnessScript?: Buffer,
|
|
52
|
-
signatureAlgorithm?: string,
|
|
53
|
-
): void;
|
|
54
|
-
build(): TransactionType;
|
|
55
|
-
addOutput(addressOrScriptBuffer: string | Buffer, value: number): void;
|
|
56
|
-
addInput(txHash: string | Buffer, vout: number, sequence?: number, prevOutScript?: Buffer): void;
|
|
57
|
-
};
|