@koralabs/kora-labs-common 5.1.32 → 5.1.34

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.
@@ -20,3 +20,5 @@ export declare enum ERROR_TEXT {
20
20
  HANDLE_PAGE_AND_SLOT_NUMBER_INVALID = "'page' and 'slot_number' can't be used together"
21
21
  }
22
22
  export declare const HANDLES_PER_PAGE_MAX = 1000;
23
+ export declare const EMPTY = "|empty|";
24
+ export declare const TWELVE_HOURS_IN_SLOTS = 43200;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.HANDLES_PER_PAGE_MAX = exports.ERROR_TEXT = exports.KORA_USER_AGENT = exports.HANDLES_API_KEY = exports.REGEX_SUB_HANDLE = exports.REGEX_HANDLE = exports.REGEX_SPLIT_ON_NUMS = exports.REGEX_SPLIT_ON_CHARS = exports.RESPONSE_NOT_ALLOWED = exports.RESPONSE_INVALID_HANDLE_FORMAT = exports.RESPONSE_UNAVAILABLE_LEGENDARY = exports.RESPONSE_UNAVAILABLE_RESERVED = exports.RESPONSE_UNAVAILABLE_ACTIVE_SESSION = exports.RESPONSE_UNAVAILABLE_PAID = exports.RESPONSE_AVAILABLE = void 0;
4
+ exports.TWELVE_HOURS_IN_SLOTS = exports.EMPTY = exports.HANDLES_PER_PAGE_MAX = exports.ERROR_TEXT = exports.KORA_USER_AGENT = exports.HANDLES_API_KEY = exports.REGEX_SUB_HANDLE = exports.REGEX_HANDLE = exports.REGEX_SPLIT_ON_NUMS = exports.REGEX_SPLIT_ON_CHARS = exports.RESPONSE_NOT_ALLOWED = exports.RESPONSE_INVALID_HANDLE_FORMAT = exports.RESPONSE_UNAVAILABLE_LEGENDARY = exports.RESPONSE_UNAVAILABLE_RESERVED = exports.RESPONSE_UNAVAILABLE_ACTIVE_SESSION = exports.RESPONSE_UNAVAILABLE_PAID = exports.RESPONSE_AVAILABLE = void 0;
5
5
  const constants_1 = require("../constants");
6
6
  exports.RESPONSE_AVAILABLE = 'Yay! This handle is available.';
7
7
  exports.RESPONSE_UNAVAILABLE_PAID = 'Sorry! This Handle is pending mint or already minted.';
@@ -26,3 +26,5 @@ var ERROR_TEXT;
26
26
  ERROR_TEXT["HANDLE_PAGE_AND_SLOT_NUMBER_INVALID"] = "'page' and 'slot_number' can't be used together";
27
27
  })(ERROR_TEXT = exports.ERROR_TEXT || (exports.ERROR_TEXT = {}));
28
28
  exports.HANDLES_PER_PAGE_MAX = 1000;
29
+ exports.EMPTY = '|empty|';
30
+ exports.TWELVE_HOURS_IN_SLOTS = 43200; // value comes from the securityParam here: https://cips.cardano.org/cips/cip9/#nonupdatableparameters then converted to slots
@@ -1,8 +1,8 @@
1
+ export * from './api';
2
+ export * from './constants';
1
3
  export * from './interfaces';
2
4
  export * from './interfaces/api';
3
- export * from './interfaces/handlesRepository';
4
- export * from './constants';
5
- export * from './api';
5
+ export * from './interfaces/handlesProvider';
6
+ export * from './models';
6
7
  export * from './policies';
7
8
  export * from './utils';
8
- export * from './models';
package/handles/index.js CHANGED
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./constants"), exports);
17
19
  __exportStar(require("./interfaces"), exports);
18
20
  __exportStar(require("./interfaces/api"), exports);
19
- __exportStar(require("./interfaces/handlesRepository"), exports);
20
- __exportStar(require("./constants"), exports);
21
- __exportStar(require("./api"), exports);
21
+ __exportStar(require("./interfaces/handlesProvider"), exports);
22
+ __exportStar(require("./models"), exports);
22
23
  __exportStar(require("./policies"), exports);
23
24
  __exportStar(require("./utils"), exports);
24
- __exportStar(require("./models"), exports);
@@ -40,10 +40,10 @@ export interface HandleHistory {
40
40
  old: Partial<StoredHandle> | null;
41
41
  new?: Partial<StoredHandle> | null;
42
42
  }
43
- export interface ISlotHistoryIndex {
43
+ export interface ISlotHistory {
44
44
  [handleHex: string]: HandleHistory;
45
45
  }
46
- export interface IHandleStoreMetrics {
46
+ export interface IApiMetrics {
47
47
  firstSlot?: number;
48
48
  lastSlot?: number;
49
49
  currentSlot?: number;
@@ -54,6 +54,8 @@ export interface IHandleStoreMetrics {
54
54
  tipBlockHash?: string;
55
55
  memorySize?: number;
56
56
  networkSync?: number;
57
+ count?: number;
58
+ schemaVersion?: number;
57
59
  }
58
60
  export interface SaveMintingTxInput {
59
61
  hex: string;
@@ -123,14 +125,15 @@ export interface SaveSubHandleSettingsInput {
123
125
  utxoDetails: IUTxO;
124
126
  slotNumber: number;
125
127
  }
126
- export interface HolderAddressIndex {
128
+ export interface Holder {
129
+ address: string;
127
130
  handles: Set<string>;
128
131
  defaultHandle: string;
129
132
  manuallySet: boolean;
130
133
  type: string;
131
134
  knownOwnerName: string;
132
135
  }
133
- export interface HolderAddressDetails {
136
+ export interface HolderViewModel {
134
137
  total_handles: number;
135
138
  address: string;
136
139
  type: string;
@@ -169,3 +172,18 @@ export interface IGetHolderAddressDetailsRequest {
169
172
  export type INormalizedQueryParams = {
170
173
  [key: string]: string;
171
174
  };
175
+ export declare enum IndexNames {
176
+ ADDRESS = "address",
177
+ CHARACTER = "characters",
178
+ HANDLE = "handle",
179
+ HASH_OF_STAKE_KEY_HASH = "hashofstakekeyhash",
180
+ HOLDER = "holder",
181
+ LENGTH = "length",
182
+ NUMERIC_MODIFIER = "numericmodifiers",
183
+ OG = "og",
184
+ PAYMENT_KEY_HASH = "paymentkeyhashes",
185
+ RARITY = "rarity",
186
+ SLOT_HISTORY = "slothistory",
187
+ SUBHANDLE = "subhandle",
188
+ STAKE_KEY_HASH = "stakekeyhash"
189
+ }
@@ -1,2 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IndexNames = void 0;
4
+ var IndexNames;
5
+ (function (IndexNames) {
6
+ IndexNames["ADDRESS"] = "address";
7
+ IndexNames["CHARACTER"] = "characters";
8
+ IndexNames["HANDLE"] = "handle";
9
+ IndexNames["HASH_OF_STAKE_KEY_HASH"] = "hashofstakekeyhash";
10
+ IndexNames["HOLDER"] = "holder";
11
+ IndexNames["LENGTH"] = "length";
12
+ IndexNames["NUMERIC_MODIFIER"] = "numericmodifiers";
13
+ IndexNames["OG"] = "og";
14
+ IndexNames["PAYMENT_KEY_HASH"] = "paymentkeyhashes";
15
+ IndexNames["RARITY"] = "rarity";
16
+ IndexNames["SLOT_HISTORY"] = "slothistory";
17
+ IndexNames["SUBHANDLE"] = "subhandle";
18
+ IndexNames["STAKE_KEY_HASH"] = "stakekeyhash";
19
+ })(IndexNames = exports.IndexNames || (exports.IndexNames = {}));
@@ -0,0 +1,28 @@
1
+ import { IApiMetrics, IndexNames, StoredHandle } from './api';
2
+ export interface IHandlesProvider {
3
+ initialize: () => Promise<IHandlesProvider>;
4
+ destroy: () => void;
5
+ rollBackToGenesis: () => void;
6
+ getStartingPoint: (save: ({ handle, oldHandle, saveHistory }: {
7
+ handle: StoredHandle;
8
+ oldHandle?: StoredHandle;
9
+ saveHistory?: boolean;
10
+ }) => Promise<void>, failed: boolean) => Promise<{
11
+ slot: number;
12
+ id: string;
13
+ } | null>;
14
+ getHandle: (key: string) => StoredHandle | null;
15
+ getHandleByHex: (hex: string) => StoredHandle | null;
16
+ getAllHandles: () => StoredHandle[];
17
+ setHandle: (key: string, value: StoredHandle) => void;
18
+ removeHandle: (handleName: string) => void;
19
+ getIndex: (index: IndexNames) => any;
20
+ getValuesFromIndex: (index: IndexNames, key: string | number) => any;
21
+ setValueOnIndex: (index: IndexNames, key: string | number, value: any) => void;
22
+ removeValueFromIndex: (index: IndexNames, key: string | number, value: string) => void;
23
+ removeKeyFromIndex: (index: IndexNames, key: string | number) => void;
24
+ getMetrics: () => IApiMetrics;
25
+ setMetrics: (metrics: IApiMetrics) => void;
26
+ count: () => number;
27
+ getSchemaVersion: () => number;
28
+ }
@@ -1,5 +1,5 @@
1
1
  import { BoolInt, FeaturedItemType, HexString, HexStringOrEmpty } from '../../types';
2
- import { ISlotHistoryIndex, StoredHandle } from './api';
2
+ import { ISlotHistory, StoredHandle } from './api';
3
3
  export declare enum Rarity {
4
4
  basic = "basic",
5
5
  common = "common",
@@ -159,7 +159,7 @@ export interface ICip68Handle extends IHandle {
159
159
  export interface IPersonalizedHandle extends ICip68Handle {
160
160
  personalization?: IPersonalization;
161
161
  }
162
- export interface IHandleStats {
162
+ export interface IApiMetricsViewModel {
163
163
  percentage_complete: string;
164
164
  current_memory_used: number;
165
165
  ogmios_elapsed: string;
@@ -348,7 +348,7 @@ export interface IHandleFileContent {
348
348
  hash: string;
349
349
  schemaVersion?: number;
350
350
  handles: Record<string, StoredHandle>;
351
- history: [number, ISlotHistoryIndex][];
351
+ history: [number, ISlotHistory][];
352
352
  }
353
353
  export interface IHandleSvgOptions extends IPersonalizationDesigner {
354
354
  pfp_image?: string;
@@ -1,5 +1,5 @@
1
1
  import { Network } from '../types';
2
- interface PolicyIds {
2
+ export interface PolicyIds {
3
3
  [key: string]: {
4
4
  firstMintingSlot: number;
5
5
  lastMintingSlot: number | null;
@@ -7,12 +7,11 @@ interface PolicyIds {
7
7
  isDeMi?: boolean;
8
8
  };
9
9
  }
10
- interface HandlePolicies {
10
+ export interface HandlePolicies {
11
11
  'preview': PolicyIds;
12
12
  'preprod': PolicyIds;
13
13
  'mainnet': PolicyIds;
14
- getActivePolicy(network: Network, atSlot?: number): string | undefined;
14
+ getActivePolicy(network: Network, isDemi?: boolean, atSlot?: number): string | undefined;
15
15
  contains(network: Network, policyId: string): boolean;
16
16
  }
17
17
  export declare const HANDLE_POLICIES: HandlePolicies;
18
- export {};
@@ -9,7 +9,7 @@ exports.HANDLE_POLICIES = {
9
9
  },
10
10
  'preprod': { 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null } },
11
11
  'mainnet': { 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null } },
12
- getActivePolicy(network, atSlot, isDeMi = false) {
12
+ getActivePolicy(network, isDeMi = false, atSlot) {
13
13
  var _a;
14
14
  const theSlot = atSlot ? atSlot : (0, utils_1.getSlotNumberFromDate)(new Date(Date.now()));
15
15
  return (_a = Object.entries(this[network]).find(([, value]) => { var _a; return value.firstMintingSlot <= theSlot && ((_a = value.lastMintingSlot) !== null && _a !== void 0 ? _a : Number.POSITIVE_INFINITY) >= theSlot && value.isDeMi == isDeMi; })) === null || _a === void 0 ? void 0 : _a[0];
package/logger/index.js CHANGED
@@ -59,8 +59,22 @@ class Logger {
59
59
  const log_milliseconds = milliseconds != undefined && milliseconds != null ? `, "milliseconds": ${milliseconds}` : '';
60
60
  const log_count = count != undefined && count != null ? `, "count": ${count}` : '';
61
61
  const log_dimensions = dimensions && Object.keys(dimensions).length ? `, "dimensions": ${JSON.stringify(dimensions)}` : '';
62
+ let logFunc = console.log;
63
+ switch (category) {
64
+ case LogCategory.DEBUG:
65
+ logFunc = console.debug;
66
+ break;
67
+ case LogCategory.WARN:
68
+ logFunc = console.warn;
69
+ break;
70
+ case LogCategory.ERROR:
71
+ case LogCategory.FATAL:
72
+ case LogCategory.NOTIFY:
73
+ logFunc = console.error;
74
+ break;
75
+ }
62
76
  // PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
63
- console.log(`{"network": "${Logger.network}", "application": "${Logger.application}", "category": "${category !== null && category !== void 0 ? category : LogCategory.INFO}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions} }`);
77
+ logFunc(`{"network": "${Logger.network}", "application": "${Logger.application}", "category": "${category !== null && category !== void 0 ? category : LogCategory.INFO}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions} }`);
64
78
  // PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
65
79
  }
66
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "5.1.32",
3
+ "version": "5.1.34",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { AddressDetails, AddressType, AssetNameLabel } from '../../types';
2
4
  export declare const getNativeCrypto: () => Promise<any>;
3
5
  export declare function dec2hex(dec: number): string;
@@ -17,8 +19,9 @@ export declare const buildPaymentAddressType: (address: string) => AddressType;
17
19
  export declare const buildStakeKey: (address: string) => string | null;
18
20
  export declare const getPaymentKeyHash: (address: string) => Promise<string | null>;
19
21
  export declare const bech32FromHex: (hex: string, isTestnet?: boolean, type?: 'addr' | 'stake' | 'pool' | 'drep' | 'cc_hot' | 'cc_cold') => string;
22
+ export declare const bech32AddressFromHashes: (paymentHash: string, paymentHashType?: 'key' | 'script', stakeHash?: string, stakeHashType?: 'key' | 'script', type?: 'addr' | 'stake', isTestnet?: boolean) => string;
20
23
  export declare const getAddressHolderDetails: (addr: string) => AddressDetails;
21
24
  export declare const checkKnownSmartContracts: (address: string, stake?: string | null) => string;
22
25
  export declare const getDateStringFromSlot: (currentSlot: number) => Date;
23
26
  export declare const getSlotNumberFromDate: (date: Date) => number;
24
- export declare const blake2b: (input: string, outlen?: number) => string;
27
+ export declare const blake2b: (input: string | Buffer | Uint8Array, outlen?: number) => string;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.blake2b = exports.getSlotNumberFromDate = exports.getDateStringFromSlot = exports.checkKnownSmartContracts = exports.getAddressHolderDetails = exports.bech32FromHex = exports.getPaymentKeyHash = exports.buildStakeKey = exports.buildPaymentAddressType = exports.getPaymentAddressType = exports.checkNameLabel = exports.parseAssetNameLabel = exports.decodeAddress = exports.getChallengeFromVerifier = exports.base64urlencode = exports.sha256 = exports.getRandomCodeVerifier = exports.dec2hex = exports.getNativeCrypto = void 0;
29
+ exports.blake2b = exports.getSlotNumberFromDate = exports.getDateStringFromSlot = exports.checkKnownSmartContracts = exports.getAddressHolderDetails = exports.bech32AddressFromHashes = exports.bech32FromHex = exports.getPaymentKeyHash = exports.buildStakeKey = exports.buildPaymentAddressType = exports.getPaymentAddressType = exports.checkNameLabel = exports.parseAssetNameLabel = exports.decodeAddress = exports.getChallengeFromVerifier = exports.base64urlencode = exports.sha256 = exports.getRandomCodeVerifier = exports.dec2hex = exports.getNativeCrypto = void 0;
30
30
  const bech32_1 = require("bech32");
31
31
  const blakejs_1 = require("blakejs");
32
32
  const bs58_1 = __importDefault(require("bs58"));
@@ -218,6 +218,23 @@ const bech32FromHex = (hex, isTestnet = !constants_1.IS_PRODUCTION, type = 'addr
218
218
  return bech32_1.bech32.encode(prefix, words, bytes.length * 2 + prefix.length);
219
219
  };
220
220
  exports.bech32FromHex = bech32FromHex;
221
+ const bech32AddressFromHashes = (paymentHash, paymentHashType = 'key', stakeHash = '', stakeHashType = 'key', type = 'addr', isTestnet = !constants_1.IS_PRODUCTION) => {
222
+ let headerByte = 0;
223
+ if (!stakeHash) {
224
+ headerByte += 6;
225
+ }
226
+ else {
227
+ if (stakeHashType == 'script') {
228
+ headerByte += 2;
229
+ }
230
+ }
231
+ if (paymentHashType == 'script') {
232
+ headerByte += 1;
233
+ }
234
+ const hex = `${headerByte.toString(16)}${isTestnet ? 0 : 1}${paymentHash}${stakeHash}`;
235
+ return (0, exports.bech32FromHex)(hex, isTestnet, type);
236
+ };
237
+ exports.bech32AddressFromHashes = bech32AddressFromHashes;
221
238
  const getAddressHolderDetails = (addr) => {
222
239
  const addressType = (0, exports.buildPaymentAddressType)(addr);
223
240
  let knownOwnerName = (0, exports.checkKnownSmartContracts)(addr);
@@ -290,6 +307,6 @@ const getSlotNumberFromDate = (date) => {
290
307
  };
291
308
  exports.getSlotNumberFromDate = getSlotNumberFromDate;
292
309
  const blake2b = (input, outlen = 32) => {
293
- return (0, blakejs_1.blake2bHex)(input, undefined, outlen);
310
+ return (0, blakejs_1.blake2bHex)(typeof input == 'string' ? Buffer.from(input, 'hex') : input, undefined, outlen);
294
311
  };
295
312
  exports.blake2b = blake2b;
@@ -1,63 +0,0 @@
1
- import { IHandleFileContent, IHandleStats, IUTxO } from '..';
2
- import { HandlePaginationModel } from '../models/handlePagination.model';
3
- import { HandleSearchModel } from '../models/handleSearch.model';
4
- import { HolderPaginationModel } from '../models/holderPagination.model';
5
- import { HolderAddressDetails, IHandleStoreMetrics, SaveMintingTxInput, SavePersonalizationInput, SaveSubHandleSettingsInput, SaveWalletAddressMoveInput, StoredHandle } from './api';
6
- export interface IHandlesRepository {
7
- initialize: () => IHandlesRepository;
8
- getAll: (params: {
9
- pagination: HandlePaginationModel;
10
- search: HandleSearchModel;
11
- }) => Promise<{
12
- searchTotal: number;
13
- handles: StoredHandle[];
14
- }>;
15
- getHandlesByPaymentKeyHashes: (hashes: string[]) => string[];
16
- getHandlesByAddresses: (addresses: string[]) => string[];
17
- getHandlesByHolderAddresses: (addresses: string[]) => string[];
18
- getHandlesByStakeKeyHashes: (hashes: string[]) => string[];
19
- getAllHandleNames: (search: HandleSearchModel, sort: string) => Promise<string[]>;
20
- getHandleByName: (handleName: string) => Promise<StoredHandle | null>;
21
- getHandleByHex: (handleHex: string) => Promise<StoredHandle | null>;
22
- getHolderAddressDetails: (key: string) => Promise<HolderAddressDetails>;
23
- getAllHolders: (params: {
24
- pagination: HolderPaginationModel;
25
- }) => Promise<HolderAddressDetails[]>;
26
- getHandleStats: () => IHandleStats;
27
- getTotalHandlesStats: () => {
28
- total_handles: number;
29
- total_holders: number;
30
- };
31
- currentHttpStatus: () => number;
32
- getHandleDatumByName: (handleName: string) => Promise<string | null>;
33
- getSubHandleSettings: (handleName: string) => Promise<{
34
- settings?: string;
35
- utxo: IUTxO;
36
- } | null>;
37
- getSubHandles: (handleName: string) => Promise<StoredHandle[]>;
38
- getTimeMetrics: () => {
39
- elapsedOgmiosExec: number;
40
- elapsedBuildingExec: number;
41
- };
42
- setMetrics: (metrics: IHandleStoreMetrics) => void;
43
- getMetrics: () => IHandleStats;
44
- getFilesContent(): Promise<IHandleFileContent[] | null>;
45
- prepareHandlesStorage: (fileContent: IHandleFileContent) => Promise<void>;
46
- rollBackToGenesis: () => Promise<void>;
47
- isCaughtUp: () => boolean;
48
- burnHandle: (handleName: string, slotNumber: number) => Promise<void>;
49
- rewindChangesToSlot: ({ slot, hash, lastSlot }: {
50
- slot: number;
51
- hash: string;
52
- lastSlot: number;
53
- }) => Promise<{
54
- name: string;
55
- action: string;
56
- handle: Partial<StoredHandle> | undefined;
57
- }[]>;
58
- savePersonalizationChange: ({ name, hex, personalization, reference_token, personalizationDatum, slotNumber, metadata }: SavePersonalizationInput) => Promise<void>;
59
- saveSubHandleSettingsChange: ({ name, settingsDatum, utxoDetails, slotNumber }: SaveSubHandleSettingsInput) => Promise<void>;
60
- saveMintedHandle: (input: SaveMintingTxInput) => Promise<void>;
61
- saveHandleUpdate: ({ name, adaAddress, utxo, slotNumber, datum, script }: SaveWalletAddressMoveInput) => Promise<void>;
62
- destroy: () => void;
63
- }