ethers.js/src.ts/utils/base64.ts

19 lines
453 B
TypeScript
Raw Normal View History

import { getBytes, getBytesCopy } from "./data.js";
2022-09-05 23:14:43 +03:00
import type { BytesLike } from "./data.js";
2022-09-09 10:37:38 +03:00
/**
* Decodes the base-64 encoded %%base64Data%%.
*/
export function decodeBase64(base64Data: string): Uint8Array {
return getBytesCopy(Buffer.from(base64Data, "base64"));
2022-09-05 23:14:43 +03:00
};
2022-09-09 10:37:38 +03:00
/**
* Encodes %%data%% as base-64 encoded data.
*/
2022-09-05 23:14:43 +03:00
export function encodeBase64(data: BytesLike): string {
return Buffer.from(getBytes(data)).toString("base64");
2022-09-05 23:14:43 +03:00
}