react-native-zcash 0.5.0 → 0.6.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 (156) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +6 -3
  3. package/android/build.gradle +5 -4
  4. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2240000.json +8 -0
  5. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2250000.json +8 -0
  6. package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +94 -121
  7. package/ios/RNZcash.m +1 -12
  8. package/ios/RNZcash.swift +119 -152
  9. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +98 -0
  10. package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +35 -0
  11. package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +30 -0
  12. package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +67 -0
  13. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +97 -0
  14. package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +33 -0
  15. package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +70 -0
  16. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +59 -0
  17. package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +48 -0
  18. package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +33 -0
  19. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +95 -0
  20. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +55 -0
  21. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +58 -0
  22. package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +60 -0
  23. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +421 -937
  24. package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +31 -17
  25. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  26. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +46 -15
  27. package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +4 -15
  28. package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
  29. package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +10 -35
  30. package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +24 -0
  31. package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +25 -0
  32. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +1 -2
  33. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +2 -5
  34. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +7 -25
  35. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +40 -42
  36. package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +13 -4
  37. package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +9 -0
  38. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +7 -10
  39. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
  40. package/ios/ZCashLightClientKit/Error/ZcashError.swift +121 -12
  41. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +43 -5
  42. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +72 -6
  43. package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +15 -0
  44. package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +18 -0
  45. package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +15 -0
  46. package/ios/ZCashLightClientKit/Initializer.swift +47 -26
  47. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -12
  48. package/ios/ZCashLightClientKit/Model/Checkpoint.swift +12 -0
  49. package/ios/ZCashLightClientKit/Model/ScanProgress.swift +29 -0
  50. package/ios/ZCashLightClientKit/Model/ScanRange.swift +31 -0
  51. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +15 -0
  52. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +150 -46
  53. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +30 -16
  54. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +32 -6
  55. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +259 -22
  56. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +193 -7
  57. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +8 -0
  58. package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +18 -28
  59. package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
  60. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +2 -6
  61. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +8 -0
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +8 -0
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +8 -0
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +8 -0
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +8 -0
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +8 -0
  100. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +8 -0
  101. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +8 -0
  102. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +8 -0
  103. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2230000.json +8 -0
  104. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +8 -0
  105. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +8 -0
  106. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +8 -0
  107. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2240000.json +8 -0
  108. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +8 -0
  109. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +8 -0
  110. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +8 -0
  111. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2250000.json +8 -0
  112. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +8 -0
  113. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +8 -0
  114. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +8 -0
  115. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +8 -0
  116. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +8 -0
  117. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +8 -0
  118. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +8 -0
  119. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +8 -0
  120. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +8 -0
  121. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +8 -0
  122. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +8 -0
  123. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +8 -0
  124. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +8 -0
  125. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +8 -0
  126. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +8 -0
  127. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +8 -0
  128. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +8 -0
  129. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +8 -0
  130. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +8 -0
  131. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +293 -158
  132. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +58 -64
  133. package/ios/ZCashLightClientKit/Rust/zcashlc.h +618 -512
  134. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +2 -8
  135. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +3 -15
  136. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +11 -30
  137. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +41 -50
  138. package/ios/ZCashLightClientKit/Synchronizer.swift +51 -65
  139. package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
  140. package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
  141. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
  142. package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +16 -0
  143. package/ios/libzcashlc.xcframework/Info.plist +9 -5
  144. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  145. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  146. package/lib/rnzcash.rn.js +8 -30
  147. package/lib/rnzcash.rn.js.map +1 -1
  148. package/lib/src/react-native.d.ts +2 -4
  149. package/lib/src/types.d.ts +14 -14
  150. package/package.json +1 -1
  151. package/src/react-native.ts +11 -20
  152. package/src/types.ts +20 -23
  153. package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +0 -200
  154. package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +0 -51
  155. package/ios/ZCashLightClientKit/DAO/BlockDao.swift +0 -112
  156. package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +0 -24
@@ -7,7 +7,7 @@
7
7
  // For information on using the generated types, please see the documentation:
8
8
  // https://github.com/apple/swift-protobuf/
9
9
 
10
- // Copyright (c) 2019-2020 The Zcash developers
10
+ // Copyright (c) 2019-2021 The Zcash developers
11
11
  // Distributed under the MIT software license, see the accompanying
12
12
  // file COPYING or https://www.opensource.org/licenses/mit-license.php .
13
13
 
@@ -24,6 +24,23 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP
24
24
  typealias Version = _2
25
25
  }
26
26
 
27
+ /// ChainMetadata represents information about the state of the chain as of a given block.
28
+ struct ChainMetadata {
29
+ // SwiftProtobuf.Message conformance is added in an extension below. See the
30
+ // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
31
+ // methods supported on all messages.
32
+
33
+ /// the size of the Sapling note commitment tree as of the end of this block
34
+ var saplingCommitmentTreeSize: UInt32 = 0
35
+
36
+ /// the size of the Orchard note commitment tree as of the end of this block
37
+ var orchardCommitmentTreeSize: UInt32 = 0
38
+
39
+ var unknownFields = SwiftProtobuf.UnknownStorage()
40
+
41
+ init() {}
42
+ }
43
+
27
44
  /// CompactBlock is a packaging of ONLY the data from a block that's needed to:
28
45
  /// 1. Detect a payment to your shielded Sapling address
29
46
  /// 2. Detect a spend of your shielded Sapling notes
@@ -40,23 +57,35 @@ struct CompactBlock {
40
57
  var height: UInt64 = 0
41
58
 
42
59
  /// the ID (hash) of this block, same as in block explorers
43
- var hash: Data = SwiftProtobuf.Internal.emptyData
60
+ var hash: Data = Data()
44
61
 
45
62
  /// the ID (hash) of this block's predecessor
46
- var prevHash: Data = SwiftProtobuf.Internal.emptyData
63
+ var prevHash: Data = Data()
47
64
 
48
65
  /// Unix epoch time when the block was mined
49
66
  var time: UInt32 = 0
50
67
 
51
68
  /// (hash, prevHash, and time) OR (full header)
52
- var header: Data = SwiftProtobuf.Internal.emptyData
69
+ var header: Data = Data()
53
70
 
54
71
  /// zero or more compact transactions from this block
55
72
  var vtx: [CompactTx] = []
56
73
 
74
+ /// information about the state of the chain as of this block
75
+ var chainMetadata: ChainMetadata {
76
+ get {return _chainMetadata ?? ChainMetadata()}
77
+ set {_chainMetadata = newValue}
78
+ }
79
+ /// Returns true if `chainMetadata` has been explicitly set.
80
+ var hasChainMetadata: Bool {return self._chainMetadata != nil}
81
+ /// Clears the value of `chainMetadata`. Subsequent reads from it will return its default value.
82
+ mutating func clearChainMetadata() {self._chainMetadata = nil}
83
+
57
84
  var unknownFields = SwiftProtobuf.UnknownStorage()
58
85
 
59
86
  init() {}
87
+
88
+ fileprivate var _chainMetadata: ChainMetadata? = nil
60
89
  }
61
90
 
62
91
  /// CompactTx contains the minimum information for a wallet to know if this transaction
@@ -67,23 +96,23 @@ struct CompactTx {
67
96
  // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
68
97
  // methods supported on all messages.
69
98
 
70
- /// the index within the full block
99
+ /// Index and hash will allow the receiver to call out to chain
100
+ /// explorers or other data structures to retrieve more information
101
+ /// about this transaction.
71
102
  var index: UInt64 = 0
72
103
 
73
104
  /// the ID (hash) of this transaction, same as in block explorers
74
- var hash: Data = SwiftProtobuf.Internal.emptyData
105
+ var hash: Data = Data()
75
106
 
76
107
  /// The transaction fee: present if server can provide. In the case of a
77
108
  /// stateless server and a transaction with transparent inputs, this will be
78
109
  /// unset because the calculation requires reference to prior transactions.
79
- /// in a pure-Sapling context, the fee will be calculable as:
80
- /// valueBalance + (sum(vPubNew) - sum(vPubOld) - sum(tOut))
110
+ /// If there are no transparent inputs, the fee will be calculable as:
111
+ /// valueBalanceSapling + valueBalanceOrchard + sum(vPubNew) - sum(vPubOld) - sum(tOut)
81
112
  var fee: UInt32 = 0
82
113
 
83
- /// inputs
84
114
  var spends: [CompactSaplingSpend] = []
85
115
 
86
- /// outputs
87
116
  var outputs: [CompactSaplingOutput] = []
88
117
 
89
118
  var actions: [CompactOrchardAction] = []
@@ -101,28 +130,31 @@ struct CompactSaplingSpend {
101
130
  // methods supported on all messages.
102
131
 
103
132
  /// nullifier (see the Zcash protocol specification)
104
- var nf: Data = SwiftProtobuf.Internal.emptyData
133
+ var nf: Data = Data()
105
134
 
106
135
  var unknownFields = SwiftProtobuf.UnknownStorage()
107
136
 
108
137
  init() {}
109
138
  }
110
139
 
111
- /// output is a Sapling Output Description as described in section 7.4 of the
112
- /// Zcash protocol spec. Total size is 948.
140
+ /// output encodes the `cmu` field, `ephemeralKey` field, and a 52-byte prefix of the
141
+ /// `encCiphertext` field of a Sapling Output Description. These fields are described in
142
+ /// section 7.4 of the Zcash protocol spec:
143
+ /// https://zips.z.cash/protocol/protocol.pdf#outputencodingandconsensus
144
+ /// Total size is 116 bytes.
113
145
  struct CompactSaplingOutput {
114
146
  // SwiftProtobuf.Message conformance is added in an extension below. See the
115
147
  // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
116
148
  // methods supported on all messages.
117
149
 
118
150
  /// note commitment u-coordinate
119
- var cmu: Data = SwiftProtobuf.Internal.emptyData
151
+ var cmu: Data = Data()
120
152
 
121
153
  /// ephemeral public key
122
- var epk: Data = SwiftProtobuf.Internal.emptyData
154
+ var ephemeralKey: Data = Data()
123
155
 
124
156
  /// first 52 bytes of ciphertext
125
- var ciphertext: Data = SwiftProtobuf.Internal.emptyData
157
+ var ciphertext: Data = Data()
126
158
 
127
159
  var unknownFields = SwiftProtobuf.UnknownStorage()
128
160
 
@@ -137,26 +169,73 @@ struct CompactOrchardAction {
137
169
  // methods supported on all messages.
138
170
 
139
171
  /// [32] The nullifier of the input note
140
- var nullifier: Data = SwiftProtobuf.Internal.emptyData
172
+ var nullifier: Data = Data()
141
173
 
142
174
  /// [32] The x-coordinate of the note commitment for the output note
143
- var cmx: Data = SwiftProtobuf.Internal.emptyData
175
+ var cmx: Data = Data()
144
176
 
145
177
  /// [32] An encoding of an ephemeral Pallas public key
146
- var ephemeralKey: Data = SwiftProtobuf.Internal.emptyData
178
+ var ephemeralKey: Data = Data()
147
179
 
148
- /// [52] The note plaintext component of the encCiphertext field
149
- var ciphertext: Data = SwiftProtobuf.Internal.emptyData
180
+ /// [52] The first 52 bytes of the encCiphertext field
181
+ var ciphertext: Data = Data()
150
182
 
151
183
  var unknownFields = SwiftProtobuf.UnknownStorage()
152
184
 
153
185
  init() {}
154
186
  }
155
187
 
188
+ #if swift(>=5.5) && canImport(_Concurrency)
189
+ extension ChainMetadata: @unchecked Sendable {}
190
+ extension CompactBlock: @unchecked Sendable {}
191
+ extension CompactTx: @unchecked Sendable {}
192
+ extension CompactSaplingSpend: @unchecked Sendable {}
193
+ extension CompactSaplingOutput: @unchecked Sendable {}
194
+ extension CompactOrchardAction: @unchecked Sendable {}
195
+ #endif // swift(>=5.5) && canImport(_Concurrency)
196
+
156
197
  // MARK: - Code below here is support for the SwiftProtobuf runtime.
157
198
 
158
199
  fileprivate let _protobuf_package = "cash.z.wallet.sdk.rpc"
159
200
 
201
+ extension ChainMetadata: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
202
+ static let protoMessageName: String = _protobuf_package + ".ChainMetadata"
203
+ static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
204
+ 1: .same(proto: "saplingCommitmentTreeSize"),
205
+ 2: .same(proto: "orchardCommitmentTreeSize"),
206
+ ]
207
+
208
+ mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
209
+ while let fieldNumber = try decoder.nextFieldNumber() {
210
+ // The use of inline closures is to circumvent an issue where the compiler
211
+ // allocates stack space for every case branch when no optimizations are
212
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
213
+ switch fieldNumber {
214
+ case 1: try { try decoder.decodeSingularUInt32Field(value: &self.saplingCommitmentTreeSize) }()
215
+ case 2: try { try decoder.decodeSingularUInt32Field(value: &self.orchardCommitmentTreeSize) }()
216
+ default: break
217
+ }
218
+ }
219
+ }
220
+
221
+ func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
222
+ if self.saplingCommitmentTreeSize != 0 {
223
+ try visitor.visitSingularUInt32Field(value: self.saplingCommitmentTreeSize, fieldNumber: 1)
224
+ }
225
+ if self.orchardCommitmentTreeSize != 0 {
226
+ try visitor.visitSingularUInt32Field(value: self.orchardCommitmentTreeSize, fieldNumber: 2)
227
+ }
228
+ try unknownFields.traverse(visitor: &visitor)
229
+ }
230
+
231
+ static func ==(lhs: ChainMetadata, rhs: ChainMetadata) -> Bool {
232
+ if lhs.saplingCommitmentTreeSize != rhs.saplingCommitmentTreeSize {return false}
233
+ if lhs.orchardCommitmentTreeSize != rhs.orchardCommitmentTreeSize {return false}
234
+ if lhs.unknownFields != rhs.unknownFields {return false}
235
+ return true
236
+ }
237
+ }
238
+
160
239
  extension CompactBlock: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
161
240
  static let protoMessageName: String = _protobuf_package + ".CompactBlock"
162
241
  static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
@@ -167,24 +246,33 @@ extension CompactBlock: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat
167
246
  5: .same(proto: "time"),
168
247
  6: .same(proto: "header"),
169
248
  7: .same(proto: "vtx"),
249
+ 8: .same(proto: "chainMetadata"),
170
250
  ]
171
251
 
172
252
  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
173
253
  while let fieldNumber = try decoder.nextFieldNumber() {
254
+ // The use of inline closures is to circumvent an issue where the compiler
255
+ // allocates stack space for every case branch when no optimizations are
256
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
174
257
  switch fieldNumber {
175
- case 1: try decoder.decodeSingularUInt32Field(value: &self.protoVersion)
176
- case 2: try decoder.decodeSingularUInt64Field(value: &self.height)
177
- case 3: try decoder.decodeSingularBytesField(value: &self.hash)
178
- case 4: try decoder.decodeSingularBytesField(value: &self.prevHash)
179
- case 5: try decoder.decodeSingularUInt32Field(value: &self.time)
180
- case 6: try decoder.decodeSingularBytesField(value: &self.header)
181
- case 7: try decoder.decodeRepeatedMessageField(value: &self.vtx)
258
+ case 1: try { try decoder.decodeSingularUInt32Field(value: &self.protoVersion) }()
259
+ case 2: try { try decoder.decodeSingularUInt64Field(value: &self.height) }()
260
+ case 3: try { try decoder.decodeSingularBytesField(value: &self.hash) }()
261
+ case 4: try { try decoder.decodeSingularBytesField(value: &self.prevHash) }()
262
+ case 5: try { try decoder.decodeSingularUInt32Field(value: &self.time) }()
263
+ case 6: try { try decoder.decodeSingularBytesField(value: &self.header) }()
264
+ case 7: try { try decoder.decodeRepeatedMessageField(value: &self.vtx) }()
265
+ case 8: try { try decoder.decodeSingularMessageField(value: &self._chainMetadata) }()
182
266
  default: break
183
267
  }
184
268
  }
185
269
  }
186
270
 
187
271
  func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
272
+ // The use of inline closures is to circumvent an issue where the compiler
273
+ // allocates stack space for every if/case branch local when no optimizations
274
+ // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
275
+ // https://github.com/apple/swift-protobuf/issues/1182
188
276
  if self.protoVersion != 0 {
189
277
  try visitor.visitSingularUInt32Field(value: self.protoVersion, fieldNumber: 1)
190
278
  }
@@ -206,6 +294,9 @@ extension CompactBlock: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat
206
294
  if !self.vtx.isEmpty {
207
295
  try visitor.visitRepeatedMessageField(value: self.vtx, fieldNumber: 7)
208
296
  }
297
+ try { if let v = self._chainMetadata {
298
+ try visitor.visitSingularMessageField(value: v, fieldNumber: 8)
299
+ } }()
209
300
  try unknownFields.traverse(visitor: &visitor)
210
301
  }
211
302
 
@@ -217,6 +308,7 @@ extension CompactBlock: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat
217
308
  if lhs.time != rhs.time {return false}
218
309
  if lhs.header != rhs.header {return false}
219
310
  if lhs.vtx != rhs.vtx {return false}
311
+ if lhs._chainMetadata != rhs._chainMetadata {return false}
220
312
  if lhs.unknownFields != rhs.unknownFields {return false}
221
313
  return true
222
314
  }
@@ -235,13 +327,16 @@ extension CompactTx: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation
235
327
 
236
328
  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
237
329
  while let fieldNumber = try decoder.nextFieldNumber() {
330
+ // The use of inline closures is to circumvent an issue where the compiler
331
+ // allocates stack space for every case branch when no optimizations are
332
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
238
333
  switch fieldNumber {
239
- case 1: try decoder.decodeSingularUInt64Field(value: &self.index)
240
- case 2: try decoder.decodeSingularBytesField(value: &self.hash)
241
- case 3: try decoder.decodeSingularUInt32Field(value: &self.fee)
242
- case 4: try decoder.decodeRepeatedMessageField(value: &self.spends)
243
- case 5: try decoder.decodeRepeatedMessageField(value: &self.outputs)
244
- case 6: try decoder.decodeRepeatedMessageField(value: &self.actions)
334
+ case 1: try { try decoder.decodeSingularUInt64Field(value: &self.index) }()
335
+ case 2: try { try decoder.decodeSingularBytesField(value: &self.hash) }()
336
+ case 3: try { try decoder.decodeSingularUInt32Field(value: &self.fee) }()
337
+ case 4: try { try decoder.decodeRepeatedMessageField(value: &self.spends) }()
338
+ case 5: try { try decoder.decodeRepeatedMessageField(value: &self.outputs) }()
339
+ case 6: try { try decoder.decodeRepeatedMessageField(value: &self.actions) }()
245
340
  default: break
246
341
  }
247
342
  }
@@ -289,8 +384,11 @@ extension CompactSaplingSpend: SwiftProtobuf.Message, SwiftProtobuf._MessageImpl
289
384
 
290
385
  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
291
386
  while let fieldNumber = try decoder.nextFieldNumber() {
387
+ // The use of inline closures is to circumvent an issue where the compiler
388
+ // allocates stack space for every case branch when no optimizations are
389
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
292
390
  switch fieldNumber {
293
- case 1: try decoder.decodeSingularBytesField(value: &self.nf)
391
+ case 1: try { try decoder.decodeSingularBytesField(value: &self.nf) }()
294
392
  default: break
295
393
  }
296
394
  }
@@ -314,16 +412,19 @@ extension CompactSaplingOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
314
412
  static let protoMessageName: String = _protobuf_package + ".CompactSaplingOutput"
315
413
  static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
316
414
  1: .same(proto: "cmu"),
317
- 2: .same(proto: "epk"),
415
+ 2: .same(proto: "ephemeralKey"),
318
416
  3: .same(proto: "ciphertext"),
319
417
  ]
320
418
 
321
419
  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
322
420
  while let fieldNumber = try decoder.nextFieldNumber() {
421
+ // The use of inline closures is to circumvent an issue where the compiler
422
+ // allocates stack space for every case branch when no optimizations are
423
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
323
424
  switch fieldNumber {
324
- case 1: try decoder.decodeSingularBytesField(value: &self.cmu)
325
- case 2: try decoder.decodeSingularBytesField(value: &self.epk)
326
- case 3: try decoder.decodeSingularBytesField(value: &self.ciphertext)
425
+ case 1: try { try decoder.decodeSingularBytesField(value: &self.cmu) }()
426
+ case 2: try { try decoder.decodeSingularBytesField(value: &self.ephemeralKey) }()
427
+ case 3: try { try decoder.decodeSingularBytesField(value: &self.ciphertext) }()
327
428
  default: break
328
429
  }
329
430
  }
@@ -333,8 +434,8 @@ extension CompactSaplingOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
333
434
  if !self.cmu.isEmpty {
334
435
  try visitor.visitSingularBytesField(value: self.cmu, fieldNumber: 1)
335
436
  }
336
- if !self.epk.isEmpty {
337
- try visitor.visitSingularBytesField(value: self.epk, fieldNumber: 2)
437
+ if !self.ephemeralKey.isEmpty {
438
+ try visitor.visitSingularBytesField(value: self.ephemeralKey, fieldNumber: 2)
338
439
  }
339
440
  if !self.ciphertext.isEmpty {
340
441
  try visitor.visitSingularBytesField(value: self.ciphertext, fieldNumber: 3)
@@ -344,7 +445,7 @@ extension CompactSaplingOutput: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
344
445
 
345
446
  static func ==(lhs: CompactSaplingOutput, rhs: CompactSaplingOutput) -> Bool {
346
447
  if lhs.cmu != rhs.cmu {return false}
347
- if lhs.epk != rhs.epk {return false}
448
+ if lhs.ephemeralKey != rhs.ephemeralKey {return false}
348
449
  if lhs.ciphertext != rhs.ciphertext {return false}
349
450
  if lhs.unknownFields != rhs.unknownFields {return false}
350
451
  return true
@@ -362,11 +463,14 @@ extension CompactOrchardAction: SwiftProtobuf.Message, SwiftProtobuf._MessageImp
362
463
 
363
464
  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
364
465
  while let fieldNumber = try decoder.nextFieldNumber() {
466
+ // The use of inline closures is to circumvent an issue where the compiler
467
+ // allocates stack space for every case branch when no optimizations are
468
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
365
469
  switch fieldNumber {
366
- case 1: try decoder.decodeSingularBytesField(value: &self.nullifier)
367
- case 2: try decoder.decodeSingularBytesField(value: &self.cmx)
368
- case 3: try decoder.decodeSingularBytesField(value: &self.ephemeralKey)
369
- case 4: try decoder.decodeSingularBytesField(value: &self.ciphertext)
470
+ case 1: try { try decoder.decodeSingularBytesField(value: &self.nullifier) }()
471
+ case 2: try { try decoder.decodeSingularBytesField(value: &self.cmx) }()
472
+ case 3: try { try decoder.decodeSingularBytesField(value: &self.ephemeralKey) }()
473
+ case 4: try { try decoder.decodeSingularBytesField(value: &self.ciphertext) }()
370
474
  default: break
371
475
  }
372
476
  }
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2019-2020 The Zcash developers
1
+ // Copyright (c) 2019-2021 The Zcash developers
2
2
  // Distributed under the MIT software license, see the accompanying
3
3
  // file COPYING or https://www.opensource.org/licenses/mit-license.php .
4
4
 
@@ -6,39 +6,50 @@ syntax = "proto3";
6
6
  package cash.z.wallet.sdk.rpc;
7
7
  option go_package = "lightwalletd/walletrpc";
8
8
  option swift_prefix = "";
9
+
9
10
  // Remember that proto3 fields are all optional. A field that is not present will be set to its zero value.
10
11
  // bytes fields of hashes are in canonical little-endian format.
11
12
 
13
+ // ChainMetadata represents information about the state of the chain as of a given block.
14
+ message ChainMetadata {
15
+ uint32 saplingCommitmentTreeSize = 1; // the size of the Sapling note commitment tree as of the end of this block
16
+ uint32 orchardCommitmentTreeSize = 2; // the size of the Orchard note commitment tree as of the end of this block
17
+ }
18
+
12
19
  // CompactBlock is a packaging of ONLY the data from a block that's needed to:
13
20
  // 1. Detect a payment to your shielded Sapling address
14
21
  // 2. Detect a spend of your shielded Sapling notes
15
22
  // 3. Update your witnesses to generate new Sapling spend proofs.
16
23
  message CompactBlock {
17
- uint32 protoVersion = 1; // the version of this wire format, for storage
18
- uint64 height = 2; // the height of this block
19
- bytes hash = 3; // the ID (hash) of this block, same as in block explorers
20
- bytes prevHash = 4; // the ID (hash) of this block's predecessor
21
- uint32 time = 5; // Unix epoch time when the block was mined
22
- bytes header = 6; // (hash, prevHash, and time) OR (full header)
23
- repeated CompactTx vtx = 7; // zero or more compact transactions from this block
24
+ uint32 protoVersion = 1; // the version of this wire format, for storage
25
+ uint64 height = 2; // the height of this block
26
+ bytes hash = 3; // the ID (hash) of this block, same as in block explorers
27
+ bytes prevHash = 4; // the ID (hash) of this block's predecessor
28
+ uint32 time = 5; // Unix epoch time when the block was mined
29
+ bytes header = 6; // (hash, prevHash, and time) OR (full header)
30
+ repeated CompactTx vtx = 7; // zero or more compact transactions from this block
31
+ ChainMetadata chainMetadata = 8; // information about the state of the chain as of this block
24
32
  }
25
33
 
26
34
  // CompactTx contains the minimum information for a wallet to know if this transaction
27
35
  // is relevant to it (either pays to it or spends from it) via shielded elements
28
36
  // only. This message will not encode a transparent-to-transparent transaction.
29
37
  message CompactTx {
38
+ // Index and hash will allow the receiver to call out to chain
39
+ // explorers or other data structures to retrieve more information
40
+ // about this transaction.
30
41
  uint64 index = 1; // the index within the full block
31
42
  bytes hash = 2; // the ID (hash) of this transaction, same as in block explorers
32
43
 
33
44
  // The transaction fee: present if server can provide. In the case of a
34
45
  // stateless server and a transaction with transparent inputs, this will be
35
46
  // unset because the calculation requires reference to prior transactions.
36
- // in a pure-Sapling context, the fee will be calculable as:
37
- // valueBalance + (sum(vPubNew) - sum(vPubOld) - sum(tOut))
47
+ // If there are no transparent inputs, the fee will be calculable as:
48
+ // valueBalanceSapling + valueBalanceOrchard + sum(vPubNew) - sum(vPubOld) - sum(tOut)
38
49
  uint32 fee = 3;
39
50
 
40
- repeated CompactSaplingSpend spends = 4; // inputs
41
- repeated CompactSaplingOutput outputs = 5; // outputs
51
+ repeated CompactSaplingSpend spends = 4;
52
+ repeated CompactSaplingOutput outputs = 5;
42
53
  repeated CompactOrchardAction actions = 6;
43
54
  }
44
55
 
@@ -48,11 +59,14 @@ message CompactSaplingSpend {
48
59
  bytes nf = 1; // nullifier (see the Zcash protocol specification)
49
60
  }
50
61
 
51
- // output is a Sapling Output Description as described in section 7.4 of the
52
- // Zcash protocol spec. Total size is 948.
62
+ // output encodes the `cmu` field, `ephemeralKey` field, and a 52-byte prefix of the
63
+ // `encCiphertext` field of a Sapling Output Description. These fields are described in
64
+ // section 7.4 of the Zcash protocol spec:
65
+ // https://zips.z.cash/protocol/protocol.pdf#outputencodingandconsensus
66
+ // Total size is 116 bytes.
53
67
  message CompactSaplingOutput {
54
68
  bytes cmu = 1; // note commitment u-coordinate
55
- bytes epk = 2; // ephemeral public key
69
+ bytes ephemeralKey = 2; // ephemeral public key
56
70
  bytes ciphertext = 3; // first 52 bytes of ciphertext
57
71
  }
58
72
 
@@ -62,5 +76,5 @@ message CompactOrchardAction {
62
76
  bytes nullifier = 1; // [32] The nullifier of the input note
63
77
  bytes cmx = 2; // [32] The x-coordinate of the note commitment for the output note
64
78
  bytes ephemeralKey = 3; // [32] An encoding of an ephemeral Pallas public key
65
- bytes ciphertext = 4; // [52] The note plaintext component of the encCiphertext field
79
+ bytes ciphertext = 4; // [52] The first 52 bytes of the encCiphertext field
66
80
  }
@@ -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 {
@@ -110,11 +110,28 @@ message Exclude {
110
110
 
111
111
  // The TreeState is derived from the Zcash z_gettreestate rpc.
112
112
  message TreeState {
113
- string network = 1; // "main" or "test"
114
- uint64 height = 2;
115
- string hash = 3; // block id
116
- uint32 time = 4; // Unix epoch time when the block was mined
117
- string tree = 5; // sapling commitment tree state
113
+ string network = 1; // "main" or "test"
114
+ uint64 height = 2; // block height
115
+ string hash = 3; // block id
116
+ uint32 time = 4; // Unix epoch time when the block was mined
117
+ string saplingTree = 5; // sapling commitment tree state
118
+ string orchardTree = 6; // orchard commitment tree state
119
+ }
120
+
121
+ enum ShieldedProtocol {
122
+ sapling = 0;
123
+ orchard = 1;
124
+ }
125
+
126
+ message GetSubtreeRootsArg {
127
+ uint32 startIndex = 1; // Index identifying where to start returning subtree roots
128
+ ShieldedProtocol shieldedProtocol = 2; // Shielded protocol to return subtree roots for
129
+ uint32 maxEntries = 3; // Maximum number of entries to return, or 0 for all entries.
130
+ }
131
+ message SubtreeRoot {
132
+ bytes rootHash = 2; // The 32-byte Merkle root of the subtree.
133
+ bytes completingBlockHash = 3; // The hash of the block that completed this subtree.
134
+ uint64 completingBlockHeight = 4; // The height of the block that completed this subtree in the main chain.
118
135
  }
119
136
 
120
137
  // Results are sorted by height, which makes it easy to issue another
@@ -141,8 +158,12 @@ service CompactTxStreamer {
141
158
  rpc GetLatestBlock(ChainSpec) returns (BlockID) {}
142
159
  // Return the compact block corresponding to the given block identifier
143
160
  rpc GetBlock(BlockID) returns (CompactBlock) {}
161
+ // Same as GetBlock except actions contain only nullifiers
162
+ rpc GetBlockNullifiers(BlockID) returns (CompactBlock) {}
144
163
  // Return a list of consecutive compact blocks
145
164
  rpc GetBlockRange(BlockRange) returns (stream CompactBlock) {}
165
+ // Same as GetBlockRange except actions contain only nullifiers
166
+ rpc GetBlockRangeNullifiers(BlockRange) returns (stream CompactBlock) {}
146
167
 
147
168
  // Return the requested full (not compact) transaction (as from zcashd)
148
169
  rpc GetTransaction(TxFilter) returns (RawTransaction) {}
@@ -174,6 +195,11 @@ service CompactTxStreamer {
174
195
  // values also (even though they can be obtained using GetBlock).
175
196
  // The block can be specified by either height or hash.
176
197
  rpc GetTreeState(BlockID) returns (TreeState) {}
198
+ rpc GetLatestTreeState(Empty) returns (TreeState) {}
199
+
200
+ // Returns a stream of information about roots of subtrees of the Sapling and Orchard
201
+ // note commitment trees.
202
+ rpc GetSubtreeRoots(GetSubtreeRootsArg) returns (stream SubtreeRoot) {}
177
203
 
178
204
  rpc GetAddressUtxos(GetAddressUtxosArg) returns (GetAddressUtxosReplyList) {}
179
205
  rpc GetAddressUtxosStream(GetAddressUtxosArg) returns (stream GetAddressUtxosReply) {}