-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathconstants.js
More file actions
308 lines (284 loc) · 9.91 KB
/
constants.js
File metadata and controls
308 lines (284 loc) · 9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
Fabric Core Constants.
---
Author: Fabric Labs
Copyright: All Rights Reserved.
*/
'use strict';
// Networking and Environment
const PEER_PORT = 7777;
const MAX_PEERS = 32;
const PRECISION = 100;
// Fabric Core
const FABRIC_USER_AGENT = 'Fabric Core 0.1.0 (@fabric/core#v0.1.0-RC2)';
const BITCOIN_NETWORK = 'mainnet';
const BITCOIN_GENESIS = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
const BITCOIN_GENESIS_ROOT = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
const FABRIC_KEY_DERIVATION_PATH = "m/44'/7777'/0'/0/0";
const FIXTURE_SEED = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const FIXTURE_XPUB = 'xpub661MyMwAqRbcF6GygV6Q6XAg8dqhPvDuhYHGniequi6HMbYhNNH5XC13Np3qRANHVD2mmnNGtMGBfDT69s2ovpHLr7q8syoAuyWqtRGEsYQ';
const FIXTURE_XPRV = 'xprv9s21ZrQH143K2cCWaTZPjPDwac1CzTW4LKMfzLFEMNZJUoDYppxpyPgZXY7CZkjefGJTrTyqKnMrM4RG6nGn7Q9cwjHggCtn3CdFGJahaWY';
// Message Constants
const MAGIC_BYTES = 0xC0D3F33D;
const VERSION_NUMBER = 0x02; // bumped for 208-byte header (optional preimage field)
/* magic, version, parent, author, type, size, hash, preimage, signature — then body */
const HEADER_SIZE = 208;
const LARGE_COLLECTION_SIZE = 10; // TODO: test with 1,000,000
const MAX_MESSAGE_SIZE = 4096 - HEADER_SIZE;
// Stacks and Frames
const MAX_STACK_HEIGHT = 32; // max height of stack (number of elements)
const MAX_FRAME_SIZE = 32; // max size of a stack frame in bytes
const MAX_MEMORY_ALLOC = MAX_STACK_HEIGHT * MAX_FRAME_SIZE;
const MAX_TX_PER_BLOCK = 4;
const MAX_CHANNEL_VALUE = 100000000;
// Machine Constraints
const MACHINE_MAX_MEMORY = MAX_MEMORY_ALLOC * MAX_MESSAGE_SIZE;
const MAX_CHAT_MESSAGE_LENGTH = 2048;
// Playnet
const FABRIC_PLAYNET_ADDRESS = ''; // deposit address (P2TR)
const FABRIC_PLAYNET_ORIGIN = ''; // block hash of first deploy
// FABRIC ONLY
const BITCOIN_BLOCK_TYPE = 21000;
const BITCOIN_BLOCK_HASH_TYPE = 21100;
const BITCOIN_TRANSACTION_TYPE = 22000;
const BITCOIN_TRANSACTION_HASH_TYPE = 22100;
const GENERIC_MESSAGE_TYPE = 15103;
const LOG_MESSAGE_TYPE = 3235156080;
const GENERIC_LIST_TYPE = 3235170158;
const DOCUMENT_PUBLISH_TYPE = 998;
const DOCUMENT_REQUEST_TYPE = 999;
const JSON_CALL_TYPE = 16000;
const PATCH_MESSAGE_TYPE = 1024;
/** Contract negotiation: batched Fabric messages + chain Merkle root + JSON Patch (RFC 6902) — see docs/CONTRACT_PROPOSAL.md */
const CONTRACT_PROPOSAL_TYPE = 138; // 0x8A (POLICY.md / FABRIC_MESSAGE_TYPE_CONSOLIDATION)
// Opcodes
const OP_CYCLE = '00';
const OP_DONE = 'ff';
// Bitcoin
const OP_0 = '00';
const OP_36 = '24';
const OP_CHECKSIG = 'ac';
const OP_DUP = '76';
const OP_EQUAL = '87';
const OP_SHA256 = 'a8';
const OP_HASH160 = 'a9';
const OP_PUSHDATA1 = '4c';
const OP_RETURN = '6a';
const OP_EQUALVERIFY = '88';
const OP_SEPARATOR = 'ab';
// Bech32m
const BECH32M_CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
// Peering
const P2P_PORT = 7777;
// Gossip and peering discovery (WebRTC + Fabric P2P)
const P2P_PEER_GOSSIP = 'P2P_PEER_GOSSIP'; // Gossip known peers for cross-cluster discovery
const P2P_PEERING_OFFER = 'P2P_PEERING_OFFER'; // Peer needs more connections; gossiped until fulfilled
/** Max gossip relays per logical hop (anti amplification). */
const GOSSIP_MAX_HOPS = 5;
/** Per-origin relay budget per rolling minute (anti flood). */
const GOSSIP_MAX_RELAYS_PER_ORIGIN_PER_MINUTE = 60;
/** Max entries for logical gossip payload dedup (excluding hop/signature churn). */
const GOSSIP_MAX_PAYLOAD_CACHE = 50000;
/** Peering-offer relay: same defaults as gossip (separate caches / rate map). */
const PEERING_OFFER_MAX_HOPS = 5;
const PEERING_OFFER_MAX_RELAYS_PER_ORIGIN_PER_MINUTE = 60;
const PEERING_OFFER_MAX_PAYLOAD_CACHE = 50000;
/** Max queued connection candidates from {@link P2P_PEERING_OFFER} (FIFO eviction). */
const PEER_MAX_CANDIDATES_QUEUE = 128;
/** Max wire-hash dedup entries in {@link Peer} (bounded memory). */
const PEER_MAX_WIRE_HASH_CACHE = 10000;
const P2P_GENERIC = 0x80; // 128 in decimal
const P2P_IDENT_REQUEST = 0x01; // 1, or the identity
const P2P_IDENT_RESPONSE = 0x11;
const P2P_ROOT = 0x00000000;
const P2P_PING = 0x00000012; // same ID as Lightning (18)
const P2P_PONG = 0x00000013; // same ID as Lightning (19)
const P2P_INSTRUCTION = 0x00000020; // TODO: select w/ no overlap
const P2P_START_CHAIN = 0x00000021;
const P2P_STATE_REQUEST = 0x00000029; // TODO: select w/ no overlap
const P2P_STATE_ROOT = 0x00000030; // TODO: select w/ no overlap
const P2P_BASE_MESSAGE = 0x00000031; // TODO: select w/ no overlap
const P2P_STATE_COMMITTMENT = 0x00000032; // TODO: select w/ no overlap
const P2P_STATE_CHANGE = 0x00000033; // TODO: select w/ no overlap
const P2P_TRANSACTION = 0x00000039; // TODO: select w/ no overlap
const P2P_CALL = 0x00000042;
const P2P_RELAY = 0x00000043; // Relay envelope for onion routing; preserves original message + signature
const P2P_MESSAGE_RECEIPT = 0x00000044; // Ack/receipt for a processed inbound message (WebSocket / P2P)
const P2P_CHAIN_SYNC_REQUEST = 0x55;
const P2P_SESSION_ACK = 0x4200;
const P2P_MUSIG_START = 0x4220;
const P2P_MUSIG_ACCEPT = 0x4221;
const P2P_MUSIG_RECEIVE_COUNTER = 0x4222;
const P2P_MUSIG_SEND_PROPOSAL = 0x4223;
const P2P_MUSIG_REPLY_TO_PROPOSAL = 0x4224;
const P2P_MUSIG_ACCEPT_PROPOSAL = 0x4225;
// Message Types
const PEER_CANDIDATE = 0x09;
// TODO: should be 0x02 for Bitcoin P2P
const BLOCK_CANDIDATE = 0x03;
const SESSION_START = 0x02;
const CHAT_MESSAGE = 0x67;
// Lightning
const LIGHTNING_TEST_HEADER = 'D0520C6E';
const LIGHTNING_PROTOCOL_H_INIT = 'Noise_XK_secp256k1_ChaChaPoly_SHA256';
const LIGHTNING_PROTOCOL_PROLOGUE = 'lightning';
// Lightning BOLT Message Types (subset)
// Setup & Control
const LIGHTNING_WARNING = 0x00000001; // 1
const LIGHTNING_INIT = 0x00000010; // 16
const LIGHTNING_ERROR = 0x00000011; // 17
const LIGHTNING_PING = 0x00000012; // 18 (alias of P2P_PING)
const LIGHTNING_PONG = 0x00000013; // 19 (alias of P2P_PONG)
// Channel Management
const LIGHTNING_OPEN_CHANNEL = 0x00000020; // 32
const LIGHTNING_ACCEPT_CHANNEL = 0x00000021; // 33
const LIGHTNING_FUNDING_CREATED = 0x00000022; // 34
const LIGHTNING_FUNDING_SIGNED = 0x00000023; // 35
const LIGHTNING_CHANNEL_READY = 0x00000024; // 36
const LIGHTNING_SHUTDOWN = 0x00000026; // 38
const LIGHTNING_CLOSING_SIGNED = 0x00000027; // 39
// Payment Messages
const LIGHTNING_UPDATE_ADD_HTLC = 0x00000080; // 128
const LIGHTNING_UPDATE_FULFILL_HTLC = 0x00000082; // 130
const LIGHTNING_UPDATE_FAIL_HTLC = 0x00000083; // 131
const LIGHTNING_COMMITMENT_SIGNED = 0x00000084; // 132
const LIGHTNING_REVOKE_AND_ACK = 0x00000085; // 133
// Gossip Protocol
const LIGHTNING_CHANNEL_ANNOUNCEMENT = 0x00000100; // 256
const LIGHTNING_NODE_ANNOUNCEMENT = 0x00000101; // 257
const LIGHTNING_CHANNEL_UPDATE = 0x00000102; // 258
// Lightning BMM
const LIGHTNING_BMM_HEADER = 'D0520C6E';
const LIGHTNING_SIDECHAIN_NUM = 0xFF; // 1-byte - sidechain number
const LIGHTNING_SIDEBLOCK_HASH = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000; // 32-bytes
const LIGHTNING_PARENT_SIDEBLOCK_HASH = 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001; // 32-bytes
const ZERO_LENGTH_PLAINTEXT = '';
// HTTP
const HTTP_HEADER_CONTENT_TYPE = 'application/json';
// UI
const INPUT_HINT = 'Press the "i" key to begin typing.';
// CommonJS Support
module.exports = {
PEER_PORT,
MAX_PEERS,
PRECISION,
BITCOIN_NETWORK,
BITCOIN_GENESIS,
BITCOIN_GENESIS_HASH: BITCOIN_GENESIS,
BITCOIN_GENESIS_ROOT,
FABRIC_KEY_DERIVATION_PATH,
FABRIC_USER_AGENT,
FIXTURE_SEED,
FIXTURE_XPUB,
FIXTURE_XPRV,
HEADER_SIZE,
BITCOIN_BLOCK_TYPE,
BITCOIN_BLOCK_HASH_TYPE,
BITCOIN_TRANSACTION_TYPE,
BITCOIN_TRANSACTION_HASH_TYPE,
GENERIC_MESSAGE_TYPE,
LOG_MESSAGE_TYPE,
GENERIC_LIST_TYPE,
LARGE_COLLECTION_SIZE,
BLOCK_CANDIDATE,
CHAT_MESSAGE,
INPUT_HINT,
ZERO_LENGTH_PLAINTEXT,
BECH32M_CHARSET,
FABRIC_PLAYNET_ADDRESS,
FABRIC_PLAYNET_ORIGIN,
LIGHTNING_TEST_HEADER,
LIGHTNING_PROTOCOL_H_INIT,
LIGHTNING_PROTOCOL_PROLOGUE,
LIGHTNING_WARNING,
LIGHTNING_INIT,
LIGHTNING_ERROR,
LIGHTNING_PING,
LIGHTNING_PONG,
LIGHTNING_OPEN_CHANNEL,
LIGHTNING_ACCEPT_CHANNEL,
LIGHTNING_FUNDING_CREATED,
LIGHTNING_FUNDING_SIGNED,
LIGHTNING_CHANNEL_READY,
LIGHTNING_SHUTDOWN,
LIGHTNING_CLOSING_SIGNED,
LIGHTNING_UPDATE_ADD_HTLC,
LIGHTNING_UPDATE_FULFILL_HTLC,
LIGHTNING_UPDATE_FAIL_HTLC,
LIGHTNING_COMMITMENT_SIGNED,
LIGHTNING_REVOKE_AND_ACK,
LIGHTNING_CHANNEL_ANNOUNCEMENT,
LIGHTNING_NODE_ANNOUNCEMENT,
LIGHTNING_CHANNEL_UPDATE,
LIGHTNING_BMM_HEADER,
LIGHTNING_SIDECHAIN_NUM,
LIGHTNING_SIDEBLOCK_HASH,
LIGHTNING_PARENT_SIDEBLOCK_HASH,
HTTP_HEADER_CONTENT_TYPE,
MAGIC_BYTES,
MAX_FRAME_SIZE,
MAX_MEMORY_ALLOC,
MAX_MESSAGE_SIZE,
MAX_STACK_HEIGHT,
MAX_CHANNEL_VALUE,
MAX_CHAT_MESSAGE_LENGTH,
MAX_TX_PER_BLOCK,
MACHINE_MAX_MEMORY,
OP_CYCLE,
OP_DONE,
OP_0,
OP_36,
OP_CHECKSIG,
OP_DUP,
OP_EQUAL,
OP_SHA256,
OP_HASH160,
OP_PUSHDATA1,
OP_RETURN,
OP_EQUALVERIFY,
OP_SEPARATOR,
P2P_GENERIC,
P2P_PEER_GOSSIP,
P2P_PEERING_OFFER,
GOSSIP_MAX_HOPS,
GOSSIP_MAX_RELAYS_PER_ORIGIN_PER_MINUTE,
GOSSIP_MAX_PAYLOAD_CACHE,
PEERING_OFFER_MAX_HOPS,
PEERING_OFFER_MAX_RELAYS_PER_ORIGIN_PER_MINUTE,
PEERING_OFFER_MAX_PAYLOAD_CACHE,
PEER_MAX_CANDIDATES_QUEUE,
PEER_MAX_WIRE_HASH_CACHE,
P2P_IDENT_REQUEST,
P2P_IDENT_RESPONSE,
P2P_CHAIN_SYNC_REQUEST,
P2P_ROOT,
P2P_PING,
P2P_PONG,
P2P_PORT,
P2P_START_CHAIN,
P2P_INSTRUCTION,
P2P_BASE_MESSAGE,
P2P_STATE_ROOT,
P2P_STATE_COMMITTMENT,
P2P_STATE_CHANGE,
P2P_STATE_REQUEST,
P2P_TRANSACTION,
P2P_CALL,
P2P_RELAY,
P2P_MESSAGE_RECEIPT,
P2P_SESSION_ACK,
P2P_MUSIG_START,
P2P_MUSIG_ACCEPT,
P2P_MUSIG_RECEIVE_COUNTER,
P2P_MUSIG_SEND_PROPOSAL,
P2P_MUSIG_REPLY_TO_PROPOSAL,
P2P_MUSIG_ACCEPT_PROPOSAL,
PEER_CANDIDATE,
DOCUMENT_PUBLISH_TYPE,
DOCUMENT_REQUEST_TYPE,
JSON_CALL_TYPE,
PATCH_MESSAGE_TYPE,
CONTRACT_PROPOSAL_TYPE,
SESSION_START,
VERSION_NUMBER
};