New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot/util-crypto

Package Overview
Dependencies
Maintainers
2
Versions
1358
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot/util-crypto

A collection of useful crypto utilities for @polkadot

  • 9.1.2-6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
114K
increased by11.4%
Maintainers
2
Weekly downloads
 
Created

What is @polkadot/util-crypto?

@polkadot/util-crypto is a utility library for cryptographic functions, specifically designed for use with the Polkadot and Substrate ecosystems. It provides a wide range of cryptographic utilities including hashing, key generation, signing, and verification.

What are @polkadot/util-crypto's main functionalities?

Hashing

This feature allows you to create a Blake2 hash of a given input. The code sample demonstrates how to hash the string 'hello world' using the Blake2 algorithm.

const { blake2AsHex } = require('@polkadot/util-crypto');
const data = 'hello world';
const hash = blake2AsHex(data);
console.log(hash);

Key Generation

This feature allows you to generate a mnemonic phrase for key generation. The code sample demonstrates how to generate a new mnemonic phrase.

const { mnemonicGenerate } = require('@polkadot/util-crypto');
const mnemonic = mnemonicGenerate();
console.log(mnemonic);

Signing

This feature allows you to verify a digital signature. The code sample demonstrates how to verify a signature for a given message and public key.

const { signatureVerify } = require('@polkadot/util-crypto');
const message = 'hello world';
const signature = '0x...'; // Replace with actual signature
const publicKey = '0x...'; // Replace with actual public key
const isValid = signatureVerify(message, signature, publicKey).isValid;
console.log(isValid);

Encryption

This feature allows you to encrypt and decrypt messages using the NaCl library. The code sample demonstrates how to encrypt and then decrypt a message.

const { naclEncrypt, naclDecrypt } = require('@polkadot/util-crypto');
const message = new Uint8Array([1, 2, 3, 4, 5]);
const secret = new Uint8Array(32); // Replace with actual secret key
const { encrypted, nonce } = naclEncrypt(message, secret);
const decrypted = naclDecrypt(encrypted, nonce, secret);
console.log(decrypted);

Other packages similar to @polkadot/util-crypto

FAQs

Package last updated on 12 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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