@taquito/signer
Version:
Provide signing functionality to be with taquito
43 lines (42 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Path = exports.Hard = exports.Ed25519 = exports.ECDSA = void 0;
const core_1 = require("@taquito/core");
exports.ECDSA = require("./ecdsa");
exports.Ed25519 = require("./ed25519");
exports.Hard = 0x80000000;
class Path extends Array {
static from(iterable) {
return super.from(iterable).map((x) => x >>> 0);
}
/**
*
* @param s derivation path eg: 44'/1729'/0'/0'
* @returns applied hardened values
*/
static fromString(s) {
if (s.length === 0) {
return new Path();
}
let parts = s.split('/');
const out = [];
if (parts[0] === 'm') {
parts = parts.slice(1);
}
for (let p of parts) {
if (p.length === 0) {
throw new core_1.InvalidDerivationPathError(s, `: Invalid BIP32 path`);
}
let h = 0;
const last = p[p.length - 1];
if (last === "'" || last === 'h' || last === 'H') {
h = exports.Hard;
p = p.slice(0, p.length - 1);
}
const index = (parseInt(p, 10) | h) >>> 0;
out.push(index);
}
return Path.from(out);
}
}
exports.Path = Path;