@sparkvault/sdk-js 1.27.3 → 1.27.5
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/README.md +6 -6
- package/dist/identity/api.d.ts +1 -1
- package/dist/sparkvault.cjs.js +83 -11
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +83 -11
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -276,12 +276,12 @@ Authentication methods are configured in your Identity Product settings. The SDK
|
|
|
276
276
|
| `totp_sms` | 6-digit code sent via SMS | Phone |
|
|
277
277
|
| `totp_voice` | 6-digit code sent via voice call | Phone |
|
|
278
278
|
| `sparklink` | One-click sign-in link via email | Email |
|
|
279
|
-
| `social_google` | Sign in with Google |
|
|
280
|
-
| `social_apple` | Sign in with Apple |
|
|
281
|
-
| `social_microsoft` | Sign in with Microsoft |
|
|
282
|
-
| `social_github` | Sign in with GitHub |
|
|
283
|
-
| `social_facebook` | Sign in with Facebook |
|
|
284
|
-
| `social_linkedin` | Sign in with LinkedIn |
|
|
279
|
+
| `social_google` | Sign in with Google | Social account |
|
|
280
|
+
| `social_apple` | Sign in with Apple | Social account |
|
|
281
|
+
| `social_microsoft` | Sign in with Microsoft | Social account |
|
|
282
|
+
| `social_github` | Sign in with GitHub | Social account |
|
|
283
|
+
| `social_facebook` | Sign in with Facebook | Social account |
|
|
284
|
+
| `social_linkedin` | Sign in with LinkedIn | Social account |
|
|
285
285
|
|
|
286
286
|
## Backend Token Verification
|
|
287
287
|
|
package/dist/identity/api.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
97
97
|
/**
|
|
98
98
|
* Get OAuth redirect URL for social provider
|
|
99
99
|
*/
|
|
100
|
-
getSocialAuthUrl(provider: string, redirectUri: string, state: string): string;
|
|
100
|
+
getSocialAuthUrl(provider: string, redirectUri: string, state: string, authContext?: AuthContext): string;
|
|
101
101
|
/**
|
|
102
102
|
* Send SparkLink email for identity verification.
|
|
103
103
|
* Includes connectionId for WebSocket push notification of verification result.
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -65,14 +65,72 @@ class PopupBlockedError extends SparkVaultError {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* SparkVault-owned domain registry.
|
|
70
|
+
*
|
|
71
|
+
* Keep platform domain decisions centralized: CSP, redirect safety, custom
|
|
72
|
+
* domain reservation, and Identity postMessage trust all depend on the same
|
|
73
|
+
* ownership boundary.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
const SPARKVAULT_ROOT_DOMAIN = 'sparkvault.com';
|
|
77
|
+
|
|
78
|
+
const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
|
|
79
|
+
'auth.sv',
|
|
80
|
+
'x.sv',
|
|
81
|
+
'files.sv',
|
|
82
|
+
'file.sv',
|
|
83
|
+
'send.sv',
|
|
84
|
+
'spark.sv',
|
|
85
|
+
'by.sv',
|
|
86
|
+
'at.sv',
|
|
87
|
+
'db.sv'
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
const SPARKVAULT_WEBSOCKET_HOSTS = Object.freeze([
|
|
91
|
+
'ws.sparkvault.com'
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
Object.freeze([
|
|
95
|
+
SPARKVAULT_ROOT_DOMAIN,
|
|
96
|
+
'app.sparkvault.com',
|
|
97
|
+
'api.sparkvault.com',
|
|
98
|
+
'cdn.sparkvault.com',
|
|
99
|
+
'forge.sparkvault.com',
|
|
100
|
+
'img.sparkvault.com',
|
|
101
|
+
...SPARKVAULT_WEBSOCKET_HOSTS,
|
|
102
|
+
...SPARKVAULT_PLATFORM_SV_HOSTS
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
function normalizeHostname(hostname) {
|
|
106
|
+
if (typeof hostname !== 'string') return '';
|
|
107
|
+
return hostname.trim().toLowerCase().replace(/\.$/, '');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isSparkVaultRootOrSubdomain(hostname) {
|
|
111
|
+
const normalized = normalizeHostname(hostname);
|
|
112
|
+
return normalized === SPARKVAULT_ROOT_DOMAIN || normalized.endsWith(`.${SPARKVAULT_ROOT_DOMAIN}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isSparkVaultPlatformSvHost(hostname) {
|
|
116
|
+
return SPARKVAULT_PLATFORM_SV_HOSTS.includes(normalizeHostname(hostname));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isSparkVaultOwnedHostname(hostname) {
|
|
120
|
+
return isSparkVaultRootOrSubdomain(hostname) || isSparkVaultPlatformSvHost(hostname);
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
/**
|
|
69
124
|
* SparkVault SDK Configuration
|
|
70
125
|
*/
|
|
126
|
+
function escapeRegExp(value) {
|
|
127
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
128
|
+
}
|
|
129
|
+
const SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN = new RegExp(`(^|\\.)(${SPARKVAULT_PLATFORM_SV_HOSTS.map(escapeRegExp).join('|')})$`, 'i');
|
|
71
130
|
// Hosts that are allowed to serve backend-issued ingot download URLs.
|
|
72
|
-
// Keep in sync with the sdk-mobile default in packages/sdk-mobile/src/config.ts.
|
|
73
131
|
const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
|
|
74
|
-
|
|
75
|
-
|
|
132
|
+
new RegExp(`(^|\\.)${escapeRegExp(SPARKVAULT_ROOT_DOMAIN)}$`, 'i'),
|
|
133
|
+
SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN,
|
|
76
134
|
/\.amazonaws\.com$/i,
|
|
77
135
|
/\.cloudfront\.net$/i,
|
|
78
136
|
];
|
|
@@ -1106,11 +1164,24 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1106
1164
|
/**
|
|
1107
1165
|
* Get OAuth redirect URL for social provider
|
|
1108
1166
|
*/
|
|
1109
|
-
getSocialAuthUrl(provider, redirectUri, state) {
|
|
1167
|
+
getSocialAuthUrl(provider, redirectUri, state, authContext) {
|
|
1110
1168
|
const params = new URLSearchParams({
|
|
1111
1169
|
redirect_uri: redirectUri,
|
|
1112
1170
|
state,
|
|
1113
1171
|
});
|
|
1172
|
+
if (authContext?.authRequestId) {
|
|
1173
|
+
params.set('auth_request_id', authContext.authRequestId);
|
|
1174
|
+
}
|
|
1175
|
+
if (authContext?.simpleMode) {
|
|
1176
|
+
const simpleMode = authContext.simpleMode.sessionId
|
|
1177
|
+
? { session_id: authContext.simpleMode.sessionId }
|
|
1178
|
+
: {
|
|
1179
|
+
success_url: authContext.simpleMode.successUrl,
|
|
1180
|
+
failure_url: authContext.simpleMode.failureUrl,
|
|
1181
|
+
state: authContext.simpleMode.state,
|
|
1182
|
+
};
|
|
1183
|
+
params.set('simple_mode', JSON.stringify(simpleMode));
|
|
1184
|
+
}
|
|
1114
1185
|
return `${this.baseUrl}/social/${provider}?${params}`;
|
|
1115
1186
|
}
|
|
1116
1187
|
/**
|
|
@@ -1624,12 +1695,7 @@ class PasskeyHandler {
|
|
|
1624
1695
|
isValidMessageOrigin(origin) {
|
|
1625
1696
|
try {
|
|
1626
1697
|
const url = new URL(origin);
|
|
1627
|
-
|
|
1628
|
-
// Allow sparkvault.com and subdomains
|
|
1629
|
-
if (hostname === 'sparkvault.com' || hostname.endsWith('.sparkvault.com')) {
|
|
1630
|
-
return true;
|
|
1631
|
-
}
|
|
1632
|
-
return false;
|
|
1698
|
+
return url.protocol === 'https:' && url.origin === origin && !url.port && isSparkVaultOwnedHostname(url.hostname);
|
|
1633
1699
|
}
|
|
1634
1700
|
catch {
|
|
1635
1701
|
return false;
|
|
@@ -5883,7 +5949,7 @@ class IdentityRenderer {
|
|
|
5883
5949
|
const redirectUri = window.location.origin + window.location.pathname;
|
|
5884
5950
|
sessionStorage.setItem('sv_oauth_state', state);
|
|
5885
5951
|
sessionStorage.setItem('sv_oauth_email', this.recipient);
|
|
5886
|
-
const authUrl = this.api.getSocialAuthUrl(provider, redirectUri, state);
|
|
5952
|
+
const authUrl = this.api.getSocialAuthUrl(provider, redirectUri, state, this.verificationState.authContext);
|
|
5887
5953
|
window.location.href = authUrl;
|
|
5888
5954
|
}
|
|
5889
5955
|
normalizeError(error) {
|
|
@@ -6723,6 +6789,10 @@ class IdentityModule {
|
|
|
6723
6789
|
if (!token) {
|
|
6724
6790
|
return null;
|
|
6725
6791
|
}
|
|
6792
|
+
const expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
6793
|
+
if (expectedState && params.get('state') !== expectedState) {
|
|
6794
|
+
throw new ValidationError('Invalid OAuth state');
|
|
6795
|
+
}
|
|
6726
6796
|
const claims = await this.verifyToken(token);
|
|
6727
6797
|
const result = {
|
|
6728
6798
|
token,
|
|
@@ -6734,6 +6804,8 @@ class IdentityModule {
|
|
|
6734
6804
|
if (typeof window.history?.replaceState === 'function') {
|
|
6735
6805
|
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
6736
6806
|
}
|
|
6807
|
+
sessionStorage.removeItem('sv_oauth_state');
|
|
6808
|
+
sessionStorage.removeItem('sv_oauth_email');
|
|
6737
6809
|
return result;
|
|
6738
6810
|
}
|
|
6739
6811
|
/**
|