chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
70 lines • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Seed = exports.SeedEncodingError = void 0;
const bip32_1 = require("@scure/bip32");
const Secret_1 = require("../Secret");
const Utils_1 = require("../../../../Utils/Utils");
const ExtendedPublicKey_1 = require("./ExtendedPublicKey");
const ExtendedPrivateKey_1 = require("./ExtendedPrivateKey");
const PublicKey_1 = require("../../PublicKey");
const PrivateKey_1 = require("./PrivateKey");
class SeedEncodingError extends Error {
constructor(message) {
super(message);
if (Error.captureStackTrace)
Error.captureStackTrace(this, SeedEncodingError);
this.name = this.constructor.name;
}
}
exports.SeedEncodingError = SeedEncodingError;
class Seed extends Secret_1.Secret {
seed;
get raw() {
return this.seed;
}
async getExtendedPublicKey(derivationPath) {
const publicKey = derivationPath ?
bip32_1.HDKey.fromMasterSeed(this.raw).derive(derivationPath) :
bip32_1.HDKey.fromMasterSeed(this.raw);
return new ExtendedPublicKey_1.ExtendedPublicKey(publicKey.publicExtendedKey);
}
async getExtendedPrivateKey(derivationPath) {
const privateKey = derivationPath ?
bip32_1.HDKey.fromMasterSeed(this.raw).derive(derivationPath) :
bip32_1.HDKey.fromMasterSeed(this.raw);
return new ExtendedPrivateKey_1.ExtendedPrivateKey(privateKey.privateExtendedKey);
}
async getPublicKey(derivationPath) {
const publicKey = derivationPath ?
bip32_1.HDKey.fromMasterSeed(this.raw).derive(derivationPath) :
bip32_1.HDKey.fromMasterSeed(this.raw);
return new PublicKey_1.PublicKey(publicKey.publicKey);
}
async getPrivateKey(derivationPath) {
const privateKey = derivationPath ?
bip32_1.HDKey.fromMasterSeed(this.raw).derive(derivationPath) :
bip32_1.HDKey.fromMasterSeed(this.raw);
return new PrivateKey_1.PrivateKey(privateKey.privateKey);
}
async getMasterPublicKey() {
const publicKey = bip32_1.HDKey.fromMasterSeed(this.raw);
return new ExtendedPublicKey_1.ExtendedPublicKey(publicKey.publicExtendedKey);
}
async getMasterPrivateKey() {
const privateKey = bip32_1.HDKey.fromMasterSeed(this.raw);
return new ExtendedPrivateKey_1.ExtendedPrivateKey(privateKey.privateExtendedKey);
}
constructor(source) {
super();
if (source instanceof Uint8Array)
this.seed = source;
else {
if ((0, Utils_1.isHex)(source))
this.seed = (0, Utils_1.hexToBytes)(source);
else
throw new SeedEncodingError('The string supplied is deemed to be invalid');
}
}
}
exports.Seed = Seed;
//# sourceMappingURL=Seed.js.map