@iov/crypto
Advanced tools
Comparing version 0.12.1 to 0.12.2
@@ -94,4 +94,10 @@ "use strict"; | ||
} | ||
static recoverPubkey(signature, messageHash) { | ||
const signatureForElliptic = { r: encoding_1.Encoding.toHex(signature.r()), s: encoding_1.Encoding.toHex(signature.s()) }; | ||
const point = secp256k1.recoverPubKey(messageHash, signatureForElliptic, signature.recovery); | ||
const keypair = secp256k1.keyFromPublic(point); | ||
return encoding_1.Encoding.fromHex(keypair.getPublic(false, "hex")); | ||
} | ||
} | ||
exports.Secp256k1 = Secp256k1; | ||
//# sourceMappingURL=secp256k1.js.map |
@@ -335,3 +335,27 @@ "use strict"; | ||
})); | ||
describe("recoverPubkey", () => { | ||
it("can recover pubkey", () => __awaiter(this, void 0, void 0, function* () { | ||
{ | ||
// Test data from https://github.com/ethereumjs/ethereumjs-util/blob/v6.1.0/test/index.js#L496 | ||
const expectedPubkey = (yield secp256k1_1.Secp256k1.makeKeypair(fromHex("3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1"))).pubkey; | ||
const signature = new secp256k1signature_1.ExtendedSecp256k1Signature(fromHex("99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9"), fromHex("129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66"), 0); | ||
const messageHash = fromHex("82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28"); | ||
const pubkey = secp256k1_1.Secp256k1.recoverPubkey(signature, messageHash); | ||
expect(pubkey).toEqual(expectedPubkey); | ||
} | ||
{ | ||
// Test data from https://github.com/randombit/botan/blob/2.9.0/src/tests/data/pubkey/ecdsa_key_recovery.vec | ||
const expectedPubkeyX = "F3F8BB913AA68589A2C8C607A877AB05252ADBD963E1BE846DDEB8456942AEDC"; | ||
const expectedPubkeyY = "A2ED51F08CA3EF3DAC0A7504613D54CD539FC1B3CBC92453CD704B6A2D012B2C"; | ||
const expectedPubkey = fromHex(`04${expectedPubkeyX}${expectedPubkeyY}`); | ||
const r = fromHex("E30F2E6A0F705F4FB5F8501BA79C7C0D3FAC847F1AD70B873E9797B17B89B390"); | ||
const s = fromHex("81F1A4457589F30D76AB9F89E748A68C8A94C30FE0BAC8FB5C0B54EA70BF6D2F"); | ||
const signature = new secp256k1signature_1.ExtendedSecp256k1Signature(r, s, 0); | ||
const messageHash = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | ||
const pubkey = secp256k1_1.Secp256k1.recoverPubkey(signature, messageHash); | ||
expect(pubkey).toEqual(expectedPubkey); | ||
} | ||
})); | ||
}); | ||
}); | ||
//# sourceMappingURL=secp256k1.spec.js.map |
{ | ||
"name": "@iov/crypto", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"description": "Cryptography resources for IOV projects", | ||
@@ -47,3 +47,3 @@ "author": "IOV SAS <admin@iov.one>", | ||
}, | ||
"gitHead": "1d5c5437bf89ab7e9219515488524f2f467f2ca9" | ||
"gitHead": "31d50f38de85345fd027f0a0acb4065ee48012cf" | ||
} |
@@ -7,3 +7,3 @@ /* tslint:disable:no-bitwise */ | ||
import { Secp256k1 } from "./secp256k1"; | ||
import { Secp256k1Signature } from "./secp256k1signature"; | ||
import { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature"; | ||
import { Sha256 } from "./sha"; | ||
@@ -355,2 +355,27 @@ | ||
}); | ||
describe("recoverPubkey", () => { | ||
it("can recover pubkey", async () => { | ||
{ | ||
// Test data from https://github.com/ethereumjs/ethereumjs-util/blob/v6.1.0/test/index.js#L496 | ||
const expectedPubkey = (await Secp256k1.makeKeypair(fromHex("3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1"))).pubkey; | ||
const signature = new ExtendedSecp256k1Signature(fromHex("99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9"), fromHex("129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66"), 0); | ||
const messageHash = fromHex("82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28"); | ||
const pubkey = Secp256k1.recoverPubkey(signature, messageHash); | ||
expect(pubkey).toEqual(expectedPubkey); | ||
} | ||
{ | ||
// Test data from https://github.com/randombit/botan/blob/2.9.0/src/tests/data/pubkey/ecdsa_key_recovery.vec | ||
const expectedPubkeyX = "F3F8BB913AA68589A2C8C607A877AB05252ADBD963E1BE846DDEB8456942AEDC"; | ||
const expectedPubkeyY = "A2ED51F08CA3EF3DAC0A7504613D54CD539FC1B3CBC92453CD704B6A2D012B2C"; | ||
const expectedPubkey = fromHex(`04${expectedPubkeyX}${expectedPubkeyY}`); | ||
const r = fromHex("E30F2E6A0F705F4FB5F8501BA79C7C0D3FAC847F1AD70B873E9797B17B89B390"); | ||
const s = fromHex("81F1A4457589F30D76AB9F89E748A68C8A94C30FE0BAC8FB5C0B54EA70BF6D2F"); | ||
const signature = new ExtendedSecp256k1Signature(r, s, 0); | ||
const messageHash = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | ||
const pubkey = Secp256k1.recoverPubkey(signature, messageHash); | ||
expect(pubkey).toEqual(expectedPubkey); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -106,2 +106,9 @@ import { Encoding } from "@iov/encoding"; | ||
} | ||
public static recoverPubkey(signature: ExtendedSecp256k1Signature, messageHash: Uint8Array): Uint8Array { | ||
const signatureForElliptic = { r: Encoding.toHex(signature.r()), s: Encoding.toHex(signature.s()) }; | ||
const point = secp256k1.recoverPubKey(messageHash, signatureForElliptic, signature.recovery); | ||
const keypair = secp256k1.keyFromPublic(point); | ||
return Encoding.fromHex(keypair.getPublic(false, "hex")); | ||
} | ||
} |
@@ -11,2 +11,3 @@ import { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature"; | ||
static verifySignature(signature: Secp256k1Signature, messageHash: Uint8Array, pubkey: Uint8Array): Promise<boolean>; | ||
static recoverPubkey(signature: ExtendedSecp256k1Signature, messageHash: Uint8Array): Uint8Array; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1090590
7536