]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/peertube-crypto.ts
Added translation using Weblate (Hebrew)
[github/Chocobozzz/PeerTube.git] / server / helpers / peertube-crypto.ts
index 89c0ab1515b24d962dca7ddbe21b47100733e3d6..1655cd7b57bd9e4033a0aaf3b9130425c3ea385a 100644 (file)
@@ -5,9 +5,8 @@ import { jsonld } from './custom-jsonld-signature'
 import { logger } from './logger'
 import { cloneDeep } from 'lodash'
 import { createSign, createVerify } from 'crypto'
-import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils'
 import * as bcrypt from 'bcrypt'
-import { MActor } from '../typings/models'
+import { MActor } from '../types/models'
 
 const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare)
 const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt)
@@ -104,12 +103,19 @@ async function signJsonLDObject (byActor: MActor, data: any) {
   return Object.assign(data, { signature })
 }
 
+function buildDigest (body: any) {
+  const rawBody = typeof body === 'string' ? body : JSON.stringify(body)
+
+  return 'SHA-256=' + sha256(rawBody, 'base64')
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   isHTTPSignatureDigestValid,
   parseHTTPSignature,
   isHTTPSignatureVerified,
+  buildDigest,
   isJsonLDSignatureVerified,
   comparePassword,
   createPrivateAndPublicKeys,