Comparing version 2.0.1 to 2.0.2
@@ -30,3 +30,3 @@ import { BaseProvider } from '@ethersproject/providers'; | ||
*/ | ||
domain: string; | ||
domain: string | null; | ||
} | ||
@@ -33,0 +33,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
import jsSha3 from"js-sha3";import{Contract}from"@ethersproject/contracts";import{getDefaultProvider}from"@ethersproject/providers";import assert from"assert";const sha3=x=>jsSha3.keccak256(x);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,fetchOptions){const domain=/^0x[a-fA-F0-9]{40}$/.test(_domain)?await provider.lookupAddress(_domain):_domain,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(async(endpoint,query,variables,fetchOptions={})=>{const res=await fetch(endpoint,{...fetchOptions,body:JSON.stringify({query:query,variables:variables}),method:"POST"});return assert.strictEqual(200,res.status),(await res.json()).data})("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},fetchOptions),records={};if(null==domains?void 0:domains[0]){const{resolvedAddress:address,resolver:resolver,owner:owner}=null==domains?void 0:domains[0];let data={owner:null,address:null,domain:domain,records:{}};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[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 jsSha3 from"js-sha3";import{Contract}from"@ethersproject/contracts";import{getDefaultProvider}from"@ethersproject/providers";import assert from"assert";const sha3=x=>jsSha3.keccak256(x);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"}],ADDRESS_REGEX=/^0x[a-fA-F0-9]{40}$/,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,fetchOptions){const domain=ADDRESS_REGEX.test(_domain)?await provider.lookupAddress(_domain):_domain;if(null==domain&&ADDRESS_REGEX.test(_domain))return{owner:_domain,address:_domain,domain:null,records:{}};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(async(endpoint,query,variables,fetchOptions={})=>{const res=await fetch(endpoint,{...fetchOptions,body:JSON.stringify({query:query,variables:variables}),method:"POST"});return assert.strictEqual(200,res.status),(await res.json()).data})("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},fetchOptions),records={};if(null==domains?void 0:domains[0]){const{resolvedAddress:address,resolver:resolver,owner:owner}=null==domains?void 0:domains[0];let data={owner:null,address:null,domain:domain,records:{}};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[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": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Get text records of an ENS address with ease.", | ||
@@ -28,20 +28,20 @@ "exports": "./dist/index.js", | ||
"dependencies": { | ||
"@ethersproject/contracts": "^5.4.1", | ||
"@ethersproject/providers": "^5.4.5", | ||
"@ethersproject/contracts": "^5.5.0", | ||
"@ethersproject/providers": "^5.5.0", | ||
"js-sha3": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^13.1.0", | ||
"@commitlint/config-conventional": "^13.1.0", | ||
"@rollup/plugin-typescript": "^8.2.5", | ||
"@types/node": "^16.9.4", | ||
"c8": "^7.9.0", | ||
"esbuild-node-loader": "^0.3.1", | ||
"husky": "^7.0.2", | ||
"node-fetch": "^3.0.0", | ||
"rollup": "^2.56.3", | ||
"@commitlint/cli": "^15.0.0", | ||
"@commitlint/config-conventional": "^15.0.0", | ||
"@rollup/plugin-typescript": "^8.3.0", | ||
"@types/node": "^16.11.9", | ||
"c8": "^7.10.0", | ||
"husky": "^7.0.4", | ||
"node-fetch": "^3.1.0", | ||
"rollup": "^2.60.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.3", | ||
"uvu": "^0.5.1" | ||
"tsm": "^2.1.4", | ||
"typescript": "^4.5.2", | ||
"uvu": "^0.5.2" | ||
}, | ||
@@ -52,3 +52,3 @@ "engines": { | ||
"scripts": { | ||
"test": "node --loader=esbuild-node-loader node_modules/uvu/bin.js tests", | ||
"test": "tsm node_modules/uvu/bin.js tests", | ||
"build": "rollup -c", | ||
@@ -55,0 +55,0 @@ "test:coverage": "c8 --include=src pnpm test", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9552
79