File tree Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -7,18 +7,17 @@ const bufferutils_1 = require('../bufferutils');
77const types_1 = require ( '../types' ) ;
88exports . LEAF_VERSION_TAPSCRIPT = 0xc0 ;
99function rootHashFromPath ( controlBlock , tapleafMsg ) {
10- const k = [ tapleafMsg ] ;
11- const e = [ ] ;
1210 const m = ( controlBlock . length - 33 ) / 32 ;
11+ let kj = tapleafMsg ;
1312 for ( let j = 0 ; j < m ; j ++ ) {
14- e [ j ] = controlBlock . slice ( 33 + 32 * j , 65 + 32 * j ) ;
15- if ( k [ j ] . compare ( e [ j ] ) < 0 ) {
16- k [ j + 1 ] = tapBranchHash ( k [ j ] , e [ j ] ) ;
13+ const ej = controlBlock . slice ( 33 + 32 * j , 65 + 32 * j ) ;
14+ if ( kj . compare ( ej ) < 0 ) {
15+ kj = tapBranchHash ( kj , ej ) ;
1716 } else {
18- k [ j + 1 ] = tapBranchHash ( e [ j ] , k [ j ] ) ;
17+ kj = tapBranchHash ( ej , kj ) ;
1918 }
2019 }
21- return k [ m ] ;
20+ return kj ;
2221}
2322exports . rootHashFromPath = rootHashFromPath ;
2423const isHashBranch = ht => 'left' in ht && 'right' in ht ;
Original file line number Diff line number Diff line change @@ -10,21 +10,19 @@ export function rootHashFromPath(
1010 controlBlock : Buffer ,
1111 tapleafMsg : Buffer ,
1212) : Buffer {
13- const k = [ tapleafMsg ] ;
14- const e = [ ] ;
15-
1613 const m = ( controlBlock . length - 33 ) / 32 ;
1714
15+ let kj = tapleafMsg ;
1816 for ( let j = 0 ; j < m ; j ++ ) {
19- e [ j ] = controlBlock . slice ( 33 + 32 * j , 65 + 32 * j ) ;
20- if ( k [ j ] . compare ( e [ j ] ) < 0 ) {
21- k [ j + 1 ] = tapBranchHash ( k [ j ] , e [ j ] ) ;
17+ const ej = controlBlock . slice ( 33 + 32 * j , 65 + 32 * j ) ;
18+ if ( kj . compare ( ej ) < 0 ) {
19+ kj = tapBranchHash ( kj , ej ) ;
2220 } else {
23- k [ j + 1 ] = tapBranchHash ( e [ j ] , k [ j ] ) ;
21+ kj = tapBranchHash ( ej , kj ) ;
2422 }
2523 }
2624
27- return k [ m ] ;
25+ return kj ;
2826}
2927
3028interface HashLeaf {
You can’t perform that action at this time.
0 commit comments