-
Notifications
You must be signed in to change notification settings - Fork 76
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
4 changed files
with
169 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { SerializedPCD } from "@pcd/pcd-types"; | ||
import { POD } from "@pcd/pod"; | ||
import { PODPCD, PODPCDPackage } from "@pcd/pod-pcd"; | ||
|
||
export async function mintPODPCD( | ||
mintUrl: string, | ||
podPCDTemplate: SerializedPCD<PODPCD>, | ||
semaphoreSignaturePCD: SerializedPCD | ||
): Promise<SerializedPCD<PODPCD>> { | ||
// Request POD by content ID. | ||
const pcd = (await PODPCDPackage.deserialize(podPCDTemplate.pcd)) as PODPCD; | ||
const contentID = pcd.pod.contentID.toString(16); | ||
const requestBody = JSON.stringify({ | ||
contentID, | ||
semaphoreSignaturePCD | ||
}); | ||
let mintedPOD: POD; | ||
let serialisedMintedPOD: string; | ||
|
||
try { | ||
const resp = await fetch(mintUrl, { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
body: requestBody | ||
}); | ||
serialisedMintedPOD = await resp.text(); | ||
} catch { | ||
throw new Error("Mint server error."); | ||
} | ||
|
||
try { | ||
mintedPOD = POD.deserialize(serialisedMintedPOD); | ||
} catch { | ||
throw new Error("Invalid mint request!"); | ||
} | ||
|
||
// Throw if signer's keys don't match. | ||
if (pcd.claim.signerPublicKey !== mintedPOD.signerPublicKey) { | ||
throw new Error("The minted POD was signed by a different party."); | ||
} | ||
|
||
const mintedPCD = new PODPCD(pcd.id, mintedPOD); | ||
return PODPCDPackage.serialize(mintedPCD); | ||
} |
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