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