@mysten-incubation/suipay-buyer 0.3.0-dev.11 → 0.3.0-dev.13

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/dist/index.js +84 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -339,7 +339,7 @@ function readIntent(body) {
339
339
  // ../sdk/dist/buyer/verify-owner-transaction.js
340
340
  import { TransactionDataBuilder } from "@mysten/sui/transactions";
341
341
  import { bcs } from "@mysten/sui/bcs";
342
- import { fromBase64, normalizeStructTag as normalizeStructTag2, normalizeSuiAddress } from "@mysten/sui/utils";
342
+ import { fromBase64, normalizeStructTag as normalizeStructTag4, normalizeSuiAddress } from "@mysten/sui/utils";
343
343
 
344
344
  // ../core/dist/assets/testnet.js
345
345
  import { normalizeStructTag } from "@mysten/sui/utils";
@@ -384,6 +384,68 @@ function tryNormalizeStructTag(coinType) {
384
384
  }
385
385
  }
386
386
 
387
+ // ../core/dist/assets/localnet.js
388
+ import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui/utils";
389
+ var LOCALNET_SUI_COIN_TYPE = TESTNET_SUI_COIN_TYPE;
390
+ var LOCALNET_SUI_DECIMALS = TESTNET_SUI_DECIMALS;
391
+ var LOCALNET_USDC_DECIMALS = 6;
392
+ function localnetAssets(usdcCoinType) {
393
+ const assets = [
394
+ {
395
+ id: "sui",
396
+ symbol: "SUI",
397
+ coinType: LOCALNET_SUI_COIN_TYPE,
398
+ decimals: LOCALNET_SUI_DECIMALS,
399
+ network: "sui:localnet"
400
+ }
401
+ ];
402
+ const usdc = usdcCoinType?.trim();
403
+ if (usdc) {
404
+ try {
405
+ normalizeStructTag2(usdc);
406
+ } catch {
407
+ throw new Error(`localnet USDC coin type is not a valid coin type: ${usdc} (check SUIPAY_COIN_TYPE)`);
408
+ }
409
+ assets.push({
410
+ id: "usdc",
411
+ symbol: "USDC",
412
+ coinType: usdc,
413
+ decimals: LOCALNET_USDC_DECIMALS,
414
+ network: "sui:localnet"
415
+ });
416
+ }
417
+ return assets;
418
+ }
419
+
420
+ // ../core/dist/assets/index.js
421
+ import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
422
+ function normalizeNetwork(network) {
423
+ const n = (network ?? "").trim();
424
+ return n === "sui:localnet" || n === "localnet" ? "sui:localnet" : "sui:testnet";
425
+ }
426
+ function assetsForNetwork(network, options) {
427
+ return normalizeNetwork(network) === "sui:localnet" ? localnetAssets(options?.usdcCoinType) : TESTNET_ASSETS;
428
+ }
429
+ function supportedAssetByCoinTypeForNetwork(coinType, network, options) {
430
+ if (normalizeNetwork(network) === "sui:testnet") {
431
+ return supportedAssetByCoinType(coinType);
432
+ }
433
+ const trimmed = coinType.trim();
434
+ if (!trimmed)
435
+ return null;
436
+ let target;
437
+ try {
438
+ target = normalizeStructTag3(trimmed);
439
+ } catch {
440
+ return null;
441
+ }
442
+ for (const asset of localnetAssets(options?.usdcCoinType)) {
443
+ if (normalizeStructTag3(asset.coinType) === target)
444
+ return asset;
445
+ }
446
+ return null;
447
+ }
448
+
387
449
  // ../sdk/dist/sponsor/kind-gas-coin.js
388
450
  function kindTouchesGasCoin(commands) {
389
451
  return commands.some(namesGasCoin);
@@ -422,7 +484,7 @@ function safeNormalizeAddress(address) {
422
484
  }
423
485
  function safeNormalizeStructTag(tag) {
424
486
  try {
425
- return normalizeStructTag2(tag);
487
+ return normalizeStructTag4(tag);
426
488
  } catch {
427
489
  }
428
490
  return null;
@@ -518,9 +580,12 @@ function verifyOwnerTransaction(input) {
518
580
  throw new TransactionVerificationError("unsupportedOperation");
519
581
  }
520
582
  }
583
+ const networkAssets = assetsForNetwork(input.assetNetwork, {
584
+ usdcCoinType: input.localnetUsdcCoinType
585
+ });
521
586
  const knownCoinPackages = /* @__PURE__ */ new Set([
522
587
  FRAMEWORK_PACKAGE_ID,
523
- ...TESTNET_ASSETS.map((a) => safeNormalizeAddress(a.coinType.split("::")[0]))
588
+ ...networkAssets.map((a) => safeNormalizeAddress(a.coinType.split("::")[0]))
524
589
  ]);
525
590
  for (const cmd of commands) {
526
591
  if (cmd.$kind === "MoveCall") {
@@ -673,7 +738,9 @@ function verifyOwnerTransaction(input) {
673
738
  switch (op.kind) {
674
739
  case "create_pool":
675
740
  case "top_up": {
676
- if (!supportedAssetByCoinType(normCoinType)) {
741
+ if (!supportedAssetByCoinTypeForNetwork(normCoinType, input.assetNetwork, {
742
+ usdcCoinType: input.localnetUsdcCoinType
743
+ })) {
677
744
  throw new TransactionVerificationError("coinType");
678
745
  }
679
746
  let expectedAmt;
@@ -2485,7 +2552,7 @@ function wrapFailover(clients, options = {}) {
2485
2552
 
2486
2553
  // ../sdk/dist/buyer-control/chain.js
2487
2554
  import { Transaction as Transaction2, coinWithBalance } from "@mysten/sui/transactions";
2488
- import { fromBase64 as fromBase643, normalizeStructTag as normalizeStructTag4, normalizeSuiAddress as normalizeSuiAddress3, toBase64 } from "@mysten/sui/utils";
2555
+ import { fromBase64 as fromBase643, normalizeStructTag as normalizeStructTag6, normalizeSuiAddress as normalizeSuiAddress3, toBase64 } from "@mysten/sui/utils";
2489
2556
 
2490
2557
  // ../core/dist/chain/address.js
2491
2558
  function hexOf(address) {
@@ -2529,7 +2596,7 @@ function objectTypeFromGetObject(object) {
2529
2596
 
2530
2597
  // ../core/dist/policy/target.js
2531
2598
  import { createHash } from "crypto";
2532
- import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
2599
+ import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui/utils";
2533
2600
 
2534
2601
  // ../core/dist/service-state/index.js
2535
2602
  var STATE_DIMENSIONS = Object.freeze([
@@ -2923,7 +2990,7 @@ var MODULE = "spend_account";
2923
2990
  var SUI_COIN_TYPE = "0x2::sui::SUI";
2924
2991
  function isSuiCoinType(coinType) {
2925
2992
  try {
2926
- return normalizeStructTag4(coinType) === normalizeStructTag4(SUI_COIN_TYPE);
2993
+ return normalizeStructTag6(coinType) === normalizeStructTag6(SUI_COIN_TYPE);
2927
2994
  } catch {
2928
2995
  return /::sui::SUI$/i.test(coinType);
2929
2996
  }
@@ -4225,7 +4292,7 @@ var sha256 = /* @__PURE__ */ createHasher(
4225
4292
  );
4226
4293
 
4227
4294
  // ../sdk/dist/protocol/offer-exclusion.js
4228
- import { normalizeStructTag as normalizeStructTag5, normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui/utils";
4295
+ import { normalizeStructTag as normalizeStructTag7, normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui/utils";
4229
4296
 
4230
4297
  // ../sdk/dist/protocol/terms.js
4231
4298
  function paymentIdHash(challengeId) {
@@ -4300,7 +4367,7 @@ function addr32(address) {
4300
4367
  return hexToBytes(normalized.slice(2));
4301
4368
  }
4302
4369
  function canonicalCoinTypeBytes(coinType) {
4303
- const normalized = normalizeStructTag5(coinType.trim());
4370
+ const normalized = normalizeStructTag7(coinType.trim());
4304
4371
  const canonical = normalized.replace(/0x([0-9a-f]{64})/g, "$1");
4305
4372
  if (!/^[0-9a-f]{64}::/.test(canonical)) {
4306
4373
  throw new Error(`coin type must resolve to a numeric package address: ${coinType}`);
@@ -4500,7 +4567,7 @@ function createGrpcExclusionRegistryReader(client) {
4500
4567
  // ../sdk/dist/delegated-signer/payer.js
4501
4568
  import { bcs as bcs7 } from "@mysten/sui/bcs";
4502
4569
  import { Transaction as Transaction4 } from "@mysten/sui/transactions";
4503
- import { fromBase64 as fromBase647, normalizeStructTag as normalizeStructTag8, normalizeSuiAddress as normalizeSuiAddress9, toBase64 as toBase645 } from "@mysten/sui/utils";
4570
+ import { fromBase64 as fromBase647, normalizeStructTag as normalizeStructTag10, normalizeSuiAddress as normalizeSuiAddress9, toBase64 as toBase645 } from "@mysten/sui/utils";
4504
4571
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
4505
4572
 
4506
4573
  // ../sdk/dist/delegated-signer/finality-poll.js
@@ -4526,7 +4593,7 @@ async function pollFinality(input) {
4526
4593
  }
4527
4594
 
4528
4595
  // ../sdk/dist/pay-operation/operation.js
4529
- import { normalizeStructTag as normalizeStructTag7, normalizeSuiAddress as normalizeSuiAddress6 } from "@mysten/sui/utils";
4596
+ import { normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as normalizeSuiAddress6 } from "@mysten/sui/utils";
4530
4597
 
4531
4598
  // ../core/dist/policy/grant-target.js
4532
4599
  function normalizeHash(hex) {
@@ -5755,7 +5822,7 @@ import { fromHex } from "@mysten/sui/utils";
5755
5822
 
5756
5823
  // ../sdk/dist/protocol/coin-type-hash.js
5757
5824
  import { createHash as createHash2 } from "crypto";
5758
- import { normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
5825
+ import { normalizeStructTag as normalizeStructTag8 } from "@mysten/sui/utils";
5759
5826
 
5760
5827
  // ../sdk/dist/protocol/refund-vault.js
5761
5828
  function isRefundableOffer(offer) {
@@ -6420,8 +6487,8 @@ function resolveAuthority(authority, offer) {
6420
6487
  };
6421
6488
  }
6422
6489
  function validateAmount(offer, resolved) {
6423
- const offerCoinType = normalizeStructTag7(offer.asset);
6424
- const grantCoinType = normalizeStructTag7(resolved.coinType);
6490
+ const offerCoinType = normalizeStructTag9(offer.asset);
6491
+ const grantCoinType = normalizeStructTag9(resolved.coinType);
6425
6492
  if (offerCoinType !== grantCoinType) {
6426
6493
  return {
6427
6494
  code: PAY_OPERATION_ERROR_CODES.COIN_TYPE_MISMATCH,
@@ -7492,7 +7559,7 @@ function atomicAmount(value) {
7492
7559
  }
7493
7560
  function sameStructTag(a, b) {
7494
7561
  try {
7495
- return normalizeStructTag8(a) === normalizeStructTag8(b);
7562
+ return normalizeStructTag10(a) === normalizeStructTag10(b);
7496
7563
  } catch {
7497
7564
  return false;
7498
7565
  }
@@ -8250,7 +8317,7 @@ async function payDelegatedSpendAccount(args) {
8250
8317
  refuseOffer("POLICY_NO_TARGET");
8251
8318
  }
8252
8319
  try {
8253
- normalizeStructTag8(offer2.asset);
8320
+ normalizeStructTag10(offer2.asset);
8254
8321
  } catch {
8255
8322
  refuseOffer("POLICY_BAD_ASSET");
8256
8323
  }
@@ -8314,7 +8381,7 @@ async function payDelegatedSpendAccount(args) {
8314
8381
  return buildSpendAccountPayKind(kindInput);
8315
8382
  };
8316
8383
  try {
8317
- normalizeStructTag8(snapshot.coinType);
8384
+ normalizeStructTag10(snapshot.coinType);
8318
8385
  } catch {
8319
8386
  return failed("POLICY_REJECTED", PUBLIC_DETAIL.POLICY_REJECTED);
8320
8387
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay-buyer",
3
- "version": "0.3.0-dev.11",
3
+ "version": "0.3.0-dev.13",
4
4
  "type": "module",
5
5
  "description": "SuiPay buyer SDK — delegated spend-account pay plus a typed /v1 control-plane client.",
6
6
  "license": "MIT",