@berrywallet/core
Version:
Berrywallet main Core for work with common cryptocurrencies like Bitcoin, Ethereum, Dash, Litecoin
55 lines (54 loc) • 1.97 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}
Object.defineProperty(exports, "__esModule", { value: true });
const Coin = __importStar(require("./"));
const HD = __importStar(require("../hd"));
class BasicNode {
constructor(node, coin) {
this.node = node;
this.coin = coin;
}
getNode() {
return this.node;
}
getCoin() {
return this.coin;
}
derive(index, hardened) {
return new BasicNode(this.getNode().derive(index, hardened), this.getCoin());
}
derivePath(path) {
return new BasicNode(this.getNode().derivePath(path), this.getCoin());
}
getPublicKey() {
return new Coin.Key.Public(this.getNode().getPublicKey(), this.getCoin().getKeyFormat());
}
getPrivateKey() {
return new Coin.Key.Private(this.getNode().getPrivateKey(), this.getCoin().getKeyFormat());
}
}
exports.BasicNode = BasicNode;
class BasicMasterNode extends BasicNode {
constructor() {
super(...arguments);
this.accountNodeCache = {};
}
deriveAddress(addressType = HD.BIP44.AddressType.RECEIVE, index = 0, accountIndex = 0) {
if (!(accountIndex in this.accountNodeCache)) {
let accountPath = HD.BIP44.getAccountHDPath(this.getCoin().getHDCoinType(), accountIndex);
this.accountNodeCache[accountIndex] = this.derivePath(accountPath);
}
let derivePath = HD.BIP44.getHDPathFromAccount(addressType, index);
return this.accountNodeCache[accountIndex].derivePath(derivePath);
}
static fromSeedBuffer(seed, coin) {
return new BasicMasterNode(HD.Node.BasicNode.fromSeedBuffer(seed), coin);
}
}
exports.BasicMasterNode = BasicMasterNode;