@asentum/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.
@@ -0,0 +1,307 @@
1
+ import { Dilithium3Keypair } from '@asentum/crypto';
2
+
3
+ /**
4
+ * AsentumClient — read-only interface to an Asentum node's RPC.
5
+ *
6
+ * Wraps the node's HTTP endpoints in a typed, Promise-based API.
7
+ * No private keys, no signing — just reads. For sending transactions,
8
+ * use {@link AsentumWallet} which extends the client with a keypair.
9
+ *
10
+ * Works in Node.js (20+) and browsers — only depends on `fetch`.
11
+ */
12
+ interface ChainInfo {
13
+ chainId: string;
14
+ height: number;
15
+ mempoolSize: number;
16
+ latestHeader: BlockHeader;
17
+ }
18
+ interface BlockHeader {
19
+ parentHash: string;
20
+ stateRoot: string;
21
+ transactionsRoot: string;
22
+ receiptsRoot: string;
23
+ number: string;
24
+ timestamp: string;
25
+ gasLimit: string;
26
+ gasUsed: string;
27
+ baseFeePerGas: string;
28
+ proposer: string;
29
+ }
30
+ interface Block {
31
+ header: BlockHeader;
32
+ hash?: string;
33
+ transactions: Transaction[];
34
+ receipts: Receipt[];
35
+ }
36
+ interface Transaction {
37
+ kind: 'transfer' | 'deploy' | 'call';
38
+ body: {
39
+ chainId: string;
40
+ nonce: string;
41
+ maxPriorityFeePerGas: string;
42
+ maxFeePerGas: string;
43
+ gasLimit: string;
44
+ to: string;
45
+ value: string;
46
+ dataSize: number;
47
+ };
48
+ call?: {
49
+ method: string;
50
+ args: unknown[];
51
+ };
52
+ }
53
+ interface Receipt {
54
+ txHash: string;
55
+ blockNumber: string;
56
+ txIndex: number;
57
+ sender: string;
58
+ recipient: string;
59
+ kind: string;
60
+ success: boolean;
61
+ gasUsed: string;
62
+ events: Array<{
63
+ name: string;
64
+ data: unknown;
65
+ }>;
66
+ returnValue?: unknown;
67
+ }
68
+ interface Balance {
69
+ address: string;
70
+ balance: string;
71
+ nonce: string;
72
+ }
73
+ interface ValidatorInfo {
74
+ address: string;
75
+ stake: string;
76
+ bondedAt: string;
77
+ pubKeySize: number;
78
+ }
79
+ interface ViewCallResult {
80
+ ok: boolean;
81
+ reason?: string;
82
+ returnValue?: unknown;
83
+ gasUsed?: string;
84
+ events?: Array<{
85
+ name: string;
86
+ data: unknown;
87
+ }>;
88
+ }
89
+ interface TxResult {
90
+ accepted: boolean;
91
+ reason?: string;
92
+ txHash?: string;
93
+ }
94
+ interface Metadata {
95
+ chainId: string;
96
+ chainName: string;
97
+ chainIdDecimal: string;
98
+ currentBlock: string;
99
+ nativeCurrency: {
100
+ name: string;
101
+ symbol: string;
102
+ decimals: number;
103
+ };
104
+ rpcUrls: string[];
105
+ blockExplorerUrls: string[];
106
+ faucetUrl: string;
107
+ }
108
+ declare class AsentumClient {
109
+ readonly rpcUrl: string;
110
+ constructor(rpcUrl: string);
111
+ /** Get chain info including the latest block header. */
112
+ getChainInfo(): Promise<ChainInfo>;
113
+ /** Get the current block height. */
114
+ getBlockNumber(): Promise<number>;
115
+ /** Get the chain ID as a bigint. */
116
+ getChainId(): Promise<bigint>;
117
+ /** Get a block by number, including transactions and receipts. */
118
+ getBlock(number: number | bigint): Promise<Block | null>;
119
+ /** Get the balance and nonce for an address. */
120
+ getBalance(address: string): Promise<Balance>;
121
+ /** Get the nonce for an address (shorthand for getBalance().nonce). */
122
+ getNonce(address: string): Promise<bigint>;
123
+ /** Get the receipt for a transaction by hash. */
124
+ getReceipt(txHash: string): Promise<Receipt | null>;
125
+ /** Get the source code of a deployed contract (hex-encoded). */
126
+ getCode(address: string): Promise<string>;
127
+ /** Get the source code of a deployed contract as a UTF-8 string. */
128
+ getContractSource(address: string): Promise<string | null>;
129
+ /** Call a contract view function (read-only, no transaction). */
130
+ viewCall(contract: string, method: string, args?: unknown[]): Promise<ViewCallResult>;
131
+ /** Get the current active validator set. */
132
+ getValidators(): Promise<{
133
+ count: number;
134
+ validators: ValidatorInfo[];
135
+ }>;
136
+ /** Get the chain metadata (EIP-3085 shape). */
137
+ getMetadata(): Promise<Metadata>;
138
+ /** Health check. */
139
+ isHealthy(): Promise<boolean>;
140
+ /** Readiness check (chain advancing). */
141
+ isReady(): Promise<boolean>;
142
+ /** Request test ASE from the faucet. */
143
+ faucet(to: string, amount?: string): Promise<TxResult>;
144
+ /** Submit a raw signed transaction (hex-encoded SSZ bytes). */
145
+ submitRawTx(rawTxHex: string): Promise<TxResult>;
146
+ /** Send a raw JSON-RPC request. */
147
+ jsonRpc<T>(method: string, params?: unknown[]): Promise<T>;
148
+ private get;
149
+ private post;
150
+ }
151
+
152
+ /**
153
+ * AsentumContract — a deployed contract instance that wraps view calls
154
+ * and write transactions.
155
+ *
156
+ * Usage:
157
+ *
158
+ * // Deploy via a wallet
159
+ * const contract = await wallet.deploy(source);
160
+ * console.log(contract.address);
161
+ *
162
+ * // Or wrap an existing deployed contract
163
+ * const contract = new AsentumContract(client, '0xabc...');
164
+ *
165
+ * // Read (free, no signature)
166
+ * const name = await contract.view('name');
167
+ * const balance = await contract.view('balanceOf', ['0x...']);
168
+ *
169
+ * // Write (requires a wallet)
170
+ * const tx = await contract.send('transfer', ['0x...', '1000']);
171
+ * const receipt = await tx.wait();
172
+ */
173
+
174
+ declare class AsentumContract {
175
+ readonly client: AsentumClient;
176
+ readonly address: string;
177
+ /** The deploy tx, if this contract was deployed in this session. */
178
+ readonly deployTx?: SentTx;
179
+ /** The wallet used to deploy this contract, if any. Used as default signer for send(). */
180
+ private wallet?;
181
+ constructor(client: AsentumClient, address: string, deployTx?: SentTx, wallet?: AsentumWallet);
182
+ /**
183
+ * Call a view function (read-only, free, no transaction).
184
+ *
185
+ * @param method - The function name to call.
186
+ * @param args - Arguments to pass to the function.
187
+ * @returns The return value of the function.
188
+ */
189
+ view(method: string, args?: unknown[]): Promise<unknown>;
190
+ /**
191
+ * Call a view function and return the full result including gas + events.
192
+ */
193
+ viewFull(method: string, args?: unknown[]): Promise<ViewCallResult>;
194
+ /**
195
+ * Send a state-changing transaction to the contract.
196
+ *
197
+ * @param method - The function name to call.
198
+ * @param args - Arguments to pass.
199
+ * @param opts - Optional: value to attach, gas limit, nonce, wallet override.
200
+ * @returns A SentTx with `.hash` and `.wait()`.
201
+ */
202
+ send(method: string, args?: unknown[], opts?: {
203
+ value?: string | number | bigint;
204
+ gasLimit?: bigint;
205
+ nonce?: bigint;
206
+ wallet?: AsentumWallet;
207
+ }): Promise<SentTx>;
208
+ /**
209
+ * Attach a wallet to this contract for future send() calls.
210
+ */
211
+ connect(wallet: AsentumWallet): AsentumContract;
212
+ /**
213
+ * Get the source code of this contract as a UTF-8 string.
214
+ * Returns null if the address has no deployed code.
215
+ */
216
+ getSource(): Promise<string | null>;
217
+ /**
218
+ * Get the ASE balance of this contract.
219
+ */
220
+ getBalance(): Promise<bigint>;
221
+ /**
222
+ * Wait for the deploy transaction to be confirmed (if this contract
223
+ * was deployed in this session). Useful after `wallet.deploy()`.
224
+ */
225
+ waitForDeploy(timeoutMs?: number): Promise<Receipt>;
226
+ }
227
+
228
+ /**
229
+ * Parse an ASE amount string into wei (bigint).
230
+ * Accepts: "1", "1.5", "0.001", or a raw wei integer string.
231
+ */
232
+ declare function parseAse(amount: string | number | bigint): bigint;
233
+ /**
234
+ * Format a wei bigint as a human-readable ASE string.
235
+ */
236
+ declare function formatAse(wei: bigint | string): string;
237
+ interface SendTransferOpts {
238
+ /** Recipient address (0x-prefixed, 40 hex chars). */
239
+ to: string;
240
+ /** Amount in ASE (e.g. "1.5") or wei (bigint). */
241
+ amount: string | number | bigint;
242
+ /** Override the gas limit. Default: 21,000. */
243
+ gasLimit?: bigint;
244
+ /** Override the nonce. Default: auto-fetched from the chain. */
245
+ nonce?: bigint;
246
+ }
247
+ interface SendCallOpts {
248
+ /** Contract address (0x-prefixed, 40 hex chars). */
249
+ to: string;
250
+ /** Method name to call on the contract. */
251
+ method: string;
252
+ /** Method arguments (passed as JSON to the contract). */
253
+ args?: unknown[];
254
+ /** ASE to attach to the call (default: 0). */
255
+ value?: string | number | bigint;
256
+ /** Override the gas limit. Default: 2,000,000. */
257
+ gasLimit?: bigint;
258
+ /** Override the nonce. Default: auto-fetched. */
259
+ nonce?: bigint;
260
+ }
261
+ interface DeployOpts {
262
+ /** The JavaScript source code of the contract. */
263
+ source: string;
264
+ /** ASE to attach to the deploy (default: 0). */
265
+ value?: string | number | bigint;
266
+ /** Override the gas limit. Default: based on source length. */
267
+ gasLimit?: bigint;
268
+ /** Override the nonce. Default: auto-fetched. */
269
+ nonce?: bigint;
270
+ }
271
+ interface SentTx {
272
+ /** The transaction hash (0x-prefixed). */
273
+ hash: string;
274
+ /** Wait for the transaction to be included in a block. */
275
+ wait(timeoutMs?: number): Promise<Receipt>;
276
+ }
277
+ declare class AsentumWallet {
278
+ readonly client: AsentumClient;
279
+ readonly keypair: Dilithium3Keypair;
280
+ readonly address: string;
281
+ private constructor();
282
+ /** Create a wallet with a random Dilithium3 keypair. */
283
+ static create(client: AsentumClient): AsentumWallet;
284
+ /** Create a wallet from a 32-byte seed. */
285
+ static fromSeed(client: AsentumClient, seed: Uint8Array): AsentumWallet;
286
+ /** Create a wallet from a hex-encoded secret key. */
287
+ static fromSecretKey(client: AsentumClient, secretKeyHex: string, publicKeyHex: string): AsentumWallet;
288
+ /** Get the secret key as a hex string (for export/backup). */
289
+ get secretKeyHex(): string;
290
+ /** Get the public key as a hex string. */
291
+ get publicKeyHex(): string;
292
+ /** Get the current balance in wei. */
293
+ getBalance(): Promise<bigint>;
294
+ /** Get the current nonce. */
295
+ getNonce(): Promise<bigint>;
296
+ /** Request test ASE from the faucet. */
297
+ requestFaucet(amount?: string): Promise<TxResult>;
298
+ /** Send ASE to another address. */
299
+ sendTransfer(opts: SendTransferOpts): Promise<SentTx>;
300
+ /** Call a method on a deployed contract (state-changing). */
301
+ sendCall(opts: SendCallOpts): Promise<SentTx>;
302
+ /** Deploy a new smart contract. Returns an AsentumContract instance. */
303
+ deploy(sourceOrOpts: string | DeployOpts): Promise<AsentumContract>;
304
+ private signAndSubmit;
305
+ }
306
+
307
+ export { AsentumClient, AsentumContract, AsentumWallet, type Balance, type Block, type BlockHeader, type ChainInfo, type DeployOpts, type Metadata, type Receipt, type SendCallOpts, type SendTransferOpts, type SentTx, type Transaction, type TxResult, type ValidatorInfo, type ViewCallResult, formatAse, parseAse };