@ensdomains/ensjs 3.0.0-beta.7 → 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.
Files changed (111) hide show
  1. package/dist/cjs/clients/public.js.map +1 -1
  2. package/dist/cjs/clients/subgraph.js.map +1 -1
  3. package/dist/cjs/errors/version.js +1 -1
  4. package/dist/cjs/functions/public/_getAddr.js +7 -19
  5. package/dist/cjs/functions/public/_getAddr.js.map +1 -1
  6. package/dist/cjs/functions/public/getName.js.map +1 -1
  7. package/dist/cjs/functions/public/getRecords.js.map +1 -1
  8. package/dist/cjs/functions/public/getResolver.js.map +1 -1
  9. package/dist/cjs/functions/public/getWrapperData.js.map +1 -1
  10. package/dist/cjs/functions/public/getWrapperName.js.map +1 -1
  11. package/dist/cjs/functions/public/multicallWrapper.js.map +1 -1
  12. package/dist/cjs/functions/public/universalWrapper.js.map +1 -1
  13. package/dist/cjs/functions/subgraph/client.js.map +1 -1
  14. package/dist/cjs/functions/subgraph/getNameHistory.js +3 -2
  15. package/dist/cjs/functions/subgraph/getNameHistory.js.map +1 -1
  16. package/dist/cjs/utils/encoders/encodeSetAddr.js +5 -16
  17. package/dist/cjs/utils/encoders/encodeSetAddr.js.map +1 -1
  18. package/dist/cjs/utils/normaliseCoinId.js +22 -2
  19. package/dist/cjs/utils/normaliseCoinId.js.map +1 -1
  20. package/dist/esm/clients/public.js.map +1 -1
  21. package/dist/esm/clients/subgraph.js.map +1 -1
  22. package/dist/esm/errors/version.js +1 -1
  23. package/dist/esm/functions/public/_getAddr.js +9 -21
  24. package/dist/esm/functions/public/_getAddr.js.map +1 -1
  25. package/dist/esm/functions/public/getName.js.map +1 -1
  26. package/dist/esm/functions/public/getRecords.js.map +1 -1
  27. package/dist/esm/functions/public/getResolver.js.map +1 -1
  28. package/dist/esm/functions/public/getWrapperData.js.map +1 -1
  29. package/dist/esm/functions/public/getWrapperName.js.map +1 -1
  30. package/dist/esm/functions/public/multicallWrapper.js.map +1 -1
  31. package/dist/esm/functions/public/universalWrapper.js.map +1 -1
  32. package/dist/esm/functions/subgraph/client.js.map +1 -1
  33. package/dist/esm/functions/subgraph/getNameHistory.js +4 -3
  34. package/dist/esm/functions/subgraph/getNameHistory.js.map +1 -1
  35. package/dist/esm/utils/encoders/encodeSetAddr.js +5 -16
  36. package/dist/esm/utils/encoders/encodeSetAddr.js.map +1 -1
  37. package/dist/esm/utils/normaliseCoinId.js +20 -1
  38. package/dist/esm/utils/normaliseCoinId.js.map +1 -1
  39. package/dist/types/clients/decorators/wallet.d.ts +7 -4
  40. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  41. package/dist/types/clients/public.d.ts +4 -236
  42. package/dist/types/clients/public.d.ts.map +1 -1
  43. package/dist/types/clients/subgraph.d.ts +4 -236
  44. package/dist/types/clients/subgraph.d.ts.map +1 -1
  45. package/dist/types/clients/wallet.d.ts +7 -4
  46. package/dist/types/clients/wallet.d.ts.map +1 -1
  47. package/dist/types/errors/version.d.ts +1 -1
  48. package/dist/types/functions/dns/importDnsName.d.ts +15 -12
  49. package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
  50. package/dist/types/functions/public/_getAddr.d.ts.map +1 -1
  51. package/dist/types/functions/subgraph/client.d.ts +2 -2
  52. package/dist/types/functions/subgraph/client.d.ts.map +1 -1
  53. package/dist/types/functions/subgraph/getNameHistory.d.ts.map +1 -1
  54. package/dist/types/functions/wallet/clearRecords.d.ts +15 -12
  55. package/dist/types/functions/wallet/clearRecords.d.ts.map +1 -1
  56. package/dist/types/functions/wallet/commitName.d.ts +15 -12
  57. package/dist/types/functions/wallet/commitName.d.ts.map +1 -1
  58. package/dist/types/functions/wallet/createSubname.d.ts +15 -12
  59. package/dist/types/functions/wallet/createSubname.d.ts.map +1 -1
  60. package/dist/types/functions/wallet/deleteSubname.d.ts +15 -12
  61. package/dist/types/functions/wallet/deleteSubname.d.ts.map +1 -1
  62. package/dist/types/functions/wallet/registerName.d.ts +14 -8
  63. package/dist/types/functions/wallet/registerName.d.ts.map +1 -1
  64. package/dist/types/functions/wallet/renewNames.d.ts +14 -8
  65. package/dist/types/functions/wallet/renewNames.d.ts.map +1 -1
  66. package/dist/types/functions/wallet/setAbiRecord.d.ts +15 -12
  67. package/dist/types/functions/wallet/setAbiRecord.d.ts.map +1 -1
  68. package/dist/types/functions/wallet/setAddressRecord.d.ts +15 -12
  69. package/dist/types/functions/wallet/setAddressRecord.d.ts.map +1 -1
  70. package/dist/types/functions/wallet/setChildFuses.d.ts +15 -12
  71. package/dist/types/functions/wallet/setChildFuses.d.ts.map +1 -1
  72. package/dist/types/functions/wallet/setContentHashRecord.d.ts +15 -12
  73. package/dist/types/functions/wallet/setContentHashRecord.d.ts.map +1 -1
  74. package/dist/types/functions/wallet/setFuses.d.ts +15 -12
  75. package/dist/types/functions/wallet/setFuses.d.ts.map +1 -1
  76. package/dist/types/functions/wallet/setPrimaryName.d.ts +15 -12
  77. package/dist/types/functions/wallet/setPrimaryName.d.ts.map +1 -1
  78. package/dist/types/functions/wallet/setRecords.d.ts +15 -12
  79. package/dist/types/functions/wallet/setRecords.d.ts.map +1 -1
  80. package/dist/types/functions/wallet/setResolver.d.ts +15 -12
  81. package/dist/types/functions/wallet/setResolver.d.ts.map +1 -1
  82. package/dist/types/functions/wallet/setTextRecord.d.ts +15 -12
  83. package/dist/types/functions/wallet/setTextRecord.d.ts.map +1 -1
  84. package/dist/types/functions/wallet/transferName.d.ts +15 -12
  85. package/dist/types/functions/wallet/transferName.d.ts.map +1 -1
  86. package/dist/types/functions/wallet/unwrapName.d.ts +15 -12
  87. package/dist/types/functions/wallet/unwrapName.d.ts.map +1 -1
  88. package/dist/types/functions/wallet/wrapName.d.ts +15 -12
  89. package/dist/types/functions/wallet/wrapName.d.ts.map +1 -1
  90. package/dist/types/types.d.ts +3 -1
  91. package/dist/types/types.d.ts.map +1 -1
  92. package/dist/types/utils/encoders/encodeSetAddr.d.ts.map +1 -1
  93. package/dist/types/utils/normaliseCoinId.d.ts +2 -0
  94. package/dist/types/utils/normaliseCoinId.d.ts.map +1 -1
  95. package/package.json +4 -4
  96. package/src/clients/public.ts +2 -1
  97. package/src/clients/subgraph.ts +2 -1
  98. package/src/errors/version.ts +1 -1
  99. package/src/functions/public/_getAddr.ts +15 -30
  100. package/src/functions/public/getName.ts +1 -1
  101. package/src/functions/public/getRecords.ts +1 -1
  102. package/src/functions/public/getResolver.ts +1 -1
  103. package/src/functions/public/getWrapperData.ts +1 -1
  104. package/src/functions/public/getWrapperName.ts +1 -1
  105. package/src/functions/public/multicallWrapper.ts +1 -1
  106. package/src/functions/public/universalWrapper.ts +1 -1
  107. package/src/functions/subgraph/client.ts +2 -2
  108. package/src/functions/subgraph/getNameHistory.ts +4 -3
  109. package/src/types.ts +6 -3
  110. package/src/utils/encoders/encodeSetAddr.ts +5 -16
  111. package/src/utils/normaliseCoinId.ts +26 -1
@@ -1 +1 @@
1
- export const version = 'v3.0.0-beta.7'
1
+ export const version = 'v3.0.0-beta.9'
@@ -1,5 +1,10 @@
1
- import { formatsByCoinType, formatsByName } from '@ensdomains/address-encoder'
2
- import { decodeFunctionResult, encodeFunctionData, trim, type Hex } from 'viem'
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 { normaliseCoinId } from '../../utils/normaliseCoinId.js'
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 normalisedCoin = normaliseCoinId(coin)
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(formatter.coinType)],
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 normalisedCoin = normaliseCoinId(coin)
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 = formatter.encoder(Buffer.from(response.slice(2), 'hex'))
103
+ const decodedAddr = coder.encode(hexToBytes(response))
119
104
 
120
105
  if (!decodedAddr) {
121
106
  return null
122
107
  }
123
108
 
124
- return { id: formatter.coinType, name: formatter.name, value: decodedAddr }
109
+ return { id: coder.coinType, name: coder.name, value: decodedAddr }
125
110
  }
126
111
 
127
112
  const _getAddr = generateFunction({ encode, decode })
@@ -83,7 +83,7 @@ const decode = async (
83
83
  functionName: 'reverse',
84
84
  args: passthrough.args,
85
85
  address: passthrough.address,
86
- })
86
+ }) as BaseError
87
87
  }
88
88
  const result = decodeFunctionResult({
89
89
  abi: universalResolverReverseSnippet,
@@ -248,7 +248,7 @@ const decode = async <TParams extends GetRecordsParameters>(
248
248
  client,
249
249
  contract: 'ensUniversalResolver',
250
250
  }),
251
- })
251
+ }) as BaseError
252
252
  }
253
253
  const result = decodeFunctionResult({
254
254
  abi: universalResolverResolveArraySnippet,
@@ -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',
@@ -71,7 +71,7 @@ const decode = async (
71
71
  functionName: 'getData',
72
72
  args: passthrough.args,
73
73
  address: passthrough.address,
74
- })
74
+ }) as BaseError
75
75
  const [owner, fuses, expiry] = decodeFunctionResult({
76
76
  abi: nameWrapperGetDataSnippet,
77
77
  functionName: 'getData',
@@ -58,7 +58,7 @@ const decode = async (
58
58
  functionName: 'names',
59
59
  args: passthrough.args,
60
60
  address: passthrough.address,
61
- })
61
+ }) as BaseError
62
62
  const result = decodeFunctionResult({
63
63
  abi: nameWrapperNamesSnippet,
64
64
  functionName: 'names',
@@ -52,7 +52,7 @@ const decode = async (
52
52
  abi: multicallTryAggregateSnippet,
53
53
  functionName: 'tryAggregate',
54
54
  args: [],
55
- })
55
+ }) as BaseError
56
56
  }
57
57
  const result = decodeFunctionResult({
58
58
  abi: multicallTryAggregateSnippet,
@@ -92,7 +92,7 @@ const decode = async (
92
92
  functionName: 'resolve',
93
93
  args: passthrough.args,
94
94
  address: passthrough.address,
95
- })
95
+ }) as BaseError
96
96
  }
97
97
 
98
98
  const result = decodeFunctionResult({
@@ -1,6 +1,6 @@
1
1
  import type { Kind, SelectionNode, SelectionSetNode } from 'graphql'
2
+ import type { RequestMiddleware, ResponseMiddleware } from 'graphql-request'
2
3
  import { GraphQLClient } from 'graphql-request'
3
- import type { RequestMiddleware, Response } from 'graphql-request/dist/types.js'
4
4
  import { parse, print, visit } from 'graphql/language/index.js'
5
5
  import traverse from 'traverse'
6
6
  import type { ClientWithEns } from '../../contracts/consts.js'
@@ -56,7 +56,7 @@ export const requestMiddleware: RequestMiddleware = (request) => {
56
56
  }
57
57
  }
58
58
 
59
- export const responseMiddleware = (response: Response<unknown> | Error) => {
59
+ export const responseMiddleware: ResponseMiddleware = (response) => {
60
60
  traverse(response).forEach(function (responseItem: unknown) {
61
61
  if (
62
62
  responseItem instanceof Object &&
@@ -1,5 +1,6 @@
1
- import { formatsByCoinType } from '@ensdomains/address-encoder'
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 = formatsByCoinType[parseInt(event.coinType)]
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.encoder(Buffer.from(multiaddr.slice(2), 'hex')),
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 = Prettify<
15
- Required<Pick<TransactionRequest, 'to' | 'data'>>
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
- let coinTypeInstance
19
- if (typeof coin === 'number') {
20
- coinTypeInstance = formatsByCoinType[coin]
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 = coinTypeInstance.decoder(
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 { type: 'name', value: coinId.toUpperCase() } as const
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
+ }