src/app/_pgp/pgp-key-store.ts
KeyStore
clearKeysInKeyring |
clearKeysInKeyring()
|
Defined in src/app/_pgp/pgp-key-store.ts:33
|
Returns :
void
|
getEncryptKeys |
getEncryptKeys()
|
Defined in src/app/_pgp/pgp-key-store.ts:17
|
Returns :
Array<any>
|
getFingerprint |
getFingerprint()
|
Defined in src/app/_pgp/pgp-key-store.ts:22
|
Returns :
string
|
getKeyId | ||||||
getKeyId(key: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:23
|
||||||
Parameters :
Returns :
string
|
getKeysForId | ||||||
getKeysForId(keyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:25
|
||||||
Parameters :
Returns :
Array<any>
|
getPrivateKey |
getPrivateKey()
|
Defined in src/app/_pgp/pgp-key-store.ts:19
|
Returns :
any
|
getPrivateKeyForId | ||||||
getPrivateKeyForId(keyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:27
|
||||||
Parameters :
Returns :
any
|
getPrivateKeyId |
getPrivateKeyId()
|
Defined in src/app/_pgp/pgp-key-store.ts:24
|
Returns :
string
|
getPrivateKeys |
getPrivateKeys()
|
Defined in src/app/_pgp/pgp-key-store.ts:18
|
Returns :
Array<any>
|
getPublicKeyForId | ||||||
getPublicKeyForId(keyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:26
|
||||||
Parameters :
Returns :
any
|
getPublicKeyForSubkeyId | ||||||
getPublicKeyForSubkeyId(subkeyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:28
|
||||||
Parameters :
Returns :
any
|
getPublicKeys |
getPublicKeys()
|
Defined in src/app/_pgp/pgp-key-store.ts:14
|
Returns :
Array<any>
|
getPublicKeysForAddress | ||||||
getPublicKeysForAddress(address: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:29
|
||||||
Parameters :
Returns :
Array<any>
|
getTrustedActiveKeys |
getTrustedActiveKeys()
|
Defined in src/app/_pgp/pgp-key-store.ts:16
|
Returns :
Array<any>
|
getTrustedKeys |
getTrustedKeys()
|
Defined in src/app/_pgp/pgp-key-store.ts:15
|
Returns :
Array<any>
|
importKeyPair |
importKeyPair(publicKey: any, privateKey: any)
|
Defined in src/app/_pgp/pgp-key-store.ts:11
|
Returns :
Promise<void>
|
importPrivateKey | ||||||
importPrivateKey(privateKey: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:13
|
||||||
Parameters :
Returns :
Promise<void>
|
importPublicKey | ||||||
importPublicKey(publicKey: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:12
|
||||||
Parameters :
Returns :
void
|
isEncryptedPrivateKey | ||||||
isEncryptedPrivateKey(privateKey: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:21
|
||||||
Parameters :
Returns :
Promise<boolean>
|
isValidKey | ||||||
isValidKey(key: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:20
|
||||||
Parameters :
Returns :
Promise<boolean>
|
loadKeyring |
loadKeyring()
|
Defined in src/app/_pgp/pgp-key-store.ts:10
|
Returns :
void
|
removeKeysForId | ||||||
removeKeysForId(keyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:30
|
||||||
Parameters :
Returns :
Array<any>
|
removePublicKey | ||||||
removePublicKey(publicKey: any)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:32
|
||||||
Parameters :
Returns :
any
|
removePublicKeyForId | ||||||
removePublicKeyForId(keyId: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:31
|
||||||
Parameters :
Returns :
any
|
sign | ||||||
sign(plainText: string)
|
||||||
Defined in src/app/_pgp/pgp-key-store.ts:34
|
||||||
Parameters :
Returns :
Promise<any>
|
import { KeyStore } from 'cic-client-meta';
// TODO should we put this on the mutable key store object
import * as openpgp from 'openpgp';
const keyring = new openpgp.Keyring();
/**
* @extends
*/
interface MutableKeyStore extends KeyStore {
loadKeyring(): void;
importKeyPair(publicKey: any, privateKey: any): Promise<void>;
importPublicKey(publicKey: any): void;
importPrivateKey(privateKey: any): Promise<void>;
getPublicKeys(): Array<any>;
getTrustedKeys(): Array<any>;
getTrustedActiveKeys(): Array<any>;
getEncryptKeys(): Array<any>;
getPrivateKeys(): Array<any>;
getPrivateKey(): any;
isValidKey(key: any): Promise<boolean>;
isEncryptedPrivateKey(privateKey: any): Promise<boolean>;
getFingerprint(): string;
getKeyId(key: any): string;
getPrivateKeyId(): string;
getKeysForId(keyId: string): Array<any>;
getPublicKeyForId(keyId: string): any;
getPrivateKeyForId(keyId: string): any;
getPublicKeyForSubkeyId(subkeyId: string): any;
getPublicKeysForAddress(address: string): Array<any>;
removeKeysForId(keyId: string): Array<any>;
removePublicKeyForId(keyId: string): any;
removePublicKey(publicKey: any): any;
clearKeysInKeyring(): void;
sign(plainText: string): Promise<any>;
}
class MutablePgpKeyStore implements MutableKeyStore {
async loadKeyring(): Promise<void> {
await keyring.load();
await keyring.store();
}
async importKeyPair(publicKey: any, privateKey: any): Promise<void> {
await keyring.publicKeys.importKey(publicKey);
await keyring.privateKeys.importKey(privateKey);
}
importPublicKey(publicKey: any): void {
keyring.publicKeys.importKey(publicKey);
}
async importPrivateKey(privateKey: any): Promise<void> {
await keyring.privateKeys.importKey(privateKey);
}
getPublicKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getTrustedKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getTrustedActiveKeys(): Array<any> {
return keyring.publicKeys.keys;
}
getEncryptKeys(): Array<any> {
return [];
}
getPrivateKeys(): Array<any> {
return keyring.privateKeys.keys;
}
getPrivateKey(): any {
return keyring.privateKeys && keyring.privateKeys.keys[0];
}
async isValidKey(key): Promise<boolean> {
// There is supposed to be an openpgp.readKey() method but I can't find it?
const testKey = await openpgp.key.readArmored(key);
return !testKey.err;
}
async isEncryptedPrivateKey(privateKey: any): Promise<boolean> {
const imported = await openpgp.key.readArmored(privateKey);
for (const key of imported.keys) {
if (key.isDecrypted()) {
return false;
}
}
return true;
}
getFingerprint(): string {
// TODO Handle multiple keys
return (
keyring.privateKeys &&
keyring.privateKeys.keys[0] &&
keyring.privateKeys.keys[0].keyPacket &&
keyring.privateKeys.keys[0].keyPacket.fingerprint
);
}
getKeyId(key: any): string {
return key.getKeyId().toHex();
}
getPrivateKeyId(): string {
// TODO is there a library that comes with angular for doing this?
return (
keyring.privateKeys &&
keyring.privateKeys.keys[0] &&
keyring.privateKeys.keys[0].getKeyId().toHex()
);
}
getKeysForId(keyId: string): Array<any> {
return keyring.getKeysForId(keyId);
}
getPublicKeyForId(keyId): any {
return keyring.publicKeys.getForId(keyId);
}
getPrivateKeyForId(keyId): any {
return keyring.privateKeys.getForId(keyId);
}
getPublicKeyForSubkeyId(subkeyId): any {
return keyring.publicKeys.getForId(subkeyId, true);
}
getPublicKeysForAddress(address): Array<any> {
return keyring.publicKeys.getForAddress(address);
}
removeKeysForId(keyId): Array<any> {
return keyring.removeKeysForId(keyId);
}
removePublicKeyForId(keyId): any {
return keyring.publicKeys.removeForId(keyId);
}
removePublicKey(publicKey: any): any {
const keyId = publicKey.getKeyId().toHex();
return keyring.publicKeys.removeForId(keyId);
}
clearKeysInKeyring(): void {
keyring.clear();
}
async sign(plainText): Promise<any> {
const privateKey = this.getPrivateKey();
if (!privateKey.isDecrypted()) {
const password = window.prompt('password');
await privateKey.decrypt(password);
}
const opts = {
message: openpgp.message.fromText(plainText),
privateKeys: [privateKey],
detached: true,
};
const signatureObject = await openpgp.sign(opts);
return signatureObject.signature;
}
}
export { MutablePgpKeyStore, MutableKeyStore };