Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable support for erc7715 permission with multi-key signer(Passkey and EOA) #636

Merged
merged 32 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c6e09f5
added Local AA Infra toggle
KannuSingh Jul 6, 2024
a7ead01
fix toggling of smartaccount and localAAInfra
KannuSingh Jul 6, 2024
248b5ee
added handling of bundlerUrl, paymasterUrl and public RpcUrl
KannuSingh Jul 6, 2024
a9185bd
handle error condition for local aa infra setup
KannuSingh Jul 6, 2024
19c4b4b
change signerToSafe7579SmartAccount to signerToSafeSmartAccount
KannuSingh Jul 8, 2024
7518799
added capability for foundry chain
KannuSingh Jul 9, 2024
cffb7d9
fix: sendTransaction call
KannuSingh Jul 9, 2024
521aeba
Merge branch 'feat-local-aa-infra-support' into permissionless-safe7579
KannuSingh Jul 9, 2024
76bd3fb
run prettier
KannuSingh Jul 9, 2024
ea47d5c
changed grantPermissions and sendBatchTransaction
KannuSingh Jul 9, 2024
2edf108
cleanup custom signerToSafe7579 implementation
KannuSingh Jul 9, 2024
a870521
added new permission validator address
KannuSingh Jul 10, 2024
5ce01eb
add decodeDIDToPublicKey method
KannuSingh Jul 10, 2024
70d55bf
add webauthn-p256 deps
KannuSingh Jul 12, 2024
db9f64d
updated decodeDIDToPublicKey method
KannuSingh Jul 12, 2024
1ec3d22
change permissionContext for PermissionValidator_v2
KannuSingh Jul 14, 2024
efdd90a
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
KannuSingh Jul 14, 2024
9db9532
fix merge
KannuSingh Jul 14, 2024
a104984
fix: actionId and getDigest read
KannuSingh Jul 14, 2024
45a5d25
fix: grantPermission method
KannuSingh Jul 15, 2024
6663fe3
fix SECP256K1_SIGNATURE_VALIDATOR_ADDRESS error
KannuSingh Jul 15, 2024
3cad803
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
KannuSingh Jul 17, 2024
81e7567
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
KannuSingh Jul 17, 2024
fdf50ab
refactor code
KannuSingh Jul 22, 2024
ff26dac
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
KannuSingh Jul 22, 2024
d5ec209
remove unused import
KannuSingh Jul 22, 2024
138ca5f
chores: code refactor
KannuSingh Jul 24, 2024
6a71d0d
chores:refactor and cleanup
KannuSingh Jul 31, 2024
a22b148
use @biconomy/permission-context-builder package
KannuSingh Aug 6, 2024
d56a653
remove old impl for permissions-validator
KannuSingh Aug 6, 2024
832ea86
update deps
KannuSingh Aug 6, 2024
4c2b9d3
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
KannuSingh Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions advanced/wallets/react-wallet-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx}'"
},
"dependencies": {
"@biconomy/permission-context-builder": "^1.0.9",
"@cosmjs/amino": "0.32.3",
"@cosmjs/encoding": "0.32.3",
"@cosmjs/proto-signing": "0.32.3",
Expand Down Expand Up @@ -40,14 +41,14 @@
"@zerodev/session-key": "5.4.0",
"@zerodev/weighted-ecdsa-validator": "5.3.0",
"borsh": "^1.0.0",
"bs58": "5.0.0",
"bs58": "6.0.0",
"cosmos-wallet": "1.2.0",
"ethers": "5.7.2",
"framer-motion": "6.5.1",
"graphql": "^16.8.2",
"near-api-js": "^0.45.0",
"next": "12.1.5",
"permissionless": "0.1.39",
"permissionless": "0.1.43",
"react": "17.0.2",
"react-code-blocks": "0.1.5",
"react-dom": "17.0.2",
Expand All @@ -56,7 +57,8 @@
"solana-wallet": "^1.0.2",
"tronweb": "^4.4.0",
"valtio": "1.13.2",
"viem": "2.16.2"
"viem": "2.17.8",
"webauthn-p256": "0.0.2"
},
"devDependencies": {
"@types/node": "17.0.35",
Expand All @@ -69,4 +71,4 @@
"prettier": "2.6.2",
"typescript": "5.2.2"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Note: ES6 syntax dont work for this package
import { smartSessionAddress } from '@biconomy/permission-context-builder'
import { ModuleType } from '@rhinestone/module-sdk'
//Note: ES6 syntax dont work for this package
const {
MULTI_FACTOR_VALIDATOR_ADDRESS,
OWNABLE_VALIDATOR_ADDRESS,
Expand All @@ -8,7 +9,6 @@ const {
SCHEDULED_TRANSFERS_EXECUTER_ADDRESS
} = require('@rhinestone/module-sdk') as typeof import('@rhinestone/module-sdk')

export const PERMISSION_VALIDATOR_ADDRESS = '0x6671AD9ED29E2d7a894E80bf48b7Bf03Ee64A0f4'
export type ModuleView =
| 'PermissionValidatorActions'
| 'OwnableValidatorActions'
Expand All @@ -31,7 +31,7 @@ export const supportedModules: Module[] = [
name: 'Permission Validator',
type: 'validator',
url: '/permission-validator',
moduleAddress: PERMISSION_VALIDATOR_ADDRESS,
moduleAddress: smartSessionAddress,
description: `The Permission Validator module is a module that allows DApp to request permissions from a wallet in order to execute transactions on users's behalf that is scoped with permissions`,
moduleData: '0x'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import {
Address,
concat,
concatHex,
createPublicClient,
getTypesForEIP712Domain,
hashTypedData,
Hex,
http,
keccak256,
PrivateKeyAccount,
PublicClient,
toFunctionSelector,
Transport,
TypedDataDefinition,
validateTypedData,
WalletGrantPermissionsParameters,
WalletGrantPermissionsReturnType,
zeroAddress
WalletGrantPermissionsReturnType
} from 'viem'
import { privateKeyToAccount, publicKeyToAddress, signMessage } from 'viem/accounts'
import { EIP155Wallet } from '../EIP155Lib'
Expand All @@ -40,20 +31,10 @@ import {
} from 'permissionless'
import { Chain } from '@/consts/smartAccounts'
import { EntryPoint } from 'permissionless/types/entrypoint'
import {
PERMISSION_VALIDATOR_ADDRESS,
SECP256K1_SIGNATURE_VALIDATOR_ADDRESS
} from '@/utils/permissionValidatorUtils/constants'
import {
getPermissionScopeData,
PermissionContext,
SingleSignerPermission
} from '@/utils/permissionValidatorUtils'
import { KERNEL_V2_4, KERNEL_V3_1 } from '@zerodev/sdk/constants'
import { KERNEL_V2_VERSION_TYPE, KERNEL_V3_VERSION_TYPE } from '@zerodev/sdk/types'
import { decodeDIDToSecp256k1PublicKey } from '@/utils/HelperUtil'
import { KeySigner } from 'viem/_types/experimental/erc7715/types/signer'
import { AccountExecuteAbi } from '@/utils/ERC7579AccountUtils'

type DonutPurchasePermissionData = {
target: string
Expand Down Expand Up @@ -398,104 +379,6 @@ export class KernelSmartAccountLib implements EIP155Wallet {
return currentNonce
}

async issuePermissionContext(
targetAddress: Address,
approvedPermissions: any
): Promise<PermissionContext> {
if (!this.client || !this.client.account) {
throw new Error('Client not initialized')
}
// this permission have dummy policy set to zeroAddress for now,
// bc current version of PermissionValidator_v1 module don't consider checking policy
const permissions: SingleSignerPermission[] = [
{
validUntil: 0,
validAfter: 0,
signatureValidationAlgorithm: SECP256K1_SIGNATURE_VALIDATOR_ADDRESS,
signer: targetAddress,
policy: zeroAddress,
policyData: '0x'
}
]

const permittedScopeData = getPermissionScopeData(permissions, this.chain)
// the smart account sign over the permittedScope and targetAddress
const permittedScopeSignature: Hex = await signMessage({
privateKey: this.getPrivateKey() as `0x${string}`,
message: { raw: concatHex([keccak256(permittedScopeData), targetAddress]) }
})

const nonce = await this.getCurrentNonce()
const validatorAddress = PERMISSION_VALIDATOR_ADDRESS
const validatorInitData = '0x'
const hookAddress = zeroAddress
const hookData = '0x'
const selectorData = toFunctionSelector(AccountExecuteAbi[0])

const validatorPluginEnableTypeData = {
domain: {
name: 'Kernel',
version: '0.3.0-beta',
chainId: this.chain.id,
verifyingContract: this.client.account.address
},
types: {
Enable: [
{ name: 'validationId', type: 'bytes21' },
{ name: 'nonce', type: 'uint32' },
{ name: 'hook', type: 'address' },
{ name: 'validatorData', type: 'bytes' },
{ name: 'hookData', type: 'bytes' },
{ name: 'selectorData', type: 'bytes' }
]
},
message: {
validationId: concat([
'0x01', // indicate secondary type
validatorAddress
]),
nonce: nonce,
hook: hookAddress,
validatorData: validatorInitData as `0x${string}`,
hookData: hookData as `0x${string}`,
selectorData: selectorData
},
primaryType: 'Enable' as 'Enable'
}

const types = {
EIP712Domain: getTypesForEIP712Domain({
domain: validatorPluginEnableTypeData.domain
}),
...validatorPluginEnableTypeData.types
}

// Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
// as we can't statically check this with TypeScript.
validateTypedData({
domain: validatorPluginEnableTypeData.domain,
message: validatorPluginEnableTypeData.message,
primaryType: validatorPluginEnableTypeData.primaryType,
types: types
} as TypedDataDefinition)

const typedHash = hashTypedData(validatorPluginEnableTypeData)

let enableSig = await this.validator!.signMessage({
message: { raw: typedHash }
})

return {
accountType: 'KernelV3',
accountAddress: this.client.account.address,
permissionValidatorAddress: validatorAddress,
permissions: permissions,
permittedScopeData: permittedScopeData,
permittedScopeSignature: permittedScopeSignature,
enableSig: enableSig
}
}

getAccount() {
if (!this.client?.account) {
throw new Error('Client not initialized')
Expand Down
Loading