@ledgerhq/hw-app-starknet
Version:
Ledger Hardware Wallet Starknet Application API
37 lines (36 loc) • 1.13 kB
JavaScript
import s from "./_virtual/bn.js";
import { encode as u } from "starknet";
const f = 2147483648;
function m(e) {
if (!e.startsWith("m/2645"))
throw new Error(
"Path should start with 'm/2645' (e.g 'm/2645'/1195502025'/1148870696'/0'/0'/0')"
);
const i = e.split("/"), a = new Uint8Array((i.length - 1) * 4), l = new DataView(a.buffer);
for (let r = 1; r < i.length; r += 1) {
let n = 0, t = i[r];
t.endsWith("'") && (n += f, t = t.slice(0, -1));
const o = Number(t);
if (Number.isNaN(o))
throw new Error(`Invalid path : ${t} is not a number.`);
if (o >= f)
throw new Error("Incorrect child value (bigger or equal to 0x80000000)");
n += o, l.setUint32(4 * (r - 1), n);
}
return a;
}
function h(e) {
return /^0x[0-9a-f]*$/i.test(e);
}
function p(e) {
if (typeof e == "bigint" || typeof e == "number")
return new s(e.toString());
if (typeof e == "string")
return e = e.toLowerCase(), h(e) ? new s(u.removeHexPrefix(e), "hex") : new s(e);
throw new Error("Invalid input type for sanitizeHexBN");
}
export {
h as isHex,
m as serializePath,
p as toBN
};