@pushchain/core 6.0.20 → 6.0.21
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/CHANGELOG.md +48 -0
- package/package.json +1 -1
- package/src/lib/cache/cache.js +2 -0
- package/src/lib/constants/abi/index.d.ts +1 -0
- package/src/lib/constants/abi/index.js +8 -1
- package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
- package/src/lib/constants/abi/pc20.evm.js +150 -0
- package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
- package/src/lib/constants/abi/prc20.evm.js +97 -0
- package/src/lib/constants/abi/universalGatewayV0.json +1 -1
- package/src/lib/constants/chain.js +38 -8
- package/src/lib/constants/selectors.js +2 -2
- package/src/lib/constants/tokens.js +4 -3
- package/src/lib/formatters.js +16 -6
- package/src/lib/generated/uexecutor/v1/query.js +2 -4
- package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
- package/src/lib/generated/uexecutor/v1/types.js +90 -47
- package/src/lib/generated/uexecutor/v2/query.js +2 -4
- package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
- package/src/lib/generated/uexecutor/v2/types.js +49 -33
- package/src/lib/generated/v1/tx.js +30 -37
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +21 -3
- package/src/lib/internal/buffer.js +1 -2
- package/src/lib/orchestrator/cea-utils.js +73 -83
- package/src/lib/orchestrator/internals/account-manager.js +130 -139
- package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
- package/src/lib/orchestrator/internals/cascade.js +1184 -1059
- package/src/lib/orchestrator/internals/confirmation.js +138 -148
- package/src/lib/orchestrator/internals/error-decoder.js +1 -1
- package/src/lib/orchestrator/internals/errors.js +12 -3
- package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
- package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
- package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
- package/src/lib/orchestrator/internals/execute-standard.js +339 -342
- package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
- package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
- package/src/lib/orchestrator/internals/gateway-client.js +102 -103
- package/src/lib/orchestrator/internals/helpers.js +30 -27
- package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
- package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
- package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
- package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
- package/src/lib/orchestrator/internals/payload-builder.js +119 -100
- package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
- package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
- package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
- package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
- package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
- package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
- package/src/lib/orchestrator/internals/pc20/export.js +412 -0
- package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
- package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
- package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
- package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
- package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
- package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
- package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
- package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
- package/src/lib/orchestrator/internals/preflight.js +1 -1
- package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
- package/src/lib/orchestrator/internals/push-chain-tx.js +319 -329
- package/src/lib/orchestrator/internals/quote.js +90 -94
- package/src/lib/orchestrator/internals/rescue.js +76 -79
- package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
- package/src/lib/orchestrator/internals/response-builder.js +817 -701
- package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
- package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
- package/src/lib/orchestrator/internals/signing.js +78 -83
- package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
- package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
- package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
- package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
- package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
- package/src/lib/orchestrator/internals/svm-rent.js +163 -141
- package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
- package/src/lib/orchestrator/internals/uea-manager.js +89 -86
- package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
- package/src/lib/orchestrator/orchestrator.js +217 -200
- package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
- package/src/lib/orchestrator/orchestrator.types.js +19 -0
- package/src/lib/orchestrator/payload-builders.d.ts +2 -2
- package/src/lib/orchestrator/payload-builders.js +26 -24
- package/src/lib/orchestrator/route-detector.js +26 -9
- package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
- package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
- package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
- package/src/lib/price-fetch/price-fetch.js +67 -68
- package/src/lib/progress-hook/progress-hook.js +124 -72
- package/src/lib/push-chain/push-chain.js +171 -153
- package/src/lib/push-client/push-client.js +223 -237
- package/src/lib/universal/account/account.js +349 -365
- package/src/lib/universal/signer/signer.js +306 -294
- package/src/lib/universal-tx-detector/auto-detect.js +55 -60
- package/src/lib/universal-tx-detector/cascade.js +160 -172
- package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
- package/src/lib/universal-tx-detector/classify.js +2 -3
- package/src/lib/universal-tx-detector/detector-svm.js +139 -147
- package/src/lib/universal-tx-detector/detector.js +145 -157
- package/src/lib/universal-tx-detector/normalize.js +7 -7
- package/src/lib/utils/external-tx-hash.js +1 -2
- package/src/lib/utils.d.ts +44 -0
- package/src/lib/utils.js +762 -683
- package/src/lib/vm-client/evm-client.js +186 -202
- package/src/lib/vm-client/svm-client.d.ts +1 -1
- package/src/lib/vm-client/svm-client.js +220 -224
- package/src/lib/vm-client/vm-client.types.d.ts +14 -2
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.createUniversalSigner = createUniversalSigner;
|
|
4
27
|
exports.toUniversalFromKeypair = toUniversalFromKeypair;
|
|
5
28
|
exports.construct = construct;
|
|
6
29
|
exports.toUniversal = toUniversal;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
30
|
const viem_1 = require("viem");
|
|
9
31
|
let _nacl = null;
|
|
10
|
-
function getNacl() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return _nacl;
|
|
15
|
-
});
|
|
32
|
+
async function getNacl() {
|
|
33
|
+
if (!_nacl)
|
|
34
|
+
_nacl = await Promise.resolve().then(() => __importStar(require('tweetnacl')));
|
|
35
|
+
return _nacl;
|
|
16
36
|
}
|
|
17
37
|
const web3_js_1 = require("@solana/web3.js");
|
|
18
38
|
const enums_1 = require("../../constants/enums");
|
|
@@ -28,19 +48,16 @@ const bs58_1 = require("../../internal/bs58");
|
|
|
28
48
|
* the entry to a zero signature and the delegation is silently dropped.
|
|
29
49
|
*/
|
|
30
50
|
function toEthersTxRequest(viemTx) {
|
|
31
|
-
const
|
|
32
|
-
const out =
|
|
51
|
+
const { gas, type, authorizationList, ...rest } = viemTx;
|
|
52
|
+
const out = { ...rest, gasLimit: gas };
|
|
33
53
|
if (Array.isArray(authorizationList) && authorizationList.length > 0) {
|
|
34
54
|
out['type'] = 4;
|
|
35
|
-
out['authorizationList'] = authorizationList.map((a) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
signature: { r: a.r, s: a.s, yParity: a.yParity },
|
|
42
|
-
});
|
|
43
|
-
});
|
|
55
|
+
out['authorizationList'] = authorizationList.map((a) => ({
|
|
56
|
+
address: a.address ?? a.contractAddress,
|
|
57
|
+
chainId: a.chainId,
|
|
58
|
+
nonce: a.nonce,
|
|
59
|
+
signature: { r: a.r, s: a.s, yParity: a.yParity },
|
|
60
|
+
}));
|
|
44
61
|
}
|
|
45
62
|
return out;
|
|
46
63
|
}
|
|
@@ -53,14 +70,20 @@ function toEthersTxRequest(viemTx) {
|
|
|
53
70
|
* fall back to non-7702 execution.
|
|
54
71
|
*/
|
|
55
72
|
function viemSignAuthorization(wallet, address) {
|
|
56
|
-
const account = wallet
|
|
73
|
+
const account = wallet?.account;
|
|
57
74
|
if (!account || typeof account.signAuthorization !== 'function') {
|
|
58
75
|
return undefined;
|
|
59
76
|
}
|
|
60
|
-
return
|
|
61
|
-
const auth =
|
|
77
|
+
return async ({ contractAddress, chainId, nonce, executor }) => {
|
|
78
|
+
const auth = await wallet.signAuthorization({
|
|
79
|
+
account: account || address,
|
|
80
|
+
contractAddress,
|
|
81
|
+
...(chainId !== undefined ? { chainId } : {}),
|
|
82
|
+
...(nonce !== undefined ? { nonce } : {}),
|
|
83
|
+
...(executor ? { executor } : {}),
|
|
84
|
+
});
|
|
62
85
|
return auth;
|
|
63
|
-
}
|
|
86
|
+
};
|
|
64
87
|
}
|
|
65
88
|
/**
|
|
66
89
|
* Builds an EIP-7702 `signAuthorization` for an ethers v6 signer. Presence of
|
|
@@ -70,26 +93,25 @@ function viemSignAuthorization(wallet, address) {
|
|
|
70
93
|
* is entirely absent (e.g. ethers v5).
|
|
71
94
|
*/
|
|
72
95
|
function ethersSignAuthorization(wallet, chain) {
|
|
73
|
-
if (typeof
|
|
96
|
+
if (typeof wallet?.authorize !== 'function')
|
|
74
97
|
return undefined;
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const auth = yield wallet.authorize({
|
|
98
|
+
return async ({ contractAddress, chainId, nonce }) => {
|
|
99
|
+
const cid = chainId ?? Number(chain.split(':')[1]);
|
|
100
|
+
const auth = await wallet.authorize({
|
|
79
101
|
address: contractAddress,
|
|
80
102
|
chainId: cid,
|
|
81
|
-
nonce: nonce
|
|
103
|
+
nonce: nonce ?? 0,
|
|
82
104
|
});
|
|
83
105
|
const sig = auth.signature;
|
|
84
106
|
return {
|
|
85
107
|
address: contractAddress,
|
|
86
|
-
chainId: Number(
|
|
87
|
-
nonce: Number(
|
|
108
|
+
chainId: Number(auth.chainId ?? cid),
|
|
109
|
+
nonce: Number(auth.nonce ?? nonce ?? 0),
|
|
88
110
|
r: sig.r,
|
|
89
111
|
s: sig.s,
|
|
90
112
|
yParity: Number(sig.yParity),
|
|
91
113
|
};
|
|
92
|
-
}
|
|
114
|
+
};
|
|
93
115
|
}
|
|
94
116
|
/**
|
|
95
117
|
* Maps an EVM numeric chainId to the corresponding CHAIN enum.
|
|
@@ -153,158 +175,156 @@ function createUniversalSigner({ account, signMessage, signAndSendTransaction, s
|
|
|
153
175
|
* @param {CHAIN} chain - The chain the signer will operate on
|
|
154
176
|
* @returns {Promise<UniversalSigner>} A signer object configured for the specified chain
|
|
155
177
|
*/
|
|
156
|
-
function toUniversalFromKeypair(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
throw new Error('Expected an object with signMessage, sendTransaction, getAddress methods for ETHEREUM_ETHERSV6 library');
|
|
174
|
-
}
|
|
175
|
-
const wallet = clientOrAccount;
|
|
176
|
-
if (!wallet.provider) {
|
|
177
|
-
throw new Error('ethers.Wallet must have a provider attached');
|
|
178
|
-
}
|
|
179
|
-
// fetch on-chain chainId
|
|
180
|
-
const { chainId } = yield wallet.provider.getNetwork();
|
|
181
|
-
if (chainId.toString() !== chain.split(':')[1]) {
|
|
182
|
-
throw new Error(`Chain mismatch: wallet is on ${chainId}, expected ${chain}`);
|
|
183
|
-
}
|
|
184
|
-
address = yield wallet.getAddress();
|
|
185
|
-
// raw bytes → signMessage → hex → back to bytes
|
|
186
|
-
signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const sigHex = yield wallet.signMessage(data);
|
|
188
|
-
return (0, viem_1.hexToBytes)(sigHex);
|
|
189
|
-
});
|
|
190
|
-
// raw unsigned tx bytes → hex → parse → signAndSendTransaction → bytes
|
|
191
|
-
signAndSendTransaction = (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
const unsignedHex = (0, viem_1.bytesToHex)(raw);
|
|
193
|
-
const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
|
|
194
|
-
const txResponse = yield wallet.sendTransaction(tx);
|
|
195
|
-
return (0, viem_1.hexToBytes)(txResponse.hash);
|
|
196
|
-
});
|
|
197
|
-
// EIP-712 typed data → signTypedData → hex → bytes
|
|
198
|
-
signTypedData = (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
|
|
199
|
-
const sigHex = yield wallet.signTypedData(domain, types, message);
|
|
200
|
-
return (0, viem_1.hexToBytes)(sigHex);
|
|
201
|
-
});
|
|
202
|
-
// EIP-7702 authorization signing (ethers v6). Backed by a runtime
|
|
203
|
-
// fallback in evm-client since `authorize` presence isn't a guarantee.
|
|
204
|
-
signAuthorization = ethersSignAuthorization(wallet, chain);
|
|
205
|
-
break;
|
|
178
|
+
async function toUniversalFromKeypair(clientOrAccount, { chain, library }) {
|
|
179
|
+
let address;
|
|
180
|
+
let signMessage;
|
|
181
|
+
let signAndSendTransaction;
|
|
182
|
+
let signTypedData;
|
|
183
|
+
// Optional: only set for EVM wallets that support EIP-7702 authorization
|
|
184
|
+
// signing. Left undefined for Solana and wallets without 7702 support, in
|
|
185
|
+
// which case callers fall back to a non-7702 path.
|
|
186
|
+
let signAuthorization;
|
|
187
|
+
// Check if signer has UID='custom', then we take signMessage, signAndSendTransaction, signTypedData, chain and address from the CustomUniversalSigner.
|
|
188
|
+
// If ViemSigner, convert ViemSigner to UniversalSigner.
|
|
189
|
+
switch (library) {
|
|
190
|
+
case enums_1.LIBRARY.ETHEREUM_ETHERSV6: {
|
|
191
|
+
if (typeof clientOrAccount.signMessage !== 'function' ||
|
|
192
|
+
typeof clientOrAccount.sendTransaction !== 'function' ||
|
|
193
|
+
typeof clientOrAccount.getAddress !== 'function') {
|
|
194
|
+
throw new Error('Expected an object with signMessage, sendTransaction, getAddress methods for ETHEREUM_ETHERSV6 library');
|
|
206
195
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
const hexSig = yield clientOrAccount.signMessage({
|
|
212
|
-
account: wallet.account || address,
|
|
213
|
-
message: { raw: data },
|
|
214
|
-
});
|
|
215
|
-
return (0, viem_1.hexToBytes)(hexSig);
|
|
216
|
-
});
|
|
217
|
-
signAndSendTransaction = (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
|
|
219
|
-
const txHash = yield wallet.sendTransaction(tx);
|
|
220
|
-
return (0, viem_1.hexToBytes)(txHash);
|
|
221
|
-
});
|
|
222
|
-
signTypedData = (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
|
|
223
|
-
const hexSig = yield wallet.signTypedData({
|
|
224
|
-
domain,
|
|
225
|
-
types,
|
|
226
|
-
primaryType,
|
|
227
|
-
message,
|
|
228
|
-
account: clientOrAccount.account ||
|
|
229
|
-
address,
|
|
230
|
-
});
|
|
231
|
-
return (0, viem_1.hexToBytes)(hexSig);
|
|
232
|
-
});
|
|
233
|
-
// EIP-7702 authorization signing — only for local viem accounts that can
|
|
234
|
-
// sign offline (gated inside the helper); JSON-RPC accounts fall back.
|
|
235
|
-
signAuthorization = viemSignAuthorization(wallet, address);
|
|
236
|
-
break;
|
|
196
|
+
const wallet = clientOrAccount;
|
|
197
|
+
if (!wallet.provider) {
|
|
198
|
+
throw new Error('ethers.Wallet must have a provider attached');
|
|
237
199
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
txHash = yield connection.sendRawTransaction(rawVtx);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
// Handle as legacy transaction
|
|
277
|
-
const tx = web3_js_1.Transaction.from(unsignedTx);
|
|
278
|
-
const messageBytes = tx.serializeMessage();
|
|
279
|
-
const nacl = yield getNacl();
|
|
280
|
-
const signature = nacl.sign.detached(messageBytes, keypair.secretKey);
|
|
281
|
-
tx.addSignature(new web3_js_1.PublicKey(keypair.publicKey.toBase58()), Buffer.from(signature));
|
|
282
|
-
const rawTx = tx.serialize();
|
|
283
|
-
txHash = yield connection.sendRawTransaction(rawTx);
|
|
284
|
-
}
|
|
285
|
-
return bs58_1.bs58.decode(txHash);
|
|
200
|
+
// fetch on-chain chainId
|
|
201
|
+
const { chainId } = await wallet.provider.getNetwork();
|
|
202
|
+
if (chainId.toString() !== chain.split(':')[1]) {
|
|
203
|
+
throw new Error(`Chain mismatch: wallet is on ${chainId}, expected ${chain}`);
|
|
204
|
+
}
|
|
205
|
+
address = await wallet.getAddress();
|
|
206
|
+
// raw bytes → signMessage → hex → back to bytes
|
|
207
|
+
signMessage = async (data) => {
|
|
208
|
+
const sigHex = await wallet.signMessage(data);
|
|
209
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
210
|
+
};
|
|
211
|
+
// raw unsigned tx bytes → hex → parse → signAndSendTransaction → bytes
|
|
212
|
+
signAndSendTransaction = async (raw) => {
|
|
213
|
+
const unsignedHex = (0, viem_1.bytesToHex)(raw);
|
|
214
|
+
const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
|
|
215
|
+
const txResponse = await wallet.sendTransaction(tx);
|
|
216
|
+
return (0, viem_1.hexToBytes)(txResponse.hash);
|
|
217
|
+
};
|
|
218
|
+
// EIP-712 typed data → signTypedData → hex → bytes
|
|
219
|
+
signTypedData = async ({ domain, types, primaryType, message }) => {
|
|
220
|
+
const sigHex = await wallet.signTypedData(domain, types, message);
|
|
221
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
222
|
+
};
|
|
223
|
+
// EIP-7702 authorization signing (ethers v6). Backed by a runtime
|
|
224
|
+
// fallback in evm-client since `authorize` presence isn't a guarantee.
|
|
225
|
+
signAuthorization = ethersSignAuthorization(wallet, chain);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case enums_1.LIBRARY.ETHEREUM_VIEM: {
|
|
229
|
+
const wallet = clientOrAccount;
|
|
230
|
+
address = (await wallet.getAddresses())[0];
|
|
231
|
+
signMessage = async (data) => {
|
|
232
|
+
const hexSig = await clientOrAccount.signMessage({
|
|
233
|
+
account: wallet.account || address,
|
|
234
|
+
message: { raw: data },
|
|
286
235
|
});
|
|
287
|
-
|
|
288
|
-
|
|
236
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
237
|
+
};
|
|
238
|
+
signAndSendTransaction = async (unsignedTx) => {
|
|
239
|
+
const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
|
|
240
|
+
const txHash = await wallet.sendTransaction(tx);
|
|
241
|
+
return (0, viem_1.hexToBytes)(txHash);
|
|
242
|
+
};
|
|
243
|
+
signTypedData = async ({ domain, types, primaryType, message }) => {
|
|
244
|
+
const hexSig = await wallet.signTypedData({
|
|
245
|
+
domain,
|
|
246
|
+
types,
|
|
247
|
+
primaryType,
|
|
248
|
+
message,
|
|
249
|
+
account: clientOrAccount.account ||
|
|
250
|
+
address,
|
|
289
251
|
});
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
252
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
253
|
+
};
|
|
254
|
+
// EIP-7702 authorization signing — only for local viem accounts that can
|
|
255
|
+
// sign offline (gated inside the helper); JSON-RPC accounts fall back.
|
|
256
|
+
signAuthorization = viemSignAuthorization(wallet, address);
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case enums_1.LIBRARY.SOLANA_WEB3JS: {
|
|
260
|
+
const keypair = clientOrAccount;
|
|
261
|
+
if (chain !== enums_1.CHAIN.SOLANA_MAINNET &&
|
|
262
|
+
chain !== enums_1.CHAIN.SOLANA_TESTNET &&
|
|
263
|
+
chain !== enums_1.CHAIN.SOLANA_DEVNET) {
|
|
264
|
+
throw new Error('Invalid chain for Solana Keypair');
|
|
294
265
|
}
|
|
266
|
+
address = keypair.publicKey.toBase58();
|
|
267
|
+
signMessage = async (data) => {
|
|
268
|
+
const nacl = await getNacl();
|
|
269
|
+
return nacl.sign.detached(data, keypair.secretKey);
|
|
270
|
+
};
|
|
271
|
+
// ✅ Sign and send the transaction to Solana network
|
|
272
|
+
signAndSendTransaction = async (unsignedTx) => {
|
|
273
|
+
const endpoint = chain_1.CHAIN_INFO[chain].defaultRPC[0];
|
|
274
|
+
const connection = new web3_js_1.Connection(endpoint, 'confirmed');
|
|
275
|
+
let txHash;
|
|
276
|
+
// Detect if this is a versioned transaction by looking at the message portion.
|
|
277
|
+
// Transaction format: [signature_count (compact-u16)][signatures][message]
|
|
278
|
+
// For versioned messages, the first byte of the message has high bit set (>= 0x80)
|
|
279
|
+
// Read signature count - if < 0x80, it's a single byte count
|
|
280
|
+
let sigOffset = 1;
|
|
281
|
+
const sigCount = unsignedTx[0];
|
|
282
|
+
if (sigCount >= 0x80) {
|
|
283
|
+
// Two-byte compact-u16 encoding
|
|
284
|
+
sigOffset = 2;
|
|
285
|
+
}
|
|
286
|
+
// Skip past signatures (64 bytes each) to get to the message
|
|
287
|
+
const messageOffset = sigOffset + sigCount * 64;
|
|
288
|
+
const isVersionedTx = unsignedTx[messageOffset] >= 0x80;
|
|
289
|
+
if (isVersionedTx) {
|
|
290
|
+
// Handle as versioned transaction (v0)
|
|
291
|
+
const vtx = web3_js_1.VersionedTransaction.deserialize(unsignedTx);
|
|
292
|
+
vtx.sign([keypair]);
|
|
293
|
+
const rawVtx = vtx.serialize();
|
|
294
|
+
txHash = await connection.sendRawTransaction(rawVtx);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
// Handle as legacy transaction
|
|
298
|
+
const tx = web3_js_1.Transaction.from(unsignedTx);
|
|
299
|
+
const messageBytes = tx.serializeMessage();
|
|
300
|
+
const nacl = await getNacl();
|
|
301
|
+
const signature = nacl.sign.detached(messageBytes, keypair.secretKey);
|
|
302
|
+
tx.addSignature(new web3_js_1.PublicKey(keypair.publicKey.toBase58()), Buffer.from(signature));
|
|
303
|
+
const rawTx = tx.serialize();
|
|
304
|
+
txHash = await connection.sendRawTransaction(rawTx);
|
|
305
|
+
}
|
|
306
|
+
return bs58_1.bs58.decode(txHash);
|
|
307
|
+
};
|
|
308
|
+
signTypedData = async () => {
|
|
309
|
+
throw new Error('Typed data signing is not supported for Solana');
|
|
310
|
+
};
|
|
311
|
+
break;
|
|
295
312
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
313
|
+
default: {
|
|
314
|
+
throw new Error(`Unsupported library: ${library}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const universalSigner = {
|
|
318
|
+
account: {
|
|
319
|
+
address,
|
|
320
|
+
chain,
|
|
321
|
+
},
|
|
322
|
+
signMessage,
|
|
323
|
+
signAndSendTransaction,
|
|
324
|
+
signTypedData,
|
|
325
|
+
signAuthorization,
|
|
326
|
+
};
|
|
327
|
+
return createUniversalSigner(universalSigner);
|
|
308
328
|
}
|
|
309
329
|
// `signTypedData` is only mandatory for EVM Signers. For Solana, this is not necessary.
|
|
310
330
|
function construct(account, options) {
|
|
@@ -327,133 +347,125 @@ function construct(account, options) {
|
|
|
327
347
|
signAuthorization,
|
|
328
348
|
};
|
|
329
349
|
}
|
|
330
|
-
function toUniversal(signer) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
350
|
+
async function toUniversal(signer) {
|
|
351
|
+
if ('signerId' in signer) {
|
|
352
|
+
return createUniversalSigner(signer);
|
|
353
|
+
}
|
|
354
|
+
let skeleton;
|
|
355
|
+
if (!isViemSigner(signer)) {
|
|
356
|
+
const wallet = signer;
|
|
357
|
+
if (!wallet.provider) {
|
|
358
|
+
throw new Error('ethers.Wallet must have a provider attached to determine chain');
|
|
334
359
|
}
|
|
335
|
-
|
|
336
|
-
if (
|
|
337
|
-
|
|
338
|
-
if (!wallet.provider) {
|
|
339
|
-
throw new Error('ethers.Wallet must have a provider attached to determine chain');
|
|
340
|
-
}
|
|
341
|
-
// Check if _signTypedData property is present to determine if it's EthersV5 or EthersV6
|
|
342
|
-
if ('_signTypedData' in wallet) {
|
|
343
|
-
skeleton = yield generateSkeletonFromEthersV5(wallet);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
skeleton = yield generateSkeletonFromEthersV6(wallet);
|
|
347
|
-
}
|
|
360
|
+
// Check if _signTypedData property is present to determine if it's EthersV5 or EthersV6
|
|
361
|
+
if ('_signTypedData' in wallet) {
|
|
362
|
+
skeleton = await generateSkeletonFromEthersV5(wallet);
|
|
348
363
|
}
|
|
349
364
|
else {
|
|
350
|
-
skeleton =
|
|
365
|
+
skeleton = await generateSkeletonFromEthersV6(wallet);
|
|
351
366
|
}
|
|
352
|
-
|
|
353
|
-
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
skeleton = await generateSkeletonFromViem(signer);
|
|
370
|
+
}
|
|
371
|
+
return createUniversalSigner(skeleton);
|
|
354
372
|
}
|
|
355
|
-
function generateSkeletonFromEthersV5(signer) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
};
|
|
379
|
-
});
|
|
373
|
+
async function generateSkeletonFromEthersV5(signer) {
|
|
374
|
+
const address = await signer.getAddress();
|
|
375
|
+
const { chainId } = await signer.provider.getNetwork();
|
|
376
|
+
const chain = chainIdToChain(chainId);
|
|
377
|
+
return {
|
|
378
|
+
signerId: `EthersSignerV5-${address}`,
|
|
379
|
+
account: { address, chain },
|
|
380
|
+
signMessage: async (data) => {
|
|
381
|
+
const sigHex = await signer.signMessage(data);
|
|
382
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
383
|
+
},
|
|
384
|
+
// raw unsigned tx bytes → hex → parse → signTransaction → bytes
|
|
385
|
+
signAndSendTransaction: async (raw) => {
|
|
386
|
+
const unsignedHex = (0, viem_1.bytesToHex)(raw);
|
|
387
|
+
const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
|
|
388
|
+
const txResponse = await signer.sendTransaction(tx);
|
|
389
|
+
return (0, viem_1.hexToBytes)(txResponse.hash);
|
|
390
|
+
},
|
|
391
|
+
signTypedData: async ({ domain, types, primaryType, message }) => {
|
|
392
|
+
const sigHex = await signer._signTypedData(domain, types, message);
|
|
393
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
394
|
+
},
|
|
395
|
+
};
|
|
380
396
|
}
|
|
381
|
-
function generateSkeletonFromEthersV6(signer) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
};
|
|
406
|
-
});
|
|
397
|
+
async function generateSkeletonFromEthersV6(signer) {
|
|
398
|
+
const address = await signer.getAddress();
|
|
399
|
+
const { chainId } = await signer.provider.getNetwork();
|
|
400
|
+
const chain = chainIdToChain(chainId);
|
|
401
|
+
return {
|
|
402
|
+
signerId: `EthersSignerV6-${address}`,
|
|
403
|
+
account: { address, chain },
|
|
404
|
+
signMessage: async (data) => {
|
|
405
|
+
const sigHex = await signer.signMessage(data);
|
|
406
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
407
|
+
},
|
|
408
|
+
// raw unsigned tx bytes → hex → parse → signTransaction → bytes
|
|
409
|
+
signAndSendTransaction: async (raw) => {
|
|
410
|
+
const unsignedHex = (0, viem_1.bytesToHex)(raw);
|
|
411
|
+
const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
|
|
412
|
+
const txResponse = await signer.sendTransaction(tx);
|
|
413
|
+
return (0, viem_1.hexToBytes)(txResponse.hash);
|
|
414
|
+
},
|
|
415
|
+
signTypedData: async ({ domain, types, primaryType, message }) => {
|
|
416
|
+
const sigHex = await signer.signTypedData(domain, types, message);
|
|
417
|
+
return (0, viem_1.hexToBytes)(sigHex);
|
|
418
|
+
},
|
|
419
|
+
signAuthorization: ethersSignAuthorization(signer, chain),
|
|
420
|
+
};
|
|
407
421
|
}
|
|
408
422
|
function isViemSigner(signer) {
|
|
409
423
|
return (typeof signer.signTypedData === 'function' &&
|
|
410
424
|
typeof signer.getChainId === 'function');
|
|
411
425
|
}
|
|
412
|
-
function generateSkeletonFromViem(signer) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
};
|
|
457
|
-
});
|
|
426
|
+
async function generateSkeletonFromViem(signer) {
|
|
427
|
+
if (!signer.account) {
|
|
428
|
+
throw new Error('Signer account is not set');
|
|
429
|
+
}
|
|
430
|
+
const address = signer.account['address'];
|
|
431
|
+
const chainId = await signer.getChainId();
|
|
432
|
+
const chain = chainIdToChain(chainId);
|
|
433
|
+
return {
|
|
434
|
+
signerId: `ViemSigner-${address}`,
|
|
435
|
+
account: {
|
|
436
|
+
address,
|
|
437
|
+
chain,
|
|
438
|
+
},
|
|
439
|
+
signMessage: async (data) => {
|
|
440
|
+
const hexSig = await signer.signMessage({
|
|
441
|
+
account: address,
|
|
442
|
+
message: { raw: data },
|
|
443
|
+
});
|
|
444
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
445
|
+
},
|
|
446
|
+
signAndSendTransaction: async (unsignedTx) => {
|
|
447
|
+
// For viem signers, we need to handle transaction signing differently
|
|
448
|
+
// Since the ViemSignerType doesn't have signTransaction, we'll need to
|
|
449
|
+
// use the account's signTransaction method if available
|
|
450
|
+
if (signer.account['signTransaction']) {
|
|
451
|
+
const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
|
|
452
|
+
const txHash = await signer.sendTransaction(tx);
|
|
453
|
+
return (0, viem_1.hexToBytes)(txHash);
|
|
454
|
+
}
|
|
455
|
+
throw new Error('Transaction signing not supported for this viem signer type');
|
|
456
|
+
},
|
|
457
|
+
signTypedData: async ({ domain, types, primaryType, message }) => {
|
|
458
|
+
const hexSig = await signer.signTypedData({
|
|
459
|
+
domain,
|
|
460
|
+
types,
|
|
461
|
+
primaryType,
|
|
462
|
+
message,
|
|
463
|
+
account: signer.account || address,
|
|
464
|
+
});
|
|
465
|
+
return (0, viem_1.hexToBytes)(hexSig);
|
|
466
|
+
},
|
|
467
|
+
// Gated on a local account inside the helper (JSON-RPC accounts → undefined).
|
|
468
|
+
signAuthorization: viemSignAuthorization(signer, address),
|
|
469
|
+
};
|
|
458
470
|
}
|
|
459
471
|
//# sourceMappingURL=signer.js.map
|