lampamazaza-new-intents-sdk 0.47.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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1083 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  4. package/dist/index.cjs +124 -0
  5. package/dist/index.d.cts +22 -0
  6. package/dist/index.d.ts +22 -0
  7. package/dist/index.js +19 -0
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
  9. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
  10. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
  11. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
  12. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
  13. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
  14. package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
  15. package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
  16. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
  17. package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
  18. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
  19. package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
  20. package/dist/src/bridges/direct-bridge/error.cjs +16 -0
  21. package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
  22. package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
  23. package/dist/src/bridges/direct-bridge/error.js +15 -0
  24. package/dist/src/bridges/hot-bridge/error.cjs +23 -0
  25. package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
  26. package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
  27. package/dist/src/bridges/hot-bridge/error.js +21 -0
  28. package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
  29. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
  30. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
  31. package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
  32. package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
  33. package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
  34. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
  35. package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
  36. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
  37. package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
  38. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
  39. package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
  40. package/dist/src/bridges/omni-bridge/error.cjs +54 -0
  41. package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
  42. package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
  43. package/dist/src/bridges/omni-bridge/error.js +49 -0
  44. package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
  45. package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
  46. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
  47. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
  48. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
  49. package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
  50. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
  51. package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
  52. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
  53. package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
  54. package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
  55. package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
  56. package/dist/src/classes/errors.cjs +87 -0
  57. package/dist/src/classes/errors.d.cts +48 -0
  58. package/dist/src/classes/errors.d.ts +48 -0
  59. package/dist/src/classes/errors.js +81 -0
  60. package/dist/src/constants/bridge-name-enum.cjs +11 -0
  61. package/dist/src/constants/bridge-name-enum.d.cts +11 -0
  62. package/dist/src/constants/bridge-name-enum.d.ts +11 -0
  63. package/dist/src/constants/bridge-name-enum.js +10 -0
  64. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  65. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  66. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  67. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  68. package/dist/src/constants/public-rpc-urls.cjs +25 -0
  69. package/dist/src/constants/public-rpc-urls.js +24 -0
  70. package/dist/src/constants/route-enum.cjs +13 -0
  71. package/dist/src/constants/route-enum.d.cts +13 -0
  72. package/dist/src/constants/route-enum.d.ts +13 -0
  73. package/dist/src/constants/route-enum.js +12 -0
  74. package/dist/src/constants/withdrawal-timing.cjs +68 -0
  75. package/dist/src/constants/withdrawal-timing.js +68 -0
  76. package/dist/src/core/withdrawal-watcher.cjs +86 -0
  77. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  78. package/dist/src/core/withdrawal-watcher.d.ts +19 -0
  79. package/dist/src/core/withdrawal-watcher.js +82 -0
  80. package/dist/src/intents/expirable-nonce.cjs +90 -0
  81. package/dist/src/intents/expirable-nonce.d.cts +44 -0
  82. package/dist/src/intents/expirable-nonce.d.ts +45 -0
  83. package/dist/src/intents/expirable-nonce.js +82 -0
  84. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
  85. package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
  86. package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
  87. package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
  88. package/dist/src/intents/intent-hash.cjs +48 -0
  89. package/dist/src/intents/intent-hash.d.cts +8 -0
  90. package/dist/src/intents/intent-hash.d.ts +8 -0
  91. package/dist/src/intents/intent-hash.js +47 -0
  92. package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
  93. package/dist/src/intents/intent-hashes/erc191.js +37 -0
  94. package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
  95. package/dist/src/intents/intent-hashes/nep413.js +22 -0
  96. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
  97. package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
  98. package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
  99. package/dist/src/intents/intent-hashes/sep53.js +35 -0
  100. package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
  101. package/dist/src/intents/intent-hashes/tip191.js +38 -0
  102. package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
  103. package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
  104. package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
  105. package/dist/src/intents/intent-hashes/webauthn.js +25 -0
  106. package/dist/src/intents/intent-payload-builder.cjs +208 -0
  107. package/dist/src/intents/intent-payload-builder.d.cts +161 -0
  108. package/dist/src/intents/intent-payload-builder.d.ts +161 -0
  109. package/dist/src/intents/intent-payload-builder.js +207 -0
  110. package/dist/src/intents/intent-payload-factory.cjs +23 -0
  111. package/dist/src/intents/intent-payload-factory.js +21 -0
  112. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
  113. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
  114. package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
  115. package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
  116. package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
  117. package/dist/src/intents/intent-signer-impl/factories.js +17 -0
  118. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
  119. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
  120. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
  121. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
  122. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
  123. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
  124. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
  125. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
  126. package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
  127. package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
  128. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
  129. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
  130. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
  131. package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
  132. package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
  133. package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
  134. package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
  135. package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
  136. package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
  137. package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
  138. package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
  139. package/dist/src/intents/salt-manager.cjs +74 -0
  140. package/dist/src/intents/salt-manager.js +72 -0
  141. package/dist/src/intents/shared-types.d.cts +20 -0
  142. package/dist/src/intents/shared-types.d.ts +20 -0
  143. package/dist/src/lib/array.cjs +11 -0
  144. package/dist/src/lib/array.js +10 -0
  145. package/dist/src/lib/caip2.cjs +50 -0
  146. package/dist/src/lib/caip2.d.cts +38 -0
  147. package/dist/src/lib/caip2.d.ts +38 -0
  148. package/dist/src/lib/caip2.js +48 -0
  149. package/dist/src/lib/configure-rpc-config.cjs +20 -0
  150. package/dist/src/lib/configure-rpc-config.js +18 -0
  151. package/dist/src/lib/estimate-fee.cjs +96 -0
  152. package/dist/src/lib/estimate-fee.js +94 -0
  153. package/dist/src/lib/hex.cjs +11 -0
  154. package/dist/src/lib/hex.js +10 -0
  155. package/dist/src/lib/nep413.cjs +42 -0
  156. package/dist/src/lib/nep413.d.cts +14 -0
  157. package/dist/src/lib/nep413.d.ts +14 -0
  158. package/dist/src/lib/nep413.js +41 -0
  159. package/dist/src/lib/object.cjs +10 -0
  160. package/dist/src/lib/object.js +9 -0
  161. package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
  162. package/dist/src/lib/parse-defuse-asset-id.js +14 -0
  163. package/dist/src/lib/route-config-factory.cjs +43 -0
  164. package/dist/src/lib/route-config-factory.d.cts +13 -0
  165. package/dist/src/lib/route-config-factory.d.ts +13 -0
  166. package/dist/src/lib/route-config-factory.js +37 -0
  167. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
  168. package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
  169. package/dist/src/lib/validateAddress.cjs +271 -0
  170. package/dist/src/lib/validateAddress.d.cts +14 -0
  171. package/dist/src/lib/validateAddress.d.ts +14 -0
  172. package/dist/src/lib/validateAddress.js +270 -0
  173. package/dist/src/sdk.cjs +435 -0
  174. package/dist/src/sdk.d.cts +231 -0
  175. package/dist/src/sdk.d.ts +231 -0
  176. package/dist/src/sdk.js +433 -0
  177. package/dist/src/shared-types.d.cts +378 -0
  178. package/dist/src/shared-types.d.ts +378 -0
  179. package/package.json +62 -0
@@ -0,0 +1,207 @@
1
+ import { VersionedNonceBuilder } from "./expirable-nonce.js";
2
+ import { DEFAULT_DEADLINE_MS, DEFAULT_NONCE_DEADLINE_OFFSET_MS } from "./intent-payload-factory.js";
3
+ import { utils } from "lampamazaza-internal-utils";
4
+
5
+ //#region src/intents/intent-payload-builder.ts
6
+ /**
7
+ * Fluent builder for constructing intent payloads with environment context.
8
+ * Provides a convenient API for generating intents that can be signed with different standards.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
13
+ *
14
+ * // Build an intent payload
15
+ * const payload = await sdk.intentBuilder()
16
+ * .setSigner('0x1234...') // EVM address or NEAR account
17
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
18
+ * .addIntent({
19
+ * intent: 'ft_withdraw',
20
+ * token: 'usdc.omft.near',
21
+ * amount: '1000000',
22
+ * receiver_id: 'user.near'
23
+ * })
24
+ * .build();
25
+ *
26
+ * // Sign with your preferred method
27
+ * const multiPayload = await signer.signIntent(payload);
28
+ * ```
29
+ */
30
+ var IntentPayloadBuilder = class IntentPayloadBuilder {
31
+ constructor(config) {
32
+ this.intents = [];
33
+ this.envConfig = config.envConfig;
34
+ this.saltManager = config.saltManager;
35
+ this.verifyingContract = this.envConfig.contractID;
36
+ }
37
+ /**
38
+ * Set the signer ID (address or account that will sign the intent).
39
+ * Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
40
+ *
41
+ * @param signerId - The identifier of the signer (must be a valid NEAR account ID)
42
+ * @returns The builder instance for chaining with updated type
43
+ * @throws Error if signerId is not a valid NEAR account ID
44
+ */
45
+ setSigner(signerId) {
46
+ if (!utils.validateNearAddress(signerId)) throw new Error(`Invalid signer_id: "${signerId}" is not a valid NEAR account ID`);
47
+ this.signerId = signerId;
48
+ return this;
49
+ }
50
+ /**
51
+ * Set the deadline for the intent expiration.
52
+ * If not set, defaults to 1 minute from build time.
53
+ *
54
+ * @param deadline - The expiration time for the intent
55
+ * @returns The builder instance for chaining
56
+ */
57
+ setDeadline(deadline) {
58
+ this.deadline = deadline;
59
+ return this;
60
+ }
61
+ /**
62
+ * Add an intent to the payload.
63
+ * Multiple intents can be added and will execute atomically.
64
+ *
65
+ * @param intent - The intent primitive to add
66
+ * @returns The builder instance for chaining
67
+ */
68
+ addIntent(intent) {
69
+ this.intents.push(intent);
70
+ return this;
71
+ }
72
+ /**
73
+ * Add multiple intents to the payload at once.
74
+ *
75
+ * @param intents - Array of intent primitives to add
76
+ * @returns The builder instance for chaining
77
+ */
78
+ addIntents(intents) {
79
+ this.intents.push(...intents);
80
+ return this;
81
+ }
82
+ /**
83
+ * Override the verifying contract address.
84
+ * Use with caution - normally this is automatically set based on environment.
85
+ *
86
+ * @param contractAddress - The contract address to use
87
+ * @returns The builder instance for chaining
88
+ */
89
+ setVerifyingContract(contractAddress) {
90
+ this.verifyingContract = contractAddress;
91
+ return this;
92
+ }
93
+ /**
94
+ * Set a custom nonce. If not provided, a nonce will be automatically generated.
95
+ * The nonce must be a valid versioned nonce format.
96
+ *
97
+ * @param nonce - Custom nonce string (base64 encoded)
98
+ * @returns The builder instance for chaining
99
+ */
100
+ setNonce(nonce) {
101
+ this.customNonce = nonce;
102
+ return this;
103
+ }
104
+ /**
105
+ * Clear all intents from the builder.
106
+ *
107
+ * @returns The builder instance for chaining
108
+ */
109
+ clearIntents() {
110
+ this.intents = [];
111
+ return this;
112
+ }
113
+ /**
114
+ * Reset the builder to its initial state.
115
+ * Keeps environment and salt manager but clears all user-set values.
116
+ *
117
+ * @returns The builder instance for chaining
118
+ */
119
+ reset() {
120
+ this.signerId = void 0;
121
+ this.deadline = void 0;
122
+ this.intents = [];
123
+ this.customNonce = void 0;
124
+ this.verifyingContract = this.envConfig.contractID;
125
+ return this;
126
+ }
127
+ /**
128
+ * Build the intent payload using a custom salt.
129
+ * Use this method if you need explicit control over the salt.
130
+ *
131
+ * @param salt - The salt to use for nonce generation
132
+ * @returns The constructed intent payload with appropriate typing
133
+ */
134
+ buildWithSalt(salt) {
135
+ const deadline = this.deadline ?? new Date(Date.now() + DEFAULT_DEADLINE_MS);
136
+ const nonceDeadline = new Date(deadline.getTime() + DEFAULT_NONCE_DEADLINE_OFFSET_MS);
137
+ const nonce = this.customNonce ?? VersionedNonceBuilder.encodeNonce(salt, nonceDeadline);
138
+ return {
139
+ verifying_contract: this.verifyingContract,
140
+ signer_id: this.signerId,
141
+ deadline: deadline.toISOString(),
142
+ nonce,
143
+ intents: [...this.intents]
144
+ };
145
+ }
146
+ /**
147
+ * Build the intent payload. Automatically fetches a fresh salt if needed.
148
+ * This is the recommended method for most use cases.
149
+ *
150
+ * @returns Promise resolving to the constructed intent payload with appropriate typing
151
+ */
152
+ async build() {
153
+ const salt = await this.saltManager.getCachedSalt();
154
+ return this.buildWithSalt(salt);
155
+ }
156
+ /**
157
+ * Build and sign the intent payload in one step.
158
+ * Convenience method that combines build() and signing.
159
+ *
160
+ * @param signer - The intent signer to use
161
+ * @returns Promise resolving to the signed multi-payload and the raw payload
162
+ */
163
+ async buildAndSign(signer) {
164
+ const payload = await this.build();
165
+ return {
166
+ signed: await signer.signIntent(payload),
167
+ payload
168
+ };
169
+ }
170
+ /**
171
+ * Create a new builder instance with the same configuration.
172
+ * Useful when you need multiple independent builders.
173
+ *
174
+ * @returns A new IntentPayloadBuilder instance
175
+ */
176
+ clone() {
177
+ const builder = new IntentPayloadBuilder({
178
+ envConfig: this.envConfig,
179
+ saltManager: this.saltManager
180
+ });
181
+ builder.verifyingContract = this.verifyingContract;
182
+ builder.signerId = this.signerId;
183
+ builder.deadline = this.deadline;
184
+ builder.intents = [...this.intents];
185
+ builder.customNonce = this.customNonce;
186
+ return builder;
187
+ }
188
+ /**
189
+ * Get the current state of the builder as a plain object.
190
+ * Useful for debugging or inspecting the builder configuration.
191
+ *
192
+ * @returns Object containing the current builder state
193
+ */
194
+ getState() {
195
+ return {
196
+ envConfig: this.envConfig,
197
+ verifyingContract: this.verifyingContract,
198
+ signerId: this.signerId,
199
+ deadline: this.deadline,
200
+ intents: [...this.intents],
201
+ customNonce: this.customNonce
202
+ };
203
+ }
204
+ };
205
+
206
+ //#endregion
207
+ export { IntentPayloadBuilder };
@@ -0,0 +1,23 @@
1
+ const require_expirable_nonce = require('./expirable-nonce.cjs');
2
+
3
+ //#region src/intents/intent-payload-factory.ts
4
+ const DEFAULT_DEADLINE_MS = 60 * 1e3;
5
+ const DEFAULT_NONCE_DEADLINE_OFFSET_MS = DEFAULT_DEADLINE_MS;
6
+ function defaultIntentPayloadFactory(salt, { intents, verifying_contract, ...params }) {
7
+ params = Object.fromEntries(Object.entries(params).filter(([, value]) => value !== void 0));
8
+ const deadline = params.deadline != null ? new Date(params.deadline) : new Date(Date.now() + DEFAULT_DEADLINE_MS);
9
+ const nonceDeadline = new Date(deadline.getTime() + DEFAULT_NONCE_DEADLINE_OFFSET_MS);
10
+ return {
11
+ verifying_contract,
12
+ deadline: deadline.toISOString(),
13
+ nonce: require_expirable_nonce.VersionedNonceBuilder.encodeNonce(salt, nonceDeadline),
14
+ intents: intents == null ? [] : intents,
15
+ signer_id: void 0,
16
+ ...params
17
+ };
18
+ }
19
+
20
+ //#endregion
21
+ exports.DEFAULT_DEADLINE_MS = DEFAULT_DEADLINE_MS;
22
+ exports.DEFAULT_NONCE_DEADLINE_OFFSET_MS = DEFAULT_NONCE_DEADLINE_OFFSET_MS;
23
+ exports.defaultIntentPayloadFactory = defaultIntentPayloadFactory;
@@ -0,0 +1,21 @@
1
+ import { VersionedNonceBuilder } from "./expirable-nonce.js";
2
+
3
+ //#region src/intents/intent-payload-factory.ts
4
+ const DEFAULT_DEADLINE_MS = 60 * 1e3;
5
+ const DEFAULT_NONCE_DEADLINE_OFFSET_MS = DEFAULT_DEADLINE_MS;
6
+ function defaultIntentPayloadFactory(salt, { intents, verifying_contract, ...params }) {
7
+ params = Object.fromEntries(Object.entries(params).filter(([, value]) => value !== void 0));
8
+ const deadline = params.deadline != null ? new Date(params.deadline) : new Date(Date.now() + DEFAULT_DEADLINE_MS);
9
+ const nonceDeadline = new Date(deadline.getTime() + DEFAULT_NONCE_DEADLINE_OFFSET_MS);
10
+ return {
11
+ verifying_contract,
12
+ deadline: deadline.toISOString(),
13
+ nonce: VersionedNonceBuilder.encodeNonce(salt, nonceDeadline),
14
+ intents: intents == null ? [] : intents,
15
+ signer_id: void 0,
16
+ ...params
17
+ };
18
+ }
19
+
20
+ //#endregion
21
+ export { DEFAULT_DEADLINE_MS, DEFAULT_NONCE_DEADLINE_OFFSET_MS, defaultIntentPayloadFactory };
@@ -0,0 +1,43 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
3
+
4
+ //#region src/intents/intent-relayer-impl/intent-relayer-public.ts
5
+ var IntentRelayerPublic = class {
6
+ constructor({ envConfig, solverRelayApiKey }) {
7
+ this.envConfig = envConfig;
8
+ this.solverRelayApiKey = solverRelayApiKey;
9
+ }
10
+ async publishIntent({ multiPayload, quoteHashes }, ctx = {}) {
11
+ return (await this.publishIntents({
12
+ multiPayloads: [multiPayload],
13
+ quoteHashes: quoteHashes ?? []
14
+ }, ctx))[0];
15
+ }
16
+ async publishIntents({ multiPayloads, quoteHashes }, ctx = {}) {
17
+ const result = await lampamazaza_internal_utils.solverRelay.publishIntents({
18
+ quote_hashes: quoteHashes,
19
+ signed_datas: multiPayloads
20
+ }, {
21
+ baseURL: this.envConfig.solverRelayBaseURL,
22
+ logger: ctx.logger,
23
+ solverRelayApiKey: this.solverRelayApiKey
24
+ });
25
+ if (result.isOk()) return result.unwrap();
26
+ throw result.unwrapErr();
27
+ }
28
+ async waitForSettlement(ticket, ctx = {}) {
29
+ return { tx: {
30
+ hash: (await lampamazaza_internal_utils.solverRelay.waitForIntentSettlement({
31
+ intentHash: ticket,
32
+ signal: ctx.signal,
33
+ baseURL: this.envConfig.solverRelayBaseURL,
34
+ logger: ctx.logger,
35
+ solverRelayApiKey: this.solverRelayApiKey
36
+ })).txHash,
37
+ accountId: this.envConfig.contractID
38
+ } };
39
+ }
40
+ };
41
+
42
+ //#endregion
43
+ exports.IntentRelayerPublic = IntentRelayerPublic;
@@ -0,0 +1,42 @@
1
+ import { solverRelay } from "lampamazaza-internal-utils";
2
+
3
+ //#region src/intents/intent-relayer-impl/intent-relayer-public.ts
4
+ var IntentRelayerPublic = class {
5
+ constructor({ envConfig, solverRelayApiKey }) {
6
+ this.envConfig = envConfig;
7
+ this.solverRelayApiKey = solverRelayApiKey;
8
+ }
9
+ async publishIntent({ multiPayload, quoteHashes }, ctx = {}) {
10
+ return (await this.publishIntents({
11
+ multiPayloads: [multiPayload],
12
+ quoteHashes: quoteHashes ?? []
13
+ }, ctx))[0];
14
+ }
15
+ async publishIntents({ multiPayloads, quoteHashes }, ctx = {}) {
16
+ const result = await solverRelay.publishIntents({
17
+ quote_hashes: quoteHashes,
18
+ signed_datas: multiPayloads
19
+ }, {
20
+ baseURL: this.envConfig.solverRelayBaseURL,
21
+ logger: ctx.logger,
22
+ solverRelayApiKey: this.solverRelayApiKey
23
+ });
24
+ if (result.isOk()) return result.unwrap();
25
+ throw result.unwrapErr();
26
+ }
27
+ async waitForSettlement(ticket, ctx = {}) {
28
+ return { tx: {
29
+ hash: (await solverRelay.waitForIntentSettlement({
30
+ intentHash: ticket,
31
+ signal: ctx.signal,
32
+ baseURL: this.envConfig.solverRelayBaseURL,
33
+ logger: ctx.logger,
34
+ solverRelayApiKey: this.solverRelayApiKey
35
+ })).txHash,
36
+ accountId: this.envConfig.contractID
37
+ } };
38
+ }
39
+ };
40
+
41
+ //#endregion
42
+ export { IntentRelayerPublic };
@@ -0,0 +1,19 @@
1
+ const require_intent_signer_nep413 = require('./intent-signer-nep413.cjs');
2
+ const require_intent_signer_near_keypair = require('./intent-signer-near-keypair.cjs');
3
+ const require_intent_signer_viem = require('./intent-signer-viem.cjs');
4
+
5
+ //#region src/intents/intent-signer-impl/factories.ts
6
+ function createIntentSignerNEP413(config) {
7
+ return new require_intent_signer_nep413.IntentSignerNEP413(config);
8
+ }
9
+ function createIntentSignerNearKeyPair(config) {
10
+ return new require_intent_signer_near_keypair.IntentSignerNearKeypair(config);
11
+ }
12
+ function createIntentSignerViem(config) {
13
+ return new require_intent_signer_viem.IntentSignerViem(config);
14
+ }
15
+
16
+ //#endregion
17
+ exports.createIntentSignerNEP413 = createIntentSignerNEP413;
18
+ exports.createIntentSignerNearKeyPair = createIntentSignerNearKeyPair;
19
+ exports.createIntentSignerViem = createIntentSignerViem;
@@ -0,0 +1,11 @@
1
+ import { IIntentSigner } from "../interfaces/intent-signer.cjs";
2
+ import { IntentSignerNEP413Config } from "./intent-signer-nep413.cjs";
3
+ import { IntentSignerNearKeypairConfig } from "./intent-signer-near-keypair.cjs";
4
+ import { IntentSignerViemConfig } from "./intent-signer-viem.cjs";
5
+
6
+ //#region src/intents/intent-signer-impl/factories.d.ts
7
+ declare function createIntentSignerNEP413(config: IntentSignerNEP413Config): IIntentSigner;
8
+ declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig): IIntentSigner;
9
+ declare function createIntentSignerViem(config: IntentSignerViemConfig): IIntentSigner;
10
+ //#endregion
11
+ export { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem };
@@ -0,0 +1,11 @@
1
+ import { IIntentSigner } from "../interfaces/intent-signer.js";
2
+ import { IntentSignerNEP413Config } from "./intent-signer-nep413.js";
3
+ import { IntentSignerNearKeypairConfig } from "./intent-signer-near-keypair.js";
4
+ import { IntentSignerViemConfig } from "./intent-signer-viem.js";
5
+
6
+ //#region src/intents/intent-signer-impl/factories.d.ts
7
+ declare function createIntentSignerNEP413(config: IntentSignerNEP413Config): IIntentSigner;
8
+ declare function createIntentSignerNearKeyPair(config: IntentSignerNearKeypairConfig): IIntentSigner;
9
+ declare function createIntentSignerViem(config: IntentSignerViemConfig): IIntentSigner;
10
+ //#endregion
11
+ export { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem };
@@ -0,0 +1,17 @@
1
+ import { IntentSignerNEP413 } from "./intent-signer-nep413.js";
2
+ import { IntentSignerNearKeypair } from "./intent-signer-near-keypair.js";
3
+ import { IntentSignerViem } from "./intent-signer-viem.js";
4
+
5
+ //#region src/intents/intent-signer-impl/factories.ts
6
+ function createIntentSignerNEP413(config) {
7
+ return new IntentSignerNEP413(config);
8
+ }
9
+ function createIntentSignerNearKeyPair(config) {
10
+ return new IntentSignerNearKeypair(config);
11
+ }
12
+ function createIntentSignerViem(config) {
13
+ return new IntentSignerViem(config);
14
+ }
15
+
16
+ //#endregion
17
+ export { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem };
@@ -0,0 +1,22 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ const require_intent_signer_nep413 = require('./intent-signer-nep413.cjs');
3
+ let _scure_base = require("@scure/base");
4
+
5
+ //#region src/intents/intent-signer-impl/intent-signer-near-keypair.ts
6
+ var IntentSignerNearKeypair = class extends require_intent_signer_nep413.IntentSignerNEP413 {
7
+ constructor({ signer, accountId }) {
8
+ super({
9
+ signMessage: (_nep413Payload, nep413Hash) => {
10
+ const { publicKey, signature } = signer.sign(nep413Hash);
11
+ return {
12
+ publicKey: publicKey.toString(),
13
+ signature: _scure_base.base64.encode(signature)
14
+ };
15
+ },
16
+ accountId
17
+ });
18
+ }
19
+ };
20
+
21
+ //#endregion
22
+ exports.IntentSignerNearKeypair = IntentSignerNearKeypair;
@@ -0,0 +1,15 @@
1
+ import * as near_api_js0 from "near-api-js";
2
+
3
+ //#region src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts
4
+ interface IntentSignerNearKeypairConfig {
5
+ /**
6
+ * Instance of near-api-js's KeyPair type
7
+ */
8
+ signer: near_api_js0.KeyPair;
9
+ /**
10
+ * Account ID to be used as signer_id of the intent.
11
+ */
12
+ accountId: string;
13
+ }
14
+ //#endregion
15
+ export { IntentSignerNearKeypairConfig };
@@ -0,0 +1,16 @@
1
+ import "./intent-signer-nep413.js";
2
+ import * as near_api_js0 from "near-api-js";
3
+
4
+ //#region src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts
5
+ interface IntentSignerNearKeypairConfig {
6
+ /**
7
+ * Instance of near-api-js's KeyPair type
8
+ */
9
+ signer: near_api_js0.KeyPair;
10
+ /**
11
+ * Account ID to be used as signer_id of the intent.
12
+ */
13
+ accountId: string;
14
+ }
15
+ //#endregion
16
+ export { IntentSignerNearKeypairConfig };
@@ -0,0 +1,21 @@
1
+ import { IntentSignerNEP413 } from "./intent-signer-nep413.js";
2
+ import { base64 } from "@scure/base";
3
+
4
+ //#region src/intents/intent-signer-impl/intent-signer-near-keypair.ts
5
+ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
6
+ constructor({ signer, accountId }) {
7
+ super({
8
+ signMessage: (_nep413Payload, nep413Hash) => {
9
+ const { publicKey, signature } = signer.sign(nep413Hash);
10
+ return {
11
+ publicKey: publicKey.toString(),
12
+ signature: base64.encode(signature)
13
+ };
14
+ },
15
+ accountId
16
+ });
17
+ }
18
+ };
19
+
20
+ //#endregion
21
+ export { IntentSignerNearKeypair };
@@ -0,0 +1,37 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ const require_nep413 = require('../../lib/nep413.cjs');
3
+ let _scure_base = require("@scure/base");
4
+
5
+ //#region src/intents/intent-signer-impl/intent-signer-nep413.ts
6
+ var IntentSignerNEP413 = class {
7
+ constructor({ signMessage, accountId }) {
8
+ this.signMessage = signMessage;
9
+ this.accountId = accountId;
10
+ }
11
+ async signIntent(intent) {
12
+ const nep413Payload = {
13
+ recipient: intent.verifying_contract,
14
+ nonce: Array.from(_scure_base.base64.decode(intent.nonce)),
15
+ message: JSON.stringify({
16
+ deadline: intent.deadline,
17
+ intents: intent.intents,
18
+ signer_id: intent.signer_id ?? this.accountId
19
+ })
20
+ };
21
+ const nep413Hash = await require_nep413.hashNEP413Message(nep413Payload);
22
+ const { publicKey, signature } = await this.signMessage(nep413Payload, nep413Hash);
23
+ const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${_scure_base.base58.encode(_scure_base.base64.decode(signature))}`;
24
+ return {
25
+ standard: "nep413",
26
+ payload: {
27
+ ...nep413Payload,
28
+ nonce: intent.nonce
29
+ },
30
+ public_key: publicKey,
31
+ signature: signatureFormatted
32
+ };
33
+ }
34
+ };
35
+
36
+ //#endregion
37
+ exports.IntentSignerNEP413 = IntentSignerNEP413;
@@ -0,0 +1,14 @@
1
+ import { NEP413Payload } from "../../lib/nep413.cjs";
2
+
3
+ //#region src/intents/intent-signer-impl/intent-signer-nep413.d.ts
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ type SignMessageNEP413 = (nep413Payload: NEP413Payload, nep413Hash: Uint8Array) => MaybePromise<{
6
+ publicKey: string;
7
+ signature: string;
8
+ }>;
9
+ interface IntentSignerNEP413Config {
10
+ signMessage: SignMessageNEP413;
11
+ accountId: string;
12
+ }
13
+ //#endregion
14
+ export { IntentSignerNEP413Config };
@@ -0,0 +1,14 @@
1
+ import { NEP413Payload } from "../../lib/nep413.js";
2
+
3
+ //#region src/intents/intent-signer-impl/intent-signer-nep413.d.ts
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ type SignMessageNEP413 = (nep413Payload: NEP413Payload, nep413Hash: Uint8Array) => MaybePromise<{
6
+ publicKey: string;
7
+ signature: string;
8
+ }>;
9
+ interface IntentSignerNEP413Config {
10
+ signMessage: SignMessageNEP413;
11
+ accountId: string;
12
+ }
13
+ //#endregion
14
+ export { IntentSignerNEP413Config };
@@ -0,0 +1,36 @@
1
+ import { hashNEP413Message } from "../../lib/nep413.js";
2
+ import { base58, base64 } from "@scure/base";
3
+
4
+ //#region src/intents/intent-signer-impl/intent-signer-nep413.ts
5
+ var IntentSignerNEP413 = class {
6
+ constructor({ signMessage, accountId }) {
7
+ this.signMessage = signMessage;
8
+ this.accountId = accountId;
9
+ }
10
+ async signIntent(intent) {
11
+ const nep413Payload = {
12
+ recipient: intent.verifying_contract,
13
+ nonce: Array.from(base64.decode(intent.nonce)),
14
+ message: JSON.stringify({
15
+ deadline: intent.deadline,
16
+ intents: intent.intents,
17
+ signer_id: intent.signer_id ?? this.accountId
18
+ })
19
+ };
20
+ const nep413Hash = await hashNEP413Message(nep413Payload);
21
+ const { publicKey, signature } = await this.signMessage(nep413Payload, nep413Hash);
22
+ const signatureFormatted = signature.startsWith("ed25519:") ? signature : `ed25519:${base58.encode(base64.decode(signature))}`;
23
+ return {
24
+ standard: "nep413",
25
+ payload: {
26
+ ...nep413Payload,
27
+ nonce: intent.nonce
28
+ },
29
+ public_key: publicKey,
30
+ signature: signatureFormatted
31
+ };
32
+ }
33
+ };
34
+
35
+ //#endregion
36
+ export { IntentSignerNEP413 };
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/intents/intent-signer-impl/intent-signer-noop.ts
3
+ const noopIntentSigner = { signIntent() {
4
+ throw new Error("Not implemented");
5
+ } };
6
+
7
+ //#endregion
8
+ exports.noopIntentSigner = noopIntentSigner;
@@ -0,0 +1,7 @@
1
+ //#region src/intents/intent-signer-impl/intent-signer-noop.ts
2
+ const noopIntentSigner = { signIntent() {
3
+ throw new Error("Not implemented");
4
+ } };
5
+
6
+ //#endregion
7
+ export { noopIntentSigner };
@@ -0,0 +1,31 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
3
+
4
+ //#region src/intents/intent-signer-impl/intent-signer-viem.ts
5
+ var IntentSignerViem = class {
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ async signIntent(intent) {
10
+ const payload = JSON.stringify({
11
+ signer_id: intent.signer_id ?? this.config.accountId ?? lampamazaza_internal_utils.utils.authHandleToIntentsUserId({
12
+ identifier: this.config.signer.address,
13
+ method: "evm"
14
+ }),
15
+ verifying_contract: intent.verifying_contract,
16
+ deadline: intent.deadline,
17
+ nonce: intent.nonce,
18
+ intents: intent.intents
19
+ });
20
+ const signature = await this.config.signer.signMessage?.({ message: payload });
21
+ if (signature == null) throw new Error("No signature is returned");
22
+ return {
23
+ standard: "erc191",
24
+ payload,
25
+ signature: lampamazaza_internal_utils.utils.transformERC191Signature(signature)
26
+ };
27
+ }
28
+ };
29
+
30
+ //#endregion
31
+ exports.IntentSignerViem = IntentSignerViem;
@@ -0,0 +1,17 @@
1
+ import { Account } from "viem";
2
+
3
+ //#region src/intents/intent-signer-impl/intent-signer-viem.d.ts
4
+ type IntentSignerViemConfig = {
5
+ /**
6
+ * Instance of viem's Account type
7
+ * @see https://viem.sh/docs/accounts/local/privateKeyToAccount
8
+ */
9
+ signer: Pick<Account, "address" | "signMessage">;
10
+ /**
11
+ * Optional account ID to be used as signer_id of the intent.
12
+ * If not provided, the signer_id will be derived from the signer's address.
13
+ */
14
+ accountId?: string;
15
+ };
16
+ //#endregion
17
+ export { IntentSignerViemConfig };
@@ -0,0 +1,17 @@
1
+ import { Account } from "viem";
2
+
3
+ //#region src/intents/intent-signer-impl/intent-signer-viem.d.ts
4
+ type IntentSignerViemConfig = {
5
+ /**
6
+ * Instance of viem's Account type
7
+ * @see https://viem.sh/docs/accounts/local/privateKeyToAccount
8
+ */
9
+ signer: Pick<Account, "address" | "signMessage">;
10
+ /**
11
+ * Optional account ID to be used as signer_id of the intent.
12
+ * If not provided, the signer_id will be derived from the signer's address.
13
+ */
14
+ accountId?: string;
15
+ };
16
+ //#endregion
17
+ export { IntentSignerViemConfig };