@zuplo/cli 6.73.27 → 6.73.29

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 (103) hide show
  1. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/README.md +13 -13
  2. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/index.d.ts +6 -5
  3. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  4. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +7 -19
  5. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  6. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +7 -19
  7. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  8. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +20 -21
  9. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  10. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  11. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  12. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  13. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  14. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  15. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  16. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +10 -34
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/export.d.ts +0 -14
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/import.d.ts +18 -28
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/types.d.ts +242 -223
  29. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  30. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  31. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  32. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  33. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +3 -21
  34. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  35. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  36. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/decrypt.js +15 -3
  37. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +33 -48
  38. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  39. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +27 -47
  40. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +3 -3
  41. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  42. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/verify.js +3 -15
  43. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -57
  44. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  45. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +18 -5
  46. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +21 -3
  47. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/decrypt.js +4 -4
  48. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  49. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  50. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/verify.js +5 -5
  51. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/export.js +34 -1
  52. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_key_pair.js +32 -82
  53. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/import.js +8 -8
  54. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +29 -65
  55. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  56. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +20 -77
  57. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/crypto_key.js +13 -127
  58. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  59. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +143 -0
  60. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +181 -0
  61. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +109 -0
  62. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwk_to_key.js +11 -96
  63. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
  64. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +68 -0
  65. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +108 -0
  66. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +9 -8
  67. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +170 -0
  68. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_algorithm.js +16 -0
  69. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  70. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +186 -29
  71. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/{validate_crit.js → options.js} +18 -0
  72. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/signing.js +20 -52
  73. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/base64url.js +11 -3
  74. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  75. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  76. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/errors.js +1 -1
  77. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +2 -4
  78. package/node_modules/@zuplo/core/customer.cli.minified.js +1 -1
  79. package/node_modules/@zuplo/core/index.minified.js +1 -1
  80. package/node_modules/@zuplo/core/package.json +1 -1
  81. package/node_modules/@zuplo/graphql/package.json +1 -1
  82. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  83. package/node_modules/@zuplo/otel/package.json +1 -1
  84. package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js +405 -0
  85. package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js.map +1 -0
  86. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  87. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  88. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  89. package/node_modules/@zuplo/runtime/out/types/index.d.ts +144 -1
  90. package/node_modules/@zuplo/runtime/package.json +1 -1
  91. package/package.json +6 -6
  92. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  93. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  94. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  95. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  96. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  97. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  98. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  99. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  100. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  101. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js +0 -405
  102. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js.map +0 -1
  103. /package/node_modules/@zuplo/runtime/out/esm/{chunk-GWEFPK3R.js.LEGAL.txt → chunk-KO2ULO4I.js.LEGAL.txt} +0 -0
@@ -475,7 +475,6 @@ export declare class AIGatewayMeteringInboundPolicy extends InboundPolicy<AIGate
475
475
  increments: AIGatewayMeterIncrements,
476
476
  context: ZuploContext
477
477
  ): Promise<void>;
478
- private static incrementMetersInternal;
479
478
  private checkWarnings;
480
479
  private checkQuotaWarning;
481
480
  private createHierarchicalQuotaExceededResponse;
@@ -492,6 +491,131 @@ export declare interface AIGatewayMeteringInboundPolicyOptions {
492
491
  throwOnFailure?: boolean;
493
492
  }
494
493
 
494
+ /**
495
+ * Meters AI Gateway v2 usage and enforces options-driven usage limits.
496
+ *
497
+ * The authentication policy must run before this policy so the app
498
+ * configuration id is available for meter storage and analytics.
499
+ *
500
+ * @title AI Gateway Metering (v2)
501
+ * @beta
502
+ * @product ai-gateway
503
+ * @requiresAI
504
+ * @param request - The ZuploRequest
505
+ * @param context - The ZuploContext
506
+ * @param options - The policy options set in policies.json
507
+ * @param policyName - The name of the policy as set in policies.json
508
+ * @returns The request, or a 429 response when a limit is exceeded
509
+ */
510
+ export declare class AIGatewayMeteringV2InboundPolicy extends InboundPolicy<AIGatewayMeteringV2InboundPolicyOptions> {
511
+ #private;
512
+ static readonly policyType = "ai-gateway-metering-v2";
513
+ constructor(
514
+ options: AIGatewayMeteringV2InboundPolicyOptions,
515
+ policyName: string
516
+ );
517
+ /** Set the meter increments accumulated for this request. */
518
+ static setIncrements(
519
+ context: ZuploContext,
520
+ increments: AIGatewayMeterIncrements
521
+ ): void;
522
+ /** Read the meter increments accumulated for this request. */
523
+ static getIncrements(context: ZuploContext): AIGatewayMeterIncrements;
524
+ /** Set the quota-fallback marker for this request. */
525
+ static setQuotaFallback(
526
+ context: ZuploContext,
527
+ quotaFallback: QuotaFallbackModels
528
+ ): void;
529
+ /** Read the quota-fallback marker for this request. */
530
+ static getQuotaFallback(
531
+ context: ZuploContext
532
+ ): QuotaFallbackModels | undefined;
533
+ /**
534
+ * Compose request-scoped limit overrides with any limits already set.
535
+ *
536
+ * Limits intentionally merge at each meter, period, and setting leaf because
537
+ * independent policies may tighten one path without restating sibling limits.
538
+ * Defined values from the newest call win; undefined values never erase an
539
+ * earlier value.
540
+ *
541
+ * @param context - The current request context
542
+ * @param limits - Limits or partial leaf overrides to compose
543
+ */
544
+ static setLimits(
545
+ context: ZuploContext,
546
+ limits: AIGatewayMeteringV2LimitOverrides
547
+ ): void;
548
+ /** Read request-scoped limit overrides. */
549
+ static getLimits(
550
+ context: ZuploContext
551
+ ): AIGatewayMeteringV2LimitOverrides | undefined;
552
+ /** Increment meters directly, for example after a streaming response. */
553
+ static incrementMeters(
554
+ configurationId: string,
555
+ increments: AIGatewayMeterIncrements,
556
+ context: ZuploContext
557
+ ): Promise<void>;
558
+ handler(
559
+ request: ZuploRequest,
560
+ context: ZuploContext
561
+ ): Promise<ZuploRequest | Response>;
562
+ private resolveConfiguration;
563
+ private fetchCurrentMeters;
564
+ private checkWarnings;
565
+ private hasWarning;
566
+ private findViolation;
567
+ private requestCapability;
568
+ private createQuotaExceededResponse;
569
+ }
570
+
571
+ /**
572
+ * Options for metering AI Gateway v2 usage and enforcing request-time limits.
573
+ * @public
574
+ */
575
+ export declare interface AIGatewayMeteringV2InboundPolicyOptions {
576
+ /**
577
+ * Throw when the metering service is unavailable instead of failing open.
578
+ */
579
+ throwOnFailure?: boolean;
580
+ /**
581
+ * Usage limits grouped by meter.
582
+ */
583
+ limits?: {
584
+ costs?: QuotaLimit;
585
+ tokens?: QuotaLimit;
586
+ requests?: QuotaLimit;
587
+ };
588
+ }
589
+
590
+ /**
591
+ * Request-scoped usage-limit overrides accepted by
592
+ * `AIGatewayMeteringV2InboundPolicy.setLimits`.
593
+ */
594
+ export declare interface AIGatewayMeteringV2LimitOverrides {
595
+ costs?: AIGatewayMeteringV2MeterLimitOverrides;
596
+ tokens?: AIGatewayMeteringV2MeterLimitOverrides;
597
+ requests?: AIGatewayMeteringV2MeterLimitOverrides;
598
+ }
599
+
600
+ /** Daily and monthly overrides for one usage meter. */
601
+ declare interface AIGatewayMeteringV2MeterLimitOverrides {
602
+ daily?: AIGatewayMeteringV2PeriodLimitOverride;
603
+ monthly?: AIGatewayMeteringV2PeriodLimitOverride;
604
+ }
605
+
606
+ /** Settings that a policy can override for one usage-limit period. */
607
+ declare interface AIGatewayMeteringV2PeriodLimitOverride {
608
+ enabled?: boolean;
609
+ limit?: number;
610
+ warning?: AIGatewayMeteringV2WarningLimitOverride;
611
+ }
612
+
613
+ /** Warning settings that a policy can override for one usage-limit period. */
614
+ declare interface AIGatewayMeteringV2WarningLimitOverride {
615
+ enabled?: boolean;
616
+ threshold?: number;
617
+ }
618
+
495
619
  /**
496
620
  * Matches AI Gateway requests against curated allow lists or open block lists,
497
621
  * then stores the winning model reference for the route handler.
@@ -12178,6 +12302,17 @@ export declare interface QuotaInboundPolicyOptions {
12178
12302
  };
12179
12303
  }
12180
12304
 
12305
+ declare interface QuotaLimit {
12306
+ daily?: QuotaSettings;
12307
+ monthly?: QuotaSettings;
12308
+ }
12309
+
12310
+ declare interface QuotaSettings {
12311
+ enabled: boolean;
12312
+ limit?: number;
12313
+ warning?: WarningSettings;
12314
+ }
12315
+
12181
12316
  /**
12182
12317
  * The identifying element of the request that enforces distinct rate limits. For example, you can limit by `user`, `ip`, `function` or `all` - function allows you to specify a simple function to create a string identifier to create a rate-limit group.
12183
12318
  * @public
@@ -15720,6 +15855,14 @@ declare interface WaitUntilFunc {
15720
15855
  (promise: Promise<any>): void;
15721
15856
  }
15722
15857
 
15858
+ declare interface WarningSettings {
15859
+ enabled: boolean;
15860
+ /**
15861
+ * Percentage of the limit at which to emit a warning event.
15862
+ */
15863
+ threshold?: number;
15864
+ }
15865
+
15723
15866
  /**
15724
15867
  * Authenticate bots using web-bot-auth HTTP Message Signatures.
15725
15868
  *
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.73.27",
4
+ "version": "6.73.29",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "6.73.27",
3
+ "version": "6.73.29",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -27,10 +27,10 @@
27
27
  "@opentelemetry/api": "1.9.0",
28
28
  "@opentelemetry/api-logs": "0.220.0",
29
29
  "@swc/core": "1.10.18",
30
- "@zuplo/core": "6.73.27",
30
+ "@zuplo/core": "6.73.29",
31
31
  "@zuplo/editor": "1.0.29844086763",
32
- "@zuplo/openapi-tools": "6.73.27",
33
- "@zuplo/runtime": "6.73.27",
32
+ "@zuplo/openapi-tools": "6.73.29",
33
+ "@zuplo/runtime": "6.73.29",
34
34
  "chalk": "5.4.1",
35
35
  "chokidar": "3.5.3",
36
36
  "cookie": "1.0.2",
@@ -61,8 +61,8 @@
61
61
  "workerd": "1.20241230.0",
62
62
  "yargs": "17.7.2",
63
63
  "zod": "3.25.76",
64
- "@zuplo/graphql": "6.73.27",
65
- "@zuplo/otel": "6.73.27"
64
+ "@zuplo/graphql": "6.73.29",
65
+ "@zuplo/otel": "6.73.29"
66
66
  },
67
67
  "bundleDependencies": [
68
68
  "@inquirer/prompts",
@@ -1,15 +0,0 @@
1
- import { encrypt, decrypt } from './content_encryption.js';
2
- import { encode as b64u } from '../util/base64url.js';
3
- export async function wrap(alg, key, cek, iv) {
4
- const jweAlgorithm = alg.slice(0, 7);
5
- const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array());
6
- return {
7
- encryptedKey: wrapped.ciphertext,
8
- iv: b64u(wrapped.iv),
9
- tag: b64u(wrapped.tag),
10
- };
11
- }
12
- export async function unwrap(alg, key, encryptedKey, iv, tag) {
13
- const jweAlgorithm = alg.slice(0, 7);
14
- return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array());
15
- }
@@ -1,25 +0,0 @@
1
- import { checkEncCryptoKey } from './crypto_key.js';
2
- function checkKeySize(key, alg) {
3
- if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
4
- throw new TypeError(`Invalid key size for alg: ${alg}`);
5
- }
6
- }
7
- function getCryptoKey(key, alg, usage) {
8
- if (key instanceof Uint8Array) {
9
- return crypto.subtle.importKey('raw', key, 'AES-KW', true, [usage]);
10
- }
11
- checkEncCryptoKey(key, alg, usage);
12
- return key;
13
- }
14
- export async function wrap(alg, key, cek) {
15
- const cryptoKey = await getCryptoKey(key, alg, 'wrapKey');
16
- checkKeySize(cryptoKey, alg);
17
- const cryptoKeyCek = await crypto.subtle.importKey('raw', cek, { hash: 'SHA-256', name: 'HMAC' }, true, ['sign']);
18
- return new Uint8Array(await crypto.subtle.wrapKey('raw', cryptoKeyCek, cryptoKey, 'AES-KW'));
19
- }
20
- export async function unwrap(alg, key, encryptedKey) {
21
- const cryptoKey = await getCryptoKey(key, alg, 'unwrapKey');
22
- checkKeySize(cryptoKey, alg);
23
- const cryptoKeyCek = await crypto.subtle.unwrapKey('raw', encryptedKey, cryptoKey, 'AES-KW', { hash: 'SHA-256', name: 'HMAC' }, true, ['sign']);
24
- return new Uint8Array(await crypto.subtle.exportKey('raw', cryptoKeyCek));
25
- }
@@ -1,122 +0,0 @@
1
- import { withAlg as invalidKeyInput } from './invalid_key_input.js';
2
- import { isKeyLike } from './is_key_like.js';
3
- import * as jwk from './type_checks.js';
4
- const tag = (key) => key?.[Symbol.toStringTag];
5
- const jwkMatchesOp = (alg, key, usage) => {
6
- if (key.use !== undefined) {
7
- let expected;
8
- switch (usage) {
9
- case 'sign':
10
- case 'verify':
11
- expected = 'sig';
12
- break;
13
- case 'encrypt':
14
- case 'decrypt':
15
- expected = 'enc';
16
- break;
17
- }
18
- if (key.use !== expected) {
19
- throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
20
- }
21
- }
22
- if (key.alg !== undefined && key.alg !== alg) {
23
- throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
24
- }
25
- if (Array.isArray(key.key_ops)) {
26
- let expectedKeyOp;
27
- switch (true) {
28
- case usage === 'sign' || usage === 'verify':
29
- case alg === 'dir':
30
- case alg.includes('CBC-HS'):
31
- expectedKeyOp = usage;
32
- break;
33
- case alg.startsWith('PBES2'):
34
- expectedKeyOp = 'deriveBits';
35
- break;
36
- case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
37
- if (!alg.includes('GCM') && alg.endsWith('KW')) {
38
- expectedKeyOp = usage === 'encrypt' ? 'wrapKey' : 'unwrapKey';
39
- }
40
- else {
41
- expectedKeyOp = usage;
42
- }
43
- break;
44
- case usage === 'encrypt' && alg.startsWith('RSA'):
45
- expectedKeyOp = 'wrapKey';
46
- break;
47
- case usage === 'decrypt':
48
- expectedKeyOp = alg.startsWith('RSA') ? 'unwrapKey' : 'deriveBits';
49
- break;
50
- }
51
- if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
52
- throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
53
- }
54
- }
55
- return true;
56
- };
57
- const symmetricTypeCheck = (alg, key, usage) => {
58
- if (key instanceof Uint8Array)
59
- return;
60
- if (jwk.isJWK(key)) {
61
- if (jwk.isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
62
- return;
63
- throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
64
- }
65
- if (!isKeyLike(key)) {
66
- throw new TypeError(invalidKeyInput(alg, key, 'CryptoKey', 'KeyObject', 'JSON Web Key', 'Uint8Array'));
67
- }
68
- if (key.type !== 'secret') {
69
- throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
70
- }
71
- };
72
- const asymmetricTypeCheck = (alg, key, usage) => {
73
- if (jwk.isJWK(key)) {
74
- switch (usage) {
75
- case 'decrypt':
76
- case 'sign':
77
- if (jwk.isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
78
- return;
79
- throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
80
- case 'encrypt':
81
- case 'verify':
82
- if (jwk.isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
83
- return;
84
- throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
85
- }
86
- }
87
- if (!isKeyLike(key)) {
88
- throw new TypeError(invalidKeyInput(alg, key, 'CryptoKey', 'KeyObject', 'JSON Web Key'));
89
- }
90
- if (key.type === 'secret') {
91
- throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
92
- }
93
- if (key.type === 'public') {
94
- switch (usage) {
95
- case 'sign':
96
- throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
97
- case 'decrypt':
98
- throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
99
- }
100
- }
101
- if (key.type === 'private') {
102
- switch (usage) {
103
- case 'verify':
104
- throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
105
- case 'encrypt':
106
- throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
107
- }
108
- }
109
- };
110
- export function checkKeyType(alg, key, usage) {
111
- switch (alg.substring(0, 2)) {
112
- case 'A1':
113
- case 'A2':
114
- case 'di':
115
- case 'HS':
116
- case 'PB':
117
- symmetricTypeCheck(alg, key, usage);
118
- break;
119
- default:
120
- asymmetricTypeCheck(alg, key, usage);
121
- }
122
- }
@@ -1,52 +0,0 @@
1
- import { encode, concat, uint32be } from './buffer_utils.js';
2
- import { checkEncCryptoKey } from './crypto_key.js';
3
- import { digest } from './helpers.js';
4
- function lengthAndInput(input) {
5
- return concat(uint32be(input.length), input);
6
- }
7
- async function concatKdf(Z, L, OtherInfo) {
8
- const dkLen = L >> 3;
9
- const hashLen = 32;
10
- const reps = Math.ceil(dkLen / hashLen);
11
- const dk = new Uint8Array(reps * hashLen);
12
- for (let i = 1; i <= reps; i++) {
13
- const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
14
- hashInput.set(uint32be(i), 0);
15
- hashInput.set(Z, 4);
16
- hashInput.set(OtherInfo, 4 + Z.length);
17
- const hashResult = await digest('sha256', hashInput);
18
- dk.set(hashResult, (i - 1) * hashLen);
19
- }
20
- return dk.slice(0, dkLen);
21
- }
22
- export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
23
- checkEncCryptoKey(publicKey, 'ECDH');
24
- checkEncCryptoKey(privateKey, 'ECDH', 'deriveBits');
25
- const algorithmID = lengthAndInput(encode(algorithm));
26
- const partyUInfo = lengthAndInput(apu);
27
- const partyVInfo = lengthAndInput(apv);
28
- const suppPubInfo = uint32be(keyLength);
29
- const suppPrivInfo = new Uint8Array();
30
- const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
31
- const Z = new Uint8Array(await crypto.subtle.deriveBits({
32
- name: publicKey.algorithm.name,
33
- public: publicKey,
34
- }, privateKey, getEcdhBitLength(publicKey)));
35
- return concatKdf(Z, keyLength, otherInfo);
36
- }
37
- function getEcdhBitLength(publicKey) {
38
- if (publicKey.algorithm.name === 'X25519') {
39
- return 256;
40
- }
41
- return (Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3);
42
- }
43
- export function allowed(key) {
44
- switch (key.algorithm.namedCurve) {
45
- case 'P-256':
46
- case 'P-384':
47
- case 'P-521':
48
- return true;
49
- default:
50
- return key.algorithm.name === 'X25519';
51
- }
52
- }
@@ -1,34 +0,0 @@
1
- import { invalidKeyInput } from './invalid_key_input.js';
2
- import { encode as b64u } from '../util/base64url.js';
3
- import { isCryptoKey, isKeyObject } from './is_key_like.js';
4
- function omitUndefinedProperties(jwk) {
5
- return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== undefined));
6
- }
7
- export async function keyToJWK(key) {
8
- if (isKeyObject(key)) {
9
- if (key.type === 'secret') {
10
- key = key.export();
11
- }
12
- else {
13
- return key.export({ format: 'jwk' });
14
- }
15
- }
16
- if (key instanceof Uint8Array) {
17
- return {
18
- kty: 'oct',
19
- k: b64u(key),
20
- };
21
- }
22
- if (!isCryptoKey(key)) {
23
- throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'Uint8Array'));
24
- }
25
- if (!key.extractable) {
26
- throw new TypeError('non-extractable CryptoKey cannot be exported as a JWK');
27
- }
28
- const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey('jwk', key));
29
- if (jwk.kty === 'AKP') {
30
- ;
31
- jwk.alg = alg;
32
- }
33
- return jwk;
34
- }
@@ -1,166 +0,0 @@
1
- import { isJWK } from './type_checks.js';
2
- import { decode } from '../util/base64url.js';
3
- import { jwkToKey } from './jwk_to_key.js';
4
- import { isCryptoKey, isKeyObject } from './is_key_like.js';
5
- const unusableForAlg = 'given KeyObject instance cannot be used for this algorithm';
6
- let cache;
7
- const handleJWK = async (key, jwk, alg, freeze = false) => {
8
- cache ||= new WeakMap();
9
- let cached = cache.get(key);
10
- if (cached?.[alg]) {
11
- return cached[alg];
12
- }
13
- const cryptoKey = await jwkToKey({ ...jwk, alg });
14
- if (freeze)
15
- Object.freeze(key);
16
- if (!cached) {
17
- cache.set(key, { [alg]: cryptoKey });
18
- }
19
- else {
20
- cached[alg] = cryptoKey;
21
- }
22
- return cryptoKey;
23
- };
24
- const handleKeyObject = (keyObject, alg) => {
25
- cache ||= new WeakMap();
26
- let cached = cache.get(keyObject);
27
- if (cached?.[alg]) {
28
- return cached[alg];
29
- }
30
- const isPublic = keyObject.type === 'public';
31
- const extractable = isPublic ? true : false;
32
- let cryptoKey;
33
- if (keyObject.asymmetricKeyType === 'x25519') {
34
- switch (alg) {
35
- case 'ECDH-ES':
36
- case 'ECDH-ES+A128KW':
37
- case 'ECDH-ES+A192KW':
38
- case 'ECDH-ES+A256KW':
39
- break;
40
- default:
41
- throw new TypeError(unusableForAlg);
42
- }
43
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ['deriveBits']);
44
- }
45
- if (keyObject.asymmetricKeyType === 'ed25519') {
46
- if (alg !== 'EdDSA' && alg !== 'Ed25519') {
47
- throw new TypeError(unusableForAlg);
48
- }
49
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
50
- isPublic ? 'verify' : 'sign',
51
- ]);
52
- }
53
- switch (keyObject.asymmetricKeyType) {
54
- case 'ml-dsa-44':
55
- case 'ml-dsa-65':
56
- case 'ml-dsa-87': {
57
- if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
58
- throw new TypeError(unusableForAlg);
59
- }
60
- cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
61
- isPublic ? 'verify' : 'sign',
62
- ]);
63
- }
64
- }
65
- if (keyObject.asymmetricKeyType === 'rsa') {
66
- let hash;
67
- switch (alg) {
68
- case 'RSA-OAEP':
69
- hash = 'SHA-1';
70
- break;
71
- case 'RS256':
72
- case 'PS256':
73
- case 'RSA-OAEP-256':
74
- hash = 'SHA-256';
75
- break;
76
- case 'RS384':
77
- case 'PS384':
78
- case 'RSA-OAEP-384':
79
- hash = 'SHA-384';
80
- break;
81
- case 'RS512':
82
- case 'PS512':
83
- case 'RSA-OAEP-512':
84
- hash = 'SHA-512';
85
- break;
86
- default:
87
- throw new TypeError(unusableForAlg);
88
- }
89
- if (alg.startsWith('RSA-OAEP')) {
90
- return keyObject.toCryptoKey({
91
- name: 'RSA-OAEP',
92
- hash,
93
- }, extractable, isPublic ? ['encrypt'] : ['decrypt']);
94
- }
95
- cryptoKey = keyObject.toCryptoKey({
96
- name: alg.startsWith('PS') ? 'RSA-PSS' : 'RSASSA-PKCS1-v1_5',
97
- hash,
98
- }, extractable, [isPublic ? 'verify' : 'sign']);
99
- }
100
- if (keyObject.asymmetricKeyType === 'ec') {
101
- const nist = new Map([
102
- ['prime256v1', 'P-256'],
103
- ['secp384r1', 'P-384'],
104
- ['secp521r1', 'P-521'],
105
- ]);
106
- const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
107
- if (!namedCurve) {
108
- throw new TypeError(unusableForAlg);
109
- }
110
- const expectedCurve = { ES256: 'P-256', ES384: 'P-384', ES512: 'P-521' };
111
- if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
112
- cryptoKey = keyObject.toCryptoKey({
113
- name: 'ECDSA',
114
- namedCurve,
115
- }, extractable, [isPublic ? 'verify' : 'sign']);
116
- }
117
- if (alg.startsWith('ECDH-ES')) {
118
- cryptoKey = keyObject.toCryptoKey({
119
- name: 'ECDH',
120
- namedCurve,
121
- }, extractable, isPublic ? [] : ['deriveBits']);
122
- }
123
- }
124
- if (!cryptoKey) {
125
- throw new TypeError(unusableForAlg);
126
- }
127
- if (!cached) {
128
- cache.set(keyObject, { [alg]: cryptoKey });
129
- }
130
- else {
131
- cached[alg] = cryptoKey;
132
- }
133
- return cryptoKey;
134
- };
135
- export async function normalizeKey(key, alg) {
136
- if (key instanceof Uint8Array) {
137
- return key;
138
- }
139
- if (isCryptoKey(key)) {
140
- return key;
141
- }
142
- if (isKeyObject(key)) {
143
- if (key.type === 'secret') {
144
- return key.export();
145
- }
146
- if ('toCryptoKey' in key && typeof key.toCryptoKey === 'function') {
147
- try {
148
- return handleKeyObject(key, alg);
149
- }
150
- catch (err) {
151
- if (err instanceof TypeError) {
152
- throw err;
153
- }
154
- }
155
- }
156
- let jwk = key.export({ format: 'jwk' });
157
- return handleJWK(key, jwk, alg);
158
- }
159
- if (isJWK(key)) {
160
- if (key.k) {
161
- return decode(key.k);
162
- }
163
- return handleJWK(key, key, alg, true);
164
- }
165
- throw new Error('unreachable');
166
- }
@@ -1,42 +0,0 @@
1
- import { encode as b64u } from '../util/base64url.js';
2
- import * as aeskw from './aeskw.js';
3
- import { checkEncCryptoKey } from './crypto_key.js';
4
- import { concat, encode } from './buffer_utils.js';
5
- import { JWEInvalid } from '../util/errors.js';
6
- function getCryptoKey(key, alg) {
7
- if (key instanceof Uint8Array) {
8
- return crypto.subtle.importKey('raw', key, 'PBKDF2', false, [
9
- 'deriveBits',
10
- ]);
11
- }
12
- checkEncCryptoKey(key, alg, 'deriveBits');
13
- return key;
14
- }
15
- const concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0x00), p2sInput);
16
- async function deriveKey(p2s, alg, p2c, key) {
17
- if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
18
- throw new JWEInvalid('PBES2 Salt Input must be 8 or more octets');
19
- }
20
- if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1) {
21
- throw new JWEInvalid('PBES2 Count Input must be a positive integer');
22
- }
23
- const salt = concatSalt(alg, p2s);
24
- const keylen = parseInt(alg.slice(13, 16), 10);
25
- const subtleAlg = {
26
- hash: `SHA-${alg.slice(8, 11)}`,
27
- iterations: p2c,
28
- name: 'PBKDF2',
29
- salt,
30
- };
31
- const cryptoKey = await getCryptoKey(key, alg);
32
- return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
33
- }
34
- export async function wrap(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
35
- const derived = await deriveKey(p2s, alg, p2c, key);
36
- const encryptedKey = await aeskw.wrap(alg.slice(-6), derived, cek);
37
- return { encryptedKey, p2c, p2s: b64u(p2s) };
38
- }
39
- export async function unwrap(alg, key, encryptedKey, p2c, p2s) {
40
- const derived = await deriveKey(p2s, alg, p2c, key);
41
- return aeskw.unwrap(alg.slice(-6), derived, encryptedKey);
42
- }