@metamask/eth-ledger-bridge-keyring
Advanced tools
Comparing version 0.4.0 to 0.5.0
50
index.js
@@ -288,3 +288,3 @@ const { EventEmitter } = require('events') | ||
} else { | ||
reject(new Error(payload.error || 'Ledger: Uknown error while signing message')) | ||
reject(new Error(payload.error || 'Ledger: Unknown error while signing message')) | ||
} | ||
@@ -313,4 +313,48 @@ }) | ||
signTypedData () { | ||
throw new Error('Not supported on this device') | ||
async signTypedData (withAccount, data, options = {}) { | ||
const isV4 = options.version === 'V4' | ||
if (!isV4) { | ||
throw new Error('Ledger: Only version 4 of typed data signing is supported') | ||
} | ||
const { | ||
domain, | ||
types, | ||
primaryType, | ||
message, | ||
} = sigUtil.TypedDataUtils.sanitizeData(data) | ||
const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct('EIP712Domain', domain, types, isV4).toString('hex') | ||
const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(primaryType, message, types, isV4).toString('hex') | ||
const hdPath = await this.unlockAccountByAddress(withAccount) | ||
const { success, payload } = await new Promise((resolve) => { | ||
this._sendMessage({ | ||
action: 'ledger-sign-typed-data', | ||
params: { | ||
hdPath, | ||
domainSeparatorHex, | ||
hashStructMessageHex, | ||
}, | ||
}, | ||
(result) => resolve(result)) | ||
}) | ||
if (success) { | ||
let v = payload.v - 27 | ||
v = v.toString(16) | ||
if (v.length < 2) { | ||
v = `0${v}` | ||
} | ||
const signature = `0x${payload.r}${payload.s}${v}` | ||
const addressSignedWith = sigUtil.recoverTypedSignature_v4({ | ||
data, | ||
sig: signature, | ||
}) | ||
if (ethUtil.toChecksumAddress(addressSignedWith) !== ethUtil.toChecksumAddress(withAccount)) { | ||
throw new Error('Ledger: The signature doesnt match the right address') | ||
} | ||
return signature | ||
} | ||
throw new Error(payload.error || 'Ledger: Unknown error while signing message') | ||
} | ||
@@ -317,0 +361,0 @@ |
{ | ||
"name": "@metamask/eth-ledger-bridge-keyring", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "A MetaMask compatible keyring, for ledger hardware wallets", | ||
@@ -41,3 +41,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"eth-sig-util": "^1.4.2", | ||
"eth-sig-util": "^2.0.0", | ||
"ethereumjs-tx": "^1.3.4", | ||
@@ -44,0 +44,0 @@ "ethereumjs-util": "^7.0.9", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21474
492
+ Added@types/bn.js@4.11.6(transitive)
+ Addedeth-sig-util@2.5.4(transitive)
+ Addedethereumjs-abi@0.6.8(transitive)
+ Addedethereumjs-util@6.2.1(transitive)
+ Addedtweetnacl@1.0.3(transitive)
+ Addedtweetnacl-util@0.15.1(transitive)
- Removedeth-sig-util@1.4.2(transitive)
Updatedeth-sig-util@^2.0.0