Skip to content

Commit

Permalink
Merge pull request #8 from NoahZinsmeister/erc191-v0-signatures
Browse files Browse the repository at this point in the history
Support ERC191 v0 signatures
  • Loading branch information
kumavis authored Mar 18, 2019
2 parents 20dbd74 + 02513fa commit bd882d1
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 bd882d1

Please sign in to comment.