Remove makeSecp256k1SignatureFromFixedLength
in favour of native Secp256k1Signature.fromFixedLength
This commit is contained in:
parent
c229df97e4
commit
dd65786df0
@ -1,4 +1,4 @@
|
||||
import { decodeSignature, makeSecp256k1SignatureFromFixedLength } from "@cosmwasm/sdk";
|
||||
import { decodeSignature } from "@cosmwasm/sdk";
|
||||
import {
|
||||
Account,
|
||||
Address,
|
||||
@ -17,7 +17,7 @@ import {
|
||||
TransactionState,
|
||||
UnsignedTransaction,
|
||||
} from "@iov/bcp";
|
||||
import { Random, Secp256k1, Sha256 } from "@iov/crypto";
|
||||
import { Random, Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
import { Bech32, Encoding } from "@iov/encoding";
|
||||
import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol";
|
||||
import { assert } from "@iov/utils";
|
||||
@ -475,7 +475,7 @@ describe("CosmWasmConnection", () => {
|
||||
const { pubkey, signature } = decodeSignature(encodeFullSignature(signatures[0]));
|
||||
const prehashed = new Sha256(signBytes).digest();
|
||||
const valid = await Secp256k1.verifySignature(
|
||||
makeSecp256k1SignatureFromFixedLength(signature),
|
||||
Secp256k1Signature.fromFixedLength(signature),
|
||||
prehashed,
|
||||
pubkey,
|
||||
);
|
||||
|
||||
@ -24,11 +24,7 @@ export {
|
||||
encodeSecp256k1Pubkey,
|
||||
} from "./pubkey";
|
||||
export { findSequenceForSignedTx } from "./sequence";
|
||||
export {
|
||||
encodeSecp256k1Signature,
|
||||
decodeSignature,
|
||||
makeSecp256k1SignatureFromFixedLength,
|
||||
} from "./signature";
|
||||
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
|
||||
export {
|
||||
SigningCallback,
|
||||
SigningCosmWasmClient,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Secp256k1, Sha256 } from "@iov/crypto";
|
||||
import { Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { Secp256k1Pen } from "./pen";
|
||||
import { decodeSignature, makeSecp256k1SignatureFromFixedLength } from "./signature";
|
||||
import { decodeSignature } from "./signature";
|
||||
|
||||
const { fromHex } = Encoding;
|
||||
|
||||
@ -37,7 +37,7 @@ describe("Sec256k1Pen", () => {
|
||||
const { pubkey, signature } = decodeSignature(await pen.sign(data));
|
||||
|
||||
const valid = await Secp256k1.verifySignature(
|
||||
makeSecp256k1SignatureFromFixedLength(signature),
|
||||
Secp256k1Signature.fromFixedLength(signature),
|
||||
new Sha256(data).digest(),
|
||||
pubkey,
|
||||
);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Secp256k1, Sha256 } from "@iov/crypto";
|
||||
import { Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
|
||||
import { makeSignBytes } from "./encoding";
|
||||
import { decodeSignature, makeSecp256k1SignatureFromFixedLength } from "./signature";
|
||||
import { decodeSignature } from "./signature";
|
||||
import { CosmosSdkTx } from "./types";
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ export async function findSequenceForSignedTx(
|
||||
if (!firstSignature) throw new Error("Signature missing in tx");
|
||||
|
||||
const { pubkey, signature } = decodeSignature(firstSignature);
|
||||
const secp256keSignature = makeSecp256k1SignatureFromFixedLength(signature);
|
||||
const secp256keSignature = Secp256k1Signature.fromFixedLength(signature);
|
||||
|
||||
for (let s = min; s < upperBound; s++) {
|
||||
// console.log(`Trying sequence ${s}`);
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import { Secp256k1Signature } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
import BN from "bn.js";
|
||||
|
||||
import { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
import { pubkeyType, StdSignature } from "./types";
|
||||
@ -39,10 +37,3 @@ export function decodeSignature(
|
||||
throw new Error("Unsupported pubkey type");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use Secp256k1Signature.fromFixedLength once this is published https://github.com/iov-one/iov-core/pull/1401
|
||||
export function makeSecp256k1SignatureFromFixedLength(signature: Uint8Array): Secp256k1Signature {
|
||||
const unpaddedR = Uint8Array.from(new BN(signature.slice(0, 32)).toArray());
|
||||
const unpaddedS = Uint8Array.from(new BN(signature.slice(32, 64)).toArray());
|
||||
return new Secp256k1Signature(unpaddedR, unpaddedS);
|
||||
}
|
||||
|
||||
6
packages/sdk/types/index.d.ts
vendored
6
packages/sdk/types/index.d.ts
vendored
@ -23,11 +23,7 @@ export {
|
||||
encodeSecp256k1Pubkey,
|
||||
} from "./pubkey";
|
||||
export { findSequenceForSignedTx } from "./sequence";
|
||||
export {
|
||||
encodeSecp256k1Signature,
|
||||
decodeSignature,
|
||||
makeSecp256k1SignatureFromFixedLength,
|
||||
} from "./signature";
|
||||
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
|
||||
export {
|
||||
SigningCallback,
|
||||
SigningCosmWasmClient,
|
||||
|
||||
2
packages/sdk/types/signature.d.ts
vendored
2
packages/sdk/types/signature.d.ts
vendored
@ -1,4 +1,3 @@
|
||||
import { Secp256k1Signature } from "@iov/crypto";
|
||||
import { StdSignature } from "./types";
|
||||
/**
|
||||
* Takes a binary pubkey and signature to create a signature object
|
||||
@ -13,4 +12,3 @@ export declare function decodeSignature(
|
||||
readonly pubkey: Uint8Array;
|
||||
readonly signature: Uint8Array;
|
||||
};
|
||||
export declare function makeSecp256k1SignatureFromFixedLength(signature: Uint8Array): Secp256k1Signature;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user