@coinbase/cdp-core 0.0.41 → 0.0.42
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.native101.js +10 -79
- package/dist/esm/index.native102.js +79 -10
- package/dist/esm/index.native13.js +1 -1
- package/dist/esm/index.native25.js +149 -940
- package/dist/esm/index.native26.js +48 -2
- package/dist/esm/index.native27.js +244 -43
- package/dist/esm/index.native28.js +55 -27
- package/dist/esm/index.native29.js +940 -149
- package/dist/esm/index.native30.js +2 -48
- package/dist/esm/index.native31.js +43 -243
- package/dist/esm/index.native32.js +27 -55
- package/dist/esm/index.native8.js +4 -4
- package/dist/esm/index.native9.js +49 -31
- package/dist/esm/index.native92.js +1 -1
- package/dist/esm/index.web100.js +9 -117
- package/dist/esm/index.web101.js +79 -10
- package/dist/esm/index.web26.js +156 -155
- package/dist/esm/index.web27.js +1 -1
- package/dist/esm/index.web8.js +49 -31
- package/dist/esm/index.web82.js +6 -6
- package/dist/esm/index.web91.js +1 -1
- package/dist/esm/index.web94.js +19 -77
- package/dist/esm/index.web95.js +10 -21
- package/dist/esm/index.web96.js +19 -9
- package/dist/esm/index.web97.js +89 -15
- package/dist/esm/index.web98.js +19 -92
- package/dist/esm/index.web99.js +115 -18
- package/dist/native/index.native101.js +10 -79
- package/dist/native/index.native102.js +79 -10
- package/dist/native/index.native13.js +1 -1
- package/dist/native/index.native25.js +149 -940
- package/dist/native/index.native26.js +48 -2
- package/dist/native/index.native27.js +244 -43
- package/dist/native/index.native28.js +55 -27
- package/dist/native/index.native29.js +940 -149
- package/dist/native/index.native30.js +2 -48
- package/dist/native/index.native31.js +43 -243
- package/dist/native/index.native32.js +27 -55
- package/dist/native/index.native8.js +4 -4
- package/dist/native/index.native9.js +49 -31
- package/dist/native/index.native92.js +1 -1
- package/dist/native-types/eip1193/errors.d.ts +6 -0
- package/dist/native-types/eip1193/internal.d.ts +3 -1
- package/dist/types/eip1193/errors.d.ts +6 -0
- package/dist/types/eip1193/internal.d.ts +3 -1
- package/dist/web/index.web100.js +9 -117
- package/dist/web/index.web101.js +79 -10
- package/dist/web/index.web26.js +156 -155
- package/dist/web/index.web27.js +1 -1
- package/dist/web/index.web8.js +49 -31
- package/dist/web/index.web82.js +6 -6
- package/dist/web/index.web91.js +1 -1
- package/dist/web/index.web94.js +19 -77
- package/dist/web/index.web95.js +10 -21
- package/dist/web/index.web96.js +19 -9
- package/dist/web/index.web97.js +89 -15
- package/dist/web/index.web98.js +19 -92
- package/dist/web/index.web99.js +115 -18
- package/dist/web-types/eip1193/errors.d.ts +6 -0
- package/dist/web-types/eip1193/internal.d.ts +3 -1
- package/package.json +2 -2
package/dist/esm/index.web8.js
CHANGED
|
@@ -2,9 +2,9 @@ import "ox";
|
|
|
2
2
|
import "viem";
|
|
3
3
|
import "zustand";
|
|
4
4
|
import "@coinbase/cdp-api-client";
|
|
5
|
-
import { getCurrentUser as
|
|
5
|
+
import { getCurrentUser as h } from "./index.web5.js";
|
|
6
6
|
import "./index.web7.js";
|
|
7
|
-
const
|
|
7
|
+
const n = {
|
|
8
8
|
rpc: {
|
|
9
9
|
invalidInput: -32e3,
|
|
10
10
|
resourceNotFound: -32001,
|
|
@@ -38,8 +38,8 @@ class o extends Error {
|
|
|
38
38
|
* @param code - The error code from EIP1193ErrorCode enum.
|
|
39
39
|
* @param message - The error message.
|
|
40
40
|
*/
|
|
41
|
-
constructor(t,
|
|
42
|
-
super(
|
|
41
|
+
constructor(t, r) {
|
|
42
|
+
super(r), this.code = t;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
class c extends Error {
|
|
@@ -53,11 +53,21 @@ class c extends Error {
|
|
|
53
53
|
* @param code - The error code from RPCErrorCode type.
|
|
54
54
|
* @param message - The error message.
|
|
55
55
|
*/
|
|
56
|
-
constructor(t,
|
|
57
|
-
super(
|
|
56
|
+
constructor(t, r) {
|
|
57
|
+
super(r), this.code = t;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
class p extends Error {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new AccountTypeMismatchError.
|
|
63
|
+
*
|
|
64
|
+
* @param message - The error message.
|
|
65
|
+
*/
|
|
66
|
+
constructor(t) {
|
|
67
|
+
super(t);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const l = /* @__PURE__ */ new Set([
|
|
61
71
|
"eth_accounts",
|
|
62
72
|
"eth_requestAccounts",
|
|
63
73
|
"personal_sign",
|
|
@@ -72,72 +82,80 @@ const p = /* @__PURE__ */ new Set([
|
|
|
72
82
|
"wallet_getCapabilities"
|
|
73
83
|
]);
|
|
74
84
|
function _(e, { chains: t }) {
|
|
75
|
-
const { method:
|
|
76
|
-
if (typeof
|
|
85
|
+
const { method: r, params: s } = e;
|
|
86
|
+
if (typeof r != "string" || r.length === 0)
|
|
77
87
|
throw new c(
|
|
78
|
-
|
|
88
|
+
n.rpc.invalidParams,
|
|
79
89
|
"'method' must be a non-empty string."
|
|
80
90
|
);
|
|
81
|
-
const
|
|
82
|
-
if (typeof
|
|
91
|
+
const a = (s ?? [])[0]?.chainId;
|
|
92
|
+
if (typeof a == "string" && !t.some((d) => d.id === Number.parseInt(a, 16)))
|
|
83
93
|
throw new o(
|
|
84
|
-
|
|
85
|
-
`Chain ${
|
|
94
|
+
n.provider.unsupportedChain,
|
|
95
|
+
`Chain ${a} not supported - make sure the provider is configured with the correct chains.`
|
|
86
96
|
);
|
|
87
|
-
if (
|
|
97
|
+
if (s !== void 0 && !Array.isArray(s))
|
|
88
98
|
throw new c(
|
|
89
|
-
|
|
99
|
+
n.rpc.invalidParams,
|
|
90
100
|
"'params' must be an array if provided."
|
|
91
101
|
);
|
|
92
|
-
if (!
|
|
102
|
+
if (!l.has(r))
|
|
93
103
|
throw new o(
|
|
94
|
-
|
|
104
|
+
n.provider.unsupportedMethod,
|
|
95
105
|
`Method ${e.method} not supported`
|
|
96
106
|
);
|
|
97
107
|
}
|
|
98
108
|
async function i() {
|
|
99
|
-
const e = await
|
|
109
|
+
const e = await h();
|
|
100
110
|
if (!e)
|
|
101
111
|
throw new o(
|
|
102
|
-
|
|
112
|
+
n.provider.unauthorized,
|
|
103
113
|
"User not connected"
|
|
104
114
|
);
|
|
105
115
|
return e;
|
|
106
116
|
}
|
|
107
|
-
async function
|
|
117
|
+
async function y(e) {
|
|
108
118
|
const t = await i();
|
|
109
|
-
if (!t.evmAccounts?.includes(e))
|
|
119
|
+
if (!t.evmAccounts?.includes(e) && !t.evmSmartAccounts?.includes(e))
|
|
110
120
|
throw new o(
|
|
111
|
-
|
|
121
|
+
n.provider.unauthorized,
|
|
112
122
|
"Address not owned by user"
|
|
113
123
|
);
|
|
114
124
|
return t;
|
|
115
125
|
}
|
|
116
|
-
async function
|
|
126
|
+
async function u() {
|
|
117
127
|
const e = await i();
|
|
118
128
|
if (!e.evmAccounts?.[0])
|
|
119
129
|
throw new o(
|
|
120
|
-
|
|
130
|
+
n.provider.unauthorized,
|
|
121
131
|
"No EVM accounts available"
|
|
122
132
|
);
|
|
123
133
|
return e;
|
|
124
134
|
}
|
|
125
|
-
async function
|
|
135
|
+
async function g() {
|
|
126
136
|
const e = await i();
|
|
127
137
|
if (!e.evmSmartAccounts?.[0])
|
|
128
138
|
throw new o(
|
|
129
|
-
|
|
139
|
+
n.provider.unauthorized,
|
|
130
140
|
"No EVM smart accounts available"
|
|
131
141
|
);
|
|
132
142
|
return e;
|
|
133
143
|
}
|
|
144
|
+
async function S({ errorMessage: e } = {}) {
|
|
145
|
+
const t = await u();
|
|
146
|
+
if (await u(), !!t.evmSmartAccounts?.length)
|
|
147
|
+
throw new p(e ?? "Method unsupported.");
|
|
148
|
+
return t;
|
|
149
|
+
}
|
|
134
150
|
export {
|
|
151
|
+
p as AccountTypeMismatchError,
|
|
135
152
|
o as EIP1193ProviderError,
|
|
136
153
|
c as RPCRequestError,
|
|
137
|
-
|
|
154
|
+
n as STANDARD_ERROR_CODES,
|
|
155
|
+
S as validateIsUsingEOA,
|
|
138
156
|
_ as validateRequest,
|
|
139
157
|
i as validateUserConnected,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
u as validateUserHasEvmAccount,
|
|
159
|
+
g as validateUserHasEvmSmartAccount,
|
|
160
|
+
y as validateUserOwnsAddress
|
|
143
161
|
};
|
package/dist/esm/index.web82.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { encode as d } from "./index.
|
|
2
|
-
import y from "./index.
|
|
3
|
-
import b from "./index.
|
|
1
|
+
import { encode as d } from "./index.web94.js";
|
|
2
|
+
import y from "./index.web95.js";
|
|
3
|
+
import b from "./index.web96.js";
|
|
4
4
|
import { JWSInvalid as r } from "./index.web33.js";
|
|
5
5
|
import { encoder as s, concat as u, decoder as h } from "./index.web83.js";
|
|
6
|
-
import g from "./index.
|
|
7
|
-
import H from "./index.
|
|
8
|
-
import P from "./index.
|
|
6
|
+
import g from "./index.web97.js";
|
|
7
|
+
import H from "./index.web98.js";
|
|
8
|
+
import P from "./index.web99.js";
|
|
9
9
|
class x {
|
|
10
10
|
#r;
|
|
11
11
|
#e;
|
package/dist/esm/index.web91.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index.
|
|
1
|
+
import { HashMD as D, SHA256_IV as b, Chi as g, Maj as p } from "./index.web101.js";
|
|
2
2
|
import { createHasher as u, clean as C, rotr as i } from "./index.web90.js";
|
|
3
3
|
const B = /* @__PURE__ */ Uint32Array.from([
|
|
4
4
|
1116352408,
|
package/dist/esm/index.web94.js
CHANGED
|
@@ -1,81 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class m extends g {
|
|
15
|
-
constructor(t, s, n, i) {
|
|
16
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = i, this.buffer = new Uint8Array(t), this.view = l(this.buffer);
|
|
17
|
-
}
|
|
18
|
-
update(t) {
|
|
19
|
-
b(this), t = a(t), d(t);
|
|
20
|
-
const { view: s, buffer: n, blockLen: i } = this, h = t.length;
|
|
21
|
-
for (let e = 0; e < h; ) {
|
|
22
|
-
const r = Math.min(i - this.pos, h - e);
|
|
23
|
-
if (r === i) {
|
|
24
|
-
const c = l(t);
|
|
25
|
-
for (; i <= h - e; e += i)
|
|
26
|
-
this.process(c, e);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
n.set(t.subarray(e, e + r), this.pos), this.pos += r, e += r, this.pos === i && (this.process(s, 0), this.pos = 0);
|
|
30
|
-
}
|
|
31
|
-
return this.length += t.length, this.roundClean(), this;
|
|
32
|
-
}
|
|
33
|
-
digestInto(t) {
|
|
34
|
-
b(this), x(t, this), this.finished = !0;
|
|
35
|
-
const { buffer: s, view: n, blockLen: i, isLE: h } = this;
|
|
36
|
-
let { pos: e } = this;
|
|
37
|
-
s[e++] = 128, w(this.buffer.subarray(e)), this.padOffset > i - e && (this.process(n, 0), e = 0);
|
|
38
|
-
for (let f = e; f < i; f++)
|
|
39
|
-
s[f] = 0;
|
|
40
|
-
y(n, i - 8, BigInt(this.length * 8), h), this.process(n, 0);
|
|
41
|
-
const r = l(t), c = this.outputLen;
|
|
42
|
-
if (c % 4)
|
|
43
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
44
|
-
const u = c / 4, p = this.get();
|
|
45
|
-
if (u > p.length)
|
|
46
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
47
|
-
for (let f = 0; f < u; f++)
|
|
48
|
-
r.setUint32(4 * f, p[f], h);
|
|
49
|
-
}
|
|
50
|
-
digest() {
|
|
51
|
-
const { buffer: t, outputLen: s } = this;
|
|
52
|
-
this.digestInto(t);
|
|
53
|
-
const n = t.slice(0, s);
|
|
54
|
-
return this.destroy(), n;
|
|
55
|
-
}
|
|
56
|
-
_cloneInto(t) {
|
|
57
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
58
|
-
const { blockLen: s, buffer: n, length: i, finished: h, destroyed: e, pos: r } = this;
|
|
59
|
-
return t.destroyed = e, t.finished = h, t.length = i, t.pos = r, i % s && t.buffer.set(n), t;
|
|
60
|
-
}
|
|
61
|
-
clone() {
|
|
62
|
-
return this._cloneInto();
|
|
1
|
+
import { encoder as t, decoder as o } from "./index.web83.js";
|
|
2
|
+
import { encodeBase64 as c, decodeBase64 as a } from "./index.web103.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.");
|
|
63
14
|
}
|
|
64
15
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
2773480762,
|
|
70
|
-
1359893119,
|
|
71
|
-
2600822924,
|
|
72
|
-
528734635,
|
|
73
|
-
1541459225
|
|
74
|
-
]);
|
|
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
|
+
}
|
|
75
20
|
export {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_ as Maj,
|
|
79
|
-
B as SHA256_IV,
|
|
80
|
-
y as setBigUint64
|
|
21
|
+
i as decode,
|
|
22
|
+
p as encode
|
|
81
23
|
};
|
package/dist/esm/index.web95.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
}
|
|
1
|
+
import n from "./index.web104.js";
|
|
2
|
+
import s from "./index.web105.js";
|
|
3
|
+
import a from "./index.web106.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
|
+
};
|
|
20
10
|
export {
|
|
21
|
-
|
|
22
|
-
p as encode
|
|
11
|
+
y as default
|
|
23
12
|
};
|
package/dist/esm/index.web96.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
s
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
19
|
};
|
|
10
20
|
export {
|
|
11
|
-
|
|
21
|
+
a as default
|
|
12
22
|
};
|
package/dist/esm/index.web97.js
CHANGED
|
@@ -1,22 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { withAlg as n } from "./index.web107.js";
|
|
2
|
+
import c from "./index.web108.js";
|
|
3
|
+
import { isJWK as p, isSecretJWK as a, isPublicJWK as y, isPrivateJWK as f } from "./index.web109.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;
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
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`);
|
|
17
45
|
}
|
|
18
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);
|
|
19
93
|
};
|
|
20
94
|
export {
|
|
21
|
-
|
|
95
|
+
d as default
|
|
22
96
|
};
|
package/dist/esm/index.web98.js
CHANGED
|
@@ -1,96 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (e.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new TypeError(`Invalid key for this operation, its "use" must be "${i}" when present`);
|
|
1
|
+
import { JOSENotSupported as f } from "./index.web33.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`);
|
|
19
18
|
}
|
|
20
|
-
|
|
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);
|
|
19
|
+
return new Set(e.crit);
|
|
93
20
|
};
|
|
94
21
|
export {
|
|
95
|
-
|
|
22
|
+
w as default
|
|
96
23
|
};
|