Skip to content

Commit

Permalink
Return result from linkIdentities
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Aug 5, 2024
1 parent 4c10828 commit 9dc093e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ import type {
SubmitProofOfUniquePersonhoodResponse,
Achievement,
PayForDiamondMembershipResponse,
LinkIdentitiesResponse,
} from "openchat-shared";
import {
AuthProvider,
Expand Down Expand Up @@ -7356,8 +7357,8 @@ export class OpenChat extends OpenChatAgentWorker {
initiatorDelegation: DelegationChain,
approverKey: ECDSAKeyIdentity,
approverDelegation: DelegationChain,
) {
this.sendRequest({
): Promise<LinkIdentitiesResponse> {
return this.sendRequest({
kind: "linkIdentities",
initiatorKey: initiatorKey.getKeyPair(),
initiatorDelegation: initiatorDelegation.toJSON(),
Expand Down
2 changes: 2 additions & 0 deletions frontend/openchat-shared/src/domain/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ export type ApproveIdentityLinkResponse =
| "link_request_not_found"
| "invalid_signature"
| "delegation_too_old";

export type LinkIdentitiesResponse = InitiateIdentityLinkResponse | ApproveIdentityLinkResponse;
3 changes: 3 additions & 0 deletions frontend/openchat-shared/src/domain/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import type {
GenerateChallengeResponse,
GetDelegationResponse,
GetOpenChatIdentityResponse,
LinkIdentitiesResponse,
PrepareDelegationResponse,
SiwePrepareLoginResponse,
SiwsPrepareLoginResponse,
Expand Down Expand Up @@ -2104,4 +2105,6 @@ export type WorkerResult<T> = T extends Init
? void
: T extends SubmitProofOfUniquePersonhood
? SubmitProofOfUniquePersonhoodResponse
: T extends LinkIdentities
? LinkIdentitiesResponse
: never;
8 changes: 5 additions & 3 deletions frontend/openchat-worker/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
type GetOpenChatIdentityResponse,
type ChallengeAttempt,
type CreateOpenChatIdentityError,
type LinkIdentitiesResponse,
} from "openchat-shared";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -1813,7 +1814,7 @@ async function linkIdentities(
initiatorDelegation: JsonnableDelegationChain,
approverKey: CryptoKeyPair,
approverDelegation: JsonnableDelegationChain,
) {
): Promise<LinkIdentitiesResponse> {
const initiatorIdentity = DelegationIdentity.fromDelegation(
await ECDSAKeyIdentity.fromKeyPair(initiatorKey),
DelegationChain.fromJSON(initiatorDelegation),
Expand All @@ -1833,7 +1834,8 @@ async function linkIdentities(
}

const initiateResponse = await initiatorAgent.initiateIdentityLink(approver);
if (initiateResponse === "success") {
await approverAgent.approveIdentityLink(initiator);
if (initiateResponse !== "success") {
return initiateResponse;
}
return await approverAgent.approveIdentityLink(initiator);
}

0 comments on commit 9dc093e

Please sign in to comment.