@taquito/michel-codec 12.0.2 → 12.1.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.
@@ -7,6 +7,10 @@
7
7
  // Michelson abstract syntax tree types https://tezos.gitlab.io/whitedoc/michelson.html#concrete-syntax
8
8
  const sourceReference = Symbol('source_reference');
9
9
 
10
+ /**
11
+ * @category Error
12
+ * @description Error that indicates a failure when performing the scan step when parsing Michelson
13
+ */
10
14
  class ScanError extends Error {
11
15
  constructor(src, idx, message) {
12
16
  super(message);
@@ -148,6 +152,7 @@
148
152
  Protocol["PtHangz2"] = "PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx";
149
153
  Protocol["PsiThaCa"] = "PsiThaCaT47Zboaw71QWScM8sXeMM7bbQFncK9FLqYc6EKdpjVP";
150
154
  Protocol["Psithaca2"] = "Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A";
155
+ Protocol["PtJakarta"] = "PtJakartaiDz69SfDDLXJSiuZqTSeSKRDbKVZC8MNzJnvRjvnGw";
151
156
  Protocol["ProtoALpha"] = "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK";
152
157
  })(exports.Protocol || (exports.Protocol = {}));
153
158
  const DefaultProtocol = exports.Protocol.Psithaca2;
@@ -168,8 +173,9 @@
168
173
  PtHangzHogokSuiMHemCuowEavgYTP8J5qQ9fQS793MHYFpCY3r: 11,
169
174
  PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx: 11,
170
175
  PsiThaCaT47Zboaw71QWScM8sXeMM7bbQFncK9FLqYc6EKdpjVP: 12,
171
- Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A: 13,
172
- ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 14,
176
+ Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A: 12,
177
+ PtJakartaiDz69SfDDLXJSiuZqTSeSKRDbKVZC8MNzJnvRjvnGw: 13,
178
+ ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 13,
173
179
  };
174
180
  function ProtoGreaterOfEqual(a, b) {
175
181
  return protoLevel[a] >= protoLevel[b];
@@ -178,6 +184,10 @@
178
184
  return protoLevel[a] < protoLevel[b];
179
185
  }
180
186
 
187
+ /**
188
+ * @category Error
189
+ * @description Indicates that an error has occurred preventing macros from being expanded in a plain Michelson input
190
+ */
181
191
  class MacroError extends Error {
182
192
  constructor(prim, message) {
183
193
  super(message);
@@ -725,6 +735,10 @@
725
735
  return ex;
726
736
  }
727
737
 
738
+ /**
739
+ * @category Error
740
+ * @description Error indicating a failure when parsing Micheline expressions
741
+ */
728
742
  class MichelineParseError extends Error {
729
743
  /**
730
744
  * @param token A token caused the error
@@ -736,6 +750,10 @@
736
750
  Object.setPrototypeOf(this, MichelineParseError.prototype);
737
751
  }
738
752
  }
753
+ /**
754
+ * @category Error
755
+ * @description Error that inidicates a failure when parsing Micheline JSON
756
+ */
739
757
  class JSONParseError extends Error {
740
758
  /**
741
759
  * @param node A node caused the error
@@ -1313,13 +1331,35 @@
1313
1331
  0xbef9a3f7 | 0,
1314
1332
  0xc67178f2 | 0,
1315
1333
  ];
1334
+ /**
1335
+ * @category Error
1336
+ * @description Error that indicates a failure when decoding a base58 encoding
1337
+ */
1338
+ class Base58DecodingError extends Error {
1339
+ constructor(message) {
1340
+ super(message);
1341
+ this.message = message;
1342
+ this.name = 'Base58DecodingError';
1343
+ }
1344
+ }
1345
+ /**
1346
+ * @category Error
1347
+ * @description
1348
+ */
1349
+ class InvalidMessageError extends Error {
1350
+ constructor(message) {
1351
+ super(message);
1352
+ this.message = message;
1353
+ this.name = 'InvalidMessageError';
1354
+ }
1355
+ }
1316
1356
  // https://tools.ietf.org/html/rfc6234
1317
1357
  function sha256(msg) {
1318
1358
  // pad the message
1319
1359
  const r = (msg.length + 9) % 64;
1320
1360
  const pad = r === 0 ? 0 : 64 - r;
1321
1361
  if (msg.length > 268435455) {
1322
- throw new Error(`sha256: message length is too big: ${msg.length}`);
1362
+ throw new InvalidMessageError(`SHA-256 -- message length is too big: ${msg.length}`);
1323
1363
  }
1324
1364
  const l = msg.length << 3;
1325
1365
  const buffer = [
@@ -1398,7 +1438,7 @@
1398
1438
  function byteAt(src, i) {
1399
1439
  const c = src.charCodeAt(i) - 49;
1400
1440
  if (c >= base58alphabetFwd.length || base58alphabetFwd[c] === -1) {
1401
- throw new Error(`Base58 decoding error: unexpected character at position ${i}: ${src[i]}`);
1441
+ throw new Base58DecodingError(`Unexpected character at position ${i}: ${src[i]}`);
1402
1442
  }
1403
1443
  return base58alphabetFwd[c];
1404
1444
  }
@@ -1455,7 +1495,7 @@
1455
1495
  function decodeBase58Check(src) {
1456
1496
  const buffer = decodeBase58(src);
1457
1497
  if (buffer.length < 4) {
1458
- throw new Error(`Base58Check decoding error: data is too short ${buffer.length}`);
1498
+ throw new Base58DecodingError(`Data is too short ${buffer.length}`);
1459
1499
  }
1460
1500
  const data = buffer.slice(0, buffer.length - 4);
1461
1501
  const sum = buffer.slice(buffer.length - 4);
@@ -1464,7 +1504,7 @@
1464
1504
  sum[1] !== computed[1] ||
1465
1505
  sum[2] !== computed[2] ||
1466
1506
  sum[3] !== computed[3]) {
1467
- throw new Error('Base58Check decoding error: invalid checksum');
1507
+ throw new Base58DecodingError('Invalid checksum');
1468
1508
  }
1469
1509
  return data;
1470
1510
  }
@@ -1473,6 +1513,88 @@
1473
1513
  return encodeBase58([...src, ...sum.slice(0, 4)]);
1474
1514
  }
1475
1515
 
1516
+ /**
1517
+ * @category Error
1518
+ * @description Error that indicates an invalid contract being passed or used
1519
+ */
1520
+ class InvalidContractError extends Error {
1521
+ constructor(message) {
1522
+ super(message);
1523
+ this.message = message;
1524
+ this.name = 'InvalidContractError';
1525
+ }
1526
+ }
1527
+ /**
1528
+ * @category Error
1529
+ * @description Error that indicates an invalid type expression being passed or used
1530
+ */
1531
+ class InvalidTypeExpressionError extends Error {
1532
+ constructor(message) {
1533
+ super(message);
1534
+ this.message = message;
1535
+ this.name = 'InvalidTypeExpressionError';
1536
+ }
1537
+ }
1538
+ /**
1539
+ * @category Error
1540
+ * @description Error that indicates an invalid data expression being passed or used
1541
+ */
1542
+ class InvalidDataExpressionError extends Error {
1543
+ constructor(message) {
1544
+ super(message);
1545
+ this.message = message;
1546
+ this.name = 'InvalidDataExpressionError';
1547
+ }
1548
+ }
1549
+ /**
1550
+ * @category Error
1551
+ * @description Error that indicates an invalid contract entrypoint being referenced or passed
1552
+ */
1553
+ class InvalidEntrypointError extends Error {
1554
+ constructor(entrypoint) {
1555
+ super(`Contract has no entrypoint named: '${entrypoint}'`);
1556
+ this.entrypoint = entrypoint;
1557
+ this.name = 'InvalidEntrypointError';
1558
+ }
1559
+ }
1560
+ /**
1561
+ * @category Error
1562
+ * @description Error that indicates a failure happening when trying to encode Tezos ID
1563
+ */
1564
+ class TezosIdEncodeError extends Error {
1565
+ constructor(message) {
1566
+ super(message);
1567
+ this.message = message;
1568
+ this.name = 'TezosIdEncodeError';
1569
+ }
1570
+ }
1571
+ /**
1572
+ * @category Error
1573
+ * @description Error that indicates a general error happening when trying to create a LongInteger
1574
+ */
1575
+ class LongIntegerError extends Error {
1576
+ constructor(message) {
1577
+ super(message);
1578
+ this.message = message;
1579
+ this.name = 'LongIntegerError';
1580
+ }
1581
+ }
1582
+ /**
1583
+ * @category Error
1584
+ * @description Error that indicates a failure occurring when trying to parse a hex byte
1585
+ */
1586
+ class HexParseError extends Error {
1587
+ constructor(hexByte) {
1588
+ super(`Unable to parse hex byte: ${hexByte}`);
1589
+ this.hexByte = hexByte;
1590
+ this.name = 'HexParseError';
1591
+ }
1592
+ }
1593
+
1594
+ /**
1595
+ * @category Error
1596
+ * @description Error that indicates a Michelson failure occurring
1597
+ */
1476
1598
  class MichelsonError extends Error {
1477
1599
  /**
1478
1600
  * @param val Value of a AST node caused the error
@@ -1518,7 +1640,7 @@
1518
1640
  }
1519
1641
  else {
1520
1642
  if (c < 0x30 || c > 0x39) {
1521
- throw new Error(`unexpected character in integer constant: ${arg[i]}`);
1643
+ throw new LongIntegerError(`unexpected character in integer constant: ${arg[i]}`);
1522
1644
  }
1523
1645
  this.append(c - 0x30);
1524
1646
  }
@@ -1681,7 +1803,7 @@
1681
1803
  function encodeTezosID(id, data) {
1682
1804
  const [plen, p] = tezosPrefix[id];
1683
1805
  if (data.length !== plen) {
1684
- throw new Error(`incorrect data length for ${id}: ${data.length}`);
1806
+ throw new TezosIdEncodeError(`Incorrect data length for ${id}: ${data.length}`);
1685
1807
  }
1686
1808
  return encodeBase58Check([...p, ...data]);
1687
1809
  }
@@ -1739,7 +1861,7 @@
1739
1861
  const ss = s.slice(i, i + 2);
1740
1862
  const x = parseInt(ss, 16);
1741
1863
  if (Number.isNaN(x)) {
1742
- throw new Error(`can't parse hex byte: ${ss}`);
1864
+ throw new HexParseError(ss);
1743
1865
  }
1744
1866
  res.push(x);
1745
1867
  }
@@ -5146,18 +5268,37 @@
5146
5268
  if (parseInt(s[0].args[0].int, 10) !== parseInt(s[1].args[0].int, 10)) {
5147
5269
  throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: sapling memo size mismatch: ${s[0].args[0].int} != ${s[1].args[0].int}`);
5148
5270
  }
5149
- return [
5150
- annotateVar({
5151
- prim: 'option',
5152
- args: [
5153
- {
5154
- prim: 'pair',
5155
- args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5156
- },
5157
- ],
5158
- }),
5159
- ...stack.slice(2),
5160
- ];
5271
+ return ProtoInferiorTo(proto, exports.Protocol.PtJakarta)
5272
+ ? [
5273
+ annotateVar({
5274
+ prim: 'option',
5275
+ args: [
5276
+ {
5277
+ prim: 'pair',
5278
+ args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5279
+ },
5280
+ ],
5281
+ }),
5282
+ ...stack.slice(2),
5283
+ ]
5284
+ : [
5285
+ annotateVar({
5286
+ prim: 'option',
5287
+ args: [
5288
+ {
5289
+ prim: 'pair',
5290
+ args: [
5291
+ { prim: 'bytes' },
5292
+ {
5293
+ prim: 'pair',
5294
+ args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5295
+ },
5296
+ ],
5297
+ },
5298
+ ],
5299
+ }),
5300
+ ...stack.slice(2),
5301
+ ];
5161
5302
  }
5162
5303
  case 'OPEN_CHEST':
5163
5304
  args(0, ['chest_key'], ['chest'], ['nat']);
@@ -5367,7 +5508,7 @@
5367
5508
  const p = new Parser(opt);
5368
5509
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5369
5510
  if (expr === null) {
5370
- throw new Error('empty contract');
5511
+ throw new InvalidContractError('empty contract');
5371
5512
  }
5372
5513
  if (assertMichelsonContract(expr)) {
5373
5514
  return new Contract(expr, opt);
@@ -5377,7 +5518,7 @@
5377
5518
  const p = new Parser(opt);
5378
5519
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5379
5520
  if (expr === null) {
5380
- throw new Error('empty type expression');
5521
+ throw new InvalidTypeExpressionError('empty type expression');
5381
5522
  }
5382
5523
  if (assertMichelsonType(expr) && assertTypeAnnotationsValid(expr)) {
5383
5524
  return expr;
@@ -5388,7 +5529,7 @@
5388
5529
  const p = new Parser(opt);
5389
5530
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5390
5531
  if (expr === null) {
5391
- throw new Error('empty data expression');
5532
+ throw new InvalidDataExpressionError('empty data expression');
5392
5533
  }
5393
5534
  if (assertMichelsonData(expr)) {
5394
5535
  return expr;
@@ -5413,7 +5554,7 @@
5413
5554
  assertParameterValid(ep, d) {
5414
5555
  const t = this.entryPoint(ep || undefined);
5415
5556
  if (t === null) {
5416
- throw new Error(`contract has no entrypoint named ${ep}`);
5557
+ throw new InvalidEntrypointError(ep === null || ep === void 0 ? void 0 : ep.toString());
5417
5558
  }
5418
5559
  this.assertDataValid(d, t);
5419
5560
  }
@@ -5493,8 +5634,8 @@ ${err.data
5493
5634
 
5494
5635
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5495
5636
  const VERSION = {
5496
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
5497
- "version": "12.0.2"
5637
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
5638
+ "version": "12.1.0"
5498
5639
  };
5499
5640
 
5500
5641
  exports.Contract = Contract;