Skip to content

Commit

Permalink
remove base58 (en/de)coders
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-block committed Nov 13, 2023
1 parent 26a4d38 commit ba532d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
36 changes: 6 additions & 30 deletions .web5-spec/encoders.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { paths } from "./openapi.js";
import { Request, Response } from "express";
import { Convert } from '@web5/common';
import { sha256 } from '@noble/hashes/sha256';
import { Convert } from "@web5/common";
import { sha256 } from "@noble/hashes/sha256";

export function encoderBase64Encode(req: Request, res: Response) {
const requestBody: paths["/encoders/base64/encode"]["post"]["requestBody"]["content"]["application/json"] =
req.body;

const resp: paths["/encoders/base64/encode"]["post"]["responses"]["200"]["content"]["application/json"] =
{
data: Convert.string(requestBody.data).toBase64Url()
data: Convert.string(requestBody.data).toBase64Url(),
};

res.json(resp);
Expand All @@ -21,31 +21,7 @@ export function encoderBase64Decode(req: Request, res: Response) {

const resp: paths["/encoders/base64/encode"]["post"]["responses"]["200"]["content"]["application/json"] =
{
data: Convert.base64Url(requestBody.data).toString()
};

res.json(resp);
}

export function encoderBase58Encode(req: Request, res: Response) {
const requestBody: paths["/encoders/base58/encode"]["post"]["requestBody"]["content"]["application/json"] =
req.body;

const resp: paths["/encoders/base58/encode"]["post"]["responses"]["200"]["content"]["application/json"] =
{
data: Convert.string(requestBody.data).toBase58Btc()
};

res.json(resp);
}

export function encoderBase58Decode(req: Request, res: Response) {
const requestBody: paths["/encoders/base58/encode"]["post"]["requestBody"]["content"]["application/json"] =
req.body;

const resp: paths["/encoders/base58/encode"]["post"]["responses"]["200"]["content"]["application/json"] =
{
data: Convert.base58Btc(requestBody.data).toString()
data: Convert.base64Url(requestBody.data).toString(),
};

res.json(resp);
Expand All @@ -57,8 +33,8 @@ export function encoderSha256Encode(req: Request, res: Response) {

const resp: paths["/encoders/sha256/encode"]["post"]["responses"]["200"]["content"]["application/json"] =
{
data: Convert.arrayBuffer(sha256(requestBody.data)).toHex()
data: Convert.arrayBuffer(sha256(requestBody.data)).toHex(),
};

res.json(resp);
}
}
2 changes: 0 additions & 2 deletions .web5-spec/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ app.post("/credentials/issue", credentialIssue);

app.post("/encoders/base64/encode", encoderBase64Encode);
app.post("/encoders/base64/decode", encoderBase64Decode);
app.post("/encoders/base58/encode", encoderBase58Encode);
app.post("/encoders/base58/decode", encoderBase58Decode);
app.post("/encoders/sha256/encode", encoderSha256Encode);

const serverID: paths["/"]["get"]["responses"]["200"]["content"]["application/json"] =
Expand Down

0 comments on commit ba532d7

Please sign in to comment.