-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Enable sendUserOp for userOpBuilder service (#680)
* chores:run prettier * add EncodeLib for SmartSession formatSignature * formatSignature implementation * add sendUserOp implementation * remove signature field from sendUserOp body * chores: refactor code use viem methods for encoding/decoding
- Loading branch information
1 parent
5825941
commit b9d266f
Showing
8 changed files
with
388 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
advanced/wallets/react-wallet-v2/src/lib/smart-accounts/builders/EncodeLib.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { SmartSessionMode } from '@biconomy/permission-context-builder' | ||
import { LibZip } from 'solady' | ||
import { Address, encodeAbiParameters, encodePacked, Hex } from 'viem' | ||
import { enableSessionsStructAbi } from './SmartSessionUserOpBuilder' | ||
|
||
type EnableSessions = { | ||
isigner: Address | ||
isignerInitData: Hex | ||
userOpPolicies: readonly { policy: Address; initData: Hex }[] | ||
erc1271Policies: readonly { policy: Address; initData: Hex }[] | ||
actions: readonly { | ||
actionId: Hex | ||
actionPolicies: readonly { policy: Address; initData: Hex }[] | ||
}[] | ||
permissionEnableSig: Hex | ||
} | ||
|
||
export function packMode(data: Hex, mode: SmartSessionMode, signerId: Hex): Hex { | ||
return encodePacked(['uint8', 'bytes32', 'bytes'], [mode, signerId, data]) | ||
} | ||
|
||
export function encodeUse(signerId: Hex, sig: Hex) { | ||
const data = encodeAbiParameters([{ type: 'bytes' }], [sig]) | ||
const compressedData = LibZip.flzCompress(data) as Hex | ||
return packMode(compressedData, SmartSessionMode.USE, signerId) | ||
} | ||
|
||
export function encodeEnable(signerId: Hex, sig: Hex, enableData: EnableSessions) { | ||
const data = encodeAbiParameters( | ||
[enableSessionsStructAbi[0], { type: 'bytes' }], | ||
[ | ||
{ | ||
...enableData | ||
}, | ||
sig | ||
] | ||
) | ||
const compressedData = LibZip.flzCompress(data) as Hex | ||
return packMode(compressedData, SmartSessionMode.UNSAFE_ENABLE, signerId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.