@graphprotocol/hypergraph 0.0.1 → 0.0.2

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.
Files changed (328) hide show
  1. package/dist/connect/abis/MainVotingPlugin.json +1865 -0
  2. package/dist/connect/abis/PersonalSpaceAdminPlugin.json +531 -0
  3. package/dist/connect/abis.d.ts +115 -0
  4. package/dist/connect/abis.d.ts.map +1 -0
  5. package/dist/connect/abis.js +141 -0
  6. package/dist/connect/abis.js.map +1 -0
  7. package/dist/connect/auth-storage.d.ts +15 -0
  8. package/dist/connect/auth-storage.js +53 -0
  9. package/dist/connect/auth-storage.js.map +1 -0
  10. package/dist/connect/create-app-identity.d.ts +7 -0
  11. package/dist/connect/create-app-identity.js +15 -0
  12. package/dist/connect/create-app-identity.js.map +1 -0
  13. package/dist/connect/create-auth-url.d.ts +15 -0
  14. package/dist/connect/create-callback-params.d.ts +28 -0
  15. package/dist/connect/create-callback-params.d.ts.map +1 -1
  16. package/dist/connect/create-callback-params.js.map +1 -1
  17. package/dist/connect/create-identity-keys.d.ts +3 -0
  18. package/dist/connect/create-identity-keys.js +20 -0
  19. package/dist/connect/create-identity-keys.js.map +1 -0
  20. package/dist/connect/identity-encryption.d.ts +12 -0
  21. package/dist/connect/identity-encryption.d.ts.map +1 -1
  22. package/dist/connect/identity-encryption.js +187 -0
  23. package/dist/connect/identity-encryption.js.map +1 -0
  24. package/dist/connect/index.d.ts +11 -0
  25. package/dist/connect/index.d.ts.map +1 -1
  26. package/dist/connect/index.js +11 -0
  27. package/dist/connect/index.js.map +1 -0
  28. package/dist/connect/login.d.ts +22 -0
  29. package/dist/connect/login.d.ts.map +1 -1
  30. package/dist/connect/login.js +172 -0
  31. package/dist/connect/login.js.map +1 -0
  32. package/dist/connect/parse-auth-params.d.ts +14 -0
  33. package/dist/connect/parse-auth-params.d.ts.map +1 -0
  34. package/dist/connect/parse-auth-params.js +40 -0
  35. package/dist/connect/parse-auth-params.js.map +1 -0
  36. package/dist/connect/parse-callback-params.d.ts +13 -0
  37. package/dist/connect/parse-callback-params.d.ts.map +1 -1
  38. package/dist/connect/parse-callback-params.js +4 -1
  39. package/dist/connect/parse-callback-params.js.map +1 -1
  40. package/dist/connect/smart-account.d.ts +96 -0
  41. package/dist/connect/smart-account.d.ts.map +1 -0
  42. package/dist/connect/smart-account.js +761 -0
  43. package/dist/connect/smart-account.js.map +1 -0
  44. package/dist/connect/types.d.ts +2 -0
  45. package/dist/connect/types.d.ts.map +1 -1
  46. package/dist/connect/types.js.map +1 -1
  47. package/dist/entity/create.d.ts +8 -0
  48. package/dist/entity/create.js +51 -0
  49. package/dist/entity/create.js.map +1 -0
  50. package/dist/entity/decodedEntitiesCache.d.ts +23 -0
  51. package/dist/entity/decodedEntitiesCache.d.ts.map +1 -1
  52. package/dist/entity/decodedEntitiesCache.js +2 -0
  53. package/dist/entity/decodedEntitiesCache.js.map +1 -0
  54. package/dist/entity/delete.d.ts +12 -0
  55. package/dist/entity/delete.js +44 -0
  56. package/dist/entity/delete.js.map +1 -0
  57. package/dist/entity/entity.d.ts +18 -0
  58. package/dist/entity/entity.js +19 -0
  59. package/dist/entity/entity.js.map +1 -0
  60. package/dist/entity/entityRelationParentsMap.d.ts +4 -0
  61. package/dist/entity/entityRelationParentsMap.js +2 -0
  62. package/dist/entity/entityRelationParentsMap.js.map +1 -0
  63. package/dist/entity/findMany.d.ts +22 -0
  64. package/dist/entity/findMany.d.ts.map +1 -1
  65. package/dist/entity/findMany.js +8 -8
  66. package/dist/entity/findMany.js.map +1 -1
  67. package/dist/entity/findOne.d.ts +8 -0
  68. package/dist/entity/findOne.js +31 -0
  69. package/dist/entity/findOne.js.map +1 -0
  70. package/dist/entity/getEntityRelations.d.ts +4 -0
  71. package/dist/entity/getEntityRelations.d.ts.map +1 -1
  72. package/dist/entity/getEntityRelations.js +35 -0
  73. package/dist/entity/getEntityRelations.js.map +1 -0
  74. package/dist/entity/hasValidTypesProperty.d.ts +2 -0
  75. package/dist/entity/hasValidTypesProperty.d.ts.map +1 -0
  76. package/dist/entity/hasValidTypesProperty.js +4 -0
  77. package/dist/entity/hasValidTypesProperty.js.map +1 -0
  78. package/dist/entity/index.d.ts +9 -0
  79. package/dist/entity/index.js +9 -0
  80. package/dist/entity/index.js.map +1 -0
  81. package/dist/entity/relationParentsMap.d.ts +4 -0
  82. package/dist/entity/relationParentsMap.js +2 -0
  83. package/dist/entity/relationParentsMap.js.map +1 -0
  84. package/dist/entity/removeRelation.d.ts +7 -0
  85. package/dist/entity/removeRelation.js +17 -0
  86. package/dist/entity/removeRelation.js.map +1 -0
  87. package/dist/entity/test.d.ts +2 -0
  88. package/dist/entity/test.d.ts.map +1 -0
  89. package/dist/entity/test.js +2 -0
  90. package/dist/entity/test.js.map +1 -0
  91. package/dist/entity/types.d.ts +8 -8
  92. package/dist/entity/update.d.ts +8 -0
  93. package/dist/entity/update.js +58 -0
  94. package/dist/entity/update.js.map +1 -0
  95. package/dist/entity/variant-schema.d.ts +247 -0
  96. package/dist/entity/variant-schema.d.ts.map +1 -0
  97. package/dist/entity/variant-schema.js +204 -0
  98. package/dist/entity/variant-schema.js.map +1 -0
  99. package/dist/identity/auth-storage.d.ts +6 -0
  100. package/dist/identity/auth-storage.d.ts.map +1 -1
  101. package/dist/identity/auth-storage.js +52 -0
  102. package/dist/identity/auth-storage.js.map +1 -0
  103. package/dist/identity/get-verified-identity.d.ts +7 -0
  104. package/dist/identity/get-verified-identity.d.ts.map +1 -1
  105. package/dist/identity/get-verified-identity.js +37 -0
  106. package/dist/identity/get-verified-identity.js.map +1 -0
  107. package/dist/identity/identity-encryption.d.ts +7 -0
  108. package/dist/identity/identity-encryption.js +120 -0
  109. package/dist/identity/identity-encryption.js.map +1 -0
  110. package/dist/identity/index.d.ts +7 -0
  111. package/dist/identity/index.d.ts.map +1 -1
  112. package/dist/identity/index.js +7 -0
  113. package/dist/identity/index.js.map +1 -0
  114. package/dist/identity/logout.d.ts +3 -0
  115. package/dist/identity/logout.js +9 -0
  116. package/dist/identity/logout.js.map +1 -0
  117. package/dist/identity/prove-ownership.d.ts +15 -0
  118. package/dist/identity/prove-ownership.d.ts.map +1 -1
  119. package/dist/identity/prove-ownership.js +90 -0
  120. package/dist/identity/prove-ownership.js.map +1 -0
  121. package/dist/identity/types.d.ts +37 -0
  122. package/dist/identity/types.d.ts.map +1 -0
  123. package/dist/identity/types.js +11 -0
  124. package/dist/identity/types.js.map +1 -0
  125. package/dist/inboxes/create-inbox.d.ts +22 -0
  126. package/dist/inboxes/create-inbox.js +76 -0
  127. package/dist/inboxes/create-inbox.js.map +1 -0
  128. package/dist/inboxes/get-list-inboxes.d.ts +20 -0
  129. package/dist/inboxes/get-list-inboxes.js +45 -0
  130. package/dist/inboxes/get-list-inboxes.js.map +1 -0
  131. package/dist/inboxes/index.d.ts +11 -0
  132. package/dist/inboxes/index.js +11 -0
  133. package/dist/inboxes/index.js.map +1 -0
  134. package/dist/inboxes/merge-messages.d.ts +6 -0
  135. package/dist/inboxes/merge-messages.js +23 -0
  136. package/dist/inboxes/merge-messages.js.map +1 -0
  137. package/dist/inboxes/message-encryption.d.ts +15 -0
  138. package/dist/inboxes/message-encryption.js +29 -0
  139. package/dist/inboxes/message-encryption.js.map +1 -0
  140. package/dist/inboxes/message-validation.d.ts +6 -0
  141. package/dist/inboxes/message-validation.d.ts.map +1 -1
  142. package/dist/inboxes/message-validation.js +53 -0
  143. package/dist/inboxes/message-validation.js.map +1 -0
  144. package/dist/inboxes/prepare-message.d.ts +2 -2
  145. package/dist/inboxes/prepare-message.js +78 -0
  146. package/dist/inboxes/prepare-message.js.map +1 -0
  147. package/dist/inboxes/recover-inbox-creator.d.ts +5 -0
  148. package/dist/inboxes/recover-inbox-creator.js +24 -0
  149. package/dist/inboxes/recover-inbox-creator.js.map +1 -0
  150. package/dist/inboxes/recover-inbox-message-signer.d.ts +4 -0
  151. package/dist/inboxes/recover-inbox-message-signer.js +32 -0
  152. package/dist/inboxes/recover-inbox-message-signer.js.map +1 -0
  153. package/dist/inboxes/send-message.d.ts +19 -0
  154. package/dist/inboxes/send-message.js +58 -0
  155. package/dist/inboxes/send-message.js.map +1 -0
  156. package/dist/inboxes/types.d.ts +4 -0
  157. package/dist/inboxes/types.d.ts.map +1 -0
  158. package/dist/inboxes/types.js +3 -0
  159. package/dist/inboxes/types.js.map +1 -0
  160. package/dist/index.d.ts +14 -0
  161. package/dist/index.js +14 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/key/create-key.d.ts +11 -0
  164. package/dist/key/create-key.d.ts.map +1 -0
  165. package/dist/key/create-key.js +22 -0
  166. package/dist/key/create-key.js.map +1 -0
  167. package/dist/key/decrypt-key.d.ts +9 -0
  168. package/dist/key/decrypt-key.d.ts.map +1 -0
  169. package/dist/key/decrypt-key.js +16 -0
  170. package/dist/key/decrypt-key.js.map +1 -0
  171. package/dist/key/encrypt-key.d.ts +11 -0
  172. package/dist/key/encrypt-key.d.ts.map +1 -0
  173. package/dist/key/encrypt-key.js +20 -0
  174. package/dist/key/encrypt-key.js.map +1 -0
  175. package/dist/key/index.d.ts +5 -0
  176. package/dist/key/index.d.ts.map +1 -0
  177. package/dist/key/index.js +5 -0
  178. package/dist/key/index.js.map +1 -0
  179. package/dist/key/key-box.d.ts +19 -0
  180. package/dist/key/key-box.d.ts.map +1 -0
  181. package/dist/key/key-box.js +38 -0
  182. package/dist/key/key-box.js.map +1 -0
  183. package/dist/messages/decrypt-message.d.ts +7 -0
  184. package/dist/messages/decrypt-message.d.ts.map +1 -0
  185. package/dist/messages/decrypt-message.js +11 -0
  186. package/dist/messages/decrypt-message.js.map +1 -0
  187. package/dist/messages/encrypt-message.d.ts +7 -0
  188. package/dist/messages/encrypt-message.d.ts.map +1 -0
  189. package/dist/messages/encrypt-message.js +12 -0
  190. package/dist/messages/encrypt-message.js.map +1 -0
  191. package/dist/messages/index.d.ts +6 -0
  192. package/dist/messages/index.js +6 -0
  193. package/dist/messages/index.js.map +1 -0
  194. package/dist/messages/serialize.d.ts +3 -0
  195. package/dist/messages/serialize.d.ts.map +1 -0
  196. package/dist/messages/serialize.js +30 -0
  197. package/dist/messages/serialize.js.map +1 -0
  198. package/dist/messages/signed-update-message.d.ts +23 -0
  199. package/dist/messages/signed-update-message.js +56 -0
  200. package/dist/messages/signed-update-message.js.map +1 -0
  201. package/dist/messages/types.d.ts +1268 -0
  202. package/dist/messages/types.d.ts.map +1 -1
  203. package/dist/messages/types.js +312 -0
  204. package/dist/messages/types.js.map +1 -0
  205. package/dist/space-events/accept-invitation.d.ts +9 -0
  206. package/dist/space-events/accept-invitation.js +28 -0
  207. package/dist/space-events/accept-invitation.js.map +1 -0
  208. package/dist/space-events/apply-event.d.ts +11 -0
  209. package/dist/space-events/apply-event.js +130 -0
  210. package/dist/space-events/apply-event.js.map +1 -0
  211. package/dist/space-events/create-inbox.d.ts +14 -0
  212. package/dist/space-events/create-inbox.js +41 -0
  213. package/dist/space-events/create-inbox.js.map +1 -0
  214. package/dist/space-events/create-invitation.d.ts +12 -0
  215. package/dist/space-events/create-invitation.js +30 -0
  216. package/dist/space-events/create-invitation.js.map +1 -0
  217. package/dist/space-events/create-space.d.ts +9 -0
  218. package/dist/space-events/create-space.js +29 -0
  219. package/dist/space-events/create-space.js.map +1 -0
  220. package/dist/space-events/delete-space.d.ts +10 -0
  221. package/dist/space-events/delete-space.js +30 -0
  222. package/dist/space-events/delete-space.js.map +1 -0
  223. package/dist/space-events/hash-event.d.ts +3 -0
  224. package/dist/space-events/hash-event.js +7 -0
  225. package/dist/space-events/hash-event.js.map +1 -0
  226. package/dist/space-events/index.d.ts +9 -0
  227. package/dist/space-events/index.js +9 -0
  228. package/dist/space-events/index.js.map +1 -0
  229. package/dist/space-events/types.d.ts +222 -0
  230. package/dist/space-events/types.d.ts.map +1 -0
  231. package/dist/space-events/types.js +102 -0
  232. package/dist/space-events/types.js.map +1 -0
  233. package/dist/space-info/decrypt-space-info.d.ts +7 -0
  234. package/dist/space-info/decrypt-space-info.js +18 -0
  235. package/dist/space-info/decrypt-space-info.js.map +1 -0
  236. package/dist/space-info/encrypt-and-sign-space-info.d.ts +17 -0
  237. package/dist/space-info/encrypt-and-sign-space-info.js +39 -0
  238. package/dist/space-info/encrypt-and-sign-space-info.js.map +1 -0
  239. package/dist/space-info/index.d.ts +4 -0
  240. package/dist/space-info/index.js +4 -0
  241. package/dist/space-info/index.js.map +1 -0
  242. package/dist/space-info/types.d.ts +6 -0
  243. package/dist/space-info/types.d.ts.map +1 -0
  244. package/dist/space-info/types.js +5 -0
  245. package/dist/space-info/types.js.map +1 -0
  246. package/dist/store-connect.d.ts +149 -0
  247. package/dist/store-connect.d.ts.map +1 -1
  248. package/dist/store-connect.js +289 -0
  249. package/dist/store-connect.js.map +1 -0
  250. package/dist/store.d.ts +158 -0
  251. package/dist/store.d.ts.map +1 -1
  252. package/dist/store.js +354 -0
  253. package/dist/store.js.map +1 -0
  254. package/dist/type/type.d.ts +14 -0
  255. package/dist/type/type.d.ts.map +1 -1
  256. package/dist/type/type.js +25 -0
  257. package/dist/type/type.js.map +1 -0
  258. package/dist/types.d.ts +80 -0
  259. package/dist/types.d.ts.map +1 -0
  260. package/dist/types.js +37 -0
  261. package/dist/types.js.map +1 -0
  262. package/dist/utils/assertExhaustive.d.ts +2 -0
  263. package/dist/utils/assertExhaustive.d.ts.map +1 -0
  264. package/dist/utils/assertExhaustive.js +4 -0
  265. package/dist/utils/assertExhaustive.js.map +1 -0
  266. package/dist/utils/automergeId.d.ts +1 -1
  267. package/dist/utils/automergeId.d.ts.map +1 -1
  268. package/dist/utils/automergeId.js +1 -1
  269. package/dist/utils/automergeId.js.map +1 -1
  270. package/dist/utils/base58.d.ts +36 -0
  271. package/dist/utils/base58.d.ts.map +1 -0
  272. package/dist/utils/base58.js +62 -0
  273. package/dist/utils/base58.js.map +1 -0
  274. package/dist/utils/hexBytesAddressUtils.d.ts +4 -0
  275. package/dist/utils/hexBytesAddressUtils.d.ts.map +1 -0
  276. package/dist/utils/hexBytesAddressUtils.js +21 -0
  277. package/dist/utils/hexBytesAddressUtils.js.map +1 -0
  278. package/dist/utils/index.d.ts +9 -0
  279. package/dist/utils/index.js +9 -0
  280. package/dist/utils/index.js.map +1 -0
  281. package/dist/utils/internal/base58Utils.d.ts +4 -0
  282. package/dist/utils/internal/base58Utils.d.ts.map +1 -0
  283. package/dist/utils/internal/base58Utils.js +40 -0
  284. package/dist/utils/internal/base58Utils.js.map +1 -0
  285. package/dist/utils/internal/deep-merge.d.ts +7 -0
  286. package/dist/utils/internal/deep-merge.d.ts.map +1 -0
  287. package/dist/utils/internal/deep-merge.js +33 -0
  288. package/dist/utils/internal/deep-merge.js.map +1 -0
  289. package/dist/utils/isRelationField.d.ts +3 -0
  290. package/dist/utils/isRelationField.d.ts.map +1 -0
  291. package/dist/utils/isRelationField.js +8 -0
  292. package/dist/utils/isRelationField.js.map +1 -0
  293. package/dist/utils/jsc.d.ts +49 -0
  294. package/dist/utils/jsc.d.ts.map +1 -0
  295. package/dist/utils/jsc.js +88 -0
  296. package/dist/utils/jsc.js.map +1 -0
  297. package/dist/utils/stringToUint8Array.d.ts +3 -0
  298. package/dist/utils/stringToUint8Array.d.ts.map +1 -0
  299. package/dist/utils/stringToUint8Array.js +9 -0
  300. package/dist/utils/stringToUint8Array.js.map +1 -0
  301. package/package.json +5 -2
  302. package/src/connect/abis/MainVotingPlugin.json +1865 -0
  303. package/src/connect/abis/PersonalSpaceAdminPlugin.json +531 -0
  304. package/src/connect/abis.ts +183 -0
  305. package/src/connect/create-callback-params.ts +4 -1
  306. package/src/connect/identity-encryption.ts +10 -14
  307. package/src/connect/index.ts +1 -1
  308. package/src/connect/login.ts +106 -18
  309. package/src/connect/parse-callback-params.ts +4 -1
  310. package/src/connect/smart-account.ts +915 -0
  311. package/src/connect/types.ts +2 -0
  312. package/src/entity/decodedEntitiesCache.ts +1 -1
  313. package/src/entity/findMany.ts +16 -14
  314. package/src/entity/getEntityRelations.ts +1 -1
  315. package/src/entity/types.ts +8 -8
  316. package/src/identity/auth-storage.ts +11 -1
  317. package/src/identity/get-verified-identity.ts +6 -1
  318. package/src/identity/index.ts +1 -1
  319. package/src/identity/prove-ownership.ts +52 -8
  320. package/src/inboxes/message-validation.ts +17 -2
  321. package/src/messages/types.ts +6 -0
  322. package/src/store-connect.ts +1 -52
  323. package/src/store.ts +78 -48
  324. package/src/type/type.ts +4 -2
  325. package/src/types.ts +19 -1
  326. package/src/utils/automergeId.ts +1 -1
  327. package/dist/connect/prove-ownership.d.ts.map +0 -1
  328. package/src/connect/prove-ownership.ts +0 -58
@@ -0,0 +1,761 @@
1
+ import { MAINNET, TESTNET } from '@graphprotocol/grc-20/contracts';
2
+ import { randomBytes } from '@noble/hashes/utils';
3
+ import { OWNABLE_VALIDATOR_ADDRESS, RHINESTONE_ATTESTER_ADDRESS, SmartSessionMode, encodeSmartSessionSignature, encodeValidationData, encodeValidatorNonce, getAccount, getEnableSessionDetails, getOwnableValidator, getOwnableValidatorMockSignature, getPermissionId, getSmartSessionsValidator, getSpendingLimitsPolicy, getSudoPolicy, getTimeFramePolicy, getUniversalActionPolicy, getUsageLimitPolicy, getValueLimitPolicy } from '@rhinestone/module-sdk';
4
+ import { createSmartAccountClient, encodeInstallModule } from 'permissionless';
5
+ import { toSafeSmartAccount } from 'permissionless/accounts';
6
+ import { getAccountNonce } from 'permissionless/actions';
7
+ import { erc7579Actions } from 'permissionless/actions/erc7579';
8
+ import { createPimlicoClient } from 'permissionless/clients/pimlico';
9
+ import { http, ContractFunctionExecutionError, createPublicClient, encodeFunctionData, getAbiItem, toBytes, toFunctionSelector, toHex } from 'viem';
10
+ import { entryPoint07Address, getUserOperationHash } from 'viem/account-abstraction';
11
+ import { privateKeyToAccount } from 'viem/accounts';
12
+ import { bytesToHex } from '../utils/hexBytesAddressUtils.js';
13
+ import { daoFactoryAbi, mainVotingAbi, personalSpaceAdminAbi, safe7579Abi, safeModuleManagerAbi, safeOwnerManagerAbi, smartSessionsAbi } from './abis.js';
14
+ export const DEFAULT_RPC_URL = 'https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz';
15
+ export const TESTNET_RPC_URL = 'https://rpc-geo-test-zc16z3tcvf.t.conduit.xyz';
16
+ /**
17
+ * We provide a fallback API key for gas sponsorship for the duration of the
18
+ * Geo Genesis early access period. This API key is gas-limited.
19
+ */
20
+ const DEFAULT_API_KEY = 'pim_KqHm63txxhbCYjdDaWaHqH';
21
+ const BUNDLER_TRANSPORT_URL_BASE = 'https://api.pimlico.io/v2/';
22
+ const SAFE_7579_MODULE_ADDRESS = '0x7579EE8307284F293B1927136486880611F20002';
23
+ const SAFE_4337_MODULE_ADDRESS = '0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226';
24
+ const ERC7579_LAUNCHPAD_ADDRESS = '0x7579011aB74c46090561ea277Ba79D510c6C00ff';
25
+ const SPACE_FACTORY_ADDRESS = {
26
+ '80451': MAINNET.DAO_FACTORY_ADDRESS,
27
+ '19411': TESTNET.DAO_FACTORY_ADDRESS
28
+ };
29
+ const MODULE_TYPE_VALIDATOR = 1;
30
+ const PUBLIC_SPACE_FUNCTIONS = ['leaveSpace', 'leaveSpaceAsEditor', 'createProposal', 'proposeEdits', 'proposeAcceptSubspace', 'proposeRemoveSubspace', 'proposeAddMember', 'proposeRemoveMember', 'proposeAddEditor', 'proposeRemoveEditor', 'cancelProposal', 'vote', 'execute'];
31
+ const PERSONAL_SPACE_FUNCTIONS = ['executeProposal', 'submitEdits', 'submitAcceptSubspace', 'submitRemoveSubspace', 'submitNewMember', 'submitRemoveMember', 'leaveSpace', 'submitNewEditor', 'submitRemoveEditor'];
32
+ export const GEOGENESIS = {
33
+ id: /*#__PURE__*/Number('80451'),
34
+ name: 'Geo Genesis',
35
+ nativeCurrency: {
36
+ name: 'Graph Token',
37
+ symbol: 'GRT',
38
+ decimals: 18
39
+ },
40
+ rpcUrls: {
41
+ default: {
42
+ http: [DEFAULT_RPC_URL]
43
+ },
44
+ public: {
45
+ http: [DEFAULT_RPC_URL]
46
+ }
47
+ }
48
+ };
49
+ export const GEO_TESTNET = {
50
+ id: /*#__PURE__*/Number('19411'),
51
+ name: 'Geo Testnet',
52
+ nativeCurrency: {
53
+ name: 'Sepolia Ether',
54
+ symbol: 'ETH',
55
+ decimals: 18
56
+ },
57
+ rpcUrls: {
58
+ default: {
59
+ http: [TESTNET_RPC_URL]
60
+ },
61
+ public: {
62
+ http: [TESTNET_RPC_URL]
63
+ }
64
+ }
65
+ };
66
+ // We re-export these functions to allow creating sessions with policies for
67
+ // additional actions without needing the Rhinestone module SDK.
68
+ export { getSudoPolicy, getUniversalActionPolicy, getSpendingLimitsPolicy, getTimeFramePolicy, getUsageLimitPolicy, getValueLimitPolicy };
69
+ // Gets the legacy Geo smart account wallet client. If the smart account returned
70
+ // by this function is deployed, it means it might need to be updated to have the 7579 module installed
71
+ const getLegacySmartAccountWalletClient = async ({
72
+ owner,
73
+ address,
74
+ chain = GEOGENESIS,
75
+ rpcUrl = DEFAULT_RPC_URL,
76
+ apiKey = DEFAULT_API_KEY
77
+ }) => {
78
+ const transport = http(rpcUrl);
79
+ const publicClient = createPublicClient({
80
+ transport,
81
+ chain
82
+ });
83
+ const safeAccountParams = {
84
+ client: publicClient,
85
+ owners: [owner],
86
+ entryPoint: {
87
+ address: entryPoint07Address,
88
+ version: '0.7'
89
+ },
90
+ version: '1.4.1'
91
+ };
92
+ if (address) {
93
+ safeAccountParams.address = address;
94
+ }
95
+ if (chain.id === GEO_TESTNET.id) {
96
+ // Custom SAFE Addresses
97
+ // TODO: remove this once we have the smart sessions module deployed on testnet
98
+ // (and the canonical addresses are deployed)
99
+ safeAccountParams.safeModuleSetupAddress = '0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47';
100
+ safeAccountParams.safe4337ModuleAddress = '0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226';
101
+ safeAccountParams.safeProxyFactoryAddress = '0xd9d2Ba03a7754250FDD71333F444636471CACBC4';
102
+ safeAccountParams.safeSingletonAddress = '0x639245e8476E03e789a244f279b5843b9633b2E7';
103
+ safeAccountParams.multiSendAddress = '0x7B21BBDBdE8D01Df591fdc2dc0bE9956Dde1e16C';
104
+ safeAccountParams.multiSendCallOnlyAddress = '0x32228dDEA8b9A2bd7f2d71A958fF241D79ca5eEC';
105
+ }
106
+ const safeAccount = await toSafeSmartAccount(safeAccountParams);
107
+ const bundlerTransport = http(`${BUNDLER_TRANSPORT_URL_BASE}${chain.id}/rpc?apikey=${apiKey}`);
108
+ const paymasterClient = createPimlicoClient({
109
+ transport: bundlerTransport,
110
+ chain,
111
+ entryPoint: {
112
+ address: entryPoint07Address,
113
+ version: '0.7'
114
+ }
115
+ });
116
+ const smartAccountClient = createSmartAccountClient({
117
+ chain,
118
+ account: safeAccount,
119
+ paymaster: paymasterClient,
120
+ bundlerTransport,
121
+ userOperation: {
122
+ estimateFeesPerGas: async () => {
123
+ return (await paymasterClient.getUserOperationGasPrice()).fast;
124
+ }
125
+ }
126
+ });
127
+ return smartAccountClient;
128
+ };
129
+ // Gets the 7579 smart account wallet client. This is the new type of smart account that
130
+ // includes the session keys validator and the 7579 module.
131
+ const get7579SmartAccountWalletClient = async ({
132
+ owner,
133
+ address,
134
+ chain = GEOGENESIS,
135
+ rpcUrl = DEFAULT_RPC_URL,
136
+ apiKey = DEFAULT_API_KEY
137
+ }) => {
138
+ const transport = http(rpcUrl);
139
+ const publicClient = createPublicClient({
140
+ transport,
141
+ chain
142
+ });
143
+ console.log('owner', owner);
144
+ console.log('chain', chain);
145
+ console.log('rpcUrl', rpcUrl);
146
+ console.log('apiKey', apiKey);
147
+ console.log('address', address);
148
+ const ownerAddress = 'account' in owner ? owner.account?.address : owner.address;
149
+ if (!ownerAddress) {
150
+ throw new Error('Owner address not found');
151
+ }
152
+ const ownableValidator = getOwnableValidator({
153
+ owners: [ownerAddress],
154
+ threshold: 1
155
+ });
156
+ const smartSessionsValidator = getSmartSessionsValidator({});
157
+ const safeAccountParams = {
158
+ client: publicClient,
159
+ owners: [owner],
160
+ version: '1.4.1',
161
+ entryPoint: {
162
+ address: entryPoint07Address,
163
+ version: '0.7'
164
+ },
165
+ safe4337ModuleAddress: SAFE_7579_MODULE_ADDRESS,
166
+ erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS,
167
+ attesters: [RHINESTONE_ATTESTER_ADDRESS // Rhinestone Attester
168
+ ],
169
+ attestersThreshold: 1,
170
+ validators: [{
171
+ address: ownableValidator.address,
172
+ context: ownableValidator.initData
173
+ }, {
174
+ address: smartSessionsValidator.address,
175
+ context: smartSessionsValidator.initData
176
+ }]
177
+ };
178
+ if (address) {
179
+ safeAccountParams.address = address;
180
+ }
181
+ const safeAccount = await toSafeSmartAccount(safeAccountParams);
182
+ const bundlerTransport = http(`${BUNDLER_TRANSPORT_URL_BASE}${chain.id}/rpc?apikey=${apiKey}`);
183
+ const paymasterClient = createPimlicoClient({
184
+ transport: bundlerTransport,
185
+ chain,
186
+ entryPoint: {
187
+ address: entryPoint07Address,
188
+ version: '0.7'
189
+ }
190
+ });
191
+ const smartAccountClient = createSmartAccountClient({
192
+ chain,
193
+ account: safeAccount,
194
+ paymaster: paymasterClient,
195
+ bundlerTransport,
196
+ userOperation: {
197
+ estimateFeesPerGas: async () => {
198
+ return (await paymasterClient.getUserOperationGasPrice()).fast;
199
+ }
200
+ }
201
+ }).extend(erc7579Actions());
202
+ // For some reason, the .extend() breaks the type inference, so we need to cast to unknown
203
+ return smartAccountClient;
204
+ };
205
+ // Checks if the smart account is deployed.
206
+ export const isSmartAccountDeployed = async smartAccountClient => {
207
+ if (!smartAccountClient.account) {
208
+ throw new Error('Invalid smart account');
209
+ }
210
+ return smartAccountClient.account.isDeployed();
211
+ };
212
+ // Gets the smart account wallet client. This is the main function to use to get a smart account wallet client.
213
+ // It will return the 7579 smart account wallet client if the smart account is deployed, otherwise it will return the legacy smart account wallet client, that might need to be updated.
214
+ // You can use smartAccountNeedsUpdate to check if the smart account needs to be updated, and then call updateLegacySmartAccount to update it,
215
+ // which requires executing a user operation.
216
+ export const getSmartAccountWalletClient = async ({
217
+ owner,
218
+ address,
219
+ chain = GEOGENESIS,
220
+ rpcUrl = DEFAULT_RPC_URL,
221
+ apiKey = DEFAULT_API_KEY
222
+ }) => {
223
+ if (chain.id === GEO_TESTNET.id) {
224
+ // We don't have the smart sessions module deployed on testnet yet, so we need to use the legacy smart account wallet client
225
+ // TODO: remove this once we have the smart sessions module deployed on testnet
226
+ const params = {
227
+ owner,
228
+ chain,
229
+ rpcUrl,
230
+ apiKey
231
+ };
232
+ if (address) {
233
+ params.address = address;
234
+ }
235
+ console.log('on testnet, getting legacy smart account wallet client');
236
+ return getLegacySmartAccountWalletClient(params);
237
+ }
238
+ if (address) {
239
+ return get7579SmartAccountWalletClient({
240
+ owner,
241
+ address,
242
+ chain,
243
+ rpcUrl,
244
+ apiKey
245
+ });
246
+ }
247
+ const legacyClient = await getLegacySmartAccountWalletClient({
248
+ owner,
249
+ chain,
250
+ rpcUrl,
251
+ apiKey
252
+ });
253
+ if (await isSmartAccountDeployed(legacyClient)) {
254
+ return legacyClient;
255
+ }
256
+ return get7579SmartAccountWalletClient({
257
+ owner,
258
+ chain,
259
+ rpcUrl,
260
+ apiKey
261
+ });
262
+ };
263
+ // Checks if the smart account has the 7579 module installed, the smart sessions validator installed, and the ownable validator installed.
264
+ export const legacySmartAccountUpdateStatus = async (smartAccountClient, chain, rpcUrl) => {
265
+ if (!smartAccountClient.account) {
266
+ throw new Error('Invalid smart account');
267
+ }
268
+ // We assume the smart account is deployed, so we just need to check if it has the 7579 module and smart sesions validator installed
269
+ // TODO: call the isModuleInstalled function from the safe7579Abi on the
270
+ // smart account, checking if the smart sessions validator is installed. This would fail
271
+ // if the smart account doesn't have the 7579 module installed.
272
+ const transport = http(rpcUrl);
273
+ const publicClient = createPublicClient({
274
+ transport,
275
+ chain
276
+ });
277
+ const smartSessionsValidator = getSmartSessionsValidator({});
278
+ let isSmartSessionsValidatorInstalled = false;
279
+ try {
280
+ isSmartSessionsValidatorInstalled = await publicClient.readContract({
281
+ abi: safe7579Abi,
282
+ address: smartAccountClient.account.address,
283
+ functionName: 'isModuleInstalled',
284
+ args: [MODULE_TYPE_VALIDATOR, smartSessionsValidator.address, '0x']
285
+ });
286
+ } catch (error) {
287
+ if (error instanceof ContractFunctionExecutionError && error.details.includes('execution reverted')) {
288
+ // If the smart account doesn't have the 7579 module installed, the isModuleInstalled function will revert
289
+ return {
290
+ has7579Module: false,
291
+ hasSmartSessionsValidator: false,
292
+ hasOwnableValidator: false
293
+ };
294
+ }
295
+ throw error;
296
+ }
297
+ const ownableValidator = getOwnableValidator({
298
+ owners: [smartAccountClient.account.address],
299
+ threshold: 1
300
+ });
301
+ // This shouldn't throw because by now we know the smart account has the 7579 module installed
302
+ const isOwnableValidatorInstalled = await publicClient.readContract({
303
+ abi: safe7579Abi,
304
+ address: smartAccountClient.account.address,
305
+ functionName: 'isModuleInstalled',
306
+ args: [MODULE_TYPE_VALIDATOR, ownableValidator.address, '0x']
307
+ });
308
+ return {
309
+ has7579Module: true,
310
+ hasSmartSessionsValidator: isSmartSessionsValidatorInstalled,
311
+ hasOwnableValidator: isOwnableValidatorInstalled
312
+ };
313
+ };
314
+ // Checks if the smart account needs to be updated from a legacy ERC-4337 smart account to an ERC-7579 smart account
315
+ // with support for smart sessions.
316
+ export const smartAccountNeedsUpdate = async (smartAccountClient, chain, rpcUrl) => {
317
+ if (chain.id === GEO_TESTNET.id) {
318
+ // We don't have the smart sessions module deployed on testnet yet, so we need to use the legacy smart account wallet client
319
+ // TODO: remove this once we have the smart sessions module deployed on testnet
320
+ return false;
321
+ }
322
+ // If we haven't deployed the smart account, we would always deploy an updated version
323
+ if (!(await isSmartAccountDeployed(smartAccountClient))) {
324
+ return false;
325
+ }
326
+ const updateStatus = await legacySmartAccountUpdateStatus(smartAccountClient, chain, rpcUrl);
327
+ return !updateStatus.has7579Module || !updateStatus.hasSmartSessionsValidator || !updateStatus.hasOwnableValidator;
328
+ };
329
+ // Legacy Geo smart accounts (i.e. the ones that don't have the 7579 module installed)
330
+ // need to be updated to have the 7579 module installed with the ownable and smart sessions validators.
331
+ export const updateLegacySmartAccount = async (smartAccountClient, chain, rpcUrl) => {
332
+ if (!smartAccountClient.account?.address) {
333
+ throw new Error('Invalid smart account');
334
+ }
335
+ if (chain.id === GEO_TESTNET.id) {
336
+ // We don't have the smart sessions module deployed on testnet yet, so we need to use the legacy smart account wallet client
337
+ // TODO: remove this once we have the smart sessions module deployed on testnet
338
+ console.log('on testnet, skipping updateLegacySmartAccount');
339
+ return;
340
+ }
341
+ const ownableValidator = getOwnableValidator({
342
+ owners: [smartAccountClient.account.address],
343
+ threshold: 1
344
+ });
345
+ const smartSessionsValidator = getSmartSessionsValidator({});
346
+ const installValidatorsTx = encodeInstallModule({
347
+ account: smartAccountClient.account,
348
+ modules: [{
349
+ type: ownableValidator.type,
350
+ address: ownableValidator.address,
351
+ context: ownableValidator.initData
352
+ }, {
353
+ type: smartSessionsValidator.type,
354
+ address: smartSessionsValidator.address,
355
+ context: smartSessionsValidator.initData
356
+ }]
357
+ });
358
+ const updateStatus = await legacySmartAccountUpdateStatus(smartAccountClient, chain, rpcUrl);
359
+ const calls = [];
360
+ if (!updateStatus.has7579Module) {
361
+ calls.push({
362
+ to: smartAccountClient.account.address,
363
+ data: encodeFunctionData({
364
+ abi: safeModuleManagerAbi,
365
+ functionName: 'enableModule',
366
+ args: [SAFE_7579_MODULE_ADDRESS]
367
+ }),
368
+ value: BigInt(0)
369
+ });
370
+ calls.push({
371
+ to: smartAccountClient.account.address,
372
+ data: encodeFunctionData({
373
+ abi: safeModuleManagerAbi,
374
+ functionName: 'setFallbackHandler',
375
+ args: [SAFE_7579_MODULE_ADDRESS]
376
+ }),
377
+ value: BigInt(0)
378
+ });
379
+ calls.push({
380
+ to: smartAccountClient.account.address,
381
+ data: encodeFunctionData({
382
+ abi: safeModuleManagerAbi,
383
+ functionName: 'disableModule',
384
+ args: [SAFE_4337_MODULE_ADDRESS]
385
+ }),
386
+ value: BigInt(0)
387
+ });
388
+ }
389
+ if (!updateStatus.hasOwnableValidator) {
390
+ calls.push({
391
+ to: installValidatorsTx[0].to,
392
+ data: installValidatorsTx[0].data,
393
+ value: installValidatorsTx[0].value
394
+ });
395
+ }
396
+ if (!updateStatus.hasSmartSessionsValidator) {
397
+ calls.push({
398
+ to: installValidatorsTx[1].to,
399
+ data: installValidatorsTx[1].data,
400
+ value: installValidatorsTx[1].value
401
+ });
402
+ }
403
+ if (calls.length === 0) {
404
+ return;
405
+ }
406
+ const tx = await smartAccountClient.sendUserOperation({
407
+ calls
408
+ });
409
+ const receipt = await smartAccountClient.waitForUserOperationReceipt({
410
+ hash: tx
411
+ });
412
+ if (!receipt.success) {
413
+ throw new Error('Transaction to update legacy smart account failed');
414
+ }
415
+ return receipt;
416
+ };
417
+ // Gets the actions that a session key needs permission to perform on a space.
418
+ const getSpaceActions = space => {
419
+ const actions = [];
420
+ if (space.type === 'public') {
421
+ for (const functionName of PUBLIC_SPACE_FUNCTIONS) {
422
+ actions.push({
423
+ actionTarget: space.address,
424
+ actionTargetSelector: toFunctionSelector(getAbiItem({
425
+ abi: mainVotingAbi,
426
+ name: functionName
427
+ })),
428
+ actionPolicies: [getSudoPolicy()]
429
+ });
430
+ }
431
+ } else {
432
+ for (const functionName of PERSONAL_SPACE_FUNCTIONS) {
433
+ actions.push({
434
+ actionTarget: space.address,
435
+ actionTargetSelector: toFunctionSelector(getAbiItem({
436
+ abi: personalSpaceAdminAbi,
437
+ name: functionName
438
+ })),
439
+ actionPolicies: [getSudoPolicy()]
440
+ });
441
+ }
442
+ }
443
+ return actions;
444
+ };
445
+ // This is the function that the Connect app uses to create a smart session and
446
+ // enable it on the smart account.
447
+ // It will prompt the user to sign the message to enable the session, and then
448
+ // execute the transaction to enable the session.
449
+ // It will return the permissionId that can be used to create a smart session client.
450
+ export const createSmartSession = async (owner, accountAddress, sessionPrivateKey, chain, rpcUrl, {
451
+ allowCreateSpace = false,
452
+ spaces = [],
453
+ additionalActions = []
454
+ } = {}) => {
455
+ const smartAccountClient = await getSmartAccountWalletClient({
456
+ owner,
457
+ address: accountAddress,
458
+ chain,
459
+ rpcUrl
460
+ });
461
+ if (!smartAccountClient.account) {
462
+ throw new Error('Invalid wallet client');
463
+ }
464
+ if (!smartAccountClient.account.isDeployed()) {
465
+ throw new Error('Smart account must be deployed');
466
+ }
467
+ if (await smartAccountNeedsUpdate(smartAccountClient, chain, rpcUrl)) {
468
+ throw new Error('Smart account needs to be updated');
469
+ }
470
+ if (!smartAccountClient.chain) {
471
+ throw new Error('Invalid smart account chain');
472
+ }
473
+ if (!owner.account) {
474
+ throw new Error('Invalid wallet client');
475
+ }
476
+ const sessionKeyAccount = privateKeyToAccount(sessionPrivateKey);
477
+ const transport = http(rpcUrl);
478
+ const publicClient = createPublicClient({
479
+ transport,
480
+ chain
481
+ });
482
+ if (chain.id === GEO_TESTNET.id) {
483
+ // We don't have the smart sessions module deployed on testnet yet, so we need to fake it by adding an account owner
484
+ // TODO: remove this once we have the smart sessions module deployed on testnet
485
+ console.log('on testnet, faking a smart session by adding an account owner');
486
+ const tx = await smartAccountClient.sendUserOperation({
487
+ calls: [{
488
+ to: smartAccountClient.account.address,
489
+ data: encodeFunctionData({
490
+ abi: safeOwnerManagerAbi,
491
+ functionName: 'addOwnerWithThreshold',
492
+ args: [sessionKeyAccount.address, BigInt(1)]
493
+ }),
494
+ value: BigInt(0)
495
+ }],
496
+ account: smartAccountClient.account
497
+ });
498
+ const receipt = await smartAccountClient.waitForUserOperationReceipt({
499
+ hash: tx
500
+ });
501
+ if (!receipt.success) {
502
+ throw new Error('Transaction to add account owner failed');
503
+ }
504
+ console.log('account owner added');
505
+ return bytesToHex(randomBytes(32));
506
+ }
507
+ // We create a dummy action so that we can execute a userOp immediately and create the session onchain,
508
+ // rather than having to pass along all the enable data to the end user app.
509
+ // In the future, if we enable attestations with the Rhinestone registry, we can remove this and instead
510
+ // call enableSessions on the smart sessions module from the smart account.
511
+ console.log('creating noOpActionPolicy');
512
+ const noOpActionPolicy = getUniversalActionPolicy({
513
+ paramRules: {
514
+ length: BigInt(1),
515
+ // @ts-expect-error - The Rhinestone SDK doesn't export the types we need here
516
+ rules: new Array(16).fill({
517
+ condition: BigInt(0),
518
+ // ParamCondition.EQUAL
519
+ isLimited: false,
520
+ offset: BigInt(0),
521
+ ref: toHex(toBytes('0x', {
522
+ size: 32
523
+ })),
524
+ usage: {
525
+ limit: BigInt(0),
526
+ used: BigInt(0)
527
+ }
528
+ })
529
+ },
530
+ valueLimitPerUse: BigInt(0)
531
+ });
532
+ console.log('noOpActionPolicy created');
533
+ const actions = [{
534
+ actionTarget: sessionKeyAccount.address,
535
+ actionTargetSelector: toFunctionSelector(getAbiItem({
536
+ abi: smartSessionsAbi,
537
+ name: 'revokeEnableSignature'
538
+ })),
539
+ actionPolicies: [noOpActionPolicy]
540
+ }];
541
+ console.log('getting space actions');
542
+ for (const space of spaces) {
543
+ actions.push(...getSpaceActions(space));
544
+ }
545
+ console.log('space actions created');
546
+ if (allowCreateSpace) {
547
+ const spaceFactoryAddress = SPACE_FACTORY_ADDRESS[chain.id.toString()];
548
+ actions.push({
549
+ actionTarget: spaceFactoryAddress,
550
+ actionTargetSelector: toFunctionSelector(getAbiItem({
551
+ abi: daoFactoryAbi,
552
+ name: 'createDao'
553
+ })),
554
+ actionPolicies: [getSudoPolicy()]
555
+ });
556
+ }
557
+ if (additionalActions) {
558
+ actions.push(...additionalActions);
559
+ }
560
+ console.log('actions created');
561
+ const session = {
562
+ sessionValidator: OWNABLE_VALIDATOR_ADDRESS,
563
+ sessionValidatorInitData: encodeValidationData({
564
+ threshold: 1,
565
+ owners: [sessionKeyAccount.address]
566
+ }),
567
+ salt: bytesToHex(randomBytes(32)),
568
+ userOpPolicies: [getSudoPolicy()],
569
+ erc7739Policies: {
570
+ allowedERC7739Content: [],
571
+ erc1271Policies: []
572
+ },
573
+ actions,
574
+ chainId: BigInt(smartAccountClient.chain.id),
575
+ permitERC4337Paymaster: true
576
+ };
577
+ const account = getAccount({
578
+ address: smartAccountClient.account.address,
579
+ type: 'safe'
580
+ });
581
+ console.log('session object');
582
+ // We use UNSAFE_ENABLE because we're not using Rhinestone's Registry
583
+ // contract to attest to the sessions we're creating.
584
+ // That's also why we set ignoreSecurityAttestations to true.
585
+ const sessionDetails = await getEnableSessionDetails({
586
+ // enableMode: SmartSessionMode.ENABLE,
587
+ sessions: [session],
588
+ account,
589
+ clients: [publicClient]
590
+ // ignoreSecurityAttestations: true,
591
+ });
592
+ console.log('signing session details');
593
+ // This will prompt the user to sign the message to enable the session
594
+ sessionDetails.enableSessionData.enableSession.permissionEnableSig = await owner.signMessage({
595
+ message: {
596
+ raw: sessionDetails.permissionEnableHash
597
+ },
598
+ account: owner.account.address
599
+ });
600
+ console.log('session details signed');
601
+ const smartSessions = getSmartSessionsValidator({});
602
+ const nonce = await getAccountNonce(publicClient, {
603
+ address: smartAccountClient.account.address,
604
+ entryPointAddress: entryPoint07Address,
605
+ key: encodeValidatorNonce({
606
+ account,
607
+ validator: smartSessions
608
+ })
609
+ });
610
+ console.log('nonce');
611
+ // This will be replaced with the actual signature below
612
+ sessionDetails.signature = getOwnableValidatorMockSignature({
613
+ threshold: 1
614
+ });
615
+ console.log('prep user op');
616
+ const userOperation = await smartAccountClient.prepareUserOperation({
617
+ account: smartAccountClient.account,
618
+ calls: [{
619
+ // We use the revokeEnableSignature with permissionId 0 function to create a noop action
620
+ to: sessionKeyAccount.address,
621
+ value: BigInt(0),
622
+ data: encodeFunctionData({
623
+ abi: smartSessionsAbi,
624
+ functionName: 'revokeEnableSignature',
625
+ args: [toHex(toBytes('0x', {
626
+ size: 32
627
+ }))]
628
+ })
629
+ }],
630
+ nonce,
631
+ signature: encodeSmartSessionSignature(sessionDetails)
632
+ });
633
+ console.log('user operation prepared');
634
+ const userOpHashToSign = getUserOperationHash({
635
+ chainId: chain.id,
636
+ entryPointAddress: entryPoint07Address,
637
+ entryPointVersion: '0.7',
638
+ userOperation
639
+ });
640
+ console.log('user op hash to sign');
641
+ sessionDetails.signature = await sessionKeyAccount.signMessage({
642
+ message: {
643
+ raw: userOpHashToSign
644
+ }
645
+ });
646
+ console.log('user op hash to sign signed');
647
+ userOperation.signature = encodeSmartSessionSignature(sessionDetails);
648
+ console.log('user op hash to sign encoded');
649
+ const userOpHash = await smartAccountClient.sendUserOperation(userOperation); // No idea why the type doesn't match
650
+ console.log('user op hash');
651
+ const receipt = await smartAccountClient.waitForUserOperationReceipt({
652
+ hash: userOpHash
653
+ });
654
+ if (!receipt.success) {
655
+ throw new Error('Transaction to create smart session failed');
656
+ }
657
+ return getPermissionId({
658
+ session
659
+ });
660
+ };
661
+ // This is the function that we use on the end user app to create a smart session client that can send transactions to the smart account.
662
+ // The session must have previously been created by the createSmartSession function.
663
+ // The client also includes a signMessage function that can be used to sign messages with the session key.
664
+ export const getSmartSessionClient = async ({
665
+ accountAddress,
666
+ chain = GEOGENESIS,
667
+ rpcUrl = DEFAULT_RPC_URL,
668
+ apiKey = DEFAULT_API_KEY,
669
+ sessionPrivateKey,
670
+ permissionId
671
+ }) => {
672
+ const sessionKeyAccount = privateKeyToAccount(sessionPrivateKey);
673
+ const smartAccountClient = await getSmartAccountWalletClient({
674
+ owner: sessionKeyAccount,
675
+ // Won't really be used (except in testnet), but we need to pass in an account
676
+ address: accountAddress,
677
+ chain,
678
+ rpcUrl,
679
+ apiKey
680
+ });
681
+ if (!smartAccountClient.account) {
682
+ throw new Error('Invalid smart account');
683
+ }
684
+ const smartSessions = getSmartSessionsValidator({});
685
+ const publicClient = createPublicClient({
686
+ transport: http(rpcUrl),
687
+ chain
688
+ });
689
+ return {
690
+ account: smartAccountClient.account,
691
+ chain,
692
+ sendUserOperation: async ({
693
+ calls
694
+ }) => {
695
+ if (!smartAccountClient.account) {
696
+ throw new Error('Invalid smart account');
697
+ }
698
+ if (chain.id === GEO_TESTNET.id) {
699
+ // We don't have the smart sessions module deployed on testnet yet, so we need to use the legacy smart account wallet client
700
+ // TODO: remove this once we have the smart sessions module deployed on testnet
701
+ return smartAccountClient.sendUserOperation({
702
+ calls: calls,
703
+ account: smartAccountClient.account
704
+ });
705
+ }
706
+ const account = getAccount({
707
+ address: smartAccountClient.account.address,
708
+ type: 'safe'
709
+ });
710
+ const sessionDetails = {
711
+ mode: SmartSessionMode.USE,
712
+ permissionId,
713
+ signature: getOwnableValidatorMockSignature({
714
+ threshold: 1
715
+ })
716
+ };
717
+ const nonce = await getAccountNonce(publicClient, {
718
+ address: smartAccountClient.account.address,
719
+ entryPointAddress: entryPoint07Address,
720
+ key: encodeValidatorNonce({
721
+ account,
722
+ validator: smartSessions
723
+ })
724
+ });
725
+ const userOperation = await smartAccountClient.prepareUserOperation({
726
+ account: smartAccountClient.account,
727
+ calls,
728
+ nonce,
729
+ signature: encodeSmartSessionSignature(sessionDetails)
730
+ });
731
+ const userOpHashToSign = getUserOperationHash({
732
+ chainId: chain.id,
733
+ entryPointAddress: entryPoint07Address,
734
+ entryPointVersion: '0.7',
735
+ userOperation
736
+ });
737
+ sessionDetails.signature = await sessionKeyAccount.signMessage({
738
+ message: {
739
+ raw: userOpHashToSign
740
+ }
741
+ });
742
+ userOperation.signature = encodeSmartSessionSignature(sessionDetails);
743
+ return smartAccountClient.sendUserOperation(userOperation);
744
+ },
745
+ signMessage: async ({
746
+ message
747
+ }) => {
748
+ return sessionKeyAccount.signMessage({
749
+ message
750
+ });
751
+ },
752
+ waitForUserOperationReceipt: async ({
753
+ hash
754
+ }) => {
755
+ return smartAccountClient.waitForUserOperationReceipt({
756
+ hash
757
+ });
758
+ }
759
+ };
760
+ };
761
+ //# sourceMappingURL=smart-account.js.map