@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.
@@ -1,6 +1,10 @@
1
1
  // Michelson abstract syntax tree types https://tezos.gitlab.io/whitedoc/michelson.html#concrete-syntax
2
2
  const sourceReference = Symbol('source_reference');
3
3
 
4
+ /**
5
+ * @category Error
6
+ * @description Error that indicates a failure when performing the scan step when parsing Michelson
7
+ */
4
8
  class ScanError extends Error {
5
9
  constructor(src, idx, message) {
6
10
  super(message);
@@ -142,6 +146,7 @@ var Protocol;
142
146
  Protocol["PtHangz2"] = "PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx";
143
147
  Protocol["PsiThaCa"] = "PsiThaCaT47Zboaw71QWScM8sXeMM7bbQFncK9FLqYc6EKdpjVP";
144
148
  Protocol["Psithaca2"] = "Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A";
149
+ Protocol["PtJakarta"] = "PtJakartaiDz69SfDDLXJSiuZqTSeSKRDbKVZC8MNzJnvRjvnGw";
145
150
  Protocol["ProtoALpha"] = "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK";
146
151
  })(Protocol || (Protocol = {}));
147
152
  const DefaultProtocol = Protocol.Psithaca2;
@@ -162,8 +167,9 @@ const protoLevel = {
162
167
  PtHangzHogokSuiMHemCuowEavgYTP8J5qQ9fQS793MHYFpCY3r: 11,
163
168
  PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx: 11,
164
169
  PsiThaCaT47Zboaw71QWScM8sXeMM7bbQFncK9FLqYc6EKdpjVP: 12,
165
- Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A: 13,
166
- ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 14,
170
+ Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A: 12,
171
+ PtJakartaiDz69SfDDLXJSiuZqTSeSKRDbKVZC8MNzJnvRjvnGw: 13,
172
+ ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 13,
167
173
  };
168
174
  function ProtoGreaterOfEqual(a, b) {
169
175
  return protoLevel[a] >= protoLevel[b];
@@ -172,6 +178,10 @@ function ProtoInferiorTo(a, b) {
172
178
  return protoLevel[a] < protoLevel[b];
173
179
  }
174
180
 
181
+ /**
182
+ * @category Error
183
+ * @description Indicates that an error has occurred preventing macros from being expanded in a plain Michelson input
184
+ */
175
185
  class MacroError extends Error {
176
186
  constructor(prim, message) {
177
187
  super(message);
@@ -719,6 +729,10 @@ function expandGlobalConstants(ex, hashAndValue) {
719
729
  return ex;
720
730
  }
721
731
 
732
+ /**
733
+ * @category Error
734
+ * @description Error indicating a failure when parsing Micheline expressions
735
+ */
722
736
  class MichelineParseError extends Error {
723
737
  /**
724
738
  * @param token A token caused the error
@@ -730,6 +744,10 @@ class MichelineParseError extends Error {
730
744
  Object.setPrototypeOf(this, MichelineParseError.prototype);
731
745
  }
732
746
  }
747
+ /**
748
+ * @category Error
749
+ * @description Error that inidicates a failure when parsing Micheline JSON
750
+ */
733
751
  class JSONParseError extends Error {
734
752
  /**
735
753
  * @param node A node caused the error
@@ -1307,13 +1325,35 @@ const K = [
1307
1325
  0xbef9a3f7 | 0,
1308
1326
  0xc67178f2 | 0,
1309
1327
  ];
1328
+ /**
1329
+ * @category Error
1330
+ * @description Error that indicates a failure when decoding a base58 encoding
1331
+ */
1332
+ class Base58DecodingError extends Error {
1333
+ constructor(message) {
1334
+ super(message);
1335
+ this.message = message;
1336
+ this.name = 'Base58DecodingError';
1337
+ }
1338
+ }
1339
+ /**
1340
+ * @category Error
1341
+ * @description
1342
+ */
1343
+ class InvalidMessageError extends Error {
1344
+ constructor(message) {
1345
+ super(message);
1346
+ this.message = message;
1347
+ this.name = 'InvalidMessageError';
1348
+ }
1349
+ }
1310
1350
  // https://tools.ietf.org/html/rfc6234
1311
1351
  function sha256(msg) {
1312
1352
  // pad the message
1313
1353
  const r = (msg.length + 9) % 64;
1314
1354
  const pad = r === 0 ? 0 : 64 - r;
1315
1355
  if (msg.length > 268435455) {
1316
- throw new Error(`sha256: message length is too big: ${msg.length}`);
1356
+ throw new InvalidMessageError(`SHA-256 -- message length is too big: ${msg.length}`);
1317
1357
  }
1318
1358
  const l = msg.length << 3;
1319
1359
  const buffer = [
@@ -1392,7 +1432,7 @@ const base58alphabetBwd = [
1392
1432
  function byteAt(src, i) {
1393
1433
  const c = src.charCodeAt(i) - 49;
1394
1434
  if (c >= base58alphabetFwd.length || base58alphabetFwd[c] === -1) {
1395
- throw new Error(`Base58 decoding error: unexpected character at position ${i}: ${src[i]}`);
1435
+ throw new Base58DecodingError(`Unexpected character at position ${i}: ${src[i]}`);
1396
1436
  }
1397
1437
  return base58alphabetFwd[c];
1398
1438
  }
@@ -1449,7 +1489,7 @@ function encodeBase58(src) {
1449
1489
  function decodeBase58Check(src) {
1450
1490
  const buffer = decodeBase58(src);
1451
1491
  if (buffer.length < 4) {
1452
- throw new Error(`Base58Check decoding error: data is too short ${buffer.length}`);
1492
+ throw new Base58DecodingError(`Data is too short ${buffer.length}`);
1453
1493
  }
1454
1494
  const data = buffer.slice(0, buffer.length - 4);
1455
1495
  const sum = buffer.slice(buffer.length - 4);
@@ -1458,7 +1498,7 @@ function decodeBase58Check(src) {
1458
1498
  sum[1] !== computed[1] ||
1459
1499
  sum[2] !== computed[2] ||
1460
1500
  sum[3] !== computed[3]) {
1461
- throw new Error('Base58Check decoding error: invalid checksum');
1501
+ throw new Base58DecodingError('Invalid checksum');
1462
1502
  }
1463
1503
  return data;
1464
1504
  }
@@ -1467,6 +1507,88 @@ function encodeBase58Check(src) {
1467
1507
  return encodeBase58([...src, ...sum.slice(0, 4)]);
1468
1508
  }
1469
1509
 
1510
+ /**
1511
+ * @category Error
1512
+ * @description Error that indicates an invalid contract being passed or used
1513
+ */
1514
+ class InvalidContractError extends Error {
1515
+ constructor(message) {
1516
+ super(message);
1517
+ this.message = message;
1518
+ this.name = 'InvalidContractError';
1519
+ }
1520
+ }
1521
+ /**
1522
+ * @category Error
1523
+ * @description Error that indicates an invalid type expression being passed or used
1524
+ */
1525
+ class InvalidTypeExpressionError extends Error {
1526
+ constructor(message) {
1527
+ super(message);
1528
+ this.message = message;
1529
+ this.name = 'InvalidTypeExpressionError';
1530
+ }
1531
+ }
1532
+ /**
1533
+ * @category Error
1534
+ * @description Error that indicates an invalid data expression being passed or used
1535
+ */
1536
+ class InvalidDataExpressionError extends Error {
1537
+ constructor(message) {
1538
+ super(message);
1539
+ this.message = message;
1540
+ this.name = 'InvalidDataExpressionError';
1541
+ }
1542
+ }
1543
+ /**
1544
+ * @category Error
1545
+ * @description Error that indicates an invalid contract entrypoint being referenced or passed
1546
+ */
1547
+ class InvalidEntrypointError extends Error {
1548
+ constructor(entrypoint) {
1549
+ super(`Contract has no entrypoint named: '${entrypoint}'`);
1550
+ this.entrypoint = entrypoint;
1551
+ this.name = 'InvalidEntrypointError';
1552
+ }
1553
+ }
1554
+ /**
1555
+ * @category Error
1556
+ * @description Error that indicates a failure happening when trying to encode Tezos ID
1557
+ */
1558
+ class TezosIdEncodeError extends Error {
1559
+ constructor(message) {
1560
+ super(message);
1561
+ this.message = message;
1562
+ this.name = 'TezosIdEncodeError';
1563
+ }
1564
+ }
1565
+ /**
1566
+ * @category Error
1567
+ * @description Error that indicates a general error happening when trying to create a LongInteger
1568
+ */
1569
+ class LongIntegerError extends Error {
1570
+ constructor(message) {
1571
+ super(message);
1572
+ this.message = message;
1573
+ this.name = 'LongIntegerError';
1574
+ }
1575
+ }
1576
+ /**
1577
+ * @category Error
1578
+ * @description Error that indicates a failure occurring when trying to parse a hex byte
1579
+ */
1580
+ class HexParseError extends Error {
1581
+ constructor(hexByte) {
1582
+ super(`Unable to parse hex byte: ${hexByte}`);
1583
+ this.hexByte = hexByte;
1584
+ this.name = 'HexParseError';
1585
+ }
1586
+ }
1587
+
1588
+ /**
1589
+ * @category Error
1590
+ * @description Error that indicates a Michelson failure occurring
1591
+ */
1470
1592
  class MichelsonError extends Error {
1471
1593
  /**
1472
1594
  * @param val Value of a AST node caused the error
@@ -1512,7 +1634,7 @@ class LongInteger {
1512
1634
  }
1513
1635
  else {
1514
1636
  if (c < 0x30 || c > 0x39) {
1515
- throw new Error(`unexpected character in integer constant: ${arg[i]}`);
1637
+ throw new LongIntegerError(`unexpected character in integer constant: ${arg[i]}`);
1516
1638
  }
1517
1639
  this.append(c - 0x30);
1518
1640
  }
@@ -1675,7 +1797,7 @@ function checkDecodeTezosID(id, ...types) {
1675
1797
  function encodeTezosID(id, data) {
1676
1798
  const [plen, p] = tezosPrefix[id];
1677
1799
  if (data.length !== plen) {
1678
- throw new Error(`incorrect data length for ${id}: ${data.length}`);
1800
+ throw new TezosIdEncodeError(`Incorrect data length for ${id}: ${data.length}`);
1679
1801
  }
1680
1802
  return encodeBase58Check([...p, ...data]);
1681
1803
  }
@@ -1733,7 +1855,7 @@ function parseHex(s) {
1733
1855
  const ss = s.slice(i, i + 2);
1734
1856
  const x = parseInt(ss, 16);
1735
1857
  if (Number.isNaN(x)) {
1736
- throw new Error(`can't parse hex byte: ${ss}`);
1858
+ throw new HexParseError(ss);
1737
1859
  }
1738
1860
  res.push(x);
1739
1861
  }
@@ -5140,18 +5262,37 @@ function functionTypeInternal(inst, stack, ctx) {
5140
5262
  if (parseInt(s[0].args[0].int, 10) !== parseInt(s[1].args[0].int, 10)) {
5141
5263
  throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: sapling memo size mismatch: ${s[0].args[0].int} != ${s[1].args[0].int}`);
5142
5264
  }
5143
- return [
5144
- annotateVar({
5145
- prim: 'option',
5146
- args: [
5147
- {
5148
- prim: 'pair',
5149
- args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5150
- },
5151
- ],
5152
- }),
5153
- ...stack.slice(2),
5154
- ];
5265
+ return ProtoInferiorTo(proto, Protocol.PtJakarta)
5266
+ ? [
5267
+ annotateVar({
5268
+ prim: 'option',
5269
+ args: [
5270
+ {
5271
+ prim: 'pair',
5272
+ args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5273
+ },
5274
+ ],
5275
+ }),
5276
+ ...stack.slice(2),
5277
+ ]
5278
+ : [
5279
+ annotateVar({
5280
+ prim: 'option',
5281
+ args: [
5282
+ {
5283
+ prim: 'pair',
5284
+ args: [
5285
+ { prim: 'bytes' },
5286
+ {
5287
+ prim: 'pair',
5288
+ args: [{ prim: 'int' }, annotate(s[1], { t: null })],
5289
+ },
5290
+ ],
5291
+ },
5292
+ ],
5293
+ }),
5294
+ ...stack.slice(2),
5295
+ ];
5155
5296
  }
5156
5297
  case 'OPEN_CHEST':
5157
5298
  args(0, ['chest_key'], ['chest'], ['nat']);
@@ -5361,7 +5502,7 @@ class Contract {
5361
5502
  const p = new Parser(opt);
5362
5503
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5363
5504
  if (expr === null) {
5364
- throw new Error('empty contract');
5505
+ throw new InvalidContractError('empty contract');
5365
5506
  }
5366
5507
  if (assertMichelsonContract(expr)) {
5367
5508
  return new Contract(expr, opt);
@@ -5371,7 +5512,7 @@ class Contract {
5371
5512
  const p = new Parser(opt);
5372
5513
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5373
5514
  if (expr === null) {
5374
- throw new Error('empty type expression');
5515
+ throw new InvalidTypeExpressionError('empty type expression');
5375
5516
  }
5376
5517
  if (assertMichelsonType(expr) && assertTypeAnnotationsValid(expr)) {
5377
5518
  return expr;
@@ -5382,7 +5523,7 @@ class Contract {
5382
5523
  const p = new Parser(opt);
5383
5524
  const expr = typeof src === 'string' ? p.parseScript(src) : p.parseJSON(src);
5384
5525
  if (expr === null) {
5385
- throw new Error('empty data expression');
5526
+ throw new InvalidDataExpressionError('empty data expression');
5386
5527
  }
5387
5528
  if (assertMichelsonData(expr)) {
5388
5529
  return expr;
@@ -5407,7 +5548,7 @@ class Contract {
5407
5548
  assertParameterValid(ep, d) {
5408
5549
  const t = this.entryPoint(ep || undefined);
5409
5550
  if (t === null) {
5410
- throw new Error(`contract has no entrypoint named ${ep}`);
5551
+ throw new InvalidEntrypointError(ep === null || ep === void 0 ? void 0 : ep.toString());
5411
5552
  }
5412
5553
  this.assertDataValid(d, t);
5413
5554
  }
@@ -5487,8 +5628,8 @@ ${err.data
5487
5628
 
5488
5629
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5489
5630
  const VERSION = {
5490
- "commitHash": "5996bf6b665e26de3201cf45884b4a2bb9218e09",
5491
- "version": "12.0.2"
5631
+ "commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
5632
+ "version": "12.1.0"
5492
5633
  };
5493
5634
 
5494
5635
  export { Contract, DefaultProtocol, JSONParseError, MacroError, MichelineParseError, MichelsonError, MichelsonInstructionError, MichelsonTypeError, MichelsonValidationError, Parser, ProtoGreaterOfEqual, ProtoInferiorTo, Protocol, VERSION, assertContractValid, assertDataListIfAny, assertDataValid, assertMichelsonBigMapStorableType, assertMichelsonComparableType, assertMichelsonContract, assertMichelsonData, assertMichelsonInstruction, assertMichelsonPackableType, assertMichelsonPassableType, assertMichelsonPushableType, assertMichelsonStorableType, assertMichelsonType, assertTypeAnnotationsValid, assertTypesEqual, assertViewNameValid, contractEntryPoint, contractEntryPoints, contractSection, contractViews, decodeAddressBytes, decodePublicKeyBytes, decodePublicKeyHashBytes, dummyContract, emitMicheline, formatError, formatStack, functionType, instructionIDs, isContractValid, isDataValid, isInstruction, isMichelsonCode, isMichelsonData, isMichelsonError, isMichelsonScript, isMichelsonType, isTypeAnnotationsValid, isTypeEqual, packData, packDataBytes, refContract, sourceReference, traceDumpFunc, unpackData, unpackDataBytes };