@okxweb3/coin-stellar
Version:
@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers
33 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScInt = void 0;
const xdr_large_int_1 = require("./xdr_large_int");
class ScInt extends xdr_large_int_1.XdrLargeInt {
constructor(value, opts) {
const signed = value < 0;
let type = opts?.type ?? '';
if (type.startsWith('u') && signed) {
throw TypeError(`specified type ${opts.type} yet negative (${value})`);
}
if (type === '') {
type = signed ? 'i' : 'u';
const bitlen = nearestBigIntSize(value);
switch (bitlen) {
case 64:
case 128:
case 256:
type += bitlen.toString();
break;
default:
throw RangeError(`expected 64/128/256 bits for input (${value}), got ${bitlen}`);
}
}
super(type, value);
}
}
exports.ScInt = ScInt;
function nearestBigIntSize(bigI) {
const bitlen = bigI.toString(2).length;
return [64, 128, 256].find((len) => bitlen <= len) ?? bitlen;
}
//# sourceMappingURL=sc_int.js.map