@ensdomains/ensjs 3.0.0-beta.8 → 3.0.0

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 (140) hide show
  1. package/contracts/OldestResolver.json +170 -0
  2. package/dist/cjs/clients/public.js.map +1 -1
  3. package/dist/cjs/clients/subgraph.js.map +1 -1
  4. package/dist/cjs/contracts/consts.js +3 -3
  5. package/dist/cjs/contracts/universalResolver.js +46 -1
  6. package/dist/cjs/contracts/universalResolver.js.map +1 -1
  7. package/dist/cjs/errors/version.js +1 -1
  8. package/dist/cjs/errors/version.js.map +1 -1
  9. package/dist/cjs/functions/public/_getAbi.js +2 -2
  10. package/dist/cjs/functions/public/_getAbi.js.map +1 -1
  11. package/dist/cjs/functions/public/_getAddr.js +7 -19
  12. package/dist/cjs/functions/public/_getAddr.js.map +1 -1
  13. package/dist/cjs/functions/public/getName.js.map +1 -1
  14. package/dist/cjs/functions/public/getRecords.js +5 -5
  15. package/dist/cjs/functions/public/getRecords.js.map +1 -1
  16. package/dist/cjs/functions/public/getResolver.js.map +1 -1
  17. package/dist/cjs/functions/public/getWrapperData.js.map +1 -1
  18. package/dist/cjs/functions/public/getWrapperName.js.map +1 -1
  19. package/dist/cjs/functions/public/multicallWrapper.js.map +1 -1
  20. package/dist/cjs/functions/public/universalWrapper.js.map +1 -1
  21. package/dist/cjs/functions/subgraph/getNameHistory.js +3 -2
  22. package/dist/cjs/functions/subgraph/getNameHistory.js.map +1 -1
  23. package/dist/cjs/utils/encoders/encodeAbi.js +2 -2
  24. package/dist/cjs/utils/encoders/encodeAbi.js.map +1 -1
  25. package/dist/cjs/utils/encoders/encodeSetAddr.js +5 -16
  26. package/dist/cjs/utils/encoders/encodeSetAddr.js.map +1 -1
  27. package/dist/cjs/utils/generateRecordCallArray.js +4 -3
  28. package/dist/cjs/utils/generateRecordCallArray.js.map +1 -1
  29. package/dist/cjs/utils/getRevertErrorData.js +4 -1
  30. package/dist/cjs/utils/getRevertErrorData.js.map +1 -1
  31. package/dist/cjs/utils/normaliseCoinId.js +22 -2
  32. package/dist/cjs/utils/normaliseCoinId.js.map +1 -1
  33. package/dist/esm/clients/public.js.map +1 -1
  34. package/dist/esm/clients/subgraph.js.map +1 -1
  35. package/dist/esm/contracts/consts.js +3 -3
  36. package/dist/esm/contracts/universalResolver.js +46 -1
  37. package/dist/esm/contracts/universalResolver.js.map +1 -1
  38. package/dist/esm/errors/version.js +1 -1
  39. package/dist/esm/errors/version.js.map +1 -1
  40. package/dist/esm/functions/public/_getAbi.js +2 -2
  41. package/dist/esm/functions/public/_getAbi.js.map +1 -1
  42. package/dist/esm/functions/public/_getAddr.js +9 -21
  43. package/dist/esm/functions/public/_getAddr.js.map +1 -1
  44. package/dist/esm/functions/public/getName.js.map +1 -1
  45. package/dist/esm/functions/public/getRecords.js +5 -9
  46. package/dist/esm/functions/public/getRecords.js.map +1 -1
  47. package/dist/esm/functions/public/getResolver.js.map +1 -1
  48. package/dist/esm/functions/public/getWrapperData.js.map +1 -1
  49. package/dist/esm/functions/public/getWrapperName.js.map +1 -1
  50. package/dist/esm/functions/public/multicallWrapper.js.map +1 -1
  51. package/dist/esm/functions/public/universalWrapper.js.map +1 -1
  52. package/dist/esm/functions/subgraph/getNameHistory.js +4 -3
  53. package/dist/esm/functions/subgraph/getNameHistory.js.map +1 -1
  54. package/dist/esm/utils/encoders/encodeAbi.js +2 -2
  55. package/dist/esm/utils/encoders/encodeAbi.js.map +1 -1
  56. package/dist/esm/utils/encoders/encodeSetAddr.js +5 -16
  57. package/dist/esm/utils/encoders/encodeSetAddr.js.map +1 -1
  58. package/dist/esm/utils/generateRecordCallArray.js +4 -3
  59. package/dist/esm/utils/generateRecordCallArray.js.map +1 -1
  60. package/dist/esm/utils/getRevertErrorData.js +4 -1
  61. package/dist/esm/utils/getRevertErrorData.js.map +1 -1
  62. package/dist/esm/utils/normaliseCoinId.js +20 -1
  63. package/dist/esm/utils/normaliseCoinId.js.map +1 -1
  64. package/dist/types/clients/public.d.ts +4 -240
  65. package/dist/types/clients/public.d.ts.map +1 -1
  66. package/dist/types/clients/subgraph.d.ts +4 -240
  67. package/dist/types/clients/subgraph.d.ts.map +1 -1
  68. package/dist/types/clients/wallet.d.ts +6 -6
  69. package/dist/types/contracts/consts.d.ts +3 -3
  70. package/dist/types/contracts/universalResolver.d.ts +133 -1
  71. package/dist/types/contracts/universalResolver.d.ts.map +1 -1
  72. package/dist/types/errors/version.d.ts +1 -1
  73. package/dist/types/errors/version.d.ts.map +1 -1
  74. package/dist/types/functions/dns/importDnsName.d.ts +1 -4
  75. package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
  76. package/dist/types/functions/public/_getAddr.d.ts.map +1 -1
  77. package/dist/types/functions/public/getRecords.d.ts.map +1 -1
  78. package/dist/types/functions/subgraph/getNameHistory.d.ts.map +1 -1
  79. package/dist/types/functions/wallet/clearRecords.d.ts +1 -4
  80. package/dist/types/functions/wallet/clearRecords.d.ts.map +1 -1
  81. package/dist/types/functions/wallet/commitName.d.ts +1 -4
  82. package/dist/types/functions/wallet/commitName.d.ts.map +1 -1
  83. package/dist/types/functions/wallet/createSubname.d.ts +1 -4
  84. package/dist/types/functions/wallet/createSubname.d.ts.map +1 -1
  85. package/dist/types/functions/wallet/deleteSubname.d.ts +1 -4
  86. package/dist/types/functions/wallet/deleteSubname.d.ts.map +1 -1
  87. package/dist/types/functions/wallet/setAbiRecord.d.ts +1 -4
  88. package/dist/types/functions/wallet/setAbiRecord.d.ts.map +1 -1
  89. package/dist/types/functions/wallet/setAddressRecord.d.ts +1 -4
  90. package/dist/types/functions/wallet/setAddressRecord.d.ts.map +1 -1
  91. package/dist/types/functions/wallet/setChildFuses.d.ts +1 -4
  92. package/dist/types/functions/wallet/setChildFuses.d.ts.map +1 -1
  93. package/dist/types/functions/wallet/setContentHashRecord.d.ts +1 -4
  94. package/dist/types/functions/wallet/setContentHashRecord.d.ts.map +1 -1
  95. package/dist/types/functions/wallet/setFuses.d.ts +1 -4
  96. package/dist/types/functions/wallet/setFuses.d.ts.map +1 -1
  97. package/dist/types/functions/wallet/setPrimaryName.d.ts +1 -4
  98. package/dist/types/functions/wallet/setPrimaryName.d.ts.map +1 -1
  99. package/dist/types/functions/wallet/setRecords.d.ts +1 -4
  100. package/dist/types/functions/wallet/setRecords.d.ts.map +1 -1
  101. package/dist/types/functions/wallet/setResolver.d.ts +1 -4
  102. package/dist/types/functions/wallet/setResolver.d.ts.map +1 -1
  103. package/dist/types/functions/wallet/setTextRecord.d.ts +1 -4
  104. package/dist/types/functions/wallet/setTextRecord.d.ts.map +1 -1
  105. package/dist/types/functions/wallet/transferName.d.ts +1 -4
  106. package/dist/types/functions/wallet/transferName.d.ts.map +1 -1
  107. package/dist/types/functions/wallet/unwrapName.d.ts +1 -4
  108. package/dist/types/functions/wallet/unwrapName.d.ts.map +1 -1
  109. package/dist/types/functions/wallet/wrapName.d.ts +1 -4
  110. package/dist/types/functions/wallet/wrapName.d.ts.map +1 -1
  111. package/dist/types/types.d.ts +3 -1
  112. package/dist/types/types.d.ts.map +1 -1
  113. package/dist/types/utils/encoders/encodeSetAddr.d.ts.map +1 -1
  114. package/dist/types/utils/generateRecordCallArray.d.ts +5 -5
  115. package/dist/types/utils/generateRecordCallArray.d.ts.map +1 -1
  116. package/dist/types/utils/getRevertErrorData.d.ts.map +1 -1
  117. package/dist/types/utils/normaliseCoinId.d.ts +2 -0
  118. package/dist/types/utils/normaliseCoinId.d.ts.map +1 -1
  119. package/package.json +5 -6
  120. package/src/clients/public.ts +2 -1
  121. package/src/clients/subgraph.ts +2 -1
  122. package/src/contracts/consts.ts +3 -3
  123. package/src/contracts/universalResolver.ts +46 -1
  124. package/src/errors/version.ts +1 -1
  125. package/src/functions/public/_getAbi.ts +2 -2
  126. package/src/functions/public/_getAddr.ts +15 -30
  127. package/src/functions/public/getName.ts +1 -1
  128. package/src/functions/public/getRecords.ts +6 -10
  129. package/src/functions/public/getResolver.ts +1 -1
  130. package/src/functions/public/getWrapperData.ts +1 -1
  131. package/src/functions/public/getWrapperName.ts +1 -1
  132. package/src/functions/public/multicallWrapper.ts +1 -1
  133. package/src/functions/public/universalWrapper.ts +1 -1
  134. package/src/functions/subgraph/getNameHistory.ts +4 -3
  135. package/src/types.ts +6 -3
  136. package/src/utils/encoders/encodeAbi.ts +2 -2
  137. package/src/utils/encoders/encodeSetAddr.ts +5 -16
  138. package/src/utils/generateRecordCallArray.ts +7 -5
  139. package/src/utils/getRevertErrorData.ts +3 -1
  140. package/src/utils/normaliseCoinId.ts +26 -1
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
@@ -86,8 +86,8 @@ export const encodeAbi = async <
86
86
  }
87
87
  case 'cbor': {
88
88
  contentType = 4
89
- const { encode } = await import('cbor')
90
- encodedData = bytesToHex(encode(data))
89
+ const { cborEncode } = await import('@ensdomains/address-encoder/utils')
90
+ encodedData = bytesToHex(new Uint8Array(cborEncode(data)))
91
91
  break
92
92
  }
93
93
  default: {
@@ -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,5 +1,6 @@
1
1
  import { type Hex } from 'viem'
2
2
  import type { Prettify } from '../types.js'
3
+ import type { EncodedAbi } from './encoders/encodeAbi.js'
3
4
  import { encodeClearRecords } from './encoders/encodeClearRecords.js'
4
5
  import {
5
6
  encodeSetAbi,
@@ -19,13 +20,13 @@ export type RecordOptions = Prettify<{
19
20
  /** Clears all current records */
20
21
  clearRecords?: boolean
21
22
  /** ContentHash value */
22
- contentHash?: string
23
+ contentHash?: string | null
23
24
  /** Array of text records */
24
25
  texts?: Omit<EncodeSetTextParameters, 'namehash'>[]
25
26
  /** Array of coin records */
26
27
  coins?: Omit<EncodeSetAddrParameters, 'namehash'>[]
27
28
  /** ABI value */
28
- abi?: Omit<EncodeSetAbiParameters, 'namehash'>
29
+ abi?: EncodedAbi | null
29
30
  }>
30
31
 
31
32
  export const generateRecordCallArray = ({
@@ -42,13 +43,14 @@ export const generateRecordCallArray = ({
42
43
  calls.push(encodeClearRecords(namehash))
43
44
  }
44
45
 
45
- if (typeof contentHash === 'string') {
46
+ if (contentHash !== undefined) {
46
47
  const data = encodeSetContentHash({ namehash, contentHash })
47
48
  if (data) calls.push(data)
48
49
  }
49
50
 
50
- if (abi) {
51
- const data = encodeSetAbi({ namehash, ...abi } as EncodeSetAbiParameters)
51
+ if (abi !== undefined) {
52
+ const abi_ = abi ?? { contentType: 0, encodedData: null }
53
+ const data = encodeSetAbi({ namehash, ...abi_ } as EncodeSetAbiParameters)
52
54
  if (data) calls.push(data)
53
55
  }
54
56
 
@@ -3,5 +3,7 @@ import { BaseError, RawContractError } from 'viem'
3
3
  export const getRevertErrorData = (err: unknown) => {
4
4
  if (!(err instanceof BaseError)) return undefined
5
5
  const error = err.walk() as RawContractError
6
- return typeof error.data === 'object' ? error.data.data : error.data
6
+ const hex = typeof error.data === 'object' ? error.data.data : error.data
7
+ if (hex === '0x') return undefined
8
+ return hex
7
9
  }
@@ -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
+ }