npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

polyfill-crypto-methods

v0.2.0

Published

Polyfill for Crypto instance methods of Web Crypto API

Downloads

3,256

Readme

Polyfill-Crypto-Methods

This is a polyfill for the Crypto instance methods of the Web Crypto API (just import this library at the top of your code entry):

This library was originally made for WeChat Miniprogram, because they do not support Web Crypto API, which prevents the use of some third-party encryption libraries, such as crypto-js, jsencrypt, @noble/curves etc.


向不支持 Web Crypto API 的运行环境,全局注入 Crypto 实例方法(只需在代码入口的顶部导入这个库):

这是库最初,是给微信小程序做的,由于不支持 Web Crypto API,导致无法使用一些第三方加密库,比如 crypto-jsjsencrypt@noble/curves 等。

Usage

NPM

npm i polyfill-crypto-methods

YARN

yarn add polyfill-crypto-methods

Examples

import 'polyfill-crypto-methods';

// Ouptut: true
console.log(globalThis.crypto === crypto);

const int8 = crypto.getRandomValues(new Int8Array(4));
const int16 = crypto.getRandomValues(new Int16Array(4));
const int32 = crypto.getRandomValues(new Int32Array(4));
const uint8 = crypto.getRandomValues(new Uint8Array(4));
const uint16 = crypto.getRandomValues(new Uint16Array(4));
const uint32 = crypto.getRandomValues(new Uint32Array(4));

// Output: [-69, 52, -69, 8]
console.log(int8);
// Ouput: [-12857, 11870, 1874, -30545]
console.log(int16);
// Output: [740598374, 1682174651, -440338757, -391071704]
console.log(int32);
// Output: [133, 69, 14, 216]
console.log(uint8);
// Output: [45360, 53346, 43256, 34054]
console.log(uint16);
// Output: [1771376779, 3593883952, 3543639388, 2288005852]
console.log(uint32);

const uuid = crypto.randomUUID();
// Output: "e6c5350a-b7f3-9b9c-3a3c-d0eab9e63122"
console.log(uuid);

// Sync
const bytes = crypto.randomBytes(4);
// Ouput: [123, 56, 189, 201]
consologe.log(bytes);

// Async
const ret = crypto.randomBytes(4, (err, arr) => {
	// Ouput: null, [92, 112, 228, 144]
  console.log(err, arr);
});
import { crypto as myCrypto } 'polyfill-crypto-methods';

// Ouptut: true
console.log(globalThis.crypto === myCrypto);

// Sync
const bytes = myCrypto.randomBytes(4);
// Ouput: [123, 56, 189, 201]
consologe.log(bytes);

// Async
const ret = myCrypto.randomBytes(4, (err, arr) => {
	// Ouput: null, [92, 112, 228, 144]
  console.log(err, arr);
});