starknet 11.4.0 → 11.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +207 -78
- package/dist/index.global.js +1106 -961
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1109 -965
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1106 -963
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -204,7 +204,8 @@ __export(index_exports, {
|
|
|
204
204
|
num: () => num_exports,
|
|
205
205
|
outsideExecution: () => outsideExecution_exports,
|
|
206
206
|
parseCalldataField: () => parseCalldataField,
|
|
207
|
-
paymaster: () =>
|
|
207
|
+
paymaster: () => utils_exports,
|
|
208
|
+
paymasterPlugin: () => paymasterPlugin,
|
|
208
209
|
provider: () => provider_exports,
|
|
209
210
|
selector: () => selector_exports,
|
|
210
211
|
shortString: () => shortString_exports,
|
|
@@ -17210,11 +17211,720 @@ function fastExecute() {
|
|
|
17210
17211
|
};
|
|
17211
17212
|
}
|
|
17212
17213
|
|
|
17214
|
+
// src/plugins/paymaster/utils.ts
|
|
17215
|
+
var utils_exports = {};
|
|
17216
|
+
__export(utils_exports, {
|
|
17217
|
+
assertCallsAreStrictlyEqual: () => assertCallsAreStrictlyEqual,
|
|
17218
|
+
assertPaymasterTransactionSafety: () => assertPaymasterTransactionSafety,
|
|
17219
|
+
getDefaultPaymasterNodeUrl: () => getDefaultPaymasterNodeUrl
|
|
17220
|
+
});
|
|
17221
|
+
|
|
17222
|
+
// src/utils/outsideExecution.ts
|
|
17223
|
+
var outsideExecution_exports = {};
|
|
17224
|
+
__export(outsideExecution_exports, {
|
|
17225
|
+
buildExecuteFromOutsideCall: () => buildExecuteFromOutsideCall,
|
|
17226
|
+
buildExecuteFromOutsideCallData: () => buildExecuteFromOutsideCallData,
|
|
17227
|
+
getOutsideCall: () => getOutsideCall,
|
|
17228
|
+
getTypedData: () => getTypedData,
|
|
17229
|
+
toOutsideCallV2: () => toOutsideCallV2
|
|
17230
|
+
});
|
|
17231
|
+
function toOutsideCallV2(call) {
|
|
17232
|
+
if ("calldata_len" in call) {
|
|
17233
|
+
return {
|
|
17234
|
+
To: call.to,
|
|
17235
|
+
Selector: call.selector,
|
|
17236
|
+
Calldata: call.calldata
|
|
17237
|
+
};
|
|
17238
|
+
}
|
|
17239
|
+
return call;
|
|
17240
|
+
}
|
|
17241
|
+
function getOutsideCall(call) {
|
|
17242
|
+
const callData = call.calldata ?? [];
|
|
17243
|
+
const callDataCompiled = Array.isArray(callData) && "__compiled__" in callData ? callData : CallData.compile(callData);
|
|
17244
|
+
return {
|
|
17245
|
+
to: call.contractAddress,
|
|
17246
|
+
selector: getSelectorFromName(call.entrypoint),
|
|
17247
|
+
calldata: callDataCompiled
|
|
17248
|
+
};
|
|
17249
|
+
}
|
|
17250
|
+
function callToTypedData(call, version) {
|
|
17251
|
+
const outsideCall = getOutsideCall(call);
|
|
17252
|
+
if (version === "1") {
|
|
17253
|
+
return {
|
|
17254
|
+
...outsideCall,
|
|
17255
|
+
calldata_len: outsideCall.calldata.length,
|
|
17256
|
+
calldata: outsideCall.calldata
|
|
17257
|
+
};
|
|
17258
|
+
}
|
|
17259
|
+
return {
|
|
17260
|
+
To: outsideCall.to,
|
|
17261
|
+
Selector: outsideCall.selector,
|
|
17262
|
+
Calldata: outsideCall.calldata
|
|
17263
|
+
};
|
|
17264
|
+
}
|
|
17265
|
+
function getDomain(chainId, version) {
|
|
17266
|
+
return {
|
|
17267
|
+
name: "Account.execute_from_outside",
|
|
17268
|
+
version,
|
|
17269
|
+
chainId,
|
|
17270
|
+
...version === "2" ? { revision: "1" } : {}
|
|
17271
|
+
};
|
|
17272
|
+
}
|
|
17273
|
+
function getTypedData(chainId, options, nonce, myCalls, version) {
|
|
17274
|
+
if (version === "1") {
|
|
17275
|
+
return {
|
|
17276
|
+
types: OutsideExecutionTypesV1,
|
|
17277
|
+
primaryType: "OutsideExecution",
|
|
17278
|
+
domain: getDomain(chainId, version),
|
|
17279
|
+
message: {
|
|
17280
|
+
...options,
|
|
17281
|
+
nonce,
|
|
17282
|
+
calls_len: myCalls.length,
|
|
17283
|
+
calls: myCalls.map((call) => callToTypedData(call, version))
|
|
17284
|
+
}
|
|
17285
|
+
};
|
|
17286
|
+
}
|
|
17287
|
+
return {
|
|
17288
|
+
types: OutsideExecutionTypesV2,
|
|
17289
|
+
primaryType: "OutsideExecution",
|
|
17290
|
+
domain: getDomain(chainId, version),
|
|
17291
|
+
message: {
|
|
17292
|
+
Caller: options.caller,
|
|
17293
|
+
Nonce: nonce,
|
|
17294
|
+
"Execute After": options.execute_after,
|
|
17295
|
+
"Execute Before": options.execute_before,
|
|
17296
|
+
Calls: myCalls.map((call) => callToTypedData(call, version))
|
|
17297
|
+
}
|
|
17298
|
+
};
|
|
17299
|
+
}
|
|
17300
|
+
function buildExecuteFromOutsideCallData(outsideTransaction) {
|
|
17301
|
+
const execution2 = outsideTransaction.outsideExecution;
|
|
17302
|
+
const formattedSignature = formatSignature(outsideTransaction.signature);
|
|
17303
|
+
return CallData.compile({
|
|
17304
|
+
outside_execution: execution2,
|
|
17305
|
+
signature: formattedSignature
|
|
17306
|
+
});
|
|
17307
|
+
}
|
|
17308
|
+
function buildExecuteFromOutsideCall(outsideTransaction) {
|
|
17309
|
+
const myOutsideTransactions = Array.isArray(outsideTransaction) ? outsideTransaction : [outsideTransaction];
|
|
17310
|
+
const multiCall = myOutsideTransactions.map((outsideTx) => {
|
|
17311
|
+
let entrypoint;
|
|
17312
|
+
if (outsideTx.version === OutsideExecutionVersion.V1) {
|
|
17313
|
+
entrypoint = "execute_from_outside";
|
|
17314
|
+
} else if (outsideTx.version === OutsideExecutionVersion.V2) {
|
|
17315
|
+
entrypoint = "execute_from_outside_v2";
|
|
17316
|
+
} else {
|
|
17317
|
+
throw new Error("Unsupported OutsideExecution version");
|
|
17318
|
+
}
|
|
17319
|
+
return {
|
|
17320
|
+
contractAddress: toHex(outsideTx.signerAddress),
|
|
17321
|
+
entrypoint,
|
|
17322
|
+
calldata: buildExecuteFromOutsideCallData(outsideTx)
|
|
17323
|
+
};
|
|
17324
|
+
});
|
|
17325
|
+
return multiCall;
|
|
17326
|
+
}
|
|
17327
|
+
|
|
17328
|
+
// src/utils/uint256.ts
|
|
17329
|
+
var uint256_exports = {};
|
|
17330
|
+
__export(uint256_exports, {
|
|
17331
|
+
bnToUint256: () => bnToUint256,
|
|
17332
|
+
isUint256: () => isUint256,
|
|
17333
|
+
uint256ToBN: () => uint256ToBN
|
|
17334
|
+
});
|
|
17335
|
+
function uint256ToBN(uint2562) {
|
|
17336
|
+
return new CairoUint256(uint2562).toBigInt();
|
|
17337
|
+
}
|
|
17338
|
+
function isUint256(bn) {
|
|
17339
|
+
return CairoUint256.is(bn);
|
|
17340
|
+
}
|
|
17341
|
+
function bnToUint256(bn) {
|
|
17342
|
+
return new CairoUint256(bn).toUint256HexString();
|
|
17343
|
+
}
|
|
17344
|
+
|
|
17345
|
+
// src/plugins/paymaster/utils.ts
|
|
17346
|
+
var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
|
|
17347
|
+
if (!mute) {
|
|
17348
|
+
logger.info("Using default public node url, please provide nodeUrl in provider options!");
|
|
17349
|
+
}
|
|
17350
|
+
const nodes = PAYMASTER_RPC_NODES[networkName ?? _NetworkName.SN_SEPOLIA];
|
|
17351
|
+
const randIdx = Math.floor(Math.random() * nodes.length);
|
|
17352
|
+
return nodes[randIdx];
|
|
17353
|
+
};
|
|
17354
|
+
var assertGasFeeFromUnsafeCalls = (unsafeCalls, fees) => {
|
|
17355
|
+
const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
|
|
17356
|
+
const unsafeGasTokenCalldata = CallData.toCalldata(unsafeCall.Calldata);
|
|
17357
|
+
const unsafeGasTokenValue = uint256ToBN({
|
|
17358
|
+
low: unsafeGasTokenCalldata[1],
|
|
17359
|
+
high: unsafeGasTokenCalldata[2]
|
|
17360
|
+
});
|
|
17361
|
+
assert(
|
|
17362
|
+
unsafeGasTokenValue === BigInt(fees),
|
|
17363
|
+
"Gas token value is not equal to the provided gas fees"
|
|
17364
|
+
);
|
|
17365
|
+
};
|
|
17366
|
+
var assertGasTokenFromUnsafeCalls = (unsafeCalls, gasToken) => {
|
|
17367
|
+
const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
|
|
17368
|
+
assert(
|
|
17369
|
+
BigInt(unsafeCall.To) === BigInt(gasToken),
|
|
17370
|
+
"Gas token address is not equal to the provided gas token"
|
|
17371
|
+
);
|
|
17372
|
+
assert(
|
|
17373
|
+
unsafeCall.Selector === getSelectorFromName("transfer"),
|
|
17374
|
+
"Gas token call selector is not a transfer"
|
|
17375
|
+
);
|
|
17376
|
+
assert(
|
|
17377
|
+
CallData.toCalldata(unsafeCall.Calldata).length === 3,
|
|
17378
|
+
"Gas token transfer calldata does not match the expected recipient/amount shape"
|
|
17379
|
+
);
|
|
17380
|
+
};
|
|
17381
|
+
function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls, isSponsored = false) {
|
|
17382
|
+
const baseError = "Provided calls are not strictly equal to the returned calls";
|
|
17383
|
+
const expectedExtraCalls = isSponsored ? 0 : 1;
|
|
17384
|
+
assert(
|
|
17385
|
+
unsafeCalls.length - expectedExtraCalls === originalCalls.length,
|
|
17386
|
+
`${baseError}: Expected ${originalCalls.length + expectedExtraCalls} calls, got ${unsafeCalls.length}`
|
|
17387
|
+
);
|
|
17388
|
+
for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
|
|
17389
|
+
const originalCall = originalCalls[callIndex];
|
|
17390
|
+
const unsafeCall = toOutsideCallV2(unsafeCalls[callIndex]);
|
|
17391
|
+
const normalizeAddress = (address) => {
|
|
17392
|
+
return toBigInt(address).toString(16).toLowerCase();
|
|
17393
|
+
};
|
|
17394
|
+
const originalAddress = normalizeAddress(originalCall.contractAddress);
|
|
17395
|
+
const unsafeAddress = normalizeAddress(unsafeCall.To);
|
|
17396
|
+
assert(
|
|
17397
|
+
originalAddress === unsafeAddress,
|
|
17398
|
+
`${baseError}: Contract address mismatch at call ${callIndex}. Expected: ${originalCall.contractAddress}, Got: ${unsafeCall.To}`
|
|
17399
|
+
);
|
|
17400
|
+
assert(
|
|
17401
|
+
getSelectorFromName(originalCall.entrypoint) === unsafeCall.Selector,
|
|
17402
|
+
`${baseError}: Entrypoint mismatch at call ${callIndex}. Expected: ${originalCall.entrypoint}, Got: ${unsafeCall.Selector}`
|
|
17403
|
+
);
|
|
17404
|
+
const originalCalldata = CallData.toCalldata(originalCall.calldata);
|
|
17405
|
+
const unsafeCalldata = CallData.toCalldata(unsafeCall.Calldata);
|
|
17406
|
+
assert(
|
|
17407
|
+
originalCalldata.length === unsafeCalldata.length,
|
|
17408
|
+
`${baseError}: Calldata length mismatch at call ${callIndex}. Expected length: ${originalCalldata.length}, Got length: ${unsafeCalldata.length}`
|
|
17409
|
+
);
|
|
17410
|
+
for (let dataIndex = 0; dataIndex < originalCalldata.length; dataIndex += 1) {
|
|
17411
|
+
const originalValue = BigInt(originalCalldata[dataIndex]);
|
|
17412
|
+
const unsafeValue = BigInt(unsafeCalldata[dataIndex]);
|
|
17413
|
+
assert(
|
|
17414
|
+
originalValue === unsafeValue,
|
|
17415
|
+
`${baseError}: Calldata value mismatch at call ${callIndex}, parameter ${dataIndex}. Expected: ${originalCalldata[dataIndex]}, Got: ${unsafeCalldata[dataIndex]}`
|
|
17416
|
+
);
|
|
17417
|
+
}
|
|
17418
|
+
}
|
|
17419
|
+
}
|
|
17420
|
+
var domainFieldToFelt = (value) => {
|
|
17421
|
+
try {
|
|
17422
|
+
return toBigInt(value);
|
|
17423
|
+
} catch {
|
|
17424
|
+
return CairoBytes31.fromText(String(value)).toBigInt();
|
|
17425
|
+
}
|
|
17426
|
+
};
|
|
17427
|
+
var assertChainIdFromTypedData = (typedData, chainId) => {
|
|
17428
|
+
assert(
|
|
17429
|
+
typedData.domain.chainId !== void 0 && domainFieldToFelt(typedData.domain.chainId) === BigInt(chainId),
|
|
17430
|
+
"Paymaster typed data domain chainId does not match the account's provider chain"
|
|
17431
|
+
);
|
|
17432
|
+
};
|
|
17433
|
+
var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, chainId, maxFeeInGasToken) => {
|
|
17434
|
+
if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
|
|
17435
|
+
assertChainIdFromTypedData(preparedTransaction.typed_data, chainId);
|
|
17436
|
+
const { message } = preparedTransaction.typed_data;
|
|
17437
|
+
const hasV1Calls = "calls" in message;
|
|
17438
|
+
const hasV2Calls = "Calls" in message;
|
|
17439
|
+
assert(
|
|
17440
|
+
hasV1Calls !== hasV2Calls,
|
|
17441
|
+
'Paymaster typed data must declare exactly one of "calls" (SNIP-9 V1) or "Calls" (SNIP-9 V2)'
|
|
17442
|
+
);
|
|
17443
|
+
const unsafeCalls = hasV1Calls ? message.calls : message.Calls;
|
|
17444
|
+
assertCallsAreStrictlyEqual(calls, unsafeCalls, paymasterDetails.feeMode.mode === "sponsored");
|
|
17445
|
+
if (paymasterDetails.feeMode.mode !== "sponsored") {
|
|
17446
|
+
assertGasTokenFromUnsafeCalls(unsafeCalls, paymasterDetails.feeMode.gasToken);
|
|
17447
|
+
assertGasFeeFromUnsafeCalls(
|
|
17448
|
+
unsafeCalls,
|
|
17449
|
+
preparedTransaction.fee.suggested_max_fee_in_gas_token
|
|
17450
|
+
);
|
|
17451
|
+
if (maxFeeInGasToken) {
|
|
17452
|
+
assert(
|
|
17453
|
+
preparedTransaction.fee.suggested_max_fee_in_gas_token <= maxFeeInGasToken,
|
|
17454
|
+
"Gas token price is too high"
|
|
17455
|
+
);
|
|
17456
|
+
}
|
|
17457
|
+
}
|
|
17458
|
+
const msg = message;
|
|
17459
|
+
const version = hasV1Calls ? OutsideExecutionVersion.V1 : OutsideExecutionVersion.V2;
|
|
17460
|
+
const [callerKey, nonceKey, afterKey, beforeKey] = hasV1Calls ? ["caller", "nonce", "execute_after", "execute_before"] : ["Caller", "Nonce", "Execute After", "Execute Before"];
|
|
17461
|
+
assert(
|
|
17462
|
+
[callerKey, nonceKey, afterKey, beforeKey].every((key) => msg[key] !== void 0),
|
|
17463
|
+
"Paymaster typed data does not match the expected outside execution"
|
|
17464
|
+
);
|
|
17465
|
+
const caller = msg[callerKey];
|
|
17466
|
+
const nonce = msg[nonceKey];
|
|
17467
|
+
const executeAfter = msg[afterKey];
|
|
17468
|
+
const executeBefore = msg[beforeKey];
|
|
17469
|
+
if (paymasterDetails.timeBounds) {
|
|
17470
|
+
const requestedAfter = toBigInt(paymasterDetails.timeBounds.executeAfter ?? 1);
|
|
17471
|
+
const requestedBefore = toBigInt(paymasterDetails.timeBounds.executeBefore);
|
|
17472
|
+
assert(
|
|
17473
|
+
toBigInt(executeAfter) >= requestedAfter && toBigInt(executeBefore) <= requestedBefore,
|
|
17474
|
+
"Paymaster typed data execution window is not within the requested time bounds"
|
|
17475
|
+
);
|
|
17476
|
+
}
|
|
17477
|
+
const expectedCalls = [...calls];
|
|
17478
|
+
if (paymasterDetails.feeMode.mode !== "sponsored") {
|
|
17479
|
+
const feeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
|
|
17480
|
+
const feeRecipient = CallData.toCalldata(feeCall.Calldata)[0];
|
|
17481
|
+
const feeAmount = bnToUint256(preparedTransaction.fee.suggested_max_fee_in_gas_token);
|
|
17482
|
+
expectedCalls.push({
|
|
17483
|
+
contractAddress: paymasterDetails.feeMode.gasToken,
|
|
17484
|
+
entrypoint: "transfer",
|
|
17485
|
+
calldata: [feeRecipient, feeAmount.low, feeAmount.high]
|
|
17486
|
+
});
|
|
17487
|
+
}
|
|
17488
|
+
const expectedTypedData = getTypedData(
|
|
17489
|
+
chainId,
|
|
17490
|
+
{ caller, execute_after: executeAfter, execute_before: executeBefore },
|
|
17491
|
+
nonce,
|
|
17492
|
+
expectedCalls,
|
|
17493
|
+
version
|
|
17494
|
+
);
|
|
17495
|
+
assert(
|
|
17496
|
+
getMessageHash(expectedTypedData, 0) === getMessageHash(preparedTransaction.typed_data, 0),
|
|
17497
|
+
"Paymaster typed data does not match the expected outside execution"
|
|
17498
|
+
);
|
|
17499
|
+
}
|
|
17500
|
+
};
|
|
17501
|
+
|
|
17502
|
+
// src/plugins/paymaster/impl.ts
|
|
17503
|
+
var PaymasterImpl = class {
|
|
17504
|
+
/**
|
|
17505
|
+
* Asks the paymaster to build a transaction for the calls of an account.
|
|
17506
|
+
* @param {Account} account The account that will sign the transaction.
|
|
17507
|
+
* @param {Call[]} calls The calls to execute.
|
|
17508
|
+
* @param {PaymasterDetails} paymasterDetails The fee mode, and optionally the deployment data
|
|
17509
|
+
* and the time bounds.
|
|
17510
|
+
* @returns {Promise<PreparedTransaction>} The transaction prepared by the paymaster, with its
|
|
17511
|
+
* typed data to sign and its fees.
|
|
17512
|
+
* @example
|
|
17513
|
+
* ```typescript
|
|
17514
|
+
* const prepared = await PaymasterImpl.build(myAccount, [myCall], {
|
|
17515
|
+
* feeMode: { mode: 'sponsored' },
|
|
17516
|
+
* });
|
|
17517
|
+
* // prepared.type = 'invoke'
|
|
17518
|
+
* ```
|
|
17519
|
+
*/
|
|
17520
|
+
static async build(account, calls, paymasterDetails) {
|
|
17521
|
+
if (!paymasterDetails.deploymentData) {
|
|
17522
|
+
const snip9Version = await account.getSnip9Version();
|
|
17523
|
+
if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
|
|
17524
|
+
throw Error("Account is not compatible with SNIP-9");
|
|
17525
|
+
}
|
|
17526
|
+
}
|
|
17527
|
+
const parameters = {
|
|
17528
|
+
version: "0x1",
|
|
17529
|
+
feeMode: paymasterDetails.feeMode,
|
|
17530
|
+
timeBounds: paymasterDetails.timeBounds
|
|
17531
|
+
};
|
|
17532
|
+
let transaction;
|
|
17533
|
+
if (paymasterDetails.deploymentData) {
|
|
17534
|
+
if (calls.length > 0) {
|
|
17535
|
+
transaction = {
|
|
17536
|
+
type: "deploy_and_invoke",
|
|
17537
|
+
invoke: { userAddress: account.address, calls },
|
|
17538
|
+
deployment: paymasterDetails.deploymentData
|
|
17539
|
+
};
|
|
17540
|
+
} else {
|
|
17541
|
+
transaction = {
|
|
17542
|
+
type: "deploy",
|
|
17543
|
+
deployment: paymasterDetails.deploymentData
|
|
17544
|
+
};
|
|
17545
|
+
}
|
|
17546
|
+
} else {
|
|
17547
|
+
transaction = {
|
|
17548
|
+
type: "invoke",
|
|
17549
|
+
invoke: { userAddress: account.address, calls }
|
|
17550
|
+
};
|
|
17551
|
+
}
|
|
17552
|
+
return account.paymaster.buildTransaction(transaction, parameters);
|
|
17553
|
+
}
|
|
17554
|
+
/**
|
|
17555
|
+
* Asks the paymaster for the fees of the calls of an account.
|
|
17556
|
+
* @param {Account} account The account that will sign the transaction.
|
|
17557
|
+
* @param {Call[]} calls The calls to execute.
|
|
17558
|
+
* @param {PaymasterDetails} paymasterDetails The fee mode, and optionally the deployment data
|
|
17559
|
+
* and the time bounds.
|
|
17560
|
+
* @returns {Promise<PaymasterFeeEstimate>} The fees, in STRK and in the gas token.
|
|
17561
|
+
* @example
|
|
17562
|
+
* ```typescript
|
|
17563
|
+
* const fees = await PaymasterImpl.estimate(myAccount, [myCall], {
|
|
17564
|
+
* feeMode: { mode: 'default', gasToken: usdcAddress },
|
|
17565
|
+
* });
|
|
17566
|
+
* // fees.suggested_max_fee_in_gas_token is the fee to show to the user
|
|
17567
|
+
* ```
|
|
17568
|
+
*/
|
|
17569
|
+
static async estimate(account, calls, paymasterDetails) {
|
|
17570
|
+
const preparedTransaction = await account.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17571
|
+
return preparedTransaction.fee;
|
|
17572
|
+
}
|
|
17573
|
+
/**
|
|
17574
|
+
* Checks that a transaction prepared by the paymaster is safe to sign, then signs it.
|
|
17575
|
+
* @param {Account} account The account that signs the transaction.
|
|
17576
|
+
* @param {PreparedTransaction} preparedTransaction The transaction returned by the paymaster.
|
|
17577
|
+
* @param {Call[]} calls The calls the user requested.
|
|
17578
|
+
* @param {PaymasterDetails} paymasterDetails The fee mode and related paymaster details.
|
|
17579
|
+
* @param {BigNumberish} [maxFeeInGasToken] Optional user-approved ceiling on the gas-token fee.
|
|
17580
|
+
* @returns {Promise<ExecutableUserTransaction>} The transaction to send to the paymaster.
|
|
17581
|
+
* @example
|
|
17582
|
+
* ```typescript
|
|
17583
|
+
* const prepared = await PaymasterImpl.build(myAccount, [myCall], paymasterDetails);
|
|
17584
|
+
* const executable = await PaymasterImpl.prepare(myAccount, prepared, [myCall], paymasterDetails);
|
|
17585
|
+
* // executable.type = 'invoke'
|
|
17586
|
+
* ```
|
|
17587
|
+
*/
|
|
17588
|
+
static async prepare(account, preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) {
|
|
17589
|
+
assertPaymasterTransactionSafety(
|
|
17590
|
+
preparedTransaction,
|
|
17591
|
+
calls,
|
|
17592
|
+
paymasterDetails,
|
|
17593
|
+
await account.provider.getChainId(),
|
|
17594
|
+
maxFeeInGasToken
|
|
17595
|
+
);
|
|
17596
|
+
let transaction;
|
|
17597
|
+
switch (preparedTransaction.type) {
|
|
17598
|
+
case "deploy_and_invoke": {
|
|
17599
|
+
const signature = await account.signMessage(preparedTransaction.typed_data);
|
|
17600
|
+
transaction = {
|
|
17601
|
+
type: "deploy_and_invoke",
|
|
17602
|
+
invoke: {
|
|
17603
|
+
userAddress: account.address,
|
|
17604
|
+
typedData: preparedTransaction.typed_data,
|
|
17605
|
+
signature: signatureToHexArray(signature)
|
|
17606
|
+
},
|
|
17607
|
+
deployment: preparedTransaction.deployment
|
|
17608
|
+
};
|
|
17609
|
+
break;
|
|
17610
|
+
}
|
|
17611
|
+
case "invoke": {
|
|
17612
|
+
const signature = await account.signMessage(preparedTransaction.typed_data);
|
|
17613
|
+
transaction = {
|
|
17614
|
+
type: "invoke",
|
|
17615
|
+
invoke: {
|
|
17616
|
+
userAddress: account.address,
|
|
17617
|
+
typedData: preparedTransaction.typed_data,
|
|
17618
|
+
signature: signatureToHexArray(signature)
|
|
17619
|
+
}
|
|
17620
|
+
};
|
|
17621
|
+
break;
|
|
17622
|
+
}
|
|
17623
|
+
case "deploy": {
|
|
17624
|
+
transaction = {
|
|
17625
|
+
type: "deploy",
|
|
17626
|
+
deployment: preparedTransaction.deployment
|
|
17627
|
+
};
|
|
17628
|
+
break;
|
|
17629
|
+
}
|
|
17630
|
+
default:
|
|
17631
|
+
throw Error("Invalid transaction type");
|
|
17632
|
+
}
|
|
17633
|
+
return transaction;
|
|
17634
|
+
}
|
|
17635
|
+
/**
|
|
17636
|
+
* Builds, checks, signs and sends a paymaster transaction for the calls of an account.
|
|
17637
|
+
* @param {Account} account The account that signs the transaction.
|
|
17638
|
+
* @param {Call[]} calls The calls to execute.
|
|
17639
|
+
* @param {PaymasterDetails} paymasterDetails The fee mode, and optionally the deployment data
|
|
17640
|
+
* and the time bounds.
|
|
17641
|
+
* @param {BigNumberish} [maxFeeInGasToken] Optional user-approved ceiling on the gas-token fee.
|
|
17642
|
+
* @returns {Promise<InvokeFunctionResponse>} The hash of the transaction sent by the paymaster.
|
|
17643
|
+
* @example
|
|
17644
|
+
* ```typescript
|
|
17645
|
+
* const { transaction_hash } = await PaymasterImpl.execute(myAccount, [myCall], {
|
|
17646
|
+
* feeMode: { mode: 'sponsored' },
|
|
17647
|
+
* });
|
|
17648
|
+
* await myAccount.provider.waitForTransaction(transaction_hash);
|
|
17649
|
+
* ```
|
|
17650
|
+
*/
|
|
17651
|
+
static async execute(account, calls, paymasterDetails, maxFeeInGasToken) {
|
|
17652
|
+
const preparedTransaction = await account.buildPaymasterTransaction(calls, paymasterDetails);
|
|
17653
|
+
const transaction = await account.preparePaymasterTransaction(
|
|
17654
|
+
preparedTransaction,
|
|
17655
|
+
calls,
|
|
17656
|
+
paymasterDetails,
|
|
17657
|
+
maxFeeInGasToken
|
|
17658
|
+
);
|
|
17659
|
+
return account.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
|
|
17660
|
+
}
|
|
17661
|
+
};
|
|
17662
|
+
|
|
17663
|
+
// src/plugins/paymaster/rpc.ts
|
|
17664
|
+
var convertCalls = (calls) => calls.map((call) => ({
|
|
17665
|
+
to: call.contractAddress,
|
|
17666
|
+
selector: getSelectorFromName(call.entrypoint),
|
|
17667
|
+
calldata: CallData.toHex(call.calldata)
|
|
17668
|
+
}));
|
|
17669
|
+
var convertFeeMode = (feeMode) => {
|
|
17670
|
+
if (feeMode.mode === "sponsored") {
|
|
17671
|
+
return { mode: "sponsored" };
|
|
17672
|
+
}
|
|
17673
|
+
return { mode: "default", gas_token: feeMode.gasToken };
|
|
17674
|
+
};
|
|
17675
|
+
var convertFEE_MODE = (feeMode) => {
|
|
17676
|
+
if (feeMode.mode === "sponsored") {
|
|
17677
|
+
return { mode: "sponsored" };
|
|
17678
|
+
}
|
|
17679
|
+
return { mode: "default", gasToken: feeMode.gas_token };
|
|
17680
|
+
};
|
|
17681
|
+
var convertTimeBounds = (timeBounds) => timeBounds ? {
|
|
17682
|
+
execute_after: timeBounds.executeAfter || 1,
|
|
17683
|
+
// If executeAfter is not provided, set it to 1, meaning the transaction can be executed immediately
|
|
17684
|
+
execute_before: timeBounds.executeBefore
|
|
17685
|
+
} : void 0;
|
|
17686
|
+
var convertTIME_BOUNDS = (timeBounds) => timeBounds ? {
|
|
17687
|
+
executeAfter: timeBounds.execute_after,
|
|
17688
|
+
executeBefore: timeBounds.execute_before
|
|
17689
|
+
} : void 0;
|
|
17690
|
+
var convertEXECUTION_PARAMETERS = (parameters) => ({
|
|
17691
|
+
version: parameters.version,
|
|
17692
|
+
feeMode: convertFEE_MODE(parameters.fee_mode),
|
|
17693
|
+
timeBounds: convertTIME_BOUNDS(parameters.time_bounds)
|
|
17694
|
+
});
|
|
17695
|
+
var defaultOptions = {
|
|
17696
|
+
headers: { "Content-Type": "application/json" }
|
|
17697
|
+
};
|
|
17698
|
+
var PaymasterRpc = class _PaymasterRpc {
|
|
17699
|
+
nodeUrl;
|
|
17700
|
+
headers;
|
|
17701
|
+
baseFetch;
|
|
17702
|
+
requestId;
|
|
17703
|
+
constructor(options) {
|
|
17704
|
+
if (options instanceof _PaymasterRpc) {
|
|
17705
|
+
this.nodeUrl = options.nodeUrl;
|
|
17706
|
+
this.headers = { ...defaultOptions.headers, ...options.headers };
|
|
17707
|
+
this.baseFetch = options.baseFetch;
|
|
17708
|
+
this.requestId = options.requestId;
|
|
17709
|
+
return;
|
|
17710
|
+
}
|
|
17711
|
+
if (options && "nodeUrl" in options && "headers" in options && "baseFetch" in options) {
|
|
17712
|
+
this.nodeUrl = options.nodeUrl ?? getDefaultPaymasterNodeUrl(void 0);
|
|
17713
|
+
this.headers = { ...defaultOptions.headers, ...options.headers };
|
|
17714
|
+
this.baseFetch = options.baseFetch ?? fetch_default;
|
|
17715
|
+
this.requestId = 0;
|
|
17716
|
+
return;
|
|
17717
|
+
}
|
|
17718
|
+
const { nodeUrl, headers, baseFetch } = options || {};
|
|
17719
|
+
if (nodeUrl && Object.values(_NetworkName).includes(nodeUrl)) {
|
|
17720
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(nodeUrl, options?.mute);
|
|
17721
|
+
} else if (nodeUrl) {
|
|
17722
|
+
this.nodeUrl = nodeUrl;
|
|
17723
|
+
} else {
|
|
17724
|
+
this.nodeUrl = getDefaultPaymasterNodeUrl(void 0, options?.mute);
|
|
17725
|
+
}
|
|
17726
|
+
this.baseFetch = baseFetch ?? fetch_default;
|
|
17727
|
+
this.headers = { ...defaultOptions.headers, ...headers };
|
|
17728
|
+
this.requestId = 0;
|
|
17729
|
+
}
|
|
17730
|
+
fetch(method, params, id = 0) {
|
|
17731
|
+
const rpcRequestBody = {
|
|
17732
|
+
id,
|
|
17733
|
+
jsonrpc: "2.0",
|
|
17734
|
+
method,
|
|
17735
|
+
...params && { params }
|
|
17736
|
+
};
|
|
17737
|
+
return this.baseFetch(this.nodeUrl, {
|
|
17738
|
+
method: "POST",
|
|
17739
|
+
body: stringify2(rpcRequestBody),
|
|
17740
|
+
headers: this.headers
|
|
17741
|
+
});
|
|
17742
|
+
}
|
|
17743
|
+
errorHandler(method, params, rpcError, otherError) {
|
|
17744
|
+
if (rpcError) {
|
|
17745
|
+
throw new RpcError(rpcError, method, params);
|
|
17746
|
+
}
|
|
17747
|
+
if (otherError instanceof LibraryError) {
|
|
17748
|
+
throw otherError;
|
|
17749
|
+
}
|
|
17750
|
+
if (otherError) {
|
|
17751
|
+
throw Error(otherError.message);
|
|
17752
|
+
}
|
|
17753
|
+
}
|
|
17754
|
+
async fetchEndpoint(method, params) {
|
|
17755
|
+
try {
|
|
17756
|
+
this.requestId += 1;
|
|
17757
|
+
const rawResult = await this.fetch(method, params, this.requestId);
|
|
17758
|
+
const { error, result } = await rawResult.json();
|
|
17759
|
+
this.errorHandler(method, params, error);
|
|
17760
|
+
return result;
|
|
17761
|
+
} catch (error) {
|
|
17762
|
+
this.errorHandler(method, params, error?.response?.data, error);
|
|
17763
|
+
throw error;
|
|
17764
|
+
}
|
|
17765
|
+
}
|
|
17766
|
+
async isAvailable() {
|
|
17767
|
+
return this.fetchEndpoint("paymaster_isAvailable");
|
|
17768
|
+
}
|
|
17769
|
+
async buildTransaction(transaction, parameters) {
|
|
17770
|
+
let userTransaction;
|
|
17771
|
+
switch (transaction.type) {
|
|
17772
|
+
case "invoke":
|
|
17773
|
+
userTransaction = {
|
|
17774
|
+
...transaction,
|
|
17775
|
+
invoke: {
|
|
17776
|
+
user_address: transaction.invoke.userAddress,
|
|
17777
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17778
|
+
}
|
|
17779
|
+
};
|
|
17780
|
+
break;
|
|
17781
|
+
case "deploy_and_invoke":
|
|
17782
|
+
userTransaction = {
|
|
17783
|
+
...transaction,
|
|
17784
|
+
invoke: {
|
|
17785
|
+
user_address: transaction.invoke.userAddress,
|
|
17786
|
+
calls: convertCalls(transaction.invoke.calls)
|
|
17787
|
+
}
|
|
17788
|
+
};
|
|
17789
|
+
break;
|
|
17790
|
+
case "deploy":
|
|
17791
|
+
default:
|
|
17792
|
+
userTransaction = transaction;
|
|
17793
|
+
break;
|
|
17794
|
+
}
|
|
17795
|
+
const executionParameters = {
|
|
17796
|
+
version: parameters.version,
|
|
17797
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17798
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17799
|
+
};
|
|
17800
|
+
const response = await this.fetchEndpoint("paymaster_buildTransaction", {
|
|
17801
|
+
transaction: userTransaction,
|
|
17802
|
+
parameters: executionParameters
|
|
17803
|
+
});
|
|
17804
|
+
const fee = {
|
|
17805
|
+
gas_token_price_in_strk: BigInt(response.fee.gas_token_price_in_strk),
|
|
17806
|
+
estimated_fee_in_strk: BigInt(response.fee.estimated_fee_in_strk),
|
|
17807
|
+
estimated_fee_in_gas_token: BigInt(response.fee.estimated_fee_in_gas_token),
|
|
17808
|
+
suggested_max_fee_in_strk: BigInt(response.fee.suggested_max_fee_in_strk),
|
|
17809
|
+
suggested_max_fee_in_gas_token: BigInt(response.fee.suggested_max_fee_in_gas_token)
|
|
17810
|
+
};
|
|
17811
|
+
switch (response.type) {
|
|
17812
|
+
case "invoke":
|
|
17813
|
+
return {
|
|
17814
|
+
type: "invoke",
|
|
17815
|
+
typed_data: response.typed_data,
|
|
17816
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17817
|
+
fee
|
|
17818
|
+
};
|
|
17819
|
+
case "deploy_and_invoke":
|
|
17820
|
+
return {
|
|
17821
|
+
type: "deploy_and_invoke",
|
|
17822
|
+
deployment: response.deployment,
|
|
17823
|
+
typed_data: response.typed_data,
|
|
17824
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17825
|
+
fee
|
|
17826
|
+
};
|
|
17827
|
+
case "deploy":
|
|
17828
|
+
default:
|
|
17829
|
+
return {
|
|
17830
|
+
type: "deploy",
|
|
17831
|
+
deployment: response.deployment,
|
|
17832
|
+
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
17833
|
+
fee
|
|
17834
|
+
};
|
|
17835
|
+
}
|
|
17836
|
+
}
|
|
17837
|
+
async executeTransaction(transaction, parameters) {
|
|
17838
|
+
let user_transaction;
|
|
17839
|
+
switch (transaction.type) {
|
|
17840
|
+
case "invoke":
|
|
17841
|
+
user_transaction = {
|
|
17842
|
+
...transaction,
|
|
17843
|
+
invoke: {
|
|
17844
|
+
user_address: transaction.invoke.userAddress,
|
|
17845
|
+
typed_data: transaction.invoke.typedData,
|
|
17846
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17847
|
+
}
|
|
17848
|
+
};
|
|
17849
|
+
break;
|
|
17850
|
+
case "deploy_and_invoke":
|
|
17851
|
+
user_transaction = {
|
|
17852
|
+
...transaction,
|
|
17853
|
+
invoke: {
|
|
17854
|
+
user_address: transaction.invoke.userAddress,
|
|
17855
|
+
typed_data: transaction.invoke.typedData,
|
|
17856
|
+
signature: signatureToHexArray(transaction.invoke.signature)
|
|
17857
|
+
}
|
|
17858
|
+
};
|
|
17859
|
+
break;
|
|
17860
|
+
case "deploy":
|
|
17861
|
+
default:
|
|
17862
|
+
user_transaction = transaction;
|
|
17863
|
+
break;
|
|
17864
|
+
}
|
|
17865
|
+
const executionParameters = {
|
|
17866
|
+
version: parameters.version,
|
|
17867
|
+
fee_mode: convertFeeMode(parameters.feeMode),
|
|
17868
|
+
time_bounds: convertTimeBounds(parameters.timeBounds)
|
|
17869
|
+
};
|
|
17870
|
+
return this.fetchEndpoint("paymaster_executeTransaction", {
|
|
17871
|
+
transaction: user_transaction,
|
|
17872
|
+
parameters: executionParameters
|
|
17873
|
+
});
|
|
17874
|
+
}
|
|
17875
|
+
async getSupportedTokens() {
|
|
17876
|
+
return this.fetchEndpoint("paymaster_getSupportedTokens").then(
|
|
17877
|
+
(tokens) => tokens.map((token) => ({
|
|
17878
|
+
token_address: token.token_address,
|
|
17879
|
+
decimals: token.decimals,
|
|
17880
|
+
priceInStrk: BigInt(token.price_in_strk)
|
|
17881
|
+
}))
|
|
17882
|
+
);
|
|
17883
|
+
}
|
|
17884
|
+
};
|
|
17885
|
+
|
|
17886
|
+
// src/plugins/paymaster/interface.ts
|
|
17887
|
+
var PaymasterInterface = class {
|
|
17888
|
+
};
|
|
17889
|
+
|
|
17890
|
+
// src/plugins/paymaster/index.ts
|
|
17891
|
+
var PAYMASTER_PLUGIN_NAME = "paymaster";
|
|
17892
|
+
function paymasterPlugin(options) {
|
|
17893
|
+
return {
|
|
17894
|
+
name: PAYMASTER_PLUGIN_NAME,
|
|
17895
|
+
accountExtend(account) {
|
|
17896
|
+
const target = account;
|
|
17897
|
+
const members = {
|
|
17898
|
+
paymaster: options ? new PaymasterRpc(options) : new PaymasterRpc({ mute: true }),
|
|
17899
|
+
buildPaymasterTransaction: (calls, paymasterDetails) => PaymasterImpl.build(target, calls, paymasterDetails),
|
|
17900
|
+
estimatePaymasterTransactionFee: (calls, paymasterDetails) => PaymasterImpl.estimate(target, calls, paymasterDetails),
|
|
17901
|
+
preparePaymasterTransaction: (preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) => PaymasterImpl.prepare(
|
|
17902
|
+
target,
|
|
17903
|
+
preparedTransaction,
|
|
17904
|
+
calls,
|
|
17905
|
+
paymasterDetails,
|
|
17906
|
+
maxFeeInGasToken
|
|
17907
|
+
),
|
|
17908
|
+
executePaymasterTransaction: (calls, paymasterDetails, maxFeeInGasToken) => PaymasterImpl.execute(target, calls, paymasterDetails, maxFeeInGasToken)
|
|
17909
|
+
};
|
|
17910
|
+
return Object.fromEntries(
|
|
17911
|
+
Object.entries(members).filter(([name]) => !(name in account))
|
|
17912
|
+
);
|
|
17913
|
+
}
|
|
17914
|
+
};
|
|
17915
|
+
}
|
|
17916
|
+
function applyPaymasterOption(plugins, paymaster) {
|
|
17917
|
+
if (!paymaster) return plugins;
|
|
17918
|
+
const configured = paymasterPlugin(paymaster);
|
|
17919
|
+
return plugins.some((plugin) => plugin.name === PAYMASTER_PLUGIN_NAME) ? plugins.map((plugin) => plugin.name === PAYMASTER_PLUGIN_NAME ? configured : plugin) : [...plugins, configured];
|
|
17920
|
+
}
|
|
17921
|
+
|
|
17213
17922
|
// src/plugins/defaults.ts
|
|
17214
17923
|
var defaultPlugins = [
|
|
17215
17924
|
starknetId(),
|
|
17216
17925
|
brotherId(),
|
|
17217
|
-
fastExecute()
|
|
17926
|
+
fastExecute(),
|
|
17927
|
+
paymasterPlugin()
|
|
17218
17928
|
];
|
|
17219
17929
|
|
|
17220
17930
|
// src/provider/rpc.ts
|
|
@@ -17774,38 +18484,19 @@ var Signer = class {
|
|
|
17774
18484
|
async signDeclareTransaction(details) {
|
|
17775
18485
|
const msgHash = calculateDeclareTransactionHash2({
|
|
17776
18486
|
...details,
|
|
17777
|
-
version: details.version,
|
|
17778
|
-
nonceDataAvailabilityMode: intDAM(details.nonceDataAvailabilityMode),
|
|
17779
|
-
feeDataAvailabilityMode: intDAM(details.feeDataAvailabilityMode)
|
|
17780
|
-
});
|
|
17781
|
-
return this.signRaw(msgHash);
|
|
17782
|
-
}
|
|
17783
|
-
async signRaw(msgHash) {
|
|
17784
|
-
return starkCurve.sign(msgHash, this.pk);
|
|
17785
|
-
}
|
|
17786
|
-
};
|
|
17787
|
-
|
|
17788
|
-
// src/signer/ethSigner.ts
|
|
17789
|
-
var import_secp256k12 = require("@noble/curves/secp256k1.js");
|
|
17790
|
-
|
|
17791
|
-
// src/utils/uint256.ts
|
|
17792
|
-
var uint256_exports = {};
|
|
17793
|
-
__export(uint256_exports, {
|
|
17794
|
-
bnToUint256: () => bnToUint256,
|
|
17795
|
-
isUint256: () => isUint256,
|
|
17796
|
-
uint256ToBN: () => uint256ToBN
|
|
17797
|
-
});
|
|
17798
|
-
function uint256ToBN(uint2562) {
|
|
17799
|
-
return new CairoUint256(uint2562).toBigInt();
|
|
17800
|
-
}
|
|
17801
|
-
function isUint256(bn) {
|
|
17802
|
-
return CairoUint256.is(bn);
|
|
17803
|
-
}
|
|
17804
|
-
function bnToUint256(bn) {
|
|
17805
|
-
return new CairoUint256(bn).toUint256HexString();
|
|
17806
|
-
}
|
|
18487
|
+
version: details.version,
|
|
18488
|
+
nonceDataAvailabilityMode: intDAM(details.nonceDataAvailabilityMode),
|
|
18489
|
+
feeDataAvailabilityMode: intDAM(details.feeDataAvailabilityMode)
|
|
18490
|
+
});
|
|
18491
|
+
return this.signRaw(msgHash);
|
|
18492
|
+
}
|
|
18493
|
+
async signRaw(msgHash) {
|
|
18494
|
+
return starkCurve.sign(msgHash, this.pk);
|
|
18495
|
+
}
|
|
18496
|
+
};
|
|
17807
18497
|
|
|
17808
18498
|
// src/signer/ethSigner.ts
|
|
18499
|
+
var import_secp256k12 = require("@noble/curves/secp256k1.js");
|
|
17809
18500
|
var EthSigner = class {
|
|
17810
18501
|
pk;
|
|
17811
18502
|
// hex string without 0x and with an odd number of characters
|
|
@@ -18147,7 +18838,7 @@ function getLedgerPathBuffer111(accountId, applicationName = "LedgerW") {
|
|
|
18147
18838
|
}
|
|
18148
18839
|
|
|
18149
18840
|
// src/utils/address.ts
|
|
18150
|
-
var
|
|
18841
|
+
var import_utils7 = require("@noble/curves/utils.js");
|
|
18151
18842
|
function addAddressPadding(address) {
|
|
18152
18843
|
const hex = toHex(isString(address) ? addHexPrefix(address) : address);
|
|
18153
18844
|
const padded = removeHexPrefix(hex).padStart(64, "0");
|
|
@@ -18167,7 +18858,7 @@ function validateAndParseAddress(address) {
|
|
|
18167
18858
|
function getChecksumAddress(address) {
|
|
18168
18859
|
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
18169
18860
|
const hex = removeHexPrefix(keccakBn(address));
|
|
18170
|
-
const hashed = (0,
|
|
18861
|
+
const hashed = (0, import_utils7.hexToBytes)(hex.padStart(64, "0"));
|
|
18171
18862
|
for (let i = 0; i < chars.length; i += 2) {
|
|
18172
18863
|
if (hashed[i >> 1] >> 4 >= 8) {
|
|
18173
18864
|
chars[i] = chars[i].toUpperCase();
|
|
@@ -18313,254 +19004,28 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
18313
19004
|
return { hash: h, signature: sign1 };
|
|
18314
19005
|
}
|
|
18315
19006
|
/** Internal function to convert a Call to an array of Uint8Array.
|
|
18316
|
-
* @param {Call} call A Call to convert.
|
|
18317
|
-
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
18318
|
-
*/
|
|
18319
|
-
encodeCall(call) {
|
|
18320
|
-
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
18321
|
-
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
18322
|
-
let calldataBuf = new Uint8Array([]);
|
|
18323
|
-
if (call.calldata) {
|
|
18324
|
-
const compiledCalldata = CallData.compile(call.calldata);
|
|
18325
|
-
calldataBuf = concatenateArrayBuffer(
|
|
18326
|
-
compiledCalldata.map((parameter) => {
|
|
18327
|
-
const a = this.convertBnToLedger(parameter);
|
|
18328
|
-
return a;
|
|
18329
|
-
})
|
|
18330
|
-
);
|
|
18331
|
-
}
|
|
18332
|
-
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
18333
|
-
const calldatas = [];
|
|
18334
|
-
const chunkSize = 7 * 32;
|
|
18335
|
-
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
18336
|
-
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
18337
|
-
return calldatas;
|
|
18338
|
-
}
|
|
18339
|
-
/**
|
|
18340
|
-
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
18341
|
-
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
18342
|
-
* @param {Call[]} calls array of Starknet invocations
|
|
18343
|
-
* @returns an object including the transaction Hash and the signature
|
|
18344
|
-
* @example
|
|
18345
|
-
* ```typescript
|
|
18346
|
-
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
18347
|
-
* entrypoint: "transfer",
|
|
18348
|
-
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
18349
|
-
* "0x9184e72a000", "0x0"]}];
|
|
18350
|
-
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
18351
|
-
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
18352
|
-
* nonce: "28", accountDeploymentData: [],
|
|
18353
|
-
* paymasterData: [], cairoVersion: "1",
|
|
18354
|
-
* feeDataAvailabilityMode: "L1", nonceDataAvailabilityMode: "L1",
|
|
18355
|
-
* resourceBounds: {
|
|
18356
|
-
* l1_gas: { max_amount: "0x2a00", max_price_per_unit: "0x5c00000"
|
|
18357
|
-
* },
|
|
18358
|
-
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
18359
|
-
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
18360
|
-
* };
|
|
18361
|
-
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
18362
|
-
* // res = {hash:
|
|
18363
|
-
* // signature:
|
|
18364
|
-
* // }
|
|
18365
|
-
* ```
|
|
18366
|
-
*/
|
|
18367
|
-
async signTxV3(txDetails, calls) {
|
|
18368
|
-
assert(txDetails.paymasterData.length <= 7, "Paymaster data includes more than 7 items.");
|
|
18369
|
-
assert(
|
|
18370
|
-
txDetails.accountDeploymentData.length <= 7,
|
|
18371
|
-
"accountDeploymentData includes more than 7 items"
|
|
18372
|
-
);
|
|
18373
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
18374
|
-
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
18375
|
-
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
18376
|
-
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
18377
|
-
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
18378
|
-
const dAModeHashBuf = this.convertBnToLedger(
|
|
18379
|
-
hashDAMode(
|
|
18380
|
-
txDetails.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
18381
|
-
txDetails.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
18382
|
-
)
|
|
18383
|
-
);
|
|
18384
|
-
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
18385
|
-
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
18386
|
-
const dataBuf = concatenateArrayBuffer([
|
|
18387
|
-
accountAddressBuf,
|
|
18388
|
-
tipBuf,
|
|
18389
|
-
l1_gasBuf,
|
|
18390
|
-
l2_gasBuf,
|
|
18391
|
-
chainIdBuf,
|
|
18392
|
-
nonceBuf,
|
|
18393
|
-
dAModeHashBuf
|
|
18394
|
-
]);
|
|
18395
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
18396
|
-
const paymasterBuf = concatenateArrayBuffer(
|
|
18397
|
-
txDetails.paymasterData.map((value) => {
|
|
18398
|
-
const a = this.convertBnToLedger(value);
|
|
18399
|
-
return a;
|
|
18400
|
-
})
|
|
18401
|
-
);
|
|
18402
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
|
|
18403
|
-
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
18404
|
-
txDetails.paymasterData.map((value) => {
|
|
18405
|
-
const a = this.convertBnToLedger(value);
|
|
18406
|
-
return a;
|
|
18407
|
-
})
|
|
18408
|
-
);
|
|
18409
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
|
|
18410
|
-
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
18411
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
|
|
18412
|
-
let respSign = new Uint8Array(0);
|
|
18413
|
-
for (const call of calls) {
|
|
18414
|
-
const calldatas = this.encodeCall(call);
|
|
18415
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
|
|
18416
|
-
if (calldatas.length > 1) {
|
|
18417
|
-
calldatas.slice(1).forEach(async (part) => {
|
|
18418
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
|
|
18419
|
-
});
|
|
18420
|
-
}
|
|
18421
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
18422
|
-
}
|
|
18423
|
-
return this.decodeSignatureLedger(respSign);
|
|
18424
|
-
}
|
|
18425
|
-
/**
|
|
18426
|
-
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
18427
|
-
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
18428
|
-
* @returns an object including the transaction Hash and the signature
|
|
18429
|
-
* @example
|
|
18430
|
-
* ```typescript
|
|
18431
|
-
* const deployData: V3DeployAccountSignerDetails =
|
|
18432
|
-
* {
|
|
18433
|
-
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
18434
|
-
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
18435
|
-
* resourceBounds: {
|
|
18436
|
-
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
18437
|
-
* l1_gas: { max_amount: '0x226', max_price_per_unit: '0x22ecb25c00' }
|
|
18438
|
-
* },
|
|
18439
|
-
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
18440
|
-
* constructorCalldata: [
|
|
18441
|
-
* '3571125127744830445572285574469842579401255431821644822726857471463672199621'
|
|
18442
|
-
* ],
|
|
18443
|
-
* contractAddress: '0x4ca062add1cf12a107be1107af17981cf6e544a24d987693230ea481d3d5e34',
|
|
18444
|
-
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
18445
|
-
* chainId: '0x534e5f5345504f4c4941',
|
|
18446
|
-
* version: '0x3', nonce: 0n
|
|
18447
|
-
*}
|
|
18448
|
-
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
18449
|
-
* // res = {hash:
|
|
18450
|
-
* // signature:
|
|
18451
|
-
* // }
|
|
18452
|
-
* ```
|
|
18453
|
-
*/
|
|
18454
|
-
async signDeployAccountV3(deployAccountDetail) {
|
|
18455
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
18456
|
-
const accountAddressBuf = this.convertBnToLedger(
|
|
18457
|
-
deployAccountDetail.contractAddress
|
|
18458
|
-
);
|
|
18459
|
-
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
18460
|
-
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
18461
|
-
const dAModeHashBuf = this.convertBnToLedger(
|
|
18462
|
-
hashDAMode(
|
|
18463
|
-
deployAccountDetail.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
18464
|
-
deployAccountDetail.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
18465
|
-
)
|
|
18466
|
-
);
|
|
18467
|
-
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
18468
|
-
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
18469
|
-
const dataBuf = concatenateArrayBuffer([
|
|
18470
|
-
accountAddressBuf,
|
|
18471
|
-
chainIdBuf,
|
|
18472
|
-
nonceBuf,
|
|
18473
|
-
dAModeHashBuf,
|
|
18474
|
-
classHashBuf,
|
|
18475
|
-
saltBuf
|
|
18476
|
-
]);
|
|
18477
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
18478
|
-
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
18479
|
-
const l1_gasBuf = this.convertBnToLedger(
|
|
18480
|
-
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
18481
|
-
);
|
|
18482
|
-
const l2_gasBuf = this.convertBnToLedger(
|
|
18483
|
-
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
18484
|
-
);
|
|
18485
|
-
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
18486
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
18487
|
-
const paymasterBuf = concatenateArrayBuffer(
|
|
18488
|
-
deployAccountDetail.paymasterData.map((value) => {
|
|
18489
|
-
const a = this.convertBnToLedger(value);
|
|
18490
|
-
return a;
|
|
18491
|
-
})
|
|
18492
|
-
);
|
|
18493
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
18494
|
-
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
18495
|
-
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
18496
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
18497
|
-
const constructorBuf = concatenateArrayBuffer(
|
|
18498
|
-
compiledConstructor.map((parameter) => {
|
|
18499
|
-
const a = this.convertBnToLedger(parameter);
|
|
18500
|
-
return a;
|
|
18501
|
-
})
|
|
18502
|
-
);
|
|
18503
|
-
const constructorChunks = [];
|
|
18504
|
-
const chunkSize = 7 * 32;
|
|
18505
|
-
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
18506
|
-
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
18507
|
-
let respSign = new Uint8Array(0);
|
|
18508
|
-
for (const chunk of constructorChunks) {
|
|
18509
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
18510
|
-
}
|
|
18511
|
-
return this.decodeSignatureLedger(respSign);
|
|
18512
|
-
}
|
|
18513
|
-
};
|
|
18514
|
-
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
18515
|
-
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
18516
|
-
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
18517
|
-
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
18518
|
-
const path2buff = concatenateArrayBuffer([
|
|
18519
|
-
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
18520
|
-
path2Base.subarray(1)
|
|
18521
|
-
]);
|
|
18522
|
-
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
18523
|
-
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
18524
|
-
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
18525
|
-
const path4buff = hexToBytes(padded);
|
|
18526
|
-
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
18527
|
-
const pathBuff = concatenateArrayBuffer([
|
|
18528
|
-
path0buff,
|
|
18529
|
-
path1buff,
|
|
18530
|
-
path2buff,
|
|
18531
|
-
path3buff,
|
|
18532
|
-
path4buff,
|
|
18533
|
-
path5buff
|
|
18534
|
-
]);
|
|
18535
|
-
return pathBuff;
|
|
18536
|
-
}
|
|
18537
|
-
|
|
18538
|
-
// src/signer/ledgerSigner231.ts
|
|
18539
|
-
var LedgerSigner231 = class extends LedgerSigner221 {
|
|
18540
|
-
/**
|
|
18541
|
-
* constructor of the LedgerSigner class.
|
|
18542
|
-
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
18543
|
-
* See Guides for more details.
|
|
18544
|
-
* @param {number} accountID ID of Ledger Nano account (can handle 2**31 accounts).
|
|
18545
|
-
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
18546
|
-
* One item is called `application` and can be customized.
|
|
18547
|
-
* Default value is `LedgerW`.
|
|
18548
|
-
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
18549
|
-
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
18550
|
-
*
|
|
18551
|
-
* If you are using APP v2.3.1 with an account created with the v1.1.1, you need to use :
|
|
18552
|
-
* ```typescript
|
|
18553
|
-
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
18554
|
-
* ```
|
|
18555
|
-
* @example
|
|
18556
|
-
* ```typescript
|
|
18557
|
-
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
18558
|
-
* const myNodeTransport = await TransportNodeHid.create();
|
|
18559
|
-
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0);
|
|
18560
|
-
* ```
|
|
19007
|
+
* @param {Call} call A Call to convert.
|
|
19008
|
+
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
18561
19009
|
*/
|
|
18562
|
-
|
|
18563
|
-
|
|
19010
|
+
encodeCall(call) {
|
|
19011
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
19012
|
+
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
19013
|
+
let calldataBuf = new Uint8Array([]);
|
|
19014
|
+
if (call.calldata) {
|
|
19015
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
19016
|
+
calldataBuf = concatenateArrayBuffer(
|
|
19017
|
+
compiledCalldata.map((parameter) => {
|
|
19018
|
+
const a = this.convertBnToLedger(parameter);
|
|
19019
|
+
return a;
|
|
19020
|
+
})
|
|
19021
|
+
);
|
|
19022
|
+
}
|
|
19023
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
19024
|
+
const calldatas = [];
|
|
19025
|
+
const chunkSize = 7 * 32;
|
|
19026
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
19027
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
19028
|
+
return calldatas;
|
|
18564
19029
|
}
|
|
18565
19030
|
/**
|
|
18566
19031
|
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
@@ -18598,61 +19063,53 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
18598
19063
|
);
|
|
18599
19064
|
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
18600
19065
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
19066
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
18601
19067
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
18602
19068
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
18603
19069
|
const dAModeHashBuf = this.convertBnToLedger(
|
|
18604
19070
|
hashDAMode(
|
|
18605
|
-
|
|
18606
|
-
|
|
19071
|
+
txDetails.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
19072
|
+
txDetails.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
18607
19073
|
)
|
|
18608
19074
|
);
|
|
19075
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
19076
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
18609
19077
|
const dataBuf = concatenateArrayBuffer([
|
|
18610
19078
|
accountAddressBuf,
|
|
19079
|
+
tipBuf,
|
|
19080
|
+
l1_gasBuf,
|
|
19081
|
+
l2_gasBuf,
|
|
18611
19082
|
chainIdBuf,
|
|
18612
19083
|
nonceBuf,
|
|
18613
19084
|
dAModeHashBuf
|
|
18614
19085
|
]);
|
|
18615
19086
|
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
18616
|
-
if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
|
|
18617
|
-
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
18618
|
-
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
18619
|
-
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
18620
|
-
const l1_data_gasBuf = this.convertBnToLedger(
|
|
18621
|
-
encodeDataResourceBoundsL1(txDetails.resourceBounds)
|
|
18622
|
-
);
|
|
18623
|
-
const feeBuf = concatenateArrayBuffer([
|
|
18624
|
-
tipBuf,
|
|
18625
|
-
l1_gasBuf,
|
|
18626
|
-
l2_gasBuf,
|
|
18627
|
-
l1_data_gasBuf
|
|
18628
|
-
]);
|
|
18629
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
|
|
18630
|
-
}
|
|
18631
19087
|
const paymasterBuf = concatenateArrayBuffer(
|
|
18632
19088
|
txDetails.paymasterData.map((value) => {
|
|
18633
19089
|
const a = this.convertBnToLedger(value);
|
|
18634
19090
|
return a;
|
|
18635
19091
|
})
|
|
18636
19092
|
);
|
|
18637
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
19093
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
|
|
18638
19094
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
18639
19095
|
txDetails.paymasterData.map((value) => {
|
|
18640
19096
|
const a = this.convertBnToLedger(value);
|
|
18641
19097
|
return a;
|
|
18642
19098
|
})
|
|
18643
19099
|
);
|
|
18644
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
19100
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
|
|
18645
19101
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
18646
|
-
await this._transporter.send(Number("0x5a"), 3,
|
|
19102
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
|
|
18647
19103
|
let respSign = new Uint8Array(0);
|
|
18648
19104
|
for (const call of calls) {
|
|
18649
19105
|
const calldatas = this.encodeCall(call);
|
|
18650
|
-
|
|
19106
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
|
|
18651
19107
|
if (calldatas.length > 1) {
|
|
18652
19108
|
calldatas.slice(1).forEach(async (part) => {
|
|
18653
|
-
|
|
19109
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
|
|
18654
19110
|
});
|
|
18655
19111
|
}
|
|
19112
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
18656
19113
|
}
|
|
18657
19114
|
return this.decodeSignatureLedger(respSign);
|
|
18658
19115
|
}
|
|
@@ -18682,581 +19139,360 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
18682
19139
|
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
18683
19140
|
* // res = {hash:
|
|
18684
19141
|
* // signature:
|
|
18685
|
-
* // }
|
|
18686
|
-
* ```
|
|
18687
|
-
*/
|
|
18688
|
-
async signDeployAccountV3(deployAccountDetail) {
|
|
18689
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
18690
|
-
const accountAddressBuf = this.convertBnToLedger(
|
|
18691
|
-
deployAccountDetail.contractAddress
|
|
18692
|
-
);
|
|
18693
|
-
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
18694
|
-
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
18695
|
-
const dAModeHashBuf = this.convertBnToLedger(
|
|
18696
|
-
hashDAMode(
|
|
18697
|
-
|
|
18698
|
-
|
|
18699
|
-
)
|
|
18700
|
-
);
|
|
18701
|
-
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
18702
|
-
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
18703
|
-
const dataBuf = concatenateArrayBuffer([
|
|
18704
|
-
accountAddressBuf,
|
|
18705
|
-
chainIdBuf,
|
|
18706
|
-
nonceBuf,
|
|
18707
|
-
dAModeHashBuf,
|
|
18708
|
-
classHashBuf,
|
|
18709
|
-
saltBuf
|
|
18710
|
-
]);
|
|
18711
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
18712
|
-
|
|
18713
|
-
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
|
|
18719
|
-
|
|
18720
|
-
|
|
18721
|
-
|
|
18722
|
-
)
|
|
18723
|
-
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
18729
|
-
|
|
18730
|
-
|
|
18731
|
-
const
|
|
18732
|
-
|
|
18733
|
-
const a = this.convertBnToLedger(
|
|
18734
|
-
return a;
|
|
18735
|
-
})
|
|
18736
|
-
);
|
|
18737
|
-
|
|
18738
|
-
const
|
|
18739
|
-
|
|
18740
|
-
|
|
18741
|
-
|
|
18742
|
-
|
|
18743
|
-
|
|
18744
|
-
return a;
|
|
18745
|
-
})
|
|
18746
|
-
);
|
|
18747
|
-
const constructorChunks = [];
|
|
18748
|
-
const chunkSize = 7 * 32;
|
|
18749
|
-
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
18750
|
-
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
18751
|
-
let respSign = new Uint8Array(0);
|
|
18752
|
-
for (const chunk of constructorChunks) {
|
|
18753
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
18754
|
-
}
|
|
18755
|
-
return this.decodeSignatureLedger(respSign);
|
|
18756
|
-
}
|
|
18757
|
-
/** Internal function to convert a Call to an array of Uint8Array.
|
|
18758
|
-
* @param {Call} call A Call to convert.
|
|
18759
|
-
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
18760
|
-
*/
|
|
18761
|
-
encodeCall(call) {
|
|
18762
|
-
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
18763
|
-
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
18764
|
-
let calldataBuf;
|
|
18765
|
-
if (call.calldata) {
|
|
18766
|
-
const compiledCalldata = CallData.compile(call.calldata);
|
|
18767
|
-
const calldataSizeBuf = this.convertBnToLedger(compiledCalldata.length);
|
|
18768
|
-
calldataBuf = concatenateArrayBuffer([
|
|
18769
|
-
calldataSizeBuf,
|
|
18770
|
-
...compiledCalldata.map((parameter) => {
|
|
18771
|
-
const a = this.convertBnToLedger(parameter);
|
|
18772
|
-
return a;
|
|
18773
|
-
})
|
|
18774
|
-
]);
|
|
18775
|
-
} else {
|
|
18776
|
-
calldataBuf = this.convertBnToLedger("0x00");
|
|
18777
|
-
}
|
|
18778
|
-
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
18779
|
-
const calldatas = [];
|
|
18780
|
-
const chunkSize = 7 * 32;
|
|
18781
|
-
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
18782
|
-
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
18783
|
-
return calldatas;
|
|
18784
|
-
}
|
|
18785
|
-
};
|
|
18786
|
-
|
|
18787
|
-
// src/utils/outsideExecution.ts
|
|
18788
|
-
var outsideExecution_exports = {};
|
|
18789
|
-
__export(outsideExecution_exports, {
|
|
18790
|
-
buildExecuteFromOutsideCall: () => buildExecuteFromOutsideCall,
|
|
18791
|
-
buildExecuteFromOutsideCallData: () => buildExecuteFromOutsideCallData,
|
|
18792
|
-
getOutsideCall: () => getOutsideCall,
|
|
18793
|
-
getTypedData: () => getTypedData,
|
|
18794
|
-
toOutsideCallV2: () => toOutsideCallV2
|
|
18795
|
-
});
|
|
18796
|
-
function toOutsideCallV2(call) {
|
|
18797
|
-
if ("calldata_len" in call) {
|
|
18798
|
-
return {
|
|
18799
|
-
To: call.to,
|
|
18800
|
-
Selector: call.selector,
|
|
18801
|
-
Calldata: call.calldata
|
|
18802
|
-
};
|
|
18803
|
-
}
|
|
18804
|
-
return call;
|
|
18805
|
-
}
|
|
18806
|
-
function getOutsideCall(call) {
|
|
18807
|
-
const callData = call.calldata ?? [];
|
|
18808
|
-
const callDataCompiled = Array.isArray(callData) ? callData : CallData.compile(callData);
|
|
18809
|
-
return {
|
|
18810
|
-
to: call.contractAddress,
|
|
18811
|
-
selector: getSelectorFromName(call.entrypoint),
|
|
18812
|
-
calldata: callDataCompiled
|
|
18813
|
-
};
|
|
18814
|
-
}
|
|
18815
|
-
function callToTypedData(call, version) {
|
|
18816
|
-
const outsideCall = getOutsideCall(call);
|
|
18817
|
-
if (version === "1") {
|
|
18818
|
-
return {
|
|
18819
|
-
...outsideCall,
|
|
18820
|
-
calldata_len: outsideCall.calldata.length,
|
|
18821
|
-
calldata: outsideCall.calldata
|
|
18822
|
-
};
|
|
18823
|
-
}
|
|
18824
|
-
return {
|
|
18825
|
-
To: outsideCall.to,
|
|
18826
|
-
Selector: outsideCall.selector,
|
|
18827
|
-
Calldata: outsideCall.calldata
|
|
18828
|
-
};
|
|
18829
|
-
}
|
|
18830
|
-
function getDomain(chainId, version) {
|
|
18831
|
-
return {
|
|
18832
|
-
name: "Account.execute_from_outside",
|
|
18833
|
-
version,
|
|
18834
|
-
chainId,
|
|
18835
|
-
...version === "2" ? { revision: "1" } : {}
|
|
18836
|
-
};
|
|
18837
|
-
}
|
|
18838
|
-
function getTypedData(chainId, options, nonce, myCalls, version) {
|
|
18839
|
-
if (version === "1") {
|
|
18840
|
-
return {
|
|
18841
|
-
types: OutsideExecutionTypesV1,
|
|
18842
|
-
primaryType: "OutsideExecution",
|
|
18843
|
-
domain: getDomain(chainId, version),
|
|
18844
|
-
message: {
|
|
18845
|
-
...options,
|
|
18846
|
-
nonce,
|
|
18847
|
-
calls_len: myCalls.length,
|
|
18848
|
-
calls: myCalls.map((call) => callToTypedData(call, version))
|
|
18849
|
-
}
|
|
18850
|
-
};
|
|
18851
|
-
}
|
|
18852
|
-
return {
|
|
18853
|
-
types: OutsideExecutionTypesV2,
|
|
18854
|
-
primaryType: "OutsideExecution",
|
|
18855
|
-
domain: getDomain(chainId, version),
|
|
18856
|
-
message: {
|
|
18857
|
-
Caller: options.caller,
|
|
18858
|
-
Nonce: nonce,
|
|
18859
|
-
"Execute After": options.execute_after,
|
|
18860
|
-
"Execute Before": options.execute_before,
|
|
18861
|
-
Calls: myCalls.map((call) => callToTypedData(call, version))
|
|
18862
|
-
}
|
|
18863
|
-
};
|
|
18864
|
-
}
|
|
18865
|
-
function buildExecuteFromOutsideCallData(outsideTransaction) {
|
|
18866
|
-
const execution2 = outsideTransaction.outsideExecution;
|
|
18867
|
-
const formattedSignature = formatSignature(outsideTransaction.signature);
|
|
18868
|
-
return CallData.compile({
|
|
18869
|
-
outside_execution: execution2,
|
|
18870
|
-
signature: formattedSignature
|
|
18871
|
-
});
|
|
18872
|
-
}
|
|
18873
|
-
function buildExecuteFromOutsideCall(outsideTransaction) {
|
|
18874
|
-
const myOutsideTransactions = Array.isArray(outsideTransaction) ? outsideTransaction : [outsideTransaction];
|
|
18875
|
-
const multiCall = myOutsideTransactions.map((outsideTx) => {
|
|
18876
|
-
let entrypoint;
|
|
18877
|
-
if (outsideTx.version === OutsideExecutionVersion.V1) {
|
|
18878
|
-
entrypoint = "execute_from_outside";
|
|
18879
|
-
} else if (outsideTx.version === OutsideExecutionVersion.V2) {
|
|
18880
|
-
entrypoint = "execute_from_outside_v2";
|
|
18881
|
-
} else {
|
|
18882
|
-
throw new Error("Unsupported OutsideExecution version");
|
|
19142
|
+
* // }
|
|
19143
|
+
* ```
|
|
19144
|
+
*/
|
|
19145
|
+
async signDeployAccountV3(deployAccountDetail) {
|
|
19146
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
19147
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
19148
|
+
deployAccountDetail.contractAddress
|
|
19149
|
+
);
|
|
19150
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
19151
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
19152
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
19153
|
+
hashDAMode(
|
|
19154
|
+
deployAccountDetail.nonceDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2,
|
|
19155
|
+
deployAccountDetail.feeDataAvailabilityMode === api_exports.EDataAvailabilityMode.L1 ? api_exports.EDAMode.L1 : api_exports.EDAMode.L2
|
|
19156
|
+
)
|
|
19157
|
+
);
|
|
19158
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
19159
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
19160
|
+
const dataBuf = concatenateArrayBuffer([
|
|
19161
|
+
accountAddressBuf,
|
|
19162
|
+
chainIdBuf,
|
|
19163
|
+
nonceBuf,
|
|
19164
|
+
dAModeHashBuf,
|
|
19165
|
+
classHashBuf,
|
|
19166
|
+
saltBuf
|
|
19167
|
+
]);
|
|
19168
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
19169
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
19170
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
19171
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
19172
|
+
);
|
|
19173
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
19174
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
19175
|
+
);
|
|
19176
|
+
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
19177
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
19178
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
19179
|
+
deployAccountDetail.paymasterData.map((value) => {
|
|
19180
|
+
const a = this.convertBnToLedger(value);
|
|
19181
|
+
return a;
|
|
19182
|
+
})
|
|
19183
|
+
);
|
|
19184
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
19185
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
19186
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
19187
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
19188
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
19189
|
+
compiledConstructor.map((parameter) => {
|
|
19190
|
+
const a = this.convertBnToLedger(parameter);
|
|
19191
|
+
return a;
|
|
19192
|
+
})
|
|
19193
|
+
);
|
|
19194
|
+
const constructorChunks = [];
|
|
19195
|
+
const chunkSize = 7 * 32;
|
|
19196
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
19197
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
19198
|
+
let respSign = new Uint8Array(0);
|
|
19199
|
+
for (const chunk of constructorChunks) {
|
|
19200
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
18883
19201
|
}
|
|
18884
|
-
return
|
|
18885
|
-
contractAddress: toHex(outsideTx.signerAddress),
|
|
18886
|
-
entrypoint,
|
|
18887
|
-
calldata: buildExecuteFromOutsideCallData(outsideTx)
|
|
18888
|
-
};
|
|
18889
|
-
});
|
|
18890
|
-
return multiCall;
|
|
18891
|
-
}
|
|
18892
|
-
|
|
18893
|
-
// src/utils/src5.ts
|
|
18894
|
-
var src5_exports = {};
|
|
18895
|
-
__export(src5_exports, {
|
|
18896
|
-
supportsInterface: () => supportsInterface
|
|
18897
|
-
});
|
|
18898
|
-
async function supportsInterface(provider, contractAddress, interfaceId) {
|
|
18899
|
-
const call = {
|
|
18900
|
-
contractAddress: toHex(contractAddress),
|
|
18901
|
-
entrypoint: "supports_interface",
|
|
18902
|
-
calldata: [toHex(interfaceId)]
|
|
18903
|
-
};
|
|
18904
|
-
try {
|
|
18905
|
-
const resp = await provider.callContract(call);
|
|
18906
|
-
return BigInt(resp[0]) !== 0n;
|
|
18907
|
-
} catch {
|
|
18908
|
-
return false;
|
|
19202
|
+
return this.decodeSignatureLedger(respSign);
|
|
18909
19203
|
}
|
|
19204
|
+
};
|
|
19205
|
+
function getLedgerPathBuffer221(accountId, applicationName = "LedgerW") {
|
|
19206
|
+
const path0buff = new Uint8Array([HARDENING_BYTE, 0, 10, 85]);
|
|
19207
|
+
const path1buff = new Uint8Array([71 | HARDENING_BYTE, 65, 233, 201]);
|
|
19208
|
+
const path2Base = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
19209
|
+
const path2buff = concatenateArrayBuffer([
|
|
19210
|
+
new Uint8Array([path2Base[0] | HARDENING_BYTE]),
|
|
19211
|
+
path2Base.subarray(1)
|
|
19212
|
+
]);
|
|
19213
|
+
const path3buff = new Uint8Array([HARDENING_BYTE, 0, 0, 0]);
|
|
19214
|
+
const hex = toHex(BigInt(accountId) | HARDENING_4BYTES);
|
|
19215
|
+
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
19216
|
+
const path4buff = hexToBytes(padded);
|
|
19217
|
+
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
19218
|
+
const pathBuff = concatenateArrayBuffer([
|
|
19219
|
+
path0buff,
|
|
19220
|
+
path1buff,
|
|
19221
|
+
path2buff,
|
|
19222
|
+
path3buff,
|
|
19223
|
+
path4buff,
|
|
19224
|
+
path5buff
|
|
19225
|
+
]);
|
|
19226
|
+
return pathBuff;
|
|
18910
19227
|
}
|
|
18911
19228
|
|
|
18912
|
-
// src/
|
|
18913
|
-
var
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
})
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
19229
|
+
// src/signer/ledgerSigner231.ts
|
|
19230
|
+
var LedgerSigner231 = class extends LedgerSigner221 {
|
|
19231
|
+
/**
|
|
19232
|
+
* constructor of the LedgerSigner class.
|
|
19233
|
+
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
19234
|
+
* See Guides for more details.
|
|
19235
|
+
* @param {number} accountID ID of Ledger Nano account (can handle 2**31 accounts).
|
|
19236
|
+
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
19237
|
+
* One item is called `application` and can be customized.
|
|
19238
|
+
* Default value is `LedgerW`.
|
|
19239
|
+
* @param {LedgerPathCalculation} [pathFunction=getLedgerPathBuffer221]
|
|
19240
|
+
* defines the function that will calculate the path. By default `getLedgerPathBuffer221` is selected.
|
|
19241
|
+
*
|
|
19242
|
+
* If you are using APP v2.3.1 with an account created with the v1.1.1, you need to use :
|
|
19243
|
+
* ```typescript
|
|
19244
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
19245
|
+
* ```
|
|
19246
|
+
* @example
|
|
19247
|
+
* ```typescript
|
|
19248
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
19249
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
19250
|
+
* const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0);
|
|
19251
|
+
* ```
|
|
19252
|
+
*/
|
|
19253
|
+
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
19254
|
+
super(transport, accountID, eip2645application, pathFunction);
|
|
18922
19255
|
}
|
|
18923
|
-
|
|
18924
|
-
|
|
18925
|
-
|
|
18926
|
-
}
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
18930
|
-
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
};
|
|
18954
|
-
function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls, isSponsored = false) {
|
|
18955
|
-
const baseError = "Provided calls are not strictly equal to the returned calls";
|
|
18956
|
-
const expectedExtraCalls = isSponsored ? 0 : 1;
|
|
18957
|
-
assert(
|
|
18958
|
-
unsafeCalls.length - expectedExtraCalls === originalCalls.length,
|
|
18959
|
-
`${baseError}: Expected ${originalCalls.length + expectedExtraCalls} calls, got ${unsafeCalls.length}`
|
|
18960
|
-
);
|
|
18961
|
-
for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
|
|
18962
|
-
const originalCall = originalCalls[callIndex];
|
|
18963
|
-
const unsafeCall = toOutsideCallV2(unsafeCalls[callIndex]);
|
|
18964
|
-
const normalizeAddress = (address) => {
|
|
18965
|
-
return toBigInt(address).toString(16).toLowerCase();
|
|
18966
|
-
};
|
|
18967
|
-
const originalAddress = normalizeAddress(originalCall.contractAddress);
|
|
18968
|
-
const unsafeAddress = normalizeAddress(unsafeCall.To);
|
|
18969
|
-
assert(
|
|
18970
|
-
originalAddress === unsafeAddress,
|
|
18971
|
-
`${baseError}: Contract address mismatch at call ${callIndex}. Expected: ${originalCall.contractAddress}, Got: ${unsafeCall.To}`
|
|
18972
|
-
);
|
|
19256
|
+
/**
|
|
19257
|
+
* Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
|
|
19258
|
+
* @param {V3InvocationsSignerDetails} txDetails All the details needed for a txV3.
|
|
19259
|
+
* @param {Call[]} calls array of Starknet invocations
|
|
19260
|
+
* @returns an object including the transaction Hash and the signature
|
|
19261
|
+
* @example
|
|
19262
|
+
* ```typescript
|
|
19263
|
+
* const calls: Call[] = [{contractAddress: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
19264
|
+
* entrypoint: "transfer",
|
|
19265
|
+
* calldata:["0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016",
|
|
19266
|
+
* "0x9184e72a000", "0x0"]}];
|
|
19267
|
+
* const txDetailsV3: V3InvocationsSignerDetails = {
|
|
19268
|
+
* chainId: constants.StarknetChainId.SN_MAIN,
|
|
19269
|
+
* nonce: "28", accountDeploymentData: [],
|
|
19270
|
+
* paymasterData: [], cairoVersion: "1",
|
|
19271
|
+
* feeDataAvailabilityMode: "L1", nonceDataAvailabilityMode: "L1",
|
|
19272
|
+
* resourceBounds: {
|
|
19273
|
+
* l1_gas: { max_amount: "0x2a00", max_price_per_unit: "0x5c00000"
|
|
19274
|
+
* },
|
|
19275
|
+
* l2_gas: { max_amount: "0x00", max_price_per_unit: "0x00"},
|
|
19276
|
+
* }, tip: 0, version: "0x3", walletAddress: account0.address
|
|
19277
|
+
* };
|
|
19278
|
+
* const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
|
|
19279
|
+
* // res = {hash:
|
|
19280
|
+
* // signature:
|
|
19281
|
+
* // }
|
|
19282
|
+
* ```
|
|
19283
|
+
*/
|
|
19284
|
+
async signTxV3(txDetails, calls) {
|
|
19285
|
+
assert(txDetails.paymasterData.length <= 7, "Paymaster data includes more than 7 items.");
|
|
18973
19286
|
assert(
|
|
18974
|
-
|
|
18975
|
-
|
|
19287
|
+
txDetails.accountDeploymentData.length <= 7,
|
|
19288
|
+
"accountDeploymentData includes more than 7 items"
|
|
18976
19289
|
);
|
|
18977
|
-
|
|
18978
|
-
const
|
|
18979
|
-
|
|
18980
|
-
|
|
18981
|
-
|
|
19290
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
19291
|
+
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
19292
|
+
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
19293
|
+
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
19294
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
19295
|
+
hashDAMode(
|
|
19296
|
+
intDAM(txDetails.nonceDataAvailabilityMode),
|
|
19297
|
+
intDAM(txDetails.feeDataAvailabilityMode)
|
|
19298
|
+
)
|
|
18982
19299
|
);
|
|
18983
|
-
|
|
18984
|
-
|
|
18985
|
-
|
|
18986
|
-
|
|
18987
|
-
|
|
18988
|
-
|
|
19300
|
+
const dataBuf = concatenateArrayBuffer([
|
|
19301
|
+
accountAddressBuf,
|
|
19302
|
+
chainIdBuf,
|
|
19303
|
+
nonceBuf,
|
|
19304
|
+
dAModeHashBuf
|
|
19305
|
+
]);
|
|
19306
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
19307
|
+
if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
|
|
19308
|
+
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
19309
|
+
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
19310
|
+
const l2_gasBuf = this.convertBnToLedger(encodeResourceBoundsL2(txDetails.resourceBounds));
|
|
19311
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
19312
|
+
encodeDataResourceBoundsL1(txDetails.resourceBounds)
|
|
18989
19313
|
);
|
|
19314
|
+
const feeBuf = concatenateArrayBuffer([
|
|
19315
|
+
tipBuf,
|
|
19316
|
+
l1_gasBuf,
|
|
19317
|
+
l2_gasBuf,
|
|
19318
|
+
l1_data_gasBuf
|
|
19319
|
+
]);
|
|
19320
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
|
|
18990
19321
|
}
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
|
|
18995
|
-
|
|
18996
|
-
} catch {
|
|
18997
|
-
return CairoBytes31.fromText(String(value)).toBigInt();
|
|
18998
|
-
}
|
|
18999
|
-
};
|
|
19000
|
-
var assertChainIdFromTypedData = (typedData, chainId) => {
|
|
19001
|
-
assert(
|
|
19002
|
-
typedData.domain.chainId !== void 0 && domainFieldToFelt(typedData.domain.chainId) === BigInt(chainId),
|
|
19003
|
-
"Paymaster typed data domain chainId does not match the account's provider chain"
|
|
19004
|
-
);
|
|
19005
|
-
};
|
|
19006
|
-
var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, chainId, maxFeeInGasToken) => {
|
|
19007
|
-
if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
|
|
19008
|
-
assertChainIdFromTypedData(preparedTransaction.typed_data, chainId);
|
|
19009
|
-
const { message } = preparedTransaction.typed_data;
|
|
19010
|
-
const hasV1Calls = "calls" in message;
|
|
19011
|
-
const hasV2Calls = "Calls" in message;
|
|
19012
|
-
assert(
|
|
19013
|
-
hasV1Calls !== hasV2Calls,
|
|
19014
|
-
'Paymaster typed data must declare exactly one of "calls" (SNIP-9 V1) or "Calls" (SNIP-9 V2)'
|
|
19322
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
19323
|
+
txDetails.paymasterData.map((value) => {
|
|
19324
|
+
const a = this.convertBnToLedger(value);
|
|
19325
|
+
return a;
|
|
19326
|
+
})
|
|
19015
19327
|
);
|
|
19016
|
-
|
|
19017
|
-
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19328
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(paymasterBuf));
|
|
19329
|
+
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
19330
|
+
txDetails.paymasterData.map((value) => {
|
|
19331
|
+
const a = this.convertBnToLedger(value);
|
|
19332
|
+
return a;
|
|
19333
|
+
})
|
|
19334
|
+
);
|
|
19335
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(accountDeployDataBuf));
|
|
19336
|
+
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
19337
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(nbCallsBuf));
|
|
19338
|
+
let respSign = new Uint8Array(0);
|
|
19339
|
+
for (const call of calls) {
|
|
19340
|
+
const calldatas = this.encodeCall(call);
|
|
19341
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, buffer_default.from(calldatas[0]));
|
|
19342
|
+
if (calldatas.length > 1) {
|
|
19343
|
+
calldatas.slice(1).forEach(async (part) => {
|
|
19344
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, buffer_default.from(part));
|
|
19345
|
+
});
|
|
19029
19346
|
}
|
|
19030
19347
|
}
|
|
19348
|
+
return this.decodeSignatureLedger(respSign);
|
|
19031
19349
|
}
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
19039
|
-
|
|
19040
|
-
|
|
19041
|
-
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
}
|
|
19046
|
-
|
|
19047
|
-
|
|
19048
|
-
|
|
19049
|
-
|
|
19050
|
-
|
|
19051
|
-
|
|
19052
|
-
|
|
19053
|
-
|
|
19054
|
-
|
|
19055
|
-
|
|
19056
|
-
|
|
19057
|
-
|
|
19058
|
-
|
|
19059
|
-
|
|
19060
|
-
|
|
19061
|
-
|
|
19062
|
-
|
|
19063
|
-
|
|
19064
|
-
|
|
19065
|
-
|
|
19066
|
-
|
|
19067
|
-
|
|
19068
|
-
|
|
19069
|
-
|
|
19070
|
-
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
|
|
19078
|
-
|
|
19079
|
-
|
|
19080
|
-
|
|
19081
|
-
|
|
19082
|
-
|
|
19083
|
-
|
|
19084
|
-
|
|
19085
|
-
|
|
19086
|
-
|
|
19087
|
-
|
|
19088
|
-
|
|
19089
|
-
|
|
19090
|
-
|
|
19091
|
-
|
|
19092
|
-
|
|
19093
|
-
|
|
19094
|
-
|
|
19095
|
-
|
|
19096
|
-
|
|
19097
|
-
|
|
19098
|
-
|
|
19099
|
-
|
|
19100
|
-
|
|
19101
|
-
|
|
19102
|
-
|
|
19103
|
-
id,
|
|
19104
|
-
jsonrpc: "2.0",
|
|
19105
|
-
method,
|
|
19106
|
-
...params && { params }
|
|
19107
|
-
};
|
|
19108
|
-
return this.baseFetch(this.nodeUrl, {
|
|
19109
|
-
method: "POST",
|
|
19110
|
-
body: stringify2(rpcRequestBody),
|
|
19111
|
-
headers: this.headers
|
|
19112
|
-
});
|
|
19113
|
-
}
|
|
19114
|
-
errorHandler(method, params, rpcError, otherError) {
|
|
19115
|
-
if (rpcError) {
|
|
19116
|
-
throw new RpcError(rpcError, method, params);
|
|
19117
|
-
}
|
|
19118
|
-
if (otherError instanceof LibraryError) {
|
|
19119
|
-
throw otherError;
|
|
19120
|
-
}
|
|
19121
|
-
if (otherError) {
|
|
19122
|
-
throw Error(otherError.message);
|
|
19123
|
-
}
|
|
19124
|
-
}
|
|
19125
|
-
async fetchEndpoint(method, params) {
|
|
19126
|
-
try {
|
|
19127
|
-
this.requestId += 1;
|
|
19128
|
-
const rawResult = await this.fetch(method, params, this.requestId);
|
|
19129
|
-
const { error, result } = await rawResult.json();
|
|
19130
|
-
this.errorHandler(method, params, error);
|
|
19131
|
-
return result;
|
|
19132
|
-
} catch (error) {
|
|
19133
|
-
this.errorHandler(method, params, error?.response?.data, error);
|
|
19134
|
-
throw error;
|
|
19135
|
-
}
|
|
19136
|
-
}
|
|
19137
|
-
async isAvailable() {
|
|
19138
|
-
return this.fetchEndpoint("paymaster_isAvailable");
|
|
19139
|
-
}
|
|
19140
|
-
async buildTransaction(transaction, parameters) {
|
|
19141
|
-
let userTransaction;
|
|
19142
|
-
switch (transaction.type) {
|
|
19143
|
-
case "invoke":
|
|
19144
|
-
userTransaction = {
|
|
19145
|
-
...transaction,
|
|
19146
|
-
invoke: {
|
|
19147
|
-
user_address: transaction.invoke.userAddress,
|
|
19148
|
-
calls: convertCalls(transaction.invoke.calls)
|
|
19149
|
-
}
|
|
19150
|
-
};
|
|
19151
|
-
break;
|
|
19152
|
-
case "deploy_and_invoke":
|
|
19153
|
-
userTransaction = {
|
|
19154
|
-
...transaction,
|
|
19155
|
-
invoke: {
|
|
19156
|
-
user_address: transaction.invoke.userAddress,
|
|
19157
|
-
calls: convertCalls(transaction.invoke.calls)
|
|
19158
|
-
}
|
|
19159
|
-
};
|
|
19160
|
-
break;
|
|
19161
|
-
case "deploy":
|
|
19162
|
-
default:
|
|
19163
|
-
userTransaction = transaction;
|
|
19164
|
-
break;
|
|
19350
|
+
/**
|
|
19351
|
+
*Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
|
|
19352
|
+
* @param {V3DeployAccountSignerDetails} deployAccountDetail All the details needed for a V3 deploy account.
|
|
19353
|
+
* @returns an object including the transaction Hash and the signature
|
|
19354
|
+
* @example
|
|
19355
|
+
* ```typescript
|
|
19356
|
+
* const deployData: V3DeployAccountSignerDetails =
|
|
19357
|
+
* {
|
|
19358
|
+
* tip: 0, paymasterData: [], accountDeploymentData: [],
|
|
19359
|
+
* nonceDataAvailabilityMode: 'L1', feeDataAvailabilityMode: 'L1',
|
|
19360
|
+
* resourceBounds: {
|
|
19361
|
+
* l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
19362
|
+
* l1_gas: { max_amount: '0x226', max_price_per_unit: '0x22ecb25c00' }
|
|
19363
|
+
* },
|
|
19364
|
+
* classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
|
|
19365
|
+
* constructorCalldata: [
|
|
19366
|
+
* '3571125127744830445572285574469842579401255431821644822726857471463672199621'
|
|
19367
|
+
* ],
|
|
19368
|
+
* contractAddress: '0x4ca062add1cf12a107be1107af17981cf6e544a24d987693230ea481d3d5e34',
|
|
19369
|
+
* addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
|
|
19370
|
+
* chainId: '0x534e5f5345504f4c4941',
|
|
19371
|
+
* version: '0x3', nonce: 0n
|
|
19372
|
+
*}
|
|
19373
|
+
* const res = await myLedgerSigner.signDeployAccountV3(deployData);
|
|
19374
|
+
* // res = {hash:
|
|
19375
|
+
* // signature:
|
|
19376
|
+
* // }
|
|
19377
|
+
* ```
|
|
19378
|
+
*/
|
|
19379
|
+
async signDeployAccountV3(deployAccountDetail) {
|
|
19380
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
19381
|
+
const accountAddressBuf = this.convertBnToLedger(
|
|
19382
|
+
deployAccountDetail.contractAddress
|
|
19383
|
+
);
|
|
19384
|
+
const chainIdBuf = this.convertBnToLedger(deployAccountDetail.chainId);
|
|
19385
|
+
const nonceBuf = this.convertBnToLedger(deployAccountDetail.nonce);
|
|
19386
|
+
const dAModeHashBuf = this.convertBnToLedger(
|
|
19387
|
+
hashDAMode(
|
|
19388
|
+
intDAM(deployAccountDetail.nonceDataAvailabilityMode),
|
|
19389
|
+
intDAM(deployAccountDetail.feeDataAvailabilityMode)
|
|
19390
|
+
)
|
|
19391
|
+
);
|
|
19392
|
+
const classHashBuf = this.convertBnToLedger(deployAccountDetail.classHash);
|
|
19393
|
+
const saltBuf = this.convertBnToLedger(deployAccountDetail.addressSalt);
|
|
19394
|
+
const dataBuf = concatenateArrayBuffer([
|
|
19395
|
+
accountAddressBuf,
|
|
19396
|
+
chainIdBuf,
|
|
19397
|
+
nonceBuf,
|
|
19398
|
+
dAModeHashBuf,
|
|
19399
|
+
classHashBuf,
|
|
19400
|
+
saltBuf
|
|
19401
|
+
]);
|
|
19402
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
19403
|
+
if (isRPC08Plus_ResourceBoundsBN(deployAccountDetail.resourceBounds)) {
|
|
19404
|
+
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
19405
|
+
const l1_gasBuf = this.convertBnToLedger(
|
|
19406
|
+
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
19407
|
+
);
|
|
19408
|
+
const l2_gasBuf = this.convertBnToLedger(
|
|
19409
|
+
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
19410
|
+
);
|
|
19411
|
+
const l1_data_gasBuf = this.convertBnToLedger(
|
|
19412
|
+
encodeDataResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
19413
|
+
);
|
|
19414
|
+
const feeBuf = concatenateArrayBuffer([
|
|
19415
|
+
tipBuf,
|
|
19416
|
+
l1_gasBuf,
|
|
19417
|
+
l2_gasBuf,
|
|
19418
|
+
l1_data_gasBuf
|
|
19419
|
+
]);
|
|
19420
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
19165
19421
|
}
|
|
19166
|
-
const
|
|
19167
|
-
|
|
19168
|
-
|
|
19169
|
-
|
|
19170
|
-
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19176
|
-
|
|
19177
|
-
|
|
19178
|
-
|
|
19179
|
-
|
|
19180
|
-
|
|
19181
|
-
|
|
19182
|
-
|
|
19183
|
-
|
|
19184
|
-
|
|
19185
|
-
|
|
19186
|
-
|
|
19187
|
-
|
|
19188
|
-
|
|
19189
|
-
};
|
|
19190
|
-
case "deploy_and_invoke":
|
|
19191
|
-
return {
|
|
19192
|
-
type: "deploy_and_invoke",
|
|
19193
|
-
deployment: response.deployment,
|
|
19194
|
-
typed_data: response.typed_data,
|
|
19195
|
-
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
19196
|
-
fee
|
|
19197
|
-
};
|
|
19198
|
-
case "deploy":
|
|
19199
|
-
default:
|
|
19200
|
-
return {
|
|
19201
|
-
type: "deploy",
|
|
19202
|
-
deployment: response.deployment,
|
|
19203
|
-
parameters: convertEXECUTION_PARAMETERS(response.parameters),
|
|
19204
|
-
fee
|
|
19205
|
-
};
|
|
19422
|
+
const paymasterBuf = concatenateArrayBuffer(
|
|
19423
|
+
deployAccountDetail.paymasterData.map((value) => {
|
|
19424
|
+
const a = this.convertBnToLedger(value);
|
|
19425
|
+
return a;
|
|
19426
|
+
})
|
|
19427
|
+
);
|
|
19428
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
19429
|
+
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
19430
|
+
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
19431
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
19432
|
+
const constructorBuf = concatenateArrayBuffer(
|
|
19433
|
+
compiledConstructor.map((parameter) => {
|
|
19434
|
+
const a = this.convertBnToLedger(parameter);
|
|
19435
|
+
return a;
|
|
19436
|
+
})
|
|
19437
|
+
);
|
|
19438
|
+
const constructorChunks = [];
|
|
19439
|
+
const chunkSize = 7 * 32;
|
|
19440
|
+
for (let i = 0; i < constructorBuf.length; i += chunkSize)
|
|
19441
|
+
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
19442
|
+
let respSign = new Uint8Array(0);
|
|
19443
|
+
for (const chunk of constructorChunks) {
|
|
19444
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
19206
19445
|
}
|
|
19446
|
+
return this.decodeSignatureLedger(respSign);
|
|
19207
19447
|
}
|
|
19208
|
-
|
|
19209
|
-
|
|
19210
|
-
|
|
19211
|
-
|
|
19212
|
-
|
|
19213
|
-
|
|
19214
|
-
|
|
19215
|
-
|
|
19216
|
-
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
}
|
|
19229
|
-
};
|
|
19230
|
-
break;
|
|
19231
|
-
case "deploy":
|
|
19232
|
-
default:
|
|
19233
|
-
user_transaction = transaction;
|
|
19234
|
-
break;
|
|
19448
|
+
/** Internal function to convert a Call to an array of Uint8Array.
|
|
19449
|
+
* @param {Call} call A Call to convert.
|
|
19450
|
+
* @return {Uint8Array[]} Call encoded in an array of Uint8Array (each containing 7 u256).
|
|
19451
|
+
*/
|
|
19452
|
+
encodeCall(call) {
|
|
19453
|
+
const toBuf = this.convertBnToLedger(call.contractAddress);
|
|
19454
|
+
const selectorBuf = hexToBytes(addAddressPadding(getSelector(call.entrypoint)));
|
|
19455
|
+
let calldataBuf;
|
|
19456
|
+
if (call.calldata) {
|
|
19457
|
+
const compiledCalldata = CallData.compile(call.calldata);
|
|
19458
|
+
const calldataSizeBuf = this.convertBnToLedger(compiledCalldata.length);
|
|
19459
|
+
calldataBuf = concatenateArrayBuffer([
|
|
19460
|
+
calldataSizeBuf,
|
|
19461
|
+
...compiledCalldata.map((parameter) => {
|
|
19462
|
+
const a = this.convertBnToLedger(parameter);
|
|
19463
|
+
return a;
|
|
19464
|
+
})
|
|
19465
|
+
]);
|
|
19466
|
+
} else {
|
|
19467
|
+
calldataBuf = this.convertBnToLedger("0x00");
|
|
19235
19468
|
}
|
|
19236
|
-
const
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
|
|
19240
|
-
|
|
19241
|
-
return
|
|
19242
|
-
transaction: user_transaction,
|
|
19243
|
-
parameters: executionParameters
|
|
19244
|
-
});
|
|
19245
|
-
}
|
|
19246
|
-
async getSupportedTokens() {
|
|
19247
|
-
return this.fetchEndpoint("paymaster_getSupportedTokens").then(
|
|
19248
|
-
(tokens) => tokens.map((token) => ({
|
|
19249
|
-
token_address: token.token_address,
|
|
19250
|
-
decimals: token.decimals,
|
|
19251
|
-
priceInStrk: BigInt(token.price_in_strk)
|
|
19252
|
-
}))
|
|
19253
|
-
);
|
|
19469
|
+
const callBuf = concatenateArrayBuffer([toBuf, selectorBuf, calldataBuf]);
|
|
19470
|
+
const calldatas = [];
|
|
19471
|
+
const chunkSize = 7 * 32;
|
|
19472
|
+
for (let i = 0; i < callBuf.length; i += chunkSize)
|
|
19473
|
+
calldatas.push(callBuf.subarray(i, i + chunkSize));
|
|
19474
|
+
return calldatas;
|
|
19254
19475
|
}
|
|
19255
19476
|
};
|
|
19256
19477
|
|
|
19257
|
-
// src/
|
|
19258
|
-
var
|
|
19259
|
-
|
|
19478
|
+
// src/utils/src5.ts
|
|
19479
|
+
var src5_exports = {};
|
|
19480
|
+
__export(src5_exports, {
|
|
19481
|
+
supportsInterface: () => supportsInterface
|
|
19482
|
+
});
|
|
19483
|
+
async function supportsInterface(provider, contractAddress, interfaceId) {
|
|
19484
|
+
const call = {
|
|
19485
|
+
contractAddress: toHex(contractAddress),
|
|
19486
|
+
entrypoint: "supports_interface",
|
|
19487
|
+
calldata: [toHex(interfaceId)]
|
|
19488
|
+
};
|
|
19489
|
+
try {
|
|
19490
|
+
const resp = await provider.callContract(call);
|
|
19491
|
+
return BigInt(resp[0]) !== 0n;
|
|
19492
|
+
} catch {
|
|
19493
|
+
return false;
|
|
19494
|
+
}
|
|
19495
|
+
}
|
|
19260
19496
|
|
|
19261
19497
|
// src/deployer/compileConstructorCalldata.ts
|
|
19262
19498
|
function checkCompiledConstructorCalldata(calldata, abi) {
|
|
@@ -19413,7 +19649,6 @@ var Account = class {
|
|
|
19413
19649
|
// holds Cairo 0 contracts, to refuse a Cairo 0 account; otherwise remove it.
|
|
19414
19650
|
cairoVersion;
|
|
19415
19651
|
transactionVersion;
|
|
19416
|
-
paymaster;
|
|
19417
19652
|
deployer;
|
|
19418
19653
|
defaultTipType;
|
|
19419
19654
|
/** @internal Account-level plugin management */
|
|
@@ -19435,11 +19670,13 @@ var Account = class {
|
|
|
19435
19670
|
this.cairoVersion = cairoVersion.toString();
|
|
19436
19671
|
}
|
|
19437
19672
|
this.transactionVersion = transactionVersion ?? config.get("transactionVersion");
|
|
19438
|
-
this.paymaster = paymaster ? new PaymasterRpc(paymaster) : new PaymasterRpc({ mute: true });
|
|
19439
19673
|
this.deployer = options.deployer ?? defaultDeployer;
|
|
19440
19674
|
this.defaultTipType = defaultTipType ?? config.get("defaultTipType");
|
|
19441
19675
|
this.accountPluginManager = new PluginManager();
|
|
19442
|
-
const plugins =
|
|
19676
|
+
const plugins = applyPaymasterOption(
|
|
19677
|
+
options.plugins === false ? [] : options.plugins ?? defaultPlugins,
|
|
19678
|
+
paymaster
|
|
19679
|
+
);
|
|
19443
19680
|
plugins.forEach((plugin) => {
|
|
19444
19681
|
this.accountPluginManager.installOnAccount(plugin, this);
|
|
19445
19682
|
});
|
|
@@ -20150,99 +20387,6 @@ var Account = class {
|
|
|
20150
20387
|
})
|
|
20151
20388
|
);
|
|
20152
20389
|
}
|
|
20153
|
-
/*
|
|
20154
|
-
* SNIP-29 Paymaster
|
|
20155
|
-
*/
|
|
20156
|
-
async buildPaymasterTransaction(calls, paymasterDetails) {
|
|
20157
|
-
if (!paymasterDetails.deploymentData) {
|
|
20158
|
-
const snip9Version = await this.getSnip9Version();
|
|
20159
|
-
if (snip9Version === OutsideExecutionVersion.UNSUPPORTED) {
|
|
20160
|
-
throw Error("Account is not compatible with SNIP-9");
|
|
20161
|
-
}
|
|
20162
|
-
}
|
|
20163
|
-
const parameters = {
|
|
20164
|
-
version: "0x1",
|
|
20165
|
-
feeMode: paymasterDetails.feeMode,
|
|
20166
|
-
timeBounds: paymasterDetails.timeBounds
|
|
20167
|
-
};
|
|
20168
|
-
let transaction;
|
|
20169
|
-
if (paymasterDetails.deploymentData) {
|
|
20170
|
-
if (calls.length > 0) {
|
|
20171
|
-
transaction = {
|
|
20172
|
-
type: "deploy_and_invoke",
|
|
20173
|
-
invoke: { userAddress: this.address, calls },
|
|
20174
|
-
deployment: paymasterDetails.deploymentData
|
|
20175
|
-
};
|
|
20176
|
-
} else {
|
|
20177
|
-
transaction = {
|
|
20178
|
-
type: "deploy",
|
|
20179
|
-
deployment: paymasterDetails.deploymentData
|
|
20180
|
-
};
|
|
20181
|
-
}
|
|
20182
|
-
} else {
|
|
20183
|
-
transaction = {
|
|
20184
|
-
type: "invoke",
|
|
20185
|
-
invoke: { userAddress: this.address, calls }
|
|
20186
|
-
};
|
|
20187
|
-
}
|
|
20188
|
-
return this.paymaster.buildTransaction(transaction, parameters);
|
|
20189
|
-
}
|
|
20190
|
-
async estimatePaymasterTransactionFee(calls, paymasterDetails) {
|
|
20191
|
-
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
20192
|
-
return preparedTransaction.fee;
|
|
20193
|
-
}
|
|
20194
|
-
async preparePaymasterTransaction(preparedTransaction) {
|
|
20195
|
-
let transaction;
|
|
20196
|
-
switch (preparedTransaction.type) {
|
|
20197
|
-
case "deploy_and_invoke": {
|
|
20198
|
-
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
20199
|
-
transaction = {
|
|
20200
|
-
type: "deploy_and_invoke",
|
|
20201
|
-
invoke: {
|
|
20202
|
-
userAddress: this.address,
|
|
20203
|
-
typedData: preparedTransaction.typed_data,
|
|
20204
|
-
signature: signatureToHexArray(signature)
|
|
20205
|
-
},
|
|
20206
|
-
deployment: preparedTransaction.deployment
|
|
20207
|
-
};
|
|
20208
|
-
break;
|
|
20209
|
-
}
|
|
20210
|
-
case "invoke": {
|
|
20211
|
-
const signature = await this.signMessage(preparedTransaction.typed_data);
|
|
20212
|
-
transaction = {
|
|
20213
|
-
type: "invoke",
|
|
20214
|
-
invoke: {
|
|
20215
|
-
userAddress: this.address,
|
|
20216
|
-
typedData: preparedTransaction.typed_data,
|
|
20217
|
-
signature: signatureToHexArray(signature)
|
|
20218
|
-
}
|
|
20219
|
-
};
|
|
20220
|
-
break;
|
|
20221
|
-
}
|
|
20222
|
-
case "deploy": {
|
|
20223
|
-
transaction = {
|
|
20224
|
-
type: "deploy",
|
|
20225
|
-
deployment: preparedTransaction.deployment
|
|
20226
|
-
};
|
|
20227
|
-
break;
|
|
20228
|
-
}
|
|
20229
|
-
default:
|
|
20230
|
-
throw Error("Invalid transaction type");
|
|
20231
|
-
}
|
|
20232
|
-
return transaction;
|
|
20233
|
-
}
|
|
20234
|
-
async executePaymasterTransaction(calls, paymasterDetails, maxFeeInGasToken) {
|
|
20235
|
-
const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
|
|
20236
|
-
assertPaymasterTransactionSafety(
|
|
20237
|
-
preparedTransaction,
|
|
20238
|
-
calls,
|
|
20239
|
-
paymasterDetails,
|
|
20240
|
-
await this.provider.getChainId(),
|
|
20241
|
-
maxFeeInGasToken
|
|
20242
|
-
);
|
|
20243
|
-
const transaction = await this.preparePaymasterTransaction(preparedTransaction);
|
|
20244
|
-
return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
|
|
20245
|
-
}
|
|
20246
20390
|
};
|
|
20247
20391
|
|
|
20248
20392
|
// src/account/interface.ts
|
|
@@ -21274,6 +21418,7 @@ function filterEventsByAddress(events, contractAddress) {
|
|
|
21274
21418
|
}
|
|
21275
21419
|
|
|
21276
21420
|
// src/contract/default.ts
|
|
21421
|
+
var NO_PAYMASTER_MESSAGE = "This account has no paymaster methods: add paymasterPlugin() to its plugins, or set its paymaster option.";
|
|
21277
21422
|
function buildCall(contract, functionAbi) {
|
|
21278
21423
|
return async function(...args) {
|
|
21279
21424
|
const options = { ...contract.withOptionsProps };
|
|
@@ -21512,13 +21657,12 @@ var Contract = class _Contract {
|
|
|
21512
21657
|
await this.ensureProvider();
|
|
21513
21658
|
if (isAccount(this.providerOrAccount)) {
|
|
21514
21659
|
if (restInvokeOptions.paymasterDetails) {
|
|
21515
|
-
|
|
21516
|
-
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
};
|
|
21660
|
+
assert(
|
|
21661
|
+
typeof this.providerOrAccount.executePaymasterTransaction === "function",
|
|
21662
|
+
NO_PAYMASTER_MESSAGE
|
|
21663
|
+
);
|
|
21520
21664
|
return this.providerOrAccount.executePaymasterTransaction(
|
|
21521
|
-
[
|
|
21665
|
+
[invocation],
|
|
21522
21666
|
restInvokeOptions.paymasterDetails,
|
|
21523
21667
|
restInvokeOptions.maxFeeInGasToken
|
|
21524
21668
|
);
|
|
@@ -21562,13 +21706,12 @@ var Contract = class _Contract {
|
|
|
21562
21706
|
await this.ensureProvider();
|
|
21563
21707
|
if (isAccount(this.providerOrAccount)) {
|
|
21564
21708
|
if (estimateDetails.paymasterDetails) {
|
|
21565
|
-
|
|
21566
|
-
|
|
21567
|
-
|
|
21568
|
-
|
|
21569
|
-
};
|
|
21709
|
+
assert(
|
|
21710
|
+
typeof this.providerOrAccount.estimatePaymasterTransactionFee === "function",
|
|
21711
|
+
NO_PAYMASTER_MESSAGE
|
|
21712
|
+
);
|
|
21570
21713
|
return this.providerOrAccount.estimatePaymasterTransactionFee(
|
|
21571
|
-
[
|
|
21714
|
+
[invocation],
|
|
21572
21715
|
estimateDetails.paymasterDetails
|
|
21573
21716
|
);
|
|
21574
21717
|
}
|
|
@@ -21941,6 +22084,7 @@ function units(amount, simbol = "fri") {
|
|
|
21941
22084
|
outsideExecution,
|
|
21942
22085
|
parseCalldataField,
|
|
21943
22086
|
paymaster,
|
|
22087
|
+
paymasterPlugin,
|
|
21944
22088
|
provider,
|
|
21945
22089
|
selector,
|
|
21946
22090
|
shortString,
|