Skip to content

Commit

Permalink
fix: update event names, history types, rpc action types (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewCLu committed Sep 30, 2023
1 parent 6762991 commit 980320e
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 178 deletions.
32 changes: 16 additions & 16 deletions packages/app/src/background/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,26 @@ function injectScript() {
);
return;
}
case EventName.ADD_VERIFIABLE_CREDENTIAL: {
case EventName.NEW_VERIFIABLE_CREDENTIAL: {
window.postMessage(
{
target: "injected-injectedscript",
payload: [null, (action.payload as { verifiableCredentialHash: string }).verifiableCredentialHash],
nonce: EventName.ADD_VERIFIABLE_CREDENTIAL,
nonce: EventName.NEW_VERIFIABLE_CREDENTIAL,
},
"*",
);
break;
}
case EventName.NEW_VERIFIABLE_PRESENTATION: {
window.postMessage(
{
target: "injected-injectedscript",
payload: [
null,
(action.payload as { verifiablePresentation: IVerifiablePresentation }).verifiablePresentation,
],
nonce: EventName.NEW_VERIFIABLE_PRESENTATION,
},
"*",
);
Expand Down Expand Up @@ -120,20 +134,6 @@ function injectScript() {
);
break;
}
case EventName.GENERATE_VERIFIABLE_PRESENTATION: {
window.postMessage(
{
target: "injected-injectedscript",
payload: [
null,
(action.payload as { verifiablePresentation: IVerifiablePresentation }).verifiablePresentation,
],
nonce: EventName.GENERATE_VERIFIABLE_PRESENTATION,
},
"*",
);
break;
}
default:
log.warn("unknown action in content script");
}
Expand Down
14 changes: 7 additions & 7 deletions packages/app/src/background/cryptKeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const RPC_METHOD_ACCESS: Record<RPCAction, boolean> = {
[RPCAction.CREATE_IDENTITY_REQUEST]: true,
[RPCAction.GENERATE_SEMAPHORE_PROOF]: true,
[RPCAction.GENERATE_RLN_PROOF]: true,
[RPCAction.ADD_VERIFIABLE_CREDENTIAL_REQUEST]: true,
[RPCAction.GENERATE_VERIFIABLE_PRESENTATION_REQUEST]: true,
[RPCAction.HANDLE_VERIFIABLE_CREDENTIAL_REQUEST]: true,
[RPCAction.HANDLE_VERIFIABLE_PRESENTATION_REQUEST]: true,
[RPCAction.REVEAL_CONNECTED_IDENTITY_COMMITMENT_REQUEST]: true,
[RPCAction.JOIN_GROUP_REQUEST]: true,
[RPCAction.GENERATE_GROUP_MERKLE_PROOF_REQUEST]: true,
Expand Down Expand Up @@ -219,10 +219,10 @@ export default class CryptKeeperController {
this.verifiableCredentialsService.addVC,
);
this.handler.add(
RPCAction.ADD_VERIFIABLE_CREDENTIAL_REQUEST,
RPCAction.HANDLE_VERIFIABLE_CREDENTIAL_REQUEST,
this.lockService.ensure,
validateSerializedVC,
this.verifiableCredentialsService.addVCRequest,
this.verifiableCredentialsService.handleVCRequest,
);
this.handler.add(
RPCAction.REJECT_VERIFIABLE_CREDENTIAL_REQUEST,
Expand Down Expand Up @@ -250,17 +250,17 @@ export default class CryptKeeperController {
this.verifiableCredentialsService.deleteAllVC,
);
this.handler.add(
RPCAction.GENERATE_VERIFIABLE_PRESENTATION,
RPCAction.ANNOUNCE_VERIFIABLE_PRESENTATION,
this.lockService.ensure,
this.verifiableCredentialsService.announceVP,
);
this.handler.add(
RPCAction.GENERATE_VERIFIABLE_PRESENTATION_WITH_CRYPTKEEPER,
RPCAction.SIGN_AND_ANNOUNCE_VERIFIABLE_PRESENTATION,
this.lockService.ensure,
this.verifiableCredentialsService.signAndAnnounceVP,
);
this.handler.add(
RPCAction.GENERATE_VERIFIABLE_PRESENTATION_REQUEST,
RPCAction.HANDLE_VERIFIABLE_PRESENTATION_REQUEST,
this.lockService.ensure,
this.verifiableCredentialsService.handleVPRequest,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe("background/services/credentials", () => {

describe("add and reject verifiable credential requests", () => {
test("should successfully create an add verifiable credential request", async () => {
await verifiableCredentialsService.addVCRequest(exampleCredentialString);
await verifiableCredentialsService.handleVCRequest(exampleCredentialString);

expect(browser.tabs.query).toBeCalledWith({ lastFocusedWindow: true });

Expand All @@ -160,7 +160,7 @@ describe("background/services/credentials", () => {
expect(browser.tabs.query).toBeCalledWith({ lastFocusedWindow: true });
expect(browser.tabs.sendMessage).toBeCalledWith(defaultTabs[0].id, {
type: EventName.USER_REJECT,
payload: { type: EventName.ADD_VERIFIABLE_CREDENTIAL },
payload: { type: EventName.VERIFIABLE_CREDENTIAL_REQUEST },
});
});
});
Expand Down Expand Up @@ -197,7 +197,7 @@ describe("background/services/credentials", () => {

expect(browser.tabs.query).toBeCalledWith({ lastFocusedWindow: true });
expect(browser.tabs.sendMessage).toBeCalledWith(defaultTabs[0].id, {
type: EventName.GENERATE_VERIFIABLE_PRESENTATION,
type: EventName.NEW_VERIFIABLE_PRESENTATION,
payload: { verifiablePresentation: exampleVerifiablePresentation },
});
});
Expand Down Expand Up @@ -227,7 +227,7 @@ describe("background/services/credentials", () => {

expect(browser.tabs.query).toBeCalledWith({ lastFocusedWindow: true });
expect(browser.tabs.sendMessage).toBeCalledWith(defaultTabs[0].id, {
type: EventName.GENERATE_VERIFIABLE_PRESENTATION,
type: EventName.NEW_VERIFIABLE_PRESENTATION,
payload: { verifiablePresentation: signedVerifiablePresentation },
});
});
Expand Down
Loading

0 comments on commit 980320e

Please sign in to comment.