@xyo-network/core 2.60.0-rc.1 → 2.60.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Hasher/Hasher.js +21 -14
- package/dist/cjs/Hasher/Hasher.js.map +1 -1
- package/dist/docs.json +3181 -1188
- package/dist/esm/Hasher/Hasher.js +17 -11
- package/dist/esm/Hasher/Hasher.js.map +1 -1
- package/dist/types/Hasher/Hasher.d.ts +6 -2
- package/dist/types/Hasher/Hasher.d.ts.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Base.html +7 -6
- package/docs/classes/Hasher.html +153 -111
- package/docs/classes/ObjectWrapper.html +7 -6
- package/docs/classes/PayloadHasher.html +441 -0
- package/docs/classes/WasmSupport.html +22 -21
- package/docs/classes/XyoAbstractData.html +11 -10
- package/docs/classes/XyoData.html +16 -15
- package/docs/classes/XyoObjectWrapper.html +6 -5
- package/docs/classes/XyoValidatorBase.html +7 -6
- package/docs/functions/deepBy.html +3 -2
- package/docs/functions/deepOmitUnderscoreFields.html +3 -2
- package/docs/functions/deepPickUnderscoreFields.html +3 -2
- package/docs/functions/dumpErrors.html +3 -2
- package/docs/functions/isBrowser.html +3 -2
- package/docs/functions/normalizeAddress.html +3 -2
- package/docs/functions/removeEmptyFields.html +3 -2
- package/docs/functions/sortFields.html +3 -2
- package/docs/functions/toUint8Array.html +3 -2
- package/docs/functions/toUint8ArrayOptional.html +3 -2
- package/docs/functions/trimAddressPrefix.html +3 -2
- package/docs/functions/uuid.html +3 -2
- package/docs/index.html +2 -1
- package/docs/interfaces/Logger.html +8 -7
- package/docs/interfaces/Validator.html +4 -3
- package/docs/modules.html +4 -2
- package/docs/types/AnyObject.html +3 -2
- package/docs/types/BaseParams.html +3 -2
- package/docs/types/BaseParamsFields.html +3 -2
- package/docs/types/DataLike.html +3 -2
- package/docs/types/EmptyObject.html +3 -2
- package/docs/types/LogFunction.html +3 -2
- package/docs/types/StringKeyObject.html +3 -2
- package/docs/types/WasmFeature.html +3 -2
- package/docs/types/WithAdditional.html +3 -2
- package/docs/variables/WasmFeatureDetectors.html +3 -2
- package/docs/variables/addressPrefix.html +3 -2
- package/package.json +3 -2
- package/src/Hasher/Hasher.ts +18 -11
package/src/Hasher/Hasher.ts
CHANGED
|
@@ -9,22 +9,22 @@ import { sortFields } from './sortFields'
|
|
|
9
9
|
|
|
10
10
|
const wasmSupportStatic = new WasmSupport(['bigInt'])
|
|
11
11
|
|
|
12
|
-
export class
|
|
12
|
+
export class PayloadHasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
|
|
13
13
|
static readonly wasmInitialized = wasmSupportStatic.initialize()
|
|
14
14
|
static readonly wasmSupport = wasmSupportStatic
|
|
15
15
|
|
|
16
16
|
/** @deprecated use hashAsync instead */
|
|
17
17
|
get hash() {
|
|
18
18
|
// eslint-disable-next-line deprecation/deprecation
|
|
19
|
-
return
|
|
19
|
+
return PayloadHasher.hash(this.obj)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
get hashFields() {
|
|
23
|
-
return
|
|
23
|
+
return PayloadHasher.hashFields(this.obj)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
get stringified() {
|
|
27
|
-
return
|
|
27
|
+
return PayloadHasher.stringify(this.obj)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
static async filterExclude<T extends AnyObject>(objs: T[] = [], hash: string[] | string): Promise<T[]> {
|
|
@@ -41,19 +41,19 @@ export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
|
|
|
41
41
|
return (await this.hashPairs(objs)).find(([_, objHash]) => objHash === hash)?.[0]
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** @deprecated use hashAsync instead */
|
|
44
|
+
/** @deprecated use hashSync or hashAsync instead */
|
|
45
45
|
static hash<T extends AnyObject>(obj: T) {
|
|
46
46
|
return shajs('sha256').update(this.stringify(obj)).digest().toString('hex')
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
static async hashAsync<T extends AnyObject>(obj: T): Promise<string> {
|
|
50
|
-
await
|
|
51
|
-
if (
|
|
50
|
+
await PayloadHasher.wasmInitialized
|
|
51
|
+
if (PayloadHasher.wasmSupport.canUseWasm) {
|
|
52
52
|
const stringToHash = this.stringify(obj)
|
|
53
53
|
try {
|
|
54
54
|
return await sha256(stringToHash)
|
|
55
55
|
} catch (ex) {
|
|
56
|
-
|
|
56
|
+
PayloadHasher.wasmSupport.allowWasm = false
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
// eslint-disable-next-line deprecation/deprecation
|
|
@@ -65,7 +65,11 @@ export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
static async hashPairs<T extends AnyObject>(objs: T[]): Promise<[T, string][]> {
|
|
68
|
-
return await Promise.all(objs.map<Promise<[T, string]>>(async (obj) => [obj, await
|
|
68
|
+
return await Promise.all(objs.map<Promise<[T, string]>>(async (obj) => [obj, await PayloadHasher.hashAsync(obj)]))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static hashSync<T extends AnyObject>(obj: T) {
|
|
72
|
+
return shajs('sha256').update(this.stringify(obj)).digest().toString('hex')
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
static async hashes<T extends AnyObject>(objs: T[]) {
|
|
@@ -78,11 +82,14 @@ export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
|
|
|
78
82
|
|
|
79
83
|
static async toMap<T extends AnyObject>(objs: T[]): Promise<Record<string, T>> {
|
|
80
84
|
const result: Record<string, T> = {}
|
|
81
|
-
await Promise.all(objs.map(async (obj) => (result[await
|
|
85
|
+
await Promise.all(objs.map(async (obj) => (result[await PayloadHasher.hashAsync(obj)] = obj)))
|
|
82
86
|
return result
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
async hashAsync() {
|
|
86
|
-
return await
|
|
90
|
+
return await PayloadHasher.hashAsync(this.obj)
|
|
87
91
|
}
|
|
88
92
|
}
|
|
93
|
+
|
|
94
|
+
/** @deprecated use PayloadHasher instead */
|
|
95
|
+
export class Hasher<T extends AnyObject = AnyObject> extends PayloadHasher<T> {}
|