-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: signTypedData of imKey * Update eth-imkey-keyring.ts * fix: wait ui
- Loading branch information
1 parent
d7ba92b
commit 1cb57e1
Showing
4 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as sigUtil from 'eth-sig-util'; | ||
import * as ethUtil from 'ethereumjs-util'; | ||
|
||
/** | ||
* Signs a typed message as per EIP-712 and returns its sha3 hash | ||
* | ||
* @param {Object} typedData - Types message data to sign | ||
* @returns {Buffer} - sha3 hash of the resulting signed message | ||
*/ | ||
export function signHashHex(typedData, useV4 = true): string { | ||
const sanitizedData = sigUtil.TypedDataUtils.sanitizeData(typedData); | ||
const parts = [Buffer.from('1901', 'hex')]; | ||
parts.push( | ||
sigUtil.TypedDataUtils.hashStruct( | ||
'EIP712Domain', | ||
sanitizedData.domain, | ||
sanitizedData.types, | ||
useV4 | ||
) | ||
); | ||
if (sanitizedData.primaryType !== 'EIP712Domain') { | ||
parts.push( | ||
sigUtil.TypedDataUtils.hashStruct( | ||
sanitizedData.primaryType as string, | ||
sanitizedData.message, | ||
sanitizedData.types, | ||
useV4 | ||
) | ||
); | ||
} | ||
return ethUtil.bufferToHex(Buffer.concat(parts)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters