Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signTx's TransactionWitnessSet produce TextEnvelope decode error in cardano-cli #85

Closed
jinglescode opened this issue Nov 4, 2021 · 18 comments

Comments

@jinglescode
Copy link

jinglescode commented Nov 4, 2021

@alessandrokonrad . For cardano.signTx(), the output TransactionWitnessSet, does not tally the input required in cardano-cli, producing this error:

Command failed: transaction sign-witness  Error: buyer_witness_set_from_nami_signTx.witness: TextEnvelope decode error: DecoderErrorDeserialiseFailure "Shelley Witness" (DeserialiseFailure 0 "expected list len")

Seems like, the cborHex Nami produced after signTx() has extra 2 characters.

@jinglescode jinglescode changed the title How to get keyHash? signTx's TransactionWitnessSet produce TextEnvelope decode error in cardano-cli Nov 7, 2021
@alessandrokonrad
Copy link
Contributor

What function are you using the cardano-cli? The TransactionWitnessSet is a wrapper around the actual vkey witness. I haven't tried it in the cli yet, but it's definitely correct what Nami returns you. It's based on top of the serialization-lib.

@jinglescode
Copy link
Author

jinglescode commented Nov 8, 2021

@alessandrokonrad thanks for you reply. Using cardanoo-cli transaction assemble I'm combining the cbor taken from TransactionWitnessSet taken from cardano.signTx(), adding the cbor into a file that looks like that:

{
    "type": "TxWitness MaryEra",
    "description": "",
    "cborHex": "CBOR TAKEN FROM TransactionWitnessSet"
}

With cardanoo-cli transaction assemble, adding other witnesses generated by cardano cli transaction witness.

@rooooooooob
Copy link

it's possibly related to IntersectMBO/cardano-node#3370 but I haven't looked into it so it might be unrelated since that issue was from cardano-cli -> cardano-serialization-lib not the other way around

@jinglescode
Copy link
Author

it's possibly related to input-output-hk/cardano-node#3370 but I haven't looked into it so it might be unrelated since that issue was from cardano-cli -> cardano-serialization-lib not the other way around

Hi @rooooooooob, any workaround on this? I'm implementing partial signing as described here.

After executing, cardano.signTx(tx, partialSign=true), the hex encoded cbor string I got from TransactionWitnessSet; can I copy the cbor string into this .witness file with the follow format?:

{
    "type": "TxWitness MaryEra",
    "description": "",
    "cborHex": "CBOR TAKEN FROM TransactionWitnessSet"
}

Do I have to manipulate the cbor string first? Does the TransactionWitnessSet cbor from the serialization library match the required input from cardano-cli?

And lastly using cardano-cli transaction assemble:

cardano-cli transaction assemble     
--tx-body-file tx.draft     
--witness-file transaction_witness_generated_by_cli.witness 
--witness-file transaction_witness_from_above_json_file.witness      
--out-file tx.signed

Error I'm getting:

TextEnvelope decode error: DecoderErrorDeserialiseFailure "Shelley Witness" (DeserialiseFailure 0 "expected list len")

@pyropy
Copy link

pyropy commented Dec 7, 2021

@jinglescode Have you managed to assemble those two transactions in the end?

@rooooooooob
Copy link

@jinglescode can you please post the output (hex string for cbor or whatever format it's in) from the CLI that you're trying to parse?

@pyropy
Copy link

pyropy commented Dec 10, 2021

I've managed to assemble witness returned from nami and tx built from cli.

What you need to do is to take vkeys and wrap them in array like so [0, [vkeys]] and then encode it to cbor once again.

@jinglescode
Copy link
Author

I've managed to assemble witness returned from nami and tx built from cli.

What you need to do is to take vkeys and wrap them in array like so [0, [vkeys]] and then encode it to cbor once again.

I tried that, and this is how it looks like.

window.cardano.signTx(cborHex, true).then((signedTx) => {

  const array_to_cli = []; // to create `[0, [vkeys]]`
  array_to_cli.push(0);

  const decoded = cbor.decode(signedTx);
  for (let i of decoded) {
    array_to_cli.push(i);
  }

  const signed_cbor_from_nami = cbor.encode(array_to_cli).toString('hex');
});

Put signed_cbor_from_nami into the witness file, so cardano-cli can consume:

{
    "type": "TxWitness MaryEra",
    "description": "",
    "cborHex": "CBOR TAKEN FROM signed_cbor_from_nami"
}

And then:

Command failed: transaction sign-witness  Error: buyer_witness_set_from_nami_signTx.witness: TextEnvelope decode error: DecoderErrorDeserialiseFailure "Shelley Witness" (DeserialiseFailure 0 "expected list len")

What I'm doing wrong here? Any advice will be helpful.

@pyropy
Copy link

pyropy commented Dec 10, 2021

@jinglescode You actually get keywitness-set returned when signing transaction that holds vkeys, which are needed to assemble witness object. Here's an example:

  const encodedTxVkeyWitnesses = await wallet.signTx(encodedTx, true);

  const txVkeyWitnesses = wasm.TransactionWitnessSet.from_bytes(
    Buffer.from(encodedTxVkeyWitnesses, "hex")
  );

  // extract vkeys from witness set as bytes
  const vkeysBytes = Buffer.from(
      txVkeyWitnesses.vkeys()?.get(0).to_bytes() as Uint8Array
    ).toString('hex');


  const vkeysDecoded = cbor.decode(vkeysBytes)
  const witness = [0, vkeysDecoded]
  const witnessCbor = cbor.encode(witness)

@rooooooooob
Copy link

@pyropy

What you need to do is to take vkeys and wrap them in array like so [0, [vkeys]] and then encode it to cbor once again.

With both being arrays? In alzono.cddl we have

transaction_witness_set =
  { ? 0: [* vkeywitness ]
  , ? 1: [* native_script ]
  , ? 2: [* bootstrap_witness ]
  , ? 3: [* plutus_script ] ;New
  , ? 4: [* plutus_data ] ;New
  , ? 5: [* redeemer ] ;New
  }

which should be a map not an array. In the cardano-serialization-lib we implemented off the binary spec which implements it as a map not an array.

Can someone please post CBOR (can be hex string or whatever format you can post here) of what is working and what isn't working so I can look into it? It seems to me like it's just map vs array but I would like to examine the CBOR see if that's the only difference. Thanks.

@jinglescode
Copy link
Author

jinglescode commented Dec 15, 2021

Edit:

Hey @rooooooooob, here is the CBOR from cardano.signTx(encodedTx, true) after applying @pyropy method:
82008258209b8e0e4205180b4a2ac3511b39435e7e472c6cd817c1f05aaa7545c4b816601a584036b135996644821b84ccd31ad0b8ee07ef9b16eca8046aec96e8e756c0fcef293aeb0cd78866823239de10f98e5f9ddf223b814aaf2140183777d4fc742a3009

This works!

@ZDust172
Copy link

ZDust172 commented Dec 18, 2021

@jinglescode @pyropy Hi, how exactly are you guys signing the transactions in the CLI before signing it with Nami? I am attempting a similar method in #147 but the CLI still rejects my transaction.

@pyropy
Copy link

pyropy commented Dec 18, 2021

@jinglescode @pyropy Hi, how exactly are you guys signing the transactions in the CLI before signing it with Nami? I am attempting a similar method in #147 but the CLI still rejects my transaction.

I have pair of some random keys that I use to sign the tx, then load signed tx to nami via cardano-serialization-lib.

@ZDust172
Copy link

@jinglescode @pyropy Hi, how exactly are you guys signing the transactions in the CLI before signing it with Nami? I am attempting a similar method in #147 but the CLI still rejects my transaction.

I have pair of some random keys that I use to sign the tx, then load signed tx to nami via cardano-serialization-lib.

Thanks for the quick reply! So you're just doing cardano-cli transaction sign --tx-body-file {FILE} --signing-key-file payment.skey then copying the generated hex CBOR into cardano.signTx()? If so I'm very puzzled by the 'InvalidWitnessUTXOW' error message I get as I'm doing exactly the same.

@pyropy
Copy link

pyropy commented Dec 20, 2021

@jinglescode @pyropy Hi, how exactly are you guys signing the transactions in the CLI before signing it with Nami? I am attempting a similar method in #147 but the CLI still rejects my transaction.

I have pair of some random keys that I use to sign the tx, then load signed tx to nami via cardano-serialization-lib.

Thanks for the quick reply! So you're just doing cardano-cli transaction sign --tx-body-file {FILE} --signing-key-file payment.skey then copying the generated hex CBOR into cardano.signTx()? If so I'm very puzzled by the 'InvalidWitnessUTXOW' error message I get as I'm doing exactly the same.

I'm gonna write a blogpost today to explain in detail what I'm doing.

@pyropy
Copy link

pyropy commented Dec 24, 2021

Reference

@ZDust172 Here's my blogpost on how to load signed tx https://srdjanstankovic.com/2021/12/24/how-to-sign-and-submit-cardano-cli-transaction-using-nami-wallet.html

@ZDust172
Copy link

Reference

@ZDust172 Here's my blogpost on how to load signed tx https://srdjanstankovic.com/2021/12/24/how-to-sign-and-submit-cardano-cli-transaction-using-nami-wallet.html

Thanks! This should be a really helpful resource for others. I eventually opted to doing it a different way avoiding the cli altogether using the method here:

Emurgo/cardano-serialization-lib#303

@mateusap1
Copy link

Very helpful blogpost @pyropy. I'm still getting an error though:

transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (PPViewHashesDontMatch (SJust (SafeHash \"e84ed35a172ed46da854a132db880a608f73e0e61d385c9475a5b14fe4b9e4a9\")) SNothing),UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash \"1ef6f56f2e174d5e0328f24aa30d55b81f3bf871361f9280dd4090c2\"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoRedeemer (Minting (PolicyID {policyID = ScriptHash \"1ef6f56f2e174d5e0328f24aa30d55b81f3bf871361f9280dd4090c2\"})),NoWitness (ScriptHash \"1ef6f56f2e174d5e0328f24aa30d55b81f3bf871361f9280dd4090c2\")]))))])

I think it has to do with the fact that my transaction requires a redeemer and a datum, but shouldn't those elements be included in the tx body it self? Or do I need to somehow add it to the witness using the serialization lib?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants