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

@bicycle-codes/crypto-stream

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bicycle-codes/crypto-stream - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

8

dist/concat-streams.d.ts
/**
* Concatenates the array of ReadableStreams passed in `inputStreams` into a single
* ReadableStream.
* Concatenates the array of ReadableStreams passed in `inputStreams`
* into a single ReadableStream.
*
* @param {ReadableStream[]} inputStreams
* @returns ReadableStream
* @returns {ReadableStream}
*/
export declare function concatStreams(inputStreams: ReadableStream[]): ReadableStream<any>;
export declare function concatStreams(inputStreams: ReadableStream[]): ReadableStream;
//# sourceMappingURL=concat-streams.d.ts.map
/**
* Concatenates the array of ReadableStreams passed in `inputStreams` into a single
* ReadableStream.
* Concatenates the array of ReadableStreams passed in `inputStreams`
* into a single ReadableStream.
*
* @param {ReadableStream[]} inputStreams
* @returns ReadableStream
* @returns {ReadableStream}
*/

@@ -8,0 +8,0 @@ export function concatStreams(inputStreams) {

@@ -35,3 +35,3 @@ /**

*/
export declare function decryptStream(input: any, secretKey: any, rs?: number): ReadableStream<any>;
export declare function decryptStream(input: ReadableStream, secretKey: CryptoKey, rs?: number): ReadableStream;
/**

@@ -42,10 +42,10 @@ * Given a desired plaintext byte range specified by `offset` and `length`,

*
* To decrypt an arbitrary plaintext range, the client will need to supply multiple
* (currently always two) ranges of encrypted data. `decryptStreamRange`
* returns a promise that resolves to an object containing `ranges`, which is
* an array of { offset, length } entries specifying the needed encrypted byte
* ranges, and `encrypt`, a callback function.
* To decrypt an arbitrary plaintext range, the client will need to supply
* multiple (currently always two) ranges of encrypted data.
* `decryptStreamRange` returns a promise that resolves to an object containing
* `ranges`, which is an array of { offset, length } entries specifying the
* needed encrypted byte ranges, and `encrypt`, a callback function.
*
* Once the client has gathered an array `streams` of encrypted ReadableStreams,
* one for each of these ranges, it should call `encrypt(streams)`. This will
* one for each of these ranges, it should call `decrypt(streams)`. This will
* then return the final plaintext ReadableStream.

@@ -52,0 +52,0 @@ *

@@ -83,10 +83,10 @@ /**

*
* To decrypt an arbitrary plaintext range, the client will need to supply multiple
* (currently always two) ranges of encrypted data. `decryptStreamRange`
* returns a promise that resolves to an object containing `ranges`, which is
* an array of { offset, length } entries specifying the needed encrypted byte
* ranges, and `encrypt`, a callback function.
* To decrypt an arbitrary plaintext range, the client will need to supply
* multiple (currently always two) ranges of encrypted data.
* `decryptStreamRange` returns a promise that resolves to an object containing
* `ranges`, which is an array of { offset, length } entries specifying the
* needed encrypted byte ranges, and `encrypt`, a callback function.
*
* Once the client has gathered an array `streams` of encrypted ReadableStreams,
* one for each of these ranges, it should call `encrypt(streams)`. This will
* one for each of these ranges, it should call `decrypt(streams)`. This will
* then return the final plaintext ReadableStream.

@@ -132,5 +132,6 @@ *

if (!(streams.every(stream => stream instanceof ReadableStream))) {
throw new TypeError('stream');
throw new TypeError('Stream is not a ReadableStream');
}
// Combine the header and data streams, and then slice how ECETransformer expects
// Combine the header and data streams, and then slice how
// ECETransformer expects
const encryptedStream = transformStream(concatStreams(streams), new SliceTransformer(HEADER_LENGTH, rs)).readable;

@@ -179,3 +180,3 @@ // Plaintext stream of needed records

if (mode !== MODE_ENCRYPT && mode !== MODE_DECRYPT) {
throw new Error('mode must be either encrypt or decrypt');
throw new Error("mode must be either 'encrypt' or 'decrypt'");
}

@@ -225,2 +226,4 @@ checkSecretKey(secretKey);

}
if (!this.nonceBase)
throw new Error('Not nonce base');
const nonce = this.nonceBase.slice();

@@ -270,2 +273,4 @@ const dv = new DataView(nonce.buffer, nonce.byteOffset, nonce.byteLength);

createHeader() {
if (!this.salt)
throw new Error('Not salt');
const header = new Uint8Array(HEADER_LENGTH);

@@ -324,2 +329,4 @@ header.set(this.salt);

async transformPrevChunk(isLast, controller) {
if (!this.prevChunk)
throw new Error('not this.prevChunk');
if (this.mode === MODE_ENCRYPT) {

@@ -330,2 +337,4 @@ controller.enqueue(await this.encryptRecord(this.prevChunk, this.seq, isLast));

if (this.seq === -1) {
if (!this.prevChunk)
throw new Error('not this.prevChunk');
// the first chunk during decryption contains only the header

@@ -332,0 +341,0 @@ const header = this.readHeader(this.prevChunk);

@@ -14,3 +14,3 @@ /**

offset: number;
constructor(offset: any, length: any);
constructor(offset: number, length: number);
transform(chunk: Uint8Array, controller: TransformStreamDefaultController): void;

@@ -17,0 +17,0 @@ flush(controller: TransformStreamDefaultController): void;

@@ -7,3 +7,3 @@ export { encryptedSize, plaintextSize } from './ece.js';

metaKeyPromise: Promise<CryptoKey>;
authTokenPromise: Promise<ArrayBuffer>;
authTokenPromise: Promise<Uint8Array>;
constructor(key?: string | Uint8Array, salt?: string | Uint8Array);

@@ -14,8 +14,35 @@ /**

get keyB64(): string;
/**
* Get the salt as base64 string
*/
get saltB64(): string;
authToken(): Promise<ArrayBuffer>;
/**
* get a promise for the auth token.
* @returns {Promise<Uint8Array>}
*/
authToken(): Promise<Uint8Array>;
/**
* Get the auth token as a base64 string
*/
authTokenB64(): Promise<string>;
/**
* Get a header string: `Bearer sync-v1 ${authTokenB64}`
*/
authHeader(): Promise<string>;
setAuthToken(authToken: string | Uint8Array | null): void;
/**
* Set the auth token
* @param authToken The new token
*/
setAuthToken(authToken?: string | Uint8Array): void;
/**
* Take a stream, return an encrypted stream.
* @param stream Input stream
* @returns {Promise<ReadableStream>}
*/
encryptStream(stream: ReadableStream): Promise<ReadableStream>;
/**
* Take an encrypted stream, return a decrypted stream.
* @param encryptedStream The input (encrypted) stream
* @returns The decrypted stream
*/
decryptStream(encryptedStream: ReadableStream): Promise<ReadableStream>;

@@ -22,0 +49,0 @@ /**

@@ -79,8 +79,18 @@ import { webcrypto } from 'one-webcrypto';

}
/**
* Get the salt as base64 string
*/
get saltB64() {
return arrayToB64(this.salt);
}
/**
* get a promise for the auth token.
* @returns {Promise<Uint8Array>}
*/
async authToken() {
return await this.authTokenPromise;
}
/**
* Get the auth token as a base64 string
*/
async authTokenB64() {

@@ -90,2 +100,5 @@ const authToken = await this.authToken();

}
/**
* Get a header string: `Bearer sync-v1 ${authTokenB64}`
*/
async authHeader() {

@@ -95,5 +108,14 @@ const authTokenB64 = await this.authTokenB64();

}
/**
* Set the auth token
* @param authToken The new token
*/
setAuthToken(authToken) {
this.authTokenPromise = Promise.resolve(decodeBits(authToken));
}
/**
* Take a stream, return an encrypted stream.
* @param stream Input stream
* @returns {Promise<ReadableStream>}
*/
async encryptStream(stream) {

@@ -106,2 +128,7 @@ if (!(stream instanceof ReadableStream)) {

}
/**
* Take an encrypted stream, return a decrypted stream.
* @param encryptedStream The input (encrypted) stream
* @returns The decrypted stream
*/
async decryptStream(encryptedStream) {

@@ -140,3 +167,3 @@ if (!(encryptedStream instanceof ReadableStream)) {

if (!(meta instanceof Uint8Array)) {
throw new TypeError('meta');
throw new TypeError('`meta` should be Uint8Array');
}

@@ -143,0 +170,0 @@ const iv = webcrypto.getRandomValues(new Uint8Array(IV_LENGTH));

@@ -15,6 +15,6 @@ /**

constructor(firstChunkSize: number, restChunkSize?: number);
send(record: any, controller: any): void;
transform(chunk: Uint8Array, controller: any): void;
flush(controller: any): void;
send(record: Uint8Array, controller: TransformStreamDefaultController): void;
transform(chunk: Uint8Array, controller: TransformStreamDefaultController): void;
flush(controller: TransformStreamDefaultController): void;
}
//# sourceMappingURL=slice-transformer.d.ts.map

@@ -7,3 +7,3 @@ /**

*/
export declare function transformStream(sourceReadable: any, transformer: Transformer): {
export declare function transformStream(sourceReadable: ReadableStream, transformer: Transformer): {
readable: ReadableStream;

@@ -10,0 +10,0 @@ done: Promise<unknown>;

@@ -13,2 +13,5 @@ /**

const transform = new TransformStream(transformer);
// .pipeTo
// returns a Promise that fulfills when the piping process
// completes successfully
done = sourceReadable.pipeTo(transform.writable);

@@ -59,3 +62,3 @@ transformedReadable = transform.readable;

this.wrappedController = {
desiredSize: 5,
desiredSize: controller.desiredSize,
enqueue: (value) => {

@@ -62,0 +65,0 @@ this.progressMade = true;

@@ -5,3 +5,3 @@ {

"type": "module",
"version": "0.0.3",
"version": "0.0.4",
"main": "dist/index.js",

@@ -8,0 +8,0 @@ "files": [

@@ -213,5 +213,6 @@ # crypto stream

Returns a `Promise` that resolves to a object containing `ranges`, which is an array of
objects containing `offset` and `length` integers specifying the encrypted byte ranges
that are needed to decrypt the client's specified range, and a `decrypt` function.
Returns a `Promise` that resolves to a object containing `ranges`, which is
an array of objects containing `offset` and `length` integers specifying the
encrypted byte ranges that are needed to decrypt the client's specified range,
and a `decrypt` function.

@@ -218,0 +219,0 @@ Once the client has gathered a stream for each byte range in `ranges`,

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

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