diff --git a/metro.config.js b/metro.config.js index d355971..7bbbd66 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1,7 +1,7 @@ // eslint-disable-next-line const { getSentryExpoConfig } = require('@sentry/react-native/metro'); -// This replaces `const config = getDefaultConfig(__dirname);` +// This replaces Expo's `const config = getDefaultConfig(__dirname);` const config = getSentryExpoConfig(__dirname); module.exports = { @@ -10,7 +10,14 @@ module.exports = { ...config.resolver, extraNodeModules: { stream: require.resolve('react-native-stream'), + // assert: require.resolve('assert-tiny'), + // fs: require.resolve('react-native-level-fs'), ...config.resolver.extraNodeModules, }, + sourceExts: [ + ...config.resolver.sourceExts, + // compile CommonJS modules for circom and snark + 'cjs', + ], }, }; diff --git a/package-lock.json b/package-lock.json index dfcfb8b..a1fbf1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,6 @@ "@apollo/client": "^3.8.6", "@arx-research/libhalo": "^1.2.17", "@expo/metro-runtime": "~3.2.1", - "@noir-lang/backend_barretenberg": "^0.31.0", - "@noir-lang/noir_js": "^0.31.0", "@react-native-async-storage/async-storage": "1.23.1", "@react-native-community/masked-view": "^0.1.11", "@rneui/base": "^4.0.0-rc.7", @@ -25,11 +23,10 @@ "@semaphore-protocol/proof": "^3.11.1", "@sentry/react-native": "~5.22.0", "@types/lodash": "^4.14.202", - "@zk-email/circuits": "^6.1.6", - "@zk-email/contracts": "^6.1.6", - "@zk-email/helpers": "^6.1.11", + "assert-tiny": "^1.0.2", "axios": "^1.5.1", "base-64": "^1.0.0", + "buffer": "^6.0.3", "circomlib": "^2.0.5", "circomlibjs": "^0.1.7", "date-fns": "^2.30.0", @@ -243,28 +240,6 @@ "safe-buffer": "~5.2.0" } }, - "node_modules/@aztec/bb.js": { - "version": "0.41.0", - "resolved": "https://registry.npmjs.org/@aztec/bb.js/-/bb.js-0.41.0.tgz", - "integrity": "sha512-Uqez8YRu+nlPdXfrqeEBF/Mz3OhhK39zXL4gzN/pGhp4FlEkeTLpCx7etHXz6aodyjri6lQCv219tGXG2IAQoA==", - "dependencies": { - "comlink": "^4.4.1", - "commander": "^10.0.1", - "debug": "^4.3.4", - "tslib": "^2.4.0" - }, - "bin": { - "bb.js": "dest/node/main.js" - } - }, - "node_modules/@aztec/bb.js/node_modules/commander": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", - "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", - "engines": { - "node": ">=14" - } - }, "node_modules/@babel/code-frame": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", @@ -5759,44 +5734,6 @@ "node": ">= 8" } }, - "node_modules/@noir-lang/acvm_js": { - "version": "0.47.0", - "resolved": "https://registry.npmjs.org/@noir-lang/acvm_js/-/acvm_js-0.47.0.tgz", - "integrity": "sha512-wS1Nx9Pcr2NXwayWz1OzuweiFuE/2nGWkpkxDDoCiY2TU6G8rfuxL2R0Z018n+emDTTxGLAeuf1WdQg5ZVAVFA==" - }, - "node_modules/@noir-lang/backend_barretenberg": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@noir-lang/backend_barretenberg/-/backend_barretenberg-0.31.0.tgz", - "integrity": "sha512-bVmv6O2BX3wUyrT5dmY9Z5oABTFYsBBtSMOA5nGalyKsZPaIwwBXpk8rF90IhR6U6jh6uZMOhzpKHbZl4WBXKA==", - "dependencies": { - "@aztec/bb.js": "0.41.0", - "@noir-lang/types": "0.31.0", - "fflate": "^0.8.0" - } - }, - "node_modules/@noir-lang/noir_js": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@noir-lang/noir_js/-/noir_js-0.31.0.tgz", - "integrity": "sha512-LCpArXg5CpM7IDQMga8mRJCGUobjC3Ckbj6F+aKiJbteVmFJzymlu36sYLOZBE0JDFZ6gu1uPujBt3I6KWfrIw==", - "dependencies": { - "@noir-lang/acvm_js": "0.47.0", - "@noir-lang/noirc_abi": "0.31.0", - "@noir-lang/types": "0.31.0" - } - }, - "node_modules/@noir-lang/noirc_abi": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@noir-lang/noirc_abi/-/noirc_abi-0.31.0.tgz", - "integrity": "sha512-Y3O2UjKaM0hvrDwPvEtP9DIbKf8aQqPdk7utrK5hGOBTFIERKIVzibhXoLBGtmDaDsm95aIKQOu3IJqYCQHVbw==", - "dependencies": { - "@noir-lang/types": "0.31.0" - } - }, - "node_modules/@noir-lang/types": { - "version": "0.31.0", - "resolved": "https://registry.npmjs.org/@noir-lang/types/-/types-0.31.0.tgz", - "integrity": "sha512-KNLJ/KnvLBLo3pVg6IJWIMPRUYs8fkIngIFdtzHaaovctYpAsUKAF4KKh8ITaSEk7hLAIiHjLunSfQ8wSe7HOA==" - }, "node_modules/@npmcli/fs": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-3.1.1.tgz", @@ -13009,6 +12946,11 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" }, + "node_modules/assert-tiny": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/assert-tiny/-/assert-tiny-1.0.2.tgz", + "integrity": "sha512-jzHPqQ95f9Hul5VteqMZ3u8nn8E/1WnLN/FhvzkcAftLkpSOPN/4/dd4xbPfcVBMun8hX77dQBlAQ6mxILgeGw==" + }, "node_modules/ast-types": { "version": "0.15.2", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.15.2.tgz", @@ -14417,11 +14359,6 @@ "node": ">= 0.8" } }, - "node_modules/comlink": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/comlink/-/comlink-4.4.1.tgz", - "integrity": "sha512-+1dlx0aY5Jo1vHy/tSsIGpSkN4tS9rZSW8FIhG0JH/crs9wwweswIo/POr451r7bZww3hFbPAKnTpimzL/mm4Q==" - }, "node_modules/command-exists": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", @@ -17661,11 +17598,6 @@ "web-worker": "^1.2.0" } }, - "node_modules/fflate": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", - "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==" - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", diff --git a/package.json b/package.json index 92c1d53..b26d7df 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,10 @@ "@semaphore-protocol/proof": "^3.11.1", "@sentry/react-native": "~5.22.0", "@types/lodash": "^4.14.202", + "assert-tiny": "^1.0.2", "axios": "^1.5.1", "base-64": "^1.0.0", + "buffer": "^6.0.3", "circomlib": "^2.0.5", "circomlibjs": "^0.1.7", "date-fns": "^2.30.0", diff --git a/shim.js b/shim.js deleted file mode 100644 index 7054aa5..0000000 --- a/shim.js +++ /dev/null @@ -1,26 +0,0 @@ -if (typeof __dirname === 'undefined') global.__dirname = '/' -if (typeof __filename === 'undefined') global.__filename = '' -if (typeof process === 'undefined') { - global.process = require('process') -} else { - const bProcess = require('process') - for (var p in bProcess) { - if (!(p in process)) { - process[p] = bProcess[p] - } - } -} - -process.browser = false -// if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer - -// global.location = global.location || { port: 80 } -const isDev = typeof __DEV__ === 'boolean' && __DEV__ -process.env.NODE_ENV = isDev ? 'development' : 'production' -if (typeof localStorage !== 'undefined') { - localStorage.debug = isDev ? '*' : '' -} - -// If using the crypto shim, uncomment the following line to ensure -// crypto is loaded first, so it can populate global.crypto -// require('crypto') diff --git a/src/utils/polyfills.ts b/src/utils/polyfills.ts index 6c00b6e..6c7e28d 100644 --- a/src/utils/polyfills.ts +++ b/src/utils/polyfills.ts @@ -2,16 +2,70 @@ * Add to React Native entry point file * Any polyfills here for node/browser functions */ + +if (typeof __dirname === 'undefined') global.__dirname = '/'; +if (typeof __filename === 'undefined') global.__filename = ''; +if (typeof process === 'undefined') { + global.process = require('process'); +} else { + const bProcess = require('process'); + for (const p in bProcess) { + if (!(p in process)) { + process[p] = bProcess[p]; + } + } +} + +if (!window) { + process.browser = false; +} + +// global.location = global.location || { port: 80 } +const isDev = typeof __DEV__ === 'boolean' && __DEV__; +process.env.NODE_ENV = isDev ? 'development' : 'production'; +if (typeof localStorage !== 'undefined') { + localStorage.debug = isDev ? '*' : ''; +} + +import { Buffer } from 'buffer'; +if (typeof global.Buffer === 'undefined') { + global.Buffer = Buffer; +} + import { encode as btoa, decode as atob } from 'base-64'; global.btoa = btoa; global.atob = atob; if (!window) { if (!global.crypto) global.crypto = {}; - global.crypto.getRandomValues = require('expo-crypto').getRandomValues; + // global.crypto.getRandomValues = require('expo-crypto').getRandomValues; + global.crypto = require('expo-crypto'); } process.version = 0; // no NodeJS version in React Native // import 'react-native-get-random-values'; // expo-crypto should preempt this // import "@ethersproject/shims" //for ethers.js + +// import 'expo-crypto'; // separate from crypto imports above + +// add `assert` shim for circom to run circuits in native app +// const { AssertionError, deepEqual, equal, notDeepEqual, notEqual, ok, strictEqual, throws } = require('assert-tiny'); + +// import { AssertionError, deepEqual, equal, notDeepEqual, notEqual, ok, strictEqual, throws } from 'assert-tiny'; +// if (typeof global === 'object') { +// // Only override the global scope if it's defined. +// if (typeof global.assert !== 'function') { +// global.assert = ok; +// } +// Object.assign(global.assert, { +// AssertionError, +// deepEqual, +// equal, +// notDeepEqual, +// notEqual, +// ok, +// strictEqual, +// throws, +// }); +// } diff --git a/src/utils/proving.ts b/src/utils/proving.ts index df70983..027e111 100644 --- a/src/utils/proving.ts +++ b/src/utils/proving.ts @@ -5,9 +5,9 @@ import { JubjubSignature } from 'types/GameMechanics'; -// import circuit from 'circuits/target/circuits.json'; -// import circ from 'circomlbjs'; -// import snark from 'snarkjs'; +import circuit from 'circuits/circle_js/circle_constraints.json'; +import circ from 'circomlibjs'; +import snark from 'snarkjs'; import { buildBabyjub, buildPoseidon } from 'circomlibjs'; import { randomUUID } from 'expo-crypto'; diff --git a/src/utils/zkpid.ts b/src/utils/zkpid.ts index 19cf289..1c57282 100644 --- a/src/utils/zkpid.ts +++ b/src/utils/zkpid.ts @@ -14,8 +14,6 @@ import { } from './config'; import { ethers, Wallet, providers } from 'ethers'; import { memoize } from 'lodash'; -import './proving'; -// createProof('asjfnaf'); const defaultProvider = (): providers.Provider => new ethers.providers.AlchemyProvider( diff --git a/src/utils/zkpid.web.ts b/src/utils/zkpid.web.ts index bb568b9..622fc5c 100644 --- a/src/utils/zkpid.web.ts +++ b/src/utils/zkpid.web.ts @@ -6,6 +6,7 @@ import { debug } from './logging'; import { JubJubSigResponse } from 'types/GameMechanics'; import { ethers } from 'ethers'; import { Errorable } from 'types/UserConfig.js'; +import { proveCircleSummoning } from './proving.ts'; interface BrowserWalletSignResult { signature: string; @@ -20,6 +21,7 @@ const signWithBrowserWallet = async (message: string): Errorable; + return web as JubJubSigResponse; } catch (err) { console.warn('utils:zkpid:web signing error', err);