Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove proofOfOwnership from unathorizedRequest #269

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading