Skip to content
Draft
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
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@
},
"license": "MIT or Apache-2.0",
"dependencies": {
"@0xpolygonid/js-sdk": "^1.7.5",
"@iden3/js-crypto": "^1.0.3",
"@iden3/js-iden3-core": "^1.1.0",
"@iden3/js-jsonld-merklization": "^1.1.2",
"@iden3/js-jwz": "^1.1.2",
"@iden3/js-merkletree": "^1.1.2",
"@iden3/react-native-rapidsnark": "../react-native-rapidsnark",
"@0xpolygonid/js-sdk": "^1.43.0",
"@iden3/js-crypto": "^1.3.2",
"@iden3/js-iden3-core": "^1.8.0",
"@iden3/js-jsonld-merklization": "^1.7.2",
"@iden3/js-jwz": "^1.13.1",
"@iden3/js-merkletree": "^1.5.1",
"@iden3/react-native-rapidsnark": "0.0.1-beta.2",
"@react-native-async-storage/async-storage": "^1.19.3",
"@react-navigation/bottom-tabs": "^6.5.9",
"@react-navigation/native": "^6.1.8",
"@react-navigation/native-stack": "^6.9.14",
"js-base64": "^3.7.5",
"node-libs-react-native": "^1.2.1",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native": "0.72.17",
"react-native-console-time-polyfill": "^1.2.3",
"react-native-fs": "^2.20.0",
"react-native-get-random-values": "^1.9.0",
"react-native-mmkv": "^2.10.2",
"react-native-quick-base64": "^2.0.7",
Expand All @@ -39,8 +40,8 @@
"react-native-webassembly": "0.3.2",
"react-native-webview": "^13.6.2",
"react-native-worklets-core": "^0.2.1",
"rfc4648": "^1.5.3",
"snarkjs": "^0.7.2",
"rfc4648": "^1.5.4",
"snarkjs": "^0.7.5",
"text-encoding-polyfill": "^0.6.7",
"uuid": "^9.0.1"
},
Expand Down
4 changes: 4 additions & 0 deletions share/proof/groth16prove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class ProvingMethodGroth16AuthV2 implements ProvingMethod {
return this.methodAlg.circuitId;
}

get supportedCircuits(): string[] {
return [this.methodAlg.circuitId];
}

async verify(
messageHash: Uint8Array,
proof: ZKProof,
Expand Down
34 changes: 23 additions & 11 deletions share/proof/prove.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {NativeModules} from 'react-native';
import {Platform} from 'react-native';
import RNFS from 'react-native-fs';
import {byteDecoder} from '@0xpolygonid/js-sdk';
import {ZKProof} from '@iden3/js-jwz';
import {fromByteArray} from 'react-native-quick-base64';
import {groth16Prove} from '@iden3/react-native-rapidsnark';
import {v4 as uuidv4} from 'uuid';

const rapidsnark = NativeModules.Rapidsnark;
export const reactNativeGroth16Prover = async (
inputs: Uint8Array,
provingKey: Uint8Array,
Expand All @@ -18,14 +20,24 @@ export const reactNativeGroth16Prover = async (

console.time('rapidsnark');

const {proof, pub_signals} = await rapidsnark.groth16_prover(
fromByteArray(provingKey),
calcResult,
);
console.timeEnd('rapidsnark');
const tmpDir =
Platform.OS === 'android'
? RNFS.CachesDirectoryPath
: RNFS.TemporaryDirectoryPath;
const zkeyPath = `${tmpDir}/proving_key_${uuidv4()}.zkey`;

return {
proof: JSON.parse(proof),
pub_signals: JSON.parse(pub_signals),
};
try {
await RNFS.writeFile(zkeyPath, fromByteArray(provingKey), 'base64');
const {proof, pub_signals} = await groth16Prove(zkeyPath, calcResult);
console.timeEnd('rapidsnark');

return {
proof: JSON.parse(proof),
pub_signals: JSON.parse(pub_signals),
};
} finally {
await RNFS.unlink(zkeyPath).catch(e =>
console.warn('Failed to clean up temp zkey file:', e),
);
}
};
8 changes: 3 additions & 5 deletions share/proof/verify.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {NativeModules} from 'react-native';
import {byteDecoder} from '@0xpolygonid/js-sdk';
import {ProofData, ZKProof} from '@iden3/js-jwz';
import {fromBigEndian} from '@iden3/js-iden3-core';

const rapidsnark = NativeModules.Rapidsnark;
import {groth16Verify} from '@iden3/react-native-rapidsnark';

export const reactNativeGroth16Verify = async (
pub_signals: string[],
proof: ProofData,
verificationKey: Uint8Array,
) => {
try {
return await rapidsnark.groth16_verify(
JSON.stringify(pub_signals),
return await groth16Verify(
JSON.stringify(proof),
JSON.stringify(pub_signals),
byteDecoder.decode(verificationKey),
);
} catch (e: any) {
Expand Down
11 changes: 11 additions & 0 deletions share/storage/app-storage-key-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ export class AppStoragePrivateKeyStore implements AbstractPrivateKeyStore {
JSON.stringify(data),
);
}

async list(): Promise<{alias: string; key: string}[]> {
const dataStr = await appStorage.getItem(
AppStoragePrivateKeyStore.storageKey,
);
if (!dataStr) {
return [];
}
const data: {id: string; value: string}[] = JSON.parse(dataStr);
return data.map(d => ({alias: d.id, key: d.value}));
}
}
6 changes: 3 additions & 3 deletions src/constants/common.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const RHS_URL = '';
export const RPC_URL = '';
export const RHS_URL = 'https://rhs-staging.polygonid.me';
export const RPC_URL = 'https://rpc-testnet.billions.network';

export const defaultEthConnectionConfig = [
{
Expand All @@ -9,7 +9,7 @@ export const defaultEthConnectionConfig = [
maxGasPrice: '100000000000',
confirmationBlockCount: 5,
confirmationTimeout: 600000,
contractAddress: '0x134b1be34911e39a8397ec6289782989729807a4',
contractAddress: '0x3C9acB2205Aa72A05F6D77d708b5Cf85FCa3a896',
receiptTimeout: 600000,
rpcResponseTimeout: 5000,
waitReceiptCycleTime: 30000,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function HomePage({route, navigation}: any) {
const [isInited, setIsInited] = useState(false);
const [credentials, setCredentials] = useState<W3CCredential[]>([]);
const [circuitsUrl, setCircuitsUrl] = useState<string>(
'http://192.168.0.100:3000',
'https://circuits.privado.id/circuits/',
);
const webViewContext = useContext(WebViewContext);

Expand Down
2 changes: 1 addition & 1 deletion src/services/App.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class AppService {
() => provingMethodGroth16AuthV2Instance,
);
let packageMgr = await AppService.getPackageMgr(
await circuitStorage.loadCircuitData(CircuitId.AuthV2),
await circuitStorage.loadCircuitData(CircuitId.AuthV3_8_32),
proofService.generateAuthV2Inputs.bind(proofService),
proofService.verifyState.bind(proofService),
);
Expand Down
66 changes: 25 additions & 41 deletions src/services/CircuitStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,61 +33,45 @@ export class CircuitStorageInstance {
console.log('loading circuits');
console.time('CircuitStorageInstance.init');
const customFetch = CircuitStorageInstance.customFetch;
const auth_w = customFetch('/AuthV2/circuit.wasm');
const mtp_w = customFetch('/credentialAtomicQueryMTPV2/circuit.wasm');
const sig_w = customFetch('/credentialAtomicQuerySigV2/circuit.wasm');
const auth_z = customFetch('/AuthV2/circuit_final.zkey');
const mtp_z = customFetch('/credentialAtomicQueryMTPV2/circuit_final.zkey');
const sig_z = customFetch('/credentialAtomicQuerySigV2/circuit_final.zkey');
const auth_w = customFetch('/authV3-8-32/circuit.wasm');
const auth_z = customFetch('/authV3-8-32/circuit_final.zkey');
const v3_z = customFetch('/credentialAtomicQueryV3/circuit_final.zkey');
const v3_w = customFetch('/credentialAtomicQueryV3/circuit.wasm');

const auth_j = customFetch('/AuthV2/verification_key.json');
const mtp_j = customFetch(
'/credentialAtomicQueryMTPV2/verification_key.json',
const auth_v = customFetch('/authV3-8-32/verification_key.json');
const v3_v = customFetch(
'/credentialAtomicQueryV3/verification_key.json',
);
const sig_j = customFetch(
'/credentialAtomicQuerySigV2/verification_key.json',
);


return Promise.all([
auth_w,
mtp_w,
sig_w,
v3_w,
auth_z,
mtp_z,
sig_z,
auth_j,
mtp_j,
sig_j,
v3_z,
auth_v,
v3_v,
]).then(
async ([
auth_w,
mtp_w,
sig_w,
auth_z,
mtp_z,
sig_z,
auth_j,
mtp_j,
sig_j,
auth_w,
v3_w,
auth_z,
v3_z,
auth_v,
v3_v,
]) => {
await this.instanceCS.saveCircuitData(CircuitId.AuthV2, {
circuitId: 'authV2'.toString(),
wasm: auth_w,
provingKey: auth_z,
verificationKey: auth_j,
verificationKey: auth_v,
});
await this.instanceCS.saveCircuitData(CircuitId.AtomicQueryMTPV2, {
circuitId: 'credentialAtomicQueryMTPV2'.toString(),
wasm: mtp_w,
provingKey: mtp_z,
verificationKey: mtp_j,
});
await this.instanceCS.saveCircuitData(CircuitId.AtomicQuerySigV2, {
circuitId: 'credentialAtomicQuerySigV2'.toString(),
wasm: sig_w,
provingKey: sig_z,
verificationKey: sig_j,
await this.instanceCS.saveCircuitData(CircuitId.AtomicQueryV3Stable, {
circuitId: 'credentialAtomicQueryV3Stable'.toString(),
wasm: v3_w,
provingKey: v3_z,
verificationKey: v3_v,
});

console.timeEnd('CircuitStorageInstance.init');
},
);
Expand Down
Loading