@koralabs/kora-labs-common 5.1.20 → 5.1.22

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.
@@ -5,16 +5,26 @@ export type NftAttributes = {
5
5
  image: string;
6
6
  [key: string]: string | number | boolean;
7
7
  };
8
+ export interface IPayout {
9
+ address: string;
10
+ lovelace: number;
11
+ }
8
12
  export interface IMarketplaceListing {
9
- assetName: string;
10
- assetNameHex: string;
13
+ asset_name: string;
14
+ asset_name_hex: string;
11
15
  image: string;
12
- assetLabel?: AssetNameLabel;
13
- policyId: string;
14
- nftAttributes?: NftAttributes;
16
+ asset_label?: AssetNameLabel;
17
+ policy_id: string;
18
+ nft_attributes?: NftAttributes;
15
19
  utxo: IUTxO;
16
20
  holder: string;
17
21
  price: number;
18
- payoutAddress: string;
19
- slotNumber: number;
22
+ payouts: IPayout[];
23
+ slot_number: number;
24
+ }
25
+ export interface PayoutStruct {
26
+ [constructor: string]: [string, number];
27
+ }
28
+ export interface MarketplaceListingDatumScript {
29
+ constructor_0: [PayoutStruct[], string];
20
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "5.1.20",
3
+ "version": "5.1.22",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  export { designerSchema } from './schema/designer';
3
- export { subHandleSettingsDatumSchema } from './schema/subHandleSettings';
4
3
  export { handleDatumSchema } from './schema/handleData';
4
+ export { marketplaceDatumSchema } from './schema/marketplaceDatum';
5
5
  export { portalSchema } from './schema/portal';
6
6
  export { socialsSchema } from './schema/socials';
7
7
  export declare enum DefaultTextFormat {
@@ -23,15 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.decodeCborToJson = exports.encodeJsonToDatum = exports.DupeKey = exports.DefaultTextFormat = exports.socialsSchema = exports.portalSchema = exports.handleDatumSchema = exports.subHandleSettingsDatumSchema = exports.designerSchema = void 0;
27
- const cbor = __importStar(require("cbor"));
26
+ exports.decodeCborToJson = exports.encodeJsonToDatum = exports.DupeKey = exports.DefaultTextFormat = exports.socialsSchema = exports.portalSchema = exports.marketplaceDatumSchema = exports.handleDatumSchema = exports.designerSchema = void 0;
28
27
  const boolean_1 = require("boolean");
28
+ const cbor = __importStar(require("cbor"));
29
29
  var designer_1 = require("./schema/designer");
30
30
  Object.defineProperty(exports, "designerSchema", { enumerable: true, get: function () { return designer_1.designerSchema; } });
31
- var subHandleSettings_1 = require("./schema/subHandleSettings");
32
- Object.defineProperty(exports, "subHandleSettingsDatumSchema", { enumerable: true, get: function () { return subHandleSettings_1.subHandleSettingsDatumSchema; } });
33
31
  var handleData_1 = require("./schema/handleData");
34
32
  Object.defineProperty(exports, "handleDatumSchema", { enumerable: true, get: function () { return handleData_1.handleDatumSchema; } });
33
+ var marketplaceDatum_1 = require("./schema/marketplaceDatum");
34
+ Object.defineProperty(exports, "marketplaceDatumSchema", { enumerable: true, get: function () { return marketplaceDatum_1.marketplaceDatumSchema; } });
35
35
  var portal_1 = require("./schema/portal");
36
36
  Object.defineProperty(exports, "portalSchema", { enumerable: true, get: function () { return portal_1.portalSchema; } });
37
37
  var socials_1 = require("./schema/socials");
@@ -170,7 +170,7 @@ const encodeJsonToDatum = async (json, options) => {
170
170
  };
171
171
  exports.encodeJsonToDatum = encodeJsonToDatum;
172
172
  const parseSchema = (key, schema, defaultKeyType, i) => {
173
- let schemaValue;
173
+ let schemaValueType;
174
174
  if (Number.isInteger(key)) {
175
175
  key = `${key}`;
176
176
  }
@@ -197,13 +197,54 @@ const parseSchema = (key, schema, defaultKeyType, i) => {
197
197
  }
198
198
  }
199
199
  if (schemaKey) {
200
- schemaValue = schema[schemaKey];
200
+ schemaValueType = schema[schemaKey];
201
201
  }
202
202
  return {
203
203
  mapKey,
204
- schemaValue
204
+ schemaValueType
205
205
  };
206
206
  };
207
+ const getAddressHexFromObject = (obj) => {
208
+ // beginning of address is split networkConstrKey on _ and use index[1]
209
+ // address type is based on paymentConstrKey and stakeConstrKey
210
+ let addressType;
211
+ const networkConstrKey = Object.keys(obj)[0];
212
+ const network = networkConstrKey.split('_')[1];
213
+ const [paymentCredential, option] = obj[networkConstrKey];
214
+ const paymentCredentialKey = Object.keys(paymentCredential)[0]; // 0 or 1
215
+ const paymentHashType = paymentCredentialKey.split('_')[1];
216
+ const paymentHash = Buffer.from(paymentCredential[paymentCredentialKey][0]).toString('hex');
217
+ let stakeHashType;
218
+ let stakeHash = '';
219
+ if (option) {
220
+ const [, [reference]] = Object.entries(option)[0];
221
+ if (reference) {
222
+ const referenceKey = Object.keys(reference)[0];
223
+ const stakeCredentialKey = Object.keys(reference[referenceKey][0])[0];
224
+ stakeHash = Buffer.from(reference[referenceKey][0][stakeCredentialKey][0]).toString('hex');
225
+ stakeHashType = stakeCredentialKey.split('_')[1];
226
+ }
227
+ }
228
+ if (paymentHashType === '0' && stakeHashType === '0') {
229
+ addressType = '0';
230
+ }
231
+ if (paymentHashType === '1' && stakeHashType === '0') {
232
+ addressType = '1';
233
+ }
234
+ if (paymentHashType === '0' && stakeHashType === '1') {
235
+ addressType = '2';
236
+ }
237
+ if (paymentHashType === '1' && stakeHashType === '1') {
238
+ addressType = '3';
239
+ }
240
+ if (paymentHashType === '0' && !stakeHashType) {
241
+ addressType = '6';
242
+ }
243
+ if (paymentHashType === '1' && !stakeHashType) {
244
+ addressType = '7';
245
+ }
246
+ return `0x${addressType}${network}${paymentHash}${stakeHash}`;
247
+ };
207
248
  const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = DefaultTextFormat.UTF8, forJson = true }) => {
208
249
  const isMap = val instanceof Map;
209
250
  if (isMap) {
@@ -213,7 +254,7 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
213
254
  for (let i = 0; i < keys.length; i++) {
214
255
  const key = keys[i];
215
256
  const value = val.get(key);
216
- const { mapKey, schemaValue } = parseSchema(key, schema, defaultKeyType, i);
257
+ const { mapKey, schemaValueType } = parseSchema(key, schema, defaultKeyType, i);
217
258
  if (obj.get(mapKey)) {
218
259
  dupeKeys = true;
219
260
  let newKey = `dupekey_str_${mapKey}_1`;
@@ -226,10 +267,10 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
226
267
  const prevValue = obj.get(mapKey);
227
268
  obj.delete(mapKey);
228
269
  obj.set(oldKey, prevValue);
229
- obj.set(newKey, decodeObject({ val: value, constr, schema: schemaValue, defaultKeyType, forJson }));
270
+ obj.set(newKey, decodeObject({ val: value, constr, schema: schemaValueType, defaultKeyType, forJson }));
230
271
  }
231
272
  else {
232
- obj.set(mapKey, decodeObject({ val: value, constr, schema: schemaValue, defaultKeyType, forJson }));
273
+ obj.set(mapKey, decodeObject({ val: value, constr, schema: schemaValueType, defaultKeyType, forJson }));
233
274
  }
234
275
  }
235
276
  if (dupeKeys) {
@@ -268,8 +309,8 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
268
309
  for (let i = 0; i < keys.length; i++) {
269
310
  const key = keys[i];
270
311
  const value = val[key];
271
- const { mapKey, schemaValue } = parseSchema(key, schema, defaultKeyType, i);
272
- obj[mapKey] = decodeObject({ val: value, schema: schemaValue, defaultKeyType, forJson });
312
+ const { mapKey, schemaValueType } = parseSchema(key, schema, defaultKeyType, i);
313
+ obj[mapKey] = decodeObject({ val: value, schema: schemaValueType, defaultKeyType, forJson });
273
314
  }
274
315
  if (constr != null) {
275
316
  return { [`constructor_${constr}`]: obj };
@@ -298,7 +339,13 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
298
339
  if (schemaKey) {
299
340
  schemaValue = schema[schemaKey];
300
341
  }
301
- arr.push(decodeObject({ val: arrayVal, schema: schemaValue, defaultKeyType, forJson }));
342
+ if (schemaValue === 'Address') {
343
+ const addressHex = getAddressHexFromObject(arrayVal);
344
+ arr.push(addressHex);
345
+ }
346
+ else {
347
+ arr.push(decodeObject({ val: arrayVal, schema: schemaValue, defaultKeyType, forJson }));
348
+ }
302
349
  }
303
350
  if (constr != null) {
304
351
  return { [`constructor_${constr}`]: arr };
@@ -0,0 +1,13 @@
1
+ export declare const marketplaceDatumSchema: {
2
+ constructor_0: {
3
+ '[0]': {
4
+ '[all]': {
5
+ constructor_0: {
6
+ '[0]': string;
7
+ '[1]': string;
8
+ };
9
+ };
10
+ };
11
+ '[1]': string;
12
+ };
13
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.marketplaceDatumSchema = void 0;
4
+ exports.marketplaceDatumSchema = {
5
+ constructor_0: {
6
+ '[0]': {
7
+ '[all]': {
8
+ constructor_0: {
9
+ '[0]': 'Address',
10
+ '[1]': 'number'
11
+ }
12
+ }
13
+ },
14
+ '[1]': 'hex'
15
+ }
16
+ };