@injectivelabs/wallet-turnkey 1.16.37 → 1.16.38-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.
Files changed (41) hide show
  1. package/dist/cjs/index.cjs +681 -0
  2. package/dist/cjs/index.d.cts +92 -0
  3. package/dist/cjs/package.json +2 -2
  4. package/dist/esm/index.d.ts +92 -3
  5. package/dist/esm/index.js +680 -3
  6. package/dist/esm/package.json +2 -2
  7. package/package.json +33 -42
  8. package/dist/cjs/index.d.ts +0 -3
  9. package/dist/cjs/index.js +0 -21
  10. package/dist/cjs/strategy/Eip1193Provider.d.ts +0 -3
  11. package/dist/cjs/strategy/Eip1193Provider.js +0 -131
  12. package/dist/cjs/strategy/consts.d.ts +0 -13
  13. package/dist/cjs/strategy/consts.js +0 -16
  14. package/dist/cjs/strategy/strategy.d.ts +0 -48
  15. package/dist/cjs/strategy/strategy.js +0 -275
  16. package/dist/cjs/strategy/turnkey/oauth.d.ts +0 -16
  17. package/dist/cjs/strategy/turnkey/oauth.js +0 -53
  18. package/dist/cjs/strategy/turnkey/otp.d.ts +0 -23
  19. package/dist/cjs/strategy/turnkey/otp.js +0 -65
  20. package/dist/cjs/strategy/turnkey/turnkey.d.ts +0 -35
  21. package/dist/cjs/strategy/turnkey/turnkey.js +0 -259
  22. package/dist/cjs/strategy/types.d.ts +0 -28
  23. package/dist/cjs/strategy/types.js +0 -6
  24. package/dist/cjs/utils.d.ts +0 -7
  25. package/dist/cjs/utils.js +0 -10
  26. package/dist/esm/strategy/Eip1193Provider.d.ts +0 -3
  27. package/dist/esm/strategy/Eip1193Provider.js +0 -127
  28. package/dist/esm/strategy/consts.d.ts +0 -13
  29. package/dist/esm/strategy/consts.js +0 -13
  30. package/dist/esm/strategy/strategy.d.ts +0 -48
  31. package/dist/esm/strategy/strategy.js +0 -271
  32. package/dist/esm/strategy/turnkey/oauth.d.ts +0 -16
  33. package/dist/esm/strategy/turnkey/oauth.js +0 -49
  34. package/dist/esm/strategy/turnkey/otp.d.ts +0 -23
  35. package/dist/esm/strategy/turnkey/otp.js +0 -61
  36. package/dist/esm/strategy/turnkey/turnkey.d.ts +0 -35
  37. package/dist/esm/strategy/turnkey/turnkey.js +0 -255
  38. package/dist/esm/strategy/types.d.ts +0 -28
  39. package/dist/esm/strategy/types.js +0 -3
  40. package/dist/esm/utils.d.ts +0 -7
  41. package/dist/esm/utils.js +0 -7
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurnkeyOauthWallet = void 0;
4
- const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
- const exceptions_1 = require("@injectivelabs/exceptions");
6
- const consts_js_1 = require("../consts.js");
7
- class TurnkeyOauthWallet {
8
- static async generateOAuthNonce(indexedDbClient) {
9
- try {
10
- await indexedDbClient.resetKeyPair();
11
- const targetPublicKey = await indexedDbClient.getPublicKey();
12
- if (!targetPublicKey) {
13
- throw new exceptions_1.WalletException(new Error('Target public key not found'));
14
- }
15
- return Array.from((0, sdk_ts_1.sha256)(new TextEncoder().encode(targetPublicKey)))
16
- .map((b) => b.toString(16).padStart(2, '0'))
17
- .join('');
18
- }
19
- catch (e) {
20
- throw new exceptions_1.WalletException(new Error(e.message), {
21
- code: exceptions_1.UnspecifiedErrorCode,
22
- type: exceptions_1.ErrorType.WalletError,
23
- contextModule: 'turnkey-generate-oauth-nonce',
24
- });
25
- }
26
- }
27
- static async oauthLogin(args) {
28
- const { client, indexedDbClient, expirationSeconds } = args;
29
- const path = args.oauthLoginPath || consts_js_1.TURNKEY_OAUTH_PATH;
30
- try {
31
- const targetPublicKey = await indexedDbClient.getPublicKey();
32
- if (!targetPublicKey) {
33
- throw new exceptions_1.WalletException(new Error('Target public key not found'));
34
- }
35
- // client.$post is undefined, resorting to this for now
36
- const response = await client.post(path, {
37
- targetPublicKey,
38
- oidcToken: args.oidcToken,
39
- providerName: args.providerName,
40
- expirationSeconds: (expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
41
- });
42
- return response.data;
43
- }
44
- catch (e) {
45
- throw new exceptions_1.WalletException(new Error(e.message), {
46
- code: exceptions_1.UnspecifiedErrorCode,
47
- type: exceptions_1.ErrorType.WalletError,
48
- contextModule: 'turnkey-oauth-login',
49
- });
50
- }
51
- }
52
- }
53
- exports.TurnkeyOauthWallet = TurnkeyOauthWallet;
@@ -1,23 +0,0 @@
1
- import { type TurnkeyConfirmEmailOTPResponse, type TurnkeyOTPCredentialsResponse } from './../types.js';
2
- import type { HttpRestClient } from '@injectivelabs/utils';
3
- import type { TurnkeyIndexedDbClient } from '@turnkey/sdk-browser';
4
- export declare class TurnkeyOtpWallet {
5
- static initEmailOTP(args: {
6
- email: string;
7
- subOrgId?: string;
8
- otpInitPath?: string;
9
- client: HttpRestClient;
10
- indexedDbClient: TurnkeyIndexedDbClient;
11
- invalidateExistingSessions?: boolean;
12
- expirationSeconds?: number;
13
- }): Promise<TurnkeyOTPCredentialsResponse | undefined>;
14
- static confirmEmailOTP(args: {
15
- otpCode: string;
16
- emailOTPId: string;
17
- client: HttpRestClient;
18
- targetPublicKey: string;
19
- organizationId: string;
20
- otpVerifyPath?: string;
21
- expirationSeconds?: number;
22
- }): Promise<TurnkeyConfirmEmailOTPResponse | undefined>;
23
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurnkeyOtpWallet = void 0;
4
- const exceptions_1 = require("@injectivelabs/exceptions");
5
- const consts_js_1 = require("../consts.js");
6
- class TurnkeyOtpWallet {
7
- static async initEmailOTP(args) {
8
- const { client, indexedDbClient, expirationSeconds } = args;
9
- try {
10
- await indexedDbClient.resetKeyPair();
11
- let publicKey = await indexedDbClient.getPublicKey();
12
- if (!publicKey) {
13
- throw new exceptions_1.WalletException(new Error('Public key not found'));
14
- }
15
- // client.$post is undefined, resorting to this for now
16
- const response = await client.post(args.otpInitPath || consts_js_1.TURNKEY_OTP_INIT_PATH, {
17
- targetPublicKey: publicKey,
18
- email: args.email,
19
- suborgId: args.subOrgId,
20
- invalidateExistingSessions: args.invalidateExistingSessions,
21
- isUsingIndexedDB: true,
22
- expirationSeconds: expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS,
23
- });
24
- return response?.data;
25
- }
26
- catch (e) {
27
- throw new exceptions_1.WalletException(new Error(e.message), {
28
- code: exceptions_1.UnspecifiedErrorCode,
29
- type: exceptions_1.ErrorType.WalletError,
30
- contextModule: 'turnkey-init-email-otp',
31
- });
32
- }
33
- }
34
- static async confirmEmailOTP(args) {
35
- const { client, expirationSeconds, targetPublicKey } = args;
36
- try {
37
- const organizationId = args.organizationId;
38
- const emailOTPId = args.emailOTPId;
39
- const otpVerifyPath = args.otpVerifyPath || consts_js_1.TURNKEY_OTP_VERIFY_PATH;
40
- if (!emailOTPId) {
41
- throw new exceptions_1.WalletException(new Error('Email OTP ID is required'));
42
- }
43
- if (!organizationId) {
44
- throw new exceptions_1.WalletException(new Error('Organization ID is required'));
45
- }
46
- const response = await client.post(otpVerifyPath, {
47
- isUsingIndexedDB: true,
48
- targetPublicKey,
49
- otpId: emailOTPId,
50
- otpCode: args.otpCode,
51
- suborgID: organizationId,
52
- expirationSeconds: (expirationSeconds || consts_js_1.DEFAULT_TURNKEY_REFRESH_SECONDS)?.toString(),
53
- });
54
- return response?.data;
55
- }
56
- catch (e) {
57
- throw new exceptions_1.WalletException(new Error(e.message), {
58
- code: exceptions_1.UnspecifiedErrorCode,
59
- type: exceptions_1.ErrorType.WalletError,
60
- contextModule: 'turnkey-confirm-email-otp',
61
- });
62
- }
63
- }
64
- }
65
- exports.TurnkeyOtpWallet = TurnkeyOtpWallet;
@@ -1,35 +0,0 @@
1
- import { createAccount } from '@turnkey/viem';
2
- import { HttpRestClient } from '@injectivelabs/utils';
3
- import { Turnkey } from '@turnkey/sdk-browser';
4
- import { TurnkeyProvider } from '@injectivelabs/wallet-base';
5
- import type { TurnkeyMetadata } from '@injectivelabs/wallet-base';
6
- import type { TurnkeyIndexedDbClient } from '@turnkey/sdk-browser';
7
- export declare class TurnkeyWallet {
8
- private otpId?;
9
- protected turnkey?: Turnkey;
10
- userOrganizationId?: string;
11
- protected client: HttpRestClient;
12
- private metadata;
13
- protected indexedDbClient?: TurnkeyIndexedDbClient;
14
- private accountMap;
15
- setMetadata(metadata: Partial<TurnkeyMetadata>): void;
16
- constructor(metadata: TurnkeyMetadata);
17
- static getTurnkeyInstance(metadata: TurnkeyMetadata): Promise<{
18
- turnkey: Turnkey;
19
- indexedDbClient: TurnkeyIndexedDbClient;
20
- }>;
21
- getTurnkey(): Promise<Turnkey>;
22
- getIndexedDbClient(): Promise<TurnkeyIndexedDbClient>;
23
- getSession(existingCredentialBundle?: string): Promise<{
24
- session: import("@turnkey/sdk-browser").Session | undefined;
25
- organizationId: string;
26
- }>;
27
- getAccounts(): Promise<string[]>;
28
- getOrCreateAndGetAccount(address: string): Promise<ReturnType<typeof createAccount>>;
29
- initOTP(email: string): Promise<import("../types.js").TurnkeyOTPCredentialsResponse>;
30
- confirmOTP(otpCode: string): Promise<import("../types.js").TurnkeyConfirmEmailOTPResponse>;
31
- initOAuth(provider: TurnkeyProvider): Promise<string>;
32
- confirmOAuth(provider: TurnkeyProvider, oidcToken: string): Promise<string>;
33
- refreshSession(): Promise<string>;
34
- private initClient;
35
- }
@@ -1,259 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurnkeyWallet = void 0;
4
- const viem_1 = require("@turnkey/viem");
5
- const utils_1 = require("@injectivelabs/utils");
6
- const sdk_ts_1 = require("@injectivelabs/sdk-ts");
7
- const sdk_browser_1 = require("@turnkey/sdk-browser");
8
- const wallet_base_1 = require("@injectivelabs/wallet-base");
9
- const exceptions_1 = require("@injectivelabs/exceptions");
10
- const otp_js_1 = require("./otp.js");
11
- const types_js_1 = require("../types.js");
12
- const oauth_js_1 = require("./oauth.js");
13
- const utils_js_1 = require("../../utils.js");
14
- const consts_js_1 = require("../consts.js");
15
- class TurnkeyWallet {
16
- otpId;
17
- turnkey;
18
- userOrganizationId;
19
- client;
20
- metadata;
21
- indexedDbClient;
22
- accountMap = {};
23
- setMetadata(metadata) {
24
- this.metadata = { ...this.metadata, ...metadata };
25
- }
26
- constructor(metadata) {
27
- this.metadata = metadata;
28
- this.client = new utils_1.HttpRestClient(metadata.apiServerEndpoint);
29
- }
30
- static async getTurnkeyInstance(metadata) {
31
- const { turnkey, indexedDbClient } = await createTurnkeyClient(metadata);
32
- return {
33
- turnkey,
34
- indexedDbClient,
35
- };
36
- }
37
- async getTurnkey() {
38
- if (!this.indexedDbClient) {
39
- await this.initClient();
40
- }
41
- if (!this.turnkey) {
42
- this.turnkey = new sdk_browser_1.Turnkey(this.metadata);
43
- }
44
- return this.turnkey;
45
- }
46
- async getIndexedDbClient() {
47
- if (!this.indexedDbClient) {
48
- await this.initClient();
49
- }
50
- if (!this.indexedDbClient) {
51
- throw new exceptions_1.WalletException(new Error('Indexed DB client not initialized'));
52
- }
53
- return this.indexedDbClient;
54
- }
55
- async getSession(existingCredentialBundle) {
56
- try {
57
- const { metadata } = this;
58
- const indexedDbClient = await this.getIndexedDbClient();
59
- const turnkey = await this.getTurnkey();
60
- const session = await turnkey.getSession();
61
- const organizationId = session?.organizationId || metadata.defaultOrganizationId;
62
- const credentialBundle = existingCredentialBundle || session?.token;
63
- if (!credentialBundle) {
64
- return {
65
- session: undefined,
66
- organizationId,
67
- };
68
- }
69
- const user = await indexedDbClient.getWhoami();
70
- const actualOrganizationId = user?.organizationId || session?.organizationId || organizationId;
71
- if (!user) {
72
- return {
73
- session: undefined,
74
- organizationId: actualOrganizationId,
75
- };
76
- }
77
- this.userOrganizationId = actualOrganizationId;
78
- return {
79
- session,
80
- organizationId: actualOrganizationId,
81
- };
82
- }
83
- catch {
84
- throw new exceptions_1.TurnkeyWalletSessionException(new Error('Session expired. Please login again.'));
85
- }
86
- }
87
- async getAccounts() {
88
- const indexedDbClient = await this.getIndexedDbClient();
89
- if (!this.userOrganizationId) {
90
- return [];
91
- }
92
- try {
93
- const response = await indexedDbClient.getWallets({
94
- organizationId: this.userOrganizationId,
95
- });
96
- const accounts = await Promise.allSettled(response.wallets.map((wallet) => indexedDbClient.getWalletAccounts({
97
- walletId: wallet.walletId,
98
- organizationId: this.userOrganizationId,
99
- })));
100
- const filteredAccounts = accounts
101
- .filter((account) => account.status === 'fulfilled')
102
- .flatMap((result) => result.value?.accounts)
103
- .filter((wa) => !!wa &&
104
- wa.addressFormat === 'ADDRESS_FORMAT_ETHEREUM' &&
105
- !!wa.address);
106
- return filteredAccounts.map((account) => (0, sdk_ts_1.getInjectiveAddress)(account.address));
107
- }
108
- catch (e) {
109
- if (e.code === types_js_1.TurnkeyErrorCodes.UserLoggedOut) {
110
- throw new exceptions_1.WalletException(new Error('User is not logged in'), {
111
- code: exceptions_1.UnspecifiedErrorCode,
112
- type: exceptions_1.ErrorType.WalletError,
113
- contextModule: wallet_base_1.WalletAction.GetAccounts,
114
- contextCode: types_js_1.TurnkeyErrorCodes.UserLoggedOut,
115
- });
116
- }
117
- throw new exceptions_1.WalletException(new Error(e.message), {
118
- code: exceptions_1.UnspecifiedErrorCode,
119
- type: exceptions_1.ErrorType.WalletError,
120
- contextModule: 'turnkey-wallet-get-accounts',
121
- });
122
- }
123
- }
124
- async getOrCreateAndGetAccount(address) {
125
- const { accountMap } = this;
126
- const indexedDbClient = await this.getIndexedDbClient();
127
- const organizationId = this.userOrganizationId;
128
- if (accountMap[address] || accountMap[address.toLowerCase()]) {
129
- return accountMap[address] || accountMap[address.toLowerCase()];
130
- }
131
- if (!organizationId) {
132
- throw new exceptions_1.WalletException(new Error('Organization ID is required'));
133
- }
134
- indexedDbClient.config.organizationId = organizationId;
135
- if (!address) {
136
- throw new exceptions_1.WalletException(new Error('Account address not found'));
137
- }
138
- const turnkeyAccount = await (0, viem_1.createAccount)({
139
- organizationId,
140
- signWith: address,
141
- client: indexedDbClient,
142
- });
143
- this.accountMap[address] = turnkeyAccount;
144
- return turnkeyAccount;
145
- }
146
- async initOTP(email) {
147
- const indexedDbClient = await this.getIndexedDbClient();
148
- const result = await otp_js_1.TurnkeyOtpWallet.initEmailOTP({
149
- client: this.client,
150
- indexedDbClient,
151
- email,
152
- otpInitPath: this.metadata.otpInitPath || consts_js_1.TURNKEY_OTP_INIT_PATH,
153
- });
154
- if (!result || !result.otpId) {
155
- throw new exceptions_1.WalletException(new Error('Failed to initialize OTP'));
156
- }
157
- if (result?.organizationId) {
158
- this.userOrganizationId = result.organizationId;
159
- }
160
- if (result?.otpId) {
161
- this.otpId = result.otpId;
162
- }
163
- return result;
164
- }
165
- async confirmOTP(otpCode) {
166
- const indexedDbClient = await this.getIndexedDbClient();
167
- const targetPublicKey = await indexedDbClient.getPublicKey();
168
- if (!this.otpId) {
169
- throw new exceptions_1.WalletException(new Error('OTP ID is required'));
170
- }
171
- if (!targetPublicKey) {
172
- throw new exceptions_1.WalletException(new Error('Target public key not found'));
173
- }
174
- if (!this.userOrganizationId) {
175
- throw new exceptions_1.WalletException(new Error('Organization ID is required'));
176
- }
177
- const result = await otp_js_1.TurnkeyOtpWallet.confirmEmailOTP({
178
- otpCode,
179
- client: this.client,
180
- emailOTPId: this.otpId,
181
- organizationId: this.userOrganizationId,
182
- targetPublicKey,
183
- otpVerifyPath: this.metadata.otpVerifyPath || consts_js_1.TURNKEY_OTP_VERIFY_PATH,
184
- });
185
- if (!result || !result.session) {
186
- throw new exceptions_1.WalletException(new Error('Failed to confirm OTP'));
187
- }
188
- await indexedDbClient.loginWithSession(result.session);
189
- this.userOrganizationId = result.organizationId;
190
- return result;
191
- }
192
- async initOAuth(provider) {
193
- if (provider === wallet_base_1.TurnkeyProvider.Apple) {
194
- throw new exceptions_1.WalletException(new Error('Apple sign in option is currently not supported'));
195
- }
196
- const indexedDbClient = await this.getIndexedDbClient();
197
- const nonce = await oauth_js_1.TurnkeyOauthWallet.generateOAuthNonce(indexedDbClient);
198
- if (!this.metadata?.googleClientId || !this.metadata?.googleRedirectUri) {
199
- throw new exceptions_1.WalletException(new Error('googleClientId and googleRedirectUri are required'));
200
- }
201
- return (0, utils_js_1.generateGoogleUrl)({
202
- nonce,
203
- clientId: this.metadata.googleClientId,
204
- redirectUri: this.metadata.googleRedirectUri,
205
- });
206
- }
207
- async confirmOAuth(provider, oidcToken) {
208
- if (provider === wallet_base_1.TurnkeyProvider.Apple) {
209
- throw new exceptions_1.WalletException(new Error('Apple sign in option is currently not supported'));
210
- }
211
- const indexedDbClient = await this.getIndexedDbClient();
212
- const oauthResult = await oauth_js_1.TurnkeyOauthWallet.oauthLogin({
213
- oidcToken,
214
- indexedDbClient,
215
- client: this.client,
216
- providerName: provider.toString(),
217
- oauthLoginPath: this.metadata.oauthLoginPath || consts_js_1.TURNKEY_OAUTH_PATH,
218
- });
219
- if (!oauthResult || !oauthResult.credentialBundle) {
220
- throw new exceptions_1.WalletException(new Error('Unexpected OAuth result'));
221
- }
222
- await indexedDbClient.loginWithSession(oauthResult.credentialBundle);
223
- this.userOrganizationId = oauthResult.organizationId;
224
- return oauthResult.credentialBundle;
225
- }
226
- async refreshSession() {
227
- const session = await this.getSession();
228
- const indexedDbClient = await this.getIndexedDbClient();
229
- if (session.session?.token) {
230
- await indexedDbClient.refreshSession({
231
- sessionType: sdk_browser_1.SessionType.READ_WRITE,
232
- expirationSeconds: this.metadata.expirationSeconds,
233
- });
234
- this.userOrganizationId = session.organizationId;
235
- return session.session.token;
236
- }
237
- throw new exceptions_1.TurnkeyWalletSessionException(new Error('Session expired. Please login again.'));
238
- }
239
- async initClient() {
240
- const { metadata } = this;
241
- const { turnkey, indexedDbClient } = await createTurnkeyClient(metadata);
242
- this.turnkey = turnkey;
243
- this.indexedDbClient = indexedDbClient;
244
- return { turnkey, indexedDbClient };
245
- }
246
- }
247
- exports.TurnkeyWallet = TurnkeyWallet;
248
- async function createTurnkeyClient(metadata) {
249
- const turnkey = new sdk_browser_1.Turnkey(metadata);
250
- const indexedDbClient = await turnkey.indexedDbClient();
251
- await indexedDbClient.init();
252
- if (!turnkey) {
253
- throw new exceptions_1.GeneralException(new Error('Turnkey is not initialized'));
254
- }
255
- return {
256
- turnkey,
257
- indexedDbClient,
258
- };
259
- }
@@ -1,28 +0,0 @@
1
- export declare const TurnkeyErrorCodes: {
2
- readonly UserLoggedOut: 7;
3
- };
4
- export type TurnkeyErrorCodes = (typeof TurnkeyErrorCodes)[keyof typeof TurnkeyErrorCodes];
5
- export type TurnkeyOAuthArgs = {
6
- provider: 'google';
7
- oidcToken: string;
8
- oauthLoginEndpoint: string;
9
- };
10
- export type TurnkeyEmailArgs = {
11
- provider: 'email';
12
- email: string;
13
- initEmailOTPEndpoint: string;
14
- };
15
- export type TurnkeyEnableArgs = TurnkeyOAuthArgs | TurnkeyEmailArgs;
16
- export type TurnkeyOTPCredentialsResponse = {
17
- otpId: string;
18
- organizationId: string;
19
- };
20
- export type TurnkeyConfirmEmailOTPResponse = {
21
- session: string;
22
- organizationId: string;
23
- };
24
- export type TurnkeyOauthLoginResponse = {
25
- organizationId: string;
26
- credentialBundle: string;
27
- message: string;
28
- };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurnkeyErrorCodes = void 0;
4
- exports.TurnkeyErrorCodes = {
5
- UserLoggedOut: 7,
6
- };
@@ -1,7 +0,0 @@
1
- export declare function generateGoogleUrl({ nonce, clientId, redirectUri, scope, prompt, }: {
2
- nonce: string;
3
- clientId: string;
4
- redirectUri: string;
5
- scope?: string;
6
- prompt?: string;
7
- }): string;
package/dist/cjs/utils.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateGoogleUrl = generateGoogleUrl;
4
- function generateGoogleUrl({ nonce, clientId, redirectUri, scope = 'openid profile email', prompt = 'consent', }) {
5
- if (!clientId) {
6
- throw new Error('Google client ID not found');
7
- }
8
- const responseType = 'id_token';
9
- return `https://accounts.google.com/o/oauth2/v2/auth?prompt=${prompt}&client_id=${clientId}&redirect_uri=${redirectUri}&response_type=${responseType}&scope=${scope}&nonce=${nonce}`;
10
- }
@@ -1,3 +0,0 @@
1
- import type { LocalAccount } from 'viem';
2
- import type { Eip1193Provider } from '@injectivelabs/wallet-base';
3
- export declare const getEip1193ProviderForTurnkey: (account: LocalAccount, chainId: string) => Promise<Eip1193Provider>;
@@ -1,127 +0,0 @@
1
- import { getEvmChainConfig, getViemPublicClient, getViemWalletClient, } from '@injectivelabs/wallet-base';
2
- export const getEip1193ProviderForTurnkey = async (account, chainId) => {
3
- const provider = new CustomEip1193Provider({
4
- chainId: parseInt(chainId, 16),
5
- signTypedData: account.signTypedData.bind(account),
6
- signMessage: account.signMessage.bind(account),
7
- signTransaction: account.signTransaction.bind(account),
8
- account,
9
- address: account.address,
10
- });
11
- return provider;
12
- };
13
- class CustomEip1193Provider {
14
- chainId;
15
- signTypedData;
16
- signMessage;
17
- signTransaction;
18
- account;
19
- address;
20
- constructor(args) {
21
- this.chainId = args.chainId ?? 1;
22
- this.signTypedData = args.signTypedData;
23
- this.signMessage = args.signMessage;
24
- this.account = args.account;
25
- this.address = args.address;
26
- this.signTransaction = args.signTransaction;
27
- }
28
- async requestAccounts() {
29
- return [this.address];
30
- }
31
- getClient() {
32
- return getViemWalletClient({
33
- chainId: this.chainId,
34
- account: this.account,
35
- });
36
- }
37
- getChain() {
38
- return getEvmChainConfig(this.chainId);
39
- }
40
- on(_event, _listener) {
41
- throw new Error('Not implemented');
42
- }
43
- removeListener(..._args) {
44
- throw new Error('Not implemented!');
45
- }
46
- async request(args) {
47
- if (args.method === 'eth_requestAccounts') {
48
- return this.requestAccounts();
49
- }
50
- if (args.method === 'eth_signTypedData') {
51
- if (!args.params) {
52
- throw new Error('params is required');
53
- }
54
- return this.signTypedData(args.params[0]);
55
- }
56
- if (args.method === 'eth_signMessage') {
57
- if (!args.params) {
58
- throw new Error('params is required');
59
- }
60
- return this.signMessage(args.params[0]);
61
- }
62
- if (args.method === 'eth_chainId') {
63
- return this.chainId;
64
- }
65
- if (args.method === 'wallet_switchEthereumChain') {
66
- if (!args.params) {
67
- throw new Error('params is required');
68
- }
69
- const chainId = String(args.params[0].chainId).replace('0x', '');
70
- this.chainId = parseInt(chainId, 16);
71
- return true;
72
- }
73
- if (args.method === 'eth_sendTransaction') {
74
- if (!args.params) {
75
- throw new Error('params is required');
76
- }
77
- const accountClient = getViemWalletClient({
78
- chainId: this.chainId,
79
- account: this.account,
80
- });
81
- const client = this.getClient();
82
- const parseHexValue = (value) => {
83
- if (typeof value === 'string') {
84
- const hexValue = value.startsWith('0x') ? value : `0x${value}`;
85
- return BigInt(hexValue);
86
- }
87
- return BigInt(value);
88
- };
89
- const txData = args.params[0];
90
- const processedTransaction = { ...txData };
91
- const hexFields = [
92
- 'value',
93
- 'gas',
94
- 'gasLimit',
95
- 'gasPrice',
96
- 'maxFeePerGas',
97
- 'maxPriorityFeePerGas',
98
- ];
99
- for (const field of hexFields) {
100
- if (processedTransaction[field] !== undefined) {
101
- processedTransaction[field] = parseHexValue(processedTransaction[field]);
102
- }
103
- }
104
- const preparedTransaction = await accountClient.prepareTransactionRequest(processedTransaction);
105
- const signedTransaction = await this.signTransaction(preparedTransaction);
106
- const tx = await client.sendRawTransaction({
107
- serializedTransaction: signedTransaction,
108
- });
109
- return tx;
110
- }
111
- if (args.method === 'eth_getTransactionCount') {
112
- if (!args.params) {
113
- throw new Error('params is required');
114
- }
115
- const client = getViemPublicClient(this.chainId);
116
- const count = await client.getTransactionCount({
117
- address: this.address,
118
- blockTag: 'pending',
119
- });
120
- return `0x${count.toString(16)}`;
121
- }
122
- return this.getClient().request({
123
- method: args.method,
124
- params: args.params,
125
- });
126
- }
127
- }
@@ -1,13 +0,0 @@
1
- export declare const TURNKEY_OAUTH_PATH = "turnkey/oauth";
2
- export declare const TURNKEY_OTP_PATH = "turnkey/otp";
3
- export declare const TURNKEY_OTP_INIT_PATH = "turnkey/otp/init";
4
- export declare const TURNKEY_OTP_VERIFY_PATH = "turnkey/otp/verify";
5
- export declare const DEFAULT_TURNKEY_REFRESH_SECONDS = "86400";
6
- export declare const DEFAULT_EVM_CHAIN_CONFIG: {
7
- name: string;
8
- nativeCurrency: {
9
- name: string;
10
- symbol: string;
11
- decimals: number;
12
- };
13
- };
@@ -1,13 +0,0 @@
1
- export const TURNKEY_OAUTH_PATH = 'turnkey/oauth';
2
- export const TURNKEY_OTP_PATH = 'turnkey/otp';
3
- export const TURNKEY_OTP_INIT_PATH = `${TURNKEY_OTP_PATH}/init`;
4
- export const TURNKEY_OTP_VERIFY_PATH = `${TURNKEY_OTP_PATH}/verify`;
5
- export const DEFAULT_TURNKEY_REFRESH_SECONDS = '86400';
6
- export const DEFAULT_EVM_CHAIN_CONFIG = {
7
- name: 'Injective',
8
- nativeCurrency: {
9
- name: 'Injective',
10
- symbol: 'INJ',
11
- decimals: 18,
12
- },
13
- };