LedgerHQ / ledgerjs

⛔️ MOVED to monorepo "ledger-live"
https://github.com/LedgerHQ/ledger-live
Apache License 2.0
574 stars 375 forks source link

signing multisign ripple transaction #175

Open y0ke opened 6 years ago

y0ke commented 6 years ago

I'm trying to sign a simple multisign transaction though, It seems that XRP's signTransactionthrows an error if a given raw tx's SigningPubKey is empty.

  Error
    at new TransportStatusError (/Projects/sandbox/ledger-test/node_modules/@ledgerhq/hw-transport/lib/Transport.js:152:16)
    at TransportNodeHid._callee$ (/Projects/sandbox/ledger-test/node_modules/@ledgerhq/hw-transport/lib/Transport.js:205:23)
    at tryCatch (/Projects/sandbox/ledger-test/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Projects/sandbox/ledger-test/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/Projects/sandbox/ledger-test/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Projects/sandbox/ledger-test/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Projects/sandbox/ledger-test/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>

Is there any way to sign a multisign transaction with ledgerjs? Any advice or suggestions will be greatly appreciated

qiluge commented 6 years ago

I use these code and meet a error same with you.

import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import AppXrp from "@ledgerhq/hw-app-xrp";

const binaryEncode = require('ripple-binary-codec');
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'});
const multiSignAddress = "rNxyGCYnypq5vELR2TdJNwrdA4PwTsN5sZ";

async function multiSign() {
    const transport = await Transport.create();
    const xrpApp = new AppXrp(transport);
    let addr1 = await xrpApp.getAddress("44'/144'/0'/0/0");
    let addr2 = await xrpApp.getAddress("44'/144'/0'/0/1");
    console.log('addr1 ', addr1);
    console.log('addr2 ', addr2);

    let payment = {
        Account: "rNxyGCYnypq5vELR2TdJNwrdA4PwTsN5sZ",
        Amount: "1000000",
        Destination: "r4Z7imQR1gKSKmi4pmmwd8CJP8cvs7nxTP",
        Fee: "36",
        Sequence: "9",
        TransactionType: "Payment",
        SigningPubKey: ""
    };
    // payment.SigningPubKey = addr1.publicKey.toUpperCase();
    let serializedTx = binaryEncode.encodeForMultisigning(payment, addr1.address);
    console.log("encode for multi sign", serializedTx);
    let signature1 = await xrpApp.signTransaction("44'/144'/0'/0/0", serializedTx);
    let signer1 = {
        Signer: {
            Account: addr1.address,
            SigningPubKey: addr1.publicKey.toUpperCase(),
            TxnSignature: signature1.toUpperCase()
        }
    };

    // payment.SigningPubKey = addr2.publicKey.toUpperCase();
    let signature2 = await xrpApp.signTransaction("44'/144'/0'/0/1", serializedTx);
    let signer2 = {
        Signer: {
            Account: addr2.address,
            SigningPubKey: addr2.publicKey.toUpperCase(),
            TxnSignature: signature2.toUpperCase()
        }
    };

    payment.SigningPubKey = "";
    payment.Signers = [signer1, signer2];

    console.log(JSON.stringify(payment));
    let signedSerialized = binaryEncode.encode(payment);
    console.log(signedSerialized);
}

multiSign();

And use following code to sign tx but got a invalid signatures

import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import AppXrp from "@ledgerhq/hw-app-xrp";

const binaryEncode = require('ripple-binary-codec');
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'});
const multiSignAddress = "rNxyGCYnypq5vELR2TdJNwrdA4PwTsN5sZ";

async function multiSign() {
    const transport = await Transport.create();
    const xrpApp = new AppXrp(transport);
    let addr1 = await xrpApp.getAddress("44'/144'/0'/0/0");
    let addr2 = await xrpApp.getAddress("44'/144'/0'/0/1");
    console.log('addr1 ', addr1);
    console.log('addr2 ', addr2);

    let payment = {
        Account: "rNxyGCYnypq5vELR2TdJNwrdA4PwTsN5sZ",
        Amount: "1000000",
        Destination: "r4Z7imQR1gKSKmi4pmmwd8CJP8cvs7nxTP",
        Fee: "36",
        Sequence: "9",
        TransactionType: "Payment",
    };
    // payment.SigningPubKey = addr1.publicKey.toUpperCase();
    let serializedTx = binaryEncode.encode(payment);
    console.log("encode for multi sign", serializedTx);
    let signature1 = await xrpApp.signTransaction("44'/144'/0'/0/0", serializedTx);
    let signer1 = {
        Signer: {
            Account: addr1.address,
            SigningPubKey: addr1.publicKey.toUpperCase(),
            TxnSignature: signature1.toUpperCase()
        }
    };

    // payment.SigningPubKey = addr2.publicKey.toUpperCase();
    let signature2 = await xrpApp.signTransaction("44'/144'/0'/0/1", serializedTx);
    let signer2 = {
        Signer: {
            Account: addr2.address,
            SigningPubKey: addr2.publicKey.toUpperCase(),
            TxnSignature: signature2.toUpperCase()
        }
    };

    payment.SigningPubKey = "";
    payment.Signers = [signer1, signer2];

    console.log(JSON.stringify(payment));
    let signedSerialized = binaryEncode.encode(payment);
    console.log(signedSerialized);
}

multiSign();

I post the signedSerialized, and response is fails local checks: Invalid signature on account rxxxxxxxx...

blockchainguyy commented 5 years ago

Hi @y0ke @qiluge, Is this issue resolved since I am getting the same error ie. : fails local checks: Invalid signature on account rxxxxxxxx... Thanks