@ensdomains/ensjs 3.0.0-beta.8 → 3.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/public.js.map +1 -1
- package/dist/cjs/clients/subgraph.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/functions/public/_getAddr.js +7 -19
- package/dist/cjs/functions/public/_getAddr.js.map +1 -1
- package/dist/cjs/functions/public/getName.js.map +1 -1
- package/dist/cjs/functions/public/getRecords.js.map +1 -1
- package/dist/cjs/functions/public/getResolver.js.map +1 -1
- package/dist/cjs/functions/public/getWrapperData.js.map +1 -1
- package/dist/cjs/functions/public/getWrapperName.js.map +1 -1
- package/dist/cjs/functions/public/multicallWrapper.js.map +1 -1
- package/dist/cjs/functions/public/universalWrapper.js.map +1 -1
- package/dist/cjs/functions/subgraph/getNameHistory.js +3 -2
- package/dist/cjs/functions/subgraph/getNameHistory.js.map +1 -1
- package/dist/cjs/utils/encoders/encodeSetAddr.js +5 -16
- package/dist/cjs/utils/encoders/encodeSetAddr.js.map +1 -1
- package/dist/cjs/utils/normaliseCoinId.js +22 -2
- package/dist/cjs/utils/normaliseCoinId.js.map +1 -1
- package/dist/esm/clients/public.js.map +1 -1
- package/dist/esm/clients/subgraph.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/functions/public/_getAddr.js +9 -21
- package/dist/esm/functions/public/_getAddr.js.map +1 -1
- package/dist/esm/functions/public/getName.js.map +1 -1
- package/dist/esm/functions/public/getRecords.js.map +1 -1
- package/dist/esm/functions/public/getResolver.js.map +1 -1
- package/dist/esm/functions/public/getWrapperData.js.map +1 -1
- package/dist/esm/functions/public/getWrapperName.js.map +1 -1
- package/dist/esm/functions/public/multicallWrapper.js.map +1 -1
- package/dist/esm/functions/public/universalWrapper.js.map +1 -1
- package/dist/esm/functions/subgraph/getNameHistory.js +4 -3
- package/dist/esm/functions/subgraph/getNameHistory.js.map +1 -1
- package/dist/esm/utils/encoders/encodeSetAddr.js +5 -16
- package/dist/esm/utils/encoders/encodeSetAddr.js.map +1 -1
- package/dist/esm/utils/normaliseCoinId.js +20 -1
- package/dist/esm/utils/normaliseCoinId.js.map +1 -1
- package/dist/types/clients/public.d.ts +4 -240
- package/dist/types/clients/public.d.ts.map +1 -1
- package/dist/types/clients/subgraph.d.ts +4 -240
- package/dist/types/clients/subgraph.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/functions/dns/importDnsName.d.ts +1 -4
- package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
- package/dist/types/functions/public/_getAddr.d.ts.map +1 -1
- package/dist/types/functions/subgraph/getNameHistory.d.ts.map +1 -1
- package/dist/types/functions/wallet/clearRecords.d.ts +1 -4
- package/dist/types/functions/wallet/clearRecords.d.ts.map +1 -1
- package/dist/types/functions/wallet/commitName.d.ts +1 -4
- package/dist/types/functions/wallet/commitName.d.ts.map +1 -1
- package/dist/types/functions/wallet/createSubname.d.ts +1 -4
- package/dist/types/functions/wallet/createSubname.d.ts.map +1 -1
- package/dist/types/functions/wallet/deleteSubname.d.ts +1 -4
- package/dist/types/functions/wallet/deleteSubname.d.ts.map +1 -1
- package/dist/types/functions/wallet/setAbiRecord.d.ts +1 -4
- package/dist/types/functions/wallet/setAbiRecord.d.ts.map +1 -1
- package/dist/types/functions/wallet/setAddressRecord.d.ts +1 -4
- package/dist/types/functions/wallet/setAddressRecord.d.ts.map +1 -1
- package/dist/types/functions/wallet/setChildFuses.d.ts +1 -4
- package/dist/types/functions/wallet/setChildFuses.d.ts.map +1 -1
- package/dist/types/functions/wallet/setContentHashRecord.d.ts +1 -4
- package/dist/types/functions/wallet/setContentHashRecord.d.ts.map +1 -1
- package/dist/types/functions/wallet/setFuses.d.ts +1 -4
- package/dist/types/functions/wallet/setFuses.d.ts.map +1 -1
- package/dist/types/functions/wallet/setPrimaryName.d.ts +1 -4
- package/dist/types/functions/wallet/setPrimaryName.d.ts.map +1 -1
- package/dist/types/functions/wallet/setRecords.d.ts +1 -4
- package/dist/types/functions/wallet/setRecords.d.ts.map +1 -1
- package/dist/types/functions/wallet/setResolver.d.ts +1 -4
- package/dist/types/functions/wallet/setResolver.d.ts.map +1 -1
- package/dist/types/functions/wallet/setTextRecord.d.ts +1 -4
- package/dist/types/functions/wallet/setTextRecord.d.ts.map +1 -1
- package/dist/types/functions/wallet/transferName.d.ts +1 -4
- package/dist/types/functions/wallet/transferName.d.ts.map +1 -1
- package/dist/types/functions/wallet/unwrapName.d.ts +1 -4
- package/dist/types/functions/wallet/unwrapName.d.ts.map +1 -1
- package/dist/types/functions/wallet/wrapName.d.ts +1 -4
- package/dist/types/functions/wallet/wrapName.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/encoders/encodeSetAddr.d.ts.map +1 -1
- package/dist/types/utils/normaliseCoinId.d.ts +2 -0
- package/dist/types/utils/normaliseCoinId.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/public.ts +2 -1
- package/src/clients/subgraph.ts +2 -1
- package/src/errors/version.ts +1 -1
- package/src/functions/public/_getAddr.ts +15 -30
- package/src/functions/public/getName.ts +1 -1
- package/src/functions/public/getRecords.ts +1 -1
- package/src/functions/public/getResolver.ts +1 -1
- package/src/functions/public/getWrapperData.ts +1 -1
- package/src/functions/public/getWrapperName.ts +1 -1
- package/src/functions/public/multicallWrapper.ts +1 -1
- package/src/functions/public/universalWrapper.ts +1 -1
- package/src/functions/subgraph/getNameHistory.ts +4 -3
- package/src/types.ts +6 -3
- package/src/utils/encoders/encodeSetAddr.ts +5 -16
- package/src/utils/normaliseCoinId.ts +26 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
decodeFunctionResult,
|
|
3
|
+
encodeFunctionData,
|
|
4
|
+
hexToBytes,
|
|
5
|
+
trim,
|
|
6
|
+
type Hex,
|
|
7
|
+
} from 'viem'
|
|
3
8
|
import { namehash } from '../../utils/normalise.js'
|
|
4
9
|
|
|
5
10
|
import type { ClientWithEns } from '../../contracts/consts.js'
|
|
@@ -7,7 +12,6 @@ import {
|
|
|
7
12
|
publicResolverMultiAddrSnippet,
|
|
8
13
|
publicResolverSingleAddrSnippet,
|
|
9
14
|
} from '../../contracts/publicResolver.js'
|
|
10
|
-
import { CoinFormatterNotFoundError } from '../../errors/public.js'
|
|
11
15
|
import type {
|
|
12
16
|
DecodedAddr,
|
|
13
17
|
Prettify,
|
|
@@ -15,7 +19,7 @@ import type {
|
|
|
15
19
|
} from '../../types.js'
|
|
16
20
|
import { EMPTY_ADDRESS } from '../../utils/consts.js'
|
|
17
21
|
import { generateFunction } from '../../utils/generateFunction.js'
|
|
18
|
-
import {
|
|
22
|
+
import { getCoderFromCoin } from '../../utils/normaliseCoinId.js'
|
|
19
23
|
|
|
20
24
|
export type InternalGetAddrParameters = {
|
|
21
25
|
/** Name to get the address record for */
|
|
@@ -32,11 +36,8 @@ const encode = (
|
|
|
32
36
|
_client: ClientWithEns,
|
|
33
37
|
{ name, coin = 60, bypassFormat }: InternalGetAddrParameters,
|
|
34
38
|
): SimpleTransactionRequest => {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
(normalisedCoin.type === 'id' && normalisedCoin.value === 60) ||
|
|
38
|
-
(normalisedCoin.type === 'name' && normalisedCoin.value === 'ETH')
|
|
39
|
-
) {
|
|
39
|
+
const coder = getCoderFromCoin(coin)
|
|
40
|
+
if (coder.coinType === 60) {
|
|
40
41
|
return {
|
|
41
42
|
to: EMPTY_ADDRESS,
|
|
42
43
|
data: encodeFunctionData({
|
|
@@ -57,20 +58,13 @@ const encode = (
|
|
|
57
58
|
}),
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
const formatter =
|
|
61
|
-
normalisedCoin.type === 'name'
|
|
62
|
-
? formatsByName[normalisedCoin.value]
|
|
63
|
-
: formatsByCoinType[normalisedCoin.value]
|
|
64
|
-
|
|
65
|
-
if (!formatter)
|
|
66
|
-
throw new CoinFormatterNotFoundError({ coinType: normalisedCoin.value })
|
|
67
61
|
|
|
68
62
|
return {
|
|
69
63
|
to: EMPTY_ADDRESS,
|
|
70
64
|
data: encodeFunctionData({
|
|
71
65
|
abi: publicResolverMultiAddrSnippet,
|
|
72
66
|
functionName: 'addr',
|
|
73
|
-
args: [namehash(name), BigInt(
|
|
67
|
+
args: [namehash(name), BigInt(coder.coinType)],
|
|
74
68
|
}),
|
|
75
69
|
}
|
|
76
70
|
}
|
|
@@ -82,19 +76,10 @@ const decode = async (
|
|
|
82
76
|
): Promise<InternalGetAddrReturnType> => {
|
|
83
77
|
if (data === '0x') return null
|
|
84
78
|
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const formatter =
|
|
88
|
-
normalisedCoin.type === 'name'
|
|
89
|
-
? formatsByName[normalisedCoin.value]
|
|
90
|
-
: formatsByCoinType[normalisedCoin.value]
|
|
91
|
-
|
|
79
|
+
const coder = getCoderFromCoin(coin)
|
|
92
80
|
let response: Hex
|
|
93
81
|
|
|
94
|
-
if (
|
|
95
|
-
(normalisedCoin.type === 'id' && normalisedCoin.value === 60) ||
|
|
96
|
-
(normalisedCoin.type === 'name' && normalisedCoin.value === 'ETH')
|
|
97
|
-
) {
|
|
82
|
+
if (coder.coinType === 60) {
|
|
98
83
|
response = decodeFunctionResult({
|
|
99
84
|
abi: publicResolverSingleAddrSnippet,
|
|
100
85
|
functionName: 'addr',
|
|
@@ -115,13 +100,13 @@ const decode = async (
|
|
|
115
100
|
return null
|
|
116
101
|
}
|
|
117
102
|
|
|
118
|
-
const decodedAddr =
|
|
103
|
+
const decodedAddr = coder.encode(hexToBytes(response))
|
|
119
104
|
|
|
120
105
|
if (!decodedAddr) {
|
|
121
106
|
return null
|
|
122
107
|
}
|
|
123
108
|
|
|
124
|
-
return { id:
|
|
109
|
+
return { id: coder.coinType, name: coder.name, value: decodedAddr }
|
|
125
110
|
}
|
|
126
111
|
|
|
127
112
|
const _getAddr = generateFunction({ encode, decode })
|
|
@@ -59,7 +59,7 @@ const decode = async (
|
|
|
59
59
|
functionName: 'findResolver',
|
|
60
60
|
args: passthrough.args,
|
|
61
61
|
address: passthrough.address,
|
|
62
|
-
})
|
|
62
|
+
}) as BaseError
|
|
63
63
|
const response = decodeFunctionResult({
|
|
64
64
|
abi: universalResolverFindResolverSnippet,
|
|
65
65
|
functionName: 'findResolver',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCoderByCoinType } from '@ensdomains/address-encoder'
|
|
2
2
|
import { gql } from 'graphql-request'
|
|
3
|
+
import { hexToBytes } from 'viem'
|
|
3
4
|
import type { ClientWithEns } from '../../contracts/consts.js'
|
|
4
5
|
import { decodeContentHash } from '../../utils/contentHash.js'
|
|
5
6
|
import { namehash } from '../../utils/normalise.js'
|
|
@@ -276,7 +277,7 @@ const getNameHistory = async (
|
|
|
276
277
|
}
|
|
277
278
|
case 'MulticoinAddrChanged': {
|
|
278
279
|
const { multiaddr, ...event_ } = event
|
|
279
|
-
const format =
|
|
280
|
+
const format = getCoderByCoinType(parseInt(event.coinType))
|
|
280
281
|
if (!format) {
|
|
281
282
|
return {
|
|
282
283
|
...event_,
|
|
@@ -297,7 +298,7 @@ const getNameHistory = async (
|
|
|
297
298
|
...event_,
|
|
298
299
|
coinName: format.name,
|
|
299
300
|
decoded: true,
|
|
300
|
-
addr: format.
|
|
301
|
+
addr: format.encode(hexToBytes(multiaddr)),
|
|
301
302
|
}
|
|
302
303
|
}
|
|
303
304
|
case 'ContenthashChanged': {
|
package/src/types.ts
CHANGED
|
@@ -11,9 +11,12 @@ export type Prettify<T> = {
|
|
|
11
11
|
[K in keyof T]: T[K]
|
|
12
12
|
} & {}
|
|
13
13
|
|
|
14
|
-
export type SimpleTransactionRequest =
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export type SimpleTransactionRequest = {
|
|
15
|
+
[P in keyof Pick<TransactionRequest, 'to' | 'data'>]-?: Exclude<
|
|
16
|
+
TransactionRequest[P],
|
|
17
|
+
null
|
|
18
|
+
>
|
|
19
|
+
}
|
|
17
20
|
|
|
18
21
|
export type TransactionRequestWithPassthrough = SimpleTransactionRequest & {
|
|
19
22
|
passthrough?: any
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { formatsByCoinType, formatsByName } from '@ensdomains/address-encoder'
|
|
2
1
|
import { bytesToHex, encodeFunctionData, type Address, type Hex } from 'viem'
|
|
3
2
|
import { publicResolverSetAddrSnippet } from '../../contracts/publicResolver.js'
|
|
3
|
+
import { getCoderFromCoin } from '../normaliseCoinId.js'
|
|
4
4
|
|
|
5
5
|
export type EncodeSetAddrParameters = {
|
|
6
6
|
namehash: Hex
|
|
@@ -15,22 +15,11 @@ export const encodeSetAddr = ({
|
|
|
15
15
|
coin,
|
|
16
16
|
value,
|
|
17
17
|
}: EncodeSetAddrParameters): EncodeSetAddrReturnType => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} else if (!Number.isNaN(parseInt(coin))) {
|
|
22
|
-
coinTypeInstance = formatsByCoinType[parseInt(coin)]
|
|
23
|
-
} else {
|
|
24
|
-
coinTypeInstance = formatsByName[coin.toUpperCase()]
|
|
25
|
-
}
|
|
26
|
-
const inputCoinType = coinTypeInstance.coinType
|
|
27
|
-
let encodedAddress: Hex | Uint8Array = value
|
|
28
|
-
? coinTypeInstance.decoder(value)
|
|
29
|
-
: '0x'
|
|
18
|
+
const coder = getCoderFromCoin(coin)
|
|
19
|
+
const inputCoinType = coder.coinType
|
|
20
|
+
let encodedAddress: Hex | Uint8Array = value ? coder.decode(value) : '0x'
|
|
30
21
|
if (inputCoinType === 60 && encodedAddress === '0x')
|
|
31
|
-
encodedAddress =
|
|
32
|
-
'0x0000000000000000000000000000000000000000',
|
|
33
|
-
)
|
|
22
|
+
encodedAddress = coder.decode('0x0000000000000000000000000000000000000000')
|
|
34
23
|
if (typeof encodedAddress !== 'string') {
|
|
35
24
|
encodedAddress = bytesToHex(encodedAddress)
|
|
36
25
|
}
|
|
@@ -1,11 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCoderByCoinName,
|
|
3
|
+
getCoderByCoinType,
|
|
4
|
+
type Coin,
|
|
5
|
+
} from '@ensdomains/address-encoder'
|
|
6
|
+
import { CoinFormatterNotFoundError } from '../errors/public.js'
|
|
7
|
+
|
|
1
8
|
export const normaliseCoinId = (coinId: string | number) => {
|
|
2
9
|
const isString = typeof coinId === 'string'
|
|
3
10
|
|
|
4
11
|
if (isString && Number.isNaN(parseInt(coinId))) {
|
|
5
|
-
return {
|
|
12
|
+
return {
|
|
13
|
+
type: 'name',
|
|
14
|
+
value: coinId.toLowerCase().replace(/legacy$/, 'Legacy'),
|
|
15
|
+
} as const
|
|
6
16
|
}
|
|
7
17
|
return {
|
|
8
18
|
type: 'id',
|
|
9
19
|
value: isString ? parseInt(coinId as string) : (coinId as number),
|
|
10
20
|
} as const
|
|
11
21
|
}
|
|
22
|
+
|
|
23
|
+
export const getCoderFromCoin = (coinId: string | number): Coin => {
|
|
24
|
+
const normalisedCoin = normaliseCoinId(coinId)
|
|
25
|
+
let coder: Coin
|
|
26
|
+
try {
|
|
27
|
+
coder =
|
|
28
|
+
normalisedCoin.type === 'id'
|
|
29
|
+
? getCoderByCoinType(normalisedCoin.value)
|
|
30
|
+
: getCoderByCoinName(normalisedCoin.value)
|
|
31
|
+
} catch {
|
|
32
|
+
throw new CoinFormatterNotFoundError({ coinType: coinId })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return coder
|
|
36
|
+
}
|