@taquito/signer
Version:
Provide signing functionality to be with taquito
52 lines (51 loc) • 2.4 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importKey = importKey;
const taquito_signer_1 = require("./taquito-signer");
/**
*
* @description Import a key to sign operation with the side-effect of setting the Tezos instance to use the InMemorySigner provider
*
* @warn The JSON faucets are no longer available on https://teztnets.com/
* @param toolkit The toolkit instance to attach a signer
* @param privateKeyOrEmail Key to load in memory
* @param passphrase If the key is encrypted passphrase to decrypt it
* @param mnemonic Faucet mnemonic
* @param secret Faucet secret
*/
function importKey(toolkit, privateKeyOrEmail, passphrase, mnemonic, secret) {
return __awaiter(this, void 0, void 0, function* () {
if (privateKeyOrEmail && passphrase && mnemonic && secret) {
const signer = taquito_signer_1.InMemorySigner.fromFundraiser(privateKeyOrEmail, passphrase, mnemonic);
toolkit.setProvider({ signer });
const pkh = yield signer.publicKeyHash();
let op;
try {
op = yield toolkit.tz.activate(pkh, secret);
}
catch (ex) {
const isInvalidActivationError = ex && ex.body && /Invalid activation/.test(ex.body);
if (!isInvalidActivationError) {
throw ex;
}
}
if (op) {
yield op.confirmation();
}
}
else {
// Fallback to regular import
const signer = yield taquito_signer_1.InMemorySigner.fromSecretKey(privateKeyOrEmail, passphrase);
toolkit.setProvider({ signer });
}
});
}
;