-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Modify bb.js to be compatible with next.js (#544)
Co-authored-by: ludamad <adam.domurad@gmail.com>
- Loading branch information
Showing
27 changed files
with
867 additions
and
706 deletions.
There are no files selected for viewing
This file contains 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 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,4 @@ | ||
#!/bin/bash | ||
# Used to call this script from a stable path | ||
DIR=$(dirname "$0") | ||
exec node "$DIR/../ts/dest/node/main.js" $@ |
This file contains 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 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 |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
node_modules | ||
dest | ||
.tsbuildinfo | ||
.tsbuildinfo.browser | ||
.tsbuildinfo.node | ||
*.log | ||
crs |
This file contains 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 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 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 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,33 @@ | ||
const replaceInFile = require('replace-in-file'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const buildTarget = process.env.BUILD_TARGET; | ||
const dynamic_imports = ['barretenberg_wasm', 'crs', 'random', 'types']; | ||
|
||
async function replaceImports() { | ||
try { | ||
dynamic_imports.forEach(async item => { | ||
await replaceInFile({ | ||
files: path.resolve(__dirname, `dest/${buildTarget}/${item}/*`), | ||
from: new RegExp(`'dynamic\\/${item}';`, 'g'), | ||
to: `'./${buildTarget}/index.js';`, | ||
}); | ||
}); | ||
const filePath = path.resolve(__dirname, `dest/${buildTarget}/barretenberg_wasm/${buildTarget}/index.js`); | ||
// Grab the contents for a hacky check if this has ran twice | ||
const contents = fs.readFileSync(filePath, 'utf8'); | ||
// hack to allow for shared .wasm files between build targets | ||
if (contents.includes('../../') && !contents.includes('../../../')) { | ||
await replaceInFile({ | ||
files: filePath, | ||
from: /\.\.\/\.\.\//g, | ||
to: `../../../`, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error('Error occurred:', error); | ||
} | ||
} | ||
|
||
replaceImports(); |
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
export { Crs } from './node/index.js'; | ||
export { Crs } from 'dynamic/crs'; |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from './node/index.js'; | ||
export * from 'dynamic/random'; |
This file contains 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 @@ | ||
export * from './point.js'; |
This file contains 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,50 @@ | ||
import { Fr } from '../index.js'; | ||
import { BufferReader } from '../../serialize/buffer_reader.js'; | ||
|
||
export class Point { | ||
static SIZE_IN_BYTES = 64; | ||
static EMPTY = new Point(Fr.ZERO, Fr.ZERO); | ||
|
||
constructor(public readonly x: Fr, public readonly y: Fr) {} | ||
|
||
static random() { | ||
// TODO: This is not a point on the curve! | ||
return new Point(Fr.random(), Fr.random()); | ||
} | ||
|
||
static fromBuffer(buffer: Uint8Array | BufferReader) { | ||
const reader = BufferReader.asReader(buffer); | ||
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader)); | ||
} | ||
|
||
static fromString(address: string) { | ||
address = address.replace(/^0x/i, ''); | ||
const byteValues = new Uint8Array(Math.ceil(address.length / 2)); | ||
for (let i = 0; i < byteValues.length; i++) { | ||
byteValues[i] = Number.parseInt(address.substr(i * 2, 2), 16); | ||
} | ||
return Point.fromBuffer(byteValues); | ||
} | ||
|
||
toBuffer() { | ||
const xBuffer = this.x.toBuffer(); | ||
const yBuffer = this.y.toBuffer(); | ||
const combined = new Uint8Array(xBuffer.length + yBuffer.length); | ||
combined.set(xBuffer, 0); | ||
combined.set(yBuffer, xBuffer.length); | ||
return combined; | ||
} | ||
|
||
toString() { | ||
const buffer = this.toBuffer(); | ||
let hexString = '0x'; | ||
for (let i = 0; i < buffer.length; i++) { | ||
hexString += buffer[i].toString(16).padStart(2, '0'); | ||
} | ||
return hexString; | ||
} | ||
|
||
equals(rhs: Point) { | ||
return this.x.equals(rhs.x) && this.y.equals(rhs.y); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './ptr.js'; | ||
export * from './fields.js'; | ||
export * from './point.js'; | ||
export * from 'dynamic/types'; | ||
export * from './fixed_size_buffer.js'; | ||
export * from './raw_buffer.js'; |
This file contains 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 @@ | ||
export * from './point.js'; |
This file contains 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.