Skip to content

Commit d4b93c4

Browse files
authored
Merge pull request #588 from multiversx/TOOL-512-Cleanup-update-descriptions
Update methods description and delete unnecessary code
2 parents 524ad09 + 10e0cb8 commit d4b93c4

32 files changed

+448
-423
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiversx/sdk-core",
3-
"version": "14.0.0-beta.1",
3+
"version": "14.0.0-beta.2",
44
"description": "MultiversX SDK for JavaScript and TypeScript",
55
"author": "MultiversX",
66
"homepage": "https://multiversx.com",

src/accountManagement/accountController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { IAccount } from "../accounts/interfaces";
21
import { Address, BaseController, BaseControllerInput } from "../core";
2+
import { IAccount } from "../core/interfaces";
33
import { Transaction } from "../core/transaction";
44
import { TransactionsFactoryConfig } from "../core/transactionsFactoryConfig";
55
import { AccountTransactionsFactory } from "./accountTransactionsFactory";

src/accounts/account.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import * as fs from "fs";
22
import { PathLike } from "fs";
3-
import { Message, MessageComputer, TransactionComputer } from "../core";
4-
import { Address } from "../core/address";
5-
import { LibraryConfig } from "../core/config";
6-
import { Transaction } from "../core/transaction";
7-
import { KeyPair, Mnemonic, UserPublicKey, UserSecretKey, UserSigner, UserWallet } from "../wallet";
8-
import { UserPem } from "../wallet/userPem";
9-
import { IAccount } from "./interfaces";
3+
import { Address, IAccount, LibraryConfig, Message, MessageComputer, Transaction, TransactionComputer } from "../core";
4+
import { KeyPair, Mnemonic, UserPem, UserPublicKey, UserSecretKey, UserSigner, UserWallet } from "../wallet";
105

116
/**
127
* An abstraction representing an account (user or Smart Contract) on the Network.

src/accounts/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from "./account";
2-
export * from "./interfaces";

src/accounts/interfaces.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export * from "./baseController";
66
export * from "./codeMetadata";
77
export * from "./config";
88
export * from "./errors";
9-
export * from "./interface";
9+
export * from "./interfaces";
1010
export * from "./logger";
1111
export * from "./message";
1212
export * from "./networkParams";

src/core/interface.ts renamed to src/core/interfaces.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { TransactionOnNetwork } from "./transactionOnNetwork";
1+
import { Address, Message, Transaction, TransactionOnNetwork } from ".";
2+
3+
export interface IAccount {
4+
readonly address: Address;
5+
6+
sign(data: Uint8Array): Promise<Uint8Array>;
7+
signTransaction(transaction: Transaction): Promise<Uint8Array>;
8+
verifyTransactionSignature(transaction: Transaction, signature: Uint8Array): Promise<boolean>;
9+
signMessage(message: Message): Promise<Uint8Array>;
10+
verifyMessageSignature(message: Message, signature: Uint8Array): Promise<boolean>;
11+
}
212

313
export interface ITransactionFetcher {
414
/**

src/core/message.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export class MessageComputer {
5151
return createKeccakHash("keccak256").update(bytesToHash).digest();
5252
}
5353

54+
/**
55+
* returns the result of `computeBytesForSigning`
56+
*/
5457
computeBytesForVerifying(message: Message): Uint8Array {
5558
return this.computeBytesForSigning(message);
5659
}
@@ -71,6 +74,10 @@ export class MessageComputer {
7174
};
7275
}
7376

77+
/**
78+
* packedMessage should be the one obtained from calling `packMessage()`
79+
* should treat both 'legacy message' and current message
80+
*/
7481
unpackMessage(packedMessage: {
7582
message: string;
7683
signature?: string;

src/core/tokens.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ interface ILegacyTokenTransferOptions {
2121
export type TokenType = "NFT" | "SFT" | "META" | "FNG";
2222

2323
export class Token {
24+
/**
25+
* E.g. "FOO-abcdef", "EGLD-000000".
26+
*/
2427
readonly identifier: string;
2528
readonly nonce: bigint;
2629

@@ -88,6 +91,10 @@ export class TokenTransfer {
8891
}
8992
}
9093

94+
/** *
95+
* @param amount
96+
* @returns @TokenTransfer from native token
97+
*/
9198
static newFromNativeAmount(amount: bigint): TokenTransfer {
9299
const token = new Token({ identifier: EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER });
93100
return new TokenTransfer({ token, amount });
@@ -98,15 +105,15 @@ export class TokenTransfer {
98105
}
99106

100107
/**
101-
* @deprecated Use the constructor instead: new TokenTransfer({ token, amount });
108+
* @deprecated Use {@link newFromNativeAmount} instead.
102109
*/
103110
static egldFromAmount(amount: BigNumber.Value) {
104111
const amountAsBigInteger = new BigNumber(amount).shiftedBy(EGLDNumDecimals).decimalPlaces(0);
105112
return this.egldFromBigInteger(amountAsBigInteger);
106113
}
107114

108115
/**
109-
* @deprecated Use the constructor instead: new TokenTransfer({ token, amount });
116+
* @deprecated Use {@link newFromNativeAmount} instead.
110117
*/
111118
static egldFromBigInteger(amountAsBigInteger: BigNumber.Value) {
112119
return new TokenTransfer({
@@ -232,10 +239,16 @@ export class TokenComputer {
232239
TOKEN_RANDOM_SEQUENCE_LENGTH = 6;
233240
constructor() {}
234241

242+
/**
243+
* Returns token.nonce == 0
244+
*/
235245
isFungible(token: Token): boolean {
236246
return token.nonce === 0n;
237247
}
238248

249+
/**
250+
* Given "FOO-abcdef-0a" returns 10.
251+
*/
239252
extractNonceFromExtendedIdentifier(identifier: string): number {
240253
const parts = identifier.split("-");
241254

@@ -252,6 +265,9 @@ export class TokenComputer {
252265
return decodeUnsignedNumber(Buffer.from(hexNonce, "hex"));
253266
}
254267

268+
/**
269+
* Given "FOO-abcdef-0a" returns FOO-abcdef.
270+
*/
255271
extractIdentifierFromExtendedIdentifier(identifier: string): string {
256272
const parts = identifier.split("-");
257273
const { prefix, ticker, randomSequence } = this.splitIdentifierIntoComponents(parts);
@@ -264,6 +280,22 @@ export class TokenComputer {
264280
return ticker + "-" + randomSequence;
265281
}
266282

283+
/**
284+
* Given "FOO-abcdef-0a" returns FOO.
285+
* Given "FOO-abcdef" returns FOO.
286+
*/
287+
extractTickerFromExtendedIdentifier(identifier: string): string {
288+
const parts = identifier.split("-");
289+
const { prefix, ticker, randomSequence } = this.splitIdentifierIntoComponents(parts);
290+
291+
this.validateExtendedIdentifier(prefix, ticker, randomSequence, parts);
292+
if (prefix) {
293+
this.checkLengthOfPrefix(prefix);
294+
return prefix + "-" + ticker + "-" + randomSequence;
295+
}
296+
return ticker;
297+
}
298+
267299
computeExtendedIdentifier(token: Token): string {
268300
const parts = token.identifier.split("-");
269301
const { prefix, ticker, randomSequence } = this.splitIdentifierIntoComponents(parts);
@@ -315,10 +347,6 @@ export class TokenComputer {
315347
}
316348
}
317349

318-
private isLowercaseAlphanumeric(str: string): boolean {
319-
return /^[a-z0-9]+$/.test(str);
320-
}
321-
322350
private checkLengthOfRandomSequence(randomSequence: string): void {
323351
if (randomSequence.length !== this.TOKEN_RANDOM_SEQUENCE_LENGTH) {
324352
throw new ErrInvalidTokenIdentifier(

0 commit comments

Comments
 (0)