Refactor order of item to follow alphabetical order.
This commit is contained in:
@@ -161,65 +161,65 @@ interface Signable {
|
||||
|
||||
/** Signature object interface */
|
||||
interface Signature {
|
||||
/** Encryption engine used. */
|
||||
engine: string;
|
||||
/** Encryption algorithm used */
|
||||
algo: string;
|
||||
/** Data to be signed. */
|
||||
data: string;
|
||||
/** Message digest */
|
||||
digest: string;
|
||||
/** Encryption engine used. */
|
||||
engine: string;
|
||||
}
|
||||
|
||||
/** Signer interface */
|
||||
interface Signer {
|
||||
/** Event triggered on successful signing of message. */
|
||||
onsign(signature: Signature): void;
|
||||
/** Event triggered on successful verification of a signature. */
|
||||
onverify(flag: boolean): void;
|
||||
/**
|
||||
* Get the private key fingerprint.
|
||||
* @returns A private key fingerprint.
|
||||
*/
|
||||
fingerprint(): string;
|
||||
/** Event triggered on successful signing of message. */
|
||||
onsign(signature: Signature): void;
|
||||
/** Event triggered on successful verification of a signature. */
|
||||
onverify(flag: boolean): void;
|
||||
/**
|
||||
* Load the message digest.
|
||||
* @param material - A signable object.
|
||||
* @returns true - If digest has been loaded successfully.
|
||||
*/
|
||||
prepare(material: Signable): boolean;
|
||||
/**
|
||||
* Verify that signature is valid.
|
||||
* @param digest - The message that was signed.
|
||||
* @param signature - The generated signature.
|
||||
*/
|
||||
verify(digest: string, signature: Signature): void;
|
||||
/**
|
||||
* Signs a message using a private key.
|
||||
* @async
|
||||
* @param digest - The message to be signed.
|
||||
*/
|
||||
sign(digest: string): Promise<void>;
|
||||
/**
|
||||
* Verify that signature is valid.
|
||||
* @param digest - The message that was signed.
|
||||
* @param signature - The generated signature.
|
||||
*/
|
||||
verify(digest: string, signature: Signature): void;
|
||||
}
|
||||
|
||||
/** Provides functionality for signing and verifying signed messages. */
|
||||
class PGPSigner implements Signer {
|
||||
/** Encryption engine used. */
|
||||
engine = 'pgp';
|
||||
/** Encryption algorithm used */
|
||||
algo = 'sha256';
|
||||
/** Message digest */
|
||||
dgst: string;
|
||||
/** Generated signature */
|
||||
signature: Signature;
|
||||
/** Encryption engine used. */
|
||||
engine = 'pgp';
|
||||
/** A keystore holding pgp keys. */
|
||||
keyStore: MutableKeyStore;
|
||||
/** A service that provides logging capabilities. */
|
||||
loggingService: LoggingService;
|
||||
/** Event triggered on successful signing of message. */
|
||||
onsign: (signature: Signature) => void;
|
||||
/** Event triggered on successful verification of a signature. */
|
||||
onverify: (flag: boolean) => void;
|
||||
/** A service that provides logging capabilities. */
|
||||
loggingService: LoggingService;
|
||||
/** Generated signature */
|
||||
signature: Signature;
|
||||
|
||||
/**
|
||||
* Initializing the Signer.
|
||||
@@ -249,6 +249,41 @@ class PGPSigner implements Signer {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs a message using a private key.
|
||||
* @async
|
||||
* @param digest - The message to be signed.
|
||||
*/
|
||||
public async sign(digest: string): Promise<void> {
|
||||
const m = openpgp.cleartext.fromText(digest);
|
||||
const pk = this.keyStore.getPrivateKey();
|
||||
if (!pk.isDecrypted()) {
|
||||
const password = window.prompt('password');
|
||||
await pk.decrypt(password);
|
||||
}
|
||||
const opts = {
|
||||
message: m,
|
||||
privateKeys: [pk],
|
||||
detached: true,
|
||||
};
|
||||
openpgp
|
||||
.sign(opts)
|
||||
.then((s) => {
|
||||
this.signature = {
|
||||
engine: this.engine,
|
||||
algo: this.algo,
|
||||
data: s.signature,
|
||||
// TODO: fix for browser later
|
||||
digest,
|
||||
};
|
||||
this.onsign(this.signature);
|
||||
})
|
||||
.catch((e) => {
|
||||
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
|
||||
this.onsign(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that signature is valid.
|
||||
* @param digest - The message that was signed.
|
||||
@@ -285,45 +320,10 @@ class PGPSigner implements Signer {
|
||||
this.onverify(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs a message using a private key.
|
||||
* @async
|
||||
* @param digest - The message to be signed.
|
||||
*/
|
||||
public async sign(digest: string): Promise<void> {
|
||||
const m = openpgp.cleartext.fromText(digest);
|
||||
const pk = this.keyStore.getPrivateKey();
|
||||
if (!pk.isDecrypted()) {
|
||||
const password = window.prompt('password');
|
||||
await pk.decrypt(password);
|
||||
}
|
||||
const opts = {
|
||||
message: m,
|
||||
privateKeys: [pk],
|
||||
detached: true,
|
||||
};
|
||||
openpgp
|
||||
.sign(opts)
|
||||
.then((s) => {
|
||||
this.signature = {
|
||||
engine: this.engine,
|
||||
algo: this.algo,
|
||||
data: s.signature,
|
||||
// TODO: fix for browser later
|
||||
digest,
|
||||
};
|
||||
this.onsign(this.signature);
|
||||
})
|
||||
.catch((e) => {
|
||||
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
|
||||
this.onsign(undefined);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** @exports */
|
||||
export { Signable, Signature, Signer, PGPSigner };
|
||||
export { PGPSigner, Signable, Signature, Signer };
|
||||
</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user