Skip to content

Commit

Permalink
upd connector, fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Apr 1, 2024
1 parent a8c89f6 commit ddb98fc
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 2,263 deletions.
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
},
"dependencies": {
"@civic/ethereum-gateway-react": "0.13.4",
"@distributedlab/jac": "^1.0.0-rc.13",
"@distributedlab/tools": "^1.0.0-rc.13",
"@distributedlab/w3p": "^1.0.0-rc.13",
"@distributedlab/jac": "^1.0.0-rc.14",
"@distributedlab/tools": "^1.0.0-rc.14",
"@distributedlab/w3p": "1.0.0-rc.6",
"@iden3/js-crypto": "1.0.0-beta.1",
"@iden3/js-iden3-core": "1.0.0-beta.2",
"@iden3/js-jsonld-merklization": "1.0.0-beta.14",
"@iden3/js-jwz": "1.0.0-beta.2",
"@iden3/js-merkletree": "1.0.0-beta.4",
"@rarimo/rarime-connector": "2.1.0-rc.13",
"@rarimo/rarime-connector": "2.1.0-rc.21",
"@sentry/react": "7.63.0",
"@sentry/rollup-plugin": "^2.7.1",
"@uauth/js": "^2.8.0",
"@walletconnect/ethereum-provider": "^2.8.6",
"@walletconnect/modal": "^2.5.9",
"caip-api": "^2.0.0-beta.1",
"downshift": "^7.1.2",
"ejc": "^1.0.4",
Expand Down Expand Up @@ -95,10 +93,10 @@
"stylelint-scss": "^5.0.1",
"typechain": "^8.2.0",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"vite-plugin-checker": "^0.6.1",
"vite": "^4.5.3",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-html": "^3.2.0",
"vite-plugin-node-polyfills": "^0.9.0",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-svg-icons": "^2.0.1",
"vite-tsconfig-paths": "^4.0.3",
"yorkie": "^2.0.0"
Expand Down
3 changes: 0 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { config } from '@config'
import { Fetcher } from '@distributedlab/fetcher'
import { JsonApiClient } from '@distributedlab/jac'
import { ZkpSnap } from '@rarimo/rarime-connector'

export let api: JsonApiClient

export let issuerApi: Fetcher

export const zkpSnap = new ZkpSnap()

export const initApi = () => {
api = new JsonApiClient({
baseUrl: config.API_URL,
Expand Down
45 changes: 30 additions & 15 deletions src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {
CheckCredentialExistenceRequestParams,
CreateProofRequestParams,
type CreateProofRequestParams,
enableSnap,
isMetamaskInstalled as detectMetamaskInstalled,
SaveCredentialsRequestParams,
isSnapInstalled as detectSnapInstalled,
type SaveCredentialsRequestParams,
SaveCredentialsResponse,
ZKPProofResponse,
type SnapConnector,
type ZKPProofResponse,
} from '@rarimo/rarime-connector'
import { createContext, FC, HTMLAttributes, useCallback, useState } from 'react'

import { zkpSnap } from '@/api'
import { saveVCResponse } from '@/contexts/ZkpContext/ZkpContext'

/**
Expand Down Expand Up @@ -87,6 +89,8 @@ export const MetamaskZkpSnapContext =
const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
children,
}) => {
const [connector, setConnector] = useState<SnapConnector>()

const [isMetamaskInstalled, setIsMetamaskInstalled] = useState(false)
const [isSnapInstalled, setIsSnapInstalled] = useState(false)

Expand All @@ -100,22 +104,31 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
* or return the existing one
*/
const createIdentity = useCallback(async () => {
return zkpSnap.createIdentity()
}, [])
if (!connector) throw new TypeError('Connector is not defined')

return connector.createIdentity()
}, [connector])

/**
* Get the verifiable credentials from the snap.
*/
const saveVerifiableCredentials = useCallback(
async (params: SaveCredentialsRequestParams) => {
return zkpSnap.saveCredentials?.(params)
if (!connector) throw new TypeError('Connector is not defined')

return connector.saveCredentials?.(params)
},
[],
[connector],
)

const createProof = useCallback(async (params: CreateProofRequestParams) => {
return zkpSnap.createProof(params)
}, [])
const createProof = useCallback(
async (params: CreateProofRequestParams) => {
if (!connector) throw new TypeError('Connector is not defined')

return connector.createProof(params)
},
[connector],
)

const checkMetamaskExists = useCallback(async () => {
const _isMetamaskInstalled = await detectMetamaskInstalled()
Expand All @@ -126,15 +139,17 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
}, [])

const checkSnapExists = useCallback(async () => {
const _isSnapInstalled = await zkpSnap.isInstalled()
const _isSnapInstalled = await detectSnapInstalled()

setIsSnapInstalled(_isSnapInstalled)

return _isSnapInstalled
}, [])

const connectOrInstallSnap = useCallback(async () => {
await zkpSnap.enable()
const snap = await enableSnap()
const connector = await snap.getConnector()
setConnector(connector)
}, [])

const checkSnapStatus = useCallback(async () => {
Expand All @@ -154,9 +169,9 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
async (
params: CheckCredentialExistenceRequestParams,
): Promise<SaveCredentialsResponse[] | undefined> => {
return zkpSnap?.checkCredentialExistence?.(params)
return connector?.checkCredentialExistence?.(params)
},
[],
[connector],
)

return (
Expand Down
3 changes: 1 addition & 2 deletions src/contexts/ZkpContext/ZkpContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { config, SUPPORTED_CHAINS } from '@config'
import { type EthTransactionResponse } from '@distributedlab/w3p'
import { type TransactionRequest } from '@ethersproject/providers'
import {
CircuitId,
CreateProofRequestParams,
SaveCredentialsRequestParams,
StateInfo,
Expand Down Expand Up @@ -197,7 +196,7 @@ const ZkpContextProvider: FC<Props> = ({ children, ...rest }) => {

const buildProofRequest = useCallback(
(issuerDid: string, vcType: string[]): CreateProofRequestParams => ({
circuitId: CircuitId.AtomicQueryMTPV2OnChain,
circuitId: 'credentialAtomicQueryMTPV2OnChain',
accountAddress: provider?.address,
issuerDid: issuerDid,

Expand Down
7 changes: 1 addition & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,9 @@ export default defineConfig(({ mode }) => {
sourcemap: true,

manualChunks: {
'js-merkletree': ['@iden3/js-merkletree'],
'js-jsonld-merklization': ['@iden3/js-jsonld-merklization'],
'js-crypto': ['@iden3/js-crypto'],
'js-jwz': ['@iden3/js-jwz'],
'js-iden3-core': ['@iden3/js-iden3-core'],
'near-api-js': ['near-api-js'],
'ethereum-gateway-react': ['@civic/ethereum-gateway-react'],
'rarime-connector': ['@rarimo/rarime-connector'],
// 'rarime-connector': ['@rarimo/rarime-connector'],
snarkjs: ['snarkjs'],
uauth: ['@uauth/js'],
},
Expand Down
Loading

0 comments on commit ddb98fc

Please sign in to comment.