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

@guildofweavers/merkle

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guildofweavers/merkle - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

38

lib/hash/index.js

@@ -6,18 +6,11 @@ "use strict";

function createHash(algorithm, useWasmOrOptions) {
if (useWasmOrOptions) {
const wasmOptions = (typeof useWasmOrOptions === 'boolean')
? {}
: useWasmOrOptions;
switch (algorithm) {
case 'blake2s256': {
return new WasmBlake2s_1.WasmBlake2s(wasmOptions.memory);
}
default: {
throw new Error(`WASM-optimization for ${algorithm} hash is not supported`);
}
}
if (!useWasmOrOptions) {
return new JsHash_1.JsHash(algorithm);
}
else {
const HashCtr = getHashConstructor(algorithm);
if (!HashCtr) {
return new JsHash_1.JsHash(algorithm);
}
const wasmOptions = normalizeWasmOptions(useWasmOrOptions);
return new HashCtr(wasmOptions);
}

@@ -36,2 +29,21 @@ exports.createHash = createHash;

exports.isWasmOptimized = isWasmOptimized;
// HELPER FUNCTIONS
// ================================================================================================
function getHashConstructor(algorithm) {
switch (algorithm) {
case 'blake2s256': {
return WasmBlake2s_1.WasmBlake2s;
}
default: {
return undefined;
}
}
}
function normalizeWasmOptions(useWasmOrOptions) {
if (typeof useWasmOrOptions === 'boolean') {
return { memory: new WebAssembly.Memory({ initial: 10 }) };
}
const memory = useWasmOrOptions.memory || new WebAssembly.Memory({ initial: 10 });
return { memory };
}
//# sourceMappingURL=index.js.map

@@ -24,2 +24,5 @@ "use strict";

}
get isOptimized() {
return false;
}
// PUBLIC METHODS

@@ -26,0 +29,0 @@ // --------------------------------------------------------------------------------------------

@@ -13,4 +13,4 @@ "use strict";

// --------------------------------------------------------------------------------------------
constructor(memory) {
this.wasm = assembly_1.instantiateBlake2s(memory);
constructor(options) {
this.wasm = assembly_1.instantiateBlake2s(options.memory);
this.iRef = this.wasm.getInputsRef();

@@ -28,2 +28,5 @@ this.oRef = this.wasm.getOutputRef();

}
get isOptimized() {
return true;
}
// PUBLIC METHODS

@@ -30,0 +33,0 @@ // --------------------------------------------------------------------------------------------

@@ -8,5 +8,5 @@ declare module '@guildofweavers/merkle' {

/**
* Creates a Hash object for the specified algorithm; if useWasm is set to true, will use a
* WebAssembly-optimized version of the algorithm. If WASM-optimization is not available for
* the specified algorithm, throws an error.
* Creates a Hash object for the specified algorithm. If useWasm is set to true, will try to
* instantiate a WebAssembly-optimized version of the algorithm. If WASM optimization is not
* available for the specified algorithm, Node's native implementation will be used.
*/

@@ -16,5 +16,5 @@ export function createHash(algorithm: HashAlgorithm, useWasm?: boolean): Hash;

/**
* Creates a WebAssembly-optimized Hash object for the specified algorithm and passes provided
* options to it. If WASM-optimization is not available for the specified algorithm, throws
* an error.
* Tries to create a WebAssembly-optimized Hash object for the specified algorithm and pass
* the provided options to it. If WASM optimization is not available for the specified algorithm,
* Node's native implementation will be used.
*/

@@ -30,2 +30,3 @@ export function createHash(algorithm: HashAlgorithm, options: Partial<WasmOptions>): Hash;

readonly digestSize : number;
readonly isOptimized: boolean;

@@ -32,0 +33,0 @@ /** Hashes the provided value */

{
"name": "@guildofweavers/merkle",
"version": "0.3.2",
"version": "0.3.3",
"description": "Merkle tree and other data structures",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -89,6 +89,6 @@ # Merkle

* **createHash**(algorithm: `string`, useWasm?: `boolean`): `Hash`<br />
Creates a Hash object for the specified `algorithm`. If the optional `useWasm` parameter is set to _true_, will use a WebAssembly-optimized version of the algorithm. If WASM-optimization is not available for the specified algorithm, throws an error.
Creates a Hash object for the specified `algorithm`. If `useWasm` is set to true, will try to instantiate a WebAssembly-optimized version of the algorithm. If WASM optimization is not available for the specified algorithm, Node's native implementation will be used.
* **createHash**(algorithm: `string`, wasmOptions: `WasmOptions`): `Hash`<br />
Creates a WebAssembly-optimized Hash object for the specified `algorithm` and passes the provided options to it. If WASM-optimization is not available for the specified algorithm, throws an error.
Tries to create a WebAssembly-optimized Hash object for the specified `algorithm` and pass the provided options to it. If WASM optimization is not available for the specified algorithm, Node's native implementation will be used.

@@ -95,0 +95,0 @@ Currently, the following hash algorithms are supported:

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