UNPKG

@tedcryptoorg/cosmos-signer

Version:

Cosmos Signer - A library for signing transactions for Cosmos SDK chains

81 lines (80 loc) 3.35 kB
"use strict"; 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.OfflineWallet = void 0; const crypto_1 = require("@cosmjs/crypto"); const BaseWallet_1 = __importDefault(require("./BaseWallet")); const proto_signing_1 = require("@cosmjs/proto-signing"); class OfflineWallet extends BaseWallet_1.default { constructor(mnemonic, logger) { super({}, logger); this.mnemonic = mnemonic; this.logger = logger; this.name = 'offline'; this.label = 'Offline Wallet'; this.keychangeEvent = 'offline_keystorechange'; } connect(network) { return __awaiter(this, void 0, void 0, function* () { var _a; try { yield this.getSigner(network); return null; } catch (error) { (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('Failed to connect to offline wallet', error); } throw new Error('Failed to connect to offline wallet'); }); } getKey() { return __awaiter(this, void 0, void 0, function* () { throw new Error('Offline wallet does not have a key'); }); } getSigner(network) { return __awaiter(this, void 0, void 0, function* () { var _a; if (!this.signer) { const hdPath = [ crypto_1.Slip10RawIndex.hardened(44), crypto_1.Slip10RawIndex.hardened(Number(network.slip44)), crypto_1.Slip10RawIndex.hardened(0), crypto_1.Slip10RawIndex.normal(0), crypto_1.Slip10RawIndex.normal(0) ]; if (Number(network.slip44) !== 118) { (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Using HD Path', (0, crypto_1.pathToString)(hdPath)); } this.signer = (yield proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(this.mnemonic, { prefix: network.bech32_prefix, hdPaths: [hdPath] })); } return this.signer; }); } signDirectSupport() { return true; } signAminoSupport() { return false; } signAmino(...args) { return __awaiter(this, void 0, void 0, function* () { throw new Error('Amino signing is not supported in offline mode'); }); } } exports.OfflineWallet = OfflineWallet;