1
1
'use strict' ;
2
2
Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
3
- exports . computeMastRoot = exports . rootHash = exports . leafHash = exports . tweakKey = exports . liftX = void 0 ;
3
+ exports . rootHashFromTree = exports . rootHashFromPath = exports . leafHash = exports . tweakKey = exports . liftX = void 0 ;
4
4
const buffer_1 = require ( 'buffer' ) ;
5
5
const BN = require ( 'bn.js' ) ;
6
6
const bcrypto = require ( './crypto' ) ;
@@ -70,7 +70,7 @@ function leafHash(script, version) {
70
70
] ) ;
71
71
}
72
72
exports . leafHash = leafHash ;
73
- function rootHash ( controlBlock , tapLeafMsg ) {
73
+ function rootHashFromPath ( controlBlock , tapLeafMsg ) {
74
74
const k = [ ] ;
75
75
const e = [ ] ;
76
76
const m = ( controlBlock . length - 33 ) / 32 ;
@@ -91,13 +91,13 @@ function rootHash(controlBlock, tapLeafMsg) {
91
91
}
92
92
return k [ m ] ;
93
93
}
94
- exports . rootHash = rootHash ;
94
+ exports . rootHashFromPath = rootHashFromPath ;
95
95
// todo: solve any[]
96
- function computeMastRoot ( scripts ) {
96
+ function rootHashFromTree ( scripts ) {
97
97
if ( scripts . length === 1 ) {
98
98
const script = scripts [ 0 ] ;
99
99
if ( Array . isArray ( script ) ) {
100
- return computeMastRoot ( script ) ;
100
+ return rootHashFromTree ( script ) ;
101
101
}
102
102
script . version = script . version || LEAF_VERSION_TAPSCRIPT ;
103
103
if ( ( script . version & 1 ) !== 0 ) throw new Error ( 'Invalid script version' ) ; // todo typedef error
@@ -113,16 +113,16 @@ function computeMastRoot(scripts) {
113
113
}
114
114
// todo: this is a binary tree, use zero an one index
115
115
const half = Math . trunc ( scripts . length / 2 ) ;
116
- let leftHash = computeMastRoot ( scripts . slice ( 0 , half ) ) ;
117
- let rightHash = computeMastRoot ( scripts . slice ( half ) ) ;
116
+ let leftHash = rootHashFromTree ( scripts . slice ( 0 , half ) ) ;
117
+ let rightHash = rootHashFromTree ( scripts . slice ( half ) ) ;
118
118
if ( leftHash . compare ( rightHash ) === 1 )
119
119
[ leftHash , rightHash ] = [ rightHash , leftHash ] ;
120
120
return bcrypto . taggedHash (
121
121
TAP_BRANCH_TAG ,
122
122
buffer_1 . Buffer . concat ( [ leftHash , rightHash ] ) ,
123
123
) ;
124
124
}
125
- exports . computeMastRoot = computeMastRoot ;
125
+ exports . rootHashFromTree = rootHashFromTree ;
126
126
function serializeScript ( s ) {
127
127
const varintLen = varuint . encodingLength ( s . length ) ;
128
128
const buffer = buffer_1 . Buffer . allocUnsafe ( varintLen ) ; // better
0 commit comments