diff --git a/packages/ensjs/package.json b/packages/ensjs/package.json index e33c41a4..f3021225 100644 --- a/packages/ensjs/package.json +++ b/packages/ensjs/package.json @@ -74,7 +74,11 @@ "!src/**/*.test.ts", "!src/test" ], - "repository": "git@github.com:ensdomains/ensjs.git", + "repository": { + "type": "git", + "url": "git+https://github.com/ensdomains/ensjs.git", + "directory": "packages/ensjs" + }, "author": "TateB ", "license": "MIT", "scripts": { @@ -137,7 +141,7 @@ "typedoc": "^0.24.8", "typedoc-plugin-markdown": "^4.0.0-next.16", "typescript": "5.3.2", - "viem": "^2.9.2", + "viem": "2.9.2", "vitest": "^1.3.1", "wait-on": "^6.0.1" }, diff --git a/packages/ensjs/src/clients/decorators/public.ts b/packages/ensjs/src/clients/decorators/public.ts index e398ae4c..720d6c1f 100644 --- a/packages/ensjs/src/clients/decorators/public.ts +++ b/packages/ensjs/src/clients/decorators/public.ts @@ -20,6 +20,10 @@ import getContentHashRecord, { type GetContentHashRecordParameters, type GetContentHashRecordReturnType, } from '../../functions/public/getContentHashRecord.js' +import getCredentials, { + type GetCredentialsParameters, + type GetCredentialsReturnType, +} from '../../functions/public/getCredentials.js' import getExpiry, { type GetExpiryParameters, type GetExpiryReturnType, @@ -187,6 +191,28 @@ export type EnsPublicActions = { * const result = await client.getExpiry({ name: 'ens.eth' }) * // { expiry: { date: Date, value: 1913933217n }, gracePeriod: 7776000, status: 'active' } */ + getCredentials: ({ + name, + gatewayUrls, + strict, + }: GetCredentialsParameters) => Promise + /** + * Gets credentials for a name. + * @param parameters - {@link GetCredentialsParameters} + * @returns Credentials, or null if none are found. {@link GetCredentialsReturnType} + * + * @example + * import { createPublicClient, http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensPublicActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensPublicActions) + * const result = await client.getCredentials({ name: 'ens.eth' }) + * // [{ url: 'https://example.com' }] + */ getExpiry: ({ name, contract, @@ -408,6 +434,7 @@ export const ensPublicActions = < getAvailable: (parameters) => getAvailable(client, parameters), getContentHashRecord: (parameters) => getContentHashRecord(client, parameters), + getCredentials: (parameters) => getCredentials(client, parameters), getExpiry: (parameters) => getExpiry(client, parameters), getName: (parameters) => getName(client, parameters), getOwner: (parameters) => getOwner(client, parameters), diff --git a/packages/ensjs/src/dns.ts b/packages/ensjs/src/dns.ts index 62b5273c..0304a1af 100644 --- a/packages/ensjs/src/dns.ts +++ b/packages/ensjs/src/dns.ts @@ -1,15 +1,18 @@ export { default as getDnsImportData, + type GetDnsImportDataErrorType, type GetDnsImportDataParameters, type GetDnsImportDataReturnType, } from './functions/dns/getDnsImportData.js' export { default as getDnsOffchainData, + type GetDnsOffchainDataErrorType, type GetDnsOffchainDataParameters, type GetDnsOffchainDataReturnType, } from './functions/dns/getDnsOffchainData.js' export { default as getDnsOwner, + type GetDnsOwnerErrorType, type GetDnsOwnerParameters, type GetDnsOwnerReturnType, } from './functions/dns/getDnsOwner.js' @@ -17,6 +20,7 @@ export { default as importDnsName, type ImportDnsNameDataParameters, type ImportDnsNameDataReturnType, + type ImportDnsNameErrorType, type ImportDnsNameParameters, type ImportDnsNameReturnType, } from './functions/dns/importDnsName.js' diff --git a/packages/ensjs/src/functions/dns/getDnsImportData.ts b/packages/ensjs/src/functions/dns/getDnsImportData.ts index 993ec860..336758cf 100644 --- a/packages/ensjs/src/functions/dns/getDnsImportData.ts +++ b/packages/ensjs/src/functions/dns/getDnsImportData.ts @@ -5,7 +5,7 @@ import { readContract } from 'viem/actions' import type { ChainWithEns } from '../../contracts/consts.js' import { dnssecImplVerifyRrSetSnippet } from '../../contracts/dnssecImpl.js' import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' -import { DnsNewerRecordTypeAvailableError } from '../../index.js' +import { DnsNewerRecordTypeAvailableError } from '../../errors/dns.js' import type { Endpoint } from './types.js' export type GetDnsImportDataParameters = { @@ -15,13 +15,15 @@ export type GetDnsImportDataParameters = { endpoint?: Endpoint } +export type GetDnsImportDataReturnType = RrSetWithSig[] + +export type GetDnsImportDataErrorType = DnsNewerRecordTypeAvailableError | Error + export type RrSetWithSig = { rrset: Hex sig: Hex } -export type GetDnsImportDataReturnType = RrSetWithSig[] - // Compares two serial numbers using RFC1982 serial number math. const serialNumberGt = (i1: number, i2: number): boolean => (i1 < i2 && i2 - i1 > 0x7fffffff) || (i1 > i2 && i1 - i2 < 0x7fffffff) diff --git a/packages/ensjs/src/functions/dns/getDnsOffchainData.ts b/packages/ensjs/src/functions/dns/getDnsOffchainData.ts index 11beda84..9919da3b 100644 --- a/packages/ensjs/src/functions/dns/getDnsOffchainData.ts +++ b/packages/ensjs/src/functions/dns/getDnsOffchainData.ts @@ -32,6 +32,15 @@ export type GetDnsOffchainDataReturnType = { extraData: string | null } | null +export type GetDnsOffchainDataErrorType = + | DnsDnssecVerificationFailedError + | DnsDnssecWildcardExpansionError + | DnsInvalidTxtRecordError + | DnsNoTxtRecordError + | DnsResponseStatusError + | UnsupportedNameTypeError + | Error + type ValidTextRecord = { isValid: true resolverAddress: Address diff --git a/packages/ensjs/src/functions/dns/getDnsOwner.ts b/packages/ensjs/src/functions/dns/getDnsOwner.ts index 7c40fee3..057a061a 100644 --- a/packages/ensjs/src/functions/dns/getDnsOwner.ts +++ b/packages/ensjs/src/functions/dns/getDnsOwner.ts @@ -23,6 +23,15 @@ export type GetDnsOwnerParameters = { export type GetDnsOwnerReturnType = Address | null +export type GetDnsOwnerErrorType = + | DnsDnssecVerificationFailedError + | DnsInvalidAddressChecksumError + | DnsInvalidTxtRecordError + | DnsNoTxtRecordError + | DnsResponseStatusError + | UnsupportedNameTypeError + | Error + /** * Gets the DNS owner of a name, via DNS record lookup * @param parameters - {@link GetDnsOwnerParameters} diff --git a/packages/ensjs/src/functions/dns/importDnsName.ts b/packages/ensjs/src/functions/dns/importDnsName.ts index 78596852..7a8864db 100644 --- a/packages/ensjs/src/functions/dns/importDnsName.ts +++ b/packages/ensjs/src/functions/dns/importDnsName.ts @@ -60,6 +60,8 @@ export type ImportDnsNameParameters< export type ImportDnsNameReturnType = Hash +export type ImportDnsNameErrorType = AdditionalParameterSpecifiedError | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/public/_getAbi.ts b/packages/ensjs/src/functions/public/_getAbi.ts index a02d5ea7..4c83e10a 100644 --- a/packages/ensjs/src/functions/public/_getAbi.ts +++ b/packages/ensjs/src/functions/public/_getAbi.ts @@ -32,6 +32,8 @@ export type InternalGetAbiParameters = { export type InternalGetAbiReturnType = Prettify +export type InternalGetAbiErrorType = Error + const encode = ( _client: ClientWithEns, { diff --git a/packages/ensjs/src/functions/public/_getAddr.ts b/packages/ensjs/src/functions/public/_getAddr.ts index d031a8dd..8d4d763d 100644 --- a/packages/ensjs/src/functions/public/_getAddr.ts +++ b/packages/ensjs/src/functions/public/_getAddr.ts @@ -34,6 +34,8 @@ export type InternalGetAddrParameters = { export type InternalGetAddrReturnType = Prettify +export type InternalGetAddrErrorType = Error + const encode = ( _client: ClientWithEns, { name, coin = 60, bypassFormat }: Omit, diff --git a/packages/ensjs/src/functions/public/_getContentHash.ts b/packages/ensjs/src/functions/public/_getContentHash.ts index e0baf32a..d22a2998 100644 --- a/packages/ensjs/src/functions/public/_getContentHash.ts +++ b/packages/ensjs/src/functions/public/_getContentHash.ts @@ -20,6 +20,8 @@ export type InternalGetContentHashParameters = { export type InternalGetContentHashReturnType = Prettify +export type InternalGetContentHashErrorType = Error + const encode = ( _client: ClientWithEns, { name }: Omit, diff --git a/packages/ensjs/src/functions/public/_getText.ts b/packages/ensjs/src/functions/public/_getText.ts index 8e6473a3..a3044588 100644 --- a/packages/ensjs/src/functions/public/_getText.ts +++ b/packages/ensjs/src/functions/public/_getText.ts @@ -17,6 +17,8 @@ export type InternalGetTextParameters = { export type InternalGetTextReturnType = string | null +export type InternalGetTextErrorType = Error + const encode = ( _client: ClientWithEns, { name, key }: Omit, diff --git a/packages/ensjs/src/functions/public/batch.ts b/packages/ensjs/src/functions/public/batch.ts index cc5967cf..c08bea10 100644 --- a/packages/ensjs/src/functions/public/batch.ts +++ b/packages/ensjs/src/functions/public/batch.ts @@ -24,6 +24,8 @@ export type BatchReturnType = { [TFunctionName in keyof TFunctions]: ExtractResult } +export type BatchErrorType = Error + const encode = ( client: ClientWithEns, ...items: BatchFunctionResult[] diff --git a/packages/ensjs/src/functions/public/getAbiRecord.ts b/packages/ensjs/src/functions/public/getAbiRecord.ts index 53dbe42d..9757f860 100644 --- a/packages/ensjs/src/functions/public/getAbiRecord.ts +++ b/packages/ensjs/src/functions/public/getAbiRecord.ts @@ -10,6 +10,7 @@ import { type GeneratedFunction, } from '../../utils/generateFunction.js' import _getAbi, { + type InternalGetAbiErrorType, type InternalGetAbiParameters, type InternalGetAbiReturnType, } from './_getAbi.js' @@ -24,6 +25,8 @@ export type GetAbiRecordParameters = Prettify< export type GetAbiRecordReturnType = Prettify +export type GetAbiRecordErrorType = InternalGetAbiErrorType + const encode = ( client: ClientWithEns, { diff --git a/packages/ensjs/src/functions/public/getAddressRecord.ts b/packages/ensjs/src/functions/public/getAddressRecord.ts index fbf79bd2..6f3e8de1 100644 --- a/packages/ensjs/src/functions/public/getAddressRecord.ts +++ b/packages/ensjs/src/functions/public/getAddressRecord.ts @@ -10,6 +10,7 @@ import { type GeneratedFunction, } from '../../utils/generateFunction.js' import _getAddr, { + type InternalGetAddrErrorType, type InternalGetAddrParameters, type InternalGetAddrReturnType, } from './_getAddr.js' @@ -24,6 +25,8 @@ export type GetAddressRecordParameters = Prettify< export type GetAddressRecordReturnType = Prettify +export type GetAddressRecordErrorType = InternalGetAddrErrorType + const encode = ( client: ClientWithEns, { diff --git a/packages/ensjs/src/functions/public/getAvailable.ts b/packages/ensjs/src/functions/public/getAvailable.ts index 04d1132d..8b4bbeb7 100644 --- a/packages/ensjs/src/functions/public/getAvailable.ts +++ b/packages/ensjs/src/functions/public/getAvailable.ts @@ -23,6 +23,8 @@ export type GetAvailableParameters = { export type GetAvailableReturnType = boolean +export type GetAvailableErrorType = UnsupportedNameTypeError | Error + const encode = ( client: ClientWithEns, { name }: GetAvailableParameters, diff --git a/packages/ensjs/src/functions/public/getContentHashRecord.ts b/packages/ensjs/src/functions/public/getContentHashRecord.ts index 4d19cee9..cbe7e1aa 100644 --- a/packages/ensjs/src/functions/public/getContentHashRecord.ts +++ b/packages/ensjs/src/functions/public/getContentHashRecord.ts @@ -10,6 +10,7 @@ import { type GeneratedFunction, } from '../../utils/generateFunction.js' import _getContentHash, { + type InternalGetContentHashErrorType, type InternalGetContentHashParameters, type InternalGetContentHashReturnType, } from './_getContentHash.js' @@ -25,6 +26,8 @@ export type GetContentHashRecordParameters = Prettify< export type GetContentHashRecordReturnType = Prettify +export type GetContentHashRecordErrorType = InternalGetContentHashErrorType + const encode = ( client: ClientWithEns, { name, gatewayUrls }: Omit, diff --git a/packages/ensjs/src/functions/public/getCredentials.ts b/packages/ensjs/src/functions/public/getCredentials.ts new file mode 100644 index 00000000..28f24d20 --- /dev/null +++ b/packages/ensjs/src/functions/public/getCredentials.ts @@ -0,0 +1,96 @@ +import type { BaseError, Hex } from 'viem' +import type { ClientWithEns } from '../../contracts/consts.js' +import type { + GenericPassthrough, + Prettify, + SimpleTransactionRequest, +} from '../../types.js' +import { + generateFunction, + type GeneratedFunction, +} from '../../utils/generateFunction.js' +import type { + GetTextRecordErrorType, + GetTextRecordParameters, +} from './getTextRecord.js' +import getTextRecord from './getTextRecord.js' + +export type GetCredentialsParameters = Prettify< + Omit +> + +export type GetCredentialsReturnType = ExternalCredential[] | null + +export type GetCredentialsErrorType = GetTextRecordErrorType + +export type ExternalCredential = { + url: string +} + +const encode = ( + client: ClientWithEns, + { name, gatewayUrls }: Omit, +): SimpleTransactionRequest => { + return getTextRecord.encode(client, { + name, + key: 'verifications', + gatewayUrls, + }) +} + +const parseCredentials = (credentials: string[]) => { + const externalCredentials: ExternalCredential[] = [] + for (const credential of credentials) { + if (URL.canParse(credential)) externalCredentials.push({ url: credential }) + } + + return externalCredentials +} + +const decode = async ( + client: ClientWithEns, + data: Hex | BaseError, + passthrough: GenericPassthrough, + { + strict, + gatewayUrls, + }: Pick, +): Promise => { + const result = await getTextRecord.decode(client, data, passthrough, { + strict, + gatewayUrls, + }) + if (!result) return null + + const credentials = JSON.parse(result) as string[] + return parseCredentials(credentials) +} + +type BatchableFunctionObject = GeneratedFunction + +/** + * Gets credentials for a name. + * @param client - {@link ClientWithEns} + * @param parameters - {@link GetCredentialsParameters} + * @returns Credentials, or null if none are found. {@link GetCredentialsReturnType} + * + * @example + * import { createPublicClient, http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts } from '@ensdomains/ensjs' + * import { getCredentials } from '@ensdomains/ensjs/public' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }) + * const result = await getCredentials(client, { name: 'ens.eth' }) + * // [{ url: 'https://example.com' }] + */ +const getCredentials = generateFunction({ encode, decode }) as (( + client: ClientWithEns, + { name, strict, gatewayUrls }: GetCredentialsParameters, +) => Promise) & + BatchableFunctionObject + +export default getCredentials diff --git a/packages/ensjs/src/functions/public/getExpiry.ts b/packages/ensjs/src/functions/public/getExpiry.ts index 438c3f89..cef4aeec 100644 --- a/packages/ensjs/src/functions/public/getExpiry.ts +++ b/packages/ensjs/src/functions/public/getExpiry.ts @@ -46,6 +46,8 @@ export type GetExpiryReturnType = Prettify<{ status: ExpiryStatus } | null> +export type GetExpiryErrorType = Error + const getContractToUse = ( contract: ContractOption | undefined, labels: string[], diff --git a/packages/ensjs/src/functions/public/getName.ts b/packages/ensjs/src/functions/public/getName.ts index 69ef7294..47727913 100644 --- a/packages/ensjs/src/functions/public/getName.ts +++ b/packages/ensjs/src/functions/public/getName.ts @@ -47,6 +47,8 @@ export type GetNameReturnType = { resolverAddress: Address } +export type GetNameErrorType = Error + const encode = ( client: ClientWithEns, { address, gatewayUrls }: Omit, diff --git a/packages/ensjs/src/functions/public/getOwner.ts b/packages/ensjs/src/functions/public/getOwner.ts index 2e9e4ec1..830cb602 100644 --- a/packages/ensjs/src/functions/public/getOwner.ts +++ b/packages/ensjs/src/functions/public/getOwner.ts @@ -67,6 +67,8 @@ export type GetOwnerReturnType< : WrappedOwnership | UnwrappedEth2ldOwnership | UnwrappedOwnership)) | null +export type GetOwnerErrorType = Error + const encode = ( client: ClientWithEns, { name, contract }: GetOwnerParameters, diff --git a/packages/ensjs/src/functions/public/getPrice.ts b/packages/ensjs/src/functions/public/getPrice.ts index 36989639..faed0677 100644 --- a/packages/ensjs/src/functions/public/getPrice.ts +++ b/packages/ensjs/src/functions/public/getPrice.ts @@ -31,6 +31,8 @@ export type GetPriceReturnType = { premium: bigint } +export type GetPriceErrorType = UnsupportedNameTypeError | Error + const encode = ( client: ClientWithEns, { nameOrNames, duration }: GetPriceParameters, diff --git a/packages/ensjs/src/functions/public/getRecords.ts b/packages/ensjs/src/functions/public/getRecords.ts index 5c9e68c9..aa90fbb1 100644 --- a/packages/ensjs/src/functions/public/getRecords.ts +++ b/packages/ensjs/src/functions/public/getRecords.ts @@ -101,6 +101,8 @@ export type GetRecordsReturnType< } > +export type GetRecordsErrorType = Error + type CallObj = | { key: string diff --git a/packages/ensjs/src/functions/public/getResolver.ts b/packages/ensjs/src/functions/public/getResolver.ts index 178b2ecd..60aade12 100644 --- a/packages/ensjs/src/functions/public/getResolver.ts +++ b/packages/ensjs/src/functions/public/getResolver.ts @@ -28,6 +28,8 @@ export type GetResolverParameters = { export type GetResolverReturnType = Address | null +export type GetResolverErrorType = Error + const encode = ( client: ClientWithEns, { name }: GetResolverParameters, diff --git a/packages/ensjs/src/functions/public/getSupportedInterfaces.ts b/packages/ensjs/src/functions/public/getSupportedInterfaces.ts index eea3012e..93b3064d 100644 --- a/packages/ensjs/src/functions/public/getSupportedInterfaces.ts +++ b/packages/ensjs/src/functions/public/getSupportedInterfaces.ts @@ -27,6 +27,8 @@ export type GetSupportedInterfacesReturnType< -readonly [K in keyof TInterfaces]: boolean } +export type GetSupportedInterfacesErrorType = Error + const encodeInterface = (interfaceId: Hex): Hex => encodeFunctionData({ abi: erc165SupportsInterfaceSnippet, diff --git a/packages/ensjs/src/functions/public/getTextRecord.ts b/packages/ensjs/src/functions/public/getTextRecord.ts index c2836180..4ad37806 100644 --- a/packages/ensjs/src/functions/public/getTextRecord.ts +++ b/packages/ensjs/src/functions/public/getTextRecord.ts @@ -10,6 +10,7 @@ import { type GeneratedFunction, } from '../../utils/generateFunction.js' import _getText, { + type InternalGetTextErrorType, type InternalGetTextParameters, type InternalGetTextReturnType, } from './_getText.js' @@ -24,6 +25,8 @@ export type GetTextRecordParameters = Prettify< export type GetTextRecordReturnType = Prettify +export type GetTextRecordErrorType = InternalGetTextErrorType + const encode = ( client: ClientWithEns, { name, key, gatewayUrls }: Omit, diff --git a/packages/ensjs/src/functions/public/getWrapperData.ts b/packages/ensjs/src/functions/public/getWrapperData.ts index 054b47ae..0789b673 100644 --- a/packages/ensjs/src/functions/public/getWrapperData.ts +++ b/packages/ensjs/src/functions/public/getWrapperData.ts @@ -40,6 +40,8 @@ export type GetWrapperDataReturnType = Prettify<{ owner: Address } | null> +export type GetWrapperDataErrorType = Error + const encode = ( client: ClientWithEns, { name }: GetWrapperDataParameters, diff --git a/packages/ensjs/src/functions/public/getWrapperName.ts b/packages/ensjs/src/functions/public/getWrapperName.ts index 6d61a608..18014186 100644 --- a/packages/ensjs/src/functions/public/getWrapperName.ts +++ b/packages/ensjs/src/functions/public/getWrapperName.ts @@ -27,6 +27,8 @@ export type GetWrapperNameParameters = { export type GetWrapperNameReturnType = string | null +export type GetWrapperNameErrorType = Error + const encode = ( client: ClientWithEns, { name }: GetWrapperNameParameters, diff --git a/packages/ensjs/src/functions/public/multicallWrapper.ts b/packages/ensjs/src/functions/public/multicallWrapper.ts index 1aa17a2f..9ac3c687 100644 --- a/packages/ensjs/src/functions/public/multicallWrapper.ts +++ b/packages/ensjs/src/functions/public/multicallWrapper.ts @@ -25,6 +25,8 @@ export type MulticallWrapperReturnType = { returnData: Hex }[] +export type MulticallWrapperErrorType = Error + const encode = ( client: ClientWithEns, { transactions, requireSuccess = false }: MulticallWrapperParameters, diff --git a/packages/ensjs/src/functions/public/universalWrapper.ts b/packages/ensjs/src/functions/public/universalWrapper.ts index 96faab6a..e6dcf0df 100644 --- a/packages/ensjs/src/functions/public/universalWrapper.ts +++ b/packages/ensjs/src/functions/public/universalWrapper.ts @@ -35,6 +35,8 @@ export type UniversalWrapperReturnType = { resolver: Address } | null +export type UniversalWrapperErrorType = Error + const encode = ( client: ClientWithEns, { name, data, gatewayUrls }: Omit, diff --git a/packages/ensjs/src/functions/subgraph/getDecodedName.ts b/packages/ensjs/src/functions/subgraph/getDecodedName.ts index 16a13cef..22dc6611 100644 --- a/packages/ensjs/src/functions/subgraph/getDecodedName.ts +++ b/packages/ensjs/src/functions/subgraph/getDecodedName.ts @@ -17,6 +17,8 @@ export type GetDecodedNameParameters = { export type GetDecodedNameReturnType = string | null +export type GetDecodedNameErrorType = Error + type SubgraphResult = { namehashLookup?: { name: string } } & { diff --git a/packages/ensjs/src/functions/subgraph/getNameHistory.ts b/packages/ensjs/src/functions/subgraph/getNameHistory.ts index 08e1bf8d..de860aaf 100644 --- a/packages/ensjs/src/functions/subgraph/getNameHistory.ts +++ b/packages/ensjs/src/functions/subgraph/getNameHistory.ts @@ -19,6 +19,17 @@ export type GetNameHistoryParameters = { name: string } +export type GetNameHistoryReturnType = { + /** Array of domain events */ + domainEvents: ReturnDomainEvent[] + /** Array of registration events */ + registrationEvents: ReturnRegistrationEvent[] | null + /** Array of resolver events */ + resolverEvents: ReturnResolverEvent[] | null +} | null + +export type GetNameHistoryErrorType = Error + type SubgraphResult = { domain?: { events: DomainEvent[] @@ -54,15 +65,6 @@ type ReturnResolverEvent = FlattenedEvent< }) > -export type GetNameHistoryReturnType = { - /** Array of domain events */ - domainEvents: ReturnDomainEvent[] - /** Array of registration events */ - registrationEvents: ReturnRegistrationEvent[] | null - /** Array of resolver events */ - resolverEvents: ReturnResolverEvent[] | null -} | null - /** * Gets the history of a name from the subgraph. * @param client - {@link ClientWithEns} diff --git a/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts b/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts index 3054e2a3..e0e8d863 100644 --- a/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts +++ b/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts @@ -18,6 +18,29 @@ import { } from './fragments.js' import { makeNameObject, type Name } from './utils.js' +export type GetNamesForAddressParameters = { + /** Address to get names for */ + address: Address + /** Names to get, in relation to address */ + filter?: GetNamesForAddressFilter + /** Parameter to order names by (default: name) */ + orderBy?: GetNamesForAddressOrderBy + /** Direction to order names in (default: asc) */ + orderDirection?: 'asc' | 'desc' + /** Previous page of names, used for pagination */ + previousPage?: NameWithRelation[] + /** Page size (default: 100) */ + pageSize?: number +} + +export type GetNamesForAddressReturnType = NameWithRelation[] + +export type GetNamesForAddressErrorType = + | InvalidOrderByError + | InvalidFilterKeyError + | FilterKeyRequiredError + | Error + const supportedOwnerFilters = [ 'owner', 'registrant', @@ -55,27 +78,10 @@ type GetNamesForAddressFilter = GetNamesForAddressRelation & { allowDeleted?: boolean } -export type GetNamesForAddressParameters = { - /** Address to get names for */ - address: Address - /** Names to get, in relation to address */ - filter?: GetNamesForAddressFilter - /** Parameter to order names by (default: name) */ - orderBy?: GetNamesForAddressOrderBy - /** Direction to order names in (default: asc) */ - orderDirection?: 'asc' | 'desc' - /** Previous page of names, used for pagination */ - previousPage?: NameWithRelation[] - /** Page size (default: 100) */ - pageSize?: number -} - export type NameWithRelation = Name & { relation: GetNamesForAddressRelation } -export type GetNamesForAddressReturnType = NameWithRelation[] - type SubgraphResult = { domains: SubgraphDomain[] } diff --git a/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts b/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts index 36eaf1af..90869050 100644 --- a/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts +++ b/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts @@ -24,6 +24,8 @@ export type GetSubgraphRecordsReturnType = { coins: string[] } | null +export type GetSubgraphRecordsErrorType = Error + const inheritedResolverQuery = gql` query getSubgraphRecords($id: String!) { domain(id: $id) { diff --git a/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts b/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts index e22ec6cd..69e919b5 100644 --- a/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts +++ b/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts @@ -12,6 +12,8 @@ export type GetSubgraphRegistrantParameters = { export type GetSubgraphRegistrantReturnType = Address | null +export type GetSubgraphRegistrantErrorType = UnsupportedNameTypeError | Error + const query = gql` query getSubgraphRegistrant($id: String!) { registration(id: $id) { diff --git a/packages/ensjs/src/functions/subgraph/getSubnames.ts b/packages/ensjs/src/functions/subgraph/getSubnames.ts index a53b1a3e..30f8ce81 100644 --- a/packages/ensjs/src/functions/subgraph/getSubnames.ts +++ b/packages/ensjs/src/functions/subgraph/getSubnames.ts @@ -14,8 +14,6 @@ import { } from './fragments.js' import { makeNameObject, type Name } from './utils.js' -type GetSubnamesOrderBy = 'expiryDate' | 'name' | 'labelName' | 'createdAt' - export type GetSubnamesParameters = { /** Name to get subnames for */ name: string @@ -37,6 +35,10 @@ export type GetSubnamesParameters = { export type GetSubnamesReturnType = Name[] +export type GetSubnamesErrorType = InvalidOrderByError | Error + +type GetSubnamesOrderBy = 'expiryDate' | 'name' | 'labelName' | 'createdAt' + type SubgraphResult = { domain?: { subdomains: SubgraphDomain[] diff --git a/packages/ensjs/src/functions/wallet/clearRecords.ts b/packages/ensjs/src/functions/wallet/clearRecords.ts index 14ba6e06..d3b8f006 100644 --- a/packages/ensjs/src/functions/wallet/clearRecords.ts +++ b/packages/ensjs/src/functions/wallet/clearRecords.ts @@ -35,6 +35,8 @@ export type ClearRecordsParameters< export type ClearRecordsReturnType = Hash +export type ClearRecordsErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/commitName.ts b/packages/ensjs/src/functions/wallet/commitName.ts index 653323f8..49f6a664 100644 --- a/packages/ensjs/src/functions/wallet/commitName.ts +++ b/packages/ensjs/src/functions/wallet/commitName.ts @@ -10,6 +10,7 @@ import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js' import { ethRegistrarControllerCommitSnippet } from '../../contracts/ethRegistrarController.js' import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' import { UnsupportedNameTypeError } from '../../errors/general.js' +import type { WrappedLabelTooLargeError } from '../../errors/utils.js' import type { Prettify, SimpleTransactionRequest, @@ -37,6 +38,11 @@ export type CommitNameParameters< export type CommitNameReturnType = Hash +export type CommitNameErrorType = + | UnsupportedNameTypeError + | WrappedLabelTooLargeError + | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/createSubname.ts b/packages/ensjs/src/functions/wallet/createSubname.ts index 219f47cc..c75f16db 100644 --- a/packages/ensjs/src/functions/wallet/createSubname.ts +++ b/packages/ensjs/src/functions/wallet/createSubname.ts @@ -15,10 +15,12 @@ import type { import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' import { nameWrapperSetSubnodeRecordSnippet } from '../../contracts/nameWrapper.js' import { registrySetSubnodeRecordSnippet } from '../../contracts/registry.js' +import { BaseError } from '../../errors/base.js' import { InvalidContractTypeError, UnsupportedNameTypeError, } from '../../errors/general.js' +import type { WrappedLabelTooLargeError } from '../../errors/utils.js' import type { AnyDate, Prettify, @@ -26,19 +28,18 @@ import type { WriteTransactionParameters, } from '../../types.js' import { - encodeFuses, ParentFuses, + encodeFuses, type EncodeFusesInputObject, } from '../../utils/fuses.js' import { getNameType } from '../../utils/getNameType.js' import { makeLabelNodeAndParent } from '../../utils/makeLabelNodeAndParent.js' import { expiryToBigInt, - wrappedLabelLengthCheck, makeDefaultExpiry, + wrappedLabelLengthCheck, } from '../../utils/wrapper.js' import getWrapperData from '../public/getWrapperData.js' -import { BaseError } from '../../errors/base.js' type BaseCreateSubnameDataParameters = { /** Subname to create */ @@ -83,6 +84,12 @@ export type CreateSubnameParameters< export type CreateSubnameReturnType = Hash +export type CreateSubnameErrorType = + | InvalidContractTypeError + | UnsupportedNameTypeError + | WrappedLabelTooLargeError + | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/deleteSubname.ts b/packages/ensjs/src/functions/wallet/deleteSubname.ts index b063337a..5f65ded4 100644 --- a/packages/ensjs/src/functions/wallet/deleteSubname.ts +++ b/packages/ensjs/src/functions/wallet/deleteSubname.ts @@ -52,6 +52,11 @@ export type DeleteSubnameParameters< export type DeleteSubnameReturnType = Hash +export type DeleteSubnameErrorType = + | InvalidContractTypeError + | UnsupportedNameTypeError + | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/registerName.ts b/packages/ensjs/src/functions/wallet/registerName.ts index 5980e9f5..070a8371 100644 --- a/packages/ensjs/src/functions/wallet/registerName.ts +++ b/packages/ensjs/src/functions/wallet/registerName.ts @@ -10,6 +10,7 @@ import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js' import { ethRegistrarControllerRegisterSnippet } from '../../contracts/ethRegistrarController.js' import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' import { UnsupportedNameTypeError } from '../../errors/general.js' +import type { WrappedLabelTooLargeError } from '../../errors/utils.js' import type { Prettify, SimpleTransactionRequest, @@ -42,6 +43,11 @@ export type RegisterNameParameters< export type RegisterNameReturnType = Hash +export type RegisterNameErrorType = + | UnsupportedNameTypeError + | WrappedLabelTooLargeError + | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/renewNames.ts b/packages/ensjs/src/functions/wallet/renewNames.ts index 2316d233..e7e26d4c 100644 --- a/packages/ensjs/src/functions/wallet/renewNames.ts +++ b/packages/ensjs/src/functions/wallet/renewNames.ts @@ -42,6 +42,8 @@ export type RenewNamesParameters< export type RenewNamesReturnType = Hash +export type RenewNamesErrorType = UnsupportedNameTypeError | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setAbiRecord.ts b/packages/ensjs/src/functions/wallet/setAbiRecord.ts index de27fd77..c1d87437 100644 --- a/packages/ensjs/src/functions/wallet/setAbiRecord.ts +++ b/packages/ensjs/src/functions/wallet/setAbiRecord.ts @@ -41,6 +41,8 @@ export type SetAbiRecordParameters< export type SetAbiRecordReturnType = Hash +export type SetAbiRecordErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setAddressRecord.ts b/packages/ensjs/src/functions/wallet/setAddressRecord.ts index 740d1b24..09658006 100644 --- a/packages/ensjs/src/functions/wallet/setAddressRecord.ts +++ b/packages/ensjs/src/functions/wallet/setAddressRecord.ts @@ -39,6 +39,8 @@ export type SetAddressRecordParameters< export type SetAddressRecordReturnType = Hash +export type SetAddressRecordErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setChildFuses.ts b/packages/ensjs/src/functions/wallet/setChildFuses.ts index ce9e9829..aff1c869 100644 --- a/packages/ensjs/src/functions/wallet/setChildFuses.ts +++ b/packages/ensjs/src/functions/wallet/setChildFuses.ts @@ -40,6 +40,8 @@ export type SetChildFusesParameters< export type SetChildFusesReturnType = Hash +export type SetChildFusesErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setContentHashRecord.ts b/packages/ensjs/src/functions/wallet/setContentHashRecord.ts index ea248a50..e3543af6 100644 --- a/packages/ensjs/src/functions/wallet/setContentHashRecord.ts +++ b/packages/ensjs/src/functions/wallet/setContentHashRecord.ts @@ -37,6 +37,8 @@ export type SetContentHashRecordParameters< export type SetContentHashRecordReturnType = Hash +export type SetContentHashRecordErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setFuses.ts b/packages/ensjs/src/functions/wallet/setFuses.ts index 37f97c11..de4238cd 100644 --- a/packages/ensjs/src/functions/wallet/setFuses.ts +++ b/packages/ensjs/src/functions/wallet/setFuses.ts @@ -40,6 +40,8 @@ export type SetFusesParameters< export type SetFusesReturnType = Hash +export type SetFusesErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setPrimaryName.ts b/packages/ensjs/src/functions/wallet/setPrimaryName.ts index 19b4089b..cbedd303 100644 --- a/packages/ensjs/src/functions/wallet/setPrimaryName.ts +++ b/packages/ensjs/src/functions/wallet/setPrimaryName.ts @@ -55,6 +55,8 @@ export type SetPrimaryNameParameters< export type SetPrimaryNameReturnType = Hash +export type SetPrimaryNameErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account, diff --git a/packages/ensjs/src/functions/wallet/setRecords.ts b/packages/ensjs/src/functions/wallet/setRecords.ts index 2f855a17..c2276148 100644 --- a/packages/ensjs/src/functions/wallet/setRecords.ts +++ b/packages/ensjs/src/functions/wallet/setRecords.ts @@ -7,7 +7,11 @@ import { type Transport, } from 'viem' import { sendTransaction } from 'viem/actions' -import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js' +import type { + ChainWithEns, + ClientWithAccount, + ClientWithEns, +} from '../../contracts/consts.js' import { publicResolverMulticallSnippet } from '../../contracts/publicResolver.js' import { NoRecordsSpecifiedError } from '../../errors/public.js' import type { @@ -41,11 +45,10 @@ export type SetRecordsParameters< export type SetRecordsReturnType = Hash -export const makeFunctionData = < - TChain extends ChainWithEns, - TAccount extends Account | undefined, ->( - _wallet: ClientWithAccount, +export type SetRecordsErrorType = NoRecordsSpecifiedError | Error + +export const encodeSetRecordsData = ( + _client: ClientWithEns, { name, resolverAddress, ...records }: SetRecordsDataParameters, ): SetRecordsDataReturnType => { const callArray = generateRecordCallArray({ @@ -114,7 +117,7 @@ async function setRecords< ...txArgs }: SetRecordsParameters, ): Promise { - const data = makeFunctionData(wallet, { + const data = encodeSetRecordsData(wallet, { name, resolverAddress, clearRecords, @@ -130,6 +133,6 @@ async function setRecords< return sendTransaction(wallet, writeArgs) } -setRecords.makeFunctionData = makeFunctionData +setRecords.encodeData = encodeSetRecordsData export default setRecords diff --git a/packages/ensjs/src/functions/wallet/setResolver.ts b/packages/ensjs/src/functions/wallet/setResolver.ts index 5a187894..c147f3b6 100644 --- a/packages/ensjs/src/functions/wallet/setResolver.ts +++ b/packages/ensjs/src/functions/wallet/setResolver.ts @@ -40,6 +40,8 @@ export type SetResolverParameters< export type SetResolverReturnType = Hash +export type SetResolverErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/setTextRecord.ts b/packages/ensjs/src/functions/wallet/setTextRecord.ts index 879c23c0..7d2f5d11 100644 --- a/packages/ensjs/src/functions/wallet/setTextRecord.ts +++ b/packages/ensjs/src/functions/wallet/setTextRecord.ts @@ -39,6 +39,8 @@ export type SetTextRecordParameters< export type SetTextRecordReturnType = Hash +export type SetTextRecordErrorType = Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account | undefined, diff --git a/packages/ensjs/src/functions/wallet/transferName.ts b/packages/ensjs/src/functions/wallet/transferName.ts index a82fbc0d..aa2eb9bd 100644 --- a/packages/ensjs/src/functions/wallet/transferName.ts +++ b/packages/ensjs/src/functions/wallet/transferName.ts @@ -80,6 +80,12 @@ export type TransferNameParameters< export type TransferNameReturnType = Hash +export type TransferNameErrorType = + | AdditionalParameterSpecifiedError + | InvalidContractTypeError + | UnsupportedNameTypeError + | Error + export const makeFunctionData = < TChain extends ChainWithEns, TAccount extends Account, diff --git a/packages/ensjs/src/functions/wallet/unwrapName.ts b/packages/ensjs/src/functions/wallet/unwrapName.ts index acf36b74..decd2d11 100644 --- a/packages/ensjs/src/functions/wallet/unwrapName.ts +++ b/packages/ensjs/src/functions/wallet/unwrapName.ts @@ -66,6 +66,11 @@ export type UnwrapNameParameters< export type UnwrapNameReturnType = Hash +export type UnwrapNameErrorType = + | AdditionalParameterSpecifiedError + | RequiredParameterNotSpecifiedError + | Error + export const makeFunctionData = < TName extends string, TChain extends ChainWithEns, diff --git a/packages/ensjs/src/functions/wallet/wrapName.ts b/packages/ensjs/src/functions/wallet/wrapName.ts index 9e74c326..b77bd5cb 100644 --- a/packages/ensjs/src/functions/wallet/wrapName.ts +++ b/packages/ensjs/src/functions/wallet/wrapName.ts @@ -16,6 +16,7 @@ import type { ChainWithEns, ClientWithAccount } from '../../contracts/consts.js' import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' import { nameWrapperWrapSnippet } from '../../contracts/nameWrapper.js' import { AdditionalParameterSpecifiedError } from '../../errors/general.js' +import type { WrappedLabelTooLargeError } from '../../errors/utils.js' import type { Eth2ldNameSpecifier, GetNameType, @@ -61,6 +62,11 @@ export type WrapNameParameters< export type WrapNameReturnType = Hash +export type WrapNameErrorType = + | AdditionalParameterSpecifiedError + | WrappedLabelTooLargeError + | Error + export const makeFunctionData = < TName extends string, TChain extends ChainWithEns, diff --git a/packages/ensjs/src/public.ts b/packages/ensjs/src/public.ts index cc00b9fc..72e23468 100644 --- a/packages/ensjs/src/public.ts +++ b/packages/ensjs/src/public.ts @@ -1,100 +1,126 @@ export { default as _getAbi, + type InternalGetAbiErrorType, type InternalGetAbiParameters, type InternalGetAbiReturnType, } from './functions/public/_getAbi.js' export { default as _getAddr, + type InternalGetAddrErrorType, type InternalGetAddrParameters, type InternalGetAddrReturnType, } from './functions/public/_getAddr.js' export { default as _getContentHash, + type InternalGetContentHashErrorType, type InternalGetContentHashParameters, type InternalGetContentHashReturnType, } from './functions/public/_getContentHash.js' export { default as _getText, + type InternalGetTextErrorType, type InternalGetTextParameters, type InternalGetTextReturnType, } from './functions/public/_getText.js' export { default as batch, + type BatchErrorType, type BatchParameters, type BatchReturnType, } from './functions/public/batch.js' export { default as getAbiRecord, + type GetAbiRecordErrorType, type GetAbiRecordParameters, type GetAbiRecordReturnType, } from './functions/public/getAbiRecord.js' export { default as getAddressRecord, + type GetAddressRecordErrorType, type GetAddressRecordParameters, type GetAddressRecordReturnType, } from './functions/public/getAddressRecord.js' export { default as getAvailable, + type GetAvailableErrorType, type GetAvailableParameters, type GetAvailableReturnType, } from './functions/public/getAvailable.js' export { default as getContentHashRecord, + type GetContentHashRecordErrorType, type GetContentHashRecordParameters, type GetContentHashRecordReturnType, } from './functions/public/getContentHashRecord.js' +export { + default as getCredentials, + type GetCredentialsErrorType, + type GetCredentialsParameters, + type GetCredentialsReturnType, +} from './functions/public/getCredentials.js' export { default as getExpiry, + type GetExpiryErrorType, type GetExpiryParameters, type GetExpiryReturnType, } from './functions/public/getExpiry.js' export { default as getName, + type GetNameErrorType, type GetNameParameters, type GetNameReturnType, } from './functions/public/getName.js' export { default as getOwner, + type GetOwnerErrorType, type GetOwnerParameters, type GetOwnerReturnType, } from './functions/public/getOwner.js' export { default as getPrice, + type GetPriceErrorType, type GetPriceParameters, type GetPriceReturnType, } from './functions/public/getPrice.js' export { default as getRecords, + type GetRecordsErrorType, type GetRecordsParameters, type GetRecordsReturnType, } from './functions/public/getRecords.js' export { default as getResolver, + type GetResolverErrorType, type GetResolverParameters, type GetResolverReturnType, } from './functions/public/getResolver.js' export { default as getSupportedInterfaces, + type GetSupportedInterfacesErrorType, type GetSupportedInterfacesParameters, type GetSupportedInterfacesReturnType, } from './functions/public/getSupportedInterfaces.js' export { default as getTextRecord, + type GetTextRecordErrorType, type GetTextRecordParameters, type GetTextRecordReturnType, } from './functions/public/getTextRecord.js' export { default as getWrapperData, + type GetWrapperDataErrorType, type GetWrapperDataParameters, type GetWrapperDataReturnType, } from './functions/public/getWrapperData.js' export { default as multicallWrapper, + type MulticallWrapperErrorType, type MulticallWrapperParameters, type MulticallWrapperReturnType, } from './functions/public/multicallWrapper.js' export { default as universalWrapper, + type UniversalWrapperErrorType, type UniversalWrapperParameters, type UniversalWrapperReturnType, } from './functions/public/universalWrapper.js' diff --git a/packages/ensjs/src/subgraph.ts b/packages/ensjs/src/subgraph.ts index 2a8739d5..c50e7051 100644 --- a/packages/ensjs/src/subgraph.ts +++ b/packages/ensjs/src/subgraph.ts @@ -34,32 +34,38 @@ export type { } from './functions/subgraph/events.js' export { default as getDecodedName, + type GetDecodedNameErrorType, type GetDecodedNameParameters, type GetDecodedNameReturnType, } from './functions/subgraph/getDecodedName.js' export { default as getNameHistory, + type GetNameHistoryErrorType, type GetNameHistoryParameters, type GetNameHistoryReturnType, } from './functions/subgraph/getNameHistory.js' export { default as getNamesForAddress, + type GetNamesForAddressErrorType, type GetNamesForAddressParameters, type GetNamesForAddressReturnType, type NameWithRelation, } from './functions/subgraph/getNamesForAddress.js' export { default as getSubgraphRecords, + type GetSubgraphRecordsErrorType, type GetSubgraphRecordsParameters, type GetSubgraphRecordsReturnType, } from './functions/subgraph/getSubgraphRecords.js' export { default as getSubgraphRegistrant, + type GetSubgraphRegistrantErrorType, type GetSubgraphRegistrantParameters, type GetSubgraphRegistrantReturnType, } from './functions/subgraph/getSubgraphRegistrant.js' export { default as getSubnames, + type GetSubnamesErrorType, type GetSubnamesParameters, type GetSubnamesReturnType, } from './functions/subgraph/getSubnames.js' diff --git a/packages/ensjs/src/wallet.ts b/packages/ensjs/src/wallet.ts index b4ae0382..034a2e2d 100644 --- a/packages/ensjs/src/wallet.ts +++ b/packages/ensjs/src/wallet.ts @@ -2,6 +2,7 @@ export { default as clearRecords, type ClearRecordsDataParameters, type ClearRecordsDataReturnType, + type ClearRecordsErrorType, type ClearRecordsParameters, type ClearRecordsReturnType, } from './functions/wallet/clearRecords.js' @@ -9,6 +10,7 @@ export { default as commitName, type CommitNameDataParameters, type CommitNameDataReturnType, + type CommitNameErrorType, type CommitNameParameters, type CommitNameReturnType, } from './functions/wallet/commitName.js' @@ -16,6 +18,7 @@ export { default as createSubname, type CreateSubnameDataParameters, type CreateSubnameDataReturnType, + type CreateSubnameErrorType, type CreateSubnameParameters, type CreateSubnameReturnType, } from './functions/wallet/createSubname.js' @@ -23,6 +26,7 @@ export { default as deleteSubname, type DeleteSubnameDataParameters, type DeleteSubnameDataReturnType, + type DeleteSubnameErrorType, type DeleteSubnameParameters, type DeleteSubnameReturnType, } from './functions/wallet/deleteSubname.js' @@ -30,6 +34,7 @@ export { default as registerName, type RegisterNameDataParameters, type RegisterNameDataReturnType, + type RegisterNameErrorType, type RegisterNameParameters, type RegisterNameReturnType, } from './functions/wallet/registerName.js' @@ -37,6 +42,7 @@ export { default as renewNames, type RenewNamesDataParameters, type RenewNamesDataReturnType, + type RenewNamesErrorType, type RenewNamesParameters, type RenewNamesReturnType, } from './functions/wallet/renewNames.js' @@ -44,6 +50,7 @@ export { default as setAbiRecord, type SetAbiRecordDataParameters, type SetAbiRecordDataReturnType, + type SetAbiRecordErrorType, type SetAbiRecordParameters, type SetAbiRecordReturnType, } from './functions/wallet/setAbiRecord.js' @@ -51,6 +58,7 @@ export { default as setAddressRecord, type SetAddressRecordDataParameters, type SetAddressRecordDataReturnType, + type SetAddressRecordErrorType, type SetAddressRecordParameters, type SetAddressRecordReturnType, } from './functions/wallet/setAddressRecord.js' @@ -58,6 +66,7 @@ export { default as setChildFuses, type SetChildFusesDataParameters, type SetChildFusesDataReturnType, + type SetChildFusesErrorType, type SetChildFusesParameters, type SetChildFusesReturnType, } from './functions/wallet/setChildFuses.js' @@ -65,6 +74,7 @@ export { default as setContentHashRecord, type SetContentHashRecordDataParameters, type SetContentHashRecordDataReturnType, + type SetContentHashRecordErrorType, type SetContentHashRecordParameters, type SetContentHashRecordReturnType, } from './functions/wallet/setContentHashRecord.js' @@ -72,6 +82,7 @@ export { default as setFuses, type SetFusesDataParameters, type SetFusesDataReturnType, + type SetFusesErrorType, type SetFusesParameters, type SetFusesReturnType, } from './functions/wallet/setFuses.js' @@ -79,13 +90,16 @@ export { default as setPrimaryName, type SetPrimaryNameDataParameters, type SetPrimaryNameDataReturnType, + type SetPrimaryNameErrorType, type SetPrimaryNameParameters, type SetPrimaryNameReturnType, } from './functions/wallet/setPrimaryName.js' export { + encodeSetRecordsData, default as setRecords, type SetRecordsDataParameters, type SetRecordsDataReturnType, + type SetRecordsErrorType, type SetRecordsParameters, type SetRecordsReturnType, } from './functions/wallet/setRecords.js' @@ -93,6 +107,7 @@ export { default as setResolver, type SetResolverDataParameters, type SetResolverDataReturnType, + type SetResolverErrorType, type SetResolverParameters, type SetResolverReturnType, } from './functions/wallet/setResolver.js' @@ -100,6 +115,7 @@ export { default as setTextRecord, type SetTextRecordDataParameters, type SetTextRecordDataReturnType, + type SetTextRecordErrorType, type SetTextRecordParameters, type SetTextRecordReturnType, } from './functions/wallet/setTextRecord.js' @@ -107,6 +123,7 @@ export { default as transferName, type TransferNameDataParameters, type TransferNameDataReturnType, + type TransferNameErrorType, type TransferNameParameters, type TransferNameReturnType, } from './functions/wallet/transferName.js' @@ -114,6 +131,7 @@ export { default as unwrapName, type UnwrapNameDataParameters, type UnwrapNameDataReturnType, + type UnwrapNameErrorType, type UnwrapNameParameters, type UnwrapNameReturnType, } from './functions/wallet/unwrapName.js' @@ -121,6 +139,7 @@ export { default as wrapName, type WrapNameDataParameters, type WrapNameDataReturnType, + type WrapNameErrorType, type WrapNameParameters, type WrapNameReturnType, } from './functions/wallet/wrapName.js' diff --git a/packages/react/.eslintrc.json b/packages/react/.eslintrc.json index 28e17e91..fbc03fa7 100644 --- a/packages/react/.eslintrc.json +++ b/packages/react/.eslintrc.json @@ -37,6 +37,10 @@ { "selector": "typeLike", "format": ["PascalCase"] + }, + { + "selector": "typeParameter", + "format": ["camelCase"] } ], "no-useless-return": ["off"], diff --git a/packages/react/README.md b/packages/react/README.md index 40aa413d..e547750e 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -7,7 +7,7 @@ React hooks & utilities to interact with the Ethereum Name Service using ENSjs After installing [wagmi](https://wagmi.sh), simply run ```sh -pnpm install @ensdomains/ensjs-react +pnpm install @ensdomains/ensjs-react @ensdomains/ensjs ``` ## Hooks diff --git a/packages/react/package.json b/packages/react/package.json index 5b41a313..fc3aff5f 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -14,6 +14,11 @@ "import": "./dist/esm/index.js", "default": "./dist/cjs/index.js" }, + "./query": { + "types": "./dist/types/query.d.ts", + "import": "./dist/esm/query.js", + "default": "./dist/cjs/query.js" + }, "./package.json": "./package.json" }, "files": [ @@ -22,8 +27,15 @@ "!src/**/*.test.ts", "!src/test" ], - "repository": "git@github.com:ensdomains/ensjs.git", - "author": "Lucemans ", + "repository": { + "type": "git", + "url": "git+https://github.com/ensdomains/ensjs.git", + "directory": "packages/react" + }, + "contributors": [ + "TateB ", + "Lucemans " + ], "license": "MIT", "scripts": { "clean": "rm -rf ./dist", @@ -49,7 +61,8 @@ "peerDependencies": { "@tanstack/react-query": "^5.54", "viem": "^2.9.2", - "wagmi": "^2" + "wagmi": "^2", + "@ensdomains/ensjs": "^4.0.1" }, "engines": { "node": ">=18" diff --git a/packages/react/src/client.ts b/packages/react/src/client.ts deleted file mode 100644 index 13e3690c..00000000 --- a/packages/react/src/client.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { ClientWithEns } from '@ensdomains/ensjs/contracts' -import type { QueryClient } from '@tanstack/react-query' -import type { UseQueryParameters } from './hooks/useQuery.js' - -export type ParamWithClients = T & { - client: ClientWithEns -} - -export type QueryConfig = { - queryClient?: QueryClient -} & UseQueryParameters diff --git a/packages/react/src/hooks.ts b/packages/react/src/hooks.ts deleted file mode 100644 index c09474f2..00000000 --- a/packages/react/src/hooks.ts +++ /dev/null @@ -1,7 +0,0 @@ -export { useEnsResolverInterfaces } from './hooks/useEnsResolverInterfaces.js' -export { useNamesForAddress } from './hooks/useNamesForAddress.js' -export { useEnsRecordsWrite } from './hooks/useEnsRecordsWrite.js' -export { useEnsCredentials } from './hooks/useEnsCredentials.js' -export { useEnsAvailable } from './hooks/useEnsAvailable.js' -export { useDecodedName } from './hooks/useDecodedName.js' -export { useEnsExpiry } from './hooks/useEnsExpiry.js' diff --git a/packages/react/src/hooks/useDecodedName.ts b/packages/react/src/hooks/useDecodedName.ts index 99486433..cf1b4a81 100644 --- a/packages/react/src/hooks/useDecodedName.ts +++ b/packages/react/src/hooks/useDecodedName.ts @@ -1,14 +1,35 @@ +import { type GetDecodedNameReturnType } from '@ensdomains/ensjs/subgraph' +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' import { - getDecodedName, - type GetDecodedNameParameters, - type GetDecodedNameReturnType, -} from '@ensdomains/ensjs/subgraph' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' + getDecodedNameQueryOptions, + type GetDecodedNameData, + type GetDecodedNameErrorType, + type GetDecodedNameOptions, + type GetDecodedNameQueryFnData, + type GetDecodedNameQueryKey, +} from '../query/getDecodedName.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' -export type UseDecodedNameParams = ParamWithClients +export type UseDecodedNameParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetDecodedNameData, +> = Compute< + GetDecodedNameOptions & + ConfigParameter & + QueryParameter< + GetDecodedNameQueryFnData, + GetDecodedNameErrorType, + selectData, + GetDecodedNameQueryKey + > +> -export type UseDecodedNameReturnType = GetDecodedNameReturnType +export type UseDecodedNameReturnType = + UseQueryReturnType /** * Decode names returned using the subgraph @@ -18,21 +39,22 @@ export type UseDecodedNameReturnType = GetDecodedNameReturnType * @param params - {@link UseDecodedNameParams} * @returns - {@link GetDecodedNameReturnType} */ -export const useDecodedName = ( - params: UseDecodedNameParams, - query?: QueryConfig, -): UseQueryReturnType => { - const { client } = params +export const useDecodedName = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetDecodedNameData, +>( + parameters: UseDecodedNameParameters = {}, +): UseDecodedNameReturnType => { + const { name, query = {} } = parameters - return useQuery( - ['ensjs', 'decoded-subgraph-name', params.name], - { - queryFn: async () => { - const result = await getDecodedName(client, params) + const config = useConfig() + const chainId = useChainId({ config }) - return result - }, - }, - query, - ) + const options = getDecodedNameQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) } diff --git a/packages/react/src/hooks/useEnsAbi.ts b/packages/react/src/hooks/useEnsAbi.ts new file mode 100644 index 00000000..763cb2ea --- /dev/null +++ b/packages/react/src/hooks/useEnsAbi.ts @@ -0,0 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsAbiQueryOptions, + type GetEnsAbiData, + type GetEnsAbiErrorType, + type GetEnsAbiOptions, + type GetEnsAbiQueryFnData, + type GetEnsAbiQueryKey, +} from '../query/getEnsAbi.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsAbiParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsAbiData, +> = Compute< + GetEnsAbiOptions & + ConfigParameter & + QueryParameter< + GetEnsAbiQueryFnData, + GetEnsAbiErrorType, + selectData, + GetEnsAbiQueryKey + > +> + +export type UseEnsAbiReturnType = + UseQueryReturnType + +/** + * Returns the ABI for a name + * + * @param parameters - {@link UseEnsAbiParameters} + * @returns - {@link UseEnsAbiReturnType} + */ +export const useEnsAbi = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsAbiData, +>( + parameters: UseEnsAbiParameters = {}, +): UseEnsAbiReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsAbiQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsAddress.ts b/packages/react/src/hooks/useEnsAddress.ts new file mode 100644 index 00000000..06fbd903 --- /dev/null +++ b/packages/react/src/hooks/useEnsAddress.ts @@ -0,0 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsAddressQueryOptions, + type GetEnsAddressData, + type GetEnsAddressErrorType, + type GetEnsAddressOptions, + type GetEnsAddressQueryFnData, + type GetEnsAddressQueryKey, +} from '../query/getEnsAddress.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsAddressParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsAddressData, +> = Compute< + GetEnsAddressOptions & + ConfigParameter & + QueryParameter< + GetEnsAddressQueryFnData, + GetEnsAddressErrorType, + selectData, + GetEnsAddressQueryKey + > +> + +export type UseEnsAddressReturnType = + UseQueryReturnType + +/** + * Returns the address for a name + * + * @param parameters - {@link UseEnsAddressParameters} + * @returns - {@link UseEnsAddressReturnType} + */ +export const useEnsAddress = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsAddressData, +>( + parameters: UseEnsAddressParameters = {}, +): UseEnsAddressReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsAddressQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsAvailable.ts b/packages/react/src/hooks/useEnsAvailable.ts index cecfc51d..c1ce01f7 100644 --- a/packages/react/src/hooks/useEnsAvailable.ts +++ b/packages/react/src/hooks/useEnsAvailable.ts @@ -1,39 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' import { - getAvailable, - type GetAvailableParameters, - type GetAvailableReturnType, -} from '@ensdomains/ensjs/public' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' + getEnsAvailableQueryOptions, + type GetEnsAvailableData, + type GetEnsAvailableErrorType, + type GetEnsAvailableOptions, + type GetEnsAvailableQueryFnData, + type GetEnsAvailableQueryKey, +} from '../query/getEnsAvailable.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' -export type UseEnsAvailableParams = ParamWithClients +export type UseEnsAvailableParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsAvailableData, +> = Compute< + GetEnsAvailableOptions & + ConfigParameter & + QueryParameter< + GetEnsAvailableQueryFnData, + GetEnsAvailableErrorType, + selectData, + GetEnsAvailableQueryKey + > +> -export type UseEnsAvailableReturnType = GetAvailableReturnType +export type UseEnsAvailableReturnType = + UseQueryReturnType /** - * Returns a list of names for an address + * Check if a .eth name is available * - * Keep in mind that this function is limited to .eth names - * - * @param params - {@link UseEnsAvailableParams} + * @param parameters - {@link UseEnsAvailableParameters} * @returns - {@link UseEnsAvailableReturnType} */ -export const useEnsAvailable = ( - params: UseEnsAvailableParams, - query?: QueryConfig, -): UseQueryReturnType => { - const { client } = params +export const useEnsAvailable = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsAvailableData, +>( + parameters: UseEnsAvailableParameters = {}, +): UseEnsAvailableReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) - return useQuery( - ['ensjs', 'eth-name-available', params.name], - { - queryKey: [], - queryFn: async () => { - const result = await getAvailable(client, params) + const options = getEnsAvailableQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) - return result - }, - }, - query, - ) + return useQuery({ ...query, ...options, enabled }) } diff --git a/packages/react/src/hooks/useEnsContentHash.ts b/packages/react/src/hooks/useEnsContentHash.ts new file mode 100644 index 00000000..01753570 --- /dev/null +++ b/packages/react/src/hooks/useEnsContentHash.ts @@ -0,0 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsContentHashQueryOptions, + type GetEnsContentHashData, + type GetEnsContentHashErrorType, + type GetEnsContentHashOptions, + type GetEnsContentHashQueryFnData, + type GetEnsContentHashQueryKey, +} from '../query/getEnsContentHash.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsContentHashParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsContentHashData, +> = Compute< + GetEnsContentHashOptions & + ConfigParameter & + QueryParameter< + GetEnsContentHashQueryFnData, + GetEnsContentHashErrorType, + selectData, + GetEnsContentHashQueryKey + > +> + +export type UseEnsContentHashReturnType = + UseQueryReturnType + +/** + * Returns the content hash for a name + * + * @param parameters - {@link UseEnsContentHashParameters} + * @returns - {@link UseEnsContentHashReturnType} + */ +export const useEnsContentHash = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsContentHashData, +>( + parameters: UseEnsContentHashParameters = {}, +): UseEnsContentHashReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsContentHashQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsCredentials.ts b/packages/react/src/hooks/useEnsCredentials.ts index e3854184..7c0d622a 100644 --- a/packages/react/src/hooks/useEnsCredentials.ts +++ b/packages/react/src/hooks/useEnsCredentials.ts @@ -1,49 +1,59 @@ -import { getTextRecord } from '@ensdomains/ensjs/public' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' - -export type UseEnsCredentialsParams = ParamWithClients<{ name: string }> - -export type ExternalCredential = { - url: string -} - -export type UseEnsCredentialsReturnType = ExternalCredential[] +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsCredentialsQueryOptions, + type GetEnsCredentialsData, + type GetEnsCredentialsErrorType, + type GetEnsCredentialsOptions, + type GetEnsCredentialsQueryFnData, + type GetEnsCredentialsQueryKey, +} from '../query/getEnsCredentials.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsCredentialsParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsCredentialsData, +> = Compute< + GetEnsCredentialsOptions & + ConfigParameter & + QueryParameter< + GetEnsCredentialsQueryFnData, + GetEnsCredentialsErrorType, + selectData, + GetEnsCredentialsQueryKey + > +> + +export type UseEnsCredentialsReturnType = + UseQueryReturnType /** * Returns credentials from a name * - * @param params - {@link UseEnsCredentialsParams} + * @param parameters - {@link UseEnsCredentialsParameters} * @returns - {@link UseEnsCredentialsReturnType} * * @beta */ -export const useEnsCredentials = ( - params: UseEnsCredentialsParams, - query?: QueryConfig, -): UseQueryReturnType => { - const { name, client } = params - - return useQuery( - ['ensjs', 'credentials', params.name], - { - queryFn: async () => { - const result = await getTextRecord(client, { - name, - key: 'verifications', - }) - - if (!result) return [] - - const credentials = (JSON.parse(result) as string[]) - .filter((url) => new URL(url)) - .map((url) => ({ - url, - })) - - return credentials - }, - }, - query, - ) +export const useEnsCredentials = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsCredentialsData, +>( + parameters: UseEnsCredentialsParameters = {}, +): UseEnsCredentialsReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsCredentialsQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) } diff --git a/packages/react/src/hooks/useEnsExpiry.ts b/packages/react/src/hooks/useEnsExpiry.ts index eb6ee2a3..a57595b8 100644 --- a/packages/react/src/hooks/useEnsExpiry.ts +++ b/packages/react/src/hooks/useEnsExpiry.ts @@ -1,34 +1,59 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' import { - getExpiry, - type GetExpiryParameters, - type GetExpiryReturnType, -} from '@ensdomains/ensjs/public' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' + getEnsExpiryQueryOptions, + type GetEnsExpiryData, + type GetEnsExpiryErrorType, + type GetEnsExpiryOptions, + type GetEnsExpiryQueryFnData, + type GetEnsExpiryQueryKey, +} from '../query/getEnsExpiry.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' -export type UseEnsExpiryParams = ParamWithClients +export type UseEnsExpiryParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsExpiryData, +> = Compute< + GetEnsExpiryOptions & + ConfigParameter & + QueryParameter< + GetEnsExpiryQueryFnData, + GetEnsExpiryErrorType, + selectData, + GetEnsExpiryQueryKey + > +> -export type UseEnsExpiryReturnType = GetExpiryReturnType +export type UseEnsExpiryReturnType = + UseQueryReturnType /** * Returns expiry of a name * * Keep in mind that this function is limited to second-level .eth names (luc.eth, nick.eth, etc) * - * @param params - {@link UseEnsExpiryParams} + * @param parameters - {@link UseEnsExpiryParameters} * @returns - {@link UseEnsExpiryReturnType} */ -export const useEnsExpiry = ( - params: UseEnsExpiryParams, - query?: QueryConfig, -): UseQueryReturnType => { - const { client } = params +export const useEnsExpiry = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsExpiryData, +>( + parameters: UseEnsExpiryParameters = {}, +): UseEnsExpiryReturnType => { + const { name, query = {} } = parameters - return useQuery( - ['ensjs', 'ens-expiry', params.name], - { - queryFn: async () => getExpiry(client, params), - }, - query, - ) + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsExpiryQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) } diff --git a/packages/react/src/hooks/useEnsNamesForAddress.ts b/packages/react/src/hooks/useEnsNamesForAddress.ts new file mode 100644 index 00000000..7101db9a --- /dev/null +++ b/packages/react/src/hooks/useEnsNamesForAddress.ts @@ -0,0 +1,61 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsNamesForAddressQueryOptions, + type GetEnsNamesForAddressData, + type GetEnsNamesForAddressErrorType, + type GetEnsNamesForAddressOptions, + type GetEnsNamesForAddressQueryFnData, + type GetEnsNamesForAddressQueryKey, +} from '../query/getEnsNamesForAddress.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsNamesForAddressParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsNamesForAddressData, +> = Compute< + GetEnsNamesForAddressOptions & + ConfigParameter & + QueryParameter< + GetEnsNamesForAddressQueryFnData, + GetEnsNamesForAddressErrorType, + selectData, + GetEnsNamesForAddressQueryKey + > +> + +export type UseEnsNamesForAddressReturnType< + selectData = GetEnsNamesForAddressData, +> = UseQueryReturnType + +/** + * Returns a list of names for an address + * + * Keep in mind that this list will be loaded from the subgraph, and only include watchable names. + * Read more about enumeration and watchability here: https://docs.ens.domains/web/enumerate + * + * @param parameters - {@link UseEnsNamesForAddressParameters} + * @returns - {@link UseEnsNamesForAddressReturnType} + */ +export const useEnsNamesForAddress = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsNamesForAddressData, +>( + parameters: UseEnsNamesForAddressParameters = {}, +): UseEnsNamesForAddressReturnType => { + const { address, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsNamesForAddressQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(address && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsOwner.ts b/packages/react/src/hooks/useEnsOwner.ts new file mode 100644 index 00000000..b2e4f7d1 --- /dev/null +++ b/packages/react/src/hooks/useEnsOwner.ts @@ -0,0 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsOwnerQueryOptions, + type GetEnsOwnerData, + type GetEnsOwnerErrorType, + type GetEnsOwnerOptions, + type GetEnsOwnerQueryFnData, + type GetEnsOwnerQueryKey, +} from '../query/getEnsOwner.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsOwnerParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsOwnerData, +> = Compute< + GetEnsOwnerOptions & + ConfigParameter & + QueryParameter< + GetEnsOwnerQueryFnData, + GetEnsOwnerErrorType, + selectData, + GetEnsOwnerQueryKey + > +> + +export type UseEnsOwnerReturnType = + UseQueryReturnType + +/** + * Returns the owner of a name + * + * @param parameters - {@link UseEnsOwnerParameters} + * @returns - {@link UseEnsOwnerReturnType} + */ +export const useEnsOwner = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsOwnerData, +>( + parameters: UseEnsOwnerParameters = {}, +): UseEnsOwnerReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsOwnerQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsPrice.ts b/packages/react/src/hooks/useEnsPrice.ts new file mode 100644 index 00000000..5e6ce4b9 --- /dev/null +++ b/packages/react/src/hooks/useEnsPrice.ts @@ -0,0 +1,57 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsPriceQueryOptions, + type GetEnsPriceData, + type GetEnsPriceErrorType, + type GetEnsPriceOptions, + type GetEnsPriceQueryFnData, + type GetEnsPriceQueryKey, +} from '../query/getEnsPrice.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsPriceParameters< + config extends ConfigWithEns = ConfigWithEns, + selectData = GetEnsPriceData, +> = Compute< + GetEnsPriceOptions & + ConfigParameter & + QueryParameter< + GetEnsPriceQueryFnData, + GetEnsPriceErrorType, + selectData, + GetEnsPriceQueryKey + > +> + +export type UseEnsPriceReturnType = + UseQueryReturnType + +/** + * Returns the price for registering or renewing a name + * + * @param parameters - {@link UseEnsPriceParameters} + * @returns - {@link UseEnsPriceReturnType} + */ +export const useEnsPrice = < + config extends ConfigWithEns = ResolvedRegister['config'], + selectData = GetEnsPriceData, +>( + parameters: UseEnsPriceParameters = {}, +): UseEnsPriceReturnType => { + const { nameOrNames, duration, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsPriceQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(nameOrNames && duration && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsRecords.ts b/packages/react/src/hooks/useEnsRecords.ts new file mode 100644 index 00000000..6717b1b3 --- /dev/null +++ b/packages/react/src/hooks/useEnsRecords.ts @@ -0,0 +1,77 @@ +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' +import { + getEnsRecordsQueryOptions, + type GetEnsRecordsData, + type GetEnsRecordsErrorType, + type GetEnsRecordsOptions, + type GetEnsRecordsQueryFnData, + type GetEnsRecordsQueryKey, +} from '../query/getEnsRecords.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseEnsRecordsParameters< + config extends ConfigWithEns = ConfigWithEns, + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, + selectData = GetEnsRecordsData, +> = Compute< + GetEnsRecordsOptions & + ConfigParameter & + QueryParameter< + GetEnsRecordsQueryFnData, + GetEnsRecordsErrorType, + selectData, + GetEnsRecordsQueryKey + > +> + +export type UseEnsRecordsReturnType< + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, + selectData = GetEnsRecordsData, +> = UseQueryReturnType + +/** + * Returns arbitrary records for a name + * + * @param parameters - {@link UseEnsRecordsParameters} + * @returns - {@link UseEnsRecordsReturnType} + */ +export const useEnsRecords = < + config extends ConfigWithEns = ResolvedRegister['config'], + const texts extends readonly string[] | undefined = undefined, + const coins extends readonly (string | number)[] | undefined = undefined, + const contentHash extends boolean | undefined = undefined, + const abi extends boolean | undefined = undefined, + selectData = GetEnsRecordsData, +>( + parameters: UseEnsRecordsParameters< + config, + texts, + coins, + contentHash, + abi, + selectData + > = {}, +): UseEnsRecordsReturnType => { + const { name, query = {} } = parameters + + const config = useConfig() + const chainId = useChainId({ config }) + + const options = getEnsRecordsQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(name && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) +} diff --git a/packages/react/src/hooks/useEnsRecordsWrite.ts b/packages/react/src/hooks/useEnsRecordsWrite.ts deleted file mode 100644 index fa943966..00000000 --- a/packages/react/src/hooks/useEnsRecordsWrite.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { useAccount } from 'wagmi' -import type { ParamWithClients } from '../client.js' - -export type UseEnsRecordsWriteParams = ParamWithClients<{}> - -/** - * Allows you to write records to a name, provided the name supports it and the signed in user has the required permissions - * - * You can use the {@link resolverInterfaces} shorthand, or manually specify a Hex value - * - * @param params - {@link UseEnsResolverInterfacesParams} - * @returns - {@link boolean[]} - * - * @alpha - */ -export const useEnsRecordsWrite = ( - _params: UseEnsRecordsWriteParams, - config?: any, -) => { - const { address } = useAccount({ config }) - // const client = useWalletClient() - - console.log('Hello ', address) - - return { data: undefined } - // return setRecords(client as any, params) -} diff --git a/packages/react/src/hooks/useEnsResolverInterfaces.ts b/packages/react/src/hooks/useEnsResolverInterfaces.ts index 7665ba94..069de1e9 100644 --- a/packages/react/src/hooks/useEnsResolverInterfaces.ts +++ b/packages/react/src/hooks/useEnsResolverInterfaces.ts @@ -1,44 +1,69 @@ import type { Hex } from 'viem' +import { useChainId, useConfig } from 'wagmi' +import { useQuery, type UseQueryReturnType } from 'wagmi/query' import { - getSupportedInterfaces, - type GetSupportedInterfacesParameters, - type GetSupportedInterfacesReturnType, -} from '@ensdomains/ensjs/public' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' + getEnsResolverInterfacesQueryOptions, + type GetEnsResolverInterfacesData, + type GetEnsResolverInterfacesErrorType, + type GetEnsResolverInterfacesOptions, + type GetEnsResolverInterfacesQueryFnData, + type GetEnsResolverInterfacesQueryKey, +} from '../query/getEnsResolverInterfaces.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter, QueryParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' -export type UseEnsResolverInterfacesParams< - Interfaces extends readonly Hex[] = [Hex, Hex], -> = ParamWithClients> +export type UseEnsResolverInterfacesParameters< + config extends ConfigWithEns = ConfigWithEns, + interfaces extends readonly Hex[] = readonly Hex[], + selectData = GetEnsResolverInterfacesData, +> = Compute< + GetEnsResolverInterfacesOptions & + ConfigParameter & + QueryParameter< + GetEnsResolverInterfacesQueryFnData, + GetEnsResolverInterfacesErrorType, + selectData, + GetEnsResolverInterfacesQueryKey + > +> export type UseEnsResolverInterfacesReturnType< - Interfaces extends readonly Hex[], -> = GetSupportedInterfacesReturnType + interfaces extends readonly Hex[], + selectData = GetEnsResolverInterfacesData, +> = UseQueryReturnType /** - * Returns a wether or not the interfaces are supported by the resolver + * Returns whether or not the interfaces are supported by the resolver * You can find a list of interfaces at https://docs.ens.domains/resolvers/interfaces * * You can use the {@link resolverInterfaces} shorthand, or manually specify a Hex value * - * @param params - {@link UseEnsResolverInterfacesParams} - * @returns - {@link boolean[]} + * @param parameters - {@link UseEnsResolverInterfacesParameters} + * @returns - {@link UseEnsResolverInterfacesReturnType} */ -export const useEnsResolverInterfaces = ( - params: UseEnsResolverInterfacesParams, - query?: QueryConfig, -): UseQueryReturnType> => { - const { client } = params +export const useEnsResolverInterfaces = < + config extends ConfigWithEns = ResolvedRegister['config'], + const interfaces extends readonly Hex[] = readonly Hex[], + selectData = GetEnsResolverInterfacesData, +>( + parameters: UseEnsResolverInterfacesParameters< + config, + interfaces, + selectData + > = {}, +): UseEnsResolverInterfacesReturnType => { + const { address, interfaces, query = {} } = parameters - return useQuery( - ['ensjs', 'resolver-interfaces', params.address], - { - queryFn: async () => { - const result = await getSupportedInterfaces(client, params) + const config = useConfig() + const chainId = useChainId({ config }) - return result - }, - }, - query, - ) + const options = getEnsResolverInterfacesQueryOptions(config, { + ...parameters, + chainId: parameters.chainId ?? chainId, + }) + const enabled = Boolean(address && interfaces && (query.enabled ?? true)) + + return useQuery({ ...query, ...options, enabled }) } diff --git a/packages/react/src/hooks/useNamesForAddress.ts b/packages/react/src/hooks/useNamesForAddress.ts deleted file mode 100644 index 3e613902..00000000 --- a/packages/react/src/hooks/useNamesForAddress.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { Address } from 'viem' -import { - getNamesForAddress, - type GetNamesForAddressReturnType, -} from '@ensdomains/ensjs/subgraph' -import type { ParamWithClients, QueryConfig } from '../client.js' -import { useQuery, type UseQueryReturnType } from './useQuery.js' - -export type UseNamesForAddressParams = ParamWithClients<{ - address: Address -}> - -export type UseNamesForAddressReturnType = GetNamesForAddressReturnType - -/** - * Returns a list of names for an address - * - * Keep in mind that this list will be loaded from the subgraph, and only include watchable names. - * Read more about enumeration and watchability here: https://docs.ens.domains/web/enumerate - * - * @param params - {@link UseNamesForAddressParams} - * @returns - {@link UseNamesForAddressReturnType} - */ -export const useNamesForAddress = ( - params: UseNamesForAddressParams, - queryConfig?: QueryConfig, -): UseQueryReturnType => { - const { address, client } = params - - return useQuery( - ['ensjs', 'names-for-address', address], - { - queryFn: async () => { - const result = await getNamesForAddress(client, { - address, - }) - - return result - }, - enabled: !!params.address, - initialData: [], - }, - queryConfig, - ) -} diff --git a/packages/react/src/hooks/useQuery.ts b/packages/react/src/hooks/useQuery.ts deleted file mode 100644 index 70fa3023..00000000 --- a/packages/react/src/hooks/useQuery.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - useQuery as useTanstackQuery, - type DefaultError, - type DefinedUseQueryResult, - type QueryKey, - type UseQueryOptions, -} from '@tanstack/react-query' -import type { ExactPartial } from 'viem' -import { fallbackQueryClient } from '../query.js' -import type { Compute } from '../utils/types.js' -import type { QueryConfig } from '../client.js' - -export type UseQueryParameters< - QueryFnData = unknown, - Error = DefaultError, - Data = QueryFnData, - TheQueryKey extends QueryKey = QueryKey, -> = Compute< - ExactPartial< - Omit, 'initialData'> - > & { - // Fix `initialData` type - initialData?: - | UseQueryOptions['initialData'] - | undefined - } -> - -export type UseQueryReturnType< - Data = unknown, - Error = DefaultError, -> = DefinedUseQueryResult - -export const useQuery = < - Parameters extends UseQueryParameters, - Data = unknown, - Error = unknown, ->( - key: QueryKey, - queryParameters: Exclude, - queryConfig?: QueryConfig, -): UseQueryReturnType => { - const parameters = { - ...queryParameters, - ...queryConfig, - queryKey: key, - } - - return useTanstackQuery( - { ...parameters } as any, - queryConfig?.queryClient ?? fallbackQueryClient, - ) -} diff --git a/packages/react/src/hooks/useWriteEnsRecords.ts b/packages/react/src/hooks/useWriteEnsRecords.ts new file mode 100644 index 00000000..28eeb2bc --- /dev/null +++ b/packages/react/src/hooks/useWriteEnsRecords.ts @@ -0,0 +1,73 @@ +import { useConfig } from 'wagmi' +import { + useMutation, + type UseMutationParameters, + type UseMutationReturnType, +} from 'wagmi/query' +import { + writeEnsRecordsMutationOptions, + type WriteEnsRecordsData, + type WriteEnsRecordsErrorType, + type WriteEnsRecordsMutate, + type WriteEnsRecordsMutateAsync, + type WriteEnsRecordsVariables, +} from '../query/writeEnsRecords.js' +import type { ConfigWithEns } from '../types/config.js' +import type { ConfigParameter } from '../types/properties.js' +import type { ResolvedRegister } from '../types/register.js' +import type { Compute } from '../types/utils.js' + +export type UseWriteEnsRecordsParameters< + config extends ConfigWithEns = ConfigWithEns, + context = unknown, +> = Compute< + ConfigParameter & { + mutation?: + | UseMutationParameters< + WriteEnsRecordsData, + WriteEnsRecordsErrorType, + WriteEnsRecordsVariables, + context + > + | undefined + } +> + +export type UseWriteEnsRecordsReturnType< + config extends ConfigWithEns = ConfigWithEns, + context = unknown, +> = Compute< + UseMutationReturnType< + WriteEnsRecordsData, + WriteEnsRecordsErrorType, + WriteEnsRecordsVariables, + context + > & { + writeEnsRecords: WriteEnsRecordsMutate + writeEnsRecordsAsync: WriteEnsRecordsMutateAsync + } +> + +export const useWriteEnsRecords = < + config extends ConfigWithEns = ResolvedRegister['config'], + context = unknown, +>( + parameters: UseWriteEnsRecordsParameters = {}, +): UseWriteEnsRecordsReturnType => { + const { mutation } = parameters + + const config = useConfig(parameters) + + const mutationOptions = writeEnsRecordsMutationOptions(config) + const { mutate, mutateAsync, ...result } = useMutation({ + ...mutation, + ...mutationOptions, + }) + + type Return = UseWriteEnsRecordsReturnType + return { + ...result, + writeEnsRecords: mutate as Return['writeEnsRecords'], + writeEnsRecordsAsync: mutateAsync as Return['writeEnsRecordsAsync'], + } +} diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 26593bd8..ebdd3096 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -1,3 +1,67 @@ -export * from './hooks.js' export { resolverInterfaces } from './interfaces.js' -export type { ParamWithClients } from './client.js' + +export { + useDecodedName, + type UseDecodedNameParameters, + type UseDecodedNameReturnType, +} from './hooks/useDecodedName.js' +export { + useEnsAbi, + type UseEnsAbiParameters, + type UseEnsAbiReturnType, +} from './hooks/useEnsAbi.js' +export { + useEnsAddress, + type UseEnsAddressParameters, + type UseEnsAddressReturnType, +} from './hooks/useEnsAddress.js' +export { + useEnsAvailable, + type UseEnsAvailableParameters, + type UseEnsAvailableReturnType, +} from './hooks/useEnsAvailable.js' +export { + useEnsContentHash, + type UseEnsContentHashParameters, + type UseEnsContentHashReturnType, +} from './hooks/useEnsContentHash.js' +export { + useEnsCredentials, + type UseEnsCredentialsParameters, + type UseEnsCredentialsReturnType, +} from './hooks/useEnsCredentials.js' +export { + useEnsExpiry, + type UseEnsExpiryParameters, + type UseEnsExpiryReturnType, +} from './hooks/useEnsExpiry.js' +export { + useEnsNamesForAddress, + type UseEnsNamesForAddressParameters, + type UseEnsNamesForAddressReturnType, +} from './hooks/useEnsNamesForAddress.js' +export { + useEnsOwner, + type UseEnsOwnerParameters, + type UseEnsOwnerReturnType, +} from './hooks/useEnsOwner.js' +export { + useEnsPrice, + type UseEnsPriceParameters, + type UseEnsPriceReturnType, +} from './hooks/useEnsPrice.js' +export { + useEnsRecords, + type UseEnsRecordsParameters, + type UseEnsRecordsReturnType, +} from './hooks/useEnsRecords.js' +export { + useEnsResolverInterfaces, + type UseEnsResolverInterfacesParameters, + type UseEnsResolverInterfacesReturnType, +} from './hooks/useEnsResolverInterfaces.js' +export { + useWriteEnsRecords, + type UseWriteEnsRecordsParameters, + type UseWriteEnsRecordsReturnType, +} from './hooks/useWriteEnsRecords.js' diff --git a/packages/react/src/query.ts b/packages/react/src/query.ts index abd7d6ba..ef109ea0 100644 --- a/packages/react/src/query.ts +++ b/packages/react/src/query.ts @@ -1,4 +1,132 @@ -import { QueryClient } from '@tanstack/react-query' - -// TODO: figure out why not taking from provider -export const fallbackQueryClient = new QueryClient() +export { + getDecodedNameQueryKey, + getDecodedNameQueryOptions, + type GetDecodedNameData, + type GetDecodedNameErrorType, + type GetDecodedNameOptions, + type GetDecodedNameParameters, + type GetDecodedNameQueryFnData, + type GetDecodedNameQueryKey, + type GetDecodedNameReturnType, +} from './query/getDecodedName.js' +export { + getEnsAbiQueryOptions, + type GetEnsAbiData, + type GetEnsAbiErrorType, + type GetEnsAbiOptions, + type GetEnsAbiParameters, + type GetEnsAbiQueryFnData, + type GetEnsAbiQueryKey, + type GetEnsAbiReturnType, +} from './query/getEnsAbi.js' +export { + getEnsAddressQueryOptions, + type GetEnsAddressData, + type GetEnsAddressErrorType, + type GetEnsAddressOptions, + type GetEnsAddressParameters, + type GetEnsAddressQueryFnData, + type GetEnsAddressQueryKey, + type GetEnsAddressReturnType, +} from './query/getEnsAddress.js' +export { + getEnsAvailableQueryOptions, + type GetEnsAvailableData, + type GetEnsAvailableErrorType, + type GetEnsAvailableOptions, + type GetEnsAvailableParameters, + type GetEnsAvailableQueryFnData, + type GetEnsAvailableQueryKey, + type GetEnsAvailableReturnType, +} from './query/getEnsAvailable.js' +export { + getEnsContentHashQueryOptions, + type GetEnsContentHashData, + type GetEnsContentHashErrorType, + type GetEnsContentHashOptions, + type GetEnsContentHashParameters, + type GetEnsContentHashQueryFnData, + type GetEnsContentHashQueryKey, + type GetEnsContentHashReturnType, +} from './query/getEnsContentHash.js' +export { + getEnsCredentialsQueryOptions, + type GetEnsCredentialsData, + type GetEnsCredentialsErrorType, + type GetEnsCredentialsOptions, + type GetEnsCredentialsParameters, + type GetEnsCredentialsQueryFnData, + type GetEnsCredentialsQueryKey, + type GetEnsCredentialsReturnType, +} from './query/getEnsCredentials.js' +export { + getEnsExpiryQueryOptions, + type GetEnsExpiryData, + type GetEnsExpiryErrorType, + type GetEnsExpiryOptions, + type GetEnsExpiryParameters, + type GetEnsExpiryQueryFnData, + type GetEnsExpiryQueryKey, + type GetEnsExpiryReturnType, +} from './query/getEnsExpiry.js' +export { + getEnsNamesForAddressQueryOptions, + type GetEnsNamesForAddressData, + type GetEnsNamesForAddressErrorType, + type GetEnsNamesForAddressOptions, + type GetEnsNamesForAddressParameters, + type GetEnsNamesForAddressQueryFnData, + type GetEnsNamesForAddressQueryKey, + type GetEnsNamesForAddressReturnType, +} from './query/getEnsNamesForAddress.js' +export { + getEnsOwnerQueryOptions, + type GetEnsOwnerData, + type GetEnsOwnerErrorType, + type GetEnsOwnerOptions, + type GetEnsOwnerParameters, + type GetEnsOwnerQueryFnData, + type GetEnsOwnerQueryKey, + type GetEnsOwnerReturnType, +} from './query/getEnsOwner.js' +export { + getEnsPriceQueryOptions, + type GetEnsPriceData, + type GetEnsPriceErrorType, + type GetEnsPriceOptions, + type GetEnsPriceParameters, + type GetEnsPriceQueryFnData, + type GetEnsPriceQueryKey, + type GetEnsPriceReturnType, +} from './query/getEnsPrice.js' +export { + getEnsRecordsQueryOptions, + type GetEnsRecordsData, + type GetEnsRecordsErrorType, + type GetEnsRecordsOptions, + type GetEnsRecordsParameters, + type GetEnsRecordsQueryFnData, + type GetEnsRecordsQueryKey, + type GetEnsRecordsReturnType, +} from './query/getEnsRecords.js' +export { + getEnsResolverInterfacesQueryOptions, + type GetEnsResolverInterfacesData, + type GetEnsResolverInterfacesErrorType, + type GetEnsResolverInterfacesOptions, + type GetEnsResolverInterfacesParameters, + type GetEnsResolverInterfacesQueryFnData, + type GetEnsResolverInterfacesQueryKey, + type GetEnsResolverInterfacesReturnType, +} from './query/getEnsResolverInterfaces.js' +export { + writeEnsRecords, + writeEnsRecordsMutationOptions, + type WriteEnsRecordsData, + type WriteEnsRecordsErrorType, + type WriteEnsRecordsMutate, + type WriteEnsRecordsMutateAsync, + type WriteEnsRecordsParameters, + type WriteEnsRecordsReturnType, + type WriteEnsRecordsVariables, +} from './query/writeEnsRecords.js' diff --git a/packages/react/src/query/getDecodedName.ts b/packages/react/src/query/getDecodedName.ts new file mode 100644 index 00000000..31c394c5 --- /dev/null +++ b/packages/react/src/query/getDecodedName.ts @@ -0,0 +1,64 @@ +import { + getDecodedName, + type GetDecodedNameErrorType as ensjs_GetDecodedNameErrorType, + type GetDecodedNameParameters as ensjs_GetDecodedNameParameters, + type GetDecodedNameReturnType as ensjs_GetDecodedNameReturnType, +} from '@ensdomains/ensjs/subgraph' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetDecodedNameParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetDecodedNameReturnType = ensjs_GetDecodedNameReturnType + +export type GetDecodedNameErrorType = ensjs_GetDecodedNameErrorType + +export type GetDecodedNameOptions< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> & ScopeKeyParameter> + +export type GetDecodedNameQueryFnData = GetDecodedNameReturnType + +export type GetDecodedNameData = GetDecodedNameReturnType + +export const getDecodedNameQueryKey = ( + options: GetDecodedNameOptions, +) => { + return ['getDecodedName', filterQueryOptions(options)] as const +} + +export type GetDecodedNameQueryKey = ReturnType< + typeof getDecodedNameQueryKey +> + +export const getDecodedNameQueryOptions = ( + config: config, + options: GetDecodedNameOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getDecodedName(client, parameters) + }, + queryKey: getDecodedNameQueryKey(options), + } as const satisfies QueryOptions< + GetDecodedNameQueryFnData, + GetDecodedNameErrorType, + GetDecodedNameData, + GetDecodedNameQueryKey + > +} diff --git a/packages/react/src/query/getEnsAbi.ts b/packages/react/src/query/getEnsAbi.ts new file mode 100644 index 00000000..a934d5d3 --- /dev/null +++ b/packages/react/src/query/getEnsAbi.ts @@ -0,0 +1,62 @@ +import { + getAbiRecord, + type GetAbiRecordErrorType as ensjs_GetEnsAbiErrorType, + type GetAbiRecordParameters as ensjs_GetEnsAbiParameters, + type GetAbiRecordReturnType as ensjs_GetEnsAbiReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsAbiParameters = + Compute> + +export type GetEnsAbiReturnType = ensjs_GetEnsAbiReturnType + +export type GetEnsAbiErrorType = ensjs_GetEnsAbiErrorType + +export type GetEnsAbiOptions = + Compute> & ScopeKeyParameter> + +export type GetEnsAbiQueryFnData = GetEnsAbiReturnType + +export type GetEnsAbiData = GetEnsAbiReturnType + +export const getEnsAbiQueryKey = ( + options: GetEnsAbiOptions, +) => { + return ['getEnsAbi', filterQueryOptions(options)] as const +} + +export type GetEnsAbiQueryKey = ReturnType< + typeof getEnsAbiQueryKey +> + +export const getEnsAbiQueryOptions = ( + config: config, + options: GetEnsAbiOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getAbiRecord(client, parameters) + }, + queryKey: getEnsAbiQueryKey(options), + } as const satisfies QueryOptions< + GetEnsAbiQueryFnData, + GetEnsAbiErrorType, + GetEnsAbiData, + GetEnsAbiQueryKey + > +} diff --git a/packages/react/src/query/getEnsAddress.ts b/packages/react/src/query/getEnsAddress.ts new file mode 100644 index 00000000..20bea9d7 --- /dev/null +++ b/packages/react/src/query/getEnsAddress.ts @@ -0,0 +1,63 @@ +import { + getAddressRecord, + type GetAddressRecordErrorType as ensjs_GetEnsAddressErrorType, + type GetAddressRecordParameters as ensjs_GetEnsAddressParameters, + type GetAddressRecordReturnType as ensjs_GetEnsAddressReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsAddressParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsAddressReturnType = ensjs_GetEnsAddressReturnType + +export type GetEnsAddressErrorType = ensjs_GetEnsAddressErrorType + +export type GetEnsAddressOptions = + Compute> & ScopeKeyParameter> + +export type GetEnsAddressQueryFnData = GetEnsAddressReturnType + +export type GetEnsAddressData = GetEnsAddressReturnType + +export const getEnsAddressQueryKey = ( + options: GetEnsAddressOptions, +) => { + return ['getEnsAddress', filterQueryOptions(options)] as const +} + +export type GetEnsAddressQueryKey = ReturnType< + typeof getEnsAddressQueryKey +> + +export const getEnsAddressQueryOptions = ( + config: config, + options: GetEnsAddressOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getAddressRecord(client, parameters) + }, + queryKey: getEnsAddressQueryKey(options), + } as const satisfies QueryOptions< + GetEnsAddressQueryFnData, + GetEnsAddressErrorType, + GetEnsAddressData, + GetEnsAddressQueryKey + > +} diff --git a/packages/react/src/query/getEnsAvailable.ts b/packages/react/src/query/getEnsAvailable.ts new file mode 100644 index 00000000..a1a156d8 --- /dev/null +++ b/packages/react/src/query/getEnsAvailable.ts @@ -0,0 +1,64 @@ +import { + getAvailable, + type GetAvailableErrorType, + type GetAvailableParameters, + type GetAvailableReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsAvailableParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsAvailableReturnType = GetAvailableReturnType + +export type GetEnsAvailableErrorType = GetAvailableErrorType + +export type GetEnsAvailableOptions< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> & ScopeKeyParameter> + +export type GetEnsAvailableQueryFnData = GetAvailableReturnType + +export type GetEnsAvailableData = GetAvailableReturnType + +export const getEnsAvailableQueryKey = ( + options: GetEnsAvailableOptions, +) => { + return ['getEnsAvailable', filterQueryOptions(options)] as const +} + +export type GetEnsAvailableQueryKey = ReturnType< + typeof getEnsAvailableQueryKey +> + +export const getEnsAvailableQueryOptions = ( + config: config, + options: GetEnsAvailableOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getAvailable(client, parameters) + }, + queryKey: getEnsAvailableQueryKey(options), + } as const satisfies QueryOptions< + GetEnsAvailableQueryFnData, + GetEnsAvailableErrorType, + GetEnsAvailableData, + GetEnsAvailableQueryKey + > +} diff --git a/packages/react/src/query/getEnsContentHash.ts b/packages/react/src/query/getEnsContentHash.ts new file mode 100644 index 00000000..f5a643a8 --- /dev/null +++ b/packages/react/src/query/getEnsContentHash.ts @@ -0,0 +1,65 @@ +import { + getContentHashRecord, + type GetContentHashRecordErrorType as ensjs_GetEnsContentHashErrorType, + type GetContentHashRecordParameters as ensjs_GetEnsContentHashParameters, + type GetContentHashRecordReturnType as ensjs_GetEnsContentHashReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsContentHashParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsContentHashReturnType = ensjs_GetEnsContentHashReturnType + +export type GetEnsContentHashErrorType = ensjs_GetEnsContentHashErrorType + +export type GetEnsContentHashOptions< + config extends ConfigWithEns = ConfigWithEns, +> = Compute< + ExactPartial> & ScopeKeyParameter +> + +export type GetEnsContentHashQueryFnData = GetEnsContentHashReturnType + +export type GetEnsContentHashData = GetEnsContentHashReturnType + +export const getEnsContentHashQueryKey = ( + options: GetEnsContentHashOptions, +) => { + return ['getEnsContentHash', filterQueryOptions(options)] as const +} + +export type GetEnsContentHashQueryKey = + ReturnType> + +export const getEnsContentHashQueryOptions = ( + config: config, + options: GetEnsContentHashOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getContentHashRecord(client, parameters) + }, + queryKey: getEnsContentHashQueryKey(options), + } as const satisfies QueryOptions< + GetEnsContentHashQueryFnData, + GetEnsContentHashErrorType, + GetEnsContentHashData, + GetEnsContentHashQueryKey + > +} diff --git a/packages/react/src/query/getEnsCredentials.ts b/packages/react/src/query/getEnsCredentials.ts new file mode 100644 index 00000000..c17742bf --- /dev/null +++ b/packages/react/src/query/getEnsCredentials.ts @@ -0,0 +1,66 @@ +import { + getCredentials, + type GetCredentialsErrorType as ensjs_GetCredentialsErrorType, + type GetCredentialsParameters as ensjs_GetCredentialsParameters, + type GetCredentialsReturnType as ensjs_GetCredentialsReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsCredentialsParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsCredentialsReturnType = ensjs_GetCredentialsReturnType + +export type GetEnsCredentialsErrorType = ensjs_GetCredentialsErrorType + +export type GetEnsCredentialsOptions< + config extends ConfigWithEns = ConfigWithEns, +> = Compute< + ExactPartial> & ScopeKeyParameter +> + +export type GetEnsCredentialsQueryFnData = GetEnsCredentialsReturnType + +export type GetEnsCredentialsData = GetEnsCredentialsReturnType + +export const getEnsCredentialsQueryKey = ( + options: GetEnsCredentialsOptions, +) => { + return ['getEnsCredentials', filterQueryOptions(options)] as const +} + +export type GetEnsCredentialsQueryKey = + ReturnType> + +export const getEnsCredentialsQueryOptions = ( + config: config, + options: GetEnsCredentialsOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + + return getCredentials(client, parameters) + }, + queryKey: getEnsCredentialsQueryKey(options), + } as const satisfies QueryOptions< + GetEnsCredentialsQueryFnData, + GetEnsCredentialsErrorType, + GetEnsCredentialsData, + GetEnsCredentialsQueryKey + > +} diff --git a/packages/react/src/query/getEnsExpiry.ts b/packages/react/src/query/getEnsExpiry.ts new file mode 100644 index 00000000..8156c1d9 --- /dev/null +++ b/packages/react/src/query/getEnsExpiry.ts @@ -0,0 +1,64 @@ +import { + getExpiry, + type GetExpiryErrorType as ensjs_GetExpiryErrorType, + type GetExpiryParameters as ensjs_GetExpiryParameters, + type GetExpiryReturnType as ensjs_GetExpiryReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsExpiryParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsExpiryReturnType = ensjs_GetExpiryReturnType + +export type GetEnsExpiryErrorType = ensjs_GetExpiryErrorType + +export type GetEnsExpiryOptions = + Compute> & ScopeKeyParameter> + +export type GetEnsExpiryQueryFnData = GetEnsExpiryReturnType + +export type GetEnsExpiryData = GetEnsExpiryReturnType + +export const getEnsExpiryQueryKey = ( + options: GetEnsExpiryOptions, +) => { + return ['getEnsExpiry', filterQueryOptions(options)] as const +} + +export type GetEnsExpiryQueryKey = ReturnType< + typeof getEnsExpiryQueryKey +> + +export const getEnsExpiryQueryOptions = ( + config: config, + options: GetEnsExpiryOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + + return getExpiry(client, parameters) + }, + queryKey: getEnsExpiryQueryKey(options), + } as const satisfies QueryOptions< + GetEnsExpiryQueryFnData, + GetEnsExpiryErrorType, + GetEnsExpiryData, + GetEnsExpiryQueryKey + > +} diff --git a/packages/react/src/query/getEnsNamesForAddress.ts b/packages/react/src/query/getEnsNamesForAddress.ts new file mode 100644 index 00000000..993118f2 --- /dev/null +++ b/packages/react/src/query/getEnsNamesForAddress.ts @@ -0,0 +1,66 @@ +import { + getNamesForAddress, + type GetNamesForAddressErrorType as ensjs_GetNamesForAddressErrorType, + type GetNamesForAddressParameters as ensjs_GetNamesForAddressParameters, + type GetNamesForAddressReturnType as ensjs_GetNamesForAddressReturnType, +} from '@ensdomains/ensjs/subgraph' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsNamesForAddressParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsNamesForAddressReturnType = ensjs_GetNamesForAddressReturnType + +export type GetEnsNamesForAddressErrorType = ensjs_GetNamesForAddressErrorType + +export type GetEnsNamesForAddressOptions< + config extends ConfigWithEns = ConfigWithEns, +> = Compute< + ExactPartial> & ScopeKeyParameter +> + +export type GetEnsNamesForAddressQueryFnData = GetEnsNamesForAddressReturnType + +export type GetEnsNamesForAddressData = GetEnsNamesForAddressReturnType + +export const getEnsNamesForAddressQueryKey = ( + options: GetEnsNamesForAddressOptions, +) => { + return ['getEnsNamesForAddress', filterQueryOptions(options)] as const +} + +export type GetEnsNamesForAddressQueryKey = + ReturnType> + +export const getEnsNamesForAddressQueryOptions = ( + config: config, + options: GetEnsNamesForAddressOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { address, ...rest } = queryKey[1] + if (!address) throw new Error('address is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + address, + }) + + return getNamesForAddress(client, parameters) + }, + queryKey: getEnsNamesForAddressQueryKey(options), + } as const satisfies QueryOptions< + GetEnsNamesForAddressQueryFnData, + GetEnsNamesForAddressErrorType, + GetEnsNamesForAddressData, + GetEnsNamesForAddressQueryKey + > +} diff --git a/packages/react/src/query/getEnsOwner.ts b/packages/react/src/query/getEnsOwner.ts new file mode 100644 index 00000000..b7f1e5bf --- /dev/null +++ b/packages/react/src/query/getEnsOwner.ts @@ -0,0 +1,63 @@ +import { + getOwner, + type GetOwnerErrorType as ensjs_GetEnsOwnerErrorType, + type GetOwnerParameters as ensjs_GetEnsOwnerParameters, + type GetOwnerReturnType as ensjs_GetEnsOwnerReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsOwnerParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsOwnerReturnType = ensjs_GetEnsOwnerReturnType + +export type GetEnsOwnerErrorType = ensjs_GetEnsOwnerErrorType + +export type GetEnsOwnerOptions = + Compute> & ScopeKeyParameter> + +export type GetEnsOwnerQueryFnData = GetEnsOwnerReturnType + +export type GetEnsOwnerData = GetEnsOwnerReturnType + +export const getEnsOwnerQueryKey = ( + options: GetEnsOwnerOptions, +) => { + return ['getEnsOwner', filterQueryOptions(options)] as const +} + +export type GetEnsOwnerQueryKey = ReturnType< + typeof getEnsOwnerQueryKey +> + +export const getEnsOwnerQueryOptions = ( + config: config, + options: GetEnsOwnerOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getOwner(client, parameters) + }, + queryKey: getEnsOwnerQueryKey(options), + } as const satisfies QueryOptions< + GetEnsOwnerQueryFnData, + GetEnsOwnerErrorType, + GetEnsOwnerData, + GetEnsOwnerQueryKey + > +} diff --git a/packages/react/src/query/getEnsPrice.ts b/packages/react/src/query/getEnsPrice.ts new file mode 100644 index 00000000..5dbb13e8 --- /dev/null +++ b/packages/react/src/query/getEnsPrice.ts @@ -0,0 +1,65 @@ +import { + getPrice, + type GetPriceErrorType as ensjs_GetEnsPriceErrorType, + type GetPriceParameters as ensjs_GetEnsPriceParameters, + type GetPriceReturnType as ensjs_GetEnsPriceReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsPriceParameters< + config extends ConfigWithEns = ConfigWithEns, +> = Compute> + +export type GetEnsPriceReturnType = ensjs_GetEnsPriceReturnType + +export type GetEnsPriceErrorType = ensjs_GetEnsPriceErrorType + +export type GetEnsPriceOptions = + Compute> & ScopeKeyParameter> + +export type GetEnsPriceQueryFnData = GetEnsPriceReturnType + +export type GetEnsPriceData = GetEnsPriceReturnType + +export const getEnsPriceQueryKey = ( + options: GetEnsPriceOptions, +) => { + return ['getEnsPrice', filterQueryOptions(options)] as const +} + +export type GetEnsPriceQueryKey = ReturnType< + typeof getEnsPriceQueryKey +> + +export const getEnsPriceQueryOptions = ( + config: config, + options: GetEnsPriceOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { nameOrNames, duration, ...rest } = queryKey[1] + if (!nameOrNames) throw new Error('nameOrNames is required') + if (!duration) throw new Error('duration is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + nameOrNames, + duration, + }) + return getPrice(client, parameters) + }, + queryKey: getEnsPriceQueryKey(options), + } as const satisfies QueryOptions< + GetEnsPriceQueryFnData, + GetEnsPriceErrorType, + GetEnsPriceData, + GetEnsPriceQueryKey + > +} diff --git a/packages/react/src/query/getEnsRecords.ts b/packages/react/src/query/getEnsRecords.ts new file mode 100644 index 00000000..6adf8901 --- /dev/null +++ b/packages/react/src/query/getEnsRecords.ts @@ -0,0 +1,113 @@ +import { + getRecords, + type GetRecordsErrorType as ensjs_GetEnsRecordsErrorType, + type GetRecordsParameters as ensjs_GetEnsRecordsParameters, + type GetRecordsReturnType as ensjs_GetEnsRecordsReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsRecordsParameters< + config extends ConfigWithEns = ConfigWithEns, + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, +> = Compute< + ensjs_GetEnsRecordsParameters & + ChainIdParameter +> + +export type GetEnsRecordsReturnType< + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, +> = ensjs_GetEnsRecordsReturnType + +export type GetEnsRecordsErrorType = ensjs_GetEnsRecordsErrorType + +export type GetEnsRecordsOptions< + config extends ConfigWithEns = ConfigWithEns, + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, +> = Compute< + ExactPartial< + GetEnsRecordsParameters + > & + ScopeKeyParameter +> + +export type GetEnsRecordsQueryFnData< + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, +> = GetEnsRecordsReturnType + +export type GetEnsRecordsData< + texts extends readonly string[] | undefined = undefined, + coins extends readonly (string | number)[] | undefined = undefined, + contentHash extends boolean | undefined = undefined, + abi extends boolean | undefined = undefined, +> = GetEnsRecordsReturnType + +export const getEnsRecordsQueryKey = < + config extends ConfigWithEns, + texts extends readonly string[] | undefined, + coins extends readonly (string | number)[] | undefined, + contentHash extends boolean | undefined, + abi extends boolean | undefined, +>( + options: GetEnsRecordsOptions, +) => { + return ['getEnsRecords', filterQueryOptions(options)] as const +} + +export type GetEnsRecordsQueryKey< + config extends ConfigWithEns, + texts extends readonly string[] | undefined, + coins extends readonly (string | number)[] | undefined, + contentHash extends boolean | undefined, + abi extends boolean | undefined, +> = ReturnType< + typeof getEnsRecordsQueryKey +> + +export const getEnsRecordsQueryOptions = < + config extends ConfigWithEns, + const texts extends readonly string[] | undefined = undefined, + const coins extends readonly (string | number)[] | undefined = undefined, + const contentHash extends boolean | undefined = undefined, + const abi extends boolean | undefined = undefined, +>( + config: config, + options: GetEnsRecordsOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { name, ...rest } = queryKey[1] + if (!name) throw new Error('name is required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + name, + }) + return getRecords(client, parameters) as any + }, + queryKey: getEnsRecordsQueryKey(options), + } as const satisfies QueryOptions< + GetEnsRecordsQueryFnData, + GetEnsRecordsErrorType, + GetEnsRecordsData, + GetEnsRecordsQueryKey + > +} diff --git a/packages/react/src/query/getEnsResolverInterfaces.ts b/packages/react/src/query/getEnsResolverInterfaces.ts new file mode 100644 index 00000000..d18e5f57 --- /dev/null +++ b/packages/react/src/query/getEnsResolverInterfaces.ts @@ -0,0 +1,88 @@ +import { + getSupportedInterfaces, + type GetSupportedInterfacesErrorType as ensjs_GetSupportedInterfacesErrorType, + type GetSupportedInterfacesParameters as ensjs_GetSupportedInterfacesParameters, + type GetSupportedInterfacesReturnType as ensjs_GetSupportedInterfacesReturnType, +} from '@ensdomains/ensjs/public' +import type { QueryOptions } from '@tanstack/react-query' +import type { Hex } from 'viem' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' +import type { Compute, ExactPartial } from '../types/utils.js' +import { filterQueryOptions, getClientAndParameters } from './utils.js' + +export type GetEnsResolverInterfacesParameters< + config extends ConfigWithEns = ConfigWithEns, + interfaces extends readonly Hex[] = readonly Hex[], +> = Compute< + ensjs_GetSupportedInterfacesParameters & ChainIdParameter +> + +export type GetEnsResolverInterfacesReturnType< + interfaces extends readonly Hex[], +> = ensjs_GetSupportedInterfacesReturnType + +export type GetEnsResolverInterfacesErrorType = + ensjs_GetSupportedInterfacesErrorType + +export type GetEnsResolverInterfacesOptions< + config extends ConfigWithEns = ConfigWithEns, + interfaces extends readonly Hex[] = readonly Hex[], +> = Compute< + ExactPartial> & + ScopeKeyParameter +> + +export type GetEnsResolverInterfacesQueryFnData< + interfaces extends readonly Hex[], +> = GetEnsResolverInterfacesReturnType + +export type GetEnsResolverInterfacesData = + GetEnsResolverInterfacesReturnType + +export const getEnsResolverInterfacesQueryKey = < + config extends ConfigWithEns, + const interfaces extends readonly Hex[], +>( + options: GetEnsResolverInterfacesOptions, +) => { + return ['getEnsResolverInterfaces', filterQueryOptions(options)] as const +} + +export type GetEnsResolverInterfacesQueryKey< + config extends ConfigWithEns, + interfaces extends readonly Hex[], +> = ReturnType> + +export const getEnsResolverInterfacesQueryOptions = < + config extends ConfigWithEns, + const interfaces extends readonly Hex[], +>( + config: config, + options: GetEnsResolverInterfacesOptions = {}, +) => { + return { + async queryFn({ queryKey }) { + const { address, interfaces, ...rest } = queryKey[1] + if (!address) throw new Error('address is required') + if (!interfaces) throw new Error('interfaces are required') + + const { client, parameters } = getClientAndParameters(config, { + ...rest, + address, + interfaces, + }) + + return getSupportedInterfaces(client, parameters) + }, + queryKey: getEnsResolverInterfacesQueryKey(options), + } as const satisfies QueryOptions< + GetEnsResolverInterfacesQueryFnData, + GetEnsResolverInterfacesErrorType, + GetEnsResolverInterfacesData, + GetEnsResolverInterfacesQueryKey + > +} diff --git a/packages/react/src/query/utils.ts b/packages/react/src/query/utils.ts new file mode 100644 index 00000000..01b733b3 --- /dev/null +++ b/packages/react/src/query/utils.ts @@ -0,0 +1,73 @@ +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ScopeKeyParameter, +} from '../types/properties.js' + +export const filterQueryOptions = >( + options: type, +): type => { + const { + // import('@tanstack/query-core').QueryOptions + _defaulted, + behavior, + gcTime, + initialData, + initialDataUpdatedAt, + maxPages, + meta, + networkMode, + queryFn, + queryHash, + queryKey, + queryKeyHashFn, + retry, + retryDelay, + structuralSharing, + + // import('@tanstack/query-core').InfiniteQueryObserverOptions + getPreviousPageParam, + getNextPageParam, + initialPageParam, + + // import('@tanstack/react-query').UseQueryOptions + _optimisticResults, + enabled, + notifyOnChangeProps, + placeholderData, + refetchInterval, + refetchIntervalInBackground, + refetchOnMount, + refetchOnReconnect, + refetchOnWindowFocus, + retryOnMount, + select, + staleTime, + suspense, + throwOnError, + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // wagmi + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + config, + connector, + query, + ...rest + } = options + + return rest as type +} + +export const getClientAndParameters = < + config extends ConfigWithEns, + parameters extends Record & + ChainIdParameter & + ScopeKeyParameter, +>( + config: config, + parameters: parameters, +) => { + const { chainId, scopeKey: _, ...rest } = parameters + const client = config.getClient({ chainId }) + return { client, parameters: rest } as const +} diff --git a/packages/react/src/query/writeEnsRecords.ts b/packages/react/src/query/writeEnsRecords.ts new file mode 100644 index 00000000..51736a64 --- /dev/null +++ b/packages/react/src/query/writeEnsRecords.ts @@ -0,0 +1,116 @@ +import type { ChainWithEns } from '@ensdomains/ensjs/contracts' +import { + encodeSetRecordsData, + type SetRecordsErrorType as ensjs_WriteEnsRecordsErrorType, + type SetRecordsParameters as ensjs_WriteEnsRecordsParameters, + type SetRecordsReturnType as ensjs_WriteEnsRecordsReturnType, +} from '@ensdomains/ensjs/wallet' +import type { MutateOptions, MutationOptions } from '@tanstack/react-query' +import type { Account } from 'viem' +import { sendTransaction, type SendTransactionParameters } from 'wagmi/actions' +import type { ConfigWithEns } from '../types/config.js' +import type { + ChainIdParameter, + ConnectorParameter, +} from '../types/properties.js' +import type { Compute } from '../types/utils.js' + +export type WriteEnsRecordsParameters< + config extends ConfigWithEns = ConfigWithEns, + chains extends readonly ChainWithEns[] = config['chains'], +> = ensjs_WriteEnsRecordsParameters & + ConnectorParameter & + ChainIdParameter + +export type WriteEnsRecordsReturnType = ensjs_WriteEnsRecordsReturnType + +export type WriteEnsRecordsErrorType = ensjs_WriteEnsRecordsErrorType + +export const writeEnsRecords = async < + config extends ConfigWithEns, + chains extends readonly ChainWithEns[] = config['chains'], +>( + config: config, + { + name, + resolverAddress, + clearRecords, + contentHash, + texts, + coins, + abi, + ...transactionParameters + }: WriteEnsRecordsParameters, +): Promise => { + const client = config.getClient({ chainId: transactionParameters.chainId }) + const data = encodeSetRecordsData(client, { + name, + resolverAddress, + clearRecords, + contentHash, + texts, + coins, + abi, + }) + + const parameters = { + ...data, + ...transactionParameters, + } as unknown as SendTransactionParameters + + return sendTransaction(config, parameters) +} + +export type WriteEnsRecordsData = Compute + +export type WriteEnsRecordsVariables = + WriteEnsRecordsParameters + +export type WriteEnsRecordsMutate< + config extends ConfigWithEns, + context = unknown, +> = ( + variables: WriteEnsRecordsVariables, + options?: + | Compute< + MutateOptions< + WriteEnsRecordsData, + WriteEnsRecordsErrorType, + Compute>, + context + > + > + | undefined, +) => WriteEnsRecordsData + +export type WriteEnsRecordsMutateAsync< + config extends ConfigWithEns, + context = unknown, +> = ( + variables: WriteEnsRecordsVariables, + options?: + | Compute< + MutateOptions< + WriteEnsRecordsData, + WriteEnsRecordsErrorType, + Compute>, + context + > + > + | undefined, +) => Promise + +export const writeEnsRecordsMutationOptions = ( + config: config, +) => { + return { + mutationFn(variables) { + return writeEnsRecords(config, variables) + }, + mutationKey: ['writeEnsRecords'], + } as const satisfies MutationOptions< + WriteEnsRecordsData, + WriteEnsRecordsErrorType, + WriteEnsRecordsVariables + > +} diff --git a/packages/react/src/types/chain.ts b/packages/react/src/types/chain.ts new file mode 100644 index 00000000..d6b1d8b3 --- /dev/null +++ b/packages/react/src/types/chain.ts @@ -0,0 +1,27 @@ +import type { ChainWithEns } from '@ensdomains/ensjs/contracts' +import type { ChainFormatters } from 'viem' +import type { ConfigWithEns } from './config.js' +import type { IsNarrowable, Merge } from './utils.js' + +/** Filters {@link Config} chains by {@link chainId} or simplifies if no `ChainFormatters` are present. */ +export type SelectChains< + config extends ConfigWithEns, + chainId extends config['chains'][number]['id'] | undefined = undefined, +> = ConfigWithEns extends config + ? readonly [ChainWithEns] // chains not inferrable, return default + : IsNarrowable extends true + ? readonly [Extract] // select specific chain + : HasFormatter extends true + ? config['chains'] // return all chains since one has formatter + : // return default chain with ID set to union (allows for more simple type since the only thing that is different is the chain ID for each chain) + readonly [Merge] + +type HasFormatter = + chains extends readonly [ + infer head extends ChainWithEns, + ...infer tail extends readonly ChainWithEns[], + ] + ? IsNarrowable extends true + ? true + : HasFormatter + : false diff --git a/packages/react/src/types/config.ts b/packages/react/src/types/config.ts new file mode 100644 index 00000000..945538ba --- /dev/null +++ b/packages/react/src/types/config.ts @@ -0,0 +1,4 @@ +import type { ChainWithEns } from '@ensdomains/ensjs/contracts' +import type { Config } from 'wagmi' + +export type ConfigWithEns = Config diff --git a/packages/react/src/types/properties.ts b/packages/react/src/types/properties.ts new file mode 100644 index 00000000..7f6bf243 --- /dev/null +++ b/packages/react/src/types/properties.ts @@ -0,0 +1,41 @@ +import type { DefaultError, QueryKey } from '@tanstack/react-query' +import type { Connector } from 'wagmi' +import type { UseQueryParameters } from 'wagmi/query' +import type { ConfigWithEns } from './config.js' + +export type ChainIdParameter< + config extends ConfigWithEns, + chainId extends + | config['chains'][number]['id'] + | undefined = config['chains'][number]['id'], +> = { + chainId?: + | (chainId extends config['chains'][number]['id'] ? chainId : undefined) + | config['chains'][number]['id'] + | undefined +} + +export type ScopeKeyParameter = { scopeKey?: string | undefined } + +// TODO(tate): not sure if this is needed yet +export type ConnectorParameter = { + connector?: Connector | undefined +} + +export type QueryParameter< + queryFnData = unknown, + error = DefaultError, + data = queryFnData, + queryKey extends QueryKey = QueryKey, +> = { + query?: + | Omit< + UseQueryParameters, + 'queryFn' | 'queryHash' | 'queryKey' | 'queryKeyHashFn' | 'throwOnError' + > + | undefined +} + +export type ConfigParameter = { + config?: ConfigWithEns | config | undefined +} diff --git a/packages/react/src/types/register.ts b/packages/react/src/types/register.ts new file mode 100644 index 00000000..9bbfca5e --- /dev/null +++ b/packages/react/src/types/register.ts @@ -0,0 +1,8 @@ +import type { Register } from 'wagmi' +import type { ConfigWithEns } from './config.js' + +export type ResolvedRegister = { + config: Register extends { config: infer config extends ConfigWithEns } + ? config + : ConfigWithEns +} diff --git a/packages/react/src/types/utils.ts b/packages/react/src/types/utils.ts new file mode 100644 index 00000000..508f50a8 --- /dev/null +++ b/packages/react/src/types/utils.ts @@ -0,0 +1,47 @@ +/** Combines members of an intersection into a readable type. */ +// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg +export type Compute = { [key in keyof type]: type[key] } & unknown + +/** + * Makes all properties of an object optional. + * + * Compatible with [`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes). + */ +export type ExactPartial = { + [key in keyof type]?: type[key] | undefined +} + +/** Checks if {@link type} can be narrowed further than {@link type2} */ +export type IsNarrowable = IsUnknown extends true + ? false + : undefined extends type + ? false + : IsNever< + (type extends type2 ? true : false) & (type2 extends type ? false : true) + > extends true + ? false + : true + +/** + * @internal + * Checks if {@link type} is `never` + */ +export type IsNever = [type] extends [never] ? true : false + +/** + * @internal + * Checks if {@link type} is `unknown` + */ +export type IsUnknown = unknown extends type ? true : false + +/** Merges two object types into new type */ +export type Merge = Compute< + LooseOmit & + obj2 +> + +/** Loose version of {@link StrictOmit} */ +export type LooseOmit = Pick< + type, + Exclude +> diff --git a/packages/react/src/utils/types.ts b/packages/react/src/utils/types.ts deleted file mode 100644 index 14d34666..00000000 --- a/packages/react/src/utils/types.ts +++ /dev/null @@ -1 +0,0 @@ -export type Compute = { [key in keyof Type]: Type[key] } & unknown diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c53c3c65..4b139248 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -236,8 +236,8 @@ importers: specifier: 5.3.2 version: 5.3.2 viem: - specifier: ^2.9.2 - version: 2.21.12(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10) + specifier: 2.9.2 + version: 2.9.2(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10) vitest: specifier: ^1.3.1 version: 1.6.0(@types/node@20.14.14)(happy-dom@13.10.1)(terser@5.31.6) @@ -8906,7 +8906,7 @@ snapshots: '@ensdomains/address-encoder@1.0.0-rc.3': dependencies: '@noble/curves': 1.4.2 - '@noble/hashes': 1.4.0 + '@noble/hashes': 1.5.0 '@scure/base': 1.1.7 '@ensdomains/address-encoder@1.1.1': @@ -9660,7 +9660,7 @@ snapshots: dependencies: '@ethereumjs/tx': 4.2.0 '@metamask/superstruct': 3.1.0 - '@noble/hashes': 1.4.0 + '@noble/hashes': 1.5.0 '@scure/base': 1.1.7 '@types/debug': 4.1.12 debug: 4.3.6(supports-color@8.1.1) @@ -9674,7 +9674,7 @@ snapshots: dependencies: '@ethereumjs/tx': 4.2.0 '@metamask/superstruct': 3.1.0 - '@noble/hashes': 1.4.0 + '@noble/hashes': 1.5.0 '@scure/base': 1.1.7 '@types/debug': 4.1.12 debug: 4.3.6(supports-color@8.1.1) @@ -11428,6 +11428,10 @@ snapshots: optionalDependencies: typescript: 5.6.2 + abitype@1.0.0(typescript@5.3.2): + optionalDependencies: + typescript: 5.3.2 + abitype@1.0.0(typescript@5.6.2): optionalDependencies: typescript: 5.6.2 @@ -13128,7 +13132,7 @@ snapshots: ethereum-bloom-filters@1.2.0: dependencies: - '@noble/hashes': 1.4.0 + '@noble/hashes': 1.5.0 ethereum-cryptography@0.1.3: dependencies: @@ -16887,25 +16891,25 @@ snapshots: - utf-8-validate - zod - viem@2.21.12(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10): + viem@2.21.12(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@5.0.10): dependencies: '@adraffy/ens-normalize': 1.10.0 '@noble/curves': 1.4.0 '@noble/hashes': 1.4.0 '@scure/bip32': 1.4.0 '@scure/bip39': 1.4.0 - abitype: 1.0.5(typescript@5.3.2) + abitype: 1.0.5(typescript@5.6.2) isows: 1.0.4(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)) webauthn-p256: 0.0.5 ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) optionalDependencies: - typescript: 5.3.2 + typescript: 5.6.2 transitivePeerDependencies: - bufferutil - utf-8-validate - zod - viem@2.21.12(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@5.0.10): + viem@2.21.12(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@6.0.3): dependencies: '@adraffy/ens-normalize': 1.10.0 '@noble/curves': 1.4.0 @@ -16913,9 +16917,9 @@ snapshots: '@scure/bip32': 1.4.0 '@scure/bip39': 1.4.0 abitype: 1.0.5(typescript@5.6.2) - isows: 1.0.4(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + isows: 1.0.4(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.3)) webauthn-p256: 0.0.5 - ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.3) optionalDependencies: typescript: 5.6.2 transitivePeerDependencies: @@ -16923,19 +16927,18 @@ snapshots: - utf-8-validate - zod - viem@2.21.12(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@6.0.3): + viem@2.9.2(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10): dependencies: '@adraffy/ens-normalize': 1.10.0 - '@noble/curves': 1.4.0 - '@noble/hashes': 1.4.0 - '@scure/bip32': 1.4.0 - '@scure/bip39': 1.4.0 - abitype: 1.0.5(typescript@5.6.2) - isows: 1.0.4(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.3)) - webauthn-p256: 0.0.5 - ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.3) + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/bip32': 1.3.2 + '@scure/bip39': 1.2.1 + abitype: 1.0.0(typescript@5.3.2) + isows: 1.0.3(ws@8.13.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + ws: 8.13.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) optionalDependencies: - typescript: 5.6.2 + typescript: 5.3.2 transitivePeerDependencies: - bufferutil - utf-8-validate @@ -17496,7 +17499,7 @@ snapshots: webauthn-p256@0.0.5: dependencies: '@noble/curves': 1.4.2 - '@noble/hashes': 1.4.0 + '@noble/hashes': 1.5.0 webextension-polyfill@0.10.0: {}