web3-eth-ens
Advanced tools
Comparing version
{ | ||
"name": "web3-eth-ens", | ||
"version": "1.2.7", | ||
"version": "1.2.8-rc.0", | ||
"description": "ENS support for web3.", | ||
@@ -12,20 +12,21 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-ens", | ||
"scripts": { | ||
"dtslint": "dtslint types" | ||
"dtslint": "dtslint --localTs node_modules/typescript/lib types" | ||
}, | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"content-hash": "^2.5.2", | ||
"eth-ens-namehash": "2.0.8", | ||
"underscore": "1.9.1", | ||
"web3-core": "1.2.7", | ||
"web3-core-helpers": "1.2.7", | ||
"web3-core-promievent": "1.2.7", | ||
"web3-eth-abi": "1.2.7", | ||
"web3-eth-contract": "1.2.7", | ||
"web3-utils": "1.2.7" | ||
"web3-core": "1.2.8-rc.0", | ||
"web3-core-helpers": "1.2.8-rc.0", | ||
"web3-core-promievent": "1.2.8-rc.0", | ||
"web3-eth-abi": "1.2.8-rc.0", | ||
"web3-eth-contract": "1.2.8-rc.0", | ||
"web3-utils": "1.2.8-rc.0" | ||
}, | ||
"devDependencies": { | ||
"definitelytyped-header-parser": "^3.9.0", | ||
"dtslint": "^3.4.1" | ||
"dtslint": "^3.4.1", | ||
"typescript": "latest" | ||
}, | ||
"gitHead": "65237be53b5d2ec7d12da12c35d7ddb7af57256f" | ||
"gitHead": "035d11acced0bdd43e500d4defbfdcd1b70768d7" | ||
} |
@@ -35,4 +35,16 @@ /* | ||
}, | ||
// These ids obtained at ensdomains docs: | ||
// https://docs.ens.domains/contract-developer-guide/writing-a-resolver | ||
interfaceIds: { | ||
addr: "0x3b3b57de", | ||
setAddr: "0x3b3b57de", | ||
pubkey: "0xc8690233", | ||
setPubkey: "0xc8690233", | ||
contenthash: "0xbc1c58d1", | ||
setContenthash: "0xbc1c58d1", | ||
content: "0xd8389dc5", | ||
setContent: "0xd8389dc5" | ||
} | ||
}; | ||
module.exports = config; |
@@ -29,2 +29,3 @@ /* | ||
var ResolverMethodHandler = require('./lib/ResolverMethodHandler'); | ||
var contenthash = require('./lib/contentHash'); | ||
@@ -367,3 +368,3 @@ /** | ||
ENS.prototype.getPubkey = function (name, callback) { | ||
return this.resolverMethodHandler.method(name, 'pubkey', [], callback).call(callback); | ||
return this.resolverMethodHandler.method(name, 'pubkey', [], null, callback).call(callback); | ||
}; | ||
@@ -422,2 +423,48 @@ | ||
/** | ||
* Returns the contenthash | ||
* | ||
* @method getContenthash | ||
* | ||
* @param {string} name | ||
* @param {function} callback | ||
* | ||
* @callback callback callback(error, result) | ||
* @returns {PromiEvent<ContentHash>} | ||
*/ | ||
ENS.prototype.getContenthash = function (name, callback) { | ||
return this.resolverMethodHandler.method(name, 'contenthash', [], contenthash.decode).call(callback); | ||
}; | ||
/** | ||
* Set the contenthash | ||
* | ||
* @method setContent | ||
* | ||
* @param {string} name | ||
* @param {string} hash | ||
* @param {function} callback | ||
* @param {TransactionConfig} txConfig | ||
* | ||
* @callback callback callback(error, result) | ||
* @returns {PromiEvent<TransactionReceipt | TransactionRevertInstructionError>} | ||
*/ | ||
ENS.prototype.setContenthash = function (name, hash, txConfig, callback) { | ||
var encoded; | ||
try { | ||
encoded = contenthash.encode(hash); | ||
} catch(err){ | ||
var error = new Error('Could not encode ' + hash + '. See docs for supported hash protocols.'); | ||
if (_.isFunction(callback)) { | ||
callback(error, null); | ||
return; | ||
} | ||
throw error; | ||
} | ||
return this.resolverMethodHandler.method(name, 'setContenthash', [encoded]).send(txConfig, callback); | ||
}; | ||
/** | ||
* Get the multihash | ||
@@ -424,0 +471,0 @@ * |
@@ -25,3 +25,5 @@ /* | ||
var namehash = require('eth-ens-namehash'); | ||
var errors = require('web3-core-helpers').errors; | ||
var _ = require('underscore'); | ||
var interfaceIds = require('../config').interfaceIds; | ||
@@ -45,3 +47,3 @@ /** | ||
*/ | ||
ResolverMethodHandler.prototype.method = function (ensName, methodName, methodArguments, callback) { | ||
ResolverMethodHandler.prototype.method = function (ensName, methodName, methodArguments, outputFormatter, callback) { | ||
return { | ||
@@ -53,3 +55,4 @@ call: this.call.bind({ | ||
callback: callback, | ||
parent: this | ||
parent: this, | ||
outputFormatter: outputFormatter | ||
}), | ||
@@ -75,5 +78,7 @@ send: this.send.bind({ | ||
var preparedArguments = this.parent.prepareArguments(this.ensName, this.methodArguments); | ||
var outputFormatter = this.outputFormatter || null; | ||
this.parent.registry.getResolver(this.ensName).then(function (resolver) { | ||
self.parent.handleCall(promiEvent, resolver.methods[self.methodName], preparedArguments, callback); | ||
this.parent.registry.getResolver(this.ensName).then(async function (resolver) { | ||
await self.parent.checkInterfaceSupport(resolver, self.methodName); | ||
self.parent.handleCall(promiEvent, resolver.methods[self.methodName], preparedArguments, outputFormatter, callback); | ||
}).catch(function(error) { | ||
@@ -105,3 +110,4 @@ if (_.isFunction(callback)) { | ||
this.parent.registry.getResolver(this.ensName).then(function (resolver) { | ||
this.parent.registry.getResolver(this.ensName).then(async function (resolver) { | ||
await self.parent.checkInterfaceSupport(resolver, self.methodName); | ||
self.parent.handleSend(promiEvent, resolver.methods[self.methodName], preparedArguments, sendOptions, callback); | ||
@@ -130,5 +136,9 @@ }).catch(function(error) { | ||
*/ | ||
ResolverMethodHandler.prototype.handleCall = function (promiEvent, method, preparedArguments, callback) { | ||
ResolverMethodHandler.prototype.handleCall = function (promiEvent, method, preparedArguments, outputFormatter, callback) { | ||
method.apply(this, preparedArguments).call() | ||
.then(function (result) { | ||
if (outputFormatter){ | ||
result = outputFormatter(result); | ||
} | ||
if (_.isFunction(callback)) { | ||
@@ -217,2 +227,29 @@ // It's required to pass the receipt to the second argument to be backwards compatible and to have the required consistency | ||
/** | ||
* | ||
* | ||
* @param {Contract} resolver | ||
* @param {string} methodName | ||
* | ||
* @returns {Promise} | ||
*/ | ||
ResolverMethodHandler.prototype.checkInterfaceSupport = async function (resolver, methodName) { | ||
// Skip validation for undocumented interface ids (ex: multihash) | ||
if (!interfaceIds[methodName]) return; | ||
var supported = false; | ||
try { | ||
supported = await resolver | ||
.methods | ||
.supportsInterface(interfaceIds[methodName]) | ||
.call(); | ||
} catch(err) { | ||
console.warn('Could not verify interface of resolver contract at "' + resolver.options.address + '". '); | ||
} | ||
if (!supported){ | ||
throw errors.ResolverMethodMissingError(resolver.options.address, methodName); | ||
} | ||
}; | ||
module.exports = ResolverMethodHandler; |
@@ -353,5 +353,59 @@ "use strict"; | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "node", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "hash", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "ContenthashChanged", | ||
"type": "event" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "node", | ||
"type": "bytes32" | ||
} | ||
], | ||
"name": "contenthash", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bytes" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "node", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"name": "hash", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "setContenthash", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
]; | ||
module.exports = RESOLVER; | ||
module.exports = RESOLVER; |
@@ -20,4 +20,2 @@ /* | ||
// Minimum TypeScript Version: 3.0 | ||
import { PromiEvent, TransactionConfig, TransactionReceipt } from 'web3-core'; | ||
@@ -28,2 +26,8 @@ import { TransactionRevertInstructionError } from 'web3-core-helpers'; | ||
export interface ContentHash { | ||
protocolType: 'ipfs' | 'bzz' | 'onion' | 'onion3' | null, | ||
decoded: string | null, | ||
error?: Error | null | ||
} | ||
// TODO: Define as soon as implemented the generic contract | ||
@@ -286,8 +290,8 @@ export class Ens { | ||
name: string, | ||
callback?: (value: any) => void | ||
): Promise<string>; | ||
callback?: (value: ContentHash) => void | ||
): Promise<ContentHash>; | ||
getContenthash( | ||
name: string, | ||
callback?: (error: Error, contenthash: string) => void | ||
): Promise<string>; | ||
callback?: (error: Error, contenthash: ContentHash) => void | ||
): Promise<ContentHash>; | ||
@@ -294,0 +298,0 @@ setContenthash( |
@@ -23,3 +23,3 @@ /* | ||
import { Contract } from 'web3-eth-contract'; | ||
import { Ens } from 'web3-eth-ens'; | ||
import { Ens, ContentHash } from 'web3-eth-ens'; | ||
import { Eth } from 'web3-eth'; | ||
@@ -214,8 +214,8 @@ | ||
// $ExpectType Promise<string> | ||
// $ExpectType Promise<ContentHash> | ||
ens.getContenthash('name'); | ||
// $ExpectType Promise<string> | ||
ens.getContenthash('name', (error: Error, contenthash: string) => {}); | ||
// $ExpectType Promise<string> | ||
ens.getContenthash('name', (value: any) => {}); | ||
// $ExpectType Promise<ContentHash> | ||
ens.getContenthash('name', (error: Error, contenthash: ContentHash) => {}); | ||
// $ExpectType Promise<ContentHash> | ||
ens.getContenthash('name', (value: ContentHash) => {}); | ||
@@ -222,0 +222,0 @@ // $ExpectType PromiEvent<TransactionReceipt | TransactionRevertInstructionError> |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
88015
9.73%15
7.14%2719
9.81%9
12.5%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated