---
# System prepended metadata

title: Untitled

---

```
* @param token
* @param payload
* @callback done on successful validation is called with encoded {did, verifiedRoles} object
*/
async function validate(
 token: string,
 payload: ITokenPayload,
 done: (err?: Error, user?: unknown, info?: unknown) => void
): Promise<void> {
 if (this.isTokenPayload(payload) && isLegacyEnabled) {
  // ...some code to get userDoc (the user DID Document)...
  const proofVerifier = new ProofVerifier(userDoc);
  const userDid = await proofVerifier.verifyAuthenticationProof(token);
 }
 else if (this.isSIWEPayload(payload)) {
  const siweMessage = new SiweMessage(payload);
  await siweMessage.verify(token);
 }
 else {
   Logger.info('Token payload is not valid');
   return done(undefined, null, 'Token payload is not valid');
 }
 ```