Add documentation to pgp module.

This commit is contained in:
Spencer Ofwiti
2021-05-12 13:21:18 +03:00
parent 948a735baf
commit 948554563d
27 changed files with 3154 additions and 744 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -64,6 +64,13 @@
<code>src/app/_pgp/pgp-signer.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Signable object interface </p>
</p>
<section>
@@ -115,14 +122,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="7"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:7</a></div>
<div class="io-line">Defined in <a href="" data-line="11"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:11</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The message to be signed. </p>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
@@ -138,56 +147,113 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as openpgp from &#x27;openpgp&#x27;;
// Application imports
import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
import { LoggingService } from &#x27;@app/_services/logging.service&#x27;;
const openpgp &#x3D; require(&#x27;openpgp&#x27;);
/** Signable object interface */
interface Signable {
/** The message to be signed. */
digest(): string;
}
/** 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;
}
/** 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;
/**
* 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&lt;void&gt;;
}
/** Provides functionality for signing and verifying signed messages. */
class PGPSigner implements Signer {
/** Encryption engine used. */
engine &#x3D; &#x27;pgp&#x27;;
/** Encryption algorithm used */
algo &#x3D; &#x27;sha256&#x27;;
/** Message digest */
dgst: string;
/** Generated signature */
signature: Signature;
/** A keystore holding pgp keys. */
keyStore: MutableKeyStore;
/** Event triggered on successful signing of message. */
onsign: (signature: Signature) &#x3D;&gt; void;
/** Event triggered on successful verification of a signature. */
onverify: (flag: boolean) &#x3D;&gt; void;
/** A service that provides logging capabilities. */
loggingService: LoggingService;
/**
* Initializing the Signer.
* @param keyStore - A keystore holding pgp keys.
*/
constructor(keyStore: MutableKeyStore) {
this.keyStore &#x3D; keyStore;
this.onsign &#x3D; (signature: Signature) &#x3D;&gt; {};
this.onverify &#x3D; (flag: boolean) &#x3D;&gt; {};
}
/**
* Get the private key fingerprint.
* @returns A private key fingerprint.
*/
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
/**
* Load the message digest.
* @param material - A signable object.
* @returns true - If digest has been loaded successfully.
*/
public prepare(material: Signable): boolean {
this.dgst &#x3D; material.digest();
return true;
}
/**
* Verify that signature is valid.
* @param digest - The message that was signed.
* @param signature - The generated signature.
*/
public verify(digest: string, signature: Signature): void {
openpgp.signature
.readArmored(signature.data)
@@ -220,6 +286,11 @@ class PGPSigner implements Signer {
});
}
/**
* Signs a message using a private key.
* @async
* @param digest - The message to be signed.
*/
public async sign(digest: string): Promise&lt;void&gt; {
const m &#x3D; openpgp.cleartext.fromText(digest);
const pk &#x3D; this.keyStore.getPrivateKey();
@@ -251,6 +322,7 @@ class PGPSigner implements Signer {
}
}
/** @exports */
export { Signable, Signature, Signer, PGPSigner };
</code></pre>
</div>

View File

@@ -61,9 +61,16 @@
<h3>File</h3>
</p>
<p class="comment">
<code>src/app/_pgp/pgp-signer.ts</code>
<code>src/app/_models/account.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Meta signature interface </p>
</p>
<section>
@@ -128,6 +135,12 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Algorithm used </p>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
@@ -157,6 +170,12 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Data that was signed. </p>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
@@ -186,6 +205,12 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Message digest </p>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
@@ -215,6 +240,12 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Encryption engine used. </p>
</div>
</td>
</tr>
</tbody>
</table>
</section>
@@ -222,120 +253,149 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
import { LoggingService } from &#x27;@app/_services/logging.service&#x27;;
const openpgp &#x3D; require(&#x27;openpgp&#x27;);
interface Signable {
digest(): string;
}
interface Signature {
engine: string;
algo: string;
data: string;
digest: string;
}
interface Signer {
onsign(signature: Signature): void;
onverify(flag: boolean): void;
fingerprint(): string;
prepare(material: Signable): boolean;
verify(digest: string, signature: Signature): void;
sign(digest: string): Promise&lt;void&gt;;
}
class PGPSigner implements Signer {
engine &#x3D; &#x27;pgp&#x27;;
algo &#x3D; &#x27;sha256&#x27;;
dgst: string;
signature: Signature;
keyStore: MutableKeyStore;
onsign: (signature: Signature) &#x3D;&gt; void;
onverify: (flag: boolean) &#x3D;&gt; void;
loggingService: LoggingService;
constructor(keyStore: MutableKeyStore) {
this.keyStore &#x3D; keyStore;
this.onsign &#x3D; (signature: Signature) &#x3D;&gt; {};
this.onverify &#x3D; (flag: boolean) &#x3D;&gt; {};
}
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
public prepare(material: Signable): boolean {
this.dgst &#x3D; material.digest();
return true;
}
public verify(digest: string, signature: Signature): void {
openpgp.signature
.readArmored(signature.data)
.then((sig) &#x3D;&gt; {
const opts &#x3D; {
message: openpgp.cleartext.fromText(digest),
publicKeys: this.keyStore.getTrustedKeys(),
signature: sig,
};
openpgp.verify(opts).then((v) &#x3D;&gt; {
let i &#x3D; 0;
for (i &#x3D; 0; i &lt; v.signatures.length; i++) {
const s &#x3D; v.signatures[i];
if (s.valid) {
this.onverify(s);
return;
}
}
this.loggingService.sendErrorLevelMessage(
&#x60;Checked ${i} signature(s) but none valid&#x60;,
this,
{ error: &#x27;404 Not found!&#x27; }
);
this.onverify(false);
});
})
.catch((e) &#x3D;&gt; {
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
this.onverify(false);
});
}
public async sign(digest: string): Promise&lt;void&gt; {
const m &#x3D; openpgp.cleartext.fromText(digest);
const pk &#x3D; this.keyStore.getPrivateKey();
if (!pk.isDecrypted()) {
const password &#x3D; window.prompt(&#x27;password&#x27;);
await pk.decrypt(password);
}
const opts &#x3D; {
message: m,
privateKeys: [pk],
detached: true,
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">interface AccountDetails {
/** Account registration day */
date_registered: number;
/** User&#x27;s gender */
gender: string;
/** Age of user */
age?: string;
/** Type of account */
type?: string;
/** Token balance on account */
balance?: number;
/** Account identifiers */
identities: {
evm: {
&#x27;bloxberg:8996&#x27;: string[];
&#x27;oldchain:1&#x27;: string[];
};
openpgp
.sign(opts)
.then((s) &#x3D;&gt; {
this.signature &#x3D; {
engine: this.engine,
algo: this.algo,
data: s.signature,
// TODO: fix for browser later
digest,
latitude: number;
longitude: number;
};
/** User&#x27;s location */
location: {
area?: string;
area_name: string;
area_type?: string;
};
/** Products or services provided by user. */
products: string[];
/** Business category of user. */
category?: string;
/** Personal identifying information of user */
vcard: {
email: [
{
value: string;
}
];
fn: [
{
value: string;
}
];
n: [
{
value: string[];
}
];
tel: [
{
meta: {
TYP: string[];
};
this.onsign(this.signature);
})
.catch((e) &#x3D;&gt; {
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
this.onsign(undefined);
});
}
value: string;
}
];
version: [
{
value: string;
}
];
};
}
export { Signable, Signature, Signer, PGPSigner };
/** Meta signature interface */
interface Signature {
/** Algorithm used */
algo: string;
/** Data that was signed. */
data: string;
/** Message digest */
digest: string;
/** Encryption engine used. */
engine: string;
}
/** Meta object interface */
interface Meta {
/** Account details */
data: AccountDetails;
/** Meta store id */
id: string;
/** Signature used during write. */
signature: Signature;
}
/** Meta response interface */
interface MetaResponse {
/** Meta store id */
id: string;
/** Meta object */
m: Meta;
}
/** Default account data object */
const defaultAccount: AccountDetails &#x3D; {
date_registered: Date.now(),
gender: &#x27;other&#x27;,
identities: {
evm: {
&#x27;bloxberg:8996&#x27;: [&#x27;&#x27;],
&#x27;oldchain:1&#x27;: [&#x27;&#x27;],
},
latitude: 0,
longitude: 0,
},
location: {
area_name: &#x27;Kilifi&#x27;,
},
products: [],
vcard: {
email: [
{
value: &#x27;&#x27;,
},
],
fn: [
{
value: &#x27;Sarafu Contract&#x27;,
},
],
n: [
{
value: [&#x27;Sarafu&#x27;, &#x27;Contract&#x27;],
},
],
tel: [
{
meta: {
TYP: [],
},
value: &#x27;&#x27;,
},
],
version: [
{
value: &#x27;3.0&#x27;,
},
],
},
};
/** @exports */
export { AccountDetails, Meta, MetaResponse, Signature, defaultAccount };
</code></pre>
</div>
</div>

View File

@@ -61,14 +61,14 @@
<h3>File</h3>
</p>
<p class="comment">
<code>src/app/_models/account.ts</code>
<code>src/app/_pgp/pgp-signer.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Meta signature interface </p>
<p>Signature object interface </p>
</p>
@@ -137,7 +137,7 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Algorithm used </p>
<div class="io-description"><p>Encryption algorithm used </p>
</div>
</td>
</tr>
@@ -172,7 +172,7 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Data that was signed. </p>
<div class="io-description"><p>Data to be signed. </p>
</div>
</td>
</tr>
@@ -253,149 +253,183 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">interface AccountDetails {
/** Account registration day */
date_registered: number;
/** User&#x27;s gender */
gender: string;
/** Age of user */
age?: string;
/** Type of account */
type?: string;
/** Token balance on account */
balance?: number;
/** Account identifiers */
identities: {
evm: {
&#x27;bloxberg:8996&#x27;: string[];
&#x27;oldchain:1&#x27;: string[];
};
latitude: number;
longitude: number;
};
/** User&#x27;s location */
location: {
area?: string;
area_name: string;
area_type?: string;
};
/** Products or services provided by user. */
products: string[];
/** Business category of user. */
category?: string;
/** Personal identifying information of user */
vcard: {
email: [
{
value: string;
}
];
fn: [
{
value: string;
}
];
n: [
{
value: string[];
}
];
tel: [
{
meta: {
TYP: string[];
};
value: string;
}
];
version: [
{
value: string;
}
];
};
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as openpgp from &#x27;openpgp&#x27;;
// Application imports
import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
import { LoggingService } from &#x27;@app/_services/logging.service&#x27;;
/** Signable object interface */
interface Signable {
/** The message to be signed. */
digest(): string;
}
/** Meta signature interface */
/** Signature object interface */
interface Signature {
/** Algorithm used */
/** Encryption engine used. */
engine: string;
/** Encryption algorithm used */
algo: string;
/** Data that was signed. */
/** Data to be signed. */
data: string;
/** Message digest */
digest: 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;
/**
* 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&lt;void&gt;;
}
/** Provides functionality for signing and verifying signed messages. */
class PGPSigner implements Signer {
/** Encryption engine used. */
engine: string;
}
/** Meta object interface */
interface Meta {
/** Account details */
data: AccountDetails;
/** Meta store id */
id: string;
/** Signature used during write. */
engine &#x3D; &#x27;pgp&#x27;;
/** Encryption algorithm used */
algo &#x3D; &#x27;sha256&#x27;;
/** Message digest */
dgst: string;
/** Generated signature */
signature: Signature;
}
/** A keystore holding pgp keys. */
keyStore: MutableKeyStore;
/** Event triggered on successful signing of message. */
onsign: (signature: Signature) &#x3D;&gt; void;
/** Event triggered on successful verification of a signature. */
onverify: (flag: boolean) &#x3D;&gt; void;
/** A service that provides logging capabilities. */
loggingService: LoggingService;
/** Meta response interface */
interface MetaResponse {
/** Meta store id */
id: string;
/** Meta object */
m: Meta;
}
/**
* Initializing the Signer.
* @param keyStore - A keystore holding pgp keys.
*/
constructor(keyStore: MutableKeyStore) {
this.keyStore &#x3D; keyStore;
this.onsign &#x3D; (signature: Signature) &#x3D;&gt; {};
this.onverify &#x3D; (flag: boolean) &#x3D;&gt; {};
}
/** Default account data object */
const defaultAccount: AccountDetails &#x3D; {
date_registered: Date.now(),
gender: &#x27;other&#x27;,
identities: {
evm: {
&#x27;bloxberg:8996&#x27;: [&#x27;&#x27;],
&#x27;oldchain:1&#x27;: [&#x27;&#x27;],
},
latitude: 0,
longitude: 0,
},
location: {
area_name: &#x27;Kilifi&#x27;,
},
products: [],
vcard: {
email: [
{
value: &#x27;&#x27;,
},
],
fn: [
{
value: &#x27;Sarafu Contract&#x27;,
},
],
n: [
{
value: [&#x27;Sarafu&#x27;, &#x27;Contract&#x27;],
},
],
tel: [
{
meta: {
TYP: [],
},
value: &#x27;&#x27;,
},
],
version: [
{
value: &#x27;3.0&#x27;,
},
],
},
};
/**
* Get the private key fingerprint.
* @returns A private key fingerprint.
*/
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
/**
* Load the message digest.
* @param material - A signable object.
* @returns true - If digest has been loaded successfully.
*/
public prepare(material: Signable): boolean {
this.dgst &#x3D; material.digest();
return true;
}
/**
* Verify that signature is valid.
* @param digest - The message that was signed.
* @param signature - The generated signature.
*/
public verify(digest: string, signature: Signature): void {
openpgp.signature
.readArmored(signature.data)
.then((sig) &#x3D;&gt; {
const opts &#x3D; {
message: openpgp.cleartext.fromText(digest),
publicKeys: this.keyStore.getTrustedKeys(),
signature: sig,
};
openpgp.verify(opts).then((v) &#x3D;&gt; {
let i &#x3D; 0;
for (i &#x3D; 0; i &lt; v.signatures.length; i++) {
const s &#x3D; v.signatures[i];
if (s.valid) {
this.onverify(s);
return;
}
}
this.loggingService.sendErrorLevelMessage(
&#x60;Checked ${i} signature(s) but none valid&#x60;,
this,
{ error: &#x27;404 Not found!&#x27; }
);
this.onverify(false);
});
})
.catch((e) &#x3D;&gt; {
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
this.onverify(false);
});
}
/**
* Signs a message using a private key.
* @async
* @param digest - The message to be signed.
*/
public async sign(digest: string): Promise&lt;void&gt; {
const m &#x3D; openpgp.cleartext.fromText(digest);
const pk &#x3D; this.keyStore.getPrivateKey();
if (!pk.isDecrypted()) {
const password &#x3D; window.prompt(&#x27;password&#x27;);
await pk.decrypt(password);
}
const opts &#x3D; {
message: m,
privateKeys: [pk],
detached: true,
};
openpgp
.sign(opts)
.then((s) &#x3D;&gt; {
this.signature &#x3D; {
engine: this.engine,
algo: this.algo,
data: s.signature,
// TODO: fix for browser later
digest,
};
this.onsign(this.signature);
})
.catch((e) &#x3D;&gt; {
this.loggingService.sendErrorLevelMessage(e.message, this, { error: e });
this.onsign(undefined);
});
}
}
/** @exports */
export { AccountDetails, Meta, MetaResponse, Signature, defaultAccount };
export { Signable, Signature, Signer, PGPSigner };
</code></pre>
</div>
</div>

View File

@@ -64,6 +64,13 @@
<code>src/app/_pgp/pgp-signer.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Signer interface </p>
</p>
<section>
@@ -130,19 +137,27 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="20"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:20</a></div>
<div class="io-line">Defined in <a href="" data-line="36"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:36</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Get the private key fingerprint.</p>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</div>
<div class="io-description">
<p>A private key fingerprint.</p>
</div>
</td>
</tr>
</tbody>
@@ -169,14 +184,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="18"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:18</a></div>
<div class="io-line">Defined in <a href="" data-line="29"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:29</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Event triggered on successful signing of message. </p>
</div>
<div class="io-description">
<b>Parameters :</b>
@@ -239,14 +256,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="19"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:19</a></div>
<div class="io-line">Defined in <a href="" data-line="31"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:31</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Event triggered on successful verification of a signature. </p>
</div>
<div class="io-description">
<b>Parameters :</b>
@@ -309,14 +328,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="21"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:21</a></div>
<div class="io-line">Defined in <a href="" data-line="42"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:42</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Load the message digest.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@@ -326,6 +347,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@@ -340,6 +362,12 @@
</td>
<td>
<ul>
<li>A signable object.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@@ -351,7 +379,8 @@
</div>
<div class="io-description">
<p>true - If digest has been loaded successfully.</p>
</div>
</td>
</tr>
@@ -379,14 +408,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="23"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:23</a></div>
<div class="io-line">Defined in <a href="" data-line="54"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:54</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Signs a message using a private key.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@@ -396,6 +427,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@@ -410,6 +442,12 @@
</td>
<td>
<ul>
<li>The message to be signed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@@ -449,14 +487,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="22"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:22</a></div>
<div class="io-line">Defined in <a href="" data-line="48"
class="link-to-prism">src/app/_pgp/pgp-signer.ts:48</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Verify that signature is valid.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@@ -466,6 +506,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@@ -480,6 +521,12 @@
</td>
<td>
<ul>
<li>The message that was signed.</li>
</ul>
</td>
</tr>
<tr>
<td>signature</td>
@@ -492,6 +539,12 @@
</td>
<td>
<ul>
<li>The generated signature.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@@ -515,56 +568,113 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as openpgp from &#x27;openpgp&#x27;;
// Application imports
import { MutableKeyStore } from &#x27;@app/_pgp/pgp-key-store&#x27;;
import { LoggingService } from &#x27;@app/_services/logging.service&#x27;;
const openpgp &#x3D; require(&#x27;openpgp&#x27;);
/** Signable object interface */
interface Signable {
/** The message to be signed. */
digest(): string;
}
/** 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;
}
/** 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;
/**
* 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&lt;void&gt;;
}
/** Provides functionality for signing and verifying signed messages. */
class PGPSigner implements Signer {
/** Encryption engine used. */
engine &#x3D; &#x27;pgp&#x27;;
/** Encryption algorithm used */
algo &#x3D; &#x27;sha256&#x27;;
/** Message digest */
dgst: string;
/** Generated signature */
signature: Signature;
/** A keystore holding pgp keys. */
keyStore: MutableKeyStore;
/** Event triggered on successful signing of message. */
onsign: (signature: Signature) &#x3D;&gt; void;
/** Event triggered on successful verification of a signature. */
onverify: (flag: boolean) &#x3D;&gt; void;
/** A service that provides logging capabilities. */
loggingService: LoggingService;
/**
* Initializing the Signer.
* @param keyStore - A keystore holding pgp keys.
*/
constructor(keyStore: MutableKeyStore) {
this.keyStore &#x3D; keyStore;
this.onsign &#x3D; (signature: Signature) &#x3D;&gt; {};
this.onverify &#x3D; (flag: boolean) &#x3D;&gt; {};
}
/**
* Get the private key fingerprint.
* @returns A private key fingerprint.
*/
public fingerprint(): string {
return this.keyStore.getFingerprint();
}
/**
* Load the message digest.
* @param material - A signable object.
* @returns true - If digest has been loaded successfully.
*/
public prepare(material: Signable): boolean {
this.dgst &#x3D; material.digest();
return true;
}
/**
* Verify that signature is valid.
* @param digest - The message that was signed.
* @param signature - The generated signature.
*/
public verify(digest: string, signature: Signature): void {
openpgp.signature
.readArmored(signature.data)
@@ -597,6 +707,11 @@ class PGPSigner implements Signer {
});
}
/**
* Signs a message using a private key.
* @async
* @param digest - The message to be signed.
*/
public async sign(digest: string): Promise&lt;void&gt; {
const m &#x3D; openpgp.cleartext.fromText(digest);
const pk &#x3D; this.keyStore.getPrivateKey();
@@ -628,6 +743,7 @@ class PGPSigner implements Signer {
}
}
/** @exports */
export { Signable, Signature, Signer, PGPSigner };
</code></pre>
</div>