fourq
Version:
91 lines • 4.33 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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const crypto = __importStar(require("crypto"));
const child_process_1 = require("child_process");
const colors = require('colors/safe');
const action = process.argv[2];
const subaction = process.argv[3];
const isApple = (process.platform === 'darwin');
const isIntel = os.cpus()[0].model.startsWith('Intel');
const isAppleSilicon = os.cpus()[0].model.startsWith('Apple M');
if (isApple) {
try {
(0, child_process_1.execSync)('xcrun --version', { stdio: [] });
}
catch (e) {
console.error(colors.red(`This module requires xcode-select to be correctly configured in your environment.\n` +
`Please make sure to run 'xcode-select --install' before proceeding.\n` +
`Original error: ${e.stderr.toString()}`));
process.exit(1);
}
}
if (action === 'set-path') {
const gypBinding = JSON.parse(fs.readFileSync('binding.gyp', 'utf8'));
const libs = gypBinding.targets[0].libraries;
const revert = subaction && subaction === 'revert';
for (let i = 0; i < libs.length; ++i) {
const split = libs[i].split('/');
if (!revert) {
libs[i] = __dirname + '/fourq-shared/' + split[split.length - 1];
}
else {
libs[i] = split[split.length - 1];
}
}
fs.writeFileSync('binding.gyp', JSON.stringify(gypBinding, null, 2));
}
else if (action === 'make') {
const randBytes32 = crypto.randomBytes(32);
const pubkeyStrings = [];
randBytes32.forEach((v, i) => {
let hex = v.toString(16);
if (hex.length === 1) {
hex += '0';
}
pubkeyStrings[i] = '\\x' + hex;
});
const pubkeyString = pubkeyStrings.join('');
let ssuContent = fs.readFileSync('./features/serverside_unknowability.cc', 'utf8');
ssuContent = ssuContent.split(' = "')[0] + ' = "' + pubkeyString + '";';
fs.writeFileSync('./features/serverside_unknowability.cc', ssuContent, 'utf8');
if (isApple && isIntel) {
(0, child_process_1.execSync)('cd FourQlib/FourQ_64bit_and_portable; make ARCH=x64 GENERIC=TRUE SHARED_LIB=TRUE; cp ../../FourQlib/FourQ_64bit_and_portable/*.so ../../fourq-shared/');
(0, child_process_1.execSync)('cd fourq-shared; install_name_tool -id "' + __dirname + '/fourq-shared/libFourQ.so" libFourQ.so');
}
else if (isApple && isAppleSilicon) {
(0, child_process_1.execSync)('cd FourQlib/FourQ_64bit_and_portable; make ARCH=APPLE_ARM64 SHARED_LIB=TRUE; cp ../../FourQlib/FourQ_64bit_and_portable/*.so ../../fourq-shared/');
(0, child_process_1.execSync)('cd fourq-shared; install_name_tool -id "' + __dirname + '/fourq-shared/libFourQ.so" libFourQ.so');
}
else if (process.arch === 'arm64') {
(0, child_process_1.execSync)('cd FourQlib/FourQ_64bit_and_portable; make ARCH=ARM64 SHARED_LIB=TRUE; cp ../../FourQlib/FourQ_64bit_and_portable/*.so ../../fourq-shared/');
}
else {
(0, child_process_1.execSync)('cd FourQlib/FourQ_64bit_and_portable; make ARCH=x64 GENERIC=TRUE SHARED_LIB=TRUE; cp ../../FourQlib/FourQ_64bit_and_portable/*.so ../../fourq-shared/');
}
}
//# sourceMappingURL=gyp.js.map
;