@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,187 @@
|
|
|
1
|
+
// Copyright (c) 2018-2020, The TurtleCoin Developers
|
|
2
|
+
//
|
|
3
|
+
// Please see the included LICENSE file for more information.
|
|
4
|
+
|
|
5
|
+
import {Common} from '../Common';
|
|
6
|
+
import {TurtleCoinCrypto} from '../Types';
|
|
7
|
+
import {Mnemonics} from 'turtlecoin-mnemonics';
|
|
8
|
+
|
|
9
|
+
/** @ignore */
|
|
10
|
+
const Config = require('../../config.json');
|
|
11
|
+
|
|
12
|
+
/** @ignore */
|
|
13
|
+
const SecureRandomString = require('secure-random-string');
|
|
14
|
+
|
|
15
|
+
export namespace ED25519 {
|
|
16
|
+
/**
|
|
17
|
+
* Represents a ED25519 Key Pair (private & public) and provides a few methods
|
|
18
|
+
* for generating new key pairs including deterministic methods.
|
|
19
|
+
*/
|
|
20
|
+
export class KeyPair {
|
|
21
|
+
private m_privateKey?: string;
|
|
22
|
+
private m_publicKey?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Constructs a new KeyPair object
|
|
26
|
+
* @param publicKey
|
|
27
|
+
* @param privateKey
|
|
28
|
+
* @param entropy
|
|
29
|
+
* @param iterations
|
|
30
|
+
*/
|
|
31
|
+
constructor(publicKey?: string, privateKey?: string, entropy?: string, iterations?: number) {
|
|
32
|
+
if (!publicKey && !privateKey && !entropy && !iterations) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (publicKey && TurtleCoinCrypto.checkKey(publicKey)) {
|
|
37
|
+
this.m_publicKey = publicKey;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (privateKey && TurtleCoinCrypto.checkScalar(privateKey)) {
|
|
41
|
+
this.m_privateKey = privateKey;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!publicKey && !privateKey) {
|
|
45
|
+
/* If no entropy was supplied, we'll go find our own */
|
|
46
|
+
entropy = entropy || SecureRandomString({length: 256});
|
|
47
|
+
|
|
48
|
+
this.privateKey = simpleKdf(
|
|
49
|
+
entropy + rand32(), iterations || Config.keccakIterations);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (this.m_privateKey && !this.m_publicKey) {
|
|
53
|
+
/* If we supplied a private key but no public key, and we said 1 iteration
|
|
54
|
+
we are probably looking to generate the deterministic view key for the
|
|
55
|
+
specified private spend key */
|
|
56
|
+
if (iterations && iterations === 1) {
|
|
57
|
+
this.privateKey = TurtleCoinCrypto.cn_fast_hash(this.m_privateKey);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.m_publicKey = TurtleCoinCrypto.secretKeyToPublicKey(this.m_privateKey);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns the private key
|
|
66
|
+
*/
|
|
67
|
+
public get privateKey(): string {
|
|
68
|
+
return (this.m_privateKey) ? this.m_privateKey : '';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets the private key or reduces the value to a private key
|
|
73
|
+
* @param key
|
|
74
|
+
*/
|
|
75
|
+
public set privateKey(key: string) {
|
|
76
|
+
this.m_privateKey = (TurtleCoinCrypto.checkScalar(key)) ?
|
|
77
|
+
key : TurtleCoinCrypto.scReduce32(key);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the public key
|
|
82
|
+
*/
|
|
83
|
+
public get publicKey(): string {
|
|
84
|
+
return (this.m_publicKey) ? this.m_publicKey : '';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sets the public key
|
|
89
|
+
* @param key
|
|
90
|
+
*/
|
|
91
|
+
public set publicKey(key: string) {
|
|
92
|
+
if (TurtleCoinCrypto.checkKey(key)) {
|
|
93
|
+
this.m_publicKey = key;
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error('Not a public key');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns if the public key belongs to the private key
|
|
101
|
+
*/
|
|
102
|
+
public get isPaired(): boolean {
|
|
103
|
+
if (this.publicKey.length === 0 || this.privateKey.length === 0) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (TurtleCoinCrypto.secretKeyToPublicKey(this.privateKey) === this.publicKey);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Represents a set of ED25519 key pairs (view and spend) used by TurtleCoin wallets
|
|
113
|
+
*/
|
|
114
|
+
export class Keys {
|
|
115
|
+
private m_spendKeys: KeyPair = new KeyPair();
|
|
116
|
+
private m_viewKeys: KeyPair = new KeyPair();
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new instance of a set of Keys
|
|
120
|
+
* @param spendKeys the spend key pair
|
|
121
|
+
* @param viewKeys the view key pair
|
|
122
|
+
*/
|
|
123
|
+
constructor(spendKeys?: KeyPair, viewKeys?: KeyPair) {
|
|
124
|
+
if (spendKeys) {
|
|
125
|
+
this.m_spendKeys = spendKeys;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (viewKeys) {
|
|
129
|
+
this.m_viewKeys = viewKeys;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!spendKeys && !viewKeys) {
|
|
133
|
+
this.m_spendKeys = new KeyPair();
|
|
134
|
+
this.m_viewKeys = new KeyPair(undefined, this.m_spendKeys.privateKey, undefined, 1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns the spend keys
|
|
140
|
+
*/
|
|
141
|
+
public get spend(): KeyPair {
|
|
142
|
+
return this.m_spendKeys;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Sets the spend keys
|
|
147
|
+
* @param keys
|
|
148
|
+
*/
|
|
149
|
+
public set spend(keys: KeyPair) {
|
|
150
|
+
this.m_spendKeys = keys;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns the view keys
|
|
155
|
+
*/
|
|
156
|
+
public get view(): KeyPair {
|
|
157
|
+
return this.m_viewKeys;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Sets the view keys
|
|
162
|
+
* @param keys
|
|
163
|
+
*/
|
|
164
|
+
public set view(keys: KeyPair) {
|
|
165
|
+
this.m_viewKeys = keys;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** @ignore */
|
|
171
|
+
function rand32(): string {
|
|
172
|
+
try {
|
|
173
|
+
return Mnemonics.random(256);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw new Error('Could not retrieve 32-bytes of random data: ' + error.toString());
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** @ignore */
|
|
180
|
+
function simpleKdf(value: string, iterations: number): string {
|
|
181
|
+
/** This is a very simple implementation of a pseudo PBKDF2 function */
|
|
182
|
+
let hex = Common.bin2hex(Common.str2bin(value));
|
|
183
|
+
for (let i = 0; i < iterations; i++) {
|
|
184
|
+
hex = TurtleCoinCrypto.cn_fast_hash(hex);
|
|
185
|
+
}
|
|
186
|
+
return hex;
|
|
187
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
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 {Common} from '../Common';
|
|
7
|
+
|
|
8
|
+
/** @ignore */
|
|
9
|
+
enum SIZES {
|
|
10
|
+
KEY = 32,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export namespace ExtraNonceTag {
|
|
14
|
+
/**
|
|
15
|
+
* Nonce subtag types
|
|
16
|
+
*/
|
|
17
|
+
export enum NonceTagType {
|
|
18
|
+
PAYMENT_ID = 0,
|
|
19
|
+
EXTRA_DATA = 127,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Abstract interface for structured Extra Nonce Field Values
|
|
24
|
+
*/
|
|
25
|
+
export abstract class IExtraNonce {
|
|
26
|
+
/**
|
|
27
|
+
* Returns the size of the nonce field in bytes including it's tag
|
|
28
|
+
*/
|
|
29
|
+
abstract get size(): number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the Extra Nonce Field tag
|
|
33
|
+
*/
|
|
34
|
+
abstract get tag(): NonceTagType;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns the Extra Nonce as a Buffer
|
|
38
|
+
* @returns the Buffer representation of the object
|
|
39
|
+
*/
|
|
40
|
+
public abstract toBuffer(): Buffer;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the Extra Nonce as a hexadecimal string (blob)
|
|
44
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
45
|
+
*/
|
|
46
|
+
public abstract toString(): string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Represents arbitrary extra data included in the nonce by the user
|
|
51
|
+
*/
|
|
52
|
+
export class ExtraNonceData implements IExtraNonce {
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The tag type of the field
|
|
56
|
+
*/
|
|
57
|
+
public get tag(): NonceTagType {
|
|
58
|
+
return this.m_tag;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The size of the field in bytes including the tag
|
|
63
|
+
*/
|
|
64
|
+
public get size(): number {
|
|
65
|
+
return this.toBuffer().length;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The arbitrary data included in the field
|
|
70
|
+
*/
|
|
71
|
+
public get data(): Buffer {
|
|
72
|
+
return this.m_data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new instance of the field using a Buffer or Blob copy of
|
|
77
|
+
* field created through other means
|
|
78
|
+
* @param data the data that makes up the nonce field
|
|
79
|
+
* @returns the new object
|
|
80
|
+
*/
|
|
81
|
+
public static from(data: Buffer | string): ExtraNonceData {
|
|
82
|
+
const reader = new Reader(data);
|
|
83
|
+
|
|
84
|
+
if (reader.varint().toJSNumber() !== NonceTagType.EXTRA_DATA) {
|
|
85
|
+
throw new Error('Not an extra data field');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
reader.varint(true);
|
|
90
|
+
} catch {
|
|
91
|
+
throw new Error('Cannot read required field data');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const length = reader.varint().toJSNumber();
|
|
95
|
+
|
|
96
|
+
if (reader.unreadBytes !== length) {
|
|
97
|
+
throw new RangeError('Not enough data available for reading');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const dataLength = reader.bytes(length);
|
|
101
|
+
|
|
102
|
+
return new ExtraNonceData(dataLength);
|
|
103
|
+
}
|
|
104
|
+
private readonly m_tag: NonceTagType = NonceTagType.EXTRA_DATA;
|
|
105
|
+
private readonly m_data: Buffer = Buffer.alloc(0);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a new instance of the field from just the extra data to be included
|
|
109
|
+
* @param data the arbitrary data to be included in the field
|
|
110
|
+
*/
|
|
111
|
+
constructor(data: Buffer) {
|
|
112
|
+
this.m_data = data;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Represents the field as a Buffer
|
|
117
|
+
* @returns the Buffer representation of the object
|
|
118
|
+
*/
|
|
119
|
+
public toBuffer(): Buffer {
|
|
120
|
+
const writer = new Writer();
|
|
121
|
+
|
|
122
|
+
writer.varint(this.tag);
|
|
123
|
+
|
|
124
|
+
writer.varint(this.data.length);
|
|
125
|
+
|
|
126
|
+
writer.write(this.data);
|
|
127
|
+
|
|
128
|
+
return writer.buffer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Represents the field as a hexadecimal string (blob)
|
|
133
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
134
|
+
*/
|
|
135
|
+
public toString(): string {
|
|
136
|
+
return this.toBuffer().toString('hex');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Represents a payment ID included in the Extra Nonce field
|
|
142
|
+
*/
|
|
143
|
+
export class ExtraNoncePaymentId implements IExtraNonce {
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The tag type of the field
|
|
147
|
+
*/
|
|
148
|
+
public get tag(): NonceTagType {
|
|
149
|
+
return this.m_tag;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The size of the field in bytes including the tag
|
|
154
|
+
*/
|
|
155
|
+
public get size(): number {
|
|
156
|
+
return this.toBuffer().length;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The payment ID contained in the field
|
|
161
|
+
*/
|
|
162
|
+
public get paymentId(): string {
|
|
163
|
+
return this.m_paymentId;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Creates a new instance of the field using a Buffer or Blob copy of
|
|
168
|
+
* field created through other means
|
|
169
|
+
* @param data the data that makes up the nonce field
|
|
170
|
+
* @returns the new object
|
|
171
|
+
*/
|
|
172
|
+
public static from(data: Buffer | string): ExtraNoncePaymentId {
|
|
173
|
+
const reader = new Reader(data);
|
|
174
|
+
|
|
175
|
+
if (reader.varint().toJSNumber() !== NonceTagType.PAYMENT_ID) {
|
|
176
|
+
throw new Error('Not a payment ID field');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (reader.unreadBytes !== SIZES.KEY) {
|
|
180
|
+
throw new RangeError('Not enough data available for reading');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const paymentId = reader.hash();
|
|
184
|
+
|
|
185
|
+
return new ExtraNoncePaymentId(paymentId);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private readonly m_tag: NonceTagType = NonceTagType.PAYMENT_ID;
|
|
189
|
+
private readonly m_paymentId: string = '';
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Constructs a new instance of the field using the supplied payment ID
|
|
193
|
+
* @param paymentId
|
|
194
|
+
*/
|
|
195
|
+
constructor(paymentId: string) {
|
|
196
|
+
if (!Common.isHex64(paymentId)) {
|
|
197
|
+
throw new Error('paymentId must be 64 hexadecimal characters');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.m_paymentId = paymentId;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Represents the field as a Buffer
|
|
205
|
+
* @returns the Buffer representation of the object
|
|
206
|
+
*/
|
|
207
|
+
public toBuffer(): Buffer {
|
|
208
|
+
const writer = new Writer();
|
|
209
|
+
|
|
210
|
+
writer.varint(this.tag);
|
|
211
|
+
|
|
212
|
+
writer.hash(this.paymentId);
|
|
213
|
+
|
|
214
|
+
return writer.buffer;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Represents the field as a hexadecimal string (blob)
|
|
219
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
220
|
+
*/
|
|
221
|
+
public toString(): string {
|
|
222
|
+
return this.toBuffer().toString('hex');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|