-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathfetch-sapling-params.js
40 lines (36 loc) · 1.26 KB
/
fetch-sapling-params.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require("fs")
const fetch = require("node-fetch");
const ZCASH_DOWNLOAD_URL = 'https://download.z.cash/downloads';
const ZCASH_SPEND_PARAMS_FILE_NAME = 'sapling-spend.params';
const ZCASH_OUTPUT_PARAMS_FILE_NAME = 'sapling-output.params';
const SPEND_PARAMS = 'saplingSpendParams';
const OUTPUT_PARAMS = 'saplingOutputParams';
async function fetchSaplingParams(url, name) {
const response = await fetch(`${ZCASH_DOWNLOAD_URL}/${url}`);
const arrBuff = await response.arrayBuffer();
const buff = Buffer.from(arrBuff);
fs.writeFile(`${name}.js`, `
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD Module
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node Module
module.exports = factory();
} else {
// Browser Global
root.returnExports = factory();
}
}(this, function () {
return {
"${name}": "${buff.toString('base64')}"
};
}));
`, (err) => {
if (err) return console.log(err);
console.log(`The file ${name} has been saved!`);
});
}
fetchSaplingParams(ZCASH_SPEND_PARAMS_FILE_NAME, SPEND_PARAMS);
fetchSaplingParams(ZCASH_OUTPUT_PARAMS_FILE_NAME, OUTPUT_PARAMS);