@unlink-xyz/core 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/account/{zkAccount.d.ts → account.d.ts} +36 -5
- package/dist/account/account.d.ts.map +1 -0
- package/dist/account/accounts.d.ts +42 -0
- package/dist/account/accounts.d.ts.map +1 -0
- package/dist/account/seed.d.ts +45 -0
- package/dist/account/seed.d.ts.map +1 -0
- package/dist/account/serialization.d.ts +6 -0
- package/dist/account/serialization.d.ts.map +1 -0
- package/dist/browser/index.js +56221 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/wallet/index.js +55942 -0
- package/dist/browser/wallet/index.js.map +1 -0
- package/dist/clients/broadcaster.d.ts +8 -2
- package/dist/clients/broadcaster.d.ts.map +1 -1
- package/dist/clients/http.d.ts +6 -0
- package/dist/clients/http.d.ts.map +1 -1
- package/dist/clients/indexer.d.ts +16 -0
- package/dist/clients/indexer.d.ts.map +1 -1
- package/dist/config.d.ts +30 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/crypto/adapters/index.d.ts +17 -0
- package/dist/crypto/adapters/index.d.ts.map +1 -0
- package/dist/crypto/adapters/polyfills.d.ts +5 -0
- package/dist/crypto/adapters/polyfills.d.ts.map +1 -0
- package/dist/crypto/encrypt.d.ts +33 -0
- package/dist/crypto/encrypt.d.ts.map +1 -0
- package/dist/crypto/secure-memory.d.ts +25 -0
- package/dist/crypto/secure-memory.d.ts.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/history/index.d.ts +3 -0
- package/dist/history/index.d.ts.map +1 -0
- package/dist/history/service.d.ts +46 -0
- package/dist/history/service.d.ts.map +1 -0
- package/dist/history/types.d.ts +21 -0
- package/dist/history/types.d.ts.map +1 -0
- package/dist/index.d.ts +16 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6721 -19
- package/dist/index.js.map +1 -0
- package/dist/keys/address.d.ts +13 -0
- package/dist/keys/address.d.ts.map +1 -0
- package/dist/keys/derive.d.ts +37 -0
- package/dist/keys/derive.d.ts.map +1 -0
- package/dist/keys/hex.d.ts +14 -0
- package/dist/keys/hex.d.ts.map +1 -0
- package/dist/keys/index.d.ts +5 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/mnemonic.d.ts +6 -0
- package/dist/keys/mnemonic.d.ts.map +1 -0
- package/dist/keys.d.ts +5 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/prover/config.d.ts +53 -22
- package/dist/prover/config.d.ts.map +1 -1
- package/dist/prover/integrity.d.ts +20 -0
- package/dist/prover/integrity.d.ts.map +1 -0
- package/dist/prover/prover.d.ts +16 -20
- package/dist/prover/prover.d.ts.map +1 -1
- package/dist/prover/registry.d.ts +3 -30
- package/dist/prover/registry.d.ts.map +1 -1
- package/dist/state/merkle/hydrator.d.ts +21 -19
- package/dist/state/merkle/hydrator.d.ts.map +1 -1
- package/dist/state/merkle/index.d.ts +2 -2
- package/dist/state/merkle/index.d.ts.map +1 -1
- package/dist/state/merkle/merkle-tree.d.ts +8 -0
- package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
- package/dist/state/store/ciphertext-store.d.ts +11 -0
- package/dist/state/store/ciphertext-store.d.ts.map +1 -1
- package/dist/state/store/history-store.d.ts +24 -0
- package/dist/state/store/history-store.d.ts.map +1 -0
- package/dist/state/store/index.d.ts +3 -2
- package/dist/state/store/index.d.ts.map +1 -1
- package/dist/state/store/job-store.d.ts +7 -7
- package/dist/state/store/job-store.d.ts.map +1 -1
- package/dist/state/store/jobs.d.ts +70 -25
- package/dist/state/store/jobs.d.ts.map +1 -1
- package/dist/state/store/leaf-store.d.ts +4 -0
- package/dist/state/store/leaf-store.d.ts.map +1 -1
- package/dist/state/store/note-store.d.ts +7 -7
- package/dist/state/store/note-store.d.ts.map +1 -1
- package/dist/state/store/nullifier-store.d.ts +9 -0
- package/dist/state/store/nullifier-store.d.ts.map +1 -1
- package/dist/state/store/records.d.ts +39 -2
- package/dist/state/store/records.d.ts.map +1 -1
- package/dist/state/store/root-store.d.ts.map +1 -1
- package/dist/state/store/store.d.ts +79 -27
- package/dist/state/store/store.d.ts.map +1 -1
- package/dist/storage/indexeddb.d.ts.map +1 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/transactions/adapter.d.ts +31 -0
- package/dist/transactions/adapter.d.ts.map +1 -0
- package/dist/transactions/deposit.d.ts +12 -15
- package/dist/transactions/deposit.d.ts.map +1 -1
- package/dist/transactions/index.d.ts +9 -4
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/note-selection.d.ts +17 -0
- package/dist/transactions/note-selection.d.ts.map +1 -0
- package/dist/transactions/note-sync.d.ts +5 -33
- package/dist/transactions/note-sync.d.ts.map +1 -1
- package/dist/transactions/reconcile.d.ts +9 -11
- package/dist/transactions/reconcile.d.ts.map +1 -1
- package/dist/transactions/transact.d.ts +30 -22
- package/dist/transactions/transact.d.ts.map +1 -1
- package/dist/transactions/transaction-planner.d.ts +34 -0
- package/dist/transactions/transaction-planner.d.ts.map +1 -0
- package/dist/transactions/transfer-planner.d.ts +37 -0
- package/dist/transactions/transfer-planner.d.ts.map +1 -0
- package/dist/transactions/types/deposit.d.ts +67 -0
- package/dist/transactions/types/deposit.d.ts.map +1 -0
- package/dist/transactions/types/domain.d.ts +70 -0
- package/dist/transactions/types/domain.d.ts.map +1 -0
- package/dist/transactions/types/index.d.ts +18 -0
- package/dist/transactions/types/index.d.ts.map +1 -0
- package/dist/transactions/types/options.d.ts +54 -0
- package/dist/transactions/types/options.d.ts.map +1 -0
- package/dist/transactions/types/planning.d.ts +82 -0
- package/dist/transactions/types/planning.d.ts.map +1 -0
- package/dist/transactions/types/state-stores.d.ts +151 -0
- package/dist/transactions/types/state-stores.d.ts.map +1 -0
- package/dist/transactions/types/transact.d.ts +83 -0
- package/dist/transactions/types/transact.d.ts.map +1 -0
- package/dist/transactions/withdrawal-planner.d.ts +58 -0
- package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsup.browser.config.d.ts +7 -0
- package/dist/tsup.browser.config.d.ts.map +1 -0
- package/dist/tsup.config.d.ts +8 -0
- package/dist/tsup.config.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/amounts.d.ts +26 -0
- package/dist/utils/amounts.d.ts.map +1 -0
- package/dist/utils/async.d.ts +9 -0
- package/dist/utils/async.d.ts.map +1 -1
- package/dist/utils/async.js +38 -11
- package/dist/utils/async.js.map +1 -0
- package/dist/utils/bigint.d.ts +0 -2
- package/dist/utils/bigint.d.ts.map +1 -1
- package/dist/utils/format.d.ts +25 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/notes.d.ts +15 -0
- package/dist/utils/notes.d.ts.map +1 -0
- package/dist/utils/polling.d.ts +5 -0
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/random.d.ts +18 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/signature.d.ts +6 -0
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/validators.d.ts +21 -10
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/wallet/adapter.d.ts +21 -0
- package/dist/wallet/adapter.d.ts.map +1 -0
- package/dist/wallet/burner/service.d.ts +32 -0
- package/dist/wallet/burner/service.d.ts.map +1 -0
- package/dist/wallet/burner/types.d.ts +47 -0
- package/dist/wallet/burner/types.d.ts.map +1 -0
- package/dist/wallet/index.d.ts +20 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +6462 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/sdk.d.ts +48 -0
- package/dist/wallet/sdk.d.ts.map +1 -0
- package/dist/wallet/types.d.ts +457 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/dist/wallet/unlink-wallet.d.ts +187 -0
- package/dist/wallet/unlink-wallet.d.ts.map +1 -0
- package/package.json +38 -15
- package/.eslintrc.json +0 -4
- package/account/zkAccount.test.ts +0 -316
- package/account/zkAccount.ts +0 -222
- package/circuits.json +0 -26
- package/clients/broadcaster.ts +0 -67
- package/clients/http.ts +0 -94
- package/clients/indexer.ts +0 -150
- package/config.ts +0 -39
- package/core.ts +0 -17
- package/dist/account/railgun-imports-prototype.d.ts +0 -12
- package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
- package/dist/account/railgun-imports-prototype.js +0 -30
- package/dist/account/zkAccount.d.ts.map +0 -1
- package/dist/account/zkAccount.js +0 -128
- package/dist/circuits.json +0 -26
- package/dist/clients/broadcaster.js +0 -23
- package/dist/clients/http.js +0 -57
- package/dist/clients/indexer.js +0 -67
- package/dist/config.js +0 -29
- package/dist/core.js +0 -12
- package/dist/errors.js +0 -18
- package/dist/key-derivation/babyjubjub.d.ts +0 -9
- package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
- package/dist/key-derivation/babyjubjub.js +0 -9
- package/dist/key-derivation/bech32.d.ts +0 -22
- package/dist/key-derivation/bech32.d.ts.map +0 -1
- package/dist/key-derivation/bech32.js +0 -86
- package/dist/key-derivation/bip32.d.ts +0 -17
- package/dist/key-derivation/bip32.d.ts.map +0 -1
- package/dist/key-derivation/bip32.js +0 -41
- package/dist/key-derivation/bip39.d.ts +0 -22
- package/dist/key-derivation/bip39.d.ts.map +0 -1
- package/dist/key-derivation/bip39.js +0 -56
- package/dist/key-derivation/bytes.d.ts +0 -19
- package/dist/key-derivation/bytes.d.ts.map +0 -1
- package/dist/key-derivation/bytes.js +0 -92
- package/dist/key-derivation/hash.d.ts +0 -3
- package/dist/key-derivation/hash.d.ts.map +0 -1
- package/dist/key-derivation/hash.js +0 -10
- package/dist/key-derivation/index.d.ts +0 -8
- package/dist/key-derivation/index.d.ts.map +0 -1
- package/dist/key-derivation/index.js +0 -7
- package/dist/key-derivation/wallet-node.d.ts +0 -45
- package/dist/key-derivation/wallet-node.d.ts.map +0 -1
- package/dist/key-derivation/wallet-node.js +0 -109
- package/dist/keys.js +0 -41
- package/dist/prover/config.js +0 -80
- package/dist/prover/index.js +0 -1
- package/dist/prover/prover.js +0 -274
- package/dist/prover/registry.js +0 -57
- package/dist/schema.js +0 -14
- package/dist/state/ciphertext-store.d.ts +0 -12
- package/dist/state/ciphertext-store.d.ts.map +0 -1
- package/dist/state/ciphertext-store.js +0 -25
- package/dist/state/hydrator.d.ts +0 -16
- package/dist/state/hydrator.d.ts.map +0 -1
- package/dist/state/hydrator.js +0 -18
- package/dist/state/index.js +0 -2
- package/dist/state/job-store.d.ts +0 -12
- package/dist/state/job-store.d.ts.map +0 -1
- package/dist/state/job-store.js +0 -118
- package/dist/state/jobs.d.ts +0 -50
- package/dist/state/jobs.d.ts.map +0 -1
- package/dist/state/jobs.js +0 -1
- package/dist/state/leaf-store.d.ts +0 -17
- package/dist/state/leaf-store.d.ts.map +0 -1
- package/dist/state/leaf-store.js +0 -35
- package/dist/state/merkle/hydrator.js +0 -36
- package/dist/state/merkle/index.js +0 -2
- package/dist/state/merkle/merkle-tree.js +0 -104
- package/dist/state/merkle-tree.d.ts +0 -34
- package/dist/state/merkle-tree.d.ts.map +0 -1
- package/dist/state/merkle-tree.js +0 -104
- package/dist/state/note-store.d.ts +0 -37
- package/dist/state/note-store.d.ts.map +0 -1
- package/dist/state/note-store.js +0 -133
- package/dist/state/nullifier-store.d.ts +0 -13
- package/dist/state/nullifier-store.d.ts.map +0 -1
- package/dist/state/nullifier-store.js +0 -21
- package/dist/state/records.d.ts +0 -57
- package/dist/state/records.d.ts.map +0 -1
- package/dist/state/records.js +0 -1
- package/dist/state/root-store.d.ts +0 -13
- package/dist/state/root-store.d.ts.map +0 -1
- package/dist/state/root-store.js +0 -30
- package/dist/state/store/ciphertext-store.js +0 -25
- package/dist/state/store/index.js +0 -8
- package/dist/state/store/job-store.js +0 -118
- package/dist/state/store/jobs.js +0 -1
- package/dist/state/store/leaf-store.js +0 -35
- package/dist/state/store/note-store.js +0 -142
- package/dist/state/store/nullifier-store.js +0 -30
- package/dist/state/store/records.js +0 -1
- package/dist/state/store/root-store.js +0 -30
- package/dist/state/store/store.js +0 -22
- package/dist/state/store.d.ts +0 -26
- package/dist/state/store.d.ts.map +0 -1
- package/dist/state/store.js +0 -19
- package/dist/state.d.ts +0 -83
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -171
- package/dist/storage/index.js +0 -2
- package/dist/storage/indexeddb.js +0 -205
- package/dist/storage/memory.js +0 -87
- package/dist/transactions/deposit.js +0 -169
- package/dist/transactions/index.js +0 -4
- package/dist/transactions/note-sync.js +0 -320
- package/dist/transactions/reconcile.js +0 -39
- package/dist/transactions/shield.d.ts +0 -5
- package/dist/transactions/shield.d.ts.map +0 -1
- package/dist/transactions/shield.js +0 -93
- package/dist/transactions/transact.js +0 -561
- package/dist/transactions/types.d.ts +0 -114
- package/dist/transactions/types.d.ts.map +0 -1
- package/dist/transactions/types.js +0 -1
- package/dist/transactions/utils.d.ts +0 -10
- package/dist/transactions/utils.d.ts.map +0 -1
- package/dist/transactions/utils.js +0 -17
- package/dist/types.js +0 -1
- package/dist/utils/bigint.js +0 -29
- package/dist/utils/crypto.d.ts +0 -12
- package/dist/utils/crypto.d.ts.map +0 -1
- package/dist/utils/crypto.js +0 -39
- package/dist/utils/json-codec.js +0 -25
- package/dist/utils/polling.js +0 -6
- package/dist/utils/signature.js +0 -12
- package/dist/utils/time.d.ts +0 -2
- package/dist/utils/time.d.ts.map +0 -1
- package/dist/utils/time.js +0 -3
- package/dist/utils/validators.js +0 -70
- package/dist/utils/witness.d.ts +0 -11
- package/dist/utils/witness.d.ts.map +0 -1
- package/dist/utils/witness.js +0 -19
- package/errors.ts +0 -20
- package/index.ts +0 -21
- package/key-derivation/babyjubjub.ts +0 -11
- package/key-derivation/bech32.test.ts +0 -90
- package/key-derivation/bech32.ts +0 -124
- package/key-derivation/bip32.ts +0 -56
- package/key-derivation/bip39.ts +0 -76
- package/key-derivation/bytes.ts +0 -118
- package/key-derivation/hash.ts +0 -13
- package/key-derivation/index.ts +0 -7
- package/key-derivation/wallet-node.ts +0 -155
- package/keys.ts +0 -47
- package/prover/config.ts +0 -104
- package/prover/index.ts +0 -1
- package/prover/prover.integration.test.ts +0 -162
- package/prover/prover.test.ts +0 -309
- package/prover/prover.ts +0 -405
- package/prover/registry.test.ts +0 -90
- package/prover/registry.ts +0 -82
- package/schema.ts +0 -17
- package/setup-artifacts.sh +0 -57
- package/state/index.ts +0 -2
- package/state/merkle/hydrator.ts +0 -69
- package/state/merkle/index.ts +0 -12
- package/state/merkle/merkle-tree.test.ts +0 -50
- package/state/merkle/merkle-tree.ts +0 -163
- package/state/store/ciphertext-store.ts +0 -28
- package/state/store/index.ts +0 -24
- package/state/store/job-store.ts +0 -162
- package/state/store/jobs.ts +0 -64
- package/state/store/leaf-store.ts +0 -39
- package/state/store/note-store.ts +0 -177
- package/state/store/nullifier-store.ts +0 -39
- package/state/store/records.ts +0 -61
- package/state/store/root-store.ts +0 -34
- package/state/store/store.ts +0 -25
- package/state.test.ts +0 -235
- package/storage/index.ts +0 -3
- package/storage/indexeddb.test.ts +0 -99
- package/storage/indexeddb.ts +0 -235
- package/storage/memory.test.ts +0 -59
- package/storage/memory.ts +0 -93
- package/transactions/deposit.test.ts +0 -160
- package/transactions/deposit.ts +0 -227
- package/transactions/index.ts +0 -20
- package/transactions/note-sync.test.ts +0 -155
- package/transactions/note-sync.ts +0 -452
- package/transactions/reconcile.ts +0 -73
- package/transactions/transact.test.ts +0 -451
- package/transactions/transact.ts +0 -811
- package/transactions/types.ts +0 -141
- package/tsconfig.json +0 -15
- package/types/global.d.ts +0 -15
- package/types.ts +0 -24
- package/utils/async.ts +0 -15
- package/utils/bigint.ts +0 -34
- package/utils/crypto.test.ts +0 -69
- package/utils/crypto.ts +0 -58
- package/utils/json-codec.ts +0 -38
- package/utils/polling.ts +0 -6
- package/utils/signature.ts +0 -16
- package/utils/validators.test.ts +0 -64
- package/utils/validators.ts +0 -86
package/transactions/types.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { IMTMerkleProof } from "@zk-kit/imt";
|
|
2
|
-
|
|
3
|
-
import type { ZkAccount } from "../account/zkAccount.js";
|
|
4
|
-
import type { CommitmentRecord } from "../clients/indexer.js";
|
|
5
|
-
import type {
|
|
6
|
-
JobStatus,
|
|
7
|
-
LeafRecord,
|
|
8
|
-
NoteRecord,
|
|
9
|
-
NullifierRecord,
|
|
10
|
-
PendingJobKind,
|
|
11
|
-
PendingJobRecord,
|
|
12
|
-
RootRecord,
|
|
13
|
-
} from "../state/index.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Base state store interface with common methods shared across services.
|
|
17
|
-
*/
|
|
18
|
-
export type BaseStateStore = {
|
|
19
|
-
putLeaf(record: LeafRecord): Promise<void>;
|
|
20
|
-
getLeaf(chainId: number, index: number): Promise<LeafRecord | null>;
|
|
21
|
-
clearLeaves(chainId: number): Promise<void>;
|
|
22
|
-
putRoot(record: RootRecord): Promise<void>;
|
|
23
|
-
putPendingJob(job: PendingJobRecord): Promise<void>;
|
|
24
|
-
getPendingJob(relayId: string): Promise<PendingJobRecord | null>;
|
|
25
|
-
listPendingJobs(filter?: {
|
|
26
|
-
kind?: PendingJobKind;
|
|
27
|
-
statuses?: JobStatus[];
|
|
28
|
-
}): Promise<PendingJobRecord[]>;
|
|
29
|
-
deletePendingJob(relayId: string): Promise<void>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type DepositStateStore = BaseStateStore;
|
|
33
|
-
|
|
34
|
-
export type TransactStateStore = BaseStateStore & {
|
|
35
|
-
getNote(chainId: number, index: number): Promise<NoteRecord | null>;
|
|
36
|
-
markNoteSpent(
|
|
37
|
-
chainId: number,
|
|
38
|
-
index: number,
|
|
39
|
-
spentAt?: number,
|
|
40
|
-
): Promise<NoteRecord>;
|
|
41
|
-
putNullifier(record: NullifierRecord): Promise<void>;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type DepositNoteInput = {
|
|
45
|
-
mpk: bigint;
|
|
46
|
-
random: bigint;
|
|
47
|
-
token: string;
|
|
48
|
-
amount: bigint;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export type DepositRequest = {
|
|
52
|
-
zkAccount: ZkAccount;
|
|
53
|
-
chainId: number;
|
|
54
|
-
poolAddress: string;
|
|
55
|
-
depositor: string;
|
|
56
|
-
note: DepositNoteInput;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type DepositRelayResult = {
|
|
60
|
-
relayId: string;
|
|
61
|
-
calldata: string;
|
|
62
|
-
commitment: string;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export type DepositSyncResult = {
|
|
66
|
-
chainId: number;
|
|
67
|
-
index: number;
|
|
68
|
-
commitment: string;
|
|
69
|
-
root: string;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Minimal reference to an input note; index resolves the canonical note state.
|
|
74
|
-
*/
|
|
75
|
-
export type SpendNoteReference = {
|
|
76
|
-
index: number;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type WithdrawalNoteInput = {
|
|
80
|
-
npk: bigint;
|
|
81
|
-
amount: bigint;
|
|
82
|
-
token: string;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Private output note to append back into the pool after spending.
|
|
87
|
-
*/
|
|
88
|
-
export type OutputNoteInput = {
|
|
89
|
-
mpk: bigint;
|
|
90
|
-
random: bigint;
|
|
91
|
-
token: string;
|
|
92
|
-
amount: bigint;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Placeholder proof structure matching the pool interface; pubSignals remain meaningful.
|
|
97
|
-
*/
|
|
98
|
-
export type Proof = {
|
|
99
|
-
pA: [bigint, bigint];
|
|
100
|
-
pB: [[bigint, bigint], [bigint, bigint]];
|
|
101
|
-
pC: [bigint, bigint];
|
|
102
|
-
pubSignals: bigint[];
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Parameters required to a mock transact call against the local state.
|
|
107
|
-
*/
|
|
108
|
-
export type TransactRequest = {
|
|
109
|
-
zkAccount: ZkAccount; // TODO: put zkAccount in parent?
|
|
110
|
-
chainId: number;
|
|
111
|
-
poolAddress: string;
|
|
112
|
-
token: string;
|
|
113
|
-
inputs: SpendNoteReference[];
|
|
114
|
-
withdrawal: WithdrawalNoteInput;
|
|
115
|
-
outputs: OutputNoteInput[];
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Result of the mock transact flow, including calldata and state deltas.
|
|
120
|
-
*/
|
|
121
|
-
export type TransactRelayResult = {
|
|
122
|
-
relayId: string;
|
|
123
|
-
calldata: string;
|
|
124
|
-
proof: Proof;
|
|
125
|
-
witnesses: IMTMerkleProof[];
|
|
126
|
-
nullifiers: string[];
|
|
127
|
-
predictedCommitments: string[];
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export type TransactSyncResult = {
|
|
131
|
-
chainId: number;
|
|
132
|
-
root: string;
|
|
133
|
-
nullifiers: string[];
|
|
134
|
-
newCommitments: string[];
|
|
135
|
-
txHash?: string;
|
|
136
|
-
indexedCommitments?: CommitmentRecord[];
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export type Ciphertext = {
|
|
140
|
-
data: [bigint, bigint, bigint];
|
|
141
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./",
|
|
6
|
-
"composite": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"noEmit": false,
|
|
10
|
-
"resolveJsonModule": true,
|
|
11
|
-
"typeRoots": ["./types", "../../node_modules/@types"]
|
|
12
|
-
},
|
|
13
|
-
"include": ["./**/*.ts", "./circuits.json"],
|
|
14
|
-
"exclude": ["./dist/**/*", "./node_modules/**/*", "**/*.test.ts"]
|
|
15
|
-
}
|
package/types/global.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare module "@railgun-community/circomlibjs" {
|
|
2
|
-
export const babyjub: {
|
|
3
|
-
Base8: [bigint, bigint];
|
|
4
|
-
packPoint: (point: [bigint, bigint]) => Uint8Array;
|
|
5
|
-
unpackPoint: (bytes: Uint8Array) => [bigint, bigint];
|
|
6
|
-
};
|
|
7
|
-
export const poseidon: (inputs: (bigint | number)[]) => bigint;
|
|
8
|
-
export const eddsa: {
|
|
9
|
-
prv2pub: (privKey: Uint8Array) => [bigint, bigint];
|
|
10
|
-
signPoseidon: (
|
|
11
|
-
privKey: Uint8Array,
|
|
12
|
-
message: bigint,
|
|
13
|
-
) => { R8: [bigint, bigint]; S: bigint };
|
|
14
|
-
};
|
|
15
|
-
}
|
package/types.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type Bytes = Uint8Array;
|
|
2
|
-
|
|
3
|
-
export type IterOptions = {
|
|
4
|
-
prefix?: string;
|
|
5
|
-
start?: string; // inclusive
|
|
6
|
-
end?: string; // inclusive
|
|
7
|
-
limit?: number;
|
|
8
|
-
reverse?: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type KvPair = { key: string; value: Bytes };
|
|
12
|
-
|
|
13
|
-
export type BatchOp = { put?: [string, Bytes]; del?: string };
|
|
14
|
-
|
|
15
|
-
export type Storage = {
|
|
16
|
-
open(): Promise<void>;
|
|
17
|
-
get(key: string): Promise<Bytes | null>;
|
|
18
|
-
delete(key: string): Promise<void>;
|
|
19
|
-
put(key: string, value: Bytes): Promise<void>;
|
|
20
|
-
batch(ops: BatchOp[]): Promise<void>;
|
|
21
|
-
iter(opts: IterOptions): Promise<KvPair[]>;
|
|
22
|
-
getSchemaVersion(): Promise<number>;
|
|
23
|
-
setSchemaVersion(v: number): Promise<void>;
|
|
24
|
-
};
|
package/utils/async.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { HttpError } from "../clients/http.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Promise-based delay utility.
|
|
5
|
-
*/
|
|
6
|
-
export function sleep(ms: number): Promise<void> {
|
|
7
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Type guard for HTTP 404 errors.
|
|
12
|
-
*/
|
|
13
|
-
export function isNotFoundError(err: unknown): err is HttpError {
|
|
14
|
-
return err instanceof HttpError && err.status === 404;
|
|
15
|
-
}
|
package/utils/bigint.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CoreError } from "../errors.js";
|
|
2
|
-
import { ByteLength, ByteUtils } from "../key-derivation/bytes.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* BigInt helpers shared across transaction builders to keep formatting consistent.
|
|
6
|
-
*/
|
|
7
|
-
export function formatUint256(value: bigint): string {
|
|
8
|
-
assertNonNegative("uint256", value);
|
|
9
|
-
return ByteUtils.nToHex(value, ByteLength.UINT_256, true);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function parseHexToBigInt(value: string): bigint {
|
|
13
|
-
return ByteUtils.hexToBigInt(value);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parseNumToBigInt(value: string | undefined): bigint {
|
|
17
|
-
if (value === undefined) {
|
|
18
|
-
throw new CoreError("Value is undefined");
|
|
19
|
-
}
|
|
20
|
-
return BigInt(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function assertNonNegative(label: string, value: bigint): void {
|
|
24
|
-
if (value < 0n) {
|
|
25
|
-
throw new CoreError(`${label} must be non-negative`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function ensureBigint(label: string, value: unknown): bigint {
|
|
30
|
-
if (typeof value !== "bigint") {
|
|
31
|
-
throw new CoreError(`${label} must be provided as a bigint`);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
package/utils/crypto.test.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { CoreError } from "../errors.js";
|
|
4
|
-
import { Ciphertext, OutputNoteInput } from "../transactions/types.js";
|
|
5
|
-
import { decryptNote, encryptNote } from "./crypto.js";
|
|
6
|
-
|
|
7
|
-
describe("crypto", () => {
|
|
8
|
-
describe("decryptNote", () => {
|
|
9
|
-
it("successfully decrypts with correct key", () => {
|
|
10
|
-
// Create a valid note
|
|
11
|
-
const originalNote: OutputNoteInput = {
|
|
12
|
-
mpk: 12345n,
|
|
13
|
-
random: 67890n,
|
|
14
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
15
|
-
amount: 1000n,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const ciphertext = encryptNote(originalNote);
|
|
19
|
-
|
|
20
|
-
// Decrypt with the correct key (mpk)
|
|
21
|
-
const decryptedNote = decryptNote(ciphertext, originalNote.mpk);
|
|
22
|
-
|
|
23
|
-
// Verify decrypted data matches original
|
|
24
|
-
expect(decryptedNote.mpk).toBe(originalNote.mpk);
|
|
25
|
-
expect(decryptedNote.random).toBe(originalNote.random);
|
|
26
|
-
expect(decryptedNote.token).toBe(originalNote.token);
|
|
27
|
-
expect(decryptedNote.amount).toBe(originalNote.amount);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("throws CoreError when decrypting with wrong key", () => {
|
|
31
|
-
const originalNote: OutputNoteInput = {
|
|
32
|
-
mpk: 12345n,
|
|
33
|
-
random: 67890n,
|
|
34
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
35
|
-
amount: 1000n,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Encrypt the note with the correct key
|
|
39
|
-
const ciphertext = encryptNote(originalNote);
|
|
40
|
-
|
|
41
|
-
// Try to decrypt with a DIFFERENT key
|
|
42
|
-
const wrongKey = 99999n;
|
|
43
|
-
|
|
44
|
-
// Should throw CoreError with "Invalid Decrypt" message
|
|
45
|
-
expect(() => decryptNote(ciphertext, wrongKey)).toThrow(CoreError);
|
|
46
|
-
expect(() => decryptNote(ciphertext, wrongKey)).toThrow(
|
|
47
|
-
"Invalid Decrypt",
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("throws CoreError when decrypted token exceeds valid Ethereum address range", () => {
|
|
52
|
-
const invalidCiphertext: Ciphertext = {
|
|
53
|
-
data: [
|
|
54
|
-
123n,
|
|
55
|
-
// This large value will decrypt to something > 160 bits
|
|
56
|
-
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,
|
|
57
|
-
456n,
|
|
58
|
-
],
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const someKey = 12345n;
|
|
62
|
-
|
|
63
|
-
expect(() => decryptNote(invalidCiphertext, someKey)).toThrow(CoreError);
|
|
64
|
-
expect(() => decryptNote(invalidCiphertext, someKey)).toThrow(
|
|
65
|
-
"Invalid Decrypt",
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
package/utils/crypto.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { poseidon } from "@railgun-community/circomlibjs";
|
|
2
|
-
|
|
3
|
-
import { CoreError } from "../errors.js";
|
|
4
|
-
import {
|
|
5
|
-
Ciphertext,
|
|
6
|
-
DepositNoteInput,
|
|
7
|
-
DepositRequest,
|
|
8
|
-
OutputNoteInput,
|
|
9
|
-
} from "../transactions/types.js";
|
|
10
|
-
import { parseHexToBigInt } from "./bigint.js";
|
|
11
|
-
|
|
12
|
-
export function encryptNote(
|
|
13
|
-
note: OutputNoteInput | DepositNoteInput,
|
|
14
|
-
): Ciphertext {
|
|
15
|
-
return {
|
|
16
|
-
data: [
|
|
17
|
-
encrypt(note.random, note.mpk),
|
|
18
|
-
encrypt(parseHexToBigInt(note.token), note.mpk),
|
|
19
|
-
encrypt(note.amount, note.mpk),
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function encrypt(data: bigint, key: bigint): bigint {
|
|
25
|
-
return poseidon([0x556e6c696e6b, key]) ^ data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function decryptNote(c: Ciphertext, key: bigint): OutputNoteInput {
|
|
29
|
-
const token_bigint = encrypt(c.data[1], key);
|
|
30
|
-
if (token_bigint > 0xffffffffffffffffffffffffffffffffffffffffn) {
|
|
31
|
-
throw new CoreError("Invalid Decrypt");
|
|
32
|
-
}
|
|
33
|
-
const result = {
|
|
34
|
-
mpk: key,
|
|
35
|
-
random: encrypt(c.data[0], key),
|
|
36
|
-
token: "0x" + token_bigint.toString(16).padStart(40, "0"),
|
|
37
|
-
amount: encrypt(c.data[2], key),
|
|
38
|
-
};
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function deriveCommitment(note: {
|
|
43
|
-
npk: bigint;
|
|
44
|
-
amount: bigint;
|
|
45
|
-
token: string;
|
|
46
|
-
}) {
|
|
47
|
-
const tokenScalar = BigInt(note.token);
|
|
48
|
-
return poseidon([note.npk, tokenScalar, note.amount]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function deriveNpk(request: DepositRequest) {
|
|
52
|
-
return poseidon([request.note.mpk, request.note.random]);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function computeCommitment(request: DepositRequest, npk: bigint) {
|
|
56
|
-
const tokenScalar = BigInt(request.note.token);
|
|
57
|
-
return poseidon([npk, tokenScalar, request.note.amount]);
|
|
58
|
-
}
|
package/utils/json-codec.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { CoreError } from "../errors.js";
|
|
2
|
-
import { validateKey } from "../keys.js";
|
|
3
|
-
import { Storage } from "../types.js";
|
|
4
|
-
|
|
5
|
-
const encoder = new TextEncoder();
|
|
6
|
-
const decoder = new TextDecoder();
|
|
7
|
-
|
|
8
|
-
export type JsonRecord = { [key: string]: unknown };
|
|
9
|
-
|
|
10
|
-
export function encodeJson(value: JsonRecord): Uint8Array {
|
|
11
|
-
return encoder.encode(JSON.stringify(value));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function decodeJson<T extends JsonRecord>(payload: Uint8Array): T {
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(decoder.decode(payload)) as T;
|
|
17
|
-
} catch (err) {
|
|
18
|
-
throw new CoreError("failed to decode stored state payload");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function putJson(
|
|
23
|
-
storage: Storage,
|
|
24
|
-
key: string,
|
|
25
|
-
record: JsonRecord,
|
|
26
|
-
) {
|
|
27
|
-
validateKey(key);
|
|
28
|
-
await storage.put(key, encodeJson(record));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function getJson<T extends JsonRecord>(
|
|
32
|
-
storage: Storage,
|
|
33
|
-
key: string,
|
|
34
|
-
) {
|
|
35
|
-
const payload = await storage.get(key);
|
|
36
|
-
if (!payload) return null;
|
|
37
|
-
return decodeJson<T>(payload);
|
|
38
|
-
}
|
package/utils/polling.ts
DELETED
package/utils/signature.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "buffer";
|
|
2
|
-
import { eddsa } from "@railgun-community/circomlibjs";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generates an EdDSA signature over a poseidon-hashed message using the spending private key.
|
|
6
|
-
* Used for transact public signal signing.
|
|
7
|
-
*/
|
|
8
|
-
export function signTransactMessage(
|
|
9
|
-
spendingPrivateKey: Uint8Array,
|
|
10
|
-
message: bigint,
|
|
11
|
-
): { R8: [bigint, bigint]; S: bigint } {
|
|
12
|
-
const key = Buffer.isBuffer(spendingPrivateKey)
|
|
13
|
-
? spendingPrivateKey
|
|
14
|
-
: Buffer.from(spendingPrivateKey);
|
|
15
|
-
return eddsa.signPoseidon(key, message);
|
|
16
|
-
}
|
package/utils/validators.test.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ensureFieldElement,
|
|
5
|
-
ensureNoteCommitmentInput,
|
|
6
|
-
ensureWithdrawalInput,
|
|
7
|
-
} from "./validators.js";
|
|
8
|
-
|
|
9
|
-
const MAX =
|
|
10
|
-
21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617n;
|
|
11
|
-
|
|
12
|
-
describe("validators", () => {
|
|
13
|
-
describe("ensureWithdrawalInput", () => {
|
|
14
|
-
it("accepts valid inputs", () => {
|
|
15
|
-
const input = ensureWithdrawalInput("withdrawal", {
|
|
16
|
-
npk: 1n,
|
|
17
|
-
amount: 2n,
|
|
18
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
19
|
-
});
|
|
20
|
-
expect(input.amount).toBe(2n);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it.skip("rejects zero amounts", () => {
|
|
24
|
-
// TODO: why would we want to do this?
|
|
25
|
-
expect(() =>
|
|
26
|
-
ensureWithdrawalInput("withdrawal", {
|
|
27
|
-
npk: 1n,
|
|
28
|
-
amount: 0n,
|
|
29
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
30
|
-
}),
|
|
31
|
-
).toThrow("withdrawal.amount must be greater than zero");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("rejects values outside the field", () => {
|
|
35
|
-
expect(() =>
|
|
36
|
-
ensureWithdrawalInput("withdrawal", {
|
|
37
|
-
npk: MAX,
|
|
38
|
-
amount: 1n,
|
|
39
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
40
|
-
}),
|
|
41
|
-
).toThrow("must be less than the SNARK scalar field");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("ensureNoteCommitmentInput", () => {
|
|
46
|
-
it("rejects zero amounts", () => {
|
|
47
|
-
expect(() =>
|
|
48
|
-
ensureNoteCommitmentInput("note", {
|
|
49
|
-
npk: 5n,
|
|
50
|
-
amount: 0n,
|
|
51
|
-
token: "0x1111111111111111111111111111111111111111",
|
|
52
|
-
}),
|
|
53
|
-
).toThrow("note.amount must be greater than zero");
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("ensureFieldElement", () => {
|
|
58
|
-
it("throws for negative values", () => {
|
|
59
|
-
expect(() => ensureFieldElement("value", -1n)).toThrow(
|
|
60
|
-
"value must be a non-negative field element",
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
package/utils/validators.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { CoreError } from "../errors.js";
|
|
2
|
-
import { assertNonNegative } from "./bigint.js";
|
|
3
|
-
|
|
4
|
-
export const SNARK_SCALAR_FIELD =
|
|
5
|
-
21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617n;
|
|
6
|
-
|
|
7
|
-
export function ensurePositiveInt(label: string, value: number) {
|
|
8
|
-
if (!Number.isInteger(value) || value < 0) {
|
|
9
|
-
throw new CoreError(`${label} must be a non-negative integer`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function ensureChainId(chainId: number) {
|
|
14
|
-
if (!Number.isInteger(chainId) || chainId <= 0) {
|
|
15
|
-
throw new CoreError("chainId must be a positive integer");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Guards master public key strings against empty values. */
|
|
20
|
-
export function ensureMpk(mpk: string) {
|
|
21
|
-
if (typeof mpk !== "string" || mpk.length === 0) {
|
|
22
|
-
throw new CoreError("note mpk must be a non-empty string");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function ensureBigIntString(label: string, value: string) {
|
|
27
|
-
let parsed: bigint;
|
|
28
|
-
try {
|
|
29
|
-
parsed = BigInt(value);
|
|
30
|
-
} catch {
|
|
31
|
-
throw new CoreError(`${label} must be a base-10 bigint string`);
|
|
32
|
-
}
|
|
33
|
-
if (parsed < 0n) {
|
|
34
|
-
throw new CoreError(`${label} must be non-negative`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
39
|
-
|
|
40
|
-
export function ensureAddress(label: string, value: string) {
|
|
41
|
-
if (typeof value !== "string" || !ADDRESS_REGEX.test(value)) {
|
|
42
|
-
throw new CoreError(`${label} must be a 0x-prefixed hex address`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Confirms the bigint resides in the SNARK scalar field range. */
|
|
47
|
-
export function ensureFieldElement(label: string, value: bigint) {
|
|
48
|
-
if (value < 0n) {
|
|
49
|
-
throw new CoreError(`${label} must be a non-negative field element`);
|
|
50
|
-
}
|
|
51
|
-
if (value >= SNARK_SCALAR_FIELD) {
|
|
52
|
-
throw new CoreError(`${label} must be less than the SNARK scalar field`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Validates withdrawal note public data before encoding calldata. */
|
|
57
|
-
export function ensureWithdrawalInput(
|
|
58
|
-
label: string,
|
|
59
|
-
withdrawal: { npk: bigint; amount: bigint; token: string },
|
|
60
|
-
) {
|
|
61
|
-
assertNonNegative(`${label}.npk`, withdrawal.npk);
|
|
62
|
-
ensureFieldElement(`${label}.npk`, withdrawal.npk);
|
|
63
|
-
assertNonNegative(`${label}.amount`, withdrawal.amount);
|
|
64
|
-
// if (withdrawal.amount === 0n) {
|
|
65
|
-
// throw new CoreError(`${label}.amount must be greater than zero`);
|
|
66
|
-
// }
|
|
67
|
-
ensureFieldElement(`${label}.amount`, withdrawal.amount);
|
|
68
|
-
ensureAddress(`${label}.token`, withdrawal.token);
|
|
69
|
-
return withdrawal;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Validates note parameters before producing a Poseidon commitment. */
|
|
73
|
-
export function ensureNoteCommitmentInput(
|
|
74
|
-
label: string,
|
|
75
|
-
note: { npk: bigint; amount: bigint; token: string },
|
|
76
|
-
) {
|
|
77
|
-
assertNonNegative(`${label}.npk`, note.npk);
|
|
78
|
-
ensureFieldElement(`${label}.npk`, note.npk);
|
|
79
|
-
assertNonNegative(`${label}.amount`, note.amount);
|
|
80
|
-
if (note.amount === 0n) {
|
|
81
|
-
throw new CoreError(`${label}.amount must be greater than zero`);
|
|
82
|
-
}
|
|
83
|
-
ensureFieldElement(`${label}.amount`, note.amount);
|
|
84
|
-
ensureAddress(`${label}.token`, note.token);
|
|
85
|
-
return note;
|
|
86
|
-
}
|