|
|
@ -150,12 +150,13 @@ module.exports = class KeyringController extends EventEmitter { |
|
|
|
mnemonic: seed, |
|
|
|
mnemonic: seed, |
|
|
|
numberOfAccounts: 1, |
|
|
|
numberOfAccounts: 1, |
|
|
|
}) |
|
|
|
}) |
|
|
|
}).then(() => { |
|
|
|
}) |
|
|
|
const firstKeyring = this.keyrings[0] |
|
|
|
.then((firstKeyring) => { |
|
|
|
return firstKeyring.getAccounts() |
|
|
|
return firstKeyring.getAccounts() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((accounts) => { |
|
|
|
.then((accounts) => { |
|
|
|
const firstAccount = accounts[0] |
|
|
|
const firstAccount = accounts[0] |
|
|
|
|
|
|
|
if (!firstAccount) throw new Error('KeyringController - First Account not found.') |
|
|
|
const hexAccount = normalize(firstAccount) |
|
|
|
const hexAccount = normalize(firstAccount) |
|
|
|
this.configManager.setSelectedAccount(hexAccount) |
|
|
|
this.configManager.setSelectedAccount(hexAccount) |
|
|
|
return this.setupAccounts(accounts) |
|
|
|
return this.setupAccounts(accounts) |
|
|
@ -164,25 +165,6 @@ module.exports = class KeyringController extends EventEmitter { |
|
|
|
.then(this.fullUpdate.bind(this)) |
|
|
|
.then(this.fullUpdate.bind(this)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// PlaceSeedWords
|
|
|
|
|
|
|
|
// returns Promise( @object state )
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Adds the current vault's seed words to the UI's state tree.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Used when creating a first vault, to allow confirmation.
|
|
|
|
|
|
|
|
// Also used when revealing the seed words in the confirmation view.
|
|
|
|
|
|
|
|
placeSeedWords () { |
|
|
|
|
|
|
|
const hdKeyrings = this.keyrings.filter((keyring) => keyring.type === 'HD Key Tree') |
|
|
|
|
|
|
|
const firstKeyring = hdKeyrings[0] |
|
|
|
|
|
|
|
if (!firstKeyring) throw new Error('KeyringController - No HD Key Tree found') |
|
|
|
|
|
|
|
return firstKeyring.serialize() |
|
|
|
|
|
|
|
.then((serialized) => { |
|
|
|
|
|
|
|
const seedWords = serialized.mnemonic |
|
|
|
|
|
|
|
this.configManager.setSeedWords(seedWords) |
|
|
|
|
|
|
|
return this.fullUpdate() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ClearSeedWordCache
|
|
|
|
// ClearSeedWordCache
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// returns Promise( @string currentSelectedAccount )
|
|
|
|
// returns Promise( @string currentSelectedAccount )
|
|
|
@ -259,9 +241,8 @@ module.exports = class KeyringController extends EventEmitter { |
|
|
|
// Calls the `addAccounts` method on the Keyring
|
|
|
|
// Calls the `addAccounts` method on the Keyring
|
|
|
|
// in the kryings array at index `keyringNum`,
|
|
|
|
// in the kryings array at index `keyringNum`,
|
|
|
|
// and then saves those changes.
|
|
|
|
// and then saves those changes.
|
|
|
|
addNewAccount (keyRingNum = 0) { |
|
|
|
addNewAccount (selectedKeyring) { |
|
|
|
const ring = this.keyrings[keyRingNum] |
|
|
|
return selectedKeyring.addAccounts(1) |
|
|
|
return ring.addAccounts(1) |
|
|
|
|
|
|
|
.then(this.setupAccounts.bind(this)) |
|
|
|
.then(this.setupAccounts.bind(this)) |
|
|
|
.then(this.persistAllKeyrings.bind(this)) |
|
|
|
.then(this.persistAllKeyrings.bind(this)) |
|
|
|
.then(this.fullUpdate.bind(this)) |
|
|
|
.then(this.fullUpdate.bind(this)) |
|
|
@ -426,18 +407,17 @@ module.exports = class KeyringController extends EventEmitter { |
|
|
|
// puts the current seed words into the state tree.
|
|
|
|
// puts the current seed words into the state tree.
|
|
|
|
createFirstKeyTree () { |
|
|
|
createFirstKeyTree () { |
|
|
|
this.clearKeyrings() |
|
|
|
this.clearKeyrings() |
|
|
|
return this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1}) |
|
|
|
return this.addNewKeyring('HD Key Tree', { numberOfAccounts: 1 }) |
|
|
|
.then(() => { |
|
|
|
.then((keyring) => { |
|
|
|
return this.keyrings[0].getAccounts() |
|
|
|
return keyring.getAccounts() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((accounts) => { |
|
|
|
.then((accounts) => { |
|
|
|
const firstAccount = accounts[0] |
|
|
|
const firstAccount = accounts[0] |
|
|
|
|
|
|
|
if (!firstAccount) throw new Error('KeyringController - No account found on keychain.') |
|
|
|
const hexAccount = normalize(firstAccount) |
|
|
|
const hexAccount = normalize(firstAccount) |
|
|
|
this.configManager.setSelectedAccount(hexAccount) |
|
|
|
this.configManager.setSelectedAccount(hexAccount) |
|
|
|
this.emit('newAccount', hexAccount) |
|
|
|
this.emit('newAccount', hexAccount) |
|
|
|
return this.setupAccounts(accounts) |
|
|
|
return this.setupAccounts(accounts) |
|
|
|
}).then(() => { |
|
|
|
|
|
|
|
return this.placeSeedWords() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(this.persistAllKeyrings.bind(this)) |
|
|
|
.then(this.persistAllKeyrings.bind(this)) |
|
|
|
} |
|
|
|
} |
|
|
@ -587,6 +567,10 @@ module.exports = class KeyringController extends EventEmitter { |
|
|
|
return this.keyringTypes.find(kr => kr.type === type) |
|
|
|
return this.keyringTypes.find(kr => kr.type === type) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getKeyringsByType (type) { |
|
|
|
|
|
|
|
return this.keyrings.filter((keyring) => keyring.type === type) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get Accounts
|
|
|
|
// Get Accounts
|
|
|
|
// returns Promise( @Array[ @string accounts ] )
|
|
|
|
// returns Promise( @Array[ @string accounts ] )
|
|
|
|
//
|
|
|
|
//
|
|
|
|