@injectivelabs/wallet-core 1.19.0 → 1.19.1
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/index.cjs +51 -0
- package/dist/cjs/index.d.cts +28 -0
- package/dist/esm/index.d.ts +28 -0
- package/dist/esm/index.js +53 -2
- package/package.json +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -357,6 +357,57 @@ var MsgBroadcaster = class {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
|
+
* Sign and broadcast a pre-built transaction whose fee payer signature
|
|
361
|
+
* is already provided (e.g. from the RFQ executor / web3-gw `prepare`
|
|
362
|
+
* endpoint). The taker is signed locally with the supplied private key.
|
|
363
|
+
*
|
|
364
|
+
* Autosign-only: the caller passes the autosign private key directly
|
|
365
|
+
* (e.g. `sharedWalletStore.autoSign.privateKey`). We don't go through
|
|
366
|
+
* `walletStrategy.signCosmosTransaction` because the PK strategy stubs
|
|
367
|
+
* that out — and going through the wallet strategy would defeat the
|
|
368
|
+
* point of autosign (no popups).
|
|
369
|
+
*
|
|
370
|
+
* @param tx Base64-encoded or raw `TxRaw` bytes returned by the prepare endpoint
|
|
371
|
+
* @param feePayerSig Hex (`0x...`) or base64 fee payer signature
|
|
372
|
+
* @param accountNumber Account number of the taker
|
|
373
|
+
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
|
+
* @returns transaction response with txHash
|
|
375
|
+
*/
|
|
376
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber }) {
|
|
377
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks } = this;
|
|
378
|
+
const pk = __injectivelabs_sdk_ts_core_accounts.PrivateKey.fromHex(privateKey);
|
|
379
|
+
if (__injectivelabs_sdk_ts_utils.ofacList.includes(pk.toHex().toLowerCase())) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("You cannot execute this transaction"));
|
|
380
|
+
const txBytes = typeof tx === "string" ? (0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(tx) : tx;
|
|
381
|
+
const txRaw = __injectivelabs_sdk_ts_core_tx.CosmosTxV1Beta1TxPb.TxRaw.fromBinary(txBytes);
|
|
382
|
+
try {
|
|
383
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationStart);
|
|
384
|
+
const signDoc = __injectivelabs_sdk_ts_core_tx.CosmosTxV1Beta1TxPb.SignDoc.create({
|
|
385
|
+
chainId,
|
|
386
|
+
bodyBytes: txRaw.bodyBytes,
|
|
387
|
+
authInfoBytes: txRaw.authInfoBytes,
|
|
388
|
+
accountNumber: BigInt(accountNumber)
|
|
389
|
+
});
|
|
390
|
+
const signDocBytes = __injectivelabs_sdk_ts_core_tx.CosmosTxV1Beta1TxPb.SignDoc.toBinary(signDoc);
|
|
391
|
+
const takerSig = await pk.sign(signDocBytes);
|
|
392
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
393
|
+
txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(feePayerSig.slice(2)) : (0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(feePayerSig)];
|
|
394
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
395
|
+
const txResponse = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRaw, { txTimeout: txTimeoutInBlocks });
|
|
396
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
397
|
+
if (txResponse.code !== 0) throw new __injectivelabs_exceptions.TransactionException(/* @__PURE__ */ new Error(`Transaction failed - ${txResponse.rawLog} - ${txResponse.txHash}`), {
|
|
398
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
399
|
+
contextCode: txResponse.code,
|
|
400
|
+
contextModule: txResponse.codespace
|
|
401
|
+
});
|
|
402
|
+
return txResponse;
|
|
403
|
+
} catch (e) {
|
|
404
|
+
const error = e;
|
|
405
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionFail);
|
|
406
|
+
if ((0, __injectivelabs_exceptions.isThrownException)(error)) throw error;
|
|
407
|
+
throw new __injectivelabs_exceptions.TransactionException(new Error(error));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
360
411
|
* Prepare/sign/broadcast transaction using
|
|
361
412
|
* Ethereum native wallets on the client side.
|
|
362
413
|
*
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -157,6 +157,34 @@ declare class MsgBroadcaster {
|
|
|
157
157
|
* @returns {string} transaction hash
|
|
158
158
|
*/
|
|
159
159
|
broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
160
|
+
/**
|
|
161
|
+
* Sign and broadcast a pre-built transaction whose fee payer signature
|
|
162
|
+
* is already provided (e.g. from the RFQ executor / web3-gw `prepare`
|
|
163
|
+
* endpoint). The taker is signed locally with the supplied private key.
|
|
164
|
+
*
|
|
165
|
+
* Autosign-only: the caller passes the autosign private key directly
|
|
166
|
+
* (e.g. `sharedWalletStore.autoSign.privateKey`). We don't go through
|
|
167
|
+
* `walletStrategy.signCosmosTransaction` because the PK strategy stubs
|
|
168
|
+
* that out — and going through the wallet strategy would defeat the
|
|
169
|
+
* point of autosign (no popups).
|
|
170
|
+
*
|
|
171
|
+
* @param tx Base64-encoded or raw `TxRaw` bytes returned by the prepare endpoint
|
|
172
|
+
* @param feePayerSig Hex (`0x...`) or base64 fee payer signature
|
|
173
|
+
* @param accountNumber Account number of the taker
|
|
174
|
+
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
175
|
+
* @returns transaction response with txHash
|
|
176
|
+
*/
|
|
177
|
+
broadcastWithFeePayerSig({
|
|
178
|
+
tx,
|
|
179
|
+
privateKey,
|
|
180
|
+
feePayerSig,
|
|
181
|
+
accountNumber
|
|
182
|
+
}: {
|
|
183
|
+
privateKey: string;
|
|
184
|
+
feePayerSig: string;
|
|
185
|
+
accountNumber: number;
|
|
186
|
+
tx: Uint8Array | string;
|
|
187
|
+
}): Promise<TxResponse>;
|
|
160
188
|
/**
|
|
161
189
|
* Prepare/sign/broadcast transaction using
|
|
162
190
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -157,6 +157,34 @@ declare class MsgBroadcaster {
|
|
|
157
157
|
* @returns {string} transaction hash
|
|
158
158
|
*/
|
|
159
159
|
broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
160
|
+
/**
|
|
161
|
+
* Sign and broadcast a pre-built transaction whose fee payer signature
|
|
162
|
+
* is already provided (e.g. from the RFQ executor / web3-gw `prepare`
|
|
163
|
+
* endpoint). The taker is signed locally with the supplied private key.
|
|
164
|
+
*
|
|
165
|
+
* Autosign-only: the caller passes the autosign private key directly
|
|
166
|
+
* (e.g. `sharedWalletStore.autoSign.privateKey`). We don't go through
|
|
167
|
+
* `walletStrategy.signCosmosTransaction` because the PK strategy stubs
|
|
168
|
+
* that out — and going through the wallet strategy would defeat the
|
|
169
|
+
* point of autosign (no popups).
|
|
170
|
+
*
|
|
171
|
+
* @param tx Base64-encoded or raw `TxRaw` bytes returned by the prepare endpoint
|
|
172
|
+
* @param feePayerSig Hex (`0x...`) or base64 fee payer signature
|
|
173
|
+
* @param accountNumber Account number of the taker
|
|
174
|
+
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
175
|
+
* @returns transaction response with txHash
|
|
176
|
+
*/
|
|
177
|
+
broadcastWithFeePayerSig({
|
|
178
|
+
tx,
|
|
179
|
+
privateKey,
|
|
180
|
+
feePayerSig,
|
|
181
|
+
accountNumber
|
|
182
|
+
}: {
|
|
183
|
+
privateKey: string;
|
|
184
|
+
feePayerSig: string;
|
|
185
|
+
accountNumber: number;
|
|
186
|
+
tx: Uint8Array | string;
|
|
187
|
+
}): Promise<TxResponse>;
|
|
160
188
|
/**
|
|
161
189
|
* Prepare/sign/broadcast transaction using
|
|
162
190
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.js
CHANGED
|
@@ -2,13 +2,13 @@ import { ChainCosmosErrorCode, GeneralException, TransactionChainErrorModule, Tr
|
|
|
2
2
|
import { EventEmitter } from "eventemitter3";
|
|
3
3
|
import { Wallet, WalletDeviceType, WalletStrategyEmitterEventType, createEip712StdSignDoc, getEthereumSignerAddress, getInjectiveSignerAddress, isCosmosAminoOnlyWallet, isCosmosWallet, isEip712V2OnlyWallet, isEvmBrowserWallet, isEvmWallet } from "@injectivelabs/wallet-base";
|
|
4
4
|
import { EvmChainId } from "@injectivelabs/ts-types";
|
|
5
|
-
import { PublicKey } from "@injectivelabs/sdk-ts/core/accounts";
|
|
5
|
+
import { PrivateKey, PublicKey } from "@injectivelabs/sdk-ts/core/accounts";
|
|
6
6
|
import { base64ToUint8Array, getGasPriceBasedOnMessage, hexToBase64, hexToBuff, hexToUint8Array, ofacList, recoverTypedSignaturePubKey, safeBigIntStringify, uint8ArrayToBase64 } from "@injectivelabs/sdk-ts/utils";
|
|
7
7
|
import { IndexerGrpcWeb3GwApi } from "@injectivelabs/sdk-ts/client/indexer";
|
|
8
8
|
import { getNetworkEndpoints, getNetworkInfo, isMainnet, isTestnet } from "@injectivelabs/networks";
|
|
9
9
|
import { ChainGrpcAuthApi, ChainGrpcTendermintApi, ChainGrpcTxFeesApi } from "@injectivelabs/sdk-ts/client/chain";
|
|
10
10
|
import { DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_GAS_PRICE, getStdFee, sleep, toBigNumber } from "@injectivelabs/utils";
|
|
11
|
-
import { SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
|
|
11
|
+
import { CosmosTxV1Beta1TxPb, SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
|
|
12
12
|
|
|
13
13
|
//#region src/utils/tx.ts
|
|
14
14
|
const checkIfTxRunOutOfGas = (e) => {
|
|
@@ -357,6 +357,57 @@ var MsgBroadcaster = class {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
|
+
* Sign and broadcast a pre-built transaction whose fee payer signature
|
|
361
|
+
* is already provided (e.g. from the RFQ executor / web3-gw `prepare`
|
|
362
|
+
* endpoint). The taker is signed locally with the supplied private key.
|
|
363
|
+
*
|
|
364
|
+
* Autosign-only: the caller passes the autosign private key directly
|
|
365
|
+
* (e.g. `sharedWalletStore.autoSign.privateKey`). We don't go through
|
|
366
|
+
* `walletStrategy.signCosmosTransaction` because the PK strategy stubs
|
|
367
|
+
* that out — and going through the wallet strategy would defeat the
|
|
368
|
+
* point of autosign (no popups).
|
|
369
|
+
*
|
|
370
|
+
* @param tx Base64-encoded or raw `TxRaw` bytes returned by the prepare endpoint
|
|
371
|
+
* @param feePayerSig Hex (`0x...`) or base64 fee payer signature
|
|
372
|
+
* @param accountNumber Account number of the taker
|
|
373
|
+
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
|
+
* @returns transaction response with txHash
|
|
375
|
+
*/
|
|
376
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber }) {
|
|
377
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks } = this;
|
|
378
|
+
const pk = PrivateKey.fromHex(privateKey);
|
|
379
|
+
if (ofacList.includes(pk.toHex().toLowerCase())) throw new GeneralException(/* @__PURE__ */ new Error("You cannot execute this transaction"));
|
|
380
|
+
const txBytes = typeof tx === "string" ? base64ToUint8Array(tx) : tx;
|
|
381
|
+
const txRaw = CosmosTxV1Beta1TxPb.TxRaw.fromBinary(txBytes);
|
|
382
|
+
try {
|
|
383
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
|
|
384
|
+
const signDoc = CosmosTxV1Beta1TxPb.SignDoc.create({
|
|
385
|
+
chainId,
|
|
386
|
+
bodyBytes: txRaw.bodyBytes,
|
|
387
|
+
authInfoBytes: txRaw.authInfoBytes,
|
|
388
|
+
accountNumber: BigInt(accountNumber)
|
|
389
|
+
});
|
|
390
|
+
const signDocBytes = CosmosTxV1Beta1TxPb.SignDoc.toBinary(signDoc);
|
|
391
|
+
const takerSig = await pk.sign(signDocBytes);
|
|
392
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
393
|
+
txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? hexToUint8Array(feePayerSig.slice(2)) : base64ToUint8Array(feePayerSig)];
|
|
394
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
395
|
+
const txResponse = await new TxGrpcApi(endpoints.grpc).broadcast(txRaw, { txTimeout: txTimeoutInBlocks });
|
|
396
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
397
|
+
if (txResponse.code !== 0) throw new TransactionException(/* @__PURE__ */ new Error(`Transaction failed - ${txResponse.rawLog} - ${txResponse.txHash}`), {
|
|
398
|
+
code: UnspecifiedErrorCode,
|
|
399
|
+
contextCode: txResponse.code,
|
|
400
|
+
contextModule: txResponse.codespace
|
|
401
|
+
});
|
|
402
|
+
return txResponse;
|
|
403
|
+
} catch (e) {
|
|
404
|
+
const error = e;
|
|
405
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionFail);
|
|
406
|
+
if (isThrownException(error)) throw error;
|
|
407
|
+
throw new TransactionException(new Error(error));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
360
411
|
* Prepare/sign/broadcast transaction using
|
|
361
412
|
* Ethereum native wallets on the client side.
|
|
362
413
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1",
|
|
4
4
|
"description": "Core wallet strategy",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@keplr-wallet/types": "^0.12.296",
|
|
46
46
|
"eventemitter3": "^5.0.1",
|
|
47
|
-
"@injectivelabs/exceptions": "1.19.
|
|
48
|
-
"@injectivelabs/networks": "1.19.
|
|
49
|
-
"@injectivelabs/sdk-ts": "1.19.
|
|
50
|
-
"@injectivelabs/ts-types": "1.19.
|
|
51
|
-
"@injectivelabs/utils": "1.19.
|
|
52
|
-
"@injectivelabs/wallet-base": "1.19.
|
|
47
|
+
"@injectivelabs/exceptions": "1.19.1",
|
|
48
|
+
"@injectivelabs/networks": "1.19.1",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.19.1",
|
|
50
|
+
"@injectivelabs/ts-types": "1.19.1",
|
|
51
|
+
"@injectivelabs/utils": "1.19.1",
|
|
52
|
+
"@injectivelabs/wallet-base": "1.19.1"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|