@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.
- package/dist/cjs/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/functions/burnFuses.d.ts +3 -1
- package/dist/cjs/functions/burnFuses.js +2 -6
- package/dist/cjs/functions/createSubname.d.ts +1 -5
- package/dist/cjs/functions/createSubname.js +3 -7
- package/dist/cjs/functions/deleteSubname.d.ts +3 -3
- package/dist/cjs/functions/deleteSubname.js +5 -2
- package/dist/cjs/functions/setName.d.ts +4 -3
- package/dist/cjs/functions/setName.js +5 -10
- package/dist/cjs/functions/setRecords.d.ts +4 -1
- package/dist/cjs/functions/setRecords.js +11 -9
- package/dist/cjs/functions/setResolver.d.ts +4 -3
- package/dist/cjs/functions/setResolver.js +5 -11
- package/dist/cjs/functions/transferName.d.ts +4 -3
- package/dist/cjs/functions/transferName.js +8 -13
- package/dist/cjs/functions/transferSubname.d.ts +4 -3
- package/dist/cjs/functions/transferSubname.js +3 -7
- package/dist/cjs/functions/unwrapName.d.ts +4 -3
- package/dist/cjs/functions/unwrapName.js +3 -8
- package/dist/cjs/functions/wrapName.d.ts +5 -3
- package/dist/cjs/functions/wrapName.js +8 -12
- package/dist/cjs/index.d.ts +40 -44
- package/dist/cjs/index.js +39 -22
- package/dist/cjs/utils/normalise.d.ts +1 -1
- package/dist/cjs/utils/normalise.js +10 -3
- package/dist/cjs/utils/writeTx.d.ts +4 -0
- package/dist/cjs/utils/writeTx.js +3 -0
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/functions/burnFuses.d.ts +3 -1
- package/dist/esm/functions/burnFuses.js +2 -6
- package/dist/esm/functions/createSubname.d.ts +1 -5
- package/dist/esm/functions/createSubname.js +3 -7
- package/dist/esm/functions/deleteSubname.d.ts +3 -3
- package/dist/esm/functions/deleteSubname.js +5 -2
- package/dist/esm/functions/setName.d.ts +4 -3
- package/dist/esm/functions/setName.js +5 -10
- package/dist/esm/functions/setRecords.d.ts +4 -1
- package/dist/esm/functions/setRecords.js +11 -9
- package/dist/esm/functions/setResolver.d.ts +4 -3
- package/dist/esm/functions/setResolver.js +5 -11
- package/dist/esm/functions/transferName.d.ts +4 -3
- package/dist/esm/functions/transferName.js +8 -13
- package/dist/esm/functions/transferSubname.d.ts +4 -3
- package/dist/esm/functions/transferSubname.js +3 -7
- package/dist/esm/functions/unwrapName.d.ts +4 -3
- package/dist/esm/functions/unwrapName.js +3 -8
- package/dist/esm/functions/wrapName.d.ts +5 -3
- package/dist/esm/functions/wrapName.js +8 -12
- package/dist/esm/index.d.ts +40 -44
- package/dist/esm/index.js +39 -22
- package/dist/esm/utils/normalise.d.ts +1 -1
- package/dist/esm/utils/normalise.js +10 -3
- package/dist/esm/utils/writeTx.d.ts +4 -0
- package/dist/esm/utils/writeTx.js +1 -0
- package/package.json +7 -5
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/functions/burnFuses.test.ts +9 -8
- package/src/functions/burnFuses.ts +7 -9
- package/src/functions/createSubname.test.ts +8 -11
- package/src/functions/createSubname.ts +5 -12
- package/src/functions/deleteSubname.test.ts +28 -27
- package/src/functions/deleteSubname.ts +9 -12
- package/src/functions/getFuses.test.ts +11 -9
- package/src/functions/getOwner.test.ts +3 -1
- package/src/functions/setName.test.ts +3 -2
- package/src/functions/setName.ts +15 -17
- package/src/functions/setRecords.test.ts +7 -5
- package/src/functions/setRecords.ts +19 -13
- package/src/functions/setResolver.test.ts +12 -15
- package/src/functions/setResolver.ts +14 -19
- package/src/functions/transferName.test.ts +27 -29
- package/src/functions/transferName.ts +17 -21
- package/src/functions/transferSubname.test.ts +30 -29
- package/src/functions/transferSubname.ts +19 -12
- package/src/functions/unwrapName.test.ts +22 -22
- package/src/functions/unwrapName.ts +18 -14
- package/src/functions/wrapName.test.ts +15 -12
- package/src/functions/wrapName.ts +20 -22
- package/src/index.ts +105 -30
- package/src/tests/populateTransaction.test.ts +40 -0
- package/src/tests/signerInjection.test.ts +46 -0
- package/src/utils/normalise.ts +10 -4
- 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
|
+
})
|
package/src/utils/normalise.ts
CHANGED
|
@@ -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 = (
|
|
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
|
-
|
|
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 {
|