@argent/x-shared 1.53.1 → 1.54.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("lodash-es"),t=require("starknet"),c=require("zod"),l=c.z.string().refine(e=>{if(e.toLowerCase()===e)return!0;try{return t.validateChecksumAddress(e)&&L(e)}catch{}return!1},"Invalid address (checksum error)"),A=c.z.string().refine(e=>{try{return t.validateAndParseAddress(e)}catch{}return!1},"Invalid address (validation error)"),n=c.z.string().regex(/^0x[0-9a-fA-F]+$/,"Invalid address"),u=n.min(50,"Addresses must at least be 50 characters long").max(66,"Addresses must at most be 66 characters long"),S=n.length(66,"Address must be 66 characters long"),o=u.pipe(l).transform(e=>`0x${(e.startsWith("0x")?e.slice(2):e).padStart(64,"0")}`),g=o.or(c.z.literal("")).transform(e=>e===""?void 0:e).optional(),x=n.transform(e=>`0x${e.replace(/^0x/,"").toLowerCase().padStart(64,"0")}`),h=e=>o.safeParse(e).success,p=h,i=e=>t.getChecksumAddress(e),$=e=>{const s=i(e),r=s.slice(0,2),a=s.slice(2,6),d=s.slice(-4);return`${r}${a}…${d}`},z=e=>{const s=i(e),r=s.slice(0,2),d=s.slice(2).match(/.{1,4}/g)||[];return`${r} ${d.join(" ")}`},L=e=>!/^0x[0-9a-f]{63,64}$/.test(e),f=(e,s)=>{try{return!e||!s?!1:t.num.hexToDecimalString(e)===t.num.hexToDecimalString(s)}catch{}return!1},T=e=>{try{return t.num.toBigInt(n.parse(e))===t.constants.ZERO}catch{}return!1},w=(e,s)=>!!(s!=null&&s.some(r=>f(r,e))),C=m.memoize(e=>{const s=e.slice(0,6),r=e.slice(-4);return`${s}…${r}`}),E=m.memoize((e,s)=>{if(e.length<s)return e;const r=Math.floor((s-1)/2),a=e.slice(0,r),d=e.slice(-r);return`${a}…${d}`});exports.addressOrEmptyUndefinedSchema=g;exports.addressSchema=o;exports.addressSchemaArgentBackend=x;exports.addressSchemaBase=n;exports.addressSchemaLooseLength=u;exports.addressSchemaStrictLength=S;exports.formatFullAddress=z;exports.formatTruncatedAddress=$;exports.formatTruncatedSignerKey=C;exports.formatTruncatedString=E;exports.includesAddress=w;exports.isAddress=h;exports.isEqualAddress=f;exports.isValidAddress=p;exports.isZeroAddress=T;exports.normalizeAddress=i;exports.validChecksumAddressSchema=l;exports.validateAddressRangeSchema=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("lodash-es"),t=require("starknet"),c=require("zod"),S=require("../../utils/base58.cjs"),u=c.z.string().refine(e=>{if(e.toLowerCase()===e)return!0;try{return t.validateChecksumAddress(e)&&T(e)}catch{}return!1},"Invalid address (checksum error)"),g=c.z.string().refine(e=>{try{return t.validateAndParseAddress(e)}catch{}return!1},"Invalid address (validation error)"),n=c.z.string().regex(/^0x[0-9a-fA-F]+$/,"Invalid address"),l=n.min(50,"Addresses must at least be 50 characters long").max(66,"Addresses must at most be 66 characters long"),x=n.length(66,"Address must be 66 characters long"),o=l.pipe(u).transform(e=>`0x${(e.startsWith("0x")?e.slice(2):e).padStart(64,"0")}`),p=o.or(c.z.literal("")).transform(e=>e===""?void 0:e).optional(),$=n.transform(e=>`0x${e.replace(/^0x/,"").toLowerCase().padStart(64,"0")}`),h=e=>o.safeParse(e).success,f=h,i=e=>t.getChecksumAddress(e),z=e=>{if(!e)return!1;try{const s=S.decodeBase58(e);return f(s)}catch{return!1}},L=e=>{const s=i(e),r=s.slice(0,2),a=s.slice(2,6),d=s.slice(-4);return`${r}${a}…${d}`},B=e=>{const s=i(e),r=s.slice(0,2),d=s.slice(2).match(/.{1,4}/g)||[];return`${r} ${d.join(" ")}`},T=e=>!/^0x[0-9a-f]{63,64}$/.test(e),A=(e,s)=>{try{return!e||!s?!1:t.num.hexToDecimalString(e)===t.num.hexToDecimalString(s)}catch{}return!1},w=e=>{try{return t.num.toBigInt(n.parse(e))===t.constants.ZERO}catch{}return!1},C=(e,s)=>!!(s!=null&&s.some(r=>A(r,e))),E=m.memoize(e=>{const s=e.slice(0,6),r=e.slice(-4);return`${s}…${r}`}),P=m.memoize((e,s)=>{if(e.length<s)return e;const r=Math.floor((s-1)/2),a=e.slice(0,r),d=e.slice(-r);return`${a}…${d}`});exports.addressOrEmptyUndefinedSchema=p;exports.addressSchema=o;exports.addressSchemaArgentBackend=$;exports.addressSchemaBase=n;exports.addressSchemaLooseLength=l;exports.addressSchemaStrictLength=x;exports.formatFullAddress=B;exports.formatTruncatedAddress=L;exports.formatTruncatedSignerKey=E;exports.formatTruncatedString=P;exports.includesAddress=C;exports.isAddress=h;exports.isBase58Address=z;exports.isEqualAddress=A;exports.isValidAddress=f;exports.isZeroAddress=w;exports.normalizeAddress=i;exports.validChecksumAddressSchema=u;exports.validateAddressRangeSchema=g;
@@ -13,6 +13,7 @@ export declare const addressSchemaArgentBackend: z.ZodEffects<z.ZodString, `0x${
13
13
  export declare const isAddress: (string?: string) => string is Address;
14
14
  export declare const isValidAddress: (string?: string) => string is Address;
15
15
  export declare const normalizeAddress: (address: string) => Address;
16
+ export declare const isBase58Address: (string?: string) => boolean;
16
17
  export declare const formatTruncatedAddress: (address: string) => string;
17
18
  export declare const formatFullAddress: (address: string) => string;
18
19
  export declare const isEqualAddress: (a?: string, b?: string) => boolean;
@@ -1,64 +1,75 @@
1
1
  import { memoize as a } from "lodash-es";
2
2
  import { validateChecksumAddress as l, validateAndParseAddress as u, getChecksumAddress as f, num as c, constants as h } from "starknet";
3
- import { z as o } from "zod";
4
- const A = o.string().refine((e) => {
3
+ import { z as d } from "zod";
4
+ import { decodeBase58 as A } from "../../utils/base58.js";
5
+ const p = d.string().refine((e) => {
5
6
  if (e.toLowerCase() === e)
6
7
  return !0;
7
8
  try {
8
- return l(e) && g(e);
9
+ return l(e) && $(e);
9
10
  } catch {
10
11
  }
11
12
  return !1;
12
- }, "Invalid address (checksum error)"), C = o.string().refine((e) => {
13
+ }, "Invalid address (checksum error)"), z = d.string().refine((e) => {
13
14
  try {
14
15
  return u(e);
15
16
  } catch {
16
17
  }
17
18
  return !1;
18
- }, "Invalid address (validation error)"), d = o.string().regex(/^0x[0-9a-fA-F]+$/, "Invalid address"), p = d.min(50, "Addresses must at least be 50 characters long").max(66, "Addresses must at most be 66 characters long"), P = d.length(66, "Address must be 66 characters long"), i = p.pipe(A).transform((e) => `0x${(e.startsWith("0x") ? e.slice(2) : e).padStart(64, "0")}`), z = i.or(o.literal("")).transform((e) => e === "" ? void 0 : e).optional(), T = d.transform((e) => `0x${e.replace(/^0x/, "").toLowerCase().padStart(64, "0")}`), x = (e) => i.safeParse(e).success, B = x, m = (e) => f(e), E = (e) => {
19
+ }, "Invalid address (validation error)"), o = d.string().regex(/^0x[0-9a-fA-F]+$/, "Invalid address"), x = o.min(50, "Addresses must at least be 50 characters long").max(66, "Addresses must at most be 66 characters long"), T = o.length(66, "Address must be 66 characters long"), i = x.pipe(p).transform((e) => `0x${(e.startsWith("0x") ? e.slice(2) : e).padStart(64, "0")}`), E = i.or(d.literal("")).transform((e) => e === "" ? void 0 : e).optional(), I = o.transform((e) => `0x${e.replace(/^0x/, "").toLowerCase().padStart(64, "0")}`), S = (e) => i.safeParse(e).success, g = S, m = (e) => f(e), Z = (e) => {
20
+ if (!e)
21
+ return !1;
22
+ try {
23
+ const s = A(e);
24
+ return g(s);
25
+ } catch {
26
+ return !1;
27
+ }
28
+ }, v = (e) => {
19
29
  const s = m(e), r = s.slice(0, 2), n = s.slice(2, 6), t = s.slice(-4);
20
30
  return `${r}${n}…${t}`;
21
- }, I = (e) => {
31
+ }, b = (e) => {
22
32
  const s = m(e), r = s.slice(0, 2), t = s.slice(2).match(/.{1,4}/g) || [];
23
33
  return `${r} ${t.join(" ")}`;
24
- }, g = (e) => !/^0x[0-9a-f]{63,64}$/.test(e), S = (e, s) => {
34
+ }, $ = (e) => !/^0x[0-9a-f]{63,64}$/.test(e), w = (e, s) => {
25
35
  try {
26
36
  return !e || !s ? !1 : c.hexToDecimalString(e) === c.hexToDecimalString(s);
27
37
  } catch {
28
38
  }
29
39
  return !1;
30
- }, Z = (e) => {
40
+ }, k = (e) => {
31
41
  try {
32
- return c.toBigInt(d.parse(e)) === h.ZERO;
42
+ return c.toBigInt(o.parse(e)) === h.ZERO;
33
43
  } catch {
34
44
  }
35
45
  return !1;
36
- }, v = (e, s) => !!(s != null && s.some((r) => S(r, e))), b = a((e) => {
46
+ }, y = (e, s) => !!(s != null && s.some((r) => w(r, e))), D = a((e) => {
37
47
  const s = e.slice(0, 6), r = e.slice(-4);
38
48
  return `${s}…${r}`;
39
- }), k = a((e, s) => {
49
+ }), F = a((e, s) => {
40
50
  if (e.length < s)
41
51
  return e;
42
52
  const r = Math.floor((s - 1) / 2), n = e.slice(0, r), t = e.slice(-r);
43
53
  return `${n}…${t}`;
44
54
  });
45
55
  export {
46
- z as addressOrEmptyUndefinedSchema,
56
+ E as addressOrEmptyUndefinedSchema,
47
57
  i as addressSchema,
48
- T as addressSchemaArgentBackend,
49
- d as addressSchemaBase,
50
- p as addressSchemaLooseLength,
51
- P as addressSchemaStrictLength,
52
- I as formatFullAddress,
53
- E as formatTruncatedAddress,
54
- b as formatTruncatedSignerKey,
55
- k as formatTruncatedString,
56
- v as includesAddress,
57
- x as isAddress,
58
- S as isEqualAddress,
59
- B as isValidAddress,
60
- Z as isZeroAddress,
58
+ I as addressSchemaArgentBackend,
59
+ o as addressSchemaBase,
60
+ x as addressSchemaLooseLength,
61
+ T as addressSchemaStrictLength,
62
+ b as formatFullAddress,
63
+ v as formatTruncatedAddress,
64
+ D as formatTruncatedSignerKey,
65
+ F as formatTruncatedString,
66
+ y as includesAddress,
67
+ S as isAddress,
68
+ Z as isBase58Address,
69
+ w as isEqualAddress,
70
+ g as isValidAddress,
71
+ k as isZeroAddress,
61
72
  m as normalizeAddress,
62
- A as validChecksumAddressSchema,
63
- C as validateAddressRangeSchema
73
+ p as validChecksumAddressSchema,
74
+ z as validateAddressRangeSchema
64
75
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("lodash-es"),a=require("./HttpError.cjs"),d=require("./IHttpService.cjs");class w{constructor(o,t="json"){this.requestInit=o,this.responseType=t}async get(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"GET",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0)});if(this.responseType==="json"){if(!e.ok)throw new a.HttpError(e.statusText,e.status);return await e.json()}return e}async post(o,t,s){const r=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,e={...r,...t,method:"POST",headers:{...r==null?void 0:r.headers,...t==null?void 0:t.headers}},n=await fetch(o,e).catch(()=>{throw new a.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!n.ok)throw new a.HttpError(n.statusText,n.status,await n.json());if(n.status===204)return{};const c=await n.json();if(s)try{return s.parse(c)}catch(i){throw new a.HttpError(i.message,0)}return c}async put(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"PUT",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError("Failed to put url",0)});if(!e.ok)throw new a.HttpError(e.statusText,e.status);return await e.json()}async delete(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"DELETE",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError("Failed to delete url",0)});if(!e.ok)throw new a.HttpError(e.statusText,e.status)}}exports.HTTPService=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es"),n=require("./HttpError.cjs"),d=require("./IHttpService.cjs");class w{constructor(a,t="json"){this.requestInit=a,this.responseType=t}async get(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"GET",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(async o=>{let c;throw o instanceof Response&&(c=await o.json().catch(()=>{})),new n.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0,c)});if(this.responseType==="json"){if(!e.ok)throw new n.HttpError(e.statusText,e.status,await e.json().catch(()=>{}));return await e.json()}return e}async post(a,t,s){const r=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,e={...r,...t,method:"POST",headers:{...r==null?void 0:r.headers,...t==null?void 0:t.headers}},o=await fetch(a,e).catch(()=>{throw new n.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!o.ok)throw new n.HttpError(o.statusText,o.status,await o.json());if(o.status===204)return{};const c=await o.json();if(s)try{return s.parse(c)}catch(h){throw new n.HttpError(h.message,0)}return c}async put(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"PUT",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(()=>{throw new n.HttpError("Failed to put url",0)});if(!e.ok)throw new n.HttpError(e.statusText,e.status);return await e.json()}async delete(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"DELETE",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(()=>{throw new n.HttpError("Failed to delete url",0)});if(!e.ok)throw new n.HttpError(e.statusText,e.status)}}exports.HTTPService=w;
@@ -1,12 +1,12 @@
1
- import { isFunction as n } from "lodash-es";
2
- import { HttpError as r } from "./HttpError.js";
1
+ import { isFunction as c } from "lodash-es";
2
+ import { HttpError as h } from "./HttpError.js";
3
3
  import { HTTP_ERROR_MESSAGE as w } from "./IHttpService.js";
4
4
  class m {
5
- constructor(o, t = "json") {
6
- this.requestInit = o, this.responseType = t;
5
+ constructor(r, t = "json") {
6
+ this.requestInit = r, this.responseType = t;
7
7
  }
8
- async get(o, t) {
9
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
8
+ async get(r, t) {
9
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
10
10
  ...s,
11
11
  ...t,
12
12
  method: "GET",
@@ -15,18 +15,21 @@ class m {
15
15
  ...s == null ? void 0 : s.headers,
16
16
  ...t == null ? void 0 : t.headers
17
17
  }
18
- }, e = await fetch(o, a).catch(() => {
19
- throw new r(w.FAILED_TO_FETCH_URL, 0);
18
+ }, e = await fetch(r, a).catch(async (o) => {
19
+ let n;
20
+ throw o instanceof Response && (n = await o.json().catch(() => {
21
+ })), new h(w.FAILED_TO_FETCH_URL, 0, n);
20
22
  });
21
23
  if (this.responseType === "json") {
22
24
  if (!e.ok)
23
- throw new r(e.statusText, e.status);
25
+ throw new h(e.statusText, e.status, await e.json().catch(() => {
26
+ }));
24
27
  return await e.json();
25
28
  }
26
29
  return e;
27
30
  }
28
- async post(o, t, s) {
29
- const a = n(this.requestInit) ? await this.requestInit() : this.requestInit, e = {
31
+ async post(r, t, s) {
32
+ const a = c(this.requestInit) ? await this.requestInit() : this.requestInit, e = {
30
33
  ...a,
31
34
  ...t,
32
35
  method: "POST",
@@ -35,24 +38,24 @@ class m {
35
38
  ...a == null ? void 0 : a.headers,
36
39
  ...t == null ? void 0 : t.headers
37
40
  }
38
- }, h = await fetch(o, e).catch(() => {
39
- throw new r(w.FAILED_TO_POST_URL, 0);
41
+ }, o = await fetch(r, e).catch(() => {
42
+ throw new h(w.FAILED_TO_POST_URL, 0);
40
43
  });
41
- if (!h.ok)
42
- throw new r(h.statusText, h.status, await h.json());
43
- if (h.status === 204)
44
+ if (!o.ok)
45
+ throw new h(o.statusText, o.status, await o.json());
46
+ if (o.status === 204)
44
47
  return {};
45
- const c = await h.json();
48
+ const n = await o.json();
46
49
  if (s)
47
50
  try {
48
- return s.parse(c);
51
+ return s.parse(n);
49
52
  } catch (i) {
50
- throw new r(i.message, 0);
53
+ throw new h(i.message, 0);
51
54
  }
52
- return c;
55
+ return n;
53
56
  }
54
- async put(o, t) {
55
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
57
+ async put(r, t) {
58
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
56
59
  ...s,
57
60
  ...t,
58
61
  method: "PUT",
@@ -61,15 +64,15 @@ class m {
61
64
  ...s == null ? void 0 : s.headers,
62
65
  ...t == null ? void 0 : t.headers
63
66
  }
64
- }, e = await fetch(o, a).catch(() => {
65
- throw new r("Failed to put url", 0);
67
+ }, e = await fetch(r, a).catch(() => {
68
+ throw new h("Failed to put url", 0);
66
69
  });
67
70
  if (!e.ok)
68
- throw new r(e.statusText, e.status);
71
+ throw new h(e.statusText, e.status);
69
72
  return await e.json();
70
73
  }
71
- async delete(o, t) {
72
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
74
+ async delete(r, t) {
75
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
73
76
  ...s,
74
77
  ...t,
75
78
  method: "DELETE",
@@ -78,11 +81,11 @@ class m {
78
81
  ...s == null ? void 0 : s.headers,
79
82
  ...t == null ? void 0 : t.headers
80
83
  }
81
- }, e = await fetch(o, a).catch(() => {
82
- throw new r("Failed to delete url", 0);
84
+ }, e = await fetch(r, a).catch(() => {
85
+ throw new h("Failed to delete url", 0);
83
86
  });
84
87
  if (!e.ok)
85
- throw new r(e.statusText, e.status);
88
+ throw new h(e.statusText, e.status);
86
89
  }
87
90
  }
88
91
  export {
@@ -1,11 +1,11 @@
1
- import { hex as r, base58 as c } from "@scure/base";
1
+ import { base58 as r, hex as c } from "@scure/base";
2
2
  import { encode as n, num as s } from "starknet";
3
3
  const a = (e) => {
4
- const o = n.removeHexPrefix(n.sanitizeHex(s.toHex(e))), t = r.decode(o);
5
- return c.encode(t);
4
+ const o = n.removeHexPrefix(n.sanitizeHex(s.toHex(e))), t = c.decode(o);
5
+ return r.encode(t);
6
6
  }, m = (e) => e.map(a), d = (e) => {
7
- const o = c.decode(e);
8
- return n.sanitizeHex(r.encode(o));
7
+ const o = r.decode(e);
8
+ return n.sanitizeHex(c.encode(o));
9
9
  }, i = (e) => e.map(d);
10
10
  export {
11
11
  d as decodeBase58,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.53.1",
3
+ "version": "1.54.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"
@@ -44,26 +44,26 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@amplitude/analytics-types": "2.8.4",
47
- "@commitlint/cli": "19.6.0",
47
+ "@commitlint/cli": "19.6.1",
48
48
  "@commitlint/config-conventional": "19.6.0",
49
- "@rollup/plugin-typescript": "12.1.1",
49
+ "@rollup/plugin-typescript": "12.1.2",
50
50
  "@semantic-release/git": "10.0.1",
51
51
  "@types/async-retry": "1.4.9",
52
52
  "@types/lodash-es": "4.17.12",
53
53
  "@types/ua-parser-js": "0.7.39",
54
- "@typescript-eslint/eslint-plugin": "8.16.0",
55
- "@typescript-eslint/parser": "8.16.0",
54
+ "@typescript-eslint/eslint-plugin": "8.18.0",
55
+ "@typescript-eslint/parser": "8.18.0",
56
56
  "eslint": "8.57.1",
57
57
  "eslint-config-prettier": "9.1.0",
58
58
  "eslint-plugin-import": "2.31.0",
59
59
  "husky": "9.1.7",
60
- "lint-staged": "15.2.10",
61
- "msw": "2.6.6",
62
- "prettier": "3.4.1",
60
+ "lint-staged": "15.2.11",
61
+ "msw": "2.6.8",
62
+ "prettier": "3.4.2",
63
63
  "semantic-release": "24.2.0",
64
64
  "ts-to-zod": "3.15.0",
65
65
  "typescript": "5.7.2",
66
- "vite": "6.0.2",
66
+ "vite": "6.0.3",
67
67
  "vite-plugin-dts": "4.3.0",
68
68
  "vitest": "2.1.8"
69
69
  },