@doko/react-native-yubikit 0.0.2

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 (144) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +126 -0
  3. package/RNYubikit.podspec +22 -0
  4. package/android/build.gradle +63 -0
  5. package/android/src/main/AndroidManifest.xml +9 -0
  6. package/android/src/main/java/com/yubikit/YubiKitManagerHolder.kt +330 -0
  7. package/android/src/main/java/com/yubikit/YubikitCoreModule.kt +142 -0
  8. package/android/src/main/java/com/yubikit/YubikitFidoModule.kt +418 -0
  9. package/android/src/main/java/com/yubikit/YubikitManagementModule.kt +132 -0
  10. package/android/src/main/java/com/yubikit/YubikitOathModule.kt +224 -0
  11. package/android/src/main/java/com/yubikit/YubikitOpenPgpModule.kt +317 -0
  12. package/android/src/main/java/com/yubikit/YubikitPackage.kt +44 -0
  13. package/android/src/main/java/com/yubikit/YubikitPivModule.kt +310 -0
  14. package/android/src/main/java/com/yubikit/YubikitSupportModule.kt +108 -0
  15. package/android/src/main/java/com/yubikit/YubikitYubiOtpModule.kt +248 -0
  16. package/android/src/main/java/com/yubikit/utils/YubikitUtils.kt +321 -0
  17. package/ios/YubikitCore.h +5 -0
  18. package/ios/YubikitCore.mm +101 -0
  19. package/ios/YubikitDeviceInfoHelper.h +13 -0
  20. package/ios/YubikitDeviceInfoHelper.mm +110 -0
  21. package/ios/YubikitFido.h +5 -0
  22. package/ios/YubikitFido.mm +373 -0
  23. package/ios/YubikitManagement.h +5 -0
  24. package/ios/YubikitManagement.mm +153 -0
  25. package/ios/YubikitManager.h +27 -0
  26. package/ios/YubikitManager.m +169 -0
  27. package/ios/YubikitOath.h +5 -0
  28. package/ios/YubikitOath.mm +583 -0
  29. package/ios/YubikitOpenPgp.h +5 -0
  30. package/ios/YubikitOpenPgp.mm +210 -0
  31. package/ios/YubikitPiv.h +5 -0
  32. package/ios/YubikitPiv.mm +813 -0
  33. package/ios/YubikitSupport.h +5 -0
  34. package/ios/YubikitSupport.mm +58 -0
  35. package/ios/YubikitYubiOtp.h +5 -0
  36. package/ios/YubikitYubiOtp.mm +120 -0
  37. package/lib/module/core.js +34 -0
  38. package/lib/module/core.js.map +1 -0
  39. package/lib/module/fido.js +40 -0
  40. package/lib/module/fido.js.map +1 -0
  41. package/lib/module/hooks/index.js +5 -0
  42. package/lib/module/hooks/index.js.map +1 -0
  43. package/lib/module/hooks/use-yubikey.js +12 -0
  44. package/lib/module/hooks/use-yubikey.js.map +1 -0
  45. package/lib/module/hooks/yubikey-provider.js +85 -0
  46. package/lib/module/hooks/yubikey-provider.js.map +1 -0
  47. package/lib/module/index.js +12 -0
  48. package/lib/module/index.js.map +1 -0
  49. package/lib/module/management.js +17 -0
  50. package/lib/module/management.js.map +1 -0
  51. package/lib/module/oath.js +53 -0
  52. package/lib/module/oath.js.map +1 -0
  53. package/lib/module/openpgp.js +89 -0
  54. package/lib/module/openpgp.js.map +1 -0
  55. package/lib/module/package.json +1 -0
  56. package/lib/module/piv.js +71 -0
  57. package/lib/module/piv.js.map +1 -0
  58. package/lib/module/specs/NativeYubikitCore.js +10 -0
  59. package/lib/module/specs/NativeYubikitCore.js.map +1 -0
  60. package/lib/module/specs/NativeYubikitFido.js +5 -0
  61. package/lib/module/specs/NativeYubikitFido.js.map +1 -0
  62. package/lib/module/specs/NativeYubikitManagement.js +5 -0
  63. package/lib/module/specs/NativeYubikitManagement.js.map +1 -0
  64. package/lib/module/specs/NativeYubikitOath.js +5 -0
  65. package/lib/module/specs/NativeYubikitOath.js.map +1 -0
  66. package/lib/module/specs/NativeYubikitOpenPgp.js +5 -0
  67. package/lib/module/specs/NativeYubikitOpenPgp.js.map +1 -0
  68. package/lib/module/specs/NativeYubikitPiv.js +5 -0
  69. package/lib/module/specs/NativeYubikitPiv.js.map +1 -0
  70. package/lib/module/specs/NativeYubikitSupport.js +5 -0
  71. package/lib/module/specs/NativeYubikitSupport.js.map +1 -0
  72. package/lib/module/specs/NativeYubikitYubiOtp.js +5 -0
  73. package/lib/module/specs/NativeYubikitYubiOtp.js.map +1 -0
  74. package/lib/module/support.js +11 -0
  75. package/lib/module/support.js.map +1 -0
  76. package/lib/module/types.js +2 -0
  77. package/lib/module/types.js.map +1 -0
  78. package/lib/module/yubiotp.js +32 -0
  79. package/lib/module/yubiotp.js.map +1 -0
  80. package/lib/typescript/package.json +1 -0
  81. package/lib/typescript/src/core.d.ts +14 -0
  82. package/lib/typescript/src/core.d.ts.map +1 -0
  83. package/lib/typescript/src/fido.d.ts +24 -0
  84. package/lib/typescript/src/fido.d.ts.map +1 -0
  85. package/lib/typescript/src/hooks/index.d.ts +3 -0
  86. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  87. package/lib/typescript/src/hooks/use-yubikey.d.ts +3 -0
  88. package/lib/typescript/src/hooks/use-yubikey.d.ts.map +1 -0
  89. package/lib/typescript/src/hooks/yubikey-provider.d.ts +23 -0
  90. package/lib/typescript/src/hooks/yubikey-provider.d.ts.map +1 -0
  91. package/lib/typescript/src/index.d.ts +10 -0
  92. package/lib/typescript/src/index.d.ts.map +1 -0
  93. package/lib/typescript/src/management.d.ts +8 -0
  94. package/lib/typescript/src/management.d.ts.map +1 -0
  95. package/lib/typescript/src/oath.d.ts +20 -0
  96. package/lib/typescript/src/oath.d.ts.map +1 -0
  97. package/lib/typescript/src/openpgp.d.ts +35 -0
  98. package/lib/typescript/src/openpgp.d.ts.map +1 -0
  99. package/lib/typescript/src/piv.d.ts +26 -0
  100. package/lib/typescript/src/piv.d.ts.map +1 -0
  101. package/lib/typescript/src/specs/NativeYubikitCore.d.ts +49 -0
  102. package/lib/typescript/src/specs/NativeYubikitCore.d.ts.map +1 -0
  103. package/lib/typescript/src/specs/NativeYubikitFido.d.ts +121 -0
  104. package/lib/typescript/src/specs/NativeYubikitFido.d.ts.map +1 -0
  105. package/lib/typescript/src/specs/NativeYubikitManagement.d.ts +53 -0
  106. package/lib/typescript/src/specs/NativeYubikitManagement.d.ts.map +1 -0
  107. package/lib/typescript/src/specs/NativeYubikitOath.d.ts +70 -0
  108. package/lib/typescript/src/specs/NativeYubikitOath.d.ts.map +1 -0
  109. package/lib/typescript/src/specs/NativeYubikitOpenPgp.d.ts +53 -0
  110. package/lib/typescript/src/specs/NativeYubikitOpenPgp.d.ts.map +1 -0
  111. package/lib/typescript/src/specs/NativeYubikitPiv.d.ts +47 -0
  112. package/lib/typescript/src/specs/NativeYubikitPiv.d.ts.map +1 -0
  113. package/lib/typescript/src/specs/NativeYubikitSupport.d.ts +49 -0
  114. package/lib/typescript/src/specs/NativeYubikitSupport.d.ts.map +1 -0
  115. package/lib/typescript/src/specs/NativeYubikitYubiOtp.d.ts +45 -0
  116. package/lib/typescript/src/specs/NativeYubikitYubiOtp.d.ts.map +1 -0
  117. package/lib/typescript/src/support.d.ts +6 -0
  118. package/lib/typescript/src/support.d.ts.map +1 -0
  119. package/lib/typescript/src/types.d.ts +293 -0
  120. package/lib/typescript/src/types.d.ts.map +1 -0
  121. package/lib/typescript/src/yubiotp.d.ts +13 -0
  122. package/lib/typescript/src/yubiotp.d.ts.map +1 -0
  123. package/package.json +181 -0
  124. package/src/core.ts +58 -0
  125. package/src/fido.ts +112 -0
  126. package/src/hooks/index.tsx +2 -0
  127. package/src/hooks/use-yubikey.tsx +10 -0
  128. package/src/hooks/yubikey-provider.tsx +146 -0
  129. package/src/index.tsx +10 -0
  130. package/src/management.ts +44 -0
  131. package/src/oath.ts +134 -0
  132. package/src/openpgp.ts +220 -0
  133. package/src/piv.ts +193 -0
  134. package/src/specs/NativeYubikitCore.ts +68 -0
  135. package/src/specs/NativeYubikitFido.ts +149 -0
  136. package/src/specs/NativeYubikitManagement.ts +78 -0
  137. package/src/specs/NativeYubikitOath.ts +110 -0
  138. package/src/specs/NativeYubikitOpenPgp.ts +148 -0
  139. package/src/specs/NativeYubikitPiv.ts +108 -0
  140. package/src/specs/NativeYubikitSupport.ts +61 -0
  141. package/src/specs/NativeYubikitYubiOtp.ts +82 -0
  142. package/src/support.ts +18 -0
  143. package/src/types.ts +404 -0
  144. package/src/yubiotp.ts +96 -0
package/src/piv.ts ADDED
@@ -0,0 +1,193 @@
1
+ import NativeYubikitPiv from './specs/NativeYubikitPiv';
2
+ import type {
3
+ Base64String,
4
+ PivBioMetadata,
5
+ PivKeyType,
6
+ PivManagementKeyMetadata,
7
+ PivManagementKeyType,
8
+ PivPinMetadata,
9
+ PivPinPolicy,
10
+ PivSlot,
11
+ PivSlotMetadata,
12
+ PivTouchPolicy,
13
+ } from './types';
14
+
15
+ export function reset(deviceHandle: string): Promise<void> {
16
+ return NativeYubikitPiv.reset(deviceHandle);
17
+ }
18
+
19
+ export function getSerialNumber(deviceHandle: string): Promise<number> {
20
+ return NativeYubikitPiv.getSerialNumber(deviceHandle);
21
+ }
22
+
23
+ export function authenticate(
24
+ deviceHandle: string,
25
+ managementKey: Base64String
26
+ ): Promise<void> {
27
+ return NativeYubikitPiv.authenticate(deviceHandle, managementKey);
28
+ }
29
+
30
+ export function setManagementKey(
31
+ deviceHandle: string,
32
+ keyType: PivManagementKeyType,
33
+ managementKey: Base64String,
34
+ requireTouch: boolean
35
+ ): Promise<void> {
36
+ return NativeYubikitPiv.setManagementKey(
37
+ deviceHandle,
38
+ keyType,
39
+ managementKey,
40
+ requireTouch
41
+ );
42
+ }
43
+
44
+ export function verifyPin(deviceHandle: string, pin: string): Promise<void> {
45
+ return NativeYubikitPiv.verifyPin(deviceHandle, pin);
46
+ }
47
+
48
+ export function getPinAttempts(deviceHandle: string): Promise<number> {
49
+ return NativeYubikitPiv.getPinAttempts(deviceHandle);
50
+ }
51
+
52
+ export function changePin(
53
+ deviceHandle: string,
54
+ oldPin: string,
55
+ newPin: string
56
+ ): Promise<void> {
57
+ return NativeYubikitPiv.changePin(deviceHandle, oldPin, newPin);
58
+ }
59
+
60
+ export function changePuk(
61
+ deviceHandle: string,
62
+ oldPuk: string,
63
+ newPuk: string
64
+ ): Promise<void> {
65
+ return NativeYubikitPiv.changePuk(deviceHandle, oldPuk, newPuk);
66
+ }
67
+
68
+ export function unblockPin(
69
+ deviceHandle: string,
70
+ puk: string,
71
+ newPin: string
72
+ ): Promise<void> {
73
+ return NativeYubikitPiv.unblockPin(deviceHandle, puk, newPin);
74
+ }
75
+
76
+ export function setPinAttempts(
77
+ deviceHandle: string,
78
+ pinAttempts: number,
79
+ pukAttempts: number
80
+ ): Promise<void> {
81
+ return NativeYubikitPiv.setPinAttempts(
82
+ deviceHandle,
83
+ pinAttempts,
84
+ pukAttempts
85
+ );
86
+ }
87
+
88
+ export function getPinMetadata(deviceHandle: string): Promise<PivPinMetadata> {
89
+ return NativeYubikitPiv.getPinMetadata(
90
+ deviceHandle
91
+ ) as Promise<PivPinMetadata>;
92
+ }
93
+
94
+ export function getPukMetadata(deviceHandle: string): Promise<PivPinMetadata> {
95
+ return NativeYubikitPiv.getPukMetadata(
96
+ deviceHandle
97
+ ) as Promise<PivPinMetadata>;
98
+ }
99
+
100
+ export function getManagementKeyMetadata(
101
+ deviceHandle: string
102
+ ): Promise<PivManagementKeyMetadata> {
103
+ return NativeYubikitPiv.getManagementKeyMetadata(
104
+ deviceHandle
105
+ ) as Promise<PivManagementKeyMetadata>;
106
+ }
107
+
108
+ export function getSlotMetadata(
109
+ deviceHandle: string,
110
+ slot: PivSlot
111
+ ): Promise<PivSlotMetadata> {
112
+ return NativeYubikitPiv.getSlotMetadata(
113
+ deviceHandle,
114
+ slot
115
+ ) as Promise<PivSlotMetadata>;
116
+ }
117
+
118
+ export function getCertificate(
119
+ deviceHandle: string,
120
+ slot: PivSlot
121
+ ): Promise<Base64String> {
122
+ return NativeYubikitPiv.getCertificate(deviceHandle, slot);
123
+ }
124
+
125
+ export function putCertificate(
126
+ deviceHandle: string,
127
+ slot: PivSlot,
128
+ certificate: Base64String,
129
+ compress?: boolean
130
+ ): Promise<void> {
131
+ return NativeYubikitPiv.putCertificate(
132
+ deviceHandle,
133
+ slot,
134
+ certificate,
135
+ compress
136
+ );
137
+ }
138
+
139
+ export function deleteCertificate(
140
+ deviceHandle: string,
141
+ slot: PivSlot
142
+ ): Promise<void> {
143
+ return NativeYubikitPiv.deleteCertificate(deviceHandle, slot);
144
+ }
145
+
146
+ export function attestKey(
147
+ deviceHandle: string,
148
+ slot: PivSlot
149
+ ): Promise<Base64String> {
150
+ return NativeYubikitPiv.attestKey(deviceHandle, slot);
151
+ }
152
+
153
+ export function generateKey(
154
+ deviceHandle: string,
155
+ slot: PivSlot,
156
+ keyType: PivKeyType,
157
+ pinPolicy: PivPinPolicy,
158
+ touchPolicy: PivTouchPolicy
159
+ ): Promise<Base64String> {
160
+ return NativeYubikitPiv.generateKey(
161
+ deviceHandle,
162
+ slot,
163
+ keyType,
164
+ pinPolicy,
165
+ touchPolicy
166
+ );
167
+ }
168
+
169
+ export function deleteKey(deviceHandle: string, slot: PivSlot): Promise<void> {
170
+ return NativeYubikitPiv.deleteKey(deviceHandle, slot);
171
+ }
172
+
173
+ export function rawSignOrDecrypt(
174
+ deviceHandle: string,
175
+ slot: PivSlot,
176
+ keyType: PivKeyType,
177
+ payload: Base64String
178
+ ): Promise<Base64String> {
179
+ return NativeYubikitPiv.rawSignOrDecrypt(
180
+ deviceHandle,
181
+ slot,
182
+ keyType,
183
+ payload
184
+ );
185
+ }
186
+
187
+ export function getBioMetadata(deviceHandle: string): Promise<PivBioMetadata> {
188
+ return NativeYubikitPiv.getBioMetadata(
189
+ deviceHandle
190
+ ) as Promise<PivBioMetadata>;
191
+ }
192
+
193
+ export { NativeYubikitPiv };
@@ -0,0 +1,68 @@
1
+ import {
2
+ TurboModuleRegistry,
3
+ type TurboModule,
4
+ type CodegenTypes,
5
+ } from 'react-native';
6
+
7
+ interface UsbConfiguration {
8
+ handlePermissions?: boolean;
9
+ }
10
+
11
+ interface NfcConfiguration {
12
+ timeout?: number;
13
+ disableNfcDiscoverySound?: boolean;
14
+ skipNdefCheck?: boolean;
15
+ handleUnavailableNfc?: boolean;
16
+ }
17
+
18
+ interface YubiKeyDevice {
19
+ handle: string;
20
+ transport: 'usb' | 'nfc';
21
+ supportedConnections: string[];
22
+ }
23
+
24
+ // Codegen doesn't support discriminated union payloads, so every variant's
25
+ // fields are optional here; consumers get the narrower YubiKeyEvent union
26
+ // via Core.addYubiKeyListener instead of calling this event directly.
27
+ interface YubiKeyEventPayload {
28
+ type: 'attached' | 'detached' | 'error';
29
+ device?: YubiKeyDevice;
30
+ handle?: string;
31
+ error?: string;
32
+ }
33
+
34
+ export interface Spec extends TurboModule {
35
+ /** Start listening for USB YubiKeys. */
36
+ startUsbDiscovery(config?: UsbConfiguration): void;
37
+ /** Stop listening for USB YubiKeys. */
38
+ stopUsbDiscovery(): void;
39
+ /** Start listening for NFC YubiKeys. */
40
+ startNfcDiscovery(config?: NfcConfiguration): void;
41
+ /** Stop listening for NFC YubiKeys. */
42
+ stopNfcDiscovery(): void;
43
+
44
+ /**
45
+ * Request a connection to a discovered device. The promise resolves with a
46
+ * connection handle that can be passed to session modules.
47
+ */
48
+ requestConnection(
49
+ deviceHandle: string,
50
+ connectionType: string
51
+ ): Promise<string>;
52
+
53
+ /**
54
+ * Send a raw APDU over a SmartCardConnection and receive the response.
55
+ */
56
+ sendApdu(connectionHandle: string, apdu: string): Promise<string>;
57
+
58
+ /** Close an opened connection. */
59
+ closeConnection(connectionHandle: string): void;
60
+
61
+ /** List devices currently held by the manager. */
62
+ getDiscoveredDevices(): YubiKeyDevice[];
63
+
64
+ /** Fires on device attach/detach and discovery-connection failures. */
65
+ readonly onYubiKeyEvent: CodegenTypes.EventEmitter<YubiKeyEventPayload>;
66
+ }
67
+
68
+ export default TurboModuleRegistry.getEnforcing<Spec>('YubikitCore');
@@ -0,0 +1,149 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ interface PublicKeyCredentialRpEntity {
4
+ id: string;
5
+ name: string;
6
+ }
7
+
8
+ interface PublicKeyCredentialUserEntity {
9
+ id: string;
10
+ name: string;
11
+ displayName: string;
12
+ }
13
+
14
+ interface PublicKeyCredentialParameters {
15
+ type: string;
16
+ alg: number;
17
+ }
18
+
19
+ interface PublicKeyCredentialCreationOptions {
20
+ rp: PublicKeyCredentialRpEntity;
21
+ user: PublicKeyCredentialUserEntity;
22
+ challenge: string;
23
+ pubKeyCredParams: PublicKeyCredentialParameters[];
24
+ timeout?: number;
25
+ excludeCredentials?: Array<{
26
+ id: string;
27
+ type: string;
28
+ transports?: string[];
29
+ }>;
30
+ authenticatorSelection?: {
31
+ authenticatorAttachment?: string;
32
+ residentKey?: string;
33
+ userVerification?: string;
34
+ };
35
+ attestation?: string;
36
+ extensions?: { [key: string]: unknown };
37
+ }
38
+
39
+ interface PublicKeyCredentialRequestOptions {
40
+ challenge: string;
41
+ timeout?: number;
42
+ rpId?: string;
43
+ allowCredentials?: Array<{
44
+ id: string;
45
+ type: string;
46
+ transports?: string[];
47
+ }>;
48
+ userVerification?: string;
49
+ extensions?: { [key: string]: unknown };
50
+ }
51
+
52
+ interface PublicKeyCredential {
53
+ id: string;
54
+ rawId: string;
55
+ type: 'public-key';
56
+ response: {
57
+ clientDataJSON: string;
58
+ authenticatorData?: string;
59
+ attestationObject?: string;
60
+ signature?: string;
61
+ userHandle?: string;
62
+ };
63
+ }
64
+
65
+ interface Ctap2Info {
66
+ versions: string[];
67
+ extensions?: string[];
68
+ aaguid?: string;
69
+ options?: { [key: string]: boolean };
70
+ maxMsgSize?: number;
71
+ pinUvAuthProtocols?: number[];
72
+ maxCredentialCountInList?: number;
73
+ maxCredentialIdLength?: number;
74
+ transports?: string[];
75
+ algorithms?: Array<{ type: string; alg: number }>;
76
+ maxLargeBlob?: number;
77
+ minPinLength?: number;
78
+ firmwareVersion?: number;
79
+ maxCredBlobLength?: number;
80
+ maxRpidsForMinPinLength?: number;
81
+ preferredPlatformUvAttempts?: number;
82
+ uvModality?: number;
83
+ certifications?: { [key: string]: number };
84
+ remainingDiscoverableCredentials?: number;
85
+ vendorPrototypeConfigCommands?: number[];
86
+ }
87
+
88
+ interface FidoCredentialDescriptor {
89
+ id: string;
90
+ type: string;
91
+ }
92
+
93
+ interface FidoCredentialUserEntity {
94
+ id: string;
95
+ name: string;
96
+ displayName: string;
97
+ }
98
+
99
+ export interface Spec extends TurboModule {
100
+ /** Get CTAP2 authenticator info. */
101
+ getInfo(deviceHandle: string): Promise<Ctap2Info>;
102
+
103
+ /** Perform a WebAuthn registration (makeCredential). */
104
+ makeCredential(
105
+ deviceHandle: string,
106
+ options: PublicKeyCredentialCreationOptions,
107
+ effectiveDomain: string,
108
+ pin?: string,
109
+ enterpriseAttestation?: number
110
+ ): Promise<PublicKeyCredential>;
111
+
112
+ /** Perform a WebAuthn authentication (getAssertion). */
113
+ getAssertion(
114
+ deviceHandle: string,
115
+ options: PublicKeyCredentialRequestOptions,
116
+ effectiveDomain: string,
117
+ pin?: string
118
+ ): Promise<PublicKeyCredential>;
119
+
120
+ /** Reset the authenticator. */
121
+ reset(deviceHandle: string): Promise<void>;
122
+
123
+ /** Credential management operations (requires PIN). */
124
+ getCredentialCount(deviceHandle: string, pin: string): Promise<number>;
125
+ getRpIdList(deviceHandle: string, pin: string): Promise<string[]>;
126
+ getCredentials(
127
+ deviceHandle: string,
128
+ rpId: string,
129
+ pin: string
130
+ ): Promise<
131
+ Array<{
132
+ credential: FidoCredentialDescriptor;
133
+ user: FidoCredentialUserEntity;
134
+ }>
135
+ >;
136
+ deleteCredential(
137
+ deviceHandle: string,
138
+ credential: FidoCredentialDescriptor,
139
+ pin: string
140
+ ): Promise<void>;
141
+ updateUserInformation(
142
+ deviceHandle: string,
143
+ credential: FidoCredentialDescriptor,
144
+ user: FidoCredentialUserEntity,
145
+ pin: string
146
+ ): Promise<void>;
147
+ }
148
+
149
+ export default TurboModuleRegistry.getEnforcing<Spec>('YubikitFido');
@@ -0,0 +1,78 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ interface Version {
4
+ major: number;
5
+ minor: number;
6
+ micro: number;
7
+ }
8
+
9
+ interface DeviceConfig {
10
+ enabledCapabilities?: {
11
+ usb?: number;
12
+ nfc?: number;
13
+ };
14
+ autoEjectTimeout?: number;
15
+ challengeResponseTimeout?: number;
16
+ nfcRestricted?: boolean;
17
+ deviceFlags?: number;
18
+ }
19
+
20
+ interface DeviceInfo {
21
+ config?: DeviceConfig;
22
+ serialNumber?: number;
23
+ version: Version;
24
+ versionName: string;
25
+ formFactor:
26
+ | 'UNKNOWN'
27
+ | 'USB_A_KEYCHAIN'
28
+ | 'USB_A_NANO'
29
+ | 'USB_C_KEYCHAIN'
30
+ | 'USB_C_NANO'
31
+ | 'USB_C_LIGHTNING'
32
+ | 'USB_A_BIO'
33
+ | 'USB_C_BIO';
34
+ supportedCapabilities: {
35
+ usb?: number;
36
+ nfc?: number;
37
+ };
38
+ hasTransportUsb: boolean;
39
+ hasTransportNfc: boolean;
40
+ isLocked: boolean;
41
+ isFips: boolean;
42
+ isSky: boolean;
43
+ partNumber?: string;
44
+ fipsCapable: number;
45
+ fipsApproved: number;
46
+ pinComplexity: boolean;
47
+ resetBlocked: number;
48
+ fpsVersion?: Version;
49
+ stmVersion?: Version;
50
+ versionQualifier?: string;
51
+ }
52
+
53
+ export interface Spec extends TurboModule {
54
+ /** Read metadata from a YubiKey. */
55
+ getDeviceInfo(deviceHandle: string): Promise<DeviceInfo>;
56
+
57
+ /** Update device configuration. */
58
+ updateDeviceConfig(
59
+ deviceHandle: string,
60
+ config: DeviceConfig,
61
+ reboot: boolean,
62
+ currentLockCode?: string,
63
+ newLockCode?: string
64
+ ): Promise<void>;
65
+
66
+ /** Set the USB interface mode. */
67
+ setMode(
68
+ deviceHandle: string,
69
+ mode: string,
70
+ chalrespTimeout: number,
71
+ autoejectTimeout: number
72
+ ): Promise<void>;
73
+
74
+ /** Reset the device to factory defaults. */
75
+ deviceReset(deviceHandle: string): Promise<void>;
76
+ }
77
+
78
+ export default TurboModuleRegistry.getEnforcing<Spec>('YubikitManagement');
@@ -0,0 +1,110 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ interface Credential {
4
+ id: string;
5
+ oathType: 'HOTP' | 'TOTP';
6
+ issuer?: string;
7
+ accountName: string;
8
+ period: number;
9
+ touchRequired: boolean;
10
+ }
11
+
12
+ interface Code {
13
+ value: string;
14
+ validFrom: number;
15
+ validUntil: number;
16
+ }
17
+
18
+ interface CredentialData {
19
+ accountName: string;
20
+ oathType: 'HOTP' | 'TOTP';
21
+ hashAlgorithm: 'SHA1' | 'SHA256' | 'SHA512';
22
+ secret: string;
23
+ digits: number;
24
+ period: number;
25
+ counter: number;
26
+ issuer?: string;
27
+ }
28
+
29
+ interface OathCredentialsResult {
30
+ credentials: Credential[];
31
+ }
32
+
33
+ interface OathCodesResult {
34
+ codes: Array<{ credential: Credential; code?: Code }>;
35
+ }
36
+
37
+ export interface Spec extends TurboModule {
38
+ /** Get a stable ID for the OATH application on this device. */
39
+ getDeviceId(deviceHandle: string): Promise<string>;
40
+
41
+ /** Reset the OATH application. */
42
+ reset(deviceHandle: string): Promise<void>;
43
+
44
+ /** True if an access key/password is configured. */
45
+ isAccessKeySet(deviceHandle: string): Promise<boolean>;
46
+
47
+ /** True if the session is locked and needs unlock. */
48
+ isLocked(deviceHandle: string): Promise<boolean>;
49
+
50
+ /** Unlock with a password. */
51
+ unlockWithPassword(deviceHandle: string, password: string): Promise<boolean>;
52
+
53
+ /** Unlock with a raw access key. */
54
+ unlockWithAccessKey(
55
+ deviceHandle: string,
56
+ accessKey: string
57
+ ): Promise<boolean>;
58
+
59
+ /** Set or change the password used to derive the access key. */
60
+ setPassword(deviceHandle: string, password: string): Promise<void>;
61
+
62
+ /** Set the raw access key directly. */
63
+ setAccessKey(deviceHandle: string, accessKey: string): Promise<void>;
64
+
65
+ /** Remove access key protection. */
66
+ deleteAccessKey(deviceHandle: string): Promise<void>;
67
+
68
+ /** List stored credentials. */
69
+ getCredentials(deviceHandle: string): Promise<OathCredentialsResult>;
70
+
71
+ /** Calculate all TOTP codes for the current time. */
72
+ calculateCodes(
73
+ deviceHandle: string,
74
+ timestamp?: number
75
+ ): Promise<OathCodesResult>;
76
+
77
+ /** Calculate a HOTP response for a credential. */
78
+ calculateResponse(
79
+ deviceHandle: string,
80
+ credentialId: string,
81
+ challenge: string
82
+ ): Promise<string>;
83
+
84
+ /** Calculate a single TOTP/HOTP code. */
85
+ calculateCode(
86
+ deviceHandle: string,
87
+ credentialId: string,
88
+ timestamp?: number
89
+ ): Promise<Code>;
90
+
91
+ /** Add a new credential. */
92
+ putCredential(
93
+ deviceHandle: string,
94
+ credentialData: CredentialData,
95
+ requireTouch: boolean
96
+ ): Promise<Credential>;
97
+
98
+ /** Delete a credential by ID. */
99
+ deleteCredential(deviceHandle: string, credentialId: string): Promise<void>;
100
+
101
+ /** Rename a credential by ID. */
102
+ renameCredential(
103
+ deviceHandle: string,
104
+ credentialId: string,
105
+ newAccountName: string,
106
+ newIssuer?: string
107
+ ): Promise<Credential>;
108
+ }
109
+
110
+ export default TurboModuleRegistry.getEnforcing<Spec>('YubikitOath');