Skip to content

Add crypto-utils building block using Noble crypto libraries#27

Open
ejacquier wants to merge 5 commits intomainfrom
crypto-building-block
Open

Add crypto-utils building block using Noble crypto libraries#27
ejacquier wants to merge 5 commits intomainfrom
crypto-building-block

Conversation

@ejacquier
Copy link
Contributor

Summary

Adds a new crypto-utils building block that demonstrates how to use cryptographic operations in CRE TypeScript workflows using the Noble crypto libraries as an alternative to the Node.js crypto module.

Why this is needed

The CRE TypeScript SDK runs on QuickJS, which doesn't support Node.js native modules. This means require('crypto') doesn't work. Noble libraries are pure JavaScript and work perfectly in QuickJS.

What's included

  • Hashing: SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, Keccak-256, BLAKE2b, BLAKE3, RIPEMD-160
  • HMAC: HMAC-SHA256, HMAC-SHA512, HMAC-SHA3-256
  • Key Derivation: PBKDF2, Scrypt, HKDF
  • Symmetric Encryption: AES-256-GCM, ChaCha20-Poly1305
  • Digital Signatures: ECDSA (secp256k1), Ed25519
  • Key Exchange: ECDH (secp256k1), X25519
  • Random Bytes: Custom implementation using CRE's Math.random() polyfill (ChaCha8Rng)
  • Real-world examples: Bitcoin and Ethereum address derivation

Random bytes

Noble's randomBytes() fails because it needs crypto.getRandomValues, but CRE provides a Math.random() polyfill using ChaCha8Rng that is consensus-safe. The template shows how to build your own randomBytes():

function randomBytes(length: number): Uint8Array {
  const bytes = new Uint8Array(length);
  for (let i = 0; i < length; i++) {
    bytes[i] = Math.floor(Math.random() * 256);
  }
  return bytes;
}

Documentation

  • Complete Node.js crypto → Noble library mapping table with code references
  • Setup and running instructions
  • Use case examples with code snippets

Test plan

  • Workflow compiles successfully
  • cre workflow simulate workflow runs without errors
  • All crypto operations produce valid output
  • Signature verification returns true
  • ECDH shared secrets match between parties
  • Encryption/decryption roundtrip works

@ejacquier ejacquier requested a review from a team as a code owner February 6, 2026 01:58
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

👋 ejacquier, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

timothyF95
timothyF95 previously approved these changes Feb 6, 2026
# In your workflow, reference the chain as evm:ChainSelector:<chain-id>@1.0.0
#
# experimental-chains:
# - chain-id: 12345 # The numeric chain ID

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The latest version of CLI changed the naming from chain-id to chain-selector smartcontractkit/cre-cli#252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants