@injectivelabs/wallet-private-key 1.20.11 → 1.20.12

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.
@@ -188,4 +188,57 @@ var PrivateKeyWallet = class extends __injectivelabs_wallet_base.BaseConcreteStr
188
188
  };
189
189
 
190
190
  //#endregion
191
+ //#region src/strategy/strategy-cosmos.ts
192
+ var PrivateKeyCosmosWallet = class extends PrivateKeyWallet {
193
+ async sendTransaction(transaction, options) {
194
+ const { endpoints, txTimeout, txInclusion, onBroadcast } = options;
195
+ if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options for using Ethereum native wallets"));
196
+ const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(transaction);
197
+ const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
198
+ txTimeout,
199
+ ...txInclusion,
200
+ onBroadcast
201
+ });
202
+ if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
203
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
204
+ contextCode: response.code,
205
+ contextModule: response.codespace
206
+ });
207
+ return response;
208
+ }
209
+ async signCosmosTransaction(transaction) {
210
+ const privateKey = this.getPrivateKey();
211
+ const publicKey = privateKey.toPublicKey();
212
+ const injectiveAddress = privateKey.toAddress().toBech32();
213
+ if (transaction.address !== injectiveAddress) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
214
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
215
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
216
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
217
+ });
218
+ try {
219
+ const signDoc = (0, __injectivelabs_sdk_ts_core_tx.createSignDocFromTransaction)(transaction);
220
+ const signBytes = __injectivelabs_sdk_ts_core_tx.CosmosTxV1Beta1TxPb.SignDoc.toBinary(signDoc);
221
+ const signature = await privateKey.sign(signBytes);
222
+ return {
223
+ signed: signDoc,
224
+ signature: {
225
+ pub_key: {
226
+ type: "tendermint/PubKeyEthSecp256k1",
227
+ value: publicKey.toBase64()
228
+ },
229
+ signature: (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)(signature)
230
+ }
231
+ };
232
+ } catch (e) {
233
+ throw new __injectivelabs_exceptions.WalletException(new Error(e.message), {
234
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
235
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
236
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
237
+ });
238
+ }
239
+ }
240
+ };
241
+
242
+ //#endregion
243
+ exports.PrivateKeyCosmosWalletStrategy = PrivateKeyCosmosWallet;
191
244
  exports.PrivateKeyWalletStrategy = PrivateKeyWallet;
@@ -1,4 +1,5 @@
1
1
  import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
2
+ import { PrivateKey } from "@injectivelabs/sdk-ts/core/accounts";
2
3
  import { BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
3
4
  import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
4
5
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
@@ -38,7 +39,18 @@ declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteW
38
39
  getPubKey(): Promise<string>;
39
40
  onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
40
41
  onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
41
- private getPrivateKey;
42
+ protected getPrivateKey(): PrivateKey;
42
43
  }
43
44
  //#endregion
44
- export { PrivateKeyWallet as PrivateKeyWalletStrategy };
45
+ //#region src/strategy/strategy-cosmos.d.ts
46
+ declare class PrivateKeyCosmosWallet extends PrivateKeyWallet implements ConcreteWalletStrategy {
47
+ sendTransaction(transaction: TxRaw | DirectSignResponse, options: SendTransactionOptions): Promise<TxResponse>;
48
+ signCosmosTransaction(transaction: {
49
+ txRaw: TxRaw;
50
+ accountNumber: number;
51
+ chainId: string;
52
+ address: string;
53
+ }): Promise<DirectSignResponse>;
54
+ }
55
+ //#endregion
56
+ export { PrivateKeyCosmosWallet as PrivateKeyCosmosWalletStrategy, PrivateKeyWallet as PrivateKeyWalletStrategy };
@@ -1,4 +1,5 @@
1
1
  import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
2
+ import { PrivateKey } from "@injectivelabs/sdk-ts/core/accounts";
2
3
  import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
3
4
  import { BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
4
5
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
@@ -38,7 +39,18 @@ declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteW
38
39
  getPubKey(): Promise<string>;
39
40
  onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
40
41
  onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
41
- private getPrivateKey;
42
+ protected getPrivateKey(): PrivateKey;
42
43
  }
43
44
  //#endregion
44
- export { PrivateKeyWallet as PrivateKeyWalletStrategy };
45
+ //#region src/strategy/strategy-cosmos.d.ts
46
+ declare class PrivateKeyCosmosWallet extends PrivateKeyWallet implements ConcreteWalletStrategy {
47
+ sendTransaction(transaction: TxRaw | DirectSignResponse, options: SendTransactionOptions): Promise<TxResponse>;
48
+ signCosmosTransaction(transaction: {
49
+ txRaw: TxRaw;
50
+ accountNumber: number;
51
+ chainId: string;
52
+ address: string;
53
+ }): Promise<DirectSignResponse>;
54
+ }
55
+ //#endregion
56
+ export { PrivateKeyCosmosWallet as PrivateKeyCosmosWalletStrategy, PrivateKeyWallet as PrivateKeyWalletStrategy };
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ChainId, EvmChainId } from "@injectivelabs/ts-types";
2
2
  import { PrivateKey } from "@injectivelabs/sdk-ts/core/accounts";
3
- import { TxGrpcApi, getInjectiveSignerAddress } from "@injectivelabs/sdk-ts/core/tx";
3
+ import { CosmosTxV1Beta1TxPb, TxGrpcApi, createSignDocFromTransaction, createTxRawFromSigResponse, getInjectiveSignerAddress } from "@injectivelabs/sdk-ts/core/tx";
4
4
  import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
5
5
  import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
6
6
  import { ErrorType, MetamaskException, TransactionException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
@@ -188,4 +188,56 @@ var PrivateKeyWallet = class extends BaseConcreteStrategy {
188
188
  };
189
189
 
190
190
  //#endregion
191
- export { PrivateKeyWallet as PrivateKeyWalletStrategy };
191
+ //#region src/strategy/strategy-cosmos.ts
192
+ var PrivateKeyCosmosWallet = class extends PrivateKeyWallet {
193
+ async sendTransaction(transaction, options) {
194
+ const { endpoints, txTimeout, txInclusion, onBroadcast } = options;
195
+ if (!endpoints) throw new WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options for using Ethereum native wallets"));
196
+ const txRaw = createTxRawFromSigResponse(transaction);
197
+ const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
198
+ txTimeout,
199
+ ...txInclusion,
200
+ onBroadcast
201
+ });
202
+ if (response.code !== 0) throw new TransactionException(new Error(response.rawLog), {
203
+ code: UnspecifiedErrorCode,
204
+ contextCode: response.code,
205
+ contextModule: response.codespace
206
+ });
207
+ return response;
208
+ }
209
+ async signCosmosTransaction(transaction) {
210
+ const privateKey = this.getPrivateKey();
211
+ const publicKey = privateKey.toPublicKey();
212
+ const injectiveAddress = privateKey.toAddress().toBech32();
213
+ if (transaction.address !== injectiveAddress) throw new WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
214
+ code: UnspecifiedErrorCode,
215
+ type: ErrorType.WalletError,
216
+ contextModule: WalletAction.SignTransaction
217
+ });
218
+ try {
219
+ const signDoc = createSignDocFromTransaction(transaction);
220
+ const signBytes = CosmosTxV1Beta1TxPb.SignDoc.toBinary(signDoc);
221
+ const signature = await privateKey.sign(signBytes);
222
+ return {
223
+ signed: signDoc,
224
+ signature: {
225
+ pub_key: {
226
+ type: "tendermint/PubKeyEthSecp256k1",
227
+ value: publicKey.toBase64()
228
+ },
229
+ signature: uint8ArrayToBase64(signature)
230
+ }
231
+ };
232
+ } catch (e) {
233
+ throw new WalletException(new Error(e.message), {
234
+ code: UnspecifiedErrorCode,
235
+ type: ErrorType.WalletError,
236
+ contextModule: WalletAction.SignTransaction
237
+ });
238
+ }
239
+ }
240
+ };
241
+
242
+ //#endregion
243
+ export { PrivateKeyCosmosWallet as PrivateKeyCosmosWalletStrategy, PrivateKeyWallet as PrivateKeyWalletStrategy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-private-key",
3
- "version": "1.20.11",
3
+ "version": "1.20.12",
4
4
  "description": "Private key wallet strategy for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -42,10 +42,10 @@
42
42
  "dist"
43
43
  ],
44
44
  "dependencies": {
45
- "@injectivelabs/exceptions": "1.20.11",
46
- "@injectivelabs/sdk-ts": "1.20.11",
47
- "@injectivelabs/wallet-base": "1.20.11",
48
- "@injectivelabs/ts-types": "1.20.11"
45
+ "@injectivelabs/exceptions": "1.20.12",
46
+ "@injectivelabs/ts-types": "1.20.12",
47
+ "@injectivelabs/sdk-ts": "1.20.12",
48
+ "@injectivelabs/wallet-base": "1.20.12"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"