Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I new a account use password? #16

Open
Musk66 opened this issue Mar 26, 2018 · 5 comments
Open

How can I new a account use password? #16

Musk66 opened this issue Mar 26, 2018 · 5 comments

Comments

@Musk66
Copy link

Musk66 commented Mar 26, 2018

Hi,how can I add a account use password?I only use the method 'randomMnemonicAccoun',but how can I know the phrase?I want to use phase to add a account.

@ricmoo
Copy link
Member

ricmoo commented Mar 26, 2018

Here is a quick example of what you are trying to do:

var wallet = Wallet.createRandom()
console.log(wallet.mnemonic)
// front chair enroll shrug twin expand forest magnet ice magic sport diet
console.log(wallet.mnemonic)
// "m/44'/60'/0'/0/0"
wallet.encrypt('password123').then(function(json) { console.log(json); })
// {"address":"ce218cf9f551848292becabd20c2d0270777173f","id":"24ae1c9d-3277-44d5-852a-5bd109c1f6b5","version":3,"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"41e9fbcbb087bf41f34de7009a16fb3f"},"ciphertext":"4b50c613404c7d8ffa0c3f549f40e5aef08fc7125c5e0f608d531090c8a7636d","kdf":"scrypt","kdfparams":{"salt":"1f338ad7089f4de9d3479f899ee212707e5c28225ec9437c637505c1898e2321","n":131072,"dklen":32,"p":1,"r":8},"mac":"a7652cf43d85e5e110657d6425ac4711802370c360016f64b2fa45bf65818a65"},"x-ethers":{"client":"ethers.js","gethFilename":"UTC--2018-03-26T02-57-52.0Z--ce218cf9f551848292becabd20c2d0270777173f","mnemonicCounter":"3a98a527914f611046a994eee976f436","mnemonicCiphertext":"2a95aba57f66b2051a3aefad605253dd","version":"0.1"}}

@ricmoo
Copy link
Member

ricmoo commented Mar 26, 2018

Oh! Sorry... That was for ethers.js.

@ricmoo
Copy link
Member

ricmoo commented Mar 26, 2018

Here is the example for ethers.objc (sorry, most questions are for my JavaScript version and I didn't notice the repo):

Account *account = [Account randomMnemonicAccount];
NSLog(@"Menonic Phrase: %@", account.mnemonicPhrase);
[account encryptSecretStorageJSON: @"password123" callback: ^(NSString json) {
    NSLog(@"Password encrypted JSON: %@", json);
}];

@Musk66
Copy link
Author

Musk66 commented Mar 27, 2018

Thanks.It works when I used this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ricmoo @Musk66 and others