mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
provider - update wallet hooks for new wallet middleware
This commit is contained in:
parent
68aa1cce5f
commit
aab9691c42
@ -69,10 +69,39 @@ module.exports = class MessageManager extends EventEmitter {
|
||||
* new Message to this.messages, and to save the unapproved Messages from that list to this.memStore.
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object possibly containing the origin
|
||||
* @returns {promise} after signature has been
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessageAsync (msgParams, req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const msgId = this.addUnapprovedMessage(msgParams, req)
|
||||
// await finished
|
||||
this.once(`${msgId}:finished`, (data) => {
|
||||
switch (data.status) {
|
||||
case 'signed':
|
||||
return resolve(data.rawSig)
|
||||
case 'rejected':
|
||||
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
default:
|
||||
return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Message with an 'unapproved' status using the passed msgParams. this.addMsg is called to add the
|
||||
* new Message to this.messages, and to save the unapproved Messages from that list to this.memStore.
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object where the origin may be specificied
|
||||
* @returns {number} The id of the newly created message.
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessage (msgParams) {
|
||||
addUnapprovedMessage (msgParams, req) {
|
||||
// add origin from request
|
||||
if (req) msgParams.origin = req.origin
|
||||
msgParams.data = normalizeMsgData(msgParams.data)
|
||||
// create txData obj with parameters and meta data
|
||||
var time = (new Date()).getTime()
|
||||
|
@ -73,11 +73,43 @@ module.exports = class PersonalMessageManager extends EventEmitter {
|
||||
* this.memStore.
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object possibly containing the origin
|
||||
* @returns {promise} When the message has been signed or rejected
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessageAsync (msgParams, req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!msgParams.from) {
|
||||
reject(new Error('MetaMask Message Signature: from field is required.'))
|
||||
}
|
||||
const msgId = this.addUnapprovedMessage(msgParams, req)
|
||||
this.once(`${msgId}:finished`, (data) => {
|
||||
switch (data.status) {
|
||||
case 'signed':
|
||||
return resolve(data.rawSig)
|
||||
case 'rejected':
|
||||
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
default:
|
||||
return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PersonalMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add
|
||||
* the new PersonalMessage to this.messages, and to save the unapproved PersonalMessages from that list to
|
||||
* this.memStore.
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object possibly containing the origin
|
||||
* @returns {number} The id of the newly created PersonalMessage.
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessage (msgParams) {
|
||||
addUnapprovedMessage (msgParams, req) {
|
||||
log.debug(`PersonalMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`)
|
||||
// add origin from request
|
||||
if (req) msgParams.origin = req.origin
|
||||
msgParams.data = this.normalizeMsgData(msgParams.data)
|
||||
// create txData obj with parameters and meta data
|
||||
var time = (new Date()).getTime()
|
||||
@ -257,4 +289,3 @@ module.exports = class PersonalMessageManager extends EventEmitter {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,40 @@ module.exports = class TypedMessageManager extends EventEmitter {
|
||||
* this.memStore. Before any of this is done, msgParams are validated
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object possibly containing the origin
|
||||
* @returns {promise} When the message has been signed or rejected
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessageAsync (msgParams, req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const msgId = this.addUnapprovedMessage(msgParams, req)
|
||||
this.once(`${msgId}:finished`, (data) => {
|
||||
switch (data.status) {
|
||||
case 'signed':
|
||||
return resolve(data.rawSig)
|
||||
case 'rejected':
|
||||
return reject(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
default:
|
||||
return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new TypedMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add
|
||||
* the new TypedMessage to this.messages, and to save the unapproved TypedMessages from that list to
|
||||
* this.memStore. Before any of this is done, msgParams are validated
|
||||
*
|
||||
* @param {Object} msgParams The params for the eth_sign call to be made after the message is approved.
|
||||
* @param {Object} req (optional) The original request object possibly containing the origin
|
||||
* @returns {number} The id of the newly created TypedMessage.
|
||||
*
|
||||
*/
|
||||
addUnapprovedMessage (msgParams) {
|
||||
addUnapprovedMessage (msgParams, req) {
|
||||
this.validateParams(msgParams)
|
||||
// add origin from request
|
||||
if (req) msgParams.origin = req.origin
|
||||
|
||||
log.debug(`TypedMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`)
|
||||
// create txData obj with parameters and meta data
|
||||
|
@ -234,28 +234,22 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
static: {
|
||||
eth_syncing: false,
|
||||
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
|
||||
getAccounts: async () => {
|
||||
const isUnlocked = this.keyringController.memStore.getState().isUnlocked
|
||||
const result = []
|
||||
const selectedAddress = this.preferencesController.getSelectedAddress()
|
||||
|
||||
// only show address if account is unlocked
|
||||
if (isUnlocked && selectedAddress) {
|
||||
result.push(selectedAddress)
|
||||
return [selectedAddress]
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
return result
|
||||
},
|
||||
// tx signing
|
||||
// old style msg signing
|
||||
processMessage: this.newUnsignedMessage.bind(this),
|
||||
// personal_sign msg signing
|
||||
processTransaction: this.txController.newUnapprovedTransaction.bind(this.txController),
|
||||
// msg signing
|
||||
processEthSignMessage: this.newUnsignedMessage.bind(this),
|
||||
processPersonalMessage: this.newUnsignedPersonalMessage.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 {Function} cb = The callback function called with the signature.
|
||||
*/
|
||||
newUnsignedMessage (msgParams, cb) {
|
||||
const msgId = this.messageManager.addUnapprovedMessage(msgParams)
|
||||
newUnsignedMessage (msgParams, req) {
|
||||
const promise = this.messageManager.addUnapprovedMessageAsync(msgParams, req)
|
||||
this.sendUpdate()
|
||||
this.opts.showUnconfirmedMessage()
|
||||
this.messageManager.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)}`))
|
||||
}
|
||||
})
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
@ -701,24 +686,11 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
* @param {Function} cb - The callback function called with the signature.
|
||||
* Passed back to the requesting Dapp.
|
||||
*/
|
||||
newUnsignedPersonalMessage (msgParams, cb) {
|
||||
if (!msgParams.from) {
|
||||
return cb(new Error('MetaMask Message Signature: from field is required.'))
|
||||
}
|
||||
|
||||
const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
|
||||
async newUnsignedPersonalMessage (msgParams, req) {
|
||||
const promise = this.personalMessageManager.addUnapprovedMessageAsync(msgParams, req)
|
||||
this.sendUpdate()
|
||||
this.opts.showUnconfirmedMessage()
|
||||
this.personalMessageManager.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)}`))
|
||||
}
|
||||
})
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
@ -767,26 +739,11 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
* @param {Object} msgParams - The params passed to eth_signTypedData.
|
||||
* @param {Function} cb - The callback function, called with the signature.
|
||||
*/
|
||||
newUnsignedTypedMessage (msgParams, cb) {
|
||||
let msgId
|
||||
try {
|
||||
msgId = this.typedMessageManager.addUnapprovedMessage(msgParams)
|
||||
this.sendUpdate()
|
||||
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)}`))
|
||||
}
|
||||
})
|
||||
newUnsignedTypedMessage (msgParams, req) {
|
||||
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req)
|
||||
this.sendUpdate()
|
||||
this.opts.showUnconfirmedMessage()
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -8210,9 +8210,9 @@
|
||||
}
|
||||
},
|
||||
"eth-json-rpc-middleware": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-2.1.1.tgz",
|
||||
"integrity": "sha512-uIMBZXMVN/ntnvNAN/o20gOFR7Ya23gg7S3jytdejpt/F6FKl25Y4zbyFrGhbt0oCKiYfECGln8pOlu6Zc8znw==",
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-2.2.0.tgz",
|
||||
"integrity": "sha512-P5TRtVRWYIVdhGFzLZoUFwOoS2r4rGhh2qxwPpeI8AcF+qj0EqgFHn22ts20XXqALTq+f7bmkwGEIE75e83pcw==",
|
||||
"requires": {
|
||||
"async": "2.6.0",
|
||||
"eth-query": "2.1.2",
|
||||
|
@ -97,7 +97,7 @@
|
||||
"eth-hd-keyring": "^1.2.1",
|
||||
"eth-json-rpc-filters": "^2.1.1",
|
||||
"eth-json-rpc-infura": "^3.0.0",
|
||||
"eth-json-rpc-middleware": "^2.1.1",
|
||||
"eth-json-rpc-middleware": "^2.2.0",
|
||||
"eth-keyring-controller": "^3.1.1",
|
||||
"eth-phishing-detect": "^1.1.4",
|
||||
"eth-query": "^2.1.2",
|
||||
|
Loading…
Reference in New Issue
Block a user