diff --git a/src/domain/buildingBlocks/Pluto.ts b/src/domain/buildingBlocks/Pluto.ts index 1c0b33c29..91d848cc8 100644 --- a/src/domain/buildingBlocks/Pluto.ts +++ b/src/domain/buildingBlocks/Pluto.ts @@ -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 diff --git a/src/domain/models/PeerDID.ts b/src/domain/models/PeerDID.ts deleted file mode 100644 index cec68df3f..000000000 --- a/src/domain/models/PeerDID.ts +++ /dev/null @@ -1,33 +0,0 @@ -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: 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(); - } - } -} diff --git a/src/domain/models/index.ts b/src/domain/models/index.ts index c08ba5005..accf342b4 100644 --- a/src/domain/models/index.ts +++ b/src/domain/models/index.ts @@ -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"; diff --git a/src/index.ts b/src/index.ts index 107b31c95..edcfca25c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, diff --git a/src/mercury/didcomm/SecretsResolver.ts b/src/mercury/didcomm/SecretsResolver.ts index 04dc2085c..84b87b3f7 100644 --- a/src/mercury/didcomm/SecretsResolver.ts +++ b/src/mercury/didcomm/SecretsResolver.ts @@ -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( @@ -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( diff --git a/src/peer-did/PeerDID.ts b/src/peer-did/PeerDID.ts index 2f4fafa70..f82bd45e7 100644 --- a/src/peer-did/PeerDID.ts +++ b/src/peer-did/PeerDID.ts @@ -1,3 +1,23 @@ +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; s: string; @@ -5,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 */ diff --git a/src/peer-did/PeerDIDCreate.ts b/src/peer-did/PeerDIDCreate.ts index 41dba97f5..a725c9129 100644 --- a/src/peer-did/PeerDIDCreate.ts +++ b/src/peer-did/PeerDIDCreate.ts @@ -1,11 +1,11 @@ import * as base64 from "multiformats/bases/base64"; -import { Curve, DID, Service as DIDDocumentService, PeerDID } from "../domain/models"; +import { Curve, DID, Service as DIDDocumentService } from "../domain/models"; import { CastorError } from "../domain/models/Errors"; import { JWKHelper, VerificationMaterial } from "./helpers/JWKHelper"; import { MultiCodec } from "./helpers/Multicodec"; -import { PeerDIDEncoded, PeerDIDService } from "./PeerDID"; +import { PeerDID, PeerDIDEncoded, PeerDIDService } from "./PeerDID"; import { Numalgo2Prefix, OctetPublicKey, diff --git a/tests/castor/PeerDID.test.ts b/tests/castor/PeerDID.test.ts index 6b77e18a7..94a02a163 100644 --- a/tests/castor/PeerDID.test.ts +++ b/tests/castor/PeerDID.test.ts @@ -1,7 +1,6 @@ import { expect } from "chai"; import { - KeyPair, Service, DID, ServiceEndpoint,