From 9228240cf5dd40d7dfd83a98a9c379e678a5bbc8 Mon Sep 17 00:00:00 2001 From: rndquu Date: Fri, 30 Aug 2024 19:42:36 +0300 Subject: [PATCH 1/2] fix: use issue.node_id for permit nonces --- src/handlers/generate-erc20-permit.ts | 14 +++++++------- src/handlers/generate-erc721-permit.ts | 12 ++++++------ src/types/permits.ts | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/handlers/generate-erc20-permit.ts b/src/handlers/generate-erc20-permit.ts index 9fd496e..e45d30a 100644 --- a/src/handlers/generate-erc20-permit.ts +++ b/src/handlers/generate-erc20-permit.ts @@ -9,7 +9,7 @@ export interface Payload { evmNetworkId: number; evmPrivateEncrypted: string; walletAddress: string; - issueId: number; + issueNodeId: string; logger: Logger; userId: number; } @@ -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; @@ -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"); } @@ -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, }; diff --git a/src/handlers/generate-erc721-permit.ts b/src/handlers/generate-erc721-permit.ts index d383c5b..745a4a5 100644 --- a/src/handlers/generate-erc721-permit.ts +++ b/src/handlers/generate-erc721-permit.ts @@ -32,7 +32,7 @@ export interface PermitPayload { nftContractAddress: string; walletAddress: string; logger: Logger; - issueId: string; + issueNodeId: string; organizationName: string; repositoryName: string; userId: number; @@ -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; @@ -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; @@ -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."); } @@ -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, }; @@ -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), }; diff --git a/src/types/permits.ts b/src/types/permits.ts index 708d29c..3300bd1 100644 --- a/src/types/permits.ts +++ b/src/types/permits.ts @@ -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; }; From 45bba3754d5fbf4a36a629261753b5f882a53ee5 Mon Sep 17 00:00:00 2001 From: rndquu Date: Fri, 30 Aug 2024 20:06:26 +0300 Subject: [PATCH 2/2] build: fix --- src/handlers/permit-type.ts | 2 +- tests/constants.ts | 1 + tests/encode-decode.test.ts | 2 +- tests/generate-erc721-permit.test.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/handlers/permit-type.ts b/src/handlers/permit-type.ts index 7ac4300..de79aac 100644 --- a/src/handlers/permit-type.ts +++ b/src/handlers/permit-type.ts @@ -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(), }), diff --git a/tests/constants.ts b/tests/constants.ts index a2d7486..42fde22 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -23,6 +23,7 @@ export const mockContext = { issue: { number: 123, id: 123, + node_id: "123", }, pull_request: { number: 123, diff --git a/tests/encode-decode.test.ts b/tests/encode-decode.test.ts index f16010e..003ca12 100644 --- a/tests/encode-decode.test.ts +++ b/tests/encode-decode.test.ts @@ -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: "", }, diff --git a/tests/generate-erc721-permit.test.ts b/tests/generate-erc721-permit.test.ts index ce0011d..847709c 100644 --- a/tests/generate-erc721-permit.test.ts +++ b/tests/generate-erc721-permit.test.ts @@ -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();