File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,30 @@ HDNode.prototype.isNeutered = function () {
291291 return ! ( this . keyPair . d )
292292}
293293
294+ HDNode . prototype . derivePath = function ( path ) {
295+ typeforce ( types . String , path )
296+
297+ var splitPath = path . split ( '/' )
298+ if ( splitPath [ 0 ] === 'm' ) {
299+ if ( this . parentFingerprint ) {
300+ throw new Error ( 'Not a master node' )
301+ }
302+
303+ splitPath = splitPath . slice ( 1 )
304+ }
305+
306+ return splitPath . reduce ( function ( prevHd , indexStr ) {
307+ var index
308+ if ( indexStr . slice ( - 1 ) === "'" ) {
309+ index = + ( indexStr . slice ( 0 , - 1 ) )
310+ return prevHd . deriveHardened ( index )
311+ } else {
312+ index = + indexStr
313+ return prevHd . derive ( index )
314+ }
315+ } , this )
316+ }
317+
294318HDNode . prototype . toString = HDNode . prototype . toBase58
295319
296320module . exports = HDNode
You can’t perform that action at this time.
0 commit comments