+
+function hash (obj: any): Promise<any> {
+ return jsonld.promises
+ .normalize(obj, {
+ algorithm: 'URDNA2015',
+ format: 'application/n-quads'
+ })
+ .then(res => sha256(res))
+}
+
+function createSignatureHash (signature: any) {
+ const signatureCopy = cloneDeep(signature)
+ Object.assign(signatureCopy, {
+ '@context': [
+ 'https://w3id.org/security/v1',
+ { RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' }
+ ]
+ })
+
+ delete signatureCopy.type
+ delete signatureCopy.id
+ delete signatureCopy.signatureValue
+
+ return hash(signatureCopy)
+}
+
+function createDocWithoutSignatureHash (doc: any) {
+ const docWithoutSignature = cloneDeep(doc)
+ delete docWithoutSignature.signature
+
+ return hash(docWithoutSignature)
+}