@leocuvee/turtlecoin-utils 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +27 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/turtlecoin-utils.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.travis.yml +11 -0
- package/CONTRIBUTING.md +3 -0
- package/LICENSE +674 -0
- package/README.md +203 -0
- package/config.json +7 -0
- package/docs/.nojekyll +0 -0
- package/docs/CNAME +1 -0
- package/docs/assets/css/main.css +2321 -0
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +1 -0
- package/docs/assets/js/search.js +3 -0
- package/docs/classes/address.html +964 -0
- package/docs/classes/addressprefix.html +431 -0
- package/docs/classes/block.html +965 -0
- package/docs/classes/blocktemplate.html +695 -0
- package/docs/classes/cryptonote.html +1137 -0
- package/docs/classes/ed25519.keypair.html +400 -0
- package/docs/classes/ed25519.keys.html +373 -0
- package/docs/classes/extranoncetag.extranoncedata.html +454 -0
- package/docs/classes/extranoncetag.extranoncepaymentid.html +453 -0
- package/docs/classes/extranoncetag.iextranonce.html +347 -0
- package/docs/classes/extratag.extramergedmining.html +494 -0
- package/docs/classes/extratag.extranonce.html +530 -0
- package/docs/classes/extratag.extrapadding.html +456 -0
- package/docs/classes/extratag.extrapublickey.html +460 -0
- package/docs/classes/extratag.iextratag.html +355 -0
- package/docs/classes/levinpacket.html +674 -0
- package/docs/classes/levinpayloads.handshake.html +731 -0
- package/docs/classes/levinpayloads.ilevinpayload.html +318 -0
- package/docs/classes/levinpayloads.liteblock.html +494 -0
- package/docs/classes/levinpayloads.missingtransactions.html +494 -0
- package/docs/classes/levinpayloads.newblock.html +540 -0
- package/docs/classes/levinpayloads.newtransactions.html +402 -0
- package/docs/classes/levinpayloads.peerentry.html +610 -0
- package/docs/classes/levinpayloads.ping.html +450 -0
- package/docs/classes/levinpayloads.rawblock.html +344 -0
- package/docs/classes/levinpayloads.requestchain.html +402 -0
- package/docs/classes/levinpayloads.requestgetobjects.html +448 -0
- package/docs/classes/levinpayloads.requesttxpool.html +402 -0
- package/docs/classes/levinpayloads.responsechain.html +494 -0
- package/docs/classes/levinpayloads.responsegetobjects.html +540 -0
- package/docs/classes/levinpayloads.timedsync.html +540 -0
- package/docs/classes/multisig.html +930 -0
- package/docs/classes/multisigmessage.html +694 -0
- package/docs/classes/parentblock.html +347 -0
- package/docs/classes/transaction.html +925 -0
- package/docs/classes/transactioninputs.coinbaseinput.html +390 -0
- package/docs/classes/transactioninputs.itransactioninput.html +321 -0
- package/docs/classes/transactioninputs.keyinput.html +459 -0
- package/docs/classes/transactionoutputs.itransactionoutput.html +317 -0
- package/docs/classes/transactionoutputs.keyoutput.html +422 -0
- package/docs/enums/extranoncetag.noncetagtype.html +246 -0
- package/docs/enums/extratag.extratagtype.html +280 -0
- package/docs/enums/levinprotocol.commandtype.html +391 -0
- package/docs/enums/transactioninputs.inputtype.html +246 -0
- package/docs/enums/transactionoutputs.outputtype.html +229 -0
- package/docs/globals.html +238 -0
- package/docs/index.html +271 -0
- package/docs/interfaces/interfaces.config.html +590 -0
- package/docs/interfaces/interfaces.daemonblocktemplateresponse.html +323 -0
- package/docs/interfaces/interfaces.generatedinput.html +304 -0
- package/docs/interfaces/interfaces.generatedoutput.html +285 -0
- package/docs/interfaces/interfaces.inputkeys.html +304 -0
- package/docs/interfaces/interfaces.ipreparedtransaction.html +268 -0
- package/docs/interfaces/interfaces.output.html +399 -0
- package/docs/interfaces/interfaces.preparedringsignature.html +377 -0
- package/docs/interfaces/interfaces.preparedtransaction.html +329 -0
- package/docs/interfaces/interfaces.randomoutput.html +285 -0
- package/docs/interfaces/interfaces.transactionrecipient.html +285 -0
- package/docs/interfaces/multisiginterfaces.partialkeyimage.html +277 -0
- package/docs/interfaces/multisiginterfaces.partialsigningkey.html +277 -0
- package/docs/modules/ed25519.html +195 -0
- package/docs/modules/extranoncetag.html +208 -0
- package/docs/modules/extratag.html +216 -0
- package/docs/modules/interfaces.html +231 -0
- package/docs/modules/levinpayloads.html +247 -0
- package/docs/modules/levinprotocol.html +191 -0
- package/docs/modules/multisiginterfaces.html +195 -0
- package/docs/modules/transactioninputs.html +208 -0
- package/docs/modules/transactionoutputs.html +204 -0
- package/index.d.ts +417 -0
- package/index.js +1508 -0
- package/lib/base58.js +220 -0
- package/lib/biginteger.js +1591 -0
- package/lib/blocktemplate.js +408 -0
- package/lib/crypto.js +19698 -0
- package/lib/mnemonic.js +1204 -0
- package/lib/nacl-fast-cn.js +608 -0
- package/lib/ringsigs.js +24262 -0
- package/lib/sha3.js +477 -0
- package/package.json +58 -0
- package/src/Address.ts +433 -0
- package/src/AddressPrefix.ts +117 -0
- package/src/Block.ts +556 -0
- package/src/BlockTemplate.ts +289 -0
- package/src/Common.ts +105 -0
- package/src/Config.ts +66 -0
- package/src/CryptoNote.ts +1072 -0
- package/src/LevinPacket.ts +366 -0
- package/src/Multisig.ts +600 -0
- package/src/MultisigMessage.ts +374 -0
- package/src/ParentBlock.ts +39 -0
- package/src/Transaction.ts +628 -0
- package/src/Types/ED25519.ts +187 -0
- package/src/Types/IExtraNonce.ts +225 -0
- package/src/Types/IExtraTag.ts +507 -0
- package/src/Types/ITransaction.ts +230 -0
- package/src/Types/ITransactionInput.ts +190 -0
- package/src/Types/ITransactionOutput.ts +108 -0
- package/src/Types/LevinPayloads.ts +1576 -0
- package/src/Types/MultisigInterfaces.ts +65 -0
- package/src/Types/PortableStorage.ts +289 -0
- package/src/Types.ts +36 -0
- package/src/index.ts +36 -0
- package/test/template.json +6 -0
- package/test/test.js +1457 -0
- package/tests/blocktemplate.json +6 -0
- package/tests/tests.js +215 -0
- package/tsconfig.json +15 -0
- package/tslint.json +36 -0
- package/typedoc.json +10 -0
- package/webpack.config.js +15 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// Copyright (c) 2018-2020, The TurtleCoin Developers
|
|
2
|
+
//
|
|
3
|
+
// Please see the included LICENSE file for more information.
|
|
4
|
+
|
|
5
|
+
import {Reader, Writer} from 'bytestream-helper';
|
|
6
|
+
import {LevinPayloads} from './Types/LevinPayloads';
|
|
7
|
+
/** @ignore */
|
|
8
|
+
import LevinPayload = LevinPayloads.LevinPayload;
|
|
9
|
+
/** @ignore */
|
|
10
|
+
import Handshake = LevinPayloads.Handshake;
|
|
11
|
+
/** @ignore */
|
|
12
|
+
import TimedSync = LevinPayloads.TimedSync;
|
|
13
|
+
/** @ignore */
|
|
14
|
+
import Ping = LevinPayloads.Ping;
|
|
15
|
+
/** @ignore */
|
|
16
|
+
import NewBlock = LevinPayloads.NewBlock;
|
|
17
|
+
/** @ignore */
|
|
18
|
+
import NewTransactions = LevinPayloads.NewTransactions;
|
|
19
|
+
/** @ignore */
|
|
20
|
+
import RequestGetObjects = LevinPayloads.RequestGetObjects;
|
|
21
|
+
/** @ignore */
|
|
22
|
+
import ResponseGetObjects = LevinPayloads.ResponseGetObjects;
|
|
23
|
+
/** @ignore */
|
|
24
|
+
import RequestChain = LevinPayloads.RequestChain;
|
|
25
|
+
/** @ignore */
|
|
26
|
+
import ResponseChain = LevinPayloads.ResponseChain;
|
|
27
|
+
/** @ignore */
|
|
28
|
+
import RequestTXPool = LevinPayloads.RequestTXPool;
|
|
29
|
+
/** @ignore */
|
|
30
|
+
import LiteBlock = LevinPayloads.LiteBlock;
|
|
31
|
+
/** @ignore */
|
|
32
|
+
import MissingTransactions = LevinPayloads.MissingTransactions;
|
|
33
|
+
/** @ignore */
|
|
34
|
+
import ILevinPayload = LevinPayloads.ILevinPayload;
|
|
35
|
+
|
|
36
|
+
/** @ignore */
|
|
37
|
+
const LevinPacketSignature = '0101010101012101';
|
|
38
|
+
|
|
39
|
+
export namespace LevinProtocol {
|
|
40
|
+
/**
|
|
41
|
+
* Describes each of the Levin Packet Command Types
|
|
42
|
+
*/
|
|
43
|
+
export enum CommandType {
|
|
44
|
+
HANDSHAKE = 1001,
|
|
45
|
+
TIMEDSYNC = 1002,
|
|
46
|
+
PING = 1003,
|
|
47
|
+
NEW_BLOCK = 2001,
|
|
48
|
+
NEW_TRANSACTIONS = 2002,
|
|
49
|
+
REQUEST_GET_OBJECTS = 2003,
|
|
50
|
+
RESPONSE_GET_OBJECTS = 2004,
|
|
51
|
+
RESERVED = 2005,
|
|
52
|
+
REQUEST_CHAIN = 2006,
|
|
53
|
+
RESPONSE_CHAIN_ENTRY = 2007,
|
|
54
|
+
REQUEST_TX_POOL = 2008,
|
|
55
|
+
LITE_BLOCK = 2009,
|
|
56
|
+
MISSING_TRANSACTIONS = 2010,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Provides a representation of a Levin Packet on a network
|
|
62
|
+
*/
|
|
63
|
+
export class LevinPacket {
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The packet signature
|
|
67
|
+
*/
|
|
68
|
+
public get signature(): string {
|
|
69
|
+
return this.m_signature;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public set signature(value: string) {
|
|
73
|
+
const reader = new Reader(value);
|
|
74
|
+
|
|
75
|
+
if (reader.length !== 8) {
|
|
76
|
+
throw new RangeError('Signature is not the correct number of bytes');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.m_signature = reader.hex(8);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Whether or not we expect a response to this request
|
|
84
|
+
*/
|
|
85
|
+
public get return_data(): boolean {
|
|
86
|
+
return this.m_return_data;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public set return_data(value: boolean) {
|
|
90
|
+
this.m_return_data = value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The Levin Packet Command type
|
|
95
|
+
*/
|
|
96
|
+
public get command(): LevinProtocol.CommandType {
|
|
97
|
+
return this.m_command;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public set command(command: LevinProtocol.CommandType) {
|
|
101
|
+
if (this.m_command !== command) {
|
|
102
|
+
switch (command) {
|
|
103
|
+
case LevinProtocol.CommandType.HANDSHAKE:
|
|
104
|
+
this.payload = new Handshake();
|
|
105
|
+
break;
|
|
106
|
+
case LevinProtocol.CommandType.TIMEDSYNC:
|
|
107
|
+
this.payload = new TimedSync();
|
|
108
|
+
break;
|
|
109
|
+
case LevinProtocol.CommandType.PING:
|
|
110
|
+
this.payload = new Ping();
|
|
111
|
+
break;
|
|
112
|
+
case LevinProtocol.CommandType.NEW_BLOCK:
|
|
113
|
+
this.payload = new NewBlock();
|
|
114
|
+
break;
|
|
115
|
+
case LevinProtocol.CommandType.NEW_TRANSACTIONS:
|
|
116
|
+
this.payload = new NewTransactions();
|
|
117
|
+
break;
|
|
118
|
+
case LevinProtocol.CommandType.REQUEST_GET_OBJECTS:
|
|
119
|
+
this.payload = new RequestGetObjects();
|
|
120
|
+
break;
|
|
121
|
+
case LevinProtocol.CommandType.RESPONSE_GET_OBJECTS:
|
|
122
|
+
this.payload = new ResponseGetObjects();
|
|
123
|
+
break;
|
|
124
|
+
case LevinProtocol.CommandType.REQUEST_CHAIN:
|
|
125
|
+
this.payload = new RequestChain();
|
|
126
|
+
break;
|
|
127
|
+
case LevinProtocol.CommandType.RESPONSE_CHAIN_ENTRY:
|
|
128
|
+
this.payload = new ResponseChain();
|
|
129
|
+
break;
|
|
130
|
+
case LevinProtocol.CommandType.REQUEST_TX_POOL:
|
|
131
|
+
this.payload = new RequestTXPool();
|
|
132
|
+
break;
|
|
133
|
+
case LevinProtocol.CommandType.LITE_BLOCK:
|
|
134
|
+
this.payload = new LiteBlock();
|
|
135
|
+
break;
|
|
136
|
+
case LevinProtocol.CommandType.MISSING_TRANSACTIONS:
|
|
137
|
+
this.payload = new MissingTransactions();
|
|
138
|
+
break;
|
|
139
|
+
case LevinProtocol.CommandType.RESERVED:
|
|
140
|
+
default:
|
|
141
|
+
throw new Error('Unknown command type: ' + command);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.m_command = command;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The response return code
|
|
150
|
+
*/
|
|
151
|
+
public get return_code(): number {
|
|
152
|
+
return this.m_return_code;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public set return_code(value: number) {
|
|
156
|
+
this.m_return_code = value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The response flags
|
|
161
|
+
*/
|
|
162
|
+
public get flags(): number {
|
|
163
|
+
return this.m_flags;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public set flags(value: number) {
|
|
167
|
+
this.m_flags = value;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The packet version
|
|
172
|
+
*/
|
|
173
|
+
public get version(): number {
|
|
174
|
+
return this.m_protocol_version;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public set version(value: number) {
|
|
178
|
+
this.m_protocol_version = value;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The packet payload - See the Levin Payloads list
|
|
183
|
+
*/
|
|
184
|
+
public get payload(): ILevinPayload {
|
|
185
|
+
return this.m_payload;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public set payload(payload: ILevinPayload) {
|
|
189
|
+
this.m_payload = payload;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Creates a new instance of a Levin Packet from the supplied data
|
|
194
|
+
* @param data the raw data that came in over the wire
|
|
195
|
+
* @returns a new instance of the object
|
|
196
|
+
*/
|
|
197
|
+
public static from(data: Reader | Buffer | string): LevinPacket {
|
|
198
|
+
const reader = new Reader(data);
|
|
199
|
+
|
|
200
|
+
if (reader.length < 33) {
|
|
201
|
+
throw new RangeError('Invalid input stream supplied');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const result = new LevinPacket();
|
|
205
|
+
|
|
206
|
+
result.signature = reader.bytes(8).swap64().toString('hex');
|
|
207
|
+
|
|
208
|
+
if (result.signature !== LevinPacketSignature) {
|
|
209
|
+
throw new Error('Invalid Levin Packet Signature');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const bodyLength = reader.uint64_t().toJSNumber();
|
|
213
|
+
|
|
214
|
+
result.return_data = (reader.uint8_t().toJSNumber() === 1);
|
|
215
|
+
|
|
216
|
+
result.command = reader.uint32_t().toJSNumber();
|
|
217
|
+
|
|
218
|
+
result.return_code = reader.uint32_t().toJSNumber();
|
|
219
|
+
|
|
220
|
+
result.flags = reader.int32_t().toJSNumber();
|
|
221
|
+
|
|
222
|
+
result.version = reader.uint32_t().toJSNumber();
|
|
223
|
+
|
|
224
|
+
const payload = reader.bytes(bodyLength);
|
|
225
|
+
|
|
226
|
+
switch (result.command) {
|
|
227
|
+
case LevinProtocol.CommandType.HANDSHAKE:
|
|
228
|
+
result.payload = Handshake.from(payload);
|
|
229
|
+
break;
|
|
230
|
+
case LevinProtocol.CommandType.TIMEDSYNC:
|
|
231
|
+
result.payload = TimedSync.from(payload);
|
|
232
|
+
break;
|
|
233
|
+
case LevinProtocol.CommandType.PING:
|
|
234
|
+
result.payload = Ping.from(payload);
|
|
235
|
+
break;
|
|
236
|
+
case LevinProtocol.CommandType.NEW_BLOCK:
|
|
237
|
+
result.payload = NewBlock.from(payload);
|
|
238
|
+
break;
|
|
239
|
+
case LevinProtocol.CommandType.NEW_TRANSACTIONS:
|
|
240
|
+
result.payload = NewTransactions.from(payload);
|
|
241
|
+
break;
|
|
242
|
+
case LevinProtocol.CommandType.REQUEST_GET_OBJECTS:
|
|
243
|
+
result.payload = RequestGetObjects.from(payload);
|
|
244
|
+
break;
|
|
245
|
+
case LevinProtocol.CommandType.RESPONSE_GET_OBJECTS:
|
|
246
|
+
result.payload = ResponseGetObjects.from(payload);
|
|
247
|
+
break;
|
|
248
|
+
case LevinProtocol.CommandType.REQUEST_CHAIN:
|
|
249
|
+
result.payload = RequestChain.from(payload);
|
|
250
|
+
break;
|
|
251
|
+
case LevinProtocol.CommandType.RESPONSE_CHAIN_ENTRY:
|
|
252
|
+
result.payload = ResponseChain.from(payload);
|
|
253
|
+
break;
|
|
254
|
+
case LevinProtocol.CommandType.REQUEST_TX_POOL:
|
|
255
|
+
result.payload = RequestTXPool.from(payload);
|
|
256
|
+
break;
|
|
257
|
+
case LevinProtocol.CommandType.LITE_BLOCK:
|
|
258
|
+
result.payload = LiteBlock.from(payload);
|
|
259
|
+
break;
|
|
260
|
+
case LevinProtocol.CommandType.MISSING_TRANSACTIONS:
|
|
261
|
+
result.payload = MissingTransactions.from(payload);
|
|
262
|
+
break;
|
|
263
|
+
case LevinProtocol.CommandType.RESERVED:
|
|
264
|
+
default:
|
|
265
|
+
throw new Error('Unknown command type: ' + result.command);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private m_signature: string = LevinPacketSignature;
|
|
272
|
+
private m_return_data: boolean = false;
|
|
273
|
+
private m_command: LevinProtocol.CommandType = 0;
|
|
274
|
+
private m_return_code: number = 0;
|
|
275
|
+
private m_flags: number = 0;
|
|
276
|
+
private m_protocol_version: number = 1;
|
|
277
|
+
private m_payload: ILevinPayload = new LevinPayload();
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Creates a new instance of a Levin packet of the given command type
|
|
281
|
+
* @param [command] the command type that the packet will be for
|
|
282
|
+
*/
|
|
283
|
+
constructor(command?: LevinProtocol.CommandType) {
|
|
284
|
+
if (command) {
|
|
285
|
+
switch (command) {
|
|
286
|
+
case LevinProtocol.CommandType.HANDSHAKE:
|
|
287
|
+
this.payload = new Handshake();
|
|
288
|
+
break;
|
|
289
|
+
case LevinProtocol.CommandType.TIMEDSYNC:
|
|
290
|
+
this.payload = new TimedSync();
|
|
291
|
+
break;
|
|
292
|
+
case LevinProtocol.CommandType.PING:
|
|
293
|
+
this.payload = new Ping();
|
|
294
|
+
break;
|
|
295
|
+
case LevinProtocol.CommandType.NEW_BLOCK:
|
|
296
|
+
this.payload = new NewBlock();
|
|
297
|
+
break;
|
|
298
|
+
case LevinProtocol.CommandType.NEW_TRANSACTIONS:
|
|
299
|
+
this.payload = new NewTransactions();
|
|
300
|
+
break;
|
|
301
|
+
case LevinProtocol.CommandType.REQUEST_GET_OBJECTS:
|
|
302
|
+
this.payload = new RequestGetObjects();
|
|
303
|
+
break;
|
|
304
|
+
case LevinProtocol.CommandType.RESPONSE_GET_OBJECTS:
|
|
305
|
+
this.payload = new ResponseGetObjects();
|
|
306
|
+
break;
|
|
307
|
+
case LevinProtocol.CommandType.REQUEST_CHAIN:
|
|
308
|
+
this.payload = new RequestChain();
|
|
309
|
+
break;
|
|
310
|
+
case LevinProtocol.CommandType.RESPONSE_CHAIN_ENTRY:
|
|
311
|
+
this.payload = new ResponseChain();
|
|
312
|
+
break;
|
|
313
|
+
case LevinProtocol.CommandType.REQUEST_TX_POOL:
|
|
314
|
+
this.payload = new RequestTXPool();
|
|
315
|
+
break;
|
|
316
|
+
case LevinProtocol.CommandType.LITE_BLOCK:
|
|
317
|
+
this.payload = new LiteBlock();
|
|
318
|
+
break;
|
|
319
|
+
case LevinProtocol.CommandType.MISSING_TRANSACTIONS:
|
|
320
|
+
this.payload = new MissingTransactions();
|
|
321
|
+
break;
|
|
322
|
+
case LevinProtocol.CommandType.RESERVED:
|
|
323
|
+
default:
|
|
324
|
+
throw new Error('Unknown command type: ' + command);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
this.command = command;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Provides the Buffer representation of the Levin Packet
|
|
333
|
+
* @returns the buffer representation of the object
|
|
334
|
+
*/
|
|
335
|
+
public toBuffer(): Buffer {
|
|
336
|
+
const writer = new Writer();
|
|
337
|
+
|
|
338
|
+
writer.write(Buffer.from(this.signature, 'hex').swap64());
|
|
339
|
+
|
|
340
|
+
const payload = this.payload.toBuffer();
|
|
341
|
+
|
|
342
|
+
writer.uint64_t(payload.length);
|
|
343
|
+
|
|
344
|
+
writer.uint8_t((this.return_data) ? 1 : 0);
|
|
345
|
+
|
|
346
|
+
writer.uint32_t(this.command);
|
|
347
|
+
|
|
348
|
+
writer.int32_t(this.return_code);
|
|
349
|
+
|
|
350
|
+
writer.uint32_t(this.flags);
|
|
351
|
+
|
|
352
|
+
writer.uint32_t(this.version);
|
|
353
|
+
|
|
354
|
+
writer.write(payload);
|
|
355
|
+
|
|
356
|
+
return writer.buffer;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Provides the hexadecimal (blob) representation of the Levin Packet
|
|
361
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
362
|
+
*/
|
|
363
|
+
public toString(): string {
|
|
364
|
+
return this.toBuffer().toString('hex');
|
|
365
|
+
}
|
|
366
|
+
}
|