@xyo-network/hash
Advanced tools
Comparing version 2.76.1 to 2.76.2
// 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) { |
@@ -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; |
@@ -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
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
140153
810
8
+ Added@scure/base@^1.1.3
+ Added@xylabs/buffer@^2.12.28
+ Added@scure/base@1.1.9(transitive)
+ Added@xylabs/buffer@2.15.1(transitive)
+ Added@xylabs/platform@2.15.1(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedieee754@1.2.1(transitive)
Updated@xyo-network/object@~2.76.2
Updated@xyo-network/typeof@~2.76.2
Updated@xyo-network/wasm@~2.76.2