UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

82 lines (78 loc) • 2.8 kB
import { Hasher } from "../../../crypto/hashes/Hasher.mjs"; import { JsonTransformer } from "../../../utils/JsonTransformer.mjs"; import "../../../utils/index.mjs"; import { BaseRecord } from "../../../storage/BaseRecord.mjs"; import { uuid } from "../../../utils/uuid.mjs"; import { CredentialMultiInstanceState } from "../../../utils/credentialUseTypes.mjs"; import "../../../crypto/index.mjs"; import { decodeSdJwtVc } from "../decodeSdJwtVc.mjs"; import { decodeSdJwtSync } from "@sd-jwt/decode"; //#region src/modules/sd-jwt-vc/repository/SdJwtVcRecord.ts var SdJwtVcRecord = class SdJwtVcRecord extends BaseRecord { /** * Only here for class transformation. If compactSdJwtVc is set we transform * it to the new sdJwtVcs array format */ set compactSdJwtVc(compactSdJwtVc) { this.credentialInstances = [{ compactSdJwtVc }]; } constructor(props) { super(); this.type = SdJwtVcRecord.type; this.multiInstanceState = CredentialMultiInstanceState.SingleInstanceUsed; if (props) { this.id = props.id ?? uuid(); this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date(); this.credentialInstances = props.credentialInstances; this.multiInstanceState = this.credentialInstances.length === 1 ? CredentialMultiInstanceState.SingleInstanceUnused : CredentialMultiInstanceState.MultiInstanceFirstUnused; this.typeMetadata = props.typeMetadata; this.typeMetadataChain = props.typeMetadataChain; this._tags = props.tags ?? {}; } } get firstCredential() { return { ...decodeSdJwtVc(this.credentialInstances[0].compactSdJwtVc, this.typeMetadata), kmsKeyId: this.credentialInstances[0].kmsKeyId }; } static fromSdJwtVc(sdJwtVc) { return new SdJwtVcRecord({ credentialInstances: [{ compactSdJwtVc: sdJwtVc.compact, kmsKeyId: sdJwtVc.kmsKeyId }], typeMetadata: sdJwtVc.typeMetadata }); } get extendedVctValues() { return this.typeMetadataChain ? this.typeMetadataChain.slice(1).map(({ vct }) => vct) : this.typeMetadata?.extends ? [this.typeMetadata.extends] : []; } getTags() { const sdjwt = decodeSdJwtSync(this.credentialInstances[0].compactSdJwtVc, Hasher.hash); const vct = sdjwt.jwt.payload.vct; const sdAlg = sdjwt.jwt.payload._sd_alg; const alg = sdjwt.jwt.header.alg; return { ...this._tags, vct, extendedVctValues: this.extendedVctValues, sdAlg: sdAlg ?? "sha-256", alg, multiInstanceState: this.multiInstanceState }; } clone() { return JsonTransformer.fromJSON(JsonTransformer.toJSON(this), this.constructor); } /** * encoded is convenience method added to all credential records */ get encoded() { return this.credentialInstances[0].compactSdJwtVc; } }; SdJwtVcRecord.type = "SdJwtVcRecord"; //#endregion export { SdJwtVcRecord }; //# sourceMappingURL=SdJwtVcRecord.mjs.map