Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance increase to sign & verify signature #20

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

DenisCarriere
Copy link
Contributor

@DenisCarriere DenisCarriere commented Feb 13, 2024

Performance increase

A significant improvement replacing tweetnacl with @noble/curves

  • sign: 6.5x faster
  • verify: 2.5x faster
image

What's Breaking?

What's new?

  • update substreams-sink
    • improved inactivity handling
  • add new webhook CLI flags
    • disablePing
    • disableSignature
    • maximumAttempt
  • Add more test cases for sign & verify

Tweetnacl

const nacl = require("tweetnacl");

// Your public key can be found on your application in the Developer Portal
const PUBLIC_KEY = "APPLICATION_PUBLIC_KEY";

const signature = req.get("X-Signature-Ed25519");
const timestamp = req.get("X-Signature-Timestamp");
const body = req.rawBody; // rawBody is expected to be a string, not raw bytes

const isVerified = nacl.sign.detached.verify(
    Buffer.from(timestamp + body),
    Buffer.from(signature, "hex"),
    Buffer.from(PUBLIC_KEY, "hex")
);

if (!isVerified) {
    return res.status(401).end("invalid request signature");
}

@noble/curves

import { ed25519 } from "@noble/curves/ed25519.js";

// validate signature using public key
const isVerified = ed25519.verify(
  signature,
  Buffer.from(timestamp + body),
  PUBLIC_KEY,
);

.env

# Webhook
PRIVATE_KEY=<Ed25519 Private Key>
WEBHOOK_URL=http://127.0.0.1:3000
PORT=9102

# Get Substreams API Key
# https://app.pinax.network
# https://app.streamingfast.io/
SUBSTREAMS_API_KEY=<Substreams API Token @ https://pinax.network>
SUBSTREAMS_ENDPOINT=https://eth.substreams.pinax.network:443

# Substreams Package (*.spkg)
MANIFEST=https://github.com/pinax-network/substreams/releases/download/blocks-v0.1.0/blocks-v0.1.0.spkg
MODULE_NAME=map_blocks
START_BLOCK=-10
PRODUCTION_MODE=true

# Webhook (Optional)
DISABLE_PING=false
DISABLE_SIGNATURE=false
VERBOSE=true
MAXIMUM_ATTEMPTS=100

@DenisCarriere DenisCarriere self-assigned this Feb 13, 2024
@DenisCarriere DenisCarriere changed the title Simplify HTTP post signature Performance increase to sign & verify signature Feb 13, 2024
@DenisCarriere DenisCarriere merged commit a361450 into main Feb 13, 2024
1 check passed
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.

1 participant