starknet 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +4 -1
- package/dist/index.d.ts +1879 -3593
- package/dist/index.global.js +4165 -1843
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +544 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +529 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -39,6 +39,8 @@ __export(src_exports, {
|
|
|
39
39
|
CairoOptionVariant: () => CairoOptionVariant,
|
|
40
40
|
CairoResult: () => CairoResult,
|
|
41
41
|
CairoResultVariant: () => CairoResultVariant,
|
|
42
|
+
CairoUint256: () => CairoUint256,
|
|
43
|
+
CairoUint512: () => CairoUint512,
|
|
42
44
|
CallData: () => CallData,
|
|
43
45
|
Contract: () => Contract,
|
|
44
46
|
ContractFactory: () => ContractFactory,
|
|
@@ -55,6 +57,7 @@ __export(src_exports, {
|
|
|
55
57
|
RPC: () => api_exports,
|
|
56
58
|
RPC06: () => rpc_0_6_exports,
|
|
57
59
|
RPC07: () => rpc_0_7_exports,
|
|
60
|
+
ReceiptTx: () => ReceiptTx,
|
|
58
61
|
RpcChannel: () => RpcChannel2,
|
|
59
62
|
RpcProvider: () => RpcProvider2,
|
|
60
63
|
SIMULATION_FLAG: () => SIMULATION_FLAG,
|
|
@@ -64,22 +67,27 @@ __export(src_exports, {
|
|
|
64
67
|
TransactionFinalityStatus: () => TransactionFinalityStatus,
|
|
65
68
|
TransactionStatus: () => TransactionStatus,
|
|
66
69
|
TransactionType: () => TransactionType,
|
|
67
|
-
TypedDataRevision: () => TypedDataRevision,
|
|
70
|
+
TypedDataRevision: () => import_starknet_types.TypedDataRevision,
|
|
71
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
72
|
+
UINT_128_MIN: () => UINT_128_MIN,
|
|
73
|
+
UINT_256_HIGH_MAX: () => UINT_256_HIGH_MAX,
|
|
74
|
+
UINT_256_HIGH_MIN: () => UINT_256_HIGH_MIN,
|
|
75
|
+
UINT_256_LOW_MAX: () => UINT_256_LOW_MAX,
|
|
76
|
+
UINT_256_LOW_MIN: () => UINT_256_LOW_MIN,
|
|
77
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
78
|
+
UINT_256_MIN: () => UINT_256_MIN,
|
|
79
|
+
UINT_512_MAX: () => UINT_512_MAX,
|
|
80
|
+
UINT_512_MIN: () => UINT_512_MIN,
|
|
68
81
|
Uint: () => Uint,
|
|
69
82
|
ValidateType: () => ValidateType,
|
|
70
83
|
WalletAccount: () => WalletAccount,
|
|
71
84
|
addAddressPadding: () => addAddressPadding,
|
|
72
|
-
addDeclareTransaction: () => addDeclareTransaction,
|
|
73
|
-
addDeployAccountTransaction: () => addDeployAccountTransaction,
|
|
74
|
-
addInvokeTransaction: () => addInvokeTransaction,
|
|
75
|
-
addStarknetChain: () => addStarknetChain,
|
|
76
85
|
buildUrl: () => buildUrl,
|
|
77
86
|
byteArray: () => byteArray_exports,
|
|
78
87
|
cairo: () => cairo_exports,
|
|
79
88
|
constants: () => constants_exports,
|
|
80
89
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
81
90
|
defaultProvider: () => defaultProvider,
|
|
82
|
-
deploymentData: () => deploymentData,
|
|
83
91
|
ec: () => ec_exports,
|
|
84
92
|
encode: () => encode_exports,
|
|
85
93
|
eth: () => eth_exports,
|
|
@@ -89,7 +97,6 @@ __export(src_exports, {
|
|
|
89
97
|
fixStack: () => fixStack,
|
|
90
98
|
getCalldata: () => getCalldata,
|
|
91
99
|
getChecksumAddress: () => getChecksumAddress,
|
|
92
|
-
getPermissions: () => getPermissions,
|
|
93
100
|
hash: () => hash_exports,
|
|
94
101
|
isSierra: () => isSierra,
|
|
95
102
|
isUrl: () => isUrl,
|
|
@@ -97,20 +104,13 @@ __export(src_exports, {
|
|
|
97
104
|
merkle: () => merkle_exports,
|
|
98
105
|
num: () => num_exports,
|
|
99
106
|
number: () => number,
|
|
100
|
-
onAccountChange: () => onAccountChange,
|
|
101
|
-
onNetworkChanged: () => onNetworkChanged,
|
|
102
107
|
parseUDCEvent: () => parseUDCEvent,
|
|
103
108
|
provider: () => provider_exports,
|
|
104
|
-
requestAccounts: () => requestAccounts,
|
|
105
|
-
requestChainId: () => requestChainId,
|
|
106
109
|
selector: () => selector_exports,
|
|
107
110
|
shortString: () => shortString_exports,
|
|
108
|
-
signMessage: () => signMessage,
|
|
109
111
|
splitArgsAndOptions: () => splitArgsAndOptions,
|
|
110
112
|
stark: () => stark_exports,
|
|
111
113
|
starknetId: () => starknetId_exports,
|
|
112
|
-
supportedSpecs: () => supportedSpecs,
|
|
113
|
-
switchStarknetChain: () => switchStarknetChain,
|
|
114
114
|
transaction: () => transaction_exports,
|
|
115
115
|
typedData: () => typedData_exports,
|
|
116
116
|
types: () => types_exports,
|
|
@@ -119,7 +119,7 @@ __export(src_exports, {
|
|
|
119
119
|
v3hash: () => v3_exports,
|
|
120
120
|
validateAndParseAddress: () => validateAndParseAddress,
|
|
121
121
|
validateChecksumAddress: () => validateChecksumAddress,
|
|
122
|
-
|
|
122
|
+
wallet: () => connect_exports
|
|
123
123
|
});
|
|
124
124
|
module.exports = __toCommonJS(src_exports);
|
|
125
125
|
|
|
@@ -133,6 +133,10 @@ __export(constants_exports, {
|
|
|
133
133
|
MASK_250: () => MASK_250,
|
|
134
134
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
135
135
|
NetworkName: () => NetworkName,
|
|
136
|
+
PRIME: () => PRIME,
|
|
137
|
+
RANGE_FELT: () => RANGE_FELT,
|
|
138
|
+
RANGE_I128: () => RANGE_I128,
|
|
139
|
+
RANGE_U128: () => RANGE_U128,
|
|
136
140
|
RPC_DEFAULT_VERSION: () => RPC_DEFAULT_VERSION,
|
|
137
141
|
RPC_NODES: () => RPC_NODES,
|
|
138
142
|
StarknetChainId: () => StarknetChainId,
|
|
@@ -440,8 +444,13 @@ var TEXT_TO_FELT_MAX_LEN = 31;
|
|
|
440
444
|
var ZERO = 0n;
|
|
441
445
|
var MASK_250 = 2n ** 250n - 1n;
|
|
442
446
|
var API_VERSION = ZERO;
|
|
447
|
+
var PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
443
448
|
var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
444
449
|
var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
450
|
+
var range = (min, max) => ({ min, max });
|
|
451
|
+
var RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
452
|
+
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
453
|
+
var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
445
454
|
var BaseUrl = /* @__PURE__ */ ((BaseUrl2) => {
|
|
446
455
|
BaseUrl2["SN_MAIN"] = "https://alpha-mainnet.starknet.io";
|
|
447
456
|
BaseUrl2["SN_GOERLI"] = "https://alpha4.starknet.io";
|
|
@@ -550,7 +559,7 @@ __export(types_exports, {
|
|
|
550
559
|
TransactionFinalityStatus: () => TransactionFinalityStatus,
|
|
551
560
|
TransactionStatus: () => TransactionStatus,
|
|
552
561
|
TransactionType: () => TransactionType,
|
|
553
|
-
TypedDataRevision: () => TypedDataRevision,
|
|
562
|
+
TypedDataRevision: () => import_starknet_types.TypedDataRevision,
|
|
554
563
|
Uint: () => Uint,
|
|
555
564
|
ValidateType: () => ValidateType
|
|
556
565
|
});
|
|
@@ -576,11 +585,13 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
|
|
|
576
585
|
Uint2["u64"] = "core::integer::u64";
|
|
577
586
|
Uint2["u128"] = "core::integer::u128";
|
|
578
587
|
Uint2["u256"] = "core::integer::u256";
|
|
588
|
+
Uint2["u512"] = "core::integer::u512";
|
|
579
589
|
return Uint2;
|
|
580
590
|
})(Uint || {});
|
|
581
591
|
var Literal = /* @__PURE__ */ ((Literal2) => {
|
|
582
592
|
Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
|
|
583
593
|
Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
|
|
594
|
+
Literal2["Secp256k1Point"] = "core::starknet::secp256k1::Secp256k1Point";
|
|
584
595
|
return Literal2;
|
|
585
596
|
})(Literal || {});
|
|
586
597
|
|
|
@@ -636,11 +647,7 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
|
|
|
636
647
|
})(BlockTag || {});
|
|
637
648
|
|
|
638
649
|
// src/types/typedData.ts
|
|
639
|
-
var
|
|
640
|
-
TypedDataRevision2["Active"] = "1";
|
|
641
|
-
TypedDataRevision2["Legacy"] = "0";
|
|
642
|
-
return TypedDataRevision2;
|
|
643
|
-
})(TypedDataRevision || {});
|
|
650
|
+
var import_starknet_types = require("starknet-types");
|
|
644
651
|
|
|
645
652
|
// src/utils/assert.ts
|
|
646
653
|
function assert(condition, message) {
|
|
@@ -663,7 +670,9 @@ __export(num_exports, {
|
|
|
663
670
|
hexToBytes: () => hexToBytes,
|
|
664
671
|
hexToDecimalString: () => hexToDecimalString,
|
|
665
672
|
isBigInt: () => isBigInt,
|
|
673
|
+
isBoolean: () => isBoolean,
|
|
666
674
|
isHex: () => isHex,
|
|
675
|
+
isNumber: () => isNumber,
|
|
667
676
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
668
677
|
toBigInt: () => toBigInt,
|
|
669
678
|
toCairoBool: () => toCairoBool,
|
|
@@ -745,6 +754,12 @@ function addPercent(number2, percent) {
|
|
|
745
754
|
const bigIntNum = BigInt(number2);
|
|
746
755
|
return bigIntNum + bigIntNum * BigInt(percent) / 100n;
|
|
747
756
|
}
|
|
757
|
+
function isNumber(value) {
|
|
758
|
+
return typeof value === "number";
|
|
759
|
+
}
|
|
760
|
+
function isBoolean(value) {
|
|
761
|
+
return typeof value === "boolean";
|
|
762
|
+
}
|
|
748
763
|
|
|
749
764
|
// src/utils/selector.ts
|
|
750
765
|
var selector_exports = {};
|
|
@@ -790,6 +805,7 @@ __export(shortString_exports, {
|
|
|
790
805
|
isLongText: () => isLongText,
|
|
791
806
|
isShortString: () => isShortString,
|
|
792
807
|
isShortText: () => isShortText,
|
|
808
|
+
isString: () => isString,
|
|
793
809
|
isText: () => isText,
|
|
794
810
|
splitLongString: () => splitLongString
|
|
795
811
|
});
|
|
@@ -802,8 +818,11 @@ function isShortString(str) {
|
|
|
802
818
|
function isDecimalString(str) {
|
|
803
819
|
return /^[0-9]*$/i.test(str);
|
|
804
820
|
}
|
|
821
|
+
function isString(value) {
|
|
822
|
+
return typeof value === "string";
|
|
823
|
+
}
|
|
805
824
|
function isText(val) {
|
|
806
|
-
return
|
|
825
|
+
return isString(val) && !isHex(val) && !isStringWholeNumber(val);
|
|
807
826
|
}
|
|
808
827
|
var isShortText = (val) => isText(val) && isShortString(val);
|
|
809
828
|
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
@@ -876,34 +895,38 @@ __export(cairo_exports, {
|
|
|
876
895
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
877
896
|
isTypeOption: () => isTypeOption,
|
|
878
897
|
isTypeResult: () => isTypeResult,
|
|
898
|
+
isTypeSecp256k1Point: () => isTypeSecp256k1Point,
|
|
879
899
|
isTypeStruct: () => isTypeStruct,
|
|
880
900
|
isTypeTuple: () => isTypeTuple,
|
|
881
901
|
isTypeUint: () => isTypeUint,
|
|
882
902
|
isTypeUint256: () => isTypeUint256,
|
|
883
903
|
tuple: () => tuple,
|
|
884
|
-
uint256: () => uint256
|
|
904
|
+
uint256: () => uint256,
|
|
905
|
+
uint512: () => uint512
|
|
885
906
|
});
|
|
886
907
|
|
|
887
908
|
// src/utils/cairoDataTypes/felt.ts
|
|
888
909
|
function CairoFelt(it) {
|
|
889
|
-
if (isBigInt(it) ||
|
|
910
|
+
if (isBigInt(it) || Number.isInteger(it)) {
|
|
890
911
|
return it.toString();
|
|
891
912
|
}
|
|
892
|
-
if (
|
|
893
|
-
if (
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
913
|
+
if (isString(it)) {
|
|
914
|
+
if (isHex(it)) {
|
|
915
|
+
return BigInt(it).toString();
|
|
916
|
+
}
|
|
917
|
+
if (isText(it)) {
|
|
918
|
+
if (!isShortString(it)) {
|
|
919
|
+
throw new Error(
|
|
920
|
+
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
return BigInt(encodeShortString(it)).toString();
|
|
924
|
+
}
|
|
925
|
+
if (isStringWholeNumber(it)) {
|
|
926
|
+
return it;
|
|
927
|
+
}
|
|
905
928
|
}
|
|
906
|
-
if (
|
|
929
|
+
if (isBoolean(it)) {
|
|
907
930
|
return `${+it}`;
|
|
908
931
|
}
|
|
909
932
|
throw new Error(`${it} can't be computed by felt()`);
|
|
@@ -1014,6 +1037,130 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1014
1037
|
}
|
|
1015
1038
|
};
|
|
1016
1039
|
|
|
1040
|
+
// src/utils/cairoDataTypes/uint512.ts
|
|
1041
|
+
var UINT_512_MAX = (1n << 512n) - 1n;
|
|
1042
|
+
var UINT_512_MIN = 0n;
|
|
1043
|
+
var UINT_128_MIN = 0n;
|
|
1044
|
+
var CairoUint512 = class _CairoUint512 {
|
|
1045
|
+
limb0;
|
|
1046
|
+
limb1;
|
|
1047
|
+
limb2;
|
|
1048
|
+
limb3;
|
|
1049
|
+
static abiSelector = "core::integer::u512";
|
|
1050
|
+
constructor(...arr) {
|
|
1051
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
1052
|
+
const props = _CairoUint512.validateProps(
|
|
1053
|
+
arr[0].limb0,
|
|
1054
|
+
arr[0].limb1,
|
|
1055
|
+
arr[0].limb2,
|
|
1056
|
+
arr[0].limb3
|
|
1057
|
+
);
|
|
1058
|
+
this.limb0 = props.limb0;
|
|
1059
|
+
this.limb1 = props.limb1;
|
|
1060
|
+
this.limb2 = props.limb2;
|
|
1061
|
+
this.limb3 = props.limb3;
|
|
1062
|
+
} else if (arr.length === 1) {
|
|
1063
|
+
const bigInt = _CairoUint512.validate(arr[0]);
|
|
1064
|
+
this.limb0 = bigInt & UINT_128_MAX;
|
|
1065
|
+
this.limb1 = (bigInt & UINT_128_MAX << 128n) >> 128n;
|
|
1066
|
+
this.limb2 = (bigInt & UINT_128_MAX << 256n) >> 256n;
|
|
1067
|
+
this.limb3 = bigInt >> 384n;
|
|
1068
|
+
} else if (arr.length === 4) {
|
|
1069
|
+
const props = _CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
|
|
1070
|
+
this.limb0 = props.limb0;
|
|
1071
|
+
this.limb1 = props.limb1;
|
|
1072
|
+
this.limb2 = props.limb2;
|
|
1073
|
+
this.limb3 = props.limb3;
|
|
1074
|
+
} else {
|
|
1075
|
+
throw Error("Incorrect Uint512 constructor parameters");
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
1080
|
+
*/
|
|
1081
|
+
static validate(bigNumberish) {
|
|
1082
|
+
const bigInt = BigInt(bigNumberish);
|
|
1083
|
+
if (bigInt < UINT_512_MIN)
|
|
1084
|
+
throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
1085
|
+
if (bigInt > UINT_512_MAX)
|
|
1086
|
+
throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
1087
|
+
return bigInt;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Validate if limbs can be represented as Uint512
|
|
1091
|
+
*/
|
|
1092
|
+
static validateProps(limb0, limb1, limb2, limb3) {
|
|
1093
|
+
const l0 = BigInt(limb0);
|
|
1094
|
+
const l1 = BigInt(limb1);
|
|
1095
|
+
const l2 = BigInt(limb2);
|
|
1096
|
+
const l3 = BigInt(limb3);
|
|
1097
|
+
[l0, l1, l2, l3].forEach((value, index) => {
|
|
1098
|
+
if (value < UINT_128_MIN || value > UINT_128_MAX) {
|
|
1099
|
+
throw Error(`limb${index} is not in the range of a u128 number`);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Check if BigNumberish can be represented as Uint512
|
|
1106
|
+
*/
|
|
1107
|
+
static is(bigNumberish) {
|
|
1108
|
+
try {
|
|
1109
|
+
_CairoUint512.validate(bigNumberish);
|
|
1110
|
+
} catch (error) {
|
|
1111
|
+
return false;
|
|
1112
|
+
}
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Check if provided abi type is this data type
|
|
1117
|
+
*/
|
|
1118
|
+
static isAbiType(abiType) {
|
|
1119
|
+
return abiType === _CairoUint512.abiSelector;
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Return bigint representation
|
|
1123
|
+
*/
|
|
1124
|
+
toBigInt() {
|
|
1125
|
+
return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Return Uint512 structure with HexString props
|
|
1129
|
+
* limbx: HexString
|
|
1130
|
+
*/
|
|
1131
|
+
toUint512HexString() {
|
|
1132
|
+
return {
|
|
1133
|
+
limb0: addHexPrefix(this.limb0.toString(16)),
|
|
1134
|
+
limb1: addHexPrefix(this.limb1.toString(16)),
|
|
1135
|
+
limb2: addHexPrefix(this.limb2.toString(16)),
|
|
1136
|
+
limb3: addHexPrefix(this.limb3.toString(16))
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Return Uint512 structure with DecimalString props
|
|
1141
|
+
* limbx DecString
|
|
1142
|
+
*/
|
|
1143
|
+
toUint512DecimalString() {
|
|
1144
|
+
return {
|
|
1145
|
+
limb0: this.limb0.toString(10),
|
|
1146
|
+
limb1: this.limb1.toString(10),
|
|
1147
|
+
limb2: this.limb2.toString(10),
|
|
1148
|
+
limb3: this.limb3.toString(10)
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Return api requests representation witch is felt array
|
|
1153
|
+
*/
|
|
1154
|
+
toApiRequest() {
|
|
1155
|
+
return [
|
|
1156
|
+
CairoFelt(this.limb0),
|
|
1157
|
+
CairoFelt(this.limb1),
|
|
1158
|
+
CairoFelt(this.limb2),
|
|
1159
|
+
CairoFelt(this.limb3)
|
|
1160
|
+
];
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1017
1164
|
// src/utils/calldata/cairo.ts
|
|
1018
1165
|
var isLen = (name) => /_len$/.test(name);
|
|
1019
1166
|
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
@@ -1032,6 +1179,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
|
|
|
1032
1179
|
var isTypeEthAddress = (type) => type === "core::starknet::eth_address::EthAddress";
|
|
1033
1180
|
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
1034
1181
|
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
1182
|
+
var isTypeSecp256k1Point = (type) => type === "core::starknet::secp256k1::Secp256k1Point";
|
|
1035
1183
|
var isCairo1Type = (type) => type.includes("::");
|
|
1036
1184
|
var getArrayType = (type) => {
|
|
1037
1185
|
if (isCairo1Type(type)) {
|
|
@@ -1065,6 +1213,9 @@ function getAbiContractVersion(abi) {
|
|
|
1065
1213
|
var uint256 = (it) => {
|
|
1066
1214
|
return new CairoUint256(it).toUint256DecimalString();
|
|
1067
1215
|
};
|
|
1216
|
+
var uint512 = (it) => {
|
|
1217
|
+
return new CairoUint512(it).toUint512DecimalString();
|
|
1218
|
+
};
|
|
1068
1219
|
var tuple = (...args) => ({ ...args });
|
|
1069
1220
|
function felt(it) {
|
|
1070
1221
|
return CairoFelt(it);
|
|
@@ -1469,6 +1620,11 @@ function errorU256(key) {
|
|
|
1469
1620
|
`Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
|
|
1470
1621
|
);
|
|
1471
1622
|
}
|
|
1623
|
+
function errorU512(key) {
|
|
1624
|
+
return Error(
|
|
1625
|
+
`Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1472
1628
|
function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
1473
1629
|
const orderInput = (unorderedItem, abiType) => {
|
|
1474
1630
|
if (isTypeArray(abiType)) {
|
|
@@ -1487,6 +1643,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1487
1643
|
if (isTypeByteArray(abiType)) {
|
|
1488
1644
|
return unorderedItem;
|
|
1489
1645
|
}
|
|
1646
|
+
if (isTypeSecp256k1Point(abiType)) {
|
|
1647
|
+
return unorderedItem;
|
|
1648
|
+
}
|
|
1490
1649
|
if (CairoUint256.isAbiType(abiType)) {
|
|
1491
1650
|
const u256 = unorderedItem;
|
|
1492
1651
|
if (typeof u256 !== "object") {
|
|
@@ -1497,6 +1656,16 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1497
1656
|
}
|
|
1498
1657
|
return { low: u256.low, high: u256.high };
|
|
1499
1658
|
}
|
|
1659
|
+
if (CairoUint512.isAbiType(abiType)) {
|
|
1660
|
+
const u512 = unorderedItem;
|
|
1661
|
+
if (typeof u512 !== "object") {
|
|
1662
|
+
return u512;
|
|
1663
|
+
}
|
|
1664
|
+
if (!["limb0", "limb1", "limb2", "limb3"].every((key) => key in u512)) {
|
|
1665
|
+
throw errorU512(abiType);
|
|
1666
|
+
}
|
|
1667
|
+
return { limb0: u512.limb0, limb1: u512.limb1, limb2: u512.limb2, limb3: u512.limb3 };
|
|
1668
|
+
}
|
|
1500
1669
|
if (isTypeStruct(abiType, structs)) {
|
|
1501
1670
|
const abiOfStruct = structs[abiType].members;
|
|
1502
1671
|
return orderStruct(unorderedItem, abiOfStruct);
|
|
@@ -1521,7 +1690,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1521
1690
|
};
|
|
1522
1691
|
function orderArray(myArray, abiParam) {
|
|
1523
1692
|
const typeInArray = getArrayType(abiParam);
|
|
1524
|
-
if (
|
|
1693
|
+
if (isString(myArray)) {
|
|
1525
1694
|
return myArray;
|
|
1526
1695
|
}
|
|
1527
1696
|
return myArray.map((myElem) => orderInput(myElem, typeInArray));
|
|
@@ -1612,8 +1781,21 @@ function parseBaseTypes(type, val) {
|
|
|
1612
1781
|
switch (true) {
|
|
1613
1782
|
case CairoUint256.isAbiType(type):
|
|
1614
1783
|
return new CairoUint256(val).toApiRequest();
|
|
1784
|
+
case CairoUint512.isAbiType(type):
|
|
1785
|
+
return new CairoUint512(val).toApiRequest();
|
|
1615
1786
|
case isTypeBytes31(type):
|
|
1616
1787
|
return encodeShortString(val.toString());
|
|
1788
|
+
case isTypeSecp256k1Point(type): {
|
|
1789
|
+
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
1790
|
+
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
1791
|
+
const pubKeyETHx = uint256(addHexPrefix(pubKeyETH.slice(0, -64)));
|
|
1792
|
+
return [
|
|
1793
|
+
felt(pubKeyETHx.low),
|
|
1794
|
+
felt(pubKeyETHx.high),
|
|
1795
|
+
felt(pubKeyETHy.low),
|
|
1796
|
+
felt(pubKeyETHy.high)
|
|
1797
|
+
];
|
|
1798
|
+
}
|
|
1617
1799
|
default:
|
|
1618
1800
|
return felt(val);
|
|
1619
1801
|
}
|
|
@@ -1660,6 +1842,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1660
1842
|
if (CairoUint256.isAbiType(type)) {
|
|
1661
1843
|
return new CairoUint256(element).toApiRequest();
|
|
1662
1844
|
}
|
|
1845
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1846
|
+
return new CairoUint512(element).toApiRequest();
|
|
1847
|
+
}
|
|
1663
1848
|
if (type === "core::starknet::eth_address::EthAddress")
|
|
1664
1849
|
return parseBaseTypes(type, element);
|
|
1665
1850
|
if (type === "core::byte_array::ByteArray")
|
|
@@ -1680,6 +1865,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1680
1865
|
if (CairoUint256.isAbiType(type)) {
|
|
1681
1866
|
return new CairoUint256(element).toApiRequest();
|
|
1682
1867
|
}
|
|
1868
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1869
|
+
return new CairoUint512(element).toApiRequest();
|
|
1870
|
+
}
|
|
1683
1871
|
if (isTypeEnum(type, enums)) {
|
|
1684
1872
|
const { variants } = enums[type];
|
|
1685
1873
|
if (isTypeOption(type)) {
|
|
@@ -1772,13 +1960,13 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
1772
1960
|
if (!Array.isArray(value) && !isText(value)) {
|
|
1773
1961
|
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
1774
1962
|
}
|
|
1775
|
-
if (
|
|
1963
|
+
if (isString(value)) {
|
|
1776
1964
|
value = splitLongString(value);
|
|
1777
1965
|
}
|
|
1778
1966
|
return parseCalldataValue(value, input.type, structs, enums);
|
|
1779
1967
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1780
1968
|
return parseBaseTypes(type, value);
|
|
1781
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
1969
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type) || CairoUint256.isAbiType(type)):
|
|
1782
1970
|
return parseCalldataValue(value, type, structs, enums);
|
|
1783
1971
|
case isTypeEnum(type, enums):
|
|
1784
1972
|
return parseCalldataValue(
|
|
@@ -1803,12 +1991,25 @@ function parseBaseTypes2(type, it) {
|
|
|
1803
1991
|
const low = it.next().value;
|
|
1804
1992
|
const high = it.next().value;
|
|
1805
1993
|
return new CairoUint256(low, high).toBigInt();
|
|
1994
|
+
case CairoUint512.isAbiType(type):
|
|
1995
|
+
const limb0 = it.next().value;
|
|
1996
|
+
const limb1 = it.next().value;
|
|
1997
|
+
const limb2 = it.next().value;
|
|
1998
|
+
const limb3 = it.next().value;
|
|
1999
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
1806
2000
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1807
2001
|
temp = it.next().value;
|
|
1808
2002
|
return BigInt(temp);
|
|
1809
2003
|
case type === "core::bytes_31::bytes31":
|
|
1810
2004
|
temp = it.next().value;
|
|
1811
2005
|
return decodeShortString(temp);
|
|
2006
|
+
case isTypeSecp256k1Point(type):
|
|
2007
|
+
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2008
|
+
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2009
|
+
const yLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2010
|
+
const yHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2011
|
+
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
2012
|
+
return pubK;
|
|
1812
2013
|
default:
|
|
1813
2014
|
temp = it.next().value;
|
|
1814
2015
|
return BigInt(temp);
|
|
@@ -1823,6 +2024,13 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
1823
2024
|
const high = responseIterator.next().value;
|
|
1824
2025
|
return new CairoUint256(low, high).toBigInt();
|
|
1825
2026
|
}
|
|
2027
|
+
if (CairoUint512.isAbiType(element.type)) {
|
|
2028
|
+
const limb0 = responseIterator.next().value;
|
|
2029
|
+
const limb1 = responseIterator.next().value;
|
|
2030
|
+
const limb2 = responseIterator.next().value;
|
|
2031
|
+
const limb3 = responseIterator.next().value;
|
|
2032
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
2033
|
+
}
|
|
1826
2034
|
if (isTypeByteArray(element.type)) {
|
|
1827
2035
|
const parsedBytes31Arr = [];
|
|
1828
2036
|
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
@@ -1946,10 +2154,10 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
1946
2154
|
// src/utils/calldata/validate.ts
|
|
1947
2155
|
var validateFelt = (parameter, input) => {
|
|
1948
2156
|
assert(
|
|
1949
|
-
|
|
2157
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
1950
2158
|
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
1951
2159
|
);
|
|
1952
|
-
if (
|
|
2160
|
+
if (isString(parameter) && !isHex(parameter))
|
|
1953
2161
|
return;
|
|
1954
2162
|
const param = BigInt(parameter.toString(10));
|
|
1955
2163
|
assert(
|
|
@@ -1959,27 +2167,37 @@ var validateFelt = (parameter, input) => {
|
|
|
1959
2167
|
);
|
|
1960
2168
|
};
|
|
1961
2169
|
var validateBytes31 = (parameter, input) => {
|
|
1962
|
-
assert(
|
|
2170
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1963
2171
|
assert(
|
|
1964
2172
|
parameter.length < 32,
|
|
1965
2173
|
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
1966
2174
|
);
|
|
1967
2175
|
};
|
|
1968
2176
|
var validateByteArray = (parameter, input) => {
|
|
1969
|
-
assert(
|
|
2177
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1970
2178
|
};
|
|
1971
2179
|
var validateUint = (parameter, input) => {
|
|
1972
|
-
if (
|
|
2180
|
+
if (isNumber(parameter)) {
|
|
1973
2181
|
assert(
|
|
1974
2182
|
parameter <= Number.MAX_SAFE_INTEGER,
|
|
1975
2183
|
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
1976
2184
|
);
|
|
1977
2185
|
}
|
|
1978
2186
|
assert(
|
|
1979
|
-
|
|
2187
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter) || typeof parameter === "object" && "low" in parameter && "high" in parameter || typeof parameter === "object" && ["limb0", "limb1", "limb2", "limb3"].every((key) => key in parameter),
|
|
1980
2188
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt), but is ${typeof parameter} ${parameter}.`
|
|
1981
2189
|
);
|
|
1982
|
-
|
|
2190
|
+
let param;
|
|
2191
|
+
switch (input.type) {
|
|
2192
|
+
case "core::integer::u256" /* u256 */:
|
|
2193
|
+
param = new CairoUint256(parameter).toBigInt();
|
|
2194
|
+
break;
|
|
2195
|
+
case "core::integer::u512" /* u512 */:
|
|
2196
|
+
param = new CairoUint512(parameter).toBigInt();
|
|
2197
|
+
break;
|
|
2198
|
+
default:
|
|
2199
|
+
param = toBigInt(parameter);
|
|
2200
|
+
}
|
|
1983
2201
|
switch (input.type) {
|
|
1984
2202
|
case "core::integer::u8" /* u8 */:
|
|
1985
2203
|
assert(
|
|
@@ -2017,6 +2235,9 @@ var validateUint = (parameter, input) => {
|
|
|
2017
2235
|
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
2018
2236
|
);
|
|
2019
2237
|
break;
|
|
2238
|
+
case "core::integer::u512" /* u512 */:
|
|
2239
|
+
assert(CairoUint512.is(param), `Validate: arg ${input.name} is ${input.type} 0 - 2^512-1`);
|
|
2240
|
+
break;
|
|
2020
2241
|
case "core::starknet::class_hash::ClassHash" /* ClassHash */:
|
|
2021
2242
|
assert(
|
|
2022
2243
|
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1670
|
|
@@ -2031,18 +2252,25 @@ var validateUint = (parameter, input) => {
|
|
|
2031
2252
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
2032
2253
|
);
|
|
2033
2254
|
break;
|
|
2255
|
+
case "core::starknet::secp256k1::Secp256k1Point" /* Secp256k1Point */: {
|
|
2256
|
+
assert(
|
|
2257
|
+
param >= 0n && param <= 2n ** 512n - 1n,
|
|
2258
|
+
`Validate: arg ${input.name} must be ${input.type} : a 512 bits number.`
|
|
2259
|
+
);
|
|
2260
|
+
break;
|
|
2261
|
+
}
|
|
2034
2262
|
default:
|
|
2035
2263
|
break;
|
|
2036
2264
|
}
|
|
2037
2265
|
};
|
|
2038
2266
|
var validateBool = (parameter, input) => {
|
|
2039
2267
|
assert(
|
|
2040
|
-
|
|
2268
|
+
isBoolean(parameter),
|
|
2041
2269
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
2042
2270
|
);
|
|
2043
2271
|
};
|
|
2044
2272
|
var validateStruct = (parameter, input, structs) => {
|
|
2045
|
-
if (input.type === "core::integer::u256" /* u256 */) {
|
|
2273
|
+
if (input.type === "core::integer::u256" /* u256 */ || input.type === "core::integer::u512" /* u512 */) {
|
|
2046
2274
|
validateUint(parameter, input);
|
|
2047
2275
|
return;
|
|
2048
2276
|
}
|
|
@@ -2123,7 +2351,7 @@ var validateArray = (parameter, input, structs, enums) => {
|
|
|
2123
2351
|
parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
|
|
2124
2352
|
break;
|
|
2125
2353
|
case (isTypeUint(baseType) || isTypeLiteral(baseType)):
|
|
2126
|
-
parameter.forEach((param) => validateUint(param,
|
|
2354
|
+
parameter.forEach((param) => validateUint(param, { name: "", type: baseType }));
|
|
2127
2355
|
break;
|
|
2128
2356
|
case isTypeBool(baseType):
|
|
2129
2357
|
parameter.forEach((param) => validateBool(param, input));
|
|
@@ -2803,7 +3031,7 @@ function computeHintedClassHash(compiledContract) {
|
|
|
2803
3031
|
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2804
3032
|
}
|
|
2805
3033
|
function computeLegacyContractClassHash(contract) {
|
|
2806
|
-
const compiledContract =
|
|
3034
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2807
3035
|
const apiVersion = toHex(API_VERSION);
|
|
2808
3036
|
const externalEntryPointsHash = computeHashOnElements2(
|
|
2809
3037
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
@@ -2899,7 +3127,7 @@ function computeSierraContractClassHash(sierra) {
|
|
|
2899
3127
|
);
|
|
2900
3128
|
}
|
|
2901
3129
|
function computeContractClassHash(contract) {
|
|
2902
|
-
const compiledContract =
|
|
3130
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2903
3131
|
if ("sierra_program" in compiledContract) {
|
|
2904
3132
|
return computeSierraContractClassHash(compiledContract);
|
|
2905
3133
|
}
|
|
@@ -2927,7 +3155,7 @@ __export(stark_exports, {
|
|
|
2927
3155
|
var import_starknet4 = require("@scure/starknet");
|
|
2928
3156
|
var import_pako = require("pako");
|
|
2929
3157
|
function compressProgram(jsonProgram) {
|
|
2930
|
-
const stringified =
|
|
3158
|
+
const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
|
|
2931
3159
|
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
2932
3160
|
return btoaUniversal(compressedProgram);
|
|
2933
3161
|
}
|
|
@@ -2967,7 +3195,7 @@ function estimatedFeeToMaxFee(estimatedFee, overhead = 50 /* MAX_FEE */) {
|
|
|
2967
3195
|
return addPercent(estimatedFee, overhead);
|
|
2968
3196
|
}
|
|
2969
3197
|
function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUNT */, priceOverhead = 50 /* L1_BOUND_MAX_PRICE_PER_UNIT */) {
|
|
2970
|
-
if (
|
|
3198
|
+
if (isBigInt(estimate)) {
|
|
2971
3199
|
return {
|
|
2972
3200
|
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
2973
3201
|
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
@@ -3035,7 +3263,7 @@ function reduceV2(providedVersion) {
|
|
|
3035
3263
|
|
|
3036
3264
|
// src/utils/contract.ts
|
|
3037
3265
|
function isSierra(contract) {
|
|
3038
|
-
const compiledContract =
|
|
3266
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
3039
3267
|
return "sierra_program" in compiledContract;
|
|
3040
3268
|
}
|
|
3041
3269
|
function extractContractHashes(payload) {
|
|
@@ -3062,6 +3290,23 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
|
3062
3290
|
return { ...contract, program: decompressProgram(contract.program) };
|
|
3063
3291
|
}
|
|
3064
3292
|
|
|
3293
|
+
// src/utils/eth.ts
|
|
3294
|
+
var eth_exports = {};
|
|
3295
|
+
__export(eth_exports, {
|
|
3296
|
+
ethRandomPrivateKey: () => ethRandomPrivateKey,
|
|
3297
|
+
validateAndParseEthAddress: () => validateAndParseEthAddress
|
|
3298
|
+
});
|
|
3299
|
+
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
3300
|
+
function ethRandomPrivateKey() {
|
|
3301
|
+
return sanitizeHex(buf2hex(import_secp256k1.secp256k1.utils.randomPrivateKey()));
|
|
3302
|
+
}
|
|
3303
|
+
function validateAndParseEthAddress(address) {
|
|
3304
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address ");
|
|
3305
|
+
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
3306
|
+
assert(result.match(/^(0x)?[0-9a-f]{40}$/), "Invalid Ethereum Address Format");
|
|
3307
|
+
return result;
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3065
3310
|
// src/utils/fetchPonyfill.ts
|
|
3066
3311
|
var import_fetch_cookie = __toESM(require("fetch-cookie"));
|
|
3067
3312
|
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
@@ -3100,7 +3345,7 @@ function createSierraContractClass(contract) {
|
|
|
3100
3345
|
return result;
|
|
3101
3346
|
}
|
|
3102
3347
|
function parseContract(contract) {
|
|
3103
|
-
const parsedContract =
|
|
3348
|
+
const parsedContract = isString(contract) ? parse2(contract) : contract;
|
|
3104
3349
|
if (!isSierra(contract)) {
|
|
3105
3350
|
return {
|
|
3106
3351
|
...parsedContract,
|
|
@@ -3117,7 +3362,7 @@ var getDefaultNodeUrl = (networkName, mute = false) => {
|
|
|
3117
3362
|
return nodes[randIdx];
|
|
3118
3363
|
};
|
|
3119
3364
|
function formatHash(hashValue) {
|
|
3120
|
-
if (
|
|
3365
|
+
if (isString(hashValue))
|
|
3121
3366
|
return hashValue;
|
|
3122
3367
|
return toHex(hashValue);
|
|
3123
3368
|
}
|
|
@@ -3134,14 +3379,16 @@ var Block = class {
|
|
|
3134
3379
|
number = null;
|
|
3135
3380
|
tag = null;
|
|
3136
3381
|
setIdentifier(__identifier) {
|
|
3137
|
-
if (
|
|
3138
|
-
|
|
3139
|
-
|
|
3382
|
+
if (isString(__identifier)) {
|
|
3383
|
+
if (isHex(__identifier)) {
|
|
3384
|
+
this.hash = __identifier;
|
|
3385
|
+
} else if (validBlockTags.includes(__identifier)) {
|
|
3386
|
+
this.tag = __identifier;
|
|
3387
|
+
}
|
|
3388
|
+
} else if (isBigInt(__identifier)) {
|
|
3140
3389
|
this.hash = toHex(__identifier);
|
|
3141
|
-
} else if (
|
|
3390
|
+
} else if (isNumber(__identifier)) {
|
|
3142
3391
|
this.number = __identifier;
|
|
3143
|
-
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3144
|
-
this.tag = __identifier;
|
|
3145
3392
|
} else {
|
|
3146
3393
|
this.tag = "pending" /* pending */;
|
|
3147
3394
|
}
|
|
@@ -3738,7 +3985,7 @@ var RpcChannel = class {
|
|
|
3738
3985
|
estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
|
|
3739
3986
|
const { from_address, to_address, entry_point_selector, payload } = message;
|
|
3740
3987
|
const formattedMessage = {
|
|
3741
|
-
from_address:
|
|
3988
|
+
from_address: validateAndParseEthAddress(from_address),
|
|
3742
3989
|
to_address: toHex(to_address),
|
|
3743
3990
|
entry_point_selector: getSelector(entry_point_selector),
|
|
3744
3991
|
payload: getHexStringArray(payload)
|
|
@@ -3850,11 +4097,11 @@ var RpcChannel2 = class {
|
|
|
3850
4097
|
requestId;
|
|
3851
4098
|
blockIdentifier;
|
|
3852
4099
|
chainId;
|
|
3853
|
-
|
|
4100
|
+
specVersion;
|
|
3854
4101
|
waitMode;
|
|
3855
4102
|
// behave like web2 rpc and return when tx is processed
|
|
3856
4103
|
constructor(optionsOrProvider) {
|
|
3857
|
-
const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
|
|
4104
|
+
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
|
|
3858
4105
|
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
3859
4106
|
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
3860
4107
|
} else if (nodeUrl) {
|
|
@@ -3866,6 +4113,7 @@ var RpcChannel2 = class {
|
|
|
3866
4113
|
this.headers = { ...defaultOptions2.headers, ...headers };
|
|
3867
4114
|
this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
|
|
3868
4115
|
this.chainId = chainId;
|
|
4116
|
+
this.specVersion = specVersion;
|
|
3869
4117
|
this.waitMode = waitMode || false;
|
|
3870
4118
|
this.requestId = 0;
|
|
3871
4119
|
}
|
|
@@ -3917,8 +4165,8 @@ var RpcChannel2 = class {
|
|
|
3917
4165
|
return this.chainId;
|
|
3918
4166
|
}
|
|
3919
4167
|
async getSpecVersion() {
|
|
3920
|
-
this.
|
|
3921
|
-
return this.
|
|
4168
|
+
this.specVersion ??= await this.fetchEndpoint("starknet_specVersion");
|
|
4169
|
+
return this.specVersion;
|
|
3922
4170
|
}
|
|
3923
4171
|
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3924
4172
|
const contract_address = toHex(contractAddress);
|
|
@@ -4275,7 +4523,7 @@ var RpcChannel2 = class {
|
|
|
4275
4523
|
estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
|
|
4276
4524
|
const { from_address, to_address, entry_point_selector, payload } = message;
|
|
4277
4525
|
const formattedMessage = {
|
|
4278
|
-
from_address:
|
|
4526
|
+
from_address: validateAndParseEthAddress(from_address),
|
|
4279
4527
|
to_address: toHex(to_address),
|
|
4280
4528
|
entry_point_selector: getSelector(entry_point_selector),
|
|
4281
4529
|
payload: getHexStringArray(payload)
|
|
@@ -4390,7 +4638,7 @@ var RPCResponseParser = class {
|
|
|
4390
4638
|
return { status: "PENDING", ...res };
|
|
4391
4639
|
}
|
|
4392
4640
|
parseTransactionReceipt(res) {
|
|
4393
|
-
if ("actual_fee" in res &&
|
|
4641
|
+
if ("actual_fee" in res && isString(res.actual_fee)) {
|
|
4394
4642
|
return {
|
|
4395
4643
|
...res,
|
|
4396
4644
|
actual_fee: {
|
|
@@ -4409,7 +4657,9 @@ var RPCResponseParser = class {
|
|
|
4409
4657
|
gas_price: toBigInt(val.gas_price),
|
|
4410
4658
|
unit: val.unit,
|
|
4411
4659
|
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
4412
|
-
resourceBounds: this.estimateFeeToBounds(val)
|
|
4660
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
4661
|
+
data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
|
|
4662
|
+
data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
|
|
4413
4663
|
};
|
|
4414
4664
|
}
|
|
4415
4665
|
parseFeeEstimateBulkResponse(res) {
|
|
@@ -4419,7 +4669,9 @@ var RPCResponseParser = class {
|
|
|
4419
4669
|
gas_price: toBigInt(val.gas_price),
|
|
4420
4670
|
unit: val.unit,
|
|
4421
4671
|
suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
|
|
4422
|
-
resourceBounds: this.estimateFeeToBounds(val)
|
|
4672
|
+
resourceBounds: this.estimateFeeToBounds(val),
|
|
4673
|
+
data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
|
|
4674
|
+
data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
|
|
4423
4675
|
}));
|
|
4424
4676
|
}
|
|
4425
4677
|
parseSimulateTransactionResponse(res) {
|
|
@@ -4434,11 +4686,59 @@ var RPCResponseParser = class {
|
|
|
4434
4686
|
parseContractClassResponse(res) {
|
|
4435
4687
|
return {
|
|
4436
4688
|
...res,
|
|
4437
|
-
abi:
|
|
4689
|
+
abi: isString(res.abi) ? JSON.parse(res.abi) : res.abi
|
|
4438
4690
|
};
|
|
4439
4691
|
}
|
|
4440
4692
|
};
|
|
4441
4693
|
|
|
4694
|
+
// src/utils/transactionReceipt.ts
|
|
4695
|
+
var ReceiptTx = class _ReceiptTx {
|
|
4696
|
+
statusReceipt;
|
|
4697
|
+
value;
|
|
4698
|
+
constructor(receipt) {
|
|
4699
|
+
[this.statusReceipt, this.value] = _ReceiptTx.isSuccess(receipt) ? ["success", receipt] : _ReceiptTx.isReverted(receipt) ? ["reverted", receipt] : _ReceiptTx.isRejected(receipt) ? ["rejected", receipt] : ["error", new Error("Unknown response type")];
|
|
4700
|
+
for (const [key] of Object.entries(this)) {
|
|
4701
|
+
Object.defineProperty(this, key, {
|
|
4702
|
+
enumerable: false
|
|
4703
|
+
});
|
|
4704
|
+
}
|
|
4705
|
+
for (const [key, value] of Object.entries(receipt)) {
|
|
4706
|
+
Object.defineProperty(this, key, {
|
|
4707
|
+
enumerable: true,
|
|
4708
|
+
writable: false,
|
|
4709
|
+
value
|
|
4710
|
+
});
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
match(callbacks) {
|
|
4714
|
+
if (this.statusReceipt in callbacks) {
|
|
4715
|
+
return callbacks[this.statusReceipt](this.value);
|
|
4716
|
+
}
|
|
4717
|
+
return callbacks._();
|
|
4718
|
+
}
|
|
4719
|
+
isSuccess() {
|
|
4720
|
+
return this.statusReceipt === "success";
|
|
4721
|
+
}
|
|
4722
|
+
isReverted() {
|
|
4723
|
+
return this.statusReceipt === "reverted";
|
|
4724
|
+
}
|
|
4725
|
+
isRejected() {
|
|
4726
|
+
return this.statusReceipt === "rejected";
|
|
4727
|
+
}
|
|
4728
|
+
isError() {
|
|
4729
|
+
return this.statusReceipt === "error";
|
|
4730
|
+
}
|
|
4731
|
+
static isSuccess(transactionReceipt) {
|
|
4732
|
+
return transactionReceipt.execution_status === "SUCCEEDED" /* SUCCEEDED */;
|
|
4733
|
+
}
|
|
4734
|
+
static isReverted(transactionReceipt) {
|
|
4735
|
+
return transactionReceipt.execution_status === "REVERTED" /* REVERTED */;
|
|
4736
|
+
}
|
|
4737
|
+
static isRejected(transactionReceipt) {
|
|
4738
|
+
return transactionReceipt.status === "REJECTED" /* REJECTED */;
|
|
4739
|
+
}
|
|
4740
|
+
};
|
|
4741
|
+
|
|
4442
4742
|
// src/provider/rpc.ts
|
|
4443
4743
|
var RpcProvider = class {
|
|
4444
4744
|
responseParser;
|
|
@@ -4523,7 +4823,9 @@ var RpcProvider = class {
|
|
|
4523
4823
|
return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index);
|
|
4524
4824
|
}
|
|
4525
4825
|
async getTransactionReceipt(txHash) {
|
|
4526
|
-
|
|
4826
|
+
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
4827
|
+
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
4828
|
+
return new ReceiptTx(txReceiptWoHelperModified);
|
|
4527
4829
|
}
|
|
4528
4830
|
async getTransactionTrace(txHash) {
|
|
4529
4831
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -4545,7 +4847,11 @@ var RpcProvider = class {
|
|
|
4545
4847
|
return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
|
|
4546
4848
|
}
|
|
4547
4849
|
async waitForTransaction(txHash, options) {
|
|
4548
|
-
|
|
4850
|
+
const receiptWoHelper = await this.channel.waitForTransaction(
|
|
4851
|
+
txHash,
|
|
4852
|
+
options
|
|
4853
|
+
);
|
|
4854
|
+
return new ReceiptTx(receiptWoHelper);
|
|
4549
4855
|
}
|
|
4550
4856
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4551
4857
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -5131,7 +5437,7 @@ var SignerInterface = class {
|
|
|
5131
5437
|
// src/utils/typedData.ts
|
|
5132
5438
|
var typedData_exports = {};
|
|
5133
5439
|
__export(typedData_exports, {
|
|
5134
|
-
TypedDataRevision: () => TypedDataRevision,
|
|
5440
|
+
TypedDataRevision: () => import_starknet_types.TypedDataRevision,
|
|
5135
5441
|
encodeData: () => encodeData,
|
|
5136
5442
|
encodeType: () => encodeType,
|
|
5137
5443
|
encodeValue: () => encodeValue,
|
|
@@ -5235,14 +5541,14 @@ var presetTypes = {
|
|
|
5235
5541
|
)
|
|
5236
5542
|
};
|
|
5237
5543
|
var revisionConfiguration = {
|
|
5238
|
-
[
|
|
5544
|
+
[import_starknet_types.TypedDataRevision.Active]: {
|
|
5239
5545
|
domain: "StarknetDomain",
|
|
5240
5546
|
hashMethod: computePoseidonHashOnElements,
|
|
5241
5547
|
hashMerkleMethod: computePoseidonHash,
|
|
5242
5548
|
escapeTypeString: (s) => `"${s}"`,
|
|
5243
5549
|
presetTypes
|
|
5244
5550
|
},
|
|
5245
|
-
[
|
|
5551
|
+
[import_starknet_types.TypedDataRevision.Legacy]: {
|
|
5246
5552
|
domain: "StarkNetDomain",
|
|
5247
5553
|
hashMethod: computePedersenHashOnElements,
|
|
5248
5554
|
hashMerkleMethod: computePedersenHash,
|
|
@@ -5250,18 +5556,22 @@ var revisionConfiguration = {
|
|
|
5250
5556
|
presetTypes: {}
|
|
5251
5557
|
}
|
|
5252
5558
|
};
|
|
5559
|
+
function assertRange(data, type, { min, max }) {
|
|
5560
|
+
const value = BigInt(data);
|
|
5561
|
+
assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
|
|
5562
|
+
}
|
|
5253
5563
|
function identifyRevision({ types, domain }) {
|
|
5254
|
-
if (revisionConfiguration[
|
|
5255
|
-
return
|
|
5256
|
-
if (revisionConfiguration[
|
|
5257
|
-
return
|
|
5564
|
+
if (revisionConfiguration[import_starknet_types.TypedDataRevision.Active].domain in types && domain.revision === import_starknet_types.TypedDataRevision.Active)
|
|
5565
|
+
return import_starknet_types.TypedDataRevision.Active;
|
|
5566
|
+
if (revisionConfiguration[import_starknet_types.TypedDataRevision.Legacy].domain in types && (domain.revision ?? import_starknet_types.TypedDataRevision.Legacy) === import_starknet_types.TypedDataRevision.Legacy)
|
|
5567
|
+
return import_starknet_types.TypedDataRevision.Legacy;
|
|
5258
5568
|
return void 0;
|
|
5259
5569
|
}
|
|
5260
5570
|
function getHex(value) {
|
|
5261
5571
|
try {
|
|
5262
5572
|
return toHex(value);
|
|
5263
5573
|
} catch (e) {
|
|
5264
|
-
if (
|
|
5574
|
+
if (isString(value)) {
|
|
5265
5575
|
return toHex(encodeShortString(value));
|
|
5266
5576
|
}
|
|
5267
5577
|
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
@@ -5279,10 +5589,10 @@ function prepareSelector(selector) {
|
|
|
5279
5589
|
function isMerkleTreeType(type) {
|
|
5280
5590
|
return type.type === "merkletree";
|
|
5281
5591
|
}
|
|
5282
|
-
function getDependencies(types, type, dependencies = [], contains = "", revision =
|
|
5592
|
+
function getDependencies(types, type, dependencies = [], contains = "", revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5283
5593
|
if (type[type.length - 1] === "*") {
|
|
5284
5594
|
type = type.slice(0, -1);
|
|
5285
|
-
} else if (revision ===
|
|
5595
|
+
} else if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5286
5596
|
if (type === "enum") {
|
|
5287
5597
|
type = contains;
|
|
5288
5598
|
} else if (type.match(/^\(.*\)$/)) {
|
|
@@ -5320,8 +5630,8 @@ function getMerkleTreeType(types, ctx) {
|
|
|
5320
5630
|
}
|
|
5321
5631
|
return "raw";
|
|
5322
5632
|
}
|
|
5323
|
-
function encodeType(types, type, revision =
|
|
5324
|
-
const allTypes = revision ===
|
|
5633
|
+
function encodeType(types, type, revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5634
|
+
const allTypes = revision === import_starknet_types.TypedDataRevision.Active ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
|
|
5325
5635
|
const [primary, ...dependencies] = getDependencies(
|
|
5326
5636
|
allTypes,
|
|
5327
5637
|
type,
|
|
@@ -5333,17 +5643,17 @@ function encodeType(types, type, revision = "0" /* Legacy */) {
|
|
|
5333
5643
|
const esc = revisionConfiguration[revision].escapeTypeString;
|
|
5334
5644
|
return newTypes.map((dependency) => {
|
|
5335
5645
|
const dependencyElements = allTypes[dependency].map((t) => {
|
|
5336
|
-
const targetType = t.type === "enum" && revision ===
|
|
5646
|
+
const targetType = t.type === "enum" && revision === import_starknet_types.TypedDataRevision.Active ? t.contains : t.type;
|
|
5337
5647
|
const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
|
|
5338
5648
|
return `${esc(t.name)}:${typeString}`;
|
|
5339
5649
|
});
|
|
5340
5650
|
return `${esc(dependency)}(${dependencyElements})`;
|
|
5341
5651
|
}).join("");
|
|
5342
5652
|
}
|
|
5343
|
-
function getTypeHash(types, type, revision =
|
|
5653
|
+
function getTypeHash(types, type, revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5344
5654
|
return getSelectorFromName(encodeType(types, type, revision));
|
|
5345
5655
|
}
|
|
5346
|
-
function encodeValue(types, type, data, ctx = {}, revision =
|
|
5656
|
+
function encodeValue(types, type, data, ctx = {}, revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5347
5657
|
if (types[type]) {
|
|
5348
5658
|
return [type, getStructHash(types, type, data, revision)];
|
|
5349
5659
|
}
|
|
@@ -5366,7 +5676,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
|
|
|
5366
5676
|
}
|
|
5367
5677
|
switch (type) {
|
|
5368
5678
|
case "enum": {
|
|
5369
|
-
if (revision ===
|
|
5679
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5370
5680
|
const [variantKey, variantData] = Object.entries(data)[0];
|
|
5371
5681
|
const parentType = types[ctx.parent][0];
|
|
5372
5682
|
const enumType = types[parentType.contains];
|
|
@@ -5400,7 +5710,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
|
|
|
5400
5710
|
return ["felt", prepareSelector(data)];
|
|
5401
5711
|
}
|
|
5402
5712
|
case "string": {
|
|
5403
|
-
if (revision ===
|
|
5713
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5404
5714
|
const byteArray = byteArrayFromString(data);
|
|
5405
5715
|
const elements = [
|
|
5406
5716
|
byteArray.data.length,
|
|
@@ -5412,24 +5722,50 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
|
|
|
5412
5722
|
}
|
|
5413
5723
|
return [type, getHex(data)];
|
|
5414
5724
|
}
|
|
5725
|
+
case "i128": {
|
|
5726
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5727
|
+
const value = BigInt(data);
|
|
5728
|
+
assertRange(value, type, RANGE_I128);
|
|
5729
|
+
return [type, getHex(value < 0n ? PRIME + value : value)];
|
|
5730
|
+
}
|
|
5731
|
+
return [type, getHex(data)];
|
|
5732
|
+
}
|
|
5733
|
+
case "timestamp":
|
|
5734
|
+
case "u128": {
|
|
5735
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5736
|
+
assertRange(data, type, RANGE_U128);
|
|
5737
|
+
}
|
|
5738
|
+
return [type, getHex(data)];
|
|
5739
|
+
}
|
|
5415
5740
|
case "felt":
|
|
5416
|
-
case "
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5741
|
+
case "shortstring": {
|
|
5742
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5743
|
+
assertRange(getHex(data), type, RANGE_FELT);
|
|
5744
|
+
}
|
|
5745
|
+
return [type, getHex(data)];
|
|
5746
|
+
}
|
|
5420
5747
|
case "ClassHash":
|
|
5421
|
-
case "
|
|
5422
|
-
|
|
5748
|
+
case "ContractAddress": {
|
|
5749
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5750
|
+
assertRange(data, type, RANGE_FELT);
|
|
5751
|
+
}
|
|
5423
5752
|
return [type, getHex(data)];
|
|
5753
|
+
}
|
|
5754
|
+
case "bool": {
|
|
5755
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5756
|
+
assert(typeof data === "boolean", `Type mismatch for ${type} ${data}`);
|
|
5757
|
+
}
|
|
5758
|
+
return [type, getHex(data)];
|
|
5759
|
+
}
|
|
5424
5760
|
default: {
|
|
5425
|
-
if (revision ===
|
|
5761
|
+
if (revision === import_starknet_types.TypedDataRevision.Active) {
|
|
5426
5762
|
throw new Error(`Unsupported type: ${type}`);
|
|
5427
5763
|
}
|
|
5428
5764
|
return [type, getHex(data)];
|
|
5429
5765
|
}
|
|
5430
5766
|
}
|
|
5431
5767
|
}
|
|
5432
|
-
function encodeData(types, type, data, revision =
|
|
5768
|
+
function encodeData(types, type, data, revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5433
5769
|
const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
|
|
5434
5770
|
const [returnTypes, values] = targetType.reduce(
|
|
5435
5771
|
([ts, vs], field) => {
|
|
@@ -5448,7 +5784,7 @@ function encodeData(types, type, data, revision = "0" /* Legacy */) {
|
|
|
5448
5784
|
);
|
|
5449
5785
|
return [returnTypes, values];
|
|
5450
5786
|
}
|
|
5451
|
-
function getStructHash(types, type, data, revision =
|
|
5787
|
+
function getStructHash(types, type, data, revision = import_starknet_types.TypedDataRevision.Legacy) {
|
|
5452
5788
|
return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
|
|
5453
5789
|
}
|
|
5454
5790
|
function getMessageHash(typedData, account) {
|
|
@@ -5560,29 +5896,48 @@ var Signer = class {
|
|
|
5560
5896
|
// src/signer/ethSigner.ts
|
|
5561
5897
|
var import_secp256k12 = require("@noble/curves/secp256k1");
|
|
5562
5898
|
|
|
5563
|
-
// src/utils/
|
|
5564
|
-
var
|
|
5565
|
-
__export(
|
|
5566
|
-
|
|
5899
|
+
// src/utils/uint256.ts
|
|
5900
|
+
var uint256_exports = {};
|
|
5901
|
+
__export(uint256_exports, {
|
|
5902
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
5903
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
5904
|
+
bnToUint256: () => bnToUint256,
|
|
5905
|
+
isUint256: () => isUint256,
|
|
5906
|
+
uint256ToBN: () => uint256ToBN
|
|
5567
5907
|
});
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5908
|
+
function uint256ToBN(uint2562) {
|
|
5909
|
+
return new CairoUint256(uint2562).toBigInt();
|
|
5910
|
+
}
|
|
5911
|
+
function isUint256(bn) {
|
|
5912
|
+
return CairoUint256.is(bn);
|
|
5913
|
+
}
|
|
5914
|
+
function bnToUint256(bn) {
|
|
5915
|
+
return new CairoUint256(bn).toUint256HexString();
|
|
5571
5916
|
}
|
|
5572
5917
|
|
|
5573
5918
|
// src/signer/ethSigner.ts
|
|
5574
5919
|
var EthSigner = class {
|
|
5575
5920
|
pk;
|
|
5576
|
-
// hex string without 0x and odd number of characters
|
|
5921
|
+
// hex string without 0x and with an odd number of characters
|
|
5577
5922
|
constructor(pk = ethRandomPrivateKey()) {
|
|
5578
|
-
this.pk = pk instanceof Uint8Array ?
|
|
5923
|
+
this.pk = pk instanceof Uint8Array ? buf2hex(pk).padStart(64, "0") : removeHexPrefix(toHex(pk)).padStart(64, "0");
|
|
5579
5924
|
}
|
|
5925
|
+
/**
|
|
5926
|
+
* provides the Ethereum full public key (without parity prefix)
|
|
5927
|
+
* @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
5928
|
+
*/
|
|
5580
5929
|
async getPubKey() {
|
|
5581
|
-
return addHexPrefix(
|
|
5930
|
+
return addHexPrefix(
|
|
5931
|
+
buf2hex(import_secp256k12.secp256k1.getPublicKey(this.pk, false)).padStart(130, "0").slice(2)
|
|
5932
|
+
);
|
|
5582
5933
|
}
|
|
5583
5934
|
async signMessage(typedData, accountAddress) {
|
|
5584
5935
|
const msgHash = getMessageHash(typedData, accountAddress);
|
|
5585
|
-
|
|
5936
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
5937
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5938
|
+
this.pk
|
|
5939
|
+
);
|
|
5940
|
+
return this.formatEthSignature(signature);
|
|
5586
5941
|
}
|
|
5587
5942
|
async signTransaction(transactions, details) {
|
|
5588
5943
|
const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
|
|
@@ -5608,7 +5963,11 @@ var EthSigner = class {
|
|
|
5608
5963
|
} else {
|
|
5609
5964
|
throw Error("unsupported signTransaction version");
|
|
5610
5965
|
}
|
|
5611
|
-
|
|
5966
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
5967
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5968
|
+
this.pk
|
|
5969
|
+
);
|
|
5970
|
+
return this.formatEthSignature(signature);
|
|
5612
5971
|
}
|
|
5613
5972
|
async signDeployAccountTransaction(details) {
|
|
5614
5973
|
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
@@ -5634,7 +5993,11 @@ var EthSigner = class {
|
|
|
5634
5993
|
} else {
|
|
5635
5994
|
throw Error("unsupported signDeployAccountTransaction version");
|
|
5636
5995
|
}
|
|
5637
|
-
|
|
5996
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
5997
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5998
|
+
this.pk
|
|
5999
|
+
);
|
|
6000
|
+
return this.formatEthSignature(signature);
|
|
5638
6001
|
}
|
|
5639
6002
|
async signDeclareTransaction(details) {
|
|
5640
6003
|
let msgHash;
|
|
@@ -5655,7 +6018,27 @@ var EthSigner = class {
|
|
|
5655
6018
|
} else {
|
|
5656
6019
|
throw Error("unsupported signDeclareTransaction version");
|
|
5657
6020
|
}
|
|
5658
|
-
|
|
6021
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
6022
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
6023
|
+
this.pk
|
|
6024
|
+
);
|
|
6025
|
+
return this.formatEthSignature(signature);
|
|
6026
|
+
}
|
|
6027
|
+
/**
|
|
6028
|
+
* Serialize the signature in conformity with starknet::eth_signature::Signature
|
|
6029
|
+
* @param ethSignature secp256k1 signature from Noble curves library
|
|
6030
|
+
* @return an array of felts, representing a Cairo Eth Signature.
|
|
6031
|
+
*/
|
|
6032
|
+
formatEthSignature(ethSignature) {
|
|
6033
|
+
const r = bnToUint256(ethSignature.r);
|
|
6034
|
+
const s = bnToUint256(ethSignature.s);
|
|
6035
|
+
return [
|
|
6036
|
+
toHex(r.low),
|
|
6037
|
+
toHex(r.high),
|
|
6038
|
+
toHex(s.low),
|
|
6039
|
+
toHex(s.high),
|
|
6040
|
+
toHex(ethSignature.recovery)
|
|
6041
|
+
];
|
|
5659
6042
|
}
|
|
5660
6043
|
};
|
|
5661
6044
|
|
|
@@ -5691,7 +6074,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5691
6074
|
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = "0x2" /* V2 */) {
|
|
5692
6075
|
super(providerOrOptions);
|
|
5693
6076
|
this.address = address.toLowerCase();
|
|
5694
|
-
this.signer =
|
|
6077
|
+
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
5695
6078
|
if (cairoVersion) {
|
|
5696
6079
|
this.cairoVersion = cairoVersion.toString();
|
|
5697
6080
|
}
|
|
@@ -5832,7 +6215,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5832
6215
|
return this.estimateInvokeFee(calls, details);
|
|
5833
6216
|
}
|
|
5834
6217
|
async estimateFeeBulk(invocations, details = {}) {
|
|
5835
|
-
const { nonce, blockIdentifier, version } = details;
|
|
6218
|
+
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
5836
6219
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
5837
6220
|
...v3Details(details),
|
|
5838
6221
|
versions: [
|
|
@@ -5845,11 +6228,12 @@ var Account = class extends RpcProvider2 {
|
|
|
5845
6228
|
// sierra
|
|
5846
6229
|
],
|
|
5847
6230
|
nonce,
|
|
5848
|
-
blockIdentifier
|
|
6231
|
+
blockIdentifier,
|
|
6232
|
+
skipValidate
|
|
5849
6233
|
});
|
|
5850
6234
|
return super.getEstimateFeeBulk(accountInvocations, {
|
|
5851
6235
|
blockIdentifier,
|
|
5852
|
-
skipValidate
|
|
6236
|
+
skipValidate
|
|
5853
6237
|
});
|
|
5854
6238
|
}
|
|
5855
6239
|
async simulateTransaction(invocations, details = {}) {
|
|
@@ -5874,8 +6258,9 @@ var Account = class extends RpcProvider2 {
|
|
|
5874
6258
|
skipExecute
|
|
5875
6259
|
});
|
|
5876
6260
|
}
|
|
5877
|
-
async execute(
|
|
5878
|
-
const
|
|
6261
|
+
async execute(transactions, arg2, transactionsDetail = {}) {
|
|
6262
|
+
const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
|
|
6263
|
+
const calls = Array.isArray(transactions) ? transactions : [transactions];
|
|
5879
6264
|
const nonce = toBigInt(details.nonce ?? await this.getNonce());
|
|
5880
6265
|
const version = toTransactionVersion(
|
|
5881
6266
|
this.getPreferredVersion("0x1" /* V1 */, "0x3" /* V3 */),
|
|
@@ -5884,7 +6269,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5884
6269
|
);
|
|
5885
6270
|
const estimate = await this.getUniversalSuggestedFee(
|
|
5886
6271
|
version,
|
|
5887
|
-
{ type: "INVOKE_FUNCTION" /* INVOKE */, payload:
|
|
6272
|
+
{ type: "INVOKE_FUNCTION" /* INVOKE */, payload: transactions },
|
|
5888
6273
|
{
|
|
5889
6274
|
...details,
|
|
5890
6275
|
version
|
|
@@ -5901,8 +6286,8 @@ var Account = class extends RpcProvider2 {
|
|
|
5901
6286
|
chainId,
|
|
5902
6287
|
cairoVersion: await this.getCairoVersion()
|
|
5903
6288
|
};
|
|
5904
|
-
const signature = await this.signer.signTransaction(
|
|
5905
|
-
const calldata = getExecuteCalldata(
|
|
6289
|
+
const signature = await this.signer.signTransaction(calls, signerDetails);
|
|
6290
|
+
const calldata = getExecuteCalldata(calls, await this.getCairoVersion());
|
|
5906
6291
|
return this.invokeFunction(
|
|
5907
6292
|
{ contractAddress: this.address, calldata, signature },
|
|
5908
6293
|
{
|
|
@@ -6114,7 +6499,9 @@ var Account = class extends RpcProvider2 {
|
|
|
6114
6499
|
overall_fee: ZERO,
|
|
6115
6500
|
unit: "FRI",
|
|
6116
6501
|
suggestedMaxFee: ZERO,
|
|
6117
|
-
resourceBounds: estimateFeeToBounds(ZERO)
|
|
6502
|
+
resourceBounds: estimateFeeToBounds(ZERO),
|
|
6503
|
+
data_gas_consumed: 0n,
|
|
6504
|
+
data_gas_price: 0n
|
|
6118
6505
|
};
|
|
6119
6506
|
break;
|
|
6120
6507
|
}
|
|
@@ -6283,6 +6670,23 @@ var AccountInterface = class extends ProviderInterface {
|
|
|
6283
6670
|
};
|
|
6284
6671
|
|
|
6285
6672
|
// src/wallet/connect.ts
|
|
6673
|
+
var connect_exports = {};
|
|
6674
|
+
__export(connect_exports, {
|
|
6675
|
+
addDeclareTransaction: () => addDeclareTransaction,
|
|
6676
|
+
addDeployAccountTransaction: () => addDeployAccountTransaction,
|
|
6677
|
+
addInvokeTransaction: () => addInvokeTransaction,
|
|
6678
|
+
addStarknetChain: () => addStarknetChain,
|
|
6679
|
+
deploymentData: () => deploymentData,
|
|
6680
|
+
getPermissions: () => getPermissions,
|
|
6681
|
+
onAccountChange: () => onAccountChange,
|
|
6682
|
+
onNetworkChanged: () => onNetworkChanged,
|
|
6683
|
+
requestAccounts: () => requestAccounts,
|
|
6684
|
+
requestChainId: () => requestChainId,
|
|
6685
|
+
signMessage: () => signMessage,
|
|
6686
|
+
supportedSpecs: () => supportedSpecs,
|
|
6687
|
+
switchStarknetChain: () => switchStarknetChain,
|
|
6688
|
+
watchAsset: () => watchAsset
|
|
6689
|
+
});
|
|
6286
6690
|
function requestAccounts(swo, silentMode = false) {
|
|
6287
6691
|
return swo.request({
|
|
6288
6692
|
type: "wallet_requestAccounts",
|
|
@@ -6853,25 +7257,6 @@ var ContractFactory = class {
|
|
|
6853
7257
|
// ethers.js' getDeployTransaction can't be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
6854
7258
|
};
|
|
6855
7259
|
|
|
6856
|
-
// src/utils/uint256.ts
|
|
6857
|
-
var uint256_exports = {};
|
|
6858
|
-
__export(uint256_exports, {
|
|
6859
|
-
UINT_128_MAX: () => UINT_128_MAX,
|
|
6860
|
-
UINT_256_MAX: () => UINT_256_MAX,
|
|
6861
|
-
bnToUint256: () => bnToUint256,
|
|
6862
|
-
isUint256: () => isUint256,
|
|
6863
|
-
uint256ToBN: () => uint256ToBN
|
|
6864
|
-
});
|
|
6865
|
-
function uint256ToBN(uint2562) {
|
|
6866
|
-
return new CairoUint256(uint2562).toBigInt();
|
|
6867
|
-
}
|
|
6868
|
-
function isUint256(bn) {
|
|
6869
|
-
return CairoUint256.is(bn);
|
|
6870
|
-
}
|
|
6871
|
-
function bnToUint256(bn) {
|
|
6872
|
-
return new CairoUint256(bn).toUint256HexString();
|
|
6873
|
-
}
|
|
6874
|
-
|
|
6875
7260
|
// src/utils/address.ts
|
|
6876
7261
|
var import_utils2 = require("@noble/curves/abstract/utils");
|
|
6877
7262
|
function addAddressPadding(address) {
|
|
@@ -6945,6 +7330,8 @@ var number = num_exports;
|
|
|
6945
7330
|
CairoOptionVariant,
|
|
6946
7331
|
CairoResult,
|
|
6947
7332
|
CairoResultVariant,
|
|
7333
|
+
CairoUint256,
|
|
7334
|
+
CairoUint512,
|
|
6948
7335
|
CallData,
|
|
6949
7336
|
Contract,
|
|
6950
7337
|
ContractFactory,
|
|
@@ -6961,6 +7348,7 @@ var number = num_exports;
|
|
|
6961
7348
|
RPC,
|
|
6962
7349
|
RPC06,
|
|
6963
7350
|
RPC07,
|
|
7351
|
+
ReceiptTx,
|
|
6964
7352
|
RpcChannel,
|
|
6965
7353
|
RpcProvider,
|
|
6966
7354
|
SIMULATION_FLAG,
|
|
@@ -6971,21 +7359,26 @@ var number = num_exports;
|
|
|
6971
7359
|
TransactionStatus,
|
|
6972
7360
|
TransactionType,
|
|
6973
7361
|
TypedDataRevision,
|
|
7362
|
+
UINT_128_MAX,
|
|
7363
|
+
UINT_128_MIN,
|
|
7364
|
+
UINT_256_HIGH_MAX,
|
|
7365
|
+
UINT_256_HIGH_MIN,
|
|
7366
|
+
UINT_256_LOW_MAX,
|
|
7367
|
+
UINT_256_LOW_MIN,
|
|
7368
|
+
UINT_256_MAX,
|
|
7369
|
+
UINT_256_MIN,
|
|
7370
|
+
UINT_512_MAX,
|
|
7371
|
+
UINT_512_MIN,
|
|
6974
7372
|
Uint,
|
|
6975
7373
|
ValidateType,
|
|
6976
7374
|
WalletAccount,
|
|
6977
7375
|
addAddressPadding,
|
|
6978
|
-
addDeclareTransaction,
|
|
6979
|
-
addDeployAccountTransaction,
|
|
6980
|
-
addInvokeTransaction,
|
|
6981
|
-
addStarknetChain,
|
|
6982
7376
|
buildUrl,
|
|
6983
7377
|
byteArray,
|
|
6984
7378
|
cairo,
|
|
6985
7379
|
constants,
|
|
6986
7380
|
contractClassResponseToLegacyCompiledContract,
|
|
6987
7381
|
defaultProvider,
|
|
6988
|
-
deploymentData,
|
|
6989
7382
|
ec,
|
|
6990
7383
|
encode,
|
|
6991
7384
|
eth,
|
|
@@ -6995,7 +7388,6 @@ var number = num_exports;
|
|
|
6995
7388
|
fixStack,
|
|
6996
7389
|
getCalldata,
|
|
6997
7390
|
getChecksumAddress,
|
|
6998
|
-
getPermissions,
|
|
6999
7391
|
hash,
|
|
7000
7392
|
isSierra,
|
|
7001
7393
|
isUrl,
|
|
@@ -7003,20 +7395,13 @@ var number = num_exports;
|
|
|
7003
7395
|
merkle,
|
|
7004
7396
|
num,
|
|
7005
7397
|
number,
|
|
7006
|
-
onAccountChange,
|
|
7007
|
-
onNetworkChanged,
|
|
7008
7398
|
parseUDCEvent,
|
|
7009
7399
|
provider,
|
|
7010
|
-
requestAccounts,
|
|
7011
|
-
requestChainId,
|
|
7012
7400
|
selector,
|
|
7013
7401
|
shortString,
|
|
7014
|
-
signMessage,
|
|
7015
7402
|
splitArgsAndOptions,
|
|
7016
7403
|
stark,
|
|
7017
7404
|
starknetId,
|
|
7018
|
-
supportedSpecs,
|
|
7019
|
-
switchStarknetChain,
|
|
7020
7405
|
transaction,
|
|
7021
7406
|
typedData,
|
|
7022
7407
|
types,
|
|
@@ -7025,6 +7410,6 @@ var number = num_exports;
|
|
|
7025
7410
|
v3hash,
|
|
7026
7411
|
validateAndParseAddress,
|
|
7027
7412
|
validateChecksumAddress,
|
|
7028
|
-
|
|
7413
|
+
wallet
|
|
7029
7414
|
});
|
|
7030
7415
|
//# sourceMappingURL=index.js.map
|