@coinbase/cdp-core 0.0.67 → 0.0.69

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 (160) hide show
  1. package/README.md +149 -1
  2. package/dist/esm/index.native113.js +1 -1
  3. package/dist/esm/index.native137.js +2 -2
  4. package/dist/esm/index.native151.js +2 -4
  5. package/dist/esm/index.native152.js +109 -2
  6. package/dist/esm/index.native153.js +2 -109
  7. package/dist/esm/index.native154.js +4 -2
  8. package/dist/esm/index.native155.js +1 -1
  9. package/dist/esm/index.native156.js +7 -38
  10. package/dist/esm/index.native158.js +375 -67
  11. package/dist/esm/index.native159.js +832 -34
  12. package/dist/esm/index.native160.js +38 -20
  13. package/dist/esm/index.native161.js +2 -8
  14. package/dist/esm/index.native162.js +70 -2
  15. package/dist/esm/index.native163.js +30 -373
  16. package/dist/esm/index.native164.js +20 -832
  17. package/dist/esm/index.native175.js +2 -2
  18. package/dist/esm/index.native176.js +2 -2
  19. package/dist/esm/index.native177.js +2 -2
  20. package/dist/esm/index.native21.js +4 -2
  21. package/dist/esm/index.native31.js +1 -1
  22. package/dist/esm/index.native35.js +13 -12
  23. package/dist/esm/index.native37.js +4 -2
  24. package/dist/esm/index.native51.js +1 -1
  25. package/dist/esm/index.native52.js +3 -3
  26. package/dist/esm/index.native60.js +377 -2
  27. package/dist/esm/index.native61.js +2 -379
  28. package/dist/esm/index.native62.js +65 -28
  29. package/dist/esm/index.native63.js +364 -28
  30. package/dist/esm/index.native64.js +4 -2
  31. package/dist/esm/index.native65.js +28 -65
  32. package/dist/esm/index.native66.js +28 -364
  33. package/dist/esm/index.native7.js +6 -10
  34. package/dist/esm/index.web104.js +1 -1
  35. package/dist/esm/index.web107.js +6 -6
  36. package/dist/esm/index.web114.js +2 -2
  37. package/dist/esm/index.web118.js +1 -1
  38. package/dist/esm/index.web122.js +3 -20
  39. package/dist/esm/index.web123.js +21 -10
  40. package/dist/esm/index.web124.js +9 -19
  41. package/dist/esm/index.web125.js +15 -89
  42. package/dist/esm/index.web126.js +92 -19
  43. package/dist/esm/index.web127.js +18 -115
  44. package/dist/esm/index.web128.js +112 -73
  45. package/dist/esm/index.web150.js +7 -3
  46. package/dist/esm/index.web151.js +2 -39
  47. package/dist/esm/index.web152.js +378 -2
  48. package/dist/esm/index.web153.js +832 -69
  49. package/dist/esm/index.web154.js +37 -33
  50. package/dist/esm/index.web155.js +2 -21
  51. package/dist/esm/index.web156.js +69 -7
  52. package/dist/esm/index.web157.js +35 -2
  53. package/dist/esm/index.web158.js +17 -374
  54. package/dist/esm/index.web159.js +78 -832
  55. package/dist/esm/index.web20.js +4 -2
  56. package/dist/esm/index.web29.js +1 -1
  57. package/dist/esm/index.web33.js +13 -12
  58. package/dist/esm/index.web35.js +4 -2
  59. package/dist/esm/index.web6.js +6 -10
  60. package/dist/native/index.native113.js +1 -1
  61. package/dist/native/index.native137.js +2 -2
  62. package/dist/native/index.native151.js +2 -4
  63. package/dist/native/index.native152.js +109 -2
  64. package/dist/native/index.native153.js +2 -109
  65. package/dist/native/index.native154.js +4 -2
  66. package/dist/native/index.native155.js +1 -1
  67. package/dist/native/index.native156.js +7 -38
  68. package/dist/native/index.native158.js +375 -67
  69. package/dist/native/index.native159.js +832 -34
  70. package/dist/native/index.native160.js +38 -20
  71. package/dist/native/index.native161.js +2 -8
  72. package/dist/native/index.native162.js +70 -2
  73. package/dist/native/index.native163.js +30 -373
  74. package/dist/native/index.native164.js +20 -832
  75. package/dist/native/index.native175.js +2 -2
  76. package/dist/native/index.native176.js +2 -2
  77. package/dist/native/index.native177.js +2 -2
  78. package/dist/native/index.native21.js +4 -2
  79. package/dist/native/index.native31.js +1 -1
  80. package/dist/native/index.native35.js +13 -12
  81. package/dist/native/index.native37.js +4 -2
  82. package/dist/native/index.native51.js +1 -1
  83. package/dist/native/index.native52.js +3 -3
  84. package/dist/native/index.native60.js +377 -2
  85. package/dist/native/index.native61.js +2 -379
  86. package/dist/native/index.native62.js +65 -28
  87. package/dist/native/index.native63.js +364 -28
  88. package/dist/native/index.native64.js +4 -2
  89. package/dist/native/index.native65.js +28 -65
  90. package/dist/native/index.native66.js +28 -364
  91. package/dist/native/index.native7.js +6 -10
  92. package/dist/native-types/actions/initiateMfaEnrollment.d.ts +9 -0
  93. package/dist/native-types/actions/initiateMfaVerification.d.ts +2 -0
  94. package/dist/native-types/actions/submitMfaEnrollment.d.ts +10 -0
  95. package/dist/native-types/actions/submitMfaVerification.d.ts +6 -0
  96. package/dist/native-types/auth/authManager.d.ts +3 -1
  97. package/dist/native-types/auth/toAuthState.d.ts +10 -3
  98. package/dist/native-types/auth/types.d.ts +3 -1
  99. package/dist/native-types/auth/withAuth.d.ts +1 -1
  100. package/dist/native-types/core.d.ts +3 -1
  101. package/dist/native-types/index.d.ts +4 -0
  102. package/dist/native-types/mocks/mockAuthManager.d.ts +3 -1
  103. package/dist/native-types/shared/validators.d.ts +4 -0
  104. package/dist/native-types/types.d.ts +2 -1
  105. package/dist/native-types/version.d.ts +1 -1
  106. package/dist/types/actions/initiateMfaEnrollment.d.ts +9 -0
  107. package/dist/types/actions/initiateMfaVerification.d.ts +2 -0
  108. package/dist/types/actions/submitMfaEnrollment.d.ts +10 -0
  109. package/dist/types/actions/submitMfaVerification.d.ts +6 -0
  110. package/dist/types/auth/authManager.d.ts +3 -1
  111. package/dist/types/auth/toAuthState.d.ts +10 -3
  112. package/dist/types/auth/types.d.ts +3 -1
  113. package/dist/types/auth/withAuth.d.ts +1 -1
  114. package/dist/types/core.d.ts +3 -1
  115. package/dist/types/index.d.ts +4 -0
  116. package/dist/types/mocks/mockAuthManager.d.ts +3 -1
  117. package/dist/types/shared/validators.d.ts +4 -0
  118. package/dist/types/types.d.ts +2 -1
  119. package/dist/types/version.d.ts +1 -1
  120. package/dist/web/index.web104.js +1 -1
  121. package/dist/web/index.web107.js +6 -6
  122. package/dist/web/index.web114.js +2 -2
  123. package/dist/web/index.web118.js +1 -1
  124. package/dist/web/index.web122.js +3 -20
  125. package/dist/web/index.web123.js +21 -10
  126. package/dist/web/index.web124.js +9 -19
  127. package/dist/web/index.web125.js +15 -89
  128. package/dist/web/index.web126.js +92 -19
  129. package/dist/web/index.web127.js +18 -115
  130. package/dist/web/index.web128.js +112 -73
  131. package/dist/web/index.web150.js +7 -3
  132. package/dist/web/index.web151.js +2 -39
  133. package/dist/web/index.web152.js +378 -2
  134. package/dist/web/index.web153.js +832 -69
  135. package/dist/web/index.web154.js +37 -33
  136. package/dist/web/index.web155.js +2 -21
  137. package/dist/web/index.web156.js +69 -7
  138. package/dist/web/index.web157.js +35 -2
  139. package/dist/web/index.web158.js +17 -374
  140. package/dist/web/index.web159.js +78 -832
  141. package/dist/web/index.web20.js +4 -2
  142. package/dist/web/index.web29.js +1 -1
  143. package/dist/web/index.web33.js +13 -12
  144. package/dist/web/index.web35.js +4 -2
  145. package/dist/web/index.web6.js +6 -10
  146. package/dist/web-types/actions/initiateMfaEnrollment.d.ts +9 -0
  147. package/dist/web-types/actions/initiateMfaVerification.d.ts +2 -0
  148. package/dist/web-types/actions/submitMfaEnrollment.d.ts +10 -0
  149. package/dist/web-types/actions/submitMfaVerification.d.ts +6 -0
  150. package/dist/web-types/auth/authManager.d.ts +3 -1
  151. package/dist/web-types/auth/toAuthState.d.ts +10 -3
  152. package/dist/web-types/auth/types.d.ts +3 -1
  153. package/dist/web-types/auth/withAuth.d.ts +1 -1
  154. package/dist/web-types/core.d.ts +3 -1
  155. package/dist/web-types/index.d.ts +4 -0
  156. package/dist/web-types/mocks/mockAuthManager.d.ts +3 -1
  157. package/dist/web-types/shared/validators.d.ts +4 -0
  158. package/dist/web-types/types.d.ts +2 -1
  159. package/dist/web-types/version.d.ts +1 -1
  160. package/package.json +3 -3
@@ -13,6 +13,10 @@ export { linkApple } from './actions/linkApple.js';
13
13
  export { createEvmEoaAccount } from './actions/createEvmEoaAccount.js';
14
14
  export { createEvmSmartAccount, type CreateEvmSmartAccountOptions, } from './actions/createEvmSmartAccount.js';
15
15
  export { createSolanaAccount } from './actions/createSolanaAccount.js';
16
+ export { initiateMfaEnrollment, type InitiateMfaEnrollmentResult, type InitiateMfaOptions, } from './actions/initiateMfaEnrollment.js';
17
+ export { submitMfaEnrollment, type SubmitMfaEnrollmentOptions, type SubmitMfaEnrollmentResult, } from './actions/submitMfaEnrollment.js';
18
+ export { initiateMfaVerification } from './actions/initiateMfaVerification.js';
19
+ export { submitMfaVerification, type SubmitMfaVerificationOptions, } from './actions/submitMfaVerification.js';
16
20
  export * from './types.js';
17
21
  export * from './viem/toViemAccount.js';
18
22
  export * from './errors.js';
@@ -9,7 +9,9 @@ export declare class MockAuthManager implements IAuthManager {
9
9
  isSignedIn(): Promise<boolean>;
10
10
  signOut(): Promise<void>;
11
11
  addAuthStateChangeCallback(callback: OnAuthStateChangeFn): void;
12
- getToken(): Promise<string | null>;
12
+ getToken(options?: {
13
+ forceRefresh?: boolean;
14
+ }): Promise<string | null>;
13
15
  getTokenExpiration(): Promise<number | null>;
14
16
  getWalletSecretId(): Promise<string>;
15
17
  getXWalletAuth(_options: {
@@ -4,3 +4,7 @@ export declare function validateUserCanCreateAccount(user: User | null, authStat
4
4
  user: User;
5
5
  authState: AuthState;
6
6
  };
7
+ export declare function validateUserAuthState(user: User | null, authState: AuthState | null): {
8
+ user: User;
9
+ authState: AuthState;
10
+ };
@@ -1,4 +1,4 @@
1
- import { SendEvmTransactionWithEndUserAccountBodyNetwork, SendSolanaTransactionWithEndUserAccountBodyNetwork, APIError, APIErrorType, ErrorType, HttpErrorType, EvmUserOperation, OAuth2ProviderType, OAuth2Authentication } from '@coinbase/cdp-api-client';
1
+ import { SendEvmTransactionWithEndUserAccountBodyNetwork, SendSolanaTransactionWithEndUserAccountBodyNetwork, APIError, APIErrorType, ErrorType, HttpErrorType, EvmUserOperation, OAuth2ProviderType, OAuth2Authentication, MFAMethods } from '@coinbase/cdp-api-client';
2
2
  import { TransactionSerializableEIP1559 } from 'viem';
3
3
  export { APIError, type APIErrorType, ErrorType, HttpErrorType, SendEvmTransactionWithEndUserAccountBodyNetwork, SendSolanaTransactionWithEndUserAccountBodyNetwork, OAuth2ProviderType, };
4
4
  export declare class CustomAuthError extends Error {
@@ -51,6 +51,7 @@ export type User = {
51
51
  evmAccounts?: EvmAddress[];
52
52
  evmSmartAccounts?: EvmAddress[];
53
53
  solanaAccounts?: SolanaAddress[];
54
+ mfaMethods?: MFAMethods;
54
55
  };
55
56
  export type EmailAuthentication = {
56
57
  type: "email";
@@ -1 +1 @@
1
- export declare const VERSION = "0.0.67";
1
+ export declare const VERSION = "0.0.69";
@@ -1,4 +1,4 @@
1
- const o = "0.0.67";
1
+ const o = "0.0.69";
2
2
  export {
3
3
  o as VERSION
4
4
  };
@@ -1,11 +1,11 @@
1
- import { encode as d } from "./index.web122.js";
2
- import y from "./index.web123.js";
3
- import b from "./index.web124.js";
1
+ import { encode as d } from "./index.web123.js";
2
+ import y from "./index.web124.js";
3
+ import b from "./index.web125.js";
4
4
  import { JWSInvalid as r } from "./index.web57.js";
5
5
  import { encoder as s, concat as u, decoder as h } from "./index.web108.js";
6
- import g from "./index.web125.js";
7
- import H from "./index.web126.js";
8
- import P from "./index.web127.js";
6
+ import g from "./index.web126.js";
7
+ import H from "./index.web127.js";
8
+ import P from "./index.web128.js";
9
9
  class x {
10
10
  #r;
11
11
  #e;
@@ -1,5 +1,5 @@
1
- import { getDefaultExportFromCjs as r } from "./index.web150.js";
2
- import { __require as o } from "./index.web151.js";
1
+ import { getDefaultExportFromCjs as r } from "./index.web122.js";
2
+ import { __require as o } from "./index.web154.js";
3
3
  var t = o();
4
4
  const a = /* @__PURE__ */ r(t);
5
5
  export {
@@ -1,4 +1,4 @@
1
- import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index.web128.js";
1
+ import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index.web159.js";
2
2
  import { createHasher as u, clean as C, rotr as i } from "./index.web117.js";
3
3
  const B = /* @__PURE__ */ Uint32Array.from([
4
4
  1116352408,
@@ -1,23 +1,6 @@
1
- import { encoder as t, decoder as o } from "./index.web108.js";
2
- import { encodeBase64 as c, decodeBase64 as a } from "./index.web164.js";
3
- function i(r) {
4
- if (Uint8Array.fromBase64)
5
- return Uint8Array.fromBase64(typeof r == "string" ? r : o.decode(r), {
6
- alphabet: "base64url"
7
- });
8
- let e = r;
9
- e instanceof Uint8Array && (e = o.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
10
- try {
11
- return a(e);
12
- } catch {
13
- throw new TypeError("The input to be decoded is not correctly encoded.");
14
- }
15
- }
16
- function p(r) {
17
- let e = r;
18
- return typeof e == "string" && (e = t.encode(e)), Uint8Array.prototype.toBase64 ? e.toBase64({ alphabet: "base64url", omitPadding: !0 }) : c(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1
+ function e(t) {
2
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
19
3
  }
20
4
  export {
21
- i as decode,
22
- p as encode
5
+ e as getDefaultExportFromCjs
23
6
  };
@@ -1,12 +1,23 @@
1
- import n from "./index.web165.js";
2
- import s from "./index.web166.js";
3
- import a from "./index.web167.js";
4
- const y = async (t, o, e) => {
5
- const r = await a(t, o, "sign");
6
- s(t, r);
7
- const i = await crypto.subtle.sign(n(t, r.algorithm), r, e);
8
- return new Uint8Array(i);
9
- };
1
+ import { encoder as t, decoder as o } from "./index.web108.js";
2
+ import { encodeBase64 as c, decodeBase64 as a } from "./index.web164.js";
3
+ function i(r) {
4
+ if (Uint8Array.fromBase64)
5
+ return Uint8Array.fromBase64(typeof r == "string" ? r : o.decode(r), {
6
+ alphabet: "base64url"
7
+ });
8
+ let e = r;
9
+ e instanceof Uint8Array && (e = o.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
10
+ try {
11
+ return a(e);
12
+ } catch {
13
+ throw new TypeError("The input to be decoded is not correctly encoded.");
14
+ }
15
+ }
16
+ function p(r) {
17
+ let e = r;
18
+ return typeof e == "string" && (e = t.encode(e)), Uint8Array.prototype.toBase64 ? e.toBase64({ alphabet: "base64url", omitPadding: !0 }) : c(e).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
19
+ }
10
20
  export {
11
- y as default
21
+ i as decode,
22
+ p as encode
12
23
  };
@@ -1,22 +1,12 @@
1
- const a = (...o) => {
2
- const t = o.filter(Boolean);
3
- if (t.length === 0 || t.length === 1)
4
- return !0;
5
- let e;
6
- for (const s of t) {
7
- const r = Object.keys(s);
8
- if (!e || e.size === 0) {
9
- e = new Set(r);
10
- continue;
11
- }
12
- for (const n of r) {
13
- if (e.has(n))
14
- return !1;
15
- e.add(n);
16
- }
17
- }
18
- return !0;
1
+ import n from "./index.web165.js";
2
+ import s from "./index.web166.js";
3
+ import a from "./index.web167.js";
4
+ const y = async (t, o, e) => {
5
+ const r = await a(t, o, "sign");
6
+ s(t, r);
7
+ const i = await crypto.subtle.sign(n(t, r.algorithm), r, e);
8
+ return new Uint8Array(i);
19
9
  };
20
10
  export {
21
- a as default
11
+ y as default
22
12
  };
@@ -1,96 +1,22 @@
1
- import { withAlg as n } from "./index.web168.js";
2
- import c from "./index.web169.js";
3
- import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index.web170.js";
4
- const s = (r) => r?.[Symbol.toStringTag], o = (r, e, t) => {
5
- if (e.use !== void 0) {
6
- let i;
7
- switch (t) {
8
- case "sign":
9
- case "verify":
10
- i = "sig";
11
- break;
12
- case "encrypt":
13
- case "decrypt":
14
- i = "enc";
15
- break;
1
+ const a = (...o) => {
2
+ const t = o.filter(Boolean);
3
+ if (t.length === 0 || t.length === 1)
4
+ return !0;
5
+ let e;
6
+ for (const s of t) {
7
+ const r = Object.keys(s);
8
+ if (!e || e.size === 0) {
9
+ e = new Set(r);
10
+ continue;
16
11
  }
17
- if (e.use !== i)
18
- throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
19
- }
20
- if (e.alg !== void 0 && e.alg !== r)
21
- throw new TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);
22
- if (Array.isArray(e.key_ops)) {
23
- let i;
24
- switch (!0) {
25
- case t === "sign":
26
- case r === "dir":
27
- case r.includes("CBC-HS"):
28
- i = t;
29
- break;
30
- case r.startsWith("PBES2"):
31
- i = "deriveBits";
32
- break;
33
- case /^A\d{3}(?:GCM)?(?:KW)?$/.test(r):
34
- !r.includes("GCM") && r.endsWith("KW") ? i = "unwrapKey" : i = t;
35
- break;
36
- case t === "encrypt":
37
- i = "wrapKey";
38
- break;
39
- case t === "decrypt":
40
- i = r.startsWith("RSA") ? "unwrapKey" : "deriveBits";
41
- break;
12
+ for (const n of r) {
13
+ if (e.has(n))
14
+ return !1;
15
+ e.add(n);
42
16
  }
43
- if (i && e.key_ops?.includes?.(i) === !1)
44
- throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
45
17
  }
46
18
  return !0;
47
- }, h = (r, e, t) => {
48
- if (!(e instanceof Uint8Array)) {
49
- if (p(e)) {
50
- if (a(e) && o(r, e, t))
51
- return;
52
- 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');
53
- }
54
- if (!c(e))
55
- throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
56
- if (e.type !== "secret")
57
- throw new TypeError(`${s(e)} instances for symmetric algorithms must be of type "secret"`);
58
- }
59
- }, m = (r, e, t) => {
60
- if (p(e))
61
- switch (t) {
62
- case "decrypt":
63
- case "sign":
64
- if (f(e) && o(r, e, t))
65
- return;
66
- throw new TypeError("JSON Web Key for this operation be a private JWK");
67
- case "encrypt":
68
- case "verify":
69
- if (y(e) && o(r, e, t))
70
- return;
71
- throw new TypeError("JSON Web Key for this operation be a public JWK");
72
- }
73
- if (!c(e))
74
- throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key"));
75
- if (e.type === "secret")
76
- throw new TypeError(`${s(e)} instances for asymmetric algorithms must not be of type "secret"`);
77
- if (e.type === "public")
78
- switch (t) {
79
- case "sign":
80
- throw new TypeError(`${s(e)} instances for asymmetric algorithm signing must be of type "private"`);
81
- case "decrypt":
82
- throw new TypeError(`${s(e)} instances for asymmetric algorithm decryption must be of type "private"`);
83
- }
84
- if (e.type === "private")
85
- switch (t) {
86
- case "verify":
87
- throw new TypeError(`${s(e)} instances for asymmetric algorithm verifying must be of type "public"`);
88
- case "encrypt":
89
- throw new TypeError(`${s(e)} instances for asymmetric algorithm encryption must be of type "public"`);
90
- }
91
- }, d = (r, e, t) => {
92
- r.startsWith("HS") || r === "dir" || r.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(r) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(r) ? h(r, e, t) : m(r, e, t);
93
19
  };
94
20
  export {
95
- d as default
21
+ a as default
96
22
  };
@@ -1,23 +1,96 @@
1
- import { JOSENotSupported as f } from "./index.web57.js";
2
- const w = (n, r, a, e, s) => {
3
- if (s.crit !== void 0 && e?.crit === void 0)
4
- throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');
5
- if (!e || e.crit === void 0)
6
- return /* @__PURE__ */ new Set();
7
- if (!Array.isArray(e.crit) || e.crit.length === 0 || e.crit.some((i) => typeof i != "string" || i.length === 0))
8
- throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
9
- let t;
10
- a !== void 0 ? t = new Map([...Object.entries(a), ...r.entries()]) : t = r;
11
- for (const i of e.crit) {
12
- if (!t.has(i))
13
- throw new f(`Extension Header Parameter "${i}" is not recognized`);
14
- if (s[i] === void 0)
15
- throw new n(`Extension Header Parameter "${i}" is missing`);
16
- if (t.get(i) && e[i] === void 0)
17
- throw new n(`Extension Header Parameter "${i}" MUST be integrity protected`);
1
+ import { withAlg as n } from "./index.web168.js";
2
+ import c from "./index.web169.js";
3
+ import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index.web170.js";
4
+ const s = (r) => r?.[Symbol.toStringTag], o = (r, e, t) => {
5
+ if (e.use !== void 0) {
6
+ let i;
7
+ switch (t) {
8
+ case "sign":
9
+ case "verify":
10
+ i = "sig";
11
+ break;
12
+ case "encrypt":
13
+ case "decrypt":
14
+ i = "enc";
15
+ break;
16
+ }
17
+ if (e.use !== i)
18
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
18
19
  }
19
- return new Set(e.crit);
20
+ if (e.alg !== void 0 && e.alg !== r)
21
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);
22
+ if (Array.isArray(e.key_ops)) {
23
+ let i;
24
+ switch (!0) {
25
+ case t === "sign":
26
+ case r === "dir":
27
+ case r.includes("CBC-HS"):
28
+ i = t;
29
+ break;
30
+ case r.startsWith("PBES2"):
31
+ i = "deriveBits";
32
+ break;
33
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(r):
34
+ !r.includes("GCM") && r.endsWith("KW") ? i = "unwrapKey" : i = t;
35
+ break;
36
+ case t === "encrypt":
37
+ i = "wrapKey";
38
+ break;
39
+ case t === "decrypt":
40
+ i = r.startsWith("RSA") ? "unwrapKey" : "deriveBits";
41
+ break;
42
+ }
43
+ if (i && e.key_ops?.includes?.(i) === !1)
44
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
45
+ }
46
+ return !0;
47
+ }, h = (r, e, t) => {
48
+ if (!(e instanceof Uint8Array)) {
49
+ if (p(e)) {
50
+ if (a(e) && o(r, e, t))
51
+ return;
52
+ 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');
53
+ }
54
+ if (!c(e))
55
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
56
+ if (e.type !== "secret")
57
+ throw new TypeError(`${s(e)} instances for symmetric algorithms must be of type "secret"`);
58
+ }
59
+ }, m = (r, e, t) => {
60
+ if (p(e))
61
+ switch (t) {
62
+ case "decrypt":
63
+ case "sign":
64
+ if (f(e) && o(r, e, t))
65
+ return;
66
+ throw new TypeError("JSON Web Key for this operation be a private JWK");
67
+ case "encrypt":
68
+ case "verify":
69
+ if (y(e) && o(r, e, t))
70
+ return;
71
+ throw new TypeError("JSON Web Key for this operation be a public JWK");
72
+ }
73
+ if (!c(e))
74
+ throw new TypeError(n(r, e, "CryptoKey", "KeyObject", "JSON Web Key"));
75
+ if (e.type === "secret")
76
+ throw new TypeError(`${s(e)} instances for asymmetric algorithms must not be of type "secret"`);
77
+ if (e.type === "public")
78
+ switch (t) {
79
+ case "sign":
80
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm signing must be of type "private"`);
81
+ case "decrypt":
82
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm decryption must be of type "private"`);
83
+ }
84
+ if (e.type === "private")
85
+ switch (t) {
86
+ case "verify":
87
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm verifying must be of type "public"`);
88
+ case "encrypt":
89
+ throw new TypeError(`${s(e)} instances for asymmetric algorithm encryption must be of type "public"`);
90
+ }
91
+ }, d = (r, e, t) => {
92
+ r.startsWith("HS") || r === "dir" || r.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(r) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(r) ? h(r, e, t) : m(r, e, t);
20
93
  };
21
94
  export {
22
- w as default
95
+ d as default
23
96
  };
@@ -1,120 +1,23 @@
1
- import { isJWK as p } from "./index.web170.js";
2
- import { decode as m } from "./index.web122.js";
3
- import y from "./index.web171.js";
4
- import { isCryptoKey as S, isKeyObject as K } from "./index.web169.js";
5
- let c;
6
- const f = async (e, r, s, i = !1) => {
7
- c ||= /* @__PURE__ */ new WeakMap();
8
- let n = c.get(e);
9
- if (n?.[s])
10
- return n[s];
11
- const t = await y({ ...r, alg: s });
12
- return i && Object.freeze(e), n ? n[s] = t : c.set(e, { [s]: t }), t;
13
- }, E = (e, r) => {
14
- c ||= /* @__PURE__ */ new WeakMap();
15
- let s = c.get(e);
16
- if (s?.[r])
17
- return s[r];
18
- const i = e.type === "public", n = !!i;
1
+ import { JOSENotSupported as f } from "./index.web57.js";
2
+ const w = (n, r, a, e, s) => {
3
+ if (s.crit !== void 0 && e?.crit === void 0)
4
+ throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');
5
+ if (!e || e.crit === void 0)
6
+ return /* @__PURE__ */ new Set();
7
+ if (!Array.isArray(e.crit) || e.crit.length === 0 || e.crit.some((i) => typeof i != "string" || i.length === 0))
8
+ throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
19
9
  let t;
20
- if (e.asymmetricKeyType === "x25519") {
21
- switch (r) {
22
- case "ECDH-ES":
23
- case "ECDH-ES+A128KW":
24
- case "ECDH-ES+A192KW":
25
- case "ECDH-ES+A256KW":
26
- break;
27
- default:
28
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
29
- }
30
- t = e.toCryptoKey(e.asymmetricKeyType, n, i ? [] : ["deriveBits"]);
10
+ a !== void 0 ? t = new Map([...Object.entries(a), ...r.entries()]) : t = r;
11
+ for (const i of e.crit) {
12
+ if (!t.has(i))
13
+ throw new f(`Extension Header Parameter "${i}" is not recognized`);
14
+ if (s[i] === void 0)
15
+ throw new n(`Extension Header Parameter "${i}" is missing`);
16
+ if (t.get(i) && e[i] === void 0)
17
+ throw new n(`Extension Header Parameter "${i}" MUST be integrity protected`);
31
18
  }
32
- if (e.asymmetricKeyType === "ed25519") {
33
- if (r !== "EdDSA" && r !== "Ed25519")
34
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
35
- t = e.toCryptoKey(e.asymmetricKeyType, n, [
36
- i ? "verify" : "sign"
37
- ]);
38
- }
39
- if (e.asymmetricKeyType === "rsa") {
40
- let a;
41
- switch (r) {
42
- case "RSA-OAEP":
43
- a = "SHA-1";
44
- break;
45
- case "RS256":
46
- case "PS256":
47
- case "RSA-OAEP-256":
48
- a = "SHA-256";
49
- break;
50
- case "RS384":
51
- case "PS384":
52
- case "RSA-OAEP-384":
53
- a = "SHA-384";
54
- break;
55
- case "RS512":
56
- case "PS512":
57
- case "RSA-OAEP-512":
58
- a = "SHA-512";
59
- break;
60
- default:
61
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
62
- }
63
- if (r.startsWith("RSA-OAEP"))
64
- return e.toCryptoKey({
65
- name: "RSA-OAEP",
66
- hash: a
67
- }, n, i ? ["encrypt"] : ["decrypt"]);
68
- t = e.toCryptoKey({
69
- name: r.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
70
- hash: a
71
- }, n, [i ? "verify" : "sign"]);
72
- }
73
- if (e.asymmetricKeyType === "ec") {
74
- const o = (/* @__PURE__ */ new Map([
75
- ["prime256v1", "P-256"],
76
- ["secp384r1", "P-384"],
77
- ["secp521r1", "P-521"]
78
- ])).get(e.asymmetricKeyDetails?.namedCurve);
79
- if (!o)
80
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
81
- r === "ES256" && o === "P-256" && (t = e.toCryptoKey({
82
- name: "ECDSA",
83
- namedCurve: o
84
- }, n, [i ? "verify" : "sign"])), r === "ES384" && o === "P-384" && (t = e.toCryptoKey({
85
- name: "ECDSA",
86
- namedCurve: o
87
- }, n, [i ? "verify" : "sign"])), r === "ES512" && o === "P-521" && (t = e.toCryptoKey({
88
- name: "ECDSA",
89
- namedCurve: o
90
- }, n, [i ? "verify" : "sign"])), r.startsWith("ECDH-ES") && (t = e.toCryptoKey({
91
- name: "ECDH",
92
- namedCurve: o
93
- }, n, i ? [] : ["deriveBits"]));
94
- }
95
- if (!t)
96
- throw new TypeError("given KeyObject instance cannot be used for this algorithm");
97
- return s ? s[r] = t : c.set(e, { [r]: t }), t;
98
- }, d = async (e, r) => {
99
- if (e instanceof Uint8Array || S(e))
100
- return e;
101
- if (K(e)) {
102
- if (e.type === "secret")
103
- return e.export();
104
- if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
105
- try {
106
- return E(e, r);
107
- } catch (i) {
108
- if (i instanceof TypeError)
109
- throw i;
110
- }
111
- let s = e.export({ format: "jwk" });
112
- return f(e, s, r);
113
- }
114
- if (p(e))
115
- return e.k ? m(e.k) : f(e, e, r, !0);
116
- throw new Error("unreachable");
19
+ return new Set(e.crit);
117
20
  };
118
21
  export {
119
- d as default
22
+ w as default
120
23
  };