@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.
- package/dist/cjs/Hasher/Hasher.js +19 -3
- package/dist/cjs/Hasher/Hasher.js.map +1 -1
- package/dist/cjs/lib/Address/index.js +6 -0
- package/dist/cjs/lib/Address/index.js.map +1 -0
- package/dist/cjs/lib/Address/normalizeAddress.js +9 -0
- package/dist/cjs/lib/Address/normalizeAddress.js.map +1 -0
- package/dist/cjs/lib/Address/trimAddressPrefix.js +13 -0
- package/dist/cjs/lib/Address/trimAddressPrefix.js.map +1 -0
- package/dist/cjs/lib/index.js +1 -0
- package/dist/cjs/lib/index.js.map +1 -1
- package/dist/docs.json +879 -609
- package/dist/esm/Hasher/Hasher.js +17 -3
- package/dist/esm/Hasher/Hasher.js.map +1 -1
- package/dist/esm/lib/Address/index.js +3 -0
- package/dist/esm/lib/Address/index.js.map +1 -0
- package/dist/esm/lib/Address/normalizeAddress.js +5 -0
- package/dist/esm/lib/Address/normalizeAddress.js.map +1 -0
- package/dist/esm/lib/Address/trimAddressPrefix.js +9 -0
- package/dist/esm/lib/Address/trimAddressPrefix.js.map +1 -0
- package/dist/esm/lib/index.js +1 -0
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/types/Hasher/Hasher.d.ts +4 -1
- package/dist/types/Hasher/Hasher.d.ts.map +1 -1
- package/dist/types/lib/Address/index.d.ts +3 -0
- package/dist/types/lib/Address/index.d.ts.map +1 -0
- package/dist/types/lib/Address/normalizeAddress.d.ts +2 -0
- package/dist/types/lib/Address/normalizeAddress.d.ts.map +1 -0
- package/dist/types/lib/Address/trimAddressPrefix.d.ts +3 -0
- package/dist/types/lib/Address/trimAddressPrefix.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +1 -0
- package/dist/types/lib/index.d.ts.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Base.html +8 -5
- package/docs/classes/Hasher.html +50 -23
- package/docs/classes/ObjectWrapper.html +7 -4
- package/docs/classes/XyoAbstractData.html +12 -9
- package/docs/classes/XyoData.html +17 -14
- package/docs/classes/XyoObjectWrapper.html +7 -4
- package/docs/classes/XyoValidatorBase.html +8 -5
- package/docs/functions/deepBy.html +4 -1
- package/docs/functions/deepOmitUnderscoreFields.html +4 -1
- package/docs/functions/deepPickUnderscoreFields.html +4 -1
- package/docs/functions/dumpErrors.html +4 -1
- package/docs/functions/isBrowser.html +4 -1
- package/docs/functions/normalizeAddress.html +79 -0
- package/docs/functions/removeEmptyFields.html +4 -1
- package/docs/functions/sortFields.html +4 -1
- package/docs/functions/toUint8Array.html +4 -1
- package/docs/functions/toUint8ArrayOptional.html +4 -1
- package/docs/functions/trimAddressPrefix.html +79 -0
- package/docs/functions/uuid.html +4 -1
- package/docs/index.html +3 -0
- package/docs/interfaces/Logger.html +9 -6
- package/docs/interfaces/Validator.html +5 -2
- package/docs/modules.html +9 -0
- package/docs/types/AnyObject.html +4 -1
- package/docs/types/BaseParams.html +4 -1
- package/docs/types/BaseParamsFields.html +4 -1
- package/docs/types/DataLike.html +4 -1
- package/docs/types/EmptyObject.html +4 -1
- package/docs/types/LogFunction.html +4 -1
- package/docs/types/StringKeyObject.html +4 -1
- package/docs/types/WithAdditional.html +4 -1
- package/docs/variables/addressPrefix.html +70 -0
- package/package.json +8 -7
- package/src/Hasher/Hasher.ts +18 -3
- package/src/lib/Address/index.ts +2 -0
- package/src/lib/Address/normalizeAddress.ts +5 -0
- package/src/lib/Address/trimAddressPrefix.ts +10 -0
- package/src/lib/index.ts +1 -0
- package/dist/cjs/lib/exists.js +0 -8
- package/dist/cjs/lib/exists.js.map +0 -1
- package/dist/esm/lib/exists.js +0 -4
- package/dist/esm/lib/exists.js.map +0 -1
- package/dist/types/lib/exists.d.ts +0 -2
- package/dist/types/lib/exists.d.ts.map +0 -1
- 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.
|
|
15
|
-
"@xylabs/bignumber": "^2.
|
|
16
|
-
"@xylabs/buffer": "^2.
|
|
17
|
-
"@xyo-network/typeof": "^2.57.
|
|
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.
|
|
29
|
-
"@xylabs/tsconfig": "^2.17.
|
|
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.
|
|
66
|
+
"version": "2.57.6"
|
|
66
67
|
}
|
package/src/Hasher/Hasher.ts
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
34
|
-
return
|
|
48
|
+
hashAsync() {
|
|
49
|
+
return Hasher.hashAsync(this.obj)
|
|
35
50
|
}
|
|
36
51
|
}
|
|
@@ -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
package/dist/cjs/lib/exists.js
DELETED
|
@@ -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"}
|
package/dist/esm/lib/exists.js
DELETED
|
@@ -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 +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