UNPKG

2.47 kBJavaScriptView Raw
1/**
2 * Constants
3 * =========
4 *
5 * Constants used to distinguish mainnet from testnet.
6 */
7'use strict'
8import { config } from './config'
9
10const Constants = {}
11
12Constants.Mainnet = {
13 maxsize: 0x02000000, // MAX_SIZE
14 Address: {
15 pubKeyHash: 0x00
16 },
17 Bip32: {
18 pubKey: 0x0488b21e,
19 privKey: 0x0488ade4
20 },
21 Block: {
22 maxNBits: 0x1d00ffff,
23 magicNum: 0xf9beb4d9
24 },
25 Msg: {
26 magicNum: 0xf9beb4d9,
27 versionBytesNum: 70012 // as of Bitcoin Core v0.12.0
28 },
29 PrivKey: {
30 versionByteNum: 0x80
31 },
32 TxBuilder: {
33 dust: 546, // number of satoshis that an output can't be less than
34 feePerKbNum: 0.00000500e8
35 },
36 Workers: {
37 // Cannot be 5 seconds. This is actually too low for low end devices. We
38 // have found by experimenting with Chrome developer tools that 60 seconds
39 // works on low end mobile.
40 timeout: 60000
41 }
42}
43
44Constants.Testnet = Object.assign({}, Constants.Mainnet, {
45 Address: {
46 pubKeyHash: 0x6f
47 },
48 Bip32: {
49 pubKey: 0x043587cf,
50 privKey: 0x04358394
51 },
52 Block: {
53 maxNBits: 0x1d00ffff,
54 magicNum: 0x0b110907
55 },
56 Msg: {
57 magicNum: 0x0b110907,
58 versionBytesNum: 70012 // as of Bitcoin Core v0.12.0
59 },
60 PrivKey: {
61 versionByteNum: 0xef
62 }
63})
64
65Constants.Regtest = Object.assign({}, Constants.Mainnet, {
66 Address: {
67 pubKeyHash: 0x6f
68 },
69 Bip32: {
70 pubKey: 0x043587cf,
71 privKey: 0x04358394
72 },
73 Block: {
74 maxNBits: 0x1d00ffff,
75 magicNum: 0xdab5bffa
76 },
77 Msg: {
78 magicNum: 0x0b110907,
79 versionBytesNum: 70012 // as of Bitcoin Core v0.12.0
80 },
81 PrivKey: {
82 versionByteNum: 0xef
83 }
84})
85
86/**
87 * Yours Bitcoin can be globally configured to mainnet or testnet. Via the
88 * inject pattern, you always have access to the other network at any time.
89 * However, it is very convenient to be able to change the default
90 * configuration. The default is mainnet, which can be changed to testnet.
91 */
92// Constants.Default = Object.assign({}, Constants.Mainnet)
93if (config.get('NETWORK') === 'testnet') {
94 Constants.Default = Object.assign({}, Constants.Testnet)
95} else if (config.get('NETWORK') === 'mainnet') {
96 Constants.Default = Object.assign({}, Constants.Mainnet)
97} else if (config.get('NETWORK') === 'regtest') {
98 Constants.Default = Object.assign({}, Constants.Regtest)
99} else {
100 throw new Error(
101 `must set network in environment variable - mainnet, testnet or regtest?, received ${config.get('NETWORK')}`
102 )
103}
104
105export { Constants }