@lukso/web-components 1.172.13 → 1.172.14

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