@veilo/sdk-core 0.4.0 → 0.5.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/LICENSE +15 -0
- package/README.md +286 -1298
- package/dist/cjs/accounts/admin.d.ts +84 -0
- package/dist/cjs/accounts/admin.js +208 -0
- package/dist/cjs/accounts/errors.d.ts +6 -0
- package/dist/cjs/accounts/errors.js +98 -0
- package/dist/cjs/accounts/index.d.ts +4 -0
- package/dist/cjs/accounts/index.js +20 -0
- package/dist/cjs/accounts/pdas.d.ts +23 -0
- package/dist/cjs/accounts/pdas.js +44 -0
- package/dist/cjs/accounts/queries.d.ts +41 -0
- package/dist/cjs/accounts/queries.js +95 -0
- package/dist/cjs/client.d.ts +2 -407
- package/dist/cjs/client.js +6 -938
- package/dist/cjs/cloak/client.d.ts +28 -0
- package/dist/cjs/cloak/client.js +68 -0
- package/dist/cjs/cloak/errors.d.ts +13 -0
- package/dist/cjs/cloak/errors.js +25 -0
- package/dist/cjs/cloak/helpers.d.ts +6 -0
- package/dist/cjs/cloak/helpers.js +35 -0
- package/dist/cjs/cloak/index.d.ts +6 -0
- package/dist/cjs/cloak/index.js +24 -0
- package/dist/cjs/cloak/polling.d.ts +7 -0
- package/dist/cjs/cloak/polling.js +66 -0
- package/dist/cjs/cloak/transport.d.ts +15 -0
- package/dist/cjs/cloak/transport.js +119 -0
- package/dist/cjs/cloak/types.d.ts +188 -0
- package/dist/cjs/cloak/types.js +5 -0
- package/dist/cjs/cloak.d.ts +1 -0
- package/dist/cjs/cloak.js +18 -0
- package/dist/cjs/compactNote.d.ts +21 -0
- package/dist/cjs/compactNote.js +31 -7
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/notes/encryption.d.ts +41 -0
- package/dist/cjs/notes/encryption.js +75 -0
- package/dist/cjs/notes/index.d.ts +5 -0
- package/dist/cjs/notes/index.js +21 -0
- package/dist/cjs/notes/mailbox.d.ts +70 -0
- package/dist/cjs/notes/mailbox.js +164 -0
- package/dist/cjs/notes/model.d.ts +91 -0
- package/dist/cjs/notes/model.js +109 -0
- package/dist/cjs/notes/nullifier.d.ts +27 -0
- package/dist/cjs/notes/nullifier.js +45 -0
- package/dist/cjs/notes/recovery.d.ts +10 -0
- package/dist/cjs/notes/recovery.js +31 -0
- package/dist/cjs/proof.d.ts +1 -183
- package/dist/cjs/proof.js +16 -290
- package/dist/cjs/proofs/encoding.d.ts +17 -0
- package/dist/cjs/proofs/encoding.js +72 -0
- package/dist/cjs/proofs/formatting.d.ts +6 -0
- package/dist/cjs/proofs/formatting.js +34 -0
- package/dist/cjs/proofs/index.d.ts +5 -0
- package/dist/cjs/proofs/index.js +21 -0
- package/dist/cjs/proofs/swap.d.ts +87 -0
- package/dist/cjs/proofs/swap.js +144 -0
- package/dist/cjs/proofs/transaction.d.ts +28 -0
- package/dist/cjs/proofs/transaction.js +110 -0
- package/dist/cjs/proofs/types.d.ts +70 -0
- package/dist/cjs/prover.d.ts +4 -1
- package/dist/cjs/prover.js +12 -2
- package/dist/cjs/relayer/client.d.ts +61 -0
- package/dist/cjs/relayer/client.js +151 -0
- package/dist/cjs/relayer/crypto.d.ts +5 -0
- package/dist/cjs/relayer/crypto.js +26 -0
- package/dist/cjs/relayer/encoding.d.ts +2 -0
- package/dist/cjs/relayer/encoding.js +23 -0
- package/dist/cjs/relayer/errors.d.ts +7 -0
- package/dist/cjs/relayer/errors.js +17 -0
- package/dist/cjs/relayer/index.d.ts +3 -0
- package/dist/cjs/relayer/index.js +19 -0
- package/dist/cjs/relayer/transport.d.ts +17 -0
- package/dist/cjs/relayer/transport.js +63 -0
- package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +44 -86
- package/dist/cjs/relayer/types.js +5 -0
- package/dist/cjs/relayer.d.ts +1 -318
- package/dist/cjs/relayer.js +15 -254
- package/dist/cjs/shield/alt.js +8 -8
- package/dist/cjs/shield/errors.js +2 -2
- package/dist/cjs/shield/finalize.js +2 -2
- package/dist/cjs/shield/ix.d.ts +1 -1
- package/dist/cjs/shield/owner.js +9 -8
- package/dist/cjs/shield/ports.js +3 -3
- package/dist/cjs/shield/preflight.js +3 -3
- package/dist/cjs/shield/shield.js +20 -19
- package/dist/cjs/shield/types.d.ts +1 -1
- package/dist/cjs/transactions/deposit.d.ts +94 -0
- package/dist/cjs/transactions/deposit.js +234 -0
- package/dist/cjs/transactions/index.d.ts +7 -0
- package/dist/cjs/transactions/index.js +26 -0
- package/dist/cjs/transactions/swap.d.ts +71 -0
- package/dist/cjs/transactions/swap.js +184 -0
- package/dist/cjs/transactions/transact.d.ts +34 -0
- package/dist/cjs/transactions/transact.js +146 -0
- package/dist/cjs/transactions/transfer.d.ts +51 -0
- package/dist/cjs/transactions/transfer.js +106 -0
- package/dist/cjs/transactions/withdraw.d.ts +52 -0
- package/dist/cjs/transactions/withdraw.js +104 -0
- package/dist/cjs/utxo.d.ts +1 -235
- package/dist/cjs/utxo.js +15 -404
- package/dist/esm/accounts/admin.d.ts +84 -0
- package/dist/esm/accounts/admin.js +165 -0
- package/dist/esm/accounts/errors.d.ts +6 -0
- package/dist/esm/accounts/errors.js +95 -0
- package/dist/esm/accounts/index.d.ts +4 -0
- package/dist/esm/accounts/index.js +4 -0
- package/dist/esm/accounts/pdas.d.ts +23 -0
- package/dist/esm/accounts/pdas.js +38 -0
- package/dist/esm/accounts/queries.d.ts +41 -0
- package/dist/esm/accounts/queries.js +88 -0
- package/dist/esm/client.d.ts +2 -407
- package/dist/esm/client.js +3 -891
- package/dist/esm/cloak/client.d.ts +28 -0
- package/dist/esm/cloak/client.js +64 -0
- package/dist/esm/cloak/errors.d.ts +13 -0
- package/dist/esm/cloak/errors.js +21 -0
- package/dist/esm/cloak/helpers.d.ts +6 -0
- package/dist/esm/cloak/helpers.js +31 -0
- package/dist/esm/cloak/index.d.ts +6 -0
- package/dist/esm/cloak/index.js +6 -0
- package/dist/esm/cloak/polling.d.ts +7 -0
- package/dist/esm/cloak/polling.js +63 -0
- package/dist/esm/cloak/transport.d.ts +15 -0
- package/dist/esm/cloak/transport.js +115 -0
- package/dist/esm/cloak/types.d.ts +188 -0
- package/dist/esm/cloak/types.js +4 -0
- package/dist/esm/cloak.d.ts +1 -0
- package/dist/esm/cloak.js +2 -0
- package/dist/esm/compactNote.d.ts +21 -0
- package/dist/esm/compactNote.js +24 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/notes/encryption.d.ts +41 -0
- package/dist/esm/notes/encryption.js +67 -0
- package/dist/esm/notes/index.d.ts +5 -0
- package/dist/esm/notes/index.js +5 -0
- package/dist/esm/notes/mailbox.d.ts +70 -0
- package/dist/esm/notes/mailbox.js +154 -0
- package/dist/esm/notes/model.d.ts +91 -0
- package/dist/esm/notes/model.js +99 -0
- package/dist/esm/notes/nullifier.d.ts +27 -0
- package/dist/esm/notes/nullifier.js +40 -0
- package/dist/esm/notes/recovery.d.ts +10 -0
- package/dist/esm/notes/recovery.js +28 -0
- package/dist/esm/proof.d.ts +1 -183
- package/dist/esm/proof.js +2 -281
- package/dist/esm/proofs/encoding.d.ts +17 -0
- package/dist/esm/proofs/encoding.js +68 -0
- package/dist/esm/proofs/formatting.d.ts +6 -0
- package/dist/esm/proofs/formatting.js +31 -0
- package/dist/esm/proofs/index.d.ts +5 -0
- package/dist/esm/proofs/index.js +5 -0
- package/dist/esm/proofs/swap.d.ts +87 -0
- package/dist/esm/proofs/swap.js +138 -0
- package/dist/esm/proofs/transaction.d.ts +28 -0
- package/dist/esm/proofs/transaction.js +105 -0
- package/dist/esm/proofs/types.d.ts +70 -0
- package/dist/esm/proofs/types.js +1 -0
- package/dist/esm/prover.d.ts +4 -1
- package/dist/esm/prover.js +10 -1
- package/dist/esm/relayer/client.d.ts +61 -0
- package/dist/esm/relayer/client.js +144 -0
- package/dist/esm/relayer/crypto.d.ts +5 -0
- package/dist/esm/relayer/crypto.js +20 -0
- package/dist/esm/relayer/encoding.d.ts +2 -0
- package/dist/esm/relayer/encoding.js +19 -0
- package/dist/esm/relayer/errors.d.ts +7 -0
- package/dist/esm/relayer/errors.js +13 -0
- package/dist/esm/relayer/index.d.ts +3 -0
- package/dist/esm/relayer/index.js +3 -0
- package/dist/esm/relayer/transport.d.ts +17 -0
- package/dist/esm/relayer/transport.js +59 -0
- package/dist/esm/relayer/types.d.ts +276 -0
- package/dist/esm/relayer/types.js +4 -0
- package/dist/esm/relayer.d.ts +1 -318
- package/dist/esm/relayer.js +2 -249
- package/dist/esm/shield/alt.js +1 -1
- package/dist/esm/shield/errors.js +1 -1
- package/dist/esm/shield/finalize.js +1 -1
- package/dist/esm/shield/ix.d.ts +1 -1
- package/dist/esm/shield/owner.js +2 -1
- package/dist/esm/shield/ports.js +1 -1
- package/dist/esm/shield/preflight.js +1 -1
- package/dist/esm/shield/shield.js +4 -3
- package/dist/esm/shield/types.d.ts +1 -1
- package/dist/esm/transactions/deposit.d.ts +94 -0
- package/dist/esm/transactions/deposit.js +198 -0
- package/dist/esm/transactions/index.d.ts +7 -0
- package/dist/esm/transactions/index.js +7 -0
- package/dist/esm/transactions/swap.d.ts +71 -0
- package/dist/esm/transactions/swap.js +144 -0
- package/dist/esm/transactions/transact.d.ts +34 -0
- package/dist/esm/transactions/transact.js +110 -0
- package/dist/esm/transactions/transfer.d.ts +51 -0
- package/dist/esm/transactions/transfer.js +103 -0
- package/dist/esm/transactions/withdraw.d.ts +52 -0
- package/dist/esm/transactions/withdraw.js +101 -0
- package/dist/esm/utxo.d.ts +1 -235
- package/dist/esm/utxo.js +2 -382
- package/package.json +54 -16
- package/SHIELD_INTEGRATION.md +0 -143
- package/config.d.ts +0 -2
- package/config.js +0 -4
- package/dist/src/client.d.ts +0 -407
- package/dist/src/client.js +0 -951
- package/dist/src/compactNote.d.ts +0 -107
- package/dist/src/compactNote.js +0 -167
- package/dist/src/config.d.ts +0 -82
- package/dist/src/config.js +0 -57
- package/dist/src/events.d.ts +0 -77
- package/dist/src/events.js +0 -167
- package/dist/src/idl/privacy_pool.d.ts +0 -5
- package/dist/src/idl/privacy_pool.js +0 -15218
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.js +0 -67
- package/dist/src/merkle.d.ts +0 -77
- package/dist/src/merkle.js +0 -156
- package/dist/src/poseidon.d.ts +0 -29
- package/dist/src/poseidon.js +0 -100
- package/dist/src/program.d.ts +0 -37
- package/dist/src/program.js +0 -61
- package/dist/src/proof.d.ts +0 -183
- package/dist/src/proof.js +0 -292
- package/dist/src/prover.d.ts +0 -54
- package/dist/src/prover.js +0 -112
- package/dist/src/random.d.ts +0 -16
- package/dist/src/random.js +0 -28
- package/dist/src/relayer.js +0 -257
- package/dist/src/retry.d.ts +0 -32
- package/dist/src/retry.js +0 -75
- package/dist/src/shield/alt.d.ts +0 -87
- package/dist/src/shield/alt.js +0 -194
- package/dist/src/shield/computeBudget.d.ts +0 -61
- package/dist/src/shield/computeBudget.js +0 -64
- package/dist/src/shield/errors.d.ts +0 -58
- package/dist/src/shield/errors.js +0 -121
- package/dist/src/shield/finalize.d.ts +0 -45
- package/dist/src/shield/finalize.js +0 -119
- package/dist/src/shield/index.d.ts +0 -35
- package/dist/src/shield/index.js +0 -68
- package/dist/src/shield/ix.d.ts +0 -54
- package/dist/src/shield/ix.js +0 -119
- package/dist/src/shield/owner.d.ts +0 -36
- package/dist/src/shield/owner.js +0 -126
- package/dist/src/shield/ports.d.ts +0 -43
- package/dist/src/shield/ports.js +0 -153
- package/dist/src/shield/preflight.d.ts +0 -30
- package/dist/src/shield/preflight.js +0 -154
- package/dist/src/shield/shield.d.ts +0 -68
- package/dist/src/shield/shield.js +0 -499
- package/dist/src/shield/types.d.ts +0 -202
- package/dist/src/utxo.d.ts +0 -235
- package/dist/src/utxo.js +0 -407
- package/dist/tests/compact-note.test.d.ts +0 -1
- package/dist/tests/compact-note.test.js +0 -173
- package/dist/tests/config.test.d.ts +0 -1
- package/dist/tests/config.test.js +0 -102
- package/dist/tests/edge-cases.test.d.ts +0 -1
- package/dist/tests/edge-cases.test.js +0 -220
- package/dist/tests/encryption.test.d.ts +0 -1
- package/dist/tests/encryption.test.js +0 -215
- package/dist/tests/events.test.d.ts +0 -1
- package/dist/tests/events.test.js +0 -78
- package/dist/tests/multi-tree.test.d.ts +0 -1
- package/dist/tests/multi-tree.test.js +0 -405
- package/dist/tests/pda.test.d.ts +0 -1
- package/dist/tests/pda.test.js +0 -229
- package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
- package/dist/tests/poseidon-builder-parity.test.js +0 -72
- package/dist/tests/poseidon.test.d.ts +0 -1
- package/dist/tests/poseidon.test.js +0 -142
- package/dist/tests/proof.test.d.ts +0 -1
- package/dist/tests/proof.test.js +0 -296
- package/dist/tests/relayer.test.d.ts +0 -1
- package/dist/tests/relayer.test.js +0 -271
- package/dist/tests/sdk.integration.test.d.ts +0 -1
- package/dist/tests/sdk.integration.test.js +0 -330
- package/dist/tests/shield-owner.test.d.ts +0 -1
- package/dist/tests/shield-owner.test.js +0 -89
- package/dist/tests/shield-preflight.test.d.ts +0 -1
- package/dist/tests/shield-preflight.test.js +0 -87
- package/dist/tests/shield-realproof.test.d.ts +0 -1
- package/dist/tests/shield-realproof.test.js +0 -272
- package/dist/tests/shield.test.d.ts +0 -1
- package/dist/tests/shield.test.js +0 -403
- package/dist/tests/utxo.test.d.ts +0 -1
- package/dist/tests/utxo.test.js +0 -140
- package/poseidon.d.ts +0 -2
- package/poseidon.js +0 -4
- package/proof.d.ts +0 -2
- package/proof.js +0 -4
- package/prover.d.ts +0 -2
- package/prover.js +0 -4
- package/shield.d.ts +0 -2
- package/shield.js +0 -4
- /package/dist/{src/shield → cjs/proofs}/types.js +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CloakCreateOrderOptions, CloakCreateOrderRequest, CloakCreateOrderResponse, CloakDepositRequest, CloakDepositResponse, CloakOrderStatus, CloakOrderStatusResponse, CloakQuoteRequest, CloakQuoteResponse, CloakRefreshTransactionResponse, CloakRequestOptions, CloakTokensResponse, CloakWaitForFinalOptions, VeiloCloakConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Typed façade for the Veilo Cloak Partner API.
|
|
4
|
+
*
|
|
5
|
+
* The client builds and reads Cloak orders; it never signs or submits a Solana
|
|
6
|
+
* transaction on the caller's behalf.
|
|
7
|
+
*/
|
|
8
|
+
export declare class VeiloCloakClient {
|
|
9
|
+
private readonly transport;
|
|
10
|
+
constructor(config: VeiloCloakConfig);
|
|
11
|
+
/** List supported assets and their current raw-unit limits. */
|
|
12
|
+
listTokens(options?: CloakRequestOptions): Promise<CloakTokensResponse>;
|
|
13
|
+
/** Price a private transfer. This creates no order and does nothing on-chain. */
|
|
14
|
+
getQuote(input: CloakQuoteRequest, options?: CloakRequestOptions): Promise<CloakQuoteResponse>;
|
|
15
|
+
/** Build an unsigned v0 deposit transaction for a signed quote. */
|
|
16
|
+
createOrder(input: CloakCreateOrderRequest, options?: CloakCreateOrderOptions): Promise<CloakCreateOrderResponse>;
|
|
17
|
+
/** Rebuild an unfunded order with a fresh blockhash. */
|
|
18
|
+
refreshTransaction(trackingId: string, options?: CloakRequestOptions): Promise<CloakRefreshTransactionResponse>;
|
|
19
|
+
/** Read the monotone public status of an order. */
|
|
20
|
+
getOrderStatus(trackingId: string, options?: CloakRequestOptions): Promise<CloakOrderStatusResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional latency hint after the user's deposit confirms. Cloak verifies the
|
|
23
|
+
* signature independently; this acknowledgement is not proof of payment.
|
|
24
|
+
*/
|
|
25
|
+
notifyDeposit(input: CloakDepositRequest, options?: CloakRequestOptions): Promise<CloakDepositResponse>;
|
|
26
|
+
/** Poll until Cloak reports a genuinely final, monotone status. */
|
|
27
|
+
waitForFinalStatus(trackingId: string, options?: CloakWaitForFinalOptions): Promise<CloakOrderStatus>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VeiloCloakClient = void 0;
|
|
4
|
+
const polling_js_1 = require("./polling.js");
|
|
5
|
+
const transport_js_1 = require("./transport.js");
|
|
6
|
+
/**
|
|
7
|
+
* Typed façade for the Veilo Cloak Partner API.
|
|
8
|
+
*
|
|
9
|
+
* The client builds and reads Cloak orders; it never signs or submits a Solana
|
|
10
|
+
* transaction on the caller's behalf.
|
|
11
|
+
*/
|
|
12
|
+
class VeiloCloakClient {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.transport = new transport_js_1.CloakHttpTransport(config);
|
|
15
|
+
}
|
|
16
|
+
/** List supported assets and their current raw-unit limits. */
|
|
17
|
+
async listTokens(options = {}) {
|
|
18
|
+
return this.transport.request("GET", "/tokens", options);
|
|
19
|
+
}
|
|
20
|
+
/** Price a private transfer. This creates no order and does nothing on-chain. */
|
|
21
|
+
async getQuote(input, options = {}) {
|
|
22
|
+
return this.transport.request("POST", "/quote", {
|
|
23
|
+
...options,
|
|
24
|
+
body: input,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Build an unsigned v0 deposit transaction for a signed quote. */
|
|
28
|
+
async createOrder(input, options = {}) {
|
|
29
|
+
const headers = {};
|
|
30
|
+
if (options.idempotencyKey?.trim()) {
|
|
31
|
+
headers["X-Idempotency-Key"] = options.idempotencyKey.trim();
|
|
32
|
+
}
|
|
33
|
+
return this.transport.request("POST", "/order", {
|
|
34
|
+
body: input,
|
|
35
|
+
headers,
|
|
36
|
+
signal: options.signal,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Rebuild an unfunded order with a fresh blockhash. */
|
|
40
|
+
async refreshTransaction(trackingId, options = {}) {
|
|
41
|
+
return this.transport.request("GET", `/order/${trackingPath(trackingId)}/transaction`, options);
|
|
42
|
+
}
|
|
43
|
+
/** Read the monotone public status of an order. */
|
|
44
|
+
async getOrderStatus(trackingId, options = {}) {
|
|
45
|
+
return this.transport.request("GET", `/status/${trackingPath(trackingId)}`, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Optional latency hint after the user's deposit confirms. Cloak verifies the
|
|
49
|
+
* signature independently; this acknowledgement is not proof of payment.
|
|
50
|
+
*/
|
|
51
|
+
async notifyDeposit(input, options = {}) {
|
|
52
|
+
return this.transport.request("POST", "/deposit", {
|
|
53
|
+
...options,
|
|
54
|
+
body: input,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Poll until Cloak reports a genuinely final, monotone status. */
|
|
58
|
+
async waitForFinalStatus(trackingId, options = {}) {
|
|
59
|
+
return (0, polling_js_1.waitForFinalCloakStatus)(this, trackingId, options);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.VeiloCloakClient = VeiloCloakClient;
|
|
63
|
+
function trackingPath(trackingId) {
|
|
64
|
+
const value = trackingId.trim();
|
|
65
|
+
if (!value)
|
|
66
|
+
throw new TypeError("trackingId must not be empty.");
|
|
67
|
+
return encodeURIComponent(value);
|
|
68
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CloakErrorCode, CloakErrorResponse } from "./types.js";
|
|
2
|
+
/** Structured error thrown for Cloak HTTP, transport, and response failures. */
|
|
3
|
+
export declare class CloakApiError extends Error {
|
|
4
|
+
readonly code: CloakErrorCode | (string & {});
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly details?: CloakErrorResponse;
|
|
7
|
+
readonly retryAfter?: number;
|
|
8
|
+
readonly min?: string;
|
|
9
|
+
readonly max?: string;
|
|
10
|
+
readonly field?: string;
|
|
11
|
+
readonly maxBps?: number;
|
|
12
|
+
constructor(code: CloakErrorCode | (string & {}), message: string, status: number, details?: CloakErrorResponse);
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloakApiError = void 0;
|
|
4
|
+
/** Structured error thrown for Cloak HTTP, transport, and response failures. */
|
|
5
|
+
class CloakApiError extends Error {
|
|
6
|
+
constructor(code, message, status, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "CloakApiError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.details = details;
|
|
12
|
+
this.retryAfter = numberField(details?.retryAfter);
|
|
13
|
+
this.min = stringField(details?.min);
|
|
14
|
+
this.max = stringField(details?.max);
|
|
15
|
+
this.field = stringField(details?.field);
|
|
16
|
+
this.maxBps = numberField(details?.maxBps);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CloakApiError = CloakApiError;
|
|
20
|
+
function stringField(value) {
|
|
21
|
+
return typeof value === "string" ? value : undefined;
|
|
22
|
+
}
|
|
23
|
+
function numberField(value) {
|
|
24
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
25
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { CloakOrderStatus, CloakOrderTransaction, CloakPartnerStatus } from "./types.js";
|
|
3
|
+
/** True for a terminal public status or a status response carrying one. */
|
|
4
|
+
export declare function isFinalCloakStatus(value: CloakPartnerStatus | Pick<CloakOrderStatus, "status" | "final">): boolean;
|
|
5
|
+
/** Deserialize the API's unsigned base64 transaction for wallet signing. */
|
|
6
|
+
export declare function deserializeCloakTransaction(value: string | Pick<CloakOrderTransaction, "transaction">): VersionedTransaction;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFinalCloakStatus = isFinalCloakStatus;
|
|
4
|
+
exports.deserializeCloakTransaction = deserializeCloakTransaction;
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const FINAL_STATUSES = new Set([
|
|
7
|
+
"SUCCESSFUL",
|
|
8
|
+
"FAILED",
|
|
9
|
+
"REFUNDED",
|
|
10
|
+
"EXPIRED",
|
|
11
|
+
]);
|
|
12
|
+
/** True for a terminal public status or a status response carrying one. */
|
|
13
|
+
function isFinalCloakStatus(value) {
|
|
14
|
+
return typeof value === "string"
|
|
15
|
+
? FINAL_STATUSES.has(value)
|
|
16
|
+
: value.final || FINAL_STATUSES.has(value.status);
|
|
17
|
+
}
|
|
18
|
+
/** Deserialize the API's unsigned base64 transaction for wallet signing. */
|
|
19
|
+
function deserializeCloakTransaction(value) {
|
|
20
|
+
const encoded = typeof value === "string" ? value : value.transaction;
|
|
21
|
+
if (!encoded)
|
|
22
|
+
throw new TypeError("Cloak transaction must not be empty.");
|
|
23
|
+
return web3_js_1.VersionedTransaction.deserialize(decodeBase64(encoded));
|
|
24
|
+
}
|
|
25
|
+
function decodeBase64(encoded) {
|
|
26
|
+
if (typeof Buffer !== "undefined") {
|
|
27
|
+
return new Uint8Array(Buffer.from(encoded, "base64"));
|
|
28
|
+
}
|
|
29
|
+
const binary = atob(encoded);
|
|
30
|
+
const bytes = new Uint8Array(binary.length);
|
|
31
|
+
for (let index = 0; index < binary.length; index++) {
|
|
32
|
+
bytes[index] = binary.charCodeAt(index);
|
|
33
|
+
}
|
|
34
|
+
return bytes;
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DEFAULT_VEILO_API_BASE_URL = void 0;
|
|
18
|
+
__exportStar(require("./types.js"), exports);
|
|
19
|
+
__exportStar(require("./errors.js"), exports);
|
|
20
|
+
__exportStar(require("./helpers.js"), exports);
|
|
21
|
+
__exportStar(require("./polling.js"), exports);
|
|
22
|
+
__exportStar(require("./client.js"), exports);
|
|
23
|
+
var transport_js_1 = require("./transport.js");
|
|
24
|
+
Object.defineProperty(exports, "DEFAULT_VEILO_API_BASE_URL", { enumerable: true, get: function () { return transport_js_1.DEFAULT_VEILO_API_BASE_URL; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CloakOrderStatus, CloakOrderStatusResponse, CloakRequestOptions, CloakWaitForFinalOptions } from "./types.js";
|
|
2
|
+
/** Minimal dependency required by the polling helper. */
|
|
3
|
+
export interface CloakStatusReader {
|
|
4
|
+
getOrderStatus(trackingId: string, options?: CloakRequestOptions): Promise<CloakOrderStatusResponse>;
|
|
5
|
+
}
|
|
6
|
+
/** Poll any compatible status reader until Cloak reaches a final state. */
|
|
7
|
+
export declare function waitForFinalCloakStatus(reader: CloakStatusReader, trackingId: string, options?: CloakWaitForFinalOptions): Promise<CloakOrderStatus>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForFinalCloakStatus = waitForFinalCloakStatus;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
const helpers_js_1 = require("./helpers.js");
|
|
6
|
+
/** Poll any compatible status reader until Cloak reaches a final state. */
|
|
7
|
+
async function waitForFinalCloakStatus(reader, trackingId, options = {}) {
|
|
8
|
+
const intervalMs = finiteNonNegative(options.intervalMs ?? 3000, "intervalMs");
|
|
9
|
+
const timeoutMs = options.timeoutMs === undefined
|
|
10
|
+
? undefined
|
|
11
|
+
: finiteNonNegative(options.timeoutMs, "timeoutMs");
|
|
12
|
+
const startedAt = Date.now();
|
|
13
|
+
for (;;) {
|
|
14
|
+
throwIfAborted(options.signal);
|
|
15
|
+
const { order } = await reader.getOrderStatus(trackingId, {
|
|
16
|
+
signal: options.signal,
|
|
17
|
+
});
|
|
18
|
+
await options.onStatus?.(order);
|
|
19
|
+
if ((0, helpers_js_1.isFinalCloakStatus)(order))
|
|
20
|
+
return order;
|
|
21
|
+
if (timeoutMs !== undefined) {
|
|
22
|
+
const elapsed = Date.now() - startedAt;
|
|
23
|
+
if (elapsed + intervalMs > timeoutMs) {
|
|
24
|
+
throw new errors_js_1.CloakApiError("POLL_TIMEOUT", `Cloak order ${trackingId} did not reach a final status within ${timeoutMs}ms.`, 0);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await abortableDelay(intervalMs, options.signal);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function finiteNonNegative(value, field) {
|
|
31
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
32
|
+
throw new TypeError(`${field} must be a finite, non-negative number.`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function abortError() {
|
|
37
|
+
const error = new Error("The operation was aborted.");
|
|
38
|
+
error.name = "AbortError";
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
function throwIfAborted(signal) {
|
|
42
|
+
if (signal?.aborted)
|
|
43
|
+
throw abortError();
|
|
44
|
+
}
|
|
45
|
+
function abortableDelay(ms, signal) {
|
|
46
|
+
if (ms === 0) {
|
|
47
|
+
throwIfAborted(signal);
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
if (signal?.aborted) {
|
|
52
|
+
reject(abortError());
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const timer = setTimeout(() => {
|
|
56
|
+
signal?.removeEventListener("abort", onAbort);
|
|
57
|
+
resolve();
|
|
58
|
+
}, ms);
|
|
59
|
+
const onAbort = () => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
signal?.removeEventListener("abort", onAbort);
|
|
62
|
+
reject(abortError());
|
|
63
|
+
};
|
|
64
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CloakRequestOptions, VeiloCloakConfig } from "./types.js";
|
|
2
|
+
/** Production Veilo API origin. Cloak routes are mounted at `/cloak/v1`. */
|
|
3
|
+
export declare const DEFAULT_VEILO_API_BASE_URL = "https://api.veilo.network";
|
|
4
|
+
export interface CloakTransportRequest extends CloakRequestOptions {
|
|
5
|
+
body?: unknown;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
/** Internal HTTP boundary. Endpoint methods depend on this instead of fetch. */
|
|
9
|
+
export declare class CloakHttpTransport {
|
|
10
|
+
private readonly baseUrl;
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly fetchImpl;
|
|
13
|
+
constructor(config: VeiloCloakConfig);
|
|
14
|
+
request<T>(method: "GET" | "POST", route: string, options?: CloakTransportRequest): Promise<T>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloakHttpTransport = exports.DEFAULT_VEILO_API_BASE_URL = void 0;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
/** Production Veilo API origin. Cloak routes are mounted at `/cloak/v1`. */
|
|
6
|
+
exports.DEFAULT_VEILO_API_BASE_URL = "https://api.veilo.network";
|
|
7
|
+
/** Internal HTTP boundary. Endpoint methods depend on this instead of fetch. */
|
|
8
|
+
class CloakHttpTransport {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
const baseUrl = config.baseUrl === undefined
|
|
11
|
+
? exports.DEFAULT_VEILO_API_BASE_URL
|
|
12
|
+
: config.baseUrl.trim();
|
|
13
|
+
const apiKey = config.apiKey?.trim();
|
|
14
|
+
if (!baseUrl) {
|
|
15
|
+
throw new TypeError("VeiloCloakClient baseUrl must not be empty.");
|
|
16
|
+
}
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
throw new TypeError("VeiloCloakClient requires an apiKey.");
|
|
19
|
+
}
|
|
20
|
+
const fetchImpl = config.fetch ?? globalThis.fetch?.bind(globalThis);
|
|
21
|
+
if (!fetchImpl) {
|
|
22
|
+
throw new TypeError("No fetch implementation is available. Pass `fetch` in the client config.");
|
|
23
|
+
}
|
|
24
|
+
this.baseUrl = cloakApiUrl(baseUrl);
|
|
25
|
+
this.apiKey = apiKey;
|
|
26
|
+
this.fetchImpl = fetchImpl;
|
|
27
|
+
}
|
|
28
|
+
async request(method, route, options = {}) {
|
|
29
|
+
let response;
|
|
30
|
+
try {
|
|
31
|
+
response = await this.fetchImpl(`${this.baseUrl}${route}`, {
|
|
32
|
+
method,
|
|
33
|
+
headers: {
|
|
34
|
+
Accept: "application/json",
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
"x-api-key": this.apiKey,
|
|
37
|
+
...options.headers,
|
|
38
|
+
},
|
|
39
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
40
|
+
signal: options.signal,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
rethrowAbort(error, options.signal);
|
|
45
|
+
throw networkError(error, "Network request failed.");
|
|
46
|
+
}
|
|
47
|
+
const parsed = await parseResponse(response, options.signal);
|
|
48
|
+
const success = parsed.success;
|
|
49
|
+
if (!response.ok || success === false) {
|
|
50
|
+
throw apiError(response, parsed);
|
|
51
|
+
}
|
|
52
|
+
if (success !== true) {
|
|
53
|
+
throw new errors_js_1.CloakApiError("INVALID_RESPONSE", `Cloak returned a response without a success marker (${response.status}).`, response.status);
|
|
54
|
+
}
|
|
55
|
+
return parsed;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.CloakHttpTransport = CloakHttpTransport;
|
|
59
|
+
function cloakApiUrl(baseUrl) {
|
|
60
|
+
const normalized = baseUrl.replace(/\/+$/, "");
|
|
61
|
+
return /\/cloak\/v1$/i.test(normalized)
|
|
62
|
+
? normalized
|
|
63
|
+
: `${normalized}/cloak/v1`;
|
|
64
|
+
}
|
|
65
|
+
async function parseResponse(response, signal) {
|
|
66
|
+
let text;
|
|
67
|
+
try {
|
|
68
|
+
text = await response.text();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
rethrowAbort(error, signal);
|
|
72
|
+
throw networkError(error, "Could not read the Cloak response.");
|
|
73
|
+
}
|
|
74
|
+
let parsed = {};
|
|
75
|
+
if (text) {
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(text);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new errors_js_1.CloakApiError("INVALID_RESPONSE", `Cloak returned a non-JSON response (${response.status}).`, response.status);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!isRecord(parsed)) {
|
|
84
|
+
throw new errors_js_1.CloakApiError("INVALID_RESPONSE", `Cloak returned an invalid response (${response.status}).`, response.status);
|
|
85
|
+
}
|
|
86
|
+
return parsed;
|
|
87
|
+
}
|
|
88
|
+
function apiError(response, body) {
|
|
89
|
+
const retryAfterHeader = parseRetryAfter(response.headers.get("retry-after"));
|
|
90
|
+
const details = body.retryAfter === undefined && retryAfterHeader !== undefined
|
|
91
|
+
? { ...body, retryAfter: retryAfterHeader }
|
|
92
|
+
: body;
|
|
93
|
+
const code = typeof body.error === "string"
|
|
94
|
+
? body.error
|
|
95
|
+
: response.ok
|
|
96
|
+
? "INVALID_RESPONSE"
|
|
97
|
+
: "HTTP_ERROR";
|
|
98
|
+
const message = typeof body.message === "string"
|
|
99
|
+
? body.message
|
|
100
|
+
: `Cloak request failed (${response.status}).`;
|
|
101
|
+
return new errors_js_1.CloakApiError(code, message, response.status, details);
|
|
102
|
+
}
|
|
103
|
+
function networkError(error, fallback) {
|
|
104
|
+
return new errors_js_1.CloakApiError("NETWORK_ERROR", error instanceof Error ? error.message : fallback, 0);
|
|
105
|
+
}
|
|
106
|
+
function rethrowAbort(error, signal) {
|
|
107
|
+
if ((error instanceof Error && error.name === "AbortError") || signal?.aborted) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function isRecord(value) {
|
|
112
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
113
|
+
}
|
|
114
|
+
function parseRetryAfter(value) {
|
|
115
|
+
if (!value)
|
|
116
|
+
return undefined;
|
|
117
|
+
const seconds = Number(value);
|
|
118
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds : undefined;
|
|
119
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** A fetch-compatible transport, injectable for runtimes without global fetch. */
|
|
2
|
+
export type CloakFetch = (input: string, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
export interface VeiloCloakConfig {
|
|
4
|
+
/** API origin or full Cloak URL. Defaults to https://api.veilo.network/. */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Partner key issued by Veilo. Sent only in the `x-api-key` header. */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Optional fetch implementation. Defaults to `globalThis.fetch`. */
|
|
9
|
+
fetch?: CloakFetch;
|
|
10
|
+
}
|
|
11
|
+
export interface CloakRequestOptions {
|
|
12
|
+
/** Cancels the HTTP request (and polling delay, when used for polling). */
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
export interface CloakCreateOrderOptions extends CloakRequestOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Deduplicates order creation. Strongly recommended even though the API falls
|
|
18
|
+
* back to the signed quote ID when this is omitted.
|
|
19
|
+
*/
|
|
20
|
+
idempotencyKey?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CloakWaitForFinalOptions extends CloakRequestOptions {
|
|
23
|
+
/** Delay between status reads. Defaults to 3 seconds. */
|
|
24
|
+
intervalMs?: number;
|
|
25
|
+
/** Optional total polling deadline. By default polling has no time limit. */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
/** Runs after every status read, including the final one. */
|
|
28
|
+
onStatus?: (order: CloakOrderStatus) => void | Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export type CloakQuoteMode = "exact_in" | "exact_out";
|
|
31
|
+
export interface CloakToken {
|
|
32
|
+
/** Veilo asset identifier. Echo this value back in quote requests. */
|
|
33
|
+
assetId: string;
|
|
34
|
+
/** Solana mint. Native SOL uses the all-zero system-program address. */
|
|
35
|
+
mint: string;
|
|
36
|
+
symbol: string;
|
|
37
|
+
decimals: number;
|
|
38
|
+
/** Minimum order amount in raw base units. */
|
|
39
|
+
minAmount: string;
|
|
40
|
+
/** Maximum order amount in raw base units. */
|
|
41
|
+
maxAmount: string;
|
|
42
|
+
}
|
|
43
|
+
export interface CloakTokensResponse {
|
|
44
|
+
success: true;
|
|
45
|
+
tokens: CloakToken[];
|
|
46
|
+
/** True when a usable cached catalogue was served after a refresh failure. */
|
|
47
|
+
stale?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface CloakQuoteRequest {
|
|
50
|
+
/** Amount in raw base units. Meaning is selected by `mode`. */
|
|
51
|
+
amount: string;
|
|
52
|
+
sourceAssetId: string;
|
|
53
|
+
/** Defaults to `sourceAssetId`; cross-asset Cloak transfers are not yet live. */
|
|
54
|
+
destinationAssetId?: string;
|
|
55
|
+
senderAddress: string;
|
|
56
|
+
recipientAddress: string;
|
|
57
|
+
/** Defaults to `exact_in`. */
|
|
58
|
+
mode?: CloakQuoteMode;
|
|
59
|
+
/** Required when `feeBps` is non-zero. */
|
|
60
|
+
feeRecipientAddress?: string;
|
|
61
|
+
/** Partner revenue share in basis points. */
|
|
62
|
+
feeBps?: number;
|
|
63
|
+
/** Optional cross-asset slippage band. The relayer clamps it to its supported range. */
|
|
64
|
+
slippageBps?: number;
|
|
65
|
+
}
|
|
66
|
+
export interface CloakFeeBreakdown {
|
|
67
|
+
/** Veilo fee in the quote's fee asset (source for sends, destination for swaps). */
|
|
68
|
+
veiloFee: string;
|
|
69
|
+
/** Partner fee in the quote's fee asset. */
|
|
70
|
+
partnerFee: string;
|
|
71
|
+
/** Relayer-funded on-chain cost in the quote's fee asset. */
|
|
72
|
+
networkFee: string;
|
|
73
|
+
/** Accepted when echoing compatibility quote shapes. */
|
|
74
|
+
partnerBps?: number;
|
|
75
|
+
/** Destination pool's own swap fee; present only for cross-asset quotes. */
|
|
76
|
+
poolSwapFee?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Terms cryptographically bound into a cross-asset signed quote. */
|
|
79
|
+
export interface CloakSwapQuoteTerms {
|
|
80
|
+
minSwapOut: string;
|
|
81
|
+
destNoteAmount: string;
|
|
82
|
+
slippageBps: number;
|
|
83
|
+
quotedOut: string;
|
|
84
|
+
}
|
|
85
|
+
/** Signed quote. Echo this object back unchanged when creating an order. */
|
|
86
|
+
export interface CloakQuote {
|
|
87
|
+
sourceAssetId: string;
|
|
88
|
+
destinationAssetId: string;
|
|
89
|
+
mode: CloakQuoteMode;
|
|
90
|
+
amountIn: string;
|
|
91
|
+
amountOut: string;
|
|
92
|
+
fee: string;
|
|
93
|
+
protocolFee: string;
|
|
94
|
+
networkFee: string;
|
|
95
|
+
feeBreakdown: CloakFeeBreakdown;
|
|
96
|
+
/** Present only when sourceAssetId and destinationAssetId differ. */
|
|
97
|
+
swap?: CloakSwapQuoteTerms;
|
|
98
|
+
/** Extra SOL paid by the sender's wallet, always denominated in lamports. */
|
|
99
|
+
senderNetworkFeeLamports: string;
|
|
100
|
+
duration: number;
|
|
101
|
+
min: string;
|
|
102
|
+
max: string;
|
|
103
|
+
quoteId: string;
|
|
104
|
+
issuedAt: string;
|
|
105
|
+
expiresAt: string;
|
|
106
|
+
}
|
|
107
|
+
export interface CloakQuoteResponse {
|
|
108
|
+
success: true;
|
|
109
|
+
quote: CloakQuote;
|
|
110
|
+
}
|
|
111
|
+
export interface CloakCreateOrderRequest {
|
|
112
|
+
/** The full object returned by `getQuote`; do not modify its values. */
|
|
113
|
+
quote: CloakQuote;
|
|
114
|
+
senderAddress: string;
|
|
115
|
+
recipientAddress: string;
|
|
116
|
+
/** Repeat the values used for the quote when charging a partner fee. */
|
|
117
|
+
feeRecipientAddress?: string;
|
|
118
|
+
feeBps?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface CloakOrderTransaction {
|
|
121
|
+
trackingId: string;
|
|
122
|
+
/** Unsigned Solana v0 transaction. */
|
|
123
|
+
transaction: string;
|
|
124
|
+
transactionEncoding: "base64";
|
|
125
|
+
amountIn: string;
|
|
126
|
+
amountOut: string;
|
|
127
|
+
expiration: string;
|
|
128
|
+
blockhashExpiresAtSlot: number;
|
|
129
|
+
}
|
|
130
|
+
export interface CloakCreatedOrder extends CloakOrderTransaction {
|
|
131
|
+
sourceSymbol: string;
|
|
132
|
+
destinationSymbol: string;
|
|
133
|
+
mint: string;
|
|
134
|
+
decimals: number;
|
|
135
|
+
/** Estimated seconds until the recipient is paid. */
|
|
136
|
+
eta: number;
|
|
137
|
+
}
|
|
138
|
+
export interface CloakCreateOrderResponse {
|
|
139
|
+
success: true;
|
|
140
|
+
order: CloakCreatedOrder;
|
|
141
|
+
}
|
|
142
|
+
export interface CloakRefreshTransactionResponse {
|
|
143
|
+
success: true;
|
|
144
|
+
order: CloakOrderTransaction;
|
|
145
|
+
}
|
|
146
|
+
export type CloakPartnerStatus = "PENDING" | "CONFIRMING" | "EXCHANGING" | "ANONYMIZING" | "SUCCESSFUL" | "FAILED" | "REFUNDED" | "EXPIRED";
|
|
147
|
+
export type CloakDetailedStatus = "awaiting_signature" | "deposit_seen" | "deposit_confirmed" | "swapping" | "swapped" | "queued_payout" | "paying" | "paid" | "refunding" | "refunded" | "expired" | "failed";
|
|
148
|
+
export interface CloakOrderStatus {
|
|
149
|
+
trackingId: string;
|
|
150
|
+
status: CloakPartnerStatus;
|
|
151
|
+
/** Monotone terminal flag. Safe to use for clearing an in-progress UI. */
|
|
152
|
+
final: boolean;
|
|
153
|
+
detailedStatus: CloakDetailedStatus;
|
|
154
|
+
amountIn: string;
|
|
155
|
+
amountOut: string;
|
|
156
|
+
sourceSymbol: string;
|
|
157
|
+
destinationSymbol: string;
|
|
158
|
+
depositTxSignature?: string | null;
|
|
159
|
+
payoutTxSignature?: string | null;
|
|
160
|
+
failureCode?: string;
|
|
161
|
+
updatedAt: string;
|
|
162
|
+
}
|
|
163
|
+
export interface CloakOrderStatusResponse {
|
|
164
|
+
success: true;
|
|
165
|
+
order: CloakOrderStatus;
|
|
166
|
+
}
|
|
167
|
+
export interface CloakDepositRequest {
|
|
168
|
+
trackingId: string;
|
|
169
|
+
txSignature: string;
|
|
170
|
+
}
|
|
171
|
+
export interface CloakDepositResponse {
|
|
172
|
+
success: true;
|
|
173
|
+
accepted: true;
|
|
174
|
+
}
|
|
175
|
+
/** Known stable error codes. New server codes remain available as plain strings. */
|
|
176
|
+
export type CloakErrorCode = "AMOUNT_BELOW_MIN" | "AMOUNT_ABOVE_MAX" | "QUOTE_FAILED" | "ASSET_NOT_SUPPORTED" | "INVALID_ADDRESS" | "PARTNER_FEE_TOO_HIGH" | "FEE_RECIPIENT_NOT_REGISTERED" | "FEE_RECIPIENT_COOLING_OFF" | "QUOTE_EXPIRED" | "QUOTE_MISMATCH" | "ORDER_IN_PROGRESS" | "IDEMPOTENCY_CONFLICT" | "ORDER_NOT_REFRESHABLE" | "ORDER_NOT_FOUND" | "UNAUTHORIZED" | "LIMIT_EXCEEDED" | "SERVICE_UNAVAILABLE" | "NETWORK_ERROR" | "INVALID_RESPONSE" | "POLL_TIMEOUT";
|
|
177
|
+
export interface CloakErrorResponse {
|
|
178
|
+
success?: false;
|
|
179
|
+
error?: CloakErrorCode | (string & {});
|
|
180
|
+
message?: string;
|
|
181
|
+
min?: string;
|
|
182
|
+
max?: string;
|
|
183
|
+
field?: string;
|
|
184
|
+
maxBps?: number;
|
|
185
|
+
retryAfter?: number;
|
|
186
|
+
status?: CloakPartnerStatus;
|
|
187
|
+
[key: string]: unknown;
|
|
188
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// Configuration and transport contracts
|
|
4
|
+
// =============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cloak/index.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Stable top-level entry point. Implementation lives in focused Cloak modules.
|
|
18
|
+
__exportStar(require("./cloak/index.js"), exports);
|