@vouchington/utils 0.7.5 → 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.
- package/README.md +24 -0
- package/dist/error-tree.d.mts +8 -0
- package/dist/error-tree.mjs +94 -0
- package/dist/job-data-scrub.d.mts +21 -0
- package/dist/job-data-scrub.mjs +83 -0
- package/dist/oauth-pkce.d.mts +6 -0
- package/dist/oauth-pkce.mjs +19 -0
- package/dist/oauth-popup.d.mts +80 -0
- package/dist/oauth-popup.mjs +106 -0
- package/dist/oauth-providers-core.d.mts +44 -0
- package/dist/oauth-providers-core.mjs +88 -0
- package/dist/oauth-providers-facebook.d.mts +9 -0
- package/dist/oauth-providers-facebook.mjs +27 -0
- package/dist/oauth-providers-github.d.mts +7 -0
- package/dist/oauth-providers-github.mjs +46 -0
- package/dist/oauth-providers-google.d.mts +7 -0
- package/dist/oauth-providers-google.mjs +43 -0
- package/dist/oauth-providers-linkedin.d.mts +7 -0
- package/dist/oauth-providers-linkedin.mjs +42 -0
- package/dist/oauth-providers-microsoft.d.mts +14 -0
- package/dist/oauth-providers-microsoft.mjs +43 -0
- package/dist/oauth-providers-x.d.mts +7 -0
- package/dist/oauth-providers-x.mjs +41 -0
- package/dist/oauth-providers.d.mts +8 -0
- package/dist/oauth-providers.mjs +7 -0
- package/dist/oauth-types.d.mts +8 -0
- package/dist/oauth-types.mjs +1 -0
- package/dist/oidc-id-token-profiles.d.mts +21 -0
- package/dist/oidc-id-token-profiles.mjs +28 -0
- package/dist/oidc-id-token-util.d.mts +6 -0
- package/dist/oidc-id-token-util.mjs +18 -0
- package/dist/oidc-id-token.d.mts +31 -0
- package/dist/oidc-id-token.mjs +141 -0
- package/package.json +31 -1
- package/dist/http-signatures-test-helpers.d.mts +0 -30
- package/dist/http-signatures-test-helpers.mjs +0 -62
|
@@ -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
|
-
}
|