@lukso/web-components 1.81.2 → 1.82.0

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 (62) hide show
  1. package/dist/components/index.cjs +3 -3
  2. package/dist/components/index.js +3 -3
  3. package/dist/components/lukso-button/index.cjs +1 -1
  4. package/dist/components/lukso-button/index.js +1 -1
  5. package/dist/components/lukso-card/index.cjs +3 -3
  6. package/dist/components/lukso-card/index.js +3 -3
  7. package/dist/components/lukso-checkbox/index.cjs +1 -1
  8. package/dist/components/lukso-checkbox/index.js +1 -1
  9. package/dist/components/lukso-footer/index.cjs +1 -1
  10. package/dist/components/lukso-footer/index.js +1 -1
  11. package/dist/components/lukso-icon/index.cjs +2 -2
  12. package/dist/components/lukso-icon/index.js +2 -2
  13. package/dist/components/lukso-image/index.cjs +2 -2
  14. package/dist/components/lukso-image/index.js +2 -2
  15. package/dist/components/lukso-input/index.cjs +2 -2
  16. package/dist/components/lukso-input/index.js +2 -2
  17. package/dist/components/lukso-modal/index.cjs +1 -1
  18. package/dist/components/lukso-modal/index.js +1 -1
  19. package/dist/components/lukso-navbar/index.cjs +3 -3
  20. package/dist/components/lukso-navbar/index.js +3 -3
  21. package/dist/components/lukso-pagination/index.cjs +2 -2
  22. package/dist/components/lukso-pagination/index.js +2 -2
  23. package/dist/components/lukso-profile/index.cjs +2 -2
  24. package/dist/components/lukso-profile/index.js +2 -2
  25. package/dist/components/lukso-progress/index.cjs +2 -2
  26. package/dist/components/lukso-progress/index.js +2 -2
  27. package/dist/components/lukso-sanitize/index.cjs +1 -1
  28. package/dist/components/lukso-sanitize/index.js +1 -1
  29. package/dist/components/lukso-search/index.cjs +6 -13
  30. package/dist/components/lukso-search/index.d.ts.map +1 -1
  31. package/dist/components/lukso-search/index.js +6 -13
  32. package/dist/components/lukso-select/index.cjs +3 -3
  33. package/dist/components/lukso-select/index.js +3 -3
  34. package/dist/components/lukso-share/index.cjs +1 -1
  35. package/dist/components/lukso-share/index.js +1 -1
  36. package/dist/components/lukso-switch/index.cjs +2 -2
  37. package/dist/components/lukso-switch/index.js +2 -2
  38. package/dist/components/lukso-tag/index.cjs +2 -2
  39. package/dist/components/lukso-tag/index.js +2 -2
  40. package/dist/components/lukso-terms/index.cjs +2 -2
  41. package/dist/components/lukso-terms/index.js +2 -2
  42. package/dist/components/lukso-test/index.cjs +1 -1
  43. package/dist/components/lukso-test/index.js +1 -1
  44. package/dist/components/lukso-tooltip/index.cjs +2 -2
  45. package/dist/components/lukso-tooltip/index.js +2 -2
  46. package/dist/components/lukso-username/index.cjs +1159 -6
  47. package/dist/components/lukso-username/index.d.ts +2 -1
  48. package/dist/components/lukso-username/index.d.ts.map +1 -1
  49. package/dist/components/lukso-username/index.js +1159 -6
  50. package/dist/components/lukso-wizard/index.cjs +1 -1
  51. package/dist/components/lukso-wizard/index.js +1 -1
  52. package/dist/{index-b9a3ecb2.cjs → index-3b498928.cjs} +1 -1
  53. package/dist/{index-b2b55120.js → index-8043be8a.js} +1 -1
  54. package/dist/{index-d2227f06.cjs → index-e653a9ff.cjs} +1 -1
  55. package/dist/{index-b500cc08.js → index-f72579d6.js} +1 -1
  56. package/dist/index.cjs +3 -3
  57. package/dist/index.js +3 -3
  58. package/dist/shared/tailwind-element/index.cjs +1 -1
  59. package/dist/shared/tailwind-element/index.js +1 -1
  60. package/dist/{style-map-333da36f.cjs → style-map-a6d61d04.cjs} +1 -1
  61. package/dist/{style-map-babc0be8.js → style-map-ad97bcc3.js} +1 -1
  62. package/package.json +3 -2
@@ -1,7 +1,7 @@
1
- import { T as TailwindStyledElement, x, A } from '../../index-b500cc08.js';
1
+ import { T as TailwindStyledElement, x, A } from '../../index-f72579d6.js';
2
2
  import { n, e } from '../../query-assigned-elements-1c8c9e90.js';
3
3
  import { c as ce } from '../../index-ca8e900d.js';
4
- import { c as customStyleMap } from '../../index-b2b55120.js';
4
+ import { c as customStyleMap } from '../../index-8043be8a.js';
5
5
  import '../../tailwind-config.js';
6
6
  import { c as cn } from '../../cn-b54dcc61.js';
7
7
  import '../../bundle-mjs-fbc6e2a8.js';
@@ -20,6 +20,1145 @@ const sliceAddress = (address, startSliceBy = 6, endSliceBy) => {
20
20
  return sliceAddress2;
21
21
  };
22
22
 
23
+ function number(n) {
24
+ if (!Number.isSafeInteger(n) || n < 0)
25
+ throw new Error(`positive integer expected, not ${n}`);
26
+ }
27
+ function bool(b) {
28
+ if (typeof b !== 'boolean')
29
+ throw new Error(`boolean expected, not ${b}`);
30
+ }
31
+ // copied from utils
32
+ function isBytes(a) {
33
+ return (a instanceof Uint8Array ||
34
+ (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
35
+ }
36
+ function bytes(b, ...lengths) {
37
+ if (!isBytes(b))
38
+ throw new Error('Uint8Array expected');
39
+ if (lengths.length > 0 && !lengths.includes(b.length))
40
+ throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
41
+ }
42
+ function hash(h) {
43
+ if (typeof h !== 'function' || typeof h.create !== 'function')
44
+ throw new Error('Hash should be wrapped by utils.wrapConstructor');
45
+ number(h.outputLen);
46
+ number(h.blockLen);
47
+ }
48
+ function exists(instance, checkFinished = true) {
49
+ if (instance.destroyed)
50
+ throw new Error('Hash instance has been destroyed');
51
+ if (checkFinished && instance.finished)
52
+ throw new Error('Hash#digest() has already been called');
53
+ }
54
+ function output(out, instance) {
55
+ bytes(out);
56
+ const min = instance.outputLen;
57
+ if (out.length < min) {
58
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
59
+ }
60
+ }
61
+ const assert = { number, bool, bytes, hash, exists, output };
62
+ const assert$1 = assert;
63
+
64
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
65
+ const _32n = /* @__PURE__ */ BigInt(32);
66
+ // We are not using BigUint64Array, because they are extremely slow as per 2022
67
+ function fromBig(n, le = false) {
68
+ if (le)
69
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
70
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
71
+ }
72
+ function split(lst, le = false) {
73
+ let Ah = new Uint32Array(lst.length);
74
+ let Al = new Uint32Array(lst.length);
75
+ for (let i = 0; i < lst.length; i++) {
76
+ const { h, l } = fromBig(lst[i], le);
77
+ [Ah[i], Al[i]] = [h, l];
78
+ }
79
+ return [Ah, Al];
80
+ }
81
+ // Left rotate for Shift in [1, 32)
82
+ const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
83
+ const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
84
+ // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
85
+ const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
86
+ const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
87
+
88
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
89
+ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
90
+ // node.js versions earlier than v19 don't declare it in global scope.
91
+ // For node.js, package.json#exports field mapping rewrites import
92
+ // from `crypto` to `cryptoNode`, which imports native module.
93
+ // Makes the utils un-importable in browsers without a bundler.
94
+ // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
95
+ const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
96
+ const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
97
+ // The byte swap operation for uint32
98
+ const byteSwap = (word) => ((word << 24) & 0xff000000) |
99
+ ((word << 8) & 0xff0000) |
100
+ ((word >>> 8) & 0xff00) |
101
+ ((word >>> 24) & 0xff);
102
+ // In place byte swap for Uint32Array
103
+ function byteSwap32(arr) {
104
+ for (let i = 0; i < arr.length; i++) {
105
+ arr[i] = byteSwap(arr[i]);
106
+ }
107
+ }
108
+ /**
109
+ * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
110
+ */
111
+ function utf8ToBytes$1(str) {
112
+ if (typeof str !== 'string')
113
+ throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
114
+ return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
115
+ }
116
+ /**
117
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
118
+ * Warning: when Uint8Array is passed, it would NOT get copied.
119
+ * Keep in mind for future mutable operations.
120
+ */
121
+ function toBytes(data) {
122
+ if (typeof data === 'string')
123
+ data = utf8ToBytes$1(data);
124
+ bytes(data);
125
+ return data;
126
+ }
127
+ // For runtime check if class implements interface
128
+ class Hash {
129
+ // Safe version that clones internal state
130
+ clone() {
131
+ return this._cloneInto();
132
+ }
133
+ }
134
+ function wrapConstructor(hashCons) {
135
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
136
+ const tmp = hashCons();
137
+ hashC.outputLen = tmp.outputLen;
138
+ hashC.blockLen = tmp.blockLen;
139
+ hashC.create = () => hashCons();
140
+ return hashC;
141
+ }
142
+
143
+ // SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
144
+ // It's called a sponge function.
145
+ // Various per round constants calculations
146
+ const SHA3_PI = [];
147
+ const SHA3_ROTL = [];
148
+ const _SHA3_IOTA = [];
149
+ const _0n = /* @__PURE__ */ BigInt(0);
150
+ const _1n = /* @__PURE__ */ BigInt(1);
151
+ const _2n = /* @__PURE__ */ BigInt(2);
152
+ const _7n = /* @__PURE__ */ BigInt(7);
153
+ const _256n = /* @__PURE__ */ BigInt(256);
154
+ const _0x71n = /* @__PURE__ */ BigInt(0x71);
155
+ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
156
+ // Pi
157
+ [x, y] = [y, (2 * x + 3 * y) % 5];
158
+ SHA3_PI.push(2 * (5 * y + x));
159
+ // Rotational
160
+ SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
161
+ // Iota
162
+ let t = _0n;
163
+ for (let j = 0; j < 7; j++) {
164
+ R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
165
+ if (R & _2n)
166
+ t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
167
+ }
168
+ _SHA3_IOTA.push(t);
169
+ }
170
+ const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
171
+ // Left rotation (without 0, 32, 64)
172
+ const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
173
+ const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
174
+ // Same as keccakf1600, but allows to skip some rounds
175
+ function keccakP(s, rounds = 24) {
176
+ const B = new Uint32Array(5 * 2);
177
+ // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
178
+ for (let round = 24 - rounds; round < 24; round++) {
179
+ // Theta θ
180
+ for (let x = 0; x < 10; x++)
181
+ B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
182
+ for (let x = 0; x < 10; x += 2) {
183
+ const idx1 = (x + 8) % 10;
184
+ const idx0 = (x + 2) % 10;
185
+ const B0 = B[idx0];
186
+ const B1 = B[idx0 + 1];
187
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
188
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
189
+ for (let y = 0; y < 50; y += 10) {
190
+ s[x + y] ^= Th;
191
+ s[x + y + 1] ^= Tl;
192
+ }
193
+ }
194
+ // Rho (ρ) and Pi (π)
195
+ let curH = s[2];
196
+ let curL = s[3];
197
+ for (let t = 0; t < 24; t++) {
198
+ const shift = SHA3_ROTL[t];
199
+ const Th = rotlH(curH, curL, shift);
200
+ const Tl = rotlL(curH, curL, shift);
201
+ const PI = SHA3_PI[t];
202
+ curH = s[PI];
203
+ curL = s[PI + 1];
204
+ s[PI] = Th;
205
+ s[PI + 1] = Tl;
206
+ }
207
+ // Chi (χ)
208
+ for (let y = 0; y < 50; y += 10) {
209
+ for (let x = 0; x < 10; x++)
210
+ B[x] = s[y + x];
211
+ for (let x = 0; x < 10; x++)
212
+ s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
213
+ }
214
+ // Iota (ι)
215
+ s[0] ^= SHA3_IOTA_H[round];
216
+ s[1] ^= SHA3_IOTA_L[round];
217
+ }
218
+ B.fill(0);
219
+ }
220
+ class Keccak extends Hash {
221
+ // NOTE: we accept arguments in bytes instead of bits here.
222
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
223
+ super();
224
+ this.blockLen = blockLen;
225
+ this.suffix = suffix;
226
+ this.outputLen = outputLen;
227
+ this.enableXOF = enableXOF;
228
+ this.rounds = rounds;
229
+ this.pos = 0;
230
+ this.posOut = 0;
231
+ this.finished = false;
232
+ this.destroyed = false;
233
+ // Can be passed from user as dkLen
234
+ number(outputLen);
235
+ // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
236
+ if (0 >= this.blockLen || this.blockLen >= 200)
237
+ throw new Error('Sha3 supports only keccak-f1600 function');
238
+ this.state = new Uint8Array(200);
239
+ this.state32 = u32(this.state);
240
+ }
241
+ keccak() {
242
+ if (!isLE)
243
+ byteSwap32(this.state32);
244
+ keccakP(this.state32, this.rounds);
245
+ if (!isLE)
246
+ byteSwap32(this.state32);
247
+ this.posOut = 0;
248
+ this.pos = 0;
249
+ }
250
+ update(data) {
251
+ exists(this);
252
+ const { blockLen, state } = this;
253
+ data = toBytes(data);
254
+ const len = data.length;
255
+ for (let pos = 0; pos < len;) {
256
+ const take = Math.min(blockLen - this.pos, len - pos);
257
+ for (let i = 0; i < take; i++)
258
+ state[this.pos++] ^= data[pos++];
259
+ if (this.pos === blockLen)
260
+ this.keccak();
261
+ }
262
+ return this;
263
+ }
264
+ finish() {
265
+ if (this.finished)
266
+ return;
267
+ this.finished = true;
268
+ const { state, suffix, pos, blockLen } = this;
269
+ // Do the padding
270
+ state[pos] ^= suffix;
271
+ if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
272
+ this.keccak();
273
+ state[blockLen - 1] ^= 0x80;
274
+ this.keccak();
275
+ }
276
+ writeInto(out) {
277
+ exists(this, false);
278
+ bytes(out);
279
+ this.finish();
280
+ const bufferOut = this.state;
281
+ const { blockLen } = this;
282
+ for (let pos = 0, len = out.length; pos < len;) {
283
+ if (this.posOut >= blockLen)
284
+ this.keccak();
285
+ const take = Math.min(blockLen - this.posOut, len - pos);
286
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
287
+ this.posOut += take;
288
+ pos += take;
289
+ }
290
+ return out;
291
+ }
292
+ xofInto(out) {
293
+ // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
294
+ if (!this.enableXOF)
295
+ throw new Error('XOF is not possible for this instance');
296
+ return this.writeInto(out);
297
+ }
298
+ xof(bytes) {
299
+ number(bytes);
300
+ return this.xofInto(new Uint8Array(bytes));
301
+ }
302
+ digestInto(out) {
303
+ output(out, this);
304
+ if (this.finished)
305
+ throw new Error('digest() was already called');
306
+ this.writeInto(out);
307
+ this.destroy();
308
+ return out;
309
+ }
310
+ digest() {
311
+ return this.digestInto(new Uint8Array(this.outputLen));
312
+ }
313
+ destroy() {
314
+ this.destroyed = true;
315
+ this.state.fill(0);
316
+ }
317
+ _cloneInto(to) {
318
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
319
+ to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
320
+ to.state32.set(this.state32);
321
+ to.pos = this.pos;
322
+ to.posOut = this.posOut;
323
+ to.finished = this.finished;
324
+ to.rounds = rounds;
325
+ // Suffix can change in cSHAKE
326
+ to.suffix = suffix;
327
+ to.outputLen = outputLen;
328
+ to.enableXOF = enableXOF;
329
+ to.destroyed = this.destroyed;
330
+ return to;
331
+ }
332
+ }
333
+ const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
334
+ /**
335
+ * keccak-256 hash function. Different from SHA3-256.
336
+ * @param message - that would be hashed
337
+ */
338
+ const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
339
+
340
+ assert$1.bool;
341
+ assert$1.bytes;
342
+ // Internal utils
343
+ function wrapHash(hash) {
344
+ return (msg) => {
345
+ assert$1.bytes(msg);
346
+ return hash(msg);
347
+ };
348
+ }
349
+ // TODO(v3): switch away from node crypto, remove this unnecessary variable.
350
+ (() => {
351
+ const webCrypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : undefined;
352
+ const nodeRequire = typeof module !== "undefined" &&
353
+ typeof module.require === "function" &&
354
+ module.require.bind(module);
355
+ return {
356
+ node: nodeRequire && !webCrypto ? nodeRequire("crypto") : undefined,
357
+ web: webCrypto
358
+ };
359
+ })();
360
+
361
+ const keccak256 = (() => {
362
+ const k = wrapHash(keccak_256);
363
+ k.create = keccak_256.create;
364
+ return k;
365
+ })();
366
+
367
+ /*
368
+ This file is part of web3.js.
369
+
370
+ web3.js is free software: you can redistribute it and/or modify
371
+ it under the terms of the GNU Lesser General Public License as published by
372
+ the Free Software Foundation, either version 3 of the License, or
373
+ (at your option) any later version.
374
+
375
+ web3.js is distributed in the hope that it will be useful,
376
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
377
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
378
+ GNU Lesser General Public License for more details.
379
+
380
+ You should have received a copy of the GNU Lesser General Public License
381
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
382
+ */
383
+ // Response error
384
+ const ERR_MULTIPLE_ERRORS = 208;
385
+ // RPC error codes (EIP-1193)
386
+ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md#provider-errors
387
+ const JSONRPC_ERR_REJECTED_REQUEST = 4001;
388
+ const JSONRPC_ERR_UNAUTHORIZED = 4100;
389
+ const JSONRPC_ERR_UNSUPPORTED_METHOD = 4200;
390
+ const JSONRPC_ERR_DISCONNECTED = 4900;
391
+ const JSONRPC_ERR_CHAIN_DISCONNECTED = 4901;
392
+ const ERR_INVALID_ADDRESS = 1005;
393
+ // RPC error codes (EIP-1474)
394
+ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md
395
+ const ERR_RPC_INVALID_JSON = -32700;
396
+ const ERR_RPC_INVALID_REQUEST = -32600;
397
+ const ERR_RPC_INVALID_METHOD = -32601;
398
+ const ERR_RPC_INVALID_PARAMS = -32602;
399
+ const ERR_RPC_INTERNAL_ERROR = -32603;
400
+ const ERR_RPC_INVALID_INPUT = -32000;
401
+ const ERR_RPC_MISSING_RESOURCE = -32001;
402
+ const ERR_RPC_UNAVAILABLE_RESOURCE = -32002;
403
+ const ERR_RPC_TRANSACTION_REJECTED = -32003;
404
+ const ERR_RPC_UNSUPPORTED_METHOD = -32004;
405
+ const ERR_RPC_LIMIT_EXCEEDED = -32005;
406
+ const ERR_RPC_NOT_SUPPORTED = -32006;
407
+
408
+ /*
409
+ This file is part of web3.js.
410
+
411
+ web3.js is free software: you can redistribute it and/or modify
412
+ it under the terms of the GNU Lesser General Public License as published by
413
+ the Free Software Foundation, either version 3 of the License, or
414
+ (at your option) any later version.
415
+
416
+ web3.js is distributed in the hope that it will be useful,
417
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
418
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
419
+ GNU Lesser General Public License for more details.
420
+
421
+ You should have received a copy of the GNU Lesser General Public License
422
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
423
+ */
424
+ /**
425
+ * Base class for Web3 errors.
426
+ */
427
+ class BaseWeb3Error extends Error {
428
+ constructor(msg, cause) {
429
+ super(msg);
430
+ if (Array.isArray(cause)) {
431
+ // eslint-disable-next-line no-use-before-define
432
+ this.cause = new MultipleErrors(cause);
433
+ }
434
+ else {
435
+ this.cause = cause;
436
+ }
437
+ this.name = this.constructor.name;
438
+ if (typeof Error.captureStackTrace === 'function') {
439
+ Error.captureStackTrace(new.target.constructor);
440
+ }
441
+ else {
442
+ this.stack = new Error().stack;
443
+ }
444
+ }
445
+ /**
446
+ * @deprecated Use the `cause` property instead.
447
+ */
448
+ get innerError() {
449
+ // eslint-disable-next-line no-use-before-define
450
+ if (this.cause instanceof MultipleErrors) {
451
+ return this.cause.errors;
452
+ }
453
+ return this.cause;
454
+ }
455
+ /**
456
+ * @deprecated Use the `cause` property instead.
457
+ */
458
+ set innerError(cause) {
459
+ if (Array.isArray(cause)) {
460
+ // eslint-disable-next-line no-use-before-define
461
+ this.cause = new MultipleErrors(cause);
462
+ }
463
+ else {
464
+ this.cause = cause;
465
+ }
466
+ }
467
+ static convertToString(value, unquotValue = false) {
468
+ // Using "null" value intentionally for validation
469
+ // eslint-disable-next-line no-null/no-null
470
+ if (value === null || value === undefined)
471
+ return 'undefined';
472
+ const result = JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? v.toString() : v));
473
+ return unquotValue && ['bigint', 'string'].includes(typeof value)
474
+ ? result.replace(/['\\"]+/g, '')
475
+ : result;
476
+ }
477
+ toJSON() {
478
+ return {
479
+ name: this.name,
480
+ code: this.code,
481
+ message: this.message,
482
+ cause: this.cause,
483
+ // deprecated
484
+ innerError: this.cause,
485
+ };
486
+ }
487
+ }
488
+ class MultipleErrors extends BaseWeb3Error {
489
+ constructor(errors) {
490
+ super(`Multiple errors occurred: [${errors.map(e => e.message).join('], [')}]`);
491
+ this.code = ERR_MULTIPLE_ERRORS;
492
+ this.errors = errors;
493
+ }
494
+ }
495
+ class InvalidValueError extends BaseWeb3Error {
496
+ constructor(value, msg) {
497
+ super(`Invalid value given "${BaseWeb3Error.convertToString(value, true)}". Error: ${msg}.`);
498
+ this.name = this.constructor.name;
499
+ }
500
+ }
501
+
502
+ /*
503
+ This file is part of web3.js.
504
+
505
+ web3.js is free software: you can redistribute it and/or modify
506
+ it under the terms of the GNU Lesser General Public License as published by
507
+ the Free Software Foundation, either version 3 of the License, or
508
+ (at your option) any later version.
509
+
510
+ web3.js is distributed in the hope that it will be useful,
511
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
512
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
513
+ GNU Lesser General Public License for more details.
514
+
515
+ You should have received a copy of the GNU Lesser General Public License
516
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
517
+ */
518
+ /* eslint-disable max-classes-per-file */
519
+ class InvalidAddressError extends InvalidValueError {
520
+ constructor(value) {
521
+ super(value, 'invalid ethereum address');
522
+ this.code = ERR_INVALID_ADDRESS;
523
+ }
524
+ }
525
+
526
+ /*
527
+ This file is part of web3.js.
528
+
529
+ web3.js is free software: you can redistribute it and/or modify
530
+ it under the terms of the GNU Lesser General Public License as published by
531
+ the Free Software Foundation, either version 3 of the License, or
532
+ (at your option) any later version.
533
+
534
+ web3.js is distributed in the hope that it will be useful,
535
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
536
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
537
+ GNU Lesser General Public License for more details.
538
+
539
+ You should have received a copy of the GNU Lesser General Public License
540
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
541
+ */
542
+ /**
543
+ * A template string for a generic Rpc Error. The `*code*` will be replaced with the code number.
544
+ * Note: consider in next version that a spelling mistake could be corrected for `occured` and the value could be:
545
+ * `An Rpc error has occurred with a code of *code*`
546
+ */
547
+ const genericRpcErrorMessageTemplate = 'An Rpc error has occured with a code of *code*';
548
+ /* eslint-disable @typescript-eslint/naming-convention */
549
+ const RpcErrorMessages = {
550
+ // EIP-1474 & JSON RPC 2.0
551
+ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md
552
+ [ERR_RPC_INVALID_JSON]: {
553
+ message: 'Parse error',
554
+ description: 'Invalid JSON',
555
+ },
556
+ [ERR_RPC_INVALID_REQUEST]: {
557
+ message: 'Invalid request',
558
+ description: 'JSON is not a valid request object ',
559
+ },
560
+ [ERR_RPC_INVALID_METHOD]: {
561
+ message: 'Method not found',
562
+ description: 'Method does not exist ',
563
+ },
564
+ [ERR_RPC_INVALID_PARAMS]: {
565
+ message: 'Invalid params',
566
+ description: 'Invalid method parameters',
567
+ },
568
+ [ERR_RPC_INTERNAL_ERROR]: {
569
+ message: 'Internal error',
570
+ description: 'Internal JSON-RPC error',
571
+ },
572
+ [ERR_RPC_INVALID_INPUT]: {
573
+ message: 'Invalid input',
574
+ description: 'Missing or invalid parameters',
575
+ },
576
+ [ERR_RPC_MISSING_RESOURCE]: {
577
+ message: 'Resource not found',
578
+ description: 'Requested resource not found',
579
+ },
580
+ [ERR_RPC_UNAVAILABLE_RESOURCE]: {
581
+ message: 'Resource unavailable',
582
+ description: 'Requested resource not available',
583
+ },
584
+ [ERR_RPC_TRANSACTION_REJECTED]: {
585
+ message: 'Transaction rejected',
586
+ description: 'Transaction creation failed',
587
+ },
588
+ [ERR_RPC_UNSUPPORTED_METHOD]: {
589
+ message: 'Method not supported',
590
+ description: 'Method is not implemented',
591
+ },
592
+ [ERR_RPC_LIMIT_EXCEEDED]: {
593
+ message: 'Limit exceeded',
594
+ description: 'Request exceeds defined limit',
595
+ },
596
+ [ERR_RPC_NOT_SUPPORTED]: {
597
+ message: 'JSON-RPC version not supported',
598
+ description: 'Version of JSON-RPC protocol is not supported',
599
+ },
600
+ // EIP-1193
601
+ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md#provider-errors
602
+ [JSONRPC_ERR_REJECTED_REQUEST]: {
603
+ name: 'User Rejected Request',
604
+ message: 'The user rejected the request.',
605
+ },
606
+ [JSONRPC_ERR_UNAUTHORIZED]: {
607
+ name: 'Unauthorized',
608
+ message: 'The requested method and/or account has not been authorized by the user.',
609
+ },
610
+ [JSONRPC_ERR_UNSUPPORTED_METHOD]: {
611
+ name: 'Unsupported Method',
612
+ message: 'The Provider does not support the requested method.',
613
+ },
614
+ [JSONRPC_ERR_DISCONNECTED]: {
615
+ name: 'Disconnected',
616
+ message: 'The Provider is disconnected from all chains.',
617
+ },
618
+ [JSONRPC_ERR_CHAIN_DISCONNECTED]: {
619
+ name: 'Chain Disconnected',
620
+ message: 'The Provider is not connected to the requested chain.',
621
+ },
622
+ // EIP-1193 - CloseEvent
623
+ // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
624
+ '0-999': {
625
+ name: '',
626
+ message: 'Not used.',
627
+ },
628
+ 1000: {
629
+ name: 'Normal Closure',
630
+ message: 'The connection successfully completed the purpose for which it was created.',
631
+ },
632
+ 1001: {
633
+ name: 'Going Away',
634
+ message: 'The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection.',
635
+ },
636
+ 1002: {
637
+ name: 'Protocol error',
638
+ message: 'The endpoint is terminating the connection due to a protocol error.',
639
+ },
640
+ 1003: {
641
+ name: 'Unsupported Data',
642
+ message: 'The connection is being terminated because the endpoint received data of a type it cannot accept. (For example, a text-only endpoint received binary data.)',
643
+ },
644
+ 1004: {
645
+ name: 'Reserved',
646
+ message: 'Reserved. A meaning might be defined in the future.',
647
+ },
648
+ 1005: {
649
+ name: 'No Status Rcvd',
650
+ message: 'Reserved. Indicates that no status code was provided even though one was expected.',
651
+ },
652
+ 1006: {
653
+ name: 'Abnormal Closure',
654
+ message: 'Reserved. Indicates that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.',
655
+ },
656
+ 1007: {
657
+ name: 'Invalid frame payload data',
658
+ message: 'The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message).',
659
+ },
660
+ 1008: {
661
+ name: 'Policy Violation',
662
+ message: 'The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable.',
663
+ },
664
+ 1009: {
665
+ name: 'Message Too Big',
666
+ message: 'The endpoint is terminating the connection because a data frame was received that is too large.',
667
+ },
668
+ 1010: {
669
+ name: 'Mandatory Ext.',
670
+ message: "The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't.",
671
+ },
672
+ 1011: {
673
+ name: 'Internal Error',
674
+ message: 'The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.',
675
+ },
676
+ 1012: {
677
+ name: 'Service Restart',
678
+ message: 'The server is terminating the connection because it is restarting.',
679
+ },
680
+ 1013: {
681
+ name: 'Try Again Later',
682
+ message: 'The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients.',
683
+ },
684
+ 1014: {
685
+ name: 'Bad Gateway',
686
+ message: 'The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code.',
687
+ },
688
+ 1015: {
689
+ name: 'TLS handshake',
690
+ message: "Reserved. Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).",
691
+ },
692
+ '1016-2999': {
693
+ name: '',
694
+ message: 'For definition by future revisions of the WebSocket Protocol specification, and for definition by extension specifications.',
695
+ },
696
+ '3000-3999': {
697
+ name: '',
698
+ message: 'For use by libraries, frameworks, and applications. These status codes are registered directly with IANA. The interpretation of these codes is undefined by the WebSocket protocol.',
699
+ },
700
+ '4000-4999': {
701
+ name: '',
702
+ message: "For private use, and thus can't be registered. Such codes can be used by prior agreements between WebSocket applications. The interpretation of these codes is undefined by the WebSocket protocol.",
703
+ },
704
+ };
705
+
706
+ /*
707
+ This file is part of web3.js.
708
+
709
+ web3.js is free software: you can redistribute it and/or modify
710
+ it under the terms of the GNU Lesser General Public License as published by
711
+ the Free Software Foundation, either version 3 of the License, or
712
+ (at your option) any later version.
713
+
714
+ web3.js is distributed in the hope that it will be useful,
715
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
716
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
717
+ GNU Lesser General Public License for more details.
718
+
719
+ You should have received a copy of the GNU Lesser General Public License
720
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
721
+ */
722
+ class RpcError extends BaseWeb3Error {
723
+ constructor(rpcError, message) {
724
+ super(message !== null && message !== void 0 ? message : genericRpcErrorMessageTemplate.replace('*code*', rpcError.error.code.toString()));
725
+ this.code = rpcError.error.code;
726
+ this.id = rpcError.id;
727
+ this.jsonrpc = rpcError.jsonrpc;
728
+ this.jsonRpcError = rpcError.error;
729
+ }
730
+ toJSON() {
731
+ return Object.assign(Object.assign({}, super.toJSON()), { error: this.jsonRpcError, id: this.id, jsonRpc: this.jsonrpc });
732
+ }
733
+ }
734
+ class ParseError extends RpcError {
735
+ constructor(rpcError) {
736
+ super(rpcError, RpcErrorMessages[ERR_RPC_INVALID_JSON].message);
737
+ this.code = ERR_RPC_INVALID_JSON;
738
+ }
739
+ }
740
+ class InvalidRequestError extends RpcError {
741
+ constructor(rpcError) {
742
+ super(rpcError, RpcErrorMessages[ERR_RPC_INVALID_REQUEST].message);
743
+ this.code = ERR_RPC_INVALID_REQUEST;
744
+ }
745
+ }
746
+ class MethodNotFoundError extends RpcError {
747
+ constructor(rpcError) {
748
+ super(rpcError, RpcErrorMessages[ERR_RPC_INVALID_METHOD].message);
749
+ this.code = ERR_RPC_INVALID_METHOD;
750
+ }
751
+ }
752
+ class InvalidParamsError extends RpcError {
753
+ constructor(rpcError) {
754
+ super(rpcError, RpcErrorMessages[ERR_RPC_INVALID_PARAMS].message);
755
+ this.code = ERR_RPC_INVALID_PARAMS;
756
+ }
757
+ }
758
+ class InternalError extends RpcError {
759
+ constructor(rpcError) {
760
+ super(rpcError, RpcErrorMessages[ERR_RPC_INTERNAL_ERROR].message);
761
+ this.code = ERR_RPC_INTERNAL_ERROR;
762
+ }
763
+ }
764
+ class InvalidInputError extends RpcError {
765
+ constructor(rpcError) {
766
+ super(rpcError, RpcErrorMessages[ERR_RPC_INVALID_INPUT].message);
767
+ this.code = ERR_RPC_INVALID_INPUT;
768
+ }
769
+ }
770
+ class MethodNotSupported extends RpcError {
771
+ constructor(rpcError) {
772
+ super(rpcError, RpcErrorMessages[ERR_RPC_UNSUPPORTED_METHOD].message);
773
+ this.code = ERR_RPC_UNSUPPORTED_METHOD;
774
+ }
775
+ }
776
+ class ResourceUnavailableError extends RpcError {
777
+ constructor(rpcError) {
778
+ super(rpcError, RpcErrorMessages[ERR_RPC_UNAVAILABLE_RESOURCE].message);
779
+ this.code = ERR_RPC_UNAVAILABLE_RESOURCE;
780
+ }
781
+ }
782
+ class ResourcesNotFoundError extends RpcError {
783
+ constructor(rpcError) {
784
+ super(rpcError, RpcErrorMessages[ERR_RPC_MISSING_RESOURCE].message);
785
+ this.code = ERR_RPC_MISSING_RESOURCE;
786
+ }
787
+ }
788
+ class VersionNotSupportedError extends RpcError {
789
+ constructor(rpcError) {
790
+ super(rpcError, RpcErrorMessages[ERR_RPC_NOT_SUPPORTED].message);
791
+ this.code = ERR_RPC_NOT_SUPPORTED;
792
+ }
793
+ }
794
+ class TransactionRejectedError extends RpcError {
795
+ constructor(rpcError) {
796
+ super(rpcError, RpcErrorMessages[ERR_RPC_TRANSACTION_REJECTED].message);
797
+ this.code = ERR_RPC_TRANSACTION_REJECTED;
798
+ }
799
+ }
800
+ class LimitExceededError extends RpcError {
801
+ constructor(rpcError) {
802
+ super(rpcError, RpcErrorMessages[ERR_RPC_LIMIT_EXCEEDED].message);
803
+ this.code = ERR_RPC_LIMIT_EXCEEDED;
804
+ }
805
+ }
806
+ const rpcErrorsMap = new Map();
807
+ rpcErrorsMap.set(ERR_RPC_INVALID_JSON, { error: ParseError });
808
+ rpcErrorsMap.set(ERR_RPC_INVALID_REQUEST, {
809
+ error: InvalidRequestError,
810
+ });
811
+ rpcErrorsMap.set(ERR_RPC_INVALID_METHOD, {
812
+ error: MethodNotFoundError,
813
+ });
814
+ rpcErrorsMap.set(ERR_RPC_INVALID_PARAMS, { error: InvalidParamsError });
815
+ rpcErrorsMap.set(ERR_RPC_INTERNAL_ERROR, { error: InternalError });
816
+ rpcErrorsMap.set(ERR_RPC_INVALID_INPUT, { error: InvalidInputError });
817
+ rpcErrorsMap.set(ERR_RPC_UNSUPPORTED_METHOD, {
818
+ error: MethodNotSupported,
819
+ });
820
+ rpcErrorsMap.set(ERR_RPC_UNAVAILABLE_RESOURCE, {
821
+ error: ResourceUnavailableError,
822
+ });
823
+ rpcErrorsMap.set(ERR_RPC_TRANSACTION_REJECTED, {
824
+ error: TransactionRejectedError,
825
+ });
826
+ rpcErrorsMap.set(ERR_RPC_MISSING_RESOURCE, {
827
+ error: ResourcesNotFoundError,
828
+ });
829
+ rpcErrorsMap.set(ERR_RPC_NOT_SUPPORTED, {
830
+ error: VersionNotSupportedError,
831
+ });
832
+ rpcErrorsMap.set(ERR_RPC_LIMIT_EXCEEDED, { error: LimitExceededError });
833
+
834
+ /*
835
+ This file is part of web3.js.
836
+
837
+ web3.js is free software: you can redistribute it and/or modify
838
+ it under the terms of the GNU Lesser General Public License as published by
839
+ the Free Software Foundation, either version 3 of the License, or
840
+ (at your option) any later version.
841
+
842
+ web3.js is distributed in the hope that it will be useful,
843
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
844
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
845
+ GNU Lesser General Public License for more details.
846
+
847
+ You should have received a copy of the GNU Lesser General Public License
848
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
849
+ */
850
+ /**
851
+ * checks input if typeof data is valid string input
852
+ */
853
+ const isHexStrict = (hex) => typeof hex === 'string' && /^((-)?0x[0-9a-f]+|(0x))$/i.test(hex);
854
+
855
+ /*
856
+ This file is part of web3.js.
857
+
858
+ web3.js is free software: you can redistribute it and/or modify
859
+ it under the terms of the GNU Lesser General Public License as published by
860
+ the Free Software Foundation, either version 3 of the License, or
861
+ (at your option) any later version.
862
+
863
+ web3.js is distributed in the hope that it will be useful,
864
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
865
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
866
+ GNU Lesser General Public License for more details.
867
+
868
+ You should have received a copy of the GNU Lesser General Public License
869
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
870
+ */
871
+ function uint8ArrayToHexString(uint8Array) {
872
+ let hexString = '0x';
873
+ for (const e of uint8Array) {
874
+ const hex = e.toString(16);
875
+ hexString += hex.length === 1 ? `0${hex}` : hex;
876
+ }
877
+ return hexString;
878
+ }
879
+ // @TODO: Remove this function and its usages once all sub dependencies uses version 1.3.3 or above of @noble/hashes
880
+ function ensureIfUint8Array(data) {
881
+ var _a;
882
+ if (!(data instanceof Uint8Array) &&
883
+ ((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array') {
884
+ return Uint8Array.from(data);
885
+ }
886
+ return data;
887
+ }
888
+
889
+ /*
890
+ This file is part of web3.js.
891
+
892
+ web3.js is free software: you can redistribute it and/or modify
893
+ it under the terms of the GNU Lesser General Public License as published by
894
+ the Free Software Foundation, either version 3 of the License, or
895
+ (at your option) any later version.
896
+
897
+ web3.js is distributed in the hope that it will be useful,
898
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
899
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
900
+ GNU Lesser General Public License for more details.
901
+
902
+ You should have received a copy of the GNU Lesser General Public License
903
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
904
+ */
905
+ /**
906
+ * checks input if typeof data is valid Uint8Array input
907
+ */
908
+ const isUint8Array = (data) => { var _a, _b; return data instanceof Uint8Array || ((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Uint8Array' || ((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'Buffer'; };
909
+
910
+ /*
911
+ This file is part of web3.js.
912
+
913
+ web3.js is free software: you can redistribute it and/or modify
914
+ it under the terms of the GNU Lesser General Public License as published by
915
+ the Free Software Foundation, either version 3 of the License, or
916
+ (at your option) any later version.
917
+
918
+ web3.js is distributed in the hope that it will be useful,
919
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
920
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
921
+ GNU Lesser General Public License for more details.
922
+
923
+ You should have received a copy of the GNU Lesser General Public License
924
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
925
+ */
926
+ /**
927
+ * Checks the checksum of a given address. Will also return false on non-checksum addresses.
928
+ */
929
+ const checkAddressCheckSum = (data) => {
930
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(data))
931
+ return false;
932
+ const address = data.slice(2);
933
+ const updatedData = utf8ToBytes$1(address.toLowerCase());
934
+ const addressHash = uint8ArrayToHexString(keccak256(ensureIfUint8Array(updatedData))).slice(2);
935
+ for (let i = 0; i < 40; i += 1) {
936
+ // the nth letter should be uppercase if the nth digit of casemap is 1
937
+ if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
938
+ (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
939
+ return false;
940
+ }
941
+ }
942
+ return true;
943
+ };
944
+ /**
945
+ * Checks if a given string is a valid Ethereum address. It will also check the checksum, if the address has upper and lowercase letters.
946
+ */
947
+ const isAddress = (value, checkChecksum = true) => {
948
+ if (typeof value !== 'string' && !isUint8Array(value)) {
949
+ return false;
950
+ }
951
+ let valueToCheck;
952
+ if (isUint8Array(value)) {
953
+ valueToCheck = uint8ArrayToHexString(value);
954
+ }
955
+ else if (typeof value === 'string' && !isHexStrict(value)) {
956
+ valueToCheck = value.toLowerCase().startsWith('0x') ? value : `0x${value}`;
957
+ }
958
+ else {
959
+ valueToCheck = value;
960
+ }
961
+ // check if it has the basic requirements of an address
962
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(valueToCheck)) {
963
+ return false;
964
+ }
965
+ // If it's ALL lowercase or ALL upppercase
966
+ if (/^(0x|0X)?[0-9a-f]{40}$/.test(valueToCheck) ||
967
+ /^(0x|0X)?[0-9A-F]{40}$/.test(valueToCheck)) {
968
+ return true;
969
+ // Otherwise check each case
970
+ }
971
+ return checkChecksum ? checkAddressCheckSum(valueToCheck) : true;
972
+ };
973
+
974
+ /*
975
+ This file is part of web3.js.
976
+
977
+ web3.js is free software: you can redistribute it and/or modify
978
+ it under the terms of the GNU Lesser General Public License as published by
979
+ the Free Software Foundation, either version 3 of the License, or
980
+ (at your option) any later version.
981
+
982
+ web3.js is distributed in the hope that it will be useful,
983
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
984
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
985
+ GNU Lesser General Public License for more details.
986
+
987
+ You should have received a copy of the GNU Lesser General Public License
988
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
989
+ */
990
+ var FMT_NUMBER;
991
+ (function (FMT_NUMBER) {
992
+ FMT_NUMBER["NUMBER"] = "NUMBER_NUMBER";
993
+ FMT_NUMBER["HEX"] = "NUMBER_HEX";
994
+ FMT_NUMBER["STR"] = "NUMBER_STR";
995
+ FMT_NUMBER["BIGINT"] = "NUMBER_BIGINT";
996
+ })(FMT_NUMBER || (FMT_NUMBER = {}));
997
+ var FMT_BYTES;
998
+ (function (FMT_BYTES) {
999
+ FMT_BYTES["HEX"] = "BYTES_HEX";
1000
+ FMT_BYTES["UINT8ARRAY"] = "BYTES_UINT8ARRAY";
1001
+ })(FMT_BYTES || (FMT_BYTES = {}));
1002
+ ({
1003
+ number: FMT_NUMBER.BIGINT,
1004
+ bytes: FMT_BYTES.HEX,
1005
+ });
1006
+ ({ number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX });
1007
+
1008
+ var BlockTags;
1009
+ (function (BlockTags) {
1010
+ BlockTags["EARLIEST"] = "earliest";
1011
+ BlockTags["LATEST"] = "latest";
1012
+ BlockTags["PENDING"] = "pending";
1013
+ BlockTags["SAFE"] = "safe";
1014
+ BlockTags["FINALIZED"] = "finalized";
1015
+ })(BlockTags || (BlockTags = {}));
1016
+ // This list of hardforks is expected to be in order
1017
+ // keep this in mind when making changes to it
1018
+ var HardforksOrdered;
1019
+ (function (HardforksOrdered) {
1020
+ HardforksOrdered["chainstart"] = "chainstart";
1021
+ HardforksOrdered["frontier"] = "frontier";
1022
+ HardforksOrdered["homestead"] = "homestead";
1023
+ HardforksOrdered["dao"] = "dao";
1024
+ HardforksOrdered["tangerineWhistle"] = "tangerineWhistle";
1025
+ HardforksOrdered["spuriousDragon"] = "spuriousDragon";
1026
+ HardforksOrdered["byzantium"] = "byzantium";
1027
+ HardforksOrdered["constantinople"] = "constantinople";
1028
+ HardforksOrdered["petersburg"] = "petersburg";
1029
+ HardforksOrdered["istanbul"] = "istanbul";
1030
+ HardforksOrdered["muirGlacier"] = "muirGlacier";
1031
+ HardforksOrdered["berlin"] = "berlin";
1032
+ HardforksOrdered["london"] = "london";
1033
+ HardforksOrdered["altair"] = "altair";
1034
+ HardforksOrdered["arrowGlacier"] = "arrowGlacier";
1035
+ HardforksOrdered["grayGlacier"] = "grayGlacier";
1036
+ HardforksOrdered["bellatrix"] = "bellatrix";
1037
+ HardforksOrdered["merge"] = "merge";
1038
+ HardforksOrdered["capella"] = "capella";
1039
+ HardforksOrdered["shanghai"] = "shanghai";
1040
+ })(HardforksOrdered || (HardforksOrdered = {}));
1041
+
1042
+ (globalThis && globalThis.__awaiter) || function (thisArg, _arguments, P, generator) {
1043
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1044
+ return new (P || (P = Promise))(function (resolve, reject) {
1045
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1046
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1047
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1048
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1049
+ });
1050
+ };
1051
+
1052
+ /*
1053
+ This file is part of web3.js.
1054
+
1055
+ web3.js is free software: you can redistribute it and/or modify
1056
+ it under the terms of the GNU Lesser General Public License as published by
1057
+ the Free Software Foundation, either version 3 of the License, or
1058
+ (at your option) any later version.
1059
+
1060
+ web3.js is distributed in the hope that it will be useful,
1061
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1062
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1063
+ GNU Lesser General Public License for more details.
1064
+
1065
+ You should have received a copy of the GNU Lesser General Public License
1066
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1067
+ */
1068
+ // Explicitly check for the
1069
+ // eslint-disable-next-line @typescript-eslint/ban-types
1070
+ const isNullish = (item) =>
1071
+ // Using "null" value intentionally for validation
1072
+ // eslint-disable-next-line no-null/no-null
1073
+ item === undefined || item === null;
1074
+
1075
+ /*
1076
+ This file is part of web3.js.
1077
+
1078
+ web3.js is free software: you can redistribute it and/or modify
1079
+ it under the terms of the GNU Lesser General Public License as published by
1080
+ the Free Software Foundation, either version 3 of the License, or
1081
+ (at your option) any later version.
1082
+
1083
+ web3.js is distributed in the hope that it will be useful,
1084
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1085
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1086
+ GNU Lesser General Public License for more details.
1087
+
1088
+ You should have received a copy of the GNU Lesser General Public License
1089
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1090
+ */
1091
+ /**
1092
+ * @module Utils
1093
+ */
1094
+ // Ref: https://ethdocs.org/en/latest/ether.html
1095
+ // Note: this could be simplified using ** operator, but babel does not handle it well (https://github.com/babel/babel/issues/13109)
1096
+ /** @internal */
1097
+ ({
1098
+ noether: BigInt(0),
1099
+ wei: BigInt(1),
1100
+ kwei: BigInt(1000),
1101
+ Kwei: BigInt(1000),
1102
+ babbage: BigInt(1000),
1103
+ femtoether: BigInt(1000),
1104
+ mwei: BigInt(1000000),
1105
+ Mwei: BigInt(1000000),
1106
+ lovelace: BigInt(1000000),
1107
+ picoether: BigInt(1000000),
1108
+ gwei: BigInt(1000000000),
1109
+ Gwei: BigInt(1000000000),
1110
+ shannon: BigInt(1000000000),
1111
+ nanoether: BigInt(1000000000),
1112
+ nano: BigInt(1000000000),
1113
+ szabo: BigInt(1000000000000),
1114
+ microether: BigInt(1000000000000),
1115
+ micro: BigInt(1000000000000),
1116
+ finney: BigInt(1000000000000000),
1117
+ milliether: BigInt(1000000000000000),
1118
+ milli: BigInt(1000000000000000),
1119
+ ether: BigInt('1000000000000000000'),
1120
+ kether: BigInt('1000000000000000000000'),
1121
+ grand: BigInt('1000000000000000000000'),
1122
+ mether: BigInt('1000000000000000000000000'),
1123
+ gether: BigInt('1000000000000000000000000000'),
1124
+ tether: BigInt('1000000000000000000000000000000'),
1125
+ });
1126
+ const utf8ToBytes = utf8ToBytes$1;
1127
+ /**
1128
+ * Will convert an upper or lowercase Ethereum address to a checksum address.
1129
+ * @param address - An address string
1130
+ * @returns The checksum address
1131
+ * @example
1132
+ * ```ts
1133
+ * web3.utils.toChecksumAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d');
1134
+ * > "0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d"
1135
+ * ```
1136
+ */
1137
+ const toChecksumAddress = (address) => {
1138
+ if (!isAddress(address, false)) {
1139
+ throw new InvalidAddressError(address);
1140
+ }
1141
+ const lowerCaseAddress = address.toLowerCase().replace(/^0x/i, '');
1142
+ // calling `Uint8Array.from` because `noble-hashes` checks with `instanceof Uint8Array` that fails in some edge cases:
1143
+ // https://github.com/paulmillr/noble-hashes/issues/25#issuecomment-1750106284
1144
+ const hash = uint8ArrayToHexString(keccak256(ensureIfUint8Array(utf8ToBytes(lowerCaseAddress))));
1145
+ if (isNullish(hash) ||
1146
+ hash === '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
1147
+ return ''; // // EIP-1052 if hash is equal to c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470, keccak was given empty data
1148
+ let checksumAddress = '0x';
1149
+ const addressHash = hash.replace(/^0x/i, '');
1150
+ for (let i = 0; i < lowerCaseAddress.length; i += 1) {
1151
+ // If ith character is 8 to f then make it uppercase
1152
+ if (parseInt(addressHash[i], 16) > 7) {
1153
+ checksumAddress += lowerCaseAddress[i].toUpperCase();
1154
+ }
1155
+ else {
1156
+ checksumAddress += lowerCaseAddress[i];
1157
+ }
1158
+ }
1159
+ return checksumAddress;
1160
+ };
1161
+
23
1162
  const style = ":host {\n display: inline-flex\n}";
24
1163
 
25
1164
  var __defProp = Object.defineProperty;
@@ -88,23 +1227,36 @@ let LuksoUsername = class extends TailwindStyledElement(style) {
88
1227
  }
89
1228
  });
90
1229
  }
91
- validateName(name) {
1230
+ transformName(name) {
92
1231
  if (this.noTransform) {
93
1232
  return name;
94
1233
  }
95
1234
  return name?.toLowerCase();
96
1235
  }
1236
+ transformAddress(address) {
1237
+ if (this.noTransform) {
1238
+ return address;
1239
+ }
1240
+ try {
1241
+ return toChecksumAddress(address);
1242
+ } catch (error) {
1243
+ console.warn(error);
1244
+ return address;
1245
+ }
1246
+ }
97
1247
  addressBytesTemplate(styles) {
1248
+ const address = this.transformAddress(this.address);
98
1249
  return x`<div
99
1250
  class=${styles}
100
1251
  style=${customStyleMap({
101
1252
  [`color: var(--${this.addressColor})`]: this.addressColor !== ""
102
1253
  })}
103
1254
  >
104
- #${this.address.slice(2, 6)}
1255
+ #${address.slice(2, 6)}
105
1256
  </div>`;
106
1257
  }
107
1258
  nameTemplate(styles) {
1259
+ const name = this.transformName(this.name);
108
1260
  return x`<div
109
1261
  class=${styles}
110
1262
  style=${customStyleMap({
@@ -112,17 +1264,18 @@ let LuksoUsername = class extends TailwindStyledElement(style) {
112
1264
  [`color: var(--${this.nameColor})`]: this.nameColor !== ""
113
1265
  })}
114
1266
  >
115
- ${this.hidePrefix ? A : this.prefix}${this.validateName(this.name)}
1267
+ ${this.hidePrefix ? A : this.prefix}${name}
116
1268
  </div>`;
117
1269
  }
118
1270
  addressTemplate(styles) {
1271
+ const address = this.transformAddress(this.address);
119
1272
  return x`<div
120
1273
  class=${styles}
121
1274
  style=${customStyleMap({
122
1275
  [`color: var(--${this.addressColor})`]: this.addressColor !== ""
123
1276
  })}
124
1277
  >
125
- ${sliceAddress(this.address, this.sliceBy, this.sliceBy)}
1278
+ ${sliceAddress(address, this.sliceBy, this.sliceBy)}
126
1279
  </div>`;
127
1280
  }
128
1281
  render() {