react-native-zcash 0.8.1 → 0.9.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/android/build.gradle +3 -3
  3. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2650000.json +8 -0
  4. package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +15 -25
  5. package/ios/RNZcash.m +3 -5
  6. package/ios/RNZcash.swift +42 -23
  7. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +1 -0
  8. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +1 -1
  9. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +1 -1
  10. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +1 -1
  11. package/ios/ZCashLightClientKit/Block/Actions/TxResubmissionAction.swift +75 -0
  12. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +1 -1
  13. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +3 -1
  14. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +14 -0
  15. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  16. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +54 -49
  17. package/ios/ZCashLightClientKit/Checkpoint/BundleCheckpointSource.swift +1 -6
  18. package/ios/ZCashLightClientKit/Checkpoint/CheckpointSourceFactory.swift +1 -1
  19. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +3 -1
  20. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +6 -2
  21. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +15 -0
  22. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +20 -4
  23. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +27 -24
  24. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +2 -2
  25. package/ios/ZCashLightClientKit/Error/ZcashError.swift +32 -1
  26. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +11 -1
  27. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +18 -0
  28. package/ios/ZCashLightClientKit/Initializer.swift +22 -14
  29. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -1
  30. package/ios/ZCashLightClientKit/Model/FiatCurrencyResult.swift +25 -0
  31. package/ios/ZCashLightClientKit/Model/Proposal.swift +1 -1
  32. package/ios/ZCashLightClientKit/Model/TransactionDataRequest.swift +26 -0
  33. package/ios/ZCashLightClientKit/Model/WalletTypes.swift +39 -1
  34. package/ios/ZCashLightClientKit/Model/Zatoshi.swift +1 -1
  35. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +39 -2
  36. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +5 -4
  37. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +819 -3
  38. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +2 -2
  39. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +3 -1
  40. package/ios/ZCashLightClientKit/Providers/ResourceProvider.swift +10 -0
  41. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +4 -0
  42. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2475000.json +8 -0
  43. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2477500.json +8 -0
  44. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2482500.json +8 -0
  45. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2485000.json +8 -0
  46. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2487500.json +8 -0
  47. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2492500.json +8 -0
  48. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2495000.json +8 -0
  49. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2497500.json +8 -0
  50. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2502500.json +8 -0
  51. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2505000.json +8 -0
  52. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2507500.json +8 -0
  53. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2512500.json +8 -0
  54. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2515000.json +8 -0
  55. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2517500.json +8 -0
  56. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2522500.json +8 -0
  57. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2525000.json +8 -0
  58. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2527500.json +8 -0
  59. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2532500.json +8 -0
  60. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2535000.json +8 -0
  61. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2537500.json +8 -0
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2542500.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2545000.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2547500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2552500.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2555000.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2557500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2562500.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2565000.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2567500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2572500.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2575000.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2577500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2582500.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2585000.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2587500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2592500.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2595000.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2597500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2602500.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2605000.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2607500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2612500.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2615000.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2617500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2622500.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2625000.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2627500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2632500.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2635000.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2637500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2642500.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2645000.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2647500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2650000.json +8 -0
  96. package/ios/ZCashLightClientKit/Rust/ZcashKeyDerivationBackend.swift +4 -24
  97. package/ios/ZCashLightClientKit/Rust/ZcashKeyDerivationBackendWelding.swift +0 -15
  98. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +133 -32
  99. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +18 -1
  100. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +4 -0
  101. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +5 -1
  102. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +53 -3
  103. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +236 -7
  104. package/ios/ZCashLightClientKit/Synchronizer.swift +28 -0
  105. package/ios/ZCashLightClientKit/Tool/DerivationTool.swift +29 -5
  106. package/ios/ZCashLightClientKit/Tor/TorClient.swift +57 -0
  107. package/ios/ZCashLightClientKit/Utils/LoggingProxy.swift +4 -0
  108. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +4 -0
  109. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  110. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  111. package/ios/zcashlc.h +287 -42
  112. package/lib/rnzcash.rn.js +8 -8
  113. package/lib/rnzcash.rn.js.map +1 -1
  114. package/lib/src/react-native.d.ts +3 -3
  115. package/lib/src/types.d.ts +4 -2
  116. package/package.json +1 -1
  117. package/src/react-native.ts +13 -18
  118. package/src/types.ts +5 -2
@@ -89,13 +89,15 @@ public enum AddressType: Equatable {
89
89
  case p2sh
90
90
  case sapling
91
91
  case unified
92
-
92
+ case tex
93
+
93
94
  var id: UInt32 {
94
95
  switch self {
95
96
  case .p2pkh: return 0
96
97
  case .p2sh: return 1
97
98
  case .sapling: return 2
98
99
  case .unified: return 3
100
+ case .tex: return 4
99
101
  }
100
102
  }
101
103
  }
@@ -107,6 +109,7 @@ extension AddressType {
107
109
  case 1: return .p2sh
108
110
  case 2: return .sapling
109
111
  case 3: return .unified
112
+ case 4: return .tex
110
113
  default: return nil
111
114
  }
112
115
  }
@@ -213,6 +216,35 @@ public struct UnifiedAddress: Equatable, StringEncoded {
213
216
  }
214
217
  }
215
218
 
219
+ /// A transparent-source-only (TEX) Address that can be encoded as a String
220
+ ///
221
+ /// Transactions sent to this address are totally visible in the public
222
+ /// ledger. See "Multiple transaction types" in https://z.cash/technology/
223
+ ///
224
+ /// Transactions sent to this address must only have transparent inputs. See ZIP 320: https://zips.z.cash/zip-0320
225
+ public struct TexAddress: Equatable, StringEncoded, Comparable {
226
+ let encoding: String
227
+
228
+ public var stringEncoded: String { encoding }
229
+
230
+ /// Initializes a new TexAddress from the provided string encoding
231
+ ///
232
+ /// - parameter encoding: String encoding of the TEX address
233
+ /// - parameter network: `NetworkType` corresponding to the encoding (Mainnet or Testnet)
234
+ /// - Throws: `texAddressInvalidInput`when the provided encoding is found to be invalid
235
+ public init(encoding: String, network: NetworkType) throws {
236
+ guard DerivationTool(networkType: network).isValidTexAddress(encoding) else {
237
+ throw ZcashError.texAddressInvalidInput
238
+ }
239
+
240
+ self.encoding = encoding
241
+ }
242
+
243
+ public static func < (lhs: TexAddress, rhs: TexAddress) -> Bool {
244
+ return lhs.encoding < rhs.encoding
245
+ }
246
+ }
247
+
216
248
  public enum TransactionRecipient: Equatable {
217
249
  case address(Recipient)
218
250
  case internalAccount(UInt32)
@@ -223,6 +255,7 @@ public enum Recipient: Equatable, StringEncoded {
223
255
  case transparent(TransparentAddress)
224
256
  case sapling(SaplingAddress)
225
257
  case unified(UnifiedAddress)
258
+ case tex(TexAddress)
226
259
 
227
260
  public var stringEncoded: String {
228
261
  switch self {
@@ -232,6 +265,8 @@ public enum Recipient: Equatable, StringEncoded {
232
265
  return zAddr.stringEncoded
233
266
  case .unified(let uAddr):
234
267
  return uAddr.stringEncoded
268
+ case .tex(let texAddr):
269
+ return texAddr.stringEncoded
235
270
  }
236
271
  }
237
272
 
@@ -246,6 +281,8 @@ public enum Recipient: Equatable, StringEncoded {
246
281
  self = .sapling(sapling)
247
282
  } else if let transparent = try? TransparentAddress(encoding: string, network: network) {
248
283
  self = .transparent(transparent)
284
+ } else if let tex = try? TexAddress(encoding: string, network: network) {
285
+ self = .tex(tex)
249
286
  } else {
250
287
  throw ZcashError.recipientInvalidInput
251
288
  }
@@ -259,6 +296,7 @@ public enum Recipient: Equatable, StringEncoded {
259
296
  case .p2sh: return (.transparent(TransparentAddress(validatedEncoding: encoded)), metadata.networkType)
260
297
  case .sapling: return (.sapling(SaplingAddress(validatedEncoding: encoded)), metadata.networkType)
261
298
  case .unified: return (.unified(UnifiedAddress(validatedEncoding: encoded, networkType: metadata.networkType)), metadata.networkType)
299
+ case .tex: return (.tex(TexAddress(validatedEncoding: encoded)), metadata.networkType)
262
300
  }
263
301
  }
264
302
  }
@@ -42,7 +42,7 @@ public struct Zatoshi {
42
42
  }
43
43
 
44
44
  /// Converts `Decimal` to `Zatoshi`
45
- public static func from(decimal: Decimal) -> Zatoshi {
45
+ public static func from(decimal: Foundation.Decimal) -> Zatoshi {
46
46
  let roundedZec = NSDecimalNumber(decimal: decimal).roundedZec
47
47
  let zec2zatoshi = Decimal(Constants.oneZecInZatoshi) * roundedZec.decimalValue
48
48
  return Zatoshi(NSDecimalNumber(decimal: zec2zatoshi).int64Value)
@@ -187,13 +187,35 @@ extension LightWalletGRPCService: LightWalletService {
187
187
  }
188
188
  }
189
189
 
190
- func fetchTransaction(txId: Data) async throws -> ZcashTransaction.Fetched {
190
+ func fetchTransaction(txId: Data) async throws -> (tx: ZcashTransaction.Fetched?, status: TransactionStatus) {
191
191
  var txFilter = TxFilter()
192
192
  txFilter.hash = txId
193
193
 
194
194
  do {
195
195
  let rawTx = try await compactTxStreamer.getTransaction(txFilter)
196
- return ZcashTransaction.Fetched(rawID: txId, minedHeight: BlockHeight(rawTx.height), raw: rawTx.data)
196
+
197
+ let isNotMined = rawTx.height == 0 || rawTx.height > UInt32.max
198
+
199
+ return (
200
+ tx:
201
+ ZcashTransaction.Fetched(
202
+ rawID: txId,
203
+ minedHeight: isNotMined ? nil : UInt32(rawTx.height),
204
+ raw: rawTx.data
205
+ ),
206
+ status: isNotMined ? .notInMainChain : .mined(Int(rawTx.height))
207
+ )
208
+ } catch let error as GRPCStatus {
209
+ if error.makeGRPCStatus().code == .notFound {
210
+ return (tx: nil, .txidNotRecognized)
211
+ } else if let notFound = error.message?.contains("Transaction not found"), notFound {
212
+ return (tx: nil, .txidNotRecognized)
213
+ } else if let notFound = error.message?.contains("No such mempool or blockchain transaction. Use gettransaction for wallet transactions."), notFound {
214
+ return (tx: nil, .txidNotRecognized)
215
+ } else {
216
+ let serviceError = error.mapToServiceError()
217
+ throw ZcashError.serviceFetchTransactionFailed(serviceError)
218
+ }
197
219
  } catch {
198
220
  let serviceError = error.mapToServiceError()
199
221
  throw ZcashError.serviceFetchTransactionFailed(serviceError)
@@ -280,6 +302,21 @@ extension LightWalletGRPCService: LightWalletService {
280
302
  try await compactTxStreamer.getTreeState(id)
281
303
  }
282
304
 
305
+ func getTaddressTxids(_ request: TransparentAddressBlockFilter) -> AsyncThrowingStream<RawTransaction, Error> {
306
+ let stream = compactTxStreamer.getTaddressTxids(request)
307
+ var iterator = stream.makeAsyncIterator()
308
+
309
+ return AsyncThrowingStream() {
310
+ do {
311
+ guard let rawTransaction = try await iterator.next() else { return nil }
312
+ return rawTransaction
313
+ } catch {
314
+ let serviceError = error.mapToServiceError()
315
+ throw ZcashError.serviceGetTaddressTxidsFailed(serviceError)
316
+ }
317
+ }
318
+ }
319
+
283
320
  func closeConnection() {
284
321
  _ = channel.close()
285
322
  }
@@ -31,7 +31,7 @@ message TxFilter {
31
31
  bytes hash = 3; // transaction ID (hash, txid)
32
32
  }
33
33
 
34
- // RawTransaction contains the complete transaction data. It also optionally includes
34
+ // RawTransaction contains the complete transaction data. It also optionally includes
35
35
  // the block height in which the transaction was included, or, when returned
36
36
  // by GetMempoolStream(), the latest block height.
37
37
  message RawTransaction {
@@ -170,7 +170,8 @@ service CompactTxStreamer {
170
170
  // Submit the given transaction to the Zcash network
171
171
  rpc SendTransaction(RawTransaction) returns (SendResponse) {}
172
172
 
173
- // Return the txids corresponding to the given t-address within the given block range
173
+ // Return the transactions corresponding to the given t-address within the given block range
174
+ // NB - this method is misnamed, it returns transactions, not transaction IDs.
174
175
  rpc GetTaddressTxids(TransparentAddressBlockFilter) returns (stream RawTransaction) {}
175
176
  rpc GetTaddressBalance(AddressList) returns (Balance) {}
176
177
  rpc GetTaddressBalanceStream(stream Address) returns (Balance) {}
@@ -197,8 +198,8 @@ service CompactTxStreamer {
197
198
  rpc GetTreeState(BlockID) returns (TreeState) {}
198
199
  rpc GetLatestTreeState(Empty) returns (TreeState) {}
199
200
 
200
- // Returns a stream of information about roots of subtrees of the Sapling and Orchard
201
- // note commitment trees.
201
+ // Returns a stream of information about roots of subtrees of the note commitment tree
202
+ // for the specified shielded protocol (Sapling or Orchard).
202
203
  rpc GetSubtreeRoots(GetSubtreeRootsArg) returns (stream SubtreeRoot) {}
203
204
 
204
205
  rpc GetAddressUtxos(GetAddressUtxosArg) returns (GetAddressUtxosReplyList) {}