@flipflop-sdk/cli
Version:
FlipFlop CLI tool for common operations
35 lines • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadKeypairFromBase58 = exports.loadKeypairFromFile = void 0;
const web3_js_1 = require("@solana/web3.js");
const fs_1 = __importDefault(require("fs"));
const bs58_1 = __importDefault(require("bs58"));
// Load keypair from file (supports .pri or JSON format)
const loadKeypairFromFile = (filePath) => {
try {
const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
const secretKeyArray = JSON.parse(fileContent);
if (!Array.isArray(secretKeyArray)) {
throw new Error('Private key file must contain an array of numbers');
}
if (secretKeyArray.length !== 64) {
throw new Error('Private key array must contain exactly 64 numbers');
}
const secretKey = new Uint8Array(secretKeyArray);
return web3_js_1.Keypair.fromSecretKey(secretKey);
}
catch (error) {
throw new Error(`Failed to load keypair from file ${filePath}: ${error.message}`);
}
};
exports.loadKeypairFromFile = loadKeypairFromFile;
// Utility to load single keypair from base58 string
const loadKeypairFromBase58 = (base58Key) => {
const secretKey = bs58_1.default.decode(base58Key.trim());
return web3_js_1.Keypair.fromSecretKey(secretKey);
};
exports.loadKeypairFromBase58 = loadKeypairFromBase58;
//# sourceMappingURL=utils.js.map