Comparing version 1.1.0 to 1.1.1
@@ -279,3 +279,3 @@ 'use strict'; | ||
var witnessProgLength = witnessProgram.length; | ||
if (witnessProgLength !== 53 && witnessProgLength !== 65) throw new Error("witness version 0 needs witness program length = 53 OR = 65"); | ||
if (witnessVersion === 0 && witnessProgLength !== 53 && witnessProgLength !== 65) throw new Error("witness version 0 needs witness program length = 53 OR = 65"); | ||
if (witnessProgLength < 2 || witnessProgLength > 65) throw new Error("witness program length should be >= 2 and <= 65"); | ||
@@ -282,0 +282,0 @@ var data = [witnessVersion].concat(convertBits(Array.from(witnessProgram), 8, 5, true)); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,e=(r=require("long"))&&"object"==typeof r&&"default"in r?r.default:r;function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}function t(r,e,t,o){if(e<1||e>8||t<1||e>8)throw new Error("only bits groups between 1 and 8 are allowed");for(var i,a=[],f=0,s=0,c=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,void 0);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,void 0):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(i=c()).done;)for(var h=i.value<<8-e,l=e;l>0;){var u=t-s,d=l;u<d&&(d=u),f=f<<d|h>>8-d,h=(h<<d)%256,l-=d,(s+=d)===t&&(a.push(f),s=0,f=0)}if(o&&s>0&&(a.push(f<<=t-s),s=0,f=0),s>0&&(s>4||0!==f))throw new Error("invalid incomplete group of bits");return a}function o(r){if(r<0||r>16)throw new Error("invalid witness version")}var i="qpzry9x8gf2tvdw0s3jn54khce6mua7l";function a(r){return e.fromString(r,!0,16)}var f=["7d52fba40bd886","5e8dbf1a03950c","1c3a3c74072a18","385d72fa0e5139","7093e5a608865b"].map(a);function s(r){if(o(r),0===r)return"blech32";if(1===r)return"blech32m";throw new Error("Unsuported witness version ("+r+"), only 0 (blech32) or 1 (blech32m) are supported")}function c(r){if("blech32"===r)return e.fromNumber(1);if("blech32m"===r)return a("2bc830a3");throw new Error("Invalid encoding type")}function h(r){for(var n=e.fromNumber(1),t=0;t<r.length;++t){var o=n.shiftRight(55);n=n.and(a("7fffffffffffff")).shiftLeft(5).xor(r[t]);for(var i=0;i<5;i++)o.shiftRight(e.fromNumber(i)).and(1).equals(1)&&(n=n.xor(f[i]))}return n}function l(r){for(var e=[],n=0;n<r.length;++n)e.push(r.charCodeAt(n)>>5);e.push(0);for(var t=0;t<r.length;++t)e.push(31&r.charCodeAt(t));return Uint8Array.from(e)}var u=[0,0,0,0,0,0,0,0,0,0,0,0];function d(r,e,n){for(var t=function(r,e,n){for(var t=h(Array.from(l(r)).concat(Array.from(e)).concat(u)).xor(c(n)),o=[],i=0;i<12;++i)o.push(t.shiftRight(5*(11-i)).and(31));return o.map((function(r){return r.toInt()}))}(r,e,n),o=Array.from(e).concat(t),a=r+"1",f=0;f<o.length;++f)a+=i.charAt(o[f]);return a}function w(r,e){for(var n=!1,t=!1,o=0;o<r.length;++o){if(r.charCodeAt(o)<33||r.charCodeAt(o)>126)throw new Error("Invalid charcode in blech32 string");r.charCodeAt(o)>=97&&r.charCodeAt(o)<=122&&(n=!0),r.charCodeAt(o)>=65&&r.charCodeAt(o)<=90&&(t=!0)}if(n&&t)throw new Error("blech32 has lowercases AND uppercases");var a=(r=r.toLowerCase()).lastIndexOf("1");if(a<1||a+13>r.length)throw new Error('Invalid index of "1"');for(var f=r.substring(0,a),s=[],u=a+1;u<r.length;++u){var d=i.indexOf(r.charAt(u));if(-1===d)throw new Error('"'+r.charAt(u)+'" is not allowed in blech32 strings');s.push(d)}if(!function(r,e,n){return h(Array.from(l(r)).concat(e)).equals(c(n))}(f,s,e))throw new Error("invalid "+e+" checksum");return{hrp:f,data:Uint8Array.from(s.slice(0,s.length-12))}}var v=function(){function r(r){this.witness=r.witness,this.blindingPublicKey=r.blindingPublicKey,this.witnessVersion=r.witnessVersion,this.address=function(r){var e=r.witness,n=r.witnessVersion,i=r.blindingPublicKey,a=r.hrp;o(n);var f=Buffer.concat([Buffer.from(i,"hex"),Buffer.from(e,"hex")]),c=f.length;if(53!==c&&65!==c)throw new Error("witness version 0 needs witness program length = 53 OR = 65");if(c<2||c>65)throw new Error("witness program length should be >= 2 and <= 65");var h=[n].concat(t(Array.from(f),8,5,!0));return d(a,Uint8Array.from(h),s(h[0]))}(r)}return r.from=function(e,n,t,o){return new r({witness:e,witnessVersion:o,blindingPublicKey:n,hrp:t})},r.fromString=function(e,n){return new r(function(r,e){var n=w(r,e),i=n.hrp,a=n.data,f=a[0];if(o(f),0===a.length||a.length>1e3)throw new Error("Invalid data length");var s=t(Array.from(a.slice(1)),5,8,!1);if(s.length<2||s.length>65)throw new Error("Invalid witness data length");if(0===a[0]&&53!==s.length&&65!==s.length)throw new Error("Invalid witness data length for witness version 0");var c=Buffer.from(s.slice(0,33)).toString("hex");return{witness:Buffer.from(s.slice(33)).toString("hex"),blindingPublicKey:c,witnessVersion:f,hrp:i}}(e,n))},r}();exports.BLECH32="blech32",exports.BLECH32M="blech32m",exports.Blech32Address=v,exports.MAX_LEN=1e3,exports.decode=w,exports.encode=d,exports.getEncodingType=s; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,e=(r=require("long"))&&"object"==typeof r&&"default"in r?r.default:r;function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}function t(r,e,t,o){if(e<1||e>8||t<1||e>8)throw new Error("only bits groups between 1 and 8 are allowed");for(var i,a=[],f=0,s=0,c=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,void 0);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,void 0):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(i=c()).done;)for(var h=i.value<<8-e,l=e;l>0;){var u=t-s,d=l;u<d&&(d=u),f=f<<d|h>>8-d,h=(h<<d)%256,l-=d,(s+=d)===t&&(a.push(f),s=0,f=0)}if(o&&s>0&&(a.push(f<<=t-s),s=0,f=0),s>0&&(s>4||0!==f))throw new Error("invalid incomplete group of bits");return a}function o(r){if(r<0||r>16)throw new Error("invalid witness version")}var i="qpzry9x8gf2tvdw0s3jn54khce6mua7l";function a(r){return e.fromString(r,!0,16)}var f=["7d52fba40bd886","5e8dbf1a03950c","1c3a3c74072a18","385d72fa0e5139","7093e5a608865b"].map(a);function s(r){if(o(r),0===r)return"blech32";if(1===r)return"blech32m";throw new Error("Unsuported witness version ("+r+"), only 0 (blech32) or 1 (blech32m) are supported")}function c(r){if("blech32"===r)return e.fromNumber(1);if("blech32m"===r)return a("2bc830a3");throw new Error("Invalid encoding type")}function h(r){for(var n=e.fromNumber(1),t=0;t<r.length;++t){var o=n.shiftRight(55);n=n.and(a("7fffffffffffff")).shiftLeft(5).xor(r[t]);for(var i=0;i<5;i++)o.shiftRight(e.fromNumber(i)).and(1).equals(1)&&(n=n.xor(f[i]))}return n}function l(r){for(var e=[],n=0;n<r.length;++n)e.push(r.charCodeAt(n)>>5);e.push(0);for(var t=0;t<r.length;++t)e.push(31&r.charCodeAt(t));return Uint8Array.from(e)}var u=[0,0,0,0,0,0,0,0,0,0,0,0];function d(r,e,n){for(var t=function(r,e,n){for(var t=h(Array.from(l(r)).concat(Array.from(e)).concat(u)).xor(c(n)),o=[],i=0;i<12;++i)o.push(t.shiftRight(5*(11-i)).and(31));return o.map((function(r){return r.toInt()}))}(r,e,n),o=Array.from(e).concat(t),a=r+"1",f=0;f<o.length;++f)a+=i.charAt(o[f]);return a}function w(r,e){for(var n=!1,t=!1,o=0;o<r.length;++o){if(r.charCodeAt(o)<33||r.charCodeAt(o)>126)throw new Error("Invalid charcode in blech32 string");r.charCodeAt(o)>=97&&r.charCodeAt(o)<=122&&(n=!0),r.charCodeAt(o)>=65&&r.charCodeAt(o)<=90&&(t=!0)}if(n&&t)throw new Error("blech32 has lowercases AND uppercases");var a=(r=r.toLowerCase()).lastIndexOf("1");if(a<1||a+13>r.length)throw new Error('Invalid index of "1"');for(var f=r.substring(0,a),s=[],u=a+1;u<r.length;++u){var d=i.indexOf(r.charAt(u));if(-1===d)throw new Error('"'+r.charAt(u)+'" is not allowed in blech32 strings');s.push(d)}if(!function(r,e,n){return h(Array.from(l(r)).concat(e)).equals(c(n))}(f,s,e))throw new Error("invalid "+e+" checksum");return{hrp:f,data:Uint8Array.from(s.slice(0,s.length-12))}}var v=function(){function r(r){this.witness=r.witness,this.blindingPublicKey=r.blindingPublicKey,this.witnessVersion=r.witnessVersion,this.address=function(r){var e=r.witness,n=r.witnessVersion,i=r.blindingPublicKey,a=r.hrp;o(n);var f=Buffer.concat([Buffer.from(i,"hex"),Buffer.from(e,"hex")]),c=f.length;if(0===n&&53!==c&&65!==c)throw new Error("witness version 0 needs witness program length = 53 OR = 65");if(c<2||c>65)throw new Error("witness program length should be >= 2 and <= 65");var h=[n].concat(t(Array.from(f),8,5,!0));return d(a,Uint8Array.from(h),s(h[0]))}(r)}return r.from=function(e,n,t,o){return new r({witness:e,witnessVersion:o,blindingPublicKey:n,hrp:t})},r.fromString=function(e,n){return new r(function(r,e){var n=w(r,e),i=n.hrp,a=n.data,f=a[0];if(o(f),0===a.length||a.length>1e3)throw new Error("Invalid data length");var s=t(Array.from(a.slice(1)),5,8,!1);if(s.length<2||s.length>65)throw new Error("Invalid witness data length");if(0===a[0]&&53!==s.length&&65!==s.length)throw new Error("Invalid witness data length for witness version 0");var c=Buffer.from(s.slice(0,33)).toString("hex");return{witness:Buffer.from(s.slice(33)).toString("hex"),blindingPublicKey:c,witnessVersion:f,hrp:i}}(e,n))},r}();exports.BLECH32="blech32",exports.BLECH32M="blech32m",exports.Blech32Address=v,exports.MAX_LEN=1e3,exports.decode=w,exports.encode=d,exports.getEncodingType=s; | ||
//# sourceMappingURL=blech32.cjs.production.min.js.map |
@@ -273,3 +273,3 @@ import Long from 'long'; | ||
var witnessProgLength = witnessProgram.length; | ||
if (witnessProgLength !== 53 && witnessProgLength !== 65) throw new Error("witness version 0 needs witness program length = 53 OR = 65"); | ||
if (witnessVersion === 0 && witnessProgLength !== 53 && witnessProgLength !== 65) throw new Error("witness version 0 needs witness program length = 53 OR = 65"); | ||
if (witnessProgLength < 2 || witnessProgLength > 65) throw new Error("witness program length should be >= 2 and <= 65"); | ||
@@ -276,0 +276,0 @@ var data = [witnessVersion].concat(convertBits(Array.from(witnessProgram), 8, 5, true)); |
{ | ||
"name": "blech32", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Blech32 encoding / decoding", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
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
84687