@coinbase/cdp-core 0.0.18 → 0.0.19

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/dist/esm/index.js CHANGED
@@ -1,31 +1,34 @@
1
- import { exportEvmAccount as n, getCurrentUser as m, initialize as E, isSignedIn as a, onAuthStateChange as s, sendEvmTransaction as p, signEvmHash as c, signEvmMessage as d, signEvmTransaction as g, signEvmTypedData as v, signInWithEmail as T, signOut as A, verifyEmailOTP as f } from "./index2.js";
2
- import { APIError as x, ErrorType as h, HttpErrorType as l, SendEvmTransactionWithEndUserAccountBodyNetwork as y } from "@coinbase/cdp-api-client";
1
+ import { exportEvmAccount as n, getAccessToken as m, getCurrentUser as s, initialize as E, isSignedIn as a, onAuthStateChange as p, sendEvmTransaction as c, signEvmHash as g, signEvmMessage as d, signEvmTransaction as v, signEvmTypedData as T, signInWithEmail as A, signInWithSms as f, signOut as S, verifyEmailOTP as h, verifySmsOTP as u } from "./index2.js";
2
+ import { APIError as y, ErrorType as P, HttpErrorType as l, SendEvmTransactionWithEndUserAccountBodyNetwork as D } from "@coinbase/cdp-api-client";
3
3
  import "viem";
4
- import { createCDPEmbeddedWallet as P } from "./index3.js";
5
- import { EIP1193ProviderError as C, STANDARD_ERROR_CODES as I } from "./index4.js";
4
+ import { createCDPEmbeddedWallet as O } from "./index3.js";
5
+ import { EIP1193ProviderError as R, STANDARD_ERROR_CODES as W } from "./index4.js";
6
6
  import "ox";
7
7
  import "zustand";
8
- import { toViemAccount as R } from "./index5.js";
8
+ import { toViemAccount as H } from "./index5.js";
9
9
  export {
10
- x as APIError,
11
- C as EIP1193ProviderError,
12
- h as ErrorType,
10
+ y as APIError,
11
+ R as EIP1193ProviderError,
12
+ P as ErrorType,
13
13
  l as HttpErrorType,
14
- I as STANDARD_ERROR_CODES,
15
- y as SendEvmTransactionWithEndUserAccountBodyNetwork,
16
- P as createCDPEmbeddedWallet,
14
+ W as STANDARD_ERROR_CODES,
15
+ D as SendEvmTransactionWithEndUserAccountBodyNetwork,
16
+ O as createCDPEmbeddedWallet,
17
17
  n as exportEvmAccount,
18
- m as getCurrentUser,
18
+ m as getAccessToken,
19
+ s as getCurrentUser,
19
20
  E as initialize,
20
21
  a as isSignedIn,
21
- s as onAuthStateChange,
22
- p as sendEvmTransaction,
23
- c as signEvmHash,
22
+ p as onAuthStateChange,
23
+ c as sendEvmTransaction,
24
+ g as signEvmHash,
24
25
  d as signEvmMessage,
25
- g as signEvmTransaction,
26
- v as signEvmTypedData,
27
- T as signInWithEmail,
28
- A as signOut,
29
- R as toViemAccount,
30
- f as verifyEmailOTP
26
+ v as signEvmTransaction,
27
+ T as signEvmTypedData,
28
+ A as signInWithEmail,
29
+ f as signInWithSms,
30
+ S as signOut,
31
+ H as toViemAccount,
32
+ h as verifyEmailOTP,
33
+ u as verifySmsOTP
31
34
  };
@@ -1,4 +1,4 @@
1
- import n from "./index85.js";
1
+ import n from "./index86.js";
2
2
  function r(t) {
3
3
  return n(t) && typeof t.kty == "string";
4
4
  }
@@ -1,4 +1,4 @@
1
- import { JOSENotSupported as s } from "./index71.js";
1
+ import { JOSENotSupported as s } from "./index73.js";
2
2
  function n(e) {
3
3
  let a, r;
4
4
  switch (e.kty) {
@@ -1,6 +1,6 @@
1
- import { CompactSign as i } from "./index70.js";
2
- import { JWTInvalid as r } from "./index71.js";
3
- import { JWTClaimsBuilder as n } from "./index72.js";
1
+ import { CompactSign as i } from "./index72.js";
2
+ import { JWTInvalid as r } from "./index73.js";
3
+ import { JWTClaimsBuilder as n } from "./index74.js";
4
4
  class d {
5
5
  #s;
6
6
  #t;
@@ -1,176 +1,190 @@
1
- import { configureCdpApiClient as w, setAuthManager as h, initiateAuthentication as y, verifyEmailAuthentication as f, createEndUserEvmAccount as I, signEvmHashWithEndUserAccount as l, signEvmTransactionWithEndUserAccount as A, sendEvmTransactionWithEndUserAccount as v, signEvmMessageWithEndUserAccount as E, signEvmTypedDataWithEndUserAccount as k, exportEndUserEvmAccount as M } from "@coinbase/cdp-api-client";
2
- import { AuthManager as S } from "./index6.js";
3
- import { toAuthState as u } from "./index7.js";
4
- import { withAuth as i } from "./index8.js";
5
- import { createExportKeyPair as U } from "./index9.js";
6
- import { decryptWithPrivateKey as C } from "./index10.js";
7
- import { MockAuthManager as T } from "./index11.js";
8
- import { mockUser as d } from "./index12.js";
9
- import { isChainSupportedForCDPSends as j } from "./index13.js";
10
- import { getConfig as r, setCoreAuthManager as g, getCoreAuthManager as n, setConfig as P } from "./index14.js";
1
+ import { configureCdpApiClient as I, setAuthManager as l, initiateAuthentication as v, createEndUserEvmAccount as A, verifyEmailAuthentication as E, verifySmsAuthentication as k, signEvmHashWithEndUserAccount as S, signEvmTransactionWithEndUserAccount as M, sendEvmTransactionWithEndUserAccount as T, signEvmMessageWithEndUserAccount as U, signEvmTypedDataWithEndUserAccount as C, exportEndUserEvmAccount as j } from "@coinbase/cdp-api-client";
2
+ import { AuthManager as P } from "./index6.js";
3
+ import { toAuthState as d } from "./index7.js";
4
+ import { withAuth as o } from "./index8.js";
5
+ import { createExportKeyPair as x } from "./index9.js";
6
+ import { decryptWithPrivateKey as b } from "./index10.js";
7
+ import { MockAuthManager as K } from "./index11.js";
8
+ import { mockUser as g } from "./index12.js";
9
+ import { isChainSupportedForCDPSends as W } from "./index13.js";
10
+ import { getConfig as n, setCoreAuthManager as m, getCoreAuthManager as s, setConfig as D } from "./index14.js";
11
11
  import "viem";
12
- import { serializeTransaction as m } from "./index15.js";
13
- const B = async (e) => {
12
+ import { serializeTransaction as p } from "./index15.js";
13
+ const Q = async (e) => {
14
14
  if (!e.projectId)
15
15
  throw new Error("Project ID is required");
16
- let s;
16
+ let r;
17
17
  try {
18
- s = r().projectId !== e.projectId;
18
+ r = n().projectId !== e.projectId;
19
19
  } catch {
20
- s = !0;
20
+ r = !0;
21
21
  }
22
- if (P(e), r().useMock) {
23
- g(new T(r().projectId));
22
+ if (D(e), n().useMock) {
23
+ m(new K(n().projectId));
24
24
  return;
25
25
  }
26
- if (w({
27
- debugging: r().debugging,
28
- basePath: r().basePath
29
- }), s) {
30
- const t = new S(r().projectId);
31
- g(t), h(t);
26
+ if (I({
27
+ debugging: n().debugging,
28
+ basePath: n().basePath
29
+ }), r) {
30
+ const t = new P(n().projectId);
31
+ m(t), l(t);
32
32
  }
33
- await n().ensureInitialized();
34
- }, V = async (e) => {
35
- if (r().useMock)
36
- return {
37
- message: "Mock sign in initiated",
38
- flowId: "mock-flow-id"
39
- };
40
- if (await n().isSignedIn())
41
- throw new Error("User is already authenticated. Please sign out first.");
42
- const t = await y(r().projectId, {
43
- email: e.email,
44
- type: "email"
45
- });
46
- return {
47
- flowId: t.flowId,
48
- message: t.message
49
- };
50
- }, G = async (e) => {
51
- if (r().useMock)
52
- return await n().setAuthState({
53
- accessToken: "mock-access-token",
54
- expiresAt: Date.now() + 1e3 * 60 * 60 * 24,
55
- user: d
56
- }), {
57
- message: "Mock email OTP verified",
58
- user: d,
59
- isNewUser: !1
60
- };
61
- if (await n().isSignedIn())
62
- throw new Error("User is already authenticated. Please sign out first.");
63
- const t = await f(r().projectId, {
64
- flowId: e.flowId,
65
- otp: e.otp
66
- });
67
- let a = u(t.accessToken, t.validUntil, t.endUser);
68
- if (await n().setAuthState(a), !a.user.evmAccounts || a.user.evmAccounts.length === 0)
69
- try {
70
- const o = await n().getWalletSecretId(), p = await I(r().projectId, a.user.userId, {
71
- walletSecretId: o
72
- });
73
- a = u(t.accessToken, t.validUntil, p), await n().setAuthState(a);
74
- } catch (o) {
75
- throw new Error(`Failed to create EVM account: ${o}`);
76
- }
77
- const c = await n().getUser();
78
- return {
79
- message: t.message,
80
- user: c,
81
- isNewUser: t.isNewEndUser
82
- };
83
- }, J = async () => n().getUser(), L = async () => n().isSignedIn(), Q = async () => {
84
- if (r().useMock) {
85
- await n().signOut();
33
+ await s().ensureInitialized();
34
+ }, R = async (e) => h({
35
+ email: e.email,
36
+ type: "email"
37
+ }), X = async (e) => h({
38
+ phoneNumber: e.phoneNumber,
39
+ type: "sms"
40
+ }), Y = async (e) => w(
41
+ e,
42
+ "Mock email OTP verified",
43
+ (r, t) => E(r, t)
44
+ ), Z = async (e) => w(
45
+ e,
46
+ "Mock SMS OTP verified",
47
+ (r, t) => k(r, t)
48
+ ), _ = async () => s().getUser(), ee = async () => s().isSignedIn(), te = async () => {
49
+ if (n().useMock) {
50
+ await s().signOut();
86
51
  return;
87
52
  }
88
- if (!await n().isSignedIn())
53
+ if (!await s().isSignedIn())
89
54
  throw new Error("User not signed in");
90
- await n().signOut();
91
- }, R = (e) => {
92
- n().addAuthStateChangeCallback(e);
93
- }, X = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
94
- signature: (await l(r().projectId, s.userId, {
55
+ await s().signOut();
56
+ }, ne = async () => s().getToken(), re = (e) => {
57
+ s().addAuthStateChangeCallback(e);
58
+ }, se = async (e) => n().useMock ? { signature: "0x0" } : o(e, s(), async ({ user: r, walletSecretId: t }) => ({
59
+ signature: (await S(n().projectId, r.userId, {
95
60
  hash: e.hash,
96
61
  address: e.evmAccount,
97
62
  walletSecretId: t
98
63
  })).signature
99
- })), Y = async (e) => r().useMock ? { signedTransaction: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => {
100
- const a = m(e.transaction);
64
+ })), ae = async (e) => n().useMock ? { signedTransaction: "0x0" } : o(e, s(), async ({ user: r, walletSecretId: t }) => {
65
+ const i = p(e.transaction);
101
66
  return {
102
- signedTransaction: (await A(
103
- r().projectId,
104
- s.userId,
67
+ signedTransaction: (await M(
68
+ n().projectId,
69
+ r.userId,
105
70
  {
106
- transaction: a,
71
+ transaction: i,
107
72
  address: e.evmAccount,
108
73
  walletSecretId: t
109
74
  }
110
75
  )).signedTransaction
111
76
  };
112
- }), Z = async (e) => {
113
- if (!j(e.network))
77
+ }), ie = async (e) => {
78
+ if (!W(e.network))
114
79
  throw new Error(`Chain ${e.network} is not supported by the CDP Apis`);
115
- if (r().useMock)
80
+ if (n().useMock)
116
81
  return { transactionHash: "0x0" };
117
- const s = m(e.transaction);
118
- return i(e, n(), async ({ user: t, walletSecretId: a }) => ({
119
- transactionHash: (await v(
120
- r().projectId,
82
+ const r = p(e.transaction);
83
+ return o(e, s(), async ({ user: t, walletSecretId: i }) => ({
84
+ transactionHash: (await T(
85
+ n().projectId,
121
86
  t.userId,
122
87
  {
123
- transaction: s,
88
+ transaction: r,
124
89
  address: e.evmAccount,
125
- walletSecretId: a,
90
+ walletSecretId: i,
126
91
  network: e.network
127
92
  }
128
93
  )).transactionHash
129
94
  }));
130
- }, _ = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
131
- signature: (await E(r().projectId, s.userId, {
95
+ }, ce = async (e) => n().useMock ? { signature: "0x0" } : o(e, s(), async ({ user: r, walletSecretId: t }) => ({
96
+ signature: (await U(n().projectId, r.userId, {
132
97
  message: e.message,
133
98
  address: e.evmAccount,
134
99
  walletSecretId: t
135
100
  })).signature
136
- })), ee = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
137
- signature: (await k(r().projectId, s.userId, {
101
+ })), oe = async (e) => n().useMock ? { signature: "0x0" } : o(e, s(), async ({ user: r, walletSecretId: t }) => ({
102
+ signature: (await C(n().projectId, r.userId, {
138
103
  typedData: e.typedData,
139
104
  address: e.evmAccount,
140
105
  walletSecretId: t
141
106
  })).signature
142
- })), te = async (e) => {
143
- if (r().useMock)
107
+ })), ue = async (e) => {
108
+ if (n().useMock)
144
109
  return {
145
110
  privateKey: "mock-private-key"
146
111
  };
147
- const s = await U();
148
- return i(e, n(), async ({ user: t, walletSecretId: a }) => {
149
- const c = await M(r().projectId, t.userId, {
112
+ const r = await x();
113
+ return o(e, s(), async ({ user: t, walletSecretId: i }) => {
114
+ const a = await j(n().projectId, t.userId, {
150
115
  address: e.evmAccount,
151
- walletSecretId: a,
152
- exportEncryptionKey: s.publicKeyBase64
116
+ walletSecretId: i,
117
+ exportEncryptionKey: r.publicKeyBase64
153
118
  });
154
119
  return {
155
- privateKey: await C(
156
- s.privateKey,
157
- c.encryptedPrivateKey
120
+ privateKey: await b(
121
+ r.privateKey,
122
+ a.encryptedPrivateKey
158
123
  )
159
124
  };
160
125
  });
126
+ }, h = async (e) => {
127
+ if (n().useMock)
128
+ return {
129
+ message: "Mock sign in initiated",
130
+ flowId: "mock-flow-id"
131
+ };
132
+ if (await s().isSignedIn())
133
+ throw new Error("User is already authenticated. Please sign out first.");
134
+ const t = await v(n().projectId, e);
135
+ return {
136
+ flowId: t.flowId,
137
+ message: t.message
138
+ };
139
+ }, w = async (e, r, t) => {
140
+ if (n().useMock)
141
+ return await s().setAuthState({
142
+ accessToken: "mock-access-token",
143
+ expiresAt: Date.now() + 1e3 * 60 * 60 * 24,
144
+ user: g
145
+ }), {
146
+ message: r,
147
+ user: g,
148
+ isNewUser: !1
149
+ };
150
+ if (await s().isSignedIn())
151
+ throw new Error("User is already authenticated. Please sign out first.");
152
+ const a = await t(n().projectId, {
153
+ flowId: e.flowId,
154
+ otp: e.otp
155
+ });
156
+ let c = d(a.accessToken, a.validUntil, a.endUser);
157
+ if (await s().setAuthState(c), !c.user.evmAccounts || c.user.evmAccounts.length === 0)
158
+ try {
159
+ const u = await s().getWalletSecretId(), f = await A(n().projectId, c.user.userId, {
160
+ walletSecretId: u
161
+ });
162
+ c = d(a.accessToken, a.validUntil, f), await s().setAuthState(c);
163
+ } catch (u) {
164
+ throw new Error(`Failed to create EVM account: ${u}`);
165
+ }
166
+ const y = await s().getUser();
167
+ return {
168
+ message: a.message,
169
+ user: y,
170
+ isNewUser: a.isNewEndUser
171
+ };
161
172
  };
162
173
  export {
163
- te as exportEvmAccount,
164
- J as getCurrentUser,
165
- B as initialize,
166
- L as isSignedIn,
167
- R as onAuthStateChange,
168
- Z as sendEvmTransaction,
169
- X as signEvmHash,
170
- _ as signEvmMessage,
171
- Y as signEvmTransaction,
172
- ee as signEvmTypedData,
173
- V as signInWithEmail,
174
- Q as signOut,
175
- G as verifyEmailOTP
174
+ ue as exportEvmAccount,
175
+ ne as getAccessToken,
176
+ _ as getCurrentUser,
177
+ Q as initialize,
178
+ ee as isSignedIn,
179
+ re as onAuthStateChange,
180
+ ie as sendEvmTransaction,
181
+ se as signEvmHash,
182
+ ce as signEvmMessage,
183
+ ae as signEvmTransaction,
184
+ oe as signEvmTypedData,
185
+ R as signInWithEmail,
186
+ X as signInWithSms,
187
+ te as signOut,
188
+ Y as verifyEmailOTP,
189
+ Z as verifySmsOTP
176
190
  };
@@ -1,4 +1,4 @@
1
- import { chainConfig as a } from "./index86.js";
1
+ import { chainConfig as a } from "./index81.js";
2
2
  import { defineChain as t } from "./index25.js";
3
3
  const e = 11155111, r = /* @__PURE__ */ t({
4
4
  ...a,
@@ -1,4 +1,4 @@
1
- import { version as o } from "./index73.js";
1
+ import { version as o } from "./index70.js";
2
2
  let r = {
3
3
  getDocsUrl: ({ docsBaseUrl: s, docsPath: t = "", docsSlug: e }) => t ? `${s ?? "https://viem.sh"}${t}${e ? `#${e}` : ""}` : void 0,
4
4
  version: `viem@${o}`
@@ -1,4 +1,4 @@
1
- import { NegativeOffsetError as o, PositionOutOfBoundsError as e, RecursiveReadLimitExceededError as n } from "./index74.js";
1
+ import { NegativeOffsetError as o, PositionOutOfBoundsError as e, RecursiveReadLimitExceededError as n } from "./index71.js";
2
2
  const h = {
3
3
  bytes: new Uint8Array(),
4
4
  dataView: new DataView(new ArrayBuffer(0)),
@@ -1,19 +1,4 @@
1
- import { FlattenedSign as n } from "./index81.js";
2
- class o {
3
- #e;
4
- constructor(e) {
5
- this.#e = new n(e);
6
- }
7
- setProtectedHeader(e) {
8
- return this.#e.setProtectedHeader(e), this;
9
- }
10
- async sign(e, r) {
11
- const t = await this.#e.sign(e, r);
12
- if (t.payload === void 0)
13
- throw new TypeError("use the flattened module for creating JWS with b64: false");
14
- return `${t.protected}.${t.payload}.${t.signature}`;
15
- }
16
- }
1
+ const o = "2.33.0";
17
2
  export {
18
- o as CompactSign
3
+ o as version
19
4
  };
@@ -1,25 +1,23 @@
1
- class c extends Error {
2
- static code = "ERR_JOSE_GENERIC";
3
- code = "ERR_JOSE_GENERIC";
4
- constructor(s, e) {
5
- super(s, e), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
1
+ import { BaseError as o } from "./index47.js";
2
+ class i extends o {
3
+ constructor({ offset: e }) {
4
+ super(`Offset \`${e}\` cannot be negative.`, {
5
+ name: "NegativeOffsetError"
6
+ });
6
7
  }
7
8
  }
8
- class E extends c {
9
- static code = "ERR_JOSE_NOT_SUPPORTED";
10
- code = "ERR_JOSE_NOT_SUPPORTED";
11
- }
12
- class o extends c {
13
- static code = "ERR_JWS_INVALID";
14
- code = "ERR_JWS_INVALID";
9
+ class n extends o {
10
+ constructor({ length: e, position: r }) {
11
+ super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`, { name: "PositionOutOfBoundsError" });
12
+ }
15
13
  }
16
- class r extends c {
17
- static code = "ERR_JWT_INVALID";
18
- code = "ERR_JWT_INVALID";
14
+ class c extends o {
15
+ constructor({ count: e, limit: r }) {
16
+ super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${e}\`).`, { name: "RecursiveReadLimitExceededError" });
17
+ }
19
18
  }
20
19
  export {
21
- c as JOSEError,
22
- E as JOSENotSupported,
23
- o as JWSInvalid,
24
- r as JWTInvalid
20
+ i as NegativeOffsetError,
21
+ n as PositionOutOfBoundsError,
22
+ c as RecursiveReadLimitExceededError
25
23
  };
@@ -1,53 +1,19 @@
1
- import { encoder as n } from "./index82.js";
2
- import e from "./index83.js";
3
- import i from "./index84.js";
4
- import o from "./index85.js";
5
- function s(r, t) {
6
- if (!Number.isFinite(t))
7
- throw new TypeError(`Invalid ${r} input`);
8
- return t;
9
- }
10
- class d {
11
- #t;
12
- constructor(t) {
13
- if (!o(t))
14
- throw new TypeError("JWT Claims Set MUST be an object");
15
- this.#t = structuredClone(t);
16
- }
17
- data() {
18
- return n.encode(JSON.stringify(this.#t));
19
- }
20
- get iss() {
21
- return this.#t.iss;
22
- }
23
- set iss(t) {
24
- this.#t.iss = t;
25
- }
26
- get sub() {
27
- return this.#t.sub;
28
- }
29
- set sub(t) {
30
- this.#t.sub = t;
31
- }
32
- get aud() {
33
- return this.#t.aud;
34
- }
35
- set aud(t) {
36
- this.#t.aud = t;
37
- }
38
- set jti(t) {
39
- this.#t.jti = t;
40
- }
41
- set nbf(t) {
42
- typeof t == "number" ? this.#t.nbf = s("setNotBefore", t) : t instanceof Date ? this.#t.nbf = s("setNotBefore", e(t)) : this.#t.nbf = e(/* @__PURE__ */ new Date()) + i(t);
1
+ import { FlattenedSign as n } from "./index82.js";
2
+ class o {
3
+ #e;
4
+ constructor(e) {
5
+ this.#e = new n(e);
43
6
  }
44
- set exp(t) {
45
- typeof t == "number" ? this.#t.exp = s("setExpirationTime", t) : t instanceof Date ? this.#t.exp = s("setExpirationTime", e(t)) : this.#t.exp = e(/* @__PURE__ */ new Date()) + i(t);
7
+ setProtectedHeader(e) {
8
+ return this.#e.setProtectedHeader(e), this;
46
9
  }
47
- set iat(t) {
48
- typeof t > "u" ? this.#t.iat = e(/* @__PURE__ */ new Date()) : t instanceof Date ? this.#t.iat = s("setIssuedAt", e(t)) : typeof t == "string" ? this.#t.iat = s("setIssuedAt", e(/* @__PURE__ */ new Date()) + i(t)) : this.#t.iat = s("setIssuedAt", t);
10
+ async sign(e, r) {
11
+ const t = await this.#e.sign(e, r);
12
+ if (t.payload === void 0)
13
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
14
+ return `${t.protected}.${t.payload}.${t.signature}`;
49
15
  }
50
16
  }
51
17
  export {
52
- d as JWTClaimsBuilder
18
+ o as CompactSign
53
19
  };
@@ -1,4 +1,25 @@
1
- const o = "2.33.0";
1
+ class c extends Error {
2
+ static code = "ERR_JOSE_GENERIC";
3
+ code = "ERR_JOSE_GENERIC";
4
+ constructor(s, e) {
5
+ super(s, e), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
6
+ }
7
+ }
8
+ class E extends c {
9
+ static code = "ERR_JOSE_NOT_SUPPORTED";
10
+ code = "ERR_JOSE_NOT_SUPPORTED";
11
+ }
12
+ class o extends c {
13
+ static code = "ERR_JWS_INVALID";
14
+ code = "ERR_JWS_INVALID";
15
+ }
16
+ class r extends c {
17
+ static code = "ERR_JWT_INVALID";
18
+ code = "ERR_JWT_INVALID";
19
+ }
2
20
  export {
3
- o as version
21
+ c as JOSEError,
22
+ E as JOSENotSupported,
23
+ o as JWSInvalid,
24
+ r as JWTInvalid
4
25
  };
@@ -1,23 +1,53 @@
1
- import { BaseError as o } from "./index47.js";
2
- class i extends o {
3
- constructor({ offset: e }) {
4
- super(`Offset \`${e}\` cannot be negative.`, {
5
- name: "NegativeOffsetError"
6
- });
7
- }
1
+ import { encoder as n } from "./index83.js";
2
+ import e from "./index84.js";
3
+ import i from "./index85.js";
4
+ import o from "./index86.js";
5
+ function s(r, t) {
6
+ if (!Number.isFinite(t))
7
+ throw new TypeError(`Invalid ${r} input`);
8
+ return t;
8
9
  }
9
- class n extends o {
10
- constructor({ length: e, position: r }) {
11
- super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`, { name: "PositionOutOfBoundsError" });
10
+ class d {
11
+ #t;
12
+ constructor(t) {
13
+ if (!o(t))
14
+ throw new TypeError("JWT Claims Set MUST be an object");
15
+ this.#t = structuredClone(t);
12
16
  }
13
- }
14
- class c extends o {
15
- constructor({ count: e, limit: r }) {
16
- super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${e}\`).`, { name: "RecursiveReadLimitExceededError" });
17
+ data() {
18
+ return n.encode(JSON.stringify(this.#t));
19
+ }
20
+ get iss() {
21
+ return this.#t.iss;
22
+ }
23
+ set iss(t) {
24
+ this.#t.iss = t;
25
+ }
26
+ get sub() {
27
+ return this.#t.sub;
28
+ }
29
+ set sub(t) {
30
+ this.#t.sub = t;
31
+ }
32
+ get aud() {
33
+ return this.#t.aud;
34
+ }
35
+ set aud(t) {
36
+ this.#t.aud = t;
37
+ }
38
+ set jti(t) {
39
+ this.#t.jti = t;
40
+ }
41
+ set nbf(t) {
42
+ typeof t == "number" ? this.#t.nbf = s("setNotBefore", t) : t instanceof Date ? this.#t.nbf = s("setNotBefore", e(t)) : this.#t.nbf = e(/* @__PURE__ */ new Date()) + i(t);
43
+ }
44
+ set exp(t) {
45
+ typeof t == "number" ? this.#t.exp = s("setExpirationTime", t) : t instanceof Date ? this.#t.exp = s("setExpirationTime", e(t)) : this.#t.exp = e(/* @__PURE__ */ new Date()) + i(t);
46
+ }
47
+ set iat(t) {
48
+ typeof t > "u" ? this.#t.iat = e(/* @__PURE__ */ new Date()) : t instanceof Date ? this.#t.iat = s("setIssuedAt", e(t)) : typeof t == "string" ? this.#t.iat = s("setIssuedAt", e(/* @__PURE__ */ new Date()) + i(t)) : this.#t.iat = s("setIssuedAt", t);
17
49
  }
18
50
  }
19
51
  export {
20
- i as NegativeOffsetError,
21
- n as PositionOutOfBoundsError,
22
- c as RecursiveReadLimitExceededError
52
+ d as JWTClaimsBuilder
23
53
  };