one 2.0.0-beta.130.1 → 2.0.0-beta.131.1

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 (66) hide show
  1. package/dist/cjs/one.cjs +1 -0
  2. package/dist/cjs/one.native.cjs +1 -0
  3. package/dist/cjs/one.native.js +1 -0
  4. package/dist/cjs/one.native.js.map +1 -1
  5. package/dist/cjs/platform/index.cjs +2 -0
  6. package/dist/cjs/platform/index.native.cjs +2 -0
  7. package/dist/cjs/platform/index.native.js +2 -0
  8. package/dist/cjs/platform/index.native.js.map +1 -1
  9. package/dist/cjs/platform/protected-store/index.cjs +32 -0
  10. package/dist/cjs/platform/protected-store/index.native.cjs +54 -0
  11. package/dist/cjs/platform/protected-store/index.native.js +56 -0
  12. package/dist/cjs/platform/protected-store/index.native.js.map +1 -0
  13. package/dist/cjs/platform/specs/OneProtectedStore.nitro.cjs +16 -0
  14. package/dist/cjs/platform/specs/OneProtectedStore.nitro.native.cjs +18 -0
  15. package/dist/cjs/platform/specs/OneProtectedStore.nitro.native.js +20 -0
  16. package/dist/cjs/platform/specs/OneProtectedStore.nitro.native.js.map +1 -0
  17. package/dist/esm/one.mjs +2 -1
  18. package/dist/esm/one.mjs.map +1 -1
  19. package/dist/esm/one.native.js +2 -1
  20. package/dist/esm/one.native.js.map +1 -1
  21. package/dist/esm/platform/index.mjs +2 -1
  22. package/dist/esm/platform/index.mjs.map +1 -1
  23. package/dist/esm/platform/index.native.js +2 -1
  24. package/dist/esm/platform/index.native.js.map +1 -1
  25. package/dist/esm/platform/protected-store/index.mjs +12 -0
  26. package/dist/esm/platform/protected-store/index.mjs.map +1 -0
  27. package/dist/esm/platform/protected-store/index.native.js +33 -0
  28. package/dist/esm/platform/protected-store/index.native.js.map +1 -0
  29. package/dist/esm/platform/specs/OneProtectedStore.nitro.mjs +0 -0
  30. package/dist/esm/platform/specs/OneProtectedStore.nitro.native.js +0 -0
  31. package/ios/Nitro/HybridOneProtectedStore.swift +246 -0
  32. package/nitrogen/generated/android/One+autolinking.cmake +1 -0
  33. package/nitrogen/generated/ios/One-Swift-Cxx-Bridge.cpp +17 -0
  34. package/nitrogen/generated/ios/One-Swift-Cxx-Bridge.hpp +25 -8
  35. package/nitrogen/generated/ios/One-Swift-Cxx-Umbrella.hpp +8 -0
  36. package/nitrogen/generated/ios/OneAutolinking.mm +8 -0
  37. package/nitrogen/generated/ios/OneAutolinking.swift +12 -0
  38. package/nitrogen/generated/ios/c++/HybridOneProtectedStoreSpecSwift.cpp +11 -0
  39. package/nitrogen/generated/ios/c++/HybridOneProtectedStoreSpecSwift.hpp +110 -0
  40. package/nitrogen/generated/ios/swift/HybridOneProtectedStoreSpec.swift +58 -0
  41. package/nitrogen/generated/ios/swift/HybridOneProtectedStoreSpec_cxx.swift +208 -0
  42. package/nitrogen/generated/ios/swift/ProtectedStorePolicy.swift +40 -0
  43. package/nitrogen/generated/shared/c++/HybridOneProtectedStoreSpec.cpp +24 -0
  44. package/nitrogen/generated/shared/c++/HybridOneProtectedStoreSpec.hpp +69 -0
  45. package/nitrogen/generated/shared/c++/ProtectedStorePolicy.hpp +76 -0
  46. package/package.json +10 -10
  47. package/src/nativeCoverage.test.ts +2 -1
  48. package/src/one.ts +3 -0
  49. package/src/platform/README.md +17 -0
  50. package/src/platform/index.native.ts +2 -0
  51. package/src/platform/index.ts +2 -0
  52. package/src/platform/protected-store/index.native.ts +32 -0
  53. package/src/platform/protected-store/index.ts +14 -0
  54. package/src/platform/specs/OneProtectedStore.nitro.ts +12 -0
  55. package/types/one.d.ts +2 -1
  56. package/types/one.d.ts.map +1 -1
  57. package/types/platform/index.d.ts +2 -0
  58. package/types/platform/index.d.ts.map +1 -1
  59. package/types/platform/index.native.d.ts +2 -0
  60. package/types/platform/index.native.d.ts.map +1 -1
  61. package/types/platform/protected-store/index.d.ts +9 -0
  62. package/types/platform/protected-store/index.d.ts.map +1 -0
  63. package/types/platform/protected-store/index.native.d.ts +13 -0
  64. package/types/platform/protected-store/index.native.d.ts.map +1 -0
  65. package/types/platform/specs/OneProtectedStore.nitro.d.ts +11 -0
  66. package/types/platform/specs/OneProtectedStore.nitro.d.ts.map +1 -0
@@ -0,0 +1,246 @@
1
+ import Foundation
2
+ import LocalAuthentication
3
+ import NitroModules
4
+ import Security
5
+
6
+ final class HybridOneProtectedStore: HybridOneProtectedStoreSpec {
7
+ private static let service = "One.ProtectedStore"
8
+
9
+ func createItem(key: String, value: String, policy: ProtectedStorePolicy) throws -> Promise<Void> {
10
+ let promise = Promise<Void>()
11
+ DispatchQueue.global(qos: .userInitiated).async {
12
+ do {
13
+ try Self.validate(key: key, operation: "createItem")
14
+ let flags: SecAccessControlCreateFlags = policy == .userpresence
15
+ ? .userPresence : .biometryCurrentSet
16
+ var accessError: Unmanaged<CFError>?
17
+ guard let access = SecAccessControlCreateWithFlags(
18
+ nil, kSecAttrAccessibleWhenUnlockedThisDeviceOnly, flags, &accessError
19
+ ) else {
20
+ let detail = accessError?.takeRetainedValue().localizedDescription ?? "access control is unavailable"
21
+ throw oneNativeError("E_PROTECTED_STORE_AUTH", "ProtectedStore.createItem: \(detail)")
22
+ }
23
+ var attributes = Self.query(key: key)
24
+ attributes[kSecValueData as String] = Data(value.utf8)
25
+ attributes[kSecAttrAccessControl as String] = access
26
+ attributes[kSecAttrLabel as String] = policy.stringValue
27
+ let status = SecItemAdd(attributes as CFDictionary, nil)
28
+ if status == errSecDuplicateItem {
29
+ throw oneNativeError("E_PROTECTED_STORE_EXISTS", "ProtectedStore.createItem: key already exists")
30
+ }
31
+ guard status == errSecSuccess else {
32
+ throw Self.failure("createItem", status)
33
+ }
34
+ promise.resolve()
35
+ } catch {
36
+ promise.reject(withError: error)
37
+ }
38
+ }
39
+ return promise
40
+ }
41
+
42
+ func getItem(key: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<String?> {
43
+ let promise = Promise<String?>()
44
+ DispatchQueue.global(qos: .userInitiated).async {
45
+ do {
46
+ try Self.validate(key: key, reason: reason, operation: "getItem")
47
+ guard try Self.exists(key: key, operation: "getItem") else {
48
+ promise.resolve(withResult: nil)
49
+ return
50
+ }
51
+ let context = Self.context(reason: reason)
52
+ Self.verify(context: context, policy: policy, reason: reason, operation: "getItem") {
53
+ error in
54
+ if let error { promise.reject(withError: error); return }
55
+ do {
56
+ guard let item = try Self.read(key: key, context: context, operation: "getItem") else {
57
+ promise.resolve(withResult: nil)
58
+ return
59
+ }
60
+ try Self.requirePolicy(item.policy, policy, operation: "getItem")
61
+ promise.resolve(withResult: item.value)
62
+ } catch {
63
+ promise.reject(withError: error)
64
+ }
65
+ }
66
+ } catch {
67
+ promise.reject(withError: error)
68
+ }
69
+ }
70
+ return promise
71
+ }
72
+
73
+ func updateItem(key: String, value: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<Void> {
74
+ let promise = Promise<Void>()
75
+ DispatchQueue.global(qos: .userInitiated).async {
76
+ do {
77
+ try Self.validate(key: key, reason: reason, operation: "updateItem")
78
+ guard try Self.exists(key: key, operation: "updateItem") else {
79
+ throw oneNativeError("E_PROTECTED_STORE_NOT_FOUND", "ProtectedStore.updateItem: key is missing")
80
+ }
81
+ let context = Self.context(reason: reason)
82
+ Self.verify(context: context, policy: policy, reason: reason, operation: "updateItem") {
83
+ error in
84
+ if let error { promise.reject(withError: error); return }
85
+ do {
86
+ guard let item = try Self.read(key: key, context: context, operation: "updateItem") else {
87
+ throw oneNativeError("E_PROTECTED_STORE_NOT_FOUND", "ProtectedStore.updateItem: key is missing")
88
+ }
89
+ try Self.requirePolicy(item.policy, policy, operation: "updateItem")
90
+ var lookup = Self.query(key: key)
91
+ lookup[kSecUseAuthenticationContext as String] = context
92
+ let status = SecItemUpdate(
93
+ lookup as CFDictionary, [kSecValueData as String: Data(value.utf8)] as CFDictionary)
94
+ if status == errSecItemNotFound {
95
+ throw oneNativeError("E_PROTECTED_STORE_NOT_FOUND", "ProtectedStore.updateItem: key is missing")
96
+ }
97
+ guard status == errSecSuccess else { throw Self.failure("updateItem", status) }
98
+ promise.resolve()
99
+ } catch {
100
+ promise.reject(withError: error)
101
+ }
102
+ }
103
+ } catch {
104
+ promise.reject(withError: error)
105
+ }
106
+ }
107
+ return promise
108
+ }
109
+
110
+ func deleteItem(key: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<Void> {
111
+ let promise = Promise<Void>()
112
+ DispatchQueue.global(qos: .userInitiated).async {
113
+ do {
114
+ try Self.validate(key: key, reason: reason, operation: "deleteItem")
115
+ guard try Self.exists(key: key, operation: "deleteItem") else {
116
+ let status = SecItemDelete(Self.query(key: key) as CFDictionary)
117
+ if status == errSecSuccess || status == errSecItemNotFound { promise.resolve() }
118
+ else { promise.reject(withError: Self.failure("deleteItem", status)) }
119
+ return
120
+ }
121
+ let context = Self.context(reason: reason)
122
+ Self.verify(context: context, policy: policy, reason: reason, operation: "deleteItem") {
123
+ error in
124
+ if let error { promise.reject(withError: error); return }
125
+ var lookup = Self.query(key: key)
126
+ lookup[kSecUseAuthenticationContext as String] = context
127
+ let status = SecItemDelete(lookup as CFDictionary)
128
+ if status != errSecSuccess && status != errSecItemNotFound {
129
+ promise.reject(withError: Self.failure("deleteItem", status))
130
+ } else { promise.resolve() }
131
+ }
132
+ } catch {
133
+ promise.reject(withError: error)
134
+ }
135
+ }
136
+ return promise
137
+ }
138
+
139
+ private static func query(key: String) -> [String: Any] {
140
+ [
141
+ kSecClass as String: kSecClassGenericPassword,
142
+ kSecAttrService as String: service,
143
+ kSecAttrAccount as String: key,
144
+ ]
145
+ }
146
+
147
+ private static func context(reason: String) -> LAContext {
148
+ let context = LAContext()
149
+ context.localizedReason = reason
150
+ return context
151
+ }
152
+
153
+ private static func exists(key: String, operation: String) throws -> Bool {
154
+ let context = LAContext()
155
+ context.interactionNotAllowed = true
156
+ var lookup = query(key: key)
157
+ lookup[kSecReturnAttributes as String] = true
158
+ lookup[kSecMatchLimit as String] = kSecMatchLimitOne
159
+ lookup[kSecUseAuthenticationContext as String] = context
160
+ var item: CFTypeRef?
161
+ let status = SecItemCopyMatching(lookup as CFDictionary, &item)
162
+ if status == errSecItemNotFound { return false }
163
+ if status == errSecSuccess || status == errSecInteractionNotAllowed || status == errSecAuthFailed {
164
+ return true
165
+ }
166
+ throw failure(operation, status)
167
+ }
168
+
169
+ private static func read(
170
+ key: String, context: LAContext, operation: String
171
+ ) throws -> (value: String, policy: ProtectedStorePolicy)? {
172
+ var lookup = query(key: key)
173
+ lookup[kSecReturnData as String] = true
174
+ lookup[kSecReturnAttributes as String] = true
175
+ lookup[kSecMatchLimit as String] = kSecMatchLimitOne
176
+ lookup[kSecUseAuthenticationContext as String] = context
177
+ var item: CFTypeRef?
178
+ let status = SecItemCopyMatching(lookup as CFDictionary, &item)
179
+ if status == errSecItemNotFound { return nil }
180
+ guard status == errSecSuccess else { throw failure(operation, status, read: true) }
181
+ guard let attributes = item as? [String: Any],
182
+ let data = attributes[kSecValueData as String] as? Data,
183
+ let value = String(data: data, encoding: .utf8),
184
+ let label = attributes[kSecAttrLabel as String] as? String,
185
+ let storedPolicy = ProtectedStorePolicy(fromString: label) else {
186
+ throw oneNativeError("E_PROTECTED_STORE_GET", "ProtectedStore.\(operation): invalid item")
187
+ }
188
+ return (value, storedPolicy)
189
+ }
190
+
191
+ private static func requirePolicy(
192
+ _ stored: ProtectedStorePolicy, _ requested: ProtectedStorePolicy, operation: String
193
+ ) throws {
194
+ guard stored == requested else {
195
+ throw oneNativeError("E_PROTECTED_STORE_POLICY", "ProtectedStore.\(operation): policy does not match the item")
196
+ }
197
+ }
198
+
199
+ private static func verify(
200
+ context: LAContext, policy: ProtectedStorePolicy, reason: String, operation: String,
201
+ completion: @escaping (Error?) -> Void
202
+ ) {
203
+ let laPolicy: LAPolicy = policy == .userpresence
204
+ ? .deviceOwnerAuthentication : .deviceOwnerAuthenticationWithBiometrics
205
+ if policy == .biometrycurrentset { context.localizedFallbackTitle = "" }
206
+ context.evaluatePolicy(laPolicy, localizedReason: reason) { success, error in
207
+ if success {
208
+ context.interactionNotAllowed = true
209
+ completion(nil)
210
+ return
211
+ }
212
+ let code: String
213
+ switch (error as? LAError)?.code {
214
+ case .userCancel, .appCancel, .systemCancel, .userFallback:
215
+ code = "E_PROTECTED_STORE_CANCELLED"
216
+ default:
217
+ code = "E_PROTECTED_STORE_AUTH"
218
+ }
219
+ completion(oneNativeError(code, "ProtectedStore.\(operation): \(error?.localizedDescription ?? "authentication failed")"))
220
+ }
221
+ }
222
+
223
+ private static func validate(key: String, reason: String? = nil, operation: String) throws {
224
+ guard let usage = Bundle.main.object(forInfoDictionaryKey: "NSFaceIDUsageDescription") as? String,
225
+ !usage.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
226
+ throw oneNativeError(
227
+ "E_PROTECTED_STORE_MANIFEST", "ProtectedStore.\(operation): set native.app.ios.faceIdUsageDescription")
228
+ }
229
+ guard !key.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
230
+ throw oneNativeError("E_PROTECTED_STORE_INPUT", "ProtectedStore.\(operation): key is required")
231
+ }
232
+ if let reason, reason.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
233
+ throw oneNativeError("E_PROTECTED_STORE_INPUT", "ProtectedStore.\(operation): reason is required")
234
+ }
235
+ }
236
+
237
+ private static func failure(_ operation: String, _ status: OSStatus, read: Bool = false) -> RuntimeError {
238
+ let code: String
239
+ switch status {
240
+ case errSecUserCanceled: code = "E_PROTECTED_STORE_CANCELLED"
241
+ case errSecAuthFailed, errSecInteractionNotAllowed: code = "E_PROTECTED_STORE_AUTH"
242
+ default: code = "E_PROTECTED_STORE_\(read || operation == "getItem" ? "GET" : "WRITE")"
243
+ }
244
+ return oneNativeError(code, "ProtectedStore.\(operation): keychain status \(status)")
245
+ }
246
+ }
@@ -56,6 +56,7 @@ target_sources(
56
56
  ../nitrogen/generated/shared/c++/HybridOneNetworkSpec.cpp
57
57
  ../nitrogen/generated/shared/c++/HybridOneNotificationsSpec.cpp
58
58
  ../nitrogen/generated/shared/c++/HybridOnePhotoLibrarySpec.cpp
59
+ ../nitrogen/generated/shared/c++/HybridOneProtectedStoreSpec.cpp
59
60
  ../nitrogen/generated/shared/c++/HybridOneSecureStoreSpec.cpp
60
61
  ../nitrogen/generated/shared/c++/HybridOneShareSpec.cpp
61
62
  ../nitrogen/generated/shared/c++/HybridOneSpeechSpec.cpp
@@ -31,6 +31,7 @@
31
31
  #include "HybridOneNetworkSpecSwift.hpp"
32
32
  #include "HybridOneNotificationsSpecSwift.hpp"
33
33
  #include "HybridOnePhotoLibrarySpecSwift.hpp"
34
+ #include "HybridOneProtectedStoreSpecSwift.hpp"
34
35
  #include "HybridOneSecureStoreSpecSwift.hpp"
35
36
  #include "HybridOneShareSpecSwift.hpp"
36
37
  #include "HybridOneSpeechSpecSwift.hpp"
@@ -784,6 +785,22 @@ namespace margelo::nitro::one::bridge::swift {
784
785
  };
785
786
  }
786
787
 
788
+ // pragma MARK: std::shared_ptr<HybridOneProtectedStoreSpec>
789
+ std::shared_ptr<HybridOneProtectedStoreSpec> create_std__shared_ptr_HybridOneProtectedStoreSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
790
+ One::HybridOneProtectedStoreSpec_cxx swiftPart = One::HybridOneProtectedStoreSpec_cxx::fromUnsafe(swiftUnsafePointer);
791
+ return std::make_shared<margelo::nitro::one::HybridOneProtectedStoreSpecSwift>(swiftPart);
792
+ }
793
+ void* NON_NULL get_std__shared_ptr_HybridOneProtectedStoreSpec_(std__shared_ptr_HybridOneProtectedStoreSpec_ cppType) {
794
+ std::shared_ptr<margelo::nitro::one::HybridOneProtectedStoreSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::one::HybridOneProtectedStoreSpecSwift>(cppType);
795
+ #ifdef NITRO_DEBUG
796
+ if (swiftWrapper == nullptr) [[unlikely]] {
797
+ throw std::runtime_error("Class \"HybridOneProtectedStoreSpec\" is not implemented in Swift!");
798
+ }
799
+ #endif
800
+ One::HybridOneProtectedStoreSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
801
+ return swiftPart.toUnsafe();
802
+ }
803
+
787
804
  // pragma MARK: std::shared_ptr<HybridOneSecureStoreSpec>
788
805
  std::shared_ptr<HybridOneSecureStoreSpec> create_std__shared_ptr_HybridOneSecureStoreSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
789
806
  One::HybridOneSecureStoreSpec_cxx swiftPart = One::HybridOneSecureStoreSpec_cxx::fromUnsafe(swiftUnsafePointer);
@@ -130,6 +130,8 @@ namespace margelo::nitro::one { class HybridOneNetworkSpec; }
130
130
  namespace margelo::nitro::one { class HybridOneNotificationsSpec; }
131
131
  // Forward declaration of `HybridOnePhotoLibrarySpec` to properly resolve imports.
132
132
  namespace margelo::nitro::one { class HybridOnePhotoLibrarySpec; }
133
+ // Forward declaration of `HybridOneProtectedStoreSpec` to properly resolve imports.
134
+ namespace margelo::nitro::one { class HybridOneProtectedStoreSpec; }
133
135
  // Forward declaration of `HybridOneSecureStoreSpec` to properly resolve imports.
134
136
  namespace margelo::nitro::one { class HybridOneSecureStoreSpec; }
135
137
  // Forward declaration of `HybridOneShareSpec` to properly resolve imports.
@@ -270,6 +272,8 @@ namespace One { class HybridOneNetworkSpec_cxx; }
270
272
  namespace One { class HybridOneNotificationsSpec_cxx; }
271
273
  // Forward declaration of `HybridOnePhotoLibrarySpec_cxx` to properly resolve imports.
272
274
  namespace One { class HybridOnePhotoLibrarySpec_cxx; }
275
+ // Forward declaration of `HybridOneProtectedStoreSpec_cxx` to properly resolve imports.
276
+ namespace One { class HybridOneProtectedStoreSpec_cxx; }
273
277
  // Forward declaration of `HybridOneSecureStoreSpec_cxx` to properly resolve imports.
274
278
  namespace One { class HybridOneSecureStoreSpec_cxx; }
275
279
  // Forward declaration of `HybridOneShareSpec_cxx` to properly resolve imports.
@@ -340,6 +344,7 @@ namespace One { class HybridOneUpdatesSpec_cxx; }
340
344
  #include "HybridOneNetworkSpec.hpp"
341
345
  #include "HybridOneNotificationsSpec.hpp"
342
346
  #include "HybridOnePhotoLibrarySpec.hpp"
347
+ #include "HybridOneProtectedStoreSpec.hpp"
343
348
  #include "HybridOneSecureStoreSpec.hpp"
344
349
  #include "HybridOneShareSpec.hpp"
345
350
  #include "HybridOneSpeechSpec.hpp"
@@ -3229,17 +3234,17 @@ namespace margelo::nitro::one::bridge::swift {
3229
3234
  return Func_void_std__optional_std__string__Wrapper(std::move(value));
3230
3235
  }
3231
3236
 
3232
- // pragma MARK: std::shared_ptr<HybridOneSecureStoreSpec>
3237
+ // pragma MARK: std::shared_ptr<HybridOneProtectedStoreSpec>
3233
3238
  /**
3234
- * Specialized version of `std::shared_ptr<HybridOneSecureStoreSpec>`.
3239
+ * Specialized version of `std::shared_ptr<HybridOneProtectedStoreSpec>`.
3235
3240
  */
3236
- using std__shared_ptr_HybridOneSecureStoreSpec_ = std::shared_ptr<HybridOneSecureStoreSpec>;
3237
- std::shared_ptr<HybridOneSecureStoreSpec> create_std__shared_ptr_HybridOneSecureStoreSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
3238
- void* NON_NULL get_std__shared_ptr_HybridOneSecureStoreSpec_(std__shared_ptr_HybridOneSecureStoreSpec_ cppType);
3241
+ using std__shared_ptr_HybridOneProtectedStoreSpec_ = std::shared_ptr<HybridOneProtectedStoreSpec>;
3242
+ std::shared_ptr<HybridOneProtectedStoreSpec> create_std__shared_ptr_HybridOneProtectedStoreSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
3243
+ void* NON_NULL get_std__shared_ptr_HybridOneProtectedStoreSpec_(std__shared_ptr_HybridOneProtectedStoreSpec_ cppType);
3239
3244
 
3240
- // pragma MARK: std::weak_ptr<HybridOneSecureStoreSpec>
3241
- using std__weak_ptr_HybridOneSecureStoreSpec_ = std::weak_ptr<HybridOneSecureStoreSpec>;
3242
- inline std__weak_ptr_HybridOneSecureStoreSpec_ weakify_std__shared_ptr_HybridOneSecureStoreSpec_(const std::shared_ptr<HybridOneSecureStoreSpec>& strong) noexcept { return strong; }
3245
+ // pragma MARK: std::weak_ptr<HybridOneProtectedStoreSpec>
3246
+ using std__weak_ptr_HybridOneProtectedStoreSpec_ = std::weak_ptr<HybridOneProtectedStoreSpec>;
3247
+ inline std__weak_ptr_HybridOneProtectedStoreSpec_ weakify_std__shared_ptr_HybridOneProtectedStoreSpec_(const std::shared_ptr<HybridOneProtectedStoreSpec>& strong) noexcept { return strong; }
3243
3248
 
3244
3249
  // pragma MARK: Result<std::shared_ptr<Promise<std::optional<std::string>>>>
3245
3250
  using Result_std__shared_ptr_Promise_std__optional_std__string____ = Result<std::shared_ptr<Promise<std::optional<std::string>>>>;
@@ -3250,6 +3255,18 @@ namespace margelo::nitro::one::bridge::swift {
3250
3255
  return Result<std::shared_ptr<Promise<std::optional<std::string>>>>::withError(error);
3251
3256
  }
3252
3257
 
3258
+ // pragma MARK: std::shared_ptr<HybridOneSecureStoreSpec>
3259
+ /**
3260
+ * Specialized version of `std::shared_ptr<HybridOneSecureStoreSpec>`.
3261
+ */
3262
+ using std__shared_ptr_HybridOneSecureStoreSpec_ = std::shared_ptr<HybridOneSecureStoreSpec>;
3263
+ std::shared_ptr<HybridOneSecureStoreSpec> create_std__shared_ptr_HybridOneSecureStoreSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
3264
+ void* NON_NULL get_std__shared_ptr_HybridOneSecureStoreSpec_(std__shared_ptr_HybridOneSecureStoreSpec_ cppType);
3265
+
3266
+ // pragma MARK: std::weak_ptr<HybridOneSecureStoreSpec>
3267
+ using std__weak_ptr_HybridOneSecureStoreSpec_ = std::weak_ptr<HybridOneSecureStoreSpec>;
3268
+ inline std__weak_ptr_HybridOneSecureStoreSpec_ weakify_std__shared_ptr_HybridOneSecureStoreSpec_(const std::shared_ptr<HybridOneSecureStoreSpec>& strong) noexcept { return strong; }
3269
+
3253
3270
  // pragma MARK: Result<std::optional<std::string>>
3254
3271
  using Result_std__optional_std__string__ = Result<std::optional<std::string>>;
3255
3272
  inline Result_std__optional_std__string__ create_Result_std__optional_std__string__(const std::optional<std::string>& value) noexcept {
@@ -148,6 +148,8 @@ namespace margelo::nitro::one { class HybridOneNetworkSpec; }
148
148
  namespace margelo::nitro::one { class HybridOneNotificationsSpec; }
149
149
  // Forward declaration of `HybridOnePhotoLibrarySpec` to properly resolve imports.
150
150
  namespace margelo::nitro::one { class HybridOnePhotoLibrarySpec; }
151
+ // Forward declaration of `HybridOneProtectedStoreSpec` to properly resolve imports.
152
+ namespace margelo::nitro::one { class HybridOneProtectedStoreSpec; }
151
153
  // Forward declaration of `HybridOneSecureStoreSpec` to properly resolve imports.
152
154
  namespace margelo::nitro::one { class HybridOneSecureStoreSpec; }
153
155
  // Forward declaration of `HybridOneShareSpec` to properly resolve imports.
@@ -234,6 +236,8 @@ namespace margelo::nitro::one { struct OneUpdatesFetchResult; }
234
236
  namespace margelo::nitro::one { enum class OneUpdatesFetchType; }
235
237
  // Forward declaration of `PhotoLibraryPermissionStatus` to properly resolve imports.
236
238
  namespace margelo::nitro::one { enum class PhotoLibraryPermissionStatus; }
239
+ // Forward declaration of `ProtectedStorePolicy` to properly resolve imports.
240
+ namespace margelo::nitro::one { enum class ProtectedStorePolicy; }
237
241
  // Forward declaration of `ReminderInfo` to properly resolve imports.
238
242
  namespace margelo::nitro::one { struct ReminderInfo; }
239
243
  // Forward declaration of `ReminderInput` to properly resolve imports.
@@ -336,6 +340,7 @@ namespace margelo::nitro::one { enum class UserInterfaceSizeClass; }
336
340
  #include "HybridOneNetworkSpec.hpp"
337
341
  #include "HybridOneNotificationsSpec.hpp"
338
342
  #include "HybridOnePhotoLibrarySpec.hpp"
343
+ #include "HybridOneProtectedStoreSpec.hpp"
339
344
  #include "HybridOneSecureStoreSpec.hpp"
340
345
  #include "HybridOneShareSpec.hpp"
341
346
  #include "HybridOneSpeechSpec.hpp"
@@ -379,6 +384,7 @@ namespace margelo::nitro::one { enum class UserInterfaceSizeClass; }
379
384
  #include "OneUpdatesFetchResult.hpp"
380
385
  #include "OneUpdatesFetchType.hpp"
381
386
  #include "PhotoLibraryPermissionStatus.hpp"
387
+ #include "ProtectedStorePolicy.hpp"
382
388
  #include "ReminderInfo.hpp"
383
389
  #include "ReminderInput.hpp"
384
390
  #include "ResolvedDocumentPickerOptions.hpp"
@@ -461,6 +467,8 @@ namespace One { class HybridOneNetworkSpec_cxx; }
461
467
  namespace One { class HybridOneNotificationsSpec_cxx; }
462
468
  // Forward declaration of `HybridOnePhotoLibrarySpec_cxx` to properly resolve imports.
463
469
  namespace One { class HybridOnePhotoLibrarySpec_cxx; }
470
+ // Forward declaration of `HybridOneProtectedStoreSpec_cxx` to properly resolve imports.
471
+ namespace One { class HybridOneProtectedStoreSpec_cxx; }
464
472
  // Forward declaration of `HybridOneSecureStoreSpec_cxx` to properly resolve imports.
465
473
  namespace One { class HybridOneSecureStoreSpec_cxx; }
466
474
  // Forward declaration of `HybridOneShareSpec_cxx` to properly resolve imports.
@@ -26,6 +26,7 @@
26
26
  #include "HybridOneFetchSpecSwift.hpp"
27
27
  #include "HybridOneAppleAuthSpecSwift.hpp"
28
28
  #include "HybridOneLocalAuthenticationSpecSwift.hpp"
29
+ #include "HybridOneProtectedStoreSpecSwift.hpp"
29
30
  #include "HybridOneLocationSpecSwift.hpp"
30
31
  #include "HybridOneFileSystemSpecSwift.hpp"
31
32
  #include "HybridOneAudioSpecSwift.hpp"
@@ -159,6 +160,13 @@
159
160
  return hybridObject;
160
161
  }
161
162
  );
163
+ HybridObjectRegistry::registerHybridObjectConstructor(
164
+ "OneProtectedStore",
165
+ []() -> std::shared_ptr<HybridObject> {
166
+ std::shared_ptr<HybridOneProtectedStoreSpec> hybridObject = One::OneAutolinking::createOneProtectedStore();
167
+ return hybridObject;
168
+ }
169
+ );
162
170
  HybridObjectRegistry::registerHybridObjectConstructor(
163
171
  "OneLocation",
164
172
  []() -> std::shared_ptr<HybridObject> {
@@ -204,6 +204,18 @@ public final class OneAutolinking {
204
204
  return HybridOneLocalAuthentication.self is any RecyclableView.Type
205
205
  }
206
206
 
207
+ public static func createOneProtectedStore() -> bridge.std__shared_ptr_HybridOneProtectedStoreSpec_ {
208
+ let hybridObject = HybridOneProtectedStore()
209
+ return { () -> bridge.std__shared_ptr_HybridOneProtectedStoreSpec_ in
210
+ let __cxxWrapped = hybridObject.getCxxWrapper()
211
+ return __cxxWrapped.getCxxPart()
212
+ }()
213
+ }
214
+
215
+ public static func isOneProtectedStoreRecyclable() -> Bool {
216
+ return HybridOneProtectedStore.self is any RecyclableView.Type
217
+ }
218
+
207
219
  public static func createOneLocation() -> bridge.std__shared_ptr_HybridOneLocationSpec_ {
208
220
  let hybridObject = HybridOneLocation()
209
221
  return { () -> bridge.std__shared_ptr_HybridOneLocationSpec_ in
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridOneProtectedStoreSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridOneProtectedStoreSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::one {
11
+ } // namespace margelo::nitro::one
@@ -0,0 +1,110 @@
1
+ ///
2
+ /// HybridOneProtectedStoreSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridOneProtectedStoreSpec.hpp"
11
+
12
+ // Forward declaration of `HybridOneProtectedStoreSpec_cxx` to properly resolve imports.
13
+ namespace One { class HybridOneProtectedStoreSpec_cxx; }
14
+
15
+ // Forward declaration of `ProtectedStorePolicy` to properly resolve imports.
16
+ namespace margelo::nitro::one { enum class ProtectedStorePolicy; }
17
+
18
+ #include <NitroModules/Promise.hpp>
19
+ #include <string>
20
+ #include "ProtectedStorePolicy.hpp"
21
+ #include <optional>
22
+
23
+ #include "One-Swift-Cxx-Umbrella.hpp"
24
+
25
+ namespace margelo::nitro::one {
26
+
27
+ /**
28
+ * The C++ part of HybridOneProtectedStoreSpec_cxx.swift.
29
+ *
30
+ * HybridOneProtectedStoreSpecSwift (C++) accesses HybridOneProtectedStoreSpec_cxx (Swift), and might
31
+ * contain some additional bridging code for C++ <> Swift interop.
32
+ *
33
+ * Since this obviously introduces an overhead, I hope at some point in
34
+ * the future, HybridOneProtectedStoreSpec_cxx can directly inherit from the C++ class HybridOneProtectedStoreSpec
35
+ * to simplify the whole structure and memory management.
36
+ */
37
+ class HybridOneProtectedStoreSpecSwift: public virtual HybridOneProtectedStoreSpec {
38
+ public:
39
+ // Constructor from a Swift instance
40
+ explicit HybridOneProtectedStoreSpecSwift(const One::HybridOneProtectedStoreSpec_cxx& swiftPart):
41
+ HybridObject(HybridOneProtectedStoreSpec::TAG),
42
+ _swiftPart(swiftPart) { }
43
+
44
+ public:
45
+ // Get the Swift part
46
+ inline One::HybridOneProtectedStoreSpec_cxx& getSwiftPart() noexcept {
47
+ return _swiftPart;
48
+ }
49
+
50
+ public:
51
+ inline size_t getExternalMemorySize() noexcept override {
52
+ return _swiftPart.getMemorySize();
53
+ }
54
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
55
+ if (auto otherCast = std::dynamic_pointer_cast<HybridOneProtectedStoreSpecSwift>(other)) {
56
+ return _swiftPart.equals(otherCast->_swiftPart);
57
+ }
58
+ return false;
59
+ }
60
+ void dispose() noexcept override {
61
+ _swiftPart.dispose();
62
+ }
63
+ std::string toString() override {
64
+ return _swiftPart.toString();
65
+ }
66
+
67
+ public:
68
+ // Properties
69
+
70
+
71
+ public:
72
+ // Methods
73
+ inline std::shared_ptr<Promise<void>> createItem(const std::string& key, const std::string& value, ProtectedStorePolicy policy) override {
74
+ auto __result = _swiftPart.createItem(key, value, static_cast<int>(policy));
75
+ if (__result.hasError()) [[unlikely]] {
76
+ std::rethrow_exception(__result.error());
77
+ }
78
+ auto __value = std::move(__result.value());
79
+ return __value;
80
+ }
81
+ inline std::shared_ptr<Promise<std::optional<std::string>>> getItem(const std::string& key, const std::string& reason, ProtectedStorePolicy policy) override {
82
+ auto __result = _swiftPart.getItem(key, reason, static_cast<int>(policy));
83
+ if (__result.hasError()) [[unlikely]] {
84
+ std::rethrow_exception(__result.error());
85
+ }
86
+ auto __value = std::move(__result.value());
87
+ return __value;
88
+ }
89
+ inline std::shared_ptr<Promise<void>> updateItem(const std::string& key, const std::string& value, const std::string& reason, ProtectedStorePolicy policy) override {
90
+ auto __result = _swiftPart.updateItem(key, value, reason, static_cast<int>(policy));
91
+ if (__result.hasError()) [[unlikely]] {
92
+ std::rethrow_exception(__result.error());
93
+ }
94
+ auto __value = std::move(__result.value());
95
+ return __value;
96
+ }
97
+ inline std::shared_ptr<Promise<void>> deleteItem(const std::string& key, const std::string& reason, ProtectedStorePolicy policy) override {
98
+ auto __result = _swiftPart.deleteItem(key, reason, static_cast<int>(policy));
99
+ if (__result.hasError()) [[unlikely]] {
100
+ std::rethrow_exception(__result.error());
101
+ }
102
+ auto __value = std::move(__result.value());
103
+ return __value;
104
+ }
105
+
106
+ private:
107
+ One::HybridOneProtectedStoreSpec_cxx _swiftPart;
108
+ };
109
+
110
+ } // namespace margelo::nitro::one
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// HybridOneProtectedStoreSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /// See ``HybridOneProtectedStoreSpec``
11
+ public protocol HybridOneProtectedStoreSpec_protocol: HybridObject {
12
+ // Properties
13
+
14
+
15
+ // Methods
16
+ func createItem(key: String, value: String, policy: ProtectedStorePolicy) throws -> Promise<Void>
17
+ func getItem(key: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<String?>
18
+ func updateItem(key: String, value: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<Void>
19
+ func deleteItem(key: String, reason: String, policy: ProtectedStorePolicy) throws -> Promise<Void>
20
+ }
21
+
22
+ public extension HybridOneProtectedStoreSpec_protocol {
23
+ /// Default implementation of ``HybridObject.toString``
24
+ func toString() -> String {
25
+ return "[HybridObject OneProtectedStore]"
26
+ }
27
+ }
28
+
29
+ /// See ``HybridOneProtectedStoreSpec``
30
+ open class HybridOneProtectedStoreSpec_base {
31
+ private weak var cxxWrapper: HybridOneProtectedStoreSpec_cxx? = nil
32
+ public init() { }
33
+ public func getCxxWrapper() -> HybridOneProtectedStoreSpec_cxx {
34
+ #if DEBUG
35
+ guard self is any HybridOneProtectedStoreSpec else {
36
+ fatalError("`self` is not a `HybridOneProtectedStoreSpec`! Did you accidentally inherit from `HybridOneProtectedStoreSpec_base` instead of `HybridOneProtectedStoreSpec`?")
37
+ }
38
+ #endif
39
+ if let cxxWrapper = self.cxxWrapper {
40
+ return cxxWrapper
41
+ } else {
42
+ let cxxWrapper = HybridOneProtectedStoreSpec_cxx(self as! any HybridOneProtectedStoreSpec)
43
+ self.cxxWrapper = cxxWrapper
44
+ return cxxWrapper
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * A Swift base-protocol representing the OneProtectedStore HybridObject.
51
+ * Implement this protocol to create Swift-based instances of OneProtectedStore.
52
+ * ```swift
53
+ * class HybridOneProtectedStore : HybridOneProtectedStoreSpec {
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ public typealias HybridOneProtectedStoreSpec = HybridOneProtectedStoreSpec_protocol & HybridOneProtectedStoreSpec_base