diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 16:27:34 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 21:55:16 +0200 |
commit | e7fa87bcc0052e1e99c6894e7e27a122374956b3 (patch) | |
tree | 56c243d08ae357533ebdb4fbf41211aa0fc914ce /src/crypto | |
parent | 08bd3dc0e8a3c2370e4e8abbaa241eaafc144f4c (diff) |
documentation and tslint settings to check for docs
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/cryptoWorker.ts | 25 | ||||
-rw-r--r-- | src/crypto/emscInterface.ts | 4 | ||||
-rw-r--r-- | src/crypto/nodeWorker.ts | 23 |
3 files changed, 49 insertions, 3 deletions
diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts index 9541b7442..1a337446d 100644 --- a/src/crypto/cryptoWorker.ts +++ b/src/crypto/cryptoWorker.ts @@ -108,6 +108,10 @@ namespace RpcFunctions { return preCoin; } + + /** + * Create and sign a message to request payback for a coin. + */ export function createPaybackRequest(coin: CoinRecord): PaybackRequest { const p = new native.PaybackRequestPS({ coin_blind: native.RsaBlindingKeySecret.fromCrock(coin.blindingKey), @@ -127,6 +131,9 @@ namespace RpcFunctions { } + /** + * Check if a payment signature is valid. + */ export function isValidPaymentSignature(sig: string, contractHash: string, merchantPub: string): boolean { const p = new native.PaymentSignaturePS({ contract_hash: native.HashCode.fromCrock(contractHash), @@ -140,6 +147,9 @@ namespace RpcFunctions { nativePub); } + /** + * Check if a wire fee is correctly signed. + */ export function isValidWireFee(type: string, wf: WireFee, masterPub: string): boolean { const p = new native.MasterWireFeePS({ closing_fee: (new native.Amount(wf.closingFee)).toNbo(), @@ -160,6 +170,9 @@ namespace RpcFunctions { } + /** + * Check if the signature of a denomination is valid. + */ export function isValidDenom(denom: DenominationRecord, masterPub: string): boolean { const p = new native.DenominationKeyValidityPS({ @@ -189,6 +202,9 @@ namespace RpcFunctions { } + /** + * Create a new EdDSA key pair. + */ export function createEddsaKeypair(): {priv: string, pub: string} { const priv = native.EddsaPrivateKey.create(); const pub = priv.getPublicKey(); @@ -196,6 +212,9 @@ namespace RpcFunctions { } + /** + * Unblind a blindly signed value. + */ export function rsaUnblind(sig: string, bk: string, pk: string): string { const denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig), native.RsaBlindingKeySecret.fromCrock(bk), @@ -278,6 +297,9 @@ namespace RpcFunctions { } + /** + * Create a new refresh session. + */ export function createRefreshSession(exchangeBaseUrl: string, kappa: number, meltCoin: CoinRecord, @@ -398,6 +420,9 @@ namespace RpcFunctions { return b.hash().toCrock(); } + /** + * Hash a denomination public key. + */ export function hashDenomPub(denomPub: string): string { return native.RsaPublicKey.fromCrock(denomPub).encode().hash().toCrock(); } diff --git a/src/crypto/emscInterface.ts b/src/crypto/emscInterface.ts index e00e67a84..f3aeb8272 100644 --- a/src/crypto/emscInterface.ts +++ b/src/crypto/emscInterface.ts @@ -259,7 +259,7 @@ interface Arena { * Arena that must be manually destroyed. */ class SimpleArena implements Arena { - heap: ArenaObject[]; + protected heap: ArenaObject[]; constructor() { this.heap = []; @@ -774,7 +774,7 @@ export class EccSignaturePurpose extends PackedArenaObject { return this.payloadSize + 8; } - payloadSize: number; + private payloadSize: number; constructor(purpose: SignaturePurpose, payload: PackedArenaObject, diff --git a/src/crypto/nodeWorker.ts b/src/crypto/nodeWorker.ts index 4352b66c2..fa942387a 100644 --- a/src/crypto/nodeWorker.ts +++ b/src/crypto/nodeWorker.ts @@ -22,10 +22,22 @@ const fork = require("child_process").fork; const nodeWorkerEntry = path.join(__dirname, "nodeWorkerEntry.js"); +/** + * Worker implementation that uses node subprocesses. + */ export class Worker { - child: any; + private child: any; + + /** + * Function to be called when we receive a message from the worker thread. + */ onmessage: undefined | ((m: any) => void); + + /** + * Function to be called when we receive an error from the worker thread. + */ onerror: undefined | ((m: any) => void); + constructor(scriptFilename: string) { this.child = fork(nodeWorkerEntry); this.onerror = undefined; @@ -55,6 +67,9 @@ export class Worker { this.child.send({scriptFilename, cwd: process.cwd()}); } + /** + * Add an event listener for either an "error" or "message" event. + */ addEventListener(event: "message" | "error", fn: (x: any) => void): void { switch (event) { case "message": @@ -66,10 +81,16 @@ export class Worker { } } + /** + * Send a message to the worker thread. + */ postMessage (msg: any) { this.child.send(JSON.stringify({data: msg})); } + /** + * Forcibly terminate the worker thread. + */ terminate () { this.child.kill("SIGINT"); } |