@pushchain/core 6.0.19 → 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.
Files changed (112) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/package.json +1 -1
  3. package/src/lib/cache/cache.js +2 -0
  4. package/src/lib/constants/abi/index.d.ts +1 -0
  5. package/src/lib/constants/abi/index.js +8 -1
  6. package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
  7. package/src/lib/constants/abi/pc20.evm.js +150 -0
  8. package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
  9. package/src/lib/constants/abi/prc20.evm.js +97 -0
  10. package/src/lib/constants/abi/universalGatewayV0.json +1 -1
  11. package/src/lib/constants/chain.js +38 -8
  12. package/src/lib/constants/selectors.js +2 -2
  13. package/src/lib/constants/tokens.js +4 -3
  14. package/src/lib/formatters.js +16 -6
  15. package/src/lib/generated/uexecutor/v1/query.js +2 -4
  16. package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
  17. package/src/lib/generated/uexecutor/v1/types.js +90 -47
  18. package/src/lib/generated/uexecutor/v2/query.js +2 -4
  19. package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
  20. package/src/lib/generated/uexecutor/v2/types.js +49 -33
  21. package/src/lib/generated/v1/tx.js +30 -37
  22. package/src/lib/index.d.ts +4 -1
  23. package/src/lib/index.js +21 -3
  24. package/src/lib/internal/buffer.js +1 -2
  25. package/src/lib/orchestrator/cea-utils.js +73 -83
  26. package/src/lib/orchestrator/internals/account-manager.js +130 -139
  27. package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
  28. package/src/lib/orchestrator/internals/cascade.js +1184 -1059
  29. package/src/lib/orchestrator/internals/confirmation.js +138 -148
  30. package/src/lib/orchestrator/internals/error-decoder.js +1 -1
  31. package/src/lib/orchestrator/internals/errors.js +12 -3
  32. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
  33. package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
  34. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
  35. package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
  36. package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
  37. package/src/lib/orchestrator/internals/execute-standard.js +339 -342
  38. package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
  39. package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
  40. package/src/lib/orchestrator/internals/gateway-client.js +102 -103
  41. package/src/lib/orchestrator/internals/helpers.js +30 -27
  42. package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
  43. package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
  44. package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
  45. package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
  46. package/src/lib/orchestrator/internals/payload-builder.js +119 -100
  47. package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
  48. package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
  49. package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
  50. package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
  51. package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
  52. package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
  53. package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
  54. package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
  55. package/src/lib/orchestrator/internals/pc20/export.js +412 -0
  56. package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
  57. package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
  58. package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
  59. package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
  60. package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
  61. package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
  62. package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
  63. package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
  64. package/src/lib/orchestrator/internals/preflight.js +1 -1
  65. package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
  66. package/src/lib/orchestrator/internals/push-chain-tx.js +319 -331
  67. package/src/lib/orchestrator/internals/quote.js +90 -94
  68. package/src/lib/orchestrator/internals/rescue.js +76 -79
  69. package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
  70. package/src/lib/orchestrator/internals/response-builder.js +817 -701
  71. package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
  72. package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
  73. package/src/lib/orchestrator/internals/signing.js +78 -83
  74. package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
  75. package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
  76. package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
  77. package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
  78. package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
  79. package/src/lib/orchestrator/internals/svm-rent.js +163 -141
  80. package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
  81. package/src/lib/orchestrator/internals/uea-manager.js +89 -86
  82. package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
  83. package/src/lib/orchestrator/orchestrator.js +217 -200
  84. package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
  85. package/src/lib/orchestrator/orchestrator.types.js +19 -0
  86. package/src/lib/orchestrator/payload-builders.d.ts +2 -2
  87. package/src/lib/orchestrator/payload-builders.js +26 -24
  88. package/src/lib/orchestrator/route-detector.js +26 -9
  89. package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
  90. package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
  91. package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
  92. package/src/lib/price-fetch/price-fetch.js +67 -68
  93. package/src/lib/progress-hook/progress-hook.js +124 -72
  94. package/src/lib/push-chain/push-chain.js +171 -153
  95. package/src/lib/push-client/push-client.js +223 -237
  96. package/src/lib/universal/account/account.js +349 -365
  97. package/src/lib/universal/signer/signer.d.ts +2 -1
  98. package/src/lib/universal/signer/signer.js +315 -299
  99. package/src/lib/universal-tx-detector/auto-detect.js +55 -60
  100. package/src/lib/universal-tx-detector/cascade.js +160 -172
  101. package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
  102. package/src/lib/universal-tx-detector/classify.js +2 -3
  103. package/src/lib/universal-tx-detector/detector-svm.js +139 -147
  104. package/src/lib/universal-tx-detector/detector.js +145 -157
  105. package/src/lib/universal-tx-detector/normalize.js +7 -7
  106. package/src/lib/utils/external-tx-hash.js +1 -2
  107. package/src/lib/utils.d.ts +44 -0
  108. package/src/lib/utils.js +762 -683
  109. package/src/lib/vm-client/evm-client.js +186 -202
  110. package/src/lib/vm-client/svm-client.d.ts +1 -1
  111. package/src/lib/vm-client/svm-client.js +220 -224
  112. 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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- if (!_nacl)
13
- _nacl = yield Promise.resolve().then(() => tslib_1.__importStar(require('tweetnacl')));
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 _a = viemTx, { gas, type, authorizationList } = _a, rest = tslib_1.__rest(_a, ["gas", "type", "authorizationList"]);
32
- const out = Object.assign(Object.assign({}, rest), { gasLimit: gas });
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
- var _a;
37
- return ({
38
- address: (_a = a.address) !== null && _a !== void 0 ? _a : a.contractAddress,
39
- chainId: a.chainId,
40
- nonce: a.nonce,
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 === null || wallet === void 0 ? void 0 : wallet.account;
73
+ const account = wallet?.account;
57
74
  if (!account || typeof account.signAuthorization !== 'function') {
58
75
  return undefined;
59
76
  }
60
- return (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ contractAddress, chainId, nonce, executor }) {
61
- const auth = yield wallet.signAuthorization(Object.assign(Object.assign(Object.assign({ account: account || address, contractAddress }, (chainId !== undefined ? { chainId } : {})), (nonce !== undefined ? { nonce } : {})), (executor ? { executor } : {})));
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 (wallet === null || wallet === void 0 ? void 0 : wallet.authorize) !== 'function')
96
+ if (typeof wallet?.authorize !== 'function')
74
97
  return undefined;
75
- return (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ contractAddress, chainId, nonce }) {
76
- var _b, _c, _d;
77
- const cid = chainId !== null && chainId !== void 0 ? chainId : Number(chain.split(':')[1]);
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 !== null && nonce !== void 0 ? nonce : 0,
103
+ nonce: nonce ?? 0,
82
104
  });
83
105
  const sig = auth.signature;
84
106
  return {
85
107
  address: contractAddress,
86
- chainId: Number((_b = auth.chainId) !== null && _b !== void 0 ? _b : cid),
87
- nonce: Number((_d = (_c = auth.nonce) !== null && _c !== void 0 ? _c : nonce) !== null && _d !== void 0 ? _d : 0),
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,303 +175,297 @@ 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(clientOrAccount_1, _a) {
157
- return tslib_1.__awaiter(this, arguments, void 0, function* (clientOrAccount, { chain, library }) {
158
- let address;
159
- let signMessage;
160
- let signAndSendTransaction;
161
- let signTypedData;
162
- // Optional: only set for EVM wallets that support EIP-7702 authorization
163
- // signing. Left undefined for Solana and wallets without 7702 support, in
164
- // which case callers fall back to a non-7702 path.
165
- let signAuthorization;
166
- // Check if signer has UID='custom', then we take signMessage, signAndSendTransaction, signTypedData, chain and address from the CustomUniversalSigner.
167
- // If ViemSigner, convert ViemSigner to UniversalSigner.
168
- switch (library) {
169
- case enums_1.LIBRARY.ETHEREUM_ETHERSV6: {
170
- if (typeof clientOrAccount.signMessage !== 'function' ||
171
- typeof clientOrAccount.sendTransaction !== 'function' ||
172
- typeof clientOrAccount.getAddress !== 'function') {
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
- case enums_1.LIBRARY.ETHEREUM_VIEM: {
208
- const wallet = clientOrAccount;
209
- address = (yield wallet.getAddresses())[0];
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
- case enums_1.LIBRARY.SOLANA_WEB3JS: {
239
- const keypair = clientOrAccount;
240
- if (chain !== enums_1.CHAIN.SOLANA_MAINNET &&
241
- chain !== enums_1.CHAIN.SOLANA_TESTNET &&
242
- chain !== enums_1.CHAIN.SOLANA_DEVNET) {
243
- throw new Error('Invalid chain for Solana Keypair');
244
- }
245
- address = keypair.publicKey.toBase58();
246
- signMessage = (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
247
- const nacl = yield getNacl();
248
- return nacl.sign.detached(data, keypair.secretKey);
249
- });
250
- // ✅ Sign and send the transaction to Solana network
251
- signAndSendTransaction = (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
252
- const endpoint = chain_1.CHAIN_INFO[chain].defaultRPC[0];
253
- const connection = new web3_js_1.Connection(endpoint, 'confirmed');
254
- let txHash;
255
- // Detect if this is a versioned transaction by looking at the message portion.
256
- // Transaction format: [signature_count (compact-u16)][signatures][message]
257
- // For versioned messages, the first byte of the message has high bit set (>= 0x80)
258
- // Read signature count - if < 0x80, it's a single byte count
259
- let sigOffset = 1;
260
- const sigCount = unsignedTx[0];
261
- if (sigCount >= 0x80) {
262
- // Two-byte compact-u16 encoding
263
- sigOffset = 2;
264
- }
265
- // Skip past signatures (64 bytes each) to get to the message
266
- const messageOffset = sigOffset + sigCount * 64;
267
- const isVersionedTx = unsignedTx[messageOffset] >= 0x80;
268
- if (isVersionedTx) {
269
- // Handle as versioned transaction (v0)
270
- const vtx = web3_js_1.VersionedTransaction.deserialize(unsignedTx);
271
- vtx.sign([keypair]);
272
- const rawVtx = vtx.serialize();
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
- signTypedData = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
288
- throw new Error('Typed data signing is not supported for Solana');
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
- break;
291
- }
292
- default: {
293
- throw new Error(`Unsupported library: ${library}`);
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
- const universalSigner = {
297
- account: {
298
- address,
299
- chain,
300
- },
301
- signMessage,
302
- signAndSendTransaction,
303
- signTypedData,
304
- signAuthorization,
305
- };
306
- return createUniversalSigner(universalSigner);
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) {
311
- const { signMessage, signAndSendTransaction, signTypedData } = options;
312
- if (signTypedData &&
313
- (account.chain === enums_1.CHAIN.SOLANA_MAINNET ||
314
- account.chain === enums_1.CHAIN.SOLANA_TESTNET ||
315
- account.chain === enums_1.CHAIN.SOLANA_DEVNET)) {
331
+ const { signMessage, signAndSendTransaction, signTypedData, signAuthorization, } = options;
332
+ const isSolana = account.chain === enums_1.CHAIN.SOLANA_MAINNET ||
333
+ account.chain === enums_1.CHAIN.SOLANA_TESTNET ||
334
+ account.chain === enums_1.CHAIN.SOLANA_DEVNET;
335
+ if (signTypedData && isSolana) {
316
336
  throw new Error('Typed data signing is not supported for Solana');
317
337
  }
338
+ if (signAuthorization && isSolana) {
339
+ throw new Error('EIP-7702 authorization is not supported for Solana');
340
+ }
318
341
  return {
319
342
  signerId: 'CustomGeneratedSigner',
320
343
  account,
321
344
  signMessage,
322
345
  signAndSendTransaction,
323
346
  signTypedData,
347
+ signAuthorization,
324
348
  };
325
349
  }
326
- function toUniversal(signer) {
327
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
328
- if ('signerId' in signer) {
329
- return createUniversalSigner(signer);
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');
330
359
  }
331
- let skeleton;
332
- if (!isViemSigner(signer)) {
333
- const wallet = signer;
334
- if (!wallet.provider) {
335
- throw new Error('ethers.Wallet must have a provider attached to determine chain');
336
- }
337
- // Check if _signTypedData property is present to determine if it's EthersV5 or EthersV6
338
- if ('_signTypedData' in wallet) {
339
- skeleton = yield generateSkeletonFromEthersV5(wallet);
340
- }
341
- else {
342
- skeleton = yield generateSkeletonFromEthersV6(wallet);
343
- }
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);
344
363
  }
345
364
  else {
346
- skeleton = yield generateSkeletonFromViem(signer);
365
+ skeleton = await generateSkeletonFromEthersV6(wallet);
347
366
  }
348
- return createUniversalSigner(skeleton);
349
- });
367
+ }
368
+ else {
369
+ skeleton = await generateSkeletonFromViem(signer);
370
+ }
371
+ return createUniversalSigner(skeleton);
350
372
  }
351
- function generateSkeletonFromEthersV5(signer) {
352
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
353
- const address = yield signer.getAddress();
354
- const { chainId } = yield signer.provider.getNetwork();
355
- const chain = chainIdToChain(chainId);
356
- return {
357
- signerId: `EthersSignerV5-${address}`,
358
- account: { address, chain },
359
- signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
360
- const sigHex = yield signer.signMessage(data);
361
- return (0, viem_1.hexToBytes)(sigHex);
362
- }),
363
- // raw unsigned tx bytes → hex → parse → signTransaction → bytes
364
- signAndSendTransaction: (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
365
- const unsignedHex = (0, viem_1.bytesToHex)(raw);
366
- const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
367
- const txResponse = yield signer.sendTransaction(tx);
368
- return (0, viem_1.hexToBytes)(txResponse.hash);
369
- }),
370
- signTypedData: (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
371
- const sigHex = yield signer._signTypedData(domain, types, message);
372
- return (0, viem_1.hexToBytes)(sigHex);
373
- }),
374
- };
375
- });
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
+ };
376
396
  }
377
- function generateSkeletonFromEthersV6(signer) {
378
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
379
- const address = yield signer.getAddress();
380
- const { chainId } = yield signer.provider.getNetwork();
381
- const chain = chainIdToChain(chainId);
382
- return {
383
- signerId: `EthersSignerV6-${address}`,
384
- account: { address, chain },
385
- signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
386
- const sigHex = yield signer.signMessage(data);
387
- return (0, viem_1.hexToBytes)(sigHex);
388
- }),
389
- // raw unsigned tx bytes → hex → parse → signTransaction → bytes
390
- signAndSendTransaction: (raw) => tslib_1.__awaiter(this, void 0, void 0, function* () {
391
- const unsignedHex = (0, viem_1.bytesToHex)(raw);
392
- const tx = toEthersTxRequest((0, viem_1.parseTransaction)(unsignedHex));
393
- const txResponse = yield signer.sendTransaction(tx);
394
- return (0, viem_1.hexToBytes)(txResponse.hash);
395
- }),
396
- signTypedData: (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
397
- const sigHex = yield signer.signTypedData(domain, types, message);
398
- return (0, viem_1.hexToBytes)(sigHex);
399
- }),
400
- signAuthorization: ethersSignAuthorization(signer, chain),
401
- };
402
- });
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
+ };
403
421
  }
404
422
  function isViemSigner(signer) {
405
423
  return (typeof signer.signTypedData === 'function' &&
406
424
  typeof signer.getChainId === 'function');
407
425
  }
408
- function generateSkeletonFromViem(signer) {
409
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
410
- if (!signer.account) {
411
- throw new Error('Signer account is not set');
412
- }
413
- const address = signer.account['address'];
414
- const chainId = yield signer.getChainId();
415
- const chain = chainIdToChain(chainId);
416
- return {
417
- signerId: `ViemSigner-${address}`,
418
- account: {
419
- address,
420
- chain,
421
- },
422
- signMessage: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
423
- const hexSig = yield signer.signMessage({
424
- account: address,
425
- message: { raw: data },
426
- });
427
- return (0, viem_1.hexToBytes)(hexSig);
428
- }),
429
- signAndSendTransaction: (unsignedTx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
430
- // For viem signers, we need to handle transaction signing differently
431
- // Since the ViemSignerType doesn't have signTransaction, we'll need to
432
- // use the account's signTransaction method if available
433
- if (signer.account['signTransaction']) {
434
- const tx = (0, viem_1.parseTransaction)((0, viem_1.bytesToHex)(unsignedTx));
435
- const txHash = yield signer.sendTransaction(tx);
436
- return (0, viem_1.hexToBytes)(txHash);
437
- }
438
- throw new Error('Transaction signing not supported for this viem signer type');
439
- }),
440
- signTypedData: (_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ domain, types, primaryType, message }) {
441
- const hexSig = yield signer.signTypedData({
442
- domain,
443
- types,
444
- primaryType,
445
- message,
446
- account: signer.account || address,
447
- });
448
- return (0, viem_1.hexToBytes)(hexSig);
449
- }),
450
- // Gated on a local account inside the helper (JSON-RPC accounts → undefined).
451
- signAuthorization: viemSignAuthorization(signer, address),
452
- };
453
- });
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
+ };
454
470
  }
455
471
  //# sourceMappingURL=signer.js.map