@xyo-network/core 2.20.47 → 2.21.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/BoundWitness/Builder/Builder.d.ts +5 -5
- package/dist/cjs/BoundWitness/Builder/Builder.js.map +1 -1
- package/dist/cjs/BoundWitness/Validator/BodyValidator.d.ts +7 -8
- package/dist/cjs/BoundWitness/Validator/BodyValidator.js +23 -20
- package/dist/cjs/BoundWitness/Validator/BodyValidator.js.map +1 -1
- package/dist/cjs/BoundWitness/Validator/MetaValidator.d.ts +4 -5
- package/dist/cjs/BoundWitness/Validator/MetaValidator.js +9 -11
- package/dist/cjs/BoundWitness/Validator/MetaValidator.js.map +1 -1
- package/dist/cjs/BoundWitness/Validator/Validator.d.ts +5 -5
- package/dist/cjs/BoundWitness/Validator/Validator.js +9 -8
- package/dist/cjs/BoundWitness/Validator/Validator.js.map +1 -1
- package/dist/cjs/BoundWitness/Wrapper/Wrapper.d.ts +5 -7
- package/dist/cjs/BoundWitness/Wrapper/Wrapper.js +5 -8
- package/dist/cjs/BoundWitness/Wrapper/Wrapper.js.map +1 -1
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBase.d.ts +9 -0
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBase.js +3 -0
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBase.js.map +1 -0
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.d.ts +36 -0
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.js +19 -0
- package/dist/cjs/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.js.map +1 -0
- package/dist/cjs/BoundWitness/models/Base/index.d.ts +2 -0
- package/dist/cjs/BoundWitness/models/Base/index.js +6 -0
- package/dist/cjs/BoundWitness/models/Base/index.js.map +1 -0
- package/dist/cjs/BoundWitness/models/Body/XyoBoundWitnessBody.d.ts +3 -5
- package/dist/cjs/BoundWitness/models/Meta/XyoBoundWitnessMeta.d.ts +7 -10
- package/dist/cjs/BoundWitness/models/WithXyoBoundWitnessMeta.d.ts +2 -2
- package/dist/cjs/BoundWitness/models/XyoBoundWitness.d.ts +2 -5
- package/dist/cjs/BoundWitness/models/index.d.ts +1 -1
- package/dist/cjs/BoundWitness/models/index.js +1 -1
- package/dist/cjs/Hasher/XyoAbstractHasher.d.ts +2 -2
- package/dist/cjs/Hasher/XyoAbstractHasher.js +3 -2
- package/dist/cjs/Hasher/XyoAbstractHasher.js.map +1 -1
- package/dist/cjs/Hasher/XyoHasher.d.ts +10 -5
- package/dist/cjs/Hasher/XyoHasher.js +28 -8
- package/dist/cjs/Hasher/XyoHasher.js.map +1 -1
- package/dist/cjs/Hasher/index.d.ts +0 -1
- package/dist/cjs/Hasher/index.js +0 -1
- package/dist/cjs/Hasher/index.js.map +1 -1
- package/dist/cjs/Hasher/removeFields.d.ts +3 -3
- package/dist/cjs/Hasher/removeFields.js +8 -5
- package/dist/cjs/Hasher/removeFields.js.map +1 -1
- package/dist/cjs/Hasher/sortFields.d.ts +1 -1
- package/dist/cjs/Hasher/sortFields.js +3 -2
- package/dist/cjs/Hasher/sortFields.js.map +1 -1
- package/dist/cjs/Huri/Huri.d.ts +2 -2
- package/dist/cjs/Payload/Builder/Builder.d.ts +3 -2
- package/dist/cjs/Payload/Builder/Builder.js.map +1 -1
- package/dist/cjs/Payload/Validator/BodyValidator.d.ts +4 -6
- package/dist/cjs/Payload/Validator/BodyValidator.js +5 -7
- package/dist/cjs/Payload/Validator/BodyValidator.js.map +1 -1
- package/dist/cjs/Payload/Validator/MetaValidator.d.ts +4 -5
- package/dist/cjs/Payload/Validator/MetaValidator.js +7 -9
- package/dist/cjs/Payload/Validator/MetaValidator.js.map +1 -1
- package/dist/cjs/Payload/Validator/Validator.d.ts +4 -5
- package/dist/cjs/Payload/Validator/Validator.js +5 -4
- package/dist/cjs/Payload/Validator/Validator.js.map +1 -1
- package/dist/cjs/Payload/Wrapper/Validator.d.ts +5 -6
- package/dist/cjs/Payload/Wrapper/Validator.js +5 -7
- package/dist/cjs/Payload/Wrapper/Validator.js.map +1 -1
- package/dist/cjs/Payload/Wrapper/Wrapper.d.ts +5 -7
- package/dist/cjs/Payload/Wrapper/Wrapper.js +5 -9
- package/dist/cjs/Payload/Wrapper/Wrapper.js.map +1 -1
- package/dist/cjs/Payload/index.d.ts +0 -1
- package/dist/cjs/Payload/index.js +0 -1
- package/dist/cjs/Payload/index.js.map +1 -1
- package/dist/cjs/Payload/models/Base.d.ts +6 -0
- package/dist/cjs/Payload/models/Base.js +3 -0
- package/dist/cjs/Payload/models/Base.js.map +1 -0
- package/dist/cjs/Payload/models/Body.d.ts +2 -3
- package/dist/cjs/Payload/models/Meta.d.ts +12 -7
- package/dist/cjs/Payload/models/WithAdditional.d.ts +4 -0
- package/dist/cjs/Payload/models/WithAdditional.js +3 -0
- package/dist/cjs/Payload/models/WithAdditional.js.map +1 -0
- package/dist/cjs/Payload/models/XyoPayload.d.ts +2 -4
- package/dist/cjs/Payload/models/index.d.ts +1 -2
- package/dist/cjs/Payload/models/index.js +1 -2
- package/dist/cjs/Payload/models/index.js.map +1 -1
- package/dist/cjs/Query/QueryPayload.d.ts +1 -1
- package/dist/cjs/Schema/Payload.d.ts +3 -3
- package/dist/cjs/Test/testBoundWitness.d.ts +2 -2
- package/dist/cjs/Test/testBoundWitness.js.map +1 -1
- package/dist/cjs/Test/testPayload.d.ts +3 -2
- package/dist/cjs/Test/testPayload.js.map +1 -1
- package/dist/cjs/Wallet/Base/WordsPayload.d.ts +1 -1
- package/dist/cjs/Witness/LegacyWitness.d.ts +3 -3
- package/dist/cjs/Witness/LegacyWitness.js.map +1 -1
- package/dist/cjs/Witness/QueryWitness.d.ts +1 -1
- package/dist/cjs/Witness/QueryWitness.js.map +1 -1
- package/dist/cjs/Witness/Witness.d.ts +1 -1
- package/dist/cjs/lib/StringKeyObject.d.ts +4 -0
- package/dist/cjs/lib/StringKeyObject.js +3 -0
- package/dist/cjs/lib/StringKeyObject.js.map +1 -0
- package/dist/cjs/lib/XyoObject.d.ts +6 -0
- package/dist/cjs/lib/XyoObject.js +13 -0
- package/dist/cjs/lib/XyoObject.js.map +1 -0
- package/dist/cjs/lib/XyoValidator.d.ts +4 -0
- package/dist/cjs/lib/XyoValidator.js +8 -0
- package/dist/cjs/lib/XyoValidator.js.map +1 -0
- package/dist/cjs/lib/index.d.ts +3 -0
- package/dist/cjs/lib/index.js +3 -0
- package/dist/cjs/lib/index.js.map +1 -1
- package/dist/cjs/lib/isXyoPayloadOfSchemaType.d.ts +3 -3
- package/dist/cjs/models/Base.d.ts +6 -0
- package/dist/cjs/models/Base.js +3 -0
- package/dist/cjs/models/Base.js.map +1 -0
- package/dist/cjs/models/Meta.d.ts +15 -0
- package/dist/cjs/models/Meta.js +3 -0
- package/dist/cjs/models/Meta.js.map +1 -0
- package/dist/cjs/models/XyoPayload.d.ts +2 -0
- package/dist/cjs/models/XyoPayload.js +3 -0
- package/dist/cjs/models/XyoPayload.js.map +1 -0
- package/dist/cjs/models/index.d.ts +3 -1
- package/dist/cjs/models/index.js +3 -1
- package/dist/cjs/models/index.js.map +1 -1
- package/dist/cjs/shared.d.ts +1 -1
- package/dist/cjs/shared.js +1 -1
- package/dist/cjs/shared.js.map +1 -1
- package/dist/esm/BoundWitness/Builder/Builder.d.ts +5 -5
- package/dist/esm/BoundWitness/Builder/Builder.js.map +1 -1
- package/dist/esm/BoundWitness/Validator/BodyValidator.d.ts +7 -8
- package/dist/esm/BoundWitness/Validator/BodyValidator.js +24 -22
- package/dist/esm/BoundWitness/Validator/BodyValidator.js.map +1 -1
- package/dist/esm/BoundWitness/Validator/MetaValidator.d.ts +4 -5
- package/dist/esm/BoundWitness/Validator/MetaValidator.js +9 -11
- package/dist/esm/BoundWitness/Validator/MetaValidator.js.map +1 -1
- package/dist/esm/BoundWitness/Validator/Validator.d.ts +5 -5
- package/dist/esm/BoundWitness/Validator/Validator.js +9 -8
- package/dist/esm/BoundWitness/Validator/Validator.js.map +1 -1
- package/dist/esm/BoundWitness/Wrapper/Wrapper.d.ts +5 -7
- package/dist/esm/BoundWitness/Wrapper/Wrapper.js +3 -7
- package/dist/esm/BoundWitness/Wrapper/Wrapper.js.map +1 -1
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBase.d.ts +9 -0
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBase.js +2 -0
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBase.js.map +1 -0
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.d.ts +36 -0
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.js +16 -0
- package/dist/esm/BoundWitness/models/Base/XyoBoundWitnessBaseSchema.js.map +1 -0
- package/dist/esm/BoundWitness/models/Base/index.d.ts +2 -0
- package/dist/esm/BoundWitness/models/Base/index.js +3 -0
- package/dist/esm/BoundWitness/models/Base/index.js.map +1 -0
- package/dist/esm/BoundWitness/models/Body/XyoBoundWitnessBody.d.ts +3 -5
- package/dist/esm/BoundWitness/models/Meta/XyoBoundWitnessMeta.d.ts +7 -10
- package/dist/esm/BoundWitness/models/WithXyoBoundWitnessMeta.d.ts +2 -2
- package/dist/esm/BoundWitness/models/XyoBoundWitness.d.ts +2 -5
- package/dist/esm/BoundWitness/models/index.d.ts +1 -1
- package/dist/esm/BoundWitness/models/index.js +1 -1
- package/dist/esm/Hasher/XyoAbstractHasher.d.ts +2 -2
- package/dist/esm/Hasher/XyoAbstractHasher.js +3 -2
- package/dist/esm/Hasher/XyoAbstractHasher.js.map +1 -1
- package/dist/esm/Hasher/XyoHasher.d.ts +10 -5
- package/dist/esm/Hasher/XyoHasher.js +27 -8
- package/dist/esm/Hasher/XyoHasher.js.map +1 -1
- package/dist/esm/Hasher/index.d.ts +0 -1
- package/dist/esm/Hasher/index.js +0 -1
- package/dist/esm/Hasher/index.js.map +1 -1
- package/dist/esm/Hasher/removeFields.d.ts +3 -3
- package/dist/esm/Hasher/removeFields.js +8 -5
- package/dist/esm/Hasher/removeFields.js.map +1 -1
- package/dist/esm/Hasher/sortFields.d.ts +1 -1
- package/dist/esm/Hasher/sortFields.js +3 -2
- package/dist/esm/Hasher/sortFields.js.map +1 -1
- package/dist/esm/Huri/Huri.d.ts +2 -2
- package/dist/esm/Payload/Builder/Builder.d.ts +3 -2
- package/dist/esm/Payload/Builder/Builder.js.map +1 -1
- package/dist/esm/Payload/Validator/BodyValidator.d.ts +4 -6
- package/dist/esm/Payload/Validator/BodyValidator.js +5 -8
- package/dist/esm/Payload/Validator/BodyValidator.js.map +1 -1
- package/dist/esm/Payload/Validator/MetaValidator.d.ts +4 -5
- package/dist/esm/Payload/Validator/MetaValidator.js +7 -9
- package/dist/esm/Payload/Validator/MetaValidator.js.map +1 -1
- package/dist/esm/Payload/Validator/Validator.d.ts +4 -5
- package/dist/esm/Payload/Validator/Validator.js +5 -5
- package/dist/esm/Payload/Validator/Validator.js.map +1 -1
- package/dist/esm/Payload/Wrapper/Validator.d.ts +5 -6
- package/dist/esm/Payload/Wrapper/Validator.js +5 -7
- package/dist/esm/Payload/Wrapper/Validator.js.map +1 -1
- package/dist/esm/Payload/Wrapper/Wrapper.d.ts +5 -7
- package/dist/esm/Payload/Wrapper/Wrapper.js +6 -10
- package/dist/esm/Payload/Wrapper/Wrapper.js.map +1 -1
- package/dist/esm/Payload/index.d.ts +0 -1
- package/dist/esm/Payload/index.js +0 -1
- package/dist/esm/Payload/index.js.map +1 -1
- package/dist/esm/Payload/models/Base.d.ts +6 -0
- package/dist/esm/Payload/models/Base.js +2 -0
- package/dist/esm/Payload/models/Base.js.map +1 -0
- package/dist/esm/Payload/models/Body.d.ts +2 -3
- package/dist/esm/Payload/models/Meta.d.ts +12 -7
- package/dist/esm/Payload/models/WithAdditional.d.ts +4 -0
- package/dist/esm/Payload/models/WithAdditional.js +2 -0
- package/dist/esm/Payload/models/WithAdditional.js.map +1 -0
- package/dist/esm/Payload/models/XyoPayload.d.ts +2 -4
- package/dist/esm/Payload/models/index.d.ts +1 -2
- package/dist/esm/Payload/models/index.js +1 -2
- package/dist/esm/Payload/models/index.js.map +1 -1
- package/dist/esm/Query/QueryPayload.d.ts +1 -1
- package/dist/esm/Schema/Payload.d.ts +3 -3
- package/dist/esm/Test/testBoundWitness.d.ts +2 -2
- package/dist/esm/Test/testBoundWitness.js.map +1 -1
- package/dist/esm/Test/testPayload.d.ts +3 -2
- package/dist/esm/Test/testPayload.js.map +1 -1
- package/dist/esm/Wallet/Base/WordsPayload.d.ts +1 -1
- package/dist/esm/Witness/LegacyWitness.d.ts +1 -1
- package/dist/esm/Witness/LegacyWitness.js.map +1 -1
- package/dist/esm/Witness/QueryWitness.d.ts +1 -1
- package/dist/esm/Witness/QueryWitness.js.map +1 -1
- package/dist/esm/Witness/Witness.d.ts +1 -1
- package/dist/esm/lib/StringKeyObject.d.ts +4 -0
- package/dist/esm/lib/StringKeyObject.js +2 -0
- package/dist/esm/lib/StringKeyObject.js.map +1 -0
- package/dist/esm/lib/XyoObject.d.ts +6 -0
- package/dist/esm/lib/XyoObject.js +9 -0
- package/dist/esm/lib/XyoObject.js.map +1 -0
- package/dist/esm/lib/XyoValidator.d.ts +4 -0
- package/dist/esm/lib/XyoValidator.js +4 -0
- package/dist/esm/lib/XyoValidator.js.map +1 -0
- package/dist/esm/lib/index.d.ts +3 -0
- package/dist/esm/lib/index.js +3 -0
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/isXyoPayloadOfSchemaType.d.ts +3 -3
- package/dist/esm/models/Base.d.ts +6 -0
- package/dist/esm/models/Base.js +2 -0
- package/dist/esm/models/Base.js.map +1 -0
- package/dist/esm/models/Meta.d.ts +15 -0
- package/dist/esm/models/Meta.js +2 -0
- package/dist/esm/models/Meta.js.map +1 -0
- package/dist/esm/models/XyoPayload.d.ts +2 -0
- package/dist/esm/models/XyoPayload.js +2 -0
- package/dist/esm/models/XyoPayload.js.map +1 -0
- package/dist/esm/models/index.d.ts +3 -1
- package/dist/esm/models/index.js +3 -1
- package/dist/esm/models/index.js.map +1 -1
- package/dist/esm/shared.d.ts +1 -1
- package/dist/esm/shared.js +1 -1
- package/dist/esm/shared.js.map +1 -1
- package/package.json +1 -1
- package/src/BoundWitness/Builder/Builder.spec.ts +4 -3
- package/src/BoundWitness/Builder/Builder.ts +7 -7
- package/src/BoundWitness/Validator/BodyValidator.spec.ts +1 -1
- package/src/BoundWitness/Validator/BodyValidator.ts +26 -27
- package/src/BoundWitness/Validator/MetaValidator.spec.ts +10 -10
- package/src/BoundWitness/Validator/MetaValidator.ts +9 -13
- package/src/BoundWitness/Validator/Validator.spec.ts +1 -1
- package/src/BoundWitness/Validator/Validator.ts +11 -11
- package/src/BoundWitness/Wrapper/Wrapper.ts +4 -11
- package/src/BoundWitness/models/Base/XyoBoundWitnessBase.ts +10 -0
- package/src/BoundWitness/models/{Body/XyoBoundWitnessBodySchema.ts → Base/XyoBoundWitnessBaseSchema.ts} +1 -3
- package/src/BoundWitness/models/Base/index.ts +2 -0
- package/src/BoundWitness/models/Meta/XyoBoundWitnessMeta.ts +7 -10
- package/src/BoundWitness/models/WithXyoBoundWitnessMeta.ts +2 -2
- package/src/BoundWitness/models/XyoBoundWitness.ts +2 -6
- package/src/BoundWitness/models/index.ts +1 -1
- package/src/Hasher/XyoHasher.ts +31 -8
- package/src/Hasher/index.ts +0 -1
- package/src/Hasher/removeFields.ts +17 -9
- package/src/Hasher/sortFields.ts +8 -5
- package/src/Huri/Huri.spec.ts +1 -1
- package/src/Huri/Huri.ts +1 -1
- package/src/Payload/Builder/Builder.ts +3 -2
- package/src/Payload/Validator/BodyValidator.spec.ts +1 -1
- package/src/Payload/Validator/BodyValidator.ts +6 -13
- package/src/Payload/Validator/MetaValidator.spec.ts +1 -1
- package/src/Payload/Validator/MetaValidator.ts +7 -11
- package/src/Payload/Validator/Validator.spec.ts +16 -16
- package/src/Payload/Validator/Validator.ts +6 -8
- package/src/Payload/Wrapper/Validator.ts +6 -10
- package/src/Payload/Wrapper/Wrapper.ts +7 -13
- package/src/Payload/index.ts +0 -1
- package/src/Query/QueryPayload.ts +1 -1
- package/src/Schema/Payload.ts +3 -3
- package/src/Test/testBoundWitness.ts +2 -2
- package/src/Test/testPayload.ts +3 -2
- package/src/Wallet/Base/WordsPayload.ts +1 -1
- package/src/Witness/LegacyWitness.ts +2 -1
- package/src/Witness/QueryWitness.ts +2 -1
- package/src/Witness/Witness.ts +1 -1
- package/src/lib/StringKeyObject.ts +2 -0
- package/src/lib/XyoObject.ts +11 -0
- package/src/lib/XyoValidator.ts +5 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/isXyoPayloadOfSchemaType.ts +1 -1
- package/src/models/Base.ts +6 -0
- package/src/models/Meta.ts +17 -0
- package/src/models/XyoPayload.ts +3 -0
- package/src/models/index.ts +3 -1
- package/src/shared.ts +1 -1
- package/src/BoundWitness/models/Body/XyoBoundWitnessBody.ts +0 -13
- package/src/BoundWitness/models/Body/index.ts +0 -2
- package/src/Hasher/XyoAbstractHasher.ts +0 -37
- package/src/Payload/models/Body.ts +0 -7
- package/src/Payload/models/Meta.ts +0 -11
- package/src/Payload/models/WithXyoPayloadMeta.ts +0 -6
- package/src/Payload/models/XyoPayload.ts +0 -6
- package/src/Payload/models/index.ts +0 -4
- package/src/models/WithStringIndex.ts +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { assertEx, Buffer } from '@xylabs/sdk-js'
|
|
2
2
|
|
|
3
3
|
import { sortFields, XyoHasher } from '../../Hasher'
|
|
4
|
-
import { XyoPayload,
|
|
4
|
+
import { XyoPayload, XyoPayloadWithPartialMeta } from '../../models'
|
|
5
5
|
import { XyoAccount } from '../../Wallet'
|
|
6
|
-
import { XyoBoundWitness } from '../models'
|
|
6
|
+
import { WithXyoBoundWitnessMeta, XyoBoundWitness, XyoBoundWitnessWithMeta } from '../models'
|
|
7
7
|
|
|
8
8
|
export interface XyoBoundWitnessBuilderConfig {
|
|
9
9
|
/** Whether or not the payloads should be included in the metadata sent to and recorded by the ArchivistApi */
|
|
@@ -28,7 +28,7 @@ export class XyoBoundWitnessBuilder {
|
|
|
28
28
|
return this
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public payloads(payloads: (
|
|
31
|
+
public payloads(payloads: (XyoPayloadWithPartialMeta | null)[]) {
|
|
32
32
|
payloads.forEach((payload) => {
|
|
33
33
|
if (payload !== null) {
|
|
34
34
|
this.payload(payload)
|
|
@@ -37,7 +37,7 @@ export class XyoBoundWitnessBuilder {
|
|
|
37
37
|
return this
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
public payload(payload?:
|
|
40
|
+
public payload(payload?: XyoPayloadWithPartialMeta) {
|
|
41
41
|
if (payload) {
|
|
42
42
|
this._payload_schemas.push(payload.schema)
|
|
43
43
|
this._payloads.push(assertEx(sortFields(payload)))
|
|
@@ -62,7 +62,7 @@ export class XyoBoundWitnessBuilder {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
private inlinePayloads() {
|
|
65
|
-
return this._payloads.map<
|
|
65
|
+
return this._payloads.map<XyoPayload>((payload, index) => {
|
|
66
66
|
return {
|
|
67
67
|
...payload,
|
|
68
68
|
schema: this._payload_schemas[index],
|
|
@@ -70,11 +70,11 @@ export class XyoBoundWitnessBuilder {
|
|
|
70
70
|
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
public build():
|
|
73
|
+
public build(): XyoBoundWitnessWithMeta {
|
|
74
74
|
const hashableFields = this.hashableFields() as unknown as Record<string, unknown>
|
|
75
75
|
const _hash = new XyoHasher(hashableFields).hash
|
|
76
76
|
|
|
77
|
-
const ret = { ...hashableFields, _client: 'js', _hash, _signatures: this.signatures(_hash), _timestamp: Date.now() } as XyoBoundWitness
|
|
77
|
+
const ret = { ...hashableFields, _client: 'js', _hash, _signatures: this.signatures(_hash), _timestamp: Date.now() } as WithXyoBoundWitnessMeta<XyoBoundWitness>
|
|
78
78
|
if (this.config.inlinePayloads) {
|
|
79
79
|
ret._payloads = this.inlinePayloads()
|
|
80
80
|
}
|
|
@@ -4,7 +4,7 @@ import { XyoBoundWitnessBodyValidator } from './BodyValidator'
|
|
|
4
4
|
|
|
5
5
|
test('all', () => {
|
|
6
6
|
const validator = new XyoBoundWitnessBodyValidator(testBoundWitness)
|
|
7
|
-
const errors = validator.
|
|
7
|
+
const errors = validator.validate()
|
|
8
8
|
dumpErrors(errors)
|
|
9
9
|
expect(errors.length).toBe(0)
|
|
10
10
|
})
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import uniq from 'lodash/uniq'
|
|
2
2
|
|
|
3
3
|
import { XyoHasher } from '../../Hasher'
|
|
4
|
-
import { validateType } from '../../lib'
|
|
5
|
-
import {
|
|
6
|
-
import { XyoPayload } from '../../Payload'
|
|
4
|
+
import { validateType, XyoValidator } from '../../lib'
|
|
5
|
+
import { XyoPayload } from '../../models'
|
|
7
6
|
import { XyoSchemaNameValidator } from '../../SchemaNameValidator'
|
|
8
|
-
import {
|
|
7
|
+
import { XyoBoundWitness } from '../models'
|
|
9
8
|
|
|
10
|
-
class XyoBoundWitnessBodyValidator {
|
|
11
|
-
private body: WithStringIndex<XyoBoundWitnessBody>
|
|
9
|
+
export class XyoBoundWitnessBodyValidator<T extends XyoBoundWitness = XyoBoundWitness> extends XyoValidator<T> {
|
|
12
10
|
private payloads?: XyoPayload[]
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
11
|
+
constructor(boundWitness: T, payloads?: XyoPayload[]) {
|
|
12
|
+
super(boundWitness)
|
|
15
13
|
this.payloads = payloads
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
public addressesUniqueness() {
|
|
19
17
|
const errors: Error[] = []
|
|
20
|
-
const { addresses } = this.
|
|
18
|
+
const { addresses } = this.obj
|
|
21
19
|
const uniqAddresses = uniq(addresses)
|
|
22
20
|
if (addresses?.length !== uniqAddresses?.length) errors.push(new Error('addresses must be unique'))
|
|
23
21
|
return errors
|
|
@@ -25,7 +23,7 @@ class XyoBoundWitnessBodyValidator {
|
|
|
25
23
|
|
|
26
24
|
public addresses() {
|
|
27
25
|
const errors: Error[] = []
|
|
28
|
-
const { addresses } = this.
|
|
26
|
+
const { addresses } = this.obj
|
|
29
27
|
if (!addresses?.length) errors.push(new Error('addresses missing [at least one address required]'))
|
|
30
28
|
errors.push(...this.addressesUniqueness())
|
|
31
29
|
return errors
|
|
@@ -34,8 +32,8 @@ class XyoBoundWitnessBodyValidator {
|
|
|
34
32
|
private validateArrayLength(fieldName: string, compareArrayName: string) {
|
|
35
33
|
const errors: Error[] = []
|
|
36
34
|
|
|
37
|
-
const [array, arrayErrors] = validateType('array', this.
|
|
38
|
-
const [compareArray, compareArrayErrors] = validateType('array', this.
|
|
35
|
+
const [array, arrayErrors] = validateType('array', this.stringKeyObj[fieldName] as [], true)
|
|
36
|
+
const [compareArray, compareArrayErrors] = validateType('array', this.stringKeyObj[compareArrayName] as [], true)
|
|
39
37
|
|
|
40
38
|
if (array?.length !== compareArray?.length) {
|
|
41
39
|
errors.push(new Error(`${fieldName}/${compareArrayName} count mismatch [${array?.length} !== ${compareArray?.length}]`))
|
|
@@ -58,10 +56,10 @@ class XyoBoundWitnessBodyValidator {
|
|
|
58
56
|
|
|
59
57
|
public payloadHashes() {
|
|
60
58
|
const errors: Error[] = []
|
|
61
|
-
const passedHashes = this.
|
|
59
|
+
const passedHashes = this.obj.payload_hashes
|
|
62
60
|
this.payloads?.forEach((payload, index) => {
|
|
63
61
|
const calcHash = new XyoHasher(payload).hash
|
|
64
|
-
const passedHash = passedHashes[index]
|
|
62
|
+
const passedHash = passedHashes?.[index]
|
|
65
63
|
if (calcHash !== passedHash) {
|
|
66
64
|
errors.push(new Error(`hash mismatch [${calcHash} !== ${passedHash}]`))
|
|
67
65
|
}
|
|
@@ -71,12 +69,15 @@ class XyoBoundWitnessBodyValidator {
|
|
|
71
69
|
|
|
72
70
|
public payloadSchemas() {
|
|
73
71
|
const errors: Error[] = []
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
const payloadSchemas = this.obj.payload_schemas
|
|
73
|
+
if (payloadSchemas) {
|
|
74
|
+
const schemaValidators: XyoSchemaNameValidator[] = payloadSchemas.map((schema: string) => {
|
|
75
|
+
return new XyoSchemaNameValidator(schema)
|
|
76
|
+
})
|
|
77
|
+
schemaValidators.forEach((validator) => {
|
|
78
|
+
errors.push(...validator.all())
|
|
79
|
+
})
|
|
80
|
+
}
|
|
80
81
|
return errors
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -85,20 +86,18 @@ class XyoBoundWitnessBodyValidator {
|
|
|
85
86
|
return errors
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
public
|
|
89
|
+
public schema() {
|
|
89
90
|
const errors: Error[] = []
|
|
90
91
|
const expectedSchema = 'network.xyo.boundwitness'
|
|
91
|
-
if (this.
|
|
92
|
-
errors.push(new Error(`invalid schema [${expectedSchema} !== ${this.
|
|
92
|
+
if (this.obj.schema !== expectedSchema) {
|
|
93
|
+
errors.push(new Error(`invalid schema [${expectedSchema} !== ${this.obj.schema}]`))
|
|
93
94
|
}
|
|
94
95
|
return errors
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
public
|
|
98
|
+
public validate() {
|
|
98
99
|
const errors: Error[] = []
|
|
99
|
-
errors.push(...this.addresses(), ...this.validateArrayLengths(), ...this.payloadHashes(), ...this.payloadSchemas(), ...this.previousHashes(), ...this.
|
|
100
|
+
errors.push(...this.addresses(), ...this.validateArrayLengths(), ...this.payloadHashes(), ...this.payloadSchemas(), ...this.previousHashes(), ...this.schema())
|
|
100
101
|
return errors
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
export { XyoBoundWitnessBodyValidator }
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import { dumpErrors } from '../../lib'
|
|
2
2
|
import { testBoundWitness } from '../../Test'
|
|
3
|
-
import {
|
|
3
|
+
import { XyoBoundWitnessWithMeta } from '../models'
|
|
4
4
|
import { XyoBoundWitnessMetaValidator } from './MetaValidator'
|
|
5
5
|
|
|
6
6
|
describe('XyoBoundWitnessMetaValidator', () => {
|
|
7
7
|
it('Validates valid Meta', () => {
|
|
8
8
|
const validator = new XyoBoundWitnessMetaValidator(testBoundWitness)
|
|
9
|
-
const errors = validator.
|
|
9
|
+
const errors = validator.validate()
|
|
10
10
|
dumpErrors(errors)
|
|
11
11
|
expect(errors.length).toBe(0)
|
|
12
12
|
})
|
|
13
13
|
describe('sourceIp', () => {
|
|
14
14
|
it('Validates valid IPv4 Address', () => {
|
|
15
|
-
const bw:
|
|
15
|
+
const bw: XyoBoundWitnessWithMeta = {
|
|
16
16
|
...testBoundWitness,
|
|
17
17
|
_source_ip: '127.0.0.1',
|
|
18
18
|
}
|
|
19
19
|
const validator = new XyoBoundWitnessMetaValidator(bw)
|
|
20
|
-
const errors = validator.
|
|
20
|
+
const errors = validator.validate()
|
|
21
21
|
dumpErrors(errors)
|
|
22
22
|
expect(errors.length).toBe(0)
|
|
23
23
|
})
|
|
24
24
|
it('Validates valid IPv6 Address', () => {
|
|
25
|
-
const bw:
|
|
25
|
+
const bw: XyoBoundWitnessWithMeta = {
|
|
26
26
|
...testBoundWitness,
|
|
27
27
|
_source_ip: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
|
28
28
|
}
|
|
29
29
|
const validator = new XyoBoundWitnessMetaValidator(bw)
|
|
30
|
-
const errors = validator.
|
|
30
|
+
const errors = validator.validate()
|
|
31
31
|
dumpErrors(errors)
|
|
32
32
|
expect(errors.length).toBe(0)
|
|
33
33
|
})
|
|
34
34
|
it('Handles missing Address', () => {
|
|
35
|
-
const bw:
|
|
35
|
+
const bw: XyoBoundWitnessWithMeta = {
|
|
36
36
|
...testBoundWitness,
|
|
37
37
|
_source_ip: undefined,
|
|
38
38
|
}
|
|
39
39
|
const validator = new XyoBoundWitnessMetaValidator(bw)
|
|
40
|
-
const errors = validator.
|
|
40
|
+
const errors = validator.validate()
|
|
41
41
|
dumpErrors(errors)
|
|
42
42
|
expect(errors.length).toBe(0)
|
|
43
43
|
})
|
|
44
44
|
it('Detects invalid Addresses', () => {
|
|
45
|
-
const bw:
|
|
45
|
+
const bw: XyoBoundWitnessWithMeta = {
|
|
46
46
|
...testBoundWitness,
|
|
47
47
|
_source_ip: 'notAnIpAddress',
|
|
48
48
|
}
|
|
49
49
|
const validator = new XyoBoundWitnessMetaValidator(bw)
|
|
50
|
-
const errors = validator.
|
|
50
|
+
const errors = validator.validate()
|
|
51
51
|
dumpErrors(errors)
|
|
52
52
|
expect(errors.length).toBe(0)
|
|
53
53
|
})
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { XyoHasher } from '../../Hasher'
|
|
2
|
-
import {
|
|
2
|
+
import { XyoValidator } from '../../lib'
|
|
3
|
+
import { XyoBoundWitnessMeta } from '../models'
|
|
3
4
|
import { isIP } from './is-ip'
|
|
4
5
|
|
|
5
6
|
const MIN_ALLOWED_TIMESTAMP = 1609459200000
|
|
6
7
|
const MAX_ALLOWED_TIMESTAMP = 4102444800000
|
|
7
8
|
|
|
8
|
-
export class XyoBoundWitnessMetaValidator {
|
|
9
|
-
private bw: XyoBoundWitness
|
|
10
|
-
constructor(bw: XyoBoundWitness) {
|
|
11
|
-
this.bw = bw
|
|
12
|
-
}
|
|
13
|
-
|
|
9
|
+
export class XyoBoundWitnessMetaValidator<T extends XyoBoundWitnessMeta = XyoBoundWitnessMeta> extends XyoValidator<T> {
|
|
14
10
|
public client() {
|
|
15
11
|
const errors: Error[] = []
|
|
16
12
|
return errors
|
|
@@ -19,10 +15,10 @@ export class XyoBoundWitnessMetaValidator {
|
|
|
19
15
|
public hash() {
|
|
20
16
|
const errors: Error[] = []
|
|
21
17
|
|
|
22
|
-
const hasher = new XyoHasher(this.
|
|
18
|
+
const hasher = new XyoHasher(this.obj)
|
|
23
19
|
|
|
24
20
|
const bodyHash = hasher.hash
|
|
25
|
-
if (bodyHash !== this.
|
|
21
|
+
if (bodyHash !== this.obj._hash) errors.push(new Error(`Body hash mismatch: [calculated: ${bodyHash}] [found: ${this.obj._hash}] [sortedStringify: ${hasher.stringified}]`))
|
|
26
22
|
return errors
|
|
27
23
|
}
|
|
28
24
|
|
|
@@ -38,7 +34,7 @@ export class XyoBoundWitnessMetaValidator {
|
|
|
38
34
|
|
|
39
35
|
public timestamp() {
|
|
40
36
|
const errors: Error[] = []
|
|
41
|
-
const { _timestamp } = this.
|
|
37
|
+
const { _timestamp } = this.obj
|
|
42
38
|
if (_timestamp === undefined) errors.push(new Error('Missing _timestamp'))
|
|
43
39
|
else if (_timestamp < MIN_ALLOWED_TIMESTAMP) errors.push(new Error('_timestamp is before year 2021'))
|
|
44
40
|
else if (_timestamp > MAX_ALLOWED_TIMESTAMP) errors.push(new Error('_timestamp is after year 2100'))
|
|
@@ -47,7 +43,7 @@ export class XyoBoundWitnessMetaValidator {
|
|
|
47
43
|
|
|
48
44
|
public sourceIp() {
|
|
49
45
|
const errors: Error[] = []
|
|
50
|
-
const { _source_ip } = this.
|
|
46
|
+
const { _source_ip } = this.obj
|
|
51
47
|
if (_source_ip && !isIP(_source_ip)) {
|
|
52
48
|
errors.push(new Error(`_source_ip invalid format [${_source_ip}]`))
|
|
53
49
|
}
|
|
@@ -56,12 +52,12 @@ export class XyoBoundWitnessMetaValidator {
|
|
|
56
52
|
|
|
57
53
|
public userAgent() {
|
|
58
54
|
const errors: Error[] = []
|
|
59
|
-
const { _user_agent } = this.
|
|
55
|
+
const { _user_agent } = this.obj
|
|
60
56
|
if (!_user_agent) errors.push(new Error('_user_agent missing'))
|
|
61
57
|
return errors
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
public
|
|
60
|
+
public validate() {
|
|
65
61
|
const errors: Error[] = []
|
|
66
62
|
errors.push(...this.client(), ...this.hash(), ...this.payloads(), ...this.signatures())
|
|
67
63
|
return errors
|
|
@@ -4,7 +4,7 @@ import { XyoBoundWitnessValidator } from './Validator'
|
|
|
4
4
|
|
|
5
5
|
test('all', () => {
|
|
6
6
|
const validator = new XyoBoundWitnessValidator(testBoundWitness)
|
|
7
|
-
const errors = validator.
|
|
7
|
+
const errors = validator.validate()
|
|
8
8
|
dumpErrors(errors)
|
|
9
9
|
expect(errors.length).toBe(0)
|
|
10
10
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/sdk-js'
|
|
2
2
|
|
|
3
|
+
import { XyoValidator } from '../../lib'
|
|
3
4
|
import { XyoAddressValue } from '../../Wallet'
|
|
4
|
-
import {
|
|
5
|
+
import { XyoBoundWitnessWithMeta } from '../models'
|
|
5
6
|
import { XyoBoundWitnessBodyValidator } from './BodyValidator'
|
|
6
7
|
import { XyoBoundWitnessMetaValidator } from './MetaValidator'
|
|
7
8
|
|
|
@@ -19,30 +20,29 @@ const validateSignature = (hash: string, address: string, signature?: string) =>
|
|
|
19
20
|
return []
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
class XyoBoundWitnessValidator {
|
|
23
|
-
private bw: XyoBoundWitness
|
|
23
|
+
class XyoBoundWitnessValidator<T extends XyoBoundWitnessWithMeta = XyoBoundWitnessWithMeta> extends XyoValidator<T> {
|
|
24
24
|
public body: XyoBoundWitnessBodyValidator
|
|
25
25
|
public meta: XyoBoundWitnessMetaValidator
|
|
26
|
-
constructor(bw:
|
|
27
|
-
|
|
26
|
+
constructor(bw: T) {
|
|
27
|
+
super(bw)
|
|
28
28
|
this.body = new XyoBoundWitnessBodyValidator(bw, bw._payloads)
|
|
29
29
|
this.meta = new XyoBoundWitnessMetaValidator(bw)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
public signatures() {
|
|
33
|
-
const hash = assertEx(this.
|
|
33
|
+
const hash = assertEx(this.obj._hash, 'Missing _hash')
|
|
34
34
|
return [
|
|
35
|
-
...validateArraysSameLength(this.
|
|
36
|
-
...this.
|
|
37
|
-
errors.push(...validateSignature(hash, address, this.
|
|
35
|
+
...validateArraysSameLength(this.obj._signatures ?? [], this.obj.addresses, 'Length mismatch: address/_signature'),
|
|
36
|
+
...this.obj.addresses.reduce<Error[]>((errors, address, index) => {
|
|
37
|
+
errors.push(...validateSignature(hash, address, this.obj._signatures?.[index]))
|
|
38
38
|
return errors
|
|
39
39
|
}, []),
|
|
40
40
|
]
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
public
|
|
43
|
+
public validate() {
|
|
44
44
|
const errors: Error[] = []
|
|
45
|
-
errors.push(...this.meta.
|
|
45
|
+
errors.push(...this.meta.validate(), ...this.body.validate())
|
|
46
46
|
errors.push(...this.signatures())
|
|
47
47
|
return errors
|
|
48
48
|
}
|
|
@@ -2,12 +2,11 @@ import pick from 'lodash/pick'
|
|
|
2
2
|
import { UAParser } from 'ua-parser-js'
|
|
3
3
|
|
|
4
4
|
import { XyoHasher } from '../../Hasher'
|
|
5
|
-
import { XyoBoundWitness } from '../models'
|
|
6
|
-
import { XyoBoundWitnessValidator } from '../Validator'
|
|
5
|
+
import { XyoBoundWitness, XyoBoundWitnessWithMeta } from '../models'
|
|
7
6
|
|
|
8
7
|
const scrubbedFields = ['_archive', '_client', '_hash', '_signatures', '_timestamp', '_user_agent', 'addresses', 'payload_schemas', 'previous_hashes', 'payload_hashes', 'schema']
|
|
9
8
|
|
|
10
|
-
class XyoBoundWitnessWrapper<T extends XyoBoundWitness> extends XyoHasher<T> {
|
|
9
|
+
export class XyoBoundWitnessWrapper<T extends XyoBoundWitness> extends XyoHasher<T> {
|
|
11
10
|
public readonly bw: T
|
|
12
11
|
constructor(bw: T) {
|
|
13
12
|
super(bw)
|
|
@@ -17,18 +16,12 @@ class XyoBoundWitnessWrapper<T extends XyoBoundWitness> extends XyoHasher<T> {
|
|
|
17
16
|
get scrubbedFields() {
|
|
18
17
|
return pick(this.bw, scrubbedFields)
|
|
19
18
|
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
get validator() {
|
|
23
|
-
this._validator = this._validator ?? new XyoBoundWitnessValidator(this.bw)
|
|
24
|
-
return this._validator
|
|
25
|
-
}
|
|
26
|
-
|
|
21
|
+
export class XyoBoundWitnessWithMetaWrapper<T extends XyoBoundWitnessWithMeta> extends XyoBoundWitnessWrapper<T> {
|
|
27
22
|
private _userAgent?: UAParser
|
|
28
23
|
get userAgent() {
|
|
29
24
|
this._userAgent = this._userAgent ?? new UAParser(this.bw._user_agent)
|
|
30
25
|
return this._userAgent
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
export { XyoBoundWitnessWrapper }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//Should type as JSONSchemaType<XyoBoundWitnessBody> once ajv/eslint issue is fixed
|
|
2
2
|
//https://github.com/microsoft/TypeScript/issues/44851
|
|
3
|
-
const
|
|
3
|
+
export const XyoBoundWitnessBaseSchema = {
|
|
4
4
|
$id: 'https://schemas.xyo.network/2.0/boundwitness/body',
|
|
5
5
|
additionalProperties: false,
|
|
6
6
|
properties: {
|
|
@@ -13,5 +13,3 @@ const XyoBoundWitnessBodySchema = {
|
|
|
13
13
|
required: ['addresses', 'payload_hashes', 'payload_schemas', 'previous_hashes', 'schema'],
|
|
14
14
|
type: 'object',
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
export { XyoBoundWitnessBodySchema }
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { XyoPayload, XyoPayloadMeta } from '../../../models'
|
|
2
|
+
import { XyoBoundWitness } from '../XyoBoundWitness'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
_client?: string
|
|
6
|
-
_hash?: string
|
|
7
|
-
_archive?: string
|
|
8
|
-
_payloads?: XyoPayloadBody[]
|
|
4
|
+
export type XyoBoundWitnessMeta = XyoPayloadMeta<{
|
|
5
|
+
_payloads?: XyoPayload[]
|
|
9
6
|
_signatures?: string[]
|
|
10
|
-
_timestamp?: number
|
|
11
7
|
_source_ip?: string
|
|
12
8
|
_user_agent?: string
|
|
13
|
-
}
|
|
9
|
+
}>
|
|
14
10
|
|
|
15
|
-
export type
|
|
11
|
+
export type XyoBoundWitnessWithMeta<T = unknown> = T & XyoBoundWitnessMeta & XyoBoundWitness
|
|
12
|
+
export type XyoBoundWitnessWithPartialMeta<T = unknown> = T & Partial<XyoBoundWitnessMeta> & XyoBoundWitness
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { XyoBoundWitnessBody } from './Body'
|
|
2
1
|
import { XyoBoundWitnessMeta } from './Meta'
|
|
2
|
+
import { XyoBoundWitness } from './XyoBoundWitness'
|
|
3
3
|
|
|
4
|
-
type WithXyoBoundWitnessMeta<T extends
|
|
4
|
+
type WithXyoBoundWitnessMeta<T extends XyoBoundWitness> = T & XyoBoundWitnessMeta
|
|
5
5
|
|
|
6
6
|
export type { WithXyoBoundWitnessMeta }
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { XyoBoundWitnessBody } from './Body'
|
|
3
|
-
import { WithXyoBoundWitnessMeta } from './WithXyoBoundWitnessMeta'
|
|
1
|
+
import { XyoBoundWitnessBase } from './Base'
|
|
4
2
|
|
|
5
|
-
type XyoBoundWitness =
|
|
6
|
-
|
|
7
|
-
export type { XyoBoundWitness }
|
|
3
|
+
export type XyoBoundWitness<T extends object = XyoBoundWitnessBase> = T & XyoBoundWitnessBase
|
package/src/Hasher/XyoHasher.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import shajs from 'sha.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { StringKeyObject, XyoObject } from '../lib'
|
|
4
|
+
import { removeEmptyFields } from './removeEmptyFields'
|
|
5
|
+
import { deepOmitUnderscoreFields } from './removeFields'
|
|
6
|
+
import { sortFields } from './sortFields'
|
|
7
|
+
|
|
8
|
+
export class XyoHasher<T extends object = StringKeyObject> extends XyoObject<T> {
|
|
9
|
+
get hashFields() {
|
|
10
|
+
return removeEmptyFields(deepOmitUnderscoreFields(this.stringKeyObj))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @deprecated use stringified instead */
|
|
14
|
+
public sortedStringify() {
|
|
15
|
+
return this.stringified
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public get stringified() {
|
|
19
|
+
const sortedEntry = sortFields(this.hashFields)
|
|
20
|
+
return JSON.stringify(sortedEntry)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @deprecated use hash instead */
|
|
24
|
+
public sortedHash() {
|
|
25
|
+
return this.hash
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get hash() {
|
|
29
|
+
return this.sortedHashData().toString('hex')
|
|
8
30
|
}
|
|
9
31
|
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
private sortedHashData() {
|
|
33
|
+
const stringObject = this.stringified
|
|
34
|
+
return shajs('sha256').update(stringObject).digest()
|
|
12
35
|
}
|
|
13
36
|
}
|
package/src/Hasher/index.ts
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
// eslint-disable-next-line no-restricted-imports
|
|
2
2
|
import { ValueKeyIteratee } from 'lodash'
|
|
3
|
-
import assign from 'lodash/assign'
|
|
4
3
|
import isObject from 'lodash/isObject'
|
|
5
4
|
import mapValues from 'lodash/mapValues'
|
|
5
|
+
import merge from 'lodash/merge'
|
|
6
6
|
import omitBy from 'lodash/omitBy'
|
|
7
7
|
import pickBy from 'lodash/pickBy'
|
|
8
8
|
|
|
9
|
-
export const deepBy = <T>(obj: T, predicate: ValueKeyIteratee<T>, func: typeof omitBy | typeof pickBy) => {
|
|
9
|
+
export const deepBy = <T extends object>(obj: T, predicate: ValueKeyIteratee<T>, func: typeof omitBy | typeof pickBy): T => {
|
|
10
10
|
if (Array.isArray(obj)) {
|
|
11
11
|
return obj
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
|
|
14
|
+
//pick the child objects
|
|
15
|
+
const onlyObjects = pickBy<T>(obj, isObject)
|
|
16
|
+
|
|
17
|
+
//pick the child non-objects
|
|
18
|
+
const nonObjects = pickBy<T>(obj, (value) => !isObject(value))
|
|
19
|
+
|
|
20
|
+
const pickedObjects = omitBy(onlyObjects, predicate)
|
|
21
|
+
const pickedNonObjects = omitBy(nonObjects, predicate)
|
|
22
|
+
|
|
23
|
+
const processedObjects = mapValues(pickedObjects, (obj: T) => deepBy(obj, predicate, func))
|
|
24
|
+
|
|
25
|
+
return merge(pickedNonObjects, processedObjects) as T
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
export const deepOmitUnderscoreFields = <T>(obj: T) => {
|
|
28
|
+
export const deepOmitUnderscoreFields = <T extends object>(obj: T) => {
|
|
21
29
|
return deepBy(obj, (_, key) => key.startsWith('_'), omitBy)
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
export const deepPickUnderscoreFields = <T>(obj: T) => {
|
|
32
|
+
export const deepPickUnderscoreFields = <T extends object>(obj: T) => {
|
|
25
33
|
return deepBy(obj, (_, key) => key.startsWith('_'), pickBy)
|
|
26
34
|
}
|
package/src/Hasher/sortFields.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { typeOf } from '../lib'
|
|
1
|
+
import { StringKeyObject, typeOf } from '../lib'
|
|
2
2
|
|
|
3
3
|
//if an object, subsort
|
|
4
4
|
const subSort = (value: unknown) => {
|
|
@@ -10,15 +10,18 @@ const subSort = (value: unknown) => {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const sortFields = <T extends
|
|
13
|
+
export const sortFields = <T extends object = object>(obj: T) => {
|
|
14
14
|
if (obj === null) {
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
const stringyObj = obj as StringKeyObject
|
|
19
|
+
|
|
20
|
+
const result: StringKeyObject = {}
|
|
21
|
+
Object.keys(stringyObj)
|
|
19
22
|
.sort()
|
|
20
23
|
.forEach((key) => {
|
|
21
|
-
result[key] = subSort(
|
|
24
|
+
result[key] = subSort(stringyObj[key])
|
|
22
25
|
})
|
|
23
26
|
return result as T
|
|
24
27
|
}
|
package/src/Huri/Huri.spec.ts
CHANGED
package/src/Huri/Huri.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/sdk-js'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
|
-
import { XyoPayload } from '../
|
|
4
|
+
import { XyoPayload } from '../models'
|
|
5
5
|
import { XyoAddressValue, XyoDataLike } from '../Wallet'
|
|
6
6
|
|
|
7
7
|
export type XyoObjectCategory = 'block' | 'payload'
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { deepOmitUnderscoreFields, removeEmptyFields, XyoHasher } from '../../Hasher'
|
|
2
|
-
import {
|
|
2
|
+
import { StringKeyObject } from '../../lib'
|
|
3
|
+
import { XyoPayload } from '../../models'
|
|
3
4
|
|
|
4
5
|
export interface XyoPayloadBuilderOptions {
|
|
5
6
|
schema: string
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export class XyoPayloadBuilder<T extends XyoPayload
|
|
9
|
+
export class XyoPayloadBuilder<T extends XyoPayload = XyoPayload<StringKeyObject>> {
|
|
9
10
|
private _fields: Partial<T> = {}
|
|
10
11
|
private _previousHash?: string
|
|
11
12
|
private _schema: string
|
|
@@ -4,7 +4,7 @@ import { XyoPayloadBodyValidator } from './BodyValidator'
|
|
|
4
4
|
|
|
5
5
|
test('all', () => {
|
|
6
6
|
const validator = new XyoPayloadBodyValidator(testPayload)
|
|
7
|
-
const errors = validator.
|
|
7
|
+
const errors = validator.validate()
|
|
8
8
|
dumpErrors(errors)
|
|
9
9
|
expect(errors.length).toBe(0)
|
|
10
10
|
})
|