@digitaldefiance/ecies-lib 4.8.2 → 4.8.5
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/package.json +8 -3
- package/src/interfaces/constants.d.ts +10 -2
- package/src/interfaces/constants.d.ts.map +1 -1
- package/src/interfaces/id-provider.d.ts +36 -9
- package/src/interfaces/id-provider.d.ts.map +1 -1
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js.map +1 -1
- package/src/lib/base-id-provider.d.ts +24 -17
- package/src/lib/base-id-provider.d.ts.map +1 -1
- package/src/lib/base-id-provider.js +16 -43
- package/src/lib/base-id-provider.js.map +1 -1
- package/src/lib/guid.d.ts +16 -0
- package/src/lib/guid.d.ts.map +1 -1
- package/src/lib/guid.js +76 -14
- package/src/lib/guid.js.map +1 -1
- package/src/lib/id-providers/custom-provider.d.ts +15 -7
- package/src/lib/id-providers/custom-provider.d.ts.map +1 -1
- package/src/lib/id-providers/custom-provider.js +20 -8
- package/src/lib/id-providers/custom-provider.js.map +1 -1
- package/src/lib/id-providers/guidv4-provider.d.ts +8 -3
- package/src/lib/id-providers/guidv4-provider.d.ts.map +1 -1
- package/src/lib/id-providers/guidv4-provider.js +15 -6
- package/src/lib/id-providers/guidv4-provider.js.map +1 -1
- package/src/lib/id-providers/index.d.ts +1 -1
- package/src/lib/id-providers/index.d.ts.map +1 -1
- package/src/lib/id-providers/objectid-provider.d.ts +9 -4
- package/src/lib/id-providers/objectid-provider.d.ts.map +1 -1
- package/src/lib/id-providers/objectid-provider.js +15 -11
- package/src/lib/id-providers/objectid-provider.js.map +1 -1
- package/src/lib/id-providers/uuid-provider.d.ts +7 -3
- package/src/lib/id-providers/uuid-provider.d.ts.map +1 -1
- package/src/lib/id-providers/uuid-provider.js +13 -1
- package/src/lib/id-providers/uuid-provider.js.map +1 -1
- package/src/lib/voting/audit.d.ts +6 -0
- package/src/lib/voting/audit.d.ts.map +1 -1
- package/src/lib/voting/audit.js +15 -4
- package/src/lib/voting/audit.js.map +1 -1
- package/src/lib/voting/poll-core.d.ts.map +1 -1
- package/src/lib/voting/poll-core.js +4 -3
- package/src/lib/voting/poll-core.js.map +1 -1
- package/src/member.d.ts +3 -1
- package/src/member.d.ts.map +1 -1
- package/src/member.js +41 -16
- package/src/member.js.map +1 -1
- package/src/secure-buffer.d.ts +3 -4
- package/src/secure-buffer.d.ts.map +1 -1
- package/src/secure-buffer.js +5 -10
- package/src/secure-buffer.js.map +1 -1
- package/src/secure-string.d.ts +4 -3
- package/src/secure-string.d.ts.map +1 -1
- package/src/secure-string.js +3 -4
- package/src/secure-string.js.map +1 -1
- package/src/services/ecies/interfaces.d.ts +9 -8
- package/src/services/ecies/interfaces.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.d.ts +19 -10
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +16 -7
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/ecies/service.d.ts +7 -6
- package/src/services/ecies/service.d.ts.map +1 -1
- package/src/services/ecies/service.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/ecies-lib",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.5",
|
|
4
4
|
"description": "Digital Defiance ECIES Library",
|
|
5
5
|
"homepage": "https://github.com/Digital-Defiance/ecies-lib",
|
|
6
6
|
"repository": {
|
|
@@ -28,10 +28,15 @@
|
|
|
28
28
|
"build:stream": "npx nx build --outputStyle=stream digitaldefiance-ecies-lib",
|
|
29
29
|
"build:logged": "npx nx build --outputStyle=stream digitaldefiance-ecies-lib 2>&1 | ansifilter -o build.log",
|
|
30
30
|
"test": "npx nx test digitaldefiance-ecies-lib",
|
|
31
|
+
"test:16": "npx nx test digitaldefiance-ecies-lib --parallel=16",
|
|
32
|
+
"test:dev": "NODE_ENV=development npx nx test digitaldefiance-ecies-lib --configuration=development",
|
|
33
|
+
"test:16:dev:noansi": "NODE_ENV=development npx nx test digitaldefiance-ecies-lib --parallel=16 --configuration=development | ansifilter",
|
|
34
|
+
"test:dev:16": "NODE_ENV=development npx nx test digitaldefiance-ecies-lib --parallel=16 --configuration=development",
|
|
35
|
+
"test:dev:16:logged": "NODE_ENV=development npx nx test digitaldefiance-ecies-lib --parallel=16 --configuration=development 2>&1 | ansifilter -o test.log",
|
|
31
36
|
"test:nocache": "npx nx test --skip-nx-cache digitaldefiance-ecies-lib",
|
|
32
37
|
"test:stream": "npx nx test --outputStyle=stream digitaldefiance-ecies-lib",
|
|
33
|
-
"test:logged": "npx jest --config=jest.config.js 2>&1 | tee test.log",
|
|
34
|
-
"test:logged:verbose": "VERBOSE_TESTS=1 npx jest --config=jest.config.js 2>&1 | tee test.log",
|
|
38
|
+
"test:logged": "npx jest --config=jest.config.js 2>&1 | ansifilter | tee test.log",
|
|
39
|
+
"test:logged:verbose": "VERBOSE_TESTS=1 npx jest --config=jest.config.js 2>&1 | ansifilter | tee test.log",
|
|
35
40
|
"test:coverage": "npx jest --coverage --testPathPattern=digitaldefiance-ecies-lib --coverageReporters=text",
|
|
36
41
|
"check:circular": "madge --circular --extensions ts src/index.ts",
|
|
37
42
|
"check:circular:json": "madge --circular --extensions ts --json src/index.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Pbkdf2Profiles } from '../pbkdf2-profiles';
|
|
2
2
|
import type { IChecksumConsts } from './checksum-consts';
|
|
3
3
|
import type { IECIESConstants } from './ecies-consts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { IIdProviderBase } from './id-provider';
|
|
5
5
|
import type { IPBkdf2Consts } from './pbkdf2-consts';
|
|
6
6
|
import type { IVotingConsts } from './voting-consts';
|
|
7
7
|
export interface IConstants {
|
|
@@ -31,6 +31,10 @@ export interface IConstants {
|
|
|
31
31
|
*
|
|
32
32
|
* Default: ObjectIdProvider (12 bytes, MongoDB compatible)
|
|
33
33
|
*
|
|
34
|
+
* The base interface provides Uint8Array-based operations (generate, validate,
|
|
35
|
+
* serialize, deserialize). For typed operations with the native ID type,
|
|
36
|
+
* cast to the specific provider type or use IIdProvider<T>.
|
|
37
|
+
*
|
|
34
38
|
* @example
|
|
35
39
|
* ```typescript
|
|
36
40
|
* import { GuidV4Provider } from './lib/id-providers';
|
|
@@ -39,9 +43,13 @@ export interface IConstants {
|
|
|
39
43
|
* const config = createRuntimeConfiguration({
|
|
40
44
|
* idProvider: new GuidV4Provider()
|
|
41
45
|
* });
|
|
46
|
+
*
|
|
47
|
+
* // For typed access:
|
|
48
|
+
* const provider = config.idProvider as GuidV4Provider;
|
|
49
|
+
* const guid = provider.fromBytes(provider.generate());
|
|
42
50
|
* ```
|
|
43
51
|
*/
|
|
44
|
-
idProvider:
|
|
52
|
+
idProvider: IIdProviderBase;
|
|
45
53
|
CHECKSUM: IChecksumConsts;
|
|
46
54
|
ECIES: IECIESConstants;
|
|
47
55
|
PBKDF2: IPBkdf2Consts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,UAAU,EAAE,eAAe,CAAC;IAE5B,QAAQ,EAAE,eAAe,CAAC;IAC1B,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,EAAE,aAAa,CAAC;IACtB,eAAe,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This
|
|
2
|
+
* Base interface for ID providers with Uint8Array-based operations.
|
|
3
|
+
* This non-generic interface is used by IConstants and validation functions
|
|
4
|
+
* that don't need to know the native ID type.
|
|
4
5
|
*/
|
|
5
|
-
export interface
|
|
6
|
+
export interface IIdProviderBase {
|
|
6
7
|
/**
|
|
7
8
|
* The fixed byte length of IDs produced by this provider.
|
|
8
9
|
* This determines the size of recipient ID fields in encrypted messages.
|
|
@@ -41,6 +42,32 @@ export interface IIdProvider {
|
|
|
41
42
|
* @throws Error if the string is not a valid representation
|
|
42
43
|
*/
|
|
43
44
|
deserialize(str: string): Uint8Array;
|
|
45
|
+
/**
|
|
46
|
+
* Convert any ID representation to canonical Uint8Array format.
|
|
47
|
+
* At the base level, accepts unknown and returns Uint8Array.
|
|
48
|
+
* @param id The ID in any supported format
|
|
49
|
+
* @returns The ID as a Uint8Array of length `byteLength`
|
|
50
|
+
*/
|
|
51
|
+
toBytes(id: unknown): Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Convert Uint8Array to the provider's native representation.
|
|
54
|
+
* At the base level, returns unknown.
|
|
55
|
+
* @param bytes The ID as a Uint8Array
|
|
56
|
+
* @returns The ID in the provider's native format
|
|
57
|
+
*/
|
|
58
|
+
fromBytes(bytes: Uint8Array): unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Full interface for ID providers that supply recipient identifiers.
|
|
62
|
+
* This allows the library to support various ID formats (ObjectID, GUID, UUID, custom).
|
|
63
|
+
*
|
|
64
|
+
* The generic type T represents the provider's "native" ID type:
|
|
65
|
+
* - ObjectIdProvider: T = ObjectId
|
|
66
|
+
* - GuidV4Provider: T = GuidV4
|
|
67
|
+
* - UuidProvider: T = string
|
|
68
|
+
* - CustomIdProvider: T = Uint8Array
|
|
69
|
+
*/
|
|
70
|
+
export interface IIdProvider<T> extends IIdProviderBase {
|
|
44
71
|
/**
|
|
45
72
|
* Compare two IDs for equality.
|
|
46
73
|
* Default implementation uses constant-time comparison.
|
|
@@ -48,39 +75,39 @@ export interface IIdProvider {
|
|
|
48
75
|
* @param b Second ID
|
|
49
76
|
* @returns True if IDs are equal, false otherwise
|
|
50
77
|
*/
|
|
51
|
-
equals(a:
|
|
78
|
+
equals(a: T, b: T): boolean;
|
|
52
79
|
/**
|
|
53
80
|
* Clone an ID buffer.
|
|
54
81
|
* Default implementation creates a defensive copy.
|
|
55
82
|
* @param id The ID to clone
|
|
56
83
|
* @returns A new Uint8Array with the same contents
|
|
57
84
|
*/
|
|
58
|
-
clone(id:
|
|
85
|
+
clone(id: T): T;
|
|
59
86
|
/**
|
|
60
87
|
* Convert an ID of unknown type to a string representation.
|
|
61
88
|
* This is useful when dealing with generic IDs that might be Uint8Array, string, or other types.
|
|
62
89
|
* @param id The ID to convert
|
|
63
90
|
* @returns A string representation of the ID
|
|
64
91
|
*/
|
|
65
|
-
idToString(id:
|
|
92
|
+
idToString(id: T): string;
|
|
66
93
|
/**
|
|
67
94
|
* Convert a string representation of an ID back to an ID buffer.
|
|
68
95
|
* This is an alias for `deserialize` to provide symmetry with `idToString`.
|
|
69
96
|
* @param str The string representation of the ID
|
|
70
97
|
* @returns The ID as a Uint8Array of length `byteLength`
|
|
71
98
|
*/
|
|
72
|
-
idFromString(str: string):
|
|
99
|
+
idFromString(str: string): T;
|
|
73
100
|
/**
|
|
74
101
|
* Convert any ID representation to canonical Uint8Array format.
|
|
75
102
|
* @param id The ID in any supported format
|
|
76
103
|
* @returns The ID as a Uint8Array of length `byteLength`
|
|
77
104
|
*/
|
|
78
|
-
toBytes(id:
|
|
105
|
+
toBytes(id: T): Uint8Array;
|
|
79
106
|
/**
|
|
80
107
|
* Convert Uint8Array to the provider's native representation.
|
|
81
108
|
* @param bytes The ID as a Uint8Array
|
|
82
109
|
* @returns The ID in the provider's native format
|
|
83
110
|
*/
|
|
84
|
-
fromBytes(bytes: Uint8Array):
|
|
111
|
+
fromBytes(bytes: Uint8Array): T;
|
|
85
112
|
}
|
|
86
113
|
//# sourceMappingURL=id-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-provider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/id-provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"id-provider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/id-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,IAAI,UAAU,CAAC;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM,CAAC;IAElC;;;;;;OAMG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAErC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,UAAU,CAAC;IAEjC;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC;CACvC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,eAAe;IACrD;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC;IAE5B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAEhB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC;IAE1B;;;;;OAKG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC;IAE3B;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,CAAC;CACjC"}
|
|
@@ -6,6 +6,7 @@ export * from './ecies-consts';
|
|
|
6
6
|
export * from './ecies-file-service';
|
|
7
7
|
export * from './ecies-library';
|
|
8
8
|
export * from './guid';
|
|
9
|
+
export type { IIdProvider, IIdProviderBase } from './id-provider';
|
|
9
10
|
export type * from './member';
|
|
10
11
|
export * from './member-storage';
|
|
11
12
|
export type * from './member-with-mnemonic';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,mBAAmB,UAAU,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,mBAAmB,wBAAwB,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,mBAAmB,UAAU,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,mBAAmB,wBAAwB,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/index.ts"],"names":[],"mappings":";;;;AAAA,4DAAkC;AAClC,4DAAkC;AAClC,sDAA4B;AAC5B,yDAA+B;AAC/B,yDAA+B;AAC/B,+DAAqC;AACrC,0DAAgC;AAChC,iDAAuB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/interfaces/index.ts"],"names":[],"mappings":";;;;AAAA,4DAAkC;AAClC,4DAAkC;AAClC,sDAA4B;AAC5B,yDAA+B;AAC/B,yDAA+B;AAC/B,+DAAqC;AACrC,0DAAgC;AAChC,iDAAuB;AAGvB,2DAAiC;AAEjC,0DAAgC;AAChC,0DAAgC;AAChC,0DAAgC;AAChC,4DAAkC;AAClC,wDAA8B;AAC9B,0DAAgC;AAChC,6CAOuB;AADrB,4GAAA,aAAa,OAAA;AAEf,2DAAiC;AACjC,0DAAgC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { IIdProvider } from '../interfaces/id-provider';
|
|
2
2
|
/**
|
|
3
3
|
* Base class for ID providers with common utility methods.
|
|
4
|
+
*
|
|
5
|
+
* Subclasses must implement all abstract methods for their specific ID type.
|
|
6
|
+
* For providers where T = Uint8Array, see ByteIdProvider for a concrete base.
|
|
4
7
|
*/
|
|
5
|
-
export declare abstract class BaseIdProvider implements IIdProvider {
|
|
8
|
+
export declare abstract class BaseIdProvider<T> implements IIdProvider<T> {
|
|
6
9
|
abstract readonly byteLength: number;
|
|
7
10
|
abstract readonly name: string;
|
|
8
11
|
abstract generate(): Uint8Array;
|
|
@@ -10,36 +13,40 @@ export declare abstract class BaseIdProvider implements IIdProvider {
|
|
|
10
13
|
abstract serialize(id: Uint8Array): string;
|
|
11
14
|
abstract deserialize(str: string): Uint8Array;
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
* Default implementation handles Uint8Array using serialize(), and falls back to String().
|
|
16
|
+
* Create a defensive copy of an ID.
|
|
15
17
|
*/
|
|
16
|
-
|
|
18
|
+
abstract clone(id: T): T;
|
|
17
19
|
/**
|
|
18
|
-
* Convert
|
|
19
|
-
* Default implementation delegates to `deserialize`.
|
|
20
|
+
* Convert Uint8Array to the provider's native representation.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
abstract fromBytes(bytes: Uint8Array): T;
|
|
22
23
|
/**
|
|
23
|
-
* Convert
|
|
24
|
-
* Default implementation handles common types.
|
|
24
|
+
* Convert the provider's native representation to Uint8Array.
|
|
25
25
|
*/
|
|
26
|
-
toBytes(id:
|
|
26
|
+
abstract toBytes(id: T): Uint8Array;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Compare two IDs for equality.
|
|
29
|
+
* Subclasses should implement constant-time comparison where possible.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
abstract equals(a: T, b: T): boolean;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Convert an ID to a string representation.
|
|
34
|
+
* Default implementation delegates to serialize().
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
+
idToString(id: T): string;
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
+
* Convert a string representation of an ID back to the native type.
|
|
39
|
+
* Default implementation delegates to deserialize().
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
idFromString(str: string): T;
|
|
40
42
|
/**
|
|
41
43
|
* Validate ID length matches expected byte length.
|
|
42
44
|
*/
|
|
43
45
|
protected validateLength(id: Uint8Array, context: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Constant-time comparison for Uint8Array buffers.
|
|
48
|
+
* Utility method for subclasses to use in their equals() implementation.
|
|
49
|
+
*/
|
|
50
|
+
protected constantTimeEquals(a: Uint8Array, b: Uint8Array): boolean;
|
|
44
51
|
}
|
|
45
52
|
//# sourceMappingURL=base-id-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-id-provider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/lib/base-id-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"base-id-provider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/lib/base-id-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;;;;GAKG;AACH,8BAAsB,cAAc,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAE/B,QAAQ,CAAC,QAAQ,IAAI,UAAU;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,EAAE,UAAU,GAAG,MAAM;IAC1C,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAE7C;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,UAAU;IAEnC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO;IAEpC;;;OAGG;IACH,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM;IAIzB;;;OAGG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;IAI5B;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAW/D;;;OAGG;IACH,SAAS,CAAC,kBAAkB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO;CAUpE"}
|
|
@@ -5,51 +5,38 @@ const id_provider_error_type_1 = require("../enumerations/id-provider-error-type
|
|
|
5
5
|
const id_provider_1 = require("../errors/id-provider");
|
|
6
6
|
/**
|
|
7
7
|
* Base class for ID providers with common utility methods.
|
|
8
|
+
*
|
|
9
|
+
* Subclasses must implement all abstract methods for their specific ID type.
|
|
10
|
+
* For providers where T = Uint8Array, see ByteIdProvider for a concrete base.
|
|
8
11
|
*/
|
|
9
12
|
class BaseIdProvider {
|
|
10
13
|
/**
|
|
11
|
-
* Convert an ID
|
|
12
|
-
* Default implementation
|
|
14
|
+
* Convert an ID to a string representation.
|
|
15
|
+
* Default implementation delegates to serialize().
|
|
13
16
|
*/
|
|
14
17
|
idToString(id) {
|
|
15
|
-
|
|
16
|
-
return this.serialize(id);
|
|
17
|
-
}
|
|
18
|
-
return String(id);
|
|
18
|
+
return this.serialize(this.toBytes(id));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Convert a string representation of an ID back to
|
|
22
|
-
* Default implementation delegates to
|
|
21
|
+
* Convert a string representation of an ID back to the native type.
|
|
22
|
+
* Default implementation delegates to deserialize().
|
|
23
23
|
*/
|
|
24
24
|
idFromString(str) {
|
|
25
|
-
return this.deserialize(str);
|
|
25
|
+
return this.fromBytes(this.deserialize(str));
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* Default implementation handles common types.
|
|
28
|
+
* Validate ID length matches expected byte length.
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
|
-
if (id
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
if (typeof id === 'string') {
|
|
36
|
-
return this.deserialize(id);
|
|
30
|
+
validateLength(id, context) {
|
|
31
|
+
if (id.length !== this.byteLength) {
|
|
32
|
+
throw new id_provider_1.IdProviderError(id_provider_error_type_1.IdProviderErrorType.InvalidLength, undefined, undefined, { context, expected: this.byteLength, actual: id.length });
|
|
37
33
|
}
|
|
38
|
-
// For other types, convert to string first then deserialize
|
|
39
|
-
return this.deserialize(String(id));
|
|
40
34
|
}
|
|
41
35
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
36
|
+
* Constant-time comparison for Uint8Array buffers.
|
|
37
|
+
* Utility method for subclasses to use in their equals() implementation.
|
|
44
38
|
*/
|
|
45
|
-
|
|
46
|
-
this.validateLength(bytes, 'BaseIdProvider.fromBytes');
|
|
47
|
-
return this.clone(bytes);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Constant-time comparison to prevent timing attacks.
|
|
51
|
-
*/
|
|
52
|
-
equals(a, b) {
|
|
39
|
+
constantTimeEquals(a, b) {
|
|
53
40
|
if (a.length !== b.length) {
|
|
54
41
|
return false;
|
|
55
42
|
}
|
|
@@ -59,20 +46,6 @@ class BaseIdProvider {
|
|
|
59
46
|
}
|
|
60
47
|
return diff === 0;
|
|
61
48
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Create a defensive copy of an ID.
|
|
64
|
-
*/
|
|
65
|
-
clone(id) {
|
|
66
|
-
return new Uint8Array(id);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Validate ID length matches expected byte length.
|
|
70
|
-
*/
|
|
71
|
-
validateLength(id, context) {
|
|
72
|
-
if (id.length !== this.byteLength) {
|
|
73
|
-
throw new id_provider_1.IdProviderError(id_provider_error_type_1.IdProviderErrorType.InvalidLength, undefined, undefined, { context, expected: this.byteLength, actual: id.length });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
49
|
}
|
|
77
50
|
exports.BaseIdProvider = BaseIdProvider;
|
|
78
51
|
//# sourceMappingURL=base-id-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-id-provider.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/lib/base-id-provider.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAC7E,uDAAwD;AAGxD
|
|
1
|
+
{"version":3,"file":"base-id-provider.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/lib/base-id-provider.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAC7E,uDAAwD;AAGxD;;;;;GAKG;AACH,MAAsB,cAAc;IA8BlC;;;OAGG;IACH,UAAU,CAAC,EAAK;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACO,cAAc,CAAC,EAAc,EAAE,OAAe;QACtD,IAAI,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;YAClC,MAAM,IAAI,6BAAe,CACvB,4CAAmB,CAAC,aAAa,EACjC,SAAS,EACT,SAAS,EACT,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,kBAAkB,CAAC,CAAa,EAAE,CAAa;QACvD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,CAAC;IACpB,CAAC;CACF;AA1ED,wCA0EC"}
|
package/src/lib/guid.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ export declare class GuidV4 implements IGuidV4 {
|
|
|
45
45
|
* Regex for validating full hex GUID format
|
|
46
46
|
*/
|
|
47
47
|
private static readonly FULL_HEX_PATTERN;
|
|
48
|
+
/**
|
|
49
|
+
* Type guard to check if a value is a Uint8Array
|
|
50
|
+
*/
|
|
51
|
+
private static isUint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if a value is a Buffer or Uint8Array
|
|
54
|
+
*/
|
|
55
|
+
private static isBufferLike;
|
|
48
56
|
/**
|
|
49
57
|
* Cached empty/nil GUID constant (all zeros)
|
|
50
58
|
*/
|
|
@@ -143,6 +151,14 @@ export declare class GuidV4 implements IGuidV4 {
|
|
|
143
151
|
* @returns A new GuidV4 instance
|
|
144
152
|
*/
|
|
145
153
|
static fromBuffer(buffer: Uint8Array): GuidV4;
|
|
154
|
+
/**
|
|
155
|
+
* Factory method to create a GUID from a raw Uint8Array.
|
|
156
|
+
* This is an explicit alias for fromBuffer(), provided for clarity when working
|
|
157
|
+
* with browser environments where Uint8Array is the native binary type.
|
|
158
|
+
* @param bytes The raw 16-byte Uint8Array
|
|
159
|
+
* @returns A new GuidV4 instance
|
|
160
|
+
*/
|
|
161
|
+
static fromUint8Array(bytes: Uint8Array): GuidV4;
|
|
146
162
|
/**
|
|
147
163
|
* Creates a namespace-based v3 GUID (MD5 hash).
|
|
148
164
|
* Use this for deterministic GUIDs based on a namespace and name.
|
package/src/lib/guid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guid.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/lib/guid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACb,MAAM,UAAU,CAAC;AAIlB,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,WAAW,GACX,YAAY,GACZ,UAAU,GACV,UAAU,GACV,aAAa,GACb,MAAM,GACN,UAAU,CAAC;AAEf;;;;;;;;;GASG;AACH,qBAAa,MAAO,YAAW,OAAO;IACpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAK5B;IAEX;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAEtC;IAEF;;OAEG;IACH,OAAO,CAAC,cAAc,CAAC,CAAc;IAErC;;OAEG;IACH,OAAO,CAAC,eAAe,CAAC,CAAe;IAEvC;;OAEG;IACH,O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55
55
|
* Regex for validating full hex GUID format
|
|
56
56
|
*/
|
|
57
57
|
static FULL_HEX_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
58
|
+
/**
|
|
59
|
+
* Type guard to check if a value is a Uint8Array
|
|
60
|
+
*/
|
|
61
|
+
static isUint8Array(value) {
|
|
62
|
+
return value instanceof Uint8Array;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Type guard to check if a value is a Buffer or Uint8Array
|
|
66
|
+
*/
|
|
67
|
+
static isBufferLike(value) {
|
|
68
|
+
return buffer_compat_1.Buffer.isBuffer(value) || GuidV4.isUint8Array(value);
|
|
69
|
+
}
|
|
58
70
|
/**
|
|
59
71
|
* Cached empty/nil GUID constant (all zeros)
|
|
60
72
|
*/
|
|
@@ -128,7 +140,14 @@ class GuidV4 {
|
|
|
128
140
|
// Convert to raw buffer
|
|
129
141
|
const buffer = GuidV4.toRawGuidBuffer(value);
|
|
130
142
|
// Validate against UUID standard (skip for boundary values)
|
|
131
|
-
|
|
143
|
+
let hexString;
|
|
144
|
+
if (GuidV4.isUint8Array(buffer) && !buffer_compat_1.Buffer.isBuffer(buffer)) {
|
|
145
|
+
hexString = Array.from(buffer).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
hexString = buffer.toString('hex');
|
|
149
|
+
}
|
|
150
|
+
const fullHex = GuidV4.toFullHexGuid(hexString);
|
|
132
151
|
const isBoundary = GuidV4.isBoundaryValue(fullHex);
|
|
133
152
|
if (!isBoundary && !uuid.validate(fullHex)) {
|
|
134
153
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid, expectedBrand, undefined, buffer);
|
|
@@ -307,6 +326,16 @@ class GuidV4 {
|
|
|
307
326
|
static fromBuffer(buffer) {
|
|
308
327
|
return new GuidV4(buffer);
|
|
309
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Factory method to create a GUID from a raw Uint8Array.
|
|
331
|
+
* This is an explicit alias for fromBuffer(), provided for clarity when working
|
|
332
|
+
* with browser environments where Uint8Array is the native binary type.
|
|
333
|
+
* @param bytes The raw 16-byte Uint8Array
|
|
334
|
+
* @returns A new GuidV4 instance
|
|
335
|
+
*/
|
|
336
|
+
static fromUint8Array(bytes) {
|
|
337
|
+
return new GuidV4(bytes);
|
|
338
|
+
}
|
|
310
339
|
/**
|
|
311
340
|
* Creates a namespace-based v3 GUID (MD5 hash).
|
|
312
341
|
* Use this for deterministic GUIDs based on a namespace and name.
|
|
@@ -373,7 +402,14 @@ class GuidV4 {
|
|
|
373
402
|
*/
|
|
374
403
|
get asFullHexGuid() {
|
|
375
404
|
if (!this._cachedFullHex) {
|
|
376
|
-
|
|
405
|
+
let hexString;
|
|
406
|
+
if (GuidV4.isUint8Array(this._value) && !buffer_compat_1.Buffer.isBuffer(this._value)) {
|
|
407
|
+
hexString = Array.from(this._value).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
hexString = this._value.toString('hex');
|
|
411
|
+
}
|
|
412
|
+
this._cachedFullHex = GuidV4.toFullHexGuid(hexString);
|
|
377
413
|
}
|
|
378
414
|
return this._cachedFullHex;
|
|
379
415
|
}
|
|
@@ -554,7 +590,7 @@ class GuidV4 {
|
|
|
554
590
|
if (typeof value === 'bigint') {
|
|
555
591
|
valueLength = value.toString(16).length;
|
|
556
592
|
}
|
|
557
|
-
else if (
|
|
593
|
+
else if (GuidV4.isBufferLike(value)) {
|
|
558
594
|
valueLength = value.length;
|
|
559
595
|
}
|
|
560
596
|
else {
|
|
@@ -564,7 +600,14 @@ class GuidV4 {
|
|
|
564
600
|
if (result) {
|
|
565
601
|
try {
|
|
566
602
|
const fromBase64 = GuidV4.toRawGuidBuffer(value);
|
|
567
|
-
|
|
603
|
+
let hexString;
|
|
604
|
+
if (GuidV4.isUint8Array(fromBase64) && !buffer_compat_1.Buffer.isBuffer(fromBase64)) {
|
|
605
|
+
hexString = Array.from(fromBase64).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
hexString = fromBase64.toString('hex');
|
|
609
|
+
}
|
|
610
|
+
const fullHexGuid = GuidV4.toFullHexGuid(hexString);
|
|
568
611
|
// Boundary values are always valid
|
|
569
612
|
if (GuidV4.isBoundaryValue(fullHexGuid)) {
|
|
570
613
|
return true;
|
|
@@ -596,7 +639,7 @@ class GuidV4 {
|
|
|
596
639
|
if (typeof value === 'bigint') {
|
|
597
640
|
valueLength = value.toString(16).length;
|
|
598
641
|
}
|
|
599
|
-
else if (
|
|
642
|
+
else if (GuidV4.isBufferLike(value)) {
|
|
600
643
|
valueLength = value.length;
|
|
601
644
|
}
|
|
602
645
|
else {
|
|
@@ -606,10 +649,17 @@ class GuidV4 {
|
|
|
606
649
|
return false;
|
|
607
650
|
}
|
|
608
651
|
try {
|
|
609
|
-
if (!
|
|
652
|
+
if (!GuidV4.isBufferLike(value)) {
|
|
610
653
|
return false;
|
|
611
654
|
}
|
|
612
|
-
|
|
655
|
+
let hexString;
|
|
656
|
+
if (GuidV4.isUint8Array(value) && !buffer_compat_1.Buffer.isBuffer(value)) {
|
|
657
|
+
hexString = Array.from(value).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
hexString = value.toString('hex');
|
|
661
|
+
}
|
|
662
|
+
const fullHexGuid = GuidV4.toFullHexGuid(hexString);
|
|
613
663
|
// Boundary values are always valid
|
|
614
664
|
if (GuidV4.isBoundaryValue(fullHexGuid)) {
|
|
615
665
|
return true;
|
|
@@ -668,7 +718,7 @@ class GuidV4 {
|
|
|
668
718
|
if (typeof value === 'bigint') {
|
|
669
719
|
return guid_brand_type_1.GuidBrandType.BigIntGuid;
|
|
670
720
|
}
|
|
671
|
-
const isBuffer =
|
|
721
|
+
const isBuffer = GuidV4.isBufferLike(value);
|
|
672
722
|
const expectedLength = isBuffer ? value.length : String(value).length;
|
|
673
723
|
return GuidV4.lengthToGuidBrand(expectedLength, isBuffer);
|
|
674
724
|
}
|
|
@@ -694,12 +744,19 @@ class GuidV4 {
|
|
|
694
744
|
if (typeof guid === 'bigint') {
|
|
695
745
|
return GuidV4.toFullHexFromBigInt(guid);
|
|
696
746
|
}
|
|
697
|
-
else if (
|
|
747
|
+
else if (GuidV4.isBufferLike(guid) &&
|
|
698
748
|
guid.length === GuidV4.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidBuffer)) {
|
|
699
|
-
|
|
749
|
+
let hexString;
|
|
750
|
+
if (GuidV4.isUint8Array(guid) && !buffer_compat_1.Buffer.isBuffer(guid)) {
|
|
751
|
+
hexString = Array.from(guid).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
hexString = guid.toString('hex');
|
|
755
|
+
}
|
|
756
|
+
const shortHex = hexString;
|
|
700
757
|
return GuidV4.shortGuidToFullGuid(shortHex);
|
|
701
758
|
}
|
|
702
|
-
else if (
|
|
759
|
+
else if (GuidV4.isBufferLike(guid)) {
|
|
703
760
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
704
761
|
}
|
|
705
762
|
// all remaining cases are string types
|
|
@@ -729,11 +786,16 @@ class GuidV4 {
|
|
|
729
786
|
const fullHex = GuidV4.toFullHexFromBigInt(guid);
|
|
730
787
|
return fullHex.replace(/-/g, '');
|
|
731
788
|
}
|
|
732
|
-
else if (
|
|
789
|
+
else if (GuidV4.isBufferLike(guid) &&
|
|
733
790
|
guid.length === GuidV4.guidBrandToLength(guid_brand_type_1.GuidBrandType.RawGuidBuffer)) {
|
|
734
|
-
|
|
791
|
+
if (GuidV4.isUint8Array(guid) && !buffer_compat_1.Buffer.isBuffer(guid)) {
|
|
792
|
+
return Array.from(guid).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
return guid.toString('hex');
|
|
796
|
+
}
|
|
735
797
|
}
|
|
736
|
-
else if (
|
|
798
|
+
else if (GuidV4.isBufferLike(guid)) {
|
|
737
799
|
throw new guid_1.GuidError(guid_error_type_1.GuidErrorType.InvalidGuid);
|
|
738
800
|
}
|
|
739
801
|
// all remaining cases are string types
|