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

External accounts implemented for issue #5640 #6007

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -687,6 +697,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 @@ -943,6 +962,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 @@ -1001,6 +1024,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 @@ -441,6 +445,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 @@ -880,6 +885,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