Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardano-sdk/core

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-sdk/core - npm Package Compare versions

Comparing version 0.5.0-nightly.3 to 0.5.0-nightly.4

4

dist/cjs/Provider/NetworkInfoProvider/types.d.ts

@@ -1,2 +0,2 @@

import { Cardano, Provider, TimeSettings } from '../..';
import { Cardano, EraSummary, Provider } from '../..';
export declare type ProtocolParametersRequiredByWallet = Required<Pick<Cardano.ProtocolParametersBabbage, 'coinsPerUtxoByte' | 'maxTxSize' | 'maxValueSize' | 'stakeKeyDeposit' | 'maxCollateralInputs' | 'minFeeCoefficient' | 'minFeeConstant' | 'minPoolCost' | 'poolDeposit' | 'protocolVersion'>>;

@@ -17,4 +17,4 @@ export declare type SupplySummary = {

stake(): Promise<StakeSummary>;
timeSettings(): Promise<TimeSettings[]>;
eraSummaries(): Promise<EraSummary[]>;
}
//# sourceMappingURL=types.d.ts.map
import { CardanoNetworkMagic, Epoch, Slot } from '../Cardano';
import { CustomError } from 'ts-custom-error';
export interface TimeSettings {
fromSlotDate: Date;
fromSlotNo: number;
slotLength: number;
epochLength: number;
}
import { EraSummary } from '../CardanoNode';
export interface SlotDate {

@@ -18,13 +13,13 @@ slot: Slot;

}
export declare class TimeSettingsError extends CustomError {
export declare class EraSummaryError extends CustomError {
}
export declare const mainnetTimeSettings: TimeSettings[];
export declare const testnetTimeSettings: TimeSettings[];
export declare type TimeSettingsMap = {
[key in CardanoNetworkMagic]: TimeSettings[];
export declare const mainnetEraSummaries: EraSummary[];
export declare const testnetEraSummaries: EraSummary[];
export declare type EraSummariesMap = {
[key in CardanoNetworkMagic]: EraSummary[];
};
export declare const timeSettingsConfig: TimeSettingsMap;
export declare const createSlotEpochCalc: (timeSettings: TimeSettings[]) => (slotNo: Slot) => Epoch;
export declare const createSlotTimeCalc: (timeSettings: TimeSettings[]) => (slotNo: Slot) => Date;
export declare const createSlotEpochInfoCalc: (timeSettings: TimeSettings[]) => (slot: Slot) => EpochInfo;
export declare const eraSummariesConfig: EraSummariesMap;
export declare const createSlotEpochCalc: (eraSummaries: EraSummary[]) => (slotNo: Slot) => Epoch;
export declare const createSlotTimeCalc: (eraSummaries: EraSummary[]) => (slotNo: Slot) => Date;
export declare const createSlotEpochInfoCalc: (eraSummaries: EraSummary[]) => (slot: Slot) => EpochInfo;
export declare type SlotTimeCalc = ReturnType<typeof createSlotTimeCalc>;

@@ -31,0 +26,0 @@ export declare type SlotEpochCalc = ReturnType<typeof createSlotEpochCalc>;

@@ -6,63 +6,71 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createSlotEpochInfoCalc = exports.createSlotTimeCalc = exports.createSlotEpochCalc = exports.timeSettingsConfig = exports.testnetTimeSettings = exports.mainnetTimeSettings = exports.TimeSettingsError = void 0;
exports.createSlotEpochInfoCalc = exports.createSlotTimeCalc = exports.createSlotEpochCalc = exports.eraSummariesConfig = exports.testnetEraSummaries = exports.mainnetEraSummaries = exports.EraSummaryError = void 0;
const Cardano_1 = require("../Cardano");
const ts_custom_error_1 = require("ts-custom-error");
const orderBy_1 = __importDefault(require("lodash/orderBy"));
class TimeSettingsError extends ts_custom_error_1.CustomError {
class EraSummaryError extends ts_custom_error_1.CustomError {
}
exports.TimeSettingsError = TimeSettingsError;
exports.mainnetTimeSettings = [
{ epochLength: 21600, fromSlotDate: new Date(1506192291000), fromSlotNo: 0, slotLength: 20000 },
{ epochLength: 432000, fromSlotDate: new Date(1596059091000), fromSlotNo: 4492800, slotLength: 1000 }
exports.EraSummaryError = EraSummaryError;
exports.mainnetEraSummaries = [
{ parameters: { epochLength: 21600, slotLength: 20000 }, start: { slot: 0, time: new Date(1506192291000) } },
{
parameters: { epochLength: 432000, slotLength: 1000 },
start: { slot: 4492800, time: new Date(1596059091000) }
}
];
exports.testnetTimeSettings = [
{ epochLength: 21600, fromSlotDate: new Date(1563999616000), fromSlotNo: 0, slotLength: 20000 },
{ epochLength: 432000, fromSlotDate: new Date(1595964016000), fromSlotNo: 1598400, slotLength: 1000 }
exports.testnetEraSummaries = [
{ parameters: { epochLength: 21600, slotLength: 20000 }, start: { slot: 0, time: new Date(1563999616000) } },
{
parameters: { epochLength: 432000, slotLength: 1000 },
start: { slot: 1598400, time: new Date(1595964016000) }
}
];
exports.timeSettingsConfig = {
[Cardano_1.CardanoNetworkMagic.Mainnet]: exports.mainnetTimeSettings,
[Cardano_1.CardanoNetworkMagic.Testnet]: exports.testnetTimeSettings
exports.eraSummariesConfig = {
[Cardano_1.CardanoNetworkMagic.Mainnet]: exports.mainnetEraSummaries,
[Cardano_1.CardanoNetworkMagic.Testnet]: exports.testnetEraSummaries
};
const createSlotEpochCalcImpl = (timeSettings) => {
const timeSettingsAsc = (0, orderBy_1.default)(timeSettings, ({ fromSlotNo }) => fromSlotNo);
const createSlotEpochCalcImpl = (eraSummaries) => {
const eraSummariesAsc = (0, orderBy_1.default)(eraSummaries, ({ start }) => start.slot);
return (slotNo) => {
const relevantTimeSettingsAsc = (0, orderBy_1.default)(timeSettingsAsc.filter(({ fromSlotNo }) => fromSlotNo <= slotNo), ({ fromSlotNo }) => fromSlotNo);
if (relevantTimeSettingsAsc.length === 0) {
throw new TimeSettingsError(`No TimeSettings for slot ${slotNo} found`);
const relevantEraSummariesAsc = (0, orderBy_1.default)(eraSummariesAsc.filter(({ start }) => start.slot <= slotNo), ({ start }) => start.slot);
if (relevantEraSummariesAsc.length === 0) {
throw new EraSummaryError(`No EraSummary for slot ${slotNo} found`);
}
let epochNo = 0;
let currentTimeSettings;
for (let i = 0; i < relevantTimeSettingsAsc.length; i++) {
currentTimeSettings = relevantTimeSettingsAsc[i];
const nextTimeSettings = relevantTimeSettingsAsc[i + 1];
epochNo += Math.floor(((nextTimeSettings?.fromSlotNo || slotNo) - currentTimeSettings.fromSlotNo) / currentTimeSettings.epochLength);
let currentEraSummary;
for (let i = 0; i < relevantEraSummariesAsc.length; i++) {
currentEraSummary = relevantEraSummariesAsc[i];
const nextEraSummary = relevantEraSummariesAsc[i + 1];
epochNo += Math.floor(((nextEraSummary?.start.slot || slotNo) - currentEraSummary.start.slot) /
currentEraSummary.parameters.epochLength);
}
return { epochNo, epochTimeSettings: currentTimeSettings };
return { epochEraSummary: currentEraSummary, epochNo };
};
};
const createSlotEpochCalc = (timeSettings) => {
const calc = createSlotEpochCalcImpl(timeSettings);
const createSlotEpochCalc = (eraSummaries) => {
const calc = createSlotEpochCalcImpl(eraSummaries);
return (slotNo) => calc(slotNo).epochNo;
};
exports.createSlotEpochCalc = createSlotEpochCalc;
const createSlotTimeCalc = (timeSettings) => {
const timeSettingsDesc = (0, orderBy_1.default)(timeSettings, ({ fromSlotNo }) => fromSlotNo, 'desc');
const createSlotTimeCalc = (eraSummaries) => {
const eraSummariesDesc = (0, orderBy_1.default)(eraSummaries, ({ start }) => start.slot, 'desc');
return (slotNo) => {
const activeTimeSettings = timeSettingsDesc.find(({ fromSlotNo }) => fromSlotNo <= slotNo);
if (!activeTimeSettings) {
throw new TimeSettingsError(`No TimeSettings for slot ${slotNo} found`);
const activeEraSummary = eraSummariesDesc.find(({ start }) => start.slot <= slotNo);
if (!activeEraSummary) {
throw new EraSummaryError(`No EraSummary for slot ${slotNo} found`);
}
return new Date(activeTimeSettings.fromSlotDate.getTime() +
(slotNo - activeTimeSettings.fromSlotNo) * activeTimeSettings.slotLength);
return new Date(activeEraSummary.start.time.getTime() +
(slotNo - activeEraSummary.start.slot) * activeEraSummary.parameters.slotLength);
};
};
exports.createSlotTimeCalc = createSlotTimeCalc;
const createSlotEpochInfoCalc = (timeSettings) => {
const slotTimeCalc = (0, exports.createSlotTimeCalc)(timeSettings);
const epochCalc = createSlotEpochCalcImpl(timeSettings);
const createSlotEpochInfoCalc = (eraSummaries) => {
const slotTimeCalc = (0, exports.createSlotTimeCalc)(eraSummaries);
const epochCalc = createSlotEpochCalcImpl(eraSummaries);
return (slot) => {
const { epochNo, epochTimeSettings } = epochCalc(slot);
const firstSlot = epochTimeSettings.fromSlotNo +
Math.floor((slot - epochTimeSettings.fromSlotNo) / epochTimeSettings.epochLength) * epochTimeSettings.epochLength;
const lastSlot = firstSlot + epochTimeSettings.epochLength - 1;
const { epochNo, epochEraSummary } = epochCalc(slot);
const firstSlot = epochEraSummary.start.slot +
Math.floor((slot - epochEraSummary.start.slot) / epochEraSummary.parameters.epochLength) *
epochEraSummary.parameters.epochLength;
const lastSlot = firstSlot + epochEraSummary.parameters.epochLength - 1;
return {

@@ -69,0 +77,0 @@ epochNo,

@@ -1,2 +0,2 @@

import { Cardano, Provider, TimeSettings } from '../..';
import { Cardano, EraSummary, Provider } from '../..';
export declare type ProtocolParametersRequiredByWallet = Required<Pick<Cardano.ProtocolParametersBabbage, 'coinsPerUtxoByte' | 'maxTxSize' | 'maxValueSize' | 'stakeKeyDeposit' | 'maxCollateralInputs' | 'minFeeCoefficient' | 'minFeeConstant' | 'minPoolCost' | 'poolDeposit' | 'protocolVersion'>>;

@@ -17,4 +17,4 @@ export declare type SupplySummary = {

stake(): Promise<StakeSummary>;
timeSettings(): Promise<TimeSettings[]>;
eraSummaries(): Promise<EraSummary[]>;
}
//# sourceMappingURL=types.d.ts.map
import { CardanoNetworkMagic, Epoch, Slot } from '../Cardano';
import { CustomError } from 'ts-custom-error';
export interface TimeSettings {
fromSlotDate: Date;
fromSlotNo: number;
slotLength: number;
epochLength: number;
}
import { EraSummary } from '../CardanoNode';
export interface SlotDate {

@@ -18,13 +13,13 @@ slot: Slot;

}
export declare class TimeSettingsError extends CustomError {
export declare class EraSummaryError extends CustomError {
}
export declare const mainnetTimeSettings: TimeSettings[];
export declare const testnetTimeSettings: TimeSettings[];
export declare type TimeSettingsMap = {
[key in CardanoNetworkMagic]: TimeSettings[];
export declare const mainnetEraSummaries: EraSummary[];
export declare const testnetEraSummaries: EraSummary[];
export declare type EraSummariesMap = {
[key in CardanoNetworkMagic]: EraSummary[];
};
export declare const timeSettingsConfig: TimeSettingsMap;
export declare const createSlotEpochCalc: (timeSettings: TimeSettings[]) => (slotNo: Slot) => Epoch;
export declare const createSlotTimeCalc: (timeSettings: TimeSettings[]) => (slotNo: Slot) => Date;
export declare const createSlotEpochInfoCalc: (timeSettings: TimeSettings[]) => (slot: Slot) => EpochInfo;
export declare const eraSummariesConfig: EraSummariesMap;
export declare const createSlotEpochCalc: (eraSummaries: EraSummary[]) => (slotNo: Slot) => Epoch;
export declare const createSlotTimeCalc: (eraSummaries: EraSummary[]) => (slotNo: Slot) => Date;
export declare const createSlotEpochInfoCalc: (eraSummaries: EraSummary[]) => (slot: Slot) => EpochInfo;
export declare type SlotTimeCalc = ReturnType<typeof createSlotTimeCalc>;

@@ -31,0 +26,0 @@ export declare type SlotEpochCalc = ReturnType<typeof createSlotEpochCalc>;

import { CardanoNetworkMagic } from '../Cardano';
import { CustomError } from 'ts-custom-error';
import orderBy from 'lodash/orderBy';
export class TimeSettingsError extends CustomError {
export class EraSummaryError extends CustomError {
}
export const mainnetTimeSettings = [
{ epochLength: 21600, fromSlotDate: new Date(1506192291000), fromSlotNo: 0, slotLength: 20000 },
{ epochLength: 432000, fromSlotDate: new Date(1596059091000), fromSlotNo: 4492800, slotLength: 1000 }
export const mainnetEraSummaries = [
{ parameters: { epochLength: 21600, slotLength: 20000 }, start: { slot: 0, time: new Date(1506192291000) } },
{
parameters: { epochLength: 432000, slotLength: 1000 },
start: { slot: 4492800, time: new Date(1596059091000) }
}
];
export const testnetTimeSettings = [
{ epochLength: 21600, fromSlotDate: new Date(1563999616000), fromSlotNo: 0, slotLength: 20000 },
{ epochLength: 432000, fromSlotDate: new Date(1595964016000), fromSlotNo: 1598400, slotLength: 1000 }
export const testnetEraSummaries = [
{ parameters: { epochLength: 21600, slotLength: 20000 }, start: { slot: 0, time: new Date(1563999616000) } },
{
parameters: { epochLength: 432000, slotLength: 1000 },
start: { slot: 1598400, time: new Date(1595964016000) }
}
];
export const timeSettingsConfig = {
[CardanoNetworkMagic.Mainnet]: mainnetTimeSettings,
[CardanoNetworkMagic.Testnet]: testnetTimeSettings
export const eraSummariesConfig = {
[CardanoNetworkMagic.Mainnet]: mainnetEraSummaries,
[CardanoNetworkMagic.Testnet]: testnetEraSummaries
};
const createSlotEpochCalcImpl = (timeSettings) => {
const timeSettingsAsc = orderBy(timeSettings, ({ fromSlotNo }) => fromSlotNo);
const createSlotEpochCalcImpl = (eraSummaries) => {
const eraSummariesAsc = orderBy(eraSummaries, ({ start }) => start.slot);
return (slotNo) => {
const relevantTimeSettingsAsc = orderBy(timeSettingsAsc.filter(({ fromSlotNo }) => fromSlotNo <= slotNo), ({ fromSlotNo }) => fromSlotNo);
if (relevantTimeSettingsAsc.length === 0) {
throw new TimeSettingsError(`No TimeSettings for slot ${slotNo} found`);
const relevantEraSummariesAsc = orderBy(eraSummariesAsc.filter(({ start }) => start.slot <= slotNo), ({ start }) => start.slot);
if (relevantEraSummariesAsc.length === 0) {
throw new EraSummaryError(`No EraSummary for slot ${slotNo} found`);
}
let epochNo = 0;
let currentTimeSettings;
for (let i = 0; i < relevantTimeSettingsAsc.length; i++) {
currentTimeSettings = relevantTimeSettingsAsc[i];
const nextTimeSettings = relevantTimeSettingsAsc[i + 1];
epochNo += Math.floor(((nextTimeSettings?.fromSlotNo || slotNo) - currentTimeSettings.fromSlotNo) / currentTimeSettings.epochLength);
let currentEraSummary;
for (let i = 0; i < relevantEraSummariesAsc.length; i++) {
currentEraSummary = relevantEraSummariesAsc[i];
const nextEraSummary = relevantEraSummariesAsc[i + 1];
epochNo += Math.floor(((nextEraSummary?.start.slot || slotNo) - currentEraSummary.start.slot) /
currentEraSummary.parameters.epochLength);
}
return { epochNo, epochTimeSettings: currentTimeSettings };
return { epochEraSummary: currentEraSummary, epochNo };
};
};
export const createSlotEpochCalc = (timeSettings) => {
const calc = createSlotEpochCalcImpl(timeSettings);
export const createSlotEpochCalc = (eraSummaries) => {
const calc = createSlotEpochCalcImpl(eraSummaries);
return (slotNo) => calc(slotNo).epochNo;
};
export const createSlotTimeCalc = (timeSettings) => {
const timeSettingsDesc = orderBy(timeSettings, ({ fromSlotNo }) => fromSlotNo, 'desc');
export const createSlotTimeCalc = (eraSummaries) => {
const eraSummariesDesc = orderBy(eraSummaries, ({ start }) => start.slot, 'desc');
return (slotNo) => {
const activeTimeSettings = timeSettingsDesc.find(({ fromSlotNo }) => fromSlotNo <= slotNo);
if (!activeTimeSettings) {
throw new TimeSettingsError(`No TimeSettings for slot ${slotNo} found`);
const activeEraSummary = eraSummariesDesc.find(({ start }) => start.slot <= slotNo);
if (!activeEraSummary) {
throw new EraSummaryError(`No EraSummary for slot ${slotNo} found`);
}
return new Date(activeTimeSettings.fromSlotDate.getTime() +
(slotNo - activeTimeSettings.fromSlotNo) * activeTimeSettings.slotLength);
return new Date(activeEraSummary.start.time.getTime() +
(slotNo - activeEraSummary.start.slot) * activeEraSummary.parameters.slotLength);
};
};
export const createSlotEpochInfoCalc = (timeSettings) => {
const slotTimeCalc = createSlotTimeCalc(timeSettings);
const epochCalc = createSlotEpochCalcImpl(timeSettings);
export const createSlotEpochInfoCalc = (eraSummaries) => {
const slotTimeCalc = createSlotTimeCalc(eraSummaries);
const epochCalc = createSlotEpochCalcImpl(eraSummaries);
return (slot) => {
const { epochNo, epochTimeSettings } = epochCalc(slot);
const firstSlot = epochTimeSettings.fromSlotNo +
Math.floor((slot - epochTimeSettings.fromSlotNo) / epochTimeSettings.epochLength) * epochTimeSettings.epochLength;
const lastSlot = firstSlot + epochTimeSettings.epochLength - 1;
const { epochNo, epochEraSummary } = epochCalc(slot);
const firstSlot = epochEraSummary.start.slot +
Math.floor((slot - epochEraSummary.start.slot) / epochEraSummary.parameters.epochLength) *
epochEraSummary.parameters.epochLength;
const lastSlot = firstSlot + epochEraSummary.parameters.epochLength - 1;
return {

@@ -59,0 +67,0 @@ epochNo,

{
"name": "@cardano-sdk/core",
"version": "0.5.0-nightly.3",
"version": "0.5.0-nightly.4",
"description": "Core types and libraries for Cardano",

@@ -79,3 +79,3 @@ "engines": {

],
"gitHead": "60e4bfaf6a113a2b63e3bebbfd515fa60a127567"
"gitHead": "462941dc783c2dfecba92d03027eaeb8ce051712"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc