electron-webauthn 0.0.5 → 0.0.7

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 (87) hide show
  1. package/README.md +6 -257
  2. package/dist/example.d.ts +2 -0
  3. package/dist/example.d.ts.map +1 -0
  4. package/dist/example.js +24 -0
  5. package/dist/example.js.map +1 -0
  6. package/dist/helper.js +23 -0
  7. package/dist/index.d.ts +12 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +46 -8
  10. package/dist/index.js.map +1 -1
  11. package/dist/objc/auth-services.js +28 -0
  12. package/dist/objc/authentication-services/as-authorization-controller-delegate.d.ts +53 -0
  13. package/dist/objc/authentication-services/as-authorization-controller-delegate.d.ts.map +1 -0
  14. package/dist/objc/authentication-services/as-authorization-controller-delegate.js +41 -0
  15. package/dist/objc/authentication-services/as-authorization-controller-delegate.js.map +1 -0
  16. package/dist/objc/authentication-services/as-authorization-controller-presentation-context-providing.d.ts +42 -0
  17. package/dist/objc/authentication-services/as-authorization-controller-presentation-context-providing.d.ts.map +1 -0
  18. package/dist/objc/authentication-services/as-authorization-controller-presentation-context-providing.js +32 -0
  19. package/dist/objc/authentication-services/as-authorization-controller-presentation-context-providing.js.map +1 -0
  20. package/dist/objc/authentication-services/as-authorization-controller.d.ts +28 -0
  21. package/dist/objc/authentication-services/as-authorization-controller.d.ts.map +1 -0
  22. package/dist/objc/authentication-services/as-authorization-controller.js +13 -0
  23. package/dist/objc/authentication-services/as-authorization-controller.js.map +1 -0
  24. package/dist/objc/authentication-services/as-authorization-platform-public-key-credential-provider.d.ts +22 -0
  25. package/dist/objc/authentication-services/as-authorization-platform-public-key-credential-provider.d.ts.map +1 -0
  26. package/dist/objc/authentication-services/as-authorization-platform-public-key-credential-provider.js +13 -0
  27. package/dist/objc/authentication-services/as-authorization-platform-public-key-credential-provider.js.map +1 -0
  28. package/dist/objc/authentication-services/index.d.ts +3 -0
  29. package/dist/objc/authentication-services/index.d.ts.map +1 -0
  30. package/dist/objc/authentication-services/index.js +4 -0
  31. package/dist/objc/authentication-services/index.js.map +1 -0
  32. package/dist/objc/foundation/helpers.js +142 -0
  33. package/dist/objc/foundation/index.d.ts +3 -0
  34. package/dist/objc/foundation/index.d.ts.map +1 -0
  35. package/dist/objc/foundation/index.js +4 -0
  36. package/dist/objc/foundation/index.js.map +1 -0
  37. package/dist/objc/foundation/main.js +4 -0
  38. package/dist/objc/foundation/nsarray.d.ts +18 -0
  39. package/dist/objc/foundation/nsarray.d.ts.map +1 -0
  40. package/dist/objc/foundation/nsarray.js +16 -0
  41. package/dist/objc/foundation/nsarray.js.map +1 -0
  42. package/dist/objc/foundation/nsdata.d.ts +109 -0
  43. package/dist/objc/foundation/nsdata.d.ts.map +1 -0
  44. package/dist/objc/foundation/nsdata.js +120 -0
  45. package/dist/objc/foundation/nsdata.js.map +1 -0
  46. package/dist/objc/foundation/nserror.d.ts +32 -0
  47. package/dist/objc/foundation/nserror.d.ts.map +1 -0
  48. package/dist/objc/foundation/nserror.js +71 -0
  49. package/dist/objc/foundation/nserror.js.map +1 -0
  50. package/dist/objc/foundation/nsstring.d.ts +15 -0
  51. package/dist/objc/foundation/nsstring.d.ts.map +1 -0
  52. package/dist/objc/foundation/nsstring.js +12 -0
  53. package/dist/objc/foundation/nsstring.js.map +1 -0
  54. package/dist/objc/foundation/nsvalue.js +2 -0
  55. package/dist/objc/foundation/nsview.d.ts +7 -0
  56. package/dist/objc/foundation/nsview.d.ts.map +1 -0
  57. package/dist/objc/foundation/nsview.js +3 -0
  58. package/dist/objc/foundation/nsview.js.map +1 -0
  59. package/dist/objc/foundation/nswindow.d.ts +5 -0
  60. package/dist/objc/foundation/nswindow.d.ts.map +1 -0
  61. package/dist/objc/foundation/nswindow.js +3 -0
  62. package/dist/objc/foundation/nswindow.js.map +1 -0
  63. package/dist/objc/foundation.js +28 -0
  64. package/dist/objc/helpers.d.ts +21 -0
  65. package/dist/objc/helpers.d.ts.map +1 -0
  66. package/dist/objc/helpers.js +32 -0
  67. package/dist/objc/helpers.js.map +1 -0
  68. package/dist/test/example.d.ts +2 -0
  69. package/dist/test/example.d.ts.map +1 -0
  70. package/dist/test/example.js +24 -0
  71. package/dist/test/example.js.map +1 -0
  72. package/dist/test/index.d.ts +2 -0
  73. package/dist/test/index.d.ts.map +1 -0
  74. package/dist/test/index.js +9 -0
  75. package/dist/test/index.js.map +1 -0
  76. package/dist/test/window.d.ts +5 -0
  77. package/dist/test/window.d.ts.map +1 -0
  78. package/dist/test/window.js +58 -0
  79. package/dist/test/window.js.map +1 -0
  80. package/dist/window.d.ts +5 -0
  81. package/dist/window.d.ts.map +1 -0
  82. package/dist/window.js +58 -0
  83. package/dist/window.js.map +1 -0
  84. package/package.json +23 -41
  85. package/LICENSE +0 -21
  86. package/index.d.ts +0 -68
  87. package/index.js +0 -316
package/README.md CHANGED
@@ -1,266 +1,15 @@
1
- # electron-webauthn
1
+ # electron-webauthn-test
2
2
 
3
- A high-performance, cross-platform WebAuthn/Passkey implementation for Electron applications, built with Rust and native platform APIs.
4
-
5
- ## Overview
6
-
7
- This library provides seamless WebAuthn (Web Authentication) and Passkey support for Electron applications across multiple platforms. It leverages native platform authenticators including Touch ID, Face ID, Windows Hello, and security keys to deliver a secure and user-friendly authentication experience.
8
-
9
- ### Key Features
10
-
11
- - **Native Platform Integration**: Uses platform-specific APIs for optimal performance and security
12
- - **Cross-Platform Support**: Works on macOS, Windows, and Linux
13
- - **WebAuthn Level 2 Compliance**: Full support for the latest WebAuthn specifications
14
- - **Biometric Authentication**: Touch ID, Face ID, Windows Hello, and Apple Watch support
15
- - **Secure Enclave Integration**: Hardware-backed key storage on supported platforms
16
- - **TypeScript Support**: Complete type definitions included
17
-
18
- ## Requirements
19
-
20
- ### macOS
21
-
22
- - **macOS 13+ (Ventura or later)** - Required for ASAuthorization framework
23
- - Touch ID, Face ID, or Apple Watch for biometric authentication
24
- - Valid code signing certificate for production use
25
-
26
- ### Windows
27
-
28
- - **Windows 10 version 1903+ or Windows 11**
29
- - Windows Hello capable device (fingerprint, face recognition, or PIN)
30
-
31
- ### Linux
32
-
33
- - Modern Linux distribution with WebAuthn support
34
- - Compatible authenticator device
35
-
36
- ## Installation
3
+ To install dependencies:
37
4
 
38
5
  ```bash
39
- npm install electron-webauthn
40
- # or
41
- yarn add electron-webauthn
6
+ bun install
42
7
  ```
43
8
 
44
- ## Usage
45
-
46
- ### Basic Registration (Creating a Credential)
47
-
48
- ```typescript
49
- import { createCredential } from "electron-webauthn";
50
-
51
- const options = {
52
- rp: {
53
- id: "example.com",
54
- name: "Example Corp",
55
- },
56
- user: {
57
- id: new Uint8Array([1, 2, 3, 4]),
58
- name: "user@example.com",
59
- displayName: "John Doe",
60
- },
61
- challenge: new Uint8Array(32), // Generate random 32 bytes
62
- pubKeyCredParams: [
63
- { type: "public-key", alg: -7 }, // ES256
64
- { type: "public-key", alg: -257 }, // RS256
65
- ],
66
- authenticatorSelection: {
67
- authenticatorAttachment: "platform",
68
- userVerification: "required",
69
- },
70
- };
71
-
72
- try {
73
- const credential = await createCredential(options);
74
- console.log("Registration successful:", credential);
75
- } catch (error) {
76
- console.error("Registration failed:", error);
77
- }
78
- ```
79
-
80
- ### Basic Authentication (Getting a Credential)
81
-
82
- ```typescript
83
- import { getCredential } from "electron-webauthn";
84
-
85
- const options = {
86
- rpId: "example.com",
87
- challenge: new Uint8Array(32), // Generate random 32 bytes
88
- allowCredentials: [
89
- {
90
- type: "public-key",
91
- id: credentialId, // From previous registration
92
- },
93
- ],
94
- userVerification: "required",
95
- };
96
-
97
- try {
98
- const assertion = await getCredential(options);
99
- console.log("Authentication successful:", assertion);
100
- } catch (error) {
101
- console.error("Authentication failed:", error);
102
- }
103
- ```
104
-
105
- ## Platform Support
106
-
107
- | Platform | Architecture | Status | Notes |
108
- | -------- | ------------- | ------ | ------------------------------ |
109
- | macOS | arm64 | ✅ | Native ASAuthorization support |
110
- | macOS | x64 | ✅ | Native ASAuthorization support |
111
- | macOS | universal | ✅ | Universal binary |
112
- | Windows | x64 | ✅ | Windows Hello integration |
113
- | Windows | arm64 | ✅ | Windows Hello integration |
114
- | Windows | ia32 | ✅ | Windows Hello integration |
115
- | Linux | x64 (GNU) | ✅ | Generic WebAuthn support |
116
- | Linux | x64 (musl) | ✅ | Alpine Linux compatible |
117
- | Linux | arm64 (GNU) | ✅ | ARM64 Linux support |
118
- | Linux | arm64 (musl) | ✅ | ARM64 Alpine support |
119
- | Linux | riscv64 (GNU) | ✅ | RISC-V architecture |
120
-
121
- ## macOS Entitlements
122
-
123
- For macOS applications, you need to include the following entitlements in your `entitlements.plist` file:
124
-
125
- ```xml
126
- <?xml version="1.0" encoding="UTF-8"?>
127
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
128
- <plist version="1.0">
129
- <dict>
130
- <!-- Required for WebAuthn/Passkey support -->
131
- <key>com.apple.developer.authentication-services.autofill-credential-provider</key>
132
- <true/>
133
-
134
- <!-- Required for platform authenticator access -->
135
- <key>com.apple.developer.web-browser</key>
136
- <true/>
137
-
138
- <!-- Required for Touch ID/Face ID/Apple Watch access -->
139
- <key>com.apple.security.device.biometry</key>
140
- <true/>
141
-
142
- <!-- Required for keychain access -->
143
- <key>keychain-access-groups</key>
144
- <array>
145
- <string>$(AppIdentifierPrefix)com.yourcompany.yourapp</string>
146
- </array>
147
-
148
- <!-- Optional: For network requests to verify credentials -->
149
- <key>com.apple.security.network.client</key>
150
- <true/>
151
- </dict>
152
- </plist>
153
- ```
154
-
155
- ### Electron Builder Configuration
156
-
157
- If using `electron-builder`, add the entitlements to your `package.json`:
158
-
159
- ```json
160
- {
161
- "build": {
162
- "mac": {
163
- "entitlements": "build/entitlements.mac.plist",
164
- "entitlementsInherit": "build/entitlements.mac.plist",
165
- "hardenedRuntime": true
166
- }
167
- }
168
- }
169
- ```
170
-
171
- ## Development
172
-
173
- ### Prerequisites
174
-
175
- - Node.js 16+
176
- - Rust 1.70+
177
- - Platform-specific build tools:
178
- - **macOS**: Xcode Command Line Tools
179
- - **Windows**: Visual Studio Build Tools
180
- - **Linux**: build-essential
181
-
182
- ### Building from Source
9
+ To run:
183
10
 
184
11
  ```bash
185
- # Clone the repository
186
- git clone https://github.com/your-org/electron-webauthn.git
187
- cd electron-webauthn
188
-
189
- # Install dependencies
190
- npm install
191
-
192
- # Build the native module
193
- npm run build
194
-
195
- # Run tests
196
- npm test
197
- ```
198
-
199
- ### Architecture
200
-
201
- This library uses:
202
-
203
- - **Rust** for high-performance native implementations
204
- - **NAPI-RS** for seamless Node.js bindings
205
- - **Platform-specific APIs**:
206
- - macOS: ASAuthorization framework
207
- - Windows: Windows Hello APIs
208
- - Linux: Generic WebAuthn implementation
209
-
210
- ## Error Handling
211
-
212
- The library provides detailed error messages for common scenarios:
213
-
214
- ```typescript
215
- try {
216
- const credential = await createCredential(options);
217
- } catch (error) {
218
- switch (error.code) {
219
- case "NotSupportedError":
220
- console.log("WebAuthn not supported on this platform");
221
- break;
222
- case "SecurityError":
223
- console.log("Security requirements not met");
224
- break;
225
- case "NotAllowedError":
226
- console.log("User cancelled or timeout occurred");
227
- break;
228
- default:
229
- console.log("Unexpected error:", error.message);
230
- }
231
- }
12
+ bun run index.ts
232
13
  ```
233
14
 
234
- ## Security Considerations
235
-
236
- - Always validate challenges on your server
237
- - Use HTTPS in production environments
238
- - Implement proper CORS policies
239
- - Store credentials securely on your backend
240
- - Regularly update the library for security patches
241
-
242
- ## Contributing
243
-
244
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
245
-
246
- ### Development Setup
247
-
248
- 1. Fork the repository
249
- 2. Create a feature branch
250
- 3. Make your changes
251
- 4. Add tests for new functionality
252
- 5. Submit a pull request
253
-
254
- ## License
255
-
256
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
257
-
258
- ## Support
259
-
260
- - **Issues**: [GitHub Issues](https://github.com/your-org/electron-webauthn/issues)
261
- - **Documentation**: [API Documentation](https://docs.your-org.com/electron-webauthn)
262
- - **Community**: [Discussions](https://github.com/your-org/electron-webauthn/discussions)
263
-
264
- ## Changelog
265
-
266
- See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.
15
+ This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { NSData } from "./objc/foundation/nsdata.js";
2
+ import { NSString } from "./objc/foundation/nsstring.js";
3
+ import { NSArray } from "./objc/foundation/nsarray.js";
4
+ const myString = NSString.stringWithUTF8String$("Hello from Objective-C!");
5
+ console.log("Created NSString:", myString);
6
+ const buf = Buffer.from("Hello from Objective-C!");
7
+ const myData = NSData.dataWithBytes$length$(buf, buf.length);
8
+ console.log("Created NSData:", myData);
9
+ // Test NSArray
10
+ const str1 = NSString.stringWithUTF8String$("First");
11
+ const str2 = NSString.stringWithUTF8String$("Second");
12
+ const str3 = NSString.stringWithUTF8String$("Third");
13
+ // Create array with one object, then add more
14
+ let myArray = NSArray.arrayWithObject$(str1);
15
+ myArray = myArray.arrayByAddingObject$(str2);
16
+ myArray = myArray.arrayByAddingObject$(str3);
17
+ console.log("Created NSArray with count:", myArray.count());
18
+ // Access elements
19
+ for (let i = 0; i < myArray.count(); i++) {
20
+ const obj = myArray.objectAtIndex$(i);
21
+ const nsString = obj;
22
+ console.log(`Array[${i}]:`, nsString.UTF8String());
23
+ }
24
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,C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AC,UAAU,EAAE,CAAC,CAAC;AACrD,CAAC"}
package/dist/helper.js ADDED
@@ -0,0 +1,23 @@
1
+ import { NobjcLibrary, NobjcObject } from "@iamevan/nobjc";
2
+ // Load the Foundation framework
3
+ export const foundation = new NobjcLibrary("/System/Library/Frameworks/Foundation.framework/Foundation");
4
+ // Load the AuthenticationServices framework
5
+ export const authServices = new NobjcLibrary("/System/Library/Frameworks/AuthenticationServices.framework/AuthenticationServices");
6
+ // NSString helpers
7
+ const NSString = foundation["NSString"];
8
+ const _stringWithUTF8String = NSString["stringWithUTF8String:"];
9
+ export function createNSString(str) {
10
+ return _stringWithUTF8String(str);
11
+ }
12
+ // NSData helpers
13
+ const NSData = foundation["NSData"];
14
+ const _dataWithBytesLength = NSData["dataWithBytes:length:"];
15
+ export function createNSData(buffer) {
16
+ return _dataWithBytesLength(buffer, buffer.length);
17
+ }
18
+ // NSArray helpers
19
+ const NSArray = foundation["NSArray"];
20
+ const _arrayWithObject = NSArray["arrayWithObject:"];
21
+ export function createNSArray(obj) {
22
+ return _arrayWithObject(obj);
23
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
- import { create, get } from "../index";
2
- export declare const webauthn: {
3
- create: typeof create;
4
- get: typeof get;
1
+ declare function getCredential(rpid: string, challenge: Buffer, nativeWindowHandle: Buffer): {
2
+ [key: string]: import("objc-js").NobjcMethod;
3
+ initWithAuthorizationRequests$(authorizationRequests: import("objc-js").NobjcObject): any;
4
+ performRequests(): void;
5
+ performRequestsWithOptions$(options: import("objc-js").NobjcObject): void;
6
+ performAutoFillAssistedRequests(): void;
7
+ cancel(): void;
8
+ setDelegate$(delegate: import("objc-js").NobjcObject): void;
9
+ delegate(): import("objc-js").NobjcObject;
10
+ setPresentationContextProvider$(provider: import("objc-js").NobjcObject): void;
11
+ presentationContextProvider(): import("objc-js").NobjcObject;
5
12
  };
13
+ export { getCredential };
6
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,QAAQ;;;CAGpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,iBAAS,aAAa,CACpB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM;;;;;;;;;;;EAmD3B;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.webauthn = void 0;
4
- const index_1 = require("../index");
5
- exports.webauthn = {
6
- create: index_1.create,
7
- get: index_1.get,
8
- };
1
+ import { fromPointer, getPointer } from "objc-js";
2
+ import { createAuthorizationControllerDelegate } from "./objc/authentication-services/as-authorization-controller-delegate.js";
3
+ import { createAuthorizationController } from "./objc/authentication-services/as-authorization-controller.js";
4
+ import { createPresentationContextProvider } from "./objc/authentication-services/as-authorization-controller-presentation-context-providing.js";
5
+ import { createPlatformPublicKeyCredentialProvider } from "./objc/authentication-services/as-authorization-platform-public-key-credential-provider.js";
6
+ import { NSArray } from "./objc/foundation/nsarray.js";
7
+ import { NSDataFromBuffer } from "./objc/foundation/nsdata.js";
8
+ import { NSStringFromString } from "./objc/foundation/nsstring.js";
9
+ function getCredential(rpid, challenge, nativeWindowHandle) {
10
+ const NS_rpID = NSStringFromString(rpid);
11
+ // let challenge: Data // Obtain this from the server.
12
+ const NS_challenge = NSDataFromBuffer(challenge);
13
+ // let platformProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: "example.com")
14
+ const platformProvider = createPlatformPublicKeyCredentialProvider(NS_rpID);
15
+ // let platformKeyRequest = platformProvider.createCredentialAssertionRequest(challenge: challenge)
16
+ const platformKeyRequest = platformProvider.createCredentialAssertionRequestWithChallenge$(NS_challenge);
17
+ // let authController = ASAuthorizationController(authorizationRequests: [platformKeyRequest])
18
+ const requestsArray = NSArray.arrayWithObject$(platformKeyRequest);
19
+ const authController = createAuthorizationController(requestsArray);
20
+ // authController.delegate = self
21
+ const delegate = createAuthorizationControllerDelegate({
22
+ didCompleteWithAuthorization: (controller, authorization) => {
23
+ console.log("Authorization succeeded:", authorization);
24
+ },
25
+ didCompleteWithError: (controller, error) => {
26
+ // Parse the NSError into a readable format
27
+ const parsedError = error;
28
+ console.error("Authorization failed:", parsedError.localizedDescription().UTF8String());
29
+ },
30
+ });
31
+ authController.setDelegate$(delegate);
32
+ // authController.presentationContextProvider = self
33
+ const presentationContextProvider = createPresentationContextProvider({
34
+ presentationAnchorForAuthorizationController: (controller) => {
35
+ // Return the NSWindow to present the authorization UI in
36
+ const nsView = fromPointer(nativeWindowHandle);
37
+ const nsWindow = nsView.window();
38
+ return nsWindow;
39
+ },
40
+ });
41
+ authController.setPresentationContextProvider$(presentationContextProvider);
42
+ // authController.performRequests()
43
+ authController.performRequests();
44
+ return authController;
45
+ }
46
+ export { getCredential };
9
47
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;AAAA,oCAAuC;AAE1B,QAAA,QAAQ,GAAG;IACtB,MAAM,EAAN,cAAM;IACN,GAAG,EAAH,WAAG;CACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,qCAAqC,EAAE,MAAM,wEAAwE,CAAC;AAC/H,OAAO,EAAE,6BAA6B,EAAE,MAAM,+DAA+D,CAAC;AAC9G,OAAO,EAAE,iCAAiC,EAAE,MAAM,8FAA8F,CAAC;AACjJ,OA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pE,4CAA4C,EAAE,CAAC,UAAU,EAAE,EAAE;YAC3D,yDAAyD;YACzD,MAAM,MAAM,GAAG,WAAW,CAAC,kBAAkB,CAAuB,CAAC;YACrE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;IACH,cAAc,CAAC,+BAA+B,CAAC,2BAA2B,CAAC,CAAC;IAE5E,mCAAmC;IACnC,cAAc,CAAC,eAAe,EAAE,CAAC;IAEjC,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { NobjcLibrary, NobjcObject } from "@iamevan/nobjc";
2
+ import { allocInit, NobjcInstanceWrapper } from "./helpers.js";
3
+ // Load the AuthenticationServices framework
4
+ export const authServices = new NobjcLibrary("/System/Library/Frameworks/AuthenticationServices.framework/AuthenticationServices");
5
+ // Wrapper for ASAuthorizationPlatformPublicKeyCredentialProvider
6
+ const _ASAuthorizationPlatformPublicKeyCredentialProvider = authServices["ASAuthorizationPlatformPublicKeyCredentialProvider"];
7
+ export class ASAuthorizationPlatformPublicKeyCredentialProvider extends NobjcInstanceWrapper {
8
+ constructor(relyingPartyIdentifier) {
9
+ const instance = allocInit(_ASAuthorizationPlatformPublicKeyCredentialProvider, "initWithRelyingPartyIdentifier:", relyingPartyIdentifier);
10
+ super(instance);
11
+ }
12
+ createCredentialAssertionRequest(challenge) {
13
+ const method = this.instance["createCredentialAssertionRequestWithChallenge:"];
14
+ return method(challenge);
15
+ }
16
+ }
17
+ // Wrapper for ASAuthorizationController
18
+ const _ASAuthorizationController = authServices["ASAuthorizationController"];
19
+ export class ASAuthorizationController extends NobjcInstanceWrapper {
20
+ constructor(authorizationRequests) {
21
+ const instance = allocInit(_ASAuthorizationController, "initWithAuthorizationRequests:", authorizationRequests);
22
+ super(instance);
23
+ }
24
+ performRequests() {
25
+ const method = this.instance["performRequests"];
26
+ method();
27
+ }
28
+ }
@@ -0,0 +1,53 @@
1
+ import { NobjcObject } from "objc-js";
2
+ /**
3
+ * ASAuthorizationControllerDelegate Protocol
4
+ *
5
+ * A protocol that provides methods for handling authorization flow events.
6
+ * https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerdelegate
7
+ *
8
+ * Protocol Methods:
9
+ * - authorizationController:didCompleteWithAuthorization: - Called when authorization succeeds
10
+ * - authorizationController:didCompleteWithError: - Called when authorization fails
11
+ */
12
+ export interface ASAuthorizationControllerDelegateCallbacks {
13
+ /**
14
+ * Tells the delegate that authorization completed successfully.
15
+ * @param controller The authorization controller that completed.
16
+ * @param authorization The authorization object containing the credential.
17
+ */
18
+ didCompleteWithAuthorization?: (controller: NobjcObject, authorization: NobjcObject) => void;
19
+ /**
20
+ * Tells the delegate that authorization failed with an error.
21
+ * @param controller The authorization controller that failed.
22
+ * @param error The error that occurred during authorization.
23
+ */
24
+ didCompleteWithError?: (controller: NobjcObject, error: NobjcObject) => void;
25
+ }
26
+ /**
27
+ * Create an ASAuthorizationControllerDelegate instance
28
+ *
29
+ * This creates an Objective-C object that implements the ASAuthorizationControllerDelegate
30
+ * protocol using the objc-js protocol implementation API.
31
+ *
32
+ * @param callbacks Object containing callback functions for delegate methods
33
+ * @returns A NobjcObject that can be set as the delegate of an ASAuthorizationController
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const delegate = createAuthorizationControllerDelegate({
38
+ * didCompleteWithAuthorization: (controller, authorization) => {
39
+ * console.log("Authorization succeeded!");
40
+ * const credential = authorization.credential();
41
+ * // Process the credential
42
+ * },
43
+ * didCompleteWithError: (controller, error) => {
44
+ * console.error("Authorization failed:", error.localizedDescription());
45
+ * }
46
+ * });
47
+ *
48
+ * authController.setDelegate$(delegate);
49
+ * authController.performRequests();
50
+ * ```
51
+ */
52
+ export declare function createAuthorizationControllerDelegate(callbacks: ASAuthorizationControllerDelegateCallbacks): NobjcObject;
53
+ //# sourceMappingURL=as-authorization-controller-delegate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-authorization-controller-delegate.d.ts","sourceRoot":"","sources":["../../../src/objc/authentication-services/as-authorization-controller-delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAErD;;;;;;;;;GASG;AAEH,MAAM,WAAW,0CAA0C;IACzD;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,CAC7B,UAAU,EAAE,WAAW,EACvB,aAAa,EAAE,WAAW,KACvB,IAAI,CAAC;IAEV;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CAC9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qCAAqC,CACnD,SAAS,EAAE,0CAA0C,GACpD,WAAW,CAoBb"}
@@ -0,0 +1,41 @@
1
+ import { NobjcObject, NobjcProtocol } from "objc-js";
2
+ /**
3
+ * Create an ASAuthorizationControllerDelegate instance
4
+ *
5
+ * This creates an Objective-C object that implements the ASAuthorizationControllerDelegate
6
+ * protocol using the objc-js protocol implementation API.
7
+ *
8
+ * @param callbacks Object containing callback functions for delegate methods
9
+ * @returns A NobjcObject that can be set as the delegate of an ASAuthorizationController
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const delegate = createAuthorizationControllerDelegate({
14
+ * didCompleteWithAuthorization: (controller, authorization) => {
15
+ * console.log("Authorization succeeded!");
16
+ * const credential = authorization.credential();
17
+ * // Process the credential
18
+ * },
19
+ * didCompleteWithError: (controller, error) => {
20
+ * console.error("Authorization failed:", error.localizedDescription());
21
+ * }
22
+ * });
23
+ *
24
+ * authController.setDelegate$(delegate);
25
+ * authController.performRequests();
26
+ * ```
27
+ */
28
+ export function createAuthorizationControllerDelegate(callbacks) {
29
+ const methodImplementations = {};
30
+ // Map the callbacks to Objective-C method names using $ notation
31
+ if (callbacks.didCompleteWithAuthorization) {
32
+ methodImplementations["authorizationController$didCompleteWithAuthorization$"] = callbacks.didCompleteWithAuthorization;
33
+ }
34
+ if (callbacks.didCompleteWithError) {
35
+ methodImplementations["authorizationController$didCompleteWithError$"] =
36
+ callbacks.didCompleteWithError;
37
+ }
38
+ // Create and return the protocol implementation
39
+ return NobjcProtocol.implement("ASAuthorizationControllerDelegate", methodImplementations);
40
+ }
41
+ //# sourceMappingURL=as-authorization-controller-delegate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-authorization-controller-delegate.js","sourceRoot":"","sources":["../../../src/objc/authentication-services/as-authorization-controller-delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgCrD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,qCAAqC,CACnD,SAAqD;IAErD,MAAM,qBAAqB,GAA4C,EAAE,CAAC;IAE1E,iEAAiE;IACjE,IAAI,SAAS,CAAC,4BAA4B,EAAE,CAAC;QAC3C,qBAAqB,CACnB,uDAAuD,CACxD,GAAG,SAAS,CAAC,4BAA4B,CAAC;IAC7C,CAAC;IAED,IAAI,SAAS,CAAC,oBAAoB,EAAE,CAAC;QACnC,qBAAqB,CAAC,+CAA+C,CAAC;YACpE,SAAS,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,gDAAgD;IAChD,OAAO,aAAa,CAAC,SAAS,CAC5B,mCAAmC,EACnC,qBAAqB,CACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { NobjcObject } from "objc-js";
2
+ /**
3
+ * ASAuthorizationControllerPresentationContextProviding Protocol
4
+ *
5
+ * A protocol that provides the window in which the authorization controller displays its interface.
6
+ * https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerpresentationcontextproviding
7
+ *
8
+ * Protocol Methods:
9
+ * - presentationAnchorForAuthorizationController: - Returns the presentation anchor (window) for the controller
10
+ */
11
+ export interface ASAuthorizationControllerPresentationContextProvidingCallbacks {
12
+ /**
13
+ * Returns the presentation anchor (window) to use when presenting the authorization interface.
14
+ * @param controller The authorization controller requesting the presentation anchor.
15
+ * @returns The window (ASPresentationAnchor/NSWindow) to use as the presentation anchor.
16
+ */
17
+ presentationAnchorForAuthorizationController: (controller: NobjcObject) => NobjcObject;
18
+ }
19
+ /**
20
+ * Create an ASAuthorizationControllerPresentationContextProviding instance
21
+ *
22
+ * This creates an Objective-C object that implements the ASAuthorizationControllerPresentationContextProviding
23
+ * protocol using the objc-js protocol implementation API.
24
+ *
25
+ * @param callbacks Object containing callback functions for protocol methods
26
+ * @returns A NobjcObject that can be set as the presentationContextProvider of an ASAuthorizationController
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const presentationContextProvider = createPresentationContextProvider({
31
+ * presentationAnchorForAuthorizationController: (controller) => {
32
+ * // Return the NSWindow to present the authorization UI in
33
+ * return myNSWindow;
34
+ * }
35
+ * });
36
+ *
37
+ * authController.setPresentationContextProvider$(presentationContextProvider);
38
+ * authController.performRequests();
39
+ * ```
40
+ */
41
+ export declare function createPresentationContextProvider(callbacks: ASAuthorizationControllerPresentationContextProvidingCallbacks): NobjcObject;
42
+ //# sourceMappingURL=as-authorization-controller-presentation-context-providing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-authorization-controller-presentation-context-providing.d.ts","sourceRoot":"","sources":["../../../src/objc/authentication-services/as-authorization-controller-presentation-context-providing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAErD;;;;;;;;GAQG;AAEH,MAAM,WAAW,8DAA8D;IAC7E;;;;OAIG;IACH,4CAA4C,EAAE,CAC5C,UAAU,EAAE,WAAW,KACpB,WAAW,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,8DAA8D,GACxE,WAAW,CAYb"}
@@ -0,0 +1,32 @@
1
+ import { NobjcObject, NobjcProtocol } from "objc-js";
2
+ /**
3
+ * Create an ASAuthorizationControllerPresentationContextProviding instance
4
+ *
5
+ * This creates an Objective-C object that implements the ASAuthorizationControllerPresentationContextProviding
6
+ * protocol using the objc-js protocol implementation API.
7
+ *
8
+ * @param callbacks Object containing callback functions for protocol methods
9
+ * @returns A NobjcObject that can be set as the presentationContextProvider of an ASAuthorizationController
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const presentationContextProvider = createPresentationContextProvider({
14
+ * presentationAnchorForAuthorizationController: (controller) => {
15
+ * // Return the NSWindow to present the authorization UI in
16
+ * return myNSWindow;
17
+ * }
18
+ * });
19
+ *
20
+ * authController.setPresentationContextProvider$(presentationContextProvider);
21
+ * authController.performRequests();
22
+ * ```
23
+ */
24
+ export function createPresentationContextProvider(callbacks) {
25
+ const methodImplementations = {};
26
+ // Map the callback to Objective-C method name using $ notation
27
+ methodImplementations["presentationAnchorForAuthorizationController$"] =
28
+ callbacks.presentationAnchorForAuthorizationController;
29
+ // Create and return the protocol implementation
30
+ return NobjcProtocol.implement("ASAuthorizationControllerPresentationContextProviding", methodImplementations);
31
+ }
32
+ //# sourceMappingURL=as-authorization-controller-presentation-context-providing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-authorization-controller-presentation-context-providing.js","sourceRoot":"","sources":["../../../src/objc/authentication-services/as-authorization-controller-presentation-context-providing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAuBrD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,iCAAiC,CAC/C,SAAyE;IAEzE,MAAM,qBAAqB,GAA4C,EAAE,CAAC;IAE1E,+DAA+D;IAC/D,qBAAqB,CAAC,+CAA+C,CAAC;QACpE,SAAS,CAAC,4CAA4C,CAAC;IAEzD,gDAAgD;IAChD,OAAO,aAAa,CAAC,SAAS,CAC5B,uDAAuD,EACvD,qBAAqB,CACtB,CAAC;AACJ,CAAC"}