@totemsdk/chain-provider 0.2.0 → 0.3.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.
@@ -0,0 +1,10 @@
1
+ export type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, BroadcastResult, VerifyDepositParams, DepositVerification, MmrChunkProof, DepositAddressOptions, DepositVerifier, } from './types.js';
2
+ export { DEPOSIT_ADDRESS_DOMAIN, depositAddressFor, verifyDeposit, verifyDepositMmrProof, withDepositVerifier, } from './verify-deposit.js';
3
+ export { HostedProvider } from './providers/hosted.js';
4
+ export type { HostedProviderConfig } from './providers/hosted.js';
5
+ export { MinimaRpcProvider } from './providers/minima-rpc.js';
6
+ export { LookupClientProvider } from './providers/lookup-client.js';
7
+ export type { LookupClientLike } from './providers/lookup-client.js';
8
+ export { CompositeProvider } from './providers/composite.js';
9
+ export { resolveChainProvider, parseMinimaRpcUrl, assertConsentedNodeUrl, isSelfHosted, } from './resolve.js';
10
+ export type { ChainProviderMode, ChainProviderConfig, HostedRelayConfig, ResolveChainProviderOptions, ParsedMinimaRpcUrl, } from './resolve.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSelfHosted = exports.assertConsentedNodeUrl = exports.parseMinimaRpcUrl = exports.resolveChainProvider = exports.CompositeProvider = exports.LookupClientProvider = exports.MinimaRpcProvider = exports.HostedProvider = exports.withDepositVerifier = exports.verifyDepositMmrProof = exports.verifyDeposit = exports.depositAddressFor = exports.DEPOSIT_ADDRESS_DOMAIN = void 0;
4
+ var verify_deposit_js_1 = require("./verify-deposit.js");
5
+ Object.defineProperty(exports, "DEPOSIT_ADDRESS_DOMAIN", { enumerable: true, get: function () { return verify_deposit_js_1.DEPOSIT_ADDRESS_DOMAIN; } });
6
+ Object.defineProperty(exports, "depositAddressFor", { enumerable: true, get: function () { return verify_deposit_js_1.depositAddressFor; } });
7
+ Object.defineProperty(exports, "verifyDeposit", { enumerable: true, get: function () { return verify_deposit_js_1.verifyDeposit; } });
8
+ Object.defineProperty(exports, "verifyDepositMmrProof", { enumerable: true, get: function () { return verify_deposit_js_1.verifyDepositMmrProof; } });
9
+ Object.defineProperty(exports, "withDepositVerifier", { enumerable: true, get: function () { return verify_deposit_js_1.withDepositVerifier; } });
10
+ var hosted_js_1 = require("./providers/hosted.js");
11
+ Object.defineProperty(exports, "HostedProvider", { enumerable: true, get: function () { return hosted_js_1.HostedProvider; } });
12
+ var minima_rpc_js_1 = require("./providers/minima-rpc.js");
13
+ Object.defineProperty(exports, "MinimaRpcProvider", { enumerable: true, get: function () { return minima_rpc_js_1.MinimaRpcProvider; } });
14
+ var lookup_client_js_1 = require("./providers/lookup-client.js");
15
+ Object.defineProperty(exports, "LookupClientProvider", { enumerable: true, get: function () { return lookup_client_js_1.LookupClientProvider; } });
16
+ var composite_js_1 = require("./providers/composite.js");
17
+ Object.defineProperty(exports, "CompositeProvider", { enumerable: true, get: function () { return composite_js_1.CompositeProvider; } });
18
+ var resolve_js_1 = require("./resolve.js");
19
+ Object.defineProperty(exports, "resolveChainProvider", { enumerable: true, get: function () { return resolve_js_1.resolveChainProvider; } });
20
+ Object.defineProperty(exports, "parseMinimaRpcUrl", { enumerable: true, get: function () { return resolve_js_1.parseMinimaRpcUrl; } });
21
+ Object.defineProperty(exports, "assertConsentedNodeUrl", { enumerable: true, get: function () { return resolve_js_1.assertConsentedNodeUrl; } });
22
+ Object.defineProperty(exports, "isSelfHosted", { enumerable: true, get: function () { return resolve_js_1.isSelfHosted; } });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * CompositeProvider — tries primary provider, falls back to secondary on any error.
3
+ */
4
+ import type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, BroadcastResult } from '../types.js';
5
+ export declare class CompositeProvider implements ChainStateProvider {
6
+ private readonly primary;
7
+ private readonly fallback;
8
+ private readonly onFallback?;
9
+ constructor(primary: ChainStateProvider, fallback: ChainStateProvider, onFallback?: ((method: string, error: unknown) => void) | undefined);
10
+ private withArg;
11
+ private withNoArg;
12
+ getCoins(query: CoinsQuery): Promise<Coin[]>;
13
+ getCoin(coinId: string): Promise<Coin | null>;
14
+ getProof(coinId: string): Promise<MMRProof>;
15
+ getTip(): Promise<ChainTip>;
16
+ getToken(tokenId: string): Promise<TokenInfo>;
17
+ searchTokens(query: TokenSearchQuery): Promise<TokenInfo[]>;
18
+ getTokensByCreator(address: string): Promise<TokenInfo[]>;
19
+ broadcastTxPoW(txpowHex: string): Promise<BroadcastResult>;
20
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * CompositeProvider — tries primary provider, falls back to secondary on any error.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CompositeProvider = void 0;
7
+ class CompositeProvider {
8
+ constructor(primary, fallback, onFallback) {
9
+ this.primary = primary;
10
+ this.fallback = fallback;
11
+ this.onFallback = onFallback;
12
+ }
13
+ withArg(method, arg) {
14
+ const p = this.primary;
15
+ const f = this.fallback;
16
+ return p[method](arg).catch((err) => {
17
+ this.onFallback?.(method, err);
18
+ return f[method](arg);
19
+ });
20
+ }
21
+ withNoArg(method) {
22
+ const p = this.primary;
23
+ const f = this.fallback;
24
+ return p[method]().catch((err) => {
25
+ this.onFallback?.(method, err);
26
+ return f[method]();
27
+ });
28
+ }
29
+ getCoins(query) {
30
+ return this.withArg('getCoins', query);
31
+ }
32
+ getCoin(coinId) {
33
+ return this.withArg('getCoin', coinId);
34
+ }
35
+ getProof(coinId) {
36
+ return this.withArg('getProof', coinId);
37
+ }
38
+ getTip() {
39
+ return this.withNoArg('getTip');
40
+ }
41
+ getToken(tokenId) {
42
+ return this.withArg('getToken', tokenId);
43
+ }
44
+ searchTokens(query) {
45
+ return this.withArg('searchTokens', query);
46
+ }
47
+ getTokensByCreator(address) {
48
+ return this.withArg('getTokensByCreator', address);
49
+ }
50
+ broadcastTxPoW(txpowHex) {
51
+ return this.withArg('broadcastTxPoW', txpowHex);
52
+ }
53
+ }
54
+ exports.CompositeProvider = CompositeProvider;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * HostedProvider — wraps Axia REST + RPC API endpoints.
3
+ *
4
+ * Endpoint map (all require x-api-key header):
5
+ * GET /v1/wallet/utxos/:address — coin list (totem-shared key)
6
+ * POST /v1/wallet/rpc — Minima RPC commands (totem-shared key)
7
+ * POST /api/meg/postminedtxn — broadcast mined TxPoW (no auth required)
8
+ *
9
+ * For dApp developers using custom project API keys the `/v1/wallet/*` routes
10
+ * require x-api-key: 'totem-shared'. Use the apiKey config option accordingly.
11
+ */
12
+ import type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, BroadcastResult } from '../types.js';
13
+ export interface HostedProviderConfig {
14
+ baseUrl: string;
15
+ apiKey: string;
16
+ timeoutMs?: number;
17
+ }
18
+ export declare class HostedProvider implements ChainStateProvider {
19
+ private readonly baseUrl;
20
+ private readonly apiKey;
21
+ private readonly timeoutMs;
22
+ constructor(config: HostedProviderConfig);
23
+ private fetchJson;
24
+ /**
25
+ * Send a Minima command to POST /v1/wallet/rpc.
26
+ * Returns the `response` field of the Minima envelope.
27
+ */
28
+ private rpc;
29
+ /**
30
+ * Get coins (UTXOs) for an address.
31
+ * Maps GET /v1/wallet/utxos/:address → Coin[].
32
+ */
33
+ getCoins(query: CoinsQuery): Promise<Coin[]>;
34
+ getCoin(coinId: string): Promise<Coin | null>;
35
+ /**
36
+ * Get MMR proof for a coin via Minima `coinproof` RPC command.
37
+ */
38
+ getProof(coinId: string): Promise<MMRProof>;
39
+ /**
40
+ * Get chain tip via Minima `status` RPC — parses response.chain.
41
+ */
42
+ getTip(): Promise<ChainTip>;
43
+ /**
44
+ * Get token info via Minima `tokens tokenid:X` RPC command.
45
+ */
46
+ getToken(tokenId: string): Promise<TokenInfo>;
47
+ /**
48
+ * Search tokens via Minima `tokens` RPC command, then filter client-side.
49
+ */
50
+ searchTokens(query: TokenSearchQuery): Promise<TokenInfo[]>;
51
+ getTokensByCreator(address: string): Promise<TokenInfo[]>;
52
+ /**
53
+ * Broadcast a mined TxPoW hex.
54
+ * Uses POST /api/meg/postminedtxn (the correct Axia MEG broadcast bridge).
55
+ */
56
+ broadcastTxPoW(txpowHex: string): Promise<BroadcastResult>;
57
+ private _mapToken;
58
+ }
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ /**
3
+ * HostedProvider — wraps Axia REST + RPC API endpoints.
4
+ *
5
+ * Endpoint map (all require x-api-key header):
6
+ * GET /v1/wallet/utxos/:address — coin list (totem-shared key)
7
+ * POST /v1/wallet/rpc — Minima RPC commands (totem-shared key)
8
+ * POST /api/meg/postminedtxn — broadcast mined TxPoW (no auth required)
9
+ *
10
+ * For dApp developers using custom project API keys the `/v1/wallet/*` routes
11
+ * require x-api-key: 'totem-shared'. Use the apiKey config option accordingly.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.HostedProvider = void 0;
15
+ function sanitizeRpcParam(value, name) {
16
+ if (value.length > 1024) {
17
+ throw new Error(`RPC parameter ${name} exceeds maximum length (1024)`);
18
+ }
19
+ if (/[\x00-\x1f\x7f]/.test(value)) {
20
+ throw new Error(`RPC parameter ${name} contains control characters`);
21
+ }
22
+ const trimmed = value.trim();
23
+ if (trimmed.length === 0) {
24
+ throw new Error(`RPC parameter ${name} is empty after trimming`);
25
+ }
26
+ return trimmed;
27
+ }
28
+ class HostedProvider {
29
+ constructor(config) {
30
+ this.baseUrl = config.baseUrl.replace(/\/$/, '');
31
+ if (!this.baseUrl.startsWith('https://')) {
32
+ throw new Error('HostedProvider requires HTTPS — credentials sent via x-api-key header');
33
+ }
34
+ this.apiKey = config.apiKey;
35
+ this.timeoutMs = config.timeoutMs ?? 30000;
36
+ }
37
+ async fetchJson(path, init) {
38
+ const controller = new AbortController();
39
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
40
+ try {
41
+ const res = await fetch(`${this.baseUrl}${path}`, {
42
+ ...init,
43
+ signal: controller.signal,
44
+ headers: {
45
+ 'x-api-key': this.apiKey,
46
+ 'Content-Type': 'application/json',
47
+ ...(init?.headers ?? {}),
48
+ },
49
+ });
50
+ if (!res.ok) {
51
+ throw new Error(`HostedProvider HTTP ${res.status} for ${path}`);
52
+ }
53
+ return res.json();
54
+ }
55
+ finally {
56
+ clearTimeout(timer);
57
+ }
58
+ }
59
+ /**
60
+ * Send a Minima command to POST /v1/wallet/rpc.
61
+ * Returns the `response` field of the Minima envelope.
62
+ */
63
+ async rpc(command) {
64
+ const controller = new AbortController();
65
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
66
+ try {
67
+ const res = await fetch(`${this.baseUrl}/v1/wallet/rpc`, {
68
+ method: 'POST',
69
+ signal: controller.signal,
70
+ headers: {
71
+ 'Content-Type': 'text/plain',
72
+ 'x-api-key': this.apiKey,
73
+ },
74
+ body: command,
75
+ });
76
+ if (!res.ok)
77
+ throw new Error(`HostedProvider RPC "${command}" HTTP ${res.status}`);
78
+ const json = await res.json();
79
+ if (json.status === false)
80
+ throw new Error(`RPC "${command}" failed: ${json.error ?? 'unknown'}`);
81
+ return json.response;
82
+ }
83
+ finally {
84
+ clearTimeout(timer);
85
+ }
86
+ }
87
+ /**
88
+ * Get coins (UTXOs) for an address.
89
+ * Maps GET /v1/wallet/utxos/:address → Coin[].
90
+ */
91
+ async getCoins(query) {
92
+ if (!query.address && !query.coinId)
93
+ return [];
94
+ if (query.coinId) {
95
+ const coin = await this.getCoin(query.coinId);
96
+ return coin ? [coin] : [];
97
+ }
98
+ const data = await this.fetchJson(`/v1/wallet/utxos/${encodeURIComponent(query.address)}`);
99
+ const raw = data.utxos ?? [];
100
+ return raw
101
+ .filter((u) => {
102
+ if (query.tokenId && u.tokenid !== query.tokenId)
103
+ return false;
104
+ if (query.sendable !== undefined && !!u.spent !== !query.sendable)
105
+ return false;
106
+ return true;
107
+ })
108
+ .map((u) => ({
109
+ coinid: u.coinid ?? u.id ?? '',
110
+ amount: String(u.amount ?? '0'),
111
+ address: u.address ?? query.address ?? '',
112
+ miniaddress: u.miniaddress,
113
+ tokenid: u.tokenid ?? '0x00',
114
+ token: u.token,
115
+ storestate: u.storestate,
116
+ state: u.state,
117
+ spent: !!u.spent,
118
+ mmrentry: u.mmrentry,
119
+ created: u.created,
120
+ }));
121
+ }
122
+ async getCoin(coinId) {
123
+ try {
124
+ const clean = sanitizeRpcParam(coinId, 'coinId');
125
+ const coins = await this.rpc(`coins coinid:${clean}`);
126
+ const u = Array.isArray(coins) ? coins[0] : null;
127
+ if (!u)
128
+ return null;
129
+ return {
130
+ coinid: u.coinid ?? coinId,
131
+ amount: String(u.amount ?? '0'),
132
+ address: u.address ?? '',
133
+ miniaddress: u.miniaddress,
134
+ tokenid: u.tokenid ?? '0x00',
135
+ token: u.token,
136
+ storestate: u.storestate,
137
+ state: u.state,
138
+ spent: !!u.spent,
139
+ mmrentry: u.mmrentry,
140
+ created: u.created,
141
+ };
142
+ }
143
+ catch {
144
+ return null;
145
+ }
146
+ }
147
+ /**
148
+ * Get MMR proof for a coin via Minima `coinproof` RPC command.
149
+ */
150
+ async getProof(coinId) {
151
+ const clean = sanitizeRpcParam(coinId, 'coinId');
152
+ const data = await this.rpc(`coinproof coinid:${clean}`);
153
+ return { coinid: coinId, data };
154
+ }
155
+ /**
156
+ * Get chain tip via Minima `status` RPC — parses response.chain.
157
+ */
158
+ async getTip() {
159
+ const data = await this.rpc('status');
160
+ const chain = data?.chain;
161
+ return {
162
+ block: chain?.block ?? 0,
163
+ hash: chain?.hash ?? '',
164
+ time: chain?.time,
165
+ };
166
+ }
167
+ /**
168
+ * Get token info via Minima `tokens tokenid:X` RPC command.
169
+ */
170
+ async getToken(tokenId) {
171
+ const clean = sanitizeRpcParam(tokenId, 'tokenId');
172
+ const data = await this.rpc(`tokens tokenid:${clean}`);
173
+ const t = Array.isArray(data) ? data[0] : data;
174
+ if (!t)
175
+ throw new Error(`Token not found: ${tokenId}`);
176
+ return this._mapToken(t);
177
+ }
178
+ /**
179
+ * Search tokens via Minima `tokens` RPC command, then filter client-side.
180
+ */
181
+ async searchTokens(query) {
182
+ const data = await this.rpc('tokens');
183
+ const all = Array.isArray(data) ? data : [];
184
+ return all
185
+ .filter((t) => {
186
+ if (t.tokenid === '0x00')
187
+ return false; // skip native Minima
188
+ if (query.name) {
189
+ const n = typeof t.name === 'object' ? (t.name?.name ?? '') : String(t.name ?? '');
190
+ if (!n.toLowerCase().includes(query.name.toLowerCase()))
191
+ return false;
192
+ }
193
+ return true;
194
+ })
195
+ .slice(query.offset ?? 0, query.limit ? (query.offset ?? 0) + query.limit : undefined)
196
+ .map(this._mapToken);
197
+ }
198
+ async getTokensByCreator(address) {
199
+ return this.searchTokens({ creatorAddress: address });
200
+ }
201
+ /**
202
+ * Broadcast a mined TxPoW hex.
203
+ * Uses POST /api/meg/postminedtxn (the correct Axia MEG broadcast bridge).
204
+ */
205
+ async broadcastTxPoW(txpowHex) {
206
+ try {
207
+ const controller = new AbortController();
208
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
209
+ let result;
210
+ try {
211
+ const res = await fetch(`${this.baseUrl}/api/meg/postminedtxn`, {
212
+ method: 'POST',
213
+ signal: controller.signal,
214
+ headers: { 'Content-Type': 'application/json' },
215
+ body: JSON.stringify({ data: txpowHex }),
216
+ });
217
+ result = await res.json();
218
+ if (!res.ok)
219
+ return { success: false, message: `HTTP ${res.status}: ${result?.error ?? ''}` };
220
+ }
221
+ finally {
222
+ clearTimeout(timer);
223
+ }
224
+ return { success: true, txpowid: result?.txpowid, message: result?.message };
225
+ }
226
+ catch (e) {
227
+ return { success: false, message: String(e) };
228
+ }
229
+ }
230
+ _mapToken(t) {
231
+ return {
232
+ tokenid: t.tokenid ?? '',
233
+ name: typeof t.name === 'object' ? t.name : { name: String(t.name ?? '') },
234
+ total: t.total,
235
+ confirmed: t.confirmed,
236
+ sendable: t.sendable,
237
+ coins: t.coins,
238
+ script: t.script,
239
+ description: t.description,
240
+ };
241
+ }
242
+ }
243
+ exports.HostedProvider = HostedProvider;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * LookupClientProvider — ChainStateProvider backed by a @totemsdk/lookup-client instance.
3
+ *
4
+ * Accepts any object that satisfies LookupClientLike (structural duck-typing),
5
+ * so @totemsdk/lookup-client remains a peer dependency: chain-provider does not
6
+ * bundle or import it at runtime. The caller is responsible for constructing the
7
+ * LookupClient and passing it in.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
12
+ *
13
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
14
+ * const provider = new LookupClientProvider(client);
15
+ *
16
+ * const tip = await provider.getTip();
17
+ * const coins = await provider.getCoins({ address: 'Mx...' });
18
+ * ```
19
+ *
20
+ * Use inside a CompositeProvider for sovereign-first / hosted-fallback:
21
+ *
22
+ * ```ts
23
+ * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
24
+ * import { connectLookupNode } from '@totemsdk/lookup-client';
25
+ *
26
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
27
+ * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
28
+ *
29
+ * const provider = new CompositeProvider(
30
+ * new LookupClientProvider(client),
31
+ * fallback,
32
+ * );
33
+ * ```
34
+ */
35
+ import type { BroadcastResult, ChainStateProvider, ChainTip, Coin, CoinsQuery, MMRProof, TokenInfo, TokenSearchQuery } from '../types.js';
36
+ /**
37
+ * Structural interface describing the subset of LookupClient methods that
38
+ * LookupClientProvider requires. Any object satisfying this interface can be
39
+ * passed in — most commonly a `LookupClient` from @totemsdk/lookup-client.
40
+ */
41
+ export interface LookupClientLike {
42
+ getCoins(query: CoinsQuery): Promise<Coin[]>;
43
+ getCoin(coinId: string): Promise<Coin | null>;
44
+ getProof(coinId: string): Promise<MMRProof>;
45
+ getTip(): Promise<ChainTip>;
46
+ getToken(tokenId: string): Promise<TokenInfo>;
47
+ searchTokens(query: TokenSearchQuery): Promise<TokenInfo[]>;
48
+ getTokensByCreator(address: string): Promise<TokenInfo[]>;
49
+ broadcastTxPoW(txpowHex: string): Promise<BroadcastResult>;
50
+ }
51
+ export declare class LookupClientProvider implements ChainStateProvider {
52
+ private readonly _client;
53
+ constructor(_client: LookupClientLike);
54
+ getCoins(query: CoinsQuery): Promise<Coin[]>;
55
+ getCoin(coinId: string): Promise<Coin | null>;
56
+ getProof(coinId: string): Promise<MMRProof>;
57
+ getTip(): Promise<ChainTip>;
58
+ getToken(tokenId: string): Promise<TokenInfo>;
59
+ searchTokens(query: TokenSearchQuery): Promise<TokenInfo[]>;
60
+ getTokensByCreator(address: string): Promise<TokenInfo[]>;
61
+ broadcastTxPoW(txpowHex: string): Promise<BroadcastResult>;
62
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * LookupClientProvider — ChainStateProvider backed by a @totemsdk/lookup-client instance.
4
+ *
5
+ * Accepts any object that satisfies LookupClientLike (structural duck-typing),
6
+ * so @totemsdk/lookup-client remains a peer dependency: chain-provider does not
7
+ * bundle or import it at runtime. The caller is responsible for constructing the
8
+ * LookupClient and passing it in.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { connectLookupNode, LookupClientProvider } from '@totemsdk/lookup-client';
13
+ *
14
+ * const client = await connectLookupNode({ hyperswarmTopic: 'deadbeef...' });
15
+ * const provider = new LookupClientProvider(client);
16
+ *
17
+ * const tip = await provider.getTip();
18
+ * const coins = await provider.getCoins({ address: 'Mx...' });
19
+ * ```
20
+ *
21
+ * Use inside a CompositeProvider for sovereign-first / hosted-fallback:
22
+ *
23
+ * ```ts
24
+ * import { CompositeProvider, HostedProvider, LookupClientProvider } from '@totemsdk/chain-provider';
25
+ * import { connectLookupNode } from '@totemsdk/lookup-client';
26
+ *
27
+ * const client = await connectLookupNode({ hyperswarmTopic: 'abc...' });
28
+ * const fallback = new HostedProvider({ baseUrl: 'https://api.axia.to', projectId: '...' });
29
+ *
30
+ * const provider = new CompositeProvider(
31
+ * new LookupClientProvider(client),
32
+ * fallback,
33
+ * );
34
+ * ```
35
+ */
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.LookupClientProvider = void 0;
38
+ class LookupClientProvider {
39
+ constructor(_client) {
40
+ this._client = _client;
41
+ }
42
+ getCoins(query) {
43
+ return this._client.getCoins(query);
44
+ }
45
+ getCoin(coinId) {
46
+ return this._client.getCoin(coinId);
47
+ }
48
+ getProof(coinId) {
49
+ return this._client.getProof(coinId);
50
+ }
51
+ getTip() {
52
+ return this._client.getTip();
53
+ }
54
+ getToken(tokenId) {
55
+ return this._client.getToken(tokenId);
56
+ }
57
+ searchTokens(query) {
58
+ return this._client.searchTokens(query);
59
+ }
60
+ getTokensByCreator(address) {
61
+ return this._client.getTokensByCreator(address);
62
+ }
63
+ broadcastTxPoW(txpowHex) {
64
+ return this._client.broadcastTxPoW(txpowHex);
65
+ }
66
+ }
67
+ exports.LookupClientProvider = LookupClientProvider;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * MinimaRpcProvider — thin wrapper over @totemsdk/minima-rpc.
3
+ */
4
+ import type { MinimaRpcClient } from '@totemsdk/minima-rpc';
5
+ import type { ChainStateProvider, CoinsQuery, Coin, MMRProof, ChainTip, TokenInfo, TokenSearchQuery, BroadcastResult, DepositVerifier, VerifyDepositParams, DepositVerification } from '../types.js';
6
+ export declare class MinimaRpcProvider implements ChainStateProvider, DepositVerifier {
7
+ private readonly client;
8
+ constructor(client: MinimaRpcClient);
9
+ getCoins(query: CoinsQuery): Promise<Coin[]>;
10
+ getCoin(coinId: string): Promise<Coin | null>;
11
+ /**
12
+ * Authoritative live check via `coinexport` (the coinproof endpoint): returns
13
+ * found/unspent/owned/token/amount + the full coin proof. `coincheck` on
14
+ * totem-node wants a full proof payload rather than a coinid, so coinexport
15
+ * is the canonical primitive (#3).
16
+ */
17
+ verifyDeposit(params: VerifyDepositParams): Promise<DepositVerification>;
18
+ depositAddressFor(lp: string, opts?: {
19
+ poolId?: string;
20
+ tokenId?: string;
21
+ }): string;
22
+ /** MMR root at tip — the anchor peers verify offline proofs against. */
23
+ getMmrRoot(): Promise<string | null>;
24
+ getProof(coinId: string): Promise<MMRProof>;
25
+ /**
26
+ * Current minimum TxPoW work from the tip block's Magic numbers (`magic`
27
+ * command). This is the live target locally mined transactions must meet;
28
+ * using it avoids hardcoding a difficulty that may be harder than the
29
+ * network currently requires (or easier than it has drifted to).
30
+ */
31
+ getMinTxPowWork(): Promise<string | null>;
32
+ getTip(): Promise<ChainTip>;
33
+ getToken(tokenId: string): Promise<TokenInfo>;
34
+ searchTokens(query: TokenSearchQuery): Promise<TokenInfo[]>;
35
+ getTokensByCreator(address: string): Promise<TokenInfo[]>;
36
+ /**
37
+ * Submit a raw transaction + witness via the node's explicit-mine path.
38
+ *
39
+ * `sendtransaction` only adds a pre-built TxPoW to the mempool; a TxPoW built
40
+ * outside the node has a placeholder header (block number 0, block difficulty
41
+ * MAX_HASH), which the node's block builder does not reliably promote. The
42
+ * node's own `txnmine` builds the header with the real tip fields and mines
43
+ * it. We then post that mined TxPoW with `sendtransaction`.
44
+ *
45
+ * TxnRow wire format (Java/C++): MiniString(id) || Transaction || Witness.
46
+ */
47
+ submitTransaction(txBytes: Uint8Array, witnessBytes: Uint8Array, id?: string): Promise<BroadcastResult>;
48
+ broadcastTxPoW(txpowHex: string): Promise<BroadcastResult>;
49
+ }