-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 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
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 }; |