-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Unblock
eth_signTypedData
(#2969)
Unblock all variants of `eth_signTypedData` as they are deemed lower risk following UI changes on the clients. Also adds logic to use it in the Ethereum provider example Snap.
- Loading branch information
1 parent
3e615f5
commit 296244d
Showing
10 changed files
with
218 additions
and
9 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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export type PersonalSignParams = { | ||
message: string; | ||
}; | ||
|
||
export type SignTypedDataParams = { | ||
message: string; | ||
}; |
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
60 changes: 60 additions & 0 deletions
60
packages/test-snaps/src/features/snaps/ethereum-provider/components/SignTypedData.tsx
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,60 @@ | ||
import { logError } from '@metamask/snaps-utils'; | ||
import type { ChangeEvent, FormEvent, FunctionComponent } from 'react'; | ||
import { useState } from 'react'; | ||
import { Button, Form } from 'react-bootstrap'; | ||
|
||
import { useInvokeMutation } from '../../../../api'; | ||
import { Result } from '../../../../components'; | ||
import { getSnapId } from '../../../../utils'; | ||
import { | ||
ETHEREUM_PROVIDER_SNAP_ID, | ||
ETHEREUM_PROVIDER_SNAP_PORT, | ||
} from '../constants'; | ||
|
||
export const SignTypedData: FunctionComponent = () => { | ||
const [message, setMessage] = useState(''); | ||
const [invokeSnap, { isLoading, data, error }] = useInvokeMutation(); | ||
|
||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
setMessage(event.target.value); | ||
}; | ||
|
||
const handleSubmit = (event: FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
invokeSnap({ | ||
snapId: getSnapId(ETHEREUM_PROVIDER_SNAP_ID, ETHEREUM_PROVIDER_SNAP_PORT), | ||
method: 'signTypedData', | ||
params: { | ||
message, | ||
}, | ||
}).catch(logError); | ||
}; | ||
|
||
return ( | ||
<> | ||
<h3 className="h5">Sign Typed Data</h3> | ||
<Form onSubmit={handleSubmit} className="mb-3"> | ||
<Form.Label>Message</Form.Label> | ||
<Form.Control | ||
type="text" | ||
placeholder="Message" | ||
value={message} | ||
onChange={handleChange} | ||
id="signTypedData" | ||
className="mb-3" | ||
/> | ||
|
||
<Button type="submit" id="signTypedDataButton" disabled={isLoading}> | ||
Sign Typed Data | ||
</Button> | ||
</Form> | ||
<Result> | ||
<span id="signTypedDataResult"> | ||
{JSON.stringify(data, null, 2)} | ||
{JSON.stringify(error, null, 2)} | ||
</span> | ||
</Result> | ||
</> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/test-snaps/src/features/snaps/ethereum-provider/components/index.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,2 @@ | ||
export * from './SignMessage'; | ||
export * from './SignTypedData'; |