/
mustreets
/
CreateTransactions
Обзор
Документация
Войти
/
mustreets
/
CreateTransactions
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
libJS/wallet/provider.ts
70 строк
2 KB
Slava
Initialize project with essential configurations and structures
14 май 2026, 22:23
14 май 2026, 22:23
a89cd26
Код
Авторство
О чём код?
import type { Reporter } from "../services/Reporting"; import { BaseKeyProvider, type IKeyProvider, type ProviderAsyncSource, type ProviderConfig, } from "./types"; /** Собирает провайдер ключа по конфигу и опционально подключает аудит безопасности. */ export class KeyProviderFactory { public static create(config: ProviderConfig, reporter?: Reporter): IKeyProvider { const { balance, gas, pk, sk } = config.sources; if (config.type === "hardware") { return new HardwareKeyProvider(balance, gas, pk, sk, reporter); } return new StorageKeyProvider(balance, gas, pk, sk, reporter); } } // Для CEX и Software export class StorageKeyProvider extends BaseKeyProvider { private readonly getStoragePublicKey: ProviderAsyncSource; private readonly getStoragePrivateKey: ProviderAsyncSource; public constructor( fetchBalance: ProviderAsyncSource, fetchGasPrice: ProviderAsyncSource, getStoragePublicKey: ProviderAsyncSource, getStoragePrivateKey: ProviderAsyncSource, reporter?: Reporter, ) { super(fetchBalance, fetchGasPrice, reporter); this.getStoragePublicKey = getStoragePublicKey; this.getStoragePrivateKey = getStoragePrivateKey; } public async getPublicKey(): Promise<string> { return await this.getStoragePublicKey(); } protected async loadPrivateKey(): Promise<string> { return await this.getStoragePrivateKey(); } } // Для Hardware (NFC/Bluetooth/QR) export class HardwareKeyProvider extends BaseKeyProvider { private readonly getHardwarePublicKey: ProviderAsyncSource; private readonly getHardwarePrivateKey: ProviderAsyncSource; public constructor( fetchBalance: ProviderAsyncSource, fetchGasPrice: ProviderAsyncSource, getHardwarePublicKey: ProviderAsyncSource, getHardwarePrivateKey: ProviderAsyncSource, reporter?: Reporter, ) { super(fetchBalance, fetchGasPrice, reporter); this.getHardwarePublicKey = getHardwarePublicKey; this.getHardwarePrivateKey = getHardwarePrivateKey; } public async getPublicKey(): Promise<string> { return await this.getHardwarePublicKey(); } protected async loadPrivateKey(): Promise<string> { return await this.getHardwarePrivateKey(); } }