Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: profile sync controller - add snap caching #4532

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,28 +311,48 @@ export default class AuthenticationController extends BaseController<
return THIRTY_MIN_MS > diffMs;
}

#_snapPublicKeyCache: string | undefined;

/**
* Returns the auth snap public key.
*
* @returns The snap public key.
*/
#snapGetPublicKey(): Promise<string> {
return this.messagingSystem.call(
async #snapGetPublicKey(): Promise<string> {
if (this.#_snapPublicKeyCache) {
return this.#_snapPublicKeyCache;
}

const result = (await this.messagingSystem.call(
'SnapController:handleRequest',
createSnapPublicKeyRequest(),
) as Promise<string>;
)) as string;

this.#_snapPublicKeyCache = result;

return result;
}

#_snapSignMessageCache: Record<`metamask:${string}`, string> = {};

/**
* Signs a specific message using an underlying auth snap.
*
* @param message - A specific tagged message to sign.
* @returns A Signature created by the snap.
*/
#snapSignMessage(message: `metamask:${string}`): Promise<string> {
return this.messagingSystem.call(
async #snapSignMessage(message: `metamask:${string}`): Promise<string> {
if (this.#_snapSignMessageCache[message]) {
return this.#_snapSignMessageCache[message];
}

const result = (await this.messagingSystem.call(
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
'SnapController:handleRequest',
createSnapSignMessageRequest(message),
) as Promise<string>;
)) as string;

this.#_snapSignMessageCache[message] = result;

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,27 @@ export default class UserStorageController extends BaseController<
return storageKey;
}

#_snapSignMessageCache: Record<`metamask:${string}`, string> = {};

/**
* Signs a specific message using an underlying auth snap.
*
* @param message - A specific tagged message to sign.
* @returns A Signature created by the snap.
*/
#snapSignMessage(message: `metamask:${string}`): Promise<string> {
return this.messagingSystem.call(
async #snapSignMessage(message: `metamask:${string}`): Promise<string> {
if (this.#_snapSignMessageCache[message]) {
return this.#_snapSignMessageCache[message];
}

const result = (await this.messagingSystem.call(
'SnapController:handleRequest',
createSnapSignMessageRequest(message),
) as Promise<string>;
)) as string;

this.#_snapSignMessageCache[message] = result;

return result;
}

#setIsProfileSyncingUpdateLoading(
Expand Down
Loading