npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

provable-domain

v1.0.1

Published

Domain ownership verification using Provable API

Downloads

18

Readme

Provable Domain

Build Status Coverage Status

This repository store contract that aims at verifying one's ownership to a domain using Provable Ethereum API.

The idea is similar to Let's Encrypt where one has to show that he/she has control over the domain by returning a specific content in a specific URL under the domain. In its current implementation (HTTPChallenge.sol), one must be able to return the address in the body section of an HTML file under http(s)://declared_domain/_address to prove their control and ownership over the domain.

This contract is designed to be used in Certicol but is open for anyone who is interested in this idea.

Running Automated Test

npm install
npm test

Generating Coverage Report

npm run coverage

License

Provable Domain is released under the Apache License 2.0.

Usage

Installation

npm i provable-domain

Contract Construction

Firstly, you should import HTTPChallenge.sol and extends from it.

In the constructor of HTTPChallenge, you are required to pass a uint256 as the parameter. This defines the gas limit used by the __callback function and must be set in accordance with the total cumulative gas cost of the __callback function. Since any implementer contract can implement their own callback function (see below), this value must be defined by the child contract.

import 'provable-domain/contracts/HTTPChallenge.sol';

contract Implementer is HTTPChallenge {

    constructor() HTTPChallenge(x) public {
    }

}

This will expose the core methods of HTTPChallenge.sol to your implementer contract described below.

Initialize an HTTP Challenge

To initialize an HTTP challenge, begins by calling initChallenge() where the owner is the claimed owner of the domain, and the domain is the domain concerned.

This would return a uint256 challengeId that is associated with the initialized challenge.

Since this function is marked as internal, any child contract should include a public/external function that indirectly exposes this function. This also provides the child contract a greater control over the process.

function initChallenge(address owner, string memory domain) internal returns (uint256);

Query the Challenge URL and HTML String

As mentioned above, the claimed owner would be required to show a specific string at a specific URL under the concerned domain. The detail of the string and URL can be queried by using the getChallenge().

This function would return an array where the first element is the URL and the second element is the HTML string that must be returned when the URL is accessed.

function getChallenge(uint256 challengeId) public view returns (string memory, string memory);

Resolving the HTTP Challenge

Once the URL is prepared as required, the HTTP challenge can be resolved by calling solveChallenge() with the challengeId associated with the challenge to be resolved.

Since this function is marked as internal, any child contract should include a public/external function that indirectly exposes this function. This also provides the child contract a greater control over the process.

function solveChallenge(uint256 challengeId) internal;

It should be noted since Provable API required payment in Ethereum as a fee. An Ethereum payment identical to the cost returned by getProvableCost() must be included when calling solveChallenge() or else it would reverts.

The fee is dependent upon BOTH the gas limit set in the constructor and the gas price used in the transaction that called solveChallenge() which has to be passed as a parameter in the function.

It is acceptable to call this function as .call() in web3 and it would return the correct value.

function getProvableCost(uint256 gasPrice) public returns (uint256)

Default Provable Callback Function

Since Provable can't immediately callback with the query result, the status of the challenge remains as unresolved after the solveChallenge() function is executed.

Once the Provable callback is executed, the contract's __callback function would execute and emits the updated status of the challenge as either an HTTPChallengeFailed or HTTPChallengeSucceed event.

/// Event that will be emitted upon each failure to solve a HTTP challenge
event HTTPChallengeFailed(uint256 indexed challengeId, bytes proof);
/// Event that will be emitted upon solving a HTTP challenge
event HTTPChallengeSucceed(uint256 indexed challengeId, bytes proof);

Custom Callback Function

Implementer contract can also implement their own follow-up action by implementing the _callbackChild function.

This function will be called after the default __callback has finished its execution. Two parameters will be passed which includes the challengeId and the updated status (true if successful or false if failed).

Thus, the gas limit of the __callback function is dependent upon the implementation of the child contract, and the developer must set it in accordance with their own implementation.

function _callbackChild(uint256 challengeId, bool validated) internal;