@miradexio/client 0.1.0 → 0.1.2
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 +57 -292
- package/dist/address/base58.d.ts.map +1 -1
- package/dist/address/base58.js +1 -2
- package/dist/address/base58.js.map +1 -1
- package/dist/address/bech32.d.ts +0 -8
- package/dist/address/bech32.d.ts.map +1 -1
- package/dist/address/bech32.js +3 -9
- package/dist/address/bech32.js.map +1 -1
- package/dist/address/evm.d.ts.map +1 -1
- package/dist/address/evm.js +1 -2
- package/dist/address/evm.js.map +1 -1
- package/dist/address/index.d.ts +0 -6
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +6 -9
- package/dist/address/index.js.map +1 -1
- package/dist/address/monero.d.ts +0 -10
- package/dist/address/monero.d.ts.map +1 -1
- package/dist/address/monero.js +4 -10
- package/dist/address/monero.js.map +1 -1
- package/dist/address/polkadot.d.ts +0 -5
- package/dist/address/polkadot.d.ts.map +1 -1
- package/dist/address/polkadot.js +2 -6
- package/dist/address/polkadot.js.map +1 -1
- package/dist/address/ton.d.ts +0 -6
- package/dist/address/ton.d.ts.map +1 -1
- package/dist/address/ton.js +3 -8
- package/dist/address/ton.js.map +1 -1
- package/dist/api/index.d.ts +0 -19
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +18 -37
- package/dist/api/index.js.map +1 -1
- package/dist/atomic-swap/drive.d.ts +0 -13
- package/dist/atomic-swap/drive.d.ts.map +1 -1
- package/dist/atomic-swap/drive.js +66 -111
- package/dist/atomic-swap/drive.js.map +1 -1
- package/dist/atomic-swap/extract.d.ts +0 -23
- package/dist/atomic-swap/extract.d.ts.map +1 -1
- package/dist/atomic-swap/extract.js +6 -16
- package/dist/atomic-swap/extract.js.map +1 -1
- package/dist/atomic-swap/index.d.ts +0 -7
- package/dist/atomic-swap/index.d.ts.map +1 -1
- package/dist/atomic-swap/index.js +1 -7
- package/dist/atomic-swap/index.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/errors.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/errors.js +5 -20
- package/dist/atomic-swap/monero-sweep/errors.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/index.d.ts +0 -13
- package/dist/atomic-swap/monero-sweep/index.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/index.js +30 -56
- package/dist/atomic-swap/monero-sweep/index.js.map +1 -1
- package/dist/atomic-swap/monero-sweep/ring-select.d.ts +0 -4
- package/dist/atomic-swap/monero-sweep/ring-select.d.ts.map +1 -1
- package/dist/atomic-swap/monero-sweep/ring-select.js +9 -21
- package/dist/atomic-swap/monero-sweep/ring-select.js.map +1 -1
- package/dist/atomic-swap/presign.d.ts +0 -63
- package/dist/atomic-swap/presign.d.ts.map +1 -1
- package/dist/atomic-swap/presign.js +30 -90
- package/dist/atomic-swap/presign.js.map +1 -1
- package/dist/atomic-swap/refund.d.ts +0 -18
- package/dist/atomic-swap/refund.d.ts.map +1 -1
- package/dist/atomic-swap/refund.js +16 -32
- package/dist/atomic-swap/refund.js.map +1 -1
- package/dist/atomic-swap/run.d.ts +0 -17
- package/dist/atomic-swap/run.d.ts.map +1 -1
- package/dist/atomic-swap/run.js +11 -25
- package/dist/atomic-swap/run.js.map +1 -1
- package/dist/atomic-swap/snapshot.d.ts +0 -30
- package/dist/atomic-swap/snapshot.d.ts.map +1 -1
- package/dist/atomic-swap/snapshot.js +8 -23
- package/dist/atomic-swap/snapshot.js.map +1 -1
- package/dist/atomic-swap/submit-encsig.d.ts +0 -7
- package/dist/atomic-swap/submit-encsig.d.ts.map +1 -1
- package/dist/atomic-swap/submit-encsig.js +2 -11
- package/dist/atomic-swap/submit-encsig.js.map +1 -1
- package/dist/atomic-swap/types.d.ts +2 -55
- package/dist/atomic-swap/types.d.ts.map +1 -1
- package/dist/atomic-swap/types.js +2 -3
- package/dist/atomic-swap/types.js.map +1 -1
- package/dist/blockchain/quorum-provider.d.ts +0 -15
- package/dist/blockchain/quorum-provider.d.ts.map +1 -1
- package/dist/blockchain/quorum-provider.js +7 -9
- package/dist/blockchain/quorum-provider.js.map +1 -1
- package/dist/cooperative-redeem.d.ts +5 -14
- package/dist/cooperative-redeem.d.ts.map +1 -1
- package/dist/cooperative-redeem.js +3 -20
- package/dist/cooperative-redeem.js.map +1 -1
- package/dist/engine/blockchain-querier.d.ts +0 -22
- package/dist/engine/blockchain-querier.d.ts.map +1 -1
- package/dist/engine/engine-state.d.ts +0 -8
- package/dist/engine/engine-state.d.ts.map +1 -1
- package/dist/engine/engine-state.js.map +1 -1
- package/dist/engine/flow-context.d.ts +0 -20
- package/dist/engine/flow-context.d.ts.map +1 -1
- package/dist/engine/flow-context.js +17 -41
- package/dist/engine/flow-context.js.map +1 -1
- package/dist/engine/flows/atomic-flow.d.ts +0 -28
- package/dist/engine/flows/atomic-flow.d.ts.map +1 -1
- package/dist/engine/flows/atomic-flow.js +64 -121
- package/dist/engine/flows/atomic-flow.js.map +1 -1
- package/dist/engine/flows/swap-flow.d.ts +0 -19
- package/dist/engine/flows/swap-flow.d.ts.map +1 -1
- package/dist/engine/flows/swap-flow.js +41 -83
- package/dist/engine/flows/swap-flow.js.map +1 -1
- package/dist/engine/miradex-engine.d.ts +1 -62
- package/dist/engine/miradex-engine.d.ts.map +1 -1
- package/dist/engine/miradex-engine.js +18 -50
- package/dist/engine/miradex-engine.js.map +1 -1
- package/dist/engine/pipeline.d.ts +0 -11
- package/dist/engine/pipeline.d.ts.map +1 -1
- package/dist/engine/pipeline.js +9 -21
- package/dist/engine/pipeline.js.map +1 -1
- package/dist/engine/platform.d.ts +0 -160
- package/dist/engine/platform.d.ts.map +1 -1
- package/dist/engine/platform.js +2 -0
- package/dist/engine/platform.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -11
- package/dist/index.js.map +1 -1
- package/dist/interfaces/blockchain.d.ts +1 -13
- package/dist/interfaces/blockchain.d.ts.map +1 -1
- package/dist/interfaces/blockchain.js +1 -0
- package/dist/interfaces/blockchain.js.map +1 -1
- package/dist/interfaces/logger.d.ts +0 -6
- package/dist/interfaces/logger.d.ts.map +1 -1
- package/dist/interfaces/logger.js.map +1 -1
- package/dist/lib/bitcoin/deposit-watcher.d.ts +0 -23
- package/dist/lib/bitcoin/deposit-watcher.d.ts.map +1 -1
- package/dist/lib/bitcoin/deposit-watcher.js +7 -31
- package/dist/lib/bitcoin/deposit-watcher.js.map +1 -1
- package/dist/lib/bitcoin/script-hash.d.ts.map +1 -1
- package/dist/lib/bitcoin/script-hash.js +2 -6
- package/dist/lib/bitcoin/script-hash.js.map +1 -1
- package/dist/lib/bitcoin/sweep.d.ts +0 -30
- package/dist/lib/bitcoin/sweep.d.ts.map +1 -1
- package/dist/lib/bitcoin/sweep.js +11 -40
- package/dist/lib/bitcoin/sweep.js.map +1 -1
- package/dist/lib/bitcoin/tx-verify.d.ts +0 -28
- package/dist/lib/bitcoin/tx-verify.d.ts.map +1 -1
- package/dist/lib/bitcoin/tx-verify.js +20 -61
- package/dist/lib/bitcoin/tx-verify.js.map +1 -1
- package/dist/lib/bitcoin/wallet.d.ts +0 -38
- package/dist/lib/bitcoin/wallet.d.ts.map +1 -1
- package/dist/lib/bitcoin/wallet.js +13 -38
- package/dist/lib/bitcoin/wallet.js.map +1 -1
- package/dist/lib/crypto/bytes.d.ts +0 -14
- package/dist/lib/crypto/bytes.d.ts.map +1 -1
- package/dist/lib/crypto/bytes.js +5 -14
- package/dist/lib/crypto/bytes.js.map +1 -1
- package/dist/lib/crypto/errors.d.ts +0 -5
- package/dist/lib/crypto/errors.d.ts.map +1 -1
- package/dist/lib/crypto/errors.js +2 -5
- package/dist/lib/crypto/errors.js.map +1 -1
- package/dist/lib/crypto/libp2p-identity.d.ts +0 -15
- package/dist/lib/crypto/libp2p-identity.d.ts.map +1 -1
- package/dist/lib/crypto/libp2p-identity.js +16 -28
- package/dist/lib/crypto/libp2p-identity.js.map +1 -1
- package/dist/lib/crypto/mnemonic.d.ts +0 -9
- package/dist/lib/crypto/mnemonic.d.ts.map +1 -1
- package/dist/lib/crypto/mnemonic.js +11 -27
- package/dist/lib/crypto/mnemonic.js.map +1 -1
- package/dist/lib/crypto/platform.d.ts +0 -6
- package/dist/lib/crypto/platform.d.ts.map +1 -1
- package/dist/lib/crypto/platform.js +2 -6
- package/dist/lib/crypto/platform.js.map +1 -1
- package/dist/lib/crypto/scalars.d.ts +0 -23
- package/dist/lib/crypto/scalars.d.ts.map +1 -1
- package/dist/lib/crypto/scalars.js +10 -23
- package/dist/lib/crypto/scalars.js.map +1 -1
- package/dist/lib/crypto/types.d.ts +0 -4
- package/dist/lib/crypto/types.d.ts.map +1 -1
- package/dist/lib/crypto/wasm.d.ts +0 -23
- package/dist/lib/crypto/wasm.d.ts.map +1 -1
- package/dist/lib/crypto/wasm.js +10 -13
- package/dist/lib/crypto/wasm.js.map +1 -1
- package/dist/lib/default-config.d.ts +1 -59
- package/dist/lib/default-config.d.ts.map +1 -1
- package/dist/lib/default-config.js +22 -61
- package/dist/lib/default-config.js.map +1 -1
- package/dist/lib/errors.d.ts +0 -54
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +12 -35
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/keystore.d.ts +0 -24
- package/dist/lib/keystore.d.ts.map +1 -1
- package/dist/lib/keystore.js +3 -10
- package/dist/lib/keystore.js.map +1 -1
- package/dist/lib/monero/output-scanner.d.ts +0 -18
- package/dist/lib/monero/output-scanner.d.ts.map +1 -1
- package/dist/lib/monero/output-scanner.js +17 -40
- package/dist/lib/monero/output-scanner.js.map +1 -1
- package/dist/lib/monero/rpc.d.ts +0 -64
- package/dist/lib/monero/rpc.d.ts.map +1 -1
- package/dist/lib/monero/rpc.js +17 -59
- package/dist/lib/monero/rpc.js.map +1 -1
- package/dist/lib/monero/verify-lock.d.ts +0 -12
- package/dist/lib/monero/verify-lock.d.ts.map +1 -1
- package/dist/lib/monero/verify-lock.js +9 -24
- package/dist/lib/monero/verify-lock.js.map +1 -1
- package/dist/lib/monero/verify-sweep.d.ts +0 -20
- package/dist/lib/monero/verify-sweep.d.ts.map +1 -1
- package/dist/lib/monero/verify-sweep.js +7 -25
- package/dist/lib/monero/verify-sweep.js.map +1 -1
- package/dist/lib/pow-solver.d.ts.map +1 -1
- package/dist/lib/pow-solver.js +3 -8
- package/dist/lib/pow-solver.js.map +1 -1
- package/dist/lib/retry.d.ts +7 -64
- package/dist/lib/retry.d.ts.map +1 -1
- package/dist/lib/retry.js +13 -13
- package/dist/lib/retry.js.map +1 -1
- package/dist/portable.d.ts.map +1 -1
- package/dist/portable.js +3 -4
- package/dist/portable.js.map +1 -1
- package/dist/quote-binding.d.ts +0 -13
- package/dist/quote-binding.d.ts.map +1 -1
- package/dist/quote-binding.js +3 -18
- package/dist/quote-binding.js.map +1 -1
- package/dist/swap-executor.d.ts +1 -5
- package/dist/swap-executor.d.ts.map +1 -1
- package/dist/swap-executor.js +1 -1
- package/dist/swap-executor.js.map +1 -1
- package/dist/types/api.d.ts +0 -6
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js +6 -9
- package/dist/types/api.js.map +1 -1
- package/dist/types/errors.d.ts +0 -7
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -7
- package/dist/types/errors.js.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/keys.d.ts +0 -15
- package/dist/types/keys.d.ts.map +1 -1
- package/dist/types/protocol.d.ts +0 -51
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +3 -8
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/status.js +9 -14
- package/dist/types/status.js.map +1 -1
- package/dist/types/verification.d.ts +0 -10
- package/dist/types/verification.d.ts.map +1 -1
- package/dist/types/verification.js +7 -15
- package/dist/types/verification.js.map +1 -1
- package/dist/verification/chainflip-networks.d.ts +2 -35
- package/dist/verification/chainflip-networks.d.ts.map +1 -1
- package/dist/verification/chainflip-networks.js +12 -4
- package/dist/verification/chainflip-networks.js.map +1 -1
- package/dist/verification/chainflip.d.ts +0 -40
- package/dist/verification/chainflip.d.ts.map +1 -1
- package/dist/verification/chainflip.js +49 -129
- package/dist/verification/chainflip.js.map +1 -1
- package/dist/verification/constants.d.ts +0 -40
- package/dist/verification/constants.d.ts.map +1 -1
- package/dist/verification/constants.js +14 -40
- package/dist/verification/constants.js.map +1 -1
- package/dist/verification/index.d.ts +0 -26
- package/dist/verification/index.d.ts.map +1 -1
- package/dist/verification/index.js +8 -12
- package/dist/verification/index.js.map +1 -1
- package/dist/verification/memo.d.ts +0 -15
- package/dist/verification/memo.d.ts.map +1 -1
- package/dist/verification/memo.js +9 -27
- package/dist/verification/memo.js.map +1 -1
- package/dist/verification/near-intents.d.ts +0 -63
- package/dist/verification/near-intents.d.ts.map +1 -1
- package/dist/verification/near-intents.js +25 -67
- package/dist/verification/near-intents.js.map +1 -1
- package/dist/verification/rate-oracle.d.ts +0 -22
- package/dist/verification/rate-oracle.d.ts.map +1 -1
- package/dist/verification/rate-oracle.js +6 -11
- package/dist/verification/rate-oracle.js.map +1 -1
- package/dist/verification/thorchain-networks.d.ts +0 -27
- package/dist/verification/thorchain-networks.d.ts.map +1 -1
- package/dist/verification/thorchain-networks.js +13 -15
- package/dist/verification/thorchain-networks.js.map +1 -1
- package/dist/verification/thorchain.d.ts +0 -30
- package/dist/verification/thorchain.d.ts.map +1 -1
- package/dist/verification/thorchain.js +24 -47
- package/dist/verification/thorchain.js.map +1 -1
- package/dist/wasm-pins.d.ts +3 -3
- package/dist/wasm-pins.js +1 -1
- package/dist/wire/near-intents.zod.d.ts +0 -27
- package/dist/wire/near-intents.zod.d.ts.map +1 -1
- package/dist/wire/near-intents.zod.js +15 -23
- package/dist/wire/near-intents.zod.js.map +1 -1
- package/dist/wire/server/action.zod.d.ts +0 -10
- package/dist/wire/server/action.zod.d.ts.map +1 -1
- package/dist/wire/server/action.zod.js +8 -14
- package/dist/wire/server/action.zod.js.map +1 -1
- package/dist/wire/server/common.zod.d.ts +0 -13
- package/dist/wire/server/common.zod.d.ts.map +1 -1
- package/dist/wire/server/common.zod.js +6 -14
- package/dist/wire/server/common.zod.js.map +1 -1
- package/dist/wire/server/swap.zod.d.ts +0 -42
- package/dist/wire/server/swap.zod.d.ts.map +1 -1
- package/dist/wire/server/swap.zod.js +12 -26
- package/dist/wire/server/swap.zod.js.map +1 -1
- package/dist/wire/thorchain.zod.d.ts +0 -8
- package/dist/wire/thorchain.zod.d.ts.map +1 -1
- package/dist/wire/thorchain.zod.js +3 -8
- package/dist/wire/thorchain.zod.js.map +1 -1
- package/package.json +4 -5
- package/wasm/miradex-rust/README.md +3 -4
- package/wasm/miradex-rust/miradex_rust.d.ts +4 -6
- package/wasm/miradex-rust/miradex_rust.js +4 -6
- package/wasm/miradex-rust/miradex_rust_bg.wasm +0 -0
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Every hardcoded default used across the codebase lives here.
|
|
5
|
-
* Individual modules import what they need — no magic strings scattered
|
|
6
|
-
* across files. When adding new infrastructure defaults, put them here.
|
|
7
|
-
*/
|
|
1
|
+
// Single home for hardcoded defaults so individual modules don't carry
|
|
2
|
+
// magic strings. Add new infrastructure defaults here.
|
|
8
3
|
export const API_URL = 'http://127.0.0.1:7001/';
|
|
9
4
|
export const API_TOR_URL = 'http://miradextor.onion:7001';
|
|
10
5
|
export const API_TIMEOUT_MS = 30_000;
|
|
@@ -20,12 +15,10 @@ export const TOR_MODE = 'bundled';
|
|
|
20
15
|
export const ELECTRUM_PRIMARY_URL = 'ssl://electrum.blockstream.info:50002';
|
|
21
16
|
/** Testnet Electrum server URL. */
|
|
22
17
|
export const ELECTRUM_TESTNET_URL = 'ssl://electrum.blockstream.info:60002';
|
|
23
|
-
/** Resolve the correct Electrum server URL for a given network. */
|
|
24
18
|
export function electrumUrlForNetwork(configuredUrl, network) {
|
|
25
|
-
//
|
|
19
|
+
// Respect a user-configured server regardless of network.
|
|
26
20
|
if (configuredUrl !== ELECTRUM_PRIMARY_URL)
|
|
27
21
|
return configuredUrl;
|
|
28
|
-
// Default server: swap to testnet variant
|
|
29
22
|
return network === 'testnet' ? ELECTRUM_TESTNET_URL : configuredUrl;
|
|
30
23
|
}
|
|
31
24
|
/** Ordered list of Electrum servers. First entry is the primary. */
|
|
@@ -45,20 +38,10 @@ export const ELECTRUM_SERVERS = [
|
|
|
45
38
|
];
|
|
46
39
|
export const ELECTRUM_CONNECT_TIMEOUT_MS = 8_000;
|
|
47
40
|
export const ELECTRUM_REQUEST_TIMEOUT_MS = 10_000;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* to:
|
|
53
|
-
* - return `Access-Control-Allow-Origin: *` (browser-fetchable),
|
|
54
|
-
* - serve `nettype=mainnet`,
|
|
55
|
-
* - present a valid TLS chain.
|
|
56
|
-
*
|
|
57
|
-
* Mainnet stays out of the crypto-server proxy on purpose — see
|
|
58
|
-
* `apps/crypto-server/src/swap/routes/monero-proxy.routes.ts`. Only
|
|
59
|
-
* stagenet/testnet runs through the proxy because there's no real-money
|
|
60
|
-
* trust to preserve in test flows.
|
|
61
|
-
*/
|
|
41
|
+
// Browser-hit directly: real-money swaps must not trust a single server-side
|
|
42
|
+
// proxy. Every entry probed 2026-05 to confirm CORS *, mainnet nettype, valid
|
|
43
|
+
// TLS. Stagenet/testnet runs through the crypto-server proxy
|
|
44
|
+
// (apps/crypto-server/src/swap/routes/monero-proxy.routes.ts); mainnet does not.
|
|
62
45
|
export const MONERO_MAINNET_NODES = [
|
|
63
46
|
'https://node.sethforprivacy.com',
|
|
64
47
|
'https://node.sethforprivacy.com:443',
|
|
@@ -98,21 +81,14 @@ export const MONERO_MAINNET_NODES = [
|
|
|
98
81
|
'https://monero.openinternet.io',
|
|
99
82
|
'https://xmr.support:18089',
|
|
100
83
|
];
|
|
101
|
-
|
|
102
|
-
* Curated Monero stagenet RPC endpoints. Stagenet is Monero's public test
|
|
103
|
-
* network (the Monero analogue of Bitcoin testnet).
|
|
104
|
-
*/
|
|
84
|
+
// Monero's public testnet equivalent.
|
|
105
85
|
export const MONERO_STAGENET_NODES = [
|
|
106
86
|
'https://node.sethforprivacy.com:38089',
|
|
107
87
|
'https://testnet.miradex.io/api/v1/swap/proxy/monero/stagenet',
|
|
108
88
|
'https://testnet.miradex.io/api/v1/swap/proxy/monero/stagenet'
|
|
109
89
|
];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* form that Electrum / monerod clients accept directly. For Monero, the
|
|
113
|
-
* `testnet` key holds stagenet endpoints (Monero has no parallel-to-Bitcoin
|
|
114
|
-
* 'testnet' notion — the closest public net is stagenet).
|
|
115
|
-
*/
|
|
90
|
+
// scheme://host:port form, accepted directly by Electrum / monerod clients.
|
|
91
|
+
// Monero `testnet` key holds stagenet endpoints (Monero has no Bitcoin-style testnet).
|
|
116
92
|
export const DEFAULT_NODES = {
|
|
117
93
|
testnet: {
|
|
118
94
|
bitcoin: [
|
|
@@ -152,37 +128,22 @@ export const DEFAULT_NODES = {
|
|
|
152
128
|
};
|
|
153
129
|
export const MEMPOOL_API = 'https://mempool.space/api';
|
|
154
130
|
export const MEMPOOL_TESTNET_API = 'https://mempool.space/testnet/api';
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
* Rounded up to 130 for safety margin (signature size variance). */
|
|
131
|
+
// 1-in P2WPKH -> 1-out P2WSH. Header(10.5) + input(68) + output(43) ~= 122 vb;
|
|
132
|
+
// rounded up to 130 for signature-size variance.
|
|
158
133
|
export const LOCK_TX_VBYTES = 130;
|
|
159
134
|
/** Fallback feerate when all fee sources are unreachable (sat/vbyte). */
|
|
160
135
|
export const FALLBACK_FEE_RATE = 10;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* 1.5–3.0 sat/vB. Setting this floor below 3 produces sporadic
|
|
165
|
-
* "min relay fee not met" rejections that force a re-sign. 3 sat/vB covers
|
|
166
|
-
* every sane operator policy we've observed with negligible extra cost.
|
|
167
|
-
*/
|
|
136
|
+
// Bitcoin Core defaults minrelaytxfee to 1.0, but many public/testnet nodes
|
|
137
|
+
// raise it to 1.5-3.0. Below 3 produces sporadic "min relay fee not met"
|
|
138
|
+
// rejections that force a re-sign; 3 sat/vB covers every sane policy.
|
|
168
139
|
export const MIN_FEE_RATE = 3;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
* estimate-at-deposit-time and broadcast-at-fund-time when mempool pressure
|
|
172
|
-
* changes. 1.25 = +25% headroom on top of the estimate.
|
|
173
|
-
*/
|
|
140
|
+
// +25% headroom on the estimate, to cover mempool changes between estimate
|
|
141
|
+
// at deposit-time and broadcast at fund-time.
|
|
174
142
|
export const FEE_MARGIN_MULTIPLIER = 1.25;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* fee market, electrum servers and mempool.space/testnet routinely
|
|
180
|
-
* return absurd `halfHourFee` values (we've seen >250 sat/vB on a chain
|
|
181
|
-
* where 1 sat/vB confirms in one block).
|
|
182
|
-
*
|
|
183
|
-
* Mainnet ceiling is set conservatively above historical peak conditions
|
|
184
|
-
* — it catches oracle bugs without gating real high-fee periods.
|
|
185
|
-
*/
|
|
143
|
+
// Sanity ceiling. Testnet halfHourFee oracles routinely return absurd
|
|
144
|
+
// values (>250 sat/vB on a chain where 1 sat/vB confirms in a block); without
|
|
145
|
+
// a cap a misbehaving oracle can drive the lock-tx fee above the deposit.
|
|
146
|
+
// Mainnet ceiling sits above historical peaks so it only catches oracle bugs.
|
|
186
147
|
export const MAX_FEE_RATE_MAINNET = 100;
|
|
187
148
|
export const MAX_FEE_RATE_TESTNET = 10;
|
|
188
149
|
export const DEPOSIT_POLL_MS = 5_000;
|
|
@@ -193,7 +154,7 @@ export const SWEEP_POLL_MS = 30_000;
|
|
|
193
154
|
export const SWEEP_TIMEOUT_MS = 3_600_000;
|
|
194
155
|
export const POW_MAX_RETRIES = 3;
|
|
195
156
|
export const POW_BACKOFF_MS = 2_000;
|
|
196
|
-
export const DEFAULT_SLIPPAGE_BPS =
|
|
157
|
+
export const DEFAULT_SLIPPAGE_BPS = 300;
|
|
197
158
|
export const DEFAULT_MAX_DEVIATION_BPS = 300;
|
|
198
159
|
export const DEFAULT_FROM_TOKEN = 'BTC';
|
|
199
160
|
export const DEFAULT_TO_TOKEN = 'XMR';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-config.js","sourceRoot":"","sources":["../../src/lib/default-config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"default-config.js","sourceRoot":"","sources":["../../src/lib/default-config.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,uDAAuD;AAEvD,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,8BAA8B,CAAC;AAC1D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEvC,MAAM,CAAC,MAAM,eAAe,GAAG,yBAAyB,CAAC;AACzD,6EAA6E;AAC7E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,MAAM,CAAC,MAAM,QAAQ,GAA2B,SAAS,CAAC;AAQ1D,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;AAE5E,mCAAmC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;AAE5E,MAAM,UAAU,qBAAqB,CACnC,aAAqB,EACrB,OAA0C;IAE1C,0DAA0D;IAC1D,IAAI,aAAa,KAA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,CAAC;AAC/B,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAC7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAO,CAAC;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAC5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C,MAAM;AACN,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE3C,4BAA4B;AAC5B,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC"}
|
package/dist/lib/errors.d.ts
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified error taxonomy for the miradex-client SDK.
|
|
3
|
-
*
|
|
4
|
-
* Every error thrown out of the SDK is either a {@link MiradexError} subclass
|
|
5
|
-
* (carrying a `category`) or a foreign error that {@link classifyError} can
|
|
6
|
-
* map to a category. The category drives retry policy via {@link withRetry}.
|
|
7
|
-
*
|
|
8
|
-
* Cross-platform: this module uses only platform-neutral primitives (`Error`,
|
|
9
|
-
* `TypeError`, `DOMException`). It never references Node-only APIs (`Buffer`,
|
|
10
|
-
* `process`, `fs`) and never assumes a particular fetch implementation. Both
|
|
11
|
-
* the browser and Node 20+ runtimes throw `TypeError("fetch failed")` /
|
|
12
|
-
* `DOMException("AbortError")` for the same underlying conditions, so a single
|
|
13
|
-
* classifier covers both.
|
|
14
|
-
*
|
|
15
|
-
* Category meaning:
|
|
16
|
-
* - `network` : transient — DNS, TLS, connection reset, fetch timeout. Retry indefinitely.
|
|
17
|
-
* - `server` : HTTP 5xx. Server fault, retry indefinitely.
|
|
18
|
-
* - `rate-limit` : HTTP 429. Server-controlled throttling. Bounded retry.
|
|
19
|
-
* - `client-bounded` : HTTP 4xx that may resolve on retry (404 freshly-created, 408, 409, 422). Bounded retry.
|
|
20
|
-
* - `client-fatal` : HTTP 4xx that won't resolve (400, 401, 403, 405, 410, ...). Fail immediately.
|
|
21
|
-
* - `protocol` : Contract violation (schema mismatch, missing required field). Fail immediately.
|
|
22
|
-
* - `verification` : Independent crypto/security check failed. Fail immediately.
|
|
23
|
-
* - `cancelled` : User/engine cancellation. Propagate.
|
|
24
|
-
* - `unknown` : Unclassified. Bounded retry as a safety net.
|
|
25
|
-
*/
|
|
26
1
|
export type ErrorCategory = 'network' | 'server' | 'rate-limit' | 'client-bounded' | 'client-fatal' | 'protocol' | 'verification' | 'cancelled' | 'unknown';
|
|
27
2
|
export interface MiradexErrorOptions {
|
|
28
3
|
readonly cause?: unknown;
|
|
29
4
|
readonly details?: Readonly<Record<string, unknown>>;
|
|
30
5
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Base for every error the SDK emits. Subclasses set `name` and `category`.
|
|
33
|
-
* `cause` and `details` are optional and travel with the error for diagnostics.
|
|
34
|
-
*/
|
|
35
6
|
export declare class MiradexError extends Error {
|
|
36
7
|
readonly name: string;
|
|
37
8
|
readonly category: ErrorCategory;
|
|
@@ -39,42 +10,17 @@ export declare class MiradexError extends Error {
|
|
|
39
10
|
readonly cause: unknown;
|
|
40
11
|
constructor(message: string, category: ErrorCategory, options?: MiradexErrorOptions);
|
|
41
12
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Determine the retry category for any value thrown from the SDK boundary.
|
|
44
|
-
*
|
|
45
|
-
* Already-classified {@link MiradexError}s short-circuit. Everything else is
|
|
46
|
-
* matched against the platform-neutral fingerprints of fetch / DNS / TLS
|
|
47
|
-
* failures.
|
|
48
|
-
*/
|
|
49
13
|
export declare function classifyError(err: unknown): ErrorCategory;
|
|
50
14
|
/** Convenience: shorthand string from an unknown thrown value. */
|
|
51
15
|
export declare function errorMessage(err: unknown): string;
|
|
52
|
-
/**
|
|
53
|
-
* User / engine cancellation. Raised when an `AbortSignal` aborts an
|
|
54
|
-
* in-flight retry loop or a long-running drive call.
|
|
55
|
-
*/
|
|
56
16
|
export declare class SwapCancelledError extends MiradexError {
|
|
57
17
|
readonly name = "SwapCancelledError";
|
|
58
18
|
constructor(message?: string);
|
|
59
19
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Transient network / fetch failure. The category is always `'network'`,
|
|
62
|
-
* which means {@link withRetry} retries indefinitely with capped backoff.
|
|
63
|
-
*/
|
|
64
20
|
export declare class NetworkError extends MiradexError {
|
|
65
21
|
readonly name = "NetworkError";
|
|
66
22
|
constructor(message: string, options?: MiradexErrorOptions);
|
|
67
23
|
}
|
|
68
|
-
/**
|
|
69
|
-
* HTTP-level error. The {@link MiradexError.category} is derived from the
|
|
70
|
-
* status code + server-emitted error code, so a single class covers the four
|
|
71
|
-
* HTTP categories (`client-bounded`, `client-fatal`, `rate-limit`, `server`)
|
|
72
|
-
* while keeping `instanceof ApiError` working for legacy callers.
|
|
73
|
-
*
|
|
74
|
-
* Special case: `code === 'SCHEMA_MISMATCH'` is `protocol` regardless of
|
|
75
|
-
* status, because a schema mismatch indicates a code-level contract violation
|
|
76
|
-
* — retrying will not fix it.
|
|
77
|
-
*/
|
|
78
24
|
export declare class ApiError extends MiradexError {
|
|
79
25
|
readonly name = "ApiError";
|
|
80
26
|
readonly statusCode: number;
|
package/dist/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"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,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,mBAAmB;CAMhC;AAED,4DAA4D;AAC5D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAQjF;AAED,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGjD;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGtD"}
|
package/dist/lib/errors.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Base for every error the SDK emits. Subclasses set `name` and `category`.
|
|
3
|
-
* `cause` and `details` are optional and travel with the error for diagnostics.
|
|
4
|
-
*/
|
|
1
|
+
// Subclasses set name and category. cause + details travel along.
|
|
5
2
|
export class MiradexError extends Error {
|
|
6
3
|
name = 'MiradexError';
|
|
7
4
|
category;
|
|
@@ -14,31 +11,25 @@ export class MiradexError extends Error {
|
|
|
14
11
|
this.details = options?.details;
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* Already-classified {@link MiradexError}s short-circuit. Everything else is
|
|
21
|
-
* matched against the platform-neutral fingerprints of fetch / DNS / TLS
|
|
22
|
-
* failures.
|
|
23
|
-
*/
|
|
14
|
+
// MiradexError short-circuits; everything else is fingerprinted against
|
|
15
|
+
// platform-neutral fetch / DNS / TLS failures.
|
|
24
16
|
export function classifyError(err) {
|
|
25
17
|
if (err instanceof MiradexError)
|
|
26
18
|
return err.category;
|
|
27
|
-
// Native fetch
|
|
28
|
-
//
|
|
29
|
-
// Browser: `TypeError: Failed to fetch` (no cause).
|
|
19
|
+
// Native fetch: Node 20+ throws TypeError("fetch failed") with .cause
|
|
20
|
+
// carrying ECONN...; browsers throw TypeError("Failed to fetch") sans cause.
|
|
30
21
|
if (err instanceof TypeError) {
|
|
31
22
|
if (/^(?:fetch failed|failed to fetch|networkerror|load failed)/i.test(err.message)) {
|
|
32
23
|
return 'network';
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
|
-
// Per-request timeout
|
|
26
|
+
// Per-request timeout via AbortController.abort().
|
|
36
27
|
if (typeof DOMException !== 'undefined' && err instanceof DOMException && err.name === 'AbortError') {
|
|
37
28
|
return 'network';
|
|
38
29
|
}
|
|
39
30
|
if (err instanceof Error) {
|
|
40
|
-
// Last-resort
|
|
41
|
-
//
|
|
31
|
+
// Last-resort fingerprint for environments that bury Node codes in
|
|
32
|
+
// message / cause without extending TypeError.
|
|
42
33
|
const merged = `${err.message} ${cause(err)}`.toLowerCase();
|
|
43
34
|
if (/\b(?:econnrefused|econnreset|enotfound|eai_again|etimedout|epipe|ehostunreach|enetunreach|socket hang up|getaddrinfo|other side closed|terminated)\b/.test(merged)) {
|
|
44
35
|
return 'network';
|
|
@@ -60,36 +51,22 @@ export function errorMessage(err) {
|
|
|
60
51
|
return err.message;
|
|
61
52
|
return String(err);
|
|
62
53
|
}
|
|
63
|
-
/**
|
|
64
|
-
* User / engine cancellation. Raised when an `AbortSignal` aborts an
|
|
65
|
-
* in-flight retry loop or a long-running drive call.
|
|
66
|
-
*/
|
|
67
54
|
export class SwapCancelledError extends MiradexError {
|
|
68
55
|
name = 'SwapCancelledError';
|
|
69
56
|
constructor(message = 'Swap cancelled by user') {
|
|
70
57
|
super(message, 'cancelled');
|
|
71
58
|
}
|
|
72
59
|
}
|
|
73
|
-
|
|
74
|
-
* Transient network / fetch failure. The category is always `'network'`,
|
|
75
|
-
* which means {@link withRetry} retries indefinitely with capped backoff.
|
|
76
|
-
*/
|
|
60
|
+
// Always category 'network' so withRetry retries forever (capped backoff).
|
|
77
61
|
export class NetworkError extends MiradexError {
|
|
78
62
|
name = 'NetworkError';
|
|
79
63
|
constructor(message, options) {
|
|
80
64
|
super(message, 'network', options);
|
|
81
65
|
}
|
|
82
66
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* HTTP categories (`client-bounded`, `client-fatal`, `rate-limit`, `server`)
|
|
87
|
-
* while keeping `instanceof ApiError` working for legacy callers.
|
|
88
|
-
*
|
|
89
|
-
* Special case: `code === 'SCHEMA_MISMATCH'` is `protocol` regardless of
|
|
90
|
-
* status, because a schema mismatch indicates a code-level contract violation
|
|
91
|
-
* — retrying will not fix it.
|
|
92
|
-
*/
|
|
67
|
+
// One class for all four HTTP categories (server / rate-limit / client-bounded
|
|
68
|
+
// / client-fatal); category derived from statusCode + code. SCHEMA_MISMATCH is
|
|
69
|
+
// always 'protocol' regardless of status — retrying won't fix it.
|
|
93
70
|
export class ApiError extends MiradexError {
|
|
94
71
|
name = 'ApiError';
|
|
95
72
|
statusCode;
|
package/dist/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AA8BA,kEAAkE;AAClE,MAAM,OAAO,YAAa,SAAQ,KAAK;IACnB,IAAI,GAAW,cAAc,CAAC;IACvC,QAAQ,CAAgB;IACxB,OAAO,CAAgD;IAC9C,KAAK,CAAU;IAEjC,YAAY,OAAe,EAAE,QAAuB,EAAE,OAA6B;QACjF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IAClC,CAAC;CACF;AAED,wEAAwE;AACxE,+CAA+C;AAC/C,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,GAAG,YAAY,YAAY;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC;IAErD,sEAAsE;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;IAC7B,OAAO,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,cAAc,IAAI,CAAC,KAAK,cAAc,IAAI,CAAC,KAAK,WAAW,CAAC;AAC/F,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,QAAQ,CAAC;AAC3C,CAAC"}
|
package/dist/lib/keystore.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Records how keys were derived so future code changes never break recovery.
|
|
3
|
-
*/
|
|
4
1
|
export interface KeystoreDerivation {
|
|
5
2
|
/** Scheme identifier (e.g. "miradex-v0") */
|
|
6
3
|
readonly scheme: string;
|
|
@@ -11,17 +8,6 @@ export interface KeystoreDerivation {
|
|
|
11
8
|
/** HMAC domain string used to derive v_b from the BIP32 seed */
|
|
12
9
|
readonly viewKeyDomain: string;
|
|
13
10
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Keystore file format v3.
|
|
16
|
-
*
|
|
17
|
-
* Adds eigenwallet_master_seed + libp2p_peer_id so a recovery binary
|
|
18
|
-
* (eigenwallet's swap CLI) can re-derive the same libp2p identity Bob used
|
|
19
|
-
* for the swap setup. Required for cross-binary recovery.
|
|
20
|
-
*
|
|
21
|
-
* Naming convention follows the atomic swap protocol:
|
|
22
|
-
* lowercase s = private (secret scalar)
|
|
23
|
-
* uppercase S = public (curve point)
|
|
24
|
-
*/
|
|
25
11
|
export interface SwapKeystore {
|
|
26
12
|
readonly version: 3;
|
|
27
13
|
readonly createdAt: string;
|
|
@@ -71,15 +57,5 @@ export declare function createKeystore(params: {
|
|
|
71
57
|
readonly mnemonic?: string;
|
|
72
58
|
readonly derivation?: KeystoreDerivation;
|
|
73
59
|
}): SwapKeystore;
|
|
74
|
-
/**
|
|
75
|
-
* Parse a raw JSON string into a SwapKeystore.
|
|
76
|
-
* Handles v1, v2 (migrated), and v3 keystore formats.
|
|
77
|
-
*
|
|
78
|
-
* V2→V3 migration: existing V2 keystores have no `eigenwallet_master_seed`.
|
|
79
|
-
* The migrator stamps an empty string for both libp2p fields; recovery for
|
|
80
|
-
* those swaps is keystore-only (mnemonic still works), but the eigenwallet
|
|
81
|
-
* binary won't reproduce the original peer-id. Newly-created keystores at V3
|
|
82
|
-
* have the field populated.
|
|
83
|
-
*/
|
|
84
60
|
export declare function parseKeystore(rawJson: string): SwapKeystore;
|
|
85
61
|
//# sourceMappingURL=keystore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keystore.d.ts","sourceRoot":"","sources":["../../src/lib/keystore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keystore.d.ts","sourceRoot":"","sources":["../../src/lib/keystore.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,gEAAgE;IAChE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAKD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE;QACZ,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CA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QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;CAC1C,GAAG,YAAY,CA+Bf;AAKD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAuB3D"}
|
package/dist/lib/keystore.js
CHANGED
|
@@ -30,16 +30,9 @@ export function createKeystore(params) {
|
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* V2→V3 migration: existing V2 keystores have no `eigenwallet_master_seed`.
|
|
38
|
-
* The migrator stamps an empty string for both libp2p fields; recovery for
|
|
39
|
-
* those swaps is keystore-only (mnemonic still works), but the eigenwallet
|
|
40
|
-
* binary won't reproduce the original peer-id. Newly-created keystores at V3
|
|
41
|
-
* have the field populated.
|
|
42
|
-
*/
|
|
33
|
+
// Handles v1, v2 (migrated), v3. V2->V3: empty libp2p fields, so recovery
|
|
34
|
+
// is keystore-only (mnemonic works) but eigenwallet can't reproduce the
|
|
35
|
+
// original peer-id. Fresh V3 keystores have the field populated.
|
|
43
36
|
export function parseKeystore(rawJson) {
|
|
44
37
|
const raw = JSON.parse(rawJson);
|
|
45
38
|
if (typeof raw !== 'object' || raw === null) {
|
package/dist/lib/keystore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keystore.js","sourceRoot":"","sources":["../../src/lib/keystore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keystore.js","sourceRoot":"","sources":["../../src/lib/keystore.ts"],"names":[],"mappings":"AA+CA,MAAM,UAAU,cAAc,CAAC,MAiB9B;IACC,MAAM,WAAW,GAAG,MAAM,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C,IAAI;KACd,CAAC;AACJ,CAAC;AAoBD,SAAS,aAAa,CAAC,GAA4B;IACjD,MAAM,EAAE,GAAG,GAA4B,CAAC;IAExC,OAAO;QACL,OAAO,EAAE,CAAC;QACV,SAAS,EAAG,GAAG,CAAC,WAAW,CAAY,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnE,OAAO,EAAE,2DAA2D;QACpE,GAAG,EAAE;YACH,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG;YACf,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO;YACvB,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,IAAI,SAAS,CAAsC;SAC5E;QACD,IAAI,EAAE;YACJ,+EAA+E;YAC/E,GAAG,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE;YACtB,GAAG,EAAE,EAAE,CAAC,MAAM,EAAE,cAAc,IAAI,EAAE;YACpC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE;YACpC,UAAU,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,MAAM,EAAE,cAAc,IAAI,EAAE;YAC/D,UAAU,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YAChC,CAAC,EAAE,EAAE;YACL,CAAC,EAAE,EAAE;SACN;QACD,IAAI,EAAE;YACJ,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,cAAc,IAAI,EAAE;YAC7C,aAAa,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,IAAI,EAAE;SAC5C;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -15,18 +15,6 @@ export interface ScannedOutput {
|
|
|
15
15
|
/** RCT commitment blinding factor (32 bytes hex). Computed via WASM. */
|
|
16
16
|
readonly rctMask: string;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Scan a transaction's outputs to find ones belonging to the given keys.
|
|
20
|
-
*
|
|
21
|
-
* @param txJson - Parsed transaction JSON from monerod
|
|
22
|
-
* @param globalOutputIndices - Global indices for each output (from get_transactions response)
|
|
23
|
-
* @param viewKeyHex - Combined private view key (32 bytes hex)
|
|
24
|
-
* @param spendPubHex - Combined public spend key S_a + S_b (32 bytes hex)
|
|
25
|
-
* @param computeMask - Function to compute commitment mask (typically WASM compute_commitment_mask)
|
|
26
|
-
* @param decryptAmountFn - Function to decrypt RCT amount (typically WASM decrypt_amount). If not provided, uses TS fallback.
|
|
27
|
-
* @param logger - Optional structured logger
|
|
28
|
-
* @returns Array of matching outputs with all metadata
|
|
29
|
-
*/
|
|
30
18
|
export declare function scanTransactionOutputs(params: {
|
|
31
19
|
readonly txJson: MoneroTxJson;
|
|
32
20
|
readonly globalOutputIndices: readonly number[];
|
|
@@ -36,18 +24,12 @@ export declare function scanTransactionOutputs(params: {
|
|
|
36
24
|
readonly decryptAmountFn?: (viewKeyHex: string, txPubKeyHex: string, outputIndex: number, encryptedHex: string) => bigint;
|
|
37
25
|
readonly logger?: Logger;
|
|
38
26
|
}): ScannedOutput[];
|
|
39
|
-
/** Extract the tx public key R from the extra field. Tag 0x01 = 32-byte pubkey. */
|
|
40
27
|
export declare function extractTxPubKey(extra: readonly number[]): Uint8Array | null;
|
|
41
|
-
/** Decode a hex-encoded little-endian scalar reduced mod L. */
|
|
42
28
|
export declare function hexToScalar(hex: string): bigint;
|
|
43
|
-
/** Hs(D8 || varint(i)) mod L: keccak output interpreted as a little-endian scalar. */
|
|
44
29
|
export declare function deriveScalar(d8Bytes: Uint8Array, outputIndex: number): bigint;
|
|
45
|
-
/** Keccak256(D8 || varint(i)) as raw 32 bytes. */
|
|
46
30
|
export declare function deriveScalarBytes(d8Bytes: Uint8Array, outputIndex: number): Uint8Array;
|
|
47
|
-
/** Decrypt a Monero RingCT amount (Bulletproofs+ style, 8-byte XOR). */
|
|
48
31
|
export declare function decryptAmount(d8Bytes: Uint8Array, outputIndex: number, ecdhInfo: {
|
|
49
32
|
readonly amount: string;
|
|
50
33
|
} | undefined): bigint;
|
|
51
|
-
/** Encode a number as a Monero varint (unsigned LEB128). */
|
|
52
34
|
export declare function encodeVarint(value: number): Uint8Array;
|
|
53
35
|
//# sourceMappingURL=output-scanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-scanner.d.ts","sourceRoot":"","sources":["../../../src/lib/monero/output-scanner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output-scanner.d.ts","sourceRoot":"","sources":["../../../src/lib/monero/output-scanner.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAQzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6CAA6C;IAC7C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAID,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/F,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1H,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,aAAa,EAAE,CAuGlB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,GAAG,IAAI,CAO3E;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAI7E;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAMtF;AASD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAChD,MAAM,CAuBR;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAUtD"}
|
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Given a transaction JSON (from monerod /get_transactions), the shared view key,
|
|
5
|
-
* and the combined spend public key, this module scans each output to determine
|
|
6
|
-
* if it belongs to the lock address. For matching outputs, it decrypts the amount
|
|
7
|
-
* and computes the RCT commitment mask.
|
|
8
|
-
*
|
|
9
|
-
* Reusable by both verify-xmr-lock.ts (lock verification) and monero-sweep.ts
|
|
10
|
-
* (sweep construction).
|
|
11
|
-
*/
|
|
1
|
+
// Detect owned outputs in a Monero tx given the shared view key and the
|
|
2
|
+
// combined spend pubkey. For matches, decrypt the amount and compute the
|
|
3
|
+
// RCT commitment mask. Used by verify-xmr-lock.ts and monero-sweep.ts.
|
|
12
4
|
import { Point } from '@noble/ed25519';
|
|
13
5
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
14
6
|
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';
|
|
15
7
|
import { noopLogger } from '../../interfaces/logger.js';
|
|
16
8
|
import { ED25519_GROUP_ORDER, bytesToBigIntLE, hexToScalarLE, bigIntToBytes, } from '../crypto/scalars.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @param txJson - Parsed transaction JSON from monerod
|
|
21
|
-
* @param globalOutputIndices - Global indices for each output (from get_transactions response)
|
|
22
|
-
* @param viewKeyHex - Combined private view key (32 bytes hex)
|
|
23
|
-
* @param spendPubHex - Combined public spend key S_a + S_b (32 bytes hex)
|
|
24
|
-
* @param computeMask - Function to compute commitment mask (typically WASM compute_commitment_mask)
|
|
25
|
-
* @param decryptAmountFn - Function to decrypt RCT amount (typically WASM decrypt_amount). If not provided, uses TS fallback.
|
|
26
|
-
* @param logger - Optional structured logger
|
|
27
|
-
* @returns Array of matching outputs with all metadata
|
|
28
|
-
*/
|
|
9
|
+
// computeMask / decryptAmountFn typically wrap the WASM equivalents;
|
|
10
|
+
// decryptAmountFn falls back to the local TS impl when omitted.
|
|
29
11
|
export function scanTransactionOutputs(params) {
|
|
30
12
|
const { txJson, globalOutputIndices, viewKeyHex, spendPubHex, computeMask, decryptAmountFn, logger: log = noopLogger } = params;
|
|
31
13
|
const txPubKeyR = extractTxPubKey(txJson.extra);
|
|
@@ -69,7 +51,7 @@ export function scanTransactionOutputs(params) {
|
|
|
69
51
|
const expectedKeyHex = bytesToHex(expectedKey.toBytes());
|
|
70
52
|
const isMatch = expectedKeyHex === outputKeyHex;
|
|
71
53
|
if (isMatch) {
|
|
72
|
-
//
|
|
54
|
+
// Prefer the WASM decrypt — same key derivation as mask / key images.
|
|
73
55
|
const ecdhInfo = txJson.rct_signatures.ecdhInfo[i];
|
|
74
56
|
let amount;
|
|
75
57
|
if (decryptAmountFn && ecdhInfo) {
|
|
@@ -105,7 +87,7 @@ export function scanTransactionOutputs(params) {
|
|
|
105
87
|
log.info({ scannedOutputs: txJson.vout.length, matches: results.length }, 'Output scanning complete');
|
|
106
88
|
return results;
|
|
107
89
|
}
|
|
108
|
-
|
|
90
|
+
// Tag 0x01 = 32B pubkey.
|
|
109
91
|
export function extractTxPubKey(extra) {
|
|
110
92
|
for (let i = 0; i < extra.length; i++) {
|
|
111
93
|
if (extra[i] === 0x01 && i + 32 < extra.length) {
|
|
@@ -114,17 +96,16 @@ export function extractTxPubKey(extra) {
|
|
|
114
96
|
}
|
|
115
97
|
return null;
|
|
116
98
|
}
|
|
117
|
-
/** Decode a hex-encoded little-endian scalar reduced mod L. */
|
|
118
99
|
export function hexToScalar(hex) {
|
|
119
100
|
return hexToScalarLE(hex);
|
|
120
101
|
}
|
|
121
|
-
|
|
102
|
+
// Hs(D8 || varint(i)) mod L; keccak output as little-endian scalar.
|
|
122
103
|
export function deriveScalar(d8Bytes, outputIndex) {
|
|
123
104
|
const hash = deriveScalarBytes(d8Bytes, outputIndex);
|
|
124
105
|
const raw = bytesToBigIntLE(hash);
|
|
125
106
|
return ((raw % ED25519_GROUP_ORDER) + ED25519_GROUP_ORDER) % ED25519_GROUP_ORDER;
|
|
126
107
|
}
|
|
127
|
-
|
|
108
|
+
// Raw 32B keccak256(D8 || varint(i)).
|
|
128
109
|
export function deriveScalarBytes(d8Bytes, outputIndex) {
|
|
129
110
|
const varintBuf = encodeVarint(outputIndex);
|
|
130
111
|
const preimage = new Uint8Array(d8Bytes.length + varintBuf.length);
|
|
@@ -132,18 +113,16 @@ export function deriveScalarBytes(d8Bytes, outputIndex) {
|
|
|
132
113
|
preimage.set(varintBuf, d8Bytes.length);
|
|
133
114
|
return keccak_256(preimage);
|
|
134
115
|
}
|
|
135
|
-
|
|
116
|
+
// RingCT amount decryption (Bulletproofs+ style 8-byte XOR).
|
|
117
|
+
// Matches wallet2 / Rust WASM decrypt_amount_inner:
|
|
118
|
+
// derivation_scalar = sc_reduce32(keccak256(D8 || varint(i)))
|
|
119
|
+
// amount_key = keccak256("amount" || derivation_scalar.as_bytes())
|
|
120
|
+
// The reduced scalar is serialised canonically as 32 LE bytes before the
|
|
121
|
+
// second hash. Skipping mod-L reduction silently produces garbage XOR
|
|
122
|
+
// plaintexts whenever the hash exceeds the group order.
|
|
136
123
|
export function decryptAmount(d8Bytes, outputIndex, ecdhInfo) {
|
|
137
124
|
if (!ecdhInfo)
|
|
138
125
|
return 0n;
|
|
139
|
-
// Match wallet2 / Rust WASM `decrypt_amount_inner`:
|
|
140
|
-
// derivation_scalar = sc_reduce32(keccak256(D8 || varint(i)))
|
|
141
|
-
// amount_key = keccak256("amount" || derivation_scalar.as_bytes())
|
|
142
|
-
// The reduced scalar is serialised canonically as 32 LE bytes before the
|
|
143
|
-
// second hash. Feeding the raw keccak256 output (without mod-L reduction)
|
|
144
|
-
// is wrong whenever the hash exceeds the group order, which silently
|
|
145
|
-
// produces garbage XOR plaintexts that can pass a one-sided
|
|
146
|
-
// `< expectedAmount` check downstream.
|
|
147
126
|
const rawDerivationHash = deriveScalarBytes(d8Bytes, outputIndex);
|
|
148
127
|
const derivationScalarBytes = bigIntToBytes(bytesToBigIntLE(rawDerivationHash));
|
|
149
128
|
const amountPrefix = new TextEncoder().encode('amount');
|
|
@@ -151,20 +130,18 @@ export function decryptAmount(d8Bytes, outputIndex, ecdhInfo) {
|
|
|
151
130
|
amountPreimage.set(amountPrefix);
|
|
152
131
|
amountPreimage.set(derivationScalarBytes, amountPrefix.length);
|
|
153
132
|
const amountKey = keccak_256(amountPreimage);
|
|
154
|
-
// XOR first 8 bytes
|
|
155
133
|
const encryptedAmount = hexToBytes(ecdhInfo.amount);
|
|
156
134
|
const decrypted = new Uint8Array(8);
|
|
157
135
|
for (let i = 0; i < 8; i++) {
|
|
158
136
|
decrypted[i] = (encryptedAmount[i] ?? 0) ^ (amountKey[i] ?? 0);
|
|
159
137
|
}
|
|
160
|
-
// Read as little-endian u64
|
|
161
138
|
let amount = 0n;
|
|
162
139
|
for (let i = 7; i >= 0; i--) {
|
|
163
140
|
amount = (amount << 8n) | BigInt(decrypted[i] ?? 0);
|
|
164
141
|
}
|
|
165
142
|
return amount;
|
|
166
143
|
}
|
|
167
|
-
|
|
144
|
+
// Monero varint = unsigned LEB128.
|
|
168
145
|
export function encodeVarint(value) {
|
|
169
146
|
const bytes = [];
|
|
170
147
|
let v = value;
|