diff --git a/__tests__/account.outsideExecution.test.ts b/__tests__/account.outsideExecution.test.ts index 966286323..d7c758932 100644 --- a/__tests__/account.outsideExecution.test.ts +++ b/__tests__/account.outsideExecution.test.ts @@ -1,4 +1,4 @@ -// Is tested here the most common case : an account compatible with ERC165 and SNIP-9 (v2). +// We test here the most common case: an account compatible with ERC-165 and SNIP-9 (v2). // To limit test duration, these cases are not tested: non ERC165 account, non SNIP-9 account, SNIP9-v1 account. import { Provider, @@ -10,7 +10,7 @@ import { CairoOption, CairoOptionVariant, CallData, - EOutsideExecutionVersion, + OutsideExecutionVersion, type OutsideExecutionOptions, type OutsideTransaction, constants, @@ -107,7 +107,7 @@ describe('Account and OutsideExecution', () => { callOptions, 21, [call1], - EOutsideExecutionVersion.V2 + OutsideExecutionVersion.V2 ); expect(message).toEqual({ domain: { @@ -200,7 +200,7 @@ describe('Account and OutsideExecution', () => { }, signature: ['0x123', '0x456'], signerAddress: '0x3b278ebae434f283f9340587a7f2dd4282658ac8e03cb9b0956db23a0a83657', - version: EOutsideExecutionVersion.V2, + version: OutsideExecutionVersion.V2, }; const execute: Calldata = outsideExecution.buildExecuteFromOutsideCallData(outsideTransaction); @@ -222,7 +222,7 @@ describe('Account and OutsideExecution', () => { }); test('Signer account should support SNIP-9 v2', async () => { - expect(await signerAccount.getSnip9Version()).toBe(EOutsideExecutionVersion.V2); + expect(await signerAccount.getSnip9Version()).toBe(OutsideExecutionVersion.V2); }); test('SNIP-9 nonce', async () => { @@ -285,7 +285,7 @@ describe('Account and OutsideExecution', () => { callOptions, call3 ); // designated caller - expect(outsideTransaction3.version).toBe(EOutsideExecutionVersion.V2); + expect(outsideTransaction3.version).toBe(OutsideExecutionVersion.V2); expect(outsideTransaction1.signerAddress).toBe(signerAccount.address); expect(outsideTransaction3.outsideExecution.caller).toBe(constants.OutsideExecutionCallerAny); expect(outsideTransaction1.outsideExecution.caller).toBe(executorAccount.address); diff --git a/src/account/default.ts b/src/account/default.ts index 2feee6d14..951246743 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -48,7 +48,7 @@ import { } from '../types'; import { ETransactionVersion, ETransactionVersion3, ResourceBounds } from '../types/api'; import { - EOutsideExecutionVersion, + OutsideExecutionVersion, type OutsideExecution, type OutsideExecutionOptions, type OutsideTransaction, @@ -599,22 +599,22 @@ export class Account extends Provider implements AccountInterface { /** * Verify if an account is compatible with SNIP-9 outside execution, and with which version of this standard. - * @returns {EOutsideExecutionVersion} Not compatible, V1, V2. + * @returns {OutsideExecutionVersion} Not compatible, V1, V2. * @example * ```typescript * const result = myAccount.getSnip9Version(); * // result = "V1" * ``` */ - public async getSnip9Version(): Promise { + public async getSnip9Version(): Promise { if (await supportsInterface(this, this.address, SNIP9_V2_INTERFACE_ID)) { - return EOutsideExecutionVersion.V2; + return OutsideExecutionVersion.V2; } if (await supportsInterface(this, this.address, SNIP9_V1_INTERFACE_ID)) { - return EOutsideExecutionVersion.V1; + return OutsideExecutionVersion.V1; } // Account does not support either version 2 or version 1 - return EOutsideExecutionVersion.UNSUPPORTED; + return OutsideExecutionVersion.UNSUPPORTED; } /** @@ -643,7 +643,7 @@ export class Account extends Provider implements AccountInterface { /** * Outside transaction needs a specific SNIP-9 nonce, that we get in this function. - * A SNIP-9 nonce can be any number not yet used ; no ordering needs. + * A SNIP-9 nonce can be any number not yet used ; no ordering is needed. * @returns {string} an Hex string of a SNIP-9 nonce. * @example * ```typescript @@ -664,7 +664,7 @@ export class Account extends Provider implements AccountInterface { * Creates an object containing transaction(s) that can be executed by an other account with` Account.executeFromOutside()`, called Outside Transaction. * @param {OutsideExecutionOptions} options Parameters of the transaction(s). * @param {AllowArray} calls Transaction(s) to execute. - * @param {EOutsideExecutionVersion} [version] SNIP-9 version of the Account that creates the outside transaction. + * @param {OutsideExecutionVersion} [version] SNIP-9 version of the Account that creates the outside transaction. * @param {BigNumberish} [nonce] Outside Nonce. * @returns {OutsideTransaction} and object that can be used in `Account.executeFromOutside()` * @example @@ -691,7 +691,7 @@ export class Account extends Provider implements AccountInterface { public async getOutsideTransaction( options: OutsideExecutionOptions, calls: AllowArray, - version?: EOutsideExecutionVersion, + version?: OutsideExecutionVersion, nonce?: BigNumberish ): Promise { if (!isHex(options.caller) && options.caller !== 'ANY_CALLER') { @@ -732,7 +732,7 @@ export class Account extends Provider implements AccountInterface { } /** - * An account B execute a transaction that has been signed by an account A. + * An account B executes a transaction that has been signed by an account A. * Fees are paid by B. * @param {AllowArray} outsideTransaction the signed transaction generated by `Account.getOutsideTransaction()`. * @param {UniversalDetails} [opts] same options than `Account.execute()`. @@ -757,9 +757,9 @@ export class Account extends Provider implements AccountInterface { : [outsideTransaction]; const multiCall: Call[] = myOutsideTransactions.map((outsideTx: OutsideTransaction) => { let entrypoint: string; - if (outsideTx.version === EOutsideExecutionVersion.V1) { + if (outsideTx.version === OutsideExecutionVersion.V1) { entrypoint = 'execute_from_outside'; - } else if (outsideTx.version === EOutsideExecutionVersion.V2) { + } else if (outsideTx.version === OutsideExecutionVersion.V2) { entrypoint = 'execute_from_outside_v2'; } else { throw new Error('Unsupported OutsideExecution version'); diff --git a/src/types/outsideExecution.ts b/src/types/outsideExecution.ts index 2eced6aed..d62d3c9f9 100644 --- a/src/types/outsideExecution.ts +++ b/src/types/outsideExecution.ts @@ -27,7 +27,7 @@ export interface OutsideTransaction { outsideExecution: OutsideExecution; signature: Signature; signerAddress: BigNumberish; - version: EOutsideExecutionVersion; + version: OutsideExecutionVersion; } export const OutsideExecutionTypesV1 = { @@ -74,7 +74,7 @@ export const OutsideExecutionTypesV2 = { ], }; -export enum EOutsideExecutionVersion { +export enum OutsideExecutionVersion { UNSUPPORTED = '0', V1 = '1', V2 = '2', diff --git a/src/utils/outsideExecution.ts b/src/utils/outsideExecution.ts index c4bd53ed9..392229dec 100644 --- a/src/utils/outsideExecution.ts +++ b/src/utils/outsideExecution.ts @@ -3,7 +3,7 @@ import { Call, type BigNumberish, type Calldata } from '../types/lib'; import { OutsideExecutionTypesV1, OutsideExecutionTypesV2, - type EOutsideExecutionVersion, + type OutsideExecutionVersion, type OutsideCall, type OutsideExecutionOptions, type OutsideTransaction, @@ -42,7 +42,7 @@ export function getOutsideCall(call: Call): OutsideCall { } /** represents a call object as a typed data, supporting both v1 and v2 versions */ -function callToTypedData(call: Call, version: EOutsideExecutionVersion) { +function callToTypedData(call: Call, version: OutsideExecutionVersion) { const outsideCall = getOutsideCall(call); if (version === '1') { return { @@ -58,7 +58,7 @@ function callToTypedData(call: Call, version: EOutsideExecutionVersion) { }; } -function getDomain(chainId: string, version: EOutsideExecutionVersion) { +function getDomain(chainId: string, version: OutsideExecutionVersion) { return { name: 'Account.execute_from_outside', version, @@ -71,9 +71,9 @@ function getDomain(chainId: string, version: EOutsideExecutionVersion) { * Build a TypedData message that will be used for an Outside execution. * @param {string} chainId The encoded string of the name of network. * @param {OutsideExecutionOptions} options Parameters related to an Outside Execution. - * @param {BigNumberish} nonce Outside execution nonce (to not confuse with normal transaction nonce). + * @param {BigNumberish} nonce Outside execution nonce (not to confuse with normal transaction nonce). * @param {Call[]} myCalls transaction(s) to proceed. - * @param {EOutsideExecutionVersion} version SNIP-9 V1 or V2. + * @param {OutsideExecutionVersion} version SNIP-9 V1 or V2. * @returns {TypedData} SNIP-12 message conform to SNIP-9. * @example * ```typescript @@ -106,7 +106,7 @@ export function getTypedData( options: OutsideExecutionOptions, nonce: BigNumberish, myCalls: Call[], - version: EOutsideExecutionVersion + version: OutsideExecutionVersion ): TypedData { if (version === '1') { return { @@ -137,14 +137,14 @@ export function getTypedData( /** * Builds a CallData for the execute_from_outside() entrypoint. - * @param {OutsideTransaction} outsideTransaction an object that all the data for a Outside Execution. + * @param {OutsideTransaction} outsideTransaction an object that contains all the data for a Outside Execution. * @returns {Calldata} The Calldata related to this Outside transaction * @example * ```typescript * const outsideTransaction: OutsideTransaction = { * outsideExecution: { * caller: '0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691', - * nonce: '0x7d0b4b4fce4b236e63d2bb5fc321935d52935cd3b268248cf9cf29c496bd0ae', + * nonce: '0x7d0b4b4fce4b236e63d2bb5fc321935d52935cd3b268248cf9cf29c496bd0ae', * execute_after: 500, execute_before: 600, * calls: [{ to: '0x678', selector: '0x890', calldata: [12, 13] }], * }, diff --git a/src/utils/src5.ts b/src/utils/src5.ts index 2006f5752..4300b8eed 100644 --- a/src/utils/src5.ts +++ b/src/utils/src5.ts @@ -7,12 +7,12 @@ import { toHex } from './num'; * Verify if a contract has implemented some standard functionalities. * @param {RpcProvider} provider the provider to access to Starknet. * @param {BigNumberish} contractAddress the address of the contract to check. - * @param {BigNumberish} interfaceId the hash of the functionally to check. - * @returns {boolean} true if the interfaceId is implement in this contract. + * @param {BigNumberish} interfaceId the hash of the functionality to check. + * @returns {boolean} true if the interfaceId is implemented in this contract. * @example * ```typescript * const snip9InterfaceV2Id = constants.SNIP9_V2_INTERFACE_ID; - * const result = src5.supportInterface(myProvider, accountContractAddress, snip9InterfaceV2Id); + * const result = src5.supportsInterface(myProvider, accountContractAddress, snip9InterfaceV2Id); * // result = true * ``` */ diff --git a/www/docs/guides/outsideExecution.md b/www/docs/guides/outsideExecution.md index d63be2f6d..313159603 100644 --- a/www/docs/guides/outsideExecution.md +++ b/www/docs/guides/outsideExecution.md @@ -39,7 +39,7 @@ if (version === EOutsideExecutionVersion.UNSUPPORTED) { :::info The account that will sign the transaction needs to be compatible with SNIP-9. -Nevertheless, the account that will execute the transaction do not needs to be SNIP-9 compatible ; it needs just to have enough fees to pay the transaction. +Nevertheless, the account that will execute the transaction do not needs to be SNIP-9 compatible ; it just needs to have enough fees to pay the transaction. ::: ### Create an `OutsideTransaction` Object @@ -74,7 +74,7 @@ const callOptions: OutsideExecutionOptions = { You can use the string `"ANY_CALLER"` as content of the `caller` property. To use with care, as anybody that get your `OutsideTransaction` object and execute it. ::: -To create the `OutsideTransaction` object, you have just to use: +To create the `OutsideTransaction` object, you just have to use: ```typescript const outsideTransaction1: OutsideTransaction = await signerAccount.getOutsideTransaction( @@ -84,7 +84,7 @@ const outsideTransaction1: OutsideTransaction = await signerAccount.getOutsideTr ``` :::note -In the same `OutsideTransaction` object, you can include several transactions. So, with only one signature of the signer Account, you can generates an `OutsideTransaction` object that perform many things: +In the same `OutsideTransaction` object, you can include several transactions. So, with only one signature of the signer Account, you can generate an `OutsideTransaction` object that performs many things: ```typescript const callOptions: OutsideExecutionOptions = { @@ -150,7 +150,7 @@ const res = await executorAccount.executeFromOutside([outsideTransaction1, outsi ## Example of Outside Execution using a Ledger Nano In this example, we want to sign, with a Ledger Nano X, several transactions at 6PM. Then a code is automatically launched each hour until the next day at 8AM, verifying if some conditions are reached. The code will then trigger the execution of some of the transactions signed earlier with the Ledger Nano. -By this way, you can pre-sign some transactions with the Ledger, and if during the night something occur, a backend can execute automatically some of these transactions, **in any order**. +By this way, you can pre-sign some transactions with the Ledger, and if during the night something occurs, a backend can execute automatically some of these transactions, **in any order**. In this process, **the private key of the Ledger account is never exposed**. First, create a Ledger account in devnet-rs. You will find some documentation [here](./signature.md#signing-with-a-ledger-hardware-wallet), and an example [here](https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/ledgerNano/4.deployLedgerAccount.ts). @@ -164,7 +164,7 @@ The initial balances are : | Account1 | 1000.0 | | Account2 | 1000.0 | -Now, we can ask to the user to sign on its Ledger some outside transactions : +Now, we can ask the user to sign on its Ledger some outside transactions: ```typescript const callOptions: OutsideExecutionOptions = {