@xyo-network/core 2.57.5 → 2.57.6

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 (77) hide show
  1. package/dist/cjs/Hasher/Hasher.js +19 -3
  2. package/dist/cjs/Hasher/Hasher.js.map +1 -1
  3. package/dist/cjs/lib/Address/index.js +6 -0
  4. package/dist/cjs/lib/Address/index.js.map +1 -0
  5. package/dist/cjs/lib/Address/normalizeAddress.js +9 -0
  6. package/dist/cjs/lib/Address/normalizeAddress.js.map +1 -0
  7. package/dist/cjs/lib/Address/trimAddressPrefix.js +13 -0
  8. package/dist/cjs/lib/Address/trimAddressPrefix.js.map +1 -0
  9. package/dist/cjs/lib/index.js +1 -0
  10. package/dist/cjs/lib/index.js.map +1 -1
  11. package/dist/docs.json +879 -609
  12. package/dist/esm/Hasher/Hasher.js +17 -3
  13. package/dist/esm/Hasher/Hasher.js.map +1 -1
  14. package/dist/esm/lib/Address/index.js +3 -0
  15. package/dist/esm/lib/Address/index.js.map +1 -0
  16. package/dist/esm/lib/Address/normalizeAddress.js +5 -0
  17. package/dist/esm/lib/Address/normalizeAddress.js.map +1 -0
  18. package/dist/esm/lib/Address/trimAddressPrefix.js +9 -0
  19. package/dist/esm/lib/Address/trimAddressPrefix.js.map +1 -0
  20. package/dist/esm/lib/index.js +1 -0
  21. package/dist/esm/lib/index.js.map +1 -1
  22. package/dist/types/Hasher/Hasher.d.ts +4 -1
  23. package/dist/types/Hasher/Hasher.d.ts.map +1 -1
  24. package/dist/types/lib/Address/index.d.ts +3 -0
  25. package/dist/types/lib/Address/index.d.ts.map +1 -0
  26. package/dist/types/lib/Address/normalizeAddress.d.ts +2 -0
  27. package/dist/types/lib/Address/normalizeAddress.d.ts.map +1 -0
  28. package/dist/types/lib/Address/trimAddressPrefix.d.ts +3 -0
  29. package/dist/types/lib/Address/trimAddressPrefix.d.ts.map +1 -0
  30. package/dist/types/lib/index.d.ts +1 -0
  31. package/dist/types/lib/index.d.ts.map +1 -1
  32. package/docs/assets/search.js +1 -1
  33. package/docs/classes/Base.html +8 -5
  34. package/docs/classes/Hasher.html +50 -23
  35. package/docs/classes/ObjectWrapper.html +7 -4
  36. package/docs/classes/XyoAbstractData.html +12 -9
  37. package/docs/classes/XyoData.html +17 -14
  38. package/docs/classes/XyoObjectWrapper.html +7 -4
  39. package/docs/classes/XyoValidatorBase.html +8 -5
  40. package/docs/functions/deepBy.html +4 -1
  41. package/docs/functions/deepOmitUnderscoreFields.html +4 -1
  42. package/docs/functions/deepPickUnderscoreFields.html +4 -1
  43. package/docs/functions/dumpErrors.html +4 -1
  44. package/docs/functions/isBrowser.html +4 -1
  45. package/docs/functions/normalizeAddress.html +79 -0
  46. package/docs/functions/removeEmptyFields.html +4 -1
  47. package/docs/functions/sortFields.html +4 -1
  48. package/docs/functions/toUint8Array.html +4 -1
  49. package/docs/functions/toUint8ArrayOptional.html +4 -1
  50. package/docs/functions/trimAddressPrefix.html +79 -0
  51. package/docs/functions/uuid.html +4 -1
  52. package/docs/index.html +3 -0
  53. package/docs/interfaces/Logger.html +9 -6
  54. package/docs/interfaces/Validator.html +5 -2
  55. package/docs/modules.html +9 -0
  56. package/docs/types/AnyObject.html +4 -1
  57. package/docs/types/BaseParams.html +4 -1
  58. package/docs/types/BaseParamsFields.html +4 -1
  59. package/docs/types/DataLike.html +4 -1
  60. package/docs/types/EmptyObject.html +4 -1
  61. package/docs/types/LogFunction.html +4 -1
  62. package/docs/types/StringKeyObject.html +4 -1
  63. package/docs/types/WithAdditional.html +4 -1
  64. package/docs/variables/addressPrefix.html +70 -0
  65. package/package.json +8 -7
  66. package/src/Hasher/Hasher.ts +18 -3
  67. package/src/lib/Address/index.ts +2 -0
  68. package/src/lib/Address/normalizeAddress.ts +5 -0
  69. package/src/lib/Address/trimAddressPrefix.ts +10 -0
  70. package/src/lib/index.ts +1 -0
  71. package/dist/cjs/lib/exists.js +0 -8
  72. package/dist/cjs/lib/exists.js.map +0 -1
  73. package/dist/esm/lib/exists.js +0 -4
  74. package/dist/esm/lib/exists.js.map +0 -1
  75. package/dist/types/lib/exists.d.ts +0 -2
  76. package/dist/types/lib/exists.d.ts.map +0 -1
  77. package/src/lib/exists.ts +0 -3
package/package.json CHANGED
@@ -11,10 +11,11 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@scure/base": "^1.1.1",
14
- "@xylabs/assert": "^2.7.6",
15
- "@xylabs/bignumber": "^2.7.6",
16
- "@xylabs/buffer": "^2.7.6",
17
- "@xyo-network/typeof": "^2.57.5",
14
+ "@xylabs/assert": "^2.8.1",
15
+ "@xylabs/bignumber": "^2.8.1",
16
+ "@xylabs/buffer": "^2.8.1",
17
+ "@xyo-network/typeof": "^2.57.6",
18
+ "hash-wasm": "^4.9.0",
18
19
  "keccak256": "^1.0.6",
19
20
  "lodash": "^4.17.21",
20
21
  "sha.js": "^2.4.11",
@@ -25,8 +26,8 @@
25
26
  "@types/lodash": "^4.14.194",
26
27
  "@types/sha.js": "^2.4.0",
27
28
  "@types/uuid": "^9.0.1",
28
- "@xylabs/ts-scripts-yarn3": "^2.17.12",
29
- "@xylabs/tsconfig": "^2.17.12",
29
+ "@xylabs/ts-scripts-yarn3": "^2.17.13",
30
+ "@xylabs/tsconfig": "^2.17.13",
30
31
  "typescript": "^5.0.4"
31
32
  },
32
33
  "browser": "dist/esm/index.js",
@@ -62,5 +63,5 @@
62
63
  },
63
64
  "sideEffects": false,
64
65
  "types": "dist/types/index.d.ts",
65
- "version": "2.57.5"
66
+ "version": "2.57.6"
66
67
  }
@@ -1,3 +1,4 @@
1
+ import { sha256 } from 'hash-wasm'
1
2
  import shajs from 'sha.js'
2
3
 
3
4
  import { AnyObject, ObjectWrapper } from '../lib'
@@ -6,6 +7,9 @@ import { deepOmitUnderscoreFields } from './removeFields'
6
7
  import { sortFields } from './sortFields'
7
8
 
8
9
  export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
10
+ static allowWasm = true
11
+ static wasmSupported = true
12
+
9
13
  get hash() {
10
14
  return Hasher.hash(this.obj)
11
15
  }
@@ -19,7 +23,18 @@ export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
19
23
  }
20
24
 
21
25
  static hash<T extends AnyObject>(obj: T) {
22
- return this.sortedHashData(obj).toString('hex')
26
+ return shajs('sha256').update(this.stringify(obj)).digest().toString('hex')
27
+ }
28
+
29
+ static async hashAsync<T extends AnyObject>(obj: T): Promise<string> {
30
+ if (this.allowWasm && this.wasmSupported) {
31
+ try {
32
+ return await sha256(this.stringify(obj))
33
+ } catch (ex) {
34
+ this.wasmSupported = false
35
+ }
36
+ }
37
+ return this.hash(obj)
23
38
  }
24
39
 
25
40
  static hashFields<T extends AnyObject>(obj: T) {
@@ -30,7 +45,7 @@ export class Hasher<T extends AnyObject = AnyObject> extends ObjectWrapper<T> {
30
45
  return JSON.stringify(sortFields(this.hashFields(obj)))
31
46
  }
32
47
 
33
- private static sortedHashData<T extends AnyObject>(obj: T) {
34
- return shajs('sha256').update(this.stringify(obj)).digest()
48
+ hashAsync() {
49
+ return Hasher.hashAsync(this.obj)
35
50
  }
36
51
  }
@@ -0,0 +1,2 @@
1
+ export * from './normalizeAddress'
2
+ export * from './trimAddressPrefix'
@@ -0,0 +1,5 @@
1
+ import { trimAddressPrefix } from './trimAddressPrefix'
2
+
3
+ export const normalizeAddress = (address: string) => {
4
+ return trimAddressPrefix(address.toLowerCase())
5
+ }
@@ -0,0 +1,10 @@
1
+ export const addressPrefix = '0x'
2
+
3
+ // NOTE: To prevent calling `.length` on every invocation, we cache the length
4
+ // but do want to tether it to the length of the actual prefix so it's not some
5
+ // magic number.
6
+ const addressPrefixLength = addressPrefix.length
7
+
8
+ export const trimAddressPrefix = (address: string) => {
9
+ return address.toLowerCase().startsWith(addressPrefix) ? address.substring(addressPrefixLength) : address
10
+ }
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './Address'
1
2
  export * from './AnyObject'
2
3
  export * from './Base'
3
4
  export * from './dumpErrors'
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exists = void 0;
4
- const exists = (x) => {
5
- return !!x;
6
- };
7
- exports.exists = exists;
8
- //# sourceMappingURL=exists.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exists.js","sourceRoot":"","sources":["../../../src/lib/exists.ts"],"names":[],"mappings":";;;AAAO,MAAM,MAAM,GAAG,CAAI,CAAuB,EAAU,EAAE;IAC3D,OAAO,CAAC,CAAC,CAAC,CAAA;AACZ,CAAC,CAAA;AAFY,QAAA,MAAM,UAElB"}
@@ -1,4 +0,0 @@
1
- export const exists = (x) => {
2
- return !!x;
3
- };
4
- //# sourceMappingURL=exists.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exists.js","sourceRoot":"","sources":["../../../src/lib/exists.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,CAAuB,EAAU,EAAE;IAC3D,OAAO,CAAC,CAAC,CAAC,CAAA;AACZ,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const exists: <T>(x: T | null | undefined) => x is T;
2
- //# sourceMappingURL=exists.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exists.d.ts","sourceRoot":"","sources":["../../../src/lib/exists.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,wCAElB,CAAA"}
package/src/lib/exists.ts DELETED
@@ -1,3 +0,0 @@
1
- export const exists = <T>(x: T | undefined | null): x is T => {
2
- return !!x
3
- }