@meshsdk/common 1.0.0-alpha.7 → 1.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/data/index.d.ts +2 -0
- package/dist/cjs/builder/data/index.js +2 -0
- package/dist/cjs/builder/data/parser.d.ts +5 -0
- package/dist/cjs/builder/data/parser.js +11 -0
- package/dist/cjs/builder/data/time.d.ts +11 -0
- package/dist/cjs/builder/data/time.js +32 -0
- package/dist/mjs/builder/data/index.d.ts +2 -0
- package/dist/mjs/builder/data/index.js +2 -0
- package/dist/mjs/builder/data/parser.d.ts +5 -0
- package/dist/mjs/builder/data/parser.js +4 -0
- package/dist/mjs/builder/data/time.d.ts +11 -0
- package/dist/mjs/builder/data/time.js +27 -0
- package/package.json +2 -2
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./mesh"), exports);
|
|
18
18
|
__exportStar(require("./plutus"), exports);
|
|
19
|
+
__exportStar(require("./parser"), exports);
|
|
20
|
+
__exportStar(require("./time"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const bytesToHex: (bytes: ArrayBuffer) => string;
|
|
3
|
+
export declare const hexToBytes: (hex: string) => Buffer;
|
|
4
|
+
export declare const stringToHex: (str: string) => string;
|
|
5
|
+
export declare const hexToString: (hex: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hexToString = exports.stringToHex = exports.hexToBytes = exports.bytesToHex = void 0;
|
|
4
|
+
const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex');
|
|
5
|
+
exports.bytesToHex = bytesToHex;
|
|
6
|
+
const hexToBytes = (hex) => Buffer.from(hex, 'hex');
|
|
7
|
+
exports.hexToBytes = hexToBytes;
|
|
8
|
+
const stringToHex = (str) => Buffer.from(str, 'utf8').toString('hex');
|
|
9
|
+
exports.stringToHex = stringToHex;
|
|
10
|
+
const hexToString = (hex) => Buffer.from(hex, 'hex').toString('utf8');
|
|
11
|
+
exports.hexToString = hexToString;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Network } from '../../types';
|
|
2
|
+
export type Slot = number;
|
|
3
|
+
export type UnixTime = number;
|
|
4
|
+
export type SlotConfig = {
|
|
5
|
+
zeroTime: UnixTime;
|
|
6
|
+
zeroSlot: Slot;
|
|
7
|
+
slotLength: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const SLOT_CONFIG_NETWORK: Record<Network, SlotConfig>;
|
|
10
|
+
export declare const slotToBeginUnixTime: (slot: Slot, slotConfig: SlotConfig) => UnixTime;
|
|
11
|
+
export declare const unixTimeToEnclosingSlot: (unixTime: UnixTime, slotConfig: SlotConfig) => Slot;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unixTimeToEnclosingSlot = exports.slotToBeginUnixTime = exports.SLOT_CONFIG_NETWORK = void 0;
|
|
4
|
+
exports.SLOT_CONFIG_NETWORK = {
|
|
5
|
+
mainnet: { zeroTime: 1596059091000, zeroSlot: 4492800, slotLength: 1000 }, // Starting at Shelley era
|
|
6
|
+
preview: { zeroTime: 1666656000000, zeroSlot: 0, slotLength: 1000 }, // Starting at Shelley era
|
|
7
|
+
preprod: {
|
|
8
|
+
zeroTime: 1654041600000 + 1728000000,
|
|
9
|
+
zeroSlot: 86400,
|
|
10
|
+
slotLength: 1000,
|
|
11
|
+
}, // Starting at Shelley era
|
|
12
|
+
/** Customizable slot config (Initialized with 0 values). */
|
|
13
|
+
testnet: { zeroTime: 0, zeroSlot: 0, slotLength: 0 },
|
|
14
|
+
};
|
|
15
|
+
const slotToBeginUnixTime = (slot, slotConfig) => {
|
|
16
|
+
const msAfterBegin = (slot - slotConfig.zeroSlot) * slotConfig.slotLength;
|
|
17
|
+
return slotConfig.zeroTime + msAfterBegin;
|
|
18
|
+
};
|
|
19
|
+
exports.slotToBeginUnixTime = slotToBeginUnixTime;
|
|
20
|
+
// slotToBeginUnixTime and slotToEndUnixTime are identical when slotLength == 1. So we don't need to worry about this now.
|
|
21
|
+
// function slotToEndUnixTime(slot: Slot, slotConfig: SlotConfig): UnixTime {
|
|
22
|
+
// return slotToBeginUnixTime(slot, slotConfig) + (slotConfig.slotLength - 1);
|
|
23
|
+
// }
|
|
24
|
+
const unixTimeToEnclosingSlot = (unixTime, slotConfig) => {
|
|
25
|
+
const timePassed = unixTime - slotConfig.zeroTime;
|
|
26
|
+
const slotsPassed = Math.floor(timePassed / slotConfig.slotLength);
|
|
27
|
+
return slotsPassed + slotConfig.zeroSlot;
|
|
28
|
+
};
|
|
29
|
+
exports.unixTimeToEnclosingSlot = unixTimeToEnclosingSlot;
|
|
30
|
+
// const timeNow = new Date().getTime();
|
|
31
|
+
// console.log(timeNow);
|
|
32
|
+
// console.log(unixTimeToEnclosingSlot(timeNow, SLOT_CONFIG_NETWORK.Preprod));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const bytesToHex: (bytes: ArrayBuffer) => string;
|
|
3
|
+
export declare const hexToBytes: (hex: string) => Buffer;
|
|
4
|
+
export declare const stringToHex: (str: string) => string;
|
|
5
|
+
export declare const hexToString: (hex: string) => string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex');
|
|
2
|
+
export const hexToBytes = (hex) => Buffer.from(hex, 'hex');
|
|
3
|
+
export const stringToHex = (str) => Buffer.from(str, 'utf8').toString('hex');
|
|
4
|
+
export const hexToString = (hex) => Buffer.from(hex, 'hex').toString('utf8');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Network } from '../../types';
|
|
2
|
+
export type Slot = number;
|
|
3
|
+
export type UnixTime = number;
|
|
4
|
+
export type SlotConfig = {
|
|
5
|
+
zeroTime: UnixTime;
|
|
6
|
+
zeroSlot: Slot;
|
|
7
|
+
slotLength: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const SLOT_CONFIG_NETWORK: Record<Network, SlotConfig>;
|
|
10
|
+
export declare const slotToBeginUnixTime: (slot: Slot, slotConfig: SlotConfig) => UnixTime;
|
|
11
|
+
export declare const unixTimeToEnclosingSlot: (unixTime: UnixTime, slotConfig: SlotConfig) => Slot;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const SLOT_CONFIG_NETWORK = {
|
|
2
|
+
mainnet: { zeroTime: 1596059091000, zeroSlot: 4492800, slotLength: 1000 }, // Starting at Shelley era
|
|
3
|
+
preview: { zeroTime: 1666656000000, zeroSlot: 0, slotLength: 1000 }, // Starting at Shelley era
|
|
4
|
+
preprod: {
|
|
5
|
+
zeroTime: 1654041600000 + 1728000000,
|
|
6
|
+
zeroSlot: 86400,
|
|
7
|
+
slotLength: 1000,
|
|
8
|
+
}, // Starting at Shelley era
|
|
9
|
+
/** Customizable slot config (Initialized with 0 values). */
|
|
10
|
+
testnet: { zeroTime: 0, zeroSlot: 0, slotLength: 0 },
|
|
11
|
+
};
|
|
12
|
+
export const slotToBeginUnixTime = (slot, slotConfig) => {
|
|
13
|
+
const msAfterBegin = (slot - slotConfig.zeroSlot) * slotConfig.slotLength;
|
|
14
|
+
return slotConfig.zeroTime + msAfterBegin;
|
|
15
|
+
};
|
|
16
|
+
// slotToBeginUnixTime and slotToEndUnixTime are identical when slotLength == 1. So we don't need to worry about this now.
|
|
17
|
+
// function slotToEndUnixTime(slot: Slot, slotConfig: SlotConfig): UnixTime {
|
|
18
|
+
// return slotToBeginUnixTime(slot, slotConfig) + (slotConfig.slotLength - 1);
|
|
19
|
+
// }
|
|
20
|
+
export const unixTimeToEnclosingSlot = (unixTime, slotConfig) => {
|
|
21
|
+
const timePassed = unixTime - slotConfig.zeroTime;
|
|
22
|
+
const slotsPassed = Math.floor(timePassed / slotConfig.slotLength);
|
|
23
|
+
return slotsPassed + slotConfig.zeroSlot;
|
|
24
|
+
};
|
|
25
|
+
// const timeNow = new Date().getTime();
|
|
26
|
+
// console.log(timeNow);
|
|
27
|
+
// console.log(unixTimeToEnclosingSlot(timeNow, SLOT_CONFIG_NETWORK.Preprod));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/common",
|
|
3
3
|
"description": "Cardano common utils & constants for Mesh SDK",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.8",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/mjs/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"cardano-serialization-lib"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"prepare": "cp
|
|
33
|
+
"prepare": "cp ../../tsconfig-base.json ./ && cp ../../tsconfig-cjs.json ./ && cp ../../tsconfig.json ./",
|
|
34
34
|
"build": "rm -fr dist/* && tsc -p ./tsconfig.json && tsc -p ./tsconfig-cjs.json",
|
|
35
35
|
"ci": "yarn && yarn build"
|
|
36
36
|
},
|