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,60 @@
import type { TypedDataDomain } from 'abitype'
import type { ErrorType } from '../../../errors/utils.js'
import type { Hex, SignableMessage } from '../../../types/misc.js'
import type { RequiredBy } from '../../../types/utils.js'
import { hashTypedData } from '../../../utils/index.js'
import type { HashTypedDataErrorType } from '../../../utils/signature/hashTypedData.js'
import {
type ToPrefixedMessageErrorType,
toPrefixedMessage,
} from '../../../utils/signature/toPrefixedMessage.js'
export type HashMessageParameters = {
message: SignableMessage
verifierDomain: RequiredBy<
TypedDataDomain,
'chainId' | 'name' | 'verifyingContract' | 'version'
>
}
export type HashMessageReturnType = Hex
export type HashMessageErrorType =
| HashTypedDataErrorType
| ToPrefixedMessageErrorType
| ErrorType
/**
* Generates a signable hash for a ERC-7739 personal sign message.
*
* @example
* ```ts
* const hash = hashMessage({
* message: 'hello world',
* verifierDomain: {
* name: 'Smart Account',
* version: '1',
* verifyingContract: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* },
* })
* ```
*/
export function hashMessage(
parameters: HashMessageParameters,
): HashMessageReturnType {
const {
message,
verifierDomain: { salt: _, ...domain },
} = parameters
return hashTypedData({
domain,
types: {
PersonalSign: [{ name: 'prefixed', type: 'bytes' }],
},
primaryType: 'PersonalSign',
message: {
prefixed: toPrefixedMessage(message),
},
})
}

View File

@@ -0,0 +1,98 @@
import type { TypedData, TypedDataDomain } 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 { RequiredBy } from '../../../types/utils.js'
import {
type HashTypedDataErrorType as HashTypedDataErrorType_,
hashTypedData as hashTypedData_,
} from '../../../utils/signature/hashTypedData.js'
export type HashTypedDataParameters<
typedData extends TypedData | Record<string, unknown> = TypedData,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
///
primaryTypes = typedData extends TypedData ? keyof typedData : string,
> = TypedDataDefinition<typedData, primaryType, primaryTypes> & {
verifierDomain: RequiredBy<
TypedDataDomain,
'chainId' | 'name' | 'verifyingContract' | 'salt' | 'version'
>
}
export type HashTypedDataReturnType = Hex
export type HashTypedDataErrorType = HashTypedDataErrorType_ | ErrorType
/**
* Generates a signable hash for ERC-7739 typed data.
*
* @example
* ```ts
* const hash = hashTypedData({
* domain: {
* name: 'Ether Mail',
* version: '1',
* chainId: 1,
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
* },
* types: {
* Person: [
* { name: 'name', type: 'string' },
* { name: 'wallet', type: 'address' },
* ],
* Mail: [
* { name: 'from', type: 'Person' },
* { name: 'to', type: 'Person' },
* { name: 'contents', type: 'string' },
* ],
* },
* primaryType: 'Mail',
* message: {
* from: {
* name: 'Cow',
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
* },
* to: {
* name: 'Bob',
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
* },
* contents: 'Hello, Bob!',
* },
* verifierDomain: {
* name: 'Smart Account',
* version: '1',
* verifyingContract: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* },
* })
* ```
*/
export function hashTypedData<
const typedData extends TypedData | Record<string, unknown>,
primaryType extends keyof typedData | 'EIP712Domain',
>(
parameters: HashTypedDataParameters<typedData, primaryType>,
): HashTypedDataReturnType {
const { domain, message, primaryType, types, verifierDomain } = parameters
return hashTypedData_({
domain: domain as any,
types: {
...types,
TypedDataSign: [
{ name: 'contents', type: primaryType },
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
],
},
primaryType: 'TypedDataSign',
message: {
contents: message as any,
...(verifierDomain as any),
},
})
}

View File

@@ -0,0 +1,108 @@
import type { TypedData } from 'abitype'
import { serializeSignature } from '../../../accounts/index.js'
import type { ByteArray, Hex, Signature } from '../../../types/misc.js'
import type { TypedDataDefinition } from '../../../types/typedData.js'
import { encodePacked } from '../../../utils/abi/encodePacked.js'
import { type IsHexErrorType, isHex } from '../../../utils/data/isHex.js'
import { size } from '../../../utils/data/size.js'
import { bytesToHex, stringToHex } from '../../../utils/encoding/toHex.js'
import {
encodeType,
hashStruct,
} from '../../../utils/signature/hashTypedData.js'
import { getTypesForEIP712Domain } from '../../../utils/typedData.js'
export type WrapTypedDataSignatureParameters<
typedData extends TypedData | Record<string, unknown> = TypedData,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
///
primaryTypes = typedData extends TypedData ? keyof typedData : string,
> = TypedDataDefinition<typedData, primaryType, primaryTypes> & {
signature: Hex | ByteArray | Signature
}
export type WrapTypedDataSignatureReturnType = Hex
export type WrapTypedDataSignatureErrorType = IsHexErrorType
/**
* Wraps a typed data signature for ERC-7739.
*
* @example
* ```ts
* const signature = wrapTypedDataSignature({
* domain: {
* name: 'Ether Mail',
* version: '1',
* chainId: 1,
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
* },
* types: {
* Person: [
* { name: 'name', type: 'string' },
* { name: 'wallet', type: 'address' },
* ],
* Mail: [
* { name: 'from', type: 'Person' },
* { name: 'to', type: 'Person' },
* { name: 'contents', type: 'string' },
* ],
* },
* primaryType: 'Mail',
* message: {
* from: {
* name: 'Cow',
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
* },
* to: {
* name: 'Bob',
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
* },
* contents: 'Hello, Bob!',
* },
* signature: '0x...',
* })
* ```
*/
export function wrapTypedDataSignature(
parameters: WrapTypedDataSignatureParameters,
): WrapTypedDataSignatureReturnType {
const { domain, message, primaryType, signature, types } = parameters
const signatureHex = (() => {
if (isHex(signature)) return signature
if (typeof signature === 'object' && 'r' in signature && 's' in signature)
return serializeSignature(signature)
return bytesToHex(signature)
})()
// Compute dependencies for wrapped signature.
const hashedDomain = hashStruct({
data: domain ?? {},
types: {
EIP712Domain: getTypesForEIP712Domain({ domain }),
},
primaryType: 'EIP712Domain',
})
const hashedContents = hashStruct({
data: message,
types: types as any,
primaryType,
})
const encodedType = encodeType({
primaryType,
types: types as any,
})
// Construct wrapped signature.
return encodePacked(
['bytes', 'bytes32', 'bytes32', 'bytes', 'uint16'],
[
signatureHex,
hashedDomain,
hashedContents,
stringToHex(encodedType),
size(stringToHex(encodedType)),
],
)
}