starknet 7.1.0 → 7.3.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 +26 -0
- package/dist/index.d.ts +539 -131
- package/dist/index.global.js +2049 -1234
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1378 -539
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1391 -564
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.global.js
CHANGED
|
@@ -52,6 +52,7 @@ var starknet = (() => {
|
|
|
52
52
|
LedgerSigner: () => LedgerSigner111,
|
|
53
53
|
LedgerSigner111: () => LedgerSigner111,
|
|
54
54
|
LedgerSigner221: () => LedgerSigner221,
|
|
55
|
+
LedgerSigner231: () => LedgerSigner231,
|
|
55
56
|
LibraryError: () => LibraryError,
|
|
56
57
|
Literal: () => Literal,
|
|
57
58
|
LogLevelIndex: () => LogLevelIndex,
|
|
@@ -59,11 +60,13 @@ var starknet = (() => {
|
|
|
59
60
|
OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
|
|
60
61
|
OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
|
|
61
62
|
OutsideExecutionVersion: () => OutsideExecutionVersion,
|
|
63
|
+
PaymasterInterface: () => PaymasterInterface,
|
|
64
|
+
PaymasterRpc: () => PaymasterRpc,
|
|
62
65
|
Provider: () => RpcProvider2,
|
|
63
66
|
ProviderInterface: () => ProviderInterface,
|
|
64
67
|
RPC: () => api_exports3,
|
|
65
|
-
RPC07: () =>
|
|
66
|
-
RPC08: () =>
|
|
68
|
+
RPC07: () => rpc_0_7_1_exports,
|
|
69
|
+
RPC08: () => rpc_0_8_1_exports,
|
|
67
70
|
RPCResponseParser: () => RPCResponseParser,
|
|
68
71
|
ReceiptTx: () => ReceiptTx,
|
|
69
72
|
ResponseParser: () => ResponseParser,
|
|
@@ -94,9 +97,10 @@ var starknet = (() => {
|
|
|
94
97
|
addAddressPadding: () => addAddressPadding,
|
|
95
98
|
byteArray: () => byteArray_exports,
|
|
96
99
|
cairo: () => cairo_exports,
|
|
97
|
-
config: () =>
|
|
100
|
+
config: () => config,
|
|
98
101
|
constants: () => constants_exports,
|
|
99
102
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
103
|
+
defaultPaymaster: () => defaultPaymaster,
|
|
100
104
|
defaultProvider: () => defaultProvider,
|
|
101
105
|
ec: () => ec_exports,
|
|
102
106
|
encode: () => encode_exports,
|
|
@@ -111,21 +115,29 @@ var starknet = (() => {
|
|
|
111
115
|
getLedgerPathBuffer111: () => getLedgerPathBuffer111,
|
|
112
116
|
getLedgerPathBuffer221: () => getLedgerPathBuffer221,
|
|
113
117
|
hash: () => hash_exports,
|
|
118
|
+
isPendingBlock: () => isPendingBlock,
|
|
119
|
+
isPendingStateUpdate: () => isPendingStateUpdate,
|
|
120
|
+
isPendingTransaction: () => isPendingTransaction,
|
|
114
121
|
isRPC08_FeeEstimate: () => isRPC08_FeeEstimate,
|
|
115
122
|
isRPC08_ResourceBounds: () => isRPC08_ResourceBounds,
|
|
116
123
|
isSierra: () => isSierra,
|
|
124
|
+
isSupportedSpecVersion: () => isSupportedSpecVersion,
|
|
125
|
+
isV3Tx: () => isV3Tx,
|
|
126
|
+
isVersion: () => isVersion,
|
|
117
127
|
json: () => json_exports,
|
|
118
128
|
logger: () => logger,
|
|
119
129
|
merkle: () => merkle_exports,
|
|
120
130
|
num: () => num_exports,
|
|
121
131
|
outsideExecution: () => outsideExecution_exports,
|
|
122
132
|
parseCalldataField: () => parseCalldataField,
|
|
133
|
+
paymaster: () => paymaster_exports,
|
|
123
134
|
provider: () => provider_exports,
|
|
124
135
|
selector: () => selector_exports,
|
|
125
136
|
shortString: () => shortString_exports,
|
|
126
137
|
src5: () => src5_exports,
|
|
127
138
|
stark: () => stark_exports,
|
|
128
139
|
starknetId: () => starknetId_exports,
|
|
140
|
+
toAnyPatchVersion: () => toAnyPatchVersion,
|
|
129
141
|
transaction: () => transaction_exports,
|
|
130
142
|
typedData: () => typedData_exports,
|
|
131
143
|
types: () => types_exports,
|
|
@@ -153,6 +165,7 @@ var starknet = (() => {
|
|
|
153
165
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
154
166
|
NetworkName: () => _NetworkName,
|
|
155
167
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
168
|
+
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
156
169
|
PRIME: () => PRIME,
|
|
157
170
|
RANGE_FELT: () => RANGE_FELT,
|
|
158
171
|
RANGE_I128: () => RANGE_I128,
|
|
@@ -194,6 +207,7 @@ var starknet = (() => {
|
|
|
194
207
|
EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
|
|
195
208
|
JRPC: () => jsonrpc_exports,
|
|
196
209
|
L1_DA_MODE: () => L1_DA_MODE,
|
|
210
|
+
PAYMASTER_API: () => snip_29_exports,
|
|
197
211
|
PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
|
|
198
212
|
PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
|
|
199
213
|
Permission: () => Permission2,
|
|
@@ -369,6 +383,7 @@ var starknet = (() => {
|
|
|
369
383
|
ETransactionVersion3: () => ETransactionVersion32,
|
|
370
384
|
EVENT_ABI_TYPE: () => EVENT_ABI_TYPE,
|
|
371
385
|
L1_DA_MODE: () => L1_DA_MODE,
|
|
386
|
+
PAYMASTER_API: () => snip_29_exports,
|
|
372
387
|
PRICE_UNIT_FRI: () => PRICE_UNIT_FRI,
|
|
373
388
|
PRICE_UNIT_WEI: () => PRICE_UNIT_WEI,
|
|
374
389
|
Permission: () => Permission2,
|
|
@@ -563,6 +578,9 @@ var starknet = (() => {
|
|
|
563
578
|
LEGACY: "0"
|
|
564
579
|
};
|
|
565
580
|
|
|
581
|
+
// node_modules/starknet-types-08/dist/esm/snip-29/index.js
|
|
582
|
+
var snip_29_exports = {};
|
|
583
|
+
|
|
566
584
|
// src/utils/encode.ts
|
|
567
585
|
var encode_exports = {};
|
|
568
586
|
__export(encode_exports, {
|
|
@@ -871,14 +889,14 @@ var starknet = (() => {
|
|
|
871
889
|
// encodeShortString('l1_handler'),
|
|
872
890
|
};
|
|
873
891
|
var _SupportedRpcVersion = {
|
|
874
|
-
0.7: "0.7",
|
|
875
|
-
0.8: "0.8",
|
|
876
|
-
|
|
877
|
-
|
|
892
|
+
"0.7.1": "0.7.1",
|
|
893
|
+
"0.8.1": "0.8.1",
|
|
894
|
+
v0_7_1: "0.7.1",
|
|
895
|
+
v0_8_1: "0.8.1"
|
|
878
896
|
};
|
|
879
897
|
var DEFAULT_GLOBAL_CONFIG = {
|
|
880
898
|
legacyMode: false,
|
|
881
|
-
rpcVersion: "0.8",
|
|
899
|
+
rpcVersion: "0.8.1",
|
|
882
900
|
transactionVersion: ETransactionVersion4.V3,
|
|
883
901
|
logLevel: "INFO",
|
|
884
902
|
feeMarginPercentage: {
|
|
@@ -897,7 +915,9 @@ var starknet = (() => {
|
|
|
897
915
|
}
|
|
898
916
|
},
|
|
899
917
|
maxFee: 50
|
|
900
|
-
}
|
|
918
|
+
},
|
|
919
|
+
fetch: void 0,
|
|
920
|
+
websocket: void 0
|
|
901
921
|
};
|
|
902
922
|
var RPC_DEFAULT_NODES = {
|
|
903
923
|
SN_MAIN: [
|
|
@@ -909,215 +929,554 @@ var starknet = (() => {
|
|
|
909
929
|
`https://free-rpc.nethermind.io/sepolia-juno/`
|
|
910
930
|
]
|
|
911
931
|
};
|
|
932
|
+
var PAYMASTER_RPC_NODES = {
|
|
933
|
+
SN_MAIN: [`https://starknet.paymaster.avnu.fi`],
|
|
934
|
+
SN_SEPOLIA: [`https://sepolia.paymaster.avnu.fi`]
|
|
935
|
+
};
|
|
912
936
|
var SYSTEM_MESSAGES = {
|
|
913
937
|
legacyTxWarningMessage: "You are using a deprecated transaction version (V0,V1,V2)!\nUpdate to the latest V3 transactions!",
|
|
914
938
|
legacyTxRPC08Message: "RPC 0.8 do not support legacy transactions",
|
|
915
|
-
SWOldV3: "RPC 0.7 V3 tx (improper resource bounds) not supported in RPC 0.8"
|
|
939
|
+
SWOldV3: "RPC 0.7 V3 tx (improper resource bounds) not supported in RPC 0.8",
|
|
940
|
+
channelVersionMismatch: "Channel specification version is not compatible with the connected node Specification Version",
|
|
941
|
+
unsupportedSpecVersion: "The connected node specification version is not supported by this library"
|
|
916
942
|
};
|
|
917
943
|
|
|
918
|
-
// src/
|
|
919
|
-
var
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
// src/utils/json.ts
|
|
925
|
-
var json_exports = {};
|
|
926
|
-
__export(json_exports, {
|
|
927
|
-
parse: () => parse2,
|
|
928
|
-
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
929
|
-
stringify: () => stringify2
|
|
930
|
-
});
|
|
931
|
-
|
|
932
|
-
// node_modules/lossless-json/lib/esm/utils.js
|
|
933
|
-
function isInteger(value) {
|
|
934
|
-
return INTEGER_REGEX.test(value);
|
|
935
|
-
}
|
|
936
|
-
var INTEGER_REGEX = /^-?[0-9]+$/;
|
|
937
|
-
function isNumber(value) {
|
|
938
|
-
return NUMBER_REGEX.test(value);
|
|
939
|
-
}
|
|
940
|
-
var NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
941
|
-
function isSafeNumber(value, config3) {
|
|
942
|
-
const num = Number.parseFloat(value);
|
|
943
|
-
const str = String(num);
|
|
944
|
-
const v = extractSignificantDigits(value);
|
|
945
|
-
const s = extractSignificantDigits(str);
|
|
946
|
-
if (v === s) {
|
|
947
|
-
return true;
|
|
944
|
+
// src/global/config.ts
|
|
945
|
+
var Configuration = class _Configuration {
|
|
946
|
+
static instance;
|
|
947
|
+
config;
|
|
948
|
+
constructor() {
|
|
949
|
+
this.initialize();
|
|
948
950
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
951
|
+
initialize() {
|
|
952
|
+
this.config = { ...DEFAULT_GLOBAL_CONFIG };
|
|
953
|
+
}
|
|
954
|
+
static getInstance() {
|
|
955
|
+
if (!_Configuration.instance) {
|
|
956
|
+
_Configuration.instance = new _Configuration();
|
|
953
957
|
}
|
|
958
|
+
return _Configuration.instance;
|
|
954
959
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
var UnsafeNumberReason = /* @__PURE__ */ function(UnsafeNumberReason2) {
|
|
958
|
-
UnsafeNumberReason2["underflow"] = "underflow";
|
|
959
|
-
UnsafeNumberReason2["overflow"] = "overflow";
|
|
960
|
-
UnsafeNumberReason2["truncate_integer"] = "truncate_integer";
|
|
961
|
-
UnsafeNumberReason2["truncate_float"] = "truncate_float";
|
|
962
|
-
return UnsafeNumberReason2;
|
|
963
|
-
}({});
|
|
964
|
-
function getUnsafeNumberReason(value) {
|
|
965
|
-
if (isSafeNumber(value, {
|
|
966
|
-
approx: false
|
|
967
|
-
})) {
|
|
968
|
-
return void 0;
|
|
960
|
+
get(key, defaultValue) {
|
|
961
|
+
return this.config[key] ?? defaultValue;
|
|
969
962
|
}
|
|
970
|
-
|
|
971
|
-
|
|
963
|
+
set(key, value) {
|
|
964
|
+
this.config[key] = value;
|
|
972
965
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
966
|
+
update(configData) {
|
|
967
|
+
this.config = {
|
|
968
|
+
...this.config,
|
|
969
|
+
...configData
|
|
970
|
+
};
|
|
976
971
|
}
|
|
977
|
-
|
|
978
|
-
return
|
|
972
|
+
getAll() {
|
|
973
|
+
return { ...this.config };
|
|
979
974
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
function extractSignificantDigits(value) {
|
|
983
|
-
return value.replace(EXPONENTIAL_PART_REGEX, "").replace(DOT_REGEX, "").replace(TRAILING_ZEROS_REGEX, "").replace(LEADING_MINUS_AND_ZEROS_REGEX, "");
|
|
984
|
-
}
|
|
985
|
-
var EXPONENTIAL_PART_REGEX = /[eE][+-]?\d+$/;
|
|
986
|
-
var LEADING_MINUS_AND_ZEROS_REGEX = /^-?(0*)?/;
|
|
987
|
-
var DOT_REGEX = /\./;
|
|
988
|
-
var TRAILING_ZEROS_REGEX = /0+$/;
|
|
989
|
-
|
|
990
|
-
// node_modules/lossless-json/lib/esm/LosslessNumber.js
|
|
991
|
-
var LosslessNumber = class {
|
|
992
|
-
// numeric value as string
|
|
993
|
-
// type information
|
|
994
|
-
isLosslessNumber = true;
|
|
995
|
-
constructor(value) {
|
|
996
|
-
if (!isNumber(value)) {
|
|
997
|
-
throw new Error(`Invalid number (value: "${value}")`);
|
|
998
|
-
}
|
|
999
|
-
this.value = value;
|
|
975
|
+
reset() {
|
|
976
|
+
this.initialize();
|
|
1000
977
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
*
|
|
1004
|
-
* - a number is returned for safe numbers and decimal values that only lose some insignificant digits
|
|
1005
|
-
* - a bigint is returned for big integer numbers
|
|
1006
|
-
* - an Error is thrown for values that will overflow or underflow
|
|
1007
|
-
*
|
|
1008
|
-
* Note that you can implement your own strategy for conversion by just getting the value as string
|
|
1009
|
-
* via .toString(), and using util functions like isInteger, isSafeNumber, getUnsafeNumberReason,
|
|
1010
|
-
* and toSafeNumberOrThrow to convert it to a numeric value.
|
|
1011
|
-
*/
|
|
1012
|
-
valueOf() {
|
|
1013
|
-
const unsafeReason = getUnsafeNumberReason(this.value);
|
|
1014
|
-
if (unsafeReason === void 0 || unsafeReason === UnsafeNumberReason.truncate_float) {
|
|
1015
|
-
return Number.parseFloat(this.value);
|
|
1016
|
-
}
|
|
1017
|
-
if (isInteger(this.value)) {
|
|
1018
|
-
return BigInt(this.value);
|
|
1019
|
-
}
|
|
1020
|
-
throw new Error(`Cannot safely convert to number: the value '${this.value}' would ${unsafeReason} and become ${Number.parseFloat(this.value)}`);
|
|
978
|
+
delete(key) {
|
|
979
|
+
delete this.config[key];
|
|
1021
980
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
*/
|
|
1025
|
-
toString() {
|
|
1026
|
-
return this.value;
|
|
981
|
+
hasKey(key) {
|
|
982
|
+
return key in this.config;
|
|
1027
983
|
}
|
|
1028
|
-
// Note: we do NOT implement a .toJSON() method, and you should not implement
|
|
1029
|
-
// or use that, it cannot safely turn the numeric value in the string into
|
|
1030
|
-
// stringified JSON since it has to be parsed into a number first.
|
|
1031
984
|
};
|
|
1032
|
-
|
|
1033
|
-
return value && typeof value === "object" && value.isLosslessNumber === true || false;
|
|
1034
|
-
}
|
|
985
|
+
var config = Configuration.getInstance();
|
|
1035
986
|
|
|
1036
|
-
//
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
987
|
+
// src/global/logger.type.ts
|
|
988
|
+
var LogLevelIndex = {
|
|
989
|
+
DEBUG: 5,
|
|
990
|
+
INFO: 4,
|
|
991
|
+
WARN: 3,
|
|
992
|
+
ERROR: 2,
|
|
993
|
+
FATAL: 1,
|
|
994
|
+
OFF: 0
|
|
995
|
+
};
|
|
1043
996
|
|
|
1044
|
-
//
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
function reviveValue(context, key, value, reviver) {
|
|
1051
|
-
if (Array.isArray(value)) {
|
|
1052
|
-
return reviver.call(context, key, reviveArray(value, reviver));
|
|
1053
|
-
}
|
|
1054
|
-
if (value && typeof value === "object" && !isLosslessNumber(value)) {
|
|
1055
|
-
return reviver.call(context, key, reviveObject(value, reviver));
|
|
997
|
+
// src/global/logger.ts
|
|
998
|
+
var Logger = class _Logger {
|
|
999
|
+
static instance;
|
|
1000
|
+
config;
|
|
1001
|
+
constructor() {
|
|
1002
|
+
this.config = config;
|
|
1056
1003
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
for (const key of Object.keys(object)) {
|
|
1061
|
-
const value = reviveValue(object, key, object[key], reviver);
|
|
1062
|
-
if (value !== void 0) {
|
|
1063
|
-
object[key] = value;
|
|
1064
|
-
} else {
|
|
1065
|
-
delete object[key];
|
|
1004
|
+
static getInstance() {
|
|
1005
|
+
if (!_Logger.instance) {
|
|
1006
|
+
_Logger.instance = new _Logger();
|
|
1066
1007
|
}
|
|
1008
|
+
return _Logger.instance;
|
|
1067
1009
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
function reviveArray(array, reviver) {
|
|
1071
|
-
for (let i = 0; i < array.length; i++) {
|
|
1072
|
-
array[i] = reviveValue(array, String(i), array[i], reviver);
|
|
1010
|
+
getTimestamp() {
|
|
1011
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1073
1012
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
skipWhitespace();
|
|
1089
|
-
const object = {};
|
|
1090
|
-
let initial = true;
|
|
1091
|
-
while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
|
|
1092
|
-
if (!initial) {
|
|
1093
|
-
eatComma();
|
|
1094
|
-
skipWhitespace();
|
|
1095
|
-
} else {
|
|
1096
|
-
initial = false;
|
|
1097
|
-
}
|
|
1098
|
-
const start = i;
|
|
1099
|
-
const key = parseString();
|
|
1100
|
-
if (key === void 0) {
|
|
1101
|
-
throwObjectKeyExpected();
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
|
-
skipWhitespace();
|
|
1105
|
-
eatColon();
|
|
1106
|
-
const value2 = parseValue();
|
|
1107
|
-
if (value2 === void 0) {
|
|
1108
|
-
throwObjectValueExpected();
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
if (Object.prototype.hasOwnProperty.call(object, key) && !isDeepEqual(value2, object[key])) {
|
|
1112
|
-
throwDuplicateKey(key, start + 1);
|
|
1113
|
-
}
|
|
1114
|
-
object[key] = value2;
|
|
1115
|
-
}
|
|
1116
|
-
if (text.charCodeAt(i) !== codeClosingBrace) {
|
|
1117
|
-
throwObjectKeyOrEndExpected();
|
|
1013
|
+
shouldLog(messageLevel) {
|
|
1014
|
+
const configLevel = this.config.get("logLevel", "INFO");
|
|
1015
|
+
return messageLevel <= LogLevelIndex[configLevel];
|
|
1016
|
+
}
|
|
1017
|
+
formatMessage(logMessage) {
|
|
1018
|
+
const { level, message, timestamp, data } = logMessage;
|
|
1019
|
+
let formattedMessage = `[${timestamp}] ${level}: ${message}`;
|
|
1020
|
+
if (data) {
|
|
1021
|
+
try {
|
|
1022
|
+
formattedMessage += `
|
|
1023
|
+
${JSON.stringify(data, null, 2)}`;
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
formattedMessage += `
|
|
1026
|
+
[JSON.stringify Error/Circular]: ${error}`;
|
|
1118
1027
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1028
|
+
}
|
|
1029
|
+
return formattedMessage;
|
|
1030
|
+
}
|
|
1031
|
+
log(level, message, data) {
|
|
1032
|
+
if (!this.shouldLog(LogLevelIndex[level])) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const logMessage = {
|
|
1036
|
+
level,
|
|
1037
|
+
message,
|
|
1038
|
+
timestamp: this.getTimestamp(),
|
|
1039
|
+
data
|
|
1040
|
+
};
|
|
1041
|
+
const formattedMessage = this.formatMessage(logMessage);
|
|
1042
|
+
switch (level) {
|
|
1043
|
+
case "DEBUG":
|
|
1044
|
+
console.debug(formattedMessage);
|
|
1045
|
+
break;
|
|
1046
|
+
case "INFO":
|
|
1047
|
+
console.info(formattedMessage);
|
|
1048
|
+
break;
|
|
1049
|
+
case "WARN":
|
|
1050
|
+
console.warn(formattedMessage);
|
|
1051
|
+
break;
|
|
1052
|
+
case "ERROR":
|
|
1053
|
+
case "FATAL":
|
|
1054
|
+
console.error(formattedMessage);
|
|
1055
|
+
break;
|
|
1056
|
+
case "OFF":
|
|
1057
|
+
break;
|
|
1058
|
+
default:
|
|
1059
|
+
console.log(formattedMessage);
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* debug will be displayed when LogLevel level is set to DEBUG(5)
|
|
1065
|
+
*/
|
|
1066
|
+
debug(message, data) {
|
|
1067
|
+
this.log("DEBUG", message, data);
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* info will be displayed when LogLevel level is set to DEBUG(5), INFO(4)
|
|
1071
|
+
*/
|
|
1072
|
+
info(message, data) {
|
|
1073
|
+
this.log("INFO", message, data);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* warn will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3)
|
|
1077
|
+
*/
|
|
1078
|
+
warn(message, data) {
|
|
1079
|
+
this.log("WARN", message, data);
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* error will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2)
|
|
1083
|
+
*/
|
|
1084
|
+
error(message, data) {
|
|
1085
|
+
this.log("ERROR", message, data);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* fatal will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2), FATAL(1)
|
|
1089
|
+
*/
|
|
1090
|
+
fatal(message, data) {
|
|
1091
|
+
this.log("FATAL", message, data);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Set the logging level you would like system to display
|
|
1095
|
+
* * 5 DEBUG - show all logs
|
|
1096
|
+
* * 4 INFO
|
|
1097
|
+
* * 3 WARN
|
|
1098
|
+
* * 2 ERROR
|
|
1099
|
+
* * 1 FATAL
|
|
1100
|
+
* * 0 OFF - disable logs
|
|
1101
|
+
*/
|
|
1102
|
+
setLogLevel(level) {
|
|
1103
|
+
this.config.set("logLevel", level);
|
|
1104
|
+
}
|
|
1105
|
+
getLogLevel() {
|
|
1106
|
+
return this.config.get("logLevel", "INFO");
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
*
|
|
1110
|
+
* @returns logs levels displayed on the configured LogLevel
|
|
1111
|
+
*/
|
|
1112
|
+
getEnabledLogLevels() {
|
|
1113
|
+
return Object.keys(LogLevelIndex).filter((s) => {
|
|
1114
|
+
return this.shouldLog(LogLevelIndex[s]) && s !== "OFF";
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
var logger = Logger.getInstance();
|
|
1119
|
+
|
|
1120
|
+
// src/channel/rpc_0_7_1.ts
|
|
1121
|
+
var rpc_0_7_1_exports = {};
|
|
1122
|
+
__export(rpc_0_7_1_exports, {
|
|
1123
|
+
RpcChannel: () => RpcChannel
|
|
1124
|
+
});
|
|
1125
|
+
|
|
1126
|
+
// src/types/index.ts
|
|
1127
|
+
var types_exports = {};
|
|
1128
|
+
__export(types_exports, {
|
|
1129
|
+
BlockStatus: () => BlockStatus,
|
|
1130
|
+
BlockTag: () => BlockTag,
|
|
1131
|
+
EDAMode: () => EDAMode3,
|
|
1132
|
+
EDataAvailabilityMode: () => EDataAvailabilityMode3,
|
|
1133
|
+
ETH_ADDRESS: () => ETH_ADDRESS,
|
|
1134
|
+
ETransactionExecutionStatus: () => ETransactionExecutionStatus3,
|
|
1135
|
+
ETransactionStatus: () => ETransactionStatus3,
|
|
1136
|
+
ETransactionVersion: () => ETransactionVersion5,
|
|
1137
|
+
ETransactionVersion2: () => ETransactionVersion23,
|
|
1138
|
+
ETransactionVersion3: () => ETransactionVersion33,
|
|
1139
|
+
EntryPointType: () => EntryPointType,
|
|
1140
|
+
Literal: () => Literal,
|
|
1141
|
+
NON_ZERO_PREFIX: () => NON_ZERO_PREFIX,
|
|
1142
|
+
OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
|
|
1143
|
+
OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
|
|
1144
|
+
OutsideExecutionVersion: () => OutsideExecutionVersion,
|
|
1145
|
+
RPC: () => api_exports3,
|
|
1146
|
+
TransactionExecutionStatus: () => TransactionExecutionStatus,
|
|
1147
|
+
TransactionFinalityStatus: () => TransactionFinalityStatus,
|
|
1148
|
+
TransactionType: () => TransactionType,
|
|
1149
|
+
TypedDataRevision: () => TypedDataRevision,
|
|
1150
|
+
Uint: () => Uint,
|
|
1151
|
+
ValidateType: () => ValidateType,
|
|
1152
|
+
isRPC08_FeeEstimate: () => isRPC08_FeeEstimate,
|
|
1153
|
+
isRPC08_ResourceBounds: () => isRPC08_ResourceBounds
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
// src/types/lib/contract/index.ts
|
|
1157
|
+
var EntryPointType = {
|
|
1158
|
+
EXTERNAL: "EXTERNAL",
|
|
1159
|
+
L1_HANDLER: "L1_HANDLER",
|
|
1160
|
+
CONSTRUCTOR: "CONSTRUCTOR"
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/types/lib/index.ts
|
|
1164
|
+
var TransactionType = {
|
|
1165
|
+
DECLARE: "DECLARE",
|
|
1166
|
+
DEPLOY: "DEPLOY",
|
|
1167
|
+
DEPLOY_ACCOUNT: "DEPLOY_ACCOUNT",
|
|
1168
|
+
INVOKE: "INVOKE_FUNCTION"
|
|
1169
|
+
};
|
|
1170
|
+
var TransactionFinalityStatus = {
|
|
1171
|
+
NOT_RECEIVED: "NOT_RECEIVED",
|
|
1172
|
+
RECEIVED: "RECEIVED",
|
|
1173
|
+
ACCEPTED_ON_L2: "ACCEPTED_ON_L2",
|
|
1174
|
+
ACCEPTED_ON_L1: "ACCEPTED_ON_L1"
|
|
1175
|
+
};
|
|
1176
|
+
var TransactionExecutionStatus = {
|
|
1177
|
+
REJECTED: "REJECTED",
|
|
1178
|
+
REVERTED: "REVERTED",
|
|
1179
|
+
SUCCEEDED: "SUCCEEDED"
|
|
1180
|
+
};
|
|
1181
|
+
var BlockStatus = {
|
|
1182
|
+
PENDING: "PENDING",
|
|
1183
|
+
ACCEPTED_ON_L1: "ACCEPTED_ON_L1",
|
|
1184
|
+
ACCEPTED_ON_L2: "ACCEPTED_ON_L2",
|
|
1185
|
+
REJECTED: "REJECTED"
|
|
1186
|
+
};
|
|
1187
|
+
var BlockTag = {
|
|
1188
|
+
PENDING: "pending",
|
|
1189
|
+
LATEST: "latest"
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
// src/provider/types/spec.type.ts
|
|
1193
|
+
var { ETransactionVersion: ETransactionVersion5 } = esm_exports2;
|
|
1194
|
+
var { ETransactionVersion2: ETransactionVersion23 } = esm_exports2;
|
|
1195
|
+
var { ETransactionVersion3: ETransactionVersion33 } = esm_exports2;
|
|
1196
|
+
var { EDataAvailabilityMode: EDataAvailabilityMode3 } = esm_exports2;
|
|
1197
|
+
var { EDAMode: EDAMode3 } = esm_exports2;
|
|
1198
|
+
function isRPC08_FeeEstimate(entry) {
|
|
1199
|
+
return "l1_data_gas_consumed" in entry;
|
|
1200
|
+
}
|
|
1201
|
+
function isRPC08_ResourceBounds(entry) {
|
|
1202
|
+
return "l1_data_gas" in entry;
|
|
1203
|
+
}
|
|
1204
|
+
var { ETransactionStatus: ETransactionStatus3 } = esm_exports2;
|
|
1205
|
+
var { ETransactionExecutionStatus: ETransactionExecutionStatus3 } = esm_exports2;
|
|
1206
|
+
|
|
1207
|
+
// src/types/calldata.ts
|
|
1208
|
+
var ValidateType = {
|
|
1209
|
+
DEPLOY: "DEPLOY",
|
|
1210
|
+
CALL: "CALL",
|
|
1211
|
+
INVOKE: "INVOKE"
|
|
1212
|
+
};
|
|
1213
|
+
var Uint = {
|
|
1214
|
+
u8: "core::integer::u8",
|
|
1215
|
+
u16: "core::integer::u16",
|
|
1216
|
+
u32: "core::integer::u32",
|
|
1217
|
+
u64: "core::integer::u64",
|
|
1218
|
+
u128: "core::integer::u128",
|
|
1219
|
+
u256: "core::integer::u256",
|
|
1220
|
+
// This one is struct
|
|
1221
|
+
u512: "core::integer::u512"
|
|
1222
|
+
// This one is struct
|
|
1223
|
+
};
|
|
1224
|
+
var Literal = {
|
|
1225
|
+
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
1226
|
+
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
1227
|
+
Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
|
|
1228
|
+
U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
|
|
1229
|
+
};
|
|
1230
|
+
var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
|
|
1231
|
+
var NON_ZERO_PREFIX = "core::zeroable::NonZero::";
|
|
1232
|
+
|
|
1233
|
+
// src/types/outsideExecution.ts
|
|
1234
|
+
var OutsideExecutionTypesV1 = {
|
|
1235
|
+
StarkNetDomain: [
|
|
1236
|
+
{ name: "name", type: "felt" },
|
|
1237
|
+
{ name: "version", type: "felt" },
|
|
1238
|
+
{ name: "chainId", type: "felt" }
|
|
1239
|
+
],
|
|
1240
|
+
OutsideExecution: [
|
|
1241
|
+
{ name: "caller", type: "felt" },
|
|
1242
|
+
{ name: "nonce", type: "felt" },
|
|
1243
|
+
{ name: "execute_after", type: "felt" },
|
|
1244
|
+
{ name: "execute_before", type: "felt" },
|
|
1245
|
+
{ name: "calls_len", type: "felt" },
|
|
1246
|
+
{ name: "calls", type: "OutsideCall*" }
|
|
1247
|
+
],
|
|
1248
|
+
OutsideCall: [
|
|
1249
|
+
{ name: "to", type: "felt" },
|
|
1250
|
+
{ name: "selector", type: "felt" },
|
|
1251
|
+
{ name: "calldata_len", type: "felt" },
|
|
1252
|
+
{ name: "calldata", type: "felt*" }
|
|
1253
|
+
]
|
|
1254
|
+
};
|
|
1255
|
+
var OutsideExecutionTypesV2 = {
|
|
1256
|
+
StarknetDomain: [
|
|
1257
|
+
// SNIP-12 revision 1 is used, so should be "StarknetDomain", not "StarkNetDomain"
|
|
1258
|
+
{ name: "name", type: "shortstring" },
|
|
1259
|
+
{ name: "version", type: "shortstring" },
|
|
1260
|
+
// set to 2 in v2
|
|
1261
|
+
{ name: "chainId", type: "shortstring" },
|
|
1262
|
+
{ name: "revision", type: "shortstring" }
|
|
1263
|
+
],
|
|
1264
|
+
OutsideExecution: [
|
|
1265
|
+
{ name: "Caller", type: "ContractAddress" },
|
|
1266
|
+
{ name: "Nonce", type: "felt" },
|
|
1267
|
+
{ name: "Execute After", type: "u128" },
|
|
1268
|
+
{ name: "Execute Before", type: "u128" },
|
|
1269
|
+
{ name: "Calls", type: "Call*" }
|
|
1270
|
+
],
|
|
1271
|
+
Call: [
|
|
1272
|
+
{ name: "To", type: "ContractAddress" },
|
|
1273
|
+
{ name: "Selector", type: "selector" },
|
|
1274
|
+
{ name: "Calldata", type: "felt*" }
|
|
1275
|
+
]
|
|
1276
|
+
};
|
|
1277
|
+
var OutsideExecutionVersion = {
|
|
1278
|
+
UNSUPPORTED: "0",
|
|
1279
|
+
V1: "1",
|
|
1280
|
+
V2: "2"
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// src/utils/json.ts
|
|
1284
|
+
var json_exports = {};
|
|
1285
|
+
__export(json_exports, {
|
|
1286
|
+
parse: () => parse2,
|
|
1287
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
1288
|
+
stringify: () => stringify2
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
// node_modules/lossless-json/lib/esm/utils.js
|
|
1292
|
+
function isInteger(value) {
|
|
1293
|
+
return INTEGER_REGEX.test(value);
|
|
1294
|
+
}
|
|
1295
|
+
var INTEGER_REGEX = /^-?[0-9]+$/;
|
|
1296
|
+
function isNumber(value) {
|
|
1297
|
+
return NUMBER_REGEX.test(value);
|
|
1298
|
+
}
|
|
1299
|
+
var NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
1300
|
+
function isSafeNumber(value, config3) {
|
|
1301
|
+
const num = Number.parseFloat(value);
|
|
1302
|
+
const str = String(num);
|
|
1303
|
+
const v = extractSignificantDigits(value);
|
|
1304
|
+
const s = extractSignificantDigits(str);
|
|
1305
|
+
if (v === s) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
if (config3?.approx === true) {
|
|
1309
|
+
const requiredDigits = 14;
|
|
1310
|
+
if (!isInteger(value) && s.length >= requiredDigits && v.startsWith(s.substring(0, requiredDigits))) {
|
|
1311
|
+
return true;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
var UnsafeNumberReason = /* @__PURE__ */ function(UnsafeNumberReason2) {
|
|
1317
|
+
UnsafeNumberReason2["underflow"] = "underflow";
|
|
1318
|
+
UnsafeNumberReason2["overflow"] = "overflow";
|
|
1319
|
+
UnsafeNumberReason2["truncate_integer"] = "truncate_integer";
|
|
1320
|
+
UnsafeNumberReason2["truncate_float"] = "truncate_float";
|
|
1321
|
+
return UnsafeNumberReason2;
|
|
1322
|
+
}({});
|
|
1323
|
+
function getUnsafeNumberReason(value) {
|
|
1324
|
+
if (isSafeNumber(value, {
|
|
1325
|
+
approx: false
|
|
1326
|
+
})) {
|
|
1327
|
+
return void 0;
|
|
1328
|
+
}
|
|
1329
|
+
if (isInteger(value)) {
|
|
1330
|
+
return UnsafeNumberReason.truncate_integer;
|
|
1331
|
+
}
|
|
1332
|
+
const num = Number.parseFloat(value);
|
|
1333
|
+
if (!Number.isFinite(num)) {
|
|
1334
|
+
return UnsafeNumberReason.overflow;
|
|
1335
|
+
}
|
|
1336
|
+
if (num === 0) {
|
|
1337
|
+
return UnsafeNumberReason.underflow;
|
|
1338
|
+
}
|
|
1339
|
+
return UnsafeNumberReason.truncate_float;
|
|
1340
|
+
}
|
|
1341
|
+
function extractSignificantDigits(value) {
|
|
1342
|
+
return value.replace(EXPONENTIAL_PART_REGEX, "").replace(DOT_REGEX, "").replace(TRAILING_ZEROS_REGEX, "").replace(LEADING_MINUS_AND_ZEROS_REGEX, "");
|
|
1343
|
+
}
|
|
1344
|
+
var EXPONENTIAL_PART_REGEX = /[eE][+-]?\d+$/;
|
|
1345
|
+
var LEADING_MINUS_AND_ZEROS_REGEX = /^-?(0*)?/;
|
|
1346
|
+
var DOT_REGEX = /\./;
|
|
1347
|
+
var TRAILING_ZEROS_REGEX = /0+$/;
|
|
1348
|
+
|
|
1349
|
+
// node_modules/lossless-json/lib/esm/LosslessNumber.js
|
|
1350
|
+
var LosslessNumber = class {
|
|
1351
|
+
// numeric value as string
|
|
1352
|
+
// type information
|
|
1353
|
+
isLosslessNumber = true;
|
|
1354
|
+
constructor(value) {
|
|
1355
|
+
if (!isNumber(value)) {
|
|
1356
|
+
throw new Error(`Invalid number (value: "${value}")`);
|
|
1357
|
+
}
|
|
1358
|
+
this.value = value;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Get the value of the LosslessNumber as number or bigint.
|
|
1362
|
+
*
|
|
1363
|
+
* - a number is returned for safe numbers and decimal values that only lose some insignificant digits
|
|
1364
|
+
* - a bigint is returned for big integer numbers
|
|
1365
|
+
* - an Error is thrown for values that will overflow or underflow
|
|
1366
|
+
*
|
|
1367
|
+
* Note that you can implement your own strategy for conversion by just getting the value as string
|
|
1368
|
+
* via .toString(), and using util functions like isInteger, isSafeNumber, getUnsafeNumberReason,
|
|
1369
|
+
* and toSafeNumberOrThrow to convert it to a numeric value.
|
|
1370
|
+
*/
|
|
1371
|
+
valueOf() {
|
|
1372
|
+
const unsafeReason = getUnsafeNumberReason(this.value);
|
|
1373
|
+
if (unsafeReason === void 0 || unsafeReason === UnsafeNumberReason.truncate_float) {
|
|
1374
|
+
return Number.parseFloat(this.value);
|
|
1375
|
+
}
|
|
1376
|
+
if (isInteger(this.value)) {
|
|
1377
|
+
return BigInt(this.value);
|
|
1378
|
+
}
|
|
1379
|
+
throw new Error(`Cannot safely convert to number: the value '${this.value}' would ${unsafeReason} and become ${Number.parseFloat(this.value)}`);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Get the value of the LosslessNumber as string.
|
|
1383
|
+
*/
|
|
1384
|
+
toString() {
|
|
1385
|
+
return this.value;
|
|
1386
|
+
}
|
|
1387
|
+
// Note: we do NOT implement a .toJSON() method, and you should not implement
|
|
1388
|
+
// or use that, it cannot safely turn the numeric value in the string into
|
|
1389
|
+
// stringified JSON since it has to be parsed into a number first.
|
|
1390
|
+
};
|
|
1391
|
+
function isLosslessNumber(value) {
|
|
1392
|
+
return value && typeof value === "object" && value.isLosslessNumber === true || false;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// node_modules/lossless-json/lib/esm/numberParsers.js
|
|
1396
|
+
function parseLosslessNumber(value) {
|
|
1397
|
+
return new LosslessNumber(value);
|
|
1398
|
+
}
|
|
1399
|
+
function parseNumberAndBigInt(value) {
|
|
1400
|
+
return isInteger(value) ? BigInt(value) : Number.parseFloat(value);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// node_modules/lossless-json/lib/esm/revive.js
|
|
1404
|
+
function revive(json, reviver) {
|
|
1405
|
+
return reviveValue({
|
|
1406
|
+
"": json
|
|
1407
|
+
}, "", json, reviver);
|
|
1408
|
+
}
|
|
1409
|
+
function reviveValue(context, key, value, reviver) {
|
|
1410
|
+
if (Array.isArray(value)) {
|
|
1411
|
+
return reviver.call(context, key, reviveArray(value, reviver));
|
|
1412
|
+
}
|
|
1413
|
+
if (value && typeof value === "object" && !isLosslessNumber(value)) {
|
|
1414
|
+
return reviver.call(context, key, reviveObject(value, reviver));
|
|
1415
|
+
}
|
|
1416
|
+
return reviver.call(context, key, value);
|
|
1417
|
+
}
|
|
1418
|
+
function reviveObject(object, reviver) {
|
|
1419
|
+
for (const key of Object.keys(object)) {
|
|
1420
|
+
const value = reviveValue(object, key, object[key], reviver);
|
|
1421
|
+
if (value !== void 0) {
|
|
1422
|
+
object[key] = value;
|
|
1423
|
+
} else {
|
|
1424
|
+
delete object[key];
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return object;
|
|
1428
|
+
}
|
|
1429
|
+
function reviveArray(array, reviver) {
|
|
1430
|
+
for (let i = 0; i < array.length; i++) {
|
|
1431
|
+
array[i] = reviveValue(array, String(i), array[i], reviver);
|
|
1432
|
+
}
|
|
1433
|
+
return array;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// node_modules/lossless-json/lib/esm/parse.js
|
|
1437
|
+
function parse(text, reviver) {
|
|
1438
|
+
let parseNumber = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : parseLosslessNumber;
|
|
1439
|
+
let i = 0;
|
|
1440
|
+
const value = parseValue();
|
|
1441
|
+
expectValue(value);
|
|
1442
|
+
expectEndOfInput();
|
|
1443
|
+
return reviver ? revive(value, reviver) : value;
|
|
1444
|
+
function parseObject() {
|
|
1445
|
+
if (text.charCodeAt(i) === codeOpeningBrace) {
|
|
1446
|
+
i++;
|
|
1447
|
+
skipWhitespace();
|
|
1448
|
+
const object = {};
|
|
1449
|
+
let initial = true;
|
|
1450
|
+
while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
|
|
1451
|
+
if (!initial) {
|
|
1452
|
+
eatComma();
|
|
1453
|
+
skipWhitespace();
|
|
1454
|
+
} else {
|
|
1455
|
+
initial = false;
|
|
1456
|
+
}
|
|
1457
|
+
const start = i;
|
|
1458
|
+
const key = parseString();
|
|
1459
|
+
if (key === void 0) {
|
|
1460
|
+
throwObjectKeyExpected();
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
skipWhitespace();
|
|
1464
|
+
eatColon();
|
|
1465
|
+
const value2 = parseValue();
|
|
1466
|
+
if (value2 === void 0) {
|
|
1467
|
+
throwObjectValueExpected();
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && !isDeepEqual(value2, object[key])) {
|
|
1471
|
+
throwDuplicateKey(key, start + 1);
|
|
1472
|
+
}
|
|
1473
|
+
object[key] = value2;
|
|
1474
|
+
}
|
|
1475
|
+
if (text.charCodeAt(i) !== codeClosingBrace) {
|
|
1476
|
+
throwObjectKeyOrEndExpected();
|
|
1477
|
+
}
|
|
1478
|
+
i++;
|
|
1479
|
+
return object;
|
|
1121
1480
|
}
|
|
1122
1481
|
}
|
|
1123
1482
|
function parseArray() {
|
|
@@ -1452,277 +1811,35 @@ ${indent}]` : "]";
|
|
|
1452
1811
|
const keyStr = JSON.stringify(key);
|
|
1453
1812
|
str += resolvedSpace ? `${childIndent + keyStr}: ` : `${keyStr}:`;
|
|
1454
1813
|
str += stringifyValue(value2, childIndent);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
str += resolvedSpace ? `
|
|
1458
|
-
${indent}}` : "}";
|
|
1459
|
-
return str;
|
|
1460
|
-
}
|
|
1461
|
-
function includeProperty(_key, value2) {
|
|
1462
|
-
return typeof value2 !== "undefined" && typeof value2 !== "function" && typeof value2 !== "symbol";
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
function resolveSpace(space) {
|
|
1466
|
-
if (typeof space === "number") {
|
|
1467
|
-
return " ".repeat(space);
|
|
1468
|
-
}
|
|
1469
|
-
if (typeof space === "string" && space !== "") {
|
|
1470
|
-
return space;
|
|
1471
|
-
}
|
|
1472
|
-
return void 0;
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
// src/utils/json.ts
|
|
1476
|
-
var parseIntAsNumberOrBigInt = (str) => {
|
|
1477
|
-
if (!isInteger(str)) return parseFloat(str);
|
|
1478
|
-
const num = parseInt(str, 10);
|
|
1479
|
-
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
1480
|
-
};
|
|
1481
|
-
var parse2 = (str) => parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
1482
|
-
var parseAlwaysAsBig = (str) => parse(String(str), void 0, parseNumberAndBigInt);
|
|
1483
|
-
var stringify2 = (value, replacer, space, numberStringifiers) => stringify(value, replacer, space, numberStringifiers);
|
|
1484
|
-
|
|
1485
|
-
// src/utils/errors/rpc.ts
|
|
1486
|
-
var errorCodes = {
|
|
1487
|
-
FAILED_TO_RECEIVE_TXN: 1,
|
|
1488
|
-
NO_TRACE_AVAILABLE: 10,
|
|
1489
|
-
CONTRACT_NOT_FOUND: 20,
|
|
1490
|
-
ENTRYPOINT_NOT_FOUND: 21,
|
|
1491
|
-
BLOCK_NOT_FOUND: 24,
|
|
1492
|
-
INVALID_TXN_INDEX: 27,
|
|
1493
|
-
CLASS_HASH_NOT_FOUND: 28,
|
|
1494
|
-
TXN_HASH_NOT_FOUND: 29,
|
|
1495
|
-
PAGE_SIZE_TOO_BIG: 31,
|
|
1496
|
-
NO_BLOCKS: 32,
|
|
1497
|
-
INVALID_CONTINUATION_TOKEN: 33,
|
|
1498
|
-
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
1499
|
-
CONTRACT_ERROR: 40,
|
|
1500
|
-
TRANSACTION_EXECUTION_ERROR: 41,
|
|
1501
|
-
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
1502
|
-
CLASS_ALREADY_DECLARED: 51,
|
|
1503
|
-
INVALID_TRANSACTION_NONCE: 52,
|
|
1504
|
-
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
1505
|
-
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
1506
|
-
VALIDATION_FAILURE: 55,
|
|
1507
|
-
COMPILATION_FAILED: 56,
|
|
1508
|
-
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
1509
|
-
NON_ACCOUNT: 58,
|
|
1510
|
-
DUPLICATE_TX: 59,
|
|
1511
|
-
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
1512
|
-
UNSUPPORTED_TX_VERSION: 61,
|
|
1513
|
-
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
1514
|
-
UNEXPECTED_ERROR: 63,
|
|
1515
|
-
INVALID_SUBSCRIPTION_ID: 66,
|
|
1516
|
-
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
1517
|
-
TOO_MANY_BLOCKS_BACK: 68,
|
|
1518
|
-
COMPILATION_ERROR: 100
|
|
1519
|
-
};
|
|
1520
|
-
var rpc_default = errorCodes;
|
|
1521
|
-
|
|
1522
|
-
// src/utils/errors/index.ts
|
|
1523
|
-
function fixStack(target, fn = target.constructor) {
|
|
1524
|
-
const { captureStackTrace } = Error;
|
|
1525
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
1526
|
-
}
|
|
1527
|
-
function fixProto(target, prototype) {
|
|
1528
|
-
const { setPrototypeOf } = Object;
|
|
1529
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
1530
|
-
}
|
|
1531
|
-
var CustomError = class extends Error {
|
|
1532
|
-
name;
|
|
1533
|
-
constructor(message) {
|
|
1534
|
-
super(message);
|
|
1535
|
-
Object.defineProperty(this, "name", {
|
|
1536
|
-
value: new.target.name,
|
|
1537
|
-
enumerable: false,
|
|
1538
|
-
configurable: true
|
|
1539
|
-
});
|
|
1540
|
-
fixProto(this, new.target.prototype);
|
|
1541
|
-
fixStack(this);
|
|
1542
|
-
}
|
|
1543
|
-
};
|
|
1544
|
-
var LibraryError = class extends CustomError {
|
|
1545
|
-
};
|
|
1546
|
-
var RpcError = class extends LibraryError {
|
|
1547
|
-
constructor(baseError, method, params) {
|
|
1548
|
-
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
1549
|
-
|
|
1550
|
-
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
1551
|
-
this.baseError = baseError;
|
|
1552
|
-
this.request = { method, params };
|
|
1553
|
-
}
|
|
1554
|
-
request;
|
|
1555
|
-
get code() {
|
|
1556
|
-
return this.baseError.code;
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
1560
|
-
* @example
|
|
1561
|
-
* ```typescript
|
|
1562
|
-
* SomeError.isType('UNEXPECTED_ERROR');
|
|
1563
|
-
* ```
|
|
1564
|
-
*/
|
|
1565
|
-
isType(typeName) {
|
|
1566
|
-
return rpc_default[typeName] === this.code;
|
|
1567
|
-
}
|
|
1568
|
-
};
|
|
1569
|
-
|
|
1570
|
-
// src/types/index.ts
|
|
1571
|
-
var types_exports = {};
|
|
1572
|
-
__export(types_exports, {
|
|
1573
|
-
BlockStatus: () => BlockStatus,
|
|
1574
|
-
BlockTag: () => BlockTag,
|
|
1575
|
-
EDAMode: () => EDAMode3,
|
|
1576
|
-
EDataAvailabilityMode: () => EDataAvailabilityMode3,
|
|
1577
|
-
ETH_ADDRESS: () => ETH_ADDRESS,
|
|
1578
|
-
ETransactionExecutionStatus: () => ETransactionExecutionStatus3,
|
|
1579
|
-
ETransactionStatus: () => ETransactionStatus3,
|
|
1580
|
-
ETransactionVersion: () => ETransactionVersion5,
|
|
1581
|
-
ETransactionVersion2: () => ETransactionVersion23,
|
|
1582
|
-
ETransactionVersion3: () => ETransactionVersion33,
|
|
1583
|
-
EntryPointType: () => EntryPointType,
|
|
1584
|
-
Literal: () => Literal,
|
|
1585
|
-
NON_ZERO_PREFIX: () => NON_ZERO_PREFIX,
|
|
1586
|
-
OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
|
|
1587
|
-
OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
|
|
1588
|
-
OutsideExecutionVersion: () => OutsideExecutionVersion,
|
|
1589
|
-
RPC: () => api_exports3,
|
|
1590
|
-
TransactionExecutionStatus: () => TransactionExecutionStatus,
|
|
1591
|
-
TransactionFinalityStatus: () => TransactionFinalityStatus,
|
|
1592
|
-
TransactionType: () => TransactionType,
|
|
1593
|
-
TypedDataRevision: () => TypedDataRevision,
|
|
1594
|
-
Uint: () => Uint,
|
|
1595
|
-
ValidateType: () => ValidateType,
|
|
1596
|
-
isRPC08_FeeEstimate: () => isRPC08_FeeEstimate,
|
|
1597
|
-
isRPC08_ResourceBounds: () => isRPC08_ResourceBounds
|
|
1598
|
-
});
|
|
1599
|
-
|
|
1600
|
-
// src/types/lib/contract/index.ts
|
|
1601
|
-
var EntryPointType = {
|
|
1602
|
-
EXTERNAL: "EXTERNAL",
|
|
1603
|
-
L1_HANDLER: "L1_HANDLER",
|
|
1604
|
-
CONSTRUCTOR: "CONSTRUCTOR"
|
|
1605
|
-
};
|
|
1606
|
-
|
|
1607
|
-
// src/types/lib/index.ts
|
|
1608
|
-
var TransactionType = {
|
|
1609
|
-
DECLARE: "DECLARE",
|
|
1610
|
-
DEPLOY: "DEPLOY",
|
|
1611
|
-
DEPLOY_ACCOUNT: "DEPLOY_ACCOUNT",
|
|
1612
|
-
INVOKE: "INVOKE_FUNCTION"
|
|
1613
|
-
};
|
|
1614
|
-
var TransactionFinalityStatus = {
|
|
1615
|
-
NOT_RECEIVED: "NOT_RECEIVED",
|
|
1616
|
-
RECEIVED: "RECEIVED",
|
|
1617
|
-
ACCEPTED_ON_L2: "ACCEPTED_ON_L2",
|
|
1618
|
-
ACCEPTED_ON_L1: "ACCEPTED_ON_L1"
|
|
1619
|
-
};
|
|
1620
|
-
var TransactionExecutionStatus = {
|
|
1621
|
-
REJECTED: "REJECTED",
|
|
1622
|
-
REVERTED: "REVERTED",
|
|
1623
|
-
SUCCEEDED: "SUCCEEDED"
|
|
1624
|
-
};
|
|
1625
|
-
var BlockStatus = {
|
|
1626
|
-
PENDING: "PENDING",
|
|
1627
|
-
ACCEPTED_ON_L1: "ACCEPTED_ON_L1",
|
|
1628
|
-
ACCEPTED_ON_L2: "ACCEPTED_ON_L2",
|
|
1629
|
-
REJECTED: "REJECTED"
|
|
1630
|
-
};
|
|
1631
|
-
var BlockTag = {
|
|
1632
|
-
PENDING: "pending",
|
|
1633
|
-
LATEST: "latest"
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
// src/provider/types/spec.type.ts
|
|
1637
|
-
var { ETransactionVersion: ETransactionVersion5 } = esm_exports2;
|
|
1638
|
-
var { ETransactionVersion2: ETransactionVersion23 } = esm_exports2;
|
|
1639
|
-
var { ETransactionVersion3: ETransactionVersion33 } = esm_exports2;
|
|
1640
|
-
var { EDataAvailabilityMode: EDataAvailabilityMode3 } = esm_exports2;
|
|
1641
|
-
var { EDAMode: EDAMode3 } = esm_exports2;
|
|
1642
|
-
function isRPC08_FeeEstimate(entry) {
|
|
1643
|
-
return "l1_data_gas_consumed" in entry;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
str += resolvedSpace ? `
|
|
1817
|
+
${indent}}` : "}";
|
|
1818
|
+
return str;
|
|
1819
|
+
}
|
|
1820
|
+
function includeProperty(_key, value2) {
|
|
1821
|
+
return typeof value2 !== "undefined" && typeof value2 !== "function" && typeof value2 !== "symbol";
|
|
1822
|
+
}
|
|
1644
1823
|
}
|
|
1645
|
-
function
|
|
1646
|
-
|
|
1824
|
+
function resolveSpace(space) {
|
|
1825
|
+
if (typeof space === "number") {
|
|
1826
|
+
return " ".repeat(space);
|
|
1827
|
+
}
|
|
1828
|
+
if (typeof space === "string" && space !== "") {
|
|
1829
|
+
return space;
|
|
1830
|
+
}
|
|
1831
|
+
return void 0;
|
|
1647
1832
|
}
|
|
1648
|
-
var { ETransactionStatus: ETransactionStatus3 } = esm_exports2;
|
|
1649
|
-
var { ETransactionExecutionStatus: ETransactionExecutionStatus3 } = esm_exports2;
|
|
1650
|
-
|
|
1651
|
-
// src/types/calldata.ts
|
|
1652
|
-
var ValidateType = {
|
|
1653
|
-
DEPLOY: "DEPLOY",
|
|
1654
|
-
CALL: "CALL",
|
|
1655
|
-
INVOKE: "INVOKE"
|
|
1656
|
-
};
|
|
1657
|
-
var Uint = {
|
|
1658
|
-
u8: "core::integer::u8",
|
|
1659
|
-
u16: "core::integer::u16",
|
|
1660
|
-
u32: "core::integer::u32",
|
|
1661
|
-
u64: "core::integer::u64",
|
|
1662
|
-
u128: "core::integer::u128",
|
|
1663
|
-
u256: "core::integer::u256",
|
|
1664
|
-
// This one is struct
|
|
1665
|
-
u512: "core::integer::u512"
|
|
1666
|
-
// This one is struct
|
|
1667
|
-
};
|
|
1668
|
-
var Literal = {
|
|
1669
|
-
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
1670
|
-
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
1671
|
-
Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
|
|
1672
|
-
U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
|
|
1673
|
-
};
|
|
1674
|
-
var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
|
|
1675
|
-
var NON_ZERO_PREFIX = "core::zeroable::NonZero::";
|
|
1676
1833
|
|
|
1677
|
-
// src/
|
|
1678
|
-
var
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
{ name: "chainId", type: "felt" }
|
|
1683
|
-
],
|
|
1684
|
-
OutsideExecution: [
|
|
1685
|
-
{ name: "caller", type: "felt" },
|
|
1686
|
-
{ name: "nonce", type: "felt" },
|
|
1687
|
-
{ name: "execute_after", type: "felt" },
|
|
1688
|
-
{ name: "execute_before", type: "felt" },
|
|
1689
|
-
{ name: "calls_len", type: "felt" },
|
|
1690
|
-
{ name: "calls", type: "OutsideCall*" }
|
|
1691
|
-
],
|
|
1692
|
-
OutsideCall: [
|
|
1693
|
-
{ name: "to", type: "felt" },
|
|
1694
|
-
{ name: "selector", type: "felt" },
|
|
1695
|
-
{ name: "calldata_len", type: "felt" },
|
|
1696
|
-
{ name: "calldata", type: "felt*" }
|
|
1697
|
-
]
|
|
1698
|
-
};
|
|
1699
|
-
var OutsideExecutionTypesV2 = {
|
|
1700
|
-
StarknetDomain: [
|
|
1701
|
-
// SNIP-12 revision 1 is used, so should be "StarknetDomain", not "StarkNetDomain"
|
|
1702
|
-
{ name: "name", type: "shortstring" },
|
|
1703
|
-
{ name: "version", type: "shortstring" },
|
|
1704
|
-
// set to 2 in v2
|
|
1705
|
-
{ name: "chainId", type: "shortstring" },
|
|
1706
|
-
{ name: "revision", type: "shortstring" }
|
|
1707
|
-
],
|
|
1708
|
-
OutsideExecution: [
|
|
1709
|
-
{ name: "Caller", type: "ContractAddress" },
|
|
1710
|
-
{ name: "Nonce", type: "felt" },
|
|
1711
|
-
{ name: "Execute After", type: "u128" },
|
|
1712
|
-
{ name: "Execute Before", type: "u128" },
|
|
1713
|
-
{ name: "Calls", type: "Call*" }
|
|
1714
|
-
],
|
|
1715
|
-
Call: [
|
|
1716
|
-
{ name: "To", type: "ContractAddress" },
|
|
1717
|
-
{ name: "Selector", type: "selector" },
|
|
1718
|
-
{ name: "Calldata", type: "felt*" }
|
|
1719
|
-
]
|
|
1720
|
-
};
|
|
1721
|
-
var OutsideExecutionVersion = {
|
|
1722
|
-
UNSUPPORTED: "0",
|
|
1723
|
-
V1: "1",
|
|
1724
|
-
V2: "2"
|
|
1834
|
+
// src/utils/json.ts
|
|
1835
|
+
var parseIntAsNumberOrBigInt = (str) => {
|
|
1836
|
+
if (!isInteger(str)) return parseFloat(str);
|
|
1837
|
+
const num = parseInt(str, 10);
|
|
1838
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
1725
1839
|
};
|
|
1840
|
+
var parse2 = (str) => parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
1841
|
+
var parseAlwaysAsBig = (str) => parse(String(str), void 0, parseNumberAndBigInt);
|
|
1842
|
+
var stringify2 = (value, replacer, space, numberStringifiers) => stringify(value, replacer, space, numberStringifiers);
|
|
1726
1843
|
|
|
1727
1844
|
// src/utils/batch/index.ts
|
|
1728
1845
|
var BatchClient = class {
|
|
@@ -11615,6 +11732,38 @@ ${indent}}` : "}";
|
|
|
11615
11732
|
var gzip_1 = gzip;
|
|
11616
11733
|
var ungzip_1 = ungzip;
|
|
11617
11734
|
|
|
11735
|
+
// src/utils/resolve.ts
|
|
11736
|
+
function isV3Tx(details) {
|
|
11737
|
+
const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
|
|
11738
|
+
return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
|
|
11739
|
+
}
|
|
11740
|
+
function isVersion(expected, provided) {
|
|
11741
|
+
const expectedParts = expected.split(".");
|
|
11742
|
+
const providedParts = provided.split(".");
|
|
11743
|
+
return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
|
|
11744
|
+
}
|
|
11745
|
+
function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
|
|
11746
|
+
return Object.values(_SupportedRpcVersion).some(
|
|
11747
|
+
(v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
|
|
11748
|
+
);
|
|
11749
|
+
}
|
|
11750
|
+
function toAnyPatchVersion(version) {
|
|
11751
|
+
const parts = version.split(".");
|
|
11752
|
+
if (parts.length < 3) {
|
|
11753
|
+
return version;
|
|
11754
|
+
}
|
|
11755
|
+
return `${parts[0]}.${parts[1]}.*`;
|
|
11756
|
+
}
|
|
11757
|
+
function isPendingBlock(response) {
|
|
11758
|
+
return response.status === "PENDING";
|
|
11759
|
+
}
|
|
11760
|
+
function isPendingTransaction(response) {
|
|
11761
|
+
return !("block_hash" in response);
|
|
11762
|
+
}
|
|
11763
|
+
function isPendingStateUpdate(response) {
|
|
11764
|
+
return !("block_hash" in response);
|
|
11765
|
+
}
|
|
11766
|
+
|
|
11618
11767
|
// src/utils/stark/rpc07.ts
|
|
11619
11768
|
function estimateFeeToBounds(estimate, overhead) {
|
|
11620
11769
|
const maxUnits = estimate.data_gas_consumed !== void 0 && estimate.data_gas_price !== void 0 ? toHex(
|
|
@@ -11654,49 +11803,6 @@ ${indent}}` : "}";
|
|
|
11654
11803
|
};
|
|
11655
11804
|
}
|
|
11656
11805
|
|
|
11657
|
-
// src/global/config.ts
|
|
11658
|
-
var Configuration = class _Configuration {
|
|
11659
|
-
static instance;
|
|
11660
|
-
config;
|
|
11661
|
-
constructor() {
|
|
11662
|
-
this.initialize();
|
|
11663
|
-
}
|
|
11664
|
-
initialize() {
|
|
11665
|
-
this.config = { ...DEFAULT_GLOBAL_CONFIG };
|
|
11666
|
-
}
|
|
11667
|
-
static getInstance() {
|
|
11668
|
-
if (!_Configuration.instance) {
|
|
11669
|
-
_Configuration.instance = new _Configuration();
|
|
11670
|
-
}
|
|
11671
|
-
return _Configuration.instance;
|
|
11672
|
-
}
|
|
11673
|
-
get(key, defaultValue) {
|
|
11674
|
-
return this.config[key] ?? defaultValue;
|
|
11675
|
-
}
|
|
11676
|
-
set(key, value) {
|
|
11677
|
-
this.config[key] = value;
|
|
11678
|
-
}
|
|
11679
|
-
update(configData) {
|
|
11680
|
-
this.config = {
|
|
11681
|
-
...this.config,
|
|
11682
|
-
...configData
|
|
11683
|
-
};
|
|
11684
|
-
}
|
|
11685
|
-
getAll() {
|
|
11686
|
-
return { ...this.config };
|
|
11687
|
-
}
|
|
11688
|
-
reset() {
|
|
11689
|
-
this.initialize();
|
|
11690
|
-
}
|
|
11691
|
-
delete(key) {
|
|
11692
|
-
delete this.config[key];
|
|
11693
|
-
}
|
|
11694
|
-
hasKey(key) {
|
|
11695
|
-
return key in this.config;
|
|
11696
|
-
}
|
|
11697
|
-
};
|
|
11698
|
-
var config2 = Configuration.getInstance();
|
|
11699
|
-
|
|
11700
11806
|
// src/utils/stark/index.ts
|
|
11701
11807
|
function compressProgram(jsonProgram) {
|
|
11702
11808
|
const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
|
|
@@ -11730,15 +11836,15 @@ ${indent}}` : "}";
|
|
|
11730
11836
|
function signatureToHexArray(sig) {
|
|
11731
11837
|
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
11732
11838
|
}
|
|
11733
|
-
function estimatedFeeToMaxFee(estimatedFee, overhead =
|
|
11839
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = config.get("feeMarginPercentage").maxFee) {
|
|
11734
11840
|
return addPercent(estimatedFee, overhead);
|
|
11735
11841
|
}
|
|
11736
|
-
function estimateFeeToBounds3(estimate, overhead =
|
|
11842
|
+
function estimateFeeToBounds3(estimate, overhead = config.get("feeMarginPercentage").bounds, specVersion) {
|
|
11737
11843
|
if (isBigInt(estimate)) {
|
|
11738
11844
|
return {
|
|
11739
11845
|
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
11740
11846
|
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
11741
|
-
...specVersion
|
|
11847
|
+
...specVersion && isVersion("0.8", specVersion) && {
|
|
11742
11848
|
l1_data_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
11743
11849
|
}
|
|
11744
11850
|
};
|
|
@@ -11808,34 +11914,130 @@ ${indent}}` : "}";
|
|
|
11808
11914
|
return fullPrivKey;
|
|
11809
11915
|
}
|
|
11810
11916
|
|
|
11811
|
-
// src/utils/contract.ts
|
|
11812
|
-
function isSierra(contract) {
|
|
11813
|
-
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
11814
|
-
return "sierra_program" in compiledContract;
|
|
11815
|
-
}
|
|
11816
|
-
function extractContractHashes(payload) {
|
|
11817
|
-
const response = { ...payload };
|
|
11818
|
-
if (isSierra(payload.contract)) {
|
|
11819
|
-
if (!payload.compiledClassHash && payload.casm) {
|
|
11820
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
11821
|
-
}
|
|
11822
|
-
if (!response.compiledClassHash)
|
|
11823
|
-
throw new Error(
|
|
11824
|
-
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
11825
|
-
);
|
|
11917
|
+
// src/utils/contract.ts
|
|
11918
|
+
function isSierra(contract) {
|
|
11919
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
11920
|
+
return "sierra_program" in compiledContract;
|
|
11921
|
+
}
|
|
11922
|
+
function extractContractHashes(payload) {
|
|
11923
|
+
const response = { ...payload };
|
|
11924
|
+
if (isSierra(payload.contract)) {
|
|
11925
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
11926
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
11927
|
+
}
|
|
11928
|
+
if (!response.compiledClassHash)
|
|
11929
|
+
throw new Error(
|
|
11930
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
11931
|
+
);
|
|
11932
|
+
}
|
|
11933
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
11934
|
+
if (!response.classHash)
|
|
11935
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
11936
|
+
return response;
|
|
11937
|
+
}
|
|
11938
|
+
function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
11939
|
+
if (isSierra(ccr)) {
|
|
11940
|
+
throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
|
|
11941
|
+
}
|
|
11942
|
+
const contract = ccr;
|
|
11943
|
+
return { ...contract, program: decompressProgram(contract.program) };
|
|
11944
|
+
}
|
|
11945
|
+
|
|
11946
|
+
// src/utils/errors/rpc.ts
|
|
11947
|
+
var errorCodes = {
|
|
11948
|
+
FAILED_TO_RECEIVE_TXN: 1,
|
|
11949
|
+
NO_TRACE_AVAILABLE: 10,
|
|
11950
|
+
CONTRACT_NOT_FOUND: 20,
|
|
11951
|
+
ENTRYPOINT_NOT_FOUND: 21,
|
|
11952
|
+
BLOCK_NOT_FOUND: 24,
|
|
11953
|
+
INVALID_TXN_INDEX: 27,
|
|
11954
|
+
CLASS_HASH_NOT_FOUND: 28,
|
|
11955
|
+
TXN_HASH_NOT_FOUND: 29,
|
|
11956
|
+
PAGE_SIZE_TOO_BIG: 31,
|
|
11957
|
+
NO_BLOCKS: 32,
|
|
11958
|
+
INVALID_CONTINUATION_TOKEN: 33,
|
|
11959
|
+
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
11960
|
+
CONTRACT_ERROR: 40,
|
|
11961
|
+
TRANSACTION_EXECUTION_ERROR: 41,
|
|
11962
|
+
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
11963
|
+
CLASS_ALREADY_DECLARED: 51,
|
|
11964
|
+
INVALID_TRANSACTION_NONCE: 52,
|
|
11965
|
+
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
11966
|
+
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
11967
|
+
VALIDATION_FAILURE: 55,
|
|
11968
|
+
COMPILATION_FAILED: 56,
|
|
11969
|
+
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
11970
|
+
NON_ACCOUNT: 58,
|
|
11971
|
+
DUPLICATE_TX: 59,
|
|
11972
|
+
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
11973
|
+
UNSUPPORTED_TX_VERSION: 61,
|
|
11974
|
+
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
11975
|
+
UNEXPECTED_ERROR: 63,
|
|
11976
|
+
INVALID_SUBSCRIPTION_ID: 66,
|
|
11977
|
+
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
11978
|
+
TOO_MANY_BLOCKS_BACK: 68,
|
|
11979
|
+
COMPILATION_ERROR: 100,
|
|
11980
|
+
INVALID_ADDRESS: 150,
|
|
11981
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
11982
|
+
INVALID_SIGNATURE: 153,
|
|
11983
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
11984
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
11985
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
11986
|
+
INVALID_TIME_BOUNDS: 157,
|
|
11987
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
11988
|
+
INVALID_CLASS_HASH: 159,
|
|
11989
|
+
INVALID_ID: 160,
|
|
11990
|
+
UNKNOWN_ERROR: 163
|
|
11991
|
+
};
|
|
11992
|
+
var rpc_default = errorCodes;
|
|
11993
|
+
|
|
11994
|
+
// src/utils/errors/index.ts
|
|
11995
|
+
function fixStack(target, fn = target.constructor) {
|
|
11996
|
+
const { captureStackTrace } = Error;
|
|
11997
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
11998
|
+
}
|
|
11999
|
+
function fixProto(target, prototype) {
|
|
12000
|
+
const { setPrototypeOf } = Object;
|
|
12001
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
12002
|
+
}
|
|
12003
|
+
var CustomError = class extends Error {
|
|
12004
|
+
name;
|
|
12005
|
+
constructor(message) {
|
|
12006
|
+
super(message);
|
|
12007
|
+
Object.defineProperty(this, "name", {
|
|
12008
|
+
value: new.target.name,
|
|
12009
|
+
enumerable: false,
|
|
12010
|
+
configurable: true
|
|
12011
|
+
});
|
|
12012
|
+
fixProto(this, new.target.prototype);
|
|
12013
|
+
fixStack(this);
|
|
12014
|
+
}
|
|
12015
|
+
};
|
|
12016
|
+
var LibraryError = class extends CustomError {
|
|
12017
|
+
};
|
|
12018
|
+
var RpcError = class extends LibraryError {
|
|
12019
|
+
constructor(baseError, method, params) {
|
|
12020
|
+
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
12021
|
+
|
|
12022
|
+
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
12023
|
+
this.baseError = baseError;
|
|
12024
|
+
this.request = { method, params };
|
|
11826
12025
|
}
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
return response;
|
|
11831
|
-
}
|
|
11832
|
-
function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
11833
|
-
if (isSierra(ccr)) {
|
|
11834
|
-
throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
|
|
12026
|
+
request;
|
|
12027
|
+
get code() {
|
|
12028
|
+
return this.baseError.code;
|
|
11835
12029
|
}
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
12030
|
+
/**
|
|
12031
|
+
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
12032
|
+
* @example
|
|
12033
|
+
* ```typescript
|
|
12034
|
+
* SomeError.isType('UNEXPECTED_ERROR');
|
|
12035
|
+
* ```
|
|
12036
|
+
*/
|
|
12037
|
+
isType(typeName) {
|
|
12038
|
+
return rpc_default[typeName] === this.code;
|
|
12039
|
+
}
|
|
12040
|
+
};
|
|
11839
12041
|
|
|
11840
12042
|
// src/utils/eth.ts
|
|
11841
12043
|
var eth_exports = {};
|
|
@@ -11935,11 +12137,8 @@ ${indent}}` : "}";
|
|
|
11935
12137
|
return result;
|
|
11936
12138
|
}
|
|
11937
12139
|
|
|
11938
|
-
// src/utils/fetch.ts
|
|
11939
|
-
var fetch_default =
|
|
11940
|
-
!isUndefined(global) && global.fetch || // use built-in fetch in node, react-native and service worker if available
|
|
11941
|
-
// throw with instructions when no fetch is detected
|
|
11942
|
-
(() => {
|
|
12140
|
+
// src/utils/connect/fetch.ts
|
|
12141
|
+
var fetch_default = typeof globalThis !== "undefined" && globalThis.fetch.bind(globalThis) || typeof window !== "undefined" && window.fetch.bind(window) || typeof global !== "undefined" && global.fetch.bind(global) || (() => {
|
|
11943
12142
|
throw new LibraryError(
|
|
11944
12143
|
"'fetch()' not detected, use the 'baseFetch' constructor parameter to set it"
|
|
11945
12144
|
);
|
|
@@ -11952,151 +12151,10 @@ ${indent}}` : "}";
|
|
|
11952
12151
|
createSierraContractClass: () => createSierraContractClass,
|
|
11953
12152
|
getDefaultNodeUrl: () => getDefaultNodeUrl,
|
|
11954
12153
|
getDefaultNodes: () => getDefaultNodes,
|
|
11955
|
-
isPendingBlock: () => isPendingBlock,
|
|
11956
|
-
isPendingStateUpdate: () => isPendingStateUpdate,
|
|
11957
|
-
isPendingTransaction: () => isPendingTransaction,
|
|
11958
|
-
isV3Tx: () => isV3Tx,
|
|
11959
|
-
isVersion: () => isVersion,
|
|
11960
12154
|
parseContract: () => parseContract,
|
|
11961
|
-
stringToSpecVersion: () => stringToSpecVersion,
|
|
11962
12155
|
validBlockTags: () => validBlockTags,
|
|
11963
12156
|
wait: () => wait
|
|
11964
12157
|
});
|
|
11965
|
-
|
|
11966
|
-
// src/global/logger.type.ts
|
|
11967
|
-
var LogLevelIndex = {
|
|
11968
|
-
DEBUG: 5,
|
|
11969
|
-
INFO: 4,
|
|
11970
|
-
WARN: 3,
|
|
11971
|
-
ERROR: 2,
|
|
11972
|
-
FATAL: 1,
|
|
11973
|
-
OFF: 0
|
|
11974
|
-
};
|
|
11975
|
-
|
|
11976
|
-
// src/global/logger.ts
|
|
11977
|
-
var Logger = class _Logger {
|
|
11978
|
-
static instance;
|
|
11979
|
-
config;
|
|
11980
|
-
constructor() {
|
|
11981
|
-
this.config = config2;
|
|
11982
|
-
}
|
|
11983
|
-
static getInstance() {
|
|
11984
|
-
if (!_Logger.instance) {
|
|
11985
|
-
_Logger.instance = new _Logger();
|
|
11986
|
-
}
|
|
11987
|
-
return _Logger.instance;
|
|
11988
|
-
}
|
|
11989
|
-
getTimestamp() {
|
|
11990
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
11991
|
-
}
|
|
11992
|
-
shouldLog(messageLevel) {
|
|
11993
|
-
const configLevel = this.config.get("logLevel", "INFO");
|
|
11994
|
-
return messageLevel <= LogLevelIndex[configLevel];
|
|
11995
|
-
}
|
|
11996
|
-
formatMessage(logMessage) {
|
|
11997
|
-
const { level, message, timestamp, data } = logMessage;
|
|
11998
|
-
let formattedMessage = `[${timestamp}] ${level}: ${message}`;
|
|
11999
|
-
if (data) {
|
|
12000
|
-
try {
|
|
12001
|
-
formattedMessage += `
|
|
12002
|
-
${JSON.stringify(data, null, 2)}`;
|
|
12003
|
-
} catch (error) {
|
|
12004
|
-
formattedMessage += `
|
|
12005
|
-
[JSON.stringify Error/Circular]: ${error}`;
|
|
12006
|
-
}
|
|
12007
|
-
}
|
|
12008
|
-
return formattedMessage;
|
|
12009
|
-
}
|
|
12010
|
-
log(level, message, data) {
|
|
12011
|
-
if (!this.shouldLog(LogLevelIndex[level])) {
|
|
12012
|
-
return;
|
|
12013
|
-
}
|
|
12014
|
-
const logMessage = {
|
|
12015
|
-
level,
|
|
12016
|
-
message,
|
|
12017
|
-
timestamp: this.getTimestamp(),
|
|
12018
|
-
data
|
|
12019
|
-
};
|
|
12020
|
-
const formattedMessage = this.formatMessage(logMessage);
|
|
12021
|
-
switch (level) {
|
|
12022
|
-
case "DEBUG":
|
|
12023
|
-
console.debug(formattedMessage);
|
|
12024
|
-
break;
|
|
12025
|
-
case "INFO":
|
|
12026
|
-
console.info(formattedMessage);
|
|
12027
|
-
break;
|
|
12028
|
-
case "WARN":
|
|
12029
|
-
console.warn(formattedMessage);
|
|
12030
|
-
break;
|
|
12031
|
-
case "ERROR":
|
|
12032
|
-
case "FATAL":
|
|
12033
|
-
console.error(formattedMessage);
|
|
12034
|
-
break;
|
|
12035
|
-
case "OFF":
|
|
12036
|
-
break;
|
|
12037
|
-
default:
|
|
12038
|
-
console.log(formattedMessage);
|
|
12039
|
-
break;
|
|
12040
|
-
}
|
|
12041
|
-
}
|
|
12042
|
-
/**
|
|
12043
|
-
* debug will be displayed when LogLevel level is set to DEBUG(5)
|
|
12044
|
-
*/
|
|
12045
|
-
debug(message, data) {
|
|
12046
|
-
this.log("DEBUG", message, data);
|
|
12047
|
-
}
|
|
12048
|
-
/**
|
|
12049
|
-
* info will be displayed when LogLevel level is set to DEBUG(5), INFO(4)
|
|
12050
|
-
*/
|
|
12051
|
-
info(message, data) {
|
|
12052
|
-
this.log("INFO", message, data);
|
|
12053
|
-
}
|
|
12054
|
-
/**
|
|
12055
|
-
* warn will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3)
|
|
12056
|
-
*/
|
|
12057
|
-
warn(message, data) {
|
|
12058
|
-
this.log("WARN", message, data);
|
|
12059
|
-
}
|
|
12060
|
-
/**
|
|
12061
|
-
* error will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2)
|
|
12062
|
-
*/
|
|
12063
|
-
error(message, data) {
|
|
12064
|
-
this.log("ERROR", message, data);
|
|
12065
|
-
}
|
|
12066
|
-
/**
|
|
12067
|
-
* fatal will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2), FATAL(1)
|
|
12068
|
-
*/
|
|
12069
|
-
fatal(message, data) {
|
|
12070
|
-
this.log("FATAL", message, data);
|
|
12071
|
-
}
|
|
12072
|
-
/**
|
|
12073
|
-
* Set the logging level you would like system to display
|
|
12074
|
-
* * 5 DEBUG - show all logs
|
|
12075
|
-
* * 4 INFO
|
|
12076
|
-
* * 3 WARN
|
|
12077
|
-
* * 2 ERROR
|
|
12078
|
-
* * 1 FATAL
|
|
12079
|
-
* * 0 OFF - disable logs
|
|
12080
|
-
*/
|
|
12081
|
-
setLogLevel(level) {
|
|
12082
|
-
this.config.set("logLevel", level);
|
|
12083
|
-
}
|
|
12084
|
-
getLogLevel() {
|
|
12085
|
-
return this.config.get("logLevel", "INFO");
|
|
12086
|
-
}
|
|
12087
|
-
/**
|
|
12088
|
-
*
|
|
12089
|
-
* @returns logs levels displayed on the configured LogLevel
|
|
12090
|
-
*/
|
|
12091
|
-
getEnabledLogLevels() {
|
|
12092
|
-
return Object.keys(LogLevelIndex).filter((s) => {
|
|
12093
|
-
return this.shouldLog(LogLevelIndex[s]) && s !== "OFF";
|
|
12094
|
-
});
|
|
12095
|
-
}
|
|
12096
|
-
};
|
|
12097
|
-
var logger = Logger.getInstance();
|
|
12098
|
-
|
|
12099
|
-
// src/utils/provider.ts
|
|
12100
12158
|
function wait(delay) {
|
|
12101
12159
|
return new Promise((res) => {
|
|
12102
12160
|
setTimeout(res, delay);
|
|
@@ -12124,7 +12182,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12124
12182
|
if (!mute) {
|
|
12125
12183
|
logger.info("Using default public node url, please provide nodeUrl in provider options!");
|
|
12126
12184
|
}
|
|
12127
|
-
const rpcNodes = getDefaultNodes(rpcVersion ??
|
|
12185
|
+
const rpcNodes = getDefaultNodes(rpcVersion ?? config.get("rpcVersion"));
|
|
12128
12186
|
const nodes = rpcNodes[networkName ?? _NetworkName.SN_SEPOLIA];
|
|
12129
12187
|
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
12130
12188
|
return nodes[randIdx];
|
|
@@ -12237,28 +12295,6 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12237
12295
|
valueOf = () => this.number;
|
|
12238
12296
|
toString = () => this.hash;
|
|
12239
12297
|
};
|
|
12240
|
-
function isV3Tx(details) {
|
|
12241
|
-
const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
|
|
12242
|
-
return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
|
|
12243
|
-
}
|
|
12244
|
-
function isVersion(version, response) {
|
|
12245
|
-
const [majorS, minorS] = version.split(".");
|
|
12246
|
-
const [majorR, minorR] = response.split(".");
|
|
12247
|
-
return majorS === majorR && minorS === minorR;
|
|
12248
|
-
}
|
|
12249
|
-
function stringToSpecVersion(version) {
|
|
12250
|
-
const [major, minor] = version.split(".");
|
|
12251
|
-
return `${major}.${minor}`;
|
|
12252
|
-
}
|
|
12253
|
-
function isPendingBlock(response) {
|
|
12254
|
-
return response.status === "PENDING";
|
|
12255
|
-
}
|
|
12256
|
-
function isPendingTransaction(response) {
|
|
12257
|
-
return !("block_hash" in response);
|
|
12258
|
-
}
|
|
12259
|
-
function isPendingStateUpdate(response) {
|
|
12260
|
-
return !("block_hash" in response);
|
|
12261
|
-
}
|
|
12262
12298
|
|
|
12263
12299
|
// src/utils/transaction.ts
|
|
12264
12300
|
var transaction_exports = {};
|
|
@@ -12351,14 +12387,18 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12351
12387
|
} : { v1: ETransactionVersion5.V1, v2: ETransactionVersion5.V2, v3: ETransactionVersion5.V3 };
|
|
12352
12388
|
}
|
|
12353
12389
|
|
|
12354
|
-
// src/channel/
|
|
12390
|
+
// src/channel/rpc_0_7_1.ts
|
|
12355
12391
|
var defaultOptions = {
|
|
12356
12392
|
headers: { "Content-Type": "application/json" },
|
|
12357
12393
|
blockIdentifier: BlockTag.PENDING,
|
|
12358
12394
|
retries: 200
|
|
12359
12395
|
};
|
|
12360
12396
|
var RpcChannel = class {
|
|
12361
|
-
id = "
|
|
12397
|
+
id = "RPC071";
|
|
12398
|
+
/**
|
|
12399
|
+
* RPC specification version this Channel class implements
|
|
12400
|
+
*/
|
|
12401
|
+
channelSpecVersion = _SupportedRpcVersion.v0_7_1;
|
|
12362
12402
|
nodeUrl;
|
|
12363
12403
|
headers;
|
|
12364
12404
|
requestId;
|
|
@@ -12367,6 +12407,9 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12367
12407
|
waitMode;
|
|
12368
12408
|
// behave like web2 rpc and return when tx is processed
|
|
12369
12409
|
chainId;
|
|
12410
|
+
/**
|
|
12411
|
+
* RPC specification version of the connected node
|
|
12412
|
+
*/
|
|
12370
12413
|
specVersion;
|
|
12371
12414
|
transactionRetryIntervalFallback;
|
|
12372
12415
|
batchClient;
|
|
@@ -12385,13 +12428,21 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12385
12428
|
waitMode
|
|
12386
12429
|
} = optionsOrProvider || {};
|
|
12387
12430
|
if (Object.values(_NetworkName).includes(nodeUrl)) {
|
|
12388
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
12431
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
12432
|
+
nodeUrl,
|
|
12433
|
+
optionsOrProvider?.default,
|
|
12434
|
+
this.channelSpecVersion
|
|
12435
|
+
);
|
|
12389
12436
|
} else if (nodeUrl) {
|
|
12390
12437
|
this.nodeUrl = nodeUrl;
|
|
12391
12438
|
} else {
|
|
12392
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
12439
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
12440
|
+
void 0,
|
|
12441
|
+
optionsOrProvider?.default,
|
|
12442
|
+
this.channelSpecVersion
|
|
12443
|
+
);
|
|
12393
12444
|
}
|
|
12394
|
-
this.baseFetch = baseFetch
|
|
12445
|
+
this.baseFetch = baseFetch || config.get("fetch") || fetch_default;
|
|
12395
12446
|
this.blockIdentifier = blockIdentifier ?? defaultOptions.blockIdentifier;
|
|
12396
12447
|
this.chainId = chainId;
|
|
12397
12448
|
this.headers = { ...defaultOptions.headers, ...headers };
|
|
@@ -12469,24 +12520,32 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12469
12520
|
return this.chainId;
|
|
12470
12521
|
}
|
|
12471
12522
|
/**
|
|
12472
|
-
* fetch
|
|
12473
|
-
*
|
|
12474
|
-
* @example this.specVersion = "0.8"
|
|
12523
|
+
* fetch rpc node specVersion
|
|
12524
|
+
* @example this.specVersion = "0.7.1"
|
|
12475
12525
|
*/
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
const extendedVersion = await this.getSpecificationVersion();
|
|
12479
|
-
const [major, minor] = extendedVersion.split(".");
|
|
12480
|
-
const specVerson = `${major}.${minor}`;
|
|
12481
|
-
this.specVersion ??= specVerson;
|
|
12482
|
-
}
|
|
12483
|
-
return this.specVersion;
|
|
12526
|
+
getSpecVersion() {
|
|
12527
|
+
return this.fetchEndpoint("starknet_specVersion");
|
|
12484
12528
|
}
|
|
12485
12529
|
/**
|
|
12486
|
-
* fetch
|
|
12530
|
+
* fetch if undefined test and set specVersion, else just return this.specVersion
|
|
12531
|
+
* @example this.specVersion = "0.7.1"
|
|
12487
12532
|
*/
|
|
12488
|
-
|
|
12489
|
-
|
|
12533
|
+
async setUpSpecVersion() {
|
|
12534
|
+
if (!this.specVersion) {
|
|
12535
|
+
const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
|
|
12536
|
+
if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
|
|
12537
|
+
logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
|
|
12538
|
+
channelId: this.id,
|
|
12539
|
+
channelSpecVersion: this.channelSpecVersion,
|
|
12540
|
+
nodeSpecVersion: this.specVersion
|
|
12541
|
+
});
|
|
12542
|
+
}
|
|
12543
|
+
if (!isSupportedSpecVersion(unknownSpecVersion)) {
|
|
12544
|
+
throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
|
|
12545
|
+
}
|
|
12546
|
+
this.specVersion = unknownSpecVersion;
|
|
12547
|
+
}
|
|
12548
|
+
return this.specVersion;
|
|
12490
12549
|
}
|
|
12491
12550
|
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
12492
12551
|
const contract_address = toHex(contractAddress);
|
|
@@ -12953,9 +13012,9 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12953
13012
|
}
|
|
12954
13013
|
};
|
|
12955
13014
|
|
|
12956
|
-
// src/channel/
|
|
12957
|
-
var
|
|
12958
|
-
__export(
|
|
13015
|
+
// src/channel/rpc_0_8_1.ts
|
|
13016
|
+
var rpc_0_8_1_exports = {};
|
|
13017
|
+
__export(rpc_0_8_1_exports, {
|
|
12959
13018
|
RpcChannel: () => RpcChannel2
|
|
12960
13019
|
});
|
|
12961
13020
|
var defaultOptions2 = {
|
|
@@ -12964,7 +13023,11 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12964
13023
|
retries: 200
|
|
12965
13024
|
};
|
|
12966
13025
|
var RpcChannel2 = class {
|
|
12967
|
-
id = "
|
|
13026
|
+
id = "RPC081";
|
|
13027
|
+
/**
|
|
13028
|
+
* RPC specification version this Channel class implements
|
|
13029
|
+
*/
|
|
13030
|
+
channelSpecVersion = _SupportedRpcVersion.v0_8_1;
|
|
12968
13031
|
nodeUrl;
|
|
12969
13032
|
headers;
|
|
12970
13033
|
requestId;
|
|
@@ -12973,6 +13036,9 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12973
13036
|
waitMode;
|
|
12974
13037
|
// behave like web2 rpc and return when tx is processed
|
|
12975
13038
|
chainId;
|
|
13039
|
+
/**
|
|
13040
|
+
* RPC specification version of the connected node
|
|
13041
|
+
*/
|
|
12976
13042
|
specVersion;
|
|
12977
13043
|
transactionRetryIntervalFallback;
|
|
12978
13044
|
batchClient;
|
|
@@ -12991,13 +13057,21 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
12991
13057
|
waitMode
|
|
12992
13058
|
} = optionsOrProvider || {};
|
|
12993
13059
|
if (Object.values(_NetworkName).includes(nodeUrl)) {
|
|
12994
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
13060
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
13061
|
+
nodeUrl,
|
|
13062
|
+
optionsOrProvider?.default,
|
|
13063
|
+
this.channelSpecVersion
|
|
13064
|
+
);
|
|
12995
13065
|
} else if (nodeUrl) {
|
|
12996
13066
|
this.nodeUrl = nodeUrl;
|
|
12997
13067
|
} else {
|
|
12998
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
13068
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
13069
|
+
void 0,
|
|
13070
|
+
optionsOrProvider?.default,
|
|
13071
|
+
this.channelSpecVersion
|
|
13072
|
+
);
|
|
12999
13073
|
}
|
|
13000
|
-
this.baseFetch = baseFetch
|
|
13074
|
+
this.baseFetch = baseFetch || config.get("fetch") || fetch_default;
|
|
13001
13075
|
this.blockIdentifier = blockIdentifier ?? defaultOptions2.blockIdentifier;
|
|
13002
13076
|
this.chainId = chainId;
|
|
13003
13077
|
this.headers = { ...defaultOptions2.headers, ...headers };
|
|
@@ -13073,6 +13147,34 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13073
13147
|
this.chainId ??= await this.fetchEndpoint("starknet_chainId");
|
|
13074
13148
|
return this.chainId;
|
|
13075
13149
|
}
|
|
13150
|
+
/**
|
|
13151
|
+
* fetch rpc node specVersion
|
|
13152
|
+
* @example this.specVersion = "0.7.1"
|
|
13153
|
+
*/
|
|
13154
|
+
getSpecVersion() {
|
|
13155
|
+
return this.fetchEndpoint("starknet_specVersion");
|
|
13156
|
+
}
|
|
13157
|
+
/**
|
|
13158
|
+
* fetch if undefined else just return this.specVersion
|
|
13159
|
+
* @example this.specVersion = "0.8.1"
|
|
13160
|
+
*/
|
|
13161
|
+
async setUpSpecVersion() {
|
|
13162
|
+
if (!this.specVersion) {
|
|
13163
|
+
const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
|
|
13164
|
+
if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
|
|
13165
|
+
logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
|
|
13166
|
+
channelId: this.id,
|
|
13167
|
+
channelSpecVersion: this.channelSpecVersion,
|
|
13168
|
+
nodeSpecVersion: this.specVersion
|
|
13169
|
+
});
|
|
13170
|
+
}
|
|
13171
|
+
if (!isSupportedSpecVersion(unknownSpecVersion)) {
|
|
13172
|
+
throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
|
|
13173
|
+
}
|
|
13174
|
+
this.specVersion = unknownSpecVersion;
|
|
13175
|
+
}
|
|
13176
|
+
return this.specVersion;
|
|
13177
|
+
}
|
|
13076
13178
|
// TODO: New Method add test
|
|
13077
13179
|
/**
|
|
13078
13180
|
* Given an l1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the l1 tx sending order
|
|
@@ -13092,35 +13194,15 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13092
13194
|
block_id,
|
|
13093
13195
|
class_hashes,
|
|
13094
13196
|
contract_addresses,
|
|
13095
|
-
contracts_storage_keys: contractsStorageKeys
|
|
13096
|
-
});
|
|
13097
|
-
}
|
|
13098
|
-
// TODO: New Method add test
|
|
13099
|
-
getCompiledCasm(classHash) {
|
|
13100
|
-
const class_hash = toHex(classHash);
|
|
13101
|
-
return this.fetchEndpoint("starknet_getCompiledCasm", {
|
|
13102
|
-
class_hash
|
|
13103
|
-
});
|
|
13104
|
-
}
|
|
13105
|
-
/**
|
|
13106
|
-
* fetch if undefined else just return this.specVersion
|
|
13107
|
-
* return this.specVersion as 'M.m'
|
|
13108
|
-
* @example this.specVersion = "0.8"
|
|
13109
|
-
*/
|
|
13110
|
-
async getSpecVersion() {
|
|
13111
|
-
if (!this.specVersion) {
|
|
13112
|
-
const extendedVersion = await this.getSpecificationVersion();
|
|
13113
|
-
const [major, minor] = extendedVersion.split(".");
|
|
13114
|
-
const specVerson = `${major}.${minor}`;
|
|
13115
|
-
this.specVersion ??= specVerson;
|
|
13116
|
-
}
|
|
13117
|
-
return this.specVersion;
|
|
13197
|
+
contracts_storage_keys: contractsStorageKeys
|
|
13198
|
+
});
|
|
13118
13199
|
}
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
|
|
13200
|
+
// TODO: New Method add test
|
|
13201
|
+
getCompiledCasm(classHash) {
|
|
13202
|
+
const class_hash = toHex(classHash);
|
|
13203
|
+
return this.fetchEndpoint("starknet_getCompiledCasm", {
|
|
13204
|
+
class_hash
|
|
13205
|
+
});
|
|
13124
13206
|
}
|
|
13125
13207
|
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
13126
13208
|
const contract_address = toHex(contractAddress);
|
|
@@ -13503,21 +13585,14 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13503
13585
|
}
|
|
13504
13586
|
};
|
|
13505
13587
|
|
|
13506
|
-
//
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
if (typeof self.WebSocket !== "undefined")
|
|
13515
|
-
return self.WebSocket;
|
|
13516
|
-
throw new Error("`WebSocket` is not supported in this environment");
|
|
13517
|
-
}
|
|
13518
|
-
|
|
13519
|
-
// node_modules/isows/_esm/native.js
|
|
13520
|
-
var WebSocket2 = getNativeWebSocket();
|
|
13588
|
+
// src/utils/connect/ws.ts
|
|
13589
|
+
var ws_default = typeof WebSocket !== "undefined" && WebSocket || typeof globalThis !== "undefined" && globalThis.WebSocket || typeof window !== "undefined" && window.WebSocket.bind(window) || typeof global !== "undefined" && global.WebSocket || class {
|
|
13590
|
+
constructor() {
|
|
13591
|
+
throw new LibraryError(
|
|
13592
|
+
"WebSocket module not detected, use the 'websocket' constructor parameter to set a compatible connection"
|
|
13593
|
+
);
|
|
13594
|
+
}
|
|
13595
|
+
};
|
|
13521
13596
|
|
|
13522
13597
|
// src/channel/ws_0_8.ts
|
|
13523
13598
|
var WSSubscriptions = {
|
|
@@ -13644,7 +13719,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13644
13719
|
constructor(options = {}) {
|
|
13645
13720
|
const nodeUrl = options.nodeUrl || "http://localhost:3000 ";
|
|
13646
13721
|
this.nodeUrl = options.websocket ? options.websocket.url : nodeUrl;
|
|
13647
|
-
this.websocket = options.websocket
|
|
13722
|
+
this.websocket = options.websocket || config.get("websocket") || new ws_default(nodeUrl);
|
|
13648
13723
|
this.websocket.addEventListener("open", this.onOpen.bind(this));
|
|
13649
13724
|
this.websocket.addEventListener("close", this.onCloseProxy.bind(this));
|
|
13650
13725
|
this.websocket.addEventListener("message", this.onMessageProxy.bind(this));
|
|
@@ -13713,7 +13788,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13713
13788
|
* Helper to check connection is open
|
|
13714
13789
|
*/
|
|
13715
13790
|
isConnected() {
|
|
13716
|
-
return this.websocket.readyState ===
|
|
13791
|
+
return this.websocket.readyState === ws_default.OPEN;
|
|
13717
13792
|
}
|
|
13718
13793
|
/**
|
|
13719
13794
|
* await while websocket is connected
|
|
@@ -13724,7 +13799,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13724
13799
|
* ```
|
|
13725
13800
|
*/
|
|
13726
13801
|
async waitForConnection() {
|
|
13727
|
-
if (this.websocket.readyState !==
|
|
13802
|
+
if (this.websocket.readyState !== ws_default.OPEN) {
|
|
13728
13803
|
return new Promise((resolve, reject) => {
|
|
13729
13804
|
if (!this.websocket) return;
|
|
13730
13805
|
this.websocket.onopen = () => resolve(this.websocket.readyState);
|
|
@@ -13749,7 +13824,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13749
13824
|
* ```
|
|
13750
13825
|
*/
|
|
13751
13826
|
async waitForDisconnection() {
|
|
13752
|
-
if (this.websocket.readyState !==
|
|
13827
|
+
if (this.websocket.readyState !== ws_default.CLOSED) {
|
|
13753
13828
|
return new Promise((resolve, reject) => {
|
|
13754
13829
|
if (!this.websocket) return;
|
|
13755
13830
|
this.websocket.onclose = () => resolve(this.websocket.readyState);
|
|
@@ -13802,7 +13877,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
13802
13877
|
* Reconnect re-create this.websocket instance
|
|
13803
13878
|
*/
|
|
13804
13879
|
reconnect() {
|
|
13805
|
-
this.websocket = new
|
|
13880
|
+
this.websocket = new ws_default(this.nodeUrl);
|
|
13806
13881
|
this.websocket.addEventListener("open", this.onOpen.bind(this));
|
|
13807
13882
|
this.websocket.addEventListener("close", this.onCloseProxy.bind(this));
|
|
13808
13883
|
this.websocket.addEventListener("message", this.onMessageProxy.bind(this));
|
|
@@ -14527,15 +14602,15 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
14527
14602
|
} else {
|
|
14528
14603
|
if (optionsOrProvider && optionsOrProvider.specVersion) {
|
|
14529
14604
|
if (isVersion("0.8", optionsOrProvider.specVersion)) {
|
|
14530
|
-
this.channel = new
|
|
14605
|
+
this.channel = new rpc_0_8_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
14531
14606
|
} else if (isVersion("0.7", optionsOrProvider.specVersion)) {
|
|
14532
|
-
this.channel = new
|
|
14607
|
+
this.channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
14533
14608
|
} else
|
|
14534
14609
|
throw new Error(`unsupported channel for spec version: ${optionsOrProvider.specVersion}`);
|
|
14535
|
-
} else if (isVersion("0.8",
|
|
14536
|
-
this.channel = new
|
|
14537
|
-
} else if (isVersion("0.7",
|
|
14538
|
-
this.channel = new
|
|
14610
|
+
} else if (isVersion("0.8", config.get("rpcVersion"))) {
|
|
14611
|
+
this.channel = new rpc_0_8_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
14612
|
+
} else if (isVersion("0.7", config.get("rpcVersion"))) {
|
|
14613
|
+
this.channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
14539
14614
|
} else throw new Error("unable to define spec version for channel");
|
|
14540
14615
|
this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage);
|
|
14541
14616
|
}
|
|
@@ -14546,15 +14621,26 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
14546
14621
|
*/
|
|
14547
14622
|
// NOTE: the generic T and 'this' reference are used so that the expanded class is generated when a mixin is applied
|
|
14548
14623
|
static async create(optionsOrProvider) {
|
|
14549
|
-
const channel = new
|
|
14624
|
+
const channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider });
|
|
14550
14625
|
const spec = await channel.getSpecVersion();
|
|
14626
|
+
if (!isSupportedSpecVersion(spec)) {
|
|
14627
|
+
logger.warn(`Using incompatible node spec version ${spec}`);
|
|
14628
|
+
}
|
|
14551
14629
|
if (isVersion("0.7", spec)) {
|
|
14552
|
-
return new this({
|
|
14630
|
+
return new this({
|
|
14631
|
+
...optionsOrProvider,
|
|
14632
|
+
specVersion: _SupportedRpcVersion.v0_7_1
|
|
14633
|
+
});
|
|
14553
14634
|
}
|
|
14554
14635
|
if (isVersion("0.8", spec)) {
|
|
14555
|
-
return new this({
|
|
14636
|
+
return new this({
|
|
14637
|
+
...optionsOrProvider,
|
|
14638
|
+
specVersion: _SupportedRpcVersion.v0_8_1
|
|
14639
|
+
});
|
|
14556
14640
|
}
|
|
14557
|
-
throw new LibraryError(
|
|
14641
|
+
throw new LibraryError(
|
|
14642
|
+
`Provided RPC node specification version ${spec} is not compatible with the SDK. SDK supported RPC versions ${Object.keys(_SupportedRpcVersion).toString()}`
|
|
14643
|
+
);
|
|
14558
14644
|
}
|
|
14559
14645
|
fetch(method, params, id = 0) {
|
|
14560
14646
|
return this.channel.fetch(method, params, id);
|
|
@@ -14563,16 +14649,22 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
14563
14649
|
return this.channel.getChainId();
|
|
14564
14650
|
}
|
|
14565
14651
|
/**
|
|
14566
|
-
*
|
|
14652
|
+
* read channel spec version
|
|
14653
|
+
*/
|
|
14654
|
+
readSpecVersion() {
|
|
14655
|
+
return this.channel.readSpecVersion();
|
|
14656
|
+
}
|
|
14657
|
+
/**
|
|
14658
|
+
* get channel spec version
|
|
14567
14659
|
*/
|
|
14568
14660
|
async getSpecVersion() {
|
|
14569
14661
|
return this.channel.getSpecVersion();
|
|
14570
14662
|
}
|
|
14571
14663
|
/**
|
|
14572
|
-
*
|
|
14664
|
+
* setup channel spec version and return it
|
|
14573
14665
|
*/
|
|
14574
|
-
|
|
14575
|
-
return this.channel.
|
|
14666
|
+
setUpSpecVersion() {
|
|
14667
|
+
return this.channel.setUpSpecVersion();
|
|
14576
14668
|
}
|
|
14577
14669
|
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
14578
14670
|
return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
|
|
@@ -14937,18 +15029,18 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
14937
15029
|
/**
|
|
14938
15030
|
* Given an l1 tx hash, returns the associated l1_handler tx hashes and statuses for all L1 -> L2 messages sent by the l1 transaction, ordered by the l1 tx sending order
|
|
14939
15031
|
*/
|
|
14940
|
-
getL1MessagesStatus(transactionHash) {
|
|
14941
|
-
if (this.channel instanceof
|
|
14942
|
-
this.channel.getMessagesStatus(transactionHash);
|
|
15032
|
+
async getL1MessagesStatus(transactionHash) {
|
|
15033
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
15034
|
+
return this.channel.getMessagesStatus(transactionHash);
|
|
14943
15035
|
}
|
|
14944
15036
|
throw new LibraryError("Unsupported method for RPC version");
|
|
14945
15037
|
}
|
|
14946
15038
|
/**
|
|
14947
15039
|
* Get merkle paths in one of the state tries: global state, classes, individual contract
|
|
14948
15040
|
*/
|
|
14949
|
-
getStorageProof(classHashes, contractAddresses, contractsStorageKeys, blockIdentifier) {
|
|
14950
|
-
if (this.channel instanceof
|
|
14951
|
-
this.channel.getStorageProof(
|
|
15041
|
+
async getStorageProof(classHashes, contractAddresses, contractsStorageKeys, blockIdentifier) {
|
|
15042
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
15043
|
+
return this.channel.getStorageProof(
|
|
14952
15044
|
classHashes,
|
|
14953
15045
|
contractAddresses,
|
|
14954
15046
|
contractsStorageKeys,
|
|
@@ -14960,9 +15052,9 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
14960
15052
|
/**
|
|
14961
15053
|
* Get the contract class definition in the given block associated with the given hash
|
|
14962
15054
|
*/
|
|
14963
|
-
getCompiledCasm(classHash) {
|
|
14964
|
-
if (this.channel instanceof
|
|
14965
|
-
this.channel.getCompiledCasm(classHash);
|
|
15055
|
+
async getCompiledCasm(classHash) {
|
|
15056
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
15057
|
+
return this.channel.getCompiledCasm(classHash);
|
|
14966
15058
|
}
|
|
14967
15059
|
throw new LibraryError("Unsupported method for RPC version");
|
|
14968
15060
|
}
|
|
@@ -15924,55 +16016,296 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
15924
16016
|
if (!this.pubKey) await this.getPublicKeys();
|
|
15925
16017
|
return this.pubKey;
|
|
15926
16018
|
}
|
|
15927
|
-
/**
|
|
15928
|
-
* provides the full public key (with parity prefix)
|
|
15929
|
-
* @returns an hex string : 2 first characters are the parity, the 64 following characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
15930
|
-
* @example
|
|
15931
|
-
* ```typescript
|
|
15932
|
-
* const result = await myLedgerSigner.getFullPubKey();
|
|
15933
|
-
* // result= "0x0403681417ba3e1f050dd3ccdceb8d22b5e44fa70ee7844d472c6a768bded5174e03cbc86f805dcfcb0c1922dd4daf181afa289d86223a18bc856276615bcc7787"
|
|
15934
|
-
* ```
|
|
15935
|
-
*/
|
|
15936
|
-
async getFullPubKey() {
|
|
15937
|
-
if (!this.fullPubKey) await this.getPublicKeys();
|
|
15938
|
-
return this.fullPubKey;
|
|
16019
|
+
/**
|
|
16020
|
+
* provides the full public key (with parity prefix)
|
|
16021
|
+
* @returns an hex string : 2 first characters are the parity, the 64 following characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
16022
|
+
* @example
|
|
16023
|
+
* ```typescript
|
|
16024
|
+
* const result = await myLedgerSigner.getFullPubKey();
|
|
16025
|
+
* // result= "0x0403681417ba3e1f050dd3ccdceb8d22b5e44fa70ee7844d472c6a768bded5174e03cbc86f805dcfcb0c1922dd4daf181afa289d86223a18bc856276615bcc7787"
|
|
16026
|
+
* ```
|
|
16027
|
+
*/
|
|
16028
|
+
async getFullPubKey() {
|
|
16029
|
+
if (!this.fullPubKey) await this.getPublicKeys();
|
|
16030
|
+
return this.fullPubKey;
|
|
16031
|
+
}
|
|
16032
|
+
/**
|
|
16033
|
+
* Returns the version of the Starknet APP implemented in the Ledger.
|
|
16034
|
+
* @returns {string} version.
|
|
16035
|
+
* @example
|
|
16036
|
+
* ```typescript
|
|
16037
|
+
* const result = await myLedgerSigner.getAppVersion();
|
|
16038
|
+
* // result= "1.1.1"
|
|
16039
|
+
* ```
|
|
16040
|
+
*/
|
|
16041
|
+
async getAppVersion() {
|
|
16042
|
+
if (!this.appVersion) {
|
|
16043
|
+
const resp = await this._transporter.send(Number("0x5a"), 0, 0, 0);
|
|
16044
|
+
this.appVersion = `${resp[0]}.${resp[1]}.${resp[2]}`;
|
|
16045
|
+
}
|
|
16046
|
+
return this.appVersion;
|
|
16047
|
+
}
|
|
16048
|
+
/**
|
|
16049
|
+
* Sign a TypedData message (SNIP-12) in a Ledger.
|
|
16050
|
+
* @param {typedDataToHash} typedDataToHash A TypedData message compatible with SNIP-12.
|
|
16051
|
+
* @param {string} accountAddress Signer account address (Hex or num string)
|
|
16052
|
+
* @returns {Signature} The signed message.
|
|
16053
|
+
* @example
|
|
16054
|
+
* ```typescript
|
|
16055
|
+
* const result = myLedgerSigner.signMessage(snip12Message, account0.address);
|
|
16056
|
+
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16057
|
+
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16058
|
+
* // recovery: 0}
|
|
16059
|
+
* ```
|
|
16060
|
+
*/
|
|
16061
|
+
async signMessage(typedDataToHash, accountAddress) {
|
|
16062
|
+
const msgHash = getMessageHash(typedDataToHash, accountAddress);
|
|
16063
|
+
return this.signRaw(msgHash);
|
|
16064
|
+
}
|
|
16065
|
+
/**
|
|
16066
|
+
* Sign in a Ledger a V1 or a V3 transaction. This is a blind sign on the Ledger screen.
|
|
16067
|
+
* @param {Call1[]} transactions An array of `Call` transactions (generated for example by `myContract.populate()`).
|
|
16068
|
+
* @param {InvocationsSignerDetails} transactionsDetail An object that includes all the necessary inputs to hash the transaction. Can be `V2InvocationsSignerDetails` or `V3InvocationsSignerDetails` type.
|
|
16069
|
+
* @returns {Signature} The signed transaction.
|
|
16070
|
+
* @example
|
|
16071
|
+
* ```typescript
|
|
16072
|
+
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
16073
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
16074
|
+
* nonce: "28",
|
|
16075
|
+
* accountDeploymentData: [],
|
|
16076
|
+
* paymasterData: [],
|
|
16077
|
+
* cairoVersion: "1",
|
|
16078
|
+
* feeDataAvailabilityMode: "L1",
|
|
16079
|
+
* nonceDataAvailabilityMode: "L1",
|
|
16080
|
+
* resourceBounds: {
|
|
16081
|
+
* l1_gas: {
|
|
16082
|
+
* max_amount: "0x2a00",
|
|
16083
|
+
* max_price_per_unit: "0x5c00000"
|
|
16084
|
+
* },
|
|
16085
|
+
* l2_gas: {
|
|
16086
|
+
* max_amount: "0x00",
|
|
16087
|
+
* max_price_per_unit: "0x00"
|
|
16088
|
+
* },
|
|
16089
|
+
* },
|
|
16090
|
+
* tip: 0,
|
|
16091
|
+
* version: "0x3",
|
|
16092
|
+
* walletAddress: account0.address
|
|
16093
|
+
* }
|
|
16094
|
+
* const result = myLedgerSigner.signTransaction([call0, call1], txDetailsV3);
|
|
16095
|
+
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16096
|
+
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16097
|
+
* // recovery: 0}
|
|
16098
|
+
* ```
|
|
16099
|
+
*/
|
|
16100
|
+
async signTransaction(transactions, transactionsDetail) {
|
|
16101
|
+
const compiledCalldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
16102
|
+
let msgHash;
|
|
16103
|
+
if (Object.values(ETransactionVersion22).includes(transactionsDetail.version)) {
|
|
16104
|
+
const det = transactionsDetail;
|
|
16105
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
16106
|
+
...det,
|
|
16107
|
+
senderAddress: det.walletAddress,
|
|
16108
|
+
compiledCalldata,
|
|
16109
|
+
version: det.version
|
|
16110
|
+
});
|
|
16111
|
+
} else if (Object.values(ETransactionVersion32).includes(transactionsDetail.version)) {
|
|
16112
|
+
const det = transactionsDetail;
|
|
16113
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
16114
|
+
...det,
|
|
16115
|
+
senderAddress: det.walletAddress,
|
|
16116
|
+
compiledCalldata,
|
|
16117
|
+
version: det.version,
|
|
16118
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16119
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16120
|
+
});
|
|
16121
|
+
} else {
|
|
16122
|
+
throw Error("unsupported signTransaction version");
|
|
16123
|
+
}
|
|
16124
|
+
return this.signRaw(msgHash);
|
|
16125
|
+
}
|
|
16126
|
+
/**
|
|
16127
|
+
* Sign in a Ledger the deployment of a new account. This is a blind sign on the Ledger screen.
|
|
16128
|
+
* @param {DeployAccountSignerDetails} details An object that includes all necessary data to calculate the Hash. It can be `V2DeployAccountSignerDetails` or `V3DeployAccountSignerDetails` types.
|
|
16129
|
+
* @returns {Signature} The deploy account signature.
|
|
16130
|
+
* @example
|
|
16131
|
+
* ```typescript
|
|
16132
|
+
* const result = myLedgerSigner.signDeployAccountTransaction(details);
|
|
16133
|
+
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16134
|
+
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16135
|
+
* // recovery: 0}
|
|
16136
|
+
* ```
|
|
16137
|
+
*/
|
|
16138
|
+
async signDeployAccountTransaction(details) {
|
|
16139
|
+
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
16140
|
+
let msgHash;
|
|
16141
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
16142
|
+
const det = details;
|
|
16143
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
16144
|
+
...det,
|
|
16145
|
+
salt: det.addressSalt,
|
|
16146
|
+
constructorCalldata: compiledConstructorCalldata,
|
|
16147
|
+
version: det.version
|
|
16148
|
+
});
|
|
16149
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
16150
|
+
const det = details;
|
|
16151
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
16152
|
+
...det,
|
|
16153
|
+
salt: det.addressSalt,
|
|
16154
|
+
compiledConstructorCalldata,
|
|
16155
|
+
version: det.version,
|
|
16156
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16157
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16158
|
+
});
|
|
16159
|
+
} else {
|
|
16160
|
+
throw Error("unsupported signDeployAccountTransaction version");
|
|
16161
|
+
}
|
|
16162
|
+
return this.signRaw(msgHash);
|
|
16163
|
+
}
|
|
16164
|
+
/**
|
|
16165
|
+
* Sign in a Ledger the declaration of a new class. This is a blind sign on the Ledger screen.
|
|
16166
|
+
* @param {DeclareSignerDetails} details An object that includes all necessary data to calculate the Hash. It can be `V3DeclareSignerDetails` or `V2DeclareSignerDetails` types.
|
|
16167
|
+
* @returns {Signature} The declare Signature.
|
|
16168
|
+
* @example
|
|
16169
|
+
* ```typescript
|
|
16170
|
+
* const result = myLedgerSigner.signDeclareTransaction(details);
|
|
16171
|
+
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16172
|
+
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16173
|
+
* // recovery: 0}
|
|
16174
|
+
* ```
|
|
16175
|
+
*/
|
|
16176
|
+
async signDeclareTransaction(details) {
|
|
16177
|
+
let msgHash;
|
|
16178
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
16179
|
+
const det = details;
|
|
16180
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
16181
|
+
...det,
|
|
16182
|
+
version: det.version
|
|
16183
|
+
});
|
|
16184
|
+
} else if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
16185
|
+
const det = details;
|
|
16186
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
16187
|
+
...det,
|
|
16188
|
+
version: det.version,
|
|
16189
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16190
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16191
|
+
});
|
|
16192
|
+
} else {
|
|
16193
|
+
throw Error("unsupported signDeclareTransaction version");
|
|
16194
|
+
}
|
|
16195
|
+
return this.signRaw(msgHash);
|
|
16196
|
+
}
|
|
16197
|
+
/**
|
|
16198
|
+
* Internal function to sign a hash in a Ledger Nano.
|
|
16199
|
+
* This is a blind sign in the Ledger ; no display of what you are signing.
|
|
16200
|
+
*/
|
|
16201
|
+
async signRaw(msgHash) {
|
|
16202
|
+
addHexPrefix(
|
|
16203
|
+
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, Buffer.from(this.pathBuffer)))
|
|
16204
|
+
);
|
|
16205
|
+
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
16206
|
+
const buff2 = hexToBytes2(shiftedHash);
|
|
16207
|
+
const respSign2 = Uint8Array.from(
|
|
16208
|
+
await this._transporter.send(Number("0x5a"), 2, 1, 0, Buffer.from(buff2))
|
|
16209
|
+
);
|
|
16210
|
+
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
16211
|
+
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
16212
|
+
const v = respSign2[65];
|
|
16213
|
+
const sign0 = new esm_exports4.Signature(r, s);
|
|
16214
|
+
const sign1 = sign0.addRecoveryBit(v);
|
|
16215
|
+
return sign1;
|
|
16216
|
+
}
|
|
16217
|
+
/** internal function to get both the Starknet public key and the full public key */
|
|
16218
|
+
async getPublicKeys() {
|
|
16219
|
+
const pathBuff = this.pathBuffer;
|
|
16220
|
+
const respGetPublic = Uint8Array.from(
|
|
16221
|
+
await this._transporter.send(Number("0x5a"), 1, 0, 0, Buffer.from(pathBuff))
|
|
16222
|
+
);
|
|
16223
|
+
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
16224
|
+
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
16225
|
+
}
|
|
16226
|
+
};
|
|
16227
|
+
function getLedgerPathBuffer111(accountId, applicationName = "LedgerW") {
|
|
16228
|
+
const path0buff = new Uint8Array([128, 0, 10, 85]);
|
|
16229
|
+
const path1buff = new Uint8Array([71, 65, 233, 201]);
|
|
16230
|
+
const path2buff = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
16231
|
+
const path3buff = new Uint8Array([0, 0, 0, 0]);
|
|
16232
|
+
const hex = toHex(accountId);
|
|
16233
|
+
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
16234
|
+
const path4buff = hexToBytes2(padded);
|
|
16235
|
+
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
16236
|
+
const pathBuff = concatenateArrayBuffer([
|
|
16237
|
+
path0buff,
|
|
16238
|
+
path1buff,
|
|
16239
|
+
path2buff,
|
|
16240
|
+
path3buff,
|
|
16241
|
+
path4buff,
|
|
16242
|
+
path5buff
|
|
16243
|
+
]);
|
|
16244
|
+
return pathBuff;
|
|
16245
|
+
}
|
|
16246
|
+
|
|
16247
|
+
// src/utils/address.ts
|
|
16248
|
+
function addAddressPadding(address) {
|
|
16249
|
+
const hex = toHex(isString(address) ? addHexPrefix(address) : address);
|
|
16250
|
+
const padded = removeHexPrefix(hex).padStart(64, "0");
|
|
16251
|
+
return addHexPrefix(padded);
|
|
16252
|
+
}
|
|
16253
|
+
function validateAndParseAddress(address) {
|
|
16254
|
+
const result = addAddressPadding(address);
|
|
16255
|
+
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
16256
|
+
throw new Error("Invalid Address Format");
|
|
16257
|
+
}
|
|
16258
|
+
assertInRange(result, ZERO, ADDR_BOUND - 1n, "Starknet Address");
|
|
16259
|
+
return result;
|
|
16260
|
+
}
|
|
16261
|
+
function getChecksumAddress(address) {
|
|
16262
|
+
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
16263
|
+
const hex = removeHexPrefix(keccakBn(address));
|
|
16264
|
+
const hashed = hexToBytes(hex.padStart(64, "0"));
|
|
16265
|
+
for (let i = 0; i < chars.length; i += 2) {
|
|
16266
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
16267
|
+
chars[i] = chars[i].toUpperCase();
|
|
16268
|
+
}
|
|
16269
|
+
if ((hashed[i >> 1] & 15) >= 8) {
|
|
16270
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
16271
|
+
}
|
|
15939
16272
|
}
|
|
16273
|
+
return addHexPrefix(chars.join(""));
|
|
16274
|
+
}
|
|
16275
|
+
function validateChecksumAddress(address) {
|
|
16276
|
+
return getChecksumAddress(address) === address;
|
|
16277
|
+
}
|
|
16278
|
+
|
|
16279
|
+
// src/signer/ledgerSigner221.ts
|
|
16280
|
+
var LedgerSigner221 = class extends LedgerSigner111 {
|
|
15940
16281
|
/**
|
|
15941
|
-
*
|
|
15942
|
-
* @
|
|
15943
|
-
*
|
|
16282
|
+
* constructor of the LedgerSigner class.
|
|
16283
|
+
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
16284
|
+
* See Guides for more details.
|
|
16285
|
+
* @param {number} accountID ID of Ledger Nano (can handle 2**31 accounts).
|
|
16286
|
+
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
16287
|
+
* One item is called `application` and can be customized.
|
|
16288
|
+
* Default value is `LedgerW`.
|
|
16289
|
+
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
16290
|
+
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
16291
|
+
*
|
|
16292
|
+
* If you are using APP v2.2.1 with an account created with the v1.1.1, you need to use :
|
|
15944
16293
|
* ```typescript
|
|
15945
|
-
* const
|
|
15946
|
-
* // result= "1.1.1"
|
|
16294
|
+
* const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
15947
16295
|
* ```
|
|
15948
|
-
*/
|
|
15949
|
-
async getAppVersion() {
|
|
15950
|
-
if (!this.appVersion) {
|
|
15951
|
-
const resp = await this._transporter.send(Number("0x5a"), 0, 0, 0);
|
|
15952
|
-
this.appVersion = `${resp[0]}.${resp[1]}.${resp[2]}`;
|
|
15953
|
-
}
|
|
15954
|
-
return this.appVersion;
|
|
15955
|
-
}
|
|
15956
|
-
/**
|
|
15957
|
-
* Sign a TypedData message (SNIP-12) in a Ledger.
|
|
15958
|
-
* @param {typedDataToHash} typedDataToHash A TypedData message compatible with SNIP-12.
|
|
15959
|
-
* @param {string} accountAddress Signer account address (Hex or num string)
|
|
15960
|
-
* @returns {Signature} The signed message.
|
|
15961
16296
|
* @example
|
|
15962
16297
|
* ```typescript
|
|
15963
|
-
*
|
|
15964
|
-
*
|
|
15965
|
-
*
|
|
15966
|
-
* // recovery: 0}
|
|
16298
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
16299
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
16300
|
+
* const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0);
|
|
15967
16301
|
* ```
|
|
15968
16302
|
*/
|
|
15969
|
-
|
|
15970
|
-
|
|
15971
|
-
return this.signRaw(msgHash);
|
|
16303
|
+
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
16304
|
+
super(transport, accountID, eip2645application, pathFunction);
|
|
15972
16305
|
}
|
|
15973
16306
|
/**
|
|
15974
|
-
* Sign in a Ledger a V1 or a V3 transaction.
|
|
15975
|
-
* @param {
|
|
16307
|
+
* Sign in a Ledger a V1 or a V3 transaction. The details are displayed on the Ledger screen.
|
|
16308
|
+
* @param {Call[]} transactions An array of `Call` transactions (generated for example by `myContract.populate()`).
|
|
15976
16309
|
* @param {InvocationsSignerDetails} transactionsDetail An object that includes all the necessary inputs to hash the transaction. Can be `V2InvocationsSignerDetails` or `V3InvocationsSignerDetails` type.
|
|
15977
16310
|
* @returns {Signature} The signed transaction.
|
|
15978
16311
|
* @example
|
|
@@ -16007,18 +16340,24 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16007
16340
|
*/
|
|
16008
16341
|
async signTransaction(transactions, transactionsDetail) {
|
|
16009
16342
|
const compiledCalldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
16010
|
-
let msgHash;
|
|
16011
16343
|
if (Object.values(ETransactionVersion22).includes(transactionsDetail.version)) {
|
|
16012
16344
|
const det = transactionsDetail;
|
|
16013
|
-
msgHash = calculateInvokeTransactionHash2({
|
|
16345
|
+
const msgHash = calculateInvokeTransactionHash2({
|
|
16014
16346
|
...det,
|
|
16015
16347
|
senderAddress: det.walletAddress,
|
|
16016
16348
|
compiledCalldata,
|
|
16017
16349
|
version: det.version
|
|
16018
16350
|
});
|
|
16019
|
-
|
|
16351
|
+
const ledgerResponse = await this.signTxV1(det, transactions);
|
|
16352
|
+
assert(
|
|
16353
|
+
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16354
|
+
"The V1 transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16355
|
+
);
|
|
16356
|
+
return ledgerResponse.signature;
|
|
16357
|
+
}
|
|
16358
|
+
if (Object.values(ETransactionVersion32).includes(transactionsDetail.version)) {
|
|
16020
16359
|
const det = transactionsDetail;
|
|
16021
|
-
msgHash = calculateInvokeTransactionHash2({
|
|
16360
|
+
const msgHash = calculateInvokeTransactionHash2({
|
|
16022
16361
|
...det,
|
|
16023
16362
|
senderAddress: det.walletAddress,
|
|
16024
16363
|
compiledCalldata,
|
|
@@ -16026,118 +16365,413 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16026
16365
|
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16027
16366
|
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16028
16367
|
});
|
|
16029
|
-
|
|
16030
|
-
|
|
16368
|
+
const ledgerResponse = await this.signTxV3(det, transactions);
|
|
16369
|
+
assert(
|
|
16370
|
+
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16371
|
+
"The V3 transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16372
|
+
);
|
|
16373
|
+
return ledgerResponse.signature;
|
|
16031
16374
|
}
|
|
16032
|
-
|
|
16375
|
+
throw Error("unsupported signTransaction version");
|
|
16033
16376
|
}
|
|
16034
16377
|
/**
|
|
16035
|
-
* Sign in a Ledger the deployment of a new account.
|
|
16378
|
+
* Sign in a Ledger the deployment of a new account. The details are displayed on the Ledger screen.
|
|
16036
16379
|
* @param {DeployAccountSignerDetails} details An object that includes all necessary data to calculate the Hash. It can be `V2DeployAccountSignerDetails` or `V3DeployAccountSignerDetails` types.
|
|
16037
16380
|
* @returns {Signature} The deploy account signature.
|
|
16038
16381
|
* @example
|
|
16039
16382
|
* ```typescript
|
|
16040
|
-
* const result = myLedgerSigner.signDeployAccountTransaction(details);
|
|
16041
|
-
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16042
|
-
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16043
|
-
* // recovery: 0}
|
|
16383
|
+
* const result = myLedgerSigner.signDeployAccountTransaction(details);
|
|
16384
|
+
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16385
|
+
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16386
|
+
* // recovery: 0}
|
|
16387
|
+
* ```
|
|
16388
|
+
*/
|
|
16389
|
+
async signDeployAccountTransaction(details) {
|
|
16390
|
+
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
16391
|
+
let msgHash;
|
|
16392
|
+
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
16393
|
+
const det = details;
|
|
16394
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
16395
|
+
...det,
|
|
16396
|
+
salt: det.addressSalt,
|
|
16397
|
+
constructorCalldata: compiledConstructorCalldata,
|
|
16398
|
+
version: det.version
|
|
16399
|
+
});
|
|
16400
|
+
const ledgerResponse = await this.signDeployAccountV1(det);
|
|
16401
|
+
assert(
|
|
16402
|
+
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16403
|
+
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16404
|
+
);
|
|
16405
|
+
return ledgerResponse.signature;
|
|
16406
|
+
}
|
|
16407
|
+
if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
16408
|
+
const det = details;
|
|
16409
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
16410
|
+
...det,
|
|
16411
|
+
salt: det.addressSalt,
|
|
16412
|
+
compiledConstructorCalldata,
|
|
16413
|
+
version: det.version,
|
|
16414
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16415
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16416
|
+
});
|
|
16417
|
+
const ledgerResponse = await this.signDeployAccountV3(det);
|
|
16418
|
+
assert(
|
|
16419
|
+
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16420
|
+
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16421
|
+
);
|
|
16422
|
+
return ledgerResponse.signature;
|
|
16423
|
+
}
|
|
16424
|
+
throw Error("unsupported signDeployAccountTransaction version");
|
|
16425
|
+
}
|
|
16426
|
+
/**
|
|
16427
|
+
* Internal function to convert a bigNumberish to an Uint8array of 256 bits
|
|
16428
|
+
* @param {BigNumberish} input input value
|
|
16429
|
+
* @returns {Uint8Array} a Uint8Array containing 32 bytes.
|
|
16430
|
+
*/
|
|
16431
|
+
convertBnToLedger(input) {
|
|
16432
|
+
return hexToBytes2(addAddressPadding(toHex(input)));
|
|
16433
|
+
}
|
|
16434
|
+
/**
|
|
16435
|
+
* Internal function to decode the response of the Ledger signature
|
|
16436
|
+
* @param {Uint8Array} respSign the Buffer response of the Ledger
|
|
16437
|
+
* @returns { hash: bigint; signature: Signature } transaction hash & signature
|
|
16438
|
+
*/
|
|
16439
|
+
decodeSignatureLedger(respSign) {
|
|
16440
|
+
const h = BigInt(addHexPrefix(buf2hex(respSign.subarray(0, 32))));
|
|
16441
|
+
const r = BigInt(addHexPrefix(buf2hex(respSign.subarray(33, 65))));
|
|
16442
|
+
const s = BigInt(addHexPrefix(buf2hex(respSign.subarray(65, 97))));
|
|
16443
|
+
const v = respSign[97];
|
|
16444
|
+
const sign0 = new esm_exports4.Signature(r, s);
|
|
16445
|
+
const sign1 = sign0.addRecoveryBit(v);
|
|
16446
|
+
return { hash: h, signature: sign1 };
|
|
16447
|
+
}
|
|
16448
|
+
/** Internal function to convert a Call to an array of Uint8Array.
|
|
16449
|
+
* @param {Call} call A Call to convert.
|
|
16450
|
+
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
16451
|
+
*/
|
|
16452
|
+
encodeCall(call) {
|
|
16453
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
16454
|
+
const selectorBuf = hexToBytes2(addAddressPadding(getSelector(call.entrypoint)));
|
|
16455
|
+
let calldataBuf = new Uint8Array([]);
|
|
16456
|
+
if (call.calldata) {
|
|
16457
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
16458
|
+
calldataBuf = concatenateArrayBuffer(
|
|
16459
|
+
compiledCalldata.map((parameter) => {
|
|
16460
|
+
const a = this.convertBnToLedger(parameter);
|
|
16461
|
+
return a;
|
|
16462
|
+
})
|
|
16463
|
+
);
|
|
16464
|
+
}
|
|
16465
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
16466
|
+
const calldatas = [];
|
|
16467
|
+
const chunkSize = 7 * 32;
|
|
16468
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
16469
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
16470
|
+
return calldatas;
|
|
16471
|
+
}
|
|
16472
|
+
/**
|
|
16473
|
+
* Ask the Ledger Nano to display and sign a Starknet V1 transaction.
|
|
16474
|
+
* @param {V2InvocationsSignerDetails} txDetails All the details needed for a txV1.
|
|
16475
|
+
* @param {Call[]} calls array of Starknet invocations
|
|
16476
|
+
* @returns an object including the transaction Hash and the signature
|
|
16477
|
+
* @example
|
|
16478
|
+
* ```typescript
|
|
16479
|
+
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
16480
|
+
* entrypoint: "transfer",
|
|
16481
|
+
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
16482
|
+
* "0x9184e72a000", "0x0"]}];
|
|
16483
|
+
* const txDet: V2InvocationsSignerDetails = {
|
|
16484
|
+
* walletAddress: txDetails.accountAddress,
|
|
16485
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
16486
|
+
* cairoVersion: "1", maxFee: txDetails.max_fee,
|
|
16487
|
+
* nonce: txDetails.nonce, version: "0x1"
|
|
16488
|
+
* };
|
|
16489
|
+
* const res = await myLedgerSigner.signTxV1(txDet, calls);
|
|
16490
|
+
* // res = {hash:
|
|
16491
|
+
* // signature:
|
|
16492
|
+
* // }
|
|
16493
|
+
* ```
|
|
16494
|
+
*/
|
|
16495
|
+
async signTxV1(txDetails, calls) {
|
|
16496
|
+
await this._transporter.send(Number("0x5a"), 4, 0, 0, Buffer.from(this.pathBuffer));
|
|
16497
|
+
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
16498
|
+
const maxFeeBuf = this.convertBnToLedger(txDetails.maxFee);
|
|
16499
|
+
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
16500
|
+
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
16501
|
+
const dataBuf = concatenateArrayBuffer([
|
|
16502
|
+
accountAddressBuf,
|
|
16503
|
+
maxFeeBuf,
|
|
16504
|
+
chainIdBuf,
|
|
16505
|
+
nonceBuf
|
|
16506
|
+
]);
|
|
16507
|
+
await this._transporter.send(Number("0x5a"), 4, 1, 0, Buffer.from(dataBuf));
|
|
16508
|
+
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
16509
|
+
await this._transporter.send(Number("0x5a"), 4, 2, 0, Buffer.from(nbCallsBuf));
|
|
16510
|
+
let respSign = new Uint8Array(0);
|
|
16511
|
+
for (const call of calls) {
|
|
16512
|
+
const calldatas = this.encodeCall(call);
|
|
16513
|
+
await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
16514
|
+
if (calldatas.length > 1) {
|
|
16515
|
+
calldatas.slice(1).forEach(async (part) => {
|
|
16516
|
+
await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
16517
|
+
});
|
|
16518
|
+
}
|
|
16519
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 2);
|
|
16520
|
+
}
|
|
16521
|
+
return this.decodeSignatureLedger(respSign);
|
|
16522
|
+
}
|
|
16523
|
+
/**
|
|
16524
|
+
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
16525
|
+
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
16526
|
+
* @param {Call[]} calls array of Starknet invocations
|
|
16527
|
+
* @returns an object including the transaction Hash and the signature
|
|
16528
|
+
* @example
|
|
16529
|
+
* ```typescript
|
|
16530
|
+
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
16531
|
+
* entrypoint: "transfer",
|
|
16532
|
+
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
16533
|
+
* "0x9184e72a000", "0x0"]}];
|
|
16534
|
+
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
16535
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
16536
|
+
* nonce: "28", accountDeploymentData: [],
|
|
16537
|
+
* paymasterData: [], cairoVersion: "1",
|
|
16538
|
+
* feeDataAvailabilityMode: "L1", nonceDataAvailabilityMode: "L1",
|
|
16539
|
+
* resourceBounds: {
|
|
16540
|
+
* l1_gas: { max_amount: "0x2a00", max_price_per_unit: "0x5c00000"
|
|
16541
|
+
* },
|
|
16542
|
+
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
16543
|
+
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
16544
|
+
* };
|
|
16545
|
+
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
16546
|
+
* // res = {hash:
|
|
16547
|
+
* // signature:
|
|
16548
|
+
* // }
|
|
16044
16549
|
* ```
|
|
16045
16550
|
*/
|
|
16046
|
-
async
|
|
16047
|
-
|
|
16048
|
-
|
|
16049
|
-
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
|
|
16053
|
-
|
|
16054
|
-
|
|
16055
|
-
|
|
16056
|
-
|
|
16057
|
-
|
|
16058
|
-
|
|
16059
|
-
|
|
16060
|
-
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
|
|
16066
|
-
|
|
16067
|
-
|
|
16068
|
-
|
|
16551
|
+
async signTxV3(txDetails, calls) {
|
|
16552
|
+
assert(txDetails.paymasterData.length <= 7, "Paymaster data includes more than 7 items.");
|
|
16553
|
+
assert(
|
|
16554
|
+
txDetails.accountDeploymentData.length <= 7,
|
|
16555
|
+
"accountDeploymentData includes more than 7 items"
|
|
16556
|
+
);
|
|
16557
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
|
|
16558
|
+
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
16559
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16560
|
+
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
16561
|
+
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
16562
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
16563
|
+
hashDAMode(
|
|
16564
|
+
txDetails.nonceDataAvailabilityMode === EDataAvailabilityMode2.L1 ? EDAMode2.L1 : EDAMode2.L2,
|
|
16565
|
+
txDetails.feeDataAvailabilityMode === EDataAvailabilityMode2.L1 ? EDAMode2.L1 : EDAMode2.L2
|
|
16566
|
+
)
|
|
16567
|
+
);
|
|
16568
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
16569
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
16570
|
+
const dataBuf = concatenateArrayBuffer([
|
|
16571
|
+
accountAddressBuf,
|
|
16572
|
+
tipBuf,
|
|
16573
|
+
l1_gasBuf,
|
|
16574
|
+
l2_gasBuf,
|
|
16575
|
+
chainIdBuf,
|
|
16576
|
+
nonceBuf,
|
|
16577
|
+
dAModeHashBuf
|
|
16578
|
+
]);
|
|
16579
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
|
|
16580
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
16581
|
+
txDetails.paymasterData.map((value) => {
|
|
16582
|
+
const a = this.convertBnToLedger(value);
|
|
16583
|
+
return a;
|
|
16584
|
+
})
|
|
16585
|
+
);
|
|
16586
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(paymasterBuf));
|
|
16587
|
+
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
16588
|
+
txDetails.paymasterData.map((value) => {
|
|
16589
|
+
const a = this.convertBnToLedger(value);
|
|
16590
|
+
return a;
|
|
16591
|
+
})
|
|
16592
|
+
);
|
|
16593
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(accountDeployDataBuf));
|
|
16594
|
+
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
16595
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(nbCallsBuf));
|
|
16596
|
+
let respSign = new Uint8Array(0);
|
|
16597
|
+
for (const call of calls) {
|
|
16598
|
+
const calldatas = this.encodeCall(call);
|
|
16599
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(calldatas[0]));
|
|
16600
|
+
if (calldatas.length > 1) {
|
|
16601
|
+
calldatas.slice(1).forEach(async (part) => {
|
|
16602
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, Buffer.from(part));
|
|
16603
|
+
});
|
|
16604
|
+
}
|
|
16605
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
16069
16606
|
}
|
|
16070
|
-
return this.
|
|
16607
|
+
return this.decodeSignatureLedger(respSign);
|
|
16071
16608
|
}
|
|
16072
16609
|
/**
|
|
16073
|
-
*
|
|
16074
|
-
* @param {
|
|
16075
|
-
* @returns
|
|
16610
|
+
* Ask the Ledger Nano to display and sign a Starknet V1 account deployment.
|
|
16611
|
+
* @param {V2DeployAccountSignerDetails} deployAccountDetail All the details needed for a V1 deploy account.
|
|
16612
|
+
* @returns an object including the transaction Hash and the signature
|
|
16076
16613
|
* @example
|
|
16077
16614
|
* ```typescript
|
|
16078
|
-
* const
|
|
16079
|
-
*
|
|
16080
|
-
*
|
|
16081
|
-
*
|
|
16615
|
+
* const deployData: V2DeployAccountSignerDetails =
|
|
16616
|
+
* {
|
|
16617
|
+
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
16618
|
+
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
16619
|
+
* resourceBounds: {
|
|
16620
|
+
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
16621
|
+
* l1_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }
|
|
16622
|
+
* },
|
|
16623
|
+
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
16624
|
+
* constructorCalldata: [
|
|
16625
|
+
* '89832696000889662999767022750851886674077821293893187900664573372145410755'
|
|
16626
|
+
* ],
|
|
16627
|
+
* contractAddress: '0x32c60fba64eb96831d064bbb2319375b7b7381543abe66da872e4344bcd72a0',
|
|
16628
|
+
* addressSalt: '0x0032d7efe2a9232f9b463e7206c68fdea4aeb13fec0cb308c6ba1d197d5922c3',
|
|
16629
|
+
* chainId: '0x534e5f5345504f4c4941', maxFee: 55050000000000n,
|
|
16630
|
+
* version: '0x1', nonce: 0n
|
|
16631
|
+
*}
|
|
16632
|
+
* const res = await myLedgerSigner.signDeployAccountV1(deployData);
|
|
16633
|
+
* // res = {hash:
|
|
16634
|
+
* // signature:
|
|
16635
|
+
* // }
|
|
16082
16636
|
* ```
|
|
16083
16637
|
*/
|
|
16084
|
-
async
|
|
16085
|
-
|
|
16086
|
-
|
|
16087
|
-
|
|
16088
|
-
|
|
16089
|
-
|
|
16090
|
-
|
|
16091
|
-
|
|
16092
|
-
|
|
16093
|
-
|
|
16094
|
-
|
|
16095
|
-
|
|
16096
|
-
|
|
16097
|
-
|
|
16098
|
-
|
|
16099
|
-
|
|
16100
|
-
|
|
16101
|
-
|
|
16638
|
+
async signDeployAccountV1(deployAccountDetail) {
|
|
16639
|
+
await this._transporter.send(Number("0x5a"), 6, 0, 0, Buffer.from(this.pathBuffer));
|
|
16640
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
16641
|
+
deployAccountDetail.contractAddress
|
|
16642
|
+
);
|
|
16643
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
16644
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
16645
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
16646
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
16647
|
+
const dataBuf = concatenateArrayBuffer([
|
|
16648
|
+
accountAddressBuf,
|
|
16649
|
+
classHashBuf,
|
|
16650
|
+
saltBuf,
|
|
16651
|
+
chainIdBuf,
|
|
16652
|
+
nonceBuf
|
|
16653
|
+
]);
|
|
16654
|
+
await this._transporter.send(Number("0x5a"), 6, 1, 0, Buffer.from(dataBuf));
|
|
16655
|
+
const maxFreeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
16656
|
+
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(maxFreeBuf));
|
|
16657
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
16658
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
16659
|
+
await this._transporter.send(Number("0x5a"), 6, 3, 0, Buffer.from(constructorLengthBuf));
|
|
16660
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
16661
|
+
compiledConstructor.map((parameter) => {
|
|
16662
|
+
const a = this.convertBnToLedger(parameter);
|
|
16663
|
+
return a;
|
|
16664
|
+
})
|
|
16665
|
+
);
|
|
16666
|
+
const constructorChunks = [];
|
|
16667
|
+
const chunkSize = 7 * 32;
|
|
16668
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
16669
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
16670
|
+
let respSign = new Uint8Array(0);
|
|
16671
|
+
for (const chunk of constructorChunks) {
|
|
16672
|
+
respSign = await this._transporter.send(Number("0x5a"), 6, 4, 0, Buffer.from(chunk));
|
|
16102
16673
|
}
|
|
16103
|
-
return this.
|
|
16674
|
+
return this.decodeSignatureLedger(respSign);
|
|
16104
16675
|
}
|
|
16105
16676
|
/**
|
|
16106
|
-
*
|
|
16107
|
-
*
|
|
16677
|
+
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
16678
|
+
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
16679
|
+
* @returns an object including the transaction Hash and the signature
|
|
16680
|
+
* @example
|
|
16681
|
+
* ```typescript
|
|
16682
|
+
* const deployData: V3DeployAccountSignerDetails =
|
|
16683
|
+
* {
|
|
16684
|
+
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
16685
|
+
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
16686
|
+
* resourceBounds: {
|
|
16687
|
+
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
16688
|
+
* l1_gas: { max_amount: '0x226', max_price_per_unit: '0x22ecb25c00' }
|
|
16689
|
+
* },
|
|
16690
|
+
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
16691
|
+
* constructorCalldata: [
|
|
16692
|
+
* '3571125127744830445572285574469842579401255431821644822726857471463672199621'
|
|
16693
|
+
* ],
|
|
16694
|
+
* contractAddress: '0x4ca062add1cf12a107be1107af17981cf6e544a24d987693230ea481d3d5e34',
|
|
16695
|
+
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
16696
|
+
* chainId: '0x534e5f5345504f4c4941', maxFee: 0,
|
|
16697
|
+
* version: '0x3', nonce: 0n
|
|
16698
|
+
*}
|
|
16699
|
+
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
16700
|
+
* // res = {hash:
|
|
16701
|
+
* // signature:
|
|
16702
|
+
* // }
|
|
16703
|
+
* ```
|
|
16108
16704
|
*/
|
|
16109
|
-
async
|
|
16110
|
-
|
|
16111
|
-
|
|
16705
|
+
async signDeployAccountV3(deployAccountDetail) {
|
|
16706
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, Buffer.from(this.pathBuffer));
|
|
16707
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
16708
|
+
deployAccountDetail.contractAddress
|
|
16112
16709
|
);
|
|
16113
|
-
const
|
|
16114
|
-
const
|
|
16115
|
-
const
|
|
16116
|
-
|
|
16710
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
16711
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
16712
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
16713
|
+
hashDAMode(
|
|
16714
|
+
deployAccountDetail.nonceDataAvailabilityMode === EDataAvailabilityMode2.L1 ? EDAMode2.L1 : EDAMode2.L2,
|
|
16715
|
+
deployAccountDetail.feeDataAvailabilityMode === EDataAvailabilityMode2.L1 ? EDAMode2.L1 : EDAMode2.L2
|
|
16716
|
+
)
|
|
16717
|
+
);
|
|
16718
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
16719
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
16720
|
+
const dataBuf = concatenateArrayBuffer([
|
|
16721
|
+
accountAddressBuf,
|
|
16722
|
+
chainIdBuf,
|
|
16723
|
+
nonceBuf,
|
|
16724
|
+
dAModeHashBuf,
|
|
16725
|
+
classHashBuf,
|
|
16726
|
+
saltBuf
|
|
16727
|
+
]);
|
|
16728
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
|
|
16729
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
16730
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
16731
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
16732
|
+
);
|
|
16733
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
16734
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
16117
16735
|
);
|
|
16118
|
-
const
|
|
16119
|
-
|
|
16120
|
-
const
|
|
16121
|
-
|
|
16122
|
-
|
|
16123
|
-
|
|
16124
|
-
|
|
16125
|
-
/** internal function to get both the Starknet public key and the full public key */
|
|
16126
|
-
async getPublicKeys() {
|
|
16127
|
-
const pathBuff = this.pathBuffer;
|
|
16128
|
-
const respGetPublic = Uint8Array.from(
|
|
16129
|
-
await this._transporter.send(Number("0x5a"), 1, 0, 0, Buffer.from(pathBuff))
|
|
16736
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
16737
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
16738
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
16739
|
+
deployAccountDetail.paymasterData.map((value) => {
|
|
16740
|
+
const a = this.convertBnToLedger(value);
|
|
16741
|
+
return a;
|
|
16742
|
+
})
|
|
16130
16743
|
);
|
|
16131
|
-
this.
|
|
16132
|
-
|
|
16744
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, Buffer.from(paymasterBuf));
|
|
16745
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
16746
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
16747
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, Buffer.from(constructorLengthBuf));
|
|
16748
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
16749
|
+
compiledConstructor.map((parameter) => {
|
|
16750
|
+
const a = this.convertBnToLedger(parameter);
|
|
16751
|
+
return a;
|
|
16752
|
+
})
|
|
16753
|
+
);
|
|
16754
|
+
const constructorChunks = [];
|
|
16755
|
+
const chunkSize = 7 * 32;
|
|
16756
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
16757
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
16758
|
+
let respSign = new Uint8Array(0);
|
|
16759
|
+
for (const chunk of constructorChunks) {
|
|
16760
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, Buffer.from(chunk));
|
|
16761
|
+
}
|
|
16762
|
+
return this.decodeSignatureLedger(respSign);
|
|
16133
16763
|
}
|
|
16134
16764
|
};
|
|
16135
|
-
function
|
|
16136
|
-
const path0buff = new Uint8Array([
|
|
16137
|
-
const path1buff = new Uint8Array([71, 65, 233, 201]);
|
|
16138
|
-
const
|
|
16139
|
-
const
|
|
16140
|
-
|
|
16765
|
+
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
16766
|
+
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
16767
|
+
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
16768
|
+
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
16769
|
+
const path2buff = concatenateArrayBuffer([
|
|
16770
|
+
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
16771
|
+
path2Base.subarray(1)
|
|
16772
|
+
]);
|
|
16773
|
+
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
16774
|
+
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
16141
16775
|
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
16142
16776
|
const path4buff = hexToBytes2(padded);
|
|
16143
16777
|
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
@@ -16152,230 +16786,32 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16152
16786
|
return pathBuff;
|
|
16153
16787
|
}
|
|
16154
16788
|
|
|
16155
|
-
// src/
|
|
16156
|
-
|
|
16157
|
-
const hex = toHex(isString(address) ? addHexPrefix(address) : address);
|
|
16158
|
-
const padded = removeHexPrefix(hex).padStart(64, "0");
|
|
16159
|
-
return addHexPrefix(padded);
|
|
16160
|
-
}
|
|
16161
|
-
function validateAndParseAddress(address) {
|
|
16162
|
-
const result = addAddressPadding(address);
|
|
16163
|
-
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
16164
|
-
throw new Error("Invalid Address Format");
|
|
16165
|
-
}
|
|
16166
|
-
assertInRange(result, ZERO, ADDR_BOUND - 1n, "Starknet Address");
|
|
16167
|
-
return result;
|
|
16168
|
-
}
|
|
16169
|
-
function getChecksumAddress(address) {
|
|
16170
|
-
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
16171
|
-
const hex = removeHexPrefix(keccakBn(address));
|
|
16172
|
-
const hashed = hexToBytes(hex.padStart(64, "0"));
|
|
16173
|
-
for (let i = 0; i < chars.length; i += 2) {
|
|
16174
|
-
if (hashed[i >> 1] >> 4 >= 8) {
|
|
16175
|
-
chars[i] = chars[i].toUpperCase();
|
|
16176
|
-
}
|
|
16177
|
-
if ((hashed[i >> 1] & 15) >= 8) {
|
|
16178
|
-
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
16179
|
-
}
|
|
16180
|
-
}
|
|
16181
|
-
return addHexPrefix(chars.join(""));
|
|
16182
|
-
}
|
|
16183
|
-
function validateChecksumAddress(address) {
|
|
16184
|
-
return getChecksumAddress(address) === address;
|
|
16185
|
-
}
|
|
16186
|
-
|
|
16187
|
-
// src/signer/ledgerSigner221.ts
|
|
16188
|
-
var LedgerSigner221 = class extends LedgerSigner111 {
|
|
16789
|
+
// src/signer/ledgerSigner231.ts
|
|
16790
|
+
var LedgerSigner231 = class extends LedgerSigner221 {
|
|
16189
16791
|
/**
|
|
16190
16792
|
* constructor of the LedgerSigner class.
|
|
16191
16793
|
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
16192
16794
|
* See Guides for more details.
|
|
16193
|
-
* @param {number} accountID ID of Ledger Nano (can handle 2**31 accounts).
|
|
16795
|
+
* @param {number} accountID ID of Ledger Nano account (can handle 2**31 accounts).
|
|
16194
16796
|
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
16195
16797
|
* One item is called `application` and can be customized.
|
|
16196
|
-
* Default value is `LedgerW`.
|
|
16197
|
-
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
16198
|
-
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
16199
|
-
*
|
|
16200
|
-
* If you are using APP v2.
|
|
16201
|
-
* ```typescript
|
|
16202
|
-
* const myLedgerSigner = new
|
|
16203
|
-
* ```
|
|
16204
|
-
* @example
|
|
16205
|
-
* ```typescript
|
|
16206
|
-
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
16207
|
-
* const myNodeTransport = await TransportNodeHid.create();
|
|
16208
|
-
* const myLedgerSigner = new
|
|
16209
|
-
* ```
|
|
16210
|
-
*/
|
|
16211
|
-
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
16212
|
-
super(transport, accountID, eip2645application, pathFunction);
|
|
16213
|
-
}
|
|
16214
|
-
/**
|
|
16215
|
-
* Sign in a Ledger a V1 or a V3 transaction. The details are displayed on the Ledger screen.
|
|
16216
|
-
* @param {Call[]} transactions An array of `Call` transactions (generated for example by `myContract.populate()`).
|
|
16217
|
-
* @param {InvocationsSignerDetails} transactionsDetail An object that includes all the necessary inputs to hash the transaction. Can be `V2InvocationsSignerDetails` or `V3InvocationsSignerDetails` type.
|
|
16218
|
-
* @returns {Signature} The signed transaction.
|
|
16219
|
-
* @example
|
|
16220
|
-
* ```typescript
|
|
16221
|
-
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
16222
|
-
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
16223
|
-
* nonce: "28",
|
|
16224
|
-
* accountDeploymentData: [],
|
|
16225
|
-
* paymasterData: [],
|
|
16226
|
-
* cairoVersion: "1",
|
|
16227
|
-
* feeDataAvailabilityMode: "L1",
|
|
16228
|
-
* nonceDataAvailabilityMode: "L1",
|
|
16229
|
-
* resourceBounds: {
|
|
16230
|
-
* l1_gas: {
|
|
16231
|
-
* max_amount: "0x2a00",
|
|
16232
|
-
* max_price_per_unit: "0x5c00000"
|
|
16233
|
-
* },
|
|
16234
|
-
* l2_gas: {
|
|
16235
|
-
* max_amount: "0x00",
|
|
16236
|
-
* max_price_per_unit: "0x00"
|
|
16237
|
-
* },
|
|
16238
|
-
* },
|
|
16239
|
-
* tip: 0,
|
|
16240
|
-
* version: "0x3",
|
|
16241
|
-
* walletAddress: account0.address
|
|
16242
|
-
* }
|
|
16243
|
-
* const result = myLedgerSigner.signTransaction([call0, call1], txDetailsV3);
|
|
16244
|
-
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16245
|
-
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16246
|
-
* // recovery: 0}
|
|
16247
|
-
* ```
|
|
16248
|
-
*/
|
|
16249
|
-
async signTransaction(transactions, transactionsDetail) {
|
|
16250
|
-
const compiledCalldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
16251
|
-
if (Object.values(ETransactionVersion22).includes(transactionsDetail.version)) {
|
|
16252
|
-
const det = transactionsDetail;
|
|
16253
|
-
const msgHash = calculateInvokeTransactionHash2({
|
|
16254
|
-
...det,
|
|
16255
|
-
senderAddress: det.walletAddress,
|
|
16256
|
-
compiledCalldata,
|
|
16257
|
-
version: det.version
|
|
16258
|
-
});
|
|
16259
|
-
const ledgerResponse = await this.signTxV1(det, transactions);
|
|
16260
|
-
assert(
|
|
16261
|
-
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16262
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16263
|
-
);
|
|
16264
|
-
return ledgerResponse.signature;
|
|
16265
|
-
}
|
|
16266
|
-
if (Object.values(ETransactionVersion32).includes(transactionsDetail.version)) {
|
|
16267
|
-
const det = transactionsDetail;
|
|
16268
|
-
const msgHash = calculateInvokeTransactionHash2({
|
|
16269
|
-
...det,
|
|
16270
|
-
senderAddress: det.walletAddress,
|
|
16271
|
-
compiledCalldata,
|
|
16272
|
-
version: det.version,
|
|
16273
|
-
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16274
|
-
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16275
|
-
});
|
|
16276
|
-
const ledgerResponse = await this.signTxV3(det, transactions);
|
|
16277
|
-
assert(
|
|
16278
|
-
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16279
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16280
|
-
);
|
|
16281
|
-
return ledgerResponse.signature;
|
|
16282
|
-
}
|
|
16283
|
-
throw Error("unsupported signTransaction version");
|
|
16284
|
-
}
|
|
16285
|
-
/**
|
|
16286
|
-
* Sign in a Ledger the deployment of a new account. The details are displayed on the Ledger screen.
|
|
16287
|
-
* @param {DeployAccountSignerDetails} details An object that includes all necessary data to calculate the Hash. It can be `V2DeployAccountSignerDetails` or `V3DeployAccountSignerDetails` types.
|
|
16288
|
-
* @returns {Signature} The deploy account signature.
|
|
16289
|
-
* @example
|
|
16290
|
-
* ```typescript
|
|
16291
|
-
* const result = myLedgerSigner.signDeployAccountTransaction(details);
|
|
16292
|
-
* // result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
|
|
16293
|
-
* // s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
|
|
16294
|
-
* // recovery: 0}
|
|
16295
|
-
* ```
|
|
16296
|
-
*/
|
|
16297
|
-
async signDeployAccountTransaction(details) {
|
|
16298
|
-
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
16299
|
-
let msgHash;
|
|
16300
|
-
if (Object.values(ETransactionVersion22).includes(details.version)) {
|
|
16301
|
-
const det = details;
|
|
16302
|
-
msgHash = calculateDeployAccountTransactionHash3({
|
|
16303
|
-
...det,
|
|
16304
|
-
salt: det.addressSalt,
|
|
16305
|
-
constructorCalldata: compiledConstructorCalldata,
|
|
16306
|
-
version: det.version
|
|
16307
|
-
});
|
|
16308
|
-
const ledgerResponse = await this.signDeployAccountV1(det);
|
|
16309
|
-
assert(
|
|
16310
|
-
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16311
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16312
|
-
);
|
|
16313
|
-
return ledgerResponse.signature;
|
|
16314
|
-
}
|
|
16315
|
-
if (Object.values(ETransactionVersion32).includes(details.version)) {
|
|
16316
|
-
const det = details;
|
|
16317
|
-
msgHash = calculateDeployAccountTransactionHash3({
|
|
16318
|
-
...det,
|
|
16319
|
-
salt: det.addressSalt,
|
|
16320
|
-
compiledConstructorCalldata,
|
|
16321
|
-
version: det.version,
|
|
16322
|
-
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
16323
|
-
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
16324
|
-
});
|
|
16325
|
-
const ledgerResponse = await this.signDeployAccountV3(det);
|
|
16326
|
-
assert(
|
|
16327
|
-
toBigInt(msgHash) === ledgerResponse.hash,
|
|
16328
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
16329
|
-
);
|
|
16330
|
-
return ledgerResponse.signature;
|
|
16331
|
-
}
|
|
16332
|
-
throw Error("unsupported signDeployAccountTransaction version");
|
|
16333
|
-
}
|
|
16334
|
-
/**
|
|
16335
|
-
* Internal function to convert a bigNumberish to an Uint8array of 256 bits
|
|
16336
|
-
* @param {BigNumberish} input input value
|
|
16337
|
-
* @returns {Uint8Array} a Uint8Array containing 32 bytes.
|
|
16338
|
-
*/
|
|
16339
|
-
convertBnToLedger(input) {
|
|
16340
|
-
return hexToBytes2(addAddressPadding(toHex(input)));
|
|
16341
|
-
}
|
|
16342
|
-
/**
|
|
16343
|
-
* Internal function to decode the response of the Ledger signature
|
|
16344
|
-
* @param {Uint8Array} respSign the Buffer response of the Ledger
|
|
16345
|
-
* @returns { hash: bigint; signature: Signature } transaction hash & signature
|
|
16346
|
-
*/
|
|
16347
|
-
decodeSignatureLedger(respSign) {
|
|
16348
|
-
const h = BigInt(addHexPrefix(buf2hex(respSign.subarray(0, 32))));
|
|
16349
|
-
const r = BigInt(addHexPrefix(buf2hex(respSign.subarray(33, 65))));
|
|
16350
|
-
const s = BigInt(addHexPrefix(buf2hex(respSign.subarray(65, 97))));
|
|
16351
|
-
const v = respSign[97];
|
|
16352
|
-
const sign0 = new esm_exports4.Signature(r, s);
|
|
16353
|
-
const sign1 = sign0.addRecoveryBit(v);
|
|
16354
|
-
return { hash: h, signature: sign1 };
|
|
16355
|
-
}
|
|
16356
|
-
/** Internal function to convert a Call to an array of Uint8Array.
|
|
16357
|
-
* @param {Call} call A Call to convert.
|
|
16358
|
-
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
16798
|
+
* Default value is `LedgerW`.
|
|
16799
|
+
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
16800
|
+
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
16801
|
+
*
|
|
16802
|
+
* If you are using APP v2.3.1 with an account created with the v1.1.1, you need to use :
|
|
16803
|
+
* ```typescript
|
|
16804
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
16805
|
+
* ```
|
|
16806
|
+
* @example
|
|
16807
|
+
* ```typescript
|
|
16808
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
16809
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
16810
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0);
|
|
16811
|
+
* ```
|
|
16359
16812
|
*/
|
|
16360
|
-
|
|
16361
|
-
|
|
16362
|
-
const selectorBuf = hexToBytes2(addAddressPadding(getSelector(call.entrypoint)));
|
|
16363
|
-
let calldataBuf = new Uint8Array([]);
|
|
16364
|
-
if (call.calldata) {
|
|
16365
|
-
const compiledCalldata = CallData.compile(call.calldata);
|
|
16366
|
-
calldataBuf = concatenateArrayBuffer(
|
|
16367
|
-
compiledCalldata.map((parameter) => {
|
|
16368
|
-
const a = this.convertBnToLedger(parameter);
|
|
16369
|
-
return a;
|
|
16370
|
-
})
|
|
16371
|
-
);
|
|
16372
|
-
}
|
|
16373
|
-
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
16374
|
-
const calldatas = [];
|
|
16375
|
-
const chunkSize = 7 * 32;
|
|
16376
|
-
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
16377
|
-
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
16378
|
-
return calldatas;
|
|
16813
|
+
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
16814
|
+
super(transport, accountID, eip2645application, pathFunction);
|
|
16379
16815
|
}
|
|
16380
16816
|
/**
|
|
16381
16817
|
* Ask the Ledger Nano to display and sign a Starknet V1 transaction.
|
|
@@ -16418,18 +16854,17 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16418
16854
|
let respSign = new Uint8Array(0);
|
|
16419
16855
|
for (const call of calls) {
|
|
16420
16856
|
const calldatas = this.encodeCall(call);
|
|
16421
|
-
await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
16857
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
16422
16858
|
if (calldatas.length > 1) {
|
|
16423
16859
|
calldatas.slice(1).forEach(async (part) => {
|
|
16424
|
-
await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
16860
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
16425
16861
|
});
|
|
16426
16862
|
}
|
|
16427
|
-
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 2);
|
|
16428
16863
|
}
|
|
16429
16864
|
return this.decodeSignatureLedger(respSign);
|
|
16430
16865
|
}
|
|
16431
16866
|
/**
|
|
16432
|
-
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
16867
|
+
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction (Rpc 0.7 & Rpc 0.8).
|
|
16433
16868
|
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
16434
16869
|
* @param {Call[]} calls array of Starknet invocations
|
|
16435
16870
|
* @returns an object including the transaction Hash and the signature
|
|
@@ -16449,7 +16884,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16449
16884
|
* },
|
|
16450
16885
|
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
16451
16886
|
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
16452
|
-
* };
|
|
16887
|
+
* }; // Rpc 0.7 transaction.
|
|
16453
16888
|
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
16454
16889
|
* // res = {hash:
|
|
16455
16890
|
* // signature:
|
|
@@ -16464,53 +16899,67 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16464
16899
|
);
|
|
16465
16900
|
await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
|
|
16466
16901
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
16467
|
-
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16468
16902
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
16469
16903
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
16470
16904
|
const dAModeHashBuf = this.convertBnToLedger(
|
|
16471
16905
|
hashDAMode(
|
|
16472
|
-
txDetails.nonceDataAvailabilityMode
|
|
16473
|
-
txDetails.feeDataAvailabilityMode
|
|
16906
|
+
intDAM(txDetails.nonceDataAvailabilityMode),
|
|
16907
|
+
intDAM(txDetails.feeDataAvailabilityMode)
|
|
16474
16908
|
)
|
|
16475
16909
|
);
|
|
16476
|
-
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
16477
|
-
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
16478
16910
|
const dataBuf = concatenateArrayBuffer([
|
|
16479
16911
|
accountAddressBuf,
|
|
16480
|
-
tipBuf,
|
|
16481
|
-
l1_gasBuf,
|
|
16482
|
-
l2_gasBuf,
|
|
16483
16912
|
chainIdBuf,
|
|
16484
16913
|
nonceBuf,
|
|
16485
16914
|
dAModeHashBuf
|
|
16486
16915
|
]);
|
|
16487
16916
|
await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
|
|
16917
|
+
if (isRPC08_ResourceBounds(txDetails.resourceBounds)) {
|
|
16918
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16919
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
16920
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
16921
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
16922
|
+
encodeDataResourceBoundsL1(txDetails.resourceBounds)
|
|
16923
|
+
);
|
|
16924
|
+
const feeBuf = concatenateArrayBuffer([
|
|
16925
|
+
tipBuf,
|
|
16926
|
+
l1_gasBuf,
|
|
16927
|
+
l2_gasBuf,
|
|
16928
|
+
l1_data_gasBuf
|
|
16929
|
+
]);
|
|
16930
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(feeBuf));
|
|
16931
|
+
} else {
|
|
16932
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16933
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
16934
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
16935
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
16936
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(feeBuf));
|
|
16937
|
+
}
|
|
16488
16938
|
const paymasterBuf = concatenateArrayBuffer(
|
|
16489
16939
|
txDetails.paymasterData.map((value) => {
|
|
16490
16940
|
const a = this.convertBnToLedger(value);
|
|
16491
16941
|
return a;
|
|
16492
16942
|
})
|
|
16493
16943
|
);
|
|
16494
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
16944
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(paymasterBuf));
|
|
16495
16945
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
16496
16946
|
txDetails.paymasterData.map((value) => {
|
|
16497
16947
|
const a = this.convertBnToLedger(value);
|
|
16498
16948
|
return a;
|
|
16499
16949
|
})
|
|
16500
16950
|
);
|
|
16501
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
16951
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(accountDeployDataBuf));
|
|
16502
16952
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
16503
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
16953
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(nbCallsBuf));
|
|
16504
16954
|
let respSign = new Uint8Array(0);
|
|
16505
16955
|
for (const call of calls) {
|
|
16506
16956
|
const calldatas = this.encodeCall(call);
|
|
16507
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
16957
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, Buffer.from(calldatas[0]));
|
|
16508
16958
|
if (calldatas.length > 1) {
|
|
16509
16959
|
calldatas.slice(1).forEach(async (part) => {
|
|
16510
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
16960
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, Buffer.from(part));
|
|
16511
16961
|
});
|
|
16512
16962
|
}
|
|
16513
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
16514
16963
|
}
|
|
16515
16964
|
return this.decodeSignatureLedger(respSign);
|
|
16516
16965
|
}
|
|
@@ -16550,21 +16999,21 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16550
16999
|
);
|
|
16551
17000
|
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
16552
17001
|
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
17002
|
+
const maxFeeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
16553
17003
|
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
16554
17004
|
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
16555
17005
|
const dataBuf = concatenateArrayBuffer([
|
|
16556
17006
|
accountAddressBuf,
|
|
16557
17007
|
classHashBuf,
|
|
16558
17008
|
saltBuf,
|
|
17009
|
+
maxFeeBuf,
|
|
16559
17010
|
chainIdBuf,
|
|
16560
17011
|
nonceBuf
|
|
16561
17012
|
]);
|
|
16562
17013
|
await this._transporter.send(Number("0x5a"), 6, 1, 0, Buffer.from(dataBuf));
|
|
16563
|
-
const maxFreeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
16564
|
-
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(maxFreeBuf));
|
|
16565
17014
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
16566
17015
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
16567
|
-
await this._transporter.send(Number("0x5a"), 6,
|
|
17016
|
+
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(constructorLengthBuf));
|
|
16568
17017
|
const constructorBuf = concatenateArrayBuffer(
|
|
16569
17018
|
compiledConstructor.map((parameter) => {
|
|
16570
17019
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -16577,12 +17026,12 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16577
17026
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
16578
17027
|
let respSign = new Uint8Array(0);
|
|
16579
17028
|
for (const chunk of constructorChunks) {
|
|
16580
|
-
respSign = await this._transporter.send(Number("0x5a"), 6,
|
|
17029
|
+
respSign = await this._transporter.send(Number("0x5a"), 6, 3, 0, Buffer.from(chunk));
|
|
16581
17030
|
}
|
|
16582
17031
|
return this.decodeSignatureLedger(respSign);
|
|
16583
17032
|
}
|
|
16584
17033
|
/**
|
|
16585
|
-
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
17034
|
+
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment (Rpc 0.7 & Rpc 0.8).
|
|
16586
17035
|
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
16587
17036
|
* @returns an object including the transaction Hash and the signature
|
|
16588
17037
|
* @example
|
|
@@ -16603,7 +17052,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16603
17052
|
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
16604
17053
|
* chainId: '0x534e5f5345504f4c4941', maxFee: 0,
|
|
16605
17054
|
* version: '0x3', nonce: 0n
|
|
16606
|
-
*}
|
|
17055
|
+
*} // Rpc 0.7 transaction.
|
|
16607
17056
|
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
16608
17057
|
* // res = {hash:
|
|
16609
17058
|
* // signature:
|
|
@@ -16619,8 +17068,8 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16619
17068
|
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
16620
17069
|
const dAModeHashBuf = this.convertBnToLedger(
|
|
16621
17070
|
hashDAMode(
|
|
16622
|
-
deployAccountDetail.nonceDataAvailabilityMode
|
|
16623
|
-
deployAccountDetail.feeDataAvailabilityMode
|
|
17071
|
+
intDAM(deployAccountDetail.nonceDataAvailabilityMode),
|
|
17072
|
+
intDAM(deployAccountDetail.feeDataAvailabilityMode)
|
|
16624
17073
|
)
|
|
16625
17074
|
);
|
|
16626
17075
|
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
@@ -16634,15 +17083,35 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16634
17083
|
saltBuf
|
|
16635
17084
|
]);
|
|
16636
17085
|
await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
|
|
16637
|
-
|
|
16638
|
-
|
|
16639
|
-
|
|
16640
|
-
|
|
16641
|
-
|
|
16642
|
-
|
|
16643
|
-
|
|
16644
|
-
|
|
16645
|
-
|
|
17086
|
+
if (isRPC08_ResourceBounds(deployAccountDetail.resourceBounds)) {
|
|
17087
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
17088
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
17089
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
17090
|
+
);
|
|
17091
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
17092
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
17093
|
+
);
|
|
17094
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
17095
|
+
encodeDataResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
17096
|
+
);
|
|
17097
|
+
const feeBuf = concatenateArrayBuffer([
|
|
17098
|
+
tipBuf,
|
|
17099
|
+
l1_gasBuf,
|
|
17100
|
+
l2_gasBuf,
|
|
17101
|
+
l1_data_gasBuf
|
|
17102
|
+
]);
|
|
17103
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
17104
|
+
} else {
|
|
17105
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
17106
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
17107
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
17108
|
+
);
|
|
17109
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
17110
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
17111
|
+
);
|
|
17112
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
17113
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
17114
|
+
}
|
|
16646
17115
|
const paymasterBuf = concatenateArrayBuffer(
|
|
16647
17116
|
deployAccountDetail.paymasterData.map((value) => {
|
|
16648
17117
|
const a = this.convertBnToLedger(value);
|
|
@@ -16669,30 +17138,35 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16669
17138
|
}
|
|
16670
17139
|
return this.decodeSignatureLedger(respSign);
|
|
16671
17140
|
}
|
|
17141
|
+
/** Internal function to convert a Call to an array of Uint8Array.
|
|
17142
|
+
* @param {Call} call A Call to convert.
|
|
17143
|
+
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
17144
|
+
*/
|
|
17145
|
+
encodeCall(call) {
|
|
17146
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
17147
|
+
const selectorBuf = hexToBytes2(addAddressPadding(getSelector(call.entrypoint)));
|
|
17148
|
+
let calldataBuf = new Uint8Array([]);
|
|
17149
|
+
if (call.calldata) {
|
|
17150
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
17151
|
+
const calldataSizeBuf = this.convertBnToLedger(compiledCalldata.length);
|
|
17152
|
+
calldataBuf = concatenateArrayBuffer([
|
|
17153
|
+
calldataSizeBuf,
|
|
17154
|
+
...compiledCalldata.map((parameter) => {
|
|
17155
|
+
const a = this.convertBnToLedger(parameter);
|
|
17156
|
+
return a;
|
|
17157
|
+
})
|
|
17158
|
+
]);
|
|
17159
|
+
} else {
|
|
17160
|
+
calldataBuf = this.convertBnToLedger("0x00");
|
|
17161
|
+
}
|
|
17162
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
17163
|
+
const calldatas = [];
|
|
17164
|
+
const chunkSize = 7 * 32;
|
|
17165
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
17166
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
17167
|
+
return calldatas;
|
|
17168
|
+
}
|
|
16672
17169
|
};
|
|
16673
|
-
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
16674
|
-
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
16675
|
-
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
16676
|
-
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
16677
|
-
const path2buff = concatenateArrayBuffer([
|
|
16678
|
-
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
16679
|
-
path2Base.subarray(1)
|
|
16680
|
-
]);
|
|
16681
|
-
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
16682
|
-
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
16683
|
-
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
16684
|
-
const path4buff = hexToBytes2(padded);
|
|
16685
|
-
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
16686
|
-
const pathBuff = concatenateArrayBuffer([
|
|
16687
|
-
path0buff,
|
|
16688
|
-
path1buff,
|
|
16689
|
-
path2buff,
|
|
16690
|
-
path3buff,
|
|
16691
|
-
path4buff,
|
|
16692
|
-
path5buff
|
|
16693
|
-
]);
|
|
16694
|
-
return pathBuff;
|
|
16695
|
-
}
|
|
16696
17170
|
|
|
16697
17171
|
// src/utils/events/index.ts
|
|
16698
17172
|
var events_exports = {};
|
|
@@ -16946,13 +17420,257 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16946
17420
|
}
|
|
16947
17421
|
}
|
|
16948
17422
|
|
|
17423
|
+
// src/utils/paymaster.ts
|
|
17424
|
+
var paymaster_exports = {};
|
|
17425
|
+
__export(paymaster_exports, {
|
|
17426
|
+
getDefaultPaymasterNodeUrl: () => getDefaultPaymasterNodeUrl
|
|
17427
|
+
});
|
|
17428
|
+
var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
|
|
17429
|
+
if (!mute) {
|
|
17430
|
+
logger.info("Using default public node url, please provide nodeUrl in provider options!");
|
|
17431
|
+
}
|
|
17432
|
+
const nodes = PAYMASTER_RPC_NODES[networkName ?? _NetworkName.SN_SEPOLIA];
|
|
17433
|
+
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
17434
|
+
return nodes[randIdx];
|
|
17435
|
+
};
|
|
17436
|
+
|
|
17437
|
+
// src/paymaster/rpc.ts
|
|
17438
|
+
var convertCalls = (calls) => calls.map((call) => ({
|
|
17439
|
+
to: call.contractAddress,
|
|
17440
|
+
selector: getSelectorFromName(call.entrypoint),
|
|
17441
|
+
calldata: CallData.toHex(call.calldata)
|
|
17442
|
+
}));
|
|
17443
|
+
var convertFeeMode = (feeMode) => {
|
|
17444
|
+
if (feeMode.mode === "sponsored") {
|
|
17445
|
+
return { mode: "sponsored" };
|
|
17446
|
+
}
|
|
17447
|
+
return { mode: "default", gas_token: feeMode.gasToken };
|
|
17448
|
+
};
|
|
17449
|
+
var convertFEE_MODE = (feeMode) => {
|
|
17450
|
+
if (feeMode.mode === "sponsored") {
|
|
17451
|
+
return { mode: "sponsored" };
|
|
17452
|
+
}
|
|
17453
|
+
return { mode: "default", gasToken: feeMode.gas_token };
|
|
17454
|
+
};
|
|
17455
|
+
var convertTimeBounds = (timeBounds) => timeBounds && timeBounds.executeAfter && timeBounds.executeBefore ? {
|
|
17456
|
+
execute_after: timeBounds.executeAfter.getTime().toString(),
|
|
17457
|
+
execute_before: timeBounds.executeBefore.getTime().toString()
|
|
17458
|
+
} : void 0;
|
|
17459
|
+
var convertTIME_BOUNDS = (timeBounds) => timeBounds && timeBounds.execute_after && timeBounds.execute_before ? {
|
|
17460
|
+
executeAfter: new Date(timeBounds.execute_after),
|
|
17461
|
+
executeBefore: new Date(timeBounds.execute_before)
|
|
17462
|
+
} : void 0;
|
|
17463
|
+
var convertEXECUTION_PARAMETERS = (parameters) => ({
|
|
17464
|
+
version: parameters.version,
|
|
17465
|
+
feeMode: convertFEE_MODE(parameters.fee_mode),
|
|
17466
|
+
timeBounds: convertTIME_BOUNDS(parameters.time_bounds)
|
|
17467
|
+
});
|
|
17468
|
+
var defaultOptions3 = {
|
|
17469
|
+
headers: { "Content-Type": "application/json" }
|
|
17470
|
+
};
|
|
17471
|
+
var PaymasterRpc = class _PaymasterRpc {
|
|
17472
|
+
nodeUrl;
|
|
17473
|
+
headers;
|
|
17474
|
+
baseFetch;
|
|
17475
|
+
requestId;
|
|
17476
|
+
constructor(options) {
|
|
17477
|
+
if (options instanceof _PaymasterRpc) {
|
|
17478
|
+
this.nodeUrl = options.nodeUrl;
|
|
17479
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
17480
|
+
this.baseFetch = options.baseFetch;
|
|
17481
|
+
this.requestId = options.requestId;
|
|
17482
|
+
return;
|
|
17483
|
+
}
|
|
17484
|
+
if (options && "nodeUrl" in options && "headers" in options && "baseFetch" in options) {
|
|
17485
|
+
this.nodeUrl = options.nodeUrl ?? getDefaultPaymasterNodeUrl(void 0);
|
|
17486
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
17487
|
+
this.baseFetch = options.baseFetch ?? fetch_default;
|
|
17488
|
+
this.requestId = 0;
|
|
17489
|
+
return;
|
|
17490
|
+
}
|
|
17491
|
+
const { nodeUrl, headers, baseFetch } = options || {};
|
|
17492
|
+
if (nodeUrl && Object.values(_NetworkName).includes(nodeUrl)) {
|
|
17493
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(nodeUrl, options?.default);
|
|
17494
|
+
} else if (nodeUrl) {
|
|
17495
|
+
this.nodeUrl = nodeUrl;
|
|
17496
|
+
} else {
|
|
17497
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(void 0, options?.default);
|
|
17498
|
+
}
|
|
17499
|
+
this.baseFetch = baseFetch ?? fetch_default;
|
|
17500
|
+
this.headers = { ...defaultOptions3.headers, ...headers };
|
|
17501
|
+
this.requestId = 0;
|
|
17502
|
+
}
|
|
17503
|
+
fetch(method, params, id = 0) {
|
|
17504
|
+
const rpcRequestBody = {
|
|
17505
|
+
id,
|
|
17506
|
+
jsonrpc: "2.0",
|
|
17507
|
+
method,
|
|
17508
|
+
...params && { params }
|
|
17509
|
+
};
|
|
17510
|
+
return this.baseFetch(this.nodeUrl, {
|
|
17511
|
+
method: "POST",
|
|
17512
|
+
body: stringify2(rpcRequestBody),
|
|
17513
|
+
headers: this.headers
|
|
17514
|
+
});
|
|
17515
|
+
}
|
|
17516
|
+
errorHandler(method, params, rpcError, otherError) {
|
|
17517
|
+
if (rpcError) {
|
|
17518
|
+
throw new RpcError(rpcError, method, params);
|
|
17519
|
+
}
|
|
17520
|
+
if (otherError instanceof LibraryError) {
|
|
17521
|
+
throw otherError;
|
|
17522
|
+
}
|
|
17523
|
+
if (otherError) {
|
|
17524
|
+
throw Error(otherError.message);
|
|
17525
|
+
}
|
|
17526
|
+
}
|
|
17527
|
+
async fetchEndpoint(method, params) {
|
|
17528
|
+
try {
|
|
17529
|
+
this.requestId += 1;
|
|
17530
|
+
const rawResult = await this.fetch(method, params, this.requestId);
|
|
17531
|
+
const { error, result } = await rawResult.json();
|
|
17532
|
+
this.errorHandler(method, params, error);
|
|
17533
|
+
return result;
|
|
17534
|
+
} catch (error) {
|
|
17535
|
+
this.errorHandler(method, params, error?.response?.data, error);
|
|
17536
|
+
throw error;
|
|
17537
|
+
}
|
|
17538
|
+
}
|
|
17539
|
+
async isAvailable() {
|
|
17540
|
+
return this.fetchEndpoint("paymaster_isAvailable");
|
|
17541
|
+
}
|
|
17542
|
+
async buildTransaction(transaction, parameters) {
|
|
17543
|
+
let userTransaction;
|
|
17544
|
+
switch (transaction.type) {
|
|
17545
|
+
case "invoke":
|
|
17546
|
+
userTransaction = {
|
|
17547
|
+
...transaction,
|
|
17548
|
+
invoke: {
|
|
17549
|
+
user_address: transaction.invoke.userAddress,
|
|
17550
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17551
|
+
}
|
|
17552
|
+
};
|
|
17553
|
+
break;
|
|
17554
|
+
case "deploy_and_invoke":
|
|
17555
|
+
userTransaction = {
|
|
17556
|
+
...transaction,
|
|
17557
|
+
invoke: {
|
|
17558
|
+
user_address: transaction.invoke.userAddress,
|
|
17559
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17560
|
+
}
|
|
17561
|
+
};
|
|
17562
|
+
break;
|
|
17563
|
+
case "deploy":
|
|
17564
|
+
default:
|
|
17565
|
+
userTransaction = transaction;
|
|
17566
|
+
break;
|
|
17567
|
+
}
|
|
17568
|
+
const executionParameters = {
|
|
17569
|
+
version: parameters.version,
|
|
17570
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17571
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17572
|
+
};
|
|
17573
|
+
const response = await this.fetchEndpoint("paymaster_buildTransaction", {
|
|
17574
|
+
transaction: userTransaction,
|
|
17575
|
+
parameters: executionParameters
|
|
17576
|
+
});
|
|
17577
|
+
const fee = {
|
|
17578
|
+
gas_token_price_in_strk: BigInt(response.fee.gas_token_price_in_strk),
|
|
17579
|
+
estimated_fee_in_strk: BigInt(response.fee.estimated_fee_in_strk),
|
|
17580
|
+
estimated_fee_in_gas_token: BigInt(response.fee.estimated_fee_in_gas_token),
|
|
17581
|
+
suggested_max_fee_in_strk: BigInt(response.fee.suggested_max_fee_in_strk),
|
|
17582
|
+
suggested_max_fee_in_gas_token: BigInt(response.fee.suggested_max_fee_in_gas_token)
|
|
17583
|
+
};
|
|
17584
|
+
switch (response.type) {
|
|
17585
|
+
case "invoke":
|
|
17586
|
+
return {
|
|
17587
|
+
type: "invoke",
|
|
17588
|
+
typed_data: response.typed_data,
|
|
17589
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17590
|
+
fee
|
|
17591
|
+
};
|
|
17592
|
+
case "deploy_and_invoke":
|
|
17593
|
+
return {
|
|
17594
|
+
type: "deploy_and_invoke",
|
|
17595
|
+
deployment: response.deployment,
|
|
17596
|
+
typed_data: response.typed_data,
|
|
17597
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17598
|
+
fee
|
|
17599
|
+
};
|
|
17600
|
+
case "deploy":
|
|
17601
|
+
default:
|
|
17602
|
+
return {
|
|
17603
|
+
type: "deploy",
|
|
17604
|
+
deployment: response.deployment,
|
|
17605
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17606
|
+
fee
|
|
17607
|
+
};
|
|
17608
|
+
}
|
|
17609
|
+
}
|
|
17610
|
+
async executeTransaction(transaction, parameters) {
|
|
17611
|
+
let user_transaction;
|
|
17612
|
+
switch (transaction.type) {
|
|
17613
|
+
case "invoke":
|
|
17614
|
+
user_transaction = {
|
|
17615
|
+
...transaction,
|
|
17616
|
+
invoke: {
|
|
17617
|
+
user_address: transaction.invoke.userAddress,
|
|
17618
|
+
typed_data: transaction.invoke.typedData,
|
|
17619
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17620
|
+
}
|
|
17621
|
+
};
|
|
17622
|
+
break;
|
|
17623
|
+
case "deploy_and_invoke":
|
|
17624
|
+
user_transaction = {
|
|
17625
|
+
...transaction,
|
|
17626
|
+
invoke: {
|
|
17627
|
+
user_address: transaction.invoke.userAddress,
|
|
17628
|
+
typed_data: transaction.invoke.typedData,
|
|
17629
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17630
|
+
}
|
|
17631
|
+
};
|
|
17632
|
+
break;
|
|
17633
|
+
case "deploy":
|
|
17634
|
+
default:
|
|
17635
|
+
user_transaction = transaction;
|
|
17636
|
+
break;
|
|
17637
|
+
}
|
|
17638
|
+
const executionParameters = {
|
|
17639
|
+
version: parameters.version,
|
|
17640
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17641
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17642
|
+
};
|
|
17643
|
+
return this.fetchEndpoint("paymaster_executeTransaction", {
|
|
17644
|
+
transaction: user_transaction,
|
|
17645
|
+
parameters: executionParameters
|
|
17646
|
+
});
|
|
17647
|
+
}
|
|
17648
|
+
async getSupportedTokens() {
|
|
17649
|
+
return this.fetchEndpoint("paymaster_getSupportedTokens").then(
|
|
17650
|
+
(tokens) => tokens.map((token) => ({
|
|
17651
|
+
token_address: token.token_address,
|
|
17652
|
+
decimals: token.decimals,
|
|
17653
|
+
priceInStrk: BigInt(token.price_in_strk)
|
|
17654
|
+
}))
|
|
17655
|
+
);
|
|
17656
|
+
}
|
|
17657
|
+
};
|
|
17658
|
+
|
|
17659
|
+
// src/paymaster/interface.ts
|
|
17660
|
+
var PaymasterInterface = class {
|
|
17661
|
+
};
|
|
17662
|
+
|
|
17663
|
+
// src/paymaster/index.ts
|
|
17664
|
+
var defaultPaymaster = new PaymasterRpc({ default: true });
|
|
17665
|
+
|
|
16949
17666
|
// src/account/default.ts
|
|
16950
17667
|
var Account = class extends RpcProvider2 {
|
|
16951
17668
|
signer;
|
|
16952
17669
|
address;
|
|
16953
17670
|
cairoVersion;
|
|
16954
17671
|
transactionVersion;
|
|
16955
|
-
|
|
17672
|
+
paymaster;
|
|
17673
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = config.get("transactionVersion"), paymaster) {
|
|
16956
17674
|
super(providerOrOptions);
|
|
16957
17675
|
this.address = address.toLowerCase();
|
|
16958
17676
|
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
@@ -16960,6 +17678,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
16960
17678
|
this.cairoVersion = cairoVersion.toString();
|
|
16961
17679
|
}
|
|
16962
17680
|
this.transactionVersion = transactionVersion;
|
|
17681
|
+
this.paymaster = paymaster ? new PaymasterRpc(paymaster) : defaultPaymaster;
|
|
16963
17682
|
logger.debug("Account setup", {
|
|
16964
17683
|
transactionVersion: this.transactionVersion,
|
|
16965
17684
|
cairoVersion: this.cairoVersion,
|
|
@@ -17017,7 +17736,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17017
17736
|
);
|
|
17018
17737
|
const chainId = await this.getChainId();
|
|
17019
17738
|
const signerDetails = {
|
|
17020
|
-
...v3Details(details, await this.channel.
|
|
17739
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17021
17740
|
walletAddress: this.address,
|
|
17022
17741
|
nonce,
|
|
17023
17742
|
maxFee: ZERO,
|
|
@@ -17029,7 +17748,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17029
17748
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
17030
17749
|
return super.getInvokeEstimateFee(
|
|
17031
17750
|
{ ...invocation },
|
|
17032
|
-
{ ...v3Details(details, await this.channel.
|
|
17751
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
17033
17752
|
blockIdentifier,
|
|
17034
17753
|
details.skipValidate
|
|
17035
17754
|
);
|
|
@@ -17048,7 +17767,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17048
17767
|
);
|
|
17049
17768
|
const chainId = await this.getChainId();
|
|
17050
17769
|
const declareContractTransaction = await this.buildDeclarePayload(payload, {
|
|
17051
|
-
...v3Details(details, await this.channel.
|
|
17770
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17052
17771
|
nonce,
|
|
17053
17772
|
chainId,
|
|
17054
17773
|
version,
|
|
@@ -17060,7 +17779,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17060
17779
|
});
|
|
17061
17780
|
return super.getDeclareEstimateFee(
|
|
17062
17781
|
declareContractTransaction,
|
|
17063
|
-
{ ...v3Details(details, await this.channel.
|
|
17782
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
17064
17783
|
blockIdentifier,
|
|
17065
17784
|
details.skipValidate
|
|
17066
17785
|
);
|
|
@@ -17081,7 +17800,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17081
17800
|
const payload = await this.buildAccountDeployPayload(
|
|
17082
17801
|
{ classHash, addressSalt, constructorCalldata, contractAddress },
|
|
17083
17802
|
{
|
|
17084
|
-
...v3Details(details, await this.channel.
|
|
17803
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17085
17804
|
nonce,
|
|
17086
17805
|
chainId,
|
|
17087
17806
|
version,
|
|
@@ -17095,7 +17814,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17095
17814
|
);
|
|
17096
17815
|
return super.getDeployAccountEstimateFee(
|
|
17097
17816
|
{ ...payload },
|
|
17098
|
-
{ ...v3Details(details, await this.channel.
|
|
17817
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
17099
17818
|
blockIdentifier,
|
|
17100
17819
|
details.skipValidate
|
|
17101
17820
|
);
|
|
@@ -17108,7 +17827,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17108
17827
|
if (!invocations.length) throw TypeError("Invocations should be non-empty array");
|
|
17109
17828
|
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
17110
17829
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
17111
|
-
...v3Details(details, await this.channel.
|
|
17830
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17112
17831
|
versions: [
|
|
17113
17832
|
ETransactionVersion5.F1,
|
|
17114
17833
|
// non-sierra
|
|
@@ -17131,7 +17850,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17131
17850
|
if (!invocations.length) throw TypeError("Invocations should be non-empty array");
|
|
17132
17851
|
const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
|
|
17133
17852
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
17134
|
-
...v3Details(details, await this.channel.
|
|
17853
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17135
17854
|
versions: [
|
|
17136
17855
|
ETransactionVersion5.V1,
|
|
17137
17856
|
// non-sierra
|
|
@@ -17152,6 +17871,13 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17152
17871
|
}
|
|
17153
17872
|
async execute(transactions, transactionsDetail = {}) {
|
|
17154
17873
|
const calls = Array.isArray(transactions) ? transactions : [transactions];
|
|
17874
|
+
if (transactionsDetail.paymaster) {
|
|
17875
|
+
return this.executePaymasterTransaction(
|
|
17876
|
+
calls,
|
|
17877
|
+
transactionsDetail.paymaster,
|
|
17878
|
+
transactionsDetail.maxFee
|
|
17879
|
+
);
|
|
17880
|
+
}
|
|
17155
17881
|
const nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
|
|
17156
17882
|
const version = toTransactionVersion(
|
|
17157
17883
|
this.getPreferredVersion(ETransactionVersion5.V1, ETransactionVersion5.V3),
|
|
@@ -17168,7 +17894,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17168
17894
|
);
|
|
17169
17895
|
const chainId = await this.getChainId();
|
|
17170
17896
|
const signerDetails = {
|
|
17171
|
-
...v3Details(transactionsDetail, await this.channel.
|
|
17897
|
+
...v3Details(transactionsDetail, await this.channel.setUpSpecVersion()),
|
|
17172
17898
|
resourceBounds: estimate.resourceBounds,
|
|
17173
17899
|
walletAddress: this.address,
|
|
17174
17900
|
nonce,
|
|
@@ -17182,7 +17908,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17182
17908
|
return this.invokeFunction(
|
|
17183
17909
|
{ contractAddress: this.address, calldata, signature },
|
|
17184
17910
|
{
|
|
17185
|
-
...v3Details(transactionsDetail, await this.channel.
|
|
17911
|
+
...v3Details(transactionsDetail, await this.channel.setUpSpecVersion()),
|
|
17186
17912
|
resourceBounds: estimate.resourceBounds,
|
|
17187
17913
|
nonce,
|
|
17188
17914
|
maxFee: estimate.maxFee,
|
|
@@ -17190,6 +17916,88 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17190
17916
|
}
|
|
17191
17917
|
);
|
|
17192
17918
|
}
|
|
17919
|
+
async buildPaymasterTransaction(calls, paymasterDetails) {
|
|
17920
|
+
if (!paymasterDetails.deploymentData) {
|
|
17921
|
+
const snip9Version = await this.getSnip9Version();
|
|
17922
|
+
if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
|
|
17923
|
+
throw Error("Account is not compatible with SNIP-9");
|
|
17924
|
+
}
|
|
17925
|
+
}
|
|
17926
|
+
const parameters = {
|
|
17927
|
+
version: "0x1",
|
|
17928
|
+
feeMode: paymasterDetails.feeMode,
|
|
17929
|
+
timeBounds: paymasterDetails.timeBounds
|
|
17930
|
+
};
|
|
17931
|
+
let transaction;
|
|
17932
|
+
if (paymasterDetails.deploymentData) {
|
|
17933
|
+
if (calls.length > 0) {
|
|
17934
|
+
transaction = {
|
|
17935
|
+
type: "deploy_and_invoke",
|
|
17936
|
+
invoke: { userAddress: this.address, calls },
|
|
17937
|
+
deployment: paymasterDetails.deploymentData
|
|
17938
|
+
};
|
|
17939
|
+
} else {
|
|
17940
|
+
transaction = {
|
|
17941
|
+
type: "deploy",
|
|
17942
|
+
deployment: paymasterDetails.deploymentData
|
|
17943
|
+
};
|
|
17944
|
+
}
|
|
17945
|
+
} else {
|
|
17946
|
+
transaction = {
|
|
17947
|
+
type: "invoke",
|
|
17948
|
+
invoke: { userAddress: this.address, calls }
|
|
17949
|
+
};
|
|
17950
|
+
}
|
|
17951
|
+
return this.paymaster.buildTransaction(transaction, parameters);
|
|
17952
|
+
}
|
|
17953
|
+
async estimatePaymasterTransactionFee(calls, paymasterDetails) {
|
|
17954
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17955
|
+
return preparedTransaction.fee;
|
|
17956
|
+
}
|
|
17957
|
+
async executePaymasterTransaction(calls, paymasterDetails, maxFee) {
|
|
17958
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17959
|
+
if (maxFee && preparedTransaction.fee.gas_token_price_in_strk > maxFee) {
|
|
17960
|
+
throw Error("Gas token price is too high");
|
|
17961
|
+
}
|
|
17962
|
+
let transaction;
|
|
17963
|
+
switch (preparedTransaction.type) {
|
|
17964
|
+
case "deploy_and_invoke": {
|
|
17965
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
17966
|
+
transaction = {
|
|
17967
|
+
type: "deploy_and_invoke",
|
|
17968
|
+
invoke: {
|
|
17969
|
+
userAddress: this.address,
|
|
17970
|
+
typedData: preparedTransaction.typed_data,
|
|
17971
|
+
signature: signatureToHexArray(signature)
|
|
17972
|
+
},
|
|
17973
|
+
deployment: preparedTransaction.deployment
|
|
17974
|
+
};
|
|
17975
|
+
break;
|
|
17976
|
+
}
|
|
17977
|
+
case "invoke": {
|
|
17978
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
17979
|
+
transaction = {
|
|
17980
|
+
type: "invoke",
|
|
17981
|
+
invoke: {
|
|
17982
|
+
userAddress: this.address,
|
|
17983
|
+
typedData: preparedTransaction.typed_data,
|
|
17984
|
+
signature: signatureToHexArray(signature)
|
|
17985
|
+
}
|
|
17986
|
+
};
|
|
17987
|
+
break;
|
|
17988
|
+
}
|
|
17989
|
+
case "deploy": {
|
|
17990
|
+
transaction = {
|
|
17991
|
+
type: "deploy",
|
|
17992
|
+
deployment: preparedTransaction.deployment
|
|
17993
|
+
};
|
|
17994
|
+
break;
|
|
17995
|
+
}
|
|
17996
|
+
default:
|
|
17997
|
+
throw Error("Invalid transaction type");
|
|
17998
|
+
}
|
|
17999
|
+
return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
|
|
18000
|
+
}
|
|
17193
18001
|
/**
|
|
17194
18002
|
* First check if contract is already declared, if not declare it
|
|
17195
18003
|
* If contract already declared returned transaction_hash is ''.
|
|
@@ -17227,7 +18035,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17227
18035
|
}
|
|
17228
18036
|
);
|
|
17229
18037
|
const declareDetails = {
|
|
17230
|
-
...v3Details(details, await this.channel.
|
|
18038
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17231
18039
|
resourceBounds: estimate.resourceBounds,
|
|
17232
18040
|
maxFee: estimate.maxFee,
|
|
17233
18041
|
nonce: toBigInt(nonce ?? await this.getNonce()),
|
|
@@ -17297,7 +18105,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17297
18105
|
details
|
|
17298
18106
|
);
|
|
17299
18107
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
17300
|
-
...v3Details(details, await this.channel.
|
|
18108
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17301
18109
|
classHash,
|
|
17302
18110
|
constructorCalldata: compiledCalldata,
|
|
17303
18111
|
contractAddress,
|
|
@@ -17311,7 +18119,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17311
18119
|
return this.deployAccountContract(
|
|
17312
18120
|
{ classHash, addressSalt, constructorCalldata, signature },
|
|
17313
18121
|
{
|
|
17314
|
-
...v3Details(details, await this.channel.
|
|
18122
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17315
18123
|
nonce,
|
|
17316
18124
|
resourceBounds: estimate.resourceBounds,
|
|
17317
18125
|
maxFee: estimate.maxFee,
|
|
@@ -17478,7 +18286,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17478
18286
|
let resourceBounds = estimateFeeToBounds3(
|
|
17479
18287
|
ZERO,
|
|
17480
18288
|
void 0,
|
|
17481
|
-
await this.channel.
|
|
18289
|
+
await this.channel.setUpSpecVersion()
|
|
17482
18290
|
);
|
|
17483
18291
|
if (version === ETransactionVersion5.V3) {
|
|
17484
18292
|
resourceBounds = details.resourceBounds ?? (await this.getSuggestedFee({ type, payload }, details)).resourceBounds;
|
|
@@ -17501,14 +18309,14 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17501
18309
|
case TransactionType.DEPLOY:
|
|
17502
18310
|
return this.estimateDeployFee(payload, details);
|
|
17503
18311
|
default:
|
|
17504
|
-
return ZEROFee(await this.channel.
|
|
18312
|
+
return ZEROFee(await this.channel.setUpSpecVersion());
|
|
17505
18313
|
}
|
|
17506
18314
|
}
|
|
17507
18315
|
async buildInvocation(call, details) {
|
|
17508
18316
|
const calldata = getExecuteCalldata(call, await this.getCairoVersion());
|
|
17509
18317
|
const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
|
|
17510
18318
|
return {
|
|
17511
|
-
...v3Details(details, await this.channel.
|
|
18319
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17512
18320
|
contractAddress: this.address,
|
|
17513
18321
|
calldata,
|
|
17514
18322
|
signature
|
|
@@ -17522,7 +18330,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17522
18330
|
}
|
|
17523
18331
|
const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
|
|
17524
18332
|
...details,
|
|
17525
|
-
...v3Details(details, await this.channel.
|
|
18333
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17526
18334
|
classHash,
|
|
17527
18335
|
compiledClassHash,
|
|
17528
18336
|
// TODO: TS, cast because optional for v2 and required for v3, thrown if not present
|
|
@@ -17545,14 +18353,14 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17545
18353
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
17546
18354
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
17547
18355
|
...details,
|
|
17548
|
-
...v3Details(details, await this.channel.
|
|
18356
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17549
18357
|
classHash,
|
|
17550
18358
|
contractAddress,
|
|
17551
18359
|
addressSalt,
|
|
17552
18360
|
constructorCalldata: compiledCalldata
|
|
17553
18361
|
}) : [];
|
|
17554
18362
|
return {
|
|
17555
|
-
...v3Details(details, await this.channel.
|
|
18363
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17556
18364
|
classHash,
|
|
17557
18365
|
addressSalt,
|
|
17558
18366
|
constructorCalldata: compiledCalldata,
|
|
@@ -17593,7 +18401,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17593
18401
|
[].concat(invocations).map(async (transaction, index) => {
|
|
17594
18402
|
const txPayload = "payload" in transaction ? transaction.payload : transaction;
|
|
17595
18403
|
const signerDetails = {
|
|
17596
|
-
...v3Details(details, await this.channel.
|
|
18404
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
17597
18405
|
walletAddress: this.address,
|
|
17598
18406
|
nonce: toBigInt(Number(safeNonce) + index),
|
|
17599
18407
|
maxFee: ZERO,
|
|
@@ -17736,8 +18544,8 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17736
18544
|
// src/wallet/account.ts
|
|
17737
18545
|
var WalletAccount = class _WalletAccount extends Account {
|
|
17738
18546
|
walletProvider;
|
|
17739
|
-
constructor(providerOrOptions, walletProvider, address, cairoVersion) {
|
|
17740
|
-
super(providerOrOptions, address, "", cairoVersion);
|
|
18547
|
+
constructor(providerOrOptions, walletProvider, address, cairoVersion, paymaster) {
|
|
18548
|
+
super(providerOrOptions, address, "", cairoVersion, void 0, paymaster);
|
|
17741
18549
|
this.walletProvider = walletProvider;
|
|
17742
18550
|
this.walletProvider.on("accountsChanged", (res) => {
|
|
17743
18551
|
if (!res) return;
|
|
@@ -17778,7 +18586,14 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17778
18586
|
/**
|
|
17779
18587
|
* ACCOUNT METHODS
|
|
17780
18588
|
*/
|
|
17781
|
-
execute(calls) {
|
|
18589
|
+
execute(calls, arg2, transactionsDetail = {}) {
|
|
18590
|
+
const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
|
|
18591
|
+
if (details.paymaster) {
|
|
18592
|
+
return this.executePaymasterTransaction(
|
|
18593
|
+
Array.isArray(calls) ? calls : [calls],
|
|
18594
|
+
details.paymaster
|
|
18595
|
+
);
|
|
18596
|
+
}
|
|
17782
18597
|
const txCalls = [].concat(calls).map((it) => {
|
|
17783
18598
|
const { contractAddress, entrypoint, calldata } = it;
|
|
17784
18599
|
return {
|
|
@@ -17819,12 +18634,12 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
17819
18634
|
signMessage(typedData) {
|
|
17820
18635
|
return signMessage(this.walletProvider, typedData);
|
|
17821
18636
|
}
|
|
17822
|
-
static async connect(provider, walletProvider, cairoVersion, silentMode = false) {
|
|
18637
|
+
static async connect(provider, walletProvider, cairoVersion, paymaster, silentMode = false) {
|
|
17823
18638
|
const [accountAddress] = await requestAccounts(walletProvider, silentMode);
|
|
17824
|
-
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion);
|
|
18639
|
+
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion, paymaster);
|
|
17825
18640
|
}
|
|
17826
|
-
static async connectSilent(provider, walletProvider, cairoVersion) {
|
|
17827
|
-
return _WalletAccount.connect(provider, walletProvider, cairoVersion, true);
|
|
18641
|
+
static async connectSilent(provider, walletProvider, cairoVersion, paymaster) {
|
|
18642
|
+
return _WalletAccount.connect(provider, walletProvider, cairoVersion, paymaster, true);
|
|
17828
18643
|
}
|
|
17829
18644
|
// TODO: MISSING ESTIMATES
|
|
17830
18645
|
};
|