-
Notifications
You must be signed in to change notification settings - Fork 12
/
HaskellShelleyModule.java
602 lines (507 loc) · 18.8 KB
/
HaskellShelleyModule.java
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
package io.emurgo.rnhaskellshelley;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class HaskellShelleyModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public HaskellShelleyModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName() {
return "HaskellShelley";
}
// Utils
@ReactMethod
public final void makeIcarusBootstrapWitness(String txBodyHash, String addr, String key, Promise promise) {
Native.I
.makeIcarusBootstrapWitness(new RPtr(txBodyHash), new RPtr(addr), new RPtr(key))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void makeVkeyWitness(String txBodyHash, String sk, Promise promise) {
Native.I
.makeVkeyWitness(new RPtr(txBodyHash), new RPtr(sk))
.map(RPtr::toJs)
.pour(promise);
}
// BigNum
@ReactMethod
public final void bigNumFromStr(String string, Promise promise) {
Native.I
.bigNumFromStr(string)
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bigNumToStr(String bigNum, Promise promise) {
Native.I
.bigNumToStr(new RPtr(bigNum))
.pour(promise);
}
// Bip32PrivateKey
@ReactMethod
public final void bip32PrivateKeyDerive(String bip32PrivateKey, Double index, Promise promise) {
Native.I
.bip32PrivateKeyDerive(new RPtr(bip32PrivateKey), index.longValue())
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyGenerateEd25519Bip32(Promise promise) {
Native.I
.bip32PrivateKeyGenerateEd25519Bip32()
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyToRawKey(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToRawKey(new RPtr(bip32PrivateKey))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyToPublic(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToPublic(new RPtr(bip32PrivateKey))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyFromBytes(String bytes, Promise promise) {
Native.I
.bip32PrivateKeyFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyAsBytes(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyAsBytes(new RPtr(bip32PrivateKey))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyFromBech32(String bech32Str, Promise promise) {
Native.I
.bip32PrivateKeyFromBech32(bech32Str)
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyToBech32(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToBech32(new RPtr(bip32PrivateKey))
.pour(promise);
}
@ReactMethod
public final void bip32PrivateKeyFromBip39Entropy(String entropy, String password, Promise promise) {
Native.I
.bip32PrivateKeyFromBip39Entropy(Base64.decode(entropy, Base64.DEFAULT), Base64.decode(password, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// ByronAddress
@ReactMethod
public final void byronAddressToBase58(String byronAddress, Promise promise) {
Native.I
.byronAddressToBase58(new RPtr(byronAddress))
.pour(promise);
}
@ReactMethod
public final void byronAddressFromBase58(String string, Promise promise) {
Native.I
.byronAddressFromBase58(string)
.map(RPtr::toJs)
.pour(promise);
}
// Address
@ReactMethod
public final void addressToBytes(String address, Promise promise) {
Native.I
.addressToBytes(new RPtr(address))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void addressFromBytes(String bytes, Promise promise) {
Native.I
.addressFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// Ed25519KeyHash
@ReactMethod
public final void ed25519KeyHashToBytes(String ed25519KeyHash, Promise promise) {
Native.I
.ed25519KeyHashToBytes(new RPtr(ed25519KeyHash))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void ed25519KeyHashFromBytes(String bytes, Promise promise) {
Native.I
.ed25519KeyHashFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// TransactionHash
@ReactMethod
public final void transactionHashToBytes(String transactionHash, Promise promise) {
Native.I
.transactionHashToBytes(new RPtr(transactionHash))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void transactionHashFromBytes(String bytes, Promise promise) {
Native.I
.transactionHashFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// StakeCredential
@ReactMethod
public final void stakeCredentialFromKeyHash(String keyHash, Promise promise) {
Native.I
.stakeCredentialFromKeyHash(new RPtr(keyHash))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void stakeCredentialToKeyHash(String stakeCredential, Promise promise) {
Native.I
.stakeCredentialToKeyHash(new RPtr(stakeCredential))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void stakeCredentialKind(String stakeCredential, Promise promise) {
Native.I
.stakeCredentialKind(new RPtr(stakeCredential))
.pour(promise);
}
@ReactMethod
public final void stakeCredentialToBytes(String stakeCredential, Promise promise) {
Native.I
.stakeCredentialToBytes(new RPtr(stakeCredential))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void stakeCredentialFromBytes(String bytes, Promise promise) {
Native.I
.stakeCredentialFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// BaseAddress
@ReactMethod
public final void baseAddressNew(Integer network, String payment, String stake, Promise promise) {
Native.I
.baseAddressNew(network, new RPtr(payment), new RPtr(stake))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void baseAddressPaymentCred(String baseAddress, Promise promise) {
Native.I
.baseAddressPaymentCred(new RPtr(baseAddress))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void baseAddressStakeCred(String baseAddress, Promise promise) {
Native.I
.baseAddressStakeCred(new RPtr(baseAddress))
.map(RPtr::toJs)
.pour(promise);
}
// UnitInterval
@ReactMethod
public final void unitIntervalToBytes(String unitInterval, Promise promise) {
Native.I
.unitIntervalToBytes(new RPtr(unitInterval))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void unitIntervalFromBytes(String bytes, Promise promise) {
Native.I
.unitIntervalFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void unitIntervalNew(String numerator, String denominator, Promise promise) {
Native.I
.unitIntervalNew(new RPtr(numerator), new RPtr(denominator))
.map(RPtr::toJs)
.pour(promise);
}
// TransactionInput
@ReactMethod
public final void transactionInputToBytes(String transactionInput, Promise promise) {
Native.I
.transactionInputToBytes(new RPtr(transactionInput))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void transactionInputFromBytes(String bytes, Promise promise) {
Native.I
.transactionInputFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionInputTransactionId(String transactionInput, Promise promise) {
Native.I
.transactionInputTransactionId(new RPtr(transactionInput))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionInputIndex(String transactionInput, Promise promise) {
Native.I
.transactionInputIndex(new RPtr(transactionInput))
.map(Long::intValue)
.pour(promise);
}
@ReactMethod
public final void transactionInputNew(String transactionId, Double index, Promise promise) {
Native.I
.transactionInputNew(new RPtr(transactionId), index.longValue())
.map(RPtr::toJs)
.pour(promise);
}
// TransactionOutput
@ReactMethod
public final void transactionOutputToBytes(String transactionOutput, Promise promise) {
Native.I
.transactionOutputToBytes(new RPtr(transactionOutput))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void transactionOutputFromBytes(String bytes, Promise promise) {
Native.I
.transactionOutputFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionOutputNew(String address, String amount, Promise promise) {
Native.I
.transactionOutputNew(new RPtr(address), new RPtr(amount))
.map(RPtr::toJs)
.pour(promise);
}
// LinearFee
@ReactMethod
public final void linearFeeCoefficient(String linearFee, Promise promise) {
Native.I
.linearFeeCoefficient(new RPtr(linearFee))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void linearFeeConstant(String linearFee, Promise promise) {
Native.I
.linearFeeConstant(new RPtr(linearFee))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void linearFeeNew(String coefficient, String constant, Promise promise) {
Native.I
.linearFeeNew(new RPtr(coefficient), new RPtr(constant))
.map(RPtr::toJs)
.pour(promise);
}
// Vkeywitnesses
@ReactMethod
public final void vkeywitnessesNew(Promise promise) {
Native.I
.vkeywitnessesNew()
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void vkeywitnessesLen(String vkwitnesses, Promise promise) {
Native.I
.vkeywitnessesLen(new RPtr(vkwitnesses))
.map(Long::intValue)
.pour(promise);
}
@ReactMethod
public final void vkeywitnessesAdd(String vkwitnesses, String item, Promise promise) {
Native.I
.vkeywitnessesAdd(new RPtr(vkwitnesses), new RPtr(item))
.pour(promise);
}
// BootstrapWitnesses
@ReactMethod
public final void bootstrapWitnessesNew(Promise promise) {
Native.I
.bootstrapWitnessesNew()
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void bootstrapWitnessesLen(String witnesses, Promise promise) {
Native.I
.bootstrapWitnessesLen(new RPtr(witnesses))
.map(Long::intValue)
.pour(promise);
}
@ReactMethod
public final void bootstrapWitnessesAdd(String witnesses, String item, Promise promise) {
Native.I
.bootstrapWitnessesAdd(new RPtr(witnesses), new RPtr(item))
.pour(promise);
}
// TransactionWitnessSet
@ReactMethod
public final void transactionWitnessSetNew(Promise promise) {
Native.I
.transactionWitnessSetNew()
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionWitnessSetSetVkeys(String witnessSet, String vkeys, Promise promise) {
Native.I
.transactionWitnessSetSetVkeys(new RPtr(witnessSet), new RPtr(vkeys))
.pour(promise);
}
@ReactMethod
public final void transactionWitnessSetSetBootstraps(String witnessSet, String bootstraps, Promise promise) {
Native.I
.transactionWitnessSetSetBootstraps(new RPtr(witnessSet), new RPtr(bootstraps))
.pour(promise);
}
// TransactionBody
@ReactMethod
public final void transactionBodyToBytes(String transactionBody, Promise promise) {
Native.I
.transactionBodyToBytes(new RPtr(transactionBody))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void transactionBodyFromBytes(String bytes, Promise promise) {
Native.I
.transactionBodyFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// Transaction
@ReactMethod
public final void transactionNew(String body, String witnessSet, Promise promise) {
Native.I
.transactionNew(new RPtr(body), new RPtr(witnessSet))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionToBytes(String transaction, Promise promise) {
Native.I
.transactionToBytes(new RPtr(transaction))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}
@ReactMethod
public final void transactionFromBytes(String bytes, Promise promise) {
Native.I
.transactionFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}
// TransactionBuilder
@ReactMethod
public final void transactionBuilderAddKeyInput(String txBuilder, String hash, String input, String amount, Promise promise) {
Native.I
.transactionBuilderAddKeyInput(new RPtr(txBuilder), new RPtr(hash), new RPtr(input), new RPtr(amount))
.pour(promise);
}
@ReactMethod
public final void transactionBuilderAddBootstrapInput(String txBuilder, String hash, String input, String amount, Promise promise) {
Native.I
.transactionBuilderAddBootstrapInput(new RPtr(txBuilder), new RPtr(hash), new RPtr(input), new RPtr(amount))
.pour(promise);
}
@ReactMethod
public final void transactionBuilderAddOutput(String txBuilder, String output, Promise promise) {
Native.I
.transactionBuilderAddOutput(new RPtr(txBuilder), new RPtr(output))
.pour(promise);
}
@ReactMethod
public final void transactionBuilderSetFee(String txBuilder, String fee, Promise promise) {
Native.I
.transactionBuilderSetFee(new RPtr(txBuilder), new RPtr(fee))
.pour(promise);
}
@ReactMethod
public final void transactionBuilderSetTtl(String txBuilder, Double ttl, Promise promise) {
Native.I
.transactionBuilderSetTtl(new RPtr(txBuilder), ttl.longValue())
.pour(promise);
}
@ReactMethod
public final void transactionBuilderNew(String linearFee, String minimumUtxoVal, String poolDeposit, String keyDeposit, Promise promise) {
Native.I
.transactionBuilderNew(new RPtr(linearFee), new RPtr(minimumUtxoVal), new RPtr(poolDeposit), new RPtr(keyDeposit))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionBuilderGetExplicitInput(String txBuilder, Promise promise) {
Native.I
.transactionBuilderGetExplicitInput(new RPtr(txBuilder))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionBuilderGetImplicitInput(String txBuilder, Promise promise) {
Native.I
.transactionBuilderGetImplicitInput(new RPtr(txBuilder))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionBuilderGetExplicitOutput(String txBuilder, Promise promise) {
Native.I
.transactionBuilderGetExplicitOutput(new RPtr(txBuilder))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionBuilderAddChangeIfNeeded(String txBuilder, String address, Promise promise) {
Native.I
.transactionBuilderAddChangeIfNeeded(new RPtr(txBuilder), new RPtr(address))
.pour(promise);
}
@ReactMethod
public final void transactionBuilderBuild(String txBuilder, Promise promise) {
Native.I
.transactionBuilderBuild(new RPtr(txBuilder))
.map(RPtr::toJs)
.pour(promise);
}
@ReactMethod
public final void transactionBuilderEstimateFee(String txBuilder, Promise promise) {
Native.I
.transactionBuilderEstimateFee(new RPtr(txBuilder))
.map(RPtr::toJs)
.pour(promise);
}
}