CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-polkadot--wasm-crypto

WebAssembly interface layer providing high-performance cryptographic functions for blockchain applications in the Polkadot ecosystem.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

ed25519.mddocs/

Ed25519 Digital Signatures

Ed25519 signature scheme implementation providing high-performance digital signatures with keypair generation, signing, and verification capabilities.

Capabilities

Generate Keypair from Seed

Generates an Ed25519 keypair from a 32-byte seed.

/**
 * Generates Ed25519 keypair from seed
 * @param seed - 32-byte seed as Uint8Array
 * @returns 64-byte keypair as Uint8Array (32-byte secret key + 32-byte public key)
 */
function ed25519KeypairFromSeed(seed: Uint8Array): Uint8Array;

Usage Example:

import { waitReady, ed25519KeypairFromSeed } from "@polkadot/wasm-crypto";

await waitReady();

const seed = new Uint8Array(32).fill(1); // Example seed
const keypair = ed25519KeypairFromSeed(seed);

const secretKey = keypair.slice(0, 32);
const publicKey = keypair.slice(32, 64);

console.log("Secret key length:", secretKey.length); // 32
console.log("Public key length:", publicKey.length); // 32

Sign Message

Signs a message using Ed25519 private key.

/**
 * Signs a message using Ed25519
 * @param pubkey - 32-byte public key as Uint8Array
 * @param seckey - 32-byte secret key as Uint8Array
 * @param message - Message to sign as Uint8Array
 * @returns 64-byte signature as Uint8Array
 */
function ed25519Sign(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array;

Usage Example:

import { waitReady, ed25519KeypairFromSeed, ed25519Sign } from "@polkadot/wasm-crypto";

await waitReady();

const seed = new Uint8Array(32).fill(1);
const keypair = ed25519KeypairFromSeed(seed);
const secretKey = keypair.slice(0, 32);
const publicKey = keypair.slice(32, 64);

const message = new TextEncoder().encode("Hello, Ed25519!");
const signature = ed25519Sign(publicKey, secretKey, message);

console.log("Signature length:", signature.length); // 64

Verify Signature

Verifies an Ed25519 signature against a message and public key.

/**
 * Verifies Ed25519 signature
 * @param signature - 64-byte signature as Uint8Array
 * @param message - Original message as Uint8Array
 * @param pubkey - 32-byte public key as Uint8Array
 * @returns true if signature is valid, false otherwise
 */
function ed25519Verify(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean;

Usage Example:

import { 
  waitReady, 
  ed25519KeypairFromSeed, 
  ed25519Sign, 
  ed25519Verify 
} from "@polkadot/wasm-crypto";

await waitReady();

const seed = new Uint8Array(32).fill(1);
const keypair = ed25519KeypairFromSeed(seed);
const secretKey = keypair.slice(0, 32);
const publicKey = keypair.slice(32, 64);

const message = new TextEncoder().encode("Hello, Ed25519!");
const signature = ed25519Sign(publicKey, secretKey, message);

const isValid = ed25519Verify(signature, message, publicKey);
console.log("Signature is valid:", isValid); // true

// Test with wrong message
const wrongMessage = new TextEncoder().encode("Wrong message");
const isInvalid = ed25519Verify(signature, wrongMessage, publicKey);
console.log("Wrong message signature is valid:", isInvalid); // false

Complete Ed25519 Workflow

import { 
  waitReady, 
  ed25519KeypairFromSeed, 
  ed25519Sign, 
  ed25519Verify 
} from "@polkadot/wasm-crypto";

async function demonstrateEd25519() {
  await waitReady();
  
  // Generate keypair from seed
  const seed = new Uint8Array(32);
  crypto.getRandomValues(seed); // Use random seed in production
  
  const keypair = ed25519KeypairFromSeed(seed);
  const secretKey = keypair.slice(0, 32);
  const publicKey = keypair.slice(32, 64);
  
  // Sign multiple messages
  const messages = [
    "First message",
    "Second message",
    "Third message"
  ];
  
  const signatures = messages.map(msg => {
    const msgBytes = new TextEncoder().encode(msg);
    return ed25519Sign(publicKey, secretKey, msgBytes);
  });
  
  // Verify all signatures
  const verifications = messages.map((msg, index) => {
    const msgBytes = new TextEncoder().encode(msg);
    return ed25519Verify(signatures[index], msgBytes, publicKey);
  });
  
  console.log("All signatures valid:", verifications.every(v => v)); // true
  
  return { keypair, signatures, verifications };
}

demonstrateEd25519();

Install with Tessl CLI

npx tessl i tessl/npm-polkadot--wasm-crypto

docs

bip39.md

ed25519.md

hashing.md

index.md

key-derivation.md

secp256k1.md

sr25519.md

vrf.md

tile.json