-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Identity-service:Interface implemented
- Loading branch information
Showing
11 changed files
with
141 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
services/identity-service/src/did/factories/blockchain-anchor.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable, BadRequestException } from '@nestjs/common'; | ||
import { AnchorCordService } from '../implementations/anchor-cord.service'; | ||
import { BlockchainAnchor } from '../interfaces/blockchain_anchor.interface'; | ||
|
||
/** | ||
* Factory class to dynamically resolve the appropriate BlockchainAnchor service. | ||
* It uses the specified method to determine which implementation to return. | ||
*/ | ||
@Injectable() | ||
export class BlockchainAnchorFactory { | ||
/** | ||
* Constructor for the BlockchainAnchorFactory. | ||
* @param cordService - An instance of AnchorCordService, which handles CORD-specific anchoring logic. | ||
*/ | ||
constructor(private readonly cordService: AnchorCordService) {} | ||
|
||
/** | ||
* Resolves the appropriate BlockchainAnchor service based on the provided method. | ||
* @param method - The blockchain method (e.g., 'cord'). | ||
* @returns The service instance corresponding to the specified method or null if no method is provided. | ||
* @throws | ||
*/ | ||
getAnchorService(method?: string): BlockchainAnchor | null { | ||
// If no method is specified, return null to indicate no anchoring is required | ||
if (!method) { | ||
return null; | ||
} | ||
|
||
// Determine the appropriate service implementation based on the method | ||
switch (method) { | ||
case 'cord': | ||
// Return the CORD-specific implementation | ||
return this.cordService; | ||
default: | ||
throw new BadRequestException(`Unsupported blockchain method: ${method}`); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
services/identity-service/src/did/implementations/anchor-cord.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable, Logger, InternalServerErrorException } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { BlockchainAnchor } from '../interfaces/blockchain_anchor.interface'; | ||
import {BadRequestException} from '@nestjs/common'; | ||
@Injectable() | ||
export class AnchorCordService implements BlockchainAnchor { | ||
private readonly logger = new Logger(AnchorCordService.name); | ||
|
||
constructor(private readonly httpService: HttpService) {} | ||
|
||
async anchorDid(body: any): Promise<{ document: any; mnemonic: string; delegateKeys: object }> { | ||
try { | ||
if (body.method !== 'cord') { | ||
throw new BadRequestException('Invalid method: only "cord" is allowed for anchoring to Cord.'); | ||
} | ||
const response = await this.httpService.axiosRef.post( | ||
`${process.env.ISSUER_AGENT_BASE_URL}/did/create/`, | ||
body, | ||
); | ||
return response.data.result; | ||
} catch (err) { | ||
this.logger.error('Error anchoring DID to CORD blockchain', err); | ||
throw new InternalServerErrorException('Failed to anchor DID to CORD blockchain'); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
services/identity-service/src/did/interfaces/blockchain_anchor.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface BlockchainAnchor { | ||
/** | ||
* Anchors a DID document to the blockchain. | ||
* @param body The request payload for anchoring. | ||
* @returns The anchored DID document or related data. | ||
*/ | ||
anchorDid(body: any): Promise<any>; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters