Socket
Socket
Sign inDemoInstall

@spartan-hc/holo-hash

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spartan-hc/holo-hash - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

42

dist/holo-hash.js

@@ -409,2 +409,4 @@ /******/ var __webpack_modules__ = ({

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "heritage": () => (/* binding */ heritage),
/* harmony export */ "in_heritage": () => (/* binding */ in_heritage),
/* harmony export */ "set_tostringtag": () => (/* binding */ set_tostringtag)

@@ -423,3 +425,30 @@ /* harmony export */ });

function heritage ( target, stop_at = "" ) {
if ( typeof target !== "function" ) {
// Empty heritage for primitive types
if ( target === null || typeof target !== "object" )
return [];
else
target = target.constructor;
}
let i = 0;
let class_names = [];
while ( target.name !== stop_at ) {
class_names.unshift( target.name );
target = Object.getPrototypeOf( target );
i++;
if ( i > 50 )
throw new Error(`heritage exceeded recursive limit (50); ${class_names.join(", ")}`);
}
return class_names;
}
function in_heritage ( target, class_name ) {
return heritage( target ).includes( class_name );
}
/***/ })

@@ -608,4 +637,6 @@

constructor ( input, strict = true ) {
if ( input instanceof HoloHash )
if ( (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__.in_heritage)( input, HoloHash.name ) ) {
debug && log("Convert instance of HoloHash to Uint8Array bytes: %s", input.constructor.name );
input = input.bytes();
}

@@ -640,7 +671,2 @@ debug && log("New construction input (strict: %s): %s", strict, String(input) );

if ( input instanceof HoloHash ) {
debug && log("Convert instance of HoloHash to Uint8Array bytes: %s", input.constructor.name );
input = input.bytes();
}
let given_dht_addr;

@@ -911,3 +937,3 @@ if ( input.length === 36 ) {

if ( this.constructor.name === AnyLinkableHash.name ) {
if ( input instanceof HoloHash )
if ( (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__.in_heritage)( input, HoloHash.name ) )
input = input.bytes();

@@ -938,3 +964,3 @@ let given_prefix = input.slice(0,3);

if ( this.constructor.name === AnyDhtHash.name ) {
if ( input instanceof HoloHash )
if ( (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__.in_heritage)( input, HoloHash.name ) )
input = input.bytes();

@@ -941,0 +967,0 @@ let given_prefix = input.slice(0,3);

2

dist/holo-hash.min.js

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

var e={29:e=>{let t=!1;function r(e,t){let r=new Uint8Array(t),s=0;for(;s<e.length;){let a=e.slice(s,s+t);s+=t;for(let e=0;e<t&&void 0!==a[e];e++)r[e]^=a[e]}return r}let s={xor_digest:r,logging(){t=!0}};e.exports={bindNative(){if(void 0!==String.prototype.xorDigest)throw new Error("Uint8Array.xorDigest is already defined as type: "+typeof Uint8Array.xorDigest);return Object.defineProperty(Uint8Array.prototype,"xorDigest",{value:function(e){return new r(this,e)},enumerable:!1,writable:!1}),s},...s}}},t={};function r(s){var a=t[s];if(void 0!==a)return a.exports;var n=t[s]={exports:{}};return e[s](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var s={};(()=>{r.d(s,{z3:()=>ActionHash,DN:()=>AgentPubKey,aV:()=>AnyDhtHash,lp:()=>N,QD:()=>AnyLinkableHash,W9:()=>L,WY:()=>BadBase64Error,jW:()=>BadChecksumError,Q8:()=>BadPrefixError,Xr:()=>BadSizeError,lC:()=>DhtOpHash,BH:()=>DnaHash,g7:()=>EntryHash,hb:()=>ExternalHash,o_:()=>HoloHash,WH:()=>HoloHashError,h8:()=>j,uu:()=>NetIdHash,ZS:()=>NoLeadingUError,v3:()=>Warning,By:()=>WasmHash,US:()=>T,Js:()=>R,ZP:()=>C,PW:()=>F});var e=r(29);const t=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),a=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(e){return 2*e})));function n(e,t,r){let s=e[t]+e[r],a=e[t+1]+e[r+1];s>=4294967296&&a++,e[t]=s,e[t+1]=a}function o(e,t,r,s){let a=e[t]+r;r<0&&(a+=4294967296);let n=e[t+1]+s;a>=4294967296&&n++,e[t]=a,e[t+1]=n}function i(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}let h=new Uint32Array(32),l=new Uint32Array(32);function c(e,t,r,s,a,i){let c=l[a],H=l[a+1],u=l[i],d=l[i+1];n(h,e,t),o(h,e,c,H);let y=h[s]^h[e],f=h[s+1]^h[e+1];h[s]=f,h[s+1]=y,n(h,r,s),y=h[t]^h[r],f=h[t+1]^h[r+1],h[t]=y>>>24^f<<8,h[t+1]=f>>>24^y<<8,n(h,e,t),o(h,e,u,d),y=h[s]^h[e],f=h[s+1]^h[e+1],h[s]=y>>>16^f<<16,h[s+1]=f>>>16^y<<16,n(h,r,s),y=h[t]^h[r],f=h[t+1]^h[r+1],h[t]=f>>>31^y<<1,h[t+1]=y>>>31^f<<1}function H(e,r){let s=0;for(s=0;s<16;s++)h[s]=e.h[s],h[s+16]=t[s];for(h[24]=h[24]^e.t,h[25]=h[25]^e.t/4294967296,r&&(h[28]=~h[28],h[29]=~h[29]),s=0;s<32;s++)l[s]=i(e.b,4*s);for(s=0;s<12;s++)c(0,8,16,24,a[16*s+0],a[16*s+1]),c(2,10,18,26,a[16*s+2],a[16*s+3]),c(4,12,20,28,a[16*s+4],a[16*s+5]),c(6,14,22,30,a[16*s+6],a[16*s+7]),c(0,10,20,30,a[16*s+8],a[16*s+9]),c(2,12,22,24,a[16*s+10],a[16*s+11]),c(4,14,16,26,a[16*s+12],a[16*s+13]),c(6,8,18,28,a[16*s+14],a[16*s+15]);for(s=0;s<16;s++)e.h[s]=e.h[s]^h[s]^h[s+16]}function u(e,t){for(let r=0;r<t.length;r++)128===e.c&&(e.t+=e.c,H(e,!1),e.c=0),e.b[e.c++]=t[r]}function d(e,r,s){if(s=s||64,Array.isArray(e))e=new Uint8Array(e);else if(!(e instanceof Uint8Array))throw new TypeError("blake2b input must be a Uint8Array; not type "+typeof e);let a=function(e,r){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(r&&r.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");let s={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e};for(let e=0;e<16;e++)s.h[e]=t[e];let a=r?r.length:0;return s.h[0]^=16842752^a<<8^e,r&&(u(s,r),s.c=128),s}(s,r);return u(a,e),function(e){for(e.t+=e.c;e.c<128;)e.b[e.c++]=0;H(e,!0);let t=new Uint8Array(e.outlen);for(let r=0;r<e.outlen;r++)t[r]=e.h[r>>2]>>8*(3&r);return t}(a)}const y=Object.freeze([132,47,190]),f=Object.freeze([132,47,255]),g=Object.freeze([132,32,36]),b=Object.freeze([132,33,36]),E=Object.freeze([132,34,36]),p=Object.freeze([132,36,36]),A=Object.freeze([132,41,36]),m=Object.freeze([132,42,36]),w=Object.freeze([132,45,36]),x=Object.freeze([132,47,36]);function P(e,t){Object.defineProperty(e,"name",{value:t||e.name}),Object.defineProperty(e.prototype,Symbol.toStringTag,{value:t||e.name,enumerable:!1})}class CustomError extends Error{static[Symbol.toPrimitive](e){return"number"===e?null:`[${this.name} {}]`}constructor(...e){super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}[Symbol.toPrimitive](e){return"number"===e?null:this.toString()}toString(){return`[${this.constructor.name}( ${this.message} )]`}toJSON(e=!1){return{error:this.name,message:this.message,stack:!0===e?"string"==typeof this.stack?this.stack.split("\n"):this.stack:void 0}}}P(CustomError);class Warning extends CustomError{}P(Warning,"Warning");class HoloHashError extends CustomError{}P(HoloHashError,"HoloHashError");class NoLeadingUError extends HoloHashError{}P(NoLeadingUError,"NoLeadingUError");class BadBase64Error extends HoloHashError{}P(BadBase64Error,"BadBase64Error");class BadSizeError extends HoloHashError{}P(BadSizeError,"BadSizeError");class BadPrefixError extends HoloHashError{}P(BadPrefixError,"BadPrefixError");class BadChecksumError extends HoloHashError{}P(BadChecksumError,"BadChecksumError");const{xor_digest:D}=e,B=new Function("try {return this===global;}catch(e){return false;}")(),S=new RegExp("^[A-Za-z0-9+/]+={0,3}$");let v=!1;function U(e,...t){let r=(new Date).toISOString();console.log(`${r} [ src/index. ] INFO: ${e}`,...t)}function O(e){return v&&U("Encode URL-safe base64:",e.constructor.name,e.length),e.replace(/[+/]/g,(e=>"+"===e?"-":"_"))}function I(e){return v&&U("Decode URL-safe base64:",e),e.replace(/[-_]/g,(e=>"-"===e?"+":"/"))}function $(e){return(B?Buffer.from(e).toString("base64"):btoa(String.fromCharCode.apply(null,e))).replace(/=+$/,"")}function W(e){if(!1===S.test(e))throw new TypeError(`Invalid base64 character(s) in '${e}'`);return B?Buffer.from(e,"base64"):[].reduce.call(atob(e),((e,t,r)=>(e[r]=t.charCodeAt(0),e)),new Uint8Array(39))}function k(e){return v&&U("Encoding URL-safe base64 hash:",typeof e,e.length),O($(e))}class HoloHash extends Uint8Array{constructor(e,t=!0){if(e instanceof HoloHash&&(e=e.bytes()),v&&U("New construction input (strict: %s): %s",t,String(e)),super(39),super.set(this.constructor.PREFIX||y),"string"==typeof e){if(e=e.trim(),!0===t&&52===e.length&&e.startsWith("hC"))throw new NoLeadingUError(`Holo Hash missing 'u' prefix: ${e}`);53===e.length&&e.startsWith("u")&&(e=e.slice(1));try{e=new Uint8Array((r=e,v&&U("Decoding URL-safe base64 hash:",r),r.startsWith("u")&&(r=r.slice(1)),W(I(r))))}catch(t){throw v&&U("Failed to decode base64:",t),new BadBase64Error(`Failed to decode base64 input (${e})`)}v&&U("Decoded base64 bytes: %s",e.length)}var r;if(!(e instanceof Uint8Array))throw new TypeError(`Invalid HoloHash input: typeof ${typeof e}; expected string or Uint8Array`);let s;if("Uint8Array"!==e.constructor.name&&(e=new Uint8Array(e)),e instanceof HoloHash&&(v&&U("Convert instance of HoloHash to Uint8Array bytes: %s",e.constructor.name),e=e.bytes()),36===e.length)s=e.slice(-4),e=e.slice(0,-4);else if(39===e.length){let r=e.slice(0,3);if(String(r)===String(this.constructor.PREFIX)||String(y)===String(r))s=e.slice(-4),e=e.slice(3,-4);else{if(String(f)!==String(this.constructor.PREFIX)){if(v&&U("Check if constructor is agnostic type: %s === %s",this.constructor.name,HoloHash.name),this.constructor.name===HoloHash.name)for(let s of Object.values(j))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(j).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any HoloHash types: ${r}; valid types are ${s}`)}s=e.slice(-4),e=e.slice(3,-4)}}if(32!==e.length)throw new BadSizeError(`Invalid input byte length (${e.length}); expected length 39, 36, or 32`);let a=function(e){v&&U("Calculate DHT address from %s bytes",e.length);let t=d(e,null,16);return D(t,4)}(e);if(!0===t&&void 0!==s&&(v&&U("Comparing DHT addresses given/calc:",s,a),String(s)!==String(a)))throw new BadChecksumError(`Given DHT address (${s}) does not match calculated address: ${a}`);super.set(e,3),super.set(a,35),Object.defineProperties(this,{prefix:{value:new Uint8Array(this.buffer,0,3),writable:!1,enumerable:!1,configurable:!1},dht_address:{value:new DataView(this.buffer,35),writable:!1,enumerable:!1,configurable:!1}})}set(){throw new Error("You should not be manually modifying HoloHash bytes")}slice(){throw new Error("HoloHash is not intended to by sliced; use <HoloHash>.bytes() to get Uint8Array slices")}bytes(e,t){let r;return void 0!==t&&(r=t<0?this.buffer.byteLength-e+t:t-e),void 0!==e&&e<0&&(e=this.buffer.byteLength+e),new Uint8Array(this.buffer,e,r)}getPrefix(){return this.bytes(0,3)}getPrefixB64(e=!0){return(!0===e?"u":"")+k(this.getPrefix())}getHash(){return this.bytes(3,-4)}getHashB64(e=!1){if(!0!==e)throw new Warning("A base64 representation of the DHT Address MIGHT not match the base64 from the full hash string.");return k(this.getHash())}getDHTAddress(){return this.bytes(-4)}getDHTAddressB64(e=!1){if(!0!==e)throw new Warning("A base64 representation of the DHT Address WILL NOT match the base64 from the full hash string.");return k(this.getDHTAddress())}getDHTLocation(){return this.dht_address.getUint32()}toBytes(){return this.bytes()}addTag(e){return Object.defineProperty(this,"tag",{value:e,writable:!0}),this}toString(e=!1){const t="u"+k(this.bytes());if(e){let e=`${t.slice(0,4)}…${t.slice(-4)}`;return this.tag?`${this.constructor.name}( ${this.tag} [${e}] )`:`${this.constructor.name}( ${e} )`}return t}toJSON(){return this.toString()}toType(e){if("string"!=typeof e&&(e=e.name),void 0===j[e])throw new Error(`Invalid HoloHash type (${e}); must be one of: ${Object.keys(j)}`);return v&&U("Retype (%s) to (%s)",this.constructor.name,e),new j[e](this.bytes(3))}retype(e){return this.toType(e)}hashType(){return this.constructor}}P(HoloHash,"HoloHash");class AnyLinkableHash extends HoloHash{static PREFIX=f;constructor(e,t){if(super(e,t),this.constructor.name===AnyLinkableHash.name){e instanceof HoloHash&&(e=e.bytes());let r=e.slice(0,3);for(let s of Object.values(L))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(L).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any AnyLinkableHash types: ${r}; valid types are ${s}`)}}}P(AnyLinkableHash,"AnyLinkableHash");class AnyDhtHash extends AnyLinkableHash{static PREFIX=f;constructor(e,t){if(super(e,t),this.constructor.name===AnyDhtHash.name){e instanceof HoloHash&&(e=e.bytes());let r=e.slice(0,3);for(let s of Object.values(N))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(N).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any AnyDhtHash types: ${r}; valid types are ${s}`)}}}P(AnyDhtHash,"AnyDhtHash");class ExternalHash extends AnyLinkableHash{static PREFIX=x}P(ExternalHash,"ExternalHash");class AgentPubKey extends AnyDhtHash{static PREFIX=g}P(AgentPubKey,"AgentPubKey");class EntryHash extends AnyDhtHash{static PREFIX=b}P(EntryHash,"EntryHash");class NetIdHash extends HoloHash{static PREFIX=E}P(NetIdHash,"NetIdHash");class DhtOpHash extends HoloHash{static PREFIX=p}P(DhtOpHash,"DhtOpHash");class ActionHash extends AnyDhtHash{static PREFIX=A}P(ActionHash,"ActionHash");class WasmHash extends HoloHash{static PREFIX=m}P(WasmHash,"WasmHash");class DnaHash extends HoloHash{static PREFIX=w}P(DnaHash,"DnaHash");const j={AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash},L={AgentPubKey,EntryHash,ActionHash,ExternalHash},N={AgentPubKey,EntryHash,ActionHash},T={encode:$,decode:W,url_encode:O,url_decode:I};function R(){if(void 0!==String.prototype.toHoloHash)throw new Error("String.toHoloHash is already defined as type: "+typeof String.toHoloHash);Object.defineProperty(String.prototype,"toHoloHash",{value:function(e){return new HoloHash(String(this),e)},enumerable:!1,writable:!1})}function F(){v=!0}const C={HoloHash,HoloHashTypes:j,AnyDhtHash,AnyDhtHashTypes:N,AnyLinkableHash,AnyLinkableHashTypes:L,AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash,Warning,HoloHashError,NoLeadingUError,BadBase64Error,BadSizeError,BadPrefixError,BadChecksumError,logging:F,base64:T,bindNative:R}})();var a=s.z3,n=s.DN,o=s.aV,i=s.lp,h=s.QD,l=s.W9,c=s.WY,H=s.jW,u=s.Q8,d=s.Xr,y=s.lC,f=s.BH,g=s.g7,b=s.hb,E=s.o_,p=s.WH,A=s.h8,m=s.uu,w=s.ZS,x=s.v3,P=s.By,D=s.US,B=s.Js,S=s.ZP,v=s.PW;export{a as ActionHash,n as AgentPubKey,o as AnyDhtHash,i as AnyDhtHashTypes,h as AnyLinkableHash,l as AnyLinkableHashTypes,c as BadBase64Error,H as BadChecksumError,u as BadPrefixError,d as BadSizeError,y as DhtOpHash,f as DnaHash,g as EntryHash,b as ExternalHash,E as HoloHash,p as HoloHashError,A as HoloHashTypes,m as NetIdHash,w as NoLeadingUError,x as Warning,P as WasmHash,D as base64,B as bindNative,S as default,v as logging};
var e={29:e=>{let t=!1;function r(e,t){let r=new Uint8Array(t),s=0;for(;s<e.length;){let a=e.slice(s,s+t);s+=t;for(let e=0;e<t&&void 0!==a[e];e++)r[e]^=a[e]}return r}let s={xor_digest:r,logging(){t=!0}};e.exports={bindNative(){if(void 0!==String.prototype.xorDigest)throw new Error("Uint8Array.xorDigest is already defined as type: "+typeof Uint8Array.xorDigest);return Object.defineProperty(Uint8Array.prototype,"xorDigest",{value:function(e){return new r(this,e)},enumerable:!1,writable:!1}),s},...s}}},t={};function r(s){var a=t[s];if(void 0!==a)return a.exports;var n=t[s]={exports:{}};return e[s](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var s={};(()=>{r.d(s,{z3:()=>ActionHash,DN:()=>AgentPubKey,aV:()=>AnyDhtHash,lp:()=>T,QD:()=>AnyLinkableHash,W9:()=>N,WY:()=>BadBase64Error,jW:()=>BadChecksumError,Q8:()=>BadPrefixError,Xr:()=>BadSizeError,lC:()=>DhtOpHash,BH:()=>DnaHash,g7:()=>EntryHash,hb:()=>ExternalHash,o_:()=>HoloHash,WH:()=>HoloHashError,h8:()=>L,uu:()=>NetIdHash,ZS:()=>NoLeadingUError,v3:()=>Warning,By:()=>WasmHash,US:()=>R,Js:()=>F,ZP:()=>z,PW:()=>C});var e=r(29);const t=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),a=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(e){return 2*e})));function n(e,t,r){let s=e[t]+e[r],a=e[t+1]+e[r+1];s>=4294967296&&a++,e[t]=s,e[t+1]=a}function o(e,t,r,s){let a=e[t]+r;r<0&&(a+=4294967296);let n=e[t+1]+s;a>=4294967296&&n++,e[t]=a,e[t+1]=n}function i(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}let h=new Uint32Array(32),l=new Uint32Array(32);function c(e,t,r,s,a,i){let c=l[a],H=l[a+1],u=l[i],d=l[i+1];n(h,e,t),o(h,e,c,H);let y=h[s]^h[e],f=h[s+1]^h[e+1];h[s]=f,h[s+1]=y,n(h,r,s),y=h[t]^h[r],f=h[t+1]^h[r+1],h[t]=y>>>24^f<<8,h[t+1]=f>>>24^y<<8,n(h,e,t),o(h,e,u,d),y=h[s]^h[e],f=h[s+1]^h[e+1],h[s]=y>>>16^f<<16,h[s+1]=f>>>16^y<<16,n(h,r,s),y=h[t]^h[r],f=h[t+1]^h[r+1],h[t]=f>>>31^y<<1,h[t+1]=y>>>31^f<<1}function H(e,r){let s=0;for(s=0;s<16;s++)h[s]=e.h[s],h[s+16]=t[s];for(h[24]=h[24]^e.t,h[25]=h[25]^e.t/4294967296,r&&(h[28]=~h[28],h[29]=~h[29]),s=0;s<32;s++)l[s]=i(e.b,4*s);for(s=0;s<12;s++)c(0,8,16,24,a[16*s+0],a[16*s+1]),c(2,10,18,26,a[16*s+2],a[16*s+3]),c(4,12,20,28,a[16*s+4],a[16*s+5]),c(6,14,22,30,a[16*s+6],a[16*s+7]),c(0,10,20,30,a[16*s+8],a[16*s+9]),c(2,12,22,24,a[16*s+10],a[16*s+11]),c(4,14,16,26,a[16*s+12],a[16*s+13]),c(6,8,18,28,a[16*s+14],a[16*s+15]);for(s=0;s<16;s++)e.h[s]=e.h[s]^h[s]^h[s+16]}function u(e,t){for(let r=0;r<t.length;r++)128===e.c&&(e.t+=e.c,H(e,!1),e.c=0),e.b[e.c++]=t[r]}function d(e,r,s){if(s=s||64,Array.isArray(e))e=new Uint8Array(e);else if(!(e instanceof Uint8Array))throw new TypeError("blake2b input must be a Uint8Array; not type "+typeof e);let a=function(e,r){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(r&&r.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");let s={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e};for(let e=0;e<16;e++)s.h[e]=t[e];let a=r?r.length:0;return s.h[0]^=16842752^a<<8^e,r&&(u(s,r),s.c=128),s}(s,r);return u(a,e),function(e){for(e.t+=e.c;e.c<128;)e.b[e.c++]=0;H(e,!0);let t=new Uint8Array(e.outlen);for(let r=0;r<e.outlen;r++)t[r]=e.h[r>>2]>>8*(3&r);return t}(a)}const y=Object.freeze([132,47,190]),f=Object.freeze([132,47,255]),g=Object.freeze([132,32,36]),b=Object.freeze([132,33,36]),E=Object.freeze([132,34,36]),p=Object.freeze([132,36,36]),m=Object.freeze([132,41,36]),A=Object.freeze([132,42,36]),w=Object.freeze([132,45,36]),x=Object.freeze([132,47,36]);function P(e,t){Object.defineProperty(e,"name",{value:t||e.name}),Object.defineProperty(e.prototype,Symbol.toStringTag,{value:t||e.name,enumerable:!1})}function D(e,t){return function(e,t=""){if("function"!=typeof e){if(null===e||"object"!=typeof e)return[];e=e.constructor}let r=0,s=[];for(;e.name!==t;)if(s.unshift(e.name),e=Object.getPrototypeOf(e),r++,r>50)throw new Error(`heritage exceeded recursive limit (50); ${s.join(", ")}`);return s}(e).includes(t)}class CustomError extends Error{static[Symbol.toPrimitive](e){return"number"===e?null:`[${this.name} {}]`}constructor(...e){super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}[Symbol.toPrimitive](e){return"number"===e?null:this.toString()}toString(){return`[${this.constructor.name}( ${this.message} )]`}toJSON(e=!1){return{error:this.name,message:this.message,stack:!0===e?"string"==typeof this.stack?this.stack.split("\n"):this.stack:void 0}}}P(CustomError);class Warning extends CustomError{}P(Warning,"Warning");class HoloHashError extends CustomError{}P(HoloHashError,"HoloHashError");class NoLeadingUError extends HoloHashError{}P(NoLeadingUError,"NoLeadingUError");class BadBase64Error extends HoloHashError{}P(BadBase64Error,"BadBase64Error");class BadSizeError extends HoloHashError{}P(BadSizeError,"BadSizeError");class BadPrefixError extends HoloHashError{}P(BadPrefixError,"BadPrefixError");class BadChecksumError extends HoloHashError{}P(BadChecksumError,"BadChecksumError");const{xor_digest:B}=e,S=new Function("try {return this===global;}catch(e){return false;}")(),v=new RegExp("^[A-Za-z0-9+/]+={0,3}$");let O=!1;function U(e,...t){let r=(new Date).toISOString();console.log(`${r} [ src/index. ] INFO: ${e}`,...t)}function I(e){return O&&U("Encode URL-safe base64:",e.constructor.name,e.length),e.replace(/[+/]/g,(e=>"+"===e?"-":"_"))}function $(e){return O&&U("Decode URL-safe base64:",e),e.replace(/[-_]/g,(e=>"-"===e?"+":"/"))}function j(e){return(S?Buffer.from(e).toString("base64"):btoa(String.fromCharCode.apply(null,e))).replace(/=+$/,"")}function W(e){if(!1===v.test(e))throw new TypeError(`Invalid base64 character(s) in '${e}'`);return S?Buffer.from(e,"base64"):[].reduce.call(atob(e),((e,t,r)=>(e[r]=t.charCodeAt(0),e)),new Uint8Array(39))}function k(e){return O&&U("Encoding URL-safe base64 hash:",typeof e,e.length),I(j(e))}class HoloHash extends Uint8Array{constructor(e,t=!0){if(D(e,HoloHash.name)&&(O&&U("Convert instance of HoloHash to Uint8Array bytes: %s",e.constructor.name),e=e.bytes()),O&&U("New construction input (strict: %s): %s",t,String(e)),super(39),super.set(this.constructor.PREFIX||y),"string"==typeof e){if(e=e.trim(),!0===t&&52===e.length&&e.startsWith("hC"))throw new NoLeadingUError(`Holo Hash missing 'u' prefix: ${e}`);53===e.length&&e.startsWith("u")&&(e=e.slice(1));try{e=new Uint8Array((r=e,O&&U("Decoding URL-safe base64 hash:",r),r.startsWith("u")&&(r=r.slice(1)),W($(r))))}catch(t){throw O&&U("Failed to decode base64:",t),new BadBase64Error(`Failed to decode base64 input (${e})`)}O&&U("Decoded base64 bytes: %s",e.length)}var r;if(!(e instanceof Uint8Array))throw new TypeError(`Invalid HoloHash input: typeof ${typeof e}; expected string or Uint8Array`);let s;if("Uint8Array"!==e.constructor.name&&(e=new Uint8Array(e)),36===e.length)s=e.slice(-4),e=e.slice(0,-4);else if(39===e.length){let r=e.slice(0,3);if(String(r)===String(this.constructor.PREFIX)||String(y)===String(r))s=e.slice(-4),e=e.slice(3,-4);else{if(String(f)!==String(this.constructor.PREFIX)){if(O&&U("Check if constructor is agnostic type: %s === %s",this.constructor.name,HoloHash.name),this.constructor.name===HoloHash.name)for(let s of Object.values(L))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(L).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any HoloHash types: ${r}; valid types are ${s}`)}s=e.slice(-4),e=e.slice(3,-4)}}if(32!==e.length)throw new BadSizeError(`Invalid input byte length (${e.length}); expected length 39, 36, or 32`);let a=function(e){O&&U("Calculate DHT address from %s bytes",e.length);let t=d(e,null,16);return B(t,4)}(e);if(!0===t&&void 0!==s&&(O&&U("Comparing DHT addresses given/calc:",s,a),String(s)!==String(a)))throw new BadChecksumError(`Given DHT address (${s}) does not match calculated address: ${a}`);super.set(e,3),super.set(a,35),Object.defineProperties(this,{prefix:{value:new Uint8Array(this.buffer,0,3),writable:!1,enumerable:!1,configurable:!1},dht_address:{value:new DataView(this.buffer,35),writable:!1,enumerable:!1,configurable:!1}})}set(){throw new Error("You should not be manually modifying HoloHash bytes")}slice(){throw new Error("HoloHash is not intended to by sliced; use <HoloHash>.bytes() to get Uint8Array slices")}bytes(e,t){let r;return void 0!==t&&(r=t<0?this.buffer.byteLength-e+t:t-e),void 0!==e&&e<0&&(e=this.buffer.byteLength+e),new Uint8Array(this.buffer,e,r)}getPrefix(){return this.bytes(0,3)}getPrefixB64(e=!0){return(!0===e?"u":"")+k(this.getPrefix())}getHash(){return this.bytes(3,-4)}getHashB64(e=!1){if(!0!==e)throw new Warning("A base64 representation of the DHT Address MIGHT not match the base64 from the full hash string.");return k(this.getHash())}getDHTAddress(){return this.bytes(-4)}getDHTAddressB64(e=!1){if(!0!==e)throw new Warning("A base64 representation of the DHT Address WILL NOT match the base64 from the full hash string.");return k(this.getDHTAddress())}getDHTLocation(){return this.dht_address.getUint32()}toBytes(){return this.bytes()}addTag(e){return Object.defineProperty(this,"tag",{value:e,writable:!0}),this}toString(e=!1){const t="u"+k(this.bytes());if(e){let e=`${t.slice(0,4)}…${t.slice(-4)}`;return this.tag?`${this.constructor.name}( ${this.tag} [${e}] )`:`${this.constructor.name}( ${e} )`}return t}toJSON(){return this.toString()}toType(e){if("string"!=typeof e&&(e=e.name),void 0===L[e])throw new Error(`Invalid HoloHash type (${e}); must be one of: ${Object.keys(L)}`);return O&&U("Retype (%s) to (%s)",this.constructor.name,e),new L[e](this.bytes(3))}retype(e){return this.toType(e)}hashType(){return this.constructor}}P(HoloHash,"HoloHash");class AnyLinkableHash extends HoloHash{static PREFIX=f;constructor(e,t){if(super(e,t),this.constructor.name===AnyLinkableHash.name){D(e,HoloHash.name)&&(e=e.bytes());let r=e.slice(0,3);for(let s of Object.values(N))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(N).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any AnyLinkableHash types: ${r}; valid types are ${s}`)}}}P(AnyLinkableHash,"AnyLinkableHash");class AnyDhtHash extends AnyLinkableHash{static PREFIX=f;constructor(e,t){if(super(e,t),this.constructor.name===AnyDhtHash.name){D(e,HoloHash.name)&&(e=e.bytes());let r=e.slice(0,3);for(let s of Object.values(T))if(String(s.PREFIX)===String(r))return new s(e.slice(3),t);const s=Object.values(T).map((e=>`${e.name} (${e.PREFIX})`)).join(", ");throw new BadPrefixError(`Hash prefix did not match any AnyDhtHash types: ${r}; valid types are ${s}`)}}}P(AnyDhtHash,"AnyDhtHash");class ExternalHash extends AnyLinkableHash{static PREFIX=x}P(ExternalHash,"ExternalHash");class AgentPubKey extends AnyDhtHash{static PREFIX=g}P(AgentPubKey,"AgentPubKey");class EntryHash extends AnyDhtHash{static PREFIX=b}P(EntryHash,"EntryHash");class NetIdHash extends HoloHash{static PREFIX=E}P(NetIdHash,"NetIdHash");class DhtOpHash extends HoloHash{static PREFIX=p}P(DhtOpHash,"DhtOpHash");class ActionHash extends AnyDhtHash{static PREFIX=m}P(ActionHash,"ActionHash");class WasmHash extends HoloHash{static PREFIX=A}P(WasmHash,"WasmHash");class DnaHash extends HoloHash{static PREFIX=w}P(DnaHash,"DnaHash");const L={AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash},N={AgentPubKey,EntryHash,ActionHash,ExternalHash},T={AgentPubKey,EntryHash,ActionHash},R={encode:j,decode:W,url_encode:I,url_decode:$};function F(){if(void 0!==String.prototype.toHoloHash)throw new Error("String.toHoloHash is already defined as type: "+typeof String.toHoloHash);Object.defineProperty(String.prototype,"toHoloHash",{value:function(e){return new HoloHash(String(this),e)},enumerable:!1,writable:!1})}function C(){O=!0}const z={HoloHash,HoloHashTypes:L,AnyDhtHash,AnyDhtHashTypes:T,AnyLinkableHash,AnyLinkableHashTypes:N,AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash,Warning,HoloHashError,NoLeadingUError,BadBase64Error,BadSizeError,BadPrefixError,BadChecksumError,logging:C,base64:R,bindNative:F}})();var a=s.z3,n=s.DN,o=s.aV,i=s.lp,h=s.QD,l=s.W9,c=s.WY,H=s.jW,u=s.Q8,d=s.Xr,y=s.lC,f=s.BH,g=s.g7,b=s.hb,E=s.o_,p=s.WH,m=s.h8,A=s.uu,w=s.ZS,x=s.v3,P=s.By,D=s.US,B=s.Js,S=s.ZP,v=s.PW;export{a as ActionHash,n as AgentPubKey,o as AnyDhtHash,i as AnyDhtHashTypes,h as AnyLinkableHash,l as AnyLinkableHashTypes,c as BadBase64Error,H as BadChecksumError,u as BadPrefixError,d as BadSizeError,y as DhtOpHash,f as DnaHash,g as EntryHash,b as ExternalHash,E as HoloHash,p as HoloHashError,m as HoloHashTypes,A as NetIdHash,w as NoLeadingUError,x as Warning,P as WasmHash,D as base64,B as bindNative,S as default,v as logging};
//# sourceMappingURL=holo-hash.min.js.map
export function set_tostringtag(cls: any, name: any): void;
export function heritage(target: any, stop_at?: string): any[];
export function in_heritage(target: any, class_name: any): boolean;
{
"name": "@spartan-hc/holo-hash",
"version": "0.6.0",
"version": "0.6.1",
"description": "A Javascript library for managing Holochain's HoloHash types",

@@ -5,0 +5,0 @@ "type": "module",

@@ -27,3 +27,6 @@

} from './errors.js';
import { set_tostringtag } from './utils.js';
import {
set_tostringtag,
in_heritage,
} from './utils.js';

@@ -107,4 +110,6 @@ const IS_NODE = (new Function("try {return this===global;}catch(e){return false;}"))();

constructor ( input, strict = true ) {
if ( input instanceof HoloHash )
if ( in_heritage( input, HoloHash.name ) ) {
debug && log("Convert instance of HoloHash to Uint8Array bytes: %s", input.constructor.name );
input = input.bytes();
}

@@ -139,7 +144,2 @@ debug && log("New construction input (strict: %s): %s", strict, String(input) );

if ( input instanceof HoloHash ) {
debug && log("Convert instance of HoloHash to Uint8Array bytes: %s", input.constructor.name );
input = input.bytes();
}
let given_dht_addr;

@@ -410,3 +410,3 @@ if ( input.length === 36 ) {

if ( this.constructor.name === AnyLinkableHash.name ) {
if ( input instanceof HoloHash )
if ( in_heritage( input, HoloHash.name ) )
input = input.bytes();

@@ -437,3 +437,3 @@ let given_prefix = input.slice(0,3);

if ( this.constructor.name === AnyDhtHash.name ) {
if ( input instanceof HoloHash )
if ( in_heritage( input, HoloHash.name ) )
input = input.bytes();

@@ -440,0 +440,0 @@ let given_prefix = input.slice(0,3);

@@ -11,1 +11,28 @@

}
export function heritage ( target, stop_at = "" ) {
if ( typeof target !== "function" ) {
// Empty heritage for primitive types
if ( target === null || typeof target !== "object" )
return [];
else
target = target.constructor;
}
let i = 0;
let class_names = [];
while ( target.name !== stop_at ) {
class_names.unshift( target.name );
target = Object.getPrototypeOf( target );
i++;
if ( i > 50 )
throw new Error(`heritage exceeded recursive limit (50); ${class_names.join(", ")}`);
}
return class_names;
}
export function in_heritage ( target, class_name ) {
return heritage( target ).includes( class_name );
}

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