near-safe 0.0.2 → 0.0.4

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.
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import { GasPrice, PaymasterData, UnsignedUserOperation, UserOperation } from "../types";
2
+ import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
3
3
  import { MetaTransaction } from "ethers-multisend";
4
4
  /**
5
5
  * All contracts used in account creation & execution
@@ -15,7 +15,7 @@ export declare class ContractSuite {
15
15
  static init(provider: ethers.JsonRpcProvider): Promise<ContractSuite>;
16
16
  addressForSetup(setup: ethers.BytesLike, saltNonce?: string): Promise<string>;
17
17
  getSetup(owners: string[]): Promise<string>;
18
- getOpHash(unsignedUserOp: UserOperation, paymasterData: PaymasterData): Promise<string>;
18
+ getOpHash(unsignedUserOp: UserOperation): Promise<string>;
19
19
  factoryDataForSetup(safeNotDeployed: boolean, setup: string, safeSaltNonce: string): {
20
20
  factory?: ethers.AddressLike;
21
21
  factoryData?: string;
@@ -58,7 +58,9 @@ class ContractSuite {
58
58
  ]);
59
59
  return setup;
60
60
  }
61
- async getOpHash(unsignedUserOp, paymasterData) {
61
+ async getOpHash(unsignedUserOp
62
+ // paymasterData: PaymasterData
63
+ ) {
62
64
  return this.m4337.getOperationHash({
63
65
  ...unsignedUserOp,
64
66
  initCode: unsignedUserOp.factory
@@ -66,7 +68,7 @@ class ContractSuite {
66
68
  : "0x",
67
69
  accountGasLimits: (0, util_1.packGas)(unsignedUserOp.verificationGasLimit, unsignedUserOp.callGasLimit),
68
70
  gasFees: (0, util_1.packGas)(unsignedUserOp.maxPriorityFeePerGas, unsignedUserOp.maxFeePerGas),
69
- paymasterAndData: (0, util_1.packPaymasterData)(paymasterData),
71
+ paymasterAndData: (0, util_1.packPaymasterData)(unsignedUserOp),
70
72
  signature: util_1.PLACEHOLDER_SIG,
71
73
  });
72
74
  }
@@ -1,7 +1,7 @@
1
1
  import { ethers } from "ethers";
2
- import { NearEthAdapter } from "near-ca";
2
+ import { NearEthAdapter, NearEthTxData } from "near-ca";
3
3
  import { Erc4337Bundler } from "./lib/bundler";
4
- import { UserOperation, UserOperationReceipt, UserOptions } from "./types";
4
+ import { UserOperation, UserOperationReceipt } from "./types";
5
5
  import { MetaTransaction } from "ethers-multisend";
6
6
  import { ContractSuite } from "./lib/safe";
7
7
  import { Account } from "near-api-js";
@@ -27,12 +27,11 @@ export declare class TransactionManager {
27
27
  getSafeBalance(): Promise<bigint>;
28
28
  buildTransaction(args: {
29
29
  transactions: MetaTransaction[];
30
- options: UserOptions;
31
- }): Promise<{
32
- safeOpHash: string;
33
- unsignedUserOp: UserOperation;
34
- }>;
30
+ usePaymaster: boolean;
31
+ }): Promise<UserOperation>;
35
32
  signTransaction(safeOpHash: string): Promise<string>;
33
+ opHash(userOp: UserOperation): Promise<string>;
34
+ encodeSignatureRequest(unsignedUserOp: UserOperation): Promise<NearEthTxData>;
36
35
  executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
37
36
  addOwnerTx(address: string): MetaTransaction;
38
37
  safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
@@ -45,7 +45,7 @@ class TransactionManager {
45
45
  return await this.provider.getBalance(this.safeAddress);
46
46
  }
47
47
  async buildTransaction(args) {
48
- const { transactions, options } = args;
48
+ const { transactions, usePaymaster } = args;
49
49
  const gasFees = (await this.bundler.getGasPrice()).fast;
50
50
  // const gasFees = await this.provider.getFeeData();
51
51
  // Build Singular MetaTransaction for Multisend from transaction list.
@@ -54,18 +54,29 @@ class TransactionManager {
54
54
  }
55
55
  const tx = transactions.length > 1 ? (0, ethers_multisend_1.encodeMulti)(transactions) : transactions[0];
56
56
  const rawUserOp = await this.safePack.buildUserOp(tx, this.safeAddress, gasFees, this.setup, this.safeNotDeployed, this.safeSaltNonce);
57
- const paymasterData = await this.bundler.getPaymasterData(rawUserOp, options.usePaymaster, this.safeNotDeployed);
57
+ const paymasterData = await this.bundler.getPaymasterData(rawUserOp, usePaymaster, this.safeNotDeployed);
58
58
  const unsignedUserOp = { ...rawUserOp, ...paymasterData };
59
- const safeOpHash = await this.safePack.getOpHash(unsignedUserOp, paymasterData);
60
- return {
61
- safeOpHash,
62
- unsignedUserOp,
63
- };
59
+ return unsignedUserOp;
64
60
  }
65
61
  async signTransaction(safeOpHash) {
66
62
  const signature = await (0, near_1.getNearSignature)(this.nearAdapter, safeOpHash);
67
63
  return (0, util_1.packSignature)(signature);
68
64
  }
65
+ async opHash(userOp) {
66
+ return this.safePack.getOpHash(userOp);
67
+ }
68
+ async encodeSignatureRequest(unsignedUserOp) {
69
+ const safeOpHash = (await this.opHash(unsignedUserOp));
70
+ const txData = this.nearAdapter.encodeSignRequest({
71
+ method: "hash",
72
+ chainId: 0,
73
+ params: safeOpHash,
74
+ });
75
+ return {
76
+ ...txData,
77
+ evmMessage: unsignedUserOp,
78
+ };
79
+ }
69
80
  async executeTransaction(userOp) {
70
81
  const userOpHash = await this.bundler.sendUserOperation(userOp);
71
82
  console.log("UserOp Hash", userOpHash);
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import { GasPrice, PaymasterData, UnsignedUserOperation, UserOperation } from "../types";
2
+ import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
3
3
  import { MetaTransaction } from "ethers-multisend";
4
4
  /**
5
5
  * All contracts used in account creation & execution
@@ -15,7 +15,7 @@ export declare class ContractSuite {
15
15
  static init(provider: ethers.JsonRpcProvider): Promise<ContractSuite>;
16
16
  addressForSetup(setup: ethers.BytesLike, saltNonce?: string): Promise<string>;
17
17
  getSetup(owners: string[]): Promise<string>;
18
- getOpHash(unsignedUserOp: UserOperation, paymasterData: PaymasterData): Promise<string>;
18
+ getOpHash(unsignedUserOp: UserOperation): Promise<string>;
19
19
  factoryDataForSetup(safeNotDeployed: boolean, setup: string, safeSaltNonce: string): {
20
20
  factory?: ethers.AddressLike;
21
21
  factoryData?: string;
@@ -61,7 +61,9 @@ export class ContractSuite {
61
61
  ]);
62
62
  return setup;
63
63
  }
64
- async getOpHash(unsignedUserOp, paymasterData) {
64
+ async getOpHash(unsignedUserOp
65
+ // paymasterData: PaymasterData
66
+ ) {
65
67
  return this.m4337.getOperationHash({
66
68
  ...unsignedUserOp,
67
69
  initCode: unsignedUserOp.factory
@@ -69,7 +71,7 @@ export class ContractSuite {
69
71
  : "0x",
70
72
  accountGasLimits: packGas(unsignedUserOp.verificationGasLimit, unsignedUserOp.callGasLimit),
71
73
  gasFees: packGas(unsignedUserOp.maxPriorityFeePerGas, unsignedUserOp.maxFeePerGas),
72
- paymasterAndData: packPaymasterData(paymasterData),
74
+ paymasterAndData: packPaymasterData(unsignedUserOp),
73
75
  signature: PLACEHOLDER_SIG,
74
76
  });
75
77
  }
@@ -1,7 +1,7 @@
1
1
  import { ethers } from "ethers";
2
- import { NearEthAdapter } from "near-ca";
2
+ import { NearEthAdapter, NearEthTxData } from "near-ca";
3
3
  import { Erc4337Bundler } from "./lib/bundler";
4
- import { UserOperation, UserOperationReceipt, UserOptions } from "./types";
4
+ import { UserOperation, UserOperationReceipt } from "./types";
5
5
  import { MetaTransaction } from "ethers-multisend";
6
6
  import { ContractSuite } from "./lib/safe";
7
7
  import { Account } from "near-api-js";
@@ -27,12 +27,11 @@ export declare class TransactionManager {
27
27
  getSafeBalance(): Promise<bigint>;
28
28
  buildTransaction(args: {
29
29
  transactions: MetaTransaction[];
30
- options: UserOptions;
31
- }): Promise<{
32
- safeOpHash: string;
33
- unsignedUserOp: UserOperation;
34
- }>;
30
+ usePaymaster: boolean;
31
+ }): Promise<UserOperation>;
35
32
  signTransaction(safeOpHash: string): Promise<string>;
33
+ opHash(userOp: UserOperation): Promise<string>;
34
+ encodeSignatureRequest(unsignedUserOp: UserOperation): Promise<NearEthTxData>;
36
35
  executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
37
36
  addOwnerTx(address: string): MetaTransaction;
38
37
  safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
@@ -50,7 +50,7 @@ export class TransactionManager {
50
50
  return await this.provider.getBalance(this.safeAddress);
51
51
  }
52
52
  async buildTransaction(args) {
53
- const { transactions, options } = args;
53
+ const { transactions, usePaymaster } = args;
54
54
  const gasFees = (await this.bundler.getGasPrice()).fast;
55
55
  // const gasFees = await this.provider.getFeeData();
56
56
  // Build Singular MetaTransaction for Multisend from transaction list.
@@ -59,18 +59,29 @@ export class TransactionManager {
59
59
  }
60
60
  const tx = transactions.length > 1 ? encodeMulti(transactions) : transactions[0];
61
61
  const rawUserOp = await this.safePack.buildUserOp(tx, this.safeAddress, gasFees, this.setup, this.safeNotDeployed, this.safeSaltNonce);
62
- const paymasterData = await this.bundler.getPaymasterData(rawUserOp, options.usePaymaster, this.safeNotDeployed);
62
+ const paymasterData = await this.bundler.getPaymasterData(rawUserOp, usePaymaster, this.safeNotDeployed);
63
63
  const unsignedUserOp = { ...rawUserOp, ...paymasterData };
64
- const safeOpHash = await this.safePack.getOpHash(unsignedUserOp, paymasterData);
65
- return {
66
- safeOpHash,
67
- unsignedUserOp,
68
- };
64
+ return unsignedUserOp;
69
65
  }
70
66
  async signTransaction(safeOpHash) {
71
67
  const signature = await getNearSignature(this.nearAdapter, safeOpHash);
72
68
  return packSignature(signature);
73
69
  }
70
+ async opHash(userOp) {
71
+ return this.safePack.getOpHash(userOp);
72
+ }
73
+ async encodeSignatureRequest(unsignedUserOp) {
74
+ const safeOpHash = (await this.opHash(unsignedUserOp));
75
+ const txData = this.nearAdapter.encodeSignRequest({
76
+ method: "hash",
77
+ chainId: 0,
78
+ params: safeOpHash,
79
+ });
80
+ return {
81
+ ...txData,
82
+ evmMessage: unsignedUserOp,
83
+ };
84
+ }
74
85
  async executeTransaction(userOp) {
75
86
  const userOpHash = await this.bundler.sendUserOperation(userOp);
76
87
  console.log("UserOp Hash", userOpHash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",
@@ -43,8 +43,8 @@
43
43
  "@safe-global/safe-modules-deployments": "^2.2.0",
44
44
  "ethers": "^6.13.1",
45
45
  "ethers-multisend": "^3.1.0",
46
- "near-api-js": "^4.0.3",
47
- "near-ca": "^0.3.1"
46
+ "near-api-js": "^5.0.0",
47
+ "near-ca": "^0.5.2"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^22.3.0",