diff --git a/package-lock.json b/package-lock.json index 41820177..a967a0b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.4.0", + "version": "12.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.4.0", + "version": "12.4.1", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index d51b4a50..f7167abe 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/transaction.ts b/src/transaction.ts index a957adf4..092aae7d 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -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 ((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); }