Skip to content

SignaturePreAuthorized.wrap

Serializes a TIP-1165 pre-authorized signature: rlp([keychain_signature, signed_key_authorization]) ‖ magic.

The signature must be a V2 keychain signature whose inner signature is secp256k1, P256, or WebAuthn.

Imports

Named
import { SignaturePreAuthorized } from 'ox/tempo'

Examples

import { Hash, Hex, Secp256k1 } from 'ox'
import {
  KeyAuthorization,
  SignatureEnvelope,
  SignaturePreAuthorized
} from 'ox/tempo'
 
const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
const accessKey = Secp256k1.randomPrivateKey()
const rootKey = Secp256k1.randomPrivateKey()
 
const authorization = KeyAuthorization.from({
  address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  chainId: 4217n,
  type: 'secp256k1'
})
const keyAuthorization = KeyAuthorization.from(
  authorization,
  {
    signature: SignatureEnvelope.from(
      Secp256k1.sign({
        payload:
          KeyAuthorization.getSignPayload(authorization),
        privateKey: rootKey
      })
    )
  }
)
 
const hash = Hash.keccak256(Hex.fromString('hello'))
const signature = SignatureEnvelope.from({
  inner: SignatureEnvelope.from(
    Secp256k1.sign({
      payload: Hash.keccak256(
        Hex.concat('0x04', hash, account)
      ),
      privateKey: accessKey
    })
  ),
  userAddress: account
})
 
const wrapped = SignaturePreAuthorized.wrap({

  keyAuthorization, 
  signature
})

Definition

function wrap(
  value: Unwrapped,
): Wrapped

Source: src/tempo/SignaturePreAuthorized.ts

Parameters

value

  • Type: Unwrapped

Unwrapped pre-authorized signature.

value.keyAuthorization

  • Type: Signed

Root key's signed authorization of the access key.

value.signature

  • Type: Keychain

V2 keychain signature by the access key.

Return Type

Wrapped pre-authorized signature.

Wrapped