diff --git a/packages/common/mod.ts b/packages/common/mod.ts index 71135bd0a..8f57c914b 100644 --- a/packages/common/mod.ts +++ b/packages/common/mod.ts @@ -30,6 +30,7 @@ export { SUITE_ID_HEADER_KEM } from "./src/interfaces/kemInterface.ts"; export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.ts"; export { + base64UrlToBytes, concat, hexToBytes, i2Osp, diff --git a/packages/dhkem-x25519/src/x25519.ts b/packages/dhkem-x25519/src/x25519.ts index 52e7916be..206ab4a66 100644 --- a/packages/dhkem-x25519/src/x25519.ts +++ b/packages/dhkem-x25519/src/x25519.ts @@ -3,6 +3,7 @@ import { x25519 } from "@noble/curves/ed25519"; import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { + base64UrlToBytes, DeriveKeyPairError, DeserializeError, EMPTY, @@ -16,16 +17,6 @@ import { const ALG_NAME = "X25519"; -function base64UrlToBytes(v: string): Uint8Array { - const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); - const byteString = atob(base64); - const ret = new Uint8Array(byteString.length); - for (let i = 0; i < byteString.length; i++) { - ret[i] = byteString.charCodeAt(i); - } - return ret; -} - export class X25519 implements DhkemPrimitives { private _hkdf: KdfInterface; private _nPk: number; diff --git a/packages/dhkem-x448/src/x448.ts b/packages/dhkem-x448/src/x448.ts index b386eeede..b74503bfc 100644 --- a/packages/dhkem-x448/src/x448.ts +++ b/packages/dhkem-x448/src/x448.ts @@ -3,6 +3,7 @@ import { x448 } from "@noble/curves/ed448"; import type { DhkemPrimitives, KdfInterface } from "@hpke/common"; import { + base64UrlToBytes, DeriveKeyPairError, DeserializeError, EMPTY, @@ -16,16 +17,6 @@ import { const ALG_NAME = "X448"; -function base64UrlToBytes(v: string): Uint8Array { - const base64 = v.replace(/-/g, "+").replace(/_/g, "/"); - const byteString = atob(base64); - const ret = new Uint8Array(byteString.length); - for (let i = 0; i < byteString.length; i++) { - ret[i] = byteString.charCodeAt(i); - } - return ret; -} - export class X448 implements DhkemPrimitives { private _hkdf: KdfInterface; private _nPk: number;