/
mod.ts
30 lines (27 loc) · 910 Bytes
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// prettier-ignore
import {
getPublicKey, sign, verify,
recoverPublicKey, getSharedSecret,
utils, CURVE, Point, Signature, schnorr
} from './index.ts';
import { hmac } from 'https://denopkg.com/chiefbiiko/hmac/mod.ts';
function concatTypedArrays(...arrays: Uint8Array[]): Uint8Array {
if (arrays.length === 1) return arrays[0];
const length = arrays.reduce((a, arr) => a + arr.length, 0);
const result = new Uint8Array(length);
for (let i = 0, pad = 0; i < arrays.length; i++) {
const arr = arrays[i];
result.set(arr, pad);
pad += arr.length;
}
return result;
}
utils.hmacSha256 = async (key: Uint8Array, ...messages: Uint8Array[]): Promise<Uint8Array> => {
return hmac('sha256', key, concatTypedArrays(...messages)) as Uint8Array;
};
// prettier-ignore
export {
getPublicKey, sign, verify,
recoverPublicKey, getSharedSecret,
utils, CURVE, Point, Signature, schnorr
};