@chainfuse/helpers 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/crypto.d.mts CHANGED
@@ -1,7 +1,13 @@
1
1
  export declare class CryptoHelpers {
2
- static secretBytes(length: number): Promise<Buffer | Uint8Array>;
3
- static base16secret(length: number): Promise<string>;
4
- static base62secret(length: number): Promise<string>;
2
+ static secretBytes(byteSize: number): Promise<Buffer | Uint8Array>;
3
+ /**
4
+ * @yields secret length = (`byteSize` * Math.log2(16)) / 8
5
+ */
6
+ static base16secret(byteSize: number): Promise<string>;
7
+ /**
8
+ * @yields secret length = (`byteSize` * Math.log2(62)) / 8
9
+ */
10
+ static base62secret(byteSize: number): Promise<string>;
5
11
  static getHash(algorithm: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', input: string | ArrayBufferLike): Promise<string>;
6
12
  /**
7
13
  * @returns Fully formatted (double quote encapsulated) `ETag` header value
package/dist/crypto.mjs CHANGED
@@ -1,22 +1,28 @@
1
1
  import { BufferHelpers } from './buffers.mjs';
2
2
  export class CryptoHelpers {
3
- static secretBytes(length) {
3
+ static secretBytes(byteSize) {
4
4
  return import('node:crypto')
5
- .then(({ randomBytes }) => randomBytes(length))
5
+ .then(({ randomBytes }) => randomBytes(byteSize))
6
6
  .catch(() => {
7
- const randomBytes = new Uint8Array(length);
7
+ const randomBytes = new Uint8Array(byteSize);
8
8
  crypto.getRandomValues(randomBytes);
9
9
  return randomBytes;
10
10
  });
11
11
  }
12
- static base16secret(length) {
13
- return this.secretBytes(length).then((bytes) => BufferHelpers.bufferToHex(bytes));
12
+ /**
13
+ * @yields secret length = (`byteSize` * Math.log2(16)) / 8
14
+ */
15
+ static base16secret(byteSize) {
16
+ return this.secretBytes(byteSize).then((bytes) => BufferHelpers.bufferToHex(bytes));
14
17
  }
15
- static base62secret(length) {
18
+ /**
19
+ * @yields secret length = (`byteSize` * Math.log2(62)) / 8
20
+ */
21
+ static base62secret(byteSize) {
16
22
  const LOWER_CHAR_SET = 'abcdefghijklmnopqrstuvwxyz';
17
23
  const NUMBER_CHAR_SET = '0123456789';
18
24
  const CHAR_SET = `${NUMBER_CHAR_SET}${LOWER_CHAR_SET}${LOWER_CHAR_SET.toUpperCase()}`;
19
- return this.secretBytes(length).then((randomBytes) => {
25
+ return this.secretBytes(byteSize).then((randomBytes) => {
20
26
  /**
21
27
  * @link https://jsbm.dev/x1F2ITy7RU8T2
22
28
  */
package/dist/net.d.mts CHANGED
@@ -11,7 +11,7 @@ export declare class NetHelpers {
11
11
  static initBodyTrimmer(init?: RequestInit): RequestInit;
12
12
  static stripSensitiveHeaders(originalHeaders?: Headers): Headers;
13
13
  static cfApi(apiKey: string, cacheTtl?: number, logger?: CustomLoging): Cloudflare;
14
- static loggingFetch(info: Parameters<typeof fetch>[0], init: Parameters<typeof fetch>[1], body?: boolean, logger?: CustomLoging): Promise<Response>;
14
+ static loggingFetch(info: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1], body?: boolean, logger?: CustomLoging): Promise<Response>;
15
15
  /**
16
16
  * Parses the Server-Timing header and returns an object with the metrics.
17
17
  * The object keys are the metric names (with optional descriptions), and the values are the duration of each metric or null if no duration is found.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -53,9 +53,9 @@
53
53
  "uuid": "^10.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@chainfuse/types": "^0.1.2",
57
- "@types/node": "^20.16.6",
56
+ "@chainfuse/types": "^0.1.3",
57
+ "@types/node": "^20.16.9",
58
58
  "@types/uuid": "^10.0.0"
59
59
  },
60
- "gitHead": "3a9cbb00aee10e7c93a24878d384eccca787b109"
60
+ "gitHead": "f497bc127523d4b5b627308e7ca69579c71dc2bf"
61
61
  }