@trezor/utxo-lib
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -0,1 +1,12 @@ | ||
# 2.0.2 | ||
- refactor(utxo-lib): composeTx merge `coinselect` modules (7a8dff467) | ||
- refactor(utxo-lib): composeTx result in one place (831d31688) | ||
- refactor(utxo-lib): composeTx request validation in one place (ecb87bccd) | ||
- chore(connect): use `tslib` as dependency in all public libs (606ecc63b) | ||
- chore: update `jest` and related dependency (b8a321c83) | ||
- chore(utxo-lib): use default imports from commonjs dependencies (466e10e4c) | ||
- refactor(utxo-lib): do not use direct `typeforce` import (96d97c312) | ||
- chore(repo): update tsx (53de3e3a8) | ||
# 2.0.1 | ||
@@ -2,0 +13,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toOutputScript = exports.getAddressType = exports.fromOutputScript = exports.toBech32 = exports.toBase58Check = exports.fromBech32 = exports.fromBase58Check = void 0; | ||
const tslib_1 = require("tslib"); | ||
const bech32_1 = require("bech32"); | ||
const bs58check = require("./bs58check"); | ||
const typeforce = require("typeforce"); | ||
const bscript = require("./script"); | ||
const payments = require("./payments"); | ||
const bs58check = tslib_1.__importStar(require("./bs58check")); | ||
const bscript = tslib_1.__importStar(require("./script")); | ||
const payments = tslib_1.__importStar(require("./payments")); | ||
const networks_1 = require("./networks"); | ||
const types = require("./types"); | ||
const types = tslib_1.__importStar(require("./types")); | ||
function fromBase58Check(address, network = networks_1.bitcoin) { | ||
@@ -43,3 +43,3 @@ return bs58check.decodeAddress(address, network); | ||
function toBase58Check(hash, version, network = networks_1.bitcoin) { | ||
typeforce(types.tuple(types.Hash160bit, types.UInt16), [hash, version]); | ||
types.typeforce(types.tuple(types.Hash160bit, types.UInt16), [hash, version]); | ||
return bs58check.encodeAddress(hash, version, network); | ||
@@ -46,0 +46,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromSeed = exports.fromPublicKey = exports.fromPrivateKey = exports.fromBase58 = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const wif = require("wif"); | ||
const typeforce = require("typeforce"); | ||
const bs58check = require("./bs58check"); | ||
const crypto = require("./crypto"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const wif_1 = tslib_1.__importDefault(require("wif")); | ||
const typeforce_1 = require("./types/typeforce"); | ||
const bs58check = tslib_1.__importStar(require("./bs58check")); | ||
const crypto = tslib_1.__importStar(require("./crypto")); | ||
const networks_1 = require("./networks"); | ||
const UINT256_TYPE = typeforce.BufferN(32); | ||
const NETWORK_TYPE = typeforce.compile({ | ||
wif: typeforce.UInt8, | ||
const UINT256_TYPE = typeforce_1.typeforce.BufferN(32); | ||
const NETWORK_TYPE = typeforce_1.typeforce.compile({ | ||
wif: typeforce_1.typeforce.UInt8, | ||
bip32: { | ||
public: typeforce.UInt32, | ||
private: typeforce.UInt32, | ||
public: typeforce_1.typeforce.UInt32, | ||
private: typeforce_1.typeforce.UInt32, | ||
}, | ||
@@ -21,9 +22,9 @@ }); | ||
function BIP32Path(value) { | ||
return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null; | ||
return typeforce_1.typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null; | ||
} | ||
function UInt31(value) { | ||
return typeforce.UInt32(value) && value <= UINT31_MAX; | ||
return typeforce_1.typeforce.UInt32(value) && value <= UINT31_MAX; | ||
} | ||
function fromPrivateKeyLocal(privateKey, chainCode, network, depth, index, parentFingerprint) { | ||
typeforce({ | ||
(0, typeforce_1.typeforce)({ | ||
privateKey: UINT256_TYPE, | ||
@@ -33,3 +34,3 @@ chainCode: UINT256_TYPE, | ||
network = network || networks_1.bitcoin; | ||
if (!ecc.isPrivate(privateKey)) | ||
if (!tiny_secp256k1_1.default.isPrivate(privateKey)) | ||
throw new TypeError('Private key not in range [1, n)'); | ||
@@ -39,8 +40,8 @@ return new BIP32(privateKey, undefined, chainCode, network, depth, index, parentFingerprint); | ||
function fromPublicKeyLocal(publicKey, chainCode, network, depth, index, parentFingerprint) { | ||
typeforce({ | ||
publicKey: typeforce.BufferN(33), | ||
(0, typeforce_1.typeforce)({ | ||
publicKey: typeforce_1.typeforce.BufferN(33), | ||
chainCode: UINT256_TYPE, | ||
}, { publicKey, chainCode }); | ||
network = network || networks_1.bitcoin; | ||
if (!ecc.isPoint(publicKey)) | ||
if (!tiny_secp256k1_1.default.isPoint(publicKey)) | ||
throw new TypeError('Point is not on the curve'); | ||
@@ -58,3 +59,3 @@ return new BIP32(undefined, publicKey, chainCode, network, depth, index, parentFingerprint); | ||
this.__PARENT_FINGERPRINT = __PARENT_FINGERPRINT; | ||
typeforce(NETWORK_TYPE, network); | ||
(0, typeforce_1.typeforce)(NETWORK_TYPE, network); | ||
this.lowR = false; | ||
@@ -73,3 +74,3 @@ } | ||
if (this.__Q === undefined) | ||
this.__Q = ecc.pointFromScalar(this.__D, true); | ||
this.__Q = tiny_secp256k1_1.default.pointFromScalar(this.__D, true); | ||
return this.__Q; | ||
@@ -118,6 +119,6 @@ } | ||
throw new TypeError('Missing private key'); | ||
return wif.encode(this.network.wif, this.privateKey, true); | ||
return wif_1.default.encode(this.network.wif, this.privateKey, true); | ||
} | ||
derive(index) { | ||
typeforce(typeforce.UInt32, index); | ||
(0, typeforce_1.typeforce)(typeforce_1.typeforce.UInt32, index); | ||
const isHardened = index >= HIGHEST_BIT; | ||
@@ -139,7 +140,7 @@ const data = Buffer.allocUnsafe(37); | ||
const IR = I.subarray(32); | ||
if (!ecc.isPrivate(IL)) | ||
if (!tiny_secp256k1_1.default.isPrivate(IL)) | ||
return this.derive(index + 1); | ||
let hd; | ||
if (!this.isNeutered()) { | ||
const ki = ecc.privateAdd(this.privateKey, IL); | ||
const ki = tiny_secp256k1_1.default.privateAdd(this.privateKey, IL); | ||
if (ki == null) | ||
@@ -150,3 +151,3 @@ return this.derive(index + 1); | ||
else { | ||
const Ki = ecc.pointAddScalar(this.publicKey, IL, true); | ||
const Ki = tiny_secp256k1_1.default.pointAddScalar(this.publicKey, IL, true); | ||
if (Ki === null) | ||
@@ -159,7 +160,7 @@ return this.derive(index + 1); | ||
deriveHardened(index) { | ||
typeforce(UInt31, index); | ||
(0, typeforce_1.typeforce)(UInt31, index); | ||
return this.derive(index + HIGHEST_BIT); | ||
} | ||
derivePath(path) { | ||
typeforce(BIP32Path, path); | ||
(0, typeforce_1.typeforce)(BIP32Path, path); | ||
let splitPath = path.split('/'); | ||
@@ -187,5 +188,5 @@ if (splitPath[0] === 'm') { | ||
if (lowR === false) { | ||
return ecc.sign(hash, this.privateKey); | ||
return tiny_secp256k1_1.default.sign(hash, this.privateKey); | ||
} | ||
let sig = ecc.sign(hash, this.privateKey); | ||
let sig = tiny_secp256k1_1.default.sign(hash, this.privateKey); | ||
const extraData = Buffer.alloc(32, 0); | ||
@@ -196,3 +197,3 @@ let counter = 0; | ||
extraData.writeUIntLE(counter, 0, 6); | ||
sig = ecc.signWithEntropy(hash, this.privateKey, extraData); | ||
sig = tiny_secp256k1_1.default.signWithEntropy(hash, this.privateKey, extraData); | ||
} | ||
@@ -202,3 +203,3 @@ return sig; | ||
verify(hash, signature) { | ||
return ecc.verify(hash, this.publicKey, signature); | ||
return tiny_secp256k1_1.default.verify(hash, this.publicKey, signature); | ||
} | ||
@@ -249,3 +250,3 @@ } | ||
function fromSeed(seed, network) { | ||
typeforce(typeforce.Buffer, seed); | ||
(0, typeforce_1.typeforce)(typeforce_1.typeforce.Buffer, seed); | ||
if (seed.length < 16) | ||
@@ -252,0 +253,0 @@ throw new TypeError('Seed should be at least 128 bits'); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encodeAddress = exports.decodeAddress = exports.decode = exports.encode = exports.encodeBlake256 = exports.decodeBlake256 = exports.decodeBlake256Key = exports.decodeBlake = void 0; | ||
const tslib_1 = require("tslib"); | ||
const networks_1 = require("./networks"); | ||
const bchaddrjs = require("bchaddrjs"); | ||
const bs58 = require("bs58"); | ||
const bs58check = require("bs58check"); | ||
const bchaddrjs_1 = tslib_1.__importDefault(require("bchaddrjs")); | ||
const bs58_1 = tslib_1.__importDefault(require("bs58")); | ||
const bs58check_1 = tslib_1.__importDefault(require("bs58check")); | ||
const crypto_1 = require("./crypto"); | ||
@@ -19,3 +20,3 @@ function decodeBlake(buffer) { | ||
function decodeBlake256Key(key) { | ||
const bytes = bs58.decode(key); | ||
const bytes = bs58_1.default.decode(key); | ||
const buffer = Buffer.from(bytes); | ||
@@ -26,3 +27,3 @@ return decodeBlake(buffer); | ||
function decodeBlake256(address) { | ||
const bytes = bs58.decode(address); | ||
const bytes = bs58_1.default.decode(address); | ||
const buffer = Buffer.from(bytes); | ||
@@ -46,11 +47,11 @@ if (buffer.length !== 26) | ||
const checksum = (0, crypto_1.blake256)((0, crypto_1.blake256)(payload)).subarray(0, 4); | ||
return bs58.encode(Buffer.concat([payload, checksum])); | ||
return bs58_1.default.encode(Buffer.concat([payload, checksum])); | ||
} | ||
exports.encodeBlake256 = encodeBlake256; | ||
function encode(payload, network = networks_1.bitcoin) { | ||
return (0, networks_1.isNetworkType)('decred', network) ? encodeBlake256(payload) : bs58check.encode(payload); | ||
return (0, networks_1.isNetworkType)('decred', network) ? encodeBlake256(payload) : bs58check_1.default.encode(payload); | ||
} | ||
exports.encode = encode; | ||
function decode(payload, network = networks_1.bitcoin) { | ||
return (0, networks_1.isNetworkType)('decred', network) ? decodeBlake256(payload) : bs58check.decode(payload); | ||
return (0, networks_1.isNetworkType)('decred', network) ? decodeBlake256(payload) : bs58check_1.default.decode(payload); | ||
} | ||
@@ -61,5 +62,5 @@ exports.decode = decode; | ||
if ((0, networks_1.isNetworkType)('bitcoinCash', network)) { | ||
if (!bchaddrjs.isCashAddress(address)) | ||
if (!bchaddrjs_1.default.isCashAddress(address)) | ||
throw Error(`${address} is not a cash address`); | ||
payload = Buffer.from(bs58check.decode(bchaddrjs.toLegacyAddress(address))); | ||
payload = Buffer.from(bs58check_1.default.decode(bchaddrjs_1.default.toLegacyAddress(address))); | ||
} | ||
@@ -93,5 +94,5 @@ else { | ||
const encoded = encode(payload, network); | ||
return (0, networks_1.isNetworkType)('bitcoinCash', network) ? bchaddrjs.toCashAddress(encoded) : encoded; | ||
return (0, networks_1.isNetworkType)('bitcoinCash', network) ? bchaddrjs_1.default.toCashAddress(encoded) : encoded; | ||
} | ||
exports.encodeAddress = encodeAddress; | ||
//# sourceMappingURL=bs58check.js.map |
/// <reference types="node" /> | ||
import * as varuint from 'varuint-bitcoin'; | ||
import varuint from 'varuint-bitcoin'; | ||
export declare function verifuint(value: number, max: number): void; | ||
@@ -4,0 +4,0 @@ export declare function readUInt64LE(buffer: Buffer, offset: number): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BufferReader = exports.BufferWriter = exports.getChunkSize = exports.reverseBuffer = exports.writePushDataInt = exports.varIntSize = exports.readPushDataInt = exports.pushDataSize = exports.cloneBuffer = exports.writeVarInt = exports.readVarInt = exports.writeInt64LE = exports.writeUInt64LEasString = exports.writeUInt64LE = exports.readInt64LE = exports.readUInt64LEasString = exports.readUInt64LE = exports.verifuint = void 0; | ||
const BN = require("bn.js"); | ||
const pushdata = require("pushdata-bitcoin"); | ||
const varuint = require("varuint-bitcoin"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const pushdata_bitcoin_1 = tslib_1.__importDefault(require("pushdata-bitcoin")); | ||
const varuint_bitcoin_1 = tslib_1.__importDefault(require("varuint-bitcoin")); | ||
const int64_buffer_1 = require("int64-buffer"); | ||
const typeforce = require("typeforce"); | ||
const utils_1 = require("@trezor/utils"); | ||
const types = require("./types"); | ||
const types = tslib_1.__importStar(require("./types")); | ||
function verifuint(value, max) { | ||
@@ -38,5 +38,5 @@ if (typeof value !== 'number') | ||
const bUint = buffer.readUInt32LE(offset + 4); | ||
const m = new BN(0x100000000); | ||
const a = new BN(aUint); | ||
const b = new BN(bUint).mul(m); | ||
const m = new bn_js_1.default(0x100000000); | ||
const a = new bn_js_1.default(aUint); | ||
const b = new bn_js_1.default(bUint).mul(m); | ||
return a.add(b).toString(); | ||
@@ -79,6 +79,6 @@ } | ||
function readVarInt(buffer, offset) { | ||
const result = varuint.decode(buffer, offset); | ||
const result = varuint_bitcoin_1.default.decode(buffer, offset); | ||
return { | ||
number: result, | ||
size: varuint.decode.bytes, | ||
size: varuint_bitcoin_1.default.decode.bytes, | ||
}; | ||
@@ -88,4 +88,4 @@ } | ||
function writeVarInt(buffer, number, offset) { | ||
varuint.encode(number, buffer, offset); | ||
return varuint.encode.bytes; | ||
varuint_bitcoin_1.default.encode(number, buffer, offset); | ||
return varuint_bitcoin_1.default.encode.bytes; | ||
} | ||
@@ -99,6 +99,6 @@ exports.writeVarInt = writeVarInt; | ||
exports.cloneBuffer = cloneBuffer; | ||
exports.pushDataSize = pushdata.encodingLength; | ||
exports.readPushDataInt = pushdata.decode; | ||
exports.varIntSize = varuint.encodingLength; | ||
exports.writePushDataInt = pushdata.encode; | ||
exports.pushDataSize = pushdata_bitcoin_1.default.encodingLength; | ||
exports.readPushDataInt = pushdata_bitcoin_1.default.decode; | ||
exports.varIntSize = varuint_bitcoin_1.default.encodingLength; | ||
exports.writePushDataInt = pushdata_bitcoin_1.default.encode; | ||
exports.reverseBuffer = utils_1.bufferUtils.reverseBuffer, exports.getChunkSize = utils_1.bufferUtils.getChunkSize; | ||
@@ -109,3 +109,3 @@ class BufferWriter { | ||
this.offset = offset; | ||
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); | ||
types.typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); | ||
} | ||
@@ -134,4 +134,4 @@ writeUInt8(i) { | ||
writeVarInt(i) { | ||
varuint.encode(i, this.buffer, this.offset); | ||
this.offset += varuint.encode.bytes; | ||
varuint_bitcoin_1.default.encode(i, this.buffer, this.offset); | ||
this.offset += varuint_bitcoin_1.default.encode.bytes; | ||
} | ||
@@ -158,3 +158,3 @@ writeSlice(slice) { | ||
this.offset = offset; | ||
typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); | ||
types.typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); | ||
} | ||
@@ -197,4 +197,4 @@ readUInt8() { | ||
readVarInt() { | ||
const vi = varuint.decode(this.buffer, this.offset); | ||
this.offset += varuint.decode.bytes; | ||
const vi = varuint_bitcoin_1.default.decode(this.buffer, this.offset); | ||
this.offset += varuint_bitcoin_1.default.decode.bytes; | ||
return vi; | ||
@@ -201,0 +201,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import * as BN from 'bn.js'; | ||
import BN from 'bn.js'; | ||
import { CoinSelectPaymentType, CoinSelectAlgorithm, CoinSelectOptions, CoinSelectInput, CoinSelectOutput, CoinSelectOutputFinal } from '../types'; | ||
@@ -3,0 +3,0 @@ import { Network } from '../networks'; |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.filterCoinbase = exports.sortByScore = exports.utxoScore = exports.anyOf = exports.finalize = exports.getFee = exports.getFeePolicy = exports.sumOrNaN = exports.bignumberOrNaN = exports.getDustAmount = exports.transactionBytes = exports.transactionWeight = exports.getFeeForBytes = exports.outputBytes = exports.outputWeight = exports.inputBytes = exports.inputWeight = exports.getVarIntSize = exports.OUTPUT_SCRIPT_LENGTH = exports.INPUT_SCRIPT_LENGTH = exports.ZERO = void 0; | ||
const BN = require("bn.js"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const networks_1 = require("../networks"); | ||
exports.ZERO = new BN(0); | ||
exports.ZERO = new bn_js_1.default(0); | ||
exports.INPUT_SCRIPT_LENGTH = { | ||
@@ -110,3 +100,3 @@ p2pkh: 108, | ||
function bignumberOrNaN(v, forgiving = false) { | ||
if (BN.isBN(v)) | ||
if (bn_js_1.default.isBN(v)) | ||
return v; | ||
@@ -117,3 +107,3 @@ const defaultValue = forgiving ? exports.ZERO : undefined; | ||
try { | ||
return new BN(v); | ||
return new bn_js_1.default(v); | ||
} | ||
@@ -154,6 +144,6 @@ catch (error) { | ||
function getDogeFee(inputs, outputs, feeRate, _a) { | ||
var { dustThreshold = 0 } = _a, options = __rest(_a, ["dustThreshold"]); | ||
var { dustThreshold = 0 } = _a, options = tslib_1.__rest(_a, ["dustThreshold"]); | ||
const fee = getBitcoinFee(inputs, outputs, feeRate, options); | ||
const limit = new BN(dustThreshold); | ||
const dustOutputsCount = outputs.filter(({ value }) => value && new BN(value).lt(limit)).length; | ||
const limit = new bn_js_1.default(dustThreshold); | ||
const dustOutputsCount = outputs.filter(({ value }) => value && new bn_js_1.default(value).lt(limit)).length; | ||
return fee + dustOutputsCount * dustThreshold; | ||
@@ -173,3 +163,3 @@ } | ||
function getFee(inputs, outputs, feeRate, _a = {}) { | ||
var { feePolicy } = _a, options = __rest(_a, ["feePolicy"]); | ||
var { feePolicy } = _a, options = tslib_1.__rest(_a, ["feePolicy"]); | ||
switch (feePolicy) { | ||
@@ -193,6 +183,6 @@ case 'doge': | ||
const sumOutputs = sumOrNaN(outputs); | ||
if (!sumInputs || !sumOutputs || sumInputs.sub(sumOutputs).lt(new BN(fee))) { | ||
if (!sumInputs || !sumOutputs || sumInputs.sub(sumOutputs).lt(new bn_js_1.default(fee))) { | ||
return { fee }; | ||
} | ||
const remainderAfterExtraOutput = sumInputs.sub(sumOutputs.add(new BN(feeAfterExtraOutput))); | ||
const remainderAfterExtraOutput = sumInputs.sub(sumOutputs.add(new bn_js_1.default(feeAfterExtraOutput))); | ||
const dustAmount = getDustAmount(feeRate, options); | ||
@@ -202,3 +192,3 @@ const finalOutputs = outputs.map(o => Object.assign({}, o, { | ||
})); | ||
if (remainderAfterExtraOutput.gte(new BN(dustAmount))) { | ||
if (remainderAfterExtraOutput.gte(new bn_js_1.default(dustAmount))) { | ||
finalOutputs.push(Object.assign(Object.assign({}, changeOutput), { value: remainderAfterExtraOutput.toString() })); | ||
@@ -228,3 +218,3 @@ } | ||
function utxoScore(x, feeRate) { | ||
return new BN(x.value).sub(new BN(getFeeForBytes(feeRate, inputBytes(x)))); | ||
return new bn_js_1.default(x.value).sub(new bn_js_1.default(getFeeForBytes(feeRate, inputBytes(x)))); | ||
} | ||
@@ -231,0 +221,0 @@ exports.utxoScore = utxoScore; |
@@ -1,3 +0,3 @@ | ||
import { CoinSelectInput, CoinSelectOutput, CoinSelectOptions } from '../types'; | ||
export declare function coinselect(inputs: CoinSelectInput[], outputs: CoinSelectOutput[], feeRate: number, options: CoinSelectOptions): import("../types").CoinSelectResult; | ||
import { CoinSelectRequest } from '../types'; | ||
export declare function coinselect({ inputs, outputs, feeRate, ...options }: CoinSelectRequest): import("../types").CoinSelectResult; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.coinselect = void 0; | ||
const tslib_1 = require("tslib"); | ||
const accumulative_1 = require("./inputs/accumulative"); | ||
const bnb_1 = require("./inputs/bnb"); | ||
const split_1 = require("./outputs/split"); | ||
const coinselectUtils_1 = require("./coinselectUtils"); | ||
const tryconfirmed_1 = require("./tryconfirmed"); | ||
function coinselect(inputs, outputs, feeRate, options) { | ||
function coinselect(_a) { | ||
var { inputs, outputs, feeRate } = _a, options = tslib_1.__rest(_a, ["inputs", "outputs", "feeRate"]); | ||
if (options.sendMaxOutputIndex >= 0) { | ||
return (0, split_1.split)(inputs, outputs, feeRate, options); | ||
} | ||
const sortedInputs = options.skipPermutation ? inputs : inputs.sort((0, coinselectUtils_1.sortByScore)(feeRate)); | ||
@@ -10,0 +16,0 @@ const algorithm = (0, tryconfirmed_1.tryConfirmed)((0, coinselectUtils_1.anyOf)([bnb_1.bnb, accumulative_1.accumulative]), options); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.accumulative = void 0; | ||
const BN = require("bn.js"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const coinselectUtils_1 = require("../coinselectUtils"); | ||
@@ -34,3 +35,3 @@ function accumulative(utxos0, outputs, feeRate, options) { | ||
const utxoValue = (0, coinselectUtils_1.bignumberOrNaN)(utxo.value); | ||
if (!utxoValue || utxoValue.lt(new BN(utxoFee))) { | ||
if (!utxoValue || utxoValue.lt(new bn_js_1.default(utxoFee))) { | ||
if (i === utxos.length - 1) { | ||
@@ -45,3 +46,3 @@ const fee = (0, coinselectUtils_1.getFee)([...inputs, utxo], outputs, feeRate, options); | ||
const fee = (0, coinselectUtils_1.getFee)(inputs, outputs, feeRate, options); | ||
const outAccumWithFee = outAccum ? outAccum.add(new BN(fee)) : coinselectUtils_1.ZERO; | ||
const outAccumWithFee = outAccum ? outAccum.add(new bn_js_1.default(fee)) : coinselectUtils_1.ZERO; | ||
if (inAccum.gte(outAccumWithFee)) { | ||
@@ -48,0 +49,0 @@ return (0, coinselectUtils_1.finalize)(inputs, outputs, feeRate, options); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bnb = void 0; | ||
const BN = require("bn.js"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const coinselectUtils_1 = require("../coinselectUtils"); | ||
@@ -17,3 +18,3 @@ const MAX_TRIES = 1000000; | ||
const effectiveFee = (0, coinselectUtils_1.getFeeForBytes)(feeRate, (0, coinselectUtils_1.inputBytes)(utxo)); | ||
const effectiveValue = value.sub(new BN(effectiveFee)); | ||
const effectiveValue = value.sub(new bn_js_1.default(effectiveFee)); | ||
return { | ||
@@ -95,4 +96,4 @@ utxo, | ||
return { fee: 0 }; | ||
const target = outputsTotalValue.add(new BN(outputsFee)); | ||
const targetRange = target.add(new BN(costOfChange)); | ||
const target = outputsTotalValue.add(new bn_js_1.default(outputsFee)); | ||
const targetRange = target.add(new bn_js_1.default(costOfChange)); | ||
const effectiveUtxos = calculateEffectiveValues(utxos, feeRate) | ||
@@ -99,0 +100,0 @@ .filter(({ effectiveValue }) => effectiveValue.gt(coinselectUtils_1.ZERO) && effectiveValue.lte(targetRange)) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.split = void 0; | ||
const BN = require("bn.js"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const coinselectUtils_1 = require("../coinselectUtils"); | ||
@@ -16,3 +17,3 @@ function split(utxosOrig, outputs, feeRate, options) { | ||
return { fee }; | ||
const remaining = inAccum.sub(outAccum).sub(new BN(fee)); | ||
const remaining = inAccum.sub(outAccum).sub(new bn_js_1.default(fee)); | ||
if (remaining.lt(coinselectUtils_1.ZERO)) | ||
@@ -24,5 +25,5 @@ return { fee }; | ||
} | ||
const splitValue = remaining.div(new BN(unspecified)); | ||
const splitValue = remaining.div(new bn_js_1.default(unspecified)); | ||
const dustAmount = (0, coinselectUtils_1.getDustAmount)(feeRate, options); | ||
if (unspecified && splitValue.lt(new BN(dustAmount))) | ||
if (unspecified && splitValue.lt(new bn_js_1.default(dustAmount))) | ||
return { fee }; | ||
@@ -29,0 +30,0 @@ const outputsSplit = outputs.map(x => { |
@@ -30,7 +30,2 @@ "use strict"; | ||
return (utxosO, outputs, feeRate, optionsIn) => { | ||
utxosO.forEach(utxo => { | ||
if (utxo.coinbase == null || utxo.own == null || utxo.confirmations == null) { | ||
throw new Error('Missing information.'); | ||
} | ||
}); | ||
const utxos = (0, coinselectUtils_1.filterCoinbase)(utxosO, coinbase); | ||
@@ -37,0 +32,0 @@ if (utxos.length === 0) { |
@@ -6,26 +6,11 @@ "use strict"; | ||
const result_1 = require("./result"); | ||
const composeUtils_1 = require("./composeUtils"); | ||
const coinselect_1 = require("./coinselect"); | ||
const coinselect_1 = require("../coinselect"); | ||
function composeTx(request) { | ||
const { utxos, outputs, feeRate, longTermFeeRate } = request; | ||
if (outputs.length === 0) { | ||
return { type: 'error', error: 'MISSING-OUTPUTS' }; | ||
const coinselectRequest = (0, request_1.validateAndParseRequest)(request); | ||
if ('error' in coinselectRequest) { | ||
return coinselectRequest; | ||
} | ||
if (utxos.length === 0) { | ||
return { type: 'error', error: 'MISSING-UTXOS' }; | ||
} | ||
const feeRateNumber = (0, composeUtils_1.convertFeeRate)(feeRate); | ||
if (!feeRateNumber) { | ||
return { type: 'error', error: 'INCORRECT-FEE-RATE' }; | ||
} | ||
let longTermFeeRateNumber; | ||
if (longTermFeeRate) { | ||
longTermFeeRateNumber = (0, composeUtils_1.convertFeeRate)(longTermFeeRate); | ||
if (!longTermFeeRateNumber) { | ||
return { type: 'error', error: 'INCORRECT-FEE-RATE' }; | ||
} | ||
} | ||
let countMax = { exists: false, id: 0 }; | ||
try { | ||
countMax = (0, request_1.getMax)(outputs); | ||
const result = (0, coinselect_1.coinselect)(coinselectRequest); | ||
return (0, result_1.getResult)(request, coinselectRequest, result); | ||
} | ||
@@ -35,15 +20,4 @@ catch (error) { | ||
} | ||
let result = { success: false }; | ||
try { | ||
result = (0, coinselect_1.coinselect)(request.txType || 'p2pkh', utxos, outputs, request.changeAddress, feeRateNumber, longTermFeeRateNumber, countMax.exists, countMax.id, request.dustThreshold, request.network, request.baseFee, request.floorBaseFee, request.skipPermutation); | ||
} | ||
catch (error) { | ||
return (0, result_1.getErrorResult)(error); | ||
} | ||
if (!result.success) { | ||
return { type: 'error', error: 'NOT-ENOUGH-FUNDS' }; | ||
} | ||
return (0, result_1.getResult)(request, result); | ||
} | ||
exports.composeTx = composeTx; | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,5 @@ | ||
import { ComposeOutput } from '../types'; | ||
export declare function getMax(outputs: ComposeOutput[]): { | ||
id: number; | ||
exists: boolean; | ||
}; | ||
import type { ComposeInput, ComposeOutput, ComposeChangeAddress, ComposeRequest, ComposeResultError, CoinSelectRequest } from '../types'; | ||
type Request = ComposeRequest<ComposeInput, ComposeOutput, ComposeChangeAddress>; | ||
export declare function validateAndParseRequest(request: Request): CoinSelectRequest | ComposeResultError; | ||
export {}; | ||
//# sourceMappingURL=request.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getMax = void 0; | ||
function getMax(outputs) { | ||
const countMaxRequests = outputs.filter(output => output.type === 'send-max-noaddress' || output.type === 'send-max'); | ||
if (countMaxRequests.length >= 2) { | ||
throw new Error('TWO-SEND-MAX'); | ||
exports.validateAndParseRequest = void 0; | ||
const address_1 = require("../address"); | ||
const embed_1 = require("../payments/embed"); | ||
const coinselectUtils_1 = require("../coinselect/coinselectUtils"); | ||
function validateAndParseFeeRate(rate) { | ||
const feeRate = typeof rate === 'string' ? Number(rate) : rate; | ||
if (typeof feeRate !== 'number' || | ||
Number.isNaN(feeRate) || | ||
!Number.isFinite(feeRate) || | ||
feeRate > Number.MAX_SAFE_INTEGER || | ||
feeRate <= 0) { | ||
return; | ||
} | ||
const id = outputs.findIndex(output => output.type === 'send-max-noaddress' || output.type === 'send-max'); | ||
const exists = countMaxRequests.length === 1; | ||
return feeRate; | ||
} | ||
function transformInput(i, utxo, txType) { | ||
if (typeof utxo.coinbase !== 'boolean') { | ||
throw new Error('Missing coinbase'); | ||
} | ||
if (typeof utxo.own !== 'boolean') { | ||
throw new Error('Missing own'); | ||
} | ||
if (typeof utxo.confirmations !== 'number') { | ||
throw new Error('Missing confirmations'); | ||
} | ||
if (typeof utxo.amount !== 'string') { | ||
throw new Error('Missing amount'); | ||
} | ||
return Object.assign(Object.assign({}, utxo), { type: txType, i, script: { length: coinselectUtils_1.INPUT_SCRIPT_LENGTH[txType] }, value: utxo.amount }); | ||
} | ||
function validateAndParseUtxos(txType, { utxos }) { | ||
if (utxos.length === 0) { | ||
return { type: 'error', error: 'MISSING-UTXOS' }; | ||
} | ||
const incorrectUtxoError = (index, message) => ({ | ||
type: 'error', | ||
error: 'INCORRECT-UTXO', | ||
message: `${message} at index ${index}`, | ||
}); | ||
const result = []; | ||
for (let i = 0; i < utxos.length; i++) { | ||
try { | ||
const csInput = transformInput(i, utxos[i], txType); | ||
csInput.weight = (0, coinselectUtils_1.inputWeight)(csInput); | ||
result.push(csInput); | ||
} | ||
catch (error) { | ||
return incorrectUtxoError(i, error.message); | ||
} | ||
} | ||
return result; | ||
} | ||
function transformOutput(output, txType, network) { | ||
const script = { length: coinselectUtils_1.OUTPUT_SCRIPT_LENGTH[txType] }; | ||
if (output.type === 'payment') { | ||
return { | ||
value: output.amount, | ||
script: (0, address_1.toOutputScript)(output.address, network), | ||
}; | ||
} | ||
if (output.type === 'payment-noaddress') { | ||
return { | ||
value: output.amount, | ||
script, | ||
}; | ||
} | ||
if (output.type === 'opreturn') { | ||
return { | ||
value: '0', | ||
script: (0, embed_1.p2data)({ data: [Buffer.from(output.dataHex, 'hex')] }).output, | ||
}; | ||
} | ||
if (output.type === 'send-max') { | ||
return { | ||
script: (0, address_1.toOutputScript)(output.address, network), | ||
}; | ||
} | ||
if (output.type === 'send-max-noaddress') { | ||
return { | ||
script, | ||
}; | ||
} | ||
throw new Error('Unknown output type'); | ||
} | ||
function validateAndParseOutputs(txType, { outputs, network }) { | ||
if (outputs.length === 0) { | ||
return { type: 'error', error: 'MISSING-OUTPUTS' }; | ||
} | ||
const incorrectOutputError = (index, message) => ({ | ||
type: 'error', | ||
error: 'INCORRECT-OUTPUT', | ||
message: `${message} at index ${index}`, | ||
}); | ||
let sendMaxOutputIndex = -1; | ||
const result = []; | ||
for (let i = 0; i < outputs.length; i++) { | ||
const output = outputs[i]; | ||
if (output.type === 'send-max-noaddress' || output.type === 'send-max') { | ||
if (sendMaxOutputIndex >= 0) { | ||
return incorrectOutputError(i, 'Multiple send-max'); | ||
} | ||
sendMaxOutputIndex = i; | ||
} | ||
if ((output.type === 'payment' || output.type === 'payment-noaddress') && | ||
typeof output.amount !== 'string') { | ||
return incorrectOutputError(i, 'Missing output amount'); | ||
} | ||
try { | ||
const csOutput = transformOutput(output, txType, network); | ||
csOutput.weight = (0, coinselectUtils_1.outputWeight)(csOutput); | ||
result.push(csOutput); | ||
} | ||
catch (error) { | ||
return incorrectOutputError(i, error.message); | ||
} | ||
} | ||
return { | ||
id, | ||
exists, | ||
outputs: result, | ||
sendMaxOutputIndex, | ||
}; | ||
} | ||
exports.getMax = getMax; | ||
function validateAndParseChangeOutput(txType, { changeAddress, network }) { | ||
try { | ||
return transformOutput(Object.assign({ type: 'send-max' }, changeAddress), txType, network); | ||
} | ||
catch (error) { | ||
return { | ||
type: 'error', | ||
error: 'INCORRECT-OUTPUT', | ||
message: error.message, | ||
}; | ||
} | ||
} | ||
function validateAndParseRequest(request) { | ||
const feeRate = validateAndParseFeeRate(request.feeRate); | ||
if (!feeRate) { | ||
return { type: 'error', error: 'INCORRECT-FEE-RATE' }; | ||
} | ||
const longTermFeeRate = validateAndParseFeeRate(request.longTermFeeRate); | ||
if (request.longTermFeeRate != null && !longTermFeeRate) { | ||
return { type: 'error', error: 'INCORRECT-FEE-RATE' }; | ||
} | ||
const txType = request.txType || 'p2pkh'; | ||
const inputs = validateAndParseUtxos(txType, request); | ||
if ('error' in inputs) { | ||
return inputs; | ||
} | ||
const outputs = validateAndParseOutputs(txType, request); | ||
if ('error' in outputs) { | ||
return outputs; | ||
} | ||
const changeOutput = validateAndParseChangeOutput(txType, request); | ||
if ('error' in changeOutput) { | ||
return changeOutput; | ||
} | ||
const feePolicy = (0, coinselectUtils_1.getFeePolicy)(request.network); | ||
return Object.assign(Object.assign({ txType, | ||
inputs }, outputs), { changeOutput, | ||
feeRate, | ||
feePolicy, | ||
longTermFeeRate, dustThreshold: request.dustThreshold, baseFee: request.baseFee, floorBaseFee: request.floorBaseFee, skipPermutation: request.skipPermutation }); | ||
} | ||
exports.validateAndParseRequest = validateAndParseRequest; | ||
//# sourceMappingURL=request.js.map |
@@ -1,4 +0,4 @@ | ||
import { CoinSelectSuccess, ComposeRequest, ComposeInput, ComposeOutput, ComposeChangeAddress, ComposeResultError, ComposeResultNonFinal, ComposeResultFinal } from '../types'; | ||
import { CoinSelectRequest, CoinSelectResult, ComposeRequest, ComposeInput, ComposeOutput, ComposeChangeAddress, ComposeResult, ComposeResultError } from '../types'; | ||
export declare function getErrorResult(error: unknown): ComposeResultError; | ||
export declare function getResult<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress>(request: ComposeRequest<Input, Output, Change>, result: CoinSelectSuccess): ComposeResultNonFinal<Input> | ComposeResultFinal<Input, Output, Change>; | ||
export declare function getResult<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress>(request: ComposeRequest<Input, Output, Change>, { sendMaxOutputIndex }: CoinSelectRequest, result: CoinSelectResult): ComposeResult<Input, Output, Change>; | ||
//# sourceMappingURL=result.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getResult = exports.getErrorResult = void 0; | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
const coinselectUtils_1 = require("../coinselect/coinselectUtils"); | ||
const transaction_1 = require("./transaction"); | ||
@@ -15,21 +18,2 @@ const types_1 = require("../types"); | ||
exports.getErrorResult = getErrorResult; | ||
function getNonfinalResult(utxos, result) { | ||
const { max, fee, feePerByte, bytes, totalSpent } = result.payload; | ||
const inputs = result.payload.inputs.map(input => utxos[input.i]); | ||
return { | ||
type: 'nonfinal', | ||
fee: fee.toString(), | ||
feePerByte: feePerByte.toString(), | ||
bytes, | ||
max, | ||
totalSpent, | ||
inputs, | ||
}; | ||
} | ||
function getFinalResult(result, transaction) { | ||
const { max, fee, feePerByte, bytes, totalSpent } = result.payload; | ||
return Object.assign({ type: 'final', fee: fee.toString(), feePerByte: feePerByte.toString(), bytes, | ||
max, | ||
totalSpent }, transaction); | ||
} | ||
function splitByCompleteness(outputs) { | ||
@@ -51,11 +35,33 @@ const complete = []; | ||
} | ||
function getResult(request, result) { | ||
const splitOutputs = splitByCompleteness(request.outputs); | ||
if (splitOutputs.incomplete.length > 0) { | ||
return getNonfinalResult(request.utxos, result); | ||
function getResult(request, { sendMaxOutputIndex }, result) { | ||
if (!result.inputs || !result.outputs) { | ||
return { type: 'error', error: 'NOT-ENOUGH-FUNDS' }; | ||
} | ||
const transaction = (0, transaction_1.createTransaction)(request.utxos, result.payload.inputs, splitOutputs.complete, result.payload.outputs, request.changeAddress, request.skipPermutation); | ||
return getFinalResult(result, transaction); | ||
const totalSpent = result.outputs.reduce((total, output, index) => { | ||
if (request.outputs[index]) { | ||
return total.add(new bn_js_1.default(output.value)); | ||
} | ||
return total; | ||
}, new bn_js_1.default(result.fee)); | ||
const max = sendMaxOutputIndex >= 0 ? result.outputs[sendMaxOutputIndex].value : undefined; | ||
const bytes = (0, coinselectUtils_1.transactionBytes)(result.inputs, result.outputs); | ||
const feePerByte = result.fee / bytes; | ||
const { complete, incomplete } = splitByCompleteness(request.outputs); | ||
if (incomplete.length > 0) { | ||
const inputs = result.inputs.map(input => request.utxos[input.i]); | ||
return { | ||
type: 'nonfinal', | ||
fee: result.fee.toString(), | ||
feePerByte: feePerByte.toString(), | ||
bytes, | ||
max, | ||
totalSpent: totalSpent.toString(), | ||
inputs, | ||
}; | ||
} | ||
const transaction = (0, transaction_1.createTransaction)(Object.assign(Object.assign({}, request), { outputs: complete }), result); | ||
return Object.assign({ type: 'final', fee: result.fee.toString(), feePerByte: feePerByte.toString(), bytes, | ||
max, totalSpent: totalSpent.toString() }, transaction); | ||
} | ||
exports.getResult = getResult; | ||
//# sourceMappingURL=result.js.map |
@@ -1,3 +0,3 @@ | ||
import { ComposeInput, ComposeChangeAddress, ComposeFinalOutput, ComposedTransaction, CoinSelectInput, CoinSelectOutputFinal } from '../types'; | ||
export declare function createTransaction<Input extends ComposeInput, Change extends ComposeChangeAddress>(allInputs: Input[], selectedInputs: CoinSelectInput[], allOutputs: ComposeFinalOutput[], selectedOutputs: CoinSelectOutputFinal[], changeAddress: Change, skipPermutation?: boolean): ComposedTransaction<Input, ComposeFinalOutput, Change>; | ||
import { ComposeRequest, CoinSelectSuccess, ComposeInput, ComposeChangeAddress, ComposeFinalOutput, ComposedTransaction } from '../types'; | ||
export declare function createTransaction<Input extends ComposeInput, Change extends ComposeChangeAddress>(request: ComposeRequest<Input, ComposeFinalOutput, Change>, result: CoinSelectSuccess): ComposedTransaction<Input, ComposeFinalOutput, Change>; | ||
//# sourceMappingURL=transaction.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTransaction = void 0; | ||
const BN = require("bn.js"); | ||
const tslib_1 = require("tslib"); | ||
const bn_js_1 = tslib_1.__importDefault(require("bn.js")); | ||
function convertOutput(selectedOutput, composeOutput) { | ||
@@ -18,3 +19,3 @@ if (composeOutput.type === 'change') { | ||
function outputComparator(a, b) { | ||
return (new BN(a.value).cmp(new BN(b.value)) || | ||
return (new bn_js_1.default(a.value).cmp(new bn_js_1.default(b.value)) || | ||
(Buffer.isBuffer(a.script) && Buffer.isBuffer(b.script) | ||
@@ -24,7 +25,13 @@ ? a.script.compare(b.script) | ||
} | ||
function createTransaction(allInputs, selectedInputs, allOutputs, selectedOutputs, changeAddress, skipPermutation) { | ||
const convertedInputs = selectedInputs.map(input => allInputs[input.i]); | ||
const convertedOutputs = selectedOutputs.map((output, index) => convertOutput(output, allOutputs[index] || Object.assign({ type: 'change' }, changeAddress))); | ||
const defaultPermutation = convertedOutputs.map((_, index) => index); | ||
if (skipPermutation) { | ||
function createTransaction(request, result) { | ||
const convertedInputs = result.inputs.map(input => request.utxos[input.i]); | ||
const defaultPermutation = []; | ||
const convertedOutputs = result.outputs.map((output, index) => { | ||
defaultPermutation.push(index); | ||
if (request.outputs[index]) { | ||
return convertOutput(output, request.outputs[index]); | ||
} | ||
return convertOutput(output, Object.assign({ type: 'change' }, request.changeAddress)); | ||
}); | ||
if (request.skipPermutation) { | ||
return { | ||
@@ -36,3 +43,3 @@ inputs: convertedInputs, | ||
} | ||
const permutation = defaultPermutation.sort((a, b) => outputComparator(selectedOutputs[a], selectedOutputs[b])); | ||
const permutation = defaultPermutation.sort((a, b) => outputComparator(result.outputs[a], result.outputs[b])); | ||
const sortedOutputs = permutation.map(index => convertedOutputs[index]); | ||
@@ -39,0 +46,0 @@ return { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hmacSHA512 = exports.hash256 = exports.hash160blake256 = exports.hash160 = exports.blake256 = exports.sha256 = exports.sha1 = exports.ripemd160 = void 0; | ||
const blakeHash = require("blake-hash"); | ||
const createHash = require("create-hash"); | ||
const createHmac = require("create-hmac"); | ||
const tslib_1 = require("tslib"); | ||
const blake_hash_1 = tslib_1.__importDefault(require("blake-hash")); | ||
const create_hash_1 = tslib_1.__importDefault(require("create-hash")); | ||
const create_hmac_1 = tslib_1.__importDefault(require("create-hmac")); | ||
function ripemd160(buffer) { | ||
try { | ||
return createHash('rmd160').update(buffer).digest(); | ||
return (0, create_hash_1.default)('rmd160').update(buffer).digest(); | ||
} | ||
catch (err) { | ||
return createHash('ripemd160').update(buffer).digest(); | ||
return (0, create_hash_1.default)('ripemd160').update(buffer).digest(); | ||
} | ||
@@ -17,11 +18,11 @@ } | ||
function sha1(buffer) { | ||
return createHash('sha1').update(buffer).digest(); | ||
return (0, create_hash_1.default)('sha1').update(buffer).digest(); | ||
} | ||
exports.sha1 = sha1; | ||
function sha256(buffer) { | ||
return createHash('sha256').update(buffer).digest(); | ||
return (0, create_hash_1.default)('sha256').update(buffer).digest(); | ||
} | ||
exports.sha256 = sha256; | ||
function blake256(buffer) { | ||
return blakeHash('blake256').update(buffer).digest(); | ||
return (0, blake_hash_1.default)('blake256').update(buffer).digest(); | ||
} | ||
@@ -42,5 +43,5 @@ exports.blake256 = blake256; | ||
function hmacSHA512(key, data) { | ||
return createHmac('sha512', key).update(data).digest(); | ||
return (0, create_hmac_1.default)('sha512', key).update(data).digest(); | ||
} | ||
exports.hmacSHA512 = hmacSHA512; | ||
//# sourceMappingURL=crypto.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.discovery = exports.countUnusedFromEnd = void 0; | ||
const tslib_1 = require("tslib"); | ||
const derivation_1 = require("./derivation"); | ||
@@ -26,3 +18,3 @@ const DISCOVERY_LOOKOUT = 20; | ||
const discovery = (discover, xpub, type, network, lookout = DISCOVERY_LOOKOUT) => { | ||
const discoverRecursive = (from, prev) => __awaiter(void 0, void 0, void 0, function* () { | ||
const discoverRecursive = (from, prev) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const unused = (0, exports.countUnusedFromEnd)(prev, a => a.empty, lookout); | ||
@@ -29,0 +21,0 @@ if (unused >= lookout) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.discovery = exports.getXpubOrDescriptorInfo = exports.deriveAddresses = exports.composeTx = exports.networks = exports.script = exports.payments = exports.crypto = exports.bufferutils = exports.bip32 = exports.address = exports.Transaction = void 0; | ||
const address = require("./address"); | ||
const tslib_1 = require("tslib"); | ||
const address = tslib_1.__importStar(require("./address")); | ||
exports.address = address; | ||
const bip32 = require("./bip32"); | ||
const bip32 = tslib_1.__importStar(require("./bip32")); | ||
exports.bip32 = bip32; | ||
const bufferutils = require("./bufferutils"); | ||
const bufferutils = tslib_1.__importStar(require("./bufferutils")); | ||
exports.bufferutils = bufferutils; | ||
const crypto = require("./crypto"); | ||
const crypto = tslib_1.__importStar(require("./crypto")); | ||
exports.crypto = crypto; | ||
const payments = require("./payments"); | ||
const payments = tslib_1.__importStar(require("./payments")); | ||
exports.payments = payments; | ||
const script = require("./script"); | ||
const script = tslib_1.__importStar(require("./script")); | ||
exports.script = script; | ||
const networks = require("./networks"); | ||
const networks = tslib_1.__importStar(require("./networks")); | ||
exports.networks = networks; | ||
@@ -18,0 +19,0 @@ const compose_1 = require("./compose"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNetworkType = exports.doge = exports.decredSim = exports.decredTest = exports.decred = exports.komodo = exports.peercoinTest = exports.peercoin = exports.zcashTest = exports.zcash = exports.dashTest = exports.dash = exports.litecoinTest = exports.litecoin = exports.bitcoingold = exports.bitcoincashTest = exports.bitcoincash = exports.testnet = exports.regtest = exports.bitcoin = void 0; | ||
const typeforce = require("typeforce"); | ||
const typeforce_1 = require("./types/typeforce"); | ||
exports.bitcoin = { | ||
@@ -230,9 +230,9 @@ messagePrefix: '\x18Bitcoin Signed Message:\n', | ||
try { | ||
typeforce({ | ||
(0, typeforce_1.typeforce)({ | ||
bip32: { | ||
public: typeforce.UInt32, | ||
private: typeforce.UInt32, | ||
public: typeforce_1.typeforce.UInt32, | ||
private: typeforce_1.typeforce.UInt32, | ||
}, | ||
pubKeyHash: typeforce.anyOf(typeforce.UInt8, typeforce.UInt16), | ||
scriptHash: typeforce.anyOf(typeforce.UInt8, typeforce.UInt16), | ||
pubKeyHash: typeforce_1.typeforce.anyOf(typeforce_1.typeforce.UInt8, typeforce_1.typeforce.UInt16), | ||
scriptHash: typeforce_1.typeforce.anyOf(typeforce_1.typeforce.UInt8, typeforce_1.typeforce.UInt16), | ||
}, network); | ||
@@ -239,0 +239,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2data = void 0; | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -18,6 +19,6 @@ function stacksEqual(a, b) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
output: typef.maybe(typef.Buffer), | ||
data: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
data: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}, a); | ||
@@ -41,3 +42,3 @@ const network = a.network || networks_1.bitcoin; | ||
throw new TypeError('Output is invalid'); | ||
if (!chunks.slice(1).every(typef.Buffer)) | ||
if (!chunks.slice(1).every(types_1.typeforce.Buffer)) | ||
throw new TypeError('Output is invalid'); | ||
@@ -44,0 +45,0 @@ if (a.data && !stacksEqual(a.data, o.data)) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2ms = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -24,10 +25,10 @@ const OP_INT_BASE = OPS.OP_RESERVED; | ||
} | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
m: typef.maybe(typef.Number), | ||
n: typef.maybe(typef.Number), | ||
output: typef.maybe(typef.Buffer), | ||
pubkeys: typef.maybe(typef.arrayOf(ecc.isPoint)), | ||
signatures: typef.maybe(typef.arrayOf(isAcceptableSignature)), | ||
input: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
m: types_1.typeforce.maybe(types_1.typeforce.Number), | ||
n: types_1.typeforce.maybe(types_1.typeforce.Number), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
pubkeys: types_1.typeforce.maybe(types_1.typeforce.arrayOf(tiny_secp256k1_1.default.isPoint)), | ||
signatures: types_1.typeforce.maybe(types_1.typeforce.arrayOf(isAcceptableSignature)), | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -96,5 +97,5 @@ const network = a.network || networks_1.bitcoin; | ||
decode(a.output); | ||
if (!typef.Number(chunks[0])) | ||
if (!types_1.typeforce.Number(chunks[0])) | ||
throw new TypeError('Output is invalid'); | ||
if (!typef.Number(chunks[chunks.length - 2])) | ||
if (!types_1.typeforce.Number(chunks[chunks.length - 2])) | ||
throw new TypeError('Output is invalid'); | ||
@@ -105,3 +106,3 @@ if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) | ||
throw new TypeError('Output is invalid'); | ||
if (!o.pubkeys.every(x => ecc.isPoint(x))) | ||
if (!o.pubkeys.every(x => tiny_secp256k1_1.default.isPoint(x))) | ||
throw new TypeError('Output is invalid'); | ||
@@ -108,0 +109,0 @@ if (a.m !== undefined && a.m !== o.m) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2pk = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -14,8 +15,8 @@ function p2pk(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
output: typef.maybe(typef.Buffer), | ||
pubkey: typef.maybe(ecc.isPoint), | ||
signature: typef.maybe(bscript.isCanonicalScriptSignature), | ||
input: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
pubkey: types_1.typeforce.maybe(tiny_secp256k1_1.default.isPoint), | ||
signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -54,3 +55,3 @@ const _chunks = lazy.value(() => bscript.decompile(a.input)); | ||
throw new TypeError('Output is invalid'); | ||
if (!ecc.isPoint(o.pubkey)) | ||
if (!tiny_secp256k1_1.default.isPoint(o.pubkey)) | ||
throw new TypeError('Output pubkey is invalid'); | ||
@@ -57,0 +58,0 @@ if (a.pubkey && !a.pubkey.equals(o.pubkey)) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2pkh = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const bs58check = require("../bs58check"); | ||
const bcrypto = require("../crypto"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -16,10 +17,10 @@ function p2pkh(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
output: typef.maybe(typef.BufferN(25)), | ||
pubkey: typef.maybe(ecc.isPoint), | ||
signature: typef.maybe(bscript.isCanonicalScriptSignature), | ||
input: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(25)), | ||
pubkey: types_1.typeforce.maybe(tiny_secp256k1_1.default.isPoint), | ||
signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -119,3 +120,3 @@ const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network)); | ||
throw new TypeError('Input has invalid signature'); | ||
if (!ecc.isPoint(chunks[1])) | ||
if (!tiny_secp256k1_1.default.isPoint(chunks[1])) | ||
throw new TypeError('Input has invalid pubkey'); | ||
@@ -122,0 +123,0 @@ if (a.signature && !a.signature.equals(chunks[0])) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2sh = void 0; | ||
const typef = require("typeforce"); | ||
const bs58check = require("../bs58check"); | ||
const bcrypto = require("../crypto"); | ||
const tslib_1 = require("tslib"); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -20,15 +21,15 @@ function stacksEqual(a, b) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
output: typef.maybe(typef.BufferN(23)), | ||
redeem: typef.maybe({ | ||
network: typef.maybe(typef.Object), | ||
output: typef.maybe(typef.Buffer), | ||
input: typef.maybe(typef.Buffer), | ||
witness: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(23)), | ||
redeem: types_1.typeforce.maybe({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}), | ||
input: typef.maybe(typef.Buffer), | ||
witness: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}, a); | ||
@@ -35,0 +36,0 @@ let { network } = a; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2tr = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const bech32_1 = require("bech32"); | ||
const networks_1 = require("../networks"); | ||
const bcrypto = require("../crypto"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -30,3 +31,3 @@ const TAGS = ['TapLeaf', 'TapBranch', 'TapTweak', 'KeyAgg list', 'KeyAgg coefficient']; | ||
} | ||
const tweakedPubkey = ecc.pointAddScalar(Buffer.concat([EVEN_Y_COORD_PREFIX, pubkey]), tapTweak); | ||
const tweakedPubkey = tiny_secp256k1_1.default.pointAddScalar(Buffer.concat([EVEN_Y_COORD_PREFIX, pubkey]), tapTweak); | ||
return { | ||
@@ -47,7 +48,7 @@ parity: tweakedPubkey[0] === EVEN_Y_COORD_PREFIX[0] ? 0 : 1, | ||
const o = { name: 'p2tr', network }; | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
output: typef.maybe(typef.BufferN(34)), | ||
pubkey: typef.maybe(typef.anyOf(typef.BufferN(32), typef.BufferN(33))), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(34)), | ||
pubkey: types_1.typeforce.maybe(types_1.typeforce.anyOf(types_1.typeforce.BufferN(32), types_1.typeforce.BufferN(33))), | ||
}, a); | ||
@@ -118,3 +119,3 @@ const _address = lazy.value(() => { | ||
hash = pkh; | ||
if (!ecc.isPoint(Buffer.concat([EVEN_Y_COORD_PREFIX, liftX(a.pubkey)]))) | ||
if (!tiny_secp256k1_1.default.isPoint(Buffer.concat([EVEN_Y_COORD_PREFIX, liftX(a.pubkey)]))) | ||
throw new TypeError('Invalid pubkey for p2tr'); | ||
@@ -121,0 +122,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2wpkh = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const bech32_1 = require("bech32"); | ||
const bcrypto = require("../crypto"); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const types_1 = require("../types"); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const { OPS } = bscript; | ||
@@ -17,11 +18,11 @@ const EMPTY_BUFFER = Buffer.alloc(0); | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
input: typef.maybe(typef.BufferN(0)), | ||
network: typef.maybe(typef.Object), | ||
output: typef.maybe(typef.BufferN(22)), | ||
pubkey: typef.maybe(ecc.isPoint), | ||
signature: typef.maybe(bscript.isCanonicalScriptSignature), | ||
witness: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
(0, types_1.typeforce)({ | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)), | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(22)), | ||
pubkey: types_1.typeforce.maybe(tiny_secp256k1_1.default.isPoint), | ||
signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), | ||
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}, a); | ||
@@ -116,3 +117,3 @@ const _address = lazy.value(() => { | ||
hash = pkh; | ||
if (!ecc.isPoint(a.pubkey) || a.pubkey.length !== 33) | ||
if (!tiny_secp256k1_1.default.isPoint(a.pubkey) || a.pubkey.length !== 33) | ||
throw new TypeError('Invalid pubkey for p2wpkh'); | ||
@@ -125,3 +126,3 @@ } | ||
throw new TypeError('Witness has invalid signature'); | ||
if (!ecc.isPoint(a.witness[1]) || a.witness[1].length !== 33) | ||
if (!tiny_secp256k1_1.default.isPoint(a.witness[1]) || a.witness[1].length !== 33) | ||
throw new TypeError('Witness has invalid pubkey'); | ||
@@ -128,0 +129,0 @@ if (a.signature && !a.signature.equals(a.witness[0])) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.p2wsh = void 0; | ||
const ecc = require("tiny-secp256k1"); | ||
const typef = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const bech32_1 = require("bech32"); | ||
const bcrypto = require("../crypto"); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -19,3 +20,3 @@ const EMPTY_BUFFER = Buffer.alloc(0); | ||
function chunkHasUncompressedPubkey(chunk) { | ||
if (Buffer.isBuffer(chunk) && chunk.length === 65 && chunk[0] === 0x04 && ecc.isPoint(chunk)) { | ||
if (Buffer.isBuffer(chunk) && chunk.length === 65 && chunk[0] === 0x04 && tiny_secp256k1_1.default.isPoint(chunk)) { | ||
return true; | ||
@@ -29,15 +30,15 @@ } | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(32)), | ||
output: typef.maybe(typef.BufferN(34)), | ||
redeem: typef.maybe({ | ||
input: typef.maybe(typef.Buffer), | ||
network: typef.maybe(typef.Object), | ||
output: typef.maybe(typef.Buffer), | ||
witness: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(34)), | ||
redeem: types_1.typeforce.maybe({ | ||
input: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}), | ||
input: typef.maybe(typef.BufferN(0)), | ||
witness: typef.maybe(typef.arrayOf(typef.Buffer)), | ||
input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)), | ||
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)), | ||
}, a); | ||
@@ -44,0 +45,0 @@ const _address = lazy.value(() => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sstxchange = void 0; | ||
const typef = require("typeforce"); | ||
const bs58check = require("../bs58check"); | ||
const tslib_1 = require("tslib"); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -14,7 +15,7 @@ function sstxchange(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
output: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -21,0 +22,0 @@ const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sstxcommitment = void 0; | ||
const typeforce = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const bufferutils_1 = require("../bufferutils"); | ||
const bs58check = require("../bs58check"); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -15,8 +16,8 @@ function sstxcommitment(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typeforce({ | ||
network: typeforce.maybe(typeforce.Object), | ||
address: typeforce.maybe(typeforce.String), | ||
amount: typeforce.maybe(typeforce.String), | ||
hash: typeforce.maybe(typeforce.BufferN(20)), | ||
output: typeforce.maybe(typeforce.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
amount: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -23,0 +24,0 @@ const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sstxpkh = void 0; | ||
const typef = require("typeforce"); | ||
const bs58check = require("../bs58check"); | ||
const tslib_1 = require("tslib"); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -14,7 +15,7 @@ function sstxpkh(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
output: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -21,0 +22,0 @@ const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sstxsh = void 0; | ||
const typef = require("typeforce"); | ||
const bs58check = require("../bs58check"); | ||
const tslib_1 = require("tslib"); | ||
const bs58check = tslib_1.__importStar(require("../bs58check")); | ||
const networks_1 = require("../networks"); | ||
const bscript = require("../script"); | ||
const lazy = require("./lazy"); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const lazy = tslib_1.__importStar(require("./lazy")); | ||
const types_1 = require("../types"); | ||
const { OPS } = bscript; | ||
@@ -14,7 +15,7 @@ function sstxsh(a, opts) { | ||
opts = Object.assign({ validate: true }, opts || {}); | ||
typef({ | ||
network: typef.maybe(typef.Object), | ||
address: typef.maybe(typef.String), | ||
hash: typef.maybe(typef.BufferN(20)), | ||
output: typef.maybe(typef.Buffer), | ||
(0, types_1.typeforce)({ | ||
network: types_1.typeforce.maybe(types_1.typeforce.Object), | ||
address: types_1.typeforce.maybe(types_1.typeforce.String), | ||
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), | ||
output: types_1.typeforce.maybe(types_1.typeforce.Buffer), | ||
}, a); | ||
@@ -21,0 +22,0 @@ const network = a.network || networks_1.decred; |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import * as types from '../types'; | ||
import type { Stack } from '../types'; | ||
import { Stack } from '../types'; | ||
export declare function isPushOnly(value: Stack): boolean; | ||
@@ -8,0 +8,0 @@ export declare function compile(chunks: Buffer | Stack): Buffer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OPS = exports.signature = exports.number = exports.isCanonicalScriptSignature = exports.isDefinedHashType = exports.isCanonicalPubKey = exports.toStack = exports.fromASM = exports.toASM = exports.decompile = exports.compile = exports.isPushOnly = void 0; | ||
const bip66 = require("bip66"); | ||
const pushdata = require("pushdata-bitcoin"); | ||
const typeforce = require("typeforce"); | ||
const ecc = require("tiny-secp256k1"); | ||
const scriptNumber = require("./scriptNumber"); | ||
const scriptSignature = require("./scriptSignature"); | ||
const tslib_1 = require("tslib"); | ||
const bip66_1 = tslib_1.__importDefault(require("bip66")); | ||
const pushdata_bitcoin_1 = tslib_1.__importDefault(require("pushdata-bitcoin")); | ||
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1")); | ||
const scriptNumber = tslib_1.__importStar(require("./scriptNumber")); | ||
const scriptSignature = tslib_1.__importStar(require("./scriptSignature")); | ||
const ops_1 = require("./ops"); | ||
const types = require("../types"); | ||
const types = tslib_1.__importStar(require("../types")); | ||
const types_1 = require("../types"); | ||
const OP_INT_BASE = ops_1.OPS.OP_RESERVED; | ||
@@ -39,3 +40,3 @@ function isOPInt(value) { | ||
return chunks; | ||
typeforce(types.Array, chunks); | ||
(0, types_1.typeforce)(types.Array, chunks); | ||
const bufferSize = chunks.reduce((accum, chunk) => { | ||
@@ -46,3 +47,3 @@ if (types.Buffer(chunk)) { | ||
} | ||
return accum + pushdata.encodingLength(chunk.length) + chunk.length; | ||
return accum + pushdata_bitcoin_1.default.encodingLength(chunk.length) + chunk.length; | ||
} | ||
@@ -61,3 +62,3 @@ return accum + 1; | ||
} | ||
offset += pushdata.encode(buffer, chunk.length, offset); | ||
offset += pushdata_bitcoin_1.default.encode(buffer, chunk.length, offset); | ||
chunk.copy(buffer, offset); | ||
@@ -79,3 +80,3 @@ offset += chunk.length; | ||
return buffer; | ||
typeforce(types.Buffer, buffer); | ||
(0, types_1.typeforce)(types.Buffer, buffer); | ||
const chunks = []; | ||
@@ -86,3 +87,3 @@ let i = 0; | ||
if (opcode > ops_1.OPS.OP_0 && opcode <= ops_1.OPS.OP_PUSHDATA4) { | ||
const d = pushdata.decode(buffer, i); | ||
const d = pushdata_bitcoin_1.default.decode(buffer, i); | ||
if (d === null) | ||
@@ -129,7 +130,7 @@ return []; | ||
function fromASM(asm) { | ||
typeforce(types.String, asm); | ||
(0, types_1.typeforce)(types.String, asm); | ||
return compile(asm.split(' ').map(chunkStr => { | ||
if (ops_1.OPS[chunkStr] !== undefined) | ||
return ops_1.OPS[chunkStr]; | ||
typeforce(types.Hex, chunkStr); | ||
(0, types_1.typeforce)(types.Hex, chunkStr); | ||
return Buffer.from(chunkStr, 'hex'); | ||
@@ -141,3 +142,3 @@ })); | ||
const chunks = decompile(chunks0); | ||
typeforce(isPushOnly, chunks); | ||
(0, types_1.typeforce)(isPushOnly, chunks); | ||
return chunks === null || chunks === void 0 ? void 0 : chunks.map(op => { | ||
@@ -153,3 +154,3 @@ if (types.Buffer(op)) | ||
function isCanonicalPubKey(buffer) { | ||
return ecc.isPoint(buffer); | ||
return tiny_secp256k1_1.default.isPoint(buffer); | ||
} | ||
@@ -167,3 +168,3 @@ exports.isCanonicalPubKey = isCanonicalPubKey; | ||
return false; | ||
return bip66.check(buffer.subarray(0, -1)); | ||
return bip66_1.default.check(buffer.subarray(0, -1)); | ||
} | ||
@@ -170,0 +171,0 @@ exports.isCanonicalScriptSignature = isCanonicalScriptSignature; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.REVERSE_OPS = exports.OPS = void 0; | ||
const ops = require("bitcoin-ops"); | ||
const tslib_1 = require("tslib"); | ||
const ops = tslib_1.__importStar(require("bitcoin-ops")); | ||
const OPS = Object.assign({ | ||
@@ -6,0 +7,0 @@ OP_SSTX: 0xba, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encode = exports.decode = exports.fromDER = exports.toDER = void 0; | ||
const bip66 = require("bip66"); | ||
const typeforce = require("typeforce"); | ||
const types = require("../types"); | ||
const tslib_1 = require("tslib"); | ||
const bip66_1 = tslib_1.__importDefault(require("bip66")); | ||
const types = tslib_1.__importStar(require("../types")); | ||
const ZERO = Buffer.alloc(1, 0); | ||
@@ -34,3 +34,3 @@ function toDER(x) { | ||
throw new Error(`Invalid hashType ${hashType}`); | ||
const decoded = bip66.decode(buffer.subarray(0, -1)); | ||
const decoded = bip66_1.default.decode(buffer.subarray(0, -1)); | ||
const r = fromDER(decoded.r); | ||
@@ -43,3 +43,3 @@ const s = fromDER(decoded.s); | ||
function encode(signature, hashType) { | ||
typeforce({ | ||
types.typeforce({ | ||
signature: types.BufferN(64), | ||
@@ -55,5 +55,5 @@ hashType: types.UInt8, | ||
const s = toDER(signature.subarray(32, 64)); | ||
return Buffer.concat([bip66.encode(r, s), hashTypeBuffer]); | ||
return Buffer.concat([bip66_1.default.encode(r, s), hashTypeBuffer]); | ||
} | ||
exports.encode = encode; | ||
//# sourceMappingURL=scriptSignature.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TransactionBase = exports.EMPTY_SCRIPT = exports.isCoinbaseHash = exports.vectorSize = exports.varSliceSize = void 0; | ||
const varuint = require("varuint-bitcoin"); | ||
const typeforce = require("typeforce"); | ||
const tslib_1 = require("tslib"); | ||
const varuint_bitcoin_1 = tslib_1.__importDefault(require("varuint-bitcoin")); | ||
const bufferutils_1 = require("../bufferutils"); | ||
const bcrypto = require("../crypto"); | ||
const types = require("../types"); | ||
const bscript = require("../script"); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const types = tslib_1.__importStar(require("../types")); | ||
const bscript = tslib_1.__importStar(require("../script")); | ||
const networks_1 = require("../networks"); | ||
function varSliceSize(someScript) { | ||
const { length } = someScript; | ||
return varuint.encodingLength(length) + length; | ||
return varuint_bitcoin_1.default.encodingLength(length) + length; | ||
} | ||
exports.varSliceSize = varSliceSize; | ||
function vectorSize(someVector) { | ||
return (varuint.encodingLength(someVector.length) + | ||
return (varuint_bitcoin_1.default.encodingLength(someVector.length) + | ||
someVector.reduce((sum, witness) => sum + varSliceSize(witness), 0)); | ||
@@ -22,3 +22,3 @@ } | ||
function isCoinbaseHash(buffer) { | ||
typeforce(types.Hash256bit, buffer); | ||
types.typeforce(types.Hash256bit, buffer); | ||
for (let i = 0; i < 32; ++i) { | ||
@@ -69,4 +69,4 @@ if (buffer[i] !== 0) | ||
(this.timestamp ? 4 : 0) + | ||
varuint.encodingLength(this.ins.length) + | ||
varuint.encodingLength(this.outs.length) + | ||
varuint_bitcoin_1.default.encodingLength(this.ins.length) + | ||
varuint_bitcoin_1.default.encodingLength(this.outs.length) + | ||
this.ins.reduce((sum, input) => sum + 40 + varSliceSize(input.script), 0) + | ||
@@ -73,0 +73,0 @@ this.outs.reduce((sum, output) => sum + 8 + varSliceSize(output.script), 0) + |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromBuffer = exports.fromConstructor = void 0; | ||
const varuint = require("varuint-bitcoin"); | ||
const tslib_1 = require("tslib"); | ||
const varuint_bitcoin_1 = tslib_1.__importDefault(require("varuint-bitcoin")); | ||
const bufferutils_1 = require("../bufferutils"); | ||
@@ -14,4 +15,4 @@ const base_1 = require("./base"); | ||
(tx.timestamp ? 4 : 0) + | ||
varuint.encodingLength(tx.ins.length) + | ||
varuint.encodingLength(tx.outs.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.ins.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.outs.length) + | ||
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) + | ||
@@ -57,3 +58,3 @@ tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) + | ||
return; | ||
const extraDataLength = varuint.encode(tx.specific.extraPayload.length); | ||
const extraDataLength = varuint_bitcoin_1.default.encode(tx.specific.extraPayload.length); | ||
return Buffer.concat([extraDataLength, tx.specific.extraPayload]); | ||
@@ -60,0 +61,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromBuffer = exports.fromConstructor = void 0; | ||
const varuint = require("varuint-bitcoin"); | ||
const tslib_1 = require("tslib"); | ||
const varuint_bitcoin_1 = tslib_1.__importDefault(require("varuint-bitcoin")); | ||
const bufferutils_1 = require("../bufferutils"); | ||
const bcrypto = require("../crypto"); | ||
const bcrypto = tslib_1.__importStar(require("../crypto")); | ||
const base_1 = require("./base"); | ||
@@ -16,3 +17,3 @@ const DECRED_TX_VERSION = 1; | ||
function byteLength(tx, _ALLOW_WITNESS = true) { | ||
let byteLength = 4 + varuint.encodingLength(tx.ins.length); | ||
let byteLength = 4 + varuint_bitcoin_1.default.encodingLength(tx.ins.length); | ||
let nWitness = 0; | ||
@@ -30,5 +31,5 @@ const hasWitnesses = _ALLOW_WITNESS && tx.hasWitnesses(); | ||
if (hasWitnesses) { | ||
byteLength += varuint.encodingLength(nWitness); | ||
byteLength += varuint_bitcoin_1.default.encodingLength(nWitness); | ||
} | ||
byteLength += varuint.encodingLength(tx.outs.length); | ||
byteLength += varuint_bitcoin_1.default.encodingLength(tx.outs.length); | ||
byteLength += tx.outs.reduce((sum, output) => { | ||
@@ -35,0 +36,0 @@ sum += 8 + 2; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Transaction = void 0; | ||
const tslib_1 = require("tslib"); | ||
const networks_1 = require("../networks"); | ||
const base_1 = require("./base"); | ||
const bitcoin = require("./bitcoin"); | ||
const dash = require("./dash"); | ||
const decred = require("./decred"); | ||
const peercoin = require("./peercoin"); | ||
const zcash = require("./zcash"); | ||
const bitcoin = tslib_1.__importStar(require("./bitcoin")); | ||
const dash = tslib_1.__importStar(require("./dash")); | ||
const decred = tslib_1.__importStar(require("./decred")); | ||
const peercoin = tslib_1.__importStar(require("./peercoin")); | ||
const zcash = tslib_1.__importStar(require("./zcash")); | ||
class Transaction extends base_1.TransactionBase { | ||
@@ -12,0 +13,0 @@ constructor(options = {}) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromBuffer = exports.fromConstructor = void 0; | ||
const varuint = require("varuint-bitcoin"); | ||
const tslib_1 = require("tslib"); | ||
const varuint_bitcoin_1 = tslib_1.__importDefault(require("varuint-bitcoin")); | ||
const blakejs_1 = require("blakejs"); | ||
@@ -37,5 +38,5 @@ const bufferutils_1 = require("../bufferutils"); | ||
? 8 + | ||
varuint.encodingLength(txSpecific.vShieldedSpend.length) + | ||
varuint_bitcoin_1.default.encodingLength(txSpecific.vShieldedSpend.length) + | ||
384 * txSpecific.vShieldedSpend.length + | ||
varuint.encodingLength(txSpecific.vShieldedOutput.length) + | ||
varuint_bitcoin_1.default.encodingLength(txSpecific.vShieldedOutput.length) + | ||
948 * txSpecific.vShieldedOutput.length + | ||
@@ -51,4 +52,4 @@ (txSpecific.vShieldedSpend.length + txSpecific.vShieldedOutput.length > 0 ? 64 : 0) | ||
return (4 + | ||
varuint.encodingLength(tx.ins.length) + | ||
varuint.encodingLength(tx.outs.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.ins.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.outs.length) + | ||
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) + | ||
@@ -190,4 +191,4 @@ tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) + | ||
(tx.version >= ZCASH_OVERWINTER_VERSION ? 8 : 0) + | ||
varuint.encodingLength(tx.ins.length) + | ||
varuint.encodingLength(tx.outs.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.ins.length) + | ||
varuint_bitcoin_1.default.encodingLength(tx.outs.length) + | ||
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) + | ||
@@ -194,0 +195,0 @@ tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) + |
@@ -41,27 +41,20 @@ export type CoinSelectPaymentType = 'p2pkh' | 'p2sh' | 'p2tr' | 'p2wpkh' | 'p2wsh'; | ||
} | ||
export type CoinSelectResult = { | ||
export interface CoinSelectRequest extends CoinSelectOptions { | ||
inputs: CoinSelectInput[]; | ||
outputs: CoinSelectOutput[]; | ||
sendMaxOutputIndex: number; | ||
feeRate: number; | ||
} | ||
export type CoinSelectAlgorithm = (inputs: CoinSelectInput[], outputs: CoinSelectOutput[], feeRate: number, options: CoinSelectOptions) => CoinSelectResult; | ||
export interface CoinSelectSuccess { | ||
fee: number; | ||
inputs?: typeof undefined; | ||
outputs?: typeof undefined; | ||
} | { | ||
fee: number; | ||
inputs: CoinSelectInput[]; | ||
outputs: CoinSelectOutputFinal[]; | ||
}; | ||
export type CoinSelectAlgorithm = (inputs: CoinSelectInput[], outputs: CoinSelectOutput[], feeRate: number, options: CoinSelectOptions) => CoinSelectResult; | ||
export interface CoinSelectSuccess { | ||
success: true; | ||
payload: { | ||
inputs: CoinSelectInput[]; | ||
outputs: CoinSelectOutputFinal[]; | ||
max?: string; | ||
totalSpent: string; | ||
fee: number; | ||
feePerByte: number; | ||
bytes: number; | ||
}; | ||
} | ||
export interface CoinSelectFailure { | ||
success: false; | ||
fee: number; | ||
inputs?: typeof undefined; | ||
outputs?: typeof undefined; | ||
} | ||
export type CoinSelectResult = CoinSelectSuccess | CoinSelectFailure; | ||
//# sourceMappingURL=coinselect.d.ts.map |
@@ -66,3 +66,3 @@ import type { Network } from '../networks'; | ||
} | ||
export declare const COMPOSE_ERROR_TYPES: readonly ["MISSING-UTXOS", "MISSING-OUTPUTS", "INCORRECT-OUTPUT-TYPE", "INCORRECT-FEE-RATE", "TWO-SEND-MAX", "NOT-ENOUGH-FUNDS"]; | ||
export declare const COMPOSE_ERROR_TYPES: readonly ["MISSING-UTXOS", "MISSING-OUTPUTS", "INCORRECT-FEE-RATE", "NOT-ENOUGH-FUNDS"]; | ||
export type ComposeResultError = { | ||
@@ -73,3 +73,3 @@ type: 'error'; | ||
type: 'error'; | ||
error: 'COINSELECT'; | ||
error: 'INCORRECT-UTXO' | 'INCORRECT-OUTPUT' | 'COINSELECT'; | ||
message: string; | ||
@@ -76,0 +76,0 @@ }; |
@@ -7,7 +7,5 @@ "use strict"; | ||
'MISSING-OUTPUTS', | ||
'INCORRECT-OUTPUT-TYPE', | ||
'INCORRECT-FEE-RATE', | ||
'TWO-SEND-MAX', | ||
'NOT-ENOUGH-FUNDS', | ||
]; | ||
//# sourceMappingURL=compose.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./coinselect"), exports); | ||
__exportStar(require("./compose"), exports); | ||
__exportStar(require("./payments"), exports); | ||
__exportStar(require("./typeforce"), exports); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./coinselect"), exports); | ||
tslib_1.__exportStar(require("./compose"), exports); | ||
tslib_1.__exportStar(require("./payments"), exports); | ||
tslib_1.__exportStar(require("./typeforce"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,2 +1,4 @@ | ||
/// <reference path="../../src/global.d.ts" /> | ||
/// <reference types="node" /> | ||
import typeforce from 'typeforce'; | ||
export declare function Satoshi(value: number): boolean; | ||
@@ -7,2 +9,3 @@ export declare const Buffer256bit: (value: any) => value is Buffer; | ||
export declare const Number: (value: any) => value is number, Array: (value: any) => value is any[], Boolean: (value: any) => value is boolean, String: (value: any) => value is string, Buffer: (value: any) => value is Buffer, Hex: (value: any) => value is string, maybe: (type: any) => boolean, tuple: (...args: any[]) => boolean, UInt8: (value: any) => value is number, UInt16: (value: any) => value is number, UInt32: (value: any) => value is number, Function: (value: any) => value is FunctionConstructor, BufferN: (length: number) => (value: any) => value is Buffer, Nil: (value: any) => boolean, anyOf: (...args: any[]) => (value: any) => boolean; | ||
export { typeforce }; | ||
//# sourceMappingURL=typeforce.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.anyOf = exports.Nil = exports.BufferN = exports.Function = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.tuple = exports.maybe = exports.Hex = exports.Buffer = exports.String = exports.Boolean = exports.Array = exports.Number = exports.Hash256bit = exports.Hash160bit = exports.Buffer256bit = exports.Satoshi = void 0; | ||
const typeforce = require("typeforce"); | ||
exports.typeforce = exports.anyOf = exports.Nil = exports.BufferN = exports.Function = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.tuple = exports.maybe = exports.Hex = exports.Buffer = exports.String = exports.Boolean = exports.Array = exports.Number = exports.Hash256bit = exports.Hash160bit = exports.Buffer256bit = exports.Satoshi = void 0; | ||
const tslib_1 = require("tslib"); | ||
const typeforce_1 = tslib_1.__importDefault(require("typeforce")); | ||
exports.typeforce = typeforce_1.default; | ||
const SATOSHI_MAX = 21 * 1e14; | ||
function Satoshi(value) { | ||
return typeforce.UInt53(value) && value <= SATOSHI_MAX; | ||
return typeforce_1.default.UInt53(value) && value <= SATOSHI_MAX; | ||
} | ||
exports.Satoshi = Satoshi; | ||
exports.Buffer256bit = typeforce.BufferN(32); | ||
exports.Hash160bit = typeforce.BufferN(20); | ||
exports.Hash256bit = typeforce.BufferN(32); | ||
exports.Number = typeforce.Number, exports.Array = typeforce.Array, exports.Boolean = typeforce.Boolean, exports.String = typeforce.String, exports.Buffer = typeforce.Buffer, exports.Hex = typeforce.Hex, exports.maybe = typeforce.maybe, exports.tuple = typeforce.tuple, exports.UInt8 = typeforce.UInt8, exports.UInt16 = typeforce.UInt16, exports.UInt32 = typeforce.UInt32, exports.Function = typeforce.Function, exports.BufferN = typeforce.BufferN, exports.Nil = typeforce.Nil, exports.anyOf = typeforce.anyOf; | ||
exports.Buffer256bit = typeforce_1.default.BufferN(32); | ||
exports.Hash160bit = typeforce_1.default.BufferN(20); | ||
exports.Hash256bit = typeforce_1.default.BufferN(32); | ||
exports.Number = typeforce_1.default.Number, exports.Array = typeforce_1.default.Array, exports.Boolean = typeforce_1.default.Boolean, exports.String = typeforce_1.default.String, exports.Buffer = typeforce_1.default.Buffer, exports.Hex = typeforce_1.default.Hex, exports.maybe = typeforce_1.default.maybe, exports.tuple = typeforce_1.default.tuple, exports.UInt8 = typeforce_1.default.UInt8, exports.UInt16 = typeforce_1.default.UInt16, exports.UInt32 = typeforce_1.default.UInt32, exports.Function = typeforce_1.default.Function, exports.BufferN = typeforce_1.default.BufferN, exports.Nil = typeforce_1.default.Nil, exports.anyOf = typeforce_1.default.anyOf; | ||
//# sourceMappingURL=typeforce.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTransactionVbytes = exports.getTransactionVbytesFromAddresses = void 0; | ||
const BitcoinJsAddress = require("./address"); | ||
const tslib_1 = require("tslib"); | ||
const BitcoinJsAddress = tslib_1.__importStar(require("./address")); | ||
const coinselectUtils_1 = require("./coinselect/coinselectUtils"); | ||
@@ -6,0 +7,0 @@ const address_1 = require("./address"); |
{ | ||
"name": "@trezor/utxo-lib", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Trezor <info@trezor.io>", | ||
@@ -39,3 +39,3 @@ "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/utxo-lib", | ||
"dependencies": { | ||
"@trezor/utils": "9.0.15", | ||
"@trezor/utils": "9.0.16", | ||
"bchaddrjs": "^0.5.2", | ||
@@ -66,8 +66,11 @@ "bech32": "^2.0.0", | ||
"@types/wif": "^2.0.4", | ||
"jest": "^26.6.3", | ||
"jest": "29.5.0", | ||
"minimaldata": "^1.0.2", | ||
"rimraf": "^5.0.5", | ||
"tsx": "^3.14.0", | ||
"tsx": "^4.6.2", | ||
"typescript": "5.3.2" | ||
}, | ||
"peerDependencies": { | ||
"tslib": "^2.6.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
230005
19
104
5546
+ Added@trezor/utils@9.0.16(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@trezor/utils@9.0.15(transitive)
Updated@trezor/utils@9.0.16