@vayolabs/core-sdk 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/dist/index.js ADDED
@@ -0,0 +1,747 @@
1
+ import { createHmac, timingSafeEqual } from 'crypto';
2
+
3
+ // src/errors.ts
4
+ var VayoApiError = class _VayoApiError extends Error {
5
+ constructor(statusCode, message, code = null, correlationId = null) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ this.code = code;
9
+ this.correlationId = correlationId;
10
+ Object.setPrototypeOf(this, _VayoApiError.prototype);
11
+ }
12
+ statusCode;
13
+ code;
14
+ correlationId;
15
+ name = "VayoApiError";
16
+ /**
17
+ * Factory used by the internal HTTP wrapper. Tolerant of malformed bodies —
18
+ * if the server returns HTML or empty content, we still construct a useful
19
+ * error from the status alone.
20
+ */
21
+ static fromBody(statusCode, statusText, body) {
22
+ const message = (body?.message && body.message.length > 0 ? body.message : null) ?? (statusText && statusText.length > 0 ? statusText : null) ?? `HTTP ${statusCode}`;
23
+ return new _VayoApiError(
24
+ statusCode,
25
+ message,
26
+ body?.code ?? null,
27
+ body?.correlationId ?? null
28
+ );
29
+ }
30
+ };
31
+
32
+ // src/http.ts
33
+ var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
34
+ var NO_BODY_STATUSES = /* @__PURE__ */ new Set([204, 205, 304]);
35
+ function buildUrl(baseURL, url, params) {
36
+ const fullUrl = [baseURL, url].filter(Boolean).join("");
37
+ if (!params || typeof params !== "object") return fullUrl;
38
+ const searchParams = new URLSearchParams();
39
+ for (const [key, value] of Object.entries(
40
+ params
41
+ )) {
42
+ if (value === void 0 || value === null) continue;
43
+ if (Array.isArray(value)) {
44
+ searchParams.append(key, value.join(","));
45
+ } else {
46
+ searchParams.append(key, String(value));
47
+ }
48
+ }
49
+ const queryString = searchParams.toString();
50
+ return queryString ? `${fullUrl}?${queryString}` : fullUrl;
51
+ }
52
+ function normalizeHeaders(headers) {
53
+ if (!headers) return {};
54
+ if (Array.isArray(headers)) return Object.fromEntries(headers);
55
+ return { ...headers };
56
+ }
57
+ function defaultIdempotencyKey() {
58
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
59
+ return crypto.randomUUID();
60
+ }
61
+ return `idem-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
62
+ }
63
+ async function client(config) {
64
+ const ctx = config.context;
65
+ if (!ctx) {
66
+ throw new Error(
67
+ "[vayo/core-sdk] internal: RequestConfig.context is missing. Generated clients must be invoked through createVayoPartnerClient()."
68
+ );
69
+ }
70
+ const baseURL = config.baseURL ?? ctx.baseUrl;
71
+ const url = buildUrl(baseURL, config.url, config.params);
72
+ const headers = normalizeHeaders(config.headers);
73
+ const method = (config.method ?? "GET").toUpperCase();
74
+ headers["x-api-key"] = ctx.apiKey;
75
+ if (MUTATING_METHODS.has(method) && !headers["Idempotency-Key"]) {
76
+ headers["Idempotency-Key"] = ctx.idempotencyKey ?? (ctx.generateIdempotencyKey ?? defaultIdempotencyKey)();
77
+ }
78
+ if (!headers["Content-Type"] && !(config.data instanceof FormData)) {
79
+ headers["Content-Type"] = "application/json";
80
+ }
81
+ let body;
82
+ if (config.data instanceof FormData) {
83
+ body = config.data;
84
+ } else if (config.data !== void 0) {
85
+ body = JSON.stringify(config.data);
86
+ }
87
+ const fetchImpl = ctx.fetch ?? fetch;
88
+ const response = await fetchImpl(url, {
89
+ method,
90
+ headers,
91
+ body,
92
+ signal: config.signal,
93
+ // Default to 'omit' (not 'include') because partners never share cookies
94
+ // cross-origin with Vayo. The webapp uses 'include' for first-party flows
95
+ // — partners use header auth.
96
+ credentials: config.credentials ?? "omit"
97
+ });
98
+ let data;
99
+ if (NO_BODY_STATUSES.has(response.status)) {
100
+ data = {};
101
+ } else {
102
+ data = await response.json().catch(() => ({}));
103
+ }
104
+ if (!response.ok) {
105
+ throw VayoApiError.fromBody(
106
+ response.status,
107
+ response.statusText,
108
+ data
109
+ );
110
+ }
111
+ return {
112
+ data,
113
+ status: response.status,
114
+ statusText: response.statusText,
115
+ headers: response.headers
116
+ };
117
+ }
118
+ var http_default = client;
119
+
120
+ // src/generated/clients/getHealthModeS.ts
121
+ function getGetHealthModeSUrl() {
122
+ const res = { method: "GET", url: `/health/mode-s` };
123
+ return res;
124
+ }
125
+ async function getHealthModeS(config = {}) {
126
+ const { client: request = http_default, ...requestConfig } = config;
127
+ const res = await request({ method: "GET", url: getGetHealthModeSUrl().url.toString(), ...requestConfig });
128
+ return res.data;
129
+ }
130
+
131
+ // src/generated/clients/getV1DashboardAllowlist.ts
132
+ function getGetV1DashboardAllowlistUrl() {
133
+ const res = { method: "GET", url: `/v1/dashboard/allowlist` };
134
+ return res;
135
+ }
136
+ async function getV1DashboardAllowlist(config = {}) {
137
+ const { client: request = http_default, ...requestConfig } = config;
138
+ const res = await request({ method: "GET", url: getGetV1DashboardAllowlistUrl().url.toString(), ...requestConfig });
139
+ return res.data;
140
+ }
141
+
142
+ // src/generated/clients/getV1DashboardApiKeys.ts
143
+ function getGetV1DashboardApiKeysUrl() {
144
+ const res = { method: "GET", url: `/v1/dashboard/api-keys` };
145
+ return res;
146
+ }
147
+ async function getV1DashboardApiKeys(config = {}) {
148
+ const { client: request = http_default, ...requestConfig } = config;
149
+ const res = await request({ method: "GET", url: getGetV1DashboardApiKeysUrl().url.toString(), ...requestConfig });
150
+ return res.data;
151
+ }
152
+
153
+ // src/generated/clients/getV1DashboardConsumption.ts
154
+ function getGetV1DashboardConsumptionUrl() {
155
+ const res = { method: "GET", url: `/v1/dashboard/consumption` };
156
+ return res;
157
+ }
158
+ async function getV1DashboardConsumption(config = {}) {
159
+ const { client: request = http_default, ...requestConfig } = config;
160
+ const res = await request({ method: "GET", url: getGetV1DashboardConsumptionUrl().url.toString(), ...requestConfig });
161
+ return res.data;
162
+ }
163
+
164
+ // src/generated/clients/getV1DashboardInvestmentPerformance.ts
165
+ function getGetV1DashboardInvestmentPerformanceUrl() {
166
+ const res = { method: "GET", url: `/v1/dashboard/investment-performance` };
167
+ return res;
168
+ }
169
+ async function getV1DashboardInvestmentPerformance(config = {}) {
170
+ const { client: request = http_default, ...requestConfig } = config;
171
+ const res = await request({ method: "GET", url: getGetV1DashboardInvestmentPerformanceUrl().url.toString(), ...requestConfig });
172
+ return res.data;
173
+ }
174
+
175
+ // src/generated/clients/getV1DashboardOverview.ts
176
+ function getGetV1DashboardOverviewUrl() {
177
+ const res = { method: "GET", url: `/v1/dashboard/overview` };
178
+ return res;
179
+ }
180
+ async function getV1DashboardOverview(config = {}) {
181
+ const { client: request = http_default, ...requestConfig } = config;
182
+ const res = await request({ method: "GET", url: getGetV1DashboardOverviewUrl().url.toString(), ...requestConfig });
183
+ return res.data;
184
+ }
185
+
186
+ // src/generated/clients/getV1DashboardPartnerFees.ts
187
+ function getGetV1DashboardPartnerFeesUrl() {
188
+ const res = { method: "GET", url: `/v1/dashboard/partner-fees` };
189
+ return res;
190
+ }
191
+ async function getV1DashboardPartnerFees(config = {}) {
192
+ const { client: request = http_default, ...requestConfig } = config;
193
+ const res = await request({ method: "GET", url: getGetV1DashboardPartnerFeesUrl().url.toString(), ...requestConfig });
194
+ return res.data;
195
+ }
196
+
197
+ // src/generated/clients/getV1DashboardPartnerFeesPayouts.ts
198
+ function getGetV1DashboardPartnerFeesPayoutsUrl() {
199
+ const res = { method: "GET", url: `/v1/dashboard/partner-fees/payouts` };
200
+ return res;
201
+ }
202
+ async function getV1DashboardPartnerFeesPayouts(params, config = {}) {
203
+ const { client: request = http_default, ...requestConfig } = config;
204
+ const res = await request({ method: "GET", url: getGetV1DashboardPartnerFeesPayoutsUrl().url.toString(), params, ...requestConfig });
205
+ return res.data;
206
+ }
207
+
208
+ // src/generated/clients/getV1DashboardPerformanceFees.ts
209
+ function getGetV1DashboardPerformanceFeesUrl() {
210
+ const res = { method: "GET", url: `/v1/dashboard/performance-fees` };
211
+ return res;
212
+ }
213
+ async function getV1DashboardPerformanceFees(config = {}) {
214
+ const { client: request = http_default, ...requestConfig } = config;
215
+ const res = await request({ method: "GET", url: getGetV1DashboardPerformanceFeesUrl().url.toString(), ...requestConfig });
216
+ return res.data;
217
+ }
218
+
219
+ // src/generated/clients/getV1DashboardTransactions.ts
220
+ function getGetV1DashboardTransactionsUrl() {
221
+ const res = { method: "GET", url: `/v1/dashboard/transactions` };
222
+ return res;
223
+ }
224
+ async function getV1DashboardTransactions(params, config = {}) {
225
+ const { client: request = http_default, ...requestConfig } = config;
226
+ const res = await request({ method: "GET", url: getGetV1DashboardTransactionsUrl().url.toString(), params, ...requestConfig });
227
+ return res.data;
228
+ }
229
+
230
+ // src/generated/clients/getV1DashboardUsers.ts
231
+ function getGetV1DashboardUsersUrl() {
232
+ const res = { method: "GET", url: `/v1/dashboard/users` };
233
+ return res;
234
+ }
235
+ async function getV1DashboardUsers(params, config = {}) {
236
+ const { client: request = http_default, ...requestConfig } = config;
237
+ const res = await request({ method: "GET", url: getGetV1DashboardUsersUrl().url.toString(), params, ...requestConfig });
238
+ return res.data;
239
+ }
240
+
241
+ // src/generated/clients/getV1LendingMarkets.ts
242
+ function getGetV1LendingMarketsUrl() {
243
+ const res = { method: "GET", url: `/v1/lending/markets` };
244
+ return res;
245
+ }
246
+ async function getV1LendingMarkets(config = {}) {
247
+ const { client: request = http_default, ...requestConfig } = config;
248
+ const res = await request({ method: "GET", url: getGetV1LendingMarketsUrl().url.toString(), ...requestConfig });
249
+ return res.data;
250
+ }
251
+
252
+ // src/generated/clients/getV1LendingReserves.ts
253
+ function getGetV1LendingReservesUrl() {
254
+ const res = { method: "GET", url: `/v1/lending/reserves` };
255
+ return res;
256
+ }
257
+ async function getV1LendingReserves(params, config = {}) {
258
+ const { client: request = http_default, ...requestConfig } = config;
259
+ const res = await request({ method: "GET", url: getGetV1LendingReservesUrl().url.toString(), params, ...requestConfig });
260
+ return res.data;
261
+ }
262
+
263
+ // src/generated/clients/postV1LendingOperationsRedeemAllocatedBuild.ts
264
+ function getPostV1LendingOperationsRedeemAllocatedBuildUrl() {
265
+ const res = { method: "POST", url: `/v1/lending-operations/redeem-allocated/build` };
266
+ return res;
267
+ }
268
+ async function postV1LendingOperationsRedeemAllocatedBuild(data, params, config = {}) {
269
+ const { client: request = http_default, ...requestConfig } = config;
270
+ const requestData = data;
271
+ const res = await request({ method: "POST", url: getPostV1LendingOperationsRedeemAllocatedBuildUrl().url.toString(), params, data: requestData, ...requestConfig });
272
+ return res.data;
273
+ }
274
+
275
+ // src/generated/clients/postV1LendingOperationsRedeemAllocatedSubmit.ts
276
+ function getPostV1LendingOperationsRedeemAllocatedSubmitUrl() {
277
+ const res = { method: "POST", url: `/v1/lending-operations/redeem-allocated/submit` };
278
+ return res;
279
+ }
280
+ async function postV1LendingOperationsRedeemAllocatedSubmit(data, config = {}) {
281
+ const { client: request = http_default, ...requestConfig } = config;
282
+ const requestData = data;
283
+ const res = await request({ method: "POST", url: getPostV1LendingOperationsRedeemAllocatedSubmitUrl().url.toString(), data: requestData, ...requestConfig });
284
+ return res.data;
285
+ }
286
+
287
+ // src/mode-s/verify-fee-recipients.ts
288
+ function assertFeeRecipientsMatch(observed, expected) {
289
+ const observedAddresses = new Set(observed.map((r) => r.address));
290
+ const missing = [];
291
+ if (!observedAddresses.has(expected.partnerPayoutAddress)) {
292
+ missing.push(`partner payout (${expected.partnerPayoutAddress})`);
293
+ }
294
+ if (!observedAddresses.has(expected.vayoTreasuryAddress)) {
295
+ missing.push(`Vayo treasury (${expected.vayoTreasuryAddress})`);
296
+ }
297
+ if (missing.length > 0) {
298
+ throw new RangeError(
299
+ `[vayo/core-sdk] /build response is missing expected fee recipients: ${missing.join(
300
+ ", "
301
+ )}. Refusing to sign \u2014 contact partners@vayo.finance.`
302
+ );
303
+ }
304
+ }
305
+
306
+ // src/mode-s/redeem.ts
307
+ var U64_MAX = "18446744073709551615";
308
+ function createModeSHelper(deps) {
309
+ return {
310
+ async redeem(input) {
311
+ const built = await deps.buildRedeem({
312
+ body: {
313
+ privyDid: input.privyDid,
314
+ marketAddress: input.marketAddress,
315
+ tokenMint: input.tokenMint,
316
+ amount: input.amount ?? U64_MAX,
317
+ reserveAddress: input.reserveAddress
318
+ },
319
+ idempotencyKey: input.idempotencyKey,
320
+ signal: input.signal
321
+ });
322
+ if (input.expectedFeeRecipients) {
323
+ assertFeeRecipientsMatch(
324
+ built.expectedFeeRecipients,
325
+ input.expectedFeeRecipients
326
+ );
327
+ }
328
+ const signedTx = await input.signTransaction(built.serializedTx);
329
+ if (typeof signedTx !== "string" || signedTx.length === 0) {
330
+ throw new TypeError(
331
+ "[vayo/core-sdk] signTransaction must return a non-empty base64 string"
332
+ );
333
+ }
334
+ try {
335
+ const submitted = await deps.submitSignedRedeem({
336
+ body: {
337
+ pendingRedeemId: built.pendingRedeemId,
338
+ serializedTx: signedTx
339
+ },
340
+ idempotencyKey: input.idempotencyKey,
341
+ signal: input.signal
342
+ });
343
+ return {
344
+ signature: submitted.signature,
345
+ pendingRedeemId: built.pendingRedeemId,
346
+ expectedFeeRecipients: built.expectedFeeRecipients,
347
+ cosignersAttached: built.cosignersAttached,
348
+ viaFallbackRpc: false
349
+ };
350
+ } catch (err) {
351
+ if (!input.fallbackRpcUrl) throw err;
352
+ const signature = await broadcastViaRpc(
353
+ input.fallbackRpcUrl,
354
+ signedTx,
355
+ input.signal
356
+ );
357
+ return {
358
+ signature,
359
+ pendingRedeemId: built.pendingRedeemId,
360
+ expectedFeeRecipients: built.expectedFeeRecipients,
361
+ cosignersAttached: built.cosignersAttached,
362
+ viaFallbackRpc: true
363
+ };
364
+ }
365
+ }
366
+ };
367
+ }
368
+ async function broadcastViaRpc(rpcUrl, serializedTxBase64, signal) {
369
+ const fetchImpl = fetch;
370
+ const res = await fetchImpl(rpcUrl, {
371
+ method: "POST",
372
+ headers: { "content-type": "application/json" },
373
+ body: JSON.stringify({
374
+ jsonrpc: "2.0",
375
+ id: 1,
376
+ method: "sendTransaction",
377
+ params: [
378
+ serializedTxBase64,
379
+ { encoding: "base64", skipPreflight: false }
380
+ ]
381
+ }),
382
+ signal
383
+ });
384
+ if (!res.ok) {
385
+ throw new Error(
386
+ `[vayo/core-sdk] direct RPC fallback failed: ${res.status} ${res.statusText}`
387
+ );
388
+ }
389
+ const body = await res.json();
390
+ if (body.error) {
391
+ throw new Error(
392
+ `[vayo/core-sdk] direct RPC sendTransaction error: ${body.error.message}`
393
+ );
394
+ }
395
+ if (!body.result) {
396
+ throw new Error("[vayo/core-sdk] direct RPC returned empty result");
397
+ }
398
+ return body.result;
399
+ }
400
+
401
+ // src/mode-s/supply.ts
402
+ function createModeSSupplyHelper(deps) {
403
+ return {
404
+ async supply(input) {
405
+ const built = await deps.buildSupply({
406
+ body: {
407
+ privyDid: input.privyDid,
408
+ marketAddress: input.marketAddress,
409
+ tokenMint: input.tokenMint,
410
+ amount: input.amount,
411
+ reserveAddress: input.reserveAddress
412
+ },
413
+ idempotencyKey: input.idempotencyKey,
414
+ signal: input.signal
415
+ });
416
+ const signedTx = await input.signTransaction(built.serializedTx);
417
+ if (typeof signedTx !== "string" || signedTx.length === 0) {
418
+ throw new TypeError(
419
+ "[vayo/core-sdk] signTransaction must return a non-empty base64 string"
420
+ );
421
+ }
422
+ const submitted = await deps.submitSignedSupply({
423
+ body: {
424
+ pendingSupplyId: built.pendingSupplyId,
425
+ serializedTx: signedTx
426
+ },
427
+ idempotencyKey: input.idempotencyKey,
428
+ signal: input.signal
429
+ });
430
+ return {
431
+ signature: submitted.signature,
432
+ pendingSupplyId: built.pendingSupplyId,
433
+ cosignersAttached: built.cosignersAttached
434
+ };
435
+ }
436
+ };
437
+ }
438
+
439
+ // src/wallet/withdraw.ts
440
+ function createWalletHelper(deps) {
441
+ return {
442
+ async withdraw(input) {
443
+ const prepared = await deps.prepareWithdrawal({
444
+ body: {
445
+ privyDid: input.privyDid,
446
+ destinationAddress: input.destinationAddress,
447
+ amount: input.amount,
448
+ exactRecipientAmount: input.exactRecipientAmount
449
+ },
450
+ idempotencyKey: input.idempotencyKey,
451
+ signal: input.signal
452
+ });
453
+ const signedMemoTx = await input.signTransaction(
454
+ prepared.serializedMemoTransaction
455
+ );
456
+ if (typeof signedMemoTx !== "string" || signedMemoTx.length === 0) {
457
+ throw new TypeError(
458
+ "[vayo/core-sdk] signTransaction must return a non-empty base64 string"
459
+ );
460
+ }
461
+ const submitted = await deps.submitWithdrawal({
462
+ body: {
463
+ pendingWithdrawalId: prepared.pendingWithdrawalId,
464
+ signedIntentTransaction: signedMemoTx
465
+ },
466
+ idempotencyKey: input.idempotencyKey,
467
+ signal: input.signal
468
+ });
469
+ return {
470
+ signature: submitted.signature,
471
+ transactionId: submitted.transactionId,
472
+ pendingWithdrawalId: prepared.pendingWithdrawalId,
473
+ memoChallenge: prepared.memoChallenge
474
+ };
475
+ }
476
+ };
477
+ }
478
+
479
+ // src/client.ts
480
+ function buildRequestConfig(ctxBase, opts) {
481
+ return {
482
+ signal: opts.signal,
483
+ context: {
484
+ ...ctxBase,
485
+ idempotencyKey: opts.idempotencyKey
486
+ }
487
+ };
488
+ }
489
+ function createVayoPartnerClient(options) {
490
+ if (!options.baseUrl) {
491
+ throw new Error(
492
+ "[vayo/core-sdk] createVayoPartnerClient: baseUrl is required"
493
+ );
494
+ }
495
+ if (!options.apiKey) {
496
+ throw new Error(
497
+ "[vayo/core-sdk] createVayoPartnerClient: apiKey is required"
498
+ );
499
+ }
500
+ const baseUrl = options.baseUrl.replace(/\/+$/, "");
501
+ const ctxBase = {
502
+ baseUrl,
503
+ apiKey: options.apiKey,
504
+ fetch: options.fetch,
505
+ generateIdempotencyKey: options.generateIdempotencyKey
506
+ };
507
+ const cfg = (opts) => buildRequestConfig(ctxBase, opts);
508
+ const lending = {
509
+ markets: (args) => getV1LendingMarkets(cfg({ signal: args?.signal })),
510
+ reserves: (args) => {
511
+ const { mints, signal } = args ?? {};
512
+ const params = mints ? { mints: Array.isArray(mints) ? mints.join(",") : mints } : void 0;
513
+ return getV1LendingReserves(params, cfg({ signal }));
514
+ }
515
+ };
516
+ const buildRedeem = ({
517
+ body,
518
+ query,
519
+ idempotencyKey,
520
+ signal
521
+ }) => postV1LendingOperationsRedeemAllocatedBuild(
522
+ body,
523
+ query,
524
+ cfg({ idempotencyKey, signal })
525
+ );
526
+ const submitSignedRedeem = ({
527
+ body,
528
+ idempotencyKey,
529
+ signal
530
+ }) => postV1LendingOperationsRedeemAllocatedSubmit(
531
+ body,
532
+ cfg({ idempotencyKey, signal })
533
+ );
534
+ const modeSHelper = createModeSHelper({ buildRedeem, submitSignedRedeem });
535
+ const rawCall = async (method, url, opts = {}) => {
536
+ const res = await client({
537
+ method,
538
+ url,
539
+ data: opts.body,
540
+ signal: opts.signal,
541
+ context: { ...ctxBase, idempotencyKey: opts.idempotencyKey }
542
+ });
543
+ return res.data;
544
+ };
545
+ const buildSupply = ({
546
+ body,
547
+ query,
548
+ idempotencyKey,
549
+ signal
550
+ }) => {
551
+ const qs = query?.gasless ? `?gasless=${query.gasless}` : "";
552
+ return rawCall(
553
+ "POST",
554
+ `/v1/lending-operations/supply-allocated/build${qs}`,
555
+ { body, idempotencyKey, signal }
556
+ );
557
+ };
558
+ const submitSignedSupply = ({
559
+ body,
560
+ idempotencyKey,
561
+ signal
562
+ }) => rawCall(
563
+ "POST",
564
+ "/v1/lending-operations/supply-allocated/submit",
565
+ { body, idempotencyKey, signal }
566
+ );
567
+ const confirmRedeem = ({
568
+ body,
569
+ idempotencyKey,
570
+ signal
571
+ }) => rawCall(
572
+ "POST",
573
+ "/v1/lending-operations/redeem-allocated/confirm",
574
+ { body, idempotencyKey, signal }
575
+ );
576
+ const confirmSupply = ({
577
+ body,
578
+ idempotencyKey,
579
+ signal
580
+ }) => rawCall(
581
+ "POST",
582
+ "/v1/lending-operations/supply-allocated/confirm",
583
+ { body, idempotencyKey, signal }
584
+ );
585
+ const modeSSupplyHelper = createModeSSupplyHelper({
586
+ buildSupply,
587
+ submitSignedSupply
588
+ });
589
+ const modeS = {
590
+ buildRedeem,
591
+ submitSignedRedeem,
592
+ redeem: modeSHelper.redeem,
593
+ buildSupply,
594
+ submitSignedSupply,
595
+ supply: modeSSupplyHelper.supply,
596
+ confirmRedeem,
597
+ confirmSupply
598
+ };
599
+ const prepareWithdrawal = ({
600
+ body,
601
+ idempotencyKey,
602
+ signal
603
+ }) => rawCall("POST", "/v1/wallet/withdraw/prepare", {
604
+ body,
605
+ idempotencyKey,
606
+ signal
607
+ });
608
+ const submitWithdrawal = ({
609
+ body,
610
+ idempotencyKey,
611
+ signal
612
+ }) => rawCall("POST", "/v1/wallet/withdraw/submit", {
613
+ body,
614
+ idempotencyKey,
615
+ signal
616
+ });
617
+ const walletHelper = createWalletHelper({
618
+ prepareWithdrawal,
619
+ submitWithdrawal
620
+ });
621
+ const wallet = {
622
+ prepareWithdrawal,
623
+ submitWithdrawal,
624
+ withdraw: walletHelper.withdraw
625
+ };
626
+ const positions = {
627
+ read: ({ body, idempotencyKey, signal }) => rawCall("POST", "/v1/positions/read", {
628
+ body,
629
+ idempotencyKey,
630
+ signal
631
+ })
632
+ };
633
+ const webhooks = {
634
+ create: ({ body, idempotencyKey, signal }) => rawCall("POST", "/v1/webhooks", {
635
+ body,
636
+ idempotencyKey,
637
+ signal
638
+ }),
639
+ list: (args) => rawCall("GET", "/v1/webhooks", {
640
+ signal: args?.signal
641
+ }),
642
+ delete: ({ subscriptionId, idempotencyKey, signal }) => rawCall("DELETE", `/v1/webhooks/${subscriptionId}`, {
643
+ idempotencyKey,
644
+ signal
645
+ }),
646
+ rotateSecret: ({ subscriptionId, idempotencyKey, signal }) => rawCall(
647
+ "POST",
648
+ `/v1/webhooks/${subscriptionId}/rotate-secret`,
649
+ { idempotencyKey, signal }
650
+ ),
651
+ test: ({ subscriptionId, idempotencyKey, signal }) => rawCall(
652
+ "POST",
653
+ `/v1/webhooks/${subscriptionId}/test`,
654
+ { idempotencyKey, signal }
655
+ ),
656
+ deliveries: ({ subscriptionId, cursor, limit, status, signal }) => {
657
+ const params = new URLSearchParams();
658
+ if (cursor) params.set("cursor", cursor);
659
+ if (limit !== void 0) params.set("limit", String(limit));
660
+ if (status) params.set("status", status);
661
+ const qs = params.toString();
662
+ return rawCall(
663
+ "GET",
664
+ `/v1/webhooks/${subscriptionId}/deliveries${qs ? `?${qs}` : ""}`,
665
+ { signal }
666
+ );
667
+ }
668
+ };
669
+ const dashboard = {
670
+ overview: (args) => getV1DashboardOverview(cfg({ signal: args?.signal })),
671
+ users: (args) => {
672
+ const { signal, limit, offset, activeOnly } = args ?? {};
673
+ const params = limit !== void 0 || offset !== void 0 || activeOnly !== void 0 ? { limit, offset, activeOnly } : void 0;
674
+ return getV1DashboardUsers(params, cfg({ signal }));
675
+ },
676
+ transactions: (args) => {
677
+ const { signal, type, status, limit, offset } = args ?? {};
678
+ const params = type !== void 0 || status !== void 0 || limit !== void 0 || offset !== void 0 ? { type, status, limit, offset } : void 0;
679
+ return getV1DashboardTransactions(params, cfg({ signal }));
680
+ },
681
+ consumption: (args) => getV1DashboardConsumption(cfg({ signal: args?.signal })),
682
+ investmentPerformance: (args) => getV1DashboardInvestmentPerformance(cfg({ signal: args?.signal })),
683
+ performanceFees: (args) => getV1DashboardPerformanceFees(cfg({ signal: args?.signal })),
684
+ partnerFees: (args) => getV1DashboardPartnerFees(cfg({ signal: args?.signal })),
685
+ partnerFeesPayouts: (args) => {
686
+ const { signal, limit, offset } = args ?? {};
687
+ const params = limit !== void 0 || offset !== void 0 ? { limit, offset } : void 0;
688
+ return getV1DashboardPartnerFeesPayouts(params, cfg({ signal }));
689
+ },
690
+ allowlist: (args) => getV1DashboardAllowlist(cfg({ signal: args?.signal })),
691
+ apiKeys: (args) => getV1DashboardApiKeys(cfg({ signal: args?.signal }))
692
+ };
693
+ const healthGet = async (url, signal) => {
694
+ const res = await client({
695
+ method: "GET",
696
+ url,
697
+ signal,
698
+ context: { ...ctxBase, idempotencyKey: void 0 }
699
+ });
700
+ return res.data;
701
+ };
702
+ const health = {
703
+ liveness: (args) => healthGet("/health", args?.signal),
704
+ ready: (args) => healthGet("/health/ready", args?.signal),
705
+ kora: (args) => healthGet("/health/kora", args?.signal),
706
+ modeS: (args) => getHealthModeS(cfg({ signal: args?.signal }))
707
+ };
708
+ const agents = {
709
+ provision: ({ body, idempotencyKey, signal }) => rawCall("POST", "/v1/agents/provision", {
710
+ body,
711
+ idempotencyKey,
712
+ signal
713
+ })
714
+ };
715
+ return {
716
+ lending,
717
+ modeS,
718
+ wallet,
719
+ positions,
720
+ webhooks,
721
+ dashboard,
722
+ health,
723
+ agents,
724
+ options: Object.freeze({ ...options })
725
+ };
726
+ }
727
+
728
+ // src/constants.ts
729
+ var U64_MAX2 = "18446744073709551615";
730
+ var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
731
+ function verifyWebhookSignature(secret, body, signatureHeader) {
732
+ if (!signatureHeader) return false;
733
+ const prefix = "sha256=";
734
+ if (!signatureHeader.startsWith(prefix)) return false;
735
+ const expected = signatureHeader.slice(prefix.length);
736
+ const computed = createHmac("sha256", secret).update(body).digest("hex");
737
+ if (expected.length !== computed.length) return false;
738
+ try {
739
+ return timingSafeEqual(Buffer.from(expected), Buffer.from(computed));
740
+ } catch {
741
+ return false;
742
+ }
743
+ }
744
+
745
+ export { U64_MAX2 as U64_MAX, USDC_MINT, VayoApiError, assertFeeRecipientsMatch, createVayoPartnerClient, verifyWebhookSignature };
746
+ //# sourceMappingURL=index.js.map
747
+ //# sourceMappingURL=index.js.map