Skip to content

Commit

Permalink
feat!: Move PeerDID outside of Domain.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: If you have imported Domain.PeerDID in your typescript application, you will need to re-import from PeerDID directly
  • Loading branch information
elribonazo committed Jan 2, 2024
1 parent caaf107 commit 521ad4c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/domain/buildingBlocks/Pluto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { DIDPair } from "../models/DIDPair";
import { PrivateKey } from "../models";
import { Mediator } from "../models/Mediator";
import { Message } from "../models/Message";
import { PeerDID } from "../models/PeerDID";
import { PrismDIDInfo } from "../models/PrismDIDInfo";
import { Credential } from "../models/Credential";
import { Anoncreds } from "../models/Anoncreds";
import { PeerDID } from "../../peer-did/PeerDID";

/**
* Pluto is a storage interface describing storage requirements of the edge agents
Expand Down
21 changes: 0 additions & 21 deletions src/domain/models/PeerDID.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/domain/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export * from "./KeyPair";
export * from "./Mediator";
export * from "./Message";
export * from "./MessageAttachment";
export * from "./PeerDID";
export * from "./PrismDIDInfo";
export * from "./PrismDIDMethodId";
export * from "./keyManagement";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export * from "./prism-agent/mediator/PlutoMediatorStore";
export * from "./mercury/didcomm/Wrapper";
export * from "./prism-agent/helpers/ApiImpl";
export { ListenerKey } from "./prism-agent/types";

export * from './peer-did/PeerDID';
export type {
MediatorHandler,
ConnectionsManager as ConnectionsManagerInterface,
Expand Down
3 changes: 2 additions & 1 deletion src/mercury/didcomm/SecretsResolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Secret, SecretsResolver } from "didcomm-node";
import * as Domain from "../../domain";
import * as DIDURLParser from "../../castor/parser/DIDUrlParser";
import { PeerDID } from "../../peer-did/PeerDID";

export class DIDCommSecretsResolver implements SecretsResolver {
constructor(
Expand Down Expand Up @@ -51,7 +52,7 @@ export class DIDCommSecretsResolver implements SecretsResolver {
}

private mapToSecret(
peerDid: Domain.PeerDID,
peerDid: PeerDID,
publicKeyJWK: Domain.PublicKeyJWK
): Secret {
const privateKeyBuffer = peerDid.privateKeys.find(
Expand Down
54 changes: 33 additions & 21 deletions src/peer-did/PeerDID.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { DID } from "../domain/models/DID";
import { CastorError } from "../domain/models/Errors";
import { CastorError, type DID, type KeyCurve } from "../domain";

export namespace PeerDID {
// Q: why is this a custom shape instead of a Domain.PrivateKey?
export interface PrivateKey {
/**
* Instance of a KeyCurve
*
* @type {KeyCurve}
*/
keyCurve: KeyCurve;
/**
* Value as Uint8Array, buffer like
*
* @type {Uint8Array}
*/
value: Uint8Array;
}
}

export interface PeerDIDEncoded {
t: string;
Expand All @@ -8,6 +25,20 @@ export interface PeerDIDEncoded {
a: string[];
}

export class PeerDID {
constructor(
public readonly did: DID,
public readonly privateKeys: PeerDID.PrivateKey[] = []
) {
const regex = /(([01](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))+(\.(S)[0-9a-zA-Z=]*)?)))$/;
const isValid = did.schema === "did" && did.method === "peer" && regex.test(did.methodId);

if (isValid === false) {
throw new CastorError.InvalidPeerDIDError();
}
}
}

/**
* Provides functionality to transfrom peerDIDServices from our interfaces into DIDComm module ones
*/
Expand Down Expand Up @@ -62,22 +93,3 @@ export class PeerDIDService {
);
}
}

export class PeerDID {
readonly did: DID;

constructor(did: DID) {
const regex =
/(([01](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))|(2((\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))+(\.(S)[0-9a-zA-Z=]*)?)))$/;
if (
!(
did.schema === "did" &&
did.method === "peer" &&
regex.test(did.methodId)
)
) {
throw new CastorError.InvalidPeerDIDError();
}
this.did = did;
}
}
1 change: 0 additions & 1 deletion tests/castor/PeerDID.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from "chai";

import {
KeyPair,
Service,
DID,
ServiceEndpoint,
Expand Down

0 comments on commit 521ad4c

Please sign in to comment.