Account.fromWebCryptoP256
Instantiates an Account from a WebCrypto P256 key pair.
Usage
import { , } from 'viem/tempo'
const = await .()
const = .()
.('Address:', .)
Address: 0x...Access Keys
Create an account that acts as an access key for a parent account:
import { , } from 'viem/tempo'
import { } from './viem.config'
// Create root account
const = .(
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
)
// Create access key
const = await .()
const = .(, { : })
// Sign a key authorization
const = await .(, {
: 1337,
: .(.() / 1000) + 86400,
})
// Attach to next transaction
const = await ..({
: ,
,
: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
})
// Now any subsequent transaction can be used with `accessKey`
// WITHOUT the `keyAuthorization` parameter!import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
The return type of Account.fromWebCryptoP256 is backwards compatible with Viem's Account type.
type ReturnType = Account
type Account = {
/** Account address */
address: Address
/** Key type */
keyType: string
/** Public key (hex) */
publicKey: Hex
/** Account source */
source: string
/** Account type */
type: 'local'
/** Signs a raw digest */
sign: (parameters: { hash: Hex }) => Promise<Hex>
/** Signs an EIP-7702 authorization */
signAuthorization: (parameters: SignAuthorizationParameters) => Promise<Authorization>
/** Signs a key authorization */
signKeyAuthorization: (
key: { accessKeyAddress: Address; keyType: string },
parameters: { chainId: number | bigint; expiry?: number; limits?: Limits }
) => Promise<KeyAuthorization>
/** Signs a EIP-191 `personal_sign` message */
signMessage: (parameters: { message: string | { raw: Hex } }) => Promise<Hex>
/** Signs a transaction */
signTransaction: (transaction: TransactionRequest) => Promise<Hex>
/** Signs a EIP-712 typed data */
signTypedData: (typedData: TypedData) => Promise<Hex>
/** Signs a TIP-20 channel voucher */
signVoucher: (parameters: {
chainId: number | bigint
channel: Channel.from.Value | Hex
cumulativeAmount: bigint
}) => Promise<Hex>
}Parameters
keyPair
- Type:
{ publicKey: PublicKey; privateKey: CryptoKey }
The WebCrypto P256 key pair from WebCryptoP256.createKeyPair().
options.access
- Type:
Address | Account
Parent account to access.