1 | 'use strict';
|
2 | Object.defineProperty(exports, '__esModule', { value: true });
|
3 | const typeforce = require('typeforce');
|
4 | const UINT31_MAX = Math.pow(2, 31) - 1;
|
5 | function UInt31(value) {
|
6 | return typeforce.UInt32(value) && value <= UINT31_MAX;
|
7 | }
|
8 | exports.UInt31 = UInt31;
|
9 | function BIP32Path(value) {
|
10 | return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/);
|
11 | }
|
12 | exports.BIP32Path = BIP32Path;
|
13 | BIP32Path.toJSON = () => {
|
14 | return 'BIP32 derivation path';
|
15 | };
|
16 | function Signer(obj) {
|
17 | return (
|
18 | (typeforce.Buffer(obj.publicKey) ||
|
19 | typeof obj.getPublicKey === 'function') &&
|
20 | typeof obj.sign === 'function'
|
21 | );
|
22 | }
|
23 | exports.Signer = Signer;
|
24 | const SATOSHI_MAX = 21 * 1e14;
|
25 | function Satoshi(value) {
|
26 | return typeforce.UInt53(value) && value <= SATOSHI_MAX;
|
27 | }
|
28 | exports.Satoshi = Satoshi;
|
29 |
|
30 | exports.ECPoint = typeforce.quacksLike('Point');
|
31 |
|
32 | exports.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 | });
|
42 | exports.Buffer256bit = typeforce.BufferN(32);
|
43 | exports.Hash160bit = typeforce.BufferN(20);
|
44 | exports.Hash256bit = typeforce.BufferN(32);
|
45 | exports.Number = typeforce.Number;
|
46 | exports.Array = typeforce.Array;
|
47 | exports.Boolean = typeforce.Boolean;
|
48 | exports.String = typeforce.String;
|
49 | exports.Buffer = typeforce.Buffer;
|
50 | exports.Hex = typeforce.Hex;
|
51 | exports.maybe = typeforce.maybe;
|
52 | exports.tuple = typeforce.tuple;
|
53 | exports.UInt8 = typeforce.UInt8;
|
54 | exports.UInt32 = typeforce.UInt32;
|
55 | exports.Function = typeforce.Function;
|
56 | exports.BufferN = typeforce.BufferN;
|
57 | exports.Null = typeforce.Null;
|
58 | exports.oneOf = typeforce.oneOf;
|