UNPKG

1.9 kBJavaScriptView Raw
1'use strict';
2Object.defineProperty(exports, '__esModule', { value: true });
3const typeforce = require('typeforce');
4const UINT31_MAX = Math.pow(2, 31) - 1;
5function UInt31(value) {
6 return typeforce.UInt32(value) && value <= UINT31_MAX;
7}
8exports.UInt31 = UInt31;
9function BIP32Path(value) {
10 return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/);
11}
12exports.BIP32Path = BIP32Path;
13BIP32Path.toJSON = () => {
14 return 'BIP32 derivation path';
15};
16function Signer(obj) {
17 return (
18 (typeforce.Buffer(obj.publicKey) ||
19 typeof obj.getPublicKey === 'function') &&
20 typeof obj.sign === 'function'
21 );
22}
23exports.Signer = Signer;
24const SATOSHI_MAX = 21 * 1e14;
25function Satoshi(value) {
26 return typeforce.UInt53(value) && value <= SATOSHI_MAX;
27}
28exports.Satoshi = Satoshi;
29// external dependent types
30exports.ECPoint = typeforce.quacksLike('Point');
31// exposed, external API
32exports.Network = typeforce.compile({
33 messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
34 bip32: {
35 public: typeforce.UInt32,
36 private: typeforce.UInt32,
37 },
38 pubKeyHash: typeforce.UInt8,
39 scriptHash: typeforce.UInt8,
40 wif: typeforce.UInt8,
41});
42exports.Buffer256bit = typeforce.BufferN(32);
43exports.Hash160bit = typeforce.BufferN(20);
44exports.Hash256bit = typeforce.BufferN(32);
45exports.Number = typeforce.Number; // tslint:disable-line variable-name
46exports.Array = typeforce.Array;
47exports.Boolean = typeforce.Boolean; // tslint:disable-line variable-name
48exports.String = typeforce.String; // tslint:disable-line variable-name
49exports.Buffer = typeforce.Buffer;
50exports.Hex = typeforce.Hex;
51exports.maybe = typeforce.maybe;
52exports.tuple = typeforce.tuple;
53exports.UInt8 = typeforce.UInt8;
54exports.UInt32 = typeforce.UInt32;
55exports.Function = typeforce.Function;
56exports.BufferN = typeforce.BufferN;
57exports.Null = typeforce.Null;
58exports.oneOf = typeforce.oneOf;