Skip to content

Commit

Permalink
Merge pull request #52 from rhinestonewtf/split-encode-sig
Browse files Browse the repository at this point in the history
split-encode-sig
  • Loading branch information
kopy-kat authored Sep 10, 2024
2 parents 2fd2b1c + 16799eb commit ae5e667
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
getOwnableValidatorOwners,
getOwnableValidatorThreshold,
getOwnableValidatorMockSignature,
encodeValidationData,
SCHEDULED_ORDERS_EXECUTER_ADDRESS,
getScheduledOrdersExecutor,
getCreateScheduledOrderAction,
Expand Down Expand Up @@ -88,6 +89,7 @@ export {
getFlashloanWhitelist,
fetchRegistryModules,
REGISTRY_ADDRESS,
MOCK_ATTESTER_ADDRESS,
SMART_SESSIONS_ADDRESS,
getSmartSessionsValidator,
getEnableSessionsAction,
Expand All @@ -106,7 +108,19 @@ export {
getSudoPolicy,
getUniversalActionPolicy,
encodeSmartSessionSignature,
encodeUseOrEnableSmartSessionSignature,
isSessionEnabled,
hashChainSessions,
SmartSessionMode,
Session,
SessionEIP712,
PolicyData,
ERC7739Data,
ActionData,
EnableSession,
EnableSessionData,
ChainDigest,
ChainSession,
CallType,
} from './module'

Expand Down
19 changes: 18 additions & 1 deletion src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export {
getOwnableValidatorOwners,
getOwnableValidatorThreshold,
getOwnableValidatorMockSignature,
encodeValidationData,
} from './ownable-validator'

export {
Expand Down Expand Up @@ -130,10 +131,26 @@ export {
getSudoPolicy,
getUniversalActionPolicy,
encodeSmartSessionSignature,
encodeUseOrEnableSmartSessionSignature,
isSessionEnabled,
hashChainSessions,
SmartSessionMode,
Session,
SessionEIP712,
PolicyData,
ERC7739Data,
ActionData,
EnableSession,
EnableSessionData,
ChainDigest,
ChainSession,
} from './smart-sessions'

export { fetchRegistryModules, REGISTRY_ADDRESS } from './registry'
export {
fetchRegistryModules,
REGISTRY_ADDRESS,
MOCK_ATTESTER_ADDRESS,
} from './registry'

export type {
ModuleType,
Expand Down
1 change: 1 addition & 0 deletions src/module/ownable-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export {
getOwnableValidatorOwners,
getOwnableValidatorMockSignature,
getOwnableValidatorThreshold,
encodeValidationData,
} from './usage'
2 changes: 1 addition & 1 deletion src/module/registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { fetchRegistryModules } from './usage'
export { REGISTRY_ADDRESS } from './constants'
export { REGISTRY_ADDRESS, MOCK_ATTESTER_ADDRESS } from './constants'
2 changes: 1 addition & 1 deletion src/module/smart-sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './installation'
export * from './usage'
export * from './constants'
export * from './policies'
export { SmartSessionMode } from './types'
export * from './types'
51 changes: 50 additions & 1 deletion src/module/smart-sessions/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,55 @@ export const encodeSmartSessionSignature = ({
}
}

export const encodeUseOrEnableSmartSessionSignature = async ({
account,
client,
permissionId,
signature,
enableSessionData,
}: {
account: Account
client: PublicClient
permissionId: Hex
signature: Hex
enableSessionData: EnableSessionData
}) => {
const sessionEnabled = await isSessionEnabled({
account,
client,
permissionId,
})

return sessionEnabled
? encodePacked(
['bytes1', 'bytes32', 'bytes'],
[
SmartSessionMode.USE,
permissionId,
LibZip.flzCompress(
encodeAbiParameters(
[
{
type: 'bytes',
},
],
[signature],
),
) as Hex,
],
)
: encodePacked(
['bytes1', 'bytes32', 'bytes'],
[
SmartSessionMode.ENABLE,
permissionId,
LibZip.flzCompress(
encodeEnableSessionSignature({ enableSessionData, signature }),
) as Hex,
],
)
}

export const hashChainSessions = (chainSessions: ChainSession[]): Hex => {
return hashTypedData({
domain: {
Expand Down Expand Up @@ -202,7 +251,7 @@ export const hashChainSessions = (chainSessions: ChainSession[]): Hex => {
})
}

export const encodeEnableSessionSignature = ({
const encodeEnableSessionSignature = ({
enableSessionData,
signature,
}: {
Expand Down

0 comments on commit ae5e667

Please sign in to comment.