-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(passport): account mask address
- Loading branch information
Showing
21 changed files
with
625 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { json } from '@remix-run/cloudflare' | ||
import type { ActionFunction } from '@remix-run/cloudflare' | ||
|
||
import { EmailAccountType, NodeType } from '@proofzero/types/account' | ||
import { type AccountURN, AccountURNSpace } from '@proofzero/urns/account' | ||
import { generateHashedIDRef } from '@proofzero/urns/idref' | ||
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors' | ||
|
||
import { getCoreClient } from '~/platform.server' | ||
import { getValidatedSessionContext } from '~/session.server' | ||
import { BadRequestError } from '@proofzero/errors' | ||
|
||
export const action: ActionFunction = getRollupReqFunctionErrorWrapper( | ||
async ({ request, context }) => { | ||
const { jwt } = await getValidatedSessionContext( | ||
request, | ||
context.authzQueryParams, | ||
context.env, | ||
context.traceSpan | ||
) | ||
|
||
const { accountURN, clientId } = await request.json<{ | ||
accountURN: AccountURN | ||
clientId: string | ||
}>() | ||
|
||
if (typeof accountURN !== 'string') | ||
throw new BadRequestError({ message: 'missing account urn' }) | ||
|
||
const coreClient = getCoreClient({ context, jwt, accountURN }) | ||
const address = await coreClient.account.getMaskedAddress.query({ | ||
clientId, | ||
}) | ||
const qc = { | ||
alias: address, | ||
source: accountURN, | ||
} | ||
const rc = { node_type: NodeType.Email, addr_type: EmailAccountType.Mask } | ||
|
||
const maskedAccountURN = AccountURNSpace.componentizedUrn( | ||
generateHashedIDRef(EmailAccountType.Mask, address), | ||
rc, | ||
qc | ||
) | ||
|
||
const maskedAccountCoreClient = getCoreClient({ | ||
context, | ||
jwt, | ||
accountURN: maskedAccountURN, | ||
}) | ||
|
||
await maskedAccountCoreClient.account.resolveIdentity.query({ jwt }) | ||
await maskedAccountCoreClient.account.setSourceAccount.mutate(accountURN) | ||
|
||
return json({ | ||
baseUrn: AccountURNSpace.getBaseURN(maskedAccountURN), | ||
qc, | ||
rc, | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.