|
|
@ -234,28 +234,22 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
static: { |
|
|
|
static: { |
|
|
|
eth_syncing: false, |
|
|
|
eth_syncing: false, |
|
|
|
web3_clientVersion: `MetaMask/v${version}`, |
|
|
|
web3_clientVersion: `MetaMask/v${version}`, |
|
|
|
eth_sendTransaction: (payload, next, end) => { |
|
|
|
|
|
|
|
const origin = payload.origin |
|
|
|
|
|
|
|
const txParams = payload.params[0] |
|
|
|
|
|
|
|
nodeify(this.txController.newUnapprovedTransaction, this.txController)(txParams, { origin }, end) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
// account mgmt
|
|
|
|
// account mgmt
|
|
|
|
getAccounts: async () => { |
|
|
|
getAccounts: async () => { |
|
|
|
const isUnlocked = this.keyringController.memStore.getState().isUnlocked |
|
|
|
const isUnlocked = this.keyringController.memStore.getState().isUnlocked |
|
|
|
const result = [] |
|
|
|
|
|
|
|
const selectedAddress = this.preferencesController.getSelectedAddress() |
|
|
|
const selectedAddress = this.preferencesController.getSelectedAddress() |
|
|
|
|
|
|
|
|
|
|
|
// only show address if account is unlocked
|
|
|
|
// only show address if account is unlocked
|
|
|
|
if (isUnlocked && selectedAddress) { |
|
|
|
if (isUnlocked && selectedAddress) { |
|
|
|
result.push(selectedAddress) |
|
|
|
return [selectedAddress] |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return [] |
|
|
|
} |
|
|
|
} |
|
|
|
return result |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
// tx signing
|
|
|
|
// tx signing
|
|
|
|
// old style msg signing
|
|
|
|
processTransaction: this.txController.newUnapprovedTransaction.bind(this.txController), |
|
|
|
processMessage: this.newUnsignedMessage.bind(this), |
|
|
|
// msg signing
|
|
|
|
// personal_sign msg signing
|
|
|
|
processEthSignMessage: this.newUnsignedMessage.bind(this), |
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
processTypedMessage: this.newUnsignedTypedMessage.bind(this), |
|
|
|
processTypedMessage: this.newUnsignedTypedMessage.bind(this), |
|
|
|
} |
|
|
|
} |
|
|
@ -634,20 +628,11 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
* @param {Object} msgParams - The params passed to eth_sign. |
|
|
|
* @param {Object} msgParams - The params passed to eth_sign. |
|
|
|
* @param {Function} cb = The callback function called with the signature. |
|
|
|
* @param {Function} cb = The callback function called with the signature. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
newUnsignedMessage (msgParams, cb) { |
|
|
|
newUnsignedMessage (msgParams, req) { |
|
|
|
const msgId = this.messageManager.addUnapprovedMessage(msgParams) |
|
|
|
const promise = this.messageManager.addUnapprovedMessageAsync(msgParams, req) |
|
|
|
this.sendUpdate() |
|
|
|
this.sendUpdate() |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
this.messageManager.once(`${msgId}:finished`, (data) => { |
|
|
|
return promise |
|
|
|
switch (data.status) { |
|
|
|
|
|
|
|
case 'signed': |
|
|
|
|
|
|
|
return cb(null, data.rawSig) |
|
|
|
|
|
|
|
case 'rejected': |
|
|
|
|
|
|
|
return cb(new Error('MetaMask Message Signature: User denied message signature.')) |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -701,24 +686,11 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
* @param {Function} cb - The callback function called with the signature. |
|
|
|
* @param {Function} cb - The callback function called with the signature. |
|
|
|
* Passed back to the requesting Dapp. |
|
|
|
* Passed back to the requesting Dapp. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
newUnsignedPersonalMessage (msgParams, cb) { |
|
|
|
async newUnsignedPersonalMessage (msgParams, req) { |
|
|
|
if (!msgParams.from) { |
|
|
|
const promise = this.personalMessageManager.addUnapprovedMessageAsync(msgParams, req) |
|
|
|
return cb(new Error('MetaMask Message Signature: from field is required.')) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams) |
|
|
|
|
|
|
|
this.sendUpdate() |
|
|
|
this.sendUpdate() |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
this.personalMessageManager.once(`${msgId}:finished`, (data) => { |
|
|
|
return promise |
|
|
|
switch (data.status) { |
|
|
|
|
|
|
|
case 'signed': |
|
|
|
|
|
|
|
return cb(null, data.rawSig) |
|
|
|
|
|
|
|
case 'rejected': |
|
|
|
|
|
|
|
return cb(new Error('MetaMask Message Signature: User denied message signature.')) |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -767,26 +739,11 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
* @param {Object} msgParams - The params passed to eth_signTypedData. |
|
|
|
* @param {Object} msgParams - The params passed to eth_signTypedData. |
|
|
|
* @param {Function} cb - The callback function, called with the signature. |
|
|
|
* @param {Function} cb - The callback function, called with the signature. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
newUnsignedTypedMessage (msgParams, cb) { |
|
|
|
newUnsignedTypedMessage (msgParams, req) { |
|
|
|
let msgId |
|
|
|
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req) |
|
|
|
try { |
|
|
|
this.sendUpdate() |
|
|
|
msgId = this.typedMessageManager.addUnapprovedMessage(msgParams) |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
this.sendUpdate() |
|
|
|
return promise |
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
return cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.typedMessageManager.once(`${msgId}:finished`, (data) => { |
|
|
|
|
|
|
|
switch (data.status) { |
|
|
|
|
|
|
|
case 'signed': |
|
|
|
|
|
|
|
return cb(null, data.rawSig) |
|
|
|
|
|
|
|
case 'rejected': |
|
|
|
|
|
|
|
return cb(new Error('MetaMask Message Signature: User denied message signature.')) |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|