Brief Intro
This Aspect will recover the signer address from the transaction signature (r,s,v).
Then, it verifies whether the signer is the session key of the EoA; if so, it will return the EoA address to the base layer.
The base layer retrieves the address and sets it as the sender of this transaction.
Project Layout
.
├── README.md
├── asconfig.json
├── assembly
│ ├── aspect <-- aspect code resides here
│ │ └── aspect.ts <-- entry functions for the aspect
│ └── index.ts
├── test_contracts <-- smart contracts for testing
├── tests <-- test
├── scripts <-- utilitity scripts, including deploying, binding and etc.
│ ├── aspect-deploy.cjs
│ ├── bind.cjs
│ ├── contract-call.cjs
│ └── contract-deploy.cjs
...
Quick start
It's a node.js project, so install the dependency first.
npm install
Build the Aspect and the testing smart contract.
npm run build
Create a testing wallet.
npm run account:create
The private key will be put in the file privateKey.txt.
The wallet address will be printed in the console, copy and require testnet $ART by this faucet guide.
If you want to use your own test net wallet, you can create the file
privateKey.txtand paste your private key into it. The private key format is a hex string like this0xabcd....abcd.
Run the test!!
npm run test
The script will run the test in the folder tests; you can run the specific case like this command node tests/test_tx. js.
Implements Intro
- The function
verifyTximplements the session key verification logic. - The function
operationimplements the session key management logic. EoA calls this function to register, update, and delete its session keys.
Usage Testnet Session-key Aspect
Session-key Aspect address (testnet)
lastest version: 0x40a908F327B22922983061E9E6a87e785d6401BB
Requirement
The smart contract needs to bind this Aspect to enable the session key feature for its users.
If a smart contract wants to bind any Aspect, it MUST implement the isOwner(address) method. Only the owner wallet can sign the binding transaction for its smart contract.
Bind Aspect
There are two ways to bind Aspects:
- Use
Aspect-toolconsole command - Use
artela-web3.jsto call Aspect system contract
Use Aspect-tool
In this way, you can bind Aspect by console command.
Step 1: install aspect-tool
npm install @artela/aspect-tool -g
Step 2: init a empty project
mkdir empty-aspect && cd empty-aspect
aspect-tool init
npm install yargs
Step 3: use the script in this project
npm run contract:bind -- --pkfile {smart-contract-owner-privateKey-path} --contract {smart-contract-address} --abi {smart-contract-abi-path} --aspectId '0x40a908F327B22922983061E9E6a87e785d6401BB' --gas '800000'
Learn more detailed steps in this guide.
Use artela-web3.js
In this way, you need to write js script. Follow this guide to bind your smart contract to Aspect by using web3.js in js.
Here are brief steps:
- using your
contract addressandabiconstruct a contract object byweb3.eth.contract - using
web3.eth.contract.bind(options, callback)to send tx to bind specific Aspect
Example:
await contract.bind({
priority: 1, // <-- Priority of the aspect, int8 number, smaller number has higher priority. Aspect with higher priority will be executed first.
aspectId: "0xABCD....ABCD", // <-- address of the aspect to bind with the contract, eg.
aspectVersion: 1, // <-- Version of the aspect to bind with the contract
}).send({ from: accounts[0], nonce, ...sendOptions });
Learn more detailed steps in this guide.