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

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',
})
}