+// User password checks
+
+function comparePassword (plainPassword: string, hashPassword: string) {
+ return bcryptComparePromise(plainPassword, hashPassword)
+}
+
+async function cryptPassword (password: string) {
+ const salt = await bcryptGenSaltPromise(BCRYPT_SALT_SIZE)
+
+ return bcryptHashPromise(password, salt)
+}
+
+// HTTP Signature
+
+function isHTTPSignatureDigestValid (rawBody: Buffer, req: Request): boolean {
+ if (req.headers[HTTP_SIGNATURE.HEADER_NAME] && req.headers['digest']) {
+ return buildDigest(rawBody.toString()) === req.headers['digest']
+ }
+
+ return true
+}
+
+function isHTTPSignatureVerified (httpSignatureParsed: any, actor: ActorModel): boolean {
+ return httpSignature.verifySignature(httpSignatureParsed, actor.publicKey) === true
+}
+
+function parseHTTPSignature (req: Request, clockSkew?: number) {
+ return httpSignature.parse(req, { authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, clockSkew })
+}
+
+// JSONLD
+
+async function isJsonLDSignatureVerified (fromActor: ActorModel, signedDocument: any): Promise<boolean> {
+ if (signedDocument.signature.type === 'RsaSignature2017') {
+ // Mastodon algorithm
+ const res = await isJsonLDRSA2017Verified(fromActor, signedDocument)
+ // Success? If no, try with our library
+ if (res === true) return true
+ }
+