@chainfuse/helpers 0.0.6 → 0.0.8
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 +9 -3
- package/dist/crypto.mjs +13 -7
- package/package.json +4 -4
package/dist/crypto.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export declare class CryptoHelpers {
|
|
2
|
-
static secretBytes(
|
|
3
|
-
|
|
4
|
-
|
|
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(
|
|
3
|
+
static secretBytes(byteSize) {
|
|
4
4
|
return import('node:crypto')
|
|
5
|
-
.then(({ randomBytes }) => randomBytes(
|
|
5
|
+
.then(({ randomBytes }) => randomBytes(byteSize))
|
|
6
6
|
.catch(() => {
|
|
7
|
-
const randomBytes = new Uint8Array(
|
|
7
|
+
const randomBytes = new Uint8Array(byteSize);
|
|
8
8
|
crypto.getRandomValues(randomBytes);
|
|
9
9
|
return randomBytes;
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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(
|
|
25
|
+
return this.secretBytes(byteSize).then((randomBytes) => {
|
|
20
26
|
/**
|
|
21
27
|
* @link https://jsbm.dev/x1F2ITy7RU8T2
|
|
22
28
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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.
|
|
57
|
-
"@types/node": "^20.16.
|
|
56
|
+
"@chainfuse/types": "^0.1.3",
|
|
57
|
+
"@types/node": "^20.16.9",
|
|
58
58
|
"@types/uuid": "^10.0.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "28cf77e03b52ff688eac5d0896061f1f04caa663"
|
|
61
61
|
}
|