starknet 5.22.0 → 5.23.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.
@@ -83,6 +83,9 @@ var starknet = (() => {
83
83
  }, this);
84
84
  } else if (Array.isArray(headers)) {
85
85
  headers.forEach(function(header) {
86
+ if (header.length != 2) {
87
+ throw new TypeError("Headers constructor: expected name/value pair to be length 2, found" + header.length);
88
+ }
86
89
  this.append(header[0], header[1]);
87
90
  }, this);
88
91
  } else if (headers) {
@@ -92,6 +95,8 @@ var starknet = (() => {
92
95
  }
93
96
  }
94
97
  function consumed(body) {
98
+ if (body._noBody)
99
+ return;
95
100
  if (body.bodyUsed) {
96
101
  return Promise.reject(new TypeError("Already read"));
97
102
  }
@@ -116,7 +121,9 @@ var starknet = (() => {
116
121
  function readBlobAsText(blob) {
117
122
  var reader = new FileReader();
118
123
  var promise = fileReaderReady(reader);
119
- reader.readAsText(blob);
124
+ var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
125
+ var encoding = match ? match[1] : "utf-8";
126
+ reader.readAsText(blob, encoding);
120
127
  return promise;
121
128
  }
122
129
  function readArrayBufferAsText(buf) {
@@ -142,6 +149,7 @@ var starknet = (() => {
142
149
  this.bodyUsed = this.bodyUsed;
143
150
  this._bodyInit = body;
144
151
  if (!body) {
152
+ this._noBody = true;
145
153
  this._bodyText = "";
146
154
  } else if (typeof body === "string") {
147
155
  this._bodyText = body;
@@ -185,27 +193,28 @@ var starknet = (() => {
185
193
  return Promise.resolve(new Blob([this._bodyText]));
186
194
  }
187
195
  };
188
- this.arrayBuffer = function() {
189
- if (this._bodyArrayBuffer) {
190
- var isConsumed = consumed(this);
191
- if (isConsumed) {
192
- return isConsumed;
193
- }
194
- if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
195
- return Promise.resolve(
196
- this._bodyArrayBuffer.buffer.slice(
197
- this._bodyArrayBuffer.byteOffset,
198
- this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
199
- )
200
- );
201
- } else {
202
- return Promise.resolve(this._bodyArrayBuffer);
203
- }
196
+ }
197
+ this.arrayBuffer = function() {
198
+ if (this._bodyArrayBuffer) {
199
+ var isConsumed = consumed(this);
200
+ if (isConsumed) {
201
+ return isConsumed;
202
+ } else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
203
+ return Promise.resolve(
204
+ this._bodyArrayBuffer.buffer.slice(
205
+ this._bodyArrayBuffer.byteOffset,
206
+ this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
207
+ )
208
+ );
204
209
  } else {
205
- return this.blob().then(readBlobAsArrayBuffer);
210
+ return Promise.resolve(this._bodyArrayBuffer);
206
211
  }
207
- };
208
- }
212
+ } else if (support.blob) {
213
+ return this.blob().then(readBlobAsArrayBuffer);
214
+ } else {
215
+ throw new Error("could not read as ArrayBuffer");
216
+ }
217
+ };
209
218
  this.text = function() {
210
219
  var rejected = consumed(this);
211
220
  if (rejected) {
@@ -266,7 +275,12 @@ var starknet = (() => {
266
275
  }
267
276
  this.method = normalizeMethod(options.method || this.method || "GET");
268
277
  this.mode = options.mode || this.mode || null;
269
- this.signal = options.signal || this.signal;
278
+ this.signal = options.signal || this.signal || function() {
279
+ if ("AbortController" in g) {
280
+ var ctrl = new AbortController();
281
+ return ctrl.signal;
282
+ }
283
+ }();
270
284
  this.referrer = null;
271
285
  if ((this.method === "GET" || this.method === "HEAD") && body) {
272
286
  throw new TypeError("Body not allowed for GET or HEAD requests");
@@ -306,7 +320,11 @@ var starknet = (() => {
306
320
  var key = parts.shift().trim();
307
321
  if (key) {
308
322
  var value = parts.join(":").trim();
309
- headers.append(key, value);
323
+ try {
324
+ headers.append(key, value);
325
+ } catch (error) {
326
+ console.warn("Response " + error.message);
327
+ }
310
328
  }
311
329
  });
312
330
  return headers;
@@ -320,6 +338,9 @@ var starknet = (() => {
320
338
  }
321
339
  this.type = "default";
322
340
  this.status = options.status === void 0 ? 200 : options.status;
341
+ if (this.status < 200 || this.status > 599) {
342
+ throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");
343
+ }
323
344
  this.ok = this.status >= 200 && this.status < 300;
324
345
  this.statusText = options.statusText === void 0 ? "" : "" + options.statusText;
325
346
  this.headers = new Headers(options.headers);
@@ -338,10 +359,14 @@ var starknet = (() => {
338
359
  }
339
360
  xhr.onload = function() {
340
361
  var options = {
341
- status: xhr.status,
342
362
  statusText: xhr.statusText,
343
363
  headers: parseHeaders(xhr.getAllResponseHeaders() || "")
344
364
  };
365
+ if (request.url.startsWith("file://") && (xhr.status < 200 || xhr.status > 599)) {
366
+ options.status = 200;
367
+ } else {
368
+ options.status = xhr.status;
369
+ }
345
370
  options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
346
371
  var body = "response" in xhr ? xhr.response : xhr.responseText;
347
372
  setTimeout(function() {
@@ -355,7 +380,7 @@ var starknet = (() => {
355
380
  };
356
381
  xhr.ontimeout = function() {
357
382
  setTimeout(function() {
358
- reject(new TypeError("Network request failed"));
383
+ reject(new TypeError("Network request timed out"));
359
384
  }, 0);
360
385
  };
361
386
  xhr.onabort = function() {
@@ -365,7 +390,7 @@ var starknet = (() => {
365
390
  };
366
391
  function fixUrl(url) {
367
392
  try {
368
- return url === "" && global2.location.href ? global2.location.href : url;
393
+ return url === "" && g.location.href ? g.location.href : url;
369
394
  } catch (e) {
370
395
  return url;
371
396
  }
@@ -379,14 +404,21 @@ var starknet = (() => {
379
404
  if ("responseType" in xhr) {
380
405
  if (support.blob) {
381
406
  xhr.responseType = "blob";
382
- } else if (support.arrayBuffer && request.headers.get("Content-Type") && request.headers.get("Content-Type").indexOf("application/octet-stream") !== -1) {
407
+ } else if (support.arrayBuffer) {
383
408
  xhr.responseType = "arraybuffer";
384
409
  }
385
410
  }
386
- if (init && typeof init.headers === "object" && !(init.headers instanceof Headers)) {
411
+ if (init && typeof init.headers === "object" && !(init.headers instanceof Headers || g.Headers && init.headers instanceof g.Headers)) {
412
+ var names = [];
387
413
  Object.getOwnPropertyNames(init.headers).forEach(function(name) {
414
+ names.push(normalizeName(name));
388
415
  xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
389
416
  });
417
+ request.headers.forEach(function(value, name) {
418
+ if (names.indexOf(name) === -1) {
419
+ xhr.setRequestHeader(name, value);
420
+ }
421
+ });
390
422
  } else {
391
423
  request.headers.forEach(function(value, name) {
392
424
  xhr.setRequestHeader(name, value);
@@ -403,14 +435,15 @@ var starknet = (() => {
403
435
  xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
404
436
  });
405
437
  }
406
- var global2, support, viewClasses, isArrayBufferView, methods, redirectStatuses, DOMException;
438
+ var g, support, viewClasses, isArrayBufferView, methods, redirectStatuses, DOMException;
407
439
  var init_fetch = __esm({
408
440
  "node_modules/whatwg-fetch/fetch.js"() {
409
- global2 = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || typeof global2 !== "undefined" && global2;
441
+ g = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || // eslint-disable-next-line no-undef
442
+ typeof global !== "undefined" && global || {};
410
443
  support = {
411
- searchParams: "URLSearchParams" in global2,
412
- iterable: "Symbol" in global2 && "iterator" in Symbol,
413
- blob: "FileReader" in global2 && "Blob" in global2 && function() {
444
+ searchParams: "URLSearchParams" in g,
445
+ iterable: "Symbol" in g && "iterator" in Symbol,
446
+ blob: "FileReader" in g && "Blob" in g && function() {
414
447
  try {
415
448
  new Blob();
416
449
  return true;
@@ -418,8 +451,8 @@ var starknet = (() => {
418
451
  return false;
419
452
  }
420
453
  }(),
421
- formData: "FormData" in global2,
422
- arrayBuffer: "ArrayBuffer" in global2
454
+ formData: "FormData" in g,
455
+ arrayBuffer: "ArrayBuffer" in g
423
456
  };
424
457
  if (support.arrayBuffer) {
425
458
  viewClasses = [
@@ -487,7 +520,7 @@ var starknet = (() => {
487
520
  if (support.iterable) {
488
521
  Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
489
522
  }
490
- methods = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
523
+ methods = ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"];
491
524
  Request.prototype.clone = function() {
492
525
  return new Request(this, { body: this._bodyInit });
493
526
  };
@@ -502,7 +535,8 @@ var starknet = (() => {
502
535
  });
503
536
  };
504
537
  Response.error = function() {
505
- var response = new Response(null, { status: 0, statusText: "" });
538
+ var response = new Response(null, { status: 200, statusText: "" });
539
+ response.status = 0;
506
540
  response.type = "error";
507
541
  return response;
508
542
  };
@@ -513,7 +547,7 @@ var starknet = (() => {
513
547
  }
514
548
  return new Response(null, { status, headers: { location: url } });
515
549
  };
516
- DOMException = global2.DOMException;
550
+ DOMException = g.DOMException;
517
551
  try {
518
552
  new DOMException();
519
553
  } catch (err2) {
@@ -527,11 +561,11 @@ var starknet = (() => {
527
561
  DOMException.prototype.constructor = DOMException;
528
562
  }
529
563
  fetch.polyfill = true;
530
- if (!global2.fetch) {
531
- global2.fetch = fetch;
532
- global2.Headers = Headers;
533
- global2.Request = Request;
534
- global2.Response = Response;
564
+ if (!g.fetch) {
565
+ g.fetch = fetch;
566
+ g.Headers = Headers;
567
+ g.Request = Request;
568
+ g.Response = Response;
535
569
  }
536
570
  }
537
571
  });
@@ -555,7 +589,7 @@ var starknet = (() => {
555
589
  else
556
590
  context[name] = definition();
557
591
  })("urljoin", exports, function() {
558
- function normalize(strArray) {
592
+ function normalize2(strArray) {
559
593
  var resultArray = [];
560
594
  if (strArray.length === 0) {
561
595
  return "";
@@ -603,7 +637,7 @@ var starknet = (() => {
603
637
  } else {
604
638
  input = [].slice.call(arguments);
605
639
  }
606
- return normalize(input);
640
+ return normalize2(input);
607
641
  };
608
642
  });
609
643
  }
@@ -660,6 +694,7 @@ var starknet = (() => {
660
694
  fixStack: () => fixStack,
661
695
  getCalldata: () => getCalldata,
662
696
  getChecksumAddress: () => getChecksumAddress,
697
+ getDefaultNodeUrl: () => getDefaultNodeUrl,
663
698
  hash: () => hash_exports,
664
699
  isSierra: () => isSierra,
665
700
  isUrl: () => isUrl,
@@ -697,6 +732,8 @@ var starknet = (() => {
697
732
  MASK_250: () => MASK_250,
698
733
  MASK_251: () => MASK_251,
699
734
  NetworkName: () => NetworkName,
735
+ RPC_GOERLI_NODES: () => RPC_GOERLI_NODES,
736
+ RPC_MAINNET_NODES: () => RPC_MAINNET_NODES,
700
737
  StarknetChainId: () => StarknetChainId,
701
738
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
702
739
  TransactionHashPrefix: () => TransactionHashPrefix,
@@ -722,6 +759,177 @@ var starknet = (() => {
722
759
  stringToArrayBuffer: () => stringToArrayBuffer,
723
760
  utf8ToArray: () => utf8ToArray
724
761
  });
762
+
763
+ // node_modules/@scure/base/lib/esm/index.js
764
+ function assertNumber(n) {
765
+ if (!Number.isSafeInteger(n))
766
+ throw new Error(`Wrong integer: ${n}`);
767
+ }
768
+ function chain(...args) {
769
+ const wrap = (a, b) => (c) => a(b(c));
770
+ const encode = Array.from(args).reverse().reduce((acc, i) => acc ? wrap(acc, i.encode) : i.encode, void 0);
771
+ const decode2 = args.reduce((acc, i) => acc ? wrap(acc, i.decode) : i.decode, void 0);
772
+ return { encode, decode: decode2 };
773
+ }
774
+ function alphabet(alphabet2) {
775
+ return {
776
+ encode: (digits) => {
777
+ if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number")
778
+ throw new Error("alphabet.encode input should be an array of numbers");
779
+ return digits.map((i) => {
780
+ assertNumber(i);
781
+ if (i < 0 || i >= alphabet2.length)
782
+ throw new Error(`Digit index outside alphabet: ${i} (alphabet: ${alphabet2.length})`);
783
+ return alphabet2[i];
784
+ });
785
+ },
786
+ decode: (input) => {
787
+ if (!Array.isArray(input) || input.length && typeof input[0] !== "string")
788
+ throw new Error("alphabet.decode input should be array of strings");
789
+ return input.map((letter) => {
790
+ if (typeof letter !== "string")
791
+ throw new Error(`alphabet.decode: not string element=${letter}`);
792
+ const index = alphabet2.indexOf(letter);
793
+ if (index === -1)
794
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${alphabet2}`);
795
+ return index;
796
+ });
797
+ }
798
+ };
799
+ }
800
+ function join(separator = "") {
801
+ if (typeof separator !== "string")
802
+ throw new Error("join separator should be string");
803
+ return {
804
+ encode: (from) => {
805
+ if (!Array.isArray(from) || from.length && typeof from[0] !== "string")
806
+ throw new Error("join.encode input should be array of strings");
807
+ for (let i of from)
808
+ if (typeof i !== "string")
809
+ throw new Error(`join.encode: non-string input=${i}`);
810
+ return from.join(separator);
811
+ },
812
+ decode: (to) => {
813
+ if (typeof to !== "string")
814
+ throw new Error("join.decode input should be string");
815
+ return to.split(separator);
816
+ }
817
+ };
818
+ }
819
+ function padding(bits, chr = "=") {
820
+ assertNumber(bits);
821
+ if (typeof chr !== "string")
822
+ throw new Error("padding chr should be string");
823
+ return {
824
+ encode(data) {
825
+ if (!Array.isArray(data) || data.length && typeof data[0] !== "string")
826
+ throw new Error("padding.encode input should be array of strings");
827
+ for (let i of data)
828
+ if (typeof i !== "string")
829
+ throw new Error(`padding.encode: non-string input=${i}`);
830
+ while (data.length * bits % 8)
831
+ data.push(chr);
832
+ return data;
833
+ },
834
+ decode(input) {
835
+ if (!Array.isArray(input) || input.length && typeof input[0] !== "string")
836
+ throw new Error("padding.encode input should be array of strings");
837
+ for (let i of input)
838
+ if (typeof i !== "string")
839
+ throw new Error(`padding.decode: non-string input=${i}`);
840
+ let end = input.length;
841
+ if (end * bits % 8)
842
+ throw new Error("Invalid padding: string should have whole number of bytes");
843
+ for (; end > 0 && input[end - 1] === chr; end--) {
844
+ if (!((end - 1) * bits % 8))
845
+ throw new Error("Invalid padding: string has too much padding");
846
+ }
847
+ return input.slice(0, end);
848
+ }
849
+ };
850
+ }
851
+ function normalize(fn) {
852
+ if (typeof fn !== "function")
853
+ throw new Error("normalize fn should be function");
854
+ return { encode: (from) => from, decode: (to) => fn(to) };
855
+ }
856
+ var gcd = (
857
+ /* @__NO_SIDE_EFFECTS__ */
858
+ (a, b) => !b ? a : gcd(b, a % b)
859
+ );
860
+ var radix2carry = (
861
+ /*@__NO_SIDE_EFFECTS__ */
862
+ (from, to) => from + (to - gcd(from, to))
863
+ );
864
+ function convertRadix2(data, from, to, padding2) {
865
+ if (!Array.isArray(data))
866
+ throw new Error("convertRadix2: data should be array");
867
+ if (from <= 0 || from > 32)
868
+ throw new Error(`convertRadix2: wrong from=${from}`);
869
+ if (to <= 0 || to > 32)
870
+ throw new Error(`convertRadix2: wrong to=${to}`);
871
+ if (radix2carry(from, to) > 32) {
872
+ throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`);
873
+ }
874
+ let carry = 0;
875
+ let pos = 0;
876
+ const mask = 2 ** to - 1;
877
+ const res = [];
878
+ for (const n of data) {
879
+ assertNumber(n);
880
+ if (n >= 2 ** from)
881
+ throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
882
+ carry = carry << from | n;
883
+ if (pos + from > 32)
884
+ throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
885
+ pos += from;
886
+ for (; pos >= to; pos -= to)
887
+ res.push((carry >> pos - to & mask) >>> 0);
888
+ carry &= 2 ** pos - 1;
889
+ }
890
+ carry = carry << to - pos & mask;
891
+ if (!padding2 && pos >= from)
892
+ throw new Error("Excess padding");
893
+ if (!padding2 && carry)
894
+ throw new Error(`Non-zero padding: ${carry}`);
895
+ if (padding2 && pos > 0)
896
+ res.push(carry >>> 0);
897
+ return res;
898
+ }
899
+ function radix2(bits, revPadding = false) {
900
+ assertNumber(bits);
901
+ if (bits <= 0 || bits > 32)
902
+ throw new Error("radix2: bits should be in (0..32]");
903
+ if (radix2carry(8, bits) > 32 || radix2carry(bits, 8) > 32)
904
+ throw new Error("radix2: carry overflow");
905
+ return {
906
+ encode: (bytes2) => {
907
+ if (!(bytes2 instanceof Uint8Array))
908
+ throw new Error("radix2.encode input should be Uint8Array");
909
+ return convertRadix2(Array.from(bytes2), 8, bits, !revPadding);
910
+ },
911
+ decode: (digits) => {
912
+ if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number")
913
+ throw new Error("radix2.decode input should be array of strings");
914
+ return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
915
+ }
916
+ };
917
+ }
918
+ var base16 = /* @__PURE__ */ chain(radix2(4), alphabet("0123456789ABCDEF"), join(""));
919
+ var base32 = /* @__PURE__ */ chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding(5), join(""));
920
+ var base32hex = /* @__PURE__ */ chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding(5), join(""));
921
+ var base32crockford = /* @__PURE__ */ chain(radix2(5), alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join(""), normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
922
+ var base64 = /* @__PURE__ */ chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding(6), join(""));
923
+ var base64url = /* @__PURE__ */ chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding(6), join(""));
924
+ var base64urlnopad = /* @__PURE__ */ chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), join(""));
925
+ var BECH_ALPHABET = /* @__PURE__ */ chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), join(""));
926
+ var hex = /* @__PURE__ */ chain(radix2(4), alphabet("0123456789abcdef"), join(""), normalize((s) => {
927
+ if (typeof s !== "string" || s.length % 2)
928
+ throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
929
+ return s.toLowerCase();
930
+ }));
931
+
932
+ // src/utils/encode.ts
725
933
  var IS_BROWSER = typeof window !== "undefined";
726
934
  var STRING_ZERO = "0";
727
935
  function arrayBufferToString(array) {
@@ -734,47 +942,47 @@ var starknet = (() => {
734
942
  return utf8ToArray(str);
735
943
  }
736
944
  function atobUniversal(a) {
737
- return IS_BROWSER ? utf8ToArray(atob(a)) : Buffer.from(a, "base64");
945
+ return base64.decode(a);
738
946
  }
739
947
  function btoaUniversal(b) {
740
- return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString("base64");
948
+ return base64.encode(new Uint8Array(b));
741
949
  }
742
950
  function buf2hex(buffer) {
743
951
  return buffer.reduce((r, x) => r + x.toString(16).padStart(2, "0"), "");
744
952
  }
745
- function removeHexPrefix(hex) {
746
- return hex.replace(/^0x/i, "");
953
+ function removeHexPrefix(hex2) {
954
+ return hex2.replace(/^0x/i, "");
747
955
  }
748
- function addHexPrefix(hex) {
749
- return `0x${removeHexPrefix(hex)}`;
956
+ function addHexPrefix(hex2) {
957
+ return `0x${removeHexPrefix(hex2)}`;
750
958
  }
751
- function padString(str, length, left, padding = STRING_ZERO) {
959
+ function padString(str, length, left, padding2 = STRING_ZERO) {
752
960
  const diff = length - str.length;
753
961
  let result = str;
754
962
  if (diff > 0) {
755
- const pad = padding.repeat(diff);
963
+ const pad = padding2.repeat(diff);
756
964
  result = left ? pad + str : str + pad;
757
965
  }
758
966
  return result;
759
967
  }
760
- function padLeft(str, length, padding = STRING_ZERO) {
761
- return padString(str, length, true, padding);
968
+ function padLeft(str, length, padding2 = STRING_ZERO) {
969
+ return padString(str, length, true, padding2);
762
970
  }
763
971
  function calcByteLength(str, byteSize = 8) {
764
972
  const { length } = str;
765
973
  const remainder = length % byteSize;
766
974
  return remainder ? (length - remainder) / byteSize * byteSize + byteSize : length;
767
975
  }
768
- function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
769
- return padLeft(str, calcByteLength(str, byteSize), padding);
976
+ function sanitizeBytes(str, byteSize = 8, padding2 = STRING_ZERO) {
977
+ return padLeft(str, calcByteLength(str, byteSize), padding2);
770
978
  }
771
- function sanitizeHex(hex) {
772
- hex = removeHexPrefix(hex);
773
- hex = sanitizeBytes(hex, 2);
774
- if (hex) {
775
- hex = addHexPrefix(hex);
979
+ function sanitizeHex(hex2) {
980
+ hex2 = removeHexPrefix(hex2);
981
+ hex2 = sanitizeBytes(hex2, 2);
982
+ if (hex2) {
983
+ hex2 = addHexPrefix(hex2);
776
984
  }
777
- return hex;
985
+ return hex2;
778
986
  }
779
987
  var pascalToSnake = (text) => /[a-z]/.test(text) ? text.split(/(?=[A-Z])/).join("_").toUpperCase() : text;
780
988
 
@@ -817,6 +1025,14 @@ var starknet = (() => {
817
1025
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
818
1026
  ENTRYPOINT: "deployContract"
819
1027
  };
1028
+ var RPC_GOERLI_NODES = [
1029
+ "https://starknet-testnet.public.blastapi.io/rpc/v0.5",
1030
+ "https://limited-rpc.nethermind.io/goerli-juno/v0_5"
1031
+ ];
1032
+ var RPC_MAINNET_NODES = [
1033
+ "https://starknet-mainnet.public.blastapi.io/rpc/v0.5",
1034
+ "https://limited-rpc.nethermind.io/mainnet-juno/v0_5"
1035
+ ];
820
1036
 
821
1037
  // src/types/index.ts
822
1038
  var types_exports = {};
@@ -837,10 +1053,10 @@ var starknet = (() => {
837
1053
  });
838
1054
 
839
1055
  // src/types/account.ts
840
- var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
841
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
842
- SIMULATION_FLAG3["SKIP_EXECUTE"] = "SKIP_EXECUTE";
843
- return SIMULATION_FLAG3;
1056
+ var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG2) => {
1057
+ SIMULATION_FLAG2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
1058
+ SIMULATION_FLAG2["SKIP_EXECUTE"] = "SKIP_EXECUTE";
1059
+ return SIMULATION_FLAG2;
844
1060
  })(SIMULATION_FLAG || {});
845
1061
 
846
1062
  // src/types/calldata.ts
@@ -874,12 +1090,12 @@ var starknet = (() => {
874
1090
  })(EntryPointType || {});
875
1091
 
876
1092
  // src/types/lib/index.ts
877
- var TransactionType = /* @__PURE__ */ ((TransactionType3) => {
878
- TransactionType3["DECLARE"] = "DECLARE";
879
- TransactionType3["DEPLOY"] = "DEPLOY";
880
- TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
881
- TransactionType3["INVOKE"] = "INVOKE_FUNCTION";
882
- return TransactionType3;
1093
+ var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
1094
+ TransactionType2["DECLARE"] = "DECLARE";
1095
+ TransactionType2["DEPLOY"] = "DEPLOY";
1096
+ TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
1097
+ TransactionType2["INVOKE"] = "INVOKE_FUNCTION";
1098
+ return TransactionType2;
883
1099
  })(TransactionType || {});
884
1100
  var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
885
1101
  TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
@@ -890,18 +1106,18 @@ var starknet = (() => {
890
1106
  TransactionStatus2["REVERTED"] = "REVERTED";
891
1107
  return TransactionStatus2;
892
1108
  })(TransactionStatus || {});
893
- var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus3) => {
894
- TransactionFinalityStatus3["NOT_RECEIVED"] = "NOT_RECEIVED";
895
- TransactionFinalityStatus3["RECEIVED"] = "RECEIVED";
896
- TransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
897
- TransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
898
- return TransactionFinalityStatus3;
1109
+ var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus2) => {
1110
+ TransactionFinalityStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
1111
+ TransactionFinalityStatus2["RECEIVED"] = "RECEIVED";
1112
+ TransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
1113
+ TransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
1114
+ return TransactionFinalityStatus2;
899
1115
  })(TransactionFinalityStatus || {});
900
- var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus3) => {
901
- TransactionExecutionStatus3["REJECTED"] = "REJECTED";
902
- TransactionExecutionStatus3["REVERTED"] = "REVERTED";
903
- TransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
904
- return TransactionExecutionStatus3;
1116
+ var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus2) => {
1117
+ TransactionExecutionStatus2["REJECTED"] = "REJECTED";
1118
+ TransactionExecutionStatus2["REVERTED"] = "REVERTED";
1119
+ TransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
1120
+ return TransactionExecutionStatus2;
905
1121
  })(TransactionExecutionStatus || {});
906
1122
  var BlockStatus = /* @__PURE__ */ ((BlockStatus2) => {
907
1123
  BlockStatus2["PENDING"] = "PENDING";
@@ -919,42 +1135,68 @@ var starknet = (() => {
919
1135
  // src/types/api/rpc.ts
920
1136
  var rpc_exports = {};
921
1137
  __export(rpc_exports, {
922
- SimulationFlag: () => SimulationFlag,
923
- TransactionExecutionStatus: () => TransactionExecutionStatus2,
924
- TransactionFinalityStatus: () => TransactionFinalityStatus2,
925
- TransactionType: () => TransactionType2
1138
+ EBlockTag: () => EBlockTag,
1139
+ EDataAvailabilityMode: () => EDataAvailabilityMode,
1140
+ ESimulationFlag: () => ESimulationFlag,
1141
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus,
1142
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus,
1143
+ ETransactionStatus: () => ETransactionStatus,
1144
+ ETransactionType: () => ETransactionType,
1145
+ Errors: () => errors_exports,
1146
+ JRPC: () => jsonrpc_exports,
1147
+ SPEC: () => components_exports
926
1148
  });
927
1149
 
928
- // src/types/api/openrpc.ts
929
- var TXN_TYPE = /* @__PURE__ */ ((TXN_TYPE2) => {
930
- TXN_TYPE2["DECLARE"] = "DECLARE";
931
- TXN_TYPE2["DEPLOY"] = "DEPLOY";
932
- TXN_TYPE2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
933
- TXN_TYPE2["INVOKE"] = "INVOKE";
934
- TXN_TYPE2["L1_HANDLER"] = "L1_HANDLER";
935
- return TXN_TYPE2;
936
- })(TXN_TYPE || {});
937
- var TXN_FINALITY_STATUS = /* @__PURE__ */ ((TXN_FINALITY_STATUS2) => {
938
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
939
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
940
- return TXN_FINALITY_STATUS2;
941
- })(TXN_FINALITY_STATUS || {});
942
- var TXN_EXECUTION_STATUS = /* @__PURE__ */ ((TXN_EXECUTION_STATUS2) => {
943
- TXN_EXECUTION_STATUS2["SUCCEEDED"] = "SUCCEEDED";
944
- TXN_EXECUTION_STATUS2["REVERTED"] = "REVERTED";
945
- return TXN_EXECUTION_STATUS2;
946
- })(TXN_EXECUTION_STATUS || {});
947
- var SIMULATION_FLAG2 = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
948
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
949
- SIMULATION_FLAG3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
950
- return SIMULATION_FLAG3;
951
- })(SIMULATION_FLAG2 || {});
1150
+ // src/types/api/jsonrpc/index.ts
1151
+ var jsonrpc_exports = {};
952
1152
 
953
- // src/types/api/rpc.ts
954
- var TransactionType2 = TXN_TYPE;
955
- var SimulationFlag = SIMULATION_FLAG2;
956
- var TransactionFinalityStatus2 = TXN_FINALITY_STATUS;
957
- var TransactionExecutionStatus2 = TXN_EXECUTION_STATUS;
1153
+ // src/types/api/rpcspec/errors.ts
1154
+ var errors_exports = {};
1155
+
1156
+ // src/types/api/rpcspec/components.ts
1157
+ var components_exports = {};
1158
+
1159
+ // src/types/api/rpcspec/nonspec.ts
1160
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
1161
+ ETransactionType2["DECLARE"] = "DECLARE";
1162
+ ETransactionType2["DEPLOY"] = "DEPLOY";
1163
+ ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
1164
+ ETransactionType2["INVOKE"] = "INVOKE";
1165
+ ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
1166
+ return ETransactionType2;
1167
+ })(ETransactionType || {});
1168
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
1169
+ ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
1170
+ ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
1171
+ return ESimulationFlag2;
1172
+ })(ESimulationFlag || {});
1173
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
1174
+ ETransactionStatus2["RECEIVED"] = "RECEIVED";
1175
+ ETransactionStatus2["REJECTED"] = "REJECTED";
1176
+ ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
1177
+ ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
1178
+ return ETransactionStatus2;
1179
+ })(ETransactionStatus || {});
1180
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
1181
+ ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
1182
+ ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
1183
+ return ETransactionFinalityStatus2;
1184
+ })(ETransactionFinalityStatus || {});
1185
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
1186
+ ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
1187
+ ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
1188
+ return ETransactionExecutionStatus2;
1189
+ })(ETransactionExecutionStatus || {});
1190
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
1191
+ EBlockTag2["LATEST"] = "latest";
1192
+ EBlockTag2["PENDING"] = "pending";
1193
+ return EBlockTag2;
1194
+ })(EBlockTag || {});
1195
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
1196
+ EDataAvailabilityMode2["L1"] = "L1";
1197
+ EDataAvailabilityMode2["L2"] = "L2";
1198
+ return EDataAvailabilityMode2;
1199
+ })(EDataAvailabilityMode || {});
958
1200
 
959
1201
  // src/types/api/sequencer.ts
960
1202
  var sequencer_exports = {};
@@ -1019,31 +1261,31 @@ var starknet = (() => {
1019
1261
  function bytesToHex(bytes2) {
1020
1262
  if (!u8a(bytes2))
1021
1263
  throw new Error("Uint8Array expected");
1022
- let hex = "";
1264
+ let hex2 = "";
1023
1265
  for (let i = 0; i < bytes2.length; i++) {
1024
- hex += hexes[bytes2[i]];
1266
+ hex2 += hexes[bytes2[i]];
1025
1267
  }
1026
- return hex;
1268
+ return hex2;
1027
1269
  }
1028
1270
  function numberToHexUnpadded(num) {
1029
- const hex = num.toString(16);
1030
- return hex.length & 1 ? `0${hex}` : hex;
1031
- }
1032
- function hexToNumber(hex) {
1033
- if (typeof hex !== "string")
1034
- throw new Error("hex string expected, got " + typeof hex);
1035
- return BigInt(hex === "" ? "0" : `0x${hex}`);
1036
- }
1037
- function hexToBytes(hex) {
1038
- if (typeof hex !== "string")
1039
- throw new Error("hex string expected, got " + typeof hex);
1040
- const len = hex.length;
1271
+ const hex2 = num.toString(16);
1272
+ return hex2.length & 1 ? `0${hex2}` : hex2;
1273
+ }
1274
+ function hexToNumber(hex2) {
1275
+ if (typeof hex2 !== "string")
1276
+ throw new Error("hex string expected, got " + typeof hex2);
1277
+ return BigInt(hex2 === "" ? "0" : `0x${hex2}`);
1278
+ }
1279
+ function hexToBytes(hex2) {
1280
+ if (typeof hex2 !== "string")
1281
+ throw new Error("hex string expected, got " + typeof hex2);
1282
+ const len = hex2.length;
1041
1283
  if (len % 2)
1042
1284
  throw new Error("padded hex string expected, got unpadded hex of length " + len);
1043
1285
  const array = new Uint8Array(len / 2);
1044
1286
  for (let i = 0; i < array.length; i++) {
1045
1287
  const j = i * 2;
1046
- const hexByte = hex.slice(j, j + 2);
1288
+ const hexByte = hex2.slice(j, j + 2);
1047
1289
  const byte = Number.parseInt(hexByte, 16);
1048
1290
  if (Number.isNaN(byte) || byte < 0)
1049
1291
  throw new Error("Invalid byte sequence");
@@ -1068,16 +1310,16 @@ var starknet = (() => {
1068
1310
  function numberToVarBytesBE(n) {
1069
1311
  return hexToBytes(numberToHexUnpadded(n));
1070
1312
  }
1071
- function ensureBytes(title, hex, expectedLength) {
1313
+ function ensureBytes(title, hex2, expectedLength) {
1072
1314
  let res;
1073
- if (typeof hex === "string") {
1315
+ if (typeof hex2 === "string") {
1074
1316
  try {
1075
- res = hexToBytes(hex);
1317
+ res = hexToBytes(hex2);
1076
1318
  } catch (e) {
1077
- throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
1319
+ throw new Error(`${title} must be valid hex string, got "${hex2}". Cause: ${e}`);
1078
1320
  }
1079
- } else if (u8a(hex)) {
1080
- res = Uint8Array.from(hex);
1321
+ } else if (u8a(hex2)) {
1322
+ res = Uint8Array.from(hex2);
1081
1323
  } else {
1082
1324
  throw new Error(`${title} must be hex string or Uint8Array`);
1083
1325
  }
@@ -1204,8 +1446,8 @@ var starknet = (() => {
1204
1446
  }
1205
1447
 
1206
1448
  // src/utils/num.ts
1207
- function isHex(hex) {
1208
- return /^0x[0-9a-f]*$/i.test(hex);
1449
+ function isHex(hex2) {
1450
+ return /^0x[0-9a-f]*$/i.test(hex2);
1209
1451
  }
1210
1452
  function toBigInt(value) {
1211
1453
  return BigInt(value);
@@ -1221,10 +1463,10 @@ var starknet = (() => {
1221
1463
  const res = addHexPrefix(toBigInt(number3).toString(16).padStart(64, "0"));
1222
1464
  return res;
1223
1465
  }
1224
- function hexToDecimalString(hex) {
1225
- return BigInt(addHexPrefix(hex)).toString(10);
1466
+ function hexToDecimalString(hex2) {
1467
+ return BigInt(addHexPrefix(hex2)).toString(10);
1226
1468
  }
1227
- var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
1469
+ var cleanHex = (hex2) => hex2.toLowerCase().replace(/^(0x)0+/, "$1");
1228
1470
  function assertInRange(input, lowerBound, upperBound, inputName = "") {
1229
1471
  const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
1230
1472
  const inputBigInt = BigInt(input);
@@ -1905,8 +2147,8 @@ var starknet = (() => {
1905
2147
  const n = y - v * q;
1906
2148
  b = a, a = r, x = u, y = v, u = m, v = n;
1907
2149
  }
1908
- const gcd = b;
1909
- if (gcd !== _1n3)
2150
+ const gcd2 = b;
2151
+ if (gcd2 !== _1n3)
1910
2152
  throw new Error("invert: does not exist");
1911
2153
  return mod(x, modulo);
1912
2154
  }
@@ -1931,7 +2173,7 @@ var starknet = (() => {
1931
2173
  if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
1932
2174
  throw new Error("Cannot find square root");
1933
2175
  let r = S;
1934
- let g = Fp.pow(Fp.mul(Fp.ONE, Z), Q);
2176
+ let g2 = Fp.pow(Fp.mul(Fp.ONE, Z), Q);
1935
2177
  let x = Fp.pow(n, Q1div2);
1936
2178
  let b = Fp.pow(n, Q);
1937
2179
  while (!Fp.eql(b, Fp.ONE)) {
@@ -1943,10 +2185,10 @@ var starknet = (() => {
1943
2185
  break;
1944
2186
  t2 = Fp.sqr(t2);
1945
2187
  }
1946
- const ge = Fp.pow(g, _1n3 << BigInt(r - m - 1));
1947
- g = Fp.sqr(ge);
2188
+ const ge = Fp.pow(g2, _1n3 << BigInt(r - m - 1));
2189
+ g2 = Fp.sqr(ge);
1948
2190
  x = Fp.mul(x, ge);
1949
- b = Fp.mul(b, g);
2191
+ b = Fp.mul(b, g2);
1950
2192
  r = m;
1951
2193
  }
1952
2194
  return x;
@@ -2402,9 +2644,9 @@ var starknet = (() => {
2402
2644
  throw new E("Invalid signature integer: unnecessary leading zero");
2403
2645
  return { d: b2n(res), l: data.subarray(len + 2) };
2404
2646
  },
2405
- toSig(hex) {
2647
+ toSig(hex2) {
2406
2648
  const { Err: E } = DER;
2407
- const data = typeof hex === "string" ? h2b(hex) : hex;
2649
+ const data = typeof hex2 === "string" ? h2b(hex2) : hex2;
2408
2650
  if (!(data instanceof Uint8Array))
2409
2651
  throw new Error("ui8a expected");
2410
2652
  let l = data.length;
@@ -2421,8 +2663,8 @@ var starknet = (() => {
2421
2663
  hexFromSig(sig) {
2422
2664
  const slice = (s2) => Number.parseInt(s2[0], 16) & 8 ? "00" + s2 : s2;
2423
2665
  const h = (num) => {
2424
- const hex = num.toString(16);
2425
- return hex.length & 1 ? `0${hex}` : hex;
2666
+ const hex2 = num.toString(16);
2667
+ return hex2.length & 1 ? `0${hex2}` : hex2;
2426
2668
  };
2427
2669
  const s = slice(h(sig.s));
2428
2670
  const r = slice(h(sig.r));
@@ -2536,8 +2778,8 @@ var starknet = (() => {
2536
2778
  * Converts hash string or Uint8Array to Point.
2537
2779
  * @param hex short/long ECDSA hex
2538
2780
  */
2539
- static fromHex(hex) {
2540
- const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
2781
+ static fromHex(hex2) {
2782
+ const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex2)));
2541
2783
  P.assertValidity();
2542
2784
  return P;
2543
2785
  }
@@ -2907,15 +3149,15 @@ var starknet = (() => {
2907
3149
  this.assertValidity();
2908
3150
  }
2909
3151
  // pair (bytes of r, bytes of s)
2910
- static fromCompact(hex) {
3152
+ static fromCompact(hex2) {
2911
3153
  const l = CURVE2.nByteLength;
2912
- hex = ensureBytes("compactSignature", hex, l * 2);
2913
- return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
3154
+ hex2 = ensureBytes("compactSignature", hex2, l * 2);
3155
+ return new Signature3(slcNum(hex2, 0, l), slcNum(hex2, l, 2 * l));
2914
3156
  }
2915
3157
  // DER encoded ECDSA signature
2916
3158
  // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
2917
- static fromDER(hex) {
2918
- const { r, s } = DER.toSig(ensureBytes("DER", hex));
3159
+ static fromDER(hex2) {
3160
+ const { r, s } = DER.toSig(ensureBytes("DER", hex2));
2919
3161
  return new Signature3(r, s);
2920
3162
  }
2921
3163
  assertValidity() {
@@ -3330,13 +3572,13 @@ var starknet = (() => {
3330
3572
  const num = bytesToNumberBE(bytes2);
3331
3573
  return delta > 0 ? num >> BigInt(delta) : num;
3332
3574
  }
3333
- function hex0xToBytes(hex) {
3334
- if (typeof hex === "string") {
3335
- hex = strip0x(hex);
3336
- if (hex.length & 1)
3337
- hex = "0" + hex;
3575
+ function hex0xToBytes(hex2) {
3576
+ if (typeof hex2 === "string") {
3577
+ hex2 = strip0x(hex2);
3578
+ if (hex2.length & 1)
3579
+ hex2 = "0" + hex2;
3338
3580
  }
3339
- return hexToBytes(hex);
3581
+ return hexToBytes(hex2);
3340
3582
  }
3341
3583
  var curve = weierstrass({
3342
3584
  a: BigInt(1),
@@ -3351,15 +3593,15 @@ var starknet = (() => {
3351
3593
  ...getHash(sha256),
3352
3594
  bits2int,
3353
3595
  bits2int_modN: (bytes2) => {
3354
- const hex = bytesToNumberBE(bytes2).toString(16);
3355
- if (hex.length === 63)
3356
- bytes2 = hex0xToBytes(hex + "0");
3596
+ const hex2 = bytesToNumberBE(bytes2).toString(16);
3597
+ if (hex2.length === 63)
3598
+ bytes2 = hex0xToBytes(hex2 + "0");
3357
3599
  return mod(bits2int(bytes2), CURVE_ORDER);
3358
3600
  }
3359
3601
  });
3360
3602
  var _starkCurve = curve;
3361
- function ensureBytes2(hex) {
3362
- return ensureBytes("", typeof hex === "string" ? hex0xToBytes(hex) : hex);
3603
+ function ensureBytes2(hex2) {
3604
+ return ensureBytes("", typeof hex2 === "string" ? hex0xToBytes(hex2) : hex2);
3363
3605
  }
3364
3606
  function normPrivKey(privKey) {
3365
3607
  return bytesToHex(ensureBytes2(privKey)).padStart(64, "0");
@@ -3406,12 +3648,12 @@ var starknet = (() => {
3406
3648
  }
3407
3649
  var { CURVE, ProjectivePoint, Signature, utils } = curve;
3408
3650
  function extractX(bytes2) {
3409
- const hex = bytesToHex(bytes2.subarray(1));
3410
- const stripped = hex.replace(/^0+/gm, "");
3651
+ const hex2 = bytesToHex(bytes2.subarray(1));
3652
+ const stripped = hex2.replace(/^0+/gm, "");
3411
3653
  return `0x${stripped}`;
3412
3654
  }
3413
- function strip0x(hex) {
3414
- return hex.replace(/^0x/i, "");
3655
+ function strip0x(hex2) {
3656
+ return hex2.replace(/^0x/i, "");
3415
3657
  }
3416
3658
  function grindKey(seed) {
3417
3659
  const _seed = ensureBytes2(seed);
@@ -3650,7 +3892,7 @@ var starknet = (() => {
3650
3892
  if (!isASCII(str))
3651
3893
  throw new Error(`${str} is not an ASCII string`);
3652
3894
  if (isHex(str)) {
3653
- return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
3895
+ return removeHexPrefix(str).replace(/.{2}/g, (hex2) => String.fromCharCode(parseInt(hex2, 16)));
3654
3896
  }
3655
3897
  if (isDecimalString(str)) {
3656
3898
  return decodeShortString("0X".concat(BigInt(str).toString(16)));
@@ -10156,10 +10398,10 @@ var starknet = (() => {
10156
10398
  const compressedProgram = gzip_1(stringified);
10157
10399
  return btoaUniversal(compressedProgram);
10158
10400
  }
10159
- function decompressProgram(base64) {
10160
- if (Array.isArray(base64))
10161
- return base64;
10162
- const decompressed = arrayBufferToString(ungzip_1(atobUniversal(base64)));
10401
+ function decompressProgram(base642) {
10402
+ if (Array.isArray(base642))
10403
+ return base642;
10404
+ const decompressed = arrayBufferToString(ungzip_1(atobUniversal(base642)));
10163
10405
  return parse2(decompressed);
10164
10406
  }
10165
10407
  function randomAddress() {
@@ -10264,22 +10506,22 @@ var starknet = (() => {
10264
10506
  parseGetBlockResponse(res) {
10265
10507
  return {
10266
10508
  timestamp: res.timestamp,
10267
- block_hash: res.block_hash,
10268
- block_number: res.block_number,
10269
- new_root: res.new_root,
10509
+ block_hash: "block_hash" in res ? res.block_hash : "",
10510
+ block_number: "block_number" in res ? res.block_number : -1,
10511
+ new_root: "new_root" in res ? res.new_root : "",
10270
10512
  parent_hash: res.parent_hash,
10271
- status: res.status,
10513
+ status: "status" in res ? res.status : "PENDING" /* PENDING */,
10272
10514
  transactions: res.transactions
10273
10515
  };
10274
10516
  }
10275
10517
  parseGetTransactionResponse(res) {
10276
10518
  return {
10277
- calldata: res.calldata || [],
10278
- contract_address: res.contract_address,
10279
- sender_address: res.contract_address,
10280
- max_fee: res.max_fee,
10281
- nonce: res.nonce,
10282
- signature: res.signature || [],
10519
+ calldata: "calldata" in res ? res.calldata : [],
10520
+ contract_address: "contract_address" in res ? res.contract_address : "",
10521
+ sender_address: "sender_address" in res ? res.sender_address : "",
10522
+ max_fee: "max_fee" in res ? res.max_fee : "",
10523
+ nonce: "nonce" in res ? res.nonce : "",
10524
+ signature: "signature" in res ? res.signature : [],
10283
10525
  transaction_hash: res.transaction_hash,
10284
10526
  version: res.version
10285
10527
  };
@@ -10555,6 +10797,13 @@ var starknet = (() => {
10555
10797
  };
10556
10798
 
10557
10799
  // src/provider/rpc.ts
10800
+ var getDefaultNodeUrl = (networkName, mute = false) => {
10801
+ if (!mute)
10802
+ console.warn("Using default public node url, please provide nodeUrl in provider options!");
10803
+ const nodes = networkName === "SN_MAIN" /* SN_MAIN */ ? RPC_MAINNET_NODES : RPC_GOERLI_NODES;
10804
+ const randIdx = Math.floor(Math.random() * nodes.length);
10805
+ return nodes[randIdx];
10806
+ };
10558
10807
  var defaultOptions = {
10559
10808
  headers: { "Content-Type": "application/json" },
10560
10809
  blockIdentifier: "pending" /* pending */,
@@ -10563,52 +10812,127 @@ var starknet = (() => {
10563
10812
  var RpcProvider = class {
10564
10813
  constructor(optionsOrProvider) {
10565
10814
  this.responseParser = new RPCResponseParser();
10566
- const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider;
10567
- this.nodeUrl = nodeUrl;
10815
+ /**
10816
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
10817
+ */
10818
+ this.getBlockHashAndNumber = this.getBlockLatestAccepted;
10819
+ /**
10820
+ * @deprecated renamed to getBlockStateUpdate();
10821
+ */
10822
+ this.getStateUpdate = this.getBlockStateUpdate;
10823
+ /**
10824
+ * Returns the execution traces of all transactions included in the given block
10825
+ * @deprecated renamed to getBlockTransactionsTraces()
10826
+ */
10827
+ this.traceBlockTransactions = this.getBlockTransactionsTraces;
10828
+ /**
10829
+ * Get the number of transactions in a block given a block id
10830
+ * @deprecated renamed to getBlockTransactionCount()
10831
+ * @returns Number of transactions
10832
+ */
10833
+ this.getTransactionCount = this.getBlockTransactionCount;
10834
+ /**
10835
+ * @deprecated renamed to getTransactionTrace();
10836
+ * For a given executed transaction, return the trace of its execution, including internal calls
10837
+ */
10838
+ this.traceTransaction = this.getTransactionTrace;
10839
+ /**
10840
+ * @deprecated renamed to simulateTransaction();
10841
+ */
10842
+ this.getSimulateTransaction = this.simulateTransaction;
10843
+ const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider || {};
10844
+ if (Object.values(NetworkName).includes(nodeUrl)) {
10845
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
10846
+ } else if (nodeUrl) {
10847
+ this.nodeUrl = nodeUrl;
10848
+ } else {
10849
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
10850
+ }
10568
10851
  this.retries = retries || defaultOptions.retries;
10569
10852
  this.headers = { ...defaultOptions.headers, ...headers };
10570
10853
  this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
10571
10854
  this.chainId = chainId;
10572
10855
  this.getChainId();
10573
10856
  }
10574
- fetch(method, params) {
10575
- const body = stringify2({ method, jsonrpc: "2.0", params, id: 0 });
10857
+ fetch(method, params, id = 0) {
10858
+ const rpcRequestBody = {
10859
+ id,
10860
+ jsonrpc: "2.0",
10861
+ method,
10862
+ ...params && { params }
10863
+ };
10576
10864
  return fetchPonyfill_default(this.nodeUrl, {
10577
10865
  method: "POST",
10578
- body,
10866
+ body: stringify2(rpcRequestBody),
10579
10867
  headers: this.headers
10580
10868
  });
10581
10869
  }
10582
- errorHandler(error) {
10583
- if (error) {
10584
- const { code, message } = error;
10585
- throw new LibraryError(`${code}: ${message}`);
10870
+ errorHandler(method, params, rpcError, otherError) {
10871
+ if (rpcError) {
10872
+ const { code, message, data } = rpcError;
10873
+ throw new LibraryError(
10874
+ `RPC: ${method} with params ${JSON.stringify(params)}
10875
+ ${code}: ${message}: ${data}`
10876
+ );
10877
+ }
10878
+ if (otherError instanceof LibraryError) {
10879
+ throw otherError;
10880
+ }
10881
+ if (otherError) {
10882
+ throw Error(otherError.message);
10586
10883
  }
10587
10884
  }
10588
10885
  async fetchEndpoint(method, params) {
10589
10886
  try {
10590
10887
  const rawResult = await this.fetch(method, params);
10591
10888
  const { error, result } = await rawResult.json();
10592
- this.errorHandler(error);
10889
+ this.errorHandler(method, params, error);
10593
10890
  return result;
10594
10891
  } catch (error) {
10595
- this.errorHandler(error?.response?.data);
10892
+ this.errorHandler(method, params, error?.response?.data, error);
10596
10893
  throw error;
10597
10894
  }
10598
10895
  }
10599
- // Methods from Interface
10600
10896
  async getChainId() {
10601
10897
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
10602
10898
  return this.chainId;
10603
10899
  }
10900
+ /**
10901
+ * NEW: Returns the version of the Starknet JSON-RPC specification being used
10902
+ */
10903
+ async getSpecVersion() {
10904
+ return this.fetchEndpoint("starknet_specVersion");
10905
+ }
10906
+ async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
10907
+ const contract_address = toHex(contractAddress);
10908
+ const block_id = new Block(blockIdentifier).identifier;
10909
+ return this.fetchEndpoint("starknet_getNonce", {
10910
+ contract_address,
10911
+ block_id
10912
+ });
10913
+ }
10914
+ /**
10915
+ * @deprecated use getBlockWithTxHashes or getBlockWithTxs (will be removed on sequencer deprecation)
10916
+ */
10604
10917
  async getBlock(blockIdentifier = this.blockIdentifier) {
10605
10918
  return this.getBlockWithTxHashes(blockIdentifier).then(
10606
10919
  this.responseParser.parseGetBlockResponse
10607
10920
  );
10608
10921
  }
10609
- async getBlockHashAndNumber() {
10922
+ /**
10923
+ * Get the most recent accepted block hash and number
10924
+ */
10925
+ async getBlockLatestAccepted() {
10610
10926
  return this.fetchEndpoint("starknet_blockHashAndNumber");
10611
10927
  }
10928
+ /**
10929
+ * @deprecated redundant use getBlockLatestAccepted();
10930
+ * Get the most recent accepted block number
10931
+ * @returns Number of the latest block
10932
+ */
10933
+ async getBlockNumber() {
10934
+ return this.fetchEndpoint("starknet_blockNumber");
10935
+ }
10612
10936
  async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
10613
10937
  const block_id = new Block(blockIdentifier).identifier;
10614
10938
  return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
@@ -10617,68 +10941,176 @@ var starknet = (() => {
10617
10941
  const block_id = new Block(blockIdentifier).identifier;
10618
10942
  return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
10619
10943
  }
10620
- async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
10944
+ async getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
10621
10945
  const block_id = new Block(blockIdentifier).identifier;
10622
- return this.fetchEndpoint("starknet_getClassHashAt", {
10623
- block_id,
10624
- contract_address: contractAddress
10625
- });
10946
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
10626
10947
  }
10627
- async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
10948
+ async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
10628
10949
  const block_id = new Block(blockIdentifier).identifier;
10629
- return this.fetchEndpoint("starknet_getNonce", {
10630
- contract_address: contractAddress,
10631
- block_id
10632
- });
10950
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
10633
10951
  }
10952
+ async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
10953
+ const block_id = new Block(blockIdentifier).identifier;
10954
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
10955
+ }
10956
+ /**
10957
+ * Return transactions from pending block
10958
+ * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
10959
+ */
10634
10960
  async getPendingTransactions() {
10635
- return this.fetchEndpoint("starknet_pendingTransactions");
10961
+ const { transactions } = await this.getBlock("pending" /* pending */);
10962
+ return Promise.all(transactions.map((it) => this.getTransactionByHash(it)));
10963
+ }
10964
+ /**
10965
+ * @deprecated use getTransactionByHash or getTransactionByBlockIdAndIndex (will be removed on sequencer deprecation)
10966
+ */
10967
+ async getTransaction(txHash) {
10968
+ return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
10636
10969
  }
10637
- async getProtocolVersion() {
10638
- throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
10970
+ async getTransactionByHash(txHash) {
10971
+ const transaction_hash = toHex(txHash);
10972
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
10973
+ transaction_hash
10974
+ });
10639
10975
  }
10640
- async getStateUpdate(blockIdentifier = this.blockIdentifier) {
10976
+ async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
10641
10977
  const block_id = new Block(blockIdentifier).identifier;
10642
- return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
10978
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
10979
+ }
10980
+ async getTransactionReceipt(txHash) {
10981
+ const transaction_hash = toHex(txHash);
10982
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
10983
+ }
10984
+ async getTransactionTrace(txHash) {
10985
+ const transaction_hash = toHex(txHash);
10986
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
10987
+ }
10988
+ // TODO: implement in waitforTransaction, add add tests, when RPC 0.5 become standard /
10989
+ /**
10990
+ * NEW: Get the status of a transaction
10991
+ */
10992
+ async getTransactionStatus(transactionHash) {
10993
+ const transaction_hash = toHex(transactionHash);
10994
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
10995
+ }
10996
+ /**
10997
+ * @param invocations AccountInvocations
10998
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
10999
+ * - blockIdentifier<br/>
11000
+ * - skipValidate (default false)<br/>
11001
+ * - skipFeeCharge (default true)<br/>
11002
+ */
11003
+ async simulateTransaction(invocations, {
11004
+ blockIdentifier = this.blockIdentifier,
11005
+ skipValidate = false,
11006
+ skipFeeCharge = true
11007
+ }) {
11008
+ const block_id = new Block(blockIdentifier).identifier;
11009
+ const simulationFlags = [];
11010
+ if (skipValidate)
11011
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_VALIDATE);
11012
+ if (skipFeeCharge)
11013
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_FEE_CHARGE);
11014
+ return this.fetchEndpoint("starknet_simulateTransactions", {
11015
+ block_id,
11016
+ transactions: invocations.map((it) => this.buildTransaction(it)),
11017
+ simulation_flags: simulationFlags
11018
+ }).then(this.responseParser.parseSimulateTransactionResponse);
11019
+ }
11020
+ async waitForTransaction(txHash, options) {
11021
+ const transactionHash = toHex(txHash);
11022
+ let { retries } = this;
11023
+ let onchain = false;
11024
+ let isErrorState = false;
11025
+ const retryInterval = options?.retryInterval ?? 5e3;
11026
+ const errorStates = options?.errorStates ?? [
11027
+ rpc_exports.ETransactionStatus.REJECTED,
11028
+ rpc_exports.ETransactionExecutionStatus.REVERTED
11029
+ ];
11030
+ const successStates = options?.successStates ?? [
11031
+ rpc_exports.ETransactionExecutionStatus.SUCCEEDED,
11032
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L2,
11033
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L1
11034
+ ];
11035
+ let txStatus;
11036
+ while (!onchain) {
11037
+ await wait(retryInterval);
11038
+ try {
11039
+ txStatus = await this.getTransactionStatus(transactionHash);
11040
+ const executionStatus = txStatus.execution_status;
11041
+ const finalityStatus = txStatus.finality_status;
11042
+ if (!finalityStatus) {
11043
+ const error = new Error("waiting for transaction status");
11044
+ throw error;
11045
+ }
11046
+ if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
11047
+ onchain = true;
11048
+ } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
11049
+ const message = `${executionStatus}: ${finalityStatus}`;
11050
+ const error = new Error(message);
11051
+ error.response = txStatus;
11052
+ isErrorState = true;
11053
+ throw error;
11054
+ }
11055
+ } catch (error) {
11056
+ if (error instanceof Error && isErrorState) {
11057
+ throw error;
11058
+ }
11059
+ if (retries <= 0) {
11060
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
11061
+ }
11062
+ }
11063
+ retries -= 1;
11064
+ }
11065
+ let txReceipt = null;
11066
+ while (txReceipt === null) {
11067
+ try {
11068
+ txReceipt = await this.getTransactionReceipt(transactionHash);
11069
+ } catch (error) {
11070
+ if (retries <= 0) {
11071
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
11072
+ }
11073
+ }
11074
+ retries -= 1;
11075
+ await wait(retryInterval);
11076
+ }
11077
+ return txReceipt;
10643
11078
  }
10644
11079
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
11080
+ const contract_address = toHex(contractAddress);
10645
11081
  const parsedKey = toStorageKey(key);
10646
11082
  const block_id = new Block(blockIdentifier).identifier;
10647
11083
  return this.fetchEndpoint("starknet_getStorageAt", {
10648
- contract_address: contractAddress,
11084
+ contract_address,
10649
11085
  key: parsedKey,
10650
11086
  block_id
10651
11087
  });
10652
11088
  }
10653
- // Methods from Interface
10654
- async getTransaction(txHash) {
10655
- return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
10656
- }
10657
- async getTransactionByHash(txHash) {
10658
- return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
10659
- }
10660
- async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
11089
+ async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
11090
+ const contract_address = toHex(contractAddress);
10661
11091
  const block_id = new Block(blockIdentifier).identifier;
10662
- return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
10663
- }
10664
- async getTransactionReceipt(txHash) {
10665
- return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
11092
+ return this.fetchEndpoint("starknet_getClassHashAt", {
11093
+ block_id,
11094
+ contract_address
11095
+ });
10666
11096
  }
10667
11097
  async getClassByHash(classHash) {
10668
11098
  return this.getClass(classHash);
10669
11099
  }
10670
11100
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
11101
+ const class_hash = toHex(classHash);
10671
11102
  const block_id = new Block(blockIdentifier).identifier;
10672
11103
  return this.fetchEndpoint("starknet_getClass", {
10673
- class_hash: classHash,
11104
+ class_hash,
10674
11105
  block_id
10675
11106
  }).then(this.responseParser.parseContractClassResponse);
10676
11107
  }
10677
11108
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
11109
+ const contract_address = toHex(contractAddress);
10678
11110
  const block_id = new Block(blockIdentifier).identifier;
10679
11111
  return this.fetchEndpoint("starknet_getClassAt", {
10680
11112
  block_id,
10681
- contract_address: contractAddress
11113
+ contract_address
10682
11114
  }).then(this.responseParser.parseContractClassResponse);
10683
11115
  }
10684
11116
  async getCode(_contractAddress, _blockIdentifier) {
@@ -10702,6 +11134,9 @@ var starknet = (() => {
10702
11134
  }
10703
11135
  return { cairo: "0", compiler: "0" };
10704
11136
  }
11137
+ /**
11138
+ * @deprecated use get*type*EstimateFee (will be refactored based on type after sequencer deprecation)
11139
+ */
10705
11140
  async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
10706
11141
  return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
10707
11142
  }
@@ -10760,11 +11195,24 @@ var starknet = (() => {
10760
11195
  block_id
10761
11196
  }).then(this.responseParser.parseFeeEstimateBulkResponse);
10762
11197
  }
11198
+ async invokeFunction(functionInvocation, details) {
11199
+ return this.fetchEndpoint("starknet_addInvokeTransaction", {
11200
+ invoke_transaction: {
11201
+ sender_address: functionInvocation.contractAddress,
11202
+ calldata: CallData.toHex(functionInvocation.calldata),
11203
+ type: rpc_exports.ETransactionType.INVOKE,
11204
+ max_fee: toHex(details.maxFee || 0),
11205
+ version: "0x1",
11206
+ signature: signatureToHexArray(functionInvocation.signature),
11207
+ nonce: toHex(details.nonce)
11208
+ }
11209
+ });
11210
+ }
10763
11211
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
10764
11212
  if (!isSierra(contract)) {
10765
11213
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
10766
11214
  declare_transaction: {
10767
- type: rpc_exports.TransactionType.DECLARE,
11215
+ type: rpc_exports.ETransactionType.DECLARE,
10768
11216
  contract_class: {
10769
11217
  program: contract.program,
10770
11218
  entry_points_by_type: contract.entry_points_by_type,
@@ -10780,7 +11228,7 @@ var starknet = (() => {
10780
11228
  }
10781
11229
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
10782
11230
  declare_transaction: {
10783
- type: rpc_exports.TransactionType.DECLARE,
11231
+ type: rpc_exports.ETransactionType.DECLARE,
10784
11232
  contract_class: {
10785
11233
  sierra_program: decompressProgram(contract.sierra_program),
10786
11234
  contract_class_version: contract.contract_class_version,
@@ -10802,7 +11250,7 @@ var starknet = (() => {
10802
11250
  constructor_calldata: CallData.toHex(constructorCalldata || []),
10803
11251
  class_hash: toHex(classHash),
10804
11252
  contract_address_salt: toHex(addressSalt || 0),
10805
- type: rpc_exports.TransactionType.DEPLOY_ACCOUNT,
11253
+ type: rpc_exports.ETransactionType.DEPLOY_ACCOUNT,
10806
11254
  max_fee: toHex(details.maxFee || 0),
10807
11255
  version: toHex(details.version || 0),
10808
11256
  signature: signatureToHexArray(signature),
@@ -10810,20 +11258,6 @@ var starknet = (() => {
10810
11258
  }
10811
11259
  });
10812
11260
  }
10813
- async invokeFunction(functionInvocation, details) {
10814
- return this.fetchEndpoint("starknet_addInvokeTransaction", {
10815
- invoke_transaction: {
10816
- sender_address: functionInvocation.contractAddress,
10817
- calldata: CallData.toHex(functionInvocation.calldata),
10818
- type: rpc_exports.TransactionType.INVOKE,
10819
- max_fee: toHex(details.maxFee || 0),
10820
- version: "0x1",
10821
- signature: signatureToHexArray(functionInvocation.signature),
10822
- nonce: toHex(details.nonce)
10823
- }
10824
- });
10825
- }
10826
- // Methods from Interface
10827
11261
  async callContract(call, blockIdentifier = this.blockIdentifier) {
10828
11262
  const block_id = new Block(blockIdentifier).identifier;
10829
11263
  const result = await this.fetchEndpoint("starknet_call", {
@@ -10836,117 +11270,47 @@ var starknet = (() => {
10836
11270
  });
10837
11271
  return this.responseParser.parseCallContractResponse(result);
10838
11272
  }
10839
- async traceTransaction(transactionHash) {
10840
- return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash: transactionHash });
10841
- }
10842
- async traceBlockTransactions(blockHash) {
10843
- return this.fetchEndpoint("starknet_traceBlockTransactions", { block_hash: blockHash });
10844
- }
10845
- async waitForTransaction(txHash, options) {
10846
- let { retries } = this;
10847
- let onchain = false;
10848
- let isErrorState = false;
10849
- let txReceipt = {};
10850
- const retryInterval = options?.retryInterval ?? 5e3;
10851
- const errorStates = options?.errorStates ?? [TransactionExecutionStatus2.REVERTED];
10852
- const successStates = options?.successStates ?? [
10853
- TransactionExecutionStatus2.SUCCEEDED,
10854
- TransactionFinalityStatus2.ACCEPTED_ON_L1,
10855
- TransactionFinalityStatus2.ACCEPTED_ON_L2
10856
- ];
10857
- while (!onchain) {
10858
- await wait(retryInterval);
10859
- try {
10860
- txReceipt = await this.getTransactionReceipt(txHash);
10861
- const executionStatus = pascalToSnake(txReceipt.execution_status);
10862
- const finalityStatus = pascalToSnake(txReceipt.finality_status);
10863
- if (!executionStatus || !finalityStatus) {
10864
- const error = new Error("waiting for transaction status");
10865
- throw error;
10866
- }
10867
- if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
10868
- onchain = true;
10869
- } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
10870
- const message = `${executionStatus}: ${finalityStatus}: ${txReceipt.revert_reason}`;
10871
- const error = new Error(message);
10872
- error.response = txReceipt;
10873
- isErrorState = true;
10874
- throw error;
10875
- }
10876
- } catch (error) {
10877
- if (error instanceof Error && isErrorState) {
10878
- throw error;
10879
- }
10880
- if (retries === 0) {
10881
- throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
10882
- }
10883
- }
10884
- retries -= 1;
10885
- }
10886
- await wait(retryInterval);
10887
- return txReceipt;
10888
- }
10889
11273
  /**
10890
- * Gets the transaction count from a block.
10891
- *
10892
- *
10893
- * @param blockIdentifier
10894
- * @returns Number of transactions
11274
+ * NEW: Estimate the fee for a message from L1
11275
+ * @param message Message From L1
10895
11276
  */
10896
- async getTransactionCount(blockIdentifier = this.blockIdentifier) {
11277
+ async estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
11278
+ const { from_address, to_address, entry_point_selector, payload } = message;
11279
+ const formattedMessage = {
11280
+ from_address: toHex(from_address),
11281
+ to_address: toHex(to_address),
11282
+ entry_point_selector: getSelector(entry_point_selector),
11283
+ payload: getHexStringArray(payload)
11284
+ };
10897
11285
  const block_id = new Block(blockIdentifier).identifier;
10898
- return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
10899
- }
10900
- /**
10901
- * Gets the latest block number
10902
- *
10903
- *
10904
- * @returns Number of the latest block
10905
- */
10906
- async getBlockNumber() {
10907
- return this.fetchEndpoint("starknet_blockNumber");
11286
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
11287
+ message: formattedMessage,
11288
+ block_id
11289
+ });
10908
11290
  }
10909
11291
  /**
10910
- * Gets syncing status of the node
10911
- *
10912
- *
11292
+ * Returns an object about the sync status, or false if the node is not synching
10913
11293
  * @returns Object with the stats data
10914
11294
  */
10915
11295
  async getSyncingStats() {
10916
11296
  return this.fetchEndpoint("starknet_syncing");
10917
11297
  }
10918
11298
  /**
10919
- * Gets all the events filtered
10920
- *
10921
- *
11299
+ * Returns all events matching the given filter
10922
11300
  * @returns events and the pagination of the events
10923
11301
  */
10924
11302
  async getEvents(eventFilter) {
10925
11303
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
10926
11304
  }
10927
- async getSimulateTransaction(invocations, {
10928
- blockIdentifier = this.blockIdentifier,
10929
- skipValidate = false,
10930
- skipExecute = false,
10931
- // @deprecated
10932
- skipFeeCharge = true
10933
- // Pathfinder currently does not support `starknet_simulateTransactions` without `SKIP_FEE_CHARGE` simulation flag being set. This will become supported in a future release
10934
- }) {
10935
- const block_id = new Block(blockIdentifier).identifier;
10936
- const simulationFlags = [];
10937
- if (skipValidate)
10938
- simulationFlags.push(SimulationFlag.SKIP_VALIDATE);
10939
- if (skipExecute || skipFeeCharge)
10940
- simulationFlags.push(SimulationFlag.SKIP_FEE_CHARGE);
10941
- return this.fetchEndpoint("starknet_simulateTransactions", {
10942
- block_id,
10943
- transactions: invocations.map((it) => this.buildTransaction(it)),
10944
- simulation_flags: simulationFlags
10945
- }).then(this.responseParser.parseSimulateTransactionResponse);
10946
- }
11305
+ /**
11306
+ * StarknetId Endpoint (get name from address)
11307
+ */
10947
11308
  async getStarkName(address, StarknetIdContract2) {
10948
11309
  return getStarkName(this, address, StarknetIdContract2);
10949
11310
  }
11311
+ /**
11312
+ * StarknetId Endpoint (get address from name)
11313
+ */
10950
11314
  async getAddressFromStarkName(name, StarknetIdContract2) {
10951
11315
  return getAddressFromStarkName(this, name, StarknetIdContract2);
10952
11316
  }
@@ -10959,12 +11323,11 @@ var starknet = (() => {
10959
11323
  };
10960
11324
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
10961
11325
  return {
10962
- type: rpc_exports.TransactionType.INVOKE,
11326
+ type: rpc_exports.ETransactionType.INVOKE,
10963
11327
  // Diff between sequencer and rpc invoke type
10964
11328
  sender_address: invocation.contractAddress,
10965
11329
  calldata: CallData.toHex(invocation.calldata),
10966
11330
  version: toHex(invocation.version || defaultVersions.v1),
10967
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
10968
11331
  ...details
10969
11332
  };
10970
11333
  }
@@ -10975,7 +11338,6 @@ var starknet = (() => {
10975
11338
  contract_class: invocation.contract,
10976
11339
  sender_address: invocation.senderAddress,
10977
11340
  version: toHex(invocation.version || defaultVersions.v1),
10978
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
10979
11341
  ...details
10980
11342
  };
10981
11343
  }
@@ -10989,7 +11351,6 @@ var starknet = (() => {
10989
11351
  compiled_class_hash: invocation.compiledClassHash || "",
10990
11352
  sender_address: invocation.senderAddress,
10991
11353
  version: toHex(invocation.version || defaultVersions.v2),
10992
- // HEX_STR_TRANSACTION_VERSION_2, // as any HOTFIX TODO: Resolve spec version
10993
11354
  ...details
10994
11355
  };
10995
11356
  }
@@ -11673,7 +12034,7 @@ ${res.tx_failure_reason.error_message}`;
11673
12034
  } else if (providerOrOptions && "sequencer" in providerOrOptions) {
11674
12035
  this.provider = new SequencerProvider(providerOrOptions.sequencer);
11675
12036
  } else {
11676
- this.provider = new SequencerProvider();
12037
+ this.provider = new RpcProvider();
11677
12038
  }
11678
12039
  }
11679
12040
  async getChainId() {
@@ -12123,7 +12484,7 @@ ${res.tx_failure_reason.error_message}`;
12123
12484
  // src/utils/events.ts
12124
12485
  function parseUDCEvent(txReceipt) {
12125
12486
  if (!txReceipt.events) {
12126
- throw new Error("UDC emited event is empty");
12487
+ throw new Error("UDC emitted event is empty");
12127
12488
  }
12128
12489
  const event = txReceipt.events.find(
12129
12490
  (it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
@@ -12662,7 +13023,7 @@ ${res.tx_failure_reason.error_message}`;
12662
13023
  };
12663
13024
 
12664
13025
  // src/provider/index.ts
12665
- var defaultProvider = new Provider();
13026
+ var defaultProvider = new Provider({ rpc: { default: true } });
12666
13027
 
12667
13028
  // src/account/interface.ts
12668
13029
  var AccountInterface = class extends ProviderInterface {
@@ -13051,8 +13412,8 @@ ${res.tx_failure_reason.error_message}`;
13051
13412
  }
13052
13413
  function getChecksumAddress(address) {
13053
13414
  const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
13054
- const hex = removeHexPrefix(keccakBn(address));
13055
- const hashed = hexToBytes(hex.padStart(64, "0"));
13415
+ const hex2 = removeHexPrefix(keccakBn(address));
13416
+ const hashed = hexToBytes(hex2.padStart(64, "0"));
13056
13417
  for (let i = 0; i < chars.length; i += 2) {
13057
13418
  if (hashed[i >> 1] >> 4 >= 8) {
13058
13419
  chars[i] = chars[i].toUpperCase();
@@ -13073,6 +13434,9 @@ ${res.tx_failure_reason.error_message}`;
13073
13434
  })();
13074
13435
  /*! Bundled license information:
13075
13436
 
13437
+ @scure/base/lib/esm/index.js:
13438
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
13439
+
13076
13440
  @noble/curves/esm/abstract/utils.js:
13077
13441
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
13078
13442