@koralabs/kora-labs-common 4.4.8 → 5.0.0
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/constants/index.d.ts +1 -0
- package/constants/index.js +4 -3
- package/errors/index.d.ts +9 -0
- package/errors/index.js +16 -1
- package/handles/constants.d.ts +9 -0
- package/handles/constants.js +11 -1
- package/handles/index.d.ts +4 -3
- package/handles/index.js +4 -7
- package/handles/interfaces/api.d.ts +124 -0
- package/handles/interfaces/api.js +2 -0
- package/handles/interfaces/handlesRepository.d.ts +65 -0
- package/handles/interfaces/handlesRepository.js +2 -0
- package/handles/{interfaces.d.ts → interfaces/index.d.ts} +5 -3
- package/handles/models/handlePagination.model.d.ts +15 -0
- package/handles/models/handlePagination.model.js +37 -0
- package/handles/models/handleSearch.model.d.ts +46 -0
- package/handles/models/handleSearch.model.js +124 -0
- package/handles/models/holderPagination.model.d.ts +13 -0
- package/handles/models/holderPagination.model.js +30 -0
- package/handles/models/index.d.ts +3 -0
- package/handles/models/index.js +19 -0
- package/handles/{buildMetadata.d.ts → utils.d.ts} +6 -0
- package/handles/{buildMetadata.js → utils.js} +42 -4
- package/package.json +4 -2
- package/types/index.d.ts +18 -0
- package/types/index.js +14 -1
- package/utils/crypto/index.d.ts +16 -0
- package/utils/crypto/index.js +207 -2
- package/utils/index.d.ts +9 -2
- package/utils/index.js +53 -8
- package/handles/getRarity.d.ts +0 -2
- package/handles/getRarity.js +0 -21
- package/handles/validation.d.ts +0 -4
- package/handles/validation.js +0 -24
- /package/handles/{interfaces.js → interfaces/index.js} +0 -0
package/constants/index.d.ts
CHANGED
package/constants/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b;
|
|
2
|
+
var _a, _b, _c;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TOU_URL = exports.AUTH_GRANT_DURATION = exports.IS_PRODUCTION = exports.IS_SERVER = void 0;
|
|
4
|
+
exports.TOU_URL = exports.AUTH_GRANT_DURATION = exports.IS_PRODUCTION = exports.NETWORK = exports.IS_SERVER = void 0;
|
|
5
5
|
exports.IS_SERVER = typeof process !== 'undefined' && typeof process.versions.node !== 'undefined';
|
|
6
|
+
exports.NETWORK = (_b = (_a = process.env.NETWORK) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'preview';
|
|
6
7
|
exports.IS_PRODUCTION = exports.IS_SERVER
|
|
7
|
-
? ((
|
|
8
|
+
? ((_c = process.env.NODE_ENV) === null || _c === void 0 ? void 0 : _c.trim()) === 'production' && exports.NETWORK == 'mainnet'
|
|
8
9
|
: !(window.location.host.includes('preview.') ||
|
|
9
10
|
window.location.host.includes('preprod.') ||
|
|
10
11
|
window.location.host.includes('localhost'));
|
package/errors/index.d.ts
CHANGED
|
@@ -2,3 +2,12 @@ export declare class OauthAccessError extends Error {
|
|
|
2
2
|
oauthErrorCode: string;
|
|
3
3
|
constructor(message: string, oauthErrorCode: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope');
|
|
4
4
|
}
|
|
5
|
+
export declare class ModelException extends Error {
|
|
6
|
+
message: string;
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class HttpException extends Error {
|
|
10
|
+
status: number;
|
|
11
|
+
message: string;
|
|
12
|
+
constructor(status: number, message: string);
|
|
13
|
+
}
|
package/errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OauthAccessError = void 0;
|
|
3
|
+
exports.HttpException = exports.ModelException = exports.OauthAccessError = void 0;
|
|
4
4
|
class OauthAccessError extends Error {
|
|
5
5
|
constructor(message, oauthErrorCode) {
|
|
6
6
|
super();
|
|
@@ -9,3 +9,18 @@ class OauthAccessError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.OauthAccessError = OauthAccessError;
|
|
12
|
+
class ModelException extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.message = message;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ModelException = ModelException;
|
|
19
|
+
class HttpException extends Error {
|
|
20
|
+
constructor(status, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.message = message;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.HttpException = HttpException;
|
package/handles/constants.d.ts
CHANGED
|
@@ -11,3 +11,12 @@ export declare const REGEX_HANDLE: RegExp;
|
|
|
11
11
|
export declare const REGEX_SUB_HANDLE: RegExp;
|
|
12
12
|
export declare const HANDLES_API_KEY: string;
|
|
13
13
|
export declare const KORA_USER_AGENT: string;
|
|
14
|
+
export declare enum ERROR_TEXT {
|
|
15
|
+
HANDLE_LIMIT_EXCEEDED = "'records_per_page' must be a number",
|
|
16
|
+
HANDLE_LIMIT_INVALID_FORMAT = "'records_per_page' can't be more than 1000",
|
|
17
|
+
HANDLE_SORT_INVALID = "'sort' must be 'desc' or 'asc'",
|
|
18
|
+
HANDLE_PAGE_INVALID = "'page' must be a number",
|
|
19
|
+
HANDLE_SLOT_NUMBER_INVALID = "'slot_number' must be a number",
|
|
20
|
+
HANDLE_PAGE_AND_SLOT_NUMBER_INVALID = "'page' and 'slot_number' can't be used together"
|
|
21
|
+
}
|
|
22
|
+
export declare const HANDLES_PER_PAGE_MAX = 1000;
|
package/handles/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
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.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.';
|
|
@@ -16,3 +16,13 @@ exports.REGEX_HANDLE = new RegExp(/^[a-zA-Z0-9_.-]{1,15}$/);
|
|
|
16
16
|
exports.REGEX_SUB_HANDLE = new RegExp(/(?:^[a-z0-9_.-]{1,15}$)|(?:^(?!.{29})[a-z0-9_.-]+@[a-z0-9_.-]{1,15}$)/g);
|
|
17
17
|
exports.HANDLES_API_KEY = constants_1.IS_PRODUCTION ? (_a = process.env.HANDLES_API_KEY) !== null && _a !== void 0 ? _a : '' : '';
|
|
18
18
|
exports.KORA_USER_AGENT = (_b = process.env.KORA_USER_AGENT) !== null && _b !== void 0 ? _b : '';
|
|
19
|
+
var ERROR_TEXT;
|
|
20
|
+
(function (ERROR_TEXT) {
|
|
21
|
+
ERROR_TEXT["HANDLE_LIMIT_EXCEEDED"] = "'records_per_page' must be a number";
|
|
22
|
+
ERROR_TEXT["HANDLE_LIMIT_INVALID_FORMAT"] = "'records_per_page' can't be more than 1000";
|
|
23
|
+
ERROR_TEXT["HANDLE_SORT_INVALID"] = "'sort' must be 'desc' or 'asc'";
|
|
24
|
+
ERROR_TEXT["HANDLE_PAGE_INVALID"] = "'page' must be a number";
|
|
25
|
+
ERROR_TEXT["HANDLE_SLOT_NUMBER_INVALID"] = "'slot_number' must be a number";
|
|
26
|
+
ERROR_TEXT["HANDLE_PAGE_AND_SLOT_NUMBER_INVALID"] = "'page' and 'slot_number' can't be used together";
|
|
27
|
+
})(ERROR_TEXT = exports.ERROR_TEXT || (exports.ERROR_TEXT = {}));
|
|
28
|
+
exports.HANDLES_PER_PAGE_MAX = 1000;
|
package/handles/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './interfaces';
|
|
2
|
+
export * from './interfaces/api';
|
|
3
|
+
export * from './interfaces/handlesRepository';
|
|
2
4
|
export * from './constants';
|
|
3
5
|
export * from './api';
|
|
4
6
|
export * from './policies';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export { checkHandlePattern } from './validation';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
export * from './models';
|
package/handles/index.js
CHANGED
|
@@ -14,14 +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
|
-
exports.checkHandlePattern = exports.buildMetadata = exports.getRarity = void 0;
|
|
18
17
|
__exportStar(require("./interfaces"), exports);
|
|
18
|
+
__exportStar(require("./interfaces/api"), exports);
|
|
19
|
+
__exportStar(require("./interfaces/handlesRepository"), exports);
|
|
19
20
|
__exportStar(require("./constants"), exports);
|
|
20
21
|
__exportStar(require("./api"), exports);
|
|
21
22
|
__exportStar(require("./policies"), exports);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var buildMetadata_1 = require("./buildMetadata");
|
|
25
|
-
Object.defineProperty(exports, "buildMetadata", { enumerable: true, get: function () { return buildMetadata_1.buildMetadata; } });
|
|
26
|
-
var validation_1 = require("./validation");
|
|
27
|
-
Object.defineProperty(exports, "checkHandlePattern", { enumerable: true, get: function () { return validation_1.checkHandlePattern; } });
|
|
23
|
+
__exportStar(require("./utils"), exports);
|
|
24
|
+
__exportStar(require("./models"), exports);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { IPersonalization, IPersonalizedHandle, IHandleMetadata, IUTxO, IReferenceToken, HandleType, ISubHandleSettings, IPzDatumConvertedUsingSchema } from '.';
|
|
2
|
+
export interface SubHandleSettings {
|
|
3
|
+
settings: ISubHandleSettings;
|
|
4
|
+
utxo: IUTxO;
|
|
5
|
+
}
|
|
6
|
+
export interface StoredHandle extends IPersonalizedHandle {
|
|
7
|
+
amount: number;
|
|
8
|
+
default?: boolean;
|
|
9
|
+
pz_enabled?: boolean;
|
|
10
|
+
resolved_addresses: {
|
|
11
|
+
ada: string;
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
14
|
+
payment_key_hash: string;
|
|
15
|
+
subhandle_settings?: {
|
|
16
|
+
settings?: string;
|
|
17
|
+
utxo: IUTxO;
|
|
18
|
+
};
|
|
19
|
+
sub_rarity?: string;
|
|
20
|
+
sub_length?: number;
|
|
21
|
+
sub_characters?: string;
|
|
22
|
+
sub_numeric_modifiers?: string;
|
|
23
|
+
virtual?: {
|
|
24
|
+
expires_time: number;
|
|
25
|
+
public_mint: boolean;
|
|
26
|
+
};
|
|
27
|
+
original_address?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface HandleHistory {
|
|
30
|
+
old: Partial<StoredHandle> | null;
|
|
31
|
+
new?: Partial<StoredHandle> | null;
|
|
32
|
+
}
|
|
33
|
+
export interface ISlotHistoryIndex {
|
|
34
|
+
[handleHex: string]: HandleHistory;
|
|
35
|
+
}
|
|
36
|
+
export interface IHandleStoreMetrics {
|
|
37
|
+
firstSlot?: number;
|
|
38
|
+
lastSlot?: number;
|
|
39
|
+
currentSlot?: number;
|
|
40
|
+
elapsedOgmiosExec?: number;
|
|
41
|
+
elapsedBuildingExec?: number;
|
|
42
|
+
firstMemoryUsage?: number;
|
|
43
|
+
currentBlockHash?: string;
|
|
44
|
+
tipBlockHash?: string;
|
|
45
|
+
memorySize?: number;
|
|
46
|
+
networkSync?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface SaveMintingTxInput {
|
|
49
|
+
hex: string;
|
|
50
|
+
name: string;
|
|
51
|
+
adaAddress: string;
|
|
52
|
+
og_number: number;
|
|
53
|
+
image: string;
|
|
54
|
+
image_hash?: string;
|
|
55
|
+
slotNumber: number;
|
|
56
|
+
utxo: string;
|
|
57
|
+
lovelace: number;
|
|
58
|
+
svg_version?: string;
|
|
59
|
+
bg_image?: string;
|
|
60
|
+
pfp_image?: string;
|
|
61
|
+
datum?: string;
|
|
62
|
+
script?: {
|
|
63
|
+
type: string;
|
|
64
|
+
cbor: string;
|
|
65
|
+
};
|
|
66
|
+
last_update_address?: string;
|
|
67
|
+
personalization?: IPersonalization;
|
|
68
|
+
reference_token?: IReferenceToken;
|
|
69
|
+
resolved_addresses?: Record<string, string>;
|
|
70
|
+
amount?: number;
|
|
71
|
+
version?: number;
|
|
72
|
+
handle_type: HandleType;
|
|
73
|
+
sub_rarity?: string;
|
|
74
|
+
sub_length?: number;
|
|
75
|
+
sub_characters?: string;
|
|
76
|
+
sub_numeric_modifiers?: string;
|
|
77
|
+
virtual?: {
|
|
78
|
+
expires_time: number;
|
|
79
|
+
public_mint: boolean;
|
|
80
|
+
};
|
|
81
|
+
original_address?: string;
|
|
82
|
+
pz_enabled?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface SaveWalletAddressMoveInput {
|
|
85
|
+
slotNumber: number;
|
|
86
|
+
name: string;
|
|
87
|
+
adaAddress: string;
|
|
88
|
+
utxo: string;
|
|
89
|
+
datum?: string;
|
|
90
|
+
script?: {
|
|
91
|
+
type: string;
|
|
92
|
+
cbor: string;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export interface SavePersonalizationInput {
|
|
96
|
+
slotNumber: number;
|
|
97
|
+
hex: string;
|
|
98
|
+
name: string;
|
|
99
|
+
personalization: IPersonalization;
|
|
100
|
+
reference_token: IReferenceToken;
|
|
101
|
+
personalizationDatum: IPzDatumConvertedUsingSchema | null;
|
|
102
|
+
metadata: IHandleMetadata | null;
|
|
103
|
+
}
|
|
104
|
+
export interface SaveSubHandleSettingsInput {
|
|
105
|
+
name: string;
|
|
106
|
+
settingsDatum?: string;
|
|
107
|
+
utxoDetails: IUTxO;
|
|
108
|
+
slotNumber: number;
|
|
109
|
+
}
|
|
110
|
+
export interface HolderAddressIndex {
|
|
111
|
+
handles: Set<string>;
|
|
112
|
+
defaultHandle: string;
|
|
113
|
+
manuallySet: boolean;
|
|
114
|
+
type: string;
|
|
115
|
+
knownOwnerName: string;
|
|
116
|
+
}
|
|
117
|
+
export interface HolderAddressDetails {
|
|
118
|
+
total_handles: number;
|
|
119
|
+
address: string;
|
|
120
|
+
type: string;
|
|
121
|
+
known_owner_name: string;
|
|
122
|
+
default_handle: string;
|
|
123
|
+
manually_set: boolean;
|
|
124
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { IHandleStats, IUTxO } from '..';
|
|
2
|
+
import { HolderAddressDetails } from './api';
|
|
3
|
+
import { HandlePaginationModel } from '../models/handlePagination.model';
|
|
4
|
+
import { HandleSearchModel } from '../models/handleSearch.model';
|
|
5
|
+
import { HolderPaginationModel } from '../models/holderPagination.model';
|
|
6
|
+
import { IHandleStoreMetrics, SaveMintingTxInput, SavePersonalizationInput, SaveSubHandleSettingsInput, SaveWalletAddressMoveInput, StoredHandle } from './api';
|
|
7
|
+
export interface IHandlesRepository {
|
|
8
|
+
initialize: () => Promise<IHandlesRepository>;
|
|
9
|
+
getAll: (params: {
|
|
10
|
+
pagination: HandlePaginationModel;
|
|
11
|
+
search: HandleSearchModel;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
searchTotal: number;
|
|
14
|
+
handles: StoredHandle[];
|
|
15
|
+
}>;
|
|
16
|
+
getHandlesByPaymentKeyHashes: (hashes: string[]) => string[];
|
|
17
|
+
getHandlesByAddresses: (addresses: string[]) => string[];
|
|
18
|
+
getHandlesByHolderAddresses: (addresses: 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
|
+
prepareHandlesStorage: (loadS3: boolean) => Promise<{
|
|
45
|
+
slot: number;
|
|
46
|
+
hash: string;
|
|
47
|
+
} | null>;
|
|
48
|
+
rollBackToGenesis: () => Promise<void>;
|
|
49
|
+
isCaughtUp: () => boolean;
|
|
50
|
+
burnHandle: (handleName: string, slotNumber: number) => Promise<void>;
|
|
51
|
+
rewindChangesToSlot: ({ slot, hash, lastSlot }: {
|
|
52
|
+
slot: number;
|
|
53
|
+
hash: string;
|
|
54
|
+
lastSlot: number;
|
|
55
|
+
}) => Promise<{
|
|
56
|
+
name: string;
|
|
57
|
+
action: string;
|
|
58
|
+
handle: Partial<StoredHandle> | undefined;
|
|
59
|
+
}[]>;
|
|
60
|
+
savePersonalizationChange: ({ name, hex, personalization, reference_token, personalizationDatum, slotNumber, metadata }: SavePersonalizationInput) => Promise<void>;
|
|
61
|
+
saveSubHandleSettingsChange: ({ name, settingsDatum, utxoDetails, slotNumber }: SaveSubHandleSettingsInput) => Promise<void>;
|
|
62
|
+
saveMintedHandle: (input: SaveMintingTxInput) => Promise<void>;
|
|
63
|
+
saveHandleUpdate: ({ name, adaAddress, utxo, slotNumber, datum, script }: SaveWalletAddressMoveInput) => Promise<void>;
|
|
64
|
+
destroy: () => void;
|
|
65
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BoolInt, FeaturedItemType, HexString, HexStringOrEmpty } from '
|
|
1
|
+
import { BoolInt, FeaturedItemType, HexString, HexStringOrEmpty } from '../../types';
|
|
2
|
+
import { ISlotHistoryIndex, StoredHandle } from './api';
|
|
2
3
|
export declare enum Rarity {
|
|
3
4
|
basic = "basic",
|
|
4
5
|
common = "common",
|
|
@@ -202,7 +203,7 @@ export interface IPzDatum {
|
|
|
202
203
|
pfp_image?: string;
|
|
203
204
|
pfp_asset?: HexStringOrEmpty;
|
|
204
205
|
bg_asset?: HexStringOrEmpty;
|
|
205
|
-
last_edited_time
|
|
206
|
+
last_edited_time?: number;
|
|
206
207
|
portal?: string;
|
|
207
208
|
designer?: string;
|
|
208
209
|
socials?: string;
|
|
@@ -335,7 +336,8 @@ export interface IHandleFileContent {
|
|
|
335
336
|
slot: number;
|
|
336
337
|
hash: string;
|
|
337
338
|
schemaVersion?: number;
|
|
338
|
-
handles: Record<string,
|
|
339
|
+
handles: Record<string, StoredHandle>;
|
|
340
|
+
history: [number, ISlotHistoryIndex][];
|
|
339
341
|
}
|
|
340
342
|
export interface IHandleSvgOptions extends IPersonalizationDesigner {
|
|
341
343
|
pfp_image?: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SortWithRandom } from '../../types';
|
|
2
|
+
export interface HandlePaginationInput {
|
|
3
|
+
handlesPerPage?: string;
|
|
4
|
+
sort?: SortWithRandom;
|
|
5
|
+
page?: string;
|
|
6
|
+
slotNumber?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class HandlePaginationModel {
|
|
9
|
+
page: number;
|
|
10
|
+
handlesPerPage: number;
|
|
11
|
+
sort: SortWithRandom;
|
|
12
|
+
slotNumber?: number | null;
|
|
13
|
+
constructor(input?: HandlePaginationInput);
|
|
14
|
+
private validateHandlePagination;
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandlePaginationModel = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
class HandlePaginationModel {
|
|
8
|
+
constructor(input) {
|
|
9
|
+
const { handlesPerPage, sort, page, slotNumber } = input !== null && input !== void 0 ? input : {};
|
|
10
|
+
this.validateHandlePagination(handlesPerPage, sort, page, slotNumber);
|
|
11
|
+
this.handlesPerPage = handlesPerPage ? parseInt(handlesPerPage) : 100;
|
|
12
|
+
this.page = page ? parseInt(page) : 1;
|
|
13
|
+
this.sort = sort !== null && sort !== void 0 ? sort : 'asc';
|
|
14
|
+
this.slotNumber = slotNumber ? parseInt(slotNumber) : null;
|
|
15
|
+
}
|
|
16
|
+
validateHandlePagination(handlesPerPage, sort, page, slotNumber) {
|
|
17
|
+
if (handlesPerPage && !(0, utils_1.isNumeric)(handlesPerPage)) {
|
|
18
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_LIMIT_INVALID_FORMAT);
|
|
19
|
+
}
|
|
20
|
+
if (handlesPerPage && parseInt(handlesPerPage) > 1000) {
|
|
21
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_LIMIT_EXCEEDED);
|
|
22
|
+
}
|
|
23
|
+
if (page && !(0, utils_1.isNumeric)(page)) {
|
|
24
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_PAGE_INVALID);
|
|
25
|
+
}
|
|
26
|
+
if (sort && !['desc', 'asc', 'random'].includes(sort)) {
|
|
27
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_SORT_INVALID);
|
|
28
|
+
}
|
|
29
|
+
if (slotNumber && !(0, utils_1.isNumeric)(slotNumber)) {
|
|
30
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_SLOT_NUMBER_INVALID);
|
|
31
|
+
}
|
|
32
|
+
if (page && slotNumber) {
|
|
33
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_PAGE_AND_SLOT_NUMBER_INVALID);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.HandlePaginationModel = HandlePaginationModel;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
interface HandleSearchInput {
|
|
2
|
+
characters?: string;
|
|
3
|
+
length?: string;
|
|
4
|
+
rarity?: string;
|
|
5
|
+
numeric_modifiers?: string;
|
|
6
|
+
search?: string;
|
|
7
|
+
holder_address?: string;
|
|
8
|
+
personalized?: boolean;
|
|
9
|
+
handle_type?: string;
|
|
10
|
+
og?: string;
|
|
11
|
+
handles?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare class HandleSearchModel {
|
|
14
|
+
private _characters?;
|
|
15
|
+
private _length?;
|
|
16
|
+
private _rarity?;
|
|
17
|
+
private _numeric_modifiers?;
|
|
18
|
+
private _search?;
|
|
19
|
+
private _holder_address?;
|
|
20
|
+
private _personalized?;
|
|
21
|
+
private _handle_type?;
|
|
22
|
+
private _og?;
|
|
23
|
+
private _handles?;
|
|
24
|
+
constructor(input?: HandleSearchInput);
|
|
25
|
+
get characters(): string | undefined;
|
|
26
|
+
set characters(value: string | undefined);
|
|
27
|
+
get rarity(): string | undefined;
|
|
28
|
+
set rarity(value: string | undefined);
|
|
29
|
+
get handle_type(): string | undefined;
|
|
30
|
+
set handle_type(value: string | undefined);
|
|
31
|
+
get length(): string | undefined;
|
|
32
|
+
set length(value: string | undefined);
|
|
33
|
+
get numeric_modifiers(): string | undefined;
|
|
34
|
+
set numeric_modifiers(value: string | undefined);
|
|
35
|
+
get search(): string | undefined;
|
|
36
|
+
set search(value: string | undefined);
|
|
37
|
+
get holder_address(): string | undefined;
|
|
38
|
+
set holder_address(value: string | undefined);
|
|
39
|
+
get personalized(): boolean | undefined;
|
|
40
|
+
set personalized(value: boolean | undefined);
|
|
41
|
+
get og(): boolean | undefined;
|
|
42
|
+
set og(value: boolean | undefined);
|
|
43
|
+
get handles(): string[] | undefined;
|
|
44
|
+
set handles(value: string[] | undefined);
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleSearchModel = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
class HandleSearchModel {
|
|
8
|
+
constructor(input) {
|
|
9
|
+
const { characters, length, rarity, numeric_modifiers, search, holder_address, og, personalized, handle_type, handles } = input !== null && input !== void 0 ? input : {};
|
|
10
|
+
this.characters = characters;
|
|
11
|
+
this.length = length;
|
|
12
|
+
this.rarity = rarity;
|
|
13
|
+
this.numeric_modifiers = numeric_modifiers;
|
|
14
|
+
this.search = search;
|
|
15
|
+
this.holder_address = holder_address;
|
|
16
|
+
this.personalized = personalized;
|
|
17
|
+
this.handle_type = handle_type;
|
|
18
|
+
this.og = og === 'true';
|
|
19
|
+
this.handles = handles;
|
|
20
|
+
}
|
|
21
|
+
get characters() {
|
|
22
|
+
return this._characters;
|
|
23
|
+
}
|
|
24
|
+
set characters(value) {
|
|
25
|
+
const validCharacters = ['letters', 'numbers', 'special'];
|
|
26
|
+
if (value && !validCharacters.some((v) => value.split(',').includes(v))) {
|
|
27
|
+
throw new errors_1.ModelException(`characters must be ${validCharacters.join(', ')}`);
|
|
28
|
+
}
|
|
29
|
+
this._characters = value;
|
|
30
|
+
}
|
|
31
|
+
get rarity() {
|
|
32
|
+
return this._rarity;
|
|
33
|
+
}
|
|
34
|
+
set rarity(value) {
|
|
35
|
+
const validRarity = Object.values(__1.Rarity);
|
|
36
|
+
if (value && !validRarity.some((v) => value.split(',').includes(v))) {
|
|
37
|
+
throw new errors_1.ModelException(`rarity must be ${validRarity.join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
this._rarity = value;
|
|
40
|
+
}
|
|
41
|
+
get handle_type() {
|
|
42
|
+
return this._handle_type;
|
|
43
|
+
}
|
|
44
|
+
set handle_type(value) {
|
|
45
|
+
const validHandleType = Object.values(__1.HandleType);
|
|
46
|
+
if (value && !validHandleType.some((v) => value.split(',').includes(v))) {
|
|
47
|
+
throw new errors_1.ModelException(`handle_type must be ${validHandleType.join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
this._handle_type = value;
|
|
50
|
+
}
|
|
51
|
+
get length() {
|
|
52
|
+
return this._length;
|
|
53
|
+
}
|
|
54
|
+
set length(value) {
|
|
55
|
+
const lengthMErrorMsg = "Length must be a number or a range of numbers (ex: 1-28) and can't exceed 28";
|
|
56
|
+
if (!value) {
|
|
57
|
+
this._length = value;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let minLength = value;
|
|
61
|
+
let maxLength = value;
|
|
62
|
+
if (value === null || value === void 0 ? void 0 : value.includes('-')) {
|
|
63
|
+
minLength = value.split('-')[0];
|
|
64
|
+
maxLength = value.split('-')[1];
|
|
65
|
+
}
|
|
66
|
+
if (!(0, utils_1.isNumeric)(minLength) || !(0, utils_1.isNumeric)(maxLength)) {
|
|
67
|
+
throw new errors_1.ModelException(lengthMErrorMsg);
|
|
68
|
+
}
|
|
69
|
+
if (parseInt(minLength) > 28 || parseInt(maxLength) > 28) {
|
|
70
|
+
throw new errors_1.ModelException(lengthMErrorMsg);
|
|
71
|
+
}
|
|
72
|
+
if (parseInt(minLength) > parseInt(maxLength)) {
|
|
73
|
+
throw new errors_1.ModelException('Invalid length range');
|
|
74
|
+
}
|
|
75
|
+
this._length = value;
|
|
76
|
+
}
|
|
77
|
+
get numeric_modifiers() {
|
|
78
|
+
return this._numeric_modifiers;
|
|
79
|
+
}
|
|
80
|
+
set numeric_modifiers(value) {
|
|
81
|
+
const validModifiers = ['negative', 'decimal'];
|
|
82
|
+
if (value && !validModifiers.some((v) => value.split(',').includes(v))) {
|
|
83
|
+
throw new errors_1.ModelException(`numeric_modifiers must be ${validModifiers.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
this._numeric_modifiers = value;
|
|
86
|
+
}
|
|
87
|
+
get search() {
|
|
88
|
+
return this._search;
|
|
89
|
+
}
|
|
90
|
+
set search(value) {
|
|
91
|
+
if (value && value.length < 3) {
|
|
92
|
+
throw new errors_1.ModelException('search must be at least 3 characters');
|
|
93
|
+
}
|
|
94
|
+
this._search = value;
|
|
95
|
+
}
|
|
96
|
+
get holder_address() {
|
|
97
|
+
return this._holder_address;
|
|
98
|
+
}
|
|
99
|
+
set holder_address(value) {
|
|
100
|
+
this._holder_address = value;
|
|
101
|
+
}
|
|
102
|
+
get personalized() {
|
|
103
|
+
return this._personalized;
|
|
104
|
+
}
|
|
105
|
+
set personalized(value) {
|
|
106
|
+
this._personalized = value;
|
|
107
|
+
}
|
|
108
|
+
get og() {
|
|
109
|
+
return this._og;
|
|
110
|
+
}
|
|
111
|
+
set og(value) {
|
|
112
|
+
this._og = value;
|
|
113
|
+
}
|
|
114
|
+
get handles() {
|
|
115
|
+
return this._handles;
|
|
116
|
+
}
|
|
117
|
+
set handles(value) {
|
|
118
|
+
if (value && !Array.isArray(value)) {
|
|
119
|
+
throw new errors_1.ModelException(`expected array and received ${typeof value}`);
|
|
120
|
+
}
|
|
121
|
+
this._handles = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.HandleSearchModel = HandleSearchModel;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Sort } from '../../types';
|
|
2
|
+
export interface HolderPaginationInput {
|
|
3
|
+
recordsPerPage?: string;
|
|
4
|
+
sort?: Sort;
|
|
5
|
+
page?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class HolderPaginationModel {
|
|
8
|
+
page: number;
|
|
9
|
+
recordsPerPage: number;
|
|
10
|
+
sort: Sort;
|
|
11
|
+
constructor(input?: HolderPaginationInput);
|
|
12
|
+
private validateHolderPagination;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HolderPaginationModel = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
class HolderPaginationModel {
|
|
8
|
+
constructor(input) {
|
|
9
|
+
const { recordsPerPage, sort, page } = input !== null && input !== void 0 ? input : {};
|
|
10
|
+
this.validateHolderPagination(recordsPerPage, sort, page);
|
|
11
|
+
this.recordsPerPage = recordsPerPage ? parseInt(recordsPerPage) : 100;
|
|
12
|
+
this.page = page ? parseInt(page) : 1;
|
|
13
|
+
this.sort = sort !== null && sort !== void 0 ? sort : 'desc';
|
|
14
|
+
}
|
|
15
|
+
validateHolderPagination(recordsPerPage, sort, page) {
|
|
16
|
+
if (recordsPerPage && !(0, utils_1.isNumeric)(recordsPerPage)) {
|
|
17
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_LIMIT_INVALID_FORMAT);
|
|
18
|
+
}
|
|
19
|
+
if (recordsPerPage && parseInt(recordsPerPage) > 1000) {
|
|
20
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_LIMIT_EXCEEDED);
|
|
21
|
+
}
|
|
22
|
+
if (page && !(0, utils_1.isNumeric)(page)) {
|
|
23
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_PAGE_INVALID);
|
|
24
|
+
}
|
|
25
|
+
if (sort && !['desc', 'asc'].includes(sort)) {
|
|
26
|
+
throw new errors_1.ModelException(constants_1.ERROR_TEXT.HANDLE_SORT_INVALID);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.HolderPaginationModel = HolderPaginationModel;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./handleSearch.model"), exports);
|
|
18
|
+
__exportStar(require("./handlePagination.model"), exports);
|
|
19
|
+
__exportStar(require("./holderPagination.model"), exports);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { HandleType, IHandleMetadata } from './interfaces';
|
|
2
|
+
import { Rarity } from './interfaces';
|
|
3
|
+
export declare const getRarity: (name: string) => Rarity;
|
|
2
4
|
export declare const buildMetadata: ({ handleName, handleType, cid, ogNumber }: {
|
|
3
5
|
handleName: string;
|
|
4
6
|
handleType: HandleType;
|
|
5
7
|
cid: string;
|
|
6
8
|
ogNumber?: number | undefined;
|
|
7
9
|
}) => IHandleMetadata;
|
|
10
|
+
export declare const checkHandlePattern: (handle: string, root?: string) => {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildMetadata = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.checkHandlePattern = exports.buildMetadata = exports.getRarity = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const interfaces_1 = require("./interfaces");
|
|
6
|
+
const getRarity = (name) => {
|
|
7
|
+
const length = name.length;
|
|
8
|
+
if (1 === length) {
|
|
9
|
+
return interfaces_1.Rarity.legendary;
|
|
10
|
+
}
|
|
11
|
+
if (2 === length) {
|
|
12
|
+
return interfaces_1.Rarity.ultra_rare;
|
|
13
|
+
}
|
|
14
|
+
if (3 === length) {
|
|
15
|
+
return interfaces_1.Rarity.rare;
|
|
16
|
+
}
|
|
17
|
+
if (length > 3 && length < 8) {
|
|
18
|
+
return interfaces_1.Rarity.common;
|
|
19
|
+
}
|
|
20
|
+
return interfaces_1.Rarity.basic;
|
|
21
|
+
};
|
|
22
|
+
exports.getRarity = getRarity;
|
|
5
23
|
const buildCharacters = (name) => {
|
|
6
24
|
const characters = [];
|
|
7
25
|
if (/[a-z]+/.test(name)) {
|
|
@@ -36,7 +54,7 @@ const buildMetadata = ({ handleName, handleType, cid, ogNumber }) => {
|
|
|
36
54
|
mediaType: 'image/jpeg',
|
|
37
55
|
og: isSubHandle ? 0 : ogNumber ? 1 : 0,
|
|
38
56
|
og_number: isSubHandle ? 0 : ogNumber !== null && ogNumber !== void 0 ? ogNumber : 0,
|
|
39
|
-
rarity: (0,
|
|
57
|
+
rarity: (0, exports.getRarity)(rootHandleName !== null && rootHandleName !== void 0 ? rootHandleName : handleName),
|
|
40
58
|
length: handleName.length,
|
|
41
59
|
characters: buildCharacters(rootHandleName !== null && rootHandleName !== void 0 ? rootHandleName : handleName),
|
|
42
60
|
numeric_modifiers: buildNumericModifiers(rootHandleName !== null && rootHandleName !== void 0 ? rootHandleName : handleName),
|
|
@@ -46,7 +64,7 @@ const buildMetadata = ({ handleName, handleType, cid, ogNumber }) => {
|
|
|
46
64
|
if (isSubHandle) {
|
|
47
65
|
metadata = {
|
|
48
66
|
...metadata,
|
|
49
|
-
sub_rarity: (0,
|
|
67
|
+
sub_rarity: (0, exports.getRarity)(subHandleName),
|
|
50
68
|
sub_length: subHandleName.length,
|
|
51
69
|
sub_characters: buildCharacters(subHandleName),
|
|
52
70
|
sub_numeric_modifiers: buildNumericModifiers(subHandleName)
|
|
@@ -55,3 +73,23 @@ const buildMetadata = ({ handleName, handleType, cid, ogNumber }) => {
|
|
|
55
73
|
return metadata;
|
|
56
74
|
};
|
|
57
75
|
exports.buildMetadata = buildMetadata;
|
|
76
|
+
const checkHandlePattern = (handle, root) => {
|
|
77
|
+
handle = handle.toLowerCase();
|
|
78
|
+
if (handle.length <= 1) {
|
|
79
|
+
return {
|
|
80
|
+
valid: false,
|
|
81
|
+
message: constants_1.RESPONSE_UNAVAILABLE_LEGENDARY
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!handle.match(constants_1.REGEX_SUB_HANDLE) && (root ? handle.endsWith(`@${root}`) : true)) {
|
|
85
|
+
return {
|
|
86
|
+
valid: false,
|
|
87
|
+
message: constants_1.RESPONSE_INVALID_HANDLE_FORMAT
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
valid: true,
|
|
92
|
+
message: constants_1.RESPONSE_AVAILABLE
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
exports.checkHandlePattern = checkHandlePattern;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koralabs/kora-labs-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Kora Labs Common Utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "eslint . --ext .ts",
|
|
22
|
-
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
22
|
+
"test": "NETWORK=mainnet node --experimental-vm-modules node_modules/.bin/jest",
|
|
23
23
|
"build": "tsc",
|
|
24
24
|
"build:local": "yarn build && cp package.json ./lib/package.json && cd lib && npm i --production",
|
|
25
25
|
"npm:publish": "yarn build && cp package.json ./lib/package.json && (cd ./lib && npm publish)"
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"bech32": "^2.0.0",
|
|
44
44
|
"boolean": "^3.2.0",
|
|
45
|
+
"bs58": "^6.0.0",
|
|
45
46
|
"cbor": "^9.0.2",
|
|
47
|
+
"crc": "^4.3.2",
|
|
46
48
|
"pluralize-esm": "^9.0.5"
|
|
47
49
|
}
|
|
48
50
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -27,3 +27,21 @@ export declare enum CardanoNetwork {
|
|
|
27
27
|
UNSET = "UNSET"
|
|
28
28
|
}
|
|
29
29
|
export type Network = 'preview' | 'preprod' | 'mainnet';
|
|
30
|
+
export type Sort = 'asc' | 'desc';
|
|
31
|
+
export type SortWithRandom = 'asc' | 'desc' | 'random';
|
|
32
|
+
export declare enum AddressType {
|
|
33
|
+
Wallet = "wallet",
|
|
34
|
+
Enterprise = "enterprise",
|
|
35
|
+
Script = "script",
|
|
36
|
+
Reward = "reward",
|
|
37
|
+
Other = "other"
|
|
38
|
+
}
|
|
39
|
+
export declare enum StakeAddressType {
|
|
40
|
+
Script = "f",
|
|
41
|
+
Key = "e"
|
|
42
|
+
}
|
|
43
|
+
export interface AddressDetails {
|
|
44
|
+
address: string;
|
|
45
|
+
type: string;
|
|
46
|
+
knownOwnerName: string;
|
|
47
|
+
}
|
package/types/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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
|
-
exports.CardanoNetwork = exports.AssetNameLabel = void 0;
|
|
17
|
+
exports.StakeAddressType = exports.AddressType = exports.CardanoNetwork = exports.AssetNameLabel = void 0;
|
|
18
18
|
__exportStar(require("./gallery"), exports);
|
|
19
19
|
/**
|
|
20
20
|
* The Cip67Label is a string that is used to identify the asset type.
|
|
@@ -38,3 +38,16 @@ var CardanoNetwork;
|
|
|
38
38
|
CardanoNetwork["PREVIEW"] = "PREVIEW";
|
|
39
39
|
CardanoNetwork["UNSET"] = "UNSET";
|
|
40
40
|
})(CardanoNetwork = exports.CardanoNetwork || (exports.CardanoNetwork = {}));
|
|
41
|
+
var AddressType;
|
|
42
|
+
(function (AddressType) {
|
|
43
|
+
AddressType["Wallet"] = "wallet";
|
|
44
|
+
AddressType["Enterprise"] = "enterprise";
|
|
45
|
+
AddressType["Script"] = "script";
|
|
46
|
+
AddressType["Reward"] = "reward";
|
|
47
|
+
AddressType["Other"] = "other";
|
|
48
|
+
})(AddressType = exports.AddressType || (exports.AddressType = {}));
|
|
49
|
+
var StakeAddressType;
|
|
50
|
+
(function (StakeAddressType) {
|
|
51
|
+
StakeAddressType["Script"] = "f";
|
|
52
|
+
StakeAddressType["Key"] = "e";
|
|
53
|
+
})(StakeAddressType = exports.StakeAddressType || (exports.StakeAddressType = {}));
|
package/utils/crypto/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AddressDetails, AddressType, AssetNameLabel } from '../../types';
|
|
1
2
|
export declare const getNativeCrypto: () => Promise<any>;
|
|
2
3
|
export declare function dec2hex(dec: number): string;
|
|
3
4
|
export declare function getRandomCodeVerifier(length: number): Promise<string>;
|
|
@@ -5,3 +6,18 @@ export declare const sha256: (plain: string) => Promise<ArrayBuffer>;
|
|
|
5
6
|
export declare function base64urlencode(a: ArrayBuffer): string;
|
|
6
7
|
export declare function getChallengeFromVerifier(verifier: string): Promise<string>;
|
|
7
8
|
export declare const decodeAddress: (address: string) => string | null;
|
|
9
|
+
export declare const parseAssetNameLabel: (assetName: string) => AssetNameLabel | null;
|
|
10
|
+
export declare const checkNameLabel: (assetName: string) => {
|
|
11
|
+
isCip67: boolean;
|
|
12
|
+
assetLabel: string | null;
|
|
13
|
+
assetName: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const getPaymentAddressType: (headerByte: number) => AddressType;
|
|
16
|
+
export declare const buildPaymentAddressType: (address: string) => AddressType;
|
|
17
|
+
export declare const buildStakeKey: (address: string) => string | null;
|
|
18
|
+
export declare const getPaymentKeyHash: (address: string) => Promise<string | null>;
|
|
19
|
+
export declare const bech32FromHex: (hex: string, isTestnet?: boolean, type?: 'addr' | 'stake' | 'pool' | 'drep') => string;
|
|
20
|
+
export declare const getAddressHolderDetails: (addr: string) => AddressDetails;
|
|
21
|
+
export declare const checkKnownSmartContracts: (address: string, stake?: string | null) => string;
|
|
22
|
+
export declare const getDateStringFromSlot: (currentSlot: number) => Date;
|
|
23
|
+
export declare const getSlotNumberFromDate: (date: Date) => number;
|
package/utils/crypto/index.js
CHANGED
|
@@ -22,10 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.decodeAddress = exports.getChallengeFromVerifier = exports.base64urlencode = exports.sha256 = exports.getRandomCodeVerifier = exports.dec2hex = exports.getNativeCrypto = void 0;
|
|
27
|
-
const bech32_1 = require("bech32");
|
|
29
|
+
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;
|
|
28
30
|
const constants_1 = require("../../constants");
|
|
31
|
+
const types_1 = require("../../types");
|
|
32
|
+
const cbor_1 = require("../cbor");
|
|
33
|
+
const logger_1 = require("../../logger");
|
|
34
|
+
const bech32_1 = require("bech32");
|
|
35
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
36
|
+
const crc_1 = require("crc");
|
|
29
37
|
// var verifier = await getRandomCodeVerifier(64);
|
|
30
38
|
// var challenge = await getChallengeFromVerifier(verifier);
|
|
31
39
|
const getNativeCrypto = async () => {
|
|
@@ -83,3 +91,200 @@ const decodeAddress = (address) => {
|
|
|
83
91
|
}
|
|
84
92
|
};
|
|
85
93
|
exports.decodeAddress = decodeAddress;
|
|
94
|
+
const parseAssetNameLabel = (assetName) => {
|
|
95
|
+
for (const lbl in types_1.AssetNameLabel) {
|
|
96
|
+
if (assetName.startsWith(types_1.AssetNameLabel[lbl])) {
|
|
97
|
+
return lbl;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
};
|
|
102
|
+
exports.parseAssetNameLabel = parseAssetNameLabel;
|
|
103
|
+
const checkNameLabel = (assetName) => {
|
|
104
|
+
const assetNameString = typeof assetName === 'string' ? assetName : new TextDecoder().decode(assetName);
|
|
105
|
+
let isCip67 = false;
|
|
106
|
+
let assetLabel = null;
|
|
107
|
+
let actualAssetName = Buffer.from(assetName, 'hex').toString('utf8');
|
|
108
|
+
if (assetNameString.length >= 8) {
|
|
109
|
+
const maybeAssetLabel = assetNameString.slice(0, 8);
|
|
110
|
+
if (maybeAssetLabel.startsWith('0') && maybeAssetLabel.endsWith('0')) {
|
|
111
|
+
const label = maybeAssetLabel.slice(1, 5);
|
|
112
|
+
const check = maybeAssetLabel.slice(5, 7);
|
|
113
|
+
if ((0, crc_1.crc8)(Buffer.from(label, 'hex')).toString(16).padStart(2, '0') == check) {
|
|
114
|
+
isCip67 = true;
|
|
115
|
+
assetLabel = `${parseInt(label, 16).toString().padStart(3, '0')}`;
|
|
116
|
+
actualAssetName = Buffer.from(assetName.slice(8), 'hex').toString('utf8');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
isCip67,
|
|
122
|
+
assetLabel,
|
|
123
|
+
assetName: actualAssetName
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
exports.checkNameLabel = checkNameLabel;
|
|
127
|
+
const getPaymentAddressType = (headerByte) => {
|
|
128
|
+
// https://cips.cardano.org/cips/cip19/#shelleyaddresses
|
|
129
|
+
if (headerByte >= 8) {
|
|
130
|
+
return types_1.AddressType.Other;
|
|
131
|
+
}
|
|
132
|
+
else if (headerByte === 6) {
|
|
133
|
+
return types_1.AddressType.Enterprise;
|
|
134
|
+
}
|
|
135
|
+
else if (headerByte % 2 === 0) {
|
|
136
|
+
return types_1.AddressType.Wallet;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return types_1.AddressType.Script;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.getPaymentAddressType = getPaymentAddressType;
|
|
143
|
+
const getDelegationAddressType = (headerByte) => {
|
|
144
|
+
if (headerByte === 2 || headerByte === 3) {
|
|
145
|
+
return types_1.StakeAddressType.Script;
|
|
146
|
+
}
|
|
147
|
+
return types_1.StakeAddressType.Key;
|
|
148
|
+
};
|
|
149
|
+
const buildPaymentAddressType = (address) => {
|
|
150
|
+
const decoded = (0, exports.decodeAddress)(address);
|
|
151
|
+
if (!decoded) {
|
|
152
|
+
return types_1.AddressType.Other;
|
|
153
|
+
}
|
|
154
|
+
const [c] = decoded;
|
|
155
|
+
const parsedChar = parseInt(c);
|
|
156
|
+
if (isNaN(parsedChar)) {
|
|
157
|
+
if (['e', 'f'].includes(c)) {
|
|
158
|
+
return types_1.AddressType.Reward;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return types_1.AddressType.Other;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const addressType = (0, exports.getPaymentAddressType)(parsedChar);
|
|
165
|
+
return addressType;
|
|
166
|
+
};
|
|
167
|
+
exports.buildPaymentAddressType = buildPaymentAddressType;
|
|
168
|
+
const buildStakeKey = (address) => {
|
|
169
|
+
try {
|
|
170
|
+
const decoded = (0, exports.decodeAddress)(address);
|
|
171
|
+
if (!decoded || decoded.length !== 114)
|
|
172
|
+
return null;
|
|
173
|
+
const [c] = decoded;
|
|
174
|
+
const parsedChar = parseInt(c);
|
|
175
|
+
const isTestnet = address.startsWith('addr_test');
|
|
176
|
+
const prefix = isTestnet ? 'stake_test' : 'stake';
|
|
177
|
+
const delegationType = `${getDelegationAddressType(parsedChar)}${isTestnet ? '0' : '1'}`;
|
|
178
|
+
// stake part of the address is the last 56 bytes
|
|
179
|
+
const stakeAddressDecoded = delegationType + decoded.slice(decoded.length - 56);
|
|
180
|
+
const stakeAddress = bech32_1.bech32.encode(prefix, bech32_1.bech32.toWords(Uint8Array.from(Buffer.from(stakeAddressDecoded, 'hex'))), 54 + prefix.length);
|
|
181
|
+
return stakeAddress;
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
logger_1.Logger.log(`Error building stake key ${error.message}`);
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
exports.buildStakeKey = buildStakeKey;
|
|
189
|
+
const getPaymentKeyHash = async (address) => {
|
|
190
|
+
try {
|
|
191
|
+
const decoded = (0, exports.decodeAddress)(address);
|
|
192
|
+
if (!decoded) {
|
|
193
|
+
try {
|
|
194
|
+
// Try Byron addresses
|
|
195
|
+
const jsonAddress = await (0, cbor_1.decodeCborToJson)({ cborString: Buffer.from(bs58_1.default.decode(address)).toString('hex') });
|
|
196
|
+
const innerAddress = await (0, cbor_1.decodeCborToJson)({ cborString: jsonAddress[0].value.toString('hex') });
|
|
197
|
+
return innerAddress[0].toString('hex').slice(2);
|
|
198
|
+
}
|
|
199
|
+
catch (_a) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return decoded.slice(2, 58);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
logger_1.Logger.log(`Error getting payment key ${error.message}`);
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.getPaymentKeyHash = getPaymentKeyHash;
|
|
213
|
+
const bech32FromHex = (hex, isTestnet = !constants_1.IS_PRODUCTION, type = 'addr') => {
|
|
214
|
+
const prefix = isTestnet ? `${type}_test` : type;
|
|
215
|
+
const bytes = Uint8Array.from(Buffer.from(hex, 'hex'));
|
|
216
|
+
const words = bech32_1.bech32.toWords(bytes);
|
|
217
|
+
return bech32_1.bech32.encode(prefix, words, bytes.length * 2 + prefix.length);
|
|
218
|
+
};
|
|
219
|
+
exports.bech32FromHex = bech32FromHex;
|
|
220
|
+
const getAddressHolderDetails = (addr) => {
|
|
221
|
+
const addressType = (0, exports.buildPaymentAddressType)(addr);
|
|
222
|
+
let knownOwnerName = (0, exports.checkKnownSmartContracts)(addr);
|
|
223
|
+
let stakeKey = null;
|
|
224
|
+
if (addressType === types_1.AddressType.Wallet || addressType === types_1.AddressType.Script) {
|
|
225
|
+
stakeKey = (0, exports.buildStakeKey)(addr);
|
|
226
|
+
knownOwnerName = (0, exports.checkKnownSmartContracts)(addr, stakeKey);
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
address: stakeKey !== null && stakeKey !== void 0 ? stakeKey : addr,
|
|
230
|
+
type: addressType,
|
|
231
|
+
knownOwnerName
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
exports.getAddressHolderDetails = getAddressHolderDetails;
|
|
235
|
+
const checkKnownSmartContracts = (address, stake) => {
|
|
236
|
+
switch (address) {
|
|
237
|
+
case 'addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3':
|
|
238
|
+
return 'jpg.store';
|
|
239
|
+
case 'addr1w9yr0zr530tp9yzrhly8lw5upddu0eym3yh0mjwa0qlr9pgmkzgv0':
|
|
240
|
+
case 'addr1w89s3lfv7gkugker5llecq6x3k2vjvfnvp4692laeqe6w6s93vj3j':
|
|
241
|
+
case 'addr1wx38kptjhuurcag7zdvh5cq98rjxt0ulf6ed7jtmz5gpkfcgjyyx3':
|
|
242
|
+
return 'cnft.io';
|
|
243
|
+
case 'addr1wyd3phmr5lhv3zssawqjdpnqrm5r5kgppmmf7864p3dvdrqwuutk4':
|
|
244
|
+
return 'epoch.art';
|
|
245
|
+
case 'addr1wxkqxmfkt6jas8mul0luqea8c5vsg8reu3ak3v9cswmm6yg2u9mrh':
|
|
246
|
+
return 'freeroam.io';
|
|
247
|
+
case 'addr1wxx0w0ku3jz8hz5dakg982lh22xx6q7z2z7vh0dt34uzghqrxdhqq':
|
|
248
|
+
return 'Cardahub.io';
|
|
249
|
+
case 'addr1wywukn5q6lxsa5uymffh2esuk8s8fel7a0tna63rdntgrysv0f3ms':
|
|
250
|
+
return 'Artifct';
|
|
251
|
+
case 'addr1wxz62xuzeujtuuzn2ewkrzwmm2pf79kfc84lrnjsd9ja2jscv3gy0':
|
|
252
|
+
return 'Genesis House';
|
|
253
|
+
case 'addr1wydpsqf5zz9ddy76d3f3jrrf6jkpyjr48nx5a706w9y68ucy4wu6s':
|
|
254
|
+
return 'Yummi-Staking';
|
|
255
|
+
case 'addr1wyl5fauf4m4thqze74kvxk8efcj4n7qjx005v33ympj7uwsscprfk':
|
|
256
|
+
return 'Tokhun';
|
|
257
|
+
case 'stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6':
|
|
258
|
+
return 'jpg.store';
|
|
259
|
+
}
|
|
260
|
+
switch (stake) {
|
|
261
|
+
case 'stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6':
|
|
262
|
+
return 'jpg.store';
|
|
263
|
+
}
|
|
264
|
+
return '';
|
|
265
|
+
};
|
|
266
|
+
exports.checkKnownSmartContracts = checkKnownSmartContracts;
|
|
267
|
+
const getDateStringFromSlot = (currentSlot) => {
|
|
268
|
+
// TODO: Make this work for all networks
|
|
269
|
+
//console.log(`preview slot date = ${new Date(currentSlot * 1000)}`)
|
|
270
|
+
if (constants_1.NETWORK == 'preview') {
|
|
271
|
+
return new Date((1666656000 + currentSlot) * 1000);
|
|
272
|
+
}
|
|
273
|
+
if (constants_1.NETWORK == 'preprod') {
|
|
274
|
+
return new Date((1654041600 + currentSlot) * 1000);
|
|
275
|
+
}
|
|
276
|
+
return new Date((1596491091 + (currentSlot - 4924800)) * 1000);
|
|
277
|
+
};
|
|
278
|
+
exports.getDateStringFromSlot = getDateStringFromSlot;
|
|
279
|
+
const getSlotNumberFromDate = (date) => {
|
|
280
|
+
if (constants_1.NETWORK == 'preview') {
|
|
281
|
+
return Math.floor(date.getTime() / 1000) - 1666656000;
|
|
282
|
+
}
|
|
283
|
+
if (constants_1.NETWORK == 'preprod') {
|
|
284
|
+
return Math.floor(date.getTime() / 1000) - 1654041600;
|
|
285
|
+
}
|
|
286
|
+
// Ignore parens to show intent
|
|
287
|
+
// prettier-ignore
|
|
288
|
+
return (Math.floor(date.getTime() / 1000) - 1596491091) + 4924800;
|
|
289
|
+
};
|
|
290
|
+
exports.getSlotNumberFromDate = getSlotNumberFromDate;
|
package/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AssetNameLabel } from '../types';
|
|
2
1
|
export declare const delay: (ms: number) => Promise<void>;
|
|
3
2
|
export declare const toLovelace: (adaAmount: number) => number;
|
|
4
3
|
export declare const toADA: (lovelaceAmount: number) => number;
|
|
@@ -10,6 +9,14 @@ export declare const isNullEmptyOrUndefined: (value: any) => boolean;
|
|
|
10
9
|
export declare const isAlphaNumeric: (str: string) => boolean;
|
|
11
10
|
export declare const getDateFromSlot: (currentSlot: number, network?: string) => number;
|
|
12
11
|
export declare const getSlotNumberFromDate: (date: Date, network?: string) => number;
|
|
13
|
-
export declare const
|
|
12
|
+
export declare const getElapsedTime: (milliseconds: number) => string;
|
|
13
|
+
export declare const objectHasKeys: (o: any) => boolean;
|
|
14
|
+
export declare const isEmpty: (obj: any) => boolean;
|
|
15
|
+
export declare const isObject: (o: any) => boolean;
|
|
16
|
+
export declare const hasOwnProperty: (o: any, v: PropertyKey) => boolean;
|
|
17
|
+
export declare const isDate: (d: any) => boolean;
|
|
18
|
+
export declare const isEmptyObject: (o: any) => boolean;
|
|
19
|
+
export declare const makeObjectWithoutPrototype: () => any;
|
|
20
|
+
export declare const diff: (lhs: any, rhs: any) => any;
|
|
14
21
|
export { DefaultTextFormat as KeyType, encodeJsonToDatum, decodeCborToJson } from './cbor';
|
|
15
22
|
export * from './crypto';
|
package/utils/index.js
CHANGED
|
@@ -14,8 +14,7 @@ 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
|
-
exports.decodeCborToJson = exports.encodeJsonToDatum = exports.KeyType = exports.
|
|
18
|
-
const types_1 = require("../types");
|
|
17
|
+
exports.decodeCborToJson = exports.encodeJsonToDatum = exports.KeyType = exports.diff = exports.makeObjectWithoutPrototype = exports.isEmptyObject = exports.isDate = exports.hasOwnProperty = exports.isObject = exports.isEmpty = exports.objectHasKeys = exports.getElapsedTime = exports.getSlotNumberFromDate = exports.getDateFromSlot = exports.isAlphaNumeric = exports.isNullEmptyOrUndefined = exports.isNumeric = exports.asyncForEach = exports.awaitForEach = exports.chunk = exports.toADA = exports.toLovelace = exports.delay = void 0;
|
|
19
18
|
const delay = (ms) => {
|
|
20
19
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
20
|
};
|
|
@@ -89,15 +88,61 @@ const getSlotNumberFromDate = (date, network) => {
|
|
|
89
88
|
return (Math.floor(date.getTime() / 1000) - 1596491091) + 4924800;
|
|
90
89
|
};
|
|
91
90
|
exports.getSlotNumberFromDate = getSlotNumberFromDate;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
const getElapsedTime = (milliseconds) => {
|
|
92
|
+
const seconds = Math.floor(milliseconds / 1000);
|
|
93
|
+
const mins = Math.floor(seconds / 60);
|
|
94
|
+
return `${mins}:${(seconds - mins * 60).toString().padStart(2, '0')}`;
|
|
95
|
+
};
|
|
96
|
+
exports.getElapsedTime = getElapsedTime;
|
|
97
|
+
const objectHasKeys = (o) => Object.keys(o).length === 0;
|
|
98
|
+
exports.objectHasKeys = objectHasKeys;
|
|
99
|
+
const isEmpty = (obj) => [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;
|
|
100
|
+
exports.isEmpty = isEmpty;
|
|
101
|
+
const isObject = (o) => o != null && typeof o === 'object';
|
|
102
|
+
exports.isObject = isObject;
|
|
103
|
+
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
104
|
+
exports.hasOwnProperty = hasOwnProperty;
|
|
105
|
+
const isDate = (d) => d instanceof Date;
|
|
106
|
+
exports.isDate = isDate;
|
|
107
|
+
const isEmptyObject = (o) => (0, exports.isObject)(o) && (0, exports.objectHasKeys)(o);
|
|
108
|
+
exports.isEmptyObject = isEmptyObject;
|
|
109
|
+
const makeObjectWithoutPrototype = () => Object.create(null);
|
|
110
|
+
exports.makeObjectWithoutPrototype = makeObjectWithoutPrototype;
|
|
111
|
+
const diff = (lhs, rhs) => {
|
|
112
|
+
if (lhs === rhs)
|
|
113
|
+
return {}; // equal return no diff
|
|
114
|
+
if (!(0, exports.isObject)(lhs) || !(0, exports.isObject)(rhs))
|
|
115
|
+
return rhs; // return updated rhs
|
|
116
|
+
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
117
|
+
if (!(0, exports.hasOwnProperty)(rhs, key)) {
|
|
118
|
+
acc[key] = undefined;
|
|
96
119
|
}
|
|
120
|
+
return acc;
|
|
121
|
+
}, (0, exports.makeObjectWithoutPrototype)());
|
|
122
|
+
if ((0, exports.isDate)(lhs) || (0, exports.isDate)(rhs)) {
|
|
123
|
+
if (lhs.valueOf() == rhs.valueOf())
|
|
124
|
+
return {};
|
|
125
|
+
return rhs;
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(lhs) || Array.isArray(rhs)) {
|
|
128
|
+
if (lhs.length === rhs.length && JSON.stringify(lhs) === JSON.stringify(rhs))
|
|
129
|
+
return {}; // return no diff
|
|
130
|
+
return rhs; // return updated rhs
|
|
97
131
|
}
|
|
98
|
-
return
|
|
132
|
+
return Object.keys(rhs).reduce((acc, key) => {
|
|
133
|
+
if (!(0, exports.hasOwnProperty)(lhs, key)) {
|
|
134
|
+
acc[key] = rhs[key]; // return added r key
|
|
135
|
+
return acc;
|
|
136
|
+
}
|
|
137
|
+
const difference = (0, exports.diff)(lhs[key], rhs[key]);
|
|
138
|
+
// If the difference is empty, and the lhs is an empty object or the rhs is not an empty object
|
|
139
|
+
if ((0, exports.isEmptyObject)(difference) && !(0, exports.isDate)(difference) && ((0, exports.isEmptyObject)(lhs[key]) || !(0, exports.isEmptyObject)(rhs[key])))
|
|
140
|
+
return acc; // return no diff
|
|
141
|
+
acc[key] = difference; // return updated key
|
|
142
|
+
return acc; // return updated key
|
|
143
|
+
}, deletedValues);
|
|
99
144
|
};
|
|
100
|
-
exports.
|
|
145
|
+
exports.diff = diff;
|
|
101
146
|
var cbor_1 = require("./cbor");
|
|
102
147
|
Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return cbor_1.DefaultTextFormat; } });
|
|
103
148
|
Object.defineProperty(exports, "encodeJsonToDatum", { enumerable: true, get: function () { return cbor_1.encodeJsonToDatum; } });
|
package/handles/getRarity.d.ts
DELETED
package/handles/getRarity.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRarity = void 0;
|
|
4
|
-
const interfaces_1 = require("./interfaces");
|
|
5
|
-
const getRarity = (name) => {
|
|
6
|
-
const length = name.length;
|
|
7
|
-
if (1 === length) {
|
|
8
|
-
return interfaces_1.Rarity.legendary;
|
|
9
|
-
}
|
|
10
|
-
if (2 === length) {
|
|
11
|
-
return interfaces_1.Rarity.ultra_rare;
|
|
12
|
-
}
|
|
13
|
-
if (3 === length) {
|
|
14
|
-
return interfaces_1.Rarity.rare;
|
|
15
|
-
}
|
|
16
|
-
if (length > 3 && length < 8) {
|
|
17
|
-
return interfaces_1.Rarity.common;
|
|
18
|
-
}
|
|
19
|
-
return interfaces_1.Rarity.basic;
|
|
20
|
-
};
|
|
21
|
-
exports.getRarity = getRarity;
|
package/handles/validation.d.ts
DELETED
package/handles/validation.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkHandlePattern = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const checkHandlePattern = (handle, root) => {
|
|
6
|
-
handle = handle.toLowerCase();
|
|
7
|
-
if (handle.length <= 1) {
|
|
8
|
-
return {
|
|
9
|
-
valid: false,
|
|
10
|
-
message: constants_1.RESPONSE_UNAVAILABLE_LEGENDARY
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
if (!handle.match(constants_1.REGEX_SUB_HANDLE) && (root ? handle.endsWith(`@${root}`) : true)) {
|
|
14
|
-
return {
|
|
15
|
-
valid: false,
|
|
16
|
-
message: constants_1.RESPONSE_INVALID_HANDLE_FORMAT
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
valid: true,
|
|
21
|
-
message: constants_1.RESPONSE_AVAILABLE
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
exports.checkHandlePattern = checkHandlePattern;
|
|
File without changes
|