From 6016bfdaa0dbab9160833b7b6534073f9a0967b4 Mon Sep 17 00:00:00 2001 From: Cameron Campbell Date: Sat, 27 Jul 2024 15:01:16 +0100 Subject: [PATCH] fixed regression with dependencies --- package.json | 2 - .../orderedDataStores_V1.ts | 4 +- src/http/httpHandler/httpHandler.ts | 153 +----------------- 3 files changed, 3 insertions(+), 156 deletions(-) diff --git a/package.json b/package.json index 458d07a..d5c2495 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,6 @@ } }, "dependencies": { - "@types/jwk-to-pem": "^2.0.3", - "jwk-to-pem": "^2.0.5", "lodash": "^4.17.21", "parse-roblox-errors": "^1.1.10", "typeforge": "^0.0.19" diff --git a/src/apis/cloud/orderedDataStores_V1/orderedDataStores_V1.ts b/src/apis/cloud/orderedDataStores_V1/orderedDataStores_V1.ts index 1d632ee..ae04741 100644 --- a/src/apis/cloud/orderedDataStores_V1/orderedDataStores_V1.ts +++ b/src/apis/cloud/orderedDataStores_V1/orderedDataStores_V1.ts @@ -1,6 +1,6 @@ // [ Modules ] /////////////////////////////////////////////////////////////////// import { createApiGroup } from "../../apiGroup" -import { cloneAndMutateObject, dataIsSuccess } from "../../../utils/utils" +import { dataIsSuccess } from "../../../utils/utils" ////////////////////////////////////////////////////////////////////////////////// @@ -12,7 +12,7 @@ import type { OrderedDatastoreEntry, PrettifiedListOrderedDatastoreEntriesData, // [ Variables ] ///////////////////////////////////////////////////////////////// -const addApiMethod = createApiGroup({ groupName: "Messaging", baseUrl: "https://apis.roblox.com/ordered-data-stores" }) +const addApiMethod = createApiGroup({ groupName: "OrderedDatastores_V1", baseUrl: "https://apis.roblox.com/ordered-data-stores" }) ////////////////////////////////////////////////////////////////////////////////// diff --git a/src/http/httpHandler/httpHandler.ts b/src/http/httpHandler/httpHandler.ts index 562b9a5..662b73e 100644 --- a/src/http/httpHandler/httpHandler.ts +++ b/src/http/httpHandler/httpHandler.ts @@ -1,7 +1,5 @@ // [ Modules ] /////////////////////////////////////////////////////////////////// import { parseBEDEV1ErrorFromStringAndHeaders, parseBEDEV2ErrorFromStringAndHeaders } from "parse-roblox-errors" -import jwkToPem from 'jwk-to-pem' -import { HBAClient } from "roblox-bat" import { HttpError, HttpResponse } from "../http.utils" import { FetchAdapter } from "../httpAdapters/fetchHttpAdapter" @@ -53,42 +51,6 @@ export const getParsedErrors = async (response: HttpResponse): Promise => { await parseBEDEV2ErrorFromStringAndHeaders(JSON.stringify(response.body), response.headers as any as Headers) : undefined } - - - -function stringToArrayBuffer(str: string) { - const buf = new ArrayBuffer(str.length); - const bufView = new Uint8Array(buf); - for (let i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; -} - -const arrayBufferToString = (buf: ArrayBuffer) => String.fromCharCode.apply(null, new Uint8Array(buf)) - -const exportPrivateKey = async (key: CryptoKey) => btoa(arrayBufferToString(await crypto.subtle.exportKey("pkcs8", key))) -const exportPublicKey = async (key: CryptoKey) => btoa(arrayBufferToString(await crypto.subtle.exportKey("spki", key))) - -const importPrivateKey = async (key: string) => await crypto.subtle.importKey( - "pkcs8", stringToArrayBuffer(atob(key)), { name: "ECDSA", namedCurve: "P-256" }, true, ["sign"] -) -const importPublicKey = async (key: string) => await crypto.subtle.importKey( - "spki", stringToArrayBuffer(atob(key)), { name: "ECDSA", namedCurve: "P-256" }, true, [] -) - - -const createHbaKeys = async () => { - const keyPair = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign"]) - return { - private: await exportPrivateKey(keyPair.privateKey), - public: await exportPublicKey(keyPair.publicKey) - } -} - -const importHbaKeys = async (keys: { private: string, public: string }): Promise => { - return { privateKey: await importPrivateKey(keys.private), publicKey: await importPublicKey(keys.public) } -} ////////////////////////////////////////////////////////////////////////////////// @@ -109,27 +71,12 @@ export const HttpHandler = async ( formData: parsedFormData, } - - - const hbaClient = new HBAClient({ - cookie, - keys: await importHbaKeys({ private: process.env.ROBLOX_HBA_PRIVATE_KEY as string, public: process.env.ROBLOX_HBA_PUBLIC_KEY as string }) - }); - - const hbaHeaders = await hbaClient.generateBaseHeaders( - url, - true, // set to false or undefined if not authenticated - body - ); - - const requestDataHeaders = removeNullUndefined({ Cookie: cookie as string, "x-api-key": cloudKey, Authorization: oauthToken && `Bearer ${oauthToken}`, "Content-Type": headers?.["Content-Type"] || (!((formData && Object.keys(formData)?.length) || rawFormData) && "application/json" || null), ...headers, - //...hbaHeaders, }) const handlerMain = async (): Promise | HttpError> => { @@ -161,102 +108,4 @@ export const HttpHandler = async ( } return await handlerMain() -} - - -/*(async () => { - let request = await window.indexedDB.open("hbaDB") - request.onsuccess = () => { - let db = request.result - let transaction = db.transaction("hbaObjectStore", "readonly") - let objStore = transaction.objectStore("hbaObjectStore") - let get = objStore.get("hba_keys") - get.onsuccess = () => { - let keys = get.result - window.crypto.subtle.exportKey("raw", keys.publicKey).then(buffer => { - let binary = ''; - const bytes = new Uint8Array(buffer); - const len = bytes.byteLength; - for (let i = 0; i < len; i++) { - binary += String.fromCharCode(bytes[i]); - } - console.log(window.btoa(binary)) - }) - } - transaction.oncomplete = () => db.close() - } -})();*/ - - - -// Helper function to convert PEM to ArrayBuffer -function pemToArrayBuffer(pem: string) { - const b64Lines = pem.replace(/-----[^-]+-----/g, "").replace(/\s+/g, ""); - const b64 = window.atob(b64Lines); - const arrayBuffer = new ArrayBuffer(b64.length); - const uint8Array = new Uint8Array(arrayBuffer); - for (let i = 0; i < b64.length; i++) { - uint8Array[i] = b64.charCodeAt(i); - } - return arrayBuffer; -} - - - - - - -/*function spkiToPEM(keydata) { - var keydataS = arrayBufferToString(keydata); - var keydataB64 = btoa(keydataS); - var keydataB64Pem = formatAsPem(keydataB64); - return keydataB64Pem; -} - -function arrayBufferToString( buffer ) { - var binary = ''; - var bytes = new Uint8Array( buffer ); - var len = bytes.byteLength; - for (var i = 0; i < len; i++) { - binary += String.fromCharCode( bytes[ i ] ); - } - return binary; -} - -function formatAsPem(str) { - var finalString = '-----BEGIN PUBLIC KEY-----\n'; - - while(str.length > 0) { - finalString += str.substring(0, 64) + '\n'; - str = str.substring(64); - } - - finalString = finalString + "-----END PUBLIC KEY-----"; - - return finalString; -}*/ - - - - -/*(async () => { - crypto.subtle.generateKey( - { - name: "ECDSA", - namedCurve: "P-256", - }, - true, - ["sign"], - ).then((keys) => { - console.log(keys) - crypto.subtle.exportKey("jwk", keys.publicKey).then(key => console.log(jwkToPem(key))) - crypto.subtle.exportKey("jwk", keys.privateKey).then(key => console.log(jwkToPem(key))) - //crypto.subtle.exportKey("jwk", keys.privateKey).then(key => console.log(jwkToPem(key).then(key => console.log(key)))) - }) - - -})(); - - - -*/ +} \ No newline at end of file