Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hpke/common

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hpke/common - npm Package Compare versions

Comparing version 0.6.0 to 1.4.0

esm/deps/jsr.io/@std/assert/1.0.0/almost_equals.d.ts.map

2

esm/mod.d.ts

@@ -24,3 +24,3 @@ export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.js";

export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.js";
export { concat, i2Osp, isCryptoKeyPair, xor } from "./src/utils/misc.js";
export { concat, hexToBytes, i2Osp, isCryptoKeyPair, isNode, kemToKeyGenAlgorithm, loadCrypto, loadSubtleCrypto, xor, } from "./src/utils/misc.js";
//# sourceMappingURL=mod.d.ts.map

@@ -14,2 +14,2 @@ export * from "./src/errors.js";

export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.js";
export { concat, i2Osp, isCryptoKeyPair, xor } from "./src/utils/misc.js";
export { concat, hexToBytes, i2Osp, isCryptoKeyPair, isNode, kemToKeyGenAlgorithm, loadCrypto, loadSubtleCrypto, xor, } from "./src/utils/misc.js";

@@ -0,1 +1,3 @@

import { KemId } from "../identifiers.js";
export declare const isNode: () => boolean;
/**

@@ -11,2 +13,5 @@ * Checks whetehr the type of input is CryptoKeyPair or not.

* Concatenates two Uint8Arrays.
* @param a Uint8Array
* @param b Uint8Array
* @returns Concatenated Uint8Array
*/

@@ -16,5 +21,34 @@ export declare function concat(a: Uint8Array, b: Uint8Array): Uint8Array;

* Decodes Base64Url-encoded data.
* @param v Base64Url-encoded string
* @returns Uint8Array
*/
export declare function base64UrlToBytes(v: string): Uint8Array;
/**
* Encodes Uint8Array to Base64Url.
* @param v Uint8Array
* @returns Base64Url-encoded string
*/
export declare function bytesToBase64Url(v: Uint8Array): string;
/**
* Decodes hex string to Uint8Array.
* @param v Hex string
* @returns Uint8Array
* @throws Error if the input is not a hex string.
*/
export declare function hexToBytes(v: string): Uint8Array;
/**
* Encodes Uint8Array to hex string.
* @param v Uint8Array
* @returns Hex string
*/
export declare function bytesToHex(v: Uint8Array): string;
/**
* Converts KemId to KeyAlgorithm.
* @param kem KemId
* @returns KeyAlgorithm
*/
export declare function kemToKeyGenAlgorithm(kem: KemId): KeyAlgorithm;
export declare function loadSubtleCrypto(): Promise<SubtleCrypto>;
export declare function loadCrypto(): Promise<Crypto>;
/**
* XOR for Uint8Array.

@@ -21,0 +55,0 @@ */

@@ -0,1 +1,6 @@

import * as dntShim from "../../_dnt.shims.js";
import { KemId } from "../identifiers.js";
export const isNode = () =>
// deno-lint-ignore no-explicit-any
dntShim.dntGlobalThis.process?.versions?.node != null;
/**

@@ -27,2 +32,5 @@ * Checks whetehr the type of input is CryptoKeyPair or not.

* Concatenates two Uint8Arrays.
* @param a Uint8Array
* @param b Uint8Array
* @returns Concatenated Uint8Array
*/

@@ -37,2 +45,4 @@ export function concat(a, b) {

* Decodes Base64Url-encoded data.
* @param v Base64Url-encoded string
* @returns Uint8Array
*/

@@ -49,2 +59,98 @@ export function base64UrlToBytes(v) {

/**
* Encodes Uint8Array to Base64Url.
* @param v Uint8Array
* @returns Base64Url-encoded string
*/
export function bytesToBase64Url(v) {
return btoa(String.fromCharCode(...v))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=*$/g, "");
}
/**
* Decodes hex string to Uint8Array.
* @param v Hex string
* @returns Uint8Array
* @throws Error if the input is not a hex string.
*/
export function hexToBytes(v) {
if (v.length === 0) {
return new Uint8Array([]);
}
const res = v.match(/[\da-f]{2}/gi);
if (res == null) {
throw new Error("Not hex string.");
}
return new Uint8Array(res.map(function (h) {
return parseInt(h, 16);
}));
}
/**
* Encodes Uint8Array to hex string.
* @param v Uint8Array
* @returns Hex string
*/
export function bytesToHex(v) {
return [...v].map((x) => x.toString(16).padStart(2, "0")).join("");
}
/**
* Converts KemId to KeyAlgorithm.
* @param kem KemId
* @returns KeyAlgorithm
*/
export function kemToKeyGenAlgorithm(kem) {
switch (kem) {
case KemId.DhkemP256HkdfSha256:
return {
name: "ECDH",
namedCurve: "P-256",
};
case KemId.DhkemP384HkdfSha384:
return {
name: "ECDH",
namedCurve: "P-384",
};
case KemId.DhkemP521HkdfSha512:
return {
name: "ECDH",
namedCurve: "P-521",
};
default:
// case KemId.DhkemX25519HkdfSha256
return {
name: "X25519",
};
}
}
export async function loadSubtleCrypto() {
if (dntShim.dntGlobalThis !== undefined && globalThis.crypto !== undefined) {
// Browsers, Node.js >= v19, Cloudflare Workers, Bun, etc.
return globalThis.crypto.subtle;
}
// Node.js <= v18
try {
// @ts-ignore: to ignore "crypto"
const { webcrypto } = await import("crypto"); // node:crypto
return webcrypto.subtle;
}
catch (_e) {
throw new Error("Failed to load SubtleCrypto");
}
}
export async function loadCrypto() {
if (dntShim.dntGlobalThis !== undefined && globalThis.crypto !== undefined) {
// Browsers, Node.js >= v19, Cloudflare Workers, Bun, etc.
return globalThis.crypto;
}
// Node.js <= v18
try {
// @ts-ignore: to ignore "crypto"
const { webcrypto } = await import("crypto"); // node:crypto
return webcrypto;
}
catch (_e) {
throw new Error("Web Cryptograph API not supported");
}
}
/**
* XOR for Uint8Array.

@@ -51,0 +157,0 @@ */

{
"name": "@hpke/common",
"version": "0.6.0",
"version": "1.4.0",
"description": "A Hybrid Public Key Encryption (HPKE) internal-use common module for @hpke family modules.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -24,3 +24,3 @@ export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.js";

export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.js";
export { concat, i2Osp, isCryptoKeyPair, xor } from "./src/utils/misc.js";
export { concat, hexToBytes, i2Osp, isCryptoKeyPair, isNode, kemToKeyGenAlgorithm, loadCrypto, loadSubtleCrypto, xor, } from "./src/utils/misc.js";
//# sourceMappingURL=mod.d.ts.map

@@ -26,3 +26,3 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.xor = exports.isCryptoKeyPair = exports.i2Osp = exports.concat = exports.MINIMUM_PSK_LENGTH = exports.INPUT_LENGTH_LIMIT = exports.EMPTY = exports.SUITE_ID_HEADER_KEM = exports.LABEL_SK = exports.LABEL_DKP_PRK = exports.KEM_USAGES = exports.AEAD_USAGES = exports.HkdfSha512Native = exports.HkdfSha384Native = exports.HkdfSha256Native = exports.XCryptoKey = exports.Hybridkem = exports.Ec = exports.Dhkem = exports.Mode = exports.KemId = exports.KdfId = exports.AeadId = exports.NativeAlgorithm = void 0;
exports.xor = exports.loadSubtleCrypto = exports.loadCrypto = exports.kemToKeyGenAlgorithm = exports.isNode = exports.isCryptoKeyPair = exports.i2Osp = exports.hexToBytes = exports.concat = exports.MINIMUM_PSK_LENGTH = exports.INPUT_LENGTH_LIMIT = exports.EMPTY = exports.SUITE_ID_HEADER_KEM = exports.LABEL_SK = exports.LABEL_DKP_PRK = exports.KEM_USAGES = exports.AEAD_USAGES = exports.HkdfSha512Native = exports.HkdfSha384Native = exports.HkdfSha256Native = exports.XCryptoKey = exports.Hybridkem = exports.Ec = exports.Dhkem = exports.Mode = exports.KemId = exports.KdfId = exports.AeadId = exports.NativeAlgorithm = void 0;
__exportStar(require("./src/errors.js"), exports);

@@ -63,5 +63,10 @@ var algorithm_js_1 = require("./src/algorithm.js");

Object.defineProperty(exports, "concat", { enumerable: true, get: function () { return misc_js_1.concat; } });
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return misc_js_1.hexToBytes; } });
Object.defineProperty(exports, "i2Osp", { enumerable: true, get: function () { return misc_js_1.i2Osp; } });
Object.defineProperty(exports, "isCryptoKeyPair", { enumerable: true, get: function () { return misc_js_1.isCryptoKeyPair; } });
Object.defineProperty(exports, "isNode", { enumerable: true, get: function () { return misc_js_1.isNode; } });
Object.defineProperty(exports, "kemToKeyGenAlgorithm", { enumerable: true, get: function () { return misc_js_1.kemToKeyGenAlgorithm; } });
Object.defineProperty(exports, "loadCrypto", { enumerable: true, get: function () { return misc_js_1.loadCrypto; } });
Object.defineProperty(exports, "loadSubtleCrypto", { enumerable: true, get: function () { return misc_js_1.loadSubtleCrypto; } });
Object.defineProperty(exports, "xor", { enumerable: true, get: function () { return misc_js_1.xor; } });
});

@@ -0,1 +1,3 @@

import { KemId } from "../identifiers.js";
export declare const isNode: () => boolean;
/**

@@ -11,2 +13,5 @@ * Checks whetehr the type of input is CryptoKeyPair or not.

* Concatenates two Uint8Arrays.
* @param a Uint8Array
* @param b Uint8Array
* @returns Concatenated Uint8Array
*/

@@ -16,5 +21,34 @@ export declare function concat(a: Uint8Array, b: Uint8Array): Uint8Array;

* Decodes Base64Url-encoded data.
* @param v Base64Url-encoded string
* @returns Uint8Array
*/
export declare function base64UrlToBytes(v: string): Uint8Array;
/**
* Encodes Uint8Array to Base64Url.
* @param v Uint8Array
* @returns Base64Url-encoded string
*/
export declare function bytesToBase64Url(v: Uint8Array): string;
/**
* Decodes hex string to Uint8Array.
* @param v Hex string
* @returns Uint8Array
* @throws Error if the input is not a hex string.
*/
export declare function hexToBytes(v: string): Uint8Array;
/**
* Encodes Uint8Array to hex string.
* @param v Uint8Array
* @returns Hex string
*/
export declare function bytesToHex(v: Uint8Array): string;
/**
* Converts KemId to KeyAlgorithm.
* @param kem KemId
* @returns KeyAlgorithm
*/
export declare function kemToKeyGenAlgorithm(kem: KemId): KeyAlgorithm;
export declare function loadSubtleCrypto(): Promise<SubtleCrypto>;
export declare function loadCrypto(): Promise<Crypto>;
/**
* XOR for Uint8Array.

@@ -21,0 +55,0 @@ */

@@ -0,1 +1,24 @@

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
(function (factory) {

@@ -7,12 +30,25 @@ if (typeof module === "object" && typeof module.exports === "object") {

else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
define(["require", "exports", "../../_dnt.shims.js", "../identifiers.js"], factory);
}
})(function (require, exports) {
"use strict";
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isCryptoKeyPair = void 0;
exports.isCryptoKeyPair = exports.isNode = void 0;
exports.i2Osp = i2Osp;
exports.concat = concat;
exports.base64UrlToBytes = base64UrlToBytes;
exports.bytesToBase64Url = bytesToBase64Url;
exports.hexToBytes = hexToBytes;
exports.bytesToHex = bytesToHex;
exports.kemToKeyGenAlgorithm = kemToKeyGenAlgorithm;
exports.loadSubtleCrypto = loadSubtleCrypto;
exports.loadCrypto = loadCrypto;
exports.xor = xor;
const dntShim = __importStar(require("../../_dnt.shims.js"));
const identifiers_js_1 = require("../identifiers.js");
const isNode = () =>
// deno-lint-ignore no-explicit-any
dntShim.dntGlobalThis.process?.versions?.node != null;
exports.isNode = isNode;
/**

@@ -45,2 +81,5 @@ * Checks whetehr the type of input is CryptoKeyPair or not.

* Concatenates two Uint8Arrays.
* @param a Uint8Array
* @param b Uint8Array
* @returns Concatenated Uint8Array
*/

@@ -55,2 +94,4 @@ function concat(a, b) {

* Decodes Base64Url-encoded data.
* @param v Base64Url-encoded string
* @returns Uint8Array
*/

@@ -67,2 +108,98 @@ function base64UrlToBytes(v) {

/**
* Encodes Uint8Array to Base64Url.
* @param v Uint8Array
* @returns Base64Url-encoded string
*/
function bytesToBase64Url(v) {
return btoa(String.fromCharCode(...v))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=*$/g, "");
}
/**
* Decodes hex string to Uint8Array.
* @param v Hex string
* @returns Uint8Array
* @throws Error if the input is not a hex string.
*/
function hexToBytes(v) {
if (v.length === 0) {
return new Uint8Array([]);
}
const res = v.match(/[\da-f]{2}/gi);
if (res == null) {
throw new Error("Not hex string.");
}
return new Uint8Array(res.map(function (h) {
return parseInt(h, 16);
}));
}
/**
* Encodes Uint8Array to hex string.
* @param v Uint8Array
* @returns Hex string
*/
function bytesToHex(v) {
return [...v].map((x) => x.toString(16).padStart(2, "0")).join("");
}
/**
* Converts KemId to KeyAlgorithm.
* @param kem KemId
* @returns KeyAlgorithm
*/
function kemToKeyGenAlgorithm(kem) {
switch (kem) {
case identifiers_js_1.KemId.DhkemP256HkdfSha256:
return {
name: "ECDH",
namedCurve: "P-256",
};
case identifiers_js_1.KemId.DhkemP384HkdfSha384:
return {
name: "ECDH",
namedCurve: "P-384",
};
case identifiers_js_1.KemId.DhkemP521HkdfSha512:
return {
name: "ECDH",
namedCurve: "P-521",
};
default:
// case KemId.DhkemX25519HkdfSha256
return {
name: "X25519",
};
}
}
async function loadSubtleCrypto() {
if (dntShim.dntGlobalThis !== undefined && globalThis.crypto !== undefined) {
// Browsers, Node.js >= v19, Cloudflare Workers, Bun, etc.
return globalThis.crypto.subtle;
}
// Node.js <= v18
try {
// @ts-ignore: to ignore "crypto"
const { webcrypto } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("crypto"))) : new Promise((resolve_1, reject_1) => { require(["crypto"], resolve_1, reject_1); }).then(__importStar)); // node:crypto
return webcrypto.subtle;
}
catch (_e) {
throw new Error("Failed to load SubtleCrypto");
}
}
async function loadCrypto() {
if (dntShim.dntGlobalThis !== undefined && globalThis.crypto !== undefined) {
// Browsers, Node.js >= v19, Cloudflare Workers, Bun, etc.
return globalThis.crypto;
}
// Node.js <= v18
try {
// @ts-ignore: to ignore "crypto"
const { webcrypto } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("crypto"))) : new Promise((resolve_2, reject_2) => { require(["crypto"], resolve_2, reject_2); }).then(__importStar)); // node:crypto
return webcrypto;
}
catch (_e) {
throw new Error("Web Cryptograph API not supported");
}
}
/**
* XOR for Uint8Array.

@@ -69,0 +206,0 @@ */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc