@suveren/gateway 0.7.6 → 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 (161) hide show
  1. package/content/integrations/mollie.json +103 -28
  2. package/dist/mcp-server/http.mjs +228 -118
  3. package/dist/ui/assets/{index-CsrM6RQr.js → index-BFnSVa9N.js} +22 -22
  4. package/dist/ui/index.html +1 -1
  5. package/node_modules/@hap/core/dist/index.d.mts +29 -6
  6. package/node_modules/@hap/core/dist/index.d.ts +29 -6
  7. package/node_modules/@hap/core/dist/index.js +54 -8
  8. package/node_modules/@hap/core/dist/index.mjs +53 -8
  9. package/node_modules/@hap/core/package.json +2 -1
  10. package/node_modules/@hap/core/src/frame.ts +115 -14
  11. package/node_modules/@hap/core/src/gatekeeper.ts +26 -0
  12. package/node_modules/@hap/core/src/types.ts +7 -1
  13. package/node_modules/@types/node/README.md +1 -1
  14. package/node_modules/@types/node/buffer.buffer.d.ts +5 -0
  15. package/node_modules/@types/node/crypto.d.ts +0 -2
  16. package/node_modules/@types/node/dgram.d.ts +119 -4
  17. package/node_modules/@types/node/ffi.d.ts +1 -1
  18. package/node_modules/@types/node/fs/promises.d.ts +61 -65
  19. package/node_modules/@types/node/fs.d.ts +86 -76
  20. package/node_modules/@types/node/http.d.ts +1 -1
  21. package/node_modules/@types/node/http2.d.ts +2 -2
  22. package/node_modules/@types/node/index.d.ts +1 -0
  23. package/node_modules/@types/node/inspector.d.ts +2 -1
  24. package/node_modules/@types/node/net.d.ts +108 -16
  25. package/node_modules/@types/node/package.json +2 -2
  26. package/node_modules/@types/node/quic.d.ts +37 -11
  27. package/node_modules/@types/node/stream/iter.d.ts +4 -4
  28. package/node_modules/@types/node/tls.d.ts +24 -0
  29. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +5 -0
  30. package/node_modules/@types/node/ts5.6/index.d.ts +1 -0
  31. package/node_modules/@types/node/ts5.7/index.d.ts +1 -0
  32. package/node_modules/@types/node/tty.d.ts +4 -3
  33. package/node_modules/@types/node/vfs.d.ts +210 -0
  34. package/node_modules/@types/node/vm.d.ts +1 -1
  35. package/node_modules/express-rate-limit/dist/index.cjs +6 -3
  36. package/node_modules/express-rate-limit/dist/index.d.cts +11 -0
  37. package/node_modules/express-rate-limit/dist/index.d.mts +11 -0
  38. package/node_modules/express-rate-limit/dist/index.d.ts +11 -0
  39. package/node_modules/express-rate-limit/dist/index.mjs +6 -3
  40. package/node_modules/express-rate-limit/{license.md → license} +7 -6
  41. package/node_modules/express-rate-limit/package.json +5 -5
  42. package/node_modules/express-rate-limit/readme.md +1 -0
  43. package/node_modules/fast-uri/index.js +20 -5
  44. package/node_modules/fast-uri/lib/utils.js +8 -1
  45. package/node_modules/fast-uri/package.json +1 -1
  46. package/node_modules/fast-uri/test/component-safe-serialization.test.js +58 -0
  47. package/node_modules/fast-uri/test/ipv6-validation.test.js +34 -0
  48. package/node_modules/ip-address/README.md +92 -82
  49. package/node_modules/ip-address/dist/common.d.ts +20 -0
  50. package/node_modules/ip-address/dist/common.js +36 -0
  51. package/node_modules/ip-address/dist/common.js.map +1 -1
  52. package/node_modules/ip-address/dist/ipv4.d.ts +50 -0
  53. package/node_modules/ip-address/dist/ipv4.js +75 -0
  54. package/node_modules/ip-address/dist/ipv4.js.map +1 -1
  55. package/node_modules/ip-address/dist/ipv6.d.ts +79 -10
  56. package/node_modules/ip-address/dist/ipv6.js +120 -30
  57. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  58. package/node_modules/ip-address/dist/v4/constants.d.ts +12 -0
  59. package/node_modules/ip-address/dist/v4/constants.js +40 -1
  60. package/node_modules/ip-address/dist/v4/constants.js.map +1 -1
  61. package/node_modules/ip-address/dist/v6/constants.d.ts +14 -0
  62. package/node_modules/ip-address/dist/v6/constants.js +47 -1
  63. package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
  64. package/node_modules/ip-address/package.json +1 -1
  65. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +7 -16
  66. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +6 -17
  67. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +7 -16
  68. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +11 -34
  69. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +7 -16
  70. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +15 -35
  71. package/node_modules/jose/dist/types/jwk/embedded.d.ts +3 -8
  72. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +5 -5
  73. package/node_modules/jose/dist/types/jwks/local.d.ts +6 -10
  74. package/node_modules/jose/dist/types/jwks/remote.d.ts +13 -24
  75. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -10
  76. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +9 -18
  77. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +7 -16
  78. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +9 -18
  79. package/node_modules/jose/dist/types/jws/general/sign.d.ts +11 -21
  80. package/node_modules/jose/dist/types/jws/general/verify.d.ts +9 -18
  81. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -20
  82. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +6 -13
  83. package/node_modules/jose/dist/types/jwt/sign.d.ts +5 -6
  84. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -14
  85. package/node_modules/jose/dist/types/jwt/verify.d.ts +9 -19
  86. package/node_modules/jose/dist/types/key/export.d.ts +4 -4
  87. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +6 -8
  88. package/node_modules/jose/dist/types/key/generate_secret.d.ts +4 -11
  89. package/node_modules/jose/dist/types/key/import.d.ts +10 -17
  90. package/node_modules/jose/dist/types/types.d.ts +44 -84
  91. package/node_modules/jose/dist/types/util/base64url.d.ts +2 -2
  92. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -10
  93. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +4 -4
  94. package/node_modules/jose/dist/types/util/errors.d.ts +26 -53
  95. package/node_modules/jose/dist/webapi/index.js +70 -32
  96. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +7 -8
  97. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +42 -48
  98. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +14 -14
  99. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +53 -64
  100. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +38 -49
  101. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +121 -169
  102. package/node_modules/jose/dist/webapi/jwk/embedded.js +30 -32
  103. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +54 -70
  104. package/node_modules/jose/dist/webapi/jwks/local.js +47 -64
  105. package/node_modules/jose/dist/webapi/jwks/remote.js +88 -136
  106. package/node_modules/jose/dist/webapi/jws/compact/sign.js +21 -21
  107. package/node_modules/jose/dist/webapi/jws/compact/verify.js +7 -8
  108. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +29 -31
  109. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +21 -24
  110. package/node_modules/jose/dist/webapi/jws/general/sign.js +61 -72
  111. package/node_modules/jose/dist/webapi/jws/general/verify.js +45 -69
  112. package/node_modules/jose/dist/webapi/jwt/decrypt.js +13 -20
  113. package/node_modules/jose/dist/webapi/jwt/encrypt.js +57 -70
  114. package/node_modules/jose/dist/webapi/jwt/sign.js +17 -16
  115. package/node_modules/jose/dist/webapi/jwt/unsecured.js +32 -40
  116. package/node_modules/jose/dist/webapi/jwt/verify.js +12 -14
  117. package/node_modules/jose/dist/webapi/key/export.js +32 -37
  118. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +40 -48
  119. package/node_modules/jose/dist/webapi/key/generate_secret.js +35 -40
  120. package/node_modules/jose/dist/webapi/key/import.js +52 -56
  121. package/node_modules/jose/dist/webapi/lib/asn1.js +130 -169
  122. package/node_modules/jose/dist/webapi/lib/base64.js +18 -20
  123. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +34 -38
  124. package/node_modules/jose/dist/webapi/lib/content_encryption.js +79 -115
  125. package/node_modules/jose/dist/webapi/lib/crypto_key.js +24 -25
  126. package/node_modules/jose/dist/webapi/lib/deflate.js +45 -47
  127. package/node_modules/jose/dist/webapi/lib/helpers.js +40 -37
  128. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +10 -24
  129. package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -15
  130. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +106 -93
  131. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +207 -230
  132. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +104 -138
  133. package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +17 -18
  134. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +9 -16
  135. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +62 -61
  136. package/node_modules/jose/dist/webapi/lib/jws_sign.js +50 -75
  137. package/node_modules/jose/dist/webapi/lib/jws_verify.js +80 -125
  138. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +123 -209
  139. package/node_modules/jose/dist/webapi/lib/key.js +84 -136
  140. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +13 -8
  141. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +8 -6
  142. package/node_modules/jose/dist/webapi/lib/key_management.js +200 -231
  143. package/node_modules/jose/dist/webapi/lib/key_options.js +7 -5
  144. package/node_modules/jose/dist/webapi/lib/options.js +55 -68
  145. package/node_modules/jose/dist/webapi/lib/signing.js +18 -22
  146. package/node_modules/jose/dist/webapi/lib/type_checks.js +26 -29
  147. package/node_modules/jose/dist/webapi/util/base64url.js +26 -35
  148. package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -31
  149. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +18 -23
  150. package/node_modules/jose/dist/webapi/util/errors.js +94 -84
  151. package/node_modules/jose/package.json +17 -81
  152. package/package.json +2 -2
  153. package/profiles/calendar/0.5.profile.json +190 -0
  154. package/profiles/charge/0.5.profile.json +210 -0
  155. package/profiles/customers/0.7.profile.json +157 -0
  156. package/profiles/deploy/0.9.profile.json +176 -0
  157. package/profiles/email/0.6.profile.json +208 -0
  158. package/profiles/index.json +9 -1
  159. package/profiles/publish/0.5.profile.json +186 -0
  160. package/profiles/purchase/0.5.profile.json +231 -0
  161. package/profiles/records/0.5.profile.json +117 -0
@@ -1,44 +1,39 @@
1
- import { toSPKI as exportPublic, toPKCS8 as exportPrivate } from '../lib/asn1.js';
2
- import { invalidKeyInput } from '../lib/invalid_key_input.js';
3
- import { encode as b64u } from '../util/base64url.js';
4
- import { isCryptoKey, isKeyObject } from '../lib/is_key_like.js';
1
+ import { toSPKI as exportPublic, toPKCS8 as exportPrivate } from "../lib/asn1.js";
2
+ import { invalidKeyInput } from "../lib/invalid_key_input.js";
3
+ import { encode as b64u } from "../util/base64url.js";
4
+ import { isCryptoKey, isKeyObject } from "../lib/is_key_like.js";
5
5
  function omitUndefinedProperties(jwk) {
6
- return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== undefined));
6
+ return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== void 0));
7
7
  }
8
8
  async function keyToJWK(key) {
9
- if (isKeyObject(key)) {
10
- if (key.type === 'secret') {
11
- key = key.export();
12
- }
13
- else {
14
- return key.export({ format: 'jwk' });
15
- }
16
- }
17
- if (key instanceof Uint8Array) {
18
- return {
19
- kty: 'oct',
20
- k: b64u(key),
21
- };
22
- }
23
- if (!isCryptoKey(key)) {
24
- throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'Uint8Array'));
25
- }
26
- if (!key.extractable) {
27
- throw new TypeError('non-extractable CryptoKey cannot be exported as a JWK');
28
- }
29
- const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey('jwk', key));
30
- if (jwk.kty === 'AKP') {
31
- ;
32
- jwk.alg = alg;
33
- }
34
- return jwk;
9
+ if (isKeyObject(key))
10
+ if (key.type === "secret")
11
+ key = key.export();
12
+ else
13
+ return key.export({ format: "jwk" });
14
+ if (key instanceof Uint8Array)
15
+ return {
16
+ kty: "oct",
17
+ k: b64u(key)
18
+ };
19
+ if (!isCryptoKey(key))
20
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
21
+ if (!key.extractable)
22
+ throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
23
+ const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey("jwk", key));
24
+ return jwk.kty === "AKP" && (jwk.alg = alg), jwk;
35
25
  }
36
- export function exportSPKI(key) {
37
- return exportPublic(key);
26
+ function exportSPKI(key) {
27
+ return exportPublic(key);
38
28
  }
39
- export function exportPKCS8(key) {
40
- return exportPrivate(key);
29
+ function exportPKCS8(key) {
30
+ return exportPrivate(key);
41
31
  }
42
- export function exportJWK(key) {
43
- return keyToJWK(key);
32
+ function exportJWK(key) {
33
+ return keyToJWK(key);
44
34
  }
35
+ export {
36
+ exportJWK,
37
+ exportPKCS8,
38
+ exportSPKI
39
+ };
@@ -1,52 +1,44 @@
1
- import { JOSENotSupported } from '../util/errors.js';
2
- import { validateExtractableOption } from '../lib/key_options.js';
3
- import { keyAlgorithm, unsupportedAlg, algArgument } from '../lib/key_algorithm.js';
1
+ import { JOSENotSupported } from "../util/errors.js";
2
+ import { validateExtractableOption } from "../lib/key_options.js";
3
+ import { keyAlgorithm, unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
4
4
  function getModulusLengthOption(options) {
5
- const modulusLength = options?.modulusLength ?? 2048;
6
- if (typeof modulusLength !== 'number' ||
7
- !Number.isInteger(modulusLength) ||
8
- modulusLength < 2048) {
9
- throw new JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
10
- }
11
- return modulusLength;
5
+ const modulusLength = options?.modulusLength ?? 2048;
6
+ if (typeof modulusLength != "number" || !Number.isInteger(modulusLength) || modulusLength < 2048)
7
+ throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
8
+ return modulusLength;
12
9
  }
13
- export async function generateKeyPair(alg, options) {
14
- const extractable = validateExtractableOption(options?.extractable);
15
- const entry = keyAlgorithm(alg, algArgument);
16
- if (entry.secret) {
17
- unsupportedAlg(algArgument);
18
- }
19
- let algorithm;
20
- if (entry.resolve) {
21
- const crv = options?.crv ?? 'P-256';
22
- switch (crv) {
23
- case 'P-256':
24
- case 'P-384':
25
- case 'P-521':
26
- algorithm = { name: 'ECDH', namedCurve: crv };
27
- break;
28
- case 'X25519':
29
- algorithm = { name: 'X25519' };
30
- break;
31
- default:
32
- throw new JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519');
33
- }
34
- }
35
- else {
36
- if (entry.crv !== undefined && options?.crv !== undefined && options.crv !== entry.crv) {
37
- throw new JOSENotSupported(`Invalid or unsupported crv option provided, the only supported value for ${alg} is ${entry.crv}`);
38
- }
39
- algorithm =
40
- entry.kty[0] === 'RSA'
41
- ? {
42
- ...entry.subtle,
43
- publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
44
- modulusLength: getModulusLengthOption(options),
45
- }
46
- : entry.subtle;
10
+ async function generateKeyPair(alg, options) {
11
+ const extractable = validateExtractableOption(options?.extractable), entry = keyAlgorithm(alg, algArgument);
12
+ entry.secret && unsupportedAlg(algArgument);
13
+ let algorithm;
14
+ if (entry.resolve) {
15
+ const crv = options?.crv ?? "P-256";
16
+ switch (crv) {
17
+ case "P-256":
18
+ case "P-384":
19
+ case "P-521":
20
+ algorithm = { name: "ECDH", namedCurve: crv };
21
+ break;
22
+ case "X25519":
23
+ algorithm = { name: "X25519" };
24
+ break;
25
+ default:
26
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
47
27
  }
48
- return crypto.subtle.generateKey(algorithm, extractable ?? false, [
49
- ...entry.usages[1],
50
- ...entry.usages[0],
51
- ]);
28
+ } else {
29
+ if (entry.crv !== void 0 && options?.crv !== void 0 && options.crv !== entry.crv)
30
+ throw new JOSENotSupported(`Invalid or unsupported crv option provided, the only supported value for ${alg} is ${entry.crv}`);
31
+ algorithm = entry.kty[0] === "RSA" ? {
32
+ ...entry.subtle,
33
+ publicExponent: Uint8Array.of(1, 0, 1),
34
+ modulusLength: getModulusLengthOption(options)
35
+ } : entry.subtle;
36
+ }
37
+ return crypto.subtle.generateKey(algorithm, extractable ?? !1, [
38
+ ...entry.usages[1],
39
+ ...entry.usages[0]
40
+ ]);
52
41
  }
42
+ export {
43
+ generateKeyPair
44
+ };
@@ -1,41 +1,36 @@
1
- import { unsupportedAlg, algArgument } from '../lib/key_algorithm.js';
2
- import { validateExtractableOption } from '../lib/key_options.js';
3
- export async function generateSecret(alg, options) {
4
- const extractable = validateExtractableOption(options?.extractable);
5
- let length;
6
- let algorithm;
7
- let keyUsages;
8
- switch (alg) {
9
- case 'HS256':
10
- case 'HS384':
11
- case 'HS512':
12
- length = +alg.slice(-3);
13
- algorithm = { name: 'HMAC', hash: `SHA-${length}`, length };
14
- keyUsages = ['sign', 'verify'];
15
- break;
16
- case 'A128CBC-HS256':
17
- case 'A192CBC-HS384':
18
- case 'A256CBC-HS512':
19
- return crypto.getRandomValues(new Uint8Array(+alg.slice(-3) >> 3));
20
- case 'A128KW':
21
- case 'A192KW':
22
- case 'A256KW':
23
- length = +alg.slice(1, 4);
24
- algorithm = { name: 'AES-KW', length };
25
- keyUsages = ['wrapKey', 'unwrapKey'];
26
- break;
27
- case 'A128GCMKW':
28
- case 'A192GCMKW':
29
- case 'A256GCMKW':
30
- case 'A128GCM':
31
- case 'A192GCM':
32
- case 'A256GCM':
33
- length = +alg.slice(1, 4);
34
- algorithm = { name: 'AES-GCM', length };
35
- keyUsages = ['encrypt', 'decrypt'];
36
- break;
37
- default:
38
- unsupportedAlg(algArgument);
39
- }
40
- return crypto.subtle.generateKey(algorithm, extractable ?? false, keyUsages);
1
+ import { unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
2
+ import { validateExtractableOption } from "../lib/key_options.js";
3
+ async function generateSecret(alg, options) {
4
+ const extractable = validateExtractableOption(options?.extractable);
5
+ let length, algorithm, keyUsages;
6
+ switch (alg) {
7
+ case "HS256":
8
+ case "HS384":
9
+ case "HS512":
10
+ length = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${length}`, length }, keyUsages = ["sign", "verify"];
11
+ break;
12
+ case "A128CBC-HS256":
13
+ case "A192CBC-HS384":
14
+ case "A256CBC-HS512":
15
+ return crypto.getRandomValues(new Uint8Array(+alg.slice(-3) >> 3));
16
+ case "A128KW":
17
+ case "A192KW":
18
+ case "A256KW":
19
+ length = +alg.slice(1, 4), algorithm = { name: "AES-KW", length }, keyUsages = ["wrapKey", "unwrapKey"];
20
+ break;
21
+ case "A128GCMKW":
22
+ case "A192GCMKW":
23
+ case "A256GCMKW":
24
+ case "A128GCM":
25
+ case "A192GCM":
26
+ case "A256GCM":
27
+ length = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length }, keyUsages = ["encrypt", "decrypt"];
28
+ break;
29
+ default:
30
+ unsupportedAlg(algArgument);
31
+ }
32
+ return crypto.subtle.generateKey(algorithm, extractable ?? !1, keyUsages);
41
33
  }
34
+ export {
35
+ generateSecret
36
+ };
@@ -1,61 +1,57 @@
1
- import { decode as decodeBase64URL } from '../util/base64url.js';
2
- import { fromSPKI, fromPKCS8, fromX509 } from '../lib/asn1.js';
3
- import { jwkToKey } from '../lib/jwk_to_key.js';
4
- import { keyAlgorithm } from '../lib/key_algorithm.js';
5
- import { JOSENotSupported } from '../util/errors.js';
6
- import { isObject } from '../lib/type_checks.js';
7
- import { validateExtractableOption } from '../lib/key_options.js';
8
- import { normalizeJwk } from '../lib/jwk_metadata.js';
9
- export async function importSPKI(spki, alg, options) {
10
- if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {
11
- throw new TypeError('"spki" must be SPKI formatted string');
12
- }
13
- return fromSPKI(spki, alg, options);
1
+ import { decode as decodeBase64URL } from "../util/base64url.js";
2
+ import { fromSPKI, fromPKCS8, fromX509 } from "../lib/asn1.js";
3
+ import { jwkToKey } from "../lib/jwk_to_key.js";
4
+ import { keyAlgorithm } from "../lib/key_algorithm.js";
5
+ import { JOSENotSupported } from "../util/errors.js";
6
+ import { isObject } from "../lib/type_checks.js";
7
+ import { validateExtractableOption } from "../lib/key_options.js";
8
+ import { normalizeJwk } from "../lib/jwk_metadata.js";
9
+ async function importSPKI(spki, alg, options) {
10
+ if (typeof spki != "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
11
+ throw new TypeError('"spki" must be SPKI formatted string');
12
+ return fromSPKI(spki, alg, options);
14
13
  }
15
- export async function importX509(x509, alg, options) {
16
- if (typeof x509 !== 'string' || x509.indexOf('-----BEGIN CERTIFICATE-----') !== 0) {
17
- throw new TypeError('"x509" must be X.509 formatted string');
18
- }
19
- return fromX509(x509, alg, options);
14
+ async function importX509(x509, alg, options) {
15
+ if (typeof x509 != "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0)
16
+ throw new TypeError('"x509" must be X.509 formatted string');
17
+ return fromX509(x509, alg, options);
20
18
  }
21
- export async function importPKCS8(pkcs8, alg, options) {
22
- if (typeof pkcs8 !== 'string' || pkcs8.indexOf('-----BEGIN PRIVATE KEY-----') !== 0) {
23
- throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
24
- }
25
- return fromPKCS8(pkcs8, alg, options);
19
+ async function importPKCS8(pkcs8, alg, options) {
20
+ if (typeof pkcs8 != "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0)
21
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
22
+ return fromPKCS8(pkcs8, alg, options);
26
23
  }
27
- export async function importJWK(jwk, alg, options) {
28
- if (!isObject(jwk)) {
29
- throw new TypeError('JWK must be an object');
30
- }
31
- const normalized = normalizeJwk(jwk);
32
- const extractable = validateExtractableOption(options?.extractable);
33
- const { alg: jwkAlg } = normalized;
34
- alg ??= jwkAlg;
35
- const ext = extractable ?? normalized.ext;
36
- if (normalized.kty !== 'oct' && !alg) {
37
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
38
- }
39
- switch (normalized.kty) {
40
- case 'oct':
41
- if (typeof normalized.k !== 'string') {
42
- throw new TypeError('missing "k" (Key Value) Parameter value');
43
- }
44
- return decodeBase64URL(normalized.k);
45
- case 'AKP': {
46
- if (typeof jwkAlg !== 'string' || !jwkAlg) {
47
- throw new TypeError('missing "alg" (Algorithm) Parameter value');
48
- }
49
- if (alg !== jwkAlg) {
50
- throw new TypeError('JWK alg and alg option value mismatch');
51
- }
52
- return jwkToKey(keyAlgorithm(alg), { ...normalized, ext });
53
- }
54
- case 'RSA':
55
- case 'EC':
56
- case 'OKP':
57
- return jwkToKey(keyAlgorithm(alg), { ...normalized, alg, ext });
58
- default:
59
- throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
24
+ async function importJWK(jwk, alg, options) {
25
+ if (!isObject(jwk))
26
+ throw new TypeError("JWK must be an object");
27
+ const normalized = normalizeJwk(jwk), extractable = validateExtractableOption(options?.extractable), { alg: jwkAlg } = normalized;
28
+ alg ??= jwkAlg;
29
+ const ext = extractable ?? normalized.ext;
30
+ if (normalized.kty !== "oct" && !alg)
31
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
32
+ switch (normalized.kty) {
33
+ case "oct":
34
+ if (typeof normalized.k != "string")
35
+ throw new TypeError('missing "k" (Key Value) Parameter value');
36
+ return decodeBase64URL(normalized.k);
37
+ case "AKP": {
38
+ if (typeof jwkAlg != "string" || !jwkAlg)
39
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
40
+ if (alg !== jwkAlg)
41
+ throw new TypeError("JWK alg and alg option value mismatch");
42
+ return jwkToKey(keyAlgorithm(alg), { ...normalized, ext });
60
43
  }
44
+ case "RSA":
45
+ case "EC":
46
+ case "OKP":
47
+ return jwkToKey(keyAlgorithm(alg), { ...normalized, alg, ext });
48
+ default:
49
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
50
+ }
61
51
  }
52
+ export {
53
+ importJWK,
54
+ importPKCS8,
55
+ importSPKI,
56
+ importX509
57
+ };