@injectivelabs/wallet-turnkey 1.16.1-alpha.1 → 1.16.1-alpha.5
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/strategy/strategy.d.ts +7 -7
- package/dist/cjs/strategy/strategy.js +16 -15
- package/dist/cjs/strategy/turnkey/turnkey.d.ts +1 -1
- package/dist/esm/strategy/strategy.d.ts +7 -7
- package/dist/esm/strategy/strategy.js +13 -12
- package/dist/esm/strategy/turnkey/turnkey.d.ts +1 -1
- package/package.json +10 -10
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TxRaw, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEvmOptions, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
|
-
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
4
2
|
import { HttpRestClient } from '@injectivelabs/utils';
|
|
5
|
-
import { AccountAddress,
|
|
3
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
5
|
+
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEthereumOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
6
6
|
import { TurnkeyWallet } from './turnkey/turnkey.js';
|
|
7
7
|
export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
8
8
|
turnkeyWallet?: TurnkeyWallet;
|
|
9
|
-
|
|
9
|
+
ethereumOptions: WalletStrategyEthereumOptions;
|
|
10
10
|
client: HttpRestClient;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
12
12
|
apiServerEndpoint?: string;
|
|
13
13
|
});
|
|
14
14
|
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
@@ -22,7 +22,7 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
22
22
|
getWalletClient<TurnkeyWallet>(): Promise<TurnkeyWallet>;
|
|
23
23
|
sendEvmTransaction(transaction: unknown, args: {
|
|
24
24
|
address: AccountAddress;
|
|
25
|
-
|
|
25
|
+
ethereumChainId: EthereumChainId;
|
|
26
26
|
}): Promise<string>;
|
|
27
27
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
28
28
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -38,7 +38,7 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
38
38
|
}): Promise<AminoSignResponse>;
|
|
39
39
|
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
40
40
|
getEthereumChainId(): Promise<string>;
|
|
41
|
-
getEvmTransactionReceipt(txHash: string,
|
|
41
|
+
getEvmTransactionReceipt(txHash: string, ethereumChainId?: EthereumChainId): Promise<Record<string, any>>;
|
|
42
42
|
getPubKey(): Promise<string>;
|
|
43
43
|
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
44
44
|
private getTurnkeyWallet;
|
|
@@ -5,14 +5,15 @@ exports.TurnkeyWalletStrategy = void 0;
|
|
|
5
5
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
6
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
9
8
|
const utils_1 = require("@injectivelabs/utils");
|
|
9
|
+
const viem_2 = require("viem");
|
|
10
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
10
11
|
const types_js_1 = require("./types.js");
|
|
11
12
|
const turnkey_js_1 = require("./turnkey/turnkey.js");
|
|
12
13
|
const consts_js_1 = require("./consts.js");
|
|
13
14
|
class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
14
15
|
turnkeyWallet;
|
|
15
|
-
|
|
16
|
+
ethereumOptions;
|
|
16
17
|
client;
|
|
17
18
|
constructor(args) {
|
|
18
19
|
super(args);
|
|
@@ -21,7 +22,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
21
22
|
throw new exceptions_1.WalletException(new Error('apiServerEndpoint is required'));
|
|
22
23
|
}
|
|
23
24
|
this.client = new utils_1.HttpRestClient(endpoint);
|
|
24
|
-
this.
|
|
25
|
+
this.ethereumOptions = args.ethereumOptions;
|
|
25
26
|
}
|
|
26
27
|
async getWalletDeviceType() {
|
|
27
28
|
return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
|
|
@@ -91,19 +92,19 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
91
92
|
}
|
|
92
93
|
async sendEvmTransaction(transaction, args) {
|
|
93
94
|
try {
|
|
94
|
-
const options = this.
|
|
95
|
+
const options = this.ethereumOptions;
|
|
95
96
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
96
97
|
const organizationId = await this.getOrganizationId();
|
|
97
|
-
const chainId = args.
|
|
98
|
-
const url = options.rpcUrl || options.rpcUrls?.[args.
|
|
98
|
+
const chainId = args.ethereumChainId || options.ethereumChainId;
|
|
99
|
+
const url = options.rpcUrl || options.rpcUrls?.[args.ethereumChainId];
|
|
99
100
|
if (!url) {
|
|
100
|
-
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the
|
|
101
|
+
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
101
102
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
102
103
|
context: wallet_base_1.WalletAction.SendEvmTransaction,
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
const account = await turnkeyWallet.getOrCreateAndGetAccount((0, viem_1.getAddress)(args.address), organizationId);
|
|
106
|
-
const accountClient = (0,
|
|
107
|
+
const accountClient = (0, viem_2.createWalletClient)({
|
|
107
108
|
account: account,
|
|
108
109
|
chain: {
|
|
109
110
|
...consts_js_1.DEFAULT_EVM_CHAIN_CONFIG,
|
|
@@ -114,7 +115,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
114
115
|
},
|
|
115
116
|
},
|
|
116
117
|
},
|
|
117
|
-
transport: (0,
|
|
118
|
+
transport: (0, viem_2.http)(url),
|
|
118
119
|
});
|
|
119
120
|
const preparedTransaction = await accountClient.prepareTransactionRequest(transaction);
|
|
120
121
|
delete preparedTransaction.account;
|
|
@@ -198,19 +199,19 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
198
199
|
context: wallet_base_1.WalletAction.GetChainId,
|
|
199
200
|
});
|
|
200
201
|
}
|
|
201
|
-
async getEvmTransactionReceipt(txHash,
|
|
202
|
-
const options = this.
|
|
202
|
+
async getEvmTransactionReceipt(txHash, ethereumChainId) {
|
|
203
|
+
const options = this.ethereumOptions;
|
|
203
204
|
const maxAttempts = 10;
|
|
204
205
|
const interval = 3000;
|
|
205
|
-
const chainId =
|
|
206
|
+
const chainId = ethereumChainId || options.ethereumChainId;
|
|
206
207
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
207
208
|
if (!url) {
|
|
208
|
-
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the
|
|
209
|
+
throw new exceptions_1.WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
209
210
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
210
211
|
context: wallet_base_1.WalletAction.GetEvmTransactionReceipt,
|
|
211
212
|
});
|
|
212
213
|
}
|
|
213
|
-
const publicClient = (0,
|
|
214
|
+
const publicClient = (0, viem_2.createPublicClient)({
|
|
214
215
|
chain: {
|
|
215
216
|
...consts_js_1.DEFAULT_EVM_CHAIN_CONFIG,
|
|
216
217
|
id: chainId,
|
|
@@ -220,7 +221,7 @@ class TurnkeyWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
|
220
221
|
},
|
|
221
222
|
},
|
|
222
223
|
},
|
|
223
|
-
transport: (0,
|
|
224
|
+
transport: (0, viem_2.http)(url),
|
|
224
225
|
});
|
|
225
226
|
let attempts = 0;
|
|
226
227
|
while (attempts < maxAttempts) {
|
|
@@ -19,7 +19,7 @@ export declare class TurnkeyWallet {
|
|
|
19
19
|
getTurnkey(): Promise<Turnkey>;
|
|
20
20
|
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
21
21
|
getSession(existingCredentialBundle?: string): Promise<{
|
|
22
|
-
session: import("@turnkey/sdk-
|
|
22
|
+
session: import("@turnkey/sdk-types").Session | undefined;
|
|
23
23
|
organizationId: string;
|
|
24
24
|
}>;
|
|
25
25
|
getAccounts(): Promise<string[]>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TxRaw, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEvmOptions, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
|
-
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
4
2
|
import { HttpRestClient } from '@injectivelabs/utils';
|
|
5
|
-
import { AccountAddress,
|
|
3
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
5
|
+
import { StdSignDoc, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, WalletStrategyEthereumOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
6
6
|
import { TurnkeyWallet } from './turnkey/turnkey.js';
|
|
7
7
|
export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
8
8
|
turnkeyWallet?: TurnkeyWallet;
|
|
9
|
-
|
|
9
|
+
ethereumOptions: WalletStrategyEthereumOptions;
|
|
10
10
|
client: HttpRestClient;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
12
12
|
apiServerEndpoint?: string;
|
|
13
13
|
});
|
|
14
14
|
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
@@ -22,7 +22,7 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
22
22
|
getWalletClient<TurnkeyWallet>(): Promise<TurnkeyWallet>;
|
|
23
23
|
sendEvmTransaction(transaction: unknown, args: {
|
|
24
24
|
address: AccountAddress;
|
|
25
|
-
|
|
25
|
+
ethereumChainId: EthereumChainId;
|
|
26
26
|
}): Promise<string>;
|
|
27
27
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
28
28
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -38,7 +38,7 @@ export declare class TurnkeyWalletStrategy extends BaseConcreteStrategy implemen
|
|
|
38
38
|
}): Promise<AminoSignResponse>;
|
|
39
39
|
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
40
40
|
getEthereumChainId(): Promise<string>;
|
|
41
|
-
getEvmTransactionReceipt(txHash: string,
|
|
41
|
+
getEvmTransactionReceipt(txHash: string, ethereumChainId?: EthereumChainId): Promise<Record<string, any>>;
|
|
42
42
|
getPubKey(): Promise<string>;
|
|
43
43
|
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
44
44
|
private getTurnkeyWallet;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/* eslint-disable class-methods-use-this */
|
|
2
2
|
import { TxGrpcApi, } from '@injectivelabs/sdk-ts';
|
|
3
3
|
import { ErrorType, WalletException, UnspecifiedErrorCode, TransactionException, CosmosWalletException, } from '@injectivelabs/exceptions';
|
|
4
|
-
import {
|
|
5
|
-
import { WalletAction, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
|
|
4
|
+
import { getAddress } from 'viem';
|
|
6
5
|
import { sleep, HttpRestClient } from '@injectivelabs/utils';
|
|
6
|
+
import { http, createPublicClient, createWalletClient, } from 'viem';
|
|
7
|
+
import { WalletAction, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
|
|
7
8
|
import { TurnkeyErrorCodes } from './types.js';
|
|
8
9
|
import { TurnkeyWallet } from './turnkey/turnkey.js';
|
|
9
10
|
import { DEFAULT_EVM_CHAIN_CONFIG } from './consts.js';
|
|
10
11
|
export class TurnkeyWalletStrategy extends BaseConcreteStrategy {
|
|
11
12
|
turnkeyWallet;
|
|
12
|
-
|
|
13
|
+
ethereumOptions;
|
|
13
14
|
client;
|
|
14
15
|
constructor(args) {
|
|
15
16
|
super(args);
|
|
@@ -18,7 +19,7 @@ export class TurnkeyWalletStrategy extends BaseConcreteStrategy {
|
|
|
18
19
|
throw new WalletException(new Error('apiServerEndpoint is required'));
|
|
19
20
|
}
|
|
20
21
|
this.client = new HttpRestClient(endpoint);
|
|
21
|
-
this.
|
|
22
|
+
this.ethereumOptions = args.ethereumOptions;
|
|
22
23
|
}
|
|
23
24
|
async getWalletDeviceType() {
|
|
24
25
|
return Promise.resolve(WalletDeviceType.Browser);
|
|
@@ -88,13 +89,13 @@ export class TurnkeyWalletStrategy extends BaseConcreteStrategy {
|
|
|
88
89
|
}
|
|
89
90
|
async sendEvmTransaction(transaction, args) {
|
|
90
91
|
try {
|
|
91
|
-
const options = this.
|
|
92
|
+
const options = this.ethereumOptions;
|
|
92
93
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
93
94
|
const organizationId = await this.getOrganizationId();
|
|
94
|
-
const chainId = args.
|
|
95
|
-
const url = options.rpcUrl || options.rpcUrls?.[args.
|
|
95
|
+
const chainId = args.ethereumChainId || options.ethereumChainId;
|
|
96
|
+
const url = options.rpcUrl || options.rpcUrls?.[args.ethereumChainId];
|
|
96
97
|
if (!url) {
|
|
97
|
-
throw new WalletException(new Error('Please pass rpcUrl within the
|
|
98
|
+
throw new WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
98
99
|
code: UnspecifiedErrorCode,
|
|
99
100
|
context: WalletAction.SendEvmTransaction,
|
|
100
101
|
});
|
|
@@ -195,14 +196,14 @@ export class TurnkeyWalletStrategy extends BaseConcreteStrategy {
|
|
|
195
196
|
context: WalletAction.GetChainId,
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
|
-
async getEvmTransactionReceipt(txHash,
|
|
199
|
-
const options = this.
|
|
199
|
+
async getEvmTransactionReceipt(txHash, ethereumChainId) {
|
|
200
|
+
const options = this.ethereumOptions;
|
|
200
201
|
const maxAttempts = 10;
|
|
201
202
|
const interval = 3000;
|
|
202
|
-
const chainId =
|
|
203
|
+
const chainId = ethereumChainId || options.ethereumChainId;
|
|
203
204
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
204
205
|
if (!url) {
|
|
205
|
-
throw new WalletException(new Error('Please pass rpcUrl within the
|
|
206
|
+
throw new WalletException(new Error('Please pass rpcUrl within the ethereumOptions'), {
|
|
206
207
|
code: UnspecifiedErrorCode,
|
|
207
208
|
context: WalletAction.GetEvmTransactionReceipt,
|
|
208
209
|
});
|
|
@@ -19,7 +19,7 @@ export declare class TurnkeyWallet {
|
|
|
19
19
|
getTurnkey(): Promise<Turnkey>;
|
|
20
20
|
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
21
21
|
getSession(existingCredentialBundle?: string): Promise<{
|
|
22
|
-
session: import("@turnkey/sdk-
|
|
22
|
+
session: import("@turnkey/sdk-types").Session | undefined;
|
|
23
23
|
organizationId: string;
|
|
24
24
|
}>;
|
|
25
25
|
getAccounts(): Promise<string[]>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-turnkey",
|
|
3
3
|
"description": "Turnkey wallet strategy for use with @injectivelabs/wallet-core.",
|
|
4
|
-
"version": "1.16.1-alpha.
|
|
4
|
+
"version": "1.16.1-alpha.5",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "yarn build:esm && yarn build:cjs && yarn build:post",
|
|
48
48
|
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
49
49
|
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
50
|
-
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json &&
|
|
50
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post",
|
|
51
51
|
"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",
|
|
52
52
|
"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",
|
|
53
53
|
"test": "jest",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"start": "node dist/index.js"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@injectivelabs/exceptions": "1.16.1-alpha.
|
|
63
|
-
"@injectivelabs/sdk-ts": "1.16.1-alpha.
|
|
64
|
-
"@injectivelabs/ts-types": "1.16.1-alpha.
|
|
65
|
-
"@injectivelabs/utils": "1.16.1-alpha.
|
|
66
|
-
"@injectivelabs/wallet-base": "1.16.1-alpha.
|
|
62
|
+
"@injectivelabs/exceptions": "^1.16.1-alpha.5",
|
|
63
|
+
"@injectivelabs/sdk-ts": "^1.16.1-alpha.5",
|
|
64
|
+
"@injectivelabs/ts-types": "^1.16.1-alpha.5",
|
|
65
|
+
"@injectivelabs/utils": "^1.16.1-alpha.5",
|
|
66
|
+
"@injectivelabs/wallet-base": "^1.16.1-alpha.5",
|
|
67
67
|
"@turnkey/sdk-browser": "5.2.3",
|
|
68
|
-
"@turnkey/viem": "0.9.9",
|
|
68
|
+
"@turnkey/viem": "^0.9.9",
|
|
69
69
|
"viem": "^2.31.3"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"tsconfig-paths": "^4.2.0",
|
|
78
78
|
"typescript": "^5.0.0"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "b58852fac80374e6795403bd5ccf06c174979e9f"
|
|
81
81
|
}
|