@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,230 @@
|
|
|
1
|
+
// Copyright (c) 2018-2020, The TurtleCoin Developers
|
|
2
|
+
//
|
|
3
|
+
// Please see the included LICENSE file for more information.
|
|
4
|
+
|
|
5
|
+
import {Transaction} from '../Transaction';
|
|
6
|
+
import {Address} from '../Address';
|
|
7
|
+
import {ED25519} from './ED25519';
|
|
8
|
+
|
|
9
|
+
export namespace Interfaces {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a transaction recipient
|
|
13
|
+
*/
|
|
14
|
+
export interface TransactionRecipient {
|
|
15
|
+
/**
|
|
16
|
+
* The recipient public wallet address
|
|
17
|
+
*/
|
|
18
|
+
address: string;
|
|
19
|
+
/**
|
|
20
|
+
* The amount sent to the recipient
|
|
21
|
+
*/
|
|
22
|
+
amount: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Represents a prepared transaction
|
|
27
|
+
*/
|
|
28
|
+
export interface PreparedTransaction {
|
|
29
|
+
/**
|
|
30
|
+
* The prepared transaction as a hexadecimal string (blob) -- this should be the prefix only (no signatures)
|
|
31
|
+
*/
|
|
32
|
+
transaction: Transaction;
|
|
33
|
+
/**
|
|
34
|
+
* The transaction one-time private key.
|
|
35
|
+
* We need this value along with the list of addresses that funds are being sent to
|
|
36
|
+
* to ensure that funds are going where we believe the funds are going.
|
|
37
|
+
*/
|
|
38
|
+
transactionPrivateKey: string;
|
|
39
|
+
/**
|
|
40
|
+
* The list of recipient addresses where funds are being sent to in the transaction.
|
|
41
|
+
* This is provided so that other participants can check the outputs to determine what
|
|
42
|
+
* amounts are going to which addresses so that they can verify that funds are going
|
|
43
|
+
* where they believe them to be going.
|
|
44
|
+
*/
|
|
45
|
+
transactionRecipients: TransactionRecipient[];
|
|
46
|
+
/**
|
|
47
|
+
* The list of prepared ring signatures (incomplete) that are later used
|
|
48
|
+
* when we generate our partial signing key for the prepared transaction
|
|
49
|
+
*/
|
|
50
|
+
signatureMeta: PreparedRingSignature[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Represents a prepared ring signature for a given input of a prepared transaction
|
|
55
|
+
*/
|
|
56
|
+
export interface PreparedRingSignature {
|
|
57
|
+
/**
|
|
58
|
+
* The index of the input in the transaction in which these prepared ring signatures belong
|
|
59
|
+
*/
|
|
60
|
+
index: number;
|
|
61
|
+
/**
|
|
62
|
+
* The index in the list of prepared ring signatures that is our real input.
|
|
63
|
+
* Although this can sometimes be deduced based on the last 32-bytes being all 0s,
|
|
64
|
+
* it is safer to make sure that this value is transferred with the prepared
|
|
65
|
+
* ring signatures
|
|
66
|
+
*/
|
|
67
|
+
realOutputIndex: number;
|
|
68
|
+
/**
|
|
69
|
+
* The randomly generated scalar value that was created in preparing the ring signatures
|
|
70
|
+
* This value is required for when we restore the ring signatures will all of the required
|
|
71
|
+
* partial signing keys.
|
|
72
|
+
*/
|
|
73
|
+
key: string;
|
|
74
|
+
/**
|
|
75
|
+
* The prepared ring signatures
|
|
76
|
+
*/
|
|
77
|
+
signatures?: string[];
|
|
78
|
+
/**
|
|
79
|
+
* The public keys used in the signature preparation (random + real)
|
|
80
|
+
*/
|
|
81
|
+
inputKeys?: string[];
|
|
82
|
+
/**
|
|
83
|
+
* The output information used to create this input
|
|
84
|
+
*/
|
|
85
|
+
input: {
|
|
86
|
+
derivation: string;
|
|
87
|
+
outputIndex: number;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Represents a Generated Output (destination)
|
|
93
|
+
*/
|
|
94
|
+
export interface GeneratedOutput {
|
|
95
|
+
/**
|
|
96
|
+
* The amount of the output
|
|
97
|
+
*/
|
|
98
|
+
amount: number;
|
|
99
|
+
/**
|
|
100
|
+
* The destination of the output
|
|
101
|
+
*/
|
|
102
|
+
destination: Address;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Represents a transaction output to external applications
|
|
107
|
+
*/
|
|
108
|
+
export interface Output {
|
|
109
|
+
/**
|
|
110
|
+
* The output key
|
|
111
|
+
*/
|
|
112
|
+
key: string;
|
|
113
|
+
/**
|
|
114
|
+
* The output index (position) in the transaction
|
|
115
|
+
*/
|
|
116
|
+
index: number;
|
|
117
|
+
/**
|
|
118
|
+
* The output global index
|
|
119
|
+
*/
|
|
120
|
+
globalIndex: number;
|
|
121
|
+
/**
|
|
122
|
+
* The output amount
|
|
123
|
+
*/
|
|
124
|
+
amount: number;
|
|
125
|
+
/**
|
|
126
|
+
* The output type
|
|
127
|
+
*/
|
|
128
|
+
type?: number;
|
|
129
|
+
/**
|
|
130
|
+
* The output key image
|
|
131
|
+
*/
|
|
132
|
+
keyImage?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The GeneratedInput of the output (if it belongs to us)
|
|
135
|
+
*/
|
|
136
|
+
input?: GeneratedInput;
|
|
137
|
+
/**
|
|
138
|
+
* Defines whether this is a partial key image
|
|
139
|
+
*/
|
|
140
|
+
isPartialKeyImage?: boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Represents a random output
|
|
145
|
+
*/
|
|
146
|
+
export interface RandomOutput {
|
|
147
|
+
/**
|
|
148
|
+
* The output key
|
|
149
|
+
*/
|
|
150
|
+
key: string;
|
|
151
|
+
/**
|
|
152
|
+
* The output global index
|
|
153
|
+
*/
|
|
154
|
+
globalIndex: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Represents a generated input if the output belongs to us
|
|
159
|
+
*/
|
|
160
|
+
export interface GeneratedInput {
|
|
161
|
+
/**
|
|
162
|
+
* The derived transaction keys
|
|
163
|
+
*/
|
|
164
|
+
transactionKeys: InputKeys;
|
|
165
|
+
/**
|
|
166
|
+
* The public ephemeral of the input
|
|
167
|
+
*/
|
|
168
|
+
publicEphemeral: string;
|
|
169
|
+
/**
|
|
170
|
+
* the private ephemeral of the input
|
|
171
|
+
*/
|
|
172
|
+
privateEphemeral?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The derived input transaction keys
|
|
177
|
+
*/
|
|
178
|
+
export interface InputKeys {
|
|
179
|
+
/**
|
|
180
|
+
* The derived public key
|
|
181
|
+
*/
|
|
182
|
+
publicKey: string;
|
|
183
|
+
/**
|
|
184
|
+
* The key derivation
|
|
185
|
+
*/
|
|
186
|
+
derivedKey: string;
|
|
187
|
+
/**
|
|
188
|
+
* The output index
|
|
189
|
+
*/
|
|
190
|
+
outputIndex: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** @ignore */
|
|
194
|
+
export interface PreparedInput {
|
|
195
|
+
amount: number;
|
|
196
|
+
realOutputIndex: number;
|
|
197
|
+
keyImage: string;
|
|
198
|
+
input: GeneratedInput;
|
|
199
|
+
outputs: PreparedInputOutputs[];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** @ignore */
|
|
203
|
+
export interface PreparedInputOutputs {
|
|
204
|
+
key: string;
|
|
205
|
+
index: number;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @ignore */
|
|
209
|
+
export interface PreparedOutput {
|
|
210
|
+
amount: number;
|
|
211
|
+
key: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** @ignore */
|
|
215
|
+
export interface PreparedOutputs {
|
|
216
|
+
transactionKeys: ED25519.KeyPair;
|
|
217
|
+
outputs: PreparedOutput[];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** @ignore */
|
|
221
|
+
export interface GeneratedRingSignatures {
|
|
222
|
+
signatures: string[];
|
|
223
|
+
index: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface IPreparedTransaction {
|
|
227
|
+
transaction: Transaction;
|
|
228
|
+
inputs: PreparedInput[];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Copyright (c) 2018-2020, The TurtleCoin Developers
|
|
2
|
+
//
|
|
3
|
+
// Please see the included LICENSE file for more information.
|
|
4
|
+
|
|
5
|
+
/** @ignore */
|
|
6
|
+
import {Writer} from 'bytestream-helper';
|
|
7
|
+
import {BigInteger} from '../Types';
|
|
8
|
+
|
|
9
|
+
export namespace TransactionInputs {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transaction Input Types
|
|
13
|
+
*/
|
|
14
|
+
export enum InputType {
|
|
15
|
+
KEY = 0x02,
|
|
16
|
+
COINBASE = 0xff,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Abstract interface for structured transaction inputs
|
|
21
|
+
*/
|
|
22
|
+
export abstract class ITransactionInput {
|
|
23
|
+
/**
|
|
24
|
+
* The input type
|
|
25
|
+
*/
|
|
26
|
+
public abstract get type(): InputType;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the input as a buffer
|
|
30
|
+
* @returns the Buffer representation of the object
|
|
31
|
+
*/
|
|
32
|
+
public abstract toBuffer(): Buffer;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns the input as a hexadecimal string (blob)
|
|
36
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
37
|
+
*/
|
|
38
|
+
public abstract toString(): string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents a Coinbase input (block reward)
|
|
43
|
+
*/
|
|
44
|
+
export class CoinbaseInput implements ITransactionInput {
|
|
45
|
+
private readonly m_type: InputType = InputType.COINBASE;
|
|
46
|
+
private readonly m_blockIndex: number = 0;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new Coinbase input for the specified block index (0-based)
|
|
50
|
+
* @param blockIndex
|
|
51
|
+
*/
|
|
52
|
+
constructor(blockIndex: number) {
|
|
53
|
+
this.m_blockIndex = blockIndex;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The input type
|
|
58
|
+
*/
|
|
59
|
+
public get type(): InputType {
|
|
60
|
+
return this.m_type;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The block index of the input (0-based)
|
|
65
|
+
*/
|
|
66
|
+
public get blockIndex(): number {
|
|
67
|
+
return this.m_blockIndex;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Represents the input as a Buffer
|
|
72
|
+
* @returns the Buffer representation of the object
|
|
73
|
+
*/
|
|
74
|
+
public toBuffer(): Buffer {
|
|
75
|
+
const writer = new Writer();
|
|
76
|
+
|
|
77
|
+
writer.uint8_t(this.type);
|
|
78
|
+
|
|
79
|
+
writer.varint(this.blockIndex);
|
|
80
|
+
|
|
81
|
+
return writer.buffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents the input as a hexadecimal string (blob)
|
|
86
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
87
|
+
*/
|
|
88
|
+
public toString(): string {
|
|
89
|
+
return this.toBuffer().toString('hex');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Represents an input from a set of keys (wallet)
|
|
95
|
+
*/
|
|
96
|
+
export class KeyInput implements ITransactionInput {
|
|
97
|
+
|
|
98
|
+
private readonly m_type: InputType = InputType.KEY;
|
|
99
|
+
private readonly m_amount: BigInteger.BigInteger = BigInteger.zero;
|
|
100
|
+
private readonly m_keyOffsets: BigInteger.BigInteger[] = [];
|
|
101
|
+
private readonly m_keyImage: string = '';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new input from existing keys using the specified values
|
|
105
|
+
* @param amount the amount of the input
|
|
106
|
+
* @param keyOffsets the input offsets used in the transaction signature(s)
|
|
107
|
+
* @param keyImage the key image of the input
|
|
108
|
+
*/
|
|
109
|
+
constructor(
|
|
110
|
+
amount: BigInteger.BigInteger | number,
|
|
111
|
+
keyOffsets: BigInteger.BigInteger[] | number[],
|
|
112
|
+
keyImage: string) {
|
|
113
|
+
if (typeof amount === 'number') {
|
|
114
|
+
amount = BigInteger(amount);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.m_amount = amount;
|
|
118
|
+
|
|
119
|
+
const tmpKeyOffsets: BigInteger.BigInteger[] = [];
|
|
120
|
+
|
|
121
|
+
for (const index of keyOffsets) {
|
|
122
|
+
if (typeof index === 'number') {
|
|
123
|
+
tmpKeyOffsets.push(BigInteger(index));
|
|
124
|
+
} else {
|
|
125
|
+
tmpKeyOffsets.push(index);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.m_keyOffsets = tmpKeyOffsets;
|
|
130
|
+
|
|
131
|
+
this.m_keyImage = keyImage;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The input type
|
|
136
|
+
*/
|
|
137
|
+
public get type(): InputType {
|
|
138
|
+
return this.m_type;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The input amount
|
|
143
|
+
*/
|
|
144
|
+
public get amount(): BigInteger.BigInteger {
|
|
145
|
+
return this.m_amount;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The input offsets used in the transaction signature(s)
|
|
150
|
+
*/
|
|
151
|
+
public get keyOffsets(): BigInteger.BigInteger[] {
|
|
152
|
+
return this.m_keyOffsets;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The key image of the input
|
|
157
|
+
*/
|
|
158
|
+
public get keyImage(): string {
|
|
159
|
+
return this.m_keyImage;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Represents the input as a Buffer
|
|
164
|
+
* @returns the Buffer representation of the object
|
|
165
|
+
*/
|
|
166
|
+
public toBuffer(): Buffer {
|
|
167
|
+
const writer = new Writer();
|
|
168
|
+
|
|
169
|
+
writer.uint8_t(this.type);
|
|
170
|
+
writer.varint(this.amount);
|
|
171
|
+
writer.varint(this.keyOffsets.length);
|
|
172
|
+
|
|
173
|
+
for (const offset of this.keyOffsets) {
|
|
174
|
+
writer.varint(offset);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
writer.hash(this.keyImage);
|
|
178
|
+
|
|
179
|
+
return writer.buffer;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Represents the input as a hexadecimal string (blob)
|
|
184
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
185
|
+
*/
|
|
186
|
+
public toString(): string {
|
|
187
|
+
return this.toBuffer().toString('hex');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright (c) 2018-2020, The TurtleCoin Developers
|
|
2
|
+
//
|
|
3
|
+
// Please see the included LICENSE file for more information.
|
|
4
|
+
|
|
5
|
+
import {BigInteger} from '../Types';
|
|
6
|
+
import {Writer} from 'bytestream-helper';
|
|
7
|
+
|
|
8
|
+
export namespace TransactionOutputs {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transaction Output Type
|
|
12
|
+
*/
|
|
13
|
+
export enum OutputType {
|
|
14
|
+
KEY = 0x02,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Abstract interface for structured transaction outputs
|
|
19
|
+
*/
|
|
20
|
+
export abstract class ITransactionOutput {
|
|
21
|
+
/**
|
|
22
|
+
* The output type
|
|
23
|
+
*/
|
|
24
|
+
public abstract get type(): OutputType;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the output as a buffer
|
|
28
|
+
* @returns the Buffer representation of the object
|
|
29
|
+
*/
|
|
30
|
+
public abstract toBuffer(): Buffer;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the input as a hexadecimal string (blob)
|
|
34
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
35
|
+
*/
|
|
36
|
+
public abstract toString(): string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represents an output to a set of keys (wallet)
|
|
41
|
+
*/
|
|
42
|
+
export class KeyOutput implements ITransactionOutput {
|
|
43
|
+
|
|
44
|
+
private readonly m_type: OutputType = OutputType.KEY;
|
|
45
|
+
private readonly m_amount: BigInteger.BigInteger = BigInteger.zero;
|
|
46
|
+
private readonly m_key: string = '';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new key output using the specified values
|
|
50
|
+
* @param amount the output amount
|
|
51
|
+
* @param key the one-time output key of the output
|
|
52
|
+
*/
|
|
53
|
+
constructor(amount: BigInteger.BigInteger | number, key: string) {
|
|
54
|
+
if (typeof amount === 'number') {
|
|
55
|
+
amount = BigInteger(amount);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.m_amount = amount;
|
|
59
|
+
|
|
60
|
+
this.m_key = key;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The output type
|
|
65
|
+
*/
|
|
66
|
+
public get type(): OutputType {
|
|
67
|
+
return this.m_type;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The output amount
|
|
72
|
+
*/
|
|
73
|
+
public get amount(): BigInteger.BigInteger {
|
|
74
|
+
return this.m_amount;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The one-time output key of the output
|
|
79
|
+
*/
|
|
80
|
+
public get key(): string {
|
|
81
|
+
return this.m_key;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents the output as a Buffer
|
|
86
|
+
* @returns the Buffer representation of the object
|
|
87
|
+
*/
|
|
88
|
+
public toBuffer(): Buffer {
|
|
89
|
+
const writer = new Writer();
|
|
90
|
+
|
|
91
|
+
writer.varint(this.amount);
|
|
92
|
+
|
|
93
|
+
writer.uint8_t(this.type);
|
|
94
|
+
|
|
95
|
+
writer.hash(this.key);
|
|
96
|
+
|
|
97
|
+
return writer.buffer;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Represents the output as a hexadecimal string (blob)
|
|
102
|
+
* @returns the hexadecimal (blob) representation of the object
|
|
103
|
+
*/
|
|
104
|
+
public toString(): string {
|
|
105
|
+
return this.toBuffer().toString('hex');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|