starknet 5.9.2 → 5.10.1
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.
- package/CHANGELOG.md +20 -0
- package/dist/index.d.ts +92 -71
- package/dist/index.global.js +1872 -1839
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +679 -641
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +671 -633
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.global.js
CHANGED
|
@@ -702,492 +702,821 @@ var starknet = (() => {
|
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
|
|
705
|
-
// src/utils/
|
|
706
|
-
var
|
|
707
|
-
__export(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
keccakBn: () => keccakBn,
|
|
725
|
-
poseidon: () => poseidon_exports,
|
|
726
|
-
starknetKeccak: () => starknetKeccak,
|
|
727
|
-
transactionVersion: () => transactionVersion,
|
|
728
|
-
transactionVersion_2: () => transactionVersion_2
|
|
705
|
+
// src/utils/num.ts
|
|
706
|
+
var num_exports = {};
|
|
707
|
+
__export(num_exports, {
|
|
708
|
+
assertInRange: () => assertInRange,
|
|
709
|
+
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
710
|
+
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
711
|
+
cleanHex: () => cleanHex,
|
|
712
|
+
getDecimalString: () => getDecimalString,
|
|
713
|
+
getHexString: () => getHexString,
|
|
714
|
+
getHexStringArray: () => getHexStringArray,
|
|
715
|
+
hexToBytes: () => hexToBytes2,
|
|
716
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
717
|
+
isBigInt: () => isBigInt,
|
|
718
|
+
isHex: () => isHex,
|
|
719
|
+
isStringWholeNumber: () => isStringWholeNumber,
|
|
720
|
+
toBigInt: () => toBigInt,
|
|
721
|
+
toCairoBool: () => toCairoBool,
|
|
722
|
+
toHex: () => toHex,
|
|
723
|
+
toHexString: () => toHexString
|
|
729
724
|
});
|
|
730
725
|
|
|
731
|
-
// node_modules/
|
|
732
|
-
var
|
|
733
|
-
__export(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
poseidonHash: () => poseidonHash,
|
|
754
|
-
poseidonHashFunc: () => poseidonHashFunc,
|
|
755
|
-
poseidonHashMany: () => poseidonHashMany,
|
|
756
|
-
poseidonHashSingle: () => poseidonHashSingle,
|
|
757
|
-
poseidonSmall: () => poseidonSmall,
|
|
758
|
-
sign: () => sign,
|
|
759
|
-
utils: () => utils,
|
|
760
|
-
verify: () => verify
|
|
726
|
+
// node_modules/@noble/curves/esm/abstract/utils.js
|
|
727
|
+
var utils_exports = {};
|
|
728
|
+
__export(utils_exports, {
|
|
729
|
+
bitGet: () => bitGet,
|
|
730
|
+
bitLen: () => bitLen,
|
|
731
|
+
bitMask: () => bitMask,
|
|
732
|
+
bitSet: () => bitSet,
|
|
733
|
+
bytesToHex: () => bytesToHex,
|
|
734
|
+
bytesToNumberBE: () => bytesToNumberBE,
|
|
735
|
+
bytesToNumberLE: () => bytesToNumberLE,
|
|
736
|
+
concatBytes: () => concatBytes,
|
|
737
|
+
createHmacDrbg: () => createHmacDrbg,
|
|
738
|
+
ensureBytes: () => ensureBytes,
|
|
739
|
+
equalBytes: () => equalBytes,
|
|
740
|
+
hexToBytes: () => hexToBytes,
|
|
741
|
+
hexToNumber: () => hexToNumber,
|
|
742
|
+
numberToBytesBE: () => numberToBytesBE,
|
|
743
|
+
numberToBytesLE: () => numberToBytesLE,
|
|
744
|
+
numberToHexUnpadded: () => numberToHexUnpadded,
|
|
745
|
+
numberToVarBytesBE: () => numberToVarBytesBE,
|
|
746
|
+
utf8ToBytes: () => utf8ToBytes,
|
|
747
|
+
validateObject: () => validateObject
|
|
761
748
|
});
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
749
|
+
var _0n = BigInt(0);
|
|
750
|
+
var _1n = BigInt(1);
|
|
751
|
+
var _2n = BigInt(2);
|
|
752
|
+
var u8a = (a) => a instanceof Uint8Array;
|
|
753
|
+
var hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
|
|
754
|
+
function bytesToHex(bytes2) {
|
|
755
|
+
if (!u8a(bytes2))
|
|
756
|
+
throw new Error("Uint8Array expected");
|
|
757
|
+
let hex = "";
|
|
758
|
+
for (let i = 0; i < bytes2.length; i++) {
|
|
759
|
+
hex += hexes[bytes2[i]];
|
|
760
|
+
}
|
|
761
|
+
return hex;
|
|
767
762
|
}
|
|
768
|
-
function
|
|
769
|
-
|
|
770
|
-
|
|
763
|
+
function numberToHexUnpadded(num) {
|
|
764
|
+
const hex = num.toString(16);
|
|
765
|
+
return hex.length & 1 ? `0${hex}` : hex;
|
|
771
766
|
}
|
|
772
|
-
function
|
|
773
|
-
if (
|
|
774
|
-
throw new
|
|
775
|
-
|
|
776
|
-
throw new TypeError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
767
|
+
function hexToNumber(hex) {
|
|
768
|
+
if (typeof hex !== "string")
|
|
769
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
770
|
+
return BigInt(hex === "" ? "0" : `0x${hex}`);
|
|
777
771
|
}
|
|
778
|
-
function
|
|
779
|
-
if (typeof
|
|
780
|
-
throw new Error("
|
|
781
|
-
|
|
782
|
-
|
|
772
|
+
function hexToBytes(hex) {
|
|
773
|
+
if (typeof hex !== "string")
|
|
774
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
775
|
+
if (hex.length % 2)
|
|
776
|
+
throw new Error("hex string is invalid: unpadded " + hex.length);
|
|
777
|
+
const array = new Uint8Array(hex.length / 2);
|
|
778
|
+
for (let i = 0; i < array.length; i++) {
|
|
779
|
+
const j = i * 2;
|
|
780
|
+
const hexByte = hex.slice(j, j + 2);
|
|
781
|
+
const byte = Number.parseInt(hexByte, 16);
|
|
782
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
783
|
+
throw new Error("invalid byte sequence");
|
|
784
|
+
array[i] = byte;
|
|
785
|
+
}
|
|
786
|
+
return array;
|
|
783
787
|
}
|
|
784
|
-
function
|
|
785
|
-
|
|
786
|
-
throw new Error("Hash instance has been destroyed");
|
|
787
|
-
if (checkFinished && instance.finished)
|
|
788
|
-
throw new Error("Hash#digest() has already been called");
|
|
788
|
+
function bytesToNumberBE(bytes2) {
|
|
789
|
+
return hexToNumber(bytesToHex(bytes2));
|
|
789
790
|
}
|
|
790
|
-
function
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
791
|
+
function bytesToNumberLE(bytes2) {
|
|
792
|
+
if (!u8a(bytes2))
|
|
793
|
+
throw new Error("Uint8Array expected");
|
|
794
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
|
|
795
|
+
}
|
|
796
|
+
var numberToBytesBE = (n, len) => hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
797
|
+
var numberToBytesLE = (n, len) => numberToBytesBE(n, len).reverse();
|
|
798
|
+
var numberToVarBytesBE = (n) => hexToBytes(numberToHexUnpadded(n));
|
|
799
|
+
function ensureBytes(title, hex, expectedLength) {
|
|
800
|
+
let res;
|
|
801
|
+
if (typeof hex === "string") {
|
|
802
|
+
try {
|
|
803
|
+
res = hexToBytes(hex);
|
|
804
|
+
} catch (e) {
|
|
805
|
+
throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
|
|
806
|
+
}
|
|
807
|
+
} else if (u8a(hex)) {
|
|
808
|
+
res = Uint8Array.from(hex);
|
|
809
|
+
} else {
|
|
810
|
+
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
795
811
|
}
|
|
812
|
+
const len = res.length;
|
|
813
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
814
|
+
throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
|
|
815
|
+
return res;
|
|
796
816
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/_u64.js
|
|
808
|
-
var U32_MASK64 = BigInt(2 ** 32 - 1);
|
|
809
|
-
var _32n = BigInt(32);
|
|
810
|
-
function fromBig(n, le = false) {
|
|
811
|
-
if (le)
|
|
812
|
-
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
813
|
-
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
817
|
+
function concatBytes(...arrs) {
|
|
818
|
+
const r = new Uint8Array(arrs.reduce((sum, a) => sum + a.length, 0));
|
|
819
|
+
let pad = 0;
|
|
820
|
+
arrs.forEach((a) => {
|
|
821
|
+
if (!u8a(a))
|
|
822
|
+
throw new Error("Uint8Array expected");
|
|
823
|
+
r.set(a, pad);
|
|
824
|
+
pad += a.length;
|
|
825
|
+
});
|
|
826
|
+
return r;
|
|
814
827
|
}
|
|
815
|
-
function
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
for (let i = 0; i <
|
|
819
|
-
|
|
820
|
-
|
|
828
|
+
function equalBytes(b1, b2) {
|
|
829
|
+
if (b1.length !== b2.length)
|
|
830
|
+
return false;
|
|
831
|
+
for (let i = 0; i < b1.length; i++)
|
|
832
|
+
if (b1[i] !== b2[i])
|
|
833
|
+
return false;
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
function utf8ToBytes(str) {
|
|
837
|
+
if (typeof str !== "string") {
|
|
838
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
821
839
|
}
|
|
822
|
-
return
|
|
840
|
+
return new TextEncoder().encode(str);
|
|
823
841
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
830
|
-
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
831
|
-
var rotr32H = (h, l) => l;
|
|
832
|
-
var rotr32L = (h, l) => h;
|
|
833
|
-
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
834
|
-
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
835
|
-
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
836
|
-
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
837
|
-
function add(Ah, Al, Bh, Bl) {
|
|
838
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
839
|
-
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
842
|
+
function bitLen(n) {
|
|
843
|
+
let len;
|
|
844
|
+
for (len = 0; n > 0n; n >>= _1n, len += 1)
|
|
845
|
+
;
|
|
846
|
+
return len;
|
|
840
847
|
}
|
|
841
|
-
var
|
|
842
|
-
var
|
|
843
|
-
var
|
|
844
|
-
var
|
|
845
|
-
var
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
848
|
+
var bitGet = (n, pos) => n >> BigInt(pos) & 1n;
|
|
849
|
+
var bitSet = (n, pos, value) => n | (value ? _1n : _0n) << BigInt(pos);
|
|
850
|
+
var bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
|
|
851
|
+
var u8n = (data) => new Uint8Array(data);
|
|
852
|
+
var u8fr = (arr) => Uint8Array.from(arr);
|
|
853
|
+
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
854
|
+
if (typeof hashLen !== "number" || hashLen < 2)
|
|
855
|
+
throw new Error("hashLen must be a number");
|
|
856
|
+
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
857
|
+
throw new Error("qByteLen must be a number");
|
|
858
|
+
if (typeof hmacFn !== "function")
|
|
859
|
+
throw new Error("hmacFn must be a function");
|
|
860
|
+
let v = u8n(hashLen);
|
|
861
|
+
let k = u8n(hashLen);
|
|
862
|
+
let i = 0;
|
|
863
|
+
const reset = () => {
|
|
864
|
+
v.fill(1);
|
|
865
|
+
k.fill(0);
|
|
866
|
+
i = 0;
|
|
867
|
+
};
|
|
868
|
+
const h = (...b) => hmacFn(k, v, ...b);
|
|
869
|
+
const reseed = (seed = u8n()) => {
|
|
870
|
+
k = h(u8fr([0]), seed);
|
|
871
|
+
v = h();
|
|
872
|
+
if (seed.length === 0)
|
|
873
|
+
return;
|
|
874
|
+
k = h(u8fr([1]), seed);
|
|
875
|
+
v = h();
|
|
876
|
+
};
|
|
877
|
+
const gen2 = () => {
|
|
878
|
+
if (i++ >= 1e3)
|
|
879
|
+
throw new Error("drbg: tried 1000 values");
|
|
880
|
+
let len = 0;
|
|
881
|
+
const out = [];
|
|
882
|
+
while (len < qByteLen) {
|
|
883
|
+
v = h();
|
|
884
|
+
const sl = v.slice();
|
|
885
|
+
out.push(sl);
|
|
886
|
+
len += v.length;
|
|
887
|
+
}
|
|
888
|
+
return concatBytes(...out);
|
|
889
|
+
};
|
|
890
|
+
const genUntil = (seed, pred) => {
|
|
891
|
+
reset();
|
|
892
|
+
reseed(seed);
|
|
893
|
+
let res = void 0;
|
|
894
|
+
while (!(res = pred(gen2())))
|
|
895
|
+
reseed();
|
|
896
|
+
reset();
|
|
897
|
+
return res;
|
|
898
|
+
};
|
|
899
|
+
return genUntil;
|
|
900
|
+
}
|
|
901
|
+
var validatorFns = {
|
|
902
|
+
bigint: (val) => typeof val === "bigint",
|
|
903
|
+
function: (val) => typeof val === "function",
|
|
904
|
+
boolean: (val) => typeof val === "boolean",
|
|
905
|
+
string: (val) => typeof val === "string",
|
|
906
|
+
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
907
|
+
array: (val) => Array.isArray(val),
|
|
908
|
+
field: (val, object) => object.Fp.isValid(val),
|
|
909
|
+
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
870
910
|
};
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
911
|
+
function validateObject(object, validators, optValidators = {}) {
|
|
912
|
+
const checkField = (fieldName, type, isOptional) => {
|
|
913
|
+
const checkVal = validatorFns[type];
|
|
914
|
+
if (typeof checkVal !== "function")
|
|
915
|
+
throw new Error(`Invalid validator "${type}", expected function`);
|
|
916
|
+
const val = object[fieldName];
|
|
917
|
+
if (isOptional && val === void 0)
|
|
918
|
+
return;
|
|
919
|
+
if (!checkVal(val, object)) {
|
|
920
|
+
throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
for (const [fieldName, type] of Object.entries(validators))
|
|
924
|
+
checkField(fieldName, type, false);
|
|
925
|
+
for (const [fieldName, type] of Object.entries(optValidators))
|
|
926
|
+
checkField(fieldName, type, true);
|
|
927
|
+
return object;
|
|
928
|
+
}
|
|
875
929
|
|
|
876
|
-
//
|
|
877
|
-
var
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
930
|
+
// src/utils/encode.ts
|
|
931
|
+
var encode_exports = {};
|
|
932
|
+
__export(encode_exports, {
|
|
933
|
+
IS_BROWSER: () => IS_BROWSER,
|
|
934
|
+
addHexPrefix: () => addHexPrefix,
|
|
935
|
+
arrayBufferToString: () => arrayBufferToString,
|
|
936
|
+
btoaUniversal: () => btoaUniversal,
|
|
937
|
+
buf2hex: () => buf2hex,
|
|
938
|
+
calcByteLength: () => calcByteLength,
|
|
939
|
+
padLeft: () => padLeft,
|
|
940
|
+
removeHexPrefix: () => removeHexPrefix,
|
|
941
|
+
sanitizeBytes: () => sanitizeBytes,
|
|
942
|
+
sanitizeHex: () => sanitizeHex,
|
|
943
|
+
utf8ToArray: () => utf8ToArray
|
|
944
|
+
});
|
|
945
|
+
var IS_BROWSER = typeof window !== "undefined";
|
|
946
|
+
var STRING_ZERO = "0";
|
|
947
|
+
function arrayBufferToString(array) {
|
|
948
|
+
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
889
949
|
}
|
|
890
|
-
function
|
|
891
|
-
|
|
892
|
-
data = utf8ToBytes(data);
|
|
893
|
-
if (!(data instanceof Uint8Array))
|
|
894
|
-
throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
|
|
895
|
-
return data;
|
|
950
|
+
function btoaUniversal(b) {
|
|
951
|
+
return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString("base64");
|
|
896
952
|
}
|
|
897
|
-
function
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
953
|
+
function buf2hex(buffer) {
|
|
954
|
+
return [...buffer].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
955
|
+
}
|
|
956
|
+
function removeHexPrefix(hex) {
|
|
957
|
+
return hex.replace(/^0x/i, "");
|
|
958
|
+
}
|
|
959
|
+
function addHexPrefix(hex) {
|
|
960
|
+
return `0x${removeHexPrefix(hex)}`;
|
|
961
|
+
}
|
|
962
|
+
function padString(str, length, left, padding = STRING_ZERO) {
|
|
963
|
+
const diff = length - str.length;
|
|
964
|
+
let result = str;
|
|
965
|
+
if (diff > 0) {
|
|
966
|
+
const pad = padding.repeat(diff);
|
|
967
|
+
result = left ? pad + str : str + pad;
|
|
908
968
|
}
|
|
909
969
|
return result;
|
|
910
970
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
return this._cloneInto();
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
function wrapConstructor(hashConstructor) {
|
|
917
|
-
const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
|
|
918
|
-
const tmp = hashConstructor();
|
|
919
|
-
hashC.outputLen = tmp.outputLen;
|
|
920
|
-
hashC.blockLen = tmp.blockLen;
|
|
921
|
-
hashC.create = () => hashConstructor();
|
|
922
|
-
return hashC;
|
|
971
|
+
function padLeft(str, length, padding = STRING_ZERO) {
|
|
972
|
+
return padString(str, length, true, padding);
|
|
923
973
|
}
|
|
924
|
-
function
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
hashC.outputLen = tmp.outputLen;
|
|
928
|
-
hashC.blockLen = tmp.blockLen;
|
|
929
|
-
hashC.create = (opts) => hashCons(opts);
|
|
930
|
-
return hashC;
|
|
974
|
+
function calcByteLength(length, byteSize = 8) {
|
|
975
|
+
const remainder = length % byteSize;
|
|
976
|
+
return remainder ? (length - remainder) / byteSize * byteSize + byteSize : length;
|
|
931
977
|
}
|
|
932
|
-
function
|
|
933
|
-
|
|
934
|
-
|
|
978
|
+
function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
|
|
979
|
+
return padLeft(str, calcByteLength(str.length, byteSize), padding);
|
|
980
|
+
}
|
|
981
|
+
function sanitizeHex(hex) {
|
|
982
|
+
hex = removeHexPrefix(hex);
|
|
983
|
+
hex = sanitizeBytes(hex, 2);
|
|
984
|
+
if (hex) {
|
|
985
|
+
hex = addHexPrefix(hex);
|
|
935
986
|
}
|
|
936
|
-
|
|
987
|
+
return hex;
|
|
988
|
+
}
|
|
989
|
+
function utf8ToArray(str) {
|
|
990
|
+
return new TextEncoder().encode(str);
|
|
937
991
|
}
|
|
938
992
|
|
|
939
|
-
//
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
var _1n = BigInt(1);
|
|
943
|
-
var _2n = BigInt(2);
|
|
944
|
-
var _7n = BigInt(7);
|
|
945
|
-
var _256n = BigInt(256);
|
|
946
|
-
var _0x71n = BigInt(113);
|
|
947
|
-
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
948
|
-
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
949
|
-
SHA3_PI.push(2 * (5 * y + x));
|
|
950
|
-
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
951
|
-
let t = _0n;
|
|
952
|
-
for (let j = 0; j < 7; j++) {
|
|
953
|
-
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
954
|
-
if (R & _2n)
|
|
955
|
-
t ^= _1n << (_1n << BigInt(j)) - _1n;
|
|
956
|
-
}
|
|
957
|
-
_SHA3_IOTA.push(t);
|
|
993
|
+
// src/utils/num.ts
|
|
994
|
+
function isHex(hex) {
|
|
995
|
+
return /^0x[0-9a-f]*$/i.test(hex);
|
|
958
996
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
var rotlL = (h, l, s) => s > 32 ? u64_default.rotlBL(h, l, s) : u64_default.rotlSL(h, l, s);
|
|
962
|
-
function keccakP(s, rounds = 24) {
|
|
963
|
-
const B = new Uint32Array(5 * 2);
|
|
964
|
-
for (let round = 24 - rounds; round < 24; round++) {
|
|
965
|
-
for (let x = 0; x < 10; x++)
|
|
966
|
-
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
967
|
-
for (let x = 0; x < 10; x += 2) {
|
|
968
|
-
const idx1 = (x + 8) % 10;
|
|
969
|
-
const idx0 = (x + 2) % 10;
|
|
970
|
-
const B0 = B[idx0];
|
|
971
|
-
const B1 = B[idx0 + 1];
|
|
972
|
-
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
973
|
-
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
974
|
-
for (let y = 0; y < 50; y += 10) {
|
|
975
|
-
s[x + y] ^= Th;
|
|
976
|
-
s[x + y + 1] ^= Tl;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
let curH = s[2];
|
|
980
|
-
let curL = s[3];
|
|
981
|
-
for (let t = 0; t < 24; t++) {
|
|
982
|
-
const shift = SHA3_ROTL[t];
|
|
983
|
-
const Th = rotlH(curH, curL, shift);
|
|
984
|
-
const Tl = rotlL(curH, curL, shift);
|
|
985
|
-
const PI = SHA3_PI[t];
|
|
986
|
-
curH = s[PI];
|
|
987
|
-
curL = s[PI + 1];
|
|
988
|
-
s[PI] = Th;
|
|
989
|
-
s[PI + 1] = Tl;
|
|
990
|
-
}
|
|
991
|
-
for (let y = 0; y < 50; y += 10) {
|
|
992
|
-
for (let x = 0; x < 10; x++)
|
|
993
|
-
B[x] = s[y + x];
|
|
994
|
-
for (let x = 0; x < 10; x++)
|
|
995
|
-
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
996
|
-
}
|
|
997
|
-
s[0] ^= SHA3_IOTA_H[round];
|
|
998
|
-
s[1] ^= SHA3_IOTA_L[round];
|
|
999
|
-
}
|
|
1000
|
-
B.fill(0);
|
|
997
|
+
function toBigInt(value) {
|
|
998
|
+
return BigInt(value);
|
|
1001
999
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
state[this.pos++] ^= data[pos++];
|
|
1034
|
-
if (this.pos === blockLen)
|
|
1035
|
-
this.keccak();
|
|
1036
|
-
}
|
|
1037
|
-
return this;
|
|
1038
|
-
}
|
|
1039
|
-
finish() {
|
|
1040
|
-
if (this.finished)
|
|
1041
|
-
return;
|
|
1042
|
-
this.finished = true;
|
|
1043
|
-
const { state, suffix, pos, blockLen } = this;
|
|
1044
|
-
state[pos] ^= suffix;
|
|
1045
|
-
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
1046
|
-
this.keccak();
|
|
1047
|
-
state[blockLen - 1] ^= 128;
|
|
1048
|
-
this.keccak();
|
|
1049
|
-
}
|
|
1050
|
-
writeInto(out) {
|
|
1051
|
-
assert_default.exists(this, false);
|
|
1052
|
-
assert_default.bytes(out);
|
|
1053
|
-
this.finish();
|
|
1054
|
-
const bufferOut = this.state;
|
|
1055
|
-
const { blockLen } = this;
|
|
1056
|
-
for (let pos = 0, len = out.length; pos < len; ) {
|
|
1057
|
-
if (this.posOut >= blockLen)
|
|
1058
|
-
this.keccak();
|
|
1059
|
-
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
1060
|
-
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
1061
|
-
this.posOut += take;
|
|
1062
|
-
pos += take;
|
|
1063
|
-
}
|
|
1064
|
-
return out;
|
|
1065
|
-
}
|
|
1066
|
-
xofInto(out) {
|
|
1067
|
-
if (!this.enableXOF)
|
|
1068
|
-
throw new Error("XOF is not possible for this instance");
|
|
1069
|
-
return this.writeInto(out);
|
|
1000
|
+
function isBigInt(value) {
|
|
1001
|
+
return typeof value === "bigint";
|
|
1002
|
+
}
|
|
1003
|
+
function toHex(number3) {
|
|
1004
|
+
return addHexPrefix(toBigInt(number3).toString(16));
|
|
1005
|
+
}
|
|
1006
|
+
function hexToDecimalString(hex) {
|
|
1007
|
+
return BigInt(addHexPrefix(hex)).toString(10);
|
|
1008
|
+
}
|
|
1009
|
+
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
1010
|
+
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
1011
|
+
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
1012
|
+
const inputBigInt = BigInt(input);
|
|
1013
|
+
const lowerBoundBigInt = BigInt(lowerBound);
|
|
1014
|
+
const upperBoundBigInt = BigInt(upperBound);
|
|
1015
|
+
assert(
|
|
1016
|
+
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
1017
|
+
`Message not signable, ${messageSuffix}.`
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
1021
|
+
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
1022
|
+
}
|
|
1023
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
1024
|
+
return rawCalldata.map((x) => toHex(x));
|
|
1025
|
+
}
|
|
1026
|
+
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
1027
|
+
var toHexString = (value) => toHex(value);
|
|
1028
|
+
function getDecimalString(value) {
|
|
1029
|
+
if (isHex(value)) {
|
|
1030
|
+
return hexToDecimalString(value);
|
|
1070
1031
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
return this.xofInto(new Uint8Array(bytes2));
|
|
1032
|
+
if (isStringWholeNumber(value)) {
|
|
1033
|
+
return value;
|
|
1074
1034
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
this.destroy();
|
|
1081
|
-
return out;
|
|
1035
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
1036
|
+
}
|
|
1037
|
+
function getHexString(value) {
|
|
1038
|
+
if (isHex(value)) {
|
|
1039
|
+
return value;
|
|
1082
1040
|
}
|
|
1083
|
-
|
|
1084
|
-
return
|
|
1041
|
+
if (isStringWholeNumber(value)) {
|
|
1042
|
+
return toHexString(value);
|
|
1085
1043
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1044
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
1045
|
+
}
|
|
1046
|
+
function getHexStringArray(value) {
|
|
1047
|
+
return value.map((el) => getHexString(el));
|
|
1048
|
+
}
|
|
1049
|
+
var toCairoBool = (value) => (+value).toString();
|
|
1050
|
+
function hexToBytes2(value) {
|
|
1051
|
+
if (!isHex(value))
|
|
1052
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
1053
|
+
let adaptedValue = removeHexPrefix(value);
|
|
1054
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
1055
|
+
adaptedValue = `0${adaptedValue}`;
|
|
1089
1056
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1057
|
+
return hexToBytes(adaptedValue);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// node_modules/micro-starknet/lib/esm/index.js
|
|
1061
|
+
var esm_exports = {};
|
|
1062
|
+
__export(esm_exports, {
|
|
1063
|
+
CURVE: () => CURVE,
|
|
1064
|
+
Fp251: () => Fp251,
|
|
1065
|
+
Fp253: () => Fp253,
|
|
1066
|
+
ProjectivePoint: () => ProjectivePoint,
|
|
1067
|
+
Signature: () => Signature,
|
|
1068
|
+
_poseidonMDS: () => _poseidonMDS,
|
|
1069
|
+
_starkCurve: () => _starkCurve,
|
|
1070
|
+
computeHashOnElements: () => computeHashOnElements,
|
|
1071
|
+
ethSigToPrivate: () => ethSigToPrivate,
|
|
1072
|
+
getAccountPath: () => getAccountPath,
|
|
1073
|
+
getPublicKey: () => getPublicKey,
|
|
1074
|
+
getSharedSecret: () => getSharedSecret,
|
|
1075
|
+
getStarkKey: () => getStarkKey,
|
|
1076
|
+
grindKey: () => grindKey,
|
|
1077
|
+
hashChain: () => hashChain,
|
|
1078
|
+
keccak: () => keccak,
|
|
1079
|
+
pedersen: () => pedersen,
|
|
1080
|
+
poseidonBasic: () => poseidonBasic,
|
|
1081
|
+
poseidonCreate: () => poseidonCreate,
|
|
1082
|
+
poseidonHash: () => poseidonHash,
|
|
1083
|
+
poseidonHashFunc: () => poseidonHashFunc,
|
|
1084
|
+
poseidonHashMany: () => poseidonHashMany,
|
|
1085
|
+
poseidonHashSingle: () => poseidonHashSingle,
|
|
1086
|
+
poseidonSmall: () => poseidonSmall,
|
|
1087
|
+
sign: () => sign,
|
|
1088
|
+
utils: () => utils,
|
|
1089
|
+
verify: () => verify
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/_assert.js
|
|
1093
|
+
function number(n) {
|
|
1094
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
1095
|
+
throw new Error(`Wrong positive integer: ${n}`);
|
|
1096
|
+
}
|
|
1097
|
+
function bool(b) {
|
|
1098
|
+
if (typeof b !== "boolean")
|
|
1099
|
+
throw new Error(`Expected boolean, not ${b}`);
|
|
1100
|
+
}
|
|
1101
|
+
function bytes(b, ...lengths) {
|
|
1102
|
+
if (!(b instanceof Uint8Array))
|
|
1103
|
+
throw new TypeError("Expected Uint8Array");
|
|
1104
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1105
|
+
throw new TypeError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
1106
|
+
}
|
|
1107
|
+
function hash(hash2) {
|
|
1108
|
+
if (typeof hash2 !== "function" || typeof hash2.create !== "function")
|
|
1109
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
1110
|
+
number(hash2.outputLen);
|
|
1111
|
+
number(hash2.blockLen);
|
|
1112
|
+
}
|
|
1113
|
+
function exists(instance, checkFinished = true) {
|
|
1114
|
+
if (instance.destroyed)
|
|
1115
|
+
throw new Error("Hash instance has been destroyed");
|
|
1116
|
+
if (checkFinished && instance.finished)
|
|
1117
|
+
throw new Error("Hash#digest() has already been called");
|
|
1118
|
+
}
|
|
1119
|
+
function output(out, instance) {
|
|
1120
|
+
bytes(out);
|
|
1121
|
+
const min = instance.outputLen;
|
|
1122
|
+
if (out.length < min) {
|
|
1123
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
1103
1124
|
}
|
|
1125
|
+
}
|
|
1126
|
+
var assert2 = {
|
|
1127
|
+
number,
|
|
1128
|
+
bool,
|
|
1129
|
+
bytes,
|
|
1130
|
+
hash,
|
|
1131
|
+
exists,
|
|
1132
|
+
output
|
|
1104
1133
|
};
|
|
1105
|
-
var
|
|
1106
|
-
var sha3_224 = gen(6, 144, 224 / 8);
|
|
1107
|
-
var sha3_256 = gen(6, 136, 256 / 8);
|
|
1108
|
-
var sha3_384 = gen(6, 104, 384 / 8);
|
|
1109
|
-
var sha3_512 = gen(6, 72, 512 / 8);
|
|
1110
|
-
var keccak_224 = gen(1, 144, 224 / 8);
|
|
1111
|
-
var keccak_256 = gen(1, 136, 256 / 8);
|
|
1112
|
-
var keccak_384 = gen(1, 104, 384 / 8);
|
|
1113
|
-
var keccak_512 = gen(1, 72, 512 / 8);
|
|
1114
|
-
var genShake = (suffix, blockLen, outputLen) => wrapConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
|
|
1115
|
-
var shake128 = genShake(31, 168, 128 / 8);
|
|
1116
|
-
var shake256 = genShake(31, 136, 256 / 8);
|
|
1134
|
+
var assert_default = assert2;
|
|
1117
1135
|
|
|
1118
|
-
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1136
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/_u64.js
|
|
1137
|
+
var U32_MASK64 = BigInt(2 ** 32 - 1);
|
|
1138
|
+
var _32n = BigInt(32);
|
|
1139
|
+
function fromBig(n, le = false) {
|
|
1140
|
+
if (le)
|
|
1141
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
1142
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
1143
|
+
}
|
|
1144
|
+
function split(lst, le = false) {
|
|
1145
|
+
let Ah = new Uint32Array(lst.length);
|
|
1146
|
+
let Al = new Uint32Array(lst.length);
|
|
1147
|
+
for (let i = 0; i < lst.length; i++) {
|
|
1148
|
+
const { h, l } = fromBig(lst[i], le);
|
|
1149
|
+
[Ah[i], Al[i]] = [h, l];
|
|
1150
|
+
}
|
|
1151
|
+
return [Ah, Al];
|
|
1152
|
+
}
|
|
1153
|
+
var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
|
|
1154
|
+
var shrSH = (h, l, s) => h >>> s;
|
|
1155
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1156
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
1157
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
1158
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
1159
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
1160
|
+
var rotr32H = (h, l) => l;
|
|
1161
|
+
var rotr32L = (h, l) => h;
|
|
1162
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
1163
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
1164
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
1165
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
1166
|
+
function add(Ah, Al, Bh, Bl) {
|
|
1167
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
1168
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
1169
|
+
}
|
|
1170
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
1171
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
1172
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
1173
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
1174
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
1175
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
1176
|
+
var u64 = {
|
|
1177
|
+
fromBig,
|
|
1178
|
+
split,
|
|
1179
|
+
toBig,
|
|
1180
|
+
shrSH,
|
|
1181
|
+
shrSL,
|
|
1182
|
+
rotrSH,
|
|
1183
|
+
rotrSL,
|
|
1184
|
+
rotrBH,
|
|
1185
|
+
rotrBL,
|
|
1186
|
+
rotr32H,
|
|
1187
|
+
rotr32L,
|
|
1188
|
+
rotlSH,
|
|
1189
|
+
rotlSL,
|
|
1190
|
+
rotlBH,
|
|
1191
|
+
rotlBL,
|
|
1192
|
+
add,
|
|
1193
|
+
add3L,
|
|
1194
|
+
add3H,
|
|
1195
|
+
add4L,
|
|
1196
|
+
add4H,
|
|
1197
|
+
add5H,
|
|
1198
|
+
add5L
|
|
1199
|
+
};
|
|
1200
|
+
var u64_default = u64;
|
|
1201
|
+
|
|
1202
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/crypto.js
|
|
1203
|
+
var crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1204
|
+
|
|
1205
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/utils.js
|
|
1206
|
+
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
1207
|
+
var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
1208
|
+
var rotr = (word, shift) => word << 32 - shift | word >>> shift;
|
|
1209
|
+
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1210
|
+
if (!isLE)
|
|
1211
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
1212
|
+
var hexes2 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
|
|
1213
|
+
function utf8ToBytes2(str) {
|
|
1214
|
+
if (typeof str !== "string") {
|
|
1215
|
+
throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
|
|
1216
|
+
}
|
|
1217
|
+
return new TextEncoder().encode(str);
|
|
1218
|
+
}
|
|
1219
|
+
function toBytes(data) {
|
|
1220
|
+
if (typeof data === "string")
|
|
1221
|
+
data = utf8ToBytes2(data);
|
|
1222
|
+
if (!(data instanceof Uint8Array))
|
|
1223
|
+
throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
|
|
1224
|
+
return data;
|
|
1225
|
+
}
|
|
1226
|
+
function concatBytes2(...arrays) {
|
|
1227
|
+
if (!arrays.every((a) => a instanceof Uint8Array))
|
|
1228
|
+
throw new Error("Uint8Array list expected");
|
|
1229
|
+
if (arrays.length === 1)
|
|
1230
|
+
return arrays[0];
|
|
1231
|
+
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
1232
|
+
const result = new Uint8Array(length);
|
|
1233
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
1234
|
+
const arr = arrays[i];
|
|
1235
|
+
result.set(arr, pad);
|
|
1236
|
+
pad += arr.length;
|
|
1237
|
+
}
|
|
1238
|
+
return result;
|
|
1239
|
+
}
|
|
1240
|
+
var Hash = class {
|
|
1241
|
+
clone() {
|
|
1242
|
+
return this._cloneInto();
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
function wrapConstructor(hashConstructor) {
|
|
1246
|
+
const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
|
|
1247
|
+
const tmp = hashConstructor();
|
|
1248
|
+
hashC.outputLen = tmp.outputLen;
|
|
1249
|
+
hashC.blockLen = tmp.blockLen;
|
|
1250
|
+
hashC.create = () => hashConstructor();
|
|
1251
|
+
return hashC;
|
|
1252
|
+
}
|
|
1253
|
+
function wrapConstructorWithOpts(hashCons) {
|
|
1254
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
1255
|
+
const tmp = hashCons({});
|
|
1256
|
+
hashC.outputLen = tmp.outputLen;
|
|
1257
|
+
hashC.blockLen = tmp.blockLen;
|
|
1258
|
+
hashC.create = (opts) => hashCons(opts);
|
|
1259
|
+
return hashC;
|
|
1260
|
+
}
|
|
1261
|
+
function randomBytes(bytesLength = 32) {
|
|
1262
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
1263
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
1264
|
+
}
|
|
1265
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/sha3.js
|
|
1269
|
+
var [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
|
|
1270
|
+
var _0n2 = BigInt(0);
|
|
1271
|
+
var _1n2 = BigInt(1);
|
|
1272
|
+
var _2n2 = BigInt(2);
|
|
1273
|
+
var _7n = BigInt(7);
|
|
1274
|
+
var _256n = BigInt(256);
|
|
1275
|
+
var _0x71n = BigInt(113);
|
|
1276
|
+
for (let round = 0, R = _1n2, x = 1, y = 0; round < 24; round++) {
|
|
1277
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
1278
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
1279
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
1280
|
+
let t = _0n2;
|
|
1281
|
+
for (let j = 0; j < 7; j++) {
|
|
1282
|
+
R = (R << _1n2 ^ (R >> _7n) * _0x71n) % _256n;
|
|
1283
|
+
if (R & _2n2)
|
|
1284
|
+
t ^= _1n2 << (_1n2 << BigInt(j)) - _1n2;
|
|
1285
|
+
}
|
|
1286
|
+
_SHA3_IOTA.push(t);
|
|
1287
|
+
}
|
|
1288
|
+
var [SHA3_IOTA_H, SHA3_IOTA_L] = u64_default.split(_SHA3_IOTA, true);
|
|
1289
|
+
var rotlH = (h, l, s) => s > 32 ? u64_default.rotlBH(h, l, s) : u64_default.rotlSH(h, l, s);
|
|
1290
|
+
var rotlL = (h, l, s) => s > 32 ? u64_default.rotlBL(h, l, s) : u64_default.rotlSL(h, l, s);
|
|
1291
|
+
function keccakP(s, rounds = 24) {
|
|
1292
|
+
const B = new Uint32Array(5 * 2);
|
|
1293
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
1294
|
+
for (let x = 0; x < 10; x++)
|
|
1295
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
1296
|
+
for (let x = 0; x < 10; x += 2) {
|
|
1297
|
+
const idx1 = (x + 8) % 10;
|
|
1298
|
+
const idx0 = (x + 2) % 10;
|
|
1299
|
+
const B0 = B[idx0];
|
|
1300
|
+
const B1 = B[idx0 + 1];
|
|
1301
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
1302
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
1303
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1304
|
+
s[x + y] ^= Th;
|
|
1305
|
+
s[x + y + 1] ^= Tl;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
let curH = s[2];
|
|
1309
|
+
let curL = s[3];
|
|
1310
|
+
for (let t = 0; t < 24; t++) {
|
|
1311
|
+
const shift = SHA3_ROTL[t];
|
|
1312
|
+
const Th = rotlH(curH, curL, shift);
|
|
1313
|
+
const Tl = rotlL(curH, curL, shift);
|
|
1314
|
+
const PI = SHA3_PI[t];
|
|
1315
|
+
curH = s[PI];
|
|
1316
|
+
curL = s[PI + 1];
|
|
1317
|
+
s[PI] = Th;
|
|
1318
|
+
s[PI + 1] = Tl;
|
|
1319
|
+
}
|
|
1320
|
+
for (let y = 0; y < 50; y += 10) {
|
|
1321
|
+
for (let x = 0; x < 10; x++)
|
|
1322
|
+
B[x] = s[y + x];
|
|
1323
|
+
for (let x = 0; x < 10; x++)
|
|
1324
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
1325
|
+
}
|
|
1326
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
1327
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
1328
|
+
}
|
|
1329
|
+
B.fill(0);
|
|
1330
|
+
}
|
|
1331
|
+
var Keccak = class extends Hash {
|
|
1332
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
1133
1333
|
super();
|
|
1134
1334
|
this.blockLen = blockLen;
|
|
1335
|
+
this.suffix = suffix;
|
|
1135
1336
|
this.outputLen = outputLen;
|
|
1136
|
-
this.
|
|
1137
|
-
this.
|
|
1138
|
-
this.finished = false;
|
|
1139
|
-
this.length = 0;
|
|
1337
|
+
this.enableXOF = enableXOF;
|
|
1338
|
+
this.rounds = rounds;
|
|
1140
1339
|
this.pos = 0;
|
|
1340
|
+
this.posOut = 0;
|
|
1341
|
+
this.finished = false;
|
|
1141
1342
|
this.destroyed = false;
|
|
1142
|
-
|
|
1143
|
-
this.
|
|
1343
|
+
assert_default.number(outputLen);
|
|
1344
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
1345
|
+
throw new Error("Sha3 supports only keccak-f1600 function");
|
|
1346
|
+
this.state = new Uint8Array(200);
|
|
1347
|
+
this.state32 = u32(this.state);
|
|
1348
|
+
}
|
|
1349
|
+
keccak() {
|
|
1350
|
+
keccakP(this.state32, this.rounds);
|
|
1351
|
+
this.posOut = 0;
|
|
1352
|
+
this.pos = 0;
|
|
1144
1353
|
}
|
|
1145
1354
|
update(data) {
|
|
1146
1355
|
assert_default.exists(this);
|
|
1147
|
-
const {
|
|
1356
|
+
const { blockLen, state } = this;
|
|
1148
1357
|
data = toBytes(data);
|
|
1149
1358
|
const len = data.length;
|
|
1150
1359
|
for (let pos = 0; pos < len; ) {
|
|
1151
1360
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1159
|
-
this.pos += take;
|
|
1160
|
-
pos += take;
|
|
1161
|
-
if (this.pos === blockLen) {
|
|
1162
|
-
this.process(view, 0);
|
|
1163
|
-
this.pos = 0;
|
|
1164
|
-
}
|
|
1361
|
+
for (let i = 0; i < take; i++)
|
|
1362
|
+
state[this.pos++] ^= data[pos++];
|
|
1363
|
+
if (this.pos === blockLen)
|
|
1364
|
+
this.keccak();
|
|
1165
1365
|
}
|
|
1166
|
-
this.length += data.length;
|
|
1167
|
-
this.roundClean();
|
|
1168
1366
|
return this;
|
|
1169
1367
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1368
|
+
finish() {
|
|
1369
|
+
if (this.finished)
|
|
1370
|
+
return;
|
|
1173
1371
|
this.finished = true;
|
|
1174
|
-
const {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
this.
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1372
|
+
const { state, suffix, pos, blockLen } = this;
|
|
1373
|
+
state[pos] ^= suffix;
|
|
1374
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
1375
|
+
this.keccak();
|
|
1376
|
+
state[blockLen - 1] ^= 128;
|
|
1377
|
+
this.keccak();
|
|
1378
|
+
}
|
|
1379
|
+
writeInto(out) {
|
|
1380
|
+
assert_default.exists(this, false);
|
|
1381
|
+
assert_default.bytes(out);
|
|
1382
|
+
this.finish();
|
|
1383
|
+
const bufferOut = this.state;
|
|
1384
|
+
const { blockLen } = this;
|
|
1385
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
1386
|
+
if (this.posOut >= blockLen)
|
|
1387
|
+
this.keccak();
|
|
1388
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
1389
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
1390
|
+
this.posOut += take;
|
|
1391
|
+
pos += take;
|
|
1392
|
+
}
|
|
1393
|
+
return out;
|
|
1394
|
+
}
|
|
1395
|
+
xofInto(out) {
|
|
1396
|
+
if (!this.enableXOF)
|
|
1397
|
+
throw new Error("XOF is not possible for this instance");
|
|
1398
|
+
return this.writeInto(out);
|
|
1399
|
+
}
|
|
1400
|
+
xof(bytes2) {
|
|
1401
|
+
assert_default.number(bytes2);
|
|
1402
|
+
return this.xofInto(new Uint8Array(bytes2));
|
|
1403
|
+
}
|
|
1404
|
+
digestInto(out) {
|
|
1405
|
+
assert_default.output(out, this);
|
|
1406
|
+
if (this.finished)
|
|
1407
|
+
throw new Error("digest() was already called");
|
|
1408
|
+
this.writeInto(out);
|
|
1409
|
+
this.destroy();
|
|
1410
|
+
return out;
|
|
1411
|
+
}
|
|
1412
|
+
digest() {
|
|
1413
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
1414
|
+
}
|
|
1415
|
+
destroy() {
|
|
1416
|
+
this.destroyed = true;
|
|
1417
|
+
this.state.fill(0);
|
|
1418
|
+
}
|
|
1419
|
+
_cloneInto(to) {
|
|
1420
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
1421
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
1422
|
+
to.state32.set(this.state32);
|
|
1423
|
+
to.pos = this.pos;
|
|
1424
|
+
to.posOut = this.posOut;
|
|
1425
|
+
to.finished = this.finished;
|
|
1426
|
+
to.rounds = rounds;
|
|
1427
|
+
to.suffix = suffix;
|
|
1428
|
+
to.outputLen = outputLen;
|
|
1429
|
+
to.enableXOF = enableXOF;
|
|
1430
|
+
to.destroyed = this.destroyed;
|
|
1431
|
+
return to;
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
var gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
|
|
1435
|
+
var sha3_224 = gen(6, 144, 224 / 8);
|
|
1436
|
+
var sha3_256 = gen(6, 136, 256 / 8);
|
|
1437
|
+
var sha3_384 = gen(6, 104, 384 / 8);
|
|
1438
|
+
var sha3_512 = gen(6, 72, 512 / 8);
|
|
1439
|
+
var keccak_224 = gen(1, 144, 224 / 8);
|
|
1440
|
+
var keccak_256 = gen(1, 136, 256 / 8);
|
|
1441
|
+
var keccak_384 = gen(1, 104, 384 / 8);
|
|
1442
|
+
var keccak_512 = gen(1, 72, 512 / 8);
|
|
1443
|
+
var genShake = (suffix, blockLen, outputLen) => wrapConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
|
|
1444
|
+
var shake128 = genShake(31, 168, 128 / 8);
|
|
1445
|
+
var shake256 = genShake(31, 136, 256 / 8);
|
|
1446
|
+
|
|
1447
|
+
// node_modules/micro-starknet/node_modules/@noble/hashes/esm/_sha2.js
|
|
1448
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
1449
|
+
if (typeof view.setBigUint64 === "function")
|
|
1450
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
|
1451
|
+
const _32n2 = BigInt(32);
|
|
1452
|
+
const _u32_max = BigInt(4294967295);
|
|
1453
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
1454
|
+
const wl = Number(value & _u32_max);
|
|
1455
|
+
const h = isLE2 ? 4 : 0;
|
|
1456
|
+
const l = isLE2 ? 0 : 4;
|
|
1457
|
+
view.setUint32(byteOffset + h, wh, isLE2);
|
|
1458
|
+
view.setUint32(byteOffset + l, wl, isLE2);
|
|
1459
|
+
}
|
|
1460
|
+
var SHA2 = class extends Hash {
|
|
1461
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
1462
|
+
super();
|
|
1463
|
+
this.blockLen = blockLen;
|
|
1464
|
+
this.outputLen = outputLen;
|
|
1465
|
+
this.padOffset = padOffset;
|
|
1466
|
+
this.isLE = isLE2;
|
|
1467
|
+
this.finished = false;
|
|
1468
|
+
this.length = 0;
|
|
1469
|
+
this.pos = 0;
|
|
1470
|
+
this.destroyed = false;
|
|
1471
|
+
this.buffer = new Uint8Array(blockLen);
|
|
1472
|
+
this.view = createView(this.buffer);
|
|
1473
|
+
}
|
|
1474
|
+
update(data) {
|
|
1475
|
+
assert_default.exists(this);
|
|
1476
|
+
const { view, buffer, blockLen } = this;
|
|
1477
|
+
data = toBytes(data);
|
|
1478
|
+
const len = data.length;
|
|
1479
|
+
for (let pos = 0; pos < len; ) {
|
|
1480
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1481
|
+
if (take === blockLen) {
|
|
1482
|
+
const dataView = createView(data);
|
|
1483
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
1484
|
+
this.process(dataView, pos);
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1488
|
+
this.pos += take;
|
|
1489
|
+
pos += take;
|
|
1490
|
+
if (this.pos === blockLen) {
|
|
1491
|
+
this.process(view, 0);
|
|
1492
|
+
this.pos = 0;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
this.length += data.length;
|
|
1496
|
+
this.roundClean();
|
|
1497
|
+
return this;
|
|
1498
|
+
}
|
|
1499
|
+
digestInto(out) {
|
|
1500
|
+
assert_default.exists(this);
|
|
1501
|
+
assert_default.output(out, this);
|
|
1502
|
+
this.finished = true;
|
|
1503
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
1504
|
+
let { pos } = this;
|
|
1505
|
+
buffer[pos++] = 128;
|
|
1506
|
+
this.buffer.subarray(pos).fill(0);
|
|
1507
|
+
if (this.padOffset > blockLen - pos) {
|
|
1508
|
+
this.process(view, 0);
|
|
1509
|
+
pos = 0;
|
|
1510
|
+
}
|
|
1511
|
+
for (let i = pos; i < blockLen; i++)
|
|
1512
|
+
buffer[i] = 0;
|
|
1513
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
1514
|
+
this.process(view, 0);
|
|
1515
|
+
const oview = createView(out);
|
|
1516
|
+
const len = this.outputLen;
|
|
1517
|
+
if (len % 4)
|
|
1518
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1519
|
+
const outLen = len / 4;
|
|
1191
1520
|
const state = this.get();
|
|
1192
1521
|
if (outLen > state.length)
|
|
1193
1522
|
throw new Error("_sha2: outputLen bigger than state");
|
|
@@ -1382,52 +1711,52 @@ var starknet = (() => {
|
|
|
1382
1711
|
var sha224 = wrapConstructor(() => new SHA224());
|
|
1383
1712
|
|
|
1384
1713
|
// node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/utils.js
|
|
1385
|
-
var
|
|
1386
|
-
__export(
|
|
1387
|
-
bitGet: () =>
|
|
1388
|
-
bitLen: () =>
|
|
1389
|
-
bitMask: () =>
|
|
1390
|
-
bitSet: () =>
|
|
1391
|
-
bytesToHex: () =>
|
|
1392
|
-
bytesToNumberBE: () =>
|
|
1393
|
-
bytesToNumberLE: () =>
|
|
1394
|
-
concatBytes: () =>
|
|
1395
|
-
createHmacDrbg: () =>
|
|
1396
|
-
ensureBytes: () =>
|
|
1397
|
-
equalBytes: () =>
|
|
1398
|
-
hexToBytes: () =>
|
|
1399
|
-
hexToNumber: () =>
|
|
1400
|
-
numberToBytesBE: () =>
|
|
1401
|
-
numberToBytesLE: () =>
|
|
1402
|
-
numberToHexUnpadded: () =>
|
|
1403
|
-
numberToVarBytesBE: () =>
|
|
1404
|
-
utf8ToBytes: () =>
|
|
1405
|
-
validateObject: () =>
|
|
1714
|
+
var utils_exports2 = {};
|
|
1715
|
+
__export(utils_exports2, {
|
|
1716
|
+
bitGet: () => bitGet2,
|
|
1717
|
+
bitLen: () => bitLen2,
|
|
1718
|
+
bitMask: () => bitMask2,
|
|
1719
|
+
bitSet: () => bitSet2,
|
|
1720
|
+
bytesToHex: () => bytesToHex2,
|
|
1721
|
+
bytesToNumberBE: () => bytesToNumberBE2,
|
|
1722
|
+
bytesToNumberLE: () => bytesToNumberLE2,
|
|
1723
|
+
concatBytes: () => concatBytes3,
|
|
1724
|
+
createHmacDrbg: () => createHmacDrbg2,
|
|
1725
|
+
ensureBytes: () => ensureBytes2,
|
|
1726
|
+
equalBytes: () => equalBytes2,
|
|
1727
|
+
hexToBytes: () => hexToBytes3,
|
|
1728
|
+
hexToNumber: () => hexToNumber2,
|
|
1729
|
+
numberToBytesBE: () => numberToBytesBE2,
|
|
1730
|
+
numberToBytesLE: () => numberToBytesLE2,
|
|
1731
|
+
numberToHexUnpadded: () => numberToHexUnpadded2,
|
|
1732
|
+
numberToVarBytesBE: () => numberToVarBytesBE2,
|
|
1733
|
+
utf8ToBytes: () => utf8ToBytes3,
|
|
1734
|
+
validateObject: () => validateObject2
|
|
1406
1735
|
});
|
|
1407
|
-
var
|
|
1408
|
-
var
|
|
1409
|
-
var
|
|
1410
|
-
var
|
|
1411
|
-
var
|
|
1412
|
-
function
|
|
1413
|
-
if (!
|
|
1736
|
+
var _0n3 = BigInt(0);
|
|
1737
|
+
var _1n3 = BigInt(1);
|
|
1738
|
+
var _2n3 = BigInt(2);
|
|
1739
|
+
var u8a2 = (a) => a instanceof Uint8Array;
|
|
1740
|
+
var hexes3 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
|
|
1741
|
+
function bytesToHex2(bytes2) {
|
|
1742
|
+
if (!u8a2(bytes2))
|
|
1414
1743
|
throw new Error("Uint8Array expected");
|
|
1415
1744
|
let hex = "";
|
|
1416
1745
|
for (let i = 0; i < bytes2.length; i++) {
|
|
1417
|
-
hex +=
|
|
1746
|
+
hex += hexes3[bytes2[i]];
|
|
1418
1747
|
}
|
|
1419
1748
|
return hex;
|
|
1420
1749
|
}
|
|
1421
|
-
function
|
|
1750
|
+
function numberToHexUnpadded2(num) {
|
|
1422
1751
|
const hex = num.toString(16);
|
|
1423
1752
|
return hex.length & 1 ? `0${hex}` : hex;
|
|
1424
1753
|
}
|
|
1425
|
-
function
|
|
1754
|
+
function hexToNumber2(hex) {
|
|
1426
1755
|
if (typeof hex !== "string")
|
|
1427
1756
|
throw new Error("hex string expected, got " + typeof hex);
|
|
1428
1757
|
return BigInt(hex === "" ? "0" : `0x${hex}`);
|
|
1429
1758
|
}
|
|
1430
|
-
function
|
|
1759
|
+
function hexToBytes3(hex) {
|
|
1431
1760
|
if (typeof hex !== "string")
|
|
1432
1761
|
throw new Error("hex string expected, got " + typeof hex);
|
|
1433
1762
|
if (hex.length % 2)
|
|
@@ -1443,26 +1772,26 @@ var starknet = (() => {
|
|
|
1443
1772
|
}
|
|
1444
1773
|
return array;
|
|
1445
1774
|
}
|
|
1446
|
-
function
|
|
1447
|
-
return
|
|
1775
|
+
function bytesToNumberBE2(bytes2) {
|
|
1776
|
+
return hexToNumber2(bytesToHex2(bytes2));
|
|
1448
1777
|
}
|
|
1449
|
-
function
|
|
1450
|
-
if (!
|
|
1778
|
+
function bytesToNumberLE2(bytes2) {
|
|
1779
|
+
if (!u8a2(bytes2))
|
|
1451
1780
|
throw new Error("Uint8Array expected");
|
|
1452
|
-
return
|
|
1781
|
+
return hexToNumber2(bytesToHex2(Uint8Array.from(bytes2).reverse()));
|
|
1453
1782
|
}
|
|
1454
|
-
var
|
|
1455
|
-
var
|
|
1456
|
-
var
|
|
1457
|
-
function
|
|
1783
|
+
var numberToBytesBE2 = (n, len) => hexToBytes3(n.toString(16).padStart(len * 2, "0"));
|
|
1784
|
+
var numberToBytesLE2 = (n, len) => numberToBytesBE2(n, len).reverse();
|
|
1785
|
+
var numberToVarBytesBE2 = (n) => hexToBytes3(numberToHexUnpadded2(n));
|
|
1786
|
+
function ensureBytes2(title, hex, expectedLength) {
|
|
1458
1787
|
let res;
|
|
1459
1788
|
if (typeof hex === "string") {
|
|
1460
1789
|
try {
|
|
1461
|
-
res =
|
|
1790
|
+
res = hexToBytes3(hex);
|
|
1462
1791
|
} catch (e) {
|
|
1463
1792
|
throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
|
|
1464
1793
|
}
|
|
1465
|
-
} else if (
|
|
1794
|
+
} else if (u8a2(hex)) {
|
|
1466
1795
|
res = Uint8Array.from(hex);
|
|
1467
1796
|
} else {
|
|
1468
1797
|
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
@@ -1472,18 +1801,18 @@ var starknet = (() => {
|
|
|
1472
1801
|
throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
|
|
1473
1802
|
return res;
|
|
1474
1803
|
}
|
|
1475
|
-
function
|
|
1804
|
+
function concatBytes3(...arrs) {
|
|
1476
1805
|
const r = new Uint8Array(arrs.reduce((sum, a) => sum + a.length, 0));
|
|
1477
1806
|
let pad = 0;
|
|
1478
1807
|
arrs.forEach((a) => {
|
|
1479
|
-
if (!
|
|
1808
|
+
if (!u8a2(a))
|
|
1480
1809
|
throw new Error("Uint8Array expected");
|
|
1481
1810
|
r.set(a, pad);
|
|
1482
1811
|
pad += a.length;
|
|
1483
1812
|
});
|
|
1484
1813
|
return r;
|
|
1485
1814
|
}
|
|
1486
|
-
function
|
|
1815
|
+
function equalBytes2(b1, b2) {
|
|
1487
1816
|
if (b1.length !== b2.length)
|
|
1488
1817
|
return false;
|
|
1489
1818
|
for (let i = 0; i < b1.length; i++)
|
|
@@ -1491,32 +1820,32 @@ var starknet = (() => {
|
|
|
1491
1820
|
return false;
|
|
1492
1821
|
return true;
|
|
1493
1822
|
}
|
|
1494
|
-
function
|
|
1823
|
+
function utf8ToBytes3(str) {
|
|
1495
1824
|
if (typeof str !== "string") {
|
|
1496
1825
|
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
1497
1826
|
}
|
|
1498
1827
|
return new TextEncoder().encode(str);
|
|
1499
1828
|
}
|
|
1500
|
-
function
|
|
1829
|
+
function bitLen2(n) {
|
|
1501
1830
|
let len;
|
|
1502
|
-
for (len = 0; n >
|
|
1831
|
+
for (len = 0; n > _0n3; n >>= _1n3, len += 1)
|
|
1503
1832
|
;
|
|
1504
1833
|
return len;
|
|
1505
1834
|
}
|
|
1506
|
-
var
|
|
1507
|
-
var
|
|
1508
|
-
var
|
|
1509
|
-
var
|
|
1510
|
-
var
|
|
1511
|
-
function
|
|
1835
|
+
var bitGet2 = (n, pos) => n >> BigInt(pos) & _1n3;
|
|
1836
|
+
var bitSet2 = (n, pos, value) => n | (value ? _1n3 : _0n3) << BigInt(pos);
|
|
1837
|
+
var bitMask2 = (n) => (_2n3 << BigInt(n - 1)) - _1n3;
|
|
1838
|
+
var u8n2 = (data) => new Uint8Array(data);
|
|
1839
|
+
var u8fr2 = (arr) => Uint8Array.from(arr);
|
|
1840
|
+
function createHmacDrbg2(hashLen, qByteLen, hmacFn) {
|
|
1512
1841
|
if (typeof hashLen !== "number" || hashLen < 2)
|
|
1513
1842
|
throw new Error("hashLen must be a number");
|
|
1514
1843
|
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
1515
1844
|
throw new Error("qByteLen must be a number");
|
|
1516
1845
|
if (typeof hmacFn !== "function")
|
|
1517
1846
|
throw new Error("hmacFn must be a function");
|
|
1518
|
-
let v =
|
|
1519
|
-
let k =
|
|
1847
|
+
let v = u8n2(hashLen);
|
|
1848
|
+
let k = u8n2(hashLen);
|
|
1520
1849
|
let i = 0;
|
|
1521
1850
|
const reset = () => {
|
|
1522
1851
|
v.fill(1);
|
|
@@ -1524,12 +1853,12 @@ var starknet = (() => {
|
|
|
1524
1853
|
i = 0;
|
|
1525
1854
|
};
|
|
1526
1855
|
const h = (...b) => hmacFn(k, v, ...b);
|
|
1527
|
-
const reseed = (seed =
|
|
1528
|
-
k = h(
|
|
1856
|
+
const reseed = (seed = u8n2()) => {
|
|
1857
|
+
k = h(u8fr2([0]), seed);
|
|
1529
1858
|
v = h();
|
|
1530
1859
|
if (seed.length === 0)
|
|
1531
1860
|
return;
|
|
1532
|
-
k = h(
|
|
1861
|
+
k = h(u8fr2([1]), seed);
|
|
1533
1862
|
v = h();
|
|
1534
1863
|
};
|
|
1535
1864
|
const gen2 = () => {
|
|
@@ -1543,7 +1872,7 @@ var starknet = (() => {
|
|
|
1543
1872
|
out.push(sl);
|
|
1544
1873
|
len += v.length;
|
|
1545
1874
|
}
|
|
1546
|
-
return
|
|
1875
|
+
return concatBytes3(...out);
|
|
1547
1876
|
};
|
|
1548
1877
|
const genUntil = (seed, pred) => {
|
|
1549
1878
|
reset();
|
|
@@ -1556,7 +1885,7 @@ var starknet = (() => {
|
|
|
1556
1885
|
};
|
|
1557
1886
|
return genUntil;
|
|
1558
1887
|
}
|
|
1559
|
-
var
|
|
1888
|
+
var validatorFns2 = {
|
|
1560
1889
|
bigint: (val) => typeof val === "bigint",
|
|
1561
1890
|
function: (val) => typeof val === "function",
|
|
1562
1891
|
boolean: (val) => typeof val === "boolean",
|
|
@@ -1566,9 +1895,9 @@ var starknet = (() => {
|
|
|
1566
1895
|
field: (val, object) => object.Fp.isValid(val),
|
|
1567
1896
|
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
1568
1897
|
};
|
|
1569
|
-
function
|
|
1898
|
+
function validateObject2(object, validators, optValidators = {}) {
|
|
1570
1899
|
const checkField = (fieldName, type, isOptional) => {
|
|
1571
|
-
const checkVal =
|
|
1900
|
+
const checkVal = validatorFns2[type];
|
|
1572
1901
|
if (typeof checkVal !== "function")
|
|
1573
1902
|
throw new Error(`Invalid validator "${type}", expected function`);
|
|
1574
1903
|
const val = object[fieldName];
|
|
@@ -1586,9 +1915,9 @@ var starknet = (() => {
|
|
|
1586
1915
|
}
|
|
1587
1916
|
|
|
1588
1917
|
// node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/modular.js
|
|
1589
|
-
var
|
|
1590
|
-
var
|
|
1591
|
-
var
|
|
1918
|
+
var _0n4 = BigInt(0);
|
|
1919
|
+
var _1n4 = BigInt(1);
|
|
1920
|
+
var _2n4 = BigInt(2);
|
|
1592
1921
|
var _3n = BigInt(3);
|
|
1593
1922
|
var _4n = BigInt(4);
|
|
1594
1923
|
var _5n = BigInt(5);
|
|
@@ -1597,30 +1926,30 @@ var starknet = (() => {
|
|
|
1597
1926
|
var _16n = BigInt(16);
|
|
1598
1927
|
function mod(a, b) {
|
|
1599
1928
|
const result = a % b;
|
|
1600
|
-
return result >=
|
|
1929
|
+
return result >= _0n4 ? result : b + result;
|
|
1601
1930
|
}
|
|
1602
1931
|
function pow(num, power, modulo) {
|
|
1603
|
-
if (modulo <=
|
|
1932
|
+
if (modulo <= _0n4 || power < _0n4)
|
|
1604
1933
|
throw new Error("Expected power/modulo > 0");
|
|
1605
|
-
if (modulo ===
|
|
1606
|
-
return
|
|
1607
|
-
let res =
|
|
1608
|
-
while (power >
|
|
1609
|
-
if (power &
|
|
1934
|
+
if (modulo === _1n4)
|
|
1935
|
+
return _0n4;
|
|
1936
|
+
let res = _1n4;
|
|
1937
|
+
while (power > _0n4) {
|
|
1938
|
+
if (power & _1n4)
|
|
1610
1939
|
res = res * num % modulo;
|
|
1611
1940
|
num = num * num % modulo;
|
|
1612
|
-
power >>=
|
|
1941
|
+
power >>= _1n4;
|
|
1613
1942
|
}
|
|
1614
1943
|
return res;
|
|
1615
1944
|
}
|
|
1616
1945
|
function invert(number3, modulo) {
|
|
1617
|
-
if (number3 ===
|
|
1946
|
+
if (number3 === _0n4 || modulo <= _0n4) {
|
|
1618
1947
|
throw new Error(`invert: expected positive integers, got n=${number3} mod=${modulo}`);
|
|
1619
1948
|
}
|
|
1620
1949
|
let a = mod(number3, modulo);
|
|
1621
1950
|
let b = modulo;
|
|
1622
|
-
let x =
|
|
1623
|
-
while (a !==
|
|
1951
|
+
let x = _0n4, y = _1n4, u = _1n4, v = _0n4;
|
|
1952
|
+
while (a !== _0n4) {
|
|
1624
1953
|
const q = b / a;
|
|
1625
1954
|
const r = b % a;
|
|
1626
1955
|
const m = x - u * q;
|
|
@@ -1628,19 +1957,19 @@ var starknet = (() => {
|
|
|
1628
1957
|
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
1629
1958
|
}
|
|
1630
1959
|
const gcd = b;
|
|
1631
|
-
if (gcd !==
|
|
1960
|
+
if (gcd !== _1n4)
|
|
1632
1961
|
throw new Error("invert: does not exist");
|
|
1633
1962
|
return mod(x, modulo);
|
|
1634
1963
|
}
|
|
1635
1964
|
function tonelliShanks(P) {
|
|
1636
|
-
const legendreC = (P -
|
|
1965
|
+
const legendreC = (P - _1n4) / _2n4;
|
|
1637
1966
|
let Q, S, Z;
|
|
1638
|
-
for (Q = P -
|
|
1967
|
+
for (Q = P - _1n4, S = 0; Q % _2n4 === _0n4; Q /= _2n4, S++)
|
|
1639
1968
|
;
|
|
1640
|
-
for (Z =
|
|
1969
|
+
for (Z = _2n4; Z < P && pow(Z, legendreC, P) !== P - _1n4; Z++)
|
|
1641
1970
|
;
|
|
1642
1971
|
if (S === 1) {
|
|
1643
|
-
const p1div4 = (P +
|
|
1972
|
+
const p1div4 = (P + _1n4) / _4n;
|
|
1644
1973
|
return function tonelliFast(Fp, n) {
|
|
1645
1974
|
const root = Fp.pow(n, p1div4);
|
|
1646
1975
|
if (!Fp.eql(Fp.sqr(root), n))
|
|
@@ -1648,7 +1977,7 @@ var starknet = (() => {
|
|
|
1648
1977
|
return root;
|
|
1649
1978
|
};
|
|
1650
1979
|
}
|
|
1651
|
-
const Q1div2 = (Q +
|
|
1980
|
+
const Q1div2 = (Q + _1n4) / _2n4;
|
|
1652
1981
|
return function tonelliSlow(Fp, n) {
|
|
1653
1982
|
if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
|
|
1654
1983
|
throw new Error("Cannot find square root");
|
|
@@ -1665,7 +1994,7 @@ var starknet = (() => {
|
|
|
1665
1994
|
break;
|
|
1666
1995
|
t2 = Fp.sqr(t2);
|
|
1667
1996
|
}
|
|
1668
|
-
const ge = Fp.pow(g,
|
|
1997
|
+
const ge = Fp.pow(g, _1n4 << BigInt(r - m - 1));
|
|
1669
1998
|
g = Fp.sqr(ge);
|
|
1670
1999
|
x = Fp.mul(x, ge);
|
|
1671
2000
|
b = Fp.mul(b, g);
|
|
@@ -1676,7 +2005,7 @@ var starknet = (() => {
|
|
|
1676
2005
|
}
|
|
1677
2006
|
function FpSqrt(P) {
|
|
1678
2007
|
if (P % _4n === _3n) {
|
|
1679
|
-
const p1div4 = (P +
|
|
2008
|
+
const p1div4 = (P + _1n4) / _4n;
|
|
1680
2009
|
return function sqrt3mod4(Fp, n) {
|
|
1681
2010
|
const root = Fp.pow(n, p1div4);
|
|
1682
2011
|
if (!Fp.eql(Fp.sqr(root), n))
|
|
@@ -1687,10 +2016,10 @@ var starknet = (() => {
|
|
|
1687
2016
|
if (P % _8n === _5n) {
|
|
1688
2017
|
const c1 = (P - _5n) / _8n;
|
|
1689
2018
|
return function sqrt5mod8(Fp, n) {
|
|
1690
|
-
const n2 = Fp.mul(n,
|
|
2019
|
+
const n2 = Fp.mul(n, _2n4);
|
|
1691
2020
|
const v = Fp.pow(n2, c1);
|
|
1692
2021
|
const nv = Fp.mul(n, v);
|
|
1693
|
-
const i = Fp.mul(Fp.mul(nv,
|
|
2022
|
+
const i = Fp.mul(Fp.mul(nv, _2n4), v);
|
|
1694
2023
|
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
1695
2024
|
if (!Fp.eql(Fp.sqr(root), n))
|
|
1696
2025
|
throw new Error("Cannot find square root");
|
|
@@ -1731,22 +2060,22 @@ var starknet = (() => {
|
|
|
1731
2060
|
map[val] = "function";
|
|
1732
2061
|
return map;
|
|
1733
2062
|
}, initial);
|
|
1734
|
-
return
|
|
2063
|
+
return validateObject2(field, opts);
|
|
1735
2064
|
}
|
|
1736
2065
|
function FpPow(f, num, power) {
|
|
1737
|
-
if (power <
|
|
2066
|
+
if (power < _0n4)
|
|
1738
2067
|
throw new Error("Expected power > 0");
|
|
1739
|
-
if (power ===
|
|
2068
|
+
if (power === _0n4)
|
|
1740
2069
|
return f.ONE;
|
|
1741
|
-
if (power ===
|
|
2070
|
+
if (power === _1n4)
|
|
1742
2071
|
return num;
|
|
1743
2072
|
let p = f.ONE;
|
|
1744
2073
|
let d = num;
|
|
1745
|
-
while (power >
|
|
1746
|
-
if (power &
|
|
2074
|
+
while (power > _0n4) {
|
|
2075
|
+
if (power & _1n4)
|
|
1747
2076
|
p = f.mul(p, d);
|
|
1748
2077
|
d = f.sqr(d);
|
|
1749
|
-
power >>=
|
|
2078
|
+
power >>= _1n4;
|
|
1750
2079
|
}
|
|
1751
2080
|
return p;
|
|
1752
2081
|
}
|
|
@@ -1773,7 +2102,7 @@ var starknet = (() => {
|
|
|
1773
2102
|
return { nBitLength: _nBitLength, nByteLength };
|
|
1774
2103
|
}
|
|
1775
2104
|
function Field(ORDER, bitLen3, isLE2 = false, redef = {}) {
|
|
1776
|
-
if (ORDER <=
|
|
2105
|
+
if (ORDER <= _0n4)
|
|
1777
2106
|
throw new Error(`Expected Fp ORDER > 0, got ${ORDER}`);
|
|
1778
2107
|
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen3);
|
|
1779
2108
|
if (BYTES > 2048)
|
|
@@ -1783,17 +2112,17 @@ var starknet = (() => {
|
|
|
1783
2112
|
ORDER,
|
|
1784
2113
|
BITS,
|
|
1785
2114
|
BYTES,
|
|
1786
|
-
MASK:
|
|
1787
|
-
ZERO:
|
|
1788
|
-
ONE:
|
|
2115
|
+
MASK: bitMask2(BITS),
|
|
2116
|
+
ZERO: _0n4,
|
|
2117
|
+
ONE: _1n4,
|
|
1789
2118
|
create: (num) => mod(num, ORDER),
|
|
1790
2119
|
isValid: (num) => {
|
|
1791
2120
|
if (typeof num !== "bigint")
|
|
1792
2121
|
throw new Error(`Invalid field element: expected bigint, got ${typeof num}`);
|
|
1793
|
-
return
|
|
2122
|
+
return _0n4 <= num && num < ORDER;
|
|
1794
2123
|
},
|
|
1795
|
-
is0: (num) => num ===
|
|
1796
|
-
isOdd: (num) => (num &
|
|
2124
|
+
is0: (num) => num === _0n4,
|
|
2125
|
+
isOdd: (num) => (num & _1n4) === _1n4,
|
|
1797
2126
|
neg: (num) => mod(-num, ORDER),
|
|
1798
2127
|
eql: (lhs, rhs) => lhs === rhs,
|
|
1799
2128
|
sqr: (num) => mod(num * num, ORDER),
|
|
@@ -1810,23 +2139,23 @@ var starknet = (() => {
|
|
|
1810
2139
|
sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
|
|
1811
2140
|
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
1812
2141
|
cmov: (a, b, c) => c ? b : a,
|
|
1813
|
-
toBytes: (num) => isLE2 ?
|
|
2142
|
+
toBytes: (num) => isLE2 ? numberToBytesLE2(num, BYTES) : numberToBytesBE2(num, BYTES),
|
|
1814
2143
|
fromBytes: (bytes2) => {
|
|
1815
2144
|
if (bytes2.length !== BYTES)
|
|
1816
2145
|
throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes2.length}`);
|
|
1817
|
-
return isLE2 ?
|
|
2146
|
+
return isLE2 ? bytesToNumberLE2(bytes2) : bytesToNumberBE2(bytes2);
|
|
1818
2147
|
}
|
|
1819
2148
|
});
|
|
1820
2149
|
return Object.freeze(f);
|
|
1821
2150
|
}
|
|
1822
2151
|
function hashToPrivateScalar(hash2, groupOrder, isLE2 = false) {
|
|
1823
|
-
hash2 =
|
|
2152
|
+
hash2 = ensureBytes2("privateHash", hash2);
|
|
1824
2153
|
const hashLen = hash2.length;
|
|
1825
2154
|
const minLen = nLength(groupOrder).nByteLength + 8;
|
|
1826
2155
|
if (minLen < 24 || hashLen < minLen || hashLen > 1024)
|
|
1827
2156
|
throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
|
|
1828
|
-
const num = isLE2 ?
|
|
1829
|
-
return mod(num, groupOrder -
|
|
2157
|
+
const num = isLE2 ? bytesToNumberLE2(hash2) : bytesToNumberBE2(hash2);
|
|
2158
|
+
return mod(num, groupOrder - _1n4) + _1n4;
|
|
1830
2159
|
}
|
|
1831
2160
|
|
|
1832
2161
|
// node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/poseidon.js
|
|
@@ -1914,8 +2243,8 @@ var starknet = (() => {
|
|
|
1914
2243
|
}
|
|
1915
2244
|
|
|
1916
2245
|
// node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/curve.js
|
|
1917
|
-
var
|
|
1918
|
-
var
|
|
2246
|
+
var _0n5 = BigInt(0);
|
|
2247
|
+
var _1n5 = BigInt(1);
|
|
1919
2248
|
function wNAF(c, bits) {
|
|
1920
2249
|
const constTimeNegate = (condition, item) => {
|
|
1921
2250
|
const neg = item.negate();
|
|
@@ -1931,11 +2260,11 @@ var starknet = (() => {
|
|
|
1931
2260
|
unsafeLadder(elm, n) {
|
|
1932
2261
|
let p = c.ZERO;
|
|
1933
2262
|
let d = elm;
|
|
1934
|
-
while (n >
|
|
1935
|
-
if (n &
|
|
2263
|
+
while (n > _0n5) {
|
|
2264
|
+
if (n & _1n5)
|
|
1936
2265
|
p = p.add(d);
|
|
1937
2266
|
d = d.double();
|
|
1938
|
-
n >>=
|
|
2267
|
+
n >>= _1n5;
|
|
1939
2268
|
}
|
|
1940
2269
|
return p;
|
|
1941
2270
|
},
|
|
@@ -1968,7 +2297,7 @@ var starknet = (() => {
|
|
|
1968
2297
|
n >>= shiftBy;
|
|
1969
2298
|
if (wbits > windowSize) {
|
|
1970
2299
|
wbits -= maxNumber;
|
|
1971
|
-
n +=
|
|
2300
|
+
n += _1n5;
|
|
1972
2301
|
}
|
|
1973
2302
|
const offset1 = offset;
|
|
1974
2303
|
const offset2 = offset + Math.abs(wbits) - 1;
|
|
@@ -1997,7 +2326,7 @@ var starknet = (() => {
|
|
|
1997
2326
|
}
|
|
1998
2327
|
function validateBasic(curve2) {
|
|
1999
2328
|
validateField(curve2.Fp);
|
|
2000
|
-
|
|
2329
|
+
validateObject2(curve2, {
|
|
2001
2330
|
n: "bigint",
|
|
2002
2331
|
h: "bigint",
|
|
2003
2332
|
Gx: "field",
|
|
@@ -2016,7 +2345,7 @@ var starknet = (() => {
|
|
|
2016
2345
|
// node_modules/micro-starknet/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
2017
2346
|
function validatePointOpts(curve2) {
|
|
2018
2347
|
const opts = validateBasic(curve2);
|
|
2019
|
-
|
|
2348
|
+
validateObject2(opts, {
|
|
2020
2349
|
a: "field",
|
|
2021
2350
|
b: "field"
|
|
2022
2351
|
}, {
|
|
@@ -2039,7 +2368,7 @@ var starknet = (() => {
|
|
|
2039
2368
|
}
|
|
2040
2369
|
return Object.freeze({ ...opts });
|
|
2041
2370
|
}
|
|
2042
|
-
var { bytesToNumberBE: b2n, hexToBytes: h2b } =
|
|
2371
|
+
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports2;
|
|
2043
2372
|
var DER = {
|
|
2044
2373
|
Err: class DERErr extends Error {
|
|
2045
2374
|
constructor(m = "") {
|
|
@@ -2091,9 +2420,9 @@ var starknet = (() => {
|
|
|
2091
2420
|
return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
|
|
2092
2421
|
}
|
|
2093
2422
|
};
|
|
2094
|
-
var
|
|
2095
|
-
var
|
|
2096
|
-
var
|
|
2423
|
+
var _0n6 = BigInt(0);
|
|
2424
|
+
var _1n6 = BigInt(1);
|
|
2425
|
+
var _2n5 = BigInt(2);
|
|
2097
2426
|
var _3n2 = BigInt(3);
|
|
2098
2427
|
var _4n2 = BigInt(4);
|
|
2099
2428
|
function weierstrassPoints(opts) {
|
|
@@ -2101,7 +2430,7 @@ var starknet = (() => {
|
|
|
2101
2430
|
const { Fp } = CURVE2;
|
|
2102
2431
|
const toBytes2 = CURVE2.toBytes || ((c, point, isCompressed) => {
|
|
2103
2432
|
const a = point.toAffine();
|
|
2104
|
-
return
|
|
2433
|
+
return concatBytes3(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
|
|
2105
2434
|
});
|
|
2106
2435
|
const fromBytes = CURVE2.fromBytes || ((bytes2) => {
|
|
2107
2436
|
const tail = bytes2.subarray(1);
|
|
@@ -2118,7 +2447,7 @@ var starknet = (() => {
|
|
|
2118
2447
|
if (!Fp.eql(Fp.sqr(CURVE2.Gy), weierstrassEquation(CURVE2.Gx)))
|
|
2119
2448
|
throw new Error("bad generator point: equation left != right");
|
|
2120
2449
|
function isWithinCurveOrder(num) {
|
|
2121
|
-
return typeof num === "bigint" &&
|
|
2450
|
+
return typeof num === "bigint" && _0n6 < num && num < CURVE2.n;
|
|
2122
2451
|
}
|
|
2123
2452
|
function assertGE(num) {
|
|
2124
2453
|
if (!isWithinCurveOrder(num))
|
|
@@ -2128,14 +2457,14 @@ var starknet = (() => {
|
|
|
2128
2457
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE2;
|
|
2129
2458
|
if (lengths && typeof key !== "bigint") {
|
|
2130
2459
|
if (key instanceof Uint8Array)
|
|
2131
|
-
key =
|
|
2460
|
+
key = bytesToHex2(key);
|
|
2132
2461
|
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
2133
2462
|
throw new Error("Invalid key");
|
|
2134
2463
|
key = key.padStart(nByteLength * 2, "0");
|
|
2135
2464
|
}
|
|
2136
2465
|
let num;
|
|
2137
2466
|
try {
|
|
2138
|
-
num = typeof key === "bigint" ? key :
|
|
2467
|
+
num = typeof key === "bigint" ? key : bytesToNumberBE2(ensureBytes2("private key", key, nByteLength));
|
|
2139
2468
|
} catch (error) {
|
|
2140
2469
|
throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
|
|
2141
2470
|
}
|
|
@@ -2183,7 +2512,7 @@ var starknet = (() => {
|
|
|
2183
2512
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
2184
2513
|
}
|
|
2185
2514
|
static fromHex(hex) {
|
|
2186
|
-
const P = Point.fromAffine(fromBytes(
|
|
2515
|
+
const P = Point.fromAffine(fromBytes(ensureBytes2("pointHex", hex)));
|
|
2187
2516
|
P.assertValidity();
|
|
2188
2517
|
return P;
|
|
2189
2518
|
}
|
|
@@ -2328,10 +2657,10 @@ var starknet = (() => {
|
|
|
2328
2657
|
}
|
|
2329
2658
|
multiplyUnsafe(n) {
|
|
2330
2659
|
const I = Point.ZERO;
|
|
2331
|
-
if (n ===
|
|
2660
|
+
if (n === _0n6)
|
|
2332
2661
|
return I;
|
|
2333
2662
|
assertGE(n);
|
|
2334
|
-
if (n ===
|
|
2663
|
+
if (n === _1n6)
|
|
2335
2664
|
return this;
|
|
2336
2665
|
const { endo } = CURVE2;
|
|
2337
2666
|
if (!endo)
|
|
@@ -2340,14 +2669,14 @@ var starknet = (() => {
|
|
|
2340
2669
|
let k1p = I;
|
|
2341
2670
|
let k2p = I;
|
|
2342
2671
|
let d = this;
|
|
2343
|
-
while (k1 >
|
|
2344
|
-
if (k1 &
|
|
2672
|
+
while (k1 > _0n6 || k2 > _0n6) {
|
|
2673
|
+
if (k1 & _1n6)
|
|
2345
2674
|
k1p = k1p.add(d);
|
|
2346
|
-
if (k2 &
|
|
2675
|
+
if (k2 & _1n6)
|
|
2347
2676
|
k2p = k2p.add(d);
|
|
2348
2677
|
d = d.double();
|
|
2349
|
-
k1 >>=
|
|
2350
|
-
k2 >>=
|
|
2678
|
+
k1 >>= _1n6;
|
|
2679
|
+
k2 >>= _1n6;
|
|
2351
2680
|
}
|
|
2352
2681
|
if (k1neg)
|
|
2353
2682
|
k1p = k1p.negate();
|
|
@@ -2379,7 +2708,7 @@ var starknet = (() => {
|
|
|
2379
2708
|
}
|
|
2380
2709
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
2381
2710
|
const G = Point.BASE;
|
|
2382
|
-
const mul = (P, a2) => a2 ===
|
|
2711
|
+
const mul = (P, a2) => a2 === _0n6 || a2 === _1n6 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
2383
2712
|
const sum = mul(this, a).add(mul(Q, b));
|
|
2384
2713
|
return sum.is0() ? void 0 : sum;
|
|
2385
2714
|
}
|
|
@@ -2399,7 +2728,7 @@ var starknet = (() => {
|
|
|
2399
2728
|
}
|
|
2400
2729
|
isTorsionFree() {
|
|
2401
2730
|
const { h: cofactor, isTorsionFree } = CURVE2;
|
|
2402
|
-
if (cofactor ===
|
|
2731
|
+
if (cofactor === _1n6)
|
|
2403
2732
|
return true;
|
|
2404
2733
|
if (isTorsionFree)
|
|
2405
2734
|
return isTorsionFree(Point, this);
|
|
@@ -2407,7 +2736,7 @@ var starknet = (() => {
|
|
|
2407
2736
|
}
|
|
2408
2737
|
clearCofactor() {
|
|
2409
2738
|
const { h: cofactor, clearCofactor } = CURVE2;
|
|
2410
|
-
if (cofactor ===
|
|
2739
|
+
if (cofactor === _1n6)
|
|
2411
2740
|
return this;
|
|
2412
2741
|
if (clearCofactor)
|
|
2413
2742
|
return clearCofactor(Point, this);
|
|
@@ -2418,7 +2747,7 @@ var starknet = (() => {
|
|
|
2418
2747
|
return toBytes2(Point, this, isCompressed);
|
|
2419
2748
|
}
|
|
2420
2749
|
toHex(isCompressed = true) {
|
|
2421
|
-
return
|
|
2750
|
+
return bytesToHex2(this.toRawBytes(isCompressed));
|
|
2422
2751
|
}
|
|
2423
2752
|
}
|
|
2424
2753
|
Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp.ONE);
|
|
@@ -2435,7 +2764,7 @@ var starknet = (() => {
|
|
|
2435
2764
|
}
|
|
2436
2765
|
function validateOpts2(curve2) {
|
|
2437
2766
|
const opts = validateBasic(curve2);
|
|
2438
|
-
|
|
2767
|
+
validateObject2(opts, {
|
|
2439
2768
|
hash: "hash",
|
|
2440
2769
|
hmac: "function",
|
|
2441
2770
|
randomBytes: "function"
|
|
@@ -2452,7 +2781,7 @@ var starknet = (() => {
|
|
|
2452
2781
|
const compressedLen = Fp.BYTES + 1;
|
|
2453
2782
|
const uncompressedLen = 2 * Fp.BYTES + 1;
|
|
2454
2783
|
function isValidFieldElement(num) {
|
|
2455
|
-
return
|
|
2784
|
+
return _0n6 < num && num < Fp.ORDER;
|
|
2456
2785
|
}
|
|
2457
2786
|
function modN(a) {
|
|
2458
2787
|
return mod(a, CURVE_ORDER2);
|
|
@@ -2465,7 +2794,7 @@ var starknet = (() => {
|
|
|
2465
2794
|
toBytes(c, point, isCompressed) {
|
|
2466
2795
|
const a = point.toAffine();
|
|
2467
2796
|
const x = Fp.toBytes(a.x);
|
|
2468
|
-
const cat =
|
|
2797
|
+
const cat = concatBytes3;
|
|
2469
2798
|
if (isCompressed) {
|
|
2470
2799
|
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
|
2471
2800
|
} else {
|
|
@@ -2477,12 +2806,12 @@ var starknet = (() => {
|
|
|
2477
2806
|
const head = bytes2[0];
|
|
2478
2807
|
const tail = bytes2.subarray(1);
|
|
2479
2808
|
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
2480
|
-
const x =
|
|
2809
|
+
const x = bytesToNumberBE2(tail);
|
|
2481
2810
|
if (!isValidFieldElement(x))
|
|
2482
2811
|
throw new Error("Point is not on curve");
|
|
2483
2812
|
const y2 = weierstrassEquation(x);
|
|
2484
2813
|
let y = Fp.sqrt(y2);
|
|
2485
|
-
const isYOdd = (y &
|
|
2814
|
+
const isYOdd = (y & _1n6) === _1n6;
|
|
2486
2815
|
const isHeadOdd = (head & 1) === 1;
|
|
2487
2816
|
if (isHeadOdd !== isYOdd)
|
|
2488
2817
|
y = Fp.neg(y);
|
|
@@ -2496,15 +2825,15 @@ var starknet = (() => {
|
|
|
2496
2825
|
}
|
|
2497
2826
|
}
|
|
2498
2827
|
});
|
|
2499
|
-
const numToNByteStr = (num) =>
|
|
2828
|
+
const numToNByteStr = (num) => bytesToHex2(numberToBytesBE2(num, CURVE2.nByteLength));
|
|
2500
2829
|
function isBiggerThanHalfOrder(number3) {
|
|
2501
|
-
const HALF = CURVE_ORDER2 >>
|
|
2830
|
+
const HALF = CURVE_ORDER2 >> _1n6;
|
|
2502
2831
|
return number3 > HALF;
|
|
2503
2832
|
}
|
|
2504
2833
|
function normalizeS(s) {
|
|
2505
2834
|
return isBiggerThanHalfOrder(s) ? modN(-s) : s;
|
|
2506
2835
|
}
|
|
2507
|
-
const slcNum = (b, from, to) =>
|
|
2836
|
+
const slcNum = (b, from, to) => bytesToNumberBE2(b.slice(from, to));
|
|
2508
2837
|
class Signature3 {
|
|
2509
2838
|
constructor(r, s, recovery) {
|
|
2510
2839
|
this.r = r;
|
|
@@ -2514,11 +2843,11 @@ var starknet = (() => {
|
|
|
2514
2843
|
}
|
|
2515
2844
|
static fromCompact(hex) {
|
|
2516
2845
|
const l = CURVE2.nByteLength;
|
|
2517
|
-
hex =
|
|
2846
|
+
hex = ensureBytes2("compactSignature", hex, l * 2);
|
|
2518
2847
|
return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
2519
2848
|
}
|
|
2520
2849
|
static fromDER(hex) {
|
|
2521
|
-
const { r, s } = DER.toSig(
|
|
2850
|
+
const { r, s } = DER.toSig(ensureBytes2("DER", hex));
|
|
2522
2851
|
return new Signature3(r, s);
|
|
2523
2852
|
}
|
|
2524
2853
|
assertValidity() {
|
|
@@ -2532,7 +2861,7 @@ var starknet = (() => {
|
|
|
2532
2861
|
}
|
|
2533
2862
|
recoverPublicKey(msgHash) {
|
|
2534
2863
|
const { r, s, recovery: rec } = this;
|
|
2535
|
-
const h = bits2int_modN(
|
|
2864
|
+
const h = bits2int_modN(ensureBytes2("msgHash", msgHash));
|
|
2536
2865
|
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
2537
2866
|
throw new Error("recovery id invalid");
|
|
2538
2867
|
const radj = rec === 2 || rec === 3 ? r + CURVE2.n : r;
|
|
@@ -2556,13 +2885,13 @@ var starknet = (() => {
|
|
|
2556
2885
|
return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
|
|
2557
2886
|
}
|
|
2558
2887
|
toDERRawBytes() {
|
|
2559
|
-
return
|
|
2888
|
+
return hexToBytes3(this.toDERHex());
|
|
2560
2889
|
}
|
|
2561
2890
|
toDERHex() {
|
|
2562
2891
|
return DER.hexFromSig({ r: this.r, s: this.s });
|
|
2563
2892
|
}
|
|
2564
2893
|
toCompactRawBytes() {
|
|
2565
|
-
return
|
|
2894
|
+
return hexToBytes3(this.toCompactHex());
|
|
2566
2895
|
}
|
|
2567
2896
|
toCompactHex() {
|
|
2568
2897
|
return numToNByteStr(this.r) + numToNByteStr(this.s);
|
|
@@ -2581,7 +2910,7 @@ var starknet = (() => {
|
|
|
2581
2910
|
randomPrivateKey: () => {
|
|
2582
2911
|
const rand = CURVE2.randomBytes(Fp.BYTES + 8);
|
|
2583
2912
|
const num = hashToPrivateScalar(rand, CURVE_ORDER2);
|
|
2584
|
-
return
|
|
2913
|
+
return numberToBytesBE2(num, CURVE2.nByteLength);
|
|
2585
2914
|
},
|
|
2586
2915
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
2587
2916
|
point._setWindowSize(windowSize);
|
|
@@ -2613,20 +2942,20 @@ var starknet = (() => {
|
|
|
2613
2942
|
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
2614
2943
|
}
|
|
2615
2944
|
const bits2int2 = CURVE2.bits2int || function(bytes2) {
|
|
2616
|
-
const num =
|
|
2945
|
+
const num = bytesToNumberBE2(bytes2);
|
|
2617
2946
|
const delta = bytes2.length * 8 - CURVE2.nBitLength;
|
|
2618
2947
|
return delta > 0 ? num >> BigInt(delta) : num;
|
|
2619
2948
|
};
|
|
2620
2949
|
const bits2int_modN = CURVE2.bits2int_modN || function(bytes2) {
|
|
2621
2950
|
return modN(bits2int2(bytes2));
|
|
2622
2951
|
};
|
|
2623
|
-
const ORDER_MASK =
|
|
2952
|
+
const ORDER_MASK = bitMask2(CURVE2.nBitLength);
|
|
2624
2953
|
function int2octets(num) {
|
|
2625
2954
|
if (typeof num !== "bigint")
|
|
2626
2955
|
throw new Error("bigint expected");
|
|
2627
|
-
if (!(
|
|
2956
|
+
if (!(_0n6 <= num && num < ORDER_MASK))
|
|
2628
2957
|
throw new Error(`bigint expected < 2^${CURVE2.nBitLength}`);
|
|
2629
|
-
return
|
|
2958
|
+
return numberToBytesBE2(num, CURVE2.nByteLength);
|
|
2630
2959
|
}
|
|
2631
2960
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
2632
2961
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
@@ -2635,17 +2964,17 @@ var starknet = (() => {
|
|
|
2635
2964
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
2636
2965
|
if (lowS == null)
|
|
2637
2966
|
lowS = true;
|
|
2638
|
-
msgHash =
|
|
2967
|
+
msgHash = ensureBytes2("msgHash", msgHash);
|
|
2639
2968
|
if (prehash)
|
|
2640
|
-
msgHash =
|
|
2969
|
+
msgHash = ensureBytes2("prehashed msgHash", hash2(msgHash));
|
|
2641
2970
|
const h1int = bits2int_modN(msgHash);
|
|
2642
2971
|
const d = normPrivateKeyToScalar(privateKey);
|
|
2643
2972
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
2644
2973
|
if (ent != null) {
|
|
2645
2974
|
const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
|
|
2646
|
-
seedArgs.push(
|
|
2975
|
+
seedArgs.push(ensureBytes2("extraEntropy", e, Fp.BYTES));
|
|
2647
2976
|
}
|
|
2648
|
-
const seed =
|
|
2977
|
+
const seed = concatBytes3(...seedArgs);
|
|
2649
2978
|
const m = h1int;
|
|
2650
2979
|
function k2sig(kBytes) {
|
|
2651
2980
|
const k = bits2int2(kBytes);
|
|
@@ -2654,12 +2983,12 @@ var starknet = (() => {
|
|
|
2654
2983
|
const ik = invN(k);
|
|
2655
2984
|
const q = Point.BASE.multiply(k).toAffine();
|
|
2656
2985
|
const r = modN(q.x);
|
|
2657
|
-
if (r ===
|
|
2986
|
+
if (r === _0n6)
|
|
2658
2987
|
return;
|
|
2659
2988
|
const s = modN(ik * modN(m + r * d));
|
|
2660
|
-
if (s ===
|
|
2989
|
+
if (s === _0n6)
|
|
2661
2990
|
return;
|
|
2662
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y &
|
|
2991
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n6);
|
|
2663
2992
|
let normS = s;
|
|
2664
2993
|
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
2665
2994
|
normS = normalizeS(s);
|
|
@@ -2673,15 +3002,15 @@ var starknet = (() => {
|
|
|
2673
3002
|
const defaultVerOpts = { lowS: CURVE2.lowS, prehash: false };
|
|
2674
3003
|
function sign2(msgHash, privKey, opts = defaultSigOpts) {
|
|
2675
3004
|
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
2676
|
-
const drbg =
|
|
3005
|
+
const drbg = createHmacDrbg2(CURVE2.hash.outputLen, CURVE2.nByteLength, CURVE2.hmac);
|
|
2677
3006
|
return drbg(seed, k2sig);
|
|
2678
3007
|
}
|
|
2679
3008
|
Point.BASE._setWindowSize(8);
|
|
2680
3009
|
function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
2681
3010
|
var _a;
|
|
2682
3011
|
const sg = signature;
|
|
2683
|
-
msgHash =
|
|
2684
|
-
publicKey =
|
|
3012
|
+
msgHash = ensureBytes2("msgHash", msgHash);
|
|
3013
|
+
publicKey = ensureBytes2("publicKey", publicKey);
|
|
2685
3014
|
if ("strict" in opts)
|
|
2686
3015
|
throw new Error("options.strict was renamed to lowS");
|
|
2687
3016
|
const { lowS, prehash } = opts;
|
|
@@ -2804,7 +3133,7 @@ var starknet = (() => {
|
|
|
2804
3133
|
function getHash(hash2) {
|
|
2805
3134
|
return {
|
|
2806
3135
|
hash: hash2,
|
|
2807
|
-
hmac: (key, ...msgs) => hmac(hash2, key,
|
|
3136
|
+
hmac: (key, ...msgs) => hmac(hash2, key, concatBytes2(...msgs)),
|
|
2808
3137
|
randomBytes
|
|
2809
3138
|
};
|
|
2810
3139
|
}
|
|
@@ -2816,7 +3145,7 @@ var starknet = (() => {
|
|
|
2816
3145
|
while (bytes2[0] === 0)
|
|
2817
3146
|
bytes2 = bytes2.subarray(1);
|
|
2818
3147
|
const delta = bytes2.length * 8 - nBitLength;
|
|
2819
|
-
const num =
|
|
3148
|
+
const num = bytesToNumberBE2(bytes2);
|
|
2820
3149
|
return delta > 0 ? num >> BigInt(delta) : num;
|
|
2821
3150
|
}
|
|
2822
3151
|
function hex0xToBytes(hex) {
|
|
@@ -2825,7 +3154,7 @@ var starknet = (() => {
|
|
|
2825
3154
|
if (hex.length & 1)
|
|
2826
3155
|
hex = "0" + hex;
|
|
2827
3156
|
}
|
|
2828
|
-
return
|
|
3157
|
+
return hexToBytes3(hex);
|
|
2829
3158
|
}
|
|
2830
3159
|
var curve = weierstrass({
|
|
2831
3160
|
a: BigInt(1),
|
|
@@ -2840,18 +3169,18 @@ var starknet = (() => {
|
|
|
2840
3169
|
...getHash(sha256),
|
|
2841
3170
|
bits2int,
|
|
2842
3171
|
bits2int_modN: (bytes2) => {
|
|
2843
|
-
const hex =
|
|
3172
|
+
const hex = bytesToNumberBE2(bytes2).toString(16);
|
|
2844
3173
|
if (hex.length === 63)
|
|
2845
3174
|
bytes2 = hex0xToBytes(hex + "0");
|
|
2846
3175
|
return mod(bits2int(bytes2), CURVE_ORDER);
|
|
2847
3176
|
}
|
|
2848
3177
|
});
|
|
2849
3178
|
var _starkCurve = curve;
|
|
2850
|
-
function
|
|
2851
|
-
return
|
|
3179
|
+
function ensureBytes3(hex) {
|
|
3180
|
+
return ensureBytes2("", typeof hex === "string" ? hex0xToBytes(hex) : hex);
|
|
2852
3181
|
}
|
|
2853
3182
|
function normPrivKey(privKey) {
|
|
2854
|
-
return
|
|
3183
|
+
return bytesToHex2(ensureBytes3(privKey)).padStart(64, "0");
|
|
2855
3184
|
}
|
|
2856
3185
|
function getPublicKey(privKey, isCompressed = false) {
|
|
2857
3186
|
return curve.getPublicKey(normPrivKey(privKey), isCompressed);
|
|
@@ -2860,15 +3189,15 @@ var starknet = (() => {
|
|
|
2860
3189
|
return curve.getSharedSecret(normPrivKey(privKeyA), pubKeyB);
|
|
2861
3190
|
}
|
|
2862
3191
|
function sign(msgHash, privKey, opts) {
|
|
2863
|
-
return curve.sign(
|
|
3192
|
+
return curve.sign(ensureBytes3(msgHash), normPrivKey(privKey), opts);
|
|
2864
3193
|
}
|
|
2865
3194
|
function verify(signature, msgHash, pubKey) {
|
|
2866
|
-
const sig = signature instanceof Signature ? signature :
|
|
2867
|
-
return curve.verify(sig,
|
|
3195
|
+
const sig = signature instanceof Signature ? signature : ensureBytes3(signature);
|
|
3196
|
+
return curve.verify(sig, ensureBytes3(msgHash), ensureBytes3(pubKey));
|
|
2868
3197
|
}
|
|
2869
3198
|
var { CURVE, ProjectivePoint, Signature, utils } = curve;
|
|
2870
3199
|
function extractX(bytes2) {
|
|
2871
|
-
const hex =
|
|
3200
|
+
const hex = bytesToHex2(bytes2.subarray(1));
|
|
2872
3201
|
const stripped = hex.replace(/^0+/gm, "");
|
|
2873
3202
|
return `0x${stripped}`;
|
|
2874
3203
|
}
|
|
@@ -2879,11 +3208,11 @@ var starknet = (() => {
|
|
|
2879
3208
|
return `0x${num.toString(16)}`;
|
|
2880
3209
|
}
|
|
2881
3210
|
function grindKey(seed) {
|
|
2882
|
-
const _seed =
|
|
3211
|
+
const _seed = ensureBytes3(seed);
|
|
2883
3212
|
const sha256mask = 2n ** 256n;
|
|
2884
3213
|
const limit = sha256mask - mod(sha256mask, CURVE_ORDER);
|
|
2885
3214
|
for (let i = 0; ; i++) {
|
|
2886
|
-
const key = sha256Num(
|
|
3215
|
+
const key = sha256Num(concatBytes3(_seed, numberToVarBytesBE2(BigInt(i))));
|
|
2887
3216
|
if (key < limit)
|
|
2888
3217
|
return mod(key, CURVE_ORDER).toString(16);
|
|
2889
3218
|
if (i === 1e5)
|
|
@@ -2904,7 +3233,7 @@ var starknet = (() => {
|
|
|
2904
3233
|
function getAccountPath(layer, application, ethereumAddress, index) {
|
|
2905
3234
|
const layerNum = int31(sha256Num(layer));
|
|
2906
3235
|
const applicationNum = int31(sha256Num(application));
|
|
2907
|
-
const eth =
|
|
3236
|
+
const eth = hexToNumber2(strip0x(ethereumAddress));
|
|
2908
3237
|
return `m/2645'/${layerNum}'/${applicationNum}'/${int31(eth)}'/${int31(eth >> 31n)}'/${index}`;
|
|
2909
3238
|
}
|
|
2910
3239
|
var PEDERSEN_POINTS = [
|
|
@@ -2939,7 +3268,7 @@ var starknet = (() => {
|
|
|
2939
3268
|
throw new Error(`Invalid pedersenArg: ${arg}`);
|
|
2940
3269
|
value = BigInt(arg);
|
|
2941
3270
|
} else {
|
|
2942
|
-
value =
|
|
3271
|
+
value = bytesToNumberBE2(ensureBytes3(arg));
|
|
2943
3272
|
}
|
|
2944
3273
|
if (!(0n <= value && value < curve.CURVE.Fp.ORDER))
|
|
2945
3274
|
throw new Error(`PedersenArg should be 0 <= value < CURVE.P: ${value}`);
|
|
@@ -2971,13 +3300,13 @@ var starknet = (() => {
|
|
|
2971
3300
|
return Array.from(data).reverse().reduce((acc, i) => fn(i, acc));
|
|
2972
3301
|
}
|
|
2973
3302
|
var computeHashOnElements = (data, fn = pedersen) => [0, ...data, data.length].reduce((x, y) => fn(x, y));
|
|
2974
|
-
var MASK_250 =
|
|
2975
|
-
var keccak = (data) =>
|
|
2976
|
-
var sha256Num = (data) =>
|
|
3303
|
+
var MASK_250 = bitMask2(250);
|
|
3304
|
+
var keccak = (data) => bytesToNumberBE2(keccak_256(data)) & MASK_250;
|
|
3305
|
+
var sha256Num = (data) => bytesToNumberBE2(sha256(data));
|
|
2977
3306
|
var Fp253 = Field(BigInt("14474011154664525231415395255581126252639794253786371766033694892385558855681"));
|
|
2978
3307
|
var Fp251 = Field(BigInt("3618502788666131213697322783095070105623107215331596699973092056135872020481"));
|
|
2979
3308
|
function poseidonRoundConstant(Fp, name, idx) {
|
|
2980
|
-
const val = Fp.fromBytes(sha256(
|
|
3309
|
+
const val = Fp.fromBytes(sha256(utf8ToBytes2(`${name}${idx}`)));
|
|
2981
3310
|
return Fp.create(val);
|
|
2982
3311
|
}
|
|
2983
3312
|
function _poseidonMDS(Fp, name, m, attempt = 0) {
|
|
@@ -3033,7 +3362,7 @@ var starknet = (() => {
|
|
|
3033
3362
|
return fn([x, y, 2n])[0];
|
|
3034
3363
|
}
|
|
3035
3364
|
function poseidonHashFunc(x, y, fn = poseidonSmall) {
|
|
3036
|
-
return
|
|
3365
|
+
return numberToVarBytesBE2(poseidonHash(bytesToNumberBE2(x), bytesToNumberBE2(y), fn));
|
|
3037
3366
|
}
|
|
3038
3367
|
function poseidonHashSingle(x, fn = poseidonSmall) {
|
|
3039
3368
|
return fn([x, 0n, 1n])[0];
|
|
@@ -3077,71 +3406,6 @@ var starknet = (() => {
|
|
|
3077
3406
|
UDC: () => UDC,
|
|
3078
3407
|
ZERO: () => ZERO
|
|
3079
3408
|
});
|
|
3080
|
-
|
|
3081
|
-
// src/utils/encode.ts
|
|
3082
|
-
var encode_exports = {};
|
|
3083
|
-
__export(encode_exports, {
|
|
3084
|
-
IS_BROWSER: () => IS_BROWSER,
|
|
3085
|
-
addHexPrefix: () => addHexPrefix,
|
|
3086
|
-
arrayBufferToString: () => arrayBufferToString,
|
|
3087
|
-
btoaUniversal: () => btoaUniversal,
|
|
3088
|
-
buf2hex: () => buf2hex,
|
|
3089
|
-
calcByteLength: () => calcByteLength,
|
|
3090
|
-
padLeft: () => padLeft,
|
|
3091
|
-
removeHexPrefix: () => removeHexPrefix,
|
|
3092
|
-
sanitizeBytes: () => sanitizeBytes,
|
|
3093
|
-
sanitizeHex: () => sanitizeHex,
|
|
3094
|
-
utf8ToArray: () => utf8ToArray
|
|
3095
|
-
});
|
|
3096
|
-
var IS_BROWSER = typeof window !== "undefined";
|
|
3097
|
-
var STRING_ZERO = "0";
|
|
3098
|
-
function arrayBufferToString(array) {
|
|
3099
|
-
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
3100
|
-
}
|
|
3101
|
-
function btoaUniversal(b) {
|
|
3102
|
-
return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString("base64");
|
|
3103
|
-
}
|
|
3104
|
-
function buf2hex(buffer) {
|
|
3105
|
-
return [...buffer].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
3106
|
-
}
|
|
3107
|
-
function removeHexPrefix(hex) {
|
|
3108
|
-
return hex.replace(/^0x/i, "");
|
|
3109
|
-
}
|
|
3110
|
-
function addHexPrefix(hex) {
|
|
3111
|
-
return `0x${removeHexPrefix(hex)}`;
|
|
3112
|
-
}
|
|
3113
|
-
function padString(str, length, left, padding = STRING_ZERO) {
|
|
3114
|
-
const diff = length - str.length;
|
|
3115
|
-
let result = str;
|
|
3116
|
-
if (diff > 0) {
|
|
3117
|
-
const pad = padding.repeat(diff);
|
|
3118
|
-
result = left ? pad + str : str + pad;
|
|
3119
|
-
}
|
|
3120
|
-
return result;
|
|
3121
|
-
}
|
|
3122
|
-
function padLeft(str, length, padding = STRING_ZERO) {
|
|
3123
|
-
return padString(str, length, true, padding);
|
|
3124
|
-
}
|
|
3125
|
-
function calcByteLength(length, byteSize = 8) {
|
|
3126
|
-
const remainder = length % byteSize;
|
|
3127
|
-
return remainder ? (length - remainder) / byteSize * byteSize + byteSize : length;
|
|
3128
|
-
}
|
|
3129
|
-
function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
|
|
3130
|
-
return padLeft(str, calcByteLength(str.length, byteSize), padding);
|
|
3131
|
-
}
|
|
3132
|
-
function sanitizeHex(hex) {
|
|
3133
|
-
hex = removeHexPrefix(hex);
|
|
3134
|
-
hex = sanitizeBytes(hex, 2);
|
|
3135
|
-
if (hex) {
|
|
3136
|
-
hex = addHexPrefix(hex);
|
|
3137
|
-
}
|
|
3138
|
-
return hex;
|
|
3139
|
-
}
|
|
3140
|
-
function utf8ToArray(str) {
|
|
3141
|
-
return new TextEncoder().encode(str);
|
|
3142
|
-
}
|
|
3143
|
-
|
|
3144
|
-
// src/constants.ts
|
|
3145
3409
|
var ZERO = 0n;
|
|
3146
3410
|
var MASK_2502 = 2n ** 250n - 1n;
|
|
3147
3411
|
var MASK_251 = 2n ** 251n;
|
|
@@ -5210,6 +5474,83 @@ var starknet = (() => {
|
|
|
5210
5474
|
]
|
|
5211
5475
|
];
|
|
5212
5476
|
|
|
5477
|
+
// src/utils/selector.ts
|
|
5478
|
+
function keccakBn(value) {
|
|
5479
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
5480
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
5481
|
+
return addHexPrefix(keccak(hexToBytes2(addHexPrefix(evenHex))).toString(16));
|
|
5482
|
+
}
|
|
5483
|
+
function keccakHex(value) {
|
|
5484
|
+
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
5485
|
+
}
|
|
5486
|
+
function starknetKeccak(value) {
|
|
5487
|
+
const hash2 = BigInt(keccakHex(value));
|
|
5488
|
+
return hash2 & MASK_2502;
|
|
5489
|
+
}
|
|
5490
|
+
function getSelectorFromName(funcName) {
|
|
5491
|
+
return toHex(starknetKeccak(funcName));
|
|
5492
|
+
}
|
|
5493
|
+
function getSelector(value) {
|
|
5494
|
+
if (isHex(value)) {
|
|
5495
|
+
return value;
|
|
5496
|
+
}
|
|
5497
|
+
if (isStringWholeNumber(value)) {
|
|
5498
|
+
return toHexString(value);
|
|
5499
|
+
}
|
|
5500
|
+
return getSelectorFromName(value);
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5503
|
+
// src/utils/shortString.ts
|
|
5504
|
+
var shortString_exports = {};
|
|
5505
|
+
__export(shortString_exports, {
|
|
5506
|
+
decodeShortString: () => decodeShortString,
|
|
5507
|
+
encodeShortString: () => encodeShortString,
|
|
5508
|
+
isASCII: () => isASCII,
|
|
5509
|
+
isDecimalString: () => isDecimalString,
|
|
5510
|
+
isLongText: () => isLongText,
|
|
5511
|
+
isShortString: () => isShortString,
|
|
5512
|
+
isShortText: () => isShortText,
|
|
5513
|
+
isText: () => isText,
|
|
5514
|
+
splitLongString: () => splitLongString
|
|
5515
|
+
});
|
|
5516
|
+
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
5517
|
+
function isASCII(str) {
|
|
5518
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
5519
|
+
}
|
|
5520
|
+
function isShortString(str) {
|
|
5521
|
+
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
5522
|
+
}
|
|
5523
|
+
function isDecimalString(decim) {
|
|
5524
|
+
return /^[0-9]*$/i.test(decim);
|
|
5525
|
+
}
|
|
5526
|
+
function isText(val) {
|
|
5527
|
+
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
5528
|
+
}
|
|
5529
|
+
var isShortText = (val) => isText(val) && isShortString(val);
|
|
5530
|
+
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
5531
|
+
function splitLongString(longStr) {
|
|
5532
|
+
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
5533
|
+
return longStr.match(regex) || [];
|
|
5534
|
+
}
|
|
5535
|
+
function encodeShortString(str) {
|
|
5536
|
+
if (!isASCII(str))
|
|
5537
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
5538
|
+
if (!isShortString(str))
|
|
5539
|
+
throw new Error(`${str} is too long`);
|
|
5540
|
+
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
5541
|
+
}
|
|
5542
|
+
function decodeShortString(str) {
|
|
5543
|
+
if (!isASCII(str))
|
|
5544
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
5545
|
+
if (isHex(str)) {
|
|
5546
|
+
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
5547
|
+
}
|
|
5548
|
+
if (isDecimalString(str)) {
|
|
5549
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
5550
|
+
}
|
|
5551
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
5552
|
+
}
|
|
5553
|
+
|
|
5213
5554
|
// src/utils/calldata/cairo.ts
|
|
5214
5555
|
var cairo_exports = {};
|
|
5215
5556
|
__export(cairo_exports, {
|
|
@@ -5231,441 +5572,666 @@ var starknet = (() => {
|
|
|
5231
5572
|
uint256: () => uint256
|
|
5232
5573
|
});
|
|
5233
5574
|
|
|
5234
|
-
// src/utils/
|
|
5235
|
-
var
|
|
5236
|
-
__export(
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
getHexString: () => getHexString,
|
|
5243
|
-
getHexStringArray: () => getHexStringArray,
|
|
5244
|
-
hexToBytes: () => hexToBytes3,
|
|
5245
|
-
hexToDecimalString: () => hexToDecimalString,
|
|
5246
|
-
isBigInt: () => isBigInt,
|
|
5247
|
-
isHex: () => isHex,
|
|
5248
|
-
isStringWholeNumber: () => isStringWholeNumber,
|
|
5249
|
-
toBigInt: () => toBigInt,
|
|
5250
|
-
toCairoBool: () => toCairoBool,
|
|
5251
|
-
toHex: () => toHex,
|
|
5252
|
-
toHexString: () => toHexString
|
|
5575
|
+
// src/utils/uint256.ts
|
|
5576
|
+
var uint256_exports = {};
|
|
5577
|
+
__export(uint256_exports, {
|
|
5578
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
5579
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
5580
|
+
bnToUint256: () => bnToUint256,
|
|
5581
|
+
isUint256: () => isUint256,
|
|
5582
|
+
uint256ToBN: () => uint256ToBN
|
|
5253
5583
|
});
|
|
5584
|
+
function uint256ToBN(uint2562) {
|
|
5585
|
+
return (toBigInt(uint2562.high) << 128n) + toBigInt(uint2562.low);
|
|
5586
|
+
}
|
|
5587
|
+
var UINT_128_MAX = (1n << 128n) - 1n;
|
|
5588
|
+
var UINT_256_MAX = (1n << 256n) - 1n;
|
|
5589
|
+
function isUint256(bn) {
|
|
5590
|
+
return toBigInt(bn) <= UINT_256_MAX;
|
|
5591
|
+
}
|
|
5592
|
+
function bnToUint256(bignumber) {
|
|
5593
|
+
const bn = toBigInt(bignumber);
|
|
5594
|
+
if (!isUint256(bn))
|
|
5595
|
+
throw new Error("Number is too large");
|
|
5596
|
+
return {
|
|
5597
|
+
low: addHexPrefix((bn & UINT_128_MAX).toString(16)),
|
|
5598
|
+
high: addHexPrefix((bn >> 128n).toString(16))
|
|
5599
|
+
};
|
|
5600
|
+
}
|
|
5254
5601
|
|
|
5255
|
-
//
|
|
5256
|
-
var
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
var _1n6 = BigInt(1);
|
|
5280
|
-
var _2n5 = BigInt(2);
|
|
5281
|
-
var u8a2 = (a) => a instanceof Uint8Array;
|
|
5282
|
-
var hexes3 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
|
|
5283
|
-
function bytesToHex2(bytes2) {
|
|
5284
|
-
if (!u8a2(bytes2))
|
|
5285
|
-
throw new Error("Uint8Array expected");
|
|
5286
|
-
let hex = "";
|
|
5287
|
-
for (let i = 0; i < bytes2.length; i++) {
|
|
5288
|
-
hex += hexes3[bytes2[i]];
|
|
5602
|
+
// src/utils/calldata/cairo.ts
|
|
5603
|
+
var Uint = /* @__PURE__ */ ((Uint2) => {
|
|
5604
|
+
Uint2["u8"] = "core::integer::u8";
|
|
5605
|
+
Uint2["u16"] = "core::integer::u16";
|
|
5606
|
+
Uint2["u32"] = "core::integer::u32";
|
|
5607
|
+
Uint2["u64"] = "core::integer::u64";
|
|
5608
|
+
Uint2["u128"] = "core::integer::u128";
|
|
5609
|
+
Uint2["u256"] = "core::integer::u256";
|
|
5610
|
+
return Uint2;
|
|
5611
|
+
})(Uint || {});
|
|
5612
|
+
var isLen = (name) => /_len$/.test(name);
|
|
5613
|
+
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
5614
|
+
var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::");
|
|
5615
|
+
var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
|
|
5616
|
+
var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
|
|
5617
|
+
var isTypeStruct = (type, structs) => type in structs;
|
|
5618
|
+
var isTypeUint = (type) => Object.values(Uint).includes(type);
|
|
5619
|
+
var isTypeUint256 = (type) => type === "core::integer::u256";
|
|
5620
|
+
var isTypeBool = (type) => type === "core::bool";
|
|
5621
|
+
var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
|
|
5622
|
+
var isCairo1Type = (type) => type.includes("core::");
|
|
5623
|
+
var getArrayType = (type) => {
|
|
5624
|
+
if (isCairo1Type(type)) {
|
|
5625
|
+
return type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
|
|
5289
5626
|
}
|
|
5290
|
-
return
|
|
5291
|
-
}
|
|
5292
|
-
|
|
5293
|
-
const
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
}
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
throw new Error("hex string is invalid: unpadded " + hex.length);
|
|
5306
|
-
const array = new Uint8Array(hex.length / 2);
|
|
5307
|
-
for (let i = 0; i < array.length; i++) {
|
|
5308
|
-
const j = i * 2;
|
|
5309
|
-
const hexByte = hex.slice(j, j + 2);
|
|
5310
|
-
const byte = Number.parseInt(hexByte, 16);
|
|
5311
|
-
if (Number.isNaN(byte) || byte < 0)
|
|
5312
|
-
throw new Error("invalid byte sequence");
|
|
5313
|
-
array[i] = byte;
|
|
5627
|
+
return type.replace("*", "");
|
|
5628
|
+
};
|
|
5629
|
+
var uint256 = (it) => {
|
|
5630
|
+
const bn = BigInt(it);
|
|
5631
|
+
if (!isUint256(bn))
|
|
5632
|
+
throw new Error("Number is too large");
|
|
5633
|
+
return {
|
|
5634
|
+
low: (bn & UINT_128_MAX).toString(10),
|
|
5635
|
+
high: (bn >> 128n).toString(10)
|
|
5636
|
+
};
|
|
5637
|
+
};
|
|
5638
|
+
var tuple = (...args) => ({ ...args });
|
|
5639
|
+
function felt(it) {
|
|
5640
|
+
if (isBigInt(it) || typeof it === "number" && Number.isInteger(it)) {
|
|
5641
|
+
return it.toString();
|
|
5314
5642
|
}
|
|
5315
|
-
|
|
5643
|
+
if (isText(it)) {
|
|
5644
|
+
if (!isShortString(it))
|
|
5645
|
+
throw new Error(
|
|
5646
|
+
`${it} is a long string > 31 chars, felt can store short strings, split it to array of short strings`
|
|
5647
|
+
);
|
|
5648
|
+
const encoded = encodeShortString(it);
|
|
5649
|
+
return BigInt(encoded).toString();
|
|
5650
|
+
}
|
|
5651
|
+
if (typeof it === "string" && isHex(it)) {
|
|
5652
|
+
return BigInt(it).toString();
|
|
5653
|
+
}
|
|
5654
|
+
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
5655
|
+
return it;
|
|
5656
|
+
}
|
|
5657
|
+
if (typeof it === "boolean") {
|
|
5658
|
+
return `${+it}`;
|
|
5659
|
+
}
|
|
5660
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
5316
5661
|
}
|
|
5317
|
-
|
|
5318
|
-
|
|
5662
|
+
|
|
5663
|
+
// src/utils/calldata/formatter.ts
|
|
5664
|
+
var guard = {
|
|
5665
|
+
isBN: (data, type, key) => {
|
|
5666
|
+
if (!isBigInt(data[key]))
|
|
5667
|
+
throw new Error(
|
|
5668
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
5669
|
+
);
|
|
5670
|
+
},
|
|
5671
|
+
unknown: (data, type, key) => {
|
|
5672
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
5673
|
+
}
|
|
5674
|
+
};
|
|
5675
|
+
function formatter(data, type, sameType) {
|
|
5676
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
5677
|
+
const elType = sameType ?? type[key];
|
|
5678
|
+
if (!(key in type) && !sameType) {
|
|
5679
|
+
acc[key] = value;
|
|
5680
|
+
return acc;
|
|
5681
|
+
}
|
|
5682
|
+
if (elType === "string") {
|
|
5683
|
+
if (Array.isArray(data[key])) {
|
|
5684
|
+
const arrayStr = formatter(
|
|
5685
|
+
data[key],
|
|
5686
|
+
data[key].map((_) => elType)
|
|
5687
|
+
);
|
|
5688
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
5689
|
+
return acc;
|
|
5690
|
+
}
|
|
5691
|
+
guard.isBN(data, type, key);
|
|
5692
|
+
acc[key] = decodeShortString(value);
|
|
5693
|
+
return acc;
|
|
5694
|
+
}
|
|
5695
|
+
if (elType === "number") {
|
|
5696
|
+
guard.isBN(data, type, key);
|
|
5697
|
+
acc[key] = Number(value);
|
|
5698
|
+
return acc;
|
|
5699
|
+
}
|
|
5700
|
+
if (typeof elType === "function") {
|
|
5701
|
+
acc[key] = elType(value);
|
|
5702
|
+
return acc;
|
|
5703
|
+
}
|
|
5704
|
+
if (Array.isArray(elType)) {
|
|
5705
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
5706
|
+
acc[key] = Object.values(arrayObj);
|
|
5707
|
+
return acc;
|
|
5708
|
+
}
|
|
5709
|
+
if (typeof elType === "object") {
|
|
5710
|
+
acc[key] = formatter(data[key], elType);
|
|
5711
|
+
return acc;
|
|
5712
|
+
}
|
|
5713
|
+
guard.unknown(data, type, key);
|
|
5714
|
+
return acc;
|
|
5715
|
+
}, {});
|
|
5319
5716
|
}
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5717
|
+
|
|
5718
|
+
// src/utils/calldata/tuple.ts
|
|
5719
|
+
function parseNamedTuple(namedTuple) {
|
|
5720
|
+
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
5721
|
+
const type = namedTuple.substring(name.length + ":".length);
|
|
5722
|
+
return { name, type };
|
|
5324
5723
|
}
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
let
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5724
|
+
function parseSubTuple(s) {
|
|
5725
|
+
if (!s.includes("("))
|
|
5726
|
+
return { subTuple: [], result: s };
|
|
5727
|
+
const subTuple = [];
|
|
5728
|
+
let result = "";
|
|
5729
|
+
let i = 0;
|
|
5730
|
+
while (i < s.length) {
|
|
5731
|
+
if (s[i] === "(") {
|
|
5732
|
+
let counter = 1;
|
|
5733
|
+
const lBracket = i;
|
|
5734
|
+
i++;
|
|
5735
|
+
while (counter) {
|
|
5736
|
+
if (s[i] === ")")
|
|
5737
|
+
counter--;
|
|
5738
|
+
if (s[i] === "(")
|
|
5739
|
+
counter++;
|
|
5740
|
+
i++;
|
|
5741
|
+
}
|
|
5742
|
+
subTuple.push(s.substring(lBracket, i));
|
|
5743
|
+
result += " ";
|
|
5744
|
+
i--;
|
|
5745
|
+
} else {
|
|
5746
|
+
result += s[i];
|
|
5335
5747
|
}
|
|
5336
|
-
|
|
5337
|
-
res = Uint8Array.from(hex);
|
|
5338
|
-
} else {
|
|
5339
|
-
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
5748
|
+
i++;
|
|
5340
5749
|
}
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5750
|
+
return {
|
|
5751
|
+
subTuple,
|
|
5752
|
+
result
|
|
5753
|
+
};
|
|
5345
5754
|
}
|
|
5346
|
-
function
|
|
5347
|
-
const
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
throw new Error("Uint8Array expected");
|
|
5352
|
-
r.set(a, pad);
|
|
5353
|
-
pad += a.length;
|
|
5755
|
+
function extractCairo0Tuple(type) {
|
|
5756
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
5757
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
5758
|
+
let recomposed = result.split(",").map((it) => {
|
|
5759
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
5354
5760
|
});
|
|
5355
|
-
|
|
5761
|
+
if (isTypeNamedTuple(type)) {
|
|
5762
|
+
recomposed = recomposed.reduce((acc, it) => {
|
|
5763
|
+
return acc.concat(parseNamedTuple(it));
|
|
5764
|
+
}, []);
|
|
5765
|
+
}
|
|
5766
|
+
return recomposed;
|
|
5356
5767
|
}
|
|
5357
|
-
function
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
for (let i = 0; i < b1.length; i++)
|
|
5361
|
-
if (b1[i] !== b2[i])
|
|
5362
|
-
return false;
|
|
5363
|
-
return true;
|
|
5768
|
+
function extractCairo1Tuple(type) {
|
|
5769
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
5770
|
+
return cleanType.split(",");
|
|
5364
5771
|
}
|
|
5365
|
-
function
|
|
5366
|
-
if (
|
|
5367
|
-
|
|
5772
|
+
function extractTupleMemberTypes(type) {
|
|
5773
|
+
if (isCairo1Type(type)) {
|
|
5774
|
+
return extractCairo1Tuple(type);
|
|
5368
5775
|
}
|
|
5369
|
-
return
|
|
5370
|
-
}
|
|
5371
|
-
function bitLen2(n) {
|
|
5372
|
-
let len;
|
|
5373
|
-
for (len = 0; n > 0n; n >>= _1n6, len += 1)
|
|
5374
|
-
;
|
|
5375
|
-
return len;
|
|
5376
|
-
}
|
|
5377
|
-
var bitGet2 = (n, pos) => n >> BigInt(pos) & 1n;
|
|
5378
|
-
var bitSet2 = (n, pos, value) => n | (value ? _1n6 : _0n6) << BigInt(pos);
|
|
5379
|
-
var bitMask2 = (n) => (_2n5 << BigInt(n - 1)) - _1n6;
|
|
5380
|
-
var u8n2 = (data) => new Uint8Array(data);
|
|
5381
|
-
var u8fr2 = (arr) => Uint8Array.from(arr);
|
|
5382
|
-
function createHmacDrbg2(hashLen, qByteLen, hmacFn) {
|
|
5383
|
-
if (typeof hashLen !== "number" || hashLen < 2)
|
|
5384
|
-
throw new Error("hashLen must be a number");
|
|
5385
|
-
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
5386
|
-
throw new Error("qByteLen must be a number");
|
|
5387
|
-
if (typeof hmacFn !== "function")
|
|
5388
|
-
throw new Error("hmacFn must be a function");
|
|
5389
|
-
let v = u8n2(hashLen);
|
|
5390
|
-
let k = u8n2(hashLen);
|
|
5391
|
-
let i = 0;
|
|
5392
|
-
const reset = () => {
|
|
5393
|
-
v.fill(1);
|
|
5394
|
-
k.fill(0);
|
|
5395
|
-
i = 0;
|
|
5396
|
-
};
|
|
5397
|
-
const h = (...b) => hmacFn(k, v, ...b);
|
|
5398
|
-
const reseed = (seed = u8n2()) => {
|
|
5399
|
-
k = h(u8fr2([0]), seed);
|
|
5400
|
-
v = h();
|
|
5401
|
-
if (seed.length === 0)
|
|
5402
|
-
return;
|
|
5403
|
-
k = h(u8fr2([1]), seed);
|
|
5404
|
-
v = h();
|
|
5405
|
-
};
|
|
5406
|
-
const gen2 = () => {
|
|
5407
|
-
if (i++ >= 1e3)
|
|
5408
|
-
throw new Error("drbg: tried 1000 values");
|
|
5409
|
-
let len = 0;
|
|
5410
|
-
const out = [];
|
|
5411
|
-
while (len < qByteLen) {
|
|
5412
|
-
v = h();
|
|
5413
|
-
const sl = v.slice();
|
|
5414
|
-
out.push(sl);
|
|
5415
|
-
len += v.length;
|
|
5416
|
-
}
|
|
5417
|
-
return concatBytes3(...out);
|
|
5418
|
-
};
|
|
5419
|
-
const genUntil = (seed, pred) => {
|
|
5420
|
-
reset();
|
|
5421
|
-
reseed(seed);
|
|
5422
|
-
let res = void 0;
|
|
5423
|
-
while (!(res = pred(gen2())))
|
|
5424
|
-
reseed();
|
|
5425
|
-
reset();
|
|
5426
|
-
return res;
|
|
5427
|
-
};
|
|
5428
|
-
return genUntil;
|
|
5429
|
-
}
|
|
5430
|
-
var validatorFns2 = {
|
|
5431
|
-
bigint: (val) => typeof val === "bigint",
|
|
5432
|
-
function: (val) => typeof val === "function",
|
|
5433
|
-
boolean: (val) => typeof val === "boolean",
|
|
5434
|
-
string: (val) => typeof val === "string",
|
|
5435
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
5436
|
-
array: (val) => Array.isArray(val),
|
|
5437
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
5438
|
-
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
5439
|
-
};
|
|
5440
|
-
function validateObject2(object, validators, optValidators = {}) {
|
|
5441
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
5442
|
-
const checkVal = validatorFns2[type];
|
|
5443
|
-
if (typeof checkVal !== "function")
|
|
5444
|
-
throw new Error(`Invalid validator "${type}", expected function`);
|
|
5445
|
-
const val = object[fieldName];
|
|
5446
|
-
if (isOptional && val === void 0)
|
|
5447
|
-
return;
|
|
5448
|
-
if (!checkVal(val, object)) {
|
|
5449
|
-
throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
|
|
5450
|
-
}
|
|
5451
|
-
};
|
|
5452
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
5453
|
-
checkField(fieldName, type, false);
|
|
5454
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
5455
|
-
checkField(fieldName, type, true);
|
|
5456
|
-
return object;
|
|
5776
|
+
return extractCairo0Tuple(type);
|
|
5457
5777
|
}
|
|
5458
5778
|
|
|
5459
|
-
// src/utils/
|
|
5460
|
-
function
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
}
|
|
5469
|
-
function toHex(number3) {
|
|
5470
|
-
return addHexPrefix(toBigInt(number3).toString(16));
|
|
5471
|
-
}
|
|
5472
|
-
function hexToDecimalString(hex) {
|
|
5473
|
-
return BigInt(addHexPrefix(hex)).toString(10);
|
|
5474
|
-
}
|
|
5475
|
-
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
5476
|
-
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
5477
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
5478
|
-
const inputBigInt = BigInt(input);
|
|
5479
|
-
const lowerBoundBigInt = BigInt(lowerBound);
|
|
5480
|
-
const upperBoundBigInt = BigInt(upperBound);
|
|
5481
|
-
assert(
|
|
5482
|
-
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
5483
|
-
`Message not signable, ${messageSuffix}.`
|
|
5484
|
-
);
|
|
5485
|
-
}
|
|
5486
|
-
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
5487
|
-
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
5779
|
+
// src/utils/calldata/requestParser.ts
|
|
5780
|
+
function parseBaseTypes(type, val) {
|
|
5781
|
+
switch (true) {
|
|
5782
|
+
case isTypeUint256(type):
|
|
5783
|
+
const el_uint256 = uint256(val);
|
|
5784
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
5785
|
+
default:
|
|
5786
|
+
return felt(val);
|
|
5787
|
+
}
|
|
5488
5788
|
}
|
|
5489
|
-
function
|
|
5490
|
-
|
|
5789
|
+
function parseTuple(element, typeStr) {
|
|
5790
|
+
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
5791
|
+
const elements = Object.values(element);
|
|
5792
|
+
if (elements.length !== memberTypes.length) {
|
|
5793
|
+
throw Error(
|
|
5794
|
+
`ParseTuple: provided and expected abi tuple size do not match.
|
|
5795
|
+
provided: ${elements}
|
|
5796
|
+
expected: ${memberTypes}`
|
|
5797
|
+
);
|
|
5798
|
+
}
|
|
5799
|
+
return memberTypes.map((it, dx) => {
|
|
5800
|
+
return {
|
|
5801
|
+
element: elements[dx],
|
|
5802
|
+
type: it.type ?? it
|
|
5803
|
+
};
|
|
5804
|
+
});
|
|
5491
5805
|
}
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
if (isHex(value)) {
|
|
5496
|
-
return hexToDecimalString(value);
|
|
5806
|
+
function parseCalldataValue(element, type, structs) {
|
|
5807
|
+
if (element === void 0) {
|
|
5808
|
+
throw Error(`Missing parameter for type ${type}`);
|
|
5497
5809
|
}
|
|
5498
|
-
if (
|
|
5499
|
-
|
|
5810
|
+
if (Array.isArray(element)) {
|
|
5811
|
+
const result = [];
|
|
5812
|
+
result.push(felt(element.length));
|
|
5813
|
+
const arrayType = getArrayType(type);
|
|
5814
|
+
return element.reduce((acc, it) => {
|
|
5815
|
+
return acc.concat(parseCalldataValue(it, arrayType, structs));
|
|
5816
|
+
}, result);
|
|
5500
5817
|
}
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5818
|
+
if (structs[type] && structs[type].members.length) {
|
|
5819
|
+
const { members } = structs[type];
|
|
5820
|
+
const subElement = element;
|
|
5821
|
+
return members.reduce((acc, it) => {
|
|
5822
|
+
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
5823
|
+
}, []);
|
|
5506
5824
|
}
|
|
5507
|
-
if (
|
|
5508
|
-
|
|
5825
|
+
if (isTypeTuple(type)) {
|
|
5826
|
+
const tupled = parseTuple(element, type);
|
|
5827
|
+
return tupled.reduce((acc, it) => {
|
|
5828
|
+
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
5829
|
+
return acc.concat(parsedData);
|
|
5830
|
+
}, []);
|
|
5509
5831
|
}
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
return
|
|
5832
|
+
if (typeof element === "object") {
|
|
5833
|
+
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
5834
|
+
}
|
|
5835
|
+
return parseBaseTypes(type, element);
|
|
5514
5836
|
}
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5837
|
+
function parseCalldataField(argsIterator, input, structs) {
|
|
5838
|
+
const { name, type } = input;
|
|
5839
|
+
let { value } = argsIterator.next();
|
|
5840
|
+
switch (true) {
|
|
5841
|
+
case isTypeArray(type):
|
|
5842
|
+
if (!Array.isArray(value) && !isText(value)) {
|
|
5843
|
+
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
5844
|
+
}
|
|
5845
|
+
if (typeof value === "string") {
|
|
5846
|
+
value = splitLongString(value);
|
|
5847
|
+
}
|
|
5848
|
+
return parseCalldataValue(value, input.type, structs);
|
|
5849
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
5850
|
+
return parseCalldataValue(value, type, structs);
|
|
5851
|
+
case isTypeUint256(type):
|
|
5852
|
+
if (typeof value === "object") {
|
|
5853
|
+
return [felt(value.low), felt(value.high)];
|
|
5854
|
+
}
|
|
5855
|
+
const el_uint256 = uint256(value);
|
|
5856
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
5857
|
+
default:
|
|
5858
|
+
return parseBaseTypes(type, value);
|
|
5522
5859
|
}
|
|
5523
|
-
return hexToBytes2(adaptedValue);
|
|
5524
5860
|
}
|
|
5525
5861
|
|
|
5526
|
-
// src/utils/
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
function isASCII(str) {
|
|
5541
|
-
return /^[\x00-\x7F]*$/.test(str);
|
|
5542
|
-
}
|
|
5543
|
-
function isShortString(str) {
|
|
5544
|
-
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
5545
|
-
}
|
|
5546
|
-
function isDecimalString(decim) {
|
|
5547
|
-
return /^[0-9]*$/i.test(decim);
|
|
5548
|
-
}
|
|
5549
|
-
function isText(val) {
|
|
5550
|
-
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
5551
|
-
}
|
|
5552
|
-
var isShortText = (val) => isText(val) && isShortString(val);
|
|
5553
|
-
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
5554
|
-
function splitLongString(longStr) {
|
|
5555
|
-
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
5556
|
-
return longStr.match(regex) || [];
|
|
5557
|
-
}
|
|
5558
|
-
function encodeShortString(str) {
|
|
5559
|
-
if (!isASCII(str))
|
|
5560
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
5561
|
-
if (!isShortString(str))
|
|
5562
|
-
throw new Error(`${str} is too long`);
|
|
5563
|
-
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
5564
|
-
}
|
|
5565
|
-
function decodeShortString(str) {
|
|
5566
|
-
if (!isASCII(str))
|
|
5567
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
5568
|
-
if (isHex(str)) {
|
|
5569
|
-
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
5570
|
-
}
|
|
5571
|
-
if (isDecimalString(str)) {
|
|
5572
|
-
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
5862
|
+
// src/utils/calldata/responseParser.ts
|
|
5863
|
+
function parseBaseTypes2(type, it) {
|
|
5864
|
+
let temp;
|
|
5865
|
+
switch (true) {
|
|
5866
|
+
case isTypeBool(type):
|
|
5867
|
+
temp = it.next().value;
|
|
5868
|
+
return Boolean(BigInt(temp));
|
|
5869
|
+
case isTypeUint256(type):
|
|
5870
|
+
const low = it.next().value;
|
|
5871
|
+
const high = it.next().value;
|
|
5872
|
+
return uint256ToBN({ low, high });
|
|
5873
|
+
default:
|
|
5874
|
+
temp = it.next().value;
|
|
5875
|
+
return BigInt(temp);
|
|
5573
5876
|
}
|
|
5574
|
-
throw new Error(`${str} is not Hex or decimal`);
|
|
5575
5877
|
}
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5878
|
+
function parseResponseValue(responseIterator, element, structs) {
|
|
5879
|
+
if (element.type in structs && structs[element.type]) {
|
|
5880
|
+
return structs[element.type].members.reduce((acc, el) => {
|
|
5881
|
+
acc[el.name] = parseResponseValue(responseIterator, el, structs);
|
|
5882
|
+
return acc;
|
|
5883
|
+
}, {});
|
|
5884
|
+
}
|
|
5885
|
+
if (isTypeTuple(element.type)) {
|
|
5886
|
+
const memberTypes = extractTupleMemberTypes(element.type);
|
|
5887
|
+
return memberTypes.reduce((acc, it, idx) => {
|
|
5888
|
+
const name = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
5889
|
+
const type = (it == null ? void 0 : it.type) ? it.type : it;
|
|
5890
|
+
const el = { name, type };
|
|
5891
|
+
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
5892
|
+
return acc;
|
|
5893
|
+
}, {});
|
|
5894
|
+
}
|
|
5895
|
+
if (isTypeArray(element.type)) {
|
|
5896
|
+
const parsedDataArr = [];
|
|
5897
|
+
const el = { name: "", type: getArrayType(element.type) };
|
|
5898
|
+
const len = BigInt(responseIterator.next().value);
|
|
5899
|
+
while (parsedDataArr.length < len) {
|
|
5900
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, structs));
|
|
5901
|
+
}
|
|
5902
|
+
return parsedDataArr;
|
|
5903
|
+
}
|
|
5904
|
+
return parseBaseTypes2(element.type, responseIterator);
|
|
5593
5905
|
}
|
|
5594
|
-
function
|
|
5595
|
-
const
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5906
|
+
function responseParser(responseIterator, output2, structs, parsedResult) {
|
|
5907
|
+
const { name, type } = output2;
|
|
5908
|
+
let temp;
|
|
5909
|
+
switch (true) {
|
|
5910
|
+
case isLen(name):
|
|
5911
|
+
temp = responseIterator.next().value;
|
|
5912
|
+
return BigInt(temp);
|
|
5913
|
+
case (type in structs || isTypeTuple(type)):
|
|
5914
|
+
return parseResponseValue(responseIterator, output2, structs);
|
|
5915
|
+
case isTypeArray(type):
|
|
5916
|
+
if (isCairo1Type(type)) {
|
|
5917
|
+
return parseResponseValue(responseIterator, output2, structs);
|
|
5918
|
+
}
|
|
5919
|
+
const parsedDataArr = [];
|
|
5920
|
+
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
5921
|
+
const arrLen = parsedResult[`${name}_len`];
|
|
5922
|
+
while (parsedDataArr.length < arrLen) {
|
|
5923
|
+
parsedDataArr.push(
|
|
5924
|
+
parseResponseValue(
|
|
5925
|
+
responseIterator,
|
|
5926
|
+
{ name, type: output2.type.replace("*", "") },
|
|
5927
|
+
structs
|
|
5928
|
+
)
|
|
5929
|
+
);
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
return parsedDataArr;
|
|
5933
|
+
default:
|
|
5934
|
+
return parseBaseTypes2(type, responseIterator);
|
|
5935
|
+
}
|
|
5602
5936
|
}
|
|
5603
5937
|
|
|
5604
|
-
// src/utils/calldata/
|
|
5605
|
-
var
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5938
|
+
// src/utils/calldata/validate.ts
|
|
5939
|
+
var validateFelt = (parameter, input) => {
|
|
5940
|
+
assert(
|
|
5941
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
5942
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
5943
|
+
);
|
|
5944
|
+
};
|
|
5945
|
+
var validateUint = (parameter, input) => {
|
|
5946
|
+
if (typeof parameter === "number") {
|
|
5947
|
+
assert(
|
|
5948
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
5949
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
5950
|
+
);
|
|
5951
|
+
}
|
|
5952
|
+
assert(
|
|
5953
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
|
|
5954
|
+
`Validate: arg ${input.name} of cairo ZORG type ${input.type} should be type (String, Number or BigInt)`
|
|
5955
|
+
);
|
|
5956
|
+
const param = typeof parameter === "object" ? uint256ToBN(parameter) : toBigInt(parameter);
|
|
5957
|
+
switch (input.type) {
|
|
5958
|
+
case "core::integer::u8" /* u8 */:
|
|
5959
|
+
assert(
|
|
5960
|
+
param >= 0n && param <= 255n,
|
|
5961
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
5962
|
+
);
|
|
5963
|
+
break;
|
|
5964
|
+
case "core::integer::u16" /* u16 */:
|
|
5965
|
+
assert(
|
|
5966
|
+
param >= 0n && param <= 65535n,
|
|
5967
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
5968
|
+
);
|
|
5969
|
+
break;
|
|
5970
|
+
case "core::integer::u32" /* u32 */:
|
|
5971
|
+
assert(
|
|
5972
|
+
param >= 0n && param <= 4294967295n,
|
|
5973
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
5974
|
+
);
|
|
5975
|
+
break;
|
|
5976
|
+
case "core::integer::u64" /* u64 */:
|
|
5977
|
+
assert(
|
|
5978
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
5979
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
5980
|
+
);
|
|
5981
|
+
break;
|
|
5982
|
+
case "core::integer::u128" /* u128 */:
|
|
5983
|
+
assert(
|
|
5984
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
5985
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
5986
|
+
);
|
|
5987
|
+
break;
|
|
5988
|
+
case "core::integer::u256" /* u256 */:
|
|
5989
|
+
assert(
|
|
5990
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
5991
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
5992
|
+
);
|
|
5993
|
+
break;
|
|
5994
|
+
default:
|
|
5995
|
+
break;
|
|
5628
5996
|
}
|
|
5629
|
-
return type.replace("*", "");
|
|
5630
5997
|
};
|
|
5631
|
-
var
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
low: (bn & UINT_128_MAX).toString(10),
|
|
5637
|
-
high: (bn >> 128n).toString(10)
|
|
5638
|
-
};
|
|
5998
|
+
var validateBool = (parameter, input) => {
|
|
5999
|
+
assert(
|
|
6000
|
+
typeof parameter === "boolean",
|
|
6001
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
6002
|
+
);
|
|
5639
6003
|
};
|
|
5640
|
-
var
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
6004
|
+
var validateStruct = (parameter, input, structs) => {
|
|
6005
|
+
assert(
|
|
6006
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
6007
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
6008
|
+
);
|
|
6009
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
6010
|
+
assert(
|
|
6011
|
+
Object.keys(parameter).includes(name),
|
|
6012
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
6013
|
+
);
|
|
6014
|
+
});
|
|
6015
|
+
};
|
|
6016
|
+
var validateTuple = (parameter, input) => {
|
|
6017
|
+
assert(
|
|
6018
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
6019
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
6020
|
+
);
|
|
6021
|
+
};
|
|
6022
|
+
var validateArray = (parameter, input, structs) => {
|
|
6023
|
+
const baseType = getArrayType(input.type);
|
|
6024
|
+
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
6025
|
+
return;
|
|
6026
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
6027
|
+
switch (true) {
|
|
6028
|
+
case isTypeFelt(baseType):
|
|
6029
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
6030
|
+
break;
|
|
6031
|
+
case isTypeTuple(baseType):
|
|
6032
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
6033
|
+
break;
|
|
6034
|
+
case isTypeStruct(baseType, structs):
|
|
6035
|
+
parameter.forEach(
|
|
6036
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
6037
|
+
);
|
|
6038
|
+
break;
|
|
6039
|
+
case isTypeUint(baseType):
|
|
6040
|
+
parameter.forEach((param) => validateUint(param, input));
|
|
6041
|
+
break;
|
|
6042
|
+
case isTypeBool(baseType):
|
|
6043
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
6044
|
+
break;
|
|
6045
|
+
case isTypeArray(baseType):
|
|
6046
|
+
parameter.forEach(
|
|
6047
|
+
(param) => validateArray(param, { name: "", type: baseType }, structs)
|
|
6048
|
+
);
|
|
6049
|
+
break;
|
|
6050
|
+
default:
|
|
5647
6051
|
throw new Error(
|
|
5648
|
-
|
|
6052
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
5649
6053
|
);
|
|
5650
|
-
const encoded = encodeShortString(it);
|
|
5651
|
-
return BigInt(encoded).toString();
|
|
5652
6054
|
}
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
6055
|
+
};
|
|
6056
|
+
function validateFields(abiMethod, args, structs) {
|
|
6057
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
6058
|
+
const parameter = args[acc];
|
|
6059
|
+
switch (true) {
|
|
6060
|
+
case isLen(input.name):
|
|
6061
|
+
return acc;
|
|
6062
|
+
case isTypeFelt(input.type):
|
|
6063
|
+
validateFelt(parameter, input);
|
|
6064
|
+
break;
|
|
6065
|
+
case isTypeUint(input.type):
|
|
6066
|
+
validateUint(parameter, input);
|
|
6067
|
+
break;
|
|
6068
|
+
case isTypeBool(input.type):
|
|
6069
|
+
validateBool(parameter, input);
|
|
6070
|
+
break;
|
|
6071
|
+
case isTypeContractAddress(input.type):
|
|
6072
|
+
break;
|
|
6073
|
+
case isTypeStruct(input.type, structs):
|
|
6074
|
+
validateStruct(parameter, input, structs);
|
|
6075
|
+
break;
|
|
6076
|
+
case isTypeTuple(input.type):
|
|
6077
|
+
validateTuple(parameter, input);
|
|
6078
|
+
break;
|
|
6079
|
+
case isTypeArray(input.type):
|
|
6080
|
+
validateArray(parameter, input, structs);
|
|
6081
|
+
break;
|
|
6082
|
+
default:
|
|
6083
|
+
throw new Error(
|
|
6084
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
6085
|
+
);
|
|
6086
|
+
}
|
|
6087
|
+
return acc + 1;
|
|
6088
|
+
}, 0);
|
|
5663
6089
|
}
|
|
5664
6090
|
|
|
5665
|
-
// src/utils/
|
|
5666
|
-
var
|
|
5667
|
-
|
|
5668
|
-
|
|
6091
|
+
// src/utils/calldata/index.ts
|
|
6092
|
+
var CallData = class {
|
|
6093
|
+
constructor(abi) {
|
|
6094
|
+
this.abi = abi;
|
|
6095
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
6096
|
+
}
|
|
6097
|
+
validate(type, method, args = []) {
|
|
6098
|
+
if (type !== "DEPLOY") {
|
|
6099
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
6100
|
+
if (abi.type !== "function")
|
|
6101
|
+
return false;
|
|
6102
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
6103
|
+
return type === "INVOKE" ? !isView : isView;
|
|
6104
|
+
}).map((abi) => abi.name);
|
|
6105
|
+
assert(
|
|
6106
|
+
invocableFunctionNames.includes(method),
|
|
6107
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
6108
|
+
);
|
|
6109
|
+
}
|
|
6110
|
+
const abiMethod = this.abi.find(
|
|
6111
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
6112
|
+
);
|
|
6113
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
6114
|
+
if (args.length !== inputsLength) {
|
|
6115
|
+
throw Error(
|
|
6116
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
6117
|
+
);
|
|
6118
|
+
}
|
|
6119
|
+
validateFields(abiMethod, args, this.structs);
|
|
6120
|
+
}
|
|
6121
|
+
compile(method, args) {
|
|
6122
|
+
const argsIterator = args[Symbol.iterator]();
|
|
6123
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
6124
|
+
return inputs.reduce(
|
|
6125
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
6126
|
+
[]
|
|
6127
|
+
);
|
|
6128
|
+
}
|
|
6129
|
+
static compile(rawArgs) {
|
|
6130
|
+
const createTree = (obj) => {
|
|
6131
|
+
const getEntries = (o, prefix = "") => {
|
|
6132
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
6133
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
6134
|
+
let value = v;
|
|
6135
|
+
if (isLongText(value))
|
|
6136
|
+
value = splitLongString(value);
|
|
6137
|
+
if (k === "entrypoint")
|
|
6138
|
+
value = getSelectorFromName(value);
|
|
6139
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
6140
|
+
if (isBigInt(value))
|
|
6141
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
6142
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
6143
|
+
});
|
|
6144
|
+
};
|
|
6145
|
+
return Object.fromEntries(getEntries(obj));
|
|
6146
|
+
};
|
|
6147
|
+
let callTreeArray;
|
|
6148
|
+
if (!Array.isArray(rawArgs)) {
|
|
6149
|
+
const callTree = createTree(rawArgs);
|
|
6150
|
+
callTreeArray = Object.values(callTree);
|
|
6151
|
+
} else {
|
|
6152
|
+
const callObj = { ...rawArgs };
|
|
6153
|
+
const callTree = createTree(callObj);
|
|
6154
|
+
callTreeArray = Object.values(callTree);
|
|
6155
|
+
}
|
|
6156
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
6157
|
+
enumerable: false,
|
|
6158
|
+
writable: false,
|
|
6159
|
+
value: true
|
|
6160
|
+
});
|
|
6161
|
+
return callTreeArray;
|
|
6162
|
+
}
|
|
6163
|
+
parse(method, response) {
|
|
6164
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
6165
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
6166
|
+
const parsed = outputs.flat().reduce((acc, output2, idx) => {
|
|
6167
|
+
const propName = output2.name ?? idx;
|
|
6168
|
+
acc[propName] = responseParser(responseIterator, output2, this.structs, acc);
|
|
6169
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
6170
|
+
delete acc[`${propName}_len`];
|
|
6171
|
+
}
|
|
6172
|
+
return acc;
|
|
6173
|
+
}, {});
|
|
6174
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
6175
|
+
}
|
|
6176
|
+
format(method, response, format) {
|
|
6177
|
+
const parsed = this.parse(method, response);
|
|
6178
|
+
return formatter(parsed, format);
|
|
6179
|
+
}
|
|
6180
|
+
static abiInputsLength(inputs) {
|
|
6181
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
6182
|
+
}
|
|
6183
|
+
static getAbiStruct(abi) {
|
|
6184
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
6185
|
+
(acc, abiEntry) => ({
|
|
6186
|
+
...acc,
|
|
6187
|
+
[abiEntry.name]: abiEntry
|
|
6188
|
+
}),
|
|
6189
|
+
{}
|
|
6190
|
+
);
|
|
6191
|
+
}
|
|
6192
|
+
static toCalldata(rawCalldata = []) {
|
|
6193
|
+
return CallData.compile(rawCalldata);
|
|
6194
|
+
}
|
|
6195
|
+
static toHex(raw = []) {
|
|
6196
|
+
const calldata = CallData.compile(raw);
|
|
6197
|
+
return calldata.map((it) => toHex(it));
|
|
6198
|
+
}
|
|
6199
|
+
};
|
|
6200
|
+
|
|
6201
|
+
// src/utils/fetchPonyfill.ts
|
|
6202
|
+
var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
|
|
6203
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
6204
|
+
|
|
6205
|
+
// src/utils/hash.ts
|
|
6206
|
+
var hash_exports = {};
|
|
6207
|
+
__export(hash_exports, {
|
|
6208
|
+
calculateContractAddressFromHash: () => calculateContractAddressFromHash,
|
|
6209
|
+
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash,
|
|
6210
|
+
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash,
|
|
6211
|
+
calculateDeployTransactionHash: () => calculateDeployTransactionHash,
|
|
6212
|
+
calculateTransactionHash: () => calculateTransactionHash,
|
|
6213
|
+
calculateTransactionHashCommon: () => calculateTransactionHashCommon,
|
|
6214
|
+
computeCompiledClassHash: () => computeCompiledClassHash,
|
|
6215
|
+
computeContractClassHash: () => computeContractClassHash,
|
|
6216
|
+
computeHashOnElements: () => computeHashOnElements2,
|
|
6217
|
+
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
6218
|
+
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
6219
|
+
default: () => computeHintedClassHash,
|
|
6220
|
+
feeTransactionVersion: () => feeTransactionVersion,
|
|
6221
|
+
formatSpaces: () => formatSpaces,
|
|
6222
|
+
getSelector: () => getSelector,
|
|
6223
|
+
getSelectorFromName: () => getSelectorFromName,
|
|
6224
|
+
keccakBn: () => keccakBn,
|
|
6225
|
+
poseidon: () => poseidon_exports,
|
|
6226
|
+
starknetKeccak: () => starknetKeccak,
|
|
6227
|
+
transactionVersion: () => transactionVersion,
|
|
6228
|
+
transactionVersion_2: () => transactionVersion_2
|
|
6229
|
+
});
|
|
6230
|
+
|
|
6231
|
+
// src/utils/ec.ts
|
|
6232
|
+
var ec_exports = {};
|
|
6233
|
+
__export(ec_exports, {
|
|
6234
|
+
starkCurve: () => esm_exports,
|
|
5669
6235
|
weierstrass: () => weierstrass_exports
|
|
5670
6236
|
});
|
|
5671
6237
|
|
|
@@ -5741,7 +6307,7 @@ var starknet = (() => {
|
|
|
5741
6307
|
map[val] = "function";
|
|
5742
6308
|
return map;
|
|
5743
6309
|
}, initial);
|
|
5744
|
-
return
|
|
6310
|
+
return validateObject(field, opts);
|
|
5745
6311
|
}
|
|
5746
6312
|
function FpPow2(f, num, power) {
|
|
5747
6313
|
if (power < _0n7)
|
|
@@ -5766,12 +6332,12 @@ var starknet = (() => {
|
|
|
5766
6332
|
return { nBitLength: _nBitLength, nByteLength };
|
|
5767
6333
|
}
|
|
5768
6334
|
function hashToPrivateScalar2(hash2, groupOrder, isLE2 = false) {
|
|
5769
|
-
hash2 =
|
|
6335
|
+
hash2 = ensureBytes("privateHash", hash2);
|
|
5770
6336
|
const hashLen = hash2.length;
|
|
5771
6337
|
const minLen = nLength2(groupOrder).nByteLength + 8;
|
|
5772
6338
|
if (minLen < 24 || hashLen < minLen || hashLen > 1024)
|
|
5773
6339
|
throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
|
|
5774
|
-
const num = isLE2 ?
|
|
6340
|
+
const num = isLE2 ? bytesToNumberLE(hash2) : bytesToNumberBE(hash2);
|
|
5775
6341
|
return mod2(num, groupOrder - _1n7) + _1n7;
|
|
5776
6342
|
}
|
|
5777
6343
|
|
|
@@ -5859,7 +6425,7 @@ var starknet = (() => {
|
|
|
5859
6425
|
}
|
|
5860
6426
|
function validateBasic2(curve2) {
|
|
5861
6427
|
validateField2(curve2.Fp);
|
|
5862
|
-
|
|
6428
|
+
validateObject(curve2, {
|
|
5863
6429
|
n: "bigint",
|
|
5864
6430
|
h: "bigint",
|
|
5865
6431
|
Gx: "field",
|
|
@@ -5874,7 +6440,7 @@ var starknet = (() => {
|
|
|
5874
6440
|
// node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
5875
6441
|
function validatePointOpts2(curve2) {
|
|
5876
6442
|
const opts = validateBasic2(curve2);
|
|
5877
|
-
|
|
6443
|
+
validateObject(opts, {
|
|
5878
6444
|
a: "field",
|
|
5879
6445
|
b: "field",
|
|
5880
6446
|
fromBytes: "function",
|
|
@@ -5897,7 +6463,7 @@ var starknet = (() => {
|
|
|
5897
6463
|
}
|
|
5898
6464
|
return Object.freeze({ ...opts });
|
|
5899
6465
|
}
|
|
5900
|
-
var { bytesToNumberBE: b2n2, hexToBytes: h2b2 } =
|
|
6466
|
+
var { bytesToNumberBE: b2n2, hexToBytes: h2b2 } = utils_exports;
|
|
5901
6467
|
var DER2 = {
|
|
5902
6468
|
Err: class DERErr2 extends Error {
|
|
5903
6469
|
constructor(m = "") {
|
|
@@ -5969,14 +6535,14 @@ var starknet = (() => {
|
|
|
5969
6535
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE2;
|
|
5970
6536
|
if (lengths && typeof key !== "bigint") {
|
|
5971
6537
|
if (key instanceof Uint8Array)
|
|
5972
|
-
key =
|
|
6538
|
+
key = bytesToHex(key);
|
|
5973
6539
|
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
5974
6540
|
throw new Error("Invalid key");
|
|
5975
6541
|
key = key.padStart(nByteLength * 2, "0");
|
|
5976
6542
|
}
|
|
5977
6543
|
let num;
|
|
5978
6544
|
try {
|
|
5979
|
-
num = typeof key === "bigint" ? key :
|
|
6545
|
+
num = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
|
|
5980
6546
|
} catch (error) {
|
|
5981
6547
|
throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
|
|
5982
6548
|
}
|
|
@@ -6024,7 +6590,7 @@ var starknet = (() => {
|
|
|
6024
6590
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
6025
6591
|
}
|
|
6026
6592
|
static fromHex(hex) {
|
|
6027
|
-
const P = Point.fromAffine(CURVE2.fromBytes(
|
|
6593
|
+
const P = Point.fromAffine(CURVE2.fromBytes(ensureBytes("pointHex", hex)));
|
|
6028
6594
|
P.assertValidity();
|
|
6029
6595
|
return P;
|
|
6030
6596
|
}
|
|
@@ -6259,7 +6825,7 @@ var starknet = (() => {
|
|
|
6259
6825
|
return CURVE2.toBytes(Point, this, isCompressed);
|
|
6260
6826
|
}
|
|
6261
6827
|
toHex(isCompressed = true) {
|
|
6262
|
-
return
|
|
6828
|
+
return bytesToHex(this.toRawBytes(isCompressed));
|
|
6263
6829
|
}
|
|
6264
6830
|
}
|
|
6265
6831
|
Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp.ONE);
|
|
@@ -6275,7 +6841,7 @@ var starknet = (() => {
|
|
|
6275
6841
|
}
|
|
6276
6842
|
function validateOpts3(curve2) {
|
|
6277
6843
|
const opts = validateBasic2(curve2);
|
|
6278
|
-
|
|
6844
|
+
validateObject(opts, {
|
|
6279
6845
|
hash: "hash",
|
|
6280
6846
|
hmac: "function",
|
|
6281
6847
|
randomBytes: "function"
|
|
@@ -6306,7 +6872,7 @@ var starknet = (() => {
|
|
|
6306
6872
|
toBytes(c, point, isCompressed) {
|
|
6307
6873
|
const a = point.toAffine();
|
|
6308
6874
|
const x = Fp.toBytes(a.x);
|
|
6309
|
-
const cat =
|
|
6875
|
+
const cat = concatBytes;
|
|
6310
6876
|
if (isCompressed) {
|
|
6311
6877
|
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
|
6312
6878
|
} else {
|
|
@@ -6318,7 +6884,7 @@ var starknet = (() => {
|
|
|
6318
6884
|
const head = bytes2[0];
|
|
6319
6885
|
const tail = bytes2.subarray(1);
|
|
6320
6886
|
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
6321
|
-
const x =
|
|
6887
|
+
const x = bytesToNumberBE(tail);
|
|
6322
6888
|
if (!isValidFieldElement(x))
|
|
6323
6889
|
throw new Error("Point is not on curve");
|
|
6324
6890
|
const y2 = weierstrassEquation(x);
|
|
@@ -6337,7 +6903,7 @@ var starknet = (() => {
|
|
|
6337
6903
|
}
|
|
6338
6904
|
}
|
|
6339
6905
|
});
|
|
6340
|
-
const numToNByteStr = (num) =>
|
|
6906
|
+
const numToNByteStr = (num) => bytesToHex(numberToBytesBE(num, CURVE2.nByteLength));
|
|
6341
6907
|
function isBiggerThanHalfOrder(number3) {
|
|
6342
6908
|
const HALF = CURVE_ORDER2 >> _1n9;
|
|
6343
6909
|
return number3 > HALF;
|
|
@@ -6345,7 +6911,7 @@ var starknet = (() => {
|
|
|
6345
6911
|
function normalizeS(s) {
|
|
6346
6912
|
return isBiggerThanHalfOrder(s) ? modN(-s) : s;
|
|
6347
6913
|
}
|
|
6348
|
-
const slcNum = (b, from, to) =>
|
|
6914
|
+
const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
|
|
6349
6915
|
class Signature3 {
|
|
6350
6916
|
constructor(r, s, recovery) {
|
|
6351
6917
|
this.r = r;
|
|
@@ -6355,11 +6921,11 @@ var starknet = (() => {
|
|
|
6355
6921
|
}
|
|
6356
6922
|
static fromCompact(hex) {
|
|
6357
6923
|
const l = CURVE2.nByteLength;
|
|
6358
|
-
hex =
|
|
6924
|
+
hex = ensureBytes("compactSignature", hex, l * 2);
|
|
6359
6925
|
return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
6360
6926
|
}
|
|
6361
6927
|
static fromDER(hex) {
|
|
6362
|
-
const { r, s } = DER2.toSig(
|
|
6928
|
+
const { r, s } = DER2.toSig(ensureBytes("DER", hex));
|
|
6363
6929
|
return new Signature3(r, s);
|
|
6364
6930
|
}
|
|
6365
6931
|
assertValidity() {
|
|
@@ -6373,7 +6939,7 @@ var starknet = (() => {
|
|
|
6373
6939
|
}
|
|
6374
6940
|
recoverPublicKey(msgHash) {
|
|
6375
6941
|
const { r, s, recovery: rec } = this;
|
|
6376
|
-
const h = bits2int_modN(
|
|
6942
|
+
const h = bits2int_modN(ensureBytes("msgHash", msgHash));
|
|
6377
6943
|
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
6378
6944
|
throw new Error("recovery id invalid");
|
|
6379
6945
|
const radj = rec === 2 || rec === 3 ? r + CURVE2.n : r;
|
|
@@ -6397,13 +6963,13 @@ var starknet = (() => {
|
|
|
6397
6963
|
return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
|
|
6398
6964
|
}
|
|
6399
6965
|
toDERRawBytes() {
|
|
6400
|
-
return
|
|
6966
|
+
return hexToBytes(this.toDERHex());
|
|
6401
6967
|
}
|
|
6402
6968
|
toDERHex() {
|
|
6403
6969
|
return DER2.hexFromSig({ r: this.r, s: this.s });
|
|
6404
6970
|
}
|
|
6405
6971
|
toCompactRawBytes() {
|
|
6406
|
-
return
|
|
6972
|
+
return hexToBytes(this.toCompactHex());
|
|
6407
6973
|
}
|
|
6408
6974
|
toCompactHex() {
|
|
6409
6975
|
return numToNByteStr(this.r) + numToNByteStr(this.s);
|
|
@@ -6422,7 +6988,7 @@ var starknet = (() => {
|
|
|
6422
6988
|
randomPrivateKey: () => {
|
|
6423
6989
|
const rand = CURVE2.randomBytes(Fp.BYTES + 8);
|
|
6424
6990
|
const num = hashToPrivateScalar2(rand, CURVE_ORDER2);
|
|
6425
|
-
return
|
|
6991
|
+
return numberToBytesBE(num, CURVE2.nByteLength);
|
|
6426
6992
|
},
|
|
6427
6993
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
6428
6994
|
point._setWindowSize(windowSize);
|
|
@@ -6454,20 +7020,20 @@ var starknet = (() => {
|
|
|
6454
7020
|
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
6455
7021
|
}
|
|
6456
7022
|
const bits2int2 = CURVE2.bits2int || function(bytes2) {
|
|
6457
|
-
const num =
|
|
7023
|
+
const num = bytesToNumberBE(bytes2);
|
|
6458
7024
|
const delta = bytes2.length * 8 - CURVE2.nBitLength;
|
|
6459
7025
|
return delta > 0 ? num >> BigInt(delta) : num;
|
|
6460
7026
|
};
|
|
6461
7027
|
const bits2int_modN = CURVE2.bits2int_modN || function(bytes2) {
|
|
6462
7028
|
return modN(bits2int2(bytes2));
|
|
6463
7029
|
};
|
|
6464
|
-
const ORDER_MASK =
|
|
7030
|
+
const ORDER_MASK = bitMask(CURVE2.nBitLength);
|
|
6465
7031
|
function int2octets(num) {
|
|
6466
7032
|
if (typeof num !== "bigint")
|
|
6467
7033
|
throw new Error("bigint expected");
|
|
6468
7034
|
if (!(_0n9 <= num && num < ORDER_MASK))
|
|
6469
7035
|
throw new Error(`bigint expected < 2^${CURVE2.nBitLength}`);
|
|
6470
|
-
return
|
|
7036
|
+
return numberToBytesBE(num, CURVE2.nByteLength);
|
|
6471
7037
|
}
|
|
6472
7038
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
6473
7039
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
@@ -6476,17 +7042,17 @@ var starknet = (() => {
|
|
|
6476
7042
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
6477
7043
|
if (lowS == null)
|
|
6478
7044
|
lowS = true;
|
|
6479
|
-
msgHash =
|
|
7045
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
|
6480
7046
|
if (prehash)
|
|
6481
|
-
msgHash =
|
|
7047
|
+
msgHash = ensureBytes("prehashed msgHash", hash2(msgHash));
|
|
6482
7048
|
const h1int = bits2int_modN(msgHash);
|
|
6483
7049
|
const d = normPrivateKeyToScalar(privateKey);
|
|
6484
7050
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
6485
7051
|
if (ent != null) {
|
|
6486
7052
|
const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
|
|
6487
|
-
seedArgs.push(
|
|
7053
|
+
seedArgs.push(ensureBytes("extraEntropy", e, Fp.BYTES));
|
|
6488
7054
|
}
|
|
6489
|
-
const seed =
|
|
7055
|
+
const seed = concatBytes(...seedArgs);
|
|
6490
7056
|
const m = h1int;
|
|
6491
7057
|
function k2sig(kBytes) {
|
|
6492
7058
|
const k = bits2int2(kBytes);
|
|
@@ -6514,15 +7080,15 @@ var starknet = (() => {
|
|
|
6514
7080
|
const defaultVerOpts = { lowS: CURVE2.lowS, prehash: false };
|
|
6515
7081
|
function sign2(msgHash, privKey, opts = defaultSigOpts) {
|
|
6516
7082
|
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
6517
|
-
const drbg =
|
|
7083
|
+
const drbg = createHmacDrbg(CURVE2.hash.outputLen, CURVE2.nByteLength, CURVE2.hmac);
|
|
6518
7084
|
return drbg(seed, k2sig);
|
|
6519
7085
|
}
|
|
6520
7086
|
Point.BASE._setWindowSize(8);
|
|
6521
7087
|
function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
6522
7088
|
var _a;
|
|
6523
7089
|
const sg = signature;
|
|
6524
|
-
msgHash =
|
|
6525
|
-
publicKey =
|
|
7090
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
|
7091
|
+
publicKey = ensureBytes("publicKey", publicKey);
|
|
6526
7092
|
if ("strict" in opts)
|
|
6527
7093
|
throw new Error("options.strict was renamed to lowS");
|
|
6528
7094
|
const { lowS, prehash } = opts;
|
|
@@ -7449,30 +8015,6 @@ var starknet = (() => {
|
|
|
7449
8015
|
var transactionVersion = 1n;
|
|
7450
8016
|
var transactionVersion_2 = 2n;
|
|
7451
8017
|
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
7452
|
-
function keccakBn(value) {
|
|
7453
|
-
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
7454
|
-
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
7455
|
-
return addHexPrefix(keccak(hexToBytes3(addHexPrefix(evenHex))).toString(16));
|
|
7456
|
-
}
|
|
7457
|
-
function keccakHex(value) {
|
|
7458
|
-
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
7459
|
-
}
|
|
7460
|
-
function starknetKeccak(value) {
|
|
7461
|
-
const hash2 = BigInt(keccakHex(value));
|
|
7462
|
-
return hash2 & MASK_2502;
|
|
7463
|
-
}
|
|
7464
|
-
function getSelectorFromName(funcName) {
|
|
7465
|
-
return toHex(starknetKeccak(funcName));
|
|
7466
|
-
}
|
|
7467
|
-
function getSelector(value) {
|
|
7468
|
-
if (isHex(value)) {
|
|
7469
|
-
return value;
|
|
7470
|
-
}
|
|
7471
|
-
if (isStringWholeNumber(value)) {
|
|
7472
|
-
return toHexString(value);
|
|
7473
|
-
}
|
|
7474
|
-
return getSelectorFromName(value);
|
|
7475
|
-
}
|
|
7476
8018
|
function computeHashOnElements2(data) {
|
|
7477
8019
|
return [...data, data.length].reduce((x, y) => esm_exports.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
7478
8020
|
}
|
|
@@ -7533,678 +8075,146 @@ var starknet = (() => {
|
|
|
7533
8075
|
contractAddress,
|
|
7534
8076
|
0,
|
|
7535
8077
|
calldata,
|
|
7536
|
-
maxFee,
|
|
7537
|
-
chainId,
|
|
7538
|
-
[nonce]
|
|
7539
|
-
);
|
|
7540
|
-
}
|
|
7541
|
-
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
7542
|
-
const constructorCalldataHash = computeHashOnElements2(constructorCalldata);
|
|
7543
|
-
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
7544
|
-
return computeHashOnElements2([
|
|
7545
|
-
CONTRACT_ADDRESS_PREFIX,
|
|
7546
|
-
deployerAddress,
|
|
7547
|
-
salt,
|
|
7548
|
-
classHash,
|
|
7549
|
-
constructorCalldataHash
|
|
7550
|
-
]);
|
|
7551
|
-
}
|
|
7552
|
-
function nullSkipReplacer(key, value) {
|
|
7553
|
-
if (key === "attributes" || key === "accessible_scopes") {
|
|
7554
|
-
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
7555
|
-
}
|
|
7556
|
-
if (key === "debug_info") {
|
|
7557
|
-
return null;
|
|
7558
|
-
}
|
|
7559
|
-
return value === null ? void 0 : value;
|
|
7560
|
-
}
|
|
7561
|
-
function formatSpaces(json) {
|
|
7562
|
-
let insideQuotes = false;
|
|
7563
|
-
let newString = "";
|
|
7564
|
-
for (const char of json) {
|
|
7565
|
-
if (char === '"' && newString.endsWith("\\") === false) {
|
|
7566
|
-
insideQuotes = !insideQuotes;
|
|
7567
|
-
}
|
|
7568
|
-
if (insideQuotes) {
|
|
7569
|
-
newString += char;
|
|
7570
|
-
} else {
|
|
7571
|
-
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
7572
|
-
}
|
|
7573
|
-
}
|
|
7574
|
-
return newString;
|
|
7575
|
-
}
|
|
7576
|
-
function computeHintedClassHash(compiledContract) {
|
|
7577
|
-
const { abi, program } = compiledContract;
|
|
7578
|
-
const contractClass = { abi, program };
|
|
7579
|
-
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
7580
|
-
return addHexPrefix(esm_exports.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
7581
|
-
}
|
|
7582
|
-
function computeLegacyContractClassHash(contract) {
|
|
7583
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
7584
|
-
const apiVersion = toHex(API_VERSION);
|
|
7585
|
-
const externalEntryPointsHash = computeHashOnElements2(
|
|
7586
|
-
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
7587
|
-
);
|
|
7588
|
-
const l1HandlerEntryPointsHash = computeHashOnElements2(
|
|
7589
|
-
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
7590
|
-
);
|
|
7591
|
-
const constructorEntryPointHash = computeHashOnElements2(
|
|
7592
|
-
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
7593
|
-
);
|
|
7594
|
-
const builtinsHash = computeHashOnElements2(
|
|
7595
|
-
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
7596
|
-
);
|
|
7597
|
-
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
7598
|
-
const dataHash = computeHashOnElements2(compiledContract.program.data);
|
|
7599
|
-
return computeHashOnElements2([
|
|
7600
|
-
apiVersion,
|
|
7601
|
-
externalEntryPointsHash,
|
|
7602
|
-
l1HandlerEntryPointsHash,
|
|
7603
|
-
constructorEntryPointHash,
|
|
7604
|
-
builtinsHash,
|
|
7605
|
-
hintedClassHash,
|
|
7606
|
-
dataHash
|
|
7607
|
-
]);
|
|
7608
|
-
}
|
|
7609
|
-
function hashBuiltins(builtins) {
|
|
7610
|
-
return poseidonHashMany(
|
|
7611
|
-
builtins.flatMap((it) => {
|
|
7612
|
-
return BigInt(encodeShortString(it));
|
|
7613
|
-
})
|
|
7614
|
-
);
|
|
7615
|
-
}
|
|
7616
|
-
function hashEntryPoint(data) {
|
|
7617
|
-
const base = data.flatMap((it) => {
|
|
7618
|
-
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
7619
|
-
});
|
|
7620
|
-
return poseidonHashMany(base);
|
|
7621
|
-
}
|
|
7622
|
-
function computeCompiledClassHash(casm) {
|
|
7623
|
-
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
7624
|
-
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
7625
|
-
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
7626
|
-
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
7627
|
-
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
7628
|
-
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
7629
|
-
return toHex(
|
|
7630
|
-
poseidonHashMany([
|
|
7631
|
-
compiledClassVersion,
|
|
7632
|
-
externalEntryPointsHash,
|
|
7633
|
-
l1Handlers,
|
|
7634
|
-
constructor,
|
|
7635
|
-
bytecode
|
|
7636
|
-
])
|
|
7637
|
-
);
|
|
7638
|
-
}
|
|
7639
|
-
function hashEntryPointSierra(data) {
|
|
7640
|
-
const base = data.flatMap((it) => {
|
|
7641
|
-
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
7642
|
-
});
|
|
7643
|
-
return poseidonHashMany(base);
|
|
7644
|
-
}
|
|
7645
|
-
function hashAbi(sierra) {
|
|
7646
|
-
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
7647
|
-
return BigInt(addHexPrefix(esm_exports.keccak(utf8ToArray(indentString)).toString(16)));
|
|
7648
|
-
}
|
|
7649
|
-
function computeSierraContractClassHash(sierra) {
|
|
7650
|
-
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
7651
|
-
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
7652
|
-
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
7653
|
-
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
7654
|
-
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
7655
|
-
const abiHash = hashAbi(sierra);
|
|
7656
|
-
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
7657
|
-
return toHex(
|
|
7658
|
-
poseidonHashMany([
|
|
7659
|
-
compiledClassVersion,
|
|
7660
|
-
externalEntryPointsHash,
|
|
7661
|
-
l1Handlers,
|
|
7662
|
-
constructor,
|
|
7663
|
-
abiHash,
|
|
7664
|
-
sierraProgram
|
|
7665
|
-
])
|
|
7666
|
-
);
|
|
7667
|
-
}
|
|
7668
|
-
function computeContractClassHash(contract) {
|
|
7669
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
7670
|
-
if ("sierra_program" in compiledContract) {
|
|
7671
|
-
return computeSierraContractClassHash(compiledContract);
|
|
7672
|
-
}
|
|
7673
|
-
return computeLegacyContractClassHash(compiledContract);
|
|
7674
|
-
}
|
|
7675
|
-
|
|
7676
|
-
// src/utils/calldata/formatter.ts
|
|
7677
|
-
var guard = {
|
|
7678
|
-
isBN: (data, type, key) => {
|
|
7679
|
-
if (!isBigInt(data[key]))
|
|
7680
|
-
throw new Error(
|
|
7681
|
-
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
7682
|
-
);
|
|
7683
|
-
},
|
|
7684
|
-
unknown: (data, type, key) => {
|
|
7685
|
-
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
7686
|
-
}
|
|
7687
|
-
};
|
|
7688
|
-
function formatter(data, type, sameType) {
|
|
7689
|
-
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
7690
|
-
const elType = sameType ?? type[key];
|
|
7691
|
-
if (!(key in type) && !sameType) {
|
|
7692
|
-
acc[key] = value;
|
|
7693
|
-
return acc;
|
|
7694
|
-
}
|
|
7695
|
-
if (elType === "string") {
|
|
7696
|
-
if (Array.isArray(data[key])) {
|
|
7697
|
-
const arrayStr = formatter(
|
|
7698
|
-
data[key],
|
|
7699
|
-
data[key].map((_) => elType)
|
|
7700
|
-
);
|
|
7701
|
-
acc[key] = Object.values(arrayStr).join("");
|
|
7702
|
-
return acc;
|
|
7703
|
-
}
|
|
7704
|
-
guard.isBN(data, type, key);
|
|
7705
|
-
acc[key] = decodeShortString(value);
|
|
7706
|
-
return acc;
|
|
7707
|
-
}
|
|
7708
|
-
if (elType === "number") {
|
|
7709
|
-
guard.isBN(data, type, key);
|
|
7710
|
-
acc[key] = Number(value);
|
|
7711
|
-
return acc;
|
|
7712
|
-
}
|
|
7713
|
-
if (typeof elType === "function") {
|
|
7714
|
-
acc[key] = elType(value);
|
|
7715
|
-
return acc;
|
|
7716
|
-
}
|
|
7717
|
-
if (Array.isArray(elType)) {
|
|
7718
|
-
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
7719
|
-
acc[key] = Object.values(arrayObj);
|
|
7720
|
-
return acc;
|
|
7721
|
-
}
|
|
7722
|
-
if (typeof elType === "object") {
|
|
7723
|
-
acc[key] = formatter(data[key], elType);
|
|
7724
|
-
return acc;
|
|
7725
|
-
}
|
|
7726
|
-
guard.unknown(data, type, key);
|
|
7727
|
-
return acc;
|
|
7728
|
-
}, {});
|
|
7729
|
-
}
|
|
7730
|
-
|
|
7731
|
-
// src/utils/calldata/tuple.ts
|
|
7732
|
-
function parseNamedTuple(namedTuple) {
|
|
7733
|
-
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
7734
|
-
const type = namedTuple.substring(name.length + ":".length);
|
|
7735
|
-
return { name, type };
|
|
7736
|
-
}
|
|
7737
|
-
function parseSubTuple(s) {
|
|
7738
|
-
if (!s.includes("("))
|
|
7739
|
-
return { subTuple: [], result: s };
|
|
7740
|
-
const subTuple = [];
|
|
7741
|
-
let result = "";
|
|
7742
|
-
let i = 0;
|
|
7743
|
-
while (i < s.length) {
|
|
7744
|
-
if (s[i] === "(") {
|
|
7745
|
-
let counter = 1;
|
|
7746
|
-
const lBracket = i;
|
|
7747
|
-
i++;
|
|
7748
|
-
while (counter) {
|
|
7749
|
-
if (s[i] === ")")
|
|
7750
|
-
counter--;
|
|
7751
|
-
if (s[i] === "(")
|
|
7752
|
-
counter++;
|
|
7753
|
-
i++;
|
|
7754
|
-
}
|
|
7755
|
-
subTuple.push(s.substring(lBracket, i));
|
|
7756
|
-
result += " ";
|
|
7757
|
-
i--;
|
|
7758
|
-
} else {
|
|
7759
|
-
result += s[i];
|
|
7760
|
-
}
|
|
7761
|
-
i++;
|
|
7762
|
-
}
|
|
7763
|
-
return {
|
|
7764
|
-
subTuple,
|
|
7765
|
-
result
|
|
7766
|
-
};
|
|
7767
|
-
}
|
|
7768
|
-
function extractCairo0Tuple(type) {
|
|
7769
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
7770
|
-
const { subTuple, result } = parseSubTuple(cleanType);
|
|
7771
|
-
let recomposed = result.split(",").map((it) => {
|
|
7772
|
-
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
7773
|
-
});
|
|
7774
|
-
if (isTypeNamedTuple(type)) {
|
|
7775
|
-
recomposed = recomposed.reduce((acc, it) => {
|
|
7776
|
-
return acc.concat(parseNamedTuple(it));
|
|
7777
|
-
}, []);
|
|
7778
|
-
}
|
|
7779
|
-
return recomposed;
|
|
7780
|
-
}
|
|
7781
|
-
function extractCairo1Tuple(type) {
|
|
7782
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
7783
|
-
return cleanType.split(",");
|
|
7784
|
-
}
|
|
7785
|
-
function extractTupleMemberTypes(type) {
|
|
7786
|
-
if (isCairo1Type(type)) {
|
|
7787
|
-
return extractCairo1Tuple(type);
|
|
7788
|
-
}
|
|
7789
|
-
return extractCairo0Tuple(type);
|
|
7790
|
-
}
|
|
7791
|
-
|
|
7792
|
-
// src/utils/calldata/requestParser.ts
|
|
7793
|
-
function parseBaseTypes(type, val) {
|
|
7794
|
-
switch (true) {
|
|
7795
|
-
case isTypeUint256(type):
|
|
7796
|
-
const el_uint256 = uint256(val);
|
|
7797
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
7798
|
-
default:
|
|
7799
|
-
return felt(val);
|
|
7800
|
-
}
|
|
7801
|
-
}
|
|
7802
|
-
function parseTuple(element, typeStr) {
|
|
7803
|
-
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
7804
|
-
const elements = Object.values(element);
|
|
7805
|
-
if (elements.length !== memberTypes.length) {
|
|
7806
|
-
throw Error(
|
|
7807
|
-
`ParseTuple: provided and expected abi tuple size do not match.
|
|
7808
|
-
provided: ${elements}
|
|
7809
|
-
expected: ${memberTypes}`
|
|
7810
|
-
);
|
|
7811
|
-
}
|
|
7812
|
-
return memberTypes.map((it, dx) => {
|
|
7813
|
-
return {
|
|
7814
|
-
element: elements[dx],
|
|
7815
|
-
type: it.type ?? it
|
|
7816
|
-
};
|
|
7817
|
-
});
|
|
7818
|
-
}
|
|
7819
|
-
function parseCalldataValue(element, type, structs) {
|
|
7820
|
-
if (element === void 0) {
|
|
7821
|
-
throw Error(`Missing parameter for type ${type}`);
|
|
7822
|
-
}
|
|
7823
|
-
if (Array.isArray(element)) {
|
|
7824
|
-
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
7825
|
-
}
|
|
7826
|
-
if (structs[type] && structs[type].members.length) {
|
|
7827
|
-
const { members } = structs[type];
|
|
7828
|
-
const subElement = element;
|
|
7829
|
-
return members.reduce((acc, it) => {
|
|
7830
|
-
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
7831
|
-
}, []);
|
|
7832
|
-
}
|
|
7833
|
-
if (isTypeTuple(type)) {
|
|
7834
|
-
const tupled = parseTuple(element, type);
|
|
7835
|
-
return tupled.reduce((acc, it) => {
|
|
7836
|
-
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
7837
|
-
return acc.concat(parsedData);
|
|
7838
|
-
}, []);
|
|
7839
|
-
}
|
|
7840
|
-
if (typeof element === "object") {
|
|
7841
|
-
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
7842
|
-
}
|
|
7843
|
-
return parseBaseTypes(type, element);
|
|
7844
|
-
}
|
|
7845
|
-
function parseCalldataField(argsIterator, input, structs) {
|
|
7846
|
-
const { name, type } = input;
|
|
7847
|
-
let { value } = argsIterator.next();
|
|
7848
|
-
switch (true) {
|
|
7849
|
-
case isTypeArray(type):
|
|
7850
|
-
if (!Array.isArray(value) && !isText(value)) {
|
|
7851
|
-
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
7852
|
-
}
|
|
7853
|
-
if (typeof value === "string") {
|
|
7854
|
-
value = splitLongString(value);
|
|
7855
|
-
}
|
|
7856
|
-
const result = [];
|
|
7857
|
-
result.push(felt(value.length));
|
|
7858
|
-
const arrayType = getArrayType(input.type);
|
|
7859
|
-
return value.reduce((acc, el) => {
|
|
7860
|
-
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
7861
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
7862
|
-
} else {
|
|
7863
|
-
return acc.concat(parseBaseTypes(arrayType, el));
|
|
7864
|
-
}
|
|
7865
|
-
return acc;
|
|
7866
|
-
}, result);
|
|
7867
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
7868
|
-
return parseCalldataValue(value, type, structs);
|
|
7869
|
-
case isTypeUint256(type):
|
|
7870
|
-
if (typeof value === "object") {
|
|
7871
|
-
return [felt(value.low), felt(value.high)];
|
|
7872
|
-
}
|
|
7873
|
-
const el_uint256 = uint256(value);
|
|
7874
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
7875
|
-
default:
|
|
7876
|
-
return parseBaseTypes(type, value);
|
|
7877
|
-
}
|
|
7878
|
-
}
|
|
7879
|
-
|
|
7880
|
-
// src/utils/calldata/responseParser.ts
|
|
7881
|
-
function parseBaseTypes2(type, it) {
|
|
7882
|
-
let temp;
|
|
7883
|
-
switch (true) {
|
|
7884
|
-
case isTypeBool(type):
|
|
7885
|
-
temp = it.next().value;
|
|
7886
|
-
return Boolean(BigInt(temp));
|
|
7887
|
-
case isTypeUint256(type):
|
|
7888
|
-
const low = it.next().value;
|
|
7889
|
-
const high = it.next().value;
|
|
7890
|
-
return uint256ToBN({ low, high });
|
|
7891
|
-
default:
|
|
7892
|
-
temp = it.next().value;
|
|
7893
|
-
return BigInt(temp);
|
|
7894
|
-
}
|
|
7895
|
-
}
|
|
7896
|
-
function parseResponseStruct(responseIterator, type, structs) {
|
|
7897
|
-
if (type in structs && structs[type]) {
|
|
7898
|
-
return structs[type].members.reduce((acc, el) => {
|
|
7899
|
-
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
7900
|
-
return acc;
|
|
7901
|
-
}, {});
|
|
7902
|
-
}
|
|
7903
|
-
if (isTypeTuple(type)) {
|
|
7904
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
7905
|
-
return memberTypes.reduce((acc, it, idx) => {
|
|
7906
|
-
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
7907
|
-
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
7908
|
-
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
7909
|
-
return acc;
|
|
7910
|
-
}, {});
|
|
7911
|
-
}
|
|
7912
|
-
return parseBaseTypes2(type, responseIterator);
|
|
7913
|
-
}
|
|
7914
|
-
function responseParser(responseIterator, output2, structs, parsedResult) {
|
|
7915
|
-
const { name, type } = output2;
|
|
7916
|
-
let temp;
|
|
7917
|
-
switch (true) {
|
|
7918
|
-
case isLen(name):
|
|
7919
|
-
temp = responseIterator.next().value;
|
|
7920
|
-
return BigInt(temp);
|
|
7921
|
-
case isTypeArray(type):
|
|
7922
|
-
const parsedDataArr = [];
|
|
7923
|
-
if (isCairo1Type(type)) {
|
|
7924
|
-
const arrayType = getArrayType(type);
|
|
7925
|
-
const len = BigInt(responseIterator.next().value);
|
|
7926
|
-
while (parsedDataArr.length < len) {
|
|
7927
|
-
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
7928
|
-
}
|
|
7929
|
-
return parsedDataArr;
|
|
7930
|
-
}
|
|
7931
|
-
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
7932
|
-
const arrLen = parsedResult[`${name}_len`];
|
|
7933
|
-
while (parsedDataArr.length < arrLen) {
|
|
7934
|
-
parsedDataArr.push(
|
|
7935
|
-
parseResponseStruct(responseIterator, output2.type.replace("*", ""), structs)
|
|
7936
|
-
);
|
|
7937
|
-
}
|
|
7938
|
-
}
|
|
7939
|
-
return parsedDataArr;
|
|
7940
|
-
case (type in structs || isTypeTuple(type)):
|
|
7941
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
7942
|
-
default:
|
|
7943
|
-
return parseBaseTypes2(type, responseIterator);
|
|
7944
|
-
}
|
|
7945
|
-
}
|
|
7946
|
-
|
|
7947
|
-
// src/utils/calldata/validate.ts
|
|
7948
|
-
var validateFelt = (parameter, input) => {
|
|
7949
|
-
assert(
|
|
7950
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
7951
|
-
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
7952
|
-
);
|
|
7953
|
-
};
|
|
7954
|
-
var validateUint = (parameter, input) => {
|
|
7955
|
-
if (typeof parameter === "number") {
|
|
7956
|
-
assert(
|
|
7957
|
-
parameter <= Number.MAX_SAFE_INTEGER,
|
|
7958
|
-
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
7959
|
-
);
|
|
7960
|
-
}
|
|
7961
|
-
assert(
|
|
7962
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
|
|
7963
|
-
`Validate: arg ${input.name} of cairo ZORG type ${input.type} should be type (String, Number or BigInt)`
|
|
7964
|
-
);
|
|
7965
|
-
const param = typeof parameter === "object" ? uint256ToBN(parameter) : toBigInt(parameter);
|
|
7966
|
-
switch (input.type) {
|
|
7967
|
-
case "core::integer::u8" /* u8 */:
|
|
7968
|
-
assert(
|
|
7969
|
-
param >= 0n && param <= 255n,
|
|
7970
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
7971
|
-
);
|
|
7972
|
-
break;
|
|
7973
|
-
case "core::integer::u16" /* u16 */:
|
|
7974
|
-
assert(
|
|
7975
|
-
param >= 0n && param <= 65535n,
|
|
7976
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
7977
|
-
);
|
|
7978
|
-
break;
|
|
7979
|
-
case "core::integer::u32" /* u32 */:
|
|
7980
|
-
assert(
|
|
7981
|
-
param >= 0n && param <= 4294967295n,
|
|
7982
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
7983
|
-
);
|
|
7984
|
-
break;
|
|
7985
|
-
case "core::integer::u64" /* u64 */:
|
|
7986
|
-
assert(
|
|
7987
|
-
param >= 0n && param <= 2n ** 64n - 1n,
|
|
7988
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
7989
|
-
);
|
|
7990
|
-
break;
|
|
7991
|
-
case "core::integer::u128" /* u128 */:
|
|
7992
|
-
assert(
|
|
7993
|
-
param >= 0n && param <= 2n ** 128n - 1n,
|
|
7994
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
7995
|
-
);
|
|
7996
|
-
break;
|
|
7997
|
-
case "core::integer::u256" /* u256 */:
|
|
7998
|
-
assert(
|
|
7999
|
-
param >= 0n && param <= 2n ** 256n - 1n,
|
|
8000
|
-
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
8001
|
-
);
|
|
8002
|
-
break;
|
|
8003
|
-
default:
|
|
8004
|
-
break;
|
|
8005
|
-
}
|
|
8006
|
-
};
|
|
8007
|
-
var validateBool = (parameter, input) => {
|
|
8008
|
-
assert(
|
|
8009
|
-
typeof parameter === "boolean",
|
|
8010
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
8011
|
-
);
|
|
8012
|
-
};
|
|
8013
|
-
var validateStruct = (parameter, input, structs) => {
|
|
8014
|
-
assert(
|
|
8015
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
8016
|
-
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
8017
|
-
);
|
|
8018
|
-
structs[input.type].members.forEach(({ name }) => {
|
|
8019
|
-
assert(
|
|
8020
|
-
Object.keys(parameter).includes(name),
|
|
8021
|
-
`Validate: arg ${input.name} should have a property ${name}`
|
|
8022
|
-
);
|
|
8023
|
-
});
|
|
8024
|
-
};
|
|
8025
|
-
var validateTuple = (parameter, input) => {
|
|
8026
|
-
assert(
|
|
8027
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
8028
|
-
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
8029
|
-
);
|
|
8030
|
-
};
|
|
8031
|
-
var validateArray = (parameter, input, structs) => {
|
|
8032
|
-
const baseType = getArrayType(input.type);
|
|
8033
|
-
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
8034
|
-
return;
|
|
8035
|
-
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
8036
|
-
switch (true) {
|
|
8037
|
-
case isTypeFelt(baseType):
|
|
8038
|
-
parameter.forEach((param) => validateFelt(param, input));
|
|
8039
|
-
break;
|
|
8040
|
-
case isTypeTuple(baseType):
|
|
8041
|
-
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
8042
|
-
break;
|
|
8043
|
-
case isTypeStruct(baseType, structs):
|
|
8044
|
-
parameter.forEach(
|
|
8045
|
-
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
8046
|
-
);
|
|
8047
|
-
break;
|
|
8048
|
-
case isTypeUint(baseType):
|
|
8049
|
-
parameter.forEach((param) => validateUint(param, input));
|
|
8050
|
-
break;
|
|
8051
|
-
case isTypeBool(baseType):
|
|
8052
|
-
parameter.forEach((param) => validateBool(param, input));
|
|
8053
|
-
break;
|
|
8054
|
-
default:
|
|
8055
|
-
throw new Error(
|
|
8056
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
8057
|
-
);
|
|
8058
|
-
}
|
|
8059
|
-
};
|
|
8060
|
-
function validateFields(abiMethod, args, structs) {
|
|
8061
|
-
abiMethod.inputs.reduce((acc, input) => {
|
|
8062
|
-
const parameter = args[acc];
|
|
8063
|
-
switch (true) {
|
|
8064
|
-
case isLen(input.name):
|
|
8065
|
-
return acc;
|
|
8066
|
-
case isTypeFelt(input.type):
|
|
8067
|
-
validateFelt(parameter, input);
|
|
8068
|
-
break;
|
|
8069
|
-
case isTypeUint(input.type):
|
|
8070
|
-
validateUint(parameter, input);
|
|
8071
|
-
break;
|
|
8072
|
-
case isTypeBool(input.type):
|
|
8073
|
-
validateBool(parameter, input);
|
|
8074
|
-
break;
|
|
8075
|
-
case isTypeContractAddress(input.type):
|
|
8076
|
-
break;
|
|
8077
|
-
case isTypeStruct(input.type, structs):
|
|
8078
|
-
validateStruct(parameter, input, structs);
|
|
8079
|
-
break;
|
|
8080
|
-
case isTypeTuple(input.type):
|
|
8081
|
-
validateTuple(parameter, input);
|
|
8082
|
-
break;
|
|
8083
|
-
case isTypeArray(input.type):
|
|
8084
|
-
validateArray(parameter, input, structs);
|
|
8085
|
-
break;
|
|
8086
|
-
default:
|
|
8087
|
-
throw new Error(
|
|
8088
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
8089
|
-
);
|
|
8090
|
-
}
|
|
8091
|
-
return acc + 1;
|
|
8092
|
-
}, 0);
|
|
8078
|
+
maxFee,
|
|
8079
|
+
chainId,
|
|
8080
|
+
[nonce]
|
|
8081
|
+
);
|
|
8093
8082
|
}
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
assert(
|
|
8110
|
-
invocableFunctionNames.includes(method),
|
|
8111
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
8112
|
-
);
|
|
8113
|
-
}
|
|
8114
|
-
const abiMethod = this.abi.find(
|
|
8115
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
8116
|
-
);
|
|
8117
|
-
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
8118
|
-
if (args.length !== inputsLength) {
|
|
8119
|
-
throw Error(
|
|
8120
|
-
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
8121
|
-
);
|
|
8122
|
-
}
|
|
8123
|
-
validateFields(abiMethod, args, this.structs);
|
|
8083
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
8084
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
8085
|
+
const constructorCalldataHash = computeHashOnElements2(compiledCalldata);
|
|
8086
|
+
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
8087
|
+
return computeHashOnElements2([
|
|
8088
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
8089
|
+
deployerAddress,
|
|
8090
|
+
salt,
|
|
8091
|
+
classHash,
|
|
8092
|
+
constructorCalldataHash
|
|
8093
|
+
]);
|
|
8094
|
+
}
|
|
8095
|
+
function nullSkipReplacer(key, value) {
|
|
8096
|
+
if (key === "attributes" || key === "accessible_scopes") {
|
|
8097
|
+
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
8124
8098
|
}
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
8128
|
-
return inputs.reduce(
|
|
8129
|
-
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
8130
|
-
[]
|
|
8131
|
-
);
|
|
8099
|
+
if (key === "debug_info") {
|
|
8100
|
+
return null;
|
|
8132
8101
|
}
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
if (isBigInt(value))
|
|
8145
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
8146
|
-
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
8147
|
-
});
|
|
8148
|
-
};
|
|
8149
|
-
return Object.fromEntries(getEntries(obj));
|
|
8150
|
-
};
|
|
8151
|
-
let callTreeArray;
|
|
8152
|
-
if (!Array.isArray(rawArgs)) {
|
|
8153
|
-
const callTree = createTree(rawArgs);
|
|
8154
|
-
callTreeArray = Object.values(callTree);
|
|
8102
|
+
return value === null ? void 0 : value;
|
|
8103
|
+
}
|
|
8104
|
+
function formatSpaces(json) {
|
|
8105
|
+
let insideQuotes = false;
|
|
8106
|
+
let newString = "";
|
|
8107
|
+
for (const char of json) {
|
|
8108
|
+
if (char === '"' && newString.endsWith("\\") === false) {
|
|
8109
|
+
insideQuotes = !insideQuotes;
|
|
8110
|
+
}
|
|
8111
|
+
if (insideQuotes) {
|
|
8112
|
+
newString += char;
|
|
8155
8113
|
} else {
|
|
8156
|
-
|
|
8157
|
-
const callTree = createTree(callObj);
|
|
8158
|
-
callTreeArray = Object.values(callTree);
|
|
8114
|
+
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
8159
8115
|
}
|
|
8160
|
-
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
8161
|
-
enumerable: false,
|
|
8162
|
-
writable: false,
|
|
8163
|
-
value: true
|
|
8164
|
-
});
|
|
8165
|
-
return callTreeArray;
|
|
8166
|
-
}
|
|
8167
|
-
parse(method, response) {
|
|
8168
|
-
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
8169
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
8170
|
-
const parsed = outputs.flat().reduce((acc, output2, idx) => {
|
|
8171
|
-
const propName = output2.name ?? idx;
|
|
8172
|
-
acc[propName] = responseParser(responseIterator, output2, this.structs, acc);
|
|
8173
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
8174
|
-
delete acc[`${propName}_len`];
|
|
8175
|
-
}
|
|
8176
|
-
return acc;
|
|
8177
|
-
}, {});
|
|
8178
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
8179
|
-
}
|
|
8180
|
-
format(method, response, format) {
|
|
8181
|
-
const parsed = this.parse(method, response);
|
|
8182
|
-
return formatter(parsed, format);
|
|
8183
|
-
}
|
|
8184
|
-
static abiInputsLength(inputs) {
|
|
8185
|
-
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
8186
|
-
}
|
|
8187
|
-
static getAbiStruct(abi) {
|
|
8188
|
-
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
8189
|
-
(acc, abiEntry) => ({
|
|
8190
|
-
...acc,
|
|
8191
|
-
[abiEntry.name]: abiEntry
|
|
8192
|
-
}),
|
|
8193
|
-
{}
|
|
8194
|
-
);
|
|
8195
8116
|
}
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8117
|
+
return newString;
|
|
8118
|
+
}
|
|
8119
|
+
function computeHintedClassHash(compiledContract) {
|
|
8120
|
+
const { abi, program } = compiledContract;
|
|
8121
|
+
const contractClass = { abi, program };
|
|
8122
|
+
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
8123
|
+
return addHexPrefix(esm_exports.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
8124
|
+
}
|
|
8125
|
+
function computeLegacyContractClassHash(contract) {
|
|
8126
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
8127
|
+
const apiVersion = toHex(API_VERSION);
|
|
8128
|
+
const externalEntryPointsHash = computeHashOnElements2(
|
|
8129
|
+
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
8130
|
+
);
|
|
8131
|
+
const l1HandlerEntryPointsHash = computeHashOnElements2(
|
|
8132
|
+
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
8133
|
+
);
|
|
8134
|
+
const constructorEntryPointHash = computeHashOnElements2(
|
|
8135
|
+
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
8136
|
+
);
|
|
8137
|
+
const builtinsHash = computeHashOnElements2(
|
|
8138
|
+
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
8139
|
+
);
|
|
8140
|
+
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
8141
|
+
const dataHash = computeHashOnElements2(compiledContract.program.data);
|
|
8142
|
+
return computeHashOnElements2([
|
|
8143
|
+
apiVersion,
|
|
8144
|
+
externalEntryPointsHash,
|
|
8145
|
+
l1HandlerEntryPointsHash,
|
|
8146
|
+
constructorEntryPointHash,
|
|
8147
|
+
builtinsHash,
|
|
8148
|
+
hintedClassHash,
|
|
8149
|
+
dataHash
|
|
8150
|
+
]);
|
|
8151
|
+
}
|
|
8152
|
+
function hashBuiltins(builtins) {
|
|
8153
|
+
return poseidonHashMany(
|
|
8154
|
+
builtins.flatMap((it) => {
|
|
8155
|
+
return BigInt(encodeShortString(it));
|
|
8156
|
+
})
|
|
8157
|
+
);
|
|
8158
|
+
}
|
|
8159
|
+
function hashEntryPoint(data) {
|
|
8160
|
+
const base = data.flatMap((it) => {
|
|
8161
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
8162
|
+
});
|
|
8163
|
+
return poseidonHashMany(base);
|
|
8164
|
+
}
|
|
8165
|
+
function computeCompiledClassHash(casm) {
|
|
8166
|
+
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
8167
|
+
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
8168
|
+
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
8169
|
+
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
8170
|
+
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
8171
|
+
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
8172
|
+
return toHex(
|
|
8173
|
+
poseidonHashMany([
|
|
8174
|
+
compiledClassVersion,
|
|
8175
|
+
externalEntryPointsHash,
|
|
8176
|
+
l1Handlers,
|
|
8177
|
+
constructor,
|
|
8178
|
+
bytecode
|
|
8179
|
+
])
|
|
8180
|
+
);
|
|
8181
|
+
}
|
|
8182
|
+
function hashEntryPointSierra(data) {
|
|
8183
|
+
const base = data.flatMap((it) => {
|
|
8184
|
+
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
8185
|
+
});
|
|
8186
|
+
return poseidonHashMany(base);
|
|
8187
|
+
}
|
|
8188
|
+
function hashAbi(sierra) {
|
|
8189
|
+
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
8190
|
+
return BigInt(addHexPrefix(esm_exports.keccak(utf8ToArray(indentString)).toString(16)));
|
|
8191
|
+
}
|
|
8192
|
+
function computeSierraContractClassHash(sierra) {
|
|
8193
|
+
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
8194
|
+
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
8195
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
8196
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
8197
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
8198
|
+
const abiHash = hashAbi(sierra);
|
|
8199
|
+
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
8200
|
+
return toHex(
|
|
8201
|
+
poseidonHashMany([
|
|
8202
|
+
compiledClassVersion,
|
|
8203
|
+
externalEntryPointsHash,
|
|
8204
|
+
l1Handlers,
|
|
8205
|
+
constructor,
|
|
8206
|
+
abiHash,
|
|
8207
|
+
sierraProgram
|
|
8208
|
+
])
|
|
8209
|
+
);
|
|
8210
|
+
}
|
|
8211
|
+
function computeContractClassHash(contract) {
|
|
8212
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
8213
|
+
if ("sierra_program" in compiledContract) {
|
|
8214
|
+
return computeSierraContractClassHash(compiledContract);
|
|
8202
8215
|
}
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
// src/utils/fetchPonyfill.ts
|
|
8206
|
-
var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
|
|
8207
|
-
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
8216
|
+
return computeLegacyContractClassHash(compiledContract);
|
|
8217
|
+
}
|
|
8208
8218
|
|
|
8209
8219
|
// src/utils/contract.ts
|
|
8210
8220
|
function isSierra(contract) {
|
|
@@ -12817,7 +12827,7 @@ var starknet = (() => {
|
|
|
12817
12827
|
return this.fetchEndpoint("starknet_estimateFee", {
|
|
12818
12828
|
request: {
|
|
12819
12829
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
12820
|
-
constructor_calldata:
|
|
12830
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
12821
12831
|
class_hash: toHex(classHash),
|
|
12822
12832
|
contract_address_salt: toHex(addressSalt || 0),
|
|
12823
12833
|
signature: signatureToHexArray(signature),
|
|
@@ -12854,7 +12864,7 @@ var starknet = (() => {
|
|
|
12854
12864
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
12855
12865
|
return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
12856
12866
|
deploy_account_transaction: {
|
|
12857
|
-
constructor_calldata:
|
|
12867
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
12858
12868
|
class_hash: toHex(classHash),
|
|
12859
12869
|
contract_address_salt: toHex(addressSalt || 0),
|
|
12860
12870
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
@@ -13292,7 +13302,7 @@ var starknet = (() => {
|
|
|
13292
13302
|
{
|
|
13293
13303
|
contract_address: contractAddress,
|
|
13294
13304
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
13295
|
-
calldata
|
|
13305
|
+
calldata: CallData.compile(calldata)
|
|
13296
13306
|
}
|
|
13297
13307
|
).then(this.responseParser.parseCallContractResponse);
|
|
13298
13308
|
}
|
|
@@ -13406,7 +13416,7 @@ var starknet = (() => {
|
|
|
13406
13416
|
{
|
|
13407
13417
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
13408
13418
|
sender_address: invocation.contractAddress,
|
|
13409
|
-
calldata: invocation.calldata ?? [],
|
|
13419
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13410
13420
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13411
13421
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
13412
13422
|
nonce: toHex(invocationDetails.nonce)
|
|
@@ -13464,7 +13474,7 @@ var starknet = (() => {
|
|
|
13464
13474
|
res = {
|
|
13465
13475
|
type: invocation.type,
|
|
13466
13476
|
sender_address: invocation.contractAddress,
|
|
13467
|
-
calldata: invocation.calldata ?? []
|
|
13477
|
+
calldata: CallData.compile(invocation.calldata ?? [])
|
|
13468
13478
|
};
|
|
13469
13479
|
} else if (invocation.type === "DECLARE") {
|
|
13470
13480
|
res = {
|
|
@@ -13547,7 +13557,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13547
13557
|
{
|
|
13548
13558
|
type: "INVOKE_FUNCTION",
|
|
13549
13559
|
sender_address: invocation.contractAddress,
|
|
13550
|
-
calldata: invocation.calldata ?? [],
|
|
13560
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13551
13561
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13552
13562
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
13553
13563
|
nonce: toHex(invocationDetails.nonce),
|
|
@@ -13960,7 +13970,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13960
13970
|
const callArray = [];
|
|
13961
13971
|
const calldata = [];
|
|
13962
13972
|
calls.forEach((call) => {
|
|
13963
|
-
const data = call.calldata || [];
|
|
13973
|
+
const data = CallData.compile(call.calldata || []);
|
|
13964
13974
|
callArray.push({
|
|
13965
13975
|
to: toBigInt(call.contractAddress).toString(10),
|
|
13966
13976
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
@@ -13991,11 +14001,16 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13991
14001
|
return callArray;
|
|
13992
14002
|
};
|
|
13993
14003
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
13994
|
-
|
|
14004
|
+
const orderCalls = calls.map((call) => ({
|
|
14005
|
+
contractAddress: call.contractAddress,
|
|
14006
|
+
entrypoint: call.entrypoint,
|
|
14007
|
+
calldata: call.calldata
|
|
14008
|
+
}));
|
|
14009
|
+
return CallData.compile({ orderCalls });
|
|
13995
14010
|
};
|
|
13996
14011
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
13997
14012
|
if (cairoVersion === "1") {
|
|
13998
|
-
return
|
|
14013
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
13999
14014
|
}
|
|
14000
14015
|
return fromCallsToExecuteCalldata(calls);
|
|
14001
14016
|
};
|
|
@@ -14249,7 +14264,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14249
14264
|
const msgHash = calculateDeployAccountTransactionHash(
|
|
14250
14265
|
contractAddress,
|
|
14251
14266
|
classHash,
|
|
14252
|
-
constructorCalldata,
|
|
14267
|
+
CallData.compile(constructorCalldata),
|
|
14253
14268
|
addressSalt,
|
|
14254
14269
|
version,
|
|
14255
14270
|
maxFee,
|
|
@@ -14305,10 +14320,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14305
14320
|
|
|
14306
14321
|
// src/account/default.ts
|
|
14307
14322
|
var Account = class extends Provider {
|
|
14308
|
-
constructor(providerOrOptions, address, pkOrSigner) {
|
|
14323
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion = "0") {
|
|
14309
14324
|
super(providerOrOptions);
|
|
14325
|
+
this.deploySelf = this.deployAccount;
|
|
14310
14326
|
this.address = address.toLowerCase();
|
|
14311
14327
|
this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
14328
|
+
this.cairoVersion = cairoVersion;
|
|
14312
14329
|
}
|
|
14313
14330
|
async getNonce(blockIdentifier) {
|
|
14314
14331
|
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
@@ -14316,7 +14333,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14316
14333
|
async estimateFee(calls, estimateFeeDetails) {
|
|
14317
14334
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
14318
14335
|
}
|
|
14319
|
-
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
14336
|
+
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
14320
14337
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
14321
14338
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14322
14339
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -14327,7 +14344,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14327
14344
|
maxFee: ZERO,
|
|
14328
14345
|
version,
|
|
14329
14346
|
chainId,
|
|
14330
|
-
cairoVersion: cairoVersion
|
|
14347
|
+
cairoVersion: this.cairoVersion
|
|
14331
14348
|
};
|
|
14332
14349
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
14333
14350
|
const response = await super.getInvokeEstimateFee(
|
|
@@ -14342,7 +14359,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14342
14359
|
suggestedMaxFee
|
|
14343
14360
|
};
|
|
14344
14361
|
}
|
|
14345
|
-
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate
|
|
14362
|
+
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate } = {}) {
|
|
14346
14363
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14347
14364
|
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
|
|
14348
14365
|
const chainId = await this.getChainId();
|
|
@@ -14354,7 +14371,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14354
14371
|
version,
|
|
14355
14372
|
walletAddress: this.address,
|
|
14356
14373
|
maxFee: ZERO,
|
|
14357
|
-
cairoVersion: cairoVersion
|
|
14374
|
+
cairoVersion: this.cairoVersion
|
|
14358
14375
|
}
|
|
14359
14376
|
);
|
|
14360
14377
|
const response = await super.getDeclareEstimateFee(
|
|
@@ -14374,7 +14391,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14374
14391
|
addressSalt = 0,
|
|
14375
14392
|
constructorCalldata = [],
|
|
14376
14393
|
contractAddress: providedContractAddress
|
|
14377
|
-
}, { blockIdentifier, skipValidate
|
|
14394
|
+
}, { blockIdentifier, skipValidate } = {}) {
|
|
14378
14395
|
const version = toBigInt(feeTransactionVersion);
|
|
14379
14396
|
const nonce = ZERO;
|
|
14380
14397
|
const chainId = await this.getChainId();
|
|
@@ -14386,7 +14403,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14386
14403
|
version,
|
|
14387
14404
|
walletAddress: this.address,
|
|
14388
14405
|
maxFee: ZERO,
|
|
14389
|
-
cairoVersion: cairoVersion
|
|
14406
|
+
cairoVersion: this.cairoVersion
|
|
14390
14407
|
}
|
|
14391
14408
|
);
|
|
14392
14409
|
const response = await super.getDeployAccountEstimateFee(
|
|
@@ -14405,7 +14422,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14405
14422
|
const calls = this.buildUDCContractPayload(payload);
|
|
14406
14423
|
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
14407
14424
|
}
|
|
14408
|
-
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier
|
|
14425
|
+
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
14409
14426
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14410
14427
|
const version = toBigInt(feeTransactionVersion);
|
|
14411
14428
|
const chainId = await this.getChainId();
|
|
@@ -14417,7 +14434,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14417
14434
|
maxFee: ZERO,
|
|
14418
14435
|
version,
|
|
14419
14436
|
chainId,
|
|
14420
|
-
cairoVersion: cairoVersion
|
|
14437
|
+
cairoVersion: this.cairoVersion
|
|
14421
14438
|
};
|
|
14422
14439
|
const txPayload = transaction.payload;
|
|
14423
14440
|
let res;
|
|
@@ -14475,7 +14492,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14475
14492
|
});
|
|
14476
14493
|
}
|
|
14477
14494
|
async buildInvocation(call, signerDetails) {
|
|
14478
|
-
const calldata = getExecuteCalldata(call,
|
|
14495
|
+
const calldata = getExecuteCalldata(call, this.cairoVersion);
|
|
14479
14496
|
const signature = await this.signer.signTransaction(call, signerDetails);
|
|
14480
14497
|
return {
|
|
14481
14498
|
contractAddress: this.address,
|
|
@@ -14492,17 +14509,16 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14492
14509
|
);
|
|
14493
14510
|
const version = toBigInt(transactionVersion);
|
|
14494
14511
|
const chainId = await this.getChainId();
|
|
14495
|
-
const cairoVersion = transactionsDetail.cairoVersion ?? "0";
|
|
14496
14512
|
const signerDetails = {
|
|
14497
14513
|
walletAddress: this.address,
|
|
14498
14514
|
nonce,
|
|
14499
14515
|
maxFee,
|
|
14500
14516
|
version,
|
|
14501
14517
|
chainId,
|
|
14502
|
-
cairoVersion
|
|
14518
|
+
cairoVersion: this.cairoVersion
|
|
14503
14519
|
};
|
|
14504
14520
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
14505
|
-
const calldata = getExecuteCalldata(transactions, cairoVersion);
|
|
14521
|
+
const calldata = getExecuteCalldata(transactions, this.cairoVersion);
|
|
14506
14522
|
return this.invokeFunction(
|
|
14507
14523
|
{ contractAddress: this.address, calldata, signature },
|
|
14508
14524
|
{
|
|
@@ -14512,6 +14528,18 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14512
14528
|
}
|
|
14513
14529
|
);
|
|
14514
14530
|
}
|
|
14531
|
+
async declareIfNot(payload, transactionsDetail = {}) {
|
|
14532
|
+
const declareContractPayload = extractContractHashes(payload);
|
|
14533
|
+
try {
|
|
14534
|
+
await this.getClassByHash(declareContractPayload.classHash);
|
|
14535
|
+
} catch (error) {
|
|
14536
|
+
return this.declare(payload, transactionsDetail);
|
|
14537
|
+
}
|
|
14538
|
+
return {
|
|
14539
|
+
transaction_hash: "",
|
|
14540
|
+
class_hash: declareContractPayload.classHash
|
|
14541
|
+
};
|
|
14542
|
+
}
|
|
14515
14543
|
async declare(payload, transactionsDetail = {}) {
|
|
14516
14544
|
const declareContractPayload = extractContractHashes(payload);
|
|
14517
14545
|
const details = {};
|
|
@@ -14528,7 +14556,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14528
14556
|
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
|
|
14529
14557
|
...details,
|
|
14530
14558
|
walletAddress: this.address,
|
|
14531
|
-
cairoVersion:
|
|
14559
|
+
cairoVersion: this.cairoVersion
|
|
14532
14560
|
});
|
|
14533
14561
|
return this.declareContract(declareContractTransaction, details);
|
|
14534
14562
|
}
|
|
@@ -14564,10 +14592,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14564
14592
|
});
|
|
14565
14593
|
const calls = params.map((it) => it.call);
|
|
14566
14594
|
const addresses = params.map((it) => it.address);
|
|
14567
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
14568
|
-
...details,
|
|
14569
|
-
cairoVersion: "0"
|
|
14570
|
-
});
|
|
14595
|
+
const invokeResponse = await this.execute(calls, void 0, details);
|
|
14571
14596
|
return {
|
|
14572
14597
|
...invokeResponse,
|
|
14573
14598
|
contract_address: addresses
|
|
@@ -14582,15 +14607,18 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14582
14607
|
}
|
|
14583
14608
|
async declareAndDeploy(payload, details) {
|
|
14584
14609
|
const { constructorCalldata, salt, unique } = payload;
|
|
14585
|
-
|
|
14586
|
-
|
|
14587
|
-
|
|
14588
|
-
|
|
14610
|
+
let declare = await this.declareIfNot(payload, details);
|
|
14611
|
+
if (declare.transaction_hash !== "") {
|
|
14612
|
+
const tx = await this.waitForTransaction(declare.transaction_hash, {
|
|
14613
|
+
successStates: ["ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */]
|
|
14614
|
+
});
|
|
14615
|
+
declare = { ...declare, ...tx };
|
|
14616
|
+
}
|
|
14589
14617
|
const deploy = await this.deployContract(
|
|
14590
|
-
{ classHash: class_hash, salt, unique, constructorCalldata },
|
|
14618
|
+
{ classHash: declare.class_hash, salt, unique, constructorCalldata },
|
|
14591
14619
|
details
|
|
14592
14620
|
);
|
|
14593
|
-
return { declare: { ...declare
|
|
14621
|
+
return { declare: { ...declare }, deploy };
|
|
14594
14622
|
}
|
|
14595
14623
|
async deployAccount({
|
|
14596
14624
|
classHash,
|
|
@@ -14606,13 +14634,18 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14606
14634
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
14607
14635
|
{
|
|
14608
14636
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
14609
|
-
payload: {
|
|
14637
|
+
payload: {
|
|
14638
|
+
classHash,
|
|
14639
|
+
constructorCalldata: compiledCalldata,
|
|
14640
|
+
addressSalt,
|
|
14641
|
+
contractAddress
|
|
14642
|
+
}
|
|
14610
14643
|
},
|
|
14611
14644
|
transactionsDetail
|
|
14612
14645
|
);
|
|
14613
14646
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
14614
14647
|
classHash,
|
|
14615
|
-
constructorCalldata,
|
|
14648
|
+
constructorCalldata: compiledCalldata,
|
|
14616
14649
|
contractAddress,
|
|
14617
14650
|
addressSalt,
|
|
14618
14651
|
chainId,
|
|
@@ -14710,12 +14743,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14710
14743
|
version,
|
|
14711
14744
|
nonce,
|
|
14712
14745
|
addressSalt,
|
|
14713
|
-
constructorCalldata
|
|
14746
|
+
constructorCalldata: compiledCalldata
|
|
14714
14747
|
});
|
|
14715
14748
|
return {
|
|
14716
14749
|
classHash,
|
|
14717
14750
|
addressSalt,
|
|
14718
|
-
constructorCalldata,
|
|
14751
|
+
constructorCalldata: compiledCalldata,
|
|
14719
14752
|
signature
|
|
14720
14753
|
};
|
|
14721
14754
|
}
|
|
@@ -14742,7 +14775,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14742
14775
|
});
|
|
14743
14776
|
return calls;
|
|
14744
14777
|
}
|
|
14745
|
-
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
14778
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
14746
14779
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
14747
14780
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14748
14781
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -14753,7 +14786,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14753
14786
|
maxFee: ZERO,
|
|
14754
14787
|
version,
|
|
14755
14788
|
chainId,
|
|
14756
|
-
cairoVersion: cairoVersion
|
|
14789
|
+
cairoVersion: this.cairoVersion
|
|
14757
14790
|
};
|
|
14758
14791
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
14759
14792
|
const response = await super.getSimulateTransaction(
|
|
@@ -14795,7 +14828,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14795
14828
|
function getChecksumAddress(address) {
|
|
14796
14829
|
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
14797
14830
|
const hex = removeHexPrefix(keccakBn(address));
|
|
14798
|
-
const hashed =
|
|
14831
|
+
const hashed = hexToBytes(hex.padStart(64, "0"));
|
|
14799
14832
|
for (let i = 0; i < chars.length; i += 2) {
|
|
14800
14833
|
if (hashed[i >> 1] >> 4 >= 8) {
|
|
14801
14834
|
chars[i] = chars[i].toUpperCase();
|