From 160101a05d626bd580a45dd4f10aedc092330c2d Mon Sep 17 00:00:00 2001 From: ayman Date: Thu, 18 Sep 2025 13:37:03 +0530 Subject: [PATCH 1/2] chore: ci to publish contracts --- .github/workflows/npm-publish.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index b3872d330..97c9af13c 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -17,6 +17,7 @@ jobs: core_changed: ${{ steps.check-version.outputs.core_changed }} qrcode_changed: ${{ steps.check-version.outputs.qrcode_changed }} common_changed: ${{ steps.check-version.outputs.common_changed }} + contracts_changed: ${{ steps.check-version.outputs.contracts_changed }} steps: - uses: actions/checkout@v4 with: @@ -42,6 +43,10 @@ jobs: echo "common_changed=true" >> $GITHUB_OUTPUT fi + if git diff HEAD^ HEAD -- contracts/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "contracts_changed=true" >> $GITHUB_OUTPUT + fi + publish-core: needs: detect-changes if: needs.detect-changes.outputs.core_changed == 'true' @@ -128,3 +133,29 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + publish-contracts: + needs: detect-changes + if: needs.detect-changes.outputs.contracts_changed == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + registry-url: "https://registry.npmjs.org" + - uses: actions/checkout@v4 + - name: Install Dependencies + uses: ./.github/actions/yarn-install + - name: Build package + run: | + yarn workspace @selfxyz/contracts build + - name: Publish to npm + working-directory: contracts + run: | + yarn config set npmScopes.selfxyz.npmAuthToken ${{ secrets.NPM_TOKEN }} + yarn config set npmPublishAccess public + yarn npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 8ae7e837c8ebe1cba34c695129351421f0967d2d Mon Sep 17 00:00:00 2001 From: ayman Date: Thu, 18 Sep 2025 13:38:11 +0530 Subject: [PATCH 2/2] yarn fmt --- contracts/contracts/libraries/SelfUtils.sol | 20 ++++----- contracts/contracts/tests/TestSelfUtils.sol | 8 ++-- contracts/test/unit/SelfUtils.test.ts | 49 ++++++++++++--------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/contracts/contracts/libraries/SelfUtils.sol b/contracts/contracts/libraries/SelfUtils.sol index 8e6ec16f9..1a06fabcf 100644 --- a/contracts/contracts/libraries/SelfUtils.sol +++ b/contracts/contracts/libraries/SelfUtils.sol @@ -14,11 +14,9 @@ library SelfUtils { * @param forbiddenCountries Array of 3-character country codes * @return output Array of 4 uint256 values containing packed country data */ - function packForbiddenCountriesList(string[] memory forbiddenCountries) - internal - pure - returns (uint256[4] memory output) - { + function packForbiddenCountriesList( + string[] memory forbiddenCountries + ) internal pure returns (uint256[4] memory output) { uint256 MAX_BYTES_IN_FIELD = 31; uint256 REQUIRED_CHUNKS = 4; @@ -82,11 +80,9 @@ library SelfUtils { * - Packed forbidden countries list for efficient circuit processing * - Replicated OFAC settings across all verification levels */ - function formatVerificationConfigV2(UnformattedVerificationConfigV2 memory unformattedVerificationConfigV2) - internal - pure - returns (SelfStructs.VerificationConfigV2 memory verificationConfigV2) - { + function formatVerificationConfigV2( + UnformattedVerificationConfigV2 memory unformattedVerificationConfigV2 + ) internal pure returns (SelfStructs.VerificationConfigV2 memory verificationConfigV2) { bool[3] memory ofacArray; ofacArray[0] = unformattedVerificationConfigV2.ofacEnabled; ofacArray[1] = unformattedVerificationConfigV2.ofacEnabled; @@ -96,7 +92,9 @@ library SelfUtils { olderThanEnabled: unformattedVerificationConfigV2.olderThan > 0, olderThan: unformattedVerificationConfigV2.olderThan, forbiddenCountriesEnabled: unformattedVerificationConfigV2.forbiddenCountries.length > 0, - forbiddenCountriesListPacked: packForbiddenCountriesList(unformattedVerificationConfigV2.forbiddenCountries), + forbiddenCountriesListPacked: packForbiddenCountriesList( + unformattedVerificationConfigV2.forbiddenCountries + ), ofacEnabled: ofacArray }); } diff --git a/contracts/contracts/tests/TestSelfUtils.sol b/contracts/contracts/tests/TestSelfUtils.sol index 5295c78a9..4764bf5ff 100644 --- a/contracts/contracts/tests/TestSelfUtils.sol +++ b/contracts/contracts/tests/TestSelfUtils.sol @@ -5,11 +5,9 @@ import "../libraries/SelfUtils.sol"; import "../libraries/CountryCode.sol"; contract TestSelfUtils { - function testPackForbiddenCountriesList(string[] memory forbiddenCountries) - external - pure - returns (uint256[4] memory) - { + function testPackForbiddenCountriesList( + string[] memory forbiddenCountries + ) external pure returns (uint256[4] memory) { return SelfUtils.packForbiddenCountriesList(forbiddenCountries); } diff --git a/contracts/test/unit/SelfUtils.test.ts b/contracts/test/unit/SelfUtils.test.ts index 2ef9e124d..cfb0740d3 100644 --- a/contracts/test/unit/SelfUtils.test.ts +++ b/contracts/test/unit/SelfUtils.test.ts @@ -19,7 +19,7 @@ describe("SelfUtils", function () { const tsResult = packForbiddenCountriesList(input); // Convert TypeScript result to the same format as contract result - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -31,7 +31,7 @@ describe("SelfUtils", function () { const contractResult = await testSelfUtils.testPackForbiddenCountriesList(input); const tsResult = packForbiddenCountriesList(input); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -43,7 +43,7 @@ describe("SelfUtils", function () { const contractResult = await testSelfUtils.testPackForbiddenCountriesList(input); const tsResult = packForbiddenCountriesList(input); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -53,14 +53,19 @@ describe("SelfUtils", function () { it("should match contract and TypeScript implementation for maximum capacity", async function () { // Create array that fills multiple chunks const countries = []; - for (let i = 0; i < 41; i++) { // 41 * 3 = 123 bytes, needs 4 chunks (31 bytes each) - countries.push(String.fromCharCode(65 + (i % 26)) + String.fromCharCode(65 + ((i + 1) % 26)) + String.fromCharCode(65 + ((i + 2) % 26))); + for (let i = 0; i < 41; i++) { + // 41 * 3 = 123 bytes, needs 4 chunks (31 bytes each) + countries.push( + String.fromCharCode(65 + (i % 26)) + + String.fromCharCode(65 + ((i + 1) % 26)) + + String.fromCharCode(65 + ((i + 2) % 26)), + ); } const contractResult = await testSelfUtils.testPackForbiddenCountriesList(countries); const tsResult = packForbiddenCountriesList(countries); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -72,7 +77,7 @@ describe("SelfUtils", function () { const contractResult = await testSelfUtils.testPackForbiddenCountriesList(input); const tsResult = packForbiddenCountriesList(input); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -84,8 +89,9 @@ describe("SelfUtils", function () { // Both implementations should reject this expect(() => packForbiddenCountriesList(input)).to.throw("Invalid country code"); - await expect(testSelfUtils.testPackForbiddenCountriesList(input)) - .to.be.revertedWith("Invalid country code: must be exactly 3 characters long"); + await expect(testSelfUtils.testPackForbiddenCountriesList(input)).to.be.revertedWith( + "Invalid country code: must be exactly 3 characters long", + ); }); it("should reject country codes that are too long", async function () { @@ -93,8 +99,9 @@ describe("SelfUtils", function () { // Both implementations should reject this expect(() => packForbiddenCountriesList(input)).to.throw("Invalid country code"); - await expect(testSelfUtils.testPackForbiddenCountriesList(input)) - .to.be.revertedWith("Invalid country code: must be exactly 3 characters long"); + await expect(testSelfUtils.testPackForbiddenCountriesList(input)).to.be.revertedWith( + "Invalid country code: must be exactly 3 characters long", + ); }); it("should reject empty country codes", async function () { @@ -102,8 +109,9 @@ describe("SelfUtils", function () { // Both implementations should reject this expect(() => packForbiddenCountriesList(input)).to.throw("Invalid country code"); - await expect(testSelfUtils.testPackForbiddenCountriesList(input)) - .to.be.revertedWith("Invalid country code: must be exactly 3 characters long"); + await expect(testSelfUtils.testPackForbiddenCountriesList(input)).to.be.revertedWith( + "Invalid country code: must be exactly 3 characters long", + ); }); it("should handle mixed valid and invalid codes consistently", async function () { @@ -111,8 +119,9 @@ describe("SelfUtils", function () { // Both implementations should reject this expect(() => packForbiddenCountriesList(input)).to.throw("Invalid country code"); - await expect(testSelfUtils.testPackForbiddenCountriesList(input)) - .to.be.revertedWith("Invalid country code: must be exactly 3 characters long"); + await expect(testSelfUtils.testPackForbiddenCountriesList(input)).to.be.revertedWith( + "Invalid country code: must be exactly 3 characters long", + ); }); it("should handle special characters in country codes", async function () { @@ -120,7 +129,7 @@ describe("SelfUtils", function () { const contractResult = await testSelfUtils.testPackForbiddenCountriesList(input); const tsResult = packForbiddenCountriesList(input); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -159,7 +168,7 @@ describe("SelfUtils", function () { const contractResult = await testSelfUtils.testPackForbiddenCountriesList(forbiddenCountries); const tsResult = packForbiddenCountriesList(forbiddenCountries); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -176,7 +185,7 @@ describe("SelfUtils", function () { // Create equivalent array in TypeScript for comparison const forbiddenCountries = ["CHN", "RUS", "IRN", "PRK", "CUB", "SYR", "AFG", "SOM"]; const tsResult = packForbiddenCountriesList(forbiddenCountries); - const expectedResults = tsResult.map(hex => BigInt(hex)); + const expectedResults = tsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(contractResult[i]).to.equal(expectedResults[i]); @@ -188,7 +197,7 @@ describe("SelfUtils", function () { const highRiskResult = await testSelfUtils.testPackHighRiskCountries(); const highRiskCountries = ["AFG", "SOM", "SDN", "YEM"]; const highRiskTsResult = packForbiddenCountriesList(highRiskCountries); - const highRiskExpected = highRiskTsResult.map(hex => BigInt(hex)); + const highRiskExpected = highRiskTsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(highRiskResult[i]).to.equal(highRiskExpected[i]); @@ -198,7 +207,7 @@ describe("SelfUtils", function () { const euResult = await testSelfUtils.testPackEUCountries(); const euCountries = ["DEU", "FRA", "ITA", "ESP", "NLD"]; const euTsResult = packForbiddenCountriesList(euCountries); - const euExpected = euTsResult.map(hex => BigInt(hex)); + const euExpected = euTsResult.map((hex) => BigInt(hex)); for (let i = 0; i < 4; i++) { expect(euResult[i]).to.equal(euExpected[i]);