11import type { OnRpcRequestHandler } from '@metamask/snaps-sdk' ;
22import {
33 DialogType ,
4- panel ,
5- text ,
6- heading ,
7- copyable ,
8- UserRejectedRequestError ,
94 MethodNotFoundError ,
5+ UserRejectedRequestError ,
106} from '@metamask/snaps-sdk' ;
7+ import { Box , Copyable , Heading , Text } from '@metamask/snaps-sdk/jsx' ;
118import { bytesToHex , stringToBytes } from '@metamask/utils' ;
129import { sign } from '@noble/bls12-381' ;
1310
1411import type { SignMessageParams } from './types' ;
15- import { getEntropy } from './utils' ;
12+ import { getEntropy , getEntropySourceName } from './utils' ;
1613
1714/**
1815 * Handle incoming JSON-RPC requests from the dapp, sent through the
@@ -31,31 +28,40 @@ import { getEntropy } from './utils';
3128export const onRpcRequest : OnRpcRequestHandler = async ( { request } ) => {
3229 switch ( request . method ) {
3330 case 'signMessage' : {
34- const { message, salt } = request . params as SignMessageParams ;
31+ const { message, salt, source } = request . params as SignMessageParams ;
3532
3633 const approved = await snap . request ( {
3734 method : 'snap_dialog' ,
3835 params : {
3936 type : DialogType . Confirmation ,
40- content : panel ( [
41- heading ( 'Signature request' ) ,
42- text (
43- 'Do you want to sign the following message with snap entropy?' ,
44- ) ,
45- copyable ( message ) ,
46- ] ) ,
37+ content : (
38+ < Box >
39+ < Heading > Signature request</ Heading >
40+ < Text >
41+ Do you want to sign the following message with Snap entropy, and
42+ the entropy source "{ await getEntropySourceName ( source ) } "?
43+ </ Text >
44+ < Copyable value = { message } />
45+ </ Box >
46+ ) ,
4747 } ,
4848 } ) ;
4949
5050 if ( ! approved ) {
5151 throw new UserRejectedRequestError ( ) ;
5252 }
5353
54- const privateKey = await getEntropy ( salt ) ;
54+ const privateKey = await getEntropy ( salt , source ) ;
5555 const newLocal = await sign ( stringToBytes ( message ) , privateKey ) ;
5656 return bytesToHex ( newLocal ) ;
5757 }
5858
59+ case 'getEntropySources' : {
60+ return await snap . request ( {
61+ method : 'snap_listEntropySources' ,
62+ } ) ;
63+ }
64+
5965 default :
6066 throw new MethodNotFoundError ( { method : request . method } ) ;
6167 }
0 commit comments