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

verify-hcaptcha

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

verify-hcaptcha - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

53

dist/index.d.ts
/**
*
* A no dependencies, fully typed library to verify hCaptcha tokens submitted by users through CAPTCHA challenges.
* A no dependencies, fully typed library to verify hCaptcha tokens
* submitted by users when solving CAPTCHA challenges.
*
* @remarks
*
* Note: this is an unofficial library; we are not affiliated with hCaptcha.com
*
* @example

@@ -28,2 +31,3 @@ *

* ```
*
* @example

@@ -91,26 +95,25 @@ *

*/
export declare enum HcaptchaError {
/** Secret key is missing */
MissingInputSecret = "missing-input-secret",
/** Secret key is invalid */
InvalidInputSecret = "invalid-input-secret",
/** User response token is missing */
MissingInputResponse = "missing-input-response",
/** User response token is invalid */
InvalidInputResponse = "invalid-input-response",
/** Site key is invalid */
InvalidSiteKey = "invalid-sitekey",
/** Remote user IP is invalid */
InvalidRemoteIp = "invalid-remoteip",
/** Request is invalid */
BadRequest = "bad-request",
/** User response token is invalid or has already been checked */
InvalidOrAlreadySeenResponse = "invalid-or-already-seen-response",
/** Must use the test site key when using a test verification token */
NotUsingDummyPassCode = "not-using-dummy-passcode",
/** Must use the test secret key when using a test verification token */
NotUsingDummySecret = "not-using-dummy-secret",
/** The site key is not associated to the secret key */
SiteKeySecretMismatch = "sitekey-secret-mismatch"
}
export declare type HcaptchaError =
/** Secret key is missing */
"missing-input-secret"
/** Secret key is invalid */
| "invalid-input-secret"
/** User response token is missing */
| "missing-input-response"
/** User response token is invalid */
| "invalid-input-response"
/** Site key is invalid */
| "invalid-sitekey"
/** Remote user IP is invalid */
| "invalid-remoteip"
/** Request is invalid */
| "bad-request"
/** User response token is invalid or has already been checked */
| "invalid-or-already-seen-response"
/** Must use the test site key when using a test verification token */
| "not-using-dummy-passcode"
/** Must use the test secret key when using a test verification token */
| "not-using-dummy-secret"
/** The site key is not associated to the secret key */
| "sitekey-secret-mismatch";
/**

@@ -117,0 +120,0 @@ * `RawHcaptchaResponse` represents the raw response to the verification challenge

@@ -63,17 +63,4 @@ 'use strict';

function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire();
}
}, fn(module, module.exports), module.exports;
}
var runtime = {exports: {}};
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var runtime_1 = createCommonjsModule(function (module) {
/**

@@ -86,2 +73,3 @@ * Copyright (c) 2014-present, Facebook, Inc.

(function (module) {
var runtime = (function (exports) {

@@ -833,47 +821,6 @@

}
});
}(runtime));
/**
* `HcaptchaError` collects the errors explaining why a verification challenge failed.
*
* @see {@link HcaptchaResponse}
* @see {@link https://docs.hcaptcha.com/#siteverify-error-codes-table}
*/
var _regeneratorRuntime = runtime.exports;
exports.HcaptchaError = void 0;
(function (HcaptchaError) {
/** Secret key is missing */
HcaptchaError["MissingInputSecret"] = "missing-input-secret";
/** Secret key is invalid */
HcaptchaError["InvalidInputSecret"] = "invalid-input-secret";
/** User response token is missing */
HcaptchaError["MissingInputResponse"] = "missing-input-response";
/** User response token is invalid */
HcaptchaError["InvalidInputResponse"] = "invalid-input-response";
/** Site key is invalid */
HcaptchaError["InvalidSiteKey"] = "invalid-sitekey";
/** Remote user IP is invalid */
HcaptchaError["InvalidRemoteIp"] = "invalid-remoteip";
/** Request is invalid */
HcaptchaError["BadRequest"] = "bad-request";
/** User response token is invalid or has already been checked */
HcaptchaError["InvalidOrAlreadySeenResponse"] = "invalid-or-already-seen-response";
/** Must use the test site key when using a test verification token */
HcaptchaError["NotUsingDummyPassCode"] = "not-using-dummy-passcode";
/** Must use the test secret key when using a test verification token */
HcaptchaError["NotUsingDummySecret"] = "not-using-dummy-secret";
/** The site key is not associated to the secret key */
HcaptchaError["SiteKeySecretMismatch"] = "sitekey-secret-mismatch";
})(exports.HcaptchaError || (exports.HcaptchaError = {}));
/**

@@ -891,3 +838,2 @@ * `verifyHcaptchaToken` verifies with the hCaptcha API that the response token

function verifyHcaptchaToken(_x) {

@@ -909,6 +855,6 @@ return _verifyHcaptchaToken.apply(this, arguments);

function _verifyHcaptchaToken() {
_verifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
_verifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
var token, secretKey, siteKey, remoteIp, _yield$rawVerifyHcapt, success, challengeTimestamp, hostname, credit, rawErrorCodes, score, scoreReasons;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {

@@ -960,5 +906,5 @@ switch (_context.prev = _context.next) {

function _rawVerifyHcaptchaToken() {
_rawVerifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
_rawVerifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
var token, secretKey, siteKey, remoteIp, form, data;
return runtime_1.wrap(function _callee2$(_context2) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {

@@ -965,0 +911,0 @@ switch (_context2.prev = _context2.next) {

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

"use strict";function t(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,e}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("https"));function r(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function c(t){r(a,o,i,c,u,"next",t)}function u(t){r(a,o,i,c,u,"throw",t)}c(void 0)}))}}var o,i,a,c=(o=function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof v?e:v).prototype),i=new I(n||[]);return o._invoke=function(t,e,r){var n=h;return function(o,i){if(n===l)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=O(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===h)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=l;var u=f(t,e,r);if("normal"===u.type){if(n=r.done?y:p,u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=y,r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h="suspendedStart",p="suspendedYield",l="executing",y="completed",d={};function v(){}function m(){}function g(){}var w={};u(w,i,(function(){return this}));var x=Object.getPrototypeOf,b=x&&x(x(S([])));b&&b!==r&&n.call(b,i)&&(w=b);var L=g.prototype=v.prototype=Object.create(w);function E(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,h=s.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function S(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:e,done:!0}}return m.prototype=g,u(L,"constructor",g),u(g,"constructor",m),m.displayName=u(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,u(t,c,"GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},E(k.prototype),u(k.prototype,a,(function(){return this})),t.AsyncIterator=k,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new k(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),u(L,c,"Generator"),u(L,i,(function(){return this})),u(L,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=S,I.prototype={constructor:I,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(j),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}},o(i={path:void 0,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),i.exports);function u(){return(u=n(c.mark((function t(e){var r,n,o,i,a;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.token,n=e.secretKey,o=e.siteKey,i=e.remoteIp,t.next=3,s({token:r,secretKey:n,siteKey:o,remoteIp:i});case 3:return t.abrupt("return",{success:(a=t.sent).success,challengeTimestamp:a.challenge_ts,hostname:a.hostname,credit:a.credit,errorCodes:a["error-codes"],score:a.score,scoreReasons:a.score_reason});case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function s(t){return f.apply(this,arguments)}function f(){return(f=n(c.mark((function t(e){var r;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=h({token:e.token,secretKey:e.secretKey,siteKey:e.siteKey,remoteIp:e.remoteIp}),t.next=4,p({form:r});case 4:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function h(t){var e=t.token,r=t.secretKey,n=t.siteKey,o=t.remoteIp,i=new URLSearchParams;return e&&i.append("response",e),r&&i.append("secret",r),n&&i.append("sitekey",n),o&&i.append("remoteip",o),i.toString()}function p(t){var r=t.form,n={host:"hcaptcha.com",path:"/siteverify",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","Content-Length":Buffer.byteLength(r)}};return new Promise((function(t,o){var i=e.request(n,(function(e){var r=[];e.setEncoding("utf-8"),e.on("data",(function(t){r.push(t)})).on("end",(function(){var e=JSON.parse(r.join(""));t(e)}))}));i.on("error",(function(t){o(t)})),i.write(r),i.end()}))}exports.HcaptchaError=void 0,(a=exports.HcaptchaError||(exports.HcaptchaError={})).MissingInputSecret="missing-input-secret",a.InvalidInputSecret="invalid-input-secret",a.MissingInputResponse="missing-input-response",a.InvalidInputResponse="invalid-input-response",a.InvalidSiteKey="invalid-sitekey",a.InvalidRemoteIp="invalid-remoteip",a.BadRequest="bad-request",a.InvalidOrAlreadySeenResponse="invalid-or-already-seen-response",a.NotUsingDummyPassCode="not-using-dummy-passcode",a.NotUsingDummySecret="not-using-dummy-secret",a.SiteKeySecretMismatch="sitekey-secret-mismatch",exports.rawVerifyHcaptchaToken=s,exports.verifyHcaptchaToken=function(t){return u.apply(this,arguments)};
"use strict";function t(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,e}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("https"));function r(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function c(t){r(a,o,i,c,u,"next",t)}function u(t){r(a,o,i,c,u,"throw",t)}c(void 0)}))}}var o={exports:{}};!function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof d?e:d).prototype),i=new P(n||[]);return o._invoke=function(t,e,r){var n=h;return function(o,i){if(n===p)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return K()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=O(a,r);if(c){if(c===v)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===h)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var u=f(t,e,r);if("normal"===u.type){if(n=r.done?y:l,u.arg===v)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=y,r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h="suspendedStart",l="suspendedYield",p="executing",y="completed",v={};function d(){}function g(){}function m(){}var w={};u(w,i,(function(){return this}));var x=Object.getPrototypeOf,b=x&&x(x(T([])));b&&b!==r&&n.call(b,i)&&(w=b);var L=m.prototype=d.prototype=Object.create(w);function E(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,e){function r(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,h=s.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:K}}function K(){return{value:e,done:!0}}return g.prototype=m,u(L,"constructor",m),u(m,"constructor",g),g.displayName=u(m,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,u(t,c,"GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},E(_.prototype),u(_.prototype,a,(function(){return this})),t.AsyncIterator=_,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new _(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),u(L,c,"Generator"),u(L,i,(function(){return this})),u(L,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=T,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(j),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:T(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(o);var i=o.exports;function a(){return(a=n(i.mark((function t(e){var r,n,o,a,u;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.token,n=e.secretKey,o=e.siteKey,a=e.remoteIp,t.next=3,c({token:r,secretKey:n,siteKey:o,remoteIp:a});case 3:return t.abrupt("return",{success:(u=t.sent).success,challengeTimestamp:u.challenge_ts,hostname:u.hostname,credit:u.credit,errorCodes:u["error-codes"],score:u.score,scoreReasons:u.score_reason});case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function c(t){return u.apply(this,arguments)}function u(){return(u=n(i.mark((function t(e){var r;return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=s({token:e.token,secretKey:e.secretKey,siteKey:e.siteKey,remoteIp:e.remoteIp}),t.next=4,f({form:r});case 4:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function s(t){var e=t.token,r=t.secretKey,n=t.siteKey,o=t.remoteIp,i=new URLSearchParams;return e&&i.append("response",e),r&&i.append("secret",r),n&&i.append("sitekey",n),o&&i.append("remoteip",o),i.toString()}function f(t){var r=t.form,n={host:"hcaptcha.com",path:"/siteverify",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","Content-Length":Buffer.byteLength(r)}};return new Promise((function(t,o){var i=e.request(n,(function(e){var r=[];e.setEncoding("utf-8"),e.on("data",(function(t){r.push(t)})).on("end",(function(){var e=JSON.parse(r.join(""));t(e)}))}));i.on("error",(function(t){o(t)})),i.write(r),i.end()}))}exports.rawVerifyHcaptchaToken=c,exports.verifyHcaptchaToken=function(t){return a.apply(this,arguments)};
//# sourceMappingURL=verify-hcaptcha.cjs.production.min.js.map

@@ -39,17 +39,4 @@ import * as https from 'https';

function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire();
}
}, fn(module, module.exports), module.exports;
}
var runtime = {exports: {}};
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var runtime_1 = createCommonjsModule(function (module) {
/**

@@ -62,2 +49,3 @@ * Copyright (c) 2014-present, Facebook, Inc.

(function (module) {
var runtime = (function (exports) {

@@ -809,47 +797,6 @@

}
});
}(runtime));
/**
* `HcaptchaError` collects the errors explaining why a verification challenge failed.
*
* @see {@link HcaptchaResponse}
* @see {@link https://docs.hcaptcha.com/#siteverify-error-codes-table}
*/
var _regeneratorRuntime = runtime.exports;
var HcaptchaError;
(function (HcaptchaError) {
/** Secret key is missing */
HcaptchaError["MissingInputSecret"] = "missing-input-secret";
/** Secret key is invalid */
HcaptchaError["InvalidInputSecret"] = "invalid-input-secret";
/** User response token is missing */
HcaptchaError["MissingInputResponse"] = "missing-input-response";
/** User response token is invalid */
HcaptchaError["InvalidInputResponse"] = "invalid-input-response";
/** Site key is invalid */
HcaptchaError["InvalidSiteKey"] = "invalid-sitekey";
/** Remote user IP is invalid */
HcaptchaError["InvalidRemoteIp"] = "invalid-remoteip";
/** Request is invalid */
HcaptchaError["BadRequest"] = "bad-request";
/** User response token is invalid or has already been checked */
HcaptchaError["InvalidOrAlreadySeenResponse"] = "invalid-or-already-seen-response";
/** Must use the test site key when using a test verification token */
HcaptchaError["NotUsingDummyPassCode"] = "not-using-dummy-passcode";
/** Must use the test secret key when using a test verification token */
HcaptchaError["NotUsingDummySecret"] = "not-using-dummy-secret";
/** The site key is not associated to the secret key */
HcaptchaError["SiteKeySecretMismatch"] = "sitekey-secret-mismatch";
})(HcaptchaError || (HcaptchaError = {}));
/**

@@ -867,3 +814,2 @@ * `verifyHcaptchaToken` verifies with the hCaptcha API that the response token

function verifyHcaptchaToken(_x) {

@@ -885,6 +831,6 @@ return _verifyHcaptchaToken.apply(this, arguments);

function _verifyHcaptchaToken() {
_verifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
_verifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
var token, secretKey, siteKey, remoteIp, _yield$rawVerifyHcapt, success, challengeTimestamp, hostname, credit, rawErrorCodes, score, scoreReasons;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {

@@ -936,5 +882,5 @@ switch (_context.prev = _context.next) {

function _rawVerifyHcaptchaToken() {
_rawVerifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
_rawVerifyHcaptchaToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
var token, secretKey, siteKey, remoteIp, form, data;
return runtime_1.wrap(function _callee2$(_context2) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {

@@ -1026,3 +972,3 @@ switch (_context2.prev = _context2.next) {

export { HcaptchaError, rawVerifyHcaptchaToken, verifyHcaptchaToken };
export { rawVerifyHcaptchaToken, verifyHcaptchaToken };
//# sourceMappingURL=verify-hcaptcha.esm.js.map
{
"name": "verify-hcaptcha",
"version": "0.1.0",
"version": "1.0.0",
"description": "A no dependencies, fully typed library to verify hCaptcha tokens submitted by users",

@@ -86,17 +86,17 @@ "author": "Edoardo Scibona",

"@pollyjs/persister-fs": "5.1.1",
"@size-limit/preset-small-lib": "5.0.5",
"@size-limit/preset-small-lib": "6.0.3",
"@types/pollyjs__adapter-node-http": "2.0.1",
"@types/pollyjs__persister-fs": "2.0.1",
"@types/setup-polly-jest": "0.5.1",
"dts-cli": "0.17.1",
"dts-cli": "0.19.4",
"eslint-plugin-prettier": "4.0.0",
"husky": "7.0.2",
"nock": "13.1.3",
"husky": "7.0.4",
"nock": "13.1.4",
"np": "7.5.0",
"prettier": "2.4.1",
"setup-polly-jest": "0.10.0",
"size-limit": "5.0.5",
"size-limit": "6.0.3",
"tslib": "2.3.1",
"typescript": "4.4.3"
"typescript": "4.4.4"
}
}

@@ -7,3 +7,2 @@ # verify-hcaptcha

![Language](https://img.shields.io/github/languages/top/velut/verify-hcaptcha)
[![Dependencies](https://img.shields.io/david/velut/verify-hcaptcha)](https://david-dm.org/velut/verify-hcaptcha)
[![npm bundle size](https://img.shields.io/bundlephobia/min/verify-hcaptcha)](https://bundlephobia.com/result?p=verify-hcaptcha)

@@ -14,5 +13,6 @@ [![npm](https://img.shields.io/npm/v/verify-hcaptcha)](https://www.npmjs.com/package/verify-hcaptcha)

A no dependencies, fully typed library to verify hCaptcha tokens submitted by users through CAPTCHA challenges.
A no dependencies, fully typed library to verify hCaptcha tokens
submitted by users when solving CAPTCHA challenges.
> Note: this is an unofficial library; we are not affiliated with hCaptcha.com
> Note: this is an **unofficial** library; we are not affiliated with hCaptcha.com

@@ -19,0 +19,0 @@ ## Features

@@ -5,6 +5,9 @@ import * as https from "https";

*
* A no dependencies, fully typed library to verify hCaptcha tokens submitted by users through CAPTCHA challenges.
* A no dependencies, fully typed library to verify hCaptcha tokens
* submitted by users when solving CAPTCHA challenges.
*
* @remarks
*
* Note: this is an unofficial library; we are not affiliated with hCaptcha.com
*
* @example

@@ -31,2 +34,3 @@ *

* ```
*
* @example

@@ -102,26 +106,25 @@ *

*/
export enum HcaptchaError {
export type HcaptchaError =
/** Secret key is missing */
MissingInputSecret = "missing-input-secret",
| "missing-input-secret"
/** Secret key is invalid */
InvalidInputSecret = "invalid-input-secret",
| "invalid-input-secret"
/** User response token is missing */
MissingInputResponse = "missing-input-response",
| "missing-input-response"
/** User response token is invalid */
InvalidInputResponse = "invalid-input-response",
| "invalid-input-response"
/** Site key is invalid */
InvalidSiteKey = "invalid-sitekey",
| "invalid-sitekey"
/** Remote user IP is invalid */
InvalidRemoteIp = "invalid-remoteip",
| "invalid-remoteip"
/** Request is invalid */
BadRequest = "bad-request",
| "bad-request"
/** User response token is invalid or has already been checked */
InvalidOrAlreadySeenResponse = "invalid-or-already-seen-response",
| "invalid-or-already-seen-response"
/** Must use the test site key when using a test verification token */
NotUsingDummyPassCode = "not-using-dummy-passcode",
| "not-using-dummy-passcode"
/** Must use the test secret key when using a test verification token */
NotUsingDummySecret = "not-using-dummy-secret",
| "not-using-dummy-secret"
/** The site key is not associated to the secret key */
SiteKeySecretMismatch = "sitekey-secret-mismatch",
}
| "sitekey-secret-mismatch";

@@ -128,0 +131,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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