From 4919f028c884a041da7ff098abb02389b4eac598 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Tue, 18 Apr 2023 03:02:17 +0800 Subject: ✨add envshare docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/encoding.ts | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 pkg/encoding.ts (limited to 'pkg/encoding.ts') diff --git a/pkg/encoding.ts b/pkg/encoding.ts deleted file mode 100644 index 2025133..0000000 --- a/pkg/encoding.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { fromBase58, toBase58 } from "../util/base58"; -import { ID_LENGTH, ENCRYPTION_KEY_LENGTH } from "./constants"; -/** - * To share links easily, we encode the id, where the data is stored in redis, together with the secret encryption key. - */ -export function encodeCompositeKey(version: number, id: string, encryptionKey: Uint8Array): string { - if (version < 0 || version > 255) { - throw new Error("Version must fit in a byte"); - } - const compositeKey = new Uint8Array([version, ...fromBase58(id), ...encryptionKey]); - - return toBase58(compositeKey); -} - -/** - * To share links easily, we encode the id, where the data is stored in redis, together with the secret encryption key. - */ -export function decodeCompositeKey(compositeKey: string): { id: string; encryptionKey: Uint8Array; version: number } { - const decoded = fromBase58(compositeKey); - const version = decoded.at(0); - - if (version === 1 || version === 2) { - return { - id: toBase58(decoded.slice(1, 1 + ID_LENGTH)), - encryptionKey: decoded.slice(1 + ID_LENGTH, 1 + ID_LENGTH + ENCRYPTION_KEY_LENGTH), - version, - }; - } - - throw new Error(`Unsupported composite key version: ${version}`); -} -- cgit v1.2.3-70-g09d2