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

View File

@@ -0,0 +1,50 @@
import type { ErrorType } from '../../errors/utils.js'
import type { AuthorizationRequest } from '../../types/authorization.js'
import type { ByteArray, Hex } from '../../types/misc.js'
import { type ConcatHexErrorType, concatHex } from '../data/concat.js'
import { type HexToBytesErrorType, hexToBytes } from '../encoding/toBytes.js'
import { type NumberToHexErrorType, numberToHex } from '../encoding/toHex.js'
import { type ToRlpErrorType, toRlp } from '../encoding/toRlp.js'
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
type To = 'hex' | 'bytes'
export type HashAuthorizationParameters<to extends To> =
AuthorizationRequest & {
/** Output format. @default "hex" */
to?: to | To | undefined
}
export type HashAuthorizationReturnType<to extends To> =
| (to extends 'bytes' ? ByteArray : never)
| (to extends 'hex' ? Hex : never)
export type HashAuthorizationErrorType =
| Keccak256ErrorType
| ConcatHexErrorType
| ToRlpErrorType
| NumberToHexErrorType
| HexToBytesErrorType
| ErrorType
/**
* Computes an Authorization hash in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
*/
export function hashAuthorization<to extends To = 'hex'>(
parameters: HashAuthorizationParameters<to>,
): HashAuthorizationReturnType<to> {
const { chainId, nonce, to } = parameters
const address = parameters.contractAddress ?? parameters.address
const hash = keccak256(
concatHex([
'0x05',
toRlp([
chainId ? numberToHex(chainId) : '0x',
address,
nonce ? numberToHex(nonce) : '0x',
]),
]),
)
if (to === 'bytes') return hexToBytes(hash) as HashAuthorizationReturnType<to>
return hash as HashAuthorizationReturnType<to>
}

View File

@@ -0,0 +1,66 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type {
Authorization,
AuthorizationRequest,
SignedAuthorization,
} from '../../types/authorization.js'
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
import type { OneOf } from '../../types/utils.js'
import {
type RecoverAddressErrorType,
recoverAddress,
} from '../signature/recoverAddress.js'
import {
type HashAuthorizationErrorType,
hashAuthorization,
} from './hashAuthorization.js'
export type RecoverAuthorizationAddressParameters<
authorization extends OneOf<
Authorization | AuthorizationRequest | SignedAuthorization
> = OneOf<Authorization | AuthorizationRequest | SignedAuthorization>,
//
_signature = Hex | ByteArray | OneOf<Signature | SignedAuthorization>,
> = {
/**
* The Authorization object.
*
* - If an unsigned `authorization` is provided, the `signature` property is required.
* - If a signed `authorization` is provided, the `signature` property does not need to be provided.
*/
authorization:
| authorization
| OneOf<Authorization | AuthorizationRequest | SignedAuthorization>
} & (authorization extends SignedAuthorization
? {
/** Signature of the Authorization. Not required if the `authorization` is signed. */
signature?: _signature | undefined
}
: {
/** Signature of the Authorization. Not required if the `authorization` is signed. */
signature: _signature
})
export type RecoverAuthorizationAddressReturnType = Address
export type RecoverAuthorizationAddressErrorType =
| HashAuthorizationErrorType
| RecoverAddressErrorType
| ErrorType
export async function recoverAuthorizationAddress<
const authorization extends OneOf<
Authorization | AuthorizationRequest | SignedAuthorization
>,
>(
parameters: RecoverAuthorizationAddressParameters<authorization>,
): Promise<RecoverAuthorizationAddressReturnType> {
const { authorization, signature } = parameters
return recoverAddress({
hash: hashAuthorization(authorization as AuthorizationRequest),
signature: (signature ?? authorization) as Signature,
})
}

View File

@@ -0,0 +1,34 @@
import type { ErrorType } from '../../errors/utils.js'
import type {
AuthorizationList,
SerializedAuthorizationList,
} from '../../types/authorization.js'
import { toHex } from '../encoding/toHex.js'
import { toYParitySignatureArray } from '../transaction/serializeTransaction.js'
export type SerializeAuthorizationListReturnType = SerializedAuthorizationList
export type SerializeAuthorizationListErrorType = ErrorType
/*
* Serializes an EIP-7702 authorization list.
*/
export function serializeAuthorizationList(
authorizationList?: AuthorizationList<number, true> | undefined,
): SerializeAuthorizationListReturnType {
if (!authorizationList || authorizationList.length === 0) return []
const serializedAuthorizationList = []
for (const authorization of authorizationList) {
const { chainId, nonce, ...signature } = authorization
const contractAddress = authorization.address
serializedAuthorizationList.push([
chainId ? toHex(chainId) : '0x',
contractAddress,
nonce ? toHex(nonce) : '0x',
...toYParitySignatureArray({}, signature),
])
}
return serializedAuthorizationList as {} as SerializeAuthorizationListReturnType
}

View File

@@ -0,0 +1,49 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import { type GetAddressErrorType, getAddress } from '../address/getAddress.js'
import {
type IsAddressEqualErrorType,
isAddressEqual,
} from '../address/isAddressEqual.js'
import {
type RecoverAuthorizationAddressErrorType,
type RecoverAuthorizationAddressParameters,
recoverAuthorizationAddress,
} from './recoverAuthorizationAddress.js'
export type VerifyAuthorizationParameters =
RecoverAuthorizationAddressParameters & {
/** The address that signed the Authorization object. */
address: Address
}
export type VerifyAuthorizationReturnType = boolean
export type VerifyAuthorizationErrorType =
| IsAddressEqualErrorType
| GetAddressErrorType
| RecoverAuthorizationAddressErrorType
| ErrorType
/**
* Verify that an Authorization object was signed by the provided address.
*
* - Docs {@link https://viem.sh/docs/utilities/verifyAuthorization}
*
* @param parameters - {@link VerifyAuthorizationParameters}
* @returns Whether or not the signature is valid. {@link VerifyAuthorizationReturnType}
*/
export async function verifyAuthorization({
address,
authorization,
signature,
}: VerifyAuthorizationParameters): Promise<VerifyAuthorizationReturnType> {
return isAddressEqual(
getAddress(address),
await recoverAuthorizationAddress({
authorization,
signature,
}),
)
}