@solana/kora 0.0.0 → 0.1.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/README.md +60 -0
- package/dist/src/client.d.ts +187 -0
- package/dist/src/client.js +287 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/types/index.d.ts +383 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/transaction.d.ts +8 -0
- package/dist/src/utils/transaction.js +32 -0
- package/dist/test/auth-setup.d.ts +1 -0
- package/dist/test/auth-setup.js +51 -0
- package/dist/test/integration.test.d.ts +1 -0
- package/dist/test/integration.test.js +307 -0
- package/dist/test/setup.d.ts +26 -0
- package/dist/test/setup.js +229 -0
- package/dist/test/unit.test.d.ts +1 -0
- package/dist/test/unit.test.js +552 -0
- package/package.json +59 -7
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Instruction } from '@solana/kit';
|
|
2
|
+
/**
|
|
3
|
+
* Request Types
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for creating a token transfer transaction.
|
|
7
|
+
*/
|
|
8
|
+
export interface TransferTransactionRequest {
|
|
9
|
+
/** Amount to transfer in the token's smallest unit (e.g., lamports for SOL) */
|
|
10
|
+
amount: number;
|
|
11
|
+
/** Mint address of the token to transfer */
|
|
12
|
+
token: string;
|
|
13
|
+
/** Public key of the source wallet (not token account) */
|
|
14
|
+
source: string;
|
|
15
|
+
/** Public key of the destination wallet (not token account) */
|
|
16
|
+
destination: string;
|
|
17
|
+
/** Optional signer address for the transaction */
|
|
18
|
+
signer_key?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parameters for signing a transaction.
|
|
22
|
+
*/
|
|
23
|
+
export interface SignTransactionRequest {
|
|
24
|
+
/** Base64-encoded transaction to sign */
|
|
25
|
+
transaction: string;
|
|
26
|
+
/** Optional signer address for the transaction */
|
|
27
|
+
signer_key?: string;
|
|
28
|
+
/** Optional signer verification during transaction simulation (defaults to false) */
|
|
29
|
+
sig_verify?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for signing and sending a transaction.
|
|
33
|
+
*/
|
|
34
|
+
export interface SignAndSendTransactionRequest {
|
|
35
|
+
/** Base64-encoded transaction to sign and send */
|
|
36
|
+
transaction: string;
|
|
37
|
+
/** Optional signer address for the transaction */
|
|
38
|
+
signer_key?: string;
|
|
39
|
+
/** Optional signer verification during transaction simulation (defaults to false) */
|
|
40
|
+
sig_verify?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parameters for estimating transaction fees.
|
|
44
|
+
*/
|
|
45
|
+
export interface EstimateTransactionFeeRequest {
|
|
46
|
+
/** Base64-encoded transaction to estimate fees for */
|
|
47
|
+
transaction: string;
|
|
48
|
+
/** Mint address of the token to calculate fees in */
|
|
49
|
+
fee_token: string;
|
|
50
|
+
/** Optional signer address for the transaction */
|
|
51
|
+
signer_key?: string;
|
|
52
|
+
/** Optional signer verification during transaction simulation (defaults to false) */
|
|
53
|
+
sig_verify?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parameters for getting a payment instruction.
|
|
57
|
+
*/
|
|
58
|
+
export interface GetPaymentInstructionRequest {
|
|
59
|
+
/** Base64-encoded transaction to estimate fees for */
|
|
60
|
+
transaction: string;
|
|
61
|
+
/** Mint address of the token to calculate fees in */
|
|
62
|
+
fee_token: string;
|
|
63
|
+
/** The wallet owner (not token account) that will be making the token payment */
|
|
64
|
+
source_wallet: string;
|
|
65
|
+
/** The token program id to use for the payment (defaults to TOKEN_PROGRAM_ID) */
|
|
66
|
+
token_program_id?: string;
|
|
67
|
+
/** Optional signer address for the transaction */
|
|
68
|
+
signer_key?: string;
|
|
69
|
+
/** Optional signer verification during transaction simulation (defaults to false) */
|
|
70
|
+
sig_verify?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Response Types
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Response from creating a transfer transaction.
|
|
77
|
+
*/
|
|
78
|
+
export interface TransferTransactionResponse {
|
|
79
|
+
/** Base64-encoded signed transaction */
|
|
80
|
+
transaction: string;
|
|
81
|
+
/** Base64-encoded message */
|
|
82
|
+
message: string;
|
|
83
|
+
/** Recent blockhash used in the transaction */
|
|
84
|
+
blockhash: string;
|
|
85
|
+
/** Public key of the signer used to send the transaction */
|
|
86
|
+
signer_pubkey: string;
|
|
87
|
+
/** Parsed instructions from the transaction message */
|
|
88
|
+
instructions: Instruction[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Response from signing a transaction.
|
|
92
|
+
*/
|
|
93
|
+
export interface SignTransactionResponse {
|
|
94
|
+
/** Base64-encoded signed transaction */
|
|
95
|
+
signed_transaction: string;
|
|
96
|
+
/** Public key of the signer used to sign the transaction */
|
|
97
|
+
signer_pubkey: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Response from signing and sending a transaction.
|
|
101
|
+
*/
|
|
102
|
+
export interface SignAndSendTransactionResponse {
|
|
103
|
+
/** Base64-encoded signed transaction */
|
|
104
|
+
signed_transaction: string;
|
|
105
|
+
/** Public key of the signer used to send the transaction */
|
|
106
|
+
signer_pubkey: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Response containing the latest blockhash.
|
|
110
|
+
*/
|
|
111
|
+
export interface GetBlockhashResponse {
|
|
112
|
+
/** Base58-encoded blockhash */
|
|
113
|
+
blockhash: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Response containing supported token mint addresses.
|
|
117
|
+
*/
|
|
118
|
+
export interface GetSupportedTokensResponse {
|
|
119
|
+
/** Array of supported token mint addresses */
|
|
120
|
+
tokens: string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Response containing estimated transaction fees.
|
|
124
|
+
*/
|
|
125
|
+
export interface EstimateTransactionFeeResponse {
|
|
126
|
+
/** Transaction fee in lamports */
|
|
127
|
+
fee_in_lamports: number;
|
|
128
|
+
/**
|
|
129
|
+
* Transaction fee in the requested token (in decimals value of the token, e.g. 10^6 for USDC)
|
|
130
|
+
*/
|
|
131
|
+
fee_in_token: number;
|
|
132
|
+
/** Public key of the signer used to estimate the fee */
|
|
133
|
+
signer_pubkey: string;
|
|
134
|
+
/** Public key of the payment destination */
|
|
135
|
+
payment_address: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Response containing the payer signer and payment destination.
|
|
139
|
+
*/
|
|
140
|
+
export interface GetPayerSignerResponse {
|
|
141
|
+
/** Public key of the payer signer */
|
|
142
|
+
signer_address: string;
|
|
143
|
+
/** Public key of the payment destination */
|
|
144
|
+
payment_address: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Response containing a payment instruction.
|
|
148
|
+
*/
|
|
149
|
+
export interface GetPaymentInstructionResponse {
|
|
150
|
+
/** Base64-encoded original transaction */
|
|
151
|
+
original_transaction: string;
|
|
152
|
+
/** Base64-encoded payment instruction */
|
|
153
|
+
payment_instruction: Instruction;
|
|
154
|
+
/** Payment amount in the requested token */
|
|
155
|
+
payment_amount: number;
|
|
156
|
+
/** Mint address of the token used for payment */
|
|
157
|
+
payment_token: string;
|
|
158
|
+
/** Public key of the payment destination */
|
|
159
|
+
payment_address: string;
|
|
160
|
+
/** Public key of the payer signer */
|
|
161
|
+
signer_address: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Configuration Types
|
|
165
|
+
*/
|
|
166
|
+
export type PriceSource = 'Jupiter' | 'Mock';
|
|
167
|
+
/**
|
|
168
|
+
* Validation configuration for the Kora server.
|
|
169
|
+
*/
|
|
170
|
+
export interface ValidationConfig {
|
|
171
|
+
/** Maximum allowed transaction value in lamports */
|
|
172
|
+
max_allowed_lamports: number;
|
|
173
|
+
/** Maximum number of signatures allowed per transaction */
|
|
174
|
+
max_signatures: number;
|
|
175
|
+
/** Price oracle source for token conversions */
|
|
176
|
+
price_source: PriceSource;
|
|
177
|
+
/** List of allowed Solana program IDs */
|
|
178
|
+
allowed_programs: string[];
|
|
179
|
+
/** List of allowed token mint addresses for fee payment */
|
|
180
|
+
allowed_tokens: string[];
|
|
181
|
+
/** List of SPL tokens accepted for paid transactions */
|
|
182
|
+
allowed_spl_paid_tokens: string[];
|
|
183
|
+
/** List of blocked account addresses */
|
|
184
|
+
disallowed_accounts: string[];
|
|
185
|
+
/** Policy controlling fee payer permissions */
|
|
186
|
+
fee_payer_policy: FeePayerPolicy;
|
|
187
|
+
/** Pricing model configuration */
|
|
188
|
+
price: PriceConfig;
|
|
189
|
+
/** Token2022 configuration */
|
|
190
|
+
token2022: Token2022Config;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Blocked extensions for Token2022.
|
|
194
|
+
*/
|
|
195
|
+
export interface Token2022Config {
|
|
196
|
+
/** List of blocked mint extensions */
|
|
197
|
+
blocked_mint_extensions: string[];
|
|
198
|
+
/** List of blocked account extensions */
|
|
199
|
+
blocked_account_extensions: string[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Pricing model for transaction fees.
|
|
203
|
+
* @remarks
|
|
204
|
+
* - `margin`: Adds a percentage margin to base fees
|
|
205
|
+
* - `fixed`: Charges a fixed amount in a specific token
|
|
206
|
+
* - `free`: No additional fees charged
|
|
207
|
+
*/
|
|
208
|
+
export type PriceModel = {
|
|
209
|
+
type: 'margin';
|
|
210
|
+
margin: number;
|
|
211
|
+
} | {
|
|
212
|
+
type: 'fixed';
|
|
213
|
+
amount: number;
|
|
214
|
+
token: string;
|
|
215
|
+
} | {
|
|
216
|
+
type: 'free';
|
|
217
|
+
};
|
|
218
|
+
export type PriceConfig = PriceModel;
|
|
219
|
+
/**
|
|
220
|
+
* Enabled status for methods for the Kora server.
|
|
221
|
+
*/
|
|
222
|
+
export interface EnabledMethods {
|
|
223
|
+
/** Whether the liveness method is enabled */
|
|
224
|
+
liveness: boolean;
|
|
225
|
+
/** Whether the estimate_transaction_fee method is enabled */
|
|
226
|
+
estimate_transaction_fee: boolean;
|
|
227
|
+
/** Whether the get_supported_tokens method is enabled */
|
|
228
|
+
get_supported_tokens: boolean;
|
|
229
|
+
/** Whether the sign_transaction method is enabled */
|
|
230
|
+
sign_transaction: boolean;
|
|
231
|
+
/** Whether the sign_and_send_transaction method is enabled */
|
|
232
|
+
sign_and_send_transaction: boolean;
|
|
233
|
+
/** Whether the transfer_transaction method is enabled */
|
|
234
|
+
transfer_transaction: boolean;
|
|
235
|
+
/** Whether the get_blockhash method is enabled */
|
|
236
|
+
get_blockhash: boolean;
|
|
237
|
+
/** Whether the get_config method is enabled */
|
|
238
|
+
get_config: boolean;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Kora server configuration.
|
|
242
|
+
*/
|
|
243
|
+
export interface Config {
|
|
244
|
+
/** Array of public keys of the fee payer accounts (signer pool) */
|
|
245
|
+
fee_payers: string[];
|
|
246
|
+
/** Validation rules and constraints */
|
|
247
|
+
validation_config: ValidationConfig;
|
|
248
|
+
/** Enabled methods */
|
|
249
|
+
enabled_methods: EnabledMethods;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Nonce instruction policy
|
|
253
|
+
*/
|
|
254
|
+
export interface NonceInstructionPolicy {
|
|
255
|
+
/** Allow fee payer to initialize nonce accounts */
|
|
256
|
+
allow_initialize: boolean;
|
|
257
|
+
/** Allow fee payer to advance nonce accounts */
|
|
258
|
+
allow_advance: boolean;
|
|
259
|
+
/** Allow fee payer to authorize nonce accounts */
|
|
260
|
+
allow_authorize: boolean;
|
|
261
|
+
/** Allow fee payer to withdraw from nonce accounts */
|
|
262
|
+
allow_withdraw: boolean;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* System instruction policy
|
|
266
|
+
*/
|
|
267
|
+
export interface SystemInstructionPolicy {
|
|
268
|
+
/** Allow fee payer to be the sender in System Transfer/TransferWithSeed */
|
|
269
|
+
allow_transfer: boolean;
|
|
270
|
+
/** Allow fee payer to be the authority in System Assign/AssignWithSeed */
|
|
271
|
+
allow_assign: boolean;
|
|
272
|
+
/** Allow fee payer to be the payer in System CreateAccount/CreateAccountWithSeed */
|
|
273
|
+
allow_create_account: boolean;
|
|
274
|
+
/** Allow fee payer to be the account in System Allocate/AllocateWithSeed */
|
|
275
|
+
allow_allocate: boolean;
|
|
276
|
+
/** Nested policy for nonce account operations */
|
|
277
|
+
nonce: NonceInstructionPolicy;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* SPL Token instruction policy
|
|
281
|
+
*/
|
|
282
|
+
export interface SplTokenInstructionPolicy {
|
|
283
|
+
/** Allow fee payer to be source in SPL token transfers */
|
|
284
|
+
allow_transfer: boolean;
|
|
285
|
+
/** Allow fee payer to burn SPL tokens */
|
|
286
|
+
allow_burn: boolean;
|
|
287
|
+
/** Allow fee payer to close SPL token accounts */
|
|
288
|
+
allow_close_account: boolean;
|
|
289
|
+
/** Allow fee payer to approve SPL token delegates */
|
|
290
|
+
allow_approve: boolean;
|
|
291
|
+
/** Allow fee payer to revoke SPL token delegates */
|
|
292
|
+
allow_revoke: boolean;
|
|
293
|
+
/** Allow fee payer to set authority on SPL token accounts */
|
|
294
|
+
allow_set_authority: boolean;
|
|
295
|
+
/** Allow fee payer to mint SPL tokens */
|
|
296
|
+
allow_mint_to: boolean;
|
|
297
|
+
/** Allow fee payer to freeze SPL token accounts */
|
|
298
|
+
allow_freeze_account: boolean;
|
|
299
|
+
/** Allow fee payer to thaw SPL token accounts */
|
|
300
|
+
allow_thaw_account: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Token2022 instruction policy
|
|
304
|
+
*/
|
|
305
|
+
export interface Token2022InstructionPolicy {
|
|
306
|
+
/** Allow fee payer to be source in Token2022 transfers */
|
|
307
|
+
allow_transfer: boolean;
|
|
308
|
+
/** Allow fee payer to burn Token2022 tokens */
|
|
309
|
+
allow_burn: boolean;
|
|
310
|
+
/** Allow fee payer to close Token2022 accounts */
|
|
311
|
+
allow_close_account: boolean;
|
|
312
|
+
/** Allow fee payer to approve Token2022 delegates */
|
|
313
|
+
allow_approve: boolean;
|
|
314
|
+
/** Allow fee payer to revoke Token2022 delegates */
|
|
315
|
+
allow_revoke: boolean;
|
|
316
|
+
/** Allow fee payer to set authority on Token2022 accounts */
|
|
317
|
+
allow_set_authority: boolean;
|
|
318
|
+
/** Allow fee payer to mint Token2022 tokens */
|
|
319
|
+
allow_mint_to: boolean;
|
|
320
|
+
/** Allow fee payer to freeze Token2022 accounts */
|
|
321
|
+
allow_freeze_account: boolean;
|
|
322
|
+
/** Allow fee payer to thaw Token2022 accounts */
|
|
323
|
+
allow_thaw_account: boolean;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Policy controlling what actions the fee payer can perform.
|
|
327
|
+
*/
|
|
328
|
+
export interface FeePayerPolicy {
|
|
329
|
+
/** System program instruction policies */
|
|
330
|
+
system: SystemInstructionPolicy;
|
|
331
|
+
/** SPL Token program instruction policies */
|
|
332
|
+
spl_token: SplTokenInstructionPolicy;
|
|
333
|
+
/** Token2022 program instruction policies */
|
|
334
|
+
token_2022: Token2022InstructionPolicy;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* RPC Types
|
|
338
|
+
*/
|
|
339
|
+
/**
|
|
340
|
+
* JSON-RPC error object.
|
|
341
|
+
*/
|
|
342
|
+
export interface RpcError {
|
|
343
|
+
/** Error code */
|
|
344
|
+
code: number;
|
|
345
|
+
/** Human-readable error message */
|
|
346
|
+
message: string;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* JSON-RPC request structure.
|
|
350
|
+
* @typeParam T - Type of the params object
|
|
351
|
+
*/
|
|
352
|
+
export interface RpcRequest<T> {
|
|
353
|
+
/** JSON-RPC version */
|
|
354
|
+
jsonrpc: '2.0';
|
|
355
|
+
/** Request ID */
|
|
356
|
+
id: number;
|
|
357
|
+
/** RPC method name */
|
|
358
|
+
method: string;
|
|
359
|
+
/** Method parameters */
|
|
360
|
+
params: T;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Authentication headers for API requests.
|
|
364
|
+
*/
|
|
365
|
+
export interface AuthenticationHeaders {
|
|
366
|
+
/** API key for simple authentication */
|
|
367
|
+
'x-api-key'?: string;
|
|
368
|
+
/** Unix timestamp for HMAC authentication */
|
|
369
|
+
'x-timestamp'?: string;
|
|
370
|
+
/** HMAC SHA256 signature of timestamp + body */
|
|
371
|
+
'x-hmac-signature'?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Options for initializing a Kora client.
|
|
375
|
+
*/
|
|
376
|
+
export interface KoraClientOptions {
|
|
377
|
+
/** URL of the Kora RPC server */
|
|
378
|
+
rpcUrl: string;
|
|
379
|
+
/** Optional API key for authentication */
|
|
380
|
+
apiKey?: string;
|
|
381
|
+
/** Optional HMAC secret for signature-based authentication */
|
|
382
|
+
hmacSecret?: string;
|
|
383
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Instruction } from '@solana/kit';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts instructions from a base64-encoded transaction message.
|
|
4
|
+
* @param message - Base64-encoded transaction message
|
|
5
|
+
* @returns Array of instructions from the transaction
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function getInstructionsFromBase64Message(message: string): Instruction[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { decompileTransactionMessage, getBase64Codec, getCompiledTransactionMessageCodec, } from '@solana/kit';
|
|
2
|
+
/**
|
|
3
|
+
* Deserializes a base64-encoded transaction message.
|
|
4
|
+
* @param message - Base64-encoded transaction message
|
|
5
|
+
* @returns Decompiled transaction message
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
function deserializeBase64Message(message) {
|
|
9
|
+
const messageBytes = getBase64Codec().encode(message);
|
|
10
|
+
const originalMessage = getCompiledTransactionMessageCodec().decode(messageBytes);
|
|
11
|
+
const decompiledMessage = decompileTransactionMessage(originalMessage);
|
|
12
|
+
return decompiledMessage;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extracts instructions from a base64-encoded transaction message.
|
|
16
|
+
* @param message - Base64-encoded transaction message
|
|
17
|
+
* @returns Array of instructions from the transaction
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export function getInstructionsFromBase64Message(message) {
|
|
21
|
+
if (!message || message === '') {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const decompiledMessage = deserializeBase64Message(message);
|
|
26
|
+
return decompiledMessage.instructions;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// Silently handle parsing errors and return empty array
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runAuthenticationTests(): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KoraClient } from '../src/index.js';
|
|
2
|
+
import { loadEnvironmentVariables } from './setup.js';
|
|
3
|
+
export function runAuthenticationTests() {
|
|
4
|
+
const { koraRpcUrl } = loadEnvironmentVariables();
|
|
5
|
+
describe('Authentication', () => {
|
|
6
|
+
it('should fail with incorrect API key', async () => {
|
|
7
|
+
const client = new KoraClient({
|
|
8
|
+
rpcUrl: koraRpcUrl,
|
|
9
|
+
apiKey: 'WRONG-API-KEY',
|
|
10
|
+
});
|
|
11
|
+
// Auth failure should result in an error (empty response body causes JSON parse error)
|
|
12
|
+
await expect(client.getConfig()).rejects.toThrow();
|
|
13
|
+
});
|
|
14
|
+
it('should fail with incorrect HMAC secret', async () => {
|
|
15
|
+
const client = new KoraClient({
|
|
16
|
+
rpcUrl: koraRpcUrl,
|
|
17
|
+
hmacSecret: 'WRONG-HMAC-SECRET',
|
|
18
|
+
});
|
|
19
|
+
// Auth failure should result in an error
|
|
20
|
+
await expect(client.getConfig()).rejects.toThrow();
|
|
21
|
+
});
|
|
22
|
+
it('should fail with both incorrect credentials', async () => {
|
|
23
|
+
const client = new KoraClient({
|
|
24
|
+
rpcUrl: koraRpcUrl,
|
|
25
|
+
apiKey: 'WRONG-API-KEY',
|
|
26
|
+
hmacSecret: 'WRONG-HMAC-SECRET',
|
|
27
|
+
});
|
|
28
|
+
// Auth failure should result in an error
|
|
29
|
+
await expect(client.getConfig()).rejects.toThrow();
|
|
30
|
+
});
|
|
31
|
+
it('should succeed with correct credentials', async () => {
|
|
32
|
+
const client = new KoraClient({
|
|
33
|
+
rpcUrl: koraRpcUrl,
|
|
34
|
+
apiKey: 'test-api-key-123',
|
|
35
|
+
hmacSecret: 'test-hmac-secret-456',
|
|
36
|
+
});
|
|
37
|
+
const config = await client.getConfig();
|
|
38
|
+
expect(config).toBeDefined();
|
|
39
|
+
expect(config.fee_payers).toBeDefined();
|
|
40
|
+
expect(Array.isArray(config.fee_payers)).toBe(true);
|
|
41
|
+
expect(config.fee_payers.length).toBeGreaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
it('should fail when no credentials provided but auth is required', async () => {
|
|
44
|
+
const client = new KoraClient({
|
|
45
|
+
rpcUrl: koraRpcUrl,
|
|
46
|
+
});
|
|
47
|
+
// No credentials should fail when auth is enabled
|
|
48
|
+
await expect(client.getConfig()).rejects.toThrow();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|