SignatureEnvelope.from
Coerces a value to a signature envelope.
Accepts either a serialized hex string or an existing signature envelope object. Use this to wrap raw signatures from Secp256k1.sign, P256.sign, WebCryptoP256.sign, or WebAuthnP256.sign into the envelope format required by Tempo transactions.
Imports
import { SignatureEnvelope } from 'ox/tempo'Examples
Secp256k1
Standard Ethereum ECDSA signature using the secp256k1 curve.
import { Secp256k1 } from 'ox'
import { SignatureEnvelope } from 'ox/tempo'
const privateKey = Secp256k1.randomPrivateKey()
const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
const envelope = SignatureEnvelope.from(signature)P256
ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the public key.
import { P256 } from 'ox'
import { SignatureEnvelope } from 'ox/tempo'
const { privateKey, publicKey } = P256.createKeyPair()
const signature = P256.sign({ payload: '0xdeadbeef', privateKey })
const envelope = SignatureEnvelope.from({
signature,
publicKey,
})P256 (WebCrypto)
When using WebCrypto keys, prehash must be true since WebCrypto always SHA256 hashes the digest before signing.
import { WebCryptoP256 } from 'ox'
import { SignatureEnvelope } from 'ox/tempo'
const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
const signature = await WebCryptoP256.sign({ payload: '0xdeadbeef', privateKey })
const envelope = SignatureEnvelope.from({
signature,
publicKey,
prehash: true,
})WebAuthn
Passkey-based signature using WebAuthn. Includes authenticator metadata (authenticatorData and clientDataJSON) along with the P-256 signature and public key.
import { WebAuthnP256 } from 'ox'
import { SignatureEnvelope } from 'ox/tempo'
const credential = await WebAuthnP256.createCredential({
name: 'Example',
})
const { metadata, signature } = await WebAuthnP256.sign({
challenge: '0xdeadbeef',
credentialId: credential.id,
})
const envelope = SignatureEnvelope.from({
signature,
publicKey: credential.publicKey,
metadata,
})Keychain
Wraps another signature type with a user address, used for delegated signing via access keys on behalf of a root account.
import { Secp256k1 } from 'ox'
import { SignatureEnvelope } from 'ox/tempo'
const privateKey = Secp256k1.randomPrivateKey()
const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
const envelope = SignatureEnvelope.from({
userAddress: '0x1234567890123456789012345678901234567890',
inner: SignatureEnvelope.from(signature),
})Definition
function from<value>(
value: value | from.Value,
): from.ReturnValue<value>Source: src/tempo/SignatureEnvelope.ts
Parameters
value
- Type:
value | from.Value
The value to coerce (either a hex string or signature envelope).
Return Type
The signature envelope.
from.ReturnValue<value>

