-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from yurenju/feat/signing-service
Feat/signing service
- Loading branch information
Showing
45 changed files
with
801 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,56 @@ | ||
import { MessageAction } from '@tw-did/core'; | ||
import { CredentialScreen, useCredentials } from '@tw-did/react-library'; | ||
import { useCallback } from 'react'; | ||
import { | ||
CredentialScreen, | ||
CredentialType, | ||
useTwDid, | ||
useCredentials, | ||
CredentialMode, | ||
ActionId, | ||
} from '@tw-did/react-library'; | ||
import { VerifiableCredential } from '@veramo/core-types'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
export function CredentialSelection() { | ||
const { | ||
user, | ||
getEthereumVerifiableCredential, | ||
generateSemaphoreVerifiableCredential, | ||
getSemaphoreGroup, | ||
generateSemaphoreIdentity, | ||
sendCredential, | ||
} = useTwDid(); | ||
const { isConnected } = useAccount(); | ||
const { credentials, sendCredential } = useCredentials(); | ||
const checkLogin = useCallback(() => true, []); | ||
const credentials = useCredentials( | ||
CredentialMode.Select, | ||
user?.nationalId, | ||
user?.ethereumAccount | ||
); | ||
|
||
const handleAction = async ( | ||
credentialKey: CredentialType, | ||
actionId: ActionId | ||
) => { | ||
let vc: VerifiableCredential | null = null; | ||
if (credentialKey === CredentialType.ETHEREUM) { | ||
vc = await getEthereumVerifiableCredential(); | ||
} else if (credentialKey === CredentialType.SEMAPHORE) { | ||
const identity = await generateSemaphoreIdentity(); | ||
const group = await getSemaphoreGroup(); | ||
|
||
vc = await generateSemaphoreVerifiableCredential(identity, group); | ||
} | ||
|
||
if (vc) { | ||
if (actionId === ActionId.SELECT) { | ||
sendCredential(MessageAction.SELECT_CREDENTIAL, vc); | ||
} | ||
} | ||
}; | ||
|
||
if (isConnected) | ||
return ( | ||
<div> | ||
<CredentialScreen | ||
credentials={credentials} | ||
actionLabels={['select']} | ||
onAction={(index, label) => { | ||
if (label !== 'select') return; | ||
sendCredential(MessageAction.SELECT_CREDENTIAL, credentials[index]); | ||
}} | ||
checkLogin={checkLogin} | ||
/> | ||
<CredentialScreen credentials={credentials} onAction={handleAction} /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.