aftermath-ts-sdk 1.2.51 → 1.2.52-perps.3

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 (214) hide show
  1. package/README.md +62 -28
  2. package/dist/general/apiHelpers/eventsApiHelpers.d.ts +1 -1
  3. package/dist/general/apiHelpers/eventsApiHelpers.d.ts.map +1 -1
  4. package/dist/general/apiHelpers/eventsApiHelpers.js +4 -1
  5. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +6 -0
  6. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
  7. package/dist/general/apiHelpers/transactionsApiHelpers.js +46 -0
  8. package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
  9. package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
  10. package/dist/general/dynamicGas/dynamicGas.js +34 -0
  11. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
  12. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
  13. package/dist/general/prices/coinGeckoTypes.d.ts +2 -0
  14. package/dist/general/prices/coinGeckoTypes.d.ts.map +1 -1
  15. package/dist/general/prices/prices.d.ts +73 -0
  16. package/dist/general/prices/prices.d.ts.map +1 -1
  17. package/dist/general/prices/prices.js +73 -0
  18. package/dist/general/providers/aftermath.d.ts +107 -27
  19. package/dist/general/providers/aftermath.d.ts.map +1 -1
  20. package/dist/general/providers/aftermath.js +110 -30
  21. package/dist/general/providers/aftermathApi.d.ts +128 -10
  22. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  23. package/dist/general/providers/aftermathApi.js +133 -14
  24. package/dist/general/types/castingTypes.d.ts +15 -7
  25. package/dist/general/types/castingTypes.d.ts.map +1 -1
  26. package/dist/general/types/castingTypes.js +6 -0
  27. package/dist/general/types/configTypes.d.ts +14 -8
  28. package/dist/general/types/configTypes.d.ts.map +1 -1
  29. package/dist/general/types/generalTypes.d.ts +229 -7
  30. package/dist/general/types/generalTypes.d.ts.map +1 -1
  31. package/dist/general/types/moveErrorsInterface.d.ts +1 -1
  32. package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
  33. package/dist/general/types/suiTypes.d.ts +0 -16
  34. package/dist/general/types/suiTypes.d.ts.map +1 -1
  35. package/dist/general/types/suiTypes.js +3 -25
  36. package/dist/general/utils/caller.d.ts +6 -3
  37. package/dist/general/utils/caller.d.ts.map +1 -1
  38. package/dist/general/utils/caller.js +22 -4
  39. package/dist/general/utils/casting.d.ts +156 -5
  40. package/dist/general/utils/casting.d.ts.map +1 -1
  41. package/dist/general/utils/casting.js +159 -18
  42. package/dist/general/utils/fixedUtils.d.ts +89 -2
  43. package/dist/general/utils/fixedUtils.d.ts.map +1 -1
  44. package/dist/general/utils/fixedUtils.js +81 -4
  45. package/dist/general/utils/helpers.d.ts +327 -10
  46. package/dist/general/utils/helpers.d.ts.map +1 -1
  47. package/dist/general/utils/helpers.js +409 -91
  48. package/dist/general/utils/iFixedUtils.d.ts +64 -0
  49. package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
  50. package/dist/general/utils/iFixedUtils.js +64 -0
  51. package/dist/general/wallet/wallet.d.ts +76 -1
  52. package/dist/general/wallet/wallet.d.ts.map +1 -1
  53. package/dist/general/wallet/wallet.js +75 -5
  54. package/dist/packages/auth/auth.d.ts +113 -4
  55. package/dist/packages/auth/auth.d.ts.map +1 -1
  56. package/dist/packages/auth/auth.js +190 -59
  57. package/dist/packages/auth/authTypes.d.ts +66 -0
  58. package/dist/packages/auth/authTypes.d.ts.map +1 -1
  59. package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
  60. package/dist/packages/coin/api/coinApi.js +29 -20
  61. package/dist/packages/coin/coin.d.ts +256 -1
  62. package/dist/packages/coin/coin.d.ts.map +1 -1
  63. package/dist/packages/coin/coin.js +246 -15
  64. package/dist/packages/coin/coinTypes.d.ts +95 -0
  65. package/dist/packages/coin/coinTypes.d.ts.map +1 -1
  66. package/dist/packages/dca/api/dcaApi.d.ts +2 -0
  67. package/dist/packages/dca/api/dcaApi.d.ts.map +1 -1
  68. package/dist/packages/dca/api/dcaApi.js +6 -3
  69. package/dist/packages/dca/dca.d.ts +125 -35
  70. package/dist/packages/dca/dca.d.ts.map +1 -1
  71. package/dist/packages/dca/dca.js +135 -43
  72. package/dist/packages/dca/dcaTypes.d.ts +217 -42
  73. package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
  74. package/dist/packages/farms/api/farmsApi.d.ts +725 -58
  75. package/dist/packages/farms/api/farmsApi.d.ts.map +1 -1
  76. package/dist/packages/farms/api/farmsApi.js +1149 -153
  77. package/dist/packages/farms/api/farmsApiCasting.d.ts +34 -18
  78. package/dist/packages/farms/api/farmsApiCasting.d.ts.map +1 -1
  79. package/dist/packages/farms/api/farmsApiCasting.js +218 -17
  80. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +117 -21
  81. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +1 -1
  82. package/dist/packages/farms/farms.d.ts +200 -12
  83. package/dist/packages/farms/farms.d.ts.map +1 -1
  84. package/dist/packages/farms/farms.js +204 -50
  85. package/dist/packages/farms/farmsStakedPosition.d.ts +143 -8
  86. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  87. package/dist/packages/farms/farmsStakedPosition.js +243 -137
  88. package/dist/packages/farms/farmsStakingPool.d.ts +171 -3
  89. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  90. package/dist/packages/farms/farmsStakingPool.js +233 -73
  91. package/dist/packages/farms/farmsTypes.d.ts +310 -2
  92. package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
  93. package/dist/packages/farms/farmsTypes.js +47 -0
  94. package/dist/packages/faucet/api/faucetApi.d.ts +9 -17
  95. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  96. package/dist/packages/faucet/api/faucetApi.js +44 -49
  97. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
  98. package/dist/packages/faucet/api/faucetApiCasting.js +8 -5
  99. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +1 -4
  100. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
  101. package/dist/packages/faucet/faucet.d.ts +1 -1
  102. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  103. package/dist/packages/faucet/faucet.js +1 -1
  104. package/dist/packages/faucet/faucetTypes.d.ts +2 -3
  105. package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
  106. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts +12 -0
  107. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts.map +1 -0
  108. package/dist/packages/limitOrders/api/limitOrdersApi.js +25 -0
  109. package/dist/packages/limitOrders/index.d.ts +2 -0
  110. package/dist/packages/limitOrders/index.d.ts.map +1 -0
  111. package/dist/packages/limitOrders/index.js +17 -0
  112. package/dist/packages/limitOrders/limitOrders.d.ts +143 -0
  113. package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -0
  114. package/dist/packages/limitOrders/limitOrders.js +190 -0
  115. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +211 -0
  116. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -0
  117. package/dist/packages/multisig/multisig.d.ts +34 -5
  118. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  119. package/dist/packages/multisig/multisig.js +33 -4
  120. package/dist/packages/multisig/multisigTypes.d.ts +17 -0
  121. package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
  122. package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
  123. package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
  124. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +38 -23
  125. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  126. package/dist/packages/perpetuals/api/perpetualsApi.js +740 -299
  127. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +10 -6
  128. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
  129. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +112 -42
  130. package/dist/packages/perpetuals/perpetuals.d.ts +33 -4
  131. package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
  132. package/dist/packages/perpetuals/perpetuals.js +105 -18
  133. package/dist/packages/perpetuals/perpetualsAccount.d.ts +107 -33
  134. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
  135. package/dist/packages/perpetuals/perpetualsAccount.js +569 -68
  136. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +104 -25
  137. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
  138. package/dist/packages/perpetuals/perpetualsMarket.d.ts +31 -9
  139. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
  140. package/dist/packages/perpetuals/perpetualsMarket.js +85 -77
  141. package/dist/packages/perpetuals/perpetualsTypes.d.ts +348 -380
  142. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
  143. package/dist/packages/perpetuals/perpetualsTypes.js +43 -113
  144. package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
  145. package/dist/packages/pools/api/poolsApiCasting.js +0 -1
  146. package/dist/packages/pools/pool.d.ts +333 -106
  147. package/dist/packages/pools/pool.d.ts.map +1 -1
  148. package/dist/packages/pools/pool.js +347 -119
  149. package/dist/packages/pools/pools.d.ts +307 -39
  150. package/dist/packages/pools/pools.d.ts.map +1 -1
  151. package/dist/packages/pools/pools.js +323 -54
  152. package/dist/packages/pools/poolsTypes.d.ts +267 -2
  153. package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
  154. package/dist/packages/referralVault/referralVault.d.ts +38 -1
  155. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  156. package/dist/packages/referralVault/referralVault.js +37 -0
  157. package/dist/packages/router/api/routerApi.d.ts +2 -2
  158. package/dist/packages/router/api/routerApi.d.ts.map +1 -1
  159. package/dist/packages/router/api/routerApi.js +19 -11
  160. package/dist/packages/router/router.d.ts +214 -18
  161. package/dist/packages/router/router.d.ts.map +1 -1
  162. package/dist/packages/router/router.js +216 -20
  163. package/dist/packages/router/routerTypes.d.ts +202 -17
  164. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  165. package/dist/packages/staking/staking.d.ts +306 -45
  166. package/dist/packages/staking/staking.d.ts.map +1 -1
  167. package/dist/packages/staking/staking.js +313 -51
  168. package/dist/packages/staking/stakingTypes.d.ts +431 -6
  169. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  170. package/dist/packages/staking/stakingTypes.js +19 -0
  171. package/dist/packages/sui/sui.d.ts +40 -1
  172. package/dist/packages/sui/sui.d.ts.map +1 -1
  173. package/dist/packages/sui/sui.js +39 -0
  174. package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
  175. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
  176. package/dist/packages/suiFrens/suiFren.d.ts +1 -1
  177. package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
  178. package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
  179. package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
  180. package/dist/packages/userData/api/userDataApi.d.ts +6 -0
  181. package/dist/packages/userData/api/userDataApi.d.ts.map +1 -0
  182. package/dist/packages/userData/api/userDataApi.js +12 -0
  183. package/dist/packages/userData/index.d.ts +2 -0
  184. package/dist/packages/userData/index.d.ts.map +1 -0
  185. package/dist/packages/userData/index.js +17 -0
  186. package/dist/packages/userData/userData.d.ts +89 -0
  187. package/dist/packages/userData/userData.d.ts.map +1 -0
  188. package/dist/packages/userData/userData.js +119 -0
  189. package/dist/packages/userData/userDataTypes.d.ts +29 -0
  190. package/dist/packages/userData/userDataTypes.d.ts.map +1 -0
  191. package/dist/types.d.ts.map +1 -1
  192. package/dist/types.js +0 -1
  193. package/package.json +1 -1
  194. package/dist/general/historicalData/historicalData.d.ts +0 -15
  195. package/dist/general/historicalData/historicalData.d.ts.map +0 -1
  196. package/dist/general/historicalData/historicalData.js +0 -45
  197. package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
  198. package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
  199. package/dist/packages/dca/api/dcaApiCasting.d.ts +0 -11
  200. package/dist/packages/dca/api/dcaApiCasting.d.ts.map +0 -1
  201. package/dist/packages/dca/api/dcaApiCasting.js +0 -186
  202. package/dist/packages/dca/api/dcaApiCastingTypes.d.ts +0 -142
  203. package/dist/packages/dca/api/dcaApiCastingTypes.d.ts.map +0 -1
  204. package/dist/packages/oracle/api/oracleApi.d.ts +0 -13
  205. package/dist/packages/oracle/api/oracleApi.d.ts.map +0 -1
  206. package/dist/packages/oracle/api/oracleApi.js +0 -35
  207. package/dist/packages/oracle/oracle.d.ts +0 -15
  208. package/dist/packages/oracle/oracle.d.ts.map +0 -1
  209. package/dist/packages/oracle/oracle.js +0 -46
  210. package/dist/packages/oracle/oracleTypes.d.ts +0 -2
  211. package/dist/packages/oracle/oracleTypes.d.ts.map +0 -1
  212. package/dist/packages/oracle/oracleTypes.js +0 -2
  213. /package/dist/{general/historicalData/historicalDataTypes.js → packages/limitOrders/limitOrdersTypes.js} +0 -0
  214. /package/dist/packages/{dca/api/dcaApiCastingTypes.js → userData/userDataTypes.js} +0 -0
@@ -23,9 +23,30 @@ const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
23
23
  const secp256k1_1 = require("@mysten/sui/keypairs/secp256k1");
24
24
  const secp256r1_1 = require("@mysten/sui/keypairs/secp256r1");
25
25
  /**
26
- * A utility class containing various helper functions for general use.
26
+ * A utility class containing various helper functions for general use across
27
+ * the Aftermath TS ecosystem. This includes numeric operations, object field
28
+ * extraction, array transformations, slippage adjustments, and Move error parsing.
27
29
  */
28
30
  class Helpers {
31
+ static uniqueObjectArray(arr) {
32
+ const seen = new Set();
33
+ return arr.filter((obj) => {
34
+ const str = JSON.stringify(obj);
35
+ if (seen.has(str)) {
36
+ return false;
37
+ }
38
+ seen.add(str);
39
+ return true;
40
+ });
41
+ }
42
+ /**
43
+ * Combines two arrays into a single array of pairs. The result length is the
44
+ * minimum of the two input arrays' lengths.
45
+ *
46
+ * @param firstCollection - The first array.
47
+ * @param lastCollection - The second array.
48
+ * @returns An array of `[firstCollection[i], lastCollection[i]]` pairs.
49
+ */
29
50
  static zip(firstCollection, lastCollection) {
30
51
  const length = Math.min(firstCollection.length, lastCollection.length);
31
52
  const zipped = [];
@@ -34,9 +55,42 @@ class Helpers {
34
55
  }
35
56
  return zipped;
36
57
  }
58
+ /**
59
+ * Removes circular references from an object or array, returning a JSON-safe structure.
60
+ * Any cyclic references are replaced with `undefined`.
61
+ *
62
+ * @param obj - The object or array to remove circular references from.
63
+ * @param seen - Internal usage to track references that have already been visited.
64
+ * @returns A structure that can be safely JSON-stringified.
65
+ */
66
+ static removeCircularReferences(obj, seen = new WeakSet()) {
67
+ if (obj && typeof obj === "object") {
68
+ if (seen.has(obj)) {
69
+ return undefined;
70
+ }
71
+ seen.add(obj);
72
+ if (Array.isArray(obj)) {
73
+ return obj.map((item) => this.removeCircularReferences(item, seen));
74
+ }
75
+ else {
76
+ const entries = Object.entries(obj).map(([key, value]) => [
77
+ key,
78
+ this.removeCircularReferences(value, seen),
79
+ ]);
80
+ return Object.fromEntries(entries);
81
+ }
82
+ }
83
+ return obj;
84
+ }
37
85
  // =========================================================================
38
86
  // Type Checking
39
87
  // =========================================================================
88
+ /**
89
+ * Checks if an unknown value is an array of strings.
90
+ *
91
+ * @param value - The value to check.
92
+ * @returns `true` if `value` is a string array, otherwise `false`.
93
+ */
40
94
  static isArrayOfStrings(value) {
41
95
  return (Array.isArray(value) &&
42
96
  value.every((item) => typeof item === "string"));
@@ -44,14 +98,28 @@ class Helpers {
44
98
  // =========================================================================
45
99
  // Sui Object Parsing
46
100
  // =========================================================================
101
+ /**
102
+ * Extracts the fully qualified type (e.g., "0x2::coin::Coin<...>") from a `SuiObjectResponse`,
103
+ * normalizing it with leading zeroes if necessary.
104
+ *
105
+ * @param data - The object response from Sui.
106
+ * @returns The normalized object type string.
107
+ * @throws If the type is not found.
108
+ */
47
109
  static getObjectType(data) {
48
110
  var _b, _c;
49
111
  const objectType = (_b = data.data) === null || _b === void 0 ? void 0 : _b.type;
50
- // NOTE: should `Helpers.addLeadingZeroesToType` not be used here ?
51
112
  if (objectType)
52
113
  return Helpers.addLeadingZeroesToType(objectType);
53
114
  throw new Error("no object type found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.objectId));
54
115
  }
116
+ /**
117
+ * Extracts the object ID from a `SuiObjectResponse`, normalizing it with leading zeroes.
118
+ *
119
+ * @param data - The object response from Sui.
120
+ * @returns A zero-padded `ObjectId`.
121
+ * @throws If the objectId is not found.
122
+ */
55
123
  static getObjectId(data) {
56
124
  var _b, _c;
57
125
  const objectId = (_b = data.data) === null || _b === void 0 ? void 0 : _b.objectId;
@@ -59,6 +127,13 @@ class Helpers {
59
127
  return Helpers.addLeadingZeroesToType(objectId);
60
128
  throw new Error("no object id found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.type));
61
129
  }
130
+ /**
131
+ * Retrieves the fields of a Move object from a `SuiObjectResponse`.
132
+ *
133
+ * @param data - The Sui object response containing a Move object.
134
+ * @returns A record of fields for that object.
135
+ * @throws If no fields are found.
136
+ */
62
137
  static getObjectFields(data) {
63
138
  var _b, _c;
64
139
  try {
@@ -69,6 +144,13 @@ class Helpers {
69
144
  throw new Error("no object fields found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.objectId));
70
145
  }
71
146
  }
147
+ /**
148
+ * Retrieves display metadata from a Sui object response, if present.
149
+ *
150
+ * @param data - The Sui object response.
151
+ * @returns The display fields for that object.
152
+ * @throws If display fields are not found.
153
+ */
72
154
  static getObjectDisplay(data) {
73
155
  var _b, _c;
74
156
  const display = (_b = data.data) === null || _b === void 0 ? void 0 : _b.display;
@@ -79,12 +161,21 @@ class Helpers {
79
161
  // =========================================================================
80
162
  // Error Parsing
81
163
  // =========================================================================
164
+ /**
165
+ * Parses a MoveAbort error message from Sui into a possible `(errorCode, packageId, module)`,
166
+ * if the message follows a known pattern. Otherwise returns undefined.
167
+ *
168
+ * @param inputs - The object containing the raw `errorMessage` from Sui.
169
+ * @returns A partial structure of the error details or undefined.
170
+ */
82
171
  static parseMoveErrorMessage(inputs) {
83
172
  const { errorMessage } = inputs;
84
173
  if (!errorMessage.toLowerCase().includes("moveabort"))
85
174
  return undefined;
86
175
  /*
87
176
  MoveAbort(MoveLocation { module: ModuleId { address: 8d8946c2a433e2bf795414498d9f7b32e04aca8dbf35a20257542dc51406242b, name: Identifier("orderbook") }, function: 11, instruction: 117, function_name: Some("fill_market_order") }, 3005) in command 2
177
+
178
+ MoveAbort(MoveLocation { module: ModuleId { address: 7c995f9c0c0553c0f3bfac7cf3c8b85716f0ca522305586bd0168ca20aeed277, name: Identifier("clearing_house") }, function: 37, instruction: 17, function_name: Some("place_limit_order") }, 1) in command 1
88
179
  */
89
180
  const moveErrorCode = (inputs) => {
90
181
  const { errorMessage } = inputs;
@@ -98,7 +189,7 @@ class Helpers {
98
189
  return undefined;
99
190
  return errorCode;
100
191
  }
101
- catch (e) {
192
+ catch (_b) {
102
193
  return undefined;
103
194
  }
104
195
  };
@@ -109,16 +200,16 @@ class Helpers {
109
200
  if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex)
110
201
  return undefined;
111
202
  try {
112
- const packageId = Helpers.addLeadingZeroesToType("0x" +
113
- errorMessage
114
- .slice(startIndex + 8, endIndex)
115
- .trim()
116
- .replaceAll("0x", ""));
203
+ const pkgStr = errorMessage
204
+ .slice(startIndex + 8, endIndex)
205
+ .trim()
206
+ .replaceAll("0x", "");
207
+ const packageId = Helpers.addLeadingZeroesToType("0x" + pkgStr);
117
208
  if (!this.isValidHex(packageId))
118
209
  return undefined;
119
210
  return packageId;
120
211
  }
121
- catch (e) {
212
+ catch (_b) {
122
213
  return undefined;
123
214
  }
124
215
  };
@@ -133,71 +224,96 @@ class Helpers {
133
224
  try {
134
225
  return errorMessage.slice(startIndex + 12, endIndex).trim();
135
226
  }
136
- catch (e) {
227
+ catch (_b) {
137
228
  return undefined;
138
229
  }
139
230
  };
140
- try {
141
- const errorCode = moveErrorCode({
142
- errorMessage,
143
- });
144
- const packageId = moveErrorPackageId({
145
- errorMessage,
146
- });
147
- const module = moveErrorModule({
148
- errorMessage,
149
- });
150
- if (errorCode === undefined || !packageId || !module)
151
- return undefined;
152
- return {
153
- errorCode,
154
- packageId,
155
- module,
156
- };
157
- }
158
- catch (e) {
231
+ const errorCode = moveErrorCode({ errorMessage });
232
+ const packageId = moveErrorPackageId({ errorMessage });
233
+ const module = moveErrorModule({ errorMessage });
234
+ if (errorCode === undefined || !packageId || !module)
159
235
  return undefined;
160
- }
236
+ return { errorCode, packageId, module };
161
237
  }
238
+ /**
239
+ * Translates a Move abort error message into a known error string if it matches
240
+ * entries in a given `moveErrors` table. This is used to map on-chain error codes
241
+ * to user-friendly messages.
242
+ *
243
+ * @param inputs - Includes the raw `errorMessage` and a `moveErrors` object keyed by package, module, and code.
244
+ * @returns A structure with `errorCode`, `packageId`, `module`, and a human-readable `error` string, or `undefined`.
245
+ */
162
246
  static translateMoveErrorMessage(inputs) {
163
247
  const { errorMessage, moveErrors } = inputs;
164
248
  const parsed = this.parseMoveErrorMessage({ errorMessage });
165
- if (!parsed ||
166
- !(parsed.packageId in moveErrors) ||
167
- !(parsed.module in moveErrors[parsed.packageId]) ||
168
- !(parsed.errorCode in moveErrors[parsed.packageId][parsed.module]))
249
+ if (!parsed || !(parsed.packageId in moveErrors))
169
250
  return undefined;
170
- return Object.assign(Object.assign({}, parsed), { error: moveErrors[parsed.packageId][parsed.module][parsed.errorCode] });
251
+ let error;
252
+ if (parsed.module in moveErrors[parsed.packageId] &&
253
+ parsed.errorCode in moveErrors[parsed.packageId][parsed.module]) {
254
+ error =
255
+ moveErrors[parsed.packageId][parsed.module][parsed.errorCode];
256
+ }
257
+ else if ("ANY" in moveErrors[parsed.packageId] &&
258
+ parsed.errorCode in moveErrors[parsed.packageId]["ANY"]) {
259
+ error = moveErrors[parsed.packageId]["ANY"][parsed.errorCode];
260
+ }
261
+ else
262
+ return undefined;
263
+ return Object.assign(Object.assign({}, parsed), { error });
171
264
  }
172
265
  }
173
266
  exports.Helpers = Helpers;
174
267
  _a = Helpers;
175
268
  // =========================================================================
176
- // Api Helpers
269
+ // Api Helpers (Static References)
177
270
  // =========================================================================
271
+ /**
272
+ * Static reference to the `DynamicFieldsApiHelpers`, providing utility methods
273
+ * for working with dynamic fields in Sui objects.
274
+ */
178
275
  Helpers.dynamicFields = dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers;
276
+ /**
277
+ * Static reference to the `EventsApiHelpers`, providing methods for
278
+ * querying and filtering Sui events.
279
+ */
179
280
  Helpers.events = eventsApiHelpers_1.EventsApiHelpers;
281
+ /**
282
+ * Static reference to the `InspectionsApiHelpers`, used for reading
283
+ * Summaries or inspection data from objects.
284
+ */
180
285
  Helpers.inspections = inspectionsApiHelpers_1.InspectionsApiHelpers;
286
+ /**
287
+ * Static reference to the `ObjectsApiHelpers`, providing direct
288
+ * retrieval or manipulation of on-chain Sui objects.
289
+ */
181
290
  Helpers.objects = objectsApiHelpers_1.ObjectsApiHelpers;
291
+ /**
292
+ * Static reference to the `TransactionsApiHelpers`, enabling easier
293
+ * queries for transaction data by digest or other criteria.
294
+ */
182
295
  Helpers.transactions = transactionsApiHelpers_1.TransactionsApiHelpers;
183
296
  // =========================================================================
184
297
  // Type Manipulation
185
298
  // =========================================================================
186
299
  /**
187
- * Removes leading zeroes from the hexadecimal representation of a given object type.
188
- * @param type - The object type to strip leading zeroes from.
189
- * @returns The object type with leading zeroes removed from its hexadecimal representation.
300
+ * Removes all leading zeroes (after the '0x') from a string that represents
301
+ * a Sui address or object type. For instance, "0x0000123" => "0x123".
302
+ *
303
+ * @param type - The hex string to process, potentially including "::" module syntax.
304
+ * @returns The same string with unnecessary leading zeroes stripped out.
190
305
  */
191
306
  Helpers.stripLeadingZeroesFromType = (type) => type.replaceAll(/x0+/g, "x");
192
307
  /**
193
- * Adds leading zeroes to a given `AnyObjectType` until it reaches a length of 64 characters.
194
- * If the input type already has a length greater than 64, an error is thrown.
195
- * @param type - The `AnyObjectType` to add leading zeroes to.
196
- * @returns The modified `AnyObjectType` with leading zeroes added.
197
- * @throws An error if the input type has a length greater than 64.
308
+ * Ensures the given Sui address or object type is zero-padded to 64 hex digits
309
+ * after the "0x". If a "::" suffix is present, only the address portion is padded.
310
+ *
311
+ * @param type - The "0x..." string or extended type (0x..::module).
312
+ * @returns A new string normalized to a 64-hex-digit address or object ID.
313
+ * @throws If the address portion is already longer than 64 hex digits.
198
314
  */
199
315
  Helpers.addLeadingZeroesToType = (type) => {
200
- const expectedTypeLength = 64;
316
+ const EXPECTED_TYPE_LENGTH = 64;
201
317
  let strippedType = type.replace("0x", "");
202
318
  let typeSuffix = "";
203
319
  if (strippedType.includes("::")) {
@@ -208,41 +324,156 @@ Helpers.addLeadingZeroesToType = (type) => {
208
324
  strippedType = splitType[0];
209
325
  }
210
326
  const typeLength = strippedType.length;
211
- if (typeLength > expectedTypeLength)
327
+ if (typeLength > EXPECTED_TYPE_LENGTH)
212
328
  throw new Error("invalid type length");
213
- const zeros = Array(expectedTypeLength - typeLength)
214
- .fill("0")
215
- .reduce((acc, val) => acc + val, "");
216
- const newType = "0x" + zeros + strippedType;
329
+ const zerosNeeded = EXPECTED_TYPE_LENGTH - typeLength;
330
+ const zeroString = Array(zerosNeeded).fill("0").join("");
331
+ const newType = "0x" + zeroString + strippedType;
217
332
  return newType + typeSuffix;
218
333
  };
334
+ /**
335
+ * Splits a non-SUI coin type string that may be prefixed by a chain ID for external usage,
336
+ * returning the chain and the coin type. If no chain is recognized, defaults to `"sui"`.
337
+ *
338
+ * @param coin - The coin string, which may look like `"bsc:0x<...>"` or just `"0x<...>"`.
339
+ * @returns An object with the `chain` (e.g. "bsc") and the `coinType`.
340
+ */
341
+ Helpers.splitNonSuiCoinType = (coin) => {
342
+ const [uncastChain, coinType] = coin.split(":");
343
+ if (!uncastChain || !coinType)
344
+ return { coinType: coin, chain: "sui" };
345
+ const chain = uncastChain;
346
+ return { chain, coinType };
347
+ };
219
348
  // =========================================================================
220
349
  // Numbers
221
350
  // =========================================================================
351
+ /**
352
+ * Checks if a given string represents a valid number (integer or decimal).
353
+ *
354
+ * @param str - The string to test.
355
+ * @returns `true` if it's a valid numeric string, otherwise `false`.
356
+ */
222
357
  Helpers.isNumber = (str) => /^\d*\.?\d*$/g.test(str);
358
+ /**
359
+ * Sums an array of floating-point numbers, returning the numeric total.
360
+ *
361
+ * @param arr - The array of numbers to sum.
362
+ * @returns The total as a float.
363
+ */
223
364
  Helpers.sum = (arr) => arr.reduce((prev, cur) => prev + cur, 0);
365
+ /**
366
+ * Sums an array of bigints, returning the total as a bigint.
367
+ *
368
+ * @param arr - The array of bigints to sum.
369
+ * @returns The resulting total as a bigint.
370
+ */
224
371
  Helpers.sumBigInt = (arr) => arr.reduce((prev, cur) => prev + cur, BigInt(0));
372
+ /**
373
+ * Determines if two numbers are close within a given tolerance factor,
374
+ * i.e., `|a - b| <= tolerance * max(a, b)`.
375
+ *
376
+ * @param a - The first number.
377
+ * @param b - The second number.
378
+ * @param tolerance - A fraction representing the max allowed difference relative to max(a, b).
379
+ * @returns `true` if within tolerance, otherwise `false`.
380
+ */
225
381
  Helpers.closeEnough = (a, b, tolerance) => Math.abs(a - b) <= tolerance * Math.max(a, b);
382
+ /**
383
+ * Determines if two bigints are close within a given tolerance factor,
384
+ * by casting them to numbers internally.
385
+ *
386
+ * @param a - First bigint.
387
+ * @param b - Second bigint.
388
+ * @param tolerance - A fraction representing the max allowed difference relative to max(a, b).
389
+ * @returns `true` if within tolerance, otherwise `false`.
390
+ */
226
391
  Helpers.closeEnoughBigInt = (a, b, tolerance) => Helpers.closeEnough(Number(a), Number(b), tolerance);
392
+ /**
393
+ * Checks whether the integer divisions of `a` and `b` (by `fixedOne`) differ
394
+ * by at most 1. Typically used in fixed math scenarios to see if two scaled
395
+ * values are "very close."
396
+ *
397
+ * @param a - First number (scaled).
398
+ * @param b - Second number (scaled).
399
+ * @param fixedOne - The scaling factor representing 1.0 in the same scale as `a` and `b`.
400
+ * @returns `true` if the integer parts differ by <= 1, otherwise `false`.
401
+ */
227
402
  Helpers.veryCloseInt = (a, b, fixedOne) => Math.abs(Math.floor(a / fixedOne) - Math.floor(b / fixedOne)) <= 1;
403
+ /**
404
+ * A small object containing "blended" math operations that handle
405
+ * mixed numeric types (number vs. bigint). This is primarily for
406
+ * internal usage in advanced math scenarios.
407
+ */
228
408
  Helpers.blendedOperations = {
409
+ /**
410
+ * Multiply two floating-point numbers.
411
+ */
229
412
  mulNNN: (a, b) => a * b,
413
+ /**
414
+ * Multiply a float and a bigint, returning a bigint (floor).
415
+ */
230
416
  mulNNB: (a, b) => BigInt(Math.floor(a * b)),
417
+ /**
418
+ * Multiply a float and a bigint, returning a float.
419
+ */
231
420
  mulNBN: (a, b) => a * Number(b),
421
+ /**
422
+ * Multiply a float and a bigint, returning a bigint (floor).
423
+ */
232
424
  mulNBB: (a, b) => BigInt(Math.floor(a * Number(b))),
425
+ /**
426
+ * Multiply two bigints, returning a float.
427
+ */
233
428
  mulBBN: (a, b) => Number(a * b),
429
+ /**
430
+ * Multiply two bigints, returning a bigint.
431
+ */
234
432
  mulBBB: (a, b) => a * b,
235
433
  };
434
+ /**
435
+ * Returns the maximum of multiple bigints.
436
+ *
437
+ * @param args - The bigints to compare.
438
+ * @returns The largest bigint.
439
+ */
236
440
  Helpers.maxBigInt = (...args) => args.reduce((m, e) => (e > m ? e : m));
441
+ /**
442
+ * Returns the minimum of multiple bigints.
443
+ *
444
+ * @param args - The bigints to compare.
445
+ * @returns The smallest bigint.
446
+ */
237
447
  Helpers.minBigInt = (...args) => args.reduce((m, e) => (e < m ? e : m));
448
+ /**
449
+ * Returns the absolute value of a bigint.
450
+ *
451
+ * @param num - The input bigint.
452
+ * @returns A bigint representing the absolute value of `num`.
453
+ */
238
454
  Helpers.absBigInt = (num) => (num < BigInt(0) ? -num : num);
239
455
  // =========================================================================
240
456
  // Display
241
457
  // =========================================================================
458
+ /**
459
+ * Capitalizes only the first letter of a string, making the rest lowercase.
460
+ * E.g., "HELLO" => "Hello".
461
+ *
462
+ * @param str - The input string to transform.
463
+ * @returns The resulting string with the first character in uppercase and the rest in lowercase.
464
+ */
242
465
  Helpers.capitalizeOnlyFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
243
466
  // =========================================================================
244
467
  // JSON
245
468
  // =========================================================================
469
+ /**
470
+ * Parses a JSON string containing potential BigInt values.
471
+ * By default, it only converts strings ending in 'n' (like `"123n"`) to BigInts.
472
+ *
473
+ * @param json - The JSON string to parse.
474
+ * @param unsafeStringNumberConversion - If `true`, all numeric strings (e.g., "123") will also become BigInts.
475
+ * @returns The parsed JSON object with BigInt conversions where applicable.
476
+ */
246
477
  Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JSON.parse(json, (key, value) => {
247
478
  // handles bigint casting
248
479
  if (typeof value === "string" && /^-?\d+n$/.test(value)) {
@@ -258,6 +489,13 @@ Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JS
258
489
  // =========================================================================
259
490
  // General
260
491
  // =========================================================================
492
+ /**
493
+ * Creates a deep copy of the given target, handling nested arrays and objects.
494
+ * Dates are cloned by their timestamp.
495
+ *
496
+ * @param target - The data to clone deeply.
497
+ * @returns A new object/array/date structure mirroring `target`.
498
+ */
261
499
  Helpers.deepCopy = (target) => {
262
500
  if (target === null) {
263
501
  return target;
@@ -265,7 +503,7 @@ Helpers.deepCopy = (target) => {
265
503
  if (target instanceof Date) {
266
504
  return new Date(target.getTime());
267
505
  }
268
- if (target instanceof Array) {
506
+ if (Array.isArray(target)) {
269
507
  const cp = [];
270
508
  target.forEach((v) => {
271
509
  cp.push(v);
@@ -281,6 +519,12 @@ Helpers.deepCopy = (target) => {
281
519
  }
282
520
  return target;
283
521
  };
522
+ /**
523
+ * Finds the index of the maximum value in an array. Returns -1 if the array is empty.
524
+ *
525
+ * @param arr - The input array.
526
+ * @returns The index of the maximum value, or -1 if the array is empty.
527
+ */
284
528
  Helpers.indexOfMax = (arr) => {
285
529
  if (arr.length === 0)
286
530
  return -1;
@@ -294,9 +538,39 @@ Helpers.indexOfMax = (arr) => {
294
538
  }
295
539
  return maxIndex;
296
540
  };
297
- Helpers.uniqueArray = (arr) => [...new Set(arr)];
541
+ /**
542
+ * Returns a new array with unique elements from the input array,
543
+ * preserving the order of first occurrences.
544
+ *
545
+ * @param arr - The original array.
546
+ * @returns An array of unique items.
547
+ */
548
+ Helpers.uniqueArray = (arr) => arr.length <= 0
549
+ ? []
550
+ : typeof arr[0] === "object"
551
+ ? Helpers.uniqueObjectArray(arr)
552
+ : [...new Set(arr)];
553
+ /**
554
+ * Returns a Promise that resolves after a specified number of milliseconds.
555
+ *
556
+ * @param ms - The delay time in milliseconds.
557
+ * @returns A promise that resolves after `ms` milliseconds.
558
+ */
298
559
  Helpers.sleep = (ms) => new Promise((r) => setTimeout(r, ms));
560
+ /**
561
+ * Creates a unique ID-like string by combining the current timestamp and random base36 digits.
562
+ *
563
+ * @returns A short random string (base36) that can serve as a unique identifier.
564
+ */
299
565
  Helpers.createUid = () => Date.now().toString(36) + Math.random().toString(36).substring(2);
566
+ /**
567
+ * Splits an array into two groups: those for which `func` returns `true` (or truthy),
568
+ * and those for which it returns `false`. The result is returned as a tuple `[trues, falses]`.
569
+ *
570
+ * @param array - The array to filter.
571
+ * @param func - The function used to test each element.
572
+ * @returns A tuple containing two arrays: `[elements that pass, elements that fail]`.
573
+ */
300
574
  Helpers.bifilter = (array, func) => {
301
575
  return array.reduce(([T, F], x, i, arr) => {
302
576
  if (func(x, i, arr) === false)
@@ -305,24 +579,64 @@ Helpers.bifilter = (array, func) => {
305
579
  return [[...T, x], F];
306
580
  }, [[], []]);
307
581
  };
582
+ /**
583
+ * An async version of `bifilter`, returning a tuple of `[trues, falses]`.
584
+ * Each element is tested asynchronously in parallel via `func`.
585
+ *
586
+ * @param array - The array to filter.
587
+ * @param func - An async function returning `true` or `false`.
588
+ * @returns A tuple `[trues, falses]` after asynchronous evaluation.
589
+ */
308
590
  Helpers.bifilterAsync = (array, func) => __awaiter(void 0, void 0, void 0, function* () {
309
591
  const predicates = yield Promise.all(array.map(func));
310
592
  return _a.bifilter(array, (_, index) => predicates[index]);
311
593
  });
594
+ /**
595
+ * Filters the entries of an object based on a predicate function,
596
+ * returning a new object with only those entries for which `predicate`
597
+ * returns `true`.
598
+ *
599
+ * @param obj - The original object to filter.
600
+ * @param predicate - A function taking `(key, value)` and returning a boolean.
601
+ * @returns A new object with only the entries that pass the predicate.
602
+ */
312
603
  Helpers.filterObject = (obj, predicate) => Object.keys(obj).reduce((acc, key) => {
313
604
  const val = obj[key];
314
605
  if (!predicate(key, val))
315
606
  return acc;
316
607
  return Object.assign(Object.assign({}, acc), { [key]: val });
317
608
  }, {});
609
+ /**
610
+ * Applies downward slippage to a bigint amount by subtracting `slippage * amount`.
611
+ * For instance, for 1% slippage, we reduce the amount by 1%.
612
+ *
613
+ * @param amount - The original bigint amount.
614
+ * @param slippage - An integer percent (e.g., 1 => 1%).
615
+ * @returns The adjusted bigint after subtracting the slippage portion.
616
+ */
318
617
  Helpers.applySlippageBigInt = (amount, slippage) => {
319
618
  return (amount -
320
619
  BigInt(Math.floor(casting_1.Casting.normalizeSlippageTolerance(slippage) *
321
620
  Number(amount))));
322
621
  };
622
+ /**
623
+ * Applies downward slippage to a floating-point amount. E.g., for 1% slippage,
624
+ * reduce by 1% of `amount`.
625
+ *
626
+ * @param amount - The original float value.
627
+ * @param slippage - An integer percent (e.g., 1 => 1%).
628
+ * @returns The float after applying slippage.
629
+ */
323
630
  Helpers.applySlippage = (amount, slippage) => {
324
631
  return amount - casting_1.Casting.normalizeSlippageTolerance(slippage) * amount;
325
632
  };
633
+ /**
634
+ * Roughly checks if a string is a valid Sui type (e.g., "0x2::sui::SUI").
635
+ * This is not guaranteed to be perfect, but covers common cases.
636
+ *
637
+ * @param str - The string to validate.
638
+ * @returns `true` if it meets the minimum structure, otherwise `false`.
639
+ */
326
640
  Helpers.isValidType = (str) => {
327
641
  // TODO: use regex
328
642
  const trimmedStr = str.trim();
@@ -332,6 +646,12 @@ Helpers.isValidType = (str) => {
332
646
  trimmedStr.lastIndexOf("::") >= 6 &&
333
647
  !trimmedStr.endsWith(":"));
334
648
  };
649
+ /**
650
+ * Checks if a string is a valid hex representation, optionally prefixed with "0x".
651
+ *
652
+ * @param hexString - The string to check.
653
+ * @returns `true` if `hexString` is a valid hex, otherwise `false`.
654
+ */
335
655
  Helpers.isValidHex = (hexString) => {
336
656
  const hexPattern = /^(0x)?[0-9A-F]+$/i;
337
657
  return hexPattern.test(hexString);
@@ -339,41 +659,29 @@ Helpers.isValidHex = (hexString) => {
339
659
  // =========================================================================
340
660
  // Tx Command Input Construction
341
661
  // =========================================================================
342
- // TODO: use this everywhere in api for tx command creation
662
+ /**
663
+ * Utility for building transaction commands with either a string-based
664
+ * `ObjectId` or an existing transaction object argument. If it's a string,
665
+ * it's converted via `tx.object(...)`; if already a `TransactionObjectArgument`,
666
+ * it's returned as-is.
667
+ *
668
+ * @param tx - The current `Transaction` block to add the object to.
669
+ * @param object - Either an `ObjectId` or a `TransactionObjectArgument`.
670
+ * @returns A `TransactionObjectArgument` referencing the provided object.
671
+ */
343
672
  Helpers.addTxObject = (tx, object) => {
344
673
  return typeof object === "string" ? tx.object(object) : object;
345
674
  };
346
675
  // =========================================================================
347
- // Constructors
676
+ // Sui Address / Key Checking
348
677
  // =========================================================================
349
- // public static async createScallopProviders(inputs: {
350
- // network: SuiNetwork;
351
- // }): Promise<ScallopProviders> {
352
- // const network = inputs.network.toLowerCase();
353
- // const networkType =
354
- // network === "local"
355
- // ? "localnet"
356
- // : network !== "mainnet" &&
357
- // network !== "testnet" &&
358
- // network !== "localnet"
359
- // ? undefined
360
- // : network;
361
- // if (!networkType)
362
- // throw new Error(`network \`${inputs.network}\` not found`);
363
- // const Main = new Scallop({
364
- // networkType,
365
- // });
366
- // const [Builder, Query] = await Promise.all([
367
- // Main.createScallopBuilder(),
368
- // Main.createScallopQuery(),
369
- // ]);
370
- // // await Promise.all([Builder.init(), Query.init()]);
371
- // return {
372
- // Main,
373
- // Builder,
374
- // Query,
375
- // };
376
- // }
678
+ /**
679
+ * Checks if a given string is a valid Sui address by normalizing it to a
680
+ * 64-hex-digit form and calling `isValidSuiAddress`.
681
+ *
682
+ * @param address - The Sui address to validate.
683
+ * @returns `true` if valid, `false` otherwise.
684
+ */
377
685
  Helpers.isValidSuiAddress = (address) => (0, utils_1.isValidSuiAddress)((() => {
378
686
  if (!address.startsWith("0x") || address.length < 3)
379
687
  return "";
@@ -387,15 +695,25 @@ Helpers.isValidSuiAddress = (address) => (0, utils_1.isValidSuiAddress)((() => {
387
695
  // =========================================================================
388
696
  // Keypair
389
697
  // =========================================================================
698
+ /**
699
+ * Constructs a `Keypair` instance from a private key string. The `privateKey`
700
+ * may indicate the signing scheme (ED25519, Secp256k1, or Secp256r1) via prefix,
701
+ * as recognized by `decodeSuiPrivateKey`.
702
+ *
703
+ * @param privateKey - The full private key string (e.g., "0x<64_hex_chars>").
704
+ * @returns A new `Keypair` instance for signing transactions.
705
+ * @throws If the schema is unsupported.
706
+ */
390
707
  Helpers.keypairFromPrivateKey = (privateKey) => {
391
708
  const parsedKeypair = (0, cryptography_1.decodeSuiPrivateKey)(privateKey);
392
- return parsedKeypair.schema === "ED25519"
393
- ? ed25519_1.Ed25519Keypair.fromSecretKey(parsedKeypair.secretKey)
394
- : parsedKeypair.schema === "Secp256k1"
395
- ? secp256k1_1.Secp256k1Keypair.fromSecretKey(parsedKeypair.secretKey)
396
- : parsedKeypair.schema === "Secp256r1"
397
- ? secp256r1_1.Secp256r1Keypair.fromSecretKey(parsedKeypair.secretKey)
398
- : (() => {
399
- throw new Error(`unsupported schema \`${parsedKeypair.schema}\``);
400
- })();
709
+ switch (parsedKeypair.schema) {
710
+ case "ED25519":
711
+ return ed25519_1.Ed25519Keypair.fromSecretKey(parsedKeypair.secretKey);
712
+ case "Secp256k1":
713
+ return secp256k1_1.Secp256k1Keypair.fromSecretKey(parsedKeypair.secretKey);
714
+ case "Secp256r1":
715
+ return secp256r1_1.Secp256r1Keypair.fromSecretKey(parsedKeypair.secretKey);
716
+ default:
717
+ throw new Error(`unsupported schema \`${parsedKeypair.schema}\``);
718
+ }
401
719
  };