gdc-common-utils-ts 1.0.4 → 1.0.7
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/AesManager.d.ts +27 -0
- package/dist/AesManager.js +62 -0
- package/dist/CryptographyService.d.ts +76 -0
- package/dist/CryptographyService.js +403 -0
- package/dist/constants/Schemas.d.ts +45 -0
- package/dist/constants/Schemas.js +48 -0
- package/dist/constants/index.js +1 -0
- package/{src/constants/schemaorg.ts → dist/constants/schemaorg.d.ts} +24 -116
- package/dist/constants/schemaorg.js +185 -0
- package/dist/cryptoDecode.d.ts +3 -0
- package/dist/cryptoDecode.js +90 -0
- package/dist/cryptoEncode.d.ts +1 -0
- package/dist/cryptoEncode.js +30 -0
- package/dist/cryptography.abstract.d.ts +13 -0
- package/{src/cryptography.abstract.ts → dist/cryptography.abstract.js} +6 -14
- package/dist/hmac.d.ts +2 -0
- package/{src/hmac.ts → dist/hmac.js} +4 -7
- package/dist/index.js +3 -0
- package/{src/interfaces/Cryptography.types.ts → dist/interfaces/Cryptography.types.d.ts} +71 -71
- package/dist/interfaces/Cryptography.types.js +8 -0
- package/dist/interfaces/ICryptoHelper.d.ts +28 -0
- package/dist/interfaces/ICryptoHelper.js +3 -0
- package/dist/interfaces/ICryptography.d.ts +154 -0
- package/dist/interfaces/ICryptography.js +3 -0
- package/dist/interfaces/IWallet.d.ts +55 -0
- package/dist/interfaces/IWallet.js +3 -0
- package/dist/interfaces/MlDsa.d.ts +9 -0
- package/{src/interfaces/MlDsa.ts → dist/interfaces/MlDsa.js} +1 -5
- package/dist/interfaces/MlKem.d.ts +11 -0
- package/{src/interfaces/MlKem.ts → dist/interfaces/MlKem.js} +0 -5
- package/dist/models/aes.d.ts +85 -0
- package/dist/models/aes.js +10 -0
- package/dist/models/auth.d.ts +35 -0
- package/dist/models/auth.js +3 -0
- package/{src/models/bundle.ts → dist/models/bundle.d.ts} +41 -63
- package/dist/models/bundle.js +26 -0
- package/dist/models/clinical-sections.d.ts +36 -0
- package/dist/models/clinical-sections.en.d.ts +75 -0
- package/dist/models/clinical-sections.en.js +81 -0
- package/dist/models/clinical-sections.js +32 -0
- package/dist/models/comm.d.ts +44 -0
- package/dist/models/comm.js +4 -0
- package/{src/models/confidential-job.ts → dist/models/confidential-job.d.ts} +23 -45
- package/dist/models/confidential-job.js +20 -0
- package/dist/models/confidential-message.d.ts +97 -0
- package/dist/models/confidential-message.js +4 -0
- package/{src/models/confidential-storage.ts → dist/models/confidential-storage.d.ts} +35 -56
- package/dist/models/confidential-storage.js +3 -0
- package/{src/models/consent-rule.ts → dist/models/consent-rule.d.ts} +22 -42
- package/dist/models/consent-rule.js +21 -0
- package/{src/models/crypto.ts → dist/models/crypto.d.ts} +5 -13
- package/dist/models/crypto.js +3 -0
- package/dist/models/device-license.d.ts +133 -0
- package/dist/models/device-license.js +3 -0
- package/{src/models/did.ts → dist/models/did.d.ts} +21 -30
- package/dist/models/did.js +3 -0
- package/dist/models/index.js +31 -0
- package/dist/models/indexing.d.ts +11 -0
- package/dist/models/indexing.js +18 -0
- package/dist/models/issue.d.ts +57 -0
- package/dist/models/issue.js +75 -0
- package/dist/models/jsonapi.d.ts +13 -0
- package/dist/models/jsonapi.js +3 -0
- package/{src/models/jwe.ts → dist/models/jwe.d.ts} +10 -22
- package/dist/models/jwe.js +3 -0
- package/{src/models/jwk.ts → dist/models/jwk.d.ts} +0 -11
- package/dist/models/jwk.js +3 -0
- package/{src/models/jws.ts → dist/models/jws.d.ts} +0 -7
- package/dist/models/jws.js +3 -0
- package/dist/models/jwt.d.ts +9 -0
- package/dist/models/jwt.js +3 -0
- package/dist/models/multibase58.d.ts +13 -0
- package/dist/models/multibase58.js +40 -0
- package/dist/models/oidc4ida.common.model.d.ts +33 -0
- package/dist/models/oidc4ida.common.model.js +3 -0
- package/dist/models/oidc4ida.document.model.d.ts +50 -0
- package/dist/models/oidc4ida.document.model.js +3 -0
- package/{src/models/oidc4ida.electronicRecord.model.ts → dist/models/oidc4ida.electronicRecord.model.d.ts} +18 -37
- package/dist/models/oidc4ida.electronicRecord.model.js +3 -0
- package/{src/models/oidc4ida.evidence.model.ts → dist/models/oidc4ida.evidence.model.d.ts} +17 -35
- package/dist/models/oidc4ida.evidence.model.js +5 -0
- package/dist/models/openid-device.d.ts +119 -0
- package/dist/models/openid-device.js +3 -0
- package/dist/models/operation-outcome.d.ts +26 -0
- package/dist/models/operation-outcome.js +3 -0
- package/{src/models/params.ts → dist/models/params.d.ts} +20 -29
- package/dist/models/params.js +3 -0
- package/dist/models/resource-document.d.ts +14 -0
- package/dist/models/resource-document.js +3 -0
- package/dist/models/response.d.ts +1 -0
- package/dist/models/response.js +3 -0
- package/dist/models/urlPath.d.ts +58 -0
- package/dist/models/urlPath.js +76 -0
- package/dist/models/verifiable-credential.d.ts +45 -0
- package/dist/models/verifiable-credential.js +8 -0
- package/dist/utils/actor.d.ts +18 -0
- package/dist/utils/actor.js +36 -0
- package/dist/utils/base-convert.d.ts +20 -0
- package/{src/utils/base-convert.ts → dist/utils/base-convert.js} +23 -36
- package/dist/utils/baseN.d.ts +35 -0
- package/dist/utils/baseN.js +174 -0
- package/dist/utils/bundle.d.ts +6 -0
- package/dist/utils/bundle.js +32 -0
- package/dist/utils/content.d.ts +55 -0
- package/{src/utils/content.ts → dist/utils/content.js} +4 -10
- package/dist/utils/did.d.ts +67 -0
- package/dist/utils/did.js +123 -0
- package/dist/utils/format-converter.d.ts +21 -0
- package/dist/utils/format-converter.js +109 -0
- package/dist/utils/index.js +13 -0
- package/dist/utils/jwt.d.ts +52 -0
- package/dist/utils/jwt.js +153 -0
- package/dist/utils/manager-error.d.ts +15 -0
- package/dist/utils/manager-error.js +23 -0
- package/dist/utils/multibase58.d.ts +13 -0
- package/dist/utils/multibase58.js +40 -0
- package/dist/utils/multibasehash.d.ts +8 -0
- package/{src/utils/multibasehash.ts → dist/utils/multibasehash.js} +8 -13
- package/dist/utils/normalize.d.ts +16 -0
- package/{src/utils/normalize.ts → dist/utils/normalize.js} +15 -18
- package/dist/utils/object-convert.d.ts +20 -0
- package/{src/utils/object-convert.ts → dist/utils/object-convert.js} +10 -16
- package/dist/utils/string-convert.d.ts +24 -0
- package/{src/utils/string-convert.ts → dist/utils/string-convert.js} +5 -14
- package/dist/utils/string-utils.d.ts +25 -0
- package/{src/utils/string-utils.ts → dist/utils/string-utils.js} +12 -16
- package/dist/utils/url.d.ts +27 -0
- package/{src/utils/url.ts → dist/utils/url.js} +6 -7
- package/package.json +56 -14
- package/PUBLISHING.md +0 -33
- package/__tests__/AesManager.test.ts +0 -53
- package/__tests__/CryptographyService.test.ts +0 -194
- package/__tests__/bundle.test.ts +0 -29
- package/__tests__/content.test.ts +0 -72
- package/__tests__/crypto-encode-decode.test.ts +0 -52
- package/__tests__/crypto-hmac.test.ts +0 -21
- package/__tests__/did-generateServiceId.errors.test.ts +0 -8
- package/__tests__/did-generateServiceId.test.ts +0 -18
- package/__tests__/models-clinical-sections.test.ts +0 -32
- package/__tests__/models-multibase58.test.ts +0 -33
- package/__tests__/multibase58.errors.test.ts +0 -7
- package/__tests__/multibase58.test.ts +0 -28
- package/__tests__/multibasehash.test.ts +0 -25
- package/__tests__/utils-actor.test.ts +0 -46
- package/__tests__/utils-base-convert.test.ts +0 -57
- package/__tests__/utils-baseN.test.ts +0 -40
- package/__tests__/utils-did-extra.test.ts +0 -33
- package/__tests__/utils-format-converter.test.ts +0 -87
- package/__tests__/utils-jwt.test.ts +0 -57
- package/__tests__/utils-manager-error.test.ts +0 -11
- package/__tests__/utils-normalize.test.ts +0 -15
- package/__tests__/utils-object-convert.test.ts +0 -38
- package/__tests__/utils-string-convert.test.ts +0 -20
- package/__tests__/utils-string-utils.test.ts +0 -25
- package/__tests__/utils-url.test.ts +0 -21
- package/babel.config.cjs +0 -5
- package/jest.config.ts +0 -47
- package/src/AesManager.ts +0 -82
- package/src/CryptographyService.ts +0 -461
- package/src/JweManager.ts.txt +0 -365
- package/src/KmsService.txt +0 -493
- package/src/constants/Schemas.ts +0 -61
- package/src/cryptoDecode.ts +0 -104
- package/src/cryptoEncode.ts +0 -36
- package/src/interfaces/ICryptoHelper.ts +0 -33
- package/src/interfaces/ICryptography.ts +0 -177
- package/src/interfaces/IWallet.ts +0 -62
- package/src/models/aes.ts +0 -93
- package/src/models/auth.ts +0 -38
- package/src/models/bundle.txt +0 -93
- package/src/models/clinical-sections.en.ts +0 -82
- package/src/models/clinical-sections.ts +0 -64
- package/src/models/comm.ts +0 -63
- package/src/models/confidential-message.ts +0 -137
- package/src/models/device-license.ts +0 -161
- package/src/models/indexing.ts +0 -20
- package/src/models/issue.ts +0 -85
- package/src/models/jsonapi.ts +0 -19
- package/src/models/jwt.ts +0 -15
- package/src/models/multibase58.ts +0 -46
- package/src/models/oidc4ida.common.model.ts +0 -39
- package/src/models/oidc4ida.document.model.ts +0 -61
- package/src/models/openid-device.ts +0 -146
- package/src/models/operation-outcome.ts +0 -34
- package/src/models/resource-document.ts +0 -21
- package/src/models/response.ts +0 -5
- package/src/models/urlPath.ts +0 -76
- package/src/models/verifiable-credential.ts +0 -52
- package/src/types/noble-hashes.d.ts +0 -4
- package/src/utils/actor.ts +0 -56
- package/src/utils/baseN.ts +0 -203
- package/src/utils/bundle.ts +0 -30
- package/src/utils/did.ts +0 -155
- package/src/utils/format-converter.ts +0 -119
- package/src/utils/jwt.ts +0 -165
- package/src/utils/manager-error.ts +0 -27
- package/src/utils/multibase58.ts +0 -46
- package/tsconfig.json +0 -15
- /package/{src/constants/index.ts → dist/constants/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/models/index.ts → dist/models/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
// Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
|
|
2
2
|
// File: crypto-ts/utils/normalize.ts
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Creates a stable, serialized JSON string from an object by sorting its keys alphabetically.
|
|
6
5
|
* This is the core function for achieving canonical serialization.
|
|
7
6
|
* @param obj The object to serialize.
|
|
8
7
|
* @returns A stable JSON string.
|
|
9
8
|
*/
|
|
10
|
-
function stableStringify(obj
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
function stableStringify(obj) {
|
|
10
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
11
|
+
const sortedObject = {};
|
|
12
|
+
for (const key of sortedKeys) {
|
|
13
|
+
sortedObject[key] = obj[key];
|
|
14
|
+
}
|
|
15
|
+
return JSON.stringify(sortedObject);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* Normalizes an object for hashing by excluding a standard set of volatile properties.
|
|
21
19
|
* This function is based on the original `normalizeAndSerializeObject` from the backend utils.
|
|
@@ -23,13 +21,12 @@ function stableStringify(obj: object): string {
|
|
|
23
21
|
* @param obj The object to normalize.
|
|
24
22
|
* @returns A stable, canonical JSON string of the object's core properties.
|
|
25
23
|
*/
|
|
26
|
-
export function normalizeObject(obj
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
export function normalizeObject(obj) {
|
|
25
|
+
// Exclude properties that are often volatile or client-specific
|
|
26
|
+
// and should not be part of the core content hash.
|
|
27
|
+
const { id, meta, text, contained, ...coreContent } = obj;
|
|
28
|
+
return stableStringify(coreContent);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
/**
|
|
34
31
|
* Normalizes a DIDComm payload specifically for generating the `payload.id` (version hash).
|
|
35
32
|
* According to the defined architecture, this specifically excludes `id` and `meta`.
|
|
@@ -37,7 +34,7 @@ export function normalizeObject(obj: object): string {
|
|
|
37
34
|
* @param payload The DIDComm payload object.
|
|
38
35
|
* @returns A stable JSON string representation of the payload's core content.
|
|
39
36
|
*/
|
|
40
|
-
export function normalizeDidcommPayloadForId(payload
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
export function normalizeDidcommPayloadForId(payload) {
|
|
38
|
+
const { id, meta, ...coreContent } = payload;
|
|
39
|
+
return stableStringify(coreContent);
|
|
43
40
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Compares two arrays and returns true if they are the same, false otherwise. */
|
|
2
|
+
export declare function arrayCompare(a: any[], b: any[]): boolean;
|
|
3
|
+
/** Merges two Uint8Arrays into a single Uint8Array. */
|
|
4
|
+
export declare function arrayMerge(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
5
|
+
/**
|
|
6
|
+
* Serializes a JavaScript object to a Uint8Array of UTF-8 bytes.
|
|
7
|
+
* NOTE: This does not perform canonicalization (sorting keys).
|
|
8
|
+
*/
|
|
9
|
+
export declare function objectToBytes(data: object): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Serializes a JavaScript object to a raw Base64URL string.
|
|
12
|
+
* NOTE: This does not perform canonicalization (sorting keys).
|
|
13
|
+
*/
|
|
14
|
+
export declare function objectToRawBase64UrlSafe(data: object): string;
|
|
15
|
+
/**
|
|
16
|
+
* Deserializes a Base64URL string back into a JavaScript object.
|
|
17
|
+
* @param base64UrlSafe The Base64URL encoded JSON string.
|
|
18
|
+
* @returns A JavaScript object.
|
|
19
|
+
*/
|
|
20
|
+
export declare function base64UrlSafeToJSON(base64UrlSafe: string | undefined): object;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// crypto-ts/utils/object-convert.ts
|
|
2
|
-
|
|
3
2
|
import { decodeURLSafe } from "@stablelib/base64";
|
|
4
|
-
import { bytesToStringUTF8, stringToBytesUTF8 } from './string-convert';
|
|
5
|
-
import { bytesToRawBase64UrlSafe } from './base-convert';
|
|
6
|
-
|
|
3
|
+
import { bytesToStringUTF8, stringToBytesUTF8 } from './string-convert.js';
|
|
4
|
+
import { bytesToRawBase64UrlSafe } from './base-convert.js';
|
|
7
5
|
/** Compares two arrays and returns true if they are the same, false otherwise. */
|
|
8
|
-
export function arrayCompare(a
|
|
6
|
+
export function arrayCompare(a, b) {
|
|
9
7
|
if (a.length !== b.length) {
|
|
10
8
|
return false;
|
|
11
9
|
}
|
|
@@ -16,42 +14,38 @@ export function arrayCompare(a: any[], b: any[]): boolean {
|
|
|
16
14
|
}
|
|
17
15
|
return true;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
/** Merges two Uint8Arrays into a single Uint8Array. */
|
|
21
|
-
export function arrayMerge(a
|
|
18
|
+
export function arrayMerge(a, b) {
|
|
22
19
|
const mergedArray = new Uint8Array(a.length + b.length);
|
|
23
20
|
mergedArray.set(a);
|
|
24
21
|
mergedArray.set(b, a.length);
|
|
25
22
|
return mergedArray;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* Serializes a JavaScript object to a Uint8Array of UTF-8 bytes.
|
|
30
26
|
* NOTE: This does not perform canonicalization (sorting keys).
|
|
31
27
|
*/
|
|
32
|
-
export function objectToBytes(data
|
|
28
|
+
export function objectToBytes(data) {
|
|
33
29
|
return stringToBytesUTF8(JSON.stringify(data));
|
|
34
|
-
}
|
|
35
|
-
|
|
30
|
+
}
|
|
31
|
+
;
|
|
36
32
|
/**
|
|
37
33
|
* Serializes a JavaScript object to a raw Base64URL string.
|
|
38
34
|
* NOTE: This does not perform canonicalization (sorting keys).
|
|
39
35
|
*/
|
|
40
|
-
export function objectToRawBase64UrlSafe(data
|
|
36
|
+
export function objectToRawBase64UrlSafe(data) {
|
|
41
37
|
const dataBytes = objectToBytes(data);
|
|
42
38
|
return bytesToRawBase64UrlSafe(dataBytes);
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
/**
|
|
46
41
|
* Deserializes a Base64URL string back into a JavaScript object.
|
|
47
42
|
* @param base64UrlSafe The Base64URL encoded JSON string.
|
|
48
43
|
* @returns A JavaScript object.
|
|
49
44
|
*/
|
|
50
|
-
export function base64UrlSafeToJSON(base64UrlSafe
|
|
45
|
+
export function base64UrlSafeToJSON(base64UrlSafe) {
|
|
51
46
|
if (!base64UrlSafe) {
|
|
52
47
|
throw new Error("Input string is undefined.");
|
|
53
48
|
}
|
|
54
|
-
const dataBytes
|
|
49
|
+
const dataBytes = decodeURLSafe(base64UrlSafe);
|
|
55
50
|
return JSON.parse(bytesToStringUTF8(dataBytes));
|
|
56
51
|
}
|
|
57
|
-
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a standard JavaScript string into a Uint8Array of strictly-validated UTF-8 bytes.
|
|
3
|
+
* This is the standard and safest method for serializing text data.
|
|
4
|
+
* @param str The string to convert.
|
|
5
|
+
* @returns A Uint8Array.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stringToBytesUTF8(str: string): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Decodes a Uint8Array of strictly-validated UTF-8 bytes back into a string.
|
|
10
|
+
* This will fail if the byte array does not represent valid UTF-8.
|
|
11
|
+
* Use this for standard text and JSON.
|
|
12
|
+
* @param array The UTF-8 byte array to convert.
|
|
13
|
+
* @returns A string.
|
|
14
|
+
*/
|
|
15
|
+
export declare function bytesToStringUTF8(array: Uint8Array): string;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a Uint8Array containing binary data into a string by processing
|
|
18
|
+
* each byte individually. This is more permissive than `bytesToStringUTF8` and is
|
|
19
|
+
* specifically required for handling payloads from libraries (e.g., pako) that
|
|
20
|
+
* may not be strictly UTF-8. Use this for decoding JWT payloads.
|
|
21
|
+
* @param array The binary/ASCII byte array to convert.
|
|
22
|
+
* @returns A string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function bytesToStringASCII(array: Uint8Array): string;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
// crypto-ts/utils/string-convert.ts
|
|
2
|
-
|
|
3
2
|
import { encode as encodeUTF8, decode as decodeUTF8 } from "@stablelib/utf8";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Encodes a standard JavaScript string into a Uint8Array of strictly-validated UTF-8 bytes.
|
|
7
5
|
* This is the standard and safest method for serializing text data.
|
|
8
6
|
* @param str The string to convert.
|
|
9
7
|
* @returns A Uint8Array.
|
|
10
8
|
*/
|
|
11
|
-
export function stringToBytesUTF8(str
|
|
9
|
+
export function stringToBytesUTF8(str) {
|
|
12
10
|
return encodeUTF8(str);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* Decodes a Uint8Array of strictly-validated UTF-8 bytes back into a string.
|
|
17
14
|
* This will fail if the byte array does not represent valid UTF-8.
|
|
@@ -19,10 +16,9 @@ export function stringToBytesUTF8(str: string): Uint8Array {
|
|
|
19
16
|
* @param array The UTF-8 byte array to convert.
|
|
20
17
|
* @returns A string.
|
|
21
18
|
*/
|
|
22
|
-
export function bytesToStringUTF8(array
|
|
19
|
+
export function bytesToStringUTF8(array) {
|
|
23
20
|
return decodeUTF8(array);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
/**
|
|
27
23
|
* Decodes a Uint8Array containing binary data into a string by processing
|
|
28
24
|
* each byte individually. This is more permissive than `bytesToStringUTF8` and is
|
|
@@ -31,18 +27,15 @@ export function bytesToStringUTF8(array: Uint8Array): string {
|
|
|
31
27
|
* @param array The binary/ASCII byte array to convert.
|
|
32
28
|
* @returns A string.
|
|
33
29
|
*/
|
|
34
|
-
export function bytesToStringASCII(array
|
|
30
|
+
export function bytesToStringASCII(array) {
|
|
35
31
|
var out, i, len, c;
|
|
36
32
|
var char2, char3;
|
|
37
|
-
|
|
38
33
|
out = "";
|
|
39
34
|
len = array.length;
|
|
40
35
|
i = 0;
|
|
41
36
|
while (i < len) {
|
|
42
37
|
c = array[i++];
|
|
43
|
-
switch (
|
|
44
|
-
c >> 4
|
|
45
|
-
) {
|
|
38
|
+
switch (c >> 4) {
|
|
46
39
|
case 0:
|
|
47
40
|
case 1:
|
|
48
41
|
case 2:
|
|
@@ -61,9 +54,7 @@ export function bytesToStringASCII(array: Uint8Array): string {
|
|
|
61
54
|
case 14:
|
|
62
55
|
char2 = array[i++];
|
|
63
56
|
char3 = array[i++];
|
|
64
|
-
out += String.fromCharCode(
|
|
65
|
-
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
|
|
66
|
-
);
|
|
57
|
+
out += String.fromCharCode(((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0));
|
|
67
58
|
break;
|
|
68
59
|
}
|
|
69
60
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of a string.
|
|
3
|
+
* @param s The input string.
|
|
4
|
+
* @returns The capitalized string.
|
|
5
|
+
*/
|
|
6
|
+
export declare function capitalize(s: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* A simple string sanitizer that removes characters that are not alphanumeric or common punctuation.
|
|
9
|
+
* @param str The string to sanitize.
|
|
10
|
+
* @returns The sanitized string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeString(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a string to a string of its ASCII character codes.
|
|
15
|
+
* @param text The input string.
|
|
16
|
+
* @returns A string of character codes.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stringToASCII(text: any): string;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a string to an array of numbers representing its byte values.
|
|
21
|
+
* From google closure library: https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
22
|
+
* @param str The input string.
|
|
23
|
+
* @returns An array of numbers.
|
|
24
|
+
*/
|
|
25
|
+
export declare function stringToBytesArrayOfNumbers(str: string): number[];
|
|
@@ -1,66 +1,62 @@
|
|
|
1
1
|
// crypto-ts/utils/string-utils.ts
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Capitalizes the first letter of a string.
|
|
5
4
|
* @param s The input string.
|
|
6
5
|
* @returns The capitalized string.
|
|
7
6
|
*/
|
|
8
|
-
export function capitalize(s
|
|
7
|
+
export function capitalize(s) {
|
|
9
8
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* A simple string sanitizer that removes characters that are not alphanumeric or common punctuation.
|
|
14
12
|
* @param str The string to sanitize.
|
|
15
13
|
* @returns The sanitized string.
|
|
16
14
|
*/
|
|
17
|
-
export function sanitizeString(str
|
|
15
|
+
export function sanitizeString(str) {
|
|
18
16
|
str = str.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, "");
|
|
19
17
|
return str.trim();
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
/**
|
|
23
20
|
* Converts a string to a string of its ASCII character codes.
|
|
24
21
|
* @param text The input string.
|
|
25
22
|
* @returns A string of character codes.
|
|
26
23
|
*/
|
|
27
24
|
/* tslint:disable:forin */
|
|
28
|
-
export function stringToASCII(text
|
|
25
|
+
export function stringToASCII(text) {
|
|
29
26
|
let ascii = "";
|
|
30
27
|
for (const f in text) {
|
|
31
28
|
ascii = ascii + text.charCodeAt(f);
|
|
32
29
|
}
|
|
33
30
|
return ascii;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
/**
|
|
37
33
|
* Converts a string to an array of numbers representing its byte values.
|
|
38
34
|
* From google closure library: https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
39
35
|
* @param str The input string.
|
|
40
36
|
* @returns An array of numbers.
|
|
41
37
|
*/
|
|
42
|
-
export function stringToBytesArrayOfNumbers(str
|
|
43
|
-
let out = [],
|
|
44
|
-
p = 0;
|
|
38
|
+
export function stringToBytesArrayOfNumbers(str) {
|
|
39
|
+
let out = [], p = 0;
|
|
45
40
|
for (var i = 0; i < str.length; i++) {
|
|
46
41
|
var c = str.charCodeAt(i);
|
|
47
42
|
if (c < 128) {
|
|
48
43
|
out[p++] = c;
|
|
49
|
-
}
|
|
44
|
+
}
|
|
45
|
+
else if (c < 2048) {
|
|
50
46
|
out[p++] = (c >> 6) | 192;
|
|
51
47
|
out[p++] = (c & 63) | 128;
|
|
52
|
-
}
|
|
53
|
-
|
|
48
|
+
}
|
|
49
|
+
else if ((c & 0xfc00) == 0xd800 &&
|
|
54
50
|
i + 1 < str.length &&
|
|
55
|
-
(str.charCodeAt(i + 1) & 0xfc00) == 0xdc00
|
|
56
|
-
) {
|
|
51
|
+
(str.charCodeAt(i + 1) & 0xfc00) == 0xdc00) {
|
|
57
52
|
// Surrogate Pair
|
|
58
53
|
c = 0x10000 + ((c & 0x03ff) << 10) + (str.charCodeAt(++i) & 0x03ff);
|
|
59
54
|
out[p++] = (c >> 18) | 240;
|
|
60
55
|
out[p++] = ((c >> 12) & 63) | 128;
|
|
61
56
|
out[p++] = ((c >> 6) & 63) | 128;
|
|
62
57
|
out[p++] = (c & 63) | 128;
|
|
63
|
-
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
64
60
|
out[p++] = (c >> 12) | 224;
|
|
65
61
|
out[p++] = ((c >> 6) & 63) | 128;
|
|
66
62
|
out[p++] = (c & 63) | 128;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Join the base_url and path without adding extra slashes.
|
|
3
|
+
*
|
|
4
|
+
* @param base_url - The base URL.
|
|
5
|
+
* @param path - The path to be appended to the base URL.
|
|
6
|
+
* @returns The safely joined URL.
|
|
7
|
+
*/
|
|
8
|
+
export declare function safelyJoinUrl(base_url: string, path: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Splits a given URL into its domain and path components.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} urlString - The full URL string to be split.
|
|
13
|
+
* @returns {{ domain: string; path: string }} An object containing the `domain` and `path` of the URL.
|
|
14
|
+
* If the URL is not valid it returns empty domain and path.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Returns { domain: 'www.example.com', path: '/some/path' }
|
|
18
|
+
* const result = splitUrl('https://www.example.com/some/path?query=string');
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* Returns null for invalid URLs
|
|
22
|
+
* const result = splitUrl('invalid-url');
|
|
23
|
+
*/
|
|
24
|
+
export declare function splitUrl(urlString: string): {
|
|
25
|
+
domain: string;
|
|
26
|
+
path: string;
|
|
27
|
+
} | null;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// crypto-ts/utils/url.ts
|
|
2
2
|
// Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Join the base_url and path without adding extra slashes.
|
|
6
|
-
*
|
|
5
|
+
*
|
|
7
6
|
* @param base_url - The base URL.
|
|
8
7
|
* @param path - The path to be appended to the base URL.
|
|
9
8
|
* @returns The safely joined URL.
|
|
10
9
|
*/
|
|
11
|
-
export function safelyJoinUrl(base_url
|
|
10
|
+
export function safelyJoinUrl(base_url, path) {
|
|
12
11
|
// Remove trailing slash from base_url if it exists
|
|
13
12
|
if (base_url.endsWith('/')) {
|
|
14
13
|
base_url = base_url.substring(0, base_url.length - 1);
|
|
@@ -19,7 +18,6 @@ export function safelyJoinUrl(base_url: string, path: string): string {
|
|
|
19
18
|
}
|
|
20
19
|
return `${base_url}/${path}`;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
/**
|
|
24
22
|
* Splits a given URL into its domain and path components.
|
|
25
23
|
*
|
|
@@ -35,12 +33,13 @@ export function safelyJoinUrl(base_url: string, path: string): string {
|
|
|
35
33
|
* Returns null for invalid URLs
|
|
36
34
|
* const result = splitUrl('invalid-url');
|
|
37
35
|
*/
|
|
38
|
-
export function splitUrl(urlString
|
|
36
|
+
export function splitUrl(urlString) {
|
|
39
37
|
try {
|
|
40
38
|
const url = new URL(urlString);
|
|
41
39
|
return { domain: url.hostname, path: url.pathname };
|
|
42
|
-
}
|
|
43
|
-
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error("Invalid URL provided:", error.message);
|
|
44
43
|
}
|
|
45
44
|
return null;
|
|
46
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdc-common-utils-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -16,22 +16,64 @@
|
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"test:coverage": "jest --coverage",
|
|
18
18
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
19
|
-
"
|
|
19
|
+
"build": "tsc -p tsconfig.build.json && node patch-esm-imports.mjs",
|
|
20
|
+
"prepublishOnly": "npm run typecheck && npm test -- --watchman=false && npm run build"
|
|
20
21
|
},
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
21
24
|
"exports": {
|
|
22
|
-
".":
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"./
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./AesManager": {
|
|
30
|
+
"types": "./dist/AesManager.d.ts",
|
|
31
|
+
"default": "./dist/AesManager.js"
|
|
32
|
+
},
|
|
33
|
+
"./CryptographyService": {
|
|
34
|
+
"types": "./dist/CryptographyService.d.ts",
|
|
35
|
+
"default": "./dist/CryptographyService.js"
|
|
36
|
+
},
|
|
37
|
+
"./hmac": {
|
|
38
|
+
"types": "./dist/hmac.d.ts",
|
|
39
|
+
"default": "./dist/hmac.js"
|
|
40
|
+
},
|
|
41
|
+
"./constants/*": {
|
|
42
|
+
"types": "./dist/constants/*.d.ts",
|
|
43
|
+
"default": "./dist/constants/*.js"
|
|
44
|
+
},
|
|
45
|
+
"./models/*": {
|
|
46
|
+
"types": "./dist/models/*.d.ts",
|
|
47
|
+
"default": "./dist/models/*.js"
|
|
48
|
+
},
|
|
49
|
+
"./utils/*": {
|
|
50
|
+
"types": "./dist/utils/*.d.ts",
|
|
51
|
+
"default": "./dist/utils/*.js"
|
|
52
|
+
},
|
|
53
|
+
"./interfaces/*": {
|
|
54
|
+
"types": "./dist/interfaces/*.d.ts",
|
|
55
|
+
"default": "./dist/interfaces/*.js"
|
|
56
|
+
},
|
|
57
|
+
"./constants": {
|
|
58
|
+
"types": "./dist/constants/index.d.ts",
|
|
59
|
+
"default": "./dist/constants/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./models": {
|
|
62
|
+
"types": "./dist/models/index.d.ts",
|
|
63
|
+
"default": "./dist/models/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./utils": {
|
|
66
|
+
"types": "./dist/utils/index.d.ts",
|
|
67
|
+
"default": "./dist/utils/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./interfaces": {
|
|
70
|
+
"types": "./dist/interfaces/index.d.ts",
|
|
71
|
+
"default": "./dist/interfaces/index.js"
|
|
72
|
+
}
|
|
34
73
|
},
|
|
74
|
+
"files": [
|
|
75
|
+
"dist"
|
|
76
|
+
],
|
|
35
77
|
"devDependencies": {
|
|
36
78
|
"@babel/preset-env": "^7.24.0",
|
|
37
79
|
"@types/jest": "^29.5.12",
|
package/PUBLISHING.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Publishing
|
|
2
|
-
|
|
3
|
-
This package is published as a public, unscoped package (`gdc-common-utils-ts`).
|
|
4
|
-
|
|
5
|
-
## NPM token
|
|
6
|
-
|
|
7
|
-
When creating a token in npmjs.com:
|
|
8
|
-
- `Packages and scopes` must be **Read and write**.
|
|
9
|
-
- `Organizations` permissions are **not required** for unscoped packages. Enable only if publishing under an org scope (`@org/`).
|
|
10
|
-
|
|
11
|
-
## Configure the token
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm config set //registry.npmjs.org/:_authToken=YOUR_TOKEN
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Verify:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm whoami
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Publish
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm publish --access public
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
If 2FA for publish is enabled, add an OTP:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
NPM_CONFIG_OTP=123456 npm publish --access public
|
|
33
|
-
```
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/__tests__/unit/security/AesManager.test.ts
|
|
2
|
-
// Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
|
|
3
|
-
|
|
4
|
-
import { jest } from '@jest/globals';
|
|
5
|
-
import { randomBytes } from 'crypto'; // Use Node.js native crypto module
|
|
6
|
-
import { ProtectedDataAES } from '../src/models/aes.js';
|
|
7
|
-
import { AesManager } from '../src/AesManager.js';
|
|
8
|
-
|
|
9
|
-
describe('AesManager', () => {
|
|
10
|
-
let aesManager: AesManager;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
aesManager = new AesManager();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should perform a round-trip (encrypt/decrypt) using base64url strings', async () => {
|
|
17
|
-
// --- 1. Arrange ---
|
|
18
|
-
const payload = { message: 'This is a secret message.', timestamp: Date.now() };
|
|
19
|
-
const plaintext = JSON.stringify(payload);
|
|
20
|
-
const cekBytes = randomBytes(32); // 256-bit Content Encryption Key
|
|
21
|
-
const aad = 'integrity-protected-data';
|
|
22
|
-
// --- 2. Act ---
|
|
23
|
-
// The public interface works with base64url strings, as required by JWE.
|
|
24
|
-
const encryptedData: ProtectedDataAES = await aesManager.encrypt(plaintext, cekBytes, aad);
|
|
25
|
-
|
|
26
|
-
// The result is then passed back to the decryption method.
|
|
27
|
-
const decryptedText = await aesManager.decrypt(encryptedData, cekBytes, aad);
|
|
28
|
-
const decryptedPayload = JSON.parse(decryptedText);
|
|
29
|
-
// --- 3. Assert ---
|
|
30
|
-
// The output of encrypt should be correctly formatted strings.
|
|
31
|
-
expect(typeof encryptedData.ciphertext).toBe('string');
|
|
32
|
-
expect(typeof encryptedData.iv).toBe('string');
|
|
33
|
-
expect(typeof encryptedData.tag).toBe('string');
|
|
34
|
-
|
|
35
|
-
// The final decrypted object must match the original payload.
|
|
36
|
-
expect(decryptedPayload).toEqual(payload);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should fail decryption if the AAD is tampered with', async () => {
|
|
40
|
-
// --- 1. Arrange ---
|
|
41
|
-
const plaintext = JSON.stringify({ data: 'secret' });
|
|
42
|
-
const cekBytes = randomBytes(32);
|
|
43
|
-
const originalAad = 'original_aad';
|
|
44
|
-
const tamperedAad = 'tampered_aad';
|
|
45
|
-
|
|
46
|
-
const encryptedData = await aesManager.encrypt(plaintext, cekBytes, originalAad);
|
|
47
|
-
// --- 2. Assert ---
|
|
48
|
-
// Expect decryption to fail when using the wrong AAD.
|
|
49
|
-
await expect(
|
|
50
|
-
aesManager.decrypt(encryptedData, cekBytes, tamperedAad)
|
|
51
|
-
).rejects.toThrow();
|
|
52
|
-
});
|
|
53
|
-
});
|