Comparing version 0.0.3 to 0.1.0
@@ -1,5 +0,3 @@ | ||
export declare const ABI: ({ | ||
anonymous: boolean; | ||
export declare const ABI: { | ||
inputs: { | ||
indexed: boolean; | ||
internalType: string; | ||
@@ -10,12 +8,2 @@ name: string; | ||
name: string; | ||
type: string; | ||
outputs?: undefined; | ||
stateMutability?: undefined; | ||
} | { | ||
inputs: { | ||
internalType: string; | ||
name: string; | ||
type: string; | ||
}[]; | ||
name: string; | ||
outputs: { | ||
@@ -28,3 +16,2 @@ internalType: string; | ||
type: string; | ||
anonymous?: undefined; | ||
})[]; | ||
}[]; |
@@ -1,2 +0,1 @@ | ||
export declare function namehash(inputName: string): string; | ||
export declare function normalize(name: string): string; | ||
export declare function namehash(name: string): string; |
@@ -1,1 +0,1 @@ | ||
import createHash from"keccak";import uts46 from"idna-uts46-hx";import{Contract}from"@ethersproject/contracts";import{getDefaultProvider}from"@ethersproject/providers";const sha3=x=>createHash("keccak256").update(x).digest().toString("hex");function namehash(inputName){let node="";for(var i=0;i<32;i++)node+="00";const name=function(name){return name?uts46.toAscii(name,{useStd3ASCII:!0,transitional:!1,verifyDnsLength:!0}):name}(inputName);if(name){const labels=name.split(".");for(let i=labels.length-1;i>=0;i--){const labelSha=sha3(labels[i]);node=sha3(Buffer.from(node+labelSha,"hex"))}}return"0x"+node}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=namehash(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),resolver){for(const record of resolver.texts)record.startsWith("com.")?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{getDefaultProvider}from"@ethersproject/providers";const sha3=x=>createHash("keccak256").update(x).digest().toString("hex");const ABI=[{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(var i=0;i<32;i++)node+="00";if(name){const labels=name.split(".");for(let 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),resolver){for(const record of resolver.texts)record.startsWith("com.")?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.0.3", | ||
"version": "0.1.0", | ||
"description": "Get text records of an ENS address with ease.", | ||
@@ -30,6 +30,7 @@ "exports": "./dist/index.js", | ||
"@ethersproject/providers": "^5.4.3", | ||
"idna-uts46-hx": "^3.4.0", | ||
"keccak": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^13.1.0", | ||
"@commitlint/config-conventional": "^13.1.0", | ||
"@rollup/plugin-typescript": "^8.2.5", | ||
@@ -40,2 +41,3 @@ "@types/keccak": "^3.0.1", | ||
"esbuild-node-loader": "^0.1.1", | ||
"husky": "^7.0.1", | ||
"node-fetch": "^2.6.1", | ||
@@ -42,0 +44,0 @@ "rollup": "^2.56.2", |
3
6580
14
38
- Removedidna-uts46-hx@^3.4.0
- Removedidna-uts46-hx@3.5.0(transitive)
- Removedpunycode@2.3.1(transitive)