Skip to content

Commit

Permalink
Tiny behavioral breaking change: remove some constraints when validat…
Browse files Browse the repository at this point in the history
…ing an address.
  • Loading branch information
andreibancioiu committed May 14, 2024
1 parent 1e8de30 commit dbf259a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const ESDT_CONTRACT_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqq
export const DEFAULT_MESSAGE_VERSION = 1;
export const MESSAGE_PREFIX = "\x17Elrond Signed Message:\n";
export const HEX_TRANSACTION_HASH_LENGTH = 64;
export const BECH32_ADDRESS_LENGTH = 62;
export const CURRENT_NUMBER_OF_SHARDS_WITHOUT_META = 3;
export const WasmVirtualMachine = "0500";
export const METACHAIN_ID = 4294967295;
Expand Down
6 changes: 1 addition & 5 deletions src/transaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UserPublicKey, UserVerifier } from "@multiversx/sdk-wallet";
import BigNumber from "bignumber.js";
import { assert } from "chai";
import { Address } from "./address";
Expand All @@ -9,7 +10,6 @@ import { TokenTransfer } from "./tokens";
import { Transaction } from "./transaction";
import { TransactionComputer } from "./transactionComputer";
import { TransactionPayload } from "./transactionPayload";
import { UserPublicKey, UserVerifier } from "@multiversx/sdk-wallet/out";

describe("test transaction", async () => {
let wallets: Record<string, TestWallet>;
Expand Down Expand Up @@ -674,10 +674,6 @@ describe("test transaction", async () => {
chainID: "",
});

assert.throws(() => {
transactionComputer.computeBytesForSigning(transaction);
}, "Invalid `sender` field. Should be the bech32 address of the sender.");

transaction.sender = wallets.alice.address.toBech32();

assert.throws(() => {
Expand Down
19 changes: 5 additions & 14 deletions src/transactionComputer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { INetworkConfig } from "./interfaceOfNetwork";
import * as errors from "./errors";
import BigNumber from "bignumber.js";
import { ITransaction } from "./interface";
import { ProtoSerializer } from "./proto";
import { Transaction } from "./transaction";
import {
BECH32_ADDRESS_LENGTH,
MIN_TRANSACTION_VERSION_THAT_SUPPORTS_OPTIONS,
TRANSACTION_OPTIONS_TX_GUARDED,
TRANSACTION_OPTIONS_TX_HASH_SIGN,
} from "./constants";
import * as errors from "./errors";
import { ITransaction } from "./interface";
import { INetworkConfig } from "./interfaceOfNetwork";
import { ProtoSerializer } from "./proto";
import { Transaction } from "./transaction";

const createTransactionHasher = require("blake2b");

Check warning on line 13 in src/transactionComputer.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Require statement not part of import statement
const createKeccakHash = require("keccak");

Check warning on line 14 in src/transactionComputer.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Require statement not part of import statement
Expand Down Expand Up @@ -125,14 +124,6 @@ export class TransactionComputer {
}

private ensureValidTransactionFields(transaction: ITransaction) {
if (transaction.sender.length !== BECH32_ADDRESS_LENGTH) {
throw new errors.ErrBadUsage("Invalid `sender` field. Should be the bech32 address of the sender.");
}

if (transaction.receiver.length !== BECH32_ADDRESS_LENGTH) {
throw new errors.ErrBadUsage("Invalid `receiver` field. Should be the bech32 address of the receiver.");
}

if (!transaction.chainID.length) {
throw new errors.ErrBadUsage("The `chainID` field is not set");
}
Expand Down

0 comments on commit dbf259a

Please sign in to comment.