-
Notifications
You must be signed in to change notification settings - Fork 200
feat: modernize circuits build pipeline #876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
transphorm
merged 6 commits into
dev
from
codex/add-circuits-build-configuration-and-scripts
Aug 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c17d874
Add tsup build for circuits
transphorm b5f8068
sort package.json
transphorm 22ecf49
cr feedback
transphorm fe9717f
circuits fixes
transphorm 320cd4f
Merge branch 'dev' into codex/add-circuits-build-configuration-and-sc…
transphorm b5540ab
fixes
transphorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| // Move type declarations to correct locations | ||
| const srcIndexTypes = 'dist/esm/src/index.d.ts'; | ||
| const destIndexTypes = 'dist/esm/index.d.ts'; | ||
| const srcTestingDir = 'dist/esm/src/testing'; | ||
| const destTestingDir = 'dist/esm/testing'; | ||
|
|
||
| // Copy main index.d.ts | ||
| if (fs.existsSync(srcIndexTypes)) { | ||
| fs.copyFileSync(srcIndexTypes, destIndexTypes); | ||
| console.log('✓ Copied index.d.ts'); | ||
| } | ||
|
|
||
| // Copy testing directory | ||
| if (fs.existsSync(srcTestingDir)) { | ||
| fs.cpSync(srcTestingDir, destTestingDir, { recursive: true }); | ||
| console.log('✓ Copied testing types'); | ||
| } | ||
|
|
||
| // Clean up intermediate directories | ||
| const srcDir = 'dist/esm/src'; | ||
| const testsDir = 'dist/esm/tests'; | ||
| if (fs.existsSync(srcDir)) { | ||
| fs.rmSync(srcDir, { recursive: true, force: true }); | ||
| console.log('✓ Cleaned up src directory'); | ||
| } | ||
| if (fs.existsSync(testsDir)) { | ||
| fs.rmSync(testsDir, { recursive: true, force: true }); | ||
| console.log('✓ Cleaned up tests directory'); | ||
| } | ||
|
|
||
| console.log('Type declarations organized successfully!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { writeFileSync, mkdirSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { shimConfigs } from './shimConfigs.js'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const DIST = path.resolve(__dirname, '..', 'dist'); | ||
|
|
||
| // Read package version | ||
| const packageJsonPath = path.resolve(__dirname, '..', 'package.json'); | ||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); | ||
|
|
||
| writeFileSync(path.join(DIST, 'esm', 'package.json'), JSON.stringify({ type: 'module' }, null, 4)); | ||
| writeFileSync( | ||
| path.join(DIST, 'cjs', 'package.json'), | ||
| JSON.stringify({ type: 'commonjs' }, null, 4) | ||
| ); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Initialize dist package.json (filled after shims) | ||
| const distPackageJson = { | ||
| name: '@selfxyz/circuits', | ||
| version: packageJson.version, | ||
| type: 'module', | ||
| exports: { '.': './esm/index.js' }, | ||
| }; | ||
|
|
||
| function toPosix(p) { | ||
| return p.split(path.sep).join('/'); | ||
| } | ||
|
|
||
| function createShim(shimPath, targetPath) { | ||
| const shimDir = path.join(DIST, shimPath); | ||
| mkdirSync(shimDir, { recursive: true }); | ||
| const esmTarget = targetPath; // e.g. ./esm/utils/rsa.js (posix-like expected) | ||
| const cjsTarget = esmTarget.replace('/esm/', '/cjs/').replace(/\.js$/, '.cjs'); | ||
|
|
||
| // ESM shim entry | ||
| writeFileSync( | ||
| path.join(shimDir, 'index.js'), | ||
| `// Shim for @selfxyz/circuits/${shimPath}\nexport * from '${esmTarget.replace(/\.js$/, '')}';\nexport { default } from '${esmTarget.replace(/\.js$/, '')}';\n` | ||
| ); | ||
| // CJS shim entry | ||
| writeFileSync( | ||
| path.join(shimDir, 'index.cjs'), | ||
| `// Shim for @selfxyz/circuits/${shimPath}\nmodule.exports = require('${cjsTarget}');\n` | ||
| ); | ||
| // Types shim | ||
| writeFileSync( | ||
| path.join(shimDir, 'index.d.ts'), | ||
| `// Types for @selfxyz/circuits/${shimPath}\nexport * from '${esmTarget.replace(/\.js$/, '')}';\nexport { default } from '${esmTarget.replace(/\.js$/, '')}';\n` | ||
| ); | ||
|
|
||
| // Add subpath export for this shim | ||
| const subpath = `./${toPosix(shimPath)}`; | ||
| distPackageJson.exports[subpath] = { | ||
| import: `./${toPosix(path.relative(DIST, path.join(shimDir, 'index.js')))}`, | ||
| require: `./${toPosix(path.relative(DIST, path.join(shimDir, 'index.cjs')))}`, | ||
| }; | ||
| } | ||
|
|
||
| // Materialize shims and export map | ||
| shimConfigs.forEach((config) => createShim(config.shimPath, config.targetPath)); | ||
|
|
||
| // Finally write dist/package.json (after exports are populated) | ||
| writeFileSync(path.join(DIST, 'package.json'), JSON.stringify(distPackageJson, null, 4)); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Shim configurations for @selfxyz/circuits | ||
| export const shimConfigs = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Main circuits package runtime API | ||
| // This package provides circuit definitions and related utilities | ||
|
|
||
| // Circuit metadata and constants | ||
| export const CIRCUITS_VERSION = '0.0.1'; | ||
|
|
||
| // Supported signature algorithms | ||
| export const SUPPORTED_SIGNATURE_ALGORITHMS = [ | ||
| 'rsa_sha256_65537_2048', | ||
| 'rsa_sha256_65537_3072', | ||
| 'rsa_sha256_65537_4096', | ||
| 'rsa_sha1_65537_2048', | ||
| 'rsa_sha512_65537_4096', | ||
| 'rsapss_sha256_65537_32_3072', | ||
| 'rsapss_sha256_65537_32_4096', | ||
| 'rsapss_sha256_3_32_3072', | ||
| 'rsapss_sha384_65537_48_3072', | ||
| 'rsapss_sha512_65537_64_4096', | ||
| ] as const; | ||
|
|
||
| export type SupportedSignatureAlgorithm = (typeof SUPPORTED_SIGNATURE_ALGORITHMS)[number]; | ||
|
|
||
| // Note: Test utilities have been moved to a dedicated './testing' export | ||
| // Import test utilities via: import { ... } from '@selfxyz/circuits/testing' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Re-export utility functions for generating mock inputs in circuit tests | ||
| export { generateMockRsaPkcs1v1_5Inputs } from '../../tests/utils/generateMockInputsInCircuits.js'; | ||
| export { | ||
| generateMockRsaPssInputs, | ||
| generateMalleableRsaPssInputs, | ||
| } from '../../tests/utils/generateMockInputsRsaPss.js'; | ||
|
|
||
| // Re-export test case configurations | ||
| export { | ||
| sigAlgs as registerSigAlgs, | ||
| fullSigAlgs as registerFullSigAlgs, | ||
| } from '../../tests/register/test_cases.js'; | ||
| export { | ||
| sigAlgs as registerIdSigAlgs, | ||
| fullSigAlgs as registerIdFullSigAlgs, | ||
| } from '../../tests/register_id/test_cases.js'; | ||
| export { | ||
| sigAlgs as dscSigAlgs, | ||
| fullSigAlgs as dscFullSigAlgs, | ||
| } from '../../tests/dsc/test_cases.js'; | ||
| export { | ||
| fullAlgorithms as rsaPssFullAlgorithms, | ||
| sigAlgs as rsaPssSigAlgs, | ||
| AdditionalCases as rsaPssAdditionalCases, | ||
| } from '../../tests/utils/testcase/rsapss.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "module": "CommonJS", | ||
| "moduleResolution": "Node", | ||
| "outDir": "./dist/cjs", | ||
| "declarationDir": "./dist/cjs", | ||
| "esModuleInterop": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "declaration": true, | ||
| "emitDeclarationOnly": true, | ||
| "declarationMap": false, | ||
| "outDir": "./dist/esm", | ||
| "declarationDir": "./dist/esm", | ||
| "composite": true, | ||
| "noEmit": false, | ||
| "rootDir": "." | ||
| }, | ||
| "include": ["src/**/*", "tests/**/*", "tests/**/*.json"], | ||
| "exclude": ["node_modules", "dist"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import path from 'path'; | ||
| import { defineConfig } from 'tsup'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| const entry = { | ||
| index: 'src/index.ts', | ||
| }; | ||
|
|
||
| export default defineConfig([ | ||
| { | ||
| tsconfig: './tsconfig.json', | ||
| entry, | ||
| format: ['esm'], | ||
| outDir: path.resolve(__dirname, 'dist/esm'), | ||
| dts: false, | ||
| splitting: false, | ||
| clean: true, | ||
| sourcemap: true, | ||
| target: 'es2020', | ||
| }, | ||
| { | ||
| tsconfig: './tsconfig.cjs.json', | ||
| entry, | ||
| format: ['cjs'], | ||
| outDir: path.resolve(__dirname, 'dist/cjs'), | ||
| dts: false, | ||
| splitting: false, | ||
| clean: false, | ||
| sourcemap: true, | ||
| target: 'es2020', | ||
| }, | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.