@le-space/chains 0.0.0-stage → 0.2.0
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/LICENSE +662 -0
- package/README.md +26 -2
- package/package.json +58 -3
- package/src/akash-console.js +456 -0
- package/src/akash-deployments.js +145 -0
- package/src/alchemy.js +648 -0
- package/src/aleph.js +448 -0
- package/src/bech32.js +126 -0
- package/src/bitcoin.js +366 -0
- package/src/core.js +8 -0
- package/src/cosmos-chains.js +80 -0
- package/src/cosmos.js +591 -0
- package/src/evm.js +697 -0
- package/src/explorer.js +14 -0
- package/src/filecoin-chain.js +45 -0
- package/src/filecoin.js +398 -0
- package/src/http.js +121 -0
- package/src/index.js +66 -0
- package/src/near.js +655 -0
- package/src/protobuf.js +130 -0
- package/src/registry.js +290 -0
- package/src/swaps.js +61 -0
- package/src/wallets.js +236 -0
- package/test/support/aleph-fetch.js +80 -0
- package/test/support/aleph-sample.js +74 -0
- package/test/support/fake-cosmos.js +650 -0
- package/test/support/fake-filfox.js +87 -0
package/src/bitcoin.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// A Bitcoin wallet, read only, by its account's extended public key: a zpub
|
|
2
|
+
// (BIP84, native SegWit, bc1q…), a ypub (BIP49, 3…), or an xpub – which
|
|
3
|
+
// wallets hand out for either kind, so with an xpub the address type is said
|
|
4
|
+
// at setup: `p2wpkh` (bc1q…) or `p2pkh` (1…).
|
|
5
|
+
//
|
|
6
|
+
// The key never leaves the bridge: `pnpm setup:bitcoin` puts it into the
|
|
7
|
+
// macOS keychain (account `bitcoin`, JSON `{ key, type }`), and the app knows
|
|
8
|
+
// the wallet only by a fingerprint (`btc-` + 8 hex of the key's SHA-256),
|
|
9
|
+
// which the bridge checks on every sync, so a replaced key does not book onto
|
|
10
|
+
// the old account.
|
|
11
|
+
//
|
|
12
|
+
// Addresses are derived here (the key is the account; /0/i receive, /1/i
|
|
13
|
+
// change) until 20 in a row have never been used (BIP44 gap limit). Each used
|
|
14
|
+
// address is asked of an Esplora API (mempool.space by default, or the
|
|
15
|
+
// person's own):
|
|
16
|
+
// GET /address/<a> chain_stats: used? balance
|
|
17
|
+
// GET /address/<a>/txs/chain[/<last>] its confirmed transactions, 25 a page
|
|
18
|
+
// That API sees every address asked and this Mac's IP, so it can tell they
|
|
19
|
+
// belong together – the consent screen says so; an own Esplora avoids it.
|
|
20
|
+
//
|
|
21
|
+
// How a transaction becomes entries, from the wallet's point of view (all
|
|
22
|
+
// its addresses together):
|
|
23
|
+
// - ours in = sum of inputs from our addresses, ours out = outputs to them
|
|
24
|
+
// - all inputs ours: we sent. The fee is an entry of its own (type fee),
|
|
25
|
+
// the rest is sent to the others (nothing, if all went to our change)
|
|
26
|
+
// - no input ours: we received what went to our addresses
|
|
27
|
+
// - some inputs ours (a payjoin or coinjoin): one entry with the net
|
|
28
|
+
// change, fee included, marked in the memo – rare, and for a person
|
|
29
|
+
// Only confirmed transactions are booked; unconfirmed ones are counted.
|
|
30
|
+
// The log gets counts, never an address, a txid or the key.
|
|
31
|
+
|
|
32
|
+
import { HDKey } from '@scure/bip32';
|
|
33
|
+
import { bech32, createBase58check } from '@scure/base';
|
|
34
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
35
|
+
import { ripemd160 } from '@noble/hashes/legacy.js';
|
|
36
|
+
import { toHex, utf8 } from '@le-space/ledger/bytes';
|
|
37
|
+
|
|
38
|
+
import { txUrl } from './registry.js';
|
|
39
|
+
import { createJsonFetcher, WalletError } from './http.js';
|
|
40
|
+
import { unitsToDecimal } from './cosmos.js';
|
|
41
|
+
|
|
42
|
+
/** SLIP-132 version bytes (mainnet) of each extended public key, with its private twin. */
|
|
43
|
+
const VERSIONS = /** @type {const} */ ({
|
|
44
|
+
xpub: { public: 0x0488b21e, private: 0x0488ade4 },
|
|
45
|
+
ypub: { public: 0x049d7cb2, private: 0x049d7878 },
|
|
46
|
+
zpub: { public: 0x04b24746, private: 0x04b2430c }
|
|
47
|
+
});
|
|
48
|
+
/** The address type a prefix means; an xpub says nothing. */
|
|
49
|
+
const TYPE_OF = /** @type {const} */ ({ ypub: 'p2sh-p2wpkh', zpub: 'p2wpkh' });
|
|
50
|
+
export const ADDRESS_TYPES = /** @type {const} */ (['p2wpkh', 'p2sh-p2wpkh', 'p2pkh']);
|
|
51
|
+
const base58check = createBase58check(sha256);
|
|
52
|
+
const GAP_LIMIT = 20;
|
|
53
|
+
const MAX_ADDRESSES = 2000;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The fingerprint the app knows a key by: `btc-` + the first 8 hex of its
|
|
57
|
+
* SHA-256. Tells two keys apart; says nothing about the addresses.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} key
|
|
60
|
+
*/
|
|
61
|
+
export function keyFingerprint(key) {
|
|
62
|
+
return `btc-${toHex(sha256(utf8(key.trim()))).slice(0, 8)}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* An extended public key and the address type to derive.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} text xpub…, ypub… or zpub…
|
|
69
|
+
* @param {string} [type] required for an xpub
|
|
70
|
+
* @returns {{ account: HDKey, type: 'p2wpkh' | 'p2sh-p2wpkh' | 'p2pkh' }} throws a WalletError when it is none
|
|
71
|
+
*/
|
|
72
|
+
export function parseExtendedKey(text, type) {
|
|
73
|
+
const key = String(text ?? '').trim();
|
|
74
|
+
const prefix = /** @type {keyof typeof VERSIONS} */ (key.slice(0, 4));
|
|
75
|
+
if (!Object.hasOwn(VERSIONS, prefix)) {
|
|
76
|
+
throw new WalletError('not an extended public key (xpub, ypub or zpub)', 'WALLET_ADDRESS', 400);
|
|
77
|
+
}
|
|
78
|
+
const implied = prefix === 'xpub' ? null : TYPE_OF[prefix];
|
|
79
|
+
const chosen = type ?? implied;
|
|
80
|
+
if (!chosen || !ADDRESS_TYPES.includes(/** @type {any} */ (chosen))) {
|
|
81
|
+
throw new WalletError(
|
|
82
|
+
'an xpub needs its address type: p2wpkh (bc1q…) or p2pkh (1…)',
|
|
83
|
+
'WALLET_ADDRESS',
|
|
84
|
+
400
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (implied && chosen !== implied) {
|
|
88
|
+
throw new WalletError(`a ${prefix} is ${implied}, not ${chosen}`, 'WALLET_ADDRESS', 400);
|
|
89
|
+
}
|
|
90
|
+
/** @type {HDKey} */ let account;
|
|
91
|
+
try {
|
|
92
|
+
account = HDKey.fromExtendedKey(key, VERSIONS[prefix]);
|
|
93
|
+
} catch {
|
|
94
|
+
throw new WalletError(
|
|
95
|
+
'not a valid extended public key (checksum or length)',
|
|
96
|
+
'WALLET_ADDRESS',
|
|
97
|
+
400
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (account.privateKey) {
|
|
101
|
+
throw new WalletError('that is a private key; give the public one', 'WALLET_ADDRESS', 400);
|
|
102
|
+
}
|
|
103
|
+
return { account, type: /** @type {'p2wpkh' | 'p2sh-p2wpkh' | 'p2pkh'} */ (chosen) };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The keychain's entry: JSON `{ key, type }`, or a bare zpub/ypub.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} stored
|
|
110
|
+
*/
|
|
111
|
+
export function parseStoredKey(stored) {
|
|
112
|
+
/** @type {any} */ let value = null;
|
|
113
|
+
try {
|
|
114
|
+
value = JSON.parse(stored);
|
|
115
|
+
} catch {
|
|
116
|
+
value = { key: stored };
|
|
117
|
+
}
|
|
118
|
+
const key = String(value?.key ?? '').trim();
|
|
119
|
+
return { key, ...parseExtendedKey(key, value?.type || undefined) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The address of the public key at `<chain>/<index>` below the account.
|
|
124
|
+
*
|
|
125
|
+
* @param {HDKey} account
|
|
126
|
+
* @param {'p2wpkh' | 'p2sh-p2wpkh' | 'p2pkh'} type
|
|
127
|
+
* @param {0 | 1} chain 0 receive, 1 change
|
|
128
|
+
* @param {number} index
|
|
129
|
+
*/
|
|
130
|
+
export function deriveAddress(account, type, chain, index) {
|
|
131
|
+
const pub = account.deriveChild(chain).deriveChild(index).publicKey;
|
|
132
|
+
if (!pub) throw new WalletError('cannot derive a public key', 'WALLET_ADDRESS', 400);
|
|
133
|
+
const hash = ripemd160(sha256(pub));
|
|
134
|
+
if (type === 'p2wpkh') return bech32.encode('bc', [0, ...bech32.toWords(hash)]);
|
|
135
|
+
if (type === 'p2pkh') return base58check.encode(Uint8Array.of(0x00, ...hash));
|
|
136
|
+
// p2sh-p2wpkh: the script hash of `0 <20-byte key hash>`
|
|
137
|
+
const redeem = Uint8Array.of(0x00, 0x14, ...hash);
|
|
138
|
+
return base58check.encode(Uint8Array.of(0x05, ...ripemd160(sha256(redeem))));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @typedef {object} EsploraTx the parts this module reads
|
|
143
|
+
* @property {string} txid
|
|
144
|
+
* @property {{ confirmed: boolean, block_height?: number, block_time?: number }} status
|
|
145
|
+
* @property {number} fee sats
|
|
146
|
+
* @property {{ prevout: { scriptpubkey_address?: string, value: number } | null }[]} vin
|
|
147
|
+
* @property {{ scriptpubkey_address?: string, value: number }[]} vout
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Entries for our transactions (pure; the tests call it directly).
|
|
152
|
+
*
|
|
153
|
+
* @param {EsploraTx[]} txs confirmed, each once
|
|
154
|
+
* @param {Set<string>} own our addresses
|
|
155
|
+
* @param {import('./registry.js').BitcoinChain} chain
|
|
156
|
+
* @returns {import('./cosmos.js').WalletEntry[]}
|
|
157
|
+
*/
|
|
158
|
+
export function normalizeBitcoin(txs, own, chain) {
|
|
159
|
+
/** @type {import('./cosmos.js').WalletEntry[]} */
|
|
160
|
+
const entries = [];
|
|
161
|
+
const decimals = chain.native.decimals;
|
|
162
|
+
const btc = (/** @type {bigint} */ sats) => unitsToDecimal(sats, decimals);
|
|
163
|
+
for (const tx of [...txs].sort(
|
|
164
|
+
(a, b) => (a.status.block_height ?? 0) - (b.status.block_height ?? 0)
|
|
165
|
+
)) {
|
|
166
|
+
const inputs = tx.vin.map((i) => i.prevout).filter((p) => p !== null);
|
|
167
|
+
const oursIn = inputs.filter((p) => own.has(String(p?.scriptpubkey_address ?? '')));
|
|
168
|
+
const inSats = oursIn.reduce((s, p) => s + BigInt(p?.value ?? 0), 0n);
|
|
169
|
+
const outSats = tx.vout
|
|
170
|
+
.filter((o) => own.has(String(o.scriptpubkey_address ?? '')))
|
|
171
|
+
.reduce((s, o) => s + BigInt(o.value), 0n);
|
|
172
|
+
const time = new Date((tx.status.block_time ?? 0) * 1000).toISOString();
|
|
173
|
+
const base = {
|
|
174
|
+
hash: tx.txid,
|
|
175
|
+
height: tx.status.block_height ?? 0,
|
|
176
|
+
time,
|
|
177
|
+
date: time.slice(0, 10),
|
|
178
|
+
asset: chain.native.symbol,
|
|
179
|
+
decimals,
|
|
180
|
+
counterpartyLabel: '',
|
|
181
|
+
success: true,
|
|
182
|
+
explorerUrl: txUrl(chain.explorer, tx.txid)
|
|
183
|
+
};
|
|
184
|
+
const fee = BigInt(tx.fee ?? 0);
|
|
185
|
+
const allOurs = oursIn.length > 0 && oursIn.length === inputs.length;
|
|
186
|
+
const firstOther = (/** @type {{ scriptpubkey_address?: string }[]} */ list) =>
|
|
187
|
+
list.map((x) => String(x?.scriptpubkey_address ?? '')).find((a) => a && !own.has(a)) ?? '';
|
|
188
|
+
|
|
189
|
+
if (allOurs) {
|
|
190
|
+
const sent = inSats - outSats - fee; // what went to others
|
|
191
|
+
if (sent > 0n) {
|
|
192
|
+
entries.push({
|
|
193
|
+
...base,
|
|
194
|
+
id: `${tx.txid}:value`,
|
|
195
|
+
type: 'sent',
|
|
196
|
+
kind: 'transfer',
|
|
197
|
+
amount: btc(-sent),
|
|
198
|
+
counterparty: firstOther(tx.vout),
|
|
199
|
+
memo: ''
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (fee > 0n) {
|
|
203
|
+
entries.push({
|
|
204
|
+
...base,
|
|
205
|
+
id: `${tx.txid}:fee`,
|
|
206
|
+
type: 'fee',
|
|
207
|
+
kind: 'fee',
|
|
208
|
+
amount: btc(-fee),
|
|
209
|
+
counterparty: '',
|
|
210
|
+
memo: ''
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
} else if (oursIn.length === 0) {
|
|
214
|
+
if (outSats > 0n) {
|
|
215
|
+
entries.push({
|
|
216
|
+
...base,
|
|
217
|
+
id: `${tx.txid}:value`,
|
|
218
|
+
type: 'received',
|
|
219
|
+
kind: 'transfer',
|
|
220
|
+
amount: btc(outSats),
|
|
221
|
+
counterparty: firstOther(inputs.map((p) => p ?? {})),
|
|
222
|
+
memo: ''
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
const net = outSats - inSats;
|
|
227
|
+
if (net !== 0n) {
|
|
228
|
+
entries.push({
|
|
229
|
+
...base,
|
|
230
|
+
id: `${tx.txid}:value`,
|
|
231
|
+
type: net < 0n ? 'sent' : 'received',
|
|
232
|
+
kind: 'transfer',
|
|
233
|
+
amount: btc(net),
|
|
234
|
+
counterparty: firstOther(net < 0n ? tx.vout : inputs.map((p) => p ?? {})),
|
|
235
|
+
memo: 'Inputs from several wallets: the fee is included in this amount.'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return entries;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {object} options
|
|
245
|
+
* @param {typeof fetch} options.fetch
|
|
246
|
+
* @param {() => Promise<string | null>} options.getZpub the keychain's zpub, or null
|
|
247
|
+
* @param {number} [options.timeoutMs]
|
|
248
|
+
* @param {(ms: number) => Promise<void>} [options.sleep]
|
|
249
|
+
* @param {number} [options.pauseMs] between requests, to stay under a public API's limit
|
|
250
|
+
*/
|
|
251
|
+
export function createBitcoinClient({
|
|
252
|
+
fetch: f,
|
|
253
|
+
getZpub,
|
|
254
|
+
timeoutMs,
|
|
255
|
+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
256
|
+
pauseMs = 250
|
|
257
|
+
}) {
|
|
258
|
+
const getJson = createJsonFetcher({ fetch: f, timeoutMs, sleep });
|
|
259
|
+
/** @param {string} url */
|
|
260
|
+
const get = async (url) => {
|
|
261
|
+
if (pauseMs) await sleep(pauseMs);
|
|
262
|
+
return getJson(url);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
async function key() {
|
|
266
|
+
const stored = await getZpub().catch(() => null);
|
|
267
|
+
if (!stored) {
|
|
268
|
+
throw new WalletError(
|
|
269
|
+
'no Bitcoin key in the keychain: run `pnpm setup:bitcoin`',
|
|
270
|
+
'WALLET_NOT_SET_UP',
|
|
271
|
+
503
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
return parseStoredKey(stored);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
/** The fingerprint of the configured zpub, or null. */
|
|
279
|
+
async fingerprint() {
|
|
280
|
+
const stored = await getZpub().catch(() => null);
|
|
281
|
+
if (!stored) return null;
|
|
282
|
+
try {
|
|
283
|
+
return keyFingerprint(parseStoredKey(stored).key);
|
|
284
|
+
} catch {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {{ chain: import('./registry.js').BitcoinChain, address: string, endpoints: { api: string } }} params
|
|
291
|
+
* `address` is the fingerprint the app knows the wallet by
|
|
292
|
+
*/
|
|
293
|
+
async history({ chain, address, endpoints }) {
|
|
294
|
+
const { key: text, account, type } = await key();
|
|
295
|
+
if (address !== keyFingerprint(text)) {
|
|
296
|
+
throw new WalletError(
|
|
297
|
+
'the Bitcoin key in the keychain is not the one this wallet was added with',
|
|
298
|
+
'WALLET_KEY_CHANGED',
|
|
299
|
+
409
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** @type {Map<string, { funded: bigint, spent: bigint, txs: number }>} */
|
|
304
|
+
const used = new Map();
|
|
305
|
+
/** @type {Set<string>} */
|
|
306
|
+
const own = new Set();
|
|
307
|
+
for (const branch of /** @type {const} */ ([0, 1])) {
|
|
308
|
+
let unused = 0;
|
|
309
|
+
for (let i = 0; unused < GAP_LIMIT; i++) {
|
|
310
|
+
if (own.size >= MAX_ADDRESSES) {
|
|
311
|
+
throw new WalletError('more than 2000 addresses in use', 'WALLET_TOO_LARGE', 413);
|
|
312
|
+
}
|
|
313
|
+
const a = deriveAddress(account, type, branch, i);
|
|
314
|
+
own.add(a);
|
|
315
|
+
const info = await get(`${endpoints.api}/address/${a}`);
|
|
316
|
+
const s = info?.chain_stats ?? {};
|
|
317
|
+
const txs = Number(s.tx_count ?? 0) + Number(info?.mempool_stats?.tx_count ?? 0);
|
|
318
|
+
if (txs === 0) {
|
|
319
|
+
unused++;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
unused = 0;
|
|
323
|
+
used.set(a, {
|
|
324
|
+
funded: BigInt(s.funded_txo_sum ?? 0),
|
|
325
|
+
spent: BigInt(s.spent_txo_sum ?? 0),
|
|
326
|
+
txs: Number(s.tx_count ?? 0)
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** @type {Map<string, EsploraTx>} */
|
|
332
|
+
const confirmed = new Map();
|
|
333
|
+
for (const [a, stats] of used) {
|
|
334
|
+
if (!stats.txs) continue;
|
|
335
|
+
let last = '';
|
|
336
|
+
for (let page = 0; page < 1000; page++) {
|
|
337
|
+
/** @type {EsploraTx[]} */
|
|
338
|
+
const list = await get(
|
|
339
|
+
`${endpoints.api}/address/${a}/txs/chain${last ? `/${last}` : ''}`
|
|
340
|
+
);
|
|
341
|
+
if (!Array.isArray(list) || !list.length) break;
|
|
342
|
+
for (const tx of list) if (tx?.status?.confirmed) confirmed.set(tx.txid, tx);
|
|
343
|
+
last = list[list.length - 1].txid;
|
|
344
|
+
if (list.length < 25) break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const balance = [...used.values()].reduce((s, u) => s + u.funded - u.spent, 0n);
|
|
348
|
+
const entries = normalizeBitcoin([...confirmed.values()], own, chain);
|
|
349
|
+
return {
|
|
350
|
+
entries,
|
|
351
|
+
balances: [
|
|
352
|
+
{
|
|
353
|
+
asset: chain.native.symbol,
|
|
354
|
+
amount: unitsToDecimal(balance, chain.native.decimals),
|
|
355
|
+
decimals: chain.native.decimals
|
|
356
|
+
}
|
|
357
|
+
],
|
|
358
|
+
transactions: confirmed.size,
|
|
359
|
+
unknownAssets: 0,
|
|
360
|
+
history: { earliestHeight: 0, earliestTime: null, pruned: false },
|
|
361
|
+
addresses: { used: used.size, derived: own.size },
|
|
362
|
+
addressUrl: ''
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
package/src/core.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// What every chain reader shares (Le-Space/belege#264): JSON over HTTPS with
|
|
3
|
+
// errors that carry a code, amounts from units, explorer links, swap
|
|
4
|
+
// detection. The entry they hand out is @le-space/ledger's WalletEntry.
|
|
5
|
+
export { WalletError, hostOf, checkEndpoint, createJsonFetcher } from './http.js';
|
|
6
|
+
export { unitsToDecimal } from '@le-space/ledger/decimal';
|
|
7
|
+
export { txUrl, addressUrl } from './explorer.js';
|
|
8
|
+
export { markSwaps } from './swaps.js';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The Cosmos chains the bridge reads (#105, #264): Nym's Nyx and Akash –
|
|
2
|
+
// their denoms, default endpoints (CometBFT RPC, REST, Akash's indexer) and
|
|
3
|
+
// explorers.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} CosmosChain
|
|
7
|
+
* @property {string} id
|
|
8
|
+
* @property {'cosmos'} kind
|
|
9
|
+
* @property {string} name
|
|
10
|
+
* @property {string} shortName in account names: `Wallet USDC (Base) ···…`
|
|
11
|
+
* @property {string} chainId
|
|
12
|
+
* @property {string} caip2
|
|
13
|
+
* @property {string} bech32Prefix
|
|
14
|
+
* @property {string} nativeDenom
|
|
15
|
+
* @property {Record<string, import('@le-space/ledger/wallet-entry').ChainAsset>} denoms base denom → asset
|
|
16
|
+
* @property {{ rpc: string, rest: string, indexer?: string }} endpoints the defaults; `indexer`: the
|
|
17
|
+
* Akash Console indexer, read for what the pruned node no longer knows (akash-console.js)
|
|
18
|
+
* @property {{ rpc: string[], rest: string[] }} alternatives also public, e.g. an archive node
|
|
19
|
+
* @property {import('./explorer.js').Explorer} explorer
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** @type {CosmosChain} */
|
|
23
|
+
export const NYX_CHAIN = {
|
|
24
|
+
id: 'nyx',
|
|
25
|
+
kind: 'cosmos',
|
|
26
|
+
name: 'Nym (Nyx)',
|
|
27
|
+
shortName: 'Nyx',
|
|
28
|
+
chainId: 'nyx',
|
|
29
|
+
caip2: 'cosmos:nyx',
|
|
30
|
+
bech32Prefix: 'n',
|
|
31
|
+
nativeDenom: 'unym',
|
|
32
|
+
denoms: {
|
|
33
|
+
unym: { symbol: 'NYM', decimals: 6 },
|
|
34
|
+
unyx: { symbol: 'NYX', decimals: 6 }
|
|
35
|
+
},
|
|
36
|
+
endpoints: { rpc: 'https://rpc.nymtech.net', rest: 'https://api.nymtech.net' },
|
|
37
|
+
// Nym's own RPC keeps only the recent part of the chain (pruned);
|
|
38
|
+
// Nodes Guru's goes back to the first block.
|
|
39
|
+
alternatives: {
|
|
40
|
+
rpc: ['https://rpc.nyx.nodes.guru'],
|
|
41
|
+
rest: ['https://api.nyx.nodes.guru']
|
|
42
|
+
},
|
|
43
|
+
explorer: {
|
|
44
|
+
name: 'Nym Explorer (Nodes Guru)',
|
|
45
|
+
tx: 'https://nym.explorers.guru/transaction/{tx}',
|
|
46
|
+
address: 'https://nym.explorers.guru/account/{address}'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** @type {CosmosChain} */
|
|
51
|
+
export const AKASH_CHAIN = {
|
|
52
|
+
id: 'akash',
|
|
53
|
+
kind: 'cosmos',
|
|
54
|
+
name: 'Akash',
|
|
55
|
+
shortName: 'Akash',
|
|
56
|
+
chainId: 'akashnet-2',
|
|
57
|
+
caip2: 'cosmos:akashnet-2',
|
|
58
|
+
bech32Prefix: 'akash',
|
|
59
|
+
nativeDenom: 'uakt',
|
|
60
|
+
denoms: { uakt: { symbol: 'AKT', decimals: 6 } },
|
|
61
|
+
// Akash runs no public RPC of its own, and the public ones are pruned:
|
|
62
|
+
// checked 2026-09-27, PublicNode's keeps the longest history (from
|
|
63
|
+
// 2026-05-25), Polkachu's and Ecostake's only a few weeks (issue #105).
|
|
64
|
+
// The history before the node's window comes from the Akash Console
|
|
65
|
+
// indexer (akash-console.js, issue #105).
|
|
66
|
+
endpoints: {
|
|
67
|
+
rpc: 'https://akash-rpc.publicnode.com',
|
|
68
|
+
rest: 'https://akash-rest.publicnode.com',
|
|
69
|
+
indexer: 'https://console-api.akash.network'
|
|
70
|
+
},
|
|
71
|
+
alternatives: {
|
|
72
|
+
rpc: ['https://akash-rpc.polkachu.com', 'https://rpc-akash.ecostake.com'],
|
|
73
|
+
rest: ['https://akash-api.polkachu.com', 'https://rest-akash.ecostake.com']
|
|
74
|
+
},
|
|
75
|
+
explorer: {
|
|
76
|
+
name: 'Mintscan',
|
|
77
|
+
tx: 'https://www.mintscan.io/akash/transactions/{tx}',
|
|
78
|
+
address: 'https://www.mintscan.io/akash/accounts/{address}'
|
|
79
|
+
}
|
|
80
|
+
};
|