From 33cc5e9cc30a0a321b2c065c07c1a85c9ea3ebc8 Mon Sep 17 00:00:00 2001 From: JuanAgudeloRSL <167249920+JuanAgudeloRSL@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:16:16 +0000 Subject: [PATCH 1/3] fix: chipher and decypher typing --- .github/workflows/build.yml | 1 + src/commands/wallet.ts | 8 ++++---- src/utils/viemProvider.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed751d6..8743efa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - fix/ci-errors jobs: build: runs-on: ubuntu-latest diff --git a/src/commands/wallet.ts b/src/commands/wallet.ts index 98c8ae9..9a9957f 100644 --- a/src/commands/wallet.ts +++ b/src/commands/wallet.ts @@ -96,8 +96,8 @@ export async function walletCommand() { ); const iv = crypto.randomBytes(16); - const key = crypto.scryptSync(password!, iv, 32); - const cipher = crypto.createCipheriv("aes-256-cbc", key, iv); + const key = crypto.scryptSync(password!, Uint8Array.from(iv), 32); + const cipher = crypto.createCipheriv("aes-256-cbc", Uint8Array.from(key), Uint8Array.from(iv)); let encryptedPrivateKey = cipher.update( prefixedPrivateKey, @@ -161,8 +161,8 @@ export async function walletCommand() { ); const iv = crypto.randomBytes(16); - const key = crypto.scryptSync(password!, iv, 32); - const cipher = crypto.createCipheriv("aes-256-cbc", key, iv); + const key = crypto.scryptSync(password!, Uint8Array.from(iv), 32); + const cipher = crypto.createCipheriv("aes-256-cbc", Uint8Array.from(key), Uint8Array.from(iv)); let encryptedPrivateKey = cipher.update( prefixedPrivateKey, diff --git a/src/utils/viemProvider.ts b/src/utils/viemProvider.ts index b76aa02..14266c1 100644 --- a/src/utils/viemProvider.ts +++ b/src/utils/viemProvider.ts @@ -66,9 +66,9 @@ class ViemProvider { const { password } = await inquirer.prompt(passwordQuestion); try { - const decipherIv = Buffer.from(iv, "hex"); + const decipherIv = Uint8Array.from(Buffer.from(iv, "hex")); const key = crypto.scryptSync(password, decipherIv, 32); - const decipher = crypto.createDecipheriv("aes-256-cbc", key, decipherIv); + const decipher = crypto.createDecipheriv("aes-256-cbc", Uint8Array.from(key), decipherIv); let decryptedPrivateKey = decipher.update( encryptedPrivateKey, From 90b0259398dac07d5bac55cd14ae041335cc4cb1 Mon Sep 17 00:00:00 2001 From: JuanAgudeloRSL <167249920+JuanAgudeloRSL@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:26:35 +0000 Subject: [PATCH 2/3] fix: ci --- .github/workflows/build.yml | 22 ---------- .github/workflows/main.yml | 86 +++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 8743efa..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Build - -on: - push: - branches: - - main - - fix/ci-errors -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: '20.x' - - name: Install pnpm - run: npm install -g pnpm - - name: Install dependencies - run: pnpm install - - name: Build project - run: pnpm build diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 82f6f54..a4d13f0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,51 +1,56 @@ -name: Deploy library on NPM +name: CI Workflow on: release: types: [published] + push: + branches: + - main + - fix/ci-errors jobs: - publish: + build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: "Check file existence" - id: check_files - uses: andstor/file-existence-action@v3 + - name: Use Node.js + uses: actions/setup-node@v4 with: - files: "package.json, README.md" + node-version: '20.x' - - name: File exists - if: steps.check_files.outputs.files_exists != 'true' - # Only runs if all of the files exists - run: exit 1 + - name: Install pnpm + run: npm install -g pnpm + + - name: Install dependencies + run: pnpm install - - name: Get package.json package name and match with repository name + - name: Build project + run: pnpm build + + - name: Verify dist folder exists + run: | + if [ ! -d "dist" ]; then + echo "Error: dist folder not found!" + exit 1 + fi + + publish: + runs-on: ubuntu-latest + needs: build # This ensures publish runs only after build succeeds + + steps: + - name: Checkout + uses: actions/checkout@v4 run: | echo PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"" | cut -f2 -d"@") >> $GITHUB_OUTPUT echo PACKAGE_VERSION="refs/tags/v"$(cat package.json | jq .version | cut -f2 -d"\"") >> $GITHUB_OUTPUT echo PACKAGE_REPOSITORY=$(cat package.json | jq .repository | cut -f2 -d"\"" | sed 's/:/\//' | sed 's/@/:\/\//') >> $GITHUB_OUTPUT id: get_package_info - - name: Check if package_name matches with repository name - if: github.repository != steps.get_package_info.outputs.PACKAGE_NAME - # Fail if package name not properly configured - run: exit 1 - - - name: Check if package version matches with tag - if: github.ref != steps.get_package_info.outputs.PACKAGE_VERSION - # Fail if package version not properly setted - run: exit 1 - - - name: Check if package repository matches with repository - if: github.repositoryUrl != steps.get_package_info.outputs.PACKAGE_REPOSITORY - # Fail if package repository doesn't match with repository - run: exit 1 - - - name: Push package to npmjs.com + - name: Set up Node.js for npm publishing uses: actions/setup-node@v4 with: node-version: 20 @@ -54,36 +59,23 @@ jobs: - name: Install dependencies run: npm ci - - name: Build the project - run: npm run build - env: - CI: false - - - name: Verify dist folder exists - run: | - if [ ! -d "dist" ]; then - echo "Error: dist folder not found!" - exit 1 - fi - - - name: Pre upload validation + - name: Pre-upload validation id: pack run: | npm pack --dry-run >> output 2>&1 - echo PRE_UPLOAD_HASH=$(cat output| grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT + echo PRE_UPLOAD_HASH=$(cat output | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT - - name: Upload package + - name: Publish package run: npm publish --access public env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Post upload validation + - name: Post-upload validation id: unpack run: | PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"")@$(cat package.json | jq .version | cut -f2 -d"\"") - echo POST_UPLOAD_HASH=$(npm view $PACKAGE_NAME) >> $GITHUB_OUTPUT + echo POST_UPLOAD_HASH=$(npm view $PACKAGE_NAME | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT - - name: Pre and Post Upload validation + - name: Pre and post upload validation if: steps.pack.outputs.PRE_UPLOAD_HASH != steps.unpack.outputs.POST_UPLOAD_HASH - # Fail if package hashes doesn't match run: exit 1 From 70b947c76477837f4ffac013d6e7a3ea3412b884 Mon Sep 17 00:00:00 2001 From: JuanAgudeloRSL <167249920+JuanAgudeloRSL@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:37:14 +0000 Subject: [PATCH 3/3] fix: ci publishing --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a4d13f0..18bc827 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,7 +6,6 @@ on: push: branches: - main - - fix/ci-errors jobs: build: