mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
parent
404db28f6f
commit
16b875fac6
@ -1,4 +1,8 @@
|
||||
import { CosmosAddressBech32Prefix, decodeSignature } from "@cosmwasm/sdk";
|
||||
import {
|
||||
CosmosAddressBech32Prefix,
|
||||
decodeSignature,
|
||||
makeSecp256k1SignatureFromFixedLength,
|
||||
} from "@cosmwasm/sdk";
|
||||
import {
|
||||
Account,
|
||||
Address,
|
||||
@ -15,7 +19,7 @@ import {
|
||||
TransactionId,
|
||||
TransactionState,
|
||||
} from "@iov/bcp";
|
||||
import { Random, Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
import { Random, Secp256k1, Sha256 } from "@iov/crypto";
|
||||
import { Bech32, Encoding } from "@iov/encoding";
|
||||
import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol";
|
||||
import { assert } from "@iov/utils";
|
||||
@ -473,7 +477,7 @@ describe("CosmWasmConnection", () => {
|
||||
const { pubkey, signature } = decodeSignature(encodeFullSignature(signatures[0]));
|
||||
const prehashed = new Sha256(signBytes).digest();
|
||||
const valid = await Secp256k1.verifySignature(
|
||||
new Secp256k1Signature(signature.slice(0, 32), signature.slice(32, 64)),
|
||||
makeSecp256k1SignatureFromFixedLength(signature),
|
||||
prehashed,
|
||||
pubkey,
|
||||
);
|
||||
|
@ -41,9 +41,11 @@
|
||||
"@iov/crypto": "^2.0.2",
|
||||
"@iov/encoding": "^2.0.2",
|
||||
"@iov/utils": "^2.0.2",
|
||||
"axios": "^0.19.0"
|
||||
"axios": "^0.19.0",
|
||||
"bn.js": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"readonly-date": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,9 @@ export {
|
||||
encodeSecp256k1Pubkey,
|
||||
} from "./pubkey";
|
||||
export { findSequenceForSignedTx } from "./sequence";
|
||||
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
|
||||
export {
|
||||
encodeSecp256k1Signature,
|
||||
decodeSignature,
|
||||
makeSecp256k1SignatureFromFixedLength,
|
||||
} from "./signature";
|
||||
export { SigningCallback, SigningCosmWasmClient, ExecuteResult } from "./signingcosmwasmclient";
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
import { Secp256k1, Sha256 } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { Secp256k1Pen } from "./pen";
|
||||
import { decodeSignature } from "./signature";
|
||||
import { decodeSignature, makeSecp256k1SignatureFromFixedLength } from "./signature";
|
||||
|
||||
const { fromHex } = Encoding;
|
||||
|
||||
@ -37,7 +37,7 @@ describe("Sec256k1Pen", () => {
|
||||
const { pubkey, signature } = decodeSignature(await pen.sign(data));
|
||||
|
||||
const valid = await Secp256k1.verifySignature(
|
||||
new Secp256k1Signature(signature.slice(0, 32), signature.slice(32, 64)),
|
||||
makeSecp256k1SignatureFromFixedLength(signature),
|
||||
new Sha256(data).digest(),
|
||||
pubkey,
|
||||
);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
|
||||
import { Secp256k1, Sha256 } from "@iov/crypto";
|
||||
|
||||
import { makeSignBytes } from "./encoding";
|
||||
import { decodeSignature } from "./signature";
|
||||
import { decodeSignature, makeSecp256k1SignatureFromFixedLength } 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 = new Secp256k1Signature(signature.slice(0, 32), signature.slice(32, 64));
|
||||
const secp256keSignature = makeSecp256k1SignatureFromFixedLength(signature);
|
||||
|
||||
for (let s = min; s < upperBound; s++) {
|
||||
// console.log(`Trying sequence ${s}`);
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { Secp256k1Signature } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
import BN from "bn.js";
|
||||
|
||||
import { encodeSecp256k1Pubkey } from "./pubkey";
|
||||
import { pubkeyType, StdSignature } from "./types";
|
||||
@ -37,3 +39,10 @@ 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
@ -22,5 +22,9 @@ export {
|
||||
encodeSecp256k1Pubkey,
|
||||
} from "./pubkey";
|
||||
export { findSequenceForSignedTx } from "./sequence";
|
||||
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
|
||||
export {
|
||||
encodeSecp256k1Signature,
|
||||
decodeSignature,
|
||||
makeSecp256k1SignatureFromFixedLength,
|
||||
} from "./signature";
|
||||
export { SigningCallback, SigningCosmWasmClient, ExecuteResult } from "./signingcosmwasmclient";
|
||||
|
2
packages/sdk/types/signature.d.ts
vendored
2
packages/sdk/types/signature.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
import { Secp256k1Signature } from "@iov/crypto";
|
||||
import { StdSignature } from "./types";
|
||||
/**
|
||||
* Takes a binary pubkey and signature to create a signature object
|
||||
@ -12,3 +13,4 @@ export declare function decodeSignature(
|
||||
readonly pubkey: Uint8Array;
|
||||
readonly signature: Uint8Array;
|
||||
};
|
||||
export declare function makeSecp256k1SignatureFromFixedLength(signature: Uint8Array): Secp256k1Signature;
|
||||
|
Loading…
x
Reference in New Issue
Block a user