@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.
Files changed (46) hide show
  1. package/dist/cjs/Hasher/Hasher.js +21 -14
  2. package/dist/cjs/Hasher/Hasher.js.map +1 -1
  3. package/dist/docs.json +3181 -1188
  4. package/dist/esm/Hasher/Hasher.js +17 -11
  5. package/dist/esm/Hasher/Hasher.js.map +1 -1
  6. package/dist/types/Hasher/Hasher.d.ts +6 -2
  7. package/dist/types/Hasher/Hasher.d.ts.map +1 -1
  8. package/docs/assets/search.js +1 -1
  9. package/docs/classes/Base.html +7 -6
  10. package/docs/classes/Hasher.html +153 -111
  11. package/docs/classes/ObjectWrapper.html +7 -6
  12. package/docs/classes/PayloadHasher.html +441 -0
  13. package/docs/classes/WasmSupport.html +22 -21
  14. package/docs/classes/XyoAbstractData.html +11 -10
  15. package/docs/classes/XyoData.html +16 -15
  16. package/docs/classes/XyoObjectWrapper.html +6 -5
  17. package/docs/classes/XyoValidatorBase.html +7 -6
  18. package/docs/functions/deepBy.html +3 -2
  19. package/docs/functions/deepOmitUnderscoreFields.html +3 -2
  20. package/docs/functions/deepPickUnderscoreFields.html +3 -2
  21. package/docs/functions/dumpErrors.html +3 -2
  22. package/docs/functions/isBrowser.html +3 -2
  23. package/docs/functions/normalizeAddress.html +3 -2
  24. package/docs/functions/removeEmptyFields.html +3 -2
  25. package/docs/functions/sortFields.html +3 -2
  26. package/docs/functions/toUint8Array.html +3 -2
  27. package/docs/functions/toUint8ArrayOptional.html +3 -2
  28. package/docs/functions/trimAddressPrefix.html +3 -2
  29. package/docs/functions/uuid.html +3 -2
  30. package/docs/index.html +2 -1
  31. package/docs/interfaces/Logger.html +8 -7
  32. package/docs/interfaces/Validator.html +4 -3
  33. package/docs/modules.html +4 -2
  34. package/docs/types/AnyObject.html +3 -2
  35. package/docs/types/BaseParams.html +3 -2
  36. package/docs/types/BaseParamsFields.html +3 -2
  37. package/docs/types/DataLike.html +3 -2
  38. package/docs/types/EmptyObject.html +3 -2
  39. package/docs/types/LogFunction.html +3 -2
  40. package/docs/types/StringKeyObject.html +3 -2
  41. package/docs/types/WasmFeature.html +3 -2
  42. package/docs/types/WithAdditional.html +3 -2
  43. package/docs/variables/WasmFeatureDetectors.html +3 -2
  44. package/docs/variables/addressPrefix.html +3 -2
  45. package/package.json +3 -2
  46. package/src/Hasher/Hasher.ts +18 -11
@@ -9,22 +9,22 @@ import { sortFields } from './sortFields'
9
9
 
10
10
  const wasmSupportStatic = new WasmSupport(['bigInt'])
11
11
 
12
- export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
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 Hasher.hash(this.obj)
19
+ return PayloadHasher.hash(this.obj)
20
20
  }
21
21
 
22
22
  get hashFields() {
23
- return Hasher.hashFields(this.obj)
23
+ return PayloadHasher.hashFields(this.obj)
24
24
  }
25
25
 
26
26
  get stringified() {
27
- return Hasher.stringify(this.obj)
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 Hasher.wasmInitialized
51
- if (Hasher.wasmSupport.canUseWasm) {
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
- Hasher.wasmSupport.allowWasm = false
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 Hasher.hashAsync(obj)]))
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 Hasher.hashAsync(obj)] = obj)))
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 Hasher.hashAsync(this.obj)
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> {}