@suigar/sdk 2.0.0-beta.11 → 2.0.0-beta.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @suigar/sdk
2
2
 
3
+ ## 2.0.0-beta.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 85ae057: Refine public validation failures to use `RangeError` and `TypeError` instead
8
+ of generic `Error` for unsupported networks, unsupported game or PvP action
9
+ inputs, unsupported configured coin types, bounded integer helpers, and
10
+ `parseCoinType()` parsing failures.
11
+
3
12
  ## 2.0.0-beta.11
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -56,14 +56,21 @@ Numeric helper behavior:
56
56
 
57
57
  - `toBigInt(value)` accepts `bigint`, finite `number`, non-negative integer
58
58
  `string`, and `boolean` inputs and returns a normalized non-negative `bigint`
59
+ while throwing `TypeError` for invalid input shapes and `RangeError` for
60
+ negative values
59
61
  - `toU8(value)` accepts a finite integer `number` or plain integer `string` in
60
- the inclusive `0..255` range and rejects booleans or fractional values
62
+ the inclusive `0..255` range, throwing `TypeError` for non-numeric input and
63
+ `RangeError` for booleans, fractional values, or out-of-range integers
61
64
  - `toU16(value)` accepts a finite integer `number` or plain integer `string`
62
- in the inclusive `0..65535` range and rejects booleans or fractional values
65
+ in the inclusive `0..65535` range, throwing `TypeError` for non-numeric
66
+ input and `RangeError` for booleans, fractional values, or out-of-range
67
+ integers
63
68
  - `fromMoveI64(value)` converts a generated Move `i64` wrapper into a
64
69
  JavaScript `number`
65
70
  - `fromMoveFloat(value)` converts a generated Move float struct into a
66
71
  JavaScript `number`
72
+ - `parseCoinType(type)` extracts the normalized first generic coin type from a
73
+ Move object type string and throws `TypeError` when no coin type can be parsed
67
74
  - `parseGameDetails(gameDetails)` decodes standard `BetResultEvent.game_details`
68
75
  byte arrays into the expected string, number, and boolean values while
69
76
  preserving the original onchain keys
@@ -122,6 +129,9 @@ const base64 = await client.suigar.serializeTransactionToBase64(tx);
122
129
 
123
130
  Creates a named Sui client extension. By default, it registers under `client.suigar`.
124
131
 
132
+ The extension constructor throws `RangeError` when the connected client network
133
+ is not one of the SDK's supported Sui networks.
134
+
125
135
  ### Partner Setup
126
136
 
127
137
  > **Important:** `partner` is the partner wallet address. Configure it once
@@ -321,6 +331,12 @@ Shared behavior:
321
331
  - the SDK resolves the price info object from the configured supported-coin mapping
322
332
  - the reward object is transferred back to `playerAddress`
323
333
 
334
+ Error behavior:
335
+
336
+ - `RangeError` when `gameId` is unsupported
337
+ - `RangeError` when `coinType` is not in the resolved supported-coin config for the active network
338
+ - `RangeError` from bounded numeric helpers such as `toU8()` when `plinko` or `wheel` `configId` is out of range or not an integer
339
+
324
340
  Per-game options:
325
341
 
326
342
  - `coinflip`: `side: 'heads' | 'tails'`
@@ -420,6 +436,11 @@ Action-specific options:
420
436
  - `join`: `gameId`
421
437
  - `cancel`: `gameId`
422
438
 
439
+ Error behavior:
440
+
441
+ - `RangeError` when `action` is unsupported
442
+ - `RangeError` when `coinType` is not in the resolved supported-coin config for the active network
443
+
423
444
  ## `bcs`
424
445
 
425
446
  BCS helpers live under `client.suigar.bcs`.
@@ -438,6 +459,7 @@ These are generated Move event decoders. Use them to parse Suigar event payloads
438
459
  - `fromMoveI64(float.exp)` converts a generated Move `i64` exponent to a JavaScript number
439
460
  - `fromMoveFloat(float)` converts a generated Move `Float` struct to a JavaScript number
440
461
  - `parseCoinType(type)` extracts the normalized coin type from generic Move object type strings such as PvP coinflip `Game<T>`
462
+ and throws `TypeError` when the type string does not include a first generic coin type
441
463
  - `parseGameDetails(game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
442
464
 
443
465
  ### Parse PvP Coinflip Game Object Data
@@ -40,7 +40,9 @@ function toBoundedInt(value, max, typeName) {
40
40
  const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
41
41
  assertFiniteNumber(num, "Value must be a finite number or integer string");
42
42
  if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
43
- throw new Error(`Value must be a ${typeName} integer (0-${max}): ${value}`);
43
+ throw new RangeError(
44
+ `Value must be a ${typeName} integer (0-${max}): ${value}`
45
+ );
44
46
  }
45
47
  return num;
46
48
  }
@@ -302,7 +304,7 @@ function fromMoveFloat(float) {
302
304
  function parseCoinType(type) {
303
305
  const coinType = parseStructTag(type).typeParams[0];
304
306
  if (!coinType) {
305
- throw new Error(`Unable to parse coin type from ${type}`);
307
+ throw new TypeError(`Unable to parse coin type from ${type}`);
306
308
  }
307
309
  return normalizeStructTag(coinType);
308
310
  }
package/dist/index.cjs CHANGED
@@ -485,7 +485,7 @@ function resolvePriceInfoObjectId(config, coinType) {
485
485
  function resolveSupportedCoin(config, coinType) {
486
486
  const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
487
487
  if (!supportedCoin) {
488
- throw new Error(
488
+ throw new RangeError(
489
489
  `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
490
490
  config.coinTypes
491
491
  ).join(", ")}`
@@ -627,7 +627,9 @@ function toBoundedInt(value, max, typeName) {
627
627
  const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
628
628
  assertFiniteNumber(num, "Value must be a finite number or integer string");
629
629
  if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
630
- throw new Error(`Value must be a ${typeName} integer (0-${max}): ${value}`);
630
+ throw new RangeError(
631
+ `Value must be a ${typeName} integer (0-${max}): ${value}`
632
+ );
631
633
  }
632
634
  return num;
633
635
  }
@@ -652,7 +654,7 @@ new TextDecoder();
652
654
  function parseCoinType(type) {
653
655
  const coinType = utils.parseStructTag(type).typeParams[0];
654
656
  if (!coinType) {
655
- throw new Error(`Unable to parse coin type from ${type}`);
657
+ throw new TypeError(`Unable to parse coin type from ${type}`);
656
658
  }
657
659
  return utils.normalizeStructTag(coinType);
658
660
  }
@@ -1036,7 +1038,7 @@ function buildPvPCoinflipTransaction(action, options) {
1036
1038
  return tx;
1037
1039
  }
1038
1040
  default:
1039
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
1041
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1040
1042
  }
1041
1043
  }
1042
1044
  var $moduleName18 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
@@ -1402,7 +1404,7 @@ var SuigarClient = class {
1402
1404
  });
1403
1405
  const network = this.#client.network;
1404
1406
  if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1405
- throw new Error(`Unsupported network: ${network}`);
1407
+ throw new RangeError(`Unsupported network: ${network}`);
1406
1408
  }
1407
1409
  this.#config = resolveSuigarConfig(network);
1408
1410
  }
@@ -1520,41 +1522,6 @@ var SuigarClient = class {
1520
1522
  (game) => game instanceof Error ? [] : [game]
1521
1523
  );
1522
1524
  }
1523
- async #fetchGameParameters(game, coinType, signal) {
1524
- const gameDefinition = GAME_SETTINGS[game];
1525
- const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
1526
- parentId: this.#config.packageIds.sweetHouse,
1527
- name: {
1528
- type: resolveGameSettingsKeyType(
1529
- gameDefinition.settingsKey.name,
1530
- resolveGamePackageId(this.#config, game)
1531
- ),
1532
- bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
1533
- },
1534
- signal
1535
- });
1536
- const { object } = await this.#client.core.getDynamicObjectField({
1537
- parentId: settingsObject.objectId,
1538
- name: {
1539
- type: TypeName.name,
1540
- bcs: TypeName.serialize({
1541
- name: resolveCoinTypeNameForTypeNameKey(coinType)
1542
- }).toBytes()
1543
- },
1544
- include: {
1545
- content: true
1546
- },
1547
- signal
1548
- });
1549
- if (!object?.content) {
1550
- throw new Error(
1551
- `Missing parameters object content for ${game} and coin type ${coinType}`
1552
- );
1553
- }
1554
- return gameDefinition.parameters.parse(
1555
- object.content
1556
- );
1557
- }
1558
1525
  /**
1559
1526
  * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
1560
1527
  *
@@ -1633,7 +1600,7 @@ var SuigarClient = class {
1633
1600
  partner: this.#partner
1634
1601
  });
1635
1602
  default:
1636
- throw new Error(`Unsupported game: ${gameId}`);
1603
+ throw new RangeError(`Unsupported game: ${gameId}`);
1637
1604
  }
1638
1605
  },
1639
1606
  /**
@@ -1667,7 +1634,7 @@ var SuigarClient = class {
1667
1634
  partner: this.#partner
1668
1635
  });
1669
1636
  default:
1670
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
1637
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1671
1638
  }
1672
1639
  }
1673
1640
  };
@@ -1684,6 +1651,41 @@ var SuigarClient = class {
1684
1651
  });
1685
1652
  };
1686
1653
  }
1654
+ async #fetchGameParameters(game, coinType, signal) {
1655
+ const gameDefinition = GAME_SETTINGS[game];
1656
+ const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
1657
+ parentId: this.#config.packageIds.sweetHouse,
1658
+ name: {
1659
+ type: resolveGameSettingsKeyType(
1660
+ gameDefinition.settingsKey.name,
1661
+ resolveGamePackageId(this.#config, game)
1662
+ ),
1663
+ bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
1664
+ },
1665
+ signal
1666
+ });
1667
+ const { object } = await this.#client.core.getDynamicObjectField({
1668
+ parentId: settingsObject.objectId,
1669
+ name: {
1670
+ type: TypeName.name,
1671
+ bcs: TypeName.serialize({
1672
+ name: resolveCoinTypeNameForTypeNameKey(coinType)
1673
+ }).toBytes()
1674
+ },
1675
+ include: {
1676
+ content: true
1677
+ },
1678
+ signal
1679
+ });
1680
+ if (!object?.content) {
1681
+ throw new Error(
1682
+ `Missing parameters object content for ${game} and coin type ${coinType}`
1683
+ );
1684
+ }
1685
+ return gameDefinition.parameters.parse(
1686
+ object.content
1687
+ );
1688
+ }
1687
1689
  };
1688
1690
 
1689
1691
  exports.SuigarClient = SuigarClient;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MoveStruct, Float, parseCoinType, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-TBJ5TYYE.js';
1
+ import { MoveStruct, Float, parseCoinType, toBigInt, toU8, DEFAULT_GAS_BUDGET_MIST, normalizeMoveArguments, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE } from './chunk-7N55D2TV.js';
2
2
  import { toBase64, normalizeStructTag, parseStructTag, normalizeSuiAddress, fromHex } from '@mysten/sui/utils';
3
3
  import { bcs } from '@mysten/sui/bcs';
4
4
  import { Transaction } from '@mysten/sui/transactions';
@@ -325,7 +325,7 @@ function resolvePriceInfoObjectId(config, coinType) {
325
325
  function resolveSupportedCoin(config, coinType) {
326
326
  const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
327
327
  if (!supportedCoin) {
328
- throw new Error(
328
+ throw new RangeError(
329
329
  `Unsupported coin type ${coinType}. Supported coin types: ${Object.values(
330
330
  config.coinTypes
331
331
  ).join(", ")}`
@@ -817,7 +817,7 @@ function buildPvPCoinflipTransaction(action, options) {
817
817
  return tx;
818
818
  }
819
819
  default:
820
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
820
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
821
821
  }
822
822
  }
823
823
  var $moduleName16 = "0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64";
@@ -1183,7 +1183,7 @@ var SuigarClient = class {
1183
1183
  });
1184
1184
  const network = this.#client.network;
1185
1185
  if (!SUPPORTED_SUI_NETWORKS.includes(network)) {
1186
- throw new Error(`Unsupported network: ${network}`);
1186
+ throw new RangeError(`Unsupported network: ${network}`);
1187
1187
  }
1188
1188
  this.#config = resolveSuigarConfig(network);
1189
1189
  }
@@ -1301,41 +1301,6 @@ var SuigarClient = class {
1301
1301
  (game) => game instanceof Error ? [] : [game]
1302
1302
  );
1303
1303
  }
1304
- async #fetchGameParameters(game, coinType, signal) {
1305
- const gameDefinition = GAME_SETTINGS[game];
1306
- const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
1307
- parentId: this.#config.packageIds.sweetHouse,
1308
- name: {
1309
- type: resolveGameSettingsKeyType(
1310
- gameDefinition.settingsKey.name,
1311
- resolveGamePackageId(this.#config, game)
1312
- ),
1313
- bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
1314
- },
1315
- signal
1316
- });
1317
- const { object } = await this.#client.core.getDynamicObjectField({
1318
- parentId: settingsObject.objectId,
1319
- name: {
1320
- type: TypeName.name,
1321
- bcs: TypeName.serialize({
1322
- name: resolveCoinTypeNameForTypeNameKey(coinType)
1323
- }).toBytes()
1324
- },
1325
- include: {
1326
- content: true
1327
- },
1328
- signal
1329
- });
1330
- if (!object?.content) {
1331
- throw new Error(
1332
- `Missing parameters object content for ${game} and coin type ${coinType}`
1333
- );
1334
- }
1335
- return gameDefinition.parameters.parse(
1336
- object.content
1337
- );
1338
- }
1339
1304
  /**
1340
1305
  * BCS struct constructors for decoding on-chain objects and events related to Suigar games.
1341
1306
  *
@@ -1414,7 +1379,7 @@ var SuigarClient = class {
1414
1379
  partner: this.#partner
1415
1380
  });
1416
1381
  default:
1417
- throw new Error(`Unsupported game: ${gameId}`);
1382
+ throw new RangeError(`Unsupported game: ${gameId}`);
1418
1383
  }
1419
1384
  },
1420
1385
  /**
@@ -1448,7 +1413,7 @@ var SuigarClient = class {
1448
1413
  partner: this.#partner
1449
1414
  });
1450
1415
  default:
1451
- throw new Error(`Unsupported PvP coinflip action: ${action}`);
1416
+ throw new RangeError(`Unsupported PvP coinflip action: ${action}`);
1452
1417
  }
1453
1418
  }
1454
1419
  };
@@ -1465,6 +1430,41 @@ var SuigarClient = class {
1465
1430
  });
1466
1431
  };
1467
1432
  }
1433
+ async #fetchGameParameters(game, coinType, signal) {
1434
+ const gameDefinition = GAME_SETTINGS[game];
1435
+ const { object: settingsObject } = await this.#client.core.getDynamicObjectField({
1436
+ parentId: this.#config.packageIds.sweetHouse,
1437
+ name: {
1438
+ type: resolveGameSettingsKeyType(
1439
+ gameDefinition.settingsKey.name,
1440
+ resolveGamePackageId(this.#config, game)
1441
+ ),
1442
+ bcs: gameDefinition.settingsKey.serialize({ dummy_field: false }).toBytes()
1443
+ },
1444
+ signal
1445
+ });
1446
+ const { object } = await this.#client.core.getDynamicObjectField({
1447
+ parentId: settingsObject.objectId,
1448
+ name: {
1449
+ type: TypeName.name,
1450
+ bcs: TypeName.serialize({
1451
+ name: resolveCoinTypeNameForTypeNameKey(coinType)
1452
+ }).toBytes()
1453
+ },
1454
+ include: {
1455
+ content: true
1456
+ },
1457
+ signal
1458
+ });
1459
+ if (!object?.content) {
1460
+ throw new Error(
1461
+ `Missing parameters object content for ${game} and coin type ${coinType}`
1462
+ );
1463
+ }
1464
+ return gameDefinition.parameters.parse(
1465
+ object.content
1466
+ );
1467
+ }
1468
1468
  };
1469
1469
 
1470
1470
  export { SuigarClient, suigar };
package/dist/utils.cjs CHANGED
@@ -42,7 +42,9 @@ function toBoundedInt(value, max, typeName) {
42
42
  const num = typeof value === "string" && value.trim() === "" ? NaN : Number(value);
43
43
  assertFiniteNumber(num, "Value must be a finite number or integer string");
44
44
  if (typeof value === "boolean" || value == null || !Number.isInteger(num) || num < 0 || num > max) {
45
- throw new Error(`Value must be a ${typeName} integer (0-${max}): ${value}`);
45
+ throw new RangeError(
46
+ `Value must be a ${typeName} integer (0-${max}): ${value}`
47
+ );
46
48
  }
47
49
  return num;
48
50
  }
@@ -192,7 +194,7 @@ function fromMoveFloat(float) {
192
194
  function parseCoinType(type) {
193
195
  const coinType = utils.parseStructTag(type).typeParams[0];
194
196
  if (!coinType) {
195
- throw new Error(`Unable to parse coin type from ${type}`);
197
+ throw new TypeError(`Unable to parse coin type from ${type}`);
196
198
  }
197
199
  return utils.normalizeStructTag(coinType);
198
200
  }
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 } from './chunk-TBJ5TYYE.js';
1
+ export { DEFAULT_GAS_BUDGET_MIST, DEFAULT_LIMBO_MULTIPLIER_SCALE, DEFAULT_RANGE_SCALE, RANGE_POINT_LIMIT, fromMoveFloat, fromMoveI64, parseCoinType, parseGameDetails, toBigInt, toU16, toU8 } from './chunk-7N55D2TV.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suigar/sdk",
3
- "version": "2.0.0-beta.11",
3
+ "version": "2.0.0-beta.12",
4
4
  "description": "TypeScript SDK for Suigar v2 Move contracts on Sui.",
5
5
  "keywords": [
6
6
  "suigar",