@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
package/dist/src/shield/ix.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.TRANSACT_ACCOUNT_NAMES = void 0;
|
|
37
|
-
exports.buildTransactInstruction = buildTransactInstruction;
|
|
38
|
-
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
39
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
40
|
-
const program_js_1 = require("../program.js");
|
|
41
|
-
const errors_js_1 = require("./errors.js");
|
|
42
|
-
const computeBudget_js_1 = require("./computeBudget.js");
|
|
43
|
-
// Anchor is CommonJS and does not expose BN as a detectable named export to
|
|
44
|
-
// Node ESM. Pull both runtime values from the namespace so CJS and ESM agree.
|
|
45
|
-
const { BN, BorshInstructionCoder } = anchor;
|
|
46
|
-
const IDL_TRANSACT = program_js_1.PRIVACY_POOL_IDL.instructions.find((i) => i.name === "transact");
|
|
47
|
-
if (!IDL_TRANSACT) {
|
|
48
|
-
throw new Error("privacy_pool IDL has no `transact` instruction");
|
|
49
|
-
}
|
|
50
|
-
/** Account names in IDL order. Exported so callers can see what must be resolved. */
|
|
51
|
-
exports.TRANSACT_ACCOUNT_NAMES = IDL_TRANSACT.accounts.map((a) => a.name);
|
|
52
|
-
/**
|
|
53
|
-
* Build the `transact` instruction.
|
|
54
|
-
*
|
|
55
|
-
* @throws ShieldError('UNRESOLVED_ACCOUNT') if the IDL declares an account the
|
|
56
|
-
* caller did not supply — a loud failure is the point, because the
|
|
57
|
-
* alternative is a misordered account list that fails opaquely on-chain.
|
|
58
|
-
*/
|
|
59
|
-
function buildTransactInstruction(accounts, args, programId = program_js_1.PRIVACY_POOL_PROGRAM_ID) {
|
|
60
|
-
const keys = IDL_TRANSACT.accounts.map((a) => {
|
|
61
|
-
const pubkey = accounts[a.name];
|
|
62
|
-
if (!pubkey) {
|
|
63
|
-
throw new errors_js_1.ShieldError("UNRESOLVED_ACCOUNT", `The IDL declares account "${a.name}" for transact, but it was not resolved. ` +
|
|
64
|
-
`Expected accounts: ${exports.TRANSACT_ACCOUNT_NAMES.join(", ")}`, { context: { missing: a.name, supplied: Object.keys(accounts) } });
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
pubkey,
|
|
68
|
-
isWritable: !!a.writable,
|
|
69
|
-
isSigner: !!a.signer,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
const coder = new BorshInstructionCoder(program_js_1.PRIVACY_POOL_IDL);
|
|
73
|
-
const data = coder.encode("transact", toBorshArgs(args));
|
|
74
|
-
if (data.length !== computeBudget_js_1.TRANSACT_INSTRUCTION_DATA_BYTES) {
|
|
75
|
-
// Not fatal — the size budget assertion downstream is authoritative — but a
|
|
76
|
-
// change here means the size arithmetic in computeBudget.ts is stale.
|
|
77
|
-
console.warn(`[veilo] transact instruction data is ${data.length} bytes, expected ` +
|
|
78
|
-
`${computeBudget_js_1.TRANSACT_INSTRUCTION_DATA_BYTES}. The shield size budget may no longer hold.`);
|
|
79
|
-
}
|
|
80
|
-
return new web3_js_1.TransactionInstruction({ programId, keys, data });
|
|
81
|
-
}
|
|
82
|
-
/** Anchor's Borsh coder wants camelCase field names, BNs, and plain arrays. */
|
|
83
|
-
function toBorshArgs(args) {
|
|
84
|
-
return {
|
|
85
|
-
root: Array.from(args.root),
|
|
86
|
-
input_tree_id: args.inputTreeId,
|
|
87
|
-
output_tree_id: args.outputTreeId,
|
|
88
|
-
public_amount: new BN(args.publicAmount.toString()),
|
|
89
|
-
ext_data_hash: Array.from(args.extDataHash),
|
|
90
|
-
mint_address: args.mintAddress,
|
|
91
|
-
input_nullifier_0: Array.from(args.inputNullifiers[0]),
|
|
92
|
-
input_nullifier_1: Array.from(args.inputNullifiers[1]),
|
|
93
|
-
output_commitment_0: Array.from(args.outputCommitments[0]),
|
|
94
|
-
output_commitment_1: Array.from(args.outputCommitments[1]),
|
|
95
|
-
deadline: new BN(args.deadline.toString()),
|
|
96
|
-
ext_data: {
|
|
97
|
-
recipient: args.extData.recipient,
|
|
98
|
-
relayer: args.extData.relayer,
|
|
99
|
-
fee: new BN(args.extData.fee.toString()),
|
|
100
|
-
refund: new BN(args.extData.refund.toString()),
|
|
101
|
-
claimant: args.extData.claimant,
|
|
102
|
-
},
|
|
103
|
-
proof: {
|
|
104
|
-
proof_a: args.proof.proofA,
|
|
105
|
-
proof_b: args.proof.proofB,
|
|
106
|
-
proof_c: args.proof.proofC,
|
|
107
|
-
},
|
|
108
|
-
note_ciphers: args.noteCiphers
|
|
109
|
-
? {
|
|
110
|
-
note0_ephemeral_key: Array.from(args.noteCiphers.note0EphemeralKey),
|
|
111
|
-
note0_encrypted: Array.from(args.noteCiphers.note0Encrypted),
|
|
112
|
-
note0_view_tag: args.noteCiphers.note0ViewTag,
|
|
113
|
-
note1_ephemeral_key: Array.from(args.noteCiphers.note1EphemeralKey),
|
|
114
|
-
note1_encrypted: Array.from(args.noteCiphers.note1Encrypted),
|
|
115
|
-
note1_view_tag: args.noteCiphers.note1ViewTag,
|
|
116
|
-
}
|
|
117
|
-
: null,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import type { ShieldOwner } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Resolve a shield recipient into the pair of keys that must belong to the same
|
|
5
|
-
* account.
|
|
6
|
-
*
|
|
7
|
-
* This is the only mechanism that makes the owner invariant safe. A note's
|
|
8
|
-
* *spend* authority is a Poseidon field element and its *detection* authority is
|
|
9
|
-
* an Ed25519 wallet key; nothing on-chain relates them, and if an integrator
|
|
10
|
-
* sources them separately and gets them wrong, the note is spendable but
|
|
11
|
-
* permanently invisible — the funds are gone from the owner's view with no error
|
|
12
|
-
* raised anywhere in the stack.
|
|
13
|
-
*
|
|
14
|
-
* `GET /auth/veiloPublicKey` returns both halves in a single response, so
|
|
15
|
-
* routing through this function makes the pairing structural rather than a
|
|
16
|
-
* convention integrators are asked to remember.
|
|
17
|
-
*
|
|
18
|
-
* Prefer this over hand-building a {@link ShieldOwner} in all cases.
|
|
19
|
-
*/
|
|
20
|
-
export declare function resolveShieldOwner(target: {
|
|
21
|
-
username: string;
|
|
22
|
-
} | {
|
|
23
|
-
publicKey: string | PublicKey;
|
|
24
|
-
}): Promise<ShieldOwner>;
|
|
25
|
-
/**
|
|
26
|
-
* Build a {@link ShieldOwner} from keys the caller already holds.
|
|
27
|
-
*
|
|
28
|
-
* Only correct when both keys provably belong to the same account. The explicit
|
|
29
|
-
* flag is not ceremony — it is the last checkpoint before a class of bug whose
|
|
30
|
-
* only symptom is a user's money quietly disappearing from their balance.
|
|
31
|
-
*/
|
|
32
|
-
export declare function unsafeShieldOwner(params: {
|
|
33
|
-
veiloPublicKey: bigint;
|
|
34
|
-
noteViewingKey: PublicKey;
|
|
35
|
-
acknowledgeOwnerInvariant: true;
|
|
36
|
-
}): ShieldOwner;
|
package/dist/src/shield/owner.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveShieldOwner = resolveShieldOwner;
|
|
4
|
-
exports.unsafeShieldOwner = unsafeShieldOwner;
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
const relayer_js_1 = require("../relayer.js");
|
|
7
|
-
const errors_js_1 = require("./errors.js");
|
|
8
|
-
/**
|
|
9
|
-
* Owner resolution is a Veilo protocol service, not an integrator-selected
|
|
10
|
-
* transport. Keep the production endpoint and public encryption key inside the
|
|
11
|
-
* SDK so callers cannot accidentally resolve the two owner keys from different
|
|
12
|
-
* relayers.
|
|
13
|
-
*
|
|
14
|
-
* These values are public network coordinates, not credentials. In particular,
|
|
15
|
-
* never put a secret API key here: browser/mobile package contents are always
|
|
16
|
-
* inspectable. The two owner endpoints used below are intentionally public and
|
|
17
|
-
* return public key material only.
|
|
18
|
-
*/
|
|
19
|
-
const OWNER_RELAYER = new relayer_js_1.VeiloRelayerClient({
|
|
20
|
-
apiKey: "",
|
|
21
|
-
relayerPublicKey: "utVxnA7zax09qJCZ7UJsa8PAOoWLRcCwOkdxg/ZGmD4=",
|
|
22
|
-
});
|
|
23
|
-
/**
|
|
24
|
-
* Resolve a shield recipient into the pair of keys that must belong to the same
|
|
25
|
-
* account.
|
|
26
|
-
*
|
|
27
|
-
* This is the only mechanism that makes the owner invariant safe. A note's
|
|
28
|
-
* *spend* authority is a Poseidon field element and its *detection* authority is
|
|
29
|
-
* an Ed25519 wallet key; nothing on-chain relates them, and if an integrator
|
|
30
|
-
* sources them separately and gets them wrong, the note is spendable but
|
|
31
|
-
* permanently invisible — the funds are gone from the owner's view with no error
|
|
32
|
-
* raised anywhere in the stack.
|
|
33
|
-
*
|
|
34
|
-
* `GET /auth/veiloPublicKey` returns both halves in a single response, so
|
|
35
|
-
* routing through this function makes the pairing structural rather than a
|
|
36
|
-
* convention integrators are asked to remember.
|
|
37
|
-
*
|
|
38
|
-
* Prefer this over hand-building a {@link ShieldOwner} in all cases.
|
|
39
|
-
*/
|
|
40
|
-
async function resolveShieldOwner(target) {
|
|
41
|
-
const query = "username" in target
|
|
42
|
-
? { username: target.username }
|
|
43
|
-
: {
|
|
44
|
-
publicKey: typeof target.publicKey === "string"
|
|
45
|
-
? target.publicKey
|
|
46
|
-
: target.publicKey.toBase58(),
|
|
47
|
-
};
|
|
48
|
-
let response;
|
|
49
|
-
try {
|
|
50
|
-
response = await OWNER_RELAYER.getVeiloPublicKey(query);
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
// A raw Solana address may not have a Veilo account yet. Provisioning is
|
|
54
|
-
// public and idempotent, and returns only the Poseidon spend key; the
|
|
55
|
-
// address we were given is the matching note-viewing key.
|
|
56
|
-
if ("publicKey" in target &&
|
|
57
|
-
(e?.status === 404 || (e instanceof relayer_js_1.VeiloApiError && e.status === 404))) {
|
|
58
|
-
const wallet = typeof target.publicKey === "string"
|
|
59
|
-
? new web3_js_1.PublicKey(target.publicKey)
|
|
60
|
-
: target.publicKey;
|
|
61
|
-
const provisioned = await OWNER_RELAYER.preRegisterKey(wallet.toBase58());
|
|
62
|
-
if (!provisioned?.veiloPublicKey) {
|
|
63
|
-
throw new errors_js_1.ShieldError("UNKNOWN", "The relayer pre-registered the recipient but returned no Veilo public key.", { context: { publicKey: wallet.toBase58(), response: provisioned }, cause: e });
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
veiloPublicKey: BigInt(provisioned.veiloPublicKey),
|
|
67
|
-
noteViewingKey: wallet,
|
|
68
|
-
acknowledgeOwnerInvariant: true,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
// A pre-registered account is one someone else created on the recipient's
|
|
72
|
-
// behalf; the recipient has never proved ownership, so the relayer refuses
|
|
73
|
-
// to resolve it by username. Shielding to them still works, but the caller
|
|
74
|
-
// must address them by Solana address instead.
|
|
75
|
-
if (e?.body?.preRegistered ||
|
|
76
|
-
e?.details?.preRegistered ||
|
|
77
|
-
/preregistered/i.test(String(e?.message ?? ""))) {
|
|
78
|
-
throw new errors_js_1.ShieldError("UNKNOWN", `"${"username" in target ? target.username : "that account"}" is pre-registered ` +
|
|
79
|
-
`and cannot be resolved by username. Resolve it by Solana address instead — ` +
|
|
80
|
-
`resolveShieldOwner({ publicKey }).`, { context: { preRegistered: true }, cause: e });
|
|
81
|
-
}
|
|
82
|
-
throw e;
|
|
83
|
-
}
|
|
84
|
-
const veiloPublicKeyRaw = response?.veiloPublicKey;
|
|
85
|
-
const walletRaw = response?.pubK;
|
|
86
|
-
if (!veiloPublicKeyRaw || !walletRaw) {
|
|
87
|
-
throw new errors_js_1.ShieldError("UNKNOWN", `The relayer did not return both keys for this recipient ` +
|
|
88
|
-
`(veiloPublicKey=${!!veiloPublicKeyRaw}, pubK=${!!walletRaw}). ` +
|
|
89
|
-
`Shielding without both would create a note the owner cannot find.`, { context: { response } });
|
|
90
|
-
}
|
|
91
|
-
const noteViewingKey = new web3_js_1.PublicKey(walletRaw);
|
|
92
|
-
if ("publicKey" in target &&
|
|
93
|
-
!noteViewingKey.equals(typeof target.publicKey === "string"
|
|
94
|
-
? new web3_js_1.PublicKey(target.publicKey)
|
|
95
|
-
: target.publicKey)) {
|
|
96
|
-
throw new errors_js_1.ShieldError("UNKNOWN", "The Veilo owner service returned a different wallet than the one requested. " +
|
|
97
|
-
"Shielding was stopped to prevent creating a note for the wrong recipient.", {
|
|
98
|
-
context: {
|
|
99
|
-
requested: typeof target.publicKey === "string"
|
|
100
|
-
? target.publicKey
|
|
101
|
-
: target.publicKey.toBase58(),
|
|
102
|
-
returned: noteViewingKey.toBase58(),
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
veiloPublicKey: BigInt(veiloPublicKeyRaw),
|
|
108
|
-
noteViewingKey,
|
|
109
|
-
// Safe to assert: both halves came from one response about one account.
|
|
110
|
-
acknowledgeOwnerInvariant: true,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Build a {@link ShieldOwner} from keys the caller already holds.
|
|
115
|
-
*
|
|
116
|
-
* Only correct when both keys provably belong to the same account. The explicit
|
|
117
|
-
* flag is not ceremony — it is the last checkpoint before a class of bug whose
|
|
118
|
-
* only symptom is a user's money quietly disappearing from their balance.
|
|
119
|
-
*/
|
|
120
|
-
function unsafeShieldOwner(params) {
|
|
121
|
-
return {
|
|
122
|
-
veiloPublicKey: params.veiloPublicKey,
|
|
123
|
-
noteViewingKey: params.noteViewingKey,
|
|
124
|
-
acknowledgeOwnerInvariant: true,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import type { DepositTarget, ShieldCachePort, TreeSource } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Injection points for the shield path.
|
|
5
|
-
*
|
|
6
|
-
* The three production deposit implementations (extension, wallet-app,
|
|
7
|
-
* veilo-dapp) are ~85% identical and diverge on exactly these axes: where
|
|
8
|
-
* proofs come from, where the tree comes from, which lookup table to use, and
|
|
9
|
-
* what to cache into. Making each an explicit port is what lets one
|
|
10
|
-
* implementation serve all of them — and lets a third-party integrator supply
|
|
11
|
-
* their own without forking anything.
|
|
12
|
-
*
|
|
13
|
-
* Proof generation is deliberately NOT redefined here: `TransactionProofBuilder`
|
|
14
|
-
* from `proof.ts` already has the right shape, and a second prover abstraction
|
|
15
|
-
* would be exactly the kind of duplication this module exists to avoid.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Read the target tree and root directly from chain.
|
|
19
|
-
*
|
|
20
|
-
* Note the account decoding: `MerkleTreeAccount::EXPECTED_SIZE` (9107) does not
|
|
21
|
-
* match the size its declared fields sum to (8987), a 120-byte discrepancy that
|
|
22
|
-
* is unexplained. Until it is, hand-slicing this account at fixed byte offsets
|
|
23
|
-
* is unsafe. Anchor's coder reads declared fields from the front and ignores the
|
|
24
|
-
* tail, so `.fetch()` stays correct regardless.
|
|
25
|
-
*/
|
|
26
|
-
export declare function onChainTreeSource(connection: Connection, programId?: PublicKey): TreeSource;
|
|
27
|
-
/**
|
|
28
|
-
* Fixed values, for tests and offline builds.
|
|
29
|
-
*
|
|
30
|
-
* Also the escape hatch for an integrator who already tracks the tree state and
|
|
31
|
-
* does not want the SDK making RPC calls on their behalf.
|
|
32
|
-
*/
|
|
33
|
-
export declare function staticTreeSource(target: DepositTarget): TreeSource;
|
|
34
|
-
/**
|
|
35
|
-
* In-memory cache with TTL. The default.
|
|
36
|
-
*
|
|
37
|
-
* Persistent storage is deliberately the caller's problem — `localStorage`,
|
|
38
|
-
* `chrome.storage`, and `AsyncStorage` are three different answers in three
|
|
39
|
-
* different apps, and none of them belongs in a published SDK.
|
|
40
|
-
*/
|
|
41
|
-
export declare function memoryCache(): ShieldCachePort;
|
|
42
|
-
/** A cache that never stores anything. Useful for tests that assert fetch counts. */
|
|
43
|
-
export declare function noCache(): ShieldCachePort;
|
package/dist/src/shield/ports.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onChainTreeSource = onChainTreeSource;
|
|
4
|
-
exports.staticTreeSource = staticTreeSource;
|
|
5
|
-
exports.memoryCache = memoryCache;
|
|
6
|
-
exports.noCache = noCache;
|
|
7
|
-
const program_js_1 = require("../program.js");
|
|
8
|
-
const client_js_1 = require("../client.js");
|
|
9
|
-
const config_js_1 = require("../config.js");
|
|
10
|
-
const errors_js_1 = require("./errors.js");
|
|
11
|
-
/**
|
|
12
|
-
* Injection points for the shield path.
|
|
13
|
-
*
|
|
14
|
-
* The three production deposit implementations (extension, wallet-app,
|
|
15
|
-
* veilo-dapp) are ~85% identical and diverge on exactly these axes: where
|
|
16
|
-
* proofs come from, where the tree comes from, which lookup table to use, and
|
|
17
|
-
* what to cache into. Making each an explicit port is what lets one
|
|
18
|
-
* implementation serve all of them — and lets a third-party integrator supply
|
|
19
|
-
* their own without forking anything.
|
|
20
|
-
*
|
|
21
|
-
* Proof generation is deliberately NOT redefined here: `TransactionProofBuilder`
|
|
22
|
-
* from `proof.ts` already has the right shape, and a second prover abstraction
|
|
23
|
-
* would be exactly the kind of duplication this module exists to avoid.
|
|
24
|
-
*/
|
|
25
|
-
// -- TreeSource ---------------------------------------------------------------
|
|
26
|
-
/**
|
|
27
|
-
* Read the target tree and root directly from chain.
|
|
28
|
-
*
|
|
29
|
-
* Note the account decoding: `MerkleTreeAccount::EXPECTED_SIZE` (9107) does not
|
|
30
|
-
* match the size its declared fields sum to (8987), a 120-byte discrepancy that
|
|
31
|
-
* is unexplained. Until it is, hand-slicing this account at fixed byte offsets
|
|
32
|
-
* is unsafe. Anchor's coder reads declared fields from the front and ignores the
|
|
33
|
-
* tail, so `.fetch()` stays correct regardless.
|
|
34
|
-
*/
|
|
35
|
-
function onChainTreeSource(connection, programId = program_js_1.PRIVACY_POOL_PROGRAM_ID) {
|
|
36
|
-
return {
|
|
37
|
-
async getDepositTarget(mint) {
|
|
38
|
-
const program = (0, program_js_1.createReadonlyVeiloProgram)(connection);
|
|
39
|
-
const { config } = (0, client_js_1.getPoolPdas)(programId, mint);
|
|
40
|
-
const cfg = await program.account.privacyConfig.fetch(config);
|
|
41
|
-
const numTrees = Number(cfg.numTrees);
|
|
42
|
-
if (!Number.isInteger(numTrees) || numTrees <= 0) {
|
|
43
|
-
throw new errors_js_1.ShieldError("TREE_FULL", `Pool ${mint.toBase58()} has no deposit tree.`, { context: { mint: mint.toBase58(), numTrees } });
|
|
44
|
-
}
|
|
45
|
-
// Fetch every tree in one RPC call. The older getBestTreeForDeposit path
|
|
46
|
-
// fetched them serially, then fetched the chosen trees a second time.
|
|
47
|
-
const treePdas = Array.from({ length: numTrees }, (_, treeId) => (0, client_js_1.getNoteTreePda)(programId, mint, treeId));
|
|
48
|
-
const infos = await connection.getMultipleAccountsInfo(treePdas, {
|
|
49
|
-
commitment: "confirmed",
|
|
50
|
-
});
|
|
51
|
-
const capacity = 2 ** config_js_1.MERKLE_TREE_DEPTH;
|
|
52
|
-
const trees = infos.map((info, treeId) => {
|
|
53
|
-
if (!info)
|
|
54
|
-
return null;
|
|
55
|
-
// Anchor camel-cases the IDL's `MerkleTreeAccount` name when it builds
|
|
56
|
-
// the Borsh account-layout map (the same key exposed as
|
|
57
|
-
// `program.account.merkleTreeAccount`).
|
|
58
|
-
const decoded = program.coder.accounts.decode("merkleTreeAccount", info.data);
|
|
59
|
-
const nextIndex = Number(decoded.nextIndex);
|
|
60
|
-
return {
|
|
61
|
-
treeId,
|
|
62
|
-
decoded,
|
|
63
|
-
nextIndex,
|
|
64
|
-
remainingCapacity: capacity - nextIndex,
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
const inputTree = trees[0];
|
|
68
|
-
if (!inputTree) {
|
|
69
|
-
throw new errors_js_1.ShieldError("POOL_NOT_FOUND", `Pool ${mint.toBase58()} is missing its input Merkle tree (tree 0).`, { context: { mint: mint.toBase58(), tree: treePdas[0].toBase58() } });
|
|
70
|
-
}
|
|
71
|
-
const available = trees.filter((tree) => !!tree && tree.nextIndex < capacity);
|
|
72
|
-
if (available.length === 0) {
|
|
73
|
-
throw new errors_js_1.ShieldError("TREE_FULL", `All ${numTrees} Merkle trees for ${mint.toBase58()} are full.`, { context: { mint: mint.toBase58(), numTrees, capacity } });
|
|
74
|
-
}
|
|
75
|
-
const minCapacity = Math.floor(capacity * 0.0001);
|
|
76
|
-
const preferred = available
|
|
77
|
-
.filter((tree) => tree.remainingCapacity >= minCapacity)
|
|
78
|
-
.sort((a, b) => a.treeId - b.treeId);
|
|
79
|
-
const outputTree = preferred[0] ??
|
|
80
|
-
available.sort((a, b) => b.remainingCapacity - a.remainingCapacity)[0];
|
|
81
|
-
return {
|
|
82
|
-
inputTreeId: 0,
|
|
83
|
-
inputRoot: extractRoot(inputTree.decoded),
|
|
84
|
-
outputTreeId: outputTree.treeId,
|
|
85
|
-
outputNextIndex: outputTree.nextIndex,
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Fixed values, for tests and offline builds.
|
|
92
|
-
*
|
|
93
|
-
* Also the escape hatch for an integrator who already tracks the tree state and
|
|
94
|
-
* does not want the SDK making RPC calls on their behalf.
|
|
95
|
-
*/
|
|
96
|
-
function staticTreeSource(target) {
|
|
97
|
-
return { async getDepositTarget() { return target; } };
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Read the root from a decoded `MerkleTreeAccount`.
|
|
101
|
-
*
|
|
102
|
-
* Uses `root_history[root_index]` rather than the `root` field. Both are written
|
|
103
|
-
* to the same value by `append` (merkle_tree.rs:108-111) so they agree, but the
|
|
104
|
-
* history read is what all three production implementations use and is therefore
|
|
105
|
-
* the one that is actually exercised against mainnet.
|
|
106
|
-
*/
|
|
107
|
-
function extractRoot(tree) {
|
|
108
|
-
const history = tree.rootHistory ?? tree.root_history;
|
|
109
|
-
const index = Number(tree.rootIndex ?? tree.root_index ?? 0);
|
|
110
|
-
if (Array.isArray(history) && history[index]) {
|
|
111
|
-
return new Uint8Array(history[index]);
|
|
112
|
-
}
|
|
113
|
-
const root = tree.root;
|
|
114
|
-
if (root)
|
|
115
|
-
return new Uint8Array(root);
|
|
116
|
-
throw new Error("could not read a Merkle root from the tree account");
|
|
117
|
-
}
|
|
118
|
-
// -- Cache --------------------------------------------------------------------
|
|
119
|
-
/**
|
|
120
|
-
* In-memory cache with TTL. The default.
|
|
121
|
-
*
|
|
122
|
-
* Persistent storage is deliberately the caller's problem — `localStorage`,
|
|
123
|
-
* `chrome.storage`, and `AsyncStorage` are three different answers in three
|
|
124
|
-
* different apps, and none of them belongs in a published SDK.
|
|
125
|
-
*/
|
|
126
|
-
function memoryCache() {
|
|
127
|
-
const store = new Map();
|
|
128
|
-
return {
|
|
129
|
-
async get(key) {
|
|
130
|
-
const hit = store.get(key);
|
|
131
|
-
if (!hit)
|
|
132
|
-
return undefined;
|
|
133
|
-
if (hit.expiresAt !== 0 && hit.expiresAt < Date.now()) {
|
|
134
|
-
store.delete(key);
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
return hit.value;
|
|
138
|
-
},
|
|
139
|
-
async set(key, value, ttlMs) {
|
|
140
|
-
store.set(key, {
|
|
141
|
-
value,
|
|
142
|
-
expiresAt: ttlMs && ttlMs > 0 ? Date.now() + ttlMs : 0,
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
/** A cache that never stores anything. Useful for tests that assert fetch counts. */
|
|
148
|
-
function noCache() {
|
|
149
|
-
return {
|
|
150
|
-
async get() { return undefined; },
|
|
151
|
-
async set() { },
|
|
152
|
-
};
|
|
153
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import type { PreflightOptions, ShieldCachePort } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Checks that run before the prover.
|
|
5
|
-
*
|
|
6
|
-
* Proving costs 10–30 seconds. Every check here is a single RPC call, and each
|
|
7
|
-
* one pre-empts an on-chain failure whose message tells the user nothing they
|
|
8
|
-
* can act on. The delegate check is the clearest example: the program requires
|
|
9
|
-
* `user_token.delegate.is_none()`, so anyone who ever approved a DEX has a
|
|
10
|
-
* permanently broken deposit path that reports only "Invalid token account
|
|
11
|
-
* authority" — with no hint that revoking a delegate would fix it.
|
|
12
|
-
*
|
|
13
|
-
* These are advisory in the sense that the chain enforces them anyway. They are
|
|
14
|
-
* not advisory in the sense that skipping them produces a materially worse
|
|
15
|
-
* product.
|
|
16
|
-
*/
|
|
17
|
-
export declare function preflightShield(params: {
|
|
18
|
-
connection: Connection;
|
|
19
|
-
amount: bigint;
|
|
20
|
-
mint: PublicKey;
|
|
21
|
-
signer: {
|
|
22
|
-
publicKey: PublicKey;
|
|
23
|
-
tokenAccount: PublicKey;
|
|
24
|
-
};
|
|
25
|
-
programId?: PublicKey;
|
|
26
|
-
options?: PreflightOptions;
|
|
27
|
-
cache?: ShieldCachePort;
|
|
28
|
-
computeUnitLimit?: number;
|
|
29
|
-
computeUnitPriceMicroLamports?: number;
|
|
30
|
-
}): Promise<void>;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preflightShield = preflightShield;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const client_js_1 = require("../client.js");
|
|
6
|
-
const program_js_1 = require("../program.js");
|
|
7
|
-
const config_js_1 = require("../config.js");
|
|
8
|
-
const errors_js_1 = require("./errors.js");
|
|
9
|
-
const computeBudget_js_1 = require("./computeBudget.js");
|
|
10
|
-
/**
|
|
11
|
-
* Checks that run before the prover.
|
|
12
|
-
*
|
|
13
|
-
* Proving costs 10–30 seconds. Every check here is a single RPC call, and each
|
|
14
|
-
* one pre-empts an on-chain failure whose message tells the user nothing they
|
|
15
|
-
* can act on. The delegate check is the clearest example: the program requires
|
|
16
|
-
* `user_token.delegate.is_none()`, so anyone who ever approved a DEX has a
|
|
17
|
-
* permanently broken deposit path that reports only "Invalid token account
|
|
18
|
-
* authority" — with no hint that revoking a delegate would fix it.
|
|
19
|
-
*
|
|
20
|
-
* These are advisory in the sense that the chain enforces them anyway. They are
|
|
21
|
-
* not advisory in the sense that skipping them produces a materially worse
|
|
22
|
-
* product.
|
|
23
|
-
*/
|
|
24
|
-
async function preflightShield(params) {
|
|
25
|
-
const { connection, amount, mint, signer, programId = program_js_1.PRIVACY_POOL_PROGRAM_ID, options = {}, } = params;
|
|
26
|
-
const isToken = !mint.equals(config_js_1.NATIVE_SOL_MINT);
|
|
27
|
-
// --- Pool state ------------------------------------------------------------
|
|
28
|
-
if (!options.skipPoolState) {
|
|
29
|
-
const program = (0, program_js_1.createReadonlyVeiloProgram)(connection);
|
|
30
|
-
const { config } = (0, client_js_1.getPoolPdas)(programId, mint);
|
|
31
|
-
let cfg;
|
|
32
|
-
try {
|
|
33
|
-
cfg = await program.account.privacyConfig.fetch(config);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw new errors_js_1.ShieldError("POOL_NOT_FOUND", `No privacy pool exists for mint ${mint.toBase58()}.`, { context: { mint: mint.toBase58(), config: config.toBase58() }, cause: e });
|
|
37
|
-
}
|
|
38
|
-
if (cfg.paused) {
|
|
39
|
-
throw new errors_js_1.ShieldError("POOL_PAUSED", "The pool is paused. Try again later.");
|
|
40
|
-
}
|
|
41
|
-
const min = BigInt(cfg.minDepositAmount?.toString() ?? "0");
|
|
42
|
-
const max = BigInt(cfg.maxDepositAmount?.toString() ?? "0");
|
|
43
|
-
if (min > 0n && amount < min) {
|
|
44
|
-
throw new errors_js_1.ShieldError("AMOUNT_BELOW_MINIMUM", `Amount ${amount} is below the pool minimum of ${min}.`, { context: { amount: amount.toString(), minimum: min.toString() } });
|
|
45
|
-
}
|
|
46
|
-
if (max > 0n && amount > max) {
|
|
47
|
-
throw new errors_js_1.ShieldError("AMOUNT_ABOVE_MAXIMUM", `Amount ${amount} exceeds the pool maximum of ${max}.`, { context: { amount: amount.toString(), maximum: max.toString() } });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// --- Source token account (SPL only) --------------------------------------
|
|
51
|
-
if (isToken && !options.skipTokenAccount) {
|
|
52
|
-
let account;
|
|
53
|
-
try {
|
|
54
|
-
account = await (0, spl_token_1.getAccount)(connection, signer.tokenAccount);
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
if (e instanceof spl_token_1.TokenAccountNotFoundError || /could not find/i.test(String(e))) {
|
|
58
|
-
// Deliberately no "create the ATA" remedy: an ATA that does not exist
|
|
59
|
-
// holds zero tokens, so creating it would only move the failure to
|
|
60
|
-
// INSUFFICIENT_TOKEN_BALANCE. Say the true thing instead.
|
|
61
|
-
throw new errors_js_1.ShieldError("TOKEN_ACCOUNT_MISSING", `The signer has no token account for ${mint.toBase58()}, so there is nothing to shield.`, { context: { tokenAccount: signer.tokenAccount.toBase58() }, cause: e });
|
|
62
|
-
}
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
if (!account.mint.equals(mint)) {
|
|
66
|
-
throw new errors_js_1.ShieldError("TOKEN_ACCOUNT_WRONG_MINT", `Token account ${signer.tokenAccount.toBase58()} holds ${account.mint.toBase58()}, not ${mint.toBase58()}.`, { context: { expected: mint.toBase58(), actual: account.mint.toBase58() } });
|
|
67
|
-
}
|
|
68
|
-
if (!account.owner.equals(signer.publicKey)) {
|
|
69
|
-
throw new errors_js_1.ShieldError("TOKEN_ACCOUNT_WRONG_OWNER", `Token account ${signer.tokenAccount.toBase58()} is owned by ${account.owner.toBase58()}, ` +
|
|
70
|
-
`not by the signing wallet. The program requires the signer to own the source account outright.`, {
|
|
71
|
-
context: {
|
|
72
|
-
tokenAccount: signer.tokenAccount.toBase58(),
|
|
73
|
-
owner: account.owner.toBase58(),
|
|
74
|
-
signer: signer.publicKey.toBase58(),
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (account.isFrozen) {
|
|
79
|
-
throw new errors_js_1.ShieldError("TOKEN_ACCOUNT_FROZEN", `Token account ${signer.tokenAccount.toBase58()} is frozen.`, { context: { tokenAccount: signer.tokenAccount.toBase58() } });
|
|
80
|
-
}
|
|
81
|
-
// The program checks `delegate.is_none()`, NOT the delegated amount — so a
|
|
82
|
-
// stale delegate with zero allowance still fails. This is the single most
|
|
83
|
-
// common avoidable failure on this path, and it is entirely fixable.
|
|
84
|
-
if (account.delegate) {
|
|
85
|
-
throw new errors_js_1.ShieldError("TOKEN_ACCOUNT_DELEGATED", `Token account ${signer.tokenAccount.toBase58()} has an active delegate ` +
|
|
86
|
-
`(${account.delegate.toBase58()}). The pool rejects deposits from delegated ` +
|
|
87
|
-
`accounts even when the delegated amount is zero. Revoke the delegate, then shield.`, {
|
|
88
|
-
context: {
|
|
89
|
-
tokenAccount: signer.tokenAccount.toBase58(),
|
|
90
|
-
delegate: account.delegate.toBase58(),
|
|
91
|
-
delegatedAmount: account.delegatedAmount.toString(),
|
|
92
|
-
},
|
|
93
|
-
remedy: {
|
|
94
|
-
description: `Revoke the delegate on ${signer.tokenAccount.toBase58()}`,
|
|
95
|
-
instructions: [
|
|
96
|
-
(0, spl_token_1.createRevokeInstruction)(signer.tokenAccount, signer.publicKey),
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (account.amount < amount) {
|
|
102
|
-
throw new errors_js_1.ShieldError("INSUFFICIENT_TOKEN_BALANCE", `Token account holds ${account.amount} but ${amount} is required.`, { context: { balance: account.amount.toString(), required: amount.toString() } });
|
|
103
|
-
}
|
|
104
|
-
// The vault's ATA must already exist — the program requires the canonical
|
|
105
|
-
// one and will not create it.
|
|
106
|
-
const { vault } = (0, client_js_1.getPoolPdas)(programId, mint);
|
|
107
|
-
const vaultAta = await (0, spl_token_1.getAssociatedTokenAddress)(mint, vault, true);
|
|
108
|
-
const vaultInfo = await connection.getAccountInfo(vaultAta);
|
|
109
|
-
if (!vaultInfo) {
|
|
110
|
-
throw new errors_js_1.ShieldError("VAULT_ATA_MISSING", `The pool vault has no associated token account for ${mint.toBase58()}. ` +
|
|
111
|
-
`This is a pool provisioning issue, not something the signer can fix.`, { context: { vault: vault.toBase58(), vaultAta: vaultAta.toBase58() } });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// --- Signer balance --------------------------------------------------------
|
|
115
|
-
if (!options.skipBalance) {
|
|
116
|
-
const rentPer = await cachedRent(connection, params.cache);
|
|
117
|
-
const rent = BigInt(rentPer) * BigInt(computeBudget_js_1.NULLIFIER_MARKERS_PER_TRANSACT);
|
|
118
|
-
const computeUnitLimit = params.computeUnitLimit ?? computeBudget_js_1.SHIELD_COMPUTE_UNIT_LIMIT;
|
|
119
|
-
const computeUnitPriceMicroLamports = params.computeUnitPriceMicroLamports ?? computeBudget_js_1.SHIELD_COMPUTE_UNIT_PRICE_MICRO_LAMPORTS;
|
|
120
|
-
const priorityFee = (BigInt(computeUnitLimit) * BigInt(computeUnitPriceMicroLamports)) /
|
|
121
|
-
1000000n;
|
|
122
|
-
const baseFee = 5000n;
|
|
123
|
-
// The signer pays the marker rent regardless of the mint — it is SOL either
|
|
124
|
-
// way, and it is burned, not refunded.
|
|
125
|
-
const required = rent + priorityFee + baseFee + (isToken ? 0n : amount);
|
|
126
|
-
const balance = BigInt(await connection.getBalance(signer.publicKey));
|
|
127
|
-
if (balance < required) {
|
|
128
|
-
throw new errors_js_1.ShieldError("INSUFFICIENT_SOL", `The signing wallet has ${balance} lamports but needs ${required} ` +
|
|
129
|
-
`(${isToken ? "" : `${amount} shielded + `}${rent} nullifier-marker rent + ` +
|
|
130
|
-
`${priorityFee + baseFee} fees). Note that the marker rent is burned, not refunded, ` +
|
|
131
|
-
`and the program forces it onto the signer — it cannot be sponsored.`, {
|
|
132
|
-
context: {
|
|
133
|
-
balance: balance.toString(),
|
|
134
|
-
required: required.toString(),
|
|
135
|
-
breakdown: {
|
|
136
|
-
amount: isToken ? "0" : amount.toString(),
|
|
137
|
-
nullifierMarkerRent: rent.toString(),
|
|
138
|
-
priorityFee: priorityFee.toString(),
|
|
139
|
-
baseFee: baseFee.toString(),
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
async function cachedRent(connection, cache) {
|
|
147
|
-
const key = `rent:${computeBudget_js_1.NULLIFIER_MARKER_ACCOUNT_BYTES}`;
|
|
148
|
-
const hit = await cache?.get(key);
|
|
149
|
-
if (hit !== undefined)
|
|
150
|
-
return hit;
|
|
151
|
-
const value = await connection.getMinimumBalanceForRentExemption(computeBudget_js_1.NULLIFIER_MARKER_ACCOUNT_BYTES);
|
|
152
|
-
await cache?.set(key, value, 60 * 60000);
|
|
153
|
-
return value;
|
|
154
|
-
}
|