import { UI_REQUEST } from '../../constants/ui-request'; import { validatePath } from '../helpers/pathUtils'; import { BaseMethod } from '../BaseMethod'; import { validateParams } from '../helpers/paramsValidator'; import { formatAnyHex } from '../helpers/hexUtils'; import type { NearSignTx as HardwareNearSignTx } from '@onekeyfe/hd-transport'; export default class NearSignTransaction extends BaseMethod { getSupportedProtocols() { return ['V1', 'V2'] as const; } init() { this.checkDeviceId = true; this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE]; this.allowUsePreInitialize = true; // check payload validateParams(this.payload, [ { name: 'path', required: true }, { name: 'rawTx', type: 'hexString', required: true }, ]); const { path, rawTx } = this.payload; const addressN = validatePath(path, 3); // init params this.params = { address_n: addressN, raw_tx: formatAnyHex(rawTx), }; } getVersionRange() { return { model_mini: { min: '2.5.0', }, }; } async run() { const res = await this.device.commands.typedCall('NearSignTx', 'NearSignedTx', { ...this.params, }); return Promise.resolve(res.message); } }