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.mjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(constants_exports, {
|
|
|
31
31
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
32
32
|
NetworkName: () => _NetworkName,
|
|
33
33
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
34
|
+
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
34
35
|
PRIME: () => PRIME,
|
|
35
36
|
RANGE_FELT: () => RANGE_FELT,
|
|
36
37
|
RANGE_I128: () => RANGE_I128,
|
|
@@ -52,6 +53,7 @@ __export(constants_exports, {
|
|
|
52
53
|
var api_exports = {};
|
|
53
54
|
__export(api_exports, {
|
|
54
55
|
JRPC: () => jsonrpc_exports,
|
|
56
|
+
PAYMASTER_API: () => PAYMASTER_API,
|
|
55
57
|
RPCSPEC07: () => RPCSPEC07,
|
|
56
58
|
RPCSPEC08: () => RPCSPEC08
|
|
57
59
|
});
|
|
@@ -63,6 +65,7 @@ var jsonrpc_exports = {};
|
|
|
63
65
|
__reExport(api_exports, starknet_types_08_star);
|
|
64
66
|
import * as RPCSPEC07 from "starknet-types-07";
|
|
65
67
|
import * as RPCSPEC08 from "starknet-types-08";
|
|
68
|
+
import { PAYMASTER_API } from "starknet-types-08";
|
|
66
69
|
import * as starknet_types_08_star from "starknet-types-08";
|
|
67
70
|
|
|
68
71
|
// src/utils/encode.ts
|
|
@@ -194,14 +197,14 @@ var _TransactionHashPrefix = {
|
|
|
194
197
|
// encodeShortString('l1_handler'),
|
|
195
198
|
};
|
|
196
199
|
var _SupportedRpcVersion = {
|
|
197
|
-
0.7: "0.7",
|
|
198
|
-
0.8: "0.8",
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
"0.7.1": "0.7.1",
|
|
201
|
+
"0.8.1": "0.8.1",
|
|
202
|
+
v0_7_1: "0.7.1",
|
|
203
|
+
v0_8_1: "0.8.1"
|
|
201
204
|
};
|
|
202
205
|
var DEFAULT_GLOBAL_CONFIG = {
|
|
203
206
|
legacyMode: false,
|
|
204
|
-
rpcVersion: "0.8",
|
|
207
|
+
rpcVersion: "0.8.1",
|
|
205
208
|
transactionVersion: api_exports.ETransactionVersion.V3,
|
|
206
209
|
logLevel: "INFO",
|
|
207
210
|
feeMarginPercentage: {
|
|
@@ -220,7 +223,9 @@ var DEFAULT_GLOBAL_CONFIG = {
|
|
|
220
223
|
}
|
|
221
224
|
},
|
|
222
225
|
maxFee: 50
|
|
223
|
-
}
|
|
226
|
+
},
|
|
227
|
+
fetch: void 0,
|
|
228
|
+
websocket: void 0
|
|
224
229
|
};
|
|
225
230
|
var RPC_DEFAULT_NODES = {
|
|
226
231
|
SN_MAIN: [
|
|
@@ -232,164 +237,244 @@ var RPC_DEFAULT_NODES = {
|
|
|
232
237
|
`https://free-rpc.nethermind.io/sepolia-juno/`
|
|
233
238
|
]
|
|
234
239
|
};
|
|
240
|
+
var PAYMASTER_RPC_NODES = {
|
|
241
|
+
SN_MAIN: [`https://starknet.paymaster.avnu.fi`],
|
|
242
|
+
SN_SEPOLIA: [`https://sepolia.paymaster.avnu.fi`]
|
|
243
|
+
};
|
|
235
244
|
var SYSTEM_MESSAGES = {
|
|
236
245
|
legacyTxWarningMessage: "You are using a deprecated transaction version (V0,V1,V2)!\nUpdate to the latest V3 transactions!",
|
|
237
246
|
legacyTxRPC08Message: "RPC 0.8 do not support legacy transactions",
|
|
238
|
-
SWOldV3: "RPC 0.7 V3 tx (improper resource bounds) not supported in RPC 0.8"
|
|
247
|
+
SWOldV3: "RPC 0.7 V3 tx (improper resource bounds) not supported in RPC 0.8",
|
|
248
|
+
channelVersionMismatch: "Channel specification version is not compatible with the connected node Specification Version",
|
|
249
|
+
unsupportedSpecVersion: "The connected node specification version is not supported by this library"
|
|
239
250
|
};
|
|
240
251
|
|
|
241
|
-
// src/
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
252
|
+
// src/global/config.ts
|
|
253
|
+
var Configuration = class _Configuration {
|
|
254
|
+
static instance;
|
|
255
|
+
config;
|
|
256
|
+
constructor() {
|
|
257
|
+
this.initialize();
|
|
258
|
+
}
|
|
259
|
+
initialize() {
|
|
260
|
+
this.config = { ...DEFAULT_GLOBAL_CONFIG };
|
|
261
|
+
}
|
|
262
|
+
static getInstance() {
|
|
263
|
+
if (!_Configuration.instance) {
|
|
264
|
+
_Configuration.instance = new _Configuration();
|
|
265
|
+
}
|
|
266
|
+
return _Configuration.instance;
|
|
267
|
+
}
|
|
268
|
+
get(key, defaultValue) {
|
|
269
|
+
return this.config[key] ?? defaultValue;
|
|
270
|
+
}
|
|
271
|
+
set(key, value) {
|
|
272
|
+
this.config[key] = value;
|
|
273
|
+
}
|
|
274
|
+
update(configData) {
|
|
275
|
+
this.config = {
|
|
276
|
+
...this.config,
|
|
277
|
+
...configData
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
getAll() {
|
|
281
|
+
return { ...this.config };
|
|
282
|
+
}
|
|
283
|
+
reset() {
|
|
284
|
+
this.initialize();
|
|
285
|
+
}
|
|
286
|
+
delete(key) {
|
|
287
|
+
delete this.config[key];
|
|
288
|
+
}
|
|
289
|
+
hasKey(key) {
|
|
290
|
+
return key in this.config;
|
|
291
|
+
}
|
|
259
292
|
};
|
|
260
|
-
var
|
|
261
|
-
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
262
|
-
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
293
|
+
var config = Configuration.getInstance();
|
|
263
294
|
|
|
264
|
-
// src/
|
|
265
|
-
var
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
CLASS_HASH_NOT_FOUND: 28,
|
|
273
|
-
TXN_HASH_NOT_FOUND: 29,
|
|
274
|
-
PAGE_SIZE_TOO_BIG: 31,
|
|
275
|
-
NO_BLOCKS: 32,
|
|
276
|
-
INVALID_CONTINUATION_TOKEN: 33,
|
|
277
|
-
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
278
|
-
CONTRACT_ERROR: 40,
|
|
279
|
-
TRANSACTION_EXECUTION_ERROR: 41,
|
|
280
|
-
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
281
|
-
CLASS_ALREADY_DECLARED: 51,
|
|
282
|
-
INVALID_TRANSACTION_NONCE: 52,
|
|
283
|
-
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
284
|
-
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
285
|
-
VALIDATION_FAILURE: 55,
|
|
286
|
-
COMPILATION_FAILED: 56,
|
|
287
|
-
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
288
|
-
NON_ACCOUNT: 58,
|
|
289
|
-
DUPLICATE_TX: 59,
|
|
290
|
-
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
291
|
-
UNSUPPORTED_TX_VERSION: 61,
|
|
292
|
-
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
293
|
-
UNEXPECTED_ERROR: 63,
|
|
294
|
-
INVALID_SUBSCRIPTION_ID: 66,
|
|
295
|
-
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
296
|
-
TOO_MANY_BLOCKS_BACK: 68,
|
|
297
|
-
COMPILATION_ERROR: 100
|
|
295
|
+
// src/global/logger.type.ts
|
|
296
|
+
var LogLevelIndex = {
|
|
297
|
+
DEBUG: 5,
|
|
298
|
+
INFO: 4,
|
|
299
|
+
WARN: 3,
|
|
300
|
+
ERROR: 2,
|
|
301
|
+
FATAL: 1,
|
|
302
|
+
OFF: 0
|
|
298
303
|
};
|
|
299
|
-
var rpc_default = errorCodes;
|
|
300
304
|
|
|
301
|
-
// src/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const { setPrototypeOf } = Object;
|
|
308
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
309
|
-
}
|
|
310
|
-
var CustomError = class extends Error {
|
|
311
|
-
name;
|
|
312
|
-
constructor(message) {
|
|
313
|
-
super(message);
|
|
314
|
-
Object.defineProperty(this, "name", {
|
|
315
|
-
value: new.target.name,
|
|
316
|
-
enumerable: false,
|
|
317
|
-
configurable: true
|
|
318
|
-
});
|
|
319
|
-
fixProto(this, new.target.prototype);
|
|
320
|
-
fixStack(this);
|
|
305
|
+
// src/global/logger.ts
|
|
306
|
+
var Logger = class _Logger {
|
|
307
|
+
static instance;
|
|
308
|
+
config;
|
|
309
|
+
constructor() {
|
|
310
|
+
this.config = config;
|
|
321
311
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
328
|
-
|
|
329
|
-
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
330
|
-
this.baseError = baseError;
|
|
331
|
-
this.request = { method, params };
|
|
312
|
+
static getInstance() {
|
|
313
|
+
if (!_Logger.instance) {
|
|
314
|
+
_Logger.instance = new _Logger();
|
|
315
|
+
}
|
|
316
|
+
return _Logger.instance;
|
|
332
317
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
318
|
+
getTimestamp() {
|
|
319
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
320
|
+
}
|
|
321
|
+
shouldLog(messageLevel) {
|
|
322
|
+
const configLevel = this.config.get("logLevel", "INFO");
|
|
323
|
+
return messageLevel <= LogLevelIndex[configLevel];
|
|
324
|
+
}
|
|
325
|
+
formatMessage(logMessage) {
|
|
326
|
+
const { level, message, timestamp, data } = logMessage;
|
|
327
|
+
let formattedMessage = `[${timestamp}] ${level}: ${message}`;
|
|
328
|
+
if (data) {
|
|
329
|
+
try {
|
|
330
|
+
formattedMessage += `
|
|
331
|
+
${JSON.stringify(data, null, 2)}`;
|
|
332
|
+
} catch (error) {
|
|
333
|
+
formattedMessage += `
|
|
334
|
+
[JSON.stringify Error/Circular]: ${error}`;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return formattedMessage;
|
|
338
|
+
}
|
|
339
|
+
log(level, message, data) {
|
|
340
|
+
if (!this.shouldLog(LogLevelIndex[level])) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const logMessage = {
|
|
344
|
+
level,
|
|
345
|
+
message,
|
|
346
|
+
timestamp: this.getTimestamp(),
|
|
347
|
+
data
|
|
348
|
+
};
|
|
349
|
+
const formattedMessage = this.formatMessage(logMessage);
|
|
350
|
+
switch (level) {
|
|
351
|
+
case "DEBUG":
|
|
352
|
+
console.debug(formattedMessage);
|
|
353
|
+
break;
|
|
354
|
+
case "INFO":
|
|
355
|
+
console.info(formattedMessage);
|
|
356
|
+
break;
|
|
357
|
+
case "WARN":
|
|
358
|
+
console.warn(formattedMessage);
|
|
359
|
+
break;
|
|
360
|
+
case "ERROR":
|
|
361
|
+
case "FATAL":
|
|
362
|
+
console.error(formattedMessage);
|
|
363
|
+
break;
|
|
364
|
+
case "OFF":
|
|
365
|
+
break;
|
|
366
|
+
default:
|
|
367
|
+
console.log(formattedMessage);
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
336
370
|
}
|
|
337
371
|
/**
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```typescript
|
|
341
|
-
* SomeError.isType('UNEXPECTED_ERROR');
|
|
342
|
-
* ```
|
|
372
|
+
* debug will be displayed when LogLevel level is set to DEBUG(5)
|
|
343
373
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
374
|
+
debug(message, data) {
|
|
375
|
+
this.log("DEBUG", message, data);
|
|
346
376
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
377
|
+
/**
|
|
378
|
+
* info will be displayed when LogLevel level is set to DEBUG(5), INFO(4)
|
|
379
|
+
*/
|
|
380
|
+
info(message, data) {
|
|
381
|
+
this.log("INFO", message, data);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* warn will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3)
|
|
385
|
+
*/
|
|
386
|
+
warn(message, data) {
|
|
387
|
+
this.log("WARN", message, data);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* error will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2)
|
|
391
|
+
*/
|
|
392
|
+
error(message, data) {
|
|
393
|
+
this.log("ERROR", message, data);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* fatal will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2), FATAL(1)
|
|
397
|
+
*/
|
|
398
|
+
fatal(message, data) {
|
|
399
|
+
this.log("FATAL", message, data);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Set the logging level you would like system to display
|
|
403
|
+
* * 5 DEBUG - show all logs
|
|
404
|
+
* * 4 INFO
|
|
405
|
+
* * 3 WARN
|
|
406
|
+
* * 2 ERROR
|
|
407
|
+
* * 1 FATAL
|
|
408
|
+
* * 0 OFF - disable logs
|
|
409
|
+
*/
|
|
410
|
+
setLogLevel(level) {
|
|
411
|
+
this.config.set("logLevel", level);
|
|
412
|
+
}
|
|
413
|
+
getLogLevel() {
|
|
414
|
+
return this.config.get("logLevel", "INFO");
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
*
|
|
418
|
+
* @returns logs levels displayed on the configured LogLevel
|
|
419
|
+
*/
|
|
420
|
+
getEnabledLogLevels() {
|
|
421
|
+
return Object.keys(LogLevelIndex).filter((s) => {
|
|
422
|
+
return this.shouldLog(LogLevelIndex[s]) && s !== "OFF";
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
var logger = Logger.getInstance();
|
|
427
|
+
|
|
428
|
+
// src/channel/rpc_0_7_1.ts
|
|
429
|
+
var rpc_0_7_1_exports = {};
|
|
430
|
+
__export(rpc_0_7_1_exports, {
|
|
431
|
+
RpcChannel: () => RpcChannel
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// src/types/index.ts
|
|
435
|
+
var types_exports = {};
|
|
436
|
+
__export(types_exports, {
|
|
437
|
+
BlockStatus: () => BlockStatus,
|
|
438
|
+
BlockTag: () => BlockTag,
|
|
439
|
+
EDAMode: () => EDAMode,
|
|
440
|
+
EDataAvailabilityMode: () => EDataAvailabilityMode,
|
|
441
|
+
ETH_ADDRESS: () => ETH_ADDRESS,
|
|
442
|
+
ETransactionExecutionStatus: () => ETransactionExecutionStatus,
|
|
443
|
+
ETransactionStatus: () => ETransactionStatus,
|
|
444
|
+
ETransactionVersion: () => ETransactionVersion2,
|
|
445
|
+
ETransactionVersion2: () => ETransactionVersion22,
|
|
446
|
+
ETransactionVersion3: () => ETransactionVersion3,
|
|
447
|
+
EntryPointType: () => EntryPointType,
|
|
448
|
+
Literal: () => Literal,
|
|
449
|
+
NON_ZERO_PREFIX: () => NON_ZERO_PREFIX,
|
|
450
|
+
OutsideExecutionTypesV1: () => OutsideExecutionTypesV1,
|
|
451
|
+
OutsideExecutionTypesV2: () => OutsideExecutionTypesV2,
|
|
452
|
+
OutsideExecutionVersion: () => OutsideExecutionVersion,
|
|
453
|
+
RPC: () => api_exports,
|
|
454
|
+
TransactionExecutionStatus: () => TransactionExecutionStatus,
|
|
455
|
+
TransactionFinalityStatus: () => TransactionFinalityStatus,
|
|
456
|
+
TransactionType: () => TransactionType,
|
|
457
|
+
TypedDataRevision: () => TypedDataRevision,
|
|
458
|
+
Uint: () => Uint,
|
|
459
|
+
ValidateType: () => ValidateType,
|
|
460
|
+
isRPC08_FeeEstimate: () => isRPC08_FeeEstimate,
|
|
461
|
+
isRPC08_ResourceBounds: () => isRPC08_ResourceBounds
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// src/types/lib/contract/index.ts
|
|
465
|
+
var EntryPointType = {
|
|
466
|
+
EXTERNAL: "EXTERNAL",
|
|
467
|
+
L1_HANDLER: "L1_HANDLER",
|
|
468
|
+
CONSTRUCTOR: "CONSTRUCTOR"
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// src/types/lib/index.ts
|
|
472
|
+
var TransactionType = {
|
|
473
|
+
DECLARE: "DECLARE",
|
|
474
|
+
DEPLOY: "DEPLOY",
|
|
475
|
+
DEPLOY_ACCOUNT: "DEPLOY_ACCOUNT",
|
|
476
|
+
INVOKE: "INVOKE_FUNCTION"
|
|
477
|
+
};
|
|
393
478
|
var TransactionFinalityStatus = {
|
|
394
479
|
NOT_RECEIVED: "NOT_RECEIVED",
|
|
395
480
|
RECEIVED: "RECEIVED",
|
|
@@ -509,6 +594,23 @@ import {
|
|
|
509
594
|
TypedDataRevision
|
|
510
595
|
} from "starknet-types-07";
|
|
511
596
|
|
|
597
|
+
// src/utils/json.ts
|
|
598
|
+
var json_exports = {};
|
|
599
|
+
__export(json_exports, {
|
|
600
|
+
parse: () => parse2,
|
|
601
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
602
|
+
stringify: () => stringify2
|
|
603
|
+
});
|
|
604
|
+
import * as json from "lossless-json";
|
|
605
|
+
var parseIntAsNumberOrBigInt = (str) => {
|
|
606
|
+
if (!json.isInteger(str)) return parseFloat(str);
|
|
607
|
+
const num = parseInt(str, 10);
|
|
608
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
609
|
+
};
|
|
610
|
+
var parse2 = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
611
|
+
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
612
|
+
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
613
|
+
|
|
512
614
|
// src/utils/batch/index.ts
|
|
513
615
|
var BatchClient = class {
|
|
514
616
|
nodeUrl;
|
|
@@ -3426,6 +3528,38 @@ __export(stark_exports, {
|
|
|
3426
3528
|
import { getPublicKey, getStarkKey, utils } from "@scure/starknet";
|
|
3427
3529
|
import { gzip, ungzip } from "pako";
|
|
3428
3530
|
|
|
3531
|
+
// src/utils/resolve.ts
|
|
3532
|
+
function isV3Tx(details) {
|
|
3533
|
+
const version = details.version ? toHex(details.version) : ETransactionVersion2.V3;
|
|
3534
|
+
return version === ETransactionVersion2.V3 || version === ETransactionVersion2.F3;
|
|
3535
|
+
}
|
|
3536
|
+
function isVersion(expected, provided) {
|
|
3537
|
+
const expectedParts = expected.split(".");
|
|
3538
|
+
const providedParts = provided.split(".");
|
|
3539
|
+
return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
|
|
3540
|
+
}
|
|
3541
|
+
function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
|
|
3542
|
+
return Object.values(_SupportedRpcVersion).some(
|
|
3543
|
+
(v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
|
|
3544
|
+
);
|
|
3545
|
+
}
|
|
3546
|
+
function toAnyPatchVersion(version) {
|
|
3547
|
+
const parts = version.split(".");
|
|
3548
|
+
if (parts.length < 3) {
|
|
3549
|
+
return version;
|
|
3550
|
+
}
|
|
3551
|
+
return `${parts[0]}.${parts[1]}.*`;
|
|
3552
|
+
}
|
|
3553
|
+
function isPendingBlock(response) {
|
|
3554
|
+
return response.status === "PENDING";
|
|
3555
|
+
}
|
|
3556
|
+
function isPendingTransaction(response) {
|
|
3557
|
+
return !("block_hash" in response);
|
|
3558
|
+
}
|
|
3559
|
+
function isPendingStateUpdate(response) {
|
|
3560
|
+
return !("block_hash" in response);
|
|
3561
|
+
}
|
|
3562
|
+
|
|
3429
3563
|
// src/utils/stark/rpc07.ts
|
|
3430
3564
|
function estimateFeeToBounds(estimate, overhead) {
|
|
3431
3565
|
const maxUnits = estimate.data_gas_consumed !== void 0 && estimate.data_gas_price !== void 0 ? toHex(
|
|
@@ -3465,49 +3599,6 @@ function estimateFeeToBounds2(estimate, overhead) {
|
|
|
3465
3599
|
};
|
|
3466
3600
|
}
|
|
3467
3601
|
|
|
3468
|
-
// src/global/config.ts
|
|
3469
|
-
var Configuration = class _Configuration {
|
|
3470
|
-
static instance;
|
|
3471
|
-
config;
|
|
3472
|
-
constructor() {
|
|
3473
|
-
this.initialize();
|
|
3474
|
-
}
|
|
3475
|
-
initialize() {
|
|
3476
|
-
this.config = { ...DEFAULT_GLOBAL_CONFIG };
|
|
3477
|
-
}
|
|
3478
|
-
static getInstance() {
|
|
3479
|
-
if (!_Configuration.instance) {
|
|
3480
|
-
_Configuration.instance = new _Configuration();
|
|
3481
|
-
}
|
|
3482
|
-
return _Configuration.instance;
|
|
3483
|
-
}
|
|
3484
|
-
get(key, defaultValue) {
|
|
3485
|
-
return this.config[key] ?? defaultValue;
|
|
3486
|
-
}
|
|
3487
|
-
set(key, value) {
|
|
3488
|
-
this.config[key] = value;
|
|
3489
|
-
}
|
|
3490
|
-
update(configData) {
|
|
3491
|
-
this.config = {
|
|
3492
|
-
...this.config,
|
|
3493
|
-
...configData
|
|
3494
|
-
};
|
|
3495
|
-
}
|
|
3496
|
-
getAll() {
|
|
3497
|
-
return { ...this.config };
|
|
3498
|
-
}
|
|
3499
|
-
reset() {
|
|
3500
|
-
this.initialize();
|
|
3501
|
-
}
|
|
3502
|
-
delete(key) {
|
|
3503
|
-
delete this.config[key];
|
|
3504
|
-
}
|
|
3505
|
-
hasKey(key) {
|
|
3506
|
-
return key in this.config;
|
|
3507
|
-
}
|
|
3508
|
-
};
|
|
3509
|
-
var config = Configuration.getInstance();
|
|
3510
|
-
|
|
3511
3602
|
// src/utils/stark/index.ts
|
|
3512
3603
|
function compressProgram(jsonProgram) {
|
|
3513
3604
|
const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
|
|
@@ -3549,7 +3640,7 @@ function estimateFeeToBounds3(estimate, overhead = config.get("feeMarginPercenta
|
|
|
3549
3640
|
return {
|
|
3550
3641
|
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
3551
3642
|
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
3552
|
-
...specVersion
|
|
3643
|
+
...specVersion && isVersion("0.8", specVersion) && {
|
|
3553
3644
|
l1_data_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
3554
3645
|
}
|
|
3555
3646
|
};
|
|
@@ -3648,32 +3739,125 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
|
3648
3739
|
return { ...contract, program: decompressProgram(contract.program) };
|
|
3649
3740
|
}
|
|
3650
3741
|
|
|
3651
|
-
// src/utils/
|
|
3652
|
-
var
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3742
|
+
// src/utils/errors/rpc.ts
|
|
3743
|
+
var errorCodes = {
|
|
3744
|
+
FAILED_TO_RECEIVE_TXN: 1,
|
|
3745
|
+
NO_TRACE_AVAILABLE: 10,
|
|
3746
|
+
CONTRACT_NOT_FOUND: 20,
|
|
3747
|
+
ENTRYPOINT_NOT_FOUND: 21,
|
|
3748
|
+
BLOCK_NOT_FOUND: 24,
|
|
3749
|
+
INVALID_TXN_INDEX: 27,
|
|
3750
|
+
CLASS_HASH_NOT_FOUND: 28,
|
|
3751
|
+
TXN_HASH_NOT_FOUND: 29,
|
|
3752
|
+
PAGE_SIZE_TOO_BIG: 31,
|
|
3753
|
+
NO_BLOCKS: 32,
|
|
3754
|
+
INVALID_CONTINUATION_TOKEN: 33,
|
|
3755
|
+
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
3756
|
+
CONTRACT_ERROR: 40,
|
|
3757
|
+
TRANSACTION_EXECUTION_ERROR: 41,
|
|
3758
|
+
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
3759
|
+
CLASS_ALREADY_DECLARED: 51,
|
|
3760
|
+
INVALID_TRANSACTION_NONCE: 52,
|
|
3761
|
+
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
3762
|
+
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
3763
|
+
VALIDATION_FAILURE: 55,
|
|
3764
|
+
COMPILATION_FAILED: 56,
|
|
3765
|
+
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
3766
|
+
NON_ACCOUNT: 58,
|
|
3767
|
+
DUPLICATE_TX: 59,
|
|
3768
|
+
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
3769
|
+
UNSUPPORTED_TX_VERSION: 61,
|
|
3770
|
+
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
3771
|
+
UNEXPECTED_ERROR: 63,
|
|
3772
|
+
INVALID_SUBSCRIPTION_ID: 66,
|
|
3773
|
+
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
3774
|
+
TOO_MANY_BLOCKS_BACK: 68,
|
|
3775
|
+
COMPILATION_ERROR: 100,
|
|
3776
|
+
INVALID_ADDRESS: 150,
|
|
3777
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
3778
|
+
INVALID_SIGNATURE: 153,
|
|
3779
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
3780
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
3781
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
3782
|
+
INVALID_TIME_BOUNDS: 157,
|
|
3783
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
3784
|
+
INVALID_CLASS_HASH: 159,
|
|
3785
|
+
INVALID_ID: 160,
|
|
3786
|
+
UNKNOWN_ERROR: 163
|
|
3787
|
+
};
|
|
3788
|
+
var rpc_default = errorCodes;
|
|
3789
|
+
|
|
3790
|
+
// src/utils/errors/index.ts
|
|
3791
|
+
function fixStack(target, fn = target.constructor) {
|
|
3792
|
+
const { captureStackTrace } = Error;
|
|
3793
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
3660
3794
|
}
|
|
3661
|
-
function
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
3665
|
-
return result;
|
|
3795
|
+
function fixProto(target, prototype) {
|
|
3796
|
+
const { setPrototypeOf } = Object;
|
|
3797
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3666
3798
|
}
|
|
3799
|
+
var CustomError = class extends Error {
|
|
3800
|
+
name;
|
|
3801
|
+
constructor(message) {
|
|
3802
|
+
super(message);
|
|
3803
|
+
Object.defineProperty(this, "name", {
|
|
3804
|
+
value: new.target.name,
|
|
3805
|
+
enumerable: false,
|
|
3806
|
+
configurable: true
|
|
3807
|
+
});
|
|
3808
|
+
fixProto(this, new.target.prototype);
|
|
3809
|
+
fixStack(this);
|
|
3810
|
+
}
|
|
3811
|
+
};
|
|
3812
|
+
var LibraryError = class extends CustomError {
|
|
3813
|
+
};
|
|
3814
|
+
var RpcError = class extends LibraryError {
|
|
3815
|
+
constructor(baseError, method, params) {
|
|
3816
|
+
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
3667
3817
|
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3818
|
+
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
3819
|
+
this.baseError = baseError;
|
|
3820
|
+
this.request = { method, params };
|
|
3821
|
+
}
|
|
3822
|
+
request;
|
|
3823
|
+
get code() {
|
|
3824
|
+
return this.baseError.code;
|
|
3825
|
+
}
|
|
3826
|
+
/**
|
|
3827
|
+
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
3828
|
+
* @example
|
|
3829
|
+
* ```typescript
|
|
3830
|
+
* SomeError.isType('UNEXPECTED_ERROR');
|
|
3831
|
+
* ```
|
|
3832
|
+
*/
|
|
3833
|
+
isType(typeName) {
|
|
3834
|
+
return rpc_default[typeName] === this.code;
|
|
3835
|
+
}
|
|
3836
|
+
};
|
|
3837
|
+
|
|
3838
|
+
// src/utils/eth.ts
|
|
3839
|
+
var eth_exports = {};
|
|
3840
|
+
__export(eth_exports, {
|
|
3841
|
+
ethRandomPrivateKey: () => ethRandomPrivateKey,
|
|
3842
|
+
validateAndParseEthAddress: () => validateAndParseEthAddress
|
|
3843
|
+
});
|
|
3844
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
3845
|
+
function ethRandomPrivateKey() {
|
|
3846
|
+
return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
|
|
3847
|
+
}
|
|
3848
|
+
function validateAndParseEthAddress(address) {
|
|
3849
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address ");
|
|
3850
|
+
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
3851
|
+
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
3852
|
+
return result;
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
// src/utils/connect/fetch.ts
|
|
3856
|
+
var fetch_default = typeof globalThis !== "undefined" && globalThis.fetch.bind(globalThis) || typeof window !== "undefined" && window.fetch.bind(window) || typeof global !== "undefined" && global.fetch.bind(global) || (() => {
|
|
3857
|
+
throw new LibraryError(
|
|
3858
|
+
"'fetch()' not detected, use the 'baseFetch' constructor parameter to set it"
|
|
3859
|
+
);
|
|
3860
|
+
});
|
|
3677
3861
|
|
|
3678
3862
|
// src/utils/provider.ts
|
|
3679
3863
|
var provider_exports = {};
|
|
@@ -3682,151 +3866,10 @@ __export(provider_exports, {
|
|
|
3682
3866
|
createSierraContractClass: () => createSierraContractClass,
|
|
3683
3867
|
getDefaultNodeUrl: () => getDefaultNodeUrl,
|
|
3684
3868
|
getDefaultNodes: () => getDefaultNodes,
|
|
3685
|
-
isPendingBlock: () => isPendingBlock,
|
|
3686
|
-
isPendingStateUpdate: () => isPendingStateUpdate,
|
|
3687
|
-
isPendingTransaction: () => isPendingTransaction,
|
|
3688
|
-
isV3Tx: () => isV3Tx,
|
|
3689
|
-
isVersion: () => isVersion,
|
|
3690
3869
|
parseContract: () => parseContract,
|
|
3691
|
-
stringToSpecVersion: () => stringToSpecVersion,
|
|
3692
3870
|
validBlockTags: () => validBlockTags,
|
|
3693
3871
|
wait: () => wait
|
|
3694
3872
|
});
|
|
3695
|
-
|
|
3696
|
-
// src/global/logger.type.ts
|
|
3697
|
-
var LogLevelIndex = {
|
|
3698
|
-
DEBUG: 5,
|
|
3699
|
-
INFO: 4,
|
|
3700
|
-
WARN: 3,
|
|
3701
|
-
ERROR: 2,
|
|
3702
|
-
FATAL: 1,
|
|
3703
|
-
OFF: 0
|
|
3704
|
-
};
|
|
3705
|
-
|
|
3706
|
-
// src/global/logger.ts
|
|
3707
|
-
var Logger = class _Logger {
|
|
3708
|
-
static instance;
|
|
3709
|
-
config;
|
|
3710
|
-
constructor() {
|
|
3711
|
-
this.config = config;
|
|
3712
|
-
}
|
|
3713
|
-
static getInstance() {
|
|
3714
|
-
if (!_Logger.instance) {
|
|
3715
|
-
_Logger.instance = new _Logger();
|
|
3716
|
-
}
|
|
3717
|
-
return _Logger.instance;
|
|
3718
|
-
}
|
|
3719
|
-
getTimestamp() {
|
|
3720
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3721
|
-
}
|
|
3722
|
-
shouldLog(messageLevel) {
|
|
3723
|
-
const configLevel = this.config.get("logLevel", "INFO");
|
|
3724
|
-
return messageLevel <= LogLevelIndex[configLevel];
|
|
3725
|
-
}
|
|
3726
|
-
formatMessage(logMessage) {
|
|
3727
|
-
const { level, message, timestamp, data } = logMessage;
|
|
3728
|
-
let formattedMessage = `[${timestamp}] ${level}: ${message}`;
|
|
3729
|
-
if (data) {
|
|
3730
|
-
try {
|
|
3731
|
-
formattedMessage += `
|
|
3732
|
-
${JSON.stringify(data, null, 2)}`;
|
|
3733
|
-
} catch (error) {
|
|
3734
|
-
formattedMessage += `
|
|
3735
|
-
[JSON.stringify Error/Circular]: ${error}`;
|
|
3736
|
-
}
|
|
3737
|
-
}
|
|
3738
|
-
return formattedMessage;
|
|
3739
|
-
}
|
|
3740
|
-
log(level, message, data) {
|
|
3741
|
-
if (!this.shouldLog(LogLevelIndex[level])) {
|
|
3742
|
-
return;
|
|
3743
|
-
}
|
|
3744
|
-
const logMessage = {
|
|
3745
|
-
level,
|
|
3746
|
-
message,
|
|
3747
|
-
timestamp: this.getTimestamp(),
|
|
3748
|
-
data
|
|
3749
|
-
};
|
|
3750
|
-
const formattedMessage = this.formatMessage(logMessage);
|
|
3751
|
-
switch (level) {
|
|
3752
|
-
case "DEBUG":
|
|
3753
|
-
console.debug(formattedMessage);
|
|
3754
|
-
break;
|
|
3755
|
-
case "INFO":
|
|
3756
|
-
console.info(formattedMessage);
|
|
3757
|
-
break;
|
|
3758
|
-
case "WARN":
|
|
3759
|
-
console.warn(formattedMessage);
|
|
3760
|
-
break;
|
|
3761
|
-
case "ERROR":
|
|
3762
|
-
case "FATAL":
|
|
3763
|
-
console.error(formattedMessage);
|
|
3764
|
-
break;
|
|
3765
|
-
case "OFF":
|
|
3766
|
-
break;
|
|
3767
|
-
default:
|
|
3768
|
-
console.log(formattedMessage);
|
|
3769
|
-
break;
|
|
3770
|
-
}
|
|
3771
|
-
}
|
|
3772
|
-
/**
|
|
3773
|
-
* debug will be displayed when LogLevel level is set to DEBUG(5)
|
|
3774
|
-
*/
|
|
3775
|
-
debug(message, data) {
|
|
3776
|
-
this.log("DEBUG", message, data);
|
|
3777
|
-
}
|
|
3778
|
-
/**
|
|
3779
|
-
* info will be displayed when LogLevel level is set to DEBUG(5), INFO(4)
|
|
3780
|
-
*/
|
|
3781
|
-
info(message, data) {
|
|
3782
|
-
this.log("INFO", message, data);
|
|
3783
|
-
}
|
|
3784
|
-
/**
|
|
3785
|
-
* warn will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3)
|
|
3786
|
-
*/
|
|
3787
|
-
warn(message, data) {
|
|
3788
|
-
this.log("WARN", message, data);
|
|
3789
|
-
}
|
|
3790
|
-
/**
|
|
3791
|
-
* error will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2)
|
|
3792
|
-
*/
|
|
3793
|
-
error(message, data) {
|
|
3794
|
-
this.log("ERROR", message, data);
|
|
3795
|
-
}
|
|
3796
|
-
/**
|
|
3797
|
-
* fatal will be displayed when LogLevel level is set to DEBUG(5), INFO(4), WARN(3), ERROR(2), FATAL(1)
|
|
3798
|
-
*/
|
|
3799
|
-
fatal(message, data) {
|
|
3800
|
-
this.log("FATAL", message, data);
|
|
3801
|
-
}
|
|
3802
|
-
/**
|
|
3803
|
-
* Set the logging level you would like system to display
|
|
3804
|
-
* * 5 DEBUG - show all logs
|
|
3805
|
-
* * 4 INFO
|
|
3806
|
-
* * 3 WARN
|
|
3807
|
-
* * 2 ERROR
|
|
3808
|
-
* * 1 FATAL
|
|
3809
|
-
* * 0 OFF - disable logs
|
|
3810
|
-
*/
|
|
3811
|
-
setLogLevel(level) {
|
|
3812
|
-
this.config.set("logLevel", level);
|
|
3813
|
-
}
|
|
3814
|
-
getLogLevel() {
|
|
3815
|
-
return this.config.get("logLevel", "INFO");
|
|
3816
|
-
}
|
|
3817
|
-
/**
|
|
3818
|
-
*
|
|
3819
|
-
* @returns logs levels displayed on the configured LogLevel
|
|
3820
|
-
*/
|
|
3821
|
-
getEnabledLogLevels() {
|
|
3822
|
-
return Object.keys(LogLevelIndex).filter((s) => {
|
|
3823
|
-
return this.shouldLog(LogLevelIndex[s]) && s !== "OFF";
|
|
3824
|
-
});
|
|
3825
|
-
}
|
|
3826
|
-
};
|
|
3827
|
-
var logger = Logger.getInstance();
|
|
3828
|
-
|
|
3829
|
-
// src/utils/provider.ts
|
|
3830
3873
|
function wait(delay) {
|
|
3831
3874
|
return new Promise((res) => {
|
|
3832
3875
|
setTimeout(res, delay);
|
|
@@ -3967,28 +4010,6 @@ var Block = class {
|
|
|
3967
4010
|
valueOf = () => this.number;
|
|
3968
4011
|
toString = () => this.hash;
|
|
3969
4012
|
};
|
|
3970
|
-
function isV3Tx(details) {
|
|
3971
|
-
const version = details.version ? toHex(details.version) : ETransactionVersion2.V3;
|
|
3972
|
-
return version === ETransactionVersion2.V3 || version === ETransactionVersion2.F3;
|
|
3973
|
-
}
|
|
3974
|
-
function isVersion(version, response) {
|
|
3975
|
-
const [majorS, minorS] = version.split(".");
|
|
3976
|
-
const [majorR, minorR] = response.split(".");
|
|
3977
|
-
return majorS === majorR && minorS === minorR;
|
|
3978
|
-
}
|
|
3979
|
-
function stringToSpecVersion(version) {
|
|
3980
|
-
const [major, minor] = version.split(".");
|
|
3981
|
-
return `${major}.${minor}`;
|
|
3982
|
-
}
|
|
3983
|
-
function isPendingBlock(response) {
|
|
3984
|
-
return response.status === "PENDING";
|
|
3985
|
-
}
|
|
3986
|
-
function isPendingTransaction(response) {
|
|
3987
|
-
return !("block_hash" in response);
|
|
3988
|
-
}
|
|
3989
|
-
function isPendingStateUpdate(response) {
|
|
3990
|
-
return !("block_hash" in response);
|
|
3991
|
-
}
|
|
3992
4013
|
|
|
3993
4014
|
// src/utils/transaction.ts
|
|
3994
4015
|
var transaction_exports = {};
|
|
@@ -4081,14 +4102,18 @@ function getVersionsByType(versionType) {
|
|
|
4081
4102
|
} : { v1: ETransactionVersion2.V1, v2: ETransactionVersion2.V2, v3: ETransactionVersion2.V3 };
|
|
4082
4103
|
}
|
|
4083
4104
|
|
|
4084
|
-
// src/channel/
|
|
4105
|
+
// src/channel/rpc_0_7_1.ts
|
|
4085
4106
|
var defaultOptions = {
|
|
4086
4107
|
headers: { "Content-Type": "application/json" },
|
|
4087
4108
|
blockIdentifier: BlockTag.PENDING,
|
|
4088
4109
|
retries: 200
|
|
4089
4110
|
};
|
|
4090
4111
|
var RpcChannel = class {
|
|
4091
|
-
id = "
|
|
4112
|
+
id = "RPC071";
|
|
4113
|
+
/**
|
|
4114
|
+
* RPC specification version this Channel class implements
|
|
4115
|
+
*/
|
|
4116
|
+
channelSpecVersion = _SupportedRpcVersion.v0_7_1;
|
|
4092
4117
|
nodeUrl;
|
|
4093
4118
|
headers;
|
|
4094
4119
|
requestId;
|
|
@@ -4097,6 +4122,9 @@ var RpcChannel = class {
|
|
|
4097
4122
|
waitMode;
|
|
4098
4123
|
// behave like web2 rpc and return when tx is processed
|
|
4099
4124
|
chainId;
|
|
4125
|
+
/**
|
|
4126
|
+
* RPC specification version of the connected node
|
|
4127
|
+
*/
|
|
4100
4128
|
specVersion;
|
|
4101
4129
|
transactionRetryIntervalFallback;
|
|
4102
4130
|
batchClient;
|
|
@@ -4115,13 +4143,21 @@ var RpcChannel = class {
|
|
|
4115
4143
|
waitMode
|
|
4116
4144
|
} = optionsOrProvider || {};
|
|
4117
4145
|
if (Object.values(_NetworkName).includes(nodeUrl)) {
|
|
4118
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
4146
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
4147
|
+
nodeUrl,
|
|
4148
|
+
optionsOrProvider?.default,
|
|
4149
|
+
this.channelSpecVersion
|
|
4150
|
+
);
|
|
4119
4151
|
} else if (nodeUrl) {
|
|
4120
4152
|
this.nodeUrl = nodeUrl;
|
|
4121
4153
|
} else {
|
|
4122
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
4154
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
4155
|
+
void 0,
|
|
4156
|
+
optionsOrProvider?.default,
|
|
4157
|
+
this.channelSpecVersion
|
|
4158
|
+
);
|
|
4123
4159
|
}
|
|
4124
|
-
this.baseFetch = baseFetch
|
|
4160
|
+
this.baseFetch = baseFetch || config.get("fetch") || fetch_default;
|
|
4125
4161
|
this.blockIdentifier = blockIdentifier ?? defaultOptions.blockIdentifier;
|
|
4126
4162
|
this.chainId = chainId;
|
|
4127
4163
|
this.headers = { ...defaultOptions.headers, ...headers };
|
|
@@ -4199,24 +4235,32 @@ var RpcChannel = class {
|
|
|
4199
4235
|
return this.chainId;
|
|
4200
4236
|
}
|
|
4201
4237
|
/**
|
|
4202
|
-
* fetch
|
|
4203
|
-
*
|
|
4204
|
-
* @example this.specVersion = "0.8"
|
|
4238
|
+
* fetch rpc node specVersion
|
|
4239
|
+
* @example this.specVersion = "0.7.1"
|
|
4205
4240
|
*/
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
const extendedVersion = await this.getSpecificationVersion();
|
|
4209
|
-
const [major, minor] = extendedVersion.split(".");
|
|
4210
|
-
const specVerson = `${major}.${minor}`;
|
|
4211
|
-
this.specVersion ??= specVerson;
|
|
4212
|
-
}
|
|
4213
|
-
return this.specVersion;
|
|
4241
|
+
getSpecVersion() {
|
|
4242
|
+
return this.fetchEndpoint("starknet_specVersion");
|
|
4214
4243
|
}
|
|
4215
4244
|
/**
|
|
4216
|
-
* fetch
|
|
4245
|
+
* fetch if undefined test and set specVersion, else just return this.specVersion
|
|
4246
|
+
* @example this.specVersion = "0.7.1"
|
|
4217
4247
|
*/
|
|
4218
|
-
|
|
4219
|
-
|
|
4248
|
+
async setUpSpecVersion() {
|
|
4249
|
+
if (!this.specVersion) {
|
|
4250
|
+
const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
|
|
4251
|
+
if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
|
|
4252
|
+
logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
|
|
4253
|
+
channelId: this.id,
|
|
4254
|
+
channelSpecVersion: this.channelSpecVersion,
|
|
4255
|
+
nodeSpecVersion: this.specVersion
|
|
4256
|
+
});
|
|
4257
|
+
}
|
|
4258
|
+
if (!isSupportedSpecVersion(unknownSpecVersion)) {
|
|
4259
|
+
throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
|
|
4260
|
+
}
|
|
4261
|
+
this.specVersion = unknownSpecVersion;
|
|
4262
|
+
}
|
|
4263
|
+
return this.specVersion;
|
|
4220
4264
|
}
|
|
4221
4265
|
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
4222
4266
|
const contract_address = toHex(contractAddress);
|
|
@@ -4683,9 +4727,9 @@ var RpcChannel = class {
|
|
|
4683
4727
|
}
|
|
4684
4728
|
};
|
|
4685
4729
|
|
|
4686
|
-
// src/channel/
|
|
4687
|
-
var
|
|
4688
|
-
__export(
|
|
4730
|
+
// src/channel/rpc_0_8_1.ts
|
|
4731
|
+
var rpc_0_8_1_exports = {};
|
|
4732
|
+
__export(rpc_0_8_1_exports, {
|
|
4689
4733
|
RpcChannel: () => RpcChannel2
|
|
4690
4734
|
});
|
|
4691
4735
|
var defaultOptions2 = {
|
|
@@ -4694,7 +4738,11 @@ var defaultOptions2 = {
|
|
|
4694
4738
|
retries: 200
|
|
4695
4739
|
};
|
|
4696
4740
|
var RpcChannel2 = class {
|
|
4697
|
-
id = "
|
|
4741
|
+
id = "RPC081";
|
|
4742
|
+
/**
|
|
4743
|
+
* RPC specification version this Channel class implements
|
|
4744
|
+
*/
|
|
4745
|
+
channelSpecVersion = _SupportedRpcVersion.v0_8_1;
|
|
4698
4746
|
nodeUrl;
|
|
4699
4747
|
headers;
|
|
4700
4748
|
requestId;
|
|
@@ -4703,6 +4751,9 @@ var RpcChannel2 = class {
|
|
|
4703
4751
|
waitMode;
|
|
4704
4752
|
// behave like web2 rpc and return when tx is processed
|
|
4705
4753
|
chainId;
|
|
4754
|
+
/**
|
|
4755
|
+
* RPC specification version of the connected node
|
|
4756
|
+
*/
|
|
4706
4757
|
specVersion;
|
|
4707
4758
|
transactionRetryIntervalFallback;
|
|
4708
4759
|
batchClient;
|
|
@@ -4721,13 +4772,21 @@ var RpcChannel2 = class {
|
|
|
4721
4772
|
waitMode
|
|
4722
4773
|
} = optionsOrProvider || {};
|
|
4723
4774
|
if (Object.values(_NetworkName).includes(nodeUrl)) {
|
|
4724
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
4775
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
4776
|
+
nodeUrl,
|
|
4777
|
+
optionsOrProvider?.default,
|
|
4778
|
+
this.channelSpecVersion
|
|
4779
|
+
);
|
|
4725
4780
|
} else if (nodeUrl) {
|
|
4726
4781
|
this.nodeUrl = nodeUrl;
|
|
4727
4782
|
} else {
|
|
4728
|
-
this.nodeUrl = getDefaultNodeUrl(
|
|
4783
|
+
this.nodeUrl = getDefaultNodeUrl(
|
|
4784
|
+
void 0,
|
|
4785
|
+
optionsOrProvider?.default,
|
|
4786
|
+
this.channelSpecVersion
|
|
4787
|
+
);
|
|
4729
4788
|
}
|
|
4730
|
-
this.baseFetch = baseFetch
|
|
4789
|
+
this.baseFetch = baseFetch || config.get("fetch") || fetch_default;
|
|
4731
4790
|
this.blockIdentifier = blockIdentifier ?? defaultOptions2.blockIdentifier;
|
|
4732
4791
|
this.chainId = chainId;
|
|
4733
4792
|
this.headers = { ...defaultOptions2.headers, ...headers };
|
|
@@ -4803,6 +4862,34 @@ var RpcChannel2 = class {
|
|
|
4803
4862
|
this.chainId ??= await this.fetchEndpoint("starknet_chainId");
|
|
4804
4863
|
return this.chainId;
|
|
4805
4864
|
}
|
|
4865
|
+
/**
|
|
4866
|
+
* fetch rpc node specVersion
|
|
4867
|
+
* @example this.specVersion = "0.7.1"
|
|
4868
|
+
*/
|
|
4869
|
+
getSpecVersion() {
|
|
4870
|
+
return this.fetchEndpoint("starknet_specVersion");
|
|
4871
|
+
}
|
|
4872
|
+
/**
|
|
4873
|
+
* fetch if undefined else just return this.specVersion
|
|
4874
|
+
* @example this.specVersion = "0.8.1"
|
|
4875
|
+
*/
|
|
4876
|
+
async setUpSpecVersion() {
|
|
4877
|
+
if (!this.specVersion) {
|
|
4878
|
+
const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
|
|
4879
|
+
if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
|
|
4880
|
+
logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
|
|
4881
|
+
channelId: this.id,
|
|
4882
|
+
channelSpecVersion: this.channelSpecVersion,
|
|
4883
|
+
nodeSpecVersion: this.specVersion
|
|
4884
|
+
});
|
|
4885
|
+
}
|
|
4886
|
+
if (!isSupportedSpecVersion(unknownSpecVersion)) {
|
|
4887
|
+
throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
|
|
4888
|
+
}
|
|
4889
|
+
this.specVersion = unknownSpecVersion;
|
|
4890
|
+
}
|
|
4891
|
+
return this.specVersion;
|
|
4892
|
+
}
|
|
4806
4893
|
// TODO: New Method add test
|
|
4807
4894
|
/**
|
|
4808
4895
|
* 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
|
|
@@ -4832,26 +4919,6 @@ var RpcChannel2 = class {
|
|
|
4832
4919
|
class_hash
|
|
4833
4920
|
});
|
|
4834
4921
|
}
|
|
4835
|
-
/**
|
|
4836
|
-
* fetch if undefined else just return this.specVersion
|
|
4837
|
-
* return this.specVersion as 'M.m'
|
|
4838
|
-
* @example this.specVersion = "0.8"
|
|
4839
|
-
*/
|
|
4840
|
-
async getSpecVersion() {
|
|
4841
|
-
if (!this.specVersion) {
|
|
4842
|
-
const extendedVersion = await this.getSpecificationVersion();
|
|
4843
|
-
const [major, minor] = extendedVersion.split(".");
|
|
4844
|
-
const specVerson = `${major}.${minor}`;
|
|
4845
|
-
this.specVersion ??= specVerson;
|
|
4846
|
-
}
|
|
4847
|
-
return this.specVersion;
|
|
4848
|
-
}
|
|
4849
|
-
/**
|
|
4850
|
-
* fetch spec version in extended format "M.m.p-?"
|
|
4851
|
-
*/
|
|
4852
|
-
getSpecificationVersion() {
|
|
4853
|
-
return this.fetchEndpoint("starknet_specVersion");
|
|
4854
|
-
}
|
|
4855
4922
|
getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
4856
4923
|
const contract_address = toHex(contractAddress);
|
|
4857
4924
|
const block_id = new Block(blockIdentifier).identifier;
|
|
@@ -5233,8 +5300,16 @@ var RpcChannel2 = class {
|
|
|
5233
5300
|
}
|
|
5234
5301
|
};
|
|
5235
5302
|
|
|
5303
|
+
// src/utils/connect/ws.ts
|
|
5304
|
+
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 {
|
|
5305
|
+
constructor() {
|
|
5306
|
+
throw new LibraryError(
|
|
5307
|
+
"WebSocket module not detected, use the 'websocket' constructor parameter to set a compatible connection"
|
|
5308
|
+
);
|
|
5309
|
+
}
|
|
5310
|
+
};
|
|
5311
|
+
|
|
5236
5312
|
// src/channel/ws_0_8.ts
|
|
5237
|
-
import { WebSocket } from "isows";
|
|
5238
5313
|
var WSSubscriptions = {
|
|
5239
5314
|
NEW_HEADS: "newHeads",
|
|
5240
5315
|
EVENTS: "events",
|
|
@@ -5359,7 +5434,7 @@ var WebSocketChannel = class {
|
|
|
5359
5434
|
constructor(options = {}) {
|
|
5360
5435
|
const nodeUrl = options.nodeUrl || "http://localhost:3000 ";
|
|
5361
5436
|
this.nodeUrl = options.websocket ? options.websocket.url : nodeUrl;
|
|
5362
|
-
this.websocket = options.websocket
|
|
5437
|
+
this.websocket = options.websocket || config.get("websocket") || new ws_default(nodeUrl);
|
|
5363
5438
|
this.websocket.addEventListener("open", this.onOpen.bind(this));
|
|
5364
5439
|
this.websocket.addEventListener("close", this.onCloseProxy.bind(this));
|
|
5365
5440
|
this.websocket.addEventListener("message", this.onMessageProxy.bind(this));
|
|
@@ -5428,7 +5503,7 @@ var WebSocketChannel = class {
|
|
|
5428
5503
|
* Helper to check connection is open
|
|
5429
5504
|
*/
|
|
5430
5505
|
isConnected() {
|
|
5431
|
-
return this.websocket.readyState ===
|
|
5506
|
+
return this.websocket.readyState === ws_default.OPEN;
|
|
5432
5507
|
}
|
|
5433
5508
|
/**
|
|
5434
5509
|
* await while websocket is connected
|
|
@@ -5439,7 +5514,7 @@ var WebSocketChannel = class {
|
|
|
5439
5514
|
* ```
|
|
5440
5515
|
*/
|
|
5441
5516
|
async waitForConnection() {
|
|
5442
|
-
if (this.websocket.readyState !==
|
|
5517
|
+
if (this.websocket.readyState !== ws_default.OPEN) {
|
|
5443
5518
|
return new Promise((resolve, reject) => {
|
|
5444
5519
|
if (!this.websocket) return;
|
|
5445
5520
|
this.websocket.onopen = () => resolve(this.websocket.readyState);
|
|
@@ -5464,7 +5539,7 @@ var WebSocketChannel = class {
|
|
|
5464
5539
|
* ```
|
|
5465
5540
|
*/
|
|
5466
5541
|
async waitForDisconnection() {
|
|
5467
|
-
if (this.websocket.readyState !==
|
|
5542
|
+
if (this.websocket.readyState !== ws_default.CLOSED) {
|
|
5468
5543
|
return new Promise((resolve, reject) => {
|
|
5469
5544
|
if (!this.websocket) return;
|
|
5470
5545
|
this.websocket.onclose = () => resolve(this.websocket.readyState);
|
|
@@ -5517,7 +5592,7 @@ var WebSocketChannel = class {
|
|
|
5517
5592
|
* Reconnect re-create this.websocket instance
|
|
5518
5593
|
*/
|
|
5519
5594
|
reconnect() {
|
|
5520
|
-
this.websocket = new
|
|
5595
|
+
this.websocket = new ws_default(this.nodeUrl);
|
|
5521
5596
|
this.websocket.addEventListener("open", this.onOpen.bind(this));
|
|
5522
5597
|
this.websocket.addEventListener("close", this.onCloseProxy.bind(this));
|
|
5523
5598
|
this.websocket.addEventListener("message", this.onMessageProxy.bind(this));
|
|
@@ -6242,15 +6317,15 @@ var RpcProvider = class {
|
|
|
6242
6317
|
} else {
|
|
6243
6318
|
if (optionsOrProvider && optionsOrProvider.specVersion) {
|
|
6244
6319
|
if (isVersion("0.8", optionsOrProvider.specVersion)) {
|
|
6245
|
-
this.channel = new
|
|
6320
|
+
this.channel = new rpc_0_8_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
6246
6321
|
} else if (isVersion("0.7", optionsOrProvider.specVersion)) {
|
|
6247
|
-
this.channel = new
|
|
6322
|
+
this.channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
6248
6323
|
} else
|
|
6249
6324
|
throw new Error(`unsupported channel for spec version: ${optionsOrProvider.specVersion}`);
|
|
6250
6325
|
} else if (isVersion("0.8", config.get("rpcVersion"))) {
|
|
6251
|
-
this.channel = new
|
|
6326
|
+
this.channel = new rpc_0_8_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
6252
6327
|
} else if (isVersion("0.7", config.get("rpcVersion"))) {
|
|
6253
|
-
this.channel = new
|
|
6328
|
+
this.channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider, waitMode: false });
|
|
6254
6329
|
} else throw new Error("unable to define spec version for channel");
|
|
6255
6330
|
this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage);
|
|
6256
6331
|
}
|
|
@@ -6261,15 +6336,26 @@ var RpcProvider = class {
|
|
|
6261
6336
|
*/
|
|
6262
6337
|
// NOTE: the generic T and 'this' reference are used so that the expanded class is generated when a mixin is applied
|
|
6263
6338
|
static async create(optionsOrProvider) {
|
|
6264
|
-
const channel = new
|
|
6339
|
+
const channel = new rpc_0_7_1_exports.RpcChannel({ ...optionsOrProvider });
|
|
6265
6340
|
const spec = await channel.getSpecVersion();
|
|
6341
|
+
if (!isSupportedSpecVersion(spec)) {
|
|
6342
|
+
logger.warn(`Using incompatible node spec version ${spec}`);
|
|
6343
|
+
}
|
|
6266
6344
|
if (isVersion("0.7", spec)) {
|
|
6267
|
-
return new this({
|
|
6345
|
+
return new this({
|
|
6346
|
+
...optionsOrProvider,
|
|
6347
|
+
specVersion: _SupportedRpcVersion.v0_7_1
|
|
6348
|
+
});
|
|
6268
6349
|
}
|
|
6269
6350
|
if (isVersion("0.8", spec)) {
|
|
6270
|
-
return new this({
|
|
6351
|
+
return new this({
|
|
6352
|
+
...optionsOrProvider,
|
|
6353
|
+
specVersion: _SupportedRpcVersion.v0_8_1
|
|
6354
|
+
});
|
|
6271
6355
|
}
|
|
6272
|
-
throw new LibraryError(
|
|
6356
|
+
throw new LibraryError(
|
|
6357
|
+
`Provided RPC node specification version ${spec} is not compatible with the SDK. SDK supported RPC versions ${Object.keys(_SupportedRpcVersion).toString()}`
|
|
6358
|
+
);
|
|
6273
6359
|
}
|
|
6274
6360
|
fetch(method, params, id = 0) {
|
|
6275
6361
|
return this.channel.fetch(method, params, id);
|
|
@@ -6278,16 +6364,22 @@ var RpcProvider = class {
|
|
|
6278
6364
|
return this.channel.getChainId();
|
|
6279
6365
|
}
|
|
6280
6366
|
/**
|
|
6281
|
-
*
|
|
6367
|
+
* read channel spec version
|
|
6282
6368
|
*/
|
|
6283
|
-
|
|
6284
|
-
return this.channel.
|
|
6369
|
+
readSpecVersion() {
|
|
6370
|
+
return this.channel.readSpecVersion();
|
|
6285
6371
|
}
|
|
6286
6372
|
/**
|
|
6287
|
-
*
|
|
6373
|
+
* get channel spec version
|
|
6288
6374
|
*/
|
|
6289
|
-
async
|
|
6290
|
-
return this.channel.
|
|
6375
|
+
async getSpecVersion() {
|
|
6376
|
+
return this.channel.getSpecVersion();
|
|
6377
|
+
}
|
|
6378
|
+
/**
|
|
6379
|
+
* setup channel spec version and return it
|
|
6380
|
+
*/
|
|
6381
|
+
setUpSpecVersion() {
|
|
6382
|
+
return this.channel.setUpSpecVersion();
|
|
6291
6383
|
}
|
|
6292
6384
|
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
6293
6385
|
return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
|
|
@@ -6652,18 +6744,18 @@ var RpcProvider = class {
|
|
|
6652
6744
|
/**
|
|
6653
6745
|
* 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
|
|
6654
6746
|
*/
|
|
6655
|
-
getL1MessagesStatus(transactionHash) {
|
|
6656
|
-
if (this.channel instanceof
|
|
6657
|
-
this.channel.getMessagesStatus(transactionHash);
|
|
6747
|
+
async getL1MessagesStatus(transactionHash) {
|
|
6748
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
6749
|
+
return this.channel.getMessagesStatus(transactionHash);
|
|
6658
6750
|
}
|
|
6659
6751
|
throw new LibraryError("Unsupported method for RPC version");
|
|
6660
6752
|
}
|
|
6661
6753
|
/**
|
|
6662
6754
|
* Get merkle paths in one of the state tries: global state, classes, individual contract
|
|
6663
6755
|
*/
|
|
6664
|
-
getStorageProof(classHashes, contractAddresses, contractsStorageKeys, blockIdentifier) {
|
|
6665
|
-
if (this.channel instanceof
|
|
6666
|
-
this.channel.getStorageProof(
|
|
6756
|
+
async getStorageProof(classHashes, contractAddresses, contractsStorageKeys, blockIdentifier) {
|
|
6757
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
6758
|
+
return this.channel.getStorageProof(
|
|
6667
6759
|
classHashes,
|
|
6668
6760
|
contractAddresses,
|
|
6669
6761
|
contractsStorageKeys,
|
|
@@ -6675,9 +6767,9 @@ var RpcProvider = class {
|
|
|
6675
6767
|
/**
|
|
6676
6768
|
* Get the contract class definition in the given block associated with the given hash
|
|
6677
6769
|
*/
|
|
6678
|
-
getCompiledCasm(classHash) {
|
|
6679
|
-
if (this.channel instanceof
|
|
6680
|
-
this.channel.getCompiledCasm(classHash);
|
|
6770
|
+
async getCompiledCasm(classHash) {
|
|
6771
|
+
if (this.channel instanceof rpc_0_8_1_exports.RpcChannel) {
|
|
6772
|
+
return this.channel.getCompiledCasm(classHash);
|
|
6681
6773
|
}
|
|
6682
6774
|
throw new LibraryError("Unsupported method for RPC version");
|
|
6683
6775
|
}
|
|
@@ -7757,7 +7849,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7757
7849
|
const ledgerResponse = await this.signTxV1(det, transactions);
|
|
7758
7850
|
assert(
|
|
7759
7851
|
toBigInt(msgHash) === ledgerResponse.hash,
|
|
7760
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
7852
|
+
"The V1 transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
7761
7853
|
);
|
|
7762
7854
|
return ledgerResponse.signature;
|
|
7763
7855
|
}
|
|
@@ -7774,7 +7866,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7774
7866
|
const ledgerResponse = await this.signTxV3(det, transactions);
|
|
7775
7867
|
assert(
|
|
7776
7868
|
toBigInt(msgHash) === ledgerResponse.hash,
|
|
7777
|
-
"The transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
7869
|
+
"The V3 transaction hash calculated by Starknet.js is different from the one calculated by the Ledger."
|
|
7778
7870
|
);
|
|
7779
7871
|
return ledgerResponse.signature;
|
|
7780
7872
|
}
|
|
@@ -7855,25 +7947,369 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7855
7947
|
* @param {Call} call A Call to convert.
|
|
7856
7948
|
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
7857
7949
|
*/
|
|
7858
|
-
encodeCall(call) {
|
|
7859
|
-
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
7860
|
-
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
7861
|
-
let calldataBuf = new Uint8Array([]);
|
|
7862
|
-
if (call.calldata) {
|
|
7863
|
-
const compiledCalldata = CallData.compile(call.calldata);
|
|
7864
|
-
calldataBuf = concatenateArrayBuffer(
|
|
7865
|
-
compiledCalldata.map((parameter) => {
|
|
7866
|
-
const a = this.convertBnToLedger(parameter);
|
|
7867
|
-
return a;
|
|
7868
|
-
})
|
|
7869
|
-
);
|
|
7870
|
-
}
|
|
7871
|
-
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
7872
|
-
const calldatas = [];
|
|
7873
|
-
const chunkSize = 7 * 32;
|
|
7874
|
-
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
7875
|
-
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
7876
|
-
return calldatas;
|
|
7950
|
+
encodeCall(call) {
|
|
7951
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
7952
|
+
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
7953
|
+
let calldataBuf = new Uint8Array([]);
|
|
7954
|
+
if (call.calldata) {
|
|
7955
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
7956
|
+
calldataBuf = concatenateArrayBuffer(
|
|
7957
|
+
compiledCalldata.map((parameter) => {
|
|
7958
|
+
const a = this.convertBnToLedger(parameter);
|
|
7959
|
+
return a;
|
|
7960
|
+
})
|
|
7961
|
+
);
|
|
7962
|
+
}
|
|
7963
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
7964
|
+
const calldatas = [];
|
|
7965
|
+
const chunkSize = 7 * 32;
|
|
7966
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
7967
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
7968
|
+
return calldatas;
|
|
7969
|
+
}
|
|
7970
|
+
/**
|
|
7971
|
+
* Ask the Ledger Nano to display and sign a Starknet V1 transaction.
|
|
7972
|
+
* @param {V2InvocationsSignerDetails} txDetails All the details needed for a txV1.
|
|
7973
|
+
* @param {Call[]} calls array of Starknet invocations
|
|
7974
|
+
* @returns an object including the transaction Hash and the signature
|
|
7975
|
+
* @example
|
|
7976
|
+
* ```typescript
|
|
7977
|
+
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
7978
|
+
* entrypoint: "transfer",
|
|
7979
|
+
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
7980
|
+
* "0x9184e72a000", "0x0"]}];
|
|
7981
|
+
* const txDet: V2InvocationsSignerDetails = {
|
|
7982
|
+
* walletAddress: txDetails.accountAddress,
|
|
7983
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
7984
|
+
* cairoVersion: "1", maxFee: txDetails.max_fee,
|
|
7985
|
+
* nonce: txDetails.nonce, version: "0x1"
|
|
7986
|
+
* };
|
|
7987
|
+
* const res = await myLedgerSigner.signTxV1(txDet, calls);
|
|
7988
|
+
* // res = {hash:
|
|
7989
|
+
* // signature:
|
|
7990
|
+
* // }
|
|
7991
|
+
* ```
|
|
7992
|
+
*/
|
|
7993
|
+
async signTxV1(txDetails, calls) {
|
|
7994
|
+
await this._transporter.send(Number("0x5a"), 4, 0, 0, Buffer.from(this.pathBuffer));
|
|
7995
|
+
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
7996
|
+
const maxFeeBuf = this.convertBnToLedger(txDetails.maxFee);
|
|
7997
|
+
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
7998
|
+
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
7999
|
+
const dataBuf = concatenateArrayBuffer([
|
|
8000
|
+
accountAddressBuf,
|
|
8001
|
+
maxFeeBuf,
|
|
8002
|
+
chainIdBuf,
|
|
8003
|
+
nonceBuf
|
|
8004
|
+
]);
|
|
8005
|
+
await this._transporter.send(Number("0x5a"), 4, 1, 0, Buffer.from(dataBuf));
|
|
8006
|
+
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8007
|
+
await this._transporter.send(Number("0x5a"), 4, 2, 0, Buffer.from(nbCallsBuf));
|
|
8008
|
+
let respSign = new Uint8Array(0);
|
|
8009
|
+
for (const call of calls) {
|
|
8010
|
+
const calldatas = this.encodeCall(call);
|
|
8011
|
+
await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
8012
|
+
if (calldatas.length > 1) {
|
|
8013
|
+
calldatas.slice(1).forEach(async (part) => {
|
|
8014
|
+
await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
8015
|
+
});
|
|
8016
|
+
}
|
|
8017
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 2);
|
|
8018
|
+
}
|
|
8019
|
+
return this.decodeSignatureLedger(respSign);
|
|
8020
|
+
}
|
|
8021
|
+
/**
|
|
8022
|
+
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
8023
|
+
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
8024
|
+
* @param {Call[]} calls array of Starknet invocations
|
|
8025
|
+
* @returns an object including the transaction Hash and the signature
|
|
8026
|
+
* @example
|
|
8027
|
+
* ```typescript
|
|
8028
|
+
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
8029
|
+
* entrypoint: "transfer",
|
|
8030
|
+
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
8031
|
+
* "0x9184e72a000", "0x0"]}];
|
|
8032
|
+
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
8033
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
8034
|
+
* nonce: "28", accountDeploymentData: [],
|
|
8035
|
+
* paymasterData: [], cairoVersion: "1",
|
|
8036
|
+
* feeDataAvailabilityMode: "L1", nonceDataAvailabilityMode: "L1",
|
|
8037
|
+
* resourceBounds: {
|
|
8038
|
+
* l1_gas: { max_amount: "0x2a00", max_price_per_unit: "0x5c00000"
|
|
8039
|
+
* },
|
|
8040
|
+
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
8041
|
+
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
8042
|
+
* };
|
|
8043
|
+
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
8044
|
+
* // res = {hash:
|
|
8045
|
+
* // signature:
|
|
8046
|
+
* // }
|
|
8047
|
+
* ```
|
|
8048
|
+
*/
|
|
8049
|
+
async signTxV3(txDetails, calls) {
|
|
8050
|
+
assert(txDetails.paymasterData.length <= 7, "Paymaster data includes more than 7 items.");
|
|
8051
|
+
assert(
|
|
8052
|
+
txDetails.accountDeploymentData.length <= 7,
|
|
8053
|
+
"accountDeploymentData includes more than 7 items"
|
|
8054
|
+
);
|
|
8055
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
|
|
8056
|
+
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
8057
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8058
|
+
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
8059
|
+
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
8060
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
8061
|
+
hashDAMode(
|
|
8062
|
+
txDetails.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
8063
|
+
txDetails.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
8064
|
+
)
|
|
8065
|
+
);
|
|
8066
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
8067
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
8068
|
+
const dataBuf = concatenateArrayBuffer([
|
|
8069
|
+
accountAddressBuf,
|
|
8070
|
+
tipBuf,
|
|
8071
|
+
l1_gasBuf,
|
|
8072
|
+
l2_gasBuf,
|
|
8073
|
+
chainIdBuf,
|
|
8074
|
+
nonceBuf,
|
|
8075
|
+
dAModeHashBuf
|
|
8076
|
+
]);
|
|
8077
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
|
|
8078
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
8079
|
+
txDetails.paymasterData.map((value) => {
|
|
8080
|
+
const a = this.convertBnToLedger(value);
|
|
8081
|
+
return a;
|
|
8082
|
+
})
|
|
8083
|
+
);
|
|
8084
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(paymasterBuf));
|
|
8085
|
+
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
8086
|
+
txDetails.paymasterData.map((value) => {
|
|
8087
|
+
const a = this.convertBnToLedger(value);
|
|
8088
|
+
return a;
|
|
8089
|
+
})
|
|
8090
|
+
);
|
|
8091
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(accountDeployDataBuf));
|
|
8092
|
+
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8093
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(nbCallsBuf));
|
|
8094
|
+
let respSign = new Uint8Array(0);
|
|
8095
|
+
for (const call of calls) {
|
|
8096
|
+
const calldatas = this.encodeCall(call);
|
|
8097
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(calldatas[0]));
|
|
8098
|
+
if (calldatas.length > 1) {
|
|
8099
|
+
calldatas.slice(1).forEach(async (part) => {
|
|
8100
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, Buffer.from(part));
|
|
8101
|
+
});
|
|
8102
|
+
}
|
|
8103
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
8104
|
+
}
|
|
8105
|
+
return this.decodeSignatureLedger(respSign);
|
|
8106
|
+
}
|
|
8107
|
+
/**
|
|
8108
|
+
* Ask the Ledger Nano to display and sign a Starknet V1 account deployment.
|
|
8109
|
+
* @param {V2DeployAccountSignerDetails} deployAccountDetail All the details needed for a V1 deploy account.
|
|
8110
|
+
* @returns an object including the transaction Hash and the signature
|
|
8111
|
+
* @example
|
|
8112
|
+
* ```typescript
|
|
8113
|
+
* const deployData: V2DeployAccountSignerDetails =
|
|
8114
|
+
* {
|
|
8115
|
+
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
8116
|
+
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
8117
|
+
* resourceBounds: {
|
|
8118
|
+
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
8119
|
+
* l1_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }
|
|
8120
|
+
* },
|
|
8121
|
+
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
8122
|
+
* constructorCalldata: [
|
|
8123
|
+
* '89832696000889662999767022750851886674077821293893187900664573372145410755'
|
|
8124
|
+
* ],
|
|
8125
|
+
* contractAddress: '0x32c60fba64eb96831d064bbb2319375b7b7381543abe66da872e4344bcd72a0',
|
|
8126
|
+
* addressSalt: '0x0032d7efe2a9232f9b463e7206c68fdea4aeb13fec0cb308c6ba1d197d5922c3',
|
|
8127
|
+
* chainId: '0x534e5f5345504f4c4941', maxFee: 55050000000000n,
|
|
8128
|
+
* version: '0x1', nonce: 0n
|
|
8129
|
+
*}
|
|
8130
|
+
* const res = await myLedgerSigner.signDeployAccountV1(deployData);
|
|
8131
|
+
* // res = {hash:
|
|
8132
|
+
* // signature:
|
|
8133
|
+
* // }
|
|
8134
|
+
* ```
|
|
8135
|
+
*/
|
|
8136
|
+
async signDeployAccountV1(deployAccountDetail) {
|
|
8137
|
+
await this._transporter.send(Number("0x5a"), 6, 0, 0, Buffer.from(this.pathBuffer));
|
|
8138
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
8139
|
+
deployAccountDetail.contractAddress
|
|
8140
|
+
);
|
|
8141
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
8142
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
8143
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
8144
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
8145
|
+
const dataBuf = concatenateArrayBuffer([
|
|
8146
|
+
accountAddressBuf,
|
|
8147
|
+
classHashBuf,
|
|
8148
|
+
saltBuf,
|
|
8149
|
+
chainIdBuf,
|
|
8150
|
+
nonceBuf
|
|
8151
|
+
]);
|
|
8152
|
+
await this._transporter.send(Number("0x5a"), 6, 1, 0, Buffer.from(dataBuf));
|
|
8153
|
+
const maxFreeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
8154
|
+
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(maxFreeBuf));
|
|
8155
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8156
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8157
|
+
await this._transporter.send(Number("0x5a"), 6, 3, 0, Buffer.from(constructorLengthBuf));
|
|
8158
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
8159
|
+
compiledConstructor.map((parameter) => {
|
|
8160
|
+
const a = this.convertBnToLedger(parameter);
|
|
8161
|
+
return a;
|
|
8162
|
+
})
|
|
8163
|
+
);
|
|
8164
|
+
const constructorChunks = [];
|
|
8165
|
+
const chunkSize = 7 * 32;
|
|
8166
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
8167
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8168
|
+
let respSign = new Uint8Array(0);
|
|
8169
|
+
for (const chunk of constructorChunks) {
|
|
8170
|
+
respSign = await this._transporter.send(Number("0x5a"), 6, 4, 0, Buffer.from(chunk));
|
|
8171
|
+
}
|
|
8172
|
+
return this.decodeSignatureLedger(respSign);
|
|
8173
|
+
}
|
|
8174
|
+
/**
|
|
8175
|
+
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
8176
|
+
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
8177
|
+
* @returns an object including the transaction Hash and the signature
|
|
8178
|
+
* @example
|
|
8179
|
+
* ```typescript
|
|
8180
|
+
* const deployData: V3DeployAccountSignerDetails =
|
|
8181
|
+
* {
|
|
8182
|
+
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
8183
|
+
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
8184
|
+
* resourceBounds: {
|
|
8185
|
+
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
8186
|
+
* l1_gas: { max_amount: '0x226', max_price_per_unit: '0x22ecb25c00' }
|
|
8187
|
+
* },
|
|
8188
|
+
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
8189
|
+
* constructorCalldata: [
|
|
8190
|
+
* '3571125127744830445572285574469842579401255431821644822726857471463672199621'
|
|
8191
|
+
* ],
|
|
8192
|
+
* contractAddress: '0x4ca062add1cf12a107be1107af17981cf6e544a24d987693230ea481d3d5e34',
|
|
8193
|
+
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
8194
|
+
* chainId: '0x534e5f5345504f4c4941', maxFee: 0,
|
|
8195
|
+
* version: '0x3', nonce: 0n
|
|
8196
|
+
*}
|
|
8197
|
+
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
8198
|
+
* // res = {hash:
|
|
8199
|
+
* // signature:
|
|
8200
|
+
* // }
|
|
8201
|
+
* ```
|
|
8202
|
+
*/
|
|
8203
|
+
async signDeployAccountV3(deployAccountDetail) {
|
|
8204
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, Buffer.from(this.pathBuffer));
|
|
8205
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
8206
|
+
deployAccountDetail.contractAddress
|
|
8207
|
+
);
|
|
8208
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
8209
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
8210
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
8211
|
+
hashDAMode(
|
|
8212
|
+
deployAccountDetail.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
8213
|
+
deployAccountDetail.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
8214
|
+
)
|
|
8215
|
+
);
|
|
8216
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
8217
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
8218
|
+
const dataBuf = concatenateArrayBuffer([
|
|
8219
|
+
accountAddressBuf,
|
|
8220
|
+
chainIdBuf,
|
|
8221
|
+
nonceBuf,
|
|
8222
|
+
dAModeHashBuf,
|
|
8223
|
+
classHashBuf,
|
|
8224
|
+
saltBuf
|
|
8225
|
+
]);
|
|
8226
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
|
|
8227
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8228
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
8229
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
8230
|
+
);
|
|
8231
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
8232
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
8233
|
+
);
|
|
8234
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
8235
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
8236
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
8237
|
+
deployAccountDetail.paymasterData.map((value) => {
|
|
8238
|
+
const a = this.convertBnToLedger(value);
|
|
8239
|
+
return a;
|
|
8240
|
+
})
|
|
8241
|
+
);
|
|
8242
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, Buffer.from(paymasterBuf));
|
|
8243
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8244
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8245
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, Buffer.from(constructorLengthBuf));
|
|
8246
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
8247
|
+
compiledConstructor.map((parameter) => {
|
|
8248
|
+
const a = this.convertBnToLedger(parameter);
|
|
8249
|
+
return a;
|
|
8250
|
+
})
|
|
8251
|
+
);
|
|
8252
|
+
const constructorChunks = [];
|
|
8253
|
+
const chunkSize = 7 * 32;
|
|
8254
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
8255
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8256
|
+
let respSign = new Uint8Array(0);
|
|
8257
|
+
for (const chunk of constructorChunks) {
|
|
8258
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, Buffer.from(chunk));
|
|
8259
|
+
}
|
|
8260
|
+
return this.decodeSignatureLedger(respSign);
|
|
8261
|
+
}
|
|
8262
|
+
};
|
|
8263
|
+
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
8264
|
+
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
8265
|
+
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
8266
|
+
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
8267
|
+
const path2buff = concatenateArrayBuffer([
|
|
8268
|
+
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
8269
|
+
path2Base.subarray(1)
|
|
8270
|
+
]);
|
|
8271
|
+
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
8272
|
+
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
8273
|
+
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
8274
|
+
const path4buff = hexToBytes(padded);
|
|
8275
|
+
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
8276
|
+
const pathBuff = concatenateArrayBuffer([
|
|
8277
|
+
path0buff,
|
|
8278
|
+
path1buff,
|
|
8279
|
+
path2buff,
|
|
8280
|
+
path3buff,
|
|
8281
|
+
path4buff,
|
|
8282
|
+
path5buff
|
|
8283
|
+
]);
|
|
8284
|
+
return pathBuff;
|
|
8285
|
+
}
|
|
8286
|
+
|
|
8287
|
+
// src/signer/ledgerSigner231.ts
|
|
8288
|
+
var LedgerSigner231 = class extends LedgerSigner221 {
|
|
8289
|
+
/**
|
|
8290
|
+
* constructor of the LedgerSigner class.
|
|
8291
|
+
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
8292
|
+
* See Guides for more details.
|
|
8293
|
+
* @param {number} accountID ID of Ledger Nano account (can handle 2**31 accounts).
|
|
8294
|
+
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
8295
|
+
* One item is called `application` and can be customized.
|
|
8296
|
+
* Default value is `LedgerW`.
|
|
8297
|
+
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
8298
|
+
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
8299
|
+
*
|
|
8300
|
+
* If you are using APP v2.3.1 with an account created with the v1.1.1, you need to use :
|
|
8301
|
+
* ```typescript
|
|
8302
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
8303
|
+
* ```
|
|
8304
|
+
* @example
|
|
8305
|
+
* ```typescript
|
|
8306
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
8307
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
8308
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0);
|
|
8309
|
+
* ```
|
|
8310
|
+
*/
|
|
8311
|
+
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
8312
|
+
super(transport, accountID, eip2645application, pathFunction);
|
|
7877
8313
|
}
|
|
7878
8314
|
/**
|
|
7879
8315
|
* Ask the Ledger Nano to display and sign a Starknet V1 transaction.
|
|
@@ -7916,18 +8352,17 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7916
8352
|
let respSign = new Uint8Array(0);
|
|
7917
8353
|
for (const call of calls) {
|
|
7918
8354
|
const calldatas = this.encodeCall(call);
|
|
7919
|
-
await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
8355
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 0, Buffer.from(calldatas[0]));
|
|
7920
8356
|
if (calldatas.length > 1) {
|
|
7921
8357
|
calldatas.slice(1).forEach(async (part) => {
|
|
7922
|
-
await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
8358
|
+
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 1, Buffer.from(part));
|
|
7923
8359
|
});
|
|
7924
8360
|
}
|
|
7925
|
-
respSign = await this._transporter.send(Number("0x5a"), 4, 3, 2);
|
|
7926
8361
|
}
|
|
7927
8362
|
return this.decodeSignatureLedger(respSign);
|
|
7928
8363
|
}
|
|
7929
8364
|
/**
|
|
7930
|
-
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
8365
|
+
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction (Rpc 0.7 & Rpc 0.8).
|
|
7931
8366
|
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
7932
8367
|
* @param {Call[]} calls array of Starknet invocations
|
|
7933
8368
|
* @returns an object including the transaction Hash and the signature
|
|
@@ -7947,7 +8382,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7947
8382
|
* },
|
|
7948
8383
|
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
7949
8384
|
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
7950
|
-
* };
|
|
8385
|
+
* }; // Rpc 0.7 transaction.
|
|
7951
8386
|
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
7952
8387
|
* // res = {hash:
|
|
7953
8388
|
* // signature:
|
|
@@ -7962,53 +8397,67 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
7962
8397
|
);
|
|
7963
8398
|
await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
|
|
7964
8399
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
7965
|
-
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
7966
8400
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
7967
8401
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
7968
8402
|
const dAModeHashBuf = this.convertBnToLedger(
|
|
7969
8403
|
hashDAMode(
|
|
7970
|
-
txDetails.nonceDataAvailabilityMode
|
|
7971
|
-
txDetails.feeDataAvailabilityMode
|
|
8404
|
+
intDAM(txDetails.nonceDataAvailabilityMode),
|
|
8405
|
+
intDAM(txDetails.feeDataAvailabilityMode)
|
|
7972
8406
|
)
|
|
7973
8407
|
);
|
|
7974
|
-
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
7975
|
-
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
7976
8408
|
const dataBuf = concatenateArrayBuffer([
|
|
7977
8409
|
accountAddressBuf,
|
|
7978
|
-
tipBuf,
|
|
7979
|
-
l1_gasBuf,
|
|
7980
|
-
l2_gasBuf,
|
|
7981
8410
|
chainIdBuf,
|
|
7982
8411
|
nonceBuf,
|
|
7983
8412
|
dAModeHashBuf
|
|
7984
8413
|
]);
|
|
7985
8414
|
await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
|
|
8415
|
+
if (isRPC08_ResourceBounds(txDetails.resourceBounds)) {
|
|
8416
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8417
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
8418
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
8419
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
8420
|
+
encodeDataResourceBoundsL1(txDetails.resourceBounds)
|
|
8421
|
+
);
|
|
8422
|
+
const feeBuf = concatenateArrayBuffer([
|
|
8423
|
+
tipBuf,
|
|
8424
|
+
l1_gasBuf,
|
|
8425
|
+
l2_gasBuf,
|
|
8426
|
+
l1_data_gasBuf
|
|
8427
|
+
]);
|
|
8428
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(feeBuf));
|
|
8429
|
+
} else {
|
|
8430
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8431
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
8432
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
8433
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
8434
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(feeBuf));
|
|
8435
|
+
}
|
|
7986
8436
|
const paymasterBuf = concatenateArrayBuffer(
|
|
7987
8437
|
txDetails.paymasterData.map((value) => {
|
|
7988
8438
|
const a = this.convertBnToLedger(value);
|
|
7989
8439
|
return a;
|
|
7990
8440
|
})
|
|
7991
8441
|
);
|
|
7992
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
8442
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(paymasterBuf));
|
|
7993
8443
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
7994
8444
|
txDetails.paymasterData.map((value) => {
|
|
7995
8445
|
const a = this.convertBnToLedger(value);
|
|
7996
8446
|
return a;
|
|
7997
8447
|
})
|
|
7998
8448
|
);
|
|
7999
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
8449
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(accountDeployDataBuf));
|
|
8000
8450
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8001
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
8451
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(nbCallsBuf));
|
|
8002
8452
|
let respSign = new Uint8Array(0);
|
|
8003
8453
|
for (const call of calls) {
|
|
8004
8454
|
const calldatas = this.encodeCall(call);
|
|
8005
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
8455
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, Buffer.from(calldatas[0]));
|
|
8006
8456
|
if (calldatas.length > 1) {
|
|
8007
8457
|
calldatas.slice(1).forEach(async (part) => {
|
|
8008
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
8458
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, Buffer.from(part));
|
|
8009
8459
|
});
|
|
8010
8460
|
}
|
|
8011
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
8012
8461
|
}
|
|
8013
8462
|
return this.decodeSignatureLedger(respSign);
|
|
8014
8463
|
}
|
|
@@ -8048,21 +8497,21 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8048
8497
|
);
|
|
8049
8498
|
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
8050
8499
|
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
8500
|
+
const maxFeeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
8051
8501
|
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
8052
8502
|
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
8053
8503
|
const dataBuf = concatenateArrayBuffer([
|
|
8054
8504
|
accountAddressBuf,
|
|
8055
8505
|
classHashBuf,
|
|
8056
8506
|
saltBuf,
|
|
8507
|
+
maxFeeBuf,
|
|
8057
8508
|
chainIdBuf,
|
|
8058
8509
|
nonceBuf
|
|
8059
8510
|
]);
|
|
8060
8511
|
await this._transporter.send(Number("0x5a"), 6, 1, 0, Buffer.from(dataBuf));
|
|
8061
|
-
const maxFreeBuf = this.convertBnToLedger(deployAccountDetail.maxFee);
|
|
8062
|
-
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(maxFreeBuf));
|
|
8063
8512
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8064
8513
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8065
|
-
await this._transporter.send(Number("0x5a"), 6,
|
|
8514
|
+
await this._transporter.send(Number("0x5a"), 6, 2, 0, Buffer.from(constructorLengthBuf));
|
|
8066
8515
|
const constructorBuf = concatenateArrayBuffer(
|
|
8067
8516
|
compiledConstructor.map((parameter) => {
|
|
8068
8517
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -8075,12 +8524,12 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8075
8524
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8076
8525
|
let respSign = new Uint8Array(0);
|
|
8077
8526
|
for (const chunk of constructorChunks) {
|
|
8078
|
-
respSign = await this._transporter.send(Number("0x5a"), 6,
|
|
8527
|
+
respSign = await this._transporter.send(Number("0x5a"), 6, 3, 0, Buffer.from(chunk));
|
|
8079
8528
|
}
|
|
8080
8529
|
return this.decodeSignatureLedger(respSign);
|
|
8081
8530
|
}
|
|
8082
8531
|
/**
|
|
8083
|
-
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
8532
|
+
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment (Rpc 0.7 & Rpc 0.8).
|
|
8084
8533
|
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
8085
8534
|
* @returns an object including the transaction Hash and the signature
|
|
8086
8535
|
* @example
|
|
@@ -8101,7 +8550,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8101
8550
|
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
8102
8551
|
* chainId: '0x534e5f5345504f4c4941', maxFee: 0,
|
|
8103
8552
|
* version: '0x3', nonce: 0n
|
|
8104
|
-
*}
|
|
8553
|
+
*} // Rpc 0.7 transaction.
|
|
8105
8554
|
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
8106
8555
|
* // res = {hash:
|
|
8107
8556
|
* // signature:
|
|
@@ -8117,8 +8566,8 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8117
8566
|
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
8118
8567
|
const dAModeHashBuf = this.convertBnToLedger(
|
|
8119
8568
|
hashDAMode(
|
|
8120
|
-
deployAccountDetail.nonceDataAvailabilityMode
|
|
8121
|
-
deployAccountDetail.feeDataAvailabilityMode
|
|
8569
|
+
intDAM(deployAccountDetail.nonceDataAvailabilityMode),
|
|
8570
|
+
intDAM(deployAccountDetail.feeDataAvailabilityMode)
|
|
8122
8571
|
)
|
|
8123
8572
|
);
|
|
8124
8573
|
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
@@ -8132,15 +8581,35 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8132
8581
|
saltBuf
|
|
8133
8582
|
]);
|
|
8134
8583
|
await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8584
|
+
if (isRPC08_ResourceBounds(deployAccountDetail.resourceBounds)) {
|
|
8585
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8586
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
8587
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
8588
|
+
);
|
|
8589
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
8590
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
8591
|
+
);
|
|
8592
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
8593
|
+
encodeDataResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
8594
|
+
);
|
|
8595
|
+
const feeBuf = concatenateArrayBuffer([
|
|
8596
|
+
tipBuf,
|
|
8597
|
+
l1_gasBuf,
|
|
8598
|
+
l2_gasBuf,
|
|
8599
|
+
l1_data_gasBuf
|
|
8600
|
+
]);
|
|
8601
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
8602
|
+
} else {
|
|
8603
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8604
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
8605
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
8606
|
+
);
|
|
8607
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
8608
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
8609
|
+
);
|
|
8610
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
8611
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
|
|
8612
|
+
}
|
|
8144
8613
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8145
8614
|
deployAccountDetail.paymasterData.map((value) => {
|
|
8146
8615
|
const a = this.convertBnToLedger(value);
|
|
@@ -8167,30 +8636,35 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8167
8636
|
}
|
|
8168
8637
|
return this.decodeSignatureLedger(respSign);
|
|
8169
8638
|
}
|
|
8639
|
+
/** Internal function to convert a Call to an array of Uint8Array.
|
|
8640
|
+
* @param {Call} call A Call to convert.
|
|
8641
|
+
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
8642
|
+
*/
|
|
8643
|
+
encodeCall(call) {
|
|
8644
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
8645
|
+
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
8646
|
+
let calldataBuf = new Uint8Array([]);
|
|
8647
|
+
if (call.calldata) {
|
|
8648
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
8649
|
+
const calldataSizeBuf = this.convertBnToLedger(compiledCalldata.length);
|
|
8650
|
+
calldataBuf = concatenateArrayBuffer([
|
|
8651
|
+
calldataSizeBuf,
|
|
8652
|
+
...compiledCalldata.map((parameter) => {
|
|
8653
|
+
const a = this.convertBnToLedger(parameter);
|
|
8654
|
+
return a;
|
|
8655
|
+
})
|
|
8656
|
+
]);
|
|
8657
|
+
} else {
|
|
8658
|
+
calldataBuf = this.convertBnToLedger("0x00");
|
|
8659
|
+
}
|
|
8660
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
8661
|
+
const calldatas = [];
|
|
8662
|
+
const chunkSize = 7 * 32;
|
|
8663
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
8664
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
8665
|
+
return calldatas;
|
|
8666
|
+
}
|
|
8170
8667
|
};
|
|
8171
|
-
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
8172
|
-
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
8173
|
-
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
8174
|
-
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
8175
|
-
const path2buff = concatenateArrayBuffer([
|
|
8176
|
-
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
8177
|
-
path2Base.subarray(1)
|
|
8178
|
-
]);
|
|
8179
|
-
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
8180
|
-
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
8181
|
-
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
8182
|
-
const path4buff = hexToBytes(padded);
|
|
8183
|
-
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
8184
|
-
const pathBuff = concatenateArrayBuffer([
|
|
8185
|
-
path0buff,
|
|
8186
|
-
path1buff,
|
|
8187
|
-
path2buff,
|
|
8188
|
-
path3buff,
|
|
8189
|
-
path4buff,
|
|
8190
|
-
path5buff
|
|
8191
|
-
]);
|
|
8192
|
-
return pathBuff;
|
|
8193
|
-
}
|
|
8194
8668
|
|
|
8195
8669
|
// src/utils/events/index.ts
|
|
8196
8670
|
var events_exports = {};
|
|
@@ -8444,13 +8918,257 @@ async function supportsInterface(provider, contractAddress, interfaceId) {
|
|
|
8444
8918
|
}
|
|
8445
8919
|
}
|
|
8446
8920
|
|
|
8921
|
+
// src/utils/paymaster.ts
|
|
8922
|
+
var paymaster_exports = {};
|
|
8923
|
+
__export(paymaster_exports, {
|
|
8924
|
+
getDefaultPaymasterNodeUrl: () => getDefaultPaymasterNodeUrl
|
|
8925
|
+
});
|
|
8926
|
+
var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
|
|
8927
|
+
if (!mute) {
|
|
8928
|
+
logger.info("Using default public node url, please provide nodeUrl in provider options!");
|
|
8929
|
+
}
|
|
8930
|
+
const nodes = PAYMASTER_RPC_NODES[networkName ?? _NetworkName.SN_SEPOLIA];
|
|
8931
|
+
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
8932
|
+
return nodes[randIdx];
|
|
8933
|
+
};
|
|
8934
|
+
|
|
8935
|
+
// src/paymaster/rpc.ts
|
|
8936
|
+
var convertCalls = (calls) => calls.map((call) => ({
|
|
8937
|
+
to: call.contractAddress,
|
|
8938
|
+
selector: getSelectorFromName(call.entrypoint),
|
|
8939
|
+
calldata: CallData.toHex(call.calldata)
|
|
8940
|
+
}));
|
|
8941
|
+
var convertFeeMode = (feeMode) => {
|
|
8942
|
+
if (feeMode.mode === "sponsored") {
|
|
8943
|
+
return { mode: "sponsored" };
|
|
8944
|
+
}
|
|
8945
|
+
return { mode: "default", gas_token: feeMode.gasToken };
|
|
8946
|
+
};
|
|
8947
|
+
var convertFEE_MODE = (feeMode) => {
|
|
8948
|
+
if (feeMode.mode === "sponsored") {
|
|
8949
|
+
return { mode: "sponsored" };
|
|
8950
|
+
}
|
|
8951
|
+
return { mode: "default", gasToken: feeMode.gas_token };
|
|
8952
|
+
};
|
|
8953
|
+
var convertTimeBounds = (timeBounds) => timeBounds && timeBounds.executeAfter && timeBounds.executeBefore ? {
|
|
8954
|
+
execute_after: timeBounds.executeAfter.getTime().toString(),
|
|
8955
|
+
execute_before: timeBounds.executeBefore.getTime().toString()
|
|
8956
|
+
} : void 0;
|
|
8957
|
+
var convertTIME_BOUNDS = (timeBounds) => timeBounds && timeBounds.execute_after && timeBounds.execute_before ? {
|
|
8958
|
+
executeAfter: new Date(timeBounds.execute_after),
|
|
8959
|
+
executeBefore: new Date(timeBounds.execute_before)
|
|
8960
|
+
} : void 0;
|
|
8961
|
+
var convertEXECUTION_PARAMETERS = (parameters) => ({
|
|
8962
|
+
version: parameters.version,
|
|
8963
|
+
feeMode: convertFEE_MODE(parameters.fee_mode),
|
|
8964
|
+
timeBounds: convertTIME_BOUNDS(parameters.time_bounds)
|
|
8965
|
+
});
|
|
8966
|
+
var defaultOptions3 = {
|
|
8967
|
+
headers: { "Content-Type": "application/json" }
|
|
8968
|
+
};
|
|
8969
|
+
var PaymasterRpc = class _PaymasterRpc {
|
|
8970
|
+
nodeUrl;
|
|
8971
|
+
headers;
|
|
8972
|
+
baseFetch;
|
|
8973
|
+
requestId;
|
|
8974
|
+
constructor(options) {
|
|
8975
|
+
if (options instanceof _PaymasterRpc) {
|
|
8976
|
+
this.nodeUrl = options.nodeUrl;
|
|
8977
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
8978
|
+
this.baseFetch = options.baseFetch;
|
|
8979
|
+
this.requestId = options.requestId;
|
|
8980
|
+
return;
|
|
8981
|
+
}
|
|
8982
|
+
if (options && "nodeUrl" in options && "headers" in options && "baseFetch" in options) {
|
|
8983
|
+
this.nodeUrl = options.nodeUrl ?? getDefaultPaymasterNodeUrl(void 0);
|
|
8984
|
+
this.headers = { ...defaultOptions3.headers, ...options.headers };
|
|
8985
|
+
this.baseFetch = options.baseFetch ?? fetch_default;
|
|
8986
|
+
this.requestId = 0;
|
|
8987
|
+
return;
|
|
8988
|
+
}
|
|
8989
|
+
const { nodeUrl, headers, baseFetch } = options || {};
|
|
8990
|
+
if (nodeUrl && Object.values(_NetworkName).includes(nodeUrl)) {
|
|
8991
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(nodeUrl, options?.default);
|
|
8992
|
+
} else if (nodeUrl) {
|
|
8993
|
+
this.nodeUrl = nodeUrl;
|
|
8994
|
+
} else {
|
|
8995
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(void 0, options?.default);
|
|
8996
|
+
}
|
|
8997
|
+
this.baseFetch = baseFetch ?? fetch_default;
|
|
8998
|
+
this.headers = { ...defaultOptions3.headers, ...headers };
|
|
8999
|
+
this.requestId = 0;
|
|
9000
|
+
}
|
|
9001
|
+
fetch(method, params, id = 0) {
|
|
9002
|
+
const rpcRequestBody = {
|
|
9003
|
+
id,
|
|
9004
|
+
jsonrpc: "2.0",
|
|
9005
|
+
method,
|
|
9006
|
+
...params && { params }
|
|
9007
|
+
};
|
|
9008
|
+
return this.baseFetch(this.nodeUrl, {
|
|
9009
|
+
method: "POST",
|
|
9010
|
+
body: stringify2(rpcRequestBody),
|
|
9011
|
+
headers: this.headers
|
|
9012
|
+
});
|
|
9013
|
+
}
|
|
9014
|
+
errorHandler(method, params, rpcError, otherError) {
|
|
9015
|
+
if (rpcError) {
|
|
9016
|
+
throw new RpcError(rpcError, method, params);
|
|
9017
|
+
}
|
|
9018
|
+
if (otherError instanceof LibraryError) {
|
|
9019
|
+
throw otherError;
|
|
9020
|
+
}
|
|
9021
|
+
if (otherError) {
|
|
9022
|
+
throw Error(otherError.message);
|
|
9023
|
+
}
|
|
9024
|
+
}
|
|
9025
|
+
async fetchEndpoint(method, params) {
|
|
9026
|
+
try {
|
|
9027
|
+
this.requestId += 1;
|
|
9028
|
+
const rawResult = await this.fetch(method, params, this.requestId);
|
|
9029
|
+
const { error, result } = await rawResult.json();
|
|
9030
|
+
this.errorHandler(method, params, error);
|
|
9031
|
+
return result;
|
|
9032
|
+
} catch (error) {
|
|
9033
|
+
this.errorHandler(method, params, error?.response?.data, error);
|
|
9034
|
+
throw error;
|
|
9035
|
+
}
|
|
9036
|
+
}
|
|
9037
|
+
async isAvailable() {
|
|
9038
|
+
return this.fetchEndpoint("paymaster_isAvailable");
|
|
9039
|
+
}
|
|
9040
|
+
async buildTransaction(transaction, parameters) {
|
|
9041
|
+
let userTransaction;
|
|
9042
|
+
switch (transaction.type) {
|
|
9043
|
+
case "invoke":
|
|
9044
|
+
userTransaction = {
|
|
9045
|
+
...transaction,
|
|
9046
|
+
invoke: {
|
|
9047
|
+
user_address: transaction.invoke.userAddress,
|
|
9048
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
9049
|
+
}
|
|
9050
|
+
};
|
|
9051
|
+
break;
|
|
9052
|
+
case "deploy_and_invoke":
|
|
9053
|
+
userTransaction = {
|
|
9054
|
+
...transaction,
|
|
9055
|
+
invoke: {
|
|
9056
|
+
user_address: transaction.invoke.userAddress,
|
|
9057
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
9058
|
+
}
|
|
9059
|
+
};
|
|
9060
|
+
break;
|
|
9061
|
+
case "deploy":
|
|
9062
|
+
default:
|
|
9063
|
+
userTransaction = transaction;
|
|
9064
|
+
break;
|
|
9065
|
+
}
|
|
9066
|
+
const executionParameters = {
|
|
9067
|
+
version: parameters.version,
|
|
9068
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
9069
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
9070
|
+
};
|
|
9071
|
+
const response = await this.fetchEndpoint("paymaster_buildTransaction", {
|
|
9072
|
+
transaction: userTransaction,
|
|
9073
|
+
parameters: executionParameters
|
|
9074
|
+
});
|
|
9075
|
+
const fee = {
|
|
9076
|
+
gas_token_price_in_strk: BigInt(response.fee.gas_token_price_in_strk),
|
|
9077
|
+
estimated_fee_in_strk: BigInt(response.fee.estimated_fee_in_strk),
|
|
9078
|
+
estimated_fee_in_gas_token: BigInt(response.fee.estimated_fee_in_gas_token),
|
|
9079
|
+
suggested_max_fee_in_strk: BigInt(response.fee.suggested_max_fee_in_strk),
|
|
9080
|
+
suggested_max_fee_in_gas_token: BigInt(response.fee.suggested_max_fee_in_gas_token)
|
|
9081
|
+
};
|
|
9082
|
+
switch (response.type) {
|
|
9083
|
+
case "invoke":
|
|
9084
|
+
return {
|
|
9085
|
+
type: "invoke",
|
|
9086
|
+
typed_data: response.typed_data,
|
|
9087
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
9088
|
+
fee
|
|
9089
|
+
};
|
|
9090
|
+
case "deploy_and_invoke":
|
|
9091
|
+
return {
|
|
9092
|
+
type: "deploy_and_invoke",
|
|
9093
|
+
deployment: response.deployment,
|
|
9094
|
+
typed_data: response.typed_data,
|
|
9095
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
9096
|
+
fee
|
|
9097
|
+
};
|
|
9098
|
+
case "deploy":
|
|
9099
|
+
default:
|
|
9100
|
+
return {
|
|
9101
|
+
type: "deploy",
|
|
9102
|
+
deployment: response.deployment,
|
|
9103
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
9104
|
+
fee
|
|
9105
|
+
};
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
async executeTransaction(transaction, parameters) {
|
|
9109
|
+
let user_transaction;
|
|
9110
|
+
switch (transaction.type) {
|
|
9111
|
+
case "invoke":
|
|
9112
|
+
user_transaction = {
|
|
9113
|
+
...transaction,
|
|
9114
|
+
invoke: {
|
|
9115
|
+
user_address: transaction.invoke.userAddress,
|
|
9116
|
+
typed_data: transaction.invoke.typedData,
|
|
9117
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
9118
|
+
}
|
|
9119
|
+
};
|
|
9120
|
+
break;
|
|
9121
|
+
case "deploy_and_invoke":
|
|
9122
|
+
user_transaction = {
|
|
9123
|
+
...transaction,
|
|
9124
|
+
invoke: {
|
|
9125
|
+
user_address: transaction.invoke.userAddress,
|
|
9126
|
+
typed_data: transaction.invoke.typedData,
|
|
9127
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
9128
|
+
}
|
|
9129
|
+
};
|
|
9130
|
+
break;
|
|
9131
|
+
case "deploy":
|
|
9132
|
+
default:
|
|
9133
|
+
user_transaction = transaction;
|
|
9134
|
+
break;
|
|
9135
|
+
}
|
|
9136
|
+
const executionParameters = {
|
|
9137
|
+
version: parameters.version,
|
|
9138
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
9139
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
9140
|
+
};
|
|
9141
|
+
return this.fetchEndpoint("paymaster_executeTransaction", {
|
|
9142
|
+
transaction: user_transaction,
|
|
9143
|
+
parameters: executionParameters
|
|
9144
|
+
});
|
|
9145
|
+
}
|
|
9146
|
+
async getSupportedTokens() {
|
|
9147
|
+
return this.fetchEndpoint("paymaster_getSupportedTokens").then(
|
|
9148
|
+
(tokens) => tokens.map((token) => ({
|
|
9149
|
+
token_address: token.token_address,
|
|
9150
|
+
decimals: token.decimals,
|
|
9151
|
+
priceInStrk: BigInt(token.price_in_strk)
|
|
9152
|
+
}))
|
|
9153
|
+
);
|
|
9154
|
+
}
|
|
9155
|
+
};
|
|
9156
|
+
|
|
9157
|
+
// src/paymaster/interface.ts
|
|
9158
|
+
var PaymasterInterface = class {
|
|
9159
|
+
};
|
|
9160
|
+
|
|
9161
|
+
// src/paymaster/index.ts
|
|
9162
|
+
var defaultPaymaster = new PaymasterRpc({ default: true });
|
|
9163
|
+
|
|
8447
9164
|
// src/account/default.ts
|
|
8448
9165
|
var Account = class extends RpcProvider2 {
|
|
8449
9166
|
signer;
|
|
8450
9167
|
address;
|
|
8451
9168
|
cairoVersion;
|
|
8452
9169
|
transactionVersion;
|
|
8453
|
-
|
|
9170
|
+
paymaster;
|
|
9171
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = config.get("transactionVersion"), paymaster) {
|
|
8454
9172
|
super(providerOrOptions);
|
|
8455
9173
|
this.address = address.toLowerCase();
|
|
8456
9174
|
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
@@ -8458,6 +9176,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8458
9176
|
this.cairoVersion = cairoVersion.toString();
|
|
8459
9177
|
}
|
|
8460
9178
|
this.transactionVersion = transactionVersion;
|
|
9179
|
+
this.paymaster = paymaster ? new PaymasterRpc(paymaster) : defaultPaymaster;
|
|
8461
9180
|
logger.debug("Account setup", {
|
|
8462
9181
|
transactionVersion: this.transactionVersion,
|
|
8463
9182
|
cairoVersion: this.cairoVersion,
|
|
@@ -8515,7 +9234,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8515
9234
|
);
|
|
8516
9235
|
const chainId = await this.getChainId();
|
|
8517
9236
|
const signerDetails = {
|
|
8518
|
-
...v3Details(details, await this.channel.
|
|
9237
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8519
9238
|
walletAddress: this.address,
|
|
8520
9239
|
nonce,
|
|
8521
9240
|
maxFee: ZERO,
|
|
@@ -8527,7 +9246,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8527
9246
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
8528
9247
|
return super.getInvokeEstimateFee(
|
|
8529
9248
|
{ ...invocation },
|
|
8530
|
-
{ ...v3Details(details, await this.channel.
|
|
9249
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
8531
9250
|
blockIdentifier,
|
|
8532
9251
|
details.skipValidate
|
|
8533
9252
|
);
|
|
@@ -8546,7 +9265,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8546
9265
|
);
|
|
8547
9266
|
const chainId = await this.getChainId();
|
|
8548
9267
|
const declareContractTransaction = await this.buildDeclarePayload(payload, {
|
|
8549
|
-
...v3Details(details, await this.channel.
|
|
9268
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8550
9269
|
nonce,
|
|
8551
9270
|
chainId,
|
|
8552
9271
|
version,
|
|
@@ -8558,7 +9277,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8558
9277
|
});
|
|
8559
9278
|
return super.getDeclareEstimateFee(
|
|
8560
9279
|
declareContractTransaction,
|
|
8561
|
-
{ ...v3Details(details, await this.channel.
|
|
9280
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
8562
9281
|
blockIdentifier,
|
|
8563
9282
|
details.skipValidate
|
|
8564
9283
|
);
|
|
@@ -8579,7 +9298,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8579
9298
|
const payload = await this.buildAccountDeployPayload(
|
|
8580
9299
|
{ classHash, addressSalt, constructorCalldata, contractAddress },
|
|
8581
9300
|
{
|
|
8582
|
-
...v3Details(details, await this.channel.
|
|
9301
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8583
9302
|
nonce,
|
|
8584
9303
|
chainId,
|
|
8585
9304
|
version,
|
|
@@ -8593,7 +9312,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8593
9312
|
);
|
|
8594
9313
|
return super.getDeployAccountEstimateFee(
|
|
8595
9314
|
{ ...payload },
|
|
8596
|
-
{ ...v3Details(details, await this.channel.
|
|
9315
|
+
{ ...v3Details(details, await this.channel.setUpSpecVersion()), version, nonce },
|
|
8597
9316
|
blockIdentifier,
|
|
8598
9317
|
details.skipValidate
|
|
8599
9318
|
);
|
|
@@ -8606,7 +9325,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8606
9325
|
if (!invocations.length) throw TypeError("Invocations should be non-empty array");
|
|
8607
9326
|
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
8608
9327
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
8609
|
-
...v3Details(details, await this.channel.
|
|
9328
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8610
9329
|
versions: [
|
|
8611
9330
|
ETransactionVersion2.F1,
|
|
8612
9331
|
// non-sierra
|
|
@@ -8629,7 +9348,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8629
9348
|
if (!invocations.length) throw TypeError("Invocations should be non-empty array");
|
|
8630
9349
|
const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
|
|
8631
9350
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
8632
|
-
...v3Details(details, await this.channel.
|
|
9351
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8633
9352
|
versions: [
|
|
8634
9353
|
ETransactionVersion2.V1,
|
|
8635
9354
|
// non-sierra
|
|
@@ -8650,6 +9369,13 @@ var Account = class extends RpcProvider2 {
|
|
|
8650
9369
|
}
|
|
8651
9370
|
async execute(transactions, transactionsDetail = {}) {
|
|
8652
9371
|
const calls = Array.isArray(transactions) ? transactions : [transactions];
|
|
9372
|
+
if (transactionsDetail.paymaster) {
|
|
9373
|
+
return this.executePaymasterTransaction(
|
|
9374
|
+
calls,
|
|
9375
|
+
transactionsDetail.paymaster,
|
|
9376
|
+
transactionsDetail.maxFee
|
|
9377
|
+
);
|
|
9378
|
+
}
|
|
8653
9379
|
const nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
|
|
8654
9380
|
const version = toTransactionVersion(
|
|
8655
9381
|
this.getPreferredVersion(ETransactionVersion2.V1, ETransactionVersion2.V3),
|
|
@@ -8666,7 +9392,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8666
9392
|
);
|
|
8667
9393
|
const chainId = await this.getChainId();
|
|
8668
9394
|
const signerDetails = {
|
|
8669
|
-
...v3Details(transactionsDetail, await this.channel.
|
|
9395
|
+
...v3Details(transactionsDetail, await this.channel.setUpSpecVersion()),
|
|
8670
9396
|
resourceBounds: estimate.resourceBounds,
|
|
8671
9397
|
walletAddress: this.address,
|
|
8672
9398
|
nonce,
|
|
@@ -8680,7 +9406,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8680
9406
|
return this.invokeFunction(
|
|
8681
9407
|
{ contractAddress: this.address, calldata, signature },
|
|
8682
9408
|
{
|
|
8683
|
-
...v3Details(transactionsDetail, await this.channel.
|
|
9409
|
+
...v3Details(transactionsDetail, await this.channel.setUpSpecVersion()),
|
|
8684
9410
|
resourceBounds: estimate.resourceBounds,
|
|
8685
9411
|
nonce,
|
|
8686
9412
|
maxFee: estimate.maxFee,
|
|
@@ -8688,6 +9414,88 @@ var Account = class extends RpcProvider2 {
|
|
|
8688
9414
|
}
|
|
8689
9415
|
);
|
|
8690
9416
|
}
|
|
9417
|
+
async buildPaymasterTransaction(calls, paymasterDetails) {
|
|
9418
|
+
if (!paymasterDetails.deploymentData) {
|
|
9419
|
+
const snip9Version = await this.getSnip9Version();
|
|
9420
|
+
if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
|
|
9421
|
+
throw Error("Account is not compatible with SNIP-9");
|
|
9422
|
+
}
|
|
9423
|
+
}
|
|
9424
|
+
const parameters = {
|
|
9425
|
+
version: "0x1",
|
|
9426
|
+
feeMode: paymasterDetails.feeMode,
|
|
9427
|
+
timeBounds: paymasterDetails.timeBounds
|
|
9428
|
+
};
|
|
9429
|
+
let transaction;
|
|
9430
|
+
if (paymasterDetails.deploymentData) {
|
|
9431
|
+
if (calls.length > 0) {
|
|
9432
|
+
transaction = {
|
|
9433
|
+
type: "deploy_and_invoke",
|
|
9434
|
+
invoke: { userAddress: this.address, calls },
|
|
9435
|
+
deployment: paymasterDetails.deploymentData
|
|
9436
|
+
};
|
|
9437
|
+
} else {
|
|
9438
|
+
transaction = {
|
|
9439
|
+
type: "deploy",
|
|
9440
|
+
deployment: paymasterDetails.deploymentData
|
|
9441
|
+
};
|
|
9442
|
+
}
|
|
9443
|
+
} else {
|
|
9444
|
+
transaction = {
|
|
9445
|
+
type: "invoke",
|
|
9446
|
+
invoke: { userAddress: this.address, calls }
|
|
9447
|
+
};
|
|
9448
|
+
}
|
|
9449
|
+
return this.paymaster.buildTransaction(transaction, parameters);
|
|
9450
|
+
}
|
|
9451
|
+
async estimatePaymasterTransactionFee(calls, paymasterDetails) {
|
|
9452
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
9453
|
+
return preparedTransaction.fee;
|
|
9454
|
+
}
|
|
9455
|
+
async executePaymasterTransaction(calls, paymasterDetails, maxFee) {
|
|
9456
|
+
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
9457
|
+
if (maxFee && preparedTransaction.fee.gas_token_price_in_strk > maxFee) {
|
|
9458
|
+
throw Error("Gas token price is too high");
|
|
9459
|
+
}
|
|
9460
|
+
let transaction;
|
|
9461
|
+
switch (preparedTransaction.type) {
|
|
9462
|
+
case "deploy_and_invoke": {
|
|
9463
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
9464
|
+
transaction = {
|
|
9465
|
+
type: "deploy_and_invoke",
|
|
9466
|
+
invoke: {
|
|
9467
|
+
userAddress: this.address,
|
|
9468
|
+
typedData: preparedTransaction.typed_data,
|
|
9469
|
+
signature: signatureToHexArray(signature)
|
|
9470
|
+
},
|
|
9471
|
+
deployment: preparedTransaction.deployment
|
|
9472
|
+
};
|
|
9473
|
+
break;
|
|
9474
|
+
}
|
|
9475
|
+
case "invoke": {
|
|
9476
|
+
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
9477
|
+
transaction = {
|
|
9478
|
+
type: "invoke",
|
|
9479
|
+
invoke: {
|
|
9480
|
+
userAddress: this.address,
|
|
9481
|
+
typedData: preparedTransaction.typed_data,
|
|
9482
|
+
signature: signatureToHexArray(signature)
|
|
9483
|
+
}
|
|
9484
|
+
};
|
|
9485
|
+
break;
|
|
9486
|
+
}
|
|
9487
|
+
case "deploy": {
|
|
9488
|
+
transaction = {
|
|
9489
|
+
type: "deploy",
|
|
9490
|
+
deployment: preparedTransaction.deployment
|
|
9491
|
+
};
|
|
9492
|
+
break;
|
|
9493
|
+
}
|
|
9494
|
+
default:
|
|
9495
|
+
throw Error("Invalid transaction type");
|
|
9496
|
+
}
|
|
9497
|
+
return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
|
|
9498
|
+
}
|
|
8691
9499
|
/**
|
|
8692
9500
|
* First check if contract is already declared, if not declare it
|
|
8693
9501
|
* If contract already declared returned transaction_hash is ''.
|
|
@@ -8725,7 +9533,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8725
9533
|
}
|
|
8726
9534
|
);
|
|
8727
9535
|
const declareDetails = {
|
|
8728
|
-
...v3Details(details, await this.channel.
|
|
9536
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8729
9537
|
resourceBounds: estimate.resourceBounds,
|
|
8730
9538
|
maxFee: estimate.maxFee,
|
|
8731
9539
|
nonce: toBigInt(nonce ?? await this.getNonce()),
|
|
@@ -8795,7 +9603,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8795
9603
|
details
|
|
8796
9604
|
);
|
|
8797
9605
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
8798
|
-
...v3Details(details, await this.channel.
|
|
9606
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8799
9607
|
classHash,
|
|
8800
9608
|
constructorCalldata: compiledCalldata,
|
|
8801
9609
|
contractAddress,
|
|
@@ -8809,7 +9617,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8809
9617
|
return this.deployAccountContract(
|
|
8810
9618
|
{ classHash, addressSalt, constructorCalldata, signature },
|
|
8811
9619
|
{
|
|
8812
|
-
...v3Details(details, await this.channel.
|
|
9620
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
8813
9621
|
nonce,
|
|
8814
9622
|
resourceBounds: estimate.resourceBounds,
|
|
8815
9623
|
maxFee: estimate.maxFee,
|
|
@@ -8976,7 +9784,7 @@ var Account = class extends RpcProvider2 {
|
|
|
8976
9784
|
let resourceBounds = estimateFeeToBounds3(
|
|
8977
9785
|
ZERO,
|
|
8978
9786
|
void 0,
|
|
8979
|
-
await this.channel.
|
|
9787
|
+
await this.channel.setUpSpecVersion()
|
|
8980
9788
|
);
|
|
8981
9789
|
if (version === ETransactionVersion2.V3) {
|
|
8982
9790
|
resourceBounds = details.resourceBounds ?? (await this.getSuggestedFee({ type, payload }, details)).resourceBounds;
|
|
@@ -8999,14 +9807,14 @@ var Account = class extends RpcProvider2 {
|
|
|
8999
9807
|
case TransactionType.DEPLOY:
|
|
9000
9808
|
return this.estimateDeployFee(payload, details);
|
|
9001
9809
|
default:
|
|
9002
|
-
return ZEROFee(await this.channel.
|
|
9810
|
+
return ZEROFee(await this.channel.setUpSpecVersion());
|
|
9003
9811
|
}
|
|
9004
9812
|
}
|
|
9005
9813
|
async buildInvocation(call, details) {
|
|
9006
9814
|
const calldata = getExecuteCalldata(call, await this.getCairoVersion());
|
|
9007
9815
|
const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
|
|
9008
9816
|
return {
|
|
9009
|
-
...v3Details(details, await this.channel.
|
|
9817
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
9010
9818
|
contractAddress: this.address,
|
|
9011
9819
|
calldata,
|
|
9012
9820
|
signature
|
|
@@ -9020,7 +9828,7 @@ var Account = class extends RpcProvider2 {
|
|
|
9020
9828
|
}
|
|
9021
9829
|
const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
|
|
9022
9830
|
...details,
|
|
9023
|
-
...v3Details(details, await this.channel.
|
|
9831
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
9024
9832
|
classHash,
|
|
9025
9833
|
compiledClassHash,
|
|
9026
9834
|
// TODO: TS, cast because optional for v2 and required for v3, thrown if not present
|
|
@@ -9043,14 +9851,14 @@ var Account = class extends RpcProvider2 {
|
|
|
9043
9851
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
9044
9852
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
9045
9853
|
...details,
|
|
9046
|
-
...v3Details(details, await this.channel.
|
|
9854
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
9047
9855
|
classHash,
|
|
9048
9856
|
contractAddress,
|
|
9049
9857
|
addressSalt,
|
|
9050
9858
|
constructorCalldata: compiledCalldata
|
|
9051
9859
|
}) : [];
|
|
9052
9860
|
return {
|
|
9053
|
-
...v3Details(details, await this.channel.
|
|
9861
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
9054
9862
|
classHash,
|
|
9055
9863
|
addressSalt,
|
|
9056
9864
|
constructorCalldata: compiledCalldata,
|
|
@@ -9091,7 +9899,7 @@ var Account = class extends RpcProvider2 {
|
|
|
9091
9899
|
[].concat(invocations).map(async (transaction, index) => {
|
|
9092
9900
|
const txPayload = "payload" in transaction ? transaction.payload : transaction;
|
|
9093
9901
|
const signerDetails = {
|
|
9094
|
-
...v3Details(details, await this.channel.
|
|
9902
|
+
...v3Details(details, await this.channel.setUpSpecVersion()),
|
|
9095
9903
|
walletAddress: this.address,
|
|
9096
9904
|
nonce: toBigInt(Number(safeNonce) + index),
|
|
9097
9905
|
maxFee: ZERO,
|
|
@@ -9234,8 +10042,8 @@ function onNetworkChanged(swo, callback) {
|
|
|
9234
10042
|
// src/wallet/account.ts
|
|
9235
10043
|
var WalletAccount = class _WalletAccount extends Account {
|
|
9236
10044
|
walletProvider;
|
|
9237
|
-
constructor(providerOrOptions, walletProvider, address, cairoVersion) {
|
|
9238
|
-
super(providerOrOptions, address, "", cairoVersion);
|
|
10045
|
+
constructor(providerOrOptions, walletProvider, address, cairoVersion, paymaster) {
|
|
10046
|
+
super(providerOrOptions, address, "", cairoVersion, void 0, paymaster);
|
|
9239
10047
|
this.walletProvider = walletProvider;
|
|
9240
10048
|
this.walletProvider.on("accountsChanged", (res) => {
|
|
9241
10049
|
if (!res) return;
|
|
@@ -9276,7 +10084,14 @@ var WalletAccount = class _WalletAccount extends Account {
|
|
|
9276
10084
|
/**
|
|
9277
10085
|
* ACCOUNT METHODS
|
|
9278
10086
|
*/
|
|
9279
|
-
execute(calls) {
|
|
10087
|
+
execute(calls, arg2, transactionsDetail = {}) {
|
|
10088
|
+
const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
|
|
10089
|
+
if (details.paymaster) {
|
|
10090
|
+
return this.executePaymasterTransaction(
|
|
10091
|
+
Array.isArray(calls) ? calls : [calls],
|
|
10092
|
+
details.paymaster
|
|
10093
|
+
);
|
|
10094
|
+
}
|
|
9280
10095
|
const txCalls = [].concat(calls).map((it) => {
|
|
9281
10096
|
const { contractAddress, entrypoint, calldata } = it;
|
|
9282
10097
|
return {
|
|
@@ -9317,12 +10132,12 @@ var WalletAccount = class _WalletAccount extends Account {
|
|
|
9317
10132
|
signMessage(typedData) {
|
|
9318
10133
|
return signMessage(this.walletProvider, typedData);
|
|
9319
10134
|
}
|
|
9320
|
-
static async connect(provider, walletProvider, cairoVersion, silentMode = false) {
|
|
10135
|
+
static async connect(provider, walletProvider, cairoVersion, paymaster, silentMode = false) {
|
|
9321
10136
|
const [accountAddress] = await requestAccounts(walletProvider, silentMode);
|
|
9322
|
-
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion);
|
|
10137
|
+
return new _WalletAccount(provider, walletProvider, accountAddress, cairoVersion, paymaster);
|
|
9323
10138
|
}
|
|
9324
|
-
static async connectSilent(provider, walletProvider, cairoVersion) {
|
|
9325
|
-
return _WalletAccount.connect(provider, walletProvider, cairoVersion, true);
|
|
10139
|
+
static async connectSilent(provider, walletProvider, cairoVersion, paymaster) {
|
|
10140
|
+
return _WalletAccount.connect(provider, walletProvider, cairoVersion, paymaster, true);
|
|
9326
10141
|
}
|
|
9327
10142
|
// TODO: MISSING ESTIMATES
|
|
9328
10143
|
};
|
|
@@ -9732,6 +10547,7 @@ export {
|
|
|
9732
10547
|
LedgerSigner111 as LedgerSigner,
|
|
9733
10548
|
LedgerSigner111,
|
|
9734
10549
|
LedgerSigner221,
|
|
10550
|
+
LedgerSigner231,
|
|
9735
10551
|
LibraryError,
|
|
9736
10552
|
Literal,
|
|
9737
10553
|
LogLevelIndex,
|
|
@@ -9739,11 +10555,13 @@ export {
|
|
|
9739
10555
|
OutsideExecutionTypesV1,
|
|
9740
10556
|
OutsideExecutionTypesV2,
|
|
9741
10557
|
OutsideExecutionVersion,
|
|
10558
|
+
PaymasterInterface,
|
|
10559
|
+
PaymasterRpc,
|
|
9742
10560
|
RpcProvider2 as Provider,
|
|
9743
10561
|
ProviderInterface,
|
|
9744
10562
|
api_exports as RPC,
|
|
9745
|
-
|
|
9746
|
-
|
|
10563
|
+
rpc_0_7_1_exports as RPC07,
|
|
10564
|
+
rpc_0_8_1_exports as RPC08,
|
|
9747
10565
|
RPCResponseParser,
|
|
9748
10566
|
ReceiptTx,
|
|
9749
10567
|
ResponseParser,
|
|
@@ -9777,6 +10595,7 @@ export {
|
|
|
9777
10595
|
config,
|
|
9778
10596
|
constants_exports as constants,
|
|
9779
10597
|
contractClassResponseToLegacyCompiledContract,
|
|
10598
|
+
defaultPaymaster,
|
|
9780
10599
|
defaultProvider,
|
|
9781
10600
|
ec_exports as ec,
|
|
9782
10601
|
encode_exports as encode,
|
|
@@ -9791,21 +10610,29 @@ export {
|
|
|
9791
10610
|
getLedgerPathBuffer111,
|
|
9792
10611
|
getLedgerPathBuffer221,
|
|
9793
10612
|
hash_exports as hash,
|
|
10613
|
+
isPendingBlock,
|
|
10614
|
+
isPendingStateUpdate,
|
|
10615
|
+
isPendingTransaction,
|
|
9794
10616
|
isRPC08_FeeEstimate,
|
|
9795
10617
|
isRPC08_ResourceBounds,
|
|
9796
10618
|
isSierra,
|
|
10619
|
+
isSupportedSpecVersion,
|
|
10620
|
+
isV3Tx,
|
|
10621
|
+
isVersion,
|
|
9797
10622
|
json_exports as json,
|
|
9798
10623
|
logger,
|
|
9799
10624
|
merkle_exports as merkle,
|
|
9800
10625
|
num_exports as num,
|
|
9801
10626
|
outsideExecution_exports as outsideExecution,
|
|
9802
10627
|
parseCalldataField,
|
|
10628
|
+
paymaster_exports as paymaster,
|
|
9803
10629
|
provider_exports as provider,
|
|
9804
10630
|
selector_exports as selector,
|
|
9805
10631
|
shortString_exports as shortString,
|
|
9806
10632
|
src5_exports as src5,
|
|
9807
10633
|
stark_exports as stark,
|
|
9808
10634
|
starknetId_exports as starknetId,
|
|
10635
|
+
toAnyPatchVersion,
|
|
9809
10636
|
transaction_exports as transaction,
|
|
9810
10637
|
typedData_exports as typedData,
|
|
9811
10638
|
types_exports as types,
|