From 7750b6b3d06245f41ffdaddf8caf75fd6e922526 Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 17 Jul 2025 10:58:43 +0200 Subject: [PATCH 1/3] build(chains): adds @kibisis/encoding package --- packages/chains/.lintstagedrc.mjs | 9 ++++- packages/chains/package.json | 5 +-- packages/chains/scripts/generate-index.ts | 40 +++++++++++++++++++++++ packages/chains/scripts/prebuild.sh | 18 ++++++++++ packages/chains/src/index.ts | 2 ++ pnpm-lock.yaml | 14 ++------ pnpm-workspace.yaml | 1 - 7 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 packages/chains/scripts/generate-index.ts create mode 100755 packages/chains/scripts/prebuild.sh diff --git a/packages/chains/.lintstagedrc.mjs b/packages/chains/.lintstagedrc.mjs index 68a5afb..3033edc 100644 --- a/packages/chains/.lintstagedrc.mjs +++ b/packages/chains/.lintstagedrc.mjs @@ -1,5 +1,12 @@ +import { resolve } from 'node:path'; + export default (() => { + const packageName = 'chains'; + return { - '**/*.{cjs,js,json,mjs,ts}': (filenames) => [`prettier --write ${filenames.join(' ')}`], + '**/*.{cjs,js,json,mjs,ts}': (filenames) => [ + `sh -c 'pnpm -F @kibisis/${packageName} run generate:index && git add ${resolve(process.cwd(), 'packages', packageName, 'src', 'index.ts')}'`, + `prettier --write ${filenames.join(' ')}`, + ], }; })(); diff --git a/packages/chains/package.json b/packages/chains/package.json index 9af431a..cfe570f 100644 --- a/packages/chains/package.json +++ b/packages/chains/package.json @@ -16,7 +16,8 @@ ], "scripts": { "build": "vite build", - "build:dependencies": "exit 0", + "build:dependencies": "./scripts/prebuild.sh", + "generate:index": "tsx ./scripts/generate-index.ts", "lint": "eslint .", "prettier": "prettier --write \"**/*.{cjs,js,json,mjs,ts}\"", "test": "vitest run --config vitest.config.ts" @@ -39,6 +40,6 @@ "vitest": "catalog:" }, "dependencies": { - "@stablelib/base64": "catalog:" + "@kibisis/encoding": "workspace:^" } } diff --git a/packages/chains/scripts/generate-index.ts b/packages/chains/scripts/generate-index.ts new file mode 100644 index 0000000..a916522 --- /dev/null +++ b/packages/chains/scripts/generate-index.ts @@ -0,0 +1,40 @@ +import chalk from 'chalk'; +import { readdirSync, type Stats, statSync, writeFileSync } from 'node:fs'; +import { join, parse, type ParsedPath } from 'node:path'; +import * as process from 'node:process'; + +/** + * Script that creates the index.ts file in the `src/` directory. + */ +function main(): void { + const exports = ['// exports will be generated automatically using: pnpm run generate:index']; + const srcDir = 'src'; + let dir: ParsedPath; + let indexFilePath: string; + let stat: Stats; + + // get utils + for (const item of readdirSync(srcDir)) { + stat = statSync(join(srcDir, item)); + + // if it is not a directory, move on + if (!stat.isDirectory()) { + continue; + } + + dir = parse(item); + + exports.push(`export * from './${dir.name}';`); + } + + indexFilePath = join(srcDir, 'index.ts'); + + // write to index file + writeFileSync(indexFilePath, `${exports.join('\n')}\n`, 'utf-8'); + + console.log(`${chalk.yellow('[INFO]')}: generated indexes to "./src/index.ts"`); + + process.exit(0); +} + +main(); diff --git a/packages/chains/scripts/prebuild.sh b/packages/chains/scripts/prebuild.sh new file mode 100755 index 0000000..3a9a9c4 --- /dev/null +++ b/packages/chains/scripts/prebuild.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Public: Performs pre-build actions such as building dependencies. +# +# Examples +# +# ./bin/prebuild.sh +# +# Returns exit code 0. +function main { + # build workspace dependencies + pnpm -F @kibisis/encoding run build + + exit 0 +} + +# and so, it begins... +main "$@" diff --git a/packages/chains/src/index.ts b/packages/chains/src/index.ts index 5186365..7e4ab7d 100644 --- a/packages/chains/src/index.ts +++ b/packages/chains/src/index.ts @@ -1,5 +1,7 @@ +// exports will be generated automatically using: pnpm run generate:index export * from './chains'; export * from './constants'; +export * from './decorators'; export * from './enums'; export * from './types'; export * from './utilities'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 17ace60..6338e57 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,9 +9,6 @@ catalogs: '@eslint/js': specifier: ^9.18.0 version: 9.26.0 - '@stablelib/base64': - specifier: ^2.0.1 - version: 2.0.1 '@types/node': specifier: ^20.9.0 version: 20.17.44 @@ -104,9 +101,9 @@ importers: packages/chains: dependencies: - '@stablelib/base64': - specifier: 'catalog:' - version: 2.0.1 + '@kibisis/encoding': + specifier: workspace:^ + version: link:../encoding devDependencies: '@eslint/js': specifier: 'catalog:' @@ -1520,9 +1517,6 @@ packages: resolution: {integrity: sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==} engines: {node: '>=18'} - '@stablelib/base64@2.0.1': - resolution: {integrity: sha512-P2z89A7N1ETt6RxgpVdDT2xlg8cnm3n6td0lY9gyK7EiWK3wdq388yFX/hLknkCC0we05OZAD1rfxlQJUbl5VQ==} - '@stablelib/binary@2.0.1': resolution: {integrity: sha512-U9iAO8lXgEDONsA0zPPSgcf3HUBNAqHiJmSHgZz62OvC3Hi2Bhc5kTnQ3S1/L+sthDTHtCMhcEiklmIly6uQ3w==} @@ -5953,8 +5947,6 @@ snapshots: '@sindresorhus/merge-streams@4.0.0': {} - '@stablelib/base64@2.0.1': {} - '@stablelib/binary@2.0.1': dependencies: '@stablelib/int': 2.0.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 9303f7e..560d183 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -4,7 +4,6 @@ packages: catalog: "@eslint/js": ^9.18.0 "@types/node": ^20.9.0 - "@stablelib/base64": ^2.0.1 chalk: ^5.3.0 concurrently: ^9.1.0 eslint: ^9.16.0 From 139918f0c55d53952f67db5daababb3e3225f841 Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 17 Jul 2025 11:01:01 +0200 Subject: [PATCH 2/3] ci: moves chains further along dependency graph on release workflow --- .github/workflows/release.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b0b9eb..e03a158 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,18 +17,8 @@ permissions: pull-requests: write # to be able to comment on released pull requests jobs: - chains: - name: "Release - @kibisis/chains" - uses: ./.github/workflows/publish_release.yml - with: - package_dir: "chains" - package_name: "@kibisis/chains" - secrets: - NPM_TOKEN: ${{ secrets.NPM_PUBLISH_PACKAGES_ACCESS_TOKEN }} - encoding: name: "Release - @kibisis/encoding" - needs: [chains] uses: ./.github/workflows/publish_release.yml with: package_dir: "encoding" @@ -38,7 +28,7 @@ jobs: icons: name: "Release - @kibisis/icons" - needs: [chains, encoding] + needs: [encoding] uses: ./.github/workflows/publish_release.yml with: package_dir: "icons" @@ -48,7 +38,7 @@ jobs: utilities: name: "Release - @kibisis/utilities" - needs: [chains, encoding, icons] + needs: [encoding, icons] uses: ./.github/workflows/publish_release.yml with: package_dir: "utilities" @@ -56,10 +46,21 @@ jobs: secrets: NPM_TOKEN: ${{ secrets.NPM_PUBLISH_PACKAGES_ACCESS_TOKEN }} + # **MUST** come after [@kibisis/encoding] as it uses them as dependencies + chains: + name: "Release - @kibisis/chains" + needs: [encoding, icons, utilities] + uses: ./.github/workflows/publish_release.yml + with: + package_dir: "chains" + package_name: "@kibisis/chains" + secrets: + NPM_TOKEN: ${{ secrets.NPM_PUBLISH_PACKAGES_ACCESS_TOKEN }} + # **MUST** come after [@kibisis/icons, @kibisis/utilities] as it uses them as dependencies react: name: "Release - @kibisis/react" - needs: [chains, encoding, icons, utilities] + needs: [encoding, icons, utilities, chains] uses: ./.github/workflows/publish_release.yml with: package_dir: "react" From 24bff58fd4f2f799c79cb0ca09d9bb5e36c46173 Mon Sep 17 00:00:00 2001 From: Kieran O'Neill Date: Thu, 17 Jul 2025 12:19:41 +0200 Subject: [PATCH 3/3] feat(chains): revamps the chain configuration to be driven by node/networks BREAKING CHANGE: chains are exported as classes --- packages/chains/package.json | 3 +- packages/chains/src/chains/Algorand.ts | 47 ++++++++++ packages/chains/src/chains/AlgorandBetanet.ts | 47 ++++++++++ packages/chains/src/chains/AlgorandFNet.ts | 47 ++++++++++ packages/chains/src/chains/AlgorandTestnet.ts | 47 ++++++++++ packages/chains/src/chains/Voi.ts | 47 ++++++++++ packages/chains/src/chains/VoiTestnet.ts | 47 ++++++++++ packages/chains/src/chains/algorand.ts | 46 --------- packages/chains/src/chains/algorandBetanet.ts | 46 --------- packages/chains/src/chains/algorandTestnet.ts | 46 --------- packages/chains/src/chains/fnet.ts | 46 --------- packages/chains/src/chains/index.ts | 12 +-- packages/chains/src/chains/voi.ts | 46 --------- packages/chains/src/chains/voiTestnet.ts | 46 --------- packages/chains/src/constants/Currencies.ts | 1 - packages/chains/src/constants/index.ts | 1 - packages/chains/src/decorators/AVMChain.ts | 81 ++++++++++++++++ packages/chains/src/decorators/Chain.ts | 93 +++++++++++++++++++ packages/chains/src/decorators/index.ts | 2 + packages/chains/src/index.ts | 1 - .../src/types/avm/AVMGenesisResponse.ts | 5 + .../src/types/avm/AVMNetworkConfiguration.ts | 13 +++ .../src/types/avm/AVMNetworkInformation.ts | 13 ++- .../types/avm/AVMTransactionParamsResponse.ts | 10 ++ packages/chains/src/types/avm/index.ts | 3 + packages/chains/src/types/chains/Chain.ts | 31 ------- .../src/types/chains/ChainParameters.ts | 12 +++ .../src/types/chains/NetworkConfiguration.ts | 13 +++ .../src/types/chains/NetworkInformation.ts | 13 +++ packages/chains/src/types/chains/index.ts | 4 +- .../avmGenesisHashToCAIP002Reference.test.ts | 40 -------- .../avm/avmGenesisHashToCAIP002Reference.ts | 15 --- packages/chains/src/utilities/avm/index.ts | 1 - packages/chains/src/utilities/caip/chainID.ts | 12 --- packages/chains/src/utilities/caip/index.ts | 1 - packages/chains/src/utilities/index.ts | 2 - pnpm-lock.yaml | 86 +++++++++++++++++ 37 files changed, 630 insertions(+), 396 deletions(-) create mode 100644 packages/chains/src/chains/Algorand.ts create mode 100644 packages/chains/src/chains/AlgorandBetanet.ts create mode 100644 packages/chains/src/chains/AlgorandFNet.ts create mode 100644 packages/chains/src/chains/AlgorandTestnet.ts create mode 100644 packages/chains/src/chains/Voi.ts create mode 100644 packages/chains/src/chains/VoiTestnet.ts delete mode 100644 packages/chains/src/chains/algorand.ts delete mode 100644 packages/chains/src/chains/algorandBetanet.ts delete mode 100644 packages/chains/src/chains/algorandTestnet.ts delete mode 100644 packages/chains/src/chains/fnet.ts delete mode 100644 packages/chains/src/chains/voi.ts delete mode 100644 packages/chains/src/chains/voiTestnet.ts delete mode 100644 packages/chains/src/constants/Currencies.ts create mode 100644 packages/chains/src/decorators/AVMChain.ts create mode 100644 packages/chains/src/decorators/Chain.ts create mode 100644 packages/chains/src/decorators/index.ts create mode 100644 packages/chains/src/types/avm/AVMGenesisResponse.ts create mode 100644 packages/chains/src/types/avm/AVMNetworkConfiguration.ts create mode 100644 packages/chains/src/types/avm/AVMTransactionParamsResponse.ts delete mode 100644 packages/chains/src/types/chains/Chain.ts create mode 100644 packages/chains/src/types/chains/ChainParameters.ts create mode 100644 packages/chains/src/types/chains/NetworkConfiguration.ts create mode 100644 packages/chains/src/types/chains/NetworkInformation.ts delete mode 100644 packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.test.ts delete mode 100644 packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.ts delete mode 100644 packages/chains/src/utilities/avm/index.ts delete mode 100644 packages/chains/src/utilities/caip/chainID.ts delete mode 100644 packages/chains/src/utilities/caip/index.ts delete mode 100644 packages/chains/src/utilities/index.ts diff --git a/packages/chains/package.json b/packages/chains/package.json index cfe570f..328a278 100644 --- a/packages/chains/package.json +++ b/packages/chains/package.json @@ -40,6 +40,7 @@ "vitest": "catalog:" }, "dependencies": { - "@kibisis/encoding": "workspace:^" + "@kibisis/encoding": "workspace:^", + "axios": "^1.10.0" } } diff --git a/packages/chains/src/chains/Algorand.ts b/packages/chains/src/chains/Algorand.ts new file mode 100644 index 0000000..182549e --- /dev/null +++ b/packages/chains/src/chains/Algorand.ts @@ -0,0 +1,47 @@ +// constants +import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class Algorand extends AVMChain { + // public static variables + public static readonly displayName = 'Algorand'; + public static readonly iconURI = ALGORAND_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.Algorand; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: ALGORAND_CURRENCY_ICON_URI, + name: 'Algo', + symbol: 'ALGO', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://mainnet-api.4160.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://mainnet-idx.4160.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = false; +} diff --git a/packages/chains/src/chains/AlgorandBetanet.ts b/packages/chains/src/chains/AlgorandBetanet.ts new file mode 100644 index 0000000..7260a1d --- /dev/null +++ b/packages/chains/src/chains/AlgorandBetanet.ts @@ -0,0 +1,47 @@ +// constants +import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class AlgorandBetanet extends AVMChain { + // public static variables + public static readonly displayName = 'Algorand Betanet'; + public static readonly iconURI = ALGORAND_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.Algorand; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: ALGORAND_CURRENCY_ICON_URI, + name: 'Algo', + symbol: 'ALGO', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://betanet-api.4160.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://betanet-idx.4160.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = true; +} diff --git a/packages/chains/src/chains/AlgorandFNet.ts b/packages/chains/src/chains/AlgorandFNet.ts new file mode 100644 index 0000000..41ce96c --- /dev/null +++ b/packages/chains/src/chains/AlgorandFNet.ts @@ -0,0 +1,47 @@ +// constants +import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class AlgorandFNet extends AVMChain { + // public static variables + public static readonly displayName = 'Algorand FNet'; + public static readonly iconURI = ALGORAND_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.Algorand; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: ALGORAND_CURRENCY_ICON_URI, + name: 'Algo', + symbol: 'ALGO', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://fnet-api.4160.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://fnet-idx.4160.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = true; +} diff --git a/packages/chains/src/chains/AlgorandTestnet.ts b/packages/chains/src/chains/AlgorandTestnet.ts new file mode 100644 index 0000000..a33abbe --- /dev/null +++ b/packages/chains/src/chains/AlgorandTestnet.ts @@ -0,0 +1,47 @@ +// constants +import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class AlgorandTestnet extends AVMChain { + // public static variables + public static readonly displayName = 'Algorand Testnet'; + public static readonly iconURI = ALGORAND_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.Algorand; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: ALGORAND_CURRENCY_ICON_URI, + name: 'Algo', + symbol: 'ALGO', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://testnet-api.4160.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://testnet-idx.4160.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = true; +} diff --git a/packages/chains/src/chains/Voi.ts b/packages/chains/src/chains/Voi.ts new file mode 100644 index 0000000..66c1cf3 --- /dev/null +++ b/packages/chains/src/chains/Voi.ts @@ -0,0 +1,47 @@ +// constants +import { VOI_CHAIN_LOGO_URI, VOI_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class Voi extends AVMChain { + // public static variables + public static readonly displayName = 'Voi Network'; + public static readonly iconURI = VOI_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.AVM; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: VOI_CURRENCY_ICON_URI, + name: 'Voi', + symbol: 'VOI', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://mainnet-api.voi.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://mainnet-idx.voi.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = false; +} diff --git a/packages/chains/src/chains/VoiTestnet.ts b/packages/chains/src/chains/VoiTestnet.ts new file mode 100644 index 0000000..de7d10a --- /dev/null +++ b/packages/chains/src/chains/VoiTestnet.ts @@ -0,0 +1,47 @@ +// constants +import { VOI_CHAIN_LOGO_URI, VOI_CURRENCY_ICON_URI } from '@/constants'; + +// decorators +import { AVMChain } from '@/decorators'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { NetworkConfiguration } from '@/types'; + +export default class VoiTestnet extends AVMChain { + // public static variables + public static readonly displayName = 'Voi Network Testnet'; + public static readonly iconURI = VOI_CHAIN_LOGO_URI; + public static readonly namespace = CAIP002Namespace.AVM; + public static readonly nativeCurrency = { + decimals: 6, + iconURI: VOI_CURRENCY_ICON_URI, + name: 'Voi', + symbol: 'VOI', + }; + public static readonly networkConfiguration: NetworkConfiguration = { + algods: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://testnet-api.voi.nodely.dev', + }, + ], + }, + indexers: { + default: 0, + nodes: [ + { + canonicalName: 'Nodely', + id: 'nodely', + origin: 'https://testnet-idx.voi.nodely.dev', + }, + ], + }, + }; + public static readonly testnet = true; +} diff --git a/packages/chains/src/chains/algorand.ts b/packages/chains/src/chains/algorand.ts deleted file mode 100644 index acaadf5..0000000 --- a/packages/chains/src/chains/algorand.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI, DEFAULT_AVM_DECIMALS } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Algorand', - iconURI: ALGORAND_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.Algorand, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: ALGORAND_CURRENCY_ICON_URI, - name: 'Algo', - symbol: 'ALGO', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://mainnet-api.4160.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://mainnet-idx.4160.nodely.dev', - }, - ], - }, - }, - reference: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73k', - testnet: false, -}; - -export default chain; diff --git a/packages/chains/src/chains/algorandBetanet.ts b/packages/chains/src/chains/algorandBetanet.ts deleted file mode 100644 index 8f72501..0000000 --- a/packages/chains/src/chains/algorandBetanet.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI, DEFAULT_AVM_DECIMALS } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Algorand Betanet', - iconURI: ALGORAND_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.Algorand, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: ALGORAND_CURRENCY_ICON_URI, - name: 'Algo', - symbol: 'ALGO', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://betanet-api.4160.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://betanet-idx.4160.nodely.dev', - }, - ], - }, - }, - reference: 'mFgazF-2uRS1tMiL9dsj01hJGySEmPN2', - testnet: true, -}; - -export default chain; diff --git a/packages/chains/src/chains/algorandTestnet.ts b/packages/chains/src/chains/algorandTestnet.ts deleted file mode 100644 index 22d67cc..0000000 --- a/packages/chains/src/chains/algorandTestnet.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI, DEFAULT_AVM_DECIMALS } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Algorand Testnet', - iconURI: ALGORAND_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.Algorand, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: ALGORAND_CURRENCY_ICON_URI, - name: 'Algo', - symbol: 'ALGO', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://testnet-api.4160.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://testnet-idx.4160.nodely.dev', - }, - ], - }, - }, - reference: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe', - testnet: true, -}; - -export default chain; diff --git a/packages/chains/src/chains/fnet.ts b/packages/chains/src/chains/fnet.ts deleted file mode 100644 index bd24450..0000000 --- a/packages/chains/src/chains/fnet.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { ALGORAND_CHAIN_LOGO_URI, ALGORAND_CURRENCY_ICON_URI, DEFAULT_AVM_DECIMALS } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Algorand FNet', - iconURI: ALGORAND_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.Algorand, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: ALGORAND_CURRENCY_ICON_URI, - name: 'Algo', - symbol: 'ALGO', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://fnet-api.4160.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://fnet-idx.4160.nodely.dev', - }, - ], - }, - }, - reference: 'kUt08LxeVAAGHnh4JoAoAMM9ql_hBwSo', - testnet: true, -}; - -export default chain; diff --git a/packages/chains/src/chains/index.ts b/packages/chains/src/chains/index.ts index cd3a6c6..9809788 100644 --- a/packages/chains/src/chains/index.ts +++ b/packages/chains/src/chains/index.ts @@ -1,6 +1,6 @@ -export { default as algorand } from './algorand'; -export { default as algorandBetanet } from './algorandBetanet'; -export { default as algorandTestnet } from './algorandTestnet'; -export { default as fnet } from './fnet'; -export { default as voi } from './voi'; -export { default as voiTestnet } from './voiTestnet'; +export { default as Algorand } from './Algorand'; +export { default as AlgorandBetanet } from './AlgorandBetanet'; +export { default as AlgorandFNet } from './AlgorandFNet'; +export { default as AlgorandTestnet } from './AlgorandTestnet'; +export { default as Voi } from './Voi'; +export { default as VoiTestnet } from './VoiTestnet'; diff --git a/packages/chains/src/chains/voi.ts b/packages/chains/src/chains/voi.ts deleted file mode 100644 index 614b43a..0000000 --- a/packages/chains/src/chains/voi.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { DEFAULT_AVM_DECIMALS, VOI_CHAIN_LOGO_URI, VOI_CURRENCY_ICON_URI } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Voi Network', - iconURI: VOI_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.AVM, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: VOI_CURRENCY_ICON_URI, - name: 'Voi', - symbol: 'VOI', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://mainnet-api.voi.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://mainnet-idx.voi.nodely.dev', - }, - ], - }, - }, - reference: 'r20fSQI8gWe_kFZziNonSPCXLwcQmH_n', - testnet: false, -}; - -export default chain; diff --git a/packages/chains/src/chains/voiTestnet.ts b/packages/chains/src/chains/voiTestnet.ts deleted file mode 100644 index 6fb69ef..0000000 --- a/packages/chains/src/chains/voiTestnet.ts +++ /dev/null @@ -1,46 +0,0 @@ -// constants -import { DEFAULT_AVM_DECIMALS, VOI_CHAIN_LOGO_URI, VOI_CURRENCY_ICON_URI } from '@/constants'; - -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { Chain } from '@/types'; - -const chain: Chain = { - displayName: 'Voi Network Testnet', - iconURI: VOI_CHAIN_LOGO_URI, - namespace: CAIP002Namespace.AVM, - nativeCurrency: { - decimals: DEFAULT_AVM_DECIMALS, - iconURI: VOI_CURRENCY_ICON_URI, - name: 'Voi', - symbol: 'VOI', - }, - network: { - algods: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://testnet-api.voi.nodely.dev', - }, - ], - }, - indexers: { - default: 0, - nodes: [ - { - canonicalName: 'Nodely', - id: 'nodely', - origin: 'https://testnet-idx.voi.nodely.dev', - }, - ], - }, - }, - reference: 'mufvzhECYAe3WaU075v0z4k1_SNUIuUP', - testnet: true, -}; - -export default chain; diff --git a/packages/chains/src/constants/Currencies.ts b/packages/chains/src/constants/Currencies.ts deleted file mode 100644 index 506cbe7..0000000 --- a/packages/chains/src/constants/Currencies.ts +++ /dev/null @@ -1 +0,0 @@ -export const DEFAULT_AVM_DECIMALS = 6; diff --git a/packages/chains/src/constants/index.ts b/packages/chains/src/constants/index.ts index e635b6c..33f80f1 100644 --- a/packages/chains/src/constants/index.ts +++ b/packages/chains/src/constants/index.ts @@ -1,2 +1 @@ -export * from './Currencies'; export * from './URIs'; diff --git a/packages/chains/src/decorators/AVMChain.ts b/packages/chains/src/decorators/AVMChain.ts new file mode 100644 index 0000000..2acf17b --- /dev/null +++ b/packages/chains/src/decorators/AVMChain.ts @@ -0,0 +1,81 @@ +import { base64 } from '@kibisis/encoding'; +import axios, { type AxiosRequestConfig } from 'axios'; + +// enums +import { CAIP002Namespace } from '@/enums'; + +// decorators +import Chain from './Chain'; + +// types +import type { + ChainParameters, + AVMGenesisResponse, + AVMNode, + AVMNodeCollection, + AVMTransactionParamsResponse, +} from '@/types'; + +export default class AVMChain extends Chain { + protected constructor(params: ChainParameters) { + super(params); + } + + /** + * protected static methods + */ + + /** + * Returns the default node from the provided node collection. + * @param {AVMNodeCollection} nodeCollection - The collection of nodes containing a default node identifier. + * @returns {AVMNode} The default node from the node collection. + */ + protected static _defaultNode(nodeCollection: AVMNodeCollection): AVMNode { + return nodeCollection.nodes[nodeCollection.default]; + } + + /** + * public static methods + */ + + public static async initialize(this: T): Promise { + const algod = this._defaultNode(this.networkConfiguration.algods); + const baseURL = `${algod.origin}${algod.port ? `:${algod.port}` : ''}`; + const config: AxiosRequestConfig | undefined = algod.token + ? { + headers: { + ['X-Algo-API-Token']: algod.token, + }, + } + : undefined; + const [{ data: transactionParams }, { data: genesis }] = await Promise.all([ + axios.get(`${baseURL}/v2/transactions/params`, config), + axios.get(`${baseURL}/genesis`, config), + ]); + const genesisHash = transactionParams['genesis-hash']; + + return new this({ + reference: this.referenceFromGenesisHash(genesisHash), + networkInformation: { + feeSinkAddress: genesis.fees, + genesisHash, + genesisID: transactionParams['genesis-id'], + }, + }); + } + + /** + * Creates the CAIP-002 chain reference from an AVM genesis hash. + * + * The reference, for AVM chains, is the first 32 bytes, converted to URL-safe base64. + * @param {string} genesisHash - An AVM genesis hash. + * @returns {string} The AVM genesis hash converted to the CAIP-002 chain reference. + * @see {@link https://namespaces.chainagnostic.org/algorand/caip2} + */ + public static referenceFromGenesisHash(genesisHash: string): string { + return base64.encode(base64.decode(genesisHash).slice(0, 32), { + noPadding: true, + urlSafe: true, + }); + } +} diff --git a/packages/chains/src/decorators/Chain.ts b/packages/chains/src/decorators/Chain.ts new file mode 100644 index 0000000..46c1afb --- /dev/null +++ b/packages/chains/src/decorators/Chain.ts @@ -0,0 +1,93 @@ +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { ChainParameters, NativeCurrency, NetworkConfiguration, NetworkInformation } from '@/types'; + +/** + * Provides a base abstraction for a blockchain chain, containing properties and methods + * to define and interact with chain-specific information. It is designed as an abstract + * class and should be extended to represent specific blockchains. + * + * The class supports CAIP-002 (Chain Agnostic Improvement Proposals) for chain identification. + * + * @abstract + */ +export default abstract class Chain { + /** + * public static variables + */ + + /** + * A human-readable name for the chain (e.g., "Algorand", "Ethereum"). + * @static + * @readonly + */ + public static readonly displayName: string; + /** + * A data URI of the chain that conforms to RFC-2397 or a URL that points to an image. + * The **RECOMMENDED** image format should be lossless or vector-based such as a PNG, WebP or SVG. + * @static + * @readonly + */ + public static readonly iconURI: string; + /** + * The CAIP-002 namespace of the chain. It acts as a resolution to the chain's reference. + * @static + * @readonly + */ + public static readonly namespace: CAIP002Namespace; + /** + * Details relating to the native currency of the chain. + * @static + * @readonly + */ + public static readonly nativeCurrency: NativeCurrency; + /** + * Network configuration containing node information and settings for the chain. + * @static + * @readonly + */ + public static readonly networkConfiguration: NetworkConfiguration; + /** + * Whether this chain is considered a testnet. + * @static + * @readonly + */ + public static readonly testnet: boolean; + + /** + * public variables + */ + + /** + * Network-specific information retrieved from the blockchain, such as genesis hash and network ID. + * @readonly + */ + public readonly networkInformation: NetworkInformation; + /** + * A unique identifier for the chain within the CAIP-002 namespace. + * @readonly + */ + public readonly reference: string; + + protected constructor({ networkInformation, reference }: ChainParameters) { + this.networkInformation = networkInformation; + this.reference = reference; + } + + /** + * public methods + */ + + /** + * Generates the CAIP-002 chain identifier by combining the namespace and reference with a colon. + * + * @return {string} The CAIP-002 chain identifier as "namespace:reference". + * @see {@link https://chainagnostic.org/CAIPs/caip-2} + * @public + */ + public chainID(): string { + return (this.constructor as typeof Chain).namespace + ':' + this.reference; + } +} diff --git a/packages/chains/src/decorators/index.ts b/packages/chains/src/decorators/index.ts new file mode 100644 index 0000000..2139e54 --- /dev/null +++ b/packages/chains/src/decorators/index.ts @@ -0,0 +1,2 @@ +export { default as AVMChain } from './AVMChain'; +export { default as Chain } from './Chain'; diff --git a/packages/chains/src/index.ts b/packages/chains/src/index.ts index 7e4ab7d..03120e7 100644 --- a/packages/chains/src/index.ts +++ b/packages/chains/src/index.ts @@ -4,4 +4,3 @@ export * from './constants'; export * from './decorators'; export * from './enums'; export * from './types'; -export * from './utilities'; diff --git a/packages/chains/src/types/avm/AVMGenesisResponse.ts b/packages/chains/src/types/avm/AVMGenesisResponse.ts new file mode 100644 index 0000000..99d9710 --- /dev/null +++ b/packages/chains/src/types/avm/AVMGenesisResponse.ts @@ -0,0 +1,5 @@ +interface AVMGenesisResponse { + fees: string; +} + +export default AVMGenesisResponse; diff --git a/packages/chains/src/types/avm/AVMNetworkConfiguration.ts b/packages/chains/src/types/avm/AVMNetworkConfiguration.ts new file mode 100644 index 0000000..fe45a9b --- /dev/null +++ b/packages/chains/src/types/avm/AVMNetworkConfiguration.ts @@ -0,0 +1,13 @@ +// types +import type AVMNodeCollection from './AVMNodeCollection'; + +/** + * @property {AVMNodeCollection} algods - A collection of Algod nodes. + * @property {AVMNodeCollection} indexers - [optional] A collection of Indexer nodes. + */ +interface AVMNetworkConfiguration { + algods: AVMNodeCollection; + indexers?: AVMNodeCollection; +} + +export default AVMNetworkConfiguration; diff --git a/packages/chains/src/types/avm/AVMNetworkInformation.ts b/packages/chains/src/types/avm/AVMNetworkInformation.ts index 0cb9755..330021f 100644 --- a/packages/chains/src/types/avm/AVMNetworkInformation.ts +++ b/packages/chains/src/types/avm/AVMNetworkInformation.ts @@ -1,13 +1,12 @@ -// types -import type AVMNodeCollection from './AVMNodeCollection'; - /** - * @property {AVMNodeCollection} algods - A collection of Algod nodes. - * @property {AVMNodeCollection} indexers - [optional] A collection of Indexer nodes. + * @property {string} feeSinkAddress - The fee sink address. + * @property {string} genesisHash - A base64 encoded hash of the genesis block. + * @property {string} genesisID - A human-readable identifier for the network. */ interface AVMNetworkInformation { - algods: AVMNodeCollection; - indexers?: AVMNodeCollection; + feeSinkAddress: string; + genesisHash: string; + genesisID: string; } export default AVMNetworkInformation; diff --git a/packages/chains/src/types/avm/AVMTransactionParamsResponse.ts b/packages/chains/src/types/avm/AVMTransactionParamsResponse.ts new file mode 100644 index 0000000..c31cac5 --- /dev/null +++ b/packages/chains/src/types/avm/AVMTransactionParamsResponse.ts @@ -0,0 +1,10 @@ +interface AVMTransactionParamsResponse { + 'consensus-version': string; + fee: number; + 'genesis-hash': string; + 'genesis-id': string; + 'last-round': number; + 'min-fee': number; +} + +export default AVMTransactionParamsResponse; diff --git a/packages/chains/src/types/avm/index.ts b/packages/chains/src/types/avm/index.ts index 36ab365..56dd9c4 100644 --- a/packages/chains/src/types/avm/index.ts +++ b/packages/chains/src/types/avm/index.ts @@ -1,3 +1,6 @@ +export type { default as AVMGenesisResponse } from './AVMGenesisResponse'; +export type { default as AVMNetworkConfiguration } from './AVMNetworkConfiguration'; export type { default as AVMNetworkInformation } from './AVMNetworkInformation'; export type { default as AVMNode } from './AVMNode'; export type { default as AVMNodeCollection } from './AVMNodeCollection'; +export type { default as AVMTransactionParamsResponse } from './AVMTransactionParamsResponse'; diff --git a/packages/chains/src/types/chains/Chain.ts b/packages/chains/src/types/chains/Chain.ts deleted file mode 100644 index eafac1e..0000000 --- a/packages/chains/src/types/chains/Chain.ts +++ /dev/null @@ -1,31 +0,0 @@ -// enums -import { CAIP002Namespace } from '@/enums'; - -// types -import type { AVMNetworkInformation, NativeCurrency } from '@/types'; - -/** - * @property {string} displayName - A human-readable name for the chain. - * @property {string} iconURI - A data URI of the chain that conforms to RFC-2397 or a URL that points to an image. The - * **RECOMMENDED** image format should be lossless or vector-based such as a PNG, WebP or SVG. - * @property {string} namespace - The CAIP-002 namespace of the chain. It acts as a resolution to the chain's reference. - * @property {NativeCurrency} nativeCurrency - Details relating to the native currency of the chain. - * @property {string} reference - A unique identifier for the chain within the CAIP-002 namespace. - * * `algorand`/`avm`: This is the first 32 characters of the base64 encoded genesis hash. - * @property {boolean} testnet - Whether this chain is considered a testnet. - */ -interface Chain { - displayName: string; - iconURI: string; - namespace: Namespace; - nativeCurrency: NativeCurrency; - network: Namespace extends CAIP002Namespace.Algorand - ? AVMNetworkInformation - : Namespace extends CAIP002Namespace.AVM - ? AVMNetworkInformation - : never; - reference: string; - testnet: boolean; -} - -export default Chain; diff --git a/packages/chains/src/types/chains/ChainParameters.ts b/packages/chains/src/types/chains/ChainParameters.ts new file mode 100644 index 0000000..6e4fc2e --- /dev/null +++ b/packages/chains/src/types/chains/ChainParameters.ts @@ -0,0 +1,12 @@ +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type NetworkInformation from './NetworkInformation'; + +interface ChainParameters { + networkInformation: NetworkInformation; + reference: string; +} + +export default ChainParameters; diff --git a/packages/chains/src/types/chains/NetworkConfiguration.ts b/packages/chains/src/types/chains/NetworkConfiguration.ts new file mode 100644 index 0000000..a3a0535 --- /dev/null +++ b/packages/chains/src/types/chains/NetworkConfiguration.ts @@ -0,0 +1,13 @@ +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { AVMNetworkConfiguration } from '@/types'; + +type NetworkConfiguration = Namespace extends CAIP002Namespace.Algorand + ? AVMNetworkConfiguration + : Namespace extends CAIP002Namespace.AVM + ? AVMNetworkConfiguration + : never; + +export default NetworkConfiguration; diff --git a/packages/chains/src/types/chains/NetworkInformation.ts b/packages/chains/src/types/chains/NetworkInformation.ts new file mode 100644 index 0000000..a4588b4 --- /dev/null +++ b/packages/chains/src/types/chains/NetworkInformation.ts @@ -0,0 +1,13 @@ +// enums +import { CAIP002Namespace } from '@/enums'; + +// types +import type { AVMNetworkInformation } from '@/types'; + +type NetworkInfomration = Namespace extends CAIP002Namespace.Algorand + ? AVMNetworkInformation + : Namespace extends CAIP002Namespace.AVM + ? AVMNetworkInformation + : never; + +export default NetworkInfomration; diff --git a/packages/chains/src/types/chains/index.ts b/packages/chains/src/types/chains/index.ts index 390c65d..a4c7c5e 100644 --- a/packages/chains/src/types/chains/index.ts +++ b/packages/chains/src/types/chains/index.ts @@ -1 +1,3 @@ -export type { default as Chain } from './Chain'; +export type { default as ChainParameters } from './ChainParameters'; +export type { default as NetworkConfiguration } from './NetworkConfiguration'; +export type { default as NetworkInformation } from './NetworkInformation'; diff --git a/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.test.ts b/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.test.ts deleted file mode 100644 index 1a1c92a..0000000 --- a/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { describe, expect, test } from 'vitest'; - -// utilities -import avmGenesisHashToCAIP002Reference from './avmGenesisHashToCAIP002Reference'; - -interface TestParameters { - expected: string; - input: string; -} - -describe('avmGenesisHashToCAIP002Reference', () => { - test.each([ - { - expected: 'r20fSQI8gWe_kFZziNonSPCXLwcQmH_n', // Voi mainnet - input: 'r20fSQI8gWe/kFZziNonSPCXLwcQmH/nxROvnnueWOk=', - }, - { - expected: 'mufvzhECYAe3WaU075v0z4k1_SNUIuUP', // Voi testnet - input: 'mufvzhECYAe3WaU075v0z4k1/SNUIuUPCyBTE+Z/08s=', - }, - { - expected: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73k', // Algorand mainnet - input: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=', - }, - { - expected: 'mFgazF-2uRS1tMiL9dsj01hJGySEmPN2', // Algorand betanet - input: 'mFgazF+2uRS1tMiL9dsj01hJGySEmPN28B/TjjvpVW0=', - }, - { - expected: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe', // Algorand testnet - input: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', - }, - { - expected: 'kUt08LxeVAAGHnh4JoAoAMM9ql_hBwSo', // Algorand fnet - input: 'kUt08LxeVAAGHnh4JoAoAMM9ql/hBwSoiFtlnKNeOxA=', - }, - ])(`should parse $input to $expected`, ({ expected, input }: TestParameters) => { - expect(avmGenesisHashToCAIP002Reference(input)).toBe(expected); - }); -}); diff --git a/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.ts b/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.ts deleted file mode 100644 index bfecb0c..0000000 --- a/packages/chains/src/utilities/avm/avmGenesisHashToCAIP002Reference.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { decode as decodeBase64, encodeURLSafe as encodeBase64URL } from '@stablelib/base64'; - -/** - * Creates the CAIP-002 chain reference from an AVM genesis hash. - * - * The reference, for AVM chains, is the first 32 bytes, converted to URL-safe base64. - * @param {string} genesisHash - An AVM genesis hash. - * @returns {string} The AVM genesis hash converted to the CAIP-002 chain reference. - * @see {@link https://chainagnostic.org/CAIPs/caip-2} - */ -export default function avmGenesisHashToCAIP002Reference(genesisHash: string): string { - const decodedGenesisHash = decodeBase64(genesisHash); - - return encodeBase64URL(decodedGenesisHash).slice(0, 32); -} diff --git a/packages/chains/src/utilities/avm/index.ts b/packages/chains/src/utilities/avm/index.ts deleted file mode 100644 index 50639a0..0000000 --- a/packages/chains/src/utilities/avm/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as avmGenesisHashToCAIP002Reference } from './avmGenesisHashToCAIP002Reference'; diff --git a/packages/chains/src/utilities/caip/chainID.ts b/packages/chains/src/utilities/caip/chainID.ts deleted file mode 100644 index 22e9c42..0000000 --- a/packages/chains/src/utilities/caip/chainID.ts +++ /dev/null @@ -1,12 +0,0 @@ -// types -import type { Chain } from '@/types'; - -/** - * Generates the CAIP-002 chain identifier by combining the namespace and reference with a colon. - * @param {chain} Chain - The chain. - * @return {string} The CAIP-002 chain identifier as "namespace:reference". - * @see {@link https://chainagnostic.org/CAIPs/caip-2} - */ -export default function chainID({ namespace, reference }: Chain): string { - return `${namespace}:${reference}`; -} diff --git a/packages/chains/src/utilities/caip/index.ts b/packages/chains/src/utilities/caip/index.ts deleted file mode 100644 index d6f6930..0000000 --- a/packages/chains/src/utilities/caip/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as chainID } from './chainID'; diff --git a/packages/chains/src/utilities/index.ts b/packages/chains/src/utilities/index.ts deleted file mode 100644 index da035ea..0000000 --- a/packages/chains/src/utilities/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './avm'; -export * from './caip'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6338e57..d67b78f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,6 +104,9 @@ importers: '@kibisis/encoding': specifier: workspace:^ version: link:../encoding + axios: + specifier: ^1.10.0 + version: 1.10.0 devDependencies: '@eslint/js': specifier: 'catalog:' @@ -2172,10 +2175,16 @@ packages: resolution: {integrity: sha512-6t10qk83GOG8p0vKmaCr8eiilZwO171AvbROMtvvNiwrTly62t+7XkA8RdIIVbpMhCASAsxgAzdRSwh6nw/5Dg==} engines: {node: '>=4'} + asynckit@0.4.0: + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + available-typed-arrays@1.0.7: resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==} engines: {node: '>= 0.4'} + axios@1.10.0: + resolution: {integrity: sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw==} + babel-plugin-macros@3.1.0: resolution: {integrity: sha512-Cg7TFGpIr01vOQNODXOOaGz2NpCU5gl8x1qJFbb6hbZxR7XrcE2vtbAsTAbJ7/xwJtUuJEw8K8Zr/AE0LHlesg==} engines: {node: '>=10', npm: '>=6'} @@ -2324,6 +2333,10 @@ packages: colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} + combined-stream@1.0.8: + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} + engines: {node: '>= 0.8'} + commander@13.1.0: resolution: {integrity: sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==} engines: {node: '>=18'} @@ -2485,6 +2498,10 @@ packages: resolution: {integrity: sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==} engines: {node: '>=10'} + delayed-stream@1.0.0: + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} + engines: {node: '>=0.4.0'} + depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -2571,6 +2588,10 @@ packages: resolution: {integrity: sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==} engines: {node: '>= 0.4'} + es-set-tostringtag@2.1.0: + resolution: {integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==} + engines: {node: '>= 0.4'} + esbuild-register@3.6.0: resolution: {integrity: sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg==} peerDependencies: @@ -2804,6 +2825,15 @@ packages: flatted@3.3.3: resolution: {integrity: sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==} + follow-redirects@1.15.9: + resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + for-each@0.3.5: resolution: {integrity: sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg==} engines: {node: '>= 0.4'} @@ -2812,6 +2842,10 @@ packages: resolution: {integrity: sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==} engines: {node: '>=14'} + form-data@4.0.4: + resolution: {integrity: sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==} + engines: {node: '>= 6'} + forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} engines: {node: '>= 0.6'} @@ -3451,10 +3485,18 @@ packages: resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} + mime-db@1.52.0: + resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} + engines: {node: '>= 0.6'} + mime-db@1.54.0: resolution: {integrity: sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==} engines: {node: '>= 0.6'} + mime-types@2.1.35: + resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} + engines: {node: '>= 0.6'} + mime-types@3.0.1: resolution: {integrity: sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==} engines: {node: '>= 0.6'} @@ -3920,6 +3962,9 @@ packages: proxy-compare@3.0.1: resolution: {integrity: sha512-V9plBAt3qjMlS1+nC8771KNf6oJ12gExvaxnNzN/9yVRLdTv/lc+oJlnSzrdYDAvBfTStPCoiaCOTmTs0adv7Q==} + proxy-from-env@1.1.0: + resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + proxy-memoize@3.0.1: resolution: {integrity: sha512-VDdG/VYtOgdGkWJx7y0o7p+zArSf2383Isci8C+BP3YXgMYDoPd3cCBjw0JdWb6YBb9sFiOPbAADDVTPJnh+9g==} @@ -6958,10 +7003,20 @@ snapshots: dependencies: tslib: 2.8.1 + asynckit@0.4.0: {} + available-typed-arrays@1.0.7: dependencies: possible-typed-array-names: 1.1.0 + axios@1.10.0: + dependencies: + follow-redirects: 1.15.9 + form-data: 4.0.4 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + babel-plugin-macros@3.1.0: dependencies: '@babel/runtime': 7.27.1 @@ -7128,6 +7183,10 @@ snapshots: colorette@2.0.20: {} + combined-stream@1.0.8: + dependencies: + delayed-stream: 1.0.0 + commander@13.1.0: {} compare-func@2.0.0: @@ -7274,6 +7333,8 @@ snapshots: rimraf: 3.0.2 slash: 3.0.0 + delayed-stream@1.0.0: {} + depd@2.0.0: {} dequal@2.0.3: {} @@ -7341,6 +7402,13 @@ snapshots: dependencies: es-errors: 1.3.0 + es-set-tostringtag@2.1.0: + dependencies: + es-errors: 1.3.0 + get-intrinsic: 1.3.0 + has-tostringtag: 1.0.2 + hasown: 2.0.2 + esbuild-register@3.6.0(esbuild@0.25.4): dependencies: debug: 4.4.0 @@ -7703,6 +7771,8 @@ snapshots: flatted@3.3.3: {} + follow-redirects@1.15.9: {} + for-each@0.3.5: dependencies: is-callable: 1.2.7 @@ -7712,6 +7782,14 @@ snapshots: cross-spawn: 7.0.6 signal-exit: 4.1.0 + form-data@4.0.4: + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + es-set-tostringtag: 2.1.0 + hasown: 2.0.2 + mime-types: 2.1.35 + forwarded@0.2.0: {} fresh@2.0.0: {} @@ -8298,8 +8376,14 @@ snapshots: braces: 3.0.3 picomatch: 2.3.1 + mime-db@1.52.0: {} + mime-db@1.54.0: {} + mime-types@2.1.35: + dependencies: + mime-db: 1.52.0 + mime-types@3.0.1: dependencies: mime-db: 1.54.0 @@ -8634,6 +8718,8 @@ snapshots: proxy-compare@3.0.1: {} + proxy-from-env@1.1.0: {} + proxy-memoize@3.0.1: dependencies: proxy-compare: 3.0.1