@veilo/sdk-core 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +449 -1243
- package/accounts.d.ts +2 -0
- package/accounts.js +3 -0
- package/cloak.d.ts +2 -0
- package/cloak.js +3 -0
- package/config.d.ts +2 -2
- package/config.js +2 -3
- 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/events/index.d.ts +6 -0
- package/dist/cjs/events/index.js +22 -0
- package/dist/cjs/events/parsing.d.ts +25 -0
- package/dist/cjs/events/parsing.js +158 -0
- package/dist/cjs/events/position.d.ts +26 -0
- package/dist/cjs/events/position.js +53 -0
- package/dist/cjs/events/recovery.d.ts +87 -0
- package/dist/cjs/events/recovery.js +281 -0
- package/dist/cjs/events/scanning.d.ts +35 -0
- package/dist/cjs/events/scanning.js +98 -0
- package/dist/cjs/events/tree.d.ts +27 -0
- package/dist/cjs/events/tree.js +63 -0
- package/dist/cjs/events/types.d.ts +39 -0
- package/dist/cjs/events.d.ts +1 -77
- package/dist/cjs/events.js +6 -154
- package/dist/cjs/identity/encoding.d.ts +9 -0
- package/dist/cjs/identity/encoding.js +85 -0
- package/dist/cjs/identity/index.d.ts +4 -0
- package/dist/cjs/identity/index.js +20 -0
- package/dist/cjs/identity/noteKey.d.ts +33 -0
- package/dist/cjs/identity/noteKey.js +97 -0
- package/dist/cjs/identity/spending.d.ts +18 -0
- package/dist/cjs/identity/spending.js +46 -0
- package/dist/cjs/identity/viewKey.d.ts +38 -0
- package/dist/cjs/identity/viewKey.js +105 -0
- package/dist/cjs/idl/index.d.ts +18 -0
- package/dist/cjs/idl/index.js +24 -0
- package/dist/cjs/idl/privacy_pool.json +9907 -9907
- package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
- package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
- package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
- package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/cjs/index.d.ts +9 -3
- package/dist/cjs/index.js +15 -2
- package/dist/cjs/notes/amount.d.ts +2 -0
- package/dist/cjs/notes/amount.js +21 -0
- package/dist/cjs/notes/encryption.d.ts +41 -0
- package/dist/cjs/notes/encryption.js +75 -0
- package/dist/cjs/notes/index.d.ts +8 -0
- package/dist/cjs/notes/index.js +24 -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 +20 -0
- package/dist/cjs/notes/recovery.js +48 -0
- package/dist/cjs/notes/selection.d.ts +77 -0
- package/dist/cjs/notes/selection.js +193 -0
- package/dist/cjs/notes/spent.d.ts +60 -0
- package/dist/cjs/notes/spent.js +101 -0
- package/dist/cjs/perps/constants.d.ts +16 -0
- package/dist/cjs/perps/constants.js +52 -0
- package/dist/cjs/perps/index.d.ts +5 -0
- package/dist/cjs/perps/index.js +21 -0
- package/dist/cjs/perps/keys.d.ts +16 -0
- package/dist/cjs/perps/keys.js +43 -0
- package/dist/cjs/perps/pdas.d.ts +29 -0
- package/dist/cjs/perps/pdas.js +55 -0
- package/dist/cjs/perps/relayer.d.ts +9 -0
- package/dist/cjs/perps/relayer.js +35 -0
- package/dist/cjs/perps/types.d.ts +126 -0
- package/dist/cjs/perps/types.js +2 -0
- package/dist/cjs/positions/index.d.ts +4 -0
- package/dist/cjs/positions/index.js +20 -0
- package/dist/cjs/positions/keys.d.ts +29 -0
- package/dist/cjs/positions/keys.js +71 -0
- package/dist/cjs/positions/pdas.d.ts +15 -0
- package/dist/cjs/positions/pdas.js +54 -0
- package/dist/cjs/positions/relayer.d.ts +4 -0
- package/dist/cjs/positions/relayer.js +15 -0
- package/dist/cjs/positions/types.d.ts +97 -0
- package/dist/cjs/positions/types.js +2 -0
- package/dist/cjs/predictions/client.d.ts +41 -0
- package/dist/cjs/predictions/client.js +147 -0
- package/dist/cjs/predictions/index.d.ts +5 -0
- package/dist/cjs/predictions/index.js +21 -0
- package/dist/cjs/predictions/keys.d.ts +14 -0
- package/dist/cjs/predictions/keys.js +40 -0
- package/dist/cjs/predictions/pdas.d.ts +6 -0
- package/dist/cjs/predictions/pdas.js +13 -0
- package/dist/cjs/predictions/relayer.d.ts +3 -0
- package/dist/cjs/predictions/relayer.js +11 -0
- package/dist/cjs/predictions/types.d.ts +178 -0
- package/dist/cjs/predictions/types.js +2 -0
- package/dist/cjs/program.d.ts +2 -0
- package/dist/cjs/program.js +8 -7
- package/dist/cjs/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/proofs/types.js +2 -0
- package/dist/cjs/prover.d.ts +30 -4
- package/dist/cjs/prover.js +118 -49
- package/dist/cjs/relayer/api.d.ts +31 -0
- package/dist/cjs/relayer/api.js +86 -0
- package/dist/cjs/relayer/client.d.ts +73 -0
- package/dist/cjs/relayer/client.js +206 -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 +6 -0
- package/dist/cjs/relayer/index.js +19 -0
- package/dist/cjs/relayer/internal-config.d.ts +36 -0
- package/dist/cjs/relayer/internal-config.js +9 -0
- package/dist/cjs/relayer/internal.d.ts +6 -0
- package/dist/cjs/relayer/internal.js +14 -0
- package/dist/cjs/relayer/transport.d.ts +19 -0
- package/dist/cjs/relayer/transport.js +68 -0
- package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +53 -96
- 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 -11
- 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/events/index.d.ts +6 -0
- package/dist/esm/events/index.js +6 -0
- package/dist/esm/events/parsing.d.ts +25 -0
- package/dist/esm/events/parsing.js +120 -0
- package/dist/esm/events/position.d.ts +26 -0
- package/dist/esm/events/position.js +48 -0
- package/dist/esm/events/recovery.d.ts +87 -0
- package/dist/esm/events/recovery.js +237 -0
- package/dist/esm/events/scanning.d.ts +35 -0
- package/dist/esm/events/scanning.js +92 -0
- package/dist/esm/events/tree.d.ts +27 -0
- package/dist/esm/events/tree.js +58 -0
- package/dist/esm/events/types.d.ts +39 -0
- package/dist/esm/events/types.js +1 -0
- package/dist/esm/events.d.ts +1 -77
- package/dist/esm/events.js +3 -129
- package/dist/esm/identity/encoding.d.ts +9 -0
- package/dist/esm/identity/encoding.js +75 -0
- package/dist/esm/identity/index.d.ts +4 -0
- package/dist/esm/identity/index.js +4 -0
- package/dist/esm/identity/noteKey.d.ts +33 -0
- package/dist/esm/identity/noteKey.js +91 -0
- package/dist/esm/identity/spending.d.ts +18 -0
- package/dist/esm/identity/spending.js +35 -0
- package/dist/esm/identity/viewKey.d.ts +38 -0
- package/dist/esm/identity/viewKey.js +96 -0
- package/dist/esm/idl/index.d.ts +18 -0
- package/dist/esm/idl/index.js +18 -0
- package/dist/esm/idl/privacy_pool.json +9907 -9907
- package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
- package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
- package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
- package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/esm/index.d.ts +9 -3
- package/dist/esm/index.js +10 -3
- package/dist/esm/notes/amount.d.ts +2 -0
- package/dist/esm/notes/amount.js +18 -0
- package/dist/esm/notes/encryption.d.ts +41 -0
- package/dist/esm/notes/encryption.js +67 -0
- package/dist/esm/notes/index.d.ts +8 -0
- package/dist/esm/notes/index.js +8 -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 +20 -0
- package/dist/esm/notes/recovery.js +45 -0
- package/dist/esm/notes/selection.d.ts +77 -0
- package/dist/esm/notes/selection.js +188 -0
- package/dist/esm/notes/spent.d.ts +60 -0
- package/dist/esm/notes/spent.js +96 -0
- package/dist/esm/perps/constants.d.ts +16 -0
- package/dist/esm/perps/constants.js +48 -0
- package/dist/esm/perps/index.d.ts +5 -0
- package/dist/esm/perps/index.js +5 -0
- package/dist/esm/perps/keys.d.ts +16 -0
- package/dist/esm/perps/keys.js +35 -0
- package/dist/esm/perps/pdas.d.ts +29 -0
- package/dist/esm/perps/pdas.js +47 -0
- package/dist/esm/perps/relayer.d.ts +9 -0
- package/dist/esm/perps/relayer.js +25 -0
- package/dist/esm/perps/types.d.ts +126 -0
- package/dist/esm/perps/types.js +1 -0
- package/dist/esm/positions/index.d.ts +4 -0
- package/dist/esm/positions/index.js +4 -0
- package/dist/esm/positions/keys.d.ts +29 -0
- package/dist/esm/positions/keys.js +65 -0
- package/dist/esm/positions/pdas.d.ts +15 -0
- package/dist/esm/positions/pdas.js +44 -0
- package/dist/esm/positions/relayer.d.ts +4 -0
- package/dist/esm/positions/relayer.js +10 -0
- package/dist/esm/positions/types.d.ts +97 -0
- package/dist/esm/positions/types.js +1 -0
- package/dist/esm/predictions/client.d.ts +41 -0
- package/dist/esm/predictions/client.js +141 -0
- package/dist/esm/predictions/index.d.ts +5 -0
- package/dist/esm/predictions/index.js +5 -0
- package/dist/esm/predictions/keys.d.ts +14 -0
- package/dist/esm/predictions/keys.js +33 -0
- package/dist/esm/predictions/pdas.d.ts +6 -0
- package/dist/esm/predictions/pdas.js +10 -0
- package/dist/esm/predictions/relayer.d.ts +3 -0
- package/dist/esm/predictions/relayer.js +7 -0
- package/dist/esm/predictions/types.d.ts +178 -0
- package/dist/esm/predictions/types.js +1 -0
- package/dist/esm/program.d.ts +2 -0
- package/dist/esm/program.js +4 -3
- package/dist/esm/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 +30 -4
- package/dist/esm/prover.js +115 -15
- package/dist/esm/relayer/api.d.ts +31 -0
- package/dist/esm/relayer/api.js +55 -0
- package/dist/esm/relayer/client.d.ts +73 -0
- package/dist/esm/relayer/client.js +199 -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 +6 -0
- package/dist/esm/relayer/index.js +3 -0
- package/dist/esm/relayer/internal-config.d.ts +36 -0
- package/dist/esm/relayer/internal-config.js +6 -0
- package/dist/esm/relayer/internal.d.ts +6 -0
- package/dist/esm/relayer/internal.js +10 -0
- package/dist/esm/relayer/transport.d.ts +19 -0
- package/dist/esm/relayer/transport.js +64 -0
- package/dist/esm/relayer/types.d.ts +275 -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 +3 -5
- 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/identity.d.ts +2 -0
- package/identity.js +3 -0
- package/idl.d.ts +2 -0
- package/idl.js +3 -0
- package/notes.d.ts +2 -0
- package/notes.js +3 -0
- package/package.json +131 -11
- package/perps.d.ts +2 -0
- package/perps.js +3 -0
- package/poseidon.d.ts +2 -2
- package/poseidon.js +2 -3
- package/positions.d.ts +2 -0
- package/positions.js +3 -0
- package/predictions.d.ts +2 -0
- package/predictions.js +3 -0
- package/proof.d.ts +2 -2
- package/proof.js +2 -3
- package/prover.d.ts +2 -2
- package/prover.js +2 -3
- package/relayer.d.ts +2 -0
- package/relayer.js +3 -0
- package/shield.d.ts +2 -2
- package/shield.js +2 -3
- package/transactions.d.ts +2 -0
- package/transactions.js +3 -0
- package/SHIELD_INTEGRATION.md +0 -143
- 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.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/dist/{src/shield → cjs/events}/types.js +0 -0
- /package/dist/{src/idl/privacy_pool.d.ts → cjs/idl/privacy_pool_legacy.d.ts} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Idl, Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { Keypair, PublicKey, type AccountMeta, type TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import type { ExtData, TransactionProofStruct } from "../proofs/types.js";
|
|
4
|
+
import type { NoteCiphers } from "../compactNote.js";
|
|
5
|
+
/** Seeds: ["swap_executor", source_mint, dest_mint, nullifier_0, relayer]. */
|
|
6
|
+
export declare function getSwapExecutorPda(programId: PublicKey, sourceMint: PublicKey, destMint: PublicKey, inputNullifier0: Uint8Array, relayer: PublicKey): PublicKey;
|
|
7
|
+
/** Build `fund_native_source`. It must immediately precede `transact_swap`. */
|
|
8
|
+
export declare function fundNativeSource<T extends Idl>(params: {
|
|
9
|
+
program: Program<T>;
|
|
10
|
+
relayer: {
|
|
11
|
+
publicKey: PublicKey;
|
|
12
|
+
};
|
|
13
|
+
sourceMint: PublicKey;
|
|
14
|
+
destMint: PublicKey;
|
|
15
|
+
inputNullifier0: Uint8Array;
|
|
16
|
+
swapAmount: bigint;
|
|
17
|
+
/** Wrapped-native mint used by the DEX. Defaults to canonical WSOL. */
|
|
18
|
+
sourceMintAccount?: PublicKey;
|
|
19
|
+
}): Promise<TransactionInstruction>;
|
|
20
|
+
export type SwapProofStruct = TransactionProofStruct;
|
|
21
|
+
/** Fields in the current IDL's `SwapParams` struct. */
|
|
22
|
+
export type SwapParams = {
|
|
23
|
+
minAmountOut: bigint;
|
|
24
|
+
deadline: bigint;
|
|
25
|
+
destAmount: bigint;
|
|
26
|
+
/** SHA-256 of the exact DEX instruction bytes passed as `swapData`. */
|
|
27
|
+
swapDataHash: Uint8Array;
|
|
28
|
+
};
|
|
29
|
+
export type TransactSwapParams<T extends Idl = Idl> = {
|
|
30
|
+
program: Program<T>;
|
|
31
|
+
relayer: {
|
|
32
|
+
publicKey: PublicKey;
|
|
33
|
+
};
|
|
34
|
+
sourceMint: PublicKey;
|
|
35
|
+
destMint: PublicKey;
|
|
36
|
+
sourceRoot: Uint8Array;
|
|
37
|
+
sourceTreeId: number;
|
|
38
|
+
destTreeId: number;
|
|
39
|
+
inputNullifiers: [Uint8Array, Uint8Array];
|
|
40
|
+
/** Output 0 is source-mint change; output 1 is the destination note. */
|
|
41
|
+
outputCommitments: [Uint8Array, Uint8Array];
|
|
42
|
+
proof: SwapProofStruct;
|
|
43
|
+
swapParams: SwapParams;
|
|
44
|
+
swapAmount: bigint;
|
|
45
|
+
/** Exact raw data from the DEX/Jupiter instruction. */
|
|
46
|
+
swapData: Uint8Array | Buffer;
|
|
47
|
+
extData: ExtData;
|
|
48
|
+
noteCiphers?: NoteCiphers | null;
|
|
49
|
+
sourceVaultTokenAccount: PublicKey;
|
|
50
|
+
/** Actual DEX source mint (WSOL for the native-SOL pool sentinel). */
|
|
51
|
+
sourceMintAccount: PublicKey;
|
|
52
|
+
destVaultTokenAccount: PublicKey;
|
|
53
|
+
/** Actual DEX destination mint (WSOL for the native-SOL pool sentinel). */
|
|
54
|
+
destMintAccount: PublicKey;
|
|
55
|
+
relayerTokenAccount: PublicKey;
|
|
56
|
+
swapProgram: PublicKey;
|
|
57
|
+
jupiterEventAuthority: PublicKey;
|
|
58
|
+
/** Preserve the DEX instruction's account order and duplicates exactly. */
|
|
59
|
+
remainingAccounts?: AccountMeta[];
|
|
60
|
+
};
|
|
61
|
+
/** Build the current IDL's `transact_swap` instruction without submitting it. */
|
|
62
|
+
export declare function buildTransactSwapInstruction<T extends Idl>(params: TransactSwapParams<T>): Promise<TransactionInstruction>;
|
|
63
|
+
/** Build the atomic instruction sequence, including native-source funding. */
|
|
64
|
+
export declare function buildPrivateSwapInstructions<T extends Idl>(params: TransactSwapParams<T>): Promise<TransactionInstruction[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Submit the parity-correct instructions as a legacy transaction. For Jupiter
|
|
67
|
+
* routes, prefer `buildPrivateSwapInstructions` and compile v0 with route ALTs.
|
|
68
|
+
*/
|
|
69
|
+
export declare function transactSwap<T extends Idl>(params: TransactSwapParams<T> & {
|
|
70
|
+
relayer: Keypair;
|
|
71
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, Transaction, } from "@solana/web3.js";
|
|
3
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, TOKEN_PROGRAM_ID, getAssociatedTokenAddress, } from "@solana/spl-token";
|
|
4
|
+
import { NATIVE_SOL_MINT } from "../config.js";
|
|
5
|
+
import { withRpcRetry } from "../retry.js";
|
|
6
|
+
import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../accounts/pdas.js";
|
|
7
|
+
const { BN } = anchor;
|
|
8
|
+
/** Seeds: ["swap_executor", source_mint, dest_mint, nullifier_0, relayer]. */
|
|
9
|
+
export function getSwapExecutorPda(programId, sourceMint, destMint, inputNullifier0, relayer) {
|
|
10
|
+
const [executor] = PublicKey.findProgramAddressSync([
|
|
11
|
+
Buffer.from("swap_executor"),
|
|
12
|
+
sourceMint.toBuffer(),
|
|
13
|
+
destMint.toBuffer(),
|
|
14
|
+
inputNullifier0,
|
|
15
|
+
relayer.toBuffer(),
|
|
16
|
+
], programId);
|
|
17
|
+
return executor;
|
|
18
|
+
}
|
|
19
|
+
/** Build `fund_native_source`. It must immediately precede `transact_swap`. */
|
|
20
|
+
export async function fundNativeSource(params) {
|
|
21
|
+
const { program, relayer, sourceMint, destMint, inputNullifier0, swapAmount, sourceMintAccount = NATIVE_MINT, } = params;
|
|
22
|
+
const { vault: sourceVault, config: sourceConfig } = getPoolPdas(program.programId, sourceMint);
|
|
23
|
+
const executor = getSwapExecutorPda(program.programId, sourceMint, destMint, inputNullifier0, relayer.publicKey);
|
|
24
|
+
const executorSourceToken = await getAssociatedTokenAddress(sourceMintAccount, executor, true);
|
|
25
|
+
return program.methods
|
|
26
|
+
.fundNativeSource(sourceMint, destMint, Array.from(inputNullifier0), new BN(swapAmount.toString()))
|
|
27
|
+
.accountsStrict({
|
|
28
|
+
executor,
|
|
29
|
+
executorSourceToken,
|
|
30
|
+
sourceVault,
|
|
31
|
+
sourceConfig,
|
|
32
|
+
sourceMintAccount,
|
|
33
|
+
relayer: relayer.publicKey,
|
|
34
|
+
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
35
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
36
|
+
systemProgram: SystemProgram.programId,
|
|
37
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
38
|
+
})
|
|
39
|
+
.instruction();
|
|
40
|
+
}
|
|
41
|
+
function encodeNoteCiphers(noteCiphers) {
|
|
42
|
+
return noteCiphers
|
|
43
|
+
? {
|
|
44
|
+
note0EphemeralKey: Array.from(noteCiphers.note0EphemeralKey),
|
|
45
|
+
note0Encrypted: Array.from(noteCiphers.note0Encrypted),
|
|
46
|
+
note0ViewTag: noteCiphers.note0ViewTag,
|
|
47
|
+
note1EphemeralKey: Array.from(noteCiphers.note1EphemeralKey),
|
|
48
|
+
note1Encrypted: Array.from(noteCiphers.note1Encrypted),
|
|
49
|
+
note1ViewTag: noteCiphers.note1ViewTag,
|
|
50
|
+
}
|
|
51
|
+
: null;
|
|
52
|
+
}
|
|
53
|
+
/** Build the current IDL's `transact_swap` instruction without submitting it. */
|
|
54
|
+
export async function buildTransactSwapInstruction(params) {
|
|
55
|
+
const { program, relayer, sourceMint, destMint, sourceRoot, sourceTreeId, destTreeId, inputNullifiers, outputCommitments, proof, swapParams, swapAmount, swapData, extData, noteCiphers = null, sourceVaultTokenAccount, sourceMintAccount, destVaultTokenAccount, destMintAccount, relayerTokenAccount, swapProgram, jupiterEventAuthority, remainingAccounts = [], } = params;
|
|
56
|
+
if (!extData.relayer.equals(relayer.publicKey)) {
|
|
57
|
+
throw new Error("extData.relayer must match the relayer account");
|
|
58
|
+
}
|
|
59
|
+
if (swapParams.deadline <= 0n) {
|
|
60
|
+
throw new Error("swapParams.deadline must be a positive Unix timestamp");
|
|
61
|
+
}
|
|
62
|
+
if (swapParams.swapDataHash.length !== 32) {
|
|
63
|
+
throw new Error("swapParams.swapDataHash must be 32 bytes");
|
|
64
|
+
}
|
|
65
|
+
const { config: sourceConfig, vault: sourceVault, nullifiers: sourceNullifiers, } = getPoolPdas(program.programId, sourceMint);
|
|
66
|
+
const { config: destConfig, vault: destVault } = getPoolPdas(program.programId, destMint);
|
|
67
|
+
const globalConfig = getGlobalConfigPda(program.programId);
|
|
68
|
+
const sourceTree = getNoteTreePda(program.programId, sourceMint, sourceTreeId);
|
|
69
|
+
const destTree = getNoteTreePda(program.programId, destMint, destTreeId);
|
|
70
|
+
const sourceNullifierMarker0 = getNullifierMarkerPda(program.programId, sourceMint, inputNullifiers[0]);
|
|
71
|
+
const sourceNullifierMarker1 = getNullifierMarkerPda(program.programId, sourceMint, inputNullifiers[1]);
|
|
72
|
+
const executor = getSwapExecutorPda(program.programId, sourceMint, destMint, inputNullifiers[0], relayer.publicKey);
|
|
73
|
+
const executorSourceToken = await getAssociatedTokenAddress(sourceMintAccount, executor, true);
|
|
74
|
+
const executorDestToken = await getAssociatedTokenAddress(destMintAccount, executor, true);
|
|
75
|
+
let method = program.methods
|
|
76
|
+
.transactSwap(sourceTreeId, sourceMint, Array.from(inputNullifiers[0]), Array.from(inputNullifiers[1]), destTreeId, destMint, { proofA: proof.proofA, proofB: proof.proofB, proofC: proof.proofC }, Array.from(sourceRoot), Array.from(outputCommitments[0]), Array.from(outputCommitments[1]), {
|
|
77
|
+
minAmountOut: new BN(swapParams.minAmountOut.toString()),
|
|
78
|
+
deadline: new BN(swapParams.deadline.toString()),
|
|
79
|
+
destAmount: new BN(swapParams.destAmount.toString()),
|
|
80
|
+
swapDataHash: Array.from(swapParams.swapDataHash),
|
|
81
|
+
}, new BN(swapAmount.toString()), Buffer.from(swapData), {
|
|
82
|
+
recipient: extData.recipient,
|
|
83
|
+
relayer: extData.relayer,
|
|
84
|
+
fee: new BN(extData.fee.toString()),
|
|
85
|
+
refund: new BN(extData.refund.toString()),
|
|
86
|
+
claimant: extData.claimant,
|
|
87
|
+
}, encodeNoteCiphers(noteCiphers))
|
|
88
|
+
.accountsStrict({
|
|
89
|
+
sourceConfig,
|
|
90
|
+
globalConfig,
|
|
91
|
+
sourceVault,
|
|
92
|
+
sourceTree,
|
|
93
|
+
sourceNullifiers,
|
|
94
|
+
sourceNullifierMarker0,
|
|
95
|
+
sourceNullifierMarker1,
|
|
96
|
+
sourceVaultTokenAccount,
|
|
97
|
+
sourceMintAccount,
|
|
98
|
+
destConfig,
|
|
99
|
+
destVault,
|
|
100
|
+
destTree,
|
|
101
|
+
destVaultTokenAccount,
|
|
102
|
+
destMintAccount,
|
|
103
|
+
executor,
|
|
104
|
+
executorSourceToken,
|
|
105
|
+
executorDestToken,
|
|
106
|
+
relayer: relayer.publicKey,
|
|
107
|
+
relayerTokenAccount,
|
|
108
|
+
swapProgram,
|
|
109
|
+
jupiterEventAuthority,
|
|
110
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
111
|
+
systemProgram: SystemProgram.programId,
|
|
112
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
113
|
+
});
|
|
114
|
+
// Jupiter account order and duplicates are part of the CPI contract.
|
|
115
|
+
method = method.remainingAccounts(remainingAccounts);
|
|
116
|
+
return method.instruction();
|
|
117
|
+
}
|
|
118
|
+
/** Build the atomic instruction sequence, including native-source funding. */
|
|
119
|
+
export async function buildPrivateSwapInstructions(params) {
|
|
120
|
+
const instructions = [];
|
|
121
|
+
if (params.sourceMint.equals(NATIVE_SOL_MINT)) {
|
|
122
|
+
instructions.push(await fundNativeSource({
|
|
123
|
+
program: params.program,
|
|
124
|
+
relayer: params.relayer,
|
|
125
|
+
sourceMint: params.sourceMint,
|
|
126
|
+
destMint: params.destMint,
|
|
127
|
+
inputNullifier0: params.inputNullifiers[0],
|
|
128
|
+
swapAmount: params.swapAmount,
|
|
129
|
+
sourceMintAccount: params.sourceMintAccount,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
instructions.push(await buildTransactSwapInstruction(params));
|
|
133
|
+
return instructions;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Submit the parity-correct instructions as a legacy transaction. For Jupiter
|
|
137
|
+
* routes, prefer `buildPrivateSwapInstructions` and compile v0 with route ALTs.
|
|
138
|
+
*/
|
|
139
|
+
export async function transactSwap(params) {
|
|
140
|
+
const instructions = await buildPrivateSwapInstructions(params);
|
|
141
|
+
const transaction = new Transaction().add(...instructions);
|
|
142
|
+
const provider = params.program.provider;
|
|
143
|
+
return withRpcRetry(() => provider.sendAndConfirm(transaction, [params.relayer]));
|
|
144
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Program, Idl } from "@coral-xyz/anchor";
|
|
2
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { ExtData, TransactionProofStruct } from "../proofs/types.js";
|
|
4
|
+
import type { NoteCiphers } from "../compactNote.js";
|
|
5
|
+
/**
|
|
6
|
+
* Execute a transaction on the privacy pool.
|
|
7
|
+
* This is the low-level function that calls the on-chain `transact` instruction.
|
|
8
|
+
*
|
|
9
|
+
* @param publicAmount - Positive for deposits, negative for withdrawals, 0 for transfers
|
|
10
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
11
|
+
* @param outputTreeId - The tree ID where output commitments will be inserted
|
|
12
|
+
*/
|
|
13
|
+
export declare function transact<T extends Idl>(params: {
|
|
14
|
+
program: Program<T>;
|
|
15
|
+
relayer: Keypair;
|
|
16
|
+
recipient: PublicKey;
|
|
17
|
+
mintAddress: PublicKey;
|
|
18
|
+
root: Uint8Array;
|
|
19
|
+
inputTreeId: number;
|
|
20
|
+
outputTreeId: number;
|
|
21
|
+
publicAmount: bigint;
|
|
22
|
+
inputNullifiers: [Uint8Array, Uint8Array];
|
|
23
|
+
outputCommitments: [Uint8Array, Uint8Array];
|
|
24
|
+
extData: ExtData;
|
|
25
|
+
proof: TransactionProofStruct;
|
|
26
|
+
/** Unix timestamp after which the tx is invalid. Defaults to 10 minutes from build time. */
|
|
27
|
+
deadline?: bigint;
|
|
28
|
+
/** Optional compact recovery payload emitted with the two output commitments. */
|
|
29
|
+
noteCiphers?: NoteCiphers | null;
|
|
30
|
+
vaultTokenAccount?: PublicKey;
|
|
31
|
+
userTokenAccount?: PublicKey;
|
|
32
|
+
recipientTokenAccount?: PublicKey;
|
|
33
|
+
relayerTokenAccount?: PublicKey;
|
|
34
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
3
|
+
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";
|
|
4
|
+
import { computeExtDataHash } from "../proofs/transaction.js";
|
|
5
|
+
import { NATIVE_SOL_MINT } from "../config.js";
|
|
6
|
+
import { withRpcRetry } from "../retry.js";
|
|
7
|
+
import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../accounts/pdas.js";
|
|
8
|
+
// Anchor is CJS and does not expose BN as a detectable Node ESM named export.
|
|
9
|
+
const { BN } = anchor;
|
|
10
|
+
// -----------------------------------------------------------------------------
|
|
11
|
+
// Main Transaction Instruction
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Execute a transaction on the privacy pool.
|
|
15
|
+
* This is the low-level function that calls the on-chain `transact` instruction.
|
|
16
|
+
*
|
|
17
|
+
* @param publicAmount - Positive for deposits, negative for withdrawals, 0 for transfers
|
|
18
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
19
|
+
* @param outputTreeId - The tree ID where output commitments will be inserted
|
|
20
|
+
*/
|
|
21
|
+
export async function transact(params) {
|
|
22
|
+
const { program, relayer, recipient, mintAddress, root, inputTreeId, outputTreeId, publicAmount, inputNullifiers, outputCommitments, extData, proof, deadline = BigInt(Math.floor(Date.now() / 1000) + 600), noteCiphers = null, vaultTokenAccount, userTokenAccount, recipientTokenAccount, relayerTokenAccount, } = params;
|
|
23
|
+
if (!recipient.equals(extData.recipient)) {
|
|
24
|
+
throw new Error("recipient account must match extData.recipient");
|
|
25
|
+
}
|
|
26
|
+
if (!relayer.publicKey.equals(extData.relayer)) {
|
|
27
|
+
throw new Error("relayer account must match extData.relayer");
|
|
28
|
+
}
|
|
29
|
+
if (deadline <= 0n) {
|
|
30
|
+
throw new Error("deadline must be a positive Unix timestamp");
|
|
31
|
+
}
|
|
32
|
+
if (publicAmount === 0n && (extData.fee !== 0n || extData.refund !== 0n)) {
|
|
33
|
+
throw new Error("Private transfers require extData fee and refund to be zero");
|
|
34
|
+
}
|
|
35
|
+
const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
|
|
36
|
+
const globalConfig = getGlobalConfigPda(program.programId);
|
|
37
|
+
const inputTree = getNoteTreePda(program.programId, mintAddress, inputTreeId);
|
|
38
|
+
const outputTree = getNoteTreePda(program.programId, mintAddress, outputTreeId);
|
|
39
|
+
// Nullifier markers are global (no tree_id) to prevent cross-tree double-spend
|
|
40
|
+
const nullifierMarker0 = getNullifierMarkerPda(program.programId, mintAddress, inputNullifiers[0]);
|
|
41
|
+
const nullifierMarker1 = getNullifierMarkerPda(program.programId, mintAddress, inputNullifiers[1]);
|
|
42
|
+
const extDataHash = computeExtDataHash(extData);
|
|
43
|
+
const isNativeSol = mintAddress.equals(NATIVE_SOL_MINT);
|
|
44
|
+
// For SPL tokens, resolve token accounts
|
|
45
|
+
let vaultTA = vaultTokenAccount;
|
|
46
|
+
let userTA = userTokenAccount;
|
|
47
|
+
let recipientTA = recipientTokenAccount;
|
|
48
|
+
let relayerTA = relayerTokenAccount;
|
|
49
|
+
if (!isNativeSol) {
|
|
50
|
+
if (!vaultTA) {
|
|
51
|
+
vaultTA = await getAssociatedTokenAddress(mintAddress, vault, true);
|
|
52
|
+
}
|
|
53
|
+
if (!userTA) {
|
|
54
|
+
userTA = await getAssociatedTokenAddress(mintAddress, relayer.publicKey);
|
|
55
|
+
}
|
|
56
|
+
if (!recipientTA) {
|
|
57
|
+
recipientTA = await getAssociatedTokenAddress(mintAddress, recipient);
|
|
58
|
+
}
|
|
59
|
+
if (!relayerTA) {
|
|
60
|
+
relayerTA = await getAssociatedTokenAddress(mintAddress, relayer.publicKey);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
vaultTA ?? (vaultTA = relayer.publicKey);
|
|
65
|
+
userTA ?? (userTA = relayer.publicKey);
|
|
66
|
+
recipientTA ?? (recipientTA = relayer.publicKey);
|
|
67
|
+
relayerTA ?? (relayerTA = relayer.publicKey);
|
|
68
|
+
}
|
|
69
|
+
const tx = program.methods
|
|
70
|
+
.transact(Array.from(root), inputTreeId, outputTreeId, new BN(publicAmount.toString()), Array.from(extDataHash), mintAddress, Array.from(inputNullifiers[0]), Array.from(inputNullifiers[1]), Array.from(outputCommitments[0]), Array.from(outputCommitments[1]), new BN(deadline.toString()), {
|
|
71
|
+
recipient: extData.recipient,
|
|
72
|
+
relayer: extData.relayer,
|
|
73
|
+
fee: new BN(extData.fee.toString()),
|
|
74
|
+
refund: new BN(extData.refund.toString()),
|
|
75
|
+
claimant: extData.claimant,
|
|
76
|
+
}, {
|
|
77
|
+
proofA: proof.proofA,
|
|
78
|
+
proofB: proof.proofB,
|
|
79
|
+
proofC: proof.proofC,
|
|
80
|
+
}, noteCiphers
|
|
81
|
+
? {
|
|
82
|
+
note0EphemeralKey: Array.from(noteCiphers.note0EphemeralKey),
|
|
83
|
+
note0Encrypted: Array.from(noteCiphers.note0Encrypted),
|
|
84
|
+
note0ViewTag: noteCiphers.note0ViewTag,
|
|
85
|
+
note1EphemeralKey: Array.from(noteCiphers.note1EphemeralKey),
|
|
86
|
+
note1Encrypted: Array.from(noteCiphers.note1Encrypted),
|
|
87
|
+
note1ViewTag: noteCiphers.note1ViewTag,
|
|
88
|
+
}
|
|
89
|
+
: null)
|
|
90
|
+
.accountsStrict({
|
|
91
|
+
config,
|
|
92
|
+
globalConfig,
|
|
93
|
+
vault,
|
|
94
|
+
inputTree,
|
|
95
|
+
outputTree,
|
|
96
|
+
nullifiers,
|
|
97
|
+
nullifierMarker0,
|
|
98
|
+
nullifierMarker1,
|
|
99
|
+
relayer: relayer.publicKey,
|
|
100
|
+
recipient,
|
|
101
|
+
vaultTokenAccount: vaultTA,
|
|
102
|
+
userTokenAccount: userTA,
|
|
103
|
+
recipientTokenAccount: recipientTA,
|
|
104
|
+
relayerTokenAccount: relayerTA,
|
|
105
|
+
tokenProgram: isNativeSol ? SystemProgram.programId : TOKEN_PROGRAM_ID,
|
|
106
|
+
systemProgram: SystemProgram.programId,
|
|
107
|
+
})
|
|
108
|
+
.signers([relayer]);
|
|
109
|
+
return withRpcRetry(() => tx.rpc());
|
|
110
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Program, Idl } from "@coral-xyz/anchor";
|
|
2
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { TransactionProofBuilder } from "../proofs/types.js";
|
|
4
|
+
import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
|
|
5
|
+
import { MerkleTree } from "../merkle.js";
|
|
6
|
+
import { type NoteCiphers } from "../compactNote.js";
|
|
7
|
+
export type TransferResult = {
|
|
8
|
+
/** Output UTXOs created by the transfer */
|
|
9
|
+
outputUTXOs: [SerializedUTXO, SerializedUTXO];
|
|
10
|
+
/** Leaf indices where the UTXOs were inserted */
|
|
11
|
+
leafIndices: [number, number];
|
|
12
|
+
/** New Merkle root after insertion */
|
|
13
|
+
root: Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Execute a private transfer within the pool.
|
|
17
|
+
*
|
|
18
|
+
* For transfers, the publicAmount is 0 (no funds enter or leave the pool).
|
|
19
|
+
* Input amounts must equal output amounts.
|
|
20
|
+
*
|
|
21
|
+
* @param inputUTXOs - The UTXOs being spent
|
|
22
|
+
* @param outputPubkeys - UTXO public keys for the recipients
|
|
23
|
+
* @param outputAmounts - Amounts for each output (must sum to input total)
|
|
24
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
25
|
+
* @param outputTreeId - The tree ID where output commitments will be inserted
|
|
26
|
+
*/
|
|
27
|
+
export declare function privateTransfer<T extends Idl>(params: {
|
|
28
|
+
program: Program<T>;
|
|
29
|
+
relayer: Keypair;
|
|
30
|
+
mintAddress: PublicKey;
|
|
31
|
+
inputUTXOs: [InputUTXO, InputUTXO];
|
|
32
|
+
outputPubkeys: [bigint, bigint];
|
|
33
|
+
outputAmounts: [bigint, bigint];
|
|
34
|
+
root: Uint8Array;
|
|
35
|
+
inputTreeId: number;
|
|
36
|
+
outputTreeId: number;
|
|
37
|
+
tree: MerkleTree;
|
|
38
|
+
proofBuilder: TransactionProofBuilder;
|
|
39
|
+
/** Must be zero: the program rejects fees on publicAmount=0 transfers. */
|
|
40
|
+
fee?: bigint;
|
|
41
|
+
deadline?: bigint;
|
|
42
|
+
/** Public recipient account committed in ExtData (no funds are sent to it). */
|
|
43
|
+
externalRecipient?: PublicKey;
|
|
44
|
+
/** Wallet keys used to encrypt output notes for on-chain recovery. */
|
|
45
|
+
noteRecipientWallets?: [
|
|
46
|
+
PublicKey | Uint8Array | null,
|
|
47
|
+
PublicKey | Uint8Array | null
|
|
48
|
+
];
|
|
49
|
+
/** Prebuilt note ciphers. Takes precedence over noteRecipientWallets. */
|
|
50
|
+
noteCiphers?: NoteCiphers | null;
|
|
51
|
+
}): Promise<TransferResult>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
|
2
|
+
import { prepareTransactionInputs } from "../proofs/transaction.js";
|
|
3
|
+
import { encodeSnarkjsProofToTransactionProof } from "../proofs/encoding.js";
|
|
4
|
+
import { createUTXO } from "../notes/model.js";
|
|
5
|
+
import { transact } from "./transact.js";
|
|
6
|
+
import { bigIntToBytesBE } from "../poseidon.js";
|
|
7
|
+
import { createNoteCiphers, } from "../compactNote.js";
|
|
8
|
+
/**
|
|
9
|
+
* Execute a private transfer within the pool.
|
|
10
|
+
*
|
|
11
|
+
* For transfers, the publicAmount is 0 (no funds enter or leave the pool).
|
|
12
|
+
* Input amounts must equal output amounts.
|
|
13
|
+
*
|
|
14
|
+
* @param inputUTXOs - The UTXOs being spent
|
|
15
|
+
* @param outputPubkeys - UTXO public keys for the recipients
|
|
16
|
+
* @param outputAmounts - Amounts for each output (must sum to input total)
|
|
17
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
18
|
+
* @param outputTreeId - The tree ID where output commitments will be inserted
|
|
19
|
+
*/
|
|
20
|
+
export async function privateTransfer(params) {
|
|
21
|
+
const { program, relayer, mintAddress, inputUTXOs, outputPubkeys, outputAmounts, root, inputTreeId, outputTreeId, tree, proofBuilder, fee = 0n, deadline = BigInt(Math.floor(Date.now() / 1000) + 600), externalRecipient = Keypair.generate().publicKey, noteRecipientWallets, noteCiphers, } = params;
|
|
22
|
+
if (fee !== 0n) {
|
|
23
|
+
throw new Error("Private transact transfers require fee=0; represent any relayer fee in the output amounts");
|
|
24
|
+
}
|
|
25
|
+
const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
|
|
26
|
+
const totalOutput = outputAmounts[0] + outputAmounts[1];
|
|
27
|
+
if (totalInput !== totalOutput) {
|
|
28
|
+
throw new Error(`Balance mismatch: inputs=${totalInput}, outputs=${totalOutput}`);
|
|
29
|
+
}
|
|
30
|
+
const outputUTXO0 = createUTXO({
|
|
31
|
+
amount: outputAmounts[0],
|
|
32
|
+
pubkey: outputPubkeys[0],
|
|
33
|
+
mintAddress,
|
|
34
|
+
});
|
|
35
|
+
const outputUTXO1 = createUTXO({
|
|
36
|
+
amount: outputAmounts[1],
|
|
37
|
+
pubkey: outputPubkeys[1],
|
|
38
|
+
mintAddress,
|
|
39
|
+
});
|
|
40
|
+
const outputUTXOs = [
|
|
41
|
+
outputUTXO0,
|
|
42
|
+
outputUTXO1,
|
|
43
|
+
];
|
|
44
|
+
const extData = {
|
|
45
|
+
recipient: externalRecipient,
|
|
46
|
+
relayer: relayer.publicKey,
|
|
47
|
+
fee: 0n,
|
|
48
|
+
refund: 0n,
|
|
49
|
+
claimant: SystemProgram.programId,
|
|
50
|
+
};
|
|
51
|
+
// publicAmount is 0 for transfers
|
|
52
|
+
const publicAmount = 0n;
|
|
53
|
+
const circuitInputs = prepareTransactionInputs({
|
|
54
|
+
inputUTXOs,
|
|
55
|
+
outputUTXOs,
|
|
56
|
+
root,
|
|
57
|
+
publicAmount,
|
|
58
|
+
extData,
|
|
59
|
+
mintAddress,
|
|
60
|
+
});
|
|
61
|
+
const rawProof = await proofBuilder(circuitInputs);
|
|
62
|
+
const proof = encodeSnarkjsProofToTransactionProof(rawProof);
|
|
63
|
+
const walletBytes = (wallet) => wallet instanceof PublicKey ? wallet.toBytes() : wallet;
|
|
64
|
+
const transferNoteCiphers = noteCiphers ??
|
|
65
|
+
(noteRecipientWallets
|
|
66
|
+
? createNoteCiphers(noteRecipientWallets[0]
|
|
67
|
+
? {
|
|
68
|
+
recipientWalletPubkey: walletBytes(noteRecipientWallets[0]),
|
|
69
|
+
blinding: bigIntToBytesBE(outputUTXOs[0].blinding),
|
|
70
|
+
amount: outputUTXOs[0].amount,
|
|
71
|
+
}
|
|
72
|
+
: null, noteRecipientWallets[1]
|
|
73
|
+
? {
|
|
74
|
+
recipientWalletPubkey: walletBytes(noteRecipientWallets[1]),
|
|
75
|
+
blinding: bigIntToBytesBE(outputUTXOs[1].blinding),
|
|
76
|
+
amount: outputUTXOs[1].amount,
|
|
77
|
+
}
|
|
78
|
+
: null)
|
|
79
|
+
: null);
|
|
80
|
+
await transact({
|
|
81
|
+
program,
|
|
82
|
+
relayer,
|
|
83
|
+
recipient: externalRecipient,
|
|
84
|
+
mintAddress,
|
|
85
|
+
root,
|
|
86
|
+
inputTreeId,
|
|
87
|
+
outputTreeId,
|
|
88
|
+
publicAmount,
|
|
89
|
+
inputNullifiers: circuitInputs.inputNullifiers,
|
|
90
|
+
outputCommitments: circuitInputs.outputCommitments,
|
|
91
|
+
extData,
|
|
92
|
+
proof,
|
|
93
|
+
deadline,
|
|
94
|
+
noteCiphers: transferNoteCiphers,
|
|
95
|
+
});
|
|
96
|
+
const { index: outIdx0 } = tree.insert(outputUTXOs[0].commitment);
|
|
97
|
+
const { index: outIdx1, root: newRoot } = tree.insert(outputUTXOs[1].commitment);
|
|
98
|
+
return {
|
|
99
|
+
outputUTXOs,
|
|
100
|
+
leafIndices: [outIdx0, outIdx1],
|
|
101
|
+
root: newRoot,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Program, Idl } from "@coral-xyz/anchor";
|
|
2
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { TransactionProofBuilder } from "../proofs/types.js";
|
|
4
|
+
import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
|
|
5
|
+
import { MerkleTree } from "../merkle.js";
|
|
6
|
+
import { type NoteCiphers } from "../compactNote.js";
|
|
7
|
+
export type WithdrawResult = {
|
|
8
|
+
/** Change UTXO (remaining balance) */
|
|
9
|
+
changeUTXO: SerializedUTXO;
|
|
10
|
+
/** Leaf index of the change UTXO */
|
|
11
|
+
leafIndex: number;
|
|
12
|
+
/** New Merkle root after insertion */
|
|
13
|
+
root: Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Withdraw funds from the privacy pool.
|
|
17
|
+
*
|
|
18
|
+
* For withdrawals, we spend input UTXOs and create change output UTXOs.
|
|
19
|
+
* The publicAmount is negative (funds flowing out).
|
|
20
|
+
*
|
|
21
|
+
* @param withdrawAmount - Amount to withdraw in lamports/token units
|
|
22
|
+
* @param inputUTXOs - The UTXOs being spent
|
|
23
|
+
* @param changePubkey - UTXO public key for the change output
|
|
24
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
25
|
+
* @param outputTreeId - The tree ID where change outputs will be inserted
|
|
26
|
+
*/
|
|
27
|
+
export declare function withdraw<T extends Idl>(params: {
|
|
28
|
+
program: Program<T>;
|
|
29
|
+
relayer: Keypair;
|
|
30
|
+
recipient: PublicKey;
|
|
31
|
+
mintAddress: PublicKey;
|
|
32
|
+
inputUTXOs: [InputUTXO, InputUTXO];
|
|
33
|
+
changePubkey: bigint;
|
|
34
|
+
withdrawAmount: bigint;
|
|
35
|
+
fee: bigint;
|
|
36
|
+
refund: bigint;
|
|
37
|
+
root: Uint8Array;
|
|
38
|
+
inputTreeId: number;
|
|
39
|
+
outputTreeId: number;
|
|
40
|
+
tree: MerkleTree;
|
|
41
|
+
proofBuilder: TransactionProofBuilder;
|
|
42
|
+
/** When true, the fee is debited in addition to withdrawAmount. */
|
|
43
|
+
feeOnTop?: boolean;
|
|
44
|
+
deadline?: bigint;
|
|
45
|
+
/** Solana wallet key used to encrypt the change note for chain recovery. */
|
|
46
|
+
changeNoteRecipientWallet?: PublicKey | Uint8Array;
|
|
47
|
+
/** Prebuilt recovery payload. Takes precedence over changeNoteRecipientWallet. */
|
|
48
|
+
noteCiphers?: NoteCiphers | null;
|
|
49
|
+
}): Promise<WithdrawResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Result of a private transfer operation.
|
|
52
|
+
*/
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { PublicKey, SystemProgram } from "@solana/web3.js";
|
|
2
|
+
import { prepareTransactionInputs } from "../proofs/transaction.js";
|
|
3
|
+
import { encodeSnarkjsProofToTransactionProof } from "../proofs/encoding.js";
|
|
4
|
+
import { createUTXO, generateKeypair } from "../notes/model.js";
|
|
5
|
+
import { transact } from "./transact.js";
|
|
6
|
+
import { bigIntToBytesBE } from "../poseidon.js";
|
|
7
|
+
import { createNoteCiphers, } from "../compactNote.js";
|
|
8
|
+
/**
|
|
9
|
+
* Withdraw funds from the privacy pool.
|
|
10
|
+
*
|
|
11
|
+
* For withdrawals, we spend input UTXOs and create change output UTXOs.
|
|
12
|
+
* The publicAmount is negative (funds flowing out).
|
|
13
|
+
*
|
|
14
|
+
* @param withdrawAmount - Amount to withdraw in lamports/token units
|
|
15
|
+
* @param inputUTXOs - The UTXOs being spent
|
|
16
|
+
* @param changePubkey - UTXO public key for the change output
|
|
17
|
+
* @param inputTreeId - The tree ID where input UTXOs are located
|
|
18
|
+
* @param outputTreeId - The tree ID where change outputs will be inserted
|
|
19
|
+
*/
|
|
20
|
+
export async function withdraw(params) {
|
|
21
|
+
const { program, relayer, recipient, mintAddress, inputUTXOs, changePubkey, withdrawAmount, fee, refund, root, inputTreeId, outputTreeId, tree, proofBuilder, feeOnTop = false, deadline = BigInt(Math.floor(Date.now() / 1000) + 600), changeNoteRecipientWallet, noteCiphers, } = params;
|
|
22
|
+
const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
|
|
23
|
+
const outflowAmount = feeOnTop ? withdrawAmount + fee : withdrawAmount;
|
|
24
|
+
const changeAmount = totalInput - outflowAmount;
|
|
25
|
+
if (withdrawAmount <= 0n) {
|
|
26
|
+
throw new Error("Withdrawal amount must be positive");
|
|
27
|
+
}
|
|
28
|
+
if (fee < 0n || refund < 0n || fee + refund > outflowAmount) {
|
|
29
|
+
throw new Error("Withdrawal fee and refund must fit within the public outflow");
|
|
30
|
+
}
|
|
31
|
+
if (changeAmount < 0n) {
|
|
32
|
+
throw new Error("Insufficient input balance for withdrawal");
|
|
33
|
+
}
|
|
34
|
+
const changeUTXO = createUTXO({
|
|
35
|
+
amount: changeAmount,
|
|
36
|
+
pubkey: changePubkey,
|
|
37
|
+
mintAddress,
|
|
38
|
+
});
|
|
39
|
+
const zeroUTXO = createUTXO({
|
|
40
|
+
amount: 0n,
|
|
41
|
+
pubkey: generateKeypair().publicKey,
|
|
42
|
+
mintAddress,
|
|
43
|
+
});
|
|
44
|
+
const outputUTXOs = [changeUTXO, zeroUTXO];
|
|
45
|
+
const extData = {
|
|
46
|
+
recipient,
|
|
47
|
+
relayer: relayer.publicKey,
|
|
48
|
+
fee,
|
|
49
|
+
refund,
|
|
50
|
+
claimant: SystemProgram.programId,
|
|
51
|
+
};
|
|
52
|
+
// publicAmount is negative for withdrawals
|
|
53
|
+
const publicAmount = -outflowAmount;
|
|
54
|
+
const circuitInputs = prepareTransactionInputs({
|
|
55
|
+
inputUTXOs,
|
|
56
|
+
outputUTXOs,
|
|
57
|
+
root,
|
|
58
|
+
publicAmount,
|
|
59
|
+
extData,
|
|
60
|
+
mintAddress,
|
|
61
|
+
});
|
|
62
|
+
const rawProof = await proofBuilder(circuitInputs);
|
|
63
|
+
const proof = encodeSnarkjsProofToTransactionProof(rawProof);
|
|
64
|
+
const withdrawNoteCiphers = noteCiphers !== undefined
|
|
65
|
+
? noteCiphers
|
|
66
|
+
: changeNoteRecipientWallet && changeAmount > 0n
|
|
67
|
+
? createNoteCiphers({
|
|
68
|
+
recipientWalletPubkey: changeNoteRecipientWallet instanceof PublicKey
|
|
69
|
+
? changeNoteRecipientWallet.toBytes()
|
|
70
|
+
: changeNoteRecipientWallet,
|
|
71
|
+
blinding: bigIntToBytesBE(changeUTXO.blinding),
|
|
72
|
+
amount: changeAmount,
|
|
73
|
+
}, null)
|
|
74
|
+
: null;
|
|
75
|
+
await transact({
|
|
76
|
+
program,
|
|
77
|
+
relayer,
|
|
78
|
+
recipient,
|
|
79
|
+
mintAddress,
|
|
80
|
+
root,
|
|
81
|
+
inputTreeId,
|
|
82
|
+
outputTreeId,
|
|
83
|
+
publicAmount,
|
|
84
|
+
inputNullifiers: circuitInputs.inputNullifiers,
|
|
85
|
+
outputCommitments: circuitInputs.outputCommitments,
|
|
86
|
+
extData,
|
|
87
|
+
proof,
|
|
88
|
+
deadline,
|
|
89
|
+
noteCiphers: withdrawNoteCiphers,
|
|
90
|
+
});
|
|
91
|
+
const { index: changeIdx } = tree.insert(changeUTXO.commitment);
|
|
92
|
+
const { root: newRoot } = tree.insert(zeroUTXO.commitment);
|
|
93
|
+
return {
|
|
94
|
+
changeUTXO,
|
|
95
|
+
leafIndex: changeIdx,
|
|
96
|
+
root: newRoot,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Result of a private transfer operation.
|
|
101
|
+
*/
|