Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-ens

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-ens - npm Package Compare versions

Comparing version 0.1.6 to 0.2.1

9

dist/index.d.ts

@@ -5,4 +5,13 @@ export declare type ENSRecords = Record<string, string | {}> & {

export interface ResolvedENS {
/**
* Owner address
*/
owner: string | null;
/**
* Resolved address
*/
address: string | null;
/**
* ENS text records
*/
records?: ENSRecords;

@@ -9,0 +18,0 @@ }

2

dist/index.js

@@ -1,1 +0,1 @@

import createHash from"keccak";import{Contract}from"@ethersproject/contracts";import{getDefaultProvider}from"@ethersproject/providers";const sha3=x=>createHash("keccak256").update(x).digest().toString("hex");const ABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"node",type:"bytes32"},{indexed:!0,internalType:"string",name:"indexedKey",type:"string"},{indexed:!1,internalType:"string",name:"key",type:"string"}],name:"TextChanged",type:"event"},{inputs:[{internalType:"bytes32",name:"node",type:"bytes32"},{internalType:"string",name:"key",type:"string"},{internalType:"string",name:"value",type:"string"}],name:"setText",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceID",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"bytes32",name:"node",type:"bytes32"},{internalType:"string",name:"key",type:"string"}],name:"text",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],getENS=(provider=getDefaultProvider(),contractAddress="0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41")=>{const contract=new Contract(contractAddress,ABI,provider),getRecord=async(node,record)=>await contract.text(node,record);return async function(domain){const node=function(name){let node="";for(let i=0;i<32;i++)node+="00";const labels=name.split(".");for(var i=labels.length-1;i>=0;i--){const labelSha=sha3(labels[i]);node=sha3(Buffer.from(node+labelSha,"hex"))}return"0x"+node}(domain),res=await fetch("https://api.thegraph.com/subgraphs/name/ensdomains/ens",{body:`{"query":"{domains(where:{name:\\"${domain}\\"}) { resolvedAddress{ id } resolver{ texts } owner{ id } }}"}`,method:"POST"}),{data:{domains:domains}}=await res.json(),records={web:{}},{resolvedAddress:address,resolver:resolver,owner:owner}=domains[0];let data={owner:null,address:null};if(owner&&(data.owner=owner.id),address&&(data.address=address.id),null==resolver?void 0:resolver.texts){for(const record of resolver.texts)record.startsWith("com.")||record.startsWith("vnd.")?records.web[record.slice(record.indexOf(".")+1)]=await getRecord(node,record):records[record]=await getRecord(node,record);return data.records=records,data}return data}};export{getENS};
import createHash from"keccak";import{Contract}from"@ethersproject/contracts";import{request}from"graphql-request";import{getDefaultProvider}from"@ethersproject/providers";const sha3=x=>createHash("keccak256").update(x).digest().toString("hex");const ABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"node",type:"bytes32"},{indexed:!0,internalType:"string",name:"indexedKey",type:"string"},{indexed:!1,internalType:"string",name:"key",type:"string"}],name:"TextChanged",type:"event"},{inputs:[{internalType:"bytes32",name:"node",type:"bytes32"},{internalType:"string",name:"key",type:"string"},{internalType:"string",name:"value",type:"string"}],name:"setText",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceID",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"bytes32",name:"node",type:"bytes32"},{internalType:"string",name:"key",type:"string"}],name:"text",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],getENS=(provider=getDefaultProvider(),contractAddress="0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41")=>{const contract=new Contract(contractAddress,ABI,provider),getRecord=async(node,record)=>await contract.text(node,record);return async function(domain){const node=function(name){let node="";for(let i=0;i<32;i++)node+="00";const labels=name.split(".");for(var i=labels.length-1;i>=0;i--){const labelSha=sha3(labels[i]);node=sha3(Buffer.from(node+labelSha,"hex"))}return"0x"+node}(domain),{domains:domains}=await request("https://api.thegraph.com/subgraphs/name/ensdomains/ens","\nquery($domain: String!) {\n domains(where:{name: $domain}) { \n resolvedAddress {\n id\n }\n resolver {\n texts\n }\n owner {\n id\n }\n }\n}\n",{domain:domain}),records={web:{}},{resolvedAddress:address,resolver:resolver,owner:owner}=domains[0];let data={owner:null,address:null};if(owner&&(data.owner=owner.id),address&&(data.address=address.id),null==resolver?void 0:resolver.texts){for(const record of resolver.texts)record.startsWith("com.")||record.startsWith("vnd.")?records.web[record.slice(record.indexOf(".")+1)]=await getRecord(node,record):records[record]=await getRecord(node,record);return data.records=records,data}return data}};export{getENS};
{
"name": "get-ens",
"version": "0.1.6",
"version": "0.2.1",
"description": "Get text records of an ENS address with ease.",

@@ -30,2 +30,4 @@ "exports": "./dist/index.js",

"@ethersproject/providers": "^5.4.3",
"graphql": "^15.5.1",
"graphql-request": "^3.5.0",
"keccak": "^3.0.1"

@@ -32,0 +34,0 @@ },

<div align="center">
<img src="https://www.pngkit.com/png/full/152-1526200_ens-logo-ethereum-name-service.png" height="150px" /><br />
# get-ens
[![Version][v-badge-url]][npm-url] [![Downloads][dl-badge-url]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Codecov][cov-badge-url]][cov-url]
[![Version][v-badge-url]][npm-url] [![Downloads][dl-badge-url]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Codecov][cov-badge-url]][cov-url] [![][docs-badge]][docs]
<sub>Get text records of an ENS address with ease.</sub>
<sub>Get text records of an [ENS](app.ens.domains) address with ease.</sub>
</div>
This library simplifies the process of retreiving ENS data with the help of [TheGraph ENS explorer](https://thegraph.com/explorer/subgraph/ensdomains/ens) and ENS [TextResolver](https://github.com/ensdomains/ens-contracts/blob/master/contracts/resolvers/profiles/TextResolver.sol) contract.
## Install

@@ -71,1 +75,3 @@

[gh-actions-img]: https://img.shields.io/github/workflow/status/talentlessguy/get-ens/CI?style=for-the-badge&color=4D48F7&label=&logo=github
[docs-badge]: https://img.shields.io/badge/Docs-4D48F7?style=for-the-badge&logo=deno
[docs]: https://doc.deno.land/https/esm.sh/get-ens
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc