@qorechain/sdk 0.1.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/README.md +152 -0
- package/dist/index.cjs +1252 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1532 -0
- package/dist/index.d.ts +1532 -0
- package/dist/index.js +1191 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1532 @@
|
|
|
1
|
+
import { EncodeObject, OfflineDirectSigner, GeneratedType, OfflineSigner, Registry } from '@cosmjs/proto-signing';
|
|
2
|
+
import { Coin, StdFee } from '@cosmjs/amino';
|
|
3
|
+
export { Coin, StdFee } from '@cosmjs/amino';
|
|
4
|
+
import { DeliverTxResponse, SigningStargateClientOptions } from '@cosmjs/stargate';
|
|
5
|
+
import { CosmWasmClient, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
|
|
6
|
+
import { Any } from 'cosmjs-types/google/protobuf/any';
|
|
7
|
+
import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Network presets for the QoreChain SDK.
|
|
11
|
+
*
|
|
12
|
+
* Both the `testnet` and `mainnet` presets are fully populated and live. Their
|
|
13
|
+
* endpoints default to localhost ports so the SDK works out of the box against a
|
|
14
|
+
* locally running node; callers override these with real hostnames when creating
|
|
15
|
+
* a client. {@link getNetwork} returns either preset.
|
|
16
|
+
*/
|
|
17
|
+
/** Bech32 human-readable prefixes used across QoreChain address types. */
|
|
18
|
+
interface Bech32Prefixes {
|
|
19
|
+
/** Prefix for account addresses (e.g. `qor1...`). */
|
|
20
|
+
account: string;
|
|
21
|
+
/** Prefix for validator operator addresses (e.g. `qorvaloper1...`). */
|
|
22
|
+
validator: string;
|
|
23
|
+
/** Prefix for validator consensus addresses (e.g. `qorvalcons1...`). */
|
|
24
|
+
consensus: string;
|
|
25
|
+
}
|
|
26
|
+
/** Display and base denomination metadata for the network's staking coin. */
|
|
27
|
+
interface CoinInfo {
|
|
28
|
+
/** Human-facing denomination (e.g. `QOR`). */
|
|
29
|
+
display: string;
|
|
30
|
+
/** Base (smallest) denomination used on-chain (e.g. `uqor`). */
|
|
31
|
+
base: string;
|
|
32
|
+
/** Decimal exponent relating base to display (1 display = 10^exponent base). */
|
|
33
|
+
exponent: number;
|
|
34
|
+
}
|
|
35
|
+
/** Service endpoints for talking to a network across its supported VMs. */
|
|
36
|
+
interface NetworkEndpoints {
|
|
37
|
+
/** Cosmos SDK REST (LCD) endpoint. */
|
|
38
|
+
rest: string;
|
|
39
|
+
/** Cosmos SDK gRPC endpoint. */
|
|
40
|
+
grpc: string;
|
|
41
|
+
/** Consensus RPC endpoint. */
|
|
42
|
+
rpc: string;
|
|
43
|
+
/** EVM JSON-RPC HTTP endpoint. */
|
|
44
|
+
evmRpc: string;
|
|
45
|
+
/** EVM JSON-RPC WebSocket endpoint. */
|
|
46
|
+
evmWs: string;
|
|
47
|
+
/** SVM JSON-RPC endpoint. */
|
|
48
|
+
svmRpc: string;
|
|
49
|
+
}
|
|
50
|
+
/** A fully described network preset. */
|
|
51
|
+
interface NetworkConfig {
|
|
52
|
+
/** Canonical preset name. */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Whether the network is live and usable without custom endpoints. */
|
|
55
|
+
live: boolean;
|
|
56
|
+
/** Chain ID. */
|
|
57
|
+
chainId: string;
|
|
58
|
+
/** Bech32 prefixes for address encoding. */
|
|
59
|
+
bech32: Bech32Prefixes;
|
|
60
|
+
/** Staking coin metadata. */
|
|
61
|
+
coin: CoinInfo;
|
|
62
|
+
/** Default endpoints. */
|
|
63
|
+
endpoints: NetworkEndpoints;
|
|
64
|
+
}
|
|
65
|
+
/** Known network preset names. */
|
|
66
|
+
type NetworkName = "testnet" | "mainnet";
|
|
67
|
+
/** The set of built-in network presets, keyed by name. */
|
|
68
|
+
declare const NETWORKS: Record<NetworkName, NetworkConfig>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a network preset by name.
|
|
71
|
+
*
|
|
72
|
+
* @returns The requested {@link NetworkConfig}, guaranteed to be live and usable.
|
|
73
|
+
*/
|
|
74
|
+
declare function getNetwork(name: NetworkName): NetworkConfig;
|
|
75
|
+
/** List the known network preset names without triggering any liveness check. */
|
|
76
|
+
declare function listNetworks(): NetworkName[];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Shared HTTP transport for the read/query clients.
|
|
80
|
+
*
|
|
81
|
+
* Provides two primitives — {@link getJson} for REST GETs and
|
|
82
|
+
* {@link postJsonRpc} for JSON-RPC POSTs — both built on the global `fetch`.
|
|
83
|
+
* `fetch` is injectable so tests can mock the network entirely; nothing here
|
|
84
|
+
* ever performs a real request on its own.
|
|
85
|
+
*
|
|
86
|
+
* Failures surface as a typed {@link QoreHttpError} (non-2xx HTTP responses).
|
|
87
|
+
* Transient transport failures (5xx and network errors) are retried with a
|
|
88
|
+
* small fixed backoff up to a configurable count; 4xx responses are never
|
|
89
|
+
* retried. Each attempt is bounded by an `AbortSignal`-driven timeout.
|
|
90
|
+
*/
|
|
91
|
+
/** A `fetch`-compatible function. Defaults to `globalThis.fetch`. */
|
|
92
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
93
|
+
/** A JSON-serializable value usable as a query-string parameter. */
|
|
94
|
+
type QueryValue = string | number | boolean | undefined | null;
|
|
95
|
+
/** Options shared by all HTTP helpers. */
|
|
96
|
+
interface HttpOptions {
|
|
97
|
+
/** Injectable `fetch`. Defaults to `globalThis.fetch`. */
|
|
98
|
+
fetch?: FetchLike;
|
|
99
|
+
/** Per-attempt timeout in milliseconds. Defaults to 30000. `0` disables it. */
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
/** Number of retries after the initial attempt for retryable errors. Defaults to 2. */
|
|
102
|
+
retries?: number;
|
|
103
|
+
/** Fixed delay between retries in milliseconds. Defaults to 250. */
|
|
104
|
+
retryDelayMs?: number;
|
|
105
|
+
/** Extra request headers, merged over the defaults. */
|
|
106
|
+
headers?: Record<string, string>;
|
|
107
|
+
}
|
|
108
|
+
/** Options for {@link getJson}, adding query-string parameters. */
|
|
109
|
+
interface GetJsonOptions extends HttpOptions {
|
|
110
|
+
/** Query parameters; `undefined`/`null` values are omitted. */
|
|
111
|
+
query?: Record<string, QueryValue>;
|
|
112
|
+
}
|
|
113
|
+
/** Thrown when an HTTP response has a non-2xx status. */
|
|
114
|
+
declare class QoreHttpError extends Error {
|
|
115
|
+
/** HTTP status code of the failing response. */
|
|
116
|
+
readonly status: number;
|
|
117
|
+
/** The URL that was requested. */
|
|
118
|
+
readonly url: string;
|
|
119
|
+
/** Raw response body text, when available. */
|
|
120
|
+
readonly body?: string;
|
|
121
|
+
constructor(status: number, url: string, body?: string);
|
|
122
|
+
}
|
|
123
|
+
/** Append query params to a URL, skipping `undefined`/`null` values. */
|
|
124
|
+
declare function buildUrl(base: string, query?: Record<string, QueryValue>): string;
|
|
125
|
+
/** Join a base URL and a path without producing double slashes. */
|
|
126
|
+
declare function joinUrl(base: string, path: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Perform a GET request and parse the JSON response.
|
|
129
|
+
*
|
|
130
|
+
* @param url - Fully-qualified URL (without query string).
|
|
131
|
+
* @param opts - Query params, injectable `fetch`, timeout, and retry settings.
|
|
132
|
+
* @throws {@link QoreHttpError} on a non-2xx response.
|
|
133
|
+
*/
|
|
134
|
+
declare function getJson<T>(url: string, opts?: GetJsonOptions): Promise<T>;
|
|
135
|
+
/**
|
|
136
|
+
* POST a JSON-RPC body and parse the JSON response.
|
|
137
|
+
*
|
|
138
|
+
* This handles only the HTTP layer; JSON-RPC error envelopes are interpreted by
|
|
139
|
+
* the {@link JsonRpcClient}.
|
|
140
|
+
*
|
|
141
|
+
* @throws {@link QoreHttpError} on a non-2xx response.
|
|
142
|
+
*/
|
|
143
|
+
declare function postJsonRpc<T>(url: string, body: unknown, opts?: HttpOptions): Promise<T>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* REST (LCD) read client for QoreChain.
|
|
147
|
+
*
|
|
148
|
+
* Wraps the standard Cosmos SDK bank endpoints plus QoreChain's custom module
|
|
149
|
+
* read routes under `/qorechain/<module>/v1/...`. All requests go through the
|
|
150
|
+
* shared {@link getJson} helper, so `fetch` is injectable and failures surface
|
|
151
|
+
* as {@link QoreHttpError}.
|
|
152
|
+
*
|
|
153
|
+
* Response shapes are modeled only where they are simple and stable (e.g. bank
|
|
154
|
+
* balances); richer module responses are returned as a caller-supplied generic
|
|
155
|
+
* defaulting to {@link Record}<string, unknown> rather than over-modeled here.
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
/** Cosmos pagination response metadata. */
|
|
159
|
+
interface PageResponse {
|
|
160
|
+
next_key: string | null;
|
|
161
|
+
total?: string;
|
|
162
|
+
}
|
|
163
|
+
/** Response of the all-balances endpoint. */
|
|
164
|
+
interface AllBalancesResponse {
|
|
165
|
+
balances: Coin[];
|
|
166
|
+
pagination?: PageResponse;
|
|
167
|
+
}
|
|
168
|
+
/** Response of the single-denom balance endpoint. */
|
|
169
|
+
interface BalanceResponse {
|
|
170
|
+
balance: Coin;
|
|
171
|
+
}
|
|
172
|
+
/** Cosmos-style key/limit pagination input. */
|
|
173
|
+
interface Pagination {
|
|
174
|
+
key?: string;
|
|
175
|
+
limit?: number;
|
|
176
|
+
}
|
|
177
|
+
/** Options accepted by paginated list endpoints. */
|
|
178
|
+
interface PaginatedOptions {
|
|
179
|
+
pagination?: Pagination;
|
|
180
|
+
}
|
|
181
|
+
/** Options for {@link RestClient}. */
|
|
182
|
+
type RestClientOptions = HttpOptions;
|
|
183
|
+
/** Relative urgency of a fee estimate. */
|
|
184
|
+
type FeeUrgency = "fast" | "normal" | "slow";
|
|
185
|
+
/** Cosmos + QoreChain REST read client. */
|
|
186
|
+
declare class RestClient {
|
|
187
|
+
private readonly baseUrl;
|
|
188
|
+
private readonly opts;
|
|
189
|
+
/**
|
|
190
|
+
* @param baseUrl - The network's REST endpoint (e.g. `endpoints.rest`).
|
|
191
|
+
* @param opts - Injectable `fetch`, timeout, and retry settings.
|
|
192
|
+
*/
|
|
193
|
+
constructor(baseUrl: string, opts?: RestClientOptions);
|
|
194
|
+
/** Injectable fetch passthrough so the escape hatch reuses the same transport. */
|
|
195
|
+
private get fetchImpl();
|
|
196
|
+
/**
|
|
197
|
+
* Generic GET escape hatch for any documented REST route.
|
|
198
|
+
*
|
|
199
|
+
* @param path - Path beginning with `/` (e.g. `/qorechain/foo/v1/bar`).
|
|
200
|
+
* Embedded path params must be URL-encoded by the caller.
|
|
201
|
+
* @param query - Optional query parameters.
|
|
202
|
+
*/
|
|
203
|
+
get<T = Record<string, unknown>>(path: string, query?: Record<string, QueryValue>): Promise<T>;
|
|
204
|
+
/** All balances of `address` (`/cosmos/bank/v1beta1/balances/{address}`). */
|
|
205
|
+
getAllBalances(address: string, opts?: PaginatedOptions): Promise<AllBalancesResponse>;
|
|
206
|
+
/** Balance of `address` in `denom` (`.../balances/{address}/by_denom`). */
|
|
207
|
+
getBalance(address: string, denom: string): Promise<BalanceResponse>;
|
|
208
|
+
/** QCAI fee/network stats (`/qorechain/ai/v1/stats`). */
|
|
209
|
+
getAiStats<T = Record<string, unknown>>(): Promise<T>;
|
|
210
|
+
/** QCAI fee estimate for an urgency level (`/qorechain/ai/v1/fee-estimate`). */
|
|
211
|
+
getFeeEstimate<T = Record<string, unknown>>(urgency: FeeUrgency): Promise<T>;
|
|
212
|
+
/** Supported bridge chains (`/qorechain/bridge/v1/chains`). */
|
|
213
|
+
getBridgeChains<T = Record<string, unknown>>(): Promise<T>;
|
|
214
|
+
/** PQC account record (`/qorechain/pqc/v1/accounts/{address}`). */
|
|
215
|
+
getPqcAccount<T = Record<string, unknown>>(address: string): Promise<T>;
|
|
216
|
+
/** Validator reputation (`/qorechain/reputation/v1/validators/{address}`). */
|
|
217
|
+
getReputation<T = Record<string, unknown>>(validatorAddress: string): Promise<T>;
|
|
218
|
+
/** Token burn statistics (`/qorechain/burn/v1/stats`). */
|
|
219
|
+
getBurnStats<T = Record<string, unknown>>(): Promise<T>;
|
|
220
|
+
/** xQORE staking position (`/qorechain/xqore/v1/position/{address}`). */
|
|
221
|
+
getXqorePosition<T = Record<string, unknown>>(address: string): Promise<T>;
|
|
222
|
+
/** Current inflation rate (`/qorechain/inflation/v1/rate`). */
|
|
223
|
+
getInflationRate<T = Record<string, unknown>>(): Promise<T>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Generic JSON-RPC 2.0 client.
|
|
228
|
+
*
|
|
229
|
+
* Manages request ids (auto-incrementing per client), serializes the standard
|
|
230
|
+
* `{ jsonrpc, id, method, params }` envelope, and maps JSON-RPC error responses
|
|
231
|
+
* to a typed {@link JsonRpcError}. It is the transport base for both the EVM
|
|
232
|
+
* `eth_*`/`net_*`/`web3_*` methods and the QoreChain `qor_*` namespace.
|
|
233
|
+
*
|
|
234
|
+
* The underlying `fetch` is injectable via {@link HttpOptions} so callers and
|
|
235
|
+
* tests can supply their own transport.
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
/** A JSON-RPC 2.0 error object. */
|
|
239
|
+
interface JsonRpcErrorObject {
|
|
240
|
+
code: number;
|
|
241
|
+
message: string;
|
|
242
|
+
data?: unknown;
|
|
243
|
+
}
|
|
244
|
+
/** A JSON-RPC 2.0 response envelope. */
|
|
245
|
+
interface JsonRpcResponse<T> {
|
|
246
|
+
jsonrpc: "2.0";
|
|
247
|
+
id: number | string | null;
|
|
248
|
+
result?: T;
|
|
249
|
+
error?: JsonRpcErrorObject;
|
|
250
|
+
}
|
|
251
|
+
/** Thrown when a JSON-RPC response carries an `error` member. */
|
|
252
|
+
declare class JsonRpcError extends Error {
|
|
253
|
+
/** JSON-RPC error code. */
|
|
254
|
+
readonly code: number;
|
|
255
|
+
/** Optional implementation-defined error data. */
|
|
256
|
+
readonly data?: unknown;
|
|
257
|
+
constructor(code: number, message: string, data?: unknown);
|
|
258
|
+
}
|
|
259
|
+
/** Options for {@link JsonRpcClient}. */
|
|
260
|
+
type JsonRpcClientOptions = HttpOptions;
|
|
261
|
+
/** A minimal JSON-RPC 2.0 client over HTTP POST. */
|
|
262
|
+
declare class JsonRpcClient {
|
|
263
|
+
protected readonly url: string;
|
|
264
|
+
protected readonly opts: JsonRpcClientOptions;
|
|
265
|
+
private nextId;
|
|
266
|
+
constructor(url: string, opts?: JsonRpcClientOptions);
|
|
267
|
+
/**
|
|
268
|
+
* Invoke a JSON-RPC method and return its `result`.
|
|
269
|
+
*
|
|
270
|
+
* @param method - Wire method name (e.g. `"eth_chainId"`).
|
|
271
|
+
* @param params - Positional params; defaults to an empty array.
|
|
272
|
+
* @throws {@link JsonRpcError} when the response contains an `error`.
|
|
273
|
+
* @throws {@link QoreHttpError} on a non-2xx transport response.
|
|
274
|
+
*/
|
|
275
|
+
call<T>(method: string, params?: unknown[]): Promise<T>;
|
|
276
|
+
/** `eth_chainId` — the chain id as a hex quantity string. */
|
|
277
|
+
ethChainId(): Promise<string>;
|
|
278
|
+
/** `eth_blockNumber` — the latest block height as a hex quantity string. */
|
|
279
|
+
ethBlockNumber(): Promise<string>;
|
|
280
|
+
/** `eth_getBalance` — wei balance of `address` as a hex quantity string. */
|
|
281
|
+
ethGetBalance(address: string, block?: string): Promise<string>;
|
|
282
|
+
/** `net_version` — the network id as a decimal string. */
|
|
283
|
+
netVersion(): Promise<string>;
|
|
284
|
+
/** `web3_clientVersion` — the node client version string. */
|
|
285
|
+
web3ClientVersion(): Promise<string>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Typed wrappers for the QoreChain `qor_*` JSON-RPC namespace.
|
|
290
|
+
*
|
|
291
|
+
* Each method maps one-to-one to a chain RPC method, exposed against the EVM
|
|
292
|
+
* JSON-RPC endpoint (`endpoints.evmRpc`). The on-the-wire method names use the
|
|
293
|
+
* chain's exact casing (e.g. `qor_getPQCKeyStatus`, `qor_getAIStats`) and must
|
|
294
|
+
* not be altered.
|
|
295
|
+
*
|
|
296
|
+
* Results are intentionally returned as generics defaulting to
|
|
297
|
+
* {@link Record}<string, unknown>: the chain returns rich, evolving JSON and the
|
|
298
|
+
* SDK does not model every field. Callers pass a concrete type argument when
|
|
299
|
+
* they know the shape.
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
/** Convenience default for unmodeled `qor_*` responses. */
|
|
303
|
+
type Json = Record<string, unknown>;
|
|
304
|
+
/**
|
|
305
|
+
* Client for the QoreChain `qor_*` JSON-RPC namespace.
|
|
306
|
+
*
|
|
307
|
+
* Built on {@link JsonRpcClient}; point it at the network's `evmRpc` endpoint.
|
|
308
|
+
*/
|
|
309
|
+
declare class QorClient extends JsonRpcClient {
|
|
310
|
+
constructor(url: string, opts?: JsonRpcClientOptions);
|
|
311
|
+
/** `qor_getPQCKeyStatus` — PQC key registration status for an address. */
|
|
312
|
+
getPqcKeyStatus<T = Json>(address: string): Promise<T>;
|
|
313
|
+
/** `qor_getHybridSignatureMode` — active hybrid-signature policy. */
|
|
314
|
+
getHybridSignatureMode<T = Json>(): Promise<T>;
|
|
315
|
+
/** `qor_getAIStats` — QCAI engine statistics. */
|
|
316
|
+
getAiStats<T = Json>(): Promise<T>;
|
|
317
|
+
/** `qor_getCrossVMMessage` — a cross-VM message by id. */
|
|
318
|
+
getCrossVmMessage<T = Json>(messageId: string): Promise<T>;
|
|
319
|
+
/** `qor_getReputationScore` — reputation score for a validator. */
|
|
320
|
+
getReputationScore<T = Json>(validator: string): Promise<T>;
|
|
321
|
+
/** `qor_getLayerInfo` — info about a chain layer. */
|
|
322
|
+
getLayerInfo<T = Json>(layerId: string): Promise<T>;
|
|
323
|
+
/** `qor_getBridgeStatus` — bridge status for a remote chain id. */
|
|
324
|
+
getBridgeStatus<T = Json>(chainId: string): Promise<T>;
|
|
325
|
+
/** `qor_getRLAgentStatus` — reinforcement-learning agent status. */
|
|
326
|
+
getRlAgentStatus<T = Json>(): Promise<T>;
|
|
327
|
+
/** `qor_getRLObservation` — latest RL observation vector. */
|
|
328
|
+
getRlObservation<T = Json>(): Promise<T>;
|
|
329
|
+
/** `qor_getRLReward` — latest RL reward signal. */
|
|
330
|
+
getRlReward<T = Json>(): Promise<T>;
|
|
331
|
+
/** `qor_getPoolClassification` — validator pool classification. */
|
|
332
|
+
getPoolClassification<T = Json>(validator: string): Promise<T>;
|
|
333
|
+
/** `qor_getBurnStats` — token burn statistics. */
|
|
334
|
+
getBurnStats<T = Json>(): Promise<T>;
|
|
335
|
+
/** `qor_getXQOREPosition` — xQORE staking position for an address. */
|
|
336
|
+
getXqorePosition<T = Json>(address: string): Promise<T>;
|
|
337
|
+
/** `qor_getInflationRate` — current inflation rate. */
|
|
338
|
+
getInflationRate<T = Json>(): Promise<T>;
|
|
339
|
+
/** `qor_getTokenomicsOverview` — aggregate tokenomics snapshot. */
|
|
340
|
+
getTokenomicsOverview<T = Json>(): Promise<T>;
|
|
341
|
+
/** `qor_getRollupStatus` — status of a rollup. */
|
|
342
|
+
getRollupStatus<T = Json>(rollupId: string): Promise<T>;
|
|
343
|
+
/** `qor_listRollups` — all known rollups. */
|
|
344
|
+
listRollups<T = Json>(): Promise<T>;
|
|
345
|
+
/** `qor_getSettlementBatch` — a settlement batch by rollup and index. */
|
|
346
|
+
getSettlementBatch<T = Json>(rollupId: string, batchIndex: number): Promise<T>;
|
|
347
|
+
/** `qor_suggestRollupProfile` — a suggested rollup profile for a use case. */
|
|
348
|
+
suggestRollupProfile<T = Json>(useCase: string): Promise<T>;
|
|
349
|
+
/** `qor_getDABlobStatus` — data-availability blob status by rollup and index. */
|
|
350
|
+
getDaBlobStatus<T = Json>(rollupId: string, blobIndex: number): Promise<T>;
|
|
351
|
+
/** `qor_getBTCStakingPosition` — BTC staking position for an address. */
|
|
352
|
+
getBtcStakingPosition<T = Json>(address: string): Promise<T>;
|
|
353
|
+
/** `qor_getAbstractAccount` — account-abstraction record for an address. */
|
|
354
|
+
getAbstractAccount<T = Json>(address: string): Promise<T>;
|
|
355
|
+
/** `qor_getFairBlockStatus` — fair-ordering / fair-block status. */
|
|
356
|
+
getFairBlockStatus<T = Json>(): Promise<T>;
|
|
357
|
+
/** `qor_getGasAbstractionConfig` — gas-abstraction configuration. */
|
|
358
|
+
getGasAbstractionConfig<T = Json>(): Promise<T>;
|
|
359
|
+
/** `qor_getLaneConfiguration` — mempool lane configuration. */
|
|
360
|
+
getLaneConfiguration<T = Json>(): Promise<T>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Native-transaction fee estimation for QoreChain.
|
|
365
|
+
*
|
|
366
|
+
* QoreChain exposes an AI-assisted fee oracle at the REST route
|
|
367
|
+
* `/qorechain/ai/v1/fee-estimate?urgency=fast|normal|slow` (see the core
|
|
368
|
+
* `AI_ENGINE.md` / `API_REFERENCE.md`). {@link estimateFee} queries it via the
|
|
369
|
+
* shared {@link RestClient} and shapes the answer as a Cosmos `StdFee`
|
|
370
|
+
* (`{ amount: Coin[]; gas: string }`).
|
|
371
|
+
*
|
|
372
|
+
* The oracle can be unavailable (node still syncing, sidecar down, custom RPC
|
|
373
|
+
* without the AI module). To keep transaction building robust, this falls back
|
|
374
|
+
* to a deterministic static fee computed from a configurable gas price in the
|
|
375
|
+
* base denom — `ceil(gas * gasPrice)` — exactly as a wallet would compute a
|
|
376
|
+
* minimum-gas-price fee. The fallback is transparent and never throws on a
|
|
377
|
+
* missing/erroring endpoint; only a successful response is preferred.
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Default static-fallback parameters, used when the AI fee oracle is
|
|
382
|
+
* unavailable. The gas price (`uqor` per unit of gas) is intentionally
|
|
383
|
+
* conservative and matches the relayer default in the core repo
|
|
384
|
+
* (`gas_price = 0.025 uqor`).
|
|
385
|
+
*/
|
|
386
|
+
declare const STATIC_FALLBACK: {
|
|
387
|
+
/** Fallback gas price, in base denom per unit of gas. */
|
|
388
|
+
readonly gasPrice: "0.025";
|
|
389
|
+
/** Base denomination fees are paid in. */
|
|
390
|
+
readonly denom: "uqor";
|
|
391
|
+
/** Default gas limit when the caller does not supply one. */
|
|
392
|
+
readonly gas: "200000";
|
|
393
|
+
};
|
|
394
|
+
/** Options for {@link estimateFee}. */
|
|
395
|
+
interface EstimateFeeOptions {
|
|
396
|
+
/** Relative urgency tier passed to the oracle. Defaults to `"normal"`. */
|
|
397
|
+
urgency?: FeeUrgency;
|
|
398
|
+
/**
|
|
399
|
+
* Gas limit to request, as a number or decimal string. Defaults to
|
|
400
|
+
* {@link STATIC_FALLBACK.gas}. The oracle only suggests a *fee amount*; the
|
|
401
|
+
* gas limit is chosen by the caller (or via {@link TxClient.simulate}).
|
|
402
|
+
*/
|
|
403
|
+
gas?: number | string;
|
|
404
|
+
/**
|
|
405
|
+
* Static-fallback gas price (base denom per gas unit) used only when the
|
|
406
|
+
* oracle is unavailable. Defaults to {@link STATIC_FALLBACK.gasPrice}.
|
|
407
|
+
*/
|
|
408
|
+
fallbackGasPrice?: string;
|
|
409
|
+
/** Base denomination for the fee. Defaults to {@link STATIC_FALLBACK.denom}. */
|
|
410
|
+
denom?: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Estimate a transaction fee for the given urgency.
|
|
414
|
+
*
|
|
415
|
+
* Queries the QoreChain AI fee oracle and returns a Cosmos `StdFee`. If the
|
|
416
|
+
* oracle is unavailable or returns no usable fee, falls back to a deterministic
|
|
417
|
+
* static fee computed from {@link EstimateFeeOptions.fallbackGasPrice}.
|
|
418
|
+
*
|
|
419
|
+
* @param rest - A {@link RestClient} bound to the network's REST endpoint.
|
|
420
|
+
* @param opts - Urgency, gas limit, and static-fallback parameters.
|
|
421
|
+
*/
|
|
422
|
+
declare function estimateFee(rest: RestClient, opts?: EstimateFeeOptions): Promise<StdFee>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Broadcast-mode definitions and the broadcast result shape for native txs.
|
|
426
|
+
*
|
|
427
|
+
* Cosmos nodes accept transactions in three modes:
|
|
428
|
+
* - `sync` — return after `CheckTx` (mempool admission); you get a tx hash but
|
|
429
|
+
* not an on-chain result.
|
|
430
|
+
* - `async` — return immediately after submission, without waiting for
|
|
431
|
+
* `CheckTx`; fire-and-forget.
|
|
432
|
+
* - `commit` — wait until the tx is included in a block; you get the full
|
|
433
|
+
* delivery result (height, gas used, events). This is the default and is what
|
|
434
|
+
* cosmjs's `signAndBroadcast` does.
|
|
435
|
+
*
|
|
436
|
+
* cosmjs surfaces only two transport methods: `signAndBroadcast` (poll-to-commit)
|
|
437
|
+
* and `signAndBroadcastSync` (return after `CheckTx`). We map `sync` and `async`
|
|
438
|
+
* onto `signAndBroadcastSync` (both return after submission without polling for a
|
|
439
|
+
* block) and `commit` onto `signAndBroadcast`.
|
|
440
|
+
*/
|
|
441
|
+
/** Broadcast mode for a signed transaction. */
|
|
442
|
+
type BroadcastMode = "sync" | "async" | "commit";
|
|
443
|
+
/**
|
|
444
|
+
* The normalized result of broadcasting a transaction.
|
|
445
|
+
*
|
|
446
|
+
* For `commit` mode all fields are populated from the delivery result. For
|
|
447
|
+
* `sync`/`async` mode only `transactionHash` (and `code = 0`) is known, since
|
|
448
|
+
* the tx has not yet been included in a block.
|
|
449
|
+
*/
|
|
450
|
+
interface BroadcastResult {
|
|
451
|
+
/** The transaction hash (uppercase hex). */
|
|
452
|
+
transactionHash: string;
|
|
453
|
+
/**
|
|
454
|
+
* The ABCI result code. `0` means success. For `sync`/`async` this is `0`
|
|
455
|
+
* once the tx is accepted into the mempool (a non-zero `CheckTx` code throws).
|
|
456
|
+
*/
|
|
457
|
+
code: number;
|
|
458
|
+
/** Block height the tx was included in (only for `commit`). */
|
|
459
|
+
height?: number;
|
|
460
|
+
/** Gas used by the tx (only for `commit`). */
|
|
461
|
+
gasUsed?: bigint;
|
|
462
|
+
/** Gas wanted by the tx (only for `commit`). */
|
|
463
|
+
gasWanted?: bigint;
|
|
464
|
+
/** Raw ABCI log, when present. */
|
|
465
|
+
rawLog?: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Native transaction builder and broadcaster for QoreChain.
|
|
470
|
+
*
|
|
471
|
+
* {@link TxClient} wraps cosmjs's `SigningStargateClient` to simulate, sign, and
|
|
472
|
+
* broadcast native (Cosmos SDK) transactions, with a `bankSend` convenience for
|
|
473
|
+
* the common transfer case. It is constructed in two ways:
|
|
474
|
+
*
|
|
475
|
+
* - {@link TxClient.connect} — the production path: connect to the network's
|
|
476
|
+
* consensus RPC with an offline signer (see {@link directSignerFromPrivateKey})
|
|
477
|
+
* and an optional custom message {@link Registry}.
|
|
478
|
+
* - `new TxClient({ signingClient, senderAddress })` — the testable path: inject
|
|
479
|
+
* any object satisfying {@link SigningClientLike}, so unit tests never touch
|
|
480
|
+
* the network.
|
|
481
|
+
*
|
|
482
|
+
* Custom QoreChain module messages are out of scope for v0.1 codegen; instead,
|
|
483
|
+
* callers may register their own protobuf types by passing `registryTypes` to
|
|
484
|
+
* {@link TxClient.connect} (added to cosmjs's default bank/staking/gov/etc.
|
|
485
|
+
* registry), then build `{ typeUrl, value }` messages for them.
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
/** The `/cosmos.bank.v1beta1.MsgSend` type URL. */
|
|
489
|
+
declare const MSG_SEND_TYPE_URL = "/cosmos.bank.v1beta1.MsgSend";
|
|
490
|
+
/**
|
|
491
|
+
* The subset of `SigningStargateClient` that {@link TxClient} depends on.
|
|
492
|
+
* Declaring it explicitly lets unit tests inject a lightweight fake.
|
|
493
|
+
*/
|
|
494
|
+
interface SigningClientLike {
|
|
495
|
+
simulate(signerAddress: string, messages: readonly EncodeObject[], memo: string | undefined): Promise<number>;
|
|
496
|
+
signAndBroadcast(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo?: string): Promise<DeliverTxResponse>;
|
|
497
|
+
signAndBroadcastSync(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo?: string): Promise<string>;
|
|
498
|
+
disconnect?(): void;
|
|
499
|
+
}
|
|
500
|
+
/** Options for constructing a {@link TxClient} directly (testing/advanced). */
|
|
501
|
+
interface TxClientOptions {
|
|
502
|
+
/** The underlying signing client (real or fake). */
|
|
503
|
+
signingClient: SigningClientLike;
|
|
504
|
+
/** The bech32 address transactions are signed and sent from. */
|
|
505
|
+
senderAddress: string;
|
|
506
|
+
}
|
|
507
|
+
/** Options for {@link TxClient.connect}. */
|
|
508
|
+
interface TxConnectOptions {
|
|
509
|
+
/** Consensus RPC endpoint (e.g. `endpoints.rpc`). */
|
|
510
|
+
rpcEndpoint: string;
|
|
511
|
+
/** An offline direct signer (see {@link directSignerFromPrivateKey}). */
|
|
512
|
+
signer: OfflineDirectSigner;
|
|
513
|
+
/**
|
|
514
|
+
* Extra protobuf message types to register, as `[typeUrl, GeneratedType]`
|
|
515
|
+
* pairs. Added to cosmjs's default registry (bank/staking/gov/distribution/…).
|
|
516
|
+
* Use this to support custom QoreChain module messages without bundling full
|
|
517
|
+
* codegen into the SDK.
|
|
518
|
+
*/
|
|
519
|
+
registryTypes?: ReadonlyArray<[string, GeneratedType]>;
|
|
520
|
+
/** Additional cosmjs `SigningStargateClientOptions` (gas price, etc.). */
|
|
521
|
+
clientOptions?: SigningStargateClientOptions;
|
|
522
|
+
}
|
|
523
|
+
/** Options accepted when signing and broadcasting. */
|
|
524
|
+
interface SignAndBroadcastOptions {
|
|
525
|
+
/** Broadcast mode. Defaults to `"commit"`. */
|
|
526
|
+
mode?: BroadcastMode;
|
|
527
|
+
}
|
|
528
|
+
/** Options for {@link TxClient.simulate}. */
|
|
529
|
+
interface SimulateOptions {
|
|
530
|
+
/** Optional tx memo to include in the simulation. */
|
|
531
|
+
memo?: string;
|
|
532
|
+
}
|
|
533
|
+
/** Options for {@link TxClient.bankSend}. */
|
|
534
|
+
interface BankSendOptions extends SignAndBroadcastOptions {
|
|
535
|
+
/** The fee to pay. Required (estimate via `estimateFee`). */
|
|
536
|
+
fee: StdFee;
|
|
537
|
+
/** Optional memo. */
|
|
538
|
+
memo?: string;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* A native-transaction client: simulate, sign, broadcast, and send tokens.
|
|
542
|
+
*/
|
|
543
|
+
declare class TxClient {
|
|
544
|
+
private readonly client;
|
|
545
|
+
/** The signing/sending bech32 address. */
|
|
546
|
+
readonly senderAddress: string;
|
|
547
|
+
constructor(opts: TxClientOptions);
|
|
548
|
+
/**
|
|
549
|
+
* Connect to a network's consensus RPC and build a {@link TxClient}.
|
|
550
|
+
*
|
|
551
|
+
* Resolves the signer's first account as the sender address and merges any
|
|
552
|
+
* `registryTypes` into cosmjs's default message registry.
|
|
553
|
+
*/
|
|
554
|
+
static connect(opts: TxConnectOptions): Promise<TxClient>;
|
|
555
|
+
/**
|
|
556
|
+
* Simulate the given messages and return the estimated gas units.
|
|
557
|
+
*
|
|
558
|
+
* Use the result (with a safety multiplier) as the `gas` for `estimateFee`.
|
|
559
|
+
*/
|
|
560
|
+
simulate(messages: readonly EncodeObject[], opts?: SimulateOptions): Promise<number>;
|
|
561
|
+
/**
|
|
562
|
+
* Sign and broadcast the given messages with an explicit fee.
|
|
563
|
+
*
|
|
564
|
+
* Broadcast mode maps onto cosmjs transports:
|
|
565
|
+
* - `commit` (default): polls until the tx lands in a block; returns the full
|
|
566
|
+
* result and throws on a non-zero delivery code.
|
|
567
|
+
* - `sync` / `async`: returns after mempool submission with just the tx hash.
|
|
568
|
+
*/
|
|
569
|
+
signAndBroadcast(messages: readonly EncodeObject[], fee: StdFee, memo?: string, opts?: SignAndBroadcastOptions): Promise<BroadcastResult>;
|
|
570
|
+
/**
|
|
571
|
+
* Send `amount` to `toAddress` via a bank `MsgSend`, then broadcast.
|
|
572
|
+
*
|
|
573
|
+
* Constructs `/cosmos.bank.v1beta1.MsgSend` from this client's sender address.
|
|
574
|
+
*/
|
|
575
|
+
bankSend(toAddress: string, amount: Coin[], opts: BankSendOptions): Promise<BroadcastResult>;
|
|
576
|
+
/** Disconnect the underlying client's transport, if it supports it. */
|
|
577
|
+
disconnect(): void;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Cross-VM read helpers for QoreChain's `x/crossvm` module.
|
|
582
|
+
*
|
|
583
|
+
* These are thin, typed wrappers over {@link RestClient} for the module's REST
|
|
584
|
+
* routes under `/qorechain/crossvm/v1/...`. They are standalone functions taking
|
|
585
|
+
* a {@link RestClient} so they compose with the existing read surface without
|
|
586
|
+
* widening the `RestClient` class itself.
|
|
587
|
+
*
|
|
588
|
+
* Responses are returned as generics defaulting to small interfaces / {@link
|
|
589
|
+
* Record}<string, unknown>: the module returns rich, evolving JSON and the SDK
|
|
590
|
+
* does not model every field.
|
|
591
|
+
*
|
|
592
|
+
* Note on direction: these helpers READ cross-VM message state. The actual
|
|
593
|
+
* EVM→native routing — e.g. an EVM contract triggering a native AMM swap — is
|
|
594
|
+
* performed on-chain via the cross-VM bridge precompile exposed in the
|
|
595
|
+
* `@qorechain/evm` package (not duplicated here). Once a message is in flight,
|
|
596
|
+
* track its status either through these REST reads or via the
|
|
597
|
+
* `qor_getCrossVMMessage` JSON-RPC method already wrapped on `QorClient`.
|
|
598
|
+
*/
|
|
599
|
+
|
|
600
|
+
/** A single cross-VM message record (unmodeled fields surface as-is). */
|
|
601
|
+
interface CrossVmMessage {
|
|
602
|
+
[key: string]: unknown;
|
|
603
|
+
}
|
|
604
|
+
/** Response of the single-message-by-id route. */
|
|
605
|
+
interface CrossVmMessageResponse {
|
|
606
|
+
message?: CrossVmMessage;
|
|
607
|
+
[key: string]: unknown;
|
|
608
|
+
}
|
|
609
|
+
/** Response of the pending-messages route. */
|
|
610
|
+
interface PendingCrossVmMessagesResponse {
|
|
611
|
+
messages?: CrossVmMessage[];
|
|
612
|
+
[key: string]: unknown;
|
|
613
|
+
}
|
|
614
|
+
/** Response of the module params route. */
|
|
615
|
+
interface CrossVmParamsResponse {
|
|
616
|
+
params?: Record<string, unknown>;
|
|
617
|
+
[key: string]: unknown;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Fetch a cross-VM message by id.
|
|
621
|
+
*
|
|
622
|
+
* GET `/qorechain/crossvm/v1/message/{id}`.
|
|
623
|
+
*/
|
|
624
|
+
declare function getCrossVmMessage<T = CrossVmMessageResponse>(rest: RestClient, id: string): Promise<T>;
|
|
625
|
+
/**
|
|
626
|
+
* Fetch all currently pending cross-VM messages.
|
|
627
|
+
*
|
|
628
|
+
* GET `/qorechain/crossvm/v1/pending`.
|
|
629
|
+
*/
|
|
630
|
+
declare function getPendingCrossVmMessages<T = PendingCrossVmMessagesResponse>(rest: RestClient): Promise<T>;
|
|
631
|
+
/**
|
|
632
|
+
* Fetch the `x/crossvm` module parameters.
|
|
633
|
+
*
|
|
634
|
+
* GET `/qorechain/crossvm/v1/params`.
|
|
635
|
+
*/
|
|
636
|
+
declare function getCrossVmParams<T = CrossVmParamsResponse>(rest: RestClient): Promise<T>;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Top-level `createClient` factory for the QoreChain SDK.
|
|
640
|
+
*
|
|
641
|
+
* {@link createClient} resolves a {@link NetworkConfig} (applying any endpoint
|
|
642
|
+
* overrides) and composes the read clients ({@link RestClient}, the EVM
|
|
643
|
+
* {@link JsonRpcClient}, and the `qor_` {@link QorClient}) plus a fee-estimate
|
|
644
|
+
* convenience over {@link estimateFee}. Signing is opt-in: call
|
|
645
|
+
* {@link QoreChainClient.connectTx} with an offline signer to get a
|
|
646
|
+
* {@link TxClient}.
|
|
647
|
+
*
|
|
648
|
+
* Network resolution rules:
|
|
649
|
+
* - The default network is `testnet`. Both `testnet` and `mainnet` are live and
|
|
650
|
+
* ship localhost endpoint defaults; pass `endpoints` to point at real
|
|
651
|
+
* hostnames.
|
|
652
|
+
*
|
|
653
|
+
* Read sub-clients are lazy getters: each only needs its own endpoint, so
|
|
654
|
+
* accessing one whose endpoint is missing throws a clear, actionable error
|
|
655
|
+
* naming the missing endpoint rather than failing later with an opaque request.
|
|
656
|
+
*/
|
|
657
|
+
|
|
658
|
+
/** Options for {@link createClient}. */
|
|
659
|
+
interface CreateClientOptions {
|
|
660
|
+
/** Network preset to target. Defaults to `"testnet"`. */
|
|
661
|
+
network?: NetworkName;
|
|
662
|
+
/**
|
|
663
|
+
* Endpoint overrides, merged over the preset's defaults. Both `testnet` and
|
|
664
|
+
* `mainnet` default to localhost; pass real hostnames here to override them.
|
|
665
|
+
*/
|
|
666
|
+
endpoints?: Partial<NetworkEndpoints>;
|
|
667
|
+
/**
|
|
668
|
+
* Chain ID override. Both presets ship a live chain ID, so this is only needed
|
|
669
|
+
* to point at a non-standard chain.
|
|
670
|
+
*/
|
|
671
|
+
chainId?: string;
|
|
672
|
+
/** Injectable `fetch` for the read clients (used by tests). */
|
|
673
|
+
fetch?: FetchLike;
|
|
674
|
+
/**
|
|
675
|
+
* Additional HTTP transport options (timeout, retries, headers) shared by the
|
|
676
|
+
* read clients.
|
|
677
|
+
*/
|
|
678
|
+
http?: Omit<HttpOptions, "fetch">;
|
|
679
|
+
}
|
|
680
|
+
/** Options for {@link QoreChainClient.connectTx}. */
|
|
681
|
+
interface ConnectTxOptions {
|
|
682
|
+
/**
|
|
683
|
+
* Extra protobuf message types to register, as `[typeUrl, GeneratedType]`
|
|
684
|
+
* pairs (forwarded to {@link TxClient.connect}).
|
|
685
|
+
*/
|
|
686
|
+
registryTypes?: ReadonlyArray<[string, GeneratedType]>;
|
|
687
|
+
}
|
|
688
|
+
/** Fee convenience surface exposed by {@link QoreChainClient}. */
|
|
689
|
+
interface ClientFees {
|
|
690
|
+
/**
|
|
691
|
+
* Estimate a fee for the given urgency via the AI fee oracle (with a static
|
|
692
|
+
* fallback). See {@link estimateFee}.
|
|
693
|
+
*/
|
|
694
|
+
estimate(urgency?: FeeUrgency): Promise<StdFee>;
|
|
695
|
+
}
|
|
696
|
+
/** Cross-VM read convenience surface, bound to the client's REST endpoint. */
|
|
697
|
+
interface ClientCrossVm {
|
|
698
|
+
/** A cross-VM message by id (`/qorechain/crossvm/v1/message/{id}`). */
|
|
699
|
+
message(id: string): Promise<CrossVmMessageResponse>;
|
|
700
|
+
/** Currently pending cross-VM messages (`/qorechain/crossvm/v1/pending`). */
|
|
701
|
+
pending(): Promise<PendingCrossVmMessagesResponse>;
|
|
702
|
+
/** Cross-VM module params (`/qorechain/crossvm/v1/params`). */
|
|
703
|
+
params(): Promise<CrossVmParamsResponse>;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* A composed QoreChain client: resolved config, read clients, fee helper, and a
|
|
707
|
+
* lazy signing entrypoint.
|
|
708
|
+
*/
|
|
709
|
+
interface QoreChainClient {
|
|
710
|
+
/** The resolved network config (with any endpoint/chain-id overrides applied). */
|
|
711
|
+
readonly network: NetworkConfig;
|
|
712
|
+
/** Cosmos + QoreChain REST read client (uses `endpoints.rest`). */
|
|
713
|
+
readonly rest: RestClient;
|
|
714
|
+
/** EVM JSON-RPC client (uses `endpoints.evmRpc`). */
|
|
715
|
+
readonly evm: JsonRpcClient;
|
|
716
|
+
/** QoreChain `qor_` namespace client (uses `endpoints.evmRpc`). */
|
|
717
|
+
readonly qor: QorClient;
|
|
718
|
+
/** Fee-estimate convenience over the REST client. */
|
|
719
|
+
readonly fees: ClientFees;
|
|
720
|
+
/** Cross-VM read helpers over the REST client. */
|
|
721
|
+
readonly crossvm: ClientCrossVm;
|
|
722
|
+
/**
|
|
723
|
+
* Connect a read-only CosmWasm client at `endpoints.rpc`.
|
|
724
|
+
*
|
|
725
|
+
* Async (the cosmjs client opens an RPC connection on connect), so this is a
|
|
726
|
+
* method rather than a lazy getter; the result is memoized across calls.
|
|
727
|
+
*/
|
|
728
|
+
cosmwasm(): Promise<CosmWasmClient>;
|
|
729
|
+
/**
|
|
730
|
+
* Connect a signer and return a {@link TxClient} bound to `endpoints.rpc`.
|
|
731
|
+
* The heavy lifting lives in {@link TxClient.connect}.
|
|
732
|
+
*/
|
|
733
|
+
connectTx(signer: OfflineDirectSigner, opts?: ConnectTxOptions): Promise<TxClient>;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Create a composed {@link QoreChainClient}.
|
|
737
|
+
*
|
|
738
|
+
* @param opts - Network selection, endpoint overrides, and transport options.
|
|
739
|
+
*/
|
|
740
|
+
declare function createClient(opts?: CreateClientOptions): QoreChainClient;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Conversion between human display amounts (e.g. `"1.5"` QOR) and integer base
|
|
744
|
+
* amounts (e.g. `"1500000"` uqor).
|
|
745
|
+
*
|
|
746
|
+
* All value math is performed with {@link BigInt} on decimal strings — there is
|
|
747
|
+
* no floating-point arithmetic anywhere in this module, so conversions are exact
|
|
748
|
+
* for any magnitude and never drift (e.g. `toBase("0.1")` is exactly
|
|
749
|
+
* `"100000"`).
|
|
750
|
+
*
|
|
751
|
+
* QoreChain's staking coin uses a default exponent of `6` (1 QOR = 10^6 uqor),
|
|
752
|
+
* but every function accepts a custom `exponent` for other denominations.
|
|
753
|
+
*/
|
|
754
|
+
/** Options shared by the denom conversion helpers. */
|
|
755
|
+
interface DenomOptions {
|
|
756
|
+
/** Decimal exponent relating base to display (1 display = 10^exponent base). Defaults to 6. */
|
|
757
|
+
exponent?: number;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Convert a human display amount to its integer base amount string.
|
|
761
|
+
*
|
|
762
|
+
* @param amount - A non-negative decimal string, e.g. `"1.5"`. Surrounding
|
|
763
|
+
* whitespace and a single leading `+` are tolerated. Scientific notation,
|
|
764
|
+
* thousands separators, and other formatting are rejected.
|
|
765
|
+
* @param opts - Optional `exponent` (defaults to 6).
|
|
766
|
+
* @returns The integer base amount as a string with no leading zeros, e.g.
|
|
767
|
+
* `"1500000"`.
|
|
768
|
+
* @throws If `amount` is not a valid decimal string, is negative, or has more
|
|
769
|
+
* fractional digits than `exponent` allows.
|
|
770
|
+
*/
|
|
771
|
+
declare function toBase(amount: string, opts?: DenomOptions): string;
|
|
772
|
+
/**
|
|
773
|
+
* Convert an integer base amount string to a normalized display string.
|
|
774
|
+
*
|
|
775
|
+
* @param base - A non-negative integer string, e.g. `"1500000"`.
|
|
776
|
+
* @param opts - Optional `exponent` (defaults to 6).
|
|
777
|
+
* @returns The display amount with no trailing zeros and no trailing dot, e.g.
|
|
778
|
+
* `"1.5"`. `"1000000"` becomes `"1"`, `"1"` becomes `"0.000001"`, `"0"`
|
|
779
|
+
* becomes `"0"`.
|
|
780
|
+
* @throws If `base` is not a valid non-negative integer string.
|
|
781
|
+
*/
|
|
782
|
+
declare function fromBase(base: string, opts?: DenomOptions): string;
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Conversion and validation for QoreChain bech32 addresses (e.g. `qor1...`) and
|
|
786
|
+
* their underlying byte payloads expressed as `0x`-prefixed hex.
|
|
787
|
+
*
|
|
788
|
+
* bech32 stores data as 5-bit groups ("words"), so encoding/decoding goes
|
|
789
|
+
* through {@link bech32.toWords}/{@link bech32.fromWords} to convert to and from
|
|
790
|
+
* the 8-bit byte representation that callers work with as hex.
|
|
791
|
+
*/
|
|
792
|
+
/**
|
|
793
|
+
* Decode a bech32 address to a `0x`-prefixed hex string of its byte payload.
|
|
794
|
+
*
|
|
795
|
+
* @param addr - A bech32 address, e.g. `qor1...`.
|
|
796
|
+
* @returns The underlying bytes as lowercase `0x`-prefixed hex.
|
|
797
|
+
* @throws If `addr` is not a valid bech32 string.
|
|
798
|
+
*/
|
|
799
|
+
declare function bech32ToHex(addr: string): string;
|
|
800
|
+
/**
|
|
801
|
+
* Encode raw bytes to a bech32 address with the given prefix.
|
|
802
|
+
*
|
|
803
|
+
* This is the primitive encoder; callers holding a `Uint8Array` payload (e.g.
|
|
804
|
+
* the 20-byte `ripemd160(sha256(pubkey))` account hash) should use this
|
|
805
|
+
* directly rather than round-tripping through hex.
|
|
806
|
+
*
|
|
807
|
+
* @param bytes - The raw byte payload.
|
|
808
|
+
* @param prefix - The bech32 human-readable prefix. Defaults to `"qor"`.
|
|
809
|
+
* @returns The bech32-encoded address, e.g. `qor1...`.
|
|
810
|
+
*/
|
|
811
|
+
declare function bytesToBech32(bytes: Uint8Array, prefix?: string): string;
|
|
812
|
+
/**
|
|
813
|
+
* Encode hex bytes to a bech32 address with the given prefix.
|
|
814
|
+
*
|
|
815
|
+
* @param hex - The byte payload as hex, with or without a `0x` prefix.
|
|
816
|
+
* @param prefix - The bech32 human-readable prefix. Defaults to `"qor"`.
|
|
817
|
+
* @returns The bech32-encoded address, e.g. `qor1...`.
|
|
818
|
+
* @throws If `hex` is not a valid hex string.
|
|
819
|
+
*/
|
|
820
|
+
declare function hexToBech32(hex: string, prefix?: string): string;
|
|
821
|
+
/**
|
|
822
|
+
* Validate a bech32 address, optionally requiring a specific prefix.
|
|
823
|
+
*
|
|
824
|
+
* @param addr - The candidate address string.
|
|
825
|
+
* @param prefix - If given, the decoded prefix must match exactly.
|
|
826
|
+
* @returns `true` if `addr` is a structurally valid bech32 string (correct
|
|
827
|
+
* checksum) and, when `prefix` is supplied, its prefix matches; `false`
|
|
828
|
+
* otherwise. Never throws.
|
|
829
|
+
*/
|
|
830
|
+
declare function isValidBech32(addr: string, prefix?: string): boolean;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Account and key types for the three address schemes QoreChain supports.
|
|
834
|
+
*
|
|
835
|
+
* All three derive from a single BIP-39 mnemonic via separate BIP-44 / SLIP-0010
|
|
836
|
+
* paths, so one seed phrase yields a native QoreChain account, an EVM account,
|
|
837
|
+
* and an SVM account independently.
|
|
838
|
+
*/
|
|
839
|
+
/** The address/key scheme an {@link Account} belongs to. */
|
|
840
|
+
type KeyType = "native" | "evm" | "svm";
|
|
841
|
+
/**
|
|
842
|
+
* A derived account, without secret material.
|
|
843
|
+
*
|
|
844
|
+
* `publicKey` is the compressed 33-byte secp256k1 public key for `native`/`evm`
|
|
845
|
+
* accounts, or the bare 32-byte ed25519 public key for `svm` accounts.
|
|
846
|
+
*/
|
|
847
|
+
interface Account {
|
|
848
|
+
/** Which address scheme this account uses. */
|
|
849
|
+
type: KeyType;
|
|
850
|
+
/**
|
|
851
|
+
* The encoded address:
|
|
852
|
+
* - `native`: bech32 with the `qor` prefix (e.g. `qor1...`)
|
|
853
|
+
* - `evm`: `0x`-prefixed, EIP-55 mixed-case checksummed hex
|
|
854
|
+
* - `svm`: base58-encoded 32-byte ed25519 public key
|
|
855
|
+
*/
|
|
856
|
+
address: string;
|
|
857
|
+
/** Compressed secp256k1 (native/evm) or 32-byte ed25519 (svm) public key. */
|
|
858
|
+
publicKey: Uint8Array;
|
|
859
|
+
}
|
|
860
|
+
/** Options controlling which account in the wallet to derive. */
|
|
861
|
+
interface DerivationOptions {
|
|
862
|
+
/**
|
|
863
|
+
* Zero-based address index, varying the last path segment. Defaults to `0`.
|
|
864
|
+
* - native/evm: `m/44'/{118|60}'/0'/0/{index}`
|
|
865
|
+
* - svm: `m/44'/501'/{index}'/0'`
|
|
866
|
+
*/
|
|
867
|
+
accountIndex?: number;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* A native QoreChain or EVM account including its 32-byte secp256k1 private key.
|
|
871
|
+
* Callers need the private key for signing; it is returned explicitly and never
|
|
872
|
+
* logged by the SDK.
|
|
873
|
+
*/
|
|
874
|
+
interface Secp256k1Account extends Account {
|
|
875
|
+
/** Raw 32-byte secp256k1 private key. Handle as a secret. */
|
|
876
|
+
privateKey: Uint8Array;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* An SVM account including its ed25519 secret key.
|
|
880
|
+
*
|
|
881
|
+
* `secretKey` follows the Solana convention of 64 bytes (`seed32 || pubkey32`),
|
|
882
|
+
* which is what `@solana/web3.js` `Keypair.fromSecretKey` expects. Handle as a
|
|
883
|
+
* secret; it is never logged by the SDK.
|
|
884
|
+
*/
|
|
885
|
+
interface Ed25519Account extends Account {
|
|
886
|
+
/** 64-byte Solana-style secret key (`privateSeed32 || publicKey32`). */
|
|
887
|
+
secretKey: Uint8Array;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Mnemonic generation/validation and hierarchical-deterministic (HD) derivation
|
|
892
|
+
* of QoreChain accounts in all three supported schemes:
|
|
893
|
+
*
|
|
894
|
+
* 1. native — Cosmos-style secp256k1, BIP-44 path `m/44'/118'/0'/0/{index}`,
|
|
895
|
+
* address = bech32(`qor`, ripemd160(sha256(compressedPubkey))).
|
|
896
|
+
* 2. evm — secp256k1, BIP-44 path `m/44'/60'/0'/0/{index}`,
|
|
897
|
+
* address = `0x` + last 20 bytes of keccak256(uncompressedPubkey[1:]),
|
|
898
|
+
* rendered with an EIP-55 mixed-case checksum.
|
|
899
|
+
* 3. svm — ed25519, SLIP-0010 path `m/44'/501'/{index}'/0'` (all hardened,
|
|
900
|
+
* the Solana standard), address = base58(32-byte ed25519 public key).
|
|
901
|
+
*
|
|
902
|
+
* Derivation uses audited primitives: @scure/bip39 (mnemonic + seed), @scure/bip32
|
|
903
|
+
* (secp256k1 HD), micro-key-producer SLIP-0010 (ed25519 HD), @noble/hashes and
|
|
904
|
+
* @noble/curves. Secret material is returned explicitly from the derive functions
|
|
905
|
+
* and is never logged.
|
|
906
|
+
*
|
|
907
|
+
* Dependency note: this module pins @noble/hashes/@noble/curves/@scure/base on
|
|
908
|
+
* the 1.x line, while `micro-key-producer` brings its own 2.x copies of those
|
|
909
|
+
* packages. The two majors are installed side by side intentionally. They never
|
|
910
|
+
* exchange hash or curve instances across the boundary — micro-key-producer is
|
|
911
|
+
* used only as a self-contained SLIP-0010 derivation black box (seed in, ed25519
|
|
912
|
+
* node out), so the duplicate copies are isolated and harmless. Do not force a
|
|
913
|
+
* `pnpm.overrides` that drags micro-key-producer onto a different major; that
|
|
914
|
+
* would risk breaking its internals for no behavioural gain here.
|
|
915
|
+
*/
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Generate a fresh BIP-39 mnemonic.
|
|
919
|
+
*
|
|
920
|
+
* @param strength - Entropy in bits: `128` → 12 words (default), `256` → 24 words.
|
|
921
|
+
* @returns A space-separated English mnemonic phrase.
|
|
922
|
+
*/
|
|
923
|
+
declare function generateMnemonic(strength?: 128 | 256): string;
|
|
924
|
+
/**
|
|
925
|
+
* Validate a BIP-39 mnemonic against the English wordlist and its checksum.
|
|
926
|
+
*
|
|
927
|
+
* @param mnemonic - The candidate phrase.
|
|
928
|
+
* @returns `true` if the phrase is a structurally valid, checksum-correct
|
|
929
|
+
* English BIP-39 mnemonic; `false` otherwise. Never throws.
|
|
930
|
+
*/
|
|
931
|
+
declare function validateMnemonic(mnemonic: string): boolean;
|
|
932
|
+
/**
|
|
933
|
+
* Derive a native QoreChain account (Cosmos-style secp256k1) from a mnemonic.
|
|
934
|
+
*
|
|
935
|
+
* Path: `m/44'/118'/0'/0/{accountIndex}`. The address is the bech32 (`qor`)
|
|
936
|
+
* encoding of `ripemd160(sha256(compressedPublicKey))`.
|
|
937
|
+
*
|
|
938
|
+
* @returns The account including its 32-byte secp256k1 private key.
|
|
939
|
+
*/
|
|
940
|
+
declare function deriveNativeAccount(mnemonic: string, opts?: DerivationOptions): Promise<Secp256k1Account>;
|
|
941
|
+
/**
|
|
942
|
+
* Derive an EVM account from a mnemonic.
|
|
943
|
+
*
|
|
944
|
+
* Path: `m/44'/60'/0'/0/{accountIndex}`. The address is the last 20 bytes of
|
|
945
|
+
* `keccak256(uncompressedPublicKey[1:])`, EIP-55 checksummed.
|
|
946
|
+
*
|
|
947
|
+
* @returns The account including its 32-byte secp256k1 private key.
|
|
948
|
+
*/
|
|
949
|
+
declare function deriveEvmAccount(mnemonic: string, opts?: DerivationOptions): Promise<Secp256k1Account>;
|
|
950
|
+
/**
|
|
951
|
+
* Derive an SVM (Solana-style ed25519) account from a mnemonic.
|
|
952
|
+
*
|
|
953
|
+
* Path: `m/44'/501'/{accountIndex}'/0'` — the conventional Solana derivation,
|
|
954
|
+
* all segments hardened (SLIP-0010 for ed25519 supports hardened keys only).
|
|
955
|
+
* The address is the base58 encoding of the 32-byte ed25519 public key.
|
|
956
|
+
*
|
|
957
|
+
* @returns The account including its 64-byte Solana-style secret key
|
|
958
|
+
* (`privateSeed32 || publicKey32`).
|
|
959
|
+
*/
|
|
960
|
+
declare function deriveSvmAccount(mnemonic: string, opts?: DerivationOptions): Promise<Ed25519Account>;
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* PQC algorithm identifiers, mirroring the chain's `x/pqc` cryptographic-agility
|
|
964
|
+
* framework (core `x/pqc/types/algorithm.go`).
|
|
965
|
+
*
|
|
966
|
+
* These numeric IDs are the on-the-wire values the chain expects in
|
|
967
|
+
* `MsgRegisterPQCKeyV2.algorithm_id` and in the `PQCHybridSignature` TX
|
|
968
|
+
* extension's `algorithm_id` field, so they MUST stay in sync with the core enum.
|
|
969
|
+
*/
|
|
970
|
+
/**
|
|
971
|
+
* Identifies a PQC algorithm. Numeric to match the chain's `uint32 AlgorithmID`.
|
|
972
|
+
* IDs 1–2 are the initial algorithms; 3–255 are reserved for future
|
|
973
|
+
* governance-approved algorithms.
|
|
974
|
+
*/
|
|
975
|
+
type AlgorithmID = number;
|
|
976
|
+
/** Unset / invalid algorithm (core: `AlgorithmUnspecified`). */
|
|
977
|
+
declare const AlgorithmUnspecified: AlgorithmID;
|
|
978
|
+
/** Dilithium-5 = ML-DSA-87, NIST FIPS 204 signatures (core: `AlgorithmDilithium5`). */
|
|
979
|
+
declare const AlgorithmDilithium5: AlgorithmID;
|
|
980
|
+
/** ML-KEM-1024, NIST FIPS 203 key encapsulation (core: `AlgorithmMLKEM1024`). */
|
|
981
|
+
declare const AlgorithmMLKEM1024: AlgorithmID;
|
|
982
|
+
/** Human-readable name for an algorithm ID (matches core `AlgorithmID.String()`). */
|
|
983
|
+
declare function algorithmName(id: AlgorithmID): string;
|
|
984
|
+
/** True if the algorithm is a digital-signature scheme (core `IsSignature`). */
|
|
985
|
+
declare function isSignatureAlgorithm(id: AlgorithmID): boolean;
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Pluggable signer abstraction.
|
|
989
|
+
*
|
|
990
|
+
* QoreChain supports three signature postures, mirroring the chain's `x/pqc`
|
|
991
|
+
* key types (see the core `PQC_INTEGRATION.md`):
|
|
992
|
+
*
|
|
993
|
+
* - `classical` — a single classical signature (secp256k1 / ed25519). Backward
|
|
994
|
+
* compatible; no post-quantum material.
|
|
995
|
+
* - `pqc` — an ML-DSA-87 (Dilithium-5) signature only. Maximum quantum safety.
|
|
996
|
+
* - `hybrid` — a classical signature PLUS an ML-DSA-87 signature carried as a TX
|
|
997
|
+
* extension, so quantum-safe wallets interoperate with classical verification.
|
|
998
|
+
*
|
|
999
|
+
* This module defines only the SIGNING primitives and the shape of their output.
|
|
1000
|
+
* Wiring a {@link SignOutput} into a real transaction (attaching the PQC
|
|
1001
|
+
* extension to the signed body, fees, broadcast) is the tx-builder's job, not
|
|
1002
|
+
* the signer's.
|
|
1003
|
+
*/
|
|
1004
|
+
|
|
1005
|
+
/** Which signature posture a {@link Signer} implements. */
|
|
1006
|
+
type SignatureMode = "classical" | "pqc" | "hybrid";
|
|
1007
|
+
/**
|
|
1008
|
+
* The post-quantum portion of a signature, present for `pqc` and `hybrid` modes.
|
|
1009
|
+
*
|
|
1010
|
+
* Field shapes are chosen so this can be handed straight to
|
|
1011
|
+
* `buildHybridSignatureExtension` to produce the on-chain
|
|
1012
|
+
* `PQCHybridSignature` TX extension.
|
|
1013
|
+
*/
|
|
1014
|
+
interface PqcSignaturePart {
|
|
1015
|
+
/** The PQC signature algorithm. For Dilithium-5 this is {@link AlgorithmID}. */
|
|
1016
|
+
algorithmId: AlgorithmID;
|
|
1017
|
+
/** Raw PQC signature bytes (ML-DSA-87 / Dilithium-5: 4627 bytes). */
|
|
1018
|
+
signature: Uint8Array;
|
|
1019
|
+
/**
|
|
1020
|
+
* The PQC public key, included so the chain can auto-register it on first use.
|
|
1021
|
+
* ML-DSA-87 / Dilithium-5: 2592 bytes.
|
|
1022
|
+
*/
|
|
1023
|
+
publicKey?: Uint8Array;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* The result of signing a message.
|
|
1027
|
+
*
|
|
1028
|
+
* - `classical` mode: only {@link classicalSignature} is set.
|
|
1029
|
+
* - `pqc` mode: only {@link pqc} is set.
|
|
1030
|
+
* - `hybrid` mode: BOTH are set.
|
|
1031
|
+
*/
|
|
1032
|
+
interface SignOutput {
|
|
1033
|
+
/** Classical signature bytes (present for `classical` and `hybrid`). */
|
|
1034
|
+
classicalSignature?: Uint8Array;
|
|
1035
|
+
/** Post-quantum signature part (present for `pqc` and `hybrid`). */
|
|
1036
|
+
pqc?: PqcSignaturePart;
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* A pluggable signer over arbitrary message bytes.
|
|
1040
|
+
*
|
|
1041
|
+
* `sign` is always asynchronous and returns a `Promise<SignOutput>`. Some
|
|
1042
|
+
* signers are inherently async (hardware/remote classical signers) while the
|
|
1043
|
+
* in-process PQC path is synchronous, but the interface normalizes both to a
|
|
1044
|
+
* Promise so callers never have to remember to `await` conditionally.
|
|
1045
|
+
*/
|
|
1046
|
+
interface Signer {
|
|
1047
|
+
/** The signature posture this signer implements. */
|
|
1048
|
+
readonly mode: SignatureMode;
|
|
1049
|
+
/**
|
|
1050
|
+
* The public key that identifies the signing account:
|
|
1051
|
+
* - `classical` / `hybrid`: the classical public key.
|
|
1052
|
+
* - `pqc`: the PQC public key.
|
|
1053
|
+
*/
|
|
1054
|
+
publicKey(): Uint8Array;
|
|
1055
|
+
/** Sign the given message bytes. Always resolves to a {@link SignOutput}. */
|
|
1056
|
+
sign(message: Uint8Array): Promise<SignOutput>;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Post-quantum (PQC) signing for QoreChain, using ML-DSA-87 (Dilithium-5,
|
|
1061
|
+
* NIST FIPS 204) for digital signatures.
|
|
1062
|
+
*
|
|
1063
|
+
* QoreChain treats PQC as a first-class signature scheme via a hybrid
|
|
1064
|
+
* architecture (see the core `PQC_INTEGRATION.md`): a transaction carries the
|
|
1065
|
+
* usual classical (secp256k1 / ed25519) signature PLUS an ML-DSA-87 signature
|
|
1066
|
+
* attached as a `PQCHybridSignature` TX extension. The chain's ante handler
|
|
1067
|
+
* verifies both, so quantum-safe wallets stay compatible with classical
|
|
1068
|
+
* verification.
|
|
1069
|
+
*
|
|
1070
|
+
* Scope: this module provides the signing PRIMITIVES (keygen / sign / verify),
|
|
1071
|
+
* a pluggable {@link Signer} for the `pqc` and `hybrid` postures, and a builder
|
|
1072
|
+
* for the on-chain hybrid-signature extension OBJECT. It deliberately does NOT
|
|
1073
|
+
* assemble or broadcast transactions — the tx-builder attaches the extension
|
|
1074
|
+
* the {@link buildHybridSignatureExtension} result describes.
|
|
1075
|
+
*
|
|
1076
|
+
* Crypto is delegated entirely to the audited, pure-TS `@noble/post-quantum`
|
|
1077
|
+
* (`ml_dsa87`). No primitives are reimplemented here.
|
|
1078
|
+
*/
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* ML-DSA-87 (Dilithium-5) byte lengths.
|
|
1082
|
+
*
|
|
1083
|
+
* These are fixed by NIST FIPS 204 and match the chain's `x/pqc` constants
|
|
1084
|
+
* exactly. The installed `@noble/post-quantum` `ml_dsa87` does not expose these
|
|
1085
|
+
* as runtime properties, so we encode the standard's values directly; the test
|
|
1086
|
+
* suite asserts that the library actually produces keys/signatures of these
|
|
1087
|
+
* lengths, guarding against any future library drift.
|
|
1088
|
+
*/
|
|
1089
|
+
/** ML-DSA-87 public-key length, in bytes (FIPS 204 / core: 2592). */
|
|
1090
|
+
declare const ML_DSA_87_PUBLIC_KEY_LENGTH = 2592;
|
|
1091
|
+
/** ML-DSA-87 secret-key length, in bytes (FIPS 204 / core: 4896). */
|
|
1092
|
+
declare const ML_DSA_87_SECRET_KEY_LENGTH = 4896;
|
|
1093
|
+
/** ML-DSA-87 signature length, in bytes (FIPS 204 / core: 4627). */
|
|
1094
|
+
declare const ML_DSA_87_SIGNATURE_LENGTH = 4627;
|
|
1095
|
+
/** Length, in bytes, of the deterministic-keygen seed (xi) per FIPS 204. */
|
|
1096
|
+
declare const ML_DSA_87_SEED_LENGTH = 32;
|
|
1097
|
+
/**
|
|
1098
|
+
* The TX-extension type URL for the on-chain `PQCHybridSignature` message
|
|
1099
|
+
* (core: `HybridSigTypeURL`). The tx-builder uses this as the extension's
|
|
1100
|
+
* type URL when packing the object from {@link buildHybridSignatureExtension}.
|
|
1101
|
+
*/
|
|
1102
|
+
declare const HYBRID_SIG_TYPE_URL = "/qorechain.pqc.v1.PQCHybridSignature";
|
|
1103
|
+
/** An ML-DSA-87 (Dilithium-5) keypair. Treat `secretKey` as a secret. */
|
|
1104
|
+
interface PqcKeypair {
|
|
1105
|
+
/** 2592-byte ML-DSA-87 public key. */
|
|
1106
|
+
publicKey: Uint8Array;
|
|
1107
|
+
/** 4896-byte ML-DSA-87 secret key. Handle as a secret; never logged. */
|
|
1108
|
+
secretKey: Uint8Array;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Generate an ML-DSA-87 (Dilithium-5) keypair.
|
|
1112
|
+
*
|
|
1113
|
+
* @param seed Optional 32-byte seed for deterministic keygen (e.g. derived from
|
|
1114
|
+
* a wallet). When omitted, a cryptographically random keypair is produced.
|
|
1115
|
+
* Must be exactly {@link ML_DSA_87_SEED_LENGTH} bytes if provided.
|
|
1116
|
+
*/
|
|
1117
|
+
declare function generatePqcKeypair(seed?: Uint8Array): PqcKeypair;
|
|
1118
|
+
/** Sign a message with an ML-DSA-87 (Dilithium-5) secret key. */
|
|
1119
|
+
declare function pqcSign(secretKey: Uint8Array, message: Uint8Array): Uint8Array;
|
|
1120
|
+
/** Verify an ML-DSA-87 (Dilithium-5) signature over a message. */
|
|
1121
|
+
declare function pqcVerify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* The on-chain `PQCHybridSignature` TX extension, as a plain object whose keys
|
|
1124
|
+
* mirror the core struct's JSON field tags EXACTLY
|
|
1125
|
+
* (`x/pqc/types/hybrid.go`):
|
|
1126
|
+
*
|
|
1127
|
+
* ```go
|
|
1128
|
+
* type PQCHybridSignature struct {
|
|
1129
|
+
* AlgorithmID AlgorithmID `json:"algorithm_id"`
|
|
1130
|
+
* PQCSignature []byte `json:"pqc_signature"`
|
|
1131
|
+
* PQCPublicKey []byte `json:"pqc_public_key,omitempty"`
|
|
1132
|
+
* }
|
|
1133
|
+
* ```
|
|
1134
|
+
*
|
|
1135
|
+
* The tx-builder is responsible for encoding this and attaching it under
|
|
1136
|
+
* {@link HYBRID_SIG_TYPE_URL}.
|
|
1137
|
+
*/
|
|
1138
|
+
interface PQCHybridSignature {
|
|
1139
|
+
/** PQC algorithm ID (core `AlgorithmID`). */
|
|
1140
|
+
algorithm_id: AlgorithmID;
|
|
1141
|
+
/** Raw PQC signature bytes. */
|
|
1142
|
+
pqc_signature: Uint8Array;
|
|
1143
|
+
/** Optional PQC public key for auto-registration on first use. */
|
|
1144
|
+
pqc_public_key?: Uint8Array;
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Build the on-chain `PQCHybridSignature` extension object from a signature.
|
|
1148
|
+
*
|
|
1149
|
+
* Validation mirrors the core `PQCHybridSignature.Validate()`: the algorithm
|
|
1150
|
+
* must be a signature scheme, the signature must be non-empty, and for
|
|
1151
|
+
* Dilithium-5 the signature/public-key lengths are enforced.
|
|
1152
|
+
*
|
|
1153
|
+
* `pqc_public_key` is omitted entirely when no public key is supplied, matching
|
|
1154
|
+
* the `omitempty` JSON tag on the core struct.
|
|
1155
|
+
*/
|
|
1156
|
+
declare function buildHybridSignatureExtension(args: {
|
|
1157
|
+
algorithmId: AlgorithmID;
|
|
1158
|
+
signature: Uint8Array;
|
|
1159
|
+
publicKey?: Uint8Array;
|
|
1160
|
+
}): PQCHybridSignature;
|
|
1161
|
+
/**
|
|
1162
|
+
* A pqc-only {@link Signer}: produces an ML-DSA-87 (Dilithium-5) signature and
|
|
1163
|
+
* no classical signature. Corresponds to the chain's `pqc_only` key type.
|
|
1164
|
+
*/
|
|
1165
|
+
declare class PqcSigner implements Signer {
|
|
1166
|
+
readonly mode: "pqc";
|
|
1167
|
+
private readonly keypair;
|
|
1168
|
+
private readonly algorithmId;
|
|
1169
|
+
constructor(keypair: PqcKeypair, algorithmId?: AlgorithmID);
|
|
1170
|
+
/** The PQC public key (the signing identity in pqc-only mode). */
|
|
1171
|
+
publicKey(): Uint8Array;
|
|
1172
|
+
sign(message: Uint8Array): Promise<SignOutput>;
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* A hybrid {@link Signer}: wraps a classical signer and an ML-DSA-87 keypair,
|
|
1176
|
+
* producing BOTH a classical signature and a PQC signature over the same
|
|
1177
|
+
* message. Corresponds to the chain's `hybrid` key type.
|
|
1178
|
+
*
|
|
1179
|
+
* The account identity is the wrapped classical signer's public key, so a
|
|
1180
|
+
* hybrid account is indistinguishable from a classical one to wallets that do
|
|
1181
|
+
* not understand the PQC extension.
|
|
1182
|
+
*/
|
|
1183
|
+
declare class HybridSigner implements Signer {
|
|
1184
|
+
readonly mode: "hybrid";
|
|
1185
|
+
private readonly classical;
|
|
1186
|
+
private readonly keypair;
|
|
1187
|
+
private readonly algorithmId;
|
|
1188
|
+
/**
|
|
1189
|
+
* @param classical The wrapped classical signer. Must be a `classical`-mode
|
|
1190
|
+
* signer; its `classicalSignature` output is passed through unchanged.
|
|
1191
|
+
* @param keypair The ML-DSA-87 keypair used for the PQC half.
|
|
1192
|
+
* @throws if `classical` is not a `classical`-mode signer.
|
|
1193
|
+
*/
|
|
1194
|
+
constructor(classical: Signer, keypair: PqcKeypair, algorithmId?: AlgorithmID);
|
|
1195
|
+
/** The classical public key — the on-chain account identity. */
|
|
1196
|
+
publicKey(): Uint8Array;
|
|
1197
|
+
sign(message: Uint8Array): Promise<SignOutput>;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* CosmWasm contract interaction for QoreChain.
|
|
1202
|
+
*
|
|
1203
|
+
* This module rounds out the triple-VM surface (native + EVM + SVM + CosmWasm)
|
|
1204
|
+
* with thin, type-safe conveniences over `@cosmjs/cosmwasm-stargate`. It does
|
|
1205
|
+
* NOT reimplement cosmjs: the wrappers forward to a `CosmWasmClient` (reads) or
|
|
1206
|
+
* `SigningCosmWasmClient` (writes) with QoreChain-friendly defaults.
|
|
1207
|
+
*
|
|
1208
|
+
* Two construction helpers ({@link createCosmWasmClient}, {@link
|
|
1209
|
+
* connectCosmWasmSigner}) build the cosmjs clients against a network's `rpc`
|
|
1210
|
+
* endpoint. The wrapper functions, however, accept an already-built client so
|
|
1211
|
+
* they are unit-testable with a stubbed fake — no real connection required.
|
|
1212
|
+
*/
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Arbitrary JSON value accepted/returned by contract calls. Mirrors cosmjs's
|
|
1216
|
+
* `JsonObject` (which is `any`) but keeps our public types honest.
|
|
1217
|
+
*/
|
|
1218
|
+
type ContractMsg = Record<string, unknown>;
|
|
1219
|
+
/** A `StdFee`, or cosmjs's `"auto"` (simulate) / a raw gas multiplier number. */
|
|
1220
|
+
type FeeInput = StdFee | "auto" | number;
|
|
1221
|
+
/**
|
|
1222
|
+
* Read-only slice of `CosmWasmClient` used by the read wrappers. Declaring the
|
|
1223
|
+
* methods we use (rather than importing the concrete class) lets tests inject a
|
|
1224
|
+
* minimal fake.
|
|
1225
|
+
*/
|
|
1226
|
+
interface CosmWasmReadClient {
|
|
1227
|
+
queryContractSmart(address: string, queryMsg: ContractMsg): Promise<unknown>;
|
|
1228
|
+
getContract(address: string): Promise<unknown>;
|
|
1229
|
+
}
|
|
1230
|
+
/** Signing slice of `SigningCosmWasmClient` used by the write wrappers. */
|
|
1231
|
+
interface CosmWasmSigningClient {
|
|
1232
|
+
upload(senderAddress: string, wasmCode: Uint8Array, fee: FeeInput, memo?: string): Promise<unknown>;
|
|
1233
|
+
instantiate(senderAddress: string, codeId: number, msg: ContractMsg, label: string, fee: FeeInput, options?: InstantiateOpts): Promise<unknown>;
|
|
1234
|
+
execute(senderAddress: string, contractAddress: string, msg: ContractMsg, fee: FeeInput, memo?: string, funds?: readonly Coin[]): Promise<unknown>;
|
|
1235
|
+
}
|
|
1236
|
+
/** Options for {@link instantiate}: cosmjs `InstantiateOptions` plus the fee. */
|
|
1237
|
+
interface InstantiateOpts {
|
|
1238
|
+
/** Fee for the instantiate tx. Defaults to `"auto"` (simulate). */
|
|
1239
|
+
fee?: FeeInput;
|
|
1240
|
+
/** Optional memo. */
|
|
1241
|
+
memo?: string;
|
|
1242
|
+
/** Native funds sent to the new contract on instantiation. */
|
|
1243
|
+
funds?: readonly Coin[];
|
|
1244
|
+
/** Optional admin address (can migrate the contract). */
|
|
1245
|
+
admin?: string;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Connect a read-only {@link CosmWasmClient} to a network's RPC endpoint.
|
|
1249
|
+
*
|
|
1250
|
+
* @param rpcUrl - The network's `rpc` endpoint (e.g. `endpoints.rpc`).
|
|
1251
|
+
*/
|
|
1252
|
+
declare function createCosmWasmClient(rpcUrl: string): Promise<CosmWasmClient>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Connect a {@link SigningCosmWasmClient} for contract writes.
|
|
1255
|
+
*
|
|
1256
|
+
* @param rpcUrl - The network's `rpc` endpoint.
|
|
1257
|
+
* @param signer - An offline signer (e.g. from `@cosmjs/proto-signing`).
|
|
1258
|
+
*/
|
|
1259
|
+
declare function connectCosmWasmSigner(rpcUrl: string, signer: OfflineSigner): Promise<SigningCosmWasmClient>;
|
|
1260
|
+
/** Run a contract's smart query (`queryContractSmart`). */
|
|
1261
|
+
declare function queryContractSmart<T = unknown>(client: CosmWasmReadClient, contractAddress: string, queryMsg: ContractMsg): Promise<T>;
|
|
1262
|
+
/** Fetch a contract's on-chain metadata (`getContract`). */
|
|
1263
|
+
declare function getContractInfo<T = unknown>(client: CosmWasmReadClient, contractAddress: string): Promise<T>;
|
|
1264
|
+
/**
|
|
1265
|
+
* Instantiate a contract from an uploaded code id.
|
|
1266
|
+
*
|
|
1267
|
+
* Forwards to `SigningCosmWasmClient.instantiate`, splitting our {@link
|
|
1268
|
+
* InstantiateOpts} into cosmjs's positional `fee` (default `"auto"`) and its
|
|
1269
|
+
* `InstantiateOptions` (`memo`/`funds`/`admin`).
|
|
1270
|
+
*/
|
|
1271
|
+
declare function instantiate<T = unknown>(client: CosmWasmSigningClient, sender: string, codeId: number, initMsg: ContractMsg, label: string, opts?: InstantiateOpts): Promise<T>;
|
|
1272
|
+
/** Execute a message against an instantiated contract. */
|
|
1273
|
+
declare function execute<T = unknown>(client: CosmWasmSigningClient, sender: string, contractAddress: string, msg: ContractMsg, fee: FeeInput, funds?: readonly Coin[]): Promise<T>;
|
|
1274
|
+
/** Upload (store) WASM bytecode, returning the assigned code id in the result. */
|
|
1275
|
+
declare function uploadCode<T = unknown>(client: CosmWasmSigningClient, sender: string, wasmBytes: Uint8Array, fee: FeeInput): Promise<T>;
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Adapter from a native QoreChain secp256k1 key to a cosmjs signer.
|
|
1279
|
+
*
|
|
1280
|
+
* The accounts module (`deriveNativeAccount`, Task 13) yields a raw 32-byte
|
|
1281
|
+
* secp256k1 private key. The transaction layer signs through cosmjs's
|
|
1282
|
+
* `SigningStargateClient`, which expects an `OfflineDirectSigner`. This module
|
|
1283
|
+
* bridges the two via `@cosmjs/proto-signing`'s `DirectSecp256k1Wallet`, binding
|
|
1284
|
+
* the key to the network's bech32 account prefix (`qor`).
|
|
1285
|
+
*
|
|
1286
|
+
* The signer performs SIGN_MODE_DIRECT (protobuf) signing — the native chain's
|
|
1287
|
+
* default — so the produced address and signatures match what the node's ante
|
|
1288
|
+
* handler verifies for a classical secp256k1 account.
|
|
1289
|
+
*/
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Adapt a raw secp256k1 private key into a cosmjs {@link OfflineDirectSigner}.
|
|
1293
|
+
*
|
|
1294
|
+
* @param privateKey - Raw 32-byte secp256k1 private key (e.g. the `privateKey`
|
|
1295
|
+
* field of a {@link Secp256k1Account} from `deriveNativeAccount`).
|
|
1296
|
+
* @param prefix - Bech32 account prefix for the network (QoreChain: `"qor"`).
|
|
1297
|
+
* @returns A direct (protobuf) offline signer whose single account address is
|
|
1298
|
+
* the bech32 encoding of the key under `prefix`.
|
|
1299
|
+
*/
|
|
1300
|
+
declare function directSignerFromPrivateKey(privateKey: Uint8Array, prefix: string): Promise<OfflineDirectSigner>;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Encoding and attachment of the QoreChain PQC hybrid-signature extension to a
|
|
1304
|
+
* native tx.
|
|
1305
|
+
*
|
|
1306
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
1307
|
+
* The wallet ↔ chain contract (now known and enforced)
|
|
1308
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
1309
|
+
* These are low-level encode/attach primitives. The full, contract-correct
|
|
1310
|
+
* hybrid build sequence lives in {@link ../tx/hybrid-tx} ({@link buildHybridTx}
|
|
1311
|
+
* / {@link signAndBroadcastHybrid}) — prefer those for end-to-end signing. This
|
|
1312
|
+
* module documents the on-wire encoding the chain reads:
|
|
1313
|
+
*
|
|
1314
|
+
* - `PQCHybridSignature` struct, JSON field tags (`algorithm_id`,
|
|
1315
|
+
* `pqc_signature`, `pqc_public_key,omitempty`), and type URL
|
|
1316
|
+
* `/qorechain.pqc.v1.PQCHybridSignature`.
|
|
1317
|
+
* - The ante handler extracts the extension by type URL and JSON-decodes it, so
|
|
1318
|
+
* the `Any.value` carries the struct's Go-JSON encoding (Go marshals
|
|
1319
|
+
* `[]byte` as standard padded base64 strings), NOT a protobuf message. This
|
|
1320
|
+
* module encodes accordingly (see {@link toGoJson}).
|
|
1321
|
+
* - PLACEMENT: the extension is a CRITICAL extension option — it goes in
|
|
1322
|
+
* `TxBody.extension_options`. {@link buildHybridTx} always uses this slot.
|
|
1323
|
+
* This module additionally exposes `non_critical_extension_options` via
|
|
1324
|
+
* {@link AttachHybridOptions.placement} for callers with other needs, but the
|
|
1325
|
+
* chain reads the critical slot.
|
|
1326
|
+
* - SIGNED BYTES: the ML-DSA-87 signature is computed over the tx body WITH the
|
|
1327
|
+
* PQC extension REMOVED, framed with the authInfo bytes:
|
|
1328
|
+
* `BE32(len(B0)) || B0 || BE32(len(A)) || A` (see {@link buildHybridTx} for
|
|
1329
|
+
* the full contract). This module does not decide what the PQC signature
|
|
1330
|
+
* signs — {@link buildHybridTx} does.
|
|
1331
|
+
*
|
|
1332
|
+
* Cross-implementation proto byte-determinism (cosmjs encode vs. the chain's
|
|
1333
|
+
* re-marshal) is confirmed on the live testnet for the default registry message
|
|
1334
|
+
* types.
|
|
1335
|
+
*/
|
|
1336
|
+
|
|
1337
|
+
/** Where the hybrid-signature extension is placed within the `TxBody`. */
|
|
1338
|
+
type HybridPlacement = "non_critical_extension_options" | "extension_options";
|
|
1339
|
+
/** Options for {@link attachHybridExtension}. */
|
|
1340
|
+
interface AttachHybridOptions {
|
|
1341
|
+
/**
|
|
1342
|
+
* Which `TxBody` extension list to attach the extension to. Defaults to
|
|
1343
|
+
* `"non_critical_extension_options"`. See the module header: the exact slot
|
|
1344
|
+
* the ante handler reads is not determinable from public core and needs
|
|
1345
|
+
* live-testnet verification.
|
|
1346
|
+
*/
|
|
1347
|
+
placement?: HybridPlacement;
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Encode a {@link PQCHybridSignature} into a protobuf `Any` for use as a
|
|
1351
|
+
* `TxBody` extension option.
|
|
1352
|
+
*
|
|
1353
|
+
* The `Any.typeUrl` is the core {@link HYBRID_SIG_TYPE_URL}; the `Any.value` is
|
|
1354
|
+
* the UTF-8 bytes of the struct's Go-JSON encoding (see {@link toGoJson} and the
|
|
1355
|
+
* module header — the chain reads this extension by type URL + JSON decoding,
|
|
1356
|
+
* not protobuf).
|
|
1357
|
+
*/
|
|
1358
|
+
declare function encodeHybridExtension(ext: PQCHybridSignature): Any;
|
|
1359
|
+
/**
|
|
1360
|
+
* Return a copy of `body` with the encoded hybrid-signature extension attached.
|
|
1361
|
+
*
|
|
1362
|
+
* The input `body` is not mutated. By default the extension is added to
|
|
1363
|
+
* `non_critical_extension_options`; pass `placement` to use `extension_options`
|
|
1364
|
+
* instead.
|
|
1365
|
+
*
|
|
1366
|
+
* @see The module header — both the placement and the bytes the PQC signature
|
|
1367
|
+
* must cover require live-testnet verification against the `full` build.
|
|
1368
|
+
*/
|
|
1369
|
+
declare function attachHybridExtension(body: TxBody, ext: PQCHybridSignature, opts?: AttachHybridOptions): TxBody;
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* End-to-end hybrid (classical + post-quantum) transaction signing for
|
|
1373
|
+
* QoreChain.
|
|
1374
|
+
*
|
|
1375
|
+
* A hybrid transaction carries the usual classical secp256k1 signature in
|
|
1376
|
+
* `TxRaw.signatures` PLUS an ML-DSA-87 (Dilithium-5) signature attached to the
|
|
1377
|
+
* `TxBody` as a `PQCHybridSignature` extension. The chain's ante handler
|
|
1378
|
+
* verifies BOTH, so a hybrid account stays interoperable with classical
|
|
1379
|
+
* verification while gaining quantum safety.
|
|
1380
|
+
*
|
|
1381
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
1382
|
+
* The wallet ↔ chain contract (enforced by the chain)
|
|
1383
|
+
* ──────────────────────────────────────────────────────────────────────────
|
|
1384
|
+
* The chain verifies the ML-DSA-87 signature over the tx body WITH the PQC
|
|
1385
|
+
* extension REMOVED. Concretely:
|
|
1386
|
+
*
|
|
1387
|
+
* - `B0` = canonical protobuf bytes of the `TxBody` containing the
|
|
1388
|
+
* messages/memo/timeoutHeight but NOT the `PQCHybridSignature` extension.
|
|
1389
|
+
* - `A` = the tx `authInfoBytes`, verbatim — the same bytes that are
|
|
1390
|
+
* broadcast.
|
|
1391
|
+
* - PQC signed message = `BE32(len(B0)) || B0 || BE32(len(A)) || A`
|
|
1392
|
+
* (4-byte big-endian length prefixes; NO hashing, NO domain prefix).
|
|
1393
|
+
* - PQC signature = `ml_dsa87.sign(pqcSecretKey, message)` (pure
|
|
1394
|
+
* ML-DSA-87, empty context) — 4627 bytes for Dilithium-5.
|
|
1395
|
+
* - The `PQCHybridSignature` extension is then added to
|
|
1396
|
+
* `TxBody.extension_options` (CRITICAL extension options) as an `Any` with
|
|
1397
|
+
* `type_url = "/qorechain.pqc.v1.PQCHybridSignature"` and `value` = UTF-8
|
|
1398
|
+
* bytes of the Go-JSON `{ "algorithm_id", "pqc_signature", "pqc_public_key"? }`
|
|
1399
|
+
* (standard padded base64; `pqc_public_key` omitted when not provided).
|
|
1400
|
+
* - The CLASSICAL signature is computed normally (SIGN_MODE_DIRECT) over the
|
|
1401
|
+
* FINAL body (the one WITH the PQC extension) + authInfo + chainId +
|
|
1402
|
+
* accountNumber, and goes in `TxRaw.signatures` (outside the body). There is
|
|
1403
|
+
* no self-reference: the classical signature never signs itself.
|
|
1404
|
+
*
|
|
1405
|
+
* The signer's PQC key must be registered on-chain (via `MsgRegisterPQCKey`)
|
|
1406
|
+
* before hybrid txs PQC-verify — unless `includePqcPublicKey` is set, which
|
|
1407
|
+
* embeds the key for auto-registration on first use. Registering the key is the
|
|
1408
|
+
* caller's responsibility.
|
|
1409
|
+
*
|
|
1410
|
+
* Determinism note: the framing above is byte-for-byte deterministic on the
|
|
1411
|
+
* wallet side. Cross-implementation determinism (this `cosmjs`/`cosmjs-types`
|
|
1412
|
+
* proto encoding vs. the chain's re-marshal of the same `TxBody`) is confirmed
|
|
1413
|
+
* against the live testnet; if a custom message type with non-canonical field
|
|
1414
|
+
* ordering were used, callers must ensure their `Registry` encodes canonically.
|
|
1415
|
+
*/
|
|
1416
|
+
|
|
1417
|
+
/** The fields shared by {@link buildHybridTx} and {@link signAndBroadcastHybrid}. */
|
|
1418
|
+
interface BuildHybridTxOptions {
|
|
1419
|
+
/**
|
|
1420
|
+
* The protobuf message {@link Registry} used to encode the messages into the
|
|
1421
|
+
* `TxBody`. Use cosmjs's `defaultRegistryTypes` (plus any custom QoreChain
|
|
1422
|
+
* message types) — the same registry the network's `TxClient` is built with.
|
|
1423
|
+
*/
|
|
1424
|
+
registry: Registry;
|
|
1425
|
+
/**
|
|
1426
|
+
* The classical secp256k1 direct signer (e.g. from
|
|
1427
|
+
* `directSignerFromPrivateKey`). Its first account is used as the signer
|
|
1428
|
+
* identity and to produce the SIGN_MODE_DIRECT classical signature.
|
|
1429
|
+
*/
|
|
1430
|
+
signer: OfflineDirectSigner;
|
|
1431
|
+
/** The ML-DSA-87 (Dilithium-5) keypair providing the post-quantum half. */
|
|
1432
|
+
pqcKeypair: PqcKeypair;
|
|
1433
|
+
/** The transaction messages, as `{ typeUrl, value }` encode objects. */
|
|
1434
|
+
messages: readonly EncodeObject[];
|
|
1435
|
+
/** The fee to pay. */
|
|
1436
|
+
fee: StdFee;
|
|
1437
|
+
/** Optional memo. Defaults to `""`. */
|
|
1438
|
+
memo?: string;
|
|
1439
|
+
/** The chain id (e.g. `"qorechain-diana"`). */
|
|
1440
|
+
chainId: string;
|
|
1441
|
+
/** The on-chain account number of the signer. */
|
|
1442
|
+
accountNumber: number | bigint;
|
|
1443
|
+
/** The signer's current account sequence (nonce). */
|
|
1444
|
+
sequence: number | bigint;
|
|
1445
|
+
/** Optional `timeoutHeight` for the tx body. */
|
|
1446
|
+
timeoutHeight?: bigint;
|
|
1447
|
+
/**
|
|
1448
|
+
* When `true`, embed the 2592-byte ML-DSA-87 public key in the extension so
|
|
1449
|
+
* the chain can auto-register it on first use. Defaults to `false` (the key
|
|
1450
|
+
* is expected to already be registered via `MsgRegisterPQCKey`).
|
|
1451
|
+
*/
|
|
1452
|
+
includePqcPublicKey?: boolean;
|
|
1453
|
+
}
|
|
1454
|
+
/** The fully assembled hybrid transaction and the intermediate artifacts. */
|
|
1455
|
+
interface BuiltHybridTx {
|
|
1456
|
+
/** The assembled `TxRaw` (final body + authInfo + classical signature). */
|
|
1457
|
+
txRaw: TxRaw;
|
|
1458
|
+
/** Encoded `TxRaw` bytes, ready to broadcast. */
|
|
1459
|
+
txRawBytes: Uint8Array;
|
|
1460
|
+
/** The `authInfoBytes` (`A`) — identical in the PQC framing and the SignDoc. */
|
|
1461
|
+
authInfoBytes: Uint8Array;
|
|
1462
|
+
/** The exact bytes the ML-DSA-87 signature was computed over (the framing). */
|
|
1463
|
+
pqcSignedMessage: Uint8Array;
|
|
1464
|
+
/** The raw ML-DSA-87 signature (Dilithium-5: 4627 bytes). */
|
|
1465
|
+
pqcSignature: Uint8Array;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Build a fully signed hybrid transaction following the chain contract.
|
|
1469
|
+
*
|
|
1470
|
+
* The build sequence (see the module header for the exact contract):
|
|
1471
|
+
* 1. Encode `B0` — the `TxBody` WITHOUT the PQC extension.
|
|
1472
|
+
* 2. Encode `A` — the single-signer `AuthInfo` (SIGN_MODE_DIRECT).
|
|
1473
|
+
* 3. Compute `message = BE32(len B0) || B0 || BE32(len A) || A`; ML-DSA-87
|
|
1474
|
+
* sign it.
|
|
1475
|
+
* 4. Build the PQC extension `Any` and attach it to a NEW body identical to
|
|
1476
|
+
* step 1 but with `extensionOptions = [ext]`; encode → final body bytes.
|
|
1477
|
+
* 5. SIGN_MODE_DIRECT classical sign over `SignDoc{ finalBody, A, chainId,
|
|
1478
|
+
* accountNumber }`.
|
|
1479
|
+
* 6. Assemble `TxRaw{ finalBody, A, [classicalSig] }`.
|
|
1480
|
+
*
|
|
1481
|
+
* The returned {@link BuiltHybridTx} exposes the intermediate artifacts so the
|
|
1482
|
+
* contract can be asserted/audited.
|
|
1483
|
+
*/
|
|
1484
|
+
declare function buildHybridTx(opts: BuildHybridTxOptions): Promise<BuiltHybridTx>;
|
|
1485
|
+
/**
|
|
1486
|
+
* A minimal broadcast transport for raw tx bytes. cosmjs's `StargateClient`
|
|
1487
|
+
* (and `SigningStargateClient`) satisfy this shape via `broadcastTx` /
|
|
1488
|
+
* `broadcastTxSync`, so production callers can pass an existing client; unit
|
|
1489
|
+
* tests can inject a fake.
|
|
1490
|
+
*/
|
|
1491
|
+
interface HybridBroadcaster {
|
|
1492
|
+
/** Poll-to-commit broadcast: returns the delivery result. */
|
|
1493
|
+
broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number): Promise<{
|
|
1494
|
+
code: number;
|
|
1495
|
+
transactionHash: string;
|
|
1496
|
+
height?: number;
|
|
1497
|
+
gasUsed?: bigint;
|
|
1498
|
+
gasWanted?: bigint;
|
|
1499
|
+
rawLog?: string;
|
|
1500
|
+
}>;
|
|
1501
|
+
/** Submit and return after CheckTx: returns the tx hash. */
|
|
1502
|
+
broadcastTxSync(tx: Uint8Array): Promise<string>;
|
|
1503
|
+
}
|
|
1504
|
+
/** Options for {@link signAndBroadcastHybrid}. */
|
|
1505
|
+
interface SignAndBroadcastHybridOptions extends BuildHybridTxOptions {
|
|
1506
|
+
/** The broadcast transport (e.g. a connected `StargateClient`). */
|
|
1507
|
+
transport: HybridBroadcaster;
|
|
1508
|
+
/** Broadcast mode. Defaults to `"commit"`. */
|
|
1509
|
+
mode?: BroadcastMode;
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Build, sign, and broadcast a hybrid transaction.
|
|
1513
|
+
*
|
|
1514
|
+
* Broadcast mode maps onto the transport:
|
|
1515
|
+
* - `commit` (default): polls until the tx lands in a block; throws on a
|
|
1516
|
+
* non-zero delivery code.
|
|
1517
|
+
* - `sync` / `async`: returns after mempool submission with just the tx hash.
|
|
1518
|
+
*/
|
|
1519
|
+
declare function signAndBroadcastHybrid(opts: SignAndBroadcastHybridOptions): Promise<BroadcastResult>;
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* `@qorechain/sdk` public API.
|
|
1523
|
+
*
|
|
1524
|
+
* The exports below are the deliberate, supported surface of the SDK. Start with
|
|
1525
|
+
* {@link createClient} for the high-level composed client; the individual
|
|
1526
|
+
* networks, accounts, query clients, and tx primitives are also exported for
|
|
1527
|
+
* callers who want to compose them directly. Internal helpers are not exported.
|
|
1528
|
+
*/
|
|
1529
|
+
/** SDK version. */
|
|
1530
|
+
declare const VERSION = "0.1.0";
|
|
1531
|
+
|
|
1532
|
+
export { type Account, AlgorithmDilithium5, type AlgorithmID, AlgorithmMLKEM1024, AlgorithmUnspecified, type AllBalancesResponse, type AttachHybridOptions, type BalanceResponse, type BankSendOptions, type Bech32Prefixes, type BroadcastMode, type BroadcastResult, type BuildHybridTxOptions, type BuiltHybridTx, type ClientFees, type CoinInfo, type ConnectTxOptions, type ContractMsg, type CosmWasmReadClient, type CosmWasmSigningClient, type CreateClientOptions, type CrossVmMessage, type CrossVmMessageResponse, type CrossVmParamsResponse, type DenomOptions, type DerivationOptions, type Ed25519Account, type EstimateFeeOptions, type FeeInput, type FeeUrgency, type FetchLike, type GetJsonOptions, HYBRID_SIG_TYPE_URL, type HttpOptions, type HybridBroadcaster, type HybridPlacement, HybridSigner, type InstantiateOpts, JsonRpcClient, type JsonRpcClientOptions, JsonRpcError, type JsonRpcErrorObject, type JsonRpcResponse, type KeyType, ML_DSA_87_PUBLIC_KEY_LENGTH, ML_DSA_87_SECRET_KEY_LENGTH, ML_DSA_87_SEED_LENGTH, ML_DSA_87_SIGNATURE_LENGTH, MSG_SEND_TYPE_URL, NETWORKS, type NetworkConfig, type NetworkEndpoints, type NetworkName, type PQCHybridSignature, type PageResponse, type PaginatedOptions, type Pagination, type PendingCrossVmMessagesResponse, type PqcKeypair, type PqcSignaturePart, PqcSigner, QorClient, type QoreChainClient, QoreHttpError, type QueryValue, RestClient, type RestClientOptions, STATIC_FALLBACK, type Secp256k1Account, type SignAndBroadcastHybridOptions, type SignAndBroadcastOptions, type SignOutput, type SignatureMode, type Signer, type SigningClientLike, type SimulateOptions, TxClient, type TxClientOptions, type TxConnectOptions, VERSION, algorithmName, attachHybridExtension, bech32ToHex, buildHybridSignatureExtension, buildHybridTx, buildUrl, bytesToBech32, connectCosmWasmSigner, createClient, createCosmWasmClient, deriveEvmAccount, deriveNativeAccount, deriveSvmAccount, directSignerFromPrivateKey, encodeHybridExtension, estimateFee, execute, fromBase, generateMnemonic, generatePqcKeypair, getContractInfo, getCrossVmMessage, getCrossVmParams, getJson, getNetwork, getPendingCrossVmMessages, hexToBech32, instantiate, isSignatureAlgorithm, isValidBech32, joinUrl, listNetworks, postJsonRpc, pqcSign, pqcVerify, queryContractSmart, signAndBroadcastHybrid, toBase, uploadCode, validateMnemonic };
|