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.
.
├── 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
...
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.txt
and 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
.
- The function
verifyTx
implements the session key verification logic. - The function
operation
implements the session key management logic. EoA calls this function to register, update, and delete its session keys.
lastest version: 0x06786bB59719d7DDD9D42457a16BbCD6953A7cab
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.
There are three ways to bind Aspects:
- Use
Aspect-tool
console command - Use
artela-web3.js
to call Aspect system contract - Use online visual dashboard to bind Session key aspect to your contract
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.
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 address
andabi
construct 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.
Access https://session-key-aspect.vercel.app/ to bind your contract by metamask!