• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger-identus / sdk-ts / 15879559936

25 Jun 2025 02:45PM UTC coverage: 72.405% (-3.8%) from 76.16%
15879559936

push

github

web-flow
fix: db improvements and inference (#442)

Signed-off-by: Francisco Javier Ribo Labrador <elribonazo@gmail.com>

1320 of 2008 branches covered (65.74%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 4 files covered. (92.86%)

162 existing lines in 12 files now uncovered.

3054 of 4033 relevant lines covered (75.73%)

44.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/src/pluto/models/Credential.ts
1
import * as sha256 from '@stablelib/sha256';
2

3
import type { Model } from "./Model";
4
import { schemaFactory } from "./Schema";
5
import { JWTVerifiableCredentialRecoveryId } from "../../pollux/models/JWTVerifiableCredential";
6
import { AnonCredsRecoveryId } from "../../pollux/models/AnonCredsVerifiableCredential";
7
import { PlutoError } from '../../domain';
8
import { MigrationStrategies } from '../types';
9

10
/**
11
 * Definition for Storable Credential model
12
 * Represents {@link Domain!Credential}
13
 * 
14
 * @typedef {Object} CredentialModel
15
 * @see Domain.Credential
16
 */
17
export interface Credential extends Model {
18
  /**
19
   * Identifier for recovery
20
   */
21
  recoveryId: string;
22
  /**
23
   * Stringified JSON values
24
   */
25
  dataJson: string;
26

27
  // searchable properties
28
  issuer?: string;
29
  subject?: string;
30
  credentialCreated?: string;
31
  credentialUpdated?: string;
32
  credentialSchema?: string;
33
  validUntil?: number;
34
  revoked?: boolean;
35
  // availableClaims?: string[];
36
  id: string;
37
}
38

39
export const CredentialSchema = schemaFactory<Credential>(schema => {
54✔
40
  schema.addProperty("string", "recoveryId");
54✔
41
  schema.addProperty("string", "dataJson");
54✔
42

43
  schema.addProperty("string", "issuer");
54✔
44
  schema.addProperty("string", "subject");
54✔
45
  schema.addProperty("string", "credentialCreated");
54✔
46
  schema.addProperty("string", "credentialUpdated");
54✔
47
  schema.addProperty("string", "credentialSchema");
54✔
48
  schema.addProperty("number", "validUntil");
54✔
49
  schema.addProperty("boolean", "revoked");
54✔
50

51
  schema.setEncrypted("dataJson");
54✔
52
  schema.setVersion(2);
54✔
53

54
  //V1
55
  schema.addProperty("string", "id");
54✔
56
  schema.setRequired("recoveryId", "dataJson", "id");
54✔
57

58
});
59

60
export const CredentialMigration: MigrationStrategies = {
54✔
61
  1: function (document) {
62
    const recoveryId = document.recoveryId;
×
63
    if (recoveryId == JWTVerifiableCredentialRecoveryId) {
×
64
      const jwtObj = JSON.parse(document.dataJson);
×
65
      return {
×
66
        ...document,
67
        id: jwtObj.id
68
      }
69
    }
70
    if (recoveryId == AnonCredsRecoveryId) {
×
71
      const anoncredsObject = JSON.parse(document.dataJson);
×
72
      if (anoncredsObject.revoked !== undefined) {
×
73
        delete anoncredsObject.revoked;
×
74
      }
75
      const anoncredsStr = JSON.stringify(anoncredsObject)
×
76
      return {
×
77
        ...document,
78
        id: Buffer.from(sha256.hash(Buffer.from(anoncredsStr))).toString('hex')
79
      }
80

81
    }
82
    throw new PlutoError.UnknownCredentialTypeError();
×
83
  },
84
  2: function (document) {
NEW
85
    return {
×
86
      ...document,
87
      validUntil: document.validUntil ? new Date(document.validUntil).getTime() : undefined
×
88
    }
89
  }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc