@iov/crypto
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -11,3 +11,3 @@ "use strict"; | ||
__export(require("./sha")); | ||
__export(require("./slip0010")); | ||
__export(require("./slip10")); | ||
//# sourceMappingURL=index.js.map |
@@ -11,2 +11,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const encoding_1 = require("@iov/encoding"); | ||
const BN = require("bn.js"); | ||
@@ -32,4 +33,4 @@ const elliptic = require("elliptic"); | ||
return { | ||
privkey: keypair.getPrivate(), | ||
pubkey: keypair.getPublic(), | ||
privkey: encoding_1.Encoding.fromHex(keypair.getPrivate("hex")), | ||
pubkey: encoding_1.Encoding.fromHex(keypair.getPublic().encodeCompressed("hex")), | ||
}; | ||
@@ -36,0 +37,0 @@ }); |
@@ -17,2 +17,19 @@ "use strict"; | ||
describe("Secp256k1", () => { | ||
it("encodes public key compressed when making a keypair", () => __awaiter(this, void 0, void 0, function* () { | ||
{ | ||
const privkey = fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f"); | ||
const keypair = yield secp256k1_1.Secp256k1.makeKeypair(privkey); | ||
expect(keypair.pubkey).toEqual(fromHex("029afc96432dc180b63f5219db853399d30cd771851babfd3564eb3d2006fdbe4b")); | ||
} | ||
{ | ||
const privkey = fromHex("8e223cf766a094585ea2a44c189fc43579de01449d74ca1f0d96c5c96edd30b7"); | ||
const keypair = yield secp256k1_1.Secp256k1.makeKeypair(privkey); | ||
expect(keypair.pubkey).toEqual(fromHex("03a47673c3f766217d5fc1655531ca590e7264ae6f17f3923c2e985a00825fa7a7")); | ||
} | ||
})); | ||
it("preserves private key when making a keypair", () => __awaiter(this, void 0, void 0, function* () { | ||
const privkey = fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f"); | ||
const keypair = yield secp256k1_1.Secp256k1.makeKeypair(privkey); | ||
expect(keypair.privkey).toEqual(fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f")); | ||
})); | ||
it("can load private keys", () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -19,0 +36,0 @@ expect(yield secp256k1_1.Secp256k1.makeKeypair(fromHex("5eaf4344dab73d0caee1fd03607bb969074fb217f076896c2125f8607feab7b1"))).toBeTruthy(); |
{ | ||
"name": "@iov/crypto", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Cryptography resources for IOV projects", | ||
@@ -32,3 +32,3 @@ "author": "IOV SAS <admin@iov.one>", | ||
"dependencies": { | ||
"@iov/encoding": "^0.4.0", | ||
"@iov/encoding": "^0.5.0", | ||
"bip39": "^2.5.0", | ||
@@ -46,3 +46,3 @@ "bn.js": "^4.11.8", | ||
}, | ||
"gitHead": "a4a364471ba4890fb6343a514a91bfe0aa45448e" | ||
"gitHead": "39379b38f0ac128a48aa7174692c4c932ed326f7" | ||
} |
@@ -6,2 +6,2 @@ export * from "./bip39"; | ||
export * from "./sha"; | ||
export * from "./slip0010"; | ||
export * from "./slip10"; |
@@ -24,2 +24,25 @@ /* tslint:disable:no-bitwise */ | ||
it("encodes public key compressed when making a keypair", async () => { | ||
// example data generated by OpenSSL: | ||
// openssl ecparam -name secp256k1 -genkey -out - | openssl ec -in - -text -noout -conv_form compressed | ||
{ | ||
// pubkey with 0x02 prefix (value less than the midpoint of the curve) | ||
const privkey = fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f"); | ||
const keypair = await Secp256k1.makeKeypair(privkey); | ||
expect(keypair.pubkey).toEqual(fromHex("029afc96432dc180b63f5219db853399d30cd771851babfd3564eb3d2006fdbe4b")); | ||
} | ||
{ | ||
// pubkey with 0x03 prefix (value greater than the midpoint of the curve) | ||
const privkey = fromHex("8e223cf766a094585ea2a44c189fc43579de01449d74ca1f0d96c5c96edd30b7"); | ||
const keypair = await Secp256k1.makeKeypair(privkey); | ||
expect(keypair.pubkey).toEqual(fromHex("03a47673c3f766217d5fc1655531ca590e7264ae6f17f3923c2e985a00825fa7a7")); | ||
} | ||
}); | ||
it("preserves private key when making a keypair", async () => { | ||
const privkey = fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f"); | ||
const keypair = await Secp256k1.makeKeypair(privkey); | ||
expect(keypair.privkey).toEqual(fromHex("8c8bc2bc7954db5ef751e3e84b4e99bbe387a90d8019d8066c0e1e8bf33e713f")); | ||
}); | ||
it("can load private keys", async () => { | ||
@@ -26,0 +49,0 @@ expect(await Secp256k1.makeKeypair(fromHex("5eaf4344dab73d0caee1fd03607bb969074fb217f076896c2125f8607feab7b1"))).toBeTruthy(); |
@@ -0,1 +1,3 @@ | ||
import { Encoding } from "@iov/encoding"; | ||
import BN = require("bn.js"); | ||
@@ -37,4 +39,4 @@ import elliptic = require("elliptic"); | ||
return { | ||
privkey: keypair.getPrivate(), | ||
pubkey: keypair.getPublic(), | ||
privkey: Encoding.fromHex(keypair.getPrivate("hex")), | ||
pubkey: Encoding.fromHex(keypair.getPublic().encodeCompressed("hex")), | ||
} as Secp256k1Keypair; | ||
@@ -41,0 +43,0 @@ } |
@@ -6,2 +6,2 @@ export * from "./bip39"; | ||
export * from "./sha"; | ||
export * from "./slip0010"; | ||
export * from "./slip10"; |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
715359
63
5534
1
+ Added@iov/encoding@0.5.3(transitive)
- Removed@iov/encoding@0.4.0(transitive)
Updated@iov/encoding@^0.5.0