Skip to content

Commit

Permalink
♻️ review poe communication
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Burg committed Mar 25, 2024
1 parent ad18446 commit 124ed38
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
16 changes: 11 additions & 5 deletions context/P2PClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
WalletClientOptions,
SigningType,
BeaconResponseInputMessage,
encodePoeChallengePayload,
} from "@airgap/beacon-sdk";
import { PreapplyParams } from "@taquito/rpc";
import { TinyEmitter } from "tiny-emitter";
import { generatePoEPayloadHash } from "../utils/hash";

export enum Event {
PERMISSION_REQUEST = "PERMISSION_REQUEST",
Expand Down Expand Up @@ -96,7 +96,8 @@ class P2PClient extends WalletClient {
...this.proofOfEvent.message,
type: BeaconMessageType.ProofOfEventChallengeResponse,
isAccepted: true,
payloadHash: generatePoEPayloadHash(this.proofOfEvent.message.payload),
payloadHash: encodePoeChallengePayload(this.proofOfEvent.message.payload),
payload: undefined,
};

this.proofOfEvent = { message: undefined, data: undefined };
Expand All @@ -107,12 +108,17 @@ class P2PClient extends WalletClient {
async refusePoeChallenge() {
if (!this.proofOfEvent.message) throw new Error("Poe not received");

return this.respond({
const payload = {
...this.proofOfEvent.message,
type: BeaconMessageType.ProofOfEventChallengeResponse,
isAccepted: false,
payloadHash: generatePoEPayloadHash(this.proofOfEvent.message.payload),
});
payloadHash: encodePoeChallengePayload(this.proofOfEvent.message.payload),
payload: undefined,
};

this.proofOfEvent = { message: undefined, data: undefined };

return this.respond(payload as BeaconResponseInputMessage);
}

handleMessages = async (
Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@radix-ui/react-select": "^1.2.0",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.3",
"@stablelib/blake2b": "^1.0.1",
"@taquito/beacon-wallet": "^17.2.0",
"@taquito/taquito": "^17.2.0",
"@taquito/tzip12": "^17.5.2",
Expand All @@ -38,7 +39,6 @@
"assert-never": "^1.2.1",
"axios": "^1.6.5",
"bignumber.js": "^9.1.1",
"blakejs": "^1.2.1",
"bs58check": "^3",
"env-cmd": "^10.1.0",
"eslint": "8.28.0",
Expand Down
16 changes: 0 additions & 16 deletions utils/hash.ts

This file was deleted.

3 changes: 1 addition & 2 deletions versioned/version0_3_4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { BigNumber } from "bignumber.js";
import { content, contractStorage as c1 } from "../types/Proposal0_3_4";
import { contractStorage } from "../types/app";
import { proposalContent } from "../types/display";
import { generatePoEPayloadHash } from "../utils/hash";
import { toStorage } from "./apis";
import { proposals } from "./interface";
import Version0_3_3 from "./version0_3_3";
Expand All @@ -19,7 +18,7 @@ class Version0_3_4 extends Version0_3_3 {
async generateSpoeOps(payload: string, cc: WalletContract, t: TezosToolkit) {
const storage = toStorage(this.version, await cc.storage(), BigNumber(0));
const proposal_id = storage.proposal_counter.plus(1);
const encodedPayload = char2Bytes(payload);
const encodedPayload = stringToBytes(payload);

const ops = [
cc.methods.proof_of_event_challenge(encodedPayload).toTransferParams(),
Expand Down

0 comments on commit 124ed38

Please sign in to comment.