From 2604583d041fcbe9d914055821991914ac3cda85 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Tue, 27 Feb 2024 16:42:09 +0100 Subject: [PATCH 1/5] chore: Bump sdk-nova version to latest commit --- .github/workflows/nova-build-temp.yaml | 2 +- setup_nova.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nova-build-temp.yaml b/.github/workflows/nova-build-temp.yaml index 7b718a706..d604f5850 100644 --- a/.github/workflows/nova-build-temp.yaml +++ b/.github/workflows/nova-build-temp.yaml @@ -6,7 +6,7 @@ on: TARGET_COMMIT: description: "Target Commit Hash for the SDK" required: false - default: "fc9f0f56bb5cfc146993e53aa9656ded220734e1" + default: "772a5665afb7663b5ddb2c1e4780d03401fc7aa2" environment: type: choice description: "Select the environment to deploy to" diff --git a/setup_nova.sh b/setup_nova.sh index b69fcd007..65cbc7009 100755 --- a/setup_nova.sh +++ b/setup_nova.sh @@ -1,6 +1,6 @@ #!/bin/bash SDK_DIR="iota-sdk" -TARGET_COMMIT="fc9f0f56bb5cfc146993e53aa9656ded220734e1" +TARGET_COMMIT="772a5665afb7663b5ddb2c1e4780d03401fc7aa2" if [ ! -d "$SDK_DIR" ]; then git clone -b 2.0 git@github.com:iotaledger/iota-sdk.git From a5fe19dc67c6ff02443113a7a1b256faa4064976 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Tue, 27 Feb 2024 18:54:12 +0100 Subject: [PATCH 2/5] chore: Improve nova address helper --- api/src/models/api/nova/IAddressDetails.ts | 1 - api/src/utils/nova/addressHelper.ts | 21 ++++++++++++------- client/src/helpers/nova/addressHelper.ts | 18 +++++++++------- client/src/models/api/nova/IAddressDetails.ts | 1 - 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/api/src/models/api/nova/IAddressDetails.ts b/api/src/models/api/nova/IAddressDetails.ts index 8dd8a13ec..8aaca791d 100644 --- a/api/src/models/api/nova/IAddressDetails.ts +++ b/api/src/models/api/nova/IAddressDetails.ts @@ -7,5 +7,4 @@ export interface IAddressDetails { hex?: string; type?: AddressType; label?: string; - capabilities?: number[]; } diff --git a/api/src/utils/nova/addressHelper.ts b/api/src/utils/nova/addressHelper.ts index b34d59066..5b4f72dc0 100644 --- a/api/src/utils/nova/addressHelper.ts +++ b/api/src/utils/nova/addressHelper.ts @@ -12,6 +12,7 @@ import { ImplicitAccountCreationAddress, } from "@iota/sdk-nova"; import { plainToInstance } from "class-transformer"; +import logger from "../../logger"; import { IAddressDetails } from "../../models/api/nova/IAddressDetails"; import { HexHelper } from "../hexHelper"; @@ -31,6 +32,7 @@ export class AddressHelper { let bech32: string; let hex: string; let type: AddressType; + if (Utils.isAddressValid(addressString)) { try { const address: Address = Utils.parseBech32Address(addressString); @@ -41,27 +43,28 @@ export class AddressHelper { hex = Utils.bech32ToHex(addressString); } } catch (e) { - console.error(e); + logger.debug(`Failed parsing Address. Cause: ${e}`); } } if (!bech32) { // We assume this is hex hex = addressString; + if (typeHint) { - bech32 = this.computeBech32FromHexAndType(hex, type, hrp); + bech32 = this.computeBech32FromHexAndType(hex, typeHint, hrp); } } return { bech32, hex: hex ? HexHelper.addPrefix(hex) : hex, - type, + type: type ?? typeHint, label: AddressHelper.typeLabel(type), }; } - private static buildAddressFromTypes(address: Address, hrp: string, capabilities?: number[]): IAddressDetails { + private static buildAddressFromTypes(address: Address, hrp: string): IAddressDetails { let hex: string = ""; let bech32: string = ""; @@ -79,14 +82,13 @@ export class AddressHelper { hex = innerAddress.pubKeyHash; } - bech32 = this.computeBech32FromHexAndType(hex, address.type, hrp); + bech32 = Utils.addressToBech32(address, hrp); return { bech32, hex, type: address.type, label: AddressHelper.typeLabel(address.type), - capabilities, }; } @@ -100,8 +102,7 @@ export class AddressHelper { } else if (addressType === AddressType.Nft) { bech32 = Utils.nftIdToBech32(hex, hrp); } else if (addressType === AddressType.Anchor) { - // Update to Utils.anchorIdToBech32 when it gets implemented - bech32 = Utils.accountIdToBech32(hex, hrp); + bech32 = Utils.anchorIdToBech32(hex, hrp); } else if (addressType === AddressType.ImplicitAccountCreation) { bech32 = Utils.hexToBech32(hex, hrp); } @@ -123,6 +124,10 @@ export class AddressHelper { return "NFT"; } else if (addressType === AddressType.Anchor) { return "Anchor"; + } else if (addressType === AddressType.ImplicitAccountCreation) { + return "Implicit Account Creation"; } + + return "Unknown"; } } diff --git a/client/src/helpers/nova/addressHelper.ts b/client/src/helpers/nova/addressHelper.ts index c1d21b217..e6915a145 100644 --- a/client/src/helpers/nova/addressHelper.ts +++ b/client/src/helpers/nova/addressHelper.ts @@ -42,7 +42,7 @@ export class AddressHelper { } if (!bech32) { - // We assume this is hex and either use the hint or assume ed25519 + // We assume this is hex hex = addressString; type = typeHint ?? AddressType.Ed25519; bech32 = this.computeBech32FromHexAndType(hex, type, hrp); @@ -51,12 +51,12 @@ export class AddressHelper { return { bech32, hex: hex ? HexHelper.addPrefix(hex) : hex, - type, + type: type ?? typeHint, label: AddressHelper.typeLabel(type), }; } - private static buildAddressFromTypes(address: Address, hrp: string, capabilities?: number[]): IAddressDetails { + private static buildAddressFromTypes(address: Address, hrp: string): IAddressDetails { let hex: string = ""; let bech32: string = ""; @@ -74,14 +74,13 @@ export class AddressHelper { hex = (innerAddress as Ed25519Address).pubKeyHash; } - bech32 = this.computeBech32FromHexAndType(hex, address.type, hrp); + bech32 = Utils.addressToBech32(address, hrp); return { bech32, hex, type: address.type, label: AddressHelper.typeLabel(address.type), - capabilities, }; } @@ -95,8 +94,7 @@ export class AddressHelper { } else if (addressType === AddressType.Nft) { bech32 = Utils.nftIdToBech32(hex, hrp); } else if (addressType === AddressType.Anchor) { - // TODO Utils.anchorIdToBech32 does not exist https://github.com/iotaledger/iota-sdk/issues/1973 - bech32 = Utils.accountIdToBech32(hex, hrp); + bech32 = Utils.anchorIdToBech32(hex, hrp); } else if (addressType === AddressType.ImplicitAccountCreation) { bech32 = Utils.hexToBech32(hex, hrp); } @@ -109,7 +107,7 @@ export class AddressHelper { * @param addressType The address type to get the label for. * @returns The label. */ - private static typeLabel(addressType?: number): string | undefined { + private static typeLabel(addressType?: AddressType): string | undefined { if (addressType === AddressType.Ed25519) { return "Ed25519"; } else if (addressType === AddressType.Account) { @@ -118,6 +116,10 @@ export class AddressHelper { return "NFT"; } else if (addressType === AddressType.Anchor) { return "Anchor"; + } else if (addressType === AddressType.ImplicitAccountCreation) { + return "Implicit Account Creation"; } + + return "Unknown"; } } diff --git a/client/src/models/api/nova/IAddressDetails.ts b/client/src/models/api/nova/IAddressDetails.ts index a9e238c56..234c08768 100644 --- a/client/src/models/api/nova/IAddressDetails.ts +++ b/client/src/models/api/nova/IAddressDetails.ts @@ -5,5 +5,4 @@ export interface IAddressDetails { hex?: string; type?: AddressType; label?: string; - capabilities?: number[]; } From d5bca2a65aaeccd5cfba568b9311527c1987dbad Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Wed, 28 Feb 2024 09:42:45 +0100 Subject: [PATCH 3/5] feat: Remove dependency on specific address to bech32 Utils methods --- api/src/utils/nova/addressHelper.ts | 15 ++++++--- client/src/app/components/nova/OutputView.tsx | 8 +++-- .../section/TransactionMetadataSection.tsx | 32 +++++++++++++------ .../src/app/routes/nova/TransactionPage.tsx | 4 +-- client/src/helpers/nova/addressHelper.ts | 15 ++++++--- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/api/src/utils/nova/addressHelper.ts b/api/src/utils/nova/addressHelper.ts index 5b4f72dc0..97e494b61 100644 --- a/api/src/utils/nova/addressHelper.ts +++ b/api/src/utils/nova/addressHelper.ts @@ -94,17 +94,22 @@ export class AddressHelper { private static computeBech32FromHexAndType(hex: string, addressType: AddressType, hrp: string) { let bech32 = ""; + let address: Address | null = null; if (addressType === AddressType.Ed25519) { - bech32 = Utils.hexToBech32(hex, hrp); + address = new Ed25519Address(hex); } else if (addressType === AddressType.Account) { - bech32 = Utils.accountIdToBech32(hex, hrp); + address = new AccountAddress(hex); } else if (addressType === AddressType.Nft) { - bech32 = Utils.nftIdToBech32(hex, hrp); + address = new NftAddress(hex); } else if (addressType === AddressType.Anchor) { - bech32 = Utils.anchorIdToBech32(hex, hrp); + address = new AnchorAddress(hex); } else if (addressType === AddressType.ImplicitAccountCreation) { - bech32 = Utils.hexToBech32(hex, hrp); + address = new ImplicitAccountCreationAddress(hex); + } + + if (address !== null) { + bech32 = Utils.addressToBech32(address, hrp); } return bech32; diff --git a/client/src/app/components/nova/OutputView.tsx b/client/src/app/components/nova/OutputView.tsx index 544a5daaf..515b9d02f 100644 --- a/client/src/app/components/nova/OutputView.tsx +++ b/client/src/app/components/nova/OutputView.tsx @@ -13,6 +13,8 @@ import { SimpleTokenScheme, DelegationOutput, Utils, + AccountAddress, + NftAddress, } from "@iota/sdk-wasm-nova/web"; import UnlockConditionView from "./UnlockConditionView"; import CopyButton from "../CopyButton"; @@ -223,11 +225,13 @@ function buildAddressForAliasOrNft(outputId: string, output: Output, bech32Hrp: const accountId = HexHelper.toBigInt256(accountIdFromOutput).eq(bigInt.zero) ? Utils.computeAccountId(outputId) : accountIdFromOutput; - bech32 = Utils.accountIdToBech32(accountId, bech32Hrp); + const accountAddress = new AccountAddress(accountId); + bech32 = Utils.addressToBech32(accountAddress, bech32Hrp); } else if (output.type === OutputType.Nft) { const nftIdFromOutput = (output as NftOutput).nftId; const nftId = HexHelper.toBigInt256(nftIdFromOutput).eq(bigInt.zero) ? Utils.computeNftId(outputId) : nftIdFromOutput; - bech32 = Utils.nftIdToBech32(nftId, bech32Hrp); + const nftAddress = new NftAddress(nftId); + bech32 = Utils.addressToBech32(nftAddress, bech32Hrp); } return bech32; diff --git a/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx b/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx index 79ea81e1c..9199f53aa 100644 --- a/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx +++ b/client/src/app/components/nova/block/section/TransactionMetadataSection.tsx @@ -1,4 +1,11 @@ -import { TRANSACTION_FAILURE_REASON_STRINGS, Transaction, TransactionMetadata, TransactionState, Utils } from "@iota/sdk-wasm-nova/web"; +import { + TRANSACTION_FAILURE_REASON_STRINGS, + Transaction, + TransactionMetadata, + TransactionState, + Utils, + AccountAddress, +} from "@iota/sdk-wasm-nova/web"; import React from "react"; import Spinner from "../../../Spinner"; import TruncatedId from "~/app/components/stardust/TruncatedId"; @@ -63,15 +70,20 @@ const TransactionMetadataSection: React.FC = ({ {transaction?.allotments && (
Mana Allotment Accounts
- {transaction?.allotments?.map((allotment, idx) => ( -
- -
- ))} + {transaction?.allotments?.map((allotment, idx) => { + const accountAddress = new AccountAddress(allotment.accountId); + const accountBech32 = Utils.addressToBech32(accountAddress, bech32Hrp); + + return ( +
+ +
+ ); + })}
)} diff --git a/client/src/app/routes/nova/TransactionPage.tsx b/client/src/app/routes/nova/TransactionPage.tsx index 79aebb339..592fb921c 100644 --- a/client/src/app/routes/nova/TransactionPage.tsx +++ b/client/src/app/routes/nova/TransactionPage.tsx @@ -1,5 +1,5 @@ /* eslint-disable react/jsx-no-useless-fragment */ -import { BasicBlockBody, SignedTransactionPayload, Utils } from "@iota/sdk-wasm-nova/web"; +import { AccountAddress, BasicBlockBody, SignedTransactionPayload, Utils } from "@iota/sdk-wasm-nova/web"; import React, { useEffect, useState } from "react"; import { RouteComponentProps } from "react-router-dom"; import metadataInfoMessage from "~assets/modals/stardust/block/metadata.json"; @@ -135,7 +135,7 @@ const TransactionPage: React.FC> = ({
diff --git a/client/src/helpers/nova/addressHelper.ts b/client/src/helpers/nova/addressHelper.ts index e6915a145..a33b31fbb 100644 --- a/client/src/helpers/nova/addressHelper.ts +++ b/client/src/helpers/nova/addressHelper.ts @@ -86,17 +86,22 @@ export class AddressHelper { private static computeBech32FromHexAndType(hex: string, addressType: AddressType, hrp: string) { let bech32 = ""; + let address: Address | null = null; if (addressType === AddressType.Ed25519) { - bech32 = Utils.hexToBech32(hex, hrp); + address = new Ed25519Address(hex); } else if (addressType === AddressType.Account) { - bech32 = Utils.accountIdToBech32(hex, hrp); + address = new AccountAddress(hex); } else if (addressType === AddressType.Nft) { - bech32 = Utils.nftIdToBech32(hex, hrp); + address = new NftAddress(hex); } else if (addressType === AddressType.Anchor) { - bech32 = Utils.anchorIdToBech32(hex, hrp); + address = new AnchorAddress(hex); } else if (addressType === AddressType.ImplicitAccountCreation) { - bech32 = Utils.hexToBech32(hex, hrp); + address = new ImplicitAccountCreationAddress(hex); + } + + if (address !== null) { + bech32 = Utils.addressToBech32(address, hrp); } return bech32; From 004cd07863118f793d7ca9a293aeab8e411e29ce Mon Sep 17 00:00:00 2001 From: Branko Bosnic Date: Wed, 28 Feb 2024 11:29:31 +0100 Subject: [PATCH 4/5] fix: nft address calculation and typo in function naming --- client/src/app/components/nova/OutputView.tsx | 4 ++-- .../src/app/components/nova/address/section/nft/Nft.tsx | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/app/components/nova/OutputView.tsx b/client/src/app/components/nova/OutputView.tsx index 515b9d02f..e8ca6c461 100644 --- a/client/src/app/components/nova/OutputView.tsx +++ b/client/src/app/components/nova/OutputView.tsx @@ -42,7 +42,7 @@ const OutputView: React.FC = ({ outputId, output, showCopyAmoun const [isFormattedBalance, setIsFormattedBalance] = useState(true); const { bech32Hrp, name: network } = useNetworkInfoNova((s) => s.networkInfo); - const aliasOrNftBech32 = buildAddressForAliasOrNft(outputId, output, bech32Hrp); + const aliasOrNftBech32 = buildAddressForAccountOrNft(outputId, output, bech32Hrp); const outputIdTransactionPart = `${outputId.slice(0, 8)}....${outputId.slice(-8, -4)}`; const outputIdIndexPart = outputId.slice(-4); const manaEntries = getManaKeyValueEntries(manaDetails); @@ -217,7 +217,7 @@ const OutputView: React.FC = ({ outputId, output, showCopyAmoun ); }; -function buildAddressForAliasOrNft(outputId: string, output: Output, bech32Hrp: string): string { +function buildAddressForAccountOrNft(outputId: string, output: Output, bech32Hrp: string): string { let bech32: string = ""; if (output.type === OutputType.Account) { diff --git a/client/src/app/components/nova/address/section/nft/Nft.tsx b/client/src/app/components/nova/address/section/nft/Nft.tsx index fe84536ab..6dd0694b1 100644 --- a/client/src/app/components/nova/address/section/nft/Nft.tsx +++ b/client/src/app/components/nova/address/section/nft/Nft.tsx @@ -16,7 +16,7 @@ import { tryParseMetadata } from "~helpers/stardust/metadataUtils"; import { INftImmutableMetadata } from "~models/api/stardust/nft/INftImmutableMetadata"; import "./Nft.scss"; import { useNetworkInfoNova } from "~/helpers/nova/networkInfo"; -import { MetadataFeature, NftOutput, Utils } from "@iota/sdk-wasm-nova/web"; +import { MetadataFeature, NftAddress, NftOutput, Utils } from "@iota/sdk-wasm-nova/web"; import TruncatedId from "~/app/components/stardust/TruncatedId"; import { TransactionsHelper } from "~/helpers/nova/transactionsHelper"; @@ -32,7 +32,8 @@ const Nft: React.FC = ({ nftOutput }) => { const [metadata, setMetadata] = useState(null); const [issuerId, setIssuerId] = useState(null); const [standardMetadata, setStandardMetadata] = useState(); - const nftAddress = Utils.hexToBech32(nftOutput.nftId, bech32Hrp); + const nftAddress = new NftAddress(nftOutput.nftId); + const nftBech32Address = Utils.addressToBech32(nftAddress, bech32Hrp); const [isWhitelisted] = useTokenRegistryNftCheck(issuerId, nftOutput.nftId); const [name, setName] = useState(); const [uri, isNftUriLoading] = useNftMetadataUri(standardMetadata?.uri); @@ -75,9 +76,9 @@ const Nft: React.FC = ({ nftOutput }) => { return (
- {nftImageContent} + {nftImageContent} - +
{name && isWhitelisted && {name}} From 22e70c443618f40e8e00f01cf796564600eb3848 Mon Sep 17 00:00:00 2001 From: Branko Bosnic Date: Wed, 28 Feb 2024 11:56:05 +0100 Subject: [PATCH 5/5] fix: variable name --- client/src/app/components/nova/OutputView.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/app/components/nova/OutputView.tsx b/client/src/app/components/nova/OutputView.tsx index e8ca6c461..9b24e53a0 100644 --- a/client/src/app/components/nova/OutputView.tsx +++ b/client/src/app/components/nova/OutputView.tsx @@ -42,7 +42,7 @@ const OutputView: React.FC = ({ outputId, output, showCopyAmoun const [isFormattedBalance, setIsFormattedBalance] = useState(true); const { bech32Hrp, name: network } = useNetworkInfoNova((s) => s.networkInfo); - const aliasOrNftBech32 = buildAddressForAccountOrNft(outputId, output, bech32Hrp); + const accountOrNftBech32 = buildAddressForAccountOrNft(outputId, output, bech32Hrp); const outputIdTransactionPart = `${outputId.slice(0, 8)}....${outputId.slice(-8, -4)}`; const outputIdIndexPart = outputId.slice(-4); const manaEntries = getManaKeyValueEntries(manaDetails); @@ -101,8 +101,8 @@ const OutputView: React.FC = ({ outputId, output, showCopyAmoun
Account address:
@@ -129,8 +129,8 @@ const OutputView: React.FC = ({ outputId, output, showCopyAmoun
Nft address: