Skip to content

Commit

Permalink
use @types/pull-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdinosaur committed Dec 13, 2023
1 parent 4aba445 commit 48fb23f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions js/pull-secret-channel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ module.exports = {

/**
@typedef {Buffer | Uint8Array} B4A
@typedef {null | true | Error} End
@typedef {(end: End, cb: (end: End, data?: any) => void) => void} Source
@typedef {import('pull-stream').Source<B4A>} Source
@typedef {import('pull-stream').Through<B4A, B4A>} Through
@typedef {import('pull-stream').EndOrError} EndOrError
@typedef {{
queue: (buf: B4A | null) => void
emit: (event: 'data' | 'end' | 'error', data?: any) => void
Expand All @@ -33,6 +34,7 @@ module.exports = {
/**
* @param {B4A} key
* @param {B4A} nonce
* @returns {Through}
*/
function pullEncrypter(key, nonce) {
const encrypter = createEncrypter(key, nonce)
Expand Down Expand Up @@ -76,23 +78,25 @@ function pullEncrypter(key, nonce) {
/**
* @param {B4A} key
* @param {B4A} nonce
* @returns {Through}
*/
function pullDecrypter(key, nonce) {
const decrypter = createDecrypter(key, nonce)

/** @type {End} */
/** @type {EndOrError} */
let ending = null
const reader = pullReader()

/**
* @param {Source} read
* @returns {Source}
*/
return function pullDecrypterThrough(read) {
reader(read)

/**
* @param {End} end
* @param {(end: End, data?: B4A) => void} cb
* @param {EndOrError} end
* @param {(end: EndOrError, data?: B4A) => void} cb
*/
return function pullDecrypterSource(end, cb) {
if (end) return reader.abort(end, cb)
Expand All @@ -102,7 +106,7 @@ function pullDecrypter(key, nonce) {
LENGTH_OR_END_CIPHERTEXT,

/**
* @param {End} err
* @param {EndOrError} err
* @param {B4A} lengthOrEndCiphertext
*/
function (err, lengthOrEndCiphertext) {
Expand Down Expand Up @@ -135,7 +139,7 @@ function pullDecrypter(key, nonce) {
reader.read(
length + TAG_SIZE,
/**
* @param {End} err
* @param {EndOrError} err
* @param {B4A} contentCiphertext
*/
function (err, contentCiphertext) {
Expand All @@ -162,7 +166,7 @@ function pullDecrypter(key, nonce) {
// use abort when the input was invalid,
// but the source hasn't actually ended yet.
/**
* @param {End} err
* @param {EndOrError} err
*/
function abort(err) {
ending = err || true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/b4a": "^1.6.4",
"@types/debug": "^4.1.12",
"@types/node": "^20.10.0",
"@types/pull-stream": "^3.6.7",
"prettier": "^3.1.0",
"typescript": "^5.3.2"
}
Expand Down

0 comments on commit 48fb23f

Please sign in to comment.