@@ -255,6 +255,13 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
255
255
return this . provider . send ( "eth_sendTransaction" , [ hexTx ] ) . then ( ( hash ) => {
256
256
return hash ;
257
257
} , ( error ) => {
258
+ if ( typeof ( error . message ) === "string" && error . message . match ( / u s e r d e n i e d / i) ) {
259
+ logger . throwError ( "user rejected transaction" , Logger . errors . ACTION_REJECTED , {
260
+ action : "sendTransaction" ,
261
+ transaction : tx
262
+ } ) ;
263
+ }
264
+
258
265
return checkError ( "sendTransaction" , error , hexTx ) ;
259
266
} ) ;
260
267
} ) ;
@@ -292,15 +299,38 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
292
299
const data = ( ( typeof ( message ) === "string" ) ? toUtf8Bytes ( message ) : message ) ;
293
300
const address = await this . getAddress ( ) ;
294
301
295
- return await this . provider . send ( "personal_sign" , [ hexlify ( data ) , address . toLowerCase ( ) ] ) ;
302
+
303
+ try {
304
+ return await this . provider . send ( "personal_sign" , [ hexlify ( data ) , address . toLowerCase ( ) ] ) ;
305
+ } catch ( error ) {
306
+ if ( typeof ( error . message ) === "string" && error . message . match ( / u s e r d e n i e d / i) ) {
307
+ logger . throwError ( "user rejected signing" , Logger . errors . ACTION_REJECTED , {
308
+ action : "signMessage" ,
309
+ from : address ,
310
+ message : data
311
+ } ) ;
312
+ }
313
+ throw error ;
314
+ }
296
315
}
297
316
298
317
async _legacySignMessage ( message : Bytes | string ) : Promise < string > {
299
318
const data = ( ( typeof ( message ) === "string" ) ? toUtf8Bytes ( message ) : message ) ;
300
319
const address = await this . getAddress ( ) ;
301
320
302
- // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
303
- return await this . provider . send ( "eth_sign" , [ address . toLowerCase ( ) , hexlify ( data ) ] ) ;
321
+ try {
322
+ // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
323
+ return await this . provider . send ( "eth_sign" , [ address . toLowerCase ( ) , hexlify ( data ) ] ) ;
324
+ } catch ( error ) {
325
+ if ( typeof ( error . message ) === "string" && error . message . match ( / u s e r d e n i e d / i) ) {
326
+ logger . throwError ( "user rejected signing" , Logger . errors . ACTION_REJECTED , {
327
+ action : "_legacySignMessage" ,
328
+ from : address ,
329
+ message : data
330
+ } ) ;
331
+ }
332
+ throw error ;
333
+ }
304
334
}
305
335
306
336
async _signTypedData ( domain : TypedDataDomain , types : Record < string , Array < TypedDataField > > , value : Record < string , any > ) : Promise < string > {
@@ -311,10 +341,21 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
311
341
312
342
const address = await this . getAddress ( ) ;
313
343
314
- return await this . provider . send ( "eth_signTypedData_v4" , [
315
- address . toLowerCase ( ) ,
316
- JSON . stringify ( _TypedDataEncoder . getPayload ( populated . domain , types , populated . value ) )
317
- ] ) ;
344
+ try {
345
+ return await this . provider . send ( "eth_signTypedData_v4" , [
346
+ address . toLowerCase ( ) ,
347
+ JSON . stringify ( _TypedDataEncoder . getPayload ( populated . domain , types , populated . value ) )
348
+ ] ) ;
349
+ } catch ( error ) {
350
+ if ( typeof ( error . message ) === "string" && error . message . match ( / u s e r d e n i e d / i) ) {
351
+ logger . throwError ( "user rejected signing" , Logger . errors . ACTION_REJECTED , {
352
+ action : "_signTypedData" ,
353
+ from : address ,
354
+ message : { domain : populated . domain , types, value : populated . value }
355
+ } ) ;
356
+ }
357
+ throw error ;
358
+ }
318
359
}
319
360
320
361
async unlock ( password : string ) : Promise < boolean > {
0 commit comments