Skip to content

Commit

Permalink
Issue MetaMask#5640 external accounts implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
r001 committed Dec 15, 2018
1 parent 30a2be8 commit 6d79056
Show file tree
Hide file tree
Showing 23 changed files with 1,065 additions and 145 deletions.
26 changes: 26 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"exposeDescription": {
"message": "Expose accounts to the current website. Useful for legacy dapps."
},
"external": {
"message": "External"
},
"externalAcc": {
"message": "External Account",
"description": "select this for entering external account without password"
},
"externalAccountMsg": {
"message": "External accounts will not be associated with your originally created MetaMask account seedphrase. When you want to confirm a transaction with external account, Metamask will provide transaction details and expects a valid signature from external signer app."
},
"confirmExpose": {
"message": "Are you sure you want to expose your accounts to the current website?"
},
Expand Down Expand Up @@ -663,6 +673,15 @@
"invalidSeedPhrase": {
"message": "Invalid seed phrase"
},
"invalidSignature": {
"message": "Invalid signature"
},
"invalidSignatureLength": {
"message": "Length should be 130 chars."
},
"invalidSignatureChar": {
"message": "Invalid character in signature."
},
"jsonFail": {
"message": "Something went wrong. Please make sure your JSON file is properly formatted."
},
Expand Down Expand Up @@ -916,6 +935,10 @@
"message": "Paste your private key string here:",
"description": "For importing an account from a private key"
},
"pasteExternalAccount": {
"message": "Paste your external account address here:",
"description": "For importing an external account from account number"
},
"pasteSeed": {
"message": "Paste your seed phrase here!"
},
Expand Down Expand Up @@ -974,6 +997,9 @@
"recipientAddress": {
"message": "Recipient Address"
},
"signature": {
"message": "Signature"
},
"refundAddress": {
"message": "Your Refund Address"
},
Expand Down
24 changes: 23 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ module.exports = class MetamaskController extends EventEmitter {
})

// key mgmt
const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring]
const additionalKeyrings = [
TrezorKeyring,
LedgerBridgeKeyring,
]
this.keyringController = new KeyringController({
keyringTypes: additionalKeyrings,
initState: initState.KeyringController,
Expand Down Expand Up @@ -401,6 +404,7 @@ module.exports = class MetamaskController extends EventEmitter {
resetAccount: nodeify(this.resetAccount, this),
removeAccount: nodeify(this.removeAccount, this),
importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
addExtAccount: nodeify(this.addExtAccount, this),

// hardware wallets
connectHardware: nodeify(this.connectHardware, this),
Expand Down Expand Up @@ -438,6 +442,7 @@ module.exports = class MetamaskController extends EventEmitter {
createNewVaultAndRestore: nodeify(this.createNewVaultAndRestore, this),
addNewKeyring: nodeify(keyringController.addNewKeyring, keyringController),
exportAccount: nodeify(keyringController.exportAccount, keyringController),
updateExternalSign: nodeify(keyringController.updateExternalSign, keyringController),

// txController
cancelTransaction: nodeify(txController.cancelTransaction, txController),
Expand Down Expand Up @@ -877,6 +882,23 @@ module.exports = class MetamaskController extends EventEmitter {
await this.preferencesController.setSelectedAddress(accounts[0])
}

/**
* Creates and external account and adds it to a newly created
* ExternalAccountKeyring.
*
* @param {string} address - A valid Ethereum address string.
*/
async addExtAccount (address) {
if (!ethUtil.isValidAddress(address)) throw new Error('Address is invalid.')
const keyring = await this.keyringController.addNewKeyring('External Account', [ address ])
const accounts = await keyring.getAccounts()
// update accounts in preferences controller
const allAccounts = await this.keyringController.getAccounts()
this.preferencesController.setAddresses(allAccounts)
// set new account as selected
await this.preferencesController.setSelectedAddress(accounts[0])
}

// ---------------------------------------------------------------------------
// Identity Management (signature operations)

Expand Down
Loading

0 comments on commit 6d79056

Please sign in to comment.