@truvity/sdk 0.28.9 → 0.30.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/api/resources/apiKeys/client/Client.js +9 -9
- package/api/resources/apiKeys/client/Client.js.map +1 -1
- package/api/resources/credentials/client/Client.js +12 -12
- package/api/resources/credentials/client/Client.js.map +1 -1
- package/api/resources/desk/client/Client.js +2 -2
- package/api/resources/desk/client/Client.js.map +1 -1
- package/api/resources/didcommMessages/client/Client.js +9 -9
- package/api/resources/didcommMessages/client/Client.js.map +1 -1
- package/api/resources/dids/client/Client.js +1 -1
- package/api/resources/dids/client/Client.js.map +1 -1
- package/api/resources/drafts/client/Client.js +12 -12
- package/api/resources/drafts/client/Client.js.map +1 -1
- package/api/resources/files/client/Client.js +12 -12
- package/api/resources/files/client/Client.js.map +1 -1
- package/api/resources/gdpr/client/Client.js +1 -1
- package/api/resources/gdpr/client/Client.js.map +1 -1
- package/api/resources/keys/client/Client.js +13 -13
- package/api/resources/keys/client/Client.js.map +1 -1
- package/api/resources/presentations/client/Client.js +14 -14
- package/api/resources/presentations/client/Client.js.map +1 -1
- package/api/types/Credential.d.ts +1 -1
- package/api/types/Credential.d.ts.map +1 -1
- package/api/types/Credential.js.map +1 -1
- package/api/types/File_.d.ts +1 -1
- package/api/types/File_.d.ts.map +1 -1
- package/api/types/File_.js.map +1 -1
- package/api/types/Presentation.d.ts +1 -1
- package/api/types/Presentation.d.ts.map +1 -1
- package/api/types/Presentation.js.map +1 -1
- package/documents/credential/claims.d.ts +29 -0
- package/documents/credential/claims.d.ts.map +1 -0
- package/documents/credential/claims.js +228 -0
- package/documents/credential/claims.js.map +1 -0
- package/documents/credential/claims.spec.d.ts +2 -0
- package/documents/credential/claims.spec.d.ts.map +1 -0
- package/documents/credential/{document.spec.js → claims.spec.js} +77 -129
- package/documents/credential/claims.spec.js.map +1 -0
- package/documents/credential/document/vcdm.d.ts +50 -0
- package/documents/credential/document/vcdm.d.ts.map +1 -0
- package/documents/credential/document/vcdm.js +76 -0
- package/documents/credential/document/vcdm.js.map +1 -0
- package/documents/credential/document.d.ts +6 -24
- package/documents/credential/document.d.ts.map +1 -1
- package/documents/credential/document.js +15 -137
- package/documents/credential/document.js.map +1 -1
- package/documents/credential/draft.d.ts +7 -5
- package/documents/credential/draft.d.ts.map +1 -1
- package/documents/credential/draft.js +15 -14
- package/documents/credential/draft.js.map +1 -1
- package/documents/credential/flavor/vcdm1_1.d.ts +76 -0
- package/documents/credential/flavor/vcdm1_1.d.ts.map +1 -0
- package/documents/credential/flavor/vcdm1_1.js +148 -0
- package/documents/credential/flavor/vcdm1_1.js.map +1 -0
- package/documents/credential/flavor/vcdm2_0.d.ts +83 -0
- package/documents/credential/flavor/vcdm2_0.d.ts.map +1 -0
- package/documents/credential/flavor/vcdm2_0.js +76 -0
- package/documents/credential/flavor/vcdm2_0.js.map +1 -0
- package/documents/credential/flavor.d.ts +8 -32
- package/documents/credential/flavor.d.ts.map +1 -1
- package/documents/credential/flavor.js +22 -99
- package/documents/credential/flavor.js.map +1 -1
- package/documents/credential/flavor.spec.js +31 -102
- package/documents/credential/flavor.spec.js.map +1 -1
- package/documents/credential/testdata/udt.d.ts +53 -0
- package/documents/credential/testdata/udt.d.ts.map +1 -0
- package/documents/credential/testdata/udt.js +243 -0
- package/documents/credential/testdata/udt.js.map +1 -0
- package/documents/credential/types.d.ts +39 -0
- package/documents/credential/types.d.ts.map +1 -0
- package/documents/credential/types.js +3 -0
- package/documents/credential/types.js.map +1 -0
- package/documents/credential/unknown.d.ts +5 -5
- package/documents/credential/unknown.d.ts.map +1 -1
- package/documents/credential/unknown.js +3 -4
- package/documents/credential/unknown.js.map +1 -1
- package/documents/credential/unknown.spec.js +12 -9
- package/documents/credential/unknown.spec.js.map +1 -1
- package/documents/credential/{baseVerifiableCredential.d.ts → verifiable.d.ts} +8 -5
- package/documents/credential/verifiable.d.ts.map +1 -0
- package/documents/credential/{baseVerifiableCredential.js → verifiable.js} +11 -7
- package/documents/credential/verifiable.js.map +1 -0
- package/documents/credential/with-claims.d.ts +15 -0
- package/documents/credential/with-claims.d.ts.map +1 -0
- package/documents/credential/{issued.js → with-claims.js} +12 -12
- package/documents/credential/with-claims.js.map +1 -0
- package/documents/credential.d.ts +13 -15
- package/documents/credential.d.ts.map +1 -1
- package/documents/credential.js +21 -102
- package/documents/credential.js.map +1 -1
- package/documents/index.d.ts +1 -0
- package/documents/index.d.ts.map +1 -1
- package/documents/index.js +1 -0
- package/documents/index.js.map +1 -1
- package/documents/models.d.ts +13 -13
- package/documents/models.d.ts.map +1 -1
- package/documents/models.js +4 -4
- package/documents/models.js.map +1 -1
- package/documents/presentation/issued.d.ts +1 -1
- package/documents/presentation/issued.d.ts.map +1 -1
- package/documents/presentation/issued.js +2 -2
- package/documents/presentation/issued.js.map +1 -1
- package/documents/presentation.d.ts +5 -5
- package/documents/presentation.d.ts.map +1 -1
- package/documents/presentation.js +4 -4
- package/documents/presentation.js.map +1 -1
- package/documents/types.d.ts +12 -32
- package/documents/types.d.ts.map +1 -1
- package/documents/types.js +25 -1
- package/documents/types.js.map +1 -1
- package/documents/utils/converters.d.ts +1 -1
- package/documents/utils/converters.d.ts.map +1 -1
- package/documents/utils/converters.js +1 -1
- package/documents/utils/converters.js.map +1 -1
- package/documents/utils/idempotency.d.ts +2 -0
- package/documents/utils/idempotency.d.ts.map +1 -0
- package/documents/utils/idempotency.js +9 -0
- package/documents/utils/idempotency.js.map +1 -0
- package/documents/utils/stream.d.ts +1 -0
- package/documents/utils/stream.d.ts.map +1 -1
- package/documents/utils/stream.js +3 -2
- package/documents/utils/stream.js.map +1 -1
- package/package.json +1 -1
- package/documents/credential/baseVerifiableCredential.d.ts.map +0 -1
- package/documents/credential/baseVerifiableCredential.js.map +0 -1
- package/documents/credential/document.spec.d.ts +0 -7
- package/documents/credential/document.spec.d.ts.map +0 -1
- package/documents/credential/document.spec.js.map +0 -1
- package/documents/credential/issued.d.ts +0 -13
- package/documents/credential/issued.d.ts.map +0 -1
- package/documents/credential/issued.js.map +0 -1
- package/documents/credential.spec.d.ts +0 -8
- package/documents/credential.spec.d.ts.map +0 -1
- package/documents/credential.spec.js +0 -246
- package/documents/credential.spec.js.map +0 -1
- package/documents/guards.d.ts +0 -6
- package/documents/guards.d.ts.map +0 -1
- package/documents/guards.js +0 -32
- package/documents/guards.js.map +0 -1
- package/documents/helpers.d.ts +0 -2
- package/documents/helpers.d.ts.map +0 -1
- package/documents/helpers.js +0 -9
- package/documents/helpers.js.map +0 -1
|
@@ -22,7 +22,7 @@ export interface Credential {
|
|
|
22
22
|
linkedCredentials?: string[];
|
|
23
23
|
/** A list of linked files. */
|
|
24
24
|
linkedFiles?: string[];
|
|
25
|
-
/** The multihash of canonical
|
|
25
|
+
/** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */
|
|
26
26
|
multihash?: string;
|
|
27
27
|
/** Timestamp string according to [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339). */
|
|
28
28
|
validUntil?: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Credential.d.ts","sourceRoot":"","sources":["../../../src/api/types/Credential.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC;IACvC,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,wFAAwF;IACxF,SAAS,EAAE,IAAI,CAAC;IAChB,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,
|
|
1
|
+
{"version":3,"file":"Credential.d.ts","sourceRoot":"","sources":["../../../src/api/types/Credential.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC;IACvC,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,wFAAwF;IACxF,SAAS,EAAE,IAAI,CAAC;IAChB,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,UAAU,CAAC,EAAE,IAAI,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Credential.js","sourceRoot":"","sources":["../../../src/api/types/Credential.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\nimport * as Truvity from '../index';\n\n/**\n * A generic representation of a verifiable crendential. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-credential).\n */\nexport interface Credential {\n /** A flavor specific representation of a verifiable crendential. */\n dataModel: Truvity.CredentialDataModel;\n /** The URI of a credential. */\n id: string;\n /** The URI of the credential issuer. */\n issuer: string;\n /** A list of credential types. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-type). */\n type: string[];\n /** Timestamp string according to [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339). */\n validFrom: Date;\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n holder?: string;\n /** A list of linked credentials. */\n linkedCredentials?: string[];\n /** A list of linked files. */\n linkedFiles?: string[];\n /** The multihash of canonical
|
|
1
|
+
{"version":3,"file":"Credential.js","sourceRoot":"","sources":["../../../src/api/types/Credential.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\nimport * as Truvity from '../index';\n\n/**\n * A generic representation of a verifiable crendential. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-credential).\n */\nexport interface Credential {\n /** A flavor specific representation of a verifiable crendential. */\n dataModel: Truvity.CredentialDataModel;\n /** The URI of a credential. */\n id: string;\n /** The URI of the credential issuer. */\n issuer: string;\n /** A list of credential types. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-type). */\n type: string[];\n /** Timestamp string according to [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339). */\n validFrom: Date;\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n holder?: string;\n /** A list of linked credentials. */\n linkedCredentials?: string[];\n /** A list of linked files. */\n linkedFiles?: string[];\n /** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */\n multihash?: string;\n /** Timestamp string according to [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339). */\n validUntil?: Date;\n}\n"]}
|
package/api/types/File_.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface File_ {
|
|
|
11
11
|
contentType: string;
|
|
12
12
|
/** The size of the file in bytes. */
|
|
13
13
|
filesize: number;
|
|
14
|
-
/** The multihash of canonical
|
|
14
|
+
/** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */
|
|
15
15
|
multihash: string;
|
|
16
16
|
/** Primitive string type. */
|
|
17
17
|
filename: string;
|
package/api/types/File_.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File_.d.ts","sourceRoot":"","sources":["../../../src/api/types/File_.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,KAAK;IAClB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,
|
|
1
|
+
{"version":3,"file":"File_.d.ts","sourceRoot":"","sources":["../../../src/api/types/File_.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,KAAK;IAClB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,0GAA0G;IAC1G,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;CACpB"}
|
package/api/types/File_.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File_.js","sourceRoot":"","sources":["../../../src/api/types/File_.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\n/**\n * A file object that can be used to read a file resource.\n */\nexport interface File_ {\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n id: string;\n /** Primitive string type. */\n contentType: string;\n /** The size of the file in bytes. */\n filesize: number;\n /** The multihash of canonical
|
|
1
|
+
{"version":3,"file":"File_.js","sourceRoot":"","sources":["../../../src/api/types/File_.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\n/**\n * A file object that can be used to read a file resource.\n */\nexport interface File_ {\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n id: string;\n /** Primitive string type. */\n contentType: string;\n /** The size of the file in bytes. */\n filesize: number;\n /** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */\n multihash: string;\n /** Primitive string type. */\n filename: string;\n}\n"]}
|
|
@@ -11,7 +11,7 @@ export interface Presentation {
|
|
|
11
11
|
id: string;
|
|
12
12
|
/** A list of linked credentials. */
|
|
13
13
|
linkedCredentials?: string[];
|
|
14
|
-
/** The multihash of canonical
|
|
14
|
+
/** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */
|
|
15
15
|
multihash: string;
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=Presentation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Presentation.d.ts","sourceRoot":"","sources":["../../../src/api/types/Presentation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,
|
|
1
|
+
{"version":3,"file":"Presentation.d.ts","sourceRoot":"","sources":["../../../src/api/types/Presentation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,0GAA0G;IAC1G,SAAS,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Presentation.js","sourceRoot":"","sources":["../../../src/api/types/Presentation.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\n/**\n * A presentation of credentials. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-presentations).\n */\nexport interface Presentation {\n /** A list of presentation types. */\n type?: string[];\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n id: string;\n /** A list of linked credentials. */\n linkedCredentials?: string[];\n /** The multihash of canonical
|
|
1
|
+
{"version":3,"file":"Presentation.js","sourceRoot":"","sources":["../../../src/api/types/Presentation.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * This file was auto-generated by Fern from our API Definition.\n */\n\n/**\n * A presentation of credentials. [Terminology](https://www.w3.org/TR/vc-data-model/#dfn-presentations).\n */\nexport interface Presentation {\n /** A list of presentation types. */\n type?: string[];\n /** Just regular URI according to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986). */\n id: string;\n /** A list of linked credentials. */\n linkedCredentials?: string[];\n /** The multihash of canonical body. [Multihash](https://www.w3.org/TR/controller-document/#multihash). */\n multihash: string;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ApiClient, Claims, Ctor, UserUpdateClaims, ReadDraftClaims, ReadClaims } from '../types';
|
|
2
|
+
import { ClaimDescriptor } from '../decorators';
|
|
3
|
+
import { DraftSchema, DraftSchemaFieldsItem } from '../../api';
|
|
4
|
+
import { CredentialClaims, Json } from './types';
|
|
5
|
+
export declare class UdtClaims<T extends Claims> {
|
|
6
|
+
protected client: ApiClient;
|
|
7
|
+
protected claimsModel: Ctor<T>;
|
|
8
|
+
constructor(client: ApiClient, claimsModel: Ctor<T>);
|
|
9
|
+
private processValues;
|
|
10
|
+
private getClaimTypeInfo;
|
|
11
|
+
/** convertApiValuesToUdt maps and converts the API received claims values to the UDT claims model */
|
|
12
|
+
protected convertApiValuesToUdt<K extends Claims>(model: Ctor<any>, input: Json): K;
|
|
13
|
+
/** convertUdtToApiValues maps and converts the user received claims values onto UDT claims model */
|
|
14
|
+
protected convertUdtToApiValues<K extends Claims>(model: Ctor<any>, input: K): CredentialClaims;
|
|
15
|
+
protected mapClaimToApi(claim: ClaimDescriptor, claimsModel: Ctor<any>): DraftSchemaFieldsItem;
|
|
16
|
+
/**
|
|
17
|
+
* Marshalling is the process of transforming the internal representation of values to a data format suitable
|
|
18
|
+
* for transmission.
|
|
19
|
+
*/
|
|
20
|
+
marshalValues(input: UserUpdateClaims<T>): Json;
|
|
21
|
+
/**
|
|
22
|
+
* Unmarshalling is the reverse process of marshalling. It involves converting data from a serialized format back
|
|
23
|
+
* into an internal representation.
|
|
24
|
+
*/
|
|
25
|
+
unmarshalValuesToDraft(input: Json): ReadDraftClaims<T>;
|
|
26
|
+
unmarshalValuesToCredential(input: Json): ReadClaims<T>;
|
|
27
|
+
getDraftSchema(): DraftSchema | undefined;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=claims.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.d.ts","sourceRoot":"","sources":["../../../src/documents/credential/claims.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,MAAM,EACN,IAAI,EAGJ,gBAAgB,EAChB,eAAe,EACf,UAAU,EACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,eAAe,EAOlB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,gBAAgB,EAAmB,IAAI,EAAE,MAAM,SAAS,CAAC;AAGlE,qBAAa,SAAS,CAAC,CAAC,SAAS,MAAM;IAE/B,SAAS,CAAC,MAAM,EAAE,SAAS;IAC3B,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;gBADpB,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAGlC,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,gBAAgB;IAYxB,qGAAqG;IACrG,SAAS,CAAC,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC;IAgEnF,oGAAoG;IACpG,SAAS,CAAC,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB;IA0D/F,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,qBAAqB;IAgG9F;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAI/C;;;OAGG;IACH,sBAAsB,CAAC,KAAK,EAAE,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC;IAIvD,2BAA2B,CAAC,KAAK,EAAE,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;IAIvD,cAAc,IAAI,WAAW,GAAG,SAAS;CAc5C"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.UdtClaims = void 0;
|
|
27
|
+
const types_1 = require("../types");
|
|
28
|
+
const decorators_1 = require("../decorators");
|
|
29
|
+
const models_1 = require("../models");
|
|
30
|
+
const converters_1 = require("../utils/converters");
|
|
31
|
+
const serialization = __importStar(require("../../serialization"));
|
|
32
|
+
const verifiable_1 = require("./verifiable");
|
|
33
|
+
class UdtClaims {
|
|
34
|
+
constructor(client, claimsModel) {
|
|
35
|
+
this.client = client;
|
|
36
|
+
this.claimsModel = claimsModel;
|
|
37
|
+
}
|
|
38
|
+
processValues(model, input, processValue, initialValue) {
|
|
39
|
+
return (0, decorators_1.getRegisteredClaimsList)(model).reduce((result, descriptor) => {
|
|
40
|
+
if (descriptor.name in input) {
|
|
41
|
+
const value = input[descriptor.name];
|
|
42
|
+
let processedValue;
|
|
43
|
+
if (descriptor.isArray) {
|
|
44
|
+
if (value == null) {
|
|
45
|
+
processedValue = null;
|
|
46
|
+
}
|
|
47
|
+
else if (Array.isArray(value)) {
|
|
48
|
+
processedValue = value.map((item) => {
|
|
49
|
+
return processValue(descriptor, item);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "Array". Please reach out to support for assistance.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
processedValue = processValue(descriptor, value);
|
|
58
|
+
}
|
|
59
|
+
Reflect.set(result, descriptor.name, processedValue);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}, initialValue);
|
|
63
|
+
}
|
|
64
|
+
getClaimTypeInfo(model, descriptor) {
|
|
65
|
+
const typeInfo = descriptor.nestedType ? descriptor.nestedType : (0, decorators_1.getTsDataTypeMetadata)(model, descriptor.name);
|
|
66
|
+
if (typeInfo == null) {
|
|
67
|
+
throw new Error(`Can't convert received value. Inconsistent data definition. Please reach out to support for assistance.`);
|
|
68
|
+
}
|
|
69
|
+
return typeInfo;
|
|
70
|
+
}
|
|
71
|
+
/** convertApiValuesToUdt maps and converts the API received claims values to the UDT claims model */
|
|
72
|
+
convertApiValuesToUdt(model, input) {
|
|
73
|
+
const processValue = (descriptor, value) => {
|
|
74
|
+
if (value == null) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if ((0, types_1.isLinkedEntityDescriptor)(value)) {
|
|
78
|
+
const isLinkedCredential = (0, decorators_1.getClaimLinkedCredentialMetadata)(model, descriptor.name);
|
|
79
|
+
if (isLinkedCredential) {
|
|
80
|
+
return new models_1.LinkedCredential(this.client, value.id, value.digestMultibase);
|
|
81
|
+
}
|
|
82
|
+
const isLinkedFile = (0, decorators_1.getClaimLinkedFileMetadata)(model, descriptor.name);
|
|
83
|
+
if (isLinkedFile) {
|
|
84
|
+
return new models_1.LinkedFile(this.client, value.id, value.digestMultibase);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const typeInfo = this.getClaimTypeInfo(model, descriptor);
|
|
88
|
+
if (typeInfo === Date) {
|
|
89
|
+
if (typeof value !== 'string') {
|
|
90
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "Date". Please reach out to support for assistance.`);
|
|
91
|
+
}
|
|
92
|
+
return new Date(value);
|
|
93
|
+
}
|
|
94
|
+
if (typeInfo === models_1.Rfc3339DateTime) {
|
|
95
|
+
if (typeof value !== 'string') {
|
|
96
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "Rfc3339DateTime". Please reach out to support for assistance.`);
|
|
97
|
+
}
|
|
98
|
+
return new models_1.Rfc3339DateTime(value);
|
|
99
|
+
}
|
|
100
|
+
if (typeInfo === models_1.Rfc3339Date) {
|
|
101
|
+
if (typeof value !== 'string') {
|
|
102
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "Rfc3339Date". Please reach out to support for assistance.`);
|
|
103
|
+
}
|
|
104
|
+
return new models_1.Rfc3339Date(value);
|
|
105
|
+
}
|
|
106
|
+
// Primitive values should be returned as-is
|
|
107
|
+
if (Array.of(String, Number, Boolean, Object).includes(typeInfo)) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
if (!(value instanceof Object)) {
|
|
111
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "${typeInfo.name}". Please reach out to support for assistance.`);
|
|
112
|
+
}
|
|
113
|
+
return this.convertApiValuesToUdt(typeInfo, value);
|
|
114
|
+
};
|
|
115
|
+
return this.processValues(model, input, processValue, new model());
|
|
116
|
+
}
|
|
117
|
+
/** convertUdtToApiValues maps and converts the user received claims values onto UDT claims model */
|
|
118
|
+
convertUdtToApiValues(model, input) {
|
|
119
|
+
const processValue = (descriptor, value) => {
|
|
120
|
+
if (value == null) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const typeInfo = this.getClaimTypeInfo(model, descriptor);
|
|
124
|
+
if ((0, decorators_1.getClaimLinkedCredentialMetadata)(model, descriptor.name)) {
|
|
125
|
+
if (value instanceof models_1.LinkedCredential) {
|
|
126
|
+
return value.toJSON();
|
|
127
|
+
}
|
|
128
|
+
if (value instanceof verifiable_1.VerifiableCredential) {
|
|
129
|
+
return value.toLinkedCredential().toJSON();
|
|
130
|
+
}
|
|
131
|
+
if ((0, types_1.isValueWithId)(value)) {
|
|
132
|
+
return models_1.LinkedCredential.createClaimValue(value.id, value.digestMultibase);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if ((0, decorators_1.getClaimLinkedFileMetadata)(model, descriptor.name)) {
|
|
136
|
+
if (value instanceof models_1.LinkedFile) {
|
|
137
|
+
return value.toJSON();
|
|
138
|
+
}
|
|
139
|
+
if ((0, types_1.isValueWithId)(value)) {
|
|
140
|
+
return models_1.LinkedFile.createClaimValue(value.id, value.digestMultibase);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (Array.of(String, Number, Date, models_1.Rfc3339DateTime, models_1.Rfc3339Date, Boolean, Object, Function).includes(typeInfo)) {
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
if (!(value instanceof Object)) {
|
|
147
|
+
throw new Error(`Can't convert received value as it has an unexpected type. The value is defined in UDT as "${typeInfo.name}". Please reach out to support for assistance.`);
|
|
148
|
+
}
|
|
149
|
+
return this.convertUdtToApiValues(typeInfo, value);
|
|
150
|
+
};
|
|
151
|
+
return this.processValues(model, input, processValue, {});
|
|
152
|
+
}
|
|
153
|
+
mapClaimToApi(claim, claimsModel) {
|
|
154
|
+
const claimJsonLdType = (0, decorators_1.getClaimJsonLdTypeMetadata)(claimsModel, claim.name);
|
|
155
|
+
const draftBaseFieldValue = {
|
|
156
|
+
name: claim.name,
|
|
157
|
+
title: claim.title,
|
|
158
|
+
notEmpty: claim.notEmpty,
|
|
159
|
+
isArray: claim.isArray || undefined,
|
|
160
|
+
};
|
|
161
|
+
if ((0, decorators_1.getClaimLinkedCredentialMetadata)(claimsModel, claim.name)) {
|
|
162
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'LINK', linkType: undefined }));
|
|
163
|
+
}
|
|
164
|
+
if ((0, decorators_1.getClaimLinkedFileMetadata)(claimsModel, claim.name)) {
|
|
165
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'FILE' }));
|
|
166
|
+
}
|
|
167
|
+
if (claim.nestedType &&
|
|
168
|
+
!Array.of(String, Number, Date, models_1.Rfc3339DateTime, models_1.Rfc3339Date, Boolean).includes(claim.nestedType)) {
|
|
169
|
+
const claimNestedType = claim.nestedType;
|
|
170
|
+
const nestedContextInfo = (0, decorators_1.getContextJsonLdMetadata)(claimNestedType);
|
|
171
|
+
if (!nestedContextInfo) {
|
|
172
|
+
throw new Error(`The information about the VC context was not found in the "${claimNestedType.name}" model. Please use the "@VcContext" decorator to define the necessary information.`);
|
|
173
|
+
}
|
|
174
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'STRUCT', fields: (0, decorators_1.getRegisteredClaimsList)(claimNestedType).map((nestedClaim) => {
|
|
175
|
+
return this.mapClaimToApi(nestedClaim, claimNestedType);
|
|
176
|
+
}), vocabNamespace: nestedContextInfo.namespace, vocabName: nestedContextInfo.name }));
|
|
177
|
+
}
|
|
178
|
+
const tsDataType = claim.nestedType || (0, decorators_1.getTsDataTypeMetadata)(claimsModel, claim.name);
|
|
179
|
+
if (!tsDataType) {
|
|
180
|
+
throw new Error(`The information about the VC claim data type was not found for the "${claim.name}" property. Ensure that "emitDecoratorMetadata" is enabled in your "tsconfig.json".`);
|
|
181
|
+
}
|
|
182
|
+
switch (tsDataType) {
|
|
183
|
+
case String:
|
|
184
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'STRING', type: claimJsonLdType, enum: claim.enumValuesDescriptor }));
|
|
185
|
+
case Number:
|
|
186
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'NUMBER', type: claimJsonLdType }));
|
|
187
|
+
case Boolean:
|
|
188
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'BOOLEAN', type: claimJsonLdType }));
|
|
189
|
+
case models_1.Rfc3339Date:
|
|
190
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'DATE', type: claimJsonLdType }));
|
|
191
|
+
case models_1.Rfc3339DateTime:
|
|
192
|
+
case Date:
|
|
193
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchemaFieldsItem, Object.assign(Object.assign({}, draftBaseFieldValue), { kind: 'DATETIME', type: claimJsonLdType }));
|
|
194
|
+
default:
|
|
195
|
+
throw new Error(`Unsupported primitive data type: ${tsDataType.name}. Please use one of the supported types. You can find more information in the documentation.`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Marshalling is the process of transforming the internal representation of values to a data format suitable
|
|
200
|
+
* for transmission.
|
|
201
|
+
*/
|
|
202
|
+
marshalValues(input) {
|
|
203
|
+
return this.convertUdtToApiValues(this.claimsModel, input);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Unmarshalling is the reverse process of marshalling. It involves converting data from a serialized format back
|
|
207
|
+
* into an internal representation.
|
|
208
|
+
*/
|
|
209
|
+
unmarshalValuesToDraft(input) {
|
|
210
|
+
return this.convertApiValuesToUdt(this.claimsModel, input);
|
|
211
|
+
}
|
|
212
|
+
unmarshalValuesToCredential(input) {
|
|
213
|
+
return this.convertApiValuesToUdt(this.claimsModel, input);
|
|
214
|
+
}
|
|
215
|
+
getDraftSchema() {
|
|
216
|
+
const vcContextMetadata = (0, decorators_1.getContextJsonLdMetadata)(this.claimsModel);
|
|
217
|
+
if (!vcContextMetadata)
|
|
218
|
+
return undefined;
|
|
219
|
+
return (0, converters_1.strictlyConvertToApiType)(serialization.DraftSchema, {
|
|
220
|
+
fields: (0, decorators_1.getRegisteredClaimsList)(this.claimsModel).map((claim) => this.mapClaimToApi(claim, this.claimsModel)),
|
|
221
|
+
vocabNamespace: vcContextMetadata.namespace,
|
|
222
|
+
vocabName: vcContextMetadata.name,
|
|
223
|
+
vcType: vcContextMetadata.vcType,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.UdtClaims = UdtClaims;
|
|
228
|
+
//# sourceMappingURL=claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.js","sourceRoot":"","sources":["../../../src/documents/credential/claims.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCASkB;AAClB,8CAQuB;AACvB,sCAAuF;AAEvF,oDAA8E;AAC9E,mEAAqD;AAErD,6CAAoD;AAEpD,MAAa,SAAS;IAClB,YACc,MAAiB,EACjB,WAAoB;QADpB,WAAM,GAAN,MAAM,CAAW;QACjB,gBAAW,GAAX,WAAW,CAAS;IAC/B,CAAC;IAEI,aAAa,CACjB,KAAgB,EAChB,KAAW,EACX,YAAsE,EACtE,YAAe;QAEf,OAAO,IAAA,oCAAuB,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;YAChE,IAAI,UAAU,CAAC,IAAI,IAAI,KAAK,EAAE;gBAC1B,MAAM,KAAK,GAAY,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC9C,IAAI,cAAuB,CAAC;gBAE5B,IAAI,UAAU,CAAC,OAAO,EAAE;oBACpB,IAAI,KAAK,IAAI,IAAI,EAAE;wBACf,cAAc,GAAG,IAAI,CAAC;qBACzB;yBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;wBAC7B,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;4BAChC,OAAO,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;wBAC1C,CAAC,CAAC,CAAC;qBACN;yBAAM;wBACH,MAAM,IAAI,KAAK,CACX,gJAAgJ,CACnJ,CAAC;qBACL;iBACJ;qBAAM;oBACH,cAAc,GAAG,YAA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iBAAiB,CAAC,SAAS;YAC3C,SAAS,EAAE,iBAAiB,CAAC,IAAI;YACjC,MAAM,EAAE,iBAAiB,CAAC,MAAM;SACnC,CAAC,CAAC;IACP,CAAC;CACJ;AAjTD,8BAiTC","sourcesContent":["import {\n ApiClient,\n Claims,\n Ctor,\n isLinkedEntityDescriptor,\n isValueWithId,\n UserUpdateClaims,\n ReadDraftClaims,\n ReadClaims,\n} from '../types';\nimport {\n ClaimDescriptor,\n getClaimJsonLdTypeMetadata,\n getClaimLinkedCredentialMetadata,\n getClaimLinkedFileMetadata,\n getContextJsonLdMetadata,\n getRegisteredClaimsList,\n getTsDataTypeMetadata,\n} from '../decorators';\nimport { Rfc3339Date, LinkedCredential, LinkedFile, Rfc3339DateTime } from '../models';\nimport { DraftSchema, DraftSchemaFieldsItem } from '../../api';\nimport { strictlyConvertToApiType, StrictPartial } from '../utils/converters';\nimport * as serialization from '../../serialization';\nimport { CredentialClaims, DraftFieldValue, Json } from './types';\nimport { VerifiableCredential } from './verifiable';\n\nexport class UdtClaims<T extends Claims> {\n constructor(\n protected client: ApiClient,\n protected claimsModel: Ctor<T>,\n ) {}\n\n private processValues<K extends Claims>(\n model: Ctor<any>,\n input: Json,\n processValue: (descriptor: ClaimDescriptor, value: unknown) => unknown,\n initialValue: K,\n ): K {\n return getRegisteredClaimsList(model).reduce((result, descriptor) => {\n if (descriptor.name in input) {\n const value: unknown = input[descriptor.name];\n let processedValue: unknown;\n\n if (descriptor.isArray) {\n if (value == null) {\n processedValue = null;\n } else if (Array.isArray(value)) {\n processedValue = value.map((item) => {\n return processValue(descriptor, item);\n });\n } else {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"Array\". Please reach out to support for assistance.`,\n );\n }\n } else {\n processedValue = processValue(descriptor, value);\n }\n Reflect.set(result, descriptor.name, processedValue);\n }\n\n return result;\n }, initialValue);\n }\n\n private getClaimTypeInfo(model: Ctor<any>, descriptor: ClaimDescriptor): Ctor<any> {\n const typeInfo = descriptor.nestedType ? descriptor.nestedType : getTsDataTypeMetadata(model, descriptor.name);\n\n if (typeInfo == null) {\n throw new Error(\n `Can't convert received value. Inconsistent data definition. Please reach out to support for assistance.`,\n );\n }\n\n return typeInfo;\n }\n\n /** convertApiValuesToUdt maps and converts the API received claims values to the UDT claims model */\n protected convertApiValuesToUdt<K extends Claims>(model: Ctor<any>, input: Json): K {\n const processValue = (descriptor: ClaimDescriptor, value: unknown): unknown => {\n if (value == null) {\n return null;\n }\n\n if (isLinkedEntityDescriptor(value)) {\n const isLinkedCredential = getClaimLinkedCredentialMetadata(model, descriptor.name);\n if (isLinkedCredential) {\n return new LinkedCredential(this.client, value.id, value.digestMultibase);\n }\n\n const isLinkedFile = getClaimLinkedFileMetadata(model, descriptor.name);\n\n if (isLinkedFile) {\n return new LinkedFile(this.client, value.id, value.digestMultibase);\n }\n }\n\n const typeInfo = this.getClaimTypeInfo(model, descriptor);\n\n if (typeInfo === Date) {\n if (typeof value !== 'string') {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"Date\". Please reach out to support for assistance.`,\n );\n }\n return new Date(value);\n }\n\n if (typeInfo === Rfc3339DateTime) {\n if (typeof value !== 'string') {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"Rfc3339DateTime\". Please reach out to support for assistance.`,\n );\n }\n return new Rfc3339DateTime(value);\n }\n\n if (typeInfo === Rfc3339Date) {\n if (typeof value !== 'string') {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"Rfc3339Date\". Please reach out to support for assistance.`,\n );\n }\n return new Rfc3339Date(value);\n }\n\n // Primitive values should be returned as-is\n if (Array.of<Ctor<any>>(String, Number, Boolean, Object).includes(typeInfo)) {\n return value;\n }\n\n if (!(value instanceof Object)) {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"${typeInfo.name}\". Please reach out to support for assistance.`,\n );\n }\n return this.convertApiValuesToUdt(typeInfo, value);\n };\n\n return this.processValues<K>(model, input, processValue, new model());\n }\n\n /** convertUdtToApiValues maps and converts the user received claims values onto UDT claims model */\n protected convertUdtToApiValues<K extends Claims>(model: Ctor<any>, input: K): CredentialClaims {\n const processValue = (descriptor: ClaimDescriptor, value: unknown): unknown => {\n if (value == null) {\n return null;\n }\n\n const typeInfo = this.getClaimTypeInfo(model, descriptor);\n\n if (getClaimLinkedCredentialMetadata(model, descriptor.name)) {\n if (value instanceof LinkedCredential) {\n return value.toJSON();\n }\n\n if (value instanceof VerifiableCredential) {\n return value.toLinkedCredential().toJSON();\n }\n\n if (isValueWithId(value)) {\n return LinkedCredential.createClaimValue(value.id, value.digestMultibase);\n }\n }\n\n if (getClaimLinkedFileMetadata(model, descriptor.name)) {\n if (value instanceof LinkedFile) {\n return value.toJSON();\n }\n\n if (isValueWithId(value)) {\n return LinkedFile.createClaimValue(value.id, value.digestMultibase);\n }\n }\n\n if (\n Array.of<Ctor<any>>(\n String,\n Number,\n Date,\n Rfc3339DateTime,\n Rfc3339Date,\n Boolean,\n Object,\n Function,\n ).includes(typeInfo)\n ) {\n return value;\n }\n\n if (!(value instanceof Object)) {\n throw new Error(\n `Can't convert received value as it has an unexpected type. The value is defined in UDT as \"${typeInfo.name}\". Please reach out to support for assistance.`,\n );\n }\n return this.convertUdtToApiValues(typeInfo, value);\n };\n\n return this.processValues(model, input, processValue, {});\n }\n\n protected mapClaimToApi(claim: ClaimDescriptor, claimsModel: Ctor<any>): DraftSchemaFieldsItem {\n const claimJsonLdType = getClaimJsonLdTypeMetadata(claimsModel, claim.name);\n const draftBaseFieldValue: StrictPartial<DraftFieldValue> = {\n name: claim.name,\n title: claim.title,\n notEmpty: claim.notEmpty,\n isArray: claim.isArray || undefined,\n };\n\n if (getClaimLinkedCredentialMetadata(claimsModel, claim.name)) {\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'LINK',\n linkType: undefined,\n });\n }\n\n if (getClaimLinkedFileMetadata(claimsModel, claim.name)) {\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'FILE',\n });\n }\n\n if (\n claim.nestedType &&\n !Array.of<Ctor<any>>(String, Number, Date, Rfc3339DateTime, Rfc3339Date, Boolean).includes(claim.nestedType)\n ) {\n const claimNestedType = claim.nestedType;\n const nestedContextInfo = getContextJsonLdMetadata(claimNestedType);\n\n if (!nestedContextInfo) {\n throw new Error(\n `The information about the VC context was not found in the \"${claimNestedType.name}\" model. Please use the \"@VcContext\" decorator to define the necessary information.`,\n );\n }\n\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'STRUCT',\n fields: getRegisteredClaimsList(claimNestedType).map((nestedClaim) => {\n return this.mapClaimToApi(nestedClaim, claimNestedType);\n }),\n vocabNamespace: nestedContextInfo.namespace,\n vocabName: nestedContextInfo.name,\n });\n }\n\n const tsDataType = claim.nestedType || getTsDataTypeMetadata(claimsModel, claim.name);\n\n if (!tsDataType) {\n throw new Error(\n `The information about the VC claim data type was not found for the \"${claim.name}\" property. Ensure that \"emitDecoratorMetadata\" is enabled in your \"tsconfig.json\".`,\n );\n }\n\n switch (tsDataType) {\n case String:\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'STRING',\n type: claimJsonLdType,\n enum: claim.enumValuesDescriptor,\n });\n case Number:\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'NUMBER',\n type: claimJsonLdType,\n });\n case Boolean:\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'BOOLEAN',\n type: claimJsonLdType,\n });\n case Rfc3339Date:\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'DATE',\n type: claimJsonLdType,\n });\n case Rfc3339DateTime:\n case Date:\n return strictlyConvertToApiType(serialization.DraftSchemaFieldsItem, {\n ...draftBaseFieldValue,\n kind: 'DATETIME',\n type: claimJsonLdType,\n });\n default:\n throw new Error(\n `Unsupported primitive data type: ${tsDataType.name}. Please use one of the supported types. You can find more information in the documentation.`,\n );\n }\n }\n\n /**\n * Marshalling is the process of transforming the internal representation of values to a data format suitable\n * for transmission.\n */\n marshalValues(input: UserUpdateClaims<T>): Json {\n return this.convertUdtToApiValues(this.claimsModel, input);\n }\n\n /**\n * Unmarshalling is the reverse process of marshalling. It involves converting data from a serialized format back\n * into an internal representation.\n */\n unmarshalValuesToDraft(input: Json): ReadDraftClaims<T> {\n return this.convertApiValuesToUdt(this.claimsModel, input);\n }\n\n unmarshalValuesToCredential(input: Json): ReadClaims<T> {\n return this.convertApiValuesToUdt(this.claimsModel, input);\n }\n\n getDraftSchema(): DraftSchema | undefined {\n const vcContextMetadata = getContextJsonLdMetadata(this.claimsModel);\n\n if (!vcContextMetadata) return undefined;\n\n return strictlyConvertToApiType(serialization.DraftSchema, {\n fields: getRegisteredClaimsList(this.claimsModel).map((claim) =>\n this.mapClaimToApi(claim, this.claimsModel),\n ),\n vocabNamespace: vcContextMetadata.namespace,\n vocabName: vcContextMetadata.name,\n vcType: vcContextMetadata.vcType,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.spec.d.ts","sourceRoot":"","sources":["../../../src/documents/credential/claims.spec.ts"],"names":[],"mappings":""}
|