Skip to content

Commit 021f9de

Browse files
committed
use ByteUtils.toHex
1 parent fe3c90b commit 021f9de

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/aws4.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BSON } from './bson';
12
import { type AWSCredentials } from './deps';
23

34
export type Options = {
@@ -23,14 +24,11 @@ export type SignedHeaders = {
2324
};
2425
};
2526

26-
const crypto = globalThis.crypto;
27-
2827
const getHash = async (str: string): Promise<string> => {
2928
const encoder = new TextEncoder();
3029
const data = encoder.encode(str);
3130
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
32-
const hashArray = Array.from(new Uint8Array(hashBuffer));
33-
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
31+
const hashHex = BSON.onDemand.ByteUtils.toHex(new Uint8Array(hashBuffer));
3432
return hashHex;
3533
};
3634
const getHmacBuffer = async (key: string | Uint8Array, str: string): Promise<Uint8Array> => {
@@ -49,8 +47,7 @@ const getHmacBuffer = async (key: string | Uint8Array, str: string): Promise<Uin
4947
};
5048
const getHmacString = async (key: Uint8Array, str: string): Promise<string> => {
5149
const hmacBuffer = await getHmacBuffer(key, str);
52-
const hashArray = Array.from(hmacBuffer);
53-
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
50+
const hashHex = BSON.onDemand.ByteUtils.toHex(hmacBuffer);
5451
return hashHex;
5552
};
5653

0 commit comments

Comments
 (0)