@nuggetslife/vc-rn 0.1.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 (137) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +31 -0
  3. package/android/build.gradle +101 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/nuggetslife/bindings/vc/vc.kt +673 -0
  8. package/android/src/main/java/com/nuggetslife/vc/VcModule.kt +30 -0
  9. package/android/src/main/java/com/nuggetslife/vc/VcPackage.kt +17 -0
  10. package/android/src/main/jniLibs/arm64-v8a/libvc.so +0 -0
  11. package/android/src/main/jniLibs/armeabi-v7a/libvc.so +0 -0
  12. package/android/src/main/jniLibs/x86/libvc.so +0 -0
  13. package/android/src/main/jniLibs/x86_64/libvc.so +0 -0
  14. package/ios/Vc-Bridging-Header.h +2 -0
  15. package/ios/VcModule.mm +14 -0
  16. package/ios/VcModule.swift +23 -0
  17. package/ios/vc.swift +446 -0
  18. package/ios/vc.xcframework/Info.plist +48 -0
  19. package/ios/vc.xcframework/ios-arm64/Headers/module.modulemap +6 -0
  20. package/ios/vc.xcframework/ios-arm64/Headers/vcFFI.h +174 -0
  21. package/ios/vc.xcframework/ios-arm64/libvc.a +0 -0
  22. package/ios/vc.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +6 -0
  23. package/ios/vc.xcframework/ios-arm64_x86_64-simulator/Headers/vcFFI.h +174 -0
  24. package/ios/vc.xcframework/ios-arm64_x86_64-simulator/libvc.a +0 -0
  25. package/ios/vcFFI.h +174 -0
  26. package/lib/commonjs/Bls12381G2KeyPair.js +405 -0
  27. package/lib/commonjs/Bls12381G2KeyPair.js.map +1 -0
  28. package/lib/commonjs/index.d.js +18 -0
  29. package/lib/commonjs/index.d.js.map +1 -0
  30. package/lib/commonjs/index.js +20 -0
  31. package/lib/commonjs/index.js.map +1 -0
  32. package/lib/commonjs/types/BlsCurveName.js +14 -0
  33. package/lib/commonjs/types/BlsCurveName.js.map +1 -0
  34. package/lib/commonjs/types/GenerateKeyPairOptions.js +2 -0
  35. package/lib/commonjs/types/GenerateKeyPairOptions.js.map +1 -0
  36. package/lib/commonjs/types/JsonWebKey.js +2 -0
  37. package/lib/commonjs/types/JsonWebKey.js.map +1 -0
  38. package/lib/commonjs/types/JwkKeyPairOptions.js +6 -0
  39. package/lib/commonjs/types/JwkKeyPairOptions.js.map +1 -0
  40. package/lib/commonjs/types/JwkKty.js +13 -0
  41. package/lib/commonjs/types/JwkKty.js.map +1 -0
  42. package/lib/commonjs/types/KeyPairOptions.js +2 -0
  43. package/lib/commonjs/types/KeyPairOptions.js.map +1 -0
  44. package/lib/commonjs/types/KeyPairSigner.js +2 -0
  45. package/lib/commonjs/types/KeyPairSigner.js.map +1 -0
  46. package/lib/commonjs/types/KeyPairVerifier.js +2 -0
  47. package/lib/commonjs/types/KeyPairVerifier.js.map +1 -0
  48. package/lib/commonjs/types/index.js +20 -0
  49. package/lib/commonjs/types/index.js.map +1 -0
  50. package/lib/commonjs/utils/codec.js +22 -0
  51. package/lib/commonjs/utils/codec.js.map +1 -0
  52. package/lib/commonjs/utils/index.js +19 -0
  53. package/lib/commonjs/utils/index.js.map +1 -0
  54. package/lib/commonjs/validators/Bls12381G2Jwk.js +19 -0
  55. package/lib/commonjs/validators/Bls12381G2Jwk.js.map +1 -0
  56. package/lib/commonjs/validators/JsonWebKey.js +27 -0
  57. package/lib/commonjs/validators/JsonWebKey.js.map +1 -0
  58. package/lib/module/Bls12381G2KeyPair.js +398 -0
  59. package/lib/module/Bls12381G2KeyPair.js.map +1 -0
  60. package/lib/module/index.d.js +9 -0
  61. package/lib/module/index.d.js.map +1 -0
  62. package/lib/module/index.js +14 -0
  63. package/lib/module/index.js.map +1 -0
  64. package/lib/module/types/BlsCurveName.js +8 -0
  65. package/lib/module/types/BlsCurveName.js.map +1 -0
  66. package/lib/module/types/GenerateKeyPairOptions.js +2 -0
  67. package/lib/module/types/GenerateKeyPairOptions.js.map +1 -0
  68. package/lib/module/types/JsonWebKey.js +2 -0
  69. package/lib/module/types/JsonWebKey.js.map +1 -0
  70. package/lib/module/types/JwkKeyPairOptions.js +2 -0
  71. package/lib/module/types/JwkKeyPairOptions.js.map +1 -0
  72. package/lib/module/types/JwkKty.js +7 -0
  73. package/lib/module/types/JwkKty.js.map +1 -0
  74. package/lib/module/types/KeyPairOptions.js +2 -0
  75. package/lib/module/types/KeyPairOptions.js.map +1 -0
  76. package/lib/module/types/KeyPairSigner.js +2 -0
  77. package/lib/module/types/KeyPairSigner.js.map +1 -0
  78. package/lib/module/types/KeyPairVerifier.js +2 -0
  79. package/lib/module/types/KeyPairVerifier.js.map +1 -0
  80. package/lib/module/types/index.js +3 -0
  81. package/lib/module/types/index.js.map +1 -0
  82. package/lib/module/utils/codec.js +13 -0
  83. package/lib/module/utils/codec.js.map +1 -0
  84. package/lib/module/utils/index.js +2 -0
  85. package/lib/module/utils/index.js.map +1 -0
  86. package/lib/module/validators/Bls12381G2Jwk.js +11 -0
  87. package/lib/module/validators/Bls12381G2Jwk.js.map +1 -0
  88. package/lib/module/validators/JsonWebKey.js +19 -0
  89. package/lib/module/validators/JsonWebKey.js.map +1 -0
  90. package/lib/typescript/src/Bls12381G2KeyPair.d.ts +104 -0
  91. package/lib/typescript/src/Bls12381G2KeyPair.d.ts.map +1 -0
  92. package/lib/typescript/src/index.d.ts +2 -0
  93. package/lib/typescript/src/index.d.ts.map +1 -0
  94. package/lib/typescript/src/types/BlsCurveName.d.ts +7 -0
  95. package/lib/typescript/src/types/BlsCurveName.d.ts.map +1 -0
  96. package/lib/typescript/src/types/GenerateKeyPairOptions.d.ts +18 -0
  97. package/lib/typescript/src/types/GenerateKeyPairOptions.d.ts.map +1 -0
  98. package/lib/typescript/src/types/JsonWebKey.d.ts +60 -0
  99. package/lib/typescript/src/types/JsonWebKey.d.ts.map +1 -0
  100. package/lib/typescript/src/types/JwkKeyPairOptions.d.ts +23 -0
  101. package/lib/typescript/src/types/JwkKeyPairOptions.d.ts.map +1 -0
  102. package/lib/typescript/src/types/JwkKty.d.ts +6 -0
  103. package/lib/typescript/src/types/JwkKty.d.ts.map +1 -0
  104. package/lib/typescript/src/types/KeyPairOptions.d.ts +22 -0
  105. package/lib/typescript/src/types/KeyPairOptions.d.ts.map +1 -0
  106. package/lib/typescript/src/types/KeyPairSigner.d.ts +7 -0
  107. package/lib/typescript/src/types/KeyPairSigner.d.ts.map +1 -0
  108. package/lib/typescript/src/types/KeyPairVerifier.d.ts +8 -0
  109. package/lib/typescript/src/types/KeyPairVerifier.d.ts.map +1 -0
  110. package/lib/typescript/src/types/index.d.ts +9 -0
  111. package/lib/typescript/src/types/index.d.ts.map +1 -0
  112. package/lib/typescript/src/utils/codec.d.ts +3 -0
  113. package/lib/typescript/src/utils/codec.d.ts.map +1 -0
  114. package/lib/typescript/src/utils/index.d.ts +2 -0
  115. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  116. package/lib/typescript/src/validators/Bls12381G2Jwk.d.ts +4 -0
  117. package/lib/typescript/src/validators/Bls12381G2Jwk.d.ts.map +1 -0
  118. package/lib/typescript/src/validators/JsonWebKey.d.ts +4 -0
  119. package/lib/typescript/src/validators/JsonWebKey.d.ts.map +1 -0
  120. package/nuggetslife-vc.podspec +42 -0
  121. package/package.json +164 -0
  122. package/src/Bls12381G2KeyPair.ts +447 -0
  123. package/src/index.d.ts +126 -0
  124. package/src/index.tsx +22 -0
  125. package/src/types/BlsCurveName.ts +6 -0
  126. package/src/types/GenerateKeyPairOptions.ts +17 -0
  127. package/src/types/JsonWebKey.ts +68 -0
  128. package/src/types/JwkKeyPairOptions.ts +24 -0
  129. package/src/types/JwkKty.ts +5 -0
  130. package/src/types/KeyPairOptions.ts +21 -0
  131. package/src/types/KeyPairSigner.ts +6 -0
  132. package/src/types/KeyPairVerifier.ts +8 -0
  133. package/src/types/index.ts +8 -0
  134. package/src/utils/codec.ts +12 -0
  135. package/src/utils/index.ts +1 -0
  136. package/src/validators/Bls12381G2Jwk.ts +21 -0
  137. package/src/validators/JsonWebKey.ts +28 -0
@@ -0,0 +1,17 @@
1
+ package com.nuggetslife.vc
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class VcPackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(VcModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return emptyList()
16
+ }
17
+ }
@@ -0,0 +1,2 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
@@ -0,0 +1,14 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(Vc, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(vc_facade:(NSString)action options:(NSString)options
6
+ resolver:(RCTPromiseResolveBlock)resolve
7
+ rejecter:(RCTPromiseRejectBlock)reject)
8
+
9
+ + (BOOL)requiresMainQueueSetup
10
+ {
11
+ return NO;
12
+ }
13
+
14
+ @end
@@ -0,0 +1,23 @@
1
+ //
2
+ // VcModule.swift
3
+ // nuggetslife-vc
4
+ //
5
+ // Created by harry on 20/6/2024.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ @objc(Vc)
11
+ class Vc: NSObject {
12
+
13
+ @objc(vc_facade:options:resolver:rejecter:)
14
+ func vc_facade(action: NSString, options: NSString, resolver:RCTPromiseResolveBlock, rejecter:RCTPromiseRejectBlock) -> Void {
15
+ do {
16
+ let result = try facade(action: action as String, options: options as String)
17
+ resolver(result)
18
+ } catch {
19
+ rejecter("", "vc_facade threw error \(error)", error)
20
+ }
21
+ }
22
+ }
23
+
package/ios/vc.swift ADDED
@@ -0,0 +1,446 @@
1
+ // This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ // Trust me, you don't want to mess with it!
3
+ import Foundation
4
+
5
+ // Depending on the consumer's build setup, the low-level FFI code
6
+ // might be in a separate module, or it might be compiled inline into
7
+ // this module. This is a bit of light hackery to work with both.
8
+ #if canImport(vcFFI)
9
+ import vcFFI
10
+ #endif
11
+
12
+ fileprivate extension RustBuffer {
13
+ // Allocate a new buffer, copying the contents of a `UInt8` array.
14
+ init(bytes: [UInt8]) {
15
+ let rbuf = bytes.withUnsafeBufferPointer { ptr in
16
+ RustBuffer.from(ptr)
17
+ }
18
+ self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
19
+ }
20
+
21
+ static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
22
+ try! rustCall { ffi_vc_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
23
+ }
24
+
25
+ // Frees the buffer in place.
26
+ // The buffer must not be used after this is called.
27
+ func deallocate() {
28
+ try! rustCall { ffi_vc_rustbuffer_free(self, $0) }
29
+ }
30
+ }
31
+
32
+ fileprivate extension ForeignBytes {
33
+ init(bufferPointer: UnsafeBufferPointer<UInt8>) {
34
+ self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
35
+ }
36
+ }
37
+
38
+ // For every type used in the interface, we provide helper methods for conveniently
39
+ // lifting and lowering that type from C-compatible data, and for reading and writing
40
+ // values of that type in a buffer.
41
+
42
+ // Helper classes/extensions that don't change.
43
+ // Someday, this will be in a library of its own.
44
+
45
+ fileprivate extension Data {
46
+ init(rustBuffer: RustBuffer) {
47
+ // TODO: This copies the buffer. Can we read directly from a
48
+ // Rust buffer?
49
+ self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len))
50
+ }
51
+ }
52
+
53
+ // Define reader functionality. Normally this would be defined in a class or
54
+ // struct, but we use standalone functions instead in order to make external
55
+ // types work.
56
+ //
57
+ // With external types, one swift source file needs to be able to call the read
58
+ // method on another source file's FfiConverter, but then what visibility
59
+ // should Reader have?
60
+ // - If Reader is fileprivate, then this means the read() must also
61
+ // be fileprivate, which doesn't work with external types.
62
+ // - If Reader is internal/public, we'll get compile errors since both source
63
+ // files will try define the same type.
64
+ //
65
+ // Instead, the read() method and these helper functions input a tuple of data
66
+
67
+ fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
68
+ (data: data, offset: 0)
69
+ }
70
+
71
+ // Reads an integer at the current offset, in big-endian order, and advances
72
+ // the offset on success. Throws if reading the integer would move the
73
+ // offset past the end of the buffer.
74
+ fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
75
+ let range = reader.offset..<reader.offset + MemoryLayout<T>.size
76
+ guard reader.data.count >= range.upperBound else {
77
+ throw UniffiInternalError.bufferOverflow
78
+ }
79
+ if T.self == UInt8.self {
80
+ let value = reader.data[reader.offset]
81
+ reader.offset += 1
82
+ return value as! T
83
+ }
84
+ var value: T = 0
85
+ let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
86
+ reader.offset = range.upperBound
87
+ return value.bigEndian
88
+ }
89
+
90
+ // Reads an arbitrary number of bytes, to be used to read
91
+ // raw bytes, this is useful when lifting strings
92
+ fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
93
+ let range = reader.offset..<(reader.offset+count)
94
+ guard reader.data.count >= range.upperBound else {
95
+ throw UniffiInternalError.bufferOverflow
96
+ }
97
+ var value = [UInt8](repeating: 0, count: count)
98
+ value.withUnsafeMutableBufferPointer({ buffer in
99
+ reader.data.copyBytes(to: buffer, from: range)
100
+ })
101
+ reader.offset = range.upperBound
102
+ return value
103
+ }
104
+
105
+ // Reads a float at the current offset.
106
+ fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
107
+ return Float(bitPattern: try readInt(&reader))
108
+ }
109
+
110
+ // Reads a float at the current offset.
111
+ fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
112
+ return Double(bitPattern: try readInt(&reader))
113
+ }
114
+
115
+ // Indicates if the offset has reached the end of the buffer.
116
+ fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
117
+ return reader.offset < reader.data.count
118
+ }
119
+
120
+ // Define writer functionality. Normally this would be defined in a class or
121
+ // struct, but we use standalone functions instead in order to make external
122
+ // types work. See the above discussion on Readers for details.
123
+
124
+ fileprivate func createWriter() -> [UInt8] {
125
+ return []
126
+ }
127
+
128
+ fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
129
+ writer.append(contentsOf: byteArr)
130
+ }
131
+
132
+ // Writes an integer in big-endian order.
133
+ //
134
+ // Warning: make sure what you are trying to write
135
+ // is in the correct type!
136
+ fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
137
+ var value = value.bigEndian
138
+ withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
139
+ }
140
+
141
+ fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
142
+ writeInt(&writer, value.bitPattern)
143
+ }
144
+
145
+ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
146
+ writeInt(&writer, value.bitPattern)
147
+ }
148
+
149
+ // Protocol for types that transfer other types across the FFI. This is
150
+ // analogous go the Rust trait of the same name.
151
+ fileprivate protocol FfiConverter {
152
+ associatedtype FfiType
153
+ associatedtype SwiftType
154
+
155
+ static func lift(_ value: FfiType) throws -> SwiftType
156
+ static func lower(_ value: SwiftType) -> FfiType
157
+ static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
158
+ static func write(_ value: SwiftType, into buf: inout [UInt8])
159
+ }
160
+
161
+ // Types conforming to `Primitive` pass themselves directly over the FFI.
162
+ fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
163
+
164
+ extension FfiConverterPrimitive {
165
+ public static func lift(_ value: FfiType) throws -> SwiftType {
166
+ return value
167
+ }
168
+
169
+ public static func lower(_ value: SwiftType) -> FfiType {
170
+ return value
171
+ }
172
+ }
173
+
174
+ // Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
175
+ // Used for complex types where it's hard to write a custom lift/lower.
176
+ fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
177
+
178
+ extension FfiConverterRustBuffer {
179
+ public static func lift(_ buf: RustBuffer) throws -> SwiftType {
180
+ var reader = createReader(data: Data(rustBuffer: buf))
181
+ let value = try read(from: &reader)
182
+ if hasRemaining(reader) {
183
+ throw UniffiInternalError.incompleteData
184
+ }
185
+ buf.deallocate()
186
+ return value
187
+ }
188
+
189
+ public static func lower(_ value: SwiftType) -> RustBuffer {
190
+ var writer = createWriter()
191
+ write(value, into: &writer)
192
+ return RustBuffer(bytes: writer)
193
+ }
194
+ }
195
+ // An error type for FFI errors. These errors occur at the UniFFI level, not
196
+ // the library level.
197
+ fileprivate enum UniffiInternalError: LocalizedError {
198
+ case bufferOverflow
199
+ case incompleteData
200
+ case unexpectedOptionalTag
201
+ case unexpectedEnumCase
202
+ case unexpectedNullPointer
203
+ case unexpectedRustCallStatusCode
204
+ case unexpectedRustCallError
205
+ case unexpectedStaleHandle
206
+ case rustPanic(_ message: String)
207
+
208
+ public var errorDescription: String? {
209
+ switch self {
210
+ case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
211
+ case .incompleteData: return "The buffer still has data after lifting its containing value"
212
+ case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
213
+ case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
214
+ case .unexpectedNullPointer: return "Raw pointer value was null"
215
+ case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
216
+ case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
217
+ case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
218
+ case let .rustPanic(message): return message
219
+ }
220
+ }
221
+ }
222
+
223
+ fileprivate let CALL_SUCCESS: Int8 = 0
224
+ fileprivate let CALL_ERROR: Int8 = 1
225
+ fileprivate let CALL_PANIC: Int8 = 2
226
+ fileprivate let CALL_CANCELLED: Int8 = 3
227
+
228
+ fileprivate extension RustCallStatus {
229
+ init() {
230
+ self.init(
231
+ code: CALL_SUCCESS,
232
+ errorBuf: RustBuffer.init(
233
+ capacity: 0,
234
+ len: 0,
235
+ data: nil
236
+ )
237
+ )
238
+ }
239
+ }
240
+
241
+ private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
242
+ try makeRustCall(callback, errorHandler: nil)
243
+ }
244
+
245
+ private func rustCallWithError<T>(
246
+ _ errorHandler: @escaping (RustBuffer) throws -> Error,
247
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
248
+ try makeRustCall(callback, errorHandler: errorHandler)
249
+ }
250
+
251
+ private func makeRustCall<T>(
252
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
253
+ errorHandler: ((RustBuffer) throws -> Error)?
254
+ ) throws -> T {
255
+ uniffiEnsureInitialized()
256
+ var callStatus = RustCallStatus.init()
257
+ let returnedVal = callback(&callStatus)
258
+ try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
259
+ return returnedVal
260
+ }
261
+
262
+ private func uniffiCheckCallStatus(
263
+ callStatus: RustCallStatus,
264
+ errorHandler: ((RustBuffer) throws -> Error)?
265
+ ) throws {
266
+ switch callStatus.code {
267
+ case CALL_SUCCESS:
268
+ return
269
+
270
+ case CALL_ERROR:
271
+ if let errorHandler = errorHandler {
272
+ throw try errorHandler(callStatus.errorBuf)
273
+ } else {
274
+ callStatus.errorBuf.deallocate()
275
+ throw UniffiInternalError.unexpectedRustCallError
276
+ }
277
+
278
+ case CALL_PANIC:
279
+ // When the rust code sees a panic, it tries to construct a RustBuffer
280
+ // with the message. But if that code panics, then it just sends back
281
+ // an empty buffer.
282
+ if callStatus.errorBuf.len > 0 {
283
+ throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
284
+ } else {
285
+ callStatus.errorBuf.deallocate()
286
+ throw UniffiInternalError.rustPanic("Rust panic")
287
+ }
288
+
289
+ case CALL_CANCELLED:
290
+ fatalError("Cancellation not supported yet")
291
+
292
+ default:
293
+ throw UniffiInternalError.unexpectedRustCallStatusCode
294
+ }
295
+ }
296
+
297
+ // Public interface members begin here.
298
+
299
+
300
+ fileprivate struct FfiConverterString: FfiConverter {
301
+ typealias SwiftType = String
302
+ typealias FfiType = RustBuffer
303
+
304
+ public static func lift(_ value: RustBuffer) throws -> String {
305
+ defer {
306
+ value.deallocate()
307
+ }
308
+ if value.data == nil {
309
+ return String()
310
+ }
311
+ let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
312
+ return String(bytes: bytes, encoding: String.Encoding.utf8)!
313
+ }
314
+
315
+ public static func lower(_ value: String) -> RustBuffer {
316
+ return value.utf8CString.withUnsafeBufferPointer { ptr in
317
+ // The swift string gives us int8_t, we want uint8_t.
318
+ ptr.withMemoryRebound(to: UInt8.self) { ptr in
319
+ // The swift string gives us a trailing null byte, we don't want it.
320
+ let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
321
+ return RustBuffer.from(buf)
322
+ }
323
+ }
324
+ }
325
+
326
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
327
+ let len: Int32 = try readInt(&buf)
328
+ return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
329
+ }
330
+
331
+ public static func write(_ value: String, into buf: inout [UInt8]) {
332
+ let len = Int32(value.utf8.count)
333
+ writeInt(&buf, len)
334
+ writeBytes(&buf, value.utf8)
335
+ }
336
+ }
337
+
338
+
339
+ public enum VcError {
340
+
341
+
342
+
343
+ case Generic(message: String)
344
+
345
+ case BlsSign(message: String)
346
+
347
+ case BlsVerify(message: String)
348
+
349
+
350
+ fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error {
351
+ return try FfiConverterTypeVCError.lift(error)
352
+ }
353
+ }
354
+
355
+
356
+ public struct FfiConverterTypeVCError: FfiConverterRustBuffer {
357
+ typealias SwiftType = VcError
358
+
359
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VcError {
360
+ let variant: Int32 = try readInt(&buf)
361
+ switch variant {
362
+
363
+
364
+
365
+
366
+ case 1: return .Generic(
367
+ message: try FfiConverterString.read(from: &buf)
368
+ )
369
+
370
+ case 2: return .BlsSign(
371
+ message: try FfiConverterString.read(from: &buf)
372
+ )
373
+
374
+ case 3: return .BlsVerify(
375
+ message: try FfiConverterString.read(from: &buf)
376
+ )
377
+
378
+
379
+ default: throw UniffiInternalError.unexpectedEnumCase
380
+ }
381
+ }
382
+
383
+ public static func write(_ value: VcError, into buf: inout [UInt8]) {
384
+ switch value {
385
+
386
+
387
+
388
+
389
+ case .Generic(_ /* message is ignored*/):
390
+ writeInt(&buf, Int32(1))
391
+ case .BlsSign(_ /* message is ignored*/):
392
+ writeInt(&buf, Int32(2))
393
+ case .BlsVerify(_ /* message is ignored*/):
394
+ writeInt(&buf, Int32(3))
395
+
396
+
397
+ }
398
+ }
399
+ }
400
+
401
+
402
+ extension VcError: Equatable, Hashable {}
403
+
404
+ extension VcError: Error { }
405
+ public func facade(action: String, options: String) throws -> String {
406
+ return try FfiConverterString.lift(
407
+ try rustCallWithError(FfiConverterTypeVCError.lift) {
408
+ uniffi_vc_fn_func_facade(
409
+ FfiConverterString.lower(action),
410
+ FfiConverterString.lower(options),$0)
411
+ }
412
+ )
413
+ }
414
+
415
+ private enum InitializationResult {
416
+ case ok
417
+ case contractVersionMismatch
418
+ case apiChecksumMismatch
419
+ }
420
+ // Use a global variables to perform the versioning checks. Swift ensures that
421
+ // the code inside is only computed once.
422
+ private var initializationResult: InitializationResult {
423
+ // Get the bindings contract version from our ComponentInterface
424
+ let bindings_contract_version = 25
425
+ // Get the scaffolding contract version by calling the into the dylib
426
+ let scaffolding_contract_version = ffi_vc_uniffi_contract_version()
427
+ if bindings_contract_version != scaffolding_contract_version {
428
+ return InitializationResult.contractVersionMismatch
429
+ }
430
+ if (uniffi_vc_checksum_func_facade() != 4396) {
431
+ return InitializationResult.apiChecksumMismatch
432
+ }
433
+
434
+ return InitializationResult.ok
435
+ }
436
+
437
+ private func uniffiEnsureInitialized() {
438
+ switch initializationResult {
439
+ case .ok:
440
+ break
441
+ case .contractVersionMismatch:
442
+ fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
443
+ case .apiChecksumMismatch:
444
+ fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
445
+ }
446
+ }
@@ -0,0 +1,48 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libvc.a</string>
10
+ <key>HeadersPath</key>
11
+ <string>Headers</string>
12
+ <key>LibraryIdentifier</key>
13
+ <string>ios-arm64_x86_64-simulator</string>
14
+ <key>LibraryPath</key>
15
+ <string>libvc.a</string>
16
+ <key>SupportedArchitectures</key>
17
+ <array>
18
+ <string>arm64</string>
19
+ <string>x86_64</string>
20
+ </array>
21
+ <key>SupportedPlatform</key>
22
+ <string>ios</string>
23
+ <key>SupportedPlatformVariant</key>
24
+ <string>simulator</string>
25
+ </dict>
26
+ <dict>
27
+ <key>BinaryPath</key>
28
+ <string>libvc.a</string>
29
+ <key>HeadersPath</key>
30
+ <string>Headers</string>
31
+ <key>LibraryIdentifier</key>
32
+ <string>ios-arm64</string>
33
+ <key>LibraryPath</key>
34
+ <string>libvc.a</string>
35
+ <key>SupportedArchitectures</key>
36
+ <array>
37
+ <string>arm64</string>
38
+ </array>
39
+ <key>SupportedPlatform</key>
40
+ <string>ios</string>
41
+ </dict>
42
+ </array>
43
+ <key>CFBundlePackageType</key>
44
+ <string>XFWK</string>
45
+ <key>XCFrameworkFormatVersion</key>
46
+ <string>1.0</string>
47
+ </dict>
48
+ </plist>
@@ -0,0 +1,6 @@
1
+ // This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ // Trust me, you don't want to mess with it!
3
+ module vcFFI {
4
+ header "vcFFI.h"
5
+ export *
6
+ }