50 lines
2.3 KiB
JavaScript
50 lines
2.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const schema_utils_1 = require("@trezor/schema-utils");
|
|
const AbstractMethod_1 = require("../core/AbstractMethod");
|
|
const types_1 = require("../types");
|
|
const paramsValidator_1 = require("./common/paramsValidator");
|
|
const coinInfo_1 = require("../data/coinInfo");
|
|
const formatUtils_1 = require("../utils/formatUtils");
|
|
const pathUtils_1 = require("../utils/pathUtils");
|
|
class SignMessage extends AbstractMethod_1.AbstractMethod {
|
|
init() {
|
|
this.requiredPermissions = ['read', 'write'];
|
|
const { payload } = this;
|
|
(0, schema_utils_1.Assert)(types_1.SignMessage, payload);
|
|
const path = (0, pathUtils_1.validatePath)(payload.path);
|
|
let coinInfo;
|
|
if (payload.coin) {
|
|
coinInfo = (0, coinInfo_1.getBitcoinNetwork)(payload.coin);
|
|
(0, paramsValidator_1.validateCoinPath)(path, coinInfo);
|
|
}
|
|
else {
|
|
coinInfo = (0, coinInfo_1.getBitcoinNetwork)(path);
|
|
}
|
|
this.firmwareRange = (0, paramsValidator_1.getFirmwareRange)(payload.no_script_type ? 'signMessageNoScriptType' : this.name, coinInfo, this.firmwareRange);
|
|
const messageHex = payload.hex
|
|
? (0, formatUtils_1.messageToHex)(payload.message)
|
|
: Buffer.from(payload.message, 'utf8').toString('hex');
|
|
const scriptType = (0, pathUtils_1.getScriptType)(path);
|
|
this.params = {
|
|
address_n: path,
|
|
message: messageHex,
|
|
coin_name: coinInfo ? coinInfo.name : undefined,
|
|
script_type: scriptType && scriptType !== 'SPENDMULTISIG' ? scriptType : 'SPENDADDRESS',
|
|
no_script_type: payload.no_script_type,
|
|
};
|
|
}
|
|
get info() {
|
|
const coinInfo = (0, coinInfo_1.getBitcoinNetwork)(this.payload.coin ?? this.params.address_n);
|
|
return (0, pathUtils_1.getLabel)('Sign #NETWORK message', coinInfo);
|
|
}
|
|
async run() {
|
|
const cmd = this.device.getCommands();
|
|
const { message } = await cmd.typedCall('SignMessage', 'MessageSignature', this.params);
|
|
const signatureBuffer = Buffer.from(message.signature, 'hex');
|
|
message.signature = signatureBuffer.toString('base64');
|
|
return message;
|
|
}
|
|
}
|
|
exports.default = SignMessage;
|
|
//# sourceMappingURL=signMessage.js.map
|