@twin.org/trust-generators 0.0.3-next.4 → 0.0.3-next.5
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/generators/jwtVerifiableCredentialGenerator.js +4 -4
- package/dist/es/generators/jwtVerifiableCredentialGenerator.js.map +1 -1
- package/dist/types/generators/jwtVerifiableCredentialGenerator.d.ts +2 -3
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/JwtVerifiableCredentialGenerator.md +6 -6
- package/package.json +2 -2
|
@@ -49,19 +49,19 @@ export class JwtVerifiableCredentialGenerator {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Generate a trust payload.
|
|
52
|
+
* @param identity The identity for which to generate the payload.
|
|
52
53
|
* @param info Information to use in the generation.
|
|
53
|
-
* @param info.identity The identity issuing the verifiable credential.
|
|
54
54
|
* @param info.subject The subject of the verifiable credential.
|
|
55
55
|
* @returns The generated payload.
|
|
56
56
|
*/
|
|
57
|
-
async generate(info) {
|
|
58
|
-
Guards.stringValue(JwtVerifiableCredentialGenerator.CLASS_NAME, "
|
|
57
|
+
async generate(identity, info) {
|
|
58
|
+
Guards.stringValue(JwtVerifiableCredentialGenerator.CLASS_NAME, "identity", identity);
|
|
59
59
|
let expirationDate;
|
|
60
60
|
if (Is.integer(this._tokenTtlInSeconds)) {
|
|
61
61
|
const ttlMs = this._tokenTtlInSeconds * 1000;
|
|
62
62
|
expirationDate = new Date(Date.now() + ttlMs);
|
|
63
63
|
}
|
|
64
|
-
const credential = await this._identityComponent.verifiableCredentialCreate(
|
|
64
|
+
const credential = await this._identityComponent.verifiableCredentialCreate(identity, DocumentHelper.joinId(identity, this._verificationMethodId), info?.subject ?? {}, {
|
|
65
65
|
expirationDate
|
|
66
66
|
});
|
|
67
67
|
return credential;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtVerifiableCredentialGenerator.js","sourceRoot":"","sources":["../../../src/generators/jwtVerifiableCredentialGenerator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAA2B,MAAM,2BAA2B,CAAC;AAMpF;;GAEG;AACH,MAAM,OAAO,gCAAgC;IAC5C;;OAEG;IACI,MAAM,CAAU,UAAU,sCAAsD;IAEvF;;;OAGG;IACc,iBAAiB,CAAqB;IAEvD;;;OAGG;IACc,kBAAkB,CAAqB;IAExD;;;OAGG;IACc,qBAAqB,CAAS;IAE/C;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAA4D;QACvE,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,WAAW,CACpD,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QAEF,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAAC,CAAC;QAE7F,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACjE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,gCAAgC,CAAC,UAAU,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"jwtVerifiableCredentialGenerator.js","sourceRoot":"","sources":["../../../src/generators/jwtVerifiableCredentialGenerator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAA2B,MAAM,2BAA2B,CAAC;AAMpF;;GAEG;AACH,MAAM,OAAO,g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,EAAE,OAAO,IAAI,EAAE,EACnB;YACC,cAAc;SACd,CACD,CAAC;QAEF,OAAO,UAAU,CAAC;IACnB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { DocumentHelper, type IIdentityComponent } from \"@twin.org/identity-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ITrustGenerator } from \"@twin.org/trust-models\";\nimport type { IJwtVerifiableCredentialGeneratorConstructorOptions } from \"../models/IJwtVerifiableCredentialGeneratorConstructorOptions.js\";\n\n/**\n * Class to generate a JWT Verifiable Credential.\n */\nexport class JwtVerifiableCredentialGenerator implements ITrustGenerator {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JwtVerifiableCredentialGenerator>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _loggingComponent?: ILoggingComponent;\n\n\t/**\n\t * The identity component.\n\t * @internal\n\t */\n\tprivate readonly _identityComponent: IIdentityComponent;\n\n\t/**\n\t * The verification method ID for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _verificationMethodId: string;\n\n\t/**\n\t * The time-to-live (TTL) for token in seconds.\n\t * @internal\n\t */\n\tprivate readonly _tokenTtlInSeconds?: number;\n\n\t/**\n\t * Create a new instance of JwtVerifiableCredentialGenerator.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options: IJwtVerifiableCredentialGeneratorConstructorOptions) {\n\t\tthis._loggingComponent = ComponentFactory.getIfExists(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._identityComponent = ComponentFactory.get(options?.identityComponentType ?? \"identity\");\n\n\t\tthis._verificationMethodId = options.config.verificationMethodId;\n\t\tthis._tokenTtlInSeconds = options.config.tokenTtlInSeconds;\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 JwtVerifiableCredentialGenerator.CLASS_NAME;\n\t}\n\n\t/**\n\t * Generate a trust payload.\n\t * @param identity The identity for which to generate the payload.\n\t * @param info Information to use in the generation.\n\t * @param info.subject The subject of the verifiable credential.\n\t * @returns The generated payload.\n\t */\n\tpublic async generate(\n\t\tidentity: string,\n\t\tinfo?: { subject?: IJsonLdNodeObject }\n\t): Promise<unknown> {\n\t\tGuards.stringValue(JwtVerifiableCredentialGenerator.CLASS_NAME, nameof(identity), identity);\n\n\t\tlet expirationDate;\n\n\t\tif (Is.integer(this._tokenTtlInSeconds)) {\n\t\t\tconst ttlMs = this._tokenTtlInSeconds * 1000;\n\t\t\texpirationDate = new Date(Date.now() + ttlMs);\n\t\t}\n\n\t\tconst credential = await this._identityComponent.verifiableCredentialCreate(\n\t\t\tidentity,\n\t\t\tDocumentHelper.joinId(identity, this._verificationMethodId),\n\t\t\tinfo?.subject ?? {},\n\t\t\t{\n\t\t\t\texpirationDate\n\t\t\t}\n\t\t);\n\n\t\treturn credential;\n\t}\n}\n"]}
|
|
@@ -21,13 +21,12 @@ export declare class JwtVerifiableCredentialGenerator implements ITrustGenerator
|
|
|
21
21
|
className(): string;
|
|
22
22
|
/**
|
|
23
23
|
* Generate a trust payload.
|
|
24
|
+
* @param identity The identity for which to generate the payload.
|
|
24
25
|
* @param info Information to use in the generation.
|
|
25
|
-
* @param info.identity The identity issuing the verifiable credential.
|
|
26
26
|
* @param info.subject The subject of the verifiable credential.
|
|
27
27
|
* @returns The generated payload.
|
|
28
28
|
*/
|
|
29
|
-
generate(
|
|
30
|
-
identity: string;
|
|
29
|
+
generate(identity: string, info?: {
|
|
31
30
|
subject?: IJsonLdNodeObject;
|
|
32
31
|
}): Promise<unknown>;
|
|
33
32
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.5](https://github.com/twinfoundation/trust/compare/trust-generators-v0.0.3-next.4...trust-generators-v0.0.3-next.5) (2025-12-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add default generator config ([54d98ba](https://github.com/twinfoundation/trust/commit/54d98ba53b7450b56337daeda504437be0d21943))
|
|
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.4 to 0.0.3-next.5
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.4](https://github.com/twinfoundation/trust/compare/trust-generators-v0.0.3-next.3...trust-generators-v0.0.3-next.4) (2025-12-04)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -56,21 +56,21 @@ The class name of the component.
|
|
|
56
56
|
|
|
57
57
|
### generate()
|
|
58
58
|
|
|
59
|
-
> **generate**(`info
|
|
59
|
+
> **generate**(`identity`, `info?`): `Promise`\<`unknown`\>
|
|
60
60
|
|
|
61
61
|
Generate a trust payload.
|
|
62
62
|
|
|
63
63
|
#### Parameters
|
|
64
64
|
|
|
65
|
-
#####
|
|
65
|
+
##### identity
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
`string`
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
The identity for which to generate the payload.
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
##### info?
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
Information to use in the generation.
|
|
74
74
|
|
|
75
75
|
###### subject?
|
|
76
76
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/trust-generators",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.5",
|
|
4
4
|
"description": "Generators for trust",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@twin.org/identity-models": "next",
|
|
20
20
|
"@twin.org/logging-models": "next",
|
|
21
21
|
"@twin.org/nameof": "next",
|
|
22
|
-
"@twin.org/trust-models": "0.0.3-next.
|
|
22
|
+
"@twin.org/trust-models": "0.0.3-next.5",
|
|
23
23
|
"@twin.org/web": "next"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/es/index.js",
|