@henrylabs-interview/payment-processor 0.1.15 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import { sha256 } from '@noble/hashes/sha2.js';
2
+ import { bytesToHex } from '@noble/hashes/utils.js';
1
3
  import crypto from 'crypto';
2
4
  export function generateID(length = 12) {
3
5
  const digits = [];
@@ -13,15 +15,8 @@ export async function generateTimeBasedID(extra = '') {
13
15
  const ms = Math.floor(now / oneMinute) * oneMinute;
14
16
  return await hashToString(`${ms}---${extra}`);
15
17
  }
16
- async function sha256(input) {
17
- const encoder = new TextEncoder();
18
- const data = encoder.encode(input);
19
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
20
- const hashArray = Array.from(new Uint8Array(hashBuffer));
21
- return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
22
- }
23
18
  export async function hashToString(input) {
24
- const hash = await sha256(input);
19
+ const hash = bytesToHex(sha256(new TextEncoder().encode(input)));
25
20
  // 16 hex characters = 64 bits
26
21
  return hash.slice(0, 16);
27
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henrylabs-interview/payment-processor",
3
- "version": "0.1.15",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,5 +21,8 @@
21
21
  "devDependencies": {
22
22
  "@types/bun": "latest",
23
23
  "typescript": "^5"
24
+ },
25
+ "dependencies": {
26
+ "@noble/hashes": "^2.0.1"
24
27
  }
25
28
  }