@gardenfi/utils 2.4.5 → 2.4.6

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 (151) hide show
  1. package/dist/index119.cjs +1 -1
  2. package/dist/index119.js +1 -1
  3. package/dist/index195.cjs +1 -1
  4. package/dist/index195.js +3 -3
  5. package/dist/index225.cjs +1 -1
  6. package/dist/index225.js +2 -2
  7. package/dist/index228.cjs +1 -1
  8. package/dist/index228.js +2 -2
  9. package/dist/index229.cjs +1 -1
  10. package/dist/index229.js +1 -1
  11. package/dist/index23.cjs +1 -1
  12. package/dist/index23.js +6 -6
  13. package/dist/index234.cjs +1 -1
  14. package/dist/index234.js +1 -1
  15. package/dist/index235.cjs +1 -1
  16. package/dist/index235.js +1 -1
  17. package/dist/index236.cjs +1 -1
  18. package/dist/index236.js +2 -2
  19. package/dist/index241.cjs +1 -1
  20. package/dist/index241.js +3 -3
  21. package/dist/index243.cjs +1 -1
  22. package/dist/index243.js +1 -1
  23. package/dist/index248.cjs +1 -1
  24. package/dist/index248.js +3 -3
  25. package/dist/index249.cjs +1 -1
  26. package/dist/index249.js +3 -3
  27. package/dist/index254.cjs +1 -1
  28. package/dist/index254.js +102 -24
  29. package/dist/index255.cjs +1 -1
  30. package/dist/index255.js +6 -13
  31. package/dist/index256.cjs +1 -1
  32. package/dist/index256.js +223 -14
  33. package/dist/index257.cjs +1 -1
  34. package/dist/index257.js +25 -5
  35. package/dist/index258.cjs +1 -1
  36. package/dist/index258.js +13 -13
  37. package/dist/index259.cjs +1 -1
  38. package/dist/index259.js +14 -9
  39. package/dist/index26.cjs +1 -1
  40. package/dist/index26.js +2 -2
  41. package/dist/index260.cjs +1 -1
  42. package/dist/index260.js +5 -16
  43. package/dist/index261.cjs +1 -2
  44. package/dist/index261.js +13 -41
  45. package/dist/index262.cjs +1 -1
  46. package/dist/index262.js +11 -2
  47. package/dist/index263.cjs +1 -1
  48. package/dist/index263.js +16 -5
  49. package/dist/index264.cjs +2 -1
  50. package/dist/index264.js +40 -9
  51. package/dist/index265.cjs +1 -1
  52. package/dist/index265.js +2 -20
  53. package/dist/index266.cjs +1 -1
  54. package/dist/index266.js +5 -8
  55. package/dist/index267.cjs +1 -1
  56. package/dist/index267.js +9 -65
  57. package/dist/index268.cjs +1 -1
  58. package/dist/index268.js +17 -63
  59. package/dist/index269.cjs +1 -1
  60. package/dist/index269.js +8 -186
  61. package/dist/index270.cjs +1 -1
  62. package/dist/index270.js +66 -22
  63. package/dist/index271.cjs +1 -1
  64. package/dist/index271.js +61 -38
  65. package/dist/index272.cjs +1 -1
  66. package/dist/index272.js +179 -69
  67. package/dist/index273.cjs +1 -1
  68. package/dist/index273.js +21 -39
  69. package/dist/index274.cjs +1 -1
  70. package/dist/index274.js +35 -9
  71. package/dist/index275.cjs +1 -1
  72. package/dist/index275.js +70 -7
  73. package/dist/index276.cjs +1 -1
  74. package/dist/index276.js +40 -12
  75. package/dist/index277.cjs +1 -2
  76. package/dist/index277.js +16 -18
  77. package/dist/index278.cjs +1 -1
  78. package/dist/index278.js +12 -13
  79. package/dist/index279.cjs +1 -1
  80. package/dist/index279.js +12 -11
  81. package/dist/index280.cjs +2 -1
  82. package/dist/index280.js +18 -103
  83. package/dist/index281.cjs +1 -1
  84. package/dist/index281.js +14 -6
  85. package/dist/index282.cjs +1 -1
  86. package/dist/index282.js +152 -221
  87. package/dist/index283.cjs +1 -1
  88. package/dist/index283.js +9 -6
  89. package/dist/index284.cjs +1 -1
  90. package/dist/index284.js +114 -7
  91. package/dist/index285.cjs +2 -1
  92. package/dist/index285.js +132 -24
  93. package/dist/index286.cjs +1 -1
  94. package/dist/index286.js +11 -19
  95. package/dist/index287.cjs +1 -1
  96. package/dist/index287.js +6 -146
  97. package/dist/index288.cjs +1 -1
  98. package/dist/index288.js +7 -4
  99. package/dist/index289.cjs +1 -1
  100. package/dist/index289.js +23 -137
  101. package/dist/index290.cjs +1 -1
  102. package/dist/index290.js +17 -153
  103. package/dist/index291.cjs +1 -1
  104. package/dist/index291.js +146 -9
  105. package/dist/index292.cjs +1 -1
  106. package/dist/index292.js +3 -113
  107. package/dist/index293.cjs +1 -2
  108. package/dist/index293.js +128 -122
  109. package/dist/index294.cjs +1 -1
  110. package/dist/index294.js +73 -134
  111. package/dist/index295.cjs +1 -1
  112. package/dist/index295.js +2 -43
  113. package/dist/index296.cjs +1 -1
  114. package/dist/index296.js +693 -73
  115. package/dist/index297.cjs +1 -1
  116. package/dist/index297.js +140 -2
  117. package/dist/index298.cjs +1 -1
  118. package/dist/index298.js +41 -10
  119. package/dist/index299.cjs +1 -1
  120. package/dist/index299.js +201 -19
  121. package/dist/index301.cjs +2 -1
  122. package/dist/index301.js +63 -695
  123. package/dist/index302.cjs +1 -1
  124. package/dist/index302.js +4 -201
  125. package/dist/index303.cjs +1 -2
  126. package/dist/index303.js +39 -65
  127. package/dist/index304.cjs +1 -1
  128. package/dist/index304.js +7 -4
  129. package/dist/index305.cjs +1 -1
  130. package/dist/index305.js +60 -38
  131. package/dist/index306.cjs +1 -1
  132. package/dist/index306.js +77 -7
  133. package/dist/index307.cjs +1 -1
  134. package/dist/index307.js +4 -63
  135. package/dist/index308.cjs +1 -1
  136. package/dist/index308.js +181 -64
  137. package/dist/index309.cjs +1 -1
  138. package/dist/index309.js +12 -4
  139. package/dist/index310.cjs +1 -1
  140. package/dist/index310.js +19 -194
  141. package/dist/index311.cjs +1 -1
  142. package/dist/index311.js +63 -4
  143. package/dist/index312.cjs +1 -1
  144. package/dist/index312.js +40 -59
  145. package/dist/index313.cjs +1 -1
  146. package/dist/index313.js +4 -44
  147. package/dist/index53.cjs +1 -1
  148. package/dist/index53.js +1 -1
  149. package/dist/index98.cjs +1 -1
  150. package/dist/index98.js +2 -2
  151. package/package.json +1 -1
package/dist/index308.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./index312.cjs"),c=require("./index314.cjs"),o=require("./index303.cjs"),m=require("./index306.cjs"),b=/^0x[a-fA-F0-9]{40}$/;function i(e,t={}){const{strict:s=!0}=t;if(!b.test(e))throw new a({address:e,cause:new l});if(s){if(e.toLowerCase()===e)return;if(d(e)!==e)throw new a({address:e,cause:new h})}}function d(e){if(c.checksum.has(e))return c.checksum.get(e);i(e,{strict:!1});const t=e.substring(2).toLowerCase(),s=m.keccak256(f.fromString(t),{as:"Bytes"}),n=t.split("");for(let r=0;r<40;r+=2)s[r>>1]>>4>=8&&n[r]&&(n[r]=n[r].toUpperCase()),(s[r>>1]&15)>=8&&n[r+1]&&(n[r+1]=n[r+1].toUpperCase());const u=`0x${n.join("")}`;return c.checksum.set(e,u),u}function p(e,t={}){const{strict:s=!0}=t??{};try{return i(e,{strict:s}),!0}catch{return!1}}class a extends o.BaseError{constructor({address:t,cause:s}){super(`Address "${t}" is invalid.`,{cause:s}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class l extends o.BaseError{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class h extends o.BaseError{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}exports.InvalidAddressError=a;exports.InvalidChecksumError=h;exports.InvalidInputError=l;exports.assert=i;exports.checksum=d;exports.validate=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./index285.cjs"),w=require("./index306.cjs"),N=require("./index301.cjs"),c=require("./index282.cjs"),x=require("./index307.cjs");function P({checksumAddress:e,parameters:r,values:n}){const t=[];for(let o=0;o<r.length;o++)t.push(f({checksumAddress:e,parameter:r[o],value:n[o]}));return t}function f({checksumAddress:e=!1,parameter:r,value:n}){const t=r,o=S(t.type);if(o){const[i,s]=o;return h(n,{checksumAddress:e,length:i,parameter:{...t,type:s}})}if(t.type==="tuple")return A(n,{checksumAddress:e,parameter:t});if(t.type==="address")return y(n,{checksum:e});if(t.type==="bool")return g(n);if(t.type.startsWith("uint")||t.type.startsWith("int")){const i=t.type.startsWith("int"),[,,s="256"]=x.integerRegex.exec(t.type)??[];return b(n,{signed:i,size:Number(s)})}if(t.type.startsWith("bytes"))return l(n,{type:t.type});if(t.type==="string")return z(n);throw new m.InvalidTypeError(t.type)}function u(e){let r=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?r+=32:r+=c.size(a)}const n=[],t=[];let o=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?(n.push(c.fromNumber(r+o,{size:32})),t.push(a),o+=c.size(a)):n.push(a)}return c.concat(...n,...t)}function y(e,r){const{checksum:n=!1}=r;return w.assert(e,{strict:n}),{dynamic:!1,encoded:c.padLeft(e.toLowerCase())}}function h(e,r){const{checksumAddress:n,length:t,parameter:o}=r,i=t===null;if(!Array.isArray(e))throw new m.InvalidArrayError(e);if(!i&&e.length!==t)throw new m.ArrayLengthMismatchError({expectedLength:t,givenLength:e.length,type:`${o.type}[${t}]`});let s=!1;const a=[];for(let d=0;d<e.length;d++){const p=f({checksumAddress:n,parameter:o,value:e[d]});p.dynamic&&(s=!0),a.push(p)}if(i||s){const d=u(a);if(i){const p=c.fromNumber(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?c.concat(p,d):p}}if(s)return{dynamic:!0,encoded:d}}return{dynamic:!1,encoded:c.concat(...a.map(({encoded:d})=>d))}}function l(e,{type:r}){const[,n]=r.split("bytes"),t=c.size(e);if(!n){let o=e;return t%32!==0&&(o=c.padRight(o,Math.ceil((e.length-2)/2/32)*32)),{dynamic:!0,encoded:c.concat(c.padLeft(c.fromNumber(t,{size:32})),o)}}if(t!==Number.parseInt(n))throw new m.BytesSizeMismatchError({expectedSize:Number.parseInt(n),value:e});return{dynamic:!1,encoded:c.padRight(e)}}function g(e){if(typeof e!="boolean")throw new N.BaseError(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:c.padLeft(c.fromBoolean(e))}}function b(e,{signed:r,size:n}){if(typeof n=="number"){const t=2n**(BigInt(n)-(r?1n:0n))-1n,o=r?-t-1n:0n;if(e>t||e<o)throw new c.IntegerOutOfRangeError({max:t.toString(),min:o.toString(),signed:r,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:c.fromNumber(e,{size:32,signed:r})}}function z(e){const r=c.fromString(e),n=Math.ceil(c.size(r)/32),t=[];for(let o=0;o<n;o++)t.push(c.padRight(c.slice(r,o*32,(o+1)*32)));return{dynamic:!0,encoded:c.concat(c.padRight(c.fromNumber(c.size(r),{size:32})),...t)}}function A(e,r){const{checksumAddress:n,parameter:t}=r;let o=!1;const i=[];for(let s=0;s<t.components.length;s++){const a=t.components[s],d=Array.isArray(e)?s:a.name,p=f({checksumAddress:n,parameter:a,value:e[d]});i.push(p),p.dynamic&&(o=!0)}return{dynamic:o,encoded:o?u(i):c.concat(...i.map(({encoded:s})=>s))}}function S(e){const r=e.match(/^(.*)\[(\d+)?\]$/);return r?[r[2]?Number(r[2]):null,r[1]]:void 0}exports.encode=u;exports.encodeAddress=y;exports.encodeArray=h;exports.encodeBoolean=g;exports.encodeBytes=l;exports.encodeNumber=b;exports.encodeString=z;exports.encodeTuple=A;exports.getArrayComponents=S;exports.prepareParameter=f;exports.prepareParameters=P;
package/dist/index308.js CHANGED
@@ -1,80 +1,197 @@
1
- import { fromString as d } from "./index312.js";
2
- import { checksum as o } from "./index314.js";
3
- import { BaseError as c } from "./index303.js";
4
- import { keccak256 as f } from "./index306.js";
5
- const l = /^0x[a-fA-F0-9]{40}$/;
6
- function u(r, t = {}) {
7
- const { strict: s = !0 } = t;
8
- if (!l.test(r))
9
- throw new i({
10
- address: r,
11
- cause: new h()
1
+ import { InvalidTypeError as g, InvalidArrayError as b, ArrayLengthMismatchError as w, BytesSizeMismatchError as z } from "./index285.js";
2
+ import { assert as x } from "./index306.js";
3
+ import { BaseError as S } from "./index301.js";
4
+ import { size as d, fromNumber as f, concat as p, padLeft as h, fromBoolean as A, IntegerOutOfRangeError as E, padRight as y, fromString as I, slice as B } from "./index282.js";
5
+ import { integerRegex as L } from "./index307.js";
6
+ function q({ checksumAddress: e, parameters: n, values: r }) {
7
+ const t = [];
8
+ for (let o = 0; o < n.length; o++)
9
+ t.push(u({
10
+ checksumAddress: e,
11
+ parameter: n[o],
12
+ value: r[o]
13
+ }));
14
+ return t;
15
+ }
16
+ function u({ checksumAddress: e = !1, parameter: n, value: r }) {
17
+ const t = n, o = k(t.type);
18
+ if (o) {
19
+ const [i, c] = o;
20
+ return P(r, {
21
+ checksumAddress: e,
22
+ length: i,
23
+ parameter: {
24
+ ...t,
25
+ type: c
26
+ }
12
27
  });
13
- if (s) {
14
- if (r.toLowerCase() === r)
15
- return;
16
- if (m(r) !== r)
17
- throw new i({
18
- address: r,
19
- cause: new p()
20
- });
21
28
  }
29
+ if (t.type === "tuple")
30
+ return R(r, {
31
+ checksumAddress: e,
32
+ parameter: t
33
+ });
34
+ if (t.type === "address")
35
+ return N(r, {
36
+ checksum: e
37
+ });
38
+ if (t.type === "bool")
39
+ return C(r);
40
+ if (t.type.startsWith("uint") || t.type.startsWith("int")) {
41
+ const i = t.type.startsWith("int"), [, , c = "256"] = L.exec(t.type) ?? [];
42
+ return M(r, {
43
+ signed: i,
44
+ size: Number(c)
45
+ });
46
+ }
47
+ if (t.type.startsWith("bytes"))
48
+ return $(r, { type: t.type });
49
+ if (t.type === "string")
50
+ return W(r);
51
+ throw new g(t.type);
22
52
  }
23
- function m(r) {
24
- if (o.has(r))
25
- return o.get(r);
26
- u(r, { strict: !1 });
27
- const t = r.substring(2).toLowerCase(), s = f(d(t), { as: "Bytes" }), n = t.split("");
28
- for (let e = 0; e < 40; e += 2)
29
- s[e >> 1] >> 4 >= 8 && n[e] && (n[e] = n[e].toUpperCase()), (s[e >> 1] & 15) >= 8 && n[e + 1] && (n[e + 1] = n[e + 1].toUpperCase());
30
- const a = `0x${n.join("")}`;
31
- return o.set(r, a), a;
32
- }
33
- function k(r, t = {}) {
34
- const { strict: s = !0 } = t ?? {};
35
- try {
36
- return u(r, { strict: s }), !0;
37
- } catch {
38
- return !1;
53
+ function l(e) {
54
+ let n = 0;
55
+ for (let i = 0; i < e.length; i++) {
56
+ const { dynamic: c, encoded: s } = e[i];
57
+ c ? n += 32 : n += d(s);
39
58
  }
59
+ const r = [], t = [];
60
+ let o = 0;
61
+ for (let i = 0; i < e.length; i++) {
62
+ const { dynamic: c, encoded: s } = e[i];
63
+ c ? (r.push(f(n + o, { size: 32 })), t.push(s), o += d(s)) : r.push(s);
64
+ }
65
+ return p(...r, ...t);
66
+ }
67
+ function N(e, n) {
68
+ const { checksum: r = !1 } = n;
69
+ return x(e, { strict: r }), {
70
+ dynamic: !1,
71
+ encoded: h(e.toLowerCase())
72
+ };
40
73
  }
41
- class i extends c {
42
- constructor({ address: t, cause: s }) {
43
- super(`Address "${t}" is invalid.`, {
44
- cause: s
45
- }), Object.defineProperty(this, "name", {
46
- enumerable: !0,
47
- configurable: !0,
48
- writable: !0,
49
- value: "Address.InvalidAddressError"
74
+ function P(e, n) {
75
+ const { checksumAddress: r, length: t, parameter: o } = n, i = t === null;
76
+ if (!Array.isArray(e))
77
+ throw new b(e);
78
+ if (!i && e.length !== t)
79
+ throw new w({
80
+ expectedLength: t,
81
+ givenLength: e.length,
82
+ type: `${o.type}[${t}]`
50
83
  });
84
+ let c = !1;
85
+ const s = [];
86
+ for (let a = 0; a < e.length; a++) {
87
+ const m = u({
88
+ checksumAddress: r,
89
+ parameter: o,
90
+ value: e[a]
91
+ });
92
+ m.dynamic && (c = !0), s.push(m);
93
+ }
94
+ if (i || c) {
95
+ const a = l(s);
96
+ if (i) {
97
+ const m = f(s.length, { size: 32 });
98
+ return {
99
+ dynamic: !0,
100
+ encoded: s.length > 0 ? p(m, a) : m
101
+ };
102
+ }
103
+ if (c)
104
+ return { dynamic: !0, encoded: a };
51
105
  }
106
+ return {
107
+ dynamic: !1,
108
+ encoded: p(...s.map(({ encoded: a }) => a))
109
+ };
52
110
  }
53
- class h extends c {
54
- constructor() {
55
- super("Address is not a 20 byte (40 hexadecimal character) value."), Object.defineProperty(this, "name", {
56
- enumerable: !0,
57
- configurable: !0,
58
- writable: !0,
59
- value: "Address.InvalidInputError"
111
+ function $(e, { type: n }) {
112
+ const [, r] = n.split("bytes"), t = d(e);
113
+ if (!r) {
114
+ let o = e;
115
+ return t % 32 !== 0 && (o = y(o, Math.ceil((e.length - 2) / 2 / 32) * 32)), {
116
+ dynamic: !0,
117
+ encoded: p(h(f(t, { size: 32 })), o)
118
+ };
119
+ }
120
+ if (t !== Number.parseInt(r))
121
+ throw new z({
122
+ expectedSize: Number.parseInt(r),
123
+ value: e
60
124
  });
125
+ return { dynamic: !1, encoded: y(e) };
126
+ }
127
+ function C(e) {
128
+ if (typeof e != "boolean")
129
+ throw new S(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);
130
+ return { dynamic: !1, encoded: h(A(e)) };
131
+ }
132
+ function M(e, { signed: n, size: r }) {
133
+ if (typeof r == "number") {
134
+ const t = 2n ** (BigInt(r) - (n ? 1n : 0n)) - 1n, o = n ? -t - 1n : 0n;
135
+ if (e > t || e < o)
136
+ throw new E({
137
+ max: t.toString(),
138
+ min: o.toString(),
139
+ signed: n,
140
+ size: r / 8,
141
+ value: e.toString()
142
+ });
61
143
  }
144
+ return {
145
+ dynamic: !1,
146
+ encoded: f(e, {
147
+ size: 32,
148
+ signed: n
149
+ })
150
+ };
62
151
  }
63
- class p extends c {
64
- constructor() {
65
- super("Address does not match its checksum counterpart."), Object.defineProperty(this, "name", {
66
- enumerable: !0,
67
- configurable: !0,
68
- writable: !0,
69
- value: "Address.InvalidChecksumError"
152
+ function W(e) {
153
+ const n = I(e), r = Math.ceil(d(n) / 32), t = [];
154
+ for (let o = 0; o < r; o++)
155
+ t.push(y(B(n, o * 32, (o + 1) * 32)));
156
+ return {
157
+ dynamic: !0,
158
+ encoded: p(y(f(d(n), { size: 32 })), ...t)
159
+ };
160
+ }
161
+ function R(e, n) {
162
+ const { checksumAddress: r, parameter: t } = n;
163
+ let o = !1;
164
+ const i = [];
165
+ for (let c = 0; c < t.components.length; c++) {
166
+ const s = t.components[c], a = Array.isArray(e) ? c : s.name, m = u({
167
+ checksumAddress: r,
168
+ parameter: s,
169
+ value: e[a]
70
170
  });
171
+ i.push(m), m.dynamic && (o = !0);
71
172
  }
173
+ return {
174
+ dynamic: o,
175
+ encoded: o ? l(i) : p(...i.map(({ encoded: c }) => c))
176
+ };
177
+ }
178
+ function k(e) {
179
+ const n = e.match(/^(.*)\[(\d+)?\]$/);
180
+ return n ? (
181
+ // Return `null` if the array is dynamic.
182
+ [n[2] ? Number(n[2]) : null, n[1]]
183
+ ) : void 0;
72
184
  }
73
185
  export {
74
- i as InvalidAddressError,
75
- p as InvalidChecksumError,
76
- h as InvalidInputError,
77
- u as assert,
78
- m as checksum,
79
- k as validate
186
+ l as encode,
187
+ N as encodeAddress,
188
+ P as encodeArray,
189
+ C as encodeBoolean,
190
+ $ as encodeBytes,
191
+ M as encodeNumber,
192
+ W as encodeString,
193
+ R as encodeTuple,
194
+ k as getArrayComponents,
195
+ u as prepareParameter,
196
+ q as prepareParameters
80
197
  };
package/dist/index309.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=/^(.*)\[([0-9]*)\]$/,t=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,g=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;exports.arrayRegex=e;exports.bytesRegex=t;exports.integerRegex=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index41.cjs");class t extends a.BaseError{constructor(e){const{docsPath:s,field:r,metaMessages:i}=e;super(`Invalid Sign-In with Ethereum message field "${r}".`,{docsPath:s,metaMessages:i,name:"SiweInvalidMessageFieldError"})}}exports.SiweInvalidMessageFieldError=t;
package/dist/index309.js CHANGED
@@ -1,6 +1,14 @@
1
- const e = /^(.*)\[([0-9]*)\]$/, t = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/, n = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;
1
+ import { BaseError as i } from "./index41.js";
2
+ class d extends i {
3
+ constructor(e) {
4
+ const { docsPath: s, field: r, metaMessages: a } = e;
5
+ super(`Invalid Sign-In with Ethereum message field "${r}".`, {
6
+ docsPath: s,
7
+ metaMessages: a,
8
+ name: "SiweInvalidMessageFieldError"
9
+ });
10
+ }
11
+ }
2
12
  export {
3
- e as arrayRegex,
4
- t as bytesRegex,
5
- n as integerRegex
13
+ d as SiweInvalidMessageFieldError
6
14
  };
package/dist/index310.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./index293.cjs"),w=require("./index308.cjs"),N=require("./index303.cjs"),c=require("./index290.cjs"),x=require("./index309.cjs");function P({checksumAddress:e,parameters:r,values:n}){const t=[];for(let o=0;o<r.length;o++)t.push(f({checksumAddress:e,parameter:r[o],value:n[o]}));return t}function f({checksumAddress:e=!1,parameter:r,value:n}){const t=r,o=S(t.type);if(o){const[i,s]=o;return h(n,{checksumAddress:e,length:i,parameter:{...t,type:s}})}if(t.type==="tuple")return A(n,{checksumAddress:e,parameter:t});if(t.type==="address")return y(n,{checksum:e});if(t.type==="bool")return g(n);if(t.type.startsWith("uint")||t.type.startsWith("int")){const i=t.type.startsWith("int"),[,,s="256"]=x.integerRegex.exec(t.type)??[];return b(n,{signed:i,size:Number(s)})}if(t.type.startsWith("bytes"))return l(n,{type:t.type});if(t.type==="string")return z(n);throw new m.InvalidTypeError(t.type)}function u(e){let r=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?r+=32:r+=c.size(a)}const n=[],t=[];let o=0;for(let i=0;i<e.length;i++){const{dynamic:s,encoded:a}=e[i];s?(n.push(c.fromNumber(r+o,{size:32})),t.push(a),o+=c.size(a)):n.push(a)}return c.concat(...n,...t)}function y(e,r){const{checksum:n=!1}=r;return w.assert(e,{strict:n}),{dynamic:!1,encoded:c.padLeft(e.toLowerCase())}}function h(e,r){const{checksumAddress:n,length:t,parameter:o}=r,i=t===null;if(!Array.isArray(e))throw new m.InvalidArrayError(e);if(!i&&e.length!==t)throw new m.ArrayLengthMismatchError({expectedLength:t,givenLength:e.length,type:`${o.type}[${t}]`});let s=!1;const a=[];for(let d=0;d<e.length;d++){const p=f({checksumAddress:n,parameter:o,value:e[d]});p.dynamic&&(s=!0),a.push(p)}if(i||s){const d=u(a);if(i){const p=c.fromNumber(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?c.concat(p,d):p}}if(s)return{dynamic:!0,encoded:d}}return{dynamic:!1,encoded:c.concat(...a.map(({encoded:d})=>d))}}function l(e,{type:r}){const[,n]=r.split("bytes"),t=c.size(e);if(!n){let o=e;return t%32!==0&&(o=c.padRight(o,Math.ceil((e.length-2)/2/32)*32)),{dynamic:!0,encoded:c.concat(c.padLeft(c.fromNumber(t,{size:32})),o)}}if(t!==Number.parseInt(n))throw new m.BytesSizeMismatchError({expectedSize:Number.parseInt(n),value:e});return{dynamic:!1,encoded:c.padRight(e)}}function g(e){if(typeof e!="boolean")throw new N.BaseError(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:c.padLeft(c.fromBoolean(e))}}function b(e,{signed:r,size:n}){if(typeof n=="number"){const t=2n**(BigInt(n)-(r?1n:0n))-1n,o=r?-t-1n:0n;if(e>t||e<o)throw new c.IntegerOutOfRangeError({max:t.toString(),min:o.toString(),signed:r,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:c.fromNumber(e,{size:32,signed:r})}}function z(e){const r=c.fromString(e),n=Math.ceil(c.size(r)/32),t=[];for(let o=0;o<n;o++)t.push(c.padRight(c.slice(r,o*32,(o+1)*32)));return{dynamic:!0,encoded:c.concat(c.padRight(c.fromNumber(c.size(r),{size:32})),...t)}}function A(e,r){const{checksumAddress:n,parameter:t}=r;let o=!1;const i=[];for(let s=0;s<t.components.length;s++){const a=t.components[s],d=Array.isArray(e)?s:a.name,p=f({checksumAddress:n,parameter:a,value:e[d]});i.push(p),p.dynamic&&(o=!0)}return{dynamic:o,encoded:o?u(i):c.concat(...i.map(({encoded:s})=>s))}}function S(e){const r=e.match(/^(.*)\[(\d+)?\]$/);return r?[r[2]?Number(r[2]):null,r[1]]:void 0}exports.encode=u;exports.encodeAddress=y;exports.encodeArray=h;exports.encodeBoolean=g;exports.encodeBytes=l;exports.encodeNumber=b;exports.encodeString=z;exports.encodeTuple=A;exports.getArrayComponents=S;exports.prepareParameter=f;exports.prepareParameters=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){if(/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(e)||/%[^0-9a-f]/i.test(e)||/%[0-9a-f](:?[^0-9a-f]|$)/i.test(e))return!1;const s=a(e),f=s[1],t=s[2],i=s[3],r=s[4],l=s[5];if(!(f!=null&&f.length&&i.length>=0))return!1;if(t!=null&&t.length){if(!(i.length===0||/^\//.test(i)))return!1}else if(/^\/\//.test(i))return!1;if(!/^[a-z][a-z0-9\+\-\.]*$/.test(f.toLowerCase()))return!1;let n="";return n+=`${f}:`,t!=null&&t.length&&(n+=`//${t}`),n+=i,r!=null&&r.length&&(n+=`?${r}`),l!=null&&l.length&&(n+=`#${l}`),n}function a(e){return e.match(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/)}exports.isUri=o;
package/dist/index310.js CHANGED
@@ -1,197 +1,22 @@
1
- import { InvalidTypeError as g, InvalidArrayError as b, ArrayLengthMismatchError as w, BytesSizeMismatchError as z } from "./index293.js";
2
- import { assert as x } from "./index308.js";
3
- import { BaseError as S } from "./index303.js";
4
- import { size as d, fromNumber as f, concat as p, padLeft as h, fromBoolean as A, IntegerOutOfRangeError as E, padRight as y, fromString as I, slice as B } from "./index290.js";
5
- import { integerRegex as L } from "./index309.js";
6
- function q({ checksumAddress: e, parameters: n, values: r }) {
7
- const t = [];
8
- for (let o = 0; o < n.length; o++)
9
- t.push(u({
10
- checksumAddress: e,
11
- parameter: n[o],
12
- value: r[o]
13
- }));
14
- return t;
15
- }
16
- function u({ checksumAddress: e = !1, parameter: n, value: r }) {
17
- const t = n, o = k(t.type);
18
- if (o) {
19
- const [i, c] = o;
20
- return P(r, {
21
- checksumAddress: e,
22
- length: i,
23
- parameter: {
24
- ...t,
25
- type: c
26
- }
27
- });
28
- }
29
- if (t.type === "tuple")
30
- return R(r, {
31
- checksumAddress: e,
32
- parameter: t
33
- });
34
- if (t.type === "address")
35
- return N(r, {
36
- checksum: e
37
- });
38
- if (t.type === "bool")
39
- return C(r);
40
- if (t.type.startsWith("uint") || t.type.startsWith("int")) {
41
- const i = t.type.startsWith("int"), [, , c = "256"] = L.exec(t.type) ?? [];
42
- return M(r, {
43
- signed: i,
44
- size: Number(c)
45
- });
46
- }
47
- if (t.type.startsWith("bytes"))
48
- return $(r, { type: t.type });
49
- if (t.type === "string")
50
- return W(r);
51
- throw new g(t.type);
52
- }
53
- function l(e) {
54
- let n = 0;
55
- for (let i = 0; i < e.length; i++) {
56
- const { dynamic: c, encoded: s } = e[i];
57
- c ? n += 32 : n += d(s);
58
- }
59
- const r = [], t = [];
60
- let o = 0;
61
- for (let i = 0; i < e.length; i++) {
62
- const { dynamic: c, encoded: s } = e[i];
63
- c ? (r.push(f(n + o, { size: 32 })), t.push(s), o += d(s)) : r.push(s);
64
- }
65
- return p(...r, ...t);
66
- }
67
- function N(e, n) {
68
- const { checksum: r = !1 } = n;
69
- return x(e, { strict: r }), {
70
- dynamic: !1,
71
- encoded: h(e.toLowerCase())
72
- };
73
- }
74
- function P(e, n) {
75
- const { checksumAddress: r, length: t, parameter: o } = n, i = t === null;
76
- if (!Array.isArray(e))
77
- throw new b(e);
78
- if (!i && e.length !== t)
79
- throw new w({
80
- expectedLength: t,
81
- givenLength: e.length,
82
- type: `${o.type}[${t}]`
83
- });
84
- let c = !1;
85
- const s = [];
86
- for (let a = 0; a < e.length; a++) {
87
- const m = u({
88
- checksumAddress: r,
89
- parameter: o,
90
- value: e[a]
91
- });
92
- m.dynamic && (c = !0), s.push(m);
93
- }
94
- if (i || c) {
95
- const a = l(s);
96
- if (i) {
97
- const m = f(s.length, { size: 32 });
98
- return {
99
- dynamic: !0,
100
- encoded: s.length > 0 ? p(m, a) : m
101
- };
102
- }
103
- if (c)
104
- return { dynamic: !0, encoded: a };
105
- }
106
- return {
107
- dynamic: !1,
108
- encoded: p(...s.map(({ encoded: a }) => a))
109
- };
110
- }
111
- function $(e, { type: n }) {
112
- const [, r] = n.split("bytes"), t = d(e);
113
- if (!r) {
114
- let o = e;
115
- return t % 32 !== 0 && (o = y(o, Math.ceil((e.length - 2) / 2 / 32) * 32)), {
116
- dynamic: !0,
117
- encoded: p(h(f(t, { size: 32 })), o)
118
- };
119
- }
120
- if (t !== Number.parseInt(r))
121
- throw new z({
122
- expectedSize: Number.parseInt(r),
123
- value: e
124
- });
125
- return { dynamic: !1, encoded: y(e) };
126
- }
127
- function C(e) {
128
- if (typeof e != "boolean")
129
- throw new S(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);
130
- return { dynamic: !1, encoded: h(A(e)) };
131
- }
132
- function M(e, { signed: n, size: r }) {
133
- if (typeof r == "number") {
134
- const t = 2n ** (BigInt(r) - (n ? 1n : 0n)) - 1n, o = n ? -t - 1n : 0n;
135
- if (e > t || e < o)
136
- throw new E({
137
- max: t.toString(),
138
- min: o.toString(),
139
- signed: n,
140
- size: r / 8,
141
- value: e.toString()
142
- });
143
- }
144
- return {
145
- dynamic: !1,
146
- encoded: f(e, {
147
- size: 32,
148
- signed: n
149
- })
150
- };
151
- }
152
- function W(e) {
153
- const n = I(e), r = Math.ceil(d(n) / 32), t = [];
154
- for (let o = 0; o < r; o++)
155
- t.push(y(B(n, o * 32, (o + 1) * 32)));
156
- return {
157
- dynamic: !0,
158
- encoded: p(y(f(d(n), { size: 32 })), ...t)
159
- };
160
- }
161
- function R(e, n) {
162
- const { checksumAddress: r, parameter: t } = n;
163
- let o = !1;
164
- const i = [];
165
- for (let c = 0; c < t.components.length; c++) {
166
- const s = t.components[c], a = Array.isArray(e) ? c : s.name, m = u({
167
- checksumAddress: r,
168
- parameter: s,
169
- value: e[a]
170
- });
171
- i.push(m), m.dynamic && (o = !0);
172
- }
173
- return {
174
- dynamic: o,
175
- encoded: o ? l(i) : p(...i.map(({ encoded: c }) => c))
176
- };
177
- }
178
- function k(e) {
179
- const n = e.match(/^(.*)\[(\d+)?\]$/);
180
- return n ? (
181
- // Return `null` if the array is dynamic.
182
- [n[2] ? Number(n[2]) : null, n[1]]
183
- ) : void 0;
1
+ function o(e) {
2
+ if (/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(e) || /%[^0-9a-f]/i.test(e) || /%[0-9a-f](:?[^0-9a-f]|$)/i.test(e))
3
+ return !1;
4
+ const s = a(e), f = s[1], t = s[2], i = s[3], r = s[4], l = s[5];
5
+ if (!(f != null && f.length && i.length >= 0))
6
+ return !1;
7
+ if (t != null && t.length) {
8
+ if (!(i.length === 0 || /^\//.test(i)))
9
+ return !1;
10
+ } else if (/^\/\//.test(i))
11
+ return !1;
12
+ if (!/^[a-z][a-z0-9\+\-\.]*$/.test(f.toLowerCase()))
13
+ return !1;
14
+ let n = "";
15
+ return n += `${f}:`, t != null && t.length && (n += `//${t}`), n += i, r != null && r.length && (n += `?${r}`), l != null && l.length && (n += `#${l}`), n;
16
+ }
17
+ function a(e) {
18
+ return e.match(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
184
19
  }
185
20
  export {
186
- l as encode,
187
- N as encodeAddress,
188
- P as encodeArray,
189
- C as encodeBoolean,
190
- $ as encodeBytes,
191
- M as encodeNumber,
192
- W as encodeString,
193
- R as encodeTuple,
194
- k as getArrayComponents,
195
- u as prepareParameter,
196
- q as prepareParameters
21
+ o as isUri
197
22
  };
package/dist/index311.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index315.cjs");function r(){return e.version}exports.getVersion=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index301.cjs"),y=require("./index282.cjs"),s=require("./index312.cjs"),z=require("./index303.cjs"),S=new TextEncoder;function x(e){return e instanceof Uint8Array?e:typeof e=="string"?h(e):g(e)}function g(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function h(e,t={}){const{size:r}=t;let n=e;r&&(z.assertSize(e,r),n=y.padRight(e,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const d=i.length/2,f=new Uint8Array(d);for(let c=0,o=0;c<d;c++){const u=s.charCodeToBase16(i.charCodeAt(o++)),b=s.charCodeToBase16(i.charCodeAt(o++));if(u===void 0||b===void 0)throw new a.BaseError(`Invalid byte sequence ("${i[o-2]}${i[o-1]}" in "${i}").`);f[c]=u*16+b}return f}function m(e,t={}){const{size:r}=t,n=S.encode(e);return typeof r=="number"?(s.assertSize(n,r),l(n,r)):n}function l(e,t){return s.pad(e,{dir:"right",size:t})}function E(e){return e.length}class p extends a.BaseError{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${t}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class $ extends a.BaseError{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${t}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}exports.SizeExceedsPaddingSizeError=$;exports.SizeOverflowError=p;exports.from=x;exports.fromArray=g;exports.fromHex=h;exports.fromString=m;exports.padRight=l;exports.size=E;
package/dist/index311.js CHANGED
@@ -1,7 +1,66 @@
1
- import { version as r } from "./index315.js";
2
- function e() {
3
- return r;
1
+ import { BaseError as c } from "./index301.js";
2
+ import { padRight as h } from "./index282.js";
3
+ import { charCodeToBase16 as b, assertSize as g, pad as m } from "./index312.js";
4
+ import { assertSize as p } from "./index303.js";
5
+ const l = /* @__PURE__ */ new TextEncoder();
6
+ function E(e) {
7
+ return e instanceof Uint8Array ? e : typeof e == "string" ? y(e) : z(e);
8
+ }
9
+ function z(e) {
10
+ return e instanceof Uint8Array ? e : new Uint8Array(e);
11
+ }
12
+ function y(e, t = {}) {
13
+ const { size: r } = t;
14
+ let n = e;
15
+ r && (p(e, r), n = h(e, r));
16
+ let i = n.slice(2);
17
+ i.length % 2 && (i = `0${i}`);
18
+ const f = i.length / 2, a = new Uint8Array(f);
19
+ for (let s = 0, o = 0; s < f; s++) {
20
+ const d = b(i.charCodeAt(o++)), u = b(i.charCodeAt(o++));
21
+ if (d === void 0 || u === void 0)
22
+ throw new c(`Invalid byte sequence ("${i[o - 2]}${i[o - 1]}" in "${i}").`);
23
+ a[s] = d * 16 + u;
24
+ }
25
+ return a;
26
+ }
27
+ function C(e, t = {}) {
28
+ const { size: r } = t, n = l.encode(e);
29
+ return typeof r == "number" ? (g(n, r), x(n, r)) : n;
30
+ }
31
+ function x(e, t) {
32
+ return m(e, { dir: "right", size: t });
33
+ }
34
+ function U(e) {
35
+ return e.length;
36
+ }
37
+ class B extends c {
38
+ constructor({ givenSize: t, maxSize: r }) {
39
+ super(`Size cannot exceed \`${r}\` bytes. Given size: \`${t}\` bytes.`), Object.defineProperty(this, "name", {
40
+ enumerable: !0,
41
+ configurable: !0,
42
+ writable: !0,
43
+ value: "Bytes.SizeOverflowError"
44
+ });
45
+ }
46
+ }
47
+ class O extends c {
48
+ constructor({ size: t, targetSize: r, type: n }) {
49
+ super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${t}\`) exceeds padding size (\`${r}\`).`), Object.defineProperty(this, "name", {
50
+ enumerable: !0,
51
+ configurable: !0,
52
+ writable: !0,
53
+ value: "Bytes.SizeExceedsPaddingSizeError"
54
+ });
55
+ }
4
56
  }
5
57
  export {
6
- e as getVersion
58
+ O as SizeExceedsPaddingSizeError,
59
+ B as SizeOverflowError,
60
+ E as from,
61
+ z as fromArray,
62
+ y as fromHex,
63
+ C as fromString,
64
+ x as padRight,
65
+ U as size
7
66
  };
package/dist/index312.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index303.cjs"),y=require("./index290.cjs"),s=require("./index313.cjs"),z=require("./index305.cjs"),S=new TextEncoder;function x(e){return e instanceof Uint8Array?e:typeof e=="string"?h(e):g(e)}function g(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function h(e,t={}){const{size:r}=t;let n=e;r&&(z.assertSize(e,r),n=y.padRight(e,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const d=i.length/2,f=new Uint8Array(d);for(let c=0,o=0;c<d;c++){const u=s.charCodeToBase16(i.charCodeAt(o++)),b=s.charCodeToBase16(i.charCodeAt(o++));if(u===void 0||b===void 0)throw new a.BaseError(`Invalid byte sequence ("${i[o-2]}${i[o-1]}" in "${i}").`);f[c]=u*16+b}return f}function m(e,t={}){const{size:r}=t,n=S.encode(e);return typeof r=="number"?(s.assertSize(n,r),l(n,r)):n}function l(e,t){return s.pad(e,{dir:"right",size:t})}function E(e){return e.length}class p extends a.BaseError{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${t}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class $ extends a.BaseError{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${t}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}exports.SizeExceedsPaddingSizeError=$;exports.SizeOverflowError=p;exports.from=x;exports.fromArray=g;exports.fromHex=h;exports.fromString=m;exports.padRight=l;exports.size=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index311.cjs");function s(e,t){if(o.size(e)>t)throw new o.SizeOverflowError({givenSize:o.size(e),maxSize:t})}const n={zero:48,nine:57,A:65,F:70,a:97,f:102};function u(e){if(e>=n.zero&&e<=n.nine)return e-n.zero;if(e>=n.A&&e<=n.F)return e-(n.A-10);if(e>=n.a&&e<=n.f)return e-(n.a-10)}function z(e,t={}){const{dir:f,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new o.SizeExceedsPaddingSizeError({size:e.length,targetSize:r,type:"Bytes"});const d=new Uint8Array(r);for(let i=0;i<r;i++){const a=f==="right";d[a?i:r-i-1]=e[a?i:e.length-i-1]}return d}exports.assertSize=s;exports.charCodeMap=n;exports.charCodeToBase16=u;exports.pad=z;