Skip to content

Commit

Permalink
docs: update tsdocs for internal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Nov 2, 2023
1 parent bd96bb5 commit a875de1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/transactions/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 14 additions & 3 deletions packages/transactions/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(obj: T): T {
return lodashCloneDeep(obj);
}
Expand All @@ -40,22 +41,30 @@ export function omit<T, K extends keyof any>(obj: T, prop: K): Omit<T, K> {
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);
Expand All @@ -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');
Expand All @@ -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');
Expand Down

1 comment on commit a875de1

@vercel
Copy link

@vercel vercel bot commented on a875de1 Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.