@veilo/sdk-core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +237 -19
- package/accounts.d.ts +2 -0
- package/accounts.js +3 -0
- package/cloak.d.ts +2 -0
- package/cloak.js +3 -0
- package/config.d.ts +2 -0
- package/config.js +3 -0
- package/dist/cjs/events/index.d.ts +6 -0
- package/dist/cjs/events/index.js +22 -0
- package/dist/cjs/events/parsing.d.ts +25 -0
- package/dist/cjs/events/parsing.js +158 -0
- package/dist/cjs/events/position.d.ts +26 -0
- package/dist/cjs/events/position.js +53 -0
- package/dist/cjs/events/recovery.d.ts +87 -0
- package/dist/cjs/events/recovery.js +281 -0
- package/dist/cjs/events/scanning.d.ts +35 -0
- package/dist/cjs/events/scanning.js +98 -0
- package/dist/cjs/events/tree.d.ts +27 -0
- package/dist/cjs/events/tree.js +63 -0
- package/dist/cjs/events/types.d.ts +39 -0
- package/dist/cjs/events/types.js +2 -0
- package/dist/cjs/events.d.ts +1 -77
- package/dist/cjs/events.js +6 -154
- package/dist/cjs/identity/encoding.d.ts +9 -0
- package/dist/cjs/identity/encoding.js +85 -0
- package/dist/cjs/identity/index.d.ts +4 -0
- package/dist/cjs/identity/index.js +20 -0
- package/dist/cjs/identity/noteKey.d.ts +33 -0
- package/dist/cjs/identity/noteKey.js +97 -0
- package/dist/cjs/identity/spending.d.ts +18 -0
- package/dist/cjs/identity/spending.js +46 -0
- package/dist/cjs/identity/viewKey.d.ts +38 -0
- package/dist/cjs/identity/viewKey.js +105 -0
- package/dist/cjs/idl/index.d.ts +18 -0
- package/dist/cjs/idl/index.js +24 -0
- package/dist/cjs/idl/privacy_pool.json +9907 -9907
- package/dist/cjs/idl/privacy_pool_legacy.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
- package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
- package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
- package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/cjs/index.d.ts +8 -3
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/notes/amount.d.ts +2 -0
- package/dist/cjs/notes/amount.js +21 -0
- package/dist/cjs/notes/index.d.ts +3 -0
- package/dist/cjs/notes/index.js +3 -0
- package/dist/cjs/notes/recovery.d.ts +16 -6
- package/dist/cjs/notes/recovery.js +33 -16
- package/dist/cjs/notes/selection.d.ts +77 -0
- package/dist/cjs/notes/selection.js +193 -0
- package/dist/cjs/notes/spent.d.ts +60 -0
- package/dist/cjs/notes/spent.js +101 -0
- package/dist/cjs/perps/constants.d.ts +16 -0
- package/dist/cjs/perps/constants.js +52 -0
- package/dist/cjs/perps/index.d.ts +5 -0
- package/dist/cjs/perps/index.js +21 -0
- package/dist/cjs/perps/keys.d.ts +16 -0
- package/dist/cjs/perps/keys.js +43 -0
- package/dist/cjs/perps/pdas.d.ts +29 -0
- package/dist/cjs/perps/pdas.js +55 -0
- package/dist/cjs/perps/relayer.d.ts +9 -0
- package/dist/cjs/perps/relayer.js +35 -0
- package/dist/cjs/perps/types.d.ts +126 -0
- package/dist/cjs/perps/types.js +2 -0
- package/dist/cjs/positions/index.d.ts +4 -0
- package/dist/cjs/positions/index.js +20 -0
- package/dist/cjs/positions/keys.d.ts +29 -0
- package/dist/cjs/positions/keys.js +71 -0
- package/dist/cjs/positions/pdas.d.ts +15 -0
- package/dist/cjs/positions/pdas.js +54 -0
- package/dist/cjs/positions/relayer.d.ts +4 -0
- package/dist/cjs/positions/relayer.js +15 -0
- package/dist/cjs/positions/types.d.ts +97 -0
- package/dist/cjs/positions/types.js +2 -0
- package/dist/cjs/predictions/client.d.ts +41 -0
- package/dist/cjs/predictions/client.js +147 -0
- package/dist/cjs/predictions/index.d.ts +5 -0
- package/dist/cjs/predictions/index.js +21 -0
- package/dist/cjs/predictions/keys.d.ts +14 -0
- package/dist/cjs/predictions/keys.js +40 -0
- package/dist/cjs/predictions/pdas.d.ts +6 -0
- package/dist/cjs/predictions/pdas.js +13 -0
- package/dist/cjs/predictions/relayer.d.ts +3 -0
- package/dist/cjs/predictions/relayer.js +11 -0
- package/dist/cjs/predictions/types.d.ts +178 -0
- package/dist/cjs/predictions/types.js +2 -0
- package/dist/cjs/program.d.ts +2 -0
- package/dist/cjs/program.js +8 -7
- package/dist/cjs/prover.d.ts +27 -4
- package/dist/cjs/prover.js +107 -48
- package/dist/cjs/relayer/api.d.ts +31 -0
- package/dist/cjs/relayer/api.js +86 -0
- package/dist/cjs/relayer/client.d.ts +29 -17
- package/dist/cjs/relayer/client.js +72 -17
- package/dist/cjs/relayer/errors.d.ts +1 -1
- package/dist/cjs/relayer/errors.js +1 -1
- package/dist/cjs/relayer/index.d.ts +4 -1
- package/dist/cjs/relayer/index.js +1 -1
- package/dist/cjs/relayer/internal-config.d.ts +36 -0
- package/dist/cjs/relayer/internal-config.js +9 -0
- package/dist/cjs/relayer/internal.d.ts +6 -0
- package/dist/cjs/relayer/internal.js +14 -0
- package/dist/cjs/relayer/transport.d.ts +4 -2
- package/dist/cjs/relayer/transport.js +10 -5
- package/dist/cjs/relayer/types.d.ts +9 -10
- package/dist/cjs/relayer/types.js +1 -1
- package/dist/cjs/shield/owner.js +1 -4
- package/dist/esm/events/index.d.ts +6 -0
- package/dist/esm/events/index.js +6 -0
- package/dist/esm/events/parsing.d.ts +25 -0
- package/dist/esm/events/parsing.js +120 -0
- package/dist/esm/events/position.d.ts +26 -0
- package/dist/esm/events/position.js +48 -0
- package/dist/esm/events/recovery.d.ts +87 -0
- package/dist/esm/events/recovery.js +237 -0
- package/dist/esm/events/scanning.d.ts +35 -0
- package/dist/esm/events/scanning.js +92 -0
- package/dist/esm/events/tree.d.ts +27 -0
- package/dist/esm/events/tree.js +58 -0
- package/dist/esm/events/types.d.ts +39 -0
- package/dist/esm/events/types.js +1 -0
- package/dist/esm/events.d.ts +1 -77
- package/dist/esm/events.js +3 -129
- package/dist/esm/identity/encoding.d.ts +9 -0
- package/dist/esm/identity/encoding.js +75 -0
- package/dist/esm/identity/index.d.ts +4 -0
- package/dist/esm/identity/index.js +4 -0
- package/dist/esm/identity/noteKey.d.ts +33 -0
- package/dist/esm/identity/noteKey.js +91 -0
- package/dist/esm/identity/spending.d.ts +18 -0
- package/dist/esm/identity/spending.js +35 -0
- package/dist/esm/identity/viewKey.d.ts +38 -0
- package/dist/esm/identity/viewKey.js +96 -0
- package/dist/esm/idl/index.d.ts +18 -0
- package/dist/esm/idl/index.js +18 -0
- package/dist/esm/idl/privacy_pool.json +9907 -9907
- package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
- package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
- package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
- package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/esm/index.d.ts +8 -3
- package/dist/esm/index.js +8 -3
- package/dist/esm/notes/amount.d.ts +2 -0
- package/dist/esm/notes/amount.js +18 -0
- package/dist/esm/notes/index.d.ts +3 -0
- package/dist/esm/notes/index.js +3 -0
- package/dist/esm/notes/recovery.d.ts +16 -6
- package/dist/esm/notes/recovery.js +33 -16
- package/dist/esm/notes/selection.d.ts +77 -0
- package/dist/esm/notes/selection.js +188 -0
- package/dist/esm/notes/spent.d.ts +60 -0
- package/dist/esm/notes/spent.js +96 -0
- package/dist/esm/perps/constants.d.ts +16 -0
- package/dist/esm/perps/constants.js +48 -0
- package/dist/esm/perps/index.d.ts +5 -0
- package/dist/esm/perps/index.js +5 -0
- package/dist/esm/perps/keys.d.ts +16 -0
- package/dist/esm/perps/keys.js +35 -0
- package/dist/esm/perps/pdas.d.ts +29 -0
- package/dist/esm/perps/pdas.js +47 -0
- package/dist/esm/perps/relayer.d.ts +9 -0
- package/dist/esm/perps/relayer.js +25 -0
- package/dist/esm/perps/types.d.ts +126 -0
- package/dist/esm/perps/types.js +1 -0
- package/dist/esm/positions/index.d.ts +4 -0
- package/dist/esm/positions/index.js +4 -0
- package/dist/esm/positions/keys.d.ts +29 -0
- package/dist/esm/positions/keys.js +65 -0
- package/dist/esm/positions/pdas.d.ts +15 -0
- package/dist/esm/positions/pdas.js +44 -0
- package/dist/esm/positions/relayer.d.ts +4 -0
- package/dist/esm/positions/relayer.js +10 -0
- package/dist/esm/positions/types.d.ts +97 -0
- package/dist/esm/positions/types.js +1 -0
- package/dist/esm/predictions/client.d.ts +41 -0
- package/dist/esm/predictions/client.js +141 -0
- package/dist/esm/predictions/index.d.ts +5 -0
- package/dist/esm/predictions/index.js +5 -0
- package/dist/esm/predictions/keys.d.ts +14 -0
- package/dist/esm/predictions/keys.js +33 -0
- package/dist/esm/predictions/pdas.d.ts +6 -0
- package/dist/esm/predictions/pdas.js +10 -0
- package/dist/esm/predictions/relayer.d.ts +3 -0
- package/dist/esm/predictions/relayer.js +7 -0
- package/dist/esm/predictions/types.d.ts +178 -0
- package/dist/esm/predictions/types.js +1 -0
- package/dist/esm/program.d.ts +2 -0
- package/dist/esm/program.js +4 -3
- package/dist/esm/prover.d.ts +27 -4
- package/dist/esm/prover.js +106 -15
- package/dist/esm/relayer/api.d.ts +31 -0
- package/dist/esm/relayer/api.js +55 -0
- package/dist/esm/relayer/client.d.ts +29 -17
- package/dist/esm/relayer/client.js +72 -17
- package/dist/esm/relayer/errors.d.ts +1 -1
- package/dist/esm/relayer/errors.js +1 -1
- package/dist/esm/relayer/index.d.ts +4 -1
- package/dist/esm/relayer/index.js +1 -1
- package/dist/esm/relayer/internal-config.d.ts +36 -0
- package/dist/esm/relayer/internal-config.js +6 -0
- package/dist/esm/relayer/internal.d.ts +6 -0
- package/dist/esm/relayer/internal.js +10 -0
- package/dist/esm/relayer/transport.d.ts +4 -2
- package/dist/esm/relayer/transport.js +10 -5
- package/dist/esm/relayer/types.d.ts +9 -10
- package/dist/esm/relayer/types.js +1 -1
- package/dist/esm/shield/owner.js +1 -4
- package/identity.d.ts +2 -0
- package/identity.js +3 -0
- package/idl.d.ts +2 -0
- package/idl.js +3 -0
- package/notes.d.ts +2 -0
- package/notes.js +3 -0
- package/package.json +85 -3
- package/perps.d.ts +2 -0
- package/perps.js +3 -0
- package/poseidon.d.ts +2 -0
- package/poseidon.js +3 -0
- package/positions.d.ts +2 -0
- package/positions.js +3 -0
- package/predictions.d.ts +2 -0
- package/predictions.js +3 -0
- package/proof.d.ts +2 -0
- package/proof.js +3 -0
- package/prover.d.ts +2 -0
- package/prover.js +3 -0
- package/relayer.d.ts +2 -0
- package/relayer.js +3 -0
- package/shield.d.ts +2 -0
- package/shield.js +3 -0
- package/transactions.d.ts +2 -0
- package/transactions.js +3 -0
package/dist/cjs/prover.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { type SwapProofBuilder } from "./proofs/swap.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Circuit artifact paths required by snarkjs.
|
|
5
5
|
*
|
|
6
|
-
* These files are large (10-100 MB) and
|
|
7
|
-
*
|
|
6
|
+
* These files are large (10-100 MB) and are NOT bundled in the npm package —
|
|
7
|
+
* `files` ships `dist/` only. Optional: omit them and the prover resolves a
|
|
8
|
+
* local copy (see `resolveCircuitArtifacts`). Supply them explicitly whenever
|
|
9
|
+
* the defaults cannot apply, which includes every browser build.
|
|
8
10
|
*
|
|
9
11
|
* For Node.js: pass file system paths (e.g. "./circuits/transaction.wasm").
|
|
10
12
|
* For browsers: pass Uint8Array buffers or URLs that fetch returns as ArrayBuffer.
|
|
@@ -15,6 +17,27 @@ export interface CircuitArtifacts {
|
|
|
15
17
|
/** Path or buffer for the Groth16 proving key (.zkey) */
|
|
16
18
|
zkeyPath: string | Uint8Array;
|
|
17
19
|
}
|
|
20
|
+
/** The circuits this package can resolve artifacts for. */
|
|
21
|
+
export type CircuitName = "transaction" | "swap";
|
|
22
|
+
/**
|
|
23
|
+
* Resolve circuit artifacts from disk when the caller did not supply them.
|
|
24
|
+
*
|
|
25
|
+
* Search order, first hit wins:
|
|
26
|
+
*
|
|
27
|
+
* 1. $VEILO_CIRCUITS_DIR explicit override
|
|
28
|
+
* 2. <package>/circuits populated by `npm run copy:circuits`
|
|
29
|
+
* 3. <cwd>/circuits
|
|
30
|
+
* 4. <cwd>/node_modules/@veilo/sdk-core/circuits
|
|
31
|
+
*
|
|
32
|
+
* NODE ONLY, AND DELIBERATELY LAZY. `node:fs` is imported inside the call, not
|
|
33
|
+
* at module scope: this module is reachable from the package root export, and a
|
|
34
|
+
* top-level `node:fs` import throws at bundle time in browser builds with no
|
|
35
|
+
* Node polyfill — the same reason `random.ts` avoids `node:crypto`. Browsers
|
|
36
|
+
* must pass `CircuitArtifacts` explicitly; there is nothing to resolve there.
|
|
37
|
+
*
|
|
38
|
+
* @throws when no candidate directory holds both files, listing what it tried
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveCircuitArtifacts(circuit: CircuitName): Promise<CircuitArtifacts>;
|
|
18
41
|
/**
|
|
19
42
|
* Create a proof builder function for the transaction circuit.
|
|
20
43
|
*
|
|
@@ -41,9 +64,9 @@ export interface CircuitArtifacts {
|
|
|
41
64
|
* const proof = await prover(circuitInputs);
|
|
42
65
|
* ```
|
|
43
66
|
*/
|
|
44
|
-
export declare function createTransactionProver(artifacts
|
|
67
|
+
export declare function createTransactionProver(artifacts?: CircuitArtifacts): TransactionProofBuilder;
|
|
45
68
|
/** Create a proof builder for the current `swap.circom` witness shape. */
|
|
46
|
-
export declare function createSwapProver(artifacts
|
|
69
|
+
export declare function createSwapProver(artifacts?: CircuitArtifacts): SwapProofBuilder;
|
|
47
70
|
/**
|
|
48
71
|
* Verify a Groth16 proof against public signals and a verification key.
|
|
49
72
|
*
|
package/dist/cjs/prover.js
CHANGED
|
@@ -1,53 +1,98 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveCircuitArtifacts = resolveCircuitArtifacts;
|
|
36
4
|
exports.createTransactionProver = createTransactionProver;
|
|
37
5
|
exports.createSwapProver = createSwapProver;
|
|
38
6
|
exports.verifyProof = verifyProof;
|
|
39
7
|
const formatting_js_1 = require("./proofs/formatting.js");
|
|
40
8
|
const swap_js_1 = require("./proofs/swap.js");
|
|
41
|
-
/**
|
|
42
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Lazy-load snarkjs — works in both CJS and ESM contexts.
|
|
11
|
+
*
|
|
12
|
+
* The import is built through `Function` so TypeScript cannot rewrite it into a
|
|
13
|
+
* `require()` in the CommonJS build, and bundlers cannot follow it into browser
|
|
14
|
+
* output. Never call `require("snarkjs")` directly here: `require` is not
|
|
15
|
+
* defined in the ESM build, so it throws ReferenceError instead of this
|
|
16
|
+
* message.
|
|
17
|
+
*/
|
|
18
|
+
async function loadSnarkjs(purpose = "proof generation") {
|
|
43
19
|
try {
|
|
44
20
|
// Dynamic import works in both CJS (Node 12+) and ESM
|
|
45
21
|
return await Function('return import("snarkjs")')();
|
|
46
22
|
}
|
|
47
23
|
catch {
|
|
48
|
-
throw new Error(
|
|
24
|
+
throw new Error(`snarkjs is required for ${purpose}. Install it: npm install snarkjs`);
|
|
49
25
|
}
|
|
50
26
|
}
|
|
27
|
+
/** Layout produced by `npm run copy:circuits`, relative to a circuits root. */
|
|
28
|
+
const ARTIFACT_LAYOUT = {
|
|
29
|
+
transaction: {
|
|
30
|
+
wasm: "transaction/transaction_js/transaction.wasm",
|
|
31
|
+
zkey: "transaction/transaction_final.zkey",
|
|
32
|
+
},
|
|
33
|
+
swap: {
|
|
34
|
+
wasm: "swap/swap_js/swap.wasm",
|
|
35
|
+
zkey: "swap/swap_final.zkey",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Resolve circuit artifacts from disk when the caller did not supply them.
|
|
40
|
+
*
|
|
41
|
+
* Search order, first hit wins:
|
|
42
|
+
*
|
|
43
|
+
* 1. $VEILO_CIRCUITS_DIR explicit override
|
|
44
|
+
* 2. <package>/circuits populated by `npm run copy:circuits`
|
|
45
|
+
* 3. <cwd>/circuits
|
|
46
|
+
* 4. <cwd>/node_modules/@veilo/sdk-core/circuits
|
|
47
|
+
*
|
|
48
|
+
* NODE ONLY, AND DELIBERATELY LAZY. `node:fs` is imported inside the call, not
|
|
49
|
+
* at module scope: this module is reachable from the package root export, and a
|
|
50
|
+
* top-level `node:fs` import throws at bundle time in browser builds with no
|
|
51
|
+
* Node polyfill — the same reason `random.ts` avoids `node:crypto`. Browsers
|
|
52
|
+
* must pass `CircuitArtifacts` explicitly; there is nothing to resolve there.
|
|
53
|
+
*
|
|
54
|
+
* @throws when no candidate directory holds both files, listing what it tried
|
|
55
|
+
*/
|
|
56
|
+
async function resolveCircuitArtifacts(circuit) {
|
|
57
|
+
let fs;
|
|
58
|
+
let path;
|
|
59
|
+
try {
|
|
60
|
+
fs = await Function('return import("node:fs")')();
|
|
61
|
+
path = await Function('return import("node:path")')();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw new Error(`Cannot resolve ${circuit} circuit artifacts: no filesystem available. ` +
|
|
65
|
+
"Pass CircuitArtifacts explicitly (browsers must supply buffers or URLs).");
|
|
66
|
+
}
|
|
67
|
+
const layout = ARTIFACT_LAYOUT[circuit];
|
|
68
|
+
if (!layout) {
|
|
69
|
+
throw new Error(`Unknown circuit ${JSON.stringify(circuit)}. Known circuits: ` +
|
|
70
|
+
`${Object.keys(ARTIFACT_LAYOUT).join(", ")}.`);
|
|
71
|
+
}
|
|
72
|
+
const cwd = typeof process !== "undefined" ? process.cwd() : ".";
|
|
73
|
+
// __dirname exists in the CJS build; the ESM build falls back to cwd-relative
|
|
74
|
+
// candidates. dist/cjs/prover.js → ../../circuits is the package root copy.
|
|
75
|
+
const packageDir = typeof __dirname !== "undefined"
|
|
76
|
+
? path.resolve(__dirname, "..", "..", "circuits")
|
|
77
|
+
: undefined;
|
|
78
|
+
const roots = [
|
|
79
|
+
process.env?.VEILO_CIRCUITS_DIR,
|
|
80
|
+
packageDir,
|
|
81
|
+
path.resolve(cwd, "circuits"),
|
|
82
|
+
path.resolve(cwd, "node_modules", "@veilo", "sdk-core", "circuits"),
|
|
83
|
+
].filter((root) => Boolean(root));
|
|
84
|
+
for (const root of roots) {
|
|
85
|
+
const wasmPath = path.resolve(root, layout.wasm);
|
|
86
|
+
const zkeyPath = path.resolve(root, layout.zkey);
|
|
87
|
+
if (fs.existsSync(wasmPath) && fs.existsSync(zkeyPath)) {
|
|
88
|
+
return { wasmPath, zkeyPath };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Cannot resolve ${circuit} circuit artifacts. Looked for ${layout.wasm} ` +
|
|
92
|
+
`and ${layout.zkey} under:\n ${roots.join("\n ")}\n` +
|
|
93
|
+
"Run `npm run copy:circuits` in the SDK, set VEILO_CIRCUITS_DIR, or pass " +
|
|
94
|
+
"CircuitArtifacts explicitly.");
|
|
95
|
+
}
|
|
51
96
|
/**
|
|
52
97
|
* Create a proof builder function for the transaction circuit.
|
|
53
98
|
*
|
|
@@ -75,18 +120,30 @@ async function loadSnarkjs() {
|
|
|
75
120
|
* ```
|
|
76
121
|
*/
|
|
77
122
|
function createTransactionProver(artifacts) {
|
|
123
|
+
// Resolved on first use, not at factory time: constructing a prover must stay
|
|
124
|
+
// free of filesystem access so browser bundles can import this module.
|
|
125
|
+
let resolved;
|
|
78
126
|
return async (inputs) => {
|
|
79
127
|
const snarkjs = await loadSnarkjs();
|
|
128
|
+
resolved ?? (resolved = artifacts
|
|
129
|
+
? Promise.resolve(artifacts)
|
|
130
|
+
: resolveCircuitArtifacts("transaction"));
|
|
131
|
+
const { wasmPath, zkeyPath } = await resolved;
|
|
80
132
|
const formattedInputs = (0, formatting_js_1.formatInputsForSnarkjs)(inputs);
|
|
81
|
-
const { proof } = await snarkjs.groth16.fullProve(formattedInputs,
|
|
133
|
+
const { proof } = await snarkjs.groth16.fullProve(formattedInputs, wasmPath, zkeyPath);
|
|
82
134
|
return proof;
|
|
83
135
|
};
|
|
84
136
|
}
|
|
85
137
|
/** Create a proof builder for the current `swap.circom` witness shape. */
|
|
86
138
|
function createSwapProver(artifacts) {
|
|
139
|
+
let resolved;
|
|
87
140
|
return async (inputs) => {
|
|
88
141
|
const snarkjs = await loadSnarkjs();
|
|
89
|
-
|
|
142
|
+
resolved ?? (resolved = artifacts
|
|
143
|
+
? Promise.resolve(artifacts)
|
|
144
|
+
: resolveCircuitArtifacts("swap"));
|
|
145
|
+
const { wasmPath, zkeyPath } = await resolved;
|
|
146
|
+
const { proof } = await snarkjs.groth16.fullProve((0, swap_js_1.formatSwapInputsForSnarkjs)(inputs), wasmPath, zkeyPath);
|
|
90
147
|
return proof;
|
|
91
148
|
};
|
|
92
149
|
}
|
|
@@ -101,18 +158,20 @@ function createSwapProver(artifacts) {
|
|
|
101
158
|
* @returns true if the proof is valid
|
|
102
159
|
*/
|
|
103
160
|
async function verifyProof(proof, publicSignals, vkey) {
|
|
104
|
-
|
|
105
|
-
let snarkjs;
|
|
106
|
-
try {
|
|
107
|
-
snarkjs = require("snarkjs");
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
throw new Error('snarkjs is required for proof verification. Install it: npm install snarkjs');
|
|
111
|
-
}
|
|
161
|
+
const snarkjs = await loadSnarkjs("proof verification");
|
|
112
162
|
let vkeyObj;
|
|
113
163
|
if (typeof vkey === "string") {
|
|
114
|
-
// Node.js file path — read and parse
|
|
115
|
-
|
|
164
|
+
// Node.js file path — read and parse. Same hidden import as
|
|
165
|
+
// resolveCircuitArtifacts: a plain `await import("fs")` is followed by
|
|
166
|
+
// bundlers and breaks browser builds that have no Node polyfill.
|
|
167
|
+
let fs;
|
|
168
|
+
try {
|
|
169
|
+
fs = await Function('return import("node:fs")')();
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
throw new Error("Reading a verification key from a path requires Node. Pass the parsed " +
|
|
173
|
+
"verification key object instead.");
|
|
174
|
+
}
|
|
116
175
|
vkeyObj = JSON.parse(fs.readFileSync(vkey, "utf-8"));
|
|
117
176
|
}
|
|
118
177
|
else {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CheckNullifiersResponse, ChallengeResponse, CheckUsernameResponse, DeleteUserDataResponse, MerkleRootResponse, MerkleTreeResponse, PreRegisterKeyResponse, PrivateSwapRequest, PrivateSwapResponse, PrivateTransferRequest, PrivateTransferResponse, QueryNotesRequest, QueryNotesResponse, RegisterRequest, RegisterResponse, RestoreRequest, RestoreResponse, SaveEncryptedNoteRequest, SaveEncryptedNoteResponse, VeiloPublicKeyResponse, WithdrawRequest, WithdrawResponse } from "./types.js";
|
|
2
|
+
/** Request a wallet-authentication challenge from Veilo. */
|
|
3
|
+
export declare function getChallenge(walletPublicKey: string): Promise<ChallengeResponse>;
|
|
4
|
+
/** Register a Veilo account and receive its auth token. */
|
|
5
|
+
export declare function register(data: RegisterRequest): Promise<RegisterResponse>;
|
|
6
|
+
/** Restore a Veilo account and receive its auth token. */
|
|
7
|
+
export declare function restore(data: RestoreRequest): Promise<RestoreResponse>;
|
|
8
|
+
export declare function checkUsername(username: string): Promise<CheckUsernameResponse>;
|
|
9
|
+
export declare function getVeiloPublicKey(params: {
|
|
10
|
+
username: string;
|
|
11
|
+
publicKey?: never;
|
|
12
|
+
} | {
|
|
13
|
+
publicKey: string;
|
|
14
|
+
username?: never;
|
|
15
|
+
}): Promise<VeiloPublicKeyResponse>;
|
|
16
|
+
export declare function preRegisterKey(solanaAddress: string): Promise<PreRegisterKeyResponse>;
|
|
17
|
+
export declare function saveEncryptedNote(data: SaveEncryptedNoteRequest): Promise<SaveEncryptedNoteResponse>;
|
|
18
|
+
/** Query notes with an explicit per-call token; no auth state is shared. */
|
|
19
|
+
export declare function queryEncryptedNotes(authToken: string, params?: QueryNotesRequest): Promise<QueryNotesResponse>;
|
|
20
|
+
/** Delete the authenticated user's stored data without retaining their token. */
|
|
21
|
+
export declare function deleteUserData(authToken: string): Promise<DeleteUserDataResponse>;
|
|
22
|
+
/** Raw check-batch call. Prefer `checkNullifiersSpent`, which chunks for you. */
|
|
23
|
+
export declare function checkNullifiers(nullifiers: string[]): Promise<CheckNullifiersResponse>;
|
|
24
|
+
export declare function getMerkleRoot(mintAddress?: string, treeId?: number): Promise<MerkleRootResponse>;
|
|
25
|
+
export declare function getMerkleTree(mintAddress?: string, treeId?: number): Promise<MerkleTreeResponse>;
|
|
26
|
+
export declare function submitWithdraw(data: WithdrawRequest): Promise<WithdrawResponse>;
|
|
27
|
+
export declare function submitPrivateTransfer(data: PrivateTransferRequest): Promise<PrivateTransferResponse>;
|
|
28
|
+
export declare function submitPrivateSwap(data: PrivateSwapRequest): Promise<PrivateSwapResponse>;
|
|
29
|
+
export { submitClosePosition, submitMergePositions, submitOpenPosition, } from "../positions/relayer.js";
|
|
30
|
+
export { submitJperpCancelTrigger, submitJperpClose, submitJperpOpen, submitJperpRecoverNative, submitJperpRecoverSeed, submitJperpReissue, submitJperpSetTpsl, submitJperpUpdateTpsl, } from "../perps/relayer.js";
|
|
31
|
+
export { submitPredictionOpen, submitPredictionReissue, } from "../predictions/relayer.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitPredictionReissue = exports.submitPredictionOpen = exports.submitJperpUpdateTpsl = exports.submitJperpSetTpsl = exports.submitJperpReissue = exports.submitJperpRecoverSeed = exports.submitJperpRecoverNative = exports.submitJperpOpen = exports.submitJperpClose = exports.submitJperpCancelTrigger = exports.submitOpenPosition = exports.submitMergePositions = exports.submitClosePosition = void 0;
|
|
4
|
+
exports.getChallenge = getChallenge;
|
|
5
|
+
exports.register = register;
|
|
6
|
+
exports.restore = restore;
|
|
7
|
+
exports.checkUsername = checkUsername;
|
|
8
|
+
exports.getVeiloPublicKey = getVeiloPublicKey;
|
|
9
|
+
exports.preRegisterKey = preRegisterKey;
|
|
10
|
+
exports.saveEncryptedNote = saveEncryptedNote;
|
|
11
|
+
exports.queryEncryptedNotes = queryEncryptedNotes;
|
|
12
|
+
exports.deleteUserData = deleteUserData;
|
|
13
|
+
exports.checkNullifiers = checkNullifiers;
|
|
14
|
+
exports.getMerkleRoot = getMerkleRoot;
|
|
15
|
+
exports.getMerkleTree = getMerkleTree;
|
|
16
|
+
exports.submitWithdraw = submitWithdraw;
|
|
17
|
+
exports.submitPrivateTransfer = submitPrivateTransfer;
|
|
18
|
+
exports.submitPrivateSwap = submitPrivateSwap;
|
|
19
|
+
const internal_js_1 = require("./internal.js");
|
|
20
|
+
/** Request a wallet-authentication challenge from Veilo. */
|
|
21
|
+
function getChallenge(walletPublicKey) {
|
|
22
|
+
return (0, internal_js_1.getInternalRelayerClient)().getChallenge(walletPublicKey);
|
|
23
|
+
}
|
|
24
|
+
/** Register a Veilo account and receive its auth token. */
|
|
25
|
+
function register(data) {
|
|
26
|
+
return (0, internal_js_1.getInternalRelayerClient)().register(data);
|
|
27
|
+
}
|
|
28
|
+
/** Restore a Veilo account and receive its auth token. */
|
|
29
|
+
function restore(data) {
|
|
30
|
+
return (0, internal_js_1.getInternalRelayerClient)().restore(data);
|
|
31
|
+
}
|
|
32
|
+
function checkUsername(username) {
|
|
33
|
+
return (0, internal_js_1.getInternalRelayerClient)().checkUsername(username);
|
|
34
|
+
}
|
|
35
|
+
function getVeiloPublicKey(params) {
|
|
36
|
+
return (0, internal_js_1.getInternalRelayerClient)().getVeiloPublicKey(params);
|
|
37
|
+
}
|
|
38
|
+
function preRegisterKey(solanaAddress) {
|
|
39
|
+
return (0, internal_js_1.getInternalRelayerClient)().preRegisterKey(solanaAddress);
|
|
40
|
+
}
|
|
41
|
+
function saveEncryptedNote(data) {
|
|
42
|
+
return (0, internal_js_1.getInternalRelayerClient)().saveEncryptedNote(data);
|
|
43
|
+
}
|
|
44
|
+
/** Query notes with an explicit per-call token; no auth state is shared. */
|
|
45
|
+
function queryEncryptedNotes(authToken, params = {}) {
|
|
46
|
+
return (0, internal_js_1.createInternalRelayerClient)({ authToken }).queryEncryptedNotes(params);
|
|
47
|
+
}
|
|
48
|
+
/** Delete the authenticated user's stored data without retaining their token. */
|
|
49
|
+
function deleteUserData(authToken) {
|
|
50
|
+
return (0, internal_js_1.createInternalRelayerClient)({ authToken }).deleteUserData();
|
|
51
|
+
}
|
|
52
|
+
/** Raw check-batch call. Prefer `checkNullifiersSpent`, which chunks for you. */
|
|
53
|
+
function checkNullifiers(nullifiers) {
|
|
54
|
+
return (0, internal_js_1.getInternalRelayerClient)().checkNullifiers(nullifiers);
|
|
55
|
+
}
|
|
56
|
+
function getMerkleRoot(mintAddress, treeId) {
|
|
57
|
+
return (0, internal_js_1.getInternalRelayerClient)().getMerkleRoot(mintAddress, treeId);
|
|
58
|
+
}
|
|
59
|
+
function getMerkleTree(mintAddress, treeId) {
|
|
60
|
+
return (0, internal_js_1.getInternalRelayerClient)().getMerkleTree(mintAddress, treeId);
|
|
61
|
+
}
|
|
62
|
+
function submitWithdraw(data) {
|
|
63
|
+
return (0, internal_js_1.getInternalRelayerClient)().submitWithdraw(data);
|
|
64
|
+
}
|
|
65
|
+
function submitPrivateTransfer(data) {
|
|
66
|
+
return (0, internal_js_1.getInternalRelayerClient)().submitPrivateTransfer(data);
|
|
67
|
+
}
|
|
68
|
+
function submitPrivateSwap(data) {
|
|
69
|
+
return (0, internal_js_1.getInternalRelayerClient)().submitPrivateSwap(data);
|
|
70
|
+
}
|
|
71
|
+
var relayer_js_1 = require("../positions/relayer.js");
|
|
72
|
+
Object.defineProperty(exports, "submitClosePosition", { enumerable: true, get: function () { return relayer_js_1.submitClosePosition; } });
|
|
73
|
+
Object.defineProperty(exports, "submitMergePositions", { enumerable: true, get: function () { return relayer_js_1.submitMergePositions; } });
|
|
74
|
+
Object.defineProperty(exports, "submitOpenPosition", { enumerable: true, get: function () { return relayer_js_1.submitOpenPosition; } });
|
|
75
|
+
var relayer_js_2 = require("../perps/relayer.js");
|
|
76
|
+
Object.defineProperty(exports, "submitJperpCancelTrigger", { enumerable: true, get: function () { return relayer_js_2.submitJperpCancelTrigger; } });
|
|
77
|
+
Object.defineProperty(exports, "submitJperpClose", { enumerable: true, get: function () { return relayer_js_2.submitJperpClose; } });
|
|
78
|
+
Object.defineProperty(exports, "submitJperpOpen", { enumerable: true, get: function () { return relayer_js_2.submitJperpOpen; } });
|
|
79
|
+
Object.defineProperty(exports, "submitJperpRecoverNative", { enumerable: true, get: function () { return relayer_js_2.submitJperpRecoverNative; } });
|
|
80
|
+
Object.defineProperty(exports, "submitJperpRecoverSeed", { enumerable: true, get: function () { return relayer_js_2.submitJperpRecoverSeed; } });
|
|
81
|
+
Object.defineProperty(exports, "submitJperpReissue", { enumerable: true, get: function () { return relayer_js_2.submitJperpReissue; } });
|
|
82
|
+
Object.defineProperty(exports, "submitJperpSetTpsl", { enumerable: true, get: function () { return relayer_js_2.submitJperpSetTpsl; } });
|
|
83
|
+
Object.defineProperty(exports, "submitJperpUpdateTpsl", { enumerable: true, get: function () { return relayer_js_2.submitJperpUpdateTpsl; } });
|
|
84
|
+
var relayer_js_3 = require("../predictions/relayer.js");
|
|
85
|
+
Object.defineProperty(exports, "submitPredictionOpen", { enumerable: true, get: function () { return relayer_js_3.submitPredictionOpen; } });
|
|
86
|
+
Object.defineProperty(exports, "submitPredictionReissue", { enumerable: true, get: function () { return relayer_js_3.submitPredictionReissue; } });
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import type { ChallengeResponse, CheckUsernameResponse, DeleteUserDataResponse, MerkleRootResponse, MerkleTreeResponse, PreRegisterKeyResponse, PrivateSwapRequest, PrivateSwapResponse, PrivateTransferRequest, PrivateTransferResponse, QueryNotesRequest, QueryNotesResponse, RegisterRequest, RegisterResponse, RestoreRequest, RestoreResponse, RetryPolicy, SaveEncryptedNoteRequest, SaveEncryptedNoteResponse, VeiloPublicKeyResponse,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const client = new VeiloRelayerClient({
|
|
11
|
-
* apiKey: "your-api-key",
|
|
12
|
-
* relayerPublicKey: "<base64 NaCl public key>",
|
|
13
|
-
* });
|
|
14
|
-
* const root = await client.getMerkleRoot("So111...");
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
1
|
+
import type { CheckNullifiersResponse, ChallengeResponse, CheckUsernameResponse, DeleteUserDataResponse, MerkleRootResponse, MerkleTreeResponse, PreRegisterKeyResponse, PrivateSwapRequest, PrivateSwapResponse, PrivateTransferRequest, PrivateTransferResponse, QueryNotesRequest, QueryNotesResponse, RegisterRequest, RegisterResponse, RestoreRequest, RestoreResponse, RetryPolicy, SaveEncryptedNoteRequest, SaveEncryptedNoteResponse, VeiloPublicKeyResponse, WithdrawRequest, WithdrawResponse } from "./types.js";
|
|
2
|
+
import { type InternalRelayerClientOptions } from "./internal-config.js";
|
|
3
|
+
import type { ClosePositionRequest, ClosePositionResponse, MergePositionsRequest, MergePositionsResponse, OpenPositionRequest, OpenPositionResponse } from "../positions/types.js";
|
|
4
|
+
import type { JperpCancelTriggerRequest, JperpCancelTriggerResponse, JperpCloseRequest, JperpDecreaseResponse, JperpOpenRequest, JperpOpenResponse, JperpRecoverNativeRequest, JperpRecoverNativeResponse, JperpRecoverSeedRequest, JperpRecoverSeedResponse, JperpReissueRequest, JperpReissueResponse, JperpSetTpslRequest, JperpUpdateTpslRequest } from "../perps/types.js";
|
|
5
|
+
import type { PredictionOpenRequest, PredictionOpenResponse, PredictionReissueRequest, PredictionReissueResponse } from "../predictions/types.js";
|
|
6
|
+
/** @internal Relayer transport behind the SDK's functional helpers. */
|
|
17
7
|
export declare class VeiloRelayerClient {
|
|
18
8
|
private readonly transport;
|
|
19
9
|
private readonly relayerPubKey;
|
|
20
|
-
constructor(config
|
|
10
|
+
constructor(config?: InternalRelayerClientOptions, retry?: Partial<RetryPolicy>);
|
|
21
11
|
/** Update the auth token (e.g. after register/restore). */
|
|
22
12
|
setAuthToken(token: string): void;
|
|
23
13
|
private encryptPayload;
|
|
@@ -47,6 +37,14 @@ export declare class VeiloRelayerClient {
|
|
|
47
37
|
/** Query encrypted notes for the authenticated user. Requires auth token. */
|
|
48
38
|
queryEncryptedNotes(params?: QueryNotesRequest): Promise<QueryNotesResponse>;
|
|
49
39
|
/** Delete all stored data for the authenticated user. Requires auth token. */
|
|
40
|
+
/**
|
|
41
|
+
* Ask which of these nullifiers the relayer has seen spent.
|
|
42
|
+
*
|
|
43
|
+
* Caller must respect MAX_NULLIFIERS_PER_CHECK; `checkNullifiersSpent` in
|
|
44
|
+
* notes/spent.ts does the chunking. Unauthenticated: a nullifier reveals
|
|
45
|
+
* nothing about ownership on its own.
|
|
46
|
+
*/
|
|
47
|
+
checkNullifiers(nullifiers: string[]): Promise<CheckNullifiersResponse>;
|
|
50
48
|
deleteUserData(): Promise<DeleteUserDataResponse>;
|
|
51
49
|
/** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
|
|
52
50
|
getMerkleRoot(mintAddress?: string, treeId?: number): Promise<MerkleRootResponse>;
|
|
@@ -58,4 +56,18 @@ export declare class VeiloRelayerClient {
|
|
|
58
56
|
submitPrivateTransfer(data: PrivateTransferRequest): Promise<PrivateTransferResponse>;
|
|
59
57
|
/** Submit an encrypted private swap request. Not retried on failure. */
|
|
60
58
|
submitPrivateSwap(data: PrivateSwapRequest): Promise<PrivateSwapResponse>;
|
|
59
|
+
submitOpenPosition(data: OpenPositionRequest): Promise<OpenPositionResponse>;
|
|
60
|
+
submitClosePosition(data: ClosePositionRequest): Promise<ClosePositionResponse>;
|
|
61
|
+
submitMergePositions(data: MergePositionsRequest): Promise<MergePositionsResponse>;
|
|
62
|
+
submitJperpOpen(data: JperpOpenRequest): Promise<JperpOpenResponse>;
|
|
63
|
+
submitJperpClose(data: JperpCloseRequest): Promise<JperpDecreaseResponse>;
|
|
64
|
+
submitJperpSetTpsl(data: JperpSetTpslRequest): Promise<JperpDecreaseResponse>;
|
|
65
|
+
submitJperpUpdateTpsl(data: JperpUpdateTpslRequest): Promise<JperpDecreaseResponse>;
|
|
66
|
+
submitJperpCancelTrigger(data: JperpCancelTriggerRequest): Promise<JperpCancelTriggerResponse>;
|
|
67
|
+
submitJperpReissue(data: JperpReissueRequest): Promise<JperpReissueResponse>;
|
|
68
|
+
submitJperpRecoverSeed(data: JperpRecoverSeedRequest): Promise<JperpRecoverSeedResponse>;
|
|
69
|
+
submitJperpRecoverNative(data: JperpRecoverNativeRequest): Promise<JperpRecoverNativeResponse>;
|
|
70
|
+
submitPredictionOpen(data: PredictionOpenRequest): Promise<PredictionOpenResponse>;
|
|
71
|
+
submitPredictionReissue(data: PredictionReissueRequest): Promise<PredictionReissueResponse>;
|
|
72
|
+
private submitEncrypted;
|
|
61
73
|
}
|
|
@@ -7,29 +7,16 @@ exports.VeiloRelayerClient = void 0;
|
|
|
7
7
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
8
8
|
const crypto_js_1 = require("./crypto.js");
|
|
9
9
|
const encoding_js_1 = require("./encoding.js");
|
|
10
|
+
const internal_config_js_1 = require("./internal-config.js");
|
|
10
11
|
const transport_js_1 = require("./transport.js");
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// Relayer Client
|
|
13
14
|
// =============================================================================
|
|
14
|
-
/**
|
|
15
|
-
* HTTP client for the Veilo relayer API.
|
|
16
|
-
*
|
|
17
|
-
* Handles auth, notes, merkle, and encrypted transact endpoints with
|
|
18
|
-
* automatic retry on transient failures and NaCl box payload encryption.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const client = new VeiloRelayerClient({
|
|
23
|
-
* apiKey: "your-api-key",
|
|
24
|
-
* relayerPublicKey: "<base64 NaCl public key>",
|
|
25
|
-
* });
|
|
26
|
-
* const root = await client.getMerkleRoot("So111...");
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
15
|
+
/** @internal Relayer transport behind the SDK's functional helpers. */
|
|
29
16
|
class VeiloRelayerClient {
|
|
30
|
-
constructor(config, retry) {
|
|
17
|
+
constructor(config = {}, retry) {
|
|
31
18
|
this.transport = new transport_js_1.RelayerHttpTransport(config, retry);
|
|
32
|
-
this.relayerPubKey = (0, encoding_js_1.fromBase64)(config.
|
|
19
|
+
this.relayerPubKey = (0, encoding_js_1.fromBase64)(config.encryptionPublicKey ?? internal_config_js_1.VEILO_RELAYER_PUBLIC_KEY);
|
|
33
20
|
}
|
|
34
21
|
/** Update the auth token (e.g. after register/restore). */
|
|
35
22
|
setAuthToken(token) {
|
|
@@ -94,6 +81,18 @@ class VeiloRelayerClient {
|
|
|
94
81
|
});
|
|
95
82
|
}
|
|
96
83
|
/** Delete all stored data for the authenticated user. Requires auth token. */
|
|
84
|
+
/**
|
|
85
|
+
* Ask which of these nullifiers the relayer has seen spent.
|
|
86
|
+
*
|
|
87
|
+
* Caller must respect MAX_NULLIFIERS_PER_CHECK; `checkNullifiersSpent` in
|
|
88
|
+
* notes/spent.ts does the chunking. Unauthenticated: a nullifier reveals
|
|
89
|
+
* nothing about ownership on its own.
|
|
90
|
+
*/
|
|
91
|
+
async checkNullifiers(nullifiers) {
|
|
92
|
+
return this.transport.request("POST", "/notes/nullifiers/check-batch", {
|
|
93
|
+
body: { nullifiers },
|
|
94
|
+
});
|
|
95
|
+
}
|
|
97
96
|
async deleteUserData() {
|
|
98
97
|
return this.transport.request("POST", "/notes/delete", { authenticated: true });
|
|
99
98
|
}
|
|
@@ -147,5 +146,61 @@ class VeiloRelayerClient {
|
|
|
147
146
|
retryable: false,
|
|
148
147
|
});
|
|
149
148
|
}
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
// Private positions (encrypted payloads)
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
async submitOpenPosition(data) {
|
|
153
|
+
return this.submitEncrypted("/positions/open", data);
|
|
154
|
+
}
|
|
155
|
+
async submitClosePosition(data) {
|
|
156
|
+
return this.submitEncrypted("/positions/close", data);
|
|
157
|
+
}
|
|
158
|
+
async submitMergePositions(data) {
|
|
159
|
+
return this.submitEncrypted("/positions/merge", data);
|
|
160
|
+
}
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// Private Jupiter Perps (encrypted payloads)
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
async submitJperpOpen(data) {
|
|
165
|
+
return this.submitEncrypted("/jperp/open", data);
|
|
166
|
+
}
|
|
167
|
+
async submitJperpClose(data) {
|
|
168
|
+
return this.submitEncrypted("/jperp/close", data);
|
|
169
|
+
}
|
|
170
|
+
async submitJperpSetTpsl(data) {
|
|
171
|
+
return this.submitEncrypted("/jperp/set-tpsl", data);
|
|
172
|
+
}
|
|
173
|
+
async submitJperpUpdateTpsl(data) {
|
|
174
|
+
return this.submitEncrypted("/jperp/update-tpsl", data);
|
|
175
|
+
}
|
|
176
|
+
async submitJperpCancelTrigger(data) {
|
|
177
|
+
return this.submitEncrypted("/jperp/cancel-trigger", data);
|
|
178
|
+
}
|
|
179
|
+
async submitJperpReissue(data) {
|
|
180
|
+
return this.submitEncrypted("/jperp/reissue", data);
|
|
181
|
+
}
|
|
182
|
+
async submitJperpRecoverSeed(data) {
|
|
183
|
+
return this.submitEncrypted("/jperp/recover-seed", data);
|
|
184
|
+
}
|
|
185
|
+
async submitJperpRecoverNative(data) {
|
|
186
|
+
return this.submitEncrypted("/jperp/recover-native", data);
|
|
187
|
+
}
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
// Private Jupiter Predictions (encrypted payloads)
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
async submitPredictionOpen(data) {
|
|
192
|
+
return this.submitEncrypted("/predictions/open", data);
|
|
193
|
+
}
|
|
194
|
+
async submitPredictionReissue(data) {
|
|
195
|
+
return this.submitEncrypted("/predictions/reissue", data);
|
|
196
|
+
}
|
|
197
|
+
submitEncrypted(route, data) {
|
|
198
|
+
const encryptedPayload = this.encryptPayload(data);
|
|
199
|
+
return this.transport.request("POST", route, {
|
|
200
|
+
body: { encryptedPayload },
|
|
201
|
+
// These endpoints can land transactions; automatic replay is unsafe.
|
|
202
|
+
retryable: false,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
150
205
|
}
|
|
151
206
|
exports.VeiloRelayerClient = VeiloRelayerClient;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// =============================================================================
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VeiloApiError = void 0;
|
|
7
|
-
/** Structured error thrown by
|
|
7
|
+
/** Structured error thrown by managed Veilo API helpers. */
|
|
8
8
|
class VeiloApiError extends Error {
|
|
9
9
|
constructor(code, message, status, details) {
|
|
10
10
|
super(message);
|
|
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types.js"), exports);
|
|
18
18
|
__exportStar(require("./errors.js"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./api.js"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Veilo network coordinates are protocol configuration, not integrator input.
|
|
3
|
+
* Keep them behind the public package entry points.
|
|
4
|
+
*/
|
|
5
|
+
export declare const VEILO_RELAYER_URL = "https://relayer-server.onrender.com";
|
|
6
|
+
export declare const VEILO_RELAYER_PUBLIC_KEY = "utVxnA7zax09qJCZ7UJsa8PAOoWLRcCwOkdxg/ZGmD4=";
|
|
7
|
+
/**
|
|
8
|
+
* Internal construction options. Overrides exist only for isolated tests.
|
|
9
|
+
*
|
|
10
|
+
* ⚠ `baseUrl` MUST NOT be promoted to the public API. Two invariants depend on
|
|
11
|
+
* it staying internal:
|
|
12
|
+
*
|
|
13
|
+
* 1. The privacy pool gates every spend on an on-chain relayer allowlist
|
|
14
|
+
* (`RelayerNotAllowed`). Only deposits are permissionless. A request sent
|
|
15
|
+
* to any other host cannot land on chain, so the option would be a
|
|
16
|
+
* footgun that fails late rather than a feature.
|
|
17
|
+
* 2. These request bodies carry note spending keys (`TransactNote.privateKey`,
|
|
18
|
+
* and `claimantSecretKey` on position close/merge). A caller-settable
|
|
19
|
+
* destination is a caller-settable exfiltration target for user funds.
|
|
20
|
+
*
|
|
21
|
+
* Only `internal.ts` may construct these options, and it builds the object
|
|
22
|
+
* literal itself — no caller-supplied object is ever forwarded here. To verify
|
|
23
|
+
* that still holds:
|
|
24
|
+
*
|
|
25
|
+
* grep -rn "createInternalRelayerClient(\|new VeiloRelayerClient(" src
|
|
26
|
+
*
|
|
27
|
+
* Whitelisted partners who run their own relayer are handled out of band, not
|
|
28
|
+
* by a config flag. See README → "Submission always targets Veilo's relayer".
|
|
29
|
+
*/
|
|
30
|
+
export interface InternalRelayerClientOptions {
|
|
31
|
+
authToken?: string;
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
encryptionPublicKey?: string;
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VEILO_RELAYER_PUBLIC_KEY = exports.VEILO_RELAYER_URL = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Veilo network coordinates are protocol configuration, not integrator input.
|
|
6
|
+
* Keep them behind the public package entry points.
|
|
7
|
+
*/
|
|
8
|
+
exports.VEILO_RELAYER_URL = "https://relayer-server.onrender.com";
|
|
9
|
+
exports.VEILO_RELAYER_PUBLIC_KEY = "utVxnA7zax09qJCZ7UJsa8PAOoWLRcCwOkdxg/ZGmD4=";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VeiloRelayerClient } from "./client.js";
|
|
2
|
+
import type { InternalRelayerClientOptions } from "./internal-config.js";
|
|
3
|
+
/** @internal Shared stateless production client for public SDK helpers. */
|
|
4
|
+
export declare function getInternalRelayerClient(): VeiloRelayerClient;
|
|
5
|
+
/** @internal Auth state is isolated per call to avoid cross-user token leaks. */
|
|
6
|
+
export declare function createInternalRelayerClient(options?: InternalRelayerClientOptions): VeiloRelayerClient;
|