Skip to content

Commit

Permalink
Switch eth-sig-util to @metamask/eth-sig-util (#286)
Browse files Browse the repository at this point in the history
* Switch eth-sig-util to @metamask/eth-sig-util

* Polyfill packages

* Remove extraneous packages not needed to start test dapp

* No resolution for extraneous packages webpack config

* Remove extra package missed in previous commit

---------

Co-authored-by: legobt <[email protected]>
Co-authored-by: legobeat <[email protected]>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent 390ff3b commit 314b221
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 231 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@metamask/auto-changelog": "^2.5.0",
"@metamask/eslint-config": "^6.0.0",
"@metamask/eslint-config-nodejs": "^6.0.0",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/onboarding": "^1.0.0",
"@openzeppelin/contracts": "4.9.6",
"assert": "^2.1.0",
Expand All @@ -52,7 +53,6 @@
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eth-sig-util": "^2.5.3",
"ethereumjs-util": "^5.1.1",
"@web3modal/ethers5": "^3.2.0",
"@walletconnect/modal": "^2.6.2",
Expand Down
34 changes: 18 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5';
import {
encrypt,
recoverPersonalSignature,
recoverTypedSignatureLegacy,
recoverTypedSignature,
recoverTypedSignature_v4 as recoverTypedSignatureV4,
} from 'eth-sig-util';
} from '@metamask/eth-sig-util';
import { ethers } from 'ethers';
import { toChecksumAddress } from 'ethereumjs-util';
import { getPermissionsDisplayString, stringifiableToHex } from './utils';
Expand Down Expand Up @@ -2037,11 +2035,11 @@ const initializeFormElements = () => {
encryptButton.onclick = () => {
try {
ciphertextDisplay.innerText = stringifiableToHex(
encrypt(
encryptionKeyDisplay.innerText,
{ data: encryptMessageInput.value },
'x25519-xsalsa20-poly1305',
),
encrypt({
publicKey: encryptionKeyDisplay.innerText,
data: encryptMessageInput.value,
version: 'x25519-xsalsa20-poly1305',
}),
);
decryptButton.disabled = false;
} catch (error) {
Expand Down Expand Up @@ -2252,7 +2250,7 @@ const initializeFormElements = () => {
const sign = personalSignResult.innerHTML;
const recoveredAddr = recoverPersonalSignature({
data: msg,
sig: sign,
signature: sign,
});
if (recoveredAddr === from) {
console.log(`SigUtil Successfully verified signer as ${recoveredAddr}`);
Expand Down Expand Up @@ -2331,9 +2329,10 @@ const initializeFormElements = () => {
try {
const from = accounts[0];
const sign = signTypedDataResult.innerHTML;
const recoveredAddr = await recoverTypedSignatureLegacy({
const recoveredAddr = await recoverTypedSignature({
data: msgParams,
sig: sign,
signature: sign,
version: 'V1',
});
if (toChecksumAddress(recoveredAddr) === toChecksumAddress(from)) {
console.log(`Successfully verified signer as ${recoveredAddr}`);
Expand Down Expand Up @@ -2450,7 +2449,8 @@ const initializeFormElements = () => {
const sign = signTypedDataV3Result.innerHTML;
const recoveredAddr = await recoverTypedSignature({
data: msgParams,
sig: sign,
signature: sign,
version: 'V3',
});
if (toChecksumAddress(recoveredAddr) === toChecksumAddress(from)) {
console.log(`Successfully verified signer as ${recoveredAddr}`);
Expand Down Expand Up @@ -2595,9 +2595,10 @@ const initializeFormElements = () => {
try {
const from = accounts[0];
const sign = signTypedDataV4Result.innerHTML;
const recoveredAddr = recoverTypedSignatureV4({
const recoveredAddr = recoverTypedSignature({
data: msgParams,
sig: sign,
signature: sign,
version: 'V4',
});
if (toChecksumAddress(recoveredAddr) === toChecksumAddress(from)) {
console.log(`Successfully verified signer as ${recoveredAddr}`);
Expand Down Expand Up @@ -2744,9 +2745,10 @@ const initializeFormElements = () => {
};
try {
const sign = signPermitResult.innerHTML;
const recoveredAddr = recoverTypedSignatureV4({
const recoveredAddr = recoverTypedSignature({
data: msgParams,
sig: sign,
signature: sign,
version: 'V4',
});
if (toChecksumAddress(recoveredAddr) === toChecksumAddress(from)) {
console.log(`Successfully verified signer as ${recoveredAddr}`);
Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module.exports = {
assert: require.resolve('assert/'),
process: require.resolve('process/browser'),
stream: require.resolve('stream-browserify'),
http: false,
https: false,
zlib: false,
url: false,
},
},
devtool: 'eval-source-map',
Expand Down
Loading

0 comments on commit 314b221

Please sign in to comment.