@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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { AccountView } from "../account/account.js";
|
|
2
|
+
import type { RelayStatusResponse } from "../clients/broadcaster.js";
|
|
3
|
+
import type { HistoryEntry } from "../history/types.js";
|
|
4
|
+
import type { NoteRecord } from "../state/store/records.js";
|
|
5
|
+
import type { DepositRelayResult, DepositSyncResult, TransactRelayResult, TransactSyncResult } from "../transactions/types/index.js";
|
|
6
|
+
import type { BurnerAccount, BurnerSendParams } from "./burner/types.js";
|
|
7
|
+
import type { AdapterExecuteResult, SignerOverride, SimpleAdapterExecuteParams, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SimpleDepositParams, SimpleTransactParams, SimpleTransferParams, SimpleWithdrawParams, TransferPlanResult, TransferResult, UnlinkWalletConfig, WalletAccountAPI, WalletSDK, WalletSDKEvent, WithdrawPlanResult, WithdrawResult } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* High-level wallet API that bakes `chainId` and `poolAddress` at construction time.
|
|
10
|
+
*
|
|
11
|
+
* Replaces `createWalletSDK` / `createBrowserWalletSDK` with a single entry point
|
|
12
|
+
* that absorbs initialization (storage, rng, core migration, environment resolution).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Browser (auto-detects IndexedDB + crypto.getRandomValues):
|
|
17
|
+
* const wallet = await UnlinkWallet.create({
|
|
18
|
+
* chainId: 11155111,
|
|
19
|
+
* environment: "testnet",
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Node (explicit storage):
|
|
23
|
+
* const wallet = await UnlinkWallet.create({
|
|
24
|
+
* chainId: 1,
|
|
25
|
+
* poolAddress: "0x...",
|
|
26
|
+
* gatewayUrl: "https://...",
|
|
27
|
+
* storage: createSqliteStorage({ path: "wallet.db" }),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Operations — no chainId/poolAddress needed:
|
|
31
|
+
* await wallet.seed.create();
|
|
32
|
+
* await wallet.accounts.create();
|
|
33
|
+
* await wallet.deposit({ depositor: "0x...", deposits: [{ token, amount }] });
|
|
34
|
+
* await wallet.transfer({ transfers: [{ token, recipient, amount }] });
|
|
35
|
+
* await wallet.getBalances();
|
|
36
|
+
* await wallet.sync();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class UnlinkWallet {
|
|
40
|
+
/** @internal */
|
|
41
|
+
private readonly sdk;
|
|
42
|
+
/** Chain ID this wallet operates on. */
|
|
43
|
+
readonly chainId: number;
|
|
44
|
+
/** Pool contract address this wallet transacts with. */
|
|
45
|
+
readonly poolAddress: string;
|
|
46
|
+
private constructor();
|
|
47
|
+
/**
|
|
48
|
+
* Create a new UnlinkWallet instance.
|
|
49
|
+
*
|
|
50
|
+
* Handles all initialization internally:
|
|
51
|
+
* - Resolves environment config (if using `environment` instead of explicit URLs)
|
|
52
|
+
* - Auto-detects storage (IndexedDB in browser) and rng (crypto.getRandomValues)
|
|
53
|
+
* - Runs schema migration via `initCore()`
|
|
54
|
+
* - Creates the internal SDK
|
|
55
|
+
*/
|
|
56
|
+
static create(config: UnlinkWalletConfig): Promise<UnlinkWallet>;
|
|
57
|
+
/** Seed management (create, import, export, delete mnemonic). */
|
|
58
|
+
get seed(): WalletSDK["seed"];
|
|
59
|
+
/** Account management (create, list, switch accounts). */
|
|
60
|
+
get accounts(): WalletAccountAPI;
|
|
61
|
+
/**
|
|
62
|
+
* Request a deposit (1 or more tokens).
|
|
63
|
+
* Returns calldata the depositor must submit on-chain via their EOA.
|
|
64
|
+
*/
|
|
65
|
+
deposit(params: SimpleDepositParams): Promise<DepositRelayResult>;
|
|
66
|
+
/** Wait for a deposit to be confirmed on-chain. */
|
|
67
|
+
confirmDeposit(relayId: string): Promise<DepositSyncResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Execute a private transfer (1 or more recipients).
|
|
70
|
+
* Handles note selection, circuit selection, and proof generation automatically.
|
|
71
|
+
*/
|
|
72
|
+
transfer(params: SimpleTransferParams, overrides?: SignerOverride): Promise<TransferResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Get a transfer plan without executing (for preview/confirmation UIs).
|
|
75
|
+
*/
|
|
76
|
+
planTransfer(params: SimpleTransferParams, account?: AccountView): Promise<TransferPlanResult>;
|
|
77
|
+
/** Execute a pre-built transfer plan. */
|
|
78
|
+
executeTransfer(plans: TransferPlanResult, overrides?: SignerOverride): Promise<TransferResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Execute a withdrawal (1 or more recipients).
|
|
81
|
+
* Handles note selection, circuit selection, and proof generation automatically.
|
|
82
|
+
*/
|
|
83
|
+
withdraw(params: SimpleWithdrawParams, overrides?: SignerOverride): Promise<WithdrawResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Get a withdrawal plan without executing (for preview/confirmation UIs).
|
|
86
|
+
*/
|
|
87
|
+
planWithdraw(params: SimpleWithdrawParams, account?: AccountView): Promise<WithdrawPlanResult>;
|
|
88
|
+
/** Execute a pre-built withdrawal plan. */
|
|
89
|
+
executeWithdraw(plans: WithdrawPlanResult, overrides?: SignerOverride): Promise<WithdrawResult>;
|
|
90
|
+
/** Wait for a transfer or withdrawal to be confirmed on-chain. */
|
|
91
|
+
confirmTransaction(relayId: string): Promise<TransactSyncResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Get balance for a specific token (defaults to all tokens if no token specified).
|
|
94
|
+
* @param token Token address. If omitted, returns balance for all tokens via getBalances().
|
|
95
|
+
*/
|
|
96
|
+
getBalance(token: string, overrides?: {
|
|
97
|
+
account: AccountView;
|
|
98
|
+
}): Promise<bigint>;
|
|
99
|
+
/** Get balances for all tokens. */
|
|
100
|
+
getBalances(overrides?: {
|
|
101
|
+
account: AccountView;
|
|
102
|
+
}): Promise<Record<string, bigint>>;
|
|
103
|
+
/** Get transaction history. */
|
|
104
|
+
getHistory(options?: {
|
|
105
|
+
includeSelfSends?: boolean;
|
|
106
|
+
}, overrides?: {
|
|
107
|
+
account: AccountView;
|
|
108
|
+
}): Promise<HistoryEntry[]>;
|
|
109
|
+
/** Get UTXO notes for the active account (or override account). */
|
|
110
|
+
getNotes(overrides?: {
|
|
111
|
+
account: AccountView;
|
|
112
|
+
}): Promise<NoteRecord[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Sync notes from the blockchain.
|
|
115
|
+
* Automatically resolves the active account (no need to pass it).
|
|
116
|
+
*/
|
|
117
|
+
sync(options?: {
|
|
118
|
+
forceFullResync?: boolean;
|
|
119
|
+
}, overrides?: {
|
|
120
|
+
account: AccountView;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/** Start auto-sync at the given interval (default: 5000ms). */
|
|
123
|
+
startAutoSync(intervalMs?: number): void;
|
|
124
|
+
/** Stop auto-sync. */
|
|
125
|
+
stopAutoSync(): void;
|
|
126
|
+
/** Get the current status of a transaction. */
|
|
127
|
+
getTxStatus(txId: string): Promise<RelayStatusResponse>;
|
|
128
|
+
/** Start tracking a transaction for status-changed events. */
|
|
129
|
+
trackTx(txId: string): void;
|
|
130
|
+
/** Stop tracking a transaction. */
|
|
131
|
+
untrackTx(txId: string): void;
|
|
132
|
+
/**
|
|
133
|
+
* Subscribe to wallet events (notes-updated, sync-error, tx-status-changed, etc.).
|
|
134
|
+
* @returns Unsubscribe function.
|
|
135
|
+
*/
|
|
136
|
+
on(listener: (event: WalletSDKEvent) => void): () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Burner account operations (BIP-44 derived EOAs for DeFi interactions).
|
|
139
|
+
* chainId/poolAddress are injected automatically for fund/sweepToPool.
|
|
140
|
+
*/
|
|
141
|
+
readonly burner: {
|
|
142
|
+
/** Derive burner address for a given index. */
|
|
143
|
+
addressOf: (index: number) => Promise<BurnerAccount>;
|
|
144
|
+
/** Send a transaction from burner at index. */
|
|
145
|
+
send: (index: number, tx: BurnerSendParams) => Promise<{
|
|
146
|
+
txHash: string;
|
|
147
|
+
}>;
|
|
148
|
+
/** Export the raw private key (0x-prefixed hex) for wallet import. */
|
|
149
|
+
exportKey: (index: number) => Promise<string>;
|
|
150
|
+
/** Withdraw from shielded pool to fund this burner. */
|
|
151
|
+
fund: (index: number, params: SimpleBurnerFundParams) => Promise<WithdrawResult>;
|
|
152
|
+
/** Approve + deposit tokens from burner back into shielded pool. */
|
|
153
|
+
sweepToPool: (index: number, params: SimpleBurnerSweepToPoolParams) => Promise<{
|
|
154
|
+
txHash: string;
|
|
155
|
+
}>;
|
|
156
|
+
/** Get ERC-20 token balance of any address. */
|
|
157
|
+
getTokenBalance: (address: string, token: string) => Promise<bigint>;
|
|
158
|
+
/** Get native ETH balance of any address. */
|
|
159
|
+
getBalance: (address: string) => Promise<bigint>;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Private DeFi adapter operations.
|
|
163
|
+
* chainId/poolAddress are injected automatically.
|
|
164
|
+
*/
|
|
165
|
+
readonly adapter: {
|
|
166
|
+
/**
|
|
167
|
+
* Execute an atomic unshield -> call(s) -> reshield flow through an adapter.
|
|
168
|
+
*/
|
|
169
|
+
execute: (params: SimpleAdapterExecuteParams, opts?: {
|
|
170
|
+
skipBroadcast?: boolean;
|
|
171
|
+
}, overrides?: SignerOverride) => Promise<AdapterExecuteResult>;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Advanced escape hatch for raw JoinSplit transaction building.
|
|
175
|
+
* Use this for custom transaction construction (e.g. swap adapters).
|
|
176
|
+
*/
|
|
177
|
+
readonly advanced: {
|
|
178
|
+
/** Build and submit raw JoinSplit transactions. */
|
|
179
|
+
transact: (params: SimpleTransactParams, opts?: {
|
|
180
|
+
skipBroadcast?: boolean;
|
|
181
|
+
}) => Promise<TransactRelayResult>;
|
|
182
|
+
/** Wait for a raw transaction to be confirmed on-chain. */
|
|
183
|
+
reconcile: (relayId: string) => Promise<TransactSyncResult>;
|
|
184
|
+
};
|
|
185
|
+
private requireActiveAccount;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=unlink-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlink-wallet.d.ts","sourceRoot":"","sources":["../../wallet/unlink-wallet.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unlink-xyz/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"
|
|
10
|
-
|
|
9
|
+
"browser": {
|
|
10
|
+
"import": "./dist/browser/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"default": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
11
17
|
},
|
|
12
|
-
"./
|
|
13
|
-
"
|
|
14
|
-
|
|
18
|
+
"./wallet": {
|
|
19
|
+
"browser": {
|
|
20
|
+
"import": "./dist/browser/wallet/index.js",
|
|
21
|
+
"types": "./dist/wallet/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"default": {
|
|
24
|
+
"import": "./dist/wallet/index.js",
|
|
25
|
+
"types": "./dist/wallet/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"./utils/async.js": {
|
|
29
|
+
"import": "./dist/utils/async.js",
|
|
30
|
+
"types": "./dist/utils/async.d.ts"
|
|
15
31
|
}
|
|
16
32
|
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
17
36
|
"publishConfig": {
|
|
18
37
|
"access": "public"
|
|
19
38
|
},
|
|
20
39
|
"scripts": {
|
|
21
|
-
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"build": "tsc -p tsconfig.json --emitDeclarationOnly && tsup && tsup --config tsup.browser.config.ts",
|
|
22
41
|
"lint": "eslint .",
|
|
23
42
|
"lint:fix": "eslint . --fix",
|
|
24
43
|
"format": "prettier . --write",
|
|
25
44
|
"format:check": "prettier . --check",
|
|
26
|
-
"test": "tsc
|
|
27
|
-
"setup:artifacts": "./setup-artifacts.sh"
|
|
45
|
+
"test": "tsc --noEmit && vitest run --test-timeout 0",
|
|
46
|
+
"setup:artifacts": "bash ./scripts/setup-artifacts.sh",
|
|
47
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
28
49
|
},
|
|
29
50
|
"dependencies": {
|
|
30
|
-
"@noble/
|
|
51
|
+
"@noble/curves": "^2.0.1",
|
|
31
52
|
"@noble/hashes": "2.0.0",
|
|
32
|
-
"@railgun-community/circomlibjs": "0.0.8",
|
|
33
53
|
"@scure/base": "2.0.0",
|
|
34
54
|
"@scure/bip39": "2.0.1",
|
|
35
55
|
"@types/snarkjs": "^0.7.9",
|
|
56
|
+
"@zk-kit/eddsa-poseidon": "^1.1.0",
|
|
36
57
|
"@zk-kit/imt": "2.0.0-beta.8",
|
|
58
|
+
"buffer": "^6.0.3",
|
|
59
|
+
"poseidon-lite": "^0.3.0",
|
|
37
60
|
"ethereum-cryptography": "3.2.0",
|
|
38
61
|
"ethers": "6.15.0",
|
|
39
62
|
"ky": "^1.14.0",
|
|
@@ -42,13 +65,13 @@
|
|
|
42
65
|
"uuid": "^13.0.0"
|
|
43
66
|
},
|
|
44
67
|
"devDependencies": {
|
|
45
|
-
"@
|
|
68
|
+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
69
|
+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
46
70
|
"@types/node": "^22.0.0",
|
|
47
|
-
"
|
|
48
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
49
|
-
"eslint": "^8.57.1",
|
|
71
|
+
"eslint": "^9.19.0",
|
|
50
72
|
"fake-indexeddb": "6.2.4",
|
|
51
73
|
"prettier": "^3.5.3",
|
|
74
|
+
"tsup": "^8.3.5",
|
|
52
75
|
"typescript": "^5.9.2",
|
|
53
76
|
"vitest": "4.0.1"
|
|
54
77
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Mnemonic } from "../key-derivation/bip39.js";
|
|
4
|
-
import { ByteUtils } from "../key-derivation/bytes.js";
|
|
5
|
-
import {
|
|
6
|
-
deriveNodesFromSeed,
|
|
7
|
-
WalletNode,
|
|
8
|
-
} from "../key-derivation/wallet-node.js";
|
|
9
|
-
import { createMemoryStorage } from "../storage/memory.js";
|
|
10
|
-
import {
|
|
11
|
-
deriveZkAccount,
|
|
12
|
-
deriveZkAccountFromMnemonic,
|
|
13
|
-
generateMasterSeed,
|
|
14
|
-
importMasterMnemonic,
|
|
15
|
-
loadMasterMnemonic,
|
|
16
|
-
loadMasterSeed,
|
|
17
|
-
MASTER_MNEMONIC_KEY,
|
|
18
|
-
MASTER_SEED_KEY,
|
|
19
|
-
MASTER_SEED_LENGTH,
|
|
20
|
-
storeMasterMnemonic,
|
|
21
|
-
type MasterSeedCrypto,
|
|
22
|
-
} from "./zkAccount.js";
|
|
23
|
-
|
|
24
|
-
describe("deriveZkAccount", () => {
|
|
25
|
-
const seed = Uint8Array.from(
|
|
26
|
-
{ length: MASTER_SEED_LENGTH },
|
|
27
|
-
(_, i) => i & 0xff,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
it("derives wallet key material", async () => {
|
|
31
|
-
const account = await deriveZkAccount(seed, 0);
|
|
32
|
-
|
|
33
|
-
expect(account.spendingKeyPair.privateKey).toHaveLength(32);
|
|
34
|
-
expect(typeof account.spendingKeyPair.pubkey[0]).toBe("bigint");
|
|
35
|
-
expect(typeof account.spendingKeyPair.pubkey[1]).toBe("bigint");
|
|
36
|
-
|
|
37
|
-
expect(account.viewingKeyPair.privateKey).toHaveLength(32);
|
|
38
|
-
expect(account.viewingKeyPair.pubkey).toHaveLength(32);
|
|
39
|
-
|
|
40
|
-
expect(account.nullifyingKey).toBeTypeOf("bigint");
|
|
41
|
-
|
|
42
|
-
const expectedNullifyingKey = await deriveNodesFromSeed(
|
|
43
|
-
seed,
|
|
44
|
-
0,
|
|
45
|
-
).viewing.getNullifyingKey();
|
|
46
|
-
expect(account.nullifyingKey).toBe(expectedNullifyingKey);
|
|
47
|
-
|
|
48
|
-
const expectedMPK = WalletNode.getMasterPublicKey(
|
|
49
|
-
account.spendingKeyPair.pubkey,
|
|
50
|
-
account.nullifyingKey,
|
|
51
|
-
);
|
|
52
|
-
expect(account.masterPublicKey).toBe(expectedMPK);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("derives distinct accounts per index", async () => {
|
|
56
|
-
const first = await deriveZkAccount(seed, 0);
|
|
57
|
-
const second = await deriveZkAccount(seed, 1);
|
|
58
|
-
|
|
59
|
-
expect(first.spendingKeyPair.privateKey).not.toEqual(
|
|
60
|
-
second.spendingKeyPair.privateKey,
|
|
61
|
-
);
|
|
62
|
-
expect(first.viewingKeyPair.privateKey).not.toEqual(
|
|
63
|
-
second.viewingKeyPair.privateKey,
|
|
64
|
-
);
|
|
65
|
-
expect(first.nullifyingKey).not.toEqual(second.nullifyingKey);
|
|
66
|
-
expect(first.masterPublicKey).not.toEqual(second.masterPublicKey);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("rejects negative indices", async () => {
|
|
70
|
-
await expect(deriveZkAccount(seed, -1)).rejects.toThrow(
|
|
71
|
-
"accountIndex must be a non-negative integer",
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("rejects non-integer indices", async () => {
|
|
76
|
-
await expect(deriveZkAccount(seed, Number.NaN)).rejects.toThrow(
|
|
77
|
-
"accountIndex must be a non-negative integer",
|
|
78
|
-
);
|
|
79
|
-
await expect(deriveZkAccount(seed, 0.25)).rejects.toThrow(
|
|
80
|
-
"accountIndex must be a non-negative integer",
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("rejects seeds that are not 64 bytes", async () => {
|
|
85
|
-
const shortSeed = Uint8Array.from({ length: 32 }, () => 1);
|
|
86
|
-
await expect(deriveZkAccount(shortSeed, 0)).rejects.toThrow(
|
|
87
|
-
"master seed must be 64 bytes",
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("derives the same keys when using mnemonic helper", async () => {
|
|
92
|
-
const entropy = Uint8Array.from({ length: 32 }, (_, i) => (i * 19) & 0xff);
|
|
93
|
-
const mnemonic = Mnemonic.fromEntropy(ByteUtils.bytesToHex(entropy));
|
|
94
|
-
const seedFromMnemonic = ByteUtils.hexStringToBytes(
|
|
95
|
-
Mnemonic.toSeed(mnemonic),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const fromSeed = await deriveZkAccount(seedFromMnemonic, 2);
|
|
99
|
-
const fromMnemonic = await deriveZkAccountFromMnemonic(mnemonic, 2);
|
|
100
|
-
|
|
101
|
-
expect(fromMnemonic).toEqual(fromSeed);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("generateMasterSeed", () => {
|
|
106
|
-
const fixtureEntropy = Uint8Array.from(
|
|
107
|
-
{ length: 32 },
|
|
108
|
-
(_, i) => (i * 13) & 0xff,
|
|
109
|
-
);
|
|
110
|
-
const fixtureMnemonic = Mnemonic.fromEntropy(
|
|
111
|
-
ByteUtils.bytesToHex(fixtureEntropy),
|
|
112
|
-
);
|
|
113
|
-
const fixtureSeed = ByteUtils.hexStringToBytes(
|
|
114
|
-
Mnemonic.toSeed(fixtureMnemonic),
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
function rngFixture(): (n: number) => Uint8Array {
|
|
118
|
-
return (n) => {
|
|
119
|
-
expect(n).toBe(32);
|
|
120
|
-
return new Uint8Array(fixtureEntropy);
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
it("creates and persists a new seed when none exists", async () => {
|
|
125
|
-
const storage = createMemoryStorage();
|
|
126
|
-
|
|
127
|
-
const seed = await generateMasterSeed({
|
|
128
|
-
storage,
|
|
129
|
-
rng: rngFixture(),
|
|
130
|
-
mnemonicPassphrase: "",
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(seed).toEqual(fixtureSeed);
|
|
134
|
-
const stored = await storage.get(MASTER_SEED_KEY);
|
|
135
|
-
expect(stored).not.toBeNull();
|
|
136
|
-
expect(stored).toEqual(fixtureSeed);
|
|
137
|
-
|
|
138
|
-
const mnemonic = await loadMasterMnemonic(storage);
|
|
139
|
-
expect(mnemonic).toEqual(fixtureMnemonic);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("returns existing seed without invoking rng", async () => {
|
|
143
|
-
const storage = createMemoryStorage();
|
|
144
|
-
await storage.put(MASTER_SEED_KEY, fixtureSeed);
|
|
145
|
-
|
|
146
|
-
const seed = await generateMasterSeed({
|
|
147
|
-
storage,
|
|
148
|
-
rng: () => {
|
|
149
|
-
throw new Error("rng should not be called when seed exists");
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
expect(seed).toEqual(fixtureSeed);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("overwrites when requested", async () => {
|
|
157
|
-
const storage = createMemoryStorage();
|
|
158
|
-
const existing = Uint8Array.from(
|
|
159
|
-
{ length: MASTER_SEED_LENGTH },
|
|
160
|
-
(_, i) => (i * 3) & 0xff,
|
|
161
|
-
);
|
|
162
|
-
await storage.put(MASTER_SEED_KEY, existing);
|
|
163
|
-
const replacementEntropy = Uint8Array.from(
|
|
164
|
-
{ length: 32 },
|
|
165
|
-
(_, i) => (i * 7) & 0xff,
|
|
166
|
-
);
|
|
167
|
-
const replacementMnemonic = Mnemonic.fromEntropy(
|
|
168
|
-
ByteUtils.bytesToHex(replacementEntropy),
|
|
169
|
-
);
|
|
170
|
-
const replacementSeed = ByteUtils.hexStringToBytes(
|
|
171
|
-
Mnemonic.toSeed(replacementMnemonic),
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const seed = await generateMasterSeed({
|
|
175
|
-
storage,
|
|
176
|
-
rng: (n) => {
|
|
177
|
-
expect(n).toBe(32);
|
|
178
|
-
return new Uint8Array(replacementEntropy);
|
|
179
|
-
},
|
|
180
|
-
overwrite: true,
|
|
181
|
-
mnemonicPassphrase: "",
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
expect(seed).toEqual(replacementSeed);
|
|
185
|
-
const stored = await storage.get(MASTER_SEED_KEY);
|
|
186
|
-
expect(stored).toEqual(replacementSeed);
|
|
187
|
-
const mnemonic = await loadMasterMnemonic(storage);
|
|
188
|
-
expect(mnemonic).toEqual(replacementMnemonic);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("applies custom crypto hooks", async () => {
|
|
192
|
-
const storage = createMemoryStorage();
|
|
193
|
-
|
|
194
|
-
const crypto: MasterSeedCrypto = {
|
|
195
|
-
encrypt(seed) {
|
|
196
|
-
return seed.map((byte) => byte ^ 0xff);
|
|
197
|
-
},
|
|
198
|
-
decrypt(payload) {
|
|
199
|
-
return payload.map((byte) => byte ^ 0xff);
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const seed = await generateMasterSeed({
|
|
204
|
-
storage,
|
|
205
|
-
rng: rngFixture(),
|
|
206
|
-
crypto,
|
|
207
|
-
mnemonicPassphrase: "",
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
expect(seed).toEqual(fixtureSeed);
|
|
211
|
-
const roundTrip = await loadMasterSeed(storage, crypto);
|
|
212
|
-
expect(roundTrip).toEqual(fixtureSeed);
|
|
213
|
-
|
|
214
|
-
const storedMnemonic = await storage.get(MASTER_MNEMONIC_KEY);
|
|
215
|
-
expect(storedMnemonic).toEqual(
|
|
216
|
-
textEncode(fixtureMnemonic).map((byte) => byte ^ 0xff),
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
const mnemonicRoundTrip = await loadMasterMnemonic(storage, crypto);
|
|
220
|
-
expect(mnemonicRoundTrip).toEqual(fixtureMnemonic);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("returns null when no seed is stored", async () => {
|
|
224
|
-
const storage = createMemoryStorage();
|
|
225
|
-
|
|
226
|
-
const result = await loadMasterSeed(storage);
|
|
227
|
-
|
|
228
|
-
expect(result).toBeNull();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("throws if rng returns incorrect length", async () => {
|
|
232
|
-
const storage = createMemoryStorage();
|
|
233
|
-
|
|
234
|
-
await expect(
|
|
235
|
-
generateMasterSeed({
|
|
236
|
-
storage,
|
|
237
|
-
rng: () => new Uint8Array(16),
|
|
238
|
-
mnemonicPassphrase: "",
|
|
239
|
-
}),
|
|
240
|
-
).rejects.toThrow(/mnemonic entropy must be 32 bytes/);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("reconstitutes seed from stored mnemonic when seed missing", async () => {
|
|
244
|
-
const storage = createMemoryStorage();
|
|
245
|
-
await storeMnemonicFixture(storage, fixtureMnemonic);
|
|
246
|
-
|
|
247
|
-
const seed = await generateMasterSeed({
|
|
248
|
-
storage,
|
|
249
|
-
rng: rngFixture(),
|
|
250
|
-
mnemonicPassphrase: "",
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expect(seed).toEqual(fixtureSeed);
|
|
254
|
-
const stored = await storage.get(MASTER_SEED_KEY);
|
|
255
|
-
expect(stored).toEqual(fixtureSeed);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe("importMasterMnemonic", () => {
|
|
260
|
-
const mnemonic =
|
|
261
|
-
"legal winner thank year wave sausage worth useful legal winner thank yellow";
|
|
262
|
-
const seed = ByteUtils.hexStringToBytes(Mnemonic.toSeed(mnemonic));
|
|
263
|
-
|
|
264
|
-
it("imports mnemonic and stores derived seed", async () => {
|
|
265
|
-
const storage = createMemoryStorage();
|
|
266
|
-
|
|
267
|
-
const derived = await importMasterMnemonic({ storage, mnemonic });
|
|
268
|
-
|
|
269
|
-
expect(derived).toEqual(seed);
|
|
270
|
-
const storedSeed = await loadMasterSeed(storage);
|
|
271
|
-
expect(storedSeed).toEqual(seed);
|
|
272
|
-
const storedMnemonic = await loadMasterMnemonic(storage);
|
|
273
|
-
expect(storedMnemonic).toEqual(mnemonic);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("refuses to overwrite without flag", async () => {
|
|
277
|
-
const storage = createMemoryStorage();
|
|
278
|
-
await importMasterMnemonic({ storage, mnemonic });
|
|
279
|
-
|
|
280
|
-
await expect(importMasterMnemonic({ storage, mnemonic })).rejects.toThrow(
|
|
281
|
-
/already exists/,
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("overwrites when requested", async () => {
|
|
286
|
-
const storage = createMemoryStorage();
|
|
287
|
-
await importMasterMnemonic({ storage, mnemonic });
|
|
288
|
-
|
|
289
|
-
const alternate =
|
|
290
|
-
"letter advice cage absurd amount doctor acoustic avoid letter advice cage above";
|
|
291
|
-
const alternateSeed = ByteUtils.hexStringToBytes(
|
|
292
|
-
Mnemonic.toSeed(alternate),
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const derived = await importMasterMnemonic({
|
|
296
|
-
storage,
|
|
297
|
-
mnemonic: alternate,
|
|
298
|
-
overwrite: true,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
expect(derived).toEqual(alternateSeed);
|
|
302
|
-
const storedMnemonic = await loadMasterMnemonic(storage);
|
|
303
|
-
expect(storedMnemonic).toEqual(alternate);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
function textEncode(value: string): Uint8Array {
|
|
308
|
-
return new TextEncoder().encode(value);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
async function storeMnemonicFixture(
|
|
312
|
-
storage: ReturnType<typeof createMemoryStorage>,
|
|
313
|
-
mnemonic: string,
|
|
314
|
-
) {
|
|
315
|
-
await storeMasterMnemonic(storage, mnemonic);
|
|
316
|
-
}
|