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

Remove (replace) "instanceof Buffer" from applySignature() #302

Merged
merged 5 commits into from
Jun 20, 2023
Merged
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: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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-core",
"version": "12.4.0",
"version": "12.4.1",
"description": "MultiversX SDK for JavaScript and TypeScript",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
34 changes: 17 additions & 17 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,28 +371,28 @@ export class Transaction {
*
* @param signature The signature, as computed by a signer.
*/
applySignature(signature: ISignature | Buffer) {
if (signature instanceof Buffer) {
this.signature = signature;
} else {
this.signature = Buffer.from(signature.hex(), "hex");
}

applySignature(signature: ISignature | Uint8Array) {
this.signature = this.interpretSignatureAsBuffer(signature);
this.hash = TransactionHash.compute(this);
}

/**
* Applies the guardian signature on the transaction.
*
* @param guardianSignature The signature, as computed by a signer.
*/
applyGuardianSignature(guardianSignature: ISignature | Buffer) {
if (guardianSignature instanceof Buffer) {
this.guardianSignature = guardianSignature;
} else {
this.guardianSignature = Buffer.from(guardianSignature.hex(), "hex");
private interpretSignatureAsBuffer(signature: ISignature | Uint8Array): Buffer {
if (ArrayBuffer.isView(signature)) {
return Buffer.from(signature);
} else if ((<any>signature).hex != null) {
return Buffer.from(signature.hex(), "hex");
}

throw new Error(`Object cannot be interpreted as a signature: ${signature}`);
}

/**
* Applies the guardian signature on the transaction.
*
* @param guardianSignature The signature, as computed by a signer.
*/
applyGuardianSignature(guardianSignature: ISignature | Uint8Array) {
this.guardianSignature = this.interpretSignatureAsBuffer(guardianSignature);
this.hash = TransactionHash.compute(this);
}

Expand Down