@sparkvault/sdk-js 5.0.2 → 7.0.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/dist/index.d.ts CHANGED
@@ -158,7 +158,7 @@ type Recommendation = {
158
158
  missingType: 'email' | 'phone';
159
159
  };
160
160
  /** A self-service screen in the auth.sv Identity portal. */
161
- type PortalSection = 'home' | 'contacts' | 'security' | 'sessions' | 'sites';
161
+ type PortalSection = 'home' | 'identity' | 'security' | 'sessions' | 'sites';
162
162
  /** Options for building an auth.sv portal deep link (`portalUrl()`). */
163
163
  interface PortalUrlOptions {
164
164
  /** Which portal screen to open. Defaults to `'home'`. */
@@ -293,8 +293,9 @@ declare class IdentityModule {
293
293
  constructor(config: ResolvedConfig);
294
294
  /**
295
295
  * Build a deep link into the person's auth.sv Identity portal — where they
296
- * manage verified contacts, passkeys, sessions, and connected sites across
297
- * every SparkVault-integrated site. Send a signed-in user here to self-serve;
296
+ * manage their verified identity, passkeys, sessions, and connected sites
297
+ * across every SparkVault-integrated site. Send a signed-in user here to
298
+ * self-serve;
298
299
  * the portal authenticates them with their own SparkVault Identity.
299
300
  *
300
301
  * @example Manage this site (block/notifications/etc.)
@@ -341,18 +342,26 @@ declare class IdentityModule {
341
342
  */
342
343
  attach(selector: string, options?: AttachOptions): () => void;
343
344
  /**
344
- * Verify and decode an identity token.
345
- * Validates the token structure, expiry, and issuer.
345
+ * Decode an identity token's claims WITHOUT verifying its signature.
346
346
  *
347
- * Note: For production use, verify the Ed25519 signature server-side
348
- * using the JWKS endpoint.
347
+ * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
348
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
349
+ * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
350
+ * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
351
+ * result MUST NOT be trusted for any authorization decision.
352
+ *
353
+ * To trust a token (e.g. before keying records by `claims.svid`), verify the
354
+ * Ed25519 signature server-side against the Identity JWKS endpoint
355
+ * (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
349
356
  */
350
- verifyToken(token: string): Promise<TokenClaims>;
357
+ decodeToken(token: string): TokenClaims;
351
358
  /**
352
359
  * Complete full-page redirect results produced by social-login flows.
353
360
  * The Identity Product redirects back with `#token=...` so the token does
354
- * not hit server logs. Consume it once, validate the issuer/expiry shape,
355
- * then remove it from the URL bar.
361
+ * not hit server logs. Consume it once, run the unverified client-side decode
362
+ * (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
363
+ * remove it from the URL bar. The host must still verify the token server-side
364
+ * via the Identity JWKS before trusting any claim.
356
365
  */
357
366
  private consumeRedirectResult;
358
367
  /**
@@ -23,8 +23,9 @@ export declare class IdentityModule {
23
23
  constructor(config: ResolvedConfig);
24
24
  /**
25
25
  * Build a deep link into the person's auth.sv Identity portal — where they
26
- * manage verified contacts, passkeys, sessions, and connected sites across
27
- * every SparkVault-integrated site. Send a signed-in user here to self-serve;
26
+ * manage their verified identity, passkeys, sessions, and connected sites
27
+ * across every SparkVault-integrated site. Send a signed-in user here to
28
+ * self-serve;
28
29
  * the portal authenticates them with their own SparkVault Identity.
29
30
  *
30
31
  * @example Manage this site (block/notifications/etc.)
@@ -71,18 +72,26 @@ export declare class IdentityModule {
71
72
  */
72
73
  attach(selector: string, options?: AttachOptions): () => void;
73
74
  /**
74
- * Verify and decode an identity token.
75
- * Validates the token structure, expiry, and issuer.
75
+ * Decode an identity token's claims WITHOUT verifying its signature.
76
76
  *
77
- * Note: For production use, verify the Ed25519 signature server-side
78
- * using the JWKS endpoint.
77
+ * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
78
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
79
+ * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
80
+ * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
81
+ * result MUST NOT be trusted for any authorization decision.
82
+ *
83
+ * To trust a token (e.g. before keying records by `claims.svid`), verify the
84
+ * Ed25519 signature server-side against the Identity JWKS endpoint
85
+ * (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
79
86
  */
80
- verifyToken(token: string): Promise<TokenClaims>;
87
+ decodeToken(token: string): TokenClaims;
81
88
  /**
82
89
  * Complete full-page redirect results produced by social-login flows.
83
90
  * The Identity Product redirects back with `#token=...` so the token does
84
- * not hit server logs. Consume it once, validate the issuer/expiry shape,
85
- * then remove it from the URL bar.
91
+ * not hit server logs. Consume it once, run the unverified client-side decode
92
+ * (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
93
+ * remove it from the URL bar. The host must still verify the token server-side
94
+ * via the Identity JWKS before trusting any claim.
86
95
  */
87
96
  private consumeRedirectResult;
88
97
  /**
@@ -92,7 +92,7 @@ export type Recommendation = {
92
92
  /** Canonical dismiss key for a recommendation (suppresses it server-side 30d). */
93
93
  export type RecommendationKey = 'passkey' | 'backup_email' | 'backup_phone';
94
94
  /** A self-service screen in the auth.sv Identity portal. */
95
- export type PortalSection = 'home' | 'contacts' | 'security' | 'sessions' | 'sites';
95
+ export type PortalSection = 'home' | 'identity' | 'security' | 'sessions' | 'sites';
96
96
  /** Options for building an auth.sv portal deep link (`portalUrl()`). */
97
97
  export interface PortalUrlOptions {
98
98
  /** Which portal screen to open. Defaults to `'home'`. */
@@ -7715,7 +7715,7 @@ function attachClickHandler(selector, onClick) {
7715
7715
  * @example Inline mode
7716
7716
  * const result = await sv.products.identity.verify({ target: '#auth-container' });
7717
7717
  */
7718
- const PORTAL_SECTIONS = ['home', 'contacts', 'security', 'sessions', 'sites'];
7718
+ const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
7719
7719
  function isTokenClaims(payload) {
7720
7720
  if (typeof payload !== 'object' || payload === null) {
7721
7721
  return false;
@@ -7744,8 +7744,9 @@ class IdentityModule {
7744
7744
  }
7745
7745
  /**
7746
7746
  * Build a deep link into the person's auth.sv Identity portal — where they
7747
- * manage verified contacts, passkeys, sessions, and connected sites across
7748
- * every SparkVault-integrated site. Send a signed-in user here to self-serve;
7747
+ * manage their verified identity, passkeys, sessions, and connected sites
7748
+ * across every SparkVault-integrated site. Send a signed-in user here to
7749
+ * self-serve;
7749
7750
  * the portal authenticates them with their own SparkVault Identity.
7750
7751
  *
7751
7752
  * @example Manage this site (block/notifications/etc.)
@@ -7933,13 +7934,19 @@ class IdentityModule {
7933
7934
  return cleanup;
7934
7935
  }
7935
7936
  /**
7936
- * Verify and decode an identity token.
7937
- * Validates the token structure, expiry, and issuer.
7937
+ * Decode an identity token's claims WITHOUT verifying its signature.
7938
7938
  *
7939
- * Note: For production use, verify the Ed25519 signature server-side
7940
- * using the JWKS endpoint.
7939
+ * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
7940
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
7941
+ * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
7942
+ * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
7943
+ * result MUST NOT be trusted for any authorization decision.
7944
+ *
7945
+ * To trust a token (e.g. before keying records by `claims.svid`), verify the
7946
+ * Ed25519 signature server-side against the Identity JWKS endpoint
7947
+ * (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
7941
7948
  */
7942
- async verifyToken(token) {
7949
+ decodeToken(token) {
7943
7950
  if (!token || typeof token !== 'string') {
7944
7951
  throw new ValidationError('Token is required');
7945
7952
  }
@@ -7947,7 +7954,17 @@ class IdentityModule {
7947
7954
  if (parts.length !== 3) {
7948
7955
  throw new ValidationError('Invalid token format');
7949
7956
  }
7950
- const [, payloadB64] = parts;
7957
+ const [headerB64, payloadB64] = parts;
7958
+ const header = JSON.parse(base64urlToString(headerB64));
7959
+ if (typeof header !== 'object' || header === null) {
7960
+ throw new ValidationError('Invalid token header');
7961
+ }
7962
+ // Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
7963
+ // tokens are Ed25519-signed; anything else is an unsigned or algorithm-
7964
+ // confused token that could never pass server-side JWKS verification.
7965
+ if (header.alg !== 'EdDSA') {
7966
+ throw new ValidationError('Unsupported token algorithm');
7967
+ }
7951
7968
  const payload = JSON.parse(base64urlToString(payloadB64));
7952
7969
  if (!isTokenClaims(payload)) {
7953
7970
  throw new ValidationError('Invalid token payload structure');
@@ -7960,13 +7977,18 @@ class IdentityModule {
7960
7977
  if (payload.iss !== expectedIssuer) {
7961
7978
  throw new ValidationError('Invalid token issuer');
7962
7979
  }
7980
+ if (payload.aud !== this.config.accountId) {
7981
+ throw new ValidationError('Invalid token audience');
7982
+ }
7963
7983
  return payload;
7964
7984
  }
7965
7985
  /**
7966
7986
  * Complete full-page redirect results produced by social-login flows.
7967
7987
  * The Identity Product redirects back with `#token=...` so the token does
7968
- * not hit server logs. Consume it once, validate the issuer/expiry shape,
7969
- * then remove it from the URL bar.
7988
+ * not hit server logs. Consume it once, run the unverified client-side decode
7989
+ * (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
7990
+ * remove it from the URL bar. The host must still verify the token server-side
7991
+ * via the Identity JWKS before trusting any claim.
7970
7992
  */
7971
7993
  async consumeRedirectResult() {
7972
7994
  if (typeof window === 'undefined' || !window.location.hash) {
@@ -7993,7 +8015,11 @@ class IdentityModule {
7993
8015
  if (expectedState && params.get('state') !== expectedState) {
7994
8016
  throw new ValidationError('Invalid OAuth state');
7995
8017
  }
7996
- const claims = await this.verifyToken(token);
8018
+ // Unverified client-side decode — surfaces the claims for the result
8019
+ // shape and rejects an obviously-bad token (expiry/issuer/audience/alg).
8020
+ // The host MUST still verify result.token server-side via the Identity
8021
+ // JWKS before trusting any claim for an authorization decision.
8022
+ const claims = this.decodeToken(token);
7997
8023
  return {
7998
8024
  token,
7999
8025
  identity: claims.identity,