-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (32 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const crypto = require("@arkecosystem/crypto");
exports.default = (message) => {
let valid;
try {
const array = message.split("\n");
const signatureIndex =
array.lastIndexOf("-----END COMPENDIA SIGNED MESSAGE-----") - 1;
const publicKeyIndex = signatureIndex - 1;
const messageIndexStart =
array.indexOf("-----BEGIN COMPENDIA SIGNED MESSAGE-----") + 1;
const messageIndexEnd = array.lastIndexOf("-----BEGIN SIGNATURE-----");
if (
signatureIndex > -1 &&
publicKeyIndex > -1 &&
messageIndexStart > -1 &&
messageIndexEnd > -1
) {
const sliced = array.slice(messageIndexStart, messageIndexEnd);
const message = sliced.join("\n");
const signature = array[signatureIndex];
const publicKey = array[publicKeyIndex];
const signedObj = { message, publicKey, signature };
valid = crypto.Crypto.Message.verify(signedObj);
return { valid, data: signedObj }
} else {
valid = false;
}
} catch (e) {
valid = false;
}
return { valid };
};