Skip to content

Commit

Permalink
Merge branch 'main' into enable-permission-validator-v2-with-wc-cosigner
Browse files Browse the repository at this point in the history
  • Loading branch information
KannuSingh committed Aug 6, 2024
2 parents 832ea86 + 5fc7b7b commit 4c2b9d3
Show file tree
Hide file tree
Showing 110 changed files with 64,548 additions and 16,050 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ env:

on:
pull_request:
branches:
- main
paths:
- "advanced/wallets/react-wallet-v2/**"
- "advanced/dapps/react-dapp-v2/**"

jobs:
code_style:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ui_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
base-url: http://localhost:3000/
wallet-url: ${{ needs.preview.outputs.preview-url }}/
skip-playwright-webserver: false
branch: V4
branch: main
command: playwright:test:wallet
uses: WalletConnect/web3modal/.github/workflows/ui_tests.yml@V4
uses: WalletConnect/web3modal/.github/workflows/ui_tests.yml@main
secrets:
NEXT_PUBLIC_PROJECT_ID: ${{ secrets.UI_TEST_PROJECT_ID }}
TESTS_NEXTAUTH_SECRET: ${{ secrets.TESTS_NEXTAUTH_SECRET }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store

# dependencies
node_modules
/node_modules
/.pnp
.pnp.js
Expand Down
9 changes: 5 additions & 4 deletions advanced/wallets/react-wallet-v2/src/data/SolanaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SOLANA_MAINNET_CHAINS = {
name: 'Solana',
logo: '/chain-logos/solana-5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp.png',
rgb: '30, 240, 166',
rpc: '',
rpc: 'https://api.mainnet-beta.solana.com',
namespace: 'solana'
}
}
Expand All @@ -41,15 +41,15 @@ export const SOLANA_TEST_CHAINS = {
name: 'Solana Devnet',
logo: '/chain-logos/solana-5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp.png',
rgb: '30, 240, 166',
rpc: '',
rpc: 'https://api.devnet.solana.com',
namespace: 'solana'
},
'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z': {
chainId: '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
name: 'Solana Testnet',
logo: '/chain-logos/solana-5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp.png',
rgb: '30, 240, 166',
rpc: '',
rpc: 'https://api.testnet.solana.com',
namespace: 'solana'
}
}
Expand All @@ -61,5 +61,6 @@ export const SOLANA_CHAINS = { ...SOLANA_MAINNET_CHAINS, ...SOLANA_TEST_CHAINS }
*/
export const SOLANA_SIGNING_METHODS = {
SOLANA_SIGN_TRANSACTION: 'solana_signTransaction',
SOLANA_SIGN_MESSAGE: 'solana_signMessage'
SOLANA_SIGN_MESSAGE: 'solana_signMessage',
SOLANA_SIGN_AND_SEND_TRANSACTION: 'solana_signAndSendTransaction'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { approveEIP5792Request } from '@/utils/EIP5792RequestHandlerUtils'
import EIP155Lib from '@/lib/EIP155Lib'
import { getWallet } from '@/utils/EIP155WalletUtil'
import { EIP7715_METHOD } from '@/data/EIP7715Data'
import { refreshSessionsList } from '@/pages/wc'

export default function useWalletConnectEventsManager(initialized: boolean) {
/******************************************************************************
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function useWalletConnectEventsManager(initialized: boolean) {

case SOLANA_SIGNING_METHODS.SOLANA_SIGN_MESSAGE:
case SOLANA_SIGNING_METHODS.SOLANA_SIGN_TRANSACTION:
case SOLANA_SIGNING_METHODS.SOLANA_SIGN_AND_SEND_TRANSACTION:
return ModalStore.open('SessionSignSolanaModal', { requestEvent, requestSession })

case POLKADOT_SIGNING_METHODS.POLKADOT_SIGN_MESSAGE:
Expand Down Expand Up @@ -173,11 +175,11 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
web3wallet.engine.signClient.events.on('session_ping', data => console.log('ping', data))
web3wallet.on('session_delete', data => {
console.log('session_delete event received', data)
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
refreshSessionsList()
})
web3wallet.on('session_authenticate', onSessionAuthenticate)
// load sessions on init
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
refreshSessionsList()
}
}, [initialized, onAuthRequest, onSessionProposal, onSessionRequest])
}, [initialized, onAuthRequest, onSessionAuthenticate, onSessionProposal, onSessionRequest])
}
58 changes: 57 additions & 1 deletion advanced/wallets/react-wallet-v2/src/lib/SolanaLib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Keypair } from '@solana/web3.js'
import {
Keypair,
Connection,
Transaction,
TransactionInstruction,
PublicKey,
SendOptions
} from '@solana/web3.js'
import bs58 from 'bs58'
import nacl from 'tweetnacl'
import SolanaWallet, { SolanaSignTransaction } from 'solana-wallet'
import { SOLANA_MAINNET_CHAINS, SOLANA_TEST_CHAINS } from '@/data/SolanaData'

/**
* Types
Expand Down Expand Up @@ -58,4 +66,52 @@ export default class SolanaLib {

return { signature }
}

public async signAndSendTransaction(
feePayer: SolanaSignTransaction['feePayer'],
instructions: SolanaSignTransaction['instructions'],
chainId: string,
options: SendOptions = {}
) {
const rpc = { ...SOLANA_TEST_CHAINS, ...SOLANA_MAINNET_CHAINS }[chainId]?.rpc

if (!rpc) {
throw new Error('There is no RPC URL for the provided chain')
}

const connection = new Connection(rpc)

const parsedInstructions = instructions.map(instruction => {
const keys = instruction.keys.map(key => ({
pubkey: new PublicKey(key.pubkey),
isSigner: key.isSigner,
isWritable: key.isWritable
}))
const programId = new PublicKey(instruction.programId)
const data =
typeof instruction.data === 'string'
? Buffer.from(bs58.decode(instruction.data).buffer)
: instruction.data

return new TransactionInstruction({
keys,
programId,
data
})
})

const transaction = new Transaction().add(...parsedInstructions)
transaction.feePayer = new PublicKey(feePayer)
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash
transaction.sign(this.keypair)

const signature = await connection.sendRawTransaction(transaction.serialize())
const confirmation = await connection.confirmTransaction(signature, options.preflightCommitment)

if (confirmation.value.err) {
throw new Error(confirmation.value.err.toString())
}

return { signature }
}
}
5 changes: 3 additions & 2 deletions advanced/wallets/react-wallet-v2/src/pages/sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import PageHeader from '@/components/PageHeader'
import SessionCard from '@/components/SessionCard'
import SettingsStore from '@/store/SettingsStore'
import { Text } from '@nextui-org/react'
import { Fragment } from 'react'
import { Fragment, useEffect } from 'react'
import { useSnapshot } from 'valtio'
import { refreshSessionsList } from './wc'

export default function SessionsPage() {
const { sessions } = useSnapshot(SettingsStore.state)

useEffect(() => refreshSessionsList(), [])
if (!sessions.length) {
return (
<Fragment>
Expand Down
2 changes: 1 addition & 1 deletion advanced/wallets/react-wallet-v2/src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function SettingsPage() {
Packages
</Text>
<Row justify="space-between" align="center">
<Text color="$gray400">@walletconnect/sign-client</Text>
<Text color="$gray400">@walletconnect/web3wallet</Text>
<Text color="$gray400">{packageJSON.dependencies['@walletconnect/web3wallet']}</Text>
</Row>

Expand Down
7 changes: 7 additions & 0 deletions advanced/wallets/react-wallet-v2/src/pages/wc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useRouter } from 'next/router'
import WalletConnectPage from './walletconnect'
import ModalStore from '@/store/ModalStore'
import { useSnapshot } from 'valtio'
import SettingsStore from '@/store/SettingsStore'
import { web3wallet } from '@/utils/WalletConnectUtil'

export default function DeepLinkPairingPage() {
const state = useSnapshot(ModalStore.state)
Expand Down Expand Up @@ -54,3 +56,8 @@ export default function DeepLinkPairingPage() {

return <WalletConnectPage deepLink={uri} />
}

export function refreshSessionsList() {
if (!web3wallet) return
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function approveSolanaRequest(
requestEvent: SignClientTypes.EventArguments['session_request']
) {
const { params, id } = requestEvent
const { request } = params
const { request, chainId } = params
const wallet = solanaWallets[getWalletAddressFromParams(solanaAddresses, params)]

switch (request.method) {
Expand All @@ -26,6 +26,16 @@ export async function approveSolanaRequest(

return formatJsonRpcResult(id, signedTransaction)

case SOLANA_SIGNING_METHODS.SOLANA_SIGN_AND_SEND_TRANSACTION:
const signedAndSentTransaction = await wallet.signAndSendTransaction(
request.params.feePayer,
request.params.instructions,
chainId,
request.params.options
)

return formatJsonRpcResult(id, signedAndSentTransaction)

default:
throw new Error(getSdkError('INVALID_METHOD').message)
}
Expand Down
2 changes: 2 additions & 0 deletions dapps/appkit-siwe/next/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_PROJECT_ID=<your-project-id-from-cloud>
NEXTAUTH_SECRET=<a-random-string>
3 changes: 3 additions & 0 deletions dapps/appkit-siwe/next/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
39 changes: 39 additions & 0 deletions dapps/appkit-siwe/next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# vscode
.vscode/settings.json
26 changes: 26 additions & 0 deletions dapps/appkit-siwe/next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Appkit SIWE Example for Next.js Router

A Minimal demo using React so developers can work on their integration with WalletConnect and SIWE using this repository as a template.

1. Install dependencies in the frontend: `pnpm install`

2. Create and complete the .env.local file with your Project Id from http://cloud.walletconnect.com

```
NEXT_PUBLIC_PROJECT_ID=...
NEXTAUTH_SECRET=<any-random-text>
```

3. Run the frontend: `pnpm run dev`

4. Open in your browser

## Server side

It verifies user signatures using NextAuth, through the Sign-In with Ethereum (SIWE) protocol, ensuring the integrity and authenticity of the sign-in process.

## Reference

- https://docs.walletconnect.com/appkit/next/core/siwe
- https://docs.login.xyz/general-information/siwe-overview/eip-4361
- https://next-auth.js.org/
Loading

0 comments on commit 4c2b9d3

Please sign in to comment.