Managing Identities
Create new identity
This creates a new keystore with 10 addresses, encrypted by the given password.
const Datum = require('datum-sdk');
let ident = new Datum().Identity();
ident.new("YourPassword", 10).then(wallet => {
//wallet contains an array of addresses and the used seed to
console.log(wallet);
}).catch(error => {
console.log(error);
});
Result
{ addresses:
[ '0xd6e592467ce32446914f9e897fb0281dcab9f128',
'0x624eb19b59dfd9f97a958b4b7673e74f970759e3',
'0x3abeb834391dfcc473574f41d89ffe604523b8c6',
'0x596e1fc17f307342d47aa51d91017883dd0362c2',
'0x161685fb854e6ebb4f75215fa0a8fa62aed67520',
'0x0b3a7ec1df4675ceb0097dd31d11c5e413b1db53',
'0x4c3c28d42c6a9040a0d6a0799f9ab979a5334d89',
'0xbf2fed1c5555069e5c7e879711c54cb690b81a12',
'0x024ce0582106ee19d41057953c40d33f9ead6185',
'0x2cf06d7c97b8b76d07d4e5721c6dfba9c5e4de76' ],
seed: 'cross alter client awake ripple simple crew super two antenna sad dune' }
Recover from seed
Recover a keystore from given seed
const Datum = require('datum-sdk');
let ident = new Datum().Identity();
var seedStoredSafe = 'cross alter client awake ripple simple crew super two antenna sad dune';
ident.recover(seedStoredSafe, "NewPassword", 5).then(wallet => {
//wallet contains an array of addresses and the used seed to
console.log(wallet);
}).catch(error => {
console.log(error);
});
Result
{ addresses:
[ '0xd6e592467ce32446914f9e897fb0281dcab9f128',
'0x624eb19b59dfd9f97a958b4b7673e74f970759e3',
'0x3abeb834391dfcc473574f41d89ffe604523b8c6',
'0x596e1fc17f307342d47aa51d91017883dd0362c2',
'0x161685fb854e6ebb4f75215fa0a8fa62aed67520' ] }
Export keystore
Export the generated keystore to save e.g. in localStorage
const Datum = require('datum-sdk');
let ident = new Datum().Identity();
ident.new("YourPassword", 5).then(wallet => {
//wallet contains an array of addresses and the used seed to
var serializedKeyStore = ident.export();
console.log(serializedKeyStore);
}).catch(error => {
console.log(error);
});
Result
{"encSeed":{"encStr":"9knIh02UCmiT6WSuzf+cBeNzz8PDgwuVSH2l803Y6noUTEPRt6DnodMkF7VG6qJMzRR8jdpfz2CJSSzF2bN+9oyorvHIfuOL2S2DhAxNGHCq549bohjegvWEl0G1D1+3oLcRzGg/ayLgLATlzzFi6/m1YumklJ97d1eEd//uEAa2wRaXXu8QWA==","nonce":"IFOaInTX1ISpM8TCDUYxSZXTPJpOEkIS"},"encHdRootPriv":{"encStr":"qU7GbAVwODfYIiPjZohggFVcPiA0CdHyp8NW1Vu5nmLFUVOJL9CTyryOV/qrilKs2QxslznoiDFEU5fAd+BFCBOKuxQCTRx4ZWGMAhXWGrNFqzzTf2/RwwkiBKC0bdvdPFazmPphR94cKLuDsfXi2t8FCwe9MgfhbwHjWmqDWA==","nonce":"90o9rGauc4mihE1KBF/386dDE4YmVBPJ"},"addresses":["76dcac0bcd42f775bd7d676c0cab6dd5e8584f7d","aa5b4883a5027f944da97df58e287a80b8e892b7"],"encPrivKeys":{"76dcac0bcd42f775bd7d676c0cab6dd5e8584f7d":{"key":"M6p75QXb5RqEto8aV68GER23s+2z9Y52N9OR/Jt/8eLW1vi3nc3n4yzmVkL4Alik","nonce":"QhBsyE+6OhfTJifJtxnrgi1PhdFPTfjf"},"aa5b4883a5027f944da97df58e287a80b8e892b7":{"key":"QayPohF5tbaN7mW2WNyXkQ/aUNAvVVfnbbM7foSttBCo/sqSfRGazVz0XKYZ5Hfg","nonce":"IrhLst9PxIxIqrXKlK2U6atHIQh6TppX"}},"hdPathString":"m/44'/60'/0'/0","salt":"/uxYHccDVI95IjQwi2iIgobkTEfmgkAAvACwQCHJlq8=","hdIndex":2,"version":3}
Import Keystore
You can import a serialized keystore either directly with the constructor or the import method
const Datum = require('datum-sdk');
let ident = new Datum().Identity();
var savedKeystore = JSON.stringify({"encSeed":{"encStr":"9knIh02UCmiT6WSuzf+cBeNzz8PDgwuVSH2l803Y6noUTEPRt6DnodMkF7VG6qJMzRR8jdpfz2CJSSzF2bN+9oyorvHIfuOL2S2DhAxNGHCq549bohjegvWEl0G1D1+3oLcRzGg/ayLgLATlzzFi6/m1YumklJ97d1eEd//uEAa2wRaXXu8QWA==","nonce":"IFOaInTX1ISpM8TCDUYxSZXTPJpOEkIS"},"encHdRootPriv":{"encStr":"qU7GbAVwODfYIiPjZohggFVcPiA0CdHyp8NW1Vu5nmLFUVOJL9CTyryOV/qrilKs2QxslznoiDFEU5fAd+BFCBOKuxQCTRx4ZWGMAhXWGrNFqzzTf2/RwwkiBKC0bdvdPFazmPphR94cKLuDsfXi2t8FCwe9MgfhbwHjWmqDWA==","nonce":"90o9rGauc4mihE1KBF/386dDE4YmVBPJ"},"addresses":["76dcac0bcd42f775bd7d676c0cab6dd5e8584f7d","aa5b4883a5027f944da97df58e287a80b8e892b7"],"encPrivKeys":{"76dcac0bcd42f775bd7d676c0cab6dd5e8584f7d":{"key":"M6p75QXb5RqEto8aV68GER23s+2z9Y52N9OR/Jt/8eLW1vi3nc3n4yzmVkL4Alik","nonce":"QhBsyE+6OhfTJifJtxnrgi1PhdFPTfjf"},"aa5b4883a5027f944da97df58e287a80b8e892b7":{"key":"QayPohF5tbaN7mW2WNyXkQ/aUNAvVVfnbbM7foSttBCo/sqSfRGazVz0XKYZ5Hfg","nonce":"IrhLst9PxIxIqrXKlK2U6atHIQh6TppX"}},"hdPathString":"m/44'/60'/0'/0","salt":"/uxYHccDVI95IjQwi2iIgobkTEfmgkAAvACwQCHJlq8=","hdIndex":2,"version":3});
ident.import(savedKeystore);
console.log(ident.addresses);
Result
[ '0x76dcac0bcd42f775bd7d676c0cab6dd5e8584f7d',
'0xaa5b4883a5027f944da97df58e287a80b8e892b7' ]
Sign message
Signs a message with actual keystore
const Datum = require('datum-sdk');
let ident = new Datum().Identity();
ident.new("YourPassword", 5).then(wallet => {
//wallet contains an array of addresses and the used seed to
return ident.signMsg("Test Message to sign","YourPassword");
}).then(signedMainAddress => {
console.log(signedMainAddress);
return ident.signMsg("Test Message to sign","YourPassword",1);
}).then(signedSecondAddress => {
console.log(signedSecondAddress);
}).catch(error => {
console.log(error);
});
Result
{ r: <Buffer d4 04 4a 57 82 13 86 d3 01 04 e1 94 13 3f c3 7d b4 82 8a 00 1b cb 33 ee 54 d5 34 76 32 53 6e 86>,
s: <Buffer 59 70 4c 62 07 50 9f 49 41 a1 ec 20 66 42 fa 16 4e 2c cc 0e d9 dc 73 5a d6 6c 1b 34 f6 05 46 91>,
v: 27 }