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