@injectivelabs/wallet-turnkey 1.15.10
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/README.md +120 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/strategy/consts.d.ts +4 -0
- package/dist/cjs/strategy/consts.js +7 -0
- package/dist/cjs/strategy/strategy/base.d.ts +47 -0
- package/dist/cjs/strategy/strategy/base.js +327 -0
- package/dist/cjs/strategy/strategy/oauth.d.ts +5 -0
- package/dist/cjs/strategy/strategy/oauth.js +14 -0
- package/dist/cjs/strategy/strategy/otp.d.ts +5 -0
- package/dist/cjs/strategy/strategy/otp.js +14 -0
- package/dist/cjs/strategy/turnkey/oauth.d.ts +16 -0
- package/dist/cjs/strategy/turnkey/oauth.js +51 -0
- package/dist/cjs/strategy/turnkey/otp.d.ts +21 -0
- package/dist/cjs/strategy/turnkey/otp.js +64 -0
- package/dist/cjs/strategy/turnkey/turnkey.d.ts +43 -0
- package/dist/cjs/strategy/turnkey/turnkey.js +196 -0
- package/dist/cjs/strategy/types.d.ts +26 -0
- package/dist/cjs/strategy/types.js +7 -0
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/utils.js +10 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/strategy/consts.d.ts +4 -0
- package/dist/esm/strategy/consts.js +4 -0
- package/dist/esm/strategy/strategy/base.d.ts +47 -0
- package/dist/esm/strategy/strategy/base.js +323 -0
- package/dist/esm/strategy/strategy/oauth.d.ts +5 -0
- package/dist/esm/strategy/strategy/oauth.js +10 -0
- package/dist/esm/strategy/strategy/otp.d.ts +5 -0
- package/dist/esm/strategy/strategy/otp.js +10 -0
- package/dist/esm/strategy/turnkey/oauth.d.ts +16 -0
- package/dist/esm/strategy/turnkey/oauth.js +47 -0
- package/dist/esm/strategy/turnkey/otp.d.ts +21 -0
- package/dist/esm/strategy/turnkey/otp.js +60 -0
- package/dist/esm/strategy/turnkey/turnkey.d.ts +43 -0
- package/dist/esm/strategy/turnkey/turnkey.js +192 -0
- package/dist/esm/strategy/types.d.ts +26 -0
- package/dist/esm/strategy/types.js +4 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +7 -0
- package/package.json +78 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
2
|
+
import { type TurnkeyConfirmEmailOTPResponse, type TurnkeyOTPCredentialsResponse } from './../types.js';
|
|
3
|
+
import { type HttpRestClient } from '@injectivelabs/utils';
|
|
4
|
+
export declare class TurnkeyOtpWallet {
|
|
5
|
+
static initEmailOTP(args: {
|
|
6
|
+
email: string;
|
|
7
|
+
subOrgId?: string;
|
|
8
|
+
otpInitPath?: string;
|
|
9
|
+
client: HttpRestClient;
|
|
10
|
+
iframeClient: TurnkeyIframeClient;
|
|
11
|
+
invalidateExistingSessions?: boolean;
|
|
12
|
+
}): Promise<TurnkeyOTPCredentialsResponse | undefined>;
|
|
13
|
+
static confirmEmailOTP(args: {
|
|
14
|
+
otpCode: string;
|
|
15
|
+
emailOTPId?: string;
|
|
16
|
+
client: HttpRestClient;
|
|
17
|
+
organizationId?: string;
|
|
18
|
+
iframeClient: TurnkeyIframeClient;
|
|
19
|
+
otpVerifyPath?: string;
|
|
20
|
+
}): Promise<TurnkeyConfirmEmailOTPResponse | undefined>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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, iframeClient } = args;
|
|
9
|
+
try {
|
|
10
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
11
|
+
if (!targetPublicKey) {
|
|
12
|
+
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
13
|
+
}
|
|
14
|
+
// client.$post is undefined, resorting to this for now
|
|
15
|
+
const response = await client.post(args.otpInitPath || consts_js_1.TURNKEY_OTP_INIT_PATH, {
|
|
16
|
+
targetPublicKey,
|
|
17
|
+
email: args.email,
|
|
18
|
+
suborgId: args.subOrgId,
|
|
19
|
+
invalidateExistingSessions: args.invalidateExistingSessions,
|
|
20
|
+
});
|
|
21
|
+
return response?.data;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
25
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
26
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
27
|
+
contextModule: 'turnkey-init-email-otp',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static async confirmEmailOTP(args) {
|
|
32
|
+
const { client, iframeClient } = args;
|
|
33
|
+
try {
|
|
34
|
+
const organizationId = args.organizationId;
|
|
35
|
+
const emailOTPId = args.emailOTPId;
|
|
36
|
+
const targetPublicKey = iframeClient.iframePublicKey;
|
|
37
|
+
const otpVerifyPath = args.otpVerifyPath || consts_js_1.TURNKEY_OTP_VERIFY_PATH;
|
|
38
|
+
if (!targetPublicKey) {
|
|
39
|
+
throw new exceptions_1.WalletException(new Error('Target public key not found'));
|
|
40
|
+
}
|
|
41
|
+
if (!emailOTPId) {
|
|
42
|
+
throw new exceptions_1.WalletException(new Error('Email OTP ID is required'));
|
|
43
|
+
}
|
|
44
|
+
if (!organizationId) {
|
|
45
|
+
throw new exceptions_1.WalletException(new Error('Organization ID is required'));
|
|
46
|
+
}
|
|
47
|
+
const response = await client.post(otpVerifyPath, {
|
|
48
|
+
targetPublicKey,
|
|
49
|
+
otpId: emailOTPId,
|
|
50
|
+
otpCode: args.otpCode,
|
|
51
|
+
suborgID: organizationId,
|
|
52
|
+
});
|
|
53
|
+
return response?.data;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
57
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
58
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
59
|
+
contextModule: 'turnkey-confirm-email-otp',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.TurnkeyOtpWallet = TurnkeyOtpWallet;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Turnkey, TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
2
|
+
import { TurnkeyMetadata } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { HttpRestClient } from '@injectivelabs/utils';
|
|
4
|
+
export declare class TurnkeyWallet {
|
|
5
|
+
protected iframeClient: TurnkeyIframeClient | undefined;
|
|
6
|
+
protected turnkey: Turnkey | undefined;
|
|
7
|
+
protected client: HttpRestClient;
|
|
8
|
+
private metadata;
|
|
9
|
+
private accountMap;
|
|
10
|
+
setMetadata(metadata: Partial<TurnkeyMetadata>): void;
|
|
11
|
+
constructor(metadata: TurnkeyMetadata);
|
|
12
|
+
static getTurnkeyInstance(metadata: TurnkeyMetadata): Promise<{
|
|
13
|
+
turnkey: Turnkey;
|
|
14
|
+
iframeClient: TurnkeyIframeClient;
|
|
15
|
+
}>;
|
|
16
|
+
getTurnkey(): Promise<Turnkey>;
|
|
17
|
+
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
18
|
+
getSession(existingCredentialBundle?: string): Promise<{
|
|
19
|
+
session: import("@turnkey/sdk-browser").Session | undefined;
|
|
20
|
+
organizationId: string;
|
|
21
|
+
}>;
|
|
22
|
+
getAccounts(): Promise<string[]>;
|
|
23
|
+
getOrCreateAndGetAccount(address: string, organizationId?: string): Promise<{
|
|
24
|
+
address: import("abitype").Address;
|
|
25
|
+
nonceManager?: import("viem").NonceManager | undefined;
|
|
26
|
+
sign?: ((parameters: {
|
|
27
|
+
hash: import("viem").Hash;
|
|
28
|
+
}) => Promise<import("viem").Hex>) | undefined | undefined;
|
|
29
|
+
signAuthorization?: ((parameters: import("viem/_types/types/authorization.js").AuthorizationRequest) => Promise<import("viem/accounts").SignAuthorizationReturnType>) | undefined | undefined;
|
|
30
|
+
signMessage: ({ message }: {
|
|
31
|
+
message: import("viem").SignableMessage;
|
|
32
|
+
}) => Promise<import("viem").Hex>;
|
|
33
|
+
signTransaction: <serializer extends import("viem").SerializeTransactionFn<import("viem").TransactionSerializable> = import("viem").SerializeTransactionFn<import("viem").TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
|
|
34
|
+
serializer?: serializer | undefined;
|
|
35
|
+
} | undefined) => Promise<import("viem").IsNarrowable<import("viem").TransactionSerialized<import("viem").GetTransactionType<transaction>>, import("viem").Hex> extends true ? import("viem").TransactionSerialized<import("viem").GetTransactionType<transaction>> : import("viem").Hex>;
|
|
36
|
+
signTypedData: <const typedData extends import("abitype").TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: import("viem").TypedDataDefinition<typedData, primaryType>) => Promise<import("viem").Hex>;
|
|
37
|
+
publicKey: import("viem").Hex;
|
|
38
|
+
source: string;
|
|
39
|
+
type: "local";
|
|
40
|
+
}>;
|
|
41
|
+
injectAndRefresh(credentialBundle: string): Promise<void>;
|
|
42
|
+
private initFrame;
|
|
43
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurnkeyWallet = void 0;
|
|
4
|
+
const sdk_browser_1 = require("@turnkey/sdk-browser");
|
|
5
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
6
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
7
|
+
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
8
|
+
const utils_1 = require("@injectivelabs/utils");
|
|
9
|
+
const viem_1 = require("@turnkey/viem");
|
|
10
|
+
const types_js_1 = require("../types.js");
|
|
11
|
+
class TurnkeyWallet {
|
|
12
|
+
iframeClient;
|
|
13
|
+
turnkey;
|
|
14
|
+
client;
|
|
15
|
+
metadata;
|
|
16
|
+
accountMap = {};
|
|
17
|
+
setMetadata(metadata) {
|
|
18
|
+
this.metadata = { ...this.metadata, ...metadata };
|
|
19
|
+
}
|
|
20
|
+
constructor(metadata) {
|
|
21
|
+
this.metadata = metadata;
|
|
22
|
+
this.client = new utils_1.HttpRestClient(metadata.apiServerEndpoint);
|
|
23
|
+
}
|
|
24
|
+
static async getTurnkeyInstance(metadata) {
|
|
25
|
+
const { turnkey, iframeClient } = await createTurnkeyIFrame(metadata);
|
|
26
|
+
return {
|
|
27
|
+
turnkey,
|
|
28
|
+
iframeClient,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async getTurnkey() {
|
|
32
|
+
if (!this.iframeClient) {
|
|
33
|
+
await this.initFrame();
|
|
34
|
+
}
|
|
35
|
+
if (!this.turnkey) {
|
|
36
|
+
this.turnkey = new sdk_browser_1.Turnkey(this.metadata);
|
|
37
|
+
}
|
|
38
|
+
return this.turnkey;
|
|
39
|
+
}
|
|
40
|
+
async getIframeClient() {
|
|
41
|
+
if (!this.iframeClient) {
|
|
42
|
+
await this.initFrame();
|
|
43
|
+
}
|
|
44
|
+
if (!this.iframeClient) {
|
|
45
|
+
throw new exceptions_1.WalletException(new Error('Iframe client not initialized'));
|
|
46
|
+
}
|
|
47
|
+
return this.iframeClient;
|
|
48
|
+
}
|
|
49
|
+
async getSession(existingCredentialBundle) {
|
|
50
|
+
const { metadata } = this;
|
|
51
|
+
const iframeClient = await this.getIframeClient();
|
|
52
|
+
const turnkey = await this.getTurnkey();
|
|
53
|
+
const currentSession = await turnkey.getSession();
|
|
54
|
+
const organizationId = currentSession?.organizationId || metadata.defaultOrganizationId;
|
|
55
|
+
const credentialBundle = existingCredentialBundle || currentSession?.token;
|
|
56
|
+
if (!credentialBundle) {
|
|
57
|
+
return {
|
|
58
|
+
session: undefined,
|
|
59
|
+
organizationId,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const loginResult = await iframeClient.injectCredentialBundle(credentialBundle);
|
|
64
|
+
// If there is no session, we want to force a refresh to enable to browser SDK to handle key storage and proper session management.
|
|
65
|
+
await iframeClient.refreshSession({
|
|
66
|
+
sessionType: sdk_browser_1.SessionType.READ_WRITE,
|
|
67
|
+
targetPublicKey: iframeClient.iframePublicKey,
|
|
68
|
+
expirationSeconds: '900',
|
|
69
|
+
});
|
|
70
|
+
const [session, user] = await Promise.all([
|
|
71
|
+
turnkey.getSession(),
|
|
72
|
+
iframeClient.getWhoami(),
|
|
73
|
+
]);
|
|
74
|
+
const actualOrganizationId = user?.organizationId || session?.organizationId || organizationId;
|
|
75
|
+
if (!loginResult) {
|
|
76
|
+
return {
|
|
77
|
+
session: undefined,
|
|
78
|
+
organizationId: actualOrganizationId,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
session,
|
|
83
|
+
organizationId: actualOrganizationId,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
88
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
89
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
90
|
+
contextModule: 'turnkey-wallet-get-session',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async getAccounts() {
|
|
95
|
+
const iframeClient = await this.getIframeClient();
|
|
96
|
+
if (!this.metadata.organizationId) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const response = await iframeClient.getWallets({
|
|
101
|
+
organizationId: this.metadata.organizationId,
|
|
102
|
+
});
|
|
103
|
+
const accounts = await Promise.allSettled(response.wallets.map((wallet) => iframeClient.getWalletAccounts({
|
|
104
|
+
walletId: wallet.walletId,
|
|
105
|
+
organizationId: this.metadata.organizationId,
|
|
106
|
+
})));
|
|
107
|
+
const filteredAccounts = accounts
|
|
108
|
+
.filter((account) => account.status === 'fulfilled')
|
|
109
|
+
.flatMap((result) => result.value?.accounts)
|
|
110
|
+
.filter((wa) => !!wa &&
|
|
111
|
+
wa.addressFormat === 'ADDRESS_FORMAT_ETHEREUM' &&
|
|
112
|
+
!!wa.address);
|
|
113
|
+
return filteredAccounts.map((account) => (0, sdk_ts_1.getInjectiveAddress)(account.address));
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (e.code === types_js_1.TurnkeyErrorCodes.UserLoggedOut) {
|
|
117
|
+
throw new exceptions_1.WalletException(new Error('User is not logged in'), {
|
|
118
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
119
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
120
|
+
contextModule: wallet_base_1.WalletAction.GetAccounts,
|
|
121
|
+
contextCode: types_js_1.TurnkeyErrorCodes.UserLoggedOut,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
throw new exceptions_1.WalletException(new Error(e.message), {
|
|
125
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
126
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
127
|
+
contextModule: 'turnkey-wallet-get-accounts',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async getOrCreateAndGetAccount(address, organizationId) {
|
|
132
|
+
const { accountMap } = this;
|
|
133
|
+
const iframeClient = await this.getIframeClient();
|
|
134
|
+
if (accountMap[address] || accountMap[address.toLowerCase()]) {
|
|
135
|
+
return accountMap[address] || accountMap[address.toLowerCase()];
|
|
136
|
+
}
|
|
137
|
+
if (!organizationId) {
|
|
138
|
+
throw new exceptions_1.WalletException(new Error('Organization ID is required'));
|
|
139
|
+
}
|
|
140
|
+
iframeClient.config.organizationId = organizationId;
|
|
141
|
+
if (!address) {
|
|
142
|
+
throw new exceptions_1.WalletException(new Error('Account address not found'));
|
|
143
|
+
}
|
|
144
|
+
const turnkeyAccount = await (0, viem_1.createAccount)({
|
|
145
|
+
organizationId,
|
|
146
|
+
signWith: address,
|
|
147
|
+
client: iframeClient,
|
|
148
|
+
});
|
|
149
|
+
this.accountMap[address] = turnkeyAccount;
|
|
150
|
+
return turnkeyAccount;
|
|
151
|
+
}
|
|
152
|
+
async injectAndRefresh(credentialBundle) {
|
|
153
|
+
const iframeClient = await this.getIframeClient();
|
|
154
|
+
await iframeClient.injectCredentialBundle(credentialBundle);
|
|
155
|
+
await iframeClient.refreshSession({
|
|
156
|
+
sessionType: sdk_browser_1.SessionType.READ_WRITE,
|
|
157
|
+
targetPublicKey: iframeClient.iframePublicKey,
|
|
158
|
+
expirationSeconds: '900',
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
async initFrame() {
|
|
163
|
+
const { metadata } = this;
|
|
164
|
+
const { turnkey, iframeClient } = await createTurnkeyIFrame(metadata);
|
|
165
|
+
this.turnkey = turnkey;
|
|
166
|
+
this.iframeClient = iframeClient;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.TurnkeyWallet = TurnkeyWallet;
|
|
170
|
+
async function createTurnkeyIFrame(metadata) {
|
|
171
|
+
const turnkey = new sdk_browser_1.Turnkey(metadata);
|
|
172
|
+
const turnkeyAuthIframeElementId = metadata.iframeElementId || 'turnkey-auth-iframe-element-id';
|
|
173
|
+
if (!metadata.iframeContainerId) {
|
|
174
|
+
throw new exceptions_1.GeneralException(new Error('iframeContainerId is required'));
|
|
175
|
+
}
|
|
176
|
+
if (!turnkey) {
|
|
177
|
+
throw new exceptions_1.GeneralException(new Error('Turnkey is not initialized'));
|
|
178
|
+
}
|
|
179
|
+
const iframe = document.getElementById(metadata.iframeContainerId);
|
|
180
|
+
if (!iframe) {
|
|
181
|
+
throw new exceptions_1.GeneralException(new Error('iframe is null'));
|
|
182
|
+
}
|
|
183
|
+
const existingIframeClient = document.getElementById(turnkeyAuthIframeElementId);
|
|
184
|
+
if (existingIframeClient) {
|
|
185
|
+
existingIframeClient.remove();
|
|
186
|
+
}
|
|
187
|
+
const iframeClient = await turnkey.iframeClient({
|
|
188
|
+
iframeContainer: iframe,
|
|
189
|
+
iframeElementId: turnkeyAuthIframeElementId,
|
|
190
|
+
iframeUrl: metadata?.iframeUrl || 'https://auth.turnkey.com',
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
turnkey,
|
|
194
|
+
iframeClient,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum TurnkeyErrorCodes {
|
|
2
|
+
UserLoggedOut = 7
|
|
3
|
+
}
|
|
4
|
+
export type TurnkeyOAuthArgs = {
|
|
5
|
+
provider: 'google';
|
|
6
|
+
oidcToken: string;
|
|
7
|
+
oauthLoginEndpoint: string;
|
|
8
|
+
};
|
|
9
|
+
export type TurnkeyEmailArgs = {
|
|
10
|
+
provider: 'email';
|
|
11
|
+
email: string;
|
|
12
|
+
initEmailOTPEndpoint: string;
|
|
13
|
+
};
|
|
14
|
+
export type TurnkeyEnableArgs = TurnkeyOAuthArgs | TurnkeyEmailArgs;
|
|
15
|
+
export type TurnkeyOTPCredentialsResponse = {
|
|
16
|
+
otpId: string;
|
|
17
|
+
organizationId: string;
|
|
18
|
+
};
|
|
19
|
+
export type TurnkeyConfirmEmailOTPResponse = {
|
|
20
|
+
credentialBundle: string;
|
|
21
|
+
};
|
|
22
|
+
export type TurnkeyOauthLoginResponse = {
|
|
23
|
+
organizationId: string;
|
|
24
|
+
credentialBundle: string;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurnkeyErrorCodes = void 0;
|
|
4
|
+
var TurnkeyErrorCodes;
|
|
5
|
+
(function (TurnkeyErrorCodes) {
|
|
6
|
+
TurnkeyErrorCodes[TurnkeyErrorCodes["UserLoggedOut"] = 7] = "UserLoggedOut";
|
|
7
|
+
})(TurnkeyErrorCodes || (exports.TurnkeyErrorCodes = TurnkeyErrorCodes = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TxRaw, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { HttpRestClient } from '@injectivelabs/utils';
|
|
3
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { StdSignDoc, TurnkeyProvider, WalletDeviceType, type WalletMetadata, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
5
|
+
import { TurnkeyWallet } from '../turnkey/turnkey.js';
|
|
6
|
+
import { TurnkeyIframeClient } from '@turnkey/sdk-browser';
|
|
7
|
+
export declare class BaseTurnkeyWalletStrategy extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
8
|
+
turnkeyWallet: TurnkeyWallet | undefined;
|
|
9
|
+
turnkeyProvider: TurnkeyProvider;
|
|
10
|
+
client: HttpRestClient;
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
12
|
+
provider: TurnkeyProvider;
|
|
13
|
+
apiServerEndpoint?: string;
|
|
14
|
+
});
|
|
15
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
16
|
+
setMetadata(metadata?: {
|
|
17
|
+
turnkey?: Partial<WalletMetadata['turnkey']>;
|
|
18
|
+
}): void;
|
|
19
|
+
private setOrganizationId;
|
|
20
|
+
enable(): Promise<boolean>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
getAddresses(): Promise<string[]>;
|
|
23
|
+
getSessionOrConfirm(): Promise<string>;
|
|
24
|
+
sendEthereumTransaction(_transaction: unknown, _options: {
|
|
25
|
+
address: AccountAddress;
|
|
26
|
+
ethereumChainId: EthereumChainId;
|
|
27
|
+
}): Promise<string>;
|
|
28
|
+
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<any>;
|
|
29
|
+
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
30
|
+
signCosmosTransaction(_transaction: {
|
|
31
|
+
txRaw: TxRaw;
|
|
32
|
+
accountNumber: number;
|
|
33
|
+
chainId: string;
|
|
34
|
+
address: string;
|
|
35
|
+
}): Promise<DirectSignResponse>;
|
|
36
|
+
signAminoCosmosTransaction(_transaction: {
|
|
37
|
+
address: string;
|
|
38
|
+
signDoc: StdSignDoc;
|
|
39
|
+
}): Promise<AminoSignResponse>;
|
|
40
|
+
signArbitrary(_signer: AccountAddress, _data: string | Uint8Array): Promise<string>;
|
|
41
|
+
getEthereumChainId(): Promise<string>;
|
|
42
|
+
getEthereumTransactionReceipt(_txHash: string): Promise<string>;
|
|
43
|
+
getPubKey(): Promise<string>;
|
|
44
|
+
getIframeClient(): Promise<TurnkeyIframeClient>;
|
|
45
|
+
private getTurnkeyWallet;
|
|
46
|
+
private getOrganizationId;
|
|
47
|
+
}
|