near-safe 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
1
  export declare const USER_OP_IDENTIFIER: `0x${string}`;
2
2
  export declare const DEFAULT_SAFE_SALT_NONCE: string;
3
3
  export declare const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
4
+ export declare const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SENTINEL_OWNERS = exports.DEFAULT_SAFE_SALT_NONCE = exports.USER_OP_IDENTIFIER = void 0;
3
+ exports.DEFAULT_SETUP_RPC = exports.SENTINEL_OWNERS = exports.DEFAULT_SAFE_SALT_NONCE = exports.USER_OP_IDENTIFIER = void 0;
4
4
  const viem_1 = require("viem");
5
5
  const DOMAIN_SEPARATOR = "bitte/near-safe";
6
6
  // 0x62697474652f6e6561722d7361666500
@@ -8,3 +8,4 @@ exports.USER_OP_IDENTIFIER = (0, viem_1.toHex)(DOMAIN_SEPARATOR, { size: 16 });
8
8
  // 130811896738364114529934864114944206080
9
9
  exports.DEFAULT_SAFE_SALT_NONCE = BigInt(exports.USER_OP_IDENTIFIER).toString();
10
10
  exports.SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
11
+ exports.DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
@@ -4,13 +4,13 @@ import { Deployment, GasPrice, MetaTransaction, UnsignedUserOperation, UserOpera
4
4
  * All contracts used in account creation & execution
5
5
  */
6
6
  export declare class SafeContractSuite {
7
- dummyClient: PublicClient;
7
+ setupClient: PublicClient;
8
8
  singleton: Deployment;
9
9
  proxyFactory: Deployment;
10
10
  m4337: Deployment;
11
11
  moduleSetup: Deployment;
12
12
  entryPoint: Deployment;
13
- constructor();
13
+ constructor(rpcUrl?: string);
14
14
  addressForSetup(setup: Hex, saltNonce: string): Promise<Address>;
15
15
  getSetup(owners: string[]): Hex;
16
16
  addOwnerData(newOwner: Address): Hex;
@@ -9,8 +9,8 @@ const util_1 = require("../util");
9
9
  * All contracts used in account creation & execution
10
10
  */
11
11
  class SafeContractSuite {
12
- constructor() {
13
- this.dummyClient = (0, util_1.getClient)(11155111);
12
+ constructor(rpcUrl = constants_1.DEFAULT_SETUP_RPC) {
13
+ this.setupClient = (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(rpcUrl) });
14
14
  const deployments = deployments_1.SAFE_DEPLOYMENTS;
15
15
  this.singleton = deployments.singleton;
16
16
  this.proxyFactory = deployments.proxyFactory;
@@ -25,7 +25,7 @@ class SafeContractSuite {
25
25
  // abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
26
26
  // cf: https://github.com/safe-global/safe-smart-account/blob/499b17ad0191b575fcadc5cb5b8e3faeae5391ae/contracts/proxies/SafeProxyFactory.sol#L29
27
27
  const initCode = (0, viem_1.encodePacked)(["bytes", "uint256"], [
28
- (await this.dummyClient.readContract({
28
+ (await this.setupClient.readContract({
29
29
  address: this.proxyFactory.address,
30
30
  abi: this.proxyFactory.abi,
31
31
  functionName: "proxyCreationCode",
@@ -1,15 +1,12 @@
1
- import { NearConfig } from "near-api-js/lib/near";
2
- import { NearEthAdapter, SignRequestData, EncodedSignRequest } from "near-ca";
1
+ import { NearEthAdapter, SignRequestData, EncodedSignRequest, SetupConfig as MpcConfig } from "near-ca";
3
2
  import { Address, Hash, Hex } from "viem";
4
3
  import { SafeContractSuite } from "./lib/safe";
5
4
  import { EncodedTxData, MetaTransaction, SponsorshipPolicyData, UserOperation, UserOperationReceipt } from "./types";
6
5
  export interface NearSafeConfig {
7
- accountId: string;
8
- mpcContractId: string;
9
- nearConfig?: NearConfig;
10
- privateKey?: string;
6
+ mpc: MpcConfig;
11
7
  pimlicoKey: string;
12
8
  safeSaltNonce?: string;
9
+ setupRpc?: string;
13
10
  }
14
11
  export declare class NearSafe {
15
12
  readonly nearAdapter: NearEthAdapter;
@@ -17,11 +17,11 @@ class NearSafe {
17
17
  * @returns {Promise<NearSafe>} - A promise that resolves to a new `NearSafe` instance.
18
18
  */
19
19
  static async create(config) {
20
- const { pimlicoKey } = config;
20
+ const { pimlicoKey, setupRpc } = config;
21
21
  const safeSaltNonce = config.safeSaltNonce || constants_1.DEFAULT_SAFE_SALT_NONCE;
22
22
  // const nearAdapter = await mockAdapter();
23
- const nearAdapter = await (0, near_ca_1.setupAdapter)({ ...config });
24
- const safePack = new safe_1.SafeContractSuite();
23
+ const nearAdapter = await (0, near_ca_1.setupAdapter)(config.mpc);
24
+ const safePack = new safe_1.SafeContractSuite(setupRpc);
25
25
  const setup = safePack.getSetup([nearAdapter.address]);
26
26
  const safeAddress = await safePack.addressForSetup(setup, safeSaltNonce);
27
27
  console.log(`
package/dist/cjs/util.js CHANGED
@@ -13,6 +13,7 @@ exports.raceToFirstResolve = raceToFirstResolve;
13
13
  exports.assertUnique = assertUnique;
14
14
  const near_ca_1 = require("near-ca");
15
15
  const viem_1 = require("viem");
16
+ const constants_1 = require("./constants");
16
17
  exports.PLACEHOLDER_SIG = (0, viem_1.encodePacked)(["uint48", "uint48"], [0, 0]);
17
18
  const packGas = (hi, lo) => (0, viem_1.encodePacked)(["uint128", "uint128"], [BigInt(hi), BigInt(lo)]);
18
19
  exports.packGas = packGas;
@@ -36,6 +37,10 @@ async function isContract(address, chainId) {
36
37
  return (await getClient(chainId).getCode({ address })) !== undefined;
37
38
  }
38
39
  function getClient(chainId) {
40
+ // TODO(bh2smith)
41
+ if (chainId === 11155111) {
42
+ return (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(constants_1.DEFAULT_SETUP_RPC) });
43
+ }
39
44
  return near_ca_1.Network.fromChainId(chainId).client;
40
45
  }
41
46
  function metaTransactionsFromRequest(params) {
@@ -1,3 +1,4 @@
1
1
  export declare const USER_OP_IDENTIFIER: `0x${string}`;
2
2
  export declare const DEFAULT_SAFE_SALT_NONCE: string;
3
3
  export declare const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
4
+ export declare const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
@@ -5,3 +5,4 @@ export const USER_OP_IDENTIFIER = toHex(DOMAIN_SEPARATOR, { size: 16 });
5
5
  // 130811896738364114529934864114944206080
6
6
  export const DEFAULT_SAFE_SALT_NONCE = BigInt(USER_OP_IDENTIFIER).toString();
7
7
  export const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
8
+ export const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
@@ -4,13 +4,13 @@ import { Deployment, GasPrice, MetaTransaction, UnsignedUserOperation, UserOpera
4
4
  * All contracts used in account creation & execution
5
5
  */
6
6
  export declare class SafeContractSuite {
7
- dummyClient: PublicClient;
7
+ setupClient: PublicClient;
8
8
  singleton: Deployment;
9
9
  proxyFactory: Deployment;
10
10
  m4337: Deployment;
11
11
  moduleSetup: Deployment;
12
12
  entryPoint: Deployment;
13
- constructor();
13
+ constructor(rpcUrl?: string);
14
14
  addressForSetup(setup: Hex, saltNonce: string): Promise<Address>;
15
15
  getSetup(owners: string[]): Hex;
16
16
  addOwnerData(newOwner: Address): Hex;
@@ -1,20 +1,20 @@
1
- import { concat, encodeFunctionData, encodePacked, getAddress, getCreate2Address, keccak256, parseAbi, toHex, zeroAddress, } from "viem";
1
+ import { concat, createPublicClient, encodeFunctionData, encodePacked, getAddress, getCreate2Address, http, keccak256, parseAbi, toHex, zeroAddress, } from "viem";
2
2
  import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
3
- import { SENTINEL_OWNERS, USER_OP_IDENTIFIER } from "../constants";
3
+ import { DEFAULT_SETUP_RPC, SENTINEL_OWNERS, USER_OP_IDENTIFIER, } from "../constants";
4
4
  import { PLACEHOLDER_SIG, getClient, packGas, packPaymasterData, } from "../util";
5
5
  /**
6
6
  * All contracts used in account creation & execution
7
7
  */
8
8
  export class SafeContractSuite {
9
9
  // Used only for stateless contract reads.
10
- dummyClient;
10
+ setupClient;
11
11
  singleton;
12
12
  proxyFactory;
13
13
  m4337;
14
14
  moduleSetup;
15
15
  entryPoint;
16
- constructor() {
17
- this.dummyClient = getClient(11155111);
16
+ constructor(rpcUrl = DEFAULT_SETUP_RPC) {
17
+ this.setupClient = createPublicClient({ transport: http(rpcUrl) });
18
18
  const deployments = SAFE_DEPLOYMENTS;
19
19
  this.singleton = deployments.singleton;
20
20
  this.proxyFactory = deployments.proxyFactory;
@@ -29,7 +29,7 @@ export class SafeContractSuite {
29
29
  // abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
30
30
  // cf: https://github.com/safe-global/safe-smart-account/blob/499b17ad0191b575fcadc5cb5b8e3faeae5391ae/contracts/proxies/SafeProxyFactory.sol#L29
31
31
  const initCode = encodePacked(["bytes", "uint256"], [
32
- (await this.dummyClient.readContract({
32
+ (await this.setupClient.readContract({
33
33
  address: this.proxyFactory.address,
34
34
  abi: this.proxyFactory.abi,
35
35
  functionName: "proxyCreationCode",
@@ -1,15 +1,12 @@
1
- import { NearConfig } from "near-api-js/lib/near";
2
- import { NearEthAdapter, SignRequestData, EncodedSignRequest } from "near-ca";
1
+ import { NearEthAdapter, SignRequestData, EncodedSignRequest, SetupConfig as MpcConfig } from "near-ca";
3
2
  import { Address, Hash, Hex } from "viem";
4
3
  import { SafeContractSuite } from "./lib/safe";
5
4
  import { EncodedTxData, MetaTransaction, SponsorshipPolicyData, UserOperation, UserOperationReceipt } from "./types";
6
5
  export interface NearSafeConfig {
7
- accountId: string;
8
- mpcContractId: string;
9
- nearConfig?: NearConfig;
10
- privateKey?: string;
6
+ mpc: MpcConfig;
11
7
  pimlicoKey: string;
12
8
  safeSaltNonce?: string;
9
+ setupRpc?: string;
13
10
  }
14
11
  export declare class NearSafe {
15
12
  readonly nearAdapter: NearEthAdapter;
@@ -20,11 +20,11 @@ export class NearSafe {
20
20
  * @returns {Promise<NearSafe>} - A promise that resolves to a new `NearSafe` instance.
21
21
  */
22
22
  static async create(config) {
23
- const { pimlicoKey } = config;
23
+ const { pimlicoKey, setupRpc } = config;
24
24
  const safeSaltNonce = config.safeSaltNonce || DEFAULT_SAFE_SALT_NONCE;
25
25
  // const nearAdapter = await mockAdapter();
26
- const nearAdapter = await setupAdapter({ ...config });
27
- const safePack = new SafeContractSuite();
26
+ const nearAdapter = await setupAdapter(config.mpc);
27
+ const safePack = new SafeContractSuite(setupRpc);
28
28
  const setup = safePack.getSetup([nearAdapter.address]);
29
29
  const safeAddress = await safePack.addressForSetup(setup, safeSaltNonce);
30
30
  console.log(`
package/dist/esm/util.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getNetworkId, Network, signatureFromTxHash as sigFromHash, } from "near-ca";
2
- import { concatHex, encodePacked, toHex, isHex, parseTransaction, zeroAddress, toBytes, keccak256, serializeSignature, } from "viem";
2
+ import { concatHex, encodePacked, toHex, isHex, parseTransaction, zeroAddress, toBytes, keccak256, serializeSignature, createPublicClient, http, } from "viem";
3
+ import { DEFAULT_SETUP_RPC } from "./constants";
3
4
  export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);
4
5
  export const packGas = (hi, lo) => encodePacked(["uint128", "uint128"], [BigInt(hi), BigInt(lo)]);
5
6
  export function packSignature(signature, validFrom = 0, validTo = 0) {
@@ -22,6 +23,10 @@ export async function isContract(address, chainId) {
22
23
  return (await getClient(chainId).getCode({ address })) !== undefined;
23
24
  }
24
25
  export function getClient(chainId) {
26
+ // TODO(bh2smith)
27
+ if (chainId === 11155111) {
28
+ return createPublicClient({ transport: http(DEFAULT_SETUP_RPC) });
29
+ }
25
30
  return Network.fromChainId(chainId).client;
26
31
  }
27
32
  export function metaTransactionsFromRequest(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",