Skip to content

Commit

Permalink
fix file sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Aug 2, 2024
1 parent 5755515 commit 0b9903c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/rarimo/rarime.git"
},
"source": {
"shasum": "kUIv3z3J4/qC7LLUzOP1Bfir+ilD80aegGUEJOc4S1k=",
"shasum": "BTuyI3vOTg/hkWecj7adgJdcWDMtBy6LlI8uAoRbKTM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
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
6 changes: 3 additions & 3 deletions packages/snap/src/zkp/helpers/file-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const readBytesFile = async (path: string) => {
const readBytesFile = async (path: string) => {
const response = await fetch(path);
return new Uint8Array(await response?.arrayBuffer?.());
};

export const getSnapFileBytes = async (path: string) => {
const getSnapFileBytes = async (path: string) => {
const response = await snap.request({
method: 'snap_getFile',
params: { path },
Expand All @@ -21,7 +21,7 @@ export const getSnapFileBytes = async (path: string) => {
return bytes;
};

export const concatAndGetShardedFiles = async (
const concatAndGetShardedFiles = async (
paths: string[],
): Promise<Uint8Array> => {
const files = await Promise.all(paths.map(getSnapFileBytes));
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

0 comments on commit 0b9903c

Please sign in to comment.