trezor / trezor-utxo-lib

UTXO coins functions implemented in pure JavaScript
MIT License
8 stars 11 forks source link

zcash send transaction fail #15

Open benjamintshi opened 3 years ago

benjamintshi commented 3 years ago

Raw hex: 0400008000000000012ea5a649c7c5188824f526674534038f00c45bcbcc1d5430a2ef91dde7a18bf1000000006a47304402204afc7ada0ccda133081f7ac01cbd4a83e39d19c0e5e21cbf33758f2f5912ce6c0220492a6c82ed9a2a5b45258243da123736f5d71ac0844618aefa16cec47e8ebd7d012103e68a8f75b6905722663837566d63823cdd60bf774a1262d817bed0aec9cb791e000000000240548900000000001976a914b5f02d8e6e831d09670898c1e2f482d4284215b788aca8370f00000000001976a9144fab54e48a2c008c4eb0315203d795c3cbe7a1be88ac00000000000000000000000000000000000000

{ "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 }

prusnak commented 3 years ago

@benjamintshi How did you create such transaction?

benjamintshi commented 3 years ago

@benjamintshi How did you create such transaction?

const {
  networks,
  ECPair,
  crypto: bcrypto,
  TransactionBuilder,
  Transaction,
  script: bscript,
} = require("trezor-utxo-lib-lite");
var network = networks.zcash;
var wif = "my private key";
var keyPair = ECPair.fromWIF(wif, network);
var pk = bcrypto.hash160(keyPair.getPublicKeyBuffer());
var spk = bscript.pubKeyHash.output.encode(pk);
var txb = new TransactionBuilder(network);
const numTx = txb.addInput(
  "f18ba1e7dd91efa230541dcccb5bc4008f0334456726f5248818c5c749a6a52e",
  0,
  0,
  spk
);
txb.addOutput("t1aTc2ux2eLwqTuDxZEWhnxc21PYhMR7BXX", 0.09 * Math.pow(10, 8));
txb.addOutput(
  "t1R8rdpUNFR44iifyUb5nzjzsRTA7qQsRTs",
  0.00997288 * Math.pow(10, 8)
);
txb.overwintered = true;
txb.setVersion(4);
txb.setVersionGroupId(0x892f2085);
txb.setExpiryHeight(0);
// var hashType = Transaction.SIGHASH_ALL;
txb.sign(0, keyPair, null, null, 0.1 * Math.pow(10, 8));
// txb.sign(1, keyPair2, null, hashType, 0.08449 * Math.pow(10, 8));
var tx = txb.build();
var hex = tx.toHex();
console.log(hex);
benjamintshi commented 3 years ago

this is my code.

benjamintshi commented 3 years ago

i forked trezor-lib, because our network can not download "blake2b": "https://github.com/BitGo/blake2b#6268e6dd678661e0acc4359e9171b97eb1ebf8ac",

prusnak commented 3 years ago

We are sunsetting this repository soon in favor of our monorepo. Can you please try the @trezor/utxo-lib package that is waiting in this PR if that code works for you? https://github.com/trezor/trezor-suite/pull/4421

benjamintshi commented 3 years ago

We are sunsetting this repository soon in favor of our monorepo. Can you please try the @trezor/utxo-lib package that is waiting in this PR if that code works for you? trezor/trezor-suite#4421

Sure, Please wait a while.

benjamintshi commented 3 years ago

We are sunsetting this repository soon in favor of our monorepo. Can you please try the @trezor/utxo-lib package that is waiting in this PR if that code works for you? trezor/trezor-suite#4421

when i used @trezor/utxo-lib, i stil got this "message": "16: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)".

raw hex:

0400008085202f89012ea5a649c7c5188824f526674534038f00c45bcbcc1d5430a2ef91dde7a18bf1000000006a4730440220500bec94871f662a9d0205cacee27550cb56b98dfd9df1191ccd54678f92b6e702202a14fbd2f59c9f69d7dbc94385217eb602950fbd891a7fa772b256c2c0edfff7012103e68a8f75b6905722663837566d63823cdd60bf774a1262d817bed0aec9cb791effffffff0240548900000000001976a914b5f02d8e6e831d09670898c1e2f482d4284215b788aca8370f00000000001976a9144fab54e48a2c008c4eb0315203d795c3cbe7a1be88ac00000000000000000000000000000000000000

trezor version : "@trezor/utxo-lib": "0.1.2",

my code

const {
  TransactionBuilder,
  Transaction,
  networks,
  ECPair,
  address,
} = require("@trezor/utxo-lib");

// Choose the configuration for the transaction builder
const zcash = networks.zcash;
const builder = new TransactionBuilder(zcash);

// 1st signature
const keyPair1 = ECPair.fromPrivateKeyBuffer(
  Buffer.from(
    "my private key hex",
    "hex"
  ),
  zcash
);

// Required Zcash parameters
builder.setVersion(4); // 4
builder.setVersionGroupId(0x892f2085);
// Optional parameters
builder.setLockTime(0);
builder.setExpiryHeight(0);
// Build inputs
builder.addInput(
  "f18ba1e7dd91efa230541dcccb5bc4008f0334456726f5248818c5c749a6a52e",
  0,
  Transaction.DEFAULT_SEQUENCE,
  address.toOutputScript("t1aTc2ux2eLwqTuDxZEWhnxc21PYhMR7BXX", zcash)
);
// Build outputs
builder.addOutput(
  "t1aTc2ux2eLwqTuDxZEWhnxc21PYhMR7BXX",
  0.09 * Math.pow(10, 8)
);
builder.addOutput(
  "t1R8rdpUNFR44iifyUb5nzjzsRTA7qQsRTs",
  0.00997288 * Math.pow(10, 8)
);
const hashType = Transaction.SIGHASH_ALL;
builder.sign(0, keyPair1, null, hashType, 0.1 * Math.pow(10, 8));
// Build final transaction
const signedTransaction = builder.build();
// hex
console.log(signedTransaction.toHex());
prusnak commented 3 years ago

trezor version : "@trezor/utxo-lib": "0.1.2",

The correct version from the monorepo should be 1.0.0, not 0.1.2. It seems you are still using the version from NPM, not from the monorepo.

benjamintshi commented 3 years ago

thanks, i'll try this version .

benjamintshi commented 3 years ago

1.0.0

npm got version 1.0.0-beta.9 1.0.0-beta.10 can not download

prusnak commented 3 years ago

npm got version 1.0.0-beta.9

Yes, 1.0.0-beta.9 is the correct one.

benjamintshi commented 3 years ago

npm got version 1.0.0-beta.9

Yes, 1.0.0-beta.9 is the correct one.

could you please give me some demo , I was confused how to use version 1.0.0 to build and sign a transaction offline , it has been changed.