@capgo/capacitor-passkey 8.2.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/CapgoCapacitorPasskey.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +692 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskey.java +21 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskeyPlugin.java +299 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1034 -0
- package/dist/esm/definitions.d.ts +531 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +87 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.d.ts +14 -0
- package/dist/esm/internal.js +2 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/shim.d.ts +8 -0
- package/dist/esm/shim.js +108 -0
- package/dist/esm/shim.js.map +1 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +69 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/esm/webauthn.d.ts +23 -0
- package/dist/esm/webauthn.js +440 -0
- package/dist/esm/webauthn.js.map +1 -0
- package/dist/plugin.cjs.js +707 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +710 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskey.swift +39 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskeyPlugin.swift +388 -0
- package/ios/Tests/CapacitorPasskeyPluginTests/CapacitorPasskeyPluginTests.swift +17 -0
- package/package.json +105 -0
- package/scripts/configure-native.js +263 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CapacitorPasskeyPlugin, ShimWebAuthnOptions } from './definitions';
|
|
2
|
+
interface InstallWebAuthnShimOptions {
|
|
3
|
+
root?: typeof globalThis;
|
|
4
|
+
plugin: CapacitorPasskeyPlugin;
|
|
5
|
+
options?: ShimWebAuthnOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function installWebAuthnShim({ root, plugin, options }: InstallWebAuthnShimOptions): void;
|
|
8
|
+
export {};
|
package/dist/esm/shim.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { abortIfNeeded, createPasskeyDomException, credentialFromJSON, normalizePluginError, parseCreationOptionsFromJSON, parseRequestOptionsFromJSON, webAuthnCreationOptionsToJSON, webAuthnRequestOptionsToJSON, } from './webauthn';
|
|
2
|
+
export function installWebAuthnShim({ root = globalThis, plugin, options }) {
|
|
3
|
+
var _a;
|
|
4
|
+
const shimRoot = root;
|
|
5
|
+
const config = Object.assign(Object.assign({}, ((_a = shimRoot.__capgoPasskeyShimConfig) !== null && _a !== void 0 ? _a : {})), (options !== null && options !== void 0 ? options : {}));
|
|
6
|
+
shimRoot.__capgoPasskeyShimConfig = config;
|
|
7
|
+
if (shimRoot.__capgoPasskeyShimInstalled && !config.force) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const originalCredentials = shimRoot.navigator.credentials;
|
|
11
|
+
const patchedCredentials = {
|
|
12
|
+
create: async (request) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const currentConfig = (_a = shimRoot.__capgoPasskeyShimConfig) !== null && _a !== void 0 ? _a : {};
|
|
15
|
+
if (!(request === null || request === void 0 ? void 0 : request.publicKey)) {
|
|
16
|
+
if (originalCredentials === null || originalCredentials === void 0 ? void 0 : originalCredentials.create) {
|
|
17
|
+
return originalCredentials.create.call(originalCredentials, request);
|
|
18
|
+
}
|
|
19
|
+
throw createPasskeyDomException('NotSupportedError', 'Only public-key credential creation is supported.');
|
|
20
|
+
}
|
|
21
|
+
abortIfNeeded(request.signal);
|
|
22
|
+
const response = (await plugin.createCredential({
|
|
23
|
+
origin: currentConfig.origin,
|
|
24
|
+
publicKey: webAuthnCreationOptionsToJSON(request.publicKey, currentConfig.origin),
|
|
25
|
+
}));
|
|
26
|
+
return credentialFromJSON(response);
|
|
27
|
+
},
|
|
28
|
+
get: async (request) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const currentConfig = (_a = shimRoot.__capgoPasskeyShimConfig) !== null && _a !== void 0 ? _a : {};
|
|
31
|
+
if (!(request === null || request === void 0 ? void 0 : request.publicKey)) {
|
|
32
|
+
if (originalCredentials === null || originalCredentials === void 0 ? void 0 : originalCredentials.get) {
|
|
33
|
+
return originalCredentials.get.call(originalCredentials, request);
|
|
34
|
+
}
|
|
35
|
+
throw createPasskeyDomException('NotSupportedError', 'Only public-key credential requests are supported.');
|
|
36
|
+
}
|
|
37
|
+
abortIfNeeded(request.signal);
|
|
38
|
+
if (request.mediation === 'conditional') {
|
|
39
|
+
throw createPasskeyDomException('NotSupportedError', 'Conditional mediation is not available through the Capacitor passkey shim.');
|
|
40
|
+
}
|
|
41
|
+
const response = (await plugin.getCredential({
|
|
42
|
+
mediation: request.mediation,
|
|
43
|
+
origin: currentConfig.origin,
|
|
44
|
+
publicKey: webAuthnRequestOptionsToJSON(request.publicKey, currentConfig.origin),
|
|
45
|
+
}));
|
|
46
|
+
return credentialFromJSON(response);
|
|
47
|
+
},
|
|
48
|
+
preventSilentAccess: async () => {
|
|
49
|
+
if (originalCredentials === null || originalCredentials === void 0 ? void 0 : originalCredentials.preventSilentAccess) {
|
|
50
|
+
await originalCredentials.preventSilentAccess.call(originalCredentials);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
store: async (credential) => {
|
|
54
|
+
if ((originalCredentials === null || originalCredentials === void 0 ? void 0 : originalCredentials.store) && credential) {
|
|
55
|
+
await originalCredentials.store.call(originalCredentials, credential);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
try {
|
|
60
|
+
Object.defineProperty(shimRoot.navigator, 'credentials', {
|
|
61
|
+
configurable: true,
|
|
62
|
+
value: patchedCredentials,
|
|
63
|
+
writable: false,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (_b) {
|
|
67
|
+
shimRoot.navigator.credentials = patchedCredentials;
|
|
68
|
+
}
|
|
69
|
+
installPublicKeyCredentialStatics(shimRoot, plugin);
|
|
70
|
+
shimRoot.__capgoPasskeyShimInstalled = true;
|
|
71
|
+
}
|
|
72
|
+
function installPublicKeyCredentialStatics(root, plugin) {
|
|
73
|
+
var _a;
|
|
74
|
+
const nativePublicKeyCredential = (_a = root.PublicKeyCredential) !== null && _a !== void 0 ? _a : class {
|
|
75
|
+
};
|
|
76
|
+
const supportRequest = async () => {
|
|
77
|
+
try {
|
|
78
|
+
return await plugin.isSupported();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw normalizePluginError(error);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
defineStatic(nativePublicKeyCredential, 'isUserVerifyingPlatformAuthenticatorAvailable', async () => {
|
|
85
|
+
const support = await supportRequest();
|
|
86
|
+
return support.available;
|
|
87
|
+
});
|
|
88
|
+
defineStatic(nativePublicKeyCredential, 'isConditionalMediationAvailable', async () => {
|
|
89
|
+
const support = await supportRequest();
|
|
90
|
+
return support.conditionalMediation;
|
|
91
|
+
});
|
|
92
|
+
defineStatic(nativePublicKeyCredential, 'parseCreationOptionsFromJSON', parseCreationOptionsFromJSON);
|
|
93
|
+
defineStatic(nativePublicKeyCredential, 'parseRequestOptionsFromJSON', parseRequestOptionsFromJSON);
|
|
94
|
+
root.PublicKeyCredential = nativePublicKeyCredential;
|
|
95
|
+
}
|
|
96
|
+
function defineStatic(target, key, value) {
|
|
97
|
+
try {
|
|
98
|
+
Object.defineProperty(target, key, {
|
|
99
|
+
configurable: true,
|
|
100
|
+
value,
|
|
101
|
+
writable: true,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (_a) {
|
|
105
|
+
Reflect.set(target, key, value);
|
|
106
|
+
}
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AAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC;IAEF,YAAY,CAAC,yBAAyB,EAAE,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAClG,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC,yBAAyB,EAAE,iCAAiC,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,oBAAoB,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC,yBAAyB,EAAE,8BAA8B,EAAE,4BAA4B,CAAC,CAAC;IACtG,YAAY,CAAC,yBAAyB,EAAE,6BAA6B,EAAE,2BAA2B,CAAC,CAAC;IAEpG,IAAI,CAAC,mBAAmB,GAAG,yBAAuD,CAAC;AACrF,CAAC;AAED,SAAS,YAAY,CAAC,MAAc,EAAE,GAAW,EAAE,KAAc;IAC/D,IAAI,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YACjC,YAAY,EAAE,IAAI;YAClB,KAAK;YACL,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;IACL,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import type {\n CapacitorPasskeyPlugin,\n PasskeyAuthenticationCredential,\n PasskeyRegistrationCredential,\n ShimWebAuthnOptions,\n} from './definitions';\nimport {\n abortIfNeeded,\n createPasskeyDomException,\n credentialFromJSON,\n normalizePluginError,\n parseCreationOptionsFromJSON,\n parseRequestOptionsFromJSON,\n webAuthnCreationOptionsToJSON,\n webAuthnRequestOptionsToJSON,\n} from './webauthn';\n\ntype CredentialsContainerLike = Pick<CredentialsContainer, 'create' | 'get' | 'preventSilentAccess' | 'store'>;\n\ntype ShimRoot = typeof globalThis & {\n navigator: Navigator & { credentials?: CredentialsContainerLike };\n __capgoPasskeyShimInstalled?: boolean;\n __capgoPasskeyShimConfig?: ShimWebAuthnOptions;\n};\n\ninterface InstallWebAuthnShimOptions {\n root?: typeof globalThis;\n plugin: CapacitorPasskeyPlugin;\n options?: ShimWebAuthnOptions;\n}\n\nexport function installWebAuthnShim({ root = globalThis, plugin, options }: InstallWebAuthnShimOptions): void {\n const shimRoot = root as ShimRoot;\n const config = {\n ...(shimRoot.__capgoPasskeyShimConfig ?? {}),\n ...(options ?? {}),\n };\n\n shimRoot.__capgoPasskeyShimConfig = config;\n\n if (shimRoot.__capgoPasskeyShimInstalled && !config.force) {\n return;\n }\n\n const originalCredentials = shimRoot.navigator.credentials;\n const patchedCredentials: CredentialsContainerLike = {\n create: async (request?: CredentialCreationOptions): Promise<Credential | null> => {\n const currentConfig = shimRoot.__capgoPasskeyShimConfig ?? {};\n\n if (!request?.publicKey) {\n if (originalCredentials?.create) {\n return originalCredentials.create.call(originalCredentials, request);\n }\n\n throw createPasskeyDomException('NotSupportedError', 'Only public-key credential creation is supported.');\n }\n\n abortIfNeeded(request.signal);\n const response = (await plugin.createCredential({\n origin: currentConfig.origin,\n publicKey: webAuthnCreationOptionsToJSON(request.publicKey, currentConfig.origin),\n })) as PasskeyRegistrationCredential;\n\n return credentialFromJSON(response) as unknown as Credential;\n },\n get: async (request?: CredentialRequestOptions): Promise<Credential | null> => {\n const currentConfig = shimRoot.__capgoPasskeyShimConfig ?? {};\n\n if (!request?.publicKey) {\n if (originalCredentials?.get) {\n return originalCredentials.get.call(originalCredentials, request);\n }\n\n throw createPasskeyDomException('NotSupportedError', 'Only public-key credential requests are supported.');\n }\n\n abortIfNeeded(request.signal);\n if (request.mediation === 'conditional') {\n throw createPasskeyDomException(\n 'NotSupportedError',\n 'Conditional mediation is not available through the Capacitor passkey shim.',\n );\n }\n\n const response = (await plugin.getCredential({\n mediation: request.mediation,\n origin: currentConfig.origin,\n publicKey: webAuthnRequestOptionsToJSON(request.publicKey, currentConfig.origin),\n })) as PasskeyAuthenticationCredential;\n\n return credentialFromJSON(response) as unknown as Credential;\n },\n preventSilentAccess: async (): Promise<void> => {\n if (originalCredentials?.preventSilentAccess) {\n await originalCredentials.preventSilentAccess.call(originalCredentials);\n }\n },\n store: async (credential?: Credential): Promise<void> => {\n if (originalCredentials?.store && credential) {\n await originalCredentials.store.call(originalCredentials, credential);\n }\n },\n };\n\n try {\n Object.defineProperty(shimRoot.navigator, 'credentials', {\n configurable: true,\n value: patchedCredentials,\n writable: false,\n });\n } catch {\n (shimRoot.navigator as Navigator & { credentials?: CredentialsContainerLike }).credentials = patchedCredentials;\n }\n\n installPublicKeyCredentialStatics(shimRoot, plugin);\n shimRoot.__capgoPasskeyShimInstalled = true;\n}\n\nfunction installPublicKeyCredentialStatics(root: ShimRoot, plugin: CapacitorPasskeyPlugin): void {\n const nativePublicKeyCredential = root.PublicKeyCredential ?? class {};\n const supportRequest = async () => {\n try {\n return await plugin.isSupported();\n } catch (error) {\n throw normalizePluginError(error);\n }\n };\n\n defineStatic(nativePublicKeyCredential, 'isUserVerifyingPlatformAuthenticatorAvailable', async () => {\n const support = await supportRequest();\n return support.available;\n });\n\n defineStatic(nativePublicKeyCredential, 'isConditionalMediationAvailable', async () => {\n const support = await supportRequest();\n return support.conditionalMediation;\n });\n\n defineStatic(nativePublicKeyCredential, 'parseCreationOptionsFromJSON', parseCreationOptionsFromJSON);\n defineStatic(nativePublicKeyCredential, 'parseRequestOptionsFromJSON', parseRequestOptionsFromJSON);\n\n root.PublicKeyCredential = nativePublicKeyCredential as typeof PublicKeyCredential;\n}\n\nfunction defineStatic(target: object, key: string, value: unknown): void {\n try {\n Object.defineProperty(target, key, {\n configurable: true,\n value,\n writable: true,\n });\n } catch {\n Reflect.set(target, key, value);\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PasskeyAuthenticationCredential, PasskeyRuntimeConfiguration, PasskeyRegistrationCredential, PasskeySupportResult, PluginVersionResult } from './definitions';
|
|
3
|
+
import type { NativeCapacitorPasskeyPlugin, NativePasskeyRequest } from './internal';
|
|
4
|
+
export declare class CapacitorPasskeyWeb extends WebPlugin implements NativeCapacitorPasskeyPlugin {
|
|
5
|
+
createCredential(options: NativePasskeyRequest): Promise<PasskeyRegistrationCredential>;
|
|
6
|
+
getCredential(options: NativePasskeyRequest): Promise<PasskeyAuthenticationCredential>;
|
|
7
|
+
getConfiguration(): Promise<PasskeyRuntimeConfiguration>;
|
|
8
|
+
isSupported(): Promise<PasskeySupportResult>;
|
|
9
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
10
|
+
private ensureCredentials;
|
|
11
|
+
private currentOrigin;
|
|
12
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import { browserAuthenticationToJSON, browserCreationOptionsFromJSON, browserRegistrationToJSON, browserRequestOptionsFromJSON, createPasskeyDomException, } from './webauthn';
|
|
3
|
+
export class CapacitorPasskeyWeb extends WebPlugin {
|
|
4
|
+
async createCredential(options) {
|
|
5
|
+
const credentials = this.ensureCredentials();
|
|
6
|
+
const parsed = JSON.parse(options.requestJson);
|
|
7
|
+
const credential = await credentials.create({
|
|
8
|
+
publicKey: browserCreationOptionsFromJSON(parsed),
|
|
9
|
+
});
|
|
10
|
+
return browserRegistrationToJSON(credential);
|
|
11
|
+
}
|
|
12
|
+
async getCredential(options) {
|
|
13
|
+
const credentials = this.ensureCredentials();
|
|
14
|
+
const parsed = JSON.parse(options.requestJson);
|
|
15
|
+
const credential = await credentials.get({
|
|
16
|
+
publicKey: browserRequestOptionsFromJSON(parsed),
|
|
17
|
+
});
|
|
18
|
+
return browserAuthenticationToJSON(credential);
|
|
19
|
+
}
|
|
20
|
+
async getConfiguration() {
|
|
21
|
+
const origin = this.currentOrigin();
|
|
22
|
+
const domains = origin ? [new URL(origin).hostname] : [];
|
|
23
|
+
return {
|
|
24
|
+
autoShim: true,
|
|
25
|
+
domains,
|
|
26
|
+
origin,
|
|
27
|
+
platform: 'web',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async isSupported() {
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
const available = typeof globalThis.PublicKeyCredential !== 'undefined' &&
|
|
33
|
+
typeof ((_b = (_a = globalThis.navigator) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b.create) === 'function' &&
|
|
34
|
+
typeof ((_d = (_c = globalThis.navigator) === null || _c === void 0 ? void 0 : _c.credentials) === null || _d === void 0 ? void 0 : _d.get) === 'function';
|
|
35
|
+
let conditionalMediation = false;
|
|
36
|
+
if (available && typeof globalThis.PublicKeyCredential.isConditionalMediationAvailable === 'function') {
|
|
37
|
+
conditionalMediation = await globalThis.PublicKeyCredential.isConditionalMediationAvailable();
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
available,
|
|
41
|
+
conditionalMediation,
|
|
42
|
+
platform: 'web',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async getPluginVersion() {
|
|
46
|
+
return {
|
|
47
|
+
version: 'web',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
ensureCredentials() {
|
|
51
|
+
var _a, _b, _c, _d;
|
|
52
|
+
if (typeof globalThis.PublicKeyCredential === 'undefined' ||
|
|
53
|
+
typeof ((_b = (_a = globalThis.navigator) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b.create) !== 'function' ||
|
|
54
|
+
typeof ((_d = (_c = globalThis.navigator) === null || _c === void 0 ? void 0 : _c.credentials) === null || _d === void 0 ? void 0 : _d.get) !== 'function') {
|
|
55
|
+
throw createPasskeyDomException('NotSupportedError', 'WebAuthn is not available in this browser.');
|
|
56
|
+
}
|
|
57
|
+
return globalThis.navigator.credentials;
|
|
58
|
+
}
|
|
59
|
+
currentOrigin() {
|
|
60
|
+
if (typeof globalThis.location === 'undefined') {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (globalThis.location.protocol !== 'http:' && globalThis.location.protocol !== 'https:') {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return globalThis.location.origin;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,yBAAyB,EACzB,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChD,KAAK,CAAC,gBAAgB,CAAC,OAA6B;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAkD,CAAC;QAChG,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC;YAC1C,SAAS,EAAE,8BAA8B,CAAC,MAAM,CAAC;SAClD,CAAC,CAAC;QAEH,OAAO,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAA6B;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAiD,CAAC;QAC/F,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC;YACvC,SAAS,EAAE,6BAA6B,CAAC,MAAM,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AAA,MAAA,MAAA,UAAU,CAAC,SAAS,0CAAE,WAAW,0CAAE,GAAG,CAAA,KAAK,UAAU,EAC5D,CAAC;YACD,MAAM,yBAAyB,CAAC,mBAAmB,EAAE,4CAA4C,CAAC,CAAC;QACrG,CAAC;QAED,OAAO,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC;IAC1C,CAAC;IAEO,aAAa;QACnB,IAAI,OAAO,UAAU,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAC/C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,KAAK,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1F,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC;IACpC,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n PasskeyAuthenticationCredential,\n PasskeyPublicKeyCredentialCreationOptionsJSON,\n PasskeyPublicKeyCredentialRequestOptionsJSON,\n PasskeyRuntimeConfiguration,\n PasskeyRegistrationCredential,\n PasskeySupportResult,\n PluginVersionResult,\n} from './definitions';\nimport type { NativeCapacitorPasskeyPlugin, NativePasskeyRequest } from './internal';\nimport {\n browserAuthenticationToJSON,\n browserCreationOptionsFromJSON,\n browserRegistrationToJSON,\n browserRequestOptionsFromJSON,\n createPasskeyDomException,\n} from './webauthn';\n\nexport class CapacitorPasskeyWeb extends WebPlugin implements NativeCapacitorPasskeyPlugin {\n async createCredential(options: NativePasskeyRequest): Promise<PasskeyRegistrationCredential> {\n const credentials = this.ensureCredentials();\n const parsed = JSON.parse(options.requestJson) as PasskeyPublicKeyCredentialCreationOptionsJSON;\n const credential = await credentials.create({\n publicKey: browserCreationOptionsFromJSON(parsed),\n });\n\n return browserRegistrationToJSON(credential);\n }\n\n async getCredential(options: NativePasskeyRequest): Promise<PasskeyAuthenticationCredential> {\n const credentials = this.ensureCredentials();\n const parsed = JSON.parse(options.requestJson) as PasskeyPublicKeyCredentialRequestOptionsJSON;\n const credential = await credentials.get({\n publicKey: browserRequestOptionsFromJSON(parsed),\n });\n\n return browserAuthenticationToJSON(credential);\n }\n\n async getConfiguration(): Promise<PasskeyRuntimeConfiguration> {\n const origin = this.currentOrigin();\n const domains = origin ? [new URL(origin).hostname] : [];\n\n return {\n autoShim: true,\n domains,\n origin,\n platform: 'web',\n };\n }\n\n async isSupported(): Promise<PasskeySupportResult> {\n const available =\n typeof globalThis.PublicKeyCredential !== 'undefined' &&\n typeof globalThis.navigator?.credentials?.create === 'function' &&\n typeof globalThis.navigator?.credentials?.get === 'function';\n\n let conditionalMediation = false;\n\n if (available && typeof globalThis.PublicKeyCredential.isConditionalMediationAvailable === 'function') {\n conditionalMediation = await globalThis.PublicKeyCredential.isConditionalMediationAvailable();\n }\n\n return {\n available,\n conditionalMediation,\n platform: 'web',\n };\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return {\n version: 'web',\n };\n }\n\n private ensureCredentials(): CredentialsContainer {\n if (\n typeof globalThis.PublicKeyCredential === 'undefined' ||\n typeof globalThis.navigator?.credentials?.create !== 'function' ||\n typeof globalThis.navigator?.credentials?.get !== 'function'\n ) {\n throw createPasskeyDomException('NotSupportedError', 'WebAuthn is not available in this browser.');\n }\n\n return globalThis.navigator.credentials;\n }\n\n private currentOrigin(): string | undefined {\n if (typeof globalThis.location === 'undefined') {\n return undefined;\n }\n\n if (globalThis.location.protocol !== 'http:' && globalThis.location.protocol !== 'https:') {\n return undefined;\n }\n\n return globalThis.location.origin;\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CreateCredentialOptions, GetCredentialOptions, PasskeyAuthenticationCredential, PasskeyPublicKeyCredentialCreationOptionsJSON, PasskeyPublicKeyCredentialRequestOptionsJSON, PasskeyRegistrationCredential } from './definitions';
|
|
2
|
+
import type { NativePasskeyRequest } from './internal';
|
|
3
|
+
type BufferLike = BufferSource | ArrayLike<number>;
|
|
4
|
+
type CredentialJson = PasskeyRegistrationCredential | PasskeyAuthenticationCredential;
|
|
5
|
+
export declare function createNativeRequest(options: CreateCredentialOptions | GetCredentialOptions): NativePasskeyRequest;
|
|
6
|
+
export declare function webAuthnCreationOptionsToJSON(options: PublicKeyCredentialCreationOptions, origin?: string): PasskeyPublicKeyCredentialCreationOptionsJSON;
|
|
7
|
+
export declare function webAuthnRequestOptionsToJSON(options: PublicKeyCredentialRequestOptions, origin?: string): PasskeyPublicKeyCredentialRequestOptionsJSON;
|
|
8
|
+
export declare function normalizeCreationOptionsJSON(options: PasskeyPublicKeyCredentialCreationOptionsJSON, origin?: string): PasskeyPublicKeyCredentialCreationOptionsJSON;
|
|
9
|
+
export declare function normalizeRequestOptionsJSON(options: PasskeyPublicKeyCredentialRequestOptionsJSON, origin?: string): PasskeyPublicKeyCredentialRequestOptionsJSON;
|
|
10
|
+
export declare function browserCreationOptionsFromJSON(options: PasskeyPublicKeyCredentialCreationOptionsJSON): PublicKeyCredentialCreationOptions;
|
|
11
|
+
export declare function browserRequestOptionsFromJSON(options: PasskeyPublicKeyCredentialRequestOptionsJSON): PublicKeyCredentialRequestOptions;
|
|
12
|
+
export declare function browserRegistrationToJSON(credential: Credential | null): Promise<PasskeyRegistrationCredential>;
|
|
13
|
+
export declare function browserAuthenticationToJSON(credential: Credential | null): Promise<PasskeyAuthenticationCredential>;
|
|
14
|
+
export declare function credentialFromJSON(credential: CredentialJson): PublicKeyCredential;
|
|
15
|
+
export declare function parseCreationOptionsFromJSON(options: PasskeyPublicKeyCredentialCreationOptionsJSON): PublicKeyCredentialCreationOptions;
|
|
16
|
+
export declare function parseRequestOptionsFromJSON(options: PasskeyPublicKeyCredentialRequestOptionsJSON): PublicKeyCredentialRequestOptions;
|
|
17
|
+
export declare function decodeBase64Url(value: string): ArrayBuffer;
|
|
18
|
+
export declare function encodeBase64Url(value: BufferLike | null | undefined): string;
|
|
19
|
+
export declare function resolveOrigin(explicitOrigin?: string, rpId?: string): string | undefined;
|
|
20
|
+
export declare function createPasskeyDomException(name: string, message: string): Error;
|
|
21
|
+
export declare function abortIfNeeded(signal?: AbortSignal | null): void;
|
|
22
|
+
export declare function normalizePluginError(error: unknown): Error;
|
|
23
|
+
export {};
|