@metamask-previews/bitcoin-regtest-up 1.0.0-preview-8bfa290fb → 2.0.0-preview-0a30e47

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 CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
15
+ - This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
16
+ - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
17
+ - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
18
+ - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
19
+ - Bump `@metamask/local-node-utils` from `^1.0.0` to `^2.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
20
+
10
21
  ## [1.0.0]
11
22
 
12
23
  ### Added
@@ -16,5 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
27
  - Exposes `bitcoin-regtest-up`, `bitcoind`, and `bitcoin-cli` binaries via `node_modules/.bin`
17
28
  - Uses `@metamask/local-node-utils` for cache resolution, downloads, and executable wrappers
18
29
 
19
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bitcoin-regtest-up@1.0.0...HEAD
30
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bitcoin-regtest-up@2.0.0...HEAD
31
+ [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/bitcoin-regtest-up@1.0.0...@metamask/bitcoin-regtest-up@2.0.0
20
32
  [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/bitcoin-regtest-up@1.0.0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bitcoin-regtest-up.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitcoin-regtest-up.d.ts","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":""}
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable no-restricted-globals */
3
- import { cleanBitcoinRegtestCache, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson } from "../install.mjs";
3
+ import { cleanBitcoinRegtestCache, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson, } from '../install.js';
4
4
  async function main() {
5
5
  const [command, ...args] = process.argv.slice(2);
6
6
  if (command === '--help' || command === 'help') {
@@ -45,4 +45,4 @@ Options:
45
45
  --platform <platform> Override platform key, e.g. linux-x64.
46
46
  --help Show this help text.`);
47
47
  }
48
- //# sourceMappingURL=bitcoin-regtest-up.mjs.map
48
+ //# sourceMappingURL=bitcoin-regtest-up.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitcoin-regtest-up.js","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":";AACA,0CAA0C;AAC1C,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,GAChD,MAAM,eAAe,CAAC;AAEvB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC/C,SAAS,EAAE,CAAC;QACZ,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QAC/C,MAAM,wBAAwB,CAAC;YAC7B,GAAG,+CAA+C,EAAE;YACpD,GAAG,oCAAoC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvD,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAClD,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC;QACzC,GAAG,+CAA+C,EAAE;QACpD,GAAG,oCAAoC,CAAC,WAAW,CAAC;KACrD,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,qCACE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WACvC,EAAE,CACH,CAAC;IACF,OAAO,CAAC,GAAG,CACT,8CAA8C,MAAM,CAAC,cAAc,EAAE,CACtE,CAAC;IACF,OAAO,CAAC,GAAG,CACT,iDAAiD,MAAM,CAAC,gBAAgB,EAAE,CAC3E,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;uDAcyC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-restricted-globals */\nimport {\n cleanBitcoinRegtestCache,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from '../install.js';\n\nasync function main(): Promise<void> {\n const [command, ...args] = process.argv.slice(2);\n\n if (command === '--help' || command === 'help') {\n printHelp();\n return;\n }\n\n if (command === 'cache' && args[0] === 'clean') {\n await cleanBitcoinRegtestCache({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(args.slice(1)),\n });\n console.log('[bitcoin-regtest-up] cache cleaned');\n return;\n }\n\n const installArgs = command === 'install' ? args : process.argv.slice(2);\n const result = await installBitcoinRegtest({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(installArgs),\n });\n\n console.log(\n `[bitcoin-regtest-up] Bitcoin Core ${\n result.cacheHit ? 'found in cache' : 'installed'\n }`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoind installed at ${result.bitcoindBinary}`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoin-cli installed at ${result.bitcoinCliBinary}`,\n );\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exit(1);\n});\n\nfunction printHelp(): void {\n console.log(`Usage: bitcoin-regtest-up [install] [options]\n bitcoin-regtest-up cache clean [options]\n\nCommands:\n install Install Bitcoin Core bitcoind and bitcoin-cli. Default command.\n cache clean Remove cached bitcoin-regtest-up artifacts.\n\nOptions:\n --bin-directory <path> Directory for executable wrappers.\n Defaults to node_modules/.bin.\n --cache-directory <path> Cache directory. Defaults to .metamask/cache.\n --bitcoin-core-url <url> Bitcoin Core archive URL for the current platform.\n --bitcoin-core-checksum <hash> Expected Bitcoin Core SHA-256 checksum.\n --platform <platform> Override platform key, e.g. linux-x64.\n --help Show this help text.`);\n}\n"]}
@@ -1,3 +1,3 @@
1
- export { BITCOIN_REGTEST_DEFAULT_CORE, cleanBitcoinRegtestCache, getBitcoinRegtestCacheDirectory, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson, } from "./install.cjs";
2
- export type { BitcoinRegtestArtifactConfig, BitcoinRegtestArtifactPlatformConfig, BitcoinRegtestInstallDependencies, BitcoinRegtestInstallOptions, BitcoinRegtestInstallResult, } from "./install.cjs";
3
- //# sourceMappingURL=index.d.cts.map
1
+ export { BITCOIN_REGTEST_DEFAULT_CORE, cleanBitcoinRegtestCache, getBitcoinRegtestCacheDirectory, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson, } from './install.js';
2
+ export type { BitcoinRegtestArtifactConfig, BitcoinRegtestArtifactPlatformConfig, BitcoinRegtestInstallDependencies, BitcoinRegtestInstallOptions, BitcoinRegtestInstallResult, } from './install.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,GAChD,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,iCAAiC,EACjC,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,cAAc,CAAC"}
@@ -1,2 +1,2 @@
1
- export { BITCOIN_REGTEST_DEFAULT_CORE, cleanBitcoinRegtestCache, getBitcoinRegtestCacheDirectory, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson } from "./install.mjs";
2
- //# sourceMappingURL=index.mjs.map
1
+ export { BITCOIN_REGTEST_DEFAULT_CORE, cleanBitcoinRegtestCache, getBitcoinRegtestCacheDirectory, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson, } from './install.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,GAChD,MAAM,cAAc,CAAC","sourcesContent":["export {\n BITCOIN_REGTEST_DEFAULT_CORE,\n cleanBitcoinRegtestCache,\n getBitcoinRegtestCacheDirectory,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from './install.js';\nexport type {\n BitcoinRegtestArtifactConfig,\n BitcoinRegtestArtifactPlatformConfig,\n BitcoinRegtestInstallDependencies,\n BitcoinRegtestInstallOptions,\n BitcoinRegtestInstallResult,\n} from './install.js';\n"]}
@@ -1,4 +1,4 @@
1
- import type { ArtifactConfig, ArtifactPlatformConfig, InstallDependencies } from "@metamask/local-node-utils";
1
+ import type { ArtifactConfig, ArtifactPlatformConfig, InstallDependencies } from '@metamask/local-node-utils';
2
2
  export type BitcoinRegtestArtifactConfig = ArtifactConfig;
3
3
  export type BitcoinRegtestArtifactPlatformConfig = ArtifactPlatformConfig;
4
4
  export type BitcoinRegtestInstallOptions = {
@@ -31,4 +31,4 @@ export declare function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd, p
31
31
  export declare function parseBitcoinRegtestInstallCliOptions(args: string[]): BitcoinRegtestInstallOptions;
32
32
  export declare function installBitcoinRegtest(options?: BitcoinRegtestInstallOptions, dependencies?: BitcoinRegtestInstallDependencies): Promise<BitcoinRegtestInstallResult>;
33
33
  export declare function cleanBitcoinRegtestCache(options?: Pick<BitcoinRegtestInstallOptions, 'cacheDirectory' | 'cwd'>): Promise<void>;
34
- //# sourceMappingURL=install.d.cts.map
34
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAQpC,MAAM,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE1D,MAA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E,IAAI,CAAC,4BAA4B,EAAE,gBAAgB,GAAG,KAAK,CAAM,GACzE,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable import-x/no-nodejs-modules, no-restricted-globals */
2
- import { cleanInstallerCache, downloadFileFromUrl, extractTarGzArchive, findExecutable, getCacheKey, getMetamaskCacheDirectory, getPlatformKey, installExecutableWrapper, mergeArtifactConfig, readCliValue, readPackageJsonToolConfig, requireCompletePlatformConfig, resolvePlatformConfig, runCommand, verifyFileChecksum } from "@metamask/local-node-utils";
3
- import { existsSync, readFileSync } from "node:fs";
4
- import { mkdir, rename, rm, writeFile } from "node:fs/promises";
5
- import { dirname, join } from "node:path";
2
+ import { cleanInstallerCache, downloadFileFromUrl, extractTarGzArchive, findExecutable, getCacheKey, getMetamaskCacheDirectory, getPlatformKey, installExecutableWrapper, mergeArtifactConfig, readCliValue, readPackageJsonToolConfig, requireCompletePlatformConfig, resolvePlatformConfig, runCommand, verifyFileChecksum, } from '@metamask/local-node-utils';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
5
+ import { dirname, join } from 'node:path';
6
6
  const BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';
7
7
  const BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';
8
8
  export const BITCOIN_REGTEST_DEFAULT_CORE = {
@@ -211,4 +211,4 @@ function findBitcoinCoreDaemonBinary(root) {
211
211
  }
212
212
  return undefined;
213
213
  }
214
- //# sourceMappingURL=install.mjs.map
214
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,mBA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;AAED,KAAK,UAAU,iCAAiC,CAAC,QAIhD;IACC,MAAM,UAAU,CAAC,QAAQ,CAAC,oBAAoB,EAAE;QAC9C,GAAG,QAAQ,CAAC,kBAAkB;QAC9B,UAAU;KACX,CAAC,CAAC;IACH,MAAM,UAAU,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY;IAO3C,MAAM,sBAAsB,GAAG,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACnE,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAE/D,IAAI,CAAC,oBAAoB,IAAI,CAAC,sBAAsB,EAAE,CAAC;QACrD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO;QACL,kBAAkB,EAAE,oBAAoB,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;QAC3E,sBAAsB;QACtB,oBAAoB,EAAE,oBAAoB,CAAC,IAAI;KAChD,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAAY;IAEZ,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/* eslint-disable import-x/no-nodejs-modules, no-restricted-globals */\nimport {\n cleanInstallerCache,\n downloadFileFromUrl,\n extractTarGzArchive,\n findExecutable,\n getCacheKey,\n getMetamaskCacheDirectory,\n getPlatformKey,\n installExecutableWrapper,\n mergeArtifactConfig,\n readCliValue,\n readPackageJsonToolConfig,\n requireCompletePlatformConfig,\n resolvePlatformConfig,\n runCommand,\n verifyFileChecksum,\n} from '@metamask/local-node-utils';\nimport type {\n ArtifactConfig,\n ArtifactPlatformConfig,\n InstallDependencies,\n} from '@metamask/local-node-utils';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rename, rm, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\n\nconst BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';\nconst BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';\n\nexport type BitcoinRegtestArtifactConfig = ArtifactConfig;\n\nexport type BitcoinRegtestArtifactPlatformConfig = ArtifactPlatformConfig;\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 = InstallDependencies;\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,\n}: {\n cwd?: string;\n homeDirectory?: string;\n} = {}): string {\n return getMetamaskCacheDirectory({\n cwd,\n homeDirectory,\n toolName: BITCOIN_REGTEST_CACHE_NAMESPACE,\n });\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 config = readPackageJsonToolConfig({\n cwd,\n packageJsonPath,\n configKeys: ['bitcoinRegtestUp', 'bitcoinregtestup', 'bitcoin-regtest-up'],\n }) as Partial<BitcoinRegtestPackageJsonConfig>;\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 = mergeArtifactConfig(\n BITCOIN_REGTEST_DEFAULT_CORE,\n options.bitcoinCore,\n );\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 pathResolution: 'absolute',\n });\n const bitcoinCliBinary = await installExecutableWrapper({\n binDirectory,\n commandName: 'bitcoin-cli',\n executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,\n pathResolution: 'absolute',\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 cleanInstallerCache({\n cacheDirectory,\n namespace: BITCOIN_REGTEST_CACHE_NAMESPACE,\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 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/bitcoin-regtest-up",
3
- "version": "1.0.0-preview-8bfa290fb",
3
+ "version": "2.0.0-preview-0a30e47",
4
4
  "description": "Bitcoin Core regtest runtime installer for MetaMask E2E tests",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -15,23 +15,16 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/MetaMask/core.git"
17
17
  },
18
- "bin": "./dist/bin/bitcoin-regtest-up.mjs",
18
+ "bin": "./dist/bin/bitcoin-regtest-up.js",
19
19
  "files": [
20
20
  "dist/"
21
21
  ],
22
+ "type": "module",
22
23
  "sideEffects": false,
23
- "main": "./dist/index.cjs",
24
- "types": "./dist/index.d.cts",
25
24
  "exports": {
26
25
  ".": {
27
- "import": {
28
- "types": "./dist/index.d.mts",
29
- "default": "./dist/index.mjs"
30
- },
31
- "require": {
32
- "types": "./dist/index.d.cts",
33
- "default": "./dist/index.cjs"
34
- }
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
35
28
  },
36
29
  "./package.json": "./package.json"
37
30
  },
@@ -40,9 +33,11 @@
40
33
  "registry": "https://registry.npmjs.org/"
41
34
  },
42
35
  "scripts": {
43
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
44
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
36
+ "build": "tsc --project tsconfig.build.json",
37
+ "build:all": "tsc --build tsconfig.build.json --verbose",
38
+ "build:clean": "yarn build:only-clean && yarn build",
45
39
  "build:docs": "typedoc",
40
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
46
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/bitcoin-regtest-up",
47
42
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/bitcoin-regtest-up",
48
43
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -56,21 +51,22 @@
56
51
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
57
52
  },
58
53
  "dependencies": {
59
- "@metamask/local-node-utils": "^1.0.0"
54
+ "@metamask/local-node-utils": "^2.0.0"
60
55
  },
61
56
  "devDependencies": {
62
57
  "@metamask/auto-changelog": "^6.1.0",
63
- "@ts-bridge/cli": "^0.6.4",
64
58
  "@types/jest": "^30.0.0",
59
+ "@typescript/native": "npm:typescript@^7.0.2",
65
60
  "deepmerge": "^4.2.2",
66
61
  "jest": "^30.4.2",
62
+ "rimraf": "^5.0.5",
67
63
  "ts-jest": "^29.4.11",
68
64
  "tsx": "^4.20.5",
69
65
  "typedoc": "^0.25.13",
70
66
  "typedoc-plugin-missing-exports": "^2.0.0",
71
- "typescript": "~5.3.3"
67
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
72
68
  },
73
69
  "engines": {
74
- "node": "^18.18 || >=20"
70
+ "node": "^22.14.0 || ^24"
75
71
  }
76
72
  }
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /* eslint-disable no-restricted-globals */
5
- const install_js_1 = require("../install.cjs");
6
- async function main() {
7
- const [command, ...args] = process.argv.slice(2);
8
- if (command === '--help' || command === 'help') {
9
- printHelp();
10
- return;
11
- }
12
- if (command === 'cache' && args[0] === 'clean') {
13
- await (0, install_js_1.cleanBitcoinRegtestCache)({
14
- ...(0, install_js_1.readBitcoinRegtestInstallOptionsFromPackageJson)(),
15
- ...(0, install_js_1.parseBitcoinRegtestInstallCliOptions)(args.slice(1)),
16
- });
17
- console.log('[bitcoin-regtest-up] cache cleaned');
18
- return;
19
- }
20
- const installArgs = command === 'install' ? args : process.argv.slice(2);
21
- const result = await (0, install_js_1.installBitcoinRegtest)({
22
- ...(0, install_js_1.readBitcoinRegtestInstallOptionsFromPackageJson)(),
23
- ...(0, install_js_1.parseBitcoinRegtestInstallCliOptions)(installArgs),
24
- });
25
- console.log(`[bitcoin-regtest-up] Bitcoin Core ${result.cacheHit ? 'found in cache' : 'installed'}`);
26
- console.log(`[bitcoin-regtest-up] bitcoind installed at ${result.bitcoindBinary}`);
27
- console.log(`[bitcoin-regtest-up] bitcoin-cli installed at ${result.bitcoinCliBinary}`);
28
- }
29
- main().catch((error) => {
30
- console.error(error);
31
- process.exit(1);
32
- });
33
- function printHelp() {
34
- console.log(`Usage: bitcoin-regtest-up [install] [options]
35
- bitcoin-regtest-up cache clean [options]
36
-
37
- Commands:
38
- install Install Bitcoin Core bitcoind and bitcoin-cli. Default command.
39
- cache clean Remove cached bitcoin-regtest-up artifacts.
40
-
41
- Options:
42
- --bin-directory <path> Directory for executable wrappers.
43
- Defaults to node_modules/.bin.
44
- --cache-directory <path> Cache directory. Defaults to .metamask/cache.
45
- --bitcoin-core-url <url> Bitcoin Core archive URL for the current platform.
46
- --bitcoin-core-checksum <hash> Expected Bitcoin Core SHA-256 checksum.
47
- --platform <platform> Override platform key, e.g. linux-x64.
48
- --help Show this help text.`);
49
- }
50
- //# sourceMappingURL=bitcoin-regtest-up.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bitcoin-regtest-up.cjs","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":";;;AACA,0CAA0C;AAC1C,+CAKuB;AAEvB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE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;;;uDAcyC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-restricted-globals */\nimport {\n cleanBitcoinRegtestCache,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from '../install.js';\n\nasync function main(): Promise<void> {\n const [command, ...args] = process.argv.slice(2);\n\n if (command === '--help' || command === 'help') {\n printHelp();\n return;\n }\n\n if (command === 'cache' && args[0] === 'clean') {\n await cleanBitcoinRegtestCache({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(args.slice(1)),\n });\n console.log('[bitcoin-regtest-up] cache cleaned');\n return;\n }\n\n const installArgs = command === 'install' ? args : process.argv.slice(2);\n const result = await installBitcoinRegtest({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(installArgs),\n });\n\n console.log(\n `[bitcoin-regtest-up] Bitcoin Core ${\n result.cacheHit ? 'found in cache' : 'installed'\n }`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoind installed at ${result.bitcoindBinary}`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoin-cli installed at ${result.bitcoinCliBinary}`,\n );\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exit(1);\n});\n\nfunction printHelp(): void {\n console.log(`Usage: bitcoin-regtest-up [install] [options]\n bitcoin-regtest-up cache clean [options]\n\nCommands:\n install Install Bitcoin Core bitcoind and bitcoin-cli. Default command.\n cache clean Remove cached bitcoin-regtest-up artifacts.\n\nOptions:\n --bin-directory <path> Directory for executable wrappers.\n Defaults to node_modules/.bin.\n --cache-directory <path> Cache directory. Defaults to .metamask/cache.\n --bitcoin-core-url <url> Bitcoin Core archive URL for the current platform.\n --bitcoin-core-checksum <hash> Expected Bitcoin Core SHA-256 checksum.\n --platform <platform> Override platform key, e.g. linux-x64.\n --help Show this help text.`);\n}\n"]}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=bitcoin-regtest-up.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bitcoin-regtest-up.d.cts","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=bitcoin-regtest-up.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bitcoin-regtest-up.d.mts","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"bitcoin-regtest-up.mjs","sourceRoot":"","sources":["../../src/bin/bitcoin-regtest-up.ts"],"names":[],"mappings":";AACA,0CAA0C;AAC1C,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,EAChD,uBAAsB;AAEvB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC/C,SAAS,EAAE,CAAC;QACZ,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QAC/C,MAAM,wBAAwB,CAAC;YAC7B,GAAG,+CAA+C,EAAE;YACpD,GAAG,oCAAoC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvD,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAClD,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC;QACzC,GAAG,+CAA+C,EAAE;QACpD,GAAG,oCAAoC,CAAC,WAAW,CAAC;KACrD,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,qCACE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WACvC,EAAE,CACH,CAAC;IACF,OAAO,CAAC,GAAG,CACT,8CAA8C,MAAM,CAAC,cAAc,EAAE,CACtE,CAAC;IACF,OAAO,CAAC,GAAG,CACT,iDAAiD,MAAM,CAAC,gBAAgB,EAAE,CAC3E,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;uDAcyC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-restricted-globals */\nimport {\n cleanBitcoinRegtestCache,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from '../install.js';\n\nasync function main(): Promise<void> {\n const [command, ...args] = process.argv.slice(2);\n\n if (command === '--help' || command === 'help') {\n printHelp();\n return;\n }\n\n if (command === 'cache' && args[0] === 'clean') {\n await cleanBitcoinRegtestCache({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(args.slice(1)),\n });\n console.log('[bitcoin-regtest-up] cache cleaned');\n return;\n }\n\n const installArgs = command === 'install' ? args : process.argv.slice(2);\n const result = await installBitcoinRegtest({\n ...readBitcoinRegtestInstallOptionsFromPackageJson(),\n ...parseBitcoinRegtestInstallCliOptions(installArgs),\n });\n\n console.log(\n `[bitcoin-regtest-up] Bitcoin Core ${\n result.cacheHit ? 'found in cache' : 'installed'\n }`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoind installed at ${result.bitcoindBinary}`,\n );\n console.log(\n `[bitcoin-regtest-up] bitcoin-cli installed at ${result.bitcoinCliBinary}`,\n );\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exit(1);\n});\n\nfunction printHelp(): void {\n console.log(`Usage: bitcoin-regtest-up [install] [options]\n bitcoin-regtest-up cache clean [options]\n\nCommands:\n install Install Bitcoin Core bitcoind and bitcoin-cli. Default command.\n cache clean Remove cached bitcoin-regtest-up artifacts.\n\nOptions:\n --bin-directory <path> Directory for executable wrappers.\n Defaults to node_modules/.bin.\n --cache-directory <path> Cache directory. Defaults to .metamask/cache.\n --bitcoin-core-url <url> Bitcoin Core archive URL for the current platform.\n --bitcoin-core-checksum <hash> Expected Bitcoin Core SHA-256 checksum.\n --platform <platform> Override platform key, e.g. linux-x64.\n --help Show this help text.`);\n}\n"]}
package/dist/index.cjs DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readBitcoinRegtestInstallOptionsFromPackageJson = exports.parseBitcoinRegtestInstallCliOptions = exports.installBitcoinRegtest = exports.getBitcoinRegtestCacheDirectory = exports.cleanBitcoinRegtestCache = exports.BITCOIN_REGTEST_DEFAULT_CORE = void 0;
4
- var install_js_1 = require("./install.cjs");
5
- Object.defineProperty(exports, "BITCOIN_REGTEST_DEFAULT_CORE", { enumerable: true, get: function () { return install_js_1.BITCOIN_REGTEST_DEFAULT_CORE; } });
6
- Object.defineProperty(exports, "cleanBitcoinRegtestCache", { enumerable: true, get: function () { return install_js_1.cleanBitcoinRegtestCache; } });
7
- Object.defineProperty(exports, "getBitcoinRegtestCacheDirectory", { enumerable: true, get: function () { return install_js_1.getBitcoinRegtestCacheDirectory; } });
8
- Object.defineProperty(exports, "installBitcoinRegtest", { enumerable: true, get: function () { return install_js_1.installBitcoinRegtest; } });
9
- Object.defineProperty(exports, "parseBitcoinRegtestInstallCliOptions", { enumerable: true, get: function () { return install_js_1.parseBitcoinRegtestInstallCliOptions; } });
10
- Object.defineProperty(exports, "readBitcoinRegtestInstallOptionsFromPackageJson", { enumerable: true, get: function () { return install_js_1.readBitcoinRegtestInstallOptionsFromPackageJson; } });
11
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4CAOsB;AANpB,0HAAA,4BAA4B,OAAA;AAC5B,sHAAA,wBAAwB,OAAA;AACxB,6HAAA,+BAA+B,OAAA;AAC/B,mHAAA,qBAAqB,OAAA;AACrB,kIAAA,oCAAoC,OAAA;AACpC,6IAAA,+CAA+C,OAAA","sourcesContent":["export {\n BITCOIN_REGTEST_DEFAULT_CORE,\n cleanBitcoinRegtestCache,\n getBitcoinRegtestCacheDirectory,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from './install.js';\nexport type {\n BitcoinRegtestArtifactConfig,\n BitcoinRegtestArtifactPlatformConfig,\n BitcoinRegtestInstallDependencies,\n BitcoinRegtestInstallOptions,\n BitcoinRegtestInstallResult,\n} from './install.js';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,GAChD,sBAAqB;AACtB,YAAY,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,iCAAiC,EACjC,4BAA4B,EAC5B,2BAA2B,GAC5B,sBAAqB"}
package/dist/index.d.mts DELETED
@@ -1,3 +0,0 @@
1
- export { BITCOIN_REGTEST_DEFAULT_CORE, cleanBitcoinRegtestCache, getBitcoinRegtestCacheDirectory, installBitcoinRegtest, parseBitcoinRegtestInstallCliOptions, readBitcoinRegtestInstallOptionsFromPackageJson, } from "./install.mjs";
2
- export type { BitcoinRegtestArtifactConfig, BitcoinRegtestArtifactPlatformConfig, BitcoinRegtestInstallDependencies, BitcoinRegtestInstallOptions, BitcoinRegtestInstallResult, } from "./install.mjs";
3
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,GAChD,sBAAqB;AACtB,YAAY,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,iCAAiC,EACjC,4BAA4B,EAC5B,2BAA2B,GAC5B,sBAAqB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,oCAAoC,EACpC,+CAA+C,EAChD,sBAAqB","sourcesContent":["export {\n BITCOIN_REGTEST_DEFAULT_CORE,\n cleanBitcoinRegtestCache,\n getBitcoinRegtestCacheDirectory,\n installBitcoinRegtest,\n parseBitcoinRegtestInstallCliOptions,\n readBitcoinRegtestInstallOptionsFromPackageJson,\n} from './install.js';\nexport type {\n BitcoinRegtestArtifactConfig,\n BitcoinRegtestArtifactPlatformConfig,\n BitcoinRegtestInstallDependencies,\n BitcoinRegtestInstallOptions,\n BitcoinRegtestInstallResult,\n} from './install.js';\n"]}
package/dist/install.cjs DELETED
@@ -1,222 +0,0 @@
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 local_node_utils_1 = require("@metamask/local-node-utils");
6
- const node_fs_1 = require("node:fs");
7
- const promises_1 = require("node:fs/promises");
8
- const node_path_1 = require("node:path");
9
- const BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';
10
- const BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';
11
- exports.BITCOIN_REGTEST_DEFAULT_CORE = {
12
- version: '30.2',
13
- platforms: {
14
- 'darwin-arm64': {
15
- checksum: 'c2ecab62891de22228043815cb6211549a32272be3d5d052ff19847d3420bd10',
16
- url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-arm64-apple-darwin.tar.gz',
17
- },
18
- 'darwin-x64': {
19
- checksum: '99d5cee9b9c37be506396c30837a4b98e320bfea71c474d6120a7e8eb6075c7b',
20
- url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-apple-darwin.tar.gz',
21
- },
22
- 'linux-arm64': {
23
- checksum: '73e76c14edc79808a0511c744d102ffbb494807ee90cbcba176568243254b532',
24
- url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-aarch64-linux-gnu.tar.gz',
25
- },
26
- 'linux-x64': {
27
- checksum: '6aa7bb4feb699c4c6262dd23e4004191f6df7f373b5d5978b5bcdd4bb72f75d8',
28
- url: 'https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz',
29
- },
30
- },
31
- };
32
- function getBitcoinRegtestCacheDirectory({ cwd = process.cwd(), homeDirectory, } = {}) {
33
- return (0, local_node_utils_1.getMetamaskCacheDirectory)({
34
- cwd,
35
- homeDirectory,
36
- toolName: BITCOIN_REGTEST_CACHE_NAMESPACE,
37
- });
38
- }
39
- exports.getBitcoinRegtestCacheDirectory = getBitcoinRegtestCacheDirectory;
40
- function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd = process.cwd(), packageJsonPath = (0, node_path_1.join)(cwd, 'package.json'), } = {}) {
41
- const config = (0, local_node_utils_1.readPackageJsonToolConfig)({
42
- cwd,
43
- packageJsonPath,
44
- configKeys: ['bitcoinRegtestUp', 'bitcoinregtestup', 'bitcoin-regtest-up'],
45
- });
46
- const options = {};
47
- if (config.binDirectory) {
48
- options.binDirectory = config.binDirectory;
49
- }
50
- if (config.bitcoinCore) {
51
- options.bitcoinCore = config.bitcoinCore;
52
- }
53
- if (config.cacheDirectory) {
54
- options.cacheDirectory = config.cacheDirectory;
55
- }
56
- return options;
57
- }
58
- exports.readBitcoinRegtestInstallOptionsFromPackageJson = readBitcoinRegtestInstallOptionsFromPackageJson;
59
- function parseBitcoinRegtestInstallCliOptions(args) {
60
- const options = {};
61
- const bitcoinCore = {};
62
- for (let index = 0; index < args.length; index += 1) {
63
- const arg = args[index];
64
- const value = args[index + 1];
65
- switch (arg) {
66
- case '--bin-directory':
67
- options.binDirectory = (0, local_node_utils_1.readCliValue)(arg, value);
68
- index += 1;
69
- break;
70
- case '--bitcoin-core-checksum':
71
- bitcoinCore.checksum = (0, local_node_utils_1.readCliValue)(arg, value);
72
- index += 1;
73
- break;
74
- case '--bitcoin-core-url':
75
- bitcoinCore.url = (0, local_node_utils_1.readCliValue)(arg, value);
76
- index += 1;
77
- break;
78
- case '--cache-directory':
79
- options.cacheDirectory = (0, local_node_utils_1.readCliValue)(arg, value);
80
- index += 1;
81
- break;
82
- case '--platform':
83
- options.platform = (0, local_node_utils_1.readCliValue)(arg, value);
84
- index += 1;
85
- break;
86
- default:
87
- throw new Error(`Unknown bitcoin-regtest-up install option: ${arg}`);
88
- }
89
- }
90
- if (bitcoinCore.url || bitcoinCore.checksum) {
91
- options.bitcoinCore = {
92
- platforms: {
93
- current: (0, local_node_utils_1.requireCompletePlatformConfig)(bitcoinCore, 'Bitcoin Core CLI options'),
94
- },
95
- };
96
- }
97
- return options;
98
- }
99
- exports.parseBitcoinRegtestInstallCliOptions = parseBitcoinRegtestInstallCliOptions;
100
- async function installBitcoinRegtest(options = {}, dependencies = {}) {
101
- const cwd = options.cwd ?? process.cwd();
102
- const cacheDirectory = options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });
103
- const binDirectory = options.binDirectory ?? (0, node_path_1.join)(cwd, 'node_modules', '.bin');
104
- const platformKey = options.platform ?? (0, local_node_utils_1.getPlatformKey)();
105
- const bitcoinCore = (0, local_node_utils_1.mergeArtifactConfig)(exports.BITCOIN_REGTEST_DEFAULT_CORE, options.bitcoinCore);
106
- const bitcoinCoreConfig = (0, local_node_utils_1.resolvePlatformConfig)(bitcoinCore, platformKey, 'Bitcoin Core archive');
107
- const bitcoinCoreResult = await installBitcoinCoreArchive({ cacheDirectory, config: bitcoinCoreConfig }, dependencies);
108
- const bitcoindBinary = await (0, local_node_utils_1.installExecutableWrapper)({
109
- binDirectory,
110
- commandName: 'bitcoind',
111
- executableArgs: bitcoinCoreResult.sourceBitcoindArgs,
112
- executablePath: bitcoinCoreResult.sourceBitcoindBinary,
113
- pathResolution: 'absolute',
114
- });
115
- const bitcoinCliBinary = await (0, local_node_utils_1.installExecutableWrapper)({
116
- binDirectory,
117
- commandName: 'bitcoin-cli',
118
- executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,
119
- pathResolution: 'absolute',
120
- });
121
- return {
122
- bitcoinCliBinary,
123
- bitcoindBinary,
124
- cacheHit: bitcoinCoreResult.cacheHit,
125
- checksum: bitcoinCoreConfig.checksum,
126
- sourceBitcoindArgs: bitcoinCoreResult.sourceBitcoindArgs,
127
- sourceBitcoinCliBinary: bitcoinCoreResult.sourceBitcoinCliBinary,
128
- sourceBitcoindBinary: bitcoinCoreResult.sourceBitcoindBinary,
129
- version: bitcoinCore.version,
130
- };
131
- }
132
- exports.installBitcoinRegtest = installBitcoinRegtest;
133
- async function cleanBitcoinRegtestCache(options = {}) {
134
- const cwd = options.cwd ?? process.cwd();
135
- const cacheDirectory = options.cacheDirectory ?? getBitcoinRegtestCacheDirectory({ cwd });
136
- await (0, local_node_utils_1.cleanInstallerCache)({
137
- cacheDirectory,
138
- namespace: BITCOIN_REGTEST_CACHE_NAMESPACE,
139
- });
140
- }
141
- exports.cleanBitcoinRegtestCache = cleanBitcoinRegtestCache;
142
- async function installBitcoinCoreArchive({ cacheDirectory, config, }, dependencies) {
143
- const cacheKey = (0, local_node_utils_1.getCacheKey)(config);
144
- const cacheRoot = (0, node_path_1.join)(cacheDirectory, BITCOIN_REGTEST_CACHE_NAMESPACE, BITCOIN_CORE_CACHE_NAMESPACE, cacheKey);
145
- const checksumPath = (0, node_path_1.join)(cacheRoot, '.source-checksum');
146
- const cached = findBitcoinCoreBinaries(cacheRoot);
147
- if (cached &&
148
- (0, node_fs_1.existsSync)(checksumPath) &&
149
- (0, node_fs_1.readFileSync)(checksumPath, 'utf8') === config.checksum &&
150
- (await areBitcoinCoreBinariesRunnable(cached))) {
151
- return { cacheHit: true, ...cached };
152
- }
153
- const tempRoot = `${cacheRoot}.downloading`;
154
- const archivePath = (0, node_path_1.join)(tempRoot, 'bitcoin-core.tar.gz');
155
- const downloadFile = dependencies.downloadFile ?? local_node_utils_1.downloadFileFromUrl;
156
- const extractArchive = dependencies.extractArchive ?? local_node_utils_1.extractTarGzArchive;
157
- await (0, promises_1.rm)(tempRoot, { force: true, recursive: true });
158
- await (0, promises_1.rm)(cacheRoot, { force: true, recursive: true });
159
- await (0, promises_1.mkdir)(tempRoot, { recursive: true });
160
- try {
161
- await downloadFile(config.url, archivePath);
162
- await (0, local_node_utils_1.verifyFileChecksum)(archivePath, config.checksum, 'Downloaded Bitcoin Core');
163
- await extractArchive(archivePath, tempRoot);
164
- const binaries = findBitcoinCoreBinaries(tempRoot);
165
- if (!binaries) {
166
- throw new Error('Bitcoin Core archive did not contain a node daemon (bitcoind, bitcoin-node, or bitcoin) and bin/bitcoin-cli.');
167
- }
168
- await assertBitcoinCoreBinariesRunnable(binaries);
169
- await (0, promises_1.writeFile)(checksumPath.replace(cacheRoot, tempRoot), config.checksum);
170
- await (0, promises_1.mkdir)((0, node_path_1.dirname)(cacheRoot), { recursive: true });
171
- await (0, promises_1.rename)(tempRoot, cacheRoot);
172
- return {
173
- cacheHit: false,
174
- sourceBitcoindArgs: binaries.sourceBitcoindArgs,
175
- sourceBitcoinCliBinary: binaries.sourceBitcoinCliBinary.replace(tempRoot, cacheRoot),
176
- sourceBitcoindBinary: binaries.sourceBitcoindBinary.replace(tempRoot, cacheRoot),
177
- };
178
- }
179
- catch (error) {
180
- await (0, promises_1.rm)(tempRoot, { force: true, recursive: true });
181
- await (0, promises_1.rm)(cacheRoot, { force: true, recursive: true });
182
- throw error;
183
- }
184
- }
185
- async function areBitcoinCoreBinariesRunnable(binaries) {
186
- try {
187
- await assertBitcoinCoreBinariesRunnable(binaries);
188
- return true;
189
- }
190
- catch {
191
- return false;
192
- }
193
- }
194
- async function assertBitcoinCoreBinariesRunnable(binaries) {
195
- await (0, local_node_utils_1.runCommand)(binaries.sourceBitcoindBinary, [
196
- ...binaries.sourceBitcoindArgs,
197
- '-version',
198
- ]);
199
- await (0, local_node_utils_1.runCommand)(binaries.sourceBitcoinCliBinary, ['-version']);
200
- }
201
- function findBitcoinCoreBinaries(root) {
202
- const sourceBitcoinCliBinary = (0, local_node_utils_1.findExecutable)(root, 'bitcoin-cli');
203
- const sourceBitcoindBinary = findBitcoinCoreDaemonBinary(root);
204
- if (!sourceBitcoindBinary || !sourceBitcoinCliBinary) {
205
- return undefined;
206
- }
207
- return {
208
- sourceBitcoindArgs: sourceBitcoindBinary.name === 'bitcoin' ? ['node'] : [],
209
- sourceBitcoinCliBinary,
210
- sourceBitcoindBinary: sourceBitcoindBinary.path,
211
- };
212
- }
213
- function findBitcoinCoreDaemonBinary(root) {
214
- for (const name of ['bitcoind', 'bitcoin-node', 'bitcoin']) {
215
- const path = (0, local_node_utils_1.findExecutable)(root, name);
216
- if (path) {
217
- return { name, path };
218
- }
219
- }
220
- return undefined;
221
- }
222
- //# sourceMappingURL=install.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install.cjs","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,iEAgBoC;AAMpC,qCAAmD;AACnD,+CAAgE;AAChE,yCAA0C;AAE1C,MAAM,+BAA+B,GAAG,oBAAoB,CAAC;AAC7D,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAgCvC,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,MAIX,EAAE;IACJ,OAAO,IAAA,4CAAyB,EAAC;QAC/B,GAAG;QACH,aAAa;QACb,QAAQ,EAAE,+BAA+B;KAC1C,CAAC,CAAC;AACL,CAAC;AAZD,0EAYC;AAED,SAAgB,+CAA+C,CAAC,EAC9D,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,eAAe,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,cAAc,CAAC,MAIzC,EAAE;IACJ,MAAM,MAAM,GAAG,IAAA,4CAAyB,EAAC;QACvC,GAAG;QACH,eAAe;QACf,UAAU,EAAE,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,oBAAoB,C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x/no-nodejs-modules, no-restricted-globals */\nimport {\n cleanInstallerCache,\n downloadFileFromUrl,\n extractTarGzArchive,\n findExecutable,\n getCacheKey,\n getMetamaskCacheDirectory,\n getPlatformKey,\n installExecutableWrapper,\n mergeArtifactConfig,\n readCliValue,\n readPackageJsonToolConfig,\n requireCompletePlatformConfig,\n resolvePlatformConfig,\n runCommand,\n verifyFileChecksum,\n} from '@metamask/local-node-utils';\nimport type {\n ArtifactConfig,\n ArtifactPlatformConfig,\n InstallDependencies,\n} from '@metamask/local-node-utils';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rename, rm, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\n\nconst BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';\nconst BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';\n\nexport type BitcoinRegtestArtifactConfig = ArtifactConfig;\n\nexport type BitcoinRegtestArtifactPlatformConfig = ArtifactPlatformConfig;\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 = InstallDependencies;\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,\n}: {\n cwd?: string;\n homeDirectory?: string;\n} = {}): string {\n return getMetamaskCacheDirectory({\n cwd,\n homeDirectory,\n toolName: BITCOIN_REGTEST_CACHE_NAMESPACE,\n });\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 config = readPackageJsonToolConfig({\n cwd,\n packageJsonPath,\n configKeys: ['bitcoinRegtestUp', 'bitcoinregtestup', 'bitcoin-regtest-up'],\n }) as Partial<BitcoinRegtestPackageJsonConfig>;\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 = mergeArtifactConfig(\n BITCOIN_REGTEST_DEFAULT_CORE,\n options.bitcoinCore,\n );\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 pathResolution: 'absolute',\n });\n const bitcoinCliBinary = await installExecutableWrapper({\n binDirectory,\n commandName: 'bitcoin-cli',\n executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,\n pathResolution: 'absolute',\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 cleanInstallerCache({\n cacheDirectory,\n namespace: BITCOIN_REGTEST_CACHE_NAMESPACE,\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 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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"install.d.cts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EACpB,mCAAmC;AAQpC,MAAM,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE1D,MAAM,MAAM,oCAAoC,GAAG,sBAAsB,CAAC;AAE1E,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,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,mBAAmB,CAAC;AAOpE,eAAO,MAAM,4BAA4B,EAAE,4BAwB1C,CAAC;AAEF,wBAAgB,+BAA+B,CAAC,EAC9C,GAAmB,EACnB,aAAa,GACd,GAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAMd;AAED,wBAAgB,+CAA+C,CAAC,EAC9D,GAAmB,EACnB,eAA2C,GAC5C,GAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,4BAA4B,CAmBpC;AAED,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,MAAM,EAAE,GACb,4BAA4B,CA8C9B;AAED,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,4BAAiC,EAC1C,YAAY,GAAE,iCAAsC,GACnD,OAAO,CAAC,2BAA2B,CAAC,CA4CtC;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,GAAE,IAAI,CAAC,4BAA4B,EAAE,gBAAgB,GAAG,KAAK,CAAM,GACzE,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -1,34 +0,0 @@
1
- import type { ArtifactConfig, ArtifactPlatformConfig, InstallDependencies } from "@metamask/local-node-utils";
2
- export type BitcoinRegtestArtifactConfig = ArtifactConfig;
3
- export type BitcoinRegtestArtifactPlatformConfig = ArtifactPlatformConfig;
4
- export type BitcoinRegtestInstallOptions = {
5
- binDirectory?: string;
6
- bitcoinCore?: BitcoinRegtestArtifactConfig;
7
- cacheDirectory?: string;
8
- cwd?: string;
9
- platform?: string;
10
- };
11
- export type BitcoinRegtestInstallResult = {
12
- bitcoinCliBinary: string;
13
- bitcoindBinary: string;
14
- cacheHit: boolean;
15
- checksum: string;
16
- sourceBitcoindArgs: string[];
17
- sourceBitcoinCliBinary: string;
18
- sourceBitcoindBinary: string;
19
- version?: string;
20
- };
21
- export type BitcoinRegtestInstallDependencies = InstallDependencies;
22
- export declare const BITCOIN_REGTEST_DEFAULT_CORE: BitcoinRegtestArtifactConfig;
23
- export declare function getBitcoinRegtestCacheDirectory({ cwd, homeDirectory, }?: {
24
- cwd?: string;
25
- homeDirectory?: string;
26
- }): string;
27
- export declare function readBitcoinRegtestInstallOptionsFromPackageJson({ cwd, packageJsonPath, }?: {
28
- cwd?: string;
29
- packageJsonPath?: string;
30
- }): BitcoinRegtestInstallOptions;
31
- export declare function parseBitcoinRegtestInstallCliOptions(args: string[]): BitcoinRegtestInstallOptions;
32
- export declare function installBitcoinRegtest(options?: BitcoinRegtestInstallOptions, dependencies?: BitcoinRegtestInstallDependencies): Promise<BitcoinRegtestInstallResult>;
33
- export declare function cleanBitcoinRegtestCache(options?: Pick<BitcoinRegtestInstallOptions, 'cacheDirectory' | 'cwd'>): Promise<void>;
34
- //# sourceMappingURL=install.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install.d.mts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EACpB,mCAAmC;AAQpC,MAAM,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE1D,MAAM,MAAM,oCAAoC,GAAG,sBAAsB,CAAC;AAE1E,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,CAA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,CAAC,sBAAsB,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY;IAO3C,MAAM,sBAAsB,GAAG,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACnE,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAE/D,IAAI,CAAC,oBAAoB,IAAI,CAAC,sBAAsB,EAAE,CAAC;QACrD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO;QACL,kBAAkB,EAAE,oBAAoB,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;QAC3E,sBAAsB;QACtB,oBAAoB,EAAE,oBAAoB,CAAC,IAAI;KAChD,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAAY;IAEZ,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/* eslint-disable import-x/no-nodejs-modules, no-restricted-globals */\nimport {\n cleanInstallerCache,\n downloadFileFromUrl,\n extractTarGzArchive,\n findExecutable,\n getCacheKey,\n getMetamaskCacheDirectory,\n getPlatformKey,\n installExecutableWrapper,\n mergeArtifactConfig,\n readCliValue,\n readPackageJsonToolConfig,\n requireCompletePlatformConfig,\n resolvePlatformConfig,\n runCommand,\n verifyFileChecksum,\n} from '@metamask/local-node-utils';\nimport type {\n ArtifactConfig,\n ArtifactPlatformConfig,\n InstallDependencies,\n} from '@metamask/local-node-utils';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rename, rm, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\n\nconst BITCOIN_REGTEST_CACHE_NAMESPACE = 'bitcoin-regtest-up';\nconst BITCOIN_CORE_CACHE_NAMESPACE = 'bitcoin-core';\n\nexport type BitcoinRegtestArtifactConfig = ArtifactConfig;\n\nexport type BitcoinRegtestArtifactPlatformConfig = ArtifactPlatformConfig;\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 = InstallDependencies;\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,\n}: {\n cwd?: string;\n homeDirectory?: string;\n} = {}): string {\n return getMetamaskCacheDirectory({\n cwd,\n homeDirectory,\n toolName: BITCOIN_REGTEST_CACHE_NAMESPACE,\n });\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 config = readPackageJsonToolConfig({\n cwd,\n packageJsonPath,\n configKeys: ['bitcoinRegtestUp', 'bitcoinregtestup', 'bitcoin-regtest-up'],\n }) as Partial<BitcoinRegtestPackageJsonConfig>;\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 = mergeArtifactConfig(\n BITCOIN_REGTEST_DEFAULT_CORE,\n options.bitcoinCore,\n );\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 pathResolution: 'absolute',\n });\n const bitcoinCliBinary = await installExecutableWrapper({\n binDirectory,\n commandName: 'bitcoin-cli',\n executablePath: bitcoinCoreResult.sourceBitcoinCliBinary,\n pathResolution: 'absolute',\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 cleanInstallerCache({\n cacheDirectory,\n namespace: BITCOIN_REGTEST_CACHE_NAMESPACE,\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 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"]}