Skip to content

Commit

Permalink
feat: confirm multiple stamps with one signature (passportxyz#1145)
Browse files Browse the repository at this point in the history
* feat(iam): add challenge string for bulk EVM

* feat(app): sign bulk stamps one time

* fix(app): fix build error

---------

Co-authored-by: nutrina <[email protected]>
  • Loading branch information
chibie and nutrina authored Apr 20, 2023
1 parent 5aa8dca commit d72a1bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions app/components/RefreshMyStampsModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ export const RefreshMyStampsModalContent = ({
// TODO: add datadog logger
// datadogLogs.logger.info("Successfully saved Stamp", { platform: platform.platformId });
setLoading(true);
const providerIds: PROVIDER_ID[] = [];
const result = await Promise.all(
selectedEVMPlatformProviders?.map(async (platformProviders) => {
const platformId = platformProviders.platformId;
const providerIds =
const providerIdsTemp =
platformProviders.platformGroup.reduce((all, stamp, i) => {
return all.concat(stamp.providers?.map((provider) => provider.name as PROVIDER_ID));
}, [] as PROVIDER_ID[]) || [];
await handleFetchCredential(platformId, providerIds);
providerIds.push(...providerIdsTemp);
})
);
await handleFetchCredential(providerIds);
setLoading(false);
resetStampsAndProgressState();
navigate("/dashboard");
Expand All @@ -97,7 +98,7 @@ export const RefreshMyStampsModalContent = ({
}
};

const handleFetchCredential = async (platformID: PLATFORM_ID, providerIDs: PROVIDER_ID[]): Promise<void> => {
const handleFetchCredential = async (providerIDs: PROVIDER_ID[]): Promise<void> => {
try {
// This array will contain all providers that new validated VCs
let vcs: Stamp[] = [];
Expand All @@ -106,7 +107,7 @@ export const RefreshMyStampsModalContent = ({
const verified: VerifiableCredentialRecord = await fetchVerifiableCredential(
iamUrl,
{
type: platformID,
type: "EVMBulkVerify",
types: selectedProviders,
version: "0.0.0",
address: address || "",
Expand Down Expand Up @@ -209,7 +210,7 @@ export const RefreshMyStampsModalContent = ({
onClick={() => {
handleRefreshSelectedStamps();
}}
disabled={!canSubmit}
disabled={!canSubmit || isLoading}
>
<span className="flex">Confirm Stamps {isLoading && <Spinner size="sm" className="my-auto ml-2" />}</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion app/components/RefreshMyStampsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function RefreshMyStampsSelector({
setSwitchState,
}: RefreshMyStampsSelectorProps) {
const [checkboxesState, setCheckboxesState] = useState<{ checked: boolean; provider: PROVIDER_ID }[]>();
const [checkboxProviders, setCheckboxProviders] = useState<PROVIDER_ID[]>();
const [checkboxProviders, setCheckboxProviders] = useState<PROVIDER_ID[]>([]);
const slicedProviders = switchState.providers.slice(0, switchState.providers.length);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions iam/src/utils/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const getChallenge = (payload: RequestPayload): ChallengePayload => {
return `I commit that this wallet is under my control and that I wish to link it with my Passport.\n\nnonce: ${nonce}`;
case "Signer":
return `I commit that I wish to register all ETH stamps associated with an Ethereum account that I control to my Passport.\n\naccount: ${payload.signer.address}\nnonce: ${nonce}`;
case "EVMBulkVerify":
return `I commit that I wish to verify all the selected EVM stamps associated with my Passport.\n\nnonce: ${nonce}`;
default:
return `I commit that this stamp is my unique and only ${provider} verification for Passport.\n\nnonce: ${nonce}`;
}
Expand Down

0 comments on commit d72a1bd

Please sign in to comment.