Skip to content

Commit

Permalink
fix: merging multiple PeerDID classes
Browse files Browse the repository at this point in the history
  • Loading branch information
curtis-h authored and elribonazo committed Jan 2, 2024
1 parent 9ed3e4e commit 3d28da7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
44 changes: 28 additions & 16 deletions src/domain/models/PeerDID.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import type { DID, KeyCurve } from ".";
import { CastorError, type DID, type KeyCurve } from ".";

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 class PeerDID {
constructor(
public readonly did: DID,
public readonly privateKeys: Array<{
/**
* Instance of a KeyCurve
*
* @type {KeyCurve}
*/
keyCurve: KeyCurve;
/**
* Value as Uint8Array, buffer like
*
* @type {Uint8Array}
*/
value: Uint8Array;
}>
) {}
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();
}
}
}
22 changes: 0 additions & 22 deletions src/peer-did/PeerDID.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { DID } from "../domain/models/DID";
import { CastorError } from "../domain/models/Errors";

export interface PeerDIDEncoded {
t: string;
s: string;
Expand Down Expand Up @@ -62,22 +59,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;
}
}
4 changes: 2 additions & 2 deletions src/peer-did/PeerDIDCreate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as base64 from "multiformats/bases/base64";

import { Curve, DID, Service as DIDDocumentService } from "../domain/models";
import { Curve, DID, Service as DIDDocumentService, PeerDID } from "../domain/models";

import { CastorError } from "../domain/models/Errors";
import { JWKHelper, VerificationMaterial } from "./helpers/JWKHelper";
import { MultiCodec } from "./helpers/Multicodec";
import { PeerDID, PeerDIDEncoded, PeerDIDService } from "./PeerDID";
import { PeerDIDEncoded, PeerDIDService } from "./PeerDID";
import {
Numalgo2Prefix,
OctetPublicKey,
Expand Down

0 comments on commit 3d28da7

Please sign in to comment.