-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
537 lines (468 loc) · 15.5 KB
/
index.d.ts
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
// Copyright (c) 2018-2023, The Zent Cash Developers
//
// Please see the included LICENSE file for more information.
export class CryptoNote {
constructor(config?: CryptoNoteOptions);
/**
* Creates a new, random address seed.
*
* @param entropy Optional entropy to use, otherwise we will use our own.
* @param interations Amount of keccak iterations to use on our pseudo pbkdf2.
* Suggested to use a high amount if using poor entropy.
*/
public createNewSeed(
entropy?: string,
iterations?: number): string;
/**
* Creates a new, random, deterministic address.
*
* @param entropy Optional entropy to use, otherwise we will use our own.
* @param lang The language to encode the mnemonic in. Defaults to english.
* @param addressPrefix The address prefix in decimal.
*/
public createNewAddress(
entropy?: string,
lang?: string,
addressPrefix?: string): Address;
/**
* Creates an address from the given seed.
*
* @param seed The seed to create this address from.
* @param lang The language to encode the mnemonic in. Defaults to english.
* @param addressPrefix The address prefix in decimal.
*/
public createAddressFromSeed(
seed: string,
lang?: string,
addressPrefix?: string): Address;
/**
* Creates an address from the given mnemonic seed.
*
* @param mnemnoic A valid 25 word mnemonic.
* @param lang The language the mnemonic is encoded in. Defaults to english.
* @param addressPrefix The address prefix in decimal.
*/
public createAddressFromMnemonic(
mnemonic: string,
lang?: string,
addressPrefix?: string): Address;
/**
* Creates an address from the given spend and view keys.
*
* @param privateSpendKey A valid, 64 char hex key.
* @param privateViewKey A valid, 64 char hex key.
* @param addressPrefix The address prefix in decimal.
*/
public createAddressFromKeys(
privateSpendKey: string,
privateViewKey: string,
addressPrefix?: string): Address;
/**
* Decodes the address prefix from the given address into a number of formats.
*/
public decodeAddressPrefix(address: string): DecodedAddressPrefix;
/**
* Decodes the given address or integrated address into public keys, prefix, and payment ID.
*/
public decodeAddress(
address: string,
addressPrefix?: string): DecodedAddress;
/**
* Encodes the raw address data into a conventional address, using base58 encoding.
*/
public encodeRawAddress(rawAddress: string): string;
/**
* Creates a standard address from a public view and spend key, and an optional payment ID,
* for integrated addresses.
*/
public encodeAddress(
publicViewKey: string,
publicSpendKey: string,
paymentId?: string,
addressPrefix?: string): string;
/**
* Creates an integrated address from a standard address and a paymentID.
*/
public createIntegratedAddress(
address: string,
paymentId: string,
addressPrefix?: string): string;
/**
* Converts a private key to the corresponding public key.
*/
public privateKeyToPublicKey(privateKey: string): string;
/**
* Scans the given outputs, determining which of them belong to us.
*
* @param transactionPublicKey The public key stored in the tx_extra of this transaction
* @param outputs The outputs of this transaction
* @param privateViewKey The private view key of the wallet you wish to scan with
* @param publicSpendKey The public spend key of the wallet you wish to scan with
* @param privateSpendKey The private spend key of the wallet you wish to scan with.
* Optional. Required to aquire the necessary information for
* spending transactions.
*/
public scanTransactionOutputs(
transactionPublicKey: string,
outputs: OutputToScan[],
privateViewKey: string,
publicSpendKey: string,
privateSpendKey?: string): OurOutput[];
/**
* Scans a single transaction output to determine if it belongs to us.
*
* @param transactionPublicKey The public key stored in the tx_extra of this transaction
* @param output The output to scan
* @param privateViewKey The private view key of the wallet you wish to scan with
* @param privateSpendKey The private spend key of the wallet you wish to scan with.
* Optional. Required to aquire the neccessary information for
* spending transactions.
*
* @returns Returns false if the output is not ours.
* Returns the output with the input filled in, if the output is ours.
* If a private spend key is given, the `input.privateEphemeral` and `keyImage` properties
* will be filled in.
*/
public isOurTransactionOutput(
transactionPublicKey: string,
output: OutputToScan,
privateViewKey: string,
privateSpendKey?: string): OurOutput | boolean;
/**
* Generates a key image for the given transaction data.
*
* @param transactionPublicKey The public key stored in the tx_extra of this transaction
* @param privateViewKey The private view key of the wallet this transaction belongs to
* @param publicSpendKey The public spend key of the wallet this transaction belongs to
* @param privateSpendKey The private spend key of the wallet this transaction belongs to
* @param outputIndex The index of this output in the transaction (0 based indexing)
*
* @returns Returns the [keyImage, privateEphemeral]
*/
public generateKeyImage(
transactionPublicKey: string,
privateViewKey: string,
publicSpendKey: string,
privateSpendKey: string,
outputIndex: number): [string, string];
/**
* Generates a key image for the given transaction data, using a previously
* created derivation.
*
* @param publicSpendKey The public spend key of the wallet this transaction belongs to
* @param privateSpendKey The private spend key of the wallet this transaction belongs to
* @param outputIndex The index of this output in the transaction (0 based indexing)
* @param derivation The derivation of the private view key and the transaction public key
*
*
* @returns Returns the [keyImage, privateEphemeral]
*/
public generateKeyImagePrimitive(
publicSpendKey: string,
privateSpendKey: string,
outputIndex: number,
derivation: string): [string, string];
/**
* Creates a valid transaction to be submitted to the network for sending.
*/
public createTransaction(
newOutputs: TxDestination[],
ourOutputs: Output[],
randomOuts: RandomOutput[][],
mixin: number,
feeAmount: number,
paymentId?: string,
unlockTime?: number,
extra?: any): CreatedTransaction;
/**
* Creates a valid transaction to be submitted to the network for sending.
* Supports passed in user functions that are asynchronous.
*/
public createTransactionAsync(
newOutputs: TxDestination[],
ourOutputs: Output[],
randomOuts: RandomOutput[][],
mixin: number,
feeAmount: number,
paymentId?: string,
unlockTime?: number,
extra?: any): Promise<CreatedTransaction>;
/**
* Converts an amount in atomic units, to a human friendly representation.
*/
public formatMoney(amount: number): string;
/**
* Generates a key derivation from the transaction public key and the
* wallet private view key.
*/
public generateKeyDerivation(
transactionPublicKey: string,
privateViewKey: string): string;
/**
* Creates the corresponding public spend key of an output key, output index,
* and derivation. If the public spend key matches the users public spend key,
* the output belongs to them.
*/
public underivePublicKey(
derivation: string,
outputIndex: number,
outputKey: string): string;
/**
* Hashes the supplied data using the CN Fast Hash method
*/
public cnFastHash(data: string): string;
/**
* Creates a BlockTemplate object based upon the JSON object returned by aLinkcolor
* getBlockTemplate call to the daemon or blockchain cache
*/
public blockTemplate(data: string): BlockTemplate;
/**
* A method to convert absolute offsets to relative offsets
*/
public absoluteToRelativeOffsets(offsets: number[]): number[];
/**
* A method to convert relative offsets to absolute offsets
*/
public relativeToAbsoluteOffsets(offsets: number[]): number[];
/**
* A primitive method to generate the signature of a message
*/
public generateSignaturePrimitive(
hash: string,
publicKey: string,
privateKey: string): string;
/**
* A primitive method to verify the signature of a message
*/
public verifySignaturePrimitive(
hash: string,
publicKey: string,
signature: string): boolean;
/**
* A method to generate the signature of a message
*/
public signMessage(
message: any,
signerAddress: string,
privateSpendKey: string): string;
/**
* A method to verify the signature of a message
*/
public verifyMessageSignature(
message: any,
signerAddress: string,
signature: string): boolean;
/**
* A method to create a deterministic subwallet from
* a given private key.
*/
public createSubWalletFromPrivateSpendKey(
privateSpendKey: string,
subWalletIndex?: number,
lang?: string,
addressPrefix?: number
): Address;
}
export interface CryptoNoteOptions {
/**
* The amount of decimal places your coin has.
*/
coinUnitPlaces?: number;
/**
* The hex/decimal address prefix of your coin.
*/
addressPrefix?: number;
/**
* The amount of iterations to perform on pseudo pbkdf2.
*/
keccakIterations?: number;
/**
* The default fee to use on a transaction when not specified.
*/
defaultNetworkFee?: number;
/*
* The max output size in atomic units to create in transactions
*/
maximumOutputAmount?: number;
/**
* The major block number where merged mining was activated
*/
mmMiningBlockVersion?: number;
/**
* A replacement function for the JS/C++ underivePublicKey.
*/
underivePublicKey?: (derivation: string,
outputIndex: number,
outputKey: string) => string;
/**
* A replacement function for the JS/C++ derivePublicKey.
*/
derivePublicKey?: (derivation: string,
outputIndex: number,
publicKey: string) => string;
/**
* A replacement function for the JS/C++ deriveSecretKey.
*/
deriveSecretKey?: (derivation: string,
outputIndex: number,
privateKey: string) => string;
/**
* A replacement function for the JS/C++ generateKeyImage.
*/
generateKeyImage?: (transactionPublicKey: string,
privateViewKey: string,
publicSpendKey: string,
privateSpendKey: string,
outputIndex: number) => string;
/**
* A replacement function for the JS/C++ secretKeyToPublicKey.
*/
secretKeyToPublicKey?: (privateKey: string) => string;
/**
* A replacement function for the JS/C++ cnFastHash.
*/
cnFastHash?: (input: string) => string;
/**
* A replacement function for the JS/C++ generateRingSignatures.
*/
generateRingSignatures?: (transactionPrefixHash: string,
keyImage: string,
inputKeys: string[],
privateKey: string,
realIndex: number) => string[];
/**
* A replacement function for the JS/C++ checkRingSignatures.
*/
checkRingSignatures?: (transactionPrefixHash: string,
keyImage: string,
publicKeys: string[],
signatures: string[]) => boolean;
/**
* A replacement function for the JS/C++ generateKeyDerivation.
*/
generateKeyDerivation?: (transactionPublicKey: string,
privateViewKey: string) => string;
/**
* A replacement function for the JS/C++ checkSignature.
*/
checkSignature?: (digestHash: string,
publicKey: string,
signature: string) => boolean;
/**
* A replacement function for the JS/C++ generateSignature.
*/
generateSignature?: (digestHash: string,
publicKey: string,
privateKey: string) => [boolean, string];
}
export interface OutputToScan {
key: string;
index: number;
}
export interface CreatedInput {
transactionKey: Keys;
publicEphemeral: string;
privateEphemeral?: string;
}
export interface OurOutput extends OutputToScan {
input: CreatedInput;
keyImage?: string;
}
export interface Output {
key: string;
input: Input;
keyImage: string;
index: number;
globalIndex: number;
amount: number;
}
export interface Input {
privateEphemeral: string;
}
export interface Address {
spend: Keys;
view: Keys;
address: string;
mnemonic: string | null;
seed: string | null;
subWalletIndex: number;
}
export interface Keys {
privateKey: string;
publicKey: string;
}
export interface DecodedAddressPrefix {
prefix: string;
base58: string;
decimal: number;
hexadecimal: string;
}
export interface DecodedAddress {
publicViewKey: string;
publicSpendKey: string;
paymentId: string;
encodedPrefix: string;
prefix: number;
rawAddress: string;
}
export interface TxDestination {
amount: number;
keys: DecodedAddress;
}
export interface Wallet {
view: Keys;
spend: Keys;
}
export interface RandomOutput {
key: string;
globalIndex: number;
}
export interface CreatedTransaction {
transaction: Transaction;
rawTransaction: string;
hash: string;
}
export interface Transaction {
version: number;
unlockTime: number;
inputs: Vin[];
outputs: Vout[];
extra: Extra;
signatures: string[][];
ignoredField: boolean;
transactionKeys: Keys;
}
type Extra = Array<PublicKeyTag | NonceTag | MergeMiningTag>;
export interface PublicKeyTag {
tag: 1;
publicKey: string;
}
export interface NonceTag {
tag: 2;
nonces: Nonce[];
}
export interface MergeMiningTag {
tag: 3;
depth: number;
merkleRoot: string;
}
export interface Nonce {
tag: 0;
paymentId: string;
}
export interface Vin {
type: string;
amount: number;
keyImage: string;
keyOffsets: number[];
}
export interface Vout {
amount: number;
type: string;
key: string;
}
export interface BlockTemplate {
blob: string;
block: object;
blockTemplate: string;
}