@maci-protocol/coordinator 0.0.0-ci.f9da2fc → 0.0.0-ci.fc91dc9

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 (88) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +13 -6
  3. package/build/hardhat.config.cjs +3 -0
  4. package/build/hardhat.config.cjs.map +1 -1
  5. package/build/hardhat.config.d.cts +3 -0
  6. package/build/scripts/generateMaciKeyPair.js +2 -2
  7. package/build/scripts/generateMaciKeyPair.js.map +1 -1
  8. package/build/tests/constants.d.ts +0 -1
  9. package/build/tests/constants.d.ts.map +1 -1
  10. package/build/tests/constants.js +0 -1
  11. package/build/tests/constants.js.map +1 -1
  12. package/build/tests/e2e.aa.test.js +17 -14
  13. package/build/tests/e2e.aa.test.js.map +1 -1
  14. package/build/tests/e2e.deploy.test.js +121 -73
  15. package/build/tests/e2e.deploy.test.js.map +1 -1
  16. package/build/tests/utils.d.ts +6 -0
  17. package/build/tests/utils.d.ts.map +1 -1
  18. package/build/tests/utils.js +12 -3
  19. package/build/tests/utils.js.map +1 -1
  20. package/build/ts/common/__tests__/common.test.js +2 -6
  21. package/build/ts/common/__tests__/common.test.js.map +1 -1
  22. package/build/ts/common/accountAbstraction.d.ts +2 -19
  23. package/build/ts/common/accountAbstraction.d.ts.map +1 -1
  24. package/build/ts/common/accountAbstraction.js +14 -43
  25. package/build/ts/common/accountAbstraction.js.map +1 -1
  26. package/build/ts/common/chain.d.ts +16 -0
  27. package/build/ts/common/chain.d.ts.map +1 -0
  28. package/build/ts/common/chain.js +35 -0
  29. package/build/ts/common/chain.js.map +1 -0
  30. package/build/ts/common/errors.d.ts +17 -18
  31. package/build/ts/common/errors.d.ts.map +1 -1
  32. package/build/ts/common/errors.js +17 -18
  33. package/build/ts/common/errors.js.map +1 -1
  34. package/build/ts/common/index.d.ts +2 -0
  35. package/build/ts/common/index.d.ts.map +1 -1
  36. package/build/ts/common/index.js +2 -0
  37. package/build/ts/common/index.js.map +1 -1
  38. package/build/ts/common/types.d.ts +2 -3
  39. package/build/ts/common/types.d.ts.map +1 -1
  40. package/build/ts/deployer/__tests__/deployer.service.test.js +30 -289
  41. package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -1
  42. package/build/ts/deployer/__tests__/utils.d.ts +30 -1
  43. package/build/ts/deployer/__tests__/utils.d.ts.map +1 -1
  44. package/build/ts/deployer/__tests__/utils.js +42 -7
  45. package/build/ts/deployer/__tests__/utils.js.map +1 -1
  46. package/build/ts/deployer/deployer.service.d.ts +17 -53
  47. package/build/ts/deployer/deployer.service.d.ts.map +1 -1
  48. package/build/ts/deployer/deployer.service.js +164 -451
  49. package/build/ts/deployer/deployer.service.js.map +1 -1
  50. package/build/ts/deployer/dto.d.ts +4 -4
  51. package/build/ts/deployer/dto.d.ts.map +1 -1
  52. package/build/ts/deployer/dto.js +9 -1
  53. package/build/ts/deployer/dto.js.map +1 -1
  54. package/build/ts/deployer/types.d.ts +57 -19
  55. package/build/ts/deployer/types.d.ts.map +1 -1
  56. package/build/ts/proof/__tests__/proof.controller.test.js +3 -1
  57. package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -1
  58. package/build/ts/proof/__tests__/proof.gateway.test.js +4 -1
  59. package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -1
  60. package/build/ts/proof/__tests__/proof.service.test.js +9 -7
  61. package/build/ts/proof/__tests__/proof.service.test.js.map +1 -1
  62. package/build/ts/proof/dto.d.ts +10 -9
  63. package/build/ts/proof/dto.d.ts.map +1 -1
  64. package/build/ts/proof/dto.js +42 -21
  65. package/build/ts/proof/dto.js.map +1 -1
  66. package/build/ts/proof/proof.controller.d.ts +3 -2
  67. package/build/ts/proof/proof.controller.d.ts.map +1 -1
  68. package/build/ts/proof/proof.controller.js.map +1 -1
  69. package/build/ts/proof/proof.service.d.ts +3 -3
  70. package/build/ts/proof/proof.service.d.ts.map +1 -1
  71. package/build/ts/proof/proof.service.js +38 -119
  72. package/build/ts/proof/proof.service.js.map +1 -1
  73. package/build/ts/proof/types.d.ts +16 -8
  74. package/build/ts/proof/types.d.ts.map +1 -1
  75. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts +53 -0
  76. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts.map +1 -0
  77. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js +105 -0
  78. package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js.map +1 -0
  79. package/build/ts/sessionKeys/sessionKeys.service.d.ts +13 -2
  80. package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -1
  81. package/build/ts/sessionKeys/sessionKeys.service.js +22 -4
  82. package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -1
  83. package/build/tsconfig.build.tsbuildinfo +1 -1
  84. package/package.json +24 -23
  85. package/build/ts/deployer/utils.d.ts +0 -8
  86. package/build/ts/deployer/utils.d.ts.map +0 -1
  87. package/build/ts/deployer/utils.js +0 -9
  88. package/build/ts/deployer/utils.js.map +0 -1
@@ -0,0 +1,105 @@
1
+ import { safeCreateCallAddress } from "@zerodev/sdk/constants";
2
+ import { encodeFunctionData, parseAbi } from "viem";
3
+ import { EventEmitter } from "events";
4
+ export const SafeCreateCallAbi = parseAbi([
5
+ "function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract)",
6
+ "function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract)",
7
+ ]);
8
+ export const encodeSafeCreateCall = (args) => encodeFunctionData({
9
+ abi: SafeCreateCallAbi,
10
+ functionName: "performCreate",
11
+ args,
12
+ });
13
+ export class KernelEIP1193Provider extends EventEmitter {
14
+ kernelClient;
15
+ constructor(kernelClient) {
16
+ super();
17
+ this.kernelClient = kernelClient;
18
+ }
19
+ async request({ method, params = [] }) {
20
+ switch (method) {
21
+ case "eth_requestAccounts":
22
+ return this.handleEthRequestAccounts();
23
+ case "eth_accounts":
24
+ return this.handleEthAccounts();
25
+ case "eth_sendTransaction":
26
+ return this.handleEthSendTransaction(params);
27
+ case "eth_sign":
28
+ return this.handleEthSign(params);
29
+ case "personal_sign":
30
+ return this.handlePersonalSign(params);
31
+ case "eth_signTypedData":
32
+ case "eth_signTypedData_v4":
33
+ return this.handleEthSignTypedDataV4(params);
34
+ default:
35
+ return this.kernelClient.transport.request({ method, params });
36
+ }
37
+ }
38
+ handleEthRequestAccounts() {
39
+ if (!this.kernelClient.account) {
40
+ return [];
41
+ }
42
+ return [this.kernelClient.account.address];
43
+ }
44
+ handleEthAccounts() {
45
+ if (!this.kernelClient.account) {
46
+ return [];
47
+ }
48
+ return [this.kernelClient.account.address];
49
+ }
50
+ async handleEthSendTransaction(params) {
51
+ const [tx] = params;
52
+ if (!("to" in tx) && tx.data) {
53
+ // contract deployment
54
+ tx.data = encodeSafeCreateCall([0n, tx.data]);
55
+ tx.to = safeCreateCallAddress;
56
+ return this.kernelClient.sendTransaction(tx);
57
+ }
58
+ // eth transaction (function call or eth transfer)
59
+ return this.kernelClient.sendTransaction(tx);
60
+ }
61
+ async handleEthSign(params) {
62
+ if (!this.kernelClient.account) {
63
+ throw new Error("account not connected!");
64
+ }
65
+ const [address, message] = params;
66
+ if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
67
+ throw new Error("cannot sign for address that is not the current account");
68
+ }
69
+ return this.kernelClient.signMessage({
70
+ message,
71
+ account: this.kernelClient.account,
72
+ });
73
+ }
74
+ async handlePersonalSign(params) {
75
+ if (!this.kernelClient.account) {
76
+ throw new Error("account not connected!");
77
+ }
78
+ const [message, address] = params;
79
+ if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
80
+ throw new Error("cannot sign for address that is not the current account");
81
+ }
82
+ return this.kernelClient.signMessage({
83
+ message,
84
+ account: this.kernelClient.account,
85
+ });
86
+ }
87
+ async handleEthSignTypedDataV4(params) {
88
+ if (!this.kernelClient.account) {
89
+ throw new Error("account not connected!");
90
+ }
91
+ const [address, typedDataJSON] = params;
92
+ const typedData = JSON.parse(typedDataJSON);
93
+ if (address.toLowerCase() !== this.kernelClient.account.address.toLowerCase()) {
94
+ throw new Error("cannot sign for address that is not the current account");
95
+ }
96
+ return this.kernelClient.signTypedData({
97
+ account: this.kernelClient.account,
98
+ domain: typedData.domain,
99
+ types: typedData.types,
100
+ message: typedData.message,
101
+ primaryType: typedData.primaryType,
102
+ });
103
+ }
104
+ }
105
+ //# sourceMappingURL=KernelEIP1193Provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KernelEIP1193Provider.js","sourceRoot":"","sources":["../../../../ts/sessionKeys/provider/KernelEIP1193Provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACxC,yGAAyG;IACzG,wHAAwH;CACzH,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAmC,EAAO,EAAE,CAC/E,kBAAkB,CAAC;IACjB,GAAG,EAAE,iBAAiB;IACtB,YAAY,EAAE,eAAe;IAC7B,IAAI;CACL,CAAC,CAAC;AAEL,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAC7C,YAAY,CAAsB;IAE1C,YAAY,YAAiC;QAC3C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,EAAqB;QACtD,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,qBAAqB;gBACxB,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACzC,KAAK,cAAc;gBACjB,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAClC,KA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,MAAwB;QAC7D,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC;QAExC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAKzC,CAAC;QAEF,IAAI,OAAO,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;YACrC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;YAClC,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,WAAW,EAAE,SAAS,CAAC,WAAW;SACnC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,4 +1,5 @@
1
- import { JsonRpcSigner } from "ethers";
1
+ import { Signer } from "ethers";
2
+ import type { AASigner } from "@maci-protocol/contracts";
2
3
  import type { Hex } from "viem";
3
4
  import { ESupportedNetworks, KernelClientType } from "../common";
4
5
  import { FileService } from "../file/file.service";
@@ -39,7 +40,17 @@ export declare class SessionKeysService {
39
40
  * @param kernelClient - kernel client
40
41
  * @returns signer
41
42
  */
42
- getKernelClientSigner(kernelClient: KernelClientType): Promise<JsonRpcSigner>;
43
+ getKernelClientSigner(kernelClient: KernelClientType): Promise<AASigner>;
44
+ /**
45
+ * Get a signer that would execute all the contract interactions in the coordinator service.
46
+ * There are particular cases where the AA signer does not work so we default to the normal signer.
47
+ * (e.g. `deployPoll`)
48
+ * @param chain - the chain to use
49
+ * @param sessionKeyAddress - the address of the session key. Defaults to normal signer if not provided
50
+ * @param approval - the approval string. Defaults to normal signer if not provided
51
+ * @returns a signer
52
+ */
53
+ getCoordinatorSigner(chain: ESupportedNetworks, sessionKeyAddress?: Hex, approval?: string): Promise<AASigner | Signer>;
43
54
  /**
44
55
  * Deactivate a session key
45
56
  *
@@ -1 +1 @@
1
- {"version":3,"file":"sessionKeys.service.d.ts","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGxD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAc,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,qBACa,kBAAkB;IAWjB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAVxC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;OAIG;gBAC0B,WAAW,EAAE,WAAW;IAIrD;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAiB9D;;;;;;;OAOG;IACG,4BAA4B,CAChC,iBAAiB,EAAE,GAAG,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,gBAAgB,CAAC;IAkB5B;;;;;OAKG;IACG,qBAAqB,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAOnF;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,GAAG,GAAG,IAAI;CAGnD"}
1
+ {"version":3,"file":"sessionKeys.service.d.ts","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAc,kBAAkB,EAAa,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,qBACa,kBAAkB;IAWjB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAVxC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;OAIG;gBAC0B,WAAW,EAAE,WAAW;IAIrD;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAiB9D;;;;;;;OAOG;IACG,4BAA4B,CAChC,iBAAiB,EAAE,GAAG,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,gBAAgB,CAAC;IAkB5B;;;;;OAKG;IACG,qBAAqB,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU9E;;;;;;;;OAQG;IACG,oBAAoB,CACxB,KAAK,EAAE,kBAAkB,EACzB,iBAAiB,CAAC,EAAE,GAAG,EACvB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;IAS7B;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,GAAG,GAAG,IAAI;CAGnD"}
@@ -10,12 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var SessionKeysService_1;
11
11
  import { Injectable, Logger } from "@nestjs/common";
12
12
  import { toECDSASigner } from "@zerodev/permissions/signers";
13
- import { KernelEIP1193Provider } from "@zerodev/sdk";
14
13
  import { BrowserProvider } from "ethers";
15
14
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
16
- import { ErrorCodes } from "../common";
15
+ import { ErrorCodes, getSigner } from "../common";
17
16
  import { getKernelClient } from "../common/accountAbstraction";
18
17
  import { FileService } from "../file/file.service";
18
+ import { KernelEIP1193Provider } from "./provider/KernelEIP1193Provider";
19
19
  /**
20
20
  * SessionKeysService is responsible for generating and managing session keys.
21
21
  */
@@ -71,7 +71,7 @@ let SessionKeysService = SessionKeysService_1 = class SessionKeysService {
71
71
  return kernelClient;
72
72
  }
73
73
  catch (error) {
74
- this.logger.error(`Error: ${ErrorCodes.INVALID_APPROVAL}`, error);
74
+ this.logger.error("Error:", error);
75
75
  throw new Error(ErrorCodes.INVALID_APPROVAL.toString());
76
76
  }
77
77
  }
@@ -85,7 +85,25 @@ let SessionKeysService = SessionKeysService_1 = class SessionKeysService {
85
85
  const kernelProvider = new KernelEIP1193Provider(kernelClient);
86
86
  const ethersProvider = new BrowserProvider(kernelProvider);
87
87
  const signer = await ethersProvider.getSigner();
88
- return signer;
88
+ const aaSigner = signer;
89
+ aaSigner.isAA = true;
90
+ return aaSigner;
91
+ }
92
+ /**
93
+ * Get a signer that would execute all the contract interactions in the coordinator service.
94
+ * There are particular cases where the AA signer does not work so we default to the normal signer.
95
+ * (e.g. `deployPoll`)
96
+ * @param chain - the chain to use
97
+ * @param sessionKeyAddress - the address of the session key. Defaults to normal signer if not provided
98
+ * @param approval - the approval string. Defaults to normal signer if not provided
99
+ * @returns a signer
100
+ */
101
+ async getCoordinatorSigner(chain, sessionKeyAddress, approval) {
102
+ if (sessionKeyAddress && approval) {
103
+ const kernelClient = await this.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
104
+ return this.getKernelClientSigner(kernelClient);
105
+ }
106
+ return getSigner(chain);
89
107
  }
90
108
  /**
91
109
  * Deactivate a session key
@@ -1 +1 @@
1
- {"version":3,"file":"sessionKeys.service.js","sourceRoot":"","sources":["../../../ts/sessionKeys/sessionKeys.service.ts"],"names":[],"mappings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