File tree Expand file tree Collapse file tree 3 files changed +9
-1
lines changed Expand file tree Collapse file tree 3 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ export const BYTES_KEY_LENGTH = 32;
33export const MIN_BIP_44_DEPTH = 0 ;
44export const MAX_BIP_44_DEPTH = 5 ;
55
6+ export const MAX_BIP_32_INDEX = 0xffffffff ;
7+
68export type MinBIP44Depth = typeof MIN_BIP_44_DEPTH ;
79export type MaxBIP44Depth = typeof MAX_BIP_44_DEPTH ;
810export type BIP44Depth = MinBIP44Depth | 1 | 2 | 3 | 4 | MaxBIP44Depth ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { SLIP10Node } from '../SLIP10Node';
1616import {
1717 isValidBytesKey ,
1818 numberToUint32 ,
19+ validateBIP32Index ,
1920 validateSpecification ,
2021} from '../utils' ;
2122
@@ -242,6 +243,8 @@ async function derivePrivateChildKey({
242243
243244 switch ( specification ) {
244245 case 'bip32' : {
246+ validateBIP32Index ( childIndex + 1 ) ;
247+
245248 const secretExtension = await deriveSecretExtension ( {
246249 privateKey,
247250 childIndex : childIndex + 1 ,
@@ -371,6 +374,8 @@ async function derivePublicChildKey({
371374
372375 switch ( specification ) {
373376 case 'bip32' : {
377+ validateBIP32Index ( childIndex + 1 ) ;
378+
374379 // As per BIP-32, if the resulting key is invalid, the key is generated
375380 // from the next child index instead.
376381 return await derivePublicChildKey ( {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 CoinTypeHDPathString ,
1717 CoinTypeToAddressTuple ,
1818 HardenedBIP32Node ,
19+ MAX_BIP_32_INDEX ,
1920 UnhardenedBIP32Node ,
2021} from './constants' ;
2122import { curves , SupportedCurve } from './curves' ;
@@ -172,7 +173,7 @@ export function validateBIP32Index(addressIndex: number) {
172173 * @returns Whether the index is a non-negative integer number.
173174 */
174175export function isValidBIP32Index ( index : number ) : boolean {
175- return isValidInteger ( index ) ;
176+ return isValidInteger ( index ) && index <= MAX_BIP_32_INDEX ;
176177}
177178
178179/**
You can’t perform that action at this time.
0 commit comments