- Notifications
You must be signed in to change notification settings - Fork 2.2k
Adding path derivation #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7defe6f 7a61526 755eac5 182698f d2b43f1 6a74eb6 3c56e80 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Again through typeforce
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -26,6 +26,11 @@ function UInt53 (value) { | |
| Math.floor(value) === value | ||
| } | ||
| | ||
| function Path (value) { | ||
| ||
| return typeforce.String(value) && | ||
| value.match(/^([m]\/)?([0-9]+[']?\/)*([0-9]+[']?)$/) | ||
| } | ||
| | ||
| // external dependent types | ||
| var BigInt = typeforce.quacksLike('BigInteger') | ||
| var ECPoint = typeforce.quacksLike('Point') | ||
| | @@ -57,7 +62,8 @@ var types = { | |
| UInt8: UInt8, | ||
| UInt31: UInt31, | ||
| UInt32: UInt32, | ||
| UInt53: UInt53 | ||
| UInt53: UInt53, | ||
| Path: Path | ||
| } | ||
| | ||
| for (var typeName in typeforce) { | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -312,8 +312,7 @@ describe('HDNode', function () { | |
| | ||
| var pathSplit = path.split('/').slice(i + 2) | ||
| var pathEnd = pathSplit.join('/') | ||
| var pathEndM = 'm/' + path | ||
| | ||
| var pathEndM = 'm/' + pathEnd | ||
| var child = cn.derivePath(pathEnd) | ||
| verifyVector(child, cc, pathSplit.length + i + 1) | ||
| | ||
| | @@ -390,7 +389,7 @@ describe('HDNode', function () { | |
| }, /Expected UInt32/) | ||
| }) | ||
| | ||
| it('throws on non-numbers', function () { | ||
| it('throws on wrong types', function () { | ||
| var f = fixtures.valid[0] | ||
| var master = HDNode.fromBase58(f.master.base58, NETWORKS_LIST) | ||
| | ||
| | @@ -406,6 +405,30 @@ describe('HDNode', function () { | |
| assert.throws(function () { | ||
| master.derive('foo') | ||
| }, /Expected UInt32/) | ||
| assert.throws(function () { | ||
| master.derivePath() | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath(2) | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath([2, 3, 4]) | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath('/') | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath('m/m/123') | ||
| }, /Expected Path/) | ||
| ||
| assert.throws(function () { | ||
| master.derivePath('a/0/1/2') | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath('m/0/ 1 /2') | ||
| }, /Expected Path/) | ||
| assert.throws(function () { | ||
| master.derivePath('m/0/1.5/2') | ||
| }, /Expected Path/) | ||
| }) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this just doesn't take a
stringas input?