@asichain/asi-wallet-sdk 0.1.6 → 1.0.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/dist/index.d.ts CHANGED
@@ -1,10 +1,103 @@
1
- import { BIP32Interface } from 'bip32';
2
1
  import { AxiosRequestConfig, AxiosInstance } from 'axios';
2
+ import { BIP32Interface } from 'bip32';
3
+
4
+ declare const NATIVE_TOKEN_DECIMALS_AMOUNT: number;
5
+ declare const DEFAULT_PHLO_LIMIT: number;
6
+ declare const DEFAULT_PHLO_PRICE: number;
7
+ declare const DEFAULT_NODE_STORAGE_DIR: string;
8
+ declare const GasFee: {
9
+ MIN: bigint;
10
+ MAX: bigint;
11
+ };
12
+ declare const DEPLOY_STATUS_POLLING_TIMEOUT: number;
13
+ declare const RESERVATION_EXPIRATION_TIME: number;
14
+
15
+ type AssetId = string;
16
+ type Assets = Map<AssetId, Asset>;
17
+
18
+ interface IAssetOptions {
19
+ id: string;
20
+ name: string;
21
+ decimals?: number;
22
+ contractAddress?: string;
23
+ }
24
+ declare class Asset {
25
+ private readonly id;
26
+ private readonly name;
27
+ private readonly decimals;
28
+ private readonly contractAddress;
29
+ constructor({ id, name, decimals, contractAddress }: IAssetOptions);
30
+ getId(): string;
31
+ getName(): string;
32
+ getDecimals(): number;
33
+ getContractAddress(): string | null;
34
+ }
35
+ declare const DEFAULT_ASSET: Asset;
36
+
37
+ interface IBip44PathOptions {
38
+ coinType: number;
39
+ account?: number;
40
+ change?: number;
41
+ index?: number;
42
+ }
43
+ declare class Bip44Path {
44
+ private static readonly BIP44_PURPOSE;
45
+ private static readonly MIN_CHANGE;
46
+ private static readonly MAX_CHANGE;
47
+ private static readonly PATH_COMPONENTS_COUNT;
48
+ private static readonly PURPOSE_INDEX;
49
+ private static readonly COIN_TYPE_INDEX;
50
+ private static readonly ACCOUNT_INDEX;
51
+ private static readonly CHANGE_INDEX;
52
+ private static readonly INDEX_COMPONENT_INDEX;
53
+ private static readonly DECIMAL_RADIX;
54
+ private coinType;
55
+ private account;
56
+ private change;
57
+ private index;
58
+ constructor({ coinType, account, change, index, }: IBip44PathOptions);
59
+ static parse(pathString: string): Bip44Path;
60
+ toString(): string;
61
+ getCoinType(): number;
62
+ getAccount(): number;
63
+ getChange(): number;
64
+ getIndex(): number;
65
+ setCoinType(value: number): void;
66
+ setAccount(value: number): void;
67
+ setChange(value: number): void;
68
+ setIndex(value: number): void;
69
+ static fromOptions(options: IBip44PathOptions): Bip44Path;
70
+ toOptions(): IBip44PathOptions;
71
+ clone(): Bip44Path;
72
+ nextIndex(): Bip44Path;
73
+ }
3
74
 
4
- declare class FeeService {
5
- static generateRandomGasFee: () => string;
6
- static getGasFeeAsNumber: () => number;
7
- static formatGasFee: (fee?: string) => string;
75
+ interface IPasswordCredentials {
76
+ password: string;
77
+ }
78
+ interface IPrivateKeyCredentials {
79
+ privateKey: Uint8Array;
80
+ }
81
+ interface ISeedCredentials {
82
+ seed: string;
83
+ }
84
+ interface IPrivateKeyWithCredentials extends IPasswordCredentials {
85
+ privateKey: Uint8Array;
86
+ }
87
+ interface IHDSecret extends ISeedCredentials {
88
+ rootHDPath: Bip44Path;
89
+ }
90
+ interface IHDSecretRecord extends ISeedCredentials {
91
+ rootHDPath: string;
92
+ }
93
+ interface IAccountHDData extends ISeedCredentials {
94
+ path: string;
95
+ }
96
+ type TSecretsProviderInterface = () => any;
97
+ declare class SecretsProvider {
98
+ #private;
99
+ constructor(providerInterface: TSecretsProviderInterface);
100
+ getSecret(): any;
8
101
  }
9
102
 
10
103
  declare const enum KeyUsage {
@@ -12,7 +105,7 @@ declare const enum KeyUsage {
12
105
  DECRYPT = "decrypt",
13
106
  DERIVATION = "deriveKey"
14
107
  }
15
- interface CryptoConfig {
108
+ type CryptoConfig = {
16
109
  readonly VERSION: number;
17
110
  readonly IV_LENGTH: number;
18
111
  readonly SALT_LENGTH: number;
@@ -23,173 +116,248 @@ interface CryptoConfig {
23
116
  readonly KEY_IMPORT_USAGE: KeyUsage[];
24
117
  readonly HASH_FUNCTION: string;
25
118
  readonly ALGORITHM: string;
26
- }
27
- interface EncryptedData {
119
+ };
120
+ type EncryptedData = {
28
121
  data: string;
29
122
  salt: string;
30
123
  iv: string;
31
124
  version: number;
32
- }
125
+ };
33
126
  declare class CryptoService {
34
127
  static encryptWithPassword(data: string, password: string): Promise<EncryptedData>;
35
128
  static decryptWithPassword(payload: EncryptedData, passphrase: string): Promise<string>;
129
+ static decryptSignerData(signerData: EncryptedData, passwordProvider: SecretsProvider): Promise<IHDSecret | IPrivateKeyCredentials>;
36
130
  static deriveKey(password: string, salt: Uint8Array): Promise<CryptoKey>;
37
131
  }
38
132
 
39
- type AssetId = string;
40
- type Assets = Map<AssetId, Asset>;
41
-
42
- declare class Asset {
43
- private id;
44
- private name;
45
- private decimals;
46
- constructor(id: string, name: string, decimals?: number);
133
+ declare enum WalletTypes {
134
+ PRIVATE_KEY = "private-key",
135
+ HD = "hd"
136
+ }
137
+ interface ISignerOptions {
138
+ id: string;
139
+ encryptedSecret: EncryptedData;
140
+ }
141
+ type TPKSigningContext = {
142
+ passwordProvider: SecretsProvider;
143
+ };
144
+ type THDSigningContext = {
145
+ passwordProvider: SecretsProvider;
146
+ index: number;
147
+ };
148
+ type ISignedMessageResponse = {
149
+ signature: Uint8Array;
150
+ publicKey: Uint8Array;
151
+ };
152
+ type TSigningContext = TPKSigningContext | THDSigningContext;
153
+ interface ISignerRecord {
154
+ id: string;
155
+ type: WalletTypes;
156
+ encryptedData: EncryptedData;
157
+ }
158
+ declare abstract class Signer {
159
+ protected readonly id: string;
160
+ protected encryptedSecret: EncryptedData;
161
+ constructor({ id, encryptedSecret }: ISignerOptions);
47
162
  getId(): string;
48
- getName(): string;
49
- getDecimals(): number;
163
+ getEncryptedSecret(): EncryptedData;
164
+ abstract sign(payload: string, signingContext: TSigningContext): Promise<ISignedMessageResponse>;
50
165
  }
51
166
 
52
- type AddressBrand = {
53
- readonly __brand: unique symbol;
167
+ declare class ItemManager<T> {
168
+ protected readonly items: Map<string, T>;
169
+ constructor(items?: Map<string, T>);
170
+ add(id: string, item: T): void;
171
+ remove(id: string): T;
172
+ get(id: string): T | null;
173
+ hasByFilter(filter: (item: T) => boolean): boolean;
174
+ has(id: string): boolean;
175
+ getAll(): T[];
176
+ getMap(): Map<string, T>;
177
+ clear(): void;
178
+ }
179
+
180
+ interface ICreatedAccountData {
181
+ accountId: string;
182
+ account: Account;
183
+ }
184
+ declare class AccountManager extends ItemManager<Account> {
185
+ private activeAccount;
186
+ constructor(accounts?: Map<string, Account>, activeAccount?: Account | null);
187
+ create(payload: TCreateAccountPayload, secretProvider: SecretsProvider): Promise<ICreatedAccountData>;
188
+ remove(id: string): Account;
189
+ update(id: string, payload: TEditableAccountOptions): void;
190
+ setActiveAccount(id: string): void;
191
+ getActiveAccount(): Account | null;
192
+ getAccounts(): Account[];
193
+ getAccountsMap(): Map<string, Account>;
194
+ getAccount(id: string): Account | null;
195
+ }
196
+
197
+ type TAxiosClientConfig = {
198
+ baseUrl: string;
199
+ axiosConfig?: AxiosRequestConfig;
54
200
  };
55
- type Address = `1111${string & AddressBrand}`;
56
- interface StoredWalletMeta {
57
- name: string;
58
- address: Address;
59
- encryptedPrivateKey: string;
60
- masterNodeId: string | null;
61
- index: string | null;
62
- }
63
- type StringifiedWalletMeta = string;
64
- type WalletMemory = Map<string, string>;
65
- declare enum WalletMemoryKeys {
66
- PRIVATE_KEY = "private_key",
67
- CRYPTO_SALT = "crypto_salt",
68
- CRYPTO_IV = "crypto_iv",
69
- CRYPTO_VERSION = "crypto version"
70
- }
71
- interface SigningCapability {
72
- signDigest(digest: Uint8Array): Promise<Uint8Array>;
73
- getPublicKey(): Uint8Array;
201
+ declare abstract class BaseHttpClient {
202
+ protected readonly client: AxiosInstance;
203
+ constructor(config: TAxiosClientConfig);
204
+ protected get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
205
+ protected post<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
74
206
  }
75
- declare class Wallet {
76
- private static unsafeRawKeyExportEnabled;
77
- private name;
78
- private address;
79
- private privateKey;
80
- private isLocked;
81
- private assets;
82
- private masterNodeId;
83
- private index;
84
- private constructor();
85
- static fromPrivateKey(name: string, privateKey: Uint8Array, password: string, masterNodeId?: string | null, index?: number | null): Promise<Wallet>;
86
- static fromEncryptedData(name: string, address: Address, encryptedPrivateKey: EncryptedData, masterNodeId: string | null, index: number | null): Wallet;
87
- /**
88
- * @deprecated Raw key export is disabled by default. Prefer `withSigningCapability()`.
89
- * Enable only for legacy migration by calling `Wallet.enableUnsafeRawKeyExportForLegacyInterop()`.
90
- */
91
- decrypt(password: string): Promise<Uint8Array>;
92
- static enableUnsafeRawKeyExportForLegacyInterop(): void;
93
- static disableUnsafeRawKeyExport(): void;
94
- static isUnsafeRawKeyExportEnabled(): boolean;
95
- private decryptPrivateKey;
96
- withSigningCapability<T>(password: string, callback: (signingCapability: SigningCapability) => Promise<T> | T): Promise<T>;
97
- getEncryptedPrivateKey(): EncryptedData;
98
- registerAsset(asset: Asset): void;
99
- getAddress(): Address;
100
- getName(): string;
101
- getIndex(): number | null;
102
- getAssets(): Assets;
103
- isWalletLocked(): boolean;
104
- toString(): StringifiedWalletMeta;
105
- private static encryptPrivateKey;
207
+
208
+ declare class BaseGraphQLClient {
209
+ private readonly client;
210
+ constructor(config: TAxiosClientConfig);
211
+ query<T>(query: string, variables?: Record<string, unknown>): Promise<T>;
106
212
  }
107
213
 
108
- interface CreateWalletOptions {
109
- name?: string;
214
+ /**
215
+ * Important: This isn't pure UI pagination. It's SDK application layer pagination. It affects what data is retrieved during database queries.
216
+ */
217
+ type Pagination = Partial<{
218
+ offset: number;
219
+ limit: number;
220
+ }>;
221
+
222
+ type NetworkName = "Dev" | "MainNet" | "TestNet" | "DevNet";
223
+ interface INetworkConfig {
224
+ ValidatorURL: string;
225
+ ReadOnlyURL: string;
226
+ IndexerURL: string;
110
227
  }
111
- interface WalletMeta {
112
- address: string;
113
- privateKey: Uint8Array;
114
- publicKey?: Uint8Array;
115
- mnemonic?: string;
228
+ type TNetworksConfig = Record<NetworkName, INetworkConfig>;
229
+
230
+ interface ITableRecord {
231
+ id: string;
232
+ [key: string]: any;
116
233
  }
117
- declare class WalletsService {
118
- static createWallet(privateKey?: Uint8Array, options?: CreateWalletOptions): WalletMeta;
119
- static createWalletFromMnemonic(mnemonic?: string, index?: number): Promise<WalletMeta>;
120
- static deriveAddressFromPrivateKey(privateKey: Uint8Array): Address;
121
- static deriveAddressFromPublicKey(publicKey: Uint8Array): Address;
234
+ interface ITableService<T extends ITableRecord> {
235
+ createTable(tableName: string, keyPath?: string): Promise<void>;
236
+ insert(tableName: string, record: T): Promise<void>;
237
+ insertMany(tableName: string, records: T[]): Promise<void>;
238
+ getById(tableName: string, id: string | number): Promise<T | null>;
239
+ getAll(tableName: string): Promise<T[]>;
240
+ update(tableName: string, id: string | number, data: Partial<T>): Promise<void>;
241
+ delete(tableName: string, id: string | number): Promise<void>;
242
+ deleteMany(tableName: string, ids: (string | number)[]): Promise<void>;
243
+ clearTable(tableName: string): Promise<void>;
244
+ dropTable(tableName: string): Promise<void>;
245
+ tableExists(tableName: string): Promise<boolean>;
246
+ close: () => Promise<void>;
247
+ init(): Promise<any>;
248
+ isInitialized(): boolean;
122
249
  }
123
250
 
124
- declare enum MnemonicStrength {
125
- TWELVE_WORDS = 128,
126
- TWENTY_FOUR_WORDS = 256
251
+ type TransactionStatus = "pending" | "confirmed" | "failed";
252
+ interface Transaction {
253
+ id: string;
254
+ timestamp: Date;
255
+ type: "send" | "receive" | "deploy";
256
+ from: string;
257
+ to?: string;
258
+ amount?: string;
259
+ deployId?: string;
260
+ blockHash?: string;
261
+ gasCost?: string;
262
+ status: TransactionStatus;
263
+ contractCode?: string;
264
+ note?: string;
265
+ networkName: NetworkName;
266
+ detectedBy?: "balance_change" | "manual" | "auto";
127
267
  }
128
- declare class MnemonicService {
129
- static generateMnemonic(strength?: MnemonicStrength): string;
130
- static generateMnemonicArray(strength?: MnemonicStrength): string[];
131
- static isMnemonicValid(mnemonic: string): boolean;
132
- static mnemonicToWordArray(mnemonic: string): string[];
133
- static wordArrayToMnemonic(words: string[]): string;
268
+ interface ITransactionReservationPrivateData {
269
+ timestamp: Date;
270
+ accountAddress: string;
271
+ pendingAmount: string;
272
+ deployId: string;
273
+ expirationTime: number;
274
+ }
275
+ interface ITransactionReservation extends ITransactionReservationPrivateData, ITableRecord {
276
+ networkName: NetworkName;
134
277
  }
135
278
 
136
- interface Bip44PathOptions {
137
- coinType: number;
138
- account?: number;
139
- change?: number;
140
- index?: number;
279
+ interface TransactionHistoryQueryData {
280
+ transfers?: RawTransfer[];
141
281
  }
142
- declare class KeyDerivationService {
143
- static buildBip44Path({ coinType, account, change, index, }: Bip44PathOptions): string;
144
- static derivePrivateKey(masterNode: BIP32Interface, path: string): Uint8Array;
145
- static mnemonicToSeed(mnemonicWords: string[] | string, passphrase?: string): Promise<Uint8Array>;
146
- static seedToMasterNode(seed: any): BIP32Interface;
147
- static deriveKeyFromMnemonic(mnemonicWords: string[], options?: Bip44PathOptions): Promise<Uint8Array>;
148
- static deriveNextKeyFromMnemonic(mnemonicWords: string[], currentIndex: number, options?: Omit<Bip44PathOptions, "index">): Promise<Uint8Array>;
282
+ interface RawTransfer {
283
+ deploy_id: string;
284
+ block_number?: number | string;
285
+ block_hash?: string;
286
+ from_address?: string;
287
+ to_address?: string;
288
+ amount_asi?: number | string;
289
+ timestamp?: number | string;
290
+ from_public_key?: string;
291
+ network_name?: string;
149
292
  }
150
293
 
151
- interface KeyPair {
152
- privateKey: Uint8Array;
153
- publicKey: Uint8Array;
294
+ declare class IndexerClient extends BaseGraphQLClient {
295
+ getTransactionHistory(address: string, pagination?: Pagination): Promise<TransactionHistoryQueryData>;
154
296
  }
155
- declare class KeysManager {
156
- static generateRandomKey(length?: number): Uint8Array;
157
- static generateKeyPair(keyLength?: number): KeyPair;
158
- static getKeyPairFromPrivateKey(privateKey: Uint8Array): KeyPair;
159
- static getPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
160
- static convertKeyToHex(key: Uint8Array): string;
161
- static deriveKeyFromMnemonic(mnemonicWords: string[], options?: Bip44PathOptions): Promise<Uint8Array>;
162
- static generateMpcKeyPair(): any;
163
- }
164
-
165
- declare enum RecoverableDeployErrors {
166
- READ_ONLY_NODE = "READ_ONLY_NODE",
167
- CASPER_INSTANCE_UNAVAILABLE = "CASPER_INSTANCE_UNAVAILABLE",
168
- INVALID_DEPLOY_ID = "INVALID_DEPLOY_ID",
169
- INVALID_BLOCK_NUMBER = "INVALID_BLOCK_NUMBER"
170
- }
171
- declare enum FatalDeployErrors {
172
- INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
173
- WRONG_NETWORK = "WRONG_NETWORK",
174
- PARSING_ERROR = "PARSING_ERROR",
175
- LOW_PHLO_PRICE = "LOW_PHLO_PRICE",
176
- SIGNATURE_ERROR = "SIGNATURE_ERROR",
177
- STORAGE_RETRIEVAL_ERROR = "STORAGE_RETRIEVAL_ERROR",
178
- UNKNOWN_ERROR = "UNKNOWN_ERROR",
179
- DEPLOY_SUBMIT_TIMEOUT = "DEPLOY_SUBMIT_TIMEOUT",
180
- BLOCK_INCLUSION_TIMEOUT = "BLOCK_INCLUSION_TIMEOUT",
181
- FINALIZATION_TIMEOUT = "FINALIZATION_TIMEOUT"
182
- }
183
- type DeploymentErrorType = RecoverableDeployErrors | FatalDeployErrors;
184
- declare const deploymentErrorMessages: Record<DeploymentErrorType, string>;
185
- declare function getDeploymentErrorMessage(errorType: DeploymentErrorType): string;
186
-
187
- declare class DeploymentErrorHandler {
188
- parseDeploymentError(errorMessage: string): DeploymentErrorType;
189
- isDeploymentErrorRecoverable(errorType: DeploymentErrorType): boolean;
190
- isDeploymentErrorFatal(errorType: DeploymentErrorType): boolean;
191
- isPollingErrorRecoverable(errorMessage: string): boolean;
192
- getErrorMessageByErrorType(errorType: DeploymentErrorType): string;
297
+
298
+ interface IBalanceResponse {
299
+ balance: number;
300
+ }
301
+ interface IBlockDto {
302
+ blockInfo: string;
303
+ blockNumber: number;
304
+ }
305
+ type TBlocksView = "summary" | "full";
306
+ interface IGetBlocksParams {
307
+ start?: number;
308
+ end?: number;
309
+ view?: TBlocksView;
310
+ }
311
+ declare class ObserverClient extends BaseHttpClient {
312
+ getDeploy(deployHash: string): Promise<unknown>;
313
+ getBlock(blockHash: string): Promise<IBlockDto>;
314
+ getBlocks(params?: IGetBlocksParams): Promise<IBlockDto[]>;
315
+ }
316
+
317
+ declare class ValidatorClient extends BaseHttpClient {
318
+ submitDeploy(deploy: any): Promise<unknown>;
319
+ submitExploratoryDeploy(rholangCode: string): Promise<any>;
320
+ getStatus(): Promise<unknown>;
321
+ }
322
+
323
+ interface IApiClients {
324
+ validator: ValidatorClient;
325
+ observer: ObserverClient;
326
+ indexer: IndexerClient;
327
+ }
328
+ declare class ApiClientManager {
329
+ private static instance;
330
+ private readonly networkConfigProvider;
331
+ private validatorClient;
332
+ private observerClient;
333
+ private indexerClient;
334
+ private currentNetwork;
335
+ private isInitialized;
336
+ private constructor();
337
+ static getInstance(): ApiClientManager;
338
+ initialize(networksConfig: TNetworksConfig, network?: NetworkName): void;
339
+ switchNetwork(network: NetworkName): void;
340
+ getValidatorClient(): ValidatorClient;
341
+ getObserverClient(): ObserverClient;
342
+ getIndexerClient(): IndexerClient;
343
+ getClients(): {
344
+ validator: ValidatorClient;
345
+ observer: ObserverClient;
346
+ indexer: IndexerClient;
347
+ };
348
+ getNetwork(): NetworkName;
349
+ getNetworkNames(): NetworkName[];
350
+ isReady(): boolean;
351
+ close(): void;
352
+ }
353
+
354
+ interface DeployData {
355
+ term: string;
356
+ phloLimit: number;
357
+ phloPrice: number;
358
+ validAfterBlockNumber: number;
359
+ timestamp: number;
360
+ shardId?: string;
193
361
  }
194
362
 
195
363
  interface SigningRequest {
@@ -202,7 +370,9 @@ interface SignedResult {
202
370
  signature: string;
203
371
  sigAlgorithm: string;
204
372
  }
205
- type PasswordProvider = () => Promise<string>;
373
+ declare class SignerService {
374
+ static readonly deployDataProtobufSerialize: (deployData: DeployData) => Uint8Array;
375
+ }
206
376
 
207
377
  declare enum DeployStatus {
208
378
  DEPLOYING = "Deploying",
@@ -210,127 +380,249 @@ declare enum DeployStatus {
210
380
  FINALIZED = "Finalized",
211
381
  CHECK_ERROR = "CheckingError"
212
382
  }
213
- type DeployStatusResult = {
214
- status: Exclude<DeployStatus, DeployStatus.CHECK_ERROR>;
383
+ type IDeployStatusResult = {
384
+ status: DeployStatus.DEPLOYING | DeployStatus.INCLUDED_IN_BLOCK | DeployStatus.FINALIZED;
215
385
  } | {
216
386
  status: DeployStatus.CHECK_ERROR;
217
387
  errorMessage: string;
218
388
  };
219
- type GatewayClientConfig = {
220
- baseUrl: string;
221
- axiosConfig?: AxiosRequestConfig;
222
- };
223
- interface BlockchainGatewayConfig {
224
- validator: GatewayClientConfig;
225
- indexer: GatewayClientConfig;
226
- }
227
- declare class BlockchainGateway {
228
- private static instance;
229
- private validatorClient;
230
- private indexerClient;
231
- private constructor();
232
- private static createHttpClient;
233
- changeValidator(config: GatewayClientConfig): this;
234
- changeIndexer(config: GatewayClientConfig): this;
235
- static init(config: BlockchainGatewayConfig): BlockchainGateway;
236
- static isInitialized(): boolean;
237
- static getInstance(): BlockchainGateway;
238
- getValidatorClientUrl(): string;
239
- submitDeploy(deployData: SignedResult): Promise<string | undefined>;
240
- submitExploratoryDeploy(rholangCode: string): Promise<any>;
389
+ declare class DeployService {
390
+ private readonly apiClientManager;
391
+ constructor(apiClientManager?: ApiClientManager);
392
+ private extractDeployId;
393
+ submitSignedDeploy(deploy: SignedResult): Promise<string | undefined>;
241
394
  exploreDeployData(rholangCode: string): Promise<any>;
242
395
  getDeploy(deployHash: string): Promise<any>;
243
396
  isDeployFinalized(deploy: any): Promise<boolean>;
244
- getDeployStatus(deployHash: string): Promise<DeployStatusResult>;
245
- getBlock(blockHash: string): Promise<any>;
397
+ getDeployStatus(deployHash: string): Promise<IDeployStatusResult>;
398
+ }
399
+
400
+ declare class BlockService {
401
+ private readonly apiClientManager;
402
+ constructor(apiClientManager?: ApiClientManager);
403
+ getBlock(blockHash: string): Promise<string>;
404
+ getLatestBlock(): Promise<IBlockDto>;
246
405
  getLatestBlockNumber(): Promise<number>;
247
406
  isValidatorActive(): Promise<boolean>;
248
- private getGatewayErrorMessage;
249
- private validateBlocksResponse;
250
- private getLatestBlock;
251
407
  }
252
408
 
253
- interface NodeProvider {
254
- connectDefaultNode(): Promise<void>;
255
- connectActiveRandomNode(): Promise<void>;
256
- deactivateCurrentNode(): void;
257
- isInitialized(): boolean;
258
- getRetriesLeft(): number;
409
+ interface ITransferDetails {
410
+ to: Address;
411
+ amount: bigint;
412
+ asset: Asset;
413
+ phloLimit?: number;
414
+ phloPrice?: number;
415
+ shardId?: string;
259
416
  }
260
- interface ResubmitConfig {
261
- phloPrice: number;
262
- useRandomNode: boolean;
263
- deployValiditySeconds: number;
264
- nodeSelectionAttempts: number;
265
- deployRetries: number;
266
- deployIntervalSeconds: number;
267
- pollingIntervalSeconds: number;
268
- }
269
- interface ErrorDetail {
270
- blockchainError?: {
271
- type: DeploymentErrorType;
272
- message: string;
273
- };
274
- exceededTimeout?: FatalDeployErrors.DEPLOY_SUBMIT_TIMEOUT | FatalDeployErrors.BLOCK_INCLUSION_TIMEOUT;
417
+ interface ITransferPayload {
418
+ walletType: WalletTypes;
419
+ account: Account;
420
+ signer: Signer;
421
+ details: ITransferDetails;
422
+ passwordProvider: SecretsProvider;
275
423
  }
276
- interface ResubmitResult {
277
- success: boolean;
278
- deployId?: string;
279
- deployStatus?: DeployStatus;
280
- error?: ErrorDetail;
281
- }
282
-
283
- declare class DeployResubmitter {
284
- private readonly config;
285
- private readonly nodeManager;
286
- private readonly errorHandler;
287
- private startSubmissionTime;
288
- constructor(config: ResubmitConfig, availableNodesUrls: string[]);
289
- private isDeployExpired;
290
- private sleep;
291
- private retryDeployToOneNode;
292
- private retryDeployToRandomNodes;
293
- private pollDeployStatus;
294
- /**
295
-
296
- * Main resubmit function
297
- * Executes the complete resubmit algorithm for deploy
298
- * NOT FOR "READ-ONLY" DEPLOYS (exploratory deploys)
299
- */
300
- resubmit(rholangCode: string, wallet: Wallet, passwordProvider: PasswordProvider, phloLimit?: number): Promise<ResubmitResult>;
301
- }
302
-
303
- declare class NodeManager implements NodeProvider {
304
- private static instance;
305
- private retriesLeft;
306
- private readonly availableNodesUrls;
307
- private readonly useRandomNode;
308
- private readonly inactiveNodesUrls;
309
- private currentNodeUrl;
424
+ declare class TransactionService {
425
+ private readonly deployService;
426
+ private readonly blockService;
427
+ constructor(deployService: DeployService, blockService: BlockService);
428
+ private signDeploy;
429
+ transfer({ walletType, account, signer, details, passwordProvider, }: ITransferPayload): Promise<string>;
430
+ }
431
+
432
+ type AddressBrand = {
433
+ readonly __brand: unique symbol;
434
+ };
435
+ type Address = `1111${string & AddressBrand}`;
436
+ interface IWalletOptions {
437
+ id?: string;
438
+ type: WalletTypes;
439
+ signer: Signer;
440
+ accounts: Map<string, Account>;
441
+ activeAccount?: Account;
442
+ }
443
+ type TCreateHDPathWalletOptions = {
444
+ customHDPath: Bip44Path;
445
+ } | {
446
+ index: number;
447
+ };
448
+ interface ICreateHDWalletOptions {
449
+ mnemonic: string;
450
+ pathOptions: TCreateHDPathWalletOptions;
451
+ accountOptions: TCreateAccountPayload;
452
+ }
453
+ interface IRestoreWalletPayload {
454
+ signerRecord: ISignerRecord;
455
+ accountRecords: IAccountRecord[];
456
+ }
457
+ declare class Wallet {
458
+ private readonly id;
459
+ private readonly type;
460
+ private readonly signer;
461
+ private readonly accountManager;
310
462
  private constructor();
311
- static initialize(availableNodesUrls: string[], nodeSelectionAttempts?: number, useRandomNode?: boolean): NodeManager;
312
- connectDefaultNode(): Promise<void>;
313
- private connectNode;
314
- static getInstance(): NodeManager;
315
- isInitialized(): boolean;
316
- private markNodeInactive;
317
- deactivateCurrentNode(): void;
318
- private deactivateNode;
319
- private getAvailableNodesUrls;
320
- getRetriesLeft(): number;
321
- private getRandomAvailableNodeUrl;
322
- connectActiveRandomNode(): Promise<void>;
463
+ getId(): string;
464
+ getType(): WalletTypes;
465
+ getSigner(): Signer;
466
+ getAccounts(): Account[];
467
+ getAccountsMap(): Map<string, Account>;
468
+ getActiveAccount(): Account | null;
469
+ setActiveAccount(id: string): void;
470
+ private getDerivationIndex;
471
+ deriveAccount(payload: Omit<TCreateAccountPayload, "index">, passwordProvider: SecretsProvider): Promise<ICreatedAccountData>;
472
+ removeAccount(id: string): Account;
473
+ updateAccount(id: string, payload: TEditableAccountOptions): void;
474
+ static createPk(accountOptions: TCreateAccountPayload, secretProvider: SecretsProvider): Promise<Wallet>;
475
+ static createHD(options: ICreateHDWalletOptions, passwordProvider: SecretsProvider): Promise<Wallet>;
476
+ static restore(payload: IRestoreWalletPayload, passwordProvider: SecretsProvider): Promise<Wallet>;
477
+ transfer(payload: ITransferDetails, passwordProvider: SecretsProvider): Promise<string>;
323
478
  }
324
479
 
325
- declare class SignerService {
326
- static sign(request: SigningRequest, passwordProvider: PasswordProvider): Promise<SignedResult>;
327
- private static readonly deployDataProtobufSerialize;
480
+ interface IPortfolioOptions {
481
+ assets?: Assets;
482
+ primaryAsset?: Asset;
483
+ }
484
+ interface IAccountOptions {
485
+ id?: string;
486
+ name: string;
487
+ index: number | null;
488
+ address: Address;
489
+ portfolioOptions?: IPortfolioOptions;
490
+ }
491
+ type TEditableAccountOptions = Partial<Pick<IAccountOptions, "name">>;
492
+ type TCreateAccountPayload = Omit<IAccountOptions, "address" | "index"> & {
493
+ index?: number;
494
+ };
495
+ interface IAccountRecord {
496
+ id: string;
497
+ signerId: string;
498
+ name: string;
499
+ index: number | null;
500
+ }
501
+ declare class Account {
502
+ private readonly id;
503
+ private readonly index;
504
+ private readonly address;
505
+ private name;
506
+ private assets;
507
+ private primaryAsset;
508
+ constructor({ id, name, index, portfolioOptions, address, }: IAccountOptions);
509
+ getId(): string;
510
+ getName(): string;
511
+ getIndex(): number | null;
512
+ listAssets(): Asset[];
513
+ getAddress(): Address;
514
+ getAsset(id: Asset["id"]): Asset | null;
515
+ registerAsset(asset: Asset): void;
516
+ setPrimaryAsset(id: Asset["id"]): void;
517
+ static create(accountOptions: TCreateAccountPayload, secretProvider: SecretsProvider): Promise<Account>;
518
+ update(options: TEditableAccountOptions): void;
519
+ getBalance(): Promise<IBalanceData>;
520
+ getTransactionsHistory(networkName?: NetworkName, pagination?: Pagination): Promise<Transaction[]>;
521
+ }
522
+
523
+ interface IStorageFabricOptions {
524
+ nodeStorageDir?: string;
328
525
  }
329
526
 
527
+ declare const ACCOUNTS_DATA_KEY: string;
528
+ interface IPublicWalletRecord extends ITableRecord {
529
+ name: string;
530
+ type: WalletTypes;
531
+ }
532
+ interface IWalletRecordEncryptedFields {
533
+ keyData: string;
534
+ depth: number | null;
535
+ HDPath: string | null;
536
+ }
537
+ interface IFullWalletRecord extends IPublicWalletRecord, ITableRecord {
538
+ encryptedData: EncryptedData;
539
+ createdAt: number;
540
+ updatedAt?: number;
541
+ }
542
+ interface IAccountStorageRecord extends ITableRecord {
543
+ signerId: string;
544
+ name: string;
545
+ index: number | null;
546
+ createdAt: number;
547
+ updatedAt?: number;
548
+ }
549
+ declare class AccountsStorageRepository {
550
+ private static instance;
551
+ private storageInterface;
552
+ private isInitialized;
553
+ private initPromise;
554
+ constructor(options?: IStorageFabricOptions);
555
+ static getInstance(options?: IStorageFabricOptions): AccountsStorageRepository;
556
+ initialize(): Promise<void>;
557
+ private doInitialize;
558
+ private ensureInitialized;
559
+ getRawDB(): ITableService<ITableRecord>;
560
+ saveAccount(accountId: string, signerId: string, name: string, index: number | null): Promise<void>;
561
+ saveAccounts(accounts: IAccountStorageRecord[]): Promise<void>;
562
+ getAccount(id: string): Promise<IAccountStorageRecord | null>;
563
+ getAllAccounts(): Promise<IAccountStorageRecord[]>;
564
+ updateAccount(accountId: string, updates: Partial<IAccountStorageRecord>): Promise<void>;
565
+ deleteAccount(accountId: string): Promise<void>;
566
+ deleteMultipleAccounts(accountIds: string[]): Promise<void>;
567
+ hasAccount(accountId: string): Promise<boolean>;
568
+ getAccountsCount(): Promise<number>;
569
+ clearAllData(): Promise<void>;
570
+ clearTable(tableName: string): Promise<void>;
571
+ isReady(): boolean;
572
+ getTablesList(): Promise<string[]>;
573
+ close(): void;
574
+ }
575
+
576
+ declare class AccountDataService {
577
+ private readonly apiClientManager;
578
+ constructor(apiClientManager?: ApiClientManager);
579
+ getTransactionHistory(address: string, networkName?: NetworkName, pagination?: Pagination): Promise<Transaction[]>;
580
+ }
581
+
582
+ interface IBalanceData {
583
+ amount: bigint;
584
+ asset: Asset;
585
+ }
330
586
  declare class AssetsService {
331
- private getBlockchainGateway;
332
- transfer(fromAddress: Address, toAddress: Address, amount: bigint, wallet: Wallet, passwordProvider: PasswordProvider, phloLimit?: number): Promise<string | undefined>;
333
- getASIBalance(address: Address): Promise<bigint>;
587
+ private readonly deployService;
588
+ constructor(deployService: DeployService);
589
+ getBalance(address: Address, asset: Asset): Promise<IBalanceData>;
590
+ }
591
+
592
+ interface IDeployConfirmedResult {
593
+ deployId: string;
594
+ blockHash?: string;
595
+ }
596
+ interface IDeployWatchCallbacks {
597
+ onConfirmed?: (result: IDeployConfirmedResult) => void;
598
+ onError?: (error: Error) => void;
599
+ onStatus?: (status: IDeployStatusResult, deployId: string) => void;
600
+ }
601
+ interface IDeployWatchOptions {
602
+ intervalMs?: number;
603
+ timeoutMs?: number;
604
+ }
605
+ interface IDeployWatchHandle {
606
+ cancel: () => void;
607
+ done: Promise<IDeployConfirmedResult>;
608
+ }
609
+ declare class DeployStatusPoller {
610
+ private readonly deployService;
611
+ constructor(deployService: DeployService);
612
+ watch(deployId: string, callbacks?: IDeployWatchCallbacks, { intervalMs, timeoutMs, }?: IDeployWatchOptions): IDeployWatchHandle;
613
+ waitFor(deployId: string, options?: IDeployWatchOptions): Promise<IDeployConfirmedResult>;
614
+ }
615
+
616
+ declare class ApiServiceRegistry {
617
+ private static instance;
618
+ readonly deploy: DeployService;
619
+ readonly blocks: BlockService;
620
+ readonly accountData: AccountDataService;
621
+ readonly assets: AssetsService;
622
+ readonly transactions: TransactionService;
623
+ readonly poller: DeployStatusPoller;
624
+ private constructor();
625
+ static getInstance(apiClientManager?: ApiClientManager): ApiServiceRegistry;
334
626
  }
335
627
 
336
628
  declare class BinaryWriterService {
@@ -342,127 +634,404 @@ declare class BinaryWriterService {
342
634
  getResultBuffer(): Uint8Array;
343
635
  }
344
636
 
345
- declare class EncryptedRecord {
346
- private encryptedSeedData;
347
- static createAndEncrypt(data: string, password: string): Promise<EncryptedRecord>;
348
- static createFromEncryptedData(encryptedData: EncryptedData): EncryptedRecord;
349
- static createFromStringifiedEncryptedData(data: string): EncryptedRecord;
350
- private constructor();
351
- decrypt(password: string): Promise<string>;
352
- toString(): string;
637
+ declare class BrowserStorage implements ITableService<ITableRecord> {
638
+ private static instance;
639
+ private readonly name;
640
+ private storageInterface;
641
+ constructor(name?: string);
642
+ static getInstance(name?: string): BrowserStorage;
643
+ init(): Promise<IDBDatabase>;
644
+ createTable(tableName: string, keyPath?: string): Promise<void>;
645
+ insert(tableName: string, record: ITableRecord): Promise<void>;
646
+ insertMany(tableName: string, records: ITableRecord[]): Promise<void>;
647
+ getById(tableName: string, id: string | number): Promise<ITableRecord | null>;
648
+ getAll(tableName: string): Promise<ITableRecord[]>;
649
+ update(tableName: string, id: string | number, data: Partial<ITableRecord>): Promise<void>;
650
+ delete(tableName: string, id: string | number): Promise<void>;
651
+ deleteMany(tableName: string, ids: (string | number)[]): Promise<void>;
652
+ clearTable(tableName: string): Promise<void>;
653
+ dropTable(tableName: string): Promise<void>;
654
+ tableExists(tableName: string): Promise<boolean>;
655
+ getVersion(): number;
656
+ getDatabaseName(): string;
657
+ getTableNamesList(): string[];
658
+ private executeTransaction;
659
+ isInitialized(): boolean;
660
+ close(): Promise<void>;
353
661
  }
354
662
 
355
- type Wallets = Map<Address, Wallet>;
356
- type Seeds = Map<string, EncryptedRecord>;
357
- type VaultRawData = string;
358
- type StoredWalletsMetaRecords = Record<Address, StringifiedWalletMeta>;
359
- type StoredSeedsMetaRecords = Record<string, string>;
360
- declare const DEFAULT_STORAGE_KEY = "0";
361
- declare class Vault {
362
- private static vaultPrefix;
363
- private isLocked;
364
- private wallets;
365
- private seeds;
366
- private encryptedVaultData;
367
- constructor(VaultData?: VaultRawData);
368
- static getSavedVaultKeys(): string[];
369
- static getVaultDataFromStorage(vaultKey: string): VaultRawData | null;
370
- isVaultLocked(): boolean;
371
- save(vaultKey?: string): void;
372
- lock(password: string): Promise<void>;
373
- unlock(password: string): Promise<void>;
374
- isEmpty(): boolean;
375
- getWallets(): Wallet[];
376
- getWalletsCount(): number;
377
- getWalletAddresses(): Address[];
378
- addWallet(wallet: Wallet): void;
379
- removeWallet(address: Address): void;
380
- getWallet(address: Address): Wallet | undefined;
381
- hasWallet(address: Address): boolean;
382
- hasSeed(seedId: string): boolean;
383
- private metaToWallets;
384
- private metaToSeeds;
385
- getSeeds(): EncryptedRecord[];
386
- getSeed(id: string): EncryptedRecord | undefined;
387
- addSeed(id: string, seed: EncryptedRecord): void;
388
- removeSeed(id: string): void;
389
- getSeedsIds(): string[];
390
- toString(): string;
391
- private ensureUnlocked;
392
- private static ensureBrowserEnvironment;
663
+ declare enum MnemonicStrength {
664
+ TWELVE_WORDS = 128,
665
+ TWENTY_FOUR_WORDS = 256
666
+ }
667
+ declare class MnemonicService {
668
+ static generateMnemonic(strength?: MnemonicStrength): string;
669
+ static generateMnemonicArray(strength?: MnemonicStrength): string[];
670
+ static isMnemonicValid(mnemonic: string): boolean;
671
+ static mnemonicToWordArray(mnemonic: string): string[];
672
+ static wordArrayToMnemonic(words: string[]): string;
673
+ static mnemonicToSeed(mnemonic: string | string[], passphrase?: string): Promise<Uint8Array>;
674
+ }
675
+
676
+ interface IAccountMetadata {
677
+ id: string;
678
+ name: string;
679
+ index: number | null;
680
+ }
681
+ interface IWalletMetadata {
682
+ signerId: string;
683
+ type: WalletTypes;
684
+ accounts: IAccountMetadata[];
685
+ }
686
+ interface ICreateHDWalletParams {
687
+ mnemonic: string;
688
+ accountName: string;
689
+ index?: number;
690
+ }
691
+ interface IDerivedAccount {
692
+ accountId: string;
693
+ account: Account;
694
+ }
695
+ declare class WalletManager extends ItemManager<Wallet> {
696
+ createHD({ mnemonic, accountName, index }: ICreateHDWalletParams, passwordProvider: SecretsProvider): Promise<Wallet>;
697
+ createPrivateKey(accountName: string, secretProvider: SecretsProvider): Promise<Wallet>;
698
+ unlock(signerId: string, passwordProvider: SecretsProvider): Promise<Wallet>;
699
+ delete(id: string): Promise<Wallet>;
700
+ deriveAccount(walletId: string, accountName: string, passwordProvider: SecretsProvider): Promise<IDerivedAccount>;
701
+ removeAccount(walletId: string, accountId: string): Promise<Account>;
702
+ renameAccount(walletId: string, accountId: string, name: string): Promise<void>;
703
+ setActiveAccount(walletId: string, accountId: string): void;
704
+ getPublicWalletsMetadata(): Promise<IWalletMetadata[]>;
705
+ count(): Promise<number>;
706
+ countInStorage(): Promise<number>;
707
+ private persist;
708
+ }
709
+
710
+ interface IInsensitiveCacheRecord extends ITableRecord {
711
+ address: string;
393
712
  }
394
713
 
395
- interface ClientOptions {
396
- vault?: Vault;
397
- password?: string;
714
+ interface IUnlockedWallet {
715
+ id: string;
716
+ signerId: string;
717
+ type: WalletTypes;
718
+ accounts: Account[];
719
+ activeAccountId: string | null;
720
+ }
721
+ interface ICreateHDWalletPayload {
722
+ mnemonic: string;
723
+ accountName: string;
724
+ index?: number;
725
+ }
726
+ interface ICreatePrivateKeyWalletPayload {
727
+ privateKey: Uint8Array;
728
+ accountName: string;
729
+ }
730
+ interface ITransferRequest {
731
+ walletId: string;
732
+ accountId: string;
733
+ to: Address;
734
+ amount: bigint;
735
+ }
736
+ interface IClientEventDispatcher {
737
+ onWalletsChanged?(wallets: Wallet[]): void;
738
+ onAccountsChanged?(walletId: string, accounts: Account[]): void;
739
+ onNetworkChanged?(networkName: NetworkName): void;
740
+ onReservationsChanged?(walletId: string, reservations: ITransactionReservation[]): void;
741
+ }
742
+ interface ICreateClientFlags {
743
+ withInsensitiveCacheStorage?: boolean;
744
+ }
745
+ interface ICreateClientOptions {
746
+ networksConfig: TNetworksConfig;
747
+ defaultNetwork?: NetworkName;
748
+ storageOptions?: IStorageFabricOptions;
749
+ eventDispatcher?: IClientEventDispatcher;
750
+ flags?: ICreateClientFlags;
398
751
  }
399
752
  declare class Client {
400
- private readonly vault;
401
- private activeWalletAddress?;
753
+ private readonly walletManager;
754
+ private readonly reservationAdapterManager;
755
+ private readonly eventDispatcher?;
756
+ private readonly flags?;
402
757
  private constructor();
403
- static create(options?: ClientOptions): Promise<Client>;
404
- createWallet(name: string, privateKey: Uint8Array, password: string): Promise<Wallet>;
405
- selectActiveWallet(walletAddress: Address): boolean;
406
- getActiveWallet(): Wallet | undefined;
407
- getWallets(): Wallet[];
758
+ static create({ networksConfig, defaultNetwork, storageOptions, eventDispatcher, flags, }: ICreateClientOptions): Promise<Client>;
759
+ getWalletManager(): WalletManager;
760
+ getInsensitiveAccountsData(): Promise<IInsensitiveCacheRecord[]>;
761
+ clearPersistence(): Promise<void>;
762
+ close(): void;
763
+ generateMnemonic(strength?: MnemonicStrength): string;
764
+ generatePrivateKey(): Uint8Array;
765
+ createHDWallet({ mnemonic, accountName, index }: ICreateHDWalletPayload, password: string): Promise<Wallet>;
766
+ createPrivateKeyWallet({ privateKey, accountName }: ICreatePrivateKeyWalletPayload, password: string): Promise<Wallet>;
767
+ removeWallet(walletId: string): Promise<void>;
768
+ unlockWallet(signerId: string, password: string): Promise<Wallet>;
769
+ deriveAccount(walletId: string, accountName: string, password: string): Promise<ICreatedAccountData>;
770
+ removeAccount(walletId: string, accountId: string): Promise<void>;
771
+ renameAccount(walletId: string, accountId: string, name: string): Promise<void>;
772
+ setActiveAccount(walletId: string, accountId: string): void;
773
+ getNetworksNames(): NetworkName[];
774
+ getCurrentNetwork(): NetworkName;
775
+ setNetwork(networkName: NetworkName): void;
776
+ getBalance(address: Address): Promise<bigint>;
777
+ getAvailableBalance(walletId: string, accountId: string): Promise<bigint>;
778
+ getReservations(walletId: string): Promise<ITransactionReservation[]>;
779
+ transfer({ walletId, accountId, to, amount }: ITransferRequest, password: string): Promise<string>;
780
+ toDisplayAmount(atomicAmount: bigint): string;
781
+ toAtomicAmount(amount: number | string): bigint;
782
+ private getUnlockedWallet;
783
+ private getAccount;
784
+ private createPasswordProvider;
785
+ private emitAccountsChanged;
786
+ private emitWalletsChanged;
408
787
  }
409
788
 
410
- interface HttpClient {
411
- get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
412
- post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
413
- getBaseUrl(): string | undefined;
789
+ declare class NetworkConfigProvider {
790
+ private networksConfig;
791
+ initialize(config: TNetworksConfig): void;
792
+ get(network: NetworkName): INetworkConfig;
793
+ getNetworkNames(): NetworkName[];
794
+ isReady(): boolean;
414
795
  }
415
- declare class AxiosHttpClient implements HttpClient {
416
- private readonly client;
417
- constructor(client: AxiosInstance);
418
- get<T>(url: string): Promise<T>;
419
- post<T>(url: string, data?: any): Promise<T>;
420
- getBaseUrl(): string | undefined;
421
- }
422
-
423
- interface Storage {
424
- write: (id: string, data: string) => void;
425
- read: (id: string) => string | null;
426
- delete: (id: string) => void;
427
- has: (id: string) => boolean;
428
- isEmpty: () => boolean;
429
- clear: () => void;
430
- }
431
- declare class BrowserStorage implements Storage {
432
- private prefix;
433
- constructor(prefix?: string);
434
- write(id: string, data: string): void;
435
- read(id: string): string | null;
436
- delete(id: string): void;
437
- has(id: string): boolean;
438
- isEmpty(): boolean;
796
+
797
+ declare class NodeStorage implements ITableService<ITableRecord> {
798
+ private static instance;
799
+ private readonly storageDir;
800
+ private storageInterface;
801
+ constructor(storageDir?: string);
802
+ static getInstance(storageDir?: string): NodeStorage;
803
+ init(): Promise<void>;
804
+ private getTableKey;
805
+ private getTable;
806
+ private saveTable;
807
+ createTable(tableName: string, _keyPath: string): Promise<void>;
808
+ insert(tableName: string, record: ITableRecord): Promise<void>;
809
+ insertMany(tableName: string, records: ITableRecord[]): Promise<void>;
810
+ getById(tableName: string, id: string | number): Promise<ITableRecord | null>;
811
+ getAll(tableName: string): Promise<ITableRecord[]>;
812
+ update(tableName: string, id: string | number, data: Partial<ITableRecord>): Promise<void>;
813
+ delete(tableName: string, id: string | number): Promise<void>;
814
+ deleteMany(tableName: string, ids: (string | number)[]): Promise<void>;
815
+ clearTable(tableName: string): Promise<void>;
816
+ dropTable(tableName: string): Promise<void>;
817
+ isInitialized(): boolean;
818
+ getKeys(): Promise<string[]>;
819
+ tableExists(tableName: string): Promise<boolean>;
820
+ close(): Promise<void>;
821
+ }
822
+
823
+ declare const SIGNERS_DATA_KEY: string;
824
+ interface IPrivateKeySignerEncryptedFields {
825
+ keyData: Uint8Array;
826
+ }
827
+ interface IHDSignerEncryptedFields {
828
+ seed: string;
829
+ rootHDPath: string;
830
+ }
831
+ interface ISignerStorageRecord extends ITableRecord {
832
+ type: WalletTypes;
833
+ encryptedData: EncryptedData;
834
+ createdAt: number;
835
+ updatedAt?: number;
836
+ }
837
+ declare class SignersStorageRepository {
838
+ private static instance;
839
+ private storageInterface;
840
+ private isInitialized;
841
+ private initPromise;
842
+ constructor(options?: IStorageFabricOptions);
843
+ static getInstance(options?: IStorageFabricOptions): SignersStorageRepository;
844
+ initialize(): Promise<void>;
845
+ private doInitialize;
846
+ private ensureInitialized;
847
+ getRawDB(): ITableService<ITableRecord>;
848
+ saveSigner(signerId: string, type: WalletTypes, encryptedData: EncryptedData): Promise<void>;
849
+ getSigner(id: string): Promise<ISignerStorageRecord | null>;
850
+ getAllSigners(): Promise<ISignerStorageRecord[]>;
851
+ updateSigner(signerId: string, updates: Partial<ISignerStorageRecord>): Promise<void>;
852
+ deleteSigner(signerId: string): Promise<void>;
853
+ deleteMultipleSigners(signerIds: string[]): Promise<void>;
854
+ hasSigner(signerId: string): Promise<boolean>;
855
+ getSignersCount(): Promise<number>;
856
+ clearAllData(): Promise<void>;
857
+ clearTable(tableName: string): Promise<void>;
858
+ isReady(): boolean;
859
+ getTablesList(): Promise<string[]>;
860
+ close(): void;
861
+ }
862
+
863
+ declare const TRANSACTION_RESERVATIONS_DATA_KEY: string;
864
+ interface ITransactionReservationsStorageRecord extends ITableRecord {
865
+ networkName: NetworkName;
866
+ signerId: string;
867
+ encryptedData: EncryptedData;
868
+ createdAt: number;
869
+ updatedAt?: number;
870
+ }
871
+ declare class TransactionReservationsStorageRepository {
872
+ private static instance;
873
+ private storageInterface;
874
+ private isInitialized;
875
+ private initPromise;
876
+ constructor(options?: IStorageFabricOptions);
877
+ static getInstance(options?: IStorageFabricOptions): TransactionReservationsStorageRepository;
878
+ initialize(): Promise<void>;
879
+ private doInitialize;
880
+ private ensureInitialized;
881
+ getRawDB(): ITableService<ITableRecord>;
882
+ saveTransactionReservation(id: string, networkName: NetworkName, signerId: string, encryptedData: EncryptedData): Promise<void>;
883
+ getTransactionReservations(id: string): Promise<ITransactionReservationsStorageRecord | null>;
884
+ getAllTransactionReservations(): Promise<ITransactionReservationsStorageRecord[]>;
885
+ updateTransactionReservation(id: string, updates: Partial<ITransactionReservationsStorageRecord>): Promise<void>;
886
+ deleteTransactionReservation(id: string): Promise<void>;
887
+ deleteMultipleTransactionReservations(ids: string[]): Promise<void>;
888
+ hasTransactionReservations(id: string): Promise<boolean>;
889
+ getTransactionReservationsCount(): Promise<number>;
890
+ clearAllData(): Promise<void>;
891
+ clearTable(tableName: string): Promise<void>;
892
+ isReady(): boolean;
893
+ getTablesList(): Promise<string[]>;
894
+ close(): void;
895
+ }
896
+
897
+ interface IDisposable {
898
+ dispose(): void;
899
+ }
900
+ declare class DisposableItemManager<T extends IDisposable> extends ItemManager<T> {
901
+ add(id: string, item: T): void;
902
+ remove(id: string): T;
439
903
  clear(): void;
440
- private getIds;
441
- private createKey;
442
904
  }
443
905
 
444
- interface WalletClientConfig {
445
- mode: string;
906
+ interface ITransactionReservationsManagerOptions {
907
+ onConfirmed?: (reservation: ITransactionReservation) => void;
908
+ onExpired?: (reservation: ITransactionReservation) => void;
909
+ onFailed?: (reservation: ITransactionReservation, error: Error) => void;
910
+ watchCallbacks?: IDeployWatchCallbacks;
911
+ watchOptions?: IDeployWatchOptions;
446
912
  }
447
- declare enum WalletClientModes {
448
- LOCAL = "local",
449
- MPC = "mpc"
913
+
914
+ declare class ReservationAdapter {
915
+ private readonly reservationsManager;
916
+ constructor(reservations: ITransactionReservation[], reservationsManagerOptions?: Omit<ITransactionReservationsManagerOptions, "onConfirmed" | "onExpired">);
917
+ static create(wallet: Wallet, passwordProvider: SecretsProvider, reservationsManagerOptions?: Omit<ITransactionReservationsManagerOptions, "onConfirmed" | "onExpired">): Promise<ReservationAdapter>;
918
+ private getReservedAmount;
919
+ getBalance(account: Account): Promise<IBalanceData>;
920
+ getReservations(): ITransactionReservation[];
921
+ dispose(): void;
922
+ private persistReservation;
923
+ validateSufficientBalance(account: Account, amount: bigint): Promise<boolean>;
924
+ transfer(wallet: Wallet, details: ITransferDetails, passwordProvider: SecretsProvider): Promise<string>;
450
925
  }
451
- declare const DEFAULT_CLIENT_CONFIG: WalletClientConfig;
452
- declare const DEFAULT_AXIOS_TIMEOUT_MS: number;
453
- declare const MAX_WALLETS_PER_ACCOUNT: number;
454
- declare const DEFAULT_DECIMALS_AMOUNT: number;
455
- declare const DEFAULT_PHLO_LIMIT: number;
456
- declare const DEFAULT_RESUBMIT_CONFIG: ResubmitConfig;
457
926
 
458
- declare const encodeBase58: (hex: string) => string;
459
- declare const decodeBase58: (value: string) => Uint8Array;
460
- declare const decodeBase16: (hex: string) => Uint8Array;
461
- declare const encodeBase16: (bytes: Uint8Array) => string;
462
- declare const arrayBufferToBase64: (buffer: ArrayBuffer) => string;
463
- declare const base64ToArrayBuffer: (base64: string) => ArrayBuffer;
464
- declare const bufferToBigInt: (buffer: Uint8Array) => bigint;
465
- declare const bigIntToBuffer: (num: bigint) => Uint8Array;
927
+ declare class ReservationAdapterManager extends DisposableItemManager<ReservationAdapter> {
928
+ create(wallet: Wallet, passwordProvider: SecretsProvider): Promise<ReservationAdapter>;
929
+ }
930
+
931
+ declare class KeyDerivationService {
932
+ static deriveKeyFromMnemonic(mnemonic: string | string[], bip44path: string | Bip44Path): Promise<Uint8Array>;
933
+ static derivePrivateKey(masterNode: BIP32Interface, path: Bip44Path): Uint8Array;
934
+ static mnemonicToSeed(mnemonicWords: string[] | string, passphrase?: string): Promise<Uint8Array>;
935
+ static seedToMasterNode(seed: any): BIP32Interface;
936
+ static deriveNextKeyFromMnemonic(mnemonicWords: string[], currentIndex: number, options?: Omit<IBip44PathOptions, "index">): Promise<Uint8Array>;
937
+ }
938
+
939
+ type KeyPair = {
940
+ privateKey: Uint8Array;
941
+ publicKey: Uint8Array;
942
+ };
943
+ interface IBaseHDWalletPrivateKeyData {
944
+ path: Bip44Path;
945
+ privateKey: Uint8Array;
946
+ }
947
+ interface IHDWalletPrivateKeyDataFromMnemonic extends IBaseHDWalletPrivateKeyData {
948
+ seed: Uint8Array;
949
+ }
950
+ interface IHDWalletPrivateKeyDataFromSeed extends IBaseHDWalletPrivateKeyData {
951
+ index: number;
952
+ }
953
+ declare class KeysManager {
954
+ static generateRandomKey(length?: number): Uint8Array;
955
+ static generateKeyPair(keyLength?: number): KeyPair;
956
+ static getKeyPairFromPrivateKey(privateKey: Uint8Array): KeyPair;
957
+ static getPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
958
+ static convertKeyToHex(key: Uint8Array): string;
959
+ static getInitialHDPathFromOptions(hdWalletOptions: TCreateHDPathWalletOptions): Promise<Bip44Path>;
960
+ static getPrivateDataFromSeed(seed: Uint8Array, path: Bip44Path): Promise<IHDWalletPrivateKeyDataFromSeed>;
961
+ }
962
+
963
+ interface ISaveSignerToStorageOptions {
964
+ id: string;
965
+ type: WalletTypes;
966
+ signer: Signer;
967
+ }
968
+ interface ISaveAccountToStorageOptions {
969
+ id: string;
970
+ account: Account;
971
+ signerId: string;
972
+ }
973
+ interface ISaveWalletToStorageOptions {
974
+ signerId: string;
975
+ wallet: Wallet;
976
+ }
977
+ interface IGetWalletFromStorageOptions {
978
+ signerId: string;
979
+ passwordProvider: SecretsProvider;
980
+ }
981
+ interface IWalletStorageData {
982
+ signer: ISignerRecord;
983
+ accounts: IAccountRecord[];
984
+ }
985
+ interface ISaveTransactionReservationsOptions {
986
+ id: string;
987
+ networkName: NetworkName;
988
+ signerId: string;
989
+ encryptedData: EncryptedData;
990
+ }
991
+ declare class StorageManager {
992
+ static init: (options?: IStorageFabricOptions) => Promise<void>;
993
+ static saveSigner: ({ id, type, signer, }: ISaveSignerToStorageOptions) => Promise<void>;
994
+ static saveSigners: (signersOptions: ISaveSignerToStorageOptions[]) => Promise<void[]>;
995
+ static getSigner: (id: string) => Promise<ISignerRecord>;
996
+ static getSigners: () => Promise<ISignerRecord[]>;
997
+ static updateSigner: (id: string, updates: Partial<ISignerRecord>) => Promise<void>;
998
+ static deleteSigner: (id: string) => Promise<void>;
999
+ static deleteMultipleSigners: (ids: string[]) => Promise<void>;
1000
+ static saveAccount: ({ id, account, signerId, }: ISaveAccountToStorageOptions) => Promise<void>;
1001
+ static saveAccounts: (accountsOptions: ISaveAccountToStorageOptions[]) => Promise<void>;
1002
+ static getAccount: (id: string) => Promise<IAccountRecord>;
1003
+ static getAccounts: () => Promise<IAccountRecord[]>;
1004
+ static updateAccount: (id: string, updates: Partial<IAccountRecord>) => Promise<void>;
1005
+ static deleteAccount: (id: string) => Promise<void>;
1006
+ static deleteMultipleAccounts: (ids: string[]) => Promise<void>;
1007
+ static saveWallet: ({ signerId, wallet, }: ISaveWalletToStorageOptions) => Promise<void>;
1008
+ static saveWallets: (walletsOptions: ISaveWalletToStorageOptions[]) => Promise<void[]>;
1009
+ static getWallet: ({ signerId, passwordProvider, }: IGetWalletFromStorageOptions) => Promise<Wallet>;
1010
+ static getWallets: () => Promise<IWalletStorageData[]>;
1011
+ static saveTransactionReservation: ({ id, networkName, signerId, encryptedData, }: ISaveTransactionReservationsOptions) => Promise<void>;
1012
+ static getTransactionReservationsBySignerId: (signerId: string, networkName: NetworkName) => Promise<ITransactionReservationsStorageRecord[]>;
1013
+ static updateTransactionReservation: (id: string, updates: Partial<ITransactionReservationsStorageRecord>) => Promise<void>;
1014
+ static deleteTransactionReservation: (id: string) => Promise<void>;
1015
+ static deleteMultipleTransactionReservations: (ids: string[]) => Promise<void>;
1016
+ static clear: () => Promise<void>;
1017
+ static close: () => void;
1018
+ }
1019
+
1020
+ interface CreateWalletOptions {
1021
+ name?: string;
1022
+ }
1023
+ interface WalletMeta {
1024
+ address: string;
1025
+ privateKey: Uint8Array;
1026
+ publicKey?: Uint8Array;
1027
+ mnemonic?: string;
1028
+ }
1029
+ declare class WalletsService {
1030
+ static createWallet(privateKey?: Uint8Array, options?: CreateWalletOptions): WalletMeta;
1031
+ static createFirstWalletWithMnemonic(mnemonic?: string, index?: number): Promise<WalletMeta>;
1032
+ static deriveAddressFromPrivateKey(privateKey: Uint8Array): Address;
1033
+ static deriveAddressFromPublicKey(publicKey: Uint8Array): Address;
1034
+ }
466
1035
 
467
1036
  declare const PRIVATE_KEY_LENGTH = 32;
468
1037
  declare const ASI_CHAIN_PREFIX: {
@@ -471,13 +1040,6 @@ declare const ASI_CHAIN_PREFIX: {
471
1040
  };
472
1041
  declare const ASI_COIN_TYPE = 60;
473
1042
  declare const ASI_DECIMALS = 8;
474
- declare const GasFee: {
475
- BASE_FEE: number;
476
- VARIATION_RANGE: number;
477
- LABEL: string;
478
- TRANSFER: string;
479
- DEPLOY: string;
480
- };
481
1043
  declare const HEX_RADIX: number;
482
1044
  declare const HEX_BYTE_PADDING: number;
483
1045
  declare const POWER_BASE: number;
@@ -491,14 +1053,34 @@ declare const DEFAULT_BIP_44_PATH_OPTIONS: {
491
1053
  index: number;
492
1054
  };
493
1055
 
494
- declare const toAtomicAmount: (amount: number | string) => bigint;
495
- declare const fromAtomicAmountToString: (atomicAmount: bigint) => string;
496
- declare const fromAtomicAmountToNumber: (atomicAmount: bigint) => number;
497
- declare const fromAtomicAmount: (atomicAmount: bigint) => string;
498
- declare const genRandomHex: (size: number) => string;
499
-
500
1056
  declare const setupBufferPolyfill: () => void;
501
1057
 
1058
+ declare const encodeBase58: (hex: string) => string;
1059
+ declare const decodeBase58: (value: string) => Uint8Array;
1060
+ declare const decodeBase16: (hex: string) => Uint8Array;
1061
+ declare const encodeBase16: (bytes: Uint8Array) => string;
1062
+ declare const arrayBufferToBase64: (buffer: ArrayBuffer) => string;
1063
+ declare const base64ToArrayBuffer: (base64: string) => ArrayBuffer;
1064
+ declare const bufferToBigInt: (buffer: Uint8Array) => bigint;
1065
+ declare const bigIntToBuffer: (num: bigint) => Uint8Array;
1066
+
1067
+ declare const genRandomHex: (size: number) => string;
1068
+ declare const generateRandomId: () => string;
1069
+ declare const toAtomicAmount: (amount: number | string, decimals: number) => bigint;
1070
+ declare const fromAtomicAmountToNumber: (atomicAmount: bigint, decimals: number) => number;
1071
+ declare const fromAtomicAmount: (atomicAmount: bigint, decimals: number) => string;
1072
+ declare const toUint8Array: (value: unknown) => Uint8Array;
1073
+ type IUrlValue = string | number | boolean | undefined;
1074
+ interface IUrlParams {
1075
+ path?: Record<string, IUrlValue>;
1076
+ query?: Record<string, IUrlValue | undefined | null>;
1077
+ }
1078
+ declare const buildUrl: (pathPrefix: string, params?: IUrlParams) => string;
1079
+ /**
1080
+ * @returns address in the format accepted within the SDK application
1081
+ */
1082
+ declare function normalizeAddress(address: string | undefined): string;
1083
+
502
1084
  declare const validateAccountName: (name: string, maxLength?: number) => {
503
1085
  isValid: boolean;
504
1086
  error?: string;
@@ -520,5 +1102,5 @@ interface AddressValidationResult {
520
1102
  declare const validateAddress: (address: string) => AddressValidationResult;
521
1103
  declare const isAddress: (address: string) => address is Address;
522
1104
 
523
- export { ASI_BASE_UNIT, ASI_CHAIN_PREFIX, ASI_COIN_TYPE, ASI_DECIMALS, AddressValidationErrorCode, Asset, AssetsService, AxiosHttpClient, BinaryWriterService as BinaryWriter, BlockchainGateway, Client, CryptoService, DEFAULT_AXIOS_TIMEOUT_MS, DEFAULT_BIP_44_PATH_OPTIONS, DEFAULT_CLIENT_CONFIG, DEFAULT_DECIMALS_AMOUNT, DEFAULT_PHLO_LIMIT, DEFAULT_RESUBMIT_CONFIG, DEFAULT_STORAGE_KEY, DeployResubmitter, DeployStatus, DeploymentErrorHandler, EncryptedRecord, FAULT_TOLERANCE_THRESHOLD, FatalDeployErrors, FeeService, GasFee, HEX_BYTE_PADDING, HEX_RADIX, INVALID_BLOCK_NUMBER, KeyDerivationService, KeysManager, MAX_WALLETS_PER_ACCOUNT, MnemonicService, MnemonicStrength, POWER_BASE, PRIVATE_KEY_LENGTH, RecoverableDeployErrors, NodeManager as ResubmitNodeManager, BrowserStorage as SecureStorage, SignerService, Vault, Wallet, WalletClientModes, WalletMemoryKeys, WalletsService, arrayBufferToBase64, base64ToArrayBuffer, bigIntToBuffer, bufferToBigInt, decodeBase16, decodeBase58, deploymentErrorMessages, encodeBase16, encodeBase58, fromAtomicAmount, fromAtomicAmountToNumber, fromAtomicAmountToString, genRandomHex, getDeploymentErrorMessage, isAddress, setupBufferPolyfill, toAtomicAmount, validateAccountName, validateAddress };
524
- export type { Address, AddressValidationResult, AssetId, Assets, Bip44PathOptions, BlockchainGatewayConfig, ClientOptions, CreateWalletOptions, CryptoConfig, DeployStatusResult, DeploymentErrorType, EncryptedData, HttpClient, KeyPair, PasswordProvider, ResubmitConfig, ResubmitResult, Seeds, SignedResult, SigningCapability, SigningRequest, StoredSeedsMetaRecords, StoredWalletMeta, StoredWalletsMetaRecords, StringifiedWalletMeta, VaultRawData, WalletClientConfig, WalletMemory, WalletMeta, Wallets };
1105
+ export { ACCOUNTS_DATA_KEY, ASI_BASE_UNIT, ASI_CHAIN_PREFIX, ASI_COIN_TYPE, ASI_DECIMALS, Account, AccountDataService, AccountManager, AccountsStorageRepository, AddressValidationErrorCode, ApiClientManager, ApiServiceRegistry, Asset, AssetsService, BaseGraphQLClient, BaseHttpClient, BinaryWriterService as BinaryWriter, Bip44Path, BlockService, BrowserStorage, Client, CryptoService as Crypto, DEFAULT_ASSET, DEFAULT_BIP_44_PATH_OPTIONS, DEFAULT_NODE_STORAGE_DIR, DEFAULT_PHLO_LIMIT, DEFAULT_PHLO_PRICE, DEPLOY_STATUS_POLLING_TIMEOUT, DeployService, DeployStatus, DeployStatusPoller, DisposableItemManager, FAULT_TOLERANCE_THRESHOLD, GasFee, HEX_BYTE_PADDING, HEX_RADIX, INVALID_BLOCK_NUMBER, IndexerClient, ItemManager, KeyDerivationService as KeyDerivation, KeysManager, MnemonicService as Mnemonic, MnemonicStrength, NATIVE_TOKEN_DECIMALS_AMOUNT, NetworkConfigProvider, NodeStorage, ObserverClient, POWER_BASE, PRIVATE_KEY_LENGTH, RESERVATION_EXPIRATION_TIME, ReservationAdapterManager, SIGNERS_DATA_KEY, SecretsProvider, Signer, SignerService, SignersStorageRepository, StorageManager, TRANSACTION_RESERVATIONS_DATA_KEY, TransactionReservationsStorageRepository, TransactionService, ValidatorClient, Wallet, WalletManager, WalletTypes, WalletsService as Wallets, arrayBufferToBase64, base64ToArrayBuffer, bigIntToBuffer, bufferToBigInt, buildUrl, decodeBase16, decodeBase58, encodeBase16, encodeBase58, fromAtomicAmount, fromAtomicAmountToNumber, genRandomHex, generateRandomId, isAddress, normalizeAddress, setupBufferPolyfill, toAtomicAmount, toUint8Array, validateAccountName, validateAddress };
1106
+ export type { Address, AddressValidationResult, AssetId, Assets, CreateWalletOptions, CryptoConfig, DeployData, EncryptedData, IAccountHDData, IAccountMetadata, IAccountOptions, IAccountRecord, IAccountStorageRecord, IApiClients, IAssetOptions, IBalanceData, IBalanceResponse, IBaseHDWalletPrivateKeyData, IBip44PathOptions, IBlockDto, IClientEventDispatcher, ICreateClientFlags, ICreateClientOptions, ICreateHDWalletOptions, ICreateHDWalletParams, ICreateHDWalletPayload, ICreatePrivateKeyWalletPayload, ICreatedAccountData, IDeployConfirmedResult, IDeployStatusResult, IDeployWatchCallbacks, IDeployWatchHandle, IDeployWatchOptions, IDerivedAccount, IDisposable, IFullWalletRecord, IGetBlocksParams, IGetWalletFromStorageOptions, IHDSecret, IHDSecretRecord, IHDSignerEncryptedFields, IHDWalletPrivateKeyDataFromMnemonic, IHDWalletPrivateKeyDataFromSeed, INetworkConfig, IPasswordCredentials, IPortfolioOptions, IPrivateKeyCredentials, IPrivateKeySignerEncryptedFields, IPrivateKeyWithCredentials, IPublicWalletRecord, IRestoreWalletPayload, ISaveAccountToStorageOptions, ISaveSignerToStorageOptions, ISaveTransactionReservationsOptions, ISaveWalletToStorageOptions, ISeedCredentials, ISignedMessageResponse, ISignerOptions, ISignerRecord, ISignerStorageRecord, ITableRecord, ITableService, ITransactionReservation, ITransactionReservationPrivateData, ITransactionReservationsStorageRecord, ITransferDetails, ITransferPayload, ITransferRequest, IUnlockedWallet, IUrlParams, IUrlValue, IWalletMetadata, IWalletOptions, IWalletRecordEncryptedFields, IWalletStorageData, KeyPair, NetworkName, SignedResult, SigningRequest, TAxiosClientConfig, TBlocksView, TCreateAccountPayload, TCreateHDPathWalletOptions, TEditableAccountOptions, THDSigningContext, TNetworksConfig, TPKSigningContext, TSecretsProviderInterface, TSigningContext, Transaction, WalletMeta };