@hot-labs/kit 1.1.3 → 1.2.0-alpha.1

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 (327) hide show
  1. package/README.md +9 -2
  2. package/package.json +4 -8
  3. package/src/HotConnector.ts +31 -24
  4. package/src/OmniConnector.ts +9 -10
  5. package/src/OmniWallet.ts +25 -24
  6. package/src/core/Intents.ts +151 -224
  7. package/src/core/api.ts +4 -44
  8. package/src/core/bridge.ts +2 -3
  9. package/src/core/index.ts +1 -1
  10. package/src/{near/rpc.ts → core/nearRpc.ts} +12 -7
  11. package/src/core/types.ts +0 -21
  12. package/src/core/utils.ts +1 -17
  13. package/src/cosmos/connector.ts +26 -22
  14. package/src/cosmos/wallet.ts +8 -3
  15. package/src/evm/connector.ts +0 -5
  16. package/src/evm/wallet.ts +6 -9
  17. package/src/exchange.ts +30 -24
  18. package/src/hot-wallet/google.ts +5 -12
  19. package/src/hot-wallet/proxy.ts +2 -2
  20. package/src/index.ts +0 -2
  21. package/src/near/connector.ts +2 -2
  22. package/src/near/wallet.ts +9 -4
  23. package/src/solana/connector.ts +8 -9
  24. package/src/solana/injected/solana-wallet.ts +6 -6
  25. package/src/solana/{WalletStandard.ts → protocol.ts} +4 -2
  26. package/src/solana/wallet.ts +20 -11
  27. package/src/stellar/connector.ts +6 -1
  28. package/src/stellar/wallet.ts +17 -17
  29. package/src/ton/connector.ts +5 -1
  30. package/src/ton/wallet.ts +3 -3
  31. package/src/ui/Popup.tsx +4 -12
  32. package/src/ui/connect/AuthPopup.tsx +1 -2
  33. package/src/ui/connect/ConnectWallet.tsx +6 -12
  34. package/src/ui/icons/arrow-right.tsx +2 -2
  35. package/src/ui/icons/close.tsx +1 -1
  36. package/src/ui/icons/exchange.tsx +4 -4
  37. package/src/ui/icons/logout.tsx +6 -6
  38. package/src/ui/icons/pending.tsx +4 -2
  39. package/src/ui/icons/qr.tsx +2 -1
  40. package/src/ui/icons/search.tsx +4 -4
  41. package/src/ui/icons/switch.tsx +4 -4
  42. package/src/ui/icons/wallet.tsx +4 -2
  43. package/src/ui/payment/Bridge.tsx +6 -25
  44. package/src/ui/payment/Payment.tsx +46 -244
  45. package/src/ui/payment/Profile.tsx +8 -10
  46. package/src/ui/payment/SelectToken.tsx +1 -1
  47. package/src/ui/payment/TokenCard.tsx +18 -22
  48. package/src/ui/router.tsx +16 -56
  49. package/src/ui/styles.ts +0 -2
  50. package/build/HotConnector.d.ts +0 -105
  51. package/build/HotConnector.js +0 -303
  52. package/build/HotConnector.js.map +0 -1
  53. package/build/OmniConnector.d.ts +0 -90
  54. package/build/OmniConnector.js +0 -121
  55. package/build/OmniConnector.js.map +0 -1
  56. package/build/OmniWallet.d.ts +0 -35
  57. package/build/OmniWallet.js +0 -56
  58. package/build/OmniWallet.js.map +0 -1
  59. package/build/activity.d.ts +0 -18
  60. package/build/activity.js +0 -87
  61. package/build/activity.js.map +0 -1
  62. package/build/core/Intents.d.ts +0 -100
  63. package/build/core/Intents.js +0 -474
  64. package/build/core/Intents.js.map +0 -1
  65. package/build/core/api.d.ts +0 -54
  66. package/build/core/api.js +0 -99
  67. package/build/core/api.js.map +0 -1
  68. package/build/core/bridge.d.ts +0 -3
  69. package/build/core/bridge.js +0 -36
  70. package/build/core/bridge.js.map +0 -1
  71. package/build/core/chains.d.ts +0 -115
  72. package/build/core/chains.js +0 -381
  73. package/build/core/chains.js.map +0 -1
  74. package/build/core/defaultTokens.d.ts +0 -17
  75. package/build/core/defaultTokens.js +0 -1079
  76. package/build/core/defaultTokens.js.map +0 -1
  77. package/build/core/events.d.ts +0 -42
  78. package/build/core/events.js +0 -64
  79. package/build/core/events.js.map +0 -1
  80. package/build/core/index.d.ts +0 -10
  81. package/build/core/index.js +0 -11
  82. package/build/core/index.js.map +0 -1
  83. package/build/core/recipient.d.ts +0 -10
  84. package/build/core/recipient.js +0 -40
  85. package/build/core/recipient.js.map +0 -1
  86. package/build/core/telemetry.d.ts +0 -13
  87. package/build/core/telemetry.js +0 -27
  88. package/build/core/telemetry.js.map +0 -1
  89. package/build/core/token.d.ts +0 -36
  90. package/build/core/token.js +0 -103
  91. package/build/core/token.js.map +0 -1
  92. package/build/core/tokens.d.ts +0 -14
  93. package/build/core/tokens.js +0 -59
  94. package/build/core/tokens.js.map +0 -1
  95. package/build/core/types.d.ts +0 -60
  96. package/build/core/types.js +0 -2
  97. package/build/core/types.js.map +0 -1
  98. package/build/core/utils.d.ts +0 -25
  99. package/build/core/utils.js +0 -170
  100. package/build/core/utils.js.map +0 -1
  101. package/build/cosmos/connector.d.ts +0 -36
  102. package/build/cosmos/connector.js +0 -211
  103. package/build/cosmos/connector.js.map +0 -1
  104. package/build/cosmos/helpers.d.ts +0 -2
  105. package/build/cosmos/helpers.js +0 -29
  106. package/build/cosmos/helpers.js.map +0 -1
  107. package/build/cosmos/index.d.ts +0 -6
  108. package/build/cosmos/index.js +0 -5
  109. package/build/cosmos/index.js.map +0 -1
  110. package/build/cosmos/wallet.d.ts +0 -26
  111. package/build/cosmos/wallet.js +0 -51
  112. package/build/cosmos/wallet.js.map +0 -1
  113. package/build/defaults.d.ts +0 -1
  114. package/build/defaults.js +0 -7
  115. package/build/defaults.js.map +0 -1
  116. package/build/evm/abi.d.ts +0 -17
  117. package/build/evm/abi.js +0 -38
  118. package/build/evm/abi.js.map +0 -1
  119. package/build/evm/connector.d.ts +0 -29
  120. package/build/evm/connector.js +0 -118
  121. package/build/evm/connector.js.map +0 -1
  122. package/build/evm/index.d.ts +0 -6
  123. package/build/evm/index.js +0 -5
  124. package/build/evm/index.js.map +0 -1
  125. package/build/evm/injected.d.ts +0 -1
  126. package/build/evm/injected.js +0 -33
  127. package/build/evm/injected.js.map +0 -1
  128. package/build/evm/wallet.d.ts +0 -42
  129. package/build/evm/wallet.js +0 -130
  130. package/build/evm/wallet.js.map +0 -1
  131. package/build/exchange.d.ts +0 -68
  132. package/build/exchange.js +0 -384
  133. package/build/exchange.js.map +0 -1
  134. package/build/hot-wallet/google.d.ts +0 -25
  135. package/build/hot-wallet/google.js +0 -117
  136. package/build/hot-wallet/google.js.map +0 -1
  137. package/build/hot-wallet/iframe.d.ts +0 -36
  138. package/build/hot-wallet/iframe.js +0 -140
  139. package/build/hot-wallet/iframe.js.map +0 -1
  140. package/build/hot-wallet/index.d.ts +0 -5
  141. package/build/hot-wallet/index.js +0 -4
  142. package/build/hot-wallet/index.js.map +0 -1
  143. package/build/hot-wallet/proxy.d.ts +0 -8
  144. package/build/hot-wallet/proxy.js +0 -45
  145. package/build/hot-wallet/proxy.js.map +0 -1
  146. package/build/index.d.ts +0 -6
  147. package/build/index.js +0 -7
  148. package/build/index.js.map +0 -1
  149. package/build/near/connector.d.ts +0 -18
  150. package/build/near/connector.js +0 -58
  151. package/build/near/connector.js.map +0 -1
  152. package/build/near/index.d.ts +0 -7
  153. package/build/near/index.js +0 -5
  154. package/build/near/index.js.map +0 -1
  155. package/build/near/rpc.d.ts +0 -23
  156. package/build/near/rpc.js +0 -162
  157. package/build/near/rpc.js.map +0 -1
  158. package/build/near/wallet.d.ts +0 -53
  159. package/build/near/wallet.js +0 -190
  160. package/build/near/wallet.js.map +0 -1
  161. package/build/solana/WalletStandard.d.ts +0 -25
  162. package/build/solana/WalletStandard.js +0 -56
  163. package/build/solana/WalletStandard.js.map +0 -1
  164. package/build/solana/connector.d.ts +0 -30
  165. package/build/solana/connector.js +0 -139
  166. package/build/solana/connector.js.map +0 -1
  167. package/build/solana/index.d.ts +0 -6
  168. package/build/solana/index.js +0 -5
  169. package/build/solana/index.js.map +0 -1
  170. package/build/solana/injected/account.d.ts +0 -11
  171. package/build/solana/injected/account.js +0 -41
  172. package/build/solana/injected/account.js.map +0 -1
  173. package/build/solana/injected/index.d.ts +0 -1
  174. package/build/solana/injected/index.js +0 -82
  175. package/build/solana/injected/index.js.map +0 -1
  176. package/build/solana/injected/register.d.ts +0 -2
  177. package/build/solana/injected/register.js +0 -41
  178. package/build/solana/injected/register.js.map +0 -1
  179. package/build/solana/injected/solana-wallet.d.ts +0 -34
  180. package/build/solana/injected/solana-wallet.js +0 -223
  181. package/build/solana/injected/solana-wallet.js.map +0 -1
  182. package/build/solana/injected/utils.d.ts +0 -32
  183. package/build/solana/injected/utils.js +0 -36
  184. package/build/solana/injected/utils.js.map +0 -1
  185. package/build/solana/wallet.d.ts +0 -40
  186. package/build/solana/wallet.js +0 -181
  187. package/build/solana/wallet.js.map +0 -1
  188. package/build/solana/walletStandartList.d.ts +0 -102
  189. package/build/solana/walletStandartList.js +0 -150
  190. package/build/solana/walletStandartList.js.map +0 -1
  191. package/build/stellar/connector.d.ts +0 -29
  192. package/build/stellar/connector.js +0 -64
  193. package/build/stellar/connector.js.map +0 -1
  194. package/build/stellar/freigher.d.ts +0 -46
  195. package/build/stellar/freigher.js +0 -110
  196. package/build/stellar/freigher.js.map +0 -1
  197. package/build/stellar/hotWallet.d.ts +0 -33
  198. package/build/stellar/hotWallet.js +0 -28
  199. package/build/stellar/hotWallet.js.map +0 -1
  200. package/build/stellar/index.d.ts +0 -6
  201. package/build/stellar/index.js +0 -5
  202. package/build/stellar/index.js.map +0 -1
  203. package/build/stellar/wallet.d.ts +0 -67
  204. package/build/stellar/wallet.js +0 -212
  205. package/build/stellar/wallet.js.map +0 -1
  206. package/build/storage.d.ts +0 -10
  207. package/build/storage.js +0 -12
  208. package/build/storage.js.map +0 -1
  209. package/build/ton/connector.d.ts +0 -24
  210. package/build/ton/connector.js +0 -111
  211. package/build/ton/connector.js.map +0 -1
  212. package/build/ton/index.d.ts +0 -7
  213. package/build/ton/index.js +0 -5
  214. package/build/ton/index.js.map +0 -1
  215. package/build/ton/injected.d.ts +0 -1
  216. package/build/ton/injected.js +0 -49
  217. package/build/ton/injected.js.map +0 -1
  218. package/build/ton/utils.d.ts +0 -45
  219. package/build/ton/utils.js +0 -63
  220. package/build/ton/utils.js.map +0 -1
  221. package/build/ton/wallet.d.ts +0 -54
  222. package/build/ton/wallet.js +0 -138
  223. package/build/ton/wallet.js.map +0 -1
  224. package/build/tron/connector.d.ts +0 -51
  225. package/build/tron/connector.js +0 -65
  226. package/build/tron/connector.js.map +0 -1
  227. package/build/tron/index.d.ts +0 -6
  228. package/build/tron/index.js +0 -5
  229. package/build/tron/index.js.map +0 -1
  230. package/build/tron/wallet.d.ts +0 -52
  231. package/build/tron/wallet.js +0 -122
  232. package/build/tron/wallet.js.map +0 -1
  233. package/build/ui/Popup.d.ts +0 -12
  234. package/build/ui/Popup.js +0 -43
  235. package/build/ui/Popup.js.map +0 -1
  236. package/build/ui/Toast.d.ts +0 -4
  237. package/build/ui/Toast.js +0 -33
  238. package/build/ui/Toast.js.map +0 -1
  239. package/build/ui/connect/AuthPopup.d.ts +0 -2
  240. package/build/ui/connect/AuthPopup.js +0 -48
  241. package/build/ui/connect/AuthPopup.js.map +0 -1
  242. package/build/ui/connect/ConnectWallet.d.ts +0 -14
  243. package/build/ui/connect/ConnectWallet.js +0 -22
  244. package/build/ui/connect/ConnectWallet.js.map +0 -1
  245. package/build/ui/connect/LogoutPopup.d.ts +0 -10
  246. package/build/ui/connect/LogoutPopup.js +0 -8
  247. package/build/ui/connect/LogoutPopup.js.map +0 -1
  248. package/build/ui/connect/PrimaryWallet.d.ts +0 -6
  249. package/build/ui/connect/PrimaryWallet.js +0 -18
  250. package/build/ui/connect/PrimaryWallet.js.map +0 -1
  251. package/build/ui/connect/WCPopup.d.ts +0 -13
  252. package/build/ui/connect/WCPopup.js +0 -81
  253. package/build/ui/connect/WCPopup.js.map +0 -1
  254. package/build/ui/connect/WCRequest.d.ts +0 -9
  255. package/build/ui/connect/WCRequest.js +0 -13
  256. package/build/ui/connect/WCRequest.js.map +0 -1
  257. package/build/ui/connect/WalletPicker.d.ts +0 -11
  258. package/build/ui/connect/WalletPicker.js +0 -48
  259. package/build/ui/connect/WalletPicker.js.map +0 -1
  260. package/build/ui/icons/arrow-right.d.ts +0 -1
  261. package/build/ui/icons/arrow-right.js +0 -5
  262. package/build/ui/icons/arrow-right.js.map +0 -1
  263. package/build/ui/icons/close.d.ts +0 -1
  264. package/build/ui/icons/close.js +0 -5
  265. package/build/ui/icons/close.js.map +0 -1
  266. package/build/ui/icons/exchange.d.ts +0 -6
  267. package/build/ui/icons/exchange.js +0 -6
  268. package/build/ui/icons/exchange.js.map +0 -1
  269. package/build/ui/icons/logout.d.ts +0 -1
  270. package/build/ui/icons/logout.js +0 -3
  271. package/build/ui/icons/logout.js.map +0 -1
  272. package/build/ui/icons/pending.d.ts +0 -1
  273. package/build/ui/icons/pending.js +0 -5
  274. package/build/ui/icons/pending.js.map +0 -1
  275. package/build/ui/icons/qr.d.ts +0 -1
  276. package/build/ui/icons/qr.js +0 -5
  277. package/build/ui/icons/qr.js.map +0 -1
  278. package/build/ui/icons/search.d.ts +0 -1
  279. package/build/ui/icons/search.js +0 -5
  280. package/build/ui/icons/search.js.map +0 -1
  281. package/build/ui/icons/switch.d.ts +0 -1
  282. package/build/ui/icons/switch.js +0 -5
  283. package/build/ui/icons/switch.js.map +0 -1
  284. package/build/ui/icons/wallet.d.ts +0 -1
  285. package/build/ui/icons/wallet.js +0 -5
  286. package/build/ui/icons/wallet.js.map +0 -1
  287. package/build/ui/payment/Bridge.d.ts +0 -29
  288. package/build/ui/payment/Bridge.js +0 -373
  289. package/build/ui/payment/Bridge.js.map +0 -1
  290. package/build/ui/payment/DepositQR.d.ts +0 -9
  291. package/build/ui/payment/DepositQR.js +0 -56
  292. package/build/ui/payment/DepositQR.js.map +0 -1
  293. package/build/ui/payment/Payment.d.ts +0 -23
  294. package/build/ui/payment/Payment.js +0 -139
  295. package/build/ui/payment/Payment.js.map +0 -1
  296. package/build/ui/payment/Profile.d.ts +0 -8
  297. package/build/ui/payment/Profile.js +0 -110
  298. package/build/ui/payment/Profile.js.map +0 -1
  299. package/build/ui/payment/SelectRecipient.d.ts +0 -14
  300. package/build/ui/payment/SelectRecipient.js +0 -68
  301. package/build/ui/payment/SelectRecipient.js.map +0 -1
  302. package/build/ui/payment/SelectSender.d.ts +0 -13
  303. package/build/ui/payment/SelectSender.js +0 -23
  304. package/build/ui/payment/SelectSender.js.map +0 -1
  305. package/build/ui/payment/SelectToken.d.ts +0 -13
  306. package/build/ui/payment/SelectToken.js +0 -92
  307. package/build/ui/payment/SelectToken.js.map +0 -1
  308. package/build/ui/payment/Stepper.d.ts +0 -13
  309. package/build/ui/payment/Stepper.js +0 -22
  310. package/build/ui/payment/Stepper.js.map +0 -1
  311. package/build/ui/payment/TokenCard.d.ts +0 -25
  312. package/build/ui/payment/TokenCard.js +0 -63
  313. package/build/ui/payment/TokenCard.js.map +0 -1
  314. package/build/ui/router.d.ts +0 -51
  315. package/build/ui/router.js +0 -68
  316. package/build/ui/router.js.map +0 -1
  317. package/build/ui/styles.d.ts +0 -13
  318. package/build/ui/styles.js +0 -290
  319. package/build/ui/styles.js.map +0 -1
  320. package/src/core/telemetry.ts +0 -28
  321. package/src/tron/connector.ts +0 -89
  322. package/src/tron/index.ts +0 -7
  323. package/src/tron/wallet.ts +0 -146
  324. package/src/ui/Toast.tsx +0 -45
  325. package/src/ui/connect/PrimaryWallet.tsx +0 -65
  326. package/src/ui/payment/Stepper.tsx +0 -50
  327. /package/src/solana/{walletStandartList.ts → wallets.ts} +0 -0
@@ -1,17 +1,14 @@
1
1
  import { sha256 } from "@noble/hashes/sha2.js";
2
+ import { ed25519 } from "@noble/curves/ed25519";
3
+ import { base58, base64, hex } from "@scure/base";
2
4
 
3
5
  import type { HotConnector } from "../HotConnector";
4
6
  import type { OmniWallet } from "../OmniWallet";
5
- import { rpc } from "../near/rpc";
7
+ import type { TransferIntent, MtWithdrawIntent, FtWithdrawIntent, TokenDiffIntent, AuthCallIntent } from "./types";
6
8
 
7
- import type { Intent, Commitment, TokenDiffIntent, MtWithdrawIntent, FtWithdrawIntent, NftWithdrawIntent, TransferIntent } from "./types";
8
9
  import { OmniToken } from "./chains";
9
10
  import { tokens } from "./tokens";
10
- import { api } from "./api";
11
-
12
- import { openConnector, openConnectPrimaryWallet, openPayment, openToast } from "../ui/router";
13
- import { formatter } from "./utils";
14
- import { BridgeReview } from "../exchange";
11
+ import { rpc } from "./nearRpc";
15
12
 
16
13
  export const TGAS = 1000000000000n;
17
14
 
@@ -22,22 +19,14 @@ export class Intents {
22
19
  return new Intents();
23
20
  }
24
21
 
25
- signedHashes: string[] = [];
26
- commitments: Commitment[] = [];
27
- need = new Map<OmniToken, bigint>();
28
- signer?: OmniWallet;
29
-
30
- unsignedCommitment?: {
31
- intents: Intent[];
32
- nonce?: Uint8Array;
33
- deadline?: Date;
34
- };
22
+ hashes: string[] = [];
23
+ intents: (TransferIntent | MtWithdrawIntent | FtWithdrawIntent | TokenDiffIntent | AuthCallIntent)[] = [];
24
+ nonce?: Uint8Array;
25
+ deadline?: Date;
26
+ signer?: OmniWallet | { ed25519PrivateKey: Uint8Array; omniAddress?: string };
35
27
 
36
- addIntent(intent: Intent) {
37
- if (!this.unsignedCommitment) this.unsignedCommitment = { intents: [] };
38
- this.unsignedCommitment.intents.push(intent);
39
- return this;
40
- }
28
+ commitments: Record<string, any>[] = [];
29
+ need = new Map<OmniToken, bigint>();
41
30
 
42
31
  addNeed(token: OmniToken, amount: bigint) {
43
32
  if (!this.need.has(token)) this.need.set(token, 0n);
@@ -47,7 +36,7 @@ export class Intents {
47
36
 
48
37
  authCall(args: { contractId: string; msg: string; attachNear: bigint; tgas: number }) {
49
38
  this.addNeed(OmniToken.NEAR, args.attachNear);
50
- this.addIntent({
39
+ this.intents.push({
51
40
  min_gas: (BigInt(args.tgas) * TGAS).toString(),
52
41
  attached_deposit: args.attachNear.toString(),
53
42
  contract_id: args.contractId,
@@ -58,22 +47,6 @@ export class Intents {
58
47
  return this;
59
48
  }
60
49
 
61
- /**
62
- * Use this method to pay for a merchant's item created in pay.hot-labs.org
63
- */
64
- merchantPayment({ merchantId, token, itemId, email, amount, memo }: { token: OmniToken; merchantId: string; itemId: string; amount: number | bigint; memo: string; email: string }) {
65
- return this.transfer({
66
- msg: JSON.stringify({ merchant_id: merchantId, item_id: itemId, memo: memo }),
67
- recipient: "pay.fi.tg",
68
- amount,
69
- token,
70
- }).depositAndExecute({
71
- title: `Pay ${this.wibe3?.omni(token).readable(amount)} ${this.wibe3?.omni(token).symbol}`,
72
- serverSideProcessing: true,
73
- payload: { email },
74
- });
75
- }
76
-
77
50
  transfer(args: { recipient: string; token: OmniToken; amount: number | bigint; memo?: string; msg?: string; tgas?: number }) {
78
51
  const omniToken = tokens.get(args.token);
79
52
  const amount = (typeof args.amount === "number" ? omniToken.int(args.amount) : args.amount).toString();
@@ -87,7 +60,7 @@ export class Intents {
87
60
  };
88
61
 
89
62
  this.addNeed(args.token, BigInt(amount));
90
- this.addIntent(intent);
63
+ this.intents.push(intent);
91
64
  return this;
92
65
  }
93
66
 
@@ -109,11 +82,11 @@ export class Intents {
109
82
  msg: args.msg,
110
83
  };
111
84
 
112
- this.addIntent(intent);
85
+ this.intents.push(intent);
113
86
  return this;
114
87
  }
115
88
 
116
- tokenDiff(args: Record<string, bigint | number>) {
89
+ tokenDiff(args: Record<OmniToken, bigint | number>) {
117
90
  const parse = (token: OmniToken, amount: bigint | number): [string, string] => {
118
91
  if (typeof amount === "number") return [token.toString(), tokens.get(token).int(amount).toString()];
119
92
  return [token.toString(), amount.toString()];
@@ -132,44 +105,45 @@ export class Intents {
132
105
  }
133
106
  }
134
107
 
135
- this.addIntent(intent);
108
+ this.intents.push(intent);
136
109
  return this;
137
110
  }
138
111
 
139
- addRawIntent(rawIntent: Intent) {
112
+ addRawIntent(rawIntent: Record<string, any>) {
140
113
  if (!rawIntent.intent) throw new Error("Intent must have 'intent' field");
141
114
  const intentType = rawIntent.intent;
142
115
 
143
116
  if (intentType === "token_diff") {
117
+ const diff = rawIntent.diff || rawIntent.token_diff;
118
+ if (!diff) throw new Error("token_diff intent must have 'diff' or 'token_diff' field");
119
+
144
120
  const tokenDiffArgs: Record<OmniToken, bigint> = {} as Record<OmniToken, bigint>;
145
- for (const [token, amountStr] of Object.entries(rawIntent.diff)) {
121
+ for (const [token, amountStr] of Object.entries(diff)) {
146
122
  tokenDiffArgs[token as OmniToken] = BigInt(amountStr as string);
147
123
  }
148
124
  return this.tokenDiff(tokenDiffArgs);
149
125
  }
150
126
 
151
127
  if (intentType === "transfer") {
128
+ if (!rawIntent.tokens || !rawIntent.receiver_id) {
129
+ throw new Error("transfer intent must have 'tokens' and 'receiver_id' fields");
130
+ }
131
+
152
132
  const tokens: Record<OmniToken, bigint> = {} as Record<OmniToken, bigint>;
153
133
  for (const [token, amount] of Object.entries(rawIntent.tokens)) {
154
134
  tokens[token as OmniToken] = BigInt(amount as string);
155
135
  }
156
-
157
136
  return this.batchTransfer({
158
- tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
159
137
  recipient: rawIntent.receiver_id,
138
+ tokens,
160
139
  memo: rawIntent.memo,
161
140
  msg: rawIntent.msg,
162
- tokens,
141
+ tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
163
142
  });
164
143
  }
165
144
 
166
145
  if (intentType === "mt_withdraw") {
167
- for (let i = 0; i < rawIntent.amounts.length; i++) {
168
- const token = `nep245:${rawIntent.token}:${rawIntent.token_ids[i]}` as OmniToken;
169
- this.addNeed(token, BigInt(rawIntent.amounts[i]));
170
- }
171
-
172
- this.addIntent({
146
+ const intent: MtWithdrawIntent = {
173
147
  intent: "mt_withdraw",
174
148
  amounts: rawIntent.amounts,
175
149
  receiver_id: rawIntent.receiver_id,
@@ -178,71 +152,58 @@ export class Intents {
178
152
  memo: rawIntent.memo,
179
153
  msg: rawIntent.msg,
180
154
  min_gas: rawIntent.min_gas,
181
- } as MtWithdrawIntent);
155
+ };
156
+
157
+ for (let i = 0; i < rawIntent.amounts.length; i++) {
158
+ const token = `nep245:${rawIntent.token}:${rawIntent.token_ids[i]}` as OmniToken;
159
+ this.addNeed(token, BigInt(rawIntent.amounts[i]));
160
+ }
161
+
162
+ this.intents.push(intent);
182
163
  return this;
183
164
  }
184
165
 
185
166
  if (intentType === "ft_withdraw") {
167
+ if (!rawIntent.token || !rawIntent.receiver_id || !rawIntent.amount) {
168
+ throw new Error("ft_withdraw intent must have 'token', 'receiver_id', and 'amount' fields");
169
+ }
170
+
171
+ const token = `nep141:${rawIntent.token}` as OmniToken;
186
172
  return this.withdraw({
187
- token: `nep141:${rawIntent.token}`,
188
173
  amount: BigInt(rawIntent.amount),
189
174
  receiver: rawIntent.receiver_id,
190
175
  memo: rawIntent.memo,
191
176
  msg: rawIntent.msg,
177
+ token,
192
178
  });
193
179
  }
194
180
 
195
181
  if (intentType === "auth_call") {
182
+ if (!rawIntent.contract_id || !rawIntent.msg || !rawIntent.attached_deposit || !rawIntent.min_gas) {
183
+ throw new Error("auth_call intent must have 'contract_id', 'msg', 'attached_deposit', and 'min_gas' fields");
184
+ }
185
+
196
186
  return this.authCall({
197
- attachNear: BigInt(rawIntent.attached_deposit),
198
- tgas: Number(BigInt(rawIntent.min_gas) / TGAS),
199
187
  contractId: rawIntent.contract_id,
200
188
  msg: rawIntent.msg,
201
- });
202
- }
203
-
204
- if (intentType === "add_public_key") {
205
- return this.addPublicKey(rawIntent.public_key);
206
- }
207
-
208
- if (intentType === "remove_public_key") {
209
- return this.removePublicKey(rawIntent.public_key);
210
- }
211
-
212
- if (intentType === "nft_withdraw") {
213
- return this.withdraw({
214
- token: rawIntent.token_id,
215
- receiver: rawIntent.receiver_id,
216
- memo: rawIntent.memo,
217
- msg: rawIntent.msg,
218
- tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
219
- amount: 1n,
189
+ attachNear: BigInt(rawIntent.attached_deposit),
190
+ tgas: Number(BigInt(rawIntent.min_gas) / TGAS),
220
191
  });
221
192
  }
222
193
 
223
194
  throw new Error(`Unsupported intent type: ${intentType}`);
224
195
  }
225
196
 
226
- addPublicKey(publicKey: string) {
227
- this.addIntent({ intent: "add_public_key", public_key: publicKey });
228
- return this;
229
- }
230
-
231
- removePublicKey(publicKey: string) {
232
- this.addIntent({ intent: "remove_public_key", public_key: publicKey });
233
- return this;
234
- }
235
-
236
- withdraw(args: { token: string; amount: number | bigint; receiver: string; memo?: string; msg?: string; tgas?: number }) {
197
+ withdraw(args: { token: OmniToken; amount: number | bigint; receiver: string; memo?: string; msg?: string; tgas?: number }) {
237
198
  const omniToken = tokens.get(args.token);
238
199
  const amount = (typeof args.amount === "number" ? omniToken.int(args.amount) : args.amount).toString();
239
200
  const [standart, ...tokenParts] = args.token.split(":");
240
- this.addNeed(args.token as OmniToken, BigInt(amount));
201
+ this.addNeed(args.token, BigInt(amount));
241
202
 
242
203
  if (standart === "nep245") {
243
204
  const mtContract = tokenParts[0];
244
205
  const tokenId = tokenParts.slice(1).join(":");
245
- this.addIntent({
206
+ const intent: MtWithdrawIntent = {
246
207
  intent: "mt_withdraw",
247
208
  amounts: [amount],
248
209
  receiver_id: args.receiver,
@@ -251,31 +212,23 @@ export class Intents {
251
212
  memo: args.memo,
252
213
  msg: args.msg,
253
214
  min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
254
- } as MtWithdrawIntent);
215
+ };
216
+
217
+ this.intents.push(intent);
255
218
  return this;
256
219
  }
257
220
 
258
221
  if (standart === "nep141") {
259
- this.addIntent({
222
+ const intent: FtWithdrawIntent = {
260
223
  intent: "ft_withdraw",
261
224
  receiver_id: args.receiver,
262
225
  token: tokenParts.join(":"),
263
226
  amount: amount,
264
227
  memo: args.memo,
265
228
  msg: args.msg,
266
- } as FtWithdrawIntent);
267
- return this;
268
- }
229
+ };
269
230
 
270
- if (standart === "nep171") {
271
- this.addIntent({
272
- intent: "nft_withdraw",
273
- receiver_id: args.receiver,
274
- token_id: tokenParts.join(":"),
275
- min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
276
- memo: args.memo,
277
- msg: args.msg,
278
- } as NftWithdrawIntent);
231
+ this.intents.push(intent);
279
232
  return this;
280
233
  }
281
234
 
@@ -283,190 +236,164 @@ export class Intents {
283
236
  }
284
237
 
285
238
  attachHashes(hashes: string[]) {
286
- this.signedHashes.push(...hashes);
239
+ this.hashes.push(...hashes);
287
240
  return this;
288
241
  }
289
242
 
290
- attachWallet(wallet?: OmniWallet) {
243
+ attachWallet(wallet: OmniWallet) {
291
244
  this.signer = wallet;
292
245
  return this;
293
246
  }
294
247
 
295
248
  attachDeadline(deadline: Date) {
296
- if (!this.unsignedCommitment) this.unsignedCommitment = { intents: [] };
297
- this.unsignedCommitment.deadline = deadline;
249
+ this.deadline = deadline;
298
250
  return this;
299
251
  }
300
252
 
301
253
  attachNonce(nonce: Uint8Array) {
302
- if (!this.unsignedCommitment) this.unsignedCommitment = { intents: [] };
303
- this.unsignedCommitment.nonce = nonce;
254
+ this.nonce = nonce;
304
255
  return this;
305
256
  }
306
257
 
307
258
  attachTimeout(seconds: number) {
308
- if (!this.unsignedCommitment) this.unsignedCommitment = { intents: [] };
309
- this.unsignedCommitment.deadline = new Date(Date.now() + seconds * 1000);
259
+ this.deadline = new Date(Date.now() + seconds * 1000);
310
260
  return this;
311
261
  }
312
262
 
313
263
  attachSeed(seed: string) {
314
- if (!this.unsignedCommitment) this.unsignedCommitment = { intents: [] };
315
- this.unsignedCommitment.nonce = new Uint8Array(sha256(new TextEncoder().encode(seed))).slice(0, 32);
316
- return this;
317
- }
318
-
319
- attachCommitment(commitment: Commitment) {
320
- this.commitments.push(commitment);
264
+ this.nonce = new Uint8Array(sha256(new TextEncoder().encode(seed))).slice(0, 32);
321
265
  return this;
322
266
  }
323
267
 
324
- take(token: string, amount: number | bigint) {
268
+ take(token: OmniToken, amount: number | bigint) {
325
269
  const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
326
270
 
327
- // this.addNeed(token, -intAmount); Do we need to add the need here?
328
- const tokenDiff = this.unsignedCommitment?.intents.find((intent) => intent.intent === "token_diff");
271
+ this.addNeed(token, intAmount);
272
+ const tokenDiff = this.intents.find((intent) => intent.intent === "token_diff");
329
273
 
330
274
  if (tokenDiff) tokenDiff.diff[token.toString()] = intAmount.toString();
331
- else this.addIntent({ intent: "token_diff", diff: { [token.toString()]: intAmount.toString() } });
275
+ else this.intents.push({ intent: "token_diff", diff: { [token.toString()]: intAmount.toString() } });
332
276
  return this;
333
277
  }
334
278
 
335
- give(token: string, amount: number | bigint) {
279
+ give(token: OmniToken, amount: number | bigint) {
336
280
  const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
337
281
 
338
- this.addNeed(token as OmniToken, intAmount);
339
- const tokenDiff = this.unsignedCommitment?.intents.find((intent) => intent.intent === "token_diff");
282
+ this.addNeed(token, -intAmount);
283
+ const tokenDiff = this.intents.find((intent) => intent.intent === "token_diff");
340
284
 
341
285
  if (tokenDiff) tokenDiff.diff[token.toString()] = (-intAmount).toString();
342
- else this.addIntent({ intent: "token_diff", diff: { [token.toString()]: (-intAmount).toString() } });
286
+ else this.intents.push({ intent: "token_diff", diff: { [token.toString()]: (-intAmount).toString() } });
343
287
  return this;
344
288
  }
345
289
 
346
- async signSequence() {
347
- const signer = this.signer;
348
- if (!signer) throw new Error("No signer attached");
349
- if (!signer.omniAddress) throw new Error("No omni address");
350
-
351
- const commitments: Commitment[] = [];
352
- for (const intent of this.unsignedCommitment?.intents || []) {
353
- commitments.push(
354
- await signer.signIntents([intent], {
355
- deadline: this.unsignedCommitment?.deadline ? +this.unsignedCommitment.deadline : undefined,
356
- nonce: this.unsignedCommitment?.nonce,
357
- })
358
- );
290
+ async signRaw({ ed25519PrivateKey, intentsAddress, checkTokens }: { ed25519PrivateKey: Uint8Array; intentsAddress?: string; checkTokens?: boolean }) {
291
+ if (checkTokens) {
292
+ await this.checkRequiredTokens();
359
293
  }
360
294
 
361
- return commitments;
362
- }
295
+ const publicKey = ed25519.getPublicKey(ed25519PrivateKey);
296
+ const nonce = new Uint8Array(this.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
363
297
 
364
- async sign() {
365
- const signer = this.signer;
366
- if (!signer) throw new Error("No signer attached");
367
- if (!signer.omniAddress) throw new Error("No omni address");
368
- const commitment = await signer.signIntents(this.unsignedCommitment?.intents || [], {
369
- deadline: this.unsignedCommitment?.deadline ? +this.unsignedCommitment.deadline : undefined,
370
- nonce: this.unsignedCommitment?.nonce,
298
+ const message = JSON.stringify({
299
+ deadline: this.deadline ? new Date(this.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
300
+ nonce: base64.encode(nonce),
301
+ verifying_contract: "intents.near",
302
+ signer_id: intentsAddress || hex.encode(publicKey).toLowerCase(),
303
+ intents: this.intents,
371
304
  });
372
305
 
373
- this.unsignedCommitment = undefined;
306
+ return {
307
+ signature: `ed25519:${base58.encode(ed25519.sign(message, ed25519PrivateKey))}`,
308
+ public_key: `ed25519:${base58.encode(publicKey)}`,
309
+ standard: "raw_ed25519",
310
+ payload: message,
311
+ };
312
+ }
313
+
314
+ async attachCommitment(commitment: Record<string, any>) {
374
315
  this.commitments.push(commitment);
375
316
  return this;
376
317
  }
377
318
 
378
- async simulate() {
379
- if (this.commitments.length === 0) throw new Error("No commitments attached");
380
- return await Intents.simulateIntents(this.commitments);
319
+ async attachSigner(signer: OmniWallet | { ed25519PrivateKey: Uint8Array; omniAddress?: string }) {
320
+ this.signer = signer;
321
+ return this;
381
322
  }
382
323
 
383
- async setupSigner() {
384
- if (!this.wibe3) throw new Error("No wibe3 attached");
385
- if (this.signer) return this.signer;
386
-
387
- if (this.wibe3.priorityWallet) {
388
- this.signer = this.wibe3.priorityWallet;
389
- return this.signer;
324
+ async checkRequiredTokens() {
325
+ if (this.wibe3 == null) return;
326
+ for (const [token, needAmount] of this.need.entries()) {
327
+ if (needAmount <= 0n) continue;
328
+ await this.wibe3.requestToken(token, needAmount);
390
329
  }
330
+ }
391
331
 
392
- if (this.wibe3.wallets.length > 0) await openConnectPrimaryWallet(this.wibe3);
393
- else await openConnector(this.wibe3);
332
+ async sign(params = { checkTokens: true }) {
333
+ const signer = this.signer;
334
+ if (!signer) throw new Error("No signer attached");
335
+ if (!signer.omniAddress) throw new Error("No omni address");
394
336
 
395
- if (this.wibe3.priorityWallet == undefined) throw new Error("No signer attached");
396
- this.signer = this.wibe3.priorityWallet;
397
- return this.signer;
398
- }
337
+ if ("ed25519PrivateKey" in signer) {
338
+ return await this.signRaw({
339
+ ed25519PrivateKey: signer.ed25519PrivateKey,
340
+ intentsAddress: signer.omniAddress,
341
+ checkTokens: params.checkTokens,
342
+ });
343
+ }
399
344
 
400
- async openSignFlow({ title, allowedTokens, onConfirm }: { title?: string; allowedTokens?: string[]; onConfirm: (args: { depositQoute?: BridgeReview; processing?: () => Promise<BridgeReview> }) => Promise<void> }) {
401
- if (!this.wibe3) throw "Attach wibe3";
402
- if (!this.signer) throw "Attach signer";
403
-
404
- // TODO: Handle multiple payables
405
- const payableToken = tokens.get(Array.from(this.need.keys())[0]);
406
- const payableAmount = this.need.get(payableToken.omniAddress as OmniToken) || 0n;
407
- const balance = await this.wibe3.fetchToken(payableToken!, this.signer);
408
- const prepaidAmount = formatter.bigIntMin(payableAmount, balance);
409
-
410
- return await openPayment(this.wibe3, {
411
- onConfirm,
412
- needAmount: payableAmount - prepaidAmount,
413
- allowedTokens,
414
- prepaidAmount,
415
- payableToken,
416
- intents: this,
417
- title,
418
- });
419
- }
345
+ if (params.checkTokens) {
346
+ await this.checkRequiredTokens();
347
+ }
420
348
 
421
- async depositAndExecute({ title = "Payment", message, allowedTokens, serverSideProcessing, payload }: { title?: string; message?: string; allowedTokens?: string[]; serverSideProcessing?: boolean; payload?: Record<string, any> } = {}) {
422
- await this.setupSigner();
423
- if (this.need.size === 0) return this.execute();
424
-
425
- await this.openSignFlow({
426
- title,
427
- allowedTokens,
428
- onConfirm: async ({ depositQoute, processing }: { depositQoute?: BridgeReview; processing?: () => Promise<BridgeReview> }) => {
429
- if (!serverSideProcessing) return;
430
-
431
- console.log("Processing 1");
432
- let depositAddress: string | undefined;
433
- if (depositQoute?.qoute === "deposit") await processing?.();
434
- else if (depositQoute?.qoute === "withdraw") await processing?.();
435
- else depositAddress = depositQoute?.qoute?.depositAddress;
436
-
437
- console.log("yieldIntentCall", depositAddress, this.commitments[0], payload);
438
- await api.yieldIntentCall({
439
- depositAddress: depositAddress,
440
- commitment: this.commitments[0],
441
- payload: payload || {},
442
- });
443
- },
349
+ return await signer.signIntents(this.intents, {
350
+ deadline: this.deadline ? +this.deadline : undefined,
351
+ nonce: this.nonce,
444
352
  });
445
-
446
- if (serverSideProcessing) return;
447
- const close = openToast(message || "Executing payment");
448
- await this.execute().finally(() => close());
449
353
  }
450
354
 
451
- async execute() {
452
- if (this.unsignedCommitment != null) await this.sign();
453
- const task = Intents.publish(this.commitments, this.signedHashes);
454
- this.commitments = [];
455
- this.signedHashes = [];
355
+ async simulate(params = { checkTokens: true }) {
356
+ const signed = await this.sign(params);
357
+ return await Intents.simulateIntents([signed]);
358
+ }
456
359
 
457
- const hash = await task;
360
+ async execute(params = { checkTokens: true }) {
361
+ const signed = await this.sign(params);
362
+ const hash = await Intents.publishSignedIntents([...this.commitments, signed], this.hashes);
458
363
  await rpc.waitTransactionResult(hash, "intents.near");
459
364
  return hash;
460
365
  }
461
366
 
462
- static async publish(signed: Commitment[], hashes: string[] = []): Promise<string> {
463
- const result = await api.publishIntents(signed, hashes);
367
+ static async publishSignedIntents(signed: Record<string, any>[], hashes: string[] = []): Promise<string> {
368
+ const res = await fetch("https://api0.herewallet.app/api/v1/evm/intent-solver", {
369
+ headers: { "Content-Type": "application/json" },
370
+ method: "POST",
371
+ body: JSON.stringify({
372
+ params: [{ signed_datas: signed, quote_hashes: hashes }],
373
+ method: "publish_intents",
374
+ id: "dontcare",
375
+ jsonrpc: "2.0",
376
+ }),
377
+ });
378
+
379
+ const { result } = await res.json();
464
380
  if (result.status === "FAILED") throw result.reason;
465
381
  const intentResult = result.intent_hashes[0];
466
382
 
467
383
  const getStatus = async () => {
468
- const statusResult = await api.getIntentsStatus(intentResult);
469
- return statusResult;
384
+ const statusRes = await fetch("https://api0.herewallet.app/api/v1/evm/intent-solver", {
385
+ headers: { "Content-Type": "application/json" },
386
+ method: "POST",
387
+ body: JSON.stringify({
388
+ params: [{ intent_hash: intentResult }],
389
+ method: "get_status",
390
+ id: "dontcare",
391
+ jsonrpc: "2.0",
392
+ }),
393
+ });
394
+
395
+ const { result } = await statusRes.json();
396
+ return result;
470
397
  };
471
398
 
472
399
  const fetchResult = async () => {
@@ -490,7 +417,7 @@ export class Intents {
490
417
  });
491
418
  }
492
419
 
493
- static async simulateIntents(signed: Commitment[]) {
420
+ static async simulateIntents(signed: Record<string, any>[]) {
494
421
  return await rpc.viewMethod({
495
422
  args: { signed: signed },
496
423
  methodName: "simulate_intents",
package/src/core/api.ts CHANGED
@@ -8,16 +8,6 @@ export class ApiError extends Error {
8
8
  }
9
9
  }
10
10
 
11
- export interface PaymentStatus {
12
- payment_id: string;
13
- timestamp: number;
14
- amount: string;
15
- token_id: string;
16
- sender_id: string;
17
- near_trx: string;
18
- status: string;
19
- }
20
-
21
11
  export interface TokenType {
22
12
  icon: string;
23
13
  symbol: string;
@@ -79,29 +69,9 @@ export class Api {
79
69
  return result.balances?.[chain] || [];
80
70
  }
81
71
 
82
- async yieldIntentCall(args: { commitment: Commitment; depositAddress?: string; payload?: Record<string, any> }) {
83
- return await this.request(`/api/v1/wibe3/yield_intent_call`, {
84
- method: "POST",
85
- body: JSON.stringify({
86
- commitment: args.commitment,
87
- deposit_address: args.depositAddress,
88
- ...args.payload,
89
- }),
90
- });
91
- }
92
-
93
- async paymentStatus(memo: string): Promise<PaymentStatus> {
94
- const result = await this.request(`/partners/processed_payments?memo=${memo}`, { method: "GET" });
95
- return result.payments[0];
96
- }
97
-
98
- async getPayments(merchantId: string): Promise<PaymentStatus[]> {
99
- const result = await this.request(`/partners/processed_payments?merchant_id=${merchantId}`, { method: "GET" });
100
- return result.payments;
101
- }
102
-
103
72
  async publishIntents(signed: Record<string, any>[], hashes: string[]) {
104
- const result = await this.request(`/api/v1/wibe3/solver-bus`, {
73
+ return await this.request(`/api/v1/wibe3/solver-bus`, {
74
+ headers: { "Content-Type": "application/json" },
105
75
  method: "POST",
106
76
  body: JSON.stringify({
107
77
  params: [{ signed_datas: signed, quote_hashes: hashes }],
@@ -110,19 +80,11 @@ export class Api {
110
80
  jsonrpc: "2.0",
111
81
  }),
112
82
  });
113
-
114
- return result.result;
115
- }
116
-
117
- async publishTelemetry(events: { event: string; value_str?: string; value_float?: number; ts: number }[], accountId: string) {
118
- await this.request(`/api/v1/wibe3/telemetry/event`, {
119
- body: JSON.stringify({ events, account_id: accountId }),
120
- method: "POST",
121
- });
122
83
  }
123
84
 
124
85
  async getIntentsStatus(intentHash: string) {
125
- const result = await this.request(`/api/v1/wibe3/solver-bus`, {
86
+ return await this.request(`/api/v1/wibe3/solver-bus`, {
87
+ headers: { "Content-Type": "application/json" },
126
88
  method: "POST",
127
89
  body: JSON.stringify({
128
90
  params: [{ intent_hash: intentHash }],
@@ -131,8 +93,6 @@ export class Api {
131
93
  jsonrpc: "2.0",
132
94
  }),
133
95
  });
134
-
135
- return result.result;
136
96
  }
137
97
  }
138
98
 
@@ -1,14 +1,13 @@
1
1
  import { CosmosConfig, HotBridge, ReviewFee } from "@hot-labs/omni-sdk";
2
2
  import { chains, Network, WalletType } from "./chains";
3
3
  import { Intents } from "./Intents";
4
- import { Commitment } from "./types";
5
4
 
6
5
  export { ReviewFee, HotBridge };
7
6
 
8
7
  export const createHotBridge = () => {
9
8
  return new HotBridge({
10
- publishIntents: async (signed: Commitment[], hashes: string[] = []) => {
11
- const hash = await Intents.publish(signed, hashes);
9
+ publishIntents: async (signed: Record<string, any>[], hashes: string[] = []) => {
10
+ const hash = await Intents.publishSignedIntents(signed, hashes);
12
11
  return { sender: "intents.near", hash };
13
12
  },
14
13