@getpara/core-sdk 2.0.0-alpha.6 → 2.0.0-alpha.61

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 (75) hide show
  1. package/dist/cjs/ParaCore.js +1038 -248
  2. package/dist/cjs/constants.js +13 -1
  3. package/dist/cjs/index.js +31 -3
  4. package/dist/cjs/shares/enclave.js +266 -0
  5. package/dist/cjs/shares/shareDistribution.js +16 -1
  6. package/dist/cjs/types/{theme.js → assets.js} +2 -2
  7. package/dist/cjs/types/{onRamps.js → auth.js} +12 -12
  8. package/dist/cjs/types/coreApi.js +20 -3
  9. package/dist/cjs/types/events.js +2 -0
  10. package/dist/cjs/types/index.js +2 -21
  11. package/dist/cjs/utils/config.js +108 -0
  12. package/dist/cjs/utils/formatting.js +46 -0
  13. package/dist/cjs/utils/index.js +2 -0
  14. package/dist/cjs/utils/onRamps.js +2 -3
  15. package/dist/cjs/utils/wallet.js +3 -0
  16. package/dist/esm/ParaCore.js +1045 -254
  17. package/dist/esm/{chunk-7B52C2XE.js → chunk-W5CT3TVS.js} +2 -0
  18. package/dist/esm/constants.js +10 -2
  19. package/dist/esm/cryptography/utils.js +1 -1
  20. package/dist/esm/errors.js +1 -1
  21. package/dist/esm/external/mpcComputationClient.js +1 -1
  22. package/dist/esm/external/userManagementClient.js +1 -1
  23. package/dist/esm/index.js +31 -6
  24. package/dist/esm/shares/KeyContainer.js +1 -1
  25. package/dist/esm/shares/enclave.js +226 -0
  26. package/dist/esm/shares/recovery.js +1 -1
  27. package/dist/esm/shares/shareDistribution.js +17 -2
  28. package/dist/esm/transmission/transmissionUtils.js +1 -1
  29. package/dist/esm/types/auth.js +11 -0
  30. package/dist/esm/types/config.js +1 -1
  31. package/dist/esm/types/coreApi.js +19 -3
  32. package/dist/esm/types/events.js +3 -1
  33. package/dist/esm/types/index.js +1 -16
  34. package/dist/esm/types/popup.js +1 -1
  35. package/dist/esm/types/wallet.js +1 -1
  36. package/dist/esm/utils/autobind.js +1 -1
  37. package/dist/esm/utils/config.js +86 -0
  38. package/dist/esm/utils/events.js +1 -1
  39. package/dist/esm/utils/formatting.js +44 -1
  40. package/dist/esm/utils/index.js +1 -0
  41. package/dist/esm/utils/json.js +1 -1
  42. package/dist/esm/utils/listeners.js +1 -1
  43. package/dist/esm/utils/onRamps.js +3 -4
  44. package/dist/esm/utils/phone.js +1 -1
  45. package/dist/esm/utils/polling.js +1 -1
  46. package/dist/esm/utils/types.js +1 -1
  47. package/dist/esm/utils/url.js +1 -1
  48. package/dist/esm/utils/wallet.js +4 -1
  49. package/dist/types/ParaCore.d.ts +115 -52
  50. package/dist/types/PlatformUtils.d.ts +2 -3
  51. package/dist/types/constants.d.ts +18 -14
  52. package/dist/types/index.d.ts +6 -4
  53. package/dist/types/shares/KeyContainer.d.ts +0 -2
  54. package/dist/types/shares/enclave.d.ts +81 -0
  55. package/dist/types/shares/shareDistribution.d.ts +4 -2
  56. package/dist/types/types/assets.d.ts +14 -0
  57. package/dist/types/types/auth.d.ts +16 -0
  58. package/dist/types/types/config.d.ts +11 -2
  59. package/dist/types/types/coreApi.d.ts +101 -36
  60. package/dist/types/types/events.d.ts +7 -2
  61. package/dist/types/types/index.d.ts +1 -4
  62. package/dist/types/types/methods.d.ts +85 -13
  63. package/dist/types/types/wallet.d.ts +7 -4
  64. package/dist/types/utils/config.d.ts +7 -0
  65. package/dist/types/utils/formatting.d.ts +12 -1
  66. package/dist/types/utils/index.d.ts +1 -0
  67. package/dist/types/utils/onRamps.d.ts +9 -10
  68. package/package.json +23 -23
  69. package/dist/cjs/types/recovery.js +0 -34
  70. package/dist/esm/types/onRamps.js +0 -11
  71. package/dist/esm/types/recovery.js +0 -12
  72. package/dist/types/types/onRamps.d.ts +0 -10
  73. package/dist/types/types/recovery.d.ts +0 -7
  74. package/dist/types/types/theme.d.ts +0 -12
  75. /package/dist/esm/types/{theme.js → assets.js} +0 -0
@@ -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
+ });
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __pow = Math.pow;
7
8
  var __export = (target, all) => {
8
9
  for (var name in all)
9
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,12 +28,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
29
  var formatting_exports = {};
29
30
  __export(formatting_exports, {
31
+ compressPubkey: () => compressPubkey,
30
32
  decimalToHex: () => decimalToHex,
33
+ formatAssetQuantity: () => formatAssetQuantity,
34
+ formatCurrency: () => formatCurrency,
31
35
  getCosmosAddress: () => getCosmosAddress,
32
36
  hexStringToBase64: () => hexStringToBase64,
33
37
  hexToDecimal: () => hexToDecimal,
34
38
  hexToSignature: () => hexToSignature,
35
39
  hexToUint8Array: () => hexToUint8Array,
40
+ rawSecp256k1PubkeyToRawAddress: () => rawSecp256k1PubkeyToRawAddress,
36
41
  truncateAddress: () => truncateAddress
37
42
  });
38
43
  module.exports = __toCommonJS(formatting_exports);
@@ -100,13 +105,54 @@ function truncateAddress(str, addressType, {
100
105
  const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
101
106
  return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
102
107
  }
108
+ function formatCurrency(value, { fallback = "" } = {}) {
109
+ if (!value) {
110
+ return fallback;
111
+ }
112
+ const formatter = new Intl.NumberFormat("en-US", {
113
+ style: "currency",
114
+ currency: value.currency
115
+ });
116
+ const zeroFormatter = new Intl.NumberFormat("en-US", {
117
+ style: "currency",
118
+ currency: value.currency,
119
+ maximumFractionDigits: 0
120
+ });
121
+ return Math.abs(value.value) < 0.01 ? zeroFormatter.format(0) : formatter.format(value.value);
122
+ }
123
+ const zeroAssetFormatter = new Intl.NumberFormat("en-US", {
124
+ style: "decimal",
125
+ maximumFractionDigits: 0,
126
+ minimumFractionDigits: 0
127
+ });
128
+ function formatAssetQuantity({
129
+ quantity,
130
+ symbol = "",
131
+ decimals,
132
+ fallback = ""
133
+ }) {
134
+ if (quantity == null) {
135
+ return fallback;
136
+ }
137
+ const formatter = new Intl.NumberFormat("en-US", {
138
+ style: "decimal",
139
+ maximumFractionDigits: decimals != null ? decimals : Math.abs(quantity) < 1e-3 ? 6 : 3,
140
+ minimumFractionDigits: decimals != null ? decimals : 3
141
+ });
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}` : ""}`;
144
+ }
103
145
  // Annotate the CommonJS export names for ESM import in node:
104
146
  0 && (module.exports = {
147
+ compressPubkey,
105
148
  decimalToHex,
149
+ formatAssetQuantity,
150
+ formatCurrency,
106
151
  getCosmosAddress,
107
152
  hexStringToBase64,
108
153
  hexToDecimal,
109
154
  hexToSignature,
110
155
  hexToUint8Array,
156
+ rawSecp256k1PubkeyToRawAddress,
111
157
  truncateAddress
112
158
  });
@@ -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"),
@@ -24,7 +24,6 @@ __export(onRamps_exports, {
24
24
  toAssetInfoArray: () => toAssetInfoArray
25
25
  });
26
26
  module.exports = __toCommonJS(onRamps_exports);
27
- var import_user_management_client = require("@getpara/user-management-client");
28
27
  function toAssetInfoArray(data) {
29
28
  const result = [];
30
29
  Object.keys(data).forEach((walletType) => {
@@ -76,8 +75,8 @@ function getOnRampAssets(data, {
76
75
  ];
77
76
  }
78
77
  const NETWORK_PREFIXES = {
79
- [import_user_management_client.Network.COSMOS]: "cosmos",
80
- [import_user_management_client.Network.NOBLE]: "noble"
78
+ COSMOS: "cosmos",
79
+ NOBLE: "noble"
81
80
  };
82
81
  function getNetworkPrefix(network) {
83
82
  return NETWORK_PREFIXES[network];
@@ -114,7 +114,10 @@ function getEquivalentTypes(types) {
114
114
  return getWalletTypes(getSchemes(Array.isArray(types) ? types : [types]));
115
115
  }
116
116
  function entityToWallet(w) {
117
+ var _a;
117
118
  return __spreadProps(__spreadValues({}, w), {
119
+ createdAt: typeof w.createdAt === "string" ? w.createdAt : w.createdAt.toISOString(),
120
+ lastUsedAt: typeof w.lastUsedAt === "string" ? w.lastUsedAt : (_a = w.lastUsedAt) == null ? void 0 : _a.toISOString(),
118
121
  scheme: w.scheme,
119
122
  type: w.type,
120
123
  pregenIdentifierType: w.pregenIdentifierType