amogus-sdk-internal-utils 0.35.2

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 (261) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  2. package/dist/_virtual/rolldown_runtime.js +18 -0
  3. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.cjs +10 -0
  4. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.d.cts +6 -0
  5. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.d.ts +6 -0
  6. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.js +10 -0
  7. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.cjs +17 -0
  8. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.d.cts +9 -0
  9. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.d.ts +9 -0
  10. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.js +12 -0
  11. package/dist/bridgeIndexer/bridgeIndexerHttpClient/runtime.cjs +20 -0
  12. package/dist/bridgeIndexer/bridgeIndexerHttpClient/runtime.js +20 -0
  13. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.cjs +25 -0
  14. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.d.cts +31 -0
  15. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.d.ts +31 -0
  16. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.js +23 -0
  17. package/dist/bridgeIndexer/index.cjs +13 -0
  18. package/dist/bridgeIndexer/index.d.cts +8 -0
  19. package/dist/bridgeIndexer/index.d.ts +8 -0
  20. package/dist/bridgeIndexer/index.js +8 -0
  21. package/dist/config.cjs +86 -0
  22. package/dist/config.d.cts +50 -0
  23. package/dist/config.d.ts +50 -0
  24. package/dist/config.js +76 -0
  25. package/dist/errors/assert.cjs +11 -0
  26. package/dist/errors/assert.d.cts +11 -0
  27. package/dist/errors/assert.d.ts +11 -0
  28. package/dist/errors/assert.js +11 -0
  29. package/dist/errors/base.cjs +34 -0
  30. package/dist/errors/base.d.cts +21 -0
  31. package/dist/errors/base.d.ts +21 -0
  32. package/dist/errors/base.js +33 -0
  33. package/dist/errors/index.cjs +23 -0
  34. package/dist/errors/index.d.cts +11 -0
  35. package/dist/errors/index.d.ts +11 -0
  36. package/dist/errors/index.js +18 -0
  37. package/dist/errors/request.cjs +48 -0
  38. package/dist/errors/request.d.cts +61 -0
  39. package/dist/errors/request.d.ts +61 -0
  40. package/dist/errors/request.js +46 -0
  41. package/dist/errors/utils/isNetworkError.cjs +23 -0
  42. package/dist/errors/utils/isNetworkError.js +22 -0
  43. package/dist/errors/utils/toError.cjs +8 -0
  44. package/dist/errors/utils/toError.d.cts +4 -0
  45. package/dist/errors/utils/toError.d.ts +4 -0
  46. package/dist/errors/utils/toError.js +7 -0
  47. package/dist/index.cjs +144 -0
  48. package/dist/index.d.cts +33 -0
  49. package/dist/index.d.ts +33 -0
  50. package/dist/index.js +33 -0
  51. package/dist/logger.d.cts +11 -0
  52. package/dist/logger.d.ts +11 -0
  53. package/dist/nearClient.cjs +18 -0
  54. package/dist/nearClient.d.cts +8 -0
  55. package/dist/nearClient.d.ts +8 -0
  56. package/dist/nearClient.js +18 -0
  57. package/dist/poaBridge/constants/blockchains.cjs +62 -0
  58. package/dist/poaBridge/constants/blockchains.d.cts +95 -0
  59. package/dist/poaBridge/constants/blockchains.d.ts +95 -0
  60. package/dist/poaBridge/constants/blockchains.js +59 -0
  61. package/dist/poaBridge/errors/withdrawal.cjs +52 -0
  62. package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
  63. package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
  64. package/dist/poaBridge/errors/withdrawal.js +50 -0
  65. package/dist/poaBridge/getPendingDeposits.cjs +31 -0
  66. package/dist/poaBridge/getPendingDeposits.d.cts +14 -0
  67. package/dist/poaBridge/getPendingDeposits.d.ts +15 -0
  68. package/dist/poaBridge/getPendingDeposits.js +31 -0
  69. package/dist/poaBridge/index.cjs +23 -0
  70. package/dist/poaBridge/index.d.cts +11 -0
  71. package/dist/poaBridge/index.d.ts +11 -0
  72. package/dist/poaBridge/index.js +18 -0
  73. package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
  74. package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
  75. package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
  76. package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
  77. package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
  78. package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
  79. package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
  80. package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
  81. package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
  82. package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
  83. package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +172 -0
  84. package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +172 -0
  85. package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
  86. package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
  87. package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
  88. package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
  89. package/dist/services/blockchainBalanceService.cjs +40 -0
  90. package/dist/services/blockchainBalanceService.d.cts +21 -0
  91. package/dist/services/blockchainBalanceService.d.ts +21 -0
  92. package/dist/services/blockchainBalanceService.js +37 -0
  93. package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
  94. package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
  95. package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
  96. package/dist/solverRelay/errors/intentSettlement.js +20 -0
  97. package/dist/solverRelay/errors/quote.cjs +18 -0
  98. package/dist/solverRelay/errors/quote.d.cts +21 -0
  99. package/dist/solverRelay/errors/quote.d.ts +22 -0
  100. package/dist/solverRelay/errors/quote.js +18 -0
  101. package/dist/solverRelay/getQuote.cjs +70 -0
  102. package/dist/solverRelay/getQuote.d.cts +14 -0
  103. package/dist/solverRelay/getQuote.d.ts +14 -0
  104. package/dist/solverRelay/getQuote.js +70 -0
  105. package/dist/solverRelay/getStatus.cjs +26 -0
  106. package/dist/solverRelay/getStatus.d.cts +17 -0
  107. package/dist/solverRelay/getStatus.d.ts +18 -0
  108. package/dist/solverRelay/getStatus.js +26 -0
  109. package/dist/solverRelay/index.cjs +27 -0
  110. package/dist/solverRelay/index.d.cts +16 -0
  111. package/dist/solverRelay/index.d.ts +16 -0
  112. package/dist/solverRelay/index.js +22 -0
  113. package/dist/solverRelay/publishIntent.cjs +20 -0
  114. package/dist/solverRelay/publishIntent.d.cts +15 -0
  115. package/dist/solverRelay/publishIntent.d.ts +16 -0
  116. package/dist/solverRelay/publishIntent.js +20 -0
  117. package/dist/solverRelay/publishIntents.cjs +42 -0
  118. package/dist/solverRelay/publishIntents.d.cts +10 -0
  119. package/dist/solverRelay/publishIntents.d.ts +11 -0
  120. package/dist/solverRelay/publishIntents.js +41 -0
  121. package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
  122. package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
  123. package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
  124. package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
  125. package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
  126. package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
  127. package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
  128. package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
  129. package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
  130. package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
  131. package/dist/solverRelay/solverRelayHttpClient/types.d.cts +117 -0
  132. package/dist/solverRelay/solverRelayHttpClient/types.d.ts +117 -0
  133. package/dist/solverRelay/utils/parseFailedPublishError.cjs +64 -0
  134. package/dist/solverRelay/utils/parseFailedPublishError.d.cts +56 -0
  135. package/dist/solverRelay/utils/parseFailedPublishError.d.ts +57 -0
  136. package/dist/solverRelay/utils/parseFailedPublishError.js +61 -0
  137. package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
  138. package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
  139. package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
  140. package/dist/solverRelay/utils/quoteWithLog.js +21 -0
  141. package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
  142. package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
  143. package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
  144. package/dist/solverRelay/waitForIntentSettlement.js +52 -0
  145. package/dist/types/authHandle.cjs +22 -0
  146. package/dist/types/authHandle.d.cts +25 -0
  147. package/dist/types/authHandle.d.ts +25 -0
  148. package/dist/types/authHandle.js +16 -0
  149. package/dist/types/base.d.cts +45 -0
  150. package/dist/types/base.d.ts +45 -0
  151. package/dist/types/intentsUserId.d.cts +10 -0
  152. package/dist/types/intentsUserId.d.ts +10 -0
  153. package/dist/types/walletMessage.cjs +11 -0
  154. package/dist/types/walletMessage.d.cts +106 -0
  155. package/dist/types/walletMessage.d.ts +106 -0
  156. package/dist/types/walletMessage.js +5 -0
  157. package/dist/utils/abortSignal.cjs +19 -0
  158. package/dist/utils/abortSignal.js +18 -0
  159. package/dist/utils/appFee.cjs +20 -0
  160. package/dist/utils/appFee.d.cts +9 -0
  161. package/dist/utils/appFee.d.ts +9 -0
  162. package/dist/utils/appFee.js +15 -0
  163. package/dist/utils/assert.cjs +9 -0
  164. package/dist/utils/assert.d.cts +7 -0
  165. package/dist/utils/assert.d.ts +7 -0
  166. package/dist/utils/assert.js +9 -0
  167. package/dist/utils/authIdentity.cjs +56 -0
  168. package/dist/utils/authIdentity.d.cts +34 -0
  169. package/dist/utils/authIdentity.d.ts +34 -0
  170. package/dist/utils/authIdentity.js +50 -0
  171. package/dist/utils/failover.cjs +36 -0
  172. package/dist/utils/failover.d.cts +24 -0
  173. package/dist/utils/failover.d.ts +24 -0
  174. package/dist/utils/failover.js +34 -0
  175. package/dist/utils/handleRPCResponse.cjs +30 -0
  176. package/dist/utils/handleRPCResponse.js +28 -0
  177. package/dist/utils/handleResponse.cjs +31 -0
  178. package/dist/utils/handleResponse.js +29 -0
  179. package/dist/utils/index.cjs +55 -0
  180. package/dist/utils/index.d.cts +13 -0
  181. package/dist/utils/index.d.ts +13 -0
  182. package/dist/utils/index.js +50 -0
  183. package/dist/utils/messageFactory.cjs +137 -0
  184. package/dist/utils/messageFactory.d.cts +70 -0
  185. package/dist/utils/messageFactory.d.ts +70 -0
  186. package/dist/utils/messageFactory.js +132 -0
  187. package/dist/utils/multiPayload/webauthn.cjs +27 -0
  188. package/dist/utils/multiPayload/webauthn.js +26 -0
  189. package/dist/utils/near.cjs +58 -0
  190. package/dist/utils/near.d.cts +35 -0
  191. package/dist/utils/near.d.ts +35 -0
  192. package/dist/utils/near.js +53 -0
  193. package/dist/utils/poll.cjs +87 -0
  194. package/dist/utils/poll.d.cts +54 -0
  195. package/dist/utils/poll.d.ts +54 -0
  196. package/dist/utils/poll.js +85 -0
  197. package/dist/utils/prepareBroadcastRequest.cjs +98 -0
  198. package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
  199. package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
  200. package/dist/utils/prepareBroadcastRequest.js +90 -0
  201. package/dist/utils/promise/withTimeout.cjs +34 -0
  202. package/dist/utils/promise/withTimeout.d.cts +16 -0
  203. package/dist/utils/promise/withTimeout.d.ts +16 -0
  204. package/dist/utils/promise/withTimeout.js +34 -0
  205. package/dist/utils/request.cjs +100 -0
  206. package/dist/utils/request.d.cts +27 -0
  207. package/dist/utils/request.d.ts +27 -0
  208. package/dist/utils/request.js +99 -0
  209. package/dist/utils/requestShouldRetry.cjs +20 -0
  210. package/dist/utils/requestShouldRetry.js +20 -0
  211. package/dist/utils/retry.cjs +66 -0
  212. package/dist/utils/retry.d.cts +56 -0
  213. package/dist/utils/retry.d.ts +56 -0
  214. package/dist/utils/retry.js +64 -0
  215. package/dist/utils/rpc-endpoint.cjs +56 -0
  216. package/dist/utils/rpc-endpoint.d.cts +20 -0
  217. package/dist/utils/rpc-endpoint.d.ts +20 -0
  218. package/dist/utils/rpc-endpoint.js +54 -0
  219. package/dist/utils/serialize.cjs +82 -0
  220. package/dist/utils/serialize.d.cts +17 -0
  221. package/dist/utils/serialize.d.ts +17 -0
  222. package/dist/utils/serialize.js +81 -0
  223. package/dist/utils/stellarAddressToBytes.cjs +295 -0
  224. package/dist/utils/stellarAddressToBytes.js +294 -0
  225. package/dist/utils/token.cjs +8 -0
  226. package/dist/utils/token.js +7 -0
  227. package/dist/utils/tokenUtils.cjs +263 -0
  228. package/dist/utils/tokenUtils.d.cts +88 -0
  229. package/dist/utils/tokenUtils.d.ts +88 -0
  230. package/dist/utils/tokenUtils.js +238 -0
  231. package/dist/utils/tronAddressToHex.cjs +18 -0
  232. package/dist/utils/tronAddressToHex.js +17 -0
  233. package/dist/utils/uint8Array.cjs +15 -0
  234. package/dist/utils/uint8Array.d.cts +4 -0
  235. package/dist/utils/uint8Array.d.ts +4 -0
  236. package/dist/utils/uint8Array.js +14 -0
  237. package/dist/utils/webAuthn.cjs +58 -0
  238. package/dist/utils/webAuthn.js +56 -0
  239. package/dist/xrpl/index.cjs +13 -0
  240. package/dist/xrpl/index.d.cts +8 -0
  241. package/dist/xrpl/index.d.ts +8 -0
  242. package/dist/xrpl/index.js +8 -0
  243. package/dist/xrpl/xrplHttpClient/apis.cjs +28 -0
  244. package/dist/xrpl/xrplHttpClient/apis.d.cts +7 -0
  245. package/dist/xrpl/xrplHttpClient/apis.d.ts +7 -0
  246. package/dist/xrpl/xrplHttpClient/apis.js +27 -0
  247. package/dist/xrpl/xrplHttpClient/errors.cjs +27 -0
  248. package/dist/xrpl/xrplHttpClient/errors.d.cts +24 -0
  249. package/dist/xrpl/xrplHttpClient/errors.d.ts +24 -0
  250. package/dist/xrpl/xrplHttpClient/errors.js +26 -0
  251. package/dist/xrpl/xrplHttpClient/index.cjs +19 -0
  252. package/dist/xrpl/xrplHttpClient/index.d.cts +10 -0
  253. package/dist/xrpl/xrplHttpClient/index.d.ts +10 -0
  254. package/dist/xrpl/xrplHttpClient/index.js +14 -0
  255. package/dist/xrpl/xrplHttpClient/runtime.cjs +57 -0
  256. package/dist/xrpl/xrplHttpClient/runtime.js +55 -0
  257. package/dist/xrpl/xrplHttpClient/types.cjs +39 -0
  258. package/dist/xrpl/xrplHttpClient/types.d.cts +64 -0
  259. package/dist/xrpl/xrplHttpClient/types.d.ts +64 -0
  260. package/dist/xrpl/xrplHttpClient/types.js +35 -0
  261. package/package.json +59 -0
@@ -0,0 +1,137 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_config = require('../config.cjs');
3
+ const require_assert = require('./assert.cjs');
4
+ let _scure_base = require("@scure/base");
5
+ let _noble_hashes_sha256 = require("@noble/hashes/sha256");
6
+
7
+ //#region src/utils/messageFactory.ts
8
+ var messageFactory_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
9
+ makeChallenge: () => makeChallenge,
10
+ makeEmptyMessage: () => makeEmptyMessage,
11
+ makeInnerSwapMessage: () => makeInnerSwapMessage,
12
+ makeInnerTransferMessage: () => makeInnerTransferMessage,
13
+ makeSwapMessage: () => makeSwapMessage,
14
+ randomDefuseNonce: () => randomDefuseNonce
15
+ });
16
+ /**
17
+ * @param tokenDeltas
18
+ * @param signerId
19
+ * @param deadlineTimestamp Unix timestamp in milliseconds
20
+ * @param referral
21
+ * @param memo
22
+ * @param appFee
23
+ * @param appFeeRecipient
24
+ */
25
+ function makeInnerSwapMessage({ tokenDeltas, signerId, deadlineTimestamp, referral, memo, appFee, appFeeRecipient }) {
26
+ const tokenDiff = {};
27
+ const tokenDiffNum = {};
28
+ const intents = [{
29
+ intent: "token_diff",
30
+ diff: tokenDiff,
31
+ referral,
32
+ memo
33
+ }];
34
+ if (appFee.length) intents.push({
35
+ intent: "transfer",
36
+ tokens: Object.fromEntries(appFee.map(([token, amount]) => [token, amount.toString()])),
37
+ receiver_id: appFeeRecipient,
38
+ memo: "APP_FEE"
39
+ });
40
+ for (const [token, amount] of tokenDeltas) {
41
+ tokenDiffNum[token] ??= 0n;
42
+ tokenDiffNum[token] += amount;
43
+ tokenDiff[token] = tokenDiffNum[token].toString();
44
+ }
45
+ if (Object.keys(tokenDiff).length === 0) return {
46
+ deadline: new Date(deadlineTimestamp).toISOString(),
47
+ intents: [],
48
+ signer_id: signerId
49
+ };
50
+ return {
51
+ deadline: new Date(deadlineTimestamp).toISOString(),
52
+ intents,
53
+ signer_id: signerId
54
+ };
55
+ }
56
+ function makeSwapMessage({ innerMessage, nonce = randomDefuseNonce() }) {
57
+ const payload = {
58
+ signer_id: innerMessage.signer_id,
59
+ verifying_contract: require_config.config.env.contractID,
60
+ deadline: innerMessage.deadline,
61
+ nonce: _scure_base.base64.encode(nonce),
62
+ intents: innerMessage.intents
63
+ };
64
+ const payloadSerialized = JSON.stringify(payload);
65
+ const payloadBytes = new TextEncoder().encode(payloadSerialized);
66
+ return {
67
+ NEP413: {
68
+ message: JSON.stringify(innerMessage),
69
+ recipient: require_config.config.env.contractID,
70
+ nonce
71
+ },
72
+ ERC191: { message: JSON.stringify(payload, null, 2) },
73
+ SOLANA: { message: payloadBytes },
74
+ STELLAR: { message: JSON.stringify(payload, null, 2) },
75
+ WEBAUTHN: {
76
+ challenge: makeChallenge(payloadBytes),
77
+ payload: payloadSerialized,
78
+ parsedPayload: payload
79
+ },
80
+ TON_CONNECT: { message: {
81
+ type: "text",
82
+ text: JSON.stringify(payload, null, 2)
83
+ } },
84
+ TRON: { message: JSON.stringify(payload, null, 2) }
85
+ };
86
+ }
87
+ function makeEmptyMessage({ signerId, deadlineTimestamp, nonce = randomDefuseNonce() }) {
88
+ return makeSwapMessage({
89
+ innerMessage: {
90
+ deadline: new Date(deadlineTimestamp).toISOString(),
91
+ intents: [],
92
+ signer_id: signerId
93
+ },
94
+ nonce
95
+ });
96
+ }
97
+ function randomDefuseNonce() {
98
+ return randomBytes(32);
99
+ }
100
+ function randomBytes(length) {
101
+ return crypto.getRandomValues(new Uint8Array(length));
102
+ }
103
+ /**
104
+ * Converts UTF-8 string to bytes for WebAuthn challenge
105
+ */
106
+ function makeChallenge(payload) {
107
+ const hash = (0, _noble_hashes_sha256.sha256)(payload);
108
+ return new Uint8Array(hash);
109
+ }
110
+ function makeInnerTransferMessage({ tokenDeltas, signerId, deadlineTimestamp, receiverId, memo }) {
111
+ const tokens = {};
112
+ const seenTokens = /* @__PURE__ */ new Set();
113
+ for (const [token, amount] of tokenDeltas) {
114
+ require_assert.assert(!seenTokens.has(token), `Duplicate token found: ${token}`);
115
+ seenTokens.add(token);
116
+ require_assert.assert(amount > 0n, `Transfer amount must be positive, got: ${amount} for token ${token}`);
117
+ tokens[token] = amount.toString();
118
+ }
119
+ return {
120
+ deadline: new Date(deadlineTimestamp).toISOString(),
121
+ intents: [{
122
+ intent: "transfer",
123
+ tokens,
124
+ receiver_id: receiverId,
125
+ ...memo ? { memo } : {}
126
+ }],
127
+ signer_id: signerId
128
+ };
129
+ }
130
+
131
+ //#endregion
132
+ Object.defineProperty(exports, 'messageFactory_exports', {
133
+ enumerable: true,
134
+ get: function () {
135
+ return messageFactory_exports;
136
+ }
137
+ });
@@ -0,0 +1,70 @@
1
+ import { IntentsUserId } from "../types/intentsUserId.cjs";
2
+ import { WalletMessage } from "../types/walletMessage.cjs";
3
+ import { Nep413DefuseMessageFor_DefuseIntents } from "amogus-sdk-contract-types";
4
+
5
+ //#region src/utils/messageFactory.d.ts
6
+ declare namespace messageFactory_d_exports {
7
+ export { makeChallenge, makeEmptyMessage, makeInnerSwapMessage, makeInnerTransferMessage, makeSwapMessage, randomDefuseNonce };
8
+ }
9
+ /**
10
+ * @param tokenDeltas
11
+ * @param signerId
12
+ * @param deadlineTimestamp Unix timestamp in milliseconds
13
+ * @param referral
14
+ * @param memo
15
+ * @param appFee
16
+ * @param appFeeRecipient
17
+ */
18
+ declare function makeInnerSwapMessage({
19
+ tokenDeltas,
20
+ signerId,
21
+ deadlineTimestamp,
22
+ referral,
23
+ memo,
24
+ appFee,
25
+ appFeeRecipient
26
+ }: {
27
+ tokenDeltas: [string, bigint][];
28
+ signerId: IntentsUserId;
29
+ deadlineTimestamp: number;
30
+ referral?: string;
31
+ memo?: string;
32
+ appFee: [string, bigint][];
33
+ appFeeRecipient: string;
34
+ }): Nep413DefuseMessageFor_DefuseIntents;
35
+ declare function makeSwapMessage({
36
+ innerMessage,
37
+ nonce
38
+ }: {
39
+ innerMessage: Nep413DefuseMessageFor_DefuseIntents;
40
+ nonce?: Uint8Array;
41
+ }): WalletMessage;
42
+ declare function makeEmptyMessage({
43
+ signerId,
44
+ deadlineTimestamp,
45
+ nonce
46
+ }: {
47
+ signerId: IntentsUserId;
48
+ deadlineTimestamp: number;
49
+ nonce?: Uint8Array;
50
+ }): WalletMessage;
51
+ declare function randomDefuseNonce(): Uint8Array;
52
+ /**
53
+ * Converts UTF-8 string to bytes for WebAuthn challenge
54
+ */
55
+ declare function makeChallenge(payload: Uint8Array): Uint8Array;
56
+ declare function makeInnerTransferMessage({
57
+ tokenDeltas,
58
+ signerId,
59
+ deadlineTimestamp,
60
+ receiverId,
61
+ memo
62
+ }: {
63
+ tokenDeltas: [string, bigint][];
64
+ signerId: IntentsUserId;
65
+ deadlineTimestamp: number;
66
+ receiverId: string;
67
+ memo?: string;
68
+ }): Nep413DefuseMessageFor_DefuseIntents;
69
+ //#endregion
70
+ export { messageFactory_d_exports };
@@ -0,0 +1,70 @@
1
+ import { IntentsUserId } from "../types/intentsUserId.js";
2
+ import { WalletMessage } from "../types/walletMessage.js";
3
+ import { Nep413DefuseMessageFor_DefuseIntents } from "amogus-sdk-contract-types";
4
+
5
+ //#region src/utils/messageFactory.d.ts
6
+ declare namespace messageFactory_d_exports {
7
+ export { makeChallenge, makeEmptyMessage, makeInnerSwapMessage, makeInnerTransferMessage, makeSwapMessage, randomDefuseNonce };
8
+ }
9
+ /**
10
+ * @param tokenDeltas
11
+ * @param signerId
12
+ * @param deadlineTimestamp Unix timestamp in milliseconds
13
+ * @param referral
14
+ * @param memo
15
+ * @param appFee
16
+ * @param appFeeRecipient
17
+ */
18
+ declare function makeInnerSwapMessage({
19
+ tokenDeltas,
20
+ signerId,
21
+ deadlineTimestamp,
22
+ referral,
23
+ memo,
24
+ appFee,
25
+ appFeeRecipient
26
+ }: {
27
+ tokenDeltas: [string, bigint][];
28
+ signerId: IntentsUserId;
29
+ deadlineTimestamp: number;
30
+ referral?: string;
31
+ memo?: string;
32
+ appFee: [string, bigint][];
33
+ appFeeRecipient: string;
34
+ }): Nep413DefuseMessageFor_DefuseIntents;
35
+ declare function makeSwapMessage({
36
+ innerMessage,
37
+ nonce
38
+ }: {
39
+ innerMessage: Nep413DefuseMessageFor_DefuseIntents;
40
+ nonce?: Uint8Array;
41
+ }): WalletMessage;
42
+ declare function makeEmptyMessage({
43
+ signerId,
44
+ deadlineTimestamp,
45
+ nonce
46
+ }: {
47
+ signerId: IntentsUserId;
48
+ deadlineTimestamp: number;
49
+ nonce?: Uint8Array;
50
+ }): WalletMessage;
51
+ declare function randomDefuseNonce(): Uint8Array;
52
+ /**
53
+ * Converts UTF-8 string to bytes for WebAuthn challenge
54
+ */
55
+ declare function makeChallenge(payload: Uint8Array): Uint8Array;
56
+ declare function makeInnerTransferMessage({
57
+ tokenDeltas,
58
+ signerId,
59
+ deadlineTimestamp,
60
+ receiverId,
61
+ memo
62
+ }: {
63
+ tokenDeltas: [string, bigint][];
64
+ signerId: IntentsUserId;
65
+ deadlineTimestamp: number;
66
+ receiverId: string;
67
+ memo?: string;
68
+ }): Nep413DefuseMessageFor_DefuseIntents;
69
+ //#endregion
70
+ export { messageFactory_d_exports };
@@ -0,0 +1,132 @@
1
+ import { __exportAll } from "../_virtual/rolldown_runtime.js";
2
+ import { config } from "../config.js";
3
+ import { assert } from "./assert.js";
4
+ import { base64 } from "@scure/base";
5
+ import { sha256 } from "@noble/hashes/sha256";
6
+
7
+ //#region src/utils/messageFactory.ts
8
+ var messageFactory_exports = /* @__PURE__ */ __exportAll({
9
+ makeChallenge: () => makeChallenge,
10
+ makeEmptyMessage: () => makeEmptyMessage,
11
+ makeInnerSwapMessage: () => makeInnerSwapMessage,
12
+ makeInnerTransferMessage: () => makeInnerTransferMessage,
13
+ makeSwapMessage: () => makeSwapMessage,
14
+ randomDefuseNonce: () => randomDefuseNonce
15
+ });
16
+ /**
17
+ * @param tokenDeltas
18
+ * @param signerId
19
+ * @param deadlineTimestamp Unix timestamp in milliseconds
20
+ * @param referral
21
+ * @param memo
22
+ * @param appFee
23
+ * @param appFeeRecipient
24
+ */
25
+ function makeInnerSwapMessage({ tokenDeltas, signerId, deadlineTimestamp, referral, memo, appFee, appFeeRecipient }) {
26
+ const tokenDiff = {};
27
+ const tokenDiffNum = {};
28
+ const intents = [{
29
+ intent: "token_diff",
30
+ diff: tokenDiff,
31
+ referral,
32
+ memo
33
+ }];
34
+ if (appFee.length) intents.push({
35
+ intent: "transfer",
36
+ tokens: Object.fromEntries(appFee.map(([token, amount]) => [token, amount.toString()])),
37
+ receiver_id: appFeeRecipient,
38
+ memo: "APP_FEE"
39
+ });
40
+ for (const [token, amount] of tokenDeltas) {
41
+ tokenDiffNum[token] ??= 0n;
42
+ tokenDiffNum[token] += amount;
43
+ tokenDiff[token] = tokenDiffNum[token].toString();
44
+ }
45
+ if (Object.keys(tokenDiff).length === 0) return {
46
+ deadline: new Date(deadlineTimestamp).toISOString(),
47
+ intents: [],
48
+ signer_id: signerId
49
+ };
50
+ return {
51
+ deadline: new Date(deadlineTimestamp).toISOString(),
52
+ intents,
53
+ signer_id: signerId
54
+ };
55
+ }
56
+ function makeSwapMessage({ innerMessage, nonce = randomDefuseNonce() }) {
57
+ const payload = {
58
+ signer_id: innerMessage.signer_id,
59
+ verifying_contract: config.env.contractID,
60
+ deadline: innerMessage.deadline,
61
+ nonce: base64.encode(nonce),
62
+ intents: innerMessage.intents
63
+ };
64
+ const payloadSerialized = JSON.stringify(payload);
65
+ const payloadBytes = new TextEncoder().encode(payloadSerialized);
66
+ return {
67
+ NEP413: {
68
+ message: JSON.stringify(innerMessage),
69
+ recipient: config.env.contractID,
70
+ nonce
71
+ },
72
+ ERC191: { message: JSON.stringify(payload, null, 2) },
73
+ SOLANA: { message: payloadBytes },
74
+ STELLAR: { message: JSON.stringify(payload, null, 2) },
75
+ WEBAUTHN: {
76
+ challenge: makeChallenge(payloadBytes),
77
+ payload: payloadSerialized,
78
+ parsedPayload: payload
79
+ },
80
+ TON_CONNECT: { message: {
81
+ type: "text",
82
+ text: JSON.stringify(payload, null, 2)
83
+ } },
84
+ TRON: { message: JSON.stringify(payload, null, 2) }
85
+ };
86
+ }
87
+ function makeEmptyMessage({ signerId, deadlineTimestamp, nonce = randomDefuseNonce() }) {
88
+ return makeSwapMessage({
89
+ innerMessage: {
90
+ deadline: new Date(deadlineTimestamp).toISOString(),
91
+ intents: [],
92
+ signer_id: signerId
93
+ },
94
+ nonce
95
+ });
96
+ }
97
+ function randomDefuseNonce() {
98
+ return randomBytes(32);
99
+ }
100
+ function randomBytes(length) {
101
+ return crypto.getRandomValues(new Uint8Array(length));
102
+ }
103
+ /**
104
+ * Converts UTF-8 string to bytes for WebAuthn challenge
105
+ */
106
+ function makeChallenge(payload) {
107
+ const hash = sha256(payload);
108
+ return new Uint8Array(hash);
109
+ }
110
+ function makeInnerTransferMessage({ tokenDeltas, signerId, deadlineTimestamp, receiverId, memo }) {
111
+ const tokens = {};
112
+ const seenTokens = /* @__PURE__ */ new Set();
113
+ for (const [token, amount] of tokenDeltas) {
114
+ assert(!seenTokens.has(token), `Duplicate token found: ${token}`);
115
+ seenTokens.add(token);
116
+ assert(amount > 0n, `Transfer amount must be positive, got: ${amount} for token ${token}`);
117
+ tokens[token] = amount.toString();
118
+ }
119
+ return {
120
+ deadline: new Date(deadlineTimestamp).toISOString(),
121
+ intents: [{
122
+ intent: "transfer",
123
+ tokens,
124
+ receiver_id: receiverId,
125
+ ...memo ? { memo } : {}
126
+ }],
127
+ signer_id: signerId
128
+ };
129
+ }
130
+
131
+ //#endregion
132
+ export { messageFactory_exports };
@@ -0,0 +1,27 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_assert = require('../assert.cjs');
3
+ const require_webAuthn = require('../webAuthn.cjs');
4
+ let _scure_base = require("@scure/base");
5
+
6
+ //#region src/utils/multiPayload/webauthn.ts
7
+ function makeWebAuthnMultiPayload(userInfo, signature) {
8
+ require_assert.assert(userInfo.userChainType === "webauthn", "User chain and signature chain must match");
9
+ const { curveType, publicKey } = require_webAuthn.parsePublicKey(userInfo.userAddress);
10
+ return {
11
+ standard: "webauthn",
12
+ payload: signature.signedData.payload,
13
+ public_key: formatPublicKey(publicKey, curveType),
14
+ signature: formatSignature(require_webAuthn.extractRawSignature(signature.signatureData.signature, curveType), curveType),
15
+ client_data_json: new TextDecoder("utf-8").decode(signature.signatureData.clientDataJSON),
16
+ authenticator_data: _scure_base.base64urlnopad.encode(new Uint8Array(signature.signatureData.authenticatorData))
17
+ };
18
+ }
19
+ function formatPublicKey(publicKey, curveType) {
20
+ return `${curveType}:${_scure_base.base58.encode(publicKey)}`;
21
+ }
22
+ function formatSignature(signature, curveType) {
23
+ return `${curveType}:${_scure_base.base58.encode(new Uint8Array(signature))}`;
24
+ }
25
+
26
+ //#endregion
27
+ exports.makeWebAuthnMultiPayload = makeWebAuthnMultiPayload;
@@ -0,0 +1,26 @@
1
+ import { assert } from "../assert.js";
2
+ import { extractRawSignature, parsePublicKey } from "../webAuthn.js";
3
+ import { base58, base64urlnopad } from "@scure/base";
4
+
5
+ //#region src/utils/multiPayload/webauthn.ts
6
+ function makeWebAuthnMultiPayload(userInfo, signature) {
7
+ assert(userInfo.userChainType === "webauthn", "User chain and signature chain must match");
8
+ const { curveType, publicKey } = parsePublicKey(userInfo.userAddress);
9
+ return {
10
+ standard: "webauthn",
11
+ payload: signature.signedData.payload,
12
+ public_key: formatPublicKey(publicKey, curveType),
13
+ signature: formatSignature(extractRawSignature(signature.signatureData.signature, curveType), curveType),
14
+ client_data_json: new TextDecoder("utf-8").decode(signature.signatureData.clientDataJSON),
15
+ authenticator_data: base64urlnopad.encode(new Uint8Array(signature.signatureData.authenticatorData))
16
+ };
17
+ }
18
+ function formatPublicKey(publicKey, curveType) {
19
+ return `${curveType}:${base58.encode(publicKey)}`;
20
+ }
21
+ function formatSignature(signature, curveType) {
22
+ return `${curveType}:${base58.encode(new Uint8Array(signature))}`;
23
+ }
24
+
25
+ //#endregion
26
+ export { makeWebAuthnMultiPayload };
@@ -0,0 +1,58 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let valibot = require("valibot");
3
+ valibot = require_rolldown_runtime.__toESM(valibot);
4
+
5
+ //#region src/utils/near.ts
6
+ /**
7
+ * Use this function to decode a raw response from `nearClient.query()`
8
+ */
9
+ function decodeQueryResult(response, schema) {
10
+ const parsed = valibot.parse(valibot.object({ result: valibot.array(valibot.number()) }), response);
11
+ const uint8Array = new Uint8Array(parsed.result);
12
+ const result = new TextDecoder().decode(uint8Array);
13
+ return valibot.parse(schema, JSON.parse(result));
14
+ }
15
+ function getBlockReference({ blockId, finality }) {
16
+ if (blockId != null) return { blockId };
17
+ if (finality != null) return { finality };
18
+ return { finality: "optimistic" };
19
+ }
20
+ async function queryContract({ nearClient, contractId, methodName, args, blockId, finality, schema }) {
21
+ return decodeQueryResult(await nearClient.query({
22
+ request_type: "call_function",
23
+ account_id: contractId,
24
+ method_name: methodName,
25
+ args_base64: btoa(JSON.stringify(args)),
26
+ ...getBlockReference({
27
+ blockId,
28
+ finality
29
+ })
30
+ }), schema);
31
+ }
32
+ const ACCOUNT_ID_REGEX = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
33
+ const MIN_ACCOUNT_ID_LENGTH = 2;
34
+ const ETH_IMPLICIT_ACCOUNT_LENGTH = 42;
35
+ const NEAR_IMPLICIT_ACCOUNT_LENGTH = 64;
36
+ function validateNearAddress(accountId) {
37
+ if (accountId.length < MIN_ACCOUNT_ID_LENGTH || accountId.length > NEAR_IMPLICIT_ACCOUNT_LENGTH) return false;
38
+ if (isImplicitAccount(accountId)) return true;
39
+ return ACCOUNT_ID_REGEX.test(accountId);
40
+ }
41
+ function isEthImplicitAccount(accountId) {
42
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0x") && /^[0-9a-f]+$/.test(accountId.slice(2));
43
+ }
44
+ function isNearDeterministic(accountId) {
45
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0s") && /^[0-9a-f]+$/.test(accountId.slice(2));
46
+ }
47
+ function isNearImplicit(accountId) {
48
+ return accountId.length === NEAR_IMPLICIT_ACCOUNT_LENGTH && /^[0-9a-f]+$/.test(accountId);
49
+ }
50
+ function isImplicitAccount(accountId) {
51
+ return isEthImplicitAccount(accountId) || isNearImplicit(accountId) || isNearDeterministic(accountId);
52
+ }
53
+
54
+ //#endregion
55
+ exports.decodeQueryResult = decodeQueryResult;
56
+ exports.isImplicitAccount = isImplicitAccount;
57
+ exports.queryContract = queryContract;
58
+ exports.validateNearAddress = validateNearAddress;
@@ -0,0 +1,35 @@
1
+ import * as v from "valibot";
2
+ import { providers } from "near-api-js";
3
+ import { BlockId, Finality } from "near-api-js/lib/providers/provider";
4
+
5
+ //#region src/utils/near.d.ts
6
+
7
+ /**
8
+ * Use this function to decode a raw response from `nearClient.query()`
9
+ */
10
+ declare function decodeQueryResult<T extends v.BaseSchema<TInput, TOutput, TIssue>, TInput, TOutput, TIssue extends v.BaseIssue<unknown>>(response: unknown, schema: T): v.InferOutput<T>;
11
+ type OptionalBlockReference = {
12
+ blockId?: BlockId;
13
+ finality?: Finality;
14
+ };
15
+ declare function queryContract<T extends v.BaseSchema<TInput, TOutput, TIssue>, TInput, TOutput, TIssue extends v.BaseIssue<unknown>>({
16
+ nearClient,
17
+ contractId,
18
+ methodName,
19
+ args,
20
+ blockId,
21
+ finality,
22
+ schema
23
+ }: {
24
+ nearClient: providers.Provider;
25
+ contractId: string;
26
+ methodName: string;
27
+ args: Record<string, unknown>;
28
+ blockId?: BlockId;
29
+ finality?: Finality;
30
+ schema: T;
31
+ }): Promise<v.InferOutput<T>>;
32
+ declare function validateNearAddress(accountId: string): boolean;
33
+ declare function isImplicitAccount(accountId: string): boolean;
34
+ //#endregion
35
+ export { OptionalBlockReference, decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress };
@@ -0,0 +1,35 @@
1
+ import * as v from "valibot";
2
+ import { providers } from "near-api-js";
3
+ import { BlockId, Finality } from "near-api-js/lib/providers/provider";
4
+
5
+ //#region src/utils/near.d.ts
6
+
7
+ /**
8
+ * Use this function to decode a raw response from `nearClient.query()`
9
+ */
10
+ declare function decodeQueryResult<T extends v.BaseSchema<TInput, TOutput, TIssue>, TInput, TOutput, TIssue extends v.BaseIssue<unknown>>(response: unknown, schema: T): v.InferOutput<T>;
11
+ type OptionalBlockReference = {
12
+ blockId?: BlockId;
13
+ finality?: Finality;
14
+ };
15
+ declare function queryContract<T extends v.BaseSchema<TInput, TOutput, TIssue>, TInput, TOutput, TIssue extends v.BaseIssue<unknown>>({
16
+ nearClient,
17
+ contractId,
18
+ methodName,
19
+ args,
20
+ blockId,
21
+ finality,
22
+ schema
23
+ }: {
24
+ nearClient: providers.Provider;
25
+ contractId: string;
26
+ methodName: string;
27
+ args: Record<string, unknown>;
28
+ blockId?: BlockId;
29
+ finality?: Finality;
30
+ schema: T;
31
+ }): Promise<v.InferOutput<T>>;
32
+ declare function validateNearAddress(accountId: string): boolean;
33
+ declare function isImplicitAccount(accountId: string): boolean;
34
+ //#endregion
35
+ export { OptionalBlockReference, decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress };
@@ -0,0 +1,53 @@
1
+ import * as v from "valibot";
2
+
3
+ //#region src/utils/near.ts
4
+ /**
5
+ * Use this function to decode a raw response from `nearClient.query()`
6
+ */
7
+ function decodeQueryResult(response, schema) {
8
+ const parsed = v.parse(v.object({ result: v.array(v.number()) }), response);
9
+ const uint8Array = new Uint8Array(parsed.result);
10
+ const result = new TextDecoder().decode(uint8Array);
11
+ return v.parse(schema, JSON.parse(result));
12
+ }
13
+ function getBlockReference({ blockId, finality }) {
14
+ if (blockId != null) return { blockId };
15
+ if (finality != null) return { finality };
16
+ return { finality: "optimistic" };
17
+ }
18
+ async function queryContract({ nearClient, contractId, methodName, args, blockId, finality, schema }) {
19
+ return decodeQueryResult(await nearClient.query({
20
+ request_type: "call_function",
21
+ account_id: contractId,
22
+ method_name: methodName,
23
+ args_base64: btoa(JSON.stringify(args)),
24
+ ...getBlockReference({
25
+ blockId,
26
+ finality
27
+ })
28
+ }), schema);
29
+ }
30
+ const ACCOUNT_ID_REGEX = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
31
+ const MIN_ACCOUNT_ID_LENGTH = 2;
32
+ const ETH_IMPLICIT_ACCOUNT_LENGTH = 42;
33
+ const NEAR_IMPLICIT_ACCOUNT_LENGTH = 64;
34
+ function validateNearAddress(accountId) {
35
+ if (accountId.length < MIN_ACCOUNT_ID_LENGTH || accountId.length > NEAR_IMPLICIT_ACCOUNT_LENGTH) return false;
36
+ if (isImplicitAccount(accountId)) return true;
37
+ return ACCOUNT_ID_REGEX.test(accountId);
38
+ }
39
+ function isEthImplicitAccount(accountId) {
40
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0x") && /^[0-9a-f]+$/.test(accountId.slice(2));
41
+ }
42
+ function isNearDeterministic(accountId) {
43
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0s") && /^[0-9a-f]+$/.test(accountId.slice(2));
44
+ }
45
+ function isNearImplicit(accountId) {
46
+ return accountId.length === NEAR_IMPLICIT_ACCOUNT_LENGTH && /^[0-9a-f]+$/.test(accountId);
47
+ }
48
+ function isImplicitAccount(accountId) {
49
+ return isEthImplicitAccount(accountId) || isNearImplicit(accountId) || isNearDeterministic(accountId);
50
+ }
51
+
52
+ //#endregion
53
+ export { decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress };