Skip to content

SignatureEnvelope.verify

Verifies a signature envelope against a digest/payload.

Supports secp256k1, p256, webAuthn, and attested signature types.

An attested signature verifies when its policy ID and user tag derive the expected address and its program key signed the attested sign payload. The node additionally checks the Attested Key Registry and validUntil against block state, which this function cannot.

:::warning keychain signatures are not supported and will throw an error. :::

Imports

Named
import { SignatureEnvelope } from 'ox/tempo'

Examples

Secp256k1

import { SignatureEnvelope } from 'ox/tempo'
import { Secp256k1 } from 'ox'
 
const privateKey = Secp256k1.randomPrivateKey()
const publicKey = Secp256k1.getPublicKey({ privateKey })
const payload = '0xdeadbeef'
 
const signature = Secp256k1.sign({ payload, privateKey })
const envelope = SignatureEnvelope.from(signature)
 
const valid = SignatureEnvelope.verify(envelope, {
  payload,
  publicKey,
})
true

P256

For P256 signatures, the address or publicKey must match the embedded public key in the signature envelope.

import { SignatureEnvelope } from 'ox/tempo'
import { P256 } from 'ox'
 
const privateKey = P256.randomPrivateKey()
const publicKey = P256.getPublicKey({ privateKey })
const payload = '0xdeadbeef'
 
const signature = P256.sign({ payload, privateKey })
const envelope = SignatureEnvelope.from({ prehash: false, publicKey, signature })
 
const valid = SignatureEnvelope.verify(envelope, {
  payload,
  publicKey,
})
true

WebCryptoP256

import { SignatureEnvelope } from 'ox/tempo'
import { WebCryptoP256 } from 'ox'
 
const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
const payload = '0xdeadbeef'
 
const signature = await WebCryptoP256.sign({ payload, privateKey })
const envelope = SignatureEnvelope.from({ prehash: true, publicKey, signature })
 
const valid = SignatureEnvelope.verify(envelope, {
  payload,
  publicKey,
})
true

WebAuthnP256

import { SignatureEnvelope } from 'ox/tempo'
import { WebAuthnP256 } from 'ox'
 
const credential = await WebAuthnP256.createCredential({ name: 'Example' })
const payload = '0xdeadbeef'
 
const { metadata, signature } = await WebAuthnP256.sign({
  challenge: payload,
  credentialId: credential.id,
})
const envelope = SignatureEnvelope.from({
  metadata,
  signature,
  publicKey: credential.publicKey,
})
 
const valid = SignatureEnvelope.verify(envelope, {
  payload,
  publicKey: credential.publicKey,
})
true

Definition

function verify(
  signature: SignatureEnvelope,
  parameters: verify.Parameters,
): boolean

Source: src/tempo/SignatureEnvelope.ts

Parameters

signature

  • Type: SignatureEnvelope

parameters

  • Type: verify.Parameters

Verification parameters.

parameters.address

  • Type: abitype_Address

Address that signed the payload.

parameters.payload

  • Type: 0x${string} | Uint8Array

Payload that was signed.

parameters.publicKey

  • Type: { prefix: number; x: bigint; y: bigint; }

Public key that signed the payload.

Return Type

true if the signature is valid, false otherwise.

boolean