File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ export interface Versions {
40
40
const hash160 = ( data : Uint8Array ) => ripemd160 ( sha256 ( data ) ) ;
41
41
const fromU32 = ( data : Uint8Array ) => createView ( data ) . getUint32 ( 0 , false ) ;
42
42
const toU32 = ( n : number ) => {
43
+ if ( ! Number . isSafeInteger ( n ) || n < 0 || n >= 2 ** 32 ) {
44
+ throw new Error ( `Invalid number=${ n } . Should be [0, 2**32)` ) ;
45
+ }
43
46
const buf = new Uint8Array ( 4 ) ;
44
47
createView ( buf ) . setUint32 ( 0 , n , false ) ;
45
48
return buf ;
@@ -224,8 +227,7 @@ export class HDKey {
224
227
if ( ! this . pubKey || ! this . chainCode ) {
225
228
throw new Error ( "No publicKey or chainCode set" ) ;
226
229
}
227
- let data = new Uint8Array ( 4 ) ;
228
- createView ( data ) . setUint32 ( 0 , index , false ) ;
230
+ let data = toU32 ( index ) ;
229
231
if ( index >= HARDENED_OFFSET ) {
230
232
// Hardened
231
233
const priv = this . privateKey ;
You can’t perform that action at this time.
0 commit comments