/
mustreets
/
CreateTransactions
Обзор
Документация
Войти
/
mustreets
/
CreateTransactions
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
libJS/wallet/types.ts
99 строк
3 KB
Slava
Initialize project with essential configurations and structures
14 май 2026, 22:23
14 май 2026, 22:23
a89cd26
Код
Авторство
О чём код?
import type { Reporter } from "../services/Reporting"; /** Асинхронный источник строки (баланс, газ, ключ из хранилища и т.д.). */ export type ProviderAsyncSource = () => Promise<string>; /** Сборка провайдера из конфигурации (configuration-driven). */ export type ProviderConfig = { type: "software" | "hardware"; sources: { balance: ProviderAsyncSource; gas: ProviderAsyncSource; pk: ProviderAsyncSource; sk: ProviderAsyncSource; }; }; // выбрать какой кошелек использовать для входа export enum Wallet { CEX_WALLET = "cex_wallet", HARDWARE_WALLET = "hardware_wallet", SOFTWARE_WALLET = "software_wallet", } export interface IValueTransfer { value: string; addressTo: string; addressFrom: string; chainId: string; gasLimit: [string]; currencyChain: string; currencyAmount: string; currencyFee: string; } export interface ICipherTransaction { header: { nonce: number; timestamp: number; }; body: { value: IValueTransfer }; signature: string; publicKey: string; id: string; payloadHash: string; expiresAt: number; } export interface IKeyProvider { getPrivateKey(): Promise<string>; getPublicKey(): Promise<string>; getBalance(address: string): Promise<string>; estimateGasPrice(): Promise<string>; } /** * Общая реализация баланса/газа и единая точка аудита доступа к секрету (getPrivateKey). * Конкретные провайдеры реализуют только loadPrivateKey / getPublicKey. */ export abstract class BaseKeyProvider implements IKeyProvider { protected readonly fetchBalance: ProviderAsyncSource; protected readonly fetchGasPrice: ProviderAsyncSource; protected readonly reporter?: Reporter; public constructor( fetchBalance: ProviderAsyncSource, fetchGasPrice: ProviderAsyncSource, reporter?: Reporter, ) { this.fetchBalance = fetchBalance; this.fetchGasPrice = fetchGasPrice; this.reporter = reporter; } public async getBalance(_address: string): Promise<string> { return await this.fetchBalance(); } public async estimateGasPrice(): Promise<string> { return await this.fetchGasPrice(); } public abstract getPublicKey(): Promise<string>; public async getPrivateKey(): Promise<string> { this.reporter?.track("security_access_sk", { provider: this.constructor.name, timestamp: Date.now(), }); return await this.loadPrivateKey(); } protected abstract loadPrivateKey(): Promise<string>; } export interface ITransactionSnapshot { readonly value: IValueTransfer; readonly wallet: Wallet; readonly timestamp: number; readonly transaction_id: string; readonly payloadHash: string; readonly expiresAt: number; }