Skip to content
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

Added custom HRP #1340

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[v3.1.1](https://github.com/multiversx/mx-sdk-dapp/pull/1341)] - 2024-12-06

- [Allow custom HRP](https://github.com/multiversx/mx-sdk-dapp/pull/1340)

## [[v3.1.0](https://github.com/multiversx/mx-sdk-dapp/pull/1339)] - 2024-12-05

- [Added address table pagination to the Ledger authentication flow](https://github.com/multiversx/mx-sdk-dapp/pull/1338)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "3.1.0",
"version": "3.1.1",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SignStepBodyComponent = ({
currentTransaction.transactionTokenInfo;

const transactionReceiver = multiTxData
? new Address(receiver).bech32()
? Address.newFromHex(receiver).toBech32()
: currentTransaction.transaction.getReceiver().toString();

const scamReport = currentTransaction.receiverScamInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/login/useLoginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useLoginService = (config?: OnProviderLoginType['nativeAuth']) => {
}

const messageToSign = new Message({
address: new Address(address),
address: Address.newFromBech32(address),
data: Buffer.from(`${address}${loginToken}`)
});

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/signMessage/getVerifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, UserPublicKey, UserVerifier } from '@multiversx/sdk-core';

export const getVerifier = (address: string) => {
const publicKey = new UserPublicKey(new Address(address).pubkey());
const publicKey = new UserPublicKey(Address.newFromBech32(address).pubkey());

return new UserVerifier(publicKey);
};
2 changes: 1 addition & 1 deletion src/hooks/signMessage/useSignMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => {
const callbackUrl = encodeURIComponent(String(callbackRoute));

const signableMessage = new Message({
address: new Address(address),
address: Address.newFromBech32(address),
data: Buffer.from(message)
});

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/signMessage/verifyMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const verifyMessage = (signedMessage: string) => {
const messageComputer = new MessageComputer();

const msg = new Message({
address: new Address(address),
address: Address.newFromBech32(address),
data: decodedMessage
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const checkNeedsGuardianSigning = ({
});

const chainId = transactions[0].getChainID().valueOf();
const sender = transactions[0].getSender().bech32().toString();
const sender = transactions[0].sender;
const environment = getEnvironmentForChainId(chainId);
const walletProviderAddress =
walletAddress ?? fallbackNetworkConfigurations[environment].walletAddress;
Expand Down
8 changes: 5 additions & 3 deletions src/models/newTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export function newTransaction(rawTransaction: RawTransactionType) {
value: rawTx.value.valueOf(),
data: getDataPayloadForTransaction(rawTx.data),
nonce: rawTx.nonce.valueOf(),
receiver: new Address(rawTx.receiver),
receiver: Address.newFromBech32(rawTx.receiver),
...(rawTx.receiverUsername
? { receiverUsername: rawTx.receiverUsername }
: {}),
sender: new Address(rawTx.sender),
sender: Address.newFromBech32(rawTx.sender),
...(rawTx.senderUsername ? { senderUsername: rawTx.senderUsername } : {}),
gasLimit: rawTx.gasLimit.valueOf() ?? GAS_LIMIT,
gasPrice: rawTx.gasPrice.valueOf() ?? GAS_PRICE,
Expand All @@ -35,7 +35,9 @@ export function newTransaction(rawTransaction: RawTransactionType) {
...(rawTx.options
? { options: new TransactionOptions(rawTx.options) }
: {}),
...(rawTx.guardian ? { guardian: new Address(rawTx.guardian) } : {})
...(rawTx.guardian
? { guardian: Address.newFromBech32(rawTx.guardian) }
: {})
});

if (rawTx.guardianSignature) {
Expand Down
4 changes: 2 additions & 2 deletions src/reduxStore/slices/accountInfoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const accountInfoSlice = createSlice({
) => {
const address = action.payload;
state.address = address;
state.publicKey = address ? new Address(address).hex() : '';
state.publicKey = address ? Address.newFromBech32(address).hex() : '';
},
setAccount: (
state: AccountInfoSliceType,
Expand Down Expand Up @@ -173,7 +173,7 @@ export const accountInfoSlice = createSlice({
) => {
const { address } = action.payload;
state.address = address;
state.publicKey = new Address(address).hex();
state.publicKey = Address.newFromBech32(address).hex();
}
);
builder.addCase(REHYDRATE, (state, action: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/transactions/isCrossShardTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function isCrossShardTransaction({
senderAddress
}: IsCrossShardTransactionPropsType) {
try {
const receiver = new Address(receiverAddress);
const receiver = Address.newFromBech32(receiverAddress);
const receiverShard = getShardOfAddress(receiver.pubkey());
if (senderShard == null && senderAddress != null) {
const sender = new Address(senderAddress);
const sender = Address.newFromBech32(senderAddress);
return getShardOfAddress(sender) === receiverShard;
}
return receiverShard === senderShard;
Expand Down
4 changes: 2 additions & 2 deletions src/services/transactions/transformAndSignTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function transformAndSignTransactions({
let validatedReceiver = receiver;

try {
const addr = new Address(receiver);
const addr = Address.newFromBech32(receiver);
validatedReceiver = addr.hex();
} catch (err) {
throw ErrorCodesEnum.invalidReceiver;
Expand All @@ -87,7 +87,7 @@ export async function transformAndSignTransactions({
gasPrice,
gasLimit: Number(gasLimit),
nonce: Number(computedNonce.valueOf().toString()),
sender: new Address(address).hex(),
sender: Address.newFromBech32(address).hex(),
chainID: transactionsChainId,
version,
options,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/account/addressIsValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Address } from '@multiversx/sdk-core';

function canTransformToPublicKey(address: string) {
try {
const checkAddress = new Address(address);
return Boolean(checkAddress.bech32());
const checkAddress = Address.newFromBech32(address);
return Boolean(checkAddress.toBech32());
} catch {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/account/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const signMessage = async ({
const callbackUrl = addOriginToLocationPath(callbackRoute);

const signableMessage = new Message({
address: new Address(address),
address: Address.newFromBech32(address),
data: Buffer.from(message)
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils/operations/calculateFeeLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export function calculateFeeLimit({
const transaction = new Transaction({
nonce: 0,
value: TokenPayment.egldFromAmount('0'),
receiver: new Address(placeholderData.to),
sender: new Address(placeholderData.to),
receiver: Address.newFromBech32(placeholderData.to),
sender: Address.newFromBech32(placeholderData.to),
gasPrice: parseInt(validGasPrice),
gasLimit: usedGasLimit,
data: new TransactionPayload(data.trim()),
Expand Down
4 changes: 2 additions & 2 deletions src/utils/transactions/getTokenFromData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ export function getTokenFromData(data?: string): {
decodeData(data);
if (
[collection, nonce, quantity, receiver].every((el) => Boolean(el)) &&
addressIsValid(new Address(receiver).bech32())
addressIsValid(Address.newFromHex(receiver).toBech32())
) {
return {
tokenId: `${collection}-${nonce}`,
amount: new BigNumber(quantity, 16).toString(10),
collection,
nonce,
receiver: new Address(receiver).bech32()
receiver: Address.newFromHex(receiver).toBech32()
};
}
} catch (err) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function parseMultiEsdtTransferDataForMultipleTransactions({
txInfo: {
tokenId,
amount,
receiver: transaction.getReceiver().bech32()
receiver: transaction.receiver
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const useAppInitializer = ({

useEffect(() => {
if (address) {
const pubKey = new Address(address).hex();
const pubKey = Address.newFromBech32(address).hex();
if (pubKey !== publicKey) {
logout(logoutRoute);
}
Expand Down
Loading