From 3adc965dd09490b7efa1cce9f09b0a3b30970277 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Wed, 19 Apr 2023 17:30:39 +0800 Subject: ✨优化文档 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- envshare/pkg/encoding.ts | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 envshare/pkg/encoding.ts (limited to 'envshare/pkg/encoding.ts') diff --git a/envshare/pkg/encoding.ts b/envshare/pkg/encoding.ts deleted file mode 100644 index 2025133..0000000 --- a/envshare/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