@gardenfi/utils 2.0.0 → 2.0.2

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 (103) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +12 -11
  3. package/dist/index11.cjs +1 -1
  4. package/dist/index11.js +186 -92
  5. package/dist/index12.cjs +1 -16
  6. package/dist/index12.js +93 -113
  7. package/dist/index13.cjs +16 -1
  8. package/dist/index13.js +112 -30
  9. package/dist/index14.cjs +1 -1
  10. package/dist/index14.js +18 -17
  11. package/dist/index15.cjs +1 -1
  12. package/dist/index15.js +31 -18
  13. package/dist/index16.cjs +1 -1
  14. package/dist/index16.js +17 -7
  15. package/dist/index17.cjs +1 -1
  16. package/dist/index17.js +6 -19
  17. package/dist/index18.cjs +1 -1
  18. package/dist/index18.js +20 -22
  19. package/dist/index19.cjs +1 -1
  20. package/dist/index19.js +21 -8
  21. package/dist/index20.cjs +1 -1
  22. package/dist/index20.js +8 -31
  23. package/dist/index21.cjs +1 -1
  24. package/dist/index21.js +31 -26
  25. package/dist/index22.cjs +1 -1
  26. package/dist/index22.js +25 -22
  27. package/dist/index23.cjs +1 -1
  28. package/dist/index23.js +22 -50
  29. package/dist/index24.cjs +1 -1
  30. package/dist/index24.js +51 -12
  31. package/dist/index25.cjs +1 -1
  32. package/dist/index25.js +12 -24
  33. package/dist/index26.cjs +1 -1
  34. package/dist/index26.js +24 -75
  35. package/dist/index27.cjs +1 -1
  36. package/dist/index27.js +74 -22
  37. package/dist/index28.cjs +1 -1
  38. package/dist/index28.js +23 -7
  39. package/dist/index29.cjs +1 -1
  40. package/dist/index29.js +7 -29
  41. package/dist/index30.cjs +1 -1
  42. package/dist/index30.js +31 -14
  43. package/dist/index31.cjs +1 -1
  44. package/dist/index31.js +16 -2
  45. package/dist/index32.cjs +1 -1
  46. package/dist/index32.js +2 -9
  47. package/dist/index33.cjs +1 -1
  48. package/dist/index33.js +8 -20
  49. package/dist/index34.cjs +1 -1
  50. package/dist/index34.js +20 -12
  51. package/dist/index35.cjs +1 -1
  52. package/dist/index35.js +10 -32
  53. package/dist/index36.cjs +1 -2
  54. package/dist/index36.js +33 -58
  55. package/dist/index37.cjs +2 -1
  56. package/dist/index37.js +60 -2
  57. package/dist/index38.cjs +1 -1
  58. package/dist/index38.js +2 -5
  59. package/dist/index39.cjs +1 -1
  60. package/dist/index39.js +4 -11
  61. package/dist/index4.cjs +1 -1
  62. package/dist/index4.js +15 -15
  63. package/dist/index40.cjs +1 -1
  64. package/dist/index40.js +11 -3
  65. package/dist/index41.cjs +1 -1
  66. package/dist/index41.js +3 -21
  67. package/dist/index42.cjs +1 -1
  68. package/dist/index42.js +21 -12
  69. package/dist/index43.cjs +1 -1
  70. package/dist/index43.js +11 -54
  71. package/dist/index44.cjs +1 -1
  72. package/dist/index44.js +55 -6
  73. package/dist/index45.cjs +1 -1
  74. package/dist/index45.js +6 -21
  75. package/dist/index46.cjs +1 -1
  76. package/dist/index46.js +21 -11
  77. package/dist/index47.cjs +1 -1
  78. package/dist/index47.js +11 -3
  79. package/dist/index48.cjs +1 -1
  80. package/dist/index48.js +3 -11
  81. package/dist/index49.cjs +1 -1
  82. package/dist/index49.js +11 -19
  83. package/dist/index50.cjs +1 -1
  84. package/dist/index50.js +19 -8
  85. package/dist/index51.cjs +1 -1
  86. package/dist/index51.js +1 -1
  87. package/dist/index52.cjs +1 -1
  88. package/dist/index52.js +8 -104
  89. package/dist/index53.cjs +1 -1
  90. package/dist/index53.js +102 -27
  91. package/dist/index54.cjs +1 -1
  92. package/dist/index54.js +27 -17
  93. package/dist/index55.cjs +1 -1
  94. package/dist/index55.js +16 -30
  95. package/dist/index56.cjs +1 -0
  96. package/dist/index56.js +41 -0
  97. package/dist/index6.cjs +1 -1
  98. package/dist/index6.js +65 -49
  99. package/dist/index9.cjs +1 -1
  100. package/dist/index9.js +6 -6
  101. package/dist/src/lib/auth/auth.types.d.ts +9 -10
  102. package/dist/src/lib/auth/siwe.d.ts +13 -3
  103. package/package.json +2 -4
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.cjs"),e=require("./index3.cjs"),i=require("./index4.cjs"),n=require("./index5.cjs"),r=require("./index6.cjs"),c=require("./index7.cjs"),s=require("./index8.cjs"),t=require("./index9.cjs"),u=require("./index10.cjs");exports.ApiStatus=o.ApiStatus;exports.Authorization=e.Authorization;exports.Environment=e.Environment;exports.Network=e.Network;exports.sleep=e.sleep;exports.with0x=e.with0x;exports.checkAllowanceAndApprove=i.checkAllowanceAndApprove;exports.Url=n.Url;exports.Siwe=r.Siwe;exports.parseJwt=r.parseJwt;exports.MemoryStorage=c.MemoryStorage;exports.StoreKeys=s.StoreKeys;exports.fetchBitcoinBlockNumber=t.fetchBitcoinBlockNumber;exports.fetchEVMBlockNumber=t.fetchEVMBlockNumber;exports.EventBroker=u.EventBroker;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.cjs"),e=require("./index3.cjs"),i=require("./index4.cjs"),n=require("./index5.cjs"),r=require("./index6.cjs"),c=require("./index7.cjs"),s=require("./index8.cjs"),t=require("./index9.cjs"),u=require("./index10.cjs");exports.ApiStatus=o.ApiStatus;exports.Authorization=e.Authorization;exports.Environment=e.Environment;exports.Network=e.Network;exports.sleep=e.sleep;exports.with0x=e.with0x;exports.checkAllowanceAndApprove=i.checkAllowanceAndApprove;exports.Url=n.Url;exports.Auth=r.Auth;exports.Siwe=r.Siwe;exports.parseJwt=r.parseJwt;exports.MemoryStorage=c.MemoryStorage;exports.StoreKeys=s.StoreKeys;exports.fetchBitcoinBlockNumber=t.fetchBitcoinBlockNumber;exports.fetchEVMBlockNumber=t.fetchEVMBlockNumber;exports.EventBroker=u.EventBroker;
package/dist/index.js CHANGED
@@ -1,26 +1,27 @@
1
1
  import { ApiStatus as e } from "./index2.js";
2
2
  import { Authorization as p, Environment as m, Network as f, sleep as x, with0x as c } from "./index3.js";
3
3
  import { checkAllowanceAndApprove as n } from "./index4.js";
4
- import { Url as a } from "./index5.js";
5
- import { Siwe as k, parseJwt as w } from "./index6.js";
4
+ import { Url as l } from "./index5.js";
5
+ import { Auth as a, Siwe as k, parseJwt as u } from "./index6.js";
6
6
  import { MemoryStorage as s } from "./index7.js";
7
- import { StoreKeys as B } from "./index8.js";
8
- import { fetchBitcoinBlockNumber as v, fetchEVMBlockNumber as E } from "./index9.js";
9
- import { EventBroker as b } from "./index10.js";
7
+ import { StoreKeys as S } from "./index8.js";
8
+ import { fetchBitcoinBlockNumber as E, fetchEVMBlockNumber as N } from "./index9.js";
9
+ import { EventBroker as y } from "./index10.js";
10
10
  export {
11
11
  e as ApiStatus,
12
+ a as Auth,
12
13
  p as Authorization,
13
14
  m as Environment,
14
- b as EventBroker,
15
+ y as EventBroker,
15
16
  s as MemoryStorage,
16
17
  f as Network,
17
18
  k as Siwe,
18
- B as StoreKeys,
19
- a as Url,
19
+ S as StoreKeys,
20
+ l as Url,
20
21
  n as checkAllowanceAndApprove,
21
- v as fetchBitcoinBlockNumber,
22
- E as fetchEVMBlockNumber,
23
- w as parseJwt,
22
+ E as fetchBitcoinBlockNumber,
23
+ N as fetchEVMBlockNumber,
24
+ u as parseJwt,
24
25
  x as sleep,
25
26
  c as with0x
26
27
  };
package/dist/index11.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./index16.cjs"),k=require("./index22.cjs"),g=require("./index28.cjs"),O=require("./index29.cjs"),S=require("./index32.cjs"),y=require("./index33.cjs"),$=require("./index31.cjs"),P=require("./index15.cjs"),W=require("./index21.cjs"),q=require("./index24.cjs"),x=require("./index26.cjs");async function z(n,{confirmations:o=1,hash:d,onReplaced:h,pollingInterval:m=n.pollingInterval,retryCount:w=6,retryDelay:R=({count:f})=>~~(1<<f)*200,timeout:N=18e4}){const f=$.stringify(["waitForTransactionReceipt",n.uid,d]);let c,a,e,i=!1;const{promise:B,resolve:F,reject:v}=S.withResolvers(),A=N?setTimeout(()=>v(new k.WaitForTransactionReceiptTimeoutError({hash:d})),N):void 0,j=O.observe(f,{onReplaced:h,resolve:F,reject:v},t=>{const E=g.getAction(n,x.watchBlockNumber,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:m,async onBlockNumber(_){const u=b=>{clearTimeout(A),E(),b(),j()};let l=_;if(!i)try{if(e){if(o>1&&(!e.blockNumber||l-e.blockNumber+1n<o))return;u(()=>t.resolve(e));return}if(c||(i=!0,await y.withRetry(async()=>{c=await g.getAction(n,W.getTransaction,"getTransaction")({hash:d}),c.blockNumber&&(l=c.blockNumber)},{delay:R,retryCount:w}),i=!1),e=await g.getAction(n,q.getTransactionReceipt,"getTransactionReceipt")({hash:d}),o>1&&(!e.blockNumber||l-e.blockNumber+1n<o))return;u(()=>t.resolve(e))}catch(b){if(b instanceof k.TransactionNotFoundError||b instanceof k.TransactionReceiptNotFoundError){if(!c){i=!1;return}try{a=c,i=!0;const p=await y.withRetry(()=>g.getAction(n,P.getBlock,"getBlock")({blockNumber:l,includeTransactions:!0}),{delay:R,retryCount:w,shouldRetry:({error:s})=>s instanceof M.BlockNotFoundError});i=!1;const r=p.transactions.find(({from:s,nonce:I})=>s===a.from&&I===a.nonce);if(!r||(e=await g.getAction(n,q.getTransactionReceipt,"getTransactionReceipt")({hash:r.hash}),o>1&&(!e.blockNumber||l-e.blockNumber+1n<o)))return;let T="replaced";r.to===a.to&&r.value===a.value?T="repriced":r.from===r.to&&r.value===0n&&(T="cancelled"),u(()=>{var s;(s=t.onReplaced)==null||s.call(t,{reason:T,replacedTransaction:a,transaction:r,transactionReceipt:e}),t.resolve(e)})}catch(p){u(()=>t.reject(p))}}else u(()=>t.reject(b))}}})});return B}exports.waitForTransactionReceipt=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var p=(a,t,e)=>{if(!t.has(a))throw TypeError("Cannot "+e)},u=(a,t,e)=>(p(a,t,"read from private field"),e?e.call(a):t.get(a)),w=(a,t,e)=>{if(t.has(a))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(a):t.set(a,e)},f=(a,t,e,r)=>(p(a,t,"write to private field"),t.set(a,e),e);const d=a=>new Promise(t=>setTimeout(t,a));class g{constructor(t,e){this.maxRetries=Math.max(t,0),this.delay=e}async retry(t){let e=0,r;for(;e<this.maxRetries+1;)try{return await t()}catch(s){e++,r=s,await d(this.delay*e)}throw r}}const v=a=>{try{return JSON.parse(a)}catch{return a}};class m{static async _postWithFallback(t,e){let r="";for(const s of t)try{const i=await fetch(s,{method:"POST",...e});if(i.status>=500){r=await(i.text()||i.json());continue}return await this.parse(i)}catch(i){r=y(i);continue}throw new Error(r||"All APIs failed")}static async postWithFallback(t,e){return await n(e).retry(()=>this._postWithFallback(t,e))}static async _getWithFallback(t,e){let r="";for(const s of t)try{const i=await fetch(s,e);if(i.status>=500){r=await(i.text()||i.json());continue}return await this.parse(i)}catch(i){r=y(i);continue}throw new Error(r||"All APIs failed")}static async getWithFallback(t,e){return await n(e).retry(()=>this._getWithFallback(t,e))}static async _get(t,e){return await this.parse(await fetch(t,e))}static async get(t,e){return await n(e).retry(()=>this._get(t,e))}static async _post(t,e){return await this.parse(await fetch(t,{method:"POST",...e}))}static async post(t,e){return await n(e).retry(()=>this._post(t,e))}static async parse(t){const e=await t.text();if(t.status>=200&&t.status<300)return v(e);throw new Error(e)}}function y(a){return(a==null?void 0:a.message)||(a==null?void 0:a.toString())||"unknown error"}const n=a=>new g((a==null?void 0:a.retryCount)??2,(a==null?void 0:a.retryDelay)??1e3);var o,c,l;class h{constructor(t,e,r=void 0){w(this,o,void 0),w(this,c,void 0),w(this,l,void 0),f(this,o,t),f(this,l,r),f(this,c,e)}get ok(){return u(this,o)}get error(){return u(this,l)}get val(){return u(this,c)}}o=new WeakMap,c=new WeakMap,l=new WeakMap;const k=a=>new h(!0,a),W=(a,...t)=>{if(typeof a=="string"&&t&&t.length>0){let e=[a,...t].map(r=>{if(r){if(r instanceof Error)return r.message;if(typeof r=="string")return r;if(r!=null&&r.toString)return r.toString()}});return new h(!1,null,e.filter(r=>r!==void 0).join(" "))}return new h(!1,null,a)};exports.Err=W;exports.Fetcher=m;exports.Ok=k;exports.Result=h;exports.Retry=g;exports.safeParseJson=v;exports.sleep=d;
package/dist/index11.js CHANGED
@@ -1,96 +1,190 @@
1
- import { BlockNotFoundError as A } from "./index16.js";
2
- import { WaitForTransactionReceiptTimeoutError as M, TransactionNotFoundError as O, TransactionReceiptNotFoundError as W } from "./index22.js";
3
- import { getAction as p } from "./index28.js";
4
- import { observe as q } from "./index29.js";
5
- import { withResolvers as z } from "./index32.js";
6
- import { withRetry as v } from "./index33.js";
7
- import { stringify as G } from "./index31.js";
8
- import { getBlock as H } from "./index15.js";
9
- import { getTransaction as J } from "./index21.js";
10
- import { getTransactionReceipt as R } from "./index24.js";
11
- import { watchBlockNumber as K } from "./index26.js";
12
- async function D(o, {
13
- confirmations: n = 1,
14
- hash: m,
15
- onReplaced: y,
16
- pollingInterval: B = o.pollingInterval,
17
- retryCount: k = 6,
18
- retryDelay: N = ({ count: b }) => ~~(1 << b) * 200,
19
- // exponential backoff
20
- timeout: w = 18e4
21
- }) {
22
- const b = G(["waitForTransactionReceipt", o.uid, m]);
23
- let a, c, r, i = !1;
24
- const { promise: h, resolve: F, reject: g } = z(), E = w ? setTimeout(() => g(new M({ hash: m })), w) : void 0, _ = q(b, { onReplaced: y, resolve: F, reject: g }, (e) => {
25
- const j = p(o, K, "watchBlockNumber")({
26
- emitMissed: !0,
27
- emitOnBegin: !0,
28
- poll: !0,
29
- pollingInterval: B,
30
- async onBlockNumber(I) {
31
- const l = (f) => {
32
- clearTimeout(E), j(), f(), _();
33
- };
34
- let u = I;
35
- if (!i)
36
- try {
37
- if (r) {
38
- if (n > 1 && (!r.blockNumber || u - r.blockNumber + 1n < n))
39
- return;
40
- l(() => e.resolve(r));
41
- return;
42
- }
43
- if (a || (i = !0, await v(async () => {
44
- a = await p(o, J, "getTransaction")({ hash: m }), a.blockNumber && (u = a.blockNumber);
45
- }, {
46
- delay: N,
47
- retryCount: k
48
- }), i = !1), r = await p(o, R, "getTransactionReceipt")({ hash: m }), n > 1 && (!r.blockNumber || u - r.blockNumber + 1n < n))
49
- return;
50
- l(() => e.resolve(r));
51
- } catch (f) {
52
- if (f instanceof O || f instanceof W) {
53
- if (!a) {
54
- i = !1;
55
- return;
56
- }
57
- try {
58
- c = a, i = !0;
59
- const d = await v(() => p(o, H, "getBlock")({
60
- blockNumber: u,
61
- includeTransactions: !0
62
- }), {
63
- delay: N,
64
- retryCount: k,
65
- shouldRetry: ({ error: s }) => s instanceof A
66
- });
67
- i = !1;
68
- const t = d.transactions.find(({ from: s, nonce: x }) => s === c.from && x === c.nonce);
69
- if (!t || (r = await p(o, R, "getTransactionReceipt")({
70
- hash: t.hash
71
- }), n > 1 && (!r.blockNumber || u - r.blockNumber + 1n < n)))
72
- return;
73
- let T = "replaced";
74
- t.to === c.to && t.value === c.value ? T = "repriced" : t.from === t.to && t.value === 0n && (T = "cancelled"), l(() => {
75
- var s;
76
- (s = e.onReplaced) == null || s.call(e, {
77
- reason: T,
78
- replacedTransaction: c,
79
- transaction: t,
80
- transactionReceipt: r
81
- }), e.resolve(r);
82
- });
83
- } catch (d) {
84
- l(() => e.reject(d));
85
- }
86
- } else
87
- l(() => e.reject(f));
88
- }
1
+ var p = (e, t, a) => {
2
+ if (!t.has(e))
3
+ throw TypeError("Cannot " + a);
4
+ }, h = (e, t, a) => (p(e, t, "read from private field"), a ? a.call(e) : t.get(e)), u = (e, t, a) => {
5
+ if (t.has(e))
6
+ throw TypeError("Cannot add the same private member more than once");
7
+ t instanceof WeakSet ? t.add(e) : t.set(e, a);
8
+ }, w = (e, t, a, r) => (p(e, t, "write to private field"), t.set(e, a), a);
9
+ const d = (e) => new Promise((t) => setTimeout(t, e));
10
+ class g {
11
+ /**
12
+ * @param {number} maxRetries - The maximum number of retries, if less < 0 then it is set to 0
13
+ * @param {number} delay - The delay between retries
14
+ */
15
+ constructor(t, a) {
16
+ this.maxRetries = Math.max(t, 0), this.delay = a;
17
+ }
18
+ /**
19
+ * Retries a function until it succeeds or the max number of retries is reached
20
+ *
21
+ * @param {() => Promise<T>} fn - The function to retry
22
+ * @return {Promise<T>} a Promise that resolves to the result of the function
23
+ */
24
+ async retry(t) {
25
+ let a = 0, r;
26
+ for (; a < this.maxRetries + 1; )
27
+ try {
28
+ return await t();
29
+ } catch (i) {
30
+ a++, r = i, await d(this.delay * a);
89
31
  }
90
- });
91
- });
92
- return h;
32
+ throw r;
33
+ }
34
+ }
35
+ const v = (e) => {
36
+ try {
37
+ return JSON.parse(e);
38
+ } catch {
39
+ return e;
40
+ }
41
+ };
42
+ class m {
43
+ static async _postWithFallback(t, a) {
44
+ let r = "";
45
+ for (const i of t)
46
+ try {
47
+ const s = await fetch(i, {
48
+ method: "POST",
49
+ ...a
50
+ });
51
+ if (s.status >= 500) {
52
+ r = await (s.text() || s.json());
53
+ continue;
54
+ }
55
+ return await this.parse(s);
56
+ } catch (s) {
57
+ r = y(s);
58
+ continue;
59
+ }
60
+ throw new Error(r || "All APIs failed");
61
+ }
62
+ /**
63
+ * Asynchronously sends a POST request to multiple URLs with fallback logic.
64
+ *
65
+ * @param {string[]} input - array of URLs to send the POST request to
66
+ * @param {RequestInit} [init] - optional request initialization options
67
+ * @return {Promise<T>} a Promise that resolves to the parsed response data
68
+ */
69
+ static async postWithFallback(t, a) {
70
+ return await n(a).retry(
71
+ () => this._postWithFallback(t, a)
72
+ );
73
+ }
74
+ static async _getWithFallback(t, a) {
75
+ let r = "";
76
+ for (const i of t)
77
+ try {
78
+ const s = await fetch(i, a);
79
+ if (s.status >= 500) {
80
+ r = await (s.text() || s.json());
81
+ continue;
82
+ }
83
+ return await this.parse(s);
84
+ } catch (s) {
85
+ r = y(s);
86
+ continue;
87
+ }
88
+ throw new Error(r || "All APIs failed");
89
+ }
90
+ /**
91
+ * Asynchronously sends a POST request to multiple URLs with fallback mechanism.
92
+ *
93
+ * @param {string[]} input - An array of URLs to retrieve data from.
94
+ * @param {RequestInit} [init] - Optional request options.
95
+ * @return {Promise<T>} A promise that resolves to the retrieved data.
96
+ */
97
+ static async getWithFallback(t, a) {
98
+ return await n(a).retry(
99
+ () => this._getWithFallback(t, a)
100
+ );
101
+ }
102
+ static async _get(t, a) {
103
+ return await this.parse(await fetch(t, a));
104
+ }
105
+ /**
106
+ * Asynchronously retrieves data of type T from the specified URL or RequestInfo, with optional initialization options.
107
+ *
108
+ * @param {RequestInfo | URL} input - The URL or RequestInfo to fetch data from
109
+ * @param {RequestInit} init - Optional initialization options for the fetch request
110
+ * @return {Promise<T>} The retrieved data of type T
111
+ */
112
+ static async get(t, a) {
113
+ return await n(a).retry(() => this._get(t, a));
114
+ }
115
+ static async _post(t, a) {
116
+ return await this.parse(
117
+ await fetch(t, {
118
+ method: "POST",
119
+ ...a
120
+ })
121
+ );
122
+ }
123
+ /**
124
+ * Asynchronously sends a POST request to the specified URL or RequestInfo, with optional initialization options.
125
+ */
126
+ static async post(t, a) {
127
+ return await n(a).retry(() => this._post(t, a));
128
+ }
129
+ /**
130
+ * Parses the response and returns the result as the specified type.
131
+ *
132
+ * @param {Response} res - the response object to be parsed
133
+ * @return {Promise<T>} the parsed result of type T
134
+ */
135
+ static async parse(t) {
136
+ const a = await t.text();
137
+ if (t.status >= 200 && t.status < 300)
138
+ return v(a);
139
+ throw new Error(a);
140
+ }
93
141
  }
142
+ function y(e) {
143
+ return (e == null ? void 0 : e.message) || (e == null ? void 0 : e.toString()) || "unknown error";
144
+ }
145
+ const n = (e) => new g((e == null ? void 0 : e.retryCount) ?? 2, (e == null ? void 0 : e.retryDelay) ?? 1e3);
146
+ var o, c, l;
147
+ class f {
148
+ constructor(t, a, r = void 0) {
149
+ u(this, o, void 0), u(this, c, void 0), u(this, l, void 0), w(this, o, t), w(this, l, r), w(this, c, a);
150
+ }
151
+ get ok() {
152
+ return h(this, o);
153
+ }
154
+ get error() {
155
+ return h(this, l);
156
+ }
157
+ get val() {
158
+ return h(this, c);
159
+ }
160
+ }
161
+ o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap();
162
+ const k = (e) => new f(!0, e), W = (e, ...t) => {
163
+ if (typeof e == "string" && t && t.length > 0) {
164
+ let a = [e, ...t].map((r) => {
165
+ if (r) {
166
+ if (r instanceof Error)
167
+ return r.message;
168
+ if (typeof r == "string")
169
+ return r;
170
+ if (r != null && r.toString)
171
+ return r.toString();
172
+ }
173
+ });
174
+ return new f(
175
+ !1,
176
+ null,
177
+ a.filter((r) => r !== void 0).join(" ")
178
+ );
179
+ }
180
+ return new f(!1, null, e);
181
+ };
94
182
  export {
95
- D as waitForTransactionReceipt
183
+ W as Err,
184
+ m as Fetcher,
185
+ k as Ok,
186
+ f as Result,
187
+ g as Retry,
188
+ v as safeParseJson,
189
+ d as sleep
96
190
  };
package/dist/index12.cjs CHANGED
@@ -1,16 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index48.cjs"),M=require("./index41.cjs"),h=require("./index49.cjs");function R(r){const{chainId:o,domain:s,expirationTime:l,issuedAt:m=new Date,nonce:a,notBefore:f,requestId:w,resources:g,scheme:i,uri:c,version:d}=r;{if(o!==Math.floor(o))throw new e.SiweInvalidMessageFieldError({field:"chainId",metaMessages:["- Chain ID must be a EIP-155 chain ID.","- See https://eips.ethereum.org/EIPS/eip-155","",`Provided value: ${o}`]});if(!(E.test(s)||F.test(s)||b.test(s)))throw new e.SiweInvalidMessageFieldError({field:"domain",metaMessages:["- Domain must be an RFC 3986 authority.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${s}`]});if(!A.test(a))throw new e.SiweInvalidMessageFieldError({field:"nonce",metaMessages:["- Nonce must be at least 8 characters.","- Nonce must be alphanumeric.","",`Provided value: ${a}`]});if(!h.isUri(c))throw new e.SiweInvalidMessageFieldError({field:"uri",metaMessages:["- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${c}`]});if(d!=="1")throw new e.SiweInvalidMessageFieldError({field:"version",metaMessages:["- Version must be '1'.","",`Provided value: ${d}`]});if(i&&!P.test(i))throw new e.SiweInvalidMessageFieldError({field:"scheme",metaMessages:["- Scheme must be an RFC 3986 URI scheme.","- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1","",`Provided value: ${i}`]});const t=r.statement;if(t!=null&&t.includes(`
2
- `))throw new e.SiweInvalidMessageFieldError({field:"statement",metaMessages:["- Statement must not include '\\n'.","",`Provided value: ${t}`]})}const $=M.getAddress(r.address),v=i?`${i}://${s}`:s,I=r.statement?`${r.statement}
3
- `:"",S=`${v} wants you to sign in with your Ethereum account:
4
- ${$}
5
-
6
- ${I}`;let n=`URI: ${c}
7
- Version: ${d}
8
- Chain ID: ${o}
9
- Nonce: ${a}
10
- Issued At: ${m.toISOString()}`;if(l&&(n+=`
11
- Expiration Time: ${l.toISOString()}`),f&&(n+=`
12
- Not Before: ${f.toISOString()}`),w&&(n+=`
13
- Request ID: ${w}`),g){let t=`
14
- Resources:`;for(const u of g){if(!h.isUri(u))throw new e.SiweInvalidMessageFieldError({field:"resources",metaMessages:["- Every resource must be a RFC 3986 URI.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${u}`]});t+=`
15
- - ${u}`}n+=t}return`${S}
16
- ${n}`}const E=/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/,F=/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/,b=/^localhost(:[0-9]{1,5})?$/,A=/^[a-zA-Z0-9]{8,}$/,P=/^([a-zA-Z][a-zA-Z0-9+-.]*)$/;exports.createSiweMessage=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./index17.cjs"),k=require("./index23.cjs"),g=require("./index29.cjs"),O=require("./index30.cjs"),S=require("./index33.cjs"),y=require("./index34.cjs"),$=require("./index32.cjs"),P=require("./index16.cjs"),W=require("./index22.cjs"),q=require("./index25.cjs"),x=require("./index27.cjs");async function z(n,{confirmations:c=1,hash:p,onReplaced:h,pollingInterval:m=n.pollingInterval,retryCount:w=6,retryDelay:R=({count:d})=>~~(1<<d)*200,timeout:N=18e4}){const d=$.stringify(["waitForTransactionReceipt",n.uid,p]);let a,o,e,i=!1;const{promise:B,resolve:F,reject:v}=S.withResolvers(),A=N?setTimeout(()=>v(new k.WaitForTransactionReceiptTimeoutError({hash:p})),N):void 0,j=O.observe(d,{onReplaced:h,resolve:F,reject:v},r=>{const E=g.getAction(n,x.watchBlockNumber,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:m,async onBlockNumber(_){const u=b=>{clearTimeout(A),E(),b(),j()};let l=_;if(!i)try{if(e){if(c>1&&(!e.blockNumber||l-e.blockNumber+1n<c))return;u(()=>r.resolve(e));return}if(a||(i=!0,await y.withRetry(async()=>{a=await g.getAction(n,W.getTransaction,"getTransaction")({hash:p}),a.blockNumber&&(l=a.blockNumber)},{delay:R,retryCount:w}),i=!1),e=await g.getAction(n,q.getTransactionReceipt,"getTransactionReceipt")({hash:p}),c>1&&(!e.blockNumber||l-e.blockNumber+1n<c))return;u(()=>r.resolve(e))}catch(b){if(b instanceof k.TransactionNotFoundError||b instanceof k.TransactionReceiptNotFoundError){if(!a){i=!1;return}try{o=a,i=!0;const f=await y.withRetry(()=>g.getAction(n,P.getBlock,"getBlock")({blockNumber:l,includeTransactions:!0}),{delay:R,retryCount:w,shouldRetry:({error:s})=>s instanceof M.BlockNotFoundError});i=!1;const t=f.transactions.find(({from:s,nonce:I})=>s===o.from&&I===o.nonce);if(!t||(e=await g.getAction(n,q.getTransactionReceipt,"getTransactionReceipt")({hash:t.hash}),c>1&&(!e.blockNumber||l-e.blockNumber+1n<c)))return;let T="replaced";t.to===o.to&&t.value===o.value&&t.input===o.input?T="repriced":t.from===t.to&&t.value===0n&&(T="cancelled"),u(()=>{var s;(s=r.onReplaced)==null||s.call(r,{reason:T,replacedTransaction:o,transaction:t,transactionReceipt:e}),r.resolve(e)})}catch(f){u(()=>r.reject(f))}}else u(()=>r.reject(b))}}})});return B}exports.waitForTransactionReceipt=z;
package/dist/index12.js CHANGED
@@ -1,116 +1,96 @@
1
- import { SiweInvalidMessageFieldError as e } from "./index48.js";
2
- import { getAddress as S } from "./index41.js";
3
- import { isUri as $ } from "./index49.js";
4
- function C(n) {
5
- const { chainId: i, domain: s, expirationTime: u, issuedAt: g = /* @__PURE__ */ new Date(), nonce: a, notBefore: m, requestId: h, resources: w, scheme: o, uri: c, version: f } = n;
6
- {
7
- if (i !== Math.floor(i))
8
- throw new e({
9
- field: "chainId",
10
- metaMessages: [
11
- "- Chain ID must be a EIP-155 chain ID.",
12
- "- See https://eips.ethereum.org/EIPS/eip-155",
13
- "",
14
- `Provided value: ${i}`
15
- ]
16
- });
17
- if (!(p.test(s) || M.test(s) || x.test(s)))
18
- throw new e({
19
- field: "domain",
20
- metaMessages: [
21
- "- Domain must be an RFC 3986 authority.",
22
- "- See https://www.rfc-editor.org/rfc/rfc3986",
23
- "",
24
- `Provided value: ${s}`
25
- ]
26
- });
27
- if (!A.test(a))
28
- throw new e({
29
- field: "nonce",
30
- metaMessages: [
31
- "- Nonce must be at least 8 characters.",
32
- "- Nonce must be alphanumeric.",
33
- "",
34
- `Provided value: ${a}`
35
- ]
36
- });
37
- if (!$(c))
38
- throw new e({
39
- field: "uri",
40
- metaMessages: [
41
- "- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.",
42
- "- See https://www.rfc-editor.org/rfc/rfc3986",
43
- "",
44
- `Provided value: ${c}`
45
- ]
46
- });
47
- if (f !== "1")
48
- throw new e({
49
- field: "version",
50
- metaMessages: [
51
- "- Version must be '1'.",
52
- "",
53
- `Provided value: ${f}`
54
- ]
55
- });
56
- if (o && !P.test(o))
57
- throw new e({
58
- field: "scheme",
59
- metaMessages: [
60
- "- Scheme must be an RFC 3986 URI scheme.",
61
- "- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1",
62
- "",
63
- `Provided value: ${o}`
64
- ]
65
- });
66
- const t = n.statement;
67
- if (t != null && t.includes(`
68
- `))
69
- throw new e({
70
- field: "statement",
71
- metaMessages: [
72
- "- Statement must not include '\\n'.",
73
- "",
74
- `Provided value: ${t}`
75
- ]
76
- });
77
- }
78
- const l = S(n.address), v = o ? `${o}://${s}` : s, I = n.statement ? `${n.statement}
79
- ` : "", R = `${v} wants you to sign in with your Ethereum account:
80
- ${l}
81
-
82
- ${I}`;
83
- let r = `URI: ${c}
84
- Version: ${f}
85
- Chain ID: ${i}
86
- Nonce: ${a}
87
- Issued At: ${g.toISOString()}`;
88
- if (u && (r += `
89
- Expiration Time: ${u.toISOString()}`), m && (r += `
90
- Not Before: ${m.toISOString()}`), h && (r += `
91
- Request ID: ${h}`), w) {
92
- let t = `
93
- Resources:`;
94
- for (const d of w) {
95
- if (!$(d))
96
- throw new e({
97
- field: "resources",
98
- metaMessages: [
99
- "- Every resource must be a RFC 3986 URI.",
100
- "- See https://www.rfc-editor.org/rfc/rfc3986",
101
- "",
102
- `Provided value: ${d}`
103
- ]
104
- });
105
- t += `
106
- - ${d}`;
107
- }
108
- r += t;
109
- }
110
- return `${R}
111
- ${r}`;
1
+ import { BlockNotFoundError as A } from "./index17.js";
2
+ import { WaitForTransactionReceiptTimeoutError as M, TransactionNotFoundError as O, TransactionReceiptNotFoundError as W } from "./index23.js";
3
+ import { getAction as f } from "./index29.js";
4
+ import { observe as q } from "./index30.js";
5
+ import { withResolvers as z } from "./index33.js";
6
+ import { withRetry as v } from "./index34.js";
7
+ import { stringify as G } from "./index32.js";
8
+ import { getBlock as H } from "./index16.js";
9
+ import { getTransaction as J } from "./index22.js";
10
+ import { getTransactionReceipt as R } from "./index25.js";
11
+ import { watchBlockNumber as K } from "./index27.js";
12
+ async function D(o, {
13
+ confirmations: a = 1,
14
+ hash: m,
15
+ onReplaced: y,
16
+ pollingInterval: B = o.pollingInterval,
17
+ retryCount: k = 6,
18
+ retryDelay: N = ({ count: b }) => ~~(1 << b) * 200,
19
+ // exponential backoff
20
+ timeout: w = 18e4
21
+ }) {
22
+ const b = G(["waitForTransactionReceipt", o.uid, m]);
23
+ let c, n, r, i = !1;
24
+ const { promise: h, resolve: F, reject: g } = z(), E = w ? setTimeout(() => g(new M({ hash: m })), w) : void 0, _ = q(b, { onReplaced: y, resolve: F, reject: g }, (t) => {
25
+ const j = f(o, K, "watchBlockNumber")({
26
+ emitMissed: !0,
27
+ emitOnBegin: !0,
28
+ poll: !0,
29
+ pollingInterval: B,
30
+ async onBlockNumber(I) {
31
+ const l = (p) => {
32
+ clearTimeout(E), j(), p(), _();
33
+ };
34
+ let u = I;
35
+ if (!i)
36
+ try {
37
+ if (r) {
38
+ if (a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a))
39
+ return;
40
+ l(() => t.resolve(r));
41
+ return;
42
+ }
43
+ if (c || (i = !0, await v(async () => {
44
+ c = await f(o, J, "getTransaction")({ hash: m }), c.blockNumber && (u = c.blockNumber);
45
+ }, {
46
+ delay: N,
47
+ retryCount: k
48
+ }), i = !1), r = await f(o, R, "getTransactionReceipt")({ hash: m }), a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a))
49
+ return;
50
+ l(() => t.resolve(r));
51
+ } catch (p) {
52
+ if (p instanceof O || p instanceof W) {
53
+ if (!c) {
54
+ i = !1;
55
+ return;
56
+ }
57
+ try {
58
+ n = c, i = !0;
59
+ const d = await v(() => f(o, H, "getBlock")({
60
+ blockNumber: u,
61
+ includeTransactions: !0
62
+ }), {
63
+ delay: N,
64
+ retryCount: k,
65
+ shouldRetry: ({ error: s }) => s instanceof A
66
+ });
67
+ i = !1;
68
+ const e = d.transactions.find(({ from: s, nonce: x }) => s === n.from && x === n.nonce);
69
+ if (!e || (r = await f(o, R, "getTransactionReceipt")({
70
+ hash: e.hash
71
+ }), a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a)))
72
+ return;
73
+ let T = "replaced";
74
+ e.to === n.to && e.value === n.value && e.input === n.input ? T = "repriced" : e.from === e.to && e.value === 0n && (T = "cancelled"), l(() => {
75
+ var s;
76
+ (s = t.onReplaced) == null || s.call(t, {
77
+ reason: T,
78
+ replacedTransaction: n,
79
+ transaction: e,
80
+ transactionReceipt: r
81
+ }), t.resolve(r);
82
+ });
83
+ } catch (d) {
84
+ l(() => t.reject(d));
85
+ }
86
+ } else
87
+ l(() => t.reject(p));
88
+ }
89
+ }
90
+ });
91
+ });
92
+ return h;
112
93
  }
113
- const p = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/, M = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/, x = /^localhost(:[0-9]{1,5})?$/, A = /^[a-zA-Z0-9]{8,}$/, P = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
114
94
  export {
115
- C as createSiweMessage
95
+ D as waitForTransactionReceipt
116
96
  };
package/dist/index13.cjs CHANGED
@@ -1 +1,16 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index50.cjs"),a=e.defineChain({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}});exports.mainnet=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index49.cjs"),M=require("./index42.cjs"),h=require("./index50.cjs");function R(r){const{chainId:o,domain:s,expirationTime:l,issuedAt:m=new Date,nonce:a,notBefore:f,requestId:w,resources:g,scheme:i,uri:c,version:d}=r;{if(o!==Math.floor(o))throw new e.SiweInvalidMessageFieldError({field:"chainId",metaMessages:["- Chain ID must be a EIP-155 chain ID.","- See https://eips.ethereum.org/EIPS/eip-155","",`Provided value: ${o}`]});if(!(E.test(s)||F.test(s)||b.test(s)))throw new e.SiweInvalidMessageFieldError({field:"domain",metaMessages:["- Domain must be an RFC 3986 authority.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${s}`]});if(!A.test(a))throw new e.SiweInvalidMessageFieldError({field:"nonce",metaMessages:["- Nonce must be at least 8 characters.","- Nonce must be alphanumeric.","",`Provided value: ${a}`]});if(!h.isUri(c))throw new e.SiweInvalidMessageFieldError({field:"uri",metaMessages:["- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${c}`]});if(d!=="1")throw new e.SiweInvalidMessageFieldError({field:"version",metaMessages:["- Version must be '1'.","",`Provided value: ${d}`]});if(i&&!P.test(i))throw new e.SiweInvalidMessageFieldError({field:"scheme",metaMessages:["- Scheme must be an RFC 3986 URI scheme.","- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1","",`Provided value: ${i}`]});const t=r.statement;if(t!=null&&t.includes(`
2
+ `))throw new e.SiweInvalidMessageFieldError({field:"statement",metaMessages:["- Statement must not include '\\n'.","",`Provided value: ${t}`]})}const $=M.getAddress(r.address),v=i?`${i}://${s}`:s,I=r.statement?`${r.statement}
3
+ `:"",S=`${v} wants you to sign in with your Ethereum account:
4
+ ${$}
5
+
6
+ ${I}`;let n=`URI: ${c}
7
+ Version: ${d}
8
+ Chain ID: ${o}
9
+ Nonce: ${a}
10
+ Issued At: ${m.toISOString()}`;if(l&&(n+=`
11
+ Expiration Time: ${l.toISOString()}`),f&&(n+=`
12
+ Not Before: ${f.toISOString()}`),w&&(n+=`
13
+ Request ID: ${w}`),g){let t=`
14
+ Resources:`;for(const u of g){if(!h.isUri(u))throw new e.SiweInvalidMessageFieldError({field:"resources",metaMessages:["- Every resource must be a RFC 3986 URI.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${u}`]});t+=`
15
+ - ${u}`}n+=t}return`${S}
16
+ ${n}`}const E=/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/,F=/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/,b=/^localhost(:[0-9]{1,5})?$/,A=/^[a-zA-Z0-9]{8,}$/,P=/^([a-zA-Z][a-zA-Z0-9+-.]*)$/;exports.createSiweMessage=R;