Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atproto/common

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atproto/common - npm Package Compare versions

Comparing version 0.4.4 to 0.4.5

tsconfig.build.tsbuildinfo

6

CHANGELOG.md
# @atproto/common
## 0.4.5
### Patch Changes
- [#3178](https://github.com/bluesky-social/atproto/pull/3178) [`588baae12`](https://github.com/bluesky-social/atproto/commit/588baae1212a3cba3bf0d95d2f268e80513fd9c4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Minor adaptation of VerifyCidTransform
## 0.4.4

@@ -4,0 +10,0 @@

1

dist/buffers.d.ts

@@ -1,4 +0,3 @@

/// <reference types="node" />
export declare function ui8ToBuffer(bytes: Uint8Array): Buffer;
export declare function ui8ToArrayBuffer(bytes: Uint8Array): ArrayBuffer;
//# sourceMappingURL=buffers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ui8ToArrayBuffer = exports.ui8ToBuffer = void 0;
exports.ui8ToBuffer = ui8ToBuffer;
exports.ui8ToArrayBuffer = ui8ToArrayBuffer;
function ui8ToBuffer(bytes) {
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
}
exports.ui8ToBuffer = ui8ToBuffer;
function ui8ToArrayBuffer(bytes) {
return bytes.buffer.slice(bytes.byteOffset, bytes.byteLength + bytes.byteOffset);
}
exports.ui8ToArrayBuffer = ui8ToArrayBuffer;
//# sourceMappingURL=buffers.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toSimplifiedISOSafe = void 0;
exports.toSimplifiedISOSafe = toSimplifiedISOSafe;
const iso_datestring_validator_1 = require("iso-datestring-validator");

@@ -19,3 +19,2 @@ // Normalize date strings to simplified ISO so that the lexical sort preserves temporal sort.

}
exports.toSimplifiedISOSafe = toSimplifiedISOSafe;
//# sourceMappingURL=dates.js.map

@@ -1,6 +0,2 @@

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import crypto from 'crypto';
import { Transform, TransformCallback } from 'stream';
import { Transform } from 'node:stream';
import { CID } from 'multiformats/cid';

@@ -20,6 +16,3 @@ import * as Block from 'multiformats/block';

cid: CID;
hasher: crypto.Hash;
constructor(cid: CID);
_transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback): void;
_flush(cb: TransformCallback): void;
}

@@ -26,0 +19,0 @@ export declare class VerifyCidError extends Error {

@@ -25,9 +25,6 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerifyCidError = exports.VerifyCidTransform = exports.sha256RawToCid = exports.sha256ToCid = exports.verifyCidForBytes = exports.cborBytesToRecord = exports.isValidCid = exports.cidForCbor = exports.dataToCborBlock = exports.cborDecode = exports.cborEncode = void 0;
const crypto_1 = __importDefault(require("crypto"));
const stream_1 = require("stream");
const node_crypto_1 = require("node:crypto");
const node_stream_1 = require("node:stream");
const common_web_1 = require("@atproto/common-web");

@@ -90,5 +87,25 @@ const cid_1 = require("multiformats/cid");

exports.sha256RawToCid = sha256RawToCid;
class VerifyCidTransform extends stream_1.Transform {
class VerifyCidTransform extends node_stream_1.Transform {
constructor(cid) {
super();
const hasher = (0, node_crypto_1.createHash)('sha256');
super({
transform(chunk, encoding, callback) {
hasher.update(chunk);
callback(null, chunk);
},
flush(callback) {
try {
const actual = (0, exports.sha256RawToCid)(hasher.digest());
if (actual.equals(cid)) {
return callback();
}
else {
return callback(new VerifyCidError(cid, actual));
}
}
catch (err) {
return callback(asError(err));
}
},
});
Object.defineProperty(this, "cid", {

@@ -100,32 +117,6 @@ enumerable: true,

});
Object.defineProperty(this, "hasher", {
enumerable: true,
configurable: true,
writable: true,
value: crypto_1.default.createHash('sha256')
});
}
_transform(chunk, _enc, cb) {
this.hasher.update(chunk);
cb(null, chunk);
}
_flush(cb) {
try {
const cid = (0, exports.sha256RawToCid)(this.hasher.digest());
if (this.cid.equals(cid)) {
return cb();
}
else {
return cb(new VerifyCidError(this.cid, cid));
}
}
catch (_err) {
const err = _err instanceof Error
? _err
: new Error('Unexpected error', { cause: _err });
return cb(err);
}
}
}
exports.VerifyCidTransform = VerifyCidTransform;
const asError = (err) => err instanceof Error ? err : new Error('Unexpected error', { cause: err });
class VerifyCidError extends Error {

@@ -132,0 +123,0 @@ constructor(expected, actual) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.obfuscateJwt = exports.obfuscateToken = exports.obfuscateBearer = exports.obfuscateBasic = exports.obfuscateAuthHeader = exports.obfuscateHeaders = exports.obfuscateWord = exports.obfuscateEmail = void 0;
exports.obfuscateEmail = obfuscateEmail;
exports.obfuscateWord = obfuscateWord;
exports.obfuscateHeaders = obfuscateHeaders;
exports.obfuscateAuthHeader = obfuscateAuthHeader;
exports.obfuscateBasic = obfuscateBasic;
exports.obfuscateBearer = obfuscateBearer;
exports.obfuscateToken = obfuscateToken;
exports.obfuscateJwt = obfuscateJwt;
function obfuscateEmail(email) {

@@ -8,7 +15,5 @@ const [local, domain] = email.split('@');

}
exports.obfuscateEmail = obfuscateEmail;
function obfuscateWord(word) {
return `${word.charAt(0)}***${word.charAt(word.length - 1)}`;
}
exports.obfuscateWord = obfuscateWord;
function obfuscateHeaders(headers) {

@@ -29,3 +34,2 @@ const obfuscatedHeaders = {};

}
exports.obfuscateHeaders = obfuscateHeaders;
function obfuscateAuthHeader(authHeader) {

@@ -47,3 +51,2 @@ // This is a hot path (runs on every request). Avoid using split() or regex.

}
exports.obfuscateAuthHeader = obfuscateAuthHeader;
function obfuscateBasic(token) {

@@ -62,7 +65,5 @@ if (!token)

}
exports.obfuscateBasic = obfuscateBasic;
function obfuscateBearer(token) {
return obfuscateJwt(token) || obfuscateToken(token);
}
exports.obfuscateBearer = obfuscateBearer;
function obfuscateToken(token) {

@@ -73,3 +74,2 @@ if (token.length >= 12)

}
exports.obfuscateToken = obfuscateToken;
function obfuscateJwt(token) {

@@ -100,3 +100,2 @@ const firstDot = token.indexOf('.');

}
exports.obfuscateJwt = obfuscateJwt;
//# sourceMappingURL=obfuscate.js.map

@@ -1,3 +0,1 @@

/// <reference types="node" />
/// <reference types="node" />
import { Duplex, Readable, Stream, Transform, TransformCallback } from 'node:stream';

@@ -4,0 +2,0 @@ export declare const forwardStreamErrors: (...streams: Stream[]) => void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDecoders = exports.decodeStream = exports.MaxSizeChecker = exports.bytesToStream = exports.byteIterableToStream = exports.streamToNodeBuffer = exports.streamToBytes = exports.streamSize = exports.cloneStream = exports.forwardStreamErrors = void 0;
exports.MaxSizeChecker = exports.bytesToStream = exports.byteIterableToStream = exports.streamToNodeBuffer = exports.streamToBytes = exports.streamSize = exports.cloneStream = exports.forwardStreamErrors = void 0;
exports.decodeStream = decodeStream;
exports.createDecoders = createDecoders;
const node_stream_1 = require("node:stream");

@@ -100,3 +102,2 @@ const node_zlib_1 = require("node:zlib");

}
exports.decodeStream = decodeStream;
/**

@@ -127,3 +128,2 @@ * Create a series of decoding streams based on the content-encoding header. The

}
exports.createDecoders = createDecoders;
function commaSplit(header) {

@@ -130,0 +130,0 @@ return header.split(',');

{
"name": "@atproto/common",
"version": "0.4.4",
"version": "0.4.5",
"license": "MIT",

@@ -27,3 +27,3 @@ "description": "Shared web-platform-friendly code for atproto libraries",

"jest": "^28.1.2",
"typescript": "^5.3.3",
"typescript": "^5.6.3",
"uint8arrays": "3.0.0"

@@ -30,0 +30,0 @@ },

@@ -1,3 +0,3 @@

import crypto from 'crypto'
import { Transform, TransformCallback } from 'stream'
import { createHash } from 'node:crypto'
import { Transform } from 'node:stream'
import { check, schema } from '@atproto/common-web'

@@ -66,30 +66,28 @@ import { CID } from 'multiformats/cid'

export class VerifyCidTransform extends Transform {
hasher = crypto.createHash('sha256')
constructor(public cid: CID) {
super()
const hasher = createHash('sha256')
super({
transform(chunk, encoding, callback) {
hasher.update(chunk)
callback(null, chunk)
},
flush(callback) {
try {
const actual = sha256RawToCid(hasher.digest())
if (actual.equals(cid)) {
return callback()
} else {
return callback(new VerifyCidError(cid, actual))
}
} catch (err) {
return callback(asError(err))
}
},
})
}
}
_transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback) {
this.hasher.update(chunk)
cb(null, chunk)
}
const asError = (err: unknown): Error =>
err instanceof Error ? err : new Error('Unexpected error', { cause: err })
_flush(cb: TransformCallback) {
try {
const cid = sha256RawToCid(this.hasher.digest())
if (this.cid.equals(cid)) {
return cb()
} else {
return cb(new VerifyCidError(this.cid, cid))
}
} catch (_err) {
const err =
_err instanceof Error
? _err
: new Error('Unexpected error', { cause: _err })
return cb(err)
}
}
}
export class VerifyCidError extends Error {

@@ -96,0 +94,0 @@ constructor(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc