Jeflopo
Jeflopo

Reputation: 2262

How should I properly create a Ripple Paper Wallet using Ripple-lib or an official api?

I'm trying to create a paper wallet using the official Ripple Api, ripple-lib.

The generateAddress() accepts some parameters.

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s1.ripple.com' // Public rippled server
});
api.connect().then(() => {
  return api.generateAddress();
}).then(info => {
  console.log(info);
  console.log('getAccountInfo done');

  /* end custom code -------------------------------------- */
}).then(() => {
  return api.disconnect();
}).then(() => {
  console.log('done and disconnected.');
}).catch(console.error);

This code actually creates a Secret key and an "Address".

{
  secret: 'sheWb..................HRyLhk',
  address: 'rNLJ.......................qu3nbb'
}

Ok. Now I have my account created. And If I fund it with the 20XRP Reserve it would become an active Ripple account. Yay !

But I don't understand:

May anyone sheed some light to these concerns ?

EDIT: I think now that the options object passed to generateAddress() is the same options parameter passed to the constructor RippleApi() described here https://ripple.com/build/rippleapi/#parameters May anyone confirm this ?

Upvotes: 1

Views: 1974

Answers (2)

SimpleXRPTools
SimpleXRPTools

Reputation: 11

The generateAddress() methods accepts three parameters. Described here: https://ripple.com/build/rippleapi/#generateaddress But I don't have a clue on how to write those parameters. I'm interested on this because I think that in the first parameter, the "options" object is where I could define the passphrase for the secret key. Maybe I'm wrong.

Here's some javascript code to demonstrate the input of entropy into the generateAddress method.

// This functions works on modern browswers, not sure about Node.js. Try https://www.npmjs.com/package/js-sha512 or https://nodejs.org/api/crypto.html
async function fun_SHA512_array(entropy) {
    'use strict';

    // Turns a string into an array of integers.
    // Made possible by https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest

    const msgUint8 = new TextEncoder().encode(entropy);                           // encode as (utf-8) Uint8Array
    const hashBuffer = await crypto.subtle.digest('SHA-512', msgUint8);           // hash the message
    const hashArray = Array.from(new Uint8Array(hashBuffer));                     // convert buffer to byte array
    // const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string

    return hashArray;
}

const str_entropy = "Use a cryptographically strong, randomly created string of characters here.";
// Or, your passphrase string would go here.
// Or, you could use a BIP39 Mnemonic but you'd have to remember how you constructed the string. e.g. Did you separate the words with a comma or with a space?
// Or, on the linux terminal you can use: openssl rand -base64 n
// Where n = the number of characters you wish to randomly generate. Which are then converted to base64, therefore the amount of characters ends up being more than n.

var array_sha512 = [];

fun_SHA512_array(str_entropy).then(array_sha512 => {
    var obj_new_account = api.generateAddress({"entropy": array_sha512});
    var str_secret = obj_new_account.secret;
    var str_public_address = obj_new_account.address;

    console.log(str_secret);
    console.log(str_public_address);
});

Remember, the entropy is like a seed and will always generate the same secret and address.

Upvotes: 1

Viacheslav Bakshaev
Viacheslav Bakshaev

Reputation: 272

For paper wallet what you need is only address(public) and secret(private):

https://github.com/Bithomp/xrp-paper-wallet

Actually, only secret would be enough, as you can get an address from the secret.

https://github.com/Bithomp/bithomp-tools

In Ripple you not have to use a new account for each new order/user. For each new transaction you can use a destination tag. That's how you can identify customer/order. Ripple also supports a key rotation, so if master key got exposed you can disable it and use a regular key. In best practices you assign a regular key and use it to sign transactions online, and master key always offline. If a regular key got exposed, you can replace it with a new regular key.

In ripple you can sign transactions with a keypair (public key + private key), or with the secret.

you can get keypairs for ripple here https://iancoleman.io/bip39/

ripple-lib's generateAddress() gives you:

1) a ripple address (your public address) starts with r

you can share it, it can be used to send you payments. You can search for the public address in the explorer.

for example: https://bithomp.com/explorer/r9fVvKgMMPkBHQ3n28sifxi22zKphwkf8u

2) a secret - a master key, which will be used to sign transactions.

3) You can also assign a regular key (https://developers.ripple.com/assign-a-regular-key-pair.html)

Options has only two parameters:

  • algorithm string, The digital signature algorithm to generate an address for. Can be ecdsa-secp256k1 (default) or ed25519.

  • entropy array\integer, The entropy to use to generate the seed.

hope it helps..

Upvotes: 1

Related Questions