You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

10 years ago
var typeforce = require('typeforce')
var UINT31_MAX = Math.pow(2, 31) - 1
10 years ago
function UInt2 (value) { return (value & 3) === value }
function UInt31 (value) {
return typeforce.UInt32(value) && value <= UINT31_MAX
10 years ago
}
function Bip32Path (value) {
return typeforce.String(value) &&
value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
}
10 years ago
// external dependent types
var BigInt = typeforce.quacksLike('BigInteger')
var ECPoint = typeforce.quacksLike('Point')
10 years ago
// exposed, external API
var ECSignature = typeforce.compile({ r: BigInt, s: BigInt })
var Network = typeforce.compile({
messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
bip32: {
public: typeforce.UInt32,
private: typeforce.UInt32
10 years ago
},
pubKeyHash: typeforce.UInt8,
scriptHash: typeforce.UInt8,
wif: typeforce.UInt8,
dustThreshold: typeforce.UInt53
10 years ago
})
// extend typeforce types with ours
var types = {
BigInt: BigInt,
Buffer256bit: typeforce.BufferN(32),
10 years ago
ECPoint: ECPoint,
ECSignature: ECSignature,
Hash160bit: typeforce.BufferN(20),
Hash256bit: typeforce.BufferN(32),
10 years ago
Network: Network,
UInt2: UInt2,
UInt31: UInt31,
Bip32Path: Bip32Path
10 years ago
}
for (var typeName in typeforce) {
types[typeName] = typeforce[typeName]
}
module.exports = types