Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ node_modules

/encrypt_data.json
/venv/
/nodejs/types
3 changes: 3 additions & 0 deletions nodejs/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ decrypt-dh.js
encrypt.js
encrypt-dh.js
test.js
types/*
!types/ece.d.ts
tsconfig.json
29 changes: 29 additions & 0 deletions nodejs/ece.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ const SHA_256_LENGTH = 32;
const MODE_ENCRYPT = 'encrypt';
const MODE_DECRYPT = 'decrypt';

/**
* @typedef {Object} Params
* @property {('aes128gcm'|'aesgcm')=} version
* @property {(number|string)=} rs
* @property {(string|Buffer)=} salt
* @property {(string|Buffer)=} keyid
* @property {(string|Buffer)=} key
* @property {crypto.ECDH=} privateKey
* @property {Object<string, Buffer>=} keymap
* @property {string=} keylabel
* @property {(string|Buffer)=} dh
* @property {(string|Buffer)=} authSecret
* @property {(number|string)=} pad Only used when encrypting.
*/

/**
* @typedef {(keyid: (string|Buffer)) => Buffer} KeyLookupCallback
*/

let keylog;
if (process.env.ECE_KEYLOG === '1') {
keylog = function(m, k) {
Expand Down Expand Up @@ -358,6 +377,11 @@ function decryptRecord(key, counter, buffer, header, last) {
* |params.dh| needs to be provided with the public key of the sender.
*
* The |params.privateKey| includes the private key of the receiver.
*
* @param {Buffer} buffer
* @param {Params} params
* @param {KeyLookupCallback=} keyLookupCallback
* @return {Buffer}
*/
function decrypt(buffer, params, keyLookupCallback) {
const header = parseParams(params);
Expand Down Expand Up @@ -451,6 +475,11 @@ function writeHeader(header) {
* For Diffie-Hellman (WebPush), |params.dh| includes the public key of the
* receiver. |params.privateKey| is used to establish a shared secret. Key
* pairs can be created using |crypto.createECDH()|.
*
* @param {Buffer} buffer
* @param {Params} params
* @param {KeyLookupCallback=} keyLookupCallback
* @return {Buffer}
*/
function encrypt(buffer, params, keyLookupCallback) {
if (!Buffer.isBuffer(buffer)) {
Expand Down
Loading
Loading