@twin.org/trust-service 0.0.3-next.4 → 0.0.3-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,6 +1,6 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- import { ComponentFactory, Guards, Is } from "@twin.org/core";
3
+ import { ComponentFactory, GeneralError, Guards, Is } from "@twin.org/core";
4
4
  import { TrustGeneratorFactory, TrustVerifierFactory } from "@twin.org/trust-models";
5
5
  /**
6
6
  * Class for performing trust operations.
@@ -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.
@@ -38,7 +44,7 @@ export class TrustService {
38
44
  async verify(payload, overrideVerifiers) {
39
45
  const verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();
40
46
  let verified = false;
41
- const info = {};
47
+ const info = { identity: "" };
42
48
  const errors = [];
43
49
  await this._loggingComponent?.log({
44
50
  level: "info",
@@ -80,20 +86,31 @@ export class TrustService {
80
86
  }
81
87
  return {
82
88
  verified,
83
- info: Object.keys(info).length > 0 ? info : undefined,
89
+ info: info.identity.length > 0 ? info : undefined,
84
90
  errors: errors.length > 0 ? errors : undefined
85
91
  };
86
92
  }
87
93
  /**
88
94
  * Generate a payload using the specified generators.
89
- * @param generatorType The type of generator to use.
95
+ * @param identity The identity for which to generate the payload.
96
+ * @param generatorType The type of generator to use, defaults to the default generator type or first in factory.
90
97
  * @param info Optional information to include in the generated payload.
91
98
  * @returns The generated payload.
92
99
  */
93
- async generate(generatorType, info) {
94
- Guards.stringValue(TrustService.CLASS_NAME, "generatorType", generatorType);
100
+ async generate(identity, generatorType, info) {
101
+ Guards.stringValue(TrustService.CLASS_NAME, "identity", identity);
102
+ if (Is.empty(generatorType)) {
103
+ generatorType = this._defaultGeneratorType;
104
+ if (Is.empty(generatorType)) {
105
+ const names = TrustGeneratorFactory.names();
106
+ if (names.length === 0) {
107
+ throw new GeneralError(TrustService.CLASS_NAME, "noGeneratorsRegistered");
108
+ }
109
+ generatorType = names[0];
110
+ }
111
+ }
95
112
  const generator = TrustGeneratorFactory.get(generatorType);
96
- return generator.generate(info);
113
+ return generator.generate(identity, info);
97
114
  }
98
115
  }
99
116
  //# 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,MAAM,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AAG3E,OAAO,EACN,qBAAqB,EACrB,oBAAoB,EAEpB,MAAM,wBAAwB,CAAC;AAGhC;;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;QAQ5B,MAAM,aAAa,GAAG,iBAAiB,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACxE,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,IAAI,GAA+B,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,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,CAAC;QAEH,KAAK,MAAM,YA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AU,mBAAyB,aAAa,CAAC,CAAC;QAElF,MAAM,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAE3D,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is, type IError } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\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 * 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 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?: {\n\t\t\t[key: string]: unknown;\n\t\t};\n\t\terrors?: IError[];\n\t}> {\n\t\tconst verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();\n\t\tlet verified = false;\n\t\tconst info: { [key: string]: unknown } = {};\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\tfor (const verifierName of verifierNames) {\n\t\t\tconst verifier = TrustVerifierFactory.get(verifierName);\n\t\t\tconst verifierResult = await verifier.verify(payload, info, errors);\n\n\t\t\tif (!Is.empty(verifierResult)) {\n\t\t\t\tverified = verifierResult;\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: Object.keys(info).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 generatorType The type of generator to use.\n\t * @param info Optional information to include in the generated payload.\n\t * @returns The generated payload.\n\t */\n\tpublic async generate(\n\t\tgeneratorType: string,\n\t\tinfo?: {\n\t\t\t[key: string]: unknown;\n\t\t}\n\t): Promise<unknown> {\n\t\tGuards.stringValue(TrustService.CLASS_NAME, nameof(generatorType), generatorType);\n\n\t\tconst generator = TrustGeneratorFactory.get(generatorType);\n\n\t\treturn generator.generate(info);\n\t}\n}\n"]}
1
+ {"version":3,"file":"trustService.js","sourceRoot":"","sources":["../../src/trustService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AAGzF,OAAO,EAEN,qBAAqB,EACrB,oBAAoB,EAEpB,MAAM,wBAAwB,CAAC;AAGhC;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB;;OAEG;IACI,MAAM,CAAU,UAAU,kBAAkC;IAEnE;;;OAGG;IACc,iBAAiB,CAAqB;IAEvD;;;OAGG;IACc,qBAAqB,CAAU;IAEhD;;;OAGG;IACH,YAAY,OAAyC;QACpD,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,WAAW,CACpD,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC;IACpE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,YAAY,CAAC,UAAU,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAClB,OAAgB,EAChB,iBAA4B;QAS5B,MAAM,aAAa,GAAG,iBAAiB,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACxE,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,MAAM,IAAI,GAA2B,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACtD,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,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,CAA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AAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,CACpB,QAAgB,EAChB,aAAsB,EACtB,IAEC;QAED,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,CAAC,CAAC;IAC3C,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?: {\n\t\t\t[key: string]: unknown;\n\t\t\tidentity: string;\n\t\t};\n\t\terrors?: IError[];\n\t}> {\n\t\tconst verifierNames = overrideVerifiers ?? TrustVerifierFactory.names();\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\tfor (const verifierName of verifierNames) {\n\t\t\tconst verifier = TrustVerifierFactory.get(verifierName);\n\t\t\tconst verifierResult = await verifier.verify(payload, info, errors);\n\n\t\t\tif (!Is.empty(verifierResult)) {\n\t\t\t\tverified = verifierResult;\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 * @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): 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);\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
  }
@@ -29,16 +29,18 @@ export declare class TrustService implements ITrustComponent {
29
29
  verified: boolean;
30
30
  info?: {
31
31
  [key: string]: unknown;
32
+ identity: string;
32
33
  };
33
34
  errors?: IError[];
34
35
  }>;
35
36
  /**
36
37
  * Generate a payload using the specified generators.
37
- * @param generatorType The type of generator to use.
38
+ * @param identity The identity for which to generate the payload.
39
+ * @param generatorType The type of generator to use, defaults to the default generator type or first in factory.
38
40
  * @param info Optional information to include in the generated payload.
39
41
  * @returns The generated payload.
40
42
  */
41
- generate(generatorType: string, info?: {
43
+ generate(identity: string, generatorType?: string, info?: {
42
44
  [key: string]: unknown;
43
45
  }): Promise<unknown>;
44
46
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.6](https://github.com/twinfoundation/trust/compare/trust-service-v0.0.3-next.5...trust-service-v0.0.3-next.6) (2025-12-04)
4
+
5
+
6
+ ### Features
7
+
8
+ * always include identity in verification info ([9594d19](https://github.com/twinfoundation/trust/commit/9594d19e9d718bd42b82964750ae3bcfb7df51bf))
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.5 to 0.0.3-next.6
16
+
17
+ ## [0.0.3-next.5](https://github.com/twinfoundation/trust/compare/trust-service-v0.0.3-next.4...trust-service-v0.0.3-next.5) (2025-12-04)
18
+
19
+
20
+ ### Features
21
+
22
+ * add default generator config ([54d98ba](https://github.com/twinfoundation/trust/commit/54d98ba53b7450b56337daeda504437be0d21943))
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.4 to 0.0.3-next.5
30
+
3
31
  ## [0.0.3-next.4](https://github.com/twinfoundation/trust/compare/trust-service-v0.0.3-next.3...trust-service-v0.0.3-next.4) (2025-12-04)
4
32
 
5
33
 
@@ -56,7 +56,7 @@ The class name of the component.
56
56
 
57
57
  ### verify()
58
58
 
59
- > **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`: \{\[`key`: `string`\]: `unknown`; \}; `errors?`: `IError`[]; \}\>
59
+ > **verify**(`payload`, `overrideVerifiers?`): `Promise`\<\{ `verified`: `boolean`; `info?`: \{\[`key`: `string`\]: `unknown`; `identity`: `string`; \}; `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,7 +76,7 @@ List of verifiers to use instead of the default ones.
76
76
 
77
77
  #### Returns
78
78
 
79
- `Promise`\<\{ `verified`: `boolean`; `info?`: \{\[`key`: `string`\]: `unknown`; \}; `errors?`: `IError`[]; \}\>
79
+ `Promise`\<\{ `verified`: `boolean`; `info?`: \{\[`key`: `string`\]: `unknown`; `identity`: `string`; \}; `errors?`: `IError`[]; \}\>
80
80
 
81
81
  Whether the payload is verified and any additional information extracted from the payload, or verification errors.
82
82
 
@@ -88,17 +88,23 @@ Whether the payload is verified and any additional information extracted from th
88
88
 
89
89
  ### generate()
90
90
 
91
- > **generate**(`generatorType`, `info?`): `Promise`\<`unknown`\>
91
+ > **generate**(`identity`, `generatorType?`, `info?`): `Promise`\<`unknown`\>
92
92
 
93
93
  Generate a payload using the specified generators.
94
94
 
95
95
  #### Parameters
96
96
 
97
- ##### generatorType
97
+ ##### identity
98
98
 
99
99
  `string`
100
100
 
101
- The type of generator to use.
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.
102
108
 
103
109
  ##### info?
104
110
 
@@ -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?
8
+
9
+ > `optional` **defaultGeneratorType**: `string`
10
+
11
+ The default generator type, uses first in factory if not specified.
@@ -15,3 +15,11 @@ The logging component type.
15
15
  ```ts
16
16
  logging
17
17
  ```
18
+
19
+ ***
20
+
21
+ ### config?
22
+
23
+ > `optional` **config**: [`ITrustServiceConfig`](ITrustServiceConfig.md)
24
+
25
+ The trust service configuration.
package/locales/en.json CHANGED
@@ -7,7 +7,8 @@
7
7
  },
8
8
  "error": {
9
9
  "trustService": {
10
- "notVerified": "Payload verification failed"
10
+ "notVerified": "Payload verification failed",
11
+ "noGeneratorsRegistered": "No trust generators are registered in the factory"
11
12
  }
12
13
  }
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/trust-service",
3
- "version": "0.0.3-next.4",
3
+ "version": "0.0.3-next.6",
4
4
  "description": "Trust service implementation",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/logging-models": "next",
19
19
  "@twin.org/nameof": "next",
20
- "@twin.org/trust-models": "0.0.3-next.4"
20
+ "@twin.org/trust-models": "0.0.3-next.6"
21
21
  },
22
22
  "main": "./dist/es/index.js",
23
23
  "types": "./dist/types/index.d.ts",