mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-07-16 02:05:42 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export declare function ledgerDerivePrivate(xprv: Uint8Array, index: number): Uint8Array;
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ledgerDerivePrivate = ledgerDerivePrivate;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const bn_js_1 = require("../../bn.js");
|
||||
const index_js_1 = require("../../hmac/index.js");
|
||||
function ledgerDerivePrivate(xprv, index) {
|
||||
const kl = xprv.subarray(0, 32);
|
||||
const kr = xprv.subarray(32, 64);
|
||||
const cc = xprv.subarray(64, 96);
|
||||
const data = (0, util_1.u8aConcat)([0], kl, kr, (0, util_1.bnToU8a)(index, bn_js_1.BN_LE_32_OPTS));
|
||||
const z = (0, index_js_1.hmacShaAsU8a)(cc, data, 512);
|
||||
data[0] = 0x01;
|
||||
return (0, util_1.u8aConcat)((0, util_1.bnToU8a)((0, util_1.u8aToBn)(kl, bn_js_1.BN_LE_OPTS).iadd((0, util_1.u8aToBn)(z.subarray(0, 28), bn_js_1.BN_LE_OPTS).imul(util_1.BN_EIGHT)), bn_js_1.BN_LE_512_OPTS).subarray(0, 32), (0, util_1.bnToU8a)((0, util_1.u8aToBn)(kr, bn_js_1.BN_LE_OPTS).iadd((0, util_1.u8aToBn)(z.subarray(32, 64), bn_js_1.BN_LE_OPTS)), bn_js_1.BN_LE_512_OPTS).subarray(0, 32), (0, index_js_1.hmacShaAsU8a)(cc, data, 512).subarray(32, 64));
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { Keypair } from '../../types.js';
|
||||
export declare function hdLedger(_mnemonic: string, path: string): Keypair;
|
||||
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hdLedger = hdLedger;
|
||||
const index_js_1 = require("../../ed25519/index.js");
|
||||
const index_js_2 = require("../../mnemonic/index.js");
|
||||
const validatePath_js_1 = require("../validatePath.js");
|
||||
const derivePrivate_js_1 = require("./derivePrivate.js");
|
||||
const master_js_1 = require("./master.js");
|
||||
function hdLedger(_mnemonic, path) {
|
||||
const words = _mnemonic
|
||||
.split(' ')
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s);
|
||||
if (![12, 24, 25].includes(words.length)) {
|
||||
throw new Error('Expected a mnemonic with 24 words (or 25 including a password)');
|
||||
}
|
||||
const [mnemonic, password] = words.length === 25
|
||||
? [words.slice(0, 24).join(' '), words[24]]
|
||||
: [words.join(' '), ''];
|
||||
if (!(0, index_js_2.mnemonicValidate)(mnemonic)) {
|
||||
throw new Error('Invalid mnemonic passed to ledger derivation');
|
||||
}
|
||||
else if (!(0, validatePath_js_1.hdValidatePath)(path)) {
|
||||
throw new Error('Invalid derivation path');
|
||||
}
|
||||
const parts = path.split('/').slice(1);
|
||||
let seed = (0, master_js_1.ledgerMaster)(mnemonic, password);
|
||||
for (const p of parts) {
|
||||
const n = parseInt(p.replace(/'$/, ''), 10);
|
||||
seed = (0, derivePrivate_js_1.ledgerDerivePrivate)(seed, (n < validatePath_js_1.HARDENED) ? (n + validatePath_js_1.HARDENED) : n);
|
||||
}
|
||||
return (0, index_js_1.ed25519PairFromSeed)(seed.slice(0, 32));
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export declare function ledgerMaster(mnemonic: string, password?: string): Uint8Array;
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ledgerMaster = ledgerMaster;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const index_js_1 = require("../../hmac/index.js");
|
||||
const bip39_js_1 = require("../../mnemonic/bip39.js");
|
||||
const ED25519_CRYPTO = 'ed25519 seed';
|
||||
function ledgerMaster(mnemonic, password) {
|
||||
const seed = (0, bip39_js_1.mnemonicToSeedSync)(mnemonic, password);
|
||||
const chainCode = (0, index_js_1.hmacShaAsU8a)(ED25519_CRYPTO, new Uint8Array([1, ...seed]), 256);
|
||||
let priv;
|
||||
while (!priv || (priv[31] & 0b0010_0000)) {
|
||||
priv = (0, index_js_1.hmacShaAsU8a)(ED25519_CRYPTO, priv || seed, 512);
|
||||
}
|
||||
priv[0] &= 0b1111_1000;
|
||||
priv[31] &= 0b0111_1111;
|
||||
priv[31] |= 0b0100_0000;
|
||||
return (0, util_1.u8aConcat)(priv, chainCode);
|
||||
}
|
||||
Reference in New Issue
Block a user