electron-webauthn 0.0.11 → 0.0.12
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/dist/get-authorization-controller.d.ts +5 -0
- package/dist/get-authorization-controller.d.ts.map +1 -0
- package/dist/get-authorization-controller.js +37 -0
- package/dist/get-authorization-controller.js.map +1 -0
- package/dist/helpers.d.ts +26 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +71 -0
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -10
- package/dist/index.js.map +1 -1
- package/dist/test/index.js +1 -1
- package/dist/test/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NobjcObject } from "objc-js";
|
|
2
|
+
export declare function setClientDataHash(self: NobjcObject, clientDataHash: Buffer): void;
|
|
3
|
+
export declare function removeClientDataHash(self: NobjcObject): void;
|
|
4
|
+
export declare const WebauthnGetController: NobjcObject;
|
|
5
|
+
//# sourceMappingURL=get-authorization-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-authorization-controller.d.ts","sourceRoot":"","sources":["../src/get-authorization-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAc,MAAM,SAAS,CAAC;AAS9D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAG1E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,QAGrD;AAED,eAAO,MAAM,qBAAqB,aAiChC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NobjcClass, NobjcObject, getPointer } from "objc-js";
|
|
2
|
+
import { NSDataFromBuffer } from "./objc/foundation/nsdata.js";
|
|
3
|
+
const getControllerState = new Map();
|
|
4
|
+
function getObjectPointerString(self) {
|
|
5
|
+
return getPointer(self).toBase64();
|
|
6
|
+
}
|
|
7
|
+
export function setClientDataHash(self, clientDataHash) {
|
|
8
|
+
const selfPointer = getObjectPointerString(self);
|
|
9
|
+
getControllerState.set(selfPointer, clientDataHash);
|
|
10
|
+
}
|
|
11
|
+
export function removeClientDataHash(self) {
|
|
12
|
+
const selfPointer = getObjectPointerString(self);
|
|
13
|
+
getControllerState.delete(selfPointer);
|
|
14
|
+
}
|
|
15
|
+
export const WebauthnGetController = NobjcClass.define({
|
|
16
|
+
name: "WebauthnGetController",
|
|
17
|
+
superclass: "ASAuthorizationController",
|
|
18
|
+
methods: {
|
|
19
|
+
// This overrides the default implementation of _requestContextWithRequests$error$ to allow us to set the clientDataHash on the assertion options
|
|
20
|
+
_requestContextWithRequests$error$: {
|
|
21
|
+
types: "@@:@^@",
|
|
22
|
+
implementation: (self, requests, outError) => {
|
|
23
|
+
const context = NobjcClass.super(self, "_requestContextWithRequests$error$", requests, outError);
|
|
24
|
+
// Grab the assertion options, set the client data hash, and set a copy of the assertion options back on the context
|
|
25
|
+
const selfPointer = getObjectPointerString(self);
|
|
26
|
+
if (getControllerState.has(selfPointer)) {
|
|
27
|
+
const assertionOptions = context.platformKeyCredentialAssertionOptions();
|
|
28
|
+
const clientDataHash = getControllerState.get(selfPointer);
|
|
29
|
+
assertionOptions.setClientDataHash$(NSDataFromBuffer(clientDataHash));
|
|
30
|
+
context.setPlatformKeyCredentialAssertionOptions$(assertionOptions.copyWithZone$(null));
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=get-authorization-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-authorization-controller.js","sourceRoot":"","sources":["../src/get-authorization-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EA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c,CAAC,CAAC,CAAC;oBAEtE,OAAO,CAAC,yCAAyC,CAC/C,gBAAgB,CAAC,aAAa,CAAC,IAAI,CAAC,CACrC,CAAC;gBACJ,CAAC;gBAED,OAAO,OAAO,CAAC;YACjB,CAAC;SACF;KACF;CACF,CAAC,CAAC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -17,4 +17,30 @@ export declare function PromiseWithResolvers<T = void>(): {
|
|
|
17
17
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
18
18
|
reject: (reason?: unknown) => void;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* WebAuthn: clientDataHash = SHA-256(clientDataJSON_bytes)
|
|
22
|
+
*
|
|
23
|
+
* - Input must be the exact bytes of CollectedClientData JSON (UTF-8).
|
|
24
|
+
* - Output is 32-byte SHA-256 digest.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clientDataJsonBufferToHash(clientDataJSON: Buffer): Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes an origin according to the HTML specification.
|
|
29
|
+
* Based on https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin
|
|
30
|
+
*
|
|
31
|
+
* @param origin - The origin string to serialize (e.g., "https://example.com:8080")
|
|
32
|
+
* @returns The serialized origin string, or "null" for opaque origins
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* serializeOrigin("https://example.com:443"); // "https://example.com:443"
|
|
37
|
+
* serializeOrigin("http://localhost:8080"); // "http://localhost:8080"
|
|
38
|
+
* serializeOrigin("null"); // "null"
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeOrigin(origin: string): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Convert an ArrayBuffer to a base64url string.
|
|
44
|
+
*/
|
|
45
|
+
export declare function bufferToBase64Url(buffer: Buffer): string;
|
|
20
46
|
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,IAAI,KAAK;IAChD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC7C,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,CAQA;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAWzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA+B7D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWxD"}
|
package/dist/helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
1
2
|
/**
|
|
2
3
|
* Creates a Promise along with its resolve and reject callbacks.
|
|
3
4
|
* This is a polyfill for the native Promise.withResolvers() method.
|
|
@@ -21,4 +22,74 @@ export function PromiseWithResolvers() {
|
|
|
21
22
|
});
|
|
22
23
|
return { promise, resolve: resolve, reject: reject };
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* WebAuthn: clientDataHash = SHA-256(clientDataJSON_bytes)
|
|
27
|
+
*
|
|
28
|
+
* - Input must be the exact bytes of CollectedClientData JSON (UTF-8).
|
|
29
|
+
* - Output is 32-byte SHA-256 digest.
|
|
30
|
+
*/
|
|
31
|
+
export function clientDataJsonBufferToHash(clientDataJSON) {
|
|
32
|
+
if (!Buffer.isBuffer(clientDataJSON)) {
|
|
33
|
+
throw new TypeError("clientDataJsonBufferToHash: clientDataJSON must be a Buffer");
|
|
34
|
+
}
|
|
35
|
+
if (clientDataJSON.length === 0) {
|
|
36
|
+
throw new RangeError("clientDataJsonBufferToHash: clientDataJSON is empty");
|
|
37
|
+
}
|
|
38
|
+
return createHash("sha256").update(clientDataJSON).digest();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Serializes an origin according to the HTML specification.
|
|
42
|
+
* Based on https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin
|
|
43
|
+
*
|
|
44
|
+
* @param origin - The origin string to serialize (e.g., "https://example.com:8080")
|
|
45
|
+
* @returns The serialized origin string, or "null" for opaque origins
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* serializeOrigin("https://example.com:443"); // "https://example.com:443"
|
|
50
|
+
* serializeOrigin("http://localhost:8080"); // "http://localhost:8080"
|
|
51
|
+
* serializeOrigin("null"); // "null"
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function serializeOrigin(origin) {
|
|
55
|
+
// If origin is an opaque origin (represented as "null"), return "null"
|
|
56
|
+
if (origin === "null" || !origin) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
// Parse the origin using URL constructor
|
|
61
|
+
const url = new URL(origin);
|
|
62
|
+
// Build the serialized origin
|
|
63
|
+
let result = url.protocol; // Already includes "://"
|
|
64
|
+
// If protocol doesn't end with "://", ensure it's added
|
|
65
|
+
if (!result.endsWith("://")) {
|
|
66
|
+
result = result.replace(/:$/, "") + "://";
|
|
67
|
+
}
|
|
68
|
+
// Append the host (already serialized by URL)
|
|
69
|
+
result += url.hostname;
|
|
70
|
+
// If port is non-null and non-default, append it
|
|
71
|
+
if (url.port) {
|
|
72
|
+
result += ":" + url.port;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// If URL parsing fails, treat as opaque origin
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Convert an ArrayBuffer to a base64url string.
|
|
83
|
+
*/
|
|
84
|
+
export function bufferToBase64Url(buffer) {
|
|
85
|
+
const bytes = new Uint8Array(buffer);
|
|
86
|
+
let binary = "";
|
|
87
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
88
|
+
binary += String.fromCharCode(bytes[i]);
|
|
89
|
+
}
|
|
90
|
+
return btoa(binary)
|
|
91
|
+
.replace(/\+/g, "-")
|
|
92
|
+
.replace(/\//g, "_")
|
|
93
|
+
.replace(/=+$/, "");
|
|
94
|
+
}
|
|
24
95
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB;IAKlC,IAAI,OAA4C,CAAC;IACjD,IAAI,MAAkC,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAQ,EAAE,MAAM,EAAE,MAAO,EAAE,CAAC;AACzD,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB;IAKlC,IAAI,OAA4C,CAAC;IACjD,IAAI,MAAkC,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CAAC,QAAQ,CAAC;QAEvB,iDAAiD;QACjD,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YACb,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;QAC3B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+CAA+C;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,CAAC;SAChB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
type AuthenticatorAttachment = "platform" | "cross-platform";
|
|
2
|
+
export type UserVerificationPreference = "preferred" | "required" | "discouraged";
|
|
2
3
|
export interface GetCredentialResult {
|
|
3
4
|
id: Buffer;
|
|
4
5
|
authenticatorAttachment: AuthenticatorAttachment;
|
|
@@ -6,9 +7,9 @@ export interface GetCredentialResult {
|
|
|
6
7
|
authenticatorData: Buffer;
|
|
7
8
|
signature: Buffer;
|
|
8
9
|
userHandle: Buffer;
|
|
9
|
-
prf: [Buffer, Buffer];
|
|
10
|
-
largeBlob: Buffer;
|
|
10
|
+
prf: [Buffer | null, Buffer | null];
|
|
11
|
+
largeBlob: Buffer | null;
|
|
11
12
|
}
|
|
12
|
-
declare function getCredential(rpid: string, challenge: Buffer, nativeWindowHandle: Buffer, allowedCredentialIds: Buffer[]): Promise<GetCredentialResult>;
|
|
13
|
+
declare function getCredential(rpid: string, challenge: Buffer, nativeWindowHandle: Buffer, origin: string, allowedCredentialIds: Buffer[], userVerificationPreference?: UserVerificationPreference): Promise<GetCredentialResult>;
|
|
13
14
|
export { getCredential };
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8BA,KAAK,uBAAuB,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAC7D,MAAM,MAAM,0BAA0B,GAClC,WAAW,GACX,UAAU,GACV,aAAa,CAAC;AAElB,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,iBAAS,aAAa,CACpB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,MAAM,EAAE,EAC9B,0BAA0B,CAAC,EAAE,0BAA0B,GACtD,OAAO,CAAC,mBAAmB,CAAC,CA+I9B;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { fromPointer } from "objc-js";
|
|
2
2
|
import { createAuthorizationControllerDelegate } from "./objc/authentication-services/as-authorization-controller-delegate.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ASAuthorizationController } from "./objc/authentication-services/as-authorization-controller.js";
|
|
4
4
|
import { createPresentationContextProvider } from "./objc/authentication-services/as-authorization-controller-presentation-context-providing.js";
|
|
5
5
|
import { createPlatformPublicKeyCredentialProvider } from "./objc/authentication-services/as-authorization-platform-public-key-credential-provider.js";
|
|
6
6
|
import { createPlatformPublicKeyCredentialDescriptor } from "./objc/authentication-services/as-authorization-platform-public-key-credential-descriptor.js";
|
|
7
7
|
import { NSArray, NSArrayFromObjects } from "./objc/foundation/nsarray.js";
|
|
8
8
|
import { bufferFromNSDataDirect, NSDataFromBuffer, } from "./objc/foundation/nsdata.js";
|
|
9
9
|
import { NSStringFromString } from "./objc/foundation/nsstring.js";
|
|
10
|
-
import { PromiseWithResolvers } from "./helpers.js";
|
|
10
|
+
import { bufferToBase64Url, clientDataJsonBufferToHash, PromiseWithResolvers, serializeOrigin, } from "./helpers.js";
|
|
11
11
|
import { ASAuthorizationPublicKeyCredentialAttachment } from "./objc/authentication-services/enums/as-authorization-public-key-credential-attachment.js";
|
|
12
|
-
|
|
12
|
+
import { removeClientDataHash, setClientDataHash, WebauthnGetController, } from "./get-authorization-controller.js";
|
|
13
|
+
function getCredential(rpid, challenge, nativeWindowHandle, origin, allowedCredentialIds, userVerificationPreference) {
|
|
13
14
|
const { promise, resolve, reject } = PromiseWithResolvers();
|
|
14
15
|
// Create NS objects
|
|
15
16
|
const NS_rpID = NSStringFromString(rpid);
|
|
@@ -19,9 +20,36 @@ function getCredential(rpid, challenge, nativeWindowHandle, allowedCredentialIds
|
|
|
19
20
|
const platformProvider = createPlatformPublicKeyCredentialProvider(NS_rpID);
|
|
20
21
|
// let platformKeyRequest = platformProvider.createCredentialAssertionRequest(challenge: challenge)
|
|
21
22
|
const platformKeyRequest = platformProvider.createCredentialAssertionRequestWithChallenge$(NS_challenge);
|
|
23
|
+
// platformKeyRequest.userVerificationPreference = ???
|
|
24
|
+
if (userVerificationPreference === "preferred") {
|
|
25
|
+
platformKeyRequest.setUserVerificationPreference$(NSStringFromString("preferred"));
|
|
26
|
+
}
|
|
27
|
+
else if (userVerificationPreference === "required") {
|
|
28
|
+
platformKeyRequest.setUserVerificationPreference$(NSStringFromString("required"));
|
|
29
|
+
}
|
|
30
|
+
else if (userVerificationPreference === "discouraged") {
|
|
31
|
+
platformKeyRequest.setUserVerificationPreference$(NSStringFromString("discouraged"));
|
|
32
|
+
}
|
|
22
33
|
// let authController = ASAuthorizationController(authorizationRequests: [platformKeyRequest])
|
|
23
34
|
const requestsArray = NSArray.arrayWithObject$(platformKeyRequest);
|
|
24
|
-
const authController =
|
|
35
|
+
const authController = WebauthnGetController.alloc().initWithAuthorizationRequests$(requestsArray);
|
|
36
|
+
// OLD: const authController = createAuthorizationController(requestsArray);
|
|
37
|
+
// Generate the client data
|
|
38
|
+
const serializedOrigin = serializeOrigin(origin);
|
|
39
|
+
const clientData = {
|
|
40
|
+
type: "webauthn.get",
|
|
41
|
+
challenge: bufferToBase64Url(challenge),
|
|
42
|
+
origin: serializedOrigin,
|
|
43
|
+
crossOrigin: false,
|
|
44
|
+
};
|
|
45
|
+
const clientDataJSON = JSON.stringify(clientData);
|
|
46
|
+
const clientDataBuffer = Buffer.from(clientDataJSON, "utf-8");
|
|
47
|
+
const clientDataHash = clientDataJsonBufferToHash(clientDataBuffer);
|
|
48
|
+
console.log("clientDataJSON", clientDataJSON);
|
|
49
|
+
setClientDataHash(authController, clientDataHash);
|
|
50
|
+
const finished = (_success) => {
|
|
51
|
+
removeClientDataHash(authController);
|
|
52
|
+
};
|
|
25
53
|
// Set allowed credentials if provided
|
|
26
54
|
if (allowedCredentialIds.length > 0) {
|
|
27
55
|
const allowedCredentials = NSArrayFromObjects(allowedCredentialIds.map((id) => createPlatformPublicKeyCredentialDescriptor(NSDataFromBuffer(id))));
|
|
@@ -41,21 +69,25 @@ function getCredential(rpid, challenge, nativeWindowHandle, allowedCredentialIds
|
|
|
41
69
|
authenticatorAttachment = "cross-platform";
|
|
42
70
|
}
|
|
43
71
|
const prf = credential.prf();
|
|
44
|
-
const prfFirst = prf.first();
|
|
45
|
-
const prfSecond = prf.second();
|
|
72
|
+
const prfFirst = prf?.first ? prf.first() : null;
|
|
73
|
+
const prfSecond = prf?.second ? prf.second() : null;
|
|
74
|
+
console.log("rawAuthenticatorData", credential.rawAuthenticatorData());
|
|
46
75
|
resolve({
|
|
47
76
|
id,
|
|
48
77
|
authenticatorAttachment,
|
|
49
|
-
clientDataJSON: bufferFromNSDataDirect(credential.rawClientDataJSON()),
|
|
78
|
+
clientDataJSON: clientDataBuffer, //bufferFromNSDataDirect(credential.rawClientDataJSON()),
|
|
50
79
|
authenticatorData: bufferFromNSDataDirect(credential.rawAuthenticatorData()),
|
|
51
80
|
signature: bufferFromNSDataDirect(credential.signature()),
|
|
52
81
|
userHandle: bufferFromNSDataDirect(credential.userID()),
|
|
53
82
|
prf: [
|
|
54
|
-
bufferFromNSDataDirect(prfFirst),
|
|
55
|
-
bufferFromNSDataDirect(prfSecond),
|
|
83
|
+
prfFirst ? bufferFromNSDataDirect(prfFirst) : null,
|
|
84
|
+
prfSecond ? bufferFromNSDataDirect(prfSecond) : null,
|
|
56
85
|
],
|
|
57
|
-
largeBlob:
|
|
86
|
+
largeBlob: credential.largeBlob()
|
|
87
|
+
? bufferFromNSDataDirect(credential.largeBlob().readData())
|
|
88
|
+
: null,
|
|
58
89
|
});
|
|
90
|
+
finished(true);
|
|
59
91
|
},
|
|
60
92
|
didCompleteWithError: (_, error) => {
|
|
61
93
|
// Parse the NSError into a readable format
|
|
@@ -63,6 +95,7 @@ function getCredential(rpid, challenge, nativeWindowHandle, allowedCredentialIds
|
|
|
63
95
|
const errorMessage = parsedError.localizedDescription().UTF8String();
|
|
64
96
|
console.error("Authorization failed:", errorMessage);
|
|
65
97
|
reject(new Error(errorMessage));
|
|
98
|
+
finished(false);
|
|
66
99
|
},
|
|
67
100
|
});
|
|
68
101
|
authController.setDelegate$(delegate);
|
|
@@ -77,6 +110,7 @@ function getCredential(rpid, challenge, nativeWindowHandle, allowedCredentialIds
|
|
|
77
110
|
});
|
|
78
111
|
authController.setPresentationContextProvider$(presentationContextProvider);
|
|
79
112
|
// authController.performRequests()
|
|
113
|
+
console.log("performing requests");
|
|
80
114
|
authController.performRequests();
|
|
81
115
|
return promise;
|
|
82
116
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,qCAAqC,EAAE,MAAM,wEAAwE,CAAC;AAC/H,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,qCAAqC,EAAE,MAAM,wEAAwE,CAAC;AAC/H,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAC1G,OAAO,EAAE,iCAAiC,EAAE,MAAM,8FAA8F,CAAC;AACjJ,OAAO,EAAE,yCAAyC,EAAE,MAAM,4FAA4F,CAAC;AACvJ,OAAO,EAAE,2CAA2C,EAAE,MAAM,8FAA8F,CAAC;AAG3J,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAEL,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,oBAAoB,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AQ,EAAE,CAAC;oBAC3D,CAAC,CAAC,IAAI;aACT,CAAC,CAAC;YAEH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QACD,oBAAoB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YACjC,2CAA2C;YAC3C,MAAM,WAAW,GAAG,KAA6C,CAAC;YAClE,MAAM,YAAY,GAAG,WAAW,CAAC,oBAAoB,EAAE,CAAC,UAAU,EAAE,CAAC;YACrE,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,YAAY,CAAC,CAAC;YACrD,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAEhC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;IACH,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAEtC,oDAAoD;IACpD,MAAM,2BAA2B,GAAG,iCAAiC,CAAC;QACpE,4CAA4C,EAAE,GAAG,EAAE;YACjD,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,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACnC,cAAc,CAAC,eAAe,EAAE,CAAC;IAEjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/test/index.js
CHANGED
|
@@ -4,6 +4,6 @@ import { getCredential } from "../index.js";
|
|
|
4
4
|
const window = createEmptyWindow();
|
|
5
5
|
const nsView = getNativeWindowHandle(window);
|
|
6
6
|
const nsViewPointer = getPointer(nsView);
|
|
7
|
-
const result = getCredential("example.com", Buffer.from("challenge"), nsViewPointer, []);
|
|
7
|
+
const result = getCredential("example.com", Buffer.from("challenge"), nsViewPointer, "https://example.com", []);
|
|
8
8
|
console.log("Result:", result);
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/test/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;AACnC,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC7C,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,MAAM,GAAG,aAAa,CAC1B,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EACxB,aAAa,EACb,EAAE,CACH,CAAC;AACF,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;AACnC,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC7C,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,MAAM,GAAG,aAAa,CAC1B,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EACxB,aAAa,EACb,qBAAqB,EACrB,EAAE,CACH,CAAC;AACF,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-webauthn",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"repository": "https://github.com/iamEvanYT/electron-webauthn",
|
|
5
5
|
"description": "Add support for WebAuthn for Electron.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "^5"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"objc-js": "^0.0.
|
|
31
|
+
"objc-js": "^0.0.14"
|
|
32
32
|
},
|
|
33
33
|
"trustedDependencies": [
|
|
34
34
|
"objc-js"
|