bitgo / bitgo-utxo-lib Goto Github PK
View Code? Open in Web Editor NEWUTXO coins functions implemented in pure JavaScript
UTXO coins functions implemented in pure JavaScript
Hi all,
Is anybody able please to provide a code example of what is required to;
(a) generate a ZEC z-addr (HDNode-derived) keyPair (my current t-addr code is below for reference)
const entropySha256 = utils.sha256_shex(entropySeed)
var root = bitgoUtxoLib.HDNode.fromSeedHex(entropySha256, network) // bitgo HDNode
...
const path = `m/44'/${meta.bip44_index}'/${accountNdx}'/${chainNdx}/${i}`
const child = root.derivePath(path)
var keyPair = child.keyPair // bitgo
var wif = keyPair.toWIF()
(b) build a ZEC t->z (and/or z->z, z->t) transaction? (again, current t->t transparent tx code is below for reference)
const txb = new bitgoUtxoLib.TransactionBuilder(network)
txb.setVersion(bitgoUtxoLib.Transaction.ZCASH_SAPLING_VERSION) // sapling: v4
txb.setVersionGroupId(2301567109) // sapling
txb.setExpiryHeight(0)
for (var i = 0; i < res.inputs.length; i++) {
txb.addInput(res.inputs[i].utxo.txid, res.inputs[i].utxo.vout)
}
res.outputs.forEach(output => {
txb.addOutput(output.address, output.value)
})
for (var i = 0; i < res.inputs.length; i++) {
var wif = addrPrivKeys.find(p => { return p.addr === res.inputs[i].utxo.address }).privKey
var keyPair = bitgoUtxoLib.ECPair.fromWIF(wif, network)
txb.sign(i, keyPair, '', bitgoUtxoLib.Transaction.SIGHASH_SINGLE, res.inputs[i].utxo.satoshis)
}
...
I'm unclear what additional ZPK proof generation needs to happen, how to do it if so, or if this is already supported internally in some way (it isn't evident to me that it does). Any inputs or assistance are greatly appreciated!
Thank you,
D.
Following README instruction for TypeScript:
$ yarn add --dev @types/bitgo-utxo-lib
yarn add v1.16.0
[1/5] Validating package.json...
[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.npmjs.org/@types%2fbitgo-utxo-lib: Not found".
info If you think this is a bug, please open a bug report with the information provided in "yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Hello,
I'm trying to sign a Bitcoin Cash transaction using sighash type
Transaction.SIGHASH_BITCOINCASHBIP143 = 0x40
but this results in the following error
[2019-03-07T17:57:52.111Z] Error: Invalid hashType 64 at ECSignature.toScriptSignature (/app/node_modules/bitgo-utxo-lib/src/ecsignature.js:89:51) at /app/node_modules/bitgo-utxo-lib/src/transaction_builder.js:829:37 at Array.some (<anonymous>) at TransactionBuilder.sign (/app/node_modules/bitgo-utxo-lib/src/transaction_builder.js:818:30) at TxBuilder.build (/app/node_modules/utxo/lib/TxBuilder.js:102:15)
In ecsignature.js line 89
ECSignature.prototype.toScriptSignature = function (hashType) {
var hashTypeMod = hashType & ~0xc0
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType)
...
the check fails because hashTypeMod evaluates to zero.
Does the library support Bitcoin Cash signatures yet?
Transaction.prototype.__toBuffer
creates a buffer bigger than expected which we end up slicing.
We are doing some miscalculation somewhere, we shouldn't have to slice the final buffer.
See 7707109#commitcomment-36629702 :
This will work for now, but it's not the ideal way to code this. In general you're assuming that the consensus branch ID is determined by the transaction version, which will cause a problem for any upgrade that doesn't change the tx version (as Blossom didn't). Furthermore there could be multiple tx versions valid at the same time, but the consensus branch ID changes at the upgrade regardless of which tx version is actually used.
I'm unable to send transaction having below error
"message": "Cannot send transaction: absurdly-high-fee, 89560829 > 10000000 (code 256)",
var txb = new litecoin.TransactionBuilder(litecoin.networks.litecoin,1500);
var keyPair = litecoin.ECPair.fromWIF(this.privateKey, litecoin.networks.litecoin);
txb.addInput("d73cc49b9a8de4d66e4d767cacc0800b7d99ad009cdbfb62881258475a022350", 0);
txb.addOutput(toAddress, amountInSatoshi);
let a = amountInSatoshi + 1500
txb.sign(0, keyPair, '', litecoin.Transaction.SIGHASH_SINGLE,a);
console.log(txb);
const txSerial = txb.build().toHex()
We just pushed out PSBT support, and are moving to remove TransactionBuilder and the templates folder completely (replaced by the payments module).
Also we have TypeScript support, which looks like it would work well with your BitgoJS/core module using TypeScript.
Feel free to ask me any questions here or on keybase (I have it linked with my Github) if you have any questions.
Payments and PSBT are an extremely powerful combination.
Have a look at the integration tests we have for PSBT:
bitcoinjs/bitcoinjs-lib : test/integration/transactions-psbt
p2sh and p2wsh payments can be nested in a loop, (see the helper function for the above integration test)
The method
fromBase58()
can take an array of network objects, but when it does that, it just pops the last one, in this case, thelitecointest
one.
Originally posted by @argjv in #35 (comment)
Instead it should be picking the correct network by some sort of identifier.
Hello, I want to add a time field when I generate the transaction signature. The present object structure is:
function Transaction () {
this.version = 1
this.locktime = 0
this.ins = []
this.outs = []
}
Hello,
I'm trying to generate a coinbase (Zcash Sapling) transaction but I get a coinbase inputs not supported
error.
Is there a way to generate coinbase transactions with this library?
Thanks
It would be nice to pull these parameters out of prova and into bitgo-utxo-lib. For reference:
(prova-lib/src/networks.js)
module.exports = {
rmg: {
messagePrefix: '\x18RMG Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4
},
rmg: 0x33, // starts with G
wif: 0x80
},
rmgTest: {
messagePrefix: '\x18RMG Test Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4
},
rmg: 0x58, // starts with T
wif: 0x80
},
litecoinTest: {
magic: 0xd9b4bef9,
messagePrefix: '\x19Litecoin Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4
},
pubKeyHash: 0x6f,
scriptHash: 0x3a,
wif: 0xb0,
dustThreshold: 0, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L360-L365
dustSoftThreshold: 100000, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.h#L53
feePerKb: 100000 // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L56
}
};
Also, I'm not sure why litecoinTest is there, but I noted that it's missing from bitgo-utxo-lib as well and should probably be added.
Hey guys,
Your library is really nice with good test coverage and we will probably use it. I just have one question. If we add support for big numbers (e.g. https://github.com/MikeMcl/bignumber.js) will you accept it? Do you even care about supporting new coins? I just wanted to ask first, so we don't waste the time.
Thank you!
When trying to sign a Zcash transaction using tx.sign, I'm getting "Expected property "2" of type Satoshi, got undefined" error.
const balance = calculateBalanceFromUtxos(utxos);
const tx = new zcore.TransactionBuilder(networkProtocol);
let nInputs = 0;
let availableSatoshis = 0;
for (let i = 0; i < utxos.length; i += 1) {
const utxo = utxos[i];
tx.addInput(utxo.txId, utxo.outputIndex);
availableSatoshis += utxo.satoshis;
nInputs += 1;
if (availableSatoshis >= amountSatoshis) break;
}
const change = availableSatoshis - amountSatoshis;
const fees = calculateFee(nInputs, change > 0 ? 2 : 1);
if (balance < amountSatoshis + fees) {
throw new Error('Insufficient balance to broadcast transaction');
}
tx.addOutput(recipientAddress, amountSatoshis - fees);
if (change > 0) tx.addOutput(senderAddress, change);
for (let i = 0; i < nInputs; i += 1) {
tx.sign(i, keyPair);
}
const msg = tx.build().toHex();
`
const bitcore = require("bitcore-lib-zcash");
const bitgoUtxoLib = require('bitgo-utxo-lib-1.9.1');
const fromZec = "tmTEYjmn2Kyhks2EQzq9aNqcZPpeRchMYev"
const privateKeyZec = "cQQcw2g2oNqJCDb9r5qRqtRAXCWenCbBr3gJJVcNVJP92RwN1nt6"
const toZec = "tmUSpr2HzQMgQq8uopYtNGShdeUXs4tCP4o"
const utxos = [
{
"txid": "d9bbd01d69029e8563d2736761a7f132ea62d92d133b85236ce58d351cf5a58c",
"vout": 1,
"address": "tmTEYjmn2Kyhks2EQzq9aNqcZPpeRchMYev",
"amount": 89.99500000,
"scriptPubKey": "76a914c03023a2285c20a5a64256b636eb9fd06406c9f788ac"
},
]
const ZcashTest = bitgoUtxoLib.networks.zcashTest
const tx = new bitgoUtxoLib.TransactionBuilder(ZcashTest);
let total = 0;
for (let key in utxos) {
key = parseInt(key)
const utxo = utxos[key];
tx.addInput(utxo.txid, utxo.vout);
total += bitcore.Unit.fromBTC(utxo.amount).toSatoshis();
}
let send = 100000000
const fees = 500000;
const change = total - send - fees;
tx.addOutput(toZec, send);
tx.addOutput(fromZec, change);
const keyPair = bitgoUtxoLib.ECPair.fromWIF(privateKeyZec, ZcashTest)
tx.setVersion(4)
tx.setVersionGroupId(0xE9FF75A6)
for (let key in utxos) {
key = parseInt(key)
tx.sign(key, keyPair, "", bitgoUtxoLib.Transaction.SIGHASH_ALL, bitcore.Unit.fromBTC(utxos[key].amount).toSatoshis())
}
const msg = tx.build().toHex();
`
Hi, I am trying to build a regular zcash transaction but ran into issue, the code is as below:
const transferTo = 'tmVdCtuT7veiasFxwAy95rJdWSrU5Huusq1'
const transferFromTxId = '0289011e07c120bbdb70c3f5113884d90790c6b241d751cbe529cc207c21496b'
const NETWORK = bitgo.networks.zcashTest
const tx = new bitgo.TransactionBuilder(NETWORK)
tx.addInput(transferFromTxId, 0)
tx.addOutput(transferTo, 1000000)
const keyPair = bitgo.ECPair.fromWIF(privateKey, NETWORK)
try {
tx.sign(0, keyPair)
} catch (err) {
console.log(err)
}
const signedTx = tx.build()
console.log(signedTx.toHex())
The error it caused is:
{ Error: Expected property "2" of type Satoshi, got undefined
at tfSubError (/Users/tiangeguo/jadepool-BN/node_modules/typeforce/errors.js:93:9)
at /Users/tiangeguo/jadepool-BN/node_modules/typeforce/index.js:159:17
at Array.every (<anonymous>)
at _tuple (/Users/tiangeguo/jadepool-BN/node_modules/typeforce/index.js:155:20)
at typeforce (/Users/tiangeguo/jadepool-BN/node_modules/typeforce/index.js:196:9)
at Transaction.hashForZcashSignature (/Users/tiangeguo/jadepool-BN/node_modules/bitgo-utxo-lib/src/transaction.js:614:3)
at TransactionBuilder.sign (/Users/tiangeguo/jadepool-BN/node_modules/bitgo-utxo-lib/src/transaction_builder.js:801:29)
at validateAddress (/Users/tiangeguo/jadepool-BN/test/unit/testzcash.js:25:8)
at Object.<anonymous> (/Users/tiangeguo/jadepool-BN/test/unit/testzcash.js:36:1)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
message: 'Expected property "2" of type Satoshi, got undefined',
__label: undefined,
__property: 2,
__type: [Function: Satoshi],
__value: undefined,
__valueTypeName: '' }
(node:35920) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Not enough signatures provided
(node:35920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I am attempting to build 2 functions with this library, one that constructs an unsigned transaction, and another that takes that unsigned transaction and signs it then returns the needed hex.
After some playing around, I got it to produce a transaction the library thinks is valid, but doesn't broadcast on the network. =\
NOTE: I am doing this for TESTNET!
I am probably just missing something simple... so figured I could share some code. =)
/**
* Returns the network object from the zcash library
* @param input.network Network string passed into coin-ops
* @returns the zcash network
*/
function zecNetwork({ network }: ZecNetworkInput): any {
switch (network) {
case "zcash-mainnet":
return bitgo.networks.zcash;
case "zcash-testnet":
return bitgo.networks.zcashTest;
default:
throw new ValidationError(`invalid network`);
}
}
/**
* Constructs a UTXO transaction.
* @param input.inputs The intended inputs for the transaction
* @param input.outputs The intended outputs for the transaction
* @param input.options The options to use when constructing
* @returns output.unsigned_tx The unsigned transaction as hex
*/
export async function constructUTXOTransaction({
inputs,
outputs,
options,
network
}: ConstructUTXOTransactionInput): Promise<ConstructUTXOTransactionOutput> {
const txb = new bitgo.TransactionBuilder(zecNetwork({ network }));
txb.setVersion(4);
txb.setVersionGroupId(0x892f2085);
txb.setExpiryHeight(0);
inputs.forEach((value, index, array) => {
txb.addInput(value.identifier.hsh, value.identifier.index);
});
outputs.forEach((value, index, array) => {
txb.addOutput(
bitgo.address.toOutputScript(value.address, zecNetwork({ network })),
value.quantity
);
});
return { unsigned_tx: txb.buildIncomplete().toHex() };
}
/**
* Signs a UTXO transaction.
* @param input.unsigned_tx The unsigned transaction in hex format.
* @param input.private_blobs A JSON-encoded list of private blobs to use
* @param input.key_id The KMS key to decrypt the encoded list of private_blobs
* @param input.network The network name to derive the blockchain settings for
* @param input.utxo_indices The private key to use for each utxo
* @param input.inputs The inputs to the contstructed transaction
* @returns output.signed_tx The signed transaction
*/
export async function signUTXOTransaction({
unsigned_tx,
private_blobs,
inputs,
key_id,
network,
utxo_indices
}: SignUTXOTransactionInput): Promise<SignUTXOTransactionOutput> {
const txb = bitgo.TransactionBuilder.fromTransaction(
bitgo.Transaction.fromHex(unsigned_tx, zecNetwork({ network })),
zecNetwork({ network })
);
const privateKeypairs = [];
if (utxo_indices.length !== inputs.length) {
throw new ValidationError(`invalid utxo_indices`);
}
for (const val of utxo_indices) {
const privateBlob = await kmsDecrypt(private_blobs[val], key_id);
const ecPair = bitgo.ECPair.fromPrivateKeyBuffer(
Buffer.from(privateBlob, "hex"),
zecNetwork({ network })
);
privateKeypairs.push(ecPair);
}
inputs.forEach((value, index, array) => {
txb.sign(
index,
privateKeypairs[index],
"",
bitgo.Transaction.SIGHASH_SINGLE,
value.amount.amount
);
});
return {
signed_tx: txb.build().toHex()
};
}
When I submit the final tx to the network I get
{
"result": null,
"error": {
"code": -26,
"message": "16: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)"
},
"id": 1
}
Here is the final signed tx hex:
0400008085202f89018379bd136089765ee9b47504540619b0cf3a8e481659551a06fc875db14ff9e2000000006b483045022100c57290968719bbedfc6e41c5b62744c125e3a9c39e626ee42291771c481231760220453b0ac696a268b72b4952e2f485ea114823557f348c2f5ae76d7da3cce716a5032102594fdae20bf32bce9d3d072813d7e5475d56a13134baa63650916d07b7985dc5ffffffff0100e1f505000000001976a914e44661aa9f4ffbe9066f90283078adf3a896b6d388ac00000000000000000000000000000000000000
The decoded transaction in json:
{
"result":{
"txid":"52302920753a6eef7212797ee08251568d832f828b4dc505e8770a95329f51df",
"overwintered":true,
"version":4,
"versiongroupid":"892f2085",
"locktime":0,
"expiryheight":0,
"vin":[
{
"txid":"e2f94fb15d87fc061a555916488e3acfb01906540475b4e95e76896013bd7983",
"vout":0,
"scriptSig":{
"asm":"3045022100a01fcec97fb383bc5fee536893479be0bb34744abdfa44efcdb7c9b9b39d858602200e8c0b75acabbed1e56d5e465f1850731d813421936bf8e7fe5be6bbc6c1c0d3[SINGLE] 02594fdae20bf32bce9d3d072813d7e5475d56a13134baa63650916d07b7985dc5",
"hex":"483045022100a01fcec97fb383bc5fee536893479be0bb34744abdfa44efcdb7c9b9b39d858602200e8c0b75acabbed1e56d5e465f1850731d813421936bf8e7fe5be6bbc6c1c0d3032102594fdae20bf32bce9d3d072813d7e5475d56a13134baa63650916d07b7985dc5"
},
"sequence":4294967295
}
],
"vout":[
{
"value":1.00000000,
"valueZat":100000000,
"valueSat":100000000,
"n":0,
"scriptPubKey":{
"asm":"OP_DUP OP_HASH160 e44661aa9f4ffbe9066f90283078adf3a896b6d3 OP_EQUALVERIFY OP_CHECKSIG",
"hex":"76a914e44661aa9f4ffbe9066f90283078adf3a896b6d388ac",
"reqSigs":1,
"type":"pubkeyhash",
"addresses":[
"tmWXMi6sHPxoKP5xqLK9Lqhxfg5hJqwsDvS"
]
}
}
],
"vjoinsplit":[
],
"valueBalance":0.00000000,
"valueBalanceZat":0,
"vShieldedSpend":[
],
"vShieldedOutput":[
]
},
"error":null,
"id":"curltest"
}
Zcash tx with negative balanceValue
if sum of amounts of shielded outputs is greater than sum of amounts of shielded inputs then tx.valueBalance is < 0. Such tx breaks Transaction.prototype.getHash
How to reproduce:
// https://zec1.trezor.io/tx/5dc7af90852a4a99e99822c6bf6996fac081fed3c51ef5912e362868069d8dc2
const hex = '0400008085202f890274e035266a710c06c8f0c93120b0153830c3f93a307e8a5685f49bb84162f6f4000000006b483045022100e7d80c47befab2c9494d64c211f4abd104aab2b75f31443b77438c4e3be4dd07022075bf764129c4775d1df4e26eb997793ed4531c4c27ddf7ff0fd188333ac58d350121033ed695b802987fb44f4401397f051cdaa9260a638f5359f866d776abf6f1549effffffffd9641e046765e49f5d9b2c0e033fc300cad47a6175e081854cc76ae8cc9253cf1c0000006a473044022045911112e79e6e0511850b20c284a21e9089ea4d10821f1a83bac28919c4ecfa022046b027e026c98f3bd0187e797651cef21fef7c6e8f54dbd206f413ee5febb1f40121033ed695b802987fb44f4401397f051cdaa9260a638f5359f866d776abf6f1549effffffff1a8c111100000000001976a914aceb8e7313c293f15bfbcefa130eb88a4fc02f2488acaf761200000000001976a9144be18cbda2883ebbc5061da1bd471600a59a94cf88ac201d0406000000001976a914c0775a0ebd52bb9ca1a998a7a49cf4aa8b7bc9ff88ac0f54fd05000000001976a9144e305867d0f7ac7066df1b00ff4dc9cba51e787088ac52cce800000000001976a914ef0b3b48f9ffad719e2e1406d373c10330972af688acc1a29a00000000001976a914e4d41695fc7b58a1da808b5bb1b79ee05fd8bc4488ac93e49800000000001976a914ef0d489856832ff4d32eaddf50e410917de1b75e88ac3ee30100000000001976a9148ce9e94ee8d6ccf75620b9e1360b8971d170ccfc88ac67120200000000001976a914359e46eb7f9ee15cb09e14a21380a75679749ed388ac00f7da1d000000001976a9143934056b5bfa87cc2a87ebc0a36f916ded16bb2788ac4c939900000000001976a914f21781907c8cb4f494294a1149f065dfbcd618ac88ac9c490f00000000001976a914edb57b3cb63f274e099cda30cde22f50638679e688ac7a070200000000001976a914a30f3d5333580596c3af791cb4fb48236fe8c04d88acff96fc02000000001976a914633270833ce33c26c7d1b92439c71acdf884ddd088ac7c80c400000000001976a914ac800d643af27b64b8d61b3547f92b8341f9c67788acda1e9c00000000001976a914041efd2ca1ba825222a418d495023439ae51ff0288ac1e8c0f00000000001976a91463716dd958c454eb0913a358a993ab6681f3db7688ac91dc5400000000001976a914e78252b0170bd337c5db064ce747b91d3681f13d88acb2baa400000000001976a914e56934520476226a95b630f3f75e3b387c8cbc0288acb67dec02000000001976a91411844f4c56672551aeb8b73813acabd4b4506b2788ac4bb31c00000000001976a914eb6108c6cf37ee21c7d21529651390825716e79e88ac5121ec00000000001976a91446bfd8b111d1fa9e9a1d7abcda6fec27f233482d88ac6e000200000000001976a914a981dde95b9cccb76dd5e73ec79ba2b9a2947a9788ac1f549a00000000001976a914df977d93f6fe0a70dfc06517cd235e795404f3e088ac9e76c0682c0000001976a914c521cb53dc20fb20049b9ab6653775b3c37411a188ac90d00300000000001976a914d995c6ef3070f64b8f29588b4786d6d450b3eff688ac00000000c6940d001877feffffffffff0001958018cae1b8cd422b719f644ab437833a6544e68093cc844fb15be0762e5339c99af38f0805842a3d4f1a50551e9aa4858150eecc1a6c4a818df5ca7c4d3e21c0be81ac4ddcf34516a9396c8a31436d57f90fff5fe6b668bb3ed28cb0fb3aae47becec7243df9d0b3ce90e25c130632763f11d2fbc4fba9b06edb124f1b21087b4c0539660d1b2a05cec8382b4875a9025a1bac5cd56a2dfcd76e0fccb25d0503a180de8acd6abe28309eb24b87c229d5075b885884b49c10ce3f1f60fc2cefb86e8859aea91bb8b7f797c4240944ef4365ecac5427a146c8de33688f2c5343b6b0eb138254c94e99eff302104714e4cd1e14bcc897f89a1fab58a866102cbfdc7839784350bc4e3b35c26a6d77934b69abb06dcd926d66369b2f273d2c4172932ee6e39c9e67f39ed588a80c6240e2b36398673c5b1e45ae477d8edcd9c10e6389d4f54b25a9a13dca4ae89034778a23f6cbbce9572d014d35f6d3fea3868c4eea96ae0f65443df55feb8aea0ae8b28e359aeedc201e921dd900ab941b19c25dfbd29ae1090e79048a938280ca6bb86d386080072933178e589ec9b7e185b1d0ed57b08e96c19a2acfa037a82e497063651ea9df9a9704d6a0a1964df49a1ed3d421dd8a857e57b5f167f0c5934b6a74bb6321dcde1d4df869b4496864013459c9497916a0adbc4649afbcb3b5be8a1b83d6830803538443f29a16796ad6b1e01f2a3cd26d6eb4a4b936d21bf70f2d615048583656b4397532fba5c9ac8fc93d5b804020d898589db1b59a9063da268f793a71297c21fd5936f83a658db9f0bcdfbe1221ddf9586780e0fd7f1eec4f63cb7691f7bab5ce07a2e7fdfced7d07289241fee44c3b809c6a3e3d9ed473419aa1f661e2af1611c57bd3f894c45ddb4db4d0adb405a9edad5807243fdecc236710165d2df68b5f0b9c0a773c8e887d461b6a88f46557ac8d6234405668b237027c0a6835af264be29405d13050a3183fe2e2f223827ee170c1196e03712138b590cdf67cfbcf46c2cae5f7131ccbdf2270c9e332f23803e3207ee8b528d26e5447a31b93deb08fea5f8575d5e9b456ae4afe39e5d154e60bbc22e3dbbecccf1f0e37c8abb1a7e3fabeb14b192c995e2a99456fb1f6eb3834667a59856192267665589c7c1b8206413e57936a2cb379c444ffb4fa7815536a96099914557944a8c428b4191757e58969084fc5cd34b11980580494a138cb56b0106da30d7c85702ad664a2e95ac93463bc3f34d5a8ad89ae4fbe8a5229028c7dd91dfa49cb6c232dac13c95861146940c2f209aee1f46752a30491278a0171ed609e8158ceb873a3c6cb00aa723df9ed6890fde178d0ebd1a45b420c9159c0b927569f789622edbde92fef885c3dfce52b0b4d0dcda8400281a13e947a64591a9ef7226f3e72a22a5e0d08';
// using latest 1.9.1 version
var Transaction = require('./node_modules/bitgo-utxo-lib/src/transaction')
var networks = require('./node_modules/bitgo-utxo-lib/src/networks')
var tx = Transaction.fromHex(hex, networks.zcash)
// this works, but note the value balance property is negative
console.log(tx);
// setting it to non-negative value makes it work
// tx.valueBalance = 0;
// but if it stays negative, this will throw
console.log(tx.getHash())
Problem is that unsigned int is expected here
bitgo-utxo-lib/src/transaction.js
Line 717 in 7c91a91
Which obviously throws here
bitgo-utxo-lib/src/bufferutils.js
Line 10 in 7c91a91
To complete the Networks.js file, you can add Bitcoin Gold Testnet
source: https://github.com/BTCGPU/bitcoinjs-lib/blob/master/src/networks.js
network: {
messagePrefix: '\x1DBitcoin Gold Signed Message:\n',
bech32: 'tbtg',
bip32: {
public: 0x043587cf,
private: 0x04358394
},
pubKeyHash: 0x6f,
scriptHash: 0xc4,
wif: 0xef,
forkHeight: 1,
equihash: {
n: 144,
k: 5,
person: 'BgoldPoW',
equihashForkHeight: 14300,
preEquihashFork: {
n: 200,
k: 9,
person: 'ZcashPoW'
}
}
}
Hi,
Compiling using webPack version 4 don't work.
Here is the error message:
ERROR in ./node_modules/bitgo-utxo-lib/node_modules/blake2b-wasm/blake2b.wasm
WebAssembly module is included in initial chunk.
This is not allowed, because WebAssembly download and compilation must happen asynchronous.
Add an async splitpoint (i. e. import()) somewhere between your entrypoint and the WebAssembly module:
./src/index.js --> ./src/components/App.js --> .........
I use this parameters :
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"css-loader": "^3.0.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"prop-types": "^15.7.2",
"style-loader": "^0.23.1",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "^3.7.1"
const bitcoin = require("bitgo-utxo-lib");
const tx = new bitcoin.TransactionBuilder(bitcoin.networks.zcashTest);
tx.addInput('bda0feb0531b0a90a46f54208e06257a57f88e6430a1fad71e850622130b3f9c', 0)
tx.addOutput('tmLYMLL8XofkMzhas7b8F8y954u9EBXJ4tJ', 280000000)
tx.addOutput('tmX73eXLXevHuhVvcXeUffXYxvGUNbNWcSQ', 10000000)
var keyPair = bitcoin.ECPair.fromWIF('cSXDRVNgdtsCpfgRji67W6Dvj2Eu8MMUuvaN6Y9wHt9EaA1vQ6Tt', bitcoin.networks.zcashTest)
tx.setVersion(4)
tx.setVersionGroupId(0x03C48270);
tx.setExpiryHeight(501430);
tx.sign(0, keyPair, '', bitcoin.Transaction.SIGHASH_ALL, 0);
//const msg = tx.build().toHex();
console.log(tx.build().toHex())
rpc error:
{
"result": null,
"error": {
"code": -22,
"message": "TX decode failed"
},
"id": 1
}
help me .
Block.fromBuffer
method isn't able to calculate a correct nTransactions
value resulting in throw of 'Unsupported zcash transaction'.Block.fromBuffer = function (buffer, network = undefined)
function readTransaction() { var tx = Transaction.fromBuffer(buffer.slice(offset), network, true) offset += tx.byteLength() return tx }
How to reproduce :
zecUtil.Block.fromHex('040000002aef47978e707a9552576cf451201961873735fa1f474d415ee5f7fd4ec200002bcc195fd5114a68a0ee65261791acadb6a96b41410e9ccfe1ce9176b12d618b2477ca322e8a5f2a43ed64365115573791597f6cfb56f15c2c0f9971c9db693bc017e45b99ca001f6fffffb700000000cc47cee231101d4100641a13000000000000000000000000fd40050029c82faac7ef06e9a0f0363bd46a050846340be8046e013587c18a656995b0832618ac094d69da55b60bab36885dceec03b391f2a9dfad4f62cd06181fcb0d2618ff7d87918cc5652749cfe24b131e129ebbda0c4485a2a6ef4479c338220030dc4d88af9f3867b52894ee4bc4af95d5bd52e2b1ea3914a0d37e5266e03abf14ccdf5b2111b1fc969cc2f8d431afcd371f085d73fff2b32d3c4fd061f85e30683dfac2fcb6fe8704ffce573f1e1f3f28361cebe6720d2f6229bf0c104499576b32144e49873c05dcf935b84324423c0a9a17a635f10748bcfe5860e2f041dad13dd73f949cdc243b3da9efac2727f2e0a659204c34df5fef9d7f9d1c716e51cbd07397def085f118c3c2eedde297601432b06ca6a85d81a586d8149ed35e207b1fa69c77f11cae4ec5b5acc361abf0329e15a962d0c4a5362dbc585a0318eddcc73715ab95d7d473f9aefb0fdff5e702c816988ff7eee3cd4c4070321eeea7ba97be98cf045660ca112bb725e44465ba69735b1aef89f9369714c05a05641337252f6bb1d95d8f94b8c85f89aba5218dd99f0ad1ff05cd72579d18e41edb511d7db1ab1023f1959384b82dadae1140dc6f0989af9672df3a12c5fc3e5ecbb661020ea644c4445e11961abd9c1731d31bf5fed3fecd83e0f44fac786a2a43093ddcb743609296e8dc9d8bf9af251dd7abeb41abc7b0226f08b211fb3e4fb0c37b0ea1ce1dbd55c3a8bb7f05a714f9fd264194eb517a456450c870837d2c59ae12fd255e39b2abd920ad404483a929bdb34ab538fb463a2774a2b4132060ff058a97882a706b5eb35a5f86870e7c90dab7949409b67a92056846f73d0229149e8416d1f1e51fda277bb636c247fe67557d18fc35cb411f523663b0de9c9afd4ba714d24e36b1c9c5de83b028c5d3686568245b443a23e7e3dd0d09d9e31d2b2601974bac618acdbed683206df43f7248655124810f0adc14c5c7c56b83842a42bbd4c8614104914f4e1306287d6cfc208207f159f0bbaf9c6445cd1270e52f49d9976a6f62030f3563c75b53c995aa7492bd08fc024ef8198a4e567bc5e464c6efd9e31b80dd7c16552374fd02ed6d4571ffaa52eab3a1af0d240d4e34d4149513e8795317dbbc14145d676c22296f8f1aae4a23e56a9a71d5a4bb6fd4a2c0331794598b95da14591970b5f0af4ca45afef8d23536705240d8465168701e147ee65b9c629180c4d54d9f59cab20cba13ffc31fd51c29979efd716fee64342053787224bfffa60c40fe322c8a9e1819b5fc458f107791d5e003bfd1fe1f01ca8bc24c41b2a449e3d42ee29bc14514da6ab122dc2e3715f4c9afdaa902a49542b0663ad7b79fed299f5621164d16e68ea053853b64001ce9e4dcd9504a6a64c996dd7ce50a8cd57be8c4cbb1cd71bc7a5d030bbac9dbae5a1b820f07277cbd8f85f17c37715e4d181d50c59c2998f5bff6aa5bb782af79523effe72848aedc7ee1ccf1dc73a30c8d74ace18d7fb82a1a374dfb6550f0f42df9f2137aaaed30965018bd4e4407b279686ca8d1d9b145f32a6a7f135cde029796063da4c72199639cb16f5d2a2c41556d9eaca41d76cd0f29f68a3194c8a5a24d1306947e4244f5496bb4451e8ac5b050ca5d7c58ad03d77ff9a7d22fc17c792506f8863e9074f98dd905357a3737ddd718a73d76e5147a42edc9ec65117858143b4b2954a695d39a20db0bf497fb564dc7cf5b89b0ce19200674e10c1cabfe354b420a171752ed9d811402553f240d04c7b801230dc62900273cf8a5fdc4016716539a5c86fb06a3c11280b0e29a97c36b834406daea5d32e22a0515ede510853a85d833f419ff7c2588c2b674ce3697f9929265030d8c496da831b994f75a8c3bc6e24436f7fb6a010400008085202f89010000000000000000000000000000000000000000000000000000000000000000ffffffff5003f523050044656661756c7420732d6e6f6d7020706f6f6c2068747470733a2f2f6769746875622e636f6d2f732d6e6f6d702f732d6e6f6d702f77696b692f496e73696768742d706f6f6c2d6c696e6bffffffff0260a4743b000000001976a914676557ba42becdcbe92cacfc359f129a1fb0936788ac80b2e60e0000000017a9145e21a7724b9dd0dd3f4df9703c078dddbfc94d268700000000000000000000000000000000000000', zecUtil.networks.zcashTest)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.