@yielded/auth-simplewebauthn 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/Browser.d.mts +4 -0
- package/dist/Browser.mjs +4 -0
- package/dist/Server.d.mts +3 -0
- package/dist/Server.mjs +3 -0
- package/dist/internal/browser/PasskeyBrowser.d.mts +17 -0
- package/dist/internal/browser/PasskeyBrowser.mjs +10 -0
- package/dist/internal/browser/PasskeyBrowser.mjs.map +1 -0
- package/dist/internal/browser/models.d.mts +37 -0
- package/dist/internal/browser/models.mjs +41 -0
- package/dist/internal/browser/models.mjs.map +1 -0
- package/dist/internal/browser/simplewebauthn.d.mts +16 -0
- package/dist/internal/browser/simplewebauthn.mjs +410 -0
- package/dist/internal/browser/simplewebauthn.mjs.map +1 -0
- package/dist/internal/server/configuration.mjs +43 -0
- package/dist/internal/server/configuration.mjs.map +1 -0
- package/dist/internal/server/models.d.mts +20 -0
- package/dist/internal/server/models.mjs +8 -0
- package/dist/internal/server/models.mjs.map +1 -0
- package/dist/internal/server/protocol.d.mts +59 -0
- package/dist/internal/server/protocol.mjs +400 -0
- package/dist/internal/server/protocol.mjs.map +1 -0
- package/package.json +1 -0
- package/src/Browser.ts +19 -0
- package/src/Server.ts +6 -0
- package/src/internal/browser/PasskeyBrowser.ts +29 -0
- package/src/internal/browser/models.ts +66 -0
- package/src/internal/browser/simplewebauthn.ts +621 -0
- package/src/internal/server/configuration.ts +101 -0
- package/src/internal/server/models.ts +8 -0
- package/src/internal/server/protocol.ts +733 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel van der Merwe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @yielded/auth-simplewebauthn
|
|
2
|
+
|
|
3
|
+
Browser WebAuthn ceremonies and server verification for Yielded Auth, backed by
|
|
4
|
+
SimpleWebAuthn. Import `@yielded/auth-simplewebauthn/Browser` for `make()` and
|
|
5
|
+
`layer`, or `/Server` for `make(options)` and `layer` using `PasskeyConfig`.
|
|
6
|
+
Install the matching `@simplewebauthn/browser` or `@simplewebauthn/server` peer.
|
|
7
|
+
|
|
8
|
+
Applications own challenges, credentials, request binding, sessions, and policy.
|
|
9
|
+
The browser adapter runs only the local ceremony inside the caller's Scope.
|
|
10
|
+
|
|
11
|
+
See the [passkey guide](https://yielded.dev/auth/guide/passkeys).
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserCapability, PasskeyBrowserFailure, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported } from "./internal/browser/models.mjs";
|
|
2
|
+
import { PasskeyBrowser } from "./internal/browser/PasskeyBrowser.mjs";
|
|
3
|
+
import { layerSimpleWebAuthnPasskeyBrowser, makeSimpleWebAuthnPasskeyBrowser } from "./internal/browser/simplewebauthn.mjs";
|
|
4
|
+
export { PasskeyBrowser, PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserCapability, PasskeyBrowserFailure, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported, layerSimpleWebAuthnPasskeyBrowser as layer, makeSimpleWebAuthnPasskeyBrowser as make };
|
package/dist/Browser.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PasskeyBrowser } from "./internal/browser/PasskeyBrowser.mjs";
|
|
2
|
+
import { PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserCapability, PasskeyBrowserFailure, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported } from "./internal/browser/models.mjs";
|
|
3
|
+
import { layerSimpleWebAuthnPasskeyBrowser, makeSimpleWebAuthnPasskeyBrowser } from "./internal/browser/simplewebauthn.mjs";
|
|
4
|
+
export { PasskeyBrowser, PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserCapability, PasskeyBrowserFailure, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported, layerSimpleWebAuthnPasskeyBrowser as layer, makeSimpleWebAuthnPasskeyBrowser as make };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SimpleWebAuthnPasskeyProtocolOptions } from "./internal/server/models.mjs";
|
|
2
|
+
import { layerSimpleWebAuthnPasskeyProtocol, makeSimpleWebAuthnPasskeyProtocol } from "./internal/server/protocol.mjs";
|
|
3
|
+
export { SimpleWebAuthnPasskeyProtocolOptions, layerSimpleWebAuthnPasskeyProtocol as layer, makeSimpleWebAuthnPasskeyProtocol as make };
|
package/dist/Server.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SimpleWebAuthnPasskeyProtocolOptions } from "./internal/server/models.mjs";
|
|
2
|
+
import { layerSimpleWebAuthnPasskeyProtocol, makeSimpleWebAuthnPasskeyProtocol } from "./internal/server/protocol.mjs";
|
|
3
|
+
export { SimpleWebAuthnPasskeyProtocolOptions, layerSimpleWebAuthnPasskeyProtocol as layer, makeSimpleWebAuthnPasskeyProtocol as make };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PasskeyBrowserAuthentication, PasskeyBrowserCapabilities, PasskeyBrowserFailure, PasskeyBrowserRegistration, PasskeyBrowserUnavailable } from "./models.mjs";
|
|
2
|
+
import { PasskeyAuthenticationStarted, PasskeyRegistrationStarted } from "@yielded/auth/Passkey";
|
|
3
|
+
import { Context, Effect } from "effect";
|
|
4
|
+
//#region src/internal/browser/PasskeyBrowser.d.ts
|
|
5
|
+
declare const PasskeyBrowser_base: Context.ServiceClass<PasskeyBrowser, "effect-auth/PasskeyBrowser", {
|
|
6
|
+
readonly capabilities: Effect.Effect<PasskeyBrowserCapabilities, PasskeyBrowserUnavailable>;
|
|
7
|
+
readonly register: (started: typeof PasskeyRegistrationStarted.Type) => Effect.Effect<PasskeyBrowserRegistration, PasskeyBrowserFailure>;
|
|
8
|
+
readonly authenticate: (input: {
|
|
9
|
+
readonly started: typeof PasskeyAuthenticationStarted.Type;
|
|
10
|
+
readonly mediation: "required" | "conditional";
|
|
11
|
+
}) => Effect.Effect<PasskeyBrowserAuthentication, PasskeyBrowserFailure>;
|
|
12
|
+
}>;
|
|
13
|
+
/** Client-local ceremony capability. The caller owns Begin/Complete RPCs and
|
|
14
|
+
* request binding. Interrupt its Effect to request cancellation; no global cancel. */
|
|
15
|
+
export declare class PasskeyBrowser extends PasskeyBrowser_base {}
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=PasskeyBrowser.d.mts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "@yielded/auth/Passkey";
|
|
2
|
+
import { Context } from "effect";
|
|
3
|
+
//#region src/internal/browser/PasskeyBrowser.ts
|
|
4
|
+
/** Client-local ceremony capability. The caller owns Begin/Complete RPCs and
|
|
5
|
+
* request binding. Interrupt its Effect to request cancellation; no global cancel. */
|
|
6
|
+
var PasskeyBrowser = class extends Context.Service()("effect-auth/PasskeyBrowser") {};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { PasskeyBrowser };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=PasskeyBrowser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PasskeyBrowser.mjs","names":[],"sources":["../../../src/internal/browser/PasskeyBrowser.ts"],"sourcesContent":["import {\n type PasskeyAuthenticationStarted,\n type PasskeyRegistrationStarted,\n} from \"@yielded/auth/Passkey\";\nimport { Context, type Effect } from \"effect\";\n\nimport type {\n PasskeyBrowserAuthentication,\n PasskeyBrowserCapabilities,\n PasskeyBrowserFailure,\n PasskeyBrowserRegistration,\n PasskeyBrowserUnavailable,\n} from \"./models\";\n\n/** Client-local ceremony capability. The caller owns Begin/Complete RPCs and\n * request binding. Interrupt its Effect to request cancellation; no global cancel. */\nexport class PasskeyBrowser extends Context.Service<\n PasskeyBrowser,\n {\n readonly capabilities: Effect.Effect<PasskeyBrowserCapabilities, PasskeyBrowserUnavailable>;\n readonly register: (\n started: typeof PasskeyRegistrationStarted.Type,\n ) => Effect.Effect<PasskeyBrowserRegistration, PasskeyBrowserFailure>;\n readonly authenticate: (input: {\n readonly started: typeof PasskeyAuthenticationStarted.Type;\n readonly mediation: \"required\" | \"conditional\";\n }) => Effect.Effect<PasskeyBrowserAuthentication, PasskeyBrowserFailure>;\n }\n>()(\"effect-auth/PasskeyBrowser\") {}\n"],"mappings":";;;;;AAgBA,IAAa,iBAAb,cAAoC,QAAQ,QAY1C,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/internal/browser/models.d.ts
|
|
3
|
+
export declare const PasskeyBrowserCapability: Schema.Literals<readonly ["supported", "unsupported", "unknown"]>;
|
|
4
|
+
export type PasskeyBrowserCapability = typeof PasskeyBrowserCapability.Type;
|
|
5
|
+
export declare const PasskeyBrowserCapabilities: Schema.Struct<{
|
|
6
|
+
readonly secureContext: Schema.Boolean;
|
|
7
|
+
readonly webAuthn: Schema.Boolean;
|
|
8
|
+
readonly conditionalGet: Schema.Literals<readonly ["supported", "unsupported", "unknown"]>;
|
|
9
|
+
readonly userVerifyingPlatformAuthenticator: Schema.Literals<readonly ["supported", "unsupported", "unknown"]>;
|
|
10
|
+
readonly hybridTransport: Schema.Literals<readonly ["supported", "unsupported", "unknown"]>;
|
|
11
|
+
readonly passkeyPlatformAuthenticator: Schema.Literals<readonly ["supported", "unsupported", "unknown"]>;
|
|
12
|
+
}>;
|
|
13
|
+
export type PasskeyBrowserCapabilities = typeof PasskeyBrowserCapabilities.Type;
|
|
14
|
+
export declare const PasskeyBrowserRegistration: Schema.Struct<{
|
|
15
|
+
readonly flowId: Schema.brand<Schema.String, "effect-auth/RequestBindingFlowId">;
|
|
16
|
+
readonly response: Schema.RedactedFromValue<Schema.NonEmptyString>;
|
|
17
|
+
}>;
|
|
18
|
+
export type PasskeyBrowserRegistration = typeof PasskeyBrowserRegistration.Type;
|
|
19
|
+
export declare const PasskeyBrowserAuthentication: Schema.Struct<{
|
|
20
|
+
readonly flowId: Schema.brand<Schema.String, "effect-auth/RequestBindingFlowId">;
|
|
21
|
+
readonly response: Schema.RedactedFromValue<Schema.NonEmptyString>;
|
|
22
|
+
}>;
|
|
23
|
+
export type PasskeyBrowserAuthentication = typeof PasskeyBrowserAuthentication.Type;
|
|
24
|
+
declare const PasskeyBrowserInputRejected_base: Schema.Class<PasskeyBrowserInputRejected, Schema.TaggedStruct<"PasskeyBrowserInputRejected", {}>, import("effect/Cause").YieldableError>;
|
|
25
|
+
export declare class PasskeyBrowserInputRejected extends PasskeyBrowserInputRejected_base {}
|
|
26
|
+
declare const PasskeyBrowserUnsupported_base: Schema.Class<PasskeyBrowserUnsupported, Schema.TaggedStruct<"PasskeyBrowserUnsupported", {}>, import("effect/Cause").YieldableError>;
|
|
27
|
+
export declare class PasskeyBrowserUnsupported extends PasskeyBrowserUnsupported_base {}
|
|
28
|
+
declare const PasskeyBrowserBusy_base: Schema.Class<PasskeyBrowserBusy, Schema.TaggedStruct<"PasskeyBrowserBusy", {}>, import("effect/Cause").YieldableError>;
|
|
29
|
+
export declare class PasskeyBrowserBusy extends PasskeyBrowserBusy_base {}
|
|
30
|
+
declare const PasskeyBrowserNotCompleted_base: Schema.Class<PasskeyBrowserNotCompleted, Schema.TaggedStruct<"PasskeyBrowserNotCompleted", {}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
export declare class PasskeyBrowserNotCompleted extends PasskeyBrowserNotCompleted_base {}
|
|
32
|
+
declare const PasskeyBrowserUnavailable_base: Schema.Class<PasskeyBrowserUnavailable, Schema.TaggedStruct<"PasskeyBrowserUnavailable", {}>, import("effect/Cause").YieldableError>;
|
|
33
|
+
export declare class PasskeyBrowserUnavailable extends PasskeyBrowserUnavailable_base {}
|
|
34
|
+
export declare const PasskeyBrowserFailure: Schema.Union<readonly [typeof PasskeyBrowserInputRejected, typeof PasskeyBrowserUnsupported, typeof PasskeyBrowserBusy, typeof PasskeyBrowserNotCompleted, typeof PasskeyBrowserUnavailable]>;
|
|
35
|
+
export type PasskeyBrowserFailure = typeof PasskeyBrowserFailure.Type;
|
|
36
|
+
//#endregion
|
|
37
|
+
//# sourceMappingURL=models.d.mts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PasskeyAssertion, PasskeyAttestation } from "@yielded/auth/Passkey";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { RequestBindingFlowId } from "@yielded/auth/Operations";
|
|
4
|
+
//#region src/internal/browser/models.ts
|
|
5
|
+
const PasskeyBrowserCapability = Schema.Literals([
|
|
6
|
+
"supported",
|
|
7
|
+
"unsupported",
|
|
8
|
+
"unknown"
|
|
9
|
+
]);
|
|
10
|
+
const PasskeyBrowserCapabilities = Schema.Struct({
|
|
11
|
+
secureContext: Schema.Boolean,
|
|
12
|
+
webAuthn: Schema.Boolean,
|
|
13
|
+
conditionalGet: PasskeyBrowserCapability,
|
|
14
|
+
userVerifyingPlatformAuthenticator: PasskeyBrowserCapability,
|
|
15
|
+
hybridTransport: PasskeyBrowserCapability,
|
|
16
|
+
passkeyPlatformAuthenticator: PasskeyBrowserCapability
|
|
17
|
+
});
|
|
18
|
+
const PasskeyBrowserRegistration = Schema.Struct({
|
|
19
|
+
flowId: RequestBindingFlowId,
|
|
20
|
+
response: PasskeyAttestation
|
|
21
|
+
});
|
|
22
|
+
const PasskeyBrowserAuthentication = Schema.Struct({
|
|
23
|
+
flowId: RequestBindingFlowId,
|
|
24
|
+
response: PasskeyAssertion
|
|
25
|
+
});
|
|
26
|
+
var PasskeyBrowserInputRejected = class extends Schema.TaggedError()("PasskeyBrowserInputRejected", {}) {};
|
|
27
|
+
var PasskeyBrowserUnsupported = class extends Schema.TaggedError()("PasskeyBrowserUnsupported", {}) {};
|
|
28
|
+
var PasskeyBrowserBusy = class extends Schema.TaggedError()("PasskeyBrowserBusy", {}) {};
|
|
29
|
+
var PasskeyBrowserNotCompleted = class extends Schema.TaggedError()("PasskeyBrowserNotCompleted", {}) {};
|
|
30
|
+
var PasskeyBrowserUnavailable = class extends Schema.TaggedError()("PasskeyBrowserUnavailable", {}) {};
|
|
31
|
+
const PasskeyBrowserFailure = Schema.Union([
|
|
32
|
+
PasskeyBrowserInputRejected,
|
|
33
|
+
PasskeyBrowserUnsupported,
|
|
34
|
+
PasskeyBrowserBusy,
|
|
35
|
+
PasskeyBrowserNotCompleted,
|
|
36
|
+
PasskeyBrowserUnavailable
|
|
37
|
+
]);
|
|
38
|
+
//#endregion
|
|
39
|
+
export { PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserCapability, PasskeyBrowserFailure, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=models.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.mjs","names":[],"sources":["../../../src/internal/browser/models.ts"],"sourcesContent":["import { RequestBindingFlowId } from \"@yielded/auth/Operations\";\nimport { PasskeyAssertion, PasskeyAttestation } from \"@yielded/auth/Passkey\";\nimport { Schema } from \"effect\";\n\nexport const PasskeyBrowserCapability = Schema.Literals([\"supported\", \"unsupported\", \"unknown\"]);\nexport type PasskeyBrowserCapability = typeof PasskeyBrowserCapability.Type;\n\nexport const PasskeyBrowserCapabilities = Schema.Struct({\n secureContext: Schema.Boolean,\n webAuthn: Schema.Boolean,\n conditionalGet: PasskeyBrowserCapability,\n userVerifyingPlatformAuthenticator: PasskeyBrowserCapability,\n hybridTransport: PasskeyBrowserCapability,\n passkeyPlatformAuthenticator: PasskeyBrowserCapability,\n});\n\nexport type PasskeyBrowserCapabilities = typeof PasskeyBrowserCapabilities.Type;\n\nexport const PasskeyBrowserRegistration = Schema.Struct({\n flowId: RequestBindingFlowId,\n response: PasskeyAttestation,\n});\n\nexport type PasskeyBrowserRegistration = typeof PasskeyBrowserRegistration.Type;\n\nexport const PasskeyBrowserAuthentication = Schema.Struct({\n flowId: RequestBindingFlowId,\n response: PasskeyAssertion,\n});\n\nexport type PasskeyBrowserAuthentication = typeof PasskeyBrowserAuthentication.Type;\n\nexport class PasskeyBrowserInputRejected extends Schema.TaggedError<PasskeyBrowserInputRejected>()(\n \"PasskeyBrowserInputRejected\",\n {},\n) {}\n\nexport class PasskeyBrowserUnsupported extends Schema.TaggedError<PasskeyBrowserUnsupported>()(\n \"PasskeyBrowserUnsupported\",\n {},\n) {}\n\nexport class PasskeyBrowserBusy extends Schema.TaggedError<PasskeyBrowserBusy>()(\n \"PasskeyBrowserBusy\",\n {},\n) {}\n\nexport class PasskeyBrowserNotCompleted extends Schema.TaggedError<PasskeyBrowserNotCompleted>()(\n \"PasskeyBrowserNotCompleted\",\n {},\n) {}\n\nexport class PasskeyBrowserUnavailable extends Schema.TaggedError<PasskeyBrowserUnavailable>()(\n \"PasskeyBrowserUnavailable\",\n {},\n) {}\n\nexport const PasskeyBrowserFailure = Schema.Union([\n PasskeyBrowserInputRejected,\n PasskeyBrowserUnsupported,\n PasskeyBrowserBusy,\n PasskeyBrowserNotCompleted,\n PasskeyBrowserUnavailable,\n]);\n\nexport type PasskeyBrowserFailure = typeof PasskeyBrowserFailure.Type;\n"],"mappings":";;;;AAIA,MAAa,2BAA2B,OAAO,SAAS;CAAC;CAAa;CAAe;AAAS,CAAC;AAG/F,MAAa,6BAA6B,OAAO,OAAO;CACtD,eAAe,OAAO;CACtB,UAAU,OAAO;CACjB,gBAAgB;CAChB,oCAAoC;CACpC,iBAAiB;CACjB,8BAA8B;AAChC,CAAC;AAID,MAAa,6BAA6B,OAAO,OAAO;CACtD,QAAQ;CACR,UAAU;AACZ,CAAC;AAID,MAAa,+BAA+B,OAAO,OAAO;CACxD,QAAQ;CACR,UAAU;AACZ,CAAC;AAID,IAAa,8BAAb,cAAiD,OAAO,YAAyC,CAAC,CAChG,+BACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,IAAa,4BAAb,cAA+C,OAAO,YAAuC,CAAC,CAC5F,6BACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,IAAa,qBAAb,cAAwC,OAAO,YAAgC,CAAC,CAC9E,sBACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,IAAa,4BAAb,cAA+C,OAAO,YAAuC,CAAC,CAC5F,6BACA,CAAC,CACH,CAAC,CAAC,CAAC;AAEH,MAAa,wBAAwB,OAAO,MAAM;CAChD;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PasskeyBrowserAuthentication, PasskeyBrowserCapabilities, PasskeyBrowserFailure, PasskeyBrowserRegistration, PasskeyBrowserUnavailable } from "./models.mjs";
|
|
2
|
+
import { PasskeyBrowser } from "./PasskeyBrowser.mjs";
|
|
3
|
+
import { PasskeyAuthenticationStarted, PasskeyRegistrationStarted } from "@yielded/auth/Passkey";
|
|
4
|
+
import { Effect, Layer } from "effect";
|
|
5
|
+
//#region src/internal/browser/simplewebauthn.d.ts
|
|
6
|
+
export declare const makeSimpleWebAuthnPasskeyBrowser: () => Effect.Effect<{
|
|
7
|
+
readonly capabilities: Effect.Effect<PasskeyBrowserCapabilities, PasskeyBrowserUnavailable>;
|
|
8
|
+
readonly register: (started: typeof PasskeyRegistrationStarted.Type) => Effect.Effect<PasskeyBrowserRegistration, PasskeyBrowserFailure>;
|
|
9
|
+
readonly authenticate: (input: {
|
|
10
|
+
readonly started: typeof PasskeyAuthenticationStarted.Type;
|
|
11
|
+
readonly mediation: "required" | "conditional";
|
|
12
|
+
}) => Effect.Effect<PasskeyBrowserAuthentication, PasskeyBrowserFailure>;
|
|
13
|
+
}, never, never>;
|
|
14
|
+
export declare const layerSimpleWebAuthnPasskeyBrowser: Layer.Layer<PasskeyBrowser>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=simplewebauthn.d.mts.map
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { PasskeyBrowser } from "./PasskeyBrowser.mjs";
|
|
2
|
+
import { PasskeyBrowserAuthentication, PasskeyBrowserBusy, PasskeyBrowserCapabilities, PasskeyBrowserInputRejected, PasskeyBrowserNotCompleted, PasskeyBrowserRegistration, PasskeyBrowserUnavailable, PasskeyBrowserUnsupported } from "./models.mjs";
|
|
3
|
+
import { PasskeyAuthenticationStarted, PasskeyProtocolCredentialId, PasskeyRegistrationStarted, snapshotPasskey } from "@yielded/auth/Passkey";
|
|
4
|
+
import { DateTime, Effect, Layer, Predicate, Redacted, Schema } from "effect";
|
|
5
|
+
import { base64URLStringToBuffer, browserSupportsWebAuthn, browserSupportsWebAuthnAutofill, bufferToBase64URLString, platformAuthenticatorIsAvailable } from "@simplewebauthn/browser";
|
|
6
|
+
//#region src/internal/browser/simplewebauthn.ts
|
|
7
|
+
const unavailable = () => PasskeyBrowserUnavailable.make({});
|
|
8
|
+
const rejected = () => PasskeyBrowserInputRejected.make({});
|
|
9
|
+
const incomplete = () => PasskeyBrowserNotCompleted.make({});
|
|
10
|
+
const unexpected = (effect) => effect.pipe(Effect.catchDefect(() => Effect.fail(unavailable())));
|
|
11
|
+
const decode = (schema, value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(unavailable));
|
|
12
|
+
const capture = (schema, value) => snapshotPasskey(schema, value).pipe(Effect.mapError(rejected));
|
|
13
|
+
const maintained = (call) => Effect.tryPromise({
|
|
14
|
+
try: call,
|
|
15
|
+
catch: unavailable
|
|
16
|
+
});
|
|
17
|
+
const timeout = Schema.Int.check(Schema.isBetween({
|
|
18
|
+
minimum: 1,
|
|
19
|
+
maximum: 3e5
|
|
20
|
+
}));
|
|
21
|
+
const registrationInput = Schema.Struct({
|
|
22
|
+
...PasskeyRegistrationStarted.fields,
|
|
23
|
+
options: Schema.Struct({
|
|
24
|
+
...PasskeyRegistrationStarted.fields.options.fields,
|
|
25
|
+
timeout
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
const authenticationInput = Schema.Struct({
|
|
29
|
+
started: Schema.Struct({
|
|
30
|
+
...PasskeyAuthenticationStarted.fields,
|
|
31
|
+
options: Schema.Struct({
|
|
32
|
+
...PasskeyAuthenticationStarted.fields.options.fields,
|
|
33
|
+
timeout
|
|
34
|
+
})
|
|
35
|
+
}),
|
|
36
|
+
mediation: Schema.Literals(["required", "conditional"])
|
|
37
|
+
});
|
|
38
|
+
const nativeCapabilities = Schema.Struct({
|
|
39
|
+
conditionalGet: Schema.UndefinedOr(Schema.Boolean),
|
|
40
|
+
userVerifyingPlatformAuthenticator: Schema.UndefinedOr(Schema.Boolean),
|
|
41
|
+
hybridTransport: Schema.UndefinedOr(Schema.Boolean),
|
|
42
|
+
passkeyPlatformAuthenticator: Schema.UndefinedOr(Schema.Boolean)
|
|
43
|
+
});
|
|
44
|
+
const support = (value) => value === void 0 ? "unknown" : value ? "supported" : "unsupported";
|
|
45
|
+
const readCapabilities = Effect.gen(function* () {
|
|
46
|
+
if (typeof globalThis.PublicKeyCredential.getClientCapabilities !== "function") return {
|
|
47
|
+
conditionalGet: void 0,
|
|
48
|
+
userVerifyingPlatformAuthenticator: void 0,
|
|
49
|
+
hybridTransport: void 0,
|
|
50
|
+
passkeyPlatformAuthenticator: void 0
|
|
51
|
+
};
|
|
52
|
+
const raw = yield* maintained(() => globalThis.PublicKeyCredential.getClientCapabilities());
|
|
53
|
+
const fields = yield* Effect.try({
|
|
54
|
+
try: () => {
|
|
55
|
+
if (!Predicate.isObject(raw)) throw unavailable();
|
|
56
|
+
return {
|
|
57
|
+
conditionalGet: raw.conditionalGet,
|
|
58
|
+
userVerifyingPlatformAuthenticator: raw.userVerifyingPlatformAuthenticator,
|
|
59
|
+
hybridTransport: raw.hybridTransport,
|
|
60
|
+
passkeyPlatformAuthenticator: raw.passkeyPlatformAuthenticator
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
catch: unavailable
|
|
64
|
+
});
|
|
65
|
+
return yield* decode(nativeCapabilities, fields);
|
|
66
|
+
});
|
|
67
|
+
const booleanCapability = Effect.fn("passkeyBrowserBooleanCapability")(function* (call) {
|
|
68
|
+
return (yield* decode(Schema.Boolean, yield* maintained(call))) ? "supported" : "unsupported";
|
|
69
|
+
});
|
|
70
|
+
const environment = Effect.try({
|
|
71
|
+
try: () => {
|
|
72
|
+
const secureContext = globalThis.isSecureContext === true;
|
|
73
|
+
const container = globalThis.navigator?.credentials;
|
|
74
|
+
return {
|
|
75
|
+
secureContext,
|
|
76
|
+
webAuthn: secureContext && browserSupportsWebAuthn() && container !== void 0 && typeof container.get === "function" && typeof container.create === "function" && typeof globalThis.AbortController === "function",
|
|
77
|
+
container
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
catch: unavailable
|
|
81
|
+
});
|
|
82
|
+
const capabilities = Effect.gen(function* () {
|
|
83
|
+
const env = yield* environment;
|
|
84
|
+
if (!env.webAuthn) return yield* snapshotPasskey(PasskeyBrowserCapabilities, {
|
|
85
|
+
secureContext: env.secureContext,
|
|
86
|
+
webAuthn: false,
|
|
87
|
+
conditionalGet: "unsupported",
|
|
88
|
+
userVerifyingPlatformAuthenticator: "unsupported",
|
|
89
|
+
hybridTransport: "unsupported",
|
|
90
|
+
passkeyPlatformAuthenticator: "unsupported"
|
|
91
|
+
}).pipe(Effect.mapError(unavailable));
|
|
92
|
+
const raw = yield* readCapabilities;
|
|
93
|
+
const values = {
|
|
94
|
+
conditionalGet: support(raw.conditionalGet),
|
|
95
|
+
userVerifyingPlatformAuthenticator: support(raw.userVerifyingPlatformAuthenticator),
|
|
96
|
+
hybridTransport: support(raw.hybridTransport),
|
|
97
|
+
passkeyPlatformAuthenticator: support(raw.passkeyPlatformAuthenticator)
|
|
98
|
+
};
|
|
99
|
+
const conditionalGet = values.conditionalGet === "unknown" ? typeof globalThis.PublicKeyCredential.isConditionalMediationAvailable === "function" ? yield* booleanCapability(browserSupportsWebAuthnAutofill) : "unsupported" : values.conditionalGet;
|
|
100
|
+
const platform = values.userVerifyingPlatformAuthenticator === "unknown" && typeof globalThis.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable === "function" ? yield* booleanCapability(platformAuthenticatorIsAvailable) : values.userVerifyingPlatformAuthenticator;
|
|
101
|
+
return yield* snapshotPasskey(PasskeyBrowserCapabilities, {
|
|
102
|
+
secureContext: env.secureContext,
|
|
103
|
+
webAuthn: true,
|
|
104
|
+
...values,
|
|
105
|
+
conditionalGet,
|
|
106
|
+
userVerifyingPlatformAuthenticator: platform
|
|
107
|
+
}).pipe(Effect.mapError(unavailable));
|
|
108
|
+
}).pipe(Effect.timeoutOrElse({
|
|
109
|
+
duration: 5e3,
|
|
110
|
+
orElse: () => Effect.fail(unavailable())
|
|
111
|
+
}), unexpected);
|
|
112
|
+
const leases = /* @__PURE__ */ new WeakMap();
|
|
113
|
+
const settle = (lease) => {
|
|
114
|
+
lease.phase = "settled";
|
|
115
|
+
if (leases.get(lease.container) === lease) leases.delete(lease.container);
|
|
116
|
+
};
|
|
117
|
+
const acquire = Effect.gen(function* () {
|
|
118
|
+
const env = yield* environment;
|
|
119
|
+
if (!env.webAuthn || env.container === void 0) return yield* PasskeyBrowserUnsupported.make({});
|
|
120
|
+
if (leases.has(env.container)) return yield* PasskeyBrowserBusy.make({});
|
|
121
|
+
const lease = {
|
|
122
|
+
container: env.container,
|
|
123
|
+
controller: new AbortController(),
|
|
124
|
+
phase: "pre-native"
|
|
125
|
+
};
|
|
126
|
+
leases.set(env.container, lease);
|
|
127
|
+
return lease;
|
|
128
|
+
});
|
|
129
|
+
const release = (lease) => Effect.sync(() => {
|
|
130
|
+
if (lease.phase === "settled") return;
|
|
131
|
+
try {
|
|
132
|
+
lease.controller.abort();
|
|
133
|
+
} catch {}
|
|
134
|
+
if (lease.phase === "pre-native") settle(lease);
|
|
135
|
+
});
|
|
136
|
+
const nativeFailure = (value) => {
|
|
137
|
+
try {
|
|
138
|
+
if (!Predicate.isObject(value)) return unavailable();
|
|
139
|
+
const parsed = Schema.decodeUnknownOption(Schema.String)(value.name);
|
|
140
|
+
if (parsed._tag === "Some" && [
|
|
141
|
+
"NotAllowedError",
|
|
142
|
+
"InvalidStateError",
|
|
143
|
+
"ConstraintError",
|
|
144
|
+
"NotSupportedError",
|
|
145
|
+
"SecurityError",
|
|
146
|
+
"AbortError"
|
|
147
|
+
].includes(parsed.value)) return incomplete();
|
|
148
|
+
} catch {}
|
|
149
|
+
return unavailable();
|
|
150
|
+
};
|
|
151
|
+
const native = (lease, request) => Effect.callback((resume, signal) => {
|
|
152
|
+
if (signal.aborted || lease.controller.signal.aborted || lease.phase !== "pre-native" || leases.get(lease.container) !== lease) {
|
|
153
|
+
resume(Effect.fail(incomplete()));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
lease.phase = "native";
|
|
157
|
+
try {
|
|
158
|
+
const promise = request._tag === "Create" ? lease.container.create({
|
|
159
|
+
publicKey: request.publicKey,
|
|
160
|
+
signal: lease.controller.signal
|
|
161
|
+
}) : lease.container.get({
|
|
162
|
+
publicKey: request.publicKey,
|
|
163
|
+
mediation: request.mediation,
|
|
164
|
+
signal: lease.controller.signal
|
|
165
|
+
});
|
|
166
|
+
Promise.resolve(promise).then((value) => {
|
|
167
|
+
try {
|
|
168
|
+
settle(lease);
|
|
169
|
+
if (!signal.aborted && !lease.controller.signal.aborted) resume(Effect.succeed(value));
|
|
170
|
+
} catch {}
|
|
171
|
+
}, (error) => {
|
|
172
|
+
try {
|
|
173
|
+
settle(lease);
|
|
174
|
+
if (!signal.aborted && !lease.controller.signal.aborted) resume(Effect.fail(nativeFailure(error)));
|
|
175
|
+
} catch {}
|
|
176
|
+
});
|
|
177
|
+
} catch (error) {
|
|
178
|
+
settle(lease);
|
|
179
|
+
resume(Effect.fail(nativeFailure(error)));
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const remaining = Effect.fn("passkeyBrowserRemaining")(function* (deadline) {
|
|
183
|
+
const duration = deadline - DateTime.toEpochMillis(yield* DateTime.now);
|
|
184
|
+
if (duration <= 0) return yield* incomplete();
|
|
185
|
+
return Math.max(1, Math.floor(duration));
|
|
186
|
+
});
|
|
187
|
+
const runCeremony = Effect.fn("passkeyBrowserRunCeremony")(function* (started, use) {
|
|
188
|
+
const now = DateTime.toEpochMillis(yield* DateTime.now);
|
|
189
|
+
if (started.expiresAtMillis <= now) return yield* rejected();
|
|
190
|
+
const deadline = Math.min(started.expiresAtMillis, now + started.options.timeout);
|
|
191
|
+
return yield* Effect.acquireUseRelease(acquire, (lease) => Effect.gen(function* () {
|
|
192
|
+
const duration = yield* remaining(deadline);
|
|
193
|
+
return yield* use(lease, deadline).pipe(Effect.timeoutOrElse({
|
|
194
|
+
duration,
|
|
195
|
+
orElse: () => Effect.fail(incomplete())
|
|
196
|
+
}));
|
|
197
|
+
}), release);
|
|
198
|
+
});
|
|
199
|
+
const nativeEnvelope = {
|
|
200
|
+
id: PasskeyProtocolCredentialId,
|
|
201
|
+
rawId: Schema.instanceOf(ArrayBuffer),
|
|
202
|
+
type: Schema.Literal("public-key")
|
|
203
|
+
};
|
|
204
|
+
const nativeRegistration = Schema.Struct({
|
|
205
|
+
...nativeEnvelope,
|
|
206
|
+
response: Schema.Struct({
|
|
207
|
+
attestationObject: Schema.instanceOf(ArrayBuffer),
|
|
208
|
+
clientDataJSON: Schema.instanceOf(ArrayBuffer)
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
const nativeAuthentication = Schema.Struct({
|
|
212
|
+
...nativeEnvelope,
|
|
213
|
+
response: Schema.Struct({
|
|
214
|
+
authenticatorData: Schema.instanceOf(ArrayBuffer),
|
|
215
|
+
clientDataJSON: Schema.instanceOf(ArrayBuffer),
|
|
216
|
+
signature: Schema.instanceOf(ArrayBuffer),
|
|
217
|
+
userHandle: Schema.optionalKey(Schema.NullOr(Schema.instanceOf(ArrayBuffer)))
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
const buffer = Effect.fn("passkeyBrowserBuffer")(function* (value, minimum, maximum) {
|
|
221
|
+
const copied = yield* Effect.try({
|
|
222
|
+
try: () => ArrayBuffer.prototype.slice.call(value, 0, maximum + 1),
|
|
223
|
+
catch: unavailable
|
|
224
|
+
});
|
|
225
|
+
if (copied.byteLength < minimum || copied.byteLength > maximum) return yield* unavailable();
|
|
226
|
+
return yield* Effect.try({
|
|
227
|
+
try: () => bufferToBase64URLString(copied),
|
|
228
|
+
catch: unavailable
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
const registrationWire = Schema.fromJsonString(Schema.Struct({
|
|
232
|
+
id: Schema.String,
|
|
233
|
+
rawId: Schema.String,
|
|
234
|
+
type: Schema.Literal("public-key"),
|
|
235
|
+
response: Schema.Struct({
|
|
236
|
+
attestationObject: Schema.String,
|
|
237
|
+
clientDataJSON: Schema.String
|
|
238
|
+
}),
|
|
239
|
+
clientExtensionResults: Schema.Struct({})
|
|
240
|
+
}));
|
|
241
|
+
const authenticationWire = Schema.fromJsonString(Schema.Struct({
|
|
242
|
+
id: Schema.String,
|
|
243
|
+
rawId: Schema.String,
|
|
244
|
+
type: Schema.Literal("public-key"),
|
|
245
|
+
response: Schema.Struct({
|
|
246
|
+
authenticatorData: Schema.String,
|
|
247
|
+
clientDataJSON: Schema.String,
|
|
248
|
+
signature: Schema.String,
|
|
249
|
+
userHandle: Schema.optionalKey(Schema.String)
|
|
250
|
+
}),
|
|
251
|
+
clientExtensionResults: Schema.Struct({})
|
|
252
|
+
}));
|
|
253
|
+
const registrationResponse = Effect.fn("passkeyBrowserRegistrationResponse")(function* (value) {
|
|
254
|
+
if (value === null) return yield* incomplete();
|
|
255
|
+
const fields = yield* Effect.try({
|
|
256
|
+
try: () => {
|
|
257
|
+
if (!Predicate.isObject(value)) throw unavailable();
|
|
258
|
+
const response = value.response;
|
|
259
|
+
if (!Predicate.isObject(response)) throw unavailable();
|
|
260
|
+
return {
|
|
261
|
+
id: value.id,
|
|
262
|
+
rawId: value.rawId,
|
|
263
|
+
type: value.type,
|
|
264
|
+
response: {
|
|
265
|
+
attestationObject: response.attestationObject,
|
|
266
|
+
clientDataJSON: response.clientDataJSON
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
catch: unavailable
|
|
271
|
+
});
|
|
272
|
+
const credential = yield* decode(nativeRegistration, fields);
|
|
273
|
+
const rawId = yield* buffer(credential.rawId, 1, 1023);
|
|
274
|
+
if (credential.id !== rawId) return yield* unavailable();
|
|
275
|
+
return yield* Schema.encodeEffect(registrationWire)({
|
|
276
|
+
id: credential.id,
|
|
277
|
+
rawId,
|
|
278
|
+
type: "public-key",
|
|
279
|
+
response: {
|
|
280
|
+
attestationObject: yield* buffer(credential.response.attestationObject, 1, 65536),
|
|
281
|
+
clientDataJSON: yield* buffer(credential.response.clientDataJSON, 1, 8192)
|
|
282
|
+
},
|
|
283
|
+
clientExtensionResults: {}
|
|
284
|
+
}).pipe(Effect.mapError(unavailable));
|
|
285
|
+
});
|
|
286
|
+
const authenticationResponse = Effect.fn("passkeyBrowserAuthenticationResponse")(function* (value) {
|
|
287
|
+
if (value === null) return yield* incomplete();
|
|
288
|
+
const fields = yield* Effect.try({
|
|
289
|
+
try: () => {
|
|
290
|
+
if (!Predicate.isObject(value)) throw unavailable();
|
|
291
|
+
const response = value.response;
|
|
292
|
+
if (!Predicate.isObject(response)) throw unavailable();
|
|
293
|
+
const userHandle = response.userHandle;
|
|
294
|
+
return {
|
|
295
|
+
id: value.id,
|
|
296
|
+
rawId: value.rawId,
|
|
297
|
+
type: value.type,
|
|
298
|
+
response: {
|
|
299
|
+
authenticatorData: response.authenticatorData,
|
|
300
|
+
clientDataJSON: response.clientDataJSON,
|
|
301
|
+
signature: response.signature,
|
|
302
|
+
...userHandle === void 0 ? {} : { userHandle }
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
catch: unavailable
|
|
307
|
+
});
|
|
308
|
+
const credential = yield* decode(nativeAuthentication, fields);
|
|
309
|
+
const rawId = yield* buffer(credential.rawId, 1, 1023);
|
|
310
|
+
if (credential.id !== rawId) return yield* unavailable();
|
|
311
|
+
const handle = credential.response.userHandle;
|
|
312
|
+
return yield* Schema.encodeEffect(authenticationWire)({
|
|
313
|
+
id: credential.id,
|
|
314
|
+
rawId,
|
|
315
|
+
type: "public-key",
|
|
316
|
+
response: {
|
|
317
|
+
authenticatorData: yield* buffer(credential.response.authenticatorData, 37, 16384),
|
|
318
|
+
clientDataJSON: yield* buffer(credential.response.clientDataJSON, 1, 8192),
|
|
319
|
+
signature: yield* buffer(credential.response.signature, 1, 1024),
|
|
320
|
+
...handle === null || handle === void 0 ? {} : { userHandle: yield* buffer(handle, 1, 64) }
|
|
321
|
+
},
|
|
322
|
+
clientExtensionResults: {}
|
|
323
|
+
}).pipe(Effect.mapError(unavailable));
|
|
324
|
+
});
|
|
325
|
+
const conditional = Effect.gen(function* () {
|
|
326
|
+
if (typeof globalThis.PublicKeyCredential.isConditionalMediationAvailable !== "function") return yield* PasskeyBrowserUnsupported.make({});
|
|
327
|
+
if ((yield* booleanCapability(browserSupportsWebAuthnAutofill)) !== "supported") return yield* PasskeyBrowserUnsupported.make({});
|
|
328
|
+
if (!(yield* Effect.try({
|
|
329
|
+
try: () => Array.from(globalThis.document.querySelectorAll("input[autocomplete]")).some((input) => input.getAttribute("autocomplete")?.split(/[\t\n\f\r ]+/).filter((token) => token.length > 0).at(-1)?.toLowerCase() === "webauthn"),
|
|
330
|
+
catch: unavailable
|
|
331
|
+
}))) return yield* rejected();
|
|
332
|
+
}).pipe(Effect.timeoutOrElse({
|
|
333
|
+
duration: 5e3,
|
|
334
|
+
orElse: () => Effect.fail(unavailable())
|
|
335
|
+
}));
|
|
336
|
+
const makeSimpleWebAuthnPasskeyBrowser = Effect.fn("makeSimpleWebAuthnPasskeyBrowser")(() => Effect.sync(() => {
|
|
337
|
+
const register = Effect.fn("PasskeyBrowser.register")(function* (input) {
|
|
338
|
+
const started = yield* capture(registrationInput, input);
|
|
339
|
+
return yield* runCeremony(started, (lease, deadline) => Effect.gen(function* () {
|
|
340
|
+
const timeoutMillis = yield* remaining(deadline);
|
|
341
|
+
const options = started.options;
|
|
342
|
+
const publicKey = {
|
|
343
|
+
challenge: base64URLStringToBuffer(options.challenge),
|
|
344
|
+
rp: { ...options.rp },
|
|
345
|
+
user: {
|
|
346
|
+
...options.user,
|
|
347
|
+
id: base64URLStringToBuffer(options.user.id)
|
|
348
|
+
},
|
|
349
|
+
pubKeyCredParams: options.pubKeyCredParams.map((value) => ({ ...value })),
|
|
350
|
+
timeout: timeoutMillis,
|
|
351
|
+
attestation: options.attestation,
|
|
352
|
+
authenticatorSelection: { ...options.authenticatorSelection },
|
|
353
|
+
excludeCredentials: options.excludeCredentials.map((value) => ({
|
|
354
|
+
type: value.type,
|
|
355
|
+
id: base64URLStringToBuffer(value.id)
|
|
356
|
+
}))
|
|
357
|
+
};
|
|
358
|
+
yield* remaining(deadline);
|
|
359
|
+
const response = yield* registrationResponse(yield* native(lease, {
|
|
360
|
+
_tag: "Create",
|
|
361
|
+
publicKey
|
|
362
|
+
}));
|
|
363
|
+
yield* remaining(deadline);
|
|
364
|
+
return yield* snapshotPasskey(PasskeyBrowserRegistration, {
|
|
365
|
+
flowId: started.flowId,
|
|
366
|
+
response: Redacted.make(response)
|
|
367
|
+
}).pipe(Effect.mapError(unavailable));
|
|
368
|
+
}));
|
|
369
|
+
}, unexpected);
|
|
370
|
+
const authenticate = Effect.fn("PasskeyBrowser.authenticate")(function* (input) {
|
|
371
|
+
const { started, mediation } = yield* capture(authenticationInput, input);
|
|
372
|
+
if (mediation === "conditional" && started.options.allowCredentials.length !== 0) return yield* rejected();
|
|
373
|
+
return yield* runCeremony(started, (lease, deadline) => Effect.gen(function* () {
|
|
374
|
+
if (mediation === "conditional") yield* conditional;
|
|
375
|
+
const timeoutMillis = yield* remaining(deadline);
|
|
376
|
+
const options = started.options;
|
|
377
|
+
const publicKey = {
|
|
378
|
+
challenge: base64URLStringToBuffer(options.challenge),
|
|
379
|
+
rpId: options.rpId,
|
|
380
|
+
userVerification: options.userVerification,
|
|
381
|
+
timeout: timeoutMillis,
|
|
382
|
+
allowCredentials: options.allowCredentials.map((value) => ({
|
|
383
|
+
type: value.type,
|
|
384
|
+
id: base64URLStringToBuffer(value.id)
|
|
385
|
+
}))
|
|
386
|
+
};
|
|
387
|
+
yield* remaining(deadline);
|
|
388
|
+
const response = yield* authenticationResponse(yield* native(lease, {
|
|
389
|
+
_tag: "Get",
|
|
390
|
+
publicKey,
|
|
391
|
+
mediation
|
|
392
|
+
}));
|
|
393
|
+
yield* remaining(deadline);
|
|
394
|
+
return yield* snapshotPasskey(PasskeyBrowserAuthentication, {
|
|
395
|
+
flowId: started.flowId,
|
|
396
|
+
response: Redacted.make(response)
|
|
397
|
+
}).pipe(Effect.mapError(unavailable));
|
|
398
|
+
}));
|
|
399
|
+
}, unexpected);
|
|
400
|
+
return PasskeyBrowser.of({
|
|
401
|
+
capabilities,
|
|
402
|
+
register,
|
|
403
|
+
authenticate
|
|
404
|
+
});
|
|
405
|
+
}));
|
|
406
|
+
const layerSimpleWebAuthnPasskeyBrowser = Layer.effect(PasskeyBrowser, makeSimpleWebAuthnPasskeyBrowser());
|
|
407
|
+
//#endregion
|
|
408
|
+
export { layerSimpleWebAuthnPasskeyBrowser, makeSimpleWebAuthnPasskeyBrowser };
|
|
409
|
+
|
|
410
|
+
//# sourceMappingURL=simplewebauthn.mjs.map
|