Skip to content

Commit

Permalink
Update rarime connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ardier16 committed Jan 25, 2024
1 parent d302980 commit 4818f1b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@distributedlab/tools": "^1.0.0-rc.8",
"@distributedlab/w3p": "^1.0.0-rc.8",
"@rarimo/rarime-connector": "2.0.0-rc.0",
"@rarimo/rarime-connector": "2.0.1",
"@walletconnect/modal": "^2.6.2",
"downshift": "^7.1.2",
"framer-motion": "^10.12.10",
Expand Down
45 changes: 34 additions & 11 deletions src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import {
CheckCredentialExistenceRequestParams,
type CreateProofRequestParams,
enableSnap,
isMetamaskInstalled as detectMetamaskInstalled,
isSnapInstalled as detectSnapInstalled,
type SaveCredentialsRequestParams,
SaveCredentialsResponse,
type SnapConnector,
type W3CCredential,
W3CCredential,
type ZKPProofResponse,
} from '@rarimo/rarime-connector'
import { createContext, FC, HTMLAttributes, useCallback, useState } from 'react'

export type saveVCResponse = { type: string[]; issuer: string }

/**
* The snap origin to use.
* Will default to the local hosted snap if no value is provided in environment.
Expand All @@ -21,13 +25,16 @@ interface MetamaskZkpSnapContextValue {

isLocalSnap: (snapId: string) => boolean

createIdentity: () => Promise<{
identityIdString: string
identityIdBigIntString: string
}>
getVerifiableCredentials: (
createIdentity: () => Promise<
| {
identityIdString: string
identityIdBigIntString: string
}
| undefined
>
saveVerifiableCredentials: (
params: SaveCredentialsRequestParams,
) => Promise<W3CCredential[] | undefined>
) => Promise<saveVCResponse[] | undefined>
createProof: (
params: CreateProofRequestParams,
) => Promise<ZKPProofResponse | undefined>
Expand All @@ -37,6 +44,9 @@ interface MetamaskZkpSnapContextValue {
isMetamaskInstalled: boolean
isSnapInstalled: boolean
}>
checkCredentialExistence: (
params: CheckCredentialExistenceRequestParams,
) => Promise<SaveCredentialsResponse[] | undefined>

connectOrInstallSnap: () => Promise<void>
getCredentials: () => Promise<W3CCredential[]>
Expand All @@ -54,7 +64,7 @@ export const MetamaskZkpSnapContext =
createIdentity: () => {
throw new Error('MetamaskZkpSnapContext not initialized')
},
getVerifiableCredentials: () => {
saveVerifiableCredentials: () => {
throw new Error('MetamaskZkpSnapContext not initialized')
},
createProof: () => {
Expand All @@ -69,6 +79,10 @@ export const MetamaskZkpSnapContext =
checkSnapStatus: () => {
throw new Error('MetamaskZkpSnapContext not initialized')
},
checkCredentialExistence: () => {
throw new Error('MetamaskZkpSnapContext not initialized')
},

connectOrInstallSnap: () => {
throw new Error('MetamaskZkpSnapContext not initialized')
},
Expand Down Expand Up @@ -103,7 +117,7 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
/**
* Get the verifiable credentials from the snap.
*/
const getVerifiableCredentials = useCallback(
const saveVerifiableCredentials = useCallback(
async (params: SaveCredentialsRequestParams) => {
if (!connector) throw new TypeError('Connector is not defined')

Expand Down Expand Up @@ -146,7 +160,6 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
const connectOrInstallSnap = useCallback(async () => {
const snap = await enableSnap()
const connector = await snap.getConnector()

setConnector(connector)
}, [])

Expand All @@ -163,6 +176,15 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
}
}, [checkMetamaskExists, checkSnapExists])

const checkCredentialExistence = useCallback(
async (
params: CheckCredentialExistenceRequestParams,
): Promise<SaveCredentialsResponse[] | undefined> => {
return connector?.checkCredentialExistence?.(params)
},
[connector],
)

return (
<MetamaskZkpSnapContext.Provider
value={{
Expand All @@ -172,8 +194,9 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
isLocalSnap,

createIdentity,
getVerifiableCredentials,
saveVerifiableCredentials,
createProof,
checkCredentialExistence,

checkMetamaskExists,
checkSnapExists,
Expand Down
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1085,12 +1085,13 @@
picocolors "^1.0.0"
tslib "^2.5.0"

"@rarimo/[email protected].0-rc.0":
version "2.0.0-rc.0"
resolved "https://registry.yarnpkg.com/@rarimo/rarime-connector/-/rarime-connector-2.0.0-rc.0.tgz#1e17cf0b943eb346b92561276c420e12cf85640e"
integrity sha512-PUSkIog3p1Y1k9JrFv5UJEw059hdSdXC5cVlV5OZcPIMBl1WmKoLEDCzllr+7uf4gU+ql2WrDco70JjCYfhiwQ==
"@rarimo/[email protected].1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@rarimo/rarime-connector/-/rarime-connector-2.0.1.tgz#e5c8c448981afbe0f339a334a645eb7206cb93f9"
integrity sha512-CVBWAFJo86NFNg59r2nmeeJYtTy0repdNEWaRNbsp8TI4Bi9rZ27JHPTCR7dP7Y7RRG2/rWlPrOLsKD4KxSG1A==
dependencies:
"@ethersproject/providers" "5.7.2"
compare-versions "^6.1.0"
ethers "5.7.2"

"@remix-run/[email protected]":
Expand Down Expand Up @@ -2512,6 +2513,11 @@ commander@^8.0.0:
resolved "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==

compare-versions@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.0.tgz#3f2131e3ae93577df111dba133e6db876ffe127a"
integrity sha512-LNZQXhqUvqUTotpZ00qLSaify3b4VFD588aRr8MKFw4CMUr98ytzCW5wDH5qx/DEY5kCDXcbcRuCqL0szEf2tg==

component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz"
Expand Down

0 comments on commit 4818f1b

Please sign in to comment.