@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 +19 -10
- package/dist/products/identity/index.d.ts +18 -9
- package/dist/products/identity/types.d.ts +1 -1
- package/dist/sparkvault.cjs.js +38 -12
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +38 -12
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.esm.js
CHANGED
|
@@ -7711,7 +7711,7 @@ function attachClickHandler(selector, onClick) {
|
|
|
7711
7711
|
* @example Inline mode
|
|
7712
7712
|
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
7713
7713
|
*/
|
|
7714
|
-
const PORTAL_SECTIONS = ['home', '
|
|
7714
|
+
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
7715
7715
|
function isTokenClaims(payload) {
|
|
7716
7716
|
if (typeof payload !== 'object' || payload === null) {
|
|
7717
7717
|
return false;
|
|
@@ -7740,8 +7740,9 @@ class IdentityModule {
|
|
|
7740
7740
|
}
|
|
7741
7741
|
/**
|
|
7742
7742
|
* Build a deep link into the person's auth.sv Identity portal — where they
|
|
7743
|
-
* manage verified
|
|
7744
|
-
* every SparkVault-integrated site. Send a signed-in user here to
|
|
7743
|
+
* manage their verified identity, passkeys, sessions, and connected sites
|
|
7744
|
+
* across every SparkVault-integrated site. Send a signed-in user here to
|
|
7745
|
+
* self-serve;
|
|
7745
7746
|
* the portal authenticates them with their own SparkVault Identity.
|
|
7746
7747
|
*
|
|
7747
7748
|
* @example Manage this site (block/notifications/etc.)
|
|
@@ -7929,13 +7930,19 @@ class IdentityModule {
|
|
|
7929
7930
|
return cleanup;
|
|
7930
7931
|
}
|
|
7931
7932
|
/**
|
|
7932
|
-
*
|
|
7933
|
-
* Validates the token structure, expiry, and issuer.
|
|
7933
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
7934
7934
|
*
|
|
7935
|
-
*
|
|
7936
|
-
*
|
|
7935
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
7936
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
7937
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
7938
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
7939
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
7940
|
+
*
|
|
7941
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
7942
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
7943
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
7937
7944
|
*/
|
|
7938
|
-
|
|
7945
|
+
decodeToken(token) {
|
|
7939
7946
|
if (!token || typeof token !== 'string') {
|
|
7940
7947
|
throw new ValidationError('Token is required');
|
|
7941
7948
|
}
|
|
@@ -7943,7 +7950,17 @@ class IdentityModule {
|
|
|
7943
7950
|
if (parts.length !== 3) {
|
|
7944
7951
|
throw new ValidationError('Invalid token format');
|
|
7945
7952
|
}
|
|
7946
|
-
const [, payloadB64] = parts;
|
|
7953
|
+
const [headerB64, payloadB64] = parts;
|
|
7954
|
+
const header = JSON.parse(base64urlToString(headerB64));
|
|
7955
|
+
if (typeof header !== 'object' || header === null) {
|
|
7956
|
+
throw new ValidationError('Invalid token header');
|
|
7957
|
+
}
|
|
7958
|
+
// Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
|
|
7959
|
+
// tokens are Ed25519-signed; anything else is an unsigned or algorithm-
|
|
7960
|
+
// confused token that could never pass server-side JWKS verification.
|
|
7961
|
+
if (header.alg !== 'EdDSA') {
|
|
7962
|
+
throw new ValidationError('Unsupported token algorithm');
|
|
7963
|
+
}
|
|
7947
7964
|
const payload = JSON.parse(base64urlToString(payloadB64));
|
|
7948
7965
|
if (!isTokenClaims(payload)) {
|
|
7949
7966
|
throw new ValidationError('Invalid token payload structure');
|
|
@@ -7956,13 +7973,18 @@ class IdentityModule {
|
|
|
7956
7973
|
if (payload.iss !== expectedIssuer) {
|
|
7957
7974
|
throw new ValidationError('Invalid token issuer');
|
|
7958
7975
|
}
|
|
7976
|
+
if (payload.aud !== this.config.accountId) {
|
|
7977
|
+
throw new ValidationError('Invalid token audience');
|
|
7978
|
+
}
|
|
7959
7979
|
return payload;
|
|
7960
7980
|
}
|
|
7961
7981
|
/**
|
|
7962
7982
|
* Complete full-page redirect results produced by social-login flows.
|
|
7963
7983
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
7964
|
-
* not hit server logs. Consume it once,
|
|
7965
|
-
*
|
|
7984
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
7985
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
7986
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
7987
|
+
* via the Identity JWKS before trusting any claim.
|
|
7966
7988
|
*/
|
|
7967
7989
|
async consumeRedirectResult() {
|
|
7968
7990
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
@@ -7989,7 +8011,11 @@ class IdentityModule {
|
|
|
7989
8011
|
if (expectedState && params.get('state') !== expectedState) {
|
|
7990
8012
|
throw new ValidationError('Invalid OAuth state');
|
|
7991
8013
|
}
|
|
7992
|
-
|
|
8014
|
+
// Unverified client-side decode — surfaces the claims for the result
|
|
8015
|
+
// shape and rejects an obviously-bad token (expiry/issuer/audience/alg).
|
|
8016
|
+
// The host MUST still verify result.token server-side via the Identity
|
|
8017
|
+
// JWKS before trusting any claim for an authorization decision.
|
|
8018
|
+
const claims = this.decodeToken(token);
|
|
7993
8019
|
return {
|
|
7994
8020
|
token,
|
|
7995
8021
|
identity: claims.identity,
|