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

encode 1271 signature #51

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "module-sdk (esm)",
"path": "./src/_esm/index.js",
"limit": "60 kB",
"limit": "70 kB",
"import": "*"
},
{
Expand Down
14 changes: 14 additions & 0 deletions src/account/api/encode1271Signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Hex } from 'viem'
import { Account, Signature1271Params } from '../types'
import { getAccountImplementation } from './getAccountImplementation'

export const encode1271Signature = ({
account,
signatureParams,
}: {
account: Account
signatureParams: Signature1271Params
}): Hex => {
const accountImplementation = getAccountImplementation({ account })
return accountImplementation.encode1271Signature(signatureParams)
}
1 change: 1 addition & 0 deletions src/account/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './getInstalledModules'
export * from './installModule'
export * from './isModuleInstalled'
export * from './uninstallModule'
export * from './encode1271Signature'
9 changes: 9 additions & 0 deletions src/account/erc7579-implementation/api/encode1271Signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Signature1271Params } from '../../types'
import { encodePacked, Hex } from 'viem'

export const encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encodePacked(['address', 'bytes'], [validator, signature])
}
12 changes: 10 additions & 2 deletions src/account/erc7579-implementation/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Address, PublicClient } from 'viem'
import { Account, Execution } from '../types'
import { Address, Hex, PublicClient } from 'viem'
import { Account, Execution, Signature1271Params } from '../types'
import { Module, ModuleType } from '../../module/types'
import { getInstalledModules } from './api/getInstalledModules'
import { installModule } from './api/installModule'
import { isModuleInstalled } from './api/isModuleInstalled'
import { uninstallModule } from './api/uninstallModule'
import { encode1271Signature } from './api/encode1271Signature'

export class ERC7579Implementation {
getInstalledModules = async ({
Expand Down Expand Up @@ -53,4 +54,11 @@ export class ERC7579Implementation {
}): Promise<Execution[]> => {
return uninstallModule({ client, account, module })
}

encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encode1271Signature({ validator, signature })
}
}
1 change: 1 addition & 0 deletions src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export {
installModule,
isModuleInstalled,
uninstallModule,
encode1271Signature,
} from './api'

export type { Account, AccountType, Execution, InitialModules } from './types'
12 changes: 12 additions & 0 deletions src/account/kernel/api/encode1271Signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Signature1271Params } from '../../types'
import { encodePacked, Hex } from 'viem'

export const encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encodePacked(
['bytes1', 'address', 'bytes'],
['0x01', validator, signature],
)
}
12 changes: 10 additions & 2 deletions src/account/kernel/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Address, PublicClient } from 'viem'
import { Account, Execution } from '../types'
import { Address, Hex, PublicClient } from 'viem'
import { Account, Execution, Signature1271Params } from '../types'
import { getInstalledModules } from './api/getInstalledModules'
import { installModule } from './api/installModule'
import { isModuleInstalled } from './api/isModuleInstalled'
import { uninstallModule } from './api/uninstallModule'
import { KernelModule, KernelModuleType } from './types'
import { encode1271Signature } from './api/encode1271Signature'

export class KernelImplementation {
getInstalledModules = async ({
Expand Down Expand Up @@ -53,4 +54,11 @@ export class KernelImplementation {
}): Promise<Execution[]> => {
return uninstallModule({ client, account, module })
}

encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encode1271Signature({ validator, signature })
}
}
9 changes: 9 additions & 0 deletions src/account/nexus/api/encode1271Signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Signature1271Params } from '../../types'
import { encodePacked, Hex } from 'viem'

export const encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encodePacked(['address', 'bytes'], [validator, signature])
}
12 changes: 10 additions & 2 deletions src/account/nexus/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Address, PublicClient } from 'viem'
import { Account, Execution } from '../types'
import { Address, Hex, PublicClient } from 'viem'
import { Account, Execution, Signature1271Params } from '../types'
import { Module, ModuleType } from '../../module/types'
import { getInstalledModules } from './api/getInstalledModules'
import { installModule } from './api/installModule'
import { isModuleInstalled } from './api/isModuleInstalled'
import { uninstallModule } from './api/uninstallModule'
import { encode1271Signature } from './api/encode1271Signature'

export class NexusImplementation {
getInstalledModules = async ({
Expand Down Expand Up @@ -53,4 +54,11 @@ export class NexusImplementation {
}): Promise<Execution[]> => {
return uninstallModule({ client, account, module })
}

encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encode1271Signature({ validator, signature })
}
}
9 changes: 9 additions & 0 deletions src/account/safe/api/encode1271Signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Signature1271Params } from '../../types'
import { encodePacked, Hex } from 'viem'

export const encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encodePacked(['address', 'bytes'], [validator, signature])
}
12 changes: 10 additions & 2 deletions src/account/safe/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Address, PublicClient } from 'viem'
import { Account, Execution } from '../types'
import { Address, Hex, PublicClient } from 'viem'
import { Account, Execution, Signature1271Params } from '../types'
import { getInstalledModules } from './api/getInstalledModules'
import { installModule } from './api/installModule'
import { isModuleInstalled } from './api/isModuleInstalled'
import { uninstallModule } from './api/uninstallModule'
import { Module, ModuleType } from '../../module'
import { encode1271Signature } from './api/encode1271Signature'

export class SafeImplementation {
getInstalledModules = async ({
Expand Down Expand Up @@ -53,4 +54,11 @@ export class SafeImplementation {
}): Promise<Execution[]> => {
return uninstallModule({ client, account, module })
}

encode1271Signature = ({
validator,
signature,
}: Signature1271Params): Hex => {
return encode1271Signature({ validator, signature })
}
}
5 changes: 5 additions & 0 deletions src/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export type InitialModules = {
hooks: Module[]
fallbacks: Module[]
}

export type Signature1271Params = {
validator: Address
signature: Hex
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
installModule,
isModuleInstalled,
uninstallModule,
encode1271Signature,
} from './account'
export type { Account, AccountType, Execution, InitialModules } from './account'

Expand Down Expand Up @@ -105,6 +106,7 @@ export {
getSudoPolicy,
getUniversalActionPolicy,
encodeSmartSessionSignature,
SmartSessionMode,
CallType,
} from './module'

Expand Down
1 change: 1 addition & 0 deletions src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export {
getSudoPolicy,
getUniversalActionPolicy,
encodeSmartSessionSignature,
SmartSessionMode,
} from './smart-sessions'

export { fetchRegistryModules, REGISTRY_ADDRESS } from './registry'
Expand Down
1 change: 1 addition & 0 deletions src/module/smart-sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './installation'
export * from './usage'
export * from './constants'
export * from './policies'
export { SmartSessionMode } from './types'
5 changes: 4 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rhinestone/module-sdk",
"version": "0.1.11",
"version": "0.1.12",
"description": "A TypeScript library for using Smart Account Modules in Applications",
"author": {
"name": "Rhinestone",
Expand Down Expand Up @@ -47,5 +47,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"solady": "^0.0.235"
}
}