Typechecking indexes
As a consequence, it will not allow accidentally double-hardened indexes. It also won't allow strings or forgotten parameters.
This commit is contained in:
parent
75bd8331cd
commit
4a72001335
3 changed files with 51 additions and 0 deletions
src
|
@ -206,6 +206,8 @@ HDNode.prototype.toBase58 = function (__isPrivate) {
|
|||
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
|
||||
HDNode.prototype.derive = function (index) {
|
||||
typeforce(types.UInt32, index)
|
||||
|
||||
var isHardened = index >= HDNode.HIGHEST_BIT
|
||||
var data = new Buffer(37)
|
||||
|
||||
|
@ -277,6 +279,8 @@ HDNode.prototype.derive = function (index) {
|
|||
}
|
||||
|
||||
HDNode.prototype.deriveHardened = function (index) {
|
||||
typeforce(types.UInt31, index)
|
||||
|
||||
// Only derives hardened private keys by default
|
||||
return this.derive(index + HDNode.HIGHEST_BIT)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue