@injectivelabs/wallet-private-key 1.16.24 → 1.16.25-alpha.0

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.
@@ -0,0 +1,178 @@
1
+ let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
2
+ let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
3
+ let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
4
+ let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
5
+
6
+ //#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
10
+ return typeof o$1;
11
+ } : function(o$1) {
12
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
13
+ }, _typeof(o);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
18
+ function toPrimitive(t, r) {
19
+ if ("object" != _typeof(t) || !t) return t;
20
+ var e = t[Symbol.toPrimitive];
21
+ if (void 0 !== e) {
22
+ var i = e.call(t, r || "default");
23
+ if ("object" != _typeof(i)) return i;
24
+ throw new TypeError("@@toPrimitive must return a primitive value.");
25
+ }
26
+ return ("string" === r ? String : Number)(t);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
31
+ function toPropertyKey(t) {
32
+ var i = toPrimitive(t, "string");
33
+ return "symbol" == _typeof(i) ? i : i + "";
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/strategy/strategy.ts
49
+ var PrivateKeyWallet = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
50
+ constructor(..._args) {
51
+ super(..._args);
52
+ _defineProperty(this, "privateKey", void 0);
53
+ }
54
+ async getWalletDeviceType() {
55
+ return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Other);
56
+ }
57
+ async enable() {
58
+ return Promise.resolve(true);
59
+ }
60
+ async disconnect() {
61
+ this.listeners = {};
62
+ }
63
+ async getAddresses() {
64
+ const pk = this.getPrivateKey();
65
+ try {
66
+ return Promise.resolve([pk.toAddress().toHex()]);
67
+ } catch (e) {
68
+ throw new __injectivelabs_exceptions.MetamaskException(new Error(e.message), {
69
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
70
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
71
+ contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
72
+ });
73
+ }
74
+ }
75
+ async getSessionOrConfirm(address) {
76
+ return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
77
+ }
78
+ async sendEvmTransaction(_transaction, _options) {
79
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support sending Evm transactions"), {
80
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
81
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
82
+ contextModule: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
83
+ });
84
+ }
85
+ async sendTransaction(transaction, options) {
86
+ const { endpoints, txTimeout } = options;
87
+ if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options for using Ethereum native wallets"));
88
+ const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
89
+ if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
90
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
91
+ contextCode: response.code,
92
+ contextModule: response.codespace
93
+ });
94
+ return response;
95
+ }
96
+ async signEip712TypedData(eip712json, address) {
97
+ const pk = this.getPrivateKey();
98
+ if ((0, __injectivelabs_sdk_ts.getInjectiveSignerAddress)(address) !== pk.toAddress().toBech32()) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
99
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
100
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
101
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
102
+ });
103
+ try {
104
+ return `0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)(await pk.signTypedData(JSON.parse(eip712json)))}`;
105
+ } catch (e) {
106
+ throw new __injectivelabs_exceptions.MetamaskException(new Error(e.message), {
107
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
108
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
109
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
110
+ });
111
+ }
112
+ }
113
+ async signAminoCosmosTransaction(_transaction) {
114
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
115
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
116
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
117
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
118
+ });
119
+ }
120
+ async signCosmosTransaction(_transaction) {
121
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
122
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
123
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
124
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
125
+ });
126
+ }
127
+ async signArbitrary(signer, data) {
128
+ const pk = this.getPrivateKey();
129
+ if ((0, __injectivelabs_sdk_ts.getInjectiveSignerAddress)(signer) !== pk.toAddress().toBech32()) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
130
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
131
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
132
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignArbitrary
133
+ });
134
+ try {
135
+ return `0x${(0, __injectivelabs_sdk_ts.uint8ArrayToBase64)(await pk.signHashed((0, __injectivelabs_sdk_ts.stringToUint8Array)((0, __injectivelabs_sdk_ts.toUtf8)(data))))}`;
136
+ } catch (e) {
137
+ throw new __injectivelabs_exceptions.MetamaskException(new Error(e.message), {
138
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
139
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
140
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignArbitrary
141
+ });
142
+ }
143
+ }
144
+ async getEthereumChainId() {
145
+ try {
146
+ return Promise.resolve((this.chainId === __injectivelabs_ts_types.ChainId.Mainnet ? __injectivelabs_ts_types.EvmChainId.Mainnet : __injectivelabs_ts_types.EvmChainId.Sepolia).toString(16));
147
+ } catch (e) {
148
+ throw new __injectivelabs_exceptions.MetamaskException(new Error(e.message), {
149
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
150
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
151
+ contextModule: __injectivelabs_wallet_base.WalletAction.GetChainId
152
+ });
153
+ }
154
+ }
155
+ async getEvmTransactionReceipt(_txHash) {
156
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Not supported"));
157
+ }
158
+ async getPubKey() {
159
+ return this.getPrivateKey().toPublicKey().toBase64();
160
+ }
161
+ async onChainIdChanged(_callback) {}
162
+ async onAccountChange(_callback) {}
163
+ getPrivateKey() {
164
+ if (!this.privateKey) {
165
+ var _this$metadata;
166
+ if (!((_this$metadata = this.metadata) === null || _this$metadata === void 0 || (_this$metadata = _this$metadata.privateKey) === null || _this$metadata === void 0 ? void 0 : _this$metadata.privateKey)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Please provide private key in the constructor"), {
167
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
168
+ type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
169
+ contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
170
+ });
171
+ this.privateKey = __injectivelabs_sdk_ts.PrivateKey.fromHex(this.metadata.privateKey.privateKey);
172
+ }
173
+ return this.privateKey;
174
+ }
175
+ };
176
+
177
+ //#endregion
178
+ exports.PrivateKeyWalletStrategy = PrivateKeyWallet;
@@ -0,0 +1,38 @@
1
+ import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
2
+ import { BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
3
+ import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
4
+
5
+ //#region src/strategy/strategy.d.ts
6
+ declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
7
+ private privateKey?;
8
+ getWalletDeviceType(): Promise<WalletDeviceType>;
9
+ enable(): Promise<boolean>;
10
+ disconnect(): Promise<void>;
11
+ getAddresses(): Promise<string[]>;
12
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
13
+ sendEvmTransaction(_transaction: unknown, _options: {
14
+ address: AccountAddress;
15
+ evmChainId: EvmChainId;
16
+ }): Promise<string>;
17
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
18
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
19
+ signAminoCosmosTransaction(_transaction: {
20
+ address: string;
21
+ signDoc: StdSignDoc;
22
+ }): Promise<AminoSignResponse>;
23
+ signCosmosTransaction(_transaction: {
24
+ txRaw: TxRaw;
25
+ accountNumber: number;
26
+ chainId: string;
27
+ address: string;
28
+ }): Promise<DirectSignResponse>;
29
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
30
+ getEthereumChainId(): Promise<string>;
31
+ getEvmTransactionReceipt(_txHash: string): Promise<string>;
32
+ getPubKey(): Promise<string>;
33
+ onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
34
+ onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
35
+ private getPrivateKey;
36
+ }
37
+ //#endregion
38
+ export { PrivateKeyWallet as PrivateKeyWalletStrategy };
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -1 +1,38 @@
1
- export { PrivateKeyWallet as PrivateKeyWalletStrategy } from './strategy/strategy.js';
1
+ import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
2
+ import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
3
+ import { BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
4
+
5
+ //#region src/strategy/strategy.d.ts
6
+ declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
7
+ private privateKey?;
8
+ getWalletDeviceType(): Promise<WalletDeviceType>;
9
+ enable(): Promise<boolean>;
10
+ disconnect(): Promise<void>;
11
+ getAddresses(): Promise<string[]>;
12
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
13
+ sendEvmTransaction(_transaction: unknown, _options: {
14
+ address: AccountAddress;
15
+ evmChainId: EvmChainId;
16
+ }): Promise<string>;
17
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
18
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
19
+ signAminoCosmosTransaction(_transaction: {
20
+ address: string;
21
+ signDoc: StdSignDoc;
22
+ }): Promise<AminoSignResponse>;
23
+ signCosmosTransaction(_transaction: {
24
+ txRaw: TxRaw;
25
+ accountNumber: number;
26
+ chainId: string;
27
+ address: string;
28
+ }): Promise<DirectSignResponse>;
29
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
30
+ getEthereumChainId(): Promise<string>;
31
+ getEvmTransactionReceipt(_txHash: string): Promise<string>;
32
+ getPubKey(): Promise<string>;
33
+ onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
34
+ onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
35
+ private getPrivateKey;
36
+ }
37
+ //#endregion
38
+ export { PrivateKeyWallet as PrivateKeyWalletStrategy };
package/dist/esm/index.js CHANGED
@@ -1 +1,178 @@
1
- export { PrivateKeyWallet as PrivateKeyWalletStrategy } from './strategy/strategy.js';
1
+ import { PrivateKey, TxGrpcApi, getInjectiveSignerAddress, stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts";
2
+ import { ChainId, EvmChainId } from "@injectivelabs/ts-types";
3
+ import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
4
+ import { ErrorType, MetamaskException, TransactionException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
5
+
6
+ //#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
10
+ return typeof o$1;
11
+ } : function(o$1) {
12
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
13
+ }, _typeof(o);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
18
+ function toPrimitive(t, r) {
19
+ if ("object" != _typeof(t) || !t) return t;
20
+ var e = t[Symbol.toPrimitive];
21
+ if (void 0 !== e) {
22
+ var i = e.call(t, r || "default");
23
+ if ("object" != _typeof(i)) return i;
24
+ throw new TypeError("@@toPrimitive must return a primitive value.");
25
+ }
26
+ return ("string" === r ? String : Number)(t);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
31
+ function toPropertyKey(t) {
32
+ var i = toPrimitive(t, "string");
33
+ return "symbol" == _typeof(i) ? i : i + "";
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/strategy/strategy.ts
49
+ var PrivateKeyWallet = class extends BaseConcreteStrategy {
50
+ constructor(..._args) {
51
+ super(..._args);
52
+ _defineProperty(this, "privateKey", void 0);
53
+ }
54
+ async getWalletDeviceType() {
55
+ return Promise.resolve(WalletDeviceType.Other);
56
+ }
57
+ async enable() {
58
+ return Promise.resolve(true);
59
+ }
60
+ async disconnect() {
61
+ this.listeners = {};
62
+ }
63
+ async getAddresses() {
64
+ const pk = this.getPrivateKey();
65
+ try {
66
+ return Promise.resolve([pk.toAddress().toHex()]);
67
+ } catch (e) {
68
+ throw new MetamaskException(new Error(e.message), {
69
+ code: UnspecifiedErrorCode,
70
+ type: ErrorType.WalletError,
71
+ contextModule: WalletAction.GetAccounts
72
+ });
73
+ }
74
+ }
75
+ async getSessionOrConfirm(address) {
76
+ return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
77
+ }
78
+ async sendEvmTransaction(_transaction, _options) {
79
+ throw new WalletException(/* @__PURE__ */ new Error("This wallet does not support sending Evm transactions"), {
80
+ code: UnspecifiedErrorCode,
81
+ type: ErrorType.WalletError,
82
+ contextModule: WalletAction.SendEvmTransaction
83
+ });
84
+ }
85
+ async sendTransaction(transaction, options) {
86
+ const { endpoints, txTimeout } = options;
87
+ if (!endpoints) throw new WalletException(/* @__PURE__ */ new Error("You have to pass endpoints within the options for using Ethereum native wallets"));
88
+ const response = await new TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
89
+ if (response.code !== 0) throw new TransactionException(new Error(response.rawLog), {
90
+ code: UnspecifiedErrorCode,
91
+ contextCode: response.code,
92
+ contextModule: response.codespace
93
+ });
94
+ return response;
95
+ }
96
+ async signEip712TypedData(eip712json, address) {
97
+ const pk = this.getPrivateKey();
98
+ if (getInjectiveSignerAddress(address) !== pk.toAddress().toBech32()) throw new WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
99
+ code: UnspecifiedErrorCode,
100
+ type: ErrorType.WalletError,
101
+ contextModule: WalletAction.SignTransaction
102
+ });
103
+ try {
104
+ return `0x${uint8ArrayToHex(await pk.signTypedData(JSON.parse(eip712json)))}`;
105
+ } catch (e) {
106
+ throw new MetamaskException(new Error(e.message), {
107
+ code: UnspecifiedErrorCode,
108
+ type: ErrorType.WalletError,
109
+ contextModule: WalletAction.SignTransaction
110
+ });
111
+ }
112
+ }
113
+ async signAminoCosmosTransaction(_transaction) {
114
+ throw new WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
115
+ code: UnspecifiedErrorCode,
116
+ type: ErrorType.WalletError,
117
+ contextModule: WalletAction.SignTransaction
118
+ });
119
+ }
120
+ async signCosmosTransaction(_transaction) {
121
+ throw new WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
122
+ code: UnspecifiedErrorCode,
123
+ type: ErrorType.WalletError,
124
+ contextModule: WalletAction.SignTransaction
125
+ });
126
+ }
127
+ async signArbitrary(signer, data) {
128
+ const pk = this.getPrivateKey();
129
+ if (getInjectiveSignerAddress(signer) !== pk.toAddress().toBech32()) throw new WalletException(/* @__PURE__ */ new Error("Signer address does not match the private key address"), {
130
+ code: UnspecifiedErrorCode,
131
+ type: ErrorType.WalletError,
132
+ contextModule: WalletAction.SignArbitrary
133
+ });
134
+ try {
135
+ return `0x${uint8ArrayToBase64(await pk.signHashed(stringToUint8Array(toUtf8(data))))}`;
136
+ } catch (e) {
137
+ throw new MetamaskException(new Error(e.message), {
138
+ code: UnspecifiedErrorCode,
139
+ type: ErrorType.WalletError,
140
+ contextModule: WalletAction.SignArbitrary
141
+ });
142
+ }
143
+ }
144
+ async getEthereumChainId() {
145
+ try {
146
+ return Promise.resolve((this.chainId === ChainId.Mainnet ? EvmChainId.Mainnet : EvmChainId.Sepolia).toString(16));
147
+ } catch (e) {
148
+ throw new MetamaskException(new Error(e.message), {
149
+ code: UnspecifiedErrorCode,
150
+ type: ErrorType.WalletError,
151
+ contextModule: WalletAction.GetChainId
152
+ });
153
+ }
154
+ }
155
+ async getEvmTransactionReceipt(_txHash) {
156
+ throw new WalletException(/* @__PURE__ */ new Error("Not supported"));
157
+ }
158
+ async getPubKey() {
159
+ return this.getPrivateKey().toPublicKey().toBase64();
160
+ }
161
+ async onChainIdChanged(_callback) {}
162
+ async onAccountChange(_callback) {}
163
+ getPrivateKey() {
164
+ if (!this.privateKey) {
165
+ var _this$metadata;
166
+ if (!((_this$metadata = this.metadata) === null || _this$metadata === void 0 || (_this$metadata = _this$metadata.privateKey) === null || _this$metadata === void 0 ? void 0 : _this$metadata.privateKey)) throw new WalletException(/* @__PURE__ */ new Error("Please provide private key in the constructor"), {
167
+ code: UnspecifiedErrorCode,
168
+ type: ErrorType.WalletNotInstalledError,
169
+ contextModule: WalletAction.GetAccounts
170
+ });
171
+ this.privateKey = PrivateKey.fromHex(this.metadata.privateKey.privateKey);
172
+ }
173
+ return this.privateKey;
174
+ }
175
+ };
176
+
177
+ //#endregion
178
+ export { PrivateKeyWallet as PrivateKeyWalletStrategy };
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "module"
3
- }
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-private-key",
3
3
  "description": "Private key wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.16.24",
4
+ "version": "1.16.25-alpha.0",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -41,30 +41,30 @@
41
41
  }
42
42
  },
43
43
  "scripts": {
44
- "build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
45
- "build:cjs": "tsc --build --force tsconfig.build.json",
46
- "build:esm": "tsc --build --force tsconfig.build.esm.json",
47
- "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
48
- "build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
49
- "clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
50
- "test": "jest",
51
- "test:watch": "jest --watch",
52
- "test:ci": "jest --coverage --ci --reporters='jest-junit'",
53
- "coverage": "jest --coverage",
44
+ "build": "pnpm type-check && tsdown",
45
+ "build:fast": "tsdown",
46
+ "build:watch": "tsdown --watch",
47
+ "clean": "shx rm -rf dist coverage *.log junit.xml && shx mkdir -p dist",
48
+ "type-check": "tsc --noEmit",
49
+ "test": "vitest",
50
+ "test:watch": "vitest --watch",
51
+ "test:ci": "vitest run --coverage --reporter=verbose",
52
+ "coverage": "vitest run --coverage",
54
53
  "coverage:show": "live-server coverage",
55
54
  "dev": "ts-node -r tsconfig-paths/register src/index.ts",
56
- "start": "node dist/index.js"
55
+ "start": "node dist/index.js",
56
+ "lint": "eslint . --ext .ts,.js"
57
57
  },
58
58
  "dependencies": {
59
- "@injectivelabs/exceptions": "1.16.24",
60
- "@injectivelabs/sdk-ts": "1.16.24",
61
- "@injectivelabs/ts-types": "1.16.24",
62
- "@injectivelabs/wallet-base": "1.16.24"
59
+ "@injectivelabs/exceptions": "1.16.25-alpha.0",
60
+ "@injectivelabs/sdk-ts": "1.16.25-alpha.0",
61
+ "@injectivelabs/ts-types": "1.16.25-alpha.0",
62
+ "@injectivelabs/wallet-base": "1.16.25-alpha.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "shx": "^0.3.4"
66
66
  },
67
- "gitHead": "87521ee4ad84b3aa691ed2954611d37f548231a9",
67
+ "gitHead": "8766fbe2bf8e2b54c7ee70430dd02b2a5da8e924",
68
68
  "typedoc": {
69
69
  "entryPoint": "./src/index.ts",
70
70
  "readmeFile": "./README.md",
@@ -1 +0,0 @@
1
- export { PrivateKeyWallet as PrivateKeyWalletStrategy } from './strategy/strategy.js';
package/dist/cjs/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrivateKeyWalletStrategy = void 0;
4
- var strategy_js_1 = require("./strategy/strategy.js");
5
- Object.defineProperty(exports, "PrivateKeyWalletStrategy", { enumerable: true, get: function () { return strategy_js_1.PrivateKeyWallet; } });
@@ -1,36 +0,0 @@
1
- import { EvmChainId } from '@injectivelabs/ts-types';
2
- import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
3
- import type { AccountAddress } from '@injectivelabs/ts-types';
4
- import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
5
- import type { StdSignDoc, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
6
- export declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
7
- private privateKey?;
8
- getWalletDeviceType(): Promise<WalletDeviceType>;
9
- enable(): Promise<boolean>;
10
- disconnect(): Promise<void>;
11
- getAddresses(): Promise<string[]>;
12
- getSessionOrConfirm(address: AccountAddress): Promise<string>;
13
- sendEvmTransaction(_transaction: unknown, _options: {
14
- address: AccountAddress;
15
- evmChainId: EvmChainId;
16
- }): Promise<string>;
17
- sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
18
- signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
19
- signAminoCosmosTransaction(_transaction: {
20
- address: string;
21
- signDoc: StdSignDoc;
22
- }): Promise<AminoSignResponse>;
23
- signCosmosTransaction(_transaction: {
24
- txRaw: TxRaw;
25
- accountNumber: number;
26
- chainId: string;
27
- address: string;
28
- }): Promise<DirectSignResponse>;
29
- signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
30
- getEthereumChainId(): Promise<string>;
31
- getEvmTransactionReceipt(_txHash: string): Promise<string>;
32
- getPubKey(): Promise<string>;
33
- onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
34
- onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
35
- private getPrivateKey;
36
- }
@@ -1,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrivateKeyWallet = void 0;
4
- const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
- const ts_types_1 = require("@injectivelabs/ts-types");
6
- const sdk_ts_2 = require("@injectivelabs/sdk-ts");
7
- const wallet_base_1 = require("@injectivelabs/wallet-base");
8
- const exceptions_1 = require("@injectivelabs/exceptions");
9
- class PrivateKeyWallet extends wallet_base_1.BaseConcreteStrategy {
10
- privateKey;
11
- async getWalletDeviceType() {
12
- return Promise.resolve(wallet_base_1.WalletDeviceType.Other);
13
- }
14
- async enable() {
15
- return Promise.resolve(true);
16
- }
17
- async disconnect() {
18
- this.listeners = {};
19
- }
20
- async getAddresses() {
21
- const pk = this.getPrivateKey();
22
- try {
23
- return Promise.resolve([pk.toAddress().toHex()]);
24
- }
25
- catch (e) {
26
- throw new exceptions_1.MetamaskException(new Error(e.message), {
27
- code: exceptions_1.UnspecifiedErrorCode,
28
- type: exceptions_1.ErrorType.WalletError,
29
- contextModule: wallet_base_1.WalletAction.GetAccounts,
30
- });
31
- }
32
- }
33
- async getSessionOrConfirm(address) {
34
- return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
35
- }
36
- async sendEvmTransaction(_transaction, _options) {
37
- throw new exceptions_1.WalletException(new Error('This wallet does not support sending Evm transactions'), {
38
- code: exceptions_1.UnspecifiedErrorCode,
39
- type: exceptions_1.ErrorType.WalletError,
40
- contextModule: wallet_base_1.WalletAction.SendEvmTransaction,
41
- });
42
- }
43
- async sendTransaction(transaction, options) {
44
- const { endpoints, txTimeout } = options;
45
- if (!endpoints) {
46
- throw new exceptions_1.WalletException(new Error('You have to pass endpoints within the options for using Ethereum native wallets'));
47
- }
48
- const txApi = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
49
- const response = await txApi.broadcast(transaction, { txTimeout });
50
- if (response.code !== 0) {
51
- throw new exceptions_1.TransactionException(new Error(response.rawLog), {
52
- code: exceptions_1.UnspecifiedErrorCode,
53
- contextCode: response.code,
54
- contextModule: response.codespace,
55
- });
56
- }
57
- return response;
58
- }
59
- async signEip712TypedData(eip712json, address) {
60
- const pk = this.getPrivateKey();
61
- if ((0, sdk_ts_2.getInjectiveSignerAddress)(address) !== pk.toAddress().toBech32()) {
62
- throw new exceptions_1.WalletException(new Error('Signer address does not match the private key address'), {
63
- code: exceptions_1.UnspecifiedErrorCode,
64
- type: exceptions_1.ErrorType.WalletError,
65
- contextModule: wallet_base_1.WalletAction.SignTransaction,
66
- });
67
- }
68
- try {
69
- const signature = await pk.signTypedData(JSON.parse(eip712json));
70
- return `0x${Buffer.from(signature).toString('hex')}`;
71
- }
72
- catch (e) {
73
- throw new exceptions_1.MetamaskException(new Error(e.message), {
74
- code: exceptions_1.UnspecifiedErrorCode,
75
- type: exceptions_1.ErrorType.WalletError,
76
- contextModule: wallet_base_1.WalletAction.SignTransaction,
77
- });
78
- }
79
- }
80
- async signAminoCosmosTransaction(_transaction) {
81
- throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
82
- code: exceptions_1.UnspecifiedErrorCode,
83
- type: exceptions_1.ErrorType.WalletError,
84
- contextModule: wallet_base_1.WalletAction.SignTransaction,
85
- });
86
- }
87
- async signCosmosTransaction(_transaction) {
88
- throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
89
- code: exceptions_1.UnspecifiedErrorCode,
90
- type: exceptions_1.ErrorType.WalletError,
91
- contextModule: wallet_base_1.WalletAction.SignTransaction,
92
- });
93
- }
94
- async signArbitrary(signer, data) {
95
- const pk = this.getPrivateKey();
96
- if ((0, sdk_ts_2.getInjectiveSignerAddress)(signer) !== pk.toAddress().toBech32()) {
97
- throw new exceptions_1.WalletException(new Error('Signer address does not match the private key address'), {
98
- code: exceptions_1.UnspecifiedErrorCode,
99
- type: exceptions_1.ErrorType.WalletError,
100
- contextModule: wallet_base_1.WalletAction.SignArbitrary,
101
- });
102
- }
103
- try {
104
- const signature = await pk.signHashed(Buffer.from((0, sdk_ts_1.toUtf8)(data), 'utf-8'));
105
- return `0x${Buffer.from(signature).toString('base64')}`;
106
- }
107
- catch (e) {
108
- throw new exceptions_1.MetamaskException(new Error(e.message), {
109
- code: exceptions_1.UnspecifiedErrorCode,
110
- type: exceptions_1.ErrorType.WalletError,
111
- contextModule: wallet_base_1.WalletAction.SignArbitrary,
112
- });
113
- }
114
- }
115
- async getEthereumChainId() {
116
- try {
117
- return Promise.resolve((this.chainId === ts_types_1.ChainId.Mainnet
118
- ? ts_types_1.EvmChainId.Mainnet
119
- : ts_types_1.EvmChainId.Sepolia).toString(16));
120
- }
121
- catch (e) {
122
- throw new exceptions_1.MetamaskException(new Error(e.message), {
123
- code: exceptions_1.UnspecifiedErrorCode,
124
- type: exceptions_1.ErrorType.WalletError,
125
- contextModule: wallet_base_1.WalletAction.GetChainId,
126
- });
127
- }
128
- }
129
- async getEvmTransactionReceipt(_txHash) {
130
- throw new exceptions_1.WalletException(new Error('Not supported'));
131
- }
132
- async getPubKey() {
133
- const pk = this.getPrivateKey();
134
- return pk.toPublicKey().toBase64();
135
- }
136
- async onChainIdChanged(_callback) {
137
- //
138
- }
139
- async onAccountChange(_callback) {
140
- //
141
- }
142
- getPrivateKey() {
143
- if (!this.privateKey) {
144
- if (!this.metadata?.privateKey?.privateKey) {
145
- throw new exceptions_1.WalletException(new Error('Please provide private key in the constructor'), {
146
- code: exceptions_1.UnspecifiedErrorCode,
147
- type: exceptions_1.ErrorType.WalletNotInstalledError,
148
- contextModule: wallet_base_1.WalletAction.GetAccounts,
149
- });
150
- }
151
- this.privateKey = sdk_ts_2.PrivateKey.fromHex(this.metadata.privateKey.privateKey);
152
- }
153
- return this.privateKey;
154
- }
155
- }
156
- exports.PrivateKeyWallet = PrivateKeyWallet;
@@ -1,36 +0,0 @@
1
- import { EvmChainId } from '@injectivelabs/ts-types';
2
- import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
3
- import type { AccountAddress } from '@injectivelabs/ts-types';
4
- import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
5
- import type { StdSignDoc, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
6
- export declare class PrivateKeyWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
7
- private privateKey?;
8
- getWalletDeviceType(): Promise<WalletDeviceType>;
9
- enable(): Promise<boolean>;
10
- disconnect(): Promise<void>;
11
- getAddresses(): Promise<string[]>;
12
- getSessionOrConfirm(address: AccountAddress): Promise<string>;
13
- sendEvmTransaction(_transaction: unknown, _options: {
14
- address: AccountAddress;
15
- evmChainId: EvmChainId;
16
- }): Promise<string>;
17
- sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
18
- signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
19
- signAminoCosmosTransaction(_transaction: {
20
- address: string;
21
- signDoc: StdSignDoc;
22
- }): Promise<AminoSignResponse>;
23
- signCosmosTransaction(_transaction: {
24
- txRaw: TxRaw;
25
- accountNumber: number;
26
- chainId: string;
27
- address: string;
28
- }): Promise<DirectSignResponse>;
29
- signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
30
- getEthereumChainId(): Promise<string>;
31
- getEvmTransactionReceipt(_txHash: string): Promise<string>;
32
- getPubKey(): Promise<string>;
33
- onChainIdChanged(_callback: (chain: string) => void): Promise<void>;
34
- onAccountChange(_callback: (account: AccountAddress | string[]) => void): Promise<void>;
35
- private getPrivateKey;
36
- }
@@ -1,152 +0,0 @@
1
- import { toUtf8, TxGrpcApi } from '@injectivelabs/sdk-ts';
2
- import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
3
- import { getInjectiveSignerAddress, PrivateKey as PrivateKeySigner, } from '@injectivelabs/sdk-ts';
4
- import { WalletAction, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
5
- import { ErrorType, WalletException, MetamaskException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
6
- export class PrivateKeyWallet extends BaseConcreteStrategy {
7
- privateKey;
8
- async getWalletDeviceType() {
9
- return Promise.resolve(WalletDeviceType.Other);
10
- }
11
- async enable() {
12
- return Promise.resolve(true);
13
- }
14
- async disconnect() {
15
- this.listeners = {};
16
- }
17
- async getAddresses() {
18
- const pk = this.getPrivateKey();
19
- try {
20
- return Promise.resolve([pk.toAddress().toHex()]);
21
- }
22
- catch (e) {
23
- throw new MetamaskException(new Error(e.message), {
24
- code: UnspecifiedErrorCode,
25
- type: ErrorType.WalletError,
26
- contextModule: WalletAction.GetAccounts,
27
- });
28
- }
29
- }
30
- async getSessionOrConfirm(address) {
31
- return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
32
- }
33
- async sendEvmTransaction(_transaction, _options) {
34
- throw new WalletException(new Error('This wallet does not support sending Evm transactions'), {
35
- code: UnspecifiedErrorCode,
36
- type: ErrorType.WalletError,
37
- contextModule: WalletAction.SendEvmTransaction,
38
- });
39
- }
40
- async sendTransaction(transaction, options) {
41
- const { endpoints, txTimeout } = options;
42
- if (!endpoints) {
43
- throw new WalletException(new Error('You have to pass endpoints within the options for using Ethereum native wallets'));
44
- }
45
- const txApi = new TxGrpcApi(endpoints.grpc);
46
- const response = await txApi.broadcast(transaction, { txTimeout });
47
- if (response.code !== 0) {
48
- throw new TransactionException(new Error(response.rawLog), {
49
- code: UnspecifiedErrorCode,
50
- contextCode: response.code,
51
- contextModule: response.codespace,
52
- });
53
- }
54
- return response;
55
- }
56
- async signEip712TypedData(eip712json, address) {
57
- const pk = this.getPrivateKey();
58
- if (getInjectiveSignerAddress(address) !== pk.toAddress().toBech32()) {
59
- throw new WalletException(new Error('Signer address does not match the private key address'), {
60
- code: UnspecifiedErrorCode,
61
- type: ErrorType.WalletError,
62
- contextModule: WalletAction.SignTransaction,
63
- });
64
- }
65
- try {
66
- const signature = await pk.signTypedData(JSON.parse(eip712json));
67
- return `0x${Buffer.from(signature).toString('hex')}`;
68
- }
69
- catch (e) {
70
- throw new MetamaskException(new Error(e.message), {
71
- code: UnspecifiedErrorCode,
72
- type: ErrorType.WalletError,
73
- contextModule: WalletAction.SignTransaction,
74
- });
75
- }
76
- }
77
- async signAminoCosmosTransaction(_transaction) {
78
- throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
79
- code: UnspecifiedErrorCode,
80
- type: ErrorType.WalletError,
81
- contextModule: WalletAction.SignTransaction,
82
- });
83
- }
84
- async signCosmosTransaction(_transaction) {
85
- throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
86
- code: UnspecifiedErrorCode,
87
- type: ErrorType.WalletError,
88
- contextModule: WalletAction.SignTransaction,
89
- });
90
- }
91
- async signArbitrary(signer, data) {
92
- const pk = this.getPrivateKey();
93
- if (getInjectiveSignerAddress(signer) !== pk.toAddress().toBech32()) {
94
- throw new WalletException(new Error('Signer address does not match the private key address'), {
95
- code: UnspecifiedErrorCode,
96
- type: ErrorType.WalletError,
97
- contextModule: WalletAction.SignArbitrary,
98
- });
99
- }
100
- try {
101
- const signature = await pk.signHashed(Buffer.from(toUtf8(data), 'utf-8'));
102
- return `0x${Buffer.from(signature).toString('base64')}`;
103
- }
104
- catch (e) {
105
- throw new MetamaskException(new Error(e.message), {
106
- code: UnspecifiedErrorCode,
107
- type: ErrorType.WalletError,
108
- contextModule: WalletAction.SignArbitrary,
109
- });
110
- }
111
- }
112
- async getEthereumChainId() {
113
- try {
114
- return Promise.resolve((this.chainId === ChainId.Mainnet
115
- ? EvmChainId.Mainnet
116
- : EvmChainId.Sepolia).toString(16));
117
- }
118
- catch (e) {
119
- throw new MetamaskException(new Error(e.message), {
120
- code: UnspecifiedErrorCode,
121
- type: ErrorType.WalletError,
122
- contextModule: WalletAction.GetChainId,
123
- });
124
- }
125
- }
126
- async getEvmTransactionReceipt(_txHash) {
127
- throw new WalletException(new Error('Not supported'));
128
- }
129
- async getPubKey() {
130
- const pk = this.getPrivateKey();
131
- return pk.toPublicKey().toBase64();
132
- }
133
- async onChainIdChanged(_callback) {
134
- //
135
- }
136
- async onAccountChange(_callback) {
137
- //
138
- }
139
- getPrivateKey() {
140
- if (!this.privateKey) {
141
- if (!this.metadata?.privateKey?.privateKey) {
142
- throw new WalletException(new Error('Please provide private key in the constructor'), {
143
- code: UnspecifiedErrorCode,
144
- type: ErrorType.WalletNotInstalledError,
145
- contextModule: WalletAction.GetAccounts,
146
- });
147
- }
148
- this.privateKey = PrivateKeySigner.fromHex(this.metadata.privateKey.privateKey);
149
- }
150
- return this.privateKey;
151
- }
152
- }