Skip to content

Commit

Permalink
fixed regression with dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Campbell authored and Cameron Campbell committed Jul 27, 2024
1 parent a07cd62 commit 6016bfd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 156 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/apis/cloud/orderedDataStores_V1/orderedDataStores_V1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// [ Modules ] ///////////////////////////////////////////////////////////////////
import { createApiGroup } from "../../apiGroup"
import { cloneAndMutateObject, dataIsSuccess } from "../../../utils/utils"
import { dataIsSuccess } from "../../../utils/utils"
//////////////////////////////////////////////////////////////////////////////////


Expand All @@ -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" })
//////////////////////////////////////////////////////////////////////////////////


Expand Down
153 changes: 1 addition & 152 deletions src/http/httpHandler/httpHandler.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -53,42 +51,6 @@ export const getParsedErrors = async (response: HttpResponse): Promise<any> => {
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, any, string>(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<CryptoKeyPair> => {
return { privateKey: await importPrivateKey(keys.private), publicKey: await importPublicKey(keys.public) }
}
//////////////////////////////////////////////////////////////////////////////////


Expand All @@ -109,27 +71,12 @@ export const HttpHandler = async <RawData extends any = any>(
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<HttpResponse<RawData> | HttpError> => {
Expand Down Expand Up @@ -161,102 +108,4 @@ export const HttpHandler = async <RawData extends any = any>(
}

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))))
})
})();
*/
}

0 comments on commit 6016bfd

Please sign in to comment.