Skip to content

Commit

Permalink
Finish removing session key docs
Browse files Browse the repository at this point in the history
  • Loading branch information
derekchiang authored Oct 27, 2023
1 parent 271729a commit 8723ac4
Showing 1 changed file with 0 additions and 108 deletions.
108 changes: 0 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,114 +416,6 @@ const { hash } = await erc165SessionKeyProvider.sendUserOperation({

### Session Key Validator

```ts
// 1. Get the default ecdsa validator provider
const ecdsaProvider = await ECDSAProvider.init({
projectId, // zeroDev projectId
owner,
});

// 2. Initialize SessionKey Validator Provider
const sessionKey = LocalAccountSigner.privateKeyToAccountSigner(<SESSION_PRIVATE_KEY>);
const accountAddress = await ecdsaProvider.getAccount().getAddress();
const sig = getFunctionSelector(
"transfer(address, uint256)"
)
const permissions = [
getPermissionFromABI({
target: <ERC20Address>, // address of the target contract,
valueLimit: 0n, // max value the session key can use in tx -- (Default: 0)
operation: Operation.Call, // The kind of call session key can make CALL/DELEGATECALL (Default: Operation.Call)
abi: TEST_ERC20Abi, // Abi of the target contract
functionName: "transfer", // The function that can be called on the target contract
args: [<SPECIFIC_ADDRESS>, 10000n], // The value to check in condition
conditions: [
ParamCondition.EQUAL,
ParamCondition.LESS_THAN_OR_EQUAL,
], // The condition to check

// To allows specific params to not have any condition pass `null` in the param position in the `args` and `conditions` like below:

// args: [<SPECIFIC_ADDRESS>, null], // The value to check in condition
// conditions: [
// ParamCondition.EQUAL,
// null
// ], // The condition to check
})
]

const sessionKeyProvider = await SessionKeyProvider.init({
projectId, //ZeroDevProject
defaultProvider: ecdsaProvider, // Pass the ECDSAProvider as default provider
sessionKey, // Session Key Signer
sessionKeyData: {
validAfter: 0, // (Default: 0)
validUntil: 0, // (Default: 0)
permissions,
paymaster, // Paymaster Address : zeroAddress means accept userOp without paymaster, oneAddress means reject userOp without paymaster, other address means accept userOp with paymaster with the address // (Default: zeroAddress)
}
});

// 3. Send the transaction
const { hash } = await sessionKeyProvider.sendUserOperation({
target: ERC20Address,
data: encodeFunctionData({
abi: TEST_ERC20Abi,
functionName: "transfer",
args: ["RECIPIENT_ADDRESS", "AMOUNT_TO_TRANSFER"],
}),
});
```

> **_NOTE:_** If you are using ERC20 Token Paymaster along with Session Key then make sure to also whitelist the Multisend contract address and function selector in the permissions alongwith with end contract permission as below.
```ts
import { constants, MultiSendAbi } from "@zerodev/sdk";

// Permission object to pass in the `sessionKeyData.permissions` array
const permissions = [
...,
getPermissionFromABI({
target: MULTISEND_ADDR,
abi: MultiSendAbi,
functionName: "multiSend",
operation: Operation.DelegateCall
}),
]
```

#### Creating Session Key on the server and using it on the client side

```ts
// 1. Initilize the session key provider
const sessionKeyProvider = await SessionKeyProvider.init({
projectId, //ZeroDevProject
defaultProvider: ecdsaProvider,
sessionKey, // Session Key Signer
sessionKeyData: {
validAfter: 0,
validUntil: 0,
permissions,
paymaster, // Paymaster Address : zeroAddress means accept userOp without paymaster, oneAddress means reject userOp without paymaster, other address means accept userOp with paymaster with the address
}
});

// 2. Serialize the session key params with the private key and send it to the client
const serializedSessionKeyParams = await sessionKeyProvider.serializeSessionKeyParams(<SESSION_PRIVATE_KEY>);

// On client side
// 3. Deserialize the session key params
const sessionKeyParams = SessionKeyProvider.deserializeSessionKeyParams(serializedSessionKeyParams);

// 4 Initialize the SessionKey Provider from the session key params
const sessionKeyProvider = await SessionKeyProvider.fromSessionKeyParams({
projectId, //ZeroDevProject
sessionKeyParams
});
```

#### Creating Session Key on the client and approving on the server

[Please check out the session key docs here.](https://docs.zerodev.app/use-wallets/use-session-keys)

### Recovery Key Validator
Expand Down

0 comments on commit 8723ac4

Please sign in to comment.