@unlink-xyz/core 0.1.3-canary.7a2ea6a → 0.1.3-canary.8cf3cb2
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/{account.d.ts → zkAccount.d.ts} +5 -36
- package/dist/account/zkAccount.d.ts.map +1 -0
- package/dist/account/{account.js → zkAccount.js} +38 -57
- package/dist/circuits.json +6 -54
- package/dist/clients/broadcaster.d.ts +2 -8
- package/dist/clients/broadcaster.d.ts.map +1 -1
- package/dist/clients/broadcaster.js +1 -32
- package/dist/clients/http.d.ts.map +1 -1
- package/dist/clients/http.js +9 -16
- package/dist/clients/indexer.d.ts +0 -15
- package/dist/clients/indexer.d.ts.map +1 -1
- package/dist/clients/indexer.js +13 -44
- package/dist/config.d.ts +9 -30
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +25 -65
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -3
- package/dist/crypto-adapters/index.d.ts +15 -0
- package/dist/crypto-adapters/index.d.ts.map +1 -0
- package/dist/crypto-adapters/index.js +20 -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 +0 -17
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -32
- package/dist/history/service.d.ts +4 -4
- package/dist/history/service.d.ts.map +1 -1
- package/dist/history/service.js +3 -3
- package/dist/index.d.ts +8 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -9
- package/dist/key-derivation/bech32.d.ts +22 -0
- package/dist/key-derivation/bech32.d.ts.map +1 -0
- package/dist/key-derivation/bech32.js +86 -0
- package/dist/key-derivation/bip32.d.ts +17 -0
- package/dist/key-derivation/bip32.d.ts.map +1 -0
- package/dist/key-derivation/bip32.js +41 -0
- package/dist/key-derivation/bip39.d.ts +22 -0
- package/dist/key-derivation/bip39.d.ts.map +1 -0
- package/dist/key-derivation/bip39.js +57 -0
- package/dist/key-derivation/bytes.d.ts +19 -0
- package/dist/key-derivation/bytes.d.ts.map +1 -0
- package/dist/key-derivation/bytes.js +92 -0
- package/dist/key-derivation/hash.d.ts +3 -0
- package/dist/key-derivation/hash.d.ts.map +1 -0
- package/dist/key-derivation/hash.js +10 -0
- package/dist/key-derivation/index.d.ts +7 -0
- package/dist/key-derivation/index.d.ts.map +1 -0
- package/dist/key-derivation/index.js +6 -0
- package/dist/key-derivation/wallet-node.d.ts +47 -0
- package/dist/key-derivation/wallet-node.d.ts.map +1 -0
- package/dist/key-derivation/wallet-node.js +110 -0
- package/dist/keys.d.ts +0 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +0 -1
- package/dist/prover/config.d.ts +22 -53
- package/dist/prover/config.d.ts.map +1 -1
- package/dist/prover/config.js +22 -65
- package/dist/prover/prover.d.ts +20 -16
- package/dist/prover/prover.d.ts.map +1 -1
- package/dist/prover/prover.js +137 -262
- package/dist/prover/registry.d.ts +30 -3
- package/dist/prover/registry.d.ts.map +1 -1
- package/dist/prover/registry.js +51 -12
- package/dist/state/merkle/hydrator.d.ts +19 -21
- package/dist/state/merkle/hydrator.d.ts.map +1 -1
- package/dist/state/merkle/hydrator.js +27 -20
- package/dist/state/merkle/index.d.ts +1 -1
- package/dist/state/merkle/index.d.ts.map +1 -1
- package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
- package/dist/state/merkle/merkle-tree.js +7 -8
- package/dist/state/store/ciphertext-store.d.ts +0 -11
- package/dist/state/store/ciphertext-store.d.ts.map +1 -1
- package/dist/state/store/ciphertext-store.js +0 -26
- package/dist/state/store/index.d.ts +1 -1
- 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/job-store.js +37 -74
- package/dist/state/store/jobs.d.ts +30 -62
- package/dist/state/store/jobs.d.ts.map +1 -1
- package/dist/state/store/leaf-store.d.ts +0 -4
- package/dist/state/store/leaf-store.d.ts.map +1 -1
- package/dist/state/store/leaf-store.js +1 -11
- package/dist/state/store/note-store.d.ts +2 -6
- package/dist/state/store/note-store.d.ts.map +1 -1
- package/dist/state/store/note-store.js +4 -22
- package/dist/state/store/nullifier-store.d.ts +0 -9
- package/dist/state/store/nullifier-store.d.ts.map +1 -1
- package/dist/state/store/nullifier-store.js +1 -31
- package/dist/state/store/records.d.ts +0 -14
- package/dist/state/store/records.d.ts.map +1 -1
- package/dist/state/store/store.d.ts +8 -42
- package/dist/state/store/store.d.ts.map +1 -1
- package/dist/state/store/store.js +1 -158
- package/dist/storage/indexeddb.d.ts.map +1 -1
- package/dist/storage/indexeddb.js +32 -70
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +0 -10
- package/dist/transactions/deposit.d.ts +4 -6
- package/dist/transactions/deposit.d.ts.map +1 -1
- package/dist/transactions/deposit.js +85 -176
- package/dist/transactions/index.d.ts +3 -7
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +2 -5
- package/dist/transactions/note-selection.d.ts +1 -1
- package/dist/transactions/note-selection.d.ts.map +1 -1
- package/dist/transactions/note-selection.js +9 -14
- package/dist/transactions/note-sync.d.ts +8 -3
- package/dist/transactions/note-sync.d.ts.map +1 -1
- package/dist/transactions/note-sync.js +170 -476
- package/dist/transactions/reconcile.d.ts +3 -3
- package/dist/transactions/reconcile.d.ts.map +1 -1
- package/dist/transactions/reconcile.js +10 -27
- package/dist/transactions/transact.d.ts +5 -27
- package/dist/transactions/transact.d.ts.map +1 -1
- package/dist/transactions/transact.js +146 -286
- package/dist/transactions/transaction-planner.d.ts +2 -2
- package/dist/transactions/transaction-planner.d.ts.map +1 -1
- package/dist/transactions/transaction-planner.js +14 -18
- package/dist/transactions/types/deposit.d.ts +14 -36
- package/dist/transactions/types/deposit.d.ts.map +1 -1
- package/dist/transactions/types/domain.d.ts +0 -5
- package/dist/transactions/types/domain.d.ts.map +1 -1
- package/dist/transactions/types/options.d.ts +1 -18
- package/dist/transactions/types/options.d.ts.map +1 -1
- package/dist/transactions/types/planning.d.ts +0 -2
- package/dist/transactions/types/planning.d.ts.map +1 -1
- package/dist/transactions/types/state-stores.d.ts +13 -113
- package/dist/transactions/types/state-stores.d.ts.map +1 -1
- package/dist/transactions/types/transact.d.ts +17 -39
- package/dist/transactions/types/transact.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/amounts.d.ts +14 -1
- package/dist/utils/amounts.d.ts.map +1 -1
- package/dist/utils/amounts.js +39 -6
- package/dist/utils/async.d.ts +0 -9
- package/dist/utils/async.d.ts.map +1 -1
- package/dist/utils/async.js +0 -24
- package/dist/utils/bigint.d.ts +2 -0
- package/dist/utils/bigint.d.ts.map +1 -1
- package/dist/utils/bigint.js +17 -5
- package/dist/utils/crypto.d.ts +12 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +39 -0
- package/dist/utils/json-codec.js +1 -1
- package/dist/utils/polling.d.ts +0 -5
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/polling.js +0 -5
- package/dist/utils/random.d.ts +0 -5
- package/dist/utils/random.d.ts.map +1 -1
- package/dist/utils/random.js +0 -7
- package/dist/utils/secure-memory.d.ts.map +1 -0
- package/dist/utils/signature.js +1 -1
- package/dist/utils/validators.d.ts +3 -16
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +21 -28
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +11 -1
- package/package.json +11 -33
- package/README.md +0 -9
- package/dist/account/account.d.ts.map +0 -1
- package/dist/account/accounts.d.ts +0 -42
- package/dist/account/accounts.d.ts.map +0 -1
- package/dist/account/accounts.js +0 -119
- package/dist/account/seed.d.ts +0 -45
- package/dist/account/seed.d.ts.map +0 -1
- package/dist/account/seed.js +0 -91
- package/dist/account/serialization.d.ts +0 -6
- package/dist/account/serialization.d.ts.map +0 -1
- package/dist/account/serialization.js +0 -53
- package/dist/browser/index.js +0 -56217
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/wallet/index.js +0 -55942
- package/dist/browser/wallet/index.js.map +0 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -5
- package/dist/crypto/adapters/index.d.ts +0 -17
- package/dist/crypto/adapters/index.d.ts.map +0 -1
- package/dist/crypto/adapters/index.js +0 -53
- package/dist/crypto/adapters/polyfills.d.ts +0 -5
- package/dist/crypto/adapters/polyfills.d.ts.map +0 -1
- package/dist/crypto/adapters/polyfills.js +0 -8
- package/dist/crypto/encrypt.d.ts +0 -33
- package/dist/crypto/encrypt.d.ts.map +0 -1
- package/dist/crypto/encrypt.js +0 -84
- package/dist/crypto/secure-memory.d.ts.map +0 -1
- package/dist/keys/address.d.ts +0 -13
- package/dist/keys/address.d.ts.map +0 -1
- package/dist/keys/address.js +0 -55
- package/dist/keys/derive.d.ts +0 -37
- package/dist/keys/derive.d.ts.map +0 -1
- package/dist/keys/derive.js +0 -109
- package/dist/keys/hex.d.ts +0 -14
- package/dist/keys/hex.d.ts.map +0 -1
- package/dist/keys/hex.js +0 -47
- package/dist/keys/index.d.ts +0 -5
- package/dist/keys/index.d.ts.map +0 -1
- package/dist/keys/index.js +0 -4
- package/dist/keys/mnemonic.d.ts +0 -6
- package/dist/keys/mnemonic.d.ts.map +0 -1
- package/dist/keys/mnemonic.js +0 -16
- package/dist/prover/integrity.d.ts +0 -20
- package/dist/prover/integrity.d.ts.map +0 -1
- package/dist/prover/integrity.js +0 -93
- package/dist/transactions/adapter.d.ts +0 -31
- package/dist/transactions/adapter.d.ts.map +0 -1
- package/dist/transactions/adapter.js +0 -106
- package/dist/transactions/transfer-planner.d.ts +0 -37
- package/dist/transactions/transfer-planner.d.ts.map +0 -1
- package/dist/transactions/transfer-planner.js +0 -91
- package/dist/transactions/withdrawal-planner.d.ts +0 -58
- package/dist/transactions/withdrawal-planner.d.ts.map +0 -1
- package/dist/transactions/withdrawal-planner.js +0 -129
- package/dist/tsup.browser.config.d.ts +0 -7
- package/dist/tsup.browser.config.d.ts.map +0 -1
- package/dist/tsup.browser.config.js +0 -34
- package/dist/wallet/adapter.d.ts +0 -21
- package/dist/wallet/adapter.d.ts.map +0 -1
- package/dist/wallet/adapter.js +0 -210
- package/dist/wallet/burner/service.d.ts +0 -32
- package/dist/wallet/burner/service.d.ts.map +0 -1
- package/dist/wallet/burner/service.js +0 -121
- package/dist/wallet/burner/types.d.ts +0 -47
- package/dist/wallet/burner/types.d.ts.map +0 -1
- package/dist/wallet/burner/types.js +0 -1
- package/dist/wallet/index.d.ts +0 -20
- package/dist/wallet/index.d.ts.map +0 -1
- package/dist/wallet/index.js +0 -12
- package/dist/wallet/sdk.d.ts +0 -48
- package/dist/wallet/sdk.d.ts.map +0 -1
- package/dist/wallet/sdk.js +0 -706
- package/dist/wallet/types.d.ts +0 -457
- package/dist/wallet/types.d.ts.map +0 -1
- package/dist/wallet/types.js +0 -2
- package/dist/wallet/unlink-wallet.d.ts +0 -187
- package/dist/wallet/unlink-wallet.d.ts.map +0 -1
- package/dist/wallet/unlink-wallet.js +0 -345
- /package/dist/{crypto → utils}/secure-memory.d.ts +0 -0
- /package/dist/{crypto → utils}/secure-memory.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SpendingKeyPair, type ViewingKeyPair } from "../
|
|
1
|
+
import { type SpendingKeyPair, type ViewingKeyPair } from "../key-derivation/wallet-node.js";
|
|
2
2
|
import type { Storage } from "../types.js";
|
|
3
3
|
export type MasterSeedCrypto = {
|
|
4
4
|
encrypt(seed: Uint8Array): Promise<Uint8Array> | Uint8Array;
|
|
@@ -14,45 +14,14 @@ export type GenerateMasterSeedOptions = {
|
|
|
14
14
|
export declare const MASTER_SEED_LENGTH = 64;
|
|
15
15
|
export declare const MASTER_SEED_KEY = "cfg:wallet:master_seed/v1";
|
|
16
16
|
export declare const MASTER_MNEMONIC_KEY = "cfg:wallet:master_mnemonic/v1";
|
|
17
|
-
export type
|
|
17
|
+
export type ZkAccount = {
|
|
18
18
|
spendingKeyPair: SpendingKeyPair;
|
|
19
19
|
viewingKeyPair: ViewingKeyPair;
|
|
20
20
|
nullifyingKey: bigint;
|
|
21
21
|
masterPublicKey: bigint;
|
|
22
|
-
/** Bech32m address (0zk1...) for this account */
|
|
23
|
-
address: string;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* without any signing capability. Both Account and MultisigAccount satisfy this.
|
|
28
|
-
*/
|
|
29
|
-
export type AccountView = {
|
|
30
|
-
nullifyingKey: bigint;
|
|
31
|
-
masterPublicKey: bigint;
|
|
32
|
-
viewingKeyPair: ViewingKeyPair;
|
|
33
|
-
address: string;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Signing capability decoupled from account identity.
|
|
37
|
-
* Async to support multi-round protocols (FROST), hardware wallets, etc.
|
|
38
|
-
*/
|
|
39
|
-
export type Signer = {
|
|
40
|
-
publicKey: [bigint, bigint];
|
|
41
|
-
sign(message: bigint): Promise<{
|
|
42
|
-
R8: [bigint, bigint];
|
|
43
|
-
S: bigint;
|
|
44
|
-
}>;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Extract an AccountView from a full Account.
|
|
48
|
-
*/
|
|
49
|
-
export declare function toAccountView(account: Account): AccountView;
|
|
50
|
-
/**
|
|
51
|
-
* Create a Signer from a single spending key pair.
|
|
52
|
-
*/
|
|
53
|
-
export declare function createSingleKeySigner(privateKey: Uint8Array, pubkey: [bigint, bigint]): Signer;
|
|
54
|
-
export declare function deriveAccount(masterSeed: Uint8Array, accountIndex?: number): Account;
|
|
55
|
-
export declare function deriveAccountFromMnemonic(mnemonic: string, accountIndex?: number, password?: string): Account;
|
|
23
|
+
export declare function deriveZkAccount(masterSeed: Uint8Array, accountIndex?: number): Promise<ZkAccount>;
|
|
24
|
+
export declare function deriveZkAccountFromMnemonic(mnemonic: string, accountIndex?: number, password?: string): Promise<ZkAccount>;
|
|
56
25
|
export declare function generateMasterSeed({ storage, rng, crypto, overwrite, mnemonicPassphrase, }: GenerateMasterSeedOptions): Promise<Uint8Array>;
|
|
57
26
|
export declare function loadMasterSeed(storage: Storage, crypto?: MasterSeedCrypto): Promise<Uint8Array | null>;
|
|
58
27
|
export declare function storeMasterSeed(storage: Storage, seed: Uint8Array, crypto?: MasterSeedCrypto): Promise<void>;
|
|
@@ -66,4 +35,4 @@ export type ImportMasterMnemonicOptions = {
|
|
|
66
35
|
};
|
|
67
36
|
export declare function importMasterMnemonic({ storage, mnemonic, crypto, overwrite, password, }: ImportMasterMnemonicOptions): Promise<Uint8Array>;
|
|
68
37
|
export declare function storeMasterMnemonic(storage: Storage, mnemonic: string, crypto?: MasterSeedCrypto): Promise<void>;
|
|
69
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=zkAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkAccount.d.ts","sourceRoot":"","sources":["../../account/zkAccount.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC5D,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,UAAU,CAAC;IAC/B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAC3D,eAAO,MAAM,mBAAmB,kCAAkC,CAAC;AAOnE,MAAM,MAAM,SAAS,GAAG;IACtB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAsB,eAAe,CACnC,UAAU,EAAE,UAAU,EACtB,YAAY,GAAE,MAAU,GACvB,OAAO,CAAC,SAAS,CAAC,CAqBpB;AAED,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,MAAU,EACxB,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC,SAAS,CAAC,CAQpB;AAWD,wBAAsB,kBAAkB,CAAC,EACvC,OAAO,EACP,GAAG,EACH,MAAiC,EACjC,SAAiB,EACjB,kBAAkB,GACnB,EAAE,yBAAyB,GAAG,OAAO,CAAC,UAAU,CAAC,CA8BjD;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,gBAA2C,GAClD,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAK5B;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,gBAA2C,GAClD,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,gBAA2C,GAClD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUxB;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,QAAQ,EACR,MAAiC,EACjC,SAAiB,EACjB,QAAa,GACd,EAAE,2BAA2B,GAAG,OAAO,CAAC,UAAU,CAAC,CAenD;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,gBAA2C,GAClD,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -1,68 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Hex } from "../keys/hex.js";
|
|
6
|
-
import { Mnemonic } from "../keys/mnemonic.js";
|
|
7
|
-
import { signTransactMessage } from "../utils/signature.js";
|
|
1
|
+
import { Mnemonic } from "../key-derivation/bip39.js";
|
|
2
|
+
import { ByteUtils } from "../key-derivation/bytes.js";
|
|
3
|
+
import { deriveNodesFromSeed, WalletNode, } from "../key-derivation/wallet-node.js";
|
|
4
|
+
import { zeroize } from "../utils/secure-memory.js";
|
|
8
5
|
export const MASTER_SEED_LENGTH = 64;
|
|
9
6
|
export const MASTER_SEED_KEY = "cfg:wallet:master_seed/v1";
|
|
10
7
|
export const MASTER_MNEMONIC_KEY = "cfg:wallet:master_mnemonic/v1";
|
|
11
8
|
const MNEMONIC_ENTROPY_BYTES = 32;
|
|
12
9
|
const textEncoder = new TextEncoder();
|
|
13
10
|
const textDecoder = new TextDecoder();
|
|
14
|
-
|
|
15
|
-
* Extract an AccountView from a full Account.
|
|
16
|
-
*/
|
|
17
|
-
export function toAccountView(account) {
|
|
18
|
-
return {
|
|
19
|
-
nullifyingKey: account.nullifyingKey,
|
|
20
|
-
masterPublicKey: account.masterPublicKey,
|
|
21
|
-
viewingKeyPair: account.viewingKeyPair,
|
|
22
|
-
address: account.address,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Create a Signer from a single spending key pair.
|
|
27
|
-
*/
|
|
28
|
-
export function createSingleKeySigner(privateKey, pubkey) {
|
|
29
|
-
return {
|
|
30
|
-
publicKey: pubkey,
|
|
31
|
-
sign: async (message) => signTransactMessage(privateKey, message),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export function deriveAccount(masterSeed, accountIndex = 0) {
|
|
11
|
+
export async function deriveZkAccount(masterSeed, accountIndex = 0) {
|
|
35
12
|
const seed = normalizeMasterSeed(masterSeed);
|
|
36
13
|
if (!Number.isInteger(accountIndex) || accountIndex < 0) {
|
|
37
|
-
throw new
|
|
14
|
+
throw new Error("accountIndex must be a non-negative integer");
|
|
38
15
|
}
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
const { spending, viewing } = deriveNodesFromSeed(seed, accountIndex);
|
|
17
|
+
const spendingKeyPair = spending.getSpendingKeyPair();
|
|
18
|
+
const viewingKeyPair = await viewing.getViewingKeyPair();
|
|
19
|
+
const nullifyingKey = WalletNode.getNullifyingKey(viewingKeyPair.privateKey);
|
|
20
|
+
const masterPublicKey = WalletNode.getMasterPublicKey(spendingKeyPair.pubkey, nullifyingKey);
|
|
44
21
|
return {
|
|
45
|
-
spendingKeyPair
|
|
46
|
-
viewingKeyPair
|
|
47
|
-
nullifyingKey
|
|
48
|
-
masterPublicKey
|
|
49
|
-
address,
|
|
22
|
+
spendingKeyPair,
|
|
23
|
+
viewingKeyPair,
|
|
24
|
+
nullifyingKey,
|
|
25
|
+
masterPublicKey,
|
|
50
26
|
};
|
|
51
27
|
}
|
|
52
|
-
export function
|
|
28
|
+
export async function deriveZkAccountFromMnemonic(mnemonic, accountIndex = 0, password = "") {
|
|
53
29
|
const normalized = normalizeMnemonic(mnemonic);
|
|
54
30
|
const seed = mnemonicToSeed(normalized, password);
|
|
55
31
|
try {
|
|
56
|
-
return
|
|
32
|
+
return await deriveZkAccount(seed, accountIndex);
|
|
57
33
|
}
|
|
58
34
|
finally {
|
|
59
35
|
zeroize(seed);
|
|
60
36
|
}
|
|
61
37
|
}
|
|
62
|
-
/** Passthrough crypto, storage handles buffer isolation */
|
|
63
38
|
const identityMasterSeedCrypto = {
|
|
64
|
-
encrypt
|
|
65
|
-
|
|
39
|
+
encrypt(seed) {
|
|
40
|
+
return clone(seed);
|
|
41
|
+
},
|
|
42
|
+
decrypt(payload) {
|
|
43
|
+
return clone(payload);
|
|
44
|
+
},
|
|
66
45
|
};
|
|
67
46
|
export async function generateMasterSeed({ storage, rng, crypto = identityMasterSeedCrypto, overwrite = false, mnemonicPassphrase, }) {
|
|
68
47
|
if (!overwrite) {
|
|
@@ -78,10 +57,10 @@ export async function generateMasterSeed({ storage, rng, crypto = identityMaster
|
|
|
78
57
|
}
|
|
79
58
|
const entropy = rng(MNEMONIC_ENTROPY_BYTES);
|
|
80
59
|
if (entropy.length !== MNEMONIC_ENTROPY_BYTES) {
|
|
81
|
-
throw new
|
|
60
|
+
throw new Error(`mnemonic entropy must be ${MNEMONIC_ENTROPY_BYTES} bytes`);
|
|
82
61
|
}
|
|
83
62
|
try {
|
|
84
|
-
const mnemonic = Mnemonic.fromEntropy(
|
|
63
|
+
const mnemonic = Mnemonic.fromEntropy(ByteUtils.bytesToHex(entropy));
|
|
85
64
|
await storeMasterMnemonic(storage, mnemonic, crypto);
|
|
86
65
|
const seed = mnemonicToSeed(mnemonic, mnemonicPassphrase);
|
|
87
66
|
await storeMasterSeed(storage, seed, crypto);
|
|
@@ -102,9 +81,9 @@ export async function storeMasterSeed(storage, seed, crypto = identityMasterSeed
|
|
|
102
81
|
const normalized = normalizeMasterSeed(seed);
|
|
103
82
|
const encrypted = await crypto.encrypt(normalized);
|
|
104
83
|
if (!(encrypted instanceof Uint8Array)) {
|
|
105
|
-
throw new
|
|
84
|
+
throw new Error("master seed encryptor must return Uint8Array");
|
|
106
85
|
}
|
|
107
|
-
await storage.put(MASTER_SEED_KEY, encrypted);
|
|
86
|
+
await storage.put(MASTER_SEED_KEY, clone(encrypted));
|
|
108
87
|
}
|
|
109
88
|
export async function loadMasterMnemonic(storage, crypto = identityMasterSeedCrypto) {
|
|
110
89
|
const stored = await storage.get(MASTER_MNEMONIC_KEY);
|
|
@@ -123,7 +102,7 @@ export async function importMasterMnemonic({ storage, mnemonic, crypto = identit
|
|
|
123
102
|
if (!overwrite) {
|
|
124
103
|
const existing = await loadMasterMnemonic(storage, crypto);
|
|
125
104
|
if (existing) {
|
|
126
|
-
throw new
|
|
105
|
+
throw new Error("master mnemonic already exists; set overwrite to true to replace it");
|
|
127
106
|
}
|
|
128
107
|
}
|
|
129
108
|
const normalized = normalizeMnemonic(mnemonic);
|
|
@@ -136,28 +115,30 @@ export async function storeMasterMnemonic(storage, mnemonic, crypto = identityMa
|
|
|
136
115
|
const normalized = normalizeMnemonic(mnemonic);
|
|
137
116
|
const encrypted = await crypto.encrypt(textEncoder.encode(normalized));
|
|
138
117
|
if (!(encrypted instanceof Uint8Array)) {
|
|
139
|
-
throw new
|
|
118
|
+
throw new Error("master mnemonic encryptor must return Uint8Array");
|
|
140
119
|
}
|
|
141
|
-
await storage.put(MASTER_MNEMONIC_KEY, encrypted);
|
|
120
|
+
await storage.put(MASTER_MNEMONIC_KEY, clone(encrypted));
|
|
121
|
+
}
|
|
122
|
+
function clone(bytes) {
|
|
123
|
+
return new Uint8Array(bytes);
|
|
142
124
|
}
|
|
143
|
-
/** Validates seed format. Storage handles buffer isolation on put/get. */
|
|
144
125
|
function normalizeMasterSeed(seed) {
|
|
145
126
|
if (!(seed instanceof Uint8Array)) {
|
|
146
|
-
throw new
|
|
127
|
+
throw new Error("master seed must be a Uint8Array");
|
|
147
128
|
}
|
|
148
129
|
if (seed.length !== MASTER_SEED_LENGTH) {
|
|
149
|
-
throw new
|
|
130
|
+
throw new Error(`master seed must be ${MASTER_SEED_LENGTH} bytes`);
|
|
150
131
|
}
|
|
151
|
-
return seed;
|
|
132
|
+
return clone(seed);
|
|
152
133
|
}
|
|
153
134
|
function normalizeMnemonic(mnemonic) {
|
|
154
135
|
const formatted = mnemonic.trim().replace(/\s+/g, " ");
|
|
155
136
|
if (!Mnemonic.validate(formatted)) {
|
|
156
|
-
throw new
|
|
137
|
+
throw new Error("invalid BIP-39 mnemonic phrase");
|
|
157
138
|
}
|
|
158
139
|
return formatted;
|
|
159
140
|
}
|
|
160
141
|
function mnemonicToSeed(mnemonic, password = "") {
|
|
161
142
|
const seedHex = Mnemonic.toSeed(mnemonic, password);
|
|
162
|
-
return
|
|
143
|
+
return ByteUtils.hexStringToBytes(seedHex);
|
|
163
144
|
}
|
package/dist/circuits.json
CHANGED
|
@@ -1,74 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
"joinsplit_1x1_16": {
|
|
3
|
-
"file": "joinsplit",
|
|
4
|
-
"template": "JoinSplit",
|
|
5
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
6
|
-
"params": [1, 1, 16]
|
|
7
|
-
},
|
|
8
|
-
"joinsplit_1x2_16": {
|
|
9
|
-
"file": "joinsplit",
|
|
10
|
-
"template": "JoinSplit",
|
|
11
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
12
|
-
"params": [1, 2, 16]
|
|
13
|
-
},
|
|
14
|
-
"joinsplit_2x1_16": {
|
|
15
|
-
"file": "joinsplit",
|
|
16
|
-
"template": "JoinSplit",
|
|
17
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
18
|
-
"params": [2, 1, 16]
|
|
19
|
-
},
|
|
20
|
-
"joinsplit_2x2_16": {
|
|
21
|
-
"file": "joinsplit",
|
|
22
|
-
"template": "JoinSplit",
|
|
23
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
24
|
-
"params": [2, 2, 16]
|
|
25
|
-
},
|
|
26
|
-
"joinsplit_2x3_16": {
|
|
27
|
-
"file": "joinsplit",
|
|
28
|
-
"template": "JoinSplit",
|
|
29
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
30
|
-
"params": [2, 3, 16]
|
|
31
|
-
},
|
|
32
|
-
"joinsplit_3x1_16": {
|
|
33
|
-
"file": "joinsplit",
|
|
34
|
-
"template": "JoinSplit",
|
|
35
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
36
|
-
"params": [3, 1, 16]
|
|
37
|
-
},
|
|
38
|
-
"joinsplit_3x2_16": {
|
|
39
|
-
"file": "joinsplit",
|
|
40
|
-
"template": "JoinSplit",
|
|
41
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
42
|
-
"params": [3, 2, 16]
|
|
43
|
-
},
|
|
44
2
|
"joinsplit_3x3_16": {
|
|
45
3
|
"file": "joinsplit",
|
|
46
4
|
"template": "JoinSplit",
|
|
47
5
|
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
48
6
|
"params": [3, 3, 16]
|
|
49
7
|
},
|
|
50
|
-
"
|
|
51
|
-
"file": "joinsplit",
|
|
52
|
-
"template": "JoinSplit",
|
|
53
|
-
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
54
|
-
"params": [4, 1, 16]
|
|
55
|
-
},
|
|
56
|
-
"joinsplit_4x2_16": {
|
|
8
|
+
"joinsplit_2x3_16": {
|
|
57
9
|
"file": "joinsplit",
|
|
58
10
|
"template": "JoinSplit",
|
|
59
11
|
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
60
|
-
"params": [
|
|
12
|
+
"params": [2, 3, 16]
|
|
61
13
|
},
|
|
62
|
-
"
|
|
14
|
+
"joinsplit_1x2_16": {
|
|
63
15
|
"file": "joinsplit",
|
|
64
16
|
"template": "JoinSplit",
|
|
65
17
|
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
66
|
-
"params": [
|
|
18
|
+
"params": [1, 2, 16]
|
|
67
19
|
},
|
|
68
|
-
"
|
|
20
|
+
"joinsplit_1x1_16": {
|
|
69
21
|
"file": "joinsplit",
|
|
70
22
|
"template": "JoinSplit",
|
|
71
23
|
"pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
72
|
-
"params": [
|
|
24
|
+
"params": [1, 1, 16]
|
|
73
25
|
}
|
|
74
26
|
}
|
|
@@ -14,17 +14,12 @@ export type SubmitRelayResponse = {
|
|
|
14
14
|
accepted: boolean;
|
|
15
15
|
message?: string | null;
|
|
16
16
|
};
|
|
17
|
-
export type RelayState = "pending" | "broadcasting" | "
|
|
18
|
-
export type TransactionReceipt = {
|
|
19
|
-
blockNumber?: number;
|
|
20
|
-
blockHash?: string;
|
|
21
|
-
transactionIndex?: number;
|
|
22
|
-
};
|
|
17
|
+
export type RelayState = "pending" | "broadcasting" | "succeeded" | "failed" | "dead";
|
|
23
18
|
export type RelayStatusResponse = {
|
|
24
19
|
id: string;
|
|
25
20
|
state: RelayState;
|
|
26
21
|
txHash?: string | null;
|
|
27
|
-
receipt?:
|
|
22
|
+
receipt?: unknown;
|
|
28
23
|
error?: string | null;
|
|
29
24
|
};
|
|
30
25
|
type BroadcasterClientDeps = {
|
|
@@ -33,7 +28,6 @@ type BroadcasterClientDeps = {
|
|
|
33
28
|
export declare function createBroadcasterClient(baseUrl: string, deps: BroadcasterClientDeps): {
|
|
34
29
|
submitRelay(params: SubmitRelayParams): Promise<SubmitRelayResponse>;
|
|
35
30
|
getRelayStatus(relayId: string): Promise<RelayStatusResponse>;
|
|
36
|
-
getRelayStatusBatch(relayIds: string[]): Promise<RelayStatusResponse[]>;
|
|
37
31
|
};
|
|
38
32
|
export {};
|
|
39
33
|
//# sourceMappingURL=broadcaster.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcaster.d.ts","sourceRoot":"","sources":["../../clients/broadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,cAAc,GACd,WAAW,GACX,
|
|
1
|
+
{"version":3,"file":"broadcaster.d.ts","sourceRoot":"","sources":["../../clients/broadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,cAAc,GACd,WAAW,GACX,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,qBAAqB;wBAKC,iBAAiB;4BAYb,MAAM;EAOvC"}
|
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
import { createJsonHttpClient } from "./http.js";
|
|
2
|
-
const RELAY_STATUS_BATCH_LIMIT = 50;
|
|
3
|
-
function toRelayStatusResponse(raw) {
|
|
4
|
-
return {
|
|
5
|
-
id: raw.id,
|
|
6
|
-
state: raw.state,
|
|
7
|
-
txHash: raw.tx_hash,
|
|
8
|
-
receipt: raw.receipt,
|
|
9
|
-
error: raw.error,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function chunkArray(items, chunkSize) {
|
|
13
|
-
const chunks = [];
|
|
14
|
-
for (let i = 0; i < items.length; i += chunkSize) {
|
|
15
|
-
chunks.push(items.slice(i, i + chunkSize));
|
|
16
|
-
}
|
|
17
|
-
return chunks;
|
|
18
|
-
}
|
|
19
2
|
export function createBroadcasterClient(baseUrl, deps) {
|
|
20
3
|
const http = createJsonHttpClient(baseUrl, deps);
|
|
21
4
|
return {
|
|
@@ -31,24 +14,10 @@ export function createBroadcasterClient(baseUrl, deps) {
|
|
|
31
14
|
});
|
|
32
15
|
},
|
|
33
16
|
async getRelayStatus(relayId) {
|
|
34
|
-
|
|
17
|
+
return http.request({
|
|
35
18
|
method: "GET",
|
|
36
19
|
path: `/relays/${relayId}`,
|
|
37
20
|
});
|
|
38
|
-
return toRelayStatusResponse(raw);
|
|
39
|
-
},
|
|
40
|
-
async getRelayStatusBatch(relayIds) {
|
|
41
|
-
if (relayIds.length === 0)
|
|
42
|
-
return [];
|
|
43
|
-
const chunks = chunkArray(relayIds, RELAY_STATUS_BATCH_LIMIT);
|
|
44
|
-
const results = await Promise.all(chunks.map(async (chunk) => {
|
|
45
|
-
const raw = await http.request({
|
|
46
|
-
method: "GET",
|
|
47
|
-
path: `/relays/batch?ids=${chunk.join(",")}`,
|
|
48
|
-
});
|
|
49
|
-
return raw.relays.map(toRelayStatusResponse);
|
|
50
|
-
}));
|
|
51
|
-
return results.flat();
|
|
52
21
|
},
|
|
53
22
|
};
|
|
54
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../clients/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../clients/http.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,aAAa,CAAC,EAAE,SAAS,GACxB,OAAO,KAAK,GAAG,SAAS,CAE1B;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAClD,CAAC;AAEF,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAK3D;AAWD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GACjB,cAAc,CA+ChB"}
|
package/dist/clients/http.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import ky, { TimeoutError } from "ky";
|
|
2
|
-
import { InitializationError } from "../errors.js";
|
|
1
|
+
import ky, { HTTPError, TimeoutError } from "ky";
|
|
3
2
|
/**
|
|
4
3
|
* Resolve fetch implementation from options or global.
|
|
5
4
|
* @param providedFetch - Optional fetch implementation
|
|
@@ -28,24 +27,20 @@ async function readErrorBodySafe(res) {
|
|
|
28
27
|
}
|
|
29
28
|
export function createJsonHttpClient(baseUrl, deps) {
|
|
30
29
|
if (!baseUrl)
|
|
31
|
-
throw new
|
|
30
|
+
throw new Error("baseUrl is required");
|
|
32
31
|
if (!deps?.fetch)
|
|
33
|
-
throw new
|
|
32
|
+
throw new Error("deps.fetch is required");
|
|
34
33
|
// Ensure `fetch` is invoked with a global `this` to avoid "Illegal invocation"
|
|
35
34
|
// errors in some browser environments when the function is extracted. // TODO: can we fix this in another way?
|
|
36
35
|
const fetchImpl = (...args) => deps.fetch.apply(globalThis, args);
|
|
37
36
|
const api = ky.create({
|
|
38
37
|
prefixUrl: baseUrl.replace(/\/+$/, ""),
|
|
39
38
|
fetch: fetchImpl,
|
|
40
|
-
// Disable ky's automatic error throwing to prevent browser DevTools
|
|
41
|
-
// from logging expected 404s as network errors
|
|
42
|
-
throwHttpErrors: false,
|
|
43
39
|
});
|
|
44
40
|
return {
|
|
45
41
|
async request(opts) {
|
|
46
|
-
let res;
|
|
47
42
|
try {
|
|
48
|
-
res =
|
|
43
|
+
const res = api(opts.path.replace(/^\//, ""), {
|
|
49
44
|
method: opts.method,
|
|
50
45
|
searchParams: opts.query,
|
|
51
46
|
json: opts.json,
|
|
@@ -53,20 +48,18 @@ export function createJsonHttpClient(baseUrl, deps) {
|
|
|
53
48
|
headers: opts.headers,
|
|
54
49
|
signal: opts.signal,
|
|
55
50
|
});
|
|
51
|
+
return await res.json();
|
|
56
52
|
}
|
|
57
53
|
catch (err) {
|
|
58
|
-
|
|
54
|
+
if (err instanceof HTTPError) {
|
|
55
|
+
const body = await readErrorBodySafe(err.response);
|
|
56
|
+
throw new HttpError(`HTTP ${err.response.status} ${err.response.statusText}`.trim(), err.response.status, body);
|
|
57
|
+
}
|
|
59
58
|
if (err instanceof TimeoutError) {
|
|
60
59
|
throw new HttpError("HTTP timeout", 408, null);
|
|
61
60
|
}
|
|
62
61
|
throw new HttpError(err instanceof Error ? err.message : "Network error", 0, null);
|
|
63
62
|
}
|
|
64
|
-
// HTTP status errors handled outside try-catch - no redundant catch/rethrow
|
|
65
|
-
if (!res.ok) {
|
|
66
|
-
const body = await readErrorBodySafe(res);
|
|
67
|
-
throw new HttpError(`HTTP ${res.status} ${res.statusText}`.trim(), res.status, body);
|
|
68
|
-
}
|
|
69
|
-
return (await res.json());
|
|
70
63
|
},
|
|
71
64
|
};
|
|
72
65
|
}
|
|
@@ -2,16 +2,11 @@ import type { FetchLike } from "./http.js";
|
|
|
2
2
|
export type CommitmentRecord = {
|
|
3
3
|
index: number;
|
|
4
4
|
commitment: string;
|
|
5
|
-
ephemeralKey: string;
|
|
6
5
|
ciphertext: [string, string, string];
|
|
7
6
|
root: string;
|
|
8
7
|
txHash: string;
|
|
9
8
|
insertedAt: number;
|
|
10
9
|
eventType: string;
|
|
11
|
-
adapterNpk?: string;
|
|
12
|
-
adapterToken?: string;
|
|
13
|
-
adapterAmount?: string;
|
|
14
|
-
adapterRandom?: string;
|
|
15
10
|
};
|
|
16
11
|
export type IndexerNullifierRecord = {
|
|
17
12
|
nullifier: string;
|
|
@@ -37,23 +32,13 @@ export type GetNullifierParams = {
|
|
|
37
32
|
chainId: number;
|
|
38
33
|
nullifier: string;
|
|
39
34
|
};
|
|
40
|
-
export type CheckNullifiersParams = {
|
|
41
|
-
chainId: number;
|
|
42
|
-
nullifiers: string[];
|
|
43
|
-
};
|
|
44
35
|
type IndexerClientDeps = {
|
|
45
36
|
fetch: FetchLike;
|
|
46
37
|
};
|
|
47
38
|
export declare function createIndexerClient(baseUrl: string, deps: IndexerClientDeps): {
|
|
48
39
|
fetchCommitmentBatch(params: FetchCommitmentsParams): Promise<CommitmentBatchResponse>;
|
|
49
40
|
getCommitment(params: GetCommitmentParams): Promise<CommitmentRecord>;
|
|
50
|
-
/**
|
|
51
|
-
* Like getCommitment but returns null when the commitment doesn't exist.
|
|
52
|
-
* Used for polling pending deposits without generating console errors.
|
|
53
|
-
*/
|
|
54
|
-
tryGetCommitment(params: GetCommitmentParams): Promise<CommitmentRecord | null>;
|
|
55
41
|
getNullifier(params: GetNullifierParams): Promise<IndexerNullifierRecord | null>;
|
|
56
|
-
checkNullifiers(params: CheckNullifiersParams): Promise<IndexerNullifierRecord[]>;
|
|
57
42
|
getNullifierCount(chainId: number): Promise<number>;
|
|
58
43
|
};
|
|
59
44
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../clients/indexer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../clients/indexer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAe3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AASF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAQF,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;iCA0B9D,sBAAsB,GAC7B,OAAO,CAAC,uBAAuB,CAAC;0BAgBzB,mBAAmB,GAC1B,OAAO,CAAC,gBAAgB,CAAC;yBAQlB,kBAAkB,GACzB,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC;+BAcR,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;EAQ5D"}
|
package/dist/clients/indexer.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNotFoundError } from "../utils/async.js";
|
|
2
|
+
import { createJsonHttpClient } from "./http.js";
|
|
2
3
|
export function createIndexerClient(baseUrl, deps) {
|
|
3
4
|
const http = createJsonHttpClient(baseUrl, deps);
|
|
5
|
+
// Converts the snake_case record from the REST API into the camelCase shape
|
|
6
|
+
// the rest of the SDK consumes.
|
|
4
7
|
const normalizeRecord = (record) => ({
|
|
5
8
|
index: record.leaf_index,
|
|
6
9
|
commitment: record.commitment,
|
|
7
|
-
ephemeralKey: record.ephemeral_key,
|
|
8
10
|
ciphertext: [...record.ciphertext],
|
|
9
11
|
root: record.root,
|
|
10
12
|
txHash: record.tx_hash,
|
|
11
13
|
insertedAt: record.inserted_at,
|
|
12
14
|
eventType: record.event_type ?? "unknown",
|
|
13
|
-
adapterNpk: record.adapter_npk,
|
|
14
|
-
adapterToken: record.adapter_token,
|
|
15
|
-
adapterAmount: record.adapter_amount,
|
|
16
|
-
adapterRandom: record.adapter_random,
|
|
17
15
|
});
|
|
18
16
|
const normalizeNullifierRecord = (record) => ({
|
|
19
17
|
nullifier: record.nullifier,
|
|
@@ -42,51 +40,22 @@ export function createIndexerClient(baseUrl, deps) {
|
|
|
42
40
|
method: "GET",
|
|
43
41
|
path: `/chains/${params.chainId}/commitments/${params.commitment}`,
|
|
44
42
|
});
|
|
45
|
-
if (!raw) {
|
|
46
|
-
throw new HttpError("commitment not found", 404, null);
|
|
47
|
-
}
|
|
48
43
|
return normalizeRecord(raw);
|
|
49
44
|
},
|
|
50
|
-
/**
|
|
51
|
-
* Like getCommitment but returns null when the commitment doesn't exist.
|
|
52
|
-
* Used for polling pending deposits without generating console errors.
|
|
53
|
-
*/
|
|
54
|
-
async tryGetCommitment(params) {
|
|
55
|
-
const raw = await http.request({
|
|
56
|
-
method: "GET",
|
|
57
|
-
path: `/chains/${params.chainId}/commitments/${params.commitment}`,
|
|
58
|
-
});
|
|
59
|
-
return raw ? normalizeRecord(raw) : null;
|
|
60
|
-
},
|
|
61
45
|
async getNullifier(params) {
|
|
62
|
-
|
|
63
|
-
method: "GET",
|
|
64
|
-
path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
|
|
65
|
-
});
|
|
66
|
-
return raw ? normalizeNullifierRecord(raw) : null;
|
|
67
|
-
},
|
|
68
|
-
async checkNullifiers(params) {
|
|
69
|
-
const CHUNK_SIZE = 1000;
|
|
70
|
-
if (params.nullifiers.length <= CHUNK_SIZE) {
|
|
46
|
+
try {
|
|
71
47
|
const raw = await http.request({
|
|
72
|
-
method: "
|
|
73
|
-
path: `/chains/${params.chainId}/nullifiers
|
|
74
|
-
json: { nullifiers: params.nullifiers },
|
|
48
|
+
method: "GET",
|
|
49
|
+
path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
|
|
75
50
|
});
|
|
76
|
-
return raw
|
|
51
|
+
return normalizeNullifierRecord(raw);
|
|
77
52
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
method: "POST",
|
|
84
|
-
path: `/chains/${params.chainId}/nullifiers/check`,
|
|
85
|
-
json: { nullifiers: chunk },
|
|
86
|
-
});
|
|
87
|
-
results.push(...raw.found.map(normalizeNullifierRecord));
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (isNotFoundError(err)) {
|
|
55
|
+
return null; // Nullifier not spent on-chain
|
|
56
|
+
}
|
|
57
|
+
throw err;
|
|
88
58
|
}
|
|
89
|
-
return results;
|
|
90
59
|
},
|
|
91
60
|
async getNullifierCount(chainId) {
|
|
92
61
|
const raw = await http.request({
|
package/dist/config.d.ts
CHANGED
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface EnvironmentConfig {
|
|
6
|
-
gatewayUrl: string;
|
|
7
|
-
poolAddress: string;
|
|
8
|
-
artifactVersion: string;
|
|
9
|
-
artifactBaseUrl?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Service configuration with broadcaster and indexer URLs.
|
|
13
|
-
*/
|
|
14
|
-
export interface ServiceConfig {
|
|
1
|
+
export declare const serviceConfig: {
|
|
2
|
+
/**
|
|
3
|
+
* Base URL for the Broadcaster HTTP API (default: http://localhost:8081).
|
|
4
|
+
*/
|
|
15
5
|
broadcasterBaseUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Base URL for the Indexer HTTP API (default: http://localhost:8082).
|
|
8
|
+
*/
|
|
16
9
|
indexerBaseUrl: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
* Fetch environment configuration from the hosted network config file.
|
|
20
|
-
*
|
|
21
|
-
* @param env - The environment to fetch config for
|
|
22
|
-
* @returns Promise resolving to the environment configuration
|
|
23
|
-
* @throws If fetch fails or environment is not found
|
|
24
|
-
*/
|
|
25
|
-
export declare function fetchEnvironmentConfig(env: Environment): Promise<EnvironmentConfig>;
|
|
26
|
-
/**
|
|
27
|
-
* Create service configuration from a gateway URL.
|
|
28
|
-
*
|
|
29
|
-
* @param gatewayUrl - The base gateway URL
|
|
30
|
-
* @returns Service configuration with broadcaster and indexer URLs
|
|
31
|
-
*/
|
|
32
|
-
export declare function createServiceConfig(gatewayUrl: string): ServiceConfig;
|
|
10
|
+
};
|
|
11
|
+
export type ServiceConfig = typeof serviceConfig;
|
|
33
12
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,aAAa;IACxB;;OAEG;;IAGH;;OAEG;;CAGJ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC"}
|