@veilo/sdk-core 0.3.3 → 0.4.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 +42 -3
- package/SHIELD_INTEGRATION.md +143 -0
- package/config.d.ts +2 -0
- package/config.js +4 -0
- package/dist/cjs/client.d.ts +5 -5
- package/dist/cjs/client.js +79 -42
- package/dist/cjs/compactNote.d.ts +107 -0
- package/dist/cjs/compactNote.js +167 -0
- package/dist/cjs/events.d.ts +1 -1
- package/dist/cjs/events.js +2 -2
- package/dist/cjs/idl/privacy_pool.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool.js +15218 -0
- package/dist/cjs/index.d.ts +16 -13
- package/dist/cjs/index.js +40 -30
- package/dist/cjs/merkle.d.ts +13 -0
- package/dist/cjs/merkle.js +31 -8
- package/dist/cjs/program.d.ts +11 -0
- package/dist/cjs/program.js +26 -3
- package/dist/cjs/proof.d.ts +1 -1
- package/dist/cjs/proof.js +37 -37
- package/dist/cjs/prover.d.ts +1 -1
- package/dist/cjs/prover.js +2 -2
- package/dist/cjs/random.d.ts +16 -0
- package/dist/cjs/random.js +28 -0
- package/dist/cjs/relayer.d.ts +27 -4
- package/dist/cjs/relayer.js +16 -5
- package/dist/cjs/shield/alt.d.ts +87 -0
- package/dist/cjs/shield/alt.js +194 -0
- package/dist/cjs/shield/computeBudget.d.ts +61 -0
- package/dist/cjs/shield/computeBudget.js +64 -0
- package/dist/cjs/shield/errors.d.ts +58 -0
- package/dist/cjs/shield/errors.js +121 -0
- package/dist/cjs/shield/finalize.d.ts +45 -0
- package/dist/cjs/shield/finalize.js +119 -0
- package/dist/cjs/shield/index.d.ts +35 -0
- package/dist/cjs/shield/index.js +68 -0
- package/dist/cjs/shield/ix.d.ts +54 -0
- package/dist/cjs/shield/ix.js +119 -0
- package/dist/cjs/shield/owner.d.ts +36 -0
- package/dist/cjs/shield/owner.js +126 -0
- package/dist/cjs/shield/ports.d.ts +43 -0
- package/dist/cjs/shield/ports.js +153 -0
- package/dist/cjs/shield/preflight.d.ts +30 -0
- package/dist/cjs/shield/preflight.js +154 -0
- package/dist/cjs/shield/shield.d.ts +68 -0
- package/dist/cjs/shield/shield.js +499 -0
- package/dist/cjs/shield/types.d.ts +202 -0
- package/dist/cjs/shield/types.js +2 -0
- package/dist/cjs/utxo.d.ts +20 -0
- package/dist/cjs/utxo.js +41 -28
- package/dist/esm/client.d.ts +407 -0
- package/dist/esm/client.js +9 -5
- package/dist/esm/compactNote.d.ts +107 -0
- package/dist/esm/compactNote.js +156 -0
- package/dist/esm/config.d.ts +82 -0
- package/dist/esm/events.d.ts +77 -0
- package/dist/esm/events.js +1 -1
- package/dist/esm/idl/privacy_pool.d.ts +5 -0
- package/dist/esm/idl/privacy_pool.js +15216 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +18 -11
- package/dist/esm/merkle.d.ts +77 -0
- package/dist/esm/merkle.js +23 -1
- package/dist/esm/package.json +1 -0
- package/dist/esm/poseidon.d.ts +29 -0
- package/dist/esm/program.d.ts +37 -0
- package/dist/esm/program.js +23 -1
- package/dist/esm/proof.d.ts +183 -0
- package/dist/esm/proof.js +2 -2
- package/dist/esm/prover.d.ts +54 -0
- package/dist/esm/prover.js +1 -1
- package/dist/esm/random.d.ts +16 -0
- package/dist/esm/random.js +21 -0
- package/dist/esm/relayer.d.ts +318 -0
- package/dist/esm/relayer.js +16 -5
- package/dist/esm/retry.d.ts +32 -0
- package/dist/esm/shield/alt.d.ts +87 -0
- package/dist/esm/shield/alt.js +186 -0
- package/dist/esm/shield/computeBudget.d.ts +61 -0
- package/dist/esm/shield/computeBudget.js +61 -0
- package/dist/esm/shield/errors.d.ts +58 -0
- package/dist/esm/shield/errors.js +115 -0
- package/dist/esm/shield/finalize.d.ts +45 -0
- package/dist/esm/shield/finalize.js +83 -0
- package/dist/esm/shield/index.d.ts +35 -0
- package/dist/esm/shield/index.js +32 -0
- package/dist/esm/shield/ix.d.ts +54 -0
- package/dist/esm/shield/ix.js +82 -0
- package/dist/esm/shield/owner.d.ts +36 -0
- package/dist/esm/shield/owner.js +122 -0
- package/dist/esm/shield/ports.d.ts +43 -0
- package/dist/esm/shield/ports.js +147 -0
- package/dist/esm/shield/preflight.d.ts +30 -0
- package/dist/esm/shield/preflight.js +151 -0
- package/dist/esm/shield/shield.d.ts +68 -0
- package/dist/esm/shield/shield.js +492 -0
- package/dist/esm/shield/types.d.ts +202 -0
- package/dist/esm/shield/types.js +1 -0
- package/dist/esm/utxo.d.ts +235 -0
- package/dist/esm/utxo.js +18 -8
- package/dist/src/client.d.ts +407 -0
- package/dist/src/client.js +951 -0
- package/dist/src/compactNote.d.ts +107 -0
- package/dist/src/compactNote.js +167 -0
- package/dist/src/config.d.ts +82 -0
- package/dist/src/config.js +57 -0
- package/dist/src/events.d.ts +77 -0
- package/dist/src/events.js +167 -0
- package/dist/src/idl/privacy_pool.d.ts +5 -0
- package/dist/src/idl/privacy_pool.js +15218 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +67 -0
- package/dist/src/merkle.d.ts +77 -0
- package/dist/src/merkle.js +156 -0
- package/dist/src/poseidon.d.ts +29 -0
- package/dist/src/poseidon.js +100 -0
- package/dist/src/program.d.ts +37 -0
- package/dist/src/program.js +61 -0
- package/dist/src/proof.d.ts +183 -0
- package/dist/src/proof.js +292 -0
- package/dist/src/prover.d.ts +54 -0
- package/dist/src/prover.js +112 -0
- package/dist/src/random.d.ts +16 -0
- package/dist/src/random.js +28 -0
- package/dist/src/relayer.d.ts +318 -0
- package/dist/src/relayer.js +257 -0
- package/dist/src/retry.d.ts +32 -0
- package/dist/src/retry.js +75 -0
- package/dist/src/shield/alt.d.ts +87 -0
- package/dist/src/shield/alt.js +194 -0
- package/dist/src/shield/computeBudget.d.ts +61 -0
- package/dist/src/shield/computeBudget.js +64 -0
- package/dist/src/shield/errors.d.ts +58 -0
- package/dist/src/shield/errors.js +121 -0
- package/dist/src/shield/finalize.d.ts +45 -0
- package/dist/src/shield/finalize.js +119 -0
- package/dist/src/shield/index.d.ts +35 -0
- package/dist/src/shield/index.js +68 -0
- package/dist/src/shield/ix.d.ts +54 -0
- package/dist/src/shield/ix.js +119 -0
- package/dist/src/shield/owner.d.ts +36 -0
- package/dist/src/shield/owner.js +126 -0
- package/dist/src/shield/ports.d.ts +43 -0
- package/dist/src/shield/ports.js +153 -0
- package/dist/src/shield/preflight.d.ts +30 -0
- package/dist/src/shield/preflight.js +154 -0
- package/dist/src/shield/shield.d.ts +68 -0
- package/dist/src/shield/shield.js +499 -0
- package/dist/src/shield/types.d.ts +202 -0
- package/dist/src/shield/types.js +2 -0
- package/dist/src/utxo.d.ts +235 -0
- package/dist/src/utxo.js +407 -0
- package/dist/tests/compact-note.test.d.ts +1 -0
- package/dist/tests/compact-note.test.js +173 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/dist/tests/config.test.js +102 -0
- package/dist/tests/edge-cases.test.d.ts +1 -0
- package/dist/tests/edge-cases.test.js +220 -0
- package/dist/tests/encryption.test.d.ts +1 -0
- package/dist/tests/encryption.test.js +215 -0
- package/dist/tests/events.test.d.ts +1 -0
- package/dist/tests/events.test.js +78 -0
- package/dist/tests/multi-tree.test.d.ts +1 -0
- package/dist/tests/multi-tree.test.js +405 -0
- package/dist/tests/pda.test.d.ts +1 -0
- package/dist/tests/pda.test.js +229 -0
- package/dist/tests/poseidon-builder-parity.test.d.ts +1 -0
- package/dist/tests/poseidon-builder-parity.test.js +72 -0
- package/dist/tests/poseidon.test.d.ts +1 -0
- package/dist/tests/poseidon.test.js +142 -0
- package/dist/tests/proof.test.d.ts +1 -0
- package/dist/tests/proof.test.js +296 -0
- package/dist/tests/relayer.test.d.ts +1 -0
- package/dist/tests/relayer.test.js +271 -0
- package/dist/tests/sdk.integration.test.d.ts +1 -0
- package/dist/tests/sdk.integration.test.js +330 -0
- package/dist/tests/shield-owner.test.d.ts +1 -0
- package/dist/tests/shield-owner.test.js +89 -0
- package/dist/tests/shield-preflight.test.d.ts +1 -0
- package/dist/tests/shield-preflight.test.js +87 -0
- package/dist/tests/shield-realproof.test.d.ts +1 -0
- package/dist/tests/shield-realproof.test.js +272 -0
- package/dist/tests/shield.test.d.ts +1 -0
- package/dist/tests/shield.test.js +403 -0
- package/dist/tests/utxo.test.d.ts +1 -0
- package/dist/tests/utxo.test.js +140 -0
- package/package.json +69 -11
- package/poseidon.d.ts +2 -0
- package/poseidon.js +4 -0
- package/proof.d.ts +2 -0
- package/proof.js +4 -0
- package/prover.d.ts +2 -0
- package/prover.js +4 -0
- package/shield.d.ts +2 -0
- package/shield.js +4 -0
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
export * from "./client";
|
|
2
|
-
export * from "./utxo";
|
|
3
|
-
export * from "./config";
|
|
4
|
-
export * from "./merkle";
|
|
5
|
-
export * from "./proof";
|
|
6
|
-
export * from "./events";
|
|
7
|
-
export { createVeiloProgram, PRIVACY_POOL_IDL, PRIVACY_POOL_PROGRAM_ID, } from "./program";
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./utxo.js";
|
|
3
|
+
export * from "./config.js";
|
|
4
|
+
export * from "./merkle.js";
|
|
5
|
+
export * from "./proof.js";
|
|
6
|
+
export * from "./events.js";
|
|
7
|
+
export { createVeiloProgram, createReadonlyVeiloProgram, PRIVACY_POOL_IDL, PRIVACY_POOL_PROGRAM_ID, } from "./program.js";
|
|
8
|
+
export * from "./shield/index.js";
|
|
9
|
+
export { createTransactionProver, verifyProof } from "./prover.js";
|
|
10
|
+
export type { CircuitArtifacts } from "./prover.js";
|
|
11
|
+
export * from "./compactNote.js";
|
|
12
|
+
export { randomBytes, randomBytes32 } from "./random.js";
|
|
13
|
+
export * from "./relayer.js";
|
|
14
|
+
export { withRpcRetry, DEFAULT_RPC_RETRY } from "./retry.js";
|
|
15
|
+
export type { RpcRetryPolicy } from "./retry.js";
|
|
16
|
+
export { initPoseidon, getPoseidon, BN254_FR_MODULUS, bytesToBigIntBE, bigIntToBytesBE, frToBigInt, poseidon1, poseidon2, poseidon3, poseidon4, pubkeyToField, } from "./poseidon.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,44 +14,54 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.pubkeyToField = exports.poseidon4 = exports.poseidon3 = exports.poseidon2 = exports.poseidon1 = exports.frToBigInt = exports.bigIntToBytesBE = exports.bytesToBigIntBE = exports.BN254_FR_MODULUS = exports.getPoseidon = exports.initPoseidon = exports.DEFAULT_RPC_RETRY = exports.withRpcRetry = exports.verifyProof = exports.createTransactionProver = exports.PRIVACY_POOL_PROGRAM_ID = exports.PRIVACY_POOL_IDL = exports.createVeiloProgram = void 0;
|
|
17
|
+
exports.pubkeyToField = exports.poseidon4 = exports.poseidon3 = exports.poseidon2 = exports.poseidon1 = exports.frToBigInt = exports.bigIntToBytesBE = exports.bytesToBigIntBE = exports.BN254_FR_MODULUS = exports.getPoseidon = exports.initPoseidon = exports.DEFAULT_RPC_RETRY = exports.withRpcRetry = exports.randomBytes32 = exports.randomBytes = exports.verifyProof = exports.createTransactionProver = exports.PRIVACY_POOL_PROGRAM_ID = exports.PRIVACY_POOL_IDL = exports.createReadonlyVeiloProgram = exports.createVeiloProgram = void 0;
|
|
18
18
|
// Core client functions
|
|
19
|
-
__exportStar(require("./client"), exports);
|
|
19
|
+
__exportStar(require("./client.js"), exports);
|
|
20
20
|
// UTXO types and functions (replaces note.ts)
|
|
21
|
-
__exportStar(require("./utxo"), exports);
|
|
21
|
+
__exportStar(require("./utxo.js"), exports);
|
|
22
22
|
// Configuration constants and types
|
|
23
|
-
__exportStar(require("./config"), exports);
|
|
23
|
+
__exportStar(require("./config.js"), exports);
|
|
24
24
|
// Merkle tree implementation
|
|
25
|
-
__exportStar(require("./merkle"), exports);
|
|
25
|
+
__exportStar(require("./merkle.js"), exports);
|
|
26
26
|
// Proof types and helpers
|
|
27
|
-
__exportStar(require("./proof"), exports);
|
|
27
|
+
__exportStar(require("./proof.js"), exports);
|
|
28
28
|
// On-chain event scanning and tree reconstruction
|
|
29
|
-
__exportStar(require("./events"), exports);
|
|
29
|
+
__exportStar(require("./events.js"), exports);
|
|
30
30
|
// Program factory and IDL
|
|
31
|
-
var
|
|
32
|
-
Object.defineProperty(exports, "createVeiloProgram", { enumerable: true, get: function () { return
|
|
33
|
-
Object.defineProperty(exports, "
|
|
34
|
-
Object.defineProperty(exports, "
|
|
31
|
+
var program_js_1 = require("./program.js");
|
|
32
|
+
Object.defineProperty(exports, "createVeiloProgram", { enumerable: true, get: function () { return program_js_1.createVeiloProgram; } });
|
|
33
|
+
Object.defineProperty(exports, "createReadonlyVeiloProgram", { enumerable: true, get: function () { return program_js_1.createReadonlyVeiloProgram; } });
|
|
34
|
+
Object.defineProperty(exports, "PRIVACY_POOL_IDL", { enumerable: true, get: function () { return program_js_1.PRIVACY_POOL_IDL; } });
|
|
35
|
+
Object.defineProperty(exports, "PRIVACY_POOL_PROGRAM_ID", { enumerable: true, get: function () { return program_js_1.PRIVACY_POOL_PROGRAM_ID; } });
|
|
36
|
+
// Wallet-agnostic shielding — build an unsigned deposit for any external wallet
|
|
37
|
+
__exportStar(require("./shield/index.js"), exports);
|
|
35
38
|
// Proof generation (requires snarkjs peer dependency)
|
|
36
|
-
var
|
|
37
|
-
Object.defineProperty(exports, "createTransactionProver", { enumerable: true, get: function () { return
|
|
38
|
-
Object.defineProperty(exports, "verifyProof", { enumerable: true, get: function () { return
|
|
39
|
+
var prover_js_1 = require("./prover.js");
|
|
40
|
+
Object.defineProperty(exports, "createTransactionProver", { enumerable: true, get: function () { return prover_js_1.createTransactionProver; } });
|
|
41
|
+
Object.defineProperty(exports, "verifyProof", { enumerable: true, get: function () { return prover_js_1.verifyProof; } });
|
|
42
|
+
// Compact note ciphers — the on-chain payload that makes notes recoverable
|
|
43
|
+
// from chain data alone, without any relayer involvement.
|
|
44
|
+
__exportStar(require("./compactNote.js"), exports);
|
|
45
|
+
// Cross-platform CSPRNG (no node:crypto import — safe in browser bundles)
|
|
46
|
+
var random_js_1 = require("./random.js");
|
|
47
|
+
Object.defineProperty(exports, "randomBytes", { enumerable: true, get: function () { return random_js_1.randomBytes; } });
|
|
48
|
+
Object.defineProperty(exports, "randomBytes32", { enumerable: true, get: function () { return random_js_1.randomBytes32; } });
|
|
39
49
|
// Relayer API client
|
|
40
|
-
__exportStar(require("./relayer"), exports);
|
|
50
|
+
__exportStar(require("./relayer.js"), exports);
|
|
41
51
|
// RPC retry / resilience
|
|
42
|
-
var
|
|
43
|
-
Object.defineProperty(exports, "withRpcRetry", { enumerable: true, get: function () { return
|
|
44
|
-
Object.defineProperty(exports, "DEFAULT_RPC_RETRY", { enumerable: true, get: function () { return
|
|
52
|
+
var retry_js_1 = require("./retry.js");
|
|
53
|
+
Object.defineProperty(exports, "withRpcRetry", { enumerable: true, get: function () { return retry_js_1.withRpcRetry; } });
|
|
54
|
+
Object.defineProperty(exports, "DEFAULT_RPC_RETRY", { enumerable: true, get: function () { return retry_js_1.DEFAULT_RPC_RETRY; } });
|
|
45
55
|
// Poseidon hash functions
|
|
46
|
-
var
|
|
47
|
-
Object.defineProperty(exports, "initPoseidon", { enumerable: true, get: function () { return
|
|
48
|
-
Object.defineProperty(exports, "getPoseidon", { enumerable: true, get: function () { return
|
|
49
|
-
Object.defineProperty(exports, "BN254_FR_MODULUS", { enumerable: true, get: function () { return
|
|
50
|
-
Object.defineProperty(exports, "bytesToBigIntBE", { enumerable: true, get: function () { return
|
|
51
|
-
Object.defineProperty(exports, "bigIntToBytesBE", { enumerable: true, get: function () { return
|
|
52
|
-
Object.defineProperty(exports, "frToBigInt", { enumerable: true, get: function () { return
|
|
53
|
-
Object.defineProperty(exports, "poseidon1", { enumerable: true, get: function () { return
|
|
54
|
-
Object.defineProperty(exports, "poseidon2", { enumerable: true, get: function () { return
|
|
55
|
-
Object.defineProperty(exports, "poseidon3", { enumerable: true, get: function () { return
|
|
56
|
-
Object.defineProperty(exports, "poseidon4", { enumerable: true, get: function () { return
|
|
57
|
-
Object.defineProperty(exports, "pubkeyToField", { enumerable: true, get: function () { return
|
|
56
|
+
var poseidon_js_1 = require("./poseidon.js");
|
|
57
|
+
Object.defineProperty(exports, "initPoseidon", { enumerable: true, get: function () { return poseidon_js_1.initPoseidon; } });
|
|
58
|
+
Object.defineProperty(exports, "getPoseidon", { enumerable: true, get: function () { return poseidon_js_1.getPoseidon; } });
|
|
59
|
+
Object.defineProperty(exports, "BN254_FR_MODULUS", { enumerable: true, get: function () { return poseidon_js_1.BN254_FR_MODULUS; } });
|
|
60
|
+
Object.defineProperty(exports, "bytesToBigIntBE", { enumerable: true, get: function () { return poseidon_js_1.bytesToBigIntBE; } });
|
|
61
|
+
Object.defineProperty(exports, "bigIntToBytesBE", { enumerable: true, get: function () { return poseidon_js_1.bigIntToBytesBE; } });
|
|
62
|
+
Object.defineProperty(exports, "frToBigInt", { enumerable: true, get: function () { return poseidon_js_1.frToBigInt; } });
|
|
63
|
+
Object.defineProperty(exports, "poseidon1", { enumerable: true, get: function () { return poseidon_js_1.poseidon1; } });
|
|
64
|
+
Object.defineProperty(exports, "poseidon2", { enumerable: true, get: function () { return poseidon_js_1.poseidon2; } });
|
|
65
|
+
Object.defineProperty(exports, "poseidon3", { enumerable: true, get: function () { return poseidon_js_1.poseidon3; } });
|
|
66
|
+
Object.defineProperty(exports, "poseidon4", { enumerable: true, get: function () { return poseidon_js_1.poseidon4; } });
|
|
67
|
+
Object.defineProperty(exports, "pubkeyToField", { enumerable: true, get: function () { return poseidon_js_1.pubkeyToField; } });
|
package/dist/cjs/merkle.d.ts
CHANGED
|
@@ -62,3 +62,16 @@ export declare class MerkleTree {
|
|
|
62
62
|
*/
|
|
63
63
|
getCircuitPath(index: number): CircuitMerklePath;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The Poseidon zero chain: `z[0] = 0`, `z[i+1] = Poseidon(z[i], z[i])`.
|
|
67
|
+
*
|
|
68
|
+
* This is the `zeroes` array a `MerkleTree` builds in its constructor, without
|
|
69
|
+
* the tree. Deposits need a Merkle path for their dummy inputs, but the circuit
|
|
70
|
+
* disables the path check when a input amount is zero (`enabled <== 1 - IsZero(amount)`
|
|
71
|
+
* in transaction.circom), so the values are never constrained — only their
|
|
72
|
+
* count is.
|
|
73
|
+
*
|
|
74
|
+
* Allocating a full depth-22 `MerkleTree` for this costs ~130 MB and several
|
|
75
|
+
* seconds. This costs 22 hashes. Any deposit-shaped transaction should use it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function poseidonZeroChain(depth?: number): Uint8Array[];
|
package/dist/cjs/merkle.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MerkleTree = void 0;
|
|
4
|
-
|
|
4
|
+
exports.poseidonZeroChain = poseidonZeroChain;
|
|
5
|
+
const poseidon_js_1 = require("./poseidon.js");
|
|
5
6
|
// Poseidon-based hash of two 32-byte field elements.
|
|
6
7
|
function hashPair(left, right) {
|
|
7
8
|
if (left.length !== 32 || right.length !== 32) {
|
|
8
9
|
throw new Error("hashPair expects 32-byte inputs");
|
|
9
10
|
}
|
|
10
|
-
const poseidon = (0,
|
|
11
|
-
const lf = (0,
|
|
12
|
-
const rf = (0,
|
|
11
|
+
const poseidon = (0, poseidon_js_1.getPoseidon)();
|
|
12
|
+
const lf = (0, poseidon_js_1.bytesToBigIntBE)(left) % poseidon_js_1.BN254_FR_MODULUS;
|
|
13
|
+
const rf = (0, poseidon_js_1.bytesToBigIntBE)(right) % poseidon_js_1.BN254_FR_MODULUS;
|
|
13
14
|
const fe = poseidon([lf, rf]);
|
|
14
|
-
const outBig = (0,
|
|
15
|
-
return (0,
|
|
15
|
+
const outBig = (0, poseidon_js_1.frToBigInt)(fe) % poseidon_js_1.BN254_FR_MODULUS;
|
|
16
|
+
return (0, poseidon_js_1.bigIntToBytesBE)(outBig);
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Fixed-depth binary Merkle tree over BN254 Fr:
|
|
@@ -32,7 +33,7 @@ class MerkleTree {
|
|
|
32
33
|
this.zeroes = [];
|
|
33
34
|
this.layers = [];
|
|
34
35
|
// zero[0] = 0 (Fr), then zero[i+1] = Poseidon(zero[i], zero[i])
|
|
35
|
-
let zero = (0,
|
|
36
|
+
let zero = (0, poseidon_js_1.bigIntToBytesBE)(0n);
|
|
36
37
|
this.zeroes.push(zero);
|
|
37
38
|
for (let level = 1; level <= depth; level++) {
|
|
38
39
|
zero = hashPair(zero, zero);
|
|
@@ -126,8 +127,30 @@ class MerkleTree {
|
|
|
126
127
|
const merklePath = this.getPath(index);
|
|
127
128
|
return {
|
|
128
129
|
pathIndex: index,
|
|
129
|
-
pathElements: merklePath.path.map((p) => (0,
|
|
130
|
+
pathElements: merklePath.path.map((p) => (0, poseidon_js_1.bytesToBigIntBE)(p) % poseidon_js_1.BN254_FR_MODULUS),
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
exports.MerkleTree = MerkleTree;
|
|
135
|
+
/**
|
|
136
|
+
* The Poseidon zero chain: `z[0] = 0`, `z[i+1] = Poseidon(z[i], z[i])`.
|
|
137
|
+
*
|
|
138
|
+
* This is the `zeroes` array a `MerkleTree` builds in its constructor, without
|
|
139
|
+
* the tree. Deposits need a Merkle path for their dummy inputs, but the circuit
|
|
140
|
+
* disables the path check when a input amount is zero (`enabled <== 1 - IsZero(amount)`
|
|
141
|
+
* in transaction.circom), so the values are never constrained — only their
|
|
142
|
+
* count is.
|
|
143
|
+
*
|
|
144
|
+
* Allocating a full depth-22 `MerkleTree` for this costs ~130 MB and several
|
|
145
|
+
* seconds. This costs 22 hashes. Any deposit-shaped transaction should use it.
|
|
146
|
+
*/
|
|
147
|
+
function poseidonZeroChain(depth = 22) {
|
|
148
|
+
const zeroes = [];
|
|
149
|
+
let zero = (0, poseidon_js_1.bigIntToBytesBE)(0n);
|
|
150
|
+
zeroes.push(zero);
|
|
151
|
+
for (let level = 1; level <= depth; level++) {
|
|
152
|
+
zero = hashPair(zero, zero);
|
|
153
|
+
zeroes.push(zero);
|
|
154
|
+
}
|
|
155
|
+
return zeroes;
|
|
156
|
+
}
|
package/dist/cjs/program.d.ts
CHANGED
|
@@ -24,3 +24,14 @@ export declare const PRIVACY_POOL_PROGRAM_ID: PublicKey;
|
|
|
24
24
|
export declare function createVeiloProgram(connection: Connection, wallet: Wallet, opts?: {
|
|
25
25
|
commitment?: "processed" | "confirmed" | "finalized";
|
|
26
26
|
}): Program;
|
|
27
|
+
/**
|
|
28
|
+
* Create a `Program` for reading on-chain accounts, with no wallet.
|
|
29
|
+
*
|
|
30
|
+
* The shield path never signs, so requiring a `Wallet` just to decode a
|
|
31
|
+
* `MerkleTreeAccount` would force integrators to invent a dummy one. This is
|
|
32
|
+
* safe for `program.account.*.fetch` and the coders; anything that would submit
|
|
33
|
+
* a transaction will fail, which is the intent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createReadonlyVeiloProgram(connection: Connection, opts?: {
|
|
36
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
37
|
+
}): Program;
|
package/dist/cjs/program.js
CHANGED
|
@@ -5,13 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PRIVACY_POOL_PROGRAM_ID = exports.PRIVACY_POOL_IDL = void 0;
|
|
7
7
|
exports.createVeiloProgram = createVeiloProgram;
|
|
8
|
+
exports.createReadonlyVeiloProgram = createReadonlyVeiloProgram;
|
|
8
9
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
10
|
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
-
const
|
|
11
|
+
const privacy_pool_js_1 = __importDefault(require("./idl/privacy_pool.js"));
|
|
11
12
|
// Re-export so consumers can access the raw IDL if needed
|
|
12
|
-
exports.PRIVACY_POOL_IDL =
|
|
13
|
+
exports.PRIVACY_POOL_IDL = privacy_pool_js_1.default;
|
|
13
14
|
/** Deployed program ID extracted from the bundled IDL. */
|
|
14
|
-
exports.PRIVACY_POOL_PROGRAM_ID = new web3_js_1.PublicKey(
|
|
15
|
+
exports.PRIVACY_POOL_PROGRAM_ID = new web3_js_1.PublicKey(privacy_pool_js_1.default.address);
|
|
15
16
|
/**
|
|
16
17
|
* Create an Anchor `Program` instance for the Veilo Privacy Pool.
|
|
17
18
|
*
|
|
@@ -36,3 +37,25 @@ function createVeiloProgram(connection, wallet, opts) {
|
|
|
36
37
|
});
|
|
37
38
|
return new anchor_1.Program(exports.PRIVACY_POOL_IDL, provider);
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a `Program` for reading on-chain accounts, with no wallet.
|
|
42
|
+
*
|
|
43
|
+
* The shield path never signs, so requiring a `Wallet` just to decode a
|
|
44
|
+
* `MerkleTreeAccount` would force integrators to invent a dummy one. This is
|
|
45
|
+
* safe for `program.account.*.fetch` and the coders; anything that would submit
|
|
46
|
+
* a transaction will fail, which is the intent.
|
|
47
|
+
*/
|
|
48
|
+
function createReadonlyVeiloProgram(connection, opts) {
|
|
49
|
+
const provider = new anchor_1.AnchorProvider(connection,
|
|
50
|
+
// No signing surface: reads only.
|
|
51
|
+
{
|
|
52
|
+
publicKey: web3_js_1.PublicKey.default,
|
|
53
|
+
signTransaction: () => {
|
|
54
|
+
throw new Error("createReadonlyVeiloProgram: this program cannot sign");
|
|
55
|
+
},
|
|
56
|
+
signAllTransactions: () => {
|
|
57
|
+
throw new Error("createReadonlyVeiloProgram: this program cannot sign");
|
|
58
|
+
},
|
|
59
|
+
}, { commitment: opts?.commitment ?? "confirmed" });
|
|
60
|
+
return new anchor_1.Program(exports.PRIVACY_POOL_IDL, provider);
|
|
61
|
+
}
|
package/dist/cjs/proof.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { SerializedUTXO, InputUTXO } from "./utxo";
|
|
2
|
+
import { SerializedUTXO, InputUTXO } from "./utxo.js";
|
|
3
3
|
/**
|
|
4
4
|
* External data that gets hashed into ext_data_hash.
|
|
5
5
|
* These are public parameters that affect financial flows.
|
package/dist/cjs/proof.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.formatSwapInputsForSnarkjs = formatSwapInputsForSnarkjs;
|
|
|
10
10
|
exports.computeSwapParamsHash = computeSwapParamsHash;
|
|
11
11
|
exports.computeSwapDataHash = computeSwapDataHash;
|
|
12
12
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const poseidon_js_1 = require("./poseidon.js");
|
|
14
|
+
const utxo_js_1 = require("./utxo.js");
|
|
15
15
|
// -----------------------------------------------------------------------------
|
|
16
16
|
// ExtData Hash Computation
|
|
17
17
|
// -----------------------------------------------------------------------------
|
|
@@ -23,15 +23,15 @@ const utxo_1 = require("./utxo");
|
|
|
23
23
|
* extDataHash = Poseidon(hash1, hash2, claimant)
|
|
24
24
|
*/
|
|
25
25
|
function computeExtDataHash(extData) {
|
|
26
|
-
const recipientField = (0,
|
|
27
|
-
const relayerField = (0,
|
|
28
|
-
const feeField = extData.fee %
|
|
29
|
-
const refundField = extData.refund %
|
|
30
|
-
const claimantField = (0,
|
|
31
|
-
const hash1 = (0,
|
|
32
|
-
const hash2 = (0,
|
|
33
|
-
const finalHash = (0,
|
|
34
|
-
return (0,
|
|
26
|
+
const recipientField = (0, poseidon_js_1.pubkeyToField)(extData.recipient);
|
|
27
|
+
const relayerField = (0, poseidon_js_1.pubkeyToField)(extData.relayer);
|
|
28
|
+
const feeField = extData.fee % poseidon_js_1.BN254_FR_MODULUS;
|
|
29
|
+
const refundField = extData.refund % poseidon_js_1.BN254_FR_MODULUS;
|
|
30
|
+
const claimantField = (0, poseidon_js_1.pubkeyToField)(extData.claimant);
|
|
31
|
+
const hash1 = (0, poseidon_js_1.poseidon2)(recipientField, relayerField);
|
|
32
|
+
const hash2 = (0, poseidon_js_1.poseidon2)(feeField, refundField);
|
|
33
|
+
const finalHash = (0, poseidon_js_1.poseidon3)(hash1, hash2, claimantField);
|
|
34
|
+
return (0, poseidon_js_1.bigIntToBytesBE)(finalHash);
|
|
35
35
|
}
|
|
36
36
|
// -----------------------------------------------------------------------------
|
|
37
37
|
// Circuit Input Preparation
|
|
@@ -42,9 +42,9 @@ function computeExtDataHash(extData) {
|
|
|
42
42
|
*/
|
|
43
43
|
function i64ToField(value) {
|
|
44
44
|
if (value >= 0n) {
|
|
45
|
-
return value %
|
|
45
|
+
return value % poseidon_js_1.BN254_FR_MODULUS;
|
|
46
46
|
}
|
|
47
|
-
return (
|
|
47
|
+
return (poseidon_js_1.BN254_FR_MODULUS + value) % poseidon_js_1.BN254_FR_MODULUS;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Prepare transaction circuit inputs from high-level parameters.
|
|
@@ -53,7 +53,7 @@ function i64ToField(value) {
|
|
|
53
53
|
function prepareTransactionInputs(params) {
|
|
54
54
|
const { inputUTXOs, outputUTXOs, root, publicAmount, extData, mintAddress } = params;
|
|
55
55
|
const extDataHash = computeExtDataHash(extData);
|
|
56
|
-
const mintField = (0,
|
|
56
|
+
const mintField = (0, poseidon_js_1.pubkeyToField)(mintAddress);
|
|
57
57
|
// Prepare input UTXO data
|
|
58
58
|
const inAmount = [
|
|
59
59
|
inputUTXOs[0].amount,
|
|
@@ -72,8 +72,8 @@ function prepareTransactionInputs(params) {
|
|
|
72
72
|
inputUTXOs[1].pathIndex,
|
|
73
73
|
];
|
|
74
74
|
const inPathElements = [
|
|
75
|
-
inputUTXOs[0].pathElements.map((e) => (0,
|
|
76
|
-
inputUTXOs[1].pathElements.map((e) => (0,
|
|
75
|
+
inputUTXOs[0].pathElements.map((e) => (0, poseidon_js_1.bytesToBigIntBE)(e) % poseidon_js_1.BN254_FR_MODULUS),
|
|
76
|
+
inputUTXOs[1].pathElements.map((e) => (0, poseidon_js_1.bytesToBigIntBE)(e) % poseidon_js_1.BN254_FR_MODULUS),
|
|
77
77
|
];
|
|
78
78
|
const inPrivateKey = [
|
|
79
79
|
inputUTXOs[0].privateKey,
|
|
@@ -94,8 +94,8 @@ function prepareTransactionInputs(params) {
|
|
|
94
94
|
];
|
|
95
95
|
// Derive nullifiers for input UTXOs
|
|
96
96
|
const inputNullifiers = [
|
|
97
|
-
(0,
|
|
98
|
-
(0,
|
|
97
|
+
(0, utxo_js_1.deriveNullifier)(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
|
|
98
|
+
(0, utxo_js_1.deriveNullifier)(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
|
|
99
99
|
];
|
|
100
100
|
return {
|
|
101
101
|
root,
|
|
@@ -193,12 +193,12 @@ function encodeSnarkjsProofToTransactionProof(proof) {
|
|
|
193
193
|
function formatInputsForSnarkjs(inputs) {
|
|
194
194
|
return {
|
|
195
195
|
// Public inputs
|
|
196
|
-
root: (0,
|
|
196
|
+
root: (0, poseidon_js_1.bytesToBigIntBE)(inputs.root).toString(),
|
|
197
197
|
publicAmount: i64ToField(inputs.publicAmount).toString(),
|
|
198
|
-
extDataHash: (0,
|
|
199
|
-
mintAddress: (0,
|
|
200
|
-
inputNullifier: inputs.inputNullifiers.map((n) => (0,
|
|
201
|
-
outputCommitment: inputs.outputCommitments.map((c) => (0,
|
|
198
|
+
extDataHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
|
|
199
|
+
mintAddress: (0, poseidon_js_1.pubkeyToField)(inputs.mintAddress).toString(),
|
|
200
|
+
inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_js_1.bytesToBigIntBE)(n).toString()),
|
|
201
|
+
outputCommitment: inputs.outputCommitments.map((c) => (0, poseidon_js_1.bytesToBigIntBE)(c).toString()),
|
|
202
202
|
// Private inputs - Input UTXOs
|
|
203
203
|
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
204
204
|
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
@@ -225,14 +225,14 @@ function formatInputsForSnarkjs(inputs) {
|
|
|
225
225
|
function formatSwapInputsForSnarkjs(inputs) {
|
|
226
226
|
return {
|
|
227
227
|
// Public inputs
|
|
228
|
-
sourceRoot: (0,
|
|
229
|
-
swapParamsHash: (0,
|
|
230
|
-
extDataHash: (0,
|
|
231
|
-
sourceMint: (0,
|
|
232
|
-
destMint: (0,
|
|
233
|
-
inputNullifier: inputs.inputNullifiers.map((n) => (0,
|
|
234
|
-
changeCommitment: (0,
|
|
235
|
-
destCommitment: (0,
|
|
228
|
+
sourceRoot: (0, poseidon_js_1.bytesToBigIntBE)(inputs.sourceRoot).toString(),
|
|
229
|
+
swapParamsHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.swapParamsHash).toString(),
|
|
230
|
+
extDataHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
|
|
231
|
+
sourceMint: (0, poseidon_js_1.pubkeyToField)(inputs.sourceMint).toString(),
|
|
232
|
+
destMint: (0, poseidon_js_1.pubkeyToField)(inputs.destMint).toString(),
|
|
233
|
+
inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_js_1.bytesToBigIntBE)(n).toString()),
|
|
234
|
+
changeCommitment: (0, poseidon_js_1.bytesToBigIntBE)(inputs.changeCommitment).toString(),
|
|
235
|
+
destCommitment: (0, poseidon_js_1.bytesToBigIntBE)(inputs.destCommitment).toString(),
|
|
236
236
|
swapAmount: inputs.swapAmount.toString(),
|
|
237
237
|
// Private inputs - Input UTXOs
|
|
238
238
|
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
@@ -274,13 +274,13 @@ function formatSwapInputsForSnarkjs(inputs) {
|
|
|
274
274
|
* relayerFee). If omitted, defaults to minAmountOut.
|
|
275
275
|
*/
|
|
276
276
|
function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
|
|
277
|
-
const srcField = (0,
|
|
278
|
-
const dstField = (0,
|
|
279
|
-
const mintPairHash = (0,
|
|
277
|
+
const srcField = (0, poseidon_js_1.pubkeyToField)(sourceMint);
|
|
278
|
+
const dstField = (0, poseidon_js_1.pubkeyToField)(destMint);
|
|
279
|
+
const mintPairHash = (0, poseidon_js_1.poseidon2)(srcField, dstField);
|
|
280
280
|
const dest = destAmount ?? minAmountOut;
|
|
281
|
-
const swapTermsHash = (0,
|
|
282
|
-
const paramsHash = (0,
|
|
283
|
-
return (0,
|
|
281
|
+
const swapTermsHash = (0, poseidon_js_1.poseidon3)(minAmountOut, deadline, dest);
|
|
282
|
+
const paramsHash = (0, poseidon_js_1.poseidon2)(mintPairHash, swapTermsHash);
|
|
283
|
+
return (0, poseidon_js_1.bigIntToBytesBE)(paramsHash);
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
286
286
|
* Compute the swap data hash committed on-chain for Jupiter instruction integrity.
|
package/dist/cjs/prover.d.ts
CHANGED
package/dist/cjs/prover.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createTransactionProver = createTransactionProver;
|
|
37
37
|
exports.verifyProof = verifyProof;
|
|
38
|
-
const
|
|
38
|
+
const proof_js_1 = require("./proof.js");
|
|
39
39
|
/** Lazy-load snarkjs — works in both CJS and ESM contexts. */
|
|
40
40
|
async function loadSnarkjs() {
|
|
41
41
|
try {
|
|
@@ -75,7 +75,7 @@ async function loadSnarkjs() {
|
|
|
75
75
|
function createTransactionProver(artifacts) {
|
|
76
76
|
return async (inputs) => {
|
|
77
77
|
const snarkjs = await loadSnarkjs();
|
|
78
|
-
const formattedInputs = (0,
|
|
78
|
+
const formattedInputs = (0, proof_js_1.formatInputsForSnarkjs)(inputs);
|
|
79
79
|
const { proof } = await snarkjs.groth16.fullProve(formattedInputs, artifacts.wasmPath, artifacts.zkeyPath);
|
|
80
80
|
return proof;
|
|
81
81
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform CSPRNG.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately backed by `nacl.randomBytes` rather than Node's `crypto.randomBytes`:
|
|
5
|
+
* tweetnacl resolves to `crypto.getRandomValues` in browsers and to Node's CSPRNG
|
|
6
|
+
* under Node, so this module carries no `node:crypto` import. That matters because
|
|
7
|
+
* every deposit path reaches this code via `createUTXO`/`generateKeypair`, and a
|
|
8
|
+
* bare `import { randomBytes } from "crypto"` throws at bundle time in browser
|
|
9
|
+
* builds that have no Node polyfill.
|
|
10
|
+
*
|
|
11
|
+
* tweetnacl is already a hard dependency, so this adds no install weight.
|
|
12
|
+
*/
|
|
13
|
+
/** `length` cryptographically-secure random bytes. */
|
|
14
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
15
|
+
/** 32 cryptographically-secure random bytes — the common case for blindings and seeds. */
|
|
16
|
+
export declare function randomBytes32(): Uint8Array;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.randomBytes = randomBytes;
|
|
7
|
+
exports.randomBytes32 = randomBytes32;
|
|
8
|
+
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
9
|
+
/**
|
|
10
|
+
* Cross-platform CSPRNG.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately backed by `nacl.randomBytes` rather than Node's `crypto.randomBytes`:
|
|
13
|
+
* tweetnacl resolves to `crypto.getRandomValues` in browsers and to Node's CSPRNG
|
|
14
|
+
* under Node, so this module carries no `node:crypto` import. That matters because
|
|
15
|
+
* every deposit path reaches this code via `createUTXO`/`generateKeypair`, and a
|
|
16
|
+
* bare `import { randomBytes } from "crypto"` throws at bundle time in browser
|
|
17
|
+
* builds that have no Node polyfill.
|
|
18
|
+
*
|
|
19
|
+
* tweetnacl is already a hard dependency, so this adds no install weight.
|
|
20
|
+
*/
|
|
21
|
+
/** `length` cryptographically-secure random bytes. */
|
|
22
|
+
function randomBytes(length) {
|
|
23
|
+
return tweetnacl_1.default.randomBytes(length);
|
|
24
|
+
}
|
|
25
|
+
/** 32 cryptographically-secure random bytes — the common case for blindings and seeds. */
|
|
26
|
+
function randomBytes32() {
|
|
27
|
+
return tweetnacl_1.default.randomBytes(32);
|
|
28
|
+
}
|
package/dist/cjs/relayer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface VeiloRelayerConfig {
|
|
2
|
-
/** Base URL of the relayer
|
|
3
|
-
relayerUrl
|
|
2
|
+
/** Base URL of the relayer. Defaults to Veilo's production service. */
|
|
3
|
+
relayerUrl?: string;
|
|
4
4
|
/** API key sent as x-api-key header */
|
|
5
5
|
apiKey: string;
|
|
6
6
|
/** Relayer's NaCl box public key (base64-encoded, 32 bytes) */
|
|
@@ -12,7 +12,8 @@ export interface VeiloRelayerConfig {
|
|
|
12
12
|
export declare class VeiloApiError extends Error {
|
|
13
13
|
code: string;
|
|
14
14
|
status: number;
|
|
15
|
-
|
|
15
|
+
details?: unknown;
|
|
16
|
+
constructor(code: string, message: string, status: number, details?: unknown);
|
|
16
17
|
}
|
|
17
18
|
/** Retry configuration for the relayer HTTP client. */
|
|
18
19
|
export interface RetryPolicy {
|
|
@@ -35,6 +36,12 @@ export interface RelayerEncryptedNote {
|
|
|
35
36
|
onchainId?: string;
|
|
36
37
|
spentTx?: string;
|
|
37
38
|
spentAt?: number;
|
|
39
|
+
compactEphemeralKey?: string | null;
|
|
40
|
+
compactBlob?: string | null;
|
|
41
|
+
viewTag?: number | null;
|
|
42
|
+
leafIndex?: number | null;
|
|
43
|
+
mintAddress?: string | null;
|
|
44
|
+
treeId?: number | null;
|
|
38
45
|
}
|
|
39
46
|
export interface QueryNotesRequest {
|
|
40
47
|
lastCheckedTimestamp?: number;
|
|
@@ -57,6 +64,14 @@ export interface SaveEncryptedNoteRequest {
|
|
|
57
64
|
blockHeight?: number;
|
|
58
65
|
txSignature?: string;
|
|
59
66
|
recipientWalletPublicKey?: string;
|
|
67
|
+
compactEphemeralKey?: string | null;
|
|
68
|
+
compactBlob?: string | null;
|
|
69
|
+
viewTag?: number | null;
|
|
70
|
+
leafIndex?: number;
|
|
71
|
+
newRoot?: string;
|
|
72
|
+
mintAddress?: string;
|
|
73
|
+
treeId?: number;
|
|
74
|
+
amountRaw?: string;
|
|
60
75
|
}
|
|
61
76
|
export interface SaveEncryptedNoteResponse {
|
|
62
77
|
success: boolean;
|
|
@@ -227,6 +242,10 @@ export interface VeiloPublicKeyResponse {
|
|
|
227
242
|
pubK: string;
|
|
228
243
|
veiloPublicKey: string;
|
|
229
244
|
}
|
|
245
|
+
export interface PreRegisterKeyResponse {
|
|
246
|
+
success: boolean;
|
|
247
|
+
veiloPublicKey: string;
|
|
248
|
+
}
|
|
230
249
|
export interface DeleteUserDataResponse {
|
|
231
250
|
success: boolean;
|
|
232
251
|
message: string;
|
|
@@ -241,7 +260,6 @@ export interface DeleteUserDataResponse {
|
|
|
241
260
|
* @example
|
|
242
261
|
* ```ts
|
|
243
262
|
* const client = new VeiloRelayerClient({
|
|
244
|
-
* relayerUrl: "https://relayer.veilo.io",
|
|
245
263
|
* apiKey: "your-api-key",
|
|
246
264
|
* relayerPublicKey: "<base64 NaCl public key>",
|
|
247
265
|
* });
|
|
@@ -276,6 +294,11 @@ export declare class VeiloRelayerClient {
|
|
|
276
294
|
publicKey: string;
|
|
277
295
|
username?: never;
|
|
278
296
|
}): Promise<VeiloPublicKeyResponse>;
|
|
297
|
+
/**
|
|
298
|
+
* Provision (or retrieve) the Veilo spend key paired with a Solana address.
|
|
299
|
+
* Public and idempotent; the response contains public key material only.
|
|
300
|
+
*/
|
|
301
|
+
preRegisterKey(solanaAddress: string): Promise<PreRegisterKeyResponse>;
|
|
279
302
|
/** Save an encrypted note to the relayer's database. */
|
|
280
303
|
saveEncryptedNote(data: SaveEncryptedNoteRequest): Promise<SaveEncryptedNoteResponse>;
|
|
281
304
|
/** Query encrypted notes for the authenticated user. Requires auth token. */
|
package/dist/cjs/relayer.js
CHANGED
|
@@ -5,16 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VeiloRelayerClient = exports.VeiloApiError = void 0;
|
|
7
7
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
8
|
+
const DEFAULT_RELAYER_URL = "https://relayer-server.onrender.com";
|
|
8
9
|
// =============================================================================
|
|
9
10
|
// Structured Error
|
|
10
11
|
// =============================================================================
|
|
11
12
|
/** Structured error thrown by VeiloRelayerClient on API failures. */
|
|
12
13
|
class VeiloApiError extends Error {
|
|
13
|
-
constructor(code, message, status) {
|
|
14
|
+
constructor(code, message, status, details) {
|
|
14
15
|
super(message);
|
|
15
16
|
this.name = "VeiloApiError";
|
|
16
17
|
this.code = code;
|
|
17
18
|
this.status = status;
|
|
19
|
+
this.details = details;
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
exports.VeiloApiError = VeiloApiError;
|
|
@@ -72,7 +74,6 @@ function encryptForRelayer(data, relayerPublicKey) {
|
|
|
72
74
|
* @example
|
|
73
75
|
* ```ts
|
|
74
76
|
* const client = new VeiloRelayerClient({
|
|
75
|
-
* relayerUrl: "https://relayer.veilo.io",
|
|
76
77
|
* apiKey: "your-api-key",
|
|
77
78
|
* relayerPublicKey: "<base64 NaCl public key>",
|
|
78
79
|
* });
|
|
@@ -81,7 +82,7 @@ function encryptForRelayer(data, relayerPublicKey) {
|
|
|
81
82
|
*/
|
|
82
83
|
class VeiloRelayerClient {
|
|
83
84
|
constructor(config, retry) {
|
|
84
|
-
this.baseUrl = config.relayerUrl.replace(/\/+$/, "");
|
|
85
|
+
this.baseUrl = (config.relayerUrl?.trim() || DEFAULT_RELAYER_URL).replace(/\/+$/, "");
|
|
85
86
|
this.apiKey = config.apiKey;
|
|
86
87
|
this.relayerPubKey = fromBase64(config.relayerPublicKey);
|
|
87
88
|
this.authToken = config.authToken;
|
|
@@ -97,8 +98,9 @@ class VeiloRelayerClient {
|
|
|
97
98
|
headers(authenticated) {
|
|
98
99
|
const h = {
|
|
99
100
|
"Content-Type": "application/json",
|
|
100
|
-
"x-api-key": this.apiKey,
|
|
101
101
|
};
|
|
102
|
+
if (this.apiKey)
|
|
103
|
+
h["x-api-key"] = this.apiKey;
|
|
102
104
|
if (authenticated && this.authToken) {
|
|
103
105
|
h["Authorization"] = `Bearer ${this.authToken}`;
|
|
104
106
|
}
|
|
@@ -131,7 +133,7 @@ class VeiloRelayerClient {
|
|
|
131
133
|
if (res.ok && data.success !== false) {
|
|
132
134
|
return data;
|
|
133
135
|
}
|
|
134
|
-
lastError = new VeiloApiError(data.error || "UNKNOWN", data.message || data.error || `Request failed: ${res.status}`, res.status);
|
|
136
|
+
lastError = new VeiloApiError(data.error || "UNKNOWN", data.message || data.error || `Request failed: ${res.status}`, res.status, data);
|
|
135
137
|
// Only retry on transient statuses
|
|
136
138
|
if (!this.retry.retryableStatuses.includes(res.status)) {
|
|
137
139
|
throw lastError;
|
|
@@ -174,6 +176,15 @@ class VeiloRelayerClient {
|
|
|
174
176
|
: `publicKey=${encodeURIComponent(params.publicKey)}`;
|
|
175
177
|
return this.request("GET", `/auth/veiloPublicKey?${query}`);
|
|
176
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Provision (or retrieve) the Veilo spend key paired with a Solana address.
|
|
181
|
+
* Public and idempotent; the response contains public key material only.
|
|
182
|
+
*/
|
|
183
|
+
async preRegisterKey(solanaAddress) {
|
|
184
|
+
return this.request("POST", "/auth/pre-register-key", {
|
|
185
|
+
body: { solanaAddress },
|
|
186
|
+
});
|
|
187
|
+
}
|
|
177
188
|
// ---------------------------------------------------------------------------
|
|
178
189
|
// Notes
|
|
179
190
|
// ---------------------------------------------------------------------------
|