@vouchington/utils 0.7.5 → 0.9.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 (37) hide show
  1. package/README.md +30 -0
  2. package/dist/error-tree.d.mts +8 -0
  3. package/dist/error-tree.mjs +94 -0
  4. package/dist/feature-flags.d.mts +1 -1
  5. package/dist/job-data-scrub.d.mts +21 -0
  6. package/dist/job-data-scrub.mjs +83 -0
  7. package/dist/oauth-pkce.d.mts +6 -0
  8. package/dist/oauth-pkce.mjs +19 -0
  9. package/dist/oauth-popup.d.mts +80 -0
  10. package/dist/oauth-popup.mjs +106 -0
  11. package/dist/oauth-providers-core.d.mts +44 -0
  12. package/dist/oauth-providers-core.mjs +88 -0
  13. package/dist/oauth-providers-facebook.d.mts +11 -0
  14. package/dist/oauth-providers-facebook.mjs +34 -0
  15. package/dist/oauth-providers-github.d.mts +7 -0
  16. package/dist/oauth-providers-github.mjs +46 -0
  17. package/dist/oauth-providers-google.d.mts +7 -0
  18. package/dist/oauth-providers-google.mjs +43 -0
  19. package/dist/oauth-providers-linkedin.d.mts +7 -0
  20. package/dist/oauth-providers-linkedin.mjs +42 -0
  21. package/dist/oauth-providers-microsoft.d.mts +11 -0
  22. package/dist/oauth-providers-microsoft.mjs +76 -0
  23. package/dist/oauth-providers-x.d.mts +7 -0
  24. package/dist/oauth-providers-x.mjs +41 -0
  25. package/dist/oauth-providers.d.mts +8 -0
  26. package/dist/oauth-providers.mjs +7 -0
  27. package/dist/oauth-types.d.mts +8 -0
  28. package/dist/oauth-types.mjs +1 -0
  29. package/dist/oidc-id-token-profiles.d.mts +23 -0
  30. package/dist/oidc-id-token-profiles.mjs +42 -0
  31. package/dist/oidc-id-token-util.d.mts +6 -0
  32. package/dist/oidc-id-token-util.mjs +18 -0
  33. package/dist/oidc-id-token.d.mts +33 -0
  34. package/dist/oidc-id-token.mjs +141 -0
  35. package/package.json +31 -1
  36. package/dist/http-signatures-test-helpers.d.mts +0 -30
  37. package/dist/http-signatures-test-helpers.mjs +0 -62
@@ -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
- }