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

hyperledger-identus / sdk-ts / 14536530200

18 Apr 2025 02:17PM UTC coverage: 82.802% (+7.3%) from 75.544%
14536530200

Pull #419

github

web-flow
Merge d20157089 into 0bddae204
Pull Request #419: test: chai and sinon removal

1711 of 2060 branches covered (83.06%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

1047 existing lines in 114 files now uncovered.

9401 of 11360 relevant lines covered (82.76%)

33.67 hits per line

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

93.65
/src/edge-agent/didcomm/CreatePeerDID.ts
1
import * as Domain from "../../domain";
1✔
2
import { Task } from "../../utils/tasks";
1✔
3
import { MediationKeysUpdateList } from "../protocols/mediation/MediationKeysUpdateList";
1✔
4
import { AgentContext } from "./Context";
5
import { Send } from "./Send";
1✔
6

7
/**
8
 * Asyncronously create and store a new peer did
9
 *
10
 * @async
11
 * @param {Service[]} services
12
 * @param {boolean} [updateMediator=false]
13
 * @returns {Promise<DID>}
14
 */
15

16
interface Args {
17
  services: Domain.Service[];
18
  updateMediator: boolean;
19
}
20

21
export class CreatePeerDID extends Task<Domain.DID, Args> {
1✔
22
  async run(ctx: AgentContext): Promise<Domain.DID> {
1✔
23
    const services = this.args.services;
8✔
24
    const updateMediator = this.args.updateMediator ?? false;
8!
25
    const publicKeys: Domain.PublicKey[] = [];
8✔
26
    const keyAgreementPrivateKey = ctx.Apollo.createPrivateKey({
8✔
27
      type: Domain.KeyTypes.Curve25519,
8✔
28
      curve: Domain.Curve.X25519,
8✔
29
    });
8✔
30

31
    const authenticationPrivateKey = ctx.Apollo.createPrivateKey({
8✔
32
      type: Domain.KeyTypes.EC,
8✔
33
      curve: Domain.Curve.ED25519,
8✔
34
    });
8✔
35

36
    publicKeys.push(keyAgreementPrivateKey.publicKey());
8✔
37
    publicKeys.push(authenticationPrivateKey.publicKey());
8✔
38
    const mediatorDID = ctx.Connections.mediator?.uri;
8✔
39

40
    if (
8✔
41
      mediatorDID &&
8✔
42
      !services.find((service) => {
8✔
43
        return service.isDIDCommMessaging;
4✔
44
      })
8✔
45
    ) {
8✔
46
      //TODO This still needs to be done update the key List
47
      services.push(
4✔
48
        new Domain.Service(
4✔
49
          "#didcomm-1",
4✔
50
          ["DIDCommMessaging"],
4✔
51
          new Domain.ServiceEndpoint(mediatorDID.toString())
4✔
52
        )
4✔
53
      );
4✔
54
    }
4✔
55
    const did = await ctx.Castor.createPeerDID(publicKeys, services);
8✔
56

57
    if (updateMediator) {
8✔
58
      await this.updateKeyListWithDID(ctx, did);
8✔
59
    }
8✔
60

61
    await ctx.Pluto.storeDID(did, [
8✔
62
      keyAgreementPrivateKey,
8✔
63
      authenticationPrivateKey,
8✔
64
    ]);
8✔
65

66
    return did;
8✔
67
  }
8✔
68

69
  /**
70
   * Asyncronously update the mediator with the new keyList, used during the mediation process or during DID Rotation
71
   *
72
   * @async
73
   * @param {DID[]} did
74
   * @returns {Promise<void>}
75
   */
76
  async updateKeyListWithDID(ctx: AgentContext, did: Domain.DID): Promise<void> {
1✔
77
    const mediator = ctx.Connections.mediator?.asMediator();
8✔
78

79
    if (!mediator) {
8!
80
      throw new Domain.AgentError.NoMediatorAvailableError();
×
UNCOV
81
    }
×
82
    const keyListUpdateMessage = new MediationKeysUpdateList(
8✔
83
      mediator.hostDID,
8✔
84
      mediator.mediatorDID,
8✔
85
      [did]
8✔
86
    ).makeMessage();
8✔
87

88
    await ctx.run(new Send({ message: keyListUpdateMessage }));
8✔
89
    // [ ] handle response https://github.com/hyperledger-identus/sdk-ts/issues/391
90
  }
8✔
91
}
1✔
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

© 2025 Coveralls, Inc