@vouchington/utils 0.7.4 → 0.8.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 (38) hide show
  1. package/README.md +28 -0
  2. package/dist/error-tree.d.mts +8 -0
  3. package/dist/error-tree.mjs +94 -0
  4. package/dist/job-data-scrub.d.mts +21 -0
  5. package/dist/job-data-scrub.mjs +83 -0
  6. package/dist/oauth-pkce.d.mts +6 -0
  7. package/dist/oauth-pkce.mjs +19 -0
  8. package/dist/oauth-popup.d.mts +80 -0
  9. package/dist/oauth-popup.mjs +106 -0
  10. package/dist/oauth-providers-core.d.mts +44 -0
  11. package/dist/oauth-providers-core.mjs +88 -0
  12. package/dist/oauth-providers-facebook.d.mts +9 -0
  13. package/dist/oauth-providers-facebook.mjs +27 -0
  14. package/dist/oauth-providers-github.d.mts +7 -0
  15. package/dist/oauth-providers-github.mjs +46 -0
  16. package/dist/oauth-providers-google.d.mts +7 -0
  17. package/dist/oauth-providers-google.mjs +43 -0
  18. package/dist/oauth-providers-linkedin.d.mts +7 -0
  19. package/dist/oauth-providers-linkedin.mjs +42 -0
  20. package/dist/oauth-providers-microsoft.d.mts +14 -0
  21. package/dist/oauth-providers-microsoft.mjs +43 -0
  22. package/dist/oauth-providers-x.d.mts +7 -0
  23. package/dist/oauth-providers-x.mjs +41 -0
  24. package/dist/oauth-providers.d.mts +8 -0
  25. package/dist/oauth-providers.mjs +7 -0
  26. package/dist/oauth-types.d.mts +8 -0
  27. package/dist/oauth-types.mjs +1 -0
  28. package/dist/oidc-id-token-profiles.d.mts +21 -0
  29. package/dist/oidc-id-token-profiles.mjs +28 -0
  30. package/dist/oidc-id-token-util.d.mts +6 -0
  31. package/dist/oidc-id-token-util.mjs +18 -0
  32. package/dist/oidc-id-token.d.mts +31 -0
  33. package/dist/oidc-id-token.mjs +141 -0
  34. package/dist/service-worker-activation.d.mts +26 -0
  35. package/dist/service-worker-activation.mjs +50 -0
  36. package/package.json +36 -1
  37. package/dist/http-signatures-test-helpers.d.mts +0 -30
  38. package/dist/http-signatures-test-helpers.mjs +0 -62
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchington/utils",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Dependency-free runtime utilities for Vouchington-style applications.",
5
5
  "homepage": "https://github.com/vouchington/vouchington-platform/tree/main/packages/utils#readme",
6
6
  "bugs": {
@@ -65,6 +65,11 @@
65
65
  "import": "./dist/web-push-binding.mjs",
66
66
  "default": "./dist/web-push-binding.mjs"
67
67
  },
68
+ "./service-worker-activation": {
69
+ "types": "./dist/service-worker-activation.d.mts",
70
+ "import": "./dist/service-worker-activation.mjs",
71
+ "default": "./dist/service-worker-activation.mjs"
72
+ },
68
73
  "./json-ld": {
69
74
  "types": "./dist/json-ld.d.mts",
70
75
  "import": "./dist/json-ld.mjs",
@@ -230,6 +235,16 @@
230
235
  "import": "./dist/observability.mjs",
231
236
  "default": "./dist/observability.mjs"
232
237
  },
238
+ "./error-tree": {
239
+ "types": "./dist/error-tree.d.mts",
240
+ "import": "./dist/error-tree.mjs",
241
+ "default": "./dist/error-tree.mjs"
242
+ },
243
+ "./job-data-scrub": {
244
+ "types": "./dist/job-data-scrub.d.mts",
245
+ "import": "./dist/job-data-scrub.mjs",
246
+ "default": "./dist/job-data-scrub.mjs"
247
+ },
233
248
  "./hashtags": {
234
249
  "types": "./dist/hashtags.d.mts",
235
250
  "import": "./dist/hashtags.mjs",
@@ -255,6 +270,26 @@
255
270
  "import": "./dist/http-link-pagination.mjs",
256
271
  "default": "./dist/http-link-pagination.mjs"
257
272
  },
273
+ "./oauth-pkce": {
274
+ "types": "./dist/oauth-pkce.d.mts",
275
+ "import": "./dist/oauth-pkce.mjs",
276
+ "default": "./dist/oauth-pkce.mjs"
277
+ },
278
+ "./oauth-popup": {
279
+ "types": "./dist/oauth-popup.d.mts",
280
+ "import": "./dist/oauth-popup.mjs",
281
+ "default": "./dist/oauth-popup.mjs"
282
+ },
283
+ "./oauth-providers": {
284
+ "types": "./dist/oauth-providers.d.mts",
285
+ "import": "./dist/oauth-providers.mjs",
286
+ "default": "./dist/oauth-providers.mjs"
287
+ },
288
+ "./oidc-id-token": {
289
+ "types": "./dist/oidc-id-token.d.mts",
290
+ "import": "./dist/oidc-id-token.mjs",
291
+ "default": "./dist/oidc-id-token.mjs"
292
+ },
258
293
  "./http-signatures": {
259
294
  "types": "./dist/http-signatures.d.mts",
260
295
  "import": "./dist/http-signatures.mjs",
@@ -1,30 +0,0 @@
1
- import type { VerifySignatureOptions } from './http-signatures-verify.mts';
2
- export declare const KEY_ID = "https://example.test/users/alice#main-key";
3
- export declare const BODY: string;
4
- export declare const FULL_HEADERS: readonly ['(request-target)', 'host', 'date', 'digest'];
5
- export declare const defaultVerifyPolicy: {
6
- readonly requiredHeaders: readonly ["(request-target)", "host", "date", "digest"];
7
- readonly allowedAlgorithms: readonly ["rsa-sha256", "hs2019"];
8
- readonly maxAgeSeconds: 3600;
9
- };
10
- export declare const defaultSignPolicy: {
11
- readonly signedHeaders: readonly ["(request-target)", "host", "date", "digest"];
12
- readonly algorithm: 'rsa-sha256';
13
- };
14
- export declare function digestAndDate(body?: string | Buffer): {
15
- digestHeader: string;
16
- dateHeader: string;
17
- };
18
- export declare function verifyArgs(publicKeyPem: string, signatureHeader: string, extras?: Partial<VerifySignatureOptions>): VerifySignatureOptions;
19
- export declare function buildManualSignature(options: {
20
- privateKeyPem: string;
21
- dateHeader: string;
22
- digestHeader: string;
23
- headerNames: readonly string[];
24
- additionalHeaders?: Record<string, string>;
25
- keyId?: string;
26
- algorithm?: string | null;
27
- method?: string;
28
- path?: string;
29
- host?: string;
30
- }): string;
@@ -1,62 +0,0 @@
1
- import { createPrivateKey, sign as cryptoSign } from 'node:crypto';
2
- import { computeDigest } from './http-signatures-digest.mjs';
3
- export const KEY_ID = 'https://example.test/users/alice#main-key';
4
- const METHOD = 'POST';
5
- const PATH = '/inbox';
6
- const HOST = 'mastodon.example';
7
- export const BODY = JSON.stringify({ type: 'Follow', object: 'https://example.test' });
8
- export const FULL_HEADERS = ['(request-target)', 'host', 'date', 'digest'];
9
- const ALLOWED_ALGORITHMS = ['rsa-sha256', 'hs2019'];
10
- const MAX_AGE_SECONDS = 3600;
11
- export const defaultVerifyPolicy = {
12
- requiredHeaders: FULL_HEADERS,
13
- allowedAlgorithms: ALLOWED_ALGORITHMS,
14
- maxAgeSeconds: MAX_AGE_SECONDS,
15
- };
16
- export const defaultSignPolicy = {
17
- signedHeaders: FULL_HEADERS,
18
- algorithm: 'rsa-sha256',
19
- };
20
- export function digestAndDate(body = BODY) {
21
- return { digestHeader: computeDigest(body), dateHeader: new Date().toUTCString() };
22
- }
23
- export function verifyArgs(publicKeyPem, signatureHeader, extras = {}) {
24
- const { digestHeader, dateHeader } = digestAndDate(extras.body ?? BODY);
25
- return {
26
- method: METHOD,
27
- path: PATH,
28
- host: HOST,
29
- body: BODY,
30
- signatureHeader,
31
- digestHeader,
32
- dateHeader,
33
- publicKeyPem,
34
- ...defaultVerifyPolicy,
35
- ...extras,
36
- };
37
- }
38
- export function buildManualSignature(options) {
39
- const headerNames = options.headerNames;
40
- const signingString = headerNames
41
- .map((name) => {
42
- if (name === '(request-target)') {
43
- return `(request-target): ${(options.method ?? METHOD).toLowerCase()} ${options.path ?? PATH}`;
44
- }
45
- if (name === 'host')
46
- return `host: ${options.host ?? HOST}`;
47
- if (name === 'date')
48
- return `date: ${options.dateHeader}`;
49
- if (name === 'digest')
50
- return `digest: ${options.digestHeader}`;
51
- return `${name}: ${options.additionalHeaders?.[name]}`;
52
- })
53
- .join('\n');
54
- const signature = cryptoSign('sha256', Buffer.from(signingString), createPrivateKey(options.privateKeyPem)).toString('base64');
55
- const headerParts = [`keyId="${options.keyId ?? KEY_ID}"`];
56
- if (options.algorithm !== null) {
57
- headerParts.push(`algorithm="${options.algorithm ?? 'rsa-sha256'}"`);
58
- }
59
- headerParts.push(`headers="${headerNames.join(' ')}"`);
60
- headerParts.push(`signature="${signature}"`);
61
- return headerParts.join(',');
62
- }