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

add experimental/smart-session #2875

Merged
merged 90 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e920b96
add enableSmartSession option
KannuSingh Sep 18, 2024
4a5a308
enableSmartSession flag in initControllers
KannuSingh Sep 18, 2024
db1f0ee
add request() on ConnectionControllerClient and its impl
KannuSingh Sep 18, 2024
f6c90a7
init experimental package
KannuSingh Sep 19, 2024
8a46f60
remove experimental package
KannuSingh Sep 19, 2024
99923d0
create experimental/smart-session package
KannuSingh Sep 19, 2024
fe0413d
add @reown/appkit-experimental-smart-session deps
KannuSingh Sep 19, 2024
4f59ff0
fix:build adapters/solana
KannuSingh Sep 19, 2024
a5f2f13
update package.json to include experimental/* packages
KannuSingh Sep 19, 2024
f234608
changed method `request` to `grantPermissions`
KannuSingh Sep 19, 2024
54c0009
export useSmartSession hook
KannuSingh Sep 20, 2024
54999b7
chores:run prettier
KannuSingh Sep 20, 2024
022cd63
update lab permissions test implementation
KannuSingh Sep 20, 2024
bbe2100
Merge branch 'main' into feat/add-smartSession
KannuSingh Sep 20, 2024
6fbcc2c
declare dev dependencies for smart-session package
KannuSingh Sep 20, 2024
cc32065
use @chakra-ui/react: "2.8.1"
KannuSingh Sep 20, 2024
4ce10d3
chores:refactor code
KannuSingh Sep 20, 2024
0bb78f9
chore:fix purchaseDonutPermissions signer
KannuSingh Sep 20, 2024
ee7d21d
chores:run prettier
KannuSingh Sep 20, 2024
50f2e57
Merge branch 'main' of github.com:WalletConnect/web3modal into feat/a…
tomiir Sep 20, 2024
916ffab
feat: add method to optional methods and fix grantPermissions handler…
tomiir Sep 20, 2024
90b1694
update smart session types to latest
KannuSingh Sep 20, 2024
68f70ed
added tests
KannuSingh Sep 21, 2024
654a5a2
chores: run prettier
KannuSingh Sep 21, 2024
827297a
Update package.json
KannuSingh Sep 21, 2024
edd815f
chores: remove loose dependencies and refactor code
KannuSingh Sep 21, 2024
f21fa30
Update .eslintrc.json
KannuSingh Sep 21, 2024
9e14919
chores:fix lint errors
KannuSingh Sep 21, 2024
0eb2d88
chores: type fixs
KannuSingh Sep 21, 2024
5fa8b09
useSmartSession hook
KannuSingh Sep 24, 2024
683173c
chores: fix permissions
KannuSingh Sep 24, 2024
818ef8d
chores:fix test
KannuSingh Sep 24, 2024
245ba75
chores: remove comment and unused import
KannuSingh Sep 24, 2024
81f9614
Merge branch 'main' into feat/add-smartSession
KannuSingh Sep 24, 2024
c03b6b4
chores:fix loose deps
KannuSingh Sep 24, 2024
6ad2698
remove smart-session feature flag
KannuSingh Sep 26, 2024
4ef9048
restructured experimental package
KannuSingh Sep 26, 2024
40e1c7d
update appkit-experimental deps on lab
KannuSingh Sep 26, 2024
c9087a7
remove WalletConnectCosignerUtils from lab
KannuSingh Sep 26, 2024
8838f76
update UserOpBuilderServiceUtils with new spec(prepareCalls and sendP…
KannuSingh Sep 26, 2024
17afa85
update donutContract address(same address on base-sepolia/sepolia))
KannuSingh Sep 26, 2024
392eb42
fix/refactor wagmi test for permissions
KannuSingh Sep 26, 2024
88df5c6
chore: adding sample wallet preview url
KannuSingh Sep 26, 2024
3799a8b
Merge branch 'main' into feat/add-smartSession
KannuSingh Sep 26, 2024
19ede68
change networks for wagmi-permissions-sync test
KannuSingh Sep 27, 2024
00c4d70
change export path for smart-session
KannuSingh Sep 27, 2024
28dd04d
update sample-wallet preview url
KannuSingh Sep 27, 2024
a65b76e
ConnectionController: update grantPermissions param type
KannuSingh Sep 27, 2024
98bd276
Update SmartSessionGrantPermissionsResponse type
KannuSingh Sep 27, 2024
4db86b2
chore: remove unused values
KannuSingh Sep 27, 2024
5268f96
chores: add explanation comments and refactor code
KannuSingh Sep 27, 2024
948f9e3
added more tests
KannuSingh Sep 27, 2024
428d9db
chore: remove unused/unsupported types
KannuSingh Sep 27, 2024
a51c9a4
chore: fix test
KannuSingh Sep 27, 2024
f056ca3
added ContractCallPermission types and validator
KannuSingh Sep 27, 2024
e4dc6d0
updated the tests
KannuSingh Sep 27, 2024
a64ce4a
updated donutPurchasePermission on lab
KannuSingh Sep 27, 2024
d279399
chore: remove unnecessary deps
KannuSingh Sep 27, 2024
2584e68
updated validation using zod schema
KannuSingh Sep 30, 2024
58a7f85
chore: fix package.json
KannuSingh Oct 1, 2024
5e961bd
chore: remove log
KannuSingh Oct 1, 2024
4257efe
update legacy repo url
KannuSingh Oct 1, 2024
6abdf65
remove WalletConnect reference
KannuSingh Oct 1, 2024
2a5f53d
remove changes on next.config.mjs
KannuSingh Oct 1, 2024
a609cc1
chore: remove WC reference in ConstantUtils.ts
KannuSingh Oct 1, 2024
343e58e
chore: update userOpService urls
KannuSingh Oct 1, 2024
3136c54
chores: remove comments
KannuSingh Oct 1, 2024
5726e18
fix: unused variable
KannuSingh Oct 1, 2024
ea0d7d0
chore: refactor lab permissions tests implementation
KannuSingh Oct 1, 2024
19f3cb1
chores: asset CosignerService.addPermissions response, change error t…
KannuSingh Oct 1, 2024
42a40ba
fix: SmartSessionGrantedPermissionsInfo component
KannuSingh Oct 2, 2024
0baeb41
fix: disable buttons logic on requestPermissions component
KannuSingh Oct 2, 2024
bdbfa0e
chores: add suggested changes
KannuSingh Oct 2, 2024
c625158
Added getCapabilities rpc method on client
KannuSingh Oct 3, 2024
327b8e1
add isSmartSessionSupported method
KannuSingh Oct 3, 2024
afe8e9c
update tests in experimental package
KannuSingh Oct 3, 2024
99dcfca
isSmartSessionSupported: return true if !provider.isWaletConnect
KannuSingh Oct 3, 2024
c5c68b5
updated lab to use experimental/smart-session
KannuSingh Oct 3, 2024
67ff5da
chores: update types and const
KannuSingh Oct 3, 2024
517df99
Merge branch 'main' into feat/add-smartSession
KannuSingh Oct 3, 2024
3638b49
fix: solana client
KannuSingh Oct 3, 2024
4d0280e
chores: pnpm install and run prettier
KannuSingh Oct 3, 2024
83d0555
fix: experimental/smart-session test
KannuSingh Oct 3, 2024
44bdb21
chores: remove loose dependency
KannuSingh Oct 3, 2024
b27adfc
Update readme.md
KannuSingh Oct 7, 2024
7d82d57
Merge branch 'main' into feat/add-smartSession
KannuSingh Oct 7, 2024
865ff20
Update pnpm-lock.yaml
KannuSingh Oct 7, 2024
824ef9a
Merge branch 'main' into feat/add-smartSession
KannuSingh Oct 7, 2024
25b8097
Update pnpm-lock.yaml
KannuSingh Oct 7, 2024
e8766c5
fix: AppKitNetwork for wagmi-permissions test
KannuSingh Oct 7, 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
2 changes: 2 additions & 0 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@
"@reown/appkit-solana": "workspace:*",
"@reown/appkit-wagmi": "workspace:*",
"@reown/appkit-wallet": "workspace:*",
"@reown/appkit-experimental": "workspace:*",
"@reown/appkit-adapter-solana": "workspace:*",
"@reown/appkit-adapter-ethers": "workspace:*",
"@reown/appkit-adapter-ethers5": "workspace:*",
"@reown/appkit-adapter-wagmi": "workspace:*",
"axios": "1.7.2",
"bs58": "6.0.0",
"date-fns": "4.1.0",
"ethers": "6.13.2",
"ethers5": "npm:[email protected]",
"framer-motion": "10.17.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react'
import { StackDivider, Heading, Box, Stack, Text } from '@chakra-ui/react'
import { getChain } from '../utils/NetworksUtil'
import { formatDistanceToNow } from 'date-fns'
import type { SmartSessionGrantPermissionsResponse } from '@reown/appkit-experimental/smart-session'

export function SmartSessionGrantedPermissionsInfo({
grantedPermissions
}: {
grantedPermissions: SmartSessionGrantPermissionsResponse | undefined
}) {
if (!grantedPermissions?.context) {
return (
<Text fontSize="md" color="yellow">
Dapp does not have any stored permissions
</Text>
)
}

const { address, chainId, expiry } = grantedPermissions
const parsedExpiry = formatDistanceToNow(new Date(expiry * 1000), { addSuffix: true })
const parsedChainId = parseInt(chainId, 16)
const chain = getChain(parsedChainId)

return (
<Stack direction={['column', 'column', 'row']} divider={<StackDivider />} spacing="4">
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Account Address
</Heading>
<Text>{address}</Text>
</Box>
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Chain Id
</Heading>
<Text>{chain?.name || chainId}</Text>
</Box>
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Expiry
</Heading>
<Text>{parsedExpiry}</Text>
</Box>
</Stack>
)
}
12 changes: 12 additions & 0 deletions apps/laboratory/src/components/Wagmi/WagmiPermissionsAsyncTest.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { Box, Card, CardBody, CardHeader, Heading, Stack, StackDivider } from '@chakra-ui/react'
import { WagmiRequestPermissionsAsyncTest } from './WagmiRequestPermissionsAsyncTest'
import { WagmiPurchaseDonutAsyncPermissionsTest } from './WagmiPurchaseDonutAsyncPermissionsTest'
import { SmartSessionGrantedPermissionsInfo } from '../SmartSessionGrantedPermissionsInfo'
import { useERC7715Permissions } from '../../hooks/useERC7715Permissions'

export function WagmiPermissionsAsyncTest() {
const { smartSession } = useERC7715Permissions()
const grantedPermissions =
smartSession?.type === 'async' ? smartSession.grantedPermissions : undefined

return (
<Card marginTop={10} marginBottom={10}>
<CardHeader>
<Heading size="md">Test Interactions</Heading>
</CardHeader>
<CardBody>
<Stack divider={<StackDivider />} spacing="4">
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Existing Session Information
</Heading>
<SmartSessionGrantedPermissionsInfo grantedPermissions={grantedPermissions} />
</Box>
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Request Permissions
Expand Down
12 changes: 12 additions & 0 deletions apps/laboratory/src/components/Wagmi/WagmiPermissionsSyncTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ import { Box, Card, CardBody, CardHeader, Heading, Stack, StackDivider } from '@
import { WagmiRequestPermissionsSyncTest } from './WagmiRequestPermissionsSyncTest'
import { WagmiPurchaseDonutSyncPermissionsTest } from './WagmiPurchaseDonutSyncPermissionsTest'
import { WagmiCreatePasskeySignerTest } from './WagmiCreatePasskeySignerTest'
import { SmartSessionGrantedPermissionsInfo } from '../SmartSessionGrantedPermissionsInfo'
import { useERC7715Permissions } from '../../hooks/useERC7715Permissions'

export function WagmiPermissionsSyncTest() {
const { smartSession } = useERC7715Permissions()
const grantedPermissions =
smartSession?.type === 'sync' ? smartSession.grantedPermissions : undefined

return (
<Card marginTop={10} marginBottom={10}>
<CardHeader>
<Heading size="md">Test Interactions</Heading>
</CardHeader>
<CardBody>
<Stack divider={<StackDivider />} spacing="4">
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Existing Session Information
</Heading>
<SmartSessionGrantedPermissionsInfo grantedPermissions={grantedPermissions} />
</Box>
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
New Passkey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@ import { useState } from 'react'
import { useChakraToast } from '../Toast'
import { encodeFunctionData, parseEther } from 'viem'
import { abi as donutContractAbi, address as donutContractaddress } from '../../utils/DonutContract'
import { sepolia } from 'viem/chains'
import { useLocalEcdsaKey } from '../../context/LocalEcdsaKeyContext'
import { useERC7715Permissions } from '../../hooks/useERC7715Permissions'
import { executeActionsWithECDSAAndCosignerPermissions } from '../../utils/ERC7715Utils'
import { executeActionsWithECDSAKey } from '../../utils/ERC7715Utils'
import { getChain } from '../../utils/NetworksUtil'
import type { SmartSessionGrantPermissionsResponse } from '@reown/appkit-experimental/smart-session'

export function WagmiPurchaseDonutAsyncPermissionsTest() {
const { privateKey } = useLocalEcdsaKey()
const { smartSession } = useERC7715Permissions()

if (smartSession?.type !== 'async' || !smartSession.grantedPermissions?.context) {
return (
<Text fontSize="md" color="yellow">
Dapp does not have the permissions
</Text>
)
}

const { grantedPermissions, pci } = useERC7715Permissions()
return <ConnectedTestContent grantedPermissions={smartSession.grantedPermissions} />
}

function ConnectedTestContent({
grantedPermissions
}: {
grantedPermissions: SmartSessionGrantPermissionsResponse
}) {
const { privateKey } = useLocalEcdsaKey()
const toast = useChakraToast()
const [isTransactionPending, setTransactionPending] = useState<boolean>(false)

const {
data: donutsOwned,
Expand All @@ -23,24 +42,24 @@ export function WagmiPurchaseDonutAsyncPermissionsTest() {
abi: donutContractAbi,
address: donutContractaddress,
functionName: 'getBalance',
args: [grantedPermissions?.signerData?.submitToAddress || '0x']
args: [grantedPermissions.address]
})

const [isTransactionPending, setTransactionPending] = useState<boolean>(false)
const toast = useChakraToast()

async function onPurchaseDonutWithPermissions() {
setTransactionPending(true)
try {
if (!privateKey) {
throw new Error(`Unable to get dApp private key`)
const chainId = parseInt(grantedPermissions.chainId, 16)
if (!chainId) {
throw new Error('Chain ID not available in granted permissions')
}
if (!grantedPermissions) {
throw Error('No permissions available')
const chain = getChain(chainId)
if (!chain) {
throw new Error('Unknown chainId')
}
if (!pci) {
throw Error('No WC cosigner data(PCI) available')
if (!privateKey) {
throw new Error(`Unable to get dApp private key`)
}

const purchaseDonutCallData = encodeFunctionData({
abi: donutContractAbi,
functionName: 'purchase',
Expand All @@ -53,12 +72,12 @@ export function WagmiPurchaseDonutAsyncPermissionsTest() {
data: purchaseDonutCallData
}
]
const txHash = await executeActionsWithECDSAAndCosignerPermissions({
const txHash = await executeActionsWithECDSAKey({
actions: purchaseDonutCallDataExecution,
chain: sepolia,
chain,
ecdsaPrivateKey: privateKey as `0x${string}`,
permissions: grantedPermissions,
pci
accountAddress: grantedPermissions.address,
permissionsContext: grantedPermissions.context
})
if (txHash) {
toast({
Expand All @@ -77,16 +96,9 @@ export function WagmiPurchaseDonutAsyncPermissionsTest() {
}
setTransactionPending(false)
}
if (!grantedPermissions) {
return (
<Text fontSize="md" color="yellow">
Dapp does not have the permissions
</Text>
)
}

return (
<Stack direction={['column', 'column', 'row']}>
<Stack direction={['column']}>
<Button
isDisabled={!grantedPermissions}
isLoading={isTransactionPending}
Expand All @@ -99,7 +111,7 @@ export function WagmiPurchaseDonutAsyncPermissionsTest() {
<Text>Fetching donuts...</Text>
) : (
<>
<Text marginRight="5px">Crypto donuts left:</Text>
<Text marginRight="5px">Crypto donuts purchased:</Text>
<Text>{donutsOwned?.toString()}</Text>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ import { encodeFunctionData, parseEther } from 'viem'
import { abi as donutContractAbi, address as donutContractaddress } from '../../utils/DonutContract'
import { useERC7715Permissions } from '../../hooks/useERC7715Permissions'
import { usePasskey } from '../../context/PasskeyContext'
import { sepolia } from 'viem/chains'
import { executeActionsWithPasskeyAndCosignerPermissions } from '../../utils/ERC7715Utils'
import { executeActionsWithPasskey } from '../../utils/ERC7715Utils'
import { getChain } from '../../utils/NetworksUtil'
import type { SmartSessionGrantPermissionsResponse } from '@reown/appkit-experimental/smart-session'

export function WagmiPurchaseDonutSyncPermissionsTest() {
const { smartSession } = useERC7715Permissions()

if (smartSession?.type !== 'sync' || !smartSession.grantedPermissions?.context) {
return (
<Text fontSize="md" color="yellow">
Dapp does not have the permissions
</Text>
)
}

return <ConnectedTestContent grantedPermissions={smartSession.grantedPermissions} />
}
function ConnectedTestContent({
grantedPermissions
}: {
grantedPermissions: SmartSessionGrantPermissionsResponse
}) {
const { passkeyId } = usePasskey()
const { grantedPermissions, pci } = useERC7715Permissions()
const toast = useChakraToast()
const [isTransactionPending, setTransactionPending] = useState<boolean>(false)

const {
data: donutsOwned,
Expand All @@ -22,22 +41,23 @@ export function WagmiPurchaseDonutSyncPermissionsTest() {
abi: donutContractAbi,
address: donutContractaddress,
functionName: 'getBalance',
args: [grantedPermissions?.signerData?.submitToAddress || '0x']
args: [grantedPermissions.address]
})

const [isTransactionPending, setTransactionPending] = useState<boolean>(false)
const toast = useChakraToast()

async function onPurchaseDonutWithPermissions() {
setTransactionPending(true)
try {
if (!grantedPermissions) {
throw Error('No permissions available')
const chainId = parseInt(grantedPermissions.chainId, 16)
if (!chainId) {
throw new Error('Chain ID not available in granted permissions')
}
if (!pci) {
throw Error('No WC cosigner data(PCI) available')
const chain = getChain(chainId)
if (!chain) {
throw new Error('Unknown chainId')
}
if (!passkeyId) {
throw new Error(`Unable to get passkeyId`)
}

const purchaseDonutCallData = encodeFunctionData({
abi: donutContractAbi,
functionName: 'purchase',
Expand All @@ -50,12 +70,12 @@ export function WagmiPurchaseDonutSyncPermissionsTest() {
data: purchaseDonutCallData
}
]
const txHash = await executeActionsWithPasskeyAndCosignerPermissions({
const txHash = await executeActionsWithPasskey({
accountAddress: grantedPermissions.address,
actions: purchaseDonutCallDataExecution,
chain: sepolia,
chain,
passkeyId,
permissions: grantedPermissions,
pci
permissionsContext: grantedPermissions.context
})
if (txHash) {
toast({
Expand All @@ -75,14 +95,6 @@ export function WagmiPurchaseDonutSyncPermissionsTest() {
setTransactionPending(false)
}

if (!grantedPermissions) {
return (
<Text fontSize="md" color="yellow">
Dapp does not have the permissions
</Text>
)
}

return (
<Stack direction={['column', 'column', 'row']}>
<Button
Expand Down
Loading
Loading