@dynamic-labs/utils 4.9.8 → 4.9.9

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/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
 
2
+ ### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * **global-wallet-client:** properly clean up the popup state when popup is closed ([#8379](https://github.com/dynamic-labs/dynamic-auth/issues/8379)) ([782963f](https://github.com/dynamic-labs/dynamic-auth/commit/782963f87fcb2658b921ff6cc6f22c63be9714fb))
8
+ * hanging promises when a starknet wallet is connected but locked ([#8376](https://github.com/dynamic-labs/dynamic-auth/issues/8376)) ([a753939](https://github.com/dynamic-labs/dynamic-auth/commit/a7539395d4653be49f000ae51d15347a176b5b6c))
9
+ * token balance list should respect sort from backend ([#8383](https://github.com/dynamic-labs/dynamic-auth/issues/8383)) ([1c3bef4](https://github.com/dynamic-labs/dynamic-auth/commit/1c3bef47dbfd319e2444368a4a503b0839b5ad4b))
10
+
11
+
12
+ * add message auth code to global wallet ([#8354](https://github.com/dynamic-labs/dynamic-auth/issues/8354)) ([c847bf8](https://github.com/dynamic-labs/dynamic-auth/commit/c847bf8d66db54534348622255997f30f4309542))
13
+
2
14
  ### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
3
15
 
4
16
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.9.8";
6
+ var version = "4.9.9";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.9.8";
2
+ var version = "4.9.9";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "4.9.8",
3
+ "version": "4.9.9",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -20,9 +20,9 @@
20
20
  "dependencies": {
21
21
  "@dynamic-labs/sdk-api-core": "0.0.644",
22
22
  "tldts": "6.0.16",
23
- "@dynamic-labs/assert-package-version": "4.9.8",
24
- "@dynamic-labs/logger": "4.9.8",
25
- "@dynamic-labs/types": "4.9.8",
23
+ "@dynamic-labs/assert-package-version": "4.9.9",
24
+ "@dynamic-labs/logger": "4.9.9",
25
+ "@dynamic-labs/types": "4.9.9",
26
26
  "buffer": "6.0.3",
27
27
  "eventemitter3": "5.0.1"
28
28
  },
@@ -11,16 +11,24 @@ var _tslib = require('../../../_virtual/_tslib.cjs');
11
11
  * @param sharedSecret - The shared secret key in hexadecimal format
12
12
  * @param message - The encrypted message in base64 format
13
13
  * @param iv - The initialization vector in hexadecimal format
14
+ * @param additionalData - Additional data to include in the decryption
14
15
  * @returns A Promise that resolves to the decrypted message as a string
15
16
  */
16
- const decryptMessage = (sharedSecret, message, iv) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
17
+ const decryptMessage = (sharedSecret, message, iv, additionalData) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
17
18
  var _a, _b;
18
19
  const decoder = new TextDecoder();
19
20
  const sharedSecretByteArray = new Uint8Array((_b = (_a = decodeURIComponent(sharedSecret)
20
21
  .match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map((byte) => parseInt(byte, 16))) !== null && _b !== void 0 ? _b : []);
21
22
  // Import the ArrayBuffer as a CryptoKey
22
23
  const sharedSecretCryptoKey = yield crypto.subtle.importKey('raw', sharedSecretByteArray.buffer, 'AES-GCM', true, ['encrypt', 'decrypt']);
23
- const decryptedData = yield crypto.subtle.decrypt({ iv: hexToUint8Array(decodeURIComponent(iv)), name: 'AES-GCM' }, sharedSecretCryptoKey, base64ToArrayBuffer(decodeURIComponent(message)));
24
+ const decryptParams = {
25
+ iv: hexToUint8Array(decodeURIComponent(iv)),
26
+ name: 'AES-GCM',
27
+ };
28
+ if (additionalData) {
29
+ decryptParams.additionalData = additionalData;
30
+ }
31
+ const decryptedData = yield crypto.subtle.decrypt(decryptParams, sharedSecretCryptoKey, base64ToArrayBuffer(decodeURIComponent(message)));
24
32
  return decoder.decode(new Uint8Array(decryptedData));
25
33
  });
26
34
  const hexToUint8Array = (hex) => {
@@ -4,6 +4,7 @@
4
4
  * @param sharedSecret - The shared secret key in hexadecimal format
5
5
  * @param message - The encrypted message in base64 format
6
6
  * @param iv - The initialization vector in hexadecimal format
7
+ * @param additionalData - Additional data to include in the decryption
7
8
  * @returns A Promise that resolves to the decrypted message as a string
8
9
  */
9
- export declare const decryptMessage: (sharedSecret: string, message: string, iv: string) => Promise<string>;
10
+ export declare const decryptMessage: (sharedSecret: string, message: string, iv: string, additionalData?: BufferSource) => Promise<string>;
@@ -7,16 +7,24 @@ import { __awaiter } from '../../../_virtual/_tslib.js';
7
7
  * @param sharedSecret - The shared secret key in hexadecimal format
8
8
  * @param message - The encrypted message in base64 format
9
9
  * @param iv - The initialization vector in hexadecimal format
10
+ * @param additionalData - Additional data to include in the decryption
10
11
  * @returns A Promise that resolves to the decrypted message as a string
11
12
  */
12
- const decryptMessage = (sharedSecret, message, iv) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const decryptMessage = (sharedSecret, message, iv, additionalData) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  var _a, _b;
14
15
  const decoder = new TextDecoder();
15
16
  const sharedSecretByteArray = new Uint8Array((_b = (_a = decodeURIComponent(sharedSecret)
16
17
  .match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map((byte) => parseInt(byte, 16))) !== null && _b !== void 0 ? _b : []);
17
18
  // Import the ArrayBuffer as a CryptoKey
18
19
  const sharedSecretCryptoKey = yield crypto.subtle.importKey('raw', sharedSecretByteArray.buffer, 'AES-GCM', true, ['encrypt', 'decrypt']);
19
- const decryptedData = yield crypto.subtle.decrypt({ iv: hexToUint8Array(decodeURIComponent(iv)), name: 'AES-GCM' }, sharedSecretCryptoKey, base64ToArrayBuffer(decodeURIComponent(message)));
20
+ const decryptParams = {
21
+ iv: hexToUint8Array(decodeURIComponent(iv)),
22
+ name: 'AES-GCM',
23
+ };
24
+ if (additionalData) {
25
+ decryptParams.additionalData = additionalData;
26
+ }
27
+ const decryptedData = yield crypto.subtle.decrypt(decryptParams, sharedSecretCryptoKey, base64ToArrayBuffer(decodeURIComponent(message)));
20
28
  return decoder.decode(new Uint8Array(decryptedData));
21
29
  });
22
30
  const hexToUint8Array = (hex) => {
@@ -9,11 +9,12 @@ var _tslib = require('../../../_virtual/_tslib.cjs');
9
9
  * Encrypts a message using AES-GCM encryption with a shared secret key
10
10
  * @param sharedSecret - Hexadecimal string representing the shared secret key
11
11
  * @param message - The plaintext message to encrypt
12
- * @returns {Promise<{encryptedMessage: string, iv: string}>} Object containing:
12
+ * @param additionalData - Additional data to include in the encryption
13
+ * @returns Object containing:
13
14
  * - encryptedMessage: Base64 encoded encrypted message
14
15
  * - iv: Hexadecimal initialization vector used for encryption
15
16
  */
16
- const encryptMessage = (sharedSecret, message) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
17
+ const encryptMessage = (sharedSecret, message, additionalData) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
17
18
  var _a, _b;
18
19
  const encoder = new TextEncoder();
19
20
  const iv = crypto.getRandomValues(new Uint8Array(12));
@@ -21,7 +22,14 @@ const encryptMessage = (sharedSecret, message) => _tslib.__awaiter(void 0, void
21
22
  const sharedSecretByteArray = new Uint8Array((_b = (_a = sharedSecret.match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map((byte) => parseInt(byte, 16))) !== null && _b !== void 0 ? _b : []);
22
23
  // Import the ArrayBuffer as a CryptoKey
23
24
  const sharedSecretCryptoKey = yield crypto.subtle.importKey('raw', sharedSecretByteArray.buffer, 'AES-GCM', true, ['encrypt', 'decrypt']);
24
- const encryptedMessage = yield crypto.subtle.encrypt({ iv, name: 'AES-GCM' }, sharedSecretCryptoKey, data);
25
+ const encryptParams = {
26
+ iv,
27
+ name: 'AES-GCM',
28
+ };
29
+ if (additionalData) {
30
+ encryptParams.additionalData = additionalData;
31
+ }
32
+ const encryptedMessage = yield crypto.subtle.encrypt(encryptParams, sharedSecretCryptoKey, data);
25
33
  return {
26
34
  encryptedMessage: encodeURIComponent(arrayBufferToBase64(encryptedMessage)),
27
35
  iv: encodeURIComponent(uint8ArrayToHex(iv)),
@@ -6,8 +6,9 @@ export type EncryptedMessage = {
6
6
  * Encrypts a message using AES-GCM encryption with a shared secret key
7
7
  * @param sharedSecret - Hexadecimal string representing the shared secret key
8
8
  * @param message - The plaintext message to encrypt
9
- * @returns {Promise<{encryptedMessage: string, iv: string}>} Object containing:
9
+ * @param additionalData - Additional data to include in the encryption
10
+ * @returns Object containing:
10
11
  * - encryptedMessage: Base64 encoded encrypted message
11
12
  * - iv: Hexadecimal initialization vector used for encryption
12
13
  */
13
- export declare const encryptMessage: (sharedSecret: string, message: string) => Promise<EncryptedMessage>;
14
+ export declare const encryptMessage: (sharedSecret: string, message: string, additionalData?: BufferSource) => Promise<EncryptedMessage>;
@@ -5,11 +5,12 @@ import { __awaiter } from '../../../_virtual/_tslib.js';
5
5
  * Encrypts a message using AES-GCM encryption with a shared secret key
6
6
  * @param sharedSecret - Hexadecimal string representing the shared secret key
7
7
  * @param message - The plaintext message to encrypt
8
- * @returns {Promise<{encryptedMessage: string, iv: string}>} Object containing:
8
+ * @param additionalData - Additional data to include in the encryption
9
+ * @returns Object containing:
9
10
  * - encryptedMessage: Base64 encoded encrypted message
10
11
  * - iv: Hexadecimal initialization vector used for encryption
11
12
  */
12
- const encryptMessage = (sharedSecret, message) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const encryptMessage = (sharedSecret, message, additionalData) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  var _a, _b;
14
15
  const encoder = new TextEncoder();
15
16
  const iv = crypto.getRandomValues(new Uint8Array(12));
@@ -17,7 +18,14 @@ const encryptMessage = (sharedSecret, message) => __awaiter(void 0, void 0, void
17
18
  const sharedSecretByteArray = new Uint8Array((_b = (_a = sharedSecret.match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map((byte) => parseInt(byte, 16))) !== null && _b !== void 0 ? _b : []);
18
19
  // Import the ArrayBuffer as a CryptoKey
19
20
  const sharedSecretCryptoKey = yield crypto.subtle.importKey('raw', sharedSecretByteArray.buffer, 'AES-GCM', true, ['encrypt', 'decrypt']);
20
- const encryptedMessage = yield crypto.subtle.encrypt({ iv, name: 'AES-GCM' }, sharedSecretCryptoKey, data);
21
+ const encryptParams = {
22
+ iv,
23
+ name: 'AES-GCM',
24
+ };
25
+ if (additionalData) {
26
+ encryptParams.additionalData = additionalData;
27
+ }
28
+ const encryptedMessage = yield crypto.subtle.encrypt(encryptParams, sharedSecretCryptoKey, data);
21
29
  return {
22
30
  encryptedMessage: encodeURIComponent(arrayBufferToBase64(encryptedMessage)),
23
31
  iv: encodeURIComponent(uint8ArrayToHex(iv)),
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var assertDefined = require('../../assertDefined/assertDefined.cjs');
8
+
9
+ /**
10
+ * Generates an HMAC (Hash-based Message Authentication Code) using SHA-256
11
+ *
12
+ * @param keyData - The secret key used for generating the HMAC
13
+ * @param data - The data to be authenticated
14
+ * @returns A hexadecimal string representation of the HMAC
15
+ *
16
+ * @example
17
+ * const hmac = await generateHMAC('secretKey', 'dataToAuthenticate');
18
+ * console.log(hmac); // outputs: "a1b2c3d4..."
19
+ */
20
+ const generateHMAC = (keyData, data) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
21
+ assertDefined.assertDefined(keyData, 'Key data must be a non-empty string');
22
+ assertDefined.assertDefined(data, 'Data must be a non-empty string');
23
+ const textEncoder = new TextEncoder();
24
+ const encodedKeyData = textEncoder.encode(keyData);
25
+ const encodedData = textEncoder.encode(data);
26
+ // Import the key for HMAC using SHA-256
27
+ const key = yield crypto.subtle.importKey('raw', encodedKeyData, { hash: 'SHA-256', name: 'HMAC' }, false, ['sign']);
28
+ // Generate the HMAC signature for the data
29
+ const signature = yield crypto.subtle.sign('HMAC', key, encodedData);
30
+ // Convert the ArrayBuffer signature into a hex string
31
+ const hashArray = Array.from(new Uint8Array(signature));
32
+ const hashHex = hashArray
33
+ .map((b) => b.toString(16).padStart(2, '0'))
34
+ .join('');
35
+ return hashHex;
36
+ });
37
+
38
+ exports.generateHMAC = generateHMAC;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generates an HMAC (Hash-based Message Authentication Code) using SHA-256
3
+ *
4
+ * @param keyData - The secret key used for generating the HMAC
5
+ * @param data - The data to be authenticated
6
+ * @returns A hexadecimal string representation of the HMAC
7
+ *
8
+ * @example
9
+ * const hmac = await generateHMAC('secretKey', 'dataToAuthenticate');
10
+ * console.log(hmac); // outputs: "a1b2c3d4..."
11
+ */
12
+ export declare const generateHMAC: (keyData: string, data: string) => Promise<string>;
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { assertDefined } from '../../assertDefined/assertDefined.js';
4
+
5
+ /**
6
+ * Generates an HMAC (Hash-based Message Authentication Code) using SHA-256
7
+ *
8
+ * @param keyData - The secret key used for generating the HMAC
9
+ * @param data - The data to be authenticated
10
+ * @returns A hexadecimal string representation of the HMAC
11
+ *
12
+ * @example
13
+ * const hmac = await generateHMAC('secretKey', 'dataToAuthenticate');
14
+ * console.log(hmac); // outputs: "a1b2c3d4..."
15
+ */
16
+ const generateHMAC = (keyData, data) => __awaiter(void 0, void 0, void 0, function* () {
17
+ assertDefined(keyData, 'Key data must be a non-empty string');
18
+ assertDefined(data, 'Data must be a non-empty string');
19
+ const textEncoder = new TextEncoder();
20
+ const encodedKeyData = textEncoder.encode(keyData);
21
+ const encodedData = textEncoder.encode(data);
22
+ // Import the key for HMAC using SHA-256
23
+ const key = yield crypto.subtle.importKey('raw', encodedKeyData, { hash: 'SHA-256', name: 'HMAC' }, false, ['sign']);
24
+ // Generate the HMAC signature for the data
25
+ const signature = yield crypto.subtle.sign('HMAC', key, encodedData);
26
+ // Convert the ArrayBuffer signature into a hex string
27
+ const hashArray = Array.from(new Uint8Array(signature));
28
+ const hashHex = hashArray
29
+ .map((b) => b.toString(16).padStart(2, '0'))
30
+ .join('');
31
+ return hashHex;
32
+ });
33
+
34
+ export { generateHMAC };
@@ -0,0 +1 @@
1
+ export { generateHMAC } from './generateHMAC';
@@ -4,4 +4,5 @@ export { convertPublicKeyCryptoKeyToHex } from './convertPublicKeyCryptoKeyToHex
4
4
  export { convertPublicKeyHexToCryptoKey } from './convertPublicKeyHexToCryptoKey';
5
5
  export { decryptMessage } from './decryptMessage';
6
6
  export { encryptMessage, type EncryptedMessage } from './encryptMessage';
7
+ export { generateHMAC } from './generateHMAC';
7
8
  export { isEncryptedMessage } from './isEncryptedMessage';
package/src/index.cjs CHANGED
@@ -78,6 +78,7 @@ var convertPublicKeyCryptoKeyToHex = require('./encryption/convertPublicKeyCrypt
78
78
  var convertPublicKeyHexToCryptoKey = require('./encryption/convertPublicKeyHexToCryptoKey/convertPublicKeyHexToCryptoKey.cjs');
79
79
  var decryptMessage = require('./encryption/decryptMessage/decryptMessage.cjs');
80
80
  var encryptMessage = require('./encryption/encryptMessage/encryptMessage.cjs');
81
+ var generateHMAC = require('./encryption/generateHMAC/generateHMAC.cjs');
81
82
  var isEncryptedMessage = require('./encryption/isEncryptedMessage/isEncryptedMessage.cjs');
82
83
  var uint8ArrayToBase64 = require('./uint8ArrayToBase64/uint8ArrayToBase64.cjs');
83
84
  var assertDefined = require('./assertDefined/assertDefined.cjs');
@@ -200,6 +201,7 @@ exports.convertPublicKeyCryptoKeyToHex = convertPublicKeyCryptoKeyToHex.convertP
200
201
  exports.convertPublicKeyHexToCryptoKey = convertPublicKeyHexToCryptoKey.convertPublicKeyHexToCryptoKey;
201
202
  exports.decryptMessage = decryptMessage.decryptMessage;
202
203
  exports.encryptMessage = encryptMessage.encryptMessage;
204
+ exports.generateHMAC = generateHMAC.generateHMAC;
203
205
  exports.isEncryptedMessage = isEncryptedMessage.isEncryptedMessage;
204
206
  exports.uint8ArrayFromBase64 = uint8ArrayToBase64.uint8ArrayFromBase64;
205
207
  exports.uint8ArrayToBase64 = uint8ArrayToBase64.uint8ArrayToBase64;
package/src/index.js CHANGED
@@ -74,6 +74,7 @@ export { convertPublicKeyCryptoKeyToHex } from './encryption/convertPublicKeyCry
74
74
  export { convertPublicKeyHexToCryptoKey } from './encryption/convertPublicKeyHexToCryptoKey/convertPublicKeyHexToCryptoKey.js';
75
75
  export { decryptMessage } from './encryption/decryptMessage/decryptMessage.js';
76
76
  export { encryptMessage } from './encryption/encryptMessage/encryptMessage.js';
77
+ export { generateHMAC } from './encryption/generateHMAC/generateHMAC.js';
77
78
  export { isEncryptedMessage } from './encryption/isEncryptedMessage/isEncryptedMessage.js';
78
79
  export { uint8ArrayFromBase64, uint8ArrayToBase64 } from './uint8ArrayToBase64/uint8ArrayToBase64.js';
79
80
  export { assertDefined } from './assertDefined/assertDefined.js';