near-safe 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "./types";
7
7
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
8
8
  * @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
9
9
  */
10
- export declare function decodeTxData({ evmMessage, chainId, }: SafeEncodedSignRequest): DecodedTxData;
10
+ export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
11
11
  export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
12
12
  export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
13
13
  export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
@@ -43,8 +43,17 @@ function decodeTxData({ evmMessage, chainId, }) {
43
43
  };
44
44
  }
45
45
  else {
46
- const message = error instanceof Error ? error.message : String(error);
47
- throw new Error(`decodeTxData: Unexpected error - ${message}`);
46
+ // TODO: This shouldn't happen anymore and can probably be reverted.
47
+ // We keep it here now, because near-ca might not have adapted its router.
48
+ console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
49
+ try {
50
+ const typedData = JSON.parse(data);
51
+ return decodeTypedData(chainId, typedData);
52
+ }
53
+ catch (error) {
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ throw new Error(`decodeTxData: Unexpected error - ${message}`);
56
+ }
48
57
  }
49
58
  }
50
59
  }
@@ -2,4 +2,5 @@ export * from "./near-safe";
2
2
  export * from "./types";
3
3
  export * from "./util";
4
4
  export * from "./constants";
5
- export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, } from "near-ca";
5
+ export * from "./decode";
6
+ export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, } from "near-ca";
package/dist/cjs/index.js CHANGED
@@ -14,13 +14,15 @@ 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.signatureFromTxHash = exports.signatureFromOutcome = exports.populateTx = exports.Network = void 0;
17
+ 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
+ __exportStar(require("./decode"), exports);
22
23
  var near_ca_1 = require("near-ca");
23
24
  Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return near_ca_1.Network; } });
24
25
  Object.defineProperty(exports, "populateTx", { enumerable: true, get: function () { return near_ca_1.populateTx; } });
25
26
  Object.defineProperty(exports, "signatureFromOutcome", { enumerable: true, get: function () { return near_ca_1.signatureFromOutcome; } });
26
27
  Object.defineProperty(exports, "signatureFromTxHash", { enumerable: true, get: function () { return near_ca_1.signatureFromTxHash; } });
28
+ Object.defineProperty(exports, "mpcRequestRouter", { enumerable: true, get: function () { return near_ca_1.requestRouter; } });
@@ -283,6 +283,7 @@ class NearSafe {
283
283
  (0, util_1.assertUnique)(fromAddresses);
284
284
  // Early return with eoaEncoding if `from` is not the Safe
285
285
  if (!this.encodeForSafe(fromAddresses[0])) {
286
+ // TODO: near-ca needs to update this for typed data like we did.
286
287
  return (0, near_ca_1.requestRouter)({ method, chainId, params });
287
288
  }
288
289
  const safeInfo = {
@@ -295,7 +296,14 @@ class NearSafe {
295
296
  // We should either confirm they agree or ignore one of the two.
296
297
  switch (method) {
297
298
  case "eth_signTypedData":
298
- case "eth_signTypedData_v4":
299
+ case "eth_signTypedData_v4": {
300
+ const [_, typedDataString] = params;
301
+ const message = (0, safe_message_1.decodeSafeMessage)(JSON.parse(typedDataString), safeInfo);
302
+ return {
303
+ evmMessage: JSON.parse(typedDataString),
304
+ hashToSign: message.safeMessageHash,
305
+ };
306
+ }
299
307
  case "eth_sign": {
300
308
  const [_, messageOrData] = params;
301
309
  const message = (0, safe_message_1.decodeSafeMessage)(messageOrData, safeInfo);
@@ -7,7 +7,7 @@ import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "./types";
7
7
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
8
8
  * @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
9
9
  */
10
- export declare function decodeTxData({ evmMessage, chainId, }: SafeEncodedSignRequest): DecodedTxData;
10
+ export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
11
11
  export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
12
12
  export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
13
13
  export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
@@ -36,8 +36,17 @@ export function decodeTxData({ evmMessage, chainId, }) {
36
36
  };
37
37
  }
38
38
  else {
39
- const message = error instanceof Error ? error.message : String(error);
40
- throw new Error(`decodeTxData: Unexpected error - ${message}`);
39
+ // TODO: This shouldn't happen anymore and can probably be reverted.
40
+ // We keep it here now, because near-ca might not have adapted its router.
41
+ console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
42
+ try {
43
+ const typedData = JSON.parse(data);
44
+ return decodeTypedData(chainId, typedData);
45
+ }
46
+ catch (error) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ throw new Error(`decodeTxData: Unexpected error - ${message}`);
49
+ }
41
50
  }
42
51
  }
43
52
  }
@@ -2,4 +2,5 @@ export * from "./near-safe";
2
2
  export * from "./types";
3
3
  export * from "./util";
4
4
  export * from "./constants";
5
- export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, } from "near-ca";
5
+ export * from "./decode";
6
+ export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, } from "near-ca";
package/dist/esm/index.js CHANGED
@@ -2,4 +2,5 @@ export * from "./near-safe";
2
2
  export * from "./types";
3
3
  export * from "./util";
4
4
  export * from "./constants";
5
- export { Network, populateTx, signatureFromOutcome, signatureFromTxHash, } from "near-ca";
5
+ export * from "./decode";
6
+ export { Network, populateTx, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, } from "near-ca";
@@ -286,6 +286,7 @@ export class NearSafe {
286
286
  assertUnique(fromAddresses);
287
287
  // Early return with eoaEncoding if `from` is not the Safe
288
288
  if (!this.encodeForSafe(fromAddresses[0])) {
289
+ // TODO: near-ca needs to update this for typed data like we did.
289
290
  return mpcRequestRouter({ method, chainId, params });
290
291
  }
291
292
  const safeInfo = {
@@ -298,7 +299,14 @@ export class NearSafe {
298
299
  // We should either confirm they agree or ignore one of the two.
299
300
  switch (method) {
300
301
  case "eth_signTypedData":
301
- case "eth_signTypedData_v4":
302
+ case "eth_signTypedData_v4": {
303
+ const [_, typedDataString] = params;
304
+ const message = decodeSafeMessage(JSON.parse(typedDataString), safeInfo);
305
+ return {
306
+ evmMessage: JSON.parse(typedDataString),
307
+ hashToSign: message.safeMessageHash,
308
+ };
309
+ }
302
310
  case "eth_sign": {
303
311
  const [_, messageOrData] = params;
304
312
  const message = decodeSafeMessage(messageOrData, safeInfo);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",