@passlock/client 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/README.template.md +2 -2
  3. package/dist/errors.d.ts +4 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +14 -0
  6. package/dist/errors.js.map +1 -0
  7. package/dist/index.d.ts +236 -31
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +236 -34
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/index.d.ts +4 -0
  12. package/dist/internal/index.d.ts.map +1 -0
  13. package/dist/internal/index.js +4 -0
  14. package/dist/internal/index.js.map +1 -0
  15. package/dist/{shared → internal}/network.d.ts +19 -16
  16. package/dist/internal/network.d.ts.map +1 -0
  17. package/dist/{shared → internal}/network.js +40 -25
  18. package/dist/internal/network.js.map +1 -0
  19. package/dist/{shared → internal}/promise.d.ts +2 -2
  20. package/dist/internal/promise.d.ts.map +1 -0
  21. package/dist/{shared → internal}/promise.js +2 -2
  22. package/dist/internal/promise.js.map +1 -0
  23. package/dist/internal/tenancy.d.ts.map +1 -0
  24. package/dist/internal/tenancy.js.map +1 -0
  25. package/dist/{logger/index.d.ts → logger.d.ts} +19 -4
  26. package/dist/logger.d.ts.map +1 -0
  27. package/dist/{logger/index.js → logger.js} +19 -4
  28. package/dist/logger.js.map +1 -0
  29. package/dist/{shared/options.d.ts → options.d.ts} +4 -0
  30. package/dist/options.d.ts.map +1 -0
  31. package/dist/{shared/options.js.map → options.js.map} +1 -1
  32. package/dist/passkey/authentication/authentication.d.ts +134 -0
  33. package/dist/passkey/authentication/authentication.d.ts.map +1 -0
  34. package/dist/passkey/{authentication.js → authentication/authentication.js} +68 -50
  35. package/dist/passkey/authentication/authentication.js.map +1 -0
  36. package/dist/passkey/errors.d.ts +158 -16
  37. package/dist/passkey/errors.d.ts.map +1 -1
  38. package/dist/passkey/errors.js +214 -6
  39. package/dist/passkey/errors.js.map +1 -1
  40. package/dist/passkey/registration/registration.d.ts +145 -0
  41. package/dist/passkey/registration/registration.d.ts.map +1 -0
  42. package/dist/passkey/{registration.js → registration/registration.js} +43 -36
  43. package/dist/passkey/registration/registration.js.map +1 -0
  44. package/dist/passkey/shared.d.ts +8 -2
  45. package/dist/passkey/shared.d.ts.map +1 -1
  46. package/dist/passkey/signals/signals.d.ts +103 -0
  47. package/dist/passkey/signals/signals.d.ts.map +1 -0
  48. package/dist/passkey/{signals.js → signals/signals.js} +69 -71
  49. package/dist/passkey/signals/signals.js.map +1 -0
  50. package/dist/passkey/support.d.ts +15 -0
  51. package/dist/passkey/support.d.ts.map +1 -1
  52. package/dist/passkey/support.js +16 -1
  53. package/dist/passkey/support.js.map +1 -1
  54. package/dist/principal.d.ts +16 -0
  55. package/dist/principal.d.ts.map +1 -0
  56. package/dist/principal.js +2 -0
  57. package/dist/principal.js.map +1 -0
  58. package/dist/safe.d.ts +247 -0
  59. package/dist/safe.d.ts.map +1 -0
  60. package/dist/safe.js +254 -0
  61. package/dist/safe.js.map +1 -0
  62. package/package.json +21 -19
  63. package/dist/logger/index.d.ts.map +0 -1
  64. package/dist/logger/index.js.map +0 -1
  65. package/dist/passkey/authentication.d.ts +0 -118
  66. package/dist/passkey/authentication.d.ts.map +0 -1
  67. package/dist/passkey/authentication.js.map +0 -1
  68. package/dist/passkey/authentication.test.d.ts +0 -2
  69. package/dist/passkey/authentication.test.d.ts.map +0 -1
  70. package/dist/passkey/authentication.test.js +0 -157
  71. package/dist/passkey/authentication.test.js.map +0 -1
  72. package/dist/passkey/registration.d.ts +0 -136
  73. package/dist/passkey/registration.d.ts.map +0 -1
  74. package/dist/passkey/registration.js.map +0 -1
  75. package/dist/passkey/registration.test.d.ts +0 -2
  76. package/dist/passkey/registration.test.d.ts.map +0 -1
  77. package/dist/passkey/registration.test.js +0 -161
  78. package/dist/passkey/registration.test.js.map +0 -1
  79. package/dist/passkey/signals.d.ts +0 -113
  80. package/dist/passkey/signals.d.ts.map +0 -1
  81. package/dist/passkey/signals.js.map +0 -1
  82. package/dist/shared/network.d.ts.map +0 -1
  83. package/dist/shared/network.js.map +0 -1
  84. package/dist/shared/options.d.ts.map +0 -1
  85. package/dist/shared/promise.d.ts.map +0 -1
  86. package/dist/shared/promise.js.map +0 -1
  87. package/dist/shared/tenancy.d.ts.map +0 -1
  88. package/dist/shared/tenancy.js.map +0 -1
  89. package/dist/surface.test.d.ts +0 -2
  90. package/dist/surface.test.d.ts.map +0 -1
  91. package/dist/surface.test.js +0 -38
  92. package/dist/surface.test.js.map +0 -1
  93. package/dist/unsafe.d.ts +0 -41
  94. package/dist/unsafe.d.ts.map +0 -1
  95. package/dist/unsafe.js +0 -52
  96. package/dist/unsafe.js.map +0 -1
  97. /package/dist/{shared → internal}/tenancy.d.ts +0 -0
  98. /package/dist/{shared → internal}/tenancy.js +0 -0
  99. /package/dist/{shared/options.js → options.js} +0 -0
@@ -1,7 +1,14 @@
1
1
  import { Context, Micro } from "effect";
2
- export class Logger extends Context.Tag("Logger")() {
2
+ /**
3
+ * Allows us to plug in specific implementations.
4
+ * @see consoleLogger and eventLogger
5
+ */
6
+ export class Logger extends Context.Tag("ClientLogger")() {
3
7
  }
4
- export const ConsoleLogger = {
8
+ /**
9
+ * Logs to the JS console
10
+ */
11
+ export const consoleLogger = {
5
12
  logDebug: (message, ...optionalArgs) => Micro.sync(() => {
6
13
  console.debug(message, optionalArgs);
7
14
  }),
@@ -22,6 +29,9 @@ export var LogLevel;
22
29
  LogLevel["ERROR"] = "ERROR";
23
30
  LogLevel["WARN"] = "WARN";
24
31
  })(LogLevel || (LogLevel = {}));
32
+ /**
33
+ * Custom event representing a log message
34
+ */
25
35
  export class LogEvent extends Event {
26
36
  #message;
27
37
  #level;
@@ -43,10 +53,15 @@ const logEvent = (level) => (message) => Micro.sync(() => {
43
53
  window.dispatchEvent(new LogEvent(message, level));
44
54
  }
45
55
  });
46
- export const EventLogger = {
56
+ /**
57
+ * Fires JS events instead of writing to the console.
58
+ * Hook into it by listening for PasslockLogEvent events
59
+ * @see LogEvent
60
+ */
61
+ export const eventLogger = {
47
62
  logDebug: logEvent(LogLevel.DEBUG),
48
63
  logError: logEvent(LogLevel.ERROR),
49
64
  logInfo: logEvent(LogLevel.INFO),
50
65
  logWarn: logEvent(LogLevel.WARN),
51
66
  };
52
- //# sourceMappingURL=index.js.map
67
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEvC;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAQpD;CAAG;AAEN;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,QAAQ,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACtE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACtC,CAAC,CAAC;IAEJ,QAAQ,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACtE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACtC,CAAC,CAAC;IAEJ,OAAO,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACrE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACrC,CAAC,CAAC;IAEJ,OAAO,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACrE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OA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QAAQ,CAAC,IAAI,CAAC;CACjC,CAAA"}
@@ -10,6 +10,10 @@ export interface PasslockOptions {
10
10
  * environment will have a different tenancyId to prod.
11
11
  */
12
12
  tenancyId: string;
13
+ /**
14
+ * Currently used for testing, but also required to support
15
+ * multi-region deployments and on-premise self-hosted setups.
16
+ */
13
17
  endpoint?: string;
14
18
  }
15
19
  //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/shared/options.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,134 @@
1
+ import * as Helper from "@simplewebauthn/browser";
2
+ import { type AuthenticationResponseJSON, type PublicKeyCredentialRequestOptionsJSON } from "@simplewebauthn/browser";
3
+ import { Micro } from "effect";
4
+ import type { Principal } from "src/principal";
5
+ import { Endpoint, TenancyId } from "../../internal";
6
+ import type { NetworkError } from "../../internal/network";
7
+ import { Logger } from "../../logger";
8
+ import type { PasslockOptions } from "../../options";
9
+ import { OtherPasskeyError, PasskeyNotFoundError, PasskeyUnsupportedError } from "../errors";
10
+ import type { Millis, UserVerification } from "../shared";
11
+ /**
12
+ * Passkey authentication options
13
+ *
14
+ * @category Passkeys (core)
15
+ */
16
+ export interface AuthenticationOptions extends PasslockOptions {
17
+ /**
18
+ * Restrict the passkey(s) the device presents to the user to a given set
19
+ *
20
+ * @see {@link https://passlock.dev/passkeys/allow-credentials/|allowCredentials}
21
+ */
22
+ allowCredentials?: Array<string> | undefined;
23
+ /**
24
+ * Whether the device should re-authenticate the user locally before
25
+ * authenticating with a passkey.
26
+ *
27
+ * @see {@link https://passlock.dev/passkeys/user-verification/|userVerification}
28
+ */
29
+ userVerification?: UserVerification | undefined;
30
+ /**
31
+ * Use browser autofill.
32
+ *
33
+ * @see {@link https://passlock.dev/passkeys/autofill/|autofill}
34
+ */
35
+ autofill?: boolean | undefined;
36
+ /**
37
+ * Receive notifications about key stages in the authentication process.
38
+ * For example, you might use event notifications to toggle loading icons or
39
+ * to disable certain form fields.
40
+ *
41
+ * @param event
42
+ * @returns Nothing.
43
+ */
44
+ onEvent?: OnAuthenticationEvent | undefined;
45
+ /**
46
+ * Abort the operation after N milliseconds
47
+ */
48
+ timeout?: Millis | undefined;
49
+ }
50
+ export declare const AuthenticationSuccessTag: "AuthenticationSuccess";
51
+ export type AuthenticationSuccessTag = typeof AuthenticationSuccessTag;
52
+ /**
53
+ * Represents the outcome of a successful passkey authentication.
54
+ * Submit the code and/or id_token to your backend, then either
55
+ * exchange the code with the passlock REST API or decode and
56
+ * verify the id_token (JWT).
57
+ *
58
+ * Note: The @passlock/node library includes utilities to do
59
+ * this for you.
60
+ *
61
+ * @category Passkeys (core)
62
+ */
63
+ export type AuthenticationSuccess = {
64
+ /**
65
+ * Discriminator for use in a discriminated union.
66
+ */
67
+ _tag: "AuthenticationSuccess";
68
+ principal: Principal;
69
+ /**
70
+ * A signed JWT representing the authenticated passkey.
71
+ * Decode and verify this in your backend or use one of the @passlock/node
72
+ * helper utilities.
73
+ *
74
+ * @see {@link https://passlock.dev/principal/idtoken-verification/|id_token}
75
+ */
76
+ id_token: string;
77
+ /**
78
+ * Call the Passlock API to exchange this code for details about the
79
+ * authenticated passkey.
80
+ *
81
+ * @see {@link https://passlock.dev/principal/code-exchange/|code exchange}
82
+ */
83
+ code: string;
84
+ };
85
+ /**
86
+ * Type guard to narrow something down to an AuthenticationSuccess
87
+ *
88
+ * @param payload
89
+ * @returns `true` if the payload is an {@link AuthenticationSuccess}.
90
+ *
91
+ * @category Passkeys (other)
92
+ */
93
+ export declare const isAuthenticationSuccess: (payload: unknown) => payload is AuthenticationSuccess;
94
+ export declare const fetchOptions: (options: Omit<AuthenticationOptions, keyof PasslockOptions>) => Micro.Micro<OptionsResponse, NetworkError, Endpoint | TenancyId | Logger>;
95
+ export type OptionsResponse = {
96
+ sessionToken: string;
97
+ optionsJSON: PublicKeyCredentialRequestOptionsJSON;
98
+ };
99
+ export declare const isOptionsResponse: (payload: unknown) => payload is OptionsResponse;
100
+ export declare const startAuthentication: (optionsJSON: PublicKeyCredentialRequestOptionsJSON, { useBrowserAutofill, onEvent, }: {
101
+ useBrowserAutofill: boolean;
102
+ onEvent?: OnAuthenticationEvent | undefined;
103
+ }) => Micro.Micro<Helper.AuthenticationResponseJSON, PasskeyUnsupportedError | OtherPasskeyError, Logger | AuthenticationHelper>;
104
+ export declare const verifyCredential: (sessionToken: string, response: AuthenticationResponseJSON, { onEvent }: {
105
+ onEvent?: OnAuthenticationEvent | undefined;
106
+ }) => Micro.Micro<AuthenticationSuccess, NetworkError | PasskeyNotFoundError, Endpoint | TenancyId | Logger>;
107
+ /**
108
+ * Potential errors associated with Passkey authentication
109
+ *
110
+ * @category Passkeys (errors)
111
+ */
112
+ export type AuthenticationError = PasskeyUnsupportedError | OtherPasskeyError | PasskeyNotFoundError | NetworkError;
113
+ /**
114
+ * Trigger local passkey authentication then verify the passkey in your Passlock vault.
115
+ * Returns a code and id_token that can be exchanged/decoded in your backend.
116
+ *
117
+ * @param options
118
+ * @returns A Micro effect that resolves with {@link AuthenticationSuccess} or
119
+ * fails with {@link AuthenticationError}.
120
+ */
121
+ export declare const authenticatePasskey: (options: AuthenticationOptions) => Micro.Micro<AuthenticationSuccess, AuthenticationError, Logger | AuthenticationHelper>;
122
+ /**
123
+ * Type of the authentication event
124
+ */
125
+ export declare const AuthenticationEvent: readonly ["optionsRequest", "getCredential", "verifyCredential"];
126
+ /**
127
+ * @category Passkeys (other)
128
+ */
129
+ export type AuthenticationEvent = (typeof AuthenticationEvent)[number];
130
+ /**
131
+ * @category Passkeys (other)
132
+ */
133
+ export type OnAuthenticationEvent = (event: AuthenticationEvent) => void;
134
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/passkey/authentication/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACjD,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,qCAAqC,EAE3C,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAW,KAAK,EAAQ,MAAM,QAAQ,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAA6B,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEzD;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IAE5C;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAE9B;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAA;IAE3C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B;AA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EACrB,mBAAmB,EACnB,MAAM,GAAG,oBAAoB,CAkC9B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,kEAItB,CAAA;AAEV;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAA"}
@@ -1,45 +1,51 @@
1
1
  import * as Helper from "@simplewebauthn/browser";
2
2
  import { WebAuthnError, } from "@simplewebauthn/browser";
3
3
  import { Context, Micro, pipe } from "effect";
4
- import { Logger } from "../logger";
5
- import { buildEndpoint, Endpoint, makeRequest } from "../shared/network";
6
- import { TenancyId } from "../shared/tenancy";
7
- import { OtherPasskeyError, PasskeyUnsupportedError } from "./errors";
4
+ import { Endpoint, makeEndpoint, makeRequest, TenancyId } from "../../internal";
5
+ import { Logger } from "../../logger";
6
+ import { OtherPasskeyError, PasskeyNotFoundError, PasskeyUnsupportedError, } from "../errors";
7
+ /**
8
+ * @internal
9
+ * @hidden
10
+ */
8
11
  export class AuthenticationHelper extends Context.Tag("AuthenticationHelper")() {
9
12
  static Default = {
10
13
  browserSupportsWebAuthn: Helper.browserSupportsWebAuthn,
11
14
  startAuthentication: Helper.startAuthentication,
12
15
  };
13
16
  }
14
- const isOptionsResponse = (payload) => {
17
+ export const AuthenticationSuccessTag = "AuthenticationSuccess";
18
+ /**
19
+ * Type guard to narrow something down to an AuthenticationSuccess
20
+ *
21
+ * @param payload
22
+ * @returns `true` if the payload is an {@link AuthenticationSuccess}.
23
+ *
24
+ * @category Passkeys (other)
25
+ */
26
+ export const isAuthenticationSuccess = (payload) => {
15
27
  if (typeof payload !== "object")
16
28
  return false;
17
29
  if (payload === null)
18
30
  return false;
19
- if (!("optionsJSON" in payload))
20
- return false;
21
- if (typeof payload.optionsJSON !== "object")
22
- return false;
23
- if (payload.optionsJSON === null)
31
+ if (!("_tag" in payload))
24
32
  return false;
25
- if (!("sessionToken" in payload))
33
+ if (typeof payload._tag !== "string")
26
34
  return false;
27
- if (typeof payload.sessionToken !== "string")
35
+ if (payload._tag !== AuthenticationSuccessTag)
28
36
  return false;
29
37
  return true;
30
38
  };
31
- export const authenticationEvent = ["optionsRequest", "getCredential", "verifyCredential"];
32
39
  export const fetchOptions = (options) => Micro.gen(function* () {
33
40
  const logger = yield* Micro.service(Logger);
34
41
  const { endpoint } = yield* Micro.service(Endpoint);
35
42
  const { tenancyId } = yield* Micro.service(TenancyId);
36
- const { userId, userVerification, allowCredentials, timeout, onEvent } = options;
43
+ const { userVerification, allowCredentials, timeout, onEvent } = options;
37
44
  const url = new URL(`${tenancyId}/passkey/authentication/options`, endpoint);
38
45
  onEvent?.("optionsRequest");
39
46
  yield* logger.logInfo("Fetching passkey authentication options from Passlock");
40
47
  const payload = {
41
48
  allowCredentials,
42
- userId,
43
49
  userVerification,
44
50
  timeout,
45
51
  };
@@ -50,42 +56,20 @@ export const fetchOptions = (options) => Micro.gen(function* () {
50
56
  url,
51
57
  });
52
58
  });
53
- const AuthenticationSuccessTag = "AuthenticationSuccess";
54
- export const isAuthenticationSuccess = (payload) => {
55
- if (typeof payload !== "object")
56
- return false;
57
- if (payload === null)
58
- return false;
59
- if (!("_tag" in payload))
60
- return false;
61
- if (typeof payload._tag !== "string")
62
- return false;
63
- if (payload._tag !== AuthenticationSuccessTag)
64
- return false;
65
- return true;
66
- };
67
- export const isPasskeyNotFound = (payload) => {
59
+ export const isOptionsResponse = (payload) => {
68
60
  if (typeof payload !== "object")
69
61
  return false;
70
62
  if (payload === null)
71
63
  return false;
72
- if (!("_tag" in payload))
73
- return false;
74
- if (typeof payload._tag !== "string")
75
- return false;
76
- if (payload._tag !== "@error/PasskeyNotFound")
77
- return false;
78
- if (!("message" in payload))
79
- return false;
80
- if (typeof payload.message !== "string")
64
+ if (!("optionsJSON" in payload))
81
65
  return false;
82
- if (!("credentialId" in payload))
66
+ if (typeof payload.optionsJSON !== "object")
83
67
  return false;
84
- if (typeof payload.credentialId !== "string")
68
+ if (payload.optionsJSON === null)
85
69
  return false;
86
- if (!("rpId" in payload))
70
+ if (!("sessionToken" in payload))
87
71
  return false;
88
- if (typeof payload.rpId !== "string")
72
+ if (typeof payload.sessionToken !== "string")
89
73
  return false;
90
74
  return true;
91
75
  };
@@ -96,9 +80,9 @@ export const startAuthentication = (optionsJSON, { useBrowserAutofill, onEvent,
96
80
  const helper = yield* Micro.service(AuthenticationHelper);
97
81
  const isSupport = helper.browserSupportsWebAuthn();
98
82
  if (!isSupport)
99
- yield* new PasskeyUnsupportedError({
83
+ yield* Micro.fail(new PasskeyUnsupportedError({
100
84
  message: "Device does not support passkeys",
101
- });
85
+ }));
102
86
  return yield* Micro.tryPromise({
103
87
  catch: (error) => {
104
88
  if (error instanceof WebAuthnError) {
@@ -116,6 +100,31 @@ export const startAuthentication = (optionsJSON, { useBrowserAutofill, onEvent,
116
100
  try: () => helper.startAuthentication({ optionsJSON, useBrowserAutofill }),
117
101
  });
118
102
  });
103
+ const isPasskeyNotFound = (payload) => {
104
+ if (typeof payload !== "object")
105
+ return false;
106
+ if (payload === null)
107
+ return false;
108
+ if (!("_tag" in payload))
109
+ return false;
110
+ if (typeof payload._tag !== "string")
111
+ return false;
112
+ if (payload._tag !== "@error/PasskeyNotFound")
113
+ return false;
114
+ if (!("message" in payload))
115
+ return false;
116
+ if (typeof payload.message !== "string")
117
+ return false;
118
+ if (!("credentialId" in payload))
119
+ return false;
120
+ if (typeof payload.credentialId !== "string")
121
+ return false;
122
+ if (!("rpId" in payload))
123
+ return false;
124
+ if (typeof payload.rpId !== "string")
125
+ return false;
126
+ return true;
127
+ };
119
128
  export const verifyCredential = (sessionToken, response, { onEvent }) => Micro.gen(function* () {
120
129
  const logger = yield* Micro.service(Logger);
121
130
  const { endpoint } = yield* Micro.service(Endpoint);
@@ -127,25 +136,26 @@ export const verifyCredential = (sessionToken, response, { onEvent }) => Micro.g
127
136
  response,
128
137
  sessionToken,
129
138
  };
130
- const authenticationResponse = yield* makeRequest({
139
+ const authenticationResponse = yield* pipe(makeRequest({
131
140
  errorPredicate: isPasskeyNotFound,
132
141
  label: "authentication verification",
133
142
  payload,
134
143
  responsePredicate: isAuthenticationSuccess,
135
144
  url,
136
- });
145
+ }), Micro.catchTag("@error/PasskeyNotFound", (err) => Micro.fail(new PasskeyNotFoundError(err))));
137
146
  yield* logger.logInfo(`Passkey with id ${authenticationResponse.principal.authenticatorId} successfully authenticated`);
138
147
  return authenticationResponse;
139
148
  });
140
149
  /**
141
- * Trigger local passkey authentication then verify the passkey in the Passlock vault.
150
+ * Trigger local passkey authentication then verify the passkey in your Passlock vault.
142
151
  * Returns a code and id_token that can be exchanged/decoded in your backend.
143
152
  *
144
153
  * @param options
145
- * @returns
154
+ * @returns A Micro effect that resolves with {@link AuthenticationSuccess} or
155
+ * fails with {@link AuthenticationError}.
146
156
  */
147
157
  export const authenticatePasskey = (options) => {
148
- const endpoint = buildEndpoint(options);
158
+ const endpoint = makeEndpoint(options);
149
159
  const micro = Micro.gen(function* () {
150
160
  const { sessionToken, optionsJSON } = yield* fetchOptions(options);
151
161
  const go = (useBrowserAutofill) => Micro.gen(function* () {
@@ -169,4 +179,12 @@ export const authenticatePasskey = (options) => {
169
179
  });
170
180
  return pipe(micro, Micro.provideService(TenancyId, options), Micro.provideService(Endpoint, endpoint));
171
181
  };
182
+ /**
183
+ * Type of the authentication event
184
+ */
185
+ export const AuthenticationEvent = [
186
+ "optionsRequest",
187
+ "getCredential",
188
+ "verifyCredential",
189
+ ];
172
190
  //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../../src/passkey/authentication/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAGL,aAAa,GACd,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,O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,GAAG,CAAC,QAAQ,CAAC;YACjB,IAAI,kBAAkB;gBAAE,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAE/C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE;gBACvD,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,kBAAkB;aACnB,CAAC,CAAA;YAEF,OAAO,CAAC,OAAO,EAAE,CAAC,kBAAkB,CAAC,CAAA;YACrC,OAAO,KAAK,CAAC,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE;gBACrD,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEJ,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACpC,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CACT,KAAK,EACL,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,EACxC,KAAK,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CACzC,CAAA;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,gBAAgB;IAChB,eAAe;IACf,kBAAkB;CACV,CAAA"}
@@ -1,25 +1,167 @@
1
- import { Micro } from "effect";
2
- export declare const isPasskeyUnsupported: (error: unknown) => error is PasskeyUnsupportedError;
3
- declare const PasskeyUnsupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Micro.YieldableError & {
4
- readonly _tag: "@error/PasskeyUnsupported";
5
- } & Readonly<A>;
6
- export declare class PasskeyUnsupportedError extends PasskeyUnsupportedError_base<{
1
+ /**
2
+ * The local device does not support Passkeys.
3
+ * See the message property (string) for more details
4
+ *
5
+ * @category Passkeys (errors)
6
+ */
7
+ export declare const isPasskeyUnsupportedError: (payload: unknown) => payload is PasskeyUnsupportedError;
8
+ /**
9
+ * The local device does not support Passkeys.
10
+ * See the message property (string) for more details
11
+ *
12
+ * @category Passkeys (errors)
13
+ */
14
+ export declare class PasskeyUnsupportedError extends Error {
15
+ readonly _tag: "PasskeyUnsupported";
7
16
  readonly message: string;
8
- }> {
9
- static isPasskeyUnsupported: (error: unknown) => error is PasskeyUnsupportedError;
17
+ constructor({ message }: {
18
+ message: string;
19
+ });
20
+ static isPasskeyUnsupportedError: (payload: unknown) => payload is PasskeyUnsupportedError;
21
+ }
22
+ /**
23
+ * Client tried to authenticate with a passkey that was not found in the vault.
24
+ * Note: this error can be passed to the {@link deletePasskey} function. This is
25
+ * useful when the user has an orphaned passkey on their device with no server-side
26
+ * component. Just pass this error into deletePasskey and the library will attempt
27
+ * to remove the orphaned passkey from the local device.
28
+ *
29
+ * @category Passkeys (errors)
30
+ */
31
+ export declare const isPasskeyNotFoundError: (payload: unknown) => payload is PasskeyNotFoundError;
32
+ /**
33
+ * Client tried to authenticate with a passkey that was not found in the vault.
34
+ * Note: this error can be passed to the {@link deletePasskey} function. This is
35
+ * useful when the user has an orphaned passkey on their device with no server-side
36
+ * component. Just pass this error into deletePasskey and the library will attempt
37
+ * to remove the orphaned passkey from the local device.
38
+ *
39
+ * @category Passkeys (errors)
40
+ */
41
+ export declare class PasskeyNotFoundError extends Error {
42
+ readonly _tag: "PasskeyNotFoundError";
43
+ readonly message: string;
44
+ readonly credentialId: string;
45
+ readonly rpId: string;
46
+ constructor({ message, credentialId, rpId, }: {
47
+ message: string;
48
+ credentialId: string;
49
+ rpId: string;
50
+ });
51
+ static isPasskeyNotFoundError: (payload: unknown) => payload is PasskeyNotFoundError;
10
52
  }
11
53
  export type ErrorCode = "ERROR_CEREMONY_ABORTED" | "ERROR_INVALID_DOMAIN" | "ERROR_INVALID_RP_ID" | "ERROR_INVALID_USER_ID_LENGTH" | "ERROR_MALFORMED_PUBKEYCREDPARAMS" | "ERROR_AUTHENTICATOR_GENERAL_ERROR" | "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT" | "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT" | "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED" | "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG" | "ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE" | "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY";
12
- export declare const isOtherPasskeyError: (error: unknown) => error is OtherPasskeyError;
13
- declare const OtherPasskeyError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Micro.YieldableError & {
14
- readonly _tag: "@error/OtherPasskeyError";
15
- } & Readonly<A>;
16
- export declare class OtherPasskeyError extends OtherPasskeyError_base<{
54
+ /**
55
+ * An unexpected passkey specific error occurred.
56
+ * Check the code and message for more information.
57
+ *
58
+ * @category Passkeys (errors)
59
+ */
60
+ export declare const isOtherPasskeyError: (payload: unknown) => payload is OtherPasskeyError;
61
+ /**
62
+ * An unexpected passkey specific error occurred.
63
+ * Check the code and message for more information.
64
+ *
65
+ * @category Passkeys (errors)
66
+ */
67
+ export declare class OtherPasskeyError extends Error {
68
+ readonly _tag: "OtherPasskey";
17
69
  readonly error: unknown;
18
70
  readonly message: string;
19
71
  readonly code?: ErrorCode;
20
72
  readonly cause?: unknown;
21
- }> {
22
- static isOtherPasskeyError: (error: unknown) => error is OtherPasskeyError;
73
+ constructor({ error, message, code, cause, }: {
74
+ error: unknown;
75
+ message: string;
76
+ code?: ErrorCode;
77
+ cause?: unknown;
78
+ });
79
+ static isOtherPasskeyError: (payload: unknown) => payload is OtherPasskeyError;
80
+ }
81
+ /**
82
+ * Raised if excludeCredentials was provided and the device
83
+ * recognises one of the excluded passkeys i.e. the user currently
84
+ * has a passkey registered for a given userId.
85
+ *
86
+ * @category Passkeys (errors)
87
+ */
88
+ export declare const isDuplicatePasskeyError: (payload: unknown) => payload is DuplicatePasskeyError;
89
+ /**
90
+ * Raised if excludeCredentials was provided and the device
91
+ * recognises one of the excluded passkeys i.e. the user currently
92
+ * has a passkey registered for a given userId.
93
+ *
94
+ * @category Passkeys (errors)
95
+ */
96
+ export declare class DuplicatePasskeyError extends Error {
97
+ readonly _tag: "DuplicatePasskeyError";
98
+ readonly message: string;
99
+ constructor({ message }: {
100
+ message: string;
101
+ });
102
+ static isDuplicatePasskeyError: (payload: unknown) => payload is DuplicatePasskeyError;
103
+ }
104
+ /**
105
+ * The browser/device was unable to delete the passkey
106
+ *
107
+ * @category Passkeys (errors)
108
+ */
109
+ export declare const isDeleteError: (payload: unknown) => payload is DeleteError;
110
+ /**
111
+ * The browser/device was unable to delete the passkey
112
+ *
113
+ * @category Passkeys (errors)
114
+ */
115
+ export declare class DeleteError extends Error {
116
+ readonly _tag: "DeleteError";
117
+ readonly message: string;
118
+ readonly code: "PASSKEY_DELETION_UNSUPPORTED" | "PASSKEY_NOT_FOUND" | "OTHER_ERROR";
119
+ constructor({ message, code, }: {
120
+ message: string;
121
+ code: "PASSKEY_DELETION_UNSUPPORTED" | "PASSKEY_NOT_FOUND" | "OTHER_ERROR";
122
+ });
123
+ static isDeleteError: (payload: unknown) => payload is DeleteError;
124
+ }
125
+ /**
126
+ * The browser/device was unable to prune the passkeys
127
+ *
128
+ * @category Passkeys (errors)
129
+ */
130
+ export declare const isPruningError: (payload: unknown) => payload is PruningError;
131
+ /**
132
+ * The browser/device was unable to prune the passkeys
133
+ *
134
+ * @category Passkeys (errors)
135
+ */
136
+ export declare class PruningError extends Error {
137
+ readonly _tag: "PruningError";
138
+ readonly message: string;
139
+ readonly code: "PASSKEY_PRUNING_UNSUPPORTED" | "OTHER_ERROR";
140
+ constructor({ message, code, }: {
141
+ message: string;
142
+ code: "PASSKEY_PRUNING_UNSUPPORTED" | "OTHER_ERROR";
143
+ });
144
+ static isPruningError: (payload: unknown) => payload is PruningError;
145
+ }
146
+ /**
147
+ * The browser/device was unable to update the local passkey
148
+ *
149
+ * @category Passkeys (errors)
150
+ */
151
+ export declare const isUpdateError: (payload: unknown) => payload is UpdateError;
152
+ /**
153
+ * The browser/device was unable to update the local passkey
154
+ *
155
+ * @category Passkeys (errors)
156
+ */
157
+ export declare class UpdateError extends Error {
158
+ readonly _tag: "UpdateError";
159
+ readonly message: string;
160
+ readonly code: "PASSKEY_UPDATE_UNSUPPORTED" | "OTHER_ERROR";
161
+ constructor({ message, code, }: {
162
+ message: string;
163
+ code: "PASSKEY_UPDATE_UNSUPPORTED" | "OTHER_ERROR";
164
+ });
165
+ static isUpdateError: (payload: unknown) => payload is UpdateError;
23
166
  }
24
- export {};
25
167
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/passkey/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAE9B,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,uBACrB,CAAA;;;;AAE1C,qBAAa,uBAAwB,SAAQ,6BAA+C;IAC1F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAC;IACA,MAAM,CAAC,oBAAoB,UANe,OAAO,KAAG,KAAK,IAAI,uBAAuB,CAMlC;CACnD;AAED,MAAM,MAAM,SAAS,GACjB,wBAAwB,GACxB,sBAAsB,GACtB,qBAAqB,GACrB,8BAA8B,GAC9B,kCAAkC,GAClC,mCAAmC,GACnC,6DAA6D,GAC7D,uDAAuD,GACvD,2CAA2C,GAC3C,uDAAuD,GAC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