@functionland/react-native-fula 1.55.15 → 1.55.17
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 -20
- package/android/build.gradle +114 -114
- package/android/gradle.properties +8 -8
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/AndroidManifestNew.xml +2 -2
- package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
- package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
- package/android/src/main/java/land/fx/fula/FulaModule.java +0 -0
- package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
- package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
- package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
- package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
- package/ios/Cryptography.swift +59 -59
- package/ios/Fula-Bridging-Header.h +3 -3
- package/ios/Fula.mm +272 -272
- package/ios/Fula.swift +32 -21
- package/ios/UserDataHelper.swift +143 -143
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api.js.map +1 -1
- package/lib/commonjs/interfaces/augment-types.js.map +1 -1
- package/lib/commonjs/interfaces/definitions.js.map +1 -1
- package/lib/commonjs/interfaces/defintions.js.map +1 -1
- package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/commonjs/interfaces/index.js.map +1 -1
- package/lib/commonjs/interfaces/lookup.js +300 -300
- package/lib/commonjs/interfaces/lookup.js.map +1 -1
- package/lib/commonjs/interfaces/registry.js.map +1 -1
- package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
- package/lib/commonjs/interfaces/types.js.map +1 -1
- package/lib/commonjs/protocols/blockchain.js +70 -70
- package/lib/commonjs/protocols/blockchain.js.map +1 -1
- package/lib/commonjs/protocols/chain-api.js.map +1 -1
- package/lib/commonjs/protocols/fula.js.map +1 -1
- package/lib/commonjs/protocols/fx-ai.js.map +1 -1
- package/lib/commonjs/protocols/fxblox.js +3 -3
- package/lib/commonjs/protocols/fxblox.js.map +1 -1
- package/lib/commonjs/types/blockchain.js.map +1 -1
- package/lib/commonjs/types/fxblox.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/augment-api-consts.js.map +1 -1
- package/lib/module/interfaces/augment-api-errors.js.map +1 -1
- package/lib/module/interfaces/augment-api-events.js.map +1 -1
- package/lib/module/interfaces/augment-api-query.js.map +1 -1
- package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
- package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
- package/lib/module/interfaces/augment-api-tx.js.map +1 -1
- package/lib/module/interfaces/augment-api.js.map +1 -1
- package/lib/module/interfaces/augment-types.js.map +1 -1
- package/lib/module/interfaces/definitions.js.map +1 -1
- package/lib/module/interfaces/defintions.js.map +1 -1
- package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/module/interfaces/index.js.map +1 -1
- package/lib/module/interfaces/lookup.js +300 -300
- package/lib/module/interfaces/lookup.js.map +1 -1
- package/lib/module/interfaces/registry.js.map +1 -1
- package/lib/module/interfaces/types-lookup.js.map +1 -1
- package/lib/module/interfaces/types.js.map +1 -1
- package/lib/module/protocols/blockchain.js +70 -70
- package/lib/module/protocols/blockchain.js.map +1 -1
- package/lib/module/protocols/chain-api.js.map +1 -1
- package/lib/module/protocols/fula.js.map +1 -1
- package/lib/module/protocols/fx-ai.js.map +1 -1
- package/lib/module/protocols/fxblox.js +3 -3
- package/lib/module/protocols/fxblox.js.map +1 -1
- package/lib/module/types/blockchain.js.map +1 -1
- package/lib/module/types/fxblox.js.map +1 -1
- package/package.json +177 -176
- package/src/index.tsx +4 -4
- package/src/interfaces/augment-api-consts.ts +273 -273
- package/src/interfaces/augment-api-errors.ts +474 -474
- package/src/interfaces/augment-api-events.ts +448 -448
- package/src/interfaces/augment-api-query.ts +466 -466
- package/src/interfaces/augment-api-rpc.ts +617 -617
- package/src/interfaces/augment-api-runtime.ts +223 -223
- package/src/interfaces/augment-api-tx.ts +709 -709
- package/src/interfaces/augment-api.ts +9 -9
- package/src/interfaces/augment-types.ts +1322 -1322
- package/src/interfaces/definitions.ts +1 -1
- package/src/interfaces/defintions.ts +1 -1
- package/src/interfaces/index.ts +3 -3
- package/src/interfaces/lookup.ts +2011 -2011
- package/src/interfaces/registry.ts +163 -163
- package/src/interfaces/types-lookup.ts +2165 -2165
- package/src/interfaces/types.ts +2 -2
- package/src/protocols/blockchain.ts +716 -716
- package/src/protocols/fxblox.ts +442 -442
package/ios/Fula.swift
CHANGED
|
@@ -4,6 +4,7 @@ import CommonCrypto
|
|
|
4
4
|
import Wnfs
|
|
5
5
|
import Fula
|
|
6
6
|
import os.log
|
|
7
|
+
import React
|
|
7
8
|
|
|
8
9
|
extension OSLog {
|
|
9
10
|
|
|
@@ -31,7 +32,7 @@ extension OSLog {
|
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
@objc(FulaModule)
|
|
34
|
-
class FulaModule:
|
|
35
|
+
class FulaModule: RCTEventEmitter {
|
|
35
36
|
public let NAME: String = "FulaModule"
|
|
36
37
|
var fula: FulamobileClient?
|
|
37
38
|
|
|
@@ -1507,7 +1508,7 @@ class FulaModule: NSObject {
|
|
|
1507
1508
|
return
|
|
1508
1509
|
}
|
|
1509
1510
|
|
|
1510
|
-
let result = try fula.
|
|
1511
|
+
let result = try fula.poolJoin(withChain: poolIdInt, chainName: chainName)
|
|
1511
1512
|
let resultString = String(data: result, encoding: .utf8)
|
|
1512
1513
|
resolve(resultString)
|
|
1513
1514
|
} catch let error {
|
|
@@ -1544,7 +1545,7 @@ class FulaModule: NSObject {
|
|
|
1544
1545
|
return
|
|
1545
1546
|
}
|
|
1546
1547
|
|
|
1547
|
-
let result = try fula.
|
|
1548
|
+
let result = try fula.poolLeave(withChain: poolIdInt, chainName: chainName)
|
|
1548
1549
|
let resultString = String(data: result, encoding: .utf8)
|
|
1549
1550
|
resolve(resultString)
|
|
1550
1551
|
} catch let error {
|
|
@@ -2091,7 +2092,7 @@ func replicateInPool(cidArray: [String], account: String, poolID: String, resolv
|
|
|
2091
2092
|
|
|
2092
2093
|
let result: Data
|
|
2093
2094
|
do {
|
|
2094
|
-
if let replicationResult =
|
|
2095
|
+
if let replicationResult = fula.replicate(inPool: cidsBytes, account: account, poolID: poolIDInt) {
|
|
2095
2096
|
result = replicationResult
|
|
2096
2097
|
} else {
|
|
2097
2098
|
throw NSError(domain: "FULAErrorDomain", code: 1007, userInfo: [NSLocalizedDescriptionKey: "Replication result is nil"])
|
|
@@ -2144,7 +2145,7 @@ func chatWithAI(aiModel: String, userMessage: String, resolve: @escaping RCTProm
|
|
|
2144
2145
|
}
|
|
2145
2146
|
|
|
2146
2147
|
// Call the Go Mobile method, which returns Data
|
|
2147
|
-
let streamIDData = try fula.
|
|
2148
|
+
let streamIDData = try fula.chat(withAI: aiModel, userMessage: userMessage)
|
|
2148
2149
|
|
|
2149
2150
|
// Convert Data to String (assuming UTF-8 encoding)
|
|
2150
2151
|
guard let streamID = String(data: streamIDData, encoding: .utf8) else {
|
|
@@ -2174,7 +2175,12 @@ func getChatChunk(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
|
|
|
2174
2175
|
}
|
|
2175
2176
|
|
|
2176
2177
|
// Call the Go Mobile method, which returns a String
|
|
2177
|
-
|
|
2178
|
+
var error: NSError?
|
|
2179
|
+
let chunk = fula.getChatChunk(streamID, error: &error)
|
|
2180
|
+
|
|
2181
|
+
if let error = error {
|
|
2182
|
+
throw error
|
|
2183
|
+
}
|
|
2178
2184
|
|
|
2179
2185
|
// Handle null or empty response
|
|
2180
2186
|
if chunk.isEmpty {
|
|
@@ -2213,9 +2219,8 @@ func streamChunks(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
|
|
|
2213
2219
|
throw MyError.runtimeError("ReactNative Fula client is not initialized")
|
|
2214
2220
|
}
|
|
2215
2221
|
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
}
|
|
2222
|
+
let iterator = fula.getStreamIterator(streamID)
|
|
2223
|
+
// Iterator is now non-optional, no need for nil check
|
|
2219
2224
|
|
|
2220
2225
|
// Start listening for chunks on the main thread
|
|
2221
2226
|
DispatchQueue.main.async {
|
|
@@ -2232,8 +2237,13 @@ func streamChunks(streamID: String, resolve: @escaping RCTPromiseResolveBlock, r
|
|
|
2232
2237
|
|
|
2233
2238
|
private func pollIterator(iterator: FulamobileStreamIterator, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
2234
2239
|
do {
|
|
2235
|
-
|
|
2236
|
-
|
|
2240
|
+
var error: NSError?
|
|
2241
|
+
let chunk = iterator.next(&error)
|
|
2242
|
+
|
|
2243
|
+
if let error = error {
|
|
2244
|
+
throw error
|
|
2245
|
+
}
|
|
2246
|
+
if !chunk.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {
|
|
2237
2247
|
self.emitEvent(eventName: "onChunkReceived", data: chunk)
|
|
2238
2248
|
}
|
|
2239
2249
|
|
|
@@ -2254,7 +2264,7 @@ private func pollIterator(iterator: FulamobileStreamIterator, resolve: @escaping
|
|
|
2254
2264
|
} else if errorMessage.contains("timeout") {
|
|
2255
2265
|
// Retry on timeout
|
|
2256
2266
|
DispatchQueue.main.async {
|
|
2257
|
-
self.pollIterator(iterator: iterator
|
|
2267
|
+
self.pollIterator(iterator: iterator!, resolve: resolve, reject: reject)
|
|
2258
2268
|
}
|
|
2259
2269
|
} else {
|
|
2260
2270
|
self.emitEvent(eventName: "onStreamError", data: errorMessage)
|
|
@@ -2264,16 +2274,17 @@ private func pollIterator(iterator: FulamobileStreamIterator, resolve: @escaping
|
|
|
2264
2274
|
}
|
|
2265
2275
|
|
|
2266
2276
|
private func emitEvent(eventName: String, data: String?) {
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
NSLog("ReactNative ERROR: Could not get event dispatcher")
|
|
2270
|
-
return
|
|
2271
|
-
}
|
|
2277
|
+
self.sendEvent(withName: eventName, body: data)
|
|
2278
|
+
}
|
|
2272
2279
|
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2280
|
+
// Required for RCTEventEmitter
|
|
2281
|
+
override func supportedEvents() -> [String]! {
|
|
2282
|
+
return ["onChunkReceived", "onStreamingCompleted", "onStreamError"]
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
// Required for RCTEventEmitter to prevent warnings
|
|
2286
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
2287
|
+
return false
|
|
2277
2288
|
}
|
|
2278
2289
|
|
|
2279
2290
|
}
|
package/ios/UserDataHelper.swift
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import CommonCrypto
|
|
3
|
-
import Foundation.NSDate // for TimeInterval
|
|
4
|
-
|
|
5
|
-
struct TimedOutError: Error, Equatable {}
|
|
6
|
-
|
|
7
|
-
public func withTimeout<R>(
|
|
8
|
-
seconds: TimeInterval,
|
|
9
|
-
operation: @escaping @Sendable () async throws -> R
|
|
10
|
-
) async throws -> R {
|
|
11
|
-
return try await withThrowingTaskGroup(of: R.self) { group in
|
|
12
|
-
defer {
|
|
13
|
-
group.cancelAll()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Start actual work.
|
|
17
|
-
group.addTask {
|
|
18
|
-
let result = try await operation()
|
|
19
|
-
try Task.checkCancellation()
|
|
20
|
-
return result
|
|
21
|
-
}
|
|
22
|
-
// Start timeout child task.
|
|
23
|
-
group.addTask {
|
|
24
|
-
if seconds > 0 {
|
|
25
|
-
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
|
|
26
|
-
}
|
|
27
|
-
try Task.checkCancellation()
|
|
28
|
-
// We’ve reached the timeout.
|
|
29
|
-
throw TimedOutError()
|
|
30
|
-
}
|
|
31
|
-
// First finished child task wins, cancel the other task.
|
|
32
|
-
let result = try await group.next()!
|
|
33
|
-
return result
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
public class UserDataHelper: NSObject {
|
|
39
|
-
var defaults: UserDefaults
|
|
40
|
-
|
|
41
|
-
override init() {
|
|
42
|
-
defaults = UserDefaults.standard
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public func getValue(_ key: String) -> String? {
|
|
46
|
-
return defaults.string(forKey: key)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public func getBooleanValue(_ key: String) -> Bool? {
|
|
50
|
-
return defaults.bool(forKey: key)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public func add(_ key: String, _ value: String) {
|
|
54
|
-
defaults.set(value, forKey: key)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public func add(_ key: String, _ value: Bool) {
|
|
58
|
-
defaults.set(value, forKey: key)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public func remove(_ key: String) {
|
|
62
|
-
defaults.removeObject(forKey: key)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public extension String {
|
|
67
|
-
func trim() -> String {
|
|
68
|
-
return self.trimmingCharacters(in: NSCharacterSet.whitespaces)
|
|
69
|
-
}
|
|
70
|
-
func fromBase64() -> Data? {
|
|
71
|
-
return Data(base64Encoded: self)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
func toUint8Array() -> Array<UInt8> {
|
|
75
|
-
return Array(self.utf8)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
func toData() -> Data {
|
|
79
|
-
return self.data(using: .utf8)!
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public extension Array<UInt8> {
|
|
84
|
-
func toHex() -> String {
|
|
85
|
-
return Data(self).toHex()
|
|
86
|
-
}
|
|
87
|
-
func toData() -> Data {
|
|
88
|
-
return Data(self)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public func toData(ptr: UnsafePointer<UInt8>?, size: Int) -> Data? {
|
|
93
|
-
// This will clone input c bytes to a swift Data class.
|
|
94
|
-
let buffer = UnsafeBufferPointer(start: ptr, count: size)
|
|
95
|
-
return Data(buffer: buffer)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public extension Data {
|
|
99
|
-
/// Fast convert to hex by reserving memory (instead of mapping and join).
|
|
100
|
-
func toHex(uppercase: Bool = false) -> String {
|
|
101
|
-
// Constants (Hex has 2 characters for each Byte).
|
|
102
|
-
let size = self.count * 2;
|
|
103
|
-
let degitToCharMap = Array((
|
|
104
|
-
uppercase ? "0123456789ABCDEF" : "0123456789abcdef"
|
|
105
|
-
).utf16);
|
|
106
|
-
// Reserve dynamic memory (plus one for null termination).
|
|
107
|
-
let buffer = UnsafeMutablePointer<unichar>.allocate(capacity: size + 1);
|
|
108
|
-
// Convert each byte.
|
|
109
|
-
var index = 0
|
|
110
|
-
for byte in self {
|
|
111
|
-
buffer[index] = degitToCharMap[Int(byte / 16)];
|
|
112
|
-
index += 1;
|
|
113
|
-
buffer[index] = degitToCharMap[Int(byte % 16)];
|
|
114
|
-
index += 1;
|
|
115
|
-
}
|
|
116
|
-
// Set Null termination.
|
|
117
|
-
buffer[index] = 0;
|
|
118
|
-
// Casts to string (without any copying).
|
|
119
|
-
return String(utf16CodeUnitsNoCopy: buffer,
|
|
120
|
-
count: size, freeWhenDone: true)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
func toUTF8String() -> String? {
|
|
124
|
-
return String(data: self, encoding: .utf8)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
func toUint8Array() -> Array<UInt8> {
|
|
128
|
-
return Array(self)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
func fromBase64() -> Data? {
|
|
132
|
-
// Finally, decode.
|
|
133
|
-
return Data(base64Encoded: self)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
func sha256() -> Data {
|
|
137
|
-
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
|
138
|
-
self.withUnsafeBytes {
|
|
139
|
-
_ = CC_SHA256($0.baseAddress, CC_LONG(self.count), &hash)
|
|
140
|
-
}
|
|
141
|
-
return Data(hash)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
import Foundation
|
|
2
|
+
import CommonCrypto
|
|
3
|
+
import Foundation.NSDate // for TimeInterval
|
|
4
|
+
|
|
5
|
+
struct TimedOutError: Error, Equatable {}
|
|
6
|
+
|
|
7
|
+
public func withTimeout<R>(
|
|
8
|
+
seconds: TimeInterval,
|
|
9
|
+
operation: @escaping @Sendable () async throws -> R
|
|
10
|
+
) async throws -> R {
|
|
11
|
+
return try await withThrowingTaskGroup(of: R.self) { group in
|
|
12
|
+
defer {
|
|
13
|
+
group.cancelAll()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Start actual work.
|
|
17
|
+
group.addTask {
|
|
18
|
+
let result = try await operation()
|
|
19
|
+
try Task.checkCancellation()
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
// Start timeout child task.
|
|
23
|
+
group.addTask {
|
|
24
|
+
if seconds > 0 {
|
|
25
|
+
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
|
|
26
|
+
}
|
|
27
|
+
try Task.checkCancellation()
|
|
28
|
+
// We’ve reached the timeout.
|
|
29
|
+
throw TimedOutError()
|
|
30
|
+
}
|
|
31
|
+
// First finished child task wins, cancel the other task.
|
|
32
|
+
let result = try await group.next()!
|
|
33
|
+
return result
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
public class UserDataHelper: NSObject {
|
|
39
|
+
var defaults: UserDefaults
|
|
40
|
+
|
|
41
|
+
override init() {
|
|
42
|
+
defaults = UserDefaults.standard
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public func getValue(_ key: String) -> String? {
|
|
46
|
+
return defaults.string(forKey: key)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public func getBooleanValue(_ key: String) -> Bool? {
|
|
50
|
+
return defaults.bool(forKey: key)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public func add(_ key: String, _ value: String) {
|
|
54
|
+
defaults.set(value, forKey: key)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public func add(_ key: String, _ value: Bool) {
|
|
58
|
+
defaults.set(value, forKey: key)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public func remove(_ key: String) {
|
|
62
|
+
defaults.removeObject(forKey: key)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public extension String {
|
|
67
|
+
func trim() -> String {
|
|
68
|
+
return self.trimmingCharacters(in: NSCharacterSet.whitespaces)
|
|
69
|
+
}
|
|
70
|
+
func fromBase64() -> Data? {
|
|
71
|
+
return Data(base64Encoded: self)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func toUint8Array() -> Array<UInt8> {
|
|
75
|
+
return Array(self.utf8)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func toData() -> Data {
|
|
79
|
+
return self.data(using: .utf8)!
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public extension Array<UInt8> {
|
|
84
|
+
func toHex() -> String {
|
|
85
|
+
return Data(self).toHex()
|
|
86
|
+
}
|
|
87
|
+
func toData() -> Data {
|
|
88
|
+
return Data(self)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public func toData(ptr: UnsafePointer<UInt8>?, size: Int) -> Data? {
|
|
93
|
+
// This will clone input c bytes to a swift Data class.
|
|
94
|
+
let buffer = UnsafeBufferPointer(start: ptr, count: size)
|
|
95
|
+
return Data(buffer: buffer)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public extension Data {
|
|
99
|
+
/// Fast convert to hex by reserving memory (instead of mapping and join).
|
|
100
|
+
func toHex(uppercase: Bool = false) -> String {
|
|
101
|
+
// Constants (Hex has 2 characters for each Byte).
|
|
102
|
+
let size = self.count * 2;
|
|
103
|
+
let degitToCharMap = Array((
|
|
104
|
+
uppercase ? "0123456789ABCDEF" : "0123456789abcdef"
|
|
105
|
+
).utf16);
|
|
106
|
+
// Reserve dynamic memory (plus one for null termination).
|
|
107
|
+
let buffer = UnsafeMutablePointer<unichar>.allocate(capacity: size + 1);
|
|
108
|
+
// Convert each byte.
|
|
109
|
+
var index = 0
|
|
110
|
+
for byte in self {
|
|
111
|
+
buffer[index] = degitToCharMap[Int(byte / 16)];
|
|
112
|
+
index += 1;
|
|
113
|
+
buffer[index] = degitToCharMap[Int(byte % 16)];
|
|
114
|
+
index += 1;
|
|
115
|
+
}
|
|
116
|
+
// Set Null termination.
|
|
117
|
+
buffer[index] = 0;
|
|
118
|
+
// Casts to string (without any copying).
|
|
119
|
+
return String(utf16CodeUnitsNoCopy: buffer,
|
|
120
|
+
count: size, freeWhenDone: true)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
func toUTF8String() -> String? {
|
|
124
|
+
return String(data: self, encoding: .utf8)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
func toUint8Array() -> Array<UInt8> {
|
|
128
|
+
return Array(self)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
func fromBase64() -> Data? {
|
|
132
|
+
// Finally, decode.
|
|
133
|
+
return Data(base64Encoded: self)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
func sha256() -> Data {
|
|
137
|
+
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
|
138
|
+
self.withUnsafeBytes {
|
|
139
|
+
_ = CC_SHA256($0.baseAddress, CC_LONG(self.count), &hash)
|
|
140
|
+
}
|
|
141
|
+
return Data(hash)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-consts.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-errors.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-events.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-query.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-rpc.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-runtime.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api-tx.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-api.ts"],"mappings":";;AAGAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["require"],"sourceRoot":"../../../src","sources":["interfaces/augment-types.ts"],"mappings":";;AAKAA,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["interfaces/definitions.ts"],"mappings":"AAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["interfaces/defintions.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Fula","NativeModules","FulaModule","Proxy","get","Error","_default","exports"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Fula","NativeModules","FulaModule","Proxy","get","Error","_default","exports"],"sourceRoot":"../../../src","sources":["interfaces/fulaNativeModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AA+JA,MAAMC,aAAa,GACjB,iFAAiF,GACjFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,IAAI,GAAGC,0BAAa,CAACC,UAAU,GACjCD,0BAAa,CAACC,UAAU,GACxB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAR,OAAA,GAESC,IAAI","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["interfaces/index.ts"],"mappings":"AAAA;AACA;AAAA","ignoreList":[]}
|