-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from enkryptcom/develop
Release: v1.21.0
- Loading branch information
Showing
11 changed files
with
90 additions
and
85 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
53 changes: 53 additions & 0 deletions
53
packages/extension/src/providers/ethereum/libs/sanitize-typed-data.ts
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,53 @@ | ||
import { | ||
TypedDataUtils, | ||
SignTypedDataVersion, | ||
MessageTypeProperty, | ||
MessageTypes, | ||
TypedMessage, | ||
} from "@metamask/eth-sig-util"; | ||
|
||
const encodeData = ( | ||
primaryType: string, | ||
data: Record<string, unknown>, | ||
types: Record<string, MessageTypeProperty[]>, | ||
version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4 | ||
): Record<string, unknown> => { | ||
const retObject: Record<string, unknown> = {}; | ||
for (const field of types[primaryType]) { | ||
if (version === SignTypedDataVersion.V3 && data[field.name] === undefined) { | ||
continue; | ||
} | ||
retObject[field.name] = data[field.name]; | ||
} | ||
return retObject; | ||
}; | ||
|
||
const sanitizeData = <T extends MessageTypes>( | ||
typedData: TypedMessage<T>, | ||
version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4 | ||
): Record<string, unknown> => { | ||
const sanitizedData = TypedDataUtils.sanitizeData(typedData); | ||
const { domain, types, primaryType, message } = sanitizedData; | ||
const domainType = { EIP712Domain: sanitizedData.types.EIP712Domain }; | ||
const domainData = encodeData("EIP712Domain", domain, domainType, version); | ||
|
||
if (sanitizedData.primaryType !== "EIP712Domain") { | ||
const messageData = encodeData( | ||
primaryType as string, | ||
message, | ||
types, | ||
version | ||
); | ||
return { | ||
domain: domainData, | ||
message: messageData, | ||
primaryType, | ||
}; | ||
} | ||
return { | ||
domain: domainData, | ||
primaryType, | ||
}; | ||
}; | ||
|
||
export { sanitizeData }; |
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
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
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
6d1a6c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/a288b51f53d650b10595732407d759d77d39d39e596d99c23934defea5bf03ae
firefox:
https://www.virustotal.com/gui/file/c4acca561abc8e1041028012e381eeaef7ccb06e1493d086fda92489ea9ecd71
6d1a6c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/31f9b2a61a0bec5ed98189738c42f9d3d9114f20832aa171234f97596257cc82
firefox:
https://www.virustotal.com/gui/file/d28c4e21b2d9622eed67c7e42e87d14d8c9813c871cea77f80a7b66c39f3f8e7