@tedcryptoorg/cosmos-signer
Version:
Cosmos Signer - A library for signing transactions for Cosmos SDK chains
59 lines (58 loc) • 2.95 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CosmostationWallet = void 0;
const BaseWallet_1 = __importDefault(require("./BaseWallet"));
class CosmostationWallet extends BaseWallet_1.default {
constructor(keplrProvider, cosmostationProvider) {
super(keplrProvider);
this.cosmostationProvider = cosmostationProvider;
this.name = 'cosmostation';
this.label = 'Cosmostation Wallet';
this.keychangeEvent = 'cosmostation_keystorechange';
this.authzAminoLiftedValueSupport = false;
}
getSigner(network) {
return __awaiter(this, void 0, void 0, function* () {
if (this.signer === null) {
const { chainId } = network;
if (this.isLedger()) {
this.signer = yield this.provider.getOfflineSignerOnlyAmino(chainId);
}
else {
this.signer = yield this.provider.getOfflineSigner(chainId);
}
}
return this.signer;
});
}
suggestChain(network) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.cosmostationProvider.request({
method: 'cos_addChain',
params: this.suggestChainData(network)
});
});
}
suggestChainData(network) {
var _a, _b;
return Object.assign({ chainId: network.chainId, chainName: network.prettyName, addressPrefix: network.prefix, baseDenom: network.denom, displayDenom: network.symbol, restURL: network.restUrl, coinType: `${network.slip44}`, decimals: network.decimals, gasRate: {
average: `${network.gasPriceStep.high}`,
low: `${network.gasPriceStep.average}`,
tiny: `${network.gasPriceStep.low}`
} }, (((_b = (_a = network.data.keplrFeatures) === null || _a === void 0 ? void 0 : _a.includes('eth-address-gen')) !== null && _b !== void 0 ? _b : network.slip44 === 60)
? { type: 'ETHERMINT' } : {}));
}
}
exports.CosmostationWallet = CosmostationWallet;