Module @pcd/passport-interface

@pcd/passport-interface

License NPM version Downloads Docs

This package contains code that defines the API of the passport server and client, and enables developers (both us, and third party developers) to communicate with those two applications. For example, this package contains code that enables you to construct a URL that requests a particular PCD from the passport webapp.

🛠 Install

Install the @pcd/passport-interface package with npm:

npm i @pcd/passport-interface

or yarn:

yarn add @pcd/passport-interface

📜 Usage

The communication between users and passport webapp is mostly via a popup, which redirects to the webapp according to the URL and its search parameters in the same popup. Once the webapp generates the requested content, the popup automatically closes, and the resulting content can be accessed through a React hook.

sequenceDiagram
User app->>User app: constructURL(PCD)
User app->>Popup route: openPopupRoute(URL)
Popup route->>Passport popup: redirectToPassportWebapp(URL)
Passport popup->>Passport popup: getPCD(PCD)
Passport popup->>Popup route: redirectToPopupRoute(PCD)
Popup route-->>User app: return <<PCD>>

Below, it will be shown how the functions of this package can be used in such a flow.

For more detailed information about the package's functions and types, please refer to the documentation site.

Using the passport popup

You can use the usePassportPopupSetup React hook to set up necessary passport popup logic on a specific route (e.g. /popup) and communicate with the passport webapp. Basically, it redirects the user to the webapp passport or initial page based on the search parameters of the URL, leveraging cross-origin communication between windows.

import { usePassportPopupSetup } from "@pcd/passport-interface"

export default function Popup() {
const error = usePassportPopupSetup()

return <div>{error}</div>
}

Then the usePassportPopupMessages React hook can be used to process the results of the requests. It listens for incoming messages from the other browsing context (i.e. the popup) and store them in a state variable.

import { usePassportPopupMessages } from "@pcd/passport-interface";

export default function App() {
const [passportPCDString] = usePassportPopupMessages();

useEffect(() => {
console.log(passportPCDString);
}, [passportPCDString]);
}

Adding a PCD to with the passport popup

You can generate a PCD and add it to the passport with constructPassportPcdProveAndAddRequestUrl.

import { EdDSAPCDPackage } from "@pcd/eddsa-pcd"
import { constructPassportPcdProveAndAddRequestUrl, openPassportPopup } from "@pcd/passport-interface"
import { ArgumentTypeName } from "@pcd/pcd-types"

const url = constructPassportPcdProveAndAddRequestUrl<typeof EdDSAPCDPackage>(
"https://zupass.org",
window.location.origin + "/popup",
EdDSAPCDPackage.name,
{
id: {
argumentType: ArgumentTypeName.String
},
message: {
argumentType: ArgumentTypeName.StringArray,,
value: ["0x32"]
},
privateKey: {
argumentType: ArgumentTypeName.String,
userProvided: true
}
},
{ title: "EdDSA Signature Proof" }
)

openPassportPopup("/popup", url)

Or add a previously generated serialized PCD with constructPassportPcdAddRequestUrl.

import { constructPassportPcdAddRequestUrl, openPassportPopup } from "@pcd/passport-interface"

// This code could be on your server.
const pcd = await prove({
id: {
argumentType: ArgumentTypeName.String
},
message: {
argumentType: ArgumentTypeName.StringArray,,
value: ["0x32"]
},
privateKey: {
argumentType: ArgumentTypeName.String,
value: "0x42"
}
})

const serializedPCD = await serialize(pcd)

const url = constructPassportPcdAddRequestUrl(
"https://zupass.org",
window.location.origin + "/popup",
serializedPCD
)

openPassportPopup("/popup", url)

Getting a PCD with the passport popup

You can get a PCD from the passport that already exists in the user's local storage with getWithoutProvingUrl.

import { EdDSAPCDPackage } from "@pcd/eddsa-pcd";
import {
getWithoutProvingUrl,
openPassportPopup
} from "@pcd/passport-interface";

const url = getWithoutProvingUrl(
"https://zupass.org",
window.location.origin + "/popup",
EdDSAPCDPackage.name
);

openPassportPopup("/popup", url);

Or you can prove a claim and get its PCD with constructPassportPcdGetRequestUrl.

import { EdDSAPCDPackage } from "@pcd/eddsa-pcd";
import {
constructPassportPcdGetRequestUrl,
openPassportPopup
} from "@pcd/passport-interface";
import { ArgumentTypeName } from "@pcd/pcd-types";

const url = constructPassportPcdGetRequestUrl<typeof EdDSAPCDPackage>(
"https://zupass.org",
window.location.origin + "/popup",
EdDSAPCDPackage.name,
{
id: {
argumentType: ArgumentTypeName.String
},
message: {
argumentType: ArgumentTypeName.StringArray,
value: ["0x32"]
},
privateKey: {
argumentType: ArgumentTypeName.String,
userProvided: true
}
}
);

openPassportPopup("/popup", url);

Interacting with the passport webapp directly without popup

If you wish to add or get a PCD from the passport webapp without relying on a popup interface but instead managing the outcome of the request on your server, you can achieve this by specifying an alternative return URL. This return URL could be a designated endpoint on your server, responsible for processing the request and its subsequent actions.

import { EdDSAPCDPackage } from "@pcd/eddsa-pcd";
import { constructPassportPcdGetRequestUrl } from "@pcd/passport-interface";
import { ArgumentTypeName } from "@pcd/pcd-types";

const url = constructPassportPcdGetRequestUrl<typeof EdDSAPCDPackage>(
"https://zupass.org",
"https://your-server.org/verify", // This endpoint will handle the request's results.
EdDSAPCDPackage.name,
{
id: {
argumentType: ArgumentTypeName.String
},
message: {
argumentType: ArgumentTypeName.StringArray,
value: ["0x32"]
},
privateKey: {
argumentType: ArgumentTypeName.String,
userProvided: true
}
},
{
genericProveScreen: true
}
);

A real use case could be a Telegram bot that redirects users to the passport webapp to allow them to enter their private key to sign a message and create a EdDSA PCD. The return URL in this case will be an endpoint in the bot's server that adds the user to a Telegram group after verifying the PCD.

Index

Enumerations

Classes

Interfaces

AgreeTermsPayload AgreeTermsRequest AgreeToTermsResponseValue BadgeConfigUI ChangeBlobKeyRequest ChangeBlobKeyResponseValue CheckTicketByIdRequest CheckTicketInByIdRequest CheckTicketInRequest CheckTicketRequest CredentialManagerAPI CredentialPayload CredentialRequest DateRange DexFrog DownloadEncryptedStorageRequest DownloadEncryptedStorageResponseValue EdgeCityBalance Feed FrogCryptoComputedUserState FrogCryptoDbFrogData FrogCryptoDeleteFrogsResponseValue FrogCryptoScore FrogCryptoShareTelegramHandleRequest FrogCryptoShareTelegramHandleResponseValue FrogCryptoUpdateFeedsResponseValue FrogCryptoUpdateFrogsResponseValue FrogCryptoUserStateRequest FrogCryptoUserStateResponseValue FullDateRange GetContactActionInfo GetOfflineTicketsRequest GetOfflineTicketsResponseValue HostedFeed HydratedPipelineHistoryEntry IFeedApi KnownTicketType KnownTicketTypesAndKeys ListFeedsResponseValue ListSingleFeedRequest NamedAPIError OfflineDevconnectTicket OfflineTickets PCDAddRequest PCDGetRequest PCDGetWithoutProvingRequest PCDProveAndAddRequest PCDRequest PendingPCD PipelineConsumer PipelineEdDSATicketZuAuthConfig PipelineFeedInfo PipelineInfoConsumer PipelineInfoRequest PipelineInfoResponseValue PipelineLoadSummary PipelineLog PipelineSemaphoreGroupInfo PodboxTicketAction PollFeedRequest PollFeedResponseValue ProofStatusRequest ProofStatusResponseValue ProveOptions ServerProofRequest SignInMessagePayload Subscription SubscriptionActions SubscriptionFetchError SubscriptionPermissionError SubscriptionProvider SupportedPCDsResponseValue SyncedEncryptedStorageV1 SyncedEncryptedStorageV2 SyncedEncryptedStorageV3 TicketInfo UploadEncryptedStorageRequest UploadEncryptedStorageResponseValue UploadOfflineCheckinsRequest UploadOfflineCheckinsResponseValue VerifiedCredential VerifyTicketByIdRequest VerifyTicketRequest ZupassUserJson

Type Aliases

APIResult ActionConfigResponseValue ActionScreenConfig AgreeTermsResult AlertsOptions AnonTopicDataPayload AnonWebAppPayload AutoIssuanceOptions Badge BadgeConfig BadgesConfig BasePipelineDefinition BasePipelineOptions CSVPipelineDefinition CSVPipelineOptions ChangeBlobKeyError ChangeBlobKeyResult CheckTicketByIdResponseValue CheckTicketByIdResult CheckTicketInByIdError CheckTicketInByIdResponseValue CheckTicketInByIdResult CheckTicketInError CheckTicketInResponseValue CheckTicketReponseValue CheckinActionInfo ConfirmEmailRequest ConfirmEmailResponseValue ConfirmEmailResult ContactsConfig CreateNewUserRequest Credential CredentialCache DeviceLoginRequest DownloadAndDecryptResult DownloadAndDecryptUpdateResult EdgeCityBalancesResult EncryptedStorageResult FeedIssuanceOptions FrogCryptoClientFeed FrogCryptoDbFeedData FrogCryptoDeleteFrogsRequest FrogCryptoDeleteFrogsResult FrogCryptoFeed FrogCryptoFeedBiomeConfigs FrogCryptoFrogData FrogCryptoGetScoreboardResult FrogCryptoShareTelegramHandleResult FrogCryptoUpdateFeedsRequest FrogCryptoUpdateFeedsResult FrogCryptoUpdateFrogsRequest FrogCryptoUpdateFrogsResult FrogCryptoUserStateResult GenericIssuanceDeletePipelineRequest GenericIssuanceDeletePipelineResponse GenericIssuanceDeletePipelineResponseValue GenericIssuanceFetchPretixEventsRequest GenericIssuanceFetchPretixEventsResponse GenericIssuanceFetchPretixEventsResponseValue GenericIssuanceFetchPretixProductsRequest GenericIssuanceFetchPretixProductsResponse GenericIssuanceFetchPretixProductsResponseValue GenericIssuanceGetAllUserPipelinesRequest GenericIssuanceGetAllUserPipelinesResponse GenericIssuanceGetAllUserPipelinesResponseValue GenericIssuanceGetPipelineRequest GenericIssuanceGetPipelineResponse GenericIssuanceGetPipelineResponseValue GenericIssuanceHistoricalSemaphoreGroupResponse GenericIssuanceHistoricalSemaphoreGroupResponseValue GenericIssuancePipelineListEntry GenericIssuancePipelineSemaphoreGroupsResponseValue GenericIssuanceSelf GenericIssuanceSelfRequest GenericIssuanceSelfResponseValue GenericIssuanceSelfResult GenericIssuanceSemaphoreGroupResponse GenericIssuanceSemaphoreGroupResponseValue GenericIssuanceSemaphoreGroupRootResponse GenericIssuanceSemaphoreGroupRootResponseValue GenericIssuanceSendEmailResponseValue GenericIssuanceUpsertPipelineRequest GenericIssuanceUpsertPipelineResponse GenericIssuanceUpsertPipelineResponseValue GenericIssuanceValidSemaphoreGroupResponse GenericIssuanceValidSemaphoreGroupResponseValue GenericPretixAnswer GenericPretixCheckin GenericPretixCheckinList GenericPretixEvent GenericPretixEventSettings GenericPretixI18nMap GenericPretixOrder GenericPretixPosition GenericPretixProduct GenericPretixProductCategory GetError GetResultValue GiveBadgeActionInfo ImageOptions InfoResult IssuanceEnabledResponseValue IssuanceServiceEnabledResult KnownPublicKey KnownTicketTypesRequest KnownTicketTypesResponseValue KnownTicketTypesResult LemonadePipelineDefinition LemonadePipelineEventConfig LemonadePipelineOptions LemonadePipelineTicketTypeConfig ListFeedsRequest ListFeedsResult LoadUserError LoginResult ManualTicket MemberCriteria NewUserResult NullifierHashPayload OfflineTicketsCheckinResult OfflineTicketsResult OneClickLoginRequest OneClickLoginResponseValue OptionalStorageWithRevision PasswordSaltResponse PipelineDefinition PipelineHistoryEntry PipelineZuAuthConfig PodboxTicketActionError PodboxTicketActionPreCheckRequest PodboxTicketActionPreCheckResult PodboxTicketActionRequest PodboxTicketActionResponseValue PodboxTicketActionResult PollFeedResult PopupActionResult PopupMessageResult PretixEventConfig PretixPipelineDefinition PretixPipelineOptions PretixProductConfig PretixSyncStatusResponseValue PretixSyncStatusResult ProveOnServerResult RateLimitedBadge ReactDataPayload RedirectTopicDataPayload RequestUserResult ResultMapper SaltRequest SaltResponseValue SemaphoreGroupConfig SemaphoreGroupResult SemaphoreValidRootResponseValue SerializedSubscriptionManager ServerEdDSAPublicKeyResult ServerProofStatusResult ServerRSAPublicKeyResult StorageWithRevision SubscriptionError SyncedEncryptedStorage TicketActions TicketError UploadEncryptedStorageResult User UserPermissionsOptions UserResponseValue VerifyTicketByIdResponseValue VerifyTicketByIdResult VerifyTicketResponseValue VerifyTicketResult VerifyTokenRequest VerifyTokenResponseValue VerifyTokenResult ZuconnectTicketType

Variables

ActionScreenConfigSchema AutoIssuanceOptionsSchema BADGES_EDGE_CITY BadgeConfigSchema BadgesConfigSchema CONTACT_EVENT_NAME ContactsConfigSchema EDGE_CITY_7_DAY_PRODUCT_IDS EDGE_CITY_EARLY_BIRD_PRODUCT_ID EDGE_CITY_EVENT_ID EDGE_CITY_GA_PRODUCT_ID EDGE_CITY_ORGANIZER_PRODUCT_ID ERROR_NAME_BAD_RESPONSE ERROR_NAME_UNKNOWN ETH_LATAM_2024_EVENT_ID EdgeCityFolderName FROG_FREEROLLS FROG_SCORE_CAP FrogCryptoDbFeedDataSchema FrogCryptoFeedBiomeConfigSchema FrogCryptoFeedBiomeConfigsSchema FrogCryptoFolderName FrogCryptoFrogDataSchema GenericPretixCheckinListSchema GenericPretixEventSchema GenericPretixEventSettingsSchema GenericPretixI18MapSchema GenericPretixOrderSchema GenericPretixProductCategorySchema GenericPretixProductSchema IFrogCryptoClientFeedSchema IFrogCryptoFeedSchema ISSUANCE_STRING LATEST_PRIVACY_NOTICE LEMONADE_EDDSA_PUBKEY MIN_PRIVACY_NOTICE MemberCriteriaSchema PODBOX_CREDENTIAL_REQUEST POST PipelineDefinitionSchema TOKEN_LONG_NAME TOTAL_SUPPLY UNREDACT_TICKETS_TERMS_VERSION UserPermissionsOptionsSchema VITALIA_ATTENDEE_PRODUCT_ID VITALIA_EVENT_ID VITALIA_PUBLIC_KEY ZUCONNECT_23_DAY_PASS_EVENT_ID ZUCONNECT_23_DAY_PASS_PRODUCT_ID ZUCONNECT_23_FIRST_WEEK_EVENT_ID ZUCONNECT_23_FIRST_WEEK_PRODUCT_ID ZUCONNECT_23_ORGANIZER_EVENT_ID ZUCONNECT_23_ORGANIZER_PRODUCT_ID ZUCONNECT_23_RESIDENT_EVENT_ID ZUCONNECT_23_RESIDENT_PRODUCT_ID ZUCONNECT_23_SCHOLARSHIP_EVENT_ID ZUCONNECT_23_SCHOLARSHIP_PRODUCT_ID ZUCONNECT_PRODUCT_ID_MAPPINGS ZUCONNECT_TICKET_NAMES ZUPASS_CREDENTIAL_REQUEST ZUZALU_23_EVENT_ID ZUZALU_23_ORGANIZER_PRODUCT_ID ZUZALU_23_RESIDENT_PRODUCT_ID ZUZALU_23_VISITOR_PRODUCT_ID zupassDefaultSubscriptions

Functions

agreeTerms apiErrorReasonFromCode applyActions constructZupassPcdAddRequestUrl constructZupassPcdGetRequestUrl constructZupassPcdProveAndAddRequestUrl createCredentialCache createCredentialPayload createStorageBackedCredentialCache defaultOfflineTickets deserializeStorage getError getI18nString getNamedAPIErrorMessage getStorageHash getWithoutProvingUrl hashProveRequest httpDelete httpDeleteSimple httpGet httpGetSimple httpPost httpPostSimple httpPut httpPutSimple isCSVPipelineDefinition isLemonadePipelineDefinition isPerDayBadge isPretixPipelineDefinition isSettledPendingPCDStatus isSyncedEncryptedStorageV1 isSyncedEncryptedStorageV2 isSyncedEncryptedStorageV3 mapStringError onNamedAPIError openGroupMembershipPopup openSemaphoreSignaturePopup openSignedZuzaluSignInPopup openSignedZuzaluUUIDPopup openZupassPopup openZupassPopupUrl postPendingPCDMessage postSerializedPCDMessage receiveZupassPopupMessage requestAgreeTerms requestChangeBlobKey requestCheckInById requestCheckTicketById requestConfirmationEmail requestCreateNewUser requestDownloadAndDecryptStorage requestDownloadAndDecryptUpdatedStorage requestEdgeCityBalances requestEncryptedStorage requestFrogCryptoDeleteFrogs requestFrogCryptoGetScoreboard requestFrogCryptoGetUserState requestFrogCryptoUpdateFeeds requestFrogCryptoUpdateFrogs requestFrogCryptoUpdateTelegramHandleSharing requestGenericIssuanceDeletePipeline requestGenericIssuanceFetchPretixEvents requestGenericIssuanceFetchPretixProducts requestGenericIssuanceGetAllUserPipelines requestGenericIssuanceGetPipeline requestGenericIssuanceHistoricalSemaphoreGroup requestGenericIssuanceSelf requestGenericIssuanceSemaphoreGroup requestGenericIssuanceSemaphoreGroupRoot requestGenericIssuanceUpsertPipeline requestGenericIssuanceValidSemaphoreGroup requestIssuanceServiceEnabled requestKnownTicketTypes requestListFeeds requestLogToServer requestOfflineTickets requestOfflineTicketsCheckin requestOneClickLogin requestPasswordSalt requestPipelineInfo requestPodboxTicketAction requestPodboxTicketActionPreCheck requestPollFeed requestPretixSyncStatus requestProveOnServer requestSemaphoreGroup requestServerEdDSAPublicKey requestServerProofStatus requestServerRSAPublicKey requestUploadEncryptedStorage requestUser requestVerifyTicket requestVerifyTicketById requestVerifyToken serializeStorage useFetchUser usePCDMultiplexer usePendingPCD useSemaphoreGroupProof useSemaphoreSignatureProof useSerializedPCD useZupassPopupMessages useZupassPopupSetup verifyCredential zupassPopupExecute zupassPopupSetup

Generated using TypeDoc