@twin.org/trust-service 0.0.3-next.2 → 0.0.3-next.20

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Trust Service
2
2
 
3
- Trust service implementation.
3
+ This package is part of the trust repository and provides reusable trust building blocks so applications can issue, validate, and orchestrate trust artefacts with consistent behaviour.
4
4
 
5
5
  ## Installation
6
6
 
package/dist/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- export * from "./trustService.js";
3
+ export * from "./models/ITrustServiceConfig.js";
4
4
  export * from "./models/ITrustServiceConstructorOptions.js";
5
+ export * from "./trustService.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6CAA6C,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./trustService.js\";\nexport * from \"./models/ITrustServiceConstructorOptions.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,mBAAmB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/ITrustServiceConfig.js\";\nexport * from \"./models/ITrustServiceConstructorOptions.js\";\nexport * from \"./trustService.js\";\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2025 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=ITrustServiceConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITrustServiceConfig.js","sourceRoot":"","sources":["../../../src/models/ITrustServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the trust service.\n */\nexport interface ITrustServiceConfig {\n\t/**\n\t * The default generator type, uses first in factory if not specified.\n\t */\n\tdefaultGeneratorType?: string;\n}\n"]}
@@ -1,4 +1,2 @@
1
- // Copyright 2025 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
1
  export {};
4
2
  //# sourceMappingURL=ITrustServiceConstructorOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ITrustServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ITrustServiceConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the trust service.\n */\nexport interface ITrustServiceConstructorOptions {\n\t/**\n\t * The logging component type.\n\t * @default logging\n\t */\n\tloggingComponentType?: string;\n}\n"]}
1
+ {"version":3,"file":"ITrustServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ITrustServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITrustServiceConfig } from \"./ITrustServiceConfig.js\";\n\n/**\n * The options for the trust service.\n */\nexport interface ITrustServiceConstructorOptions {\n\t/**\n\t * The logging component type.\n\t * @default logging\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * The trust service configuration.\n\t */\n\tconfig?: ITrustServiceConfig;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- import { ComponentFactory, Is } from "@twin.org/core";
4
- import { TrustVerifierFactory } from "@twin.org/trust-models";
3
+ import { ComponentFactory, GeneralError, Guards, Is } from "@twin.org/core";
4
+ import { TrustGeneratorFactory, TrustVerifierFactory } from "@twin.org/trust-models";
5
5
  /**
6
6
  * Class for performing trust operations.
7
7
  */
@@ -15,12 +15,18 @@ export class TrustService {
15
15
  * @internal
16
16
  */
17
17
  _loggingComponent;
18
+ /**
19
+ * The default generator type.
20
+ * @internal
21
+ */
22
+ _defaultGeneratorType;
18
23
  /**
19
24
  * Create a new instance of TrustService.
20
25
  * @param options The options for the service.
21
26
  */
22
27
  constructor(options) {
23
28
  this._loggingComponent = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
29
+ this._defaultGeneratorType = options?.config?.defaultGeneratorType;
24
30
  }
25
31
  /**
26
32
  * Returns the class name of the component.
@@ -33,13 +39,13 @@ export class TrustService {
33
39
  * Verify a payload by checking the validity of its structure and content using the registered verifiers.
34
40
  * @param payload The payload to verify.
35
41
  * @param overrideVerifiers List of verifiers to use instead of the default ones.
36
- * @returns Whether the payload is verified and any additional information extracted from the payload, or failures per verifier.
42
+ * @returns Whether the payload is verified and any additional information extracted from the payload, or verification errors.
37
43
  */
38
44
  async verify(payload, overrideVerifiers) {
39
45
  const verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();
40
46
  let verified = false;
41
- const info = [];
42
- const failures = {};
47
+ const info = { identity: "" };
48
+ const errors = [];
43
49
  await this._loggingComponent?.log({
44
50
  level: "info",
45
51
  source: TrustService.CLASS_NAME,
@@ -49,13 +55,15 @@ export class TrustService {
49
55
  payload: payload?.toString() ?? ""
50
56
  }
51
57
  });
52
- for (const verifierName of verifierNames) {
53
- const verifier = TrustVerifierFactory.get(verifierName);
54
- const verifierResult = await verifier.verify(payload, info);
55
- if (Is.object(verifierResult)) {
56
- verified = verifierResult.verified;
57
- if (Is.arrayValue(verifierResult.failures)) {
58
- failures[verifierName] = verifierResult.failures;
58
+ if (verifierNames.length === 0) {
59
+ errors.push(new GeneralError(TrustService.CLASS_NAME, "noVerifiersRegistered"));
60
+ }
61
+ else {
62
+ for (const verifierName of verifierNames) {
63
+ const verifier = TrustVerifierFactory.get(verifierName);
64
+ const verifierResult = await verifier.verify(payload, info, errors);
65
+ if (!Is.empty(verifierResult)) {
66
+ verified = verifierResult;
59
67
  }
60
68
  }
61
69
  }
@@ -66,7 +74,7 @@ export class TrustService {
66
74
  message: "verified",
67
75
  ts: Date.now(),
68
76
  data: {
69
- info: JSON.stringify(info)
77
+ info
70
78
  }
71
79
  });
72
80
  }
@@ -77,15 +85,42 @@ export class TrustService {
77
85
  message: "notVerified",
78
86
  ts: Date.now(),
79
87
  data: {
80
- failures: JSON.stringify(failures)
88
+ errors
81
89
  }
82
90
  });
83
91
  }
84
92
  return {
85
93
  verified,
86
- info: Is.arrayValue(info) ? info : undefined,
87
- failures: Is.objectValue(failures) ? failures : undefined
94
+ info: info.identity.length > 0 ? info : undefined,
95
+ errors: errors.length > 0 ? errors : undefined
88
96
  };
89
97
  }
98
+ /**
99
+ * Generate a payload using the specified generators.
100
+ * @param identity The identity for which to generate the payload.
101
+ * @param generatorType The type of generator to use, defaults to the default generator type or first in factory.
102
+ * @param info Optional information to include in the generated payload.
103
+ * @param tenantId Optional tenant identifier to embed in the payload.
104
+ * @param organizationId Optional organization identifier to embed in the payload.
105
+ * @param options Per-call generation options.
106
+ * @param options.tokenTtlInSeconds TTL override in seconds for this token only. Takes precedence over the
107
+ * config-level `tokenTtlInSeconds` when provided.
108
+ * @returns The generated payload.
109
+ */
110
+ async generate(identity, generatorType, info, tenantId, organizationId, options) {
111
+ Guards.stringValue(TrustService.CLASS_NAME, "identity", identity);
112
+ if (Is.empty(generatorType)) {
113
+ generatorType = this._defaultGeneratorType;
114
+ if (Is.empty(generatorType)) {
115
+ const names = TrustGeneratorFactory.names();
116
+ if (names.length === 0) {
117
+ throw new GeneralError(TrustService.CLASS_NAME, "noGeneratorsRegistered");
118
+ }
119
+ generatorType = names[0];
120
+ }
121
+ }
122
+ const generator = TrustGeneratorFactory.get(generatorType);
123
+ return generator.generate(identity, info, tenantId, organizationId, options);
124
+ }
90
125
  }
91
126
  //# sourceMappingURL=trustService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trustService.js","sourceRoot":"","sources":["../../src/trustService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAe,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAInE,OAAO,EAAE,oBAAoB,EAAwB,MAAM,wBAAwB,CAAC;AAGpF;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;OAGG;IACc,iBAAiB,CAAqB;IAEvD;;;OAGG;IACH,YAAY,OAAyC;QACpD,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,WAAW,CACpD,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,YAAY,CAAC,UAAU,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAClB,OAAgB,EAChB,iBAA4B;QAM5B,MAAM,aAAa,GAAG,iBAAiB,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACxE,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,IAAI,GAAwB,EAAE,CAAC;QACrC,MAAM,QAAQ,GAA+B,EAAE,CAAC;QAEhD,MAAM,IAAI,CAAC,iBAAiB,EAAE,GAAG,CAAC;YACjC,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,YAAY,CAAC,UAAU;YAC/B,OAAO,EAAE,WAAW;YACpB,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI,EAAE;gBACL,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;aAClC;SACD,CAAC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AAC,SAAS;YAC5C,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACzD,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, type IError, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { TrustVerifierFactory, type ITrustComponent } from \"@twin.org/trust-models\";\nimport type { ITrustServiceConstructorOptions } from \"./models/ITrustServiceConstructorOptions.js\";\n\n/**\n * Class for performing trust operations.\n */\nexport class TrustService implements ITrustComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TrustService>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _loggingComponent?: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of TrustService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: ITrustServiceConstructorOptions) {\n\t\tthis._loggingComponent = ComponentFactory.getIfExists(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TrustService.CLASS_NAME;\n\t}\n\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 failures per verifier.\n\t */\n\tpublic async verify(\n\t\tpayload: unknown,\n\t\toverrideVerifiers?: string[]\n\t): Promise<{\n\t\tverified: boolean;\n\t\tinfo?: IJsonLdNodeObject[];\n\t\tfailures?: { [id: string]: IError[] };\n\t}> {\n\t\tconst verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();\n\t\tlet verified = false;\n\t\tconst info: IJsonLdNodeObject[] = [];\n\t\tconst failures: { [id: string]: IError[] } = {};\n\n\t\tawait this._loggingComponent?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\tmessage: \"verifying\",\n\t\t\tts: Date.now(),\n\t\t\tdata: {\n\t\t\t\tpayload: payload?.toString() ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\tfor (const verifierName of verifierNames) {\n\t\t\tconst verifier = TrustVerifierFactory.get(verifierName);\n\t\t\tconst verifierResult = await verifier.verify(payload, info);\n\n\t\t\tif (Is.object(verifierResult)) {\n\t\t\t\tverified = verifierResult.verified;\n\n\t\t\t\tif (Is.arrayValue(verifierResult.failures)) {\n\t\t\t\t\tfailures[verifierName] = verifierResult.failures;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (verified) {\n\t\t\tawait this._loggingComponent?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\t\tmessage: \"verified\",\n\t\t\t\tts: Date.now(),\n\t\t\t\tdata: {\n\t\t\t\t\tinfo: JSON.stringify(info)\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tawait this._loggingComponent?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\t\tmessage: \"notVerified\",\n\t\t\t\tts: Date.now(),\n\t\t\t\tdata: {\n\t\t\t\t\tfailures: JSON.stringify(failures)\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tverified,\n\t\t\tinfo: Is.arrayValue(info) ? info : undefined,\n\t\t\tfailures: Is.objectValue(failures) ? failures : undefined\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"trustService.js","sourceRoot":"","sources":["../../src/trustService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EA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;;;;;;;OAWG;IACI,KAAK,CAAC,QAAQ,CACpB,QAAgB,EAChB,aAAsB,EACtB,IAEC,EACD,QAAiB,EACjB,cAAuB,EACvB,OAAuC;QAEvC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QAExE,IAAI,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7B,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC;YAE3C,IAAI,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC7B,MAAM,KAAK,GAAG,qBAAqB,CAAC,KAAK,EAAE,CAAC;gBAC5C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACxB,MAAM,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;gBAC3E,CAAC;gBACD,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC;QACF,CAAC;QAED,MAAM,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAE3D,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, GeneralError, Guards, Is, type IError } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype ITrustVerificationInfo,\n\tTrustGeneratorFactory,\n\tTrustVerifierFactory,\n\ttype ITrustComponent\n} from \"@twin.org/trust-models\";\nimport type { ITrustServiceConstructorOptions } from \"./models/ITrustServiceConstructorOptions.js\";\n\n/**\n * Class for performing trust operations.\n */\nexport class TrustService implements ITrustComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TrustService>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _loggingComponent?: ILoggingComponent;\n\n\t/**\n\t * The default generator type.\n\t * @internal\n\t */\n\tprivate readonly _defaultGeneratorType?: string;\n\n\t/**\n\t * Create a new instance of TrustService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: ITrustServiceConstructorOptions) {\n\t\tthis._loggingComponent = ComponentFactory.getIfExists(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._defaultGeneratorType = options?.config?.defaultGeneratorType;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TrustService.CLASS_NAME;\n\t}\n\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 verification errors.\n\t */\n\tpublic async verify(\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\t\tconst verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();\n\n\t\tlet verified = false;\n\t\tconst info: ITrustVerificationInfo = { identity: \"\" };\n\t\tconst errors: IError[] = [];\n\n\t\tawait this._loggingComponent?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\tmessage: \"verifying\",\n\t\t\tts: Date.now(),\n\t\t\tdata: {\n\t\t\t\tpayload: payload?.toString() ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\tif (verifierNames.length === 0) {\n\t\t\terrors.push(new GeneralError(TrustService.CLASS_NAME, \"noVerifiersRegistered\"));\n\t\t} else {\n\t\t\tfor (const verifierName of verifierNames) {\n\t\t\t\tconst verifier = TrustVerifierFactory.get(verifierName);\n\t\t\t\tconst verifierResult = await verifier.verify(payload, info, errors);\n\n\t\t\t\tif (!Is.empty(verifierResult)) {\n\t\t\t\t\tverified = verifierResult;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (verified) {\n\t\t\tawait this._loggingComponent?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\t\tmessage: \"verified\",\n\t\t\t\tts: Date.now(),\n\t\t\t\tdata: {\n\t\t\t\t\tinfo\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tawait this._loggingComponent?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: TrustService.CLASS_NAME,\n\t\t\t\tmessage: \"notVerified\",\n\t\t\t\tts: Date.now(),\n\t\t\t\tdata: {\n\t\t\t\t\terrors\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tverified,\n\t\t\tinfo: info.identity.length > 0 ? info : undefined,\n\t\t\terrors: errors.length > 0 ? errors : undefined\n\t\t};\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 * @param tenantId Optional tenant identifier to embed in the payload.\n\t * @param organizationId Optional organization identifier to embed in the payload.\n\t * @param options Per-call generation options.\n\t * @param options.tokenTtlInSeconds TTL override in seconds for this token only. Takes precedence over the\n\t * config-level `tokenTtlInSeconds` when provided.\n\t * @returns The generated payload.\n\t */\n\tpublic async generate(\n\t\tidentity: string,\n\t\tgeneratorType?: string,\n\t\tinfo?: {\n\t\t\t[key: string]: unknown;\n\t\t},\n\t\ttenantId?: string,\n\t\torganizationId?: string,\n\t\toptions?: { tokenTtlInSeconds: number }\n\t): Promise<unknown> {\n\t\tGuards.stringValue(TrustService.CLASS_NAME, nameof(identity), identity);\n\n\t\tif (Is.empty(generatorType)) {\n\t\t\tgeneratorType = this._defaultGeneratorType;\n\n\t\t\tif (Is.empty(generatorType)) {\n\t\t\t\tconst names = TrustGeneratorFactory.names();\n\t\t\t\tif (names.length === 0) {\n\t\t\t\t\tthrow new GeneralError(TrustService.CLASS_NAME, \"noGeneratorsRegistered\");\n\t\t\t\t}\n\t\t\t\tgeneratorType = names[0];\n\t\t\t}\n\t\t}\n\n\t\tconst generator = TrustGeneratorFactory.get(generatorType);\n\n\t\treturn generator.generate(identity, info, tenantId, organizationId, options);\n\t}\n}\n"]}
@@ -1,2 +1,3 @@
1
- export * from "./trustService.js";
1
+ export * from "./models/ITrustServiceConfig.js";
2
2
  export * from "./models/ITrustServiceConstructorOptions.js";
3
+ export * from "./trustService.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The options for the trust service.
3
+ */
4
+ export interface ITrustServiceConfig {
5
+ /**
6
+ * The default generator type, uses first in factory if not specified.
7
+ */
8
+ defaultGeneratorType?: string;
9
+ }
@@ -1,3 +1,4 @@
1
+ import type { ITrustServiceConfig } from "./ITrustServiceConfig.js";
1
2
  /**
2
3
  * The options for the trust service.
3
4
  */
@@ -7,4 +8,8 @@ export interface ITrustServiceConstructorOptions {
7
8
  * @default logging
8
9
  */
9
10
  loggingComponentType?: string;
11
+ /**
12
+ * The trust service configuration.
13
+ */
14
+ config?: ITrustServiceConfig;
10
15
  }
@@ -1,6 +1,5 @@
1
1
  import { type IError } from "@twin.org/core";
2
- import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
3
- import { type ITrustComponent } from "@twin.org/trust-models";
2
+ import { type ITrustVerificationInfo, type ITrustComponent } from "@twin.org/trust-models";
4
3
  import type { ITrustServiceConstructorOptions } from "./models/ITrustServiceConstructorOptions.js";
5
4
  /**
6
5
  * Class for performing trust operations.
@@ -24,13 +23,28 @@ export declare class TrustService implements ITrustComponent {
24
23
  * Verify a payload by checking the validity of its structure and content using the registered verifiers.
25
24
  * @param payload The payload to verify.
26
25
  * @param overrideVerifiers List of verifiers to use instead of the default ones.
27
- * @returns Whether the payload is verified and any additional information extracted from the payload, or failures per verifier.
26
+ * @returns Whether the payload is verified and any additional information extracted from the payload, or verification errors.
28
27
  */
29
28
  verify(payload: unknown, overrideVerifiers?: string[]): Promise<{
30
29
  verified: boolean;
31
- info?: IJsonLdNodeObject[];
32
- failures?: {
33
- [id: string]: IError[];
34
- };
30
+ info?: ITrustVerificationInfo;
31
+ errors?: IError[];
35
32
  }>;
33
+ /**
34
+ * Generate a payload using the specified generators.
35
+ * @param identity The identity for which to generate the payload.
36
+ * @param generatorType The type of generator to use, defaults to the default generator type or first in factory.
37
+ * @param info Optional information to include in the generated payload.
38
+ * @param tenantId Optional tenant identifier to embed in the payload.
39
+ * @param organizationId Optional organization identifier to embed in the payload.
40
+ * @param options Per-call generation options.
41
+ * @param options.tokenTtlInSeconds TTL override in seconds for this token only. Takes precedence over the
42
+ * config-level `tokenTtlInSeconds` when provided.
43
+ * @returns The generated payload.
44
+ */
45
+ generate(identity: string, generatorType?: string, info?: {
46
+ [key: string]: unknown;
47
+ }, tenantId?: string, organizationId?: string, options?: {
48
+ tokenTtlInSeconds: number;
49
+ }): Promise<unknown>;
36
50
  }
package/docs/changelog.md CHANGED
@@ -1,11 +1,263 @@
1
1
  # Changelog
2
2
 
3
- ## [0.0.3-next.2](https://github.com/twinfoundation/trust/compare/trust-service-v0.0.3-next.1...trust-service-v0.0.3-next.2) (2025-12-03)
3
+ ## [0.0.3-next.20](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.19...trust-service-v0.0.3-next.20) (2026-06-10)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **trust-service:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/trust-models bumped from 0.0.3-next.19 to 0.0.3-next.20
16
+
17
+ ## [0.0.3-next.19](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.18...trust-service-v0.0.3-next.19) (2026-06-05)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **trust-service:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/trust-models bumped from 0.0.3-next.18 to 0.0.3-next.19
30
+
31
+ ## [0.0.3-next.18](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.17...trust-service-v0.0.3-next.18) (2026-06-05)
32
+
33
+
34
+ ### Features
35
+
36
+ * add allow deny verifier ([#32](https://github.com/iotaledger/twin-trust/issues/32)) ([daf5d03](https://github.com/iotaledger/twin-trust/commit/daf5d033ffbe82e2228c48ca7ffea870a1ce956e))
37
+
38
+
39
+ ### Dependencies
40
+
41
+ * The following workspace dependencies were updated
42
+ * dependencies
43
+ * @twin.org/trust-models bumped from 0.0.3-next.17 to 0.0.3-next.18
44
+
45
+ ## [0.0.3-next.17](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.16...trust-service-v0.0.3-next.17) (2026-06-02)
46
+
47
+
48
+ ### Miscellaneous Chores
49
+
50
+ * **trust-service:** Synchronize repo versions
51
+
52
+
53
+ ### Dependencies
54
+
55
+ * The following workspace dependencies were updated
56
+ * dependencies
57
+ * @twin.org/trust-models bumped from 0.0.3-next.16 to 0.0.3-next.17
58
+
59
+ ## [0.0.3-next.16](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.15...trust-service-v0.0.3-next.16) (2026-05-27)
60
+
61
+
62
+ ### Features
63
+
64
+ * ttl-token per generation ([#26](https://github.com/iotaledger/twin-trust/issues/26)) ([a35e925](https://github.com/iotaledger/twin-trust/commit/a35e925560d05f30dd8c02eb4184c0c503ca075a))
65
+
66
+
67
+ ### Dependencies
68
+
69
+ * The following workspace dependencies were updated
70
+ * dependencies
71
+ * @twin.org/trust-models bumped from 0.0.3-next.15 to 0.0.3-next.16
72
+
73
+ ## [0.0.3-next.15](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.14...trust-service-v0.0.3-next.15) (2026-05-26)
74
+
75
+
76
+ ### Miscellaneous Chores
77
+
78
+ * **trust-service:** Synchronize repo versions
79
+
80
+
81
+ ### Dependencies
82
+
83
+ * The following workspace dependencies were updated
84
+ * dependencies
85
+ * @twin.org/trust-models bumped from 0.0.3-next.14 to 0.0.3-next.15
86
+
87
+ ## [0.0.3-next.14](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.13...trust-service-v0.0.3-next.14) (2026-05-22)
88
+
89
+
90
+ ### Features
91
+
92
+ * add optional tenantId + organizationId to trust VC payload ([#19](https://github.com/iotaledger/twin-trust/issues/19)) ([1e93f6b](https://github.com/iotaledger/twin-trust/commit/1e93f6b0eacbfa725f3c3515d4255b39dd122ce7))
93
+
94
+
95
+ ### Dependencies
96
+
97
+ * The following workspace dependencies were updated
98
+ * dependencies
99
+ * @twin.org/trust-models bumped from 0.0.3-next.13 to 0.0.3-next.14
100
+
101
+ ## [0.0.3-next.13](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.12...trust-service-v0.0.3-next.13) (2026-05-20)
102
+
103
+
104
+ ### Features
105
+
106
+ * update dependencies ([367d7fc](https://github.com/iotaledger/twin-trust/commit/367d7fc1f970522650c776d231bfacc84f97be67))
107
+
108
+
109
+ ### Dependencies
110
+
111
+ * The following workspace dependencies were updated
112
+ * dependencies
113
+ * @twin.org/trust-models bumped from 0.0.3-next.12 to 0.0.3-next.13
114
+
115
+ ## [0.0.3-next.12](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.11...trust-service-v0.0.3-next.12) (2026-05-11)
116
+
117
+
118
+ ### Features
119
+
120
+ * typescript 6 update ([a232da2](https://github.com/iotaledger/twin-trust/commit/a232da293afbd3b42843e187e4952dabd7917397))
121
+
122
+
123
+ ### Dependencies
124
+
125
+ * The following workspace dependencies were updated
126
+ * dependencies
127
+ * @twin.org/trust-models bumped from 0.0.3-next.11 to 0.0.3-next.12
128
+
129
+ ## [0.0.3-next.11](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.10...trust-service-v0.0.3-next.11) (2026-03-04)
130
+
131
+
132
+ ### Miscellaneous Chores
133
+
134
+ * **trust-service:** Synchronize repo versions
135
+
136
+
137
+ ### Dependencies
138
+
139
+ * The following workspace dependencies were updated
140
+ * dependencies
141
+ * @twin.org/trust-models bumped from 0.0.3-next.10 to 0.0.3-next.11
142
+
143
+ ## [0.0.3-next.10](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.9...trust-service-v0.0.3-next.10) (2026-02-27)
144
+
145
+
146
+ ### Miscellaneous Chores
147
+
148
+ * **trust-service:** Synchronize repo versions
149
+
150
+
151
+ ### Dependencies
152
+
153
+ * The following workspace dependencies were updated
154
+ * dependencies
155
+ * @twin.org/trust-models bumped from 0.0.3-next.9 to 0.0.3-next.10
156
+
157
+ ## [0.0.3-next.9](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.8...trust-service-v0.0.3-next.9) (2026-02-26)
158
+
159
+
160
+ ### Features
161
+
162
+ * error if no verifiers registered ([aa1cef6](https://github.com/iotaledger/twin-trust/commit/aa1cef6a130b008144073696077fd0a41d4bc533))
163
+
164
+
165
+ ### Dependencies
166
+
167
+ * The following workspace dependencies were updated
168
+ * dependencies
169
+ * @twin.org/trust-models bumped from 0.0.3-next.8 to 0.0.3-next.9
170
+
171
+ ## [0.0.3-next.8](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.7...trust-service-v0.0.3-next.8) (2026-01-30)
172
+
173
+
174
+ ### Features
175
+
176
+ * verification info structure ([#10](https://github.com/iotaledger/twin-trust/issues/10)) ([8b09ec8](https://github.com/iotaledger/twin-trust/commit/8b09ec8128214b659f427fc3a985eb8ced9ed5dc))
177
+
178
+
179
+ ### Dependencies
180
+
181
+ * The following workspace dependencies were updated
182
+ * dependencies
183
+ * @twin.org/trust-models bumped from 0.0.3-next.7 to 0.0.3-next.8
184
+
185
+ ## [0.0.3-next.7](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.6...trust-service-v0.0.3-next.7) (2025-12-04)
186
+
187
+
188
+ ### Miscellaneous Chores
189
+
190
+ * **trust-service:** Synchronize repo versions
191
+
192
+
193
+ ### Dependencies
194
+
195
+ * The following workspace dependencies were updated
196
+ * dependencies
197
+ * @twin.org/trust-models bumped from 0.0.3-next.6 to 0.0.3-next.7
198
+
199
+ ## [0.0.3-next.6](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.5...trust-service-v0.0.3-next.6) (2025-12-04)
200
+
201
+
202
+ ### Features
203
+
204
+ * always include identity in verification info ([9594d19](https://github.com/iotaledger/twin-trust/commit/9594d19e9d718bd42b82964750ae3bcfb7df51bf))
205
+
206
+
207
+ ### Dependencies
208
+
209
+ * The following workspace dependencies were updated
210
+ * dependencies
211
+ * @twin.org/trust-models bumped from 0.0.3-next.5 to 0.0.3-next.6
212
+
213
+ ## [0.0.3-next.5](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.4...trust-service-v0.0.3-next.5) (2025-12-04)
214
+
215
+
216
+ ### Features
217
+
218
+ * add default generator config ([54d98ba](https://github.com/iotaledger/twin-trust/commit/54d98ba53b7450b56337daeda504437be0d21943))
219
+
220
+
221
+ ### Dependencies
222
+
223
+ * The following workspace dependencies were updated
224
+ * dependencies
225
+ * @twin.org/trust-models bumped from 0.0.3-next.4 to 0.0.3-next.5
226
+
227
+ ## [0.0.3-next.4](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.3...trust-service-v0.0.3-next.4) (2025-12-04)
228
+
229
+
230
+ ### Features
231
+
232
+ * add generators ([6228c88](https://github.com/iotaledger/twin-trust/commit/6228c88a8f0244b7bdfc76b8624c427c81d23f7b))
233
+
234
+
235
+ ### Dependencies
236
+
237
+ * The following workspace dependencies were updated
238
+ * dependencies
239
+ * @twin.org/trust-models bumped from 0.0.3-next.3 to 0.0.3-next.4
240
+
241
+ ## [0.0.3-next.3](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.2...trust-service-v0.0.3-next.3) (2025-12-04)
242
+
243
+
244
+ ### Features
245
+
246
+ * flatten error structure ([5fdd665](https://github.com/iotaledger/twin-trust/commit/5fdd665d0fc523a655563a0c20d1d82b634534e2))
247
+
248
+
249
+ ### Dependencies
250
+
251
+ * The following workspace dependencies were updated
252
+ * dependencies
253
+ * @twin.org/trust-models bumped from 0.0.3-next.2 to 0.0.3-next.3
254
+
255
+ ## [0.0.3-next.2](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.1...trust-service-v0.0.3-next.2) (2025-12-03)
4
256
 
5
257
 
6
258
  ### Features
7
259
 
8
- * support pass through of info between verifiers ([1ce64b9](https://github.com/twinfoundation/trust/commit/1ce64b97a949278b447cc12b576ce5de537f30f3))
260
+ * support pass through of info between verifiers ([1ce64b9](https://github.com/iotaledger/twin-trust/commit/1ce64b97a949278b447cc12b576ce5de537f30f3))
9
261
 
10
262
 
11
263
  ### Dependencies
@@ -14,13 +266,13 @@
14
266
  * dependencies
15
267
  * @twin.org/trust-models bumped from 0.0.3-next.1 to 0.0.3-next.2
16
268
 
17
- ## [0.0.3-next.1](https://github.com/twinfoundation/trust/compare/trust-service-v0.0.3-next.0...trust-service-v0.0.3-next.1) (2025-12-02)
269
+ ## [0.0.3-next.1](https://github.com/iotaledger/twin-trust/compare/trust-service-v0.0.3-next.0...trust-service-v0.0.3-next.1) (2025-12-02)
18
270
 
19
271
 
20
272
  ### Features
21
273
 
22
- * add verifier overrides ([bb16a35](https://github.com/twinfoundation/trust/commit/bb16a35e0d6966e050cbdcc9e32a8c78839431d4))
23
- * initial commit ([d378ef4](https://github.com/twinfoundation/trust/commit/d378ef4cd66c98fa188aaf3b23152d1e47d88a37))
274
+ * add verifier overrides ([bb16a35](https://github.com/iotaledger/twin-trust/commit/bb16a35e0d6966e050cbdcc9e32a8c78839431d4))
275
+ * initial commit ([d378ef4](https://github.com/iotaledger/twin-trust/commit/d378ef4cd66c98fa188aaf3b23152d1e47d88a37))
24
276
 
25
277
 
26
278
  ### Dependencies
@@ -29,4 +281,4 @@
29
281
  * dependencies
30
282
  * @twin.org/trust-models bumped from 0.0.3-next.0 to 0.0.3-next.1
31
283
 
32
- ## @twin.org/trust-service - Changelog
284
+ ## Changelog
package/docs/examples.md CHANGED
@@ -1 +1,69 @@
1
- # @twin.org/trust-service - Examples
1
+ # Trust Service Examples
2
+
3
+ The following snippets show a practical end-to-end flow where generators and verifiers are registered once and reused for trust operations.
4
+
5
+ ## TrustService
6
+
7
+ ```typescript
8
+ import { TrustService } from '@twin.org/trust-service';
9
+ import {
10
+ TrustGeneratorFactory,
11
+ TrustVerifierFactory,
12
+ type ITrustGenerator,
13
+ type ITrustVerifier
14
+ } from '@twin.org/trust-models';
15
+ import type { IError } from '@twin.org/core';
16
+
17
+ const generator: ITrustGenerator = {
18
+ className: () => 'JwtGenerator',
19
+ generate: async (identity, info) => ({
20
+ token: 'eyJhbGciOiJFZERTQSJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTppc3N1ZXIifQ.signature',
21
+ identity,
22
+ subject: info?.subject
23
+ })
24
+ };
25
+
26
+ const verifier: ITrustVerifier = {
27
+ className: () => 'JwtVerifier',
28
+ verify: async (payload, info, _errors) => {
29
+ const hasToken = typeof payload === 'object' && payload !== null && 'token' in payload;
30
+ if (!hasToken) {
31
+ return false;
32
+ }
33
+
34
+ info.identity = 'did:example:issuer';
35
+ info.data = {
36
+ subject: {
37
+ id: 'did:example:subject',
38
+ status: 'active'
39
+ }
40
+ };
41
+ return true;
42
+ }
43
+ };
44
+
45
+ TrustGeneratorFactory.register('jwt', () => generator);
46
+ TrustVerifierFactory.register('jwt', () => verifier);
47
+
48
+ const trustService = new TrustService({
49
+ config: {
50
+ defaultGeneratorType: 'jwt'
51
+ }
52
+ });
53
+
54
+ console.log(trustService.className()); // TrustService
55
+
56
+ const payload = await trustService.generate('did:example:issuer', 'jwt', {
57
+ subject: {
58
+ id: 'did:example:subject',
59
+ level: 'gold'
60
+ }
61
+ });
62
+
63
+ console.log(payload); // { token: "eyJhbGciOiJFZERTQSJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTppc3N1ZXIifQ.signature", identity: "did:example:issuer", subject: { id: "did:example:subject", level: "gold" } }
64
+
65
+ const verification = await trustService.verify(payload, ['jwt']);
66
+
67
+ console.log(verification.verified); // true
68
+ console.log(verification.info?.identity); // did:example:issuer
69
+ ```
@@ -28,7 +28,7 @@ The options for the service.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,9 +54,9 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### verify()
57
+ ### verify() {#verify}
58
58
 
59
- > **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`: `IJsonLdNodeObject`[]; `failures?`: \{\[`id`: `string`\]: `IError`[]; \}; \}\>
59
+ > **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`: `ITrustVerificationInfo`; `errors?`: `IError`[]; \}\>
60
60
 
61
61
  Verify a payload by checking the validity of its structure and content using the registered verifiers.
62
62
 
@@ -76,10 +76,69 @@ List of verifiers to use instead of the default ones.
76
76
 
77
77
  #### Returns
78
78
 
79
- `Promise`\<\{ `verified`: `boolean`; `info?`: `IJsonLdNodeObject`[]; `failures?`: \{\[`id`: `string`\]: `IError`[]; \}; \}\>
79
+ `Promise`\<\{ `verified`: `boolean`; `info?`: `ITrustVerificationInfo`; `errors?`: `IError`[]; \}\>
80
80
 
81
- Whether the payload is verified and any additional information extracted from the payload, or failures per verifier.
81
+ Whether the payload is verified and any additional information extracted from the payload, or verification errors.
82
82
 
83
83
  #### Implementation of
84
84
 
85
85
  `ITrustComponent.verify`
86
+
87
+ ***
88
+
89
+ ### generate() {#generate}
90
+
91
+ > **generate**(`identity`, `generatorType?`, `info?`, `tenantId?`, `organizationId?`, `options?`): `Promise`\<`unknown`\>
92
+
93
+ Generate a payload using the specified generators.
94
+
95
+ #### Parameters
96
+
97
+ ##### identity
98
+
99
+ `string`
100
+
101
+ The identity for which to generate the payload.
102
+
103
+ ##### generatorType?
104
+
105
+ `string`
106
+
107
+ The type of generator to use, defaults to the default generator type or first in factory.
108
+
109
+ ##### info?
110
+
111
+ Optional information to include in the generated payload.
112
+
113
+ ##### tenantId?
114
+
115
+ `string`
116
+
117
+ Optional tenant identifier to embed in the payload.
118
+
119
+ ##### organizationId?
120
+
121
+ `string`
122
+
123
+ Optional organization identifier to embed in the payload.
124
+
125
+ ##### options?
126
+
127
+ Per-call generation options.
128
+
129
+ ###### tokenTtlInSeconds
130
+
131
+ `number`
132
+
133
+ TTL override in seconds for this token only. Takes precedence over the
134
+ config-level `tokenTtlInSeconds` when provided.
135
+
136
+ #### Returns
137
+
138
+ `Promise`\<`unknown`\>
139
+
140
+ The generated payload.
141
+
142
+ #### Implementation of
143
+
144
+ `ITrustComponent.generate`
@@ -6,4 +6,5 @@
6
6
 
7
7
  ## Interfaces
8
8
 
9
+ - [ITrustServiceConfig](interfaces/ITrustServiceConfig.md)
9
10
  - [ITrustServiceConstructorOptions](interfaces/ITrustServiceConstructorOptions.md)
@@ -0,0 +1,11 @@
1
+ # Interface: ITrustServiceConfig
2
+
3
+ The options for the trust service.
4
+
5
+ ## Properties
6
+
7
+ ### defaultGeneratorType? {#defaultgeneratortype}
8
+
9
+ > `optional` **defaultGeneratorType?**: `string`
10
+
11
+ The default generator type, uses first in factory if not specified.
@@ -4,9 +4,9 @@ The options for the trust service.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### loggingComponentType?
7
+ ### loggingComponentType? {#loggingcomponenttype}
8
8
 
9
- > `optional` **loggingComponentType**: `string`
9
+ > `optional` **loggingComponentType?**: `string`
10
10
 
11
11
  The logging component type.
12
12
 
@@ -15,3 +15,11 @@ The logging component type.
15
15
  ```ts
16
16
  logging
17
17
  ```
18
+
19
+ ***
20
+
21
+ ### config? {#config}
22
+
23
+ > `optional` **config?**: [`ITrustServiceConfig`](ITrustServiceConfig.md)
24
+
25
+ The trust service configuration.
package/locales/en.json CHANGED
@@ -2,12 +2,14 @@
2
2
  "info": {
3
3
  "trustService": {
4
4
  "verifying": "Verifying payload: \"{payload}\"",
5
- "verified": "Payload verified successfully: \"{info}\""
5
+ "verified": "Payload verified successfully"
6
6
  }
7
7
  },
8
8
  "error": {
9
9
  "trustService": {
10
- "notVerified": "Payload verification failed: \"{failures}\""
10
+ "notVerified": "Payload verification failed",
11
+ "noGeneratorsRegistered": "No trust generators are registered in the factory",
12
+ "noVerifiersRegistered": "No trust verifiers are registered in the factory"
11
13
  }
12
14
  }
13
15
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/trust-service",
3
- "version": "0.0.3-next.2",
4
- "description": "Trust service implementation",
3
+ "version": "0.0.3-next.20",
4
+ "description": "Provides an orchestrating trust service that composes generators and verifiers into a unified API",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/trust.git",
7
+ "url": "git+https://github.com/iotaledger/twin-trust.git",
8
8
  "directory": "packages/trust-service"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -15,10 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/data-json-ld": "next",
19
18
  "@twin.org/logging-models": "next",
20
19
  "@twin.org/nameof": "next",
21
- "@twin.org/trust-models": "0.0.3-next.2"
20
+ "@twin.org/trust-models": "0.0.3-next.20"
22
21
  },
23
22
  "main": "./dist/es/index.js",
24
23
  "types": "./dist/types/index.d.ts",
@@ -49,7 +48,7 @@
49
48
  "business-logic"
50
49
  ],
51
50
  "bugs": {
52
- "url": "git+https://github.com/twinfoundation/trust/issues"
51
+ "url": "git+https://github.com/iotaledger/twin-trust/issues"
53
52
  },
54
53
  "homepage": "https://twindev.org"
55
54
  }