34 lines
1004 B
TypeScript
34 lines
1004 B
TypeScript
// import * as openpgp from '../../assets/js/openpgp.min.js';
|
|
const openpgp = require('../../assets/js/openpgp.min.js');
|
|
|
|
export function UnsafeKeyStore(): void {
|
|
this.key = undefined;
|
|
}
|
|
|
|
UnsafeKeyStore.prototype.set = async function(privateKeyArmored): Promise<void> {
|
|
this.key = (await openpgp.key.readArmored(privateKeyArmored)).keys[0];
|
|
console.log('set pgp key', this.key.getKeyId().toHex());
|
|
};
|
|
|
|
UnsafeKeyStore.prototype.fingerprint = function(): any {
|
|
return this.key.keyPacket.fingerprint;
|
|
};
|
|
|
|
UnsafeKeyStore.prototype.keyId = function(): any {
|
|
return this.key.getKeyId();
|
|
};
|
|
|
|
UnsafeKeyStore.prototype.sign = async function(plainText): Promise<any> {
|
|
if (!this.key.isDecrypted()) {
|
|
const password = window.prompt('password');
|
|
await this.key.decrypt(password);
|
|
}
|
|
const opts = {
|
|
message: openpgp.message.fromText(plainText),
|
|
privateKeys: [this.key],
|
|
detached: true,
|
|
};
|
|
const signatureObject = await openpgp.sign(opts);
|
|
return signatureObject.signature;
|
|
};
|