ton-crypto
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -74,3 +74,3 @@ "use strict"; | ||
}]; | ||
describe('keys', () => { | ||
describe('ed25519', () => { | ||
// Root | ||
@@ -77,0 +77,0 @@ for (let v of testVectors) { |
@@ -16,1 +16,2 @@ export { sha256, sha256_sync } from './primitives/sha256'; | ||
export { getSymmetricMasterKeyFromSeed, deriveSymmetricHardenedKey, deriveSymmetricPath } from './hd/symmetric'; | ||
export { deriveMnemonicsPath, deriveMnemonicHardenedKey, getMnemonicsMasterKeyFromSeed } from './hd/mnemonics'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deriveSymmetricPath = exports.deriveSymmetricHardenedKey = exports.getSymmetricMasterKeyFromSeed = exports.deriveEd25519Path = exports.deriveED25519HardenedKey = exports.getED25519MasterKeyFromSeed = exports.signVerify = exports.sign = exports.keyPairFromSecretKey = exports.keyPairFromSeed = exports.openBox = exports.sealBox = exports.mnemonicWordList = exports.mnemonicToHDSeed = exports.mnemonicToSeed = exports.mnemonicToWalletKey = exports.mnemonicToPrivateKey = exports.mnemonicValidate = exports.mnemonicNew = exports.newSecurePassphrase = exports.newSecureWords = exports.getSecureRandomNumber = exports.getSecureRandomWords = exports.getSecureRandomBytes = exports.hmac_sha512 = exports.pbkdf2_sha512 = exports.sha512_sync = exports.sha512 = exports.sha256_sync = exports.sha256 = void 0; | ||
exports.getMnemonicsMasterKeyFromSeed = exports.deriveMnemonicHardenedKey = exports.deriveMnemonicsPath = exports.deriveSymmetricPath = exports.deriveSymmetricHardenedKey = exports.getSymmetricMasterKeyFromSeed = exports.deriveEd25519Path = exports.deriveED25519HardenedKey = exports.getED25519MasterKeyFromSeed = exports.signVerify = exports.sign = exports.keyPairFromSecretKey = exports.keyPairFromSeed = exports.openBox = exports.sealBox = exports.mnemonicWordList = exports.mnemonicToHDSeed = exports.mnemonicToSeed = exports.mnemonicToWalletKey = exports.mnemonicToPrivateKey = exports.mnemonicValidate = exports.mnemonicNew = exports.newSecurePassphrase = exports.newSecureWords = exports.getSecureRandomNumber = exports.getSecureRandomWords = exports.getSecureRandomBytes = exports.hmac_sha512 = exports.pbkdf2_sha512 = exports.sha512_sync = exports.sha512 = exports.sha256_sync = exports.sha256 = void 0; | ||
var sha256_1 = require("./primitives/sha256"); | ||
@@ -47,1 +47,5 @@ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return sha256_1.sha256; } }); | ||
Object.defineProperty(exports, "deriveSymmetricPath", { enumerable: true, get: function () { return symmetric_1.deriveSymmetricPath; } }); | ||
var mnemonics_1 = require("./hd/mnemonics"); | ||
Object.defineProperty(exports, "deriveMnemonicsPath", { enumerable: true, get: function () { return mnemonics_1.deriveMnemonicsPath; } }); | ||
Object.defineProperty(exports, "deriveMnemonicHardenedKey", { enumerable: true, get: function () { return mnemonics_1.deriveMnemonicHardenedKey; } }); | ||
Object.defineProperty(exports, "getMnemonicsMasterKeyFromSeed", { enumerable: true, get: function () { return mnemonics_1.getMnemonicsMasterKeyFromSeed; } }); |
@@ -40,1 +40,21 @@ /// <reference types="node" /> | ||
export declare function mnemonicNew(wordsCount?: number, password?: string | null | undefined): Promise<string[]>; | ||
/** | ||
* Converts bytes to mnemonics array (could be invalid for TON) | ||
* @param src source buffer | ||
* @param wordsCount number of words | ||
*/ | ||
export declare function bytesToMnemonicIndexes(src: Buffer, wordsCount: number): number[]; | ||
export declare function bytesToMnemonics(src: Buffer, wordsCount: number): string[]; | ||
/** | ||
* Converts mnemonics indexes to buffer with zero padding in the end | ||
* @param src source indexes | ||
* @returns Buffer | ||
*/ | ||
export declare function mnemonicIndexesToBytes(src: number[]): Buffer; | ||
/** | ||
* Generates deterministically mnemonics | ||
* @param seed | ||
* @param wordsCount | ||
* @param password | ||
*/ | ||
export declare function mnemonicFromRandomSeed(seed: Buffer, wordsCount?: number, password?: string | null | undefined): Promise<string[]>; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mnemonicNew = exports.mnemonicValidate = exports.mnemonicToHDSeed = exports.mnemonicToWalletKey = exports.mnemonicToPrivateKey = exports.mnemonicToSeed = exports.mnemonicToEntropy = void 0; | ||
exports.mnemonicFromRandomSeed = exports.mnemonicIndexesToBytes = exports.bytesToMnemonics = exports.bytesToMnemonicIndexes = exports.mnemonicNew = exports.mnemonicValidate = exports.mnemonicToHDSeed = exports.mnemonicToWalletKey = exports.mnemonicToPrivateKey = exports.mnemonicToSeed = exports.mnemonicToEntropy = void 0; | ||
const tweetnacl_1 = __importDefault(require("tweetnacl")); | ||
@@ -12,2 +12,3 @@ const getSecureRandom_1 = require("../primitives/getSecureRandom"); | ||
const pbkdf2_sha512_1 = require("../primitives/pbkdf2_sha512"); | ||
const binary_1 = require("../utils/binary"); | ||
const wordlist_1 = require("./wordlist"); | ||
@@ -167,1 +168,69 @@ const PBKDF_ITERATIONS = 100000; | ||
exports.mnemonicNew = mnemonicNew; | ||
/** | ||
* Converts bytes to mnemonics array (could be invalid for TON) | ||
* @param src source buffer | ||
* @param wordsCount number of words | ||
*/ | ||
function bytesToMnemonicIndexes(src, wordsCount) { | ||
let bits = (0, binary_1.bytesToBits)(src); | ||
let indexes = []; | ||
for (let i = 0; i < wordsCount; i++) { | ||
let sl = bits.slice(i * 11, i * 11 + 11); | ||
indexes.push(parseInt(sl, 2)); | ||
} | ||
return indexes; | ||
} | ||
exports.bytesToMnemonicIndexes = bytesToMnemonicIndexes; | ||
function bytesToMnemonics(src, wordsCount) { | ||
let mnemonics = bytesToMnemonicIndexes(src, wordsCount); | ||
let res = []; | ||
for (let m of mnemonics) { | ||
res.push(wordlist_1.wordlist[m]); | ||
} | ||
return res; | ||
} | ||
exports.bytesToMnemonics = bytesToMnemonics; | ||
/** | ||
* Converts mnemonics indexes to buffer with zero padding in the end | ||
* @param src source indexes | ||
* @returns Buffer | ||
*/ | ||
function mnemonicIndexesToBytes(src) { | ||
let res = ''; | ||
for (let s of src) { | ||
if (!Number.isSafeInteger(s)) { | ||
throw Error('Invalid input'); | ||
} | ||
if (s < 0 || s >= 2028) { | ||
throw Error('Invalid input'); | ||
} | ||
res += (0, binary_1.lpad)(s.toString(2), '0', 11); | ||
} | ||
while (res.length % 8 !== 0) { | ||
res = res + '0'; | ||
} | ||
return (0, binary_1.bitsToBytes)(res); | ||
} | ||
exports.mnemonicIndexesToBytes = mnemonicIndexesToBytes; | ||
/** | ||
* Generates deterministically mnemonics | ||
* @param seed | ||
* @param wordsCount | ||
* @param password | ||
*/ | ||
async function mnemonicFromRandomSeed(seed, wordsCount = 24, password) { | ||
const bytesLength = Math.ceil(wordsCount * 11 / 8); | ||
let currentSeed = seed; | ||
while (true) { | ||
// Create entropy | ||
let entropy = await (0, pbkdf2_sha512_1.pbkdf2_sha512)(currentSeed, 'TON mnemonic seed', Math.max(1, Math.floor(PBKDF_ITERATIONS / 256)), bytesLength); | ||
// Create mnemonics | ||
let mnemonics = bytesToMnemonics(entropy, wordsCount); | ||
// Check if mnemonics are valid | ||
if (await mnemonicValidate(mnemonics, password)) { | ||
return mnemonics; | ||
} | ||
currentSeed = entropy; | ||
} | ||
} | ||
exports.mnemonicFromRandomSeed = mnemonicFromRandomSeed; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const getSecureRandom_1 = require("../primitives/getSecureRandom"); | ||
const mnemonic_1 = require("./mnemonic"); | ||
@@ -94,2 +95,5 @@ const testVectors = [ | ||
}); | ||
it('should generate mnemonics from random seed', async () => { | ||
await (0, mnemonic_1.mnemonicFromRandomSeed)(await (0, getSecureRandom_1.getSecureRandomBytes)(32)); | ||
}); | ||
}); |
{ | ||
"name": "ton-crypto", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"repository": "https://github.com/ex3ndr/ton-crypto.git", | ||
@@ -5,0 +5,0 @@ "author": "Steve Korshakov <steve@korshakov.com>", |
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
206770
59
9226
17260