Skip to content

Commit

Permalink
add typed data v0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed Dec 5, 2018
1 parent 072ae7a commit 02513fa
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function createWalletMiddleware(opts = {}) {
// parse + validate options
const getAccounts = opts.getAccounts
const processTypedMessage = opts.processTypedMessage
const processTypedMessageV0 = opts.processTypedMessageV0
const processTypedMessageV3 = opts.processTypedMessageV3
const processPersonalMessage = opts.processPersonalMessage
const processEthSignMessage = opts.processEthSignMessage
Expand All @@ -22,6 +23,7 @@ function createWalletMiddleware(opts = {}) {
// message signatures
'eth_sign': createAsyncMiddleware(ethSign),
'eth_signTypedData': createAsyncMiddleware(signTypedData),
'eth_signTypedData_v0': createAsyncMiddleware(signTypedDataV0),
'eth_signTypedData_v3': createAsyncMiddleware(signTypedDataV3),
'personal_sign': createAsyncMiddleware(personalSign),
'personal_ecRecover': createAsyncMiddleware(personalRecover),
Expand Down Expand Up @@ -91,6 +93,22 @@ function createWalletMiddleware(opts = {}) {
res.result = await processTypedMessage(msgParams, req, version)
}

async function signTypedDataV0 (req, res) {
if (!processTypedMessageV0) throw new Error('WalletMiddleware - opts.processTypedMessage not provided')
const from = req.from
const message = req.params[1]
const address = req.params[0]
const version = 'V0'
await validateSender(address, req)
await validateSender(from, req)
const msgParams = {
data: message,
from: address,
version
}
res.result = await processTypedMessageV0(msgParams, req, version)
}

async function signTypedDataV3 (req, res) {
if (!processTypedMessageV3) throw new Error('WalletMiddleware - opts.processTypedMessage not provided')
const from = req.from
Expand Down

0 comments on commit 02513fa

Please sign in to comment.