Browse Source

types: remove unused UInt2, BIP32 is capitals

hk-custom-address
Daniel Cousens 8 years ago
committed by Daniel Cousens
parent
commit
9f1ebf72a6
  1. 2
      src/hdnode.js
  2. 15
      src/types.js

2
src/hdnode.js

@ -294,7 +294,7 @@ HDNode.prototype.isNeutered = function () {
} }
HDNode.prototype.derivePath = function (path) { HDNode.prototype.derivePath = function (path) {
typeforce(types.Bip32Path, path) typeforce(types.BIP32Path, path)
var splitPath = path.split('/') var splitPath = path.split('/')
if (splitPath[0] === 'm') { if (splitPath[0] === 'm') {

15
src/types.js

@ -1,21 +1,19 @@
var typeforce = require('typeforce') var typeforce = require('typeforce')
var UINT31_MAX = Math.pow(2, 31) - 1 var UINT31_MAX = Math.pow(2, 31) - 1
function UInt2 (value) { return (value & 3) === value }
function UInt31 (value) { function UInt31 (value) {
return typeforce.UInt32(value) && value <= UINT31_MAX return typeforce.UInt32(value) && value <= UINT31_MAX
} }
function BIP32Path (value) {
return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
}
var SATOSHI_MAX = 2.1 * 1e15 var SATOSHI_MAX = 2.1 * 1e15
function Satoshi (value) { function Satoshi (value) {
return typeforce.UInt53(value) && value <= SATOSHI_MAX return typeforce.UInt53(value) && value <= SATOSHI_MAX
} }
function Bip32Path (value) {
return typeforce.String(value) &&
value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
}
// external dependent types // external dependent types
var BigInt = typeforce.quacksLike('BigInteger') var BigInt = typeforce.quacksLike('BigInteger')
var ECPoint = typeforce.quacksLike('Point') var ECPoint = typeforce.quacksLike('Point')
@ -37,6 +35,7 @@ var Network = typeforce.compile({
// extend typeforce types with ours // extend typeforce types with ours
var types = { var types = {
BigInt: BigInt, BigInt: BigInt,
BIP32Path: BIP32Path,
Buffer256bit: typeforce.BufferN(32), Buffer256bit: typeforce.BufferN(32),
ECPoint: ECPoint, ECPoint: ECPoint,
ECSignature: ECSignature, ECSignature: ECSignature,
@ -44,9 +43,7 @@ var types = {
Hash256bit: typeforce.BufferN(32), Hash256bit: typeforce.BufferN(32),
Network: Network, Network: Network,
Satoshi: Satoshi, Satoshi: Satoshi,
UInt2: UInt2, UInt31: UInt31
UInt31: UInt31,
Bip32Path: Bip32Path
} }
for (var typeName in typeforce) { for (var typeName in typeforce) {

Loading…
Cancel
Save