File tree 4 files changed +31
-14
lines changed
keyring-eth-ledger-bridge/src
4 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -484,12 +484,16 @@ export class LedgerKeyring implements Keyring {
484
484
return hdPath ;
485
485
}
486
486
487
- async signTypedData < T extends MessageTypes > (
487
+ async signTypedData <
488
+ Version extends SignTypedDataVersion . V4 ,
489
+ Types extends MessageTypes ,
490
+ Options extends { version ?: Version } ,
491
+ > (
488
492
withAccount : Hex ,
489
- data : TypedMessage < T > ,
490
- options : { version ?: string } = { } ,
493
+ data : TypedMessage < Types > ,
494
+ options : Options ,
491
495
) : Promise < string > {
492
- const isV4 = options . version === 'V4' ;
496
+ const isV4 = options ? .version === 'V4' ;
493
497
if ( ! isV4 ) {
494
498
throw new Error (
495
499
'Ledger: Only version 4 of typed data signing is supported' ,
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ import {
10
10
toBuffer ,
11
11
} from '@ethereumjs/util' ;
12
12
import {
13
+ type TypedDataV1 ,
14
+ type MessageTypes ,
15
+ type TypedMessage ,
13
16
concatSig ,
14
17
decrypt ,
15
18
EIP7702Authorization ,
@@ -147,17 +150,23 @@ export default class SimpleKeyring implements Keyring {
147
150
return decrypt ( { privateKey, encryptedData } ) ;
148
151
}
149
152
150
- // personal_signTypedData, signs data along with the schema
151
- async signTypedData (
153
+ async signTypedData <
154
+ Version extends SignTypedDataVersion ,
155
+ Types extends MessageTypes ,
156
+ Options extends { version : Version } & KeyringOpt ,
157
+ > (
152
158
address : Hex ,
153
- typedData : any ,
154
- opts : KeyringOpt = { version : SignTypedDataVersion . V1 } ,
159
+ typedData : Version extends SignTypedDataVersion . V1
160
+ ? TypedDataV1
161
+ : TypedMessage < Types > ,
162
+ opts ?: Options ,
155
163
) : Promise < string > {
164
+ const options = opts ?? { version : SignTypedDataVersion . V1 } ;
156
165
// Treat invalid versions as "V1"
157
166
let version = SignTypedDataVersion . V1 ;
158
167
159
- if ( opts . version && isSignTypedDataVersion ( opts . version ) ) {
160
- version = SignTypedDataVersion [ opts . version ] ;
168
+ if ( options . version && isSignTypedDataVersion ( options . version ) ) {
169
+ version = SignTypedDataVersion [ options . version ] ;
161
170
}
162
171
163
172
const privateKey = this . #getPrivateKeyFor( address , opts ) ;
Original file line number Diff line number Diff line change @@ -453,10 +453,14 @@ export class TrezorKeyring implements Keyring {
453
453
}
454
454
455
455
// EIP-712 Sign Typed Data
456
- async signTypedData < T extends MessageTypes > (
456
+ async signTypedData <
457
+ Version extends SignTypedDataVersion . V3 | SignTypedDataVersion . V4 ,
458
+ Types extends MessageTypes ,
459
+ Options extends { version ?: Version } ,
460
+ > (
457
461
address : Hex ,
458
- data : TypedMessage < T > ,
459
- { version } : { version : SignTypedDataVersion } ,
462
+ data : TypedMessage < Types > ,
463
+ { version } : Options ,
460
464
) : Promise < string > {
461
465
const dataWithHashes = transformTypedData (
462
466
data ,
Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ export type Keyring = {
229
229
*/
230
230
signTypedData ?(
231
231
address : Hex ,
232
- typedData : Record < string , unknown > ,
232
+ typedData : unknown [ ] | Record < string , unknown > ,
233
233
options ?: Record < string , unknown > ,
234
234
) : Promise < string > ;
235
235
You can’t perform that action at this time.
0 commit comments