@ensdomains/ensjs 3.0.0-alpha.4 → 3.0.0-alpha.7

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 (86) hide show
  1. package/dist/cjs/GqlManager.d.ts +3 -0
  2. package/dist/cjs/GqlManager.js +62 -2
  3. package/dist/cjs/functions/burnFuses.d.ts +3 -1
  4. package/dist/cjs/functions/burnFuses.js +2 -6
  5. package/dist/cjs/functions/createSubname.d.ts +1 -5
  6. package/dist/cjs/functions/createSubname.js +3 -7
  7. package/dist/cjs/functions/deleteSubname.d.ts +3 -3
  8. package/dist/cjs/functions/deleteSubname.js +5 -2
  9. package/dist/cjs/functions/setName.d.ts +4 -3
  10. package/dist/cjs/functions/setName.js +5 -10
  11. package/dist/cjs/functions/setRecords.d.ts +4 -1
  12. package/dist/cjs/functions/setRecords.js +11 -9
  13. package/dist/cjs/functions/setResolver.d.ts +4 -3
  14. package/dist/cjs/functions/setResolver.js +5 -11
  15. package/dist/cjs/functions/transferName.d.ts +4 -3
  16. package/dist/cjs/functions/transferName.js +8 -13
  17. package/dist/cjs/functions/transferSubname.d.ts +4 -3
  18. package/dist/cjs/functions/transferSubname.js +3 -7
  19. package/dist/cjs/functions/unwrapName.d.ts +4 -3
  20. package/dist/cjs/functions/unwrapName.js +3 -8
  21. package/dist/cjs/functions/wrapName.d.ts +5 -3
  22. package/dist/cjs/functions/wrapName.js +8 -12
  23. package/dist/cjs/index.d.ts +40 -44
  24. package/dist/cjs/index.js +39 -22
  25. package/dist/cjs/utils/normalise.d.ts +1 -1
  26. package/dist/cjs/utils/normalise.js +10 -3
  27. package/dist/cjs/utils/writeTx.d.ts +4 -0
  28. package/dist/cjs/utils/writeTx.js +3 -0
  29. package/dist/esm/GqlManager.d.ts +3 -0
  30. package/dist/esm/GqlManager.js +58 -2
  31. package/dist/esm/functions/burnFuses.d.ts +3 -1
  32. package/dist/esm/functions/burnFuses.js +2 -6
  33. package/dist/esm/functions/createSubname.d.ts +1 -5
  34. package/dist/esm/functions/createSubname.js +3 -7
  35. package/dist/esm/functions/deleteSubname.d.ts +3 -3
  36. package/dist/esm/functions/deleteSubname.js +5 -2
  37. package/dist/esm/functions/setName.d.ts +4 -3
  38. package/dist/esm/functions/setName.js +5 -10
  39. package/dist/esm/functions/setRecords.d.ts +4 -1
  40. package/dist/esm/functions/setRecords.js +11 -9
  41. package/dist/esm/functions/setResolver.d.ts +4 -3
  42. package/dist/esm/functions/setResolver.js +5 -11
  43. package/dist/esm/functions/transferName.d.ts +4 -3
  44. package/dist/esm/functions/transferName.js +8 -13
  45. package/dist/esm/functions/transferSubname.d.ts +4 -3
  46. package/dist/esm/functions/transferSubname.js +3 -7
  47. package/dist/esm/functions/unwrapName.d.ts +4 -3
  48. package/dist/esm/functions/unwrapName.js +3 -8
  49. package/dist/esm/functions/wrapName.d.ts +5 -3
  50. package/dist/esm/functions/wrapName.js +8 -12
  51. package/dist/esm/index.d.ts +40 -44
  52. package/dist/esm/index.js +39 -22
  53. package/dist/esm/utils/normalise.d.ts +1 -1
  54. package/dist/esm/utils/normalise.js +10 -3
  55. package/dist/esm/utils/writeTx.d.ts +4 -0
  56. package/dist/esm/utils/writeTx.js +1 -0
  57. package/package.json +7 -5
  58. package/src/GqlManager.test.ts +170 -0
  59. package/src/GqlManager.ts +67 -2
  60. package/src/functions/burnFuses.test.ts +9 -8
  61. package/src/functions/burnFuses.ts +7 -9
  62. package/src/functions/createSubname.test.ts +8 -11
  63. package/src/functions/createSubname.ts +5 -12
  64. package/src/functions/deleteSubname.test.ts +28 -27
  65. package/src/functions/deleteSubname.ts +9 -12
  66. package/src/functions/getFuses.test.ts +11 -9
  67. package/src/functions/getOwner.test.ts +3 -1
  68. package/src/functions/setName.test.ts +3 -2
  69. package/src/functions/setName.ts +15 -17
  70. package/src/functions/setRecords.test.ts +7 -5
  71. package/src/functions/setRecords.ts +19 -13
  72. package/src/functions/setResolver.test.ts +12 -15
  73. package/src/functions/setResolver.ts +14 -19
  74. package/src/functions/transferName.test.ts +27 -29
  75. package/src/functions/transferName.ts +17 -21
  76. package/src/functions/transferSubname.test.ts +30 -29
  77. package/src/functions/transferSubname.ts +19 -12
  78. package/src/functions/unwrapName.test.ts +22 -22
  79. package/src/functions/unwrapName.ts +18 -14
  80. package/src/functions/wrapName.test.ts +15 -12
  81. package/src/functions/wrapName.ts +20 -22
  82. package/src/index.ts +105 -30
  83. package/src/tests/populateTransaction.test.ts +40 -0
  84. package/src/tests/signerInjection.test.ts +46 -0
  85. package/src/utils/normalise.ts +10 -4
  86. package/src/utils/writeTx.ts +6 -0
@@ -0,0 +1,46 @@
1
+ import { ContractTransaction, ethers } from 'ethers'
2
+ import { ENS } from '..'
3
+ import setup from '../tests/setup'
4
+
5
+ let ENSInstance: ENS
6
+ let revert: Awaited<ReturnType<typeof setup>>['revert']
7
+ let provider: ethers.providers.JsonRpcProvider
8
+ let accounts: string[]
9
+
10
+ beforeAll(async () => {
11
+ ;({ ENSInstance, revert, provider } = await setup())
12
+ accounts = await provider.listAccounts()
13
+ })
14
+
15
+ afterAll(async () => {
16
+ await revert()
17
+ })
18
+
19
+ jest.setTimeout(20000)
20
+
21
+ describe('Signer Injection', () => {
22
+ beforeEach(async () => {
23
+ await revert()
24
+ })
25
+ it('should return a transaction successfully for a custom signer', async () => {
26
+ const signer = provider.getSigner(accounts[3])
27
+ const tx = await ENSInstance.setName('fleek.eth', {
28
+ signer,
29
+ })
30
+ expect(tx).toBeTruthy()
31
+ if (tx) {
32
+ await tx.wait()
33
+ expect(tx.from).toBe(accounts[3])
34
+ }
35
+ })
36
+ it('should return a transaction succesfully for a custom signer index', async () => {
37
+ const tx = (await ENSInstance.setName('fleek.eth', {
38
+ addressOrIndex: 3,
39
+ })) as ContractTransaction
40
+ expect(tx).toBeTruthy()
41
+ if (tx) {
42
+ await tx.wait()
43
+ expect(tx.from).toBe(accounts[3])
44
+ }
45
+ })
46
+ })
@@ -1,5 +1,6 @@
1
1
  import { concat, hexlify, keccak256, toUtf8Bytes } from 'ethers/lib/utils'
2
2
  import uts46 from 'idna-uts46-hx/uts46bundle.js'
3
+ import { decodeLabelhash, isEncodedLabelhash } from './labels'
3
4
 
4
5
  const zeros = new Uint8Array(32)
5
6
  zeros.fill(0)
@@ -7,16 +8,21 @@ zeros.fill(0)
7
8
  export const normalise = (name: string) =>
8
9
  name ? uts46.toUnicode(name, { useStd3ASCII: true }) : name
9
10
 
10
- export const namehash = (inputName: string): string => {
11
+ export const namehash = (name: string): string => {
11
12
  let result: string | Uint8Array = zeros
12
13
 
13
- const name = normalise(inputName)
14
-
15
14
  if (name) {
16
15
  const labels = name.split('.')
17
16
 
18
17
  for (var i = labels.length - 1; i >= 0; i--) {
19
- const labelSha = keccak256(toUtf8Bytes(labels[i]))
18
+ let labelSha: string
19
+ if (isEncodedLabelhash(labels[i])) {
20
+ labelSha = decodeLabelhash(labels[i])
21
+ } else {
22
+ const normalised = normalise(labels[i])
23
+ labelSha = keccak256(toUtf8Bytes(normalised))
24
+ }
25
+
20
26
  result = keccak256(concat([result, labelSha]))
21
27
  }
22
28
  } else {
@@ -0,0 +1,6 @@
1
+ import { JsonRpcSigner } from '@ethersproject/providers'
2
+ import type { PopulatedTransaction } from 'ethers'
3
+
4
+ export default (signer: JsonRpcSigner, populate: boolean) =>
5
+ (tx: PopulatedTransaction) =>
6
+ populate ? tx : signer.sendTransaction(tx)