UNPKG

thingy-crypto-node

Version:

The thingy-crypto-node is the keeper of an ed25519 keypair, implementing all basic crypto functionality for this specific keypair

45 lines (35 loc) 1.23 kB
// Generated by CoffeeScript 2.7.0 //########################################################### var defaultContext; import * as secUtl from "secret-manager-crypto-utils"; //########################################################### defaultContext = "standard ThingyCryptoNode"; //########################################################### export var ThingyCryptoNode = class ThingyCryptoNode { constructor(o) { this.key = o.secretKeyHex; this.id = o.publicKeyHex; this.ctx = o.context; if (this.ctx == null) { this.ctx = defaultContext; } } //####################################################### async sign(content) { return (await secUtl.createSignatureHex(content, this.key)); } async verify(sig, content) { return (await secUtl.verifyHex(sig, this.id, content)); } async encrypt(content) { return (await secUtl.asymmetricEncryptHex(content, this.id)); } async decrypt(secretsObj) { return (await secUtl.asymmetricDecryptHex(secretsObj, this.key)); } async diffieHellmanFor(id, salt, timestamp) { var context; context = `${salt}:${this.ctx}_${timestamp}`; return (await secUtl.diffieHellmanSecretHashHex(this.key, id, context)); } };