@@ -15,20 +15,20 @@ const { RegistryTypes } = extend;
1515type signRequestProps = {
1616 requestId ?: Buffer ;
1717 data : Buffer ;
18- derivationPath : CryptoKeypath ;
18+ derivationPaths : CryptoKeypath [ ] ;
1919 utxos : AvalancheUtxo [ ] ;
2020} ;
2121
2222enum Keys {
2323 requestId = 1 ,
2424 signData ,
25- derivationPath ,
25+ derivationPaths ,
2626 utxos ,
2727}
2828export class AvalancheSignRequest extends RegistryItem {
2929 private requestId ?: Buffer ;
3030 private data : Buffer ;
31- private derivationPath : CryptoKeypath ;
31+ private derivationPaths : CryptoKeypath [ ] ;
3232 private utxos : AvalancheUtxo [ ] ;
3333
3434
@@ -38,14 +38,14 @@ export class AvalancheSignRequest extends RegistryItem {
3838 super ( ) ;
3939 this . requestId = args . requestId ;
4040 this . data = args . data ;
41- this . derivationPath = args . derivationPath ;
41+ this . derivationPaths = args . derivationPaths ;
4242 this . utxos = args . utxos ;
4343 }
4444
4545 public getRequestId = ( ) => this . requestId ;
4646 public getSignData = ( ) => this . data ;
4747 public getUtxos = ( ) => this . utxos ;
48- public getDerivationPath = ( ) => this . derivationPath ;
48+ public getDerivationPaths = ( ) => this . derivationPaths ;
4949
5050 public toDataItem = ( ) => {
5151 const map : DataItemMap = { } ;
@@ -58,9 +58,11 @@ export class AvalancheSignRequest extends RegistryItem {
5858
5959 map [ Keys . signData ] = Buffer . from ( this . data ) ;
6060
61- const keyPath = this . derivationPath . toDataItem ( ) ;
62- keyPath . setTag ( this . derivationPath . getRegistryType ( ) . getTag ( ) ) ;
63- map [ Keys . derivationPath ] = keyPath ;
61+ map [ Keys . derivationPaths ] = this . derivationPaths . map ( ( keypath ) => {
62+ const item = keypath . toDataItem ( ) ;
63+ item . setTag ( keypath . getRegistryType ( ) . getTag ( ) ) ;
64+ return item ;
65+ } ) ;
6466
6567 map [ Keys . utxos ] = this . utxos . map ( ( utxo ) => {
6668 const res = utxo . toDataItem ( ) ;
@@ -77,22 +79,24 @@ export class AvalancheSignRequest extends RegistryItem {
7779 ? map [ Keys . requestId ] . getData ( )
7880 : undefined ;
7981 const data = map [ Keys . signData ] ;
80- const derivationPath = CryptoKeypath . fromDataItem ( map [ Keys . derivationPath ] ) ;
82+ const derivationPaths : CryptoKeypath [ ] = map [ Keys . derivationPaths ] . map (
83+ ( item : DataItem ) => CryptoKeypath . fromDataItem ( item )
84+ ) ;
8185 const utxos : AvalancheUtxo [ ] = map [ Keys . utxos ] . map ( ( utxo : DataItem ) =>
8286 AvalancheUtxo . fromDataItem ( utxo )
8387 ) ;
8488
8589 return new AvalancheSignRequest ( {
8690 requestId,
8791 data,
88- derivationPath ,
92+ derivationPaths ,
8993 utxos,
9094 } ) ;
9195 } ;
9296
9397 public static constructAvalancheRequest (
9498 data : Buffer ,
95- hdPath : string ,
99+ hdPaths : string [ ] ,
96100 utxos : AvalancheUtxoData [ ] ,
97101 xfp : string ,
98102 requestId ?: string | Buffer
@@ -110,23 +114,22 @@ export class AvalancheSignRequest extends RegistryItem {
110114 AvalancheUtxo . constructAvalancheUtxo ( utxo )
111115 ) ;
112116
113- const paths = hdPath . replace ( / [ m | M ] \/ / , "" ) . split ( "/" ) ;
114- const hdpathObject = new CryptoKeypath (
115- paths . map ( ( path ) => {
116- const index = parseInt ( path . replace ( "'" , "" ) ) ;
117- let isHardened = false ;
118- if ( path . endsWith ( "'" ) ) {
119- isHardened = true ;
120- }
121- return new PathComponent ( { index, hardened : isHardened } ) ;
122- } ) ,
123- Buffer . from ( xfp , "hex" )
124- ) ;
117+ const derivationPaths = hdPaths . map ( hdPath => {
118+ const paths = hdPath . replace ( / [ m | M ] \/ / , "" ) . split ( "/" ) ;
119+ return new CryptoKeypath (
120+ paths . map ( ( path ) => {
121+ const index = parseInt ( path . replace ( / [ ^ 0 - 9 ] / g, "" ) ) ;
122+ const isHardened = path . endsWith ( "'" ) || path . toLowerCase ( ) . endsWith ( "h" ) ;
123+ return new PathComponent ( { index, hardened : isHardened } ) ;
124+ } ) ,
125+ Buffer . from ( xfp , "hex" )
126+ ) ;
127+ } ) ;
125128
126129 return new AvalancheSignRequest ( {
127130 data,
128131 requestId : _requestId ,
129- derivationPath : hdpathObject ,
132+ derivationPaths : derivationPaths ,
130133 utxos : avalancheUtxos ,
131134 } ) ;
132135 }
0 commit comments