Pull out encodeSecp256k1Pubkey
This commit is contained in:
parent
3207a5d5ed
commit
266697a63f
@ -41,6 +41,7 @@ export function main(originalArgs: readonly string[]): void {
|
||||
[
|
||||
"@cosmwasm/sdk",
|
||||
[
|
||||
"encodeSecp256k1Pubkey",
|
||||
"encodeSecp256k1Signature",
|
||||
"makeSignBytes",
|
||||
"marshalTx",
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { Secp256k1 } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { Msg, NonceInfo, pubkeyType, StdFee, StdSignature, StdTx } from "./types";
|
||||
import { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
import { Msg, NonceInfo, StdFee, StdSignature, StdTx } from "./types";
|
||||
|
||||
const { toBase64, toUtf8 } = Encoding;
|
||||
|
||||
@ -61,10 +62,7 @@ export function makeSignBytes(
|
||||
export function encodeSecp256k1Signature(pubkey: Uint8Array, signature: Uint8Array): StdSignature {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
pub_key: {
|
||||
type: pubkeyType.secp256k1,
|
||||
value: toBase64(Secp256k1.compressPubkey(pubkey)),
|
||||
},
|
||||
pub_key: encodeSecp256k1Pubkey(pubkey),
|
||||
// Recovery seems to be unused
|
||||
signature: toBase64(Secp256k1.trimRecoveryByte(signature)),
|
||||
};
|
||||
|
||||
@ -7,3 +7,4 @@ export { unmarshalTx } from "./decoding";
|
||||
export { encodeSecp256k1Signature, makeSignBytes, marshalTx } from "./encoding";
|
||||
export { RestClient, TxsResponse } from "./restclient";
|
||||
export { makeCosmoshubPath, Pen, PrehashType, Secp256k1Pen } from "./pen";
|
||||
export { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
|
||||
27
packages/sdk/src/pubkey.spec.ts
Normal file
27
packages/sdk/src/pubkey.spec.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
|
||||
const { fromBase64 } = Encoding;
|
||||
|
||||
describe("pubkey", () => {
|
||||
describe("encodeSecp256k1Pubkey", () => {
|
||||
it("encodes a full signature", () => {
|
||||
const pubkey = fromBase64("AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP");
|
||||
expect(encodeSecp256k1Pubkey(pubkey)).toEqual({
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP",
|
||||
});
|
||||
});
|
||||
|
||||
it("compresses uncompressed public keys", () => {
|
||||
const pubkey = fromBase64(
|
||||
"BE8EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQE7WHpoHoNswYeoFkuYpYSKK4mzFzMV/dB0DVAy4lnNU=",
|
||||
);
|
||||
expect(encodeSecp256k1Pubkey(pubkey)).toEqual({
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
11
packages/sdk/src/pubkey.ts
Normal file
11
packages/sdk/src/pubkey.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Secp256k1 } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { PubKey, pubkeyType } from "./types";
|
||||
|
||||
export function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey {
|
||||
return {
|
||||
type: pubkeyType.secp256k1,
|
||||
value: Encoding.toBase64(Secp256k1.compressPubkey(pubkey)),
|
||||
};
|
||||
}
|
||||
1
packages/sdk/types/index.d.ts
vendored
1
packages/sdk/types/index.d.ts
vendored
@ -6,3 +6,4 @@ export { unmarshalTx } from "./decoding";
|
||||
export { encodeSecp256k1Signature, makeSignBytes, marshalTx } from "./encoding";
|
||||
export { RestClient, TxsResponse } from "./restclient";
|
||||
export { makeCosmoshubPath, Pen, PrehashType, Secp256k1Pen } from "./pen";
|
||||
export { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
|
||||
2
packages/sdk/types/pubkey.d.ts
vendored
Normal file
2
packages/sdk/types/pubkey.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { PubKey } from "./types";
|
||||
export declare function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey;
|
||||
Loading…
Reference in New Issue
Block a user