lampamazaza-new-internal-utils 0.24.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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.js +18 -0
  4. package/dist/config.cjs +82 -0
  5. package/dist/config.d.cts +42 -0
  6. package/dist/config.d.ts +42 -0
  7. package/dist/config.js +72 -0
  8. package/dist/errors/assert.cjs +11 -0
  9. package/dist/errors/assert.d.cts +11 -0
  10. package/dist/errors/assert.d.ts +11 -0
  11. package/dist/errors/assert.js +11 -0
  12. package/dist/errors/base.cjs +34 -0
  13. package/dist/errors/base.d.cts +21 -0
  14. package/dist/errors/base.d.ts +21 -0
  15. package/dist/errors/base.js +33 -0
  16. package/dist/errors/index.cjs +23 -0
  17. package/dist/errors/index.d.cts +11 -0
  18. package/dist/errors/index.d.ts +11 -0
  19. package/dist/errors/index.js +18 -0
  20. package/dist/errors/request.cjs +48 -0
  21. package/dist/errors/request.d.cts +61 -0
  22. package/dist/errors/request.d.ts +61 -0
  23. package/dist/errors/request.js +46 -0
  24. package/dist/errors/utils/isNetworkError.cjs +23 -0
  25. package/dist/errors/utils/isNetworkError.js +22 -0
  26. package/dist/errors/utils/toError.cjs +8 -0
  27. package/dist/errors/utils/toError.d.cts +4 -0
  28. package/dist/errors/utils/toError.d.ts +4 -0
  29. package/dist/errors/utils/toError.js +7 -0
  30. package/dist/index.cjs +125 -0
  31. package/dist/index.d.cts +30 -0
  32. package/dist/index.d.ts +30 -0
  33. package/dist/index.js +30 -0
  34. package/dist/logger.d.cts +11 -0
  35. package/dist/logger.d.ts +11 -0
  36. package/dist/nearClient.cjs +18 -0
  37. package/dist/nearClient.d.cts +8 -0
  38. package/dist/nearClient.d.ts +8 -0
  39. package/dist/nearClient.js +18 -0
  40. package/dist/poaBridge/constants/blockchains.cjs +57 -0
  41. package/dist/poaBridge/constants/blockchains.d.cts +86 -0
  42. package/dist/poaBridge/constants/blockchains.d.ts +86 -0
  43. package/dist/poaBridge/constants/blockchains.js +54 -0
  44. package/dist/poaBridge/errors/withdrawal.cjs +52 -0
  45. package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
  46. package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
  47. package/dist/poaBridge/errors/withdrawal.js +50 -0
  48. package/dist/poaBridge/getPendingDeposits.cjs +9 -0
  49. package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
  50. package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
  51. package/dist/poaBridge/getPendingDeposits.js +9 -0
  52. package/dist/poaBridge/index.cjs +23 -0
  53. package/dist/poaBridge/index.d.cts +11 -0
  54. package/dist/poaBridge/index.d.ts +11 -0
  55. package/dist/poaBridge/index.js +18 -0
  56. package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
  57. package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
  58. package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
  59. package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
  60. package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
  61. package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
  62. package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
  63. package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
  64. package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
  65. package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
  66. package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
  67. package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
  68. package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
  69. package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
  70. package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
  71. package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
  72. package/dist/services/blockchainBalanceService.cjs +40 -0
  73. package/dist/services/blockchainBalanceService.d.cts +21 -0
  74. package/dist/services/blockchainBalanceService.d.ts +21 -0
  75. package/dist/services/blockchainBalanceService.js +37 -0
  76. package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
  77. package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
  78. package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
  79. package/dist/solverRelay/errors/intentSettlement.js +20 -0
  80. package/dist/solverRelay/errors/quote.cjs +18 -0
  81. package/dist/solverRelay/errors/quote.d.cts +21 -0
  82. package/dist/solverRelay/errors/quote.d.ts +22 -0
  83. package/dist/solverRelay/errors/quote.js +18 -0
  84. package/dist/solverRelay/getQuote.cjs +49 -0
  85. package/dist/solverRelay/getQuote.d.cts +14 -0
  86. package/dist/solverRelay/getQuote.d.ts +14 -0
  87. package/dist/solverRelay/getQuote.js +49 -0
  88. package/dist/solverRelay/getStatus.cjs +26 -0
  89. package/dist/solverRelay/getStatus.d.cts +17 -0
  90. package/dist/solverRelay/getStatus.d.ts +18 -0
  91. package/dist/solverRelay/getStatus.js +26 -0
  92. package/dist/solverRelay/index.cjs +27 -0
  93. package/dist/solverRelay/index.d.cts +16 -0
  94. package/dist/solverRelay/index.d.ts +16 -0
  95. package/dist/solverRelay/index.js +22 -0
  96. package/dist/solverRelay/publishIntent.cjs +20 -0
  97. package/dist/solverRelay/publishIntent.d.cts +15 -0
  98. package/dist/solverRelay/publishIntent.d.ts +16 -0
  99. package/dist/solverRelay/publishIntent.js +20 -0
  100. package/dist/solverRelay/publishIntents.cjs +43 -0
  101. package/dist/solverRelay/publishIntents.d.cts +10 -0
  102. package/dist/solverRelay/publishIntents.d.ts +11 -0
  103. package/dist/solverRelay/publishIntents.js +42 -0
  104. package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
  105. package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
  106. package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
  107. package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
  108. package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
  109. package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
  110. package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
  111. package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
  112. package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
  113. package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
  114. package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
  115. package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
  116. package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
  117. package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
  118. package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
  119. package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
  120. package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
  121. package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
  122. package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
  123. package/dist/solverRelay/utils/quoteWithLog.js +21 -0
  124. package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
  125. package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
  126. package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
  127. package/dist/solverRelay/waitForIntentSettlement.js +52 -0
  128. package/dist/types/authHandle.cjs +22 -0
  129. package/dist/types/authHandle.d.cts +25 -0
  130. package/dist/types/authHandle.d.ts +25 -0
  131. package/dist/types/authHandle.js +16 -0
  132. package/dist/types/base.d.cts +45 -0
  133. package/dist/types/base.d.ts +45 -0
  134. package/dist/types/intentsUserId.d.cts +10 -0
  135. package/dist/types/intentsUserId.d.ts +10 -0
  136. package/dist/types/walletMessage.cjs +11 -0
  137. package/dist/types/walletMessage.d.cts +106 -0
  138. package/dist/types/walletMessage.d.ts +106 -0
  139. package/dist/types/walletMessage.js +5 -0
  140. package/dist/utils/abortSignal.cjs +19 -0
  141. package/dist/utils/abortSignal.js +18 -0
  142. package/dist/utils/appFee.cjs +20 -0
  143. package/dist/utils/appFee.d.cts +9 -0
  144. package/dist/utils/appFee.d.ts +9 -0
  145. package/dist/utils/appFee.js +15 -0
  146. package/dist/utils/assert.cjs +9 -0
  147. package/dist/utils/assert.d.cts +7 -0
  148. package/dist/utils/assert.d.ts +7 -0
  149. package/dist/utils/assert.js +9 -0
  150. package/dist/utils/authIdentity.cjs +56 -0
  151. package/dist/utils/authIdentity.d.cts +34 -0
  152. package/dist/utils/authIdentity.d.ts +34 -0
  153. package/dist/utils/authIdentity.js +50 -0
  154. package/dist/utils/failover.cjs +22 -0
  155. package/dist/utils/failover.d.cts +16 -0
  156. package/dist/utils/failover.d.ts +16 -0
  157. package/dist/utils/failover.js +20 -0
  158. package/dist/utils/handleRPCResponse.cjs +30 -0
  159. package/dist/utils/handleRPCResponse.js +28 -0
  160. package/dist/utils/index.cjs +55 -0
  161. package/dist/utils/index.d.cts +13 -0
  162. package/dist/utils/index.d.ts +13 -0
  163. package/dist/utils/index.js +50 -0
  164. package/dist/utils/messageFactory.cjs +137 -0
  165. package/dist/utils/messageFactory.d.cts +70 -0
  166. package/dist/utils/messageFactory.d.ts +70 -0
  167. package/dist/utils/messageFactory.js +132 -0
  168. package/dist/utils/multiPayload/webauthn.cjs +27 -0
  169. package/dist/utils/multiPayload/webauthn.js +26 -0
  170. package/dist/utils/near.cjs +58 -0
  171. package/dist/utils/near.d.cts +35 -0
  172. package/dist/utils/near.d.ts +35 -0
  173. package/dist/utils/near.js +53 -0
  174. package/dist/utils/poll.cjs +87 -0
  175. package/dist/utils/poll.d.cts +54 -0
  176. package/dist/utils/poll.d.ts +54 -0
  177. package/dist/utils/poll.js +85 -0
  178. package/dist/utils/prepareBroadcastRequest.cjs +98 -0
  179. package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
  180. package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
  181. package/dist/utils/prepareBroadcastRequest.js +90 -0
  182. package/dist/utils/promise/withTimeout.cjs +34 -0
  183. package/dist/utils/promise/withTimeout.d.cts +16 -0
  184. package/dist/utils/promise/withTimeout.d.ts +16 -0
  185. package/dist/utils/promise/withTimeout.js +34 -0
  186. package/dist/utils/request.cjs +100 -0
  187. package/dist/utils/request.d.cts +27 -0
  188. package/dist/utils/request.d.ts +27 -0
  189. package/dist/utils/request.js +99 -0
  190. package/dist/utils/requestShouldRetry.cjs +20 -0
  191. package/dist/utils/requestShouldRetry.js +20 -0
  192. package/dist/utils/retry.cjs +66 -0
  193. package/dist/utils/retry.d.cts +56 -0
  194. package/dist/utils/retry.d.ts +56 -0
  195. package/dist/utils/retry.js +64 -0
  196. package/dist/utils/serialize.cjs +82 -0
  197. package/dist/utils/serialize.d.cts +17 -0
  198. package/dist/utils/serialize.d.ts +17 -0
  199. package/dist/utils/serialize.js +81 -0
  200. package/dist/utils/stellarAddressToBytes.cjs +295 -0
  201. package/dist/utils/stellarAddressToBytes.js +294 -0
  202. package/dist/utils/token.cjs +8 -0
  203. package/dist/utils/token.js +7 -0
  204. package/dist/utils/tokenUtils.cjs +263 -0
  205. package/dist/utils/tokenUtils.d.cts +88 -0
  206. package/dist/utils/tokenUtils.d.ts +88 -0
  207. package/dist/utils/tokenUtils.js +238 -0
  208. package/dist/utils/tronAddressToHex.cjs +18 -0
  209. package/dist/utils/tronAddressToHex.js +17 -0
  210. package/dist/utils/uint8Array.cjs +15 -0
  211. package/dist/utils/uint8Array.d.cts +4 -0
  212. package/dist/utils/uint8Array.d.ts +4 -0
  213. package/dist/utils/uint8Array.js +14 -0
  214. package/dist/utils/webAuthn.cjs +91 -0
  215. package/dist/utils/webAuthn.js +89 -0
  216. package/package.json +56 -0
@@ -0,0 +1,70 @@
1
+ import { IntentsUserId } from "../types/intentsUserId.cjs";
2
+ import { WalletMessage } from "../types/walletMessage.cjs";
3
+ import { Nep413DefuseMessageFor_DefuseIntents } from "lampamazaza-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 "lampamazaza-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]+$/i.test(accountId.slice(2));
43
+ }
44
+ function isNearDeterministic(accountId) {
45
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0s") && /^[0-9a-f]+$/i.test(accountId.slice(2));
46
+ }
47
+ function isNearImplicit(accountId) {
48
+ return accountId.length === NEAR_IMPLICIT_ACCOUNT_LENGTH && /^[0-9a-f]+$/i.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 { providers } from "near-api-js";
2
+ import { BlockId, Finality } from "near-api-js/lib/providers/provider";
3
+ import * as v from "valibot";
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]+$/i.test(accountId.slice(2));
41
+ }
42
+ function isNearDeterministic(accountId) {
43
+ return accountId.length === ETH_IMPLICIT_ACCOUNT_LENGTH && accountId.startsWith("0s") && /^[0-9a-f]+$/i.test(accountId.slice(2));
44
+ }
45
+ function isNearImplicit(accountId) {
46
+ return accountId.length === NEAR_IMPLICIT_ACCOUNT_LENGTH && /^[0-9a-f]+$/i.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 };
@@ -0,0 +1,87 @@
1
+ const require_base = require('../errors/base.cjs');
2
+
3
+ //#region src/utils/poll.ts
4
+ const PHASE = {
5
+ HOT: "HOT",
6
+ COOLING: "COOLING",
7
+ COLD: "COLD"
8
+ };
9
+ const DEFAULT_INTERVALS = {
10
+ [PHASE.HOT]: 300,
11
+ [PHASE.COOLING]: 3e3,
12
+ [PHASE.COLD]: 1e4
13
+ };
14
+ /**
15
+ * Sentinel value to signal that polling should continue.
16
+ * Return this from the poll function to indicate "not done yet".
17
+ */
18
+ const POLL_PENDING = Symbol("poll.pending");
19
+ var PollTimeoutError = class extends require_base.BaseError {
20
+ constructor(elapsedMs, timeoutMs) {
21
+ super("Polling timed out", { details: `Operation did not complete within ${timeoutMs}ms (elapsed: ${elapsedMs}ms)` });
22
+ this.elapsedMs = elapsedMs;
23
+ this.timeoutMs = timeoutMs;
24
+ this.name = "PollTimeoutError";
25
+ }
26
+ };
27
+ /**
28
+ * Polls a function using latency-optimized intervals.
29
+ *
30
+ * Polls aggressively early (when completion is most likely), backs off later
31
+ * for outliers. Optimized for latency-sensitive operations like swaps.
32
+ *
33
+ * Interval strategy:
34
+ * - 0 → p50: HOT (300ms) - most completions happen here (~50%)
35
+ * - p50 → p90: COOLING (3s) - moderate polling (~40%)
36
+ * - p90 → p99: COLD (10s) - back off for outliers (~9%)
37
+ *
38
+ * @param fn - Function to poll. Return POLL_PENDING to continue, any other value to complete.
39
+ * @param options - Polling configuration with completion stats
40
+ * @returns The resolved value from fn
41
+ * @throws PollTimeoutError when p99 is exceeded
42
+ * @throws AbortError when signal is aborted
43
+ */
44
+ async function poll(fn, options) {
45
+ const { stats, signal, minInterval = 300, maxInterval = 3e4 } = options;
46
+ const { p50, p90, p99 } = stats;
47
+ const startTime = performance.now();
48
+ while (true) {
49
+ signal?.throwIfAborted();
50
+ const elapsed = performance.now() - startTime;
51
+ if (elapsed >= p99) throw new PollTimeoutError(elapsed, p99);
52
+ const result = await fn();
53
+ if (result !== POLL_PENDING) return result;
54
+ const rawInterval = DEFAULT_INTERVALS[getPhase(elapsed, p50, p90)];
55
+ await sleep(clamp(rawInterval, minInterval, maxInterval), signal);
56
+ }
57
+ }
58
+ function getPhase(elapsed, p50, p90) {
59
+ if (elapsed < p50) return PHASE.HOT;
60
+ if (elapsed < p90) return PHASE.COOLING;
61
+ return PHASE.COLD;
62
+ }
63
+ function clamp(value, min, max) {
64
+ return Math.max(min, Math.min(max, value));
65
+ }
66
+ function sleep(ms, signal) {
67
+ return new Promise((resolve, reject) => {
68
+ if (signal?.aborted) {
69
+ reject(signal.reason);
70
+ return;
71
+ }
72
+ const abortHandler = () => {
73
+ clearTimeout(timeoutId);
74
+ reject(signal?.reason);
75
+ };
76
+ const timeoutId = setTimeout(() => {
77
+ signal?.removeEventListener("abort", abortHandler);
78
+ resolve();
79
+ }, ms);
80
+ signal?.addEventListener("abort", abortHandler);
81
+ });
82
+ }
83
+
84
+ //#endregion
85
+ exports.POLL_PENDING = POLL_PENDING;
86
+ exports.PollTimeoutError = PollTimeoutError;
87
+ exports.poll = poll;
@@ -0,0 +1,54 @@
1
+ import { BaseError } from "../errors/base.cjs";
2
+
3
+ //#region src/utils/poll.d.ts
4
+
5
+ /**
6
+ * Sentinel value to signal that polling should continue.
7
+ * Return this from the poll function to indicate "not done yet".
8
+ */
9
+ declare const POLL_PENDING: unique symbol;
10
+ type PollTimeoutErrorType = PollTimeoutError & {
11
+ name: "PollTimeoutError";
12
+ };
13
+ declare class PollTimeoutError extends BaseError {
14
+ elapsedMs: number;
15
+ timeoutMs: number;
16
+ name: "PollTimeoutError";
17
+ constructor(elapsedMs: number, timeoutMs: number);
18
+ }
19
+ interface CompletionStats {
20
+ /** 50th percentile (median completion time in ms) */
21
+ p50: number;
22
+ /** 90th percentile (in ms) */
23
+ p90: number;
24
+ /** 99th percentile - hard timeout (in ms) */
25
+ p99: number;
26
+ }
27
+ interface PollOptions {
28
+ stats: CompletionStats;
29
+ signal?: AbortSignal;
30
+ /** Minimum interval floor (default: 300ms) */
31
+ minInterval?: number;
32
+ /** Maximum interval ceiling (default: 30000ms) */
33
+ maxInterval?: number;
34
+ }
35
+ /**
36
+ * Polls a function using latency-optimized intervals.
37
+ *
38
+ * Polls aggressively early (when completion is most likely), backs off later
39
+ * for outliers. Optimized for latency-sensitive operations like swaps.
40
+ *
41
+ * Interval strategy:
42
+ * - 0 → p50: HOT (300ms) - most completions happen here (~50%)
43
+ * - p50 → p90: COOLING (3s) - moderate polling (~40%)
44
+ * - p90 → p99: COLD (10s) - back off for outliers (~9%)
45
+ *
46
+ * @param fn - Function to poll. Return POLL_PENDING to continue, any other value to complete.
47
+ * @param options - Polling configuration with completion stats
48
+ * @returns The resolved value from fn
49
+ * @throws PollTimeoutError when p99 is exceeded
50
+ * @throws AbortError when signal is aborted
51
+ */
52
+ declare function poll<T>(fn: () => Promise<T | typeof POLL_PENDING>, options: PollOptions): Promise<T>;
53
+ //#endregion
54
+ export { CompletionStats, POLL_PENDING, PollOptions, PollTimeoutError, PollTimeoutErrorType, poll };