XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

Does ripple-lib support offline sign? #972

Closed readygo586 closed 5 years ago

readygo586 commented 5 years ago

In ripple-lib's source code, I find many api.sign( ), does these function call send the txjson and secret to the network? if yes, is there any method to sign locally?

imerkle commented 5 years ago
import {RippleAPI} from 'ripple-lib';

let rapi;
   try{
        rapi = new RippleAPI({ server:`wss://s.altnet.rippletest.net:51233`});
        await rapi.connect();
    }catch(e){console.log(e)}
    const payment = {
        "source": {
            "address": from,
            "maxAmount": {
                "value": amount.toString(),
                "currency": `XRP`,
            }
        },
        "destination": {
            "address": address,
            "amount": {
                "value": amount.toString(),
                "currency": `XRP`,
            }
        }
    };
    let prepared;
    try{
        prepared = await rapi.preparePayment(from, payment);
    }catch(e){
        console.log(e)
    }
    //Dont connect to node here
    rapi = new RippleAPI();
    const tx = await rapi.sign(prepared.txJSON, wif)
    console.log(tx)

   //submit the signed tx

Alternatively you can directly create and send your own txJSON

intelliot commented 5 years ago

Does ripple-lib support offline sign?

Yes.

In ripple-lib's source code, I find many api.sign( ), does these function call send the txjson and secret to the network?

No. You can see the source code here: https://github.com/ripple/ripple-lib/blob/develop/src/transaction/sign.ts

It uses the local signing functionality provided by ripple-keypairs.

Thanks for the question!

readygo586 commented 5 years ago

@intelliot @imerkle very thanks for you clarification.