react-native-zcash 0.4.1 → 0.5.0
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/CHANGELOG.md +12 -0
- package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2230000.json +8 -0
- package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +101 -77
- package/ios/RNZcash.swift +12 -9
- package/lib/rnzcash.rn.js.map +1 -1
- package/lib/src/react-native.d.ts +2 -2
- package/lib/src/types.d.ts +6 -1
- package/package.json +1 -1
- package/src/react-native.ts +2 -1
- package/src/types.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# React Native Zcash
|
|
2
2
|
|
|
3
|
+
## 0.5.0 (2023-09-20)
|
|
4
|
+
|
|
5
|
+
- changed: `deriveUnifiedAddress` will now return all three address types
|
|
6
|
+
- changed: Replace `runBlocking` with async/await (Android)
|
|
7
|
+
- fixed: Rewrite `getTransactions` (Android)
|
|
8
|
+
- fixed: Force balance refresh before grabbing balances in `getBalance` (workaround for bug in SDK) (Android)
|
|
9
|
+
|
|
10
|
+
## 0.4.2 (2023-09-14)
|
|
11
|
+
|
|
12
|
+
- changed: Always return memos array with transactions
|
|
13
|
+
- changed: Simplify compactMap transform
|
|
14
|
+
|
|
3
15
|
## 0.4.1 (2023-09-13)
|
|
4
16
|
|
|
5
17
|
- fixed: Update checkpoint path (Android)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "main",
|
|
3
|
+
"height": "2230000",
|
|
4
|
+
"hash": "00000000012d4b6a23c7fb155f41880059ab76b1e53eeb00fd815fec785d8c9f",
|
|
5
|
+
"time": 1694943243,
|
|
6
|
+
"saplingTree": "0153aa9b90d677f07c26197fa64bbb2ca536073a86fd33d2abd39ba7571e1bb32b01a3af5fed6ecb6d8adc882abc339c4478e738befc199aeeec86000964684580241a013bdf293a70d1fe712b7288c7b71b5ac3d1e1511253e8b2a8bbfce0d23dc160440001f00f1e31571c262208a894786cac5b6ec972789320249b9abde08dd776cbcc41000000000001aae6f66d11fd0fcff3e6aaa713857451f02ea45c85c2695262a51b4282185633012931e37c5440eeeee1be3c3f728062754b2b614f57483d6f60154c3676a69515000001579ced54cf6fbdf70a333d261545807f712a060ca270c4dd38b66761f77a98520000000182ac7ebe2f7e9d8084a38aa8be56b1bd86292babf05f98882a6959cf9d318c110001d8ccea507421a590ed38116b834189cdc22421b4764179fa4e364803dfa66d56018cf6f5034a55fed59d1d832620916a43c756d2379e50ef9440fc4c3e7a29aa2300011619f99023a69bb647eab2d2aa1a73c3673c74bb033c3c4930eacda19e6fd93b0000000160272b134ca494b602137d89e528c751c06d3ef4a87a45f33af343c15060cc1e",
|
|
7
|
+
"orchardTree": "017138fa0167df524c3b884dda160c109760bd63da1a83617390b5d84b558fe51a0145762a76c27a5531dabd7065983681a260ef6ff287bef443c767772ecdc4c20c1f0000015a69d102fca262dc52daa3c6f5afb3cdff72a9a970b7034f07573a03c4b7053201e17ab5213711283230fcc5c7a7a8024bfe59b4dfe75aa60aa66de84286c6752f0001eb2578733549c4e9ef210f060838b756fa26459421bd65e6f33c1fbf38ea2d07015b720382157758674694fb7ab102a26196abcc0e2b8b5f3481997620535fe23c0000000000000001dd3e61f3e1d497d923486bd000737ea0ffac885fa481316727d0d8f7fc2138100001cf3bf92f69798e68555548afcce1648add1fb2548d64fa9a1ec22a3e26e7890101e637281deb58dff0c44ba13149b784a95da1b493005efd057e6f4ac20ef5d81d000001cc2dcaa338b312112db04b435a706d63244dd435238f0aa1e9e1598d35470810012dcc4273c8a0ed2337ecf7879380a07e7d427c7f9d82e538002bd1442978402c01daf63debf5b40df902dae98dadc029f281474d190cddecef1b10653248a234150001e2bca6a8d987d668defba89dc082196a922634ed88e065c669e526bb8815ee1b000000000000"
|
|
8
|
+
}
|
|
@@ -14,11 +14,11 @@ import co.electriccoin.lightwallet.client.model.Response
|
|
|
14
14
|
import co.electriccoin.lightwallet.client.new
|
|
15
15
|
import com.facebook.react.bridge.*
|
|
16
16
|
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
17
|
+
import kotlinx.coroutines.async
|
|
17
18
|
import kotlinx.coroutines.CoroutineScope
|
|
18
19
|
import kotlinx.coroutines.cancel
|
|
19
20
|
import kotlinx.coroutines.flow.*
|
|
20
21
|
import kotlinx.coroutines.launch
|
|
21
|
-
import kotlinx.coroutines.runBlocking
|
|
22
22
|
import kotlin.coroutines.EmptyCoroutineContext
|
|
23
23
|
|
|
24
24
|
class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
@@ -51,21 +51,23 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
51
51
|
val wallet = getWallet(alias)
|
|
52
52
|
val scope = wallet.coroutineScope
|
|
53
53
|
wallet.processorInfo.collectWith(scope, { update ->
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
scope.launch {
|
|
55
|
+
var lastDownloadedHeight = this.async { wallet.processor.downloader.getLastDownloadedHeight() }.await()
|
|
56
|
+
if (lastDownloadedHeight == null) lastDownloadedHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
|
|
57
|
+
|
|
58
|
+
var lastScannedHeight = update.lastSyncedHeight
|
|
59
|
+
if (lastScannedHeight == null) lastScannedHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
|
|
60
|
+
|
|
61
|
+
var networkBlockHeight = update.networkBlockHeight
|
|
62
|
+
if (networkBlockHeight == null) networkBlockHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
|
|
63
|
+
|
|
64
|
+
sendEvent("UpdateEvent") { args ->
|
|
65
|
+
args.putString("alias", alias)
|
|
66
|
+
args.putInt("lastDownloadedHeight", lastDownloadedHeight.value.toInt())
|
|
67
|
+
args.putInt("lastScannedHeight", lastScannedHeight.value.toInt())
|
|
68
|
+
args.putInt("scanProgress", wallet.processor.progress.value.toPercentage())
|
|
69
|
+
args.putInt("networkBlockHeight", networkBlockHeight.value.toInt())
|
|
70
|
+
}
|
|
69
71
|
}
|
|
70
72
|
})
|
|
71
73
|
wallet.status.collectWith(scope, { status ->
|
|
@@ -81,13 +83,9 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
81
83
|
@ReactMethod
|
|
82
84
|
fun stop(alias: String, promise: Promise) {
|
|
83
85
|
val wallet = getWallet(alias)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
synchronizerMap.remove(alias)
|
|
88
|
-
promise.resolve(null)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
86
|
+
wallet.close()
|
|
87
|
+
synchronizerMap.remove(alias)
|
|
88
|
+
promise.resolve(null)
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
fun inRange(tx: TransactionOverview, first: Int, last: Int): Boolean {
|
|
@@ -97,70 +95,87 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
97
95
|
return false
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
val
|
|
98
|
+
suspend fun collectTxs(wallet: SdkSynchronizer, limit: Int): List<TransactionOverview> {
|
|
99
|
+
val allTxs = mutableListOf<TransactionOverview>()
|
|
100
|
+
val job = wallet.coroutineScope.launch {
|
|
101
|
+
wallet.transactions.collect { txList ->
|
|
102
|
+
txList.forEach { tx ->
|
|
103
|
+
allTxs.add(tx)
|
|
104
|
+
}
|
|
105
|
+
if (allTxs.size == limit) {
|
|
106
|
+
cancel()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
job.join()
|
|
103
111
|
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
return allTxs
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
suspend fun parseTx(wallet: SdkSynchronizer, tx: TransactionOverview): WritableMap {
|
|
116
|
+
val map = Arguments.createMap()
|
|
117
|
+
val job = wallet.coroutineScope.launch {
|
|
106
118
|
map.putString("value", tx.netValue.value.toString())
|
|
107
119
|
map.putInt("minedHeight", tx.minedHeight!!.value.toInt())
|
|
108
120
|
map.putInt("blockTimeInSeconds", tx.blockTimeEpochSeconds.toInt())
|
|
109
121
|
map.putString("rawTransactionId", tx.rawId.byteArray.toHexReversed())
|
|
110
122
|
if (tx.isSentTransaction) {
|
|
111
|
-
val recipient =
|
|
123
|
+
val recipient = wallet.getRecipients(tx).first()
|
|
112
124
|
if (recipient is TransactionRecipient.Address) {
|
|
113
125
|
map.putString("toAddress", recipient.addressValue)
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
if (tx.memoCount > 0) {
|
|
117
|
-
val memos =
|
|
129
|
+
val memos = wallet.getMemos(tx).take(tx.memoCount).toList()
|
|
118
130
|
map.putArray("memos", Arguments.fromList(memos))
|
|
131
|
+
} else {
|
|
132
|
+
map.putArray("memos", Arguments.createArray())
|
|
119
133
|
}
|
|
120
|
-
return map
|
|
121
134
|
}
|
|
135
|
+
job.join()
|
|
136
|
+
return map
|
|
137
|
+
}
|
|
122
138
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
@ReactMethod
|
|
140
|
+
fun getTransactions(alias: String, first: Int, last: Int, promise: Promise) {
|
|
141
|
+
val wallet = getWallet(alias)
|
|
142
|
+
|
|
143
|
+
wallet.coroutineScope.launch {
|
|
144
|
+
val numTxs = async { wallet.getTransactionCount() }.await()
|
|
126
145
|
val nativeArray = Arguments.createArray()
|
|
127
146
|
if (numTxs == 0) {
|
|
128
147
|
promise.resolve(nativeArray)
|
|
129
148
|
return@launch
|
|
130
149
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}.collect()
|
|
144
|
-
}
|
|
150
|
+
|
|
151
|
+
val allTxs = async { collectTxs(wallet, numTxs) }.await()
|
|
152
|
+
val filteredTxs = allTxs.filter { tx -> inRange(tx, first, last) }
|
|
153
|
+
|
|
154
|
+
filteredTxs.map { tx -> launch {
|
|
155
|
+
val parsedTx = parseTx(wallet, tx)
|
|
156
|
+
nativeArray.pushMap(parsedTx)
|
|
157
|
+
} }.forEach { it.join() }
|
|
158
|
+
|
|
159
|
+
promise.resolve(nativeArray)
|
|
145
160
|
}
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
@ReactMethod
|
|
149
164
|
fun rescan(alias: String, promise: Promise) {
|
|
150
165
|
val wallet = getWallet(alias)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
promise.resolve(null)
|
|
155
|
-
}
|
|
166
|
+
wallet.coroutineScope.launch {
|
|
167
|
+
wallet.coroutineScope.async { wallet.rewindToNearestHeight(wallet.latestBirthdayHeight, true) }.await()
|
|
168
|
+
promise.resolve(null)
|
|
156
169
|
}
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
@ReactMethod
|
|
160
173
|
fun deriveViewingKey(seed: String, network: String = "mainnet", promise: Promise) {
|
|
161
174
|
var seedPhrase = SeedPhrase.new(seed)
|
|
162
|
-
|
|
163
|
-
|
|
175
|
+
moduleScope.launch {
|
|
176
|
+
var keys = moduleScope.async { DerivationTool.getInstance().deriveUnifiedFullViewingKeys(seedPhrase.toByteArray(), networks.getOrDefault(network, ZcashNetwork.Mainnet), DerivationTool.DEFAULT_NUMBER_OF_ACCOUNTS)[0] }.await()
|
|
177
|
+
promise.resolve(keys.encoding)
|
|
178
|
+
}
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
//
|
|
@@ -197,25 +212,29 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
197
212
|
}
|
|
198
213
|
|
|
199
214
|
@ReactMethod
|
|
200
|
-
fun getBalance(alias: String, promise: Promise)
|
|
215
|
+
fun getBalance(alias: String, promise: Promise) {
|
|
201
216
|
val wallet = getWallet(alias)
|
|
202
217
|
var availableZatoshi = Zatoshi(0L)
|
|
203
218
|
var totalZatoshi = Zatoshi(0L)
|
|
204
219
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
220
|
+
wallet.coroutineScope.launch {
|
|
221
|
+
wallet.coroutineScope.async { wallet.refreshAllBalances() }.await()
|
|
222
|
+
|
|
223
|
+
val transparentBalances = wallet.transparentBalances.value
|
|
224
|
+
availableZatoshi = availableZatoshi.plus(transparentBalances?.available ?: Zatoshi(0L))
|
|
225
|
+
totalZatoshi = totalZatoshi.plus(transparentBalances?.total ?: Zatoshi(0L))
|
|
226
|
+
val saplingBalances = wallet.saplingBalances.value
|
|
227
|
+
availableZatoshi = availableZatoshi.plus(saplingBalances?.available ?: Zatoshi(0L))
|
|
228
|
+
totalZatoshi = totalZatoshi.plus(saplingBalances?.total ?: Zatoshi(0L))
|
|
229
|
+
val orchardBalances = wallet.orchardBalances.value
|
|
230
|
+
availableZatoshi = availableZatoshi.plus(orchardBalances?.available ?: Zatoshi(0L))
|
|
231
|
+
totalZatoshi = totalZatoshi.plus(orchardBalances?.total ?: Zatoshi(0L))
|
|
214
232
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
233
|
+
val map = Arguments.createMap()
|
|
234
|
+
map.putString("totalZatoshi", totalZatoshi.value.toString())
|
|
235
|
+
map.putString("availableZatoshi", availableZatoshi.value.toString())
|
|
236
|
+
promise.resolve(map)
|
|
237
|
+
}
|
|
219
238
|
}
|
|
220
239
|
|
|
221
240
|
@ReactMethod
|
|
@@ -230,7 +249,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
230
249
|
val wallet = getWallet(alias)
|
|
231
250
|
wallet.coroutineScope.launch {
|
|
232
251
|
var seedPhrase = SeedPhrase.new(seed)
|
|
233
|
-
val usk =
|
|
252
|
+
val usk = wallet.coroutineScope.async { DerivationTool.getInstance().deriveUnifiedSpendingKey(seedPhrase.toByteArray(), wallet.network, Account.DEFAULT) }.await()
|
|
234
253
|
try {
|
|
235
254
|
val internalId = wallet.sendToAddress(
|
|
236
255
|
usk,
|
|
@@ -238,7 +257,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
238
257
|
toAddress,
|
|
239
258
|
memo,
|
|
240
259
|
)
|
|
241
|
-
val tx =
|
|
260
|
+
val tx = wallet.coroutineScope.async { wallet.transactions.flatMapConcat { list -> flowOf(*list.toTypedArray()) } }.await().firstOrNull { item -> item.id == internalId }
|
|
242
261
|
if (tx == null) throw Exception("transaction failed")
|
|
243
262
|
|
|
244
263
|
val map = Arguments.createMap()
|
|
@@ -256,13 +275,18 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
|
|
|
256
275
|
//
|
|
257
276
|
|
|
258
277
|
@ReactMethod
|
|
259
|
-
fun deriveUnifiedAddress(alias: String, promise: Promise)
|
|
278
|
+
fun deriveUnifiedAddress(alias: String, promise: Promise) {
|
|
260
279
|
val wallet = getWallet(alias)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
280
|
+
wallet.coroutineScope.launch {
|
|
281
|
+
var unifiedAddress = wallet.coroutineScope.async { wallet.getUnifiedAddress(Account(0)) }.await()
|
|
282
|
+
val saplingAddress = wallet.coroutineScope.async { wallet.getSaplingAddress(Account(0)) }.await()
|
|
283
|
+
val transparentAddress = wallet.coroutineScope.async { wallet.getTransparentAddress(Account(0)) }.await()
|
|
284
|
+
|
|
285
|
+
val map = Arguments.createMap()
|
|
286
|
+
map.putString("unifiedAddress", unifiedAddress)
|
|
287
|
+
map.putString("saplingAddress", saplingAddress)
|
|
288
|
+
map.putString("transparentAddress", transparentAddress)
|
|
289
|
+
promise.resolve(map)
|
|
266
290
|
}
|
|
267
291
|
}
|
|
268
292
|
|
package/ios/RNZcash.swift
CHANGED
|
@@ -11,7 +11,7 @@ struct ConfirmedTx {
|
|
|
11
11
|
var rawTransactionId: String
|
|
12
12
|
var blockTimeInSeconds: Int
|
|
13
13
|
var value: String
|
|
14
|
-
var
|
|
14
|
+
var memos: Array<String>?
|
|
15
15
|
var dictionary: [String: Any?] {
|
|
16
16
|
return [
|
|
17
17
|
"minedHeight": minedHeight,
|
|
@@ -19,7 +19,7 @@ struct ConfirmedTx {
|
|
|
19
19
|
"rawTransactionId": rawTransactionId,
|
|
20
20
|
"blockTimeInSeconds": blockTimeInSeconds,
|
|
21
21
|
"value": value,
|
|
22
|
-
"
|
|
22
|
+
"memos": memos ?? [],
|
|
23
23
|
]
|
|
24
24
|
}
|
|
25
25
|
var nsDictionary: NSDictionary {
|
|
@@ -278,13 +278,9 @@ class RNZcash: RCTEventEmitter {
|
|
|
278
278
|
if tx.memoCount > 0 {
|
|
279
279
|
let memos = (try? await wallet.synchronizer.getMemos(for: tx)) ?? []
|
|
280
280
|
let textMemos = memos.compactMap {
|
|
281
|
-
|
|
282
|
-
return memo.string
|
|
283
|
-
} else {
|
|
284
|
-
return nil
|
|
285
|
-
}
|
|
281
|
+
return $0.toString()
|
|
286
282
|
}
|
|
287
|
-
confTx.
|
|
283
|
+
confTx.memos = textMemos
|
|
288
284
|
}
|
|
289
285
|
out.append(confTx.nsDictionary)
|
|
290
286
|
}
|
|
@@ -409,7 +405,14 @@ class RNZcash: RCTEventEmitter {
|
|
|
409
405
|
if let wallet = SynchronizerMap[alias] {
|
|
410
406
|
do {
|
|
411
407
|
let unifiedAddress = try await wallet.synchronizer.getUnifiedAddress(accountIndex: 0)
|
|
412
|
-
|
|
408
|
+
let saplingAddress = try await wallet.synchronizer.getSaplingAddress(accountIndex: 0)
|
|
409
|
+
let transparentAddress = try await wallet.synchronizer.getTransparentAddress(accountIndex: 0)
|
|
410
|
+
let addresses: NSDictionary = [
|
|
411
|
+
"unifiedAddress": unifiedAddress.stringEncoded,
|
|
412
|
+
"saplingAddress": saplingAddress.stringEncoded,
|
|
413
|
+
"transparentAddress": transparentAddress.stringEncoded
|
|
414
|
+
]
|
|
415
|
+
resolve(addresses)
|
|
413
416
|
return
|
|
414
417
|
} catch {
|
|
415
418
|
reject("deriveUnifiedAddress", "Failed to derive unified address", error)
|
package/lib/rnzcash.rn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rnzcash.rn.js","sources":["../src/react-native.ts"],"sourcesContent":["import {\n EventSubscription,\n NativeEventEmitter,\n NativeModules\n} from 'react-native'\n\nimport {\n BlockRange,\n ConfirmedTransaction,\n InitializerConfig,\n Network,\n SpendFailure,\n SpendInfo,\n SpendSuccess,\n SynchronizerCallbacks,\n UnifiedViewingKey,\n WalletBalance\n} from './types'\n\nconst { RNZcash } = NativeModules\n\ntype Callback = (...args: any[]) => any\n\nexport const Tools = {\n deriveViewingKey: async (\n seedBytesHex: string,\n network: Network\n ): Promise<UnifiedViewingKey> => {\n const result = await RNZcash.deriveViewingKey(seedBytesHex, network)\n return result\n },\n getBirthdayHeight: async (host: string, port: number): Promise<number> => {\n const result = await RNZcash.getBirthdayHeight(host, port)\n return result\n },\n isValidAddress: async (\n address: string,\n network: Network = 'mainnet'\n ): Promise<boolean> => {\n const result = await RNZcash.isValidAddress(address, network)\n return result\n }\n}\n\nexport class Synchronizer {\n eventEmitter: NativeEventEmitter\n subscriptions: EventSubscription[]\n alias: string\n network: Network\n\n constructor(alias: string, network: Network) {\n this.eventEmitter = new NativeEventEmitter(RNZcash)\n this.subscriptions = []\n this.alias = alias\n this.network = network\n }\n\n async stop(): Promise<String> {\n this.unsubscribe()\n const result = await RNZcash.stop(this.alias)\n return result\n }\n\n async initialize(initializerConfig: InitializerConfig): Promise<void> {\n await RNZcash.initialize(\n initializerConfig.mnemonicSeed,\n initializerConfig.birthdayHeight,\n initializerConfig.alias,\n initializerConfig.networkName,\n initializerConfig.defaultHost,\n initializerConfig.defaultPort\n )\n }\n\n async deriveUnifiedAddress(): Promise<
|
|
1
|
+
{"version":3,"file":"rnzcash.rn.js","sources":["../src/react-native.ts"],"sourcesContent":["import {\n EventSubscription,\n NativeEventEmitter,\n NativeModules\n} from 'react-native'\n\nimport {\n Addresses,\n BlockRange,\n ConfirmedTransaction,\n InitializerConfig,\n Network,\n SpendFailure,\n SpendInfo,\n SpendSuccess,\n SynchronizerCallbacks,\n UnifiedViewingKey,\n WalletBalance\n} from './types'\n\nconst { RNZcash } = NativeModules\n\ntype Callback = (...args: any[]) => any\n\nexport const Tools = {\n deriveViewingKey: async (\n seedBytesHex: string,\n network: Network\n ): Promise<UnifiedViewingKey> => {\n const result = await RNZcash.deriveViewingKey(seedBytesHex, network)\n return result\n },\n getBirthdayHeight: async (host: string, port: number): Promise<number> => {\n const result = await RNZcash.getBirthdayHeight(host, port)\n return result\n },\n isValidAddress: async (\n address: string,\n network: Network = 'mainnet'\n ): Promise<boolean> => {\n const result = await RNZcash.isValidAddress(address, network)\n return result\n }\n}\n\nexport class Synchronizer {\n eventEmitter: NativeEventEmitter\n subscriptions: EventSubscription[]\n alias: string\n network: Network\n\n constructor(alias: string, network: Network) {\n this.eventEmitter = new NativeEventEmitter(RNZcash)\n this.subscriptions = []\n this.alias = alias\n this.network = network\n }\n\n async stop(): Promise<String> {\n this.unsubscribe()\n const result = await RNZcash.stop(this.alias)\n return result\n }\n\n async initialize(initializerConfig: InitializerConfig): Promise<void> {\n await RNZcash.initialize(\n initializerConfig.mnemonicSeed,\n initializerConfig.birthdayHeight,\n initializerConfig.alias,\n initializerConfig.networkName,\n initializerConfig.defaultHost,\n initializerConfig.defaultPort\n )\n }\n\n async deriveUnifiedAddress(): Promise<Addresses> {\n const result = await RNZcash.deriveUnifiedAddress(this.alias)\n return result\n }\n\n async getLatestNetworkHeight(alias: string): Promise<number> {\n const result = await RNZcash.getLatestNetworkHeight(alias)\n return result\n }\n\n async getBalance(): Promise<WalletBalance> {\n const result = await RNZcash.getBalance(this.alias)\n return result\n }\n\n async getTransactions(range: BlockRange): Promise<ConfirmedTransaction[]> {\n const result = await RNZcash.getTransactions(\n this.alias,\n range.first,\n range.last\n )\n return result\n }\n\n rescan(): void {\n RNZcash.rescan(this.alias)\n }\n\n async sendToAddress(\n spendInfo: SpendInfo\n ): Promise<SpendSuccess | SpendFailure> {\n const result = await RNZcash.sendToAddress(\n this.alias,\n spendInfo.zatoshi,\n spendInfo.toAddress,\n spendInfo.memo,\n spendInfo.mnemonicSeed\n )\n return result\n }\n\n // Events\n\n subscribe({ onStatusChanged, onUpdate }: SynchronizerCallbacks): void {\n this.setListener('StatusEvent', onStatusChanged)\n this.setListener('UpdateEvent', onUpdate)\n }\n\n private setListener<T>(\n eventName: string,\n callback: Callback = (t: any) => null\n ): void {\n this.subscriptions.push(\n this.eventEmitter.addListener(eventName, arg =>\n arg.alias === this.alias ? callback(arg) : null\n )\n )\n }\n\n unsubscribe(): void {\n this.subscriptions.forEach(subscription => {\n subscription.remove()\n })\n }\n}\n\nexport const makeSynchronizer = async (\n initializerConfig: InitializerConfig\n): Promise<Synchronizer> => {\n const synchronizer = new Synchronizer(\n initializerConfig.alias,\n initializerConfig.networkName\n )\n await synchronizer.initialize(initializerConfig)\n return synchronizer\n}\n"],"names":["RNZcash","NativeModules","Tools","deriveViewingKey","seedBytesHex","network","result","getBirthdayHeight","host","port","isValidAddress","address","Synchronizer","alias","eventEmitter","NativeEventEmitter","subscriptions","stop","unsubscribe","initialize","initializerConfig","mnemonicSeed","birthdayHeight","networkName","defaultHost","defaultPort","deriveUnifiedAddress","getLatestNetworkHeight","getBalance","getTransactions","range","first","last","rescan","sendToAddress","spendInfo","zatoshi","toAddress","memo","subscribe","onStatusChanged","onUpdate","setListener","eventName","callback","t","push","addListener","arg","forEach","subscription","remove","makeSynchronizer","synchronizer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ADC,EAEnBO,iBAAiB,CAACG,WAFC,CAArB;AAIA,UAAM8B,YAAY,CAAClC,UAAb,CAAwBC,iBAAxB,CAAN;AACA,WAAOiC,YAAP;AACD,GAT4B;;AAAA,kBAAhBD,gBAAgB;AAAA;AAAA;AAAA;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventSubscription, NativeEventEmitter } from 'react-native';
|
|
2
|
-
import { BlockRange, ConfirmedTransaction, InitializerConfig, Network, SpendFailure, SpendInfo, SpendSuccess, SynchronizerCallbacks, UnifiedViewingKey, WalletBalance } from './types';
|
|
2
|
+
import { Addresses, BlockRange, ConfirmedTransaction, InitializerConfig, Network, SpendFailure, SpendInfo, SpendSuccess, SynchronizerCallbacks, UnifiedViewingKey, WalletBalance } from './types';
|
|
3
3
|
export declare const Tools: {
|
|
4
4
|
deriveViewingKey: (seedBytesHex: string, network: Network) => Promise<UnifiedViewingKey>;
|
|
5
5
|
getBirthdayHeight: (host: string, port: number) => Promise<number>;
|
|
@@ -13,7 +13,7 @@ export declare class Synchronizer {
|
|
|
13
13
|
constructor(alias: string, network: Network);
|
|
14
14
|
stop(): Promise<String>;
|
|
15
15
|
initialize(initializerConfig: InitializerConfig): Promise<void>;
|
|
16
|
-
deriveUnifiedAddress(): Promise<
|
|
16
|
+
deriveUnifiedAddress(): Promise<Addresses>;
|
|
17
17
|
getLatestNetworkHeight(alias: string): Promise<number>;
|
|
18
18
|
getBalance(): Promise<WalletBalance>;
|
|
19
19
|
getTransactions(range: BlockRange): Promise<ConfirmedTransaction[]>;
|
package/lib/src/types.d.ts
CHANGED
|
@@ -60,5 +60,10 @@ export interface ConfirmedTransaction {
|
|
|
60
60
|
minedHeight: number;
|
|
61
61
|
value: string;
|
|
62
62
|
toAddress?: string;
|
|
63
|
-
|
|
63
|
+
memos: string[];
|
|
64
|
+
}
|
|
65
|
+
export interface Addresses {
|
|
66
|
+
unifiedAddress: string;
|
|
67
|
+
saplingAddress: string;
|
|
68
|
+
transparentAddress: string;
|
|
64
69
|
}
|
package/package.json
CHANGED
package/src/react-native.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
} from 'react-native'
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
Addresses,
|
|
8
9
|
BlockRange,
|
|
9
10
|
ConfirmedTransaction,
|
|
10
11
|
InitializerConfig,
|
|
@@ -72,7 +73,7 @@ export class Synchronizer {
|
|
|
72
73
|
)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
async deriveUnifiedAddress(): Promise<
|
|
76
|
+
async deriveUnifiedAddress(): Promise<Addresses> {
|
|
76
77
|
const result = await RNZcash.deriveUnifiedAddress(this.alias)
|
|
77
78
|
return result
|
|
78
79
|
}
|
package/src/types.ts
CHANGED
|
@@ -79,5 +79,11 @@ export interface ConfirmedTransaction {
|
|
|
79
79
|
minedHeight: number
|
|
80
80
|
value: string
|
|
81
81
|
toAddress?: string
|
|
82
|
-
|
|
82
|
+
memos: string[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface Addresses {
|
|
86
|
+
unifiedAddress: string
|
|
87
|
+
saplingAddress: string
|
|
88
|
+
transparentAddress: string
|
|
83
89
|
}
|