@metamask-previews/bitcoin-regtest-up 0.0.0-preview-82e080825
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +6 -0
- package/LICENSE.APACHE2 +201 -0
- package/LICENSE.MIT +21 -0
- package/README.md +116 -0
- package/dist/bin/bitcoin-regtest-up.cjs +50 -0
- package/dist/bin/bitcoin-regtest-up.cjs.map +1 -0
- package/dist/bin/bitcoin-regtest-up.d.cts +3 -0
- package/dist/bin/bitcoin-regtest-up.d.cts.map +1 -0
- package/dist/bin/bitcoin-regtest-up.d.mts +3 -0
- package/dist/bin/bitcoin-regtest-up.d.mts.map +1 -0
- package/dist/bin/bitcoin-regtest-up.mjs +48 -0
- package/dist/bin/bitcoin-regtest-up.mjs.map +1 -0
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/install.cjs +398 -0
- package/dist/install.cjs.map +1 -0
- package/dist/install.d.cts +43 -0
- package/dist/install.d.cts.map +1 -0
- package/dist/install.d.mts +43 -0
- package/dist/install.d.mts.map +1 -0
- package/dist/install.mjs +390 -0
- package/dist/install.mjs.map +1 -0
- package/package.json +71 -0
package/dist/install.cjs
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanBitcoinRegtestCache = exports.installBitcoinRegtest = exports.parseBitcoinRegtestInstallCliOptions = exports.readBitcoinRegtestInstallOptionsFromPackageJson = exports.getBitcoinRegtestCacheDirectory = exports.BITCOIN_REGTEST_DEFAULT_CORE = void 0;
|
|
4
|
+
/* eslint-disable import-x/no-nodejs-modules, no-restricted-globals */
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const node_http_1 = require("node:http");
|
|
10
|
+
const node_https_1 = require("node:https");
|
|
11
|
+
const node_os_1 = require("node:os");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const promises_2 = require("node:stream/promises");
|
|
14
|
+
const BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';
|
|
15
|
+
const BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';
|
|
16
|
+
exports.BITCOIN_REGTEST_DEFAULT_CORE = {
|
|
17
|
+
version: '30.2',
|
|
18
|
+
platforms: {
|
|
19
|
+
'darwin-arm64': {
|
|
20
|
+
checksum: 'c2ecab62891de22228043815cb6211549a32272be3d5d052ff19847d3420bd10',
|
|
21
|
+
url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-arm64-apple-darwin.tar.gz',
|
|
22
|
+
},
|
|
23
|
+
'darwin-x64': {
|
|
24
|
+
checksum: '99d5cee9b9c37be506396c30837a4b98e320bfea71c474d6120a7e8eb6075c7b',
|
|
25
|
+
url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-apple-darwin.tar.gz',
|
|
26
|
+
},
|
|
27
|
+
'linux-arm64': {
|
|
28
|
+
checksum: '73e76c14edc79808a0511c744d102ffbb494807ee90cbcba176568243254b532',
|
|
29
|
+
url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-aarch64-linux-gnu.tar.gz',
|
|
30
|
+
},
|
|
31
|
+
'linux-x64': {
|
|
32
|
+
checksum: '6aa7bb4feb699c4c6262dd23e4004191f6df7f373b5d5978b5bcdd4bb72f75d8',
|
|
33
|
+
url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
function getBitcoinRegtestCacheDirectory({ cwd = process.cwd(), homeDirectory = (0, node_os_1.homedir)(), } = {}) {
|
|
38
|
+
const yarnRcPath = (0, node_path_1.join)(cwd, '.yarnrc.yml');
|
|
39
|
+
try {
|
|
40
|
+
const yarnRc = (0, node_fs_1.readFileSync)(yarnRcPath, 'utf8');
|
|
41
|
+
if (/^\s*enableGlobalCache:\s*true\s*$/mu.test(yarnRc)) {
|
|
42
|
+
return (0, node_path_1.join)(homeDirectory, '.cache', 'metamask');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (!isFileMissingError(error)) {
|
|
47
|
+
console.warn(`Warning: Error reading ${yarnRcPath}, using local bitcoin-regtest-up cache:`, error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return (0, node_path_1.join)(cwd, '.metamask', 'cache');
|
|
51
|
+
}
|
|
52
|
+
exports.getBitcoinRegtestCacheDirectory = getBitcoinRegtestCacheDirectory;
|
|
53
|
+
function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd = process.cwd(), packageJsonPath = (0, node_path_1.join)(cwd, 'package.json'), } = {}) {
|
|
54
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, 'utf8'));
|
|
55
|
+
const config = packageJson.bitcoinRegtestUp ??
|
|
56
|
+
packageJson.bitcoinregtestup ??
|
|
57
|
+
packageJson['bitcoin-regtest-up'];
|
|
58
|
+
const options = {};
|
|
59
|
+
if (config?.binDirectory) {
|
|
60
|
+
options.binDirectory = config.binDirectory;
|
|
61
|
+
}
|
|
62
|
+
if (config?.bitcoinCore) {
|
|
63
|
+
options.bitcoinCore = config.bitcoinCore;
|
|
64
|
+
}
|
|
65
|
+
if (config?.cacheDirectory) {
|
|
66
|
+
options.cacheDirectory = config.cacheDirectory;
|
|
67
|
+
}
|
|
68
|
+
return options;
|
|
69
|
+
}
|
|
70
|
+
exports.readBitcoinRegtestInstallOptionsFromPackageJson = readBitcoinRegtestInstallOptionsFromPackageJson;
|
|
71
|
+
function parseBitcoinRegtestInstallCliOptions(args) {
|
|
72
|
+
const options = {};
|
|
73
|
+
const bitcoinCore = {};
|
|
74
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
75
|
+
const arg = args[index];
|
|
76
|
+
const value = args[index + 1];
|
|
77
|
+
switch (arg) {
|
|
78
|
+
case '--bin-directory':
|
|
79
|
+
options.binDirectory = readCliValue(arg, value);
|
|
80
|
+
index += 1;
|
|
81
|
+
break;
|
|
82
|
+
case '--bitcoin-core-checksum':
|
|
83
|
+
bitcoinCore.checksum = readCliValue(arg, value);
|
|
84
|
+
index += 1;
|
|
85
|
+
break;
|
|
86
|
+
case '--bitcoin-core-url':
|
|
87
|
+
bitcoinCore.url = readCliValue(arg, value);
|
|
88
|
+
index += 1;
|
|
89
|
+
break;
|
|
90
|
+
case '--cache-directory':
|
|
91
|
+
options.cacheDirectory = readCliValue(arg, value);
|
|
92
|
+
index += 1;
|
|
93
|
+
break;
|
|
94
|
+
case '--platform':
|
|
95
|
+
options.platform = readCliValue(arg, value);
|
|
96
|
+
index += 1;
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
throw new Error(`Unknown bitcoin-regtest-up install option: ${arg}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (bitcoinCore.url || bitcoinCore.checksum) {
|
|
103
|
+
options.bitcoinCore = {
|
|
104
|
+
platforms: {
|
|
105
|
+
current: requireCompletePlatformConfig(bitcoinCore, 'Bitcoin Core CLI options'),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return options;
|
|
110
|
+
}
|
|
111
|
+
exports.parseBitcoinRegtestInstallCliOptions = parseBitcoinRegtestInstallCliOptions;
|
|
112
|
+
async function installBitcoinRegtest(options = {}, dependencies = {}) {
|
|
113
|
+
const cwd = options.cwd ?? process.cwd();
|
|
114
|
+
const cacheDirectory = options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });
|
|
115
|
+
const binDirectory = options.binDirectory ?? (0, node_path_1.join)(cwd, 'node_modules', '.bin');
|
|
116
|
+
const platformKey = options.platform ?? getPlatformKey();
|
|
117
|
+
const bitcoinCore = options.bitcoinCore ?? exports.BITCOIN_REGTEST_DEFAULT_CORE;
|
|
118
|
+
const bitcoinCoreConfig = resolvePlatformConfig(bitcoinCore, platformKey, 'Bitcoin Core archive');
|
|
119
|
+
const bitcoinCoreResult = await installBitcoinCoreArchive({ cacheDirectory, config: bitcoinCoreConfig }, dependencies);
|
|
120
|
+
const bitcoindBinary = await installExecutableWrapper({
|
|
121
|
+
binDirectory,
|
|
122
|
+
commandName: 'bitcoind',
|
|
123
|
+
executableArgs: bitcoinCoreResult.sourceBitcoindArgs,
|
|
124
|
+
executablePath: bitcoinCoreResult.sourceBitcoindBinary,
|
|
125
|
+
});
|
|
126
|
+
const bitcoinCliBinary = await installExecutableWrapper({
|
|
127
|
+
binDirectory,
|
|
128
|
+
commandName: 'bitcoin-cli',
|
|
129
|
+
executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
bitcoinCliBinary,
|
|
133
|
+
bitcoindBinary,
|
|
134
|
+
cacheHit: bitcoinCoreResult.cacheHit,
|
|
135
|
+
checksum: bitcoinCoreConfig.checksum,
|
|
136
|
+
sourceBitcoindArgs: bitcoinCoreResult.sourceBitcoindArgs,
|
|
137
|
+
sourceBitcoinCliBinary: bitcoinCoreResult.sourceBitcoinCliBinary,
|
|
138
|
+
sourceBitcoindBinary: bitcoinCoreResult.sourceBitcoindBinary,
|
|
139
|
+
version: bitcoinCore.version,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exports.installBitcoinRegtest = installBitcoinRegtest;
|
|
143
|
+
async function cleanBitcoinRegtestCache(options = {}) {
|
|
144
|
+
const cwd = options.cwd ?? process.cwd();
|
|
145
|
+
const cacheDirectory = options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });
|
|
146
|
+
await (0, promises_1.rm)((0, node_path_1.join)(cacheDirectory, BITCOIN_REGTEST_CACHE_NAMESPACE), {
|
|
147
|
+
force: true,
|
|
148
|
+
recursive: true,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
exports.cleanBitcoinRegtestCache = cleanBitcoinRegtestCache;
|
|
152
|
+
async function installBitcoinCoreArchive({ cacheDirectory, config, }, dependencies) {
|
|
153
|
+
const cacheKey = getCacheKey(config);
|
|
154
|
+
const cacheRoot = (0, node_path_1.join)(cacheDirectory, BITCOIN_REGTEST_CACHE_NAMESPACE, BITCOIN_CORE_CACHE_NAMESPACE, cacheKey);
|
|
155
|
+
const checksumPath = (0, node_path_1.join)(cacheRoot, '.source-checksum');
|
|
156
|
+
const cached = findBitcoinCoreBinaries(cacheRoot);
|
|
157
|
+
if (cached &&
|
|
158
|
+
(0, node_fs_1.existsSync)(checksumPath) &&
|
|
159
|
+
(0, node_fs_1.readFileSync)(checksumPath, 'utf8') === config.checksum &&
|
|
160
|
+
(await areBitcoinCoreBinariesRunnable(cached))) {
|
|
161
|
+
return { cacheHit: true, ...cached };
|
|
162
|
+
}
|
|
163
|
+
const tempRoot = `${cacheRoot}.downloading`;
|
|
164
|
+
const archivePath = (0, node_path_1.join)(tempRoot, 'bitcoin-core.tar.gz');
|
|
165
|
+
const downloadFile = dependencies.downloadFile ?? downloadFileFromUrl;
|
|
166
|
+
const extractArchive = dependencies.extractArchive ?? extractTarGzArchive;
|
|
167
|
+
await (0, promises_1.rm)(tempRoot, { force: true, recursive: true });
|
|
168
|
+
await (0, promises_1.rm)(cacheRoot, { force: true, recursive: true });
|
|
169
|
+
await (0, promises_1.mkdir)(tempRoot, { recursive: true });
|
|
170
|
+
try {
|
|
171
|
+
await downloadFile(config.url, archivePath);
|
|
172
|
+
await verifyFileChecksum(archivePath, config.checksum, 'Downloaded Bitcoin Core');
|
|
173
|
+
await extractArchive(archivePath, tempRoot);
|
|
174
|
+
const binaries = findBitcoinCoreBinaries(tempRoot);
|
|
175
|
+
if (!binaries) {
|
|
176
|
+
throw new Error('Bitcoin Core archive did not contain a node daemon (bitcoind, bitcoin-node, or bitcoin) and bin/bitcoin-cli.');
|
|
177
|
+
}
|
|
178
|
+
await assertBitcoinCoreBinariesRunnable(binaries);
|
|
179
|
+
await (0, promises_1.writeFile)(checksumPath.replace(cacheRoot, tempRoot), config.checksum);
|
|
180
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(cacheRoot), { recursive: true });
|
|
181
|
+
await (0, promises_1.rename)(tempRoot, cacheRoot);
|
|
182
|
+
return {
|
|
183
|
+
cacheHit: false,
|
|
184
|
+
sourceBitcoindArgs: binaries.sourceBitcoindArgs,
|
|
185
|
+
sourceBitcoinCliBinary: binaries.sourceBitcoinCliBinary.replace(tempRoot, cacheRoot),
|
|
186
|
+
sourceBitcoindBinary: binaries.sourceBitcoindBinary.replace(tempRoot, cacheRoot),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
await (0, promises_1.rm)(tempRoot, { force: true, recursive: true });
|
|
191
|
+
await (0, promises_1.rm)(cacheRoot, { force: true, recursive: true });
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function installExecutableWrapper({ binDirectory, commandName, executableArgs = [], executablePath, }) {
|
|
196
|
+
const binaryPath = (0, node_path_1.join)(binDirectory, commandName);
|
|
197
|
+
const resolvedExecutablePath = (0, node_path_1.resolve)(executablePath);
|
|
198
|
+
await (0, promises_1.mkdir)(binDirectory, { recursive: true });
|
|
199
|
+
await (0, promises_1.unlink)(binaryPath).catch((error) => {
|
|
200
|
+
if (!isFileMissingError(error)) {
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
await (0, promises_1.writeFile)(binaryPath, `#!/usr/bin/env node
|
|
205
|
+
const { spawnSync } = require('node:child_process');
|
|
206
|
+
|
|
207
|
+
const executablePath = ${JSON.stringify(resolvedExecutablePath)};
|
|
208
|
+
const result = spawnSync(executablePath, ${JSON.stringify(executableArgs)}.concat(process.argv.slice(2)), {
|
|
209
|
+
stdio: 'inherit',
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (result.error) {
|
|
213
|
+
console.error(result.error.message);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (result.signal) {
|
|
218
|
+
process.kill(process.pid, result.signal);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
process.exit(result.status ?? 0);
|
|
222
|
+
`);
|
|
223
|
+
await (0, promises_1.chmod)(binaryPath, 0o755);
|
|
224
|
+
return binaryPath;
|
|
225
|
+
}
|
|
226
|
+
async function areBitcoinCoreBinariesRunnable(binaries) {
|
|
227
|
+
try {
|
|
228
|
+
await assertBitcoinCoreBinariesRunnable(binaries);
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function assertBitcoinCoreBinariesRunnable(binaries) {
|
|
236
|
+
await runCommand(binaries.sourceBitcoindBinary, [
|
|
237
|
+
...binaries.sourceBitcoindArgs,
|
|
238
|
+
'-version',
|
|
239
|
+
]);
|
|
240
|
+
await runCommand(binaries.sourceBitcoinCliBinary, ['-version']);
|
|
241
|
+
}
|
|
242
|
+
function findBitcoinCoreBinaries(root) {
|
|
243
|
+
const sourceBitcoinCliBinary = findExecutable(root, 'bitcoin-cli');
|
|
244
|
+
const sourceBitcoindBinary = findBitcoinCoreDaemonBinary(root);
|
|
245
|
+
if (!sourceBitcoindBinary || !sourceBitcoinCliBinary) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
sourceBitcoindArgs: sourceBitcoindBinary.name === 'bitcoin' ? ['node'] : [],
|
|
250
|
+
sourceBitcoinCliBinary,
|
|
251
|
+
sourceBitcoindBinary: sourceBitcoindBinary.path,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function findBitcoinCoreDaemonBinary(root) {
|
|
255
|
+
for (const name of ['bitcoind', 'bitcoin-node', 'bitcoin']) {
|
|
256
|
+
const path = findExecutable(root, name);
|
|
257
|
+
if (path) {
|
|
258
|
+
return { name, path };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
function findExecutable(root, name) {
|
|
264
|
+
if (!(0, node_fs_1.existsSync)(root)) {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
for (const entry of (0, node_fs_1.readdirSync)(root)) {
|
|
268
|
+
const entryPath = (0, node_path_1.join)(root, entry);
|
|
269
|
+
const stat = (0, node_fs_1.statSync)(entryPath);
|
|
270
|
+
if (stat.isDirectory()) {
|
|
271
|
+
const found = findExecutable(entryPath, name);
|
|
272
|
+
if (found) {
|
|
273
|
+
return found;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else if (entry === name) {
|
|
277
|
+
return entryPath;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
function resolvePlatformConfig(config, platform, label) {
|
|
283
|
+
const platformConfig = config.platforms[platform] ?? config.platforms.current;
|
|
284
|
+
if (!platformConfig) {
|
|
285
|
+
throw new Error(`No ${label} is configured for ${platform}.`);
|
|
286
|
+
}
|
|
287
|
+
return platformConfig;
|
|
288
|
+
}
|
|
289
|
+
function requireCompletePlatformConfig(config, label) {
|
|
290
|
+
if (!config.url || !config.checksum) {
|
|
291
|
+
throw new Error(`${label} require both a URL and a checksum.`);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
checksum: config.checksum,
|
|
295
|
+
url: config.url,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function getCacheKey(config) {
|
|
299
|
+
return (0, node_crypto_1.createHash)('sha256')
|
|
300
|
+
.update(`${config.url}:${config.checksum}`)
|
|
301
|
+
.digest('hex');
|
|
302
|
+
}
|
|
303
|
+
async function verifyFileChecksum(filePath, expectedChecksum, label) {
|
|
304
|
+
const checksum = (0, node_crypto_1.createHash)('sha256')
|
|
305
|
+
.update(await (0, promises_1.readFile)(filePath))
|
|
306
|
+
.digest('hex');
|
|
307
|
+
if (checksum !== expectedChecksum) {
|
|
308
|
+
throw new Error(`${label} checksum mismatch. Expected ${expectedChecksum}, got ${checksum}.`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function downloadFileFromUrl(url, destination) {
|
|
312
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(destination), { recursive: true });
|
|
313
|
+
await (0, promises_2.pipeline)(await openDownloadStream(new URL(url)), (0, node_fs_1.createWriteStream)(destination));
|
|
314
|
+
}
|
|
315
|
+
async function openDownloadStream(url, redirectsRemaining = 5) {
|
|
316
|
+
const request = url.protocol === 'http:' ? node_http_1.request : node_https_1.request;
|
|
317
|
+
return await new Promise((resolvePromise, rejectPromise) => {
|
|
318
|
+
const req = request(url, (response) => {
|
|
319
|
+
const { headers, statusCode, statusMessage } = response;
|
|
320
|
+
if (statusCode &&
|
|
321
|
+
statusCode >= 300 &&
|
|
322
|
+
statusCode < 400 &&
|
|
323
|
+
headers.location) {
|
|
324
|
+
response.resume();
|
|
325
|
+
if (redirectsRemaining <= 0) {
|
|
326
|
+
rejectPromise(new Error(`Too many redirects downloading ${url}`));
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
openDownloadStream(new URL(headers.location, url), redirectsRemaining - 1)
|
|
330
|
+
.then(resolvePromise)
|
|
331
|
+
.catch(rejectPromise);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (!statusCode || statusCode < 200 || statusCode >= 300) {
|
|
335
|
+
response.resume();
|
|
336
|
+
rejectPromise(new Error(`Request to ${url} failed with ${statusCode ?? 'unknown'} ${statusMessage ?? ''}`.trim()));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
resolvePromise(response);
|
|
340
|
+
});
|
|
341
|
+
req.on('error', rejectPromise);
|
|
342
|
+
req.end();
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async function extractTarGzArchive(archivePath, destination) {
|
|
346
|
+
await runCommand('tar', ['-xzf', archivePath, '-C', destination]);
|
|
347
|
+
}
|
|
348
|
+
async function runCommand(command, args) {
|
|
349
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
350
|
+
const child = (0, node_child_process_1.spawn)(command, args, {
|
|
351
|
+
shell: false,
|
|
352
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
353
|
+
});
|
|
354
|
+
let stderr = '';
|
|
355
|
+
child.stderr.on('data', (chunk) => {
|
|
356
|
+
stderr += chunk.toString();
|
|
357
|
+
});
|
|
358
|
+
child.on('error', rejectPromise);
|
|
359
|
+
child.on('close', (code, signal) => {
|
|
360
|
+
if (code === 0) {
|
|
361
|
+
resolvePromise();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const exitStatus = signal ? `signal ${signal}` : `code ${code ?? 'null'}`;
|
|
365
|
+
rejectPromise(new Error(`${command} ${args.join(' ')} failed with ${exitStatus}: ${stderr}`));
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function getPlatformKey() {
|
|
370
|
+
const platform = (0, node_os_1.platform)();
|
|
371
|
+
const arch = (0, node_os_1.arch)();
|
|
372
|
+
if (platform === 'darwin' && arch === 'arm64') {
|
|
373
|
+
return 'darwin-arm64';
|
|
374
|
+
}
|
|
375
|
+
if (platform === 'darwin' && arch === 'x64') {
|
|
376
|
+
return 'darwin-x64';
|
|
377
|
+
}
|
|
378
|
+
if (platform === 'linux' && arch === 'arm64') {
|
|
379
|
+
return 'linux-arm64';
|
|
380
|
+
}
|
|
381
|
+
if (platform === 'linux' && arch === 'x64') {
|
|
382
|
+
return 'linux-x64';
|
|
383
|
+
}
|
|
384
|
+
return `${platform}-${arch}`;
|
|
385
|
+
}
|
|
386
|
+
function readCliValue(arg, value) {
|
|
387
|
+
if (!value || value.startsWith('--')) {
|
|
388
|
+
throw new Error(`${arg} requires a value.`);
|
|
389
|
+
}
|
|
390
|
+
return value;
|
|
391
|
+
}
|
|
392
|
+
function isFileMissingError(error) {
|
|
393
|
+
return (typeof error === 'object' &&
|
|
394
|
+
error !== null &&
|
|
395
|
+
Object.prototype.hasOwnProperty.call(error, 'code') &&
|
|
396
|
+
error.code === 'ENOENT');
|
|
397
|
+
}
|
|
398
|
+
//# sourceMappingURL=install.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.cjs","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,2DAA2C;AAC3C,6CAAyC;AACzC,qCAMiB;AACjB,+CAQ0B;AAC1B,yCAAmD;AACnD,2CAAqD;AACrD,qCAA0E;AAC1E,yCAAmD;AACnD,mDAAgD;AAEhD,MAAM,+BAA+B,GAAG,oBAAoB,CAAC;AAC7D,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAgDvC,QAAA,4BAA4B,GAAiC;IACxE,OAAO,EAAE,MAAM;IACf,SAAS,EAAE;QACT,cAAc,EAAE;YACd,QAAQ,EACN,kEAAkE;YACpE,GAAG,EAAE,sFAAsF;SAC5F;QACD,YAAY,EAAE;YACZ,QAAQ,EACN,kEAAkE;YACpE,GAAG,EAAE,uFAAuF;SAC7F;QACD,aAAa,EAAE;YACb,QAAQ,EACN,kEAAkE;YACpE,GAAG,EAAE,qFAAqF;SAC3F;QACD,WAAW,EAAE;YACX,QAAQ,EACN,kEAAkE;YACpE,GAAG,EAAE,oFAAoF;SAC1F;KACF;CACF,CAAC;AAEF,SAAgB,+BAA+B,CAAC,EAC9C,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,aAAa,GAAG,IAA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CACnD,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable import-x/no-nodejs-modules, no-restricted-globals */\nimport { spawn } from 'node:child_process';\nimport { createHash } from 'node:crypto';\nimport {\n createWriteStream,\n existsSync,\n readdirSync,\n readFileSync,\n statSync,\n} from 'node:fs';\nimport {\n chmod,\n mkdir,\n readFile,\n rename,\n rm,\n unlink,\n writeFile,\n} from 'node:fs/promises';\nimport { request as requestHttp } from 'node:http';\nimport { request as requestHttps } from 'node:https';\nimport { arch as osArch, homedir, platform as osPlatform } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\nimport { pipeline } from 'node:stream/promises';\n\nconst BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';\nconst BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';\n\nexport type BitcoinRegtestArtifactConfig = {\n platforms: Record<string, BitcoinRegtestArtifactPlatformConfig | undefined>;\n version?: string;\n};\n\nexport type BitcoinRegtestArtifactPlatformConfig = {\n checksum: string;\n size?: number;\n url: string;\n};\n\nexport type BitcoinRegtestInstallOptions = {\n binDirectory?: string;\n bitcoinCore?: BitcoinRegtestArtifactConfig;\n cacheDirectory?: string;\n cwd?: string;\n platform?: string;\n};\n\nexport type BitcoinRegtestInstallResult = {\n bitcoinCliBinary: string;\n bitcoindBinary: string;\n cacheHit: boolean;\n checksum: string;\n sourceBitcoindArgs: string[];\n sourceBitcoinCliBinary: string;\n sourceBitcoindBinary: string;\n version?: string;\n};\n\nexport type BitcoinRegtestInstallDependencies = {\n downloadFile?: (url: string, destination: string) => Promise<void>;\n extractArchive?: (archivePath: string, destination: string) => Promise<void>;\n};\n\ntype BitcoinRegtestPackageJson = {\n 'bitcoin-regtest-up'?: BitcoinRegtestPackageJsonConfig;\n bitcoinRegtestUp?: BitcoinRegtestPackageJsonConfig;\n bitcoinregtestup?: BitcoinRegtestPackageJsonConfig;\n};\n\ntype BitcoinRegtestPackageJsonConfig = Pick<\n BitcoinRegtestInstallOptions,\n 'binDirectory' | 'bitcoinCore' | 'cacheDirectory'\n>;\n\nexport const BITCOIN_REGTEST_DEFAULT_CORE: BitcoinRegtestArtifactConfig = {\n version: '30.2',\n platforms: {\n 'darwin-arm64': {\n checksum:\n 'c2ecab62891de22228043815cb6211549a32272be3d5d052ff19847d3420bd10',\n url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-arm64-apple-darwin.tar.gz',\n },\n 'darwin-x64': {\n checksum:\n '99d5cee9b9c37be506396c30837a4b98e320bfea71c474d6120a7e8eb6075c7b',\n url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-apple-darwin.tar.gz',\n },\n 'linux-arm64': {\n checksum:\n '73e76c14edc79808a0511c744d102ffbb494807ee90cbcba176568243254b532',\n url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-aarch64-linux-gnu.tar.gz',\n },\n 'linux-x64': {\n checksum:\n '6aa7bb4feb699c4c6262dd23e4004191f6df7f373b5d5978b5bcdd4bb72f75d8',\n url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz',\n },\n },\n};\n\nexport function getBitcoinRegtestCacheDirectory({\n cwd = process.cwd(),\n homeDirectory = homedir(),\n}: {\n cwd?: string;\n homeDirectory?: string;\n} = {}): string {\n const yarnRcPath = join(cwd, '.yarnrc.yml');\n\n try {\n const yarnRc = readFileSync(yarnRcPath, 'utf8');\n if (/^\\s*enableGlobalCache:\\s*true\\s*$/mu.test(yarnRc)) {\n return join(homeDirectory, '.cache', 'metamask');\n }\n } catch (error) {\n if (!isFileMissingError(error)) {\n console.warn(\n `Warning: Error reading ${yarnRcPath}, using local bitcoin-regtest-up cache:`,\n error,\n );\n }\n }\n\n return join(cwd, '.metamask', 'cache');\n}\n\nexport function readBitcoinRegtestInstallOptionsFromPackageJson({\n cwd = process.cwd(),\n packageJsonPath = join(cwd, 'package.json'),\n}: {\n cwd?: string;\n packageJsonPath?: string;\n} = {}): BitcoinRegtestInstallOptions {\n const packageJson = JSON.parse(\n readFileSync(packageJsonPath, 'utf8'),\n ) as BitcoinRegtestPackageJson;\n const config =\n packageJson.bitcoinRegtestUp ??\n packageJson.bitcoinregtestup ??\n packageJson['bitcoin-regtest-up'];\n const options: BitcoinRegtestInstallOptions = {};\n\n if (config?.binDirectory) {\n options.binDirectory = config.binDirectory;\n }\n if (config?.bitcoinCore) {\n options.bitcoinCore = config.bitcoinCore;\n }\n if (config?.cacheDirectory) {\n options.cacheDirectory = config.cacheDirectory;\n }\n\n return options;\n}\n\nexport function parseBitcoinRegtestInstallCliOptions(\n args: string[],\n): BitcoinRegtestInstallOptions {\n const options: BitcoinRegtestInstallOptions = {};\n const bitcoinCore: Partial<BitcoinRegtestArtifactPlatformConfig> = {};\n\n for (let index = 0; index < args.length; index += 1) {\n const arg = args[index];\n const value = args[index + 1];\n\n switch (arg) {\n case '--bin-directory':\n options.binDirectory = readCliValue(arg, value);\n index += 1;\n break;\n case '--bitcoin-core-checksum':\n bitcoinCore.checksum = readCliValue(arg, value);\n index += 1;\n break;\n case '--bitcoin-core-url':\n bitcoinCore.url = readCliValue(arg, value);\n index += 1;\n break;\n case '--cache-directory':\n options.cacheDirectory = readCliValue(arg, value);\n index += 1;\n break;\n case '--platform':\n options.platform = readCliValue(arg, value);\n index += 1;\n break;\n default:\n throw new Error(`Unknown bitcoin-regtest-up install option: ${arg}`);\n }\n }\n\n if (bitcoinCore.url || bitcoinCore.checksum) {\n options.bitcoinCore = {\n platforms: {\n current: requireCompletePlatformConfig(\n bitcoinCore,\n 'Bitcoin Core CLI options',\n ),\n },\n };\n }\n\n return options;\n}\n\nexport async function installBitcoinRegtest(\n options: BitcoinRegtestInstallOptions = {},\n dependencies: BitcoinRegtestInstallDependencies = {},\n): Promise<BitcoinRegtestInstallResult> {\n const cwd = options.cwd ?? process.cwd();\n const cacheDirectory =\n options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });\n const binDirectory =\n options.binDirectory ?? join(cwd, 'node_modules', '.bin');\n const platformKey = options.platform ?? getPlatformKey();\n const bitcoinCore = options.bitcoinCore ?? BITCOIN_REGTEST_DEFAULT_CORE;\n const bitcoinCoreConfig = resolvePlatformConfig(\n bitcoinCore,\n platformKey,\n 'Bitcoin Core archive',\n );\n const bitcoinCoreResult = await installBitcoinCoreArchive(\n { cacheDirectory, config: bitcoinCoreConfig },\n dependencies,\n );\n const bitcoindBinary = await installExecutableWrapper({\n binDirectory,\n commandName: 'bitcoind',\n executableArgs: bitcoinCoreResult.sourceBitcoindArgs,\n executablePath: bitcoinCoreResult.sourceBitcoindBinary,\n });\n const bitcoinCliBinary = await installExecutableWrapper({\n binDirectory,\n commandName: 'bitcoin-cli',\n executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,\n });\n\n return {\n bitcoinCliBinary,\n bitcoindBinary,\n cacheHit: bitcoinCoreResult.cacheHit,\n checksum: bitcoinCoreConfig.checksum,\n sourceBitcoindArgs: bitcoinCoreResult.sourceBitcoindArgs,\n sourceBitcoinCliBinary: bitcoinCoreResult.sourceBitcoinCliBinary,\n sourceBitcoindBinary: bitcoinCoreResult.sourceBitcoindBinary,\n version: bitcoinCore.version,\n };\n}\n\nexport async function cleanBitcoinRegtestCache(\n options: Pick<BitcoinRegtestInstallOptions, 'cacheDirectory' | 'cwd'> = {},\n): Promise<void> {\n const cwd = options.cwd ?? process.cwd();\n const cacheDirectory =\n options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });\n\n await rm(join(cacheDirectory, BITCOIN_REGTEST_CACHE_NAMESPACE), {\n force: true,\n recursive: true,\n });\n}\n\nasync function installBitcoinCoreArchive(\n {\n cacheDirectory,\n config,\n }: {\n cacheDirectory: string;\n config: BitcoinRegtestArtifactPlatformConfig;\n },\n dependencies: BitcoinRegtestInstallDependencies,\n): Promise<{\n cacheHit: boolean;\n sourceBitcoindArgs: string[];\n sourceBitcoinCliBinary: string;\n sourceBitcoindBinary: string;\n}> {\n const cacheKey = getCacheKey(config);\n const cacheRoot = join(\n cacheDirectory,\n BITCOIN_REGTEST_CACHE_NAMESPACE,\n BITCOIN_CORE_CACHE_NAMESPACE,\n cacheKey,\n );\n const checksumPath = join(cacheRoot, '.source-checksum');\n const cached = findBitcoinCoreBinaries(cacheRoot);\n\n if (\n cached &&\n existsSync(checksumPath) &&\n readFileSync(checksumPath, 'utf8') === config.checksum &&\n (await areBitcoinCoreBinariesRunnable(cached))\n ) {\n return { cacheHit: true, ...cached };\n }\n\n const tempRoot = `${cacheRoot}.downloading`;\n const archivePath = join(tempRoot, 'bitcoin-core.tar.gz');\n const downloadFile = dependencies.downloadFile ?? downloadFileFromUrl;\n const extractArchive = dependencies.extractArchive ?? extractTarGzArchive;\n\n await rm(tempRoot, { force: true, recursive: true });\n await rm(cacheRoot, { force: true, recursive: true });\n await mkdir(tempRoot, { recursive: true });\n\n try {\n await downloadFile(config.url, archivePath);\n await verifyFileChecksum(\n archivePath,\n config.checksum,\n 'Downloaded Bitcoin Core',\n );\n await extractArchive(archivePath, tempRoot);\n\n const binaries = findBitcoinCoreBinaries(tempRoot);\n if (!binaries) {\n throw new Error(\n 'Bitcoin Core archive did not contain a node daemon (bitcoind, bitcoin-node, or bitcoin) and bin/bitcoin-cli.',\n );\n }\n await assertBitcoinCoreBinariesRunnable(binaries);\n\n await writeFile(checksumPath.replace(cacheRoot, tempRoot), config.checksum);\n await mkdir(dirname(cacheRoot), { recursive: true });\n await rename(tempRoot, cacheRoot);\n\n return {\n cacheHit: false,\n sourceBitcoindArgs: binaries.sourceBitcoindArgs,\n sourceBitcoinCliBinary: binaries.sourceBitcoinCliBinary.replace(\n tempRoot,\n cacheRoot,\n ),\n sourceBitcoindBinary: binaries.sourceBitcoindBinary.replace(\n tempRoot,\n cacheRoot,\n ),\n };\n } catch (error) {\n await rm(tempRoot, { force: true, recursive: true });\n await rm(cacheRoot, { force: true, recursive: true });\n throw error;\n }\n}\n\nasync function installExecutableWrapper({\n binDirectory,\n commandName,\n executableArgs = [],\n executablePath,\n}: {\n binDirectory: string;\n commandName: string;\n executableArgs?: string[];\n executablePath: string;\n}): Promise<string> {\n const binaryPath = join(binDirectory, commandName);\n const resolvedExecutablePath = resolve(executablePath);\n\n await mkdir(binDirectory, { recursive: true });\n await unlink(binaryPath).catch((error) => {\n if (!isFileMissingError(error)) {\n throw error;\n }\n });\n await writeFile(\n binaryPath,\n `#!/usr/bin/env node\nconst { spawnSync } = require('node:child_process');\n\nconst executablePath = ${JSON.stringify(resolvedExecutablePath)};\nconst result = spawnSync(executablePath, ${JSON.stringify(executableArgs)}.concat(process.argv.slice(2)), {\n stdio: 'inherit',\n});\n\nif (result.error) {\n console.error(result.error.message);\n process.exit(1);\n}\n\nif (result.signal) {\n process.kill(process.pid, result.signal);\n}\n\nprocess.exit(result.status ?? 0);\n`,\n );\n await chmod(binaryPath, 0o755);\n\n return binaryPath;\n}\n\nasync function areBitcoinCoreBinariesRunnable(binaries: {\n sourceBitcoindArgs: string[];\n sourceBitcoinCliBinary: string;\n sourceBitcoindBinary: string;\n}): Promise<boolean> {\n try {\n await assertBitcoinCoreBinariesRunnable(binaries);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function assertBitcoinCoreBinariesRunnable(binaries: {\n sourceBitcoindArgs: string[];\n sourceBitcoinCliBinary: string;\n sourceBitcoindBinary: string;\n}): Promise<void> {\n await runCommand(binaries.sourceBitcoindBinary, [\n ...binaries.sourceBitcoindArgs,\n '-version',\n ]);\n await runCommand(binaries.sourceBitcoinCliBinary, ['-version']);\n}\n\nfunction findBitcoinCoreBinaries(root: string):\n | {\n sourceBitcoindArgs: string[];\n sourceBitcoinCliBinary: string;\n sourceBitcoindBinary: string;\n }\n | undefined {\n const sourceBitcoinCliBinary = findExecutable(root, 'bitcoin-cli');\n const sourceBitcoindBinary = findBitcoinCoreDaemonBinary(root);\n\n if (!sourceBitcoindBinary || !sourceBitcoinCliBinary) {\n return undefined;\n }\n\n return {\n sourceBitcoindArgs: sourceBitcoindBinary.name === 'bitcoin' ? ['node'] : [],\n sourceBitcoinCliBinary,\n sourceBitcoindBinary: sourceBitcoindBinary.path,\n };\n}\n\nfunction findBitcoinCoreDaemonBinary(\n root: string,\n): { name: string; path: string } | undefined {\n for (const name of ['bitcoind', 'bitcoin-node', 'bitcoin']) {\n const path = findExecutable(root, name);\n if (path) {\n return { name, path };\n }\n }\n\n return undefined;\n}\n\nfunction findExecutable(root: string, name: string): string | undefined {\n if (!existsSync(root)) {\n return undefined;\n }\n\n for (const entry of readdirSync(root)) {\n const entryPath = join(root, entry);\n const stat = statSync(entryPath);\n if (stat.isDirectory()) {\n const found = findExecutable(entryPath, name);\n if (found) {\n return found;\n }\n } else if (entry === name) {\n return entryPath;\n }\n }\n\n return undefined;\n}\n\nfunction resolvePlatformConfig(\n config: BitcoinRegtestArtifactConfig,\n platform: string,\n label: string,\n): BitcoinRegtestArtifactPlatformConfig {\n const platformConfig = config.platforms[platform] ?? config.platforms.current;\n\n if (!platformConfig) {\n throw new Error(`No ${label} is configured for ${platform}.`);\n }\n\n return platformConfig;\n}\n\nfunction requireCompletePlatformConfig(\n config: Partial<BitcoinRegtestArtifactPlatformConfig>,\n label: string,\n): BitcoinRegtestArtifactPlatformConfig {\n if (!config.url || !config.checksum) {\n throw new Error(`${label} require both a URL and a checksum.`);\n }\n\n return {\n checksum: config.checksum,\n url: config.url,\n };\n}\n\nfunction getCacheKey(config: BitcoinRegtestArtifactPlatformConfig): string {\n return createHash('sha256')\n .update(`${config.url}:${config.checksum}`)\n .digest('hex');\n}\n\nasync function verifyFileChecksum(\n filePath: string,\n expectedChecksum: string,\n label: string,\n): Promise<void> {\n const checksum = createHash('sha256')\n .update(await readFile(filePath))\n .digest('hex');\n\n if (checksum !== expectedChecksum) {\n throw new Error(\n `${label} checksum mismatch. Expected ${expectedChecksum}, got ${checksum}.`,\n );\n }\n}\n\nasync function downloadFileFromUrl(\n url: string,\n destination: string,\n): Promise<void> {\n await mkdir(dirname(destination), { recursive: true });\n await pipeline(\n await openDownloadStream(new URL(url)),\n createWriteStream(destination),\n );\n}\n\nasync function openDownloadStream(\n url: URL,\n redirectsRemaining = 5,\n): Promise<NodeJS.ReadableStream> {\n const request = url.protocol === 'http:' ? requestHttp : requestHttps;\n\n return await new Promise((resolvePromise, rejectPromise) => {\n const req = request(url, (response) => {\n const { headers, statusCode, statusMessage } = response;\n\n if (\n statusCode &&\n statusCode >= 300 &&\n statusCode < 400 &&\n headers.location\n ) {\n response.resume();\n if (redirectsRemaining <= 0) {\n rejectPromise(new Error(`Too many redirects downloading ${url}`));\n return;\n }\n\n openDownloadStream(\n new URL(headers.location, url),\n redirectsRemaining - 1,\n )\n .then(resolvePromise)\n .catch(rejectPromise);\n return;\n }\n\n if (!statusCode || statusCode < 200 || statusCode >= 300) {\n response.resume();\n rejectPromise(\n new Error(\n `Request to ${url} failed with ${statusCode ?? 'unknown'} ${\n statusMessage ?? ''\n }`.trim(),\n ),\n );\n return;\n }\n\n resolvePromise(response);\n });\n\n req.on('error', rejectPromise);\n req.end();\n });\n}\n\nasync function extractTarGzArchive(\n archivePath: string,\n destination: string,\n): Promise<void> {\n await runCommand('tar', ['-xzf', archivePath, '-C', destination]);\n}\n\nasync function runCommand(command: string, args: string[]): Promise<void> {\n await new Promise<void>((resolvePromise, rejectPromise) => {\n const child = spawn(command, args, {\n shell: false,\n stdio: ['ignore', 'ignore', 'pipe'],\n });\n let stderr = '';\n\n child.stderr.on('data', (chunk) => {\n stderr += chunk.toString();\n });\n child.on('error', rejectPromise);\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolvePromise();\n return;\n }\n const exitStatus = signal ? `signal ${signal}` : `code ${code ?? 'null'}`;\n rejectPromise(\n new Error(\n `${command} ${args.join(' ')} failed with ${exitStatus}: ${stderr}`,\n ),\n );\n });\n });\n}\n\nfunction getPlatformKey(): string {\n const platform = osPlatform();\n const arch = osArch();\n\n if (platform === 'darwin' && arch === 'arm64') {\n return 'darwin-arm64';\n }\n if (platform === 'darwin' && arch === 'x64') {\n return 'darwin-x64';\n }\n if (platform === 'linux' && arch === 'arm64') {\n return 'linux-arm64';\n }\n if (platform === 'linux' && arch === 'x64') {\n return 'linux-x64';\n }\n\n return `${platform}-${arch}`;\n}\n\nfunction readCliValue(arg: string, value: string | undefined): string {\n if (!value || value.startsWith('--')) {\n throw new Error(`${arg} requires a value.`);\n }\n\n return value;\n}\n\nfunction isFileMissingError(error: unknown): boolean {\n return (\n typeof error === 'object' &&\n error !== null &&\n Object.prototype.hasOwnProperty.call(error, 'code') &&\n (error as NodeJS.ErrnoException).code === 'ENOENT'\n );\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type BitcoinRegtestArtifactConfig = {
|
|
2
|
+
platforms: Record<string, BitcoinRegtestArtifactPlatformConfig | undefined>;
|
|
3
|
+
version?: string;
|
|
4
|
+
};
|
|
5
|
+
export type BitcoinRegtestArtifactPlatformConfig = {
|
|
6
|
+
checksum: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
url: string;
|
|
9
|
+
};
|
|
10
|
+
export type BitcoinRegtestInstallOptions = {
|
|
11
|
+
binDirectory?: string;
|
|
12
|
+
bitcoinCore?: BitcoinRegtestArtifactConfig;
|
|
13
|
+
cacheDirectory?: string;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
platform?: string;
|
|
16
|
+
};
|
|
17
|
+
export type BitcoinRegtestInstallResult = {
|
|
18
|
+
bitcoinCliBinary: string;
|
|
19
|
+
bitcoindBinary: string;
|
|
20
|
+
cacheHit: boolean;
|
|
21
|
+
checksum: string;
|
|
22
|
+
sourceBitcoindArgs: string[];
|
|
23
|
+
sourceBitcoinCliBinary: string;
|
|
24
|
+
sourceBitcoindBinary: string;
|
|
25
|
+
version?: string;
|
|
26
|
+
};
|
|
27
|
+
export type BitcoinRegtestInstallDependencies = {
|
|
28
|
+
downloadFile?: (url: string, destination: string) => Promise<void>;
|
|
29
|
+
extractArchive?: (archivePath: string, destination: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export declare const BITCOIN_REGTEST_DEFAULT_CORE: BitcoinRegtestArtifactConfig;
|
|
32
|
+
export declare function getBitcoinRegtestCacheDirectory({ cwd, homeDirectory, }?: {
|
|
33
|
+
cwd?: string;
|
|
34
|
+
homeDirectory?: string;
|
|
35
|
+
}): string;
|
|
36
|
+
export declare function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd, packageJsonPath, }?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
packageJsonPath?: string;
|
|
39
|
+
}): BitcoinRegtestInstallOptions;
|
|
40
|
+
export declare function parseBitcoinRegtestInstallCliOptions(args: string[]): BitcoinRegtestInstallOptions;
|
|
41
|
+
export declare function installBitcoinRegtest(options?: BitcoinRegtestInstallOptions, dependencies?: BitcoinRegtestInstallDependencies): Promise<BitcoinRegtestInstallResult>;
|
|
42
|
+
export declare function cleanBitcoinRegtestCache(options?: Pick<BitcoinRegtestInstallOptions, 'cacheDirectory' | 'cwd'>): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=install.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.cts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AA4BA,MAAM,MAAM,4BAA4B,GAAG;IACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,oCAAoC,GAAG,SAAS,CAAC,CAAC;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAA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AC5C,OAAO,GAAE,IAAI,CAAC,4BAA4B,EAAE,gBAAgB,GAAG,KAAK,CAAM,GACzE,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type BitcoinRegtestArtifactConfig = {
|
|
2
|
+
platforms: Record<string, BitcoinRegtestArtifactPlatformConfig | undefined>;
|
|
3
|
+
version?: string;
|
|
4
|
+
};
|
|
5
|
+
export type BitcoinRegtestArtifactPlatformConfig = {
|
|
6
|
+
checksum: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
url: string;
|
|
9
|
+
};
|
|
10
|
+
export type BitcoinRegtestInstallOptions = {
|
|
11
|
+
binDirectory?: string;
|
|
12
|
+
bitcoinCore?: BitcoinRegtestArtifactConfig;
|
|
13
|
+
cacheDirectory?: string;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
platform?: string;
|
|
16
|
+
};
|
|
17
|
+
export type BitcoinRegtestInstallResult = {
|
|
18
|
+
bitcoinCliBinary: string;
|
|
19
|
+
bitcoindBinary: string;
|
|
20
|
+
cacheHit: boolean;
|
|
21
|
+
checksum: string;
|
|
22
|
+
sourceBitcoindArgs: string[];
|
|
23
|
+
sourceBitcoinCliBinary: string;
|
|
24
|
+
sourceBitcoindBinary: string;
|
|
25
|
+
version?: string;
|
|
26
|
+
};
|
|
27
|
+
export type BitcoinRegtestInstallDependencies = {
|
|
28
|
+
downloadFile?: (url: string, destination: string) => Promise<void>;
|
|
29
|
+
extractArchive?: (archivePath: string, destination: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export declare const BITCOIN_REGTEST_DEFAULT_CORE: BitcoinRegtestArtifactConfig;
|
|
32
|
+
export declare function getBitcoinRegtestCacheDirectory({ cwd, homeDirectory, }?: {
|
|
33
|
+
cwd?: string;
|
|
34
|
+
homeDirectory?: string;
|
|
35
|
+
}): string;
|
|
36
|
+
export declare function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd, packageJsonPath, }?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
packageJsonPath?: string;
|
|
39
|
+
}): BitcoinRegtestInstallOptions;
|
|
40
|
+
export declare function parseBitcoinRegtestInstallCliOptions(args: string[]): BitcoinRegtestInstallOptions;
|
|
41
|
+
export declare function installBitcoinRegtest(options?: BitcoinRegtestInstallOptions, dependencies?: BitcoinRegtestInstallDependencies): Promise<BitcoinRegtestInstallResult>;
|
|
42
|
+
export declare function cleanBitcoinRegtestCache(options?: Pick<BitcoinRegtestInstallOptions, 'cacheDirectory' | 'cwd'>): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=install.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.mts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AA4BA,MAAM,MAAM,4BAA4B,GAAG;IACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,oCAAoC,GAAG,SAAS,CAAC,CAAC;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,sBAAsB,EAAE,MAAM,C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