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

@unique-nft/sr25519

v0.0.2

Published

Pure Typescript sr25519 implementation

Downloads

2,608

Readme

Pure Javascript Implementation of sr25519

npm version

This is a pure Javascript implementation of sr25519, which is a main key derivation and signature algorithm on Polkadot. The sr25519 algorithm based on the Ristretto group and Schnorr signatures). This implementation is actually a partial port of w3f/schnorrkel to Typescript, and it does not require any additional binaries, Rust libraries, or WASM.

This library provides functions for keypair generation, signature generation and verification, and address encoding and decoding in the Polkadot format. It also supports mnemonic parsing and Polkadot-style hard and soft key derivation.

This library can be used as a tool for generating keypairs and signing transactions for the Polkadot ecosystem and parachains. Additionally, it can serve as a lightweight substitute for the @polkadot-js/keyring and @polkadot-js/util-crypto packages, providing similar functionality without requiring the use of WASM or other heavy dependencies. These libraries provide a lot of useful functionality, but they are also quite large and require the use of WASM, which can be problematic in some environments. Also it requires to be warmed up every time which may bring some another difficulties.

This library is lightweight as possible and includes only some parts of the @noble/hashes library for cryptographic hash functions and the base-x library for base64.

No WASM, no rust, no any binaries - plain Javascript. With Typescript typings included.

Features

Here are the main features of this implementation:

Key pair generation

The implementation includes functions to generate sr25519 key pairs, including mnemonic parsing and Polkadot-style hard and soft key derivation.

Signature generation and verification

The implementation can generate and verify signatures for messages using the sr25519 scheme.

Polkadot-format address encoding and decoding

The implementation includes functions for encoding and decoding Polkadot-format addresses.

Usage

import {Sr25519Account} from '@unique-nft/sr25519'

const account = Sr25519Account.fromUri('//Alice')
console.log(account.address) // 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

// sign, parameter may be Uint8Array, hex string or a plain string
console.log(account.sign('hello world')) //Uint8Array(64) [142, 143, 161,  13,   5, 154, 144, 125, 160, 247, 255, 182, 128,  53, 182,  98, 190, 132, 167, 230,  68, 189, 88, 155, 206, 154, 192,  36, 242,  76, 152,  43, 112, 28,  57, 190,  89,  44,  80,  30,  55,  54,  18,  61, 132, 130,  35, 202,  86,  53, 153,  43,  13, 168, 237, 248, 104,  93,  95, 151,  98, 201, 146, 136] 

// account has verify method
console.log(account.verify('hello world', account.sign('hello world'))) // true

// also signature can be verified with static method without instantiating an account
console.log(Sr25519Account.verifySignature('hello world', account.sign('hello world'), account.address)) // true

// a new random mnemonic and a new Sr25519Account account can be generated like this
const mnemonic = Sr25519Account.generateMnemonic()
const account2 = Sr25519Account.fromUri(mnemonic)

// also package provides the account Typescript type
import type {ISr25519Account} from '@unique-nft/sr25519'

Also this lib provides a ready to use signer for the Unique SDK:

const account = Sr25519Account.fromUri('//Alice')
const sdk = new UniqueSdk.Sdk({
  baseUrl: 'https://rest.unique.network/opal/v1',
  account,
})

License: MIT