Rename method to pubkeyToAddress

This commit is contained in:
Simon Warta 2020-02-19 10:06:10 +01:00
parent ef999070e8
commit 67b21337ba
6 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { decodeBech32Pubkey, encodeAddress, types } from "@cosmwasm/sdk";
import { decodeBech32Pubkey, pubkeyToAddress as sdkPubkeyToAddress, types } from "@cosmwasm/sdk";
import { Address, Algorithm, PubkeyBundle, PubkeyBytes } from "@iov/bcp";
import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
@ -34,5 +34,5 @@ export function pubkeyToAddress(pubkey: PubkeyBundle, prefix: string): Address {
throw new Error(`Unsupported algorithm: ${pubkey.algo}`);
}
return encodeAddress(sdkKey, prefix) as Address;
return sdkPubkeyToAddress(sdkKey, prefix) as Address;
}

View File

@ -1,18 +1,18 @@
import { Encoding } from "@iov/encoding";
import { encodeAddress } from "./address";
import { pubkeyToAddress } from "./address";
const { toBase64, fromHex } = Encoding;
describe("address", () => {
describe("encodeAddress", () => {
describe("pubkeyToAddress", () => {
it("works for Secp256k1 compressed", () => {
const prefix = "cosmos";
const pubkey = {
type: "tendermint/PubKeySecp256k1",
value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP",
};
expect(encodeAddress(pubkey, prefix)).toEqual("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r");
expect(pubkeyToAddress(pubkey, prefix)).toEqual("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r");
});
it("works for Ed25519", () => {
@ -21,7 +21,7 @@ describe("address", () => {
type: "tendermint/PubKeyEd25519",
value: toBase64(fromHex("12ee6f581fe55673a1e9e1382a0829e32075a0aa4763c968bc526e1852e78c95")),
};
expect(encodeAddress(pubkey, prefix)).toEqual("cosmos1pfq05em6sfkls66ut4m2257p7qwlk448h8mysz");
expect(pubkeyToAddress(pubkey, prefix)).toEqual("cosmos1pfq05em6sfkls66ut4m2257p7qwlk448h8mysz");
});
});
});

View File

@ -7,7 +7,7 @@ const { fromBase64 } = Encoding;
// See https://github.com/tendermint/tendermint/blob/f2ada0a604b4c0763bda2f64fac53d506d3beca7/docs/spec/blockchain/encoding.md#public-key-cryptography
// This assumes we already have a cosmos-compressed pubkey
export function encodeAddress(pubkey: PubKey, prefix: string): string {
export function pubkeyToAddress(pubkey: PubKey, prefix: string): string {
const pubkeyBytes = fromBase64(pubkey.value);
switch (pubkey.type) {
case pubkeyType.secp256k1: {

View File

@ -2,7 +2,7 @@ import * as logs from "./logs";
import * as types from "./types";
export { logs, types };
export { encodeAddress } from "./address";
export { pubkeyToAddress } from "./address";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";

View File

@ -1,2 +1,2 @@
import { PubKey } from "./types";
export declare function encodeAddress(pubkey: PubKey, prefix: string): string;
export declare function pubkeyToAddress(pubkey: PubKey, prefix: string): string;

View File

@ -1,7 +1,7 @@
import * as logs from "./logs";
import * as types from "./types";
export { logs, types };
export { encodeAddress } from "./address";
export { pubkeyToAddress } from "./address";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";