permissionless 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/_cjs/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
- package/_cjs/accounts/index.js +3 -1
- package/_cjs/accounts/index.js.map +1 -1
- package/_cjs/accounts/nexus/toNexusSmartAccount.js +198 -0
- package/_cjs/accounts/nexus/toNexusSmartAccount.js.map +1 -0
- package/_cjs/accounts/safe/toSafeSmartAccount.js +1 -9
- package/_cjs/accounts/safe/toSafeSmartAccount.js.map +1 -1
- package/_cjs/actions/erc7579/isModuleInstalled.js +8 -13
- package/_cjs/actions/erc7579/isModuleInstalled.js.map +1 -1
- package/_cjs/utils/encodeInstallModule.js +9 -6
- package/_cjs/utils/encodeInstallModule.js.map +1 -1
- package/_cjs/utils/encodeUninstallModule.js +9 -6
- package/_cjs/utils/encodeUninstallModule.js.map +1 -1
- package/_esm/accounts/biconomy/toBiconomySmartAccount.js +2 -7
- package/_esm/accounts/biconomy/toBiconomySmartAccount.js.map +1 -1
- package/_esm/accounts/index.js +2 -1
- package/_esm/accounts/index.js.map +1 -1
- package/_esm/accounts/nexus/toNexusSmartAccount.js +201 -0
- package/_esm/accounts/nexus/toNexusSmartAccount.js.map +1 -0
- package/_esm/accounts/safe/toSafeSmartAccount.js +1 -9
- package/_esm/accounts/safe/toSafeSmartAccount.js.map +1 -1
- package/_esm/actions/erc7579/isModuleInstalled.js +8 -13
- package/_esm/actions/erc7579/isModuleInstalled.js.map +1 -1
- package/_esm/utils/encodeInstallModule.js +9 -6
- package/_esm/utils/encodeInstallModule.js.map +1 -1
- package/_esm/utils/encodeUninstallModule.js +9 -6
- package/_esm/utils/encodeUninstallModule.js.map +1 -1
- package/_types/accounts/biconomy/toBiconomySmartAccount.d.ts +2 -7
- package/_types/accounts/biconomy/toBiconomySmartAccount.d.ts.map +1 -1
- package/_types/accounts/index.d.ts +2 -1
- package/_types/accounts/index.d.ts.map +1 -1
- package/_types/accounts/nexus/toNexusSmartAccount.d.ts +26 -0
- package/_types/accounts/nexus/toNexusSmartAccount.d.ts.map +1 -0
- package/_types/accounts/safe/toSafeSmartAccount.d.ts.map +1 -1
- package/_types/actions/erc7579/isModuleInstalled.d.ts.map +1 -1
- package/_types/utils/encodeInstallModule.d.ts.map +1 -1
- package/_types/utils/encodeUninstallModule.d.ts.map +1 -1
- package/accounts/biconomy/toBiconomySmartAccount.ts +2 -8
- package/accounts/index.ts +11 -0
- package/accounts/nexus/toNexusSmartAccount.ts +331 -0
- package/accounts/safe/toSafeSmartAccount.ts +1 -12
- package/actions/erc7579/installModule.test.ts +4 -4
- package/actions/erc7579/installModules.test.ts +4 -4
- package/actions/erc7579/isModuleInstalled.test.ts +2 -2
- package/actions/erc7579/isModuleInstalled.ts +8 -13
- package/actions/erc7579/uninstallModule.test.ts +2 -2
- package/actions/erc7579/uninstallModules.test.ts +2 -2
- package/package.json +1 -1
- package/utils/encodeInstallModule.ts +9 -6
- package/utils/encodeUninstallModule.ts +9 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isModuleInstalled.d.ts","sourceRoot":"","sources":["../../../actions/erc7579/isModuleInstalled.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EAEX,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,SAAS,EAIjB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AAIjC,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAErE,MAAM,MAAM,2BAA2B,CACnC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACC;IACI,iBAAiB,EAAE,GAAG,CAAA;CACzB,GACD;IACI,OAAO,EAAE,GAAG,CAAA;CACf,CACN,CAAA;AAEL,wBAAsB,iBAAiB,CACnC,aAAa,SAAS,YAAY,GAAG,SAAS,EAE9C,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,aAAa,CAAC,EAC3D,UAAU,EAAE,2BAA2B,CAAC,aAAa,CAAC,GACvD,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"isModuleInstalled.d.ts","sourceRoot":"","sources":["../../../actions/erc7579/isModuleInstalled.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EAEX,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,SAAS,EAIjB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AAIjC,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAErE,MAAM,MAAM,2BAA2B,CACnC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACC;IACI,iBAAiB,EAAE,GAAG,CAAA;CACzB,GACD;IACI,OAAO,EAAE,GAAG,CAAA;CACf,CACN,CAAA;AAEL,wBAAsB,iBAAiB,CACnC,aAAa,SAAS,YAAY,GAAG,SAAS,EAE9C,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,GAAG,SAAS,EAAE,aAAa,CAAC,EAC3D,UAAU,EAAE,2BAA2B,CAAC,aAAa,CAAC,GACvD,OAAO,CAAC,OAAO,CAAC,CA2FlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodeInstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeInstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,4BAA4B,GAAG;IACvC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,QAAQ,EAAE,GAAG,CAAA;CAChB,CACN,CAAA;AAED,MAAM,MAAM,6BAA6B,CACrC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,4BAA4B,EAAE,GAAG,4BAA4B,CAAA;CACzE,CAAA;AAED,wBAAgB,mBAAmB,CAC/B,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,6BAA6B,CAAC,aAAa,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"encodeInstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeInstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,4BAA4B,GAAG;IACvC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,QAAQ,EAAE,GAAG,CAAA;CAChB,CACN,CAAA;AAED,MAAM,MAAM,6BAA6B,CACrC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,4BAA4B,EAAE,GAAG,4BAA4B,CAAA;CACzE,CAAA;AAED,wBAAgB,mBAAmB,CAC/B,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,6BAA6B,CAAC,aAAa,CAAC;;;;IAkDzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodeUninstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeUninstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,8BAA8B,GAAG;IACzC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,UAAU,EAAE,GAAG,CAAA;CAClB,CACN,CAAA;AAED,MAAM,MAAM,+BAA+B,CACvC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,8BAA8B,EAAE,GAAG,8BAA8B,CAAA;CAC7E,CAAA;AAED,wBAAgB,qBAAqB,CACjC,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,+BAA+B,CAAC,aAAa,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"encodeUninstallModule.d.ts","sourceRoot":"","sources":["../../utils/encodeUninstallModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,KAAK,EAGb,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,UAAU,EAElB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,MAAM,8BAA8B,GAAG;IACzC,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;CACnB,GAAG,KAAK,CACH;IACI,OAAO,EAAE,GAAG,CAAA;CACf,GACD;IACI,UAAU,EAAE,GAAG,CAAA;CAClB,CACN,CAAA;AAED,MAAM,MAAM,+BAA+B,CACvC,aAAa,SAAS,YAAY,GAAG,SAAS,IAC9C,wBAAwB,CAAC,aAAa,CAAC,GAAG;IAC1C,OAAO,EAAE,8BAA8B,EAAE,GAAG,8BAA8B,CAAA;CAC7E,CAAA;AAED,wBAAgB,qBAAqB,CACjC,aAAa,SAAS,YAAY,GAAG,SAAS,EAChD,UAAU,EAAE,+BAA+B,CAAC,aAAa,CAAC;;;;IAkD3D"}
|
|
@@ -176,15 +176,9 @@ const getAccountAddress = async ({
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @
|
|
181
|
-
* @param privateKey
|
|
182
|
-
* @param entryPoint
|
|
183
|
-
* @param index
|
|
184
|
-
* @param factoryAddress
|
|
185
|
-
* @param ecdsaModuleAddress
|
|
179
|
+
* @deprecated Biconomy Smart Account is deprecated. Please use toNexusSmartAccount instead.
|
|
180
|
+
* @see toNexusSmartAccount
|
|
186
181
|
*/
|
|
187
|
-
|
|
188
182
|
export async function toBiconomySmartAccount(
|
|
189
183
|
parameters: ToBiconomySmartAccountParameters
|
|
190
184
|
): Promise<ToBiconomySmartAccountReturnType> {
|
package/accounts/index.ts
CHANGED
|
@@ -43,6 +43,13 @@ import {
|
|
|
43
43
|
toBiconomySmartAccount
|
|
44
44
|
} from "./biconomy/toBiconomySmartAccount"
|
|
45
45
|
|
|
46
|
+
import {
|
|
47
|
+
type NexusSmartAccountImplementation,
|
|
48
|
+
type ToNexusSmartAccountParameters,
|
|
49
|
+
type ToNexusSmartAccountReturnType,
|
|
50
|
+
toNexusSmartAccount
|
|
51
|
+
} from "./nexus/toNexusSmartAccount"
|
|
52
|
+
|
|
46
53
|
import {
|
|
47
54
|
type ThirdwebSmartAccountImplementation,
|
|
48
55
|
type ToThirdwebSmartAccountParameters,
|
|
@@ -74,6 +81,10 @@ export {
|
|
|
74
81
|
type SafeVersion,
|
|
75
82
|
type KernelVersion,
|
|
76
83
|
toEcdsaKernelSmartAccount,
|
|
84
|
+
type NexusSmartAccountImplementation,
|
|
85
|
+
type ToNexusSmartAccountParameters,
|
|
86
|
+
type ToNexusSmartAccountReturnType,
|
|
87
|
+
toNexusSmartAccount,
|
|
77
88
|
type ToBiconomySmartAccountReturnType,
|
|
78
89
|
type ToBiconomySmartAccountParameters,
|
|
79
90
|
type BiconomySmartAccountImplementation,
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Assign,
|
|
4
|
+
Chain,
|
|
5
|
+
EIP1193Provider,
|
|
6
|
+
OneOf,
|
|
7
|
+
Prettify,
|
|
8
|
+
Transport,
|
|
9
|
+
TypedDataDefinition,
|
|
10
|
+
WalletClient
|
|
11
|
+
} from "viem"
|
|
12
|
+
import {
|
|
13
|
+
type Address,
|
|
14
|
+
type Client,
|
|
15
|
+
type Hex,
|
|
16
|
+
type LocalAccount,
|
|
17
|
+
concat,
|
|
18
|
+
concatHex,
|
|
19
|
+
domainSeparator,
|
|
20
|
+
encodeAbiParameters,
|
|
21
|
+
encodeFunctionData,
|
|
22
|
+
encodePacked,
|
|
23
|
+
getTypesForEIP712Domain,
|
|
24
|
+
hashMessage,
|
|
25
|
+
hashTypedData,
|
|
26
|
+
keccak256,
|
|
27
|
+
stringToHex,
|
|
28
|
+
toHex,
|
|
29
|
+
validateTypedData
|
|
30
|
+
} from "viem"
|
|
31
|
+
import {
|
|
32
|
+
type SmartAccount,
|
|
33
|
+
type SmartAccountImplementation,
|
|
34
|
+
entryPoint07Abi,
|
|
35
|
+
entryPoint07Address,
|
|
36
|
+
getUserOperationHash,
|
|
37
|
+
toSmartAccount
|
|
38
|
+
} from "viem/account-abstraction"
|
|
39
|
+
import { getChainId, readContract } from "viem/actions"
|
|
40
|
+
import { getAction } from "viem/utils"
|
|
41
|
+
import { getAccountNonce } from "../../actions/public/getAccountNonce"
|
|
42
|
+
import { encode7579Calls } from "../../utils"
|
|
43
|
+
import { toOwner } from "../../utils/toOwner"
|
|
44
|
+
|
|
45
|
+
const wrapMessageHash = (
|
|
46
|
+
messageHash: Hex,
|
|
47
|
+
{
|
|
48
|
+
accountAddress,
|
|
49
|
+
version,
|
|
50
|
+
chainId
|
|
51
|
+
}: {
|
|
52
|
+
accountAddress: Address
|
|
53
|
+
version: "1.0.0"
|
|
54
|
+
chainId: number
|
|
55
|
+
}
|
|
56
|
+
) => {
|
|
57
|
+
const _domainSeparator = domainSeparator({
|
|
58
|
+
domain: {
|
|
59
|
+
name: "Nexus",
|
|
60
|
+
version: version,
|
|
61
|
+
chainId,
|
|
62
|
+
verifyingContract: accountAddress
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
const parentStructHash = keccak256(
|
|
66
|
+
encodeAbiParameters(
|
|
67
|
+
[{ type: "bytes32" }, { type: "bytes32" }],
|
|
68
|
+
[
|
|
69
|
+
keccak256(stringToHex("PersonalSign(bytes prefixed)")),
|
|
70
|
+
messageHash
|
|
71
|
+
]
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
return keccak256(concatHex(["0x1901", _domainSeparator, parentStructHash]))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The account creation ABI for Biconomy Smart Account (from the biconomy SmartAccountFactory)
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Default addresses for Biconomy Smart Account
|
|
83
|
+
*/
|
|
84
|
+
const BICONOMY_ADDRESSES: {
|
|
85
|
+
K1_VALIDATOR_FACTORY_ADDRESS: Address
|
|
86
|
+
K1_VALIDATOR_ADDRESS: Address
|
|
87
|
+
} = {
|
|
88
|
+
K1_VALIDATOR_FACTORY_ADDRESS: "0x00000bb19a3579F4D779215dEf97AFbd0e30DB55",
|
|
89
|
+
K1_VALIDATOR_ADDRESS: "0x00000004171351c442B202678c48D8AB5B321E8f"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type ToNexusSmartAccountParameters = Prettify<{
|
|
93
|
+
client: Client
|
|
94
|
+
owners: [
|
|
95
|
+
OneOf<
|
|
96
|
+
| EIP1193Provider
|
|
97
|
+
| WalletClient<Transport, Chain | undefined, Account>
|
|
98
|
+
| LocalAccount
|
|
99
|
+
>
|
|
100
|
+
]
|
|
101
|
+
version: "1.0.0"
|
|
102
|
+
address?: Address | undefined
|
|
103
|
+
entryPoint?: {
|
|
104
|
+
address: Address
|
|
105
|
+
version: "0.7"
|
|
106
|
+
}
|
|
107
|
+
index?: bigint
|
|
108
|
+
factoryAddress?: Address
|
|
109
|
+
validatorAddress?: Address
|
|
110
|
+
attesters?: Address[]
|
|
111
|
+
threshold?: number
|
|
112
|
+
}>
|
|
113
|
+
|
|
114
|
+
export type NexusSmartAccountImplementation = Assign<
|
|
115
|
+
SmartAccountImplementation<typeof entryPoint07Abi, "0.7">,
|
|
116
|
+
{ sign: NonNullable<SmartAccountImplementation["sign"]> }
|
|
117
|
+
>
|
|
118
|
+
|
|
119
|
+
export type ToNexusSmartAccountReturnType = Prettify<
|
|
120
|
+
SmartAccount<NexusSmartAccountImplementation>
|
|
121
|
+
>
|
|
122
|
+
|
|
123
|
+
export async function toNexusSmartAccount(
|
|
124
|
+
parameters: ToNexusSmartAccountParameters
|
|
125
|
+
): Promise<ToNexusSmartAccountReturnType> {
|
|
126
|
+
const {
|
|
127
|
+
owners,
|
|
128
|
+
client,
|
|
129
|
+
index = 0n,
|
|
130
|
+
address,
|
|
131
|
+
version,
|
|
132
|
+
factoryAddress = BICONOMY_ADDRESSES.K1_VALIDATOR_FACTORY_ADDRESS,
|
|
133
|
+
validatorAddress = BICONOMY_ADDRESSES.K1_VALIDATOR_ADDRESS,
|
|
134
|
+
attesters = [],
|
|
135
|
+
threshold = 0
|
|
136
|
+
} = parameters
|
|
137
|
+
|
|
138
|
+
const localOwner = await toOwner({ owner: owners[0] })
|
|
139
|
+
|
|
140
|
+
const entryPoint = {
|
|
141
|
+
address: parameters.entryPoint?.address ?? entryPoint07Address,
|
|
142
|
+
abi: entryPoint07Abi,
|
|
143
|
+
version: parameters.entryPoint?.version ?? "0.7"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let accountAddress: Address | undefined = address
|
|
147
|
+
|
|
148
|
+
const getFactoryArgs = async () => {
|
|
149
|
+
return {
|
|
150
|
+
factory: factoryAddress,
|
|
151
|
+
factoryData: encodeFunctionData({
|
|
152
|
+
abi: [
|
|
153
|
+
{
|
|
154
|
+
name: "createAccount",
|
|
155
|
+
type: "function",
|
|
156
|
+
stateMutability: "nonpayable",
|
|
157
|
+
inputs: [
|
|
158
|
+
{ type: "address", name: "eoaOwner" },
|
|
159
|
+
{ type: "uint256", name: "index" },
|
|
160
|
+
{ type: "address[]", name: "attesters" },
|
|
161
|
+
{ type: "uint8", name: "threshold" }
|
|
162
|
+
],
|
|
163
|
+
outputs: [{ type: "address" }]
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
functionName: "createAccount",
|
|
167
|
+
args: [localOwner.address, index, attesters, threshold]
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let chainId: number
|
|
173
|
+
const getMemoizedChainId = async () => {
|
|
174
|
+
if (chainId) return chainId
|
|
175
|
+
chainId = client.chain
|
|
176
|
+
? client.chain.id
|
|
177
|
+
: await getAction(client, getChainId, "getChainId")({})
|
|
178
|
+
return chainId
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return toSmartAccount({
|
|
182
|
+
client,
|
|
183
|
+
entryPoint,
|
|
184
|
+
getFactoryArgs,
|
|
185
|
+
async getAddress() {
|
|
186
|
+
if (accountAddress) return accountAddress
|
|
187
|
+
|
|
188
|
+
accountAddress = await readContract(client, {
|
|
189
|
+
address: factoryAddress,
|
|
190
|
+
abi: [
|
|
191
|
+
{
|
|
192
|
+
name: "computeAccountAddress",
|
|
193
|
+
type: "function",
|
|
194
|
+
stateMutability: "view",
|
|
195
|
+
inputs: [
|
|
196
|
+
{ type: "address", name: "eoaOwner" },
|
|
197
|
+
{ type: "uint256", name: "index" },
|
|
198
|
+
{ type: "address[]", name: "attesters" },
|
|
199
|
+
{ type: "uint8", name: "threshold" }
|
|
200
|
+
],
|
|
201
|
+
outputs: [{ type: "address" }]
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
functionName: "computeAccountAddress",
|
|
205
|
+
args: [localOwner.address, index, attesters, threshold]
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
return accountAddress
|
|
209
|
+
},
|
|
210
|
+
async getNonce(args) {
|
|
211
|
+
const TIMESTAMP_ADJUSTMENT = 16777215n // max value for size 3
|
|
212
|
+
const defaultedKey = (args?.key ?? 0n) % TIMESTAMP_ADJUSTMENT
|
|
213
|
+
const defaultedValidationMode = "0x00"
|
|
214
|
+
const key = concat([
|
|
215
|
+
toHex(defaultedKey, { size: 3 }),
|
|
216
|
+
defaultedValidationMode,
|
|
217
|
+
validatorAddress
|
|
218
|
+
])
|
|
219
|
+
|
|
220
|
+
const address = await this.getAddress()
|
|
221
|
+
|
|
222
|
+
return getAccountNonce(client, {
|
|
223
|
+
address,
|
|
224
|
+
entryPointAddress: entryPoint.address,
|
|
225
|
+
key: BigInt(key)
|
|
226
|
+
})
|
|
227
|
+
},
|
|
228
|
+
encodeCalls: async (calls) => {
|
|
229
|
+
return encode7579Calls({
|
|
230
|
+
mode: {
|
|
231
|
+
type: calls.length > 1 ? "batchcall" : "call",
|
|
232
|
+
revertOnError: false,
|
|
233
|
+
selector: "0x",
|
|
234
|
+
context: "0x"
|
|
235
|
+
},
|
|
236
|
+
callData: calls
|
|
237
|
+
})
|
|
238
|
+
},
|
|
239
|
+
async getStubSignature() {
|
|
240
|
+
const dynamicPart = validatorAddress.substring(2).padEnd(40, "0")
|
|
241
|
+
return `0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${dynamicPart}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000` as Hex
|
|
242
|
+
},
|
|
243
|
+
async sign({ hash }) {
|
|
244
|
+
return this.signMessage({ message: hash })
|
|
245
|
+
},
|
|
246
|
+
async signMessage({ message }) {
|
|
247
|
+
const wrappedMessageHash = wrapMessageHash(hashMessage(message), {
|
|
248
|
+
version,
|
|
249
|
+
accountAddress: await this.getAddress(),
|
|
250
|
+
chainId: await getMemoizedChainId()
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
const signature = await localOwner.signMessage({
|
|
254
|
+
message: {
|
|
255
|
+
raw: wrappedMessageHash
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
return encodePacked(
|
|
260
|
+
["address", "bytes"],
|
|
261
|
+
[validatorAddress, signature]
|
|
262
|
+
)
|
|
263
|
+
},
|
|
264
|
+
async signTypedData(typedData) {
|
|
265
|
+
const {
|
|
266
|
+
message,
|
|
267
|
+
primaryType,
|
|
268
|
+
types: _types,
|
|
269
|
+
domain
|
|
270
|
+
} = typedData as TypedDataDefinition
|
|
271
|
+
|
|
272
|
+
const types = {
|
|
273
|
+
EIP712Domain: getTypesForEIP712Domain({
|
|
274
|
+
domain: domain
|
|
275
|
+
}),
|
|
276
|
+
..._types
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
validateTypedData({
|
|
280
|
+
domain,
|
|
281
|
+
message,
|
|
282
|
+
primaryType,
|
|
283
|
+
types
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
const typedHash = hashTypedData({
|
|
287
|
+
message,
|
|
288
|
+
primaryType,
|
|
289
|
+
types,
|
|
290
|
+
domain
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const wrappedMessageHash = wrapMessageHash(typedHash, {
|
|
294
|
+
version,
|
|
295
|
+
accountAddress: await this.getAddress(),
|
|
296
|
+
chainId: await getMemoizedChainId()
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const signature = await localOwner.signMessage({
|
|
300
|
+
message: {
|
|
301
|
+
raw: wrappedMessageHash
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
return encodePacked(
|
|
306
|
+
["address", "bytes"],
|
|
307
|
+
[validatorAddress, signature]
|
|
308
|
+
)
|
|
309
|
+
},
|
|
310
|
+
async signUserOperation(parameters) {
|
|
311
|
+
const { chainId = await getMemoizedChainId(), ...userOperation } =
|
|
312
|
+
parameters
|
|
313
|
+
|
|
314
|
+
if (!chainId) throw new Error("Chain id not found")
|
|
315
|
+
|
|
316
|
+
const hash = getUserOperationHash({
|
|
317
|
+
userOperation: {
|
|
318
|
+
...userOperation,
|
|
319
|
+
sender: userOperation.sender ?? (await this.getAddress()),
|
|
320
|
+
signature: "0x"
|
|
321
|
+
},
|
|
322
|
+
entryPointAddress: entryPoint.address,
|
|
323
|
+
entryPointVersion: entryPoint.version,
|
|
324
|
+
chainId: chainId
|
|
325
|
+
})
|
|
326
|
+
return await localOwner.signMessage({
|
|
327
|
+
message: { raw: hash as Hex }
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
})
|
|
331
|
+
}
|
|
@@ -1439,12 +1439,9 @@ export async function toSafeSmartAccount<
|
|
|
1439
1439
|
entryPoint: entryPoint.address
|
|
1440
1440
|
}
|
|
1441
1441
|
|
|
1442
|
-
let isDeployed = false
|
|
1443
|
-
|
|
1444
1442
|
if ("initCode" in userOperation) {
|
|
1445
1443
|
message.paymasterAndData =
|
|
1446
1444
|
userOperation.paymasterAndData ?? "0x"
|
|
1447
|
-
isDeployed = userOperation.initCode === "0x"
|
|
1448
1445
|
}
|
|
1449
1446
|
|
|
1450
1447
|
if ("factory" in userOperation) {
|
|
@@ -1458,14 +1455,6 @@ export async function toSafeSmartAccount<
|
|
|
1458
1455
|
...userOperation,
|
|
1459
1456
|
sender: userOperation.sender ?? (await this.getAddress())
|
|
1460
1457
|
})
|
|
1461
|
-
isDeployed = !userOperation.factory
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
let verifyingContract = safe4337ModuleAddress
|
|
1465
|
-
|
|
1466
|
-
if (erc7579LaunchpadAddress && !isDeployed) {
|
|
1467
|
-
verifyingContract =
|
|
1468
|
-
userOperation.sender ?? (await this.getAddress())
|
|
1469
1458
|
}
|
|
1470
1459
|
|
|
1471
1460
|
const signatures = [
|
|
@@ -1475,7 +1464,7 @@ export async function toSafeSmartAccount<
|
|
|
1475
1464
|
account: localOwner,
|
|
1476
1465
|
domain: {
|
|
1477
1466
|
chainId,
|
|
1478
|
-
verifyingContract
|
|
1467
|
+
verifyingContract: safe4337ModuleAddress
|
|
1479
1468
|
},
|
|
1480
1469
|
types:
|
|
1481
1470
|
entryPoint.version === "0.6"
|
|
@@ -35,7 +35,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
35
35
|
const opHash = await installModule(smartClient, {
|
|
36
36
|
account: smartClient.account,
|
|
37
37
|
type: "executor",
|
|
38
|
-
address: "
|
|
38
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
39
39
|
initData: name.startsWith("Kernel 7579")
|
|
40
40
|
? encodePacked(
|
|
41
41
|
["address", "bytes"],
|
|
@@ -74,7 +74,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
74
74
|
|
|
75
75
|
const isModuleInstalled = await smartClient.isModuleInstalled({
|
|
76
76
|
type: "executor",
|
|
77
|
-
address: "
|
|
77
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
78
78
|
context: "0x"
|
|
79
79
|
})
|
|
80
80
|
|
|
@@ -127,7 +127,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
127
127
|
const opHash = await installModule(smartClient, {
|
|
128
128
|
account: smartClient.account,
|
|
129
129
|
type: "executor",
|
|
130
|
-
address: "
|
|
130
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
131
131
|
context: name.startsWith("Kernel 7579")
|
|
132
132
|
? encodePacked(
|
|
133
133
|
["address", "bytes"],
|
|
@@ -165,7 +165,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
165
165
|
|
|
166
166
|
const isModuleInstalled = await smartClient.isModuleInstalled({
|
|
167
167
|
type: "executor",
|
|
168
|
-
address: "
|
|
168
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
169
169
|
context: "0x"
|
|
170
170
|
})
|
|
171
171
|
|
|
@@ -45,7 +45,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
45
45
|
{
|
|
46
46
|
type: "executor",
|
|
47
47
|
address:
|
|
48
|
-
"
|
|
48
|
+
"0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
49
49
|
context: name.startsWith("Kernel 7579")
|
|
50
50
|
? encodePacked(
|
|
51
51
|
["address", "bytes"],
|
|
@@ -88,7 +88,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
88
88
|
|
|
89
89
|
const isModuleInstalled = await smartClient.isModuleInstalled({
|
|
90
90
|
type: "executor",
|
|
91
|
-
address: "
|
|
91
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
92
92
|
context: "0x"
|
|
93
93
|
})
|
|
94
94
|
|
|
@@ -144,7 +144,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
144
144
|
{
|
|
145
145
|
type: "executor",
|
|
146
146
|
address:
|
|
147
|
-
"
|
|
147
|
+
"0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
148
148
|
context: name.startsWith("Kernel 7579")
|
|
149
149
|
? encodePacked(
|
|
150
150
|
["address", "bytes"],
|
|
@@ -187,7 +187,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
187
187
|
|
|
188
188
|
const isModuleInstalled = await smartClient.isModuleInstalled({
|
|
189
189
|
type: "executor",
|
|
190
|
-
address: "
|
|
190
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
191
191
|
context: "0x"
|
|
192
192
|
})
|
|
193
193
|
|
|
@@ -35,7 +35,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
35
35
|
const opHash = await smartClient.installModule({
|
|
36
36
|
account: smartClient.account as any,
|
|
37
37
|
type: "executor",
|
|
38
|
-
address: "
|
|
38
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
39
39
|
context: name.startsWith("Kernel 7579")
|
|
40
40
|
? encodePacked(
|
|
41
41
|
["address", "bytes"],
|
|
@@ -60,7 +60,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
60
60
|
{
|
|
61
61
|
account: smartClient.account,
|
|
62
62
|
type: "executor",
|
|
63
|
-
address: "
|
|
63
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
64
64
|
context: "0x"
|
|
65
65
|
}
|
|
66
66
|
)
|
|
@@ -58,28 +58,23 @@ export async function isModuleInstalled<
|
|
|
58
58
|
|
|
59
59
|
const abi = [
|
|
60
60
|
{
|
|
61
|
-
name: "isModuleInstalled",
|
|
62
61
|
type: "function",
|
|
63
|
-
|
|
62
|
+
name: "isModuleInstalled",
|
|
64
63
|
inputs: [
|
|
65
64
|
{
|
|
65
|
+
name: "moduleType",
|
|
66
66
|
type: "uint256",
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: "address",
|
|
71
|
-
name: "module"
|
|
67
|
+
internalType: "uint256"
|
|
72
68
|
},
|
|
69
|
+
{ name: "module", type: "address", internalType: "address" },
|
|
73
70
|
{
|
|
71
|
+
name: "additionalContext",
|
|
74
72
|
type: "bytes",
|
|
75
|
-
|
|
73
|
+
internalType: "bytes"
|
|
76
74
|
}
|
|
77
75
|
],
|
|
78
|
-
outputs: [
|
|
79
|
-
|
|
80
|
-
type: "bool"
|
|
81
|
-
}
|
|
82
|
-
]
|
|
76
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
77
|
+
stateMutability: "view"
|
|
83
78
|
}
|
|
84
79
|
] as const
|
|
85
80
|
|
|
@@ -34,7 +34,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
34
34
|
|
|
35
35
|
const opHash = await smartClient.installModule({
|
|
36
36
|
type: "executor",
|
|
37
|
-
address: "
|
|
37
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
38
38
|
context: name.startsWith("Kernel 7579")
|
|
39
39
|
? encodePacked(
|
|
40
40
|
["address", "bytes"],
|
|
@@ -59,7 +59,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
59
59
|
{
|
|
60
60
|
account: smartClient.account,
|
|
61
61
|
type: "executor",
|
|
62
|
-
address: "
|
|
62
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
63
63
|
context: name.startsWith("Kernel 7579")
|
|
64
64
|
? "0x"
|
|
65
65
|
: encodeAbiParameters(
|
|
@@ -34,7 +34,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
34
34
|
|
|
35
35
|
const opHash = await smartClient.installModule({
|
|
36
36
|
type: "executor",
|
|
37
|
-
address: "
|
|
37
|
+
address: "0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
38
38
|
context: name.startsWith("Kernel 7579")
|
|
39
39
|
? encodePacked(
|
|
40
40
|
["address", "bytes"],
|
|
@@ -62,7 +62,7 @@ describe.each(getCoreSmartAccounts())(
|
|
|
62
62
|
{
|
|
63
63
|
type: "executor",
|
|
64
64
|
address:
|
|
65
|
-
"
|
|
65
|
+
"0x4Fd8d57b94966982B62e9588C27B4171B55E8354",
|
|
66
66
|
context: name.startsWith("Kernel 7579")
|
|
67
67
|
? "0x"
|
|
68
68
|
: encodeAbiParameters(
|
package/package.json
CHANGED
|
@@ -54,24 +54,27 @@ export function encodeInstallModule<
|
|
|
54
54
|
data: encodeFunctionData({
|
|
55
55
|
abi: [
|
|
56
56
|
{
|
|
57
|
-
name: "installModule",
|
|
58
57
|
type: "function",
|
|
59
|
-
|
|
58
|
+
name: "installModule",
|
|
60
59
|
inputs: [
|
|
61
60
|
{
|
|
61
|
+
name: "moduleType",
|
|
62
62
|
type: "uint256",
|
|
63
|
-
|
|
63
|
+
internalType: "uint256"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
|
+
name: "module",
|
|
66
67
|
type: "address",
|
|
67
|
-
|
|
68
|
+
internalType: "address"
|
|
68
69
|
},
|
|
69
70
|
{
|
|
71
|
+
name: "initData",
|
|
70
72
|
type: "bytes",
|
|
71
|
-
|
|
73
|
+
internalType: "bytes"
|
|
72
74
|
}
|
|
73
75
|
],
|
|
74
|
-
outputs: []
|
|
76
|
+
outputs: [],
|
|
77
|
+
stateMutability: "nonpayable"
|
|
75
78
|
}
|
|
76
79
|
],
|
|
77
80
|
functionName: "installModule",
|
|
@@ -54,24 +54,27 @@ export function encodeUninstallModule<
|
|
|
54
54
|
data: encodeFunctionData({
|
|
55
55
|
abi: [
|
|
56
56
|
{
|
|
57
|
-
name: "uninstallModule",
|
|
58
57
|
type: "function",
|
|
59
|
-
|
|
58
|
+
name: "uninstallModule",
|
|
60
59
|
inputs: [
|
|
61
60
|
{
|
|
61
|
+
name: "moduleType",
|
|
62
62
|
type: "uint256",
|
|
63
|
-
|
|
63
|
+
internalType: "uint256"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
|
+
name: "module",
|
|
66
67
|
type: "address",
|
|
67
|
-
|
|
68
|
+
internalType: "address"
|
|
68
69
|
},
|
|
69
70
|
{
|
|
71
|
+
name: "deInitData",
|
|
70
72
|
type: "bytes",
|
|
71
|
-
|
|
73
|
+
internalType: "bytes"
|
|
72
74
|
}
|
|
73
75
|
],
|
|
74
|
-
outputs: []
|
|
76
|
+
outputs: [],
|
|
77
|
+
stateMutability: "nonpayable"
|
|
75
78
|
}
|
|
76
79
|
],
|
|
77
80
|
functionName: "uninstallModule",
|