Skip to content
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

Split MTP V2 OnChain zkey file #54

Merged
merged 10 commits into from
Aug 2, 2024
Merged
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
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extract `RarimeSnapBase` as a base snap instance and `ZkpSnap` as an instance for ZKP interactions
- Define global reusable types & helpers

## [2.1.2] - 2024-07-29

### Fixed
- `@rarimo/rarime` - split big `.zkey` files into smaller ones to fit chrome limits

## [2.1.1] - 2024-06-18

### Fixed
- `@rarimo/rarime-connector`
- - request params: `wallet_invokeSnap` method should accept `params` only if it exists, passing `undefined` would cause an error at least in Metamask Flask version `11.16.10-flask.0` and Metamask version `11.16.11`

## [2.1.0] - 2024-04-08
### Added
- `@rarimo/rarime`:
Expand Down Expand Up @@ -201,7 +212,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Implemented `@rarimo/rarime-connector` and `@rarimo/rarime` packages

[Unreleased]: https://github.com/rarimo/rarime/compare/2.1.0...HEAD
[Unreleased]: https://github.com/rarimo/rarime/compare/2.1.2...HEAD
[2.1.2]: https://github.com/rarimo/rarime/compare/2.1.1...2.1.2
[2.1.1]: https://github.com/rarimo/rarime/compare/2.1.0...2.1.1
[2.1.0]: https://github.com/rarimo/rarime/compare/2.0.3...2.1.0
[2.0.3]: https://github.com/rarimo/rarime/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/rarimo/rarime/compare/2.0.1...2.0.2
Expand Down
2 changes: 1 addition & 1 deletion packages/connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/rarime-connector",
"version": "3.0.0-rc.0",
"version": "3.0.0-rc.2",
"description": "Facilitates interaction between a DApp and RariMe MetaMask snap",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/connector/src/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "3.0.0-rc.0"
"version": "3.0.0-rc.2"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/rarime",
"version": "3.0.0-rc.0",
"version": "3.0.0-rc.2",
"description": "RariMe is a MetaMask Snap that safely holds any of your credentials and allows you to prove your identity without revealing any personal data. Powered by Rarimo Protocol and Zero-Knowledge Proof technology.",
"repository": {
"type": "git",
Expand Down
8 changes: 5 additions & 3 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "3.0.0-rc.0",
"version": "3.0.0-rc.2",
"description": "Securely store and manage all of your identity credentials. Use them across chains with ZK-protected privacy guarantees.",
"proposedName": "RariMe",
"repository": {
"type": "git",
"url": "https://github.com/rarimo/rarime.git"
},
"source": {
"shasum": "xB5FVBf7NayGVtDRsVxWfuGwCF8vvt6adWySQle9npI=",
"shasum": "B4twi73NQGZuEBN6R8OB1sc+mLfOnW2nqamdYfSIo8Q=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -20,7 +20,9 @@
"./assets/circuits/auth/circuit.wasm",
"./assets/circuits/auth/circuit_final.zkey",
"./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm",
"./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey"
"./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part1",
"./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part2",
"./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part3"
]
},
"initialPermissions": {
Expand Down
7 changes: 5 additions & 2 deletions packages/snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export const config = {

CIRCUIT_MTP_V2_ON_CHAIN_WASM_URL:
'./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm',
CIRCUIT_MTP_V2_ON_CHAIN_FINAL_KEY_URL:
'./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey',
CIRCUIT_MTP_V2_ON_CHAIN_FINAL_KEY_URL: [
'./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part1',
'./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part2',
'./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey.part3',
],
};

export const HOSTNAMES_WHITELIST = [
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/zkp/handlers/CreateProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import type { TextField } from '@/types';
import { isValidCreateProofRequest } from '@/typia-generated';
import { getSnapFileBytes, VCManager } from '@/zkp/helpers';
import { getFileBytes, VCManager } from '@/zkp/helpers';

export const createProof = async ({
request,
Expand Down Expand Up @@ -136,7 +136,7 @@ export const createProof = async ({
const zkpGen = new ZkpGen(identity, createProofRequest, vc, {
coreEvmRpcApiUrl: coreChainInfo.rpcEvm,
coreStateContractAddress: coreChainInfo.stateContractAddress,
loadingCircuitCb: getSnapFileBytes,
loadingCircuitCb: getFileBytes,
circuitsUrls: {
[CircuitId.AtomicQuerySigV2]: {
wasmUrl: config.CIRCUIT_SIG_V2_WASM_URL,
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/zkp/handlers/SaveCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { config } from '@/config';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { isValidSaveCredentialsOfferRequest } from '@/typia-generated';
import { getSnapFileBytes, VCManager } from '@/zkp/helpers';
import { getFileBytes, VCManager } from '@/zkp/helpers';

export const saveCredentials = async ({
request,
Expand Down Expand Up @@ -69,7 +69,7 @@ export const saveCredentials = async ({
const authProof = new AuthZkp(identity, offer, {
coreEvmRpcApiUrl: coreChainInfo.rpcEvm,
coreStateContractAddress: coreChainInfo.stateContractAddress,
loadingCircuitCb: getSnapFileBytes,
loadingCircuitCb: getFileBytes,
circuitsUrls: {
wasmUrl: config.CIRCUIT_AUTH_WASM_URL,
keyUrl: config.CIRCUIT_AUTH_FINAL_KEY_URL,
Expand Down
31 changes: 30 additions & 1 deletion packages/snap/src/zkp/helpers/file-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const getSnapFileBytes = async (path: string) => {
const readBytesFile = async (path: string) => {
const response = await fetch(path);
return new Uint8Array(await response?.arrayBuffer?.());
};

const getSnapFileBytes = async (path: string) => {
const response = await snap.request({
method: 'snap_getFile',
params: { path },
Expand All @@ -15,3 +20,27 @@ export const getSnapFileBytes = async (path: string) => {

return bytes;
};

const concatAndGetShardedFiles = async (
paths: string[],
): Promise<Uint8Array> => {
const files = await Promise.all(paths.map(getSnapFileBytes));

return new Uint8Array(
files.reduce((acc, fileBytes) => {
return [...acc, ...fileBytes];
}, []),
);
};

export const getFileBytes = async (path: string | string[]) => {
if (typeof path === 'string') {
try {
return await readBytesFile(new URL(path).href);
} catch (error) {
return await getSnapFileBytes(path);
}
}

return await concatAndGetShardedFiles(path);
};
2 changes: 1 addition & 1 deletion packages/zkp-iden3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/zkp-iden3",
"version": "3.0.0-rc.0",
"version": "3.0.0-rc.2",
"description": "Tools that generate zero-knowledge proofs for the Iden3 protocol.",
"repository": {
"type": "git",
Expand Down
14 changes: 11 additions & 3 deletions packages/zkp-iden3/src/helpers/file-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ export const readBytesFile = async (path: string) => {
};

export const getFileBytes = async (
path: string,
loadCircuitsCb?: (path: string) => Promise<Uint8Array>,
path: string | string[],
loadCircuitsCb?: (path: string | string[]) => Promise<Uint8Array>,
): Promise<Uint8Array> => {
return loadCircuitsCb?.(path) || readBytesFile(path);
if (typeof path === 'string') {
return loadCircuitsCb?.(path) || readBytesFile(path);
}

if (!loadCircuitsCb) {
throw new TypeError('loadCircuitsCb is required for multiple paths');
}

return loadCircuitsCb?.(path);
};
4 changes: 2 additions & 2 deletions packages/zkp-iden3/src/instances/auth-zkp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type { Identity } from '@/instances/identity';
import type { W3CCredential } from '@/types';

type Config = {
loadingCircuitCb?: (path: string) => Promise<Uint8Array>;
circuitsUrls: { wasmUrl: string; keyUrl: string };
loadingCircuitCb?: (path: string | string[]) => Promise<Uint8Array>;
circuitsUrls: { wasmUrl: string; keyUrl: string | string[] };

coreEvmRpcApiUrl: string;
coreStateContractAddress: string;
Expand Down
7 changes: 5 additions & 2 deletions packages/zkp-iden3/src/instances/zkp-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ import type {
} from '@/types';

type Config = {
loadingCircuitCb?: (path: string) => Promise<Uint8Array>;
circuitsUrls: Record<CircuitId, { wasmUrl: string; keyUrl: string }>;
loadingCircuitCb?: (path: string | string[]) => Promise<Uint8Array>;
circuitsUrls: Record<
CircuitId,
{ wasmUrl: string; keyUrl: string | string[] }
>;

coreEvmRpcApiUrl: string;
coreStateContractAddress: string;
Expand Down
Loading
Loading