This is the LemoChain Wallet library which is used to manage private keys.
yarn add lemo-wallet
- Include
lemo-wallet.js
in your html file. - Use the
LemoWallet
object directly from global namespace
const LemoWallet = require('lemo-wallet')
const wallet = new LemoWallet({storage: localStorage})
wallet.setupPassword('12345678')
const account = wallet.createAccount('my-wallet', '12345678')
const txConfig = {chainID: 1, to: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', amount: '100000000000000000000'}
const signedTx = wallet.sign(account.address, txConfig, '12345678')
console.log(signedTx.toString())
// send the signedTx by lemo client SDK
##lemoWallet API
API | description |
---|---|
wallet.setupPassword(password) | Setup wallet password |
wallet.createAccount(addressName, password) | Create account |
wallet.importMnemonic(mnemonic, addressName, password) | Restore the account information by import mnemonic words |
wallet.importPrivate(privKey, addressName, password) | Restore the account information by import the private key |
wallet.exportMnemonic(address, password) | Export mnemonic words |
wallet.exportPrivateKey(address, password) | Export the private key |
wallet.getAccountList() | Load the account list |
wallet.sign(address, txConfig, password) | Sign transaction |
wallet.modifyPassword(oldPassword, newPassword) | Modify password |
wallet.deleteAccount(address, password) | Delete account information |
- Node.js
- yarn
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install yarn
account information
{
"address": "Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D",
"addressName": "hello",
"privateKey": "U2FsdGVkX19E0h17Y2dqcLra30FgPy79GdKnGMdvEVKvDL2k0Ve1hFK4EPKDq+cJJwxMX2IG8KJhTN3JqrRIwL4RI6Xiq3tWioNKsxScQq9X8cQn2prblWvBrmeSZsAL",
"mnemonic": "U2FsdGVkX1/TQI6vcK/OXAfUHgy/XsdYnMPAADurRoI/YDDPUqiGC06D4xhihAmFoc7VRe2a1CSaAhCK0IwpuBlLkiaFchoXkbv4hjjTY62DZh+3w6vDTRfGSOdFRQ1w",
"basePath": "m/44\'/60\'/0\'/0",
}
address
lemoChain addressaddressName
account nameprivateKey
private key, Save as encrypted private key informationmnemonic
mnemonic, which consisting of 12 lowercase English words, encrypted and saved in storage.basePath
path, path to generate the private key
Storage functions object
setItem(key, value)
The function to store data into storage, both parameters are stringsgetItem(key)
Get the data stored in storage by key. The argument and return value are both strings
wallet = new LemoWallet({
storage: localStorage
})
storage
Storage functions object. In the browser, it is localStorage or sessionStorage
wallet.setupPassword(password)
Create and save the password and store the encrypted password to storage
string
- The password set by the user
None
const pwd = '12345678'
wallet.setupPassword(pwd)
wallet.createAccount(addressName, password)
Create account and return the generated account information.
string
- account namestring
- The password that passed in the setupPassword
object
- Return account information. Details refer toaccount Information
const password = '123AbC789'
const result = wallet.createAccount('hello', password)
console.log(JSON.stringify(result)) // {"privKey":"0xf9d8b666237ad79877cb8356c97f3aaa503700bb37a9c19767e97f059f0f9594","address":"Lemo83ZS6A5JFYQCHJJSZSSDKP2H26Z5FFRR5447","mnemonic":"reject job eight parade push miss honey leave pact genuine ivory put","addressName":"hello","path":"m/44'/60'/0'/0"}
wallet.importMnemonic(mnemonic, addressName, password)
Import mnemonic words, restore the account information
string|array
- mnemonicstring
- addressNamestring
- The password that passed in the setupPassword
object
- Return account information. Details refer toaccount Information
const password = '123AbC789'
const mnemonic = ['minor', 'half', 'image', 'census', 'endless', 'save', 'wreck', 'fork', 'key', 'wear', 'famous', 'mail']
const addressName = 'hello'
const result = wallet.importMnemonic(mnemonic, addressName, password)
console.log(JSON.stringify(result)) // {"privKey":"0xb16043f818288c75627feb6ec52eb6246bfbf5dda2ce0055e499850423919a32","address":"Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ","mnemonic":["minor","half","image","census","endless","save","wreck","fork","key","wear","famous","mail"],"addressName":"hello","path":"m/44'/60'/0'/0"}
wallet.importPrivate(privKey, addressName, password)
Import the private key, restore the account information
string
- privKeystring
- addressNamestring
- The password that passed in the setupPassword
object
- Return account information and no mnemonic. Details refer toaccount Information
const password = '123AbC789'
const priv = '0xb16043f818288c75627feb6ec52eb6246bfbf5dda2ce0055e499850423919a32'
const name = 'hhh'
const result = wallet.importPrivate(priv, name, password)
console.log(JSON.stringify(result)) // {"privKey":"0xb16043f818288c75627feb6ec52eb6246bfbf5dda2ce0055e499850423919a32","address":"Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ","addressName":"hhh","path":"m/44'/60'/0'/0"}
wallet.exportMnemonic(address, password)
Verify the user's password, find the user's locally stored account information through the account address, and export the mnemonic
string
- addressstring
- The password that passed in the setupPassword
array
- mnemonic
const password = '123AbC789'
const address = 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q'
const result = wallet.exportMnemonic(address, password)
console.log(result) // ['certain', 'blade', 'someone', 'unusual', 'time', 'clarify', 'minute', 'airport', 'long', 'claw', 'roast', 'wink']
wallet.exportPrivateKey(address, password)
Verify the user password, find the user's locally stored account information through the account address, and then export the private key
string
- addressstring
- The password that passed in the setupPassword
string
- PrivateKey
const password = '123AbC789'
const address = 'Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ'
const result = wallet.exportPrivateKey(address, password)
console.log(result) //"0xf9d8b666237ad79877cb8356c97f3aaa503700bb37a9c19767e97f059f0f9594"
wallet.getAccountList()
load account lists
None
array
- account list, it includes the following fields:
string
addressNamestring
address
const result = wallet.getAccountList()
console.log(result) // [ { addressName: 'hello',address: 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q' }, {addressName: 'demo',address: 'Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ'} ]
wallet.sign(address, txConfig, password)
Verify the password, sign transaction
string
- addressobject
- The constructor params for lemo-txstring
- The password that passed in the setupPassword
LemoTx
- Signed LemoTx instance
const txConfig = {
chainID: 100,
from: 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q',
to: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG',
amount: '1000',
}
const password = '123AbC789'
const address = 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q'
const result = wallet.sign(address, txConfig, password)// {"type":"0","version":"1","chainID":"100","from":"Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q","gasPrice":"3000000000","gasLimit":"2000000","amount":"1000","expirationTime":"1566352964","to":"Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG","sigs":["0xab17544ad52e965c71c67458911bb025020f58de0b147dd22f614347ac8bbe70121ef1c174860eebb7f63c8e0ec1c9f47e6e76851be08950c92bb8dec906e90301"],"gasPayerSigs":[]}
wallet.modifyPassword(oldPassword, newPassword)
Verify and change the password
string
- old passwordstring
- new password
None
const oldPassword = '123AbC789'
const newPassword = 'aaaaaaa'
wallet.modifyPassword(oldPassword, newPassword)
wallet.deleteAccount(address, password)
Verify password and delete account information
string
- addressstring
- The password that passed in the setupPassword
None
const address = 'Lemo83QTS9H6DDWRC77SG774PF46TD46YA8RCBD7'
const password = '123AbC789'
wallet.deleteAccount(address, password)
yarn build
yarn test
LGPL-3.0