Skip to content

Commit

Permalink
Update rarime connector (#25)
Browse files Browse the repository at this point in the history
* upd connector, major

* hotfix

* bump connector
  • Loading branch information
lukachi authored Aug 2, 2024
1 parent e65f4be commit bd0588a
Show file tree
Hide file tree
Showing 4 changed files with 671 additions and 564 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@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.1",
"@rarimo/rarime-connector": "^3.0.0-rc.2",
"@sentry/react": "7.63.0",
"@sentry/rollup-plugin": "^2.7.1",
"@uauth/js": "^2.8.0",
Expand Down
42 changes: 14 additions & 28 deletions src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
CheckCredentialExistenceRequestParams,
type CreateProofRequestParams,
enableSnap,
isMetamaskInstalled as detectMetamaskInstalled,
isSnapInstalled as detectSnapInstalled,
type SaveCredentialsRequestParams,
SaveCredentialsResponse,
type SnapConnector,
type ZKPProofResponse,
ZkpSnap,
} from '@rarimo/rarime-connector'
import { createContext, FC, HTMLAttributes, useCallback, useState } from 'react'

Expand Down Expand Up @@ -86,11 +84,11 @@ export const MetamaskZkpSnapContext =
},
})

export const zkpSnap = new ZkpSnap()

const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
children,
}) => {
const [connector, setConnector] = useState<SnapConnector>()

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

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

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

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

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

const createProof = useCallback(
async (params: CreateProofRequestParams) => {
if (!connector) throw new TypeError('Connector is not defined')

return connector.createProof(params)
},
[connector],
)
const createProof = useCallback(async (params: CreateProofRequestParams) => {
return zkpSnap.createProof(params)
}, [])

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

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

const _isSnapInstalled = await zkpSnap.isInstalled()
setIsSnapInstalled(_isSnapInstalled)

return _isSnapInstalled
}, [])

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

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

return (
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/ZkpContext/ZkpContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -196,7 +197,7 @@ const ZkpContextProvider: FC<Props> = ({ children, ...rest }) => {

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

Expand Down
Loading

0 comments on commit bd0588a

Please sign in to comment.