-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monero-rpc.js
438 lines (368 loc) · 10.8 KB
/
monero-rpc.js
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
class MoneroWalletRPC {
constructor(url) {
// URL should be in the format: http://IP:PORT/json_rpc
// For example: http://127.0.0.1:18082/json_rpc
this.url = url;
}
async call(method, params = {}) {
// This method creates the JSON-RPC request
const response = await fetch(this.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
// This body corresponds to the -d parameter in the curl example
body: JSON.stringify({
jsonrpc: '2.0',
id: '0',
method: method, // This is the $METHOD in the curl example
params: params, // This is the $PARAMS in the curl example
}),
});
const data = await response.json();
if (data.error) {
throw new Error(data.error.message);
}
return data.result;
}
// Example method using the JSON-RPC interface
async makeIntegratedAddress(paymentId) {
return this.call('make_integrated_address', { payment_id: paymentId });
}
//JSON RPC method is set_daemon
async setDaemon({
address = "",
trusted = false,
ssl_support = "autodetect",
ssl_private_key_path,
ssl_certificate_path,
ssl_ca_file,
ssl_allowed_fingerprints,
ssl_allow_any_cert = false,
username,
password
} = {}) {
const params = {
address,
trusted,
ssl_support,
ssl_private_key_path,
ssl_certificate_path,
ssl_ca_file,
ssl_allowed_fingerprints,
ssl_allow_any_cert,
username,
password
};
// Remove undefined parameters
Object.keys(params).forEach(key => params[key] === undefined && delete params[key]);
return this.call('set_daemon', params);
}
//JSON RPC method is get_balance
async getBalance({
account_index,
address_indices,
all_accounts = false,
strict = false
} = {}) {
const params = {
account_index,
address_indices,
all_accounts,
strict
};
// Remove undefined parameters
Object.keys(params).forEach(key => params[key] === undefined && delete params[key]);
return this.call('get_balance', params);
}
}
// get_address
async getAddress(account_index, address_index) {
return this.call('get_address', { account_index, address_index });
}
// get_address_index
async getAddressIndex(address) {
return this.call('get_address_index', { address });
}
// create_address
async createAddress(account_index, label, count) {
return this.call('create_address', { account_index, label, count });
}
// label_address
async labelAddress(index, label) {
return this.call('label_address', { index, label });
}
// validate_address
async validateAddress(address, any_net_type, allow_openalias) {
return this.call('validate_address', { address, any_net_type, allow_openalias });
}
// transfer
async transfer(destinations, account_index, subaddr_indices, priority, ring_size, unlock_time, payment_id, get_tx_key, do_not_relay, get_tx_hex, get_tx_metadata) {
return this.call('transfer', {
destinations,
account_index,
subaddr_indices,
priority,
ring_size,
unlock_time,
payment_id,
get_tx_key,
do_not_relay,
get_tx_hex,
get_tx_metadata
});
}
// transfer_split
async transferSplit(destinations, account_index, subaddr_indices, priority, ring_size, unlock_time, payment_id, get_tx_keys, do_not_relay, get_tx_hex, get_tx_metadata) {
return this.call('transfer_split', {
destinations,
account_index,
subaddr_indices,
priority,
ring_size,
unlock_time,
payment_id,
get_tx_keys,
do_not_relay,
get_tx_hex,
get_tx_metadata
});
}
// sign_transfer
async signTransfer(unsigned_txset, export_raw) {
return this.call('sign_transfer', { unsigned_txset, export_raw });
}
// submit_transfer
async submitTransfer(tx_data_hex) {
return this.call('submit_transfer', { tx_data_hex });
}
// sweep_dust
async sweepDust(get_tx_keys, do_not_relay, get_tx_hex, get_tx_metadata) {
return this.call('sweep_dust', { get_tx_keys, do_not_relay, get_tx_hex, get_tx_metadata });
}
// sweep_all
async sweepAll(address, account_index, subaddr_indices, priority, ring_size, unlock_time, payment_id, get_tx_keys, below_amount, do_not_relay, get_tx_hex, get_tx_metadata) {
return this.call('sweep_all', {
address,
account_index,
subaddr_indices,
priority,
ring_size,
unlock_time,
payment_id,
get_tx_keys,
below_amount,
do_not_relay,
get_tx_hex,
get_tx_metadata
});
}
// sweep_single
async sweepSingle(address, txid, account_index, priority, ring_size, unlock_time, payment_id, get_tx_key, do_not_relay, get_tx_hex, get_tx_metadata) {
return this.call('sweep_single', {
address,
txid,
account_index,
priority,
ring_size,
unlock_time,
payment_id,
get_tx_key,
do_not_relay,
get_tx_hex,
get_tx_metadata
});
}
// relay_tx
async relayTx(hex) {
return this.call('relay_tx', { hex });
}
// store
async store() {
return this.call('store');
}
// get_payments
async getPayments(payment_id) {
return this.call('get_payments', { payment_id });
}
// get_bulk_payments
async getBulkPayments(payment_ids, min_block_height) {
return this.call('get_bulk_payments', { payment_ids, min_block_height });
}
}
// get_accounts
async getAccounts(tag) {
return this.call('get_accounts', { tag });
}
// create_account
async createAccount(label) {
return this.call('create_account', { label });
}
// get_account_tags
async getAccountTags() {
return this.call('get_account_tags');
}
// get_height
async getHeight() {
return this.call('get_height');
}
// incoming_transfers
async incomingTransfers(transfer_type, account_index, subaddr_indices) {
return this.call('incoming_transfers', { transfer_type, account_index, subaddr_indices });
}
// query_key
async queryKey(key_type) {
return this.call('query_key', { key_type });
}
// make_integrated_address
async makeIntegratedAddress(standard_address, payment_id) {
return this.call('make_integrated_address', { standard_address, payment_id });
}
// split_integrated_address
async splitIntegratedAddress(integrated_address) {
return this.call('split_integrated_address', { integrated_address });
}
// stop_wallet
async stopWallet() {
return this.call('stop_wallet');
}
// rescan_blockchain
async rescanBlockchain() {
return this.call('rescan_blockchain');
}
// set_tx_notes
async setTxNotes(txids, notes) {
return this.call('set_tx_notes', { txids, notes });
}
// get_tx_notes
async getTxNotes(txids) {
return this.call('get_tx_notes', { txids });
}
// set_attribute
async setAttribute(key, value) {
return this.call('set_attribute', { key, value });
}
// get_attribute
async getAttribute(key) {
return this.call('get_attribute', { key });
}
}
// get_tx_key
async getTxKey(txid) {
return this.call('get_tx_key', { txid });
}
// check_tx_key
async checkTxKey(txid, tx_key, address) {
return this.call('check_tx_key', { txid, tx_key, address });
}
// get_tx_proof
async getTxProof(txid, address, message) {
return this.call('get_tx_proof', { txid, address, message });
}
// check_tx_proof
async checkTxProof(txid, address, message, signature) {
return this.call('check_tx_proof', { txid, address, message, signature });
}
// get_spend_proof
async getSpendProof(txid, message) {
return this.call('get_spend_proof', { txid, message });
}
// check_spend_proof
async checkSpendProof(txid, message, signature) {
return this.call('check_spend_proof', { txid, message, signature });
}
// get_reserve_proof
async getReserveProof(all, account_index, amount, message) {
return this.call('get_reserve_proof', { all, account_index, amount, message });
}
// check_reserve_proof
async checkReserveProof(address, message, signature) {
return this.call('check_reserve_proof', { address, message, signature });
}
// get_transfers
async getTransfers(in_, out, pending, failed, pool, filter_by_height, min_height, max_height, account_index, subaddr_indices) {
return this.call('get_transfers', {
in, out, pending, failed, pool,
filter_by_height, min_height, max_height,
account_index, subaddr_indices
});
}
// get_transfer_by_txid
async getTransferByTxid(txid, account_index) {
return this.call('get_transfer_by_txid', { txid, account_index });
}
// describe_transfer
async describeTransfer(unsigned_txset, multisig_txset) {
return this.call('describe_transfer', { unsigned_txset, multisig_txset });
}
// sign
async sign(data) {
return this.call('sign', { data });
}
// verify
async verify(data, address, signature) {
return this.call('verify', { data, address, signature });
}
// export_outputs
async exportOutputs(all) {
return this.call('export_outputs', { all });
}
}
// import_outputs
async importOutputs(outputs_data_hex) {
return this.call('import_outputs', { outputs_data_hex });
}
// export_key_images
async exportKeyImages(all) {
return this.call('export_key_images', { all });
}
// import_key_images
async importKeyImages(signed_key_images) {
return this.call('import_key_images', { signed_key_images });
}
// make_uri
async makeUri(address, amount, payment_id, recipient_name, tx_description) {
return this.call('make_uri', { address, amount, payment_id, recipient_name, tx_description });
}
// parse_uri
async parseUri(uri) {
return this.call('parse_uri', { uri });
}
// get_address_book
async getAddressBook(entries) {
return this.call('get_address_book', { entries });
}
// add_address_book
async addAddressBook(address, payment_id, description) {
return this.call('add_address_book', { address, payment_id, description });
}
// delete_address_book
async deleteAddressBook(index) {
return this.call('delete_address_book', { index });
}
// refresh
async refresh(start_height) {
return this.call('refresh', { start_height });
}
// rescan_spent
async rescanSpent() {
return this.call('rescan_spent');
}
// start_mining
async startMining(threads_count, do_background_mining, ignore_battery) {
return this.call('start_mining', { threads_count, do_background_mining, ignore_battery });
}
// stop_mining
async stopMining() {
return this.call('stop_mining');
}
// get_languages
async getLanguages() {
return this.call('get_languages');
}
// create_wallet
async createWallet(filename, password, language) {
return this.call('create_wallet', { filename, password, language });
}
}
export default MoneroWalletRPC;