@lukso/web-components 1.147.0 → 1.147.1

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.
@@ -10,6 +10,7 @@ const styleMap = require('../../style-map-CV0IkMGG.cjs');
10
10
  const index = require('../../index-CaJky2qL.cjs');
11
11
  require('../../tailwind-config.cjs');
12
12
  const cn = require('../../cn-CNdKneQ1.cjs');
13
+ const isAddress = require('../../isAddress-CmQX7QJh.cjs');
13
14
  const index$1 = require('../../index-CzuGUp5e.cjs');
14
15
  require('../lukso-image/index.cjs');
15
16
 
@@ -26,841 +27,11 @@ const e=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"objec
26
27
  * SPDX-License-Identifier: BSD-3-Clause
27
28
  */function o(o){return (e$1,n)=>{const{slot:r,selector:s}=o??{},c="slot"+(r?`[name=${r}]`:":not([name])");return e(e$1,n,{get(){const t=this.renderRoot?.querySelector(c),e=t?.assignedElements(o)??[];return void 0===s?e:e.filter((t=>t.matches(s)))}})}}
28
29
 
29
- function isHex(value, { strict = true } = {}) {
30
- if (!value)
31
- return false;
32
- if (typeof value !== 'string')
33
- return false;
34
- return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x');
35
- }
36
-
37
- /**
38
- * @description Retrieves the size of the value (in bytes).
39
- *
40
- * @param value The value (hex or byte array) to retrieve the size of.
41
- * @returns The size of the value (in bytes).
42
- */
43
- function size(value) {
44
- if (isHex(value, { strict: false }))
45
- return Math.ceil((value.length - 2) / 2);
46
- return value.length;
47
- }
48
-
49
- const version = '2.33.0';
50
-
51
- let errorConfig = {
52
- getDocsUrl: ({ docsBaseUrl, docsPath = '', docsSlug, }) => docsPath
53
- ? `${docsBaseUrl ?? 'https://viem.sh'}${docsPath}${docsSlug ? `#${docsSlug}` : ''}`
54
- : undefined,
55
- version: `viem@${version}`,
56
- };
57
- class BaseError extends Error {
58
- constructor(shortMessage, args = {}) {
59
- const details = (() => {
60
- if (args.cause instanceof BaseError)
61
- return args.cause.details;
62
- if (args.cause?.message)
63
- return args.cause.message;
64
- return args.details;
65
- })();
66
- const docsPath = (() => {
67
- if (args.cause instanceof BaseError)
68
- return args.cause.docsPath || args.docsPath;
69
- return args.docsPath;
70
- })();
71
- const docsUrl = errorConfig.getDocsUrl?.({ ...args, docsPath });
72
- const message = [
73
- shortMessage || 'An error occurred.',
74
- '',
75
- ...(args.metaMessages ? [...args.metaMessages, ''] : []),
76
- ...(docsUrl ? [`Docs: ${docsUrl}`] : []),
77
- ...(details ? [`Details: ${details}`] : []),
78
- ...(errorConfig.version ? [`Version: ${errorConfig.version}`] : []),
79
- ].join('\n');
80
- super(message, args.cause ? { cause: args.cause } : undefined);
81
- Object.defineProperty(this, "details", {
82
- enumerable: true,
83
- configurable: true,
84
- writable: true,
85
- value: void 0
86
- });
87
- Object.defineProperty(this, "docsPath", {
88
- enumerable: true,
89
- configurable: true,
90
- writable: true,
91
- value: void 0
92
- });
93
- Object.defineProperty(this, "metaMessages", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: void 0
98
- });
99
- Object.defineProperty(this, "shortMessage", {
100
- enumerable: true,
101
- configurable: true,
102
- writable: true,
103
- value: void 0
104
- });
105
- Object.defineProperty(this, "version", {
106
- enumerable: true,
107
- configurable: true,
108
- writable: true,
109
- value: void 0
110
- });
111
- Object.defineProperty(this, "name", {
112
- enumerable: true,
113
- configurable: true,
114
- writable: true,
115
- value: 'BaseError'
116
- });
117
- this.details = details;
118
- this.docsPath = docsPath;
119
- this.metaMessages = args.metaMessages;
120
- this.name = args.name ?? this.name;
121
- this.shortMessage = shortMessage;
122
- this.version = version;
123
- }
124
- walk(fn) {
125
- return walk(this, fn);
126
- }
127
- }
128
- function walk(err, fn) {
129
- if (fn?.(err))
130
- return err;
131
- if (err &&
132
- typeof err === 'object' &&
133
- 'cause' in err &&
134
- err.cause !== undefined)
135
- return walk(err.cause, fn);
136
- return fn ? null : err;
137
- }
138
-
139
- class SizeExceedsPaddingSizeError extends BaseError {
140
- constructor({ size, targetSize, type, }) {
141
- super(`${type.charAt(0).toUpperCase()}${type
142
- .slice(1)
143
- .toLowerCase()} size (${size}) exceeds padding size (${targetSize}).`, { name: 'SizeExceedsPaddingSizeError' });
144
- }
145
- }
146
-
147
- function pad(hexOrBytes, { dir, size = 32 } = {}) {
148
- if (typeof hexOrBytes === 'string')
149
- return padHex(hexOrBytes, { dir, size });
150
- return padBytes(hexOrBytes, { dir, size });
151
- }
152
- function padHex(hex_, { dir, size = 32 } = {}) {
153
- if (size === null)
154
- return hex_;
155
- const hex = hex_.replace('0x', '');
156
- if (hex.length > size * 2)
157
- throw new SizeExceedsPaddingSizeError({
158
- size: Math.ceil(hex.length / 2),
159
- targetSize: size,
160
- type: 'hex',
161
- });
162
- return `0x${hex[dir === 'right' ? 'padEnd' : 'padStart'](size * 2, '0')}`;
163
- }
164
- function padBytes(bytes, { dir, size = 32 } = {}) {
165
- if (size === null)
166
- return bytes;
167
- if (bytes.length > size)
168
- throw new SizeExceedsPaddingSizeError({
169
- size: bytes.length,
170
- targetSize: size,
171
- type: 'bytes',
172
- });
173
- const paddedBytes = new Uint8Array(size);
174
- for (let i = 0; i < size; i++) {
175
- const padEnd = dir === 'right';
176
- paddedBytes[padEnd ? i : size - i - 1] =
177
- bytes[padEnd ? i : bytes.length - i - 1];
178
- }
179
- return paddedBytes;
180
- }
181
-
182
- class IntegerOutOfRangeError extends BaseError {
183
- constructor({ max, min, signed, size, value, }) {
184
- super(`Number "${value}" is not in safe ${size ? `${size * 8}-bit ${signed ? 'signed' : 'unsigned'} ` : ''}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`, { name: 'IntegerOutOfRangeError' });
185
- }
186
- }
187
- class SizeOverflowError extends BaseError {
188
- constructor({ givenSize, maxSize }) {
189
- super(`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`, { name: 'SizeOverflowError' });
190
- }
191
- }
192
-
193
- function assertSize(hexOrBytes, { size: size$1 }) {
194
- if (size(hexOrBytes) > size$1)
195
- throw new SizeOverflowError({
196
- givenSize: size(hexOrBytes),
197
- maxSize: size$1,
198
- });
199
- }
200
-
201
- /**
202
- * Encodes a number or bigint into a hex string
203
- *
204
- * - Docs: https://viem.sh/docs/utilities/toHex#numbertohex
205
- *
206
- * @param value Value to encode.
207
- * @param opts Options.
208
- * @returns Hex value.
209
- *
210
- * @example
211
- * import { numberToHex } from 'viem'
212
- * const data = numberToHex(420)
213
- * // '0x1a4'
214
- *
215
- * @example
216
- * import { numberToHex } from 'viem'
217
- * const data = numberToHex(420, { size: 32 })
218
- * // '0x00000000000000000000000000000000000000000000000000000000000001a4'
219
- */
220
- function numberToHex(value_, opts = {}) {
221
- const { signed, size } = opts;
222
- const value = BigInt(value_);
223
- let maxValue;
224
- if (size) {
225
- if (signed)
226
- maxValue = (1n << (BigInt(size) * 8n - 1n)) - 1n;
227
- else
228
- maxValue = 2n ** (BigInt(size) * 8n) - 1n;
229
- }
230
- else if (typeof value_ === 'number') {
231
- maxValue = BigInt(Number.MAX_SAFE_INTEGER);
232
- }
233
- const minValue = typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0;
234
- if ((maxValue && value > maxValue) || value < minValue) {
235
- const suffix = typeof value_ === 'bigint' ? 'n' : '';
236
- throw new IntegerOutOfRangeError({
237
- max: maxValue ? `${maxValue}${suffix}` : undefined,
238
- min: `${minValue}${suffix}`,
239
- signed,
240
- size,
241
- value: `${value_}${suffix}`,
242
- });
243
- }
244
- const hex = `0x${(signed && value < 0 ? (1n << BigInt(size * 8)) + BigInt(value) : value).toString(16)}`;
245
- if (size)
246
- return pad(hex, { size });
247
- return hex;
248
- }
249
-
250
- const encoder = /*#__PURE__*/ new TextEncoder();
251
- /**
252
- * Encodes a UTF-8 string, hex value, bigint, number or boolean to a byte array.
253
- *
254
- * - Docs: https://viem.sh/docs/utilities/toBytes
255
- * - Example: https://viem.sh/docs/utilities/toBytes#usage
256
- *
257
- * @param value Value to encode.
258
- * @param opts Options.
259
- * @returns Byte array value.
260
- *
261
- * @example
262
- * import { toBytes } from 'viem'
263
- * const data = toBytes('Hello world')
264
- * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
265
- *
266
- * @example
267
- * import { toBytes } from 'viem'
268
- * const data = toBytes(420)
269
- * // Uint8Array([1, 164])
270
- *
271
- * @example
272
- * import { toBytes } from 'viem'
273
- * const data = toBytes(420, { size: 4 })
274
- * // Uint8Array([0, 0, 1, 164])
275
- */
276
- function toBytes$1(value, opts = {}) {
277
- if (typeof value === 'number' || typeof value === 'bigint')
278
- return numberToBytes(value, opts);
279
- if (typeof value === 'boolean')
280
- return boolToBytes(value, opts);
281
- if (isHex(value))
282
- return hexToBytes(value, opts);
283
- return stringToBytes(value, opts);
284
- }
285
- /**
286
- * Encodes a boolean into a byte array.
287
- *
288
- * - Docs: https://viem.sh/docs/utilities/toBytes#booltobytes
289
- *
290
- * @param value Boolean value to encode.
291
- * @param opts Options.
292
- * @returns Byte array value.
293
- *
294
- * @example
295
- * import { boolToBytes } from 'viem'
296
- * const data = boolToBytes(true)
297
- * // Uint8Array([1])
298
- *
299
- * @example
300
- * import { boolToBytes } from 'viem'
301
- * const data = boolToBytes(true, { size: 32 })
302
- * // Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
303
- */
304
- function boolToBytes(value, opts = {}) {
305
- const bytes = new Uint8Array(1);
306
- bytes[0] = Number(value);
307
- if (typeof opts.size === 'number') {
308
- assertSize(bytes, { size: opts.size });
309
- return pad(bytes, { size: opts.size });
310
- }
311
- return bytes;
312
- }
313
- // We use very optimized technique to convert hex string to byte array
314
- const charCodeMap = {
315
- zero: 48,
316
- nine: 57,
317
- A: 65,
318
- F: 70,
319
- a: 97,
320
- f: 102,
321
- };
322
- function charCodeToBase16(char) {
323
- if (char >= charCodeMap.zero && char <= charCodeMap.nine)
324
- return char - charCodeMap.zero;
325
- if (char >= charCodeMap.A && char <= charCodeMap.F)
326
- return char - (charCodeMap.A - 10);
327
- if (char >= charCodeMap.a && char <= charCodeMap.f)
328
- return char - (charCodeMap.a - 10);
329
- return undefined;
330
- }
331
- /**
332
- * Encodes a hex string into a byte array.
333
- *
334
- * - Docs: https://viem.sh/docs/utilities/toBytes#hextobytes
335
- *
336
- * @param hex Hex string to encode.
337
- * @param opts Options.
338
- * @returns Byte array value.
339
- *
340
- * @example
341
- * import { hexToBytes } from 'viem'
342
- * const data = hexToBytes('0x48656c6c6f20776f726c6421')
343
- * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
344
- *
345
- * @example
346
- * import { hexToBytes } from 'viem'
347
- * const data = hexToBytes('0x48656c6c6f20776f726c6421', { size: 32 })
348
- * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
349
- */
350
- function hexToBytes(hex_, opts = {}) {
351
- let hex = hex_;
352
- if (opts.size) {
353
- assertSize(hex, { size: opts.size });
354
- hex = pad(hex, { dir: 'right', size: opts.size });
355
- }
356
- let hexString = hex.slice(2);
357
- if (hexString.length % 2)
358
- hexString = `0${hexString}`;
359
- const length = hexString.length / 2;
360
- const bytes = new Uint8Array(length);
361
- for (let index = 0, j = 0; index < length; index++) {
362
- const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++));
363
- const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++));
364
- if (nibbleLeft === undefined || nibbleRight === undefined) {
365
- throw new BaseError(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
366
- }
367
- bytes[index] = nibbleLeft * 16 + nibbleRight;
368
- }
369
- return bytes;
370
- }
371
- /**
372
- * Encodes a number into a byte array.
373
- *
374
- * - Docs: https://viem.sh/docs/utilities/toBytes#numbertobytes
375
- *
376
- * @param value Number to encode.
377
- * @param opts Options.
378
- * @returns Byte array value.
379
- *
380
- * @example
381
- * import { numberToBytes } from 'viem'
382
- * const data = numberToBytes(420)
383
- * // Uint8Array([1, 164])
384
- *
385
- * @example
386
- * import { numberToBytes } from 'viem'
387
- * const data = numberToBytes(420, { size: 4 })
388
- * // Uint8Array([0, 0, 1, 164])
389
- */
390
- function numberToBytes(value, opts) {
391
- const hex = numberToHex(value, opts);
392
- return hexToBytes(hex);
393
- }
394
- /**
395
- * Encodes a UTF-8 string into a byte array.
396
- *
397
- * - Docs: https://viem.sh/docs/utilities/toBytes#stringtobytes
398
- *
399
- * @param value String to encode.
400
- * @param opts Options.
401
- * @returns Byte array value.
402
- *
403
- * @example
404
- * import { stringToBytes } from 'viem'
405
- * const data = stringToBytes('Hello world!')
406
- * // Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
407
- *
408
- * @example
409
- * import { stringToBytes } from 'viem'
410
- * const data = stringToBytes('Hello world!', { size: 32 })
411
- * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
412
- */
413
- function stringToBytes(value, opts = {}) {
414
- const bytes = encoder.encode(value);
415
- if (typeof opts.size === 'number') {
416
- assertSize(bytes, { size: opts.size });
417
- return pad(bytes, { dir: 'right', size: opts.size });
418
- }
419
- return bytes;
420
- }
421
-
422
- /**
423
- * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
424
- * @todo re-check https://issues.chromium.org/issues/42212588
425
- * @module
426
- */
427
- const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
428
- const _32n = /* @__PURE__ */ BigInt(32);
429
- function fromBig(n, le = false) {
430
- if (le)
431
- return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
432
- return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
433
- }
434
- function split(lst, le = false) {
435
- const len = lst.length;
436
- let Ah = new Uint32Array(len);
437
- let Al = new Uint32Array(len);
438
- for (let i = 0; i < len; i++) {
439
- const { h, l } = fromBig(lst[i], le);
440
- [Ah[i], Al[i]] = [h, l];
441
- }
442
- return [Ah, Al];
443
- }
444
- // Left rotate for Shift in [1, 32)
445
- const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
446
- const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
447
- // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
448
- const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
449
- const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
450
-
451
- /**
452
- * Utilities for hex, bytes, CSPRNG.
453
- * @module
454
- */
455
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
456
- // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
457
- // node.js versions earlier than v19 don't declare it in global scope.
458
- // For node.js, package.json#exports field mapping rewrites import
459
- // from `crypto` to `cryptoNode`, which imports native module.
460
- // Makes the utils un-importable in browsers without a bundler.
461
- // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
462
- /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
463
- function isBytes(a) {
464
- return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
465
- }
466
- /** Asserts something is positive integer. */
467
- function anumber(n) {
468
- if (!Number.isSafeInteger(n) || n < 0)
469
- throw new Error('positive integer expected, got ' + n);
470
- }
471
- /** Asserts something is Uint8Array. */
472
- function abytes(b, ...lengths) {
473
- if (!isBytes(b))
474
- throw new Error('Uint8Array expected');
475
- if (lengths.length > 0 && !lengths.includes(b.length))
476
- throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
477
- }
478
- /** Asserts a hash instance has not been destroyed / finished */
479
- function aexists(instance, checkFinished = true) {
480
- if (instance.destroyed)
481
- throw new Error('Hash instance has been destroyed');
482
- if (checkFinished && instance.finished)
483
- throw new Error('Hash#digest() has already been called');
484
- }
485
- /** Asserts output is properly-sized byte array */
486
- function aoutput(out, instance) {
487
- abytes(out);
488
- const min = instance.outputLen;
489
- if (out.length < min) {
490
- throw new Error('digestInto() expects output buffer of length at least ' + min);
491
- }
492
- }
493
- /** Cast u8 / u16 / u32 to u32. */
494
- function u32(arr) {
495
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
496
- }
497
- /** Zeroize a byte array. Warning: JS provides no guarantees. */
498
- function clean(...arrays) {
499
- for (let i = 0; i < arrays.length; i++) {
500
- arrays[i].fill(0);
501
- }
502
- }
503
- /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
504
- const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
505
- /** The byte swap operation for uint32 */
506
- function byteSwap(word) {
507
- return (((word << 24) & 0xff000000) |
508
- ((word << 8) & 0xff0000) |
509
- ((word >>> 8) & 0xff00) |
510
- ((word >>> 24) & 0xff));
511
- }
512
- /** In place byte swap for Uint32Array */
513
- function byteSwap32(arr) {
514
- for (let i = 0; i < arr.length; i++) {
515
- arr[i] = byteSwap(arr[i]);
516
- }
517
- return arr;
518
- }
519
- const swap32IfBE = isLE
520
- ? (u) => u
521
- : byteSwap32;
522
- /**
523
- * Converts string to bytes using UTF8 encoding.
524
- * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
525
- */
526
- function utf8ToBytes(str) {
527
- if (typeof str !== 'string')
528
- throw new Error('string expected');
529
- return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
530
- }
531
- /**
532
- * Normalizes (non-hex) string or Uint8Array to Uint8Array.
533
- * Warning: when Uint8Array is passed, it would NOT get copied.
534
- * Keep in mind for future mutable operations.
535
- */
536
- function toBytes(data) {
537
- if (typeof data === 'string')
538
- data = utf8ToBytes(data);
539
- abytes(data);
540
- return data;
541
- }
542
- /** For runtime check if class implements interface */
543
- class Hash {
544
- }
545
- /** Wraps hash function, creating an interface on top of it */
546
- function createHasher(hashCons) {
547
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
548
- const tmp = hashCons();
549
- hashC.outputLen = tmp.outputLen;
550
- hashC.blockLen = tmp.blockLen;
551
- hashC.create = () => hashCons();
552
- return hashC;
553
- }
554
-
555
- /**
556
- * SHA3 (keccak) hash function, based on a new "Sponge function" design.
557
- * Different from older hashes, the internal state is bigger than output size.
558
- *
559
- * Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
560
- * [Website](https://keccak.team/keccak.html),
561
- * [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
562
- *
563
- * Check out `sha3-addons` module for cSHAKE, k12, and others.
564
- * @module
565
- */
566
- // No __PURE__ annotations in sha3 header:
567
- // EVERYTHING is in fact used on every export.
568
- // Various per round constants calculations
569
- const _0n = BigInt(0);
570
- const _1n = BigInt(1);
571
- const _2n = BigInt(2);
572
- const _7n = BigInt(7);
573
- const _256n = BigInt(256);
574
- const _0x71n = BigInt(0x71);
575
- const SHA3_PI = [];
576
- const SHA3_ROTL = [];
577
- const _SHA3_IOTA = [];
578
- for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
579
- // Pi
580
- [x, y] = [y, (2 * x + 3 * y) % 5];
581
- SHA3_PI.push(2 * (5 * y + x));
582
- // Rotational
583
- SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
584
- // Iota
585
- let t = _0n;
586
- for (let j = 0; j < 7; j++) {
587
- R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
588
- if (R & _2n)
589
- t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
590
- }
591
- _SHA3_IOTA.push(t);
592
- }
593
- const IOTAS = split(_SHA3_IOTA, true);
594
- const SHA3_IOTA_H = IOTAS[0];
595
- const SHA3_IOTA_L = IOTAS[1];
596
- // Left rotation (without 0, 32, 64)
597
- const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
598
- const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
599
- /** `keccakf1600` internal function, additionally allows to adjust round count. */
600
- function keccakP(s, rounds = 24) {
601
- const B = new Uint32Array(5 * 2);
602
- // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
603
- for (let round = 24 - rounds; round < 24; round++) {
604
- // Theta θ
605
- for (let x = 0; x < 10; x++)
606
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
607
- for (let x = 0; x < 10; x += 2) {
608
- const idx1 = (x + 8) % 10;
609
- const idx0 = (x + 2) % 10;
610
- const B0 = B[idx0];
611
- const B1 = B[idx0 + 1];
612
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
613
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
614
- for (let y = 0; y < 50; y += 10) {
615
- s[x + y] ^= Th;
616
- s[x + y + 1] ^= Tl;
617
- }
618
- }
619
- // Rho (ρ) and Pi (π)
620
- let curH = s[2];
621
- let curL = s[3];
622
- for (let t = 0; t < 24; t++) {
623
- const shift = SHA3_ROTL[t];
624
- const Th = rotlH(curH, curL, shift);
625
- const Tl = rotlL(curH, curL, shift);
626
- const PI = SHA3_PI[t];
627
- curH = s[PI];
628
- curL = s[PI + 1];
629
- s[PI] = Th;
630
- s[PI + 1] = Tl;
631
- }
632
- // Chi (χ)
633
- for (let y = 0; y < 50; y += 10) {
634
- for (let x = 0; x < 10; x++)
635
- B[x] = s[y + x];
636
- for (let x = 0; x < 10; x++)
637
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
638
- }
639
- // Iota (ι)
640
- s[0] ^= SHA3_IOTA_H[round];
641
- s[1] ^= SHA3_IOTA_L[round];
642
- }
643
- clean(B);
644
- }
645
- /** Keccak sponge function. */
646
- class Keccak extends Hash {
647
- // NOTE: we accept arguments in bytes instead of bits here.
648
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
649
- super();
650
- this.pos = 0;
651
- this.posOut = 0;
652
- this.finished = false;
653
- this.destroyed = false;
654
- this.enableXOF = false;
655
- this.blockLen = blockLen;
656
- this.suffix = suffix;
657
- this.outputLen = outputLen;
658
- this.enableXOF = enableXOF;
659
- this.rounds = rounds;
660
- // Can be passed from user as dkLen
661
- anumber(outputLen);
662
- // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
663
- // 0 < blockLen < 200
664
- if (!(0 < blockLen && blockLen < 200))
665
- throw new Error('only keccak-f1600 function is supported');
666
- this.state = new Uint8Array(200);
667
- this.state32 = u32(this.state);
668
- }
669
- clone() {
670
- return this._cloneInto();
671
- }
672
- keccak() {
673
- swap32IfBE(this.state32);
674
- keccakP(this.state32, this.rounds);
675
- swap32IfBE(this.state32);
676
- this.posOut = 0;
677
- this.pos = 0;
678
- }
679
- update(data) {
680
- aexists(this);
681
- data = toBytes(data);
682
- abytes(data);
683
- const { blockLen, state } = this;
684
- const len = data.length;
685
- for (let pos = 0; pos < len;) {
686
- const take = Math.min(blockLen - this.pos, len - pos);
687
- for (let i = 0; i < take; i++)
688
- state[this.pos++] ^= data[pos++];
689
- if (this.pos === blockLen)
690
- this.keccak();
691
- }
692
- return this;
693
- }
694
- finish() {
695
- if (this.finished)
696
- return;
697
- this.finished = true;
698
- const { state, suffix, pos, blockLen } = this;
699
- // Do the padding
700
- state[pos] ^= suffix;
701
- if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
702
- this.keccak();
703
- state[blockLen - 1] ^= 0x80;
704
- this.keccak();
705
- }
706
- writeInto(out) {
707
- aexists(this, false);
708
- abytes(out);
709
- this.finish();
710
- const bufferOut = this.state;
711
- const { blockLen } = this;
712
- for (let pos = 0, len = out.length; pos < len;) {
713
- if (this.posOut >= blockLen)
714
- this.keccak();
715
- const take = Math.min(blockLen - this.posOut, len - pos);
716
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
717
- this.posOut += take;
718
- pos += take;
719
- }
720
- return out;
721
- }
722
- xofInto(out) {
723
- // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
724
- if (!this.enableXOF)
725
- throw new Error('XOF is not possible for this instance');
726
- return this.writeInto(out);
727
- }
728
- xof(bytes) {
729
- anumber(bytes);
730
- return this.xofInto(new Uint8Array(bytes));
731
- }
732
- digestInto(out) {
733
- aoutput(out, this);
734
- if (this.finished)
735
- throw new Error('digest() was already called');
736
- this.writeInto(out);
737
- this.destroy();
738
- return out;
739
- }
740
- digest() {
741
- return this.digestInto(new Uint8Array(this.outputLen));
742
- }
743
- destroy() {
744
- this.destroyed = true;
745
- clean(this.state);
746
- }
747
- _cloneInto(to) {
748
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
749
- to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
750
- to.state32.set(this.state32);
751
- to.pos = this.pos;
752
- to.posOut = this.posOut;
753
- to.finished = this.finished;
754
- to.rounds = rounds;
755
- // Suffix can change in cSHAKE
756
- to.suffix = suffix;
757
- to.outputLen = outputLen;
758
- to.enableXOF = enableXOF;
759
- to.destroyed = this.destroyed;
760
- return to;
761
- }
762
- }
763
- const gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
764
- /** keccak-256 hash function. Different from SHA3-256. */
765
- const keccak_256 = /* @__PURE__ */ (() => gen(0x01, 136, 256 / 8))();
766
-
767
- function keccak256(value, to_) {
768
- const bytes = keccak_256(isHex(value, { strict: false }) ? toBytes$1(value) : value);
769
- return bytes;
770
- }
771
-
772
- /**
773
- * Map with a LRU (Least recently used) policy.
774
- *
775
- * @link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
776
- */
777
- class LruMap extends Map {
778
- constructor(size) {
779
- super();
780
- Object.defineProperty(this, "maxSize", {
781
- enumerable: true,
782
- configurable: true,
783
- writable: true,
784
- value: void 0
785
- });
786
- this.maxSize = size;
787
- }
788
- get(key) {
789
- const value = super.get(key);
790
- if (super.has(key) && value !== undefined) {
791
- this.delete(key);
792
- super.set(key, value);
793
- }
794
- return value;
795
- }
796
- set(key, value) {
797
- super.set(key, value);
798
- if (this.maxSize && this.size > this.maxSize) {
799
- const firstKey = this.keys().next().value;
800
- if (firstKey)
801
- this.delete(firstKey);
802
- }
803
- return this;
804
- }
805
- }
806
-
807
- const checksumAddressCache = /*#__PURE__*/ new LruMap(8192);
808
- function checksumAddress(address_,
809
- /**
810
- * Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
811
- * wider Ethereum ecosystem, meaning it will break when validated against an application/tool
812
- * that relies on EIP-55 checksum encoding (checksum without chainId).
813
- *
814
- * It is highly recommended to not use this feature unless you
815
- * know what you are doing.
816
- *
817
- * See more: https://github.com/ethereum/EIPs/issues/1121
818
- */
819
- chainId) {
820
- if (checksumAddressCache.has(`${address_}.${chainId}`))
821
- return checksumAddressCache.get(`${address_}.${chainId}`);
822
- const hexAddress = address_.substring(2).toLowerCase();
823
- const hash = keccak256(stringToBytes(hexAddress));
824
- const address = (hexAddress).split('');
825
- for (let i = 0; i < 40; i += 2) {
826
- if (hash[i >> 1] >> 4 >= 8 && address[i]) {
827
- address[i] = address[i].toUpperCase();
828
- }
829
- if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) {
830
- address[i + 1] = address[i + 1].toUpperCase();
831
- }
832
- }
833
- const result = `0x${address.join('')}`;
834
- checksumAddressCache.set(`${address_}.${chainId}`, result);
835
- return result;
836
- }
837
-
838
- const addressRegex = /^0x[a-fA-F0-9]{40}$/;
839
- /** @internal */
840
- const isAddressCache = /*#__PURE__*/ new LruMap(8192);
841
- function isAddress(address, options) {
842
- const { strict = true } = {};
843
- const cacheKey = `${address}.${strict}`;
844
- if (isAddressCache.has(cacheKey))
845
- return isAddressCache.get(cacheKey);
846
- const result = (() => {
847
- if (!addressRegex.test(address))
848
- return false;
849
- if (address.toLowerCase() === address)
850
- return true;
851
- if (strict)
852
- return checksumAddress(address) === address;
853
- return true;
854
- })();
855
- isAddressCache.set(cacheKey, result);
856
- return result;
857
- }
858
-
859
30
  const backgroundGradient = (address) => {
860
31
  let gradientStart = "#24354210";
861
32
  let gradientEnd = "#24354220";
862
33
  const opacity = "80";
863
- if (address && isAddress(address)) {
34
+ if (address && isAddress.isAddress(address)) {
864
35
  gradientStart = `#${address.slice(2, 8)}${opacity}`;
865
36
  gradientEnd = `#${address.slice(36, 42)}${opacity}`;
866
37
  }