Add privatri wco
This commit is contained in:
@@ -58,4 +58,53 @@ apx.crypto.decryptMessage = async (encryptedMessage, privateKey) => {
|
||||
);
|
||||
};
|
||||
|
||||
apx.crypto.sign = async (message, privateKey) => {
|
||||
privateKey = await openpgp.readPrivateKey(
|
||||
{
|
||||
armoredKey: privateKey
|
||||
}
|
||||
);
|
||||
|
||||
return await openpgp.sign(
|
||||
{
|
||||
message: await openpgp.createMessage(
|
||||
{
|
||||
text: message
|
||||
}
|
||||
),
|
||||
signingKeys: privateKey
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
apx.crypto.verifySignature = async (message, signature, publicKey) => {
|
||||
publicKey = await openpgp.readKey(
|
||||
{
|
||||
armoredKey: publicKey
|
||||
}
|
||||
);
|
||||
|
||||
const verified = await openpgp.verify(
|
||||
{
|
||||
message: await openpgp.createMessage(
|
||||
{
|
||||
text: message
|
||||
}
|
||||
),
|
||||
signature: await openpgp.readSignature(
|
||||
{
|
||||
armoredSignature: signature
|
||||
}
|
||||
),
|
||||
verificationKeys: publicKey
|
||||
}
|
||||
);
|
||||
|
||||
if (await verified.signatures[0].verified) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
export default apx;
|
Reference in New Issue
Block a user