Skip to content

Commit

Permalink
refactored snap into separate rarimo package
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Mar 6, 2024
1 parent dae5489 commit 2ee4d3c
Show file tree
Hide file tree
Showing 30 changed files with 126 additions and 2,290 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,20 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=16.0.0"
},
"resolutions": {
"rarimo-js-sdk-monorepo-root": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk",
"@rarimo/bridge": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/bridge",
"@rarimo/client": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/client",
"@rarimo/nft-checkout": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/nft-checkout",
"@rarimo/provider": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/provider",
"@rarimo/providers-evm": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-evm",
"@rarimo/providers-near": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-near",
"@rarimo/providers-solana": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-solana",
"@rarimo/react-nft-checkout": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/react-nft-checkout",
"@rarimo/react-provider": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/react-provider",
"@rarimo/shared": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/shared",
"@rarimo/swap": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/swap",
"@rarimo/zkp-iden3": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/zkp-iden3"
}
}
1 change: 1 addition & 0 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@noble/hashes": "^1.3.3",
"@noble/secp256k1": "1.7.1",
"@rarimo/rarime-connector": "2.1.0-rc.3",
"@rarimo/zkp-iden3": "*",
"base64-js": "^1.5.1",
"bech32": "^2.0.0",
"buffer": "6.0.3",
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": "7bsozDwYAOD2TjXCs29INb7vtKXR4BccEF5wHXh6Wpk=",
"shasum": "Ms7L0rMmYYffBfujJZ8pCOsb1Uhda71snhVKmMTWIbI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/types/storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ChainInfo } from '@rarimo/rarime-connector';
import type { W3CCredential } from '@rarimo/zkp-iden3';

import type { StorageKeys } from '@/enums';
import type { W3CCredential } from '@/zkp/types';

export type StorageMap = {
[StorageKeys.identity]: {
Expand Down
128 changes: 0 additions & 128 deletions packages/snap/src/zkp/auth-zkp.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/snap/src/zkp/const/general.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/snap/src/zkp/const/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/snap/src/zkp/enums/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/snap/src/zkp/enums/proof.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/snap/src/zkp/handlers/CheckStateContractSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import type {
RPCMethods,
SnapRequestsResponses,
} from '@rarimo/rarime-connector';
import { checkIfStateSynced } from '@rarimo/zkp-iden3';

import { checkIfStateSynced } from '@/zkp/helpers';
import { getProviderChainInfo } from '@/zkp/helpers';

export const checkStateContractSync = async (): Promise<
SnapRequestsResponses[RPCMethods.CheckStateContractSync]
> => {
return checkIfStateSynced();
const chainInfo = await getProviderChainInfo();

return checkIfStateSynced(chainInfo.id);
};
4 changes: 2 additions & 2 deletions packages/snap/src/zkp/handlers/CreateIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type {
SnapRequestParams,
SnapRequestsResponses,
} from '@rarimo/rarime-connector';
import { Identity, isDidSupported } from '@rarimo/zkp-iden3';
import { utils } from 'ethers';

import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { genPkHexFromEntropy, isDidSupported } from '@/zkp/helpers';
import { Identity } from '@/zkp/identity';
import { genPkHexFromEntropy } from '@/zkp/helpers';

export const createIdentity = async ({
request,
Expand Down
35 changes: 22 additions & 13 deletions packages/snap/src/zkp/handlers/CreateProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ import type {
SnapRequestsResponses,
} from '@rarimo/rarime-connector';
import { CircuitId } from '@rarimo/rarime-connector';

import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import type { TextField } from '@/types';
import { isValidCreateProofRequest } from '@/typia-generated';
import type { GetStateInfoResponse, MerkleProof } from '@rarimo/zkp-iden3';
import {
ZkpGen,
Identity,
checkIfStateSynced,
getCoreOperationByIndex,
getProviderChainInfo,
getRarimoCoreUrl,
loadDataFromRarimoCore,
parseDidV2,
} from '@rarimo/zkp-iden3';

import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import type { TextField } from '@/types';
import { isValidCreateProofRequest } from '@/typia-generated';
import {
getSnapFileBytes,
VCManager,
getProviderChainInfo,
} from '@/zkp/helpers';
import { Identity } from '@/zkp/identity';
import type { GetStateInfoResponse, MerkleProof } from '@/zkp/types';
import { ZkpGen } from '@/zkp/zkp-gen';

export const createProof = async ({
request,
Expand Down Expand Up @@ -129,15 +132,18 @@ export const createProof = async ({

const identity = await Identity.create(identityStorage.privateKeyHex);

const zkpGen = new ZkpGen(identity, createProofRequest, vc);
const chainInfo = await getProviderChainInfo();

// ================ LOAD STATE DETAILS =====================
const zkpGen = new ZkpGen(identity, createProofRequest, vc, {
chainId: chainInfo.id,
loadingCircuitCb: getSnapFileBytes,
});

const chainInfo = await getProviderChainInfo();
// ================ LOAD STATE DETAILS =====================

const rarimoCoreUrl = getRarimoCoreUrl(chainInfo.id);

const isSynced = await checkIfStateSynced();
const isSynced = await checkIfStateSynced(chainInfo.id);

const did = parseDidV2(issuerDid);

Expand All @@ -146,14 +152,17 @@ export const createProof = async ({
const issuerHexId = `0x0${issuerId.bigInt().toString(16)}`;

const stateData = await loadDataFromRarimoCore<GetStateInfoResponse>(
chainInfo.id,
`/rarimo/rarimo-core/identity/state/${issuerHexId}`,
);
const merkleProof = await loadDataFromRarimoCore<MerkleProof>(
chainInfo.id,
`/rarimo/rarimo-core/identity/state/${issuerHexId}/proof`,
stateData.state.createdAtBlock,
);

const operation = await getCoreOperationByIndex(
chainInfo.id,
stateData.state.lastUpdateOperationIndex,
);

Expand Down
16 changes: 12 additions & 4 deletions packages/snap/src/zkp/handlers/SaveCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import type {
SnapRequestParams,
SnapRequestsResponses,
} from '@rarimo/rarime-connector';
import { AuthZkp, Identity } from '@rarimo/zkp-iden3';

import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';
import { isValidSaveCredentialsOfferRequest } from '@/typia-generated';
import { AuthZkp } from '@/zkp/auth-zkp';
import { VCManager } from '@/zkp/helpers';
import { Identity } from '@/zkp/identity';
import {
getProviderChainInfo,
getSnapFileBytes,
VCManager,
} from '@/zkp/helpers';

export const saveCredentials = async ({
request,
Expand Down Expand Up @@ -60,7 +63,12 @@ export const saveCredentials = async ({

const identity = await Identity.create(identityStorage.privateKeyHex);

const authProof = new AuthZkp(identity, offer);
const currentChain = await getProviderChainInfo();

const authProof = new AuthZkp(identity, offer, {
chainId: currentChain.id,
loadingCircuitCb: getSnapFileBytes,
});

const credentials = await authProof.getVerifiableCredentials();

Expand Down
Loading

0 comments on commit 2ee4d3c

Please sign in to comment.