@yuants/utils
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -22,4 +22,14 @@ import bs58 from 'bs58'; | ||
export const fromPrivateKey = (privateKey) => { | ||
const pair = sign.keyPair.fromSecretKey(bs58.decode(privateKey)); | ||
return { public_key: bs58.encode(pair.publicKey), private_key: privateKey }; | ||
const buffer = bs58.decode(privateKey); | ||
if (buffer.length !== 64) { | ||
throw new Error('Invalid private key: wrong size'); | ||
} | ||
const seed = buffer.slice(0, 32); | ||
const pair = sign.keyPair.fromSeed(seed); | ||
const public_key = bs58.encode(pair.publicKey); | ||
const the_public_key = bs58.encode(buffer.slice(32, 64)); | ||
if (public_key !== the_public_key) { | ||
throw new Error(`Invalid private key: public key mismatch: expected ${public_key}, got ${the_public_key}`); | ||
} | ||
return { public_key, private_key: privateKey }; | ||
}; | ||
@@ -26,0 +36,0 @@ /** |
@@ -29,4 +29,14 @@ "use strict"; | ||
const fromPrivateKey = (privateKey) => { | ||
const pair = tweetnacl_1.sign.keyPair.fromSecretKey(bs58_1.default.decode(privateKey)); | ||
return { public_key: bs58_1.default.encode(pair.publicKey), private_key: privateKey }; | ||
const buffer = bs58_1.default.decode(privateKey); | ||
if (buffer.length !== 64) { | ||
throw new Error('Invalid private key: wrong size'); | ||
} | ||
const seed = buffer.slice(0, 32); | ||
const pair = tweetnacl_1.sign.keyPair.fromSeed(seed); | ||
const public_key = bs58_1.default.encode(pair.publicKey); | ||
const the_public_key = bs58_1.default.encode(buffer.slice(32, 64)); | ||
if (public_key !== the_public_key) { | ||
throw new Error(`Invalid private key: public key mismatch: expected ${public_key}, got ${the_public_key}`); | ||
} | ||
return { public_key, private_key: privateKey }; | ||
}; | ||
@@ -33,0 +43,0 @@ exports.fromPrivateKey = fromPrivateKey; |
{ | ||
"name": "@yuants/utils", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.js", |
{ | ||
"libraries/utils/CHANGELOG.json": "d8e2168bd5f988e32a55055a2656b2e2094074d4", | ||
"libraries/utils/CHANGELOG.md": "8e4159ee6ec54bbe070aafb20e45ca3a7e717d45", | ||
"libraries/utils/CHANGELOG.json": "34ab68f0435cbbd6bb79e7e7c477a5389f9112a6", | ||
"libraries/utils/CHANGELOG.md": "38450c0a9470167ccdb9be7517c4e977d958efd2", | ||
"libraries/utils/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c", | ||
@@ -9,6 +9,6 @@ "libraries/utils/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd", | ||
"libraries/utils/etc/utils.api.md": "237b97b46b05e3f335a0d87a38964fc0ab1277d5", | ||
"libraries/utils/package.json": "fbf6eb19e483ea18475b1d31346cda5645e898fa", | ||
"libraries/utils/package.json": "0f94fec16c6b6eb2dca78932b2b240abcf9528ce", | ||
"libraries/utils/src/async-iterator-interop.test.ts": "ec6e2470d1ace812d5fac14450a2568ff8a4dfd5", | ||
"libraries/utils/src/async-iterator-interop.ts": "8dbb6150c1d75ed4d5c11be6fec6290fd8c0a561", | ||
"libraries/utils/src/crypto.ts": "bf43e1f195c554c2e324ec171c8acbf075f7b417", | ||
"libraries/utils/src/crypto.ts": "608e80e543ec20c1ee1db17861879d253c0c744a", | ||
"libraries/utils/src/index.ts": "72bc55afb3398495923a188333996788753db7f5", | ||
@@ -15,0 +15,0 @@ "libraries/utils/src/order-utils.ts": "e0340bdfd925c6a1943871f37638947657dd0e4c", |
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
187932
2785