11import { expect } from '@jest/globals' ;
22import { assertIsConfirmationDialog , installSnap } from '@metamask/snaps-jest' ;
3- import { copyable , heading , panel , text } from '@metamask/snaps-sdk' ;
3+ import { Box , Copyable , Heading , Text } from '@metamask/snaps-sdk/jsx ' ;
44
55describe ( 'onRpcRequest' , ( ) => {
66 it ( 'throws an error if the requested method does not exist' , async ( ) => {
@@ -38,6 +38,23 @@ describe('onRpcRequest', () => {
3838 ) ;
3939 } ) ;
4040
41+ it ( 'returns an secp256k1 public key for a given BIP-32 path with a different source' , async ( ) => {
42+ const { request } = await installSnap ( ) ;
43+
44+ const response = await request ( {
45+ method : 'getPublicKey' ,
46+ params : {
47+ path : [ 'm' , "44'" , "0'" ] ,
48+ curve : 'secp256k1' ,
49+ source : 'alternative' ,
50+ } ,
51+ } ) ;
52+
53+ expect ( response ) . toRespondWith (
54+ '0x04f72f0e3684b0d7295f391616f12a469070bfcd175c55366239047495a2c1c410b4d820fb4147de213a2d25fb19f9451354ad5949fc881a2d219529703416de73' ,
55+ ) ;
56+ } ) ;
57+
4158 it ( 'returns a compressed secp256k1 public key for a given BIP-32 path' , async ( ) => {
4259 const { request } = await installSnap ( ) ;
4360
@@ -110,15 +127,14 @@ describe('onRpcRequest', () => {
110127 const ui = await response . getInterface ( ) ;
111128 assertIsConfirmationDialog ( ui ) ;
112129 expect ( ui ) . toRender (
113- panel ( [
114- heading ( 'Signature request' ) ,
115- text (
116- `Do you want to secp256k1 sign "Hello, world!" with the following public key?` ,
117- ) ,
118- copyable (
119- '0x0423a6a6f8800b2d0710595969f40148a28953c9eebc0c0da78a89be3b3935f59c0069dfe1cace1a083e9c962c9f2ef932e9346cd907e647d993d787c4e59d03d1' ,
120- ) ,
121- ] ) ,
130+ < Box >
131+ < Heading > Signature request</ Heading >
132+ < Text >
133+ Do you want to { 'secp256k1' } sign "{ 'Hello, world!' } " with the
134+ following public key?
135+ </ Text >
136+ < Copyable value = "0x0423a6a6f8800b2d0710595969f40148a28953c9eebc0c0da78a89be3b3935f59c0069dfe1cace1a083e9c962c9f2ef932e9346cd907e647d993d787c4e59d03d1" />
137+ </ Box > ,
122138 ) ;
123139
124140 await ui . ok ( ) ;
@@ -128,6 +144,39 @@ describe('onRpcRequest', () => {
128144 ) ;
129145 } ) ;
130146
147+ it ( 'signs a message for the given BIP-32 path using secp256k1 with a different source' , async ( ) => {
148+ const { request } = await installSnap ( ) ;
149+
150+ const response = request ( {
151+ method : 'signMessage' ,
152+ params : {
153+ path : [ 'm' , "44'" , "0'" ] ,
154+ curve : 'secp256k1' ,
155+ message : 'Hello, world!' ,
156+ source : 'alternative' ,
157+ } ,
158+ } ) ;
159+
160+ const ui = await response . getInterface ( ) ;
161+ assertIsConfirmationDialog ( ui ) ;
162+ expect ( ui ) . toRender (
163+ < Box >
164+ < Heading > Signature request</ Heading >
165+ < Text >
166+ Do you want to { 'secp256k1' } sign "{ 'Hello, world!' } " with the
167+ following public key?
168+ </ Text >
169+ < Copyable value = "0x04f72f0e3684b0d7295f391616f12a469070bfcd175c55366239047495a2c1c410b4d820fb4147de213a2d25fb19f9451354ad5949fc881a2d219529703416de73" />
170+ </ Box > ,
171+ ) ;
172+
173+ await ui . ok ( ) ;
174+
175+ expect ( await response ) . toRespondWith (
176+ '0x3044022049a3e74ed526df8b2a8e16e95a181d909255c90f6f63eb8efc16625af917b07d022014f2b203b0749058cbfc3ad0456c7b2bdf1ab809fd5913c6ee272cfc56f30ef2' ,
177+ ) ;
178+ } ) ;
179+
131180 it ( 'signs a message for the given BIP-32 path using ed25519' , async ( ) => {
132181 const { request } = await installSnap ( ) ;
133182
@@ -143,15 +192,14 @@ describe('onRpcRequest', () => {
143192 const ui = await response . getInterface ( ) ;
144193 assertIsConfirmationDialog ( ui ) ;
145194 expect ( ui ) . toRender (
146- panel ( [
147- heading ( 'Signature request' ) ,
148- text (
149- `Do you want to ed25519 sign "Hello, world!" with the following public key?` ,
150- ) ,
151- copyable (
152- '0x000b96ba23cae9597de51e0187d7ef1b2d1a782dc2d5ceac770a327de3844dd533' ,
153- ) ,
154- ] ) ,
195+ < Box >
196+ < Heading > Signature request</ Heading >
197+ < Text >
198+ Do you want to { 'ed25519' } sign "{ 'Hello, world!' } " with the
199+ following public key?
200+ </ Text >
201+ < Copyable value = "0x000b96ba23cae9597de51e0187d7ef1b2d1a782dc2d5ceac770a327de3844dd533" />
202+ </ Box > ,
155203 ) ;
156204
157205 await ui . ok ( ) ;
@@ -176,15 +224,14 @@ describe('onRpcRequest', () => {
176224 const ui = await response . getInterface ( ) ;
177225 assertIsConfirmationDialog ( ui ) ;
178226 expect ( ui ) . toRender (
179- panel ( [
180- heading ( 'Signature request' ) ,
181- text (
182- `Do you want to ed25519Bip32 sign "Hello, world!" with the following public key?` ,
183- ) ,
184- copyable (
185- '0x2c3ac523b470dead7981df46c93d894ed4381e94c23aa1ec3806a320ff8ceb42' ,
186- ) ,
187- ] ) ,
227+ < Box >
228+ < Heading > Signature request</ Heading >
229+ < Text >
230+ Do you want to { 'ed25519Bip32' } sign "{ 'Hello, world!' } " with the
231+ following public key?
232+ </ Text >
233+ < Copyable value = "0x2c3ac523b470dead7981df46c93d894ed4381e94c23aa1ec3806a320ff8ceb42" />
234+ </ Box > ,
188235 ) ;
189236
190237 await ui . ok ( ) ;
0 commit comments