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 {
4040const hash160 = ( data : Uint8Array ) => ripemd160 ( sha256 ( data ) ) ;
4141const fromU32 = ( data : Uint8Array ) => createView ( data ) . getUint32 ( 0 , false ) ;
4242const 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+ }
4346 const buf = new Uint8Array ( 4 ) ;
4447 createView ( buf ) . setUint32 ( 0 , n , false ) ;
4548 return buf ;
@@ -224,8 +227,7 @@ export class HDKey {
224227 if ( ! this . pubKey || ! this . chainCode ) {
225228 throw new Error ( "No publicKey or chainCode set" ) ;
226229 }
227- let data = new Uint8Array ( 4 ) ;
228- createView ( data ) . setUint32 ( 0 , index , false ) ;
230+ let data = toU32 ( index ) ;
229231 if ( index >= HARDENED_OFFSET ) {
230232 // Hardened
231233 const priv = this . privateKey ;
You can’t perform that action at this time.
0 commit comments