@unlink-xyz/core 0.1.2 → 0.1.3-canary.0877bfe
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/dist/account/{zkAccount.d.ts → account.d.ts} +7 -5
- package/dist/account/account.d.ts.map +1 -0
- package/dist/account/{zkAccount.js → account.js} +57 -43
- package/dist/browser/index.js +108202 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/circuits.json +74 -0
- package/dist/clients/broadcaster.d.ts +7 -2
- package/dist/clients/broadcaster.d.ts.map +1 -1
- package/dist/clients/broadcaster.js +9 -1
- package/dist/clients/http.d.ts +6 -0
- package/dist/clients/http.d.ts.map +1 -1
- package/dist/clients/http.js +24 -9
- package/dist/clients/indexer.d.ts +11 -0
- package/dist/clients/indexer.d.ts.map +1 -1
- package/dist/clients/indexer.js +40 -11
- package/dist/config.d.ts +28 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +33 -26
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +5 -2
- package/dist/crypto-adapters/auto-init.d.ts +2 -0
- package/dist/crypto-adapters/auto-init.d.ts.map +1 -0
- package/dist/crypto-adapters/auto-init.js +7 -0
- package/dist/crypto-adapters/index.d.ts +22 -0
- package/dist/crypto-adapters/index.d.ts.map +1 -0
- package/dist/crypto-adapters/index.js +47 -0
- package/dist/crypto-adapters/polyfills.d.ts +5 -0
- package/dist/crypto-adapters/polyfills.d.ts.map +1 -0
- package/dist/crypto-adapters/polyfills.js +8 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -0
- package/dist/history/index.d.ts +3 -0
- package/dist/history/index.d.ts.map +1 -0
- package/dist/history/index.js +2 -0
- package/dist/history/service.d.ts +46 -0
- package/dist/history/service.d.ts.map +1 -0
- package/dist/history/service.js +354 -0
- package/dist/history/types.d.ts +21 -0
- package/dist/history/types.d.ts.map +1 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/keys/address.d.ts +13 -0
- package/dist/keys/address.d.ts.map +1 -0
- package/dist/keys/address.js +55 -0
- package/dist/keys/derive.d.ts +37 -0
- package/dist/keys/derive.d.ts.map +1 -0
- package/dist/keys/derive.js +112 -0
- package/dist/keys/hex.d.ts +17 -0
- package/dist/keys/hex.d.ts.map +1 -0
- package/dist/keys/hex.js +66 -0
- package/dist/keys/index.d.ts +5 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +4 -0
- package/dist/keys/mnemonic.d.ts +8 -0
- package/dist/keys/mnemonic.d.ts.map +1 -0
- package/dist/keys/mnemonic.js +23 -0
- package/dist/keys.d.ts +4 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +4 -0
- package/dist/prover/config.d.ts +1 -15
- package/dist/prover/config.d.ts.map +1 -1
- package/dist/prover/config.js +1 -11
- package/dist/prover/prover.d.ts +15 -4
- package/dist/prover/prover.d.ts.map +1 -1
- package/dist/prover/prover.js +115 -98
- package/dist/prover/registry.d.ts +3 -30
- package/dist/prover/registry.d.ts.map +1 -1
- package/dist/prover/registry.js +12 -51
- package/dist/state/merkle/hydrator.d.ts.map +1 -1
- package/dist/state/merkle/hydrator.js +3 -2
- package/dist/state/merkle/index.d.ts +1 -1
- package/dist/state/merkle/index.d.ts.map +1 -1
- package/dist/state/merkle/index.js +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/merkle/merkle-tree.js +16 -7
- package/dist/state/store/ciphertext-store.d.ts +4 -0
- package/dist/state/store/ciphertext-store.d.ts.map +1 -1
- package/dist/state/store/ciphertext-store.js +12 -0
- 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/history-store.js +53 -0
- package/dist/state/store/index.d.ts +3 -2
- package/dist/state/store/index.d.ts.map +1 -1
- package/dist/state/store/index.js +1 -0
- 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/job-store.js +65 -39
- package/dist/state/store/jobs.d.ts +65 -18
- package/dist/state/store/jobs.d.ts.map +1 -1
- package/dist/state/store/leaf-store.d.ts.map +1 -1
- package/dist/state/store/leaf-store.js +0 -3
- 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/note-store.js +38 -34
- 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/nullifier-store.js +32 -2
- package/dist/state/store/records.d.ts +31 -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/root-store.js +0 -4
- package/dist/state/store/store.d.ts +61 -27
- package/dist/state/store/store.d.ts.map +1 -1
- package/dist/state/store/store.js +92 -1
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +5 -1
- package/dist/transactions/deposit.d.ts +12 -15
- package/dist/transactions/deposit.d.ts.map +1 -1
- package/dist/transactions/deposit.js +203 -152
- package/dist/transactions/index.d.ts +7 -4
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +7 -2
- package/dist/transactions/note-selection.d.ts +17 -0
- package/dist/transactions/note-selection.d.ts.map +1 -0
- package/dist/transactions/note-selection.js +201 -0
- package/dist/transactions/note-sync.d.ts +5 -33
- package/dist/transactions/note-sync.d.ts.map +1 -1
- package/dist/transactions/note-sync.js +320 -155
- package/dist/transactions/reconcile.d.ts +10 -12
- package/dist/transactions/reconcile.d.ts.map +1 -1
- package/dist/transactions/reconcile.js +53 -7
- package/dist/transactions/transact.d.ts +13 -24
- package/dist/transactions/transact.d.ts.map +1 -1
- package/dist/transactions/transact.js +393 -507
- package/dist/transactions/transaction-planner.d.ts +34 -0
- package/dist/transactions/transaction-planner.d.ts.map +1 -0
- package/dist/transactions/transaction-planner.js +116 -0
- package/dist/transactions/transfer-planner.d.ts +36 -0
- package/dist/transactions/transfer-planner.d.ts.map +1 -0
- package/dist/transactions/transfer-planner.js +85 -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 +67 -0
- package/dist/transactions/types/domain.d.ts.map +1 -0
- package/dist/transactions/types/domain.js +4 -0
- package/dist/transactions/types/index.d.ts +18 -0
- package/dist/transactions/types/index.d.ts.map +1 -0
- package/dist/transactions/types/index.js +17 -0
- package/dist/transactions/types/options.d.ts +45 -0
- package/dist/transactions/types/options.d.ts.map +1 -0
- package/dist/transactions/types/options.js +1 -0
- package/dist/transactions/types/planning.d.ts +80 -0
- package/dist/transactions/types/planning.d.ts.map +1 -0
- package/dist/transactions/types/planning.js +1 -0
- package/dist/transactions/types/state-stores.d.ts +103 -0
- package/dist/transactions/types/state-stores.d.ts.map +1 -0
- package/dist/transactions/types/state-stores.js +1 -0
- package/dist/transactions/types/transact.d.ts +76 -0
- package/dist/transactions/types/transact.d.ts.map +1 -0
- package/dist/transactions/types/transact.js +1 -0
- package/dist/transactions/withdrawal-planner.d.ts +58 -0
- package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
- package/dist/transactions/withdrawal-planner.js +128 -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.browser.config.js +34 -0
- package/dist/utils/amounts.d.ts +39 -0
- package/dist/utils/amounts.d.ts.map +1 -0
- package/dist/utils/amounts.js +89 -0
- package/dist/utils/async.d.ts +9 -0
- package/dist/utils/async.d.ts.map +1 -1
- package/dist/utils/async.js +24 -0
- package/dist/utils/bigint.js +7 -7
- package/dist/utils/crypto.d.ts +11 -5
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +12 -6
- package/dist/utils/format.d.ts +25 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +33 -0
- package/dist/utils/json-codec.js +1 -1
- package/dist/utils/notes.d.ts +15 -0
- package/dist/utils/notes.d.ts.map +1 -0
- package/dist/utils/notes.js +14 -0
- package/dist/utils/polling.d.ts +5 -0
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/polling.js +5 -0
- package/dist/utils/random.d.ts +13 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +27 -0
- package/dist/utils/secure-memory.d.ts +25 -0
- package/dist/utils/secure-memory.d.ts.map +1 -0
- package/dist/utils/secure-memory.js +28 -0
- package/dist/utils/signature.d.ts +6 -0
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/signature.js +8 -6
- package/dist/utils/validators.d.ts +21 -10
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +37 -11
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +13 -0
- package/package.json +28 -11
- package/.eslintrc.json +0 -4
- package/account/zkAccount.test.ts +0 -316
- package/account/zkAccount.ts +0 -222
- 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/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/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/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-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/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.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/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/types.d.ts +0 -114
- package/dist/transactions/types.d.ts.map +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/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/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 -17
- 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 -14
- 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/dist/{transactions → history}/types.js +0 -0
- /package/dist/{state/records.js → transactions/types/deposit.js} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser build configuration.
|
|
3
|
+
* Bundles all dependencies with Node.js polyfills for browser compatibility.
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: import("tsup").Options | import("tsup").Options[] | ((overrideOptions: import("tsup").Options) => import("tsup").Options | import("tsup").Options[] | Promise<import("tsup").Options | import("tsup").Options[]>);
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=tsup.browser.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsup.browser.config.d.ts","sourceRoot":"","sources":["../tsup.browser.config.ts"],"names":[],"mappings":"AAIA;;;GAGG;;AACH,wBA0BG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
|
|
2
|
+
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
|
|
3
|
+
import { defineConfig } from "tsup";
|
|
4
|
+
/**
|
|
5
|
+
* Browser build configuration.
|
|
6
|
+
* Bundles all dependencies with Node.js polyfills for browser compatibility.
|
|
7
|
+
*/
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
entry: ["index.ts"],
|
|
10
|
+
format: ["esm"],
|
|
11
|
+
dts: false, // Types are generated by the main tsc build
|
|
12
|
+
clean: false, // Don't clean dist/ to preserve tsc output
|
|
13
|
+
splitting: false,
|
|
14
|
+
sourcemap: true,
|
|
15
|
+
minify: false,
|
|
16
|
+
// Bundle everything including dependencies for browser compatibility
|
|
17
|
+
noExternal: [/.*/],
|
|
18
|
+
esbuildPlugins: [
|
|
19
|
+
NodeModulesPolyfillPlugin(),
|
|
20
|
+
NodeGlobalsPolyfillPlugin({
|
|
21
|
+
buffer: true,
|
|
22
|
+
process: true,
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
esbuildOptions(options) {
|
|
26
|
+
options.supported = {
|
|
27
|
+
...options.supported,
|
|
28
|
+
"top-level-await": true,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
platform: "browser",
|
|
32
|
+
target: "es2022",
|
|
33
|
+
outDir: "dist/browser",
|
|
34
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a decimal string to bigint with specified decimals.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Decimal string (e.g., "10.5", "42")
|
|
5
|
+
* @param decimals - Number of decimal
|
|
6
|
+
* @returns Amount as bigint in atomic units
|
|
7
|
+
* @throws ValidationError if value is invalid or has too many decimal places
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* parseAmount("10.5", 18) // Returns 10500000000000000000n
|
|
11
|
+
* parseAmount("0.001", 6) // Returns 1000n
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseAmount(value: string, decimals: number): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Format a bigint amount to a decimal string.
|
|
16
|
+
*
|
|
17
|
+
* @param amount - Amount in atomic units as bigint
|
|
18
|
+
* @param decimals - Number of decimal places
|
|
19
|
+
* @returns Human-readable decimal string
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* formatAmount(10500000000000000000n, 18) // Returns "10.5"
|
|
23
|
+
* formatAmount(1000n, 6) // Returns "0.001"
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatAmount(amount: bigint, decimals: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Split a total amount into N equal parts, distributing remainder evenly.
|
|
28
|
+
*
|
|
29
|
+
* @param total - Total amount to split
|
|
30
|
+
* @param parts - Number of parts to split into
|
|
31
|
+
* @returns Array of amounts that sum to total
|
|
32
|
+
* @throws ValidationError if parts is invalid or amount is too small to split
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* splitAmount(100n, 3) // Returns [34n, 33n, 33n] (remainder goes to first outputs)
|
|
36
|
+
* splitAmount(10n, 2) // Returns [5n, 5n]
|
|
37
|
+
*/
|
|
38
|
+
export declare function splitAmount(total: bigint, parts: number): bigint[];
|
|
39
|
+
//# sourceMappingURL=amounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amounts.d.ts","sourceRoot":"","sources":["../../utils/amounts.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA8BnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAcrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAgClE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ValidationError } from "../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a decimal string to bigint with specified decimals.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Decimal string (e.g., "10.5", "42")
|
|
6
|
+
* @param decimals - Number of decimal
|
|
7
|
+
* @returns Amount as bigint in atomic units
|
|
8
|
+
* @throws ValidationError if value is invalid or has too many decimal places
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* parseAmount("10.5", 18) // Returns 10500000000000000000n
|
|
12
|
+
* parseAmount("0.001", 6) // Returns 1000n
|
|
13
|
+
*/
|
|
14
|
+
export function parseAmount(value, decimals) {
|
|
15
|
+
const trimmed = value.trim();
|
|
16
|
+
if (!trimmed) {
|
|
17
|
+
throw new ValidationError("Amount cannot be empty");
|
|
18
|
+
}
|
|
19
|
+
if (!/^\d*(\.\d*)?$/.test(trimmed)) {
|
|
20
|
+
throw new ValidationError("Amount must be numeric and can include decimals (e.g., '10.5')");
|
|
21
|
+
}
|
|
22
|
+
const [rawWhole = "0", rawFraction = ""] = trimmed.split(".");
|
|
23
|
+
const whole = rawWhole === "" ? "0" : rawWhole;
|
|
24
|
+
if (rawFraction.length > decimals) {
|
|
25
|
+
throw new ValidationError(`Amount supports up to ${decimals} decimal places; trim the fractional part`);
|
|
26
|
+
}
|
|
27
|
+
// Pad fraction to full decimal places
|
|
28
|
+
const fraction = rawFraction.padEnd(decimals, "0");
|
|
29
|
+
const combined = `${whole}${fraction}`;
|
|
30
|
+
// Remove leading zeros
|
|
31
|
+
const normalized = combined.replace(/^0+(?=\d)/, "");
|
|
32
|
+
return normalized ? BigInt(normalized) : 0n;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Format a bigint amount to a decimal string.
|
|
36
|
+
*
|
|
37
|
+
* @param amount - Amount in atomic units as bigint
|
|
38
|
+
* @param decimals - Number of decimal places
|
|
39
|
+
* @returns Human-readable decimal string
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* formatAmount(10500000000000000000n, 18) // Returns "10.5"
|
|
43
|
+
* formatAmount(1000n, 6) // Returns "0.001"
|
|
44
|
+
*/
|
|
45
|
+
export function formatAmount(amount, decimals) {
|
|
46
|
+
if (amount < 0n) {
|
|
47
|
+
throw new ValidationError("Amount must be non-negative");
|
|
48
|
+
}
|
|
49
|
+
const amountStr = amount.toString().padStart(decimals + 1, "0");
|
|
50
|
+
const wholePartEnd = amountStr.length - decimals;
|
|
51
|
+
const wholePart = amountStr.slice(0, wholePartEnd) || "0";
|
|
52
|
+
const fractionPart = amountStr.slice(wholePartEnd);
|
|
53
|
+
// Remove trailing zeros from fraction
|
|
54
|
+
const trimmedFraction = fractionPart.replace(/0+$/, "");
|
|
55
|
+
return trimmedFraction ? `${wholePart}.${trimmedFraction}` : wholePart;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Split a total amount into N equal parts, distributing remainder evenly.
|
|
59
|
+
*
|
|
60
|
+
* @param total - Total amount to split
|
|
61
|
+
* @param parts - Number of parts to split into
|
|
62
|
+
* @returns Array of amounts that sum to total
|
|
63
|
+
* @throws ValidationError if parts is invalid or amount is too small to split
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* splitAmount(100n, 3) // Returns [34n, 33n, 33n] (remainder goes to first outputs)
|
|
67
|
+
* splitAmount(10n, 2) // Returns [5n, 5n]
|
|
68
|
+
*/
|
|
69
|
+
export function splitAmount(total, parts) {
|
|
70
|
+
if (parts === 0) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
if (parts < 0) {
|
|
74
|
+
throw new ValidationError("Number of parts must be non-negative");
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isInteger(parts)) {
|
|
77
|
+
throw new ValidationError("Number of parts must be an integer");
|
|
78
|
+
}
|
|
79
|
+
if (total < BigInt(parts)) {
|
|
80
|
+
throw new ValidationError(`Amount (${total}) is too small to distribute across ${parts} outputs (minimum 1 per output)`);
|
|
81
|
+
}
|
|
82
|
+
const base = total / BigInt(parts);
|
|
83
|
+
if (base <= 0n) {
|
|
84
|
+
throw new ValidationError("Output share must be positive");
|
|
85
|
+
}
|
|
86
|
+
const remainder = Number(total - base * BigInt(parts));
|
|
87
|
+
// Distribute remainder across first N outputs
|
|
88
|
+
return Array.from({ length: parts }, (_, idx) => base + (idx < remainder ? 1n : 0n));
|
|
89
|
+
}
|
package/dist/utils/async.d.ts
CHANGED
|
@@ -7,4 +7,13 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
7
7
|
* Type guard for HTTP 404 errors.
|
|
8
8
|
*/
|
|
9
9
|
export declare function isNotFoundError(err: unknown): err is HttpError;
|
|
10
|
+
/**
|
|
11
|
+
* Race a promise against a timeout, rejecting if the timeout fires first.
|
|
12
|
+
* Properly cleans up the timeout to avoid memory leaks.
|
|
13
|
+
*
|
|
14
|
+
* @param promise - The promise to race against the timeout
|
|
15
|
+
* @param ms - Timeout in milliseconds
|
|
16
|
+
* @param error - Error to throw on timeout (string message or Error instance)
|
|
17
|
+
*/
|
|
18
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number, error?: string | Error): Promise<T>;
|
|
10
19
|
//# sourceMappingURL=async.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../utils/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAE9D"}
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../utils/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAE9D;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,EAAE,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,GACrB,OAAO,CAAC,CAAC,CAAC,CAgBZ"}
|
package/dist/utils/async.js
CHANGED
|
@@ -11,3 +11,27 @@ export function sleep(ms) {
|
|
|
11
11
|
export function isNotFoundError(err) {
|
|
12
12
|
return err instanceof HttpError && err.status === 404;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Race a promise against a timeout, rejecting if the timeout fires first.
|
|
16
|
+
* Properly cleans up the timeout to avoid memory leaks.
|
|
17
|
+
*
|
|
18
|
+
* @param promise - The promise to race against the timeout
|
|
19
|
+
* @param ms - Timeout in milliseconds
|
|
20
|
+
* @param error - Error to throw on timeout (string message or Error instance)
|
|
21
|
+
*/
|
|
22
|
+
export async function withTimeout(promise, ms, error) {
|
|
23
|
+
let timeoutId;
|
|
24
|
+
return Promise.race([
|
|
25
|
+
promise,
|
|
26
|
+
new Promise((_, reject) => {
|
|
27
|
+
timeoutId = setTimeout(() => {
|
|
28
|
+
reject(error instanceof Error
|
|
29
|
+
? error
|
|
30
|
+
: new Error(error ?? `Operation timed out after ${ms}ms`));
|
|
31
|
+
}, ms);
|
|
32
|
+
}),
|
|
33
|
+
]).finally(() => {
|
|
34
|
+
if (timeoutId !== undefined)
|
|
35
|
+
clearTimeout(timeoutId);
|
|
36
|
+
});
|
|
37
|
+
}
|
package/dist/utils/bigint.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ValidationError } from "../errors.js";
|
|
2
|
+
import { FieldSize, Hex } from "../keys/hex.js";
|
|
3
3
|
/**
|
|
4
4
|
* BigInt helpers shared across transaction builders to keep formatting consistent.
|
|
5
5
|
*/
|
|
6
6
|
export function formatUint256(value) {
|
|
7
7
|
assertNonNegative("uint256", value);
|
|
8
|
-
return
|
|
8
|
+
return Hex.fromBigInt(value, FieldSize.SCALAR, true);
|
|
9
9
|
}
|
|
10
10
|
export function parseHexToBigInt(value) {
|
|
11
|
-
return
|
|
11
|
+
return Hex.toBigInt(value);
|
|
12
12
|
}
|
|
13
13
|
export function parseNumToBigInt(value) {
|
|
14
14
|
if (value === undefined) {
|
|
15
|
-
throw new
|
|
15
|
+
throw new ValidationError("Value is undefined");
|
|
16
16
|
}
|
|
17
17
|
return BigInt(value);
|
|
18
18
|
}
|
|
19
19
|
export function assertNonNegative(label, value) {
|
|
20
20
|
if (value < 0n) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new ValidationError(`${label} must be non-negative`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export function ensureBigint(label, value) {
|
|
25
25
|
if (typeof value !== "bigint") {
|
|
26
|
-
throw new
|
|
26
|
+
throw new ValidationError(`${label} must be provided as a bigint`);
|
|
27
27
|
}
|
|
28
28
|
return value;
|
|
29
29
|
}
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { Ciphertext,
|
|
2
|
-
export declare function encryptNote(note:
|
|
1
|
+
import { Ciphertext, NoteInput } from "../transactions/types/index.js";
|
|
2
|
+
export declare function encryptNote(note: NoteInput): Ciphertext;
|
|
3
3
|
export declare function encrypt(data: bigint, key: bigint): bigint;
|
|
4
|
-
export declare function decryptNote(c: Ciphertext, key: bigint):
|
|
4
|
+
export declare function decryptNote(c: Ciphertext, key: bigint): NoteInput;
|
|
5
5
|
export declare function deriveCommitment(note: {
|
|
6
6
|
npk: bigint;
|
|
7
7
|
amount: bigint;
|
|
8
8
|
token: string;
|
|
9
9
|
}): bigint;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Derive the nullifier public key (npk) from a note.
|
|
12
|
+
*/
|
|
13
|
+
export declare function deriveNpk(note: NoteInput): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Compute the commitment for a note given its npk.
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeCommitment(note: NoteInput, npk: bigint): bigint;
|
|
12
18
|
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../utils/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../utils/crypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAGvE,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAQvD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAYjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,UAGA;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,UAExC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,UAG7D"}
|
package/dist/utils/crypto.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { poseidon } from "
|
|
1
|
+
import { poseidon } from "../crypto-adapters/index.js";
|
|
2
2
|
import { CoreError } from "../errors.js";
|
|
3
3
|
import { parseHexToBigInt } from "./bigint.js";
|
|
4
4
|
export function encryptNote(note) {
|
|
@@ -30,10 +30,16 @@ export function deriveCommitment(note) {
|
|
|
30
30
|
const tokenScalar = BigInt(note.token);
|
|
31
31
|
return poseidon([note.npk, tokenScalar, note.amount]);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Derive the nullifier public key (npk) from a note.
|
|
35
|
+
*/
|
|
36
|
+
export function deriveNpk(note) {
|
|
37
|
+
return poseidon([note.mpk, note.random]);
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Compute the commitment for a note given its npk.
|
|
41
|
+
*/
|
|
42
|
+
export function computeCommitment(note, npk) {
|
|
43
|
+
const tokenScalar = BigInt(note.token);
|
|
44
|
+
return poseidon([npk, tokenScalar, note.amount]);
|
|
39
45
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize and validate an Ethereum address.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Address string to normalize
|
|
5
|
+
* @returns Normalized lowercase address
|
|
6
|
+
* @throws CoreError if the address is invalid
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* normalizeAddress("0xABC123...") // Returns "0xabc123..."
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeAddress(value: string): `0x${string}`;
|
|
12
|
+
/**
|
|
13
|
+
* Shorten a hex string for display.
|
|
14
|
+
*
|
|
15
|
+
* @param value - Hex string to shorten
|
|
16
|
+
* @param chars - Number of characters to show at start/end (default: 4)
|
|
17
|
+
* @returns Shortened string like "0x1234…abcd"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* shortenHex("0x1234567890abcdef1234567890abcdef12345678") // "0x1234…5678"
|
|
21
|
+
* shortenHex("0x1234567890abcdef1234567890abcdef12345678", 6) // "0x123456…345678"
|
|
22
|
+
*/
|
|
23
|
+
export declare function shortenHex(value: string, chars?: number): string;
|
|
24
|
+
export { randomHex, randomBigint } from "./random.js";
|
|
25
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../utils/format.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAE7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAK3D;AAGD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ensureAddress } from "./validators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Normalize and validate an Ethereum address.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Address string to normalize
|
|
6
|
+
* @returns Normalized lowercase address
|
|
7
|
+
* @throws CoreError if the address is invalid
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* normalizeAddress("0xABC123...") // Returns "0xabc123..."
|
|
11
|
+
*/
|
|
12
|
+
export function normalizeAddress(value) {
|
|
13
|
+
return ensureAddress("address", value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Shorten a hex string for display.
|
|
17
|
+
*
|
|
18
|
+
* @param value - Hex string to shorten
|
|
19
|
+
* @param chars - Number of characters to show at start/end (default: 4)
|
|
20
|
+
* @returns Shortened string like "0x1234…abcd"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* shortenHex("0x1234567890abcdef1234567890abcdef12345678") // "0x1234…5678"
|
|
24
|
+
* shortenHex("0x1234567890abcdef1234567890abcdef12345678", 6) // "0x123456…345678"
|
|
25
|
+
*/
|
|
26
|
+
export function shortenHex(value, chars = 4) {
|
|
27
|
+
if (!value.startsWith("0x") || value.length <= chars * 2 + 2) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return `${value.slice(0, chars + 2)}…${value.slice(-chars)}`;
|
|
31
|
+
}
|
|
32
|
+
// Re-export random utilities from dedicated module
|
|
33
|
+
export { randomHex, randomBigint } from "./random.js";
|
package/dist/utils/json-codec.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal note shape required for balance computation.
|
|
3
|
+
*/
|
|
4
|
+
export type BalanceableNote = {
|
|
5
|
+
token: string;
|
|
6
|
+
value: bigint | string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Computes token balances from a list of notes.
|
|
10
|
+
*
|
|
11
|
+
* @param notes - Array of notes to compute balances from
|
|
12
|
+
* @returns Record mapping token address to total balance
|
|
13
|
+
*/
|
|
14
|
+
export declare function computeBalances(notes: BalanceableNote[]): Record<string, bigint>;
|
|
15
|
+
//# sourceMappingURL=notes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.d.ts","sourceRoot":"","sources":["../../utils/notes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,eAAe,EAAE,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes token balances from a list of notes.
|
|
3
|
+
*
|
|
4
|
+
* @param notes - Array of notes to compute balances from
|
|
5
|
+
* @returns Record mapping token address to total balance
|
|
6
|
+
*/
|
|
7
|
+
export function computeBalances(notes) {
|
|
8
|
+
const totals = {};
|
|
9
|
+
for (const note of notes) {
|
|
10
|
+
const value = typeof note.value === "bigint" ? note.value : BigInt(note.value);
|
|
11
|
+
totals[note.token] = (totals[note.token] ?? 0n) + value;
|
|
12
|
+
}
|
|
13
|
+
return totals;
|
|
14
|
+
}
|
package/dist/utils/polling.d.ts
CHANGED
|
@@ -4,4 +4,9 @@
|
|
|
4
4
|
export declare const DEFAULT_POLL_INTERVAL_MS = 500;
|
|
5
5
|
export declare const DEFAULT_POLL_TIMEOUT_MS = 30000;
|
|
6
6
|
export declare const MAX_POLL_INTERVAL_MS = 5000;
|
|
7
|
+
/**
|
|
8
|
+
* Initial delay before first poll for fresh deposits.
|
|
9
|
+
* Reduces wasted 404 requests while commitment is being indexed.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_INITIAL_POLL_DELAY_MS = 2000;
|
|
7
12
|
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../utils/polling.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,oBAAoB,OAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../utils/polling.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C;;;GAGG;AACH,eAAO,MAAM,6BAA6B,OAAQ,CAAC"}
|
package/dist/utils/polling.js
CHANGED
|
@@ -4,3 +4,8 @@
|
|
|
4
4
|
export const DEFAULT_POLL_INTERVAL_MS = 500;
|
|
5
5
|
export const DEFAULT_POLL_TIMEOUT_MS = 30_000;
|
|
6
6
|
export const MAX_POLL_INTERVAL_MS = 5_000;
|
|
7
|
+
/**
|
|
8
|
+
* Initial delay before first poll for fresh deposits.
|
|
9
|
+
* Reduces wasted 404 requests while commitment is being indexed.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_INITIAL_POLL_DELAY_MS = 2_000;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a cryptographically secure random bigint.
|
|
3
|
+
* @param bytes - Number of bytes of randomness (default: 32 for 256-bit)
|
|
4
|
+
* @returns Random bigint
|
|
5
|
+
*/
|
|
6
|
+
export declare function randomBigint(bytes?: number): bigint;
|
|
7
|
+
/**
|
|
8
|
+
* Generate a cryptographically secure random hex string.
|
|
9
|
+
* @param bytes - Number of bytes of randomness
|
|
10
|
+
* @returns Random hex string with 0x prefix
|
|
11
|
+
*/
|
|
12
|
+
export declare function randomHex(bytes: number): `0x${string}`;
|
|
13
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../utils/random.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,SAAK,GAAG,MAAM,CAY/C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAItD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CoreError } from "../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a cryptographically secure random bigint.
|
|
4
|
+
* @param bytes - Number of bytes of randomness (default: 32 for 256-bit)
|
|
5
|
+
* @returns Random bigint
|
|
6
|
+
*/
|
|
7
|
+
export function randomBigint(bytes = 32) {
|
|
8
|
+
if (typeof globalThis.crypto?.getRandomValues !== "function") {
|
|
9
|
+
throw new CoreError("crypto.getRandomValues is not available");
|
|
10
|
+
}
|
|
11
|
+
const buffer = new Uint8Array(bytes);
|
|
12
|
+
globalThis.crypto.getRandomValues(buffer);
|
|
13
|
+
return BigInt("0x" +
|
|
14
|
+
Array.from(buffer)
|
|
15
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
16
|
+
.join(""));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate a cryptographically secure random hex string.
|
|
20
|
+
* @param bytes - Number of bytes of randomness
|
|
21
|
+
* @returns Random hex string with 0x prefix
|
|
22
|
+
*/
|
|
23
|
+
export function randomHex(bytes) {
|
|
24
|
+
return `0x${randomBigint(bytes)
|
|
25
|
+
.toString(16)
|
|
26
|
+
.padStart(bytes * 2, "0")}`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT limitations:
|
|
3
|
+
* - Garbage collection timing is unpredictable
|
|
4
|
+
* - Strings are immutable
|
|
5
|
+
* - No compiler enforcement to prevent copies
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Securely zeros out a Uint8Array's contents by overwriting with zeros.
|
|
9
|
+
* This should be called on all sensitive cryptographic material after use
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - The Uint8Array to zeroize (will be mutated in place)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const privateKey = derivePrivateKey(seed);
|
|
16
|
+
* try {
|
|
17
|
+
* const signature = sign(message, privateKey);
|
|
18
|
+
* return signature;
|
|
19
|
+
* } finally {
|
|
20
|
+
* zeroize(privateKey); // Clear sensitive data
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function zeroize(bytes: Uint8Array): void;
|
|
25
|
+
//# sourceMappingURL=secure-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-memory.d.ts","sourceRoot":"","sources":["../../utils/secure-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAI/C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT limitations:
|
|
3
|
+
* - Garbage collection timing is unpredictable
|
|
4
|
+
* - Strings are immutable
|
|
5
|
+
* - No compiler enforcement to prevent copies
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Securely zeros out a Uint8Array's contents by overwriting with zeros.
|
|
9
|
+
* This should be called on all sensitive cryptographic material after use
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - The Uint8Array to zeroize (will be mutated in place)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const privateKey = derivePrivateKey(seed);
|
|
16
|
+
* try {
|
|
17
|
+
* const signature = sign(message, privateKey);
|
|
18
|
+
* return signature;
|
|
19
|
+
* } finally {
|
|
20
|
+
* zeroize(privateKey); // Clear sensitive data
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function zeroize(bytes) {
|
|
25
|
+
if (!bytes || bytes.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
bytes.fill(0);
|
|
28
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates an EdDSA signature over a poseidon-hashed message using the spending private key.
|
|
3
3
|
* Used for transact public signal signing.
|
|
4
|
+
*
|
|
5
|
+
* The spendingPrivateKey parameter should be zeroized by the caller after use.
|
|
6
|
+
*
|
|
7
|
+
* @param spendingPrivateKey - The 32-byte spending private key (will not be mutated)
|
|
8
|
+
* @param message - The bigint message to sign
|
|
9
|
+
* @returns The EdDSA signature
|
|
4
10
|
*/
|
|
5
11
|
export declare function signTransactMessage(spendingPrivateKey: Uint8Array, message: bigint): {
|
|
6
12
|
R8: [bigint, bigint];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../utils/signature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../utils/signature.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,kBAAkB,EAAE,UAAU,EAC9B,OAAO,EAAE,MAAM,GACd;IAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAErC"}
|
package/dist/utils/signature.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { eddsa } from "@railgun-community/circomlibjs";
|
|
1
|
+
import { signMessage } from "../crypto-adapters/index.js";
|
|
3
2
|
/**
|
|
4
3
|
* Generates an EdDSA signature over a poseidon-hashed message using the spending private key.
|
|
5
4
|
* Used for transact public signal signing.
|
|
5
|
+
*
|
|
6
|
+
* The spendingPrivateKey parameter should be zeroized by the caller after use.
|
|
7
|
+
*
|
|
8
|
+
* @param spendingPrivateKey - The 32-byte spending private key (will not be mutated)
|
|
9
|
+
* @param message - The bigint message to sign
|
|
10
|
+
* @returns The EdDSA signature
|
|
6
11
|
*/
|
|
7
12
|
export function signTransactMessage(spendingPrivateKey, message) {
|
|
8
|
-
|
|
9
|
-
? spendingPrivateKey
|
|
10
|
-
: Buffer.from(spendingPrivateKey);
|
|
11
|
-
return eddsa.signPoseidon(key, message);
|
|
13
|
+
return signMessage(spendingPrivateKey, message);
|
|
12
14
|
}
|