@dynamic-labs/ethereum 3.0.0-alpha.46 → 3.0.0-alpha.48
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/CHANGELOG.md +34 -0
- package/package.json +9 -9
- package/src/utils/L2ResolverAbi.cjs +1287 -0
- package/src/utils/L2ResolverAbi.d.ts +993 -0
- package/src/utils/L2ResolverAbi.js +1285 -0
- package/src/utils/getNameservice.cjs +30 -10
- package/src/utils/getNameservice.js +30 -10
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
-
var
|
|
7
|
+
var viem = require('viem');
|
|
8
|
+
var L2ResolverAbi = require('./L2ResolverAbi.cjs');
|
|
8
9
|
|
|
9
10
|
const getNameservice = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ rpcProvider, address, }) {
|
|
10
|
-
var _b;
|
|
11
11
|
const nsData = {
|
|
12
12
|
avatar: undefined,
|
|
13
13
|
name: undefined,
|
|
@@ -16,19 +16,39 @@ const getNameservice = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function*
|
|
|
16
16
|
if (!network) {
|
|
17
17
|
return nsData;
|
|
18
18
|
}
|
|
19
|
-
//
|
|
19
|
+
// per CB team they recommended using the code
|
|
20
|
+
// from: https://github.com/coinbase/onchainkit/blob/main/src/identity/utils/getName.ts
|
|
21
|
+
// Once they will have proper resolver for the ens names we can remove this code
|
|
22
|
+
const convertReverseNodeToBytes = (address, chainId) => {
|
|
23
|
+
const addressFormatted = address.toLocaleLowerCase();
|
|
24
|
+
const addressNode = viem.keccak256(addressFormatted.substring(2));
|
|
25
|
+
const chainCoinType = convertChainIdToCoinType(chainId);
|
|
26
|
+
const baseReverseNode = viem.namehash(`${chainCoinType.toLocaleUpperCase()}.reverse`);
|
|
27
|
+
const addressReverseNode = viem.keccak256(viem.encodePacked(['bytes32', 'bytes32'], [baseReverseNode, addressNode]));
|
|
28
|
+
return addressReverseNode;
|
|
29
|
+
};
|
|
30
|
+
const convertChainIdToCoinType = (chainId) => {
|
|
31
|
+
const cointype = (0x80000000 | chainId) >>> 0;
|
|
32
|
+
return cointype.toString(16).toLocaleUpperCase();
|
|
33
|
+
};
|
|
20
34
|
if (network === 8453) {
|
|
35
|
+
const addressReverseNode = convertReverseNodeToBytes(address, 8453);
|
|
21
36
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
const baseName = yield rpcProvider.readContract({
|
|
38
|
+
abi: L2ResolverAbi,
|
|
39
|
+
address: '0xC6d566A56A1aFf6508b41f6c90ff131615583BCD',
|
|
40
|
+
args: [addressReverseNode],
|
|
41
|
+
functionName: 'name',
|
|
42
|
+
});
|
|
43
|
+
if (baseName) {
|
|
44
|
+
nsData.name = baseName;
|
|
45
|
+
return nsData;
|
|
26
46
|
}
|
|
27
47
|
}
|
|
28
|
-
catch (
|
|
29
|
-
|
|
48
|
+
catch (_error) {
|
|
49
|
+
// This is a best effort attempt, so we don't need to do anything here.
|
|
50
|
+
return nsData;
|
|
30
51
|
}
|
|
31
|
-
return nsData;
|
|
32
52
|
}
|
|
33
53
|
else {
|
|
34
54
|
nsData.name = (yield rpcProvider.getEnsName({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import {
|
|
3
|
+
import { keccak256, namehash, encodePacked } from 'viem';
|
|
4
|
+
import L2ResolverAbi from './L2ResolverAbi.js';
|
|
4
5
|
|
|
5
6
|
const getNameservice = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rpcProvider, address, }) {
|
|
6
|
-
var _b;
|
|
7
7
|
const nsData = {
|
|
8
8
|
avatar: undefined,
|
|
9
9
|
name: undefined,
|
|
@@ -12,19 +12,39 @@ const getNameservice = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rpcP
|
|
|
12
12
|
if (!network) {
|
|
13
13
|
return nsData;
|
|
14
14
|
}
|
|
15
|
-
//
|
|
15
|
+
// per CB team they recommended using the code
|
|
16
|
+
// from: https://github.com/coinbase/onchainkit/blob/main/src/identity/utils/getName.ts
|
|
17
|
+
// Once they will have proper resolver for the ens names we can remove this code
|
|
18
|
+
const convertReverseNodeToBytes = (address, chainId) => {
|
|
19
|
+
const addressFormatted = address.toLocaleLowerCase();
|
|
20
|
+
const addressNode = keccak256(addressFormatted.substring(2));
|
|
21
|
+
const chainCoinType = convertChainIdToCoinType(chainId);
|
|
22
|
+
const baseReverseNode = namehash(`${chainCoinType.toLocaleUpperCase()}.reverse`);
|
|
23
|
+
const addressReverseNode = keccak256(encodePacked(['bytes32', 'bytes32'], [baseReverseNode, addressNode]));
|
|
24
|
+
return addressReverseNode;
|
|
25
|
+
};
|
|
26
|
+
const convertChainIdToCoinType = (chainId) => {
|
|
27
|
+
const cointype = (0x80000000 | chainId) >>> 0;
|
|
28
|
+
return cointype.toString(16).toLocaleUpperCase();
|
|
29
|
+
};
|
|
16
30
|
if (network === 8453) {
|
|
31
|
+
const addressReverseNode = convertReverseNodeToBytes(address, 8453);
|
|
17
32
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
const baseName = yield rpcProvider.readContract({
|
|
34
|
+
abi: L2ResolverAbi,
|
|
35
|
+
address: '0xC6d566A56A1aFf6508b41f6c90ff131615583BCD',
|
|
36
|
+
args: [addressReverseNode],
|
|
37
|
+
functionName: 'name',
|
|
38
|
+
});
|
|
39
|
+
if (baseName) {
|
|
40
|
+
nsData.name = baseName;
|
|
41
|
+
return nsData;
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
|
-
catch (
|
|
25
|
-
|
|
44
|
+
catch (_error) {
|
|
45
|
+
// This is a best effort attempt, so we don't need to do anything here.
|
|
46
|
+
return nsData;
|
|
26
47
|
}
|
|
27
|
-
return nsData;
|
|
28
48
|
}
|
|
29
49
|
else {
|
|
30
50
|
nsData.name = (yield rpcProvider.getEnsName({
|