@meshconnect/web-link-sdk 3.2.14 → 3.2.15
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/jest.setup.ts +4 -0
- package/package.json +20 -8
- package/src/Link.test.ts +434 -0
- package/src/Link.ts +491 -0
- package/src/index.ts +3 -0
- package/src/utils/__snapshots__/popup.test.ts.snap +89 -0
- package/src/utils/connectors/evm/chainConfigs.ts +120 -0
- package/src/utils/connectors/evm/chainSwitching.ts +165 -0
- package/src/utils/connectors/evm/index.ts +8 -0
- package/src/utils/connectors/evm/provider.ts +22 -0
- package/src/utils/connectors/evm/signing.ts +39 -0
- package/src/utils/connectors/evm/transactions.ts +356 -0
- package/src/utils/connectors/evm/types.ts +63 -0
- package/src/utils/connectors/evm/walletConnection.ts +140 -0
- package/src/utils/connectors/evm/walletDiscovery.ts +67 -0
- package/src/utils/connectors/solana/connection.ts +69 -0
- package/src/utils/connectors/solana/index.ts +5 -0
- package/src/utils/connectors/solana/providerDiscovery.ts +153 -0
- package/src/utils/connectors/solana/signing.ts +18 -0
- package/src/utils/connectors/solana/transaction.ts +382 -0
- package/src/utils/connectors/solana/types.ts +66 -0
- package/{utils/event-types.js → src/utils/event-types.test.ts} +15 -5
- package/src/utils/event-types.ts +350 -0
- package/src/utils/popup.test.ts +50 -0
- package/src/utils/popup.ts +123 -0
- package/src/utils/sdk-specs.test.ts +18 -0
- package/src/utils/sdk-specs.ts +7 -0
- package/src/utils/style.test.ts +33 -0
- package/src/utils/style.ts +15 -0
- package/src/utils/types.ts +270 -0
- package/src/utils/version.ts +1 -0
- package/src/utils/wallet/EVMWalletStrategy.ts +176 -0
- package/src/utils/wallet/SolanaWalletStrategy.ts +207 -0
- package/src/utils/wallet/WalletStrategy.ts +99 -0
- package/src/utils/wallet/WalletStrategyFactory.ts +46 -0
- package/src/utils/wallet/__tests__/EVMWalletStrategy.test.ts +233 -0
- package/src/utils/wallet/__tests__/SolanaWalletStrategy.test.ts +253 -0
- package/src/utils/wallet/__tests__/WalletStrategy.test.ts +77 -0
- package/src/utils/wallet/__tests__/WalletStrategyFactory.test.ts +65 -0
- package/src/utils/wallet/index.ts +4 -0
- package/src/utils/wallet-browser-event-types.ts +190 -0
- package/tools/copy.js +26 -0
- package/tools/update-version.js +10 -0
- package/tsconfig.json +14 -0
- package/Link.d.ts +0 -2
- package/Link.js +0 -530
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/utils/connectors/evm/chainConfigs.d.ts +0 -2
- package/utils/connectors/evm/chainConfigs.js +0 -115
- package/utils/connectors/evm/chainSwitching.d.ts +0 -15
- package/utils/connectors/evm/chainSwitching.js +0 -242
- package/utils/connectors/evm/index.d.ts +0 -8
- package/utils/connectors/evm/index.js +0 -8
- package/utils/connectors/evm/provider.d.ts +0 -6
- package/utils/connectors/evm/provider.js +0 -13
- package/utils/connectors/evm/signing.d.ts +0 -1
- package/utils/connectors/evm/signing.js +0 -78
- package/utils/connectors/evm/transactions.d.ts +0 -28
- package/utils/connectors/evm/transactions.js +0 -381
- package/utils/connectors/evm/types.d.ts +0 -57
- package/utils/connectors/evm/types.js +0 -1
- package/utils/connectors/evm/walletConnection.d.ts +0 -20
- package/utils/connectors/evm/walletConnection.js +0 -160
- package/utils/connectors/evm/walletDiscovery.d.ts +0 -10
- package/utils/connectors/evm/walletDiscovery.js +0 -55
- package/utils/connectors/solana/connection.d.ts +0 -4
- package/utils/connectors/solana/connection.js +0 -108
- package/utils/connectors/solana/index.d.ts +0 -5
- package/utils/connectors/solana/index.js +0 -5
- package/utils/connectors/solana/providerDiscovery.d.ts +0 -3
- package/utils/connectors/solana/providerDiscovery.js +0 -127
- package/utils/connectors/solana/signing.d.ts +0 -1
- package/utils/connectors/solana/signing.js +0 -59
- package/utils/connectors/solana/transaction.d.ts +0 -17
- package/utils/connectors/solana/transaction.js +0 -362
- package/utils/connectors/solana/types.d.ts +0 -71
- package/utils/connectors/solana/types.js +0 -8
- package/utils/event-types.d.ts +0 -233
- package/utils/popup.d.ts +0 -3
- package/utils/popup.js +0 -36
- package/utils/sdk-specs.d.ts +0 -5
- package/utils/sdk-specs.js +0 -6
- package/utils/style.d.ts +0 -3
- package/utils/style.js +0 -13
- package/utils/types.d.ts +0 -234
- package/utils/types.js +0 -1
- package/utils/version.d.ts +0 -1
- package/utils/version.js +0 -1
- package/utils/wallet/EVMWalletStrategy.d.ts +0 -31
- package/utils/wallet/EVMWalletStrategy.js +0 -265
- package/utils/wallet/SolanaWalletStrategy.d.ts +0 -33
- package/utils/wallet/SolanaWalletStrategy.js +0 -293
- package/utils/wallet/WalletStrategy.d.ts +0 -61
- package/utils/wallet/WalletStrategy.js +0 -25
- package/utils/wallet/WalletStrategyFactory.d.ts +0 -15
- package/utils/wallet/WalletStrategyFactory.js +0 -31
- package/utils/wallet/index.d.ts +0 -4
- package/utils/wallet/index.js +0 -4
- package/utils/wallet-browser-event-types.d.ts +0 -116
- package/utils/wallet-browser-event-types.js +0 -17
@@ -0,0 +1,382 @@
|
|
1
|
+
import {
|
2
|
+
PublicKey,
|
3
|
+
SystemProgram,
|
4
|
+
TransactionMessage,
|
5
|
+
VersionedTransaction,
|
6
|
+
TransactionInstruction
|
7
|
+
} from '@meshconnect/solana-web3.js'
|
8
|
+
import { getSolanaProvider } from './providerDiscovery'
|
9
|
+
import { TransactionConfig, SolanaProvider } from './types'
|
10
|
+
import {
|
11
|
+
SolanaAccountMeta,
|
12
|
+
SolanaTransferWithInstructionsPayload,
|
13
|
+
TransactionInstructionDto
|
14
|
+
} from '../../../utils/types'
|
15
|
+
|
16
|
+
const TOKEN_PROGRAM_ID = new PublicKey(
|
17
|
+
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
|
18
|
+
)
|
19
|
+
const TOKEN_2022_PROGRAM_ID = new PublicKey(
|
20
|
+
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'
|
21
|
+
)
|
22
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey(
|
23
|
+
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
|
24
|
+
)
|
25
|
+
|
26
|
+
const isUserRejection = (error: unknown): boolean => {
|
27
|
+
if (!error || typeof error !== 'object') return false
|
28
|
+
const err = error as Record<string, any>
|
29
|
+
const message = (err.message || '').toLowerCase()
|
30
|
+
return (
|
31
|
+
message.includes('user rejected') ||
|
32
|
+
message.includes('declined') ||
|
33
|
+
message.includes('cancelled') ||
|
34
|
+
message.includes('denied') ||
|
35
|
+
err.code === 4001
|
36
|
+
)
|
37
|
+
}
|
38
|
+
|
39
|
+
export async function getAssociatedTokenAddress(
|
40
|
+
mint: PublicKey,
|
41
|
+
owner: PublicKey,
|
42
|
+
programId = TOKEN_PROGRAM_ID.toBase58()
|
43
|
+
): Promise<PublicKey> {
|
44
|
+
const [address] = await PublicKey.findProgramAddress(
|
45
|
+
[owner.toBuffer(), new PublicKey(programId).toBuffer(), mint.toBuffer()],
|
46
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
47
|
+
)
|
48
|
+
return address
|
49
|
+
}
|
50
|
+
|
51
|
+
function createTokenAccountInstruction(
|
52
|
+
payer: PublicKey,
|
53
|
+
associatedToken: PublicKey,
|
54
|
+
owner: PublicKey,
|
55
|
+
mint: PublicKey,
|
56
|
+
programId = TOKEN_PROGRAM_ID
|
57
|
+
): TransactionInstruction {
|
58
|
+
const keys = [
|
59
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
60
|
+
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
61
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
62
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
63
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
64
|
+
{ pubkey: programId, isSigner: false, isWritable: false }
|
65
|
+
]
|
66
|
+
|
67
|
+
return new TransactionInstruction({
|
68
|
+
keys,
|
69
|
+
programId: ASSOCIATED_TOKEN_PROGRAM_ID,
|
70
|
+
data: Buffer.alloc(0)
|
71
|
+
})
|
72
|
+
}
|
73
|
+
|
74
|
+
export function createTransferCheckedInstruction(
|
75
|
+
fromTokenAccount: PublicKey,
|
76
|
+
toTokenAccount: PublicKey,
|
77
|
+
owner: PublicKey,
|
78
|
+
amount: bigint,
|
79
|
+
decimals = 9,
|
80
|
+
tokenMint: PublicKey
|
81
|
+
): TransactionInstruction {
|
82
|
+
const data = Buffer.alloc(10)
|
83
|
+
data[0] = 12 // TransferChecked instruction enum
|
84
|
+
data.writeBigUInt64LE(amount, 1) // 8-byte amount
|
85
|
+
data[9] = decimals // single-byte decimal
|
86
|
+
|
87
|
+
const programId = TOKEN_2022_PROGRAM_ID
|
88
|
+
|
89
|
+
return new TransactionInstruction({
|
90
|
+
keys: [
|
91
|
+
{ pubkey: fromTokenAccount, isSigner: false, isWritable: true },
|
92
|
+
{ pubkey: tokenMint, isSigner: false, isWritable: false },
|
93
|
+
{ pubkey: toTokenAccount, isSigner: false, isWritable: true },
|
94
|
+
{ pubkey: owner, isSigner: true, isWritable: false }
|
95
|
+
],
|
96
|
+
programId,
|
97
|
+
data
|
98
|
+
})
|
99
|
+
}
|
100
|
+
|
101
|
+
export function createSPLTransferInstruction({
|
102
|
+
fromTokenAccount,
|
103
|
+
toTokenAccount,
|
104
|
+
owner,
|
105
|
+
amount
|
106
|
+
}: {
|
107
|
+
fromTokenAccount: PublicKey
|
108
|
+
toTokenAccount: PublicKey
|
109
|
+
owner: PublicKey
|
110
|
+
amount: bigint
|
111
|
+
}): TransactionInstruction {
|
112
|
+
const data = Buffer.alloc(9)
|
113
|
+
data[0] = 3 // Transfer instruction
|
114
|
+
data.writeBigUInt64LE(amount, 1)
|
115
|
+
|
116
|
+
return new TransactionInstruction({
|
117
|
+
keys: [
|
118
|
+
{ pubkey: fromTokenAccount, isSigner: false, isWritable: true },
|
119
|
+
{ pubkey: toTokenAccount, isSigner: false, isWritable: true },
|
120
|
+
{ pubkey: owner, isSigner: true, isWritable: false }
|
121
|
+
],
|
122
|
+
programId: TOKEN_PROGRAM_ID,
|
123
|
+
data
|
124
|
+
})
|
125
|
+
}
|
126
|
+
|
127
|
+
export async function createTransferTransaction(
|
128
|
+
config: TransactionConfig
|
129
|
+
): Promise<VersionedTransaction> {
|
130
|
+
const instructions = await createTransferInstructions(config)
|
131
|
+
|
132
|
+
const fromPubkey = new PublicKey(config.fromAddress)
|
133
|
+
|
134
|
+
const messageV0 = new TransactionMessage({
|
135
|
+
payerKey: fromPubkey,
|
136
|
+
recentBlockhash: config.blockhash,
|
137
|
+
instructions
|
138
|
+
}).compileToV0Message()
|
139
|
+
|
140
|
+
return new VersionedTransaction(messageV0)
|
141
|
+
}
|
142
|
+
|
143
|
+
async function createTransferInstructions(config: TransactionConfig) {
|
144
|
+
const fromPubkey = new PublicKey(config.fromAddress)
|
145
|
+
const toPubkey = new PublicKey(config.toAddress)
|
146
|
+
const instructions: TransactionInstruction[] = []
|
147
|
+
|
148
|
+
if (!config.tokenMint) {
|
149
|
+
instructions.push(
|
150
|
+
SystemProgram.transfer({
|
151
|
+
fromPubkey,
|
152
|
+
toPubkey,
|
153
|
+
lamports: Number(config.amount)
|
154
|
+
})
|
155
|
+
)
|
156
|
+
} else {
|
157
|
+
const tokenMintPubkey = new PublicKey(config.tokenMint)
|
158
|
+
|
159
|
+
const fromTokenAccount = await getAssociatedTokenAddress(
|
160
|
+
tokenMintPubkey,
|
161
|
+
fromPubkey,
|
162
|
+
config.tokenProgram
|
163
|
+
)
|
164
|
+
|
165
|
+
const toTokenAccount = await getAssociatedTokenAddress(
|
166
|
+
tokenMintPubkey,
|
167
|
+
toPubkey,
|
168
|
+
config.tokenProgram
|
169
|
+
)
|
170
|
+
|
171
|
+
if (config.createATA) {
|
172
|
+
instructions.push(
|
173
|
+
createTokenAccountInstruction(
|
174
|
+
fromPubkey,
|
175
|
+
toTokenAccount,
|
176
|
+
toPubkey,
|
177
|
+
tokenMintPubkey,
|
178
|
+
config.tokenProgram
|
179
|
+
? new PublicKey(config.tokenProgram)
|
180
|
+
: TOKEN_PROGRAM_ID
|
181
|
+
)
|
182
|
+
)
|
183
|
+
}
|
184
|
+
|
185
|
+
if (config.tokenProgram === TOKEN_2022_PROGRAM_ID.toBase58()) {
|
186
|
+
instructions.push(
|
187
|
+
createTransferCheckedInstruction(
|
188
|
+
fromTokenAccount,
|
189
|
+
toTokenAccount,
|
190
|
+
fromPubkey,
|
191
|
+
BigInt(config.amount),
|
192
|
+
config.tokenDecimals,
|
193
|
+
tokenMintPubkey
|
194
|
+
)
|
195
|
+
)
|
196
|
+
} else {
|
197
|
+
instructions.push(
|
198
|
+
createSPLTransferInstruction({
|
199
|
+
fromTokenAccount,
|
200
|
+
toTokenAccount,
|
201
|
+
owner: fromPubkey,
|
202
|
+
amount: BigInt(config.amount)
|
203
|
+
})
|
204
|
+
)
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return instructions
|
208
|
+
}
|
209
|
+
|
210
|
+
export async function handleManualSignAndSend(
|
211
|
+
transaction: VersionedTransaction,
|
212
|
+
provider: SolanaProvider
|
213
|
+
): Promise<string> {
|
214
|
+
try {
|
215
|
+
if (provider.signAndSendTransaction) {
|
216
|
+
const { signature } = await provider.signAndSendTransaction(transaction)
|
217
|
+
return signature
|
218
|
+
} else {
|
219
|
+
const signedTransaction = await provider.signTransaction(transaction)
|
220
|
+
if (!provider.sendTransaction) {
|
221
|
+
throw new Error('Provider does not support sendTransaction')
|
222
|
+
}
|
223
|
+
const signature = await provider.sendTransaction(signedTransaction)
|
224
|
+
return signature
|
225
|
+
}
|
226
|
+
} catch (error: unknown) {
|
227
|
+
console.error('Error in handleManualSignAndSend:', error)
|
228
|
+
if (error instanceof Error && error.message?.includes('User rejected')) {
|
229
|
+
throw new Error('Transaction was rejected by user')
|
230
|
+
}
|
231
|
+
throw error
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
export async function getTransferInstructions(
|
236
|
+
instructions: TransactionInstructionDto[]
|
237
|
+
): Promise<TransactionInstruction[]> {
|
238
|
+
const result: TransactionInstruction[] = []
|
239
|
+
|
240
|
+
for (let instrIndex = 0; instrIndex < instructions.length; instrIndex++) {
|
241
|
+
const ix = instructions[instrIndex]
|
242
|
+
const programId = new PublicKey(ix.programId)
|
243
|
+
|
244
|
+
const keys = ix.accounts.map(
|
245
|
+
(meta: SolanaAccountMeta, accountIndex: number) => {
|
246
|
+
if (!meta.pubKey) {
|
247
|
+
throw new Error(
|
248
|
+
`Account at instruction ${instrIndex}, index ${accountIndex} has no pubKey and is not fillable`
|
249
|
+
)
|
250
|
+
}
|
251
|
+
|
252
|
+
const resolvedPubkey: PublicKey = new PublicKey(meta.pubKey)
|
253
|
+
return {
|
254
|
+
pubkey: resolvedPubkey,
|
255
|
+
isSigner: meta.isSigner,
|
256
|
+
isWritable: meta.isWritable
|
257
|
+
}
|
258
|
+
}
|
259
|
+
)
|
260
|
+
|
261
|
+
result.push(
|
262
|
+
new TransactionInstruction({
|
263
|
+
keys,
|
264
|
+
programId,
|
265
|
+
data: Buffer.from(ix.data, 'base64')
|
266
|
+
})
|
267
|
+
)
|
268
|
+
}
|
269
|
+
|
270
|
+
return result
|
271
|
+
}
|
272
|
+
|
273
|
+
export const sendSOLTransaction = async (
|
274
|
+
config: TransactionConfig
|
275
|
+
): Promise<string> => {
|
276
|
+
try {
|
277
|
+
const provider = getSolanaProvider(config.walletName)
|
278
|
+
const transaction = await createTransferTransaction(config)
|
279
|
+
|
280
|
+
const isManualWallet =
|
281
|
+
(provider as any).isTrust ||
|
282
|
+
(provider as any).isTrustWallet ||
|
283
|
+
config.walletName.toLowerCase().includes('trust')
|
284
|
+
|
285
|
+
if (isManualWallet) {
|
286
|
+
return await handleManualSignAndSend(transaction, provider)
|
287
|
+
}
|
288
|
+
|
289
|
+
if (provider.signAndSendTransaction) {
|
290
|
+
try {
|
291
|
+
const { signature }: { signature: string } =
|
292
|
+
await provider.signAndSendTransaction(transaction)
|
293
|
+
|
294
|
+
// @TODO: validate that signature was a successful tx
|
295
|
+
return signature
|
296
|
+
} catch (error) {
|
297
|
+
if (isUserRejection(error)) {
|
298
|
+
throw new Error('Transaction was rejected by user')
|
299
|
+
}
|
300
|
+
return handleManualSignAndSend(transaction, provider)
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
return handleManualSignAndSend(transaction, provider)
|
305
|
+
} catch (error) {
|
306
|
+
if (isUserRejection(error)) {
|
307
|
+
throw new Error('Transaction was rejected by user')
|
308
|
+
}
|
309
|
+
throw error instanceof Error
|
310
|
+
? error
|
311
|
+
: new Error(
|
312
|
+
`Failed to send SOL transaction with ${config.walletName} wallet`
|
313
|
+
)
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
export const sendSOLTransactionWithInstructions = async (
|
318
|
+
payload: SolanaTransferWithInstructionsPayload,
|
319
|
+
transferConfig: TransactionConfig
|
320
|
+
): Promise<string> => {
|
321
|
+
const walletName = payload.transactionInstructions.walletName || 'Phantom'
|
322
|
+
|
323
|
+
try {
|
324
|
+
const instructions = await getTransferInstructions(
|
325
|
+
payload.transactionInstructions.instructions
|
326
|
+
)
|
327
|
+
|
328
|
+
const fromPubkey = new PublicKey(transferConfig.fromAddress)
|
329
|
+
|
330
|
+
const transferInstructions = await createTransferInstructions(
|
331
|
+
transferConfig
|
332
|
+
)
|
333
|
+
|
334
|
+
instructions.push(...transferInstructions)
|
335
|
+
|
336
|
+
const transaction = new VersionedTransaction(
|
337
|
+
new TransactionMessage({
|
338
|
+
payerKey: fromPubkey,
|
339
|
+
recentBlockhash: payload.transactionInstructions.blockhash,
|
340
|
+
instructions: instructions
|
341
|
+
}).compileToV0Message()
|
342
|
+
)
|
343
|
+
|
344
|
+
return await sendSolanaTransfer(walletName, transaction)
|
345
|
+
} catch (error) {
|
346
|
+
if (isUserRejection(error)) {
|
347
|
+
throw new Error('Transaction was rejected by user')
|
348
|
+
}
|
349
|
+
throw error instanceof Error
|
350
|
+
? error
|
351
|
+
: new Error(`Failed to send SOL transaction with ${walletName} wallet`)
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
export const sendSolanaTransfer = async (
|
356
|
+
walletName: string,
|
357
|
+
transaction: VersionedTransaction
|
358
|
+
): Promise<string> => {
|
359
|
+
const provider = getSolanaProvider(walletName)
|
360
|
+
const isManualWallet =
|
361
|
+
(provider as any).isTrust ||
|
362
|
+
(provider as any).isTrustWallet ||
|
363
|
+
walletName.includes('trust')
|
364
|
+
|
365
|
+
if (isManualWallet) {
|
366
|
+
return await handleManualSignAndSend(transaction, provider)
|
367
|
+
}
|
368
|
+
|
369
|
+
if (provider.signAndSendTransaction) {
|
370
|
+
try {
|
371
|
+
const { signature }: { signature: string } =
|
372
|
+
await provider.signAndSendTransaction(transaction)
|
373
|
+
return signature
|
374
|
+
} catch (error) {
|
375
|
+
if (isUserRejection(error)) {
|
376
|
+
throw new Error('Transaction was rejected by user')
|
377
|
+
}
|
378
|
+
return handleManualSignAndSend(transaction, provider)
|
379
|
+
}
|
380
|
+
}
|
381
|
+
return handleManualSignAndSend(transaction, provider)
|
382
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { Transaction, VersionedTransaction } from '@meshconnect/solana-web3.js'
|
2
|
+
|
3
|
+
export enum SolanaWalletType {
|
4
|
+
PHANTOM = 'phantom',
|
5
|
+
SOLFLARE = 'solflare',
|
6
|
+
TRUST = 'trustwallet',
|
7
|
+
EXODUS = 'exodus',
|
8
|
+
UNKNOWN = 'unknown'
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface SolanaConnectResult {
|
12
|
+
accounts: string[]
|
13
|
+
chainId: string
|
14
|
+
isConnected: boolean
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface SolanaProvider {
|
18
|
+
connect(options?: {
|
19
|
+
onlyIfTrusted?: boolean
|
20
|
+
}): Promise<{ publicKey: { toString(): string; toBase58(): string } }>
|
21
|
+
disconnect(): Promise<void>
|
22
|
+
walletType?: SolanaWalletType
|
23
|
+
isConnected?: boolean
|
24
|
+
publicKey?: { toString(): string; toBase58(): string }
|
25
|
+
on(
|
26
|
+
event: 'connect' | 'disconnect' | 'accountChanged',
|
27
|
+
callback: (publicKey?: any) => void
|
28
|
+
): void
|
29
|
+
signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>
|
30
|
+
signTransaction(
|
31
|
+
transaction: Transaction | VersionedTransaction
|
32
|
+
): Promise<Transaction | VersionedTransaction>
|
33
|
+
signAndSendTransaction?(
|
34
|
+
transaction: Transaction | VersionedTransaction
|
35
|
+
): Promise<{ signature: string }>
|
36
|
+
sendTransaction?(
|
37
|
+
transaction: Transaction | VersionedTransaction
|
38
|
+
): Promise<string>
|
39
|
+
// Wallet checks
|
40
|
+
isPhantom?: boolean
|
41
|
+
isSolflare?: boolean
|
42
|
+
isTrust?: boolean
|
43
|
+
isTrustWallet?: boolean
|
44
|
+
isExodus?: boolean
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface WindowWithSolanaProviders extends Window {
|
48
|
+
solana?: SolanaProvider
|
49
|
+
phantom?: { solana?: SolanaProvider }
|
50
|
+
exodus?: { solana?: SolanaProvider }
|
51
|
+
trustwallet?: { solana?: SolanaProvider }
|
52
|
+
solflare?: SolanaProvider
|
53
|
+
[key: string]: { solana?: SolanaProvider } | SolanaProvider | undefined | any
|
54
|
+
}
|
55
|
+
|
56
|
+
export interface TransactionConfig {
|
57
|
+
toAddress: string
|
58
|
+
amount: bigint
|
59
|
+
fromAddress: string
|
60
|
+
blockhash: string
|
61
|
+
walletName: string
|
62
|
+
tokenMint?: string
|
63
|
+
createATA?: boolean
|
64
|
+
tokenProgram?: string
|
65
|
+
tokenDecimals?: number
|
66
|
+
}
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
import { isLinkEventTypeKey } from './event-types'
|
2
|
+
|
3
|
+
describe('Event types tests', () => {
|
4
|
+
test.each([
|
2
5
|
'integrationConnected',
|
3
6
|
'integrationConnectionError',
|
4
7
|
'integrationMfaRequired',
|
@@ -38,7 +41,14 @@ var LINK_EVENT_TYPE_KEYS = [
|
|
38
41
|
'fundingOptionsUpdated',
|
39
42
|
'fundingOptionsViewed',
|
40
43
|
'gasIncreaseWarning'
|
41
|
-
]
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
])(
|
45
|
+
'isLinkEventTypeKey should return true if parameter is "%s"',
|
46
|
+
eventType => {
|
47
|
+
expect(isLinkEventTypeKey(eventType)).toBe(true)
|
48
|
+
}
|
49
|
+
)
|
50
|
+
|
51
|
+
test('isLinkEventTypeKey should return false if parameter is not event', () => {
|
52
|
+
expect(isLinkEventTypeKey('test')).toBe(false)
|
53
|
+
})
|
54
|
+
})
|