@coinbase/cdp-core 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -85,6 +85,10 @@ if (signedIn) {
85
85
  const user = await getCurrentUser();
86
86
  console.log("User ID:", user.userId);
87
87
  console.log("EVM Accounts:", user.evmAccounts);
88
+
89
+ // Find the user's email address (if they logged in with email/otp)
90
+ const email = user.authenticationMethods.email?.email;
91
+ console.log("Email Address": email)
88
92
  }
89
93
  ```
90
94
 
@@ -1,4 +1,4 @@
1
- import n from "./index86.js";
1
+ import n from "./index85.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 "./index73.js";
1
+ import { JOSENotSupported as s } from "./index71.js";
2
2
  function n(e) {
3
3
  let a, r;
4
4
  switch (e.kty) {
@@ -1,8 +1,14 @@
1
- const s = "0x0000000000000000000000000000000000000000", c = {
1
+ const e = "0x0000000000000000000000000000000000000000", t = {
2
2
  userId: "mock-user-id",
3
- evmAccounts: [s]
3
+ evmAccounts: [e],
4
+ authenticationMethods: {
5
+ email: {
6
+ type: "email",
7
+ email: "test@test.com"
8
+ }
9
+ }
4
10
  };
5
11
  export {
6
- s as mockAddress,
7
- c as mockUser
12
+ e as mockAddress,
13
+ t as mockUser
8
14
  };
@@ -1,6 +1,6 @@
1
- import { CompactSign as i } from "./index72.js";
2
- import { JWTInvalid as r } from "./index73.js";
3
- import { JWTClaimsBuilder as n } from "./index74.js";
1
+ import { CompactSign as i } from "./index70.js";
2
+ import { JWTInvalid as r } from "./index71.js";
3
+ import { JWTClaimsBuilder as n } from "./index72.js";
4
4
  class d {
5
5
  #s;
6
6
  #t;
@@ -1,4 +1,4 @@
1
- import { configureCdpApiClient as p, setAuthManager as w, initiateAuthentication as h, verifyEmailAuthentication as y, createEndUserEvmAccount as f, signEvmHashWithEndUserAccount as I, signEvmTransactionWithEndUserAccount as l, sendEvmTransactionWithEndUserAccount as E, signEvmMessageWithEndUserAccount as v, signEvmTypedDataWithEndUserAccount as A, exportEndUserEvmAccount as k } from "@coinbase/cdp-api-client";
1
+ import { configureCdpApiClient as p, setAuthManager as w, initiateAuthentication as h, verifyEmailAuthentication as y, createEndUserEvmAccount as f, signEvmHashWithEndUserAccount as I, signEvmTransactionWithEndUserAccount as l, sendEvmTransactionWithEndUserAccount as v, signEvmMessageWithEndUserAccount as A, signEvmTypedDataWithEndUserAccount as E, exportEndUserEvmAccount as k } from "@coinbase/cdp-api-client";
2
2
  import { AuthManager as M } from "./index6.js";
3
3
  import { toAuthState as u } from "./index7.js";
4
4
  import { withAuth as i } from "./index8.js";
@@ -64,7 +64,7 @@ const $ = async (e) => {
64
64
  otp: e.otp
65
65
  });
66
66
  let a = u(t.accessToken, t.validUntil, t.endUser);
67
- if (a.user.evmAccounts.length === 0)
67
+ if (!a.user.evmAccounts || a.user.evmAccounts.length === 0)
68
68
  try {
69
69
  const o = await f(r().projectId, a.user.userId, {
70
70
  walletSecretId: await n().getWalletSecretId(a)
@@ -116,7 +116,7 @@ const $ = async (e) => {
116
116
  return { transactionHash: "0x0" };
117
117
  const s = m(e.transaction);
118
118
  return i(e, n(), async ({ user: t, walletSecretId: a }) => ({
119
- transactionHash: (await E(
119
+ transactionHash: (await v(
120
120
  r().projectId,
121
121
  t.userId,
122
122
  {
@@ -128,13 +128,13 @@ const $ = async (e) => {
128
128
  )).transactionHash
129
129
  }));
130
130
  }, Y = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
131
- signature: (await v(r().projectId, s.userId, {
131
+ signature: (await A(r().projectId, s.userId, {
132
132
  message: e.message,
133
133
  address: e.evmAccount,
134
134
  walletSecretId: t
135
135
  })).signature
136
136
  })), Z = async (e) => r().useMock ? { signature: "0x0" } : i(e, n(), async ({ user: s, walletSecretId: t }) => ({
137
- signature: (await A(r().projectId, s.userId, {
137
+ signature: (await E(r().projectId, s.userId, {
138
138
  typedData: e.typedData,
139
139
  address: e.evmAccount,
140
140
  walletSecretId: t
@@ -1,8 +1,8 @@
1
1
  import { Provider as y, Hex as I } from "ox";
2
2
  import { createWalletClient as E } from "viem";
3
- import { signEvmTypedData as S, signEvmHash as P, getCurrentUser as f, signOut as R, sendEvmTransaction as T, signEvmTransaction as A, signEvmMessage as x } from "./index2.js";
3
+ import { signEvmTypedData as P, signEvmHash as S, getCurrentUser as f, signOut as R, sendEvmTransaction as T, signEvmTransaction as A, signEvmMessage as x } from "./index2.js";
4
4
  import "./index3.js";
5
- import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as c, validateUserHasEvmAccount as C, validateUserConnected as D } from "./index4.js";
5
+ import { validateUserOwnsAddress as m, EIP1193ProviderError as l, STANDARD_ERROR_CODES as s, RPCRequestError as o, validateUserHasEvmAccount as C, validateUserConnected as D } from "./index4.js";
6
6
  import { isChainIdSupportedForCDPSends as b, chainIdToNameMapping as j } from "./index13.js";
7
7
  function g(e) {
8
8
  return {
@@ -16,14 +16,14 @@ function g(e) {
16
16
  type: "eip1559"
17
17
  };
18
18
  }
19
- async function U() {
19
+ async function H() {
20
20
  return (await f())?.evmAccounts || [];
21
21
  }
22
22
  async function M(e, n) {
23
23
  const a = await D();
24
24
  return e.emit("connect", {
25
25
  chainId: I.fromNumber(n.getState().chainId)
26
- }), a.evmAccounts;
26
+ }), a.evmAccounts || [];
27
27
  }
28
28
  async function _(e) {
29
29
  const [n, a] = e;
@@ -34,10 +34,10 @@ async function _(e) {
34
34
  evmAccount: a,
35
35
  message: t
36
36
  })).signature;
37
- } catch (o) {
37
+ } catch (c) {
38
38
  throw new l(
39
39
  s.provider.userRejectedRequest,
40
- o instanceof Error ? o.message : "Signing failed"
40
+ c instanceof Error ? c.message : "Signing failed"
41
41
  );
42
42
  }
43
43
  }
@@ -45,7 +45,7 @@ async function k(e) {
45
45
  const [n, a] = e;
46
46
  await m(n);
47
47
  try {
48
- return (await S({
48
+ return (await P({
49
49
  evmAccount: n,
50
50
  typedData: JSON.parse(a)
51
51
  })).signature;
@@ -59,16 +59,21 @@ async function k(e) {
59
59
  async function z(e, n, a) {
60
60
  const [t] = e;
61
61
  if (!t || typeof t != "object")
62
- throw new c(
62
+ throw new o(
63
63
  s.rpc.invalidParams,
64
64
  "Transaction parameter must be an object"
65
65
  );
66
66
  if (!t.to)
67
- throw new c(
67
+ throw new o(
68
68
  s.rpc.invalidParams,
69
69
  "Transaction must include 'to' field"
70
70
  );
71
- const d = (await C()).evmAccounts[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
71
+ const d = (await C()).evmAccounts?.[0], u = n.getState(), i = t.chainId ? Number(t.chainId) : u.chainId;
72
+ if (!d)
73
+ throw new o(
74
+ s.rpc.invalidParams,
75
+ "User does not have an EVM account"
76
+ );
72
77
  if (b(i))
73
78
  try {
74
79
  return (await T({
@@ -77,7 +82,7 @@ async function z(e, n, a) {
77
82
  network: j[i]
78
83
  })).transactionHash;
79
84
  } catch (r) {
80
- throw console.log("Transaction failed", r), new c(
85
+ throw console.log("Transaction failed", r), new o(
81
86
  s.rpc.transactionRejected,
82
87
  r instanceof Error ? r.message : "Transaction failed"
83
88
  );
@@ -89,13 +94,13 @@ async function z(e, n, a) {
89
94
  chain: u.chains.find((h) => h.id === i),
90
95
  transport: a[i],
91
96
  account: d
92
- }), p = u.chains.find((h) => h.id === i), w = await r.prepareTransactionRequest({
97
+ }), w = u.chains.find((h) => h.id === i), p = await r.prepareTransactionRequest({
93
98
  ...g(t),
94
- chain: p
99
+ chain: w
95
100
  }), v = await A({
96
101
  evmAccount: d,
97
102
  transaction: {
98
- ...w,
103
+ ...p,
99
104
  type: "eip1559"
100
105
  }
101
106
  });
@@ -103,7 +108,7 @@ async function z(e, n, a) {
103
108
  serializedTransaction: v.signedTransaction
104
109
  });
105
110
  } catch (r) {
106
- throw new c(
111
+ throw new o(
107
112
  s.rpc.transactionRejected,
108
113
  r instanceof Error ? r.message : "Transaction failed"
109
114
  );
@@ -113,7 +118,7 @@ async function J(e) {
113
118
  const [n, a] = e;
114
119
  await m(a);
115
120
  try {
116
- return (await P({
121
+ return (await S({
117
122
  evmAccount: a,
118
123
  hash: n
119
124
  })).signature;
@@ -124,25 +129,25 @@ async function J(e) {
124
129
  );
125
130
  }
126
131
  }
127
- async function W(e) {
132
+ async function V(e) {
128
133
  return `0x${e.getState().chainId.toString(16)}`;
129
134
  }
130
- async function $(e) {
135
+ async function W(e) {
131
136
  await f() && await R(), e.emit("disconnect", new y.DisconnectedError());
132
137
  }
133
- function K(e, n) {
138
+ function $(e, n) {
134
139
  const a = Number.parseInt(e[0].chainId, 16);
135
140
  n.getState().setChainId(a);
136
141
  }
137
142
  export {
138
- U as handleAccounts,
139
- W as handleChainId,
140
- $ as handleDisconnect,
143
+ H as handleAccounts,
144
+ V as handleChainId,
145
+ W as handleDisconnect,
141
146
  J as handleEthSign,
142
147
  _ as handlePersonalSign,
143
148
  M as handleRequestAccounts,
144
149
  z as handleSendTransaction,
145
150
  k as handleSignTypedData,
146
- K as handleSwitchEthereumChain,
151
+ $ as handleSwitchEthereumChain,
147
152
  g as shimProviderTxRequest
148
153
  };
@@ -1,4 +1,4 @@
1
- import { chainConfig as a } from "./index81.js";
1
+ import { chainConfig as a } from "./index86.js";
2
2
  import { defineChain as t } from "./index25.js";
3
3
  const e = 11155111, r = /* @__PURE__ */ t({
4
4
  ...a,
@@ -100,7 +100,7 @@ async function d() {
100
100
  }
101
101
  async function w(e) {
102
102
  const t = await d();
103
- if (!t.evmAccounts.includes(e))
103
+ if (!t.evmAccounts?.includes(e))
104
104
  throw new o(
105
105
  n.provider.unauthorized,
106
106
  "Address not owned by user"
@@ -109,7 +109,7 @@ async function w(e) {
109
109
  }
110
110
  async function f() {
111
111
  const e = await d();
112
- if (!e.evmAccounts[0])
112
+ if (!e.evmAccounts?.[0])
113
113
  throw new o(
114
114
  n.provider.unauthorized,
115
115
  "No EVM accounts available"
@@ -1,4 +1,4 @@
1
- import { version as o } from "./index70.js";
1
+ import { version as o } from "./index73.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 "./index71.js";
1
+ import { NegativeOffsetError as o, PositionOutOfBoundsError as e, RecursiveReadLimitExceededError as n } from "./index74.js";
2
2
  const h = {
3
3
  bytes: new Uint8Array(),
4
4
  dataView: new DataView(new ArrayBuffer(0)),
@@ -1,14 +1,15 @@
1
- const u = (e, s, t) => {
2
- const c = new Date(s).getTime(), o = {
3
- userId: t.userId,
4
- evmAccounts: t.evmAccounts?.map((r) => r) ?? []
1
+ const c = (u, n, e) => {
2
+ const o = new Date(n).getTime(), r = {
3
+ userId: e.userId,
4
+ evmAccounts: e.evmAccounts?.map((t) => t) ?? [],
5
+ authenticationMethods: e.authenticationMethods.reduce((t, s) => (t[s.type] = s, t), {})
5
6
  };
6
7
  return {
7
- accessToken: e,
8
- expiresAt: c,
9
- user: o
8
+ accessToken: u,
9
+ expiresAt: o,
10
+ user: r
10
11
  };
11
12
  };
12
13
  export {
13
- u as toAuthState
14
+ c as toAuthState
14
15
  };
@@ -1,4 +1,19 @@
1
- const o = "2.33.0";
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
+ }
2
17
  export {
3
- o as version
18
+ o as CompactSign
4
19
  };
@@ -1,23 +1,25 @@
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
- });
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);
7
6
  }
8
7
  }
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
- }
8
+ class E extends c {
9
+ static code = "ERR_JOSE_NOT_SUPPORTED";
10
+ code = "ERR_JOSE_NOT_SUPPORTED";
13
11
  }
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
- }
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";
18
19
  }
19
20
  export {
20
- i as NegativeOffsetError,
21
- n as PositionOutOfBoundsError,
22
- c as RecursiveReadLimitExceededError
21
+ c as JOSEError,
22
+ E as JOSENotSupported,
23
+ o as JWSInvalid,
24
+ r as JWTInvalid
23
25
  };
@@ -1,19 +1,53 @@
1
- import { FlattenedSign as n } from "./index82.js";
2
- class o {
3
- #e;
4
- constructor(e) {
5
- this.#e = new n(e);
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);
6
43
  }
7
- setProtectedHeader(e) {
8
- return this.#e.setProtectedHeader(e), this;
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);
9
46
  }
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}`;
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);
15
49
  }
16
50
  }
17
51
  export {
18
- o as CompactSign
52
+ d as JWTClaimsBuilder
19
53
  };
@@ -1,25 +1,4 @@
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
- }
1
+ const o = "2.33.0";
20
2
  export {
21
- c as JOSEError,
22
- E as JOSENotSupported,
23
- o as JWSInvalid,
24
- r as JWTInvalid
3
+ o as version
25
4
  };
@@ -1,53 +1,23 @@
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;
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;
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
+ });
31
7
  }
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);
8
+ }
9
+ class n extends o {
10
+ constructor({ length: e, position: r }) {
11
+ super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`, { name: "PositionOutOfBoundsError" });
46
12
  }
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);
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" });
49
17
  }
50
18
  }
51
19
  export {
52
- d as JWTClaimsBuilder
20
+ i as NegativeOffsetError,
21
+ n as PositionOutOfBoundsError,
22
+ c as RecursiveReadLimitExceededError
53
23
  };
@@ -3,7 +3,7 @@ async function s(t, n, r) {
3
3
  if (!await o(n))
4
4
  throw new Error("User not signed in");
5
5
  const e = await n.getUser();
6
- if (!e.evmAccounts.find((i) => i === t.evmAccount))
6
+ if (!e.evmAccounts?.find((i) => i === t.evmAccount))
7
7
  throw new Error("EVM account not found");
8
8
  const c = await n.getWalletSecretId();
9
9
  return r({ ...t, user: e, walletSecretId: c });
@@ -1,12 +1,57 @@
1
- import { contracts as o } from "./index88.js";
2
- import { formatters as r } from "./index89.js";
3
- import { serializers as t } from "./index90.js";
4
- const e = {
5
- blockTime: 2e3,
6
- contracts: o,
7
- formatters: r,
8
- serializers: t
9
- };
1
+ import { encode as d } from "./index88.js";
2
+ import y from "./index89.js";
3
+ import b from "./index90.js";
4
+ import { JWSInvalid as r } from "./index71.js";
5
+ import { encoder as s, concat as u, decoder as h } from "./index82.js";
6
+ import g from "./index91.js";
7
+ import H from "./index92.js";
8
+ import P from "./index93.js";
9
+ class x {
10
+ #r;
11
+ #e;
12
+ #t;
13
+ constructor(e) {
14
+ if (!(e instanceof Uint8Array))
15
+ throw new TypeError("payload must be an instance of Uint8Array");
16
+ this.#r = e;
17
+ }
18
+ setProtectedHeader(e) {
19
+ if (this.#e)
20
+ throw new TypeError("setProtectedHeader can only be called once");
21
+ return this.#e = e, this;
22
+ }
23
+ setUnprotectedHeader(e) {
24
+ if (this.#t)
25
+ throw new TypeError("setUnprotectedHeader can only be called once");
26
+ return this.#t = e, this;
27
+ }
28
+ async sign(e, l) {
29
+ if (!this.#e && !this.#t)
30
+ throw new r("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
31
+ if (!b(this.#e, this.#t))
32
+ throw new r("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
33
+ const c = {
34
+ ...this.#e,
35
+ ...this.#t
36
+ }, p = H(r, /* @__PURE__ */ new Map([["b64", !0]]), l?.crit, this.#e, c);
37
+ let o = !0;
38
+ if (p.has("b64") && (o = this.#e.b64, typeof o != "boolean"))
39
+ throw new r('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
40
+ const { alg: t } = c;
41
+ if (typeof t != "string" || !t)
42
+ throw new r('JWS "alg" (Algorithm) Header Parameter missing or invalid');
43
+ g(t, e, "sign");
44
+ let i = this.#r;
45
+ o && (i = s.encode(d(i)));
46
+ let n;
47
+ this.#e ? n = s.encode(d(JSON.stringify(this.#e))) : n = s.encode("");
48
+ const f = u(n, s.encode("."), i), m = await P(e, t), w = await y(t, m, f), a = {
49
+ signature: d(w),
50
+ payload: ""
51
+ };
52
+ return o && (a.payload = h.decode(i)), this.#t && (a.header = this.#t), this.#e && (a.protected = h.decode(n)), a;
53
+ }
54
+ }
10
55
  export {
11
- e as chainConfig
56
+ x as FlattenedSign
12
57
  };