@anywalletkit/wallet-near 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,677 @@
1
+ import { IWalletAccountReadOnly, TransferResult, IWalletAccount, Signer, WalletManager, FeeRates } from '@anywalletkit/core';
2
+ export { HistoryFetch, HistoryUnavailableError, NearChainTx, NearHistoryCursor, NearHistoryOptions, NearHistoryPage, NearHistoryRaw, NearHistorySource, NearblocksFtRow, NearblocksReceiptRow, NearblocksTxn, RpcTxStatus, createNearHistory, decodeFunctionCallArgs, decodeCursor as decodeHistoryCursor, encodeCursor as encodeHistoryCursor, mapNearblocksGroup, mapNearblocksTxn, mapRpcTxStatus, nearExplorerTxUrl, parseJsonPreservingBigInts } from './history.cjs';
3
+
4
+ /** JSON-RPC transport: `method` + `params`, returns the `result` (throws on `error`). */
5
+ type NearFetch = (method: string, params: unknown) => Promise<unknown>;
6
+ /** One RPC base url (e.g. "https://free.rpc.fastnear.com") or a ready transport. */
7
+ type NearProvider = string | NearFetch;
8
+ /**
9
+ * Options for a NEAR wallet manager or account: RPC endpoints, network, fee caps and the
10
+ * pre-sign checks.
11
+ */
12
+ interface NearConfig {
13
+ /** RPC url(s) / transport(s). A list fails over in order. Omit for an offline (sign-only) wallet. */
14
+ provider?: NearProvider | NearProvider[];
15
+ /** Extra attempts across the provider list after the first failure (default 3). */
16
+ retries?: number;
17
+ /** Optional headers for every request (e.g. an API key). */
18
+ headers?: Record<string, string>;
19
+ /** "mainnet" (default) | "testnet" | any CAIP-2 suffix. */
20
+ network?: 'mainnet' | 'testnet' | string;
21
+ /** Max fee (yoctoNEAR) for `transfer`. */
22
+ transferMaxFee?: bigint | number;
23
+ /** Max fee (yoctoNEAR) for `sendTransaction` / `signTransaction`. */
24
+ transactionMaxFee?: bigint | number;
25
+ /** Run the balance / account / access-key preflight before signing (default true). */
26
+ simulate?: boolean;
27
+ /**
28
+ * Allow actions that change the account itself or deploy code (AddKey, DeleteKey,
29
+ * DeleteAccount, DeployContract, Stake, CreateAccount, global-contract actions,
30
+ * SignedDelegate). Default false: they are refused with `dangerous-action`.
31
+ */
32
+ allowDangerousActions?: boolean;
33
+ /**
34
+ * Most yoctoNEAR a token `transfer` may attach as `storage_deposit` to register the
35
+ * recipient (the amount comes from the token contract itself). Default 0.0125 NEAR,
36
+ * ten times the usual NEP-145 minimum.
37
+ */
38
+ maxStorageDeposit?: bigint | number;
39
+ }
40
+ interface NearTransferAction {
41
+ transfer: {
42
+ deposit: bigint;
43
+ };
44
+ }
45
+ interface NearFunctionCallAction {
46
+ functionCall: {
47
+ methodName: string;
48
+ /** Raw bytes, or a JSON-serialisable object / string (encoded as UTF-8 JSON). */
49
+ args: Uint8Array | Record<string, unknown> | string;
50
+ /** Prepaid gas (default 30 Tgas). Max 300 Tgas. */
51
+ gas?: bigint;
52
+ /** Attached deposit in yoctoNEAR (default 0). */
53
+ deposit?: bigint;
54
+ };
55
+ }
56
+ interface NearCreateAccountAction {
57
+ createAccount: Record<string, never>;
58
+ }
59
+ interface NearDeployContractAction {
60
+ deployContract: {
61
+ code: Uint8Array;
62
+ };
63
+ }
64
+ interface NearStakeAction {
65
+ stake: {
66
+ stake: bigint;
67
+ publicKey: NearPublicKey;
68
+ };
69
+ }
70
+ /** An access key's nonce and permission (full access or a function-call key). */
71
+ interface NearAccessKey {
72
+ nonce: bigint;
73
+ permission: {
74
+ fullAccess: Record<string, never>;
75
+ } | {
76
+ functionCall: {
77
+ allowance?: bigint;
78
+ receiverId: string;
79
+ methodNames: string[];
80
+ };
81
+ };
82
+ }
83
+ interface NearAddKeyAction {
84
+ addKey: {
85
+ publicKey: NearPublicKey;
86
+ accessKey: NearAccessKey;
87
+ };
88
+ }
89
+ interface NearDeleteKeyAction {
90
+ deleteKey: {
91
+ publicKey: NearPublicKey;
92
+ };
93
+ }
94
+ interface NearDeleteAccountAction {
95
+ deleteAccount: {
96
+ beneficiaryId: string;
97
+ };
98
+ }
99
+ interface NearDelegateAction {
100
+ senderId: string;
101
+ receiverId: string;
102
+ actions: NearAction[];
103
+ nonce: bigint;
104
+ maxBlockHeight: bigint;
105
+ publicKey: NearPublicKey;
106
+ }
107
+ interface NearSignedDelegateAction {
108
+ signedDelegate: {
109
+ delegateAction: NearDelegateAction;
110
+ signature: NearSignature;
111
+ };
112
+ }
113
+ interface NearDeployGlobalContractAction {
114
+ deployGlobalContract: {
115
+ code: Uint8Array;
116
+ deployMode: 'codeHash' | 'accountId';
117
+ };
118
+ }
119
+ interface NearUseGlobalContractAction {
120
+ useGlobalContract: {
121
+ codeHash: Uint8Array;
122
+ } | {
123
+ accountId: string;
124
+ };
125
+ }
126
+ /** One action of a NEAR transaction. */
127
+ type NearAction = NearCreateAccountAction | NearDeployContractAction | NearFunctionCallAction | NearTransferAction | NearStakeAction | NearAddKeyAction | NearDeleteKeyAction | NearDeleteAccountAction | NearSignedDelegateAction | NearDeployGlobalContractAction | NearUseGlobalContractAction;
128
+ /** A public key as NEAR encodes it: curve tag + raw bytes. */
129
+ interface NearPublicKey {
130
+ keyType: 'ed25519' | 'secp256k1';
131
+ data: Uint8Array;
132
+ }
133
+ interface NearSignature {
134
+ keyType: 'ed25519' | 'secp256k1';
135
+ data: Uint8Array;
136
+ }
137
+ /**
138
+ * A transaction to sign. `signerId` / `publicKey` default to the account's; `nonce` /
139
+ * `blockHash` are fetched from the network when omitted (the account `needsNetwork`).
140
+ */
141
+ interface NearTransaction {
142
+ receiverId: string;
143
+ actions: NearAction[];
144
+ signerId?: string;
145
+ publicKey?: NearPublicKey;
146
+ nonce?: bigint;
147
+ /** 32 bytes, or base58. */
148
+ blockHash?: Uint8Array | string;
149
+ }
150
+ /** Fully specified transaction as it is hashed and signed. */
151
+ interface NearBuiltTransaction {
152
+ signerId: string;
153
+ publicKey: NearPublicKey;
154
+ nonce: bigint;
155
+ receiverId: string;
156
+ blockHash: Uint8Array;
157
+ actions: NearAction[];
158
+ }
159
+ interface NearSignedTransaction {
160
+ transaction: NearBuiltTransaction;
161
+ signature: NearSignature;
162
+ }
163
+ /** Shorthand for `transfer`: native NEAR (no `token`) or a NEP-141 token (`token` = contract account id). */
164
+ interface NearTransferOptions {
165
+ token?: string;
166
+ recipient: string;
167
+ amount: bigint | number | string;
168
+ /** NEP-141 `memo` (ignored for native transfers — NEAR transfers carry no memo). */
169
+ memo?: string;
170
+ }
171
+ /** Gas a transaction may burn and its cost in yoctoNEAR. */
172
+ interface NearFeeEstimate {
173
+ /** Gas the transaction can burn at most (prepaid function-call gas counts in full). */
174
+ gas: bigint;
175
+ /** yoctoNEAR per gas unit at quote time. */
176
+ gasPrice: bigint;
177
+ /** Upper bound of the fee in yoctoNEAR (`gas * gasPrice`, plus the account-creation charge when `createsAccount`). */
178
+ fee: bigint;
179
+ /** yoctoNEAR the actions attach (transfer deposits + function-call deposits). */
180
+ deposit: bigint;
181
+ /** True when a native transfer will create an implicit account (extra gas included). */
182
+ createsAccount: boolean;
183
+ }
184
+ /** Fee of a transaction in yoctoNEAR, with the estimate behind it. */
185
+ interface NearQuote {
186
+ /** = `estimate.fee`. */
187
+ fee: bigint;
188
+ estimate: NearFeeEstimate;
189
+ }
190
+ /** Whether a transaction is expected to succeed, and why not. */
191
+ interface NearSimulation {
192
+ ok: boolean;
193
+ reason?: string;
194
+ }
195
+ /** An account's balance, locked stake and storage. */
196
+ interface NearAccountView {
197
+ amount: bigint;
198
+ locked: bigint;
199
+ storageUsage: bigint;
200
+ /** `amount - locked - storageUsage * STORAGE_PRICE_PER_BYTE` (never below 0). */
201
+ available: bigint;
202
+ }
203
+ /** Outcome of a NEAR transaction. */
204
+ interface NearReceipt {
205
+ hash: string;
206
+ /** 1 success, 0 failed. */
207
+ status: 0 | 1;
208
+ blockNumber?: bigint;
209
+ /** Decoded failure, when any receipt failed. */
210
+ failure?: string;
211
+ /** Raw `tx` RPC payload. */
212
+ raw: Record<string, unknown>;
213
+ }
214
+ /** What a NEAR transaction does. */
215
+ type NearTxKind = 'near-transfer' | 'ft-transfer' | 'ft-storage-deposit' | 'function-call' | 'batch' | 'create-account' | 'deploy-contract' | 'stake' | 'add-key' | 'delete-key' | 'delete-account' | 'delegate' | 'global-contract';
216
+ /** Problems a NEAR description is flagged with. */
217
+ type NearTxWarningCode = 'dangerous-action' | 'full-access-key' | 'zero-amount' | 'implicit-new-account' | 'self-transfer' | 'high-gas' | 'unknown-method' | 'invalid-account';
218
+ /** One flagged problem, with a sentence a wallet can show. */
219
+ interface NearTxWarning {
220
+ code: NearTxWarningCode;
221
+ message: string;
222
+ }
223
+ /** A NEAR transaction decoded for a confirmation screen. */
224
+ interface NearTxDescription {
225
+ kind: NearTxKind;
226
+ warnings: NearTxWarning[];
227
+ /** Signer account id when known. */
228
+ from?: string;
229
+ /** Receiver account id (native transfer) or NEP-141 `receiver_id` (ft-transfer). */
230
+ to?: string;
231
+ /** yoctoNEAR (native) or token base units (ft-transfer). */
232
+ amount?: bigint;
233
+ /** NEP-141 contract account id. */
234
+ token?: string;
235
+ /** NEP-141 memo. */
236
+ memo?: string;
237
+ /** Called contract (function-call / batch). */
238
+ contract?: string;
239
+ /** Methods called, in order. */
240
+ methods?: string[];
241
+ /** Total yoctoNEAR attached across actions. */
242
+ deposit: bigint;
243
+ /** Total prepaid gas across function calls. */
244
+ gas: bigint;
245
+ actionCount: number;
246
+ }
247
+ /** CAIP-2 ids of NEAR mainnet and testnet. */
248
+ declare const CAIP2: Record<string, string>;
249
+ /** 1 NEAR = 10^24 yoctoNEAR. */
250
+ declare const YOCTO: bigint;
251
+ /** 1 Tgas. */
252
+ declare const TGAS: bigint;
253
+ /** Hard per-transaction prepaid gas limit. */
254
+ declare const MAX_GAS: bigint;
255
+ /** Protocol storage price: 10^19 yoctoNEAR per byte. */
256
+ declare const STORAGE_PRICE_PER_BYTE: bigint;
257
+ /** NEP-141 `ft_transfer` requires exactly 1 yoctoNEAR attached. */
258
+ declare const ONE_YOCTO = 1n;
259
+ /** Default gas for `ft_transfer` / `storage_deposit`. */
260
+ declare const FT_TRANSFER_GAS: bigint;
261
+ /** Gas attached to a NEP-145 `storage_deposit` call. */
262
+ declare const STORAGE_DEPOSIT_GAS: bigint;
263
+ /** Minimum native transfer that can create an implicit account (covers its storage). */
264
+ declare const IMPLICIT_ACCOUNT_MIN_DEPOSIT: bigint;
265
+
266
+ /** Why a transaction was refused before signing. */
267
+ type UnsafeTransactionCode = 'signer-mismatch' | 'public-key-mismatch' | 'dangerous-action' | 'invalid-account' | 'no-actions' | 'gas-limit' | 'fee-limit' | 'missing-block-hash' | 'missing-nonce' | 'unknown-action' | 'insufficient-balance' | 'implicit-account-min-deposit' | 'no-access-key' | 'storage-deposit';
268
+ /** A transaction failed a hard check and was not signed. */
269
+ declare class UnsafeTransactionError extends Error {
270
+ readonly code: UnsafeTransactionCode;
271
+ constructor(code: UnsafeTransactionCode, message: string);
272
+ }
273
+ /** The preflight (balances, account, access key, token registration) predicted failure; nothing was signed. */
274
+ declare class SimulationError extends Error {
275
+ readonly reason: string;
276
+ constructor(reason: string);
277
+ }
278
+ /** The RPC answered with an `error` object. */
279
+ declare class NearRpcError extends Error {
280
+ readonly method: string;
281
+ readonly errorName: string | undefined;
282
+ readonly cause: unknown;
283
+ constructor(method: string, error: {
284
+ name?: string;
285
+ message?: string;
286
+ cause?: {
287
+ name?: string;
288
+ info?: unknown;
289
+ };
290
+ data?: unknown;
291
+ code?: number;
292
+ });
293
+ }
294
+
295
+ /** True for a valid NEAR account id: 2–64 characters of the allowed alphabet, implicit or named. */
296
+ declare function isValidAccountId(id: string): boolean;
297
+ /** 64 lowercase hex chars = an implicit account (the account id IS the ed25519 public key). */
298
+ declare function isImplicitAccountId(id: string): boolean;
299
+ /** The implicit account id of an ed25519 public key. */
300
+ declare function implicitAccountId(publicKey: Uint8Array): string;
301
+ /** "ed25519:<base58>" as NEAR tooling prints keys. */
302
+ declare function publicKeyToString(k: NearPublicKey): string;
303
+ /** Parse `ed25519:<base58>` (or bare base58) into a public key. */
304
+ declare function parsePublicKey(s: string): NearPublicKey;
305
+ /** A NEAR public key from 32 ed25519 bytes. */
306
+ declare function ed25519Key(publicKey: Uint8Array): NearPublicKey;
307
+ /** The ed25519 public key behind an implicit account id. */
308
+ declare function publicKeyOfImplicit(accountId: string): Uint8Array;
309
+ /** Decode base58, optionally checking the length. */
310
+ declare function base58ToBytes(s: string, length?: number): Uint8Array;
311
+ /** Encode bytes as base58. */
312
+ declare const bytesToBase58: (b: Uint8Array) => string;
313
+
314
+ /**
315
+ * Borsh (https://borsh.io) for NEAR transactions — the exact layout nearcore and
316
+ * @near-js/transactions use, written by hand so the package has no borsh dependency:
317
+ * little-endian integers, u32-length-prefixed strings / vectors, u8 enum tags.
318
+ */
319
+
320
+ /** @internal Minimal borsh encoder for NEAR transactions. */
321
+ declare class BorshWriter {
322
+ private _buf;
323
+ private _len;
324
+ private ensure;
325
+ u8(v: number): this;
326
+ u32(v: number): this;
327
+ uint(v: bigint, bytes: number): this;
328
+ u64(v: bigint): this;
329
+ u128(v: bigint): this;
330
+ bytes(b: Uint8Array): this;
331
+ /** Vec<u8> / String: u32 length + bytes. */
332
+ vecU8(b: Uint8Array): this;
333
+ string(s: string): this;
334
+ option<T>(v: T | undefined, write: (v: T) => void): this;
335
+ toBytes(): Uint8Array;
336
+ }
337
+ /** @internal Minimal borsh decoder for NEAR transactions. */
338
+ declare class BorshReader {
339
+ private readonly _buf;
340
+ private _pos;
341
+ constructor(_buf: Uint8Array);
342
+ get remaining(): number;
343
+ private need;
344
+ u8(): number;
345
+ u32(): number;
346
+ uint(bytes: number): bigint;
347
+ u64(): bigint;
348
+ u128(): bigint;
349
+ bytes(n: number): Uint8Array;
350
+ vecU8(): Uint8Array;
351
+ string(): string;
352
+ option<T>(read: () => T): T | undefined;
353
+ done(): void;
354
+ }
355
+ declare function writePublicKey(w: BorshWriter, k: NearPublicKey): void;
356
+ declare function readPublicKey(r: BorshReader): NearPublicKey;
357
+ declare function writeSignature(w: BorshWriter, s: NearSignature): void;
358
+ declare function readSignature(r: BorshReader): NearSignature;
359
+ /** Enum order from nearcore `Action` (and @near-js/transactions SCHEMA.Action). */
360
+ declare const ACTION_TAG: {
361
+ readonly createAccount: 0;
362
+ readonly deployContract: 1;
363
+ readonly functionCall: 2;
364
+ readonly transfer: 3;
365
+ readonly stake: 4;
366
+ readonly addKey: 5;
367
+ readonly deleteKey: 6;
368
+ readonly deleteAccount: 7;
369
+ readonly signedDelegate: 8;
370
+ readonly deployGlobalContract: 9;
371
+ readonly useGlobalContract: 10;
372
+ };
373
+ type NearActionKey = keyof typeof ACTION_TAG;
374
+ declare function actionKey(a: NearAction): NearActionKey;
375
+ /** Function-call args as bytes: raw bytes pass through; objects / strings become UTF-8 JSON / UTF-8. */
376
+ declare function argsBytes(args: Uint8Array | Record<string, unknown> | string): Uint8Array;
377
+ declare function writeAction(w: BorshWriter, a: NearAction): void;
378
+ declare function readAction(r: BorshReader): NearAction;
379
+ /** Borsh bytes of an unsigned transaction. */
380
+ declare function encodeTransaction(tx: NearBuiltTransaction): Uint8Array;
381
+ /** Decode an unsigned transaction from borsh bytes. */
382
+ declare function decodeTransaction(bytes: Uint8Array): NearBuiltTransaction;
383
+ /** Borsh bytes of a signed transaction, ready to broadcast as base64. */
384
+ declare function encodeSignedTransaction(s: NearSignedTransaction): Uint8Array;
385
+ /** Decode a signed transaction from borsh bytes. */
386
+ declare function decodeSignedTransaction(bytes: Uint8Array): NearSignedTransaction;
387
+ /** Unsigned or signed borsh bytes → the transaction (and signature when present). */
388
+ declare function decodeAnyTransaction(bytes: Uint8Array): {
389
+ transaction: NearBuiltTransaction;
390
+ signature?: NearSignature;
391
+ };
392
+
393
+ /** Base64 helpers that work in Node, browsers and Hermes (no Buffer). */
394
+ declare function toBase64(bytes: Uint8Array): string;
395
+ declare function fromBase64(s: string): Uint8Array;
396
+ /** One transport, or a failover transport over the list. */
397
+ declare function createClient(config: NearConfig): NearFetch | undefined;
398
+ interface RawAccountView {
399
+ amount: string;
400
+ locked: string;
401
+ storage_usage: number;
402
+ code_hash?: string;
403
+ block_height?: number;
404
+ block_hash?: string;
405
+ }
406
+ interface RawAccessKeyView {
407
+ nonce: number;
408
+ permission: 'FullAccess' | {
409
+ FunctionCall: {
410
+ allowance: string | null;
411
+ receiver_id: string;
412
+ method_names: string[];
413
+ };
414
+ };
415
+ block_hash?: string;
416
+ block_height?: number;
417
+ }
418
+ interface RawFinalOutcome {
419
+ status?: Record<string, unknown>;
420
+ final_execution_status?: string;
421
+ transaction?: {
422
+ hash?: string;
423
+ signer_id?: string;
424
+ };
425
+ transaction_outcome?: {
426
+ id?: string;
427
+ block_hash?: string;
428
+ outcome?: {
429
+ status?: Record<string, unknown>;
430
+ gas_burnt?: number;
431
+ tokens_burnt?: string;
432
+ };
433
+ };
434
+ receipts_outcome?: Array<{
435
+ id?: string;
436
+ block_hash?: string;
437
+ outcome?: {
438
+ status?: Record<string, unknown>;
439
+ gas_burnt?: number;
440
+ tokens_burnt?: string;
441
+ };
442
+ }>;
443
+ }
444
+ /** The NEAR JSON-RPC calls a wallet uses, with parsed results. */
445
+ declare class NearRpc {
446
+ readonly fetch: NearFetch;
447
+ constructor(fetch: NearFetch);
448
+ /** `undefined` when the account does not exist. */
449
+ viewAccount(accountId: string): Promise<RawAccountView | undefined>;
450
+ /** `undefined` when the key is not on the account. */
451
+ viewAccessKey(accountId: string, publicKey: string): Promise<RawAccessKeyView | undefined>;
452
+ /** View call; the JSON-decoded return value (`null` for an empty result). */
453
+ callFunction<T = unknown>(contract: string, method: string, args?: Record<string, unknown>): Promise<T>;
454
+ latestBlockHash(): Promise<string>;
455
+ gasPrice(): Promise<bigint>;
456
+ sendTx(signedTxBase64: string, waitUntil?: 'NONE' | 'INCLUDED' | 'EXECUTED_OPTIMISTIC' | 'INCLUDED_FINAL' | 'EXECUTED' | 'FINAL'): Promise<RawFinalOutcome>;
457
+ /** `undefined` when the node does not know the transaction. */
458
+ txStatus(hash: string, senderId: string): Promise<RawFinalOutcome | undefined>;
459
+ }
460
+ /** Human-readable failure from an execution `status` (`{Failure: {...}}`), or undefined on success. */
461
+ declare function failureOf(status: Record<string, unknown> | undefined): string | undefined;
462
+ /** Did the whole transaction (every receipt) succeed? */
463
+ declare function outcomeFailed(o: RawFinalOutcome): string | undefined;
464
+
465
+ /** What an offline description can be told to sharpen its warnings. */
466
+ interface DescribeContext {
467
+ /** The signing account; adds `self-transfer` and fills `from`. */
468
+ signerId?: string;
469
+ /** Whether the receiver account exists; `describeTransactionOnline` fills it from the node. */
470
+ recipientExists?: boolean;
471
+ }
472
+ /** Actions that change the account itself, its keys, or deploy code. Refused unless `allowDangerousActions`. */
473
+ declare const DANGEROUS_ACTIONS: Set<string>;
474
+ /** What a transaction does, decoded offline. Never throws on odd input — it warns. */
475
+ declare function describeTransaction(tx: NearTransaction, ctx?: DescribeContext): NearTxDescription;
476
+ /**
477
+ * True for actions that change who controls the account or its code: keys, account creation
478
+ * or deletion, contract deployment, staking, delegated actions. Refused unless
479
+ * `allowDangerousActions` is set.
480
+ */
481
+ declare const isDangerous: (a: NearAction) => boolean;
482
+
483
+ /** NEP-413 tag (2^31 + 413) that keeps a signed message from being a valid transaction. */
484
+ declare const NEP413_PREFIX: number;
485
+ /** A NEP-413 sign-in message, as a site asks for it. */
486
+ interface Nep413Payload {
487
+ message: string;
488
+ /** 32 random bytes chosen by the verifier (replay protection). */
489
+ nonce: Uint8Array;
490
+ /** Who the message is for (e.g. "intents.near"). */
491
+ recipient: string;
492
+ callbackUrl?: string;
493
+ }
494
+ /** A NEP-413 signature and the key that made it. */
495
+ interface Nep413Signed {
496
+ /** Base64 of the 64-byte ed25519 signature — the encoding wallets return. */
497
+ signature: string;
498
+ /** "ed25519:<base58>" */
499
+ publicKey: string;
500
+ accountId: string;
501
+ }
502
+ /** Borsh bytes of a NEP-413 payload, ready to hash and sign. */
503
+ declare function nep413Bytes(p: Nep413Payload): Uint8Array;
504
+ /** The 32-byte digest an ed25519 signer signs for a NEP-413 message. */
505
+ declare function nep413Hash(p: Nep413Payload): Uint8Array;
506
+
507
+ /**
508
+ * A NEAR account without a key: balances, NEP-141 tokens and storage, fee estimates, simulation,
509
+ * receipts and signature checks.
510
+ */
511
+ declare class WalletAccountReadOnlyNear implements IWalletAccountReadOnly {
512
+ /** Account id: the implicit hex id of the key, or a named account bound to it. */
513
+ readonly address: string;
514
+ readonly chain: string;
515
+ readonly publicKey: NearPublicKey;
516
+ protected readonly _config: NearConfig;
517
+ protected readonly _client: NearFetch | undefined;
518
+ protected readonly _rpc: NearRpc | undefined;
519
+ /**
520
+ * @param address account id; an implicit (64-hex) id also fixes the public key.
521
+ * @param publicKey required for a named account (the key the account signs with).
522
+ */
523
+ constructor(address: string, config?: NearConfig, publicKey?: Uint8Array | NearPublicKey);
524
+ /** "ed25519:<base58>" */
525
+ get publicKeyString(): string;
526
+ protected requireRpc(what: string): NearRpc;
527
+ /** The account id. */
528
+ getAddress(): Promise<string>;
529
+ /** The account as the node sees it; `undefined` when it does not exist yet. */
530
+ getAccountView(accountId?: string): Promise<NearAccountView | undefined>;
531
+ /** Total NEAR balance in yoctoNEAR (0 for an account that does not exist yet). */
532
+ getBalance(): Promise<bigint>;
533
+ /** What can actually be spent: total − locked (staked) − storage reservation. */
534
+ getAvailableBalance(): Promise<bigint>;
535
+ /** True when the account exists on chain. */
536
+ accountExists(accountId: string): Promise<boolean>;
537
+ /** NEP-141 `ft_balance_of`. */
538
+ getTokenBalance(token: string): Promise<bigint>;
539
+ /** Several NEP-141 balances in parallel, keyed by the token contracts as given. */
540
+ getTokenBalances(tokens: string[]): Promise<Record<string, bigint>>;
541
+ /** NEP-145 storage registration of `accountId` on a token contract (`null` = not registered). */
542
+ getStorageBalance(token: string, accountId?: string): Promise<{
543
+ total: bigint;
544
+ available: bigint;
545
+ } | null>;
546
+ /** Minimum deposit a token contract wants for a registration (`storage_balance_bounds.min`). */
547
+ getStorageDepositMin(token: string): Promise<bigint>;
548
+ /**
549
+ * The actions for `transfer`: native → one Transfer; NEP-141 → `ft_transfer` (1 yocto, 30 Tgas),
550
+ * preceded by `storage_deposit` when the recipient is not registered on the token.
551
+ */
552
+ transferActions(o: NearTransferOptions): Promise<{
553
+ receiverId: string;
554
+ actions: NearAction[];
555
+ }>;
556
+ /** Fill `signerId` / `publicKey` / `nonce` / `blockHash` (the last two from the node when missing). */
557
+ buildTransaction(tx: NearTransaction | string): Promise<NearBuiltTransaction>;
558
+ /** Gas upper bound for the actions (prepaid function-call gas in full). */
559
+ static gasOf(actions: NearAction[], createsAccount: boolean): bigint;
560
+ static depositOf(actions: NearAction[]): bigint;
561
+ protected estimate(tx: Pick<NearBuiltTransaction, 'receiverId' | 'actions'>, recipientExists?: boolean): Promise<NearFeeEstimate>;
562
+ /** Gas and cost of a transaction. */
563
+ estimateFee(tx: NearTransaction | string): Promise<NearFeeEstimate>;
564
+ /** Fee of a transaction in yoctoNEAR. */
565
+ quoteSendTransaction(tx: NearTransaction | string): Promise<NearQuote>;
566
+ /** Fee of a transfer in yoctoNEAR, for the same actions `transfer` would send. */
567
+ quoteTransfer(o: NearTransferOptions): Promise<NearQuote>;
568
+ /**
569
+ * Predict failure without signing: the signer account and its access key exist,
570
+ * the spendable balance covers deposits + fee, a named recipient exists (an
571
+ * implicit one may be created, for ≥ 0.002 NEAR), the token balance covers an
572
+ * `ft_transfer`. Transport failures throw; predicted failures don't.
573
+ */
574
+ simulateTransaction(tx: NearBuiltTransaction | NearTransaction, estimate?: NearFeeEstimate): Promise<NearSimulation>;
575
+ /**
576
+ * Refuse what cannot be right: a foreign signer or key, no actions, a dangerous
577
+ * action (unless `allowDangerousActions`), an invalid receiver, prepaid gas over
578
+ * 300 Tgas, a fee above `transactionMaxFee`.
579
+ */
580
+ assertSafe(tx: NearBuiltTransaction, fee?: bigint): void;
581
+ /** `describeTransaction` plus the recipient-existence check against the node. */
582
+ describeTransactionOnline(tx: NearTransaction, ctx?: DescribeContext): Promise<NearTxDescription>;
583
+ /** Status of one of this account's transactions (the `tx` RPC needs the sender). */
584
+ getTransactionReceipt(hash: string): Promise<NearReceipt | undefined>;
585
+ /** Verify an `ed25519:<base58>` (or bare base58 / hex) signature produced by `sign`. */
586
+ verify(message: string | Uint8Array, signature: string): Promise<boolean>;
587
+ /** sha256(borsh(tx)) — what gets signed; base58 of it is the transaction hash. */
588
+ static hashOf(tx: NearBuiltTransaction): Uint8Array;
589
+ static txHash(tx: NearBuiltTransaction): string;
590
+ }
591
+ declare function receiptOf(hash: string, o: RawFinalOutcome): NearReceipt;
592
+ declare function parseSignature(signature: string): Uint8Array;
593
+
594
+ interface NearTransferResult extends TransferResult {
595
+ estimate?: NearFeeEstimate;
596
+ }
597
+ /**
598
+ * Signing NEAR account. The key lives in an ed25519 {@link Signer} (a local key
599
+ * zeroized by `dispose()`, or an external hardware / MPC / backend signer). The
600
+ * account builds the transaction (nonce + block hash from the node), checks it,
601
+ * runs the preflight, has the signer sign sha256(borsh(tx)) (context `near-tx`)
602
+ * and broadcasts it with `send_tx`.
603
+ *
604
+ * By default the account id is the implicit one (hex of the public key). Pass
605
+ * `accountId` for a named account whose full-access key this is.
606
+ */
607
+ declare class WalletAccountNear extends WalletAccountReadOnlyNear implements IWalletAccount {
608
+ /** nonce / block hash come from the node, so building needs the network. */
609
+ readonly needsNetwork = true;
610
+ /** Derivation path, or `external` for an external signer. */
611
+ readonly path: string;
612
+ /** The signer that holds the key. */
613
+ readonly signer: Signer;
614
+ private _disposed;
615
+ private _readOnly;
616
+ constructor(signer: Signer, publicKey: Uint8Array, path: string, config?: NearConfig, accountId?: string);
617
+ /** Wrap a raw derived key (takes ownership; zeroized on dispose). */
618
+ static fromPrivateKey(privateKey: Uint8Array, publicKey: Uint8Array, path: string, config?: NearConfig, accountId?: string): WalletAccountNear;
619
+ /** Account index for the standard m/44'/397'/i' path. */
620
+ get index(): number | undefined;
621
+ /** The same key bound to a named account (`alice.near`) that lists it as a full-access key. */
622
+ withAccountId(accountId: string): WalletAccountNear;
623
+ private key;
624
+ private signBytes;
625
+ /** Raw ed25519 signature over the message bytes, as NEAR tooling prints it: "ed25519:<base58>". */
626
+ sign(message: string | Uint8Array): Promise<string>;
627
+ /** NEP-413 off-chain message (what NEAR Intents and dApps ask wallets to sign). */
628
+ signNep413(payload: Nep413Payload): Promise<Nep413Signed>;
629
+ /** Sign a fully built transaction. No checks — see `signTransaction`. */
630
+ signBuilt(tx: NearBuiltTransaction): Promise<NearSignedTransaction>;
631
+ /** Build → hard checks → preflight → fee cap. Shared by sign / send / transfer. */
632
+ private prepare;
633
+ /** Build, check, preflight and sign; returns the signed transaction as base64 borsh (what `send_tx` takes). */
634
+ signTransaction(tx: NearTransaction | string): Promise<string>;
635
+ private broadcast;
636
+ /**
637
+ * Sign and broadcast. Accepts a transaction, or base64 borsh of an unsigned /
638
+ * already-signed transaction (a signed one is checked, not re-signed).
639
+ */
640
+ sendTransaction(tx: NearTransaction | string): Promise<NearTransferResult>;
641
+ /** Native NEAR (no `token`) or NEP-141 `ft_transfer` (with `storage_deposit` when the recipient needs it). */
642
+ transfer(o: NearTransferOptions): Promise<NearTransferResult>;
643
+ /** The same account as a {@link WalletAccountReadOnlyNear}. */
644
+ toReadOnlyAccount(): IWalletAccountReadOnly;
645
+ /** Dispose the signer (zeroizes a local key). Idempotent. */
646
+ dispose(): void;
647
+ }
648
+
649
+ /** Base derivation path; account `i` is at `m/44'/397'/i'`. */
650
+ declare const NEAR_BASE_PATH = "m/44'/397'";
651
+ /**
652
+ * One seed → NEAR accounts at m/44'/397'/i' (SLIP-10 ed25519 — the NEAR Wallet /
653
+ * near-seed-phrase path; index 0 is what every NEAR wallet derives). Paths may be
654
+ * given relative to m/44'/397' ("0'") or in full; every segment must be hardened.
655
+ *
656
+ * Built with an ed25519 `Signer` instead of a seed, the manager wraps it:
657
+ * - a derivable `SeedSigner` sitting at `m/44'/397'` yields `getAccount(i)` → `i'` children;
658
+ * - a `SeedSigner` at a leaf, or any external signer, is `getAccount(0)` (path = the
659
+ * signer's path, or 'external'); other indexes/paths throw `SignerError`.
660
+ *
661
+ * `getNamedAccount("alice.near", i)` binds account i's key to a named account.
662
+ */
663
+ declare class WalletManagerNear extends WalletManager<WalletAccountNear, NearConfig> {
664
+ constructor(seedOrSigner: string | Uint8Array | Signer, config?: NearConfig);
665
+ getAccount(index?: number): Promise<WalletAccountNear>;
666
+ getAccountByPath(path: string): Promise<WalletAccountNear>;
667
+ /** The key of account `index`, bound to a named account that lists it as a full-access key. */
668
+ getNamedAccount(accountId: string, index?: number): Promise<WalletAccountNear>;
669
+ /** Resolve `path` against an injected signer: the signer itself, or a child when it can derive there. */
670
+ private fromSigner;
671
+ /** A read-only account for any account id, with this manager's config. */
672
+ getReadOnlyAccount(accountId: string, publicKey?: Uint8Array | NearPublicKey): WalletAccountReadOnlyNear;
673
+ /** NEAR has one protocol gas price (`gas_price` RPC, yoctoNEAR per gas); it can rise ~1%/block, so fast = ×1.1. */
674
+ getFeeRates(): Promise<FeeRates>;
675
+ }
676
+
677
+ export { ACTION_TAG, BorshReader, BorshWriter, CAIP2, DANGEROUS_ACTIONS, type DescribeContext, FT_TRANSFER_GAS, IMPLICIT_ACCOUNT_MIN_DEPOSIT, MAX_GAS, NEAR_BASE_PATH, NEP413_PREFIX, type NearAccessKey, type NearAccountView, type NearAction, type NearAddKeyAction, type NearBuiltTransaction, type NearConfig, type NearCreateAccountAction, type NearDelegateAction, type NearDeleteAccountAction, type NearDeleteKeyAction, type NearDeployContractAction, type NearDeployGlobalContractAction, type NearFeeEstimate, type NearFetch, type NearFunctionCallAction, type NearProvider, type NearPublicKey, type NearQuote, type NearReceipt, NearRpc, NearRpcError, type NearSignature, type NearSignedDelegateAction, type NearSignedTransaction, type NearSimulation, type NearStakeAction, type NearTransaction, type NearTransferAction, type NearTransferOptions, type NearTransferResult, type NearTxDescription, type NearTxKind, type NearTxWarning, type NearTxWarningCode, type NearUseGlobalContractAction, type Nep413Payload, type Nep413Signed, ONE_YOCTO, STORAGE_DEPOSIT_GAS, STORAGE_PRICE_PER_BYTE, SimulationError, TGAS, type UnsafeTransactionCode, UnsafeTransactionError, WalletAccountNear, WalletAccountReadOnlyNear, WalletManagerNear, YOCTO, actionKey, argsBytes, base58ToBytes, bytesToBase58, createClient, decodeAnyTransaction, decodeSignedTransaction, decodeTransaction, WalletManagerNear as default, describeTransaction, ed25519Key, encodeSignedTransaction, encodeTransaction, failureOf, fromBase64, implicitAccountId, isDangerous, isImplicitAccountId, isValidAccountId, nep413Bytes, nep413Hash, outcomeFailed, parsePublicKey, parseSignature, publicKeyOfImplicit, publicKeyToString, readAction, readPublicKey, readSignature, receiptOf, toBase64, writeAction, writePublicKey, writeSignature };