@trustvc/trustvc 2.11.0 → 2.11.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.
@@ -21,24 +21,15 @@ const ENCRYPTION_PARAMETERS = Object.freeze({
21
21
  // Type 1 using the above params without compression
22
22
  });
23
23
  const generateEncryptionKey = /* @__PURE__ */ __name((keyLengthInBits = ENCRYPTION_PARAMETERS.keyLength) => {
24
- if (!Number.isInteger(keyLengthInBits) || ![128, 192, 256].includes(keyLengthInBits)) {
25
- throw new Error("keyLengthInBits must be one of 128, 192, or 256");
26
- }
27
24
  const encryptionKey = forge__default.default.random.getBytesSync(keyLengthInBits / 8);
28
25
  return forge__default.default.util.bytesToHex(encryptionKey);
29
26
  }, "generateEncryptionKey");
30
27
  const encodeDocument = /* @__PURE__ */ __name((document) => {
31
28
  const bytes = forge__default.default.util.encodeUtf8(document);
32
- const standard = forge__default.default.util.encode64(bytes);
33
- const s = standard.replace(/\+/g, "-").replace(/\//g, "_");
34
- const trim = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
35
- return trim ? s.slice(0, -trim) : s;
29
+ return forge__default.default.util.encode64(bytes);
36
30
  }, "encodeDocument");
37
31
  const decodeDocument = /* @__PURE__ */ __name((encoded) => {
38
- let normalized = encoded.replace(/-/g, "+").replace(/_/g, "/");
39
- const pad = normalized.length % 4;
40
- if (pad) normalized += "=".repeat(4 - pad);
41
- const decoded = forge__default.default.util.decode64(normalized);
32
+ const decoded = forge__default.default.util.decode64(encoded);
42
33
  return forge__default.default.util.decodeUtf8(decoded);
43
34
  }, "decodeDocument");
44
35
  const {
@@ -16,24 +16,15 @@ const ENCRYPTION_PARAMETERS = Object.freeze({
16
16
  // Type 1 using the above params without compression
17
17
  });
18
18
  const generateEncryptionKey = /* @__PURE__ */ __name((keyLengthInBits = ENCRYPTION_PARAMETERS.keyLength) => {
19
- if (!Number.isInteger(keyLengthInBits) || ![128, 192, 256].includes(keyLengthInBits)) {
20
- throw new Error("keyLengthInBits must be one of 128, 192, or 256");
21
- }
22
19
  const encryptionKey = forge.random.getBytesSync(keyLengthInBits / 8);
23
20
  return forge.util.bytesToHex(encryptionKey);
24
21
  }, "generateEncryptionKey");
25
22
  const encodeDocument = /* @__PURE__ */ __name((document) => {
26
23
  const bytes = forge.util.encodeUtf8(document);
27
- const standard = forge.util.encode64(bytes);
28
- const s = standard.replace(/\+/g, "-").replace(/\//g, "_");
29
- const trim = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
30
- return trim ? s.slice(0, -trim) : s;
24
+ return forge.util.encode64(bytes);
31
25
  }, "encodeDocument");
32
26
  const decodeDocument = /* @__PURE__ */ __name((encoded) => {
33
- let normalized = encoded.replace(/-/g, "+").replace(/_/g, "/");
34
- const pad = normalized.length % 4;
35
- if (pad) normalized += "=".repeat(4 - pad);
36
- const decoded = forge.util.decode64(normalized);
27
+ const decoded = forge.util.decode64(encoded);
37
28
  return forge.util.decodeUtf8(decoded);
38
29
  }, "decodeDocument");
39
30
  const {
@@ -3,10 +3,10 @@ import '@tradetrust-tt/tradetrust';
3
3
  import '@tradetrust-tt/tradetrust/dist/types/shared/utils';
4
4
 
5
5
  /**
6
- * Encrypts a given string with symmetric AES-GCM.
7
- * @param {string} document - Input string to encrypt.
8
- * @param {string} [key] - Optional encryption key in hexadecimal (64 chars for 256-bit). If omitted, a key is generated.
9
- * @returns {IEncryptionResults} Object with cipherText (base64), iv (base64), tag (base64), key (hex), and type.
6
+ * Encrypts a given string with symmetric AES
7
+ * @param {string} document Input string to encrypt
8
+ * @param {string} [key] Optional encryption key in hexadecimal; generated if omitted
9
+ * @returns {IEncryptionResults} Object with cipherText (base64), iv (base64), tag (base64), key (hex), and type (algorithm identifier)
10
10
  */
11
11
  declare const encryptString: (document: string, key?: string) => IEncryptionResults;
12
12
 
@@ -19,23 +19,21 @@ declare const ENCRYPTION_PARAMETERS: Readonly<{
19
19
  readonly version: "OPEN-ATTESTATION-TYPE-1";
20
20
  }>;
21
21
  /**
22
- * Generates a random key represented as a hexadecimal string.
23
- * @param {number} [keyLengthInBits] - Key length in bits.
24
- * @returns {string} Hexadecimal-encoded encryption key.
22
+ * Generates a random key represented as a hexadecimal string
23
+ * @param {number} keyLengthInBits Key length in bits
24
+ * @returns {string} Encryption key as hexadecimal string
25
25
  */
26
- declare const generateEncryptionKey: (keyLengthInBits?: number) => string;
26
+ declare const generateEncryptionKey: (keyLengthInBits?: 256) => string;
27
27
  /**
28
- * Encode document string to URL-safe base64 (base64url: UTF-8 then base64 with +→-, /→_, no padding).
29
- * Safe for use in query strings and JSON without further encoding.
30
- * @param {string} document - Plain text document to encode.
31
- * @returns {string} Base64url-encoded string.
28
+ * Encode document string to base64 (UTF-8 then base64).
29
+ * @param {string} document UTF-8 document string to encode
30
+ * @returns {string} Base64-encoded document
32
31
  */
33
32
  declare const encodeDocument: (document: string) => string;
34
33
  /**
35
- * Decode base64url-encoded document string back to UTF-8.
36
- * Accepts both base64url (no padding, - and _) and standard base64 for backwards compatibility.
37
- * @param {string} encoded - Base64- or base64url-encoded string to decode.
38
- * @returns {string} Decoded UTF-8 plain text.
34
+ * Decode base64-encoded document string back to UTF-8.
35
+ * @param {string} encoded Base64-encoded document string
36
+ * @returns {string} Decoded UTF-8 document string
39
37
  */
40
38
  declare const decodeDocument: (encoded: string) => string;
41
39
  declare const isTransferableAsset: (document: any) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "2.11.0",
3
+ "version": "2.11.1",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",