@sd-jwt/sd-jwt-vc 0.9.2-next.1 → 0.9.2-next.3

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 CHANGED
@@ -97,7 +97,7 @@ const sdjwt = new SDJwtVcInstance({
97
97
  signAlg: 'EdDSA',
98
98
  verifier,
99
99
  hasher: digest,
100
- hashAlg: 'SHA-256',
100
+ hashAlg: 'sha-256',
101
101
  saltGenerator: generateSalt,
102
102
  loadTypeMetadataFormat: true,
103
103
  });
package/dist/index.d.mts CHANGED
@@ -27,6 +27,7 @@ type SDJWTVCConfig = SDJWTConfig & {
27
27
  statusValidator?: StatusValidator;
28
28
  vctFetcher?: VcTFetcher;
29
29
  loadTypeMetadataFormat?: boolean;
30
+ timeout?: number;
30
31
  };
31
32
 
32
33
  interface SDJWTVCStatusReference {
package/dist/index.d.ts CHANGED
@@ -27,6 +27,7 @@ type SDJWTVCConfig = SDJWTConfig & {
27
27
  statusValidator?: StatusValidator;
28
28
  vctFetcher?: VcTFetcher;
29
29
  loadTypeMetadataFormat?: boolean;
30
+ timeout?: number;
30
31
  };
31
32
 
32
33
  interface SDJWTVCStatusReference {
package/dist/index.js CHANGED
@@ -178,17 +178,29 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
178
178
  */
179
179
  fetch(url, integrity) {
180
180
  return __async(this, null, function* () {
181
+ var _a;
181
182
  const controller = new AbortController();
182
- const timeoutId = setTimeout(() => controller.abort(), 1e4);
183
+ const timeoutId = setTimeout(
184
+ () => controller.abort(),
185
+ (_a = this.userConfig.timeout) != null ? _a : 1e4
186
+ );
183
187
  try {
184
188
  const response = yield fetch(url, {
185
189
  signal: controller.signal
186
190
  });
187
191
  if (!response.ok) {
188
- throw new Error(yield response.text());
192
+ const errorText = yield response.text();
193
+ throw new Error(
194
+ `Error fetching ${url}: ${response.status} ${response.statusText} - ${errorText}`
195
+ );
189
196
  }
190
197
  yield this.validateIntegrity(response.clone(), url, integrity);
191
198
  return response.json();
199
+ } catch (error) {
200
+ if (error instanceof DOMException && error.name === "AbortError") {
201
+ throw new Error(`Request to ${url} timed out`);
202
+ }
203
+ throw error;
192
204
  } finally {
193
205
  clearTimeout(timeoutId);
194
206
  }
package/dist/index.mjs CHANGED
@@ -146,17 +146,29 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
146
146
  */
147
147
  fetch(url, integrity) {
148
148
  return __async(this, null, function* () {
149
+ var _a;
149
150
  const controller = new AbortController();
150
- const timeoutId = setTimeout(() => controller.abort(), 1e4);
151
+ const timeoutId = setTimeout(
152
+ () => controller.abort(),
153
+ (_a = this.userConfig.timeout) != null ? _a : 1e4
154
+ );
151
155
  try {
152
156
  const response = yield fetch(url, {
153
157
  signal: controller.signal
154
158
  });
155
159
  if (!response.ok) {
156
- throw new Error(yield response.text());
160
+ const errorText = yield response.text();
161
+ throw new Error(
162
+ `Error fetching ${url}: ${response.status} ${response.statusText} - ${errorText}`
163
+ );
157
164
  }
158
165
  yield this.validateIntegrity(response.clone(), url, integrity);
159
166
  return response.json();
167
+ } catch (error) {
168
+ if (error instanceof DOMException && error.name === "AbortError") {
169
+ throw new Error(`Request to ${url} timed out`);
170
+ }
171
+ throw error;
160
172
  } finally {
161
173
  clearTimeout(timeoutId);
162
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/sd-jwt-vc",
3
- "version": "0.9.2-next.1+d6f70c3",
3
+ "version": "0.9.2-next.3+06e3319",
4
4
  "description": "sd-jwt draft 7 implementation in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -39,15 +39,15 @@
39
39
  },
40
40
  "license": "Apache-2.0",
41
41
  "dependencies": {
42
- "@sd-jwt/core": "0.9.2-next.1+d6f70c3",
43
- "@sd-jwt/jwt-status-list": "0.9.2-next.1+d6f70c3",
44
- "@sd-jwt/utils": "0.9.2-next.1+d6f70c3",
42
+ "@sd-jwt/core": "0.9.2-next.3+06e3319",
43
+ "@sd-jwt/jwt-status-list": "0.9.2-next.3+06e3319",
44
+ "@sd-jwt/utils": "0.9.2-next.3+06e3319",
45
45
  "ajv": "^8.17.1",
46
46
  "ajv-formats": "^3.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@sd-jwt/crypto-nodejs": "0.9.2-next.1+d6f70c3",
50
- "@sd-jwt/types": "0.9.2-next.1+d6f70c3",
49
+ "@sd-jwt/crypto-nodejs": "0.9.2-next.3+06e3319",
50
+ "@sd-jwt/types": "0.9.2-next.3+06e3319",
51
51
  "jose": "^5.2.2",
52
52
  "msw": "^2.3.5"
53
53
  },
@@ -67,5 +67,5 @@
67
67
  "esm"
68
68
  ]
69
69
  },
70
- "gitHead": "d6f70c37efaafe5123b7ffd1115069ba6e0e4e6e"
70
+ "gitHead": "06e3319e4293845cd830fbe41d3607fee4e493f8"
71
71
  }
@@ -16,4 +16,6 @@ export type SDJWTVCConfig = SDJWTConfig & {
16
16
  vctFetcher?: VcTFetcher;
17
17
  // if set to true, it will load the metadata format based on the vct value. If not provided, it will default to false.
18
18
  loadTypeMetadataFormat?: boolean;
19
+ // timeout value in milliseconds when to abort the fetch request. If not provided, it will default to 10000.
20
+ timeout?: number;
19
21
  };
@@ -166,18 +166,31 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
166
166
  * @param url
167
167
  * @returns
168
168
  */
169
- private async fetch<T>(url: string, integrity?: string) {
169
+ private async fetch<T>(url: string, integrity?: string): Promise<T> {
170
170
  const controller = new AbortController();
171
- const timeoutId = setTimeout(() => controller.abort(), 10000);
171
+ const timeoutId = setTimeout(
172
+ () => controller.abort(),
173
+ this.userConfig.timeout ?? 10000,
174
+ );
175
+
172
176
  try {
173
177
  const response = await fetch(url, {
174
178
  signal: controller.signal,
175
179
  });
180
+
176
181
  if (!response.ok) {
177
- throw new Error(await response.text());
182
+ const errorText = await response.text();
183
+ throw new Error(
184
+ `Error fetching ${url}: ${response.status} ${response.statusText} - ${errorText}`,
185
+ );
178
186
  }
179
187
  await this.validateIntegrity(response.clone(), url, integrity);
180
188
  return response.json() as Promise<T>;
189
+ } catch (error) {
190
+ if (error instanceof DOMException && error.name === 'AbortError') {
191
+ throw new Error(`Request to ${url} timed out`);
192
+ }
193
+ throw error;
181
194
  } finally {
182
195
  clearTimeout(timeoutId);
183
196
  }
@@ -67,7 +67,7 @@ describe('App', () => {
67
67
  signAlg: 'EdDSA',
68
68
  verifier,
69
69
  hasher: digest,
70
- hashAlg: 'SHA-256',
70
+ hashAlg: 'sha-256',
71
71
  saltGenerator: generateSalt,
72
72
  });
73
73
 
@@ -94,7 +94,7 @@ describe('Revocation', () => {
94
94
  signAlg: 'EdDSA',
95
95
  verifier,
96
96
  hasher: digest,
97
- hashAlg: 'SHA-256',
97
+ hashAlg: 'sha-256',
98
98
  saltGenerator: generateSalt,
99
99
  statusListFetcher(uri: string) {
100
100
  // we emulate fetching the status list from the uri. Validation of the JWT is not done here in the test but should be done in the implementation.
@@ -97,7 +97,7 @@ describe('App', () => {
97
97
  signAlg: 'EdDSA',
98
98
  verifier,
99
99
  hasher: digest,
100
- hashAlg: 'SHA-256',
100
+ hashAlg: 'sha-256',
101
101
  saltGenerator: generateSalt,
102
102
  loadTypeMetadataFormat: true,
103
103
  });
@@ -40,7 +40,7 @@ describe('App', () => {
40
40
  signAlg: 'EdDSA',
41
41
  verifier,
42
42
  hasher: digest,
43
- hashAlg: 'SHA-256',
43
+ hashAlg: 'sha-256',
44
44
  saltGenerator: generateSalt,
45
45
  });
46
46
 
@@ -222,7 +222,7 @@ async function JSONtest(filename: string) {
222
222
  signAlg: 'EdDSA',
223
223
  verifier,
224
224
  hasher: digest,
225
- hashAlg: 'SHA-256',
225
+ hashAlg: 'sha-256',
226
226
  saltGenerator: generateSalt,
227
227
  });
228
228