Skip to content

Commit

Permalink
chore: update rpc schema
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Feb 8, 2025
1 parent df2a851 commit 05e6d6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
36 changes: 9 additions & 27 deletions playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ExperimentERC20 } from './contracts'

const porto = Porto.create({
implementation: Implementation.dialog({
host: import.meta.env.VITE_HOST ?? 'https://exp.porto.sh/dialog',
host: 'https://exp.porto.sh/dialog',
}),
})

Expand Down Expand Up @@ -521,24 +521,13 @@ function PreparedCalls() {
},
})

const _grantPermissions = await porto.provider.request({
const permissionsResult = await porto.provider.request({
method: 'experimental_grantPermissions',
params: [
{
key,
address: account,
expiry: key.expiry,
permissions: {
calls: key.permissions?.calls,
spend: key.permissions?.spend?.map((limit) => ({
...limit,
limit: Hex.fromNumber(limit.limit),
})),
},
},
],
params: [{ key, address: account, ...permissions() }],
})

console.info(permissionsResult)

setKey(key)
setStep('PREPARE-SEND')
}
Expand Down Expand Up @@ -590,32 +579,24 @@ function PreparedCalls() {
method: 'wallet_prepareCalls',
params: [
{
calls: calls as any,
version: '1',
from: account,
calls: permissions().permissions.calls,
chainId: Hex.fromNumber(Chains.odysseyTestnet.id),
},
],
})

setDigest(digest)

// const signature = await Key.sign(
// Key.from(Key.fromP256({ ...key!, privateKey: key!.privateKey() })),
// {
// address: account,
// payload: digest,
// },
// )

const signature = P256.sign({
payload: digest,
privateKey: key!.privateKey(),
})

setSignature(Signature.toHex(signature))

const [hash] = await porto.provider.request({
const [sendPreparedCallsResult] = await porto.provider.request({
method: 'wallet_sendPreparedCalls',
params: [
{
Expand All @@ -628,8 +609,9 @@ function PreparedCalls() {
},
],
})
console.info(sendPreparedCallsResult)

setHash(hash)
setHash(sendPreparedCallsResult.id)
}
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/core/RpcSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Schema = RpcSchema.From<
| {
Request: {
method: 'wallet_prepareCalls'
params: RpcSchema.ExtractParams<Schema, 'wallet_sendCalls'>
params: [internal.WalletPrepareCallsParameters]
}
ReturnType: internal.WalletPrepareCallsReturnType
}
Expand Down Expand Up @@ -94,6 +94,6 @@ export type Schema = RpcSchema.From<
method: 'wallet_sendPreparedCalls'
params: [internal.WalletSendPreparedCallsParameters]
}
ReturnType: Hex.Hex[]
ReturnType: internal.WalletSendPreparedCallsReturnType
}
>
18 changes: 18 additions & 0 deletions src/core/internal/rpcSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ export type RevokePermissionsParameters = {
id: Hex.Hex
}

export type WalletPrepareCallsParameters = {
version?: string | undefined
chainId: Hex.Hex
from?: Address.Address | undefined
calls: readonly {
to: Address.Address
data?: Hex.Hex | undefined
value?: Hex.Hex | undefined
capabilities?: Record<string, any> | undefined
}[]
capabilities?: Record<string, any> | undefined
}

export type WalletPrepareCallsReturnType = {
capabilities?: Record<string, any>
chainId?: Hex.Hex | undefined
Expand All @@ -96,3 +109,8 @@ export type WalletSendPreparedCallsParameters = Omit<
value: Hex.Hex
}
}

export type WalletSendPreparedCallsReturnType = {
id: string
capabilities?: Record<string, any>
}[]

0 comments on commit 05e6d6b

Please sign in to comment.