@flarenetwork/flare-stake-tool
Version:
Utilities for staking on the Flare network
177 lines • 5.71 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPublicKey = getPublicKey;
exports.verifyCAddress = verifyCAddress;
exports.verifyPAddress = verifyPAddress;
exports.onlyHashSign = onlyHashSign;
exports.sign = sign;
exports.signEvmTransaction = signEvmTransaction;
exports.signHash = signHash;
exports.signPersonalMessage = signPersonalMessage;
const avalanche = __importStar(require("./avalanche"));
const ethereum = __importStar(require("./ethereum"));
const flare = __importStar(require("./flare"));
const pubk = __importStar(require("../flare/pubk"));
const utils = __importStar(require("../utils"));
const AVALANCHE = 'Avalanche';
const ETHEREUM = 'Ethereum';
const FLARE = 'Flare';
async function getPublicKey(bip44Path, hrp) {
let app = await _getApp();
if (app === FLARE) {
return await flare.getPublicKey(bip44Path, hrp);
}
else if (app === AVALANCHE) {
return await avalanche.getPublicKey(bip44Path, hrp);
}
else if (app === ETHEREUM) {
return await ethereum.getPublicKey(bip44Path);
}
else {
return '';
}
}
async function verifyCAddress(bip44Path) {
let app = await _getApp();
if (app === FLARE) {
return await flare.getCAddress(bip44Path, true);
}
else if (app === AVALANCHE) {
return await avalanche.getCAddress(bip44Path, true);
}
else if (app === ETHEREUM) {
return await ethereum.getCAddress(bip44Path, true);
}
else {
return '';
}
}
async function verifyPAddress(bip44Path, hrp) {
let app = await _getApp();
if (app === FLARE) {
return await flare.getPAddress(bip44Path, hrp, true);
}
else if (app === AVALANCHE) {
return await avalanche.getPAddress(bip44Path, hrp, true);
}
else if (app === ETHEREUM) {
throw new Error('P-chain address can not be verified in Ethereum app.');
}
else {
return '';
}
}
async function onlyHashSign() {
let app = await _getApp();
return app === AVALANCHE || app === ETHEREUM;
}
async function sign(bip44Path, tx) {
let app = await _getApp();
if (app === FLARE) {
return await flare.sign(bip44Path, tx);
}
else if (app === AVALANCHE) {
throw new Error('Nonblind signing of transactions is not supported on Avalanche app');
}
else if (app === ETHEREUM) {
throw new Error('Nonblind signing of transactions is not supported on Ethereum app');
}
else {
return '';
}
}
async function signEvmTransaction(bip44Path, tx) {
let app = await _getApp();
if (app === FLARE) {
return await flare.signEvmTransaction(bip44Path, tx);
}
else if (app === AVALANCHE) {
return await avalanche.signEvmTransaction(bip44Path, tx);
}
else if (app === ETHEREUM) {
return await ethereum.signEvmTransaction(bip44Path, tx);
}
else {
return '';
}
}
async function signHash(bip44Path, message) {
let app = await _getApp();
if (app === FLARE) {
return await flare.signHash(bip44Path, message);
}
else if (app === AVALANCHE) {
return await avalanche.signHash(bip44Path, message);
}
else if (app === ETHEREUM) {
return await ethereum.signPersonalMessage(bip44Path, utils.toHex(message, false));
}
else {
return '';
}
}
async function signPersonalMessage(bip44Path, message) {
let app = await _getApp();
if (app === FLARE) {
let hashedEthMsg = pubk.getHashedEthMsg(message);
return await flare.signHash(bip44Path, hashedEthMsg);
}
else if (app === AVALANCHE) {
let hashedEthMsg = pubk.getHashedEthMsg(message);
return await avalanche.signHash(bip44Path, hashedEthMsg);
}
else if (app === ETHEREUM) {
return await ethereum.signPersonalMessage(bip44Path, message);
}
else {
return '';
}
}
async function _getApp() {
if (await flare.isFlareApp()) {
return FLARE;
}
else if (await avalanche.isAvalancheApp()) {
return AVALANCHE;
}
else if (await avalanche.isEthereumApp()) {
return ETHEREUM;
}
else {
throw new Error('A supported app (Flare or Avalanche) is not running on the connected Ledger device');
}
}
//# sourceMappingURL=index.js.map