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

@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.5.4 to 0.6.0

1

dist/constants.d.ts
export const BLANK_PREFIX: readonly number[];
export const ENUM_PREFIX: readonly number[];
export const AGENT_PREFIX: readonly number[];

@@ -3,0 +4,0 @@ export const ENTRY_PREFIX: readonly number[];

@@ -300,2 +300,3 @@ /******/ var __webpack_modules__ = ({

/* harmony export */ "ENTRY_PREFIX": () => (/* binding */ ENTRY_PREFIX),
/* harmony export */ "ENUM_PREFIX": () => (/* binding */ ENUM_PREFIX),
/* harmony export */ "EXTERNAL_PREFIX": () => (/* binding */ EXTERNAL_PREFIX),

@@ -307,2 +308,4 @@ /* harmony export */ "NETID_PREFIX": () => (/* binding */ NETID_PREFIX),

const BLANK_PREFIX = Object.freeze([132, 47, 190]); // hC--
const ENUM_PREFIX = Object.freeze([132, 47, 255]); // hC//
const AGENT_PREFIX = Object.freeze([132, 32, 36]); // hCAk

@@ -491,3 +494,5 @@ const ENTRY_PREFIX = Object.freeze([132, 33, 36]); // hCEk

/* harmony export */ "AnyDhtHash": () => (/* binding */ AnyDhtHash),
/* harmony export */ "AnyDhtHashTypes": () => (/* binding */ AnyDhtHashTypes),
/* harmony export */ "AnyLinkableHash": () => (/* binding */ AnyLinkableHash),
/* harmony export */ "AnyLinkableHashTypes": () => (/* binding */ AnyLinkableHashTypes),
/* harmony export */ "BadBase64Error": () => (/* reexport safe */ _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadBase64Error),

@@ -604,2 +609,5 @@ /* harmony export */ "BadChecksumError": () => (/* reexport safe */ _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadChecksumError),

constructor ( input, strict = true ) {
if ( input instanceof HoloHash )
input = input.bytes();
debug && log("New construction input (strict: %s): %s", strict, String(input) );

@@ -646,2 +654,3 @@ super(39);

// If the original constructor has a defined prefix...
if ( String(given_prefix) === String(this.constructor.PREFIX)

@@ -652,2 +661,8 @@ || String(_constants_js__WEBPACK_IMPORTED_MODULE_2__.BLANK_PREFIX) === String(given_prefix) ) {

}
// If the original constructor is an enum type...
else if ( String(_constants_js__WEBPACK_IMPORTED_MODULE_2__.ENUM_PREFIX) === String(this.constructor.PREFIX) ) {
given_dht_addr = input.slice(-4);
input = input.slice(3,-4);
}
// If the original constructor has no defined prefix...
else {

@@ -662,3 +677,6 @@ debug && log("Check if constructor is agnostic type: %s === %s", this.constructor.name, HoloHash.name );

throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadPrefixError(`Hash prefix did not match any HoloHash types: ${given_prefix}`);
const valid_types = Object.values( HoloHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadPrefixError(`Hash prefix did not match any HoloHash types: ${given_prefix}; valid types are ${valid_types}`);
}

@@ -856,2 +874,5 @@ }

toType ( type ) {
if ( typeof type !== "string" ) // Assume 'type' is one of the HoloHash classes
type = type.name;
if ( HoloHashTypes[type] === undefined )

@@ -887,2 +908,24 @@ throw new Error(`Invalid HoloHash type (${type}); must be one of: ${Object.keys(HoloHashTypes)}`);

class AnyLinkableHash extends HoloHash {
static PREFIX = _constants_js__WEBPACK_IMPORTED_MODULE_2__.ENUM_PREFIX;
constructor ( input, strict ) {
super( input, strict );
// If the original constructor is this class, we will return the specific type instead of this
if ( this.constructor.name === AnyLinkableHash.name ) {
if ( input instanceof HoloHash )
input = input.bytes();
let given_prefix = input.slice(0,3);
for (let type of Object.values( AnyLinkableHashTypes )) {
if ( String(type.PREFIX) === String(given_prefix) )
return new type( input.slice(3), strict );
};
const valid_types = Object.values( AnyLinkableHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadPrefixError(`Hash prefix did not match any AnyLinkableHash types: ${given_prefix}; valid types are ${valid_types}`);
}
}
}

@@ -892,2 +935,24 @@ (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__.set_tostringtag)( AnyLinkableHash, "AnyLinkableHash" );

class AnyDhtHash extends AnyLinkableHash {
static PREFIX = _constants_js__WEBPACK_IMPORTED_MODULE_2__.ENUM_PREFIX;
constructor ( input, strict ) {
super( input, strict );
// If the original constructor is this class, we will return the specific type instead of this
if ( this.constructor.name === AnyDhtHash.name ) {
if ( input instanceof HoloHash )
input = input.bytes();
let given_prefix = input.slice(0,3);
for (let type of Object.values( AnyDhtHashTypes )) {
if ( String(type.PREFIX) === String(given_prefix) )
return new type( input.slice(3), strict );
};
const valid_types = Object.values( AnyDhtHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.BadPrefixError(`Hash prefix did not match any AnyDhtHash types: ${given_prefix}; valid types are ${valid_types}`);
}
}
}

@@ -950,2 +1015,15 @@ (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__.set_tostringtag)( AnyDhtHash, "AnyDhtHash" );

const AnyLinkableHashTypes = {
AgentPubKey,
EntryHash,
ActionHash,
ExternalHash,
};
const AnyDhtHashTypes = {
AgentPubKey,
EntryHash,
ActionHash,
};
const base64 = {

@@ -980,4 +1058,8 @@ "encode": bytes_to_b64,

HoloHashTypes,
AnyDhtHash,
AnyDhtHashTypes,
AnyLinkableHash,
AnyLinkableHashTypes,

@@ -1011,3 +1093,5 @@ AgentPubKey,

var __webpack_exports__AnyDhtHash = __webpack_exports__.AnyDhtHash;
var __webpack_exports__AnyDhtHashTypes = __webpack_exports__.AnyDhtHashTypes;
var __webpack_exports__AnyLinkableHash = __webpack_exports__.AnyLinkableHash;
var __webpack_exports__AnyLinkableHashTypes = __webpack_exports__.AnyLinkableHashTypes;
var __webpack_exports__BadBase64Error = __webpack_exports__.BadBase64Error;

@@ -1032,4 +1116,4 @@ var __webpack_exports__BadChecksumError = __webpack_exports__.BadChecksumError;

var __webpack_exports__logging = __webpack_exports__.logging;
export { __webpack_exports__ActionHash as ActionHash, __webpack_exports__AgentPubKey as AgentPubKey, __webpack_exports__AnyDhtHash as AnyDhtHash, __webpack_exports__AnyLinkableHash as AnyLinkableHash, __webpack_exports__BadBase64Error as BadBase64Error, __webpack_exports__BadChecksumError as BadChecksumError, __webpack_exports__BadPrefixError as BadPrefixError, __webpack_exports__BadSizeError as BadSizeError, __webpack_exports__DhtOpHash as DhtOpHash, __webpack_exports__DnaHash as DnaHash, __webpack_exports__EntryHash as EntryHash, __webpack_exports__ExternalHash as ExternalHash, __webpack_exports__HoloHash as HoloHash, __webpack_exports__HoloHashError as HoloHashError, __webpack_exports__HoloHashTypes as HoloHashTypes, __webpack_exports__NetIdHash as NetIdHash, __webpack_exports__NoLeadingUError as NoLeadingUError, __webpack_exports__Warning as Warning, __webpack_exports__WasmHash as WasmHash, __webpack_exports__base64 as base64, __webpack_exports__bindNative as bindNative, __webpack_exports__default as default, __webpack_exports__logging as logging };
export { __webpack_exports__ActionHash as ActionHash, __webpack_exports__AgentPubKey as AgentPubKey, __webpack_exports__AnyDhtHash as AnyDhtHash, __webpack_exports__AnyDhtHashTypes as AnyDhtHashTypes, __webpack_exports__AnyLinkableHash as AnyLinkableHash, __webpack_exports__AnyLinkableHashTypes as AnyLinkableHashTypes, __webpack_exports__BadBase64Error as BadBase64Error, __webpack_exports__BadChecksumError as BadChecksumError, __webpack_exports__BadPrefixError as BadPrefixError, __webpack_exports__BadSizeError as BadSizeError, __webpack_exports__DhtOpHash as DhtOpHash, __webpack_exports__DnaHash as DnaHash, __webpack_exports__EntryHash as EntryHash, __webpack_exports__ExternalHash as ExternalHash, __webpack_exports__HoloHash as HoloHash, __webpack_exports__HoloHashError as HoloHashError, __webpack_exports__HoloHashTypes as HoloHashTypes, __webpack_exports__NetIdHash as NetIdHash, __webpack_exports__NoLeadingUError as NoLeadingUError, __webpack_exports__Warning as Warning, __webpack_exports__WasmHash as WasmHash, __webpack_exports__base64 as base64, __webpack_exports__bindNative as bindNative, __webpack_exports__default as default, __webpack_exports__logging as logging };
//# sourceMappingURL=holo-hash.js.map

2

dist/holo-hash.min.js

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

var e={29:e=>{let r=!1;function t(e,r){let t=new Uint8Array(r),s=0;for(;s<e.length;){let a=e.slice(s,s+r);s+=r;for(let e=0;e<r&&void 0!==a[e];e++)t[e]^=a[e]}return t}let s={xor_digest:t,logging(){r=!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 t(this,e)},enumerable:!1,writable:!1}),s},...s}}},r={};function t(s){var a=r[s];if(void 0!==a)return a.exports;var n=r[s]={exports:{}};return e[s](n,n.exports,t),n.exports}t.d=(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);var s={};(()=>{t.d(s,{z3:()=>ActionHash,DN:()=>AgentPubKey,aV:()=>AnyDhtHash,QD:()=>AnyLinkableHash,WY:()=>BadBase64Error,jW:()=>BadChecksumError,Q8:()=>BadPrefixError,Xr:()=>BadSizeError,lC:()=>DhtOpHash,BH:()=>DnaHash,g7:()=>EntryHash,hb:()=>ExternalHash,o_:()=>HoloHash,WH:()=>HoloHashError,h8:()=>N,uu:()=>NetIdHash,ZS:()=>NoLeadingUError,v3:()=>Warning,By:()=>WasmHash,US:()=>L,Js:()=>$,ZP:()=>C,PW:()=>T});var e=t(29);const r=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,r,t){let s=e[r]+e[t],a=e[r+1]+e[t+1];s>=4294967296&&a++,e[r]=s,e[r+1]=a}function o(e,r,t,s){let a=e[r]+t;t<0&&(a+=4294967296);let n=e[r+1]+s;a>=4294967296&&n++,e[r]=a,e[r+1]=n}function i(e,r){return e[r]^e[r+1]<<8^e[r+2]<<16^e[r+3]<<24}let h=new Uint32Array(32),l=new Uint32Array(32);function c(e,r,t,s,a,i){let c=l[a],H=l[a+1],u=l[i],d=l[i+1];n(h,e,r),o(h,e,c,H);let f=h[s]^h[e],y=h[s+1]^h[e+1];h[s]=y,h[s+1]=f,n(h,t,s),f=h[r]^h[t],y=h[r+1]^h[t+1],h[r]=f>>>24^y<<8,h[r+1]=y>>>24^f<<8,n(h,e,r),o(h,e,u,d),f=h[s]^h[e],y=h[s+1]^h[e+1],h[s]=f>>>16^y<<16,h[s+1]=y>>>16^f<<16,n(h,t,s),f=h[r]^h[t],y=h[r+1]^h[t+1],h[r]=y>>>31^f<<1,h[r+1]=f>>>31^y<<1}function H(e,t){let s=0;for(s=0;s<16;s++)h[s]=e.h[s],h[s+16]=r[s];for(h[24]=h[24]^e.t,h[25]=h[25]^e.t/4294967296,t&&(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,r){for(let t=0;t<r.length;t++)128===e.c&&(e.t+=e.c,H(e,!1),e.c=0),e.b[e.c++]=r[t]}function d(e,t,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,t){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(t&&t.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]=r[e];let a=t?t.length:0;return s.h[0]^=16842752^a<<8^e,t&&(u(s,t),s.c=128),s}(s,t);return u(a,e),function(e){for(e.t+=e.c;e.c<128;)e.b[e.c++]=0;H(e,!0);let r=new Uint8Array(e.outlen);for(let t=0;t<e.outlen;t++)r[t]=e.h[t>>2]>>8*(3&t);return r}(a)}const f=Object.freeze([132,47,190]),y=Object.freeze([132,32,36]),g=Object.freeze([132,33,36]),b=Object.freeze([132,34,36]),E=Object.freeze([132,36,36]),p=Object.freeze([132,41,36]),A=Object.freeze([132,42,36]),m=Object.freeze([132,45,36]),w=Object.freeze([132,47,36]);function x(e,r){Object.defineProperty(e,"name",{value:r||e.name}),Object.defineProperty(e.prototype,Symbol.toStringTag,{value:r||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}}}x(CustomError);class Warning extends CustomError{}x(Warning,"Warning");class HoloHashError extends CustomError{}x(HoloHashError,"HoloHashError");class NoLeadingUError extends HoloHashError{}x(NoLeadingUError,"NoLeadingUError");class BadBase64Error extends HoloHashError{}x(BadBase64Error,"BadBase64Error");class BadSizeError extends HoloHashError{}x(BadSizeError,"BadSizeError");class BadPrefixError extends HoloHashError{}x(BadPrefixError,"BadPrefixError");class BadChecksumError extends HoloHashError{}x(BadChecksumError,"BadChecksumError");const{xor_digest:B}=e,D=new Function("try {return this===global;}catch(e){return false;}")(),P=new RegExp("^[A-Za-z0-9+/]+={0,3}$");let S=!1;function U(e,...r){let t=(new Date).toISOString();console.log(`${t} [ src/index. ] INFO: ${e}`,...r)}function v(e){return S&&U("Encode URL-safe base64:",e.constructor.name,e.length),e.replace(/[+/]/g,(e=>"+"===e?"-":"_"))}function O(e){return S&&U("Decode URL-safe base64:",e),e.replace(/[-_]/g,(e=>"-"===e?"+":"/"))}function I(e){return(D?Buffer.from(e).toString("base64"):btoa(String.fromCharCode.apply(null,e))).replace(/=+$/,"")}function W(e){if(!1===P.test(e))throw new TypeError(`Invalid base64 character(s) in '${e}'`);return D?Buffer.from(e,"base64"):[].reduce.call(atob(e),((e,r,t)=>(e[t]=r.charCodeAt(0),e)),new Uint8Array(39))}function k(e){return S&&U("Encoding URL-safe base64 hash:",typeof e,e.length),v(I(e))}class HoloHash extends Uint8Array{constructor(e,r=!0){if(S&&U("New construction input (strict: %s): %s",r,String(e)),super(39),super.set(this.constructor.PREFIX||f),"string"==typeof e){if(e=e.trim(),!0===r&&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((t=e,S&&U("Decoding URL-safe base64 hash:",t),t.startsWith("u")&&(t=t.slice(1)),W(O(t))))}catch(r){throw S&&U("Failed to decode base64:",r),new BadBase64Error(`Failed to decode base64 input (${e})`)}S&&U("Decoded base64 bytes: %s",e.length)}var t;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&&(S&&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 t=e.slice(0,3);if(String(t)!==String(this.constructor.PREFIX)&&String(f)!==String(t)){if(S&&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(N))if(String(s.PREFIX)===String(t))return new s(e.slice(3),r);throw new BadPrefixError(`Hash prefix did not match any HoloHash types: ${t}`)}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){S&&U("Calculate DHT address from %s bytes",e.length);let r=d(e,null,16);return B(r,4)}(e);if(!0===r&&void 0!==s&&(S&&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,r){let t;return void 0!==r&&(t=r<0?this.buffer.byteLength-e+r:r-e),void 0!==e&&e<0&&(e=this.buffer.byteLength+e),new Uint8Array(this.buffer,e,t)}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 r="u"+k(this.bytes());if(e){let e=`${r.slice(0,4)}…${r.slice(-4)}`;return this.tag?`${this.constructor.name}( ${this.tag} [${e}] )`:`${this.constructor.name}( ${e} )`}return r}toJSON(){return this.toString()}toType(e){if(void 0===N[e])throw new Error(`Invalid HoloHash type (${e}); must be one of: ${Object.keys(N)}`);return S&&U("Retype (%s) to (%s)",this.constructor.name,e),new N[e](this.bytes(3))}retype(e){return this.toType(e)}hashType(){return this.constructor}}x(HoloHash,"HoloHash");class AnyLinkableHash extends HoloHash{}x(AnyLinkableHash,"AnyLinkableHash");class AnyDhtHash extends AnyLinkableHash{}x(AnyDhtHash,"AnyDhtHash");class ExternalHash extends AnyLinkableHash{static PREFIX=w}x(ExternalHash,"ExternalHash");class AgentPubKey extends AnyDhtHash{static PREFIX=y}x(AgentPubKey,"AgentPubKey");class EntryHash extends AnyDhtHash{static PREFIX=g}x(EntryHash,"EntryHash");class NetIdHash extends HoloHash{static PREFIX=b}x(NetIdHash,"NetIdHash");class DhtOpHash extends HoloHash{static PREFIX=E}x(DhtOpHash,"DhtOpHash");class ActionHash extends AnyDhtHash{static PREFIX=p}x(ActionHash,"ActionHash");class WasmHash extends HoloHash{static PREFIX=A}x(WasmHash,"WasmHash");class DnaHash extends HoloHash{static PREFIX=m}x(DnaHash,"DnaHash");const N={AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash},L={encode:I,decode:W,url_encode:v,url_decode:O};function $(){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 T(){S=!0}const C={HoloHash,HoloHashTypes:N,AnyDhtHash,AnyLinkableHash,AgentPubKey,EntryHash,NetIdHash,DhtOpHash,ActionHash,WasmHash,DnaHash,ExternalHash,Warning,HoloHashError,NoLeadingUError,BadBase64Error,BadSizeError,BadPrefixError,BadChecksumError,logging:T,base64:L,bindNative:$}})();var a=s.z3,n=s.DN,o=s.aV,i=s.QD,h=s.WY,l=s.jW,c=s.Q8,H=s.Xr,u=s.lC,d=s.BH,f=s.g7,y=s.hb,g=s.o_,b=s.WH,E=s.h8,p=s.uu,A=s.ZS,m=s.v3,w=s.By,x=s.US,B=s.Js,D=s.ZP,P=s.PW;export{a as ActionHash,n as AgentPubKey,o as AnyDhtHash,i as AnyLinkableHash,h as BadBase64Error,l as BadChecksumError,c as BadPrefixError,H as BadSizeError,u as DhtOpHash,d as DnaHash,f as EntryHash,y as ExternalHash,g as HoloHash,b as HoloHashError,E as HoloHashTypes,p as NetIdHash,A as NoLeadingUError,m as Warning,w as WasmHash,x as base64,B as bindNative,D as default,P 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:()=>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};
//# sourceMappingURL=holo-hash.min.js.map

@@ -116,2 +116,4 @@ export function bindNative(): void;

export class AnyLinkableHash extends HoloHash {
static PREFIX: readonly number[];
constructor(input: any, strict: any);
}

@@ -121,9 +123,6 @@ export class AnyDhtHash extends AnyLinkableHash {

export class ExternalHash extends AnyLinkableHash {
static PREFIX: readonly number[];
}
export class AgentPubKey extends AnyDhtHash {
static PREFIX: readonly number[];
}
export class EntryHash extends AnyDhtHash {
static PREFIX: readonly number[];
}

@@ -137,3 +136,2 @@ export class NetIdHash extends HoloHash {

export class ActionHash extends AnyDhtHash {
static PREFIX: readonly number[];
}

@@ -156,2 +154,13 @@ export class WasmHash extends HoloHash {

}
export namespace AnyLinkableHashTypes {
export { AgentPubKey };
export { EntryHash };
export { ActionHash };
export { ExternalHash };
}
export namespace AnyDhtHashTypes {
export { AgentPubKey };
export { EntryHash };
export { ActionHash };
}
export namespace base64 {

@@ -167,3 +176,5 @@ export { bytes_to_b64 as encode };

export { AnyDhtHash };
export { AnyDhtHashTypes };
export { AnyLinkableHash };
export { AnyLinkableHashTypes };
export { AgentPubKey };

@@ -170,0 +181,0 @@ export { EntryHash };

{
"name": "@spartan-hc/holo-hash",
"version": "0.5.4",
"version": "0.6.0",
"description": "A Javascript library for managing Holochain's HoloHash types",

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

export const BLANK_PREFIX = Object.freeze([132, 47, 190]); // hC--
export const ENUM_PREFIX = Object.freeze([132, 47, 255]); // hC//
export const AGENT_PREFIX = Object.freeze([132, 32, 36]); // hCAk

@@ -4,0 +6,0 @@ export const ENTRY_PREFIX = Object.freeze([132, 33, 36]); // hCEk

@@ -8,2 +8,3 @@

BLANK_PREFIX,
ENUM_PREFIX,
AGENT_PREFIX,

@@ -106,2 +107,5 @@ ENTRY_PREFIX,

constructor ( input, strict = true ) {
if ( input instanceof HoloHash )
input = input.bytes();
debug && log("New construction input (strict: %s): %s", strict, String(input) );

@@ -148,2 +152,3 @@ super(39);

// If the original constructor has a defined prefix...
if ( String(given_prefix) === String(this.constructor.PREFIX)

@@ -154,2 +159,8 @@ || String(BLANK_PREFIX) === String(given_prefix) ) {

}
// If the original constructor is an enum type...
else if ( String(ENUM_PREFIX) === String(this.constructor.PREFIX) ) {
given_dht_addr = input.slice(-4);
input = input.slice(3,-4);
}
// If the original constructor has no defined prefix...
else {

@@ -164,3 +175,6 @@ debug && log("Check if constructor is agnostic type: %s === %s", this.constructor.name, HoloHash.name );

throw new BadPrefixError(`Hash prefix did not match any HoloHash types: ${given_prefix}`);
const valid_types = Object.values( HoloHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new BadPrefixError(`Hash prefix did not match any HoloHash types: ${given_prefix}; valid types are ${valid_types}`);
}

@@ -358,2 +372,5 @@ }

toType ( type ) {
if ( typeof type !== "string" ) // Assume 'type' is one of the HoloHash classes
type = type.name;
if ( HoloHashTypes[type] === undefined )

@@ -389,2 +406,24 @@ throw new Error(`Invalid HoloHash type (${type}); must be one of: ${Object.keys(HoloHashTypes)}`);

export class AnyLinkableHash extends HoloHash {
static PREFIX = ENUM_PREFIX;
constructor ( input, strict ) {
super( input, strict );
// If the original constructor is this class, we will return the specific type instead of this
if ( this.constructor.name === AnyLinkableHash.name ) {
if ( input instanceof HoloHash )
input = input.bytes();
let given_prefix = input.slice(0,3);
for (let type of Object.values( AnyLinkableHashTypes )) {
if ( String(type.PREFIX) === String(given_prefix) )
return new type( input.slice(3), strict );
};
const valid_types = Object.values( AnyLinkableHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new BadPrefixError(`Hash prefix did not match any AnyLinkableHash types: ${given_prefix}; valid types are ${valid_types}`);
}
}
}

@@ -394,2 +433,24 @@ set_tostringtag( AnyLinkableHash, "AnyLinkableHash" );

export class AnyDhtHash extends AnyLinkableHash {
static PREFIX = ENUM_PREFIX;
constructor ( input, strict ) {
super( input, strict );
// If the original constructor is this class, we will return the specific type instead of this
if ( this.constructor.name === AnyDhtHash.name ) {
if ( input instanceof HoloHash )
input = input.bytes();
let given_prefix = input.slice(0,3);
for (let type of Object.values( AnyDhtHashTypes )) {
if ( String(type.PREFIX) === String(given_prefix) )
return new type( input.slice(3), strict );
};
const valid_types = Object.values( AnyDhtHashTypes )
.map( type => `${type.name} (${type.PREFIX})` )
.join(', ');
throw new BadPrefixError(`Hash prefix did not match any AnyDhtHash types: ${given_prefix}; valid types are ${valid_types}`);
}
}
}

@@ -452,2 +513,15 @@ set_tostringtag( AnyDhtHash, "AnyDhtHash" );

export const AnyLinkableHashTypes = {
AgentPubKey,
EntryHash,
ActionHash,
ExternalHash,
};
export const AnyDhtHashTypes = {
AgentPubKey,
EntryHash,
ActionHash,
};
export const base64 = {

@@ -490,4 +564,8 @@ "encode": bytes_to_b64,

HoloHashTypes,
AnyDhtHash,
AnyDhtHashTypes,
AnyLinkableHash,
AnyLinkableHashTypes,

@@ -494,0 +572,0 @@ AgentPubKey,

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