@twin.org/trust-models 0.0.3-next.5 → 0.0.3-next.7
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/es/helpers/trustHelper.js +2 -2
- package/dist/es/helpers/trustHelper.js.map +1 -1
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITrustComponent.js.map +1 -1
- package/dist/es/models/ITrustVerificationInfo.js +4 -0
- package/dist/es/models/ITrustVerificationInfo.js.map +1 -0
- package/dist/es/models/ITrustVerifier.js.map +1 -1
- package/dist/types/helpers/trustHelper.d.ts +2 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/ITrustComponent.d.ts +2 -3
- package/dist/types/models/ITrustVerificationInfo.d.ts +10 -0
- package/dist/types/models/ITrustVerifier.d.ts +3 -3
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/TrustHelper.md +2 -2
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/ITrustComponent.md +2 -2
- package/docs/reference/interfaces/ITrustVerificationInfo.md +15 -0
- package/docs/reference/interfaces/ITrustVerifier.md +2 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2025 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { UnauthorizedError } from "@twin.org/core";
|
|
3
|
+
import { Is, UnauthorizedError } from "@twin.org/core";
|
|
4
4
|
/**
|
|
5
5
|
* Helper class for trust-related operations.
|
|
6
6
|
*/
|
|
@@ -19,7 +19,7 @@ export class TrustHelper {
|
|
|
19
19
|
*/
|
|
20
20
|
static async verifyTrust(component, trustPayload, action, overrideVerifiers) {
|
|
21
21
|
const trustResult = await component.verify(trustPayload, overrideVerifiers);
|
|
22
|
-
if (!trustResult.verified) {
|
|
22
|
+
if (!trustResult.verified || !Is.stringValue(trustResult.info?.identity)) {
|
|
23
23
|
throw new UnauthorizedError(TrustHelper.CLASS_NAME, "trustVerifyFailed", {
|
|
24
24
|
action,
|
|
25
25
|
errors: trustResult.errors
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trustHelper.js","sourceRoot":"","sources":["../../../src/helpers/trustHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"trustHelper.js","sourceRoot":"","sources":["../../../src/helpers/trustHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKvD;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;OAEG;IACI,MAAM,CAAU,UAAU,iBAAiC;IAElE;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,WAAW,CAC9B,SAA0B,EAC1B,YAAqB,EACrB,MAAc,EACd,iBAA4B;QAE5B,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;QAC5E,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC1E,MAAM,IAAI,iBAAiB,CAAC,WAAW,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACxE,MAAM;gBACN,MAAM,EAAE,WAAW,CAAC,MAAM;aAC1B,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC,IAAI,CAAC;IACzB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, UnauthorizedError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ITrustComponent } from \"../models/ITrustComponent.js\";\nimport type { ITrustVerificationInfo } from \"../models/ITrustVerificationInfo.js\";\n\n/**\n * Helper class for trust-related operations.\n */\nexport class TrustHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TrustHelper>();\n\n\t/**\n\t * Verify the trust payload for the action.\n\t * @param component The trust component to use.\n\t * @param trustPayload The trust payload to verify.\n\t * @param action The action being performed.\n\t * @param overrideVerifiers List of verifiers to use instead of the default ones.\n\t * @returns The information from the trust verification.\n\t */\n\tpublic static async verifyTrust(\n\t\tcomponent: ITrustComponent,\n\t\ttrustPayload: unknown,\n\t\taction: string,\n\t\toverrideVerifiers?: string[]\n\t): Promise<ITrustVerificationInfo> {\n\t\tconst trustResult = await component.verify(trustPayload, overrideVerifiers);\n\t\tif (!trustResult.verified || !Is.stringValue(trustResult.info?.identity)) {\n\t\t\tthrow new UnauthorizedError(TrustHelper.CLASS_NAME, \"trustVerifyFailed\", {\n\t\t\t\taction,\n\t\t\t\terrors: trustResult.errors\n\t\t\t});\n\t\t}\n\t\treturn trustResult.info;\n\t}\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -5,5 +5,6 @@ export * from "./factories/trustVerifierFactory.js";
|
|
|
5
5
|
export * from "./helpers/trustHelper.js";
|
|
6
6
|
export * from "./models/ITrustComponent.js";
|
|
7
7
|
export * from "./models/ITrustGenerator.js";
|
|
8
|
+
export * from "./models/ITrustVerificationInfo.js";
|
|
8
9
|
export * from "./models/ITrustVerifier.js";
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./factories/trustGeneratorFactory.js\";\nexport * from \"./factories/trustVerifierFactory.js\";\nexport * from \"./helpers/trustHelper.js\";\nexport * from \"./models/ITrustComponent.js\";\nexport * from \"./models/ITrustGenerator.js\";\nexport * from \"./models/ITrustVerifier.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./factories/trustGeneratorFactory.js\";\nexport * from \"./factories/trustVerifierFactory.js\";\nexport * from \"./helpers/trustHelper.js\";\nexport * from \"./models/ITrustComponent.js\";\nexport * from \"./models/ITrustGenerator.js\";\nexport * from \"./models/ITrustVerificationInfo.js\";\nexport * from \"./models/ITrustVerifier.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITrustComponent.js","sourceRoot":"","sources":["../../../src/models/ITrustComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent, IError } from \"@twin.org/core\";\n\n/**\n * Interface describing a trust component.\n */\nexport interface ITrustComponent extends IComponent {\n\t/**\n\t * Verify a payload by checking the validity of its structure and content using the registered verifiers.\n\t * @param payload The payload to verify.\n\t * @param overrideVerifiers List of verifiers to use instead of the default ones.\n\t * @returns Whether the payload is verified and any additional information extracted from the payload, or errors.\n\t */\n\tverify(\n\t\tpayload: unknown,\n\t\toverrideVerifiers?: string[]\n\t): Promise<{\n\t\tverified: boolean;\n\t\tinfo?:
|
|
1
|
+
{"version":3,"file":"ITrustComponent.js","sourceRoot":"","sources":["../../../src/models/ITrustComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent, IError } from \"@twin.org/core\";\nimport type { ITrustVerificationInfo } from \"./ITrustVerificationInfo.js\";\n\n/**\n * Interface describing a trust component.\n */\nexport interface ITrustComponent extends IComponent {\n\t/**\n\t * Verify a payload by checking the validity of its structure and content using the registered verifiers.\n\t * @param payload The payload to verify.\n\t * @param overrideVerifiers List of verifiers to use instead of the default ones.\n\t * @returns Whether the payload is verified and any additional information extracted from the payload, or errors.\n\t */\n\tverify(\n\t\tpayload: unknown,\n\t\toverrideVerifiers?: string[]\n\t): Promise<{\n\t\tverified: boolean;\n\t\tinfo?: ITrustVerificationInfo;\n\t\terrors?: IError[];\n\t}>;\n\n\t/**\n\t * Generate a payload using the specified generators.\n\t * @param identity The identity for which to generate the payload.\n\t * @param generatorType The type of generator to use, defaults to the default generator type or first in factory.\n\t * @param info Optional information to include in the generated payload.\n\t * @returns The generated payload.\n\t */\n\tgenerate(\n\t\tidentity: string,\n\t\tgeneratorType?: string,\n\t\tinfo?: { [key: string]: unknown }\n\t): Promise<unknown>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITrustVerificationInfo.js","sourceRoot":"","sources":["../../../src/models/ITrustVerificationInfo.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface describing a trust verifier information.\n */\nexport interface ITrustVerificationInfo {\n\t[key: string]: unknown;\n\n\t/**\n\t * The identity associated with the payload.\n\t */\n\tidentity: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITrustVerifier.js","sourceRoot":"","sources":["../../../src/models/ITrustVerifier.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent, IError } from \"@twin.org/core\";\n\n/**\n * Interface describing a trust verifier component.\n */\nexport interface ITrustVerifier extends IComponent {\n\t/**\n\t * Verify a payload by checking the validity of its structure and content.\n\t * @param payload The payload to verify.\n\t * @param info Information extracted from previous verifiers and to be added by this verifier.\n\t * @param errors Array to collect verification errors.\n\t * @returns Whether the payload is verified, returns undefined if payload was not processed.\n\t */\n\tverify(\n\t\tpayload: unknown,\n\t\tinfo:
|
|
1
|
+
{"version":3,"file":"ITrustVerifier.js","sourceRoot":"","sources":["../../../src/models/ITrustVerifier.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent, IError } from \"@twin.org/core\";\nimport type { ITrustVerificationInfo } from \"./ITrustVerificationInfo.js\";\n\n/**\n * Interface describing a trust verifier component.\n */\nexport interface ITrustVerifier extends IComponent {\n\t/**\n\t * Verify a payload by checking the validity of its structure and content.\n\t * @param payload The payload to verify.\n\t * @param info Information extracted from previous verifiers and to be added by this verifier.\n\t * @param info.identity The identity associated with the payload.\n\t * @param errors Array to collect verification errors.\n\t * @returns Whether the payload is verified, returns undefined if payload was not processed.\n\t */\n\tverify(\n\t\tpayload: unknown,\n\t\tinfo: ITrustVerificationInfo,\n\t\terrors: IError[]\n\t): Promise<boolean | undefined>;\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ITrustComponent } from "../models/ITrustComponent.js";
|
|
2
|
+
import type { ITrustVerificationInfo } from "../models/ITrustVerificationInfo.js";
|
|
2
3
|
/**
|
|
3
4
|
* Helper class for trust-related operations.
|
|
4
5
|
*/
|
|
@@ -15,7 +16,5 @@ export declare class TrustHelper {
|
|
|
15
16
|
* @param overrideVerifiers List of verifiers to use instead of the default ones.
|
|
16
17
|
* @returns The information from the trust verification.
|
|
17
18
|
*/
|
|
18
|
-
static verifyTrust(component: ITrustComponent, trustPayload: unknown, action: string, overrideVerifiers?: string[]): Promise<
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
} | undefined>;
|
|
19
|
+
static verifyTrust(component: ITrustComponent, trustPayload: unknown, action: string, overrideVerifiers?: string[]): Promise<ITrustVerificationInfo>;
|
|
21
20
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export * from "./factories/trustVerifierFactory.js";
|
|
|
3
3
|
export * from "./helpers/trustHelper.js";
|
|
4
4
|
export * from "./models/ITrustComponent.js";
|
|
5
5
|
export * from "./models/ITrustGenerator.js";
|
|
6
|
+
export * from "./models/ITrustVerificationInfo.js";
|
|
6
7
|
export * from "./models/ITrustVerifier.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IComponent, IError } from "@twin.org/core";
|
|
2
|
+
import type { ITrustVerificationInfo } from "./ITrustVerificationInfo.js";
|
|
2
3
|
/**
|
|
3
4
|
* Interface describing a trust component.
|
|
4
5
|
*/
|
|
@@ -11,9 +12,7 @@ export interface ITrustComponent extends IComponent {
|
|
|
11
12
|
*/
|
|
12
13
|
verify(payload: unknown, overrideVerifiers?: string[]): Promise<{
|
|
13
14
|
verified: boolean;
|
|
14
|
-
info?:
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
};
|
|
15
|
+
info?: ITrustVerificationInfo;
|
|
17
16
|
errors?: IError[];
|
|
18
17
|
}>;
|
|
19
18
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IComponent, IError } from "@twin.org/core";
|
|
2
|
+
import type { ITrustVerificationInfo } from "./ITrustVerificationInfo.js";
|
|
2
3
|
/**
|
|
3
4
|
* Interface describing a trust verifier component.
|
|
4
5
|
*/
|
|
@@ -7,10 +8,9 @@ export interface ITrustVerifier extends IComponent {
|
|
|
7
8
|
* Verify a payload by checking the validity of its structure and content.
|
|
8
9
|
* @param payload The payload to verify.
|
|
9
10
|
* @param info Information extracted from previous verifiers and to be added by this verifier.
|
|
11
|
+
* @param info.identity The identity associated with the payload.
|
|
10
12
|
* @param errors Array to collect verification errors.
|
|
11
13
|
* @returns Whether the payload is verified, returns undefined if payload was not processed.
|
|
12
14
|
*/
|
|
13
|
-
verify(payload: unknown, info:
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
}, errors: IError[]): Promise<boolean | undefined>;
|
|
15
|
+
verify(payload: unknown, info: ITrustVerificationInfo, errors: IError[]): Promise<boolean | undefined>;
|
|
16
16
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.7](https://github.com/twinfoundation/trust/compare/trust-models-v0.0.3-next.6...trust-models-v0.0.3-next.7) (2025-12-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* guarantee identity in helper return value ([8a582f3](https://github.com/twinfoundation/trust/commit/8a582f32125365a414dbd61c28dd870fb60d3acb))
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.6](https://github.com/twinfoundation/trust/compare/trust-models-v0.0.3-next.5...trust-models-v0.0.3-next.6) (2025-12-04)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* always include identity in verification info ([9594d19](https://github.com/twinfoundation/trust/commit/9594d19e9d718bd42b82964750ae3bcfb7df51bf))
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.5](https://github.com/twinfoundation/trust/compare/trust-models-v0.0.3-next.4...trust-models-v0.0.3-next.5) (2025-12-04)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -24,7 +24,7 @@ Runtime name for the class.
|
|
|
24
24
|
|
|
25
25
|
### verifyTrust()
|
|
26
26
|
|
|
27
|
-
> `static` **verifyTrust**(`component`, `trustPayload`, `action`, `overrideVerifiers?`): `Promise
|
|
27
|
+
> `static` **verifyTrust**(`component`, `trustPayload`, `action`, `overrideVerifiers?`): `Promise`\<[`ITrustVerificationInfo`](../interfaces/ITrustVerificationInfo.md)\>
|
|
28
28
|
|
|
29
29
|
Verify the trust payload for the action.
|
|
30
30
|
|
|
@@ -56,6 +56,6 @@ List of verifiers to use instead of the default ones.
|
|
|
56
56
|
|
|
57
57
|
#### Returns
|
|
58
58
|
|
|
59
|
-
`Promise
|
|
59
|
+
`Promise`\<[`ITrustVerificationInfo`](../interfaces/ITrustVerificationInfo.md)\>
|
|
60
60
|
|
|
61
61
|
The information from the trust verification.
|
package/docs/reference/index.md
CHANGED
|
@@ -10,7 +10,7 @@ Interface describing a trust component.
|
|
|
10
10
|
|
|
11
11
|
### verify()
|
|
12
12
|
|
|
13
|
-
> **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`:
|
|
13
|
+
> **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`: [`ITrustVerificationInfo`](ITrustVerificationInfo.md); `errors?`: `IError`[]; \}\>
|
|
14
14
|
|
|
15
15
|
Verify a payload by checking the validity of its structure and content using the registered verifiers.
|
|
16
16
|
|
|
@@ -30,7 +30,7 @@ List of verifiers to use instead of the default ones.
|
|
|
30
30
|
|
|
31
31
|
#### Returns
|
|
32
32
|
|
|
33
|
-
`Promise`\<\{ `verified`: `boolean`; `info?`:
|
|
33
|
+
`Promise`\<\{ `verified`: `boolean`; `info?`: [`ITrustVerificationInfo`](ITrustVerificationInfo.md); `errors?`: `IError`[]; \}\>
|
|
34
34
|
|
|
35
35
|
Whether the payload is verified and any additional information extracted from the payload, or errors.
|
|
36
36
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Interface: ITrustVerificationInfo
|
|
2
|
+
|
|
3
|
+
Interface describing a trust verifier information.
|
|
4
|
+
|
|
5
|
+
## Indexable
|
|
6
|
+
|
|
7
|
+
\[`key`: `string`\]: `unknown`
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### identity
|
|
12
|
+
|
|
13
|
+
> **identity**: `string`
|
|
14
|
+
|
|
15
|
+
The identity associated with the payload.
|