@gardenfi/utils 2.0.6 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +22 -20
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +37 -19
  5. package/dist/index100.cjs +1 -1
  6. package/dist/index100.js +77 -126
  7. package/dist/index101.cjs +1 -1
  8. package/dist/index101.js +17 -111
  9. package/dist/index102.cjs +1 -1
  10. package/dist/index102.js +10 -77
  11. package/dist/index103.cjs +1 -1
  12. package/dist/index103.js +20 -2
  13. package/dist/index104.cjs +1 -1
  14. package/dist/index104.js +11 -16
  15. package/dist/index105.cjs +1 -1
  16. package/dist/index105.js +38 -18
  17. package/dist/index106.cjs +1 -1
  18. package/dist/index106.js +5 -17
  19. package/dist/index107.cjs +1 -1
  20. package/dist/index107.js +10 -223
  21. package/dist/index108.cjs +1 -2
  22. package/dist/index108.js +2 -3
  23. package/dist/index109.cjs +1 -1
  24. package/dist/index109.js +18 -32
  25. package/dist/index11.cjs +1 -1
  26. package/dist/index11.js +19 -134
  27. package/dist/index110.cjs +1 -1
  28. package/dist/index110.js +126 -17
  29. package/dist/index111.cjs +1 -1
  30. package/dist/index111.js +6 -69
  31. package/dist/index112.cjs +1 -1
  32. package/dist/index112.js +2 -68
  33. package/dist/index113.cjs +1 -1
  34. package/dist/index113.js +38 -2
  35. package/dist/index114.cjs +1 -1
  36. package/dist/index114.js +5 -41
  37. package/dist/index115.cjs +2 -1
  38. package/dist/index115.js +3 -644
  39. package/dist/index116.cjs +1 -1
  40. package/dist/index116.js +15 -228
  41. package/dist/index117.cjs +1 -1
  42. package/dist/index117.js +624 -153
  43. package/dist/index118.cjs +1 -0
  44. package/dist/index118.js +175 -0
  45. package/dist/index12.cjs +1 -1
  46. package/dist/index12.js +136 -10
  47. package/dist/index13.cjs +1 -1
  48. package/dist/index13.js +15 -2
  49. package/dist/index14.cjs +1 -1
  50. package/dist/index14.js +2 -34
  51. package/dist/index15.cjs +1 -1
  52. package/dist/index15.js +32 -17
  53. package/dist/index16.cjs +1 -1
  54. package/dist/index16.js +14 -183
  55. package/dist/index17.cjs +1 -1
  56. package/dist/index17.js +187 -92
  57. package/dist/index18.cjs +1 -1
  58. package/dist/index18.js +92 -34
  59. package/dist/index19.cjs +1 -1
  60. package/dist/index19.js +36 -32
  61. package/dist/index20.cjs +1 -16
  62. package/dist/index20.js +30 -113
  63. package/dist/index21.cjs +1 -1
  64. package/dist/index21.js +18 -17
  65. package/dist/index22.cjs +16 -1
  66. package/dist/index22.js +113 -17
  67. package/dist/index23.cjs +1 -1
  68. package/dist/index23.js +17 -7
  69. package/dist/index24.cjs +1 -1
  70. package/dist/index24.js +6 -44
  71. package/dist/index25.cjs +1 -1
  72. package/dist/index25.js +45 -21
  73. package/dist/index26.cjs +1 -1
  74. package/dist/index26.js +21 -8
  75. package/dist/index27.cjs +1 -1
  76. package/dist/index27.js +8 -31
  77. package/dist/index28.cjs +1 -1
  78. package/dist/index28.js +31 -26
  79. package/dist/index29.cjs +1 -2
  80. package/dist/index29.js +25 -64
  81. package/dist/index30.cjs +2 -1
  82. package/dist/index30.js +64 -50
  83. package/dist/index31.cjs +1 -1
  84. package/dist/index31.js +51 -12
  85. package/dist/index32.cjs +1 -1
  86. package/dist/index32.js +12 -24
  87. package/dist/index33.cjs +1 -1
  88. package/dist/index33.js +24 -75
  89. package/dist/index34.cjs +1 -1
  90. package/dist/index34.js +74 -22
  91. package/dist/index35.cjs +1 -1
  92. package/dist/index35.js +23 -7
  93. package/dist/index36.cjs +1 -1
  94. package/dist/index36.js +7 -32
  95. package/dist/index37.cjs +1 -1
  96. package/dist/index37.js +31 -14
  97. package/dist/index38.cjs +1 -1
  98. package/dist/index38.js +16 -2
  99. package/dist/index39.cjs +1 -1
  100. package/dist/index39.js +2 -9
  101. package/dist/index4.cjs +1 -1
  102. package/dist/index4.js +2 -2
  103. package/dist/index40.cjs +1 -1
  104. package/dist/index40.js +8 -20
  105. package/dist/index41.cjs +1 -1
  106. package/dist/index41.js +20 -12
  107. package/dist/index42.cjs +1 -1
  108. package/dist/index42.js +40 -33
  109. package/dist/index43.cjs +1 -2
  110. package/dist/index43.js +24 -58
  111. package/dist/index44.cjs +1 -1
  112. package/dist/index44.js +7 -2
  113. package/dist/index45.cjs +1 -1
  114. package/dist/index45.js +13 -6
  115. package/dist/index46.cjs +1 -1
  116. package/dist/index46.js +15 -6
  117. package/dist/index47.cjs +1 -1
  118. package/dist/index47.js +5 -4
  119. package/dist/index48.cjs +1 -1
  120. package/dist/index48.js +13 -11
  121. package/dist/index49.cjs +1 -5
  122. package/dist/index49.js +10 -56
  123. package/dist/index50.cjs +1 -2
  124. package/dist/index50.js +10 -32
  125. package/dist/index51.cjs +1 -1
  126. package/dist/index51.js +11 -5
  127. package/dist/index52.cjs +1 -1
  128. package/dist/index52.js +13 -3
  129. package/dist/index53.cjs +1 -1
  130. package/dist/index53.js +54 -20
  131. package/dist/index54.cjs +1 -1
  132. package/dist/index54.js +16 -12
  133. package/dist/index55.cjs +1 -1
  134. package/dist/index55.js +5 -55
  135. package/dist/index56.cjs +1 -1
  136. package/dist/index56.js +4 -4
  137. package/dist/index57.cjs +1 -1
  138. package/dist/index57.js +169 -19
  139. package/dist/index58.cjs +1 -1
  140. package/dist/index58.js +103 -11
  141. package/dist/index59.cjs +1 -1
  142. package/dist/index59.js +21 -8
  143. package/dist/index6.cjs +1 -1
  144. package/dist/index6.js +40 -22
  145. package/dist/index60.cjs +1 -1
  146. package/dist/index60.js +11 -9
  147. package/dist/index61.cjs +1 -1
  148. package/dist/index61.js +34 -11
  149. package/dist/index62.cjs +1 -1
  150. package/dist/index62.js +8 -6
  151. package/dist/index63.cjs +2 -1
  152. package/dist/index63.js +59 -13
  153. package/dist/index64.cjs +1 -1
  154. package/dist/index64.js +2 -33
  155. package/dist/index65.cjs +1 -1
  156. package/dist/index65.js +6 -14
  157. package/dist/index66.cjs +1 -1
  158. package/dist/index66.js +6 -64
  159. package/dist/index67.cjs +1 -1
  160. package/dist/index67.js +4 -27
  161. package/dist/index68.cjs +1 -1
  162. package/dist/index68.js +12 -3
  163. package/dist/index69.cjs +1 -1
  164. package/dist/index69.js +3 -3
  165. package/dist/index7.cjs +1 -1
  166. package/dist/index7.js +24 -2
  167. package/dist/index70.cjs +5 -1
  168. package/dist/index70.js +56 -13
  169. package/dist/index71.cjs +2 -1
  170. package/dist/index71.js +33 -40
  171. package/dist/index72.cjs +1 -1
  172. package/dist/index72.js +5 -5
  173. package/dist/index73.cjs +1 -1
  174. package/dist/index73.js +21 -8
  175. package/dist/index74.cjs +1 -1
  176. package/dist/index74.js +8 -103
  177. package/dist/index75.cjs +1 -1
  178. package/dist/index75.js +9 -190
  179. package/dist/index76.cjs +1 -1
  180. package/dist/index76.js +11 -18
  181. package/dist/index77.cjs +1 -1
  182. package/dist/index77.js +6 -11
  183. package/dist/index78.cjs +1 -1
  184. package/dist/index78.js +13 -19
  185. package/dist/index79.cjs +1 -1
  186. package/dist/index79.js +31 -11
  187. package/dist/index8.cjs +1 -1
  188. package/dist/index8.js +2 -100
  189. package/dist/index80.cjs +1 -1
  190. package/dist/index80.js +14 -25
  191. package/dist/index81.cjs +1 -1
  192. package/dist/index81.js +64 -6
  193. package/dist/index82.cjs +1 -1
  194. package/dist/index82.js +27 -13
  195. package/dist/index83.cjs +1 -1
  196. package/dist/index83.js +3 -16
  197. package/dist/index84.cjs +1 -1
  198. package/dist/index84.js +3 -5
  199. package/dist/index85.cjs +1 -1
  200. package/dist/index85.js +8 -13
  201. package/dist/index86.cjs +1 -1
  202. package/dist/index86.js +190 -9
  203. package/dist/index87.cjs +1 -1
  204. package/dist/index87.js +18 -16
  205. package/dist/index88.cjs +1 -1
  206. package/dist/index88.js +39 -170
  207. package/dist/index89.cjs +1 -1
  208. package/dist/index89.js +30 -34
  209. package/dist/index9.cjs +1 -1
  210. package/dist/index9.js +105 -34
  211. package/dist/index90.cjs +1 -1
  212. package/dist/index90.js +69 -8
  213. package/dist/index91.cjs +1 -1
  214. package/dist/index91.js +113 -5
  215. package/dist/index92.cjs +1 -1
  216. package/dist/index92.js +67 -10
  217. package/dist/index93.cjs +1 -1
  218. package/dist/index93.js +2 -2
  219. package/dist/index94.cjs +1 -1
  220. package/dist/index94.js +15 -103
  221. package/dist/index95.cjs +1 -1
  222. package/dist/index95.js +218 -37
  223. package/dist/index96.cjs +1 -1
  224. package/dist/index96.js +227 -16
  225. package/dist/index97.cjs +1 -1
  226. package/dist/index97.js +42 -6
  227. package/dist/index98.cjs +1 -1
  228. package/dist/index98.js +105 -5
  229. package/dist/index99.cjs +1 -1
  230. package/dist/index99.js +16 -36
  231. package/dist/src/index.d.ts +1 -0
  232. package/dist/src/lib/auth/siwe/siwe.d.ts +3 -2
  233. package/dist/src/lib/digestKey/digestKey.d.ts +12 -0
  234. package/package.json +4 -1
package/dist/index103.js CHANGED
@@ -1,4 +1,22 @@
1
- const e = 1;
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(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
19
+ }
2
20
  export {
3
- e as versionedHashVersionKzg
21
+ o as isUri
4
22
  };
package/dist/index104.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index24.cjs"),c=require("./index88.cjs");function u(t){if(!t||t.length===0)return[];const e=[];for(const n of t){const{contractAddress:s,chainId:r,nonce:i,...a}=n;e.push([r?o.toHex(r):"0x",s,i?o.toHex(i):"0x",...c.toYParitySignatureArray({},a)])}return e}exports.serializeAuthorizationList=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index63.cjs");class i extends t.BaseError{constructor({offset:r,position:s,size:e}){super(`Slice ${s==="start"?"starting":"ending"} at offset "${r}" is out-of-bounds (size: ${e}).`,{name:"SliceOffsetOutOfBoundsError"})}}class d extends t.BaseError{constructor({size:r,targetSize:s,type:e}){super(`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()} size (${r}) exceeds padding size (${s}).`,{name:"SizeExceedsPaddingSizeError"})}}exports.SizeExceedsPaddingSizeError=d;exports.SliceOffsetOutOfBoundsError=i;
package/dist/index104.js CHANGED
@@ -1,20 +1,15 @@
1
- import { toHex as i } from "./index24.js";
2
- import { toYParitySignatureArray as c } from "./index88.js";
3
- function d(r) {
4
- if (!r || r.length === 0)
5
- return [];
6
- const t = [];
7
- for (const e of r) {
8
- const { contractAddress: s, chainId: o, nonce: n, ...a } = e;
9
- t.push([
10
- o ? i(o) : "0x",
11
- s,
12
- n ? i(n) : "0x",
13
- ...c({}, a)
14
- ]);
1
+ import { BaseError as o } from "./index63.js";
2
+ class d extends o {
3
+ constructor({ offset: r, position: s, size: e }) {
4
+ super(`Slice ${s === "start" ? "starting" : "ending"} at offset "${r}" is out-of-bounds (size: ${e}).`, { name: "SliceOffsetOutOfBoundsError" });
5
+ }
6
+ }
7
+ class n extends o {
8
+ constructor({ size: r, targetSize: s, type: e }) {
9
+ super(`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()} size (${r}) exceeds padding size (${s}).`, { name: "SizeExceedsPaddingSizeError" });
15
10
  }
16
- return t;
17
11
  }
18
12
  export {
19
- d as serializeAuthorizationList
13
+ n as SizeExceedsPaddingSizeError,
14
+ d as SliceOffsetOutOfBoundsError
20
15
  };
package/dist/index105.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index54.cjs"),d=require("./index29.cjs"),l=require("./index58.cjs");function a(e){if(!e||e.length===0)return[];const n=[];for(let t=0;t<e.length;t++){const{address:i,storageKeys:r}=e[t];for(let s=0;s<r.length;s++)if(r[s].length-2!==64)throw new d.InvalidStorageKeySizeError({storageKey:r[s]});if(!l.isAddress(i,{strict:!1}))throw new o.InvalidAddressError({address:i});n.push([i,r])}return n}exports.serializeAccessList=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index104.cjs"),O=require("./index84.cjs"),n=require("./index67.cjs");function p(i,e,s,{strict:f}={}){return O.isHex(i,{strict:!1})?l(i,e,s,{strict:f}):u(i,e,s,{strict:f})}function r(i,e){if(typeof e=="number"&&e>0&&e>n.size(i)-1)throw new t.SliceOffsetOutOfBoundsError({offset:e,position:"start",size:n.size(i)})}function c(i,e,s){if(typeof e=="number"&&typeof s=="number"&&n.size(i)!==s-e)throw new t.SliceOffsetOutOfBoundsError({offset:s,position:"end",size:n.size(i)})}function u(i,e,s,{strict:f}={}){r(i,e);const o=i.slice(e,s);return f&&c(o,e,s),o}function l(i,e,s,{strict:f}={}){r(i,e);const o=`0x${i.replace("0x","").slice((e??0)*2,(s??i.length)*2)}`;return f&&c(o,e,s),o}exports.slice=p;exports.sliceBytes=u;exports.sliceHex=l;
package/dist/index105.js CHANGED
@@ -1,21 +1,41 @@
1
- import { InvalidAddressError as s } from "./index54.js";
2
- import { InvalidStorageKeySizeError as l } from "./index29.js";
3
- import { isAddress as f } from "./index58.js";
4
- function a(r) {
5
- if (!r || r.length === 0)
6
- return [];
7
- const n = [];
8
- for (let o = 0; o < r.length; o++) {
9
- const { address: i, storageKeys: e } = r[o];
10
- for (let t = 0; t < e.length; t++)
11
- if (e[t].length - 2 !== 64)
12
- throw new l({ storageKey: e[t] });
13
- if (!f(i, { strict: !1 }))
14
- throw new s({ address: i });
15
- n.push([i, e]);
16
- }
17
- return n;
1
+ import { SliceOffsetOutOfBoundsError as t } from "./index104.js";
2
+ import { isHex as p } from "./index84.js";
3
+ import { size as r } from "./index67.js";
4
+ function w(e, f, i, { strict: o } = {}) {
5
+ return p(e, { strict: !1 }) ? u(e, f, i, {
6
+ strict: o
7
+ }) : m(e, f, i, {
8
+ strict: o
9
+ });
10
+ }
11
+ function s(e, f) {
12
+ if (typeof f == "number" && f > 0 && f > r(e) - 1)
13
+ throw new t({
14
+ offset: f,
15
+ position: "start",
16
+ size: r(e)
17
+ });
18
+ }
19
+ function c(e, f, i) {
20
+ if (typeof f == "number" && typeof i == "number" && r(e) !== i - f)
21
+ throw new t({
22
+ offset: i,
23
+ position: "end",
24
+ size: r(e)
25
+ });
26
+ }
27
+ function m(e, f, i, { strict: o } = {}) {
28
+ s(e, f);
29
+ const n = e.slice(f, i);
30
+ return o && c(n, f, i), n;
31
+ }
32
+ function u(e, f, i, { strict: o } = {}) {
33
+ s(e, f);
34
+ const n = `0x${e.replace("0x", "").slice((f ?? 0) * 2, (i ?? e.length) * 2)}`;
35
+ return o && c(n, f, i), n;
18
36
  }
19
37
  export {
20
- a as serializeAccessList
38
+ w as slice,
39
+ m as sliceBytes,
40
+ u as sliceHex
21
41
  };
package/dist/index106.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index114.cjs"),s=require("./index111.cjs"),o=require("./index115.cjs");/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function c(e){return{hash:e,hmac:(r,...t)=>a.hmac(e,r,s.concatBytes(...t)),randomBytes:s.randomBytes}}function u(e,r){const t=n=>o.weierstrass({...e,...c(n)});return{...t(r),create:t}}exports.createCurve=u;exports.getHash=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={ether:-9,wei:9};exports.gweiUnits=e;
package/dist/index106.js CHANGED
@@ -1,19 +1,7 @@
1
- import { hmac as c } from "./index114.js";
2
- import { concatBytes as m, randomBytes as n } from "./index111.js";
3
- import { weierstrass as a } from "./index115.js";
4
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
5
- function i(r) {
6
- return {
7
- hash: r,
8
- hmac: (e, ...t) => c(r, e, m(...t)),
9
- randomBytes: n
10
- };
11
- }
12
- function p(r, e) {
13
- const t = (o) => a({ ...r, ...i(o) });
14
- return { ...t(e), create: t };
15
- }
1
+ const e = {
2
+ ether: -9,
3
+ wei: 9
4
+ };
16
5
  export {
17
- p as createCurve,
18
- i as getHash
6
+ e as gweiUnits
19
7
  };
package/dist/index107.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index116.cjs");/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const d=BigInt(0),c=BigInt(1),w=BigInt(2),j=BigInt(3),E=BigInt(4),S=BigInt(5),I=BigInt(8);function g(t,i){const r=t%i;return r>=d?r:i+r}function L(t,i,r){if(i<d)throw new Error("invalid exponent, negatives unsupported");if(r<=d)throw new Error("invalid modulus");if(r===c)return d;let n=c;for(;i>d;)i&c&&(n=n*t%r),t=t*t%r,i>>=c;return n}function H(t,i,r){let n=t;for(;i-- >d;)n*=n,n%=r;return n}function m(t,i){if(t===d)throw new Error("invert: expected non-zero number");if(i<=d)throw new Error("invert: expected positive modulus, got "+i);let r=g(t,i),n=i,s=d,u=c;for(;r!==d;){const o=n/r,e=n%r,l=s-u*o;n=r,r=e,s=u,u=l}if(n!==c)throw new Error("invert: does not exist");return g(s,i)}function T(t){const i=(t-c)/w;let r,n,s;for(r=t-c,n=0;r%w===d;r/=w,n++);for(s=w;s<t&&L(s,i,t)!==t-c;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const f=(t+c)/E;return function(e,l){const h=e.pow(l,f);if(!e.eql(e.sqr(h),l))throw new Error("Cannot find square root");return h}}const u=(r+c)/w;return function(o,e){if(o.pow(e,i)===o.neg(o.ONE))throw new Error("Cannot find square root");let l=n,h=o.pow(o.mul(o.ONE,s),r),v=o.pow(e,u),q=o.pow(e,r);for(;!o.eql(q,o.ONE);){if(o.eql(q,o.ZERO))return o.ZERO;let b=1;for(let B=o.sqr(q);b<l&&!o.eql(B,o.ONE);b++)B=o.sqr(B);const y=o.pow(h,c<<BigInt(l-b-1));h=o.sqr(y),v=o.mul(v,y),q=o.mul(q,h),l=b}return v}}function x(t){if(t%E===j){const i=(t+c)/E;return function(n,s){const u=n.pow(s,i);if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}if(t%I===S){const i=(t-S)/I;return function(n,s){const u=n.mul(s,w),f=n.pow(u,i),o=n.mul(s,f),e=n.mul(n.mul(o,w),f),l=n.mul(o,n.sub(e,n.ONE));if(!n.eql(n.sqr(l),s))throw new Error("Cannot find square root");return l}}return T(t)}const Z=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function k(t){const i={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Z.reduce((n,s)=>(n[s]="function",n),i);return a.validateObject(t,r)}function M(t,i,r){if(r<d)throw new Error("invalid exponent, negatives unsupported");if(r===d)return t.ONE;if(r===c)return i;let n=t.ONE,s=i;for(;r>d;)r&c&&(n=t.mul(n,s)),s=t.sqr(s),r>>=c;return n}function _(t,i){const r=new Array(i.length),n=i.reduce((u,f,o)=>t.is0(f)?u:(r[o]=u,t.mul(u,f)),t.ONE),s=t.inv(n);return i.reduceRight((u,f,o)=>t.is0(f)?u:(r[o]=t.mul(u,r[o]),t.mul(u,f)),s),r}function p(t,i){const r=i!==void 0?i:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function z(t,i,r=!1,n={}){if(t<=d)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:s,nByteLength:u}=p(t,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const o=Object.freeze({ORDER:t,isLE:r,BITS:s,BYTES:u,MASK:a.bitMask(s),ZERO:d,ONE:c,create:e=>g(e,t),isValid:e=>{if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return d<=e&&e<t},is0:e=>e===d,isOdd:e=>(e&c)===c,neg:e=>g(-e,t),eql:(e,l)=>e===l,sqr:e=>g(e*e,t),add:(e,l)=>g(e+l,t),sub:(e,l)=>g(e-l,t),mul:(e,l)=>g(e*l,t),pow:(e,l)=>M(o,e,l),div:(e,l)=>g(e*m(l,t),t),sqrN:e=>e*e,addN:(e,l)=>e+l,subN:(e,l)=>e-l,mulN:(e,l)=>e*l,inv:e=>m(e,t),sqrt:n.sqrt||(e=>(f||(f=x(t)),f(o,e))),invertBatch:e=>_(o,e),cmov:(e,l,h)=>h?l:e,toBytes:e=>r?a.numberToBytesLE(e,u):a.numberToBytesBE(e,u),fromBytes:e=>{if(e.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+e.length);return r?a.bytesToNumberLE(e):a.bytesToNumberBE(e)}});return Object.freeze(o)}function N(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const i=t.toString(2).length;return Math.ceil(i/8)}function C(t){const i=N(t);return i+Math.ceil(i/2)}function A(t,i,r=!1){const n=t.length,s=N(i),u=C(i);if(n<16||n<u||n>1024)throw new Error("expected "+u+"-1024 bytes of input, got "+n);const f=r?a.bytesToNumberLE(t):a.bytesToNumberBE(t),o=g(f,i-c)+c;return r?a.numberToBytesLE(o,s):a.numberToBytesBE(o,s)}exports.Field=z;exports.FpInvertBatch=_;exports.FpPow=M;exports.FpSqrt=x;exports.getFieldBytesLength=N;exports.getMinHashLength=C;exports.invert=m;exports.mapHashToField=A;exports.mod=g;exports.nLength=p;exports.pow=L;exports.pow2=H;exports.tonelliShanks=T;exports.validateField=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(r,i){let t=r.toString();const n=t.startsWith("-");n&&(t=t.slice(1)),t=t.padStart(i,"0");let[l,e]=[t.slice(0,t.length-i),t.slice(t.length-i)];return e=e.replace(/(0+)$/,""),`${n?"-":""}${l||"0"}${e?`.${e}`:""}`}exports.formatUnits=o;
package/dist/index107.js CHANGED
@@ -1,226 +1,13 @@
1
- import { bitMask as _, numberToBytesLE as S, numberToBytesBE as x, bytesToNumberLE as y, bytesToNumberBE as L, validateObject as M } from "./index116.js";
2
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
- const d = BigInt(0), c = BigInt(1), w = /* @__PURE__ */ BigInt(2), C = /* @__PURE__ */ BigInt(3), b = /* @__PURE__ */ BigInt(4), N = /* @__PURE__ */ BigInt(5), m = /* @__PURE__ */ BigInt(8);
4
- function g(t, i) {
5
- const r = t % i;
6
- return r >= d ? r : i + r;
7
- }
8
- function Z(t, i, r) {
9
- if (i < d)
10
- throw new Error("invalid exponent, negatives unsupported");
11
- if (r <= d)
12
- throw new Error("invalid modulus");
13
- if (r === c)
14
- return d;
15
- let e = c;
16
- for (; i > d; )
17
- i & c && (e = e * t % r), t = t * t % r, i >>= c;
18
- return e;
19
- }
20
- function V(t, i, r) {
21
- let e = t;
22
- for (; i-- > d; )
23
- e *= e, e %= r;
24
- return e;
25
- }
26
- function I(t, i) {
27
- if (t === d)
28
- throw new Error("invert: expected non-zero number");
29
- if (i <= d)
30
- throw new Error("invert: expected positive modulus, got " + i);
31
- let r = g(t, i), e = i, s = d, u = c;
32
- for (; r !== d; ) {
33
- const o = e / r, n = e % r, l = s - u * o;
34
- e = r, r = n, s = u, u = l;
35
- }
36
- if (e !== c)
37
- throw new Error("invert: does not exist");
38
- return g(s, i);
39
- }
40
- function j(t) {
41
- const i = (t - c) / w;
42
- let r, e, s;
43
- for (r = t - c, e = 0; r % w === d; r /= w, e++)
44
- ;
45
- for (s = w; s < t && Z(s, i, t) !== t - c; s++)
46
- if (s > 1e3)
47
- throw new Error("Cannot find square root: likely non-prime P");
48
- if (e === 1) {
49
- const f = (t + c) / b;
50
- return function(n, l) {
51
- const h = n.pow(l, f);
52
- if (!n.eql(n.sqr(h), l))
53
- throw new Error("Cannot find square root");
54
- return h;
55
- };
56
- }
57
- const u = (r + c) / w;
58
- return function(o, n) {
59
- if (o.pow(n, i) === o.neg(o.ONE))
60
- throw new Error("Cannot find square root");
61
- let l = e, h = o.pow(o.mul(o.ONE, s), r), v = o.pow(n, u), a = o.pow(n, r);
62
- for (; !o.eql(a, o.ONE); ) {
63
- if (o.eql(a, o.ZERO))
64
- return o.ZERO;
65
- let q = 1;
66
- for (let B = o.sqr(a); q < l && !o.eql(B, o.ONE); q++)
67
- B = o.sqr(B);
68
- const E = o.pow(h, c << BigInt(l - q - 1));
69
- h = o.sqr(E), v = o.mul(v, E), a = o.mul(a, h), l = q;
70
- }
71
- return v;
72
- };
73
- }
74
- function z(t) {
75
- if (t % b === C) {
76
- const i = (t + c) / b;
77
- return function(e, s) {
78
- const u = e.pow(s, i);
79
- if (!e.eql(e.sqr(u), s))
80
- throw new Error("Cannot find square root");
81
- return u;
82
- };
83
- }
84
- if (t % m === N) {
85
- const i = (t - N) / m;
86
- return function(e, s) {
87
- const u = e.mul(s, w), f = e.pow(u, i), o = e.mul(s, f), n = e.mul(e.mul(o, w), f), l = e.mul(o, e.sub(n, e.ONE));
88
- if (!e.eql(e.sqr(l), s))
89
- throw new Error("Cannot find square root");
90
- return l;
91
- };
92
- }
93
- return j(t);
94
- }
95
- const A = [
96
- "create",
97
- "isValid",
98
- "is0",
99
- "neg",
100
- "inv",
101
- "sqrt",
102
- "sqr",
103
- "eql",
104
- "add",
105
- "sub",
106
- "mul",
107
- "pow",
108
- "div",
109
- "addN",
110
- "subN",
111
- "mulN",
112
- "sqrN"
113
- ];
114
- function Y(t) {
115
- const i = {
116
- ORDER: "bigint",
117
- MASK: "bigint",
118
- BYTES: "isSafeInteger",
119
- BITS: "isSafeInteger"
120
- }, r = A.reduce((e, s) => (e[s] = "function", e), i);
121
- return M(t, r);
122
- }
123
- function k(t, i, r) {
124
- if (r < d)
125
- throw new Error("invalid exponent, negatives unsupported");
126
- if (r === d)
127
- return t.ONE;
128
- if (r === c)
129
- return i;
130
- let e = t.ONE, s = i;
131
- for (; r > d; )
132
- r & c && (e = t.mul(e, s)), s = t.sqr(s), r >>= c;
133
- return e;
134
- }
135
- function H(t, i) {
136
- const r = new Array(i.length), e = i.reduce((u, f, o) => t.is0(f) ? u : (r[o] = u, t.mul(u, f)), t.ONE), s = t.inv(e);
137
- return i.reduceRight((u, f, o) => t.is0(f) ? u : (r[o] = t.mul(u, r[o]), t.mul(u, f)), s), r;
138
- }
139
- function K(t, i) {
140
- const r = i !== void 0 ? i : t.toString(2).length, e = Math.ceil(r / 8);
141
- return { nBitLength: r, nByteLength: e };
142
- }
143
- function p(t, i, r = !1, e = {}) {
144
- if (t <= d)
145
- throw new Error("invalid field: expected ORDER > 0, got " + t);
146
- const { nBitLength: s, nByteLength: u } = K(t, i);
147
- if (u > 2048)
148
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
149
- let f;
150
- const o = Object.freeze({
151
- ORDER: t,
152
- isLE: r,
153
- BITS: s,
154
- BYTES: u,
155
- MASK: _(s),
156
- ZERO: d,
157
- ONE: c,
158
- create: (n) => g(n, t),
159
- isValid: (n) => {
160
- if (typeof n != "bigint")
161
- throw new Error("invalid field element: expected bigint, got " + typeof n);
162
- return d <= n && n < t;
163
- },
164
- is0: (n) => n === d,
165
- isOdd: (n) => (n & c) === c,
166
- neg: (n) => g(-n, t),
167
- eql: (n, l) => n === l,
168
- sqr: (n) => g(n * n, t),
169
- add: (n, l) => g(n + l, t),
170
- sub: (n, l) => g(n - l, t),
171
- mul: (n, l) => g(n * l, t),
172
- pow: (n, l) => k(o, n, l),
173
- div: (n, l) => g(n * I(l, t), t),
174
- // Same as above, but doesn't normalize
175
- sqrN: (n) => n * n,
176
- addN: (n, l) => n + l,
177
- subN: (n, l) => n - l,
178
- mulN: (n, l) => n * l,
179
- inv: (n) => I(n, t),
180
- sqrt: e.sqrt || ((n) => (f || (f = z(t)), f(o, n))),
181
- invertBatch: (n) => H(o, n),
182
- // TODO: do we really need constant cmov?
183
- // We don't have const-time bigints anyway, so probably will be not very useful
184
- cmov: (n, l, h) => h ? l : n,
185
- toBytes: (n) => r ? S(n, u) : x(n, u),
186
- fromBytes: (n) => {
187
- if (n.length !== u)
188
- throw new Error("Field.fromBytes: expected " + u + " bytes, got " + n.length);
189
- return r ? y(n) : L(n);
190
- }
191
- });
192
- return Object.freeze(o);
193
- }
194
- function T(t) {
195
- if (typeof t != "bigint")
196
- throw new Error("field order must be bigint");
197
- const i = t.toString(2).length;
198
- return Math.ceil(i / 8);
199
- }
200
- function O(t) {
201
- const i = T(t);
202
- return i + Math.ceil(i / 2);
203
- }
204
- function G(t, i, r = !1) {
205
- const e = t.length, s = T(i), u = O(i);
206
- if (e < 16 || e < u || e > 1024)
207
- throw new Error("expected " + u + "-1024 bytes of input, got " + e);
208
- const f = r ? y(t) : L(t), o = g(f, i - c) + c;
209
- return r ? S(o, s) : x(o, s);
1
+ function a(r, n) {
2
+ let t = r.toString();
3
+ const i = t.startsWith("-");
4
+ i && (t = t.slice(1)), t = t.padStart(n, "0");
5
+ let [l, e] = [
6
+ t.slice(0, t.length - n),
7
+ t.slice(t.length - n)
8
+ ];
9
+ return e = e.replace(/(0+)$/, ""), `${i ? "-" : ""}${l || "0"}${e ? `.${e}` : ""}`;
210
10
  }
211
11
  export {
212
- p as Field,
213
- H as FpInvertBatch,
214
- k as FpPow,
215
- z as FpSqrt,
216
- T as getFieldBytesLength,
217
- O as getMinHashLength,
218
- I as invert,
219
- G as mapHashToField,
220
- g as mod,
221
- K as nLength,
222
- Z as pow,
223
- V as pow2,
224
- j as tonelliShanks,
225
- Y as validateField
12
+ a as formatUnits
226
13
  };
package/dist/index108.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`Ethereum Signed Message:
2
- `;exports.presignMessagePrefix=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=2n**256n-1n;exports.maxUint256=t;
package/dist/index108.js CHANGED
@@ -1,5 +1,4 @@
1
- const e = `Ethereum Signed Message:
2
- `;
1
+ const n = 2n ** 256n - 1n;
3
2
  export {
4
- e as presignMessagePrefix
3
+ n as maxUint256
5
4
  };
package/dist/index109.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function i(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function o(e,...t){if(!i(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function a(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");r(e.outputLen),r(e.blockLen)}function s(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function u(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}exports.abytes=o;exports.aexists=s;exports.ahash=a;exports.anumber=r;exports.aoutput=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index63.cjs");class t extends o.BaseError{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class i extends o.BaseError{constructor({length:e,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class n extends o.BaseError{constructor({count:e,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}exports.NegativeOffsetError=t;exports.PositionOutOfBoundsError=i;exports.RecursiveReadLimitExceededError=n;
package/dist/index109.js CHANGED
@@ -1,37 +1,23 @@
1
- function n(e) {
2
- if (!Number.isSafeInteger(e) || e < 0)
3
- throw new Error("positive integer expected, got " + e);
1
+ import { BaseError as o } from "./index63.js";
2
+ class i extends o {
3
+ constructor({ offset: e }) {
4
+ super(`Offset \`${e}\` cannot be negative.`, {
5
+ name: "NegativeOffsetError"
6
+ });
7
+ }
4
8
  }
5
- function o(e) {
6
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
9
+ class n extends o {
10
+ constructor({ length: e, position: r }) {
11
+ super(`Position \`${r}\` is out of bounds (\`0 < position < ${e}\`).`, { name: "PositionOutOfBoundsError" });
12
+ }
7
13
  }
8
- function i(e, ...t) {
9
- if (!o(e))
10
- throw new Error("Uint8Array expected");
11
- if (t.length > 0 && !t.includes(e.length))
12
- throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
13
- }
14
- function f(e) {
15
- if (typeof e != "function" || typeof e.create != "function")
16
- throw new Error("Hash should be wrapped by utils.wrapConstructor");
17
- n(e.outputLen), n(e.blockLen);
18
- }
19
- function s(e, t = !0) {
20
- if (e.destroyed)
21
- throw new Error("Hash instance has been destroyed");
22
- if (t && e.finished)
23
- throw new Error("Hash#digest() has already been called");
24
- }
25
- function u(e, t) {
26
- i(e);
27
- const r = t.outputLen;
28
- if (e.length < r)
29
- throw new Error("digestInto() expects output buffer of length at least " + r);
14
+ class c extends o {
15
+ constructor({ count: e, limit: r }) {
16
+ super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${e}\`).`, { name: "RecursiveReadLimitExceededError" });
17
+ }
30
18
  }
31
19
  export {
32
- i as abytes,
33
- s as aexists,
34
- f as ahash,
35
- n as anumber,
36
- u as aoutput
20
+ i as NegativeOffsetError,
21
+ n as PositionOutOfBoundsError,
22
+ c as RecursiveReadLimitExceededError
37
23
  };
package/dist/index11.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index16.cjs"),l=require("@simplewebauthn/browser");class c{constructor(r,t){if(this.storeKey="passkey-auth",!window)throw new Error("Passkey is only supported in the browser environment.");this.url=r.endpoint("passkey"),this.store=t}getPasskeyFromStore(){if(this.token&&this.userName)return e.Ok({token:this.token,gardenUserName:this.userName});const r=this.store.getItem(this.storeKey);if(r){const t=JSON.parse(r);return e.Ok(t)}return e.Err("Passkey is not set")}validateUsername(r){return!r||r.length===0?e.Err("Username cannot be empty"):r.length<3||r.length>32?e.Err("Username must be between 3 and 32 characters"):r.includes(" ")?e.Err("Username cannot contain spaces"):e.Ok(r.trim().toLowerCase())}async register(r){var i;const t=this.validateUsername(r);if(t.error)return e.Err(t.error);try{const n=await e.Fetcher.post(this.url.endpoint("register/begin"),{body:JSON.stringify({username:t}),headers:{credentials:"include","Content-Type":"application/json"}});if(n.error)return e.Err("Failed to start registration",n.error);const s=(i=n.result)==null?void 0:i.challenge;if(!s)return e.Err("No challenge found");if(!s.publicKey.authenticatorSelection)return e.Err("No authenticator selection found");s.publicKey.authenticatorSelection.requireResidentKey=!0,s.publicKey.authenticatorSelection.residentKey="required";const a=await l.startRegistration({optionsJSON:s.publicKey}),o=await e.Fetcher.post(this.url.endpoint("register/finish"),{body:JSON.stringify({username:t,credential:a}),headers:{credentials:"include","Content-Type":"application/json"}});return o.error?e.Err("Failed to verify registration: "+o.error):o.result?(this.token=o.result.token,this.userName=t.val,e.Ok(o.result)):e.Err("No verification result found")}catch(n){return e.Err("Registration error",n)}}async login(r){var i;const t=this.validateUsername(r);if(t.error)return e.Err(t.error);try{const n=await e.Fetcher.post(this.url.endpoint("login/begin"),{body:JSON.stringify({username:t}),headers:{credentials:"include","Content-Type":"application/json"}});if(n.error)return e.Err("Failed to start login",n.error);const s=(i=n.result)==null?void 0:i.challenge;if(!s)return e.Err("No challenge found");const a=await l.startAuthentication({optionsJSON:s.publicKey}),o=await e.Fetcher.post(this.url.endpoint("login/finish"),{body:JSON.stringify({username:t,credential:a}),headers:{credentials:"include","Content-Type":"application/json"}});return o.error?e.Err("Failed to verify login",o.error):o.result?(this.token=o.result.token,this.userName=t.val,e.Ok(o.result)):e.Err("No verification result found")}catch(n){return e.Err("Login error",n)}}async conditionalLogin(){var r,t;try{const i=await e.Fetcher.get(this.url.endpoint("conditional-login/begin"),{headers:{credentials:"include"}});if(i.error)return e.Err("Failed to start login",i.error);const n=(r=i.result)==null?void 0:r.challenge;if(!n)return e.Err("No challenge found");const s=await l.startAuthentication({optionsJSON:n.publicKey}),a=await e.Fetcher.post(this.url.endpoint("conditional-login/finish"),{body:JSON.stringify({login_id:(t=i.result)==null?void 0:t.login_id,credential:s}),headers:{credentials:"include","Content-Type":"application/json"}});return a.error?e.Err("Failed to verify login",a.error):a.result?(this.token=a.result.token,this.userName=a.result.gardenUserName,e.Ok(a.result)):e.Err("No verification result found")}catch(i){return e.Err("Conditional login error",i)}}}exports.PasskeyLogin=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index17.cjs"),o=require("./index8.cjs"),s=require("./index3.cjs");class i{constructor(e){this.token=e}async getToken(){return this.token?this.verifyToken(this.token).ok?t.Ok(this.token):t.Err("Token is invalid"):t.Err("Token is not set")}verifyToken(e){try{const r=s.parseJwt(e);if(!r)return t.Ok(!1);const n=Math.floor(Date.now()/1e3)+120;return t.Ok(r.exp>n)}catch{return t.Ok(!1)}}async getAuthHeaders(){const e=await this.getToken();return e.ok?t.Ok({[o.AuthHeaderEnum.Authorization]:e.val}):t.Err(e.error??"Failed to get auth token")}}exports.Passkey=i;