@@ -287,7 +287,7 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
287287 getCredentials < UnsignedTx extends AVMUnsignedTx | PlatformUnsignedTx | EVMUnsignedTx > (
288288 unsignedTx : UnsignedTx ,
289289 paths : string [ ] ,
290- sigMap : any ,
290+ sigMap : Map < string , Buffer > ,
291291 chainId : ChainIdType
292292 ) : Credential [ ] {
293293 const creds : Credential [ ] = [ ]
@@ -340,6 +340,7 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
340340 const pathStr = paths [ pathIndex ]
341341
342342 const sigRaw = sigMap . get ( pathStr )
343+ if ( ! sigRaw ) throw new Error ( 'Missing signature.' )
343344 const sigBuff = BufferAvax . from ( sigRaw )
344345 const sig : Signature = new Signature ( )
345346 sig . fromBuffer ( sigBuff )
@@ -358,6 +359,7 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
358359 const pathStr = paths [ pathIndex ]
359360
360361 const sigRaw = sigMap . get ( pathStr )
362+ if ( ! sigRaw ) throw new Error ( 'Missing signature.' )
361363 const sigBuff = BufferAvax . from ( sigRaw )
362364 const sig : Signature = new Signature ( )
363365 sig . fromBuffer ( sigBuff )
@@ -376,6 +378,7 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
376378 const pathStr = paths [ pathIndex ]
377379
378380 const sigRaw = sigMap . get ( pathStr )
381+ if ( ! sigRaw ) throw new Error ( 'Missing signature.' )
379382 const sigBuff = BufferAvax . from ( sigRaw )
380383 const sig : Signature = new Signature ( )
381384 sig . fromBuffer ( sigBuff )
@@ -399,6 +402,8 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
399402 try {
400403 store . commit ( 'Ledger/openModal' , {
401404 title : 'Sign Hash' ,
405+ warning :
406+ 'Signing hashes are dangerous, continue at your own risk. Ledger is unable display this transaction because it is too large.' ,
402407 messages : [ ] ,
403408 info : msg . toString ( 'hex' ) . toUpperCase ( ) ,
404409 } )
@@ -419,7 +424,7 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
419424 const creds : Credential [ ] = this . getCredentials < UnsignedTx > (
420425 unsignedTx ,
421426 paths ,
422- sigMap ,
427+ sigMap . signatures ,
423428 chainId
424429 )
425430
@@ -472,8 +477,6 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
472477 // Get their paths, for owned ones
473478 const changePaths = this . getAddressPaths ( outputAddrs )
474479
475- console . log ( 'change paths: ' , changePaths )
476-
477480 const messages = this . getTransactionMessages < UnsignedTx > (
478481 unsignedTx ,
479482 chainId ,
@@ -726,12 +729,28 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
726729 const chainId : ChainIdType = 'X'
727730 const { paths } = this . getTransactionPaths < AVMUnsignedTx > ( unsignedTx , chainId )
728731
729- const signedTx = await this . signTransactionParsable < AVMUnsignedTx , AVMTx > (
730- unsignedTx ,
731- paths ,
732- chainId
732+ // We dont know the number of change paths but can assume worst case and use number of signer paths
733+ const canSign = this . provider . canParseTx (
734+ unsignedTx . toBuffer ( ) . length ,
735+ paths . length ,
736+ paths . length
733737 )
734738
739+ let signedTx
740+ if ( canSign ) {
741+ signedTx = await this . signTransactionParsable < AVMUnsignedTx , AVMTx > (
742+ unsignedTx ,
743+ paths ,
744+ chainId
745+ )
746+ } else {
747+ signedTx = await this . signTransactionHash < AVMUnsignedTx , AVMTx > (
748+ unsignedTx ,
749+ paths ,
750+ chainId
751+ )
752+ }
753+
735754 store . commit ( 'Ledger/closeModal' )
736755 return signedTx
737756 }
@@ -741,11 +760,28 @@ class LedgerWallet extends HdWalletCore implements AvaWalletCore {
741760
742761 const { paths } = this . getTransactionPaths < PlatformUnsignedTx > ( unsignedTx , chainId )
743762
744- const signedTx = await this . signTransactionParsable < PlatformUnsignedTx , PlatformTx > (
745- unsignedTx ,
746- paths ,
747- chainId
763+ // We dont know the number of change paths but can assume worst case and use number of signer paths
764+ const canSign = this . provider . canParseTx (
765+ unsignedTx . toBuffer ( ) . length ,
766+ paths . length ,
767+ paths . length
748768 )
769+
770+ let signedTx
771+ if ( canSign ) {
772+ signedTx = await this . signTransactionParsable < PlatformUnsignedTx , PlatformTx > (
773+ unsignedTx ,
774+ paths ,
775+ chainId
776+ )
777+ } else {
778+ signedTx = await this . signTransactionHash < PlatformUnsignedTx , PlatformTx > (
779+ unsignedTx ,
780+ paths ,
781+ chainId
782+ )
783+ }
784+
749785 store . commit ( 'Ledger/closeModal' )
750786 return signedTx
751787 }
0 commit comments