Skip to content

Commit

Permalink
chore: implement changes requested by Ivan
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeR26 authored and penovicp committed Aug 26, 2024
1 parent 894d9f7 commit 8dea170
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions __tests__/account.outsideExecution.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +10,7 @@ import {
CairoOption,
CairoOptionVariant,
CallData,
EOutsideExecutionVersion,
OutsideExecutionVersion,
type OutsideExecutionOptions,
type OutsideTransaction,
constants,
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Account and OutsideExecution', () => {
callOptions,
21,
[call1],
EOutsideExecutionVersion.V2
OutsideExecutionVersion.V2
);
expect(message).toEqual({
domain: {
Expand Down Expand Up @@ -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);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
} from '../types';
import { ETransactionVersion, ETransactionVersion3, ResourceBounds } from '../types/api';
import {
EOutsideExecutionVersion,
OutsideExecutionVersion,
type OutsideExecution,
type OutsideExecutionOptions,
type OutsideTransaction,
Expand Down Expand Up @@ -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<EOutsideExecutionVersion> {
public async getSnip9Version(): Promise<OutsideExecutionVersion> {
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;
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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<Call>} 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
Expand All @@ -691,7 +691,7 @@ export class Account extends Provider implements AccountInterface {
public async getOutsideTransaction(
options: OutsideExecutionOptions,
calls: AllowArray<Call>,
version?: EOutsideExecutionVersion,
version?: OutsideExecutionVersion,
nonce?: BigNumberish
): Promise<OutsideTransaction> {
if (!isHex(options.caller) && options.caller !== 'ANY_CALLER') {
Expand Down Expand Up @@ -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>} outsideTransaction the signed transaction generated by `Account.getOutsideTransaction()`.
* @param {UniversalDetails} [opts] same options than `Account.execute()`.
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/types/outsideExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface OutsideTransaction {
outsideExecution: OutsideExecution;
signature: Signature;
signerAddress: BigNumberish;
version: EOutsideExecutionVersion;
version: OutsideExecutionVersion;
}

export const OutsideExecutionTypesV1 = {
Expand Down Expand Up @@ -74,7 +74,7 @@ export const OutsideExecutionTypesV2 = {
],
};

export enum EOutsideExecutionVersion {
export enum OutsideExecutionVersion {
UNSUPPORTED = '0',
V1 = '1',
V2 = '2',
Expand Down
16 changes: 8 additions & 8 deletions src/utils/outsideExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -106,7 +106,7 @@ export function getTypedData(
options: OutsideExecutionOptions,
nonce: BigNumberish,
myCalls: Call[],
version: EOutsideExecutionVersion
version: OutsideExecutionVersion
): TypedData {
if (version === '1') {
return {
Expand Down Expand Up @@ -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] }],
* },
Expand Down
6 changes: 3 additions & 3 deletions src/utils/src5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* ```
*/
Expand Down
10 changes: 5 additions & 5 deletions www/docs/guides/outsideExecution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 = {
Expand Down Expand Up @@ -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).
Expand All @@ -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 = {
Expand Down

0 comments on commit 8dea170

Please sign in to comment.