Skip to main content

SEA.verify()

Verify that a digital signature is valid and was created by the owner of a specific public key. Used to confirm data authenticity and integrity.

Syntax

Parameters

  • signed (string|object): Signed data from SEA.sign()
  • publicKey (string|object): Public key to verify against, or key pair with pub property
  • callback (function, optional): Called with verified data or undefined
  • options (object, optional):
    • encode: Signature encoding (default: ‘base64’)
    • fallback: Enable fallback verification (default: enabled)

Returns

A Promise that resolves to:
  • The original data if signature is valid
  • undefined if signature is invalid

Basic Usage

Verify a Signature

Verify with Key Pair

With Callback

How It Works

Reference: ~/workspace/source/sea/verify.js:9-41
  1. Parse Signed Data: Extracts message (m) and signature (s)
  2. Import Public Key: Converts public key to Web Crypto format
  3. Hash Message: Computes SHA-256 hash of the message
  4. Verify Signature: Uses ECDSA to verify signature against hash
  5. Return: Original message if valid, undefined if invalid

Verification Process

Signature Verification

Valid Signature

Invalid Signature (Wrong Key)

Tampered Data

Skip Verification

Pass false as the public key to skip verification and extract the message:
Using SEA.verify(data, false) bypasses security. Only use this when you explicitly want to extract the message without verification, such as for debugging or when verification happens elsewhere.

Use Cases

Verify User Messages

Verify Identity

Verify Transactions

Verify File Integrity

Fallback Verification

SEA includes fallback verification for backward compatibility with older signature formats. Reference: ~/workspace/source/sea/verify.js:55-79

Automatic Fallback

Configure Fallback

Security Considerations

Trust the Public Key

Verification only confirms the signature matches the public key. You must trust that the public key belongs to the claimed entity:

Message Integrity

Verification guarantees:
  • Authenticity: Message was signed by holder of private key
  • Integrity: Message has not been modified
  • Non-repudiation: Signer cannot deny creating the signature
Verification does NOT guarantee:
  • The public key belongs to who you think it does
  • The message content is truthful
  • The signer had authority to make the claim

Memory Leak Prevention

SEA caches imported public keys to prevent memory leaks: Reference: ~/workspace/source/sea/verify.js:46-52

Error Handling

Invalid Signature

With Callback

Try-Catch

Performance

  • Speed: ~1-3ms per verification (varies by device)
  • Caching: Public keys are cached for reuse
  • Async: Always asynchronous

Batch Verification

Common Patterns

Verify Before Processing

Multi-signature Verification

Verify Chain of Signatures

Trust List Verification

Integration with GUN

Auto-verification

GUN automatically verifies signatures when reading user data:

Manual Verification