@tensile-tools/auth-client 0.0.0-stage → 0.3.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.
Files changed (44) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +62 -2
  3. package/dist/client.d.ts +569 -0
  4. package/dist/client.js +637 -0
  5. package/dist/devtools.d.ts +12 -0
  6. package/dist/devtools.js +44 -0
  7. package/dist/elements/account.d.ts +63 -0
  8. package/dist/elements/account.js +331 -0
  9. package/dist/elements/approvals.d.ts +61 -0
  10. package/dist/elements/approvals.js +252 -0
  11. package/dist/elements/auth.d.ts +48 -0
  12. package/dist/elements/auth.js +238 -0
  13. package/dist/elements/base.d.ts +176 -0
  14. package/dist/elements/base.js +540 -0
  15. package/dist/elements/config.d.ts +70 -0
  16. package/dist/elements/config.js +119 -0
  17. package/dist/elements/format.d.ts +32 -0
  18. package/dist/elements/format.js +67 -0
  19. package/dist/elements/index.d.ts +21 -0
  20. package/dist/elements/index.js +31 -0
  21. package/dist/elements/qr.d.ts +9 -0
  22. package/dist/elements/qr.js +302 -0
  23. package/dist/elements/returnto.d.ts +17 -0
  24. package/dist/elements/returnto.js +63 -0
  25. package/dist/elements/setup.d.ts +70 -0
  26. package/dist/elements/setup.js +316 -0
  27. package/dist/elements/styles.d.ts +3 -0
  28. package/dist/elements/styles.js +194 -0
  29. package/dist/elements/text.d.ts +21 -0
  30. package/dist/elements/text.js +302 -0
  31. package/dist/fonts/OFL-geist-mono.txt +93 -0
  32. package/dist/fonts/OFL-geist.txt +93 -0
  33. package/dist/fonts/OFL-inter.txt +93 -0
  34. package/dist/fonts/README.md +18 -0
  35. package/dist/fonts/geist-mono.woff2 +0 -0
  36. package/dist/fonts/geist.woff2 +0 -0
  37. package/dist/fonts/inter.woff2 +0 -0
  38. package/dist/index.d.ts +4 -0
  39. package/dist/index.js +5 -0
  40. package/dist/problem.d.ts +54 -0
  41. package/dist/problem.js +40 -0
  42. package/dist/webauthn.d.ts +46 -0
  43. package/dist/webauthn.js +102 -0
  44. package/package.json +51 -4
@@ -0,0 +1,54 @@
1
+ /** A factor the account can step up with. */
2
+ export type Method = 'passkey' | 'totp' | 'recovery' | 'federated' | 'external' | 'password' | 'bridged';
3
+ /** How strongly a person proved who they are. */
4
+ export type Assurance = 'none' | 'recovering' | 'single' | 'multi';
5
+ /** An approval an agent can wait for instead of stopping. */
6
+ export interface ChallengeApproval {
7
+ id: string;
8
+ url?: string;
9
+ summary: string;
10
+ expires_in: number;
11
+ /** The Prefer header value to send with the retry, for example `wait=60`. */
12
+ wait_hint?: string;
13
+ }
14
+ /** What would turn a refusal into a success. */
15
+ export interface Challenge {
16
+ action: string;
17
+ assurance: Assurance;
18
+ within_seconds?: number;
19
+ human?: boolean;
20
+ scopes?: string[];
21
+ satisfy_with: Method[];
22
+ begin?: string;
23
+ approval?: ChallengeApproval;
24
+ purpose?: {
25
+ name: string;
26
+ resource?: string;
27
+ };
28
+ }
29
+ /** One error shape for every refusal. */
30
+ export interface Problem {
31
+ type: string;
32
+ title: string;
33
+ status: number;
34
+ code: string;
35
+ detail?: string;
36
+ fix?: string;
37
+ retry_after?: number;
38
+ challenge?: Challenge;
39
+ }
40
+ /** The media type of problem responses. */
41
+ export declare const problemType = "application/problem+json";
42
+ /** Codes whose challenge a step-up can satisfy. */
43
+ export declare const stepUpCodes: Set<string>;
44
+ /**
45
+ * Reads the problem from a failed response. A response that isn't a
46
+ * problem becomes one with the code `http_<status>`, so callers handle a
47
+ * single shape.
48
+ */
49
+ export declare function readProblem(res: Response): Promise<Problem>;
50
+ /** An error that carries a problem, thrown by `AuthClient.fetch`. */
51
+ export declare class ProblemError extends Error {
52
+ readonly problem: Problem;
53
+ constructor(problem: Problem);
54
+ }
@@ -0,0 +1,40 @@
1
+ // Problem details (RFC 9457) as tensile-auth writes them.
2
+ /** The media type of problem responses. */
3
+ export const problemType = 'application/problem+json';
4
+ /** Codes whose challenge a step-up can satisfy. */
5
+ export const stepUpCodes = new Set(['step_up_required', 'stronger_factor_required']);
6
+ /**
7
+ * Reads the problem from a failed response. A response that isn't a
8
+ * problem becomes one with the code `http_<status>`, so callers handle a
9
+ * single shape.
10
+ */
11
+ export async function readProblem(res) {
12
+ const type = res.headers.get('content-type') ?? '';
13
+ if (type.startsWith(problemType) || type.startsWith('application/json')) {
14
+ try {
15
+ const body = (await res.json());
16
+ if (typeof body.code === 'string' && typeof body.title === 'string') {
17
+ return { ...body, status: body.status ?? res.status };
18
+ }
19
+ }
20
+ catch {
21
+ // Fall through to the generic problem.
22
+ }
23
+ }
24
+ return {
25
+ type: 'about:blank',
26
+ title: res.statusText || 'Request failed',
27
+ status: res.status,
28
+ code: `http_${res.status}`,
29
+ fix: 'Try again.',
30
+ };
31
+ }
32
+ /** An error that carries a problem, thrown by `AuthClient.fetch`. */
33
+ export class ProblemError extends Error {
34
+ problem;
35
+ constructor(problem) {
36
+ super(problem.fix ? `${problem.title}. ${problem.fix}` : problem.title);
37
+ this.name = 'ProblemError';
38
+ this.problem = problem;
39
+ }
40
+ }
@@ -0,0 +1,46 @@
1
+ /** base64url without padding, as WebAuthn JSON uses. */
2
+ export declare function toBase64url(buf: ArrayBuffer | ArrayBufferView): string;
3
+ /** Decodes base64url, with or without padding. */
4
+ export declare function fromBase64url(s: string): ArrayBuffer;
5
+ type Json = Record<string, unknown>;
6
+ interface PKC {
7
+ parseCreationOptionsFromJSON?: (o: Json) => PublicKeyCredentialCreationOptions;
8
+ parseRequestOptionsFromJSON?: (o: Json) => PublicKeyCredentialRequestOptions;
9
+ getClientCapabilities?: () => Promise<Record<string, boolean>>;
10
+ signalUnknownCredential?: (o: Json) => Promise<void>;
11
+ signalAllAcceptedCredentials?: (o: Json) => Promise<void>;
12
+ signalCurrentUserDetails?: (o: Json) => Promise<void>;
13
+ isConditionalMediationAvailable?: () => Promise<boolean>;
14
+ isUserVerifyingPlatformAuthenticatorAvailable?: () => Promise<boolean>;
15
+ }
16
+ /** The PublicKeyCredential global, or undefined outside a WebAuthn browser. */
17
+ export declare function pkc(): PKC | undefined;
18
+ /** Unwraps the server's `{publicKey: …}` and decodes it for create(). */
19
+ export declare function creationOptions(server: Json): PublicKeyCredentialCreationOptions;
20
+ /** Unwraps the server's `{publicKey: …}` and decodes it for get(). */
21
+ export declare function requestOptions(server: Json): PublicKeyCredentialRequestOptions;
22
+ /** Encodes a credential from create() or get() for the server. */
23
+ export declare function credentialJSON(cred: PublicKeyCredential): Json;
24
+ /** What this browser can do with passkeys. */
25
+ export interface Capabilities {
26
+ /** WebAuthn is available at all. */
27
+ webauthn: boolean;
28
+ /** Passkeys can appear in autofill (conditional UI). */
29
+ conditionalGet: boolean;
30
+ /** The device has a built-in authenticator, such as Touch ID or Windows Hello. */
31
+ platformAuthenticator: boolean;
32
+ /** Sign-in with a phone over QR and Bluetooth (hybrid transport). */
33
+ hybridTransport: boolean;
34
+ /** The PRF extension, for keys derived from a passkey. */
35
+ prf: boolean;
36
+ /** The browser can answer at once when no passkey exists (immediate mediation). */
37
+ immediateGet: boolean;
38
+ /** The Signal API, to keep password managers in sync. */
39
+ signals: boolean;
40
+ }
41
+ /**
42
+ * Reports what the browser supports. It uses getClientCapabilities()
43
+ * where the browser has it, and older checks elsewhere.
44
+ */
45
+ export declare function capabilities(): Promise<Capabilities>;
46
+ export {};
@@ -0,0 +1,102 @@
1
+ // WebAuthn plumbing: JSON options in, JSON credentials out, and capability
2
+ // detection. It prefers the browser's own JSON helpers and falls back to
3
+ // converting base64url fields by hand.
4
+ /** base64url without padding, as WebAuthn JSON uses. */
5
+ export function toBase64url(buf) {
6
+ const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
7
+ let bin = '';
8
+ for (const b of bytes)
9
+ bin += String.fromCharCode(b);
10
+ return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
11
+ }
12
+ /** Decodes base64url, with or without padding. */
13
+ export function fromBase64url(s) {
14
+ const b64 = s.replace(/-/g, '+').replace(/_/g, '/') + '==='.slice((s.length + 3) % 4);
15
+ const bin = atob(b64);
16
+ const out = new Uint8Array(bin.length);
17
+ for (let i = 0; i < bin.length; i++)
18
+ out[i] = bin.charCodeAt(i);
19
+ return out.buffer;
20
+ }
21
+ /** The PublicKeyCredential global, or undefined outside a WebAuthn browser. */
22
+ export function pkc() {
23
+ return globalThis.PublicKeyCredential;
24
+ }
25
+ /** Unwraps the server's `{publicKey: …}` and decodes it for create(). */
26
+ export function creationOptions(server) {
27
+ const o = (server.publicKey ?? server);
28
+ const native = pkc()?.parseCreationOptionsFromJSON;
29
+ if (native)
30
+ return native(o);
31
+ const user = o.user;
32
+ return {
33
+ ...o,
34
+ challenge: fromBase64url(o.challenge),
35
+ user: { ...user, id: fromBase64url(user.id) },
36
+ excludeCredentials: (o.excludeCredentials ?? []).map(c => ({ ...c, id: fromBase64url(c.id) })),
37
+ };
38
+ }
39
+ /** Unwraps the server's `{publicKey: …}` and decodes it for get(). */
40
+ export function requestOptions(server) {
41
+ const o = (server.publicKey ?? server);
42
+ const native = pkc()?.parseRequestOptionsFromJSON;
43
+ if (native)
44
+ return native(o);
45
+ return {
46
+ ...o,
47
+ challenge: fromBase64url(o.challenge),
48
+ allowCredentials: (o.allowCredentials ?? []).map(c => ({ ...c, id: fromBase64url(c.id) })),
49
+ };
50
+ }
51
+ /** Encodes a credential from create() or get() for the server. */
52
+ export function credentialJSON(cred) {
53
+ const withJSON = cred;
54
+ if (typeof withJSON.toJSON === 'function')
55
+ return withJSON.toJSON();
56
+ const r = cred.response;
57
+ const response = { clientDataJSON: toBase64url(r.clientDataJSON) };
58
+ if (r.attestationObject) {
59
+ response.attestationObject = toBase64url(r.attestationObject);
60
+ response.transports = r.getTransports?.() ?? [];
61
+ }
62
+ if (r.authenticatorData)
63
+ response.authenticatorData = toBase64url(r.authenticatorData);
64
+ if (r.signature)
65
+ response.signature = toBase64url(r.signature);
66
+ if (r.userHandle)
67
+ response.userHandle = toBase64url(r.userHandle);
68
+ return {
69
+ id: cred.id,
70
+ rawId: toBase64url(cred.rawId),
71
+ type: cred.type,
72
+ authenticatorAttachment: cred.authenticatorAttachment ?? undefined,
73
+ clientExtensionResults: cred.getClientExtensionResults(),
74
+ response,
75
+ };
76
+ }
77
+ /**
78
+ * Reports what the browser supports. It uses getClientCapabilities()
79
+ * where the browser has it, and older checks elsewhere.
80
+ */
81
+ export async function capabilities() {
82
+ const p = pkc();
83
+ const none = {
84
+ webauthn: false, conditionalGet: false, platformAuthenticator: false, hybridTransport: false,
85
+ prf: false, immediateGet: false, signals: false,
86
+ };
87
+ if (!p)
88
+ return none;
89
+ const caps = (await p.getClientCapabilities?.().catch(() => undefined)) ?? {};
90
+ const conditional = caps.conditionalGet ?? (await p.isConditionalMediationAvailable?.().catch(() => false)) ?? false;
91
+ const platform = caps.userVerifyingPlatformAuthenticator ??
92
+ (await p.isUserVerifyingPlatformAuthenticatorAvailable?.().catch(() => false)) ?? false;
93
+ return {
94
+ webauthn: true,
95
+ conditionalGet: Boolean(conditional),
96
+ platformAuthenticator: Boolean(platform),
97
+ hybridTransport: Boolean(caps.hybridTransport),
98
+ prf: Boolean(caps['extension:prf']),
99
+ immediateGet: Boolean(caps.immediateGet),
100
+ signals: typeof p.signalAllAcceptedCredentials === 'function',
101
+ };
102
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@tensile-tools/auth-client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Browser client for tensile-auth, like Better Auth but built for AI agents: passkey ceremonies with honest outcomes, one problem shape, step-up and approval challenges, password-manager sync, and tab sync.",
5
+ "license": "Apache-2.0",
6
+ "keywords": [
7
+ "auth",
8
+ "authentication",
9
+ "passkeys",
10
+ "webauthn",
11
+ "browser",
12
+ "web-components",
13
+ "step-up",
14
+ "ai-agents",
15
+ "approvals"
16
+ ],
17
+ "homepage": "https://auth.tensile.tools/docs/guides/browser-client/",
18
+ "bugs": {
19
+ "url": "https://github.com/tensile-tools/tensile-auth/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/tensile-tools/tensile-auth.git",
24
+ "directory": "client"
25
+ },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "test": "node --test test/*.test.ts",
38
+ "check": "tsc --noEmit -p .",
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "engines": {
43
+ "node": ">=22.18"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "22.15.3",
51
+ "typescript": "5.8.3"
52
+ }
53
+ }