@synonymdev/react-native-pubky 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.
- package/LICENSE +20 -0
- package/README.md +57 -0
- package/android/build.gradle +101 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/pubky/PubkyModule.kt +43 -0
- package/android/src/main/java/com/pubky/PubkyPackage.kt +17 -0
- package/android/src/main/java/com/pubky/pubky.iml +11 -0
- package/android/src/main/java/uniffi/mobile/mobile.kt +688 -0
- package/android/src/main/jniLibs/arm64-v8a/libmobile.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libmobile.so +0 -0
- package/android/src/main/jniLibs/x86/libmobile.so +0 -0
- package/android/src/main/jniLibs/x86_64/libmobile.so +0 -0
- package/ios/Frameworks/Mobile.xcframework/Info.plist +47 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/Headers/mobileFFI.h +194 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/Headers/module.modulemap +6 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/libmobile.a +0 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/Headers/mobileFFI.h +194 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/Headers/module.modulemap +6 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/libmobile.a +0 -0
- package/ios/Pubky-Bridging-Header.h +2 -0
- package/ios/Pubky.mm +16 -0
- package/ios/Pubky.swift +16 -0
- package/ios/mobile.swift +484 -0
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +21 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +3 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +3 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +198 -0
- package/react-native-pubky.podspec +50 -0
- package/src/index.tsx +30 -0
package/ios/mobile.swift
ADDED
@@ -0,0 +1,484 @@
|
|
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(mobileFFI)
|
9
|
+
import mobileFFI
|
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_mobile_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_mobile_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
|
+
throw CancellationError()
|
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
|
+
fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
339
|
+
typealias SwiftType = [String]
|
340
|
+
|
341
|
+
public static func write(_ value: [String], into buf: inout [UInt8]) {
|
342
|
+
let len = Int32(value.count)
|
343
|
+
writeInt(&buf, len)
|
344
|
+
for item in value {
|
345
|
+
FfiConverterString.write(item, into: &buf)
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
|
350
|
+
let len: Int32 = try readInt(&buf)
|
351
|
+
var seq = [String]()
|
352
|
+
seq.reserveCapacity(Int(len))
|
353
|
+
for _ in 0 ..< len {
|
354
|
+
seq.append(try FfiConverterString.read(from: &buf))
|
355
|
+
}
|
356
|
+
return seq
|
357
|
+
}
|
358
|
+
}
|
359
|
+
private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
|
360
|
+
private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1
|
361
|
+
|
362
|
+
fileprivate func uniffiRustCallAsync<F, T>(
|
363
|
+
rustFutureFunc: () -> UnsafeMutableRawPointer,
|
364
|
+
pollFunc: (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> (),
|
365
|
+
completeFunc: (UnsafeMutableRawPointer, UnsafeMutablePointer<RustCallStatus>) -> F,
|
366
|
+
freeFunc: (UnsafeMutableRawPointer) -> (),
|
367
|
+
liftFunc: (F) throws -> T,
|
368
|
+
errorHandler: ((RustBuffer) throws -> Error)?
|
369
|
+
) async throws -> T {
|
370
|
+
// Make sure to call uniffiEnsureInitialized() since future creation doesn't have a
|
371
|
+
// RustCallStatus param, so doesn't use makeRustCall()
|
372
|
+
uniffiEnsureInitialized()
|
373
|
+
let rustFuture = rustFutureFunc()
|
374
|
+
defer {
|
375
|
+
freeFunc(rustFuture)
|
376
|
+
}
|
377
|
+
var pollResult: Int8;
|
378
|
+
repeat {
|
379
|
+
pollResult = await withUnsafeContinuation {
|
380
|
+
pollFunc(rustFuture, ContinuationHolder($0).toOpaque())
|
381
|
+
}
|
382
|
+
} while pollResult != UNIFFI_RUST_FUTURE_POLL_READY
|
383
|
+
|
384
|
+
return try liftFunc(makeRustCall(
|
385
|
+
{ completeFunc(rustFuture, $0) },
|
386
|
+
errorHandler: errorHandler
|
387
|
+
))
|
388
|
+
}
|
389
|
+
|
390
|
+
// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They
|
391
|
+
// lift the return value or error and resume the suspended function.
|
392
|
+
fileprivate func uniffiFutureContinuationCallback(ptr: UnsafeMutableRawPointer, pollResult: Int8) {
|
393
|
+
ContinuationHolder.fromOpaque(ptr).resume(pollResult)
|
394
|
+
}
|
395
|
+
|
396
|
+
// Wraps UnsafeContinuation in a class so that we can use reference counting when passing it across
|
397
|
+
// the FFI
|
398
|
+
fileprivate class ContinuationHolder {
|
399
|
+
let continuation: UnsafeContinuation<Int8, Never>
|
400
|
+
|
401
|
+
init(_ continuation: UnsafeContinuation<Int8, Never>) {
|
402
|
+
self.continuation = continuation
|
403
|
+
}
|
404
|
+
|
405
|
+
func resume(_ pollResult: Int8) {
|
406
|
+
self.continuation.resume(returning: pollResult)
|
407
|
+
}
|
408
|
+
|
409
|
+
func toOpaque() -> UnsafeMutableRawPointer {
|
410
|
+
return Unmanaged<ContinuationHolder>.passRetained(self).toOpaque()
|
411
|
+
}
|
412
|
+
|
413
|
+
static func fromOpaque(_ ptr: UnsafeRawPointer) -> ContinuationHolder {
|
414
|
+
return Unmanaged<ContinuationHolder>.fromOpaque(ptr).takeRetainedValue()
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
fileprivate func uniffiInitContinuationCallback() {
|
419
|
+
ffi_mobile_rust_future_continuation_callback_set(uniffiFutureContinuationCallback)
|
420
|
+
}
|
421
|
+
|
422
|
+
public func auth(url: String, secretKey: String) async -> [String] {
|
423
|
+
return try! await uniffiRustCallAsync(
|
424
|
+
rustFutureFunc: {
|
425
|
+
uniffi_mobile_fn_func_auth(
|
426
|
+
FfiConverterString.lower(url),
|
427
|
+
FfiConverterString.lower(secretKey)
|
428
|
+
)
|
429
|
+
},
|
430
|
+
pollFunc: ffi_mobile_rust_future_poll_rust_buffer,
|
431
|
+
completeFunc: ffi_mobile_rust_future_complete_rust_buffer,
|
432
|
+
freeFunc: ffi_mobile_rust_future_free_rust_buffer,
|
433
|
+
liftFunc: FfiConverterSequenceString.lift,
|
434
|
+
errorHandler: nil
|
435
|
+
|
436
|
+
)
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
public func myexample() -> [String] {
|
442
|
+
return try! FfiConverterSequenceString.lift(
|
443
|
+
try! rustCall() {
|
444
|
+
uniffi_mobile_fn_func_myexample($0)
|
445
|
+
}
|
446
|
+
)
|
447
|
+
}
|
448
|
+
|
449
|
+
private enum InitializationResult {
|
450
|
+
case ok
|
451
|
+
case contractVersionMismatch
|
452
|
+
case apiChecksumMismatch
|
453
|
+
}
|
454
|
+
// Use a global variables to perform the versioning checks. Swift ensures that
|
455
|
+
// the code inside is only computed once.
|
456
|
+
private var initializationResult: InitializationResult {
|
457
|
+
// Get the bindings contract version from our ComponentInterface
|
458
|
+
let bindings_contract_version = 24
|
459
|
+
// Get the scaffolding contract version by calling the into the dylib
|
460
|
+
let scaffolding_contract_version = ffi_mobile_uniffi_contract_version()
|
461
|
+
if bindings_contract_version != scaffolding_contract_version {
|
462
|
+
return InitializationResult.contractVersionMismatch
|
463
|
+
}
|
464
|
+
if (uniffi_mobile_checksum_func_auth() != 55720) {
|
465
|
+
return InitializationResult.apiChecksumMismatch
|
466
|
+
}
|
467
|
+
if (uniffi_mobile_checksum_func_myexample() != 65225) {
|
468
|
+
return InitializationResult.apiChecksumMismatch
|
469
|
+
}
|
470
|
+
|
471
|
+
uniffiInitContinuationCallback()
|
472
|
+
return InitializationResult.ok
|
473
|
+
}
|
474
|
+
|
475
|
+
private func uniffiEnsureInitialized() {
|
476
|
+
switch initializationResult {
|
477
|
+
case .ok:
|
478
|
+
break
|
479
|
+
case .contractVersionMismatch:
|
480
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
481
|
+
case .apiChecksumMismatch:
|
482
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
483
|
+
}
|
484
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.auth = auth;
|
7
|
+
var _reactNative = require("react-native");
|
8
|
+
var _result = require("@synonymdev/result");
|
9
|
+
const LINKING_ERROR = `The package 'react-native-pubky' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
10
|
+
ios: "- You have run 'pod install'\n",
|
11
|
+
default: ''
|
12
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
13
|
+
const Pubky = _reactNative.NativeModules.Pubky ? _reactNative.NativeModules.Pubky : new Proxy({}, {
|
14
|
+
get() {
|
15
|
+
throw new Error(LINKING_ERROR);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
async function auth(url, secretKey) {
|
19
|
+
const res = await Pubky.auth(url, secretKey);
|
20
|
+
if (res[0] === 'error') {
|
21
|
+
return (0, _result.err)(res[1]);
|
22
|
+
}
|
23
|
+
return (0, _result.ok)(res[1]);
|
24
|
+
}
|
25
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_result","LINKING_ERROR","Platform","select","ios","default","Pubky","NativeModules","Proxy","get","Error","auth","url","secretKey","res","err","ok"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,aAAa,GACjB,6EAA6E,GAC7EC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,KAAK,GAAGC,0BAAa,CAACD,KAAK,GAC7BC,0BAAa,CAACD,KAAK,GACnB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEE,eAAeU,IAAIA,CACxBC,GAAW,EACXC,SAAiB,EACU;EAC3B,MAAMC,GAAG,GAAG,MAAMR,KAAK,CAACK,IAAI,CAACC,GAAG,EAAEC,SAAS,CAAC;EAC5C,IAAIC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,OAAO,IAAAC,WAAG,EAACD,GAAG,CAAC,CAAC,CAAC,CAAC;EACpB;EACA,OAAO,IAAAE,UAAE,EAACF,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB","ignoreList":[]}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import { NativeModules, Platform } from 'react-native';
|
4
|
+
import { ok, err } from '@synonymdev/result';
|
5
|
+
const LINKING_ERROR = `The package 'react-native-pubky' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
6
|
+
ios: "- You have run 'pod install'\n",
|
7
|
+
default: ''
|
8
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
9
|
+
const Pubky = NativeModules.Pubky ? NativeModules.Pubky : new Proxy({}, {
|
10
|
+
get() {
|
11
|
+
throw new Error(LINKING_ERROR);
|
12
|
+
}
|
13
|
+
});
|
14
|
+
export async function auth(url, secretKey) {
|
15
|
+
const res = await Pubky.auth(url, secretKey);
|
16
|
+
if (res[0] === 'error') {
|
17
|
+
return err(res[1]);
|
18
|
+
}
|
19
|
+
return ok(res[1]);
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","ok","err","LINKING_ERROR","select","ios","default","Pubky","Proxy","get","Error","auth","url","secretKey","res"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SAASC,EAAE,EAAEC,GAAG,QAAqB,oBAAoB;AAEzD,MAAMC,aAAa,GACjB,6EAA6E,GAC7EH,QAAQ,CAACI,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,KAAK,GAAGR,aAAa,CAACQ,KAAK,GAC7BR,aAAa,CAACQ,KAAK,GACnB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,eAAeQ,IAAIA,CACxBC,GAAW,EACXC,SAAiB,EACU;EAC3B,MAAMC,GAAG,GAAG,MAAMP,KAAK,CAACI,IAAI,CAACC,GAAG,EAAEC,SAAS,CAAC;EAC5C,IAAIC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,OAAOZ,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAAC;EACpB;EACA,OAAOb,EAAE,CAACa,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB","ignoreList":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type":"commonjs"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type":"module"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B"}
|