LemoChain Wallet
This is the LemoChain Wallet library which is used to manage private keys.
Installing
Using Yarn
yarn add lemo-wallet
As Browser module
- Include
lemo-wallet.js
in your html file. - Use the
LemoWallet
object directly from global namespace
Example
const LemoWallet = const wallet = storage: localStoragewalletconst account = walletconst txConfig = chainID: 1 to: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D' amount: '100000000000000000000'const signedTx = walletconsole// 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 |
Developing
Requirements
- Node.js
- yarn
sudo apt-get updatesudo apt-get install nodejssudo apt-get install yarn
data structure
account
account information
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
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
Constructor
wallet = new LemoWallet({
storage: localStorage
})
storage
Storage functions object. In the browser, it is localStorage or sessionStorage
API
wallet.setupPassword
wallet.setupPassword(password)
Create and save the password and store the encrypted password to storage
Parameters
string
- The password set by the user
Returns
None
Example
const pwd = '12345678'wallet
wallet.createAccount
wallet.createAccount(addressName, password)
Create account and return the generated account information.
Parameters
string
- account namestring
- The password that passed in the setupPassword
Returns
object
- Return account information. Details refer toaccount Information
Example
const password = '123AbC789'const result = walletconsole // {"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
wallet.importMnemonic(mnemonic, addressName, password)
Import mnemonic words, restore the account information
Parameters
string|array
- mnemonicstring
- addressNamestring
- The password that passed in the setupPassword
Returns
object
- Return account information. Details refer toaccount Information
Example
const password = '123AbC789'const mnemonic = 'minor' 'half' 'image' 'census' 'endless' 'save' 'wreck' 'fork' 'key' 'wear' 'famous' 'mail'const addressName = 'hello'const result = walletconsole // {"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
wallet.importPrivate(privKey, addressName, password)
Import the private key, restore the account information
Parameters
string
- privKeystring
- addressNamestring
- The password that passed in the setupPassword
Returns
object
- Return account information and no mnemonic. Details refer toaccount Information
Example
const password = '123AbC789'const priv = '0xb16043f818288c75627feb6ec52eb6246bfbf5dda2ce0055e499850423919a32'const name = 'hhh'const result = walletconsole // {"privKey":"0xb16043f818288c75627feb6ec52eb6246bfbf5dda2ce0055e499850423919a32","address":"Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ","addressName":"hhh","path":"m/44'/60'/0'/0"}
wallet.exportMnemonic
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
Parameters
string
- addressstring
- The password that passed in the setupPassword
Returns
array
- mnemonic
Example
const password = '123AbC789'const address = 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q'const result = walletconsole // ['certain', 'blade', 'someone', 'unusual', 'time', 'clarify', 'minute', 'airport', 'long', 'claw', 'roast', 'wink']
wallet.exportPrivateKey
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
Parameters
string
- addressstring
- The password that passed in the setupPassword
Returns
string
- PrivateKey
Example
const password = '123AbC789'const address = 'Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ'const result = walletconsole //"0xf9d8b666237ad79877cb8356c97f3aaa503700bb37a9c19767e97f059f0f9594"
wallet.getAccountList
wallet.getAccountList()
load account lists
Parameters
None
Returns
array
- account list, it includes the following fields:
string
addressNamestring
address
Example
const result = walletconsole // [ { addressName: 'hello',address: 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q' }, {addressName: 'demo',address: 'Lemo83B5737DA39JJHYJF8DBZ468S4GRAW7BNFAJ'} ]
wallet.sign
wallet.sign(address, txConfig, password)
Verify the password, sign transaction
Parameters
string
- addressobject
- The constructor params for lemo-txstring
- The password that passed in the setupPassword
Returns
LemoTx
- Signed LemoTx instance
Example
const txConfig = chainID: 100 from: 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q' to: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG' amount: '1000'const password = '123AbC789'const address = 'Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q'const result = wallet// {"type":"0","version":"1","chainID":"100","from":"Lemo83S826GC446HF2FWQ2895FP8J7ARQTKRGG3Q","gasPrice":"3000000000","gasLimit":"2000000","amount":"1000","expirationTime":"1566352964","to":"Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG","sigs":["0xab17544ad52e965c71c67458911bb025020f58de0b147dd22f614347ac8bbe70121ef1c174860eebb7f63c8e0ec1c9f47e6e76851be08950c92bb8dec906e90301"],"gasPayerSigs":[]}
wallet.modifyPassword
wallet.modifyPassword(oldPassword, newPassword)
Verify and change the password
Parameters
string
- old passwordstring
- new password
Returns
None
Example
const oldPassword = '123AbC789'const newPassword = 'aaaaaaa'wallet
wallet.deleteAccount
wallet.deleteAccount(address, password)
Verify password and delete account information
Parameters
string
- addressstring
- The password that passed in the setupPassword
Returns
None
Example
const address = 'Lemo83QTS9H6DDWRC77SG774PF46TD46YA8RCBD7'const password = '123AbC789'wallet
Building
yarn build
Testing
yarn test
Licensing
LGPL-3.0