Skip to content

Commit a2696e6

Browse files
committed
refactor(sdk-coin-rune): change type from Buffer to Uint8Array
Ticket: COIN-2191
1 parent e34b33e commit a2696e6

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class RuneUtils extends CosmosUtils {
3232
}
3333

3434
/** @inheritdoc */
35-
isValidAddress(address: string | Buffer): boolean {
35+
isValidAddress(address: string | Uint8Array): boolean {
3636
if (address === undefined || address === null) {
3737
return false;
3838
}
@@ -46,13 +46,13 @@ export class RuneUtils extends CosmosUtils {
4646
}
4747

4848
/**
49-
* Validates a decoded address in `Buffer` form by encoding it and
49+
* Validates a decoded address in `Uint8Array` form by encoding it and
5050
* checking if the encoded version is valid
5151
*
52-
* @param address - The decoded address as a `Buffer`.
52+
* @param address - The decoded address as a `Uint8Array`.
5353
* @returns `true` if the encoded address is valid, `false` otherwise.
5454
*/
55-
private isValidDecodedAddress(address: Buffer): boolean {
55+
private isValidDecodedAddress(address: Uint8Array): boolean {
5656
const encodedAddress = this.getEncodedAddress(address);
5757
return this.isValidEncodedAddress(encodedAddress);
5858
}
@@ -71,14 +71,14 @@ export class RuneUtils extends CosmosUtils {
7171
}
7272

7373
/**
74-
* Encodes a given address `Buffer` into a bech32 string format, based on the current network type.
75-
* Primarily serves as a utility to convert a `Buffer`-type address to a bech32 encoded string
74+
* Encodes a given address `Uint8Array` into a bech32 string format, based on the current network type.
75+
* Primarily serves as a utility to convert a `Uint8Array`-type address to a bech32 encoded string
7676
*
77-
* @param address - The address to be encoded, provided as a `Buffer`.
77+
* @param address - The address to be encoded, provided as a `Uint8Array`.
7878
* @returns A bech32-encoded string representing the address.
7979
* @throws Error - Throws an error if encoding fails
8080
*/
81-
getEncodedAddress(address: Buffer): string {
81+
getEncodedAddress(address: Uint8Array): string {
8282
try {
8383
return this.networkType === NetworkType.TESTNET
8484
? bech32.encode(TESTNET_ADDRESS_PREFIX, address)
@@ -89,14 +89,14 @@ export class RuneUtils extends CosmosUtils {
8989
}
9090

9191
/**
92-
* Decodes a bech32-encoded address string back into a `Buffer`.
92+
* Decodes a bech32-encoded address string back into a `Uint8Array`.
9393
* Primarily serves as a utility to convert a string-type address into its binary representation,
9494
*
9595
* @param address - The bech32-encoded address as a `string`.
96-
* @returns The decoded address as a `Buffer`.
96+
* @returns The decoded address as a `Uint8Array`.
9797
* @throws Error - Throws an error if decoding fails
9898
*/
99-
getDecodedAddress(address: string): Buffer {
99+
getDecodedAddress(address: string): Uint8Array {
100100
try {
101101
return bech32.decode(address).data;
102102
} catch (error) {
@@ -128,7 +128,7 @@ export class RuneUtils extends CosmosUtils {
128128
}
129129
}
130130

131-
convertMessageAddressToBuffer(messages: MessageData[]): MessageData[] {
131+
convertMessageAddressToUint8Array(messages: MessageData[]): MessageData[] {
132132
return messages.map((message) => {
133133
if ('fromAddress' in message.value && 'toAddress' in message.value) {
134134
const sendMessage = message.value;
@@ -161,7 +161,7 @@ export class RuneUtils extends CosmosUtils {
161161
publicKey?: string,
162162
memo?: string
163163
): CosmosLikeTransaction {
164-
messages = this.convertMessageAddressToBuffer(messages);
164+
messages = this.convertMessageAddressToUint8Array(messages);
165165
const cosmosLikeTxn = {
166166
sequence: sequence,
167167
sendMessages: messages,

modules/sdk-coin-rune/test/unit/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ describe('utils', () => {
8383

8484
it('should convert string type testnet address to Uint8Array', () => {
8585
const decodedAddress = testnetUtils.getDecodedAddress(testnetAddress.address1);
86-
should.equal(decodedAddress instanceof Uint8Array, true);
8786
should.equal(decodedAddress.length, 20);
8887
});
8988

9089
it('should convert string type mainnet address to Uint8Array', () => {
9190
const decodedAddress = mainnetUtils.getDecodedAddress(mainnetAddress.address1);
92-
should.equal(decodedAddress instanceof Uint8Array, true);
9391
should.equal(decodedAddress.length, 20);
9492
});
9593

0 commit comments

Comments
 (0)