From 7153be594851fb755f67035317c9fdc8c40682c2 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Sat, 18 Mar 2023 12:13:58 -0500 Subject: [PATCH] some cleanup --- packages/background/src/backend/core.ts | 57 ++++++++----------- packages/background/src/frontend/server-ui.ts | 39 ------------- packages/common/src/constants.ts | 4 -- packages/common/src/plugin.ts | 22 ------- 4 files changed, 24 insertions(+), 98 deletions(-) diff --git a/packages/background/src/backend/core.ts b/packages/background/src/backend/core.ts index 76f40ea24..89493c72d 100644 --- a/packages/background/src/backend/core.ts +++ b/packages/background/src/backend/core.ts @@ -1322,6 +1322,10 @@ export class Backend { ); } + /////////////////////////////////////////////////////////////////////////////// + // User account. + /////////////////////////////////////////////////////////////////////////////// + /** * Add a public key to a Backpack account via the Backpack API. */ @@ -1541,31 +1545,12 @@ export class Backend { return json; } - /** - * Query the Backpack API to check if a user has already used any of the - * blockchain/public key pairs from a list. - */ - async findServerPublicKeyConflicts( - serverPublicKeys: ServerPublicKey[] - ): Promise { - const url = `${BACKEND_API_URL}/publicKeys`; - const response = await fetch(url, { - method: "POST", - body: JSON.stringify(serverPublicKeys), - headers: { - "Content-Type": "application/json", - }, - }).then((r) => r.json()); - - return response; - } - /** * Find a `WalletDescriptor` that can be used to create a new account. * This requires that the sub wallets on the account index are not used by a * existing user account. This is checked by querying the Backpack API. * - * This only works for mnemonics or a keyring store unlocked with a mnemoni + * This only works for mnemonics or a keyring store unlocked with a mnemonic * because the background service worker can't use a Ledger. */ async findWalletDescriptor( @@ -1605,6 +1590,25 @@ export class Backend { } } + /** + * Query the Backpack API to check if a user has already used any of the + * blockchain/public key pairs from a list. + */ + async findServerPublicKeyConflicts( + serverPublicKeys: ServerPublicKey[] + ): Promise { + const url = `${BACKEND_API_URL}/publicKeys`; + const response = await fetch(url, { + method: "POST", + body: JSON.stringify(serverPublicKeys), + headers: { + "Content-Type": "application/json", + }, + }).then((r) => r.json()); + + return response; + } + /////////////////////////////////////////////////////////////////////////////// // Preferences. /////////////////////////////////////////////////////////////////////////////// @@ -2023,19 +2027,6 @@ export class Backend { return SUCCESS_RESPONSE; } - - async pluginLocalStorageGet(xnftAddress: string, key: string): Promise { - return await store.LocalStorageDb.get(`${xnftAddress}:${key}`); - } - - async pluginLocalStoragePut( - xnftAddress: string, - key: string, - value: any - ): Promise { - await store.LocalStorageDb.set(`${xnftAddress}:${key}`, value); - return SUCCESS_RESPONSE; - } } export const SUCCESS_RESPONSE = "success"; diff --git a/packages/background/src/frontend/server-ui.ts b/packages/background/src/frontend/server-ui.ts index 1c336c432..4a8a59604 100644 --- a/packages/background/src/frontend/server-ui.ts +++ b/packages/background/src/frontend/server-ui.ts @@ -75,8 +75,6 @@ import { UI_RPC_METHOD_NAVIGATION_TO_DEFAULT, UI_RPC_METHOD_NAVIGATION_TO_ROOT, UI_RPC_METHOD_PASSWORD_UPDATE, - UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_GET, - UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_PUT, UI_RPC_METHOD_PREFERENCES_READ, UI_RPC_METHOD_PREVIEW_PUBKEYS, UI_RPC_METHOD_SET_FEATURE_GATES, @@ -369,18 +367,6 @@ async function handle( case UI_RPC_METHOD_KEYRING_STORE_CHECK_PASSWORD: return await handleKeyringStoreCheckPassword(ctx, params[0]); // - // xNFT storage. - // - case UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_GET: - return await handlePluginLocalStorageGet(ctx, params[0], params[1]); - case UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_PUT: - return await handlePluginLocalStoragePut( - ctx, - params[0], - params[1], - params[2] - ); - // // Solana. // case UI_RPC_METHOD_SOLANA_SIMULATE: @@ -1145,28 +1131,3 @@ async function handlePreviewPubkeys( const resp = await ctx.backend.previewPubkeys(...args); return [resp]; } - -// This API is only safe because it assumes the frontend UI code is doing -// the proper gatekeeping. It shouldn't allow other xNFTs to call this -// api with a fake plugin string. -async function handlePluginLocalStorageGet( - ctx: Context, - xnftAddress: string, - key: string -): Promise> { - const resp = await ctx.backend.pluginLocalStorageGet(xnftAddress, key); - return [resp]; -} - -// This API is only safe because it assumes the frontend UI code is doing -// the proper gatekeeping. It shouldn't allow other xNFTs to call this -// api with a fake plugin string. -async function handlePluginLocalStoragePut( - ctx: Context, - xnftAddress: string, - key: string, - value: any -): Promise> { - const resp = await ctx.backend.pluginLocalStoragePut(xnftAddress, key, value); - return [resp]; -} diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts index 769436990..6f9df45f8 100644 --- a/packages/common/src/constants.ts +++ b/packages/common/src/constants.ts @@ -174,10 +174,6 @@ export const UI_RPC_METHOD_NAVIGATION_TO_ROOT = export const UI_RPC_METHOD_NAVIGATION_TO_DEFAULT = "ui-rpc-method-navigation-to-default"; export const UI_RPC_METHOD_PASSWORD_UPDATE = "ui-rpc-method-password-update"; -export const UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_GET = - "ui-rpc-method-plugin-storage-get"; -export const UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_PUT = - "ui-rpc-method-plugin-storage-put"; export const UI_RPC_METHOD_SET_FEATURE_GATES = "ui-rpc-method-set-feature-gates"; export const UI_RPC_METHOD_GET_FEATURE_GATES = diff --git a/packages/common/src/plugin.ts b/packages/common/src/plugin.ts index 96cb0088c..d9e19c8f6 100644 --- a/packages/common/src/plugin.ts +++ b/packages/common/src/plugin.ts @@ -38,8 +38,6 @@ import { SOLANA_RPC_METHOD_SIGN_MESSAGE as PLUGIN_SOLANA_RPC_METHOD_SIGN_MESSAGE, SOLANA_RPC_METHOD_SIGN_TX as PLUGIN_SOLANA_RPC_METHOD_SIGN_TX, SOLANA_RPC_METHOD_SIMULATE as PLUGIN_SOLANA_RPC_METHOD_SIMULATE_TX, - UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_GET, - UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_PUT, } from "./constants"; import { getLogger } from "./logging"; import type { Event, RpcResponse, XnftMetadata, XnftPreference } from "./types"; @@ -415,10 +413,6 @@ export class Plugin { const { method, params } = req; switch (method) { - case PLUGIN_RPC_METHOD_LOCAL_STORAGE_GET: - return await this._handleGet(params[0]); - case PLUGIN_RPC_METHOD_LOCAL_STORAGE_PUT: - return await this._handlePut(params[0], params[1]); case PLUGIN_RPC_METHOD_WINDOW_OPEN: return await this._handleWindowOpen(params[0]); case PLUGIN_RPC_METHOD_PLUGIN_OPEN: @@ -582,22 +576,6 @@ export class Plugin { return ["success"]; } - private async _handleGet(key: string): Promise { - const resp = await this._backgroundClient?.request({ - method: UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_GET, - params: [this.xnftAddress.toString(), key], - }); - return [resp]; - } - - private async _handlePut(key: string, value: any): Promise { - const resp = await this._backgroundClient?.request({ - method: UI_RPC_METHOD_PLUGIN_LOCAL_STORAGE_PUT, - params: [this.xnftAddress.toString(), key, value], - }); - return [resp]; - } - private async _handlePopout(fullscreen: boolean): Promise { if (fullscreen) { window.open("popup.html", "_blank");