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

Feat/46 #47

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions src/handlers/generate-erc20-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Payload {
evmNetworkId: number;
evmPrivateEncrypted: string;
walletAddress: string;
issueId: number;
issueNodeId: string;
logger: Logger;
userId: number;
}
Expand All @@ -25,17 +25,17 @@ export async function generateErc20PermitSignature(
let _logger: Logger;
const _username = username;
let _walletAddress: string | null | undefined;
let _issueId: number;
let _issueNodeId: string;
let _evmNetworkId: number;
let _evmPrivateEncrypted: string;
let _userId: number;

if ("issueId" in contextOrPayload) {
if ("issueNodeId" in contextOrPayload) {
_logger = contextOrPayload.logger as Logger;
_walletAddress = contextOrPayload.walletAddress;
_evmNetworkId = contextOrPayload.evmNetworkId;
_evmPrivateEncrypted = contextOrPayload.evmPrivateEncrypted;
_issueId = contextOrPayload.issueId;
_issueNodeId = contextOrPayload.issueNodeId;
_userId = contextOrPayload.userId;
} else {
const config = contextOrPayload.config;
Expand All @@ -51,9 +51,9 @@ export async function generateErc20PermitSignature(
_evmNetworkId = evmNetworkId;
_evmPrivateEncrypted = evmPrivateEncrypted;
if ("issue" in contextOrPayload.payload) {
_issueId = contextOrPayload.payload.issue.id;
_issueNodeId = contextOrPayload.payload.issue.node_id;
} else if ("pull_request" in contextOrPayload.payload) {
_issueId = contextOrPayload.payload.pull_request.id;
_issueNodeId = contextOrPayload.payload.pull_request.node_id;
} else {
throw new Error("Issue Id is missing");
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export async function generateErc20PermitSignature(
amount: parseUnits(amount.toString(), tokenDecimals),
},
spender: _walletAddress,
nonce: BigInt(keccak256(toUtf8Bytes(`${_userId}-${_issueId}`))),
nonce: BigInt(keccak256(toUtf8Bytes(`${_userId}-${_issueNodeId}`))),
deadline: MaxInt256,
};

Expand Down
12 changes: 6 additions & 6 deletions src/handlers/generate-erc721-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface PermitPayload {
nftContractAddress: string;
walletAddress: string;
logger: Logger;
issueId: string;
issueNodeId: string;
organizationName: string;
repositoryName: string;
userId: number;
Expand All @@ -51,7 +51,7 @@ export async function generateErc721PermitSignature(
let _nftMinterPrivateKey: string;
let _userId: number;
let _walletAddress: string;
let _issueId: string;
let _issueNodeId: string;
let _organizationName: string;
let _repositoryName: string;
let _username = username;
Expand All @@ -62,7 +62,7 @@ export async function generateErc721PermitSignature(
_nftMinterPrivateKey = contextOrPermitPayload.nftMinterPrivateKey;
_evmNetworkId = contextOrPermitPayload.evmNetworkId;
_walletAddress = contextOrPermitPayload.walletAddress;
_issueId = contextOrPermitPayload.issueId;
_issueNodeId = contextOrPermitPayload.issueNodeId;
_organizationName = contextOrPermitPayload.organizationName;
_repositoryName = contextOrPermitPayload.repositoryName;
_userId = contextOrPermitPayload.userId;
Expand All @@ -76,7 +76,7 @@ export async function generateErc721PermitSignature(
_nftMinterPrivateKey = NFT_MINTER_PRIVATE_KEY;
_username = username;
if (isIssueEvent(contextOrPermitPayload)) {
_issueId = contextOrPermitPayload.payload.issue.id.toString();
_issueNodeId = contextOrPermitPayload.payload.issue.node_id;
} else {
throw new Error("Issue Id is missing.");
}
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function generateErc721PermitSignature(
const erc721Metadata = {
GITHUB_ORGANIZATION_NAME: _organizationName,
GITHUB_REPOSITORY_NAME: _repositoryName,
GITHUB_ISSUE_ID: _issueId,
GITHUB_ISSUE_NODE_ID: _issueNodeId,
GITHUB_USERNAME: _username,
GITHUB_CONTRIBUTION_TYPE: contributionType,
};
Expand All @@ -130,7 +130,7 @@ export async function generateErc721PermitSignature(
beneficiary: _walletAddress,
deadline: MaxUint256.toBigInt(),
keys: metadata.map(([key]) => keccak256(toUtf8Bytes(key))),
nonce: BigInt(keccak256(toUtf8Bytes(`${_userId}-${_issueId}`))),
nonce: BigInt(keccak256(toUtf8Bytes(`${_userId}-${_issueNodeId}`))),
values: metadata.map(([, value]) => value),
};

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/permit-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const erc721PermitT = T.Object({
nftMetadata: T.Object({
GITHUB_ORGANIZATION_NAME: T.String(),
GITHUB_REPOSITORY_NAME: T.String(),
GITHUB_ISSUE_ID: T.String(),
GITHUB_ISSUE_NODE_ID: T.String(),
GITHUB_USERNAME: T.String(),
GITHUB_CONTRIBUTION_TYPE: T.String(),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/types/permits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Erc721PermitReward extends CommonFields {
metadata: {
GITHUB_ORGANIZATION_NAME: string;
GITHUB_REPOSITORY_NAME: string;
GITHUB_ISSUE_ID: string;
GITHUB_ISSUE_NODE_ID: string;
GITHUB_USERNAME: string;
GITHUB_CONTRIBUTION_TYPE: string;
};
Expand Down
1 change: 1 addition & 0 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const mockContext = {
issue: {
number: 123,
id: 123,
node_id: "123",
},
pull_request: {
number: 123,
Expand Down
2 changes: 1 addition & 1 deletion tests/encode-decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Encoding / Decoding tests", () => {
metadata: {
GITHUB_ORGANIZATION_NAME: "",
GITHUB_REPOSITORY_NAME: "",
GITHUB_ISSUE_ID: "",
GITHUB_ISSUE_NODE_ID: "",
GITHUB_USERNAME: "",
GITHUB_CONTRIBUTION_TYPE: "",
},
Expand Down
2 changes: 1 addition & 1 deletion tests/generate-erc721-permit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("generateErc721PermitSignature", () => {
const organizationName = "test";
const repositoryName = "test";
const issueNumber = issueId.toString();
const keys = ["GITHUB_ORGANIZATION_NAME", "GITHUB_REPOSITORY_NAME", "GITHUB_ISSUE_ID", "GITHUB_USERNAME", "GITHUB_CONTRIBUTION_TYPE"];
const keys = ["GITHUB_ORGANIZATION_NAME", "GITHUB_REPOSITORY_NAME", "GITHUB_ISSUE_NODE_ID", "GITHUB_USERNAME", "GITHUB_CONTRIBUTION_TYPE"];

if (result && typeof result === "object") {
expect(result).toBeDefined();
Expand Down