Skip to content

ethereum utility library #2404

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

Merged
merged 23 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 21 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
16 changes: 12 additions & 4 deletions .github/workflows/e2e-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ on:
release-version:
description: "Test Release version (v#.#.#[-rc#])"
required: true
ethereum-utils-version:
description: "Ethereum utils version to use (v#.#.#[-rc#])"
required: true

env:
TAG_FROM_UI: ${{github.event.inputs.release-version}}
ETHEREUM_UTILS_FROM_UI: ${{github.event.inputs.ethereum-utils-version}}

# Set default permissions as restrictive
permissions:
Expand All @@ -29,10 +33,12 @@ jobs:
shell: bash
run: |
version=${{env.TAG_FROM_UI}}
ethereum_utils_version=${{env.ETHEREUM_UTILS_FROM_UI}}
echo "Release version entered in UI: $version"
echo "Ethereum utils version entered in UI: $ethereum_utils_version"
regex='^v([0-9]+)\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))(-rc[1-9][0-9]*)?$'
if [[ ! $version =~ $regex ]]; then
echo "ERROR: Entered version $version is not valid."
if [[ ! $version =~ $regex ]] || [[ ! $ethereum_utils_version =~ $regex ]]; then
echo "ERROR: Entered version $version or ethereum_version $ethereum_utils_version is not valid."
echo "Please use v#.#.#[-rc#] format."
exit 1
fi
Expand All @@ -44,14 +50,15 @@ jobs:
- name: Set Env Vars
run: |
echo "API_AUGMENT_VERSION=$(echo ${{ env.TAG_FROM_UI }} | sed 's/^v//')" >> $GITHUB_ENV
echo "ETHEREUM_UTILS_VERSION=$(echo ${{ env.ETHEREUM_UTILS_FROM_UI }} | sed 's/^v//')" >> $GITHUB_ENV
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 22
cache: "npm"
cache-dependency-path: e2e/package-lock.json
- name: Install Built api-augment
run: npm install @frequency-chain/api-augment@${{ env.API_AUGMENT_VERSION }}
run: npm install @frequency-chain/api-augment@${{ env.API_AUGMENT_VERSION }} @frequency-chain/ethereum-utils@${{ env.ETHEREUM_UTILS_VERSION }}
working-directory: e2e
- name: Fund e2e Tests
working-directory: e2e
Expand Down Expand Up @@ -87,14 +94,15 @@ jobs:
- name: Set Env Vars
run: |
echo "API_AUGMENT_VERSION=$(echo ${{ env.TAG_FROM_UI }} | sed 's/^v//')" >> $GITHUB_ENV
echo "ETHEREUM_UTILS_VERSION=$(echo ${{ env.ETHEREUM_UTILS_FROM_UI }} | sed 's/^v//')" >> $GITHUB_ENV
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 22
cache: "npm"
cache-dependency-path: e2e/package-lock.json
- name: Install Built api-augment
run: npm install @frequency-chain/api-augment@${{ env.API_AUGMENT_VERSION }}
run: npm install @frequency-chain/api-augment@${{ env.API_AUGMENT_VERSION }} @frequency-chain/ethereum-utils@${{ env.ETHEREUM_UTILS_VERSION }}
working-directory: e2e
- name: E2E Test - ${{ matrix.test-file }}
working-directory: e2e
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,35 @@ jobs:
path: js/api-augment/dist
if-no-files-found: error

build-js-ethereum-utils:
name: Build JS Ethereum utils
runs-on: ubuntu-24.04
container: ghcr.io/frequency-chain/frequency/ci-base-image:1.5.5
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{env.RELEASE_BRANCH_NAME}}
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: js/ethereum-utils/package-lock.json
- name: Install
run: npm ci
working-directory: js/ethereum-utils
- name: Build
run: npm run build
working-directory: js/ethereum-utils
- name: Upload Dist Dir
uses: actions/upload-artifact@v4
with:
name: js-ethereum-utils-${{github.run_id}}
path: js/ethereum-utils/dist
if-no-files-found: error

build-js-schemas:
name: Build JS Schemas
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -705,6 +734,7 @@ jobs:
test-version-matches-release,
build-rust-developer-docs,
build-js-api-augment,
build-js-ethereum-utils,
build-js-schemas,
]
name: Wait for All Builds to Finish
Expand Down Expand Up @@ -1205,6 +1235,52 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

release-js-ethereum-utils:
needs: wait-for-all-builds
name: Release JS Ethereum utils
runs-on: ubuntu-24.04
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{env.RELEASE_BRANCH_NAME}}
- name: Full Release?
id: is-full-release
uses: ./.github/workflows/common/is-full-release
with:
version-tag: ${{env.NEW_RELEASE_TAG}}
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: js/ethereum-utils/package-lock.json
- name: Download Dist Dir
id: download
uses: actions/download-artifact@v4
with:
name: js-api-ethereum-utils-${{github.run_id}}
path: js/ethereum-utils/dist
- name: Version Package
if: env.TEST_RUN != 'true'
run: npm version --new-version "${{env.NEW_RELEASE_TAG}}" --no-git-tag-version
working-directory: js/ethereum-utils/dist
- name: Release on NPM @latest
if: env.TEST_RUN != 'true' &&
steps.is-full-release.outputs.is-full-release == 'true'
run: npm publish --tag latest --access public
working-directory: ./js/ethereum-utils/dist
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
- name: Release Candidate on NPM
if: env.TEST_RUN != 'true' &&
steps.is-full-release.outputs.is-full-release != 'true'
run: npm publish --tag next --access public
working-directory: ./js/ethereum-utils/dist
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

release-js-schemas:
needs: wait-for-all-builds
name: Release JS Schemas
Expand Down
51 changes: 48 additions & 3 deletions .github/workflows/verify-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'js/api-augment/**'
- 'js/ethereum-utils/**'
- 'e2e/**/*.{ts,json}'
cargo-lock:
- '**/Cargo.toml'
Expand Down Expand Up @@ -487,6 +488,45 @@ jobs:
path: js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz
if-no-files-found: error

verify-js-ethereum-utils:
needs: build-binaries
name: Verify Ethereum utils
runs-on: ubuntu-24.04
container: ghcr.io/frequency-chain/frequency/ci-base-image:1.5.5
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: js/ethereum-utils/package-lock.json
- name: Install Latest Versions
run: npm install
working-directory: js/ethereum-utils
- name: Lint
run: npm run lint
working-directory: js/ethereum-utils
- name: Test
run: npm test
working-directory: js/ethereum-utils
- name: Build
run: npm run build
working-directory: js/ethereum-utils
- name: Build & Publish Dry Run
run: npm publish --dry-run
working-directory: js/ethereum-utils/dist
- name: Generate npm tarball
run: npm pack
working-directory: js/ethereum-utils/dist
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-ethereum-utils-${{github.run_id}}
path: js/ethereum-utils/dist/frequency-chain-ethereum-utils-0.0.0.tgz
if-no-files-found: error

verify-js-schemas:
name: Verify JS Schemas
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -738,7 +778,7 @@ jobs:

run-e2e:
if: needs.changes.outputs.run-e2e == 'true'
needs: [build-binaries, verify-js-api-augment]
needs: [build-binaries, verify-js-api-augment, verify-js-ethereum-utils]
name: Run E2E Tests
runs-on: ubuntu-24.04
steps:
Expand Down Expand Up @@ -767,6 +807,11 @@ jobs:
with:
name: artifacts-api-augment-${{github.run_id}}
path: js/api-augment/dist
- name: Download ethereum-utils tarball
uses: actions/download-artifact@v4
with:
name: artifacts-ethereum-utils-${{github.run_id}}
path: js/ethereum-utils/dist
- name: Set Binaries Permissions
working-directory: ${{env.BIN_DIR_DEBUG}}
run: |
Expand Down Expand Up @@ -794,8 +839,8 @@ jobs:
node-version: 20
cache: "npm"
cache-dependency-path: e2e/package-lock.json
- name: Install Built api-augment
run: npm install ../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz
- name: Install Built api-augment and ethereum-utils
run: npm install ../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz ../js/ethereum-utils/dist/frequency-chain-ethereum-utils-0.0.0.tgz
working-directory: e2e
- name: Install NPM Modules
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion e2e/capacity/capacityFail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
assertAddNewKey,
} from '../scaffolding/helpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion e2e/capacity/capacity_rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../scaffolding/helpers';
import { FeeDetails } from '@polkadot/types/interfaces';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion e2e/capacity/list_unclaimed_rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../scaffolding/helpers';
import { isTestnet } from '../scaffolding/env';
import { KeyringPair } from '@polkadot/keyring/types';
import { getUnifiedAddress } from '../scaffolding/ethereum';
import { getUnifiedAddress } from '@frequency-chain/ethereum-utils';

const fundingSource = getFundingSource(import.meta.url);

Expand Down
2 changes: 1 addition & 1 deletion e2e/capacity/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '../scaffolding/helpers';
import { ipfsCid } from '../messages/ipfs';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion e2e/capacity/transactionsBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getTestHandle,
} from '../scaffolding/helpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion e2e/load-tests/signatureRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { KeyringPair } from '@polkadot/keyring/types';
import { AddKeyData, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { u64, Option } from '@polkadot/types';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress, getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedAddress, getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

interface GeneratedMsa {
id: u64;
Expand Down
2 changes: 1 addition & 1 deletion e2e/miscellaneous/balance.ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DOLLARS, createAndFundKeypair, createKeys } from '../scaffolding/helper
import { KeyringPair } from '@polkadot/keyring/types';
import { Extrinsic, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress } from '../scaffolding/ethereum';
import { getUnifiedAddress } from '@frequency-chain/ethereum-utils';

const fundingSource: KeyringPair = getFundingSource(import.meta.url);

Expand Down
2 changes: 1 addition & 1 deletion e2e/miscellaneous/frequency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Extrinsic, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { getFundingSource } from '../scaffolding/funding';
import { u8, Option } from '@polkadot/types';
import { u8aToHex } from '@polkadot/util/u8a/toHex';
import { getUnifiedAddress, getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedAddress, getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const fundingSource: KeyringPair = getFundingSource(import.meta.url);

Expand Down
2 changes: 1 addition & 1 deletion e2e/miscellaneous/utilityBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { DOLLARS, createAndFundKeypair } from '../scaffolding/helpers';
import { ApiTypes, SubmittableExtrinsic } from '@polkadot/api/types';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress } from '../scaffolding/ethereum';
import { getUnifiedAddress } from '@frequency-chain/ethereum-utils';

const fundingSource = getFundingSource(import.meta.url);

Expand Down
21 changes: 13 additions & 8 deletions e2e/msa/keyManagement.ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
MultiSignatureType,
DOLLARS,
createAndFundKeypairs,
signEip712AddKeyData,
getEthereumKeyPairFromUnifiedAddress,
} from '../scaffolding/helpers';
import { KeyringPair } from '@polkadot/keyring/types';
import { AddKeyData, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { u64 } from '@polkadot/types';
import { Codec } from '@polkadot/types/types';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress, getUnifiedPublicKey } from '../scaffolding/ethereum';
import { createAddKeyData, getUnifiedAddress, getUnifiedPublicKey, signEip712 } from '@frequency-chain/ethereum-utils';
import { u8aToHex } from '@polkadot/util';

const maxU64 = 18_446_744_073_709_551_615n;
const fundingSource = getFundingSource(import.meta.url);
Expand Down Expand Up @@ -131,13 +131,18 @@ describe('MSA Key management Ethereum', function () {
newPublicKey: getUnifiedPublicKey(thirdKey),
});

ownerSig = await signEip712AddKeyData(
getEthereumKeyPairFromUnifiedAddress(getUnifiedAddress(secondaryKey)),
newPayload
const signingPayload = createAddKeyData(
payload.msaId!.toString(),
u8aToHex(newPayload.newPublicKey),
newPayload.expiration
);
newSig = await signEip712AddKeyData(
getEthereumKeyPairFromUnifiedAddress(getUnifiedAddress(thirdKey)),
newPayload
ownerSig = await signEip712(
u8aToHex(getEthereumKeyPairFromUnifiedAddress(getUnifiedAddress(secondaryKey)).secretKey),
signingPayload
);
newSig = await signEip712(
u8aToHex(getEthereumKeyPairFromUnifiedAddress(getUnifiedAddress(thirdKey)).secretKey),
signingPayload
);
const op = ExtrinsicHelper.addPublicKeyToMsa(secondaryKey, ownerSig, newSig, newPayload);
const { target: event } = await op.fundAndSend(fundingSource);
Expand Down
2 changes: 1 addition & 1 deletion e2e/msa/msaKeyManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AddKeyData, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { u64 } from '@polkadot/types';
import { Codec } from '@polkadot/types/types';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';
import { getUnifiedPublicKey } from '@frequency-chain/ethereum-utils';

const maxU64 = 18_446_744_073_709_551_615n;
const fundingSource = getFundingSource(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion e2e/msa/msaTokens.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@frequency-chain/api-augment';
import assert from 'assert';
import { ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { ethereumAddressToKeyringPair } from '../scaffolding/ethereum';
import { ethereumAddressToKeyringPair } from '@frequency-chain/ethereum-utils';
import { getFundingSource } from '../scaffolding/funding';
import { H160 } from '@polkadot/types/interfaces';
import { bnToU8a, hexToU8a, stringToU8a } from '@polkadot/util';
Expand Down
Loading