Skip to content

Commit dbe8eea

Browse files
committed
fix(sdk-coin-icp): enhance hash functions to support Uint8Array in Utils class
TICKET: WIN-5215
1 parent 1e096b9 commit dbe8eea

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/sdk-coin-icp/src/lib/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class Transaction extends BaseTransaction {
118118
throw new Error('Invalid transaction type');
119119
}
120120
} catch (error) {
121-
throw new InvalidTransactionError('Invalid raw transaction');
121+
throw new InvalidTransactionError(`Invalid transaction type: ${error.message}`);
122122
}
123123
}
124124

modules/sdk-coin-icp/src/lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ export class Utils implements BaseUtils {
472472
hashVal(val: string | Buffer | BigInt | number | Array<unknown>): Buffer {
473473
if (typeof val === 'string') {
474474
return utils.hashString(val);
475-
} else if (Buffer.isBuffer(val)) {
475+
} else if (Buffer.isBuffer(val) || val instanceof Uint8Array) {
476476
return utils.hashBytes(val);
477477
} else if (typeof val === 'bigint' || typeof val === 'number') {
478478
return utils.hashU64(BigInt(val));
@@ -489,7 +489,7 @@ export class Utils implements BaseUtils {
489489
* @param value - The buffer to hash.
490490
* @returns The SHA-256 hash of the input buffer.
491491
*/
492-
hashBytes(value: Buffer): Buffer {
492+
hashBytes(value: Buffer | Uint8Array): Buffer {
493493
return this.sha256([value]);
494494
}
495495

@@ -499,7 +499,7 @@ export class Utils implements BaseUtils {
499499
* @param {Array<Buffer>} chunks - An array of Buffer objects to be hashed.
500500
* @returns {Buffer} - The resulting SHA-256 hash as a Buffer.
501501
*/
502-
sha256(chunks: Array<Buffer>): Buffer {
502+
sha256(chunks: Array<Buffer> | Array<Uint8Array>): Buffer {
503503
const hasher = js_sha256.sha256.create();
504504
chunks.forEach((chunk) => hasher.update(chunk));
505505
return Buffer.from(hasher.arrayBuffer());

0 commit comments

Comments
 (0)