Skip to content

Commit

Permalink
Create blockchain.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 2, 2024
1 parent 4ca162c commit ba5dfed
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/cosmic_pi_network/did-manager/src/blockchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interface BlockchainOptions {
nodeUrl: string;
}

class Blockchain {
private nodeUrl: string;

constructor(options: BlockchainOptions) {
this.nodeUrl = options.nodeUrl;
}

async createDID(did: string): Promise<void> {
// Create a new DID on the blockchain
const response = await fetch(`${this.nodeUrl}/createDID`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ did }),
});
if (!response.ok) {
throw new Error(`Error creating DID: ${response.statusText}`);
}
}

async resolveDID(did: string): Promise<string> {
// Resolve a DID on the blockchain
const response = await fetch(`${this.nodeUrl}/resolveDID`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ did }),
});
if (!response.ok) {
throw new Error(`Error resolving DID: ${response.statusText}`);
}
return await response.json();
}
}

export { Blockchain };

0 comments on commit ba5dfed

Please sign in to comment.