Skip to content

Commit

Permalink
fix code review comments by @sampocs
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Aug 1, 2024
1 parent e0c1df4 commit 2e3a23d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
30 changes: 21 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ export function feeFromGas(gasLimit: number, gasPrice: number = 0.025): StdFee {
};
}

/**
* Represents an IBC transfer path.
*/
export type IbcTransferPath = {
/**
* The port ID on the receiving chain.
*/
incomingPortId: string;

/**
* The channel ID on the receiving chain.
*/
incomingChannelId: string;
};

/**
* Compute the IBC denom of a token that was sent over IBC.
*
Expand All @@ -102,15 +117,12 @@ export function feeFromGas(gasLimit: number, gasPrice: number = 0.025): StdFee {
* ibcDenom([{incomingPortId: "transfer", incomingChannelId: "channel-326"}], "ustrd")
* ```
*
* @param {Object[]} paths An array of objects containing information about the IBC transfer paths.
* @param {IbcTransferPath[]} paths An array of objects containing information about the IBC transfer paths.
* @param {string} coinMinimalDenom The minimal denom of the coin.
* @returns {string} The computed IBC denom of the token.
*/
export function ibcDenom(
paths: {
incomingPortId: string;
incomingChannelId: string;
}[],
paths: IbcTransferPath[],
coinMinimalDenom: string,
): string {
const prefixes: string[] = [];
Expand Down Expand Up @@ -139,9 +151,9 @@ export function pubkeyToAddress(
}

/**
* Convert a secp256k1 compressed public key to an address.
* Convert a base64 encoded secp256k1 compressed public key to an address.
*
* @param {Uint8Array} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {string} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {String} [prefix="stride"] The address' bech32 prefix. Defaults to `"stride"`.
* @returns the account's address
*/
Expand Down Expand Up @@ -198,9 +210,9 @@ export function tendermintPubkeyToValconsAddress(
}

/**
* Convert a secp256k1 compressed public key to an address.
* Convert a base64 encoded secp256k1 compressed public key to a validator address.
*
* @param {Uint8Array} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {string} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {String} [prefix="stride"] The address' bech32 prefix. Defaults to `"stride"`.
* @returns the account's address.
*/
Expand Down
28 changes: 19 additions & 9 deletions types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ export declare function coinsFromString(coinsAsString: string): Coin[];
* @returns {StdFee} A StdFee object with the calculated fee amount and gas limit.
*/
export declare function feeFromGas(gasLimit: number, gasPrice?: number): StdFee;
/**
* Represents an IBC transfer path.
*/
export declare type IbcTransferPath = {
/**
* The port ID on the receiving chain.
*/
incomingPortId: string;
/**
* The channel ID on the receiving chain.
*/
incomingChannelId: string;
};
/**
* Compute the IBC denom of a token that was sent over IBC.
*
Expand All @@ -78,14 +91,11 @@ export declare function feeFromGas(gasLimit: number, gasPrice?: number): StdFee;
* ibcDenom([{incomingPortId: "transfer", incomingChannelId: "channel-326"}], "ustrd")
* ```
*
* @param {Object[]} paths An array of objects containing information about the IBC transfer paths.
* @param {IbcTransferPath[]} paths An array of objects containing information about the IBC transfer paths.
* @param {string} coinMinimalDenom The minimal denom of the coin.
* @returns {string} The computed IBC denom of the token.
*/
export declare function ibcDenom(paths: {
incomingPortId: string;
incomingChannelId: string;
}[], coinMinimalDenom: string): string;
export declare function ibcDenom(paths: IbcTransferPath[], coinMinimalDenom: string): string;
/**
* Convert a secp256k1 compressed public key to an address.
*
Expand All @@ -95,9 +105,9 @@ export declare function ibcDenom(paths: {
*/
export declare function pubkeyToAddress(pubkey: Uint8Array, prefix?: string): string;
/**
* Convert a secp256k1 compressed public key to an address.
* Convert a base64 encoded secp256k1 compressed public key to an address.
*
* @param {Uint8Array} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {string} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {String} [prefix="stride"] The address' bech32 prefix. Defaults to `"stride"`.
* @returns the account's address
*/
Expand Down Expand Up @@ -127,9 +137,9 @@ export declare function validatorAddressToSelfDelegatorAddress(validator: string
*/
export declare function tendermintPubkeyToValconsAddress(pubkey: Uint8Array, prefix?: string): string;
/**
* Convert a secp256k1 compressed public key to an address.
* Convert a base64 encoded secp256k1 compressed public key to a validator address.
*
* @param {Uint8Array} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {string} pubkey The account's pubkey as base64 string, should be 33 bytes (compressed secp256k1).
* @param {String} [prefix="stride"] The address' bech32 prefix. Defaults to `"stride"`.
* @returns the account's address.
*/
Expand Down

0 comments on commit 2e3a23d

Please sign in to comment.