From a24d3695c61c485f49254ca78682ee00af4e2aed Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Fri, 18 Oct 2024 17:14:31 +0100 Subject: [PATCH 1/2] fix: ignore non-utf-8 encoded notes (#341) * ci: replace dapp example deploy workflow to use github's actions * fix: parse note safely and skip non-utf-8 encoded notes --- .github/workflows/deploy_dapp_example.yml | 34 +++++++-------- .../mapAlgorandTransactionToTransaction.ts | 43 +++++++++---------- .../parseNote.ts | 29 +++++++++++++ 3 files changed, 66 insertions(+), 40 deletions(-) create mode 100644 src/extension/utils/mapAlgorandTransactionToTransaction/parseNote.ts diff --git a/.github/workflows/deploy_dapp_example.yml b/.github/workflows/deploy_dapp_example.yml index 9e568d62..ff66728d 100644 --- a/.github/workflows/deploy_dapp_example.yml +++ b/.github/workflows/deploy_dapp_example.yml @@ -6,32 +6,32 @@ on: - beta jobs: - install: - name: "Install" + build: + name: "Build" runs-on: ubuntu-latest steps: - name: "šŸ›Ž Checkout" uses: actions/checkout@v4 - name: "šŸ”§ Setup" uses: ./.github/actions/use-dependencies + - name: "šŸ—ļø Build" + run: yarn build:dapp-example + - name: "šŸ“¤ Upload artifact" + uses: actions/upload-pages-artifact@v3 + with: + path: ./.dapp_example_build deploy: name: "Deploy" - needs: [install] + needs: build + permissions: + pages: write # to deploy to pages + id-token: write # to verify the deployment originates from an appropriate source + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - - name: "šŸ›Ž Checkout" - uses: actions/checkout@v4 - - name: "šŸ”§ Setup" - uses: ./.github/actions/use-dependencies - - name: "šŸ—ļø Build" - run: yarn build:dapp-example - name: "šŸš€ Deploy" - uses: peaceiris/actions-gh-pages@v3 - with: - force_orphan: true # create empty branch if missing - personal_token: ${{ secrets.WRITE_REPOS_TOKEN }} - publish_branch: gh-pages - publish_dir: ./.dapp_example_build - user_name: agoralabs-bot - user_email: tech@agoralabs.sh + id: deployment + uses: actions/deploy-pages@v4 diff --git a/src/extension/utils/mapAlgorandTransactionToTransaction/mapAlgorandTransactionToTransaction.ts b/src/extension/utils/mapAlgorandTransactionToTransaction/mapAlgorandTransactionToTransaction.ts index 71645e27..d9c136bf 100644 --- a/src/extension/utils/mapAlgorandTransactionToTransaction/mapAlgorandTransactionToTransaction.ts +++ b/src/extension/utils/mapAlgorandTransactionToTransaction/mapAlgorandTransactionToTransaction.ts @@ -1,5 +1,3 @@ -import { decode as decodeBase64 } from '@stablelib/base64'; -import { decode as decodeUtf8 } from '@stablelib/utf8'; import { BigNumber } from 'bignumber.js'; // enums @@ -18,59 +16,58 @@ import parseAssetConfigTransaction from './parseAssetConfigTransaction'; import parseAssetFreezeTransaction from './parseAssetFreezeTransaction'; import parseAssetTransferTransaction from './parseAssetTransferTransaction'; import parseKeyRegistrationTransaction from './parseKeyRegistrationTransaction'; +import parseNote from './parseNote'; import parsePaymentAndReKeyTransaction from './parsePaymentAndReKeyTransaction'; export default function mapAlgorandTransactionToTransaction( - algorandTransaction: IAlgorandTransaction + avmTransaction: IAlgorandTransaction ): ITransactions { const baseTransaction: IBaseTransaction = { - authAddr: algorandTransaction['auth-addr'] || null, - completedAt: algorandTransaction['round-time'] - ? new BigNumber(String(algorandTransaction['round-time'] as bigint)) + authAddr: avmTransaction['auth-addr'] || null, + completedAt: avmTransaction['round-time'] + ? new BigNumber(String(avmTransaction['round-time'] as bigint)) .multipliedBy(1000) // we want milliseconds, as 'round-time' is in seconds .toNumber() : null, - fee: new BigNumber(String(algorandTransaction.fee as bigint)).toFixed(), - id: algorandTransaction.id || null, - genesisHash: algorandTransaction['genesis-hash'] || null, - groupId: algorandTransaction.group || null, - note: algorandTransaction.note - ? decodeUtf8(decodeBase64(algorandTransaction.note)) - : null, - rekeyTo: algorandTransaction['rekey-to'] || null, - sender: algorandTransaction.sender, + fee: new BigNumber(String(avmTransaction.fee as bigint)).toFixed(), + id: avmTransaction.id || null, + genesisHash: avmTransaction['genesis-hash'] || null, + groupId: avmTransaction.group || null, + note: avmTransaction.note ? parseNote(avmTransaction.note) : null, + rekeyTo: avmTransaction['rekey-to'] || null, + sender: avmTransaction.sender, }; - switch (algorandTransaction['tx-type']) { + switch (avmTransaction['tx-type']) { case 'acfg': return parseAssetConfigTransaction( - algorandTransaction['asset-config-transaction'], + avmTransaction['asset-config-transaction'], baseTransaction ); case 'afrz': return parseAssetFreezeTransaction( - algorandTransaction['asset-freeze-transaction'], + avmTransaction['asset-freeze-transaction'], baseTransaction ); case 'appl': return parseApplicationTransaction( - algorandTransaction['application-transaction'], + avmTransaction['application-transaction'], baseTransaction, - algorandTransaction['inner-txns'] + avmTransaction['inner-txns'] ); case 'axfer': return parseAssetTransferTransaction( - algorandTransaction['asset-transfer-transaction'], + avmTransaction['asset-transfer-transaction'], baseTransaction ); case 'keyreg': return parseKeyRegistrationTransaction( - algorandTransaction['keyreg-transaction'], + avmTransaction['keyreg-transaction'], baseTransaction ); case 'pay': return parsePaymentAndReKeyTransaction( - algorandTransaction['payment-transaction'], + avmTransaction['payment-transaction'], baseTransaction ); default: diff --git a/src/extension/utils/mapAlgorandTransactionToTransaction/parseNote.ts b/src/extension/utils/mapAlgorandTransactionToTransaction/parseNote.ts new file mode 100644 index 00000000..62342244 --- /dev/null +++ b/src/extension/utils/mapAlgorandTransactionToTransaction/parseNote.ts @@ -0,0 +1,29 @@ +import { decode as decodeBase64 } from '@stablelib/base64'; +import { decode as decodeUtf8 } from '@stablelib/utf8'; + +// types +import type { IBaseOptions } from '@common/types'; + +/** + * Parses the note field. The note field will be encoded in base64 and this function will attempt to decode to UTF-8. If + * the note field is not in UTF-8 format, it gracefully errors and returns null. + * @param {string} encodedNote - The note field encoded in base64. + * @param {IBaseOptions} options - [optional] Base options that include the logger for logging. + * @returns {string | null} The decoded note field or null if UTF-8 decoding failed. + */ +export default function parseNote( + encodedNote: string, + options?: IBaseOptions +): string | null { + const _functionName = 'parseNote'; + + try { + return decodeUtf8( + decodeBase64(encodedNote) // decode from base64 + ); + } catch (error) { + options?.logger?.debug(`${_functionName}: note not encoded in utf-8`); + + return null; + } +} From cb5af478ff15683a9beebc98b91407be2fa8c7f9 Mon Sep 17 00:00:00 2001 From: kibi-bot Date: Fri, 18 Oct 2024 16:15:46 +0000 Subject: [PATCH 2/2] chore(release): 2.3.2 ## [2.3.2](https://github.com/kibis-is/web-extension/compare/v2.3.1...v2.3.2) (2024-10-18) ### Bug Fixes * ignore non-utf-8 encoded notes ([#341](https://github.com/kibis-is/web-extension/issues/341)) ([a24d369](https://github.com/kibis-is/web-extension/commit/a24d3695c61c485f49254ca78682ee00af4e2aed)) --- .github/ISSUE_TEMPLATE/bug_report_template.yml | 1 + CHANGELOG.md | 7 +++++++ package.json | 2 +- src/manifest.common.json | 10 +++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report_template.yml b/.github/ISSUE_TEMPLATE/bug_report_template.yml index 6683d718..3edecfaf 100644 --- a/.github/ISSUE_TEMPLATE/bug_report_template.yml +++ b/.github/ISSUE_TEMPLATE/bug_report_template.yml @@ -26,6 +26,7 @@ body: label: Version description: What version of the software are you running? options: + - 2.3.2 - 2.3.1 - 2.3.0 - 2.2.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index ade122c9..35e44233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.3.2](https://github.com/kibis-is/web-extension/compare/v2.3.1...v2.3.2) (2024-10-18) + + +### Bug Fixes + +* ignore non-utf-8 encoded notes ([#341](https://github.com/kibis-is/web-extension/issues/341)) ([a24d369](https://github.com/kibis-is/web-extension/commit/a24d3695c61c485f49254ca78682ee00af4e2aed)) + <<<<<<< Updated upstream ## [2.3.1](https://github.com/agoralabs-sh/kibisis-web-extension/compare/v2.3.0...v2.3.1) (2024-10-03) ======= diff --git a/package.json b/package.json index 4d74a6eb..9a0c188f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kibis-is/web-extension", - "version": "2.3.1", + "version": "2.3.2", "description": "An AVM wallet that goes beyond just DeFi.", "main": "build/main.js", "repository": { diff --git a/src/manifest.common.json b/src/manifest.common.json index 85932150..f0051d63 100644 --- a/src/manifest.common.json +++ b/src/manifest.common.json @@ -1,6 +1,6 @@ { "name": "Kibisis", - "version": "2.3.1", + "version": "2.3.2", "description": "The wallet for your lifestyle.", "author": "Kibisis OƜ", "icons": { @@ -9,8 +9,12 @@ }, "content_scripts": [ { - "matches": ["*://*/*"], - "js": ["content-script.js"] + "matches": [ + "*://*/*" + ], + "js": [ + "content-script.js" + ] } ], "omnibox": {