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');
7
7
const types_1 = require ( '../types' ) ;
8
8
exports . LEAF_VERSION_TAPSCRIPT = 0xc0 ;
9
9
function rootHashFromPath ( controlBlock , tapleafMsg ) {
10
- const k = [ tapleafMsg ] ;
11
- const e = [ ] ;
12
10
const m = ( controlBlock . length - 33 ) / 32 ;
11
+ let kj = tapleafMsg ;
13
12
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 ) ;
17
16
} else {
18
- k [ j + 1 ] = tapBranchHash ( e [ j ] , k [ j ] ) ;
17
+ kj = tapBranchHash ( ej , kj ) ;
19
18
}
20
19
}
21
- return k [ m ] ;
20
+ return kj ;
22
21
}
23
22
exports . rootHashFromPath = rootHashFromPath ;
24
23
const 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(
10
10
controlBlock : Buffer ,
11
11
tapleafMsg : Buffer ,
12
12
) : Buffer {
13
- const k = [ tapleafMsg ] ;
14
- const e = [ ] ;
15
-
16
13
const m = ( controlBlock . length - 33 ) / 32 ;
17
14
15
+ let kj = tapleafMsg ;
18
16
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 ) ;
22
20
} else {
23
- k [ j + 1 ] = tapBranchHash ( e [ j ] , k [ j ] ) ;
21
+ kj = tapBranchHash ( ej , kj ) ;
24
22
}
25
23
}
26
24
27
- return k [ m ] ;
25
+ return kj ;
28
26
}
29
27
30
28
interface HashLeaf {
You can’t perform that action at this time.
0 commit comments