-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
2 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,58 @@ | ||
import type { | ||
Request, | ||
ResponseObject, | ||
ResponseToolkit, | ||
ServerRoute, | ||
} from '@hapi/hapi'; | ||
import type { IEncryptedMessage } from '@kiltprotocol/sdk-js'; | ||
import type { HexString } from '@polkadot/util/types'; | ||
|
||
import { z } from 'zod'; | ||
|
||
import { encryptMessageBody } from '../utilities/encryptMessage'; | ||
import { paths } from '../endpoints/paths'; | ||
import { getSession } from '../utilities/sessionStorage'; | ||
|
||
const zodPayload = z.object({ | ||
rootHash: z | ||
.string() | ||
.trim() | ||
.refine((input: string): input is HexString => input.startsWith('0x')), | ||
}); | ||
|
||
export type Input = z.infer<typeof zodPayload>; | ||
|
||
export type Output = IEncryptedMessage; | ||
|
||
async function handler( | ||
request: Request<{ Payload: Input }>, | ||
h: ResponseToolkit, | ||
): Promise<ResponseObject> { | ||
const { logger } = request; | ||
logger.debug('Reject attestation started'); | ||
|
||
const { rootHash } = request.payload; | ||
const session = getSession(request.headers); | ||
const { encryptionKeyUri } = session; | ||
|
||
logger.debug('Reject attestation rootHash found'); | ||
|
||
const output = await encryptMessageBody(encryptionKeyUri, { | ||
content: rootHash, | ||
type: 'reject-attestation', | ||
}); | ||
|
||
logger.debug('Reject attestation completed'); | ||
return h.response(output as Output); | ||
} | ||
|
||
export const rejectAttestation = { | ||
method: 'POST', | ||
path: paths.verifier.rejectAttestation, | ||
handler, | ||
options: { | ||
validate: { | ||
payload: async (payload) => zodPayload.parse(payload), | ||
}, | ||
}, | ||
} as ServerRoute; |
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,14 @@ | ||
import ky from 'ky'; | ||
|
||
import { paths } from '../endpoints/paths'; | ||
import { sessionHeader } from '../endpoints/sessionHeader'; | ||
|
||
import { Input, Output } from './rejectAttestation'; | ||
|
||
export async function rejectAttestation( | ||
json: Input, | ||
sessionId: string, | ||
): Promise<Output> { | ||
const headers = { [sessionHeader]: sessionId }; | ||
return ky.post(paths.verifier.rejectAttestation, { json, headers }).json(); | ||
} |
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