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

@xyo-network/hash

Package Overview
Dependencies
Maintainers
7
Versions
429
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xyo-network/hash - npm Package Compare versions

Comparing version 2.76.1 to 2.76.2

16

dist/browser/index.js
// src/PayloadHasher.ts
import { base16 } from "@scure/base";
import { Buffer } from "@xylabs/buffer";
import { ObjectWrapper } from "@xyo-network/object";
import { WasmSupport } from "@xyo-network/wasm";
import { subtle } from "crypto";
import { sha256 } from "hash-wasm";

@@ -60,2 +63,3 @@ import shajs from "sha.js";

var PayloadHasher = class _PayloadHasher extends ObjectWrapper {
static allowSubtle = true;
static wasmInitialized = wasmSupportStatic.initialize();

@@ -75,2 +79,14 @@ static wasmSupport = wasmSupportStatic;

static async hashAsync(obj) {
if (_PayloadHasher.allowSubtle) {
try {
const enc = new TextEncoder();
const stringToHash = this.stringifyHashFields(obj);
const b = enc.encode(stringToHash);
const hashArray = await subtle.digest("SHA-256", b);
return base16.encode(Buffer.from(hashArray)).toLowerCase();
} catch (ex) {
console.log("Setting allowSubtle to false");
_PayloadHasher.allowSubtle = false;
}
}
await this.wasmInitialized;

@@ -77,0 +93,0 @@ if (this.wasmSupport.canUseWasm) {

1

dist/browser/PayloadHasher.d.ts

@@ -5,2 +5,3 @@ import { AnyObject, ObjectWrapper } from '@xyo-network/object';

export declare class PayloadHasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
static allowSubtle: boolean;
static readonly wasmInitialized: Promise<void>;

@@ -7,0 +8,0 @@ static readonly wasmSupport: WasmSupport;

@@ -43,4 +43,7 @@ "use strict";

// src/PayloadHasher.ts
var import_base = require("@scure/base");
var import_buffer = require("@xylabs/buffer");
var import_object2 = require("@xyo-network/object");
var import_wasm = require("@xyo-network/wasm");
var import_crypto = require("crypto");
var import_hash_wasm = require("hash-wasm");

@@ -102,2 +105,3 @@ var import_sha = __toESM(require("sha.js"));

var PayloadHasher = class _PayloadHasher extends import_object2.ObjectWrapper {
static allowSubtle = true;
static wasmInitialized = wasmSupportStatic.initialize();

@@ -120,2 +124,14 @@ static wasmSupport = wasmSupportStatic;

static async hashAsync(obj) {
if (_PayloadHasher.allowSubtle) {
try {
const enc = new TextEncoder();
const stringToHash = this.stringifyHashFields(obj);
const b = enc.encode(stringToHash);
const hashArray = await import_crypto.subtle.digest("SHA-256", b);
return import_base.base16.encode(import_buffer.Buffer.from(hashArray)).toLowerCase();
} catch (ex) {
console.log("Setting allowSubtle to false");
_PayloadHasher.allowSubtle = false;
}
}
await this.wasmInitialized;

@@ -122,0 +138,0 @@ if (this.wasmSupport.canUseWasm) {

@@ -5,2 +5,3 @@ import { AnyObject, ObjectWrapper } from '@xyo-network/object';

export declare class PayloadHasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
static allowSubtle: boolean;
static readonly wasmInitialized: Promise<void>;

@@ -7,0 +8,0 @@ static readonly wasmSupport: WasmSupport;

10

package.json

@@ -13,6 +13,8 @@ {

"dependencies": {
"@scure/base": "^1.1.3",
"@xylabs/buffer": "^2.12.28",
"@xylabs/lodash": "^2.12.28",
"@xyo-network/object": "~2.76.1",
"@xyo-network/typeof": "~2.76.1",
"@xyo-network/wasm": "~2.76.1",
"@xyo-network/object": "~2.76.2",
"@xyo-network/typeof": "~2.76.2",
"@xyo-network/wasm": "~2.76.2",
"hash-wasm": "^4.10.0",

@@ -67,3 +69,3 @@ "sha.js": "^2.4.11"

"types": "dist/node/index.d.ts",
"version": "2.76.1"
"version": "2.76.2"
}

@@ -0,3 +1,6 @@

import { base16 } from '@scure/base'
import { Buffer } from '@xylabs/buffer'
import { AnyObject, ObjectWrapper } from '@xyo-network/object'
import { WasmSupport } from '@xyo-network/wasm'
import { subtle } from 'crypto'
import { sha256 } from 'hash-wasm'

@@ -14,2 +17,3 @@ import shajs from 'sha.js'

export class PayloadHasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
static allowSubtle = true
static readonly wasmInitialized = wasmSupportStatic.initialize()

@@ -33,2 +37,15 @@ static readonly wasmSupport = wasmSupportStatic

static async hashAsync<T extends AnyObject>(obj: T): Promise<Hash> {
if (PayloadHasher.allowSubtle) {
try {
const enc = new TextEncoder()
const stringToHash = this.stringifyHashFields(obj)
const b = enc.encode(stringToHash)
const hashArray = await subtle.digest('SHA-256', b)
return base16.encode(Buffer.from(hashArray)).toLowerCase()
} catch (ex) {
console.log('Setting allowSubtle to false')
PayloadHasher.allowSubtle = false
}
}
await this.wasmInitialized

@@ -35,0 +52,0 @@ if (this.wasmSupport.canUseWasm) {

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

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

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

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