@chainfuse/helpers 0.4.0 → 0.4.1

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.
@@ -1,18 +1,18 @@
1
- import type { UndefinedProperties } from '@chainfuse/types';
2
- import type { PrefixedUuid, UuidExport } from '@chainfuse/types/d1';
1
+ import type { D1Blob, PrefixedUuid, UndefinedProperties, UuidExport } from '@chainfuse/types';
3
2
  export declare class BufferHelpers {
4
3
  /**
5
4
  * @deprecated
6
5
  */
7
6
  static bufferFromHex(...args: Parameters<typeof this.hexToBuffer>): ReturnType<typeof this.hexToBuffer>;
8
7
  static hexToBuffer(hex: UuidExport['hex']): Promise<UuidExport['blob']>;
9
- static bufferToHex(buffer: UuidExport['blob']): Promise<UuidExport['hex']>;
8
+ static bufferToHex(buffer: UuidExport['blob'] | D1Blob): Promise<UuidExport['hex']>;
10
9
  static base64ToBuffer(rawBase64: string, urlSafe: boolean): Promise<UuidExport['blob']>;
11
- static bufferToBase64(buffer: UuidExport['blob'], urlSafe: boolean): Promise<string>;
10
+ static bufferToBase64(buffer: UuidExport['blob'] | D1Blob, urlSafe: boolean): Promise<string>;
12
11
  static get generateUuid(): Promise<UuidExport>;
13
- static uuidConvert(input: UuidExport['blob']): Promise<UuidExport>;
12
+ static uuidConvert(input: undefined): Promise<UndefinedProperties<UuidExport>>;
14
13
  static uuidConvert(prefixedUtf: PrefixedUuid): Promise<UuidExport>;
15
14
  static uuidConvert(input: UuidExport['utf8']): Promise<UuidExport>;
16
15
  static uuidConvert(input: UuidExport['hex']): Promise<UuidExport>;
17
- static uuidConvert(input: undefined): Promise<UndefinedProperties<UuidExport>>;
16
+ static uuidConvert(input: UuidExport['blob']): Promise<UuidExport>;
17
+ static uuidConvert(input: D1Blob): Promise<UuidExport>;
18
18
  }
package/dist/buffers.mjs CHANGED
@@ -19,10 +19,12 @@ export class BufferHelpers {
19
19
  }
20
20
  static bufferToHex(buffer) {
21
21
  return (import('node:buffer')
22
+ // @ts-expect-error `ArrayBufferLike` or D1Blob is actually accepted and fine
22
23
  .then(({ Buffer }) => Buffer.from(buffer).toString('hex'))
23
24
  /**
24
25
  * @link https://jsbm.dev/AoXo8dEke1GUg
25
26
  */
27
+ // @ts-expect-error `ArrayBufferLike` or D1Blob is actually accepted and fine
26
28
  .catch(() => new Uint8Array(buffer).reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '')));
27
29
  }
28
30
  static base64ToBuffer(rawBase64, urlSafe) {
@@ -44,7 +46,8 @@ export class BufferHelpers {
44
46
  });
45
47
  }
46
48
  static bufferToBase64(buffer, urlSafe) {
47
- return import('node:buffer')
49
+ return (import('node:buffer')
50
+ // @ts-expect-error `ArrayBufferLike` or D1Blob is actually accepted and fine
48
51
  .then(({ Buffer }) => Buffer.from(buffer).toString(urlSafe ? 'base64url' : 'base64'))
49
52
  .catch(() => {
50
53
  // @ts-expect-error `ArrayBufferLike` is actually accepted and fine
@@ -55,7 +58,7 @@ export class BufferHelpers {
55
58
  else {
56
59
  return raw;
57
60
  }
58
- });
61
+ }));
59
62
  }
60
63
  static get generateUuid() {
61
64
  return Promise.all([CryptoHelpers.secretBytes(16), import('uuid')]).then(([random, { v7: uuidv7 }]) => {
@@ -94,11 +97,11 @@ export class BufferHelpers {
94
97
  }
95
98
  }
96
99
  else {
97
- const blob = input;
98
- return this.bufferToHex(blob).then((hex) => ({
100
+ return this.bufferToHex(input).then((hex) => ({
99
101
  utf8: `${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}`,
100
102
  hex,
101
- blob,
103
+ // @ts-expect-error `ArrayBufferLike` or D1Blob is actually accepted and fine
104
+ blob: new Uint8Array(input).buffer,
102
105
  }));
103
106
  }
104
107
  }
package/dist/crypto.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare class CryptoHelpers {
2
- static secretBytes(byteSize: number): Promise<Uint8Array<ArrayBuffer | SharedArrayBuffer> | Uint8Array<ArrayBuffer>>;
2
+ static secretBytes(byteSize: number): Promise<Uint8Array<ArrayBuffer> | Uint8Array<ArrayBuffer | SharedArrayBuffer>>;
3
3
  /**
4
4
  * @yields secret length = (`byteSize` * Math.log2(16)) / 8
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -55,8 +55,8 @@
55
55
  "uuid": "^11.0.3"
56
56
  },
57
57
  "devDependencies": {
58
- "@chainfuse/types": "^1.2.1",
58
+ "@chainfuse/types": "^1.3.0",
59
59
  "@types/node": "^22.10.0"
60
60
  },
61
- "gitHead": "1bdc9ab8d4604ec581e390361a78f5dcc615dbbf"
61
+ "gitHead": "ea93b05607f7e9687526434591370bfad1ad8605"
62
62
  }