Source:
dev 4ab0eb2
@railgun-reloaded/ipfs-artifact-fetcherA simple module for fetching RAILGUN or PPOI circuit artifacts from IPFS
npm install @railgun-reloaded/ipfs-artifact-fetcher
To download artifacts, also install @helia/verified-fetch:
npm install @helia/verified-fetch@^5.1.1
The supported range is ^5.1.1.
Definitions imports and cached artifact reads do not need Helia.
The downloader loads Helia only when an artifact is absent from the store.
If Helia cannot load, the error includes the install command.
RAILGUN circuit artifacts are cryptographic files required for zero-knowledge proof generation and verification:
zkey, wasm, and dat files are stored on IPFS for decentralized access as .br filetypesvkey files are stored uncompressed as JSONBuffer polyfill is required.The store API works in both environments. For browsers, supply storage callbacks for IndexedDB or another byte store. The paths below are store keys; the downloader does not write files itself.
First, create an ArtifactStore instance with file system operations:
import fs from 'node:fs'
import { ArtifactStore } from '@railgun-reloaded/ipfs-artifact-fetcher'
const artifactStore = new ArtifactStore(
fs.promises.readFile, // get function
async (dir, path, data) => {
await fs.promises.mkdir(dir, { recursive: true })
await fs.promises.writeFile(path, data)
}, // store function
(path: string): Promise<boolean> => {
return new Promise(resolve => {
fs.promises
.access(path)
.then(() => resolve(true))
.catch(() => resolve(false))
})
} // exist function
)
import { ArtifactDownloader } from '@railgun-reloaded/ipfs-artifact-fetcher'
// For WASM artifacts (web/JavaScript environments)
const downloader = new ArtifactDownloader({
artifactStore,
useNativeArtifacts: false
})
// For native artifacts (Node.js/native environments)
const nativeDownloader = new ArtifactDownloader({
artifactStore,
useNativeArtifacts: true
})
// Download all RAILGUN 01x01 artifacts
const artifacts = await downloader.downloadArtifactsForVariant('01x01')
console.log('Downloaded RAILGUN artifacts:')
console.log('- Path to Verification Key file:', artifacts.vkeyStoredPath)
console.log('- Path to Proving Key file:', artifacts.zkeyStoredPath)
console.log('- Path to WASM/DAT file:', artifacts.wasmOrDatStoredPath)
// Download PPOI 3x3 artifacts
const ppoiArtifacts = await downloader.downloadArtifactsForVariant('POI_3x3')
console.log('Downloaded PPOI artifacts:')
console.log('- Path to Verification Key file:', ppoiArtifacts.vkeyStoredPath)
console.log('- Path to Proving Key file:', ppoiArtifacts.zkeyStoredPath)
console.log('- Path to WASM/DAT file:', ppoiArtifacts.wasmOrDatStoredPath)
Call stop() when you no longer need the downloader. This releases the verified-fetch instance. It does not close the store you supply.
const downloader = new ArtifactDownloader({
artifactStore,
useNativeArtifacts: false
});
try {
// Use the downloader
const artifacts = await downloader.downloadArtifactsForVariant('01x01');
} finally {
// Release verified-fetch resources.
await downloader.stop();
}
Use fetchFromIPFS to fetch one artifact. It returns decompressed Uint8Array bytes, not a path. Verification keys remain JSON bytes. Cache hits return stored bytes without a network request.
import { ArtifactName, RAILGUN_ARTIFACTS_CID_ROOT, PPOI_ARTIFACTS_CID } from '@railgun-reloaded/ipfs-artifact-fetcher'
// Download individual RAILGUN artifacts
const vkeyBytes = await downloader.fetchFromIPFS(
RAILGUN_ARTIFACTS_CID_ROOT,
'01x01',
ArtifactName.VKEY
)
const zkeyBytes = await downloader.fetchFromIPFS(
RAILGUN_ARTIFACTS_CID_ROOT,
'01x01',
ArtifactName.ZKEY
)
const wasmBytes = await downloader.fetchFromIPFS(
RAILGUN_ARTIFACTS_CID_ROOT,
'01x01',
ArtifactName.WASM
)
console.log('Individual RAILGUN artifacts:')
console.log('- Verification Key bytes:', vkeyBytes)
console.log('- Proving Key bytes:', zkeyBytes)
console.log('- WASM bytes:', wasmBytes)
// Download individual PPOI artifacts
const ppoiVkeyBytes = await downloader.fetchFromIPFS(
PPOI_ARTIFACTS_CID,
'POI_3x3',
ArtifactName.VKEY
)
const ppoiZkeyBytes = await downloader.fetchFromIPFS(
PPOI_ARTIFACTS_CID,
'POI_3x3',
ArtifactName.ZKEY
)
const ppoiWasmBytes = await downloader.fetchFromIPFS(
PPOI_ARTIFACTS_CID,
'POI_3x3',
ArtifactName.WASM
)
console.log('Individual PPOI artifacts:')
console.log('- Verification Key bytes:', ppoiVkeyBytes)
console.log('- Proving Key bytes:', ppoiZkeyBytes)
console.log('- WASM bytes:', ppoiWasmBytes)
The downloader uses these store keys. Each download stores wasm or dat, as specified by useNativeArtifacts.
artifacts-v2.1/
├── 01x01/
│ ├── vkey.json
│ ├── zkey
│ ├── dat
│ └── wasm
├── 02x02/
│ ├── vkey.json
│ ├── zkey
│ ├── dat
│ └── wasm
└── QmZ2MyM6TKxffkv6stuo2hFwmUfs3q4xgMYN164Sje8new/
├── POI_3x3/
│ ├── vkey.json
│ ├── zkey
│ ├── dat
│ └── wasm
└── POI_13x13/
├── vkey.json
├── zkey
├── dat
└── wasm
POI downloads use the Community wallet's V2 artifact set. The public
variant names remain POI_3x3 and POI_13x13. IPFS files use circuit
directories 03x03 and 13x13: verification and proving keys under
circuits/, WASM under prover/snarkjs/, and DAT under
prover/native-legacy/.
POI cache keys include the supplied root CID. Older files under
ppoi-nov-2-23 are not reused. Store callbacks must accept the returned
paths rather than assume a fixed POI directory.
Run npm test for the offline checks. The acquisition tests run without Node globals.
Run npm run test:live to download the transaction verification key and both
POI verification keys and WASM files with verified-fetch. The check compares
the POI files with Mopro release keys and Community wallet WASM hashes. It
requires network access and working native dependencies in Node.