You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allows deriving keys that can't be seriliazed due to overflowing depth #92
Hi,
extended keys at depths of 256 and higher can be derived. But cannot be serialized. This is compliant with BIP32 specification, but is allowing the derivation of such keys intentional?
See the following tests for examples:
diff --git a/test/index.js b/test/index.js
index 1f16f65..6b9096a 100644
--- a/test/index.js+++ b/test/index.js@@ -226,6 +226,38 @@ tape('fromSeed', (t) => {
t.end()
})
+tape('derives keys with overflowing depth', (t) => {+ let hd = BIP32.fromSeed(Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex'))++ for (let i = 0; i < 255; i++) {+ hd = hd.derive(0);+ }+ // Extended key at 255th is serializable+ t.equal(hd.depth, BIP32.fromBase58(hd.toBase58()).depth);++ hd = hd.derive(0);+ t.equal(hd.depth, 256);++ // throws ERR_OUT_OF_RANGE+ hd.toBase58();+ t.end()+})++tape('derives keys from path with overflowing depth', (t) => {+ let hd = BIP32.fromSeed(Buffer.from('000102030405060708090a0b0c0d0e0f', 'hex'))++ hd = hd.derivePath("m" + "/0".repeat(255));+ // Extended key at 255th is serializable+ t.equal(hd.depth, BIP32.fromBase58(hd.toBase58()).depth);++ hd = hd.derive(0);+ // Extended key at 256th depth that overflows a byte+ t.equal(hd.depth, 256);++ // throws ERR_OUT_OF_RANGE+ hd.toBase58();+ t.end()+})+
tape('ecdsa', (t) => {
let seed = Buffer.alloc(32, 1)
let hash = Buffer.alloc(32, 2)
Activity
junderw commentedon Apr 6, 2025
This is not intentional, but it is also not a problem for normal use.
Since the BIP makes no restrictions on the depth outside the implied limit of the serialization, I see no reason to limit the depth.
If the BIP32 document changes I will consider fixing it.
Thanks for the issue.