FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

19
node_modules/viem/accounts/generateMnemonic.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import { generateMnemonic as generateMnemonic_ } from '@scure/bip39'
import type { ErrorType } from '../errors/utils.js'
export type GenerateMnemonicErrorType = ErrorType
/**
* @description Generates a random mnemonic phrase with a given wordlist.
*
* @param wordlist The wordlist to use for generating the mnemonic phrase.
* @param strength mnemonic strength 128-256 bits
*
* @returns A randomly generated mnemonic phrase.
*/
export function generateMnemonic(
wordlist: string[],
strength?: number | undefined,
): string {
return generateMnemonic_(wordlist, strength)
}

16
node_modules/viem/accounts/generatePrivateKey.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { secp256k1 } from '@noble/curves/secp256k1'
import type { ErrorType } from '../errors/utils.js'
import type { Hex } from '../types/misc.js'
import { type ToHexErrorType, toHex } from '../utils/encoding/toHex.js'
export type GeneratePrivateKeyErrorType = ToHexErrorType | ErrorType
/**
* @description Generates a random private key.
*
* @returns A randomly generated private key.
*/
export function generatePrivateKey(): Hex {
return toHex(secp256k1.utils.randomPrivateKey())
}

42
node_modules/viem/accounts/hdKeyToAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,42 @@
import type { ErrorType } from '../errors/utils.js'
import type { HDKey } from '../types/account.js'
import { type ToHexErrorType, toHex } from '../utils/encoding/toHex.js'
import {
type PrivateKeyToAccountErrorType,
type PrivateKeyToAccountOptions,
privateKeyToAccount,
} from './privateKeyToAccount.js'
import type { HDAccount, HDOptions } from './types.js'
export type HDKeyToAccountOptions = HDOptions & PrivateKeyToAccountOptions
export type HDKeyToAccountErrorType =
| PrivateKeyToAccountErrorType
| ToHexErrorType
| ErrorType
/**
* @description Creates an Account from a HD Key.
*
* @returns A HD Account.
*/
export function hdKeyToAccount(
hdKey_: HDKey,
{
accountIndex = 0,
addressIndex = 0,
changeIndex = 0,
path,
...options
}: HDKeyToAccountOptions = {},
): HDAccount {
const hdKey = hdKey_.derive(
path || `m/44'/60'/${accountIndex}'/${changeIndex}/${addressIndex}`,
)
const account = privateKeyToAccount(toHex(hdKey.privateKey!), options)
return {
...account,
getHdKey: () => hdKey,
source: 'hd',
}
}

107
node_modules/viem/accounts/index.ts generated vendored Normal file
View File

@@ -0,0 +1,107 @@
// biome-ignore lint/performance/noBarrelFile: entrypoint module
export { HDKey } from '@scure/bip32'
export type { Address } from 'abitype'
export {
type CreateNonceManagerParameters,
createNonceManager,
type NonceManager,
type NonceManagerSource,
nonceManager,
} from '../utils/nonceManager.js'
export {
/** @deprecated Use `SignatureToHexErrorType` instead. */
type SerializeSignatureErrorType as SignatureToHexErrorType,
type SerializeSignatureErrorType,
/** @deprecated Use `serializeSignature` instead. */
serializeSignature as signatureToHex,
serializeSignature,
} from '../utils/signature/serializeSignature.js'
export {
type GenerateMnemonicErrorType,
generateMnemonic,
} from './generateMnemonic.js'
export {
type GeneratePrivateKeyErrorType,
generatePrivateKey,
} from './generatePrivateKey.js'
export {
type HDKeyToAccountErrorType,
type HDKeyToAccountOptions,
hdKeyToAccount,
} from './hdKeyToAccount.js'
export {
type MnemonicToAccountErrorType,
type MnemonicToAccountOptions,
mnemonicToAccount,
} from './mnemonicToAccount.js'
export {
type PrivateKeyToAccountErrorType,
type PrivateKeyToAccountOptions,
privateKeyToAccount,
} from './privateKeyToAccount.js'
export { type ToAccountErrorType, toAccount } from './toAccount.js'
export type {
Account,
AccountSource,
CustomSource,
HDAccount,
HDOptions,
JsonRpcAccount,
LocalAccount,
PrivateKeyAccount,
} from './types.js'
export {
type ParseAccountErrorType,
parseAccount,
} from './utils/parseAccount.js'
export {
type PrivateKeyToAddressErrorType,
privateKeyToAddress,
} from './utils/privateKeyToAddress.js'
export {
type PublicKeyToAddressErrorType,
publicKeyToAddress,
} from './utils/publicKeyToAddress.js'
export {
type SignErrorType,
type SignParameters,
type SignReturnType,
setSignEntropy,
sign,
} from './utils/sign.js'
export {
type SignAuthorizationErrorType,
type SignAuthorizationParameters,
type SignAuthorizationReturnType,
signAuthorization,
} from './utils/signAuthorization.js'
export {
type SignMessageErrorType,
type SignMessageParameters,
type SignMessageReturnType,
signMessage,
} from './utils/signMessage.js'
export {
type SignTransactionErrorType,
type SignTransactionParameters,
type SignTransactionReturnType,
signTransaction,
} from './utils/signTransaction.js'
export {
type SignTypedDataErrorType,
type SignTypedDataParameters,
type SignTypedDataReturnType,
signTypedData,
} from './utils/signTypedData.js'
export {
czech,
english,
french,
italian,
japanese,
korean,
portuguese,
simplifiedChinese,
spanish,
traditionalChinese,
} from './wordlists.js'

29
node_modules/viem/accounts/mnemonicToAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import { HDKey } from '@scure/bip32'
import { mnemonicToSeedSync } from '@scure/bip39'
import type { ErrorType } from '../errors/utils.js'
import {
type HDKeyToAccountErrorType,
type HDKeyToAccountOptions,
hdKeyToAccount,
} from './hdKeyToAccount.js'
import type { HDAccount } from './types.js'
export type MnemonicToAccountOptions = HDKeyToAccountOptions & {
passphrase?: string
}
export type MnemonicToAccountErrorType = HDKeyToAccountErrorType | ErrorType
/**
* @description Creates an Account from a mnemonic phrase.
*
* @returns A HD Account.
*/
export function mnemonicToAccount(
mnemonic: string,
{ passphrase, ...hdKeyOpts }: MnemonicToAccountOptions = {},
): HDAccount {
const seed = mnemonicToSeedSync(mnemonic, passphrase)
return hdKeyToAccount(HDKey.fromMasterSeed(seed), hdKeyOpts)
}

6
node_modules/viem/accounts/package.json generated vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"type": "module",
"types": "../_types/accounts/index.d.ts",
"module": "../_esm/accounts/index.js",
"main": "../_cjs/accounts/index.js"
}

76
node_modules/viem/accounts/privateKeyToAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,76 @@
import { secp256k1 } from '@noble/curves/secp256k1'
import type { ErrorType } from '../errors/utils.js'
import type { Hex } from '../types/misc.js'
import { type ToHexErrorType, toHex } from '../utils/encoding/toHex.js'
import type { NonceManager } from '../utils/nonceManager.js'
import { type ToAccountErrorType, toAccount } from './toAccount.js'
import type { PrivateKeyAccount } from './types.js'
import {
type PublicKeyToAddressErrorType,
publicKeyToAddress,
} from './utils/publicKeyToAddress.js'
import { type SignErrorType, sign } from './utils/sign.js'
import { signAuthorization } from './utils/signAuthorization.js'
import { type SignMessageErrorType, signMessage } from './utils/signMessage.js'
import {
type SignTransactionErrorType,
signTransaction,
} from './utils/signTransaction.js'
import {
type SignTypedDataErrorType,
signTypedData,
} from './utils/signTypedData.js'
export type PrivateKeyToAccountOptions = {
nonceManager?: NonceManager | undefined
}
export type PrivateKeyToAccountErrorType =
| ToAccountErrorType
| ToHexErrorType
| PublicKeyToAddressErrorType
| SignErrorType
| SignMessageErrorType
| SignTransactionErrorType
| SignTypedDataErrorType
| ErrorType
/**
* @description Creates an Account from a private key.
*
* @returns A Private Key Account.
*/
export function privateKeyToAccount(
privateKey: Hex,
options: PrivateKeyToAccountOptions = {},
): PrivateKeyAccount {
const { nonceManager } = options
const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false))
const address = publicKeyToAddress(publicKey)
const account = toAccount({
address,
nonceManager,
async sign({ hash }) {
return sign({ hash, privateKey, to: 'hex' })
},
async signAuthorization(authorization) {
return signAuthorization({ ...authorization, privateKey })
},
async signMessage({ message }) {
return signMessage({ message, privateKey })
},
async signTransaction(transaction, { serializer } = {}) {
return signTransaction({ privateKey, transaction, serializer })
},
async signTypedData(typedData) {
return signTypedData({ ...typedData, privateKey } as any)
},
})
return {
...account,
publicKey,
source: 'privateKey',
} as PrivateKeyAccount
}

60
node_modules/viem/accounts/toAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,60 @@
// TODO(v3): Rename to `toLocalAccount` + add `source` property to define source (privateKey, mnemonic, hdKey, etc).
import type { Address } from 'abitype'
import {
InvalidAddressError,
type InvalidAddressErrorType,
} from '../errors/address.js'
import type { ErrorType } from '../errors/utils.js'
import {
type IsAddressErrorType,
isAddress,
} from '../utils/address/isAddress.js'
import type {
AccountSource,
CustomSource,
JsonRpcAccount,
LocalAccount,
} from './types.js'
type GetAccountReturnType<accountSource extends AccountSource> =
| (accountSource extends Address ? JsonRpcAccount : never)
| (accountSource extends CustomSource ? LocalAccount : never)
export type ToAccountErrorType =
| InvalidAddressErrorType
| IsAddressErrorType
| ErrorType
/**
* @description Creates an Account from a custom signing implementation.
*
* @returns A Local Account.
*/
export function toAccount<accountSource extends AccountSource>(
source: accountSource,
): GetAccountReturnType<accountSource> {
if (typeof source === 'string') {
if (!isAddress(source, { strict: false }))
throw new InvalidAddressError({ address: source })
return {
address: source,
type: 'json-rpc',
} as GetAccountReturnType<accountSource>
}
if (!isAddress(source.address, { strict: false }))
throw new InvalidAddressError({ address: source.address })
return {
address: source.address,
nonceManager: source.nonceManager,
sign: source.sign,
signAuthorization: source.signAuthorization,
signMessage: source.signMessage,
signTransaction: source.signTransaction,
signTypedData: source.signTypedData,
source: 'custom',
type: 'local',
} as GetAccountReturnType<accountSource>
}

107
node_modules/viem/accounts/types.ts generated vendored Normal file
View File

@@ -0,0 +1,107 @@
import type { Address, TypedData } from 'abitype'
import type { SmartAccount } from '../account-abstraction/accounts/types.js'
import type { HDKey } from '../types/account.js'
import type { AuthorizationRequest } from '../types/authorization.js'
import type { Hash, Hex, SignableMessage } from '../types/misc.js'
import type { TransactionSerializable } from '../types/transaction.js'
import type { TypedDataDefinition } from '../types/typedData.js'
import type { OneOf, Prettify } from '../types/utils.js'
import type { NonceManager } from '../utils/nonceManager.js'
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
import type { SignAuthorizationReturnType } from './utils/signAuthorization.js'
export type Account<address extends Address = Address> = OneOf<
JsonRpcAccount<address> | LocalAccount<string, address> | SmartAccount
>
///////////////////////////////////////////////////////////////////////////////////////////////////
// Sources
///////////////////////////////////////////////////////////////////////////////////////////////////
export type AccountSource = Address | CustomSource
export type CustomSource = {
address: Address
nonceManager?: NonceManager | undefined
// TODO(v3): Make `sign` required.
sign?: ((parameters: { hash: Hash }) => Promise<Hex>) | undefined
signAuthorization?:
| ((
parameters: AuthorizationRequest,
) => Promise<SignAuthorizationReturnType>)
| undefined
signMessage: ({ message }: { message: SignableMessage }) => Promise<Hex>
signTransaction: <
serializer extends
SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,
transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],
>(
transaction: transaction,
options?:
| {
serializer?: serializer | undefined
}
| undefined,
) => Promise<Hex>
signTypedData: <
const typedData extends TypedData | Record<string, unknown>,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
>(
parameters: TypedDataDefinition<typedData, primaryType>,
) => Promise<Hex>
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Accounts
///////////////////////////////////////////////////////////////////////////////////////////////////
export type JsonRpcAccount<address extends Address = Address> = {
address: address
type: 'json-rpc'
}
export type LocalAccount<
source extends string = string,
address extends Address = Address,
> = Prettify<
CustomSource & {
address: address
publicKey: Hex
source: source
type: 'local'
}
>
export type HDAccount = Prettify<
LocalAccount<'hd'> & {
getHdKey(): HDKey
// TODO(v3): This will be redundant.
sign: NonNullable<CustomSource['sign']>
}
>
export type HDOptions =
| {
/** The account index to use in the path (`"m/44'/60'/${accountIndex}'/0/0"`). */
accountIndex?: number | undefined
/** The address index to use in the path (`"m/44'/60'/0'/0/${addressIndex}"`). */
addressIndex?: number | undefined
/** The change index to use in the path (`"m/44'/60'/0'/${changeIndex}/0"`). */
changeIndex?: number | undefined
path?: undefined
}
| {
accountIndex?: undefined
addressIndex?: undefined
changeIndex?: undefined
/** The HD path. */
path: `m/44'/60'/${string}`
}
export type PrivateKeyAccount = Prettify<
LocalAccount<'privateKey'> & {
// TODO(v3): This will be redundant.
sign: NonNullable<CustomSource['sign']>
signAuthorization: NonNullable<CustomSource['signAuthorization']>
}
>

14
node_modules/viem/accounts/utils/parseAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../types.js'
export type ParseAccountErrorType = ErrorType
export function parseAccount<accountOrAddress extends Address | Account>(
account: accountOrAddress,
): accountOrAddress extends Address ? Account : accountOrAddress {
if (typeof account === 'string')
return { address: account, type: 'json-rpc' } as any
return account as any
}

View File

@@ -0,0 +1,32 @@
import { secp256k1 } from '@noble/curves/secp256k1'
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import {
type BytesToHexErrorType,
bytesToHex,
} from '../../utils/encoding/toHex.js'
import {
type PublicKeyToAddressErrorType,
publicKeyToAddress,
} from './publicKeyToAddress.js'
export type PrivateKeyToAddressErrorType =
| BytesToHexErrorType
| PublicKeyToAddressErrorType
| ErrorType
/**
* @description Converts an ECDSA private key to an address.
*
* @param privateKey The private key to convert.
*
* @returns The address.
*/
export function privateKeyToAddress(privateKey: Hex): Address {
const publicKey = bytesToHex(
secp256k1.getPublicKey(privateKey.slice(2), false),
)
return publicKeyToAddress(publicKey)
}

29
node_modules/viem/accounts/utils/publicKeyToAddress.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import {
type ChecksumAddressErrorType,
checksumAddress,
} from '../../utils/address/getAddress.js'
import {
type Keccak256ErrorType,
keccak256,
} from '../../utils/hash/keccak256.js'
export type PublicKeyToAddressErrorType =
| ChecksumAddressErrorType
| Keccak256ErrorType
| ErrorType
/**
* @description Converts an ECDSA public key to an address.
*
* @param publicKey The public key to convert.
*
* @returns The address.
*/
export function publicKeyToAddress(publicKey: Hex): Address {
const address = keccak256(`0x${publicKey.substring(4)}`).substring(26)
return checksumAddress(`0x${address}`) as Address
}

81
node_modules/viem/accounts/utils/sign.ts generated vendored Normal file
View File

@@ -0,0 +1,81 @@
// TODO(v3): Convert to sync.
import { secp256k1 } from '@noble/curves/secp256k1'
import type { ErrorType } from '../../errors/utils.js'
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
import { type IsHexErrorType, isHex } from '../../utils/data/isHex.js'
import {
type HexToBytesErrorType,
hexToBytes,
} from '../../utils/encoding/toBytes.js'
import {
type NumberToHexErrorType,
numberToHex,
} from '../../utils/encoding/toHex.js'
import { serializeSignature } from '../../utils/signature/serializeSignature.js'
type To = 'object' | 'bytes' | 'hex'
export type SignParameters<to extends To = 'object'> = {
hash: Hex
privateKey: Hex
to?: to | To | undefined
}
export type SignReturnType<to extends To = 'object'> =
| (to extends 'object' ? Signature : never)
| (to extends 'bytes' ? ByteArray : never)
| (to extends 'hex' ? Hex : never)
export type SignErrorType =
| HexToBytesErrorType
| IsHexErrorType
| NumberToHexErrorType
| ErrorType
let extraEntropy: Hex | boolean = false
/**
* Sets extra entropy for signing functions.
*/
export function setSignEntropy(entropy: true | Hex) {
if (!entropy) throw new Error('must be a `true` or a hex value.')
extraEntropy = entropy
}
/**
* @description Signs a hash with a given private key.
*
* @param hash The hash to sign.
* @param privateKey The private key to sign with.
*
* @returns The signature.
*/
export async function sign<to extends To = 'object'>({
hash,
privateKey,
to = 'object',
}: SignParameters<to>): Promise<SignReturnType<to>> {
const { r, s, recovery } = secp256k1.sign(
hash.slice(2),
privateKey.slice(2),
{
lowS: true,
extraEntropy: isHex(extraEntropy, { strict: false })
? hexToBytes(extraEntropy)
: extraEntropy,
},
)
const signature = {
r: numberToHex(r, { size: 32 }),
s: numberToHex(s, { size: 32 }),
v: recovery ? 28n : 27n,
yParity: recovery,
}
return (() => {
if (to === 'bytes' || to === 'hex')
return serializeSignature({ ...signature, to })
return signature
})() as SignReturnType<to>
}

58
node_modules/viem/accounts/utils/signAuthorization.ts generated vendored Normal file
View File

@@ -0,0 +1,58 @@
import type { ErrorType } from '../../errors/utils.js'
import type {
AuthorizationRequest,
SignedAuthorization,
} from '../../types/authorization.js'
import type { Hex, Signature } from '../../types/misc.js'
import type { Prettify } from '../../types/utils.js'
import {
type HashAuthorizationErrorType,
hashAuthorization,
} from '../../utils/authorization/hashAuthorization.js'
import {
type SignErrorType,
type SignParameters,
type SignReturnType,
sign,
} from './sign.js'
type To = 'object' | 'bytes' | 'hex'
export type SignAuthorizationParameters<to extends To = 'object'> =
AuthorizationRequest & {
/** The private key to sign with. */
privateKey: Hex
to?: SignParameters<to>['to'] | undefined
}
export type SignAuthorizationReturnType<to extends To = 'object'> = Prettify<
to extends 'object' ? SignedAuthorization : SignReturnType<to>
>
export type SignAuthorizationErrorType =
| SignErrorType
| HashAuthorizationErrorType
| ErrorType
/**
* Signs an Authorization hash in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
*/
export async function signAuthorization<to extends To = 'object'>(
parameters: SignAuthorizationParameters<to>,
): Promise<SignAuthorizationReturnType<to>> {
const { chainId, nonce, privateKey, to = 'object' } = parameters
const address = parameters.contractAddress ?? parameters.address
const signature = await sign({
hash: hashAuthorization({ address, chainId, nonce }),
privateKey,
to,
})
if (to === 'object')
return {
address,
chainId,
nonce,
...(signature as Signature),
} as any
return signature as any
}

35
node_modules/viem/accounts/utils/signMessage.ts generated vendored Normal file
View File

@@ -0,0 +1,35 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Hex, SignableMessage } from '../../types/misc.js'
import {
type HashMessageErrorType,
hashMessage,
} from '../../utils/signature/hashMessage.js'
import { type SignErrorType, sign } from './sign.js'
export type SignMessageParameters = {
/** The message to sign. */
message: SignableMessage
/** The private key to sign with. */
privateKey: Hex
}
export type SignMessageReturnType = Hex
export type SignMessageErrorType =
| SignErrorType
| HashMessageErrorType
| ErrorType
/**
* @description Calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191):
* `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
*
* @returns The signature.
*/
export async function signMessage({
message,
privateKey,
}: SignMessageParameters): Promise<SignMessageReturnType> {
return await sign({ hash: hashMessage(message), privateKey, to: 'hex' })
}

72
node_modules/viem/accounts/utils/signTransaction.ts generated vendored Normal file
View File

@@ -0,0 +1,72 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import type {
TransactionSerializable,
TransactionSerialized,
} from '../../types/transaction.js'
import {
type Keccak256ErrorType,
keccak256,
} from '../../utils/hash/keccak256.js'
import type { GetTransactionType } from '../../utils/transaction/getTransactionType.js'
import {
type SerializeTransactionFn,
serializeTransaction,
} from '../../utils/transaction/serializeTransaction.js'
import { type SignErrorType, sign } from './sign.js'
export type SignTransactionParameters<
serializer extends
SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,
transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],
> = {
privateKey: Hex
transaction: transaction
serializer?: serializer | undefined
}
export type SignTransactionReturnType<
serializer extends
SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,
transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],
> = TransactionSerialized<GetTransactionType<transaction>>
export type SignTransactionErrorType =
| Keccak256ErrorType
| SignErrorType
| ErrorType
export async function signTransaction<
serializer extends
SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,
transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],
>(
parameters: SignTransactionParameters<serializer, transaction>,
): Promise<SignTransactionReturnType<serializer, transaction>> {
const {
privateKey,
transaction,
serializer = serializeTransaction,
} = parameters
const signableTransaction = (() => {
// For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper).
// See: https://github.com/ethereum/EIPs/blob/e00f4daa66bd56e2dbd5f1d36d09fd613811a48b/EIPS/eip-4844.md#networking
if (transaction.type === 'eip4844')
return {
...transaction,
sidecars: false,
}
return transaction
})()
const signature = await sign({
hash: keccak256(await serializer(signableTransaction)),
privateKey,
})
return (await serializer(
transaction,
signature,
)) as SignTransactionReturnType<serializer, transaction>
}

45
node_modules/viem/accounts/utils/signTypedData.ts generated vendored Normal file
View File

@@ -0,0 +1,45 @@
import type { TypedData } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import type { TypedDataDefinition } from '../../types/typedData.js'
import {
type HashTypedDataErrorType,
hashTypedData,
} from '../../utils/signature/hashTypedData.js'
import { type SignErrorType, sign } from './sign.js'
export type SignTypedDataParameters<
typedData extends TypedData | Record<string, unknown> = TypedData,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
> = TypedDataDefinition<typedData, primaryType> & {
/** The private key to sign with. */
privateKey: Hex
}
export type SignTypedDataReturnType = Hex
export type SignTypedDataErrorType =
| HashTypedDataErrorType
| SignErrorType
| ErrorType
/**
* @description Signs typed data and calculates an Ethereum-specific signature in [https://eips.ethereum.org/EIPS/eip-712](https://eips.ethereum.org/EIPS/eip-712):
* `sign(keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message)))`.
*
* @returns The signature.
*/
export async function signTypedData<
const typedData extends TypedData | Record<string, unknown>,
primaryType extends keyof typedData | 'EIP712Domain',
>(
parameters: SignTypedDataParameters<typedData, primaryType>,
): Promise<SignTypedDataReturnType> {
const { privateKey, ...typedData } =
parameters as unknown as SignTypedDataParameters
return await sign({
hash: hashTypedData(typedData),
privateKey,
to: 'hex',
})
}

11
node_modules/viem/accounts/wordlists.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
// biome-ignore lint/performance/noBarrelFile: _
export { wordlist as czech } from '@scure/bip39/wordlists/czech'
export { wordlist as english } from '@scure/bip39/wordlists/english'
export { wordlist as french } from '@scure/bip39/wordlists/french'
export { wordlist as italian } from '@scure/bip39/wordlists/italian'
export { wordlist as japanese } from '@scure/bip39/wordlists/japanese'
export { wordlist as korean } from '@scure/bip39/wordlists/korean'
export { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese'
export { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese'
export { wordlist as spanish } from '@scure/bip39/wordlists/spanish'
export { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese'