@koralabs/kora-labs-common 2.6.0 → 3.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/lib/handles/interfaces.d.ts +4 -2
- package/lib/utils/cbor/index.d.ts +26 -0
- package/lib/utils/cbor/index.js +335 -0
- package/lib/utils/cbor/index.test.d.ts +1 -0
- package/lib/utils/cbor/index.test.js +532 -0
- package/lib/utils/cbor/schema/designer.d.ts +18 -0
- package/lib/utils/cbor/schema/designer.js +21 -0
- package/lib/utils/cbor/schema/handleData.d.ts +30 -0
- package/lib/utils/cbor/schema/handleData.js +33 -0
- package/lib/utils/cbor/schema/portal.d.ts +8 -0
- package/lib/utils/cbor/schema/portal.js +11 -0
- package/lib/utils/cbor/schema/socials.d.ts +6 -0
- package/lib/utils/cbor/schema/socials.js +9 -0
- package/lib/utils/cbor/schema/subHandleSettings.d.ts +43 -0
- package/lib/utils/cbor/schema/subHandleSettings.js +27 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +12 -6
- package/package.json +3 -1
|
@@ -197,12 +197,14 @@ export interface IPzDatum {
|
|
|
197
197
|
[key: string]: string;
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
+
export interface ISubHandleSettingsCreatorDefaults extends ICreatorDefaults {
|
|
201
|
+
bg_image: string;
|
|
202
|
+
}
|
|
200
203
|
export interface ISubHandleSettings {
|
|
201
204
|
enabled?: BoolInt;
|
|
202
205
|
tierPricing?: [number, number][];
|
|
203
206
|
enablePz?: BoolInt;
|
|
204
|
-
creatorDefaults?:
|
|
205
|
-
creatorDefaultsBgImage?: string;
|
|
207
|
+
creatorDefaults?: ISubHandleSettingsCreatorDefaults;
|
|
206
208
|
}
|
|
207
209
|
export interface IVirtualSubHandleSettings extends ISubHandleSettings {
|
|
208
210
|
expires_in_days?: number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare enum KeyType {
|
|
3
|
+
UTF8 = "utf8",
|
|
4
|
+
HEX = "hex"
|
|
5
|
+
}
|
|
6
|
+
declare class JsonToDatumObject {
|
|
7
|
+
json: any;
|
|
8
|
+
numericKeys: boolean;
|
|
9
|
+
constructor(json: any, numericKeys?: boolean);
|
|
10
|
+
getFormattedKey: (key: string) => number | Buffer;
|
|
11
|
+
getHexOrString: (key: string) => Buffer;
|
|
12
|
+
encodeCBOR: (encoder: any) => any;
|
|
13
|
+
keyIsNumeric: (key: any) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class DupeKey extends JsonToDatumObject {
|
|
16
|
+
key: string;
|
|
17
|
+
constructor(key: string);
|
|
18
|
+
}
|
|
19
|
+
export declare const encodeJsonToDatum: (json: any, numericKeys?: boolean) => Promise<string>;
|
|
20
|
+
export declare const decodeCborToJson: ({ cborString, schema, defaultKeyType, forJson }: {
|
|
21
|
+
cborString: string;
|
|
22
|
+
schema?: any;
|
|
23
|
+
defaultKeyType?: KeyType | undefined;
|
|
24
|
+
forJson?: boolean | undefined;
|
|
25
|
+
}) => Promise<any>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,335 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.decodeCborToJson = exports.encodeJsonToDatum = exports.DupeKey = exports.KeyType = void 0;
|
|
36
|
+
const cbor = __importStar(require("cbor"));
|
|
37
|
+
const boolean_1 = require("boolean");
|
|
38
|
+
// The five ways to represent metadata/datum:
|
|
39
|
+
// Json (cardano-cli can take this with --tx-out-datum-json-value)
|
|
40
|
+
// TxMetadataJson ("Detailed Schema")
|
|
41
|
+
// TxMetadataCbor
|
|
42
|
+
// PlutusDataJson ("Schema Json")
|
|
43
|
+
// PlutusDataCbor
|
|
44
|
+
// Constructor vs Not
|
|
45
|
+
// Sort of similar to:
|
|
46
|
+
// const instance = new CustomObject(<json>)
|
|
47
|
+
// vs
|
|
48
|
+
// const obj = JSON.parse(<json>)
|
|
49
|
+
var KeyType;
|
|
50
|
+
(function (KeyType) {
|
|
51
|
+
KeyType["UTF8"] = "utf8";
|
|
52
|
+
KeyType["HEX"] = "hex";
|
|
53
|
+
})(KeyType = exports.KeyType || (exports.KeyType = {}));
|
|
54
|
+
class JsonToDatumObject {
|
|
55
|
+
constructor(json, numericKeys = false) {
|
|
56
|
+
this.getFormattedKey = (key) => {
|
|
57
|
+
if (key.startsWith('0x')) {
|
|
58
|
+
return Buffer.from(key.substring(2), 'hex');
|
|
59
|
+
}
|
|
60
|
+
if (this.keyIsNumeric(key)) {
|
|
61
|
+
return parseInt(key);
|
|
62
|
+
}
|
|
63
|
+
if (key.startsWith('~0x')) {
|
|
64
|
+
key = key.slice(1);
|
|
65
|
+
}
|
|
66
|
+
return Buffer.from(key);
|
|
67
|
+
};
|
|
68
|
+
this.getHexOrString = (key) => {
|
|
69
|
+
if (key.startsWith('0x')) {
|
|
70
|
+
return Buffer.from(key.substring(2), 'hex');
|
|
71
|
+
}
|
|
72
|
+
if (key.startsWith('~0x')) {
|
|
73
|
+
key = key.slice(1);
|
|
74
|
+
}
|
|
75
|
+
return Buffer.from(key);
|
|
76
|
+
};
|
|
77
|
+
this.encodeCBOR = (encoder) => {
|
|
78
|
+
var _a;
|
|
79
|
+
if (Array.isArray(this.json)) {
|
|
80
|
+
return cbor.Encoder.encodeIndefinite(encoder, this.json);
|
|
81
|
+
}
|
|
82
|
+
else if (typeof this.json === 'object') {
|
|
83
|
+
if (this.json !== null) {
|
|
84
|
+
const fieldsMap = new Map();
|
|
85
|
+
let tag = null;
|
|
86
|
+
const keys = this.json instanceof Map ? this.json.keys() : Object.keys(this.json);
|
|
87
|
+
for (let key of keys) {
|
|
88
|
+
if (key instanceof DupeKey) {
|
|
89
|
+
fieldsMap.set(key, this.json.get(key));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
let split_key = parseInt((_a = key.split('_').at(1)) !== null && _a !== void 0 ? _a : '');
|
|
93
|
+
if (key.startsWith('constructor_') &&
|
|
94
|
+
!isNaN(split_key) &&
|
|
95
|
+
[0, 1, 2, 3].includes(split_key)) {
|
|
96
|
+
tag = 121 + split_key;
|
|
97
|
+
return encoder.pushAny(new cbor.Tagged(tag, this.json[key]));
|
|
98
|
+
}
|
|
99
|
+
const bufferedKey = this.getFormattedKey(key);
|
|
100
|
+
fieldsMap.set(bufferedKey, this.json[key]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return encoder.pushAny(fieldsMap);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return encoder.pushAny(Buffer.from('null'));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (Number.isInteger(this.json)) {
|
|
110
|
+
return encoder.pushAny(this.json);
|
|
111
|
+
}
|
|
112
|
+
else if (typeof this.json === 'string') {
|
|
113
|
+
// check for hex and if so, decode it
|
|
114
|
+
const bufferedString = this.getHexOrString(this.json);
|
|
115
|
+
return bufferedString.length > 64
|
|
116
|
+
? cbor.Encoder.encodeIndefinite(encoder, bufferedString, { chunkSize: 64 })
|
|
117
|
+
: encoder.pushAny(bufferedString);
|
|
118
|
+
}
|
|
119
|
+
else if (typeof this.json === 'boolean') {
|
|
120
|
+
return encoder.pushAny(this.json ? 1 : 0);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// anything else: convert to simple type - String.
|
|
124
|
+
// e.g. undefined, true, false, NaN, Infinity.
|
|
125
|
+
// Some of these can't be represented in JSON anyway.
|
|
126
|
+
// Floating point numbers: note there can be loss of precision when
|
|
127
|
+
// representing floats as decimal numbers
|
|
128
|
+
return encoder.pushAny(Buffer.from('' + this.json));
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
this.keyIsNumeric = (key) => {
|
|
132
|
+
return this.numericKeys && key !== null && key.length > 0 && !isNaN(key);
|
|
133
|
+
};
|
|
134
|
+
this.json = json;
|
|
135
|
+
this.numericKeys = numericKeys;
|
|
136
|
+
if (Array.isArray(this.json)) {
|
|
137
|
+
for (let i = 0; i < this.json.length; i++) {
|
|
138
|
+
this.json[i] = new JsonToDatumObject(this.json[i], numericKeys);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (typeof this.json === 'object') {
|
|
142
|
+
if (this.json !== null) {
|
|
143
|
+
Object.keys(this.json).map((key) => {
|
|
144
|
+
this.json[key] = new JsonToDatumObject(this.json[key], numericKeys);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
class DupeKey extends JsonToDatumObject {
|
|
151
|
+
constructor(key) {
|
|
152
|
+
super(key);
|
|
153
|
+
this.key = key;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.DupeKey = DupeKey;
|
|
157
|
+
const encodeJsonToDatum = (json, numericKeys = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
const obj = new JsonToDatumObject(json, numericKeys);
|
|
159
|
+
const result = yield cbor.encodeAsync(obj, { chunkSize: 64 });
|
|
160
|
+
return result.toString('hex');
|
|
161
|
+
});
|
|
162
|
+
exports.encodeJsonToDatum = encodeJsonToDatum;
|
|
163
|
+
const parseSchema = (key, schema, defaultKeyType, i) => {
|
|
164
|
+
let schemaValue;
|
|
165
|
+
if (Number.isInteger(key)) {
|
|
166
|
+
key = `${key}`;
|
|
167
|
+
}
|
|
168
|
+
let mapKey = Buffer.from(key).toString('utf8');
|
|
169
|
+
const hexKey = `0x${Buffer.from(key).toString('hex')}`;
|
|
170
|
+
// check schema to see if it matches
|
|
171
|
+
// key name match
|
|
172
|
+
let schemaKey = Object.keys(schema).find((k) => k === mapKey);
|
|
173
|
+
if (!schemaKey) {
|
|
174
|
+
schemaKey = Object.keys(schema).find((k) => k.replace('0x', '') === mapKey);
|
|
175
|
+
if (schemaKey || defaultKeyType == KeyType.HEX) {
|
|
176
|
+
mapKey = hexKey;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// index match
|
|
180
|
+
if (!schemaKey) {
|
|
181
|
+
schemaKey = Object.keys(schema).find((k) => k === `[${i}]`);
|
|
182
|
+
}
|
|
183
|
+
// dynamic match
|
|
184
|
+
if (!schemaKey) {
|
|
185
|
+
schemaKey = Object.keys(schema).find((k) => k.startsWith('<') && k.endsWith('>'));
|
|
186
|
+
if (schemaKey === '<hexstring>' || defaultKeyType == KeyType.HEX) {
|
|
187
|
+
mapKey = hexKey;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (schemaKey) {
|
|
191
|
+
schemaValue = schema[schemaKey];
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
mapKey,
|
|
195
|
+
schemaValue
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = KeyType.UTF8, forJson = true }) => {
|
|
199
|
+
const isMap = val instanceof Map;
|
|
200
|
+
if (isMap) {
|
|
201
|
+
const obj = new Map();
|
|
202
|
+
let dupeKeys = false;
|
|
203
|
+
const keys = [...val.keys()];
|
|
204
|
+
for (let i = 0; i < keys.length; i++) {
|
|
205
|
+
const key = keys[i];
|
|
206
|
+
let value = val.get(key);
|
|
207
|
+
const { mapKey, schemaValue } = parseSchema(key, schema, defaultKeyType, i);
|
|
208
|
+
if (obj.get(mapKey)) {
|
|
209
|
+
dupeKeys = true;
|
|
210
|
+
let newKey = `dupekey_str_${mapKey}_1`;
|
|
211
|
+
const currentKeyIndex = [...obj.keys()].filter((k) => (typeof k === 'string' && k.startsWith(`dupekey_str_${mapKey}`)) || k === mapKey).length - 1;
|
|
212
|
+
let oldKey = `dupekey_str_${mapKey}_${currentKeyIndex}`;
|
|
213
|
+
if (!forJson) {
|
|
214
|
+
newKey = new DupeKey(mapKey);
|
|
215
|
+
oldKey = new DupeKey(mapKey);
|
|
216
|
+
}
|
|
217
|
+
const prevValue = obj.get(mapKey);
|
|
218
|
+
obj.delete(mapKey);
|
|
219
|
+
obj.set(oldKey, prevValue);
|
|
220
|
+
obj.set(newKey, decodeObject({ val: value, constr, schema: schemaValue, defaultKeyType, forJson }));
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
obj.set(mapKey, decodeObject({ val: value, constr, schema: schemaValue, defaultKeyType, forJson }));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (dupeKeys) {
|
|
227
|
+
// convert keys that didnt get converted
|
|
228
|
+
if (forJson) {
|
|
229
|
+
[...obj.keys()].forEach((key) => {
|
|
230
|
+
if (!key.startsWith('dupekey')) {
|
|
231
|
+
const prevValue = obj.get(key);
|
|
232
|
+
obj.delete(key);
|
|
233
|
+
obj.set(`dupekey_str_${key}_0`, prevValue);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// if key is a string, replace with dedupe class
|
|
239
|
+
[...obj.keys()].forEach((key) => {
|
|
240
|
+
if (!(key instanceof DupeKey)) {
|
|
241
|
+
const prevValue = obj.get(key);
|
|
242
|
+
obj.delete(key);
|
|
243
|
+
obj.set(new DupeKey(key), prevValue);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const finalObj = dupeKeys && !forJson ? obj : Object.fromEntries(obj);
|
|
249
|
+
if (constr != null) {
|
|
250
|
+
return { [`constructor_${constr}`]: finalObj };
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return finalObj;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (typeof val === 'object' && val.constructor === Object) {
|
|
257
|
+
const obj = {};
|
|
258
|
+
const keys = Object.keys(val);
|
|
259
|
+
for (let i = 0; i < keys.length; i++) {
|
|
260
|
+
const key = keys[i];
|
|
261
|
+
let value = val[key];
|
|
262
|
+
const { mapKey, schemaValue } = parseSchema(key, schema, defaultKeyType, i);
|
|
263
|
+
obj[mapKey] = decodeObject({ val: value, schema: schemaValue, defaultKeyType, forJson });
|
|
264
|
+
}
|
|
265
|
+
if (constr != null) {
|
|
266
|
+
return { [`constructor_${constr}`]: obj };
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
return obj;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (Array.isArray(val)) {
|
|
273
|
+
const arr = [];
|
|
274
|
+
if (constr !== null && Object.keys(schema).some((k) => k === `constructor_${constr}`)) {
|
|
275
|
+
schema = schema[`constructor_${constr}`];
|
|
276
|
+
}
|
|
277
|
+
for (let i = 0; i < val.length; i++) {
|
|
278
|
+
const arrayVal = val[i];
|
|
279
|
+
let schemaValue;
|
|
280
|
+
let schemaKey;
|
|
281
|
+
// index match
|
|
282
|
+
if (!schemaKey) {
|
|
283
|
+
schemaKey = Object.keys(schema).find((k) => k === `[${i}]`);
|
|
284
|
+
}
|
|
285
|
+
// dynamic match
|
|
286
|
+
if (!schemaKey) {
|
|
287
|
+
schemaKey = Object.keys(schema).find((k) => k === '[all]');
|
|
288
|
+
}
|
|
289
|
+
if (schemaKey) {
|
|
290
|
+
schemaValue = schema[schemaKey];
|
|
291
|
+
}
|
|
292
|
+
arr.push(decodeObject({ val: arrayVal, schema: schemaValue, defaultKeyType, forJson }));
|
|
293
|
+
}
|
|
294
|
+
if (constr != null) {
|
|
295
|
+
return { [`constructor_${constr}`]: arr };
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return arr;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else if (Buffer.isBuffer(val)) {
|
|
302
|
+
if (schema === 'string' || schema === 'bool') {
|
|
303
|
+
const result = Buffer.from(val).toString('utf8');
|
|
304
|
+
if (schema === 'bool' && (0, boolean_1.isBooleanable)(result)) {
|
|
305
|
+
return (0, boolean_1.boolean)(result);
|
|
306
|
+
}
|
|
307
|
+
// Figure out if we want to add the ~ to the front of the hex string
|
|
308
|
+
// if (result.startsWith('0x')) {
|
|
309
|
+
// return `~${result}`;
|
|
310
|
+
// }
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
return `0x${Buffer.from(val).toString('hex')}`;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
if (schema === 'bool' && (0, boolean_1.isBooleanable)(val)) {
|
|
317
|
+
return (0, boolean_1.boolean)(val);
|
|
318
|
+
}
|
|
319
|
+
return val;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const decodeCborToJson = ({ cborString, schema, defaultKeyType, forJson }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
|
+
const decoded = yield cbor.decodeAll(Buffer.from(cborString, 'hex'), {
|
|
324
|
+
tags: {
|
|
325
|
+
121: (val) => ({ [`constructor_0`]: val }),
|
|
326
|
+
122: (val) => ({ [`constructor_1`]: val }),
|
|
327
|
+
123: (val) => ({ [`constructor_2`]: val }),
|
|
328
|
+
124: (val) => ({ [`constructor_3`]: val })
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
let [data] = decoded;
|
|
332
|
+
data = decodeObject({ val: data, schema, defaultKeyType, forJson });
|
|
333
|
+
return data;
|
|
334
|
+
});
|
|
335
|
+
exports.decodeCborToJson = decodeCborToJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const index_1 = require("./index");
|
|
13
|
+
const handleData_1 = require("./schema/handleData");
|
|
14
|
+
const designer_1 = require("./schema/designer");
|
|
15
|
+
const portal_1 = require("./schema/portal");
|
|
16
|
+
describe('CBOR tests', () => {
|
|
17
|
+
describe('Encode/decode Handle JSON and PlutusDataCbor', () => {
|
|
18
|
+
const plutusDataJson = {
|
|
19
|
+
constructor_0: [
|
|
20
|
+
{
|
|
21
|
+
name: 'xar12345',
|
|
22
|
+
image: 'ipfs://image_cid',
|
|
23
|
+
mediaType: 'image/jpeg',
|
|
24
|
+
og: true,
|
|
25
|
+
og_number: 0,
|
|
26
|
+
rarity: 'basic',
|
|
27
|
+
length: 8,
|
|
28
|
+
characters: 'characters,numbers',
|
|
29
|
+
numeric_modifiers: '',
|
|
30
|
+
version: 1
|
|
31
|
+
},
|
|
32
|
+
1,
|
|
33
|
+
{
|
|
34
|
+
standard_image: 'ipfs://cid',
|
|
35
|
+
bg_image: 'ipfs://cid',
|
|
36
|
+
pfp_image: 'ipfs://cid',
|
|
37
|
+
pfp_asset: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
38
|
+
bg_asset: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
39
|
+
portal: 'ipfs://cid',
|
|
40
|
+
designer: 'ipfs://cid',
|
|
41
|
+
socials: 'ipfs://cid',
|
|
42
|
+
vendor: 'ipfs://cid',
|
|
43
|
+
default: false,
|
|
44
|
+
last_update_address: '0x00f749548d2cd66bb9adc5c508de3c9ff938d19f59e93aa623eb356c022b61a21becbc6b3199bab4f0f5eaabafcc50eb87ecf5cc843465d625',
|
|
45
|
+
validated_by: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
46
|
+
trial: true
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
const expectedCbor = 'd8799faa446e616d6548786172313233343545696d61676550697066733a2f2f696d6167655f636964496d65646961547970654a696d6167652f6a706567426f6701496f675f6e756d6265720046726172697479456261736963466c656e677468084a6368617261637465727352636861726163746572732c6e756d62657273516e756d657269635f6d6f64696669657273404776657273696f6e0101ad4e7374616e646172645f696d6167654a697066733a2f2f6369644862675f696d6167654a697066733a2f2f636964497066705f696d6167654a697066733a2f2f636964497066705f6173736574581c4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e14862675f6173736574581c4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e146706f7274616c4a697066733a2f2f6369644864657369676e65724a697066733a2f2f63696447736f6369616c734a697066733a2f2f6369644676656e646f724a697066733a2f2f6369644764656661756c7400536c6173745f7570646174655f61646472657373583900f749548d2cd66bb9adc5c508de3c9ff938d19f59e93aa623eb356c022b61a21becbc6b3199bab4f0f5eaabafcc50eb87ecf5cc843465d6254c76616c6964617465645f6279581c4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e145747269616c01ff';
|
|
51
|
+
it('Should convert from JSON to PlutusDataCbor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(plutusDataJson);
|
|
53
|
+
expect(encoded).toEqual(expectedCbor);
|
|
54
|
+
}));
|
|
55
|
+
it('Should convert from PlutusDataCbor to JSON', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: expectedCbor, schema: handleData_1.handleDatumSchema });
|
|
57
|
+
expect(decoded).toEqual({
|
|
58
|
+
constructor_0: [
|
|
59
|
+
{
|
|
60
|
+
characters: 'characters,numbers',
|
|
61
|
+
image: 'ipfs://image_cid',
|
|
62
|
+
length: 8,
|
|
63
|
+
mediaType: 'image/jpeg',
|
|
64
|
+
name: 'xar12345',
|
|
65
|
+
numeric_modifiers: '',
|
|
66
|
+
og: true,
|
|
67
|
+
og_number: 0,
|
|
68
|
+
rarity: 'basic',
|
|
69
|
+
version: 1
|
|
70
|
+
},
|
|
71
|
+
1,
|
|
72
|
+
{
|
|
73
|
+
bg_asset: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
74
|
+
bg_image: 'ipfs://cid',
|
|
75
|
+
default: false,
|
|
76
|
+
designer: 'ipfs://cid',
|
|
77
|
+
last_update_address: '0x00f749548d2cd66bb9adc5c508de3c9ff938d19f59e93aa623eb356c022b61a21becbc6b3199bab4f0f5eaabafcc50eb87ecf5cc843465d625',
|
|
78
|
+
pfp_asset: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
79
|
+
pfp_image: 'ipfs://cid',
|
|
80
|
+
portal: 'ipfs://cid',
|
|
81
|
+
socials: 'ipfs://cid',
|
|
82
|
+
standard_image: 'ipfs://cid',
|
|
83
|
+
trial: true,
|
|
84
|
+
validated_by: '0x4da965a049dfd15ed1ee19fba6e2974a0b79fc416dd1796a1f97f5e1',
|
|
85
|
+
vendor: 'ipfs://cid'
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
});
|
|
91
|
+
describe('Encode/decode designer datum', () => {
|
|
92
|
+
const getJson = () => ({
|
|
93
|
+
font_shadow_color: '0x000000',
|
|
94
|
+
bg_color: '0x0a1fd3',
|
|
95
|
+
bg_border_color: '0x0a1fd3',
|
|
96
|
+
qr_link: 'https://handle.me/burrito',
|
|
97
|
+
socials: [{ display: 'taco', url: 'https://handle.me/taco' }],
|
|
98
|
+
pfp_border_color: '0x0a1fd3',
|
|
99
|
+
qr_inner_eye: 'rounded,#0a1fd3',
|
|
100
|
+
qr_outer_eye: 'square,#0a1fd3',
|
|
101
|
+
qr_dot: 'dot,#0a1fd3',
|
|
102
|
+
qr_bg_color: '0x22d1af',
|
|
103
|
+
pfp_zoom: 20,
|
|
104
|
+
pfp_offset: [124, 58],
|
|
105
|
+
font: 'Family Name,https://fonts.com/super_cool_font.woff',
|
|
106
|
+
font_color: '0x0a1fd3',
|
|
107
|
+
font_shadow_size: [12, 12, 8],
|
|
108
|
+
text_ribbon_colors: ['0x0a1fd3', '0x22d1af', '0x31bc23'],
|
|
109
|
+
text_ribbon_gradient: 'linear-45'
|
|
110
|
+
});
|
|
111
|
+
const cbor = 'b151666f6e745f736861646f775f636f6c6f72430000004862675f636f6c6f72430a1fd34f62675f626f726465725f636f6c6f72430a1fd34771725f6c696e6b581968747470733a2f2f68616e646c652e6d652f6275727269746f47736f6369616c739fa247646973706c6179447461636f4375726c5668747470733a2f2f68616e646c652e6d652f7461636fff507066705f626f726465725f636f6c6f72430a1fd34c71725f696e6e65725f6579654f726f756e6465642c233061316664334c71725f6f757465725f6579654e7371756172652c233061316664334671725f646f744b646f742c233061316664334b71725f62675f636f6c6f724322d1af487066705f7a6f6f6d144a7066705f6f66667365749f187c183aff44666f6e74583246616d696c79204e616d652c68747470733a2f2f666f6e74732e636f6d2f73757065725f636f6f6c5f666f6e742e776f66664a666f6e745f636f6c6f72430a1fd350666f6e745f736861646f775f73697a659f0c0c08ff52746578745f726962626f6e5f636f6c6f72739f430a1fd34322d1af4331bc23ff54746578745f726962626f6e5f6772616469656e74496c696e6561722d3435';
|
|
112
|
+
it('Should convert designer datum to cbor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(getJson());
|
|
114
|
+
expect(encoded).toEqual(cbor);
|
|
115
|
+
}));
|
|
116
|
+
it('Should convert cbor to designer datum', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema: designer_1.designerSchema });
|
|
118
|
+
expect(decoded).toEqual(getJson());
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
describe('Encode/decode portal datum', () => {
|
|
122
|
+
const getJson = () => ({
|
|
123
|
+
type: 'redirect',
|
|
124
|
+
domain: 'https://handle.me',
|
|
125
|
+
default: true
|
|
126
|
+
});
|
|
127
|
+
const cbor = 'a3447479706548726564697265637446646f6d61696e5168747470733a2f2f68616e646c652e6d654764656661756c7401';
|
|
128
|
+
it('Should convert portal datum to cbor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(getJson());
|
|
130
|
+
expect(encoded).toEqual(cbor);
|
|
131
|
+
}));
|
|
132
|
+
it('Should convert cbor to portal datum', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema: portal_1.portalSchema });
|
|
134
|
+
expect(decoded).toEqual(getJson());
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
describe('Encode/decode Standard JSON and PlutusDataCbor', () => {
|
|
138
|
+
const json = {
|
|
139
|
+
firstKey: 'string',
|
|
140
|
+
secondKey: {
|
|
141
|
+
firstList: [1, 3],
|
|
142
|
+
'0x222222': [{ thirdKey: '222222' }, { fourthKey: '0x333333' }, { fifthKey: 0 }]
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const cbor = 'a24866697273744b657946737472696e67497365636f6e644b6579a24966697273744c6973749f0103ff432222229fa14874686972644b657946323232323232a149666f757274684b657943333333a14866696674684b657900ff';
|
|
146
|
+
it('Should convert from JSON to TxMetadataJson', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(json);
|
|
148
|
+
expect(encoded).toEqual(cbor);
|
|
149
|
+
}));
|
|
150
|
+
it('Should decode from TxMetadataJson to JSON', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const schema = {
|
|
152
|
+
firstKey: 'string',
|
|
153
|
+
secondKey: {
|
|
154
|
+
firstList: {
|
|
155
|
+
'[0]': 'bool'
|
|
156
|
+
},
|
|
157
|
+
'<hexstring>': {
|
|
158
|
+
'[0]': {
|
|
159
|
+
thirdKey: 'string'
|
|
160
|
+
},
|
|
161
|
+
'[2]': {
|
|
162
|
+
fifthKey: 'number'
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const expectedJson = {
|
|
168
|
+
firstKey: 'string',
|
|
169
|
+
secondKey: {
|
|
170
|
+
firstList: [true, 3],
|
|
171
|
+
'0x222222': [{ thirdKey: '222222' }, { fourthKey: '0x333333' }, { fifthKey: 0 }]
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema });
|
|
175
|
+
expect(decoded).toEqual(expectedJson);
|
|
176
|
+
}));
|
|
177
|
+
});
|
|
178
|
+
describe('Encode/decode personalization settings', () => {
|
|
179
|
+
const pzSettings = [
|
|
180
|
+
1500000,
|
|
181
|
+
'0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8',
|
|
182
|
+
3500000,
|
|
183
|
+
['0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8'],
|
|
184
|
+
['0x3ac54dace81eb69b2c974a1db2b89f2529fbf4da97c482decb32b6a5'],
|
|
185
|
+
['0x151a82d0669a20bd77de1296eee5ef1259ce98ecd81bd7121825f9eb'],
|
|
186
|
+
'0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8'
|
|
187
|
+
];
|
|
188
|
+
const pzCbor = '9f1a0016e360581c300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b81a003567e09f581c300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8ff9f581c3ac54dace81eb69b2c974a1db2b89f2529fbf4da97c482decb32b6a5ff9f581c151a82d0669a20bd77de1296eee5ef1259ce98ecd81bd7121825f9ebff581c300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8ff';
|
|
189
|
+
it('Should encode personalization settings', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(pzSettings);
|
|
191
|
+
expect(encoded).toEqual(pzCbor);
|
|
192
|
+
}));
|
|
193
|
+
it('Should decode personalization settings', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: pzCbor });
|
|
195
|
+
expect(decoded).toEqual([
|
|
196
|
+
1500000,
|
|
197
|
+
'0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8',
|
|
198
|
+
3500000,
|
|
199
|
+
['0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8'],
|
|
200
|
+
['0x3ac54dace81eb69b2c974a1db2b89f2529fbf4da97c482decb32b6a5'],
|
|
201
|
+
['0x151a82d0669a20bd77de1296eee5ef1259ce98ecd81bd7121825f9eb'],
|
|
202
|
+
'0x300b1c7993d1e2f33007ca24a00c977d9b187d57e77e0b8fc6b344b8'
|
|
203
|
+
]);
|
|
204
|
+
}));
|
|
205
|
+
});
|
|
206
|
+
describe('Encode/decode hex colors', () => {
|
|
207
|
+
it('Should encode hex encoded values properly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)({
|
|
209
|
+
colors: ['0xffffff', '0x000000']
|
|
210
|
+
});
|
|
211
|
+
expect(encoded).toEqual('a146636f6c6f72739f43ffffff43000000ff');
|
|
212
|
+
}));
|
|
213
|
+
it('Should decode hex properly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
214
|
+
const cbor = 'a166636f6c6f72738243ffffff43000000';
|
|
215
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor });
|
|
216
|
+
expect(decoded).toEqual({ colors: ['0xffffff', '0x000000'] });
|
|
217
|
+
}));
|
|
218
|
+
});
|
|
219
|
+
describe('Encode/decode nested constructors', () => {
|
|
220
|
+
it('Should encode multiple constructors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
const json = [
|
|
222
|
+
{
|
|
223
|
+
constructor_0: [
|
|
224
|
+
{
|
|
225
|
+
name: 'xar12345'
|
|
226
|
+
},
|
|
227
|
+
1,
|
|
228
|
+
{
|
|
229
|
+
constructor_1: [
|
|
230
|
+
{
|
|
231
|
+
custom_image: {
|
|
232
|
+
constructor_2: [{ image: 'ipfs://cid' }]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
constructor_0: [
|
|
241
|
+
{
|
|
242
|
+
name: 'xar12345'
|
|
243
|
+
},
|
|
244
|
+
1,
|
|
245
|
+
{
|
|
246
|
+
constructor_1: [
|
|
247
|
+
{
|
|
248
|
+
custom_image: {
|
|
249
|
+
constructor_2: [{ image: 'ipfs://cid' }]
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
];
|
|
257
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(json);
|
|
258
|
+
expect(encoded).toEqual('9fd8799fa1446e616d6548786172313233343501d87a9fa14c637573746f6d5f696d616765d87b9fa145696d6167654a697066733a2f2f636964ffffffd8799fa1446e616d6548786172313233343501d87a9fa14c637573746f6d5f696d616765d87b9fa145696d6167654a697066733a2f2f636964ffffffff');
|
|
259
|
+
}));
|
|
260
|
+
it('Should decode nested constructors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
261
|
+
const cbor = '82d87983a1446e616d6548786172313233343501d87a81a14c637573746f6d5f696d616765d87b81a145696d6167654a697066733a2f2f636964d87983a1446e616d6548786172313233343501d87a81a14c637573746f6d5f696d616765d87b81a145696d6167654a697066733a2f2f636964';
|
|
262
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor });
|
|
263
|
+
expect(decoded).toEqual([
|
|
264
|
+
{
|
|
265
|
+
constructor_0: [
|
|
266
|
+
{ name: '0x7861723132333435' },
|
|
267
|
+
1,
|
|
268
|
+
{ constructor_1: [{ custom_image: { constructor_2: [{ image: '0x697066733a2f2f636964' }] } }] }
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
constructor_0: [
|
|
273
|
+
{ name: '0x7861723132333435' },
|
|
274
|
+
1,
|
|
275
|
+
{ constructor_1: [{ custom_image: { constructor_2: [{ image: '0x697066733a2f2f636964' }] } }] }
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
]);
|
|
279
|
+
}));
|
|
280
|
+
});
|
|
281
|
+
describe('encodeJsonToDatum tests', () => {
|
|
282
|
+
it('Should encode policyIds correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
283
|
+
const json = {
|
|
284
|
+
'0x5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6': {
|
|
285
|
+
'': 0
|
|
286
|
+
},
|
|
287
|
+
'0x8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eb': {
|
|
288
|
+
'': 0
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(json);
|
|
292
|
+
expect(encoded).toEqual('a2581c5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6a14000581c8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eba14000');
|
|
293
|
+
}));
|
|
294
|
+
it('Should encode nested arrays and objects correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
+
const json = [
|
|
296
|
+
{
|
|
297
|
+
'0x5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6': {
|
|
298
|
+
'': 0
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
[
|
|
302
|
+
{
|
|
303
|
+
'0x8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eb': {
|
|
304
|
+
'': 0
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
'0x444444': {
|
|
309
|
+
'': 0
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
];
|
|
314
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(json);
|
|
315
|
+
expect(encoded).toEqual('9fa1581c5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6a140009fa1581c8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eba14000a143444444a14000ffff');
|
|
316
|
+
}));
|
|
317
|
+
it('Should encode really long string', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
318
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)({
|
|
319
|
+
colors: '012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'
|
|
320
|
+
});
|
|
321
|
+
expect(encoded).toEqual('a146636f6c6f72735f5840303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132335840343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536375638393031323334353637383930313233343536373839ff');
|
|
322
|
+
}));
|
|
323
|
+
});
|
|
324
|
+
describe('decodeJsonDatumToJson tests', () => {
|
|
325
|
+
it('Should decode cbor that is not a 12(1-4) tag', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
326
|
+
const cbor = 'a2581c5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6a14000581c8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eba14000';
|
|
327
|
+
const schema = {
|
|
328
|
+
'<hexstring>': {
|
|
329
|
+
'<hexstring>': 'number'
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema });
|
|
333
|
+
expect(decoded).toEqual({
|
|
334
|
+
'0x5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6': { '0x': 0 },
|
|
335
|
+
'0x8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eb': { '0x': 0 }
|
|
336
|
+
});
|
|
337
|
+
}));
|
|
338
|
+
it('should use default key type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
|
+
const cbor = 'a2581c5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6a14000581c8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eba14000';
|
|
340
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, defaultKeyType: index_1.KeyType.HEX });
|
|
341
|
+
expect(decoded).toEqual({
|
|
342
|
+
'0x5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6': { '0x': 0 },
|
|
343
|
+
'0x8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eb': { '0x': 0 }
|
|
344
|
+
});
|
|
345
|
+
}));
|
|
346
|
+
it('Should decode cbor that is an array of objects and not a 12(1-4) tag', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
const cbor = '82a1581c5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6a1400082a1581c8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eba14000a143444444a14000';
|
|
348
|
+
const schema = {
|
|
349
|
+
'[0]': {
|
|
350
|
+
'<hexstring>': {
|
|
351
|
+
'<hexstring>': 'number'
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
'[1]': {
|
|
355
|
+
'[all]': {
|
|
356
|
+
'<hexstring>': {
|
|
357
|
+
'<hexstring>': 'number'
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema });
|
|
363
|
+
expect(decoded).toEqual([
|
|
364
|
+
{ '0x5ca7f4e1e708ddf1958b2b7e65134738ebba5d8c803bdbe50ea0f3c6': { '0x': 0 } },
|
|
365
|
+
[
|
|
366
|
+
{ '0x8ed30c080aba8eb431dabb802ea8dda3a131b0f49c72d2766b25b1eb': { '0x': 0 } },
|
|
367
|
+
{ '0x444444': { '0x': 0 } }
|
|
368
|
+
]
|
|
369
|
+
]);
|
|
370
|
+
}));
|
|
371
|
+
});
|
|
372
|
+
describe('Encode/decode numeric keys', () => {
|
|
373
|
+
const getJson = () => [
|
|
374
|
+
'0x008e4ac0583cfeb7a1bb3434f10afc8439aa4d5e7eac6e6f2822ce5b9dfc56a127f684fe6d2bb4eedaef9525a69f0fa08b5796599cb6eae25d',
|
|
375
|
+
'0x700401221efdbba348b80457d4f27b17db1b45ad510511a8756ff564b5',
|
|
376
|
+
[
|
|
377
|
+
[
|
|
378
|
+
'0x001bc2805461636f2031',
|
|
379
|
+
['0x04507ca1f0757dce73d1c410fa2a47918582f1c52a0661a308b97a27f24897f4', 0],
|
|
380
|
+
5000000,
|
|
381
|
+
0,
|
|
382
|
+
{}
|
|
383
|
+
],
|
|
384
|
+
[
|
|
385
|
+
'0x001bc2805461636f2032',
|
|
386
|
+
['0x39dbe8fd40bfee718b34a6464731ae02f0c89e153ec2ffc5ebc0c0c5476a0c9c', 0],
|
|
387
|
+
0,
|
|
388
|
+
0,
|
|
389
|
+
{}
|
|
390
|
+
],
|
|
391
|
+
[
|
|
392
|
+
'0x001bc2805461636f2033',
|
|
393
|
+
['0x939db71ab742a955ed2cb6c359a8f36dca52749871656fc13683c77072a3bc0b', 0],
|
|
394
|
+
10000000,
|
|
395
|
+
0,
|
|
396
|
+
{}
|
|
397
|
+
],
|
|
398
|
+
[
|
|
399
|
+
'0x001bc2805461636f2034',
|
|
400
|
+
['0xb5ee5636290985cf378cc2819346eeee06efa8c13ab044f426b59c52e8224a99', 0],
|
|
401
|
+
5000000,
|
|
402
|
+
1698956400000,
|
|
403
|
+
{}
|
|
404
|
+
],
|
|
405
|
+
[
|
|
406
|
+
'0x001bc2805461636f2035',
|
|
407
|
+
['0x1928d9ad51fdd909e187d7babdba79052cddb3aced97d2a7a28b3f7881545f26', 0],
|
|
408
|
+
10000000,
|
|
409
|
+
1698966000716,
|
|
410
|
+
{
|
|
411
|
+
'0xf0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a': {
|
|
412
|
+
'1': 5000000,
|
|
413
|
+
'2': 2500000,
|
|
414
|
+
'3': 1000000
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
],
|
|
419
|
+
{
|
|
420
|
+
collectionName: 'Tacos',
|
|
421
|
+
collectionImage: 'ipfs://bafybeicy7cvoqste36bjfxsm37xuofxgh7kj7ryal7tbwmbhqowm4kmxke',
|
|
422
|
+
royaltyPercentage: 0,
|
|
423
|
+
royaltyAddress: 'addr_test1qz8y4szc8nlt0gdmxs60zzhussu65n2706kxumegyt89h80u26sj0a5ylekjhd8wmthe2fdxnu86pz6hjeveedh2ufwsq9puqn',
|
|
424
|
+
lastEditingContractHash: '0x0401221efdbba348b80457d4f27b17db1b45ad510511a8756ff564b5',
|
|
425
|
+
mintingPolicyId: '0x931f6c1fd0374e2c08449986c946aef138e95c3e3ff8c30a37bd017b',
|
|
426
|
+
nsfw: 0
|
|
427
|
+
}
|
|
428
|
+
];
|
|
429
|
+
const schema = {
|
|
430
|
+
'[2]': {
|
|
431
|
+
'[all]': {
|
|
432
|
+
'[4]': {
|
|
433
|
+
'<hexstring>': {
|
|
434
|
+
'<string>': 'number'
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
'[3]': {
|
|
440
|
+
collectionName: 'string',
|
|
441
|
+
collectionImage: 'string',
|
|
442
|
+
royaltyAddress: 'string'
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const cbor = '9f5839008e4ac0583cfeb7a1bb3434f10afc8439aa4d5e7eac6e6f2822ce5b9dfc56a127f684fe6d2bb4eedaef9525a69f0fa08b5796599cb6eae25d581d700401221efdbba348b80457d4f27b17db1b45ad510511a8756ff564b59f9f4a001bc2805461636f20319f582004507ca1f0757dce73d1c410fa2a47918582f1c52a0661a308b97a27f24897f400ff1a004c4b4000a0ff9f4a001bc2805461636f20329f582039dbe8fd40bfee718b34a6464731ae02f0c89e153ec2ffc5ebc0c0c5476a0c9c00ff0000a0ff9f4a001bc2805461636f20339f5820939db71ab742a955ed2cb6c359a8f36dca52749871656fc13683c77072a3bc0b00ff1a0098968000a0ff9f4a001bc2805461636f20349f5820b5ee5636290985cf378cc2819346eeee06efa8c13ab044f426b59c52e8224a9900ff1a004c4b401b0000018b91b15580a0ff9f4a001bc2805461636f20359f58201928d9ad51fdd909e187d7babdba79052cddb3aced97d2a7a28b3f7881545f2600ff1a009896801b0000018b9243d44ca1581cf0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9aa3011a004c4b40021a002625a0031a000f4240ffffa74e636f6c6c656374696f6e4e616d65455461636f734f636f6c6c656374696f6e496d6167655f5840697066733a2f2f6261667962656963793763766f717374653336626a6678736d333778756f66786768376b6a377279616c377462776d6268716f776d346b6d78426b65ff51726f79616c747950657263656e74616765004e726f79616c7479416464726573735f5840616464725f7465737431717a387934737a63386e6c743067646d787336307a7a687573737536356e323730366b78756d656779743839683830753236736a3061582c35796c656b6a686438776d746865326664786e753836707a36686a657665656468327566777371397075716eff576c61737445646974696e67436f6e747261637448617368581c0401221efdbba348b80457d4f27b17db1b45ad510511a8756ff564b54f6d696e74696e67506f6c6963794964581c931f6c1fd0374e2c08449986c946aef138e95c3e3ff8c30a37bd017b446e73667700ff';
|
|
446
|
+
it('Should convert from JSON to TxMetadataJson with numberic keys', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
447
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(getJson(), true);
|
|
448
|
+
expect(encoded).toEqual(cbor);
|
|
449
|
+
}));
|
|
450
|
+
it('Should convert cbor to portal datum', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
451
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema });
|
|
452
|
+
expect(decoded).toEqual(getJson());
|
|
453
|
+
}));
|
|
454
|
+
});
|
|
455
|
+
describe('Encode/deode 0x strings', () => {
|
|
456
|
+
const getJson = () => [
|
|
457
|
+
'~0x008e4ac0583cfeb7a1bb3434f10afc8439aa4d5e7eac6e6f2822ce5b9dfc56a127f684fe6d2bb4eedaef9525a69f0fa08b5796599cb6eae25d'
|
|
458
|
+
];
|
|
459
|
+
const schema = {
|
|
460
|
+
'[all]': 'string'
|
|
461
|
+
};
|
|
462
|
+
const cbor = '9f5f584030783030386534616330353833636665623761316262333433346631306166633834333961613464356537656163366536663238323263653562396466633536583461313237663638346665366432626234656564616566393532356136396630666130386235373936353939636236656165323564ffff';
|
|
463
|
+
it('Should convert from JSON to TxMetadataJson with numberic keys', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
464
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(getJson());
|
|
465
|
+
expect(encoded).toEqual(cbor);
|
|
466
|
+
}));
|
|
467
|
+
it('Should convert cbor to portal datum', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
468
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, schema });
|
|
469
|
+
expect(decoded).toEqual([
|
|
470
|
+
'0x008e4ac0583cfeb7a1bb3434f10afc8439aa4d5e7eac6e6f2822ce5b9dfc56a127f684fe6d2bb4eedaef9525a69f0fa08b5796599cb6eae25d'
|
|
471
|
+
]);
|
|
472
|
+
}));
|
|
473
|
+
});
|
|
474
|
+
describe('Encode/decode duplicate keys', () => {
|
|
475
|
+
const dupeKeyMap = new Map();
|
|
476
|
+
dupeKeyMap.set(new index_1.DupeKey('a'), 'abc');
|
|
477
|
+
dupeKeyMap.set(new index_1.DupeKey('a'), 'def');
|
|
478
|
+
dupeKeyMap.set(new index_1.DupeKey('b'), 'ghi');
|
|
479
|
+
dupeKeyMap.set(new index_1.DupeKey('b'), 'jkl');
|
|
480
|
+
dupeKeyMap.set(new index_1.DupeKey('c'), 'mno');
|
|
481
|
+
const json = {
|
|
482
|
+
discounts: dupeKeyMap
|
|
483
|
+
};
|
|
484
|
+
const cbor = 'a149646973636f756e7473a54161636162634161636465664162636768694162636a6b6c4163636d6e6f';
|
|
485
|
+
it('Should encode duplicate keys', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
486
|
+
const encoded = yield (0, index_1.encodeJsonToDatum)(json);
|
|
487
|
+
expect(encoded).toEqual(cbor);
|
|
488
|
+
}));
|
|
489
|
+
it('Should decode duplicate keys as Dedupe Map', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
490
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor, forJson: false });
|
|
491
|
+
const expected = [
|
|
492
|
+
{
|
|
493
|
+
key: 'a',
|
|
494
|
+
value: 'abc'
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
key: 'a',
|
|
498
|
+
value: 'def'
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
key: 'b',
|
|
502
|
+
value: 'ghi'
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
key: 'b',
|
|
506
|
+
value: 'jkl'
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
key: 'c',
|
|
510
|
+
value: 'mno'
|
|
511
|
+
}
|
|
512
|
+
];
|
|
513
|
+
expect([...decoded.discounts.entries()].map(([key, value]) => ({
|
|
514
|
+
key: key instanceof index_1.DupeKey ? key.key : key,
|
|
515
|
+
value
|
|
516
|
+
}))).toEqual(expected);
|
|
517
|
+
}));
|
|
518
|
+
it('Should decode duplicate keys for json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
519
|
+
const decoded = yield (0, index_1.decodeCborToJson)({ cborString: cbor });
|
|
520
|
+
const expected = {
|
|
521
|
+
discounts: {
|
|
522
|
+
dupekey_str_a_0: 'abc',
|
|
523
|
+
dupekey_str_a_1: 'def',
|
|
524
|
+
dupekey_str_b_0: 'ghi',
|
|
525
|
+
dupekey_str_b_1: 'jkl',
|
|
526
|
+
dupekey_str_c_0: 'mno'
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
expect(decoded).toEqual(expected);
|
|
530
|
+
}));
|
|
531
|
+
});
|
|
532
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const designerSchema: {
|
|
2
|
+
bg_image: string;
|
|
3
|
+
pfp_image: string;
|
|
4
|
+
svg_version: string;
|
|
5
|
+
qr_link: string;
|
|
6
|
+
qr_inner_eye: string;
|
|
7
|
+
qr_outer_eye: string;
|
|
8
|
+
qr_dot: string;
|
|
9
|
+
qr_image: string;
|
|
10
|
+
font: string;
|
|
11
|
+
socials: {
|
|
12
|
+
'[all]': {
|
|
13
|
+
display: string;
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
text_ribbon_gradient: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.designerSchema = void 0;
|
|
4
|
+
exports.designerSchema = {
|
|
5
|
+
bg_image: 'string',
|
|
6
|
+
pfp_image: 'string',
|
|
7
|
+
svg_version: 'string',
|
|
8
|
+
qr_link: 'string',
|
|
9
|
+
qr_inner_eye: 'string',
|
|
10
|
+
qr_outer_eye: 'string',
|
|
11
|
+
qr_dot: 'string',
|
|
12
|
+
qr_image: 'string',
|
|
13
|
+
font: 'string',
|
|
14
|
+
socials: {
|
|
15
|
+
'[all]': {
|
|
16
|
+
display: 'string',
|
|
17
|
+
url: 'string'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
text_ribbon_gradient: 'string'
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const handleDatumSchema: {
|
|
2
|
+
constructor_0: {
|
|
3
|
+
'[0]': {
|
|
4
|
+
name: string;
|
|
5
|
+
image: string;
|
|
6
|
+
mediaType: string;
|
|
7
|
+
og: string;
|
|
8
|
+
rarity: string;
|
|
9
|
+
characters: string;
|
|
10
|
+
numeric_modifiers: string;
|
|
11
|
+
};
|
|
12
|
+
'[2]': {
|
|
13
|
+
standard_image: string;
|
|
14
|
+
bg_image: string;
|
|
15
|
+
pfp_image: string;
|
|
16
|
+
portal: string;
|
|
17
|
+
designer: string;
|
|
18
|
+
socials: string;
|
|
19
|
+
vendor: string;
|
|
20
|
+
default: string;
|
|
21
|
+
resolved_addresses: {
|
|
22
|
+
ada: string;
|
|
23
|
+
'<string>': string;
|
|
24
|
+
};
|
|
25
|
+
trial: string;
|
|
26
|
+
nsfw: string;
|
|
27
|
+
svg_version: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleDatumSchema = void 0;
|
|
4
|
+
exports.handleDatumSchema = {
|
|
5
|
+
constructor_0: {
|
|
6
|
+
'[0]': {
|
|
7
|
+
name: 'string',
|
|
8
|
+
image: 'string',
|
|
9
|
+
mediaType: 'string',
|
|
10
|
+
og: 'bool',
|
|
11
|
+
rarity: 'string',
|
|
12
|
+
characters: 'string',
|
|
13
|
+
numeric_modifiers: 'string'
|
|
14
|
+
},
|
|
15
|
+
'[2]': {
|
|
16
|
+
standard_image: 'string',
|
|
17
|
+
bg_image: 'string',
|
|
18
|
+
pfp_image: 'string',
|
|
19
|
+
portal: 'string',
|
|
20
|
+
designer: 'string',
|
|
21
|
+
socials: 'string',
|
|
22
|
+
vendor: 'string',
|
|
23
|
+
default: 'bool',
|
|
24
|
+
resolved_addresses: {
|
|
25
|
+
ada: 'hex',
|
|
26
|
+
'<string>': 'string'
|
|
27
|
+
},
|
|
28
|
+
trial: 'bool',
|
|
29
|
+
nsfw: 'bool',
|
|
30
|
+
svg_version: 'string'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const subHandleSettingsDatumSchema: {
|
|
2
|
+
nft: {
|
|
3
|
+
enabled: string;
|
|
4
|
+
tierPricing: {
|
|
5
|
+
'[all]': {
|
|
6
|
+
0: string;
|
|
7
|
+
1: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
enablePz: string;
|
|
11
|
+
creatorDefaults: {
|
|
12
|
+
font: string;
|
|
13
|
+
text_ribbon_gradient: string;
|
|
14
|
+
force_creator_settings: string;
|
|
15
|
+
qr_inner_eye: string;
|
|
16
|
+
qr_outer_eye: string;
|
|
17
|
+
qr_dot: string;
|
|
18
|
+
bg_image: string;
|
|
19
|
+
};
|
|
20
|
+
creatorDefaultsBgImage: string;
|
|
21
|
+
};
|
|
22
|
+
virtual: {
|
|
23
|
+
expires_in_days: string;
|
|
24
|
+
enabled: string;
|
|
25
|
+
tierPricing: {
|
|
26
|
+
'[all]': {
|
|
27
|
+
0: string;
|
|
28
|
+
1: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
enablePz: string;
|
|
32
|
+
creatorDefaults: {
|
|
33
|
+
font: string;
|
|
34
|
+
text_ribbon_gradient: string;
|
|
35
|
+
force_creator_settings: string;
|
|
36
|
+
qr_inner_eye: string;
|
|
37
|
+
qr_outer_eye: string;
|
|
38
|
+
qr_dot: string;
|
|
39
|
+
bg_image: string;
|
|
40
|
+
};
|
|
41
|
+
creatorDefaultsBgImage: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subHandleSettingsDatumSchema = void 0;
|
|
4
|
+
const subHandleSettings = {
|
|
5
|
+
enabled: 'bool',
|
|
6
|
+
tierPricing: {
|
|
7
|
+
'[all]': {
|
|
8
|
+
['0']: 'number',
|
|
9
|
+
['1']: 'number'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
enablePz: 'bool',
|
|
13
|
+
creatorDefaults: {
|
|
14
|
+
font: 'string',
|
|
15
|
+
text_ribbon_gradient: 'string',
|
|
16
|
+
force_creator_settings: 'bool',
|
|
17
|
+
qr_inner_eye: 'string',
|
|
18
|
+
qr_outer_eye: 'string',
|
|
19
|
+
qr_dot: 'string',
|
|
20
|
+
bg_image: 'string'
|
|
21
|
+
},
|
|
22
|
+
creatorDefaultsBgImage: 'string'
|
|
23
|
+
};
|
|
24
|
+
exports.subHandleSettingsDatumSchema = {
|
|
25
|
+
nft: subHandleSettings,
|
|
26
|
+
virtual: Object.assign(Object.assign({}, subHandleSettings), { expires_in_days: 'number' })
|
|
27
|
+
};
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const asyncForEach: <T, U>(array: T[], callback: (item: T, index:
|
|
|
7
7
|
export declare const isNumeric: (n: string) => boolean;
|
|
8
8
|
export declare const isNullEmptyOrUndefined: (value: any) => boolean;
|
|
9
9
|
export declare const isAlphaNumeric: (str: string) => boolean;
|
|
10
|
+
export { KeyType, encodeJsonToDatum, decodeCborToJson } from './cbor';
|
package/lib/utils/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.isAlphaNumeric = exports.isNullEmptyOrUndefined = exports.isNumeric = exports.asyncForEach = exports.awaitForEach = exports.chunk = exports.toADA = exports.toLovelace = exports.delay = void 0;
|
|
12
|
+
exports.decodeCborToJson = exports.encodeJsonToDatum = exports.KeyType = exports.isAlphaNumeric = exports.isNullEmptyOrUndefined = exports.isNumeric = exports.asyncForEach = exports.awaitForEach = exports.chunk = exports.toADA = exports.toLovelace = exports.delay = void 0;
|
|
13
13
|
const delay = (ms) => {
|
|
14
14
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
15
|
};
|
|
@@ -20,9 +20,7 @@ const toADA = (lovelaceAmount) => lovelaceAmount / 1000000;
|
|
|
20
20
|
exports.toADA = toADA;
|
|
21
21
|
const chunk = (input, size) => {
|
|
22
22
|
return input.reduce((arr, item, idx) => {
|
|
23
|
-
return idx % size === 0
|
|
24
|
-
? [...arr, [item]]
|
|
25
|
-
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
|
|
23
|
+
return idx % size === 0 ? [...arr, [item]] : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
|
|
26
24
|
}, []);
|
|
27
25
|
};
|
|
28
26
|
exports.chunk = chunk;
|
|
@@ -32,7 +30,7 @@ const awaitForEach = (array, callback) => __awaiter(void 0, void 0, void 0, func
|
|
|
32
30
|
}
|
|
33
31
|
});
|
|
34
32
|
exports.awaitForEach = awaitForEach;
|
|
35
|
-
// Used to execute Promises in order, but still async.
|
|
33
|
+
// Used to execute Promises in order, but still async.
|
|
36
34
|
// Good for adding delay between API calls and you need the complete list of results when they all resolve
|
|
37
35
|
const asyncForEach = (array, callback, delayInMilliseconds = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
36
|
const promises = [];
|
|
@@ -50,10 +48,18 @@ const isNumeric = (n) => {
|
|
|
50
48
|
};
|
|
51
49
|
exports.isNumeric = isNumeric;
|
|
52
50
|
const isNullEmptyOrUndefined = (value) => {
|
|
53
|
-
return value == undefined ||
|
|
51
|
+
return (value == undefined ||
|
|
52
|
+
value == null ||
|
|
53
|
+
value == '' ||
|
|
54
|
+
JSON.stringify(value) === '{}' ||
|
|
55
|
+
JSON.stringify(value) === '[]');
|
|
54
56
|
};
|
|
55
57
|
exports.isNullEmptyOrUndefined = isNullEmptyOrUndefined;
|
|
56
58
|
const isAlphaNumeric = (str) => {
|
|
57
59
|
return /^[a-zA-Z0-9]+$/.test(str);
|
|
58
60
|
};
|
|
59
61
|
exports.isAlphaNumeric = isAlphaNumeric;
|
|
62
|
+
var cbor_1 = require("./cbor");
|
|
63
|
+
Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return cbor_1.KeyType; } });
|
|
64
|
+
Object.defineProperty(exports, "encodeJsonToDatum", { enumerable: true, get: function () { return cbor_1.encodeJsonToDatum; } });
|
|
65
|
+
Object.defineProperty(exports, "decodeCborToJson", { enumerable: true, get: function () { return cbor_1.decodeCborToJson; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koralabs/kora-labs-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Kora Labs Common Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
"typescript": "^4.7.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"boolean": "^3.2.0",
|
|
34
|
+
"cbor": "^9.0.2",
|
|
33
35
|
"pluralize": "^8.0.0"
|
|
34
36
|
},
|
|
35
37
|
"files": [
|