Skip to content

Commit

Permalink
upd auth instances agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Mar 7, 2024
1 parent 706e6a7 commit cbd7db6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/connector/src/zkp/types/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ export type CreateIdentityRequestParams = {
privateKeyHex?: string;
};

export type CheckCredentialExistenceRequestParams = {
claimOffer?: SaveCredentialsRequestParams;
proofRequest?: CreateProofRequestParams;
};

export type SaveCredentialsRequestParams = {
body: {
Credentials: [
Expand All @@ -27,6 +22,11 @@ export type SaveCredentialsRequestParams = {
type: string;
};

export type CheckCredentialExistenceRequestParams = {
claimOffer?: SaveCredentialsRequestParams;
proofRequest?: CreateProofRequestParams;
};

export type RemoveCredentialsRequestParams = {
ids: string[];
};
Expand Down
1 change: 0 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@iden3/js-merkletree": "1.1.2",
"@leapwallet/buffer-boba": "^0.1.8",
"@leapwallet/parser-parfait": "^0.7.0",
"@metamask/key-tree": "^9.0.0",
"@metamask/snaps-jest": "^5.0.0",
"@metamask/snaps-sdk": "^2.0.0",
"@metamask/snaps-utils": "^6.0.0",
Expand Down
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": "1+p7tiw9zprBgeZrAavS6zqrPs2fwRDOTAN1QCIccM8=",
"shasum": "VV2DJhPawNyH1L9DvBeQ+BYgHpwx1Hu0kD+78EIJNtI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5 changes: 5 additions & 0 deletions packages/snap/src/zkp/handlers/CreateIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import { Identity, isDidSupported } from '@rarimo/zkp-iden3';
import { utils } from 'ethers';

import { config } from '@/config';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { genPkHexFromEntropy } from '@/zkp/helpers';
Expand Down Expand Up @@ -60,6 +61,10 @@ export const createIdentity = async ({
}

const identity = await Identity.create(
{
schemaHashHex: config.AUTH_BJJ_CREDENTIAL_HASH,
idType: config.ID_TYPE,
},
params?.privateKeyHex || (await genPkHexFromEntropy()),
);

Expand Down
27 changes: 26 additions & 1 deletion packages/snap/src/zkp/handlers/CreateProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from '@rarimo/rarime-connector';
import { ZkpGen, Identity, parseDidV2 } from '@rarimo/zkp-iden3';

import { config } from '@/config';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import type { TextField } from '@/types';
Expand Down Expand Up @@ -128,13 +129,37 @@ export const createProof = async ({
throw new Error('User rejected request');
}

const identity = await Identity.create(identityStorage.privateKeyHex);
const identity = await Identity.create(
{
schemaHashHex: config.AUTH_BJJ_CREDENTIAL_HASH,
idType: config.ID_TYPE,
},
identityStorage.privateKeyHex,
);

const chainInfo = await getProviderChainInfo();

const zkpGen = new ZkpGen(identity, createProofRequest, vc, {
chainInfo,
loadingCircuitCb: getSnapFileBytes,
circuitsUrls: {
[CircuitId.AtomicQuerySigV2]: {
wasmUrl: config.CIRCUIT_SIG_V2_WASM_URL,
keyUrl: config.CIRCUIT_SIG_V2_FINAL_KEY_URL,
},
[CircuitId.AtomicQueryMTPV2]: {
wasmUrl: config.CIRCUIT_MTP_V2_WASM_URL,
keyUrl: config.CIRCUIT_MTP_V2_FINAL_KEY_URL,
},
[CircuitId.AtomicQuerySigV2OnChain]: {
wasmUrl: config.CIRCUIT_SIG_V2_ON_CHAIN_WASM_URL,
keyUrl: config.CIRCUIT_SIG_V2_ON_CHAIN_FINAL_KEY_URL,
},
[CircuitId.AtomicQueryMTPV2OnChain]: {
wasmUrl: config.CIRCUIT_MTP_V2_ON_CHAIN_WASM_URL,
keyUrl: config.CIRCUIT_MTP_V2_ON_CHAIN_FINAL_KEY_URL,
},
},
});

// ================ LOAD STATE DETAILS =====================
Expand Down
13 changes: 12 additions & 1 deletion packages/snap/src/zkp/handlers/SaveCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from '@rarimo/rarime-connector';
import { AuthZkp, Identity } from '@rarimo/zkp-iden3';

import { config } from '@/config';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { isValidSaveCredentialsOfferRequest } from '@/typia-generated';
Expand Down Expand Up @@ -61,13 +62,23 @@ export const saveCredentials = async ({

const vcManager = await VCManager.create();

const identity = await Identity.create(identityStorage.privateKeyHex);
const identity = await Identity.create(
{
schemaHashHex: config.AUTH_BJJ_CREDENTIAL_HASH,
idType: config.ID_TYPE,
},
identityStorage.privateKeyHex,
);

const chainInfo = await getProviderChainInfo();

const authProof = new AuthZkp(identity, offer, {
chainInfo,
loadingCircuitCb: getSnapFileBytes,
circuitsUrls: {
wasmUrl: config.CIRCUIT_AUTH_WASM_URL,
keyUrl: config.CIRCUIT_AUTH_FINAL_KEY_URL,
},
});

const credentials = await authProof.getVerifiableCredentials();
Expand Down
9 changes: 8 additions & 1 deletion packages/snap/src/zkp/helpers/credential-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { DocumentNode } from 'graphql/language';
import VerifiableRuntimeComposite from '../../../ceramic/composites/VerifiableCredentials-runtime.json';
import VerifiableRuntimeCompositeV2 from '../../../ceramic/composites/VerifiableCredentialsV2-runtime.json';

import { config } from '@/config';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { CeramicProvider } from '@/zkp/helpers/ceramic-helpers';
Expand Down Expand Up @@ -501,7 +502,13 @@ export const migrateVCsToLastCeramicModel = async () => {

const entropyKeyHex = await genPkHexFromEntropy();

const entropyIdentity = await Identity.create(entropyKeyHex);
const entropyIdentity = await Identity.create(
{
idType: config.ID_TYPE,
schemaHashHex: config.AUTH_BJJ_CREDENTIAL_HASH,
},
entropyKeyHex,
);

const identityStorage = await snapStorage.getItem(StorageKeys.identity);

Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5746,7 +5746,6 @@ __metadata:
"@leapwallet/buffer-boba": ^0.1.8
"@leapwallet/parser-parfait": ^0.7.0
"@metamask/auto-changelog": ^3.4.4
"@metamask/key-tree": ^9.0.0
"@metamask/snaps-cli": ^5.0.0
"@metamask/snaps-jest": ^5.0.0
"@metamask/snaps-sdk": ^2.0.0
Expand Down

0 comments on commit cbd7db6

Please sign in to comment.