Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add strict/gatewayUrls param + getRecords tweaks #157

Merged
merged 11 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16]
node-version: [18]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.release.target_commitish }}

- uses: pnpm/[email protected]
with:
version: 7.8.0
version: 8.14.0

- name: Install Node.js
uses: actions/setup-node@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: pnpm/[email protected]
with:
version: 7.8.0
version: 8.14.0

- name: Install Node.js
uses: actions/setup-node@v3
Expand All @@ -34,7 +34,7 @@ jobs:

- uses: pnpm/[email protected]
with:
version: 7.8.0
version: 8.14.0

- name: Install Node.js
uses: actions/setup-node@v3
Expand Down
35 changes: 31 additions & 4 deletions packages/ensjs/src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export type EnsPublicActions = {
*/
getAbiRecord: ({
name,
gatewayUrls,
strict,
}: GetAbiRecordParameters) => Promise<GetAbiRecordReturnType>
/**
* Gets an address record for a name and specified coin
Expand All @@ -122,6 +124,8 @@ export type EnsPublicActions = {
name,
coin,
bypassFormat,
gatewayUrls,
strict,
}: GetAddressRecordParameters) => Promise<GetAddressRecordReturnType>
/**
* Gets the availability of a name to register
Expand Down Expand Up @@ -162,6 +166,8 @@ export type EnsPublicActions = {
*/
getContentHashRecord: ({
name,
gatewayUrls,
strict,
}: GetContentHashRecordParameters) => Promise<GetContentHashRecordReturnType>
/**
* Gets the expiry for a name
Expand Down Expand Up @@ -201,7 +207,12 @@ export type EnsPublicActions = {
* const result = await client.getName({ address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5' })
* // { name: 'nick.eth', match: true, reverseResolverAddress: '0xa2c122be93b0074270ebee7f6b7292c7deb45047', resolverAddress: '0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41' }
*/
getName: ({ address }: GetNameParameters) => Promise<GetNameReturnType>
getName: ({
address,
allowMismatch,
gatewayUrls,
strict,
}: GetNameParameters) => Promise<GetNameReturnType>
/**
* Gets the owner(s) of a name.
* @param parameters - {@link GetOwnerParameters}
Expand Down Expand Up @@ -268,11 +279,25 @@ export type EnsPublicActions = {
* })
* // { texts: [{ key: 'com.twitter', value: 'ensdomains' }, { key: 'com.github', value: 'ensdomains' }], coins: [{ id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }], contentHash: { protocolType: 'ipns', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } }
*/
getRecords: ({
getRecords: <
const TTexts extends readonly string[] = readonly string[],
const TCoins extends readonly (string | number)[] = readonly (
| string
| number
)[],
const TContentHash extends boolean = true,
const TAbi extends boolean = true,
>({
name,
records,
texts,
coins,
contentHash,
abi,
resolver,
}: GetRecordsParameters) => Promise<GetRecordsReturnType>
gatewayUrls,
}: GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>) => Promise<
GetRecordsReturnType<TTexts, TCoins, TContentHash, TAbi>
>
/**
* Gets the resolver address for a name.
* @param parameters - {@link GetResolverParameters}
Expand Down Expand Up @@ -313,6 +338,8 @@ export type EnsPublicActions = {
getTextRecord: ({
name,
key,
gatewayUrls,
strict,
}: GetTextRecordParameters) => Promise<GetTextRecordReturnType>
/**
* Gets the wrapper data for a name.
Expand Down
6 changes: 3 additions & 3 deletions packages/ensjs/src/contracts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const addresses = {
address: '0x21745FF62108968fBf5aB1E07961CC0FCBeB2364',
},
ensUniversalResolver: {
address: '0x20814C8e689187DfF7C93A9239ea22385d13b9F1',
address: '0x8cab227b1162f03b8338331adaad7aadc83b895e',
},
},
goerli: {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const addresses = {
address: '0xF427c4AdED8B6dfde604865c1a7E953B160C26f0',
},
ensUniversalResolver: {
address: '0xaac727b9451268d7779F699dbaF6c2eAE571C369',
address: '0xfc4AC75C46C914aF5892d6d3eFFcebD7917293F1',
},
},
sepolia: {
Expand Down Expand Up @@ -123,7 +123,7 @@ export const addresses = {
address: '0x7b3ada1c8f012bae747cf99d6cbbf70d040b84cf',
},
ensUniversalResolver: {
address: '0x64da0719987c29e0CEC0113D605996c6a4D4aB0c',
address: '0xBaBC7678D7A63104f1658c11D6AE9A21cdA09725',
},
},
} as const satisfies Record<
Expand Down
154 changes: 95 additions & 59 deletions packages/ensjs/src/contracts/universalResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,92 +46,128 @@ export const universalResolverErrors = [
},
] as const

const universalResolverReverse = {
inputs: [
{
name: 'reverseName',
type: 'bytes',
},
],
name: 'reverse',
outputs: [
{ type: 'string', name: 'resolvedName' },
{ type: 'address', name: 'resolvedAddress' },
{ type: 'address', name: 'reverseResolver' },
{ type: 'address', name: 'resolver' },
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverReverseSnippet = [
...universalResolverErrors,
universalResolverReverse,
{
...universalResolverReverse,
inputs: [
...universalResolverReverse.inputs,
{
name: 'reverseName',
type: 'bytes',
name: 'gateways',
type: 'string[]',
},
],
name: 'reverse',
outputs: [
{ type: 'string', name: 'resolvedName' },
{ type: 'address', name: 'resolvedAddress' },
{ type: 'address', name: 'reverseResolver' },
{ type: 'address', name: 'resolver' },
],
stateMutability: 'view',
type: 'function',
},
] as const

const universalResolverResolve = {
inputs: [
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes',
},
],
name: 'resolve',
outputs: [
{
name: 'data',
type: 'bytes',
},
{
name: 'resolver',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverResolveSnippet = [
...universalResolverErrors,
universalResolverResolve,
{
...universalResolverResolve,
inputs: [
...universalResolverResolve.inputs,
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes',
name: 'gateways',
type: 'string[]',
},
],
name: 'resolve',
outputs: [
{
name: 'data',
type: 'bytes',
},
{
name: 'resolver',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

const universalResolverResolveArray = {
inputs: [
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes[]',
},
],
name: 'resolve',
outputs: [
{
components: [
{
name: 'success',
type: 'bool',
},
{
name: 'returnData',
type: 'bytes',
},
],
name: '',
type: 'tuple[]',
},
{
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverResolveArraySnippet = [
...universalResolverErrors,
universalResolverResolveArray,
{
...universalResolverResolveArray,
inputs: [
...universalResolverResolveArray.inputs,
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes[]',
},
],
name: 'resolve',
outputs: [
{
components: [
{
name: 'success',
type: 'bool',
},
{
name: 'returnData',
type: 'bytes',
},
],
name: '',
type: 'tuple[]',
},
{
name: '',
type: 'address',
name: 'gateways',
type: 'string[]',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

Expand Down
21 changes: 21 additions & 0 deletions packages/ensjs/src/functions/public/_getAbi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ClientWithEns } from '../../contracts/consts.js'
import _getAbi from './_getAbi.js'

it('does not propagate error when strict is false', async () => {
const result = await _getAbi.decode({} as ClientWithEns, '0x1234', {
strict: false,
})
expect(result).toBeNull()
})

it('propagates error when strict is true', async () => {
await expect(_getAbi.decode({} as ClientWithEns, '0x1234', { strict: true }))
.rejects.toThrowErrorMatchingInlineSnapshot(`
"Data size of 2 bytes is too small for given parameters.

Params: (uint256, bytes)
Data: 0x1234 (2 bytes)

Version: [email protected]"
`)
})
Loading
Loading