near-safe 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
- import { DecodedTxData, SafeEncodedSignRequest } from "../types";
1
+ import { EvmMessage } from "near-ca";
2
+ import { TransactionSerializable } from "viem";
3
+ import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "../types";
2
4
  /**
3
5
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
4
6
  *
@@ -6,3 +8,19 @@ import { DecodedTxData, SafeEncodedSignRequest } from "../types";
6
8
  * @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
7
9
  */
8
10
  export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
11
+ /**
12
+ * Represents different types of broadcastable messages
13
+ */
14
+ export type BroadcastTarget = {
15
+ type: "evm";
16
+ transaction: TransactionSerializable;
17
+ } | {
18
+ type: "bundler";
19
+ userOp: UserOperation;
20
+ };
21
+ /**
22
+ * Determines where and how an EVM message should be broadcast
23
+ * @param evmMessage - The message to be analyzed
24
+ * @returns Information about how to broadcast the message, or null if invalid
25
+ */
26
+ export declare function determineBroadcastTarget(evmMessage: EvmMessage): BroadcastTarget | null;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeTxData = decodeTxData;
4
+ exports.determineBroadcastTarget = determineBroadcastTarget;
4
5
  const near_ca_1 = require("near-ca");
6
+ const viem_1 = require("viem");
5
7
  const types_1 = require("../types");
6
8
  const util_1 = require("./util");
7
9
  /**
@@ -42,3 +44,40 @@ function decodeTxData({ evmMessage, chainId, }) {
42
44
  console.warn("Unrecognized txData format,", chainId, data);
43
45
  throw new Error(`decodeTxData: Invalid or unsupported message format ${data}`);
44
46
  }
47
+ /**
48
+ * Determines where and how an EVM message should be broadcast
49
+ * @param evmMessage - The message to be analyzed
50
+ * @returns Information about how to broadcast the message, or null if invalid
51
+ */
52
+ function determineBroadcastTarget(evmMessage) {
53
+ // Case 1: User Operation
54
+ if (typeof evmMessage === "string") {
55
+ try {
56
+ const parsed = (0, types_1.parseUserOperation)(evmMessage);
57
+ if (parsed) {
58
+ return {
59
+ type: "bundler",
60
+ userOp: parsed,
61
+ };
62
+ }
63
+ }
64
+ catch (error) {
65
+ console.warn("Failed to parse potential UserOperation:", error);
66
+ }
67
+ }
68
+ // Case 2: RLP Encoded EVM transaction
69
+ if ((0, near_ca_1.isRlpHex)(evmMessage)) {
70
+ return {
71
+ type: "evm",
72
+ transaction: (0, viem_1.parseTransaction)(evmMessage),
73
+ };
74
+ }
75
+ // Case 3: Serializable Transaction
76
+ if ((0, near_ca_1.isTransactionSerializable)(evmMessage)) {
77
+ return {
78
+ type: "evm",
79
+ transaction: evmMessage,
80
+ };
81
+ }
82
+ return null;
83
+ }
@@ -4,4 +4,4 @@ export * from "./util";
4
4
  export * from "./constants";
5
5
  export * from "./decode";
6
6
  export * from "./lib/safe-message";
7
- export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, } from "near-ca";
7
+ export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, isRlpHex, } from "near-ca";
package/dist/cjs/index.js CHANGED
@@ -14,16 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.mpcRequestRouter = exports.signatureFromTxHash = exports.signatureFromOutcome = exports.populateTx = exports.Network = void 0;
17
+ exports.isRlpHex = exports.mpcRequestRouter = exports.signatureFromTxHash = exports.signatureFromOutcome = exports.populateTx = exports.Network = void 0;
18
18
  __exportStar(require("./near-safe"), exports);
19
19
  __exportStar(require("./types"), exports);
20
20
  __exportStar(require("./util"), exports);
21
21
  __exportStar(require("./constants"), exports);
22
22
  __exportStar(require("./decode"), exports);
23
23
  __exportStar(require("./lib/safe-message"), exports);
24
+ // TODO: Improve re-exports...
24
25
  var near_ca_1 = require("near-ca");
25
26
  Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return near_ca_1.Network; } });
26
27
  Object.defineProperty(exports, "populateTx", { enumerable: true, get: function () { return near_ca_1.populateTx; } });
27
28
  Object.defineProperty(exports, "signatureFromOutcome", { enumerable: true, get: function () { return near_ca_1.signatureFromOutcome; } });
28
29
  Object.defineProperty(exports, "signatureFromTxHash", { enumerable: true, get: function () { return near_ca_1.signatureFromTxHash; } });
29
30
  Object.defineProperty(exports, "mpcRequestRouter", { enumerable: true, get: function () { return near_ca_1.requestRouter; } });
31
+ Object.defineProperty(exports, "isRlpHex", { enumerable: true, get: function () { return near_ca_1.isRlpHex; } });
@@ -1,4 +1,6 @@
1
- import { DecodedTxData, SafeEncodedSignRequest } from "../types";
1
+ import { EvmMessage } from "near-ca";
2
+ import { TransactionSerializable } from "viem";
3
+ import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "../types";
2
4
  /**
3
5
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
4
6
  *
@@ -6,3 +8,19 @@ import { DecodedTxData, SafeEncodedSignRequest } from "../types";
6
8
  * @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
7
9
  */
8
10
  export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
11
+ /**
12
+ * Represents different types of broadcastable messages
13
+ */
14
+ export type BroadcastTarget = {
15
+ type: "evm";
16
+ transaction: TransactionSerializable;
17
+ } | {
18
+ type: "bundler";
19
+ userOp: UserOperation;
20
+ };
21
+ /**
22
+ * Determines where and how an EVM message should be broadcast
23
+ * @param evmMessage - The message to be analyzed
24
+ * @returns Information about how to broadcast the message, or null if invalid
25
+ */
26
+ export declare function determineBroadcastTarget(evmMessage: EvmMessage): BroadcastTarget | null;
@@ -1,4 +1,5 @@
1
1
  import { isRlpHex, isTransactionSerializable } from "near-ca";
2
+ import { parseTransaction } from "viem";
2
3
  import { parseEip712TypedData, parseUserOperation, } from "../types";
3
4
  import { decodeRlpHex, decodeTransactionSerializable, decodeTypedData, decodeUserOperation, } from "./util";
4
5
  /**
@@ -39,3 +40,40 @@ export function decodeTxData({ evmMessage, chainId, }) {
39
40
  console.warn("Unrecognized txData format,", chainId, data);
40
41
  throw new Error(`decodeTxData: Invalid or unsupported message format ${data}`);
41
42
  }
43
+ /**
44
+ * Determines where and how an EVM message should be broadcast
45
+ * @param evmMessage - The message to be analyzed
46
+ * @returns Information about how to broadcast the message, or null if invalid
47
+ */
48
+ export function determineBroadcastTarget(evmMessage) {
49
+ // Case 1: User Operation
50
+ if (typeof evmMessage === "string") {
51
+ try {
52
+ const parsed = parseUserOperation(evmMessage);
53
+ if (parsed) {
54
+ return {
55
+ type: "bundler",
56
+ userOp: parsed,
57
+ };
58
+ }
59
+ }
60
+ catch (error) {
61
+ console.warn("Failed to parse potential UserOperation:", error);
62
+ }
63
+ }
64
+ // Case 2: RLP Encoded EVM transaction
65
+ if (isRlpHex(evmMessage)) {
66
+ return {
67
+ type: "evm",
68
+ transaction: parseTransaction(evmMessage),
69
+ };
70
+ }
71
+ // Case 3: Serializable Transaction
72
+ if (isTransactionSerializable(evmMessage)) {
73
+ return {
74
+ type: "evm",
75
+ transaction: evmMessage,
76
+ };
77
+ }
78
+ return null;
79
+ }
@@ -4,4 +4,4 @@ export * from "./util";
4
4
  export * from "./constants";
5
5
  export * from "./decode";
6
6
  export * from "./lib/safe-message";
7
- export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, } from "near-ca";
7
+ export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, isRlpHex, } from "near-ca";
package/dist/esm/index.js CHANGED
@@ -4,4 +4,5 @@ export * from "./util";
4
4
  export * from "./constants";
5
5
  export * from "./decode";
6
6
  export * from "./lib/safe-message";
7
- export { Network, populateTx, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, } from "near-ca";
7
+ // TODO: Improve re-exports...
8
+ export { Network, populateTx, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, isRlpHex, } from "near-ca";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
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,19 +43,19 @@
43
43
  "dependencies": {
44
44
  "@safe-global/safe-gateway-typescript-sdk": "^3.22.2",
45
45
  "near-api-js": "^5.0.1",
46
- "near-ca": "^0.7.2",
46
+ "near-ca": "^0.7.3",
47
47
  "semver": "^7.6.3",
48
- "viem": "^2.21.41"
48
+ "viem": "^2.21.45"
49
49
  },
50
50
  "devDependencies": {
51
- "@safe-global/safe-deployments": "^1.37.14",
51
+ "@safe-global/safe-deployments": "^1.37.16",
52
52
  "@safe-global/safe-modules-deployments": "^2.2.4",
53
53
  "@types/jest": "^29.5.14",
54
54
  "@types/node": "^22.9.0",
55
55
  "@types/semver": "^7.5.8",
56
56
  "@types/yargs": "^17.0.33",
57
- "@typescript-eslint/eslint-plugin": "^8.13.0",
58
- "@typescript-eslint/parser": "^8.13.0",
57
+ "@typescript-eslint/eslint-plugin": "^8.14.0",
58
+ "@typescript-eslint/parser": "^8.14.0",
59
59
  "dotenv": "^16.4.5",
60
60
  "eslint": "^9.14.0",
61
61
  "eslint-plugin-import": "^2.31.0",