From a875de1e712d090d7090968af3f24c02f51719e4 Mon Sep 17 00:00:00 2001 From: janniks Date: Mon, 30 Oct 2023 23:42:59 +0100 Subject: [PATCH] docs: update tsdocs for internal methods --- packages/transactions/src/constants.ts | 1 + packages/transactions/src/utils.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/transactions/src/constants.ts b/packages/transactions/src/constants.ts index 97375ec97..47ea8aab2 100644 --- a/packages/transactions/src/constants.ts +++ b/packages/transactions/src/constants.ts @@ -234,6 +234,7 @@ export enum AssetType { } // todo: refactor this, if only used in one place, just use a string +/** @ignore */ export enum TxRejectedReason { Serialization = 'Serialization', Deserialization = 'Deserialization', diff --git a/packages/transactions/src/utils.ts b/packages/transactions/src/utils.ts index 84648b3a5..85a7a3804 100644 --- a/packages/transactions/src/utils.ts +++ b/packages/transactions/src/utils.ts @@ -29,6 +29,7 @@ export const rightPadHexToLength = (hexString: string, length: number): string = export const exceedsMaxLengthBytes = (string: string, maxLengthBytes: number): boolean => string ? utf8ToBytes(string).length > maxLengthBytes : false; +/** @ignore */ export function cloneDeep(obj: T): T { return lodashCloneDeep(obj); } @@ -40,22 +41,30 @@ export function omit(obj: T, prop: K): Omit { return clone; } +export const hash160 = (input: Uint8Array): Uint8Array => { + return ripemd160(sha256(input)); +}; + +/** @deprecated renamed to {@link txidFromBytes} */ export const txidFromData = (data: Uint8Array): string => { return bytesToHex(sha512_256(data)); }; -export const hash160 = (input: Uint8Array): Uint8Array => { - return ripemd160(sha256(input)); -}; +/** + * Computes the transaction ID of the bytes from a serialized transaction (or any other bytes using the same hash function). + */ +export const txidFromBytes = txidFromData; // Internally, the Stacks blockchain encodes address the same as Bitcoin // single-sig address (p2pkh) +/** @ignore */ export const hashP2PKH = (input: Uint8Array): string => { return bytesToHex(hash160(input)); }; // Internally, the Stacks blockchain encodes address the same as Bitcoin // single-sig address over p2sh (p2h-p2wpkh) +/** @ignore */ export const hashP2WPKH = (input: Uint8Array): string => { const keyHash = hash160(input); const redeemScript = concatBytes(new Uint8Array([0]), new Uint8Array([keyHash.length]), keyHash); @@ -65,6 +74,7 @@ export const hashP2WPKH = (input: Uint8Array): string => { // Internally, the Stacks blockchain encodes address the same as Bitcoin // multi-sig address (p2sh) +/** @ignore */ export const hashP2SH = (numSigs: number, pubKeys: Uint8Array[]): string => { if (numSigs > 15 || pubKeys.length > 15) { throw Error('P2SH multisig address can only contain up to 15 public keys'); @@ -91,6 +101,7 @@ export const hashP2SH = (numSigs: number, pubKeys: Uint8Array[]): string => { // Internally, the Stacks blockchain encodes address the same as Bitcoin // multisig address over p2sh (p2sh-p2wsh) +/** @ignore */ export const hashP2WSH = (numSigs: number, pubKeys: Uint8Array[]): string => { if (numSigs > 15 || pubKeys.length > 15) { throw Error('P2WSH multisig address can only contain up to 15 public keys');