Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 123 additions & 21 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reclaimprotocol/zk-symmetric-crypto",
"version": "5.0.1",
"version": "5.0.2",
"description": "JS Wrappers for Various ZK Snark Circuits",
"type": "module",
"exports": {
Expand Down Expand Up @@ -54,10 +54,10 @@
"lib"
],
"peerDependencies": {
"@reclaimprotocol/tls": "*",
"koffi": "*",
"p-queue": "*",
"snarkjs": "*",
"@reclaimprotocol/tls": "*"
"snarkjs": "*"
},
"peerDependenciesMeta": {
"snarkjs": {
Expand All @@ -79,6 +79,7 @@
"@commitlint/config-conventional": "^17.7.0",
"@reclaimprotocol/tls": "^0.1.0",
"@types/node": "^22.0.0",
"@types/unzipper": "^0.10.11",
"circom_tester": "^0.0.20",
"circomlib": "^2.0.5",
"compare-versions": "^6.1.1",
Expand All @@ -87,6 +88,7 @@
"p-queue": "^8.0.0",
"snarkjs": "git+https://github.com/reclaimprotocol/snarkjs.git",
"tinybench": "^3.0.3",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"unzipper": "^0.12.3"
}
}
72 changes: 51 additions & 21 deletions js/src/scripts/download-files.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { exec } from 'child_process'
import { createReadStream, createWriteStream } from 'fs'
import { rename, rm } from 'fs/promises'
import { dirname, join } from 'path'
import { promisify } from 'util'
import { Readable } from 'stream'
import { pipeline } from 'stream/promises'
import { Extract } from 'unzipper'
import { GIT_COMMIT_HASH } from '../config.ts'
import { Logger } from '../types.ts'
import type { Logger } from '../types.ts'

const execPromise = promisify(exec)

const logger: Logger = console

const CLONE_DIR = './zk-symmetric-crypto'
const CLONE_CMD = [
`git clone https://github.com/reclaimprotocol/zk-symmetric-crypto ${CLONE_DIR}`,
`cd ${CLONE_DIR}`,
`git reset ${GIT_COMMIT_HASH} --hard`
].join(' && ')
const ZIP_URL = `https://github.com/reclaimprotocol/zk-symmetric-crypto/archive/${GIT_COMMIT_HASH}.zip`
const DOWNLOAD_DIR = './zk-symmetric-crypto-download'
const EXTRACTED_DIR = `./zk-symmetric-crypto-${GIT_COMMIT_HASH}`

const __dirname = dirname(import.meta.url.replace('file://', ''))
const BASE_DIR = join(__dirname, '../../')
Expand All @@ -23,28 +21,60 @@ const DIRS_TO_COPY = [
'bin'
]

async function downloadAndExtractZip() {
logger.info(`downloading archive from ${ZIP_URL}`)

const response = await fetch(ZIP_URL)
if(!response.ok) {
throw new Error(`Failed to download: ${response.status} ${response.statusText}`)
}

const zipPath = join(DOWNLOAD_DIR, 'repo.zip')
await rm(DOWNLOAD_DIR, { recursive: true, force: true })
await rm(EXTRACTED_DIR, { recursive: true, force: true })

// Create download directory and download ZIP
const { mkdir } = await import('fs/promises')
await mkdir(DOWNLOAD_DIR, { recursive: true })

if(!response.body) {
throw new Error('Response body is null')
}

await pipeline(
// @ts-ignore
Readable.from(response.body),
createWriteStream(zipPath)
)

logger.info('downloaded ZIP, extracting...')

// Extract ZIP
await pipeline(
createReadStream(zipPath),
Extract({ path: './' })
)

logger.info(`extracted to ${EXTRACTED_DIR}`)
}

async function main() {
for(const dir of DIRS_TO_COPY) {
await rm(join(BASE_DIR, dir), { recursive: true, force: true })
logger.info(`removing old "${dir}" directory`)
}

// remove in case it already exists -- we want to clone fresh
await rm(CLONE_DIR, { recursive: true, force: true })
logger.info(`removed old cloned "${CLONE_DIR}" directory`)

logger.info(`cloning repo, #${GIT_COMMIT_HASH}. This may take a while...`)

await execPromise(CLONE_CMD)
logger.info(`cloned repo to "${CLONE_DIR}"`)
await downloadAndExtractZip()

for(const dir of DIRS_TO_COPY) {
await rename(join(CLONE_DIR, dir), join(BASE_DIR, dir))
await rename(join(EXTRACTED_DIR, dir), join(BASE_DIR, dir))
logger.info(`moved "${dir}" directory`)
}

await rm(CLONE_DIR, { recursive: true, force: true })
logger.info(`removed "${CLONE_DIR}" directory`)
// Clean up
await rm(DOWNLOAD_DIR, { recursive: true, force: true })
await rm(EXTRACTED_DIR, { recursive: true, force: true })
logger.info('cleaned up temporary files')

logger.info('done')
}
Expand Down
Loading