@koralabs/kora-labs-common 6.0.3 → 6.1.2
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 +2 -1
- package/handles/interfaces/api.d.ts +16 -79
- package/handles/interfaces/handlesProvider.d.ts +8 -10
- package/handles/interfaces/index.d.ts +1 -1
- package/handles/models/handleSearch.model.d.ts +8 -17
- package/handles/models/handleSearch.model.js +11 -11
- package/handles/policies.d.ts +15 -26
- package/handles/policies.js +8 -8
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/cbor/index.d.ts +1 -0
- package/utils/cbor/index.js +4 -3
- package/utils/crypto/index.d.ts +8 -5
- package/utils/crypto/index.js +28 -15
- package/utils/index.d.ts +2 -1
- package/utils/index.js +5 -3
package/constants/index.d.ts
CHANGED
package/constants/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.MINTED_OG_LIST = exports.TOU_URL = exports.AUTH_GRANT_DURATION = exports.IS_PRODUCTION = exports.NETWORK = exports.IS_SERVER = void 0;
|
|
4
|
+
exports.MINTED_OG_LIST = exports.TOU_URL = exports.AUTH_GRANT_DURATION = exports.IS_PRODUCTION = exports.NETWORK = exports.IS_LOCAL = exports.IS_SERVER = void 0;
|
|
5
5
|
const mintedOgList_1 = require("./mintedOgList");
|
|
6
6
|
exports.IS_SERVER = typeof process !== 'undefined' && typeof process.versions.node !== 'undefined';
|
|
7
|
+
exports.IS_LOCAL = exports.IS_SERVER ? process.env.IS_LOCAL === 'true' : window.location.host.includes('localhost');
|
|
7
8
|
exports.NETWORK = (_b = (_a = process.env.NETWORK) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'preview';
|
|
8
9
|
exports.IS_PRODUCTION = exports.IS_SERVER
|
|
9
10
|
? ((_c = process.env.NODE_ENV) === null || _c === void 0 ? void 0 : _c.trim()) === 'production' && exports.NETWORK == 'mainnet'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPersonalizedHandle, ISubHandleSettings, IUTxO } from '.';
|
|
2
2
|
import { Sort } from '../../types';
|
|
3
|
-
export interface SubHandleSettings {
|
|
4
|
-
settings: ISubHandleSettings;
|
|
3
|
+
export interface SubHandleSettings extends ISubHandleSettings {
|
|
5
4
|
utxo: IUTxO;
|
|
6
5
|
}
|
|
7
6
|
export interface StoredHandle extends IPersonalizedHandle {
|
|
@@ -14,10 +13,7 @@ export interface StoredHandle extends IPersonalizedHandle {
|
|
|
14
13
|
[key: string]: string;
|
|
15
14
|
};
|
|
16
15
|
payment_key_hash: string;
|
|
17
|
-
subhandle_settings?:
|
|
18
|
-
settings?: string;
|
|
19
|
-
utxo: IUTxO;
|
|
20
|
-
};
|
|
16
|
+
subhandle_settings?: SubHandleSettings;
|
|
21
17
|
sub_rarity?: string;
|
|
22
18
|
sub_length?: number;
|
|
23
19
|
sub_characters?: string;
|
|
@@ -57,72 +53,7 @@ export interface IApiMetrics {
|
|
|
57
53
|
count?: number;
|
|
58
54
|
schemaVersion?: number;
|
|
59
55
|
}
|
|
60
|
-
export interface SaveMintingTxInput {
|
|
61
|
-
hex: string;
|
|
62
|
-
name: string;
|
|
63
|
-
adaAddress: string;
|
|
64
|
-
og_number: number;
|
|
65
|
-
image: string;
|
|
66
|
-
image_hash?: string;
|
|
67
|
-
slotNumber: number;
|
|
68
|
-
utxo: string;
|
|
69
|
-
lovelace: number;
|
|
70
|
-
svg_version?: string;
|
|
71
|
-
bg_image?: string;
|
|
72
|
-
pfp_image?: string;
|
|
73
|
-
datum?: string;
|
|
74
|
-
script?: {
|
|
75
|
-
type: string;
|
|
76
|
-
cbor: string;
|
|
77
|
-
};
|
|
78
|
-
last_update_address?: string;
|
|
79
|
-
personalization?: IPersonalization;
|
|
80
|
-
reference_token?: IReferenceToken;
|
|
81
|
-
resolved_addresses?: Record<string, string>;
|
|
82
|
-
amount?: number;
|
|
83
|
-
version?: number;
|
|
84
|
-
handle_type: HandleType;
|
|
85
|
-
sub_rarity?: string;
|
|
86
|
-
sub_length?: number;
|
|
87
|
-
sub_characters?: string;
|
|
88
|
-
sub_numeric_modifiers?: string;
|
|
89
|
-
virtual?: {
|
|
90
|
-
expires_time: number;
|
|
91
|
-
public_mint: boolean;
|
|
92
|
-
};
|
|
93
|
-
original_address?: string;
|
|
94
|
-
id_hash?: string;
|
|
95
|
-
pz_enabled?: boolean;
|
|
96
|
-
last_edited_time?: number;
|
|
97
|
-
}
|
|
98
|
-
export interface SaveWalletAddressMoveInput {
|
|
99
|
-
slotNumber: number;
|
|
100
|
-
name: string;
|
|
101
|
-
adaAddress: string;
|
|
102
|
-
utxo: string;
|
|
103
|
-
datum?: string;
|
|
104
|
-
script?: {
|
|
105
|
-
type: string;
|
|
106
|
-
cbor: string;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
export interface SavePersonalizationInput {
|
|
110
|
-
slotNumber: number;
|
|
111
|
-
hex: string;
|
|
112
|
-
name: string;
|
|
113
|
-
personalization: IPersonalization;
|
|
114
|
-
reference_token: IReferenceToken;
|
|
115
|
-
personalizationDatum: IPzDatumConvertedUsingSchema | null;
|
|
116
|
-
metadata: IHandleMetadata | null;
|
|
117
|
-
}
|
|
118
|
-
export interface SaveSubHandleSettingsInput {
|
|
119
|
-
name: string;
|
|
120
|
-
settingsDatum?: string;
|
|
121
|
-
utxoDetails: IUTxO;
|
|
122
|
-
slotNumber: number;
|
|
123
|
-
}
|
|
124
56
|
export interface Holder {
|
|
125
|
-
address: string;
|
|
126
57
|
handles: Set<string>;
|
|
127
58
|
defaultHandle: string;
|
|
128
59
|
manuallySet: boolean;
|
|
@@ -137,21 +68,27 @@ export interface HolderViewModel {
|
|
|
137
68
|
default_handle: string;
|
|
138
69
|
manually_set: boolean;
|
|
139
70
|
}
|
|
140
|
-
export interface
|
|
141
|
-
records_per_page?: string;
|
|
142
|
-
page?: string;
|
|
143
|
-
sort?: Sort;
|
|
71
|
+
export interface IHandleSearchParams {
|
|
144
72
|
characters?: string;
|
|
145
73
|
length?: string;
|
|
146
74
|
rarity?: string;
|
|
147
75
|
numeric_modifiers?: string;
|
|
148
|
-
slot_number?: string;
|
|
149
76
|
search?: string;
|
|
150
77
|
holder_address?: string;
|
|
151
78
|
personalized?: boolean;
|
|
152
|
-
og?: 'true' | 'false';
|
|
153
79
|
handle_type?: string;
|
|
154
|
-
|
|
80
|
+
public_subhandles?: boolean;
|
|
81
|
+
og?: 'true' | 'false';
|
|
82
|
+
}
|
|
83
|
+
export interface IHandleSearchInput extends IHandleSearchParams {
|
|
84
|
+
handles?: string[];
|
|
85
|
+
}
|
|
86
|
+
export interface IGetAllQueryParams extends IHandleSearchParams {
|
|
87
|
+
records_per_page?: string;
|
|
88
|
+
page?: string;
|
|
89
|
+
sort?: Sort;
|
|
90
|
+
slot_number?: string;
|
|
91
|
+
type?: 'bech32stake' | 'holder' | 'stakekeyhash' | 'assetname' | 'handlehex' | 'paymentkeyhash' | 'bech32address' | 'hexaddress';
|
|
155
92
|
}
|
|
156
93
|
export type ISearchBody = string[];
|
|
157
94
|
export interface IGetAllHoldersQueryParams {
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { IApiMetrics, IndexNames, StoredHandle } from './api';
|
|
1
|
+
import { Holder, IApiMetrics, IndexNames, ISlotHistory, StoredHandle } from './api';
|
|
2
2
|
export interface IHandlesProvider {
|
|
3
3
|
initialize: () => Promise<IHandlesProvider>;
|
|
4
4
|
destroy: () => void;
|
|
5
5
|
rollBackToGenesis: () => void;
|
|
6
|
-
getStartingPoint: (save: (
|
|
7
|
-
handle: StoredHandle;
|
|
8
|
-
oldHandle?: StoredHandle;
|
|
9
|
-
saveHistory?: boolean;
|
|
10
|
-
}) => Promise<void>, failed: boolean) => Promise<{
|
|
6
|
+
getStartingPoint: (save: (handle: StoredHandle) => Promise<void>, failed: boolean) => Promise<{
|
|
11
7
|
slot: number;
|
|
12
8
|
id: string;
|
|
13
9
|
} | null>;
|
|
@@ -16,11 +12,13 @@ export interface IHandlesProvider {
|
|
|
16
12
|
getAllHandles: () => StoredHandle[];
|
|
17
13
|
setHandle: (key: string, value: StoredHandle) => void;
|
|
18
14
|
removeHandle: (handleName: string) => void;
|
|
19
|
-
getIndex: (index: IndexNames) =>
|
|
20
|
-
|
|
21
|
-
setValueOnIndex: (index: IndexNames, key: string | number, value:
|
|
22
|
-
removeValueFromIndex: (index: IndexNames, key: string | number, value: string) => void;
|
|
15
|
+
getIndex: (index: IndexNames) => Map<string | number, Set<string> | Holder | ISlotHistory | StoredHandle>;
|
|
16
|
+
getValueFromIndex: (index: IndexNames, key: string | number) => Set<string> | Holder | ISlotHistory | StoredHandle | undefined;
|
|
17
|
+
setValueOnIndex: (index: IndexNames, key: string | number, value: Set<string> | Holder | ISlotHistory | StoredHandle) => void;
|
|
23
18
|
removeKeyFromIndex: (index: IndexNames, key: string | number) => void;
|
|
19
|
+
getValuesFromIndexedSet: (index: IndexNames, key: string | number) => Set<string> | undefined;
|
|
20
|
+
addValueToIndexedSet: (index: IndexNames, key: string | number, value: string) => void;
|
|
21
|
+
removeValueFromIndexedSet: (index: IndexNames, key: string | number, value: string) => void;
|
|
24
22
|
getMetrics: () => IApiMetrics;
|
|
25
23
|
setMetrics: (metrics: IApiMetrics) => void;
|
|
26
24
|
count: () => number;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 {
|
|
1
|
+
import { IHandleSearchInput } from '..';
|
|
2
|
+
export declare class HandleSearchModel implements IHandleSearchInput {
|
|
14
3
|
private _characters?;
|
|
15
4
|
private _length?;
|
|
16
5
|
private _rarity?;
|
|
@@ -21,7 +10,8 @@ export declare class HandleSearchModel {
|
|
|
21
10
|
private _handle_type?;
|
|
22
11
|
private _og?;
|
|
23
12
|
private _handles?;
|
|
24
|
-
|
|
13
|
+
private _public_subhandles?;
|
|
14
|
+
constructor(input?: IHandleSearchInput);
|
|
25
15
|
get characters(): string | undefined;
|
|
26
16
|
set characters(value: string | undefined);
|
|
27
17
|
get rarity(): string | undefined;
|
|
@@ -38,9 +28,10 @@ export declare class HandleSearchModel {
|
|
|
38
28
|
set holder_address(value: string | undefined);
|
|
39
29
|
get personalized(): boolean | undefined;
|
|
40
30
|
set personalized(value: boolean | undefined);
|
|
41
|
-
get og():
|
|
42
|
-
set og(value:
|
|
31
|
+
get og(): "true" | "false" | undefined;
|
|
32
|
+
set og(value: "true" | "false" | undefined);
|
|
33
|
+
get public_subhandles(): boolean | undefined;
|
|
34
|
+
set public_subhandles(value: boolean | undefined);
|
|
43
35
|
get handles(): string[] | undefined;
|
|
44
36
|
set handles(value: string[] | undefined);
|
|
45
37
|
}
|
|
46
|
-
export {};
|
|
@@ -6,17 +6,11 @@ const errors_1 = require("../../errors");
|
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
class HandleSearchModel {
|
|
8
8
|
constructor(input) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
9
|
+
for (const key in input) {
|
|
10
|
+
if (input.hasOwnProperty(key) && this.hasOwnProperty(key)) {
|
|
11
|
+
this[key] = input[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
20
14
|
}
|
|
21
15
|
get characters() {
|
|
22
16
|
return this._characters;
|
|
@@ -111,6 +105,12 @@ class HandleSearchModel {
|
|
|
111
105
|
set og(value) {
|
|
112
106
|
this._og = value;
|
|
113
107
|
}
|
|
108
|
+
get public_subhandles() {
|
|
109
|
+
return this._public_subhandles;
|
|
110
|
+
}
|
|
111
|
+
set public_subhandles(value) {
|
|
112
|
+
this._public_subhandles = value;
|
|
113
|
+
}
|
|
114
114
|
get handles() {
|
|
115
115
|
return this._handles;
|
|
116
116
|
}
|
package/handles/policies.d.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import { Network } from '../types';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
isDeMi: boolean;
|
|
9
|
-
};
|
|
2
|
+
export interface PolicyIds {
|
|
3
|
+
[key: string]: {
|
|
4
|
+
firstMintingSlot: number;
|
|
5
|
+
lastMintingSlot: number | null;
|
|
6
|
+
sunsetSlot: number | null;
|
|
7
|
+
isDeMi?: boolean;
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a: {
|
|
21
|
-
firstMintingSlot: number;
|
|
22
|
-
lastMintingSlot: null;
|
|
23
|
-
sunsetSlot: null;
|
|
24
|
-
isDeMi: boolean;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
getActivePolicy(network: Network, atSlot?: number, isDeMi?: boolean): string | undefined;
|
|
28
|
-
};
|
|
9
|
+
}
|
|
10
|
+
export interface HandlePolicies {
|
|
11
|
+
'preview': PolicyIds;
|
|
12
|
+
'preprod': PolicyIds;
|
|
13
|
+
'mainnet': PolicyIds;
|
|
14
|
+
getActivePolicy(network: Network, isDemi?: boolean, atSlot?: number): string | undefined;
|
|
15
|
+
contains(network: Network, policyId: string): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const HANDLE_POLICIES: HandlePolicies;
|
package/handles/policies.js
CHANGED
|
@@ -4,17 +4,17 @@ exports.HANDLE_POLICIES = void 0;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
exports.HANDLE_POLICIES = {
|
|
6
6
|
'preview': {
|
|
7
|
-
'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null
|
|
7
|
+
'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null },
|
|
8
|
+
'6c32db33a422e0bc2cb535bb850b5a6e9a9572222056d6ddc9cbc26e': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null, isDeMi: true }
|
|
8
9
|
},
|
|
9
|
-
'preprod': {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'mainnet': {
|
|
13
|
-
'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null, isDeMi: false }
|
|
14
|
-
},
|
|
15
|
-
getActivePolicy(network, atSlot, isDeMi = false) {
|
|
10
|
+
'preprod': { 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null } },
|
|
11
|
+
'mainnet': { 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': { firstMintingSlot: 0, lastMintingSlot: null, sunsetSlot: null } },
|
|
12
|
+
getActivePolicy(network, isDeMi = false, atSlot) {
|
|
16
13
|
var _a;
|
|
17
14
|
const theSlot = atSlot ? atSlot : (0, utils_1.getSlotNumberFromDate)(new Date(Date.now()));
|
|
18
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];
|
|
16
|
+
},
|
|
17
|
+
contains(network, policyId) {
|
|
18
|
+
return Object.keys(this[network]).includes(policyId);
|
|
19
19
|
}
|
|
20
20
|
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface KeyPair {
|
|
|
14
14
|
* Finally, use the decimal number and convert to CRC8. It should match the last 2 characters. https://crccalc.com/
|
|
15
15
|
*/
|
|
16
16
|
export declare enum AssetNameLabel {
|
|
17
|
+
NONE = "",
|
|
17
18
|
LBL_000 = "00000000",
|
|
18
19
|
LBL_001 = "00001070",
|
|
19
20
|
LBL_002 = "000020e0",
|
package/types/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./profile-header"), exports);
|
|
|
25
25
|
*/
|
|
26
26
|
var AssetNameLabel;
|
|
27
27
|
(function (AssetNameLabel) {
|
|
28
|
+
AssetNameLabel["NONE"] = "";
|
|
28
29
|
AssetNameLabel["LBL_000"] = "00000000";
|
|
29
30
|
AssetNameLabel["LBL_001"] = "00001070";
|
|
30
31
|
AssetNameLabel["LBL_002"] = "000020e0";
|
package/utils/cbor/index.d.ts
CHANGED
package/utils/cbor/index.js
CHANGED
|
@@ -358,7 +358,7 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
|
|
|
358
358
|
}
|
|
359
359
|
else if (Buffer.isBuffer(val)) {
|
|
360
360
|
if (schema === 'string' || schema === 'bool') {
|
|
361
|
-
const result =
|
|
361
|
+
const result = val.toString('utf8');
|
|
362
362
|
if (schema === 'bool' && (0, boolean_1.isBooleanable)(result)) {
|
|
363
363
|
return (0, boolean_1.boolean)(result);
|
|
364
364
|
}
|
|
@@ -368,7 +368,7 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
|
|
|
368
368
|
// }
|
|
369
369
|
return result;
|
|
370
370
|
}
|
|
371
|
-
return `0x${
|
|
371
|
+
return `0x${val.toString('hex')}`;
|
|
372
372
|
}
|
|
373
373
|
else {
|
|
374
374
|
if (schema === 'bool' && (0, boolean_1.isBooleanable)(val)) {
|
|
@@ -383,7 +383,8 @@ const decodeCborToJson = async ({ cborString, schema, defaultKeyType, forJson })
|
|
|
383
383
|
121: (val) => ({ [`constructor_0`]: val }),
|
|
384
384
|
122: (val) => ({ [`constructor_1`]: val }),
|
|
385
385
|
123: (val) => ({ [`constructor_2`]: val }),
|
|
386
|
-
124: (val) => ({ [`constructor_3`]: val })
|
|
386
|
+
124: (val) => ({ [`constructor_3`]: val }),
|
|
387
|
+
125: (val) => ({ [`constructor_3`]: val })
|
|
387
388
|
}
|
|
388
389
|
});
|
|
389
390
|
let [data] = decoded;
|
package/utils/crypto/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -6,19 +8,20 @@ export declare const sha256: (plain: string) => Promise<ArrayBuffer>;
|
|
|
6
8
|
export declare function base64urlencode(a: ArrayBuffer): string;
|
|
7
9
|
export declare function getChallengeFromVerifier(verifier: string): Promise<string>;
|
|
8
10
|
export declare const decodeAddress: (address: string) => string | null;
|
|
9
|
-
export declare const parseAssetNameLabel: (assetName: string) => AssetNameLabel
|
|
11
|
+
export declare const parseAssetNameLabel: (assetName: string) => AssetNameLabel;
|
|
10
12
|
export declare const checkNameLabel: (assetName: string) => {
|
|
11
13
|
isCip67: boolean;
|
|
12
|
-
assetLabel:
|
|
13
|
-
|
|
14
|
+
assetLabel: AssetNameLabel;
|
|
15
|
+
name: string;
|
|
14
16
|
};
|
|
15
17
|
export declare const getPaymentAddressType: (headerByte: number) => AddressType;
|
|
16
18
|
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;
|
|
20
|
-
export declare const
|
|
22
|
+
export declare const bech32AddressFromHashes: (paymentHash: string, paymentHashType?: 'key' | 'script', stakeHash?: string, stakeHashType?: 'key' | 'script', type?: 'addr' | 'stake', isTestnet?: boolean) => string;
|
|
23
|
+
export declare const buildHolderInfo: (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;
|
package/utils/crypto/index.js
CHANGED
|
@@ -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.
|
|
29
|
+
exports.blake2b = exports.getSlotNumberFromDate = exports.getDateStringFromSlot = exports.checkKnownSmartContracts = exports.buildHolderInfo = 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"));
|
|
@@ -93,19 +93,15 @@ const decodeAddress = (address) => {
|
|
|
93
93
|
};
|
|
94
94
|
exports.decodeAddress = decodeAddress;
|
|
95
95
|
const parseAssetNameLabel = (assetName) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return lbl;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
96
|
+
const maybeAssetNameLabel = assetName.slice(0, 8);
|
|
97
|
+
return Object.values(types_1.AssetNameLabel).includes(maybeAssetNameLabel) ? maybeAssetNameLabel : types_1.AssetNameLabel.NONE;
|
|
102
98
|
};
|
|
103
99
|
exports.parseAssetNameLabel = parseAssetNameLabel;
|
|
104
100
|
const checkNameLabel = (assetName) => {
|
|
105
101
|
const assetNameString = typeof assetName === 'string' ? assetName : new TextDecoder().decode(assetName);
|
|
106
102
|
let isCip67 = false;
|
|
107
|
-
let assetLabel =
|
|
108
|
-
let
|
|
103
|
+
let assetLabel = types_1.AssetNameLabel.NONE;
|
|
104
|
+
let utf8Name = Buffer.from(assetName, 'hex').toString('utf8');
|
|
109
105
|
if (assetNameString.length >= 8) {
|
|
110
106
|
const maybeAssetLabel = assetNameString.slice(0, 8);
|
|
111
107
|
if (maybeAssetLabel.startsWith('0') && maybeAssetLabel.endsWith('0')) {
|
|
@@ -113,15 +109,15 @@ const checkNameLabel = (assetName) => {
|
|
|
113
109
|
const check = maybeAssetLabel.slice(5, 7);
|
|
114
110
|
if ((0, crc_1.crc8)(Buffer.from(label, 'hex')).toString(16).padStart(2, '0') == check) {
|
|
115
111
|
isCip67 = true;
|
|
116
|
-
assetLabel =
|
|
117
|
-
|
|
112
|
+
assetLabel = (0, exports.parseAssetNameLabel)(assetName);
|
|
113
|
+
utf8Name = Buffer.from(assetName.slice(8), 'hex').toString('utf8');
|
|
118
114
|
}
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
return {
|
|
122
118
|
isCip67,
|
|
123
119
|
assetLabel,
|
|
124
|
-
|
|
120
|
+
name: utf8Name
|
|
125
121
|
};
|
|
126
122
|
};
|
|
127
123
|
exports.checkNameLabel = checkNameLabel;
|
|
@@ -218,7 +214,24 @@ const bech32FromHex = (hex, isTestnet = !constants_1.IS_PRODUCTION, type = 'addr
|
|
|
218
214
|
return bech32_1.bech32.encode(prefix, words, bytes.length * 2 + prefix.length);
|
|
219
215
|
};
|
|
220
216
|
exports.bech32FromHex = bech32FromHex;
|
|
221
|
-
const
|
|
217
|
+
const bech32AddressFromHashes = (paymentHash, paymentHashType = 'key', stakeHash = '', stakeHashType = 'key', type = 'addr', isTestnet = !constants_1.IS_PRODUCTION) => {
|
|
218
|
+
let headerByte = 0;
|
|
219
|
+
if (!stakeHash) {
|
|
220
|
+
headerByte += 6;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
if (stakeHashType == 'script') {
|
|
224
|
+
headerByte += 2;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (paymentHashType == 'script') {
|
|
228
|
+
headerByte += 1;
|
|
229
|
+
}
|
|
230
|
+
const hex = `${headerByte.toString(16)}${isTestnet ? 0 : 1}${paymentHash}${stakeHash}`;
|
|
231
|
+
return (0, exports.bech32FromHex)(hex, isTestnet, type);
|
|
232
|
+
};
|
|
233
|
+
exports.bech32AddressFromHashes = bech32AddressFromHashes;
|
|
234
|
+
const buildHolderInfo = (addr) => {
|
|
222
235
|
const addressType = (0, exports.buildPaymentAddressType)(addr);
|
|
223
236
|
let knownOwnerName = (0, exports.checkKnownSmartContracts)(addr);
|
|
224
237
|
let stakeKey = null;
|
|
@@ -232,7 +245,7 @@ const getAddressHolderDetails = (addr) => {
|
|
|
232
245
|
knownOwnerName
|
|
233
246
|
};
|
|
234
247
|
};
|
|
235
|
-
exports.
|
|
248
|
+
exports.buildHolderInfo = buildHolderInfo;
|
|
236
249
|
const checkKnownSmartContracts = (address, stake) => {
|
|
237
250
|
switch (address) {
|
|
238
251
|
case 'addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3':
|
|
@@ -290,6 +303,6 @@ const getSlotNumberFromDate = (date) => {
|
|
|
290
303
|
};
|
|
291
304
|
exports.getSlotNumberFromDate = getSlotNumberFromDate;
|
|
292
305
|
const blake2b = (input, outlen = 32) => {
|
|
293
|
-
return (0, blakejs_1.blake2bHex)(input, undefined, outlen);
|
|
306
|
+
return (0, blakejs_1.blake2bHex)(typeof input == 'string' ? Buffer.from(input, 'hex') : input, undefined, outlen);
|
|
294
307
|
};
|
|
295
308
|
exports.blake2b = blake2b;
|
package/utils/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const hasOwnProperty: (o: any, v: PropertyKey) => boolean;
|
|
|
17
17
|
export declare const isDate: (d: any) => boolean;
|
|
18
18
|
export declare const isEmptyObject: (o: any) => boolean;
|
|
19
19
|
export declare const makeObjectWithoutPrototype: () => any;
|
|
20
|
+
export declare const ExcludesFalse: <T>(n?: T | null | undefined) => n is T;
|
|
20
21
|
export declare const diff: (lhs: any, rhs: any) => any;
|
|
21
|
-
export { DefaultTextFormat as KeyType
|
|
22
|
+
export { decodeCborToJson, encodeJsonToDatum, DefaultTextFormat as KeyType } from './cbor';
|
|
22
23
|
export * from './crypto';
|
package/utils/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.
|
|
17
|
+
exports.KeyType = exports.encodeJsonToDatum = exports.decodeCborToJson = exports.diff = exports.ExcludesFalse = 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;
|
|
18
18
|
const delay = (ms) => {
|
|
19
19
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
20
|
};
|
|
@@ -108,6 +108,8 @@ const isEmptyObject = (o) => (0, exports.isObject)(o) && (0, exports.objectHasKe
|
|
|
108
108
|
exports.isEmptyObject = isEmptyObject;
|
|
109
109
|
const makeObjectWithoutPrototype = () => Object.create(null);
|
|
110
110
|
exports.makeObjectWithoutPrototype = makeObjectWithoutPrototype;
|
|
111
|
+
const ExcludesFalse = (n) => Boolean(n);
|
|
112
|
+
exports.ExcludesFalse = ExcludesFalse;
|
|
111
113
|
const diff = (lhs, rhs) => {
|
|
112
114
|
if (lhs === rhs)
|
|
113
115
|
return {}; // equal return no diff
|
|
@@ -144,7 +146,7 @@ const diff = (lhs, rhs) => {
|
|
|
144
146
|
};
|
|
145
147
|
exports.diff = diff;
|
|
146
148
|
var cbor_1 = require("./cbor");
|
|
147
|
-
Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return cbor_1.DefaultTextFormat; } });
|
|
148
|
-
Object.defineProperty(exports, "encodeJsonToDatum", { enumerable: true, get: function () { return cbor_1.encodeJsonToDatum; } });
|
|
149
149
|
Object.defineProperty(exports, "decodeCborToJson", { enumerable: true, get: function () { return cbor_1.decodeCborToJson; } });
|
|
150
|
+
Object.defineProperty(exports, "encodeJsonToDatum", { enumerable: true, get: function () { return cbor_1.encodeJsonToDatum; } });
|
|
151
|
+
Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return cbor_1.DefaultTextFormat; } });
|
|
150
152
|
__exportStar(require("./crypto"), exports);
|