@functionland/react-native-fula 1.14.2 → 1.14.4

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 (135) hide show
  1. package/LICENSE +20 -21
  2. package/android/build.gradle +90 -50
  3. package/android/gradle.properties +5 -1
  4. package/android/src/main/AndroidManifest.xml +3 -4
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +1466 -1466
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +36 -0
  14. package/ios/Fula-Bridging-Header.h +3 -0
  15. package/ios/Fula.mm +199 -0
  16. package/ios/Fula.swift +1152 -0
  17. package/ios/{FulaModule.xcodeproj → Fula.xcodeproj}/project.pbxproj +38 -16
  18. package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  19. package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  20. package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  21. package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  22. package/ios/UserDataHelper.swift +143 -0
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/interfaces/api-lookup.js +266 -266
  25. package/lib/commonjs/interfaces/api-lookup.js.map +1 -1
  26. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  27. package/lib/commonjs/protocols/blockchain.js +64 -64
  28. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  29. package/lib/commonjs/protocols/chain-api.js +10 -0
  30. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  31. package/lib/commonjs/protocols/fula.js +99 -99
  32. package/lib/commonjs/protocols/fula.js.map +1 -1
  33. package/lib/commonjs/protocols/fxblox.js +3 -3
  34. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  35. package/lib/commonjs/types/blockchain.js.map +1 -1
  36. package/lib/commonjs/types/fxblox.js.map +1 -1
  37. package/lib/module/index.js +4 -8
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/interfaces/api-lookup.js +266 -266
  40. package/lib/module/interfaces/api-lookup.js.map +1 -1
  41. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  42. package/lib/module/protocols/blockchain.js +64 -64
  43. package/lib/module/protocols/blockchain.js.map +1 -1
  44. package/lib/module/protocols/chain-api.js +8 -0
  45. package/lib/module/protocols/chain-api.js.map +1 -1
  46. package/lib/module/protocols/fula.js +99 -99
  47. package/lib/module/protocols/fula.js.map +1 -1
  48. package/lib/module/protocols/fxblox.js +3 -3
  49. package/lib/module/protocols/fxblox.js.map +1 -1
  50. package/lib/module/types/blockchain.js.map +1 -1
  51. package/lib/module/types/fxblox.js.map +1 -1
  52. package/lib/typescript/index.d.ts +5 -4
  53. package/lib/typescript/index.d.ts.map +1 -0
  54. package/lib/typescript/interfaces/api-lookup.d.ts +1644 -1643
  55. package/lib/typescript/interfaces/api-lookup.d.ts.map +1 -0
  56. package/lib/typescript/interfaces/fulaNativeModule.d.ts +62 -61
  57. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -0
  58. package/lib/typescript/protocols/blockchain.d.ts +18 -17
  59. package/lib/typescript/protocols/blockchain.d.ts.map +1 -0
  60. package/lib/typescript/protocols/chain-api.d.ts +7 -6
  61. package/lib/typescript/protocols/chain-api.d.ts.map +1 -0
  62. package/lib/typescript/protocols/fula.d.ts +132 -131
  63. package/lib/typescript/protocols/fula.d.ts.map +1 -0
  64. package/lib/typescript/protocols/fxblox.d.ts +8 -7
  65. package/lib/typescript/protocols/fxblox.d.ts.map +1 -0
  66. package/lib/typescript/types/blockchain.d.ts +69 -68
  67. package/lib/typescript/types/blockchain.d.ts.map +1 -0
  68. package/lib/typescript/types/fxblox.d.ts +9 -8
  69. package/lib/typescript/types/fxblox.d.ts.map +1 -0
  70. package/package.json +43 -28
  71. package/react-native-fula.podspec +47 -19
  72. package/src/index.tsx +4 -4
  73. package/src/interfaces/api-lookup.ts +1647 -1647
  74. package/src/interfaces/fulaNativeModule.ts +122 -122
  75. package/src/protocols/blockchain.ts +504 -504
  76. package/src/protocols/chain-api.ts +8 -0
  77. package/src/protocols/fula.ts +314 -314
  78. package/src/protocols/fxblox.ts +49 -49
  79. package/src/types/blockchain.ts +80 -80
  80. package/src/types/fxblox.ts +8 -8
  81. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  82. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  83. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  84. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  85. package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
  86. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  87. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  88. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  89. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  90. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  91. package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
  92. package/android/.gradle/7.5.1/gc.properties +0 -0
  93. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  94. package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
  95. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  96. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  97. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  98. package/android/.gradle/7.6/executionHistory/executionHistory.bin +0 -0
  99. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  100. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  101. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  102. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  103. package/android/.gradle/7.6/fileHashes/resourceHashesCache.bin +0 -0
  104. package/android/.gradle/7.6/gc.properties +0 -0
  105. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  106. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  107. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  108. package/android/.gradle/file-system.probe +0 -0
  109. package/android/.gradle/vcs-1/gc.properties +0 -0
  110. package/android/.idea/compiler.xml +0 -6
  111. package/android/.idea/gradle.xml +0 -20
  112. package/android/.idea/jarRepositories.xml +0 -50
  113. package/android/.idea/misc.xml +0 -10
  114. package/android/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  115. package/android/.idea/sonarlint/issuestore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  116. package/android/.idea/sonarlint/issuestore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  117. package/android/.idea/sonarlint/issuestore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  118. package/android/.idea/sonarlint/issuestore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  119. package/android/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  120. package/android/.idea/sonarlint/issuestore/index.pb +0 -13
  121. package/android/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  122. package/android/.idea/sonarlint/securityhotspotstore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  123. package/android/.idea/sonarlint/securityhotspotstore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  124. package/android/.idea/sonarlint/securityhotspotstore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  125. package/android/.idea/sonarlint/securityhotspotstore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  126. package/android/.idea/sonarlint/securityhotspotstore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  127. package/android/.idea/sonarlint/securityhotspotstore/index.pb +0 -13
  128. package/android/.idea/vcs.xml +0 -6
  129. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  130. package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
  131. package/android/gradlew +0 -291
  132. package/android/gradlew.bat +0 -91
  133. package/android/local.properties +0 -8
  134. package/ios/FulaModule.h +0 -10
  135. package/ios/FulaModule.m +0 -149
@@ -6,6 +6,12 @@
6
6
  objectVersion = 46;
7
7
  objects = {
8
8
 
9
+ /* Begin PBXBuildFile section */
10
+ 060162ED2A84149500A6E464 /* Cryptography.swift in Sources */ = {isa = PBXBuildFile; fileRef = 060162EC2A84149500A6E464 /* Cryptography.swift */; };
11
+ 060162EF2A8414AD00A6E464 /* UserDataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 060162EE2A8414AD00A6E464 /* UserDataHelper.swift */; };
12
+ F4FF95D7245B92E800C19C63 /* Fula.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* Fula.swift */; };
13
+ /* End PBXBuildFile section */
14
+
9
15
  /* Begin PBXCopyFilesBuildPhase section */
10
16
  58B511D91A9E6C8500147676 /* CopyFiles */ = {
11
17
  isa = PBXCopyFilesBuildPhase;
@@ -19,9 +25,12 @@
19
25
  /* End PBXCopyFilesBuildPhase section */
20
26
 
21
27
  /* Begin PBXFileReference section */
22
- 11C0B56928882C93007D9057 /* FulaModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FulaModule.h; sourceTree = "<group>"; };
23
- 11C0B56A28882C93007D9057 /* FulaModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FulaModule.m; sourceTree = "<group>"; };
24
- 134814201AA4EA6300B7C361 /* libFulaModule.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFulaModule.a; sourceTree = BUILT_PRODUCTS_DIR; };
28
+ 060162EC2A84149500A6E464 /* Cryptography.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cryptography.swift; sourceTree = "<group>"; };
29
+ 060162EE2A8414AD00A6E464 /* UserDataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDataHelper.swift; sourceTree = "<group>"; };
30
+ 134814201AA4EA6300B7C361 /* libFula.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFula.a; sourceTree = BUILT_PRODUCTS_DIR; };
31
+ B3E7B5891CC2AC0600A0062D /* Fula.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Fula.mm; sourceTree = "<group>"; };
32
+ F4FF95D5245B92E700C19C63 /* Fula-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Fula-Bridging-Header.h"; sourceTree = "<group>"; };
33
+ F4FF95D6245B92E800C19C63 /* Fula.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fula.swift; sourceTree = "<group>"; };
25
34
  /* End PBXFileReference section */
26
35
 
27
36
  /* Begin PBXFrameworksBuildPhase section */
@@ -38,7 +47,7 @@
38
47
  134814211AA4EA7D00B7C361 /* Products */ = {
39
48
  isa = PBXGroup;
40
49
  children = (
41
- 134814201AA4EA6300B7C361 /* libFulaModule.a */,
50
+ 134814201AA4EA6300B7C361 /* libFula.a */,
42
51
  );
43
52
  name = Products;
44
53
  sourceTree = "<group>";
@@ -46,8 +55,11 @@
46
55
  58B511D21A9E6C8500147676 = {
47
56
  isa = PBXGroup;
48
57
  children = (
49
- 11C0B56928882C93007D9057 /* FulaModule.h */,
50
- 11C0B56A28882C93007D9057 /* FulaModule.m */,
58
+ 060162EE2A8414AD00A6E464 /* UserDataHelper.swift */,
59
+ 060162EC2A84149500A6E464 /* Cryptography.swift */,
60
+ F4FF95D6245B92E800C19C63 /* Fula.swift */,
61
+ B3E7B5891CC2AC0600A0062D /* Fula.mm */,
62
+ F4FF95D5245B92E700C19C63 /* Fula-Bridging-Header.h */,
51
63
  134814211AA4EA7D00B7C361 /* Products */,
52
64
  );
53
65
  sourceTree = "<group>";
@@ -55,9 +67,9 @@
55
67
  /* End PBXGroup section */
56
68
 
57
69
  /* Begin PBXNativeTarget section */
58
- 58B511DA1A9E6C8500147676 /* FulaModule */ = {
70
+ 58B511DA1A9E6C8500147676 /* Fula */ = {
59
71
  isa = PBXNativeTarget;
60
- buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "FulaModule" */;
72
+ buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Fula" */;
61
73
  buildPhases = (
62
74
  58B511D71A9E6C8500147676 /* Sources */,
63
75
  58B511D81A9E6C8500147676 /* Frameworks */,
@@ -67,9 +79,9 @@
67
79
  );
68
80
  dependencies = (
69
81
  );
70
- name = FulaModule;
82
+ name = Fula;
71
83
  productName = RCTDataManager;
72
- productReference = 134814201AA4EA6300B7C361 /* libFulaModule.a */;
84
+ productReference = 134814201AA4EA6300B7C361 /* libFula.a */;
73
85
  productType = "com.apple.product-type.library.static";
74
86
  };
75
87
  /* End PBXNativeTarget section */
@@ -86,7 +98,7 @@
86
98
  };
87
99
  };
88
100
  };
89
- buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "FulaModule" */;
101
+ buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Fula" */;
90
102
  compatibilityVersion = "Xcode 3.2";
91
103
  developmentRegion = English;
92
104
  hasScannedForEncodings = 0;
@@ -99,7 +111,7 @@
99
111
  projectDirPath = "";
100
112
  projectRoot = "";
101
113
  targets = (
102
- 58B511DA1A9E6C8500147676 /* FulaModule */,
114
+ 58B511DA1A9E6C8500147676 /* Fula */,
103
115
  );
104
116
  };
105
117
  /* End PBXProject section */
@@ -109,6 +121,9 @@
109
121
  isa = PBXSourcesBuildPhase;
110
122
  buildActionMask = 2147483647;
111
123
  files = (
124
+ 060162EF2A8414AD00A6E464 /* UserDataHelper.swift in Sources */,
125
+ 060162ED2A84149500A6E464 /* Cryptography.swift in Sources */,
126
+ F4FF95D7245B92E800C19C63 /* Fula.swift in Sources */,
112
127
  );
113
128
  runOnlyForDeploymentPostprocessing = 0;
114
129
  };
@@ -143,6 +158,7 @@
143
158
  COPY_PHASE_STRIP = NO;
144
159
  ENABLE_STRICT_OBJC_MSGSEND = YES;
145
160
  ENABLE_TESTABILITY = YES;
161
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
146
162
  GCC_C_LANGUAGE_STANDARD = gnu99;
147
163
  GCC_DYNAMIC_NO_PIC = NO;
148
164
  GCC_NO_COMMON_BLOCKS = YES;
@@ -193,6 +209,7 @@
193
209
  COPY_PHASE_STRIP = YES;
194
210
  ENABLE_NS_ASSERTIONS = NO;
195
211
  ENABLE_STRICT_OBJC_MSGSEND = YES;
212
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
196
213
  GCC_C_LANGUAGE_STANDARD = gnu99;
197
214
  GCC_NO_COMMON_BLOCKS = YES;
198
215
  GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -219,8 +236,11 @@
219
236
  );
220
237
  LIBRARY_SEARCH_PATHS = "$(inherited)";
221
238
  OTHER_LDFLAGS = "-ObjC";
222
- PRODUCT_NAME = FulaModule;
239
+ PRODUCT_NAME = Fula;
223
240
  SKIP_INSTALL = YES;
241
+ SWIFT_OBJC_BRIDGING_HEADER = "Fula-Bridging-Header.h";
242
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
243
+ SWIFT_VERSION = 5.0;
224
244
  };
225
245
  name = Debug;
226
246
  };
@@ -235,15 +255,17 @@
235
255
  );
236
256
  LIBRARY_SEARCH_PATHS = "$(inherited)";
237
257
  OTHER_LDFLAGS = "-ObjC";
238
- PRODUCT_NAME = FulaModule;
258
+ PRODUCT_NAME = Fula;
239
259
  SKIP_INSTALL = YES;
260
+ SWIFT_OBJC_BRIDGING_HEADER = "Fula-Bridging-Header.h";
261
+ SWIFT_VERSION = 5.0;
240
262
  };
241
263
  name = Release;
242
264
  };
243
265
  /* End XCBuildConfiguration section */
244
266
 
245
267
  /* Begin XCConfigurationList section */
246
- 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "FulaModule" */ = {
268
+ 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Fula" */ = {
247
269
  isa = XCConfigurationList;
248
270
  buildConfigurations = (
249
271
  58B511ED1A9E6C8500147676 /* Debug */,
@@ -252,7 +274,7 @@
252
274
  defaultConfigurationIsVisible = 0;
253
275
  defaultConfigurationName = Release;
254
276
  };
255
- 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "FulaModule" */ = {
277
+ 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Fula" */ = {
256
278
  isa = XCConfigurationList;
257
279
  buildConfigurations = (
258
280
  58B511F01A9E6C8500147676 /* Debug */,
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
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>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,14 @@
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>SchemeUserState</key>
6
+ <dict>
7
+ <key>Fula.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
@@ -0,0 +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 +1 @@
1
- {"version":3,"names":[],"sources":["index.tsx"],"sourcesContent":["export * as fula from './protocols/fula';\r\nexport * as blockchain from './protocols/blockchain';\r\nexport * as chainApi from './protocols/chain-api';\r\nexport * as fxblox from './protocols/fxblox';\r\n"],"mappings":""}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":""}