@getpara/core-sdk 2.0.0-alpha.54 → 2.0.0-alpha.55

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.
@@ -43,7 +43,7 @@ __export(constants_exports, {
43
43
  SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
44
44
  });
45
45
  module.exports = __toCommonJS(constants_exports);
46
- const PARA_CORE_VERSION = "2.0.0-alpha.54";
46
+ const PARA_CORE_VERSION = "2.0.0-alpha.55";
47
47
  const PREFIX = "@CAPSULE/";
48
48
  const PARA_PREFIX = "@PARA/";
49
49
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
package/dist/cjs/index.js CHANGED
@@ -112,6 +112,7 @@ __reExport(src_exports, require("./errors.js"), module.exports);
112
112
  __reExport(src_exports, require("./utils/formatting.js"), module.exports);
113
113
  __reExport(src_exports, require("./utils/polling.js"), module.exports);
114
114
  __reExport(src_exports, require("./utils/phone.js"), module.exports);
115
+ __reExport(src_exports, require("./utils/config.js"), module.exports);
115
116
  var import_wallet = require("./utils/wallet.js");
116
117
  var import_onRamps = require("./utils/onRamps.js");
117
118
  var import_url = require("./utils/url.js");
@@ -190,5 +191,6 @@ var src_default = import_ParaCore.ParaCore;
190
191
  ...require("./errors.js"),
191
192
  ...require("./utils/formatting.js"),
192
193
  ...require("./utils/polling.js"),
193
- ...require("./utils/phone.js")
194
+ ...require("./utils/phone.js"),
195
+ ...require("./utils/config.js")
194
196
  });
@@ -0,0 +1,108 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var config_exports = {};
19
+ __export(config_exports, {
20
+ validateBalancesConfig: () => validateBalancesConfig
21
+ });
22
+ module.exports = __toCommonJS(config_exports);
23
+ var import_user_management_client = require("@getpara/user-management-client");
24
+ function validateBalancesConfig(obj) {
25
+ if (!obj || typeof obj !== "object") {
26
+ return false;
27
+ }
28
+ if (!obj.displayType || obj.displayType !== "AGGREGATED" && obj.displayType !== "CUSTOM_ASSET") {
29
+ return false;
30
+ }
31
+ if (obj.displayType === "AGGREGATED") {
32
+ if (obj.excludeStandardAssets !== void 0 && typeof obj.excludeStandardAssets !== "boolean") {
33
+ return false;
34
+ }
35
+ if (obj.additionalAssets !== void 0) {
36
+ if (!Array.isArray(obj.additionalAssets)) {
37
+ return false;
38
+ }
39
+ for (const asset of obj.additionalAssets) {
40
+ if (!validateCustomAsset(asset)) {
41
+ return false;
42
+ }
43
+ const hasPriceUrl = typeof asset.priceUrl === "string" && asset.priceUrl.trim();
44
+ const hasPrice = asset.price && typeof asset.price === "object" && typeof asset.price.value === "number" && asset.price.value > 0 && typeof asset.price.currency === "string" && asset.price.currency.trim();
45
+ if (!hasPriceUrl && !hasPrice) {
46
+ return false;
47
+ }
48
+ if (hasPriceUrl && hasPrice) {
49
+ return false;
50
+ }
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ if (obj.displayType === "CUSTOM_ASSET") {
56
+ if (!obj.asset) {
57
+ return false;
58
+ }
59
+ if (!validateCustomAsset(obj.asset)) {
60
+ return false;
61
+ }
62
+ const hasPriceUrl = typeof obj.asset.priceUrl === "string" && obj.asset.priceUrl.trim();
63
+ const hasPrice = obj.asset.price && typeof obj.asset.price === "object" && typeof obj.asset.price.value === "number" && obj.asset.price.value > 0 && typeof obj.asset.price.currency === "string" && obj.asset.price.currency.trim();
64
+ if (hasPriceUrl && hasPrice) {
65
+ return false;
66
+ }
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ function validateCustomAsset(obj) {
72
+ if (!obj || typeof obj !== "object") {
73
+ return false;
74
+ }
75
+ if (typeof obj.name !== "string" || !obj.name.trim() || typeof obj.symbol !== "string" || !obj.symbol.trim()) {
76
+ return false;
77
+ }
78
+ if (!Array.isArray(obj.implementations) || obj.implementations.length === 0) {
79
+ return false;
80
+ }
81
+ for (const network of obj.implementations) {
82
+ if (!network || typeof network !== "object") {
83
+ return false;
84
+ }
85
+ if (typeof network.network === "string") {
86
+ if (!import_user_management_client.NETWORKS.includes(network.network)) {
87
+ return false;
88
+ }
89
+ if (typeof network.contractAddress !== "string" || !network.contractAddress.trim()) {
90
+ return false;
91
+ }
92
+ } else if (typeof network.network === "object") {
93
+ if (typeof network.network.name !== "string" || !network.network.name.trim() || typeof network.network.rpcUrl !== "string" || !network.network.rpcUrl.trim() || typeof network.network.evmChainId !== "string" || !network.network.evmChainId.trim()) {
94
+ return false;
95
+ }
96
+ if (network.contractAddress !== void 0 && (typeof network.contractAddress !== "string" || !network.contractAddress.trim())) {
97
+ return false;
98
+ }
99
+ } else {
100
+ return false;
101
+ }
102
+ }
103
+ return true;
104
+ }
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ validateBalancesConfig
108
+ });
@@ -131,7 +131,7 @@ function formatAssetQuantity({
131
131
  decimals,
132
132
  fallback = ""
133
133
  }) {
134
- if (!quantity) {
134
+ if (quantity == null) {
135
135
  return fallback;
136
136
  }
137
137
  const formatter = new Intl.NumberFormat("en-US", {
@@ -139,7 +139,8 @@ function formatAssetQuantity({
139
139
  maximumFractionDigits: decimals != null ? decimals : Math.abs(quantity) < 1e-3 ? 6 : 3,
140
140
  minimumFractionDigits: decimals != null ? decimals : 3
141
141
  });
142
- return `${Math.abs(quantity) < __pow(10, -1 * (decimals != null ? decimals : 6)) ? zeroAssetFormatter.format(0) : formatter.format(quantity)}${symbol && symbol.length > 0 ? ` ${symbol}` : ""}`;
142
+ const formattedQuantity = quantity === 0 ? "0" : Math.abs(quantity) < __pow(10, -1 * (decimals != null ? decimals : 6)) ? zeroAssetFormatter.format(0) : formatter.format(quantity);
143
+ return `${formattedQuantity}${symbol && symbol.length > 0 ? ` ${symbol}` : ""}`;
143
144
  }
144
145
  // Annotate the CommonJS export names for ESM import in node:
145
146
  0 && (module.exports = {
@@ -15,6 +15,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
15
  var utils_exports = {};
16
16
  module.exports = __toCommonJS(utils_exports);
17
17
  __reExport(utils_exports, require("./autobind.js"), module.exports);
18
+ __reExport(utils_exports, require("./config.js"), module.exports);
18
19
  __reExport(utils_exports, require("./events.js"), module.exports);
19
20
  __reExport(utils_exports, require("./formatting.js"), module.exports);
20
21
  __reExport(utils_exports, require("./json.js"), module.exports);
@@ -28,6 +29,7 @@ __reExport(utils_exports, require("./wallet.js"), module.exports);
28
29
  // Annotate the CommonJS export names for ESM import in node:
29
30
  0 && (module.exports = {
30
31
  ...require("./autobind.js"),
32
+ ...require("./config.js"),
31
33
  ...require("./events.js"),
32
34
  ...require("./formatting.js"),
33
35
  ...require("./json.js"),
@@ -1,5 +1,5 @@
1
1
  import "./chunk-W5CT3TVS.js";
2
- const PARA_CORE_VERSION = "2.0.0-alpha.54";
2
+ const PARA_CORE_VERSION = "2.0.0-alpha.55";
3
3
  const PREFIX = "@CAPSULE/";
4
4
  const PARA_PREFIX = "@PARA/";
5
5
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
package/dist/esm/index.js CHANGED
@@ -63,6 +63,7 @@ export * from "./errors.js";
63
63
  export * from "./utils/formatting.js";
64
64
  export * from "./utils/polling.js";
65
65
  export * from "./utils/phone.js";
66
+ export * from "./utils/config.js";
66
67
  import { isWalletSupported } from "./utils/wallet.js";
67
68
  import { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from "./utils/onRamps.js";
68
69
  import { getPortalBaseURL } from "./utils/url.js";
@@ -0,0 +1,86 @@
1
+ import "../chunk-W5CT3TVS.js";
2
+ import { NETWORKS } from "@getpara/user-management-client";
3
+ function validateBalancesConfig(obj) {
4
+ if (!obj || typeof obj !== "object") {
5
+ return false;
6
+ }
7
+ if (!obj.displayType || obj.displayType !== "AGGREGATED" && obj.displayType !== "CUSTOM_ASSET") {
8
+ return false;
9
+ }
10
+ if (obj.displayType === "AGGREGATED") {
11
+ if (obj.excludeStandardAssets !== void 0 && typeof obj.excludeStandardAssets !== "boolean") {
12
+ return false;
13
+ }
14
+ if (obj.additionalAssets !== void 0) {
15
+ if (!Array.isArray(obj.additionalAssets)) {
16
+ return false;
17
+ }
18
+ for (const asset of obj.additionalAssets) {
19
+ if (!validateCustomAsset(asset)) {
20
+ return false;
21
+ }
22
+ const hasPriceUrl = typeof asset.priceUrl === "string" && asset.priceUrl.trim();
23
+ const hasPrice = asset.price && typeof asset.price === "object" && typeof asset.price.value === "number" && asset.price.value > 0 && typeof asset.price.currency === "string" && asset.price.currency.trim();
24
+ if (!hasPriceUrl && !hasPrice) {
25
+ return false;
26
+ }
27
+ if (hasPriceUrl && hasPrice) {
28
+ return false;
29
+ }
30
+ }
31
+ }
32
+ return true;
33
+ }
34
+ if (obj.displayType === "CUSTOM_ASSET") {
35
+ if (!obj.asset) {
36
+ return false;
37
+ }
38
+ if (!validateCustomAsset(obj.asset)) {
39
+ return false;
40
+ }
41
+ const hasPriceUrl = typeof obj.asset.priceUrl === "string" && obj.asset.priceUrl.trim();
42
+ const hasPrice = obj.asset.price && typeof obj.asset.price === "object" && typeof obj.asset.price.value === "number" && obj.asset.price.value > 0 && typeof obj.asset.price.currency === "string" && obj.asset.price.currency.trim();
43
+ if (hasPriceUrl && hasPrice) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ return false;
49
+ }
50
+ function validateCustomAsset(obj) {
51
+ if (!obj || typeof obj !== "object") {
52
+ return false;
53
+ }
54
+ if (typeof obj.name !== "string" || !obj.name.trim() || typeof obj.symbol !== "string" || !obj.symbol.trim()) {
55
+ return false;
56
+ }
57
+ if (!Array.isArray(obj.implementations) || obj.implementations.length === 0) {
58
+ return false;
59
+ }
60
+ for (const network of obj.implementations) {
61
+ if (!network || typeof network !== "object") {
62
+ return false;
63
+ }
64
+ if (typeof network.network === "string") {
65
+ if (!NETWORKS.includes(network.network)) {
66
+ return false;
67
+ }
68
+ if (typeof network.contractAddress !== "string" || !network.contractAddress.trim()) {
69
+ return false;
70
+ }
71
+ } else if (typeof network.network === "object") {
72
+ if (typeof network.network.name !== "string" || !network.network.name.trim() || typeof network.network.rpcUrl !== "string" || !network.network.rpcUrl.trim() || typeof network.network.evmChainId !== "string" || !network.network.evmChainId.trim()) {
73
+ return false;
74
+ }
75
+ if (network.contractAddress !== void 0 && (typeof network.contractAddress !== "string" || !network.contractAddress.trim())) {
76
+ return false;
77
+ }
78
+ } else {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ }
84
+ export {
85
+ validateBalancesConfig
86
+ };
@@ -91,7 +91,7 @@ function formatAssetQuantity({
91
91
  decimals,
92
92
  fallback = ""
93
93
  }) {
94
- if (!quantity) {
94
+ if (quantity == null) {
95
95
  return fallback;
96
96
  }
97
97
  const formatter = new Intl.NumberFormat("en-US", {
@@ -99,7 +99,8 @@ function formatAssetQuantity({
99
99
  maximumFractionDigits: decimals != null ? decimals : Math.abs(quantity) < 1e-3 ? 6 : 3,
100
100
  minimumFractionDigits: decimals != null ? decimals : 3
101
101
  });
102
- return `${Math.abs(quantity) < __pow(10, -1 * (decimals != null ? decimals : 6)) ? zeroAssetFormatter.format(0) : formatter.format(quantity)}${symbol && symbol.length > 0 ? ` ${symbol}` : ""}`;
102
+ const formattedQuantity = quantity === 0 ? "0" : Math.abs(quantity) < __pow(10, -1 * (decimals != null ? decimals : 6)) ? zeroAssetFormatter.format(0) : formatter.format(quantity);
103
+ return `${formattedQuantity}${symbol && symbol.length > 0 ? ` ${symbol}` : ""}`;
103
104
  }
104
105
  export {
105
106
  compressPubkey,
@@ -1,4 +1,5 @@
1
1
  export * from "./autobind.js";
2
+ export * from "./config.js";
2
3
  export * from "./events.js";
3
4
  export * from "./formatting.js";
4
5
  export * from "./json.js";
@@ -18,6 +18,7 @@ export * from './errors.js';
18
18
  export * from './utils/formatting.js';
19
19
  export * from './utils/polling.js';
20
20
  export * from './utils/phone.js';
21
+ export * from './utils/config.js';
21
22
  export { isWalletSupported } from './utils/wallet.js';
22
23
  export { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from './utils/onRamps.js';
23
24
  export { getPortalBaseURL } from './utils/url.js';
@@ -0,0 +1,7 @@
1
+ import { BalancesConfig } from '@getpara/user-management-client';
2
+ /**
3
+ * Validates if an object is a valid BalancesConfig
4
+ * @param obj - The object to validate
5
+ * @returns True if the object is a valid BalancesConfig, false otherwise
6
+ */
7
+ export declare function validateBalancesConfig(obj: any): obj is BalancesConfig;
@@ -1,4 +1,5 @@
1
1
  export * from './autobind.js';
2
+ export * from './config.js';
2
3
  export * from './events.js';
3
4
  export * from './formatting.js';
4
5
  export * from './json.js';
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@getpara/core-sdk",
3
- "version": "2.0.0-alpha.54",
3
+ "version": "2.0.0-alpha.55",
4
4
  "dependencies": {
5
5
  "@celo/utils": "^8.0.2",
6
6
  "@cosmjs/encoding": "^0.32.4",
7
7
  "@ethereumjs/util": "^9.1.0",
8
- "@getpara/user-management-client": "2.0.0-alpha.54",
8
+ "@getpara/user-management-client": "2.0.0-alpha.55",
9
9
  "@noble/hashes": "^1.5.0",
10
10
  "base64url": "^3.0.1",
11
11
  "libphonenumber-js": "^1.11.7",
@@ -27,7 +27,7 @@
27
27
  "dist",
28
28
  "package.json"
29
29
  ],
30
- "gitHead": "680049700f7b36b7ef407cab0fbfadad8c069d74",
30
+ "gitHead": "370bc842fc70118826e3b75815ba923c50f28100",
31
31
  "main": "dist/cjs/index.js",
32
32
  "module": "dist/esm/index.js",
33
33
  "scripts": {