near-safe 0.3.1 → 0.3.2
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.
- package/dist/cjs/lib/safe-message.d.ts +2 -7
- package/dist/cjs/lib/safe-message.js +0 -17
- package/dist/cjs/tx-manager.d.ts +4 -4
- package/dist/cjs/tx-manager.js +22 -13
- package/dist/cjs/types.d.ts +12 -1
- package/dist/esm/lib/safe-message.d.ts +2 -7
- package/dist/esm/lib/safe-message.js +0 -16
- package/dist/esm/tx-manager.d.ts +4 -4
- package/dist/esm/tx-manager.js +23 -14
- package/dist/esm/types.d.ts +12 -1
- package/package.json +1 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
import { type SafeInfo } from "@safe-global/safe-gateway-typescript-sdk";
|
2
|
-
import { EIP712TypedData
|
3
|
-
import {
|
2
|
+
import { EIP712TypedData } from "near-ca";
|
3
|
+
import { Hash } from "viem";
|
4
4
|
export type DecodedSafeMessage = {
|
5
5
|
decodedMessage: string | EIP712TypedData;
|
6
6
|
safeMessageMessage: string;
|
@@ -20,8 +20,3 @@ export type MinimalSafeInfo = Pick<SafeInfo, "address" | "version" | "chainId">;
|
|
20
20
|
* }`
|
21
21
|
*/
|
22
22
|
export declare function decodeSafeMessage(message: string | EIP712TypedData, safe: MinimalSafeInfo): DecodedSafeMessage;
|
23
|
-
export declare function safeMessageTxData(method: string, message: DecodedSafeMessage, sender: Address): {
|
24
|
-
evmMessage: string;
|
25
|
-
payload: number[];
|
26
|
-
recoveryData: RecoveryData;
|
27
|
-
};
|
@@ -1,8 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.decodeSafeMessage = decodeSafeMessage;
|
4
|
-
exports.safeMessageTxData = safeMessageTxData;
|
5
|
-
const near_ca_1 = require("near-ca");
|
6
4
|
const semver_1 = require("semver");
|
7
5
|
const viem_1 = require("viem");
|
8
6
|
/*
|
@@ -84,21 +82,6 @@ function decodeSafeMessage(message, safe) {
|
|
84
82
|
safeMessageHash: generateSafeMessageHash(safe, decodedMessage),
|
85
83
|
};
|
86
84
|
}
|
87
|
-
function safeMessageTxData(method, message, sender) {
|
88
|
-
return {
|
89
|
-
evmMessage: message.safeMessageMessage,
|
90
|
-
payload: (0, near_ca_1.toPayload)(message.safeMessageHash),
|
91
|
-
recoveryData: {
|
92
|
-
type: method,
|
93
|
-
data: {
|
94
|
-
address: sender,
|
95
|
-
// TODO - Upgrade Signable Message in near-ca
|
96
|
-
// @ts-expect-error: Type 'string | EIP712TypedData' is not assignable to type 'SignableMessage'.
|
97
|
-
message: decodedMessage,
|
98
|
-
},
|
99
|
-
},
|
100
|
-
};
|
101
|
-
}
|
102
85
|
// const isEIP712TypedData = (obj: any): obj is EIP712TypedData => {
|
103
86
|
// return (
|
104
87
|
// typeof obj === "object" &&
|
package/dist/cjs/tx-manager.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
2
|
-
import { NearEthAdapter, SignRequestData
|
2
|
+
import { NearEthAdapter, SignRequestData } from "near-ca";
|
3
3
|
import { Address, Hash, Hex } from "viem";
|
4
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
-
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
6
|
+
import { EncodedTxData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export declare class TransactionManager {
|
8
8
|
readonly nearAdapter: NearEthAdapter;
|
9
9
|
readonly address: Address;
|
@@ -31,7 +31,7 @@ export declare class TransactionManager {
|
|
31
31
|
}): Promise<UserOperation>;
|
32
32
|
signTransaction(safeOpHash: Hex): Promise<Hex>;
|
33
33
|
opHash(userOp: UserOperation): Promise<Hash>;
|
34
|
-
encodeSignRequest(signRequest: SignRequestData, usePaymaster: boolean): Promise<
|
34
|
+
encodeSignRequest(signRequest: SignRequestData, usePaymaster: boolean): Promise<EncodedTxData>;
|
35
35
|
executeTransaction(chainId: number, userOp: UserOperation): Promise<UserOperationReceipt>;
|
36
36
|
safeDeployed(chainId: number): Promise<boolean>;
|
37
37
|
addOwnerTx(address: Address): MetaTransaction;
|
@@ -53,6 +53,6 @@ export declare class TransactionManager {
|
|
53
53
|
requestRouter({ method, chainId, params }: SignRequestData, usePaymaster: boolean): Promise<{
|
54
54
|
evmMessage: string;
|
55
55
|
payload: number[];
|
56
|
-
|
56
|
+
hash: Hash;
|
57
57
|
}>;
|
58
58
|
}
|
package/dist/cjs/tx-manager.js
CHANGED
@@ -68,14 +68,18 @@ class TransactionManager {
|
|
68
68
|
return this.safePack.getOpHash(userOp);
|
69
69
|
}
|
70
70
|
async encodeSignRequest(signRequest, usePaymaster) {
|
71
|
-
const
|
71
|
+
const { payload, evmMessage, hash } = await this.requestRouter(signRequest, usePaymaster);
|
72
72
|
return {
|
73
73
|
nearPayload: await this.nearAdapter.mpcContract.encodeSignatureRequestTx({
|
74
74
|
path: this.nearAdapter.derivationPath,
|
75
|
-
payload
|
75
|
+
payload,
|
76
76
|
key_version: 0,
|
77
77
|
}),
|
78
|
-
|
78
|
+
evmData: {
|
79
|
+
chainId: signRequest.chainId,
|
80
|
+
data: evmMessage,
|
81
|
+
hash,
|
82
|
+
},
|
79
83
|
};
|
80
84
|
}
|
81
85
|
async executeTransaction(chainId, userOp) {
|
@@ -152,12 +156,22 @@ class TransactionManager {
|
|
152
156
|
case "eth_signTypedData":
|
153
157
|
case "eth_signTypedData_v4":
|
154
158
|
case "eth_sign": {
|
155
|
-
const [
|
156
|
-
|
159
|
+
const [_, messageOrData] = params;
|
160
|
+
const message = (0, safe_message_1.decodeSafeMessage)(messageOrData, safeInfo);
|
161
|
+
return {
|
162
|
+
evmMessage: message.safeMessageMessage,
|
163
|
+
payload: (0, near_ca_1.toPayload)(message.safeMessageHash),
|
164
|
+
hash: message.safeMessageHash,
|
165
|
+
};
|
157
166
|
}
|
158
167
|
case "personal_sign": {
|
159
|
-
const [messageHash,
|
160
|
-
|
168
|
+
const [messageHash, _] = params;
|
169
|
+
const message = (0, safe_message_1.decodeSafeMessage)(messageHash, safeInfo);
|
170
|
+
return {
|
171
|
+
evmMessage: message.safeMessageMessage,
|
172
|
+
payload: (0, near_ca_1.toPayload)(message.safeMessageHash),
|
173
|
+
hash: message.safeMessageHash,
|
174
|
+
};
|
161
175
|
}
|
162
176
|
case "eth_sendTransaction": {
|
163
177
|
const transactions = (0, util_1.metaTransactionsFromRequest)(params);
|
@@ -170,12 +184,7 @@ class TransactionManager {
|
|
170
184
|
return {
|
171
185
|
payload: (0, near_ca_1.toPayload)(opHash),
|
172
186
|
evmMessage: JSON.stringify(userOp),
|
173
|
-
|
174
|
-
type: method,
|
175
|
-
// TODO: Double check that this is sufficient for UI.
|
176
|
-
// We may want to adapt and return the `MetaTransactions` instead.
|
177
|
-
data: opHash,
|
178
|
-
},
|
187
|
+
hash: await this.opHash(userOp),
|
179
188
|
};
|
180
189
|
}
|
181
190
|
}
|
package/dist/cjs/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionCallTransaction, SignArgs } from "near-ca";
|
2
|
+
import { Address, Hash, Hex, TransactionSerializable } from "viem";
|
2
3
|
export interface UnsignedUserOperation {
|
3
4
|
sender: Address;
|
4
5
|
nonce: string;
|
@@ -89,4 +90,14 @@ export interface MetaTransaction {
|
|
89
90
|
readonly data: string;
|
90
91
|
readonly operation?: OperationType;
|
91
92
|
}
|
93
|
+
export interface EncodedTxData {
|
94
|
+
evmData: {
|
95
|
+
chainId: number;
|
96
|
+
data: string | TransactionSerializable;
|
97
|
+
hash: Hash;
|
98
|
+
};
|
99
|
+
nearPayload: FunctionCallTransaction<{
|
100
|
+
request: SignArgs;
|
101
|
+
}>;
|
102
|
+
}
|
92
103
|
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { type SafeInfo } from "@safe-global/safe-gateway-typescript-sdk";
|
2
|
-
import { EIP712TypedData
|
3
|
-
import {
|
2
|
+
import { EIP712TypedData } from "near-ca";
|
3
|
+
import { Hash } from "viem";
|
4
4
|
export type DecodedSafeMessage = {
|
5
5
|
decodedMessage: string | EIP712TypedData;
|
6
6
|
safeMessageMessage: string;
|
@@ -20,8 +20,3 @@ export type MinimalSafeInfo = Pick<SafeInfo, "address" | "version" | "chainId">;
|
|
20
20
|
* }`
|
21
21
|
*/
|
22
22
|
export declare function decodeSafeMessage(message: string | EIP712TypedData, safe: MinimalSafeInfo): DecodedSafeMessage;
|
23
|
-
export declare function safeMessageTxData(method: string, message: DecodedSafeMessage, sender: Address): {
|
24
|
-
evmMessage: string;
|
25
|
-
payload: number[];
|
26
|
-
recoveryData: RecoveryData;
|
27
|
-
};
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { toPayload } from "near-ca";
|
2
1
|
import { gte } from "semver";
|
3
2
|
import { fromHex, hashMessage, hashTypedData, isHex, } from "viem";
|
4
3
|
/*
|
@@ -80,21 +79,6 @@ export function decodeSafeMessage(message, safe) {
|
|
80
79
|
safeMessageHash: generateSafeMessageHash(safe, decodedMessage),
|
81
80
|
};
|
82
81
|
}
|
83
|
-
export function safeMessageTxData(method, message, sender) {
|
84
|
-
return {
|
85
|
-
evmMessage: message.safeMessageMessage,
|
86
|
-
payload: toPayload(message.safeMessageHash),
|
87
|
-
recoveryData: {
|
88
|
-
type: method,
|
89
|
-
data: {
|
90
|
-
address: sender,
|
91
|
-
// TODO - Upgrade Signable Message in near-ca
|
92
|
-
// @ts-expect-error: Type 'string | EIP712TypedData' is not assignable to type 'SignableMessage'.
|
93
|
-
message: decodedMessage,
|
94
|
-
},
|
95
|
-
},
|
96
|
-
};
|
97
|
-
}
|
98
82
|
// const isEIP712TypedData = (obj: any): obj is EIP712TypedData => {
|
99
83
|
// return (
|
100
84
|
// typeof obj === "object" &&
|
package/dist/esm/tx-manager.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
2
|
-
import { NearEthAdapter, SignRequestData
|
2
|
+
import { NearEthAdapter, SignRequestData } from "near-ca";
|
3
3
|
import { Address, Hash, Hex } from "viem";
|
4
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
-
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
6
|
+
import { EncodedTxData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export declare class TransactionManager {
|
8
8
|
readonly nearAdapter: NearEthAdapter;
|
9
9
|
readonly address: Address;
|
@@ -31,7 +31,7 @@ export declare class TransactionManager {
|
|
31
31
|
}): Promise<UserOperation>;
|
32
32
|
signTransaction(safeOpHash: Hex): Promise<Hex>;
|
33
33
|
opHash(userOp: UserOperation): Promise<Hash>;
|
34
|
-
encodeSignRequest(signRequest: SignRequestData, usePaymaster: boolean): Promise<
|
34
|
+
encodeSignRequest(signRequest: SignRequestData, usePaymaster: boolean): Promise<EncodedTxData>;
|
35
35
|
executeTransaction(chainId: number, userOp: UserOperation): Promise<UserOperationReceipt>;
|
36
36
|
safeDeployed(chainId: number): Promise<boolean>;
|
37
37
|
addOwnerTx(address: Address): MetaTransaction;
|
@@ -53,6 +53,6 @@ export declare class TransactionManager {
|
|
53
53
|
requestRouter({ method, chainId, params }: SignRequestData, usePaymaster: boolean): Promise<{
|
54
54
|
evmMessage: string;
|
55
55
|
payload: number[];
|
56
|
-
|
56
|
+
hash: Hash;
|
57
57
|
}>;
|
58
58
|
}
|
package/dist/esm/tx-manager.js
CHANGED
@@ -3,7 +3,7 @@ import { serializeSignature } from "viem";
|
|
3
3
|
import { Erc4337Bundler } from "./lib/bundler";
|
4
4
|
import { encodeMulti } from "./lib/multisend";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
-
import { decodeSafeMessage
|
6
|
+
import { decodeSafeMessage } from "./lib/safe-message";
|
7
7
|
import { getClient, isContract, metaTransactionsFromRequest, packSignature, } from "./util";
|
8
8
|
export class TransactionManager {
|
9
9
|
nearAdapter;
|
@@ -72,14 +72,18 @@ export class TransactionManager {
|
|
72
72
|
return this.safePack.getOpHash(userOp);
|
73
73
|
}
|
74
74
|
async encodeSignRequest(signRequest, usePaymaster) {
|
75
|
-
const
|
75
|
+
const { payload, evmMessage, hash } = await this.requestRouter(signRequest, usePaymaster);
|
76
76
|
return {
|
77
77
|
nearPayload: await this.nearAdapter.mpcContract.encodeSignatureRequestTx({
|
78
78
|
path: this.nearAdapter.derivationPath,
|
79
|
-
payload
|
79
|
+
payload,
|
80
80
|
key_version: 0,
|
81
81
|
}),
|
82
|
-
|
82
|
+
evmData: {
|
83
|
+
chainId: signRequest.chainId,
|
84
|
+
data: evmMessage,
|
85
|
+
hash,
|
86
|
+
},
|
83
87
|
};
|
84
88
|
}
|
85
89
|
async executeTransaction(chainId, userOp) {
|
@@ -156,12 +160,22 @@ export class TransactionManager {
|
|
156
160
|
case "eth_signTypedData":
|
157
161
|
case "eth_signTypedData_v4":
|
158
162
|
case "eth_sign": {
|
159
|
-
const [
|
160
|
-
|
163
|
+
const [_, messageOrData] = params;
|
164
|
+
const message = decodeSafeMessage(messageOrData, safeInfo);
|
165
|
+
return {
|
166
|
+
evmMessage: message.safeMessageMessage,
|
167
|
+
payload: toPayload(message.safeMessageHash),
|
168
|
+
hash: message.safeMessageHash,
|
169
|
+
};
|
161
170
|
}
|
162
171
|
case "personal_sign": {
|
163
|
-
const [messageHash,
|
164
|
-
|
172
|
+
const [messageHash, _] = params;
|
173
|
+
const message = decodeSafeMessage(messageHash, safeInfo);
|
174
|
+
return {
|
175
|
+
evmMessage: message.safeMessageMessage,
|
176
|
+
payload: toPayload(message.safeMessageHash),
|
177
|
+
hash: message.safeMessageHash,
|
178
|
+
};
|
165
179
|
}
|
166
180
|
case "eth_sendTransaction": {
|
167
181
|
const transactions = metaTransactionsFromRequest(params);
|
@@ -174,12 +188,7 @@ export class TransactionManager {
|
|
174
188
|
return {
|
175
189
|
payload: toPayload(opHash),
|
176
190
|
evmMessage: JSON.stringify(userOp),
|
177
|
-
|
178
|
-
type: method,
|
179
|
-
// TODO: Double check that this is sufficient for UI.
|
180
|
-
// We may want to adapt and return the `MetaTransactions` instead.
|
181
|
-
data: opHash,
|
182
|
-
},
|
191
|
+
hash: await this.opHash(userOp),
|
183
192
|
};
|
184
193
|
}
|
185
194
|
}
|
package/dist/esm/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionCallTransaction, SignArgs } from "near-ca";
|
2
|
+
import { Address, Hash, Hex, TransactionSerializable } from "viem";
|
2
3
|
export interface UnsignedUserOperation {
|
3
4
|
sender: Address;
|
4
5
|
nonce: string;
|
@@ -89,4 +90,14 @@ export interface MetaTransaction {
|
|
89
90
|
readonly data: string;
|
90
91
|
readonly operation?: OperationType;
|
91
92
|
}
|
93
|
+
export interface EncodedTxData {
|
94
|
+
evmData: {
|
95
|
+
chainId: number;
|
96
|
+
data: string | TransactionSerializable;
|
97
|
+
hash: Hash;
|
98
|
+
};
|
99
|
+
nearPayload: FunctionCallTransaction<{
|
100
|
+
request: SignArgs;
|
101
|
+
}>;
|
102
|
+
}
|
92
103
|
export {};
|