@unlink-xyz/core 0.1.3-canary.e85e37f → 0.1.3-canary.fc5edd1
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 -7
- package/dist/account/zkAccount.d.ts.map +1 -0
- package/dist/account/{account.js → zkAccount.js} +37 -35
- package/dist/circuits.json +6 -54
- package/dist/clients/broadcaster.d.ts +2 -7
- package/dist/clients/broadcaster.d.ts.map +1 -1
- package/dist/clients/broadcaster.js +1 -8
- package/dist/clients/http.d.ts.map +1 -1
- package/dist/clients/http.js +9 -16
- package/dist/clients/indexer.d.ts +0 -10
- package/dist/clients/indexer.d.ts.map +1 -1
- package/dist/clients/indexer.js +13 -39
- package/dist/config.d.ts +4 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -8
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -3
- package/dist/crypto-adapters/index.d.ts.map +1 -1
- package/dist/crypto-adapters/index.js +1 -2
- package/dist/errors.d.ts +0 -9
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -18
- package/dist/history/service.d.ts +4 -4
- package/dist/history/service.d.ts.map +1 -1
- package/dist/history/service.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- 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/prover/prover.d.ts.map +1 -1
- package/dist/prover/prover.js +18 -18
- 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.map +1 -1
- package/dist/state/merkle/hydrator.js +2 -3
- package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
- package/dist/state/merkle/merkle-tree.js +6 -7
- package/dist/state/store/ciphertext-store.d.ts +0 -4
- package/dist/state/store/ciphertext-store.d.ts.map +1 -1
- package/dist/state/store/ciphertext-store.js +0 -12
- 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 +38 -61
- package/dist/state/store/jobs.d.ts +18 -52
- package/dist/state/store/jobs.d.ts.map +1 -1
- 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 +0 -32
- package/dist/state/store/records.d.ts +0 -6
- package/dist/state/store/records.d.ts.map +1 -1
- package/dist/state/store/store.d.ts +8 -24
- package/dist/state/store/store.d.ts.map +1 -1
- package/dist/state/store/store.js +1 -89
- package/dist/storage/indexeddb.js +1 -1
- package/dist/transactions/deposit.d.ts +4 -6
- package/dist/transactions/deposit.d.ts.map +1 -1
- package/dist/transactions/deposit.js +82 -174
- package/dist/transactions/index.d.ts +4 -5
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +3 -4
- 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 +159 -308
- package/dist/transactions/reconcile.d.ts +2 -2
- package/dist/transactions/reconcile.d.ts.map +1 -1
- package/dist/transactions/reconcile.js +8 -9
- package/dist/transactions/transact.d.ts +2 -5
- package/dist/transactions/transact.d.ts.map +1 -1
- package/dist/transactions/transact.js +148 -204
- package/dist/transactions/transaction-planner.d.ts +1 -1
- package/dist/transactions/transaction-planner.d.ts.map +1 -1
- package/dist/transactions/transaction-planner.js +8 -9
- package/dist/transactions/types/deposit.d.ts +14 -36
- package/dist/transactions/types/deposit.d.ts.map +1 -1
- package/dist/transactions/types/options.d.ts +0 -4
- package/dist/transactions/types/options.d.ts.map +1 -1
- package/dist/transactions/types/state-stores.d.ts +9 -61
- package/dist/transactions/types/state-stores.d.ts.map +1 -1
- package/dist/transactions/types/transact.d.ts +17 -32
- package/dist/transactions/types/transact.d.ts.map +1 -1
- package/dist/transactions/withdrawal-planner.d.ts +28 -25
- package/dist/transactions/withdrawal-planner.d.ts.map +1 -1
- package/dist/transactions/withdrawal-planner.js +47 -76
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/amounts.d.ts +2 -2
- package/dist/utils/amounts.js +11 -11
- 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.js +7 -7
- package/dist/utils/crypto.d.ts +3 -9
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +5 -11
- 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/validators.d.ts +3 -16
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +19 -29
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +7 -2
- package/package.json +9 -21
- package/dist/account/account.d.ts.map +0 -1
- package/dist/browser/index.js +0 -108202
- package/dist/browser/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/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 -112
- package/dist/keys/hex.d.ts +0 -17
- package/dist/keys/hex.d.ts.map +0 -1
- package/dist/keys/hex.js +0 -66
- 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 -8
- package/dist/keys/mnemonic.d.ts.map +0 -1
- package/dist/keys/mnemonic.js +0 -23
- package/dist/transactions/transfer-planner.d.ts +0 -36
- package/dist/transactions/transfer-planner.d.ts.map +0 -1
- package/dist/transactions/transfer-planner.js +0 -85
- 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
|
@@ -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,16 +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
|
-
export declare function
|
|
26
|
-
export declare function
|
|
23
|
+
export declare function deriveZkAccount(masterSeed: Uint8Array, accountIndex?: number): Promise<ZkAccount>;
|
|
24
|
+
export declare function deriveZkAccountFromMnemonic(mnemonic: string, accountIndex?: number, password?: string): Promise<ZkAccount>;
|
|
27
25
|
export declare function generateMasterSeed({ storage, rng, crypto, overwrite, mnemonicPassphrase, }: GenerateMasterSeedOptions): Promise<Uint8Array>;
|
|
28
26
|
export declare function loadMasterSeed(storage: Storage, crypto?: MasterSeedCrypto): Promise<Uint8Array | null>;
|
|
29
27
|
export declare function storeMasterSeed(storage: Storage, seed: Uint8Array, crypto?: MasterSeedCrypto): Promise<void>;
|
|
@@ -37,4 +35,4 @@ export type ImportMasterMnemonicOptions = {
|
|
|
37
35
|
};
|
|
38
36
|
export declare function importMasterMnemonic({ storage, mnemonic, crypto, overwrite, password, }: ImportMasterMnemonicOptions): Promise<Uint8Array>;
|
|
39
37
|
export declare function storeMasterMnemonic(storage: Storage, mnemonic: string, crypto?: MasterSeedCrypto): Promise<void>;
|
|
40
|
-
//# 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,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Hex } from "../keys/hex.js";
|
|
5
|
-
import { Mnemonic } from "../keys/mnemonic.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";
|
|
6
4
|
import { zeroize } from "../utils/secure-memory.js";
|
|
7
5
|
export const MASTER_SEED_LENGTH = 64;
|
|
8
6
|
export const MASTER_SEED_KEY = "cfg:wallet:master_seed/v1";
|
|
@@ -10,38 +8,40 @@ export const MASTER_MNEMONIC_KEY = "cfg:wallet:master_mnemonic/v1";
|
|
|
10
8
|
const MNEMONIC_ENTROPY_BYTES = 32;
|
|
11
9
|
const textEncoder = new TextEncoder();
|
|
12
10
|
const textDecoder = new TextDecoder();
|
|
13
|
-
export async function
|
|
11
|
+
export async function deriveZkAccount(masterSeed, accountIndex = 0) {
|
|
14
12
|
const seed = normalizeMasterSeed(masterSeed);
|
|
15
13
|
if (!Number.isInteger(accountIndex) || accountIndex < 0) {
|
|
16
|
-
throw new
|
|
14
|
+
throw new Error("accountIndex must be a non-negative integer");
|
|
17
15
|
}
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
21
|
return {
|
|
24
|
-
spendingKeyPair
|
|
25
|
-
viewingKeyPair
|
|
26
|
-
nullifyingKey
|
|
27
|
-
masterPublicKey
|
|
28
|
-
address,
|
|
22
|
+
spendingKeyPair,
|
|
23
|
+
viewingKeyPair,
|
|
24
|
+
nullifyingKey,
|
|
25
|
+
masterPublicKey,
|
|
29
26
|
};
|
|
30
27
|
}
|
|
31
|
-
export async function
|
|
28
|
+
export async function deriveZkAccountFromMnemonic(mnemonic, accountIndex = 0, password = "") {
|
|
32
29
|
const normalized = normalizeMnemonic(mnemonic);
|
|
33
30
|
const seed = mnemonicToSeed(normalized, password);
|
|
34
31
|
try {
|
|
35
|
-
return await
|
|
32
|
+
return await deriveZkAccount(seed, accountIndex);
|
|
36
33
|
}
|
|
37
34
|
finally {
|
|
38
35
|
zeroize(seed);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
/** Passthrough crypto, storage handles buffer isolation */
|
|
42
38
|
const identityMasterSeedCrypto = {
|
|
43
|
-
encrypt
|
|
44
|
-
|
|
39
|
+
encrypt(seed) {
|
|
40
|
+
return clone(seed);
|
|
41
|
+
},
|
|
42
|
+
decrypt(payload) {
|
|
43
|
+
return clone(payload);
|
|
44
|
+
},
|
|
45
45
|
};
|
|
46
46
|
export async function generateMasterSeed({ storage, rng, crypto = identityMasterSeedCrypto, overwrite = false, mnemonicPassphrase, }) {
|
|
47
47
|
if (!overwrite) {
|
|
@@ -57,10 +57,10 @@ export async function generateMasterSeed({ storage, rng, crypto = identityMaster
|
|
|
57
57
|
}
|
|
58
58
|
const entropy = rng(MNEMONIC_ENTROPY_BYTES);
|
|
59
59
|
if (entropy.length !== MNEMONIC_ENTROPY_BYTES) {
|
|
60
|
-
throw new
|
|
60
|
+
throw new Error(`mnemonic entropy must be ${MNEMONIC_ENTROPY_BYTES} bytes`);
|
|
61
61
|
}
|
|
62
62
|
try {
|
|
63
|
-
const mnemonic = Mnemonic.fromEntropy(
|
|
63
|
+
const mnemonic = Mnemonic.fromEntropy(ByteUtils.bytesToHex(entropy));
|
|
64
64
|
await storeMasterMnemonic(storage, mnemonic, crypto);
|
|
65
65
|
const seed = mnemonicToSeed(mnemonic, mnemonicPassphrase);
|
|
66
66
|
await storeMasterSeed(storage, seed, crypto);
|
|
@@ -81,9 +81,9 @@ export async function storeMasterSeed(storage, seed, crypto = identityMasterSeed
|
|
|
81
81
|
const normalized = normalizeMasterSeed(seed);
|
|
82
82
|
const encrypted = await crypto.encrypt(normalized);
|
|
83
83
|
if (!(encrypted instanceof Uint8Array)) {
|
|
84
|
-
throw new
|
|
84
|
+
throw new Error("master seed encryptor must return Uint8Array");
|
|
85
85
|
}
|
|
86
|
-
await storage.put(MASTER_SEED_KEY, encrypted);
|
|
86
|
+
await storage.put(MASTER_SEED_KEY, clone(encrypted));
|
|
87
87
|
}
|
|
88
88
|
export async function loadMasterMnemonic(storage, crypto = identityMasterSeedCrypto) {
|
|
89
89
|
const stored = await storage.get(MASTER_MNEMONIC_KEY);
|
|
@@ -102,7 +102,7 @@ export async function importMasterMnemonic({ storage, mnemonic, crypto = identit
|
|
|
102
102
|
if (!overwrite) {
|
|
103
103
|
const existing = await loadMasterMnemonic(storage, crypto);
|
|
104
104
|
if (existing) {
|
|
105
|
-
throw new
|
|
105
|
+
throw new Error("master mnemonic already exists; set overwrite to true to replace it");
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
const normalized = normalizeMnemonic(mnemonic);
|
|
@@ -115,28 +115,30 @@ export async function storeMasterMnemonic(storage, mnemonic, crypto = identityMa
|
|
|
115
115
|
const normalized = normalizeMnemonic(mnemonic);
|
|
116
116
|
const encrypted = await crypto.encrypt(textEncoder.encode(normalized));
|
|
117
117
|
if (!(encrypted instanceof Uint8Array)) {
|
|
118
|
-
throw new
|
|
118
|
+
throw new Error("master mnemonic encryptor must return Uint8Array");
|
|
119
119
|
}
|
|
120
|
-
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);
|
|
121
124
|
}
|
|
122
|
-
/** Validates seed format. Storage handles buffer isolation on put/get. */
|
|
123
125
|
function normalizeMasterSeed(seed) {
|
|
124
126
|
if (!(seed instanceof Uint8Array)) {
|
|
125
|
-
throw new
|
|
127
|
+
throw new Error("master seed must be a Uint8Array");
|
|
126
128
|
}
|
|
127
129
|
if (seed.length !== MASTER_SEED_LENGTH) {
|
|
128
|
-
throw new
|
|
130
|
+
throw new Error(`master seed must be ${MASTER_SEED_LENGTH} bytes`);
|
|
129
131
|
}
|
|
130
|
-
return seed;
|
|
132
|
+
return clone(seed);
|
|
131
133
|
}
|
|
132
134
|
function normalizeMnemonic(mnemonic) {
|
|
133
135
|
const formatted = mnemonic.trim().replace(/\s+/g, " ");
|
|
134
136
|
if (!Mnemonic.validate(formatted)) {
|
|
135
|
-
throw new
|
|
137
|
+
throw new Error("invalid BIP-39 mnemonic phrase");
|
|
136
138
|
}
|
|
137
139
|
return formatted;
|
|
138
140
|
}
|
|
139
141
|
function mnemonicToSeed(mnemonic, password = "") {
|
|
140
142
|
const seedHex = Mnemonic.toSeed(mnemonic, password);
|
|
141
|
-
return
|
|
143
|
+
return ByteUtils.hexStringToBytes(seedHex);
|
|
142
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 = {
|
|
@@ -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"}
|
|
@@ -14,17 +14,10 @@ export function createBroadcasterClient(baseUrl, deps) {
|
|
|
14
14
|
});
|
|
15
15
|
},
|
|
16
16
|
async getRelayStatus(relayId) {
|
|
17
|
-
|
|
17
|
+
return http.request({
|
|
18
18
|
method: "GET",
|
|
19
19
|
path: `/relays/${relayId}`,
|
|
20
20
|
});
|
|
21
|
-
return {
|
|
22
|
-
id: raw.id,
|
|
23
|
-
state: raw.state,
|
|
24
|
-
txHash: raw.tx_hash,
|
|
25
|
-
receipt: raw.receipt,
|
|
26
|
-
error: raw.error,
|
|
27
|
-
};
|
|
28
21
|
},
|
|
29
22
|
};
|
|
30
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
|
}
|
|
@@ -32,23 +32,13 @@ export type GetNullifierParams = {
|
|
|
32
32
|
chainId: number;
|
|
33
33
|
nullifier: string;
|
|
34
34
|
};
|
|
35
|
-
export type CheckNullifiersParams = {
|
|
36
|
-
chainId: number;
|
|
37
|
-
nullifiers: string[];
|
|
38
|
-
};
|
|
39
35
|
type IndexerClientDeps = {
|
|
40
36
|
fetch: FetchLike;
|
|
41
37
|
};
|
|
42
38
|
export declare function createIndexerClient(baseUrl: string, deps: IndexerClientDeps): {
|
|
43
39
|
fetchCommitmentBatch(params: FetchCommitmentsParams): Promise<CommitmentBatchResponse>;
|
|
44
40
|
getCommitment(params: GetCommitmentParams): Promise<CommitmentRecord>;
|
|
45
|
-
/**
|
|
46
|
-
* Like getCommitment but returns null when the commitment doesn't exist.
|
|
47
|
-
* Used for polling pending deposits without generating console errors.
|
|
48
|
-
*/
|
|
49
|
-
tryGetCommitment(params: GetCommitmentParams): Promise<CommitmentRecord | null>;
|
|
50
41
|
getNullifier(params: GetNullifierParams): Promise<IndexerNullifierRecord | null>;
|
|
51
|
-
checkNullifiers(params: CheckNullifiersParams): Promise<IndexerNullifierRecord[]>;
|
|
52
42
|
getNullifierCount(chainId: number): Promise<number>;
|
|
53
43
|
};
|
|
54
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,6 +1,9 @@
|
|
|
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,
|
|
@@ -37,51 +40,22 @@ export function createIndexerClient(baseUrl, deps) {
|
|
|
37
40
|
method: "GET",
|
|
38
41
|
path: `/chains/${params.chainId}/commitments/${params.commitment}`,
|
|
39
42
|
});
|
|
40
|
-
if (!raw) {
|
|
41
|
-
throw new HttpError("commitment not found", 404, null);
|
|
42
|
-
}
|
|
43
43
|
return normalizeRecord(raw);
|
|
44
44
|
},
|
|
45
|
-
/**
|
|
46
|
-
* Like getCommitment but returns null when the commitment doesn't exist.
|
|
47
|
-
* Used for polling pending deposits without generating console errors.
|
|
48
|
-
*/
|
|
49
|
-
async tryGetCommitment(params) {
|
|
50
|
-
const raw = await http.request({
|
|
51
|
-
method: "GET",
|
|
52
|
-
path: `/chains/${params.chainId}/commitments/${params.commitment}`,
|
|
53
|
-
});
|
|
54
|
-
return raw ? normalizeRecord(raw) : null;
|
|
55
|
-
},
|
|
56
45
|
async getNullifier(params) {
|
|
57
|
-
|
|
58
|
-
method: "GET",
|
|
59
|
-
path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
|
|
60
|
-
});
|
|
61
|
-
return raw ? normalizeNullifierRecord(raw) : null;
|
|
62
|
-
},
|
|
63
|
-
async checkNullifiers(params) {
|
|
64
|
-
const CHUNK_SIZE = 1000;
|
|
65
|
-
if (params.nullifiers.length <= CHUNK_SIZE) {
|
|
46
|
+
try {
|
|
66
47
|
const raw = await http.request({
|
|
67
|
-
method: "
|
|
68
|
-
path: `/chains/${params.chainId}/nullifiers
|
|
69
|
-
json: { nullifiers: params.nullifiers },
|
|
48
|
+
method: "GET",
|
|
49
|
+
path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
|
|
70
50
|
});
|
|
71
|
-
return raw
|
|
51
|
+
return normalizeNullifierRecord(raw);
|
|
72
52
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
method: "POST",
|
|
79
|
-
path: `/chains/${params.chainId}/nullifiers/check`,
|
|
80
|
-
json: { nullifiers: chunk },
|
|
81
|
-
});
|
|
82
|
-
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;
|
|
83
58
|
}
|
|
84
|
-
return results;
|
|
85
59
|
},
|
|
86
60
|
async getNullifierCount(chainId) {
|
|
87
61
|
const raw = await http.request({
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment types for SDK configuration.
|
|
3
|
+
*/
|
|
1
4
|
export type Environment = "mainnet" | "testnet" | "local";
|
|
2
5
|
/**
|
|
3
6
|
* Configuration for a specific environment.
|
|
@@ -14,7 +17,7 @@ export interface ServiceConfig {
|
|
|
14
17
|
indexerBaseUrl: string;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
17
|
-
* Fetch environment configuration from the hosted
|
|
20
|
+
* Fetch environment configuration from the hosted config file.
|
|
18
21
|
*
|
|
19
22
|
* @param env - The environment to fetch config for
|
|
20
23
|
* @returns Promise resolving to the environment configuration
|
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":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAKD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,iBAAiB,CAAC,CAU5B;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAMjE"}
|
package/dist/config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
const CONFIG_URL = "https://raw.githubusercontent.com/unlink-xyz/monorepo/main/sdk/config/environments.json";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
import { InitializationError } from "./errors.js";
|
|
5
|
-
const CONFIG_URL = "https://api.unlink.xyz/config/networks.json";
|
|
6
|
-
/**
|
|
7
|
-
* Fetch environment configuration from the hosted network config file.
|
|
3
|
+
* Fetch environment configuration from the hosted config file.
|
|
8
4
|
*
|
|
9
5
|
* @param env - The environment to fetch config for
|
|
10
6
|
* @returns Promise resolving to the environment configuration
|
|
@@ -13,11 +9,11 @@ const CONFIG_URL = "https://api.unlink.xyz/config/networks.json";
|
|
|
13
9
|
export async function fetchEnvironmentConfig(env) {
|
|
14
10
|
const res = await fetch(CONFIG_URL);
|
|
15
11
|
if (!res.ok) {
|
|
16
|
-
throw new
|
|
12
|
+
throw new Error(`Failed to fetch SDK config: ${res.status}`);
|
|
17
13
|
}
|
|
18
14
|
const config = (await res.json());
|
|
19
15
|
if (!config[env]) {
|
|
20
|
-
throw new
|
|
16
|
+
throw new Error(`Unknown environment: ${env}`);
|
|
21
17
|
}
|
|
22
18
|
return config[env];
|
|
23
19
|
}
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,UAAU,CAAC;CAChC,CAAC;AAEF,wBAAsB,QAAQ,CAAC,IAAI,EAAE,QAAQ;;aAHlC,MAAM,KAAK,UAAU;GAa/B"}
|
package/dist/core.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { initCrypto } from "./crypto-adapters/index.js";
|
|
2
|
-
import { InitializationError } from "./errors.js";
|
|
3
2
|
import { migrate } from "./schema.js";
|
|
4
3
|
export async function initCore(deps) {
|
|
5
4
|
if (!deps?.storage)
|
|
6
|
-
throw new
|
|
5
|
+
throw new Error("storage dep required");
|
|
7
6
|
if (!deps?.rng)
|
|
8
|
-
throw new
|
|
7
|
+
throw new Error("rng dep required");
|
|
9
8
|
await initCrypto();
|
|
10
9
|
await migrate(deps.storage);
|
|
11
10
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../crypto-adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../crypto-adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,gBAAgB,CAAC;AASxB;;;;GAIG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAehD;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAG,MAQtD,CAAC;AAEF,OAAO,EACL,eAAe,IAAI,uBAAuB,EAC1C,WAAW,EACX,eAAe,GAChB,MAAM,wBAAwB,CAAC"}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
// Polyfill must be the first import
|
|
10
10
|
import "./polyfills.js";
|
|
11
|
-
import { InitializationError } from "../errors.js";
|
|
12
11
|
let _poseidon = null;
|
|
13
12
|
let _initPromise = null;
|
|
14
13
|
/**
|
|
@@ -39,7 +38,7 @@ export async function initCrypto() {
|
|
|
39
38
|
*/
|
|
40
39
|
export const poseidon = (inputs) => {
|
|
41
40
|
if (!_poseidon) {
|
|
42
|
-
throw new
|
|
41
|
+
throw new Error("Crypto not initialized. Call initCrypto() before using poseidon().");
|
|
43
42
|
}
|
|
44
43
|
const hash = _poseidon(inputs);
|
|
45
44
|
return _poseidon.F.toObject(hash);
|
package/dist/errors.d.ts
CHANGED
|
@@ -7,13 +7,4 @@ export declare class KeyValidationError extends CoreError {
|
|
|
7
7
|
export declare class SchemaMismatchError extends CoreError {
|
|
8
8
|
constructor(current: number, expected: number);
|
|
9
9
|
}
|
|
10
|
-
export declare class ValidationError extends CoreError {
|
|
11
|
-
constructor(message: string);
|
|
12
|
-
}
|
|
13
|
-
export declare class ProofError extends CoreError {
|
|
14
|
-
constructor(message: string);
|
|
15
|
-
}
|
|
16
|
-
export declare class InitializationError extends CoreError {
|
|
17
|
-
constructor(message: string);
|
|
18
|
-
}
|
|
19
10
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C"}
|
package/dist/errors.js
CHANGED
|
@@ -16,21 +16,3 @@ export class SchemaMismatchError extends CoreError {
|
|
|
16
16
|
this.name = "SchemaMismatchError";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export class ValidationError extends CoreError {
|
|
20
|
-
constructor(message) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = "ValidationError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export class ProofError extends CoreError {
|
|
26
|
-
constructor(message) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.name = "ProofError";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export class InitializationError extends CoreError {
|
|
32
|
-
constructor(message) {
|
|
33
|
-
super(message);
|
|
34
|
-
this.name = "InitializationError";
|
|
35
|
-
}
|
|
36
|
-
}
|