@koralabs/kora-labs-common 5.1.3 → 5.1.4

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.
Files changed (2) hide show
  1. package/handles/utils.js +12 -10
  2. package/package.json +1 -1
package/handles/utils.js CHANGED
@@ -25,8 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.buildDrep = exports.checkHandlePattern = exports.buildMetadata = exports.buildNumericModifiers = exports.buildCharacters = exports.getRarity = void 0;
27
27
  const crypto = __importStar(require("crypto"));
28
+ const constants_1 = require("../constants");
28
29
  const utils_1 = require("../utils");
29
- const constants_1 = require("./constants");
30
+ const constants_2 = require("./constants");
30
31
  const interfaces_1 = require("./interfaces");
31
32
  const getRarity = (name) => {
32
33
  const length = name.length;
@@ -105,18 +106,18 @@ const checkHandlePattern = (handle, root) => {
105
106
  if (handle.length <= 1) {
106
107
  return {
107
108
  valid: false,
108
- message: constants_1.RESPONSE_UNAVAILABLE_LEGENDARY
109
+ message: constants_2.RESPONSE_UNAVAILABLE_LEGENDARY
109
110
  };
110
111
  }
111
- if (!handle.match(constants_1.REGEX_SUB_HANDLE) && (root ? handle.endsWith(`@${root}`) : true)) {
112
+ if (!handle.match(constants_2.REGEX_SUB_HANDLE) && (root ? handle.endsWith(`@${root}`) : true)) {
112
113
  return {
113
114
  valid: false,
114
- message: constants_1.RESPONSE_INVALID_HANDLE_FORMAT
115
+ message: constants_2.RESPONSE_INVALID_HANDLE_FORMAT
115
116
  };
116
117
  }
117
118
  return {
118
119
  valid: true,
119
- message: constants_1.RESPONSE_AVAILABLE
120
+ message: constants_2.RESPONSE_AVAILABLE
120
121
  };
121
122
  };
122
123
  exports.checkHandlePattern = checkHandlePattern;
@@ -124,20 +125,21 @@ const buildDrep = (address, id_hash) => {
124
125
  var _a;
125
126
  if (!id_hash)
126
127
  return undefined;
127
- const decoded = (_a = (0, utils_1.decodeAddress)(address)) === null || _a === void 0 ? void 0 : _a.slice(1);
128
+ const decoded = (_a = (0, utils_1.decodeAddress)(address)) === null || _a === void 0 ? void 0 : _a.slice(2, 58);
128
129
  if (!decoded || decoded == '')
129
130
  return undefined;
130
131
  const hashed = crypto.createHash('md5').update(Buffer.from(decoded, 'hex')).digest('hex');
131
132
  if (!id_hash.startsWith(hashed))
132
133
  return undefined;
133
- const typeByte = id_hash.slice(16, 1);
134
+ const typeByte = id_hash.slice(32, 34);
134
135
  const typeByteDec = parseInt(typeByte, 16);
136
+ const prefix = (typeByteDec & 32) !== 0 ? 'drep' : (typeByteDec & 16) !== 0 ? 'cc_cold' : 'cc_hot';
135
137
  return {
136
- type: (typeByteDec & 32) !== 0 ? 'drep' : (typeByteDec & 16) !== 0 ? 'cc_cold' : 'cc_hot',
138
+ type: prefix,
137
139
  cred: (typeByteDec & 1) !== 0 ? 'script' : 'key',
138
140
  hex: decoded,
139
- cip_105: (0, utils_1.bech32FromHex)(decoded),
140
- cip_129: (0, utils_1.bech32FromHex)(typeByte + decoded)
141
+ cip_105: (0, utils_1.bech32FromHex)(decoded, constants_1.IS_PRODUCTION, prefix),
142
+ cip_129: (0, utils_1.bech32FromHex)(typeByte + decoded, constants_1.IS_PRODUCTION, prefix)
141
143
  };
142
144
  };
143
145
  exports.buildDrep = buildDrep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",