@koralabs/kora-labs-common 6.13.2 → 6.13.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "6.13.2",
3
+ "version": "6.13.3",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "@aiken-lang/merkle-patricia-forestry": "^1.2.0",
41
41
  "@aws-sdk/client-dynamodb": "^3.549.0",
42
42
  "@aws-sdk/lib-dynamodb": "^3.549.0",
43
- "@cardano-sdk/core": "^0.47.0",
43
+ "@cardano-sdk/core": "^0.46.15",
44
44
  "@cardano-sdk/crypto": "^0.4.7",
45
45
  "@emurgo/cardano-message-signing-nodejs": "^1.1.0",
46
46
  "@types/jest": "^30.0.0",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@aiken-lang/merkle-patricia-forestry": "^1.2.0",
75
- "@cardano-sdk/core": "^0.46.12 || ^0.47.0",
75
+ "@cardano-sdk/core": "^0.46.12",
76
76
  "@cardano-sdk/crypto": "^0.4.5",
77
77
  "bip39": "^3.1.0",
78
78
  "@emurgo/cardano-message-signing-nodejs": "^1.1.0"
@@ -1,3 +1,4 @@
1
+ import * as cbor from 'cbor';
1
2
  export { designerSchema } from './schema/designer';
2
3
  export { handleDatumSchema } from './schema/handleData';
3
4
  export { marketplaceDatumSchema } from './schema/marketplaceDatum';
@@ -52,6 +53,7 @@ export declare class DupeKey extends JsonToDatumObject {
52
53
  constructor(key: string);
53
54
  }
54
55
  export declare const encodeJsonToDatum: (json: any, options?: EncodeOptions) => Promise<string>;
56
+ export declare const constrToTagged: (index: number, fields: unknown) => cbor.Tagged;
55
57
  export declare const decodeCborToJson: ({ cborString, schema, defaultKeyType, forJson }: {
56
58
  cborString: string;
57
59
  schema?: any;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.decodeCborToJson = exports.encodeJsonToDatum = exports.DupeKey = exports.DefaultTextFormat = exports.subHandleSettingsDatumSchema = exports.socialsSchema = exports.portalSchema = exports.marketplaceDatumSchema = exports.handleDatumSchema = exports.designerSchema = void 0;
36
+ exports.decodeCborToJson = exports.constrToTagged = exports.encodeJsonToDatum = exports.DupeKey = exports.DefaultTextFormat = exports.subHandleSettingsDatumSchema = exports.socialsSchema = exports.portalSchema = exports.marketplaceDatumSchema = exports.handleDatumSchema = exports.designerSchema = void 0;
37
37
  const boolean_1 = require("boolean");
38
38
  const cbor = __importStar(require("cbor"));
39
39
  var designer_1 = require("./schema/designer");
@@ -96,7 +96,6 @@ class JsonToDatumObject {
96
96
  else if (typeof this.json === 'object') {
97
97
  if (this.json !== null) {
98
98
  const fieldsMap = new Map();
99
- let tag = null;
100
99
  const keys = this.json instanceof Map ? this.json.keys() : Object.keys(this.json);
101
100
  for (const key of keys) {
102
101
  if (key instanceof DupeKey) {
@@ -104,11 +103,8 @@ class JsonToDatumObject {
104
103
  }
105
104
  else {
106
105
  const split_key = parseInt((_a = key.split('_').at(1)) !== null && _a !== void 0 ? _a : '');
107
- if (key.startsWith('constructor_') &&
108
- !isNaN(split_key) &&
109
- [0, 1, 2, 3].includes(split_key)) {
110
- tag = 121 + split_key;
111
- return encoder.pushAny(new cbor.Tagged(tag, this.json[key]));
106
+ if (key.startsWith('constructor_') && Number.isInteger(split_key) && split_key >= 0) {
107
+ return encoder.pushAny((0, exports.constrToTagged)(split_key, this.json[key]));
112
108
  }
113
109
  const bufferedKey = this.getFormattedKey(key);
114
110
  fieldsMap.set(bufferedKey, this.json[key]);
@@ -393,15 +389,26 @@ const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = Defaul
393
389
  return val;
394
390
  }
395
391
  };
392
+ // Plutus Constr tag scheme (CIP-0005 / plutus-core): 0-6 -> 121-127, 7-127 -> 1280-1400,
393
+ // anything else -> tag 102 wrapping [index, fields]. Every index must round-trip; an
394
+ // unrecognized `constructor_N` key would otherwise be encoded as a text-keyed map.
395
+ const constrToTagged = (index, fields) => {
396
+ if (index <= 6)
397
+ return new cbor.Tagged(121 + index, fields);
398
+ if (index <= 127)
399
+ return new cbor.Tagged(1280 + index - 7, fields);
400
+ return new cbor.Tagged(102, [index, fields]);
401
+ };
402
+ exports.constrToTagged = constrToTagged;
403
+ const CONSTR_DECODE_TAGS = {
404
+ 102: ([index, fields]) => ({ [`constructor_${index}`]: fields })
405
+ };
406
+ for (let index = 0; index <= 127; index++) {
407
+ CONSTR_DECODE_TAGS[index <= 6 ? 121 + index : 1280 + index - 7] = (val) => ({ [`constructor_${index}`]: val });
408
+ }
396
409
  const decodeCborToJson = ({ cborString, schema, defaultKeyType, forJson }) => {
397
410
  const decoded = cbor.decodeAllSync(Buffer.from(cborString, 'hex'), {
398
- tags: {
399
- 121: (val) => ({ [`constructor_0`]: val }),
400
- 122: (val) => ({ [`constructor_1`]: val }),
401
- 123: (val) => ({ [`constructor_2`]: val }),
402
- 124: (val) => ({ [`constructor_3`]: val }),
403
- 125: (val) => ({ [`constructor_4`]: val })
404
- }
411
+ tags: CONSTR_DECODE_TAGS
405
412
  });
406
413
  let [data] = decoded;
407
414
  data = decodeObject({ val: data, schema, defaultKeyType, forJson });