Skip to content

Commit

Permalink
fix: remove proofOfOwnership from unathorizedRequest
Browse files Browse the repository at this point in the history
Proof Of Ownership can only be part of authorized request
  • Loading branch information
dawidsowardx committed Oct 22, 2024
1 parent 4b1ade9 commit 38208e7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const toWalletRequest = ({
oneTime,
}

if (!oneTime) {
if (!oneTime || dataRequestState.proofOfOwnership) {
const persona = walletData.persona

if (walletData.persona) draft.persona = persona
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const TransformRdtDataRequestToWalletRequestInput = object({
const isAuthorized = (
input: TransformRdtDataRequestToWalletRequestInput,
): boolean => {
const { persona, accounts, personaData } = input
const { persona, accounts, personaData, proofOfOwnership } = input

const isPersonaLogin = !!persona
const shouldResetData = accounts?.reset || personaData?.reset
Expand All @@ -62,8 +62,9 @@ const isAuthorized = (
shouldResetData ||
isOngoingAccountsRequest ||
isOngoingPersonaDataRequest ||
isPersonaLogin
)
isPersonaLogin ||
proofOfOwnership
)

return isAuthorizedRequest
}
Expand Down Expand Up @@ -130,7 +131,7 @@ const withProofOfOwnershipRequestItem =
const { challenge, accountAddresses, identityAddress } =
input.proofOfOwnership

if (challenge) {
if (challenge && updatedRequestItems.discriminator === 'authorizedRequest') {
updatedRequestItems['proofOfOwnership'] = {
challenge,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ const withProofs =
)
draft.proofs.push(...accountProofs)
}

if (input.proofOfOwnership) {
draft.proofs.push(
...convertOwnershipProofsToSignedChallenge(
input.proofOfOwnership.challenge,
input.proofOfOwnership.proofs,
),
)
}
}
if (input.discriminator === 'unauthorizedRequest') {
if (
Expand All @@ -168,14 +177,6 @@ const withProofs =
draft.proofs.push(...accountProofs)
}
}
if (input.proofOfOwnership) {
draft.proofs.push(
...convertOwnershipProofsToSignedChallenge(
input.proofOfOwnership.challenge,
input.proofOfOwnership.proofs,
),
)
}
})

export const transformWalletResponseToRdtWalletData = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export const WalletRequestModule = (input: {
!state.walletData.persona &&
walletDataRequest.discriminator === 'authorizedRequest'

const isProofOfOwnershipRequest = !!walletDataRequest.proofOfOwnership
const isProofOfOwnershipRequest =
walletDataRequest.discriminator === 'authorizedRequest' &&
!!walletDataRequest.proofOfOwnership

const requestType = isLoginRequest
? 'loginRequest'
Expand Down
2 changes: 0 additions & 2 deletions packages/dapp-toolkit/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export type WalletUnauthorizedRequestItems = InferOutput<
>
export const WalletUnauthorizedRequestItems = object({
discriminator: literal('unauthorizedRequest'),
proofOfOwnership: optional(ProofOfOwnershipRequestItem),
oneTimeAccounts: optional(AccountsRequestItem),
oneTimePersonaData: optional(PersonaDataRequestItem),
})
Expand Down Expand Up @@ -271,7 +270,6 @@ export type WalletUnauthorizedRequestResponseItems = InferOutput<
>
const WalletUnauthorizedRequestResponseItems = object({
discriminator: literal('unauthorizedRequest'),
proofOfOwnership: optional(ProofOfOwnershipResponseItem),
oneTimeAccounts: optional(AccountsRequestResponseItem),
oneTimePersonaData: optional(PersonaDataRequestResponseItem),
})
Expand Down

0 comments on commit 38208e7

Please sign in to comment.