react-native-nitro-passkeys 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 +21 -0
- package/NitroPasskeys.podspec +37 -0
- package/README.md +314 -0
- package/android/CMakeLists.txt +31 -0
- package/android/build.gradle +155 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/margelo/nitro/nitropasskeys/HybridNitroPasskeys.kt +65 -0
- package/android/src/main/java/com/margelo/nitro/nitropasskeys/NitroPasskeysPackage.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitropasskeys/PasskeyErrorToken.kt +64 -0
- package/android/src/test/java/com/margelo/nitro/nitropasskeys/PasskeyErrorTokenTest.kt +128 -0
- package/ios/Base64URL.swift +37 -0
- package/ios/Bridge.h +1 -0
- package/ios/HybridNitroPasskeys.swift +290 -0
- package/ios/PasskeyErrorToken.swift +32 -0
- package/ios/PasskeyJSON.swift +195 -0
- package/lib/commonjs/PasskeyError.js +39 -0
- package/lib/commonjs/PasskeyError.js.map +1 -0
- package/lib/commonjs/index.js +52 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/response.js +30 -0
- package/lib/commonjs/response.js.map +1 -0
- package/lib/commonjs/specs/nitro-passkeys.nitro.js +6 -0
- package/lib/commonjs/specs/nitro-passkeys.nitro.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/validate.js +118 -0
- package/lib/commonjs/validate.js.map +1 -0
- package/lib/module/PasskeyError.js +34 -0
- package/lib/module/PasskeyError.js.map +1 -0
- package/lib/module/index.js +42 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/response.js +25 -0
- package/lib/module/response.js.map +1 -0
- package/lib/module/specs/nitro-passkeys.nitro.js +4 -0
- package/lib/module/specs/nitro-passkeys.nitro.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/validate.js +109 -0
- package/lib/module/validate.js.map +1 -0
- package/lib/typescript/example/server/index.d.ts +2 -0
- package/lib/typescript/example/server/index.d.ts.map +1 -0
- package/lib/typescript/src/PasskeyError.d.ts +8 -0
- package/lib/typescript/src/PasskeyError.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/response.d.ts +4 -0
- package/lib/typescript/src/response.d.ts.map +1 -0
- package/lib/typescript/src/specs/nitro-passkeys.nitro.d.ts +12 -0
- package/lib/typescript/src/specs/nitro-passkeys.nitro.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +104 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/validate.d.ts +14 -0
- package/lib/typescript/src/validate.d.ts.map +1 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroPasskeys+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroPasskeys+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroPasskeysOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroPasskeysOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JHybridNitroPasskeysSpec.cpp +86 -0
- package/nitrogen/generated/android/c++/JHybridNitroPasskeysSpec.hpp +64 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitropasskeys/HybridNitroPasskeysSpec.kt +63 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitropasskeys/NitroPasskeysOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroPasskeys+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroPasskeys-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/NitroPasskeys-Swift-Cxx-Bridge.hpp +111 -0
- package/nitrogen/generated/ios/NitroPasskeys-Swift-Cxx-Umbrella.hpp +45 -0
- package/nitrogen/generated/ios/NitroPasskeysAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroPasskeysAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroPasskeysSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroPasskeysSpecSwift.hpp +93 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNitroPasskeysSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroPasskeysSpec_cxx.swift +169 -0
- package/nitrogen/generated/shared/c++/HybridNitroPasskeysSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroPasskeysSpec.hpp +64 -0
- package/package.json +106 -0
- package/src/PasskeyError.ts +58 -0
- package/src/index.ts +66 -0
- package/src/response.ts +49 -0
- package/src/specs/nitro-passkeys.nitro.ts +12 -0
- package/src/types.ts +124 -0
- package/src/validate.ts +132 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string.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
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: String) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__string {
|
|
15
|
+
public typealias bridge = margelo.nitro.nitropasskeys.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: String) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: String) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: std.string) -> Void {
|
|
25
|
+
self.closure(String(value))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__string`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__string>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string {
|
|
44
|
+
return Unmanaged<Func_void_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroPasskeysSpec.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 ``HybridNitroPasskeysSpec``
|
|
11
|
+
public protocol HybridNitroPasskeysSpec_protocol: HybridObject {
|
|
12
|
+
// Properties
|
|
13
|
+
var isSupported: Bool { get }
|
|
14
|
+
|
|
15
|
+
// Methods
|
|
16
|
+
func create(creationOptionsJson: String) throws -> Promise<String>
|
|
17
|
+
func get(requestOptionsJson: String) throws -> Promise<String>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public extension HybridNitroPasskeysSpec_protocol {
|
|
21
|
+
/// Default implementation of ``HybridObject.toString``
|
|
22
|
+
func toString() -> String {
|
|
23
|
+
return "[HybridObject NitroPasskeys]"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// See ``HybridNitroPasskeysSpec``
|
|
28
|
+
open class HybridNitroPasskeysSpec_base {
|
|
29
|
+
private weak var cxxWrapper: HybridNitroPasskeysSpec_cxx? = nil
|
|
30
|
+
public init() { }
|
|
31
|
+
public func getCxxWrapper() -> HybridNitroPasskeysSpec_cxx {
|
|
32
|
+
#if DEBUG
|
|
33
|
+
guard self is any HybridNitroPasskeysSpec else {
|
|
34
|
+
fatalError("`self` is not a `HybridNitroPasskeysSpec`! Did you accidentally inherit from `HybridNitroPasskeysSpec_base` instead of `HybridNitroPasskeysSpec`?")
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
38
|
+
return cxxWrapper
|
|
39
|
+
} else {
|
|
40
|
+
let cxxWrapper = HybridNitroPasskeysSpec_cxx(self as! any HybridNitroPasskeysSpec)
|
|
41
|
+
self.cxxWrapper = cxxWrapper
|
|
42
|
+
return cxxWrapper
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A Swift base-protocol representing the NitroPasskeys HybridObject.
|
|
49
|
+
* Implement this protocol to create Swift-based instances of NitroPasskeys.
|
|
50
|
+
* ```swift
|
|
51
|
+
* class HybridNitroPasskeys : HybridNitroPasskeysSpec {
|
|
52
|
+
* // ...
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
public typealias HybridNitroPasskeysSpec = HybridNitroPasskeysSpec_protocol & HybridNitroPasskeysSpec_base
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroPasskeysSpec_cxx.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
|
+
/**
|
|
11
|
+
* A class implementation that bridges HybridNitroPasskeysSpec over to C++.
|
|
12
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
13
|
+
*
|
|
14
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
15
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
16
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
17
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
18
|
+
*/
|
|
19
|
+
open class HybridNitroPasskeysSpec_cxx {
|
|
20
|
+
/**
|
|
21
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::nitropasskeys::bridge::swift`)
|
|
22
|
+
* from `NitroPasskeys-Swift-Cxx-Bridge.hpp`.
|
|
23
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
24
|
+
*/
|
|
25
|
+
public typealias bridge = margelo.nitro.nitropasskeys.bridge.swift
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Holds an instance of the `HybridNitroPasskeysSpec` Swift protocol.
|
|
29
|
+
*/
|
|
30
|
+
private var __implementation: any HybridNitroPasskeysSpec
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
34
|
+
*/
|
|
35
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridNitroPasskeysSpec_
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a new `HybridNitroPasskeysSpec_cxx` that wraps the given `HybridNitroPasskeysSpec`.
|
|
39
|
+
* All properties and methods bridge to C++ types.
|
|
40
|
+
*/
|
|
41
|
+
public init(_ implementation: any HybridNitroPasskeysSpec) {
|
|
42
|
+
self.__implementation = implementation
|
|
43
|
+
self.__cxxPart = .init()
|
|
44
|
+
/* no base class */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the actual `HybridNitroPasskeysSpec` instance this class wraps.
|
|
49
|
+
*/
|
|
50
|
+
@inline(__always)
|
|
51
|
+
public func getHybridNitroPasskeysSpec() -> any HybridNitroPasskeysSpec {
|
|
52
|
+
return __implementation
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
57
|
+
* This acquires one additional strong reference on the object!
|
|
58
|
+
*/
|
|
59
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
60
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Casts an unsafe pointer to a `HybridNitroPasskeysSpec_cxx`.
|
|
65
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridNitroPasskeysSpec_cxx>`.
|
|
66
|
+
* This removes one strong reference from the object!
|
|
67
|
+
*/
|
|
68
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNitroPasskeysSpec_cxx {
|
|
69
|
+
return Unmanaged<HybridNitroPasskeysSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
74
|
+
* The C++ part is a `std::shared_ptr<HybridNitroPasskeysSpec>`.
|
|
75
|
+
*/
|
|
76
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridNitroPasskeysSpec_ {
|
|
77
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
78
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
79
|
+
return cachedCxxPart
|
|
80
|
+
} else {
|
|
81
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridNitroPasskeysSpec_(self.toUnsafe())
|
|
82
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridNitroPasskeysSpec_(newCxxPart)
|
|
83
|
+
return newCxxPart
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
91
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
92
|
+
*/
|
|
93
|
+
@inline(__always)
|
|
94
|
+
public var memorySize: Int {
|
|
95
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Compares this object with the given [other] object for reference equality.
|
|
100
|
+
*/
|
|
101
|
+
@inline(__always)
|
|
102
|
+
public func equals(other: HybridNitroPasskeysSpec_cxx) -> Bool {
|
|
103
|
+
return self.__implementation === other.__implementation
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Call dispose() on the Swift class.
|
|
108
|
+
* This _may_ be called manually from JS.
|
|
109
|
+
*/
|
|
110
|
+
@inline(__always)
|
|
111
|
+
public func dispose() {
|
|
112
|
+
self.__implementation.dispose()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Call toString() on the Swift class.
|
|
117
|
+
*/
|
|
118
|
+
@inline(__always)
|
|
119
|
+
public func toString() -> String {
|
|
120
|
+
return self.__implementation.toString()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Properties
|
|
124
|
+
public final var isSupported: Bool {
|
|
125
|
+
@inline(__always)
|
|
126
|
+
get {
|
|
127
|
+
return self.__implementation.isSupported
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Methods
|
|
132
|
+
@inline(__always)
|
|
133
|
+
public final func create(creationOptionsJson: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
134
|
+
do {
|
|
135
|
+
let __result = try self.__implementation.create(creationOptionsJson: String(creationOptionsJson))
|
|
136
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
137
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
138
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
139
|
+
__result
|
|
140
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
141
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
142
|
+
return __promise
|
|
143
|
+
}()
|
|
144
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
145
|
+
} catch (let __error) {
|
|
146
|
+
let __exceptionPtr = __error.toCpp()
|
|
147
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@inline(__always)
|
|
152
|
+
public final func get(requestOptionsJson: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
153
|
+
do {
|
|
154
|
+
let __result = try self.__implementation.get(requestOptionsJson: String(requestOptionsJson))
|
|
155
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
156
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
157
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
158
|
+
__result
|
|
159
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
160
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
161
|
+
return __promise
|
|
162
|
+
}()
|
|
163
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
164
|
+
} catch (let __error) {
|
|
165
|
+
let __exceptionPtr = __error.toCpp()
|
|
166
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroPasskeysSpec.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 "HybridNitroPasskeysSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitropasskeys {
|
|
11
|
+
|
|
12
|
+
void HybridNitroPasskeysSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isSupported", &HybridNitroPasskeysSpec::getIsSupported);
|
|
18
|
+
prototype.registerHybridMethod("create", &HybridNitroPasskeysSpec::create);
|
|
19
|
+
prototype.registerHybridMethod("get", &HybridNitroPasskeysSpec::get);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::nitropasskeys
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroPasskeysSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#include <string>
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::nitropasskeys {
|
|
22
|
+
|
|
23
|
+
using namespace margelo::nitro;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An abstract base class for `NitroPasskeys`
|
|
27
|
+
* Inherit this class to create instances of `HybridNitroPasskeysSpec` in C++.
|
|
28
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
29
|
+
* @example
|
|
30
|
+
* ```cpp
|
|
31
|
+
* class HybridNitroPasskeys: public HybridNitroPasskeysSpec {
|
|
32
|
+
* public:
|
|
33
|
+
* HybridNitroPasskeys(...): HybridObject(TAG) { ... }
|
|
34
|
+
* // ...
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class HybridNitroPasskeysSpec: public virtual HybridObject {
|
|
39
|
+
public:
|
|
40
|
+
// Constructor
|
|
41
|
+
explicit HybridNitroPasskeysSpec(): HybridObject(TAG) { }
|
|
42
|
+
|
|
43
|
+
// Destructor
|
|
44
|
+
~HybridNitroPasskeysSpec() override = default;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
// Properties
|
|
48
|
+
virtual bool getIsSupported() = 0;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Methods
|
|
52
|
+
virtual std::shared_ptr<Promise<std::string>> create(const std::string& creationOptionsJson) = 0;
|
|
53
|
+
virtual std::shared_ptr<Promise<std::string>> get(const std::string& requestOptionsJson) = 0;
|
|
54
|
+
|
|
55
|
+
protected:
|
|
56
|
+
// Hybrid Setup
|
|
57
|
+
void loadHybridMethods() override;
|
|
58
|
+
|
|
59
|
+
protected:
|
|
60
|
+
// Tag for logging
|
|
61
|
+
static constexpr auto TAG = "NitroPasskeys";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace margelo::nitro::nitropasskeys
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-nitro-passkeys",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WebAuthn passkeys for bare React Native, built with Nitro Modules",
|
|
5
|
+
"main": "./lib/commonjs/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "oxlint && oxfmt --check",
|
|
13
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
14
|
+
"format": "oxfmt",
|
|
15
|
+
"test": "bun test src",
|
|
16
|
+
"example:server": "bun example/server/index.ts",
|
|
17
|
+
"clean": "git clean -dfX",
|
|
18
|
+
"prepare": "lefthook install || true",
|
|
19
|
+
"release": "semantic-release",
|
|
20
|
+
"build": "bun run typecheck && bob build",
|
|
21
|
+
"codegen": "nitrogen --logLevel=\"debug\" && bun run build"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react-native",
|
|
25
|
+
"nitro",
|
|
26
|
+
"passkeys",
|
|
27
|
+
"webauthn",
|
|
28
|
+
"fido2",
|
|
29
|
+
"react-native-nitro-passkeys"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"!src/**/__tests__",
|
|
34
|
+
"lib",
|
|
35
|
+
"nitrogen",
|
|
36
|
+
"nitro.json",
|
|
37
|
+
"android/build.gradle",
|
|
38
|
+
"android/fix-prefab.gradle",
|
|
39
|
+
"android/gradle.properties",
|
|
40
|
+
"android/CMakeLists.txt",
|
|
41
|
+
"android/src",
|
|
42
|
+
"ios/**/*.h",
|
|
43
|
+
"ios/**/*.m",
|
|
44
|
+
"ios/**/*.mm",
|
|
45
|
+
"ios/**/*.cpp",
|
|
46
|
+
"ios/**/*.swift",
|
|
47
|
+
"*.podspec",
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
50
|
+
"workspaces": [
|
|
51
|
+
"example"
|
|
52
|
+
],
|
|
53
|
+
"repository": "https://github.com/aparedes/react-native-nitro-passkeys.git",
|
|
54
|
+
"author": "aparedes",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": "https://github.com/aparedes/react-native-nitro-passkeys/issues",
|
|
57
|
+
"homepage": "https://github.com/aparedes/react-native-nitro-passkeys#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"registry": "https://registry.npmjs.org/"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"react": "*",
|
|
64
|
+
"react-native": "*",
|
|
65
|
+
"react-native-nitro-modules": ">=0.37.1 <0.38.0"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
69
|
+
"@semantic-release/git": "^11.0.1",
|
|
70
|
+
"@simplewebauthn/server": "^14.0.2",
|
|
71
|
+
"@types/bun": "^1.4.0",
|
|
72
|
+
"@types/react": "19.2.18",
|
|
73
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
74
|
+
"lefthook": "^2.1.10",
|
|
75
|
+
"nitrogen": "0.37.1",
|
|
76
|
+
"oxfmt": "^0.65.0",
|
|
77
|
+
"oxlint": "^1.80.0",
|
|
78
|
+
"react": "19.2.3",
|
|
79
|
+
"react-native": "0.87.1",
|
|
80
|
+
"react-native-builder-bob": "^0.43.0",
|
|
81
|
+
"react-native-nitro-modules": "0.37.1",
|
|
82
|
+
"semantic-release": "^25.0.9",
|
|
83
|
+
"typescript": "^7.0.2"
|
|
84
|
+
},
|
|
85
|
+
"overrides": {
|
|
86
|
+
"lodash-es": "4.17.21",
|
|
87
|
+
"typescript": "$typescript"
|
|
88
|
+
},
|
|
89
|
+
"react-native-builder-bob": {
|
|
90
|
+
"source": "src",
|
|
91
|
+
"output": "lib",
|
|
92
|
+
"targets": [
|
|
93
|
+
"commonjs",
|
|
94
|
+
"module",
|
|
95
|
+
[
|
|
96
|
+
"typescript",
|
|
97
|
+
{
|
|
98
|
+
"project": "tsconfig.build.json"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"trustedDependencies": [
|
|
104
|
+
"lefthook"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type PasskeyErrorCode =
|
|
2
|
+
| 'canceled'
|
|
3
|
+
| 'noCredentials'
|
|
4
|
+
| 'alreadyRegistered'
|
|
5
|
+
| 'domainNotAssociated'
|
|
6
|
+
| 'unsupported'
|
|
7
|
+
| 'invalidOptions'
|
|
8
|
+
| 'unknown';
|
|
9
|
+
|
|
10
|
+
const CODES: ReadonlySet<string> = new Set<PasskeyErrorCode>([
|
|
11
|
+
'canceled',
|
|
12
|
+
'noCredentials',
|
|
13
|
+
'alreadyRegistered',
|
|
14
|
+
'domainNotAssociated',
|
|
15
|
+
'unsupported',
|
|
16
|
+
'invalidOptions',
|
|
17
|
+
'unknown',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const TOKEN_RE = /\[Passkeys:([A-Za-z0-9-]+)\]\s?/;
|
|
21
|
+
const ASAUTH_RE = /^asauth-\d+$/;
|
|
22
|
+
|
|
23
|
+
function codeForToken(token: string | undefined): PasskeyErrorCode {
|
|
24
|
+
if (token === undefined) return 'unknown';
|
|
25
|
+
if (token === 'asauth-1001') return 'canceled';
|
|
26
|
+
if (token === 'asauth-1006') return 'alreadyRegistered';
|
|
27
|
+
if (ASAUTH_RE.test(token)) return 'unknown';
|
|
28
|
+
return CODES.has(token) ? (token as PasskeyErrorCode) : 'unknown';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class PasskeyError extends Error {
|
|
32
|
+
readonly code: PasskeyErrorCode;
|
|
33
|
+
|
|
34
|
+
constructor(code: PasskeyErrorCode, message: string) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'PasskeyError';
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Normalises any thrown value into a `PasskeyError`. Never throws. */
|
|
41
|
+
static from(error: unknown): PasskeyError {
|
|
42
|
+
try {
|
|
43
|
+
if (error instanceof PasskeyError) return error;
|
|
44
|
+
const original =
|
|
45
|
+
error instanceof Error
|
|
46
|
+
? error.message
|
|
47
|
+
: typeof error === 'string'
|
|
48
|
+
? error
|
|
49
|
+
: 'Unknown error';
|
|
50
|
+
const match = TOKEN_RE.exec(original);
|
|
51
|
+
const code = codeForToken(match?.[1]);
|
|
52
|
+
const stripped = match ? original.replace(TOKEN_RE, '') : original;
|
|
53
|
+
return new PasskeyError(code, stripped.length > 0 ? stripped : original);
|
|
54
|
+
} catch {
|
|
55
|
+
return new PasskeyError('unknown', 'Unknown error');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
import { PasskeyError } from './PasskeyError';
|
|
4
|
+
import {
|
|
5
|
+
parseAuthenticationResponse,
|
|
6
|
+
parseRegistrationResponse,
|
|
7
|
+
} from './response';
|
|
8
|
+
import type { NitroPasskeys } from './specs/nitro-passkeys.nitro';
|
|
9
|
+
import type {
|
|
10
|
+
AuthenticationResponseJSON,
|
|
11
|
+
PublicKeyCredentialCreationOptionsJSON,
|
|
12
|
+
PublicKeyCredentialRequestOptionsJSON,
|
|
13
|
+
RegistrationResponseJSON,
|
|
14
|
+
} from './types';
|
|
15
|
+
import { validateCreationOptions, validateRequestOptions } from './validate';
|
|
16
|
+
|
|
17
|
+
// Deliberately not exported: every caller goes through the helpers and gets typed errors.
|
|
18
|
+
const native = NitroModules.createHybridObject<NitroPasskeys>('NitroPasskeys');
|
|
19
|
+
|
|
20
|
+
export function isPasskeySupported(): boolean {
|
|
21
|
+
return native.isSupported;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function createPasskey(
|
|
25
|
+
options: PublicKeyCredentialCreationOptionsJSON,
|
|
26
|
+
): Promise<RegistrationResponseJSON> {
|
|
27
|
+
if (!isPasskeySupported()) {
|
|
28
|
+
throw new PasskeyError(
|
|
29
|
+
'unsupported',
|
|
30
|
+
'Passkeys are not supported on this device',
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const reason = validateCreationOptions(options);
|
|
34
|
+
if (reason) throw new PasskeyError('invalidOptions', reason);
|
|
35
|
+
let raw: string;
|
|
36
|
+
try {
|
|
37
|
+
raw = await native.create(JSON.stringify(options));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw PasskeyError.from(error);
|
|
40
|
+
}
|
|
41
|
+
return parseRegistrationResponse(raw);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function getPasskey(
|
|
45
|
+
options: PublicKeyCredentialRequestOptionsJSON,
|
|
46
|
+
): Promise<AuthenticationResponseJSON> {
|
|
47
|
+
if (!isPasskeySupported()) {
|
|
48
|
+
throw new PasskeyError(
|
|
49
|
+
'unsupported',
|
|
50
|
+
'Passkeys are not supported on this device',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const reason = validateRequestOptions(options);
|
|
54
|
+
if (reason) throw new PasskeyError('invalidOptions', reason);
|
|
55
|
+
let raw: string;
|
|
56
|
+
try {
|
|
57
|
+
raw = await native.get(JSON.stringify(options));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw PasskeyError.from(error);
|
|
60
|
+
}
|
|
61
|
+
return parseAuthenticationResponse(raw);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { PasskeyError } from './PasskeyError';
|
|
65
|
+
export type { PasskeyErrorCode } from './PasskeyError';
|
|
66
|
+
export type * from './types';
|
package/src/response.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PasskeyError } from './PasskeyError';
|
|
2
|
+
import type {
|
|
3
|
+
AuthenticationResponseJSON,
|
|
4
|
+
RegistrationResponseJSON,
|
|
5
|
+
} from './types';
|
|
6
|
+
import {
|
|
7
|
+
validateAuthenticationResponse,
|
|
8
|
+
validateRegistrationResponse,
|
|
9
|
+
} from './validate';
|
|
10
|
+
|
|
11
|
+
function parse<T extends { clientExtensionResults: unknown }>(
|
|
12
|
+
raw: string,
|
|
13
|
+
label: 'registration' | 'authentication',
|
|
14
|
+
validate: (value: unknown) => string | undefined,
|
|
15
|
+
): T {
|
|
16
|
+
let value: unknown;
|
|
17
|
+
try {
|
|
18
|
+
value = JSON.parse(raw);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new PasskeyError('unknown', `Malformed ${label} response: not JSON`);
|
|
21
|
+
}
|
|
22
|
+
const reason = validate(value);
|
|
23
|
+
if (reason)
|
|
24
|
+
throw new PasskeyError('unknown', `Malformed ${label} response: ${reason}`);
|
|
25
|
+
const result = value as T;
|
|
26
|
+
// The only normalisation: nothing else is added, removed or re-encoded.
|
|
27
|
+
result.clientExtensionResults ??= {};
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function parseRegistrationResponse(
|
|
32
|
+
raw: string,
|
|
33
|
+
): RegistrationResponseJSON {
|
|
34
|
+
return parse<RegistrationResponseJSON>(
|
|
35
|
+
raw,
|
|
36
|
+
'registration',
|
|
37
|
+
validateRegistrationResponse,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function parseAuthenticationResponse(
|
|
42
|
+
raw: string,
|
|
43
|
+
): AuthenticationResponseJSON {
|
|
44
|
+
return parse<AuthenticationResponseJSON>(
|
|
45
|
+
raw,
|
|
46
|
+
'authentication',
|
|
47
|
+
validateAuthenticationResponse,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface NitroPasskeys extends HybridObject<{
|
|
4
|
+
ios: 'swift';
|
|
5
|
+
android: 'kotlin';
|
|
6
|
+
}> {
|
|
7
|
+
readonly isSupported: boolean;
|
|
8
|
+
/** creationOptionsJson: PublicKeyCredentialCreationOptionsJSON → RegistrationResponseJSON (both JSON strings). */
|
|
9
|
+
create(creationOptionsJson: string): Promise<string>;
|
|
10
|
+
/** requestOptionsJson: PublicKeyCredentialRequestOptionsJSON → AuthenticationResponseJSON (both JSON strings). */
|
|
11
|
+
get(requestOptionsJson: string): Promise<string>;
|
|
12
|
+
}
|