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,208 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_expirable_nonce = require('./expirable-nonce.cjs');
3
+ const require_intent_payload_factory = require('./intent-payload-factory.cjs');
4
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
5
+
6
+ //#region src/intents/intent-payload-builder.ts
7
+ /**
8
+ * Fluent builder for constructing intent payloads with environment context.
9
+ * Provides a convenient API for generating intents that can be signed with different standards.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
14
+ *
15
+ * // Build an intent payload
16
+ * const payload = await sdk.intentBuilder()
17
+ * .setSigner('0x1234...') // EVM address or NEAR account
18
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
19
+ * .addIntent({
20
+ * intent: 'ft_withdraw',
21
+ * token: 'usdc.omft.near',
22
+ * amount: '1000000',
23
+ * receiver_id: 'user.near'
24
+ * })
25
+ * .build();
26
+ *
27
+ * // Sign with your preferred method
28
+ * const multiPayload = await signer.signIntent(payload);
29
+ * ```
30
+ */
31
+ var IntentPayloadBuilder = class IntentPayloadBuilder {
32
+ constructor(config) {
33
+ this.intents = [];
34
+ this.envConfig = config.envConfig;
35
+ this.saltManager = config.saltManager;
36
+ this.verifyingContract = this.envConfig.contractID;
37
+ }
38
+ /**
39
+ * Set the signer ID (address or account that will sign the intent).
40
+ * Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
41
+ *
42
+ * @param signerId - The identifier of the signer (must be a valid NEAR account ID)
43
+ * @returns The builder instance for chaining with updated type
44
+ * @throws Error if signerId is not a valid NEAR account ID
45
+ */
46
+ setSigner(signerId) {
47
+ if (!lampamazaza_internal_utils.utils.validateNearAddress(signerId)) throw new Error(`Invalid signer_id: "${signerId}" is not a valid NEAR account ID`);
48
+ this.signerId = signerId;
49
+ return this;
50
+ }
51
+ /**
52
+ * Set the deadline for the intent expiration.
53
+ * If not set, defaults to 1 minute from build time.
54
+ *
55
+ * @param deadline - The expiration time for the intent
56
+ * @returns The builder instance for chaining
57
+ */
58
+ setDeadline(deadline) {
59
+ this.deadline = deadline;
60
+ return this;
61
+ }
62
+ /**
63
+ * Add an intent to the payload.
64
+ * Multiple intents can be added and will execute atomically.
65
+ *
66
+ * @param intent - The intent primitive to add
67
+ * @returns The builder instance for chaining
68
+ */
69
+ addIntent(intent) {
70
+ this.intents.push(intent);
71
+ return this;
72
+ }
73
+ /**
74
+ * Add multiple intents to the payload at once.
75
+ *
76
+ * @param intents - Array of intent primitives to add
77
+ * @returns The builder instance for chaining
78
+ */
79
+ addIntents(intents) {
80
+ this.intents.push(...intents);
81
+ return this;
82
+ }
83
+ /**
84
+ * Override the verifying contract address.
85
+ * Use with caution - normally this is automatically set based on environment.
86
+ *
87
+ * @param contractAddress - The contract address to use
88
+ * @returns The builder instance for chaining
89
+ */
90
+ setVerifyingContract(contractAddress) {
91
+ this.verifyingContract = contractAddress;
92
+ return this;
93
+ }
94
+ /**
95
+ * Set a custom nonce. If not provided, a nonce will be automatically generated.
96
+ * The nonce must be a valid versioned nonce format.
97
+ *
98
+ * @param nonce - Custom nonce string (base64 encoded)
99
+ * @returns The builder instance for chaining
100
+ */
101
+ setNonce(nonce) {
102
+ this.customNonce = nonce;
103
+ return this;
104
+ }
105
+ /**
106
+ * Clear all intents from the builder.
107
+ *
108
+ * @returns The builder instance for chaining
109
+ */
110
+ clearIntents() {
111
+ this.intents = [];
112
+ return this;
113
+ }
114
+ /**
115
+ * Reset the builder to its initial state.
116
+ * Keeps environment and salt manager but clears all user-set values.
117
+ *
118
+ * @returns The builder instance for chaining
119
+ */
120
+ reset() {
121
+ this.signerId = void 0;
122
+ this.deadline = void 0;
123
+ this.intents = [];
124
+ this.customNonce = void 0;
125
+ this.verifyingContract = this.envConfig.contractID;
126
+ return this;
127
+ }
128
+ /**
129
+ * Build the intent payload using a custom salt.
130
+ * Use this method if you need explicit control over the salt.
131
+ *
132
+ * @param salt - The salt to use for nonce generation
133
+ * @returns The constructed intent payload with appropriate typing
134
+ */
135
+ buildWithSalt(salt) {
136
+ const deadline = this.deadline ?? new Date(Date.now() + require_intent_payload_factory.DEFAULT_DEADLINE_MS);
137
+ const nonceDeadline = new Date(deadline.getTime() + require_intent_payload_factory.DEFAULT_NONCE_DEADLINE_OFFSET_MS);
138
+ const nonce = this.customNonce ?? require_expirable_nonce.VersionedNonceBuilder.encodeNonce(salt, nonceDeadline);
139
+ return {
140
+ verifying_contract: this.verifyingContract,
141
+ signer_id: this.signerId,
142
+ deadline: deadline.toISOString(),
143
+ nonce,
144
+ intents: [...this.intents]
145
+ };
146
+ }
147
+ /**
148
+ * Build the intent payload. Automatically fetches a fresh salt if needed.
149
+ * This is the recommended method for most use cases.
150
+ *
151
+ * @returns Promise resolving to the constructed intent payload with appropriate typing
152
+ */
153
+ async build() {
154
+ const salt = await this.saltManager.getCachedSalt();
155
+ return this.buildWithSalt(salt);
156
+ }
157
+ /**
158
+ * Build and sign the intent payload in one step.
159
+ * Convenience method that combines build() and signing.
160
+ *
161
+ * @param signer - The intent signer to use
162
+ * @returns Promise resolving to the signed multi-payload and the raw payload
163
+ */
164
+ async buildAndSign(signer) {
165
+ const payload = await this.build();
166
+ return {
167
+ signed: await signer.signIntent(payload),
168
+ payload
169
+ };
170
+ }
171
+ /**
172
+ * Create a new builder instance with the same configuration.
173
+ * Useful when you need multiple independent builders.
174
+ *
175
+ * @returns A new IntentPayloadBuilder instance
176
+ */
177
+ clone() {
178
+ const builder = new IntentPayloadBuilder({
179
+ envConfig: this.envConfig,
180
+ saltManager: this.saltManager
181
+ });
182
+ builder.verifyingContract = this.verifyingContract;
183
+ builder.signerId = this.signerId;
184
+ builder.deadline = this.deadline;
185
+ builder.intents = [...this.intents];
186
+ builder.customNonce = this.customNonce;
187
+ return builder;
188
+ }
189
+ /**
190
+ * Get the current state of the builder as a plain object.
191
+ * Useful for debugging or inspecting the builder configuration.
192
+ *
193
+ * @returns Object containing the current builder state
194
+ */
195
+ getState() {
196
+ return {
197
+ envConfig: this.envConfig,
198
+ verifyingContract: this.verifyingContract,
199
+ signerId: this.signerId,
200
+ deadline: this.deadline,
201
+ intents: [...this.intents],
202
+ customNonce: this.customNonce
203
+ };
204
+ }
205
+ };
206
+
207
+ //#endregion
208
+ exports.IntentPayloadBuilder = IntentPayloadBuilder;
@@ -0,0 +1,161 @@
1
+ import { Salt } from "./expirable-nonce.cjs";
2
+ import { IntentPayload, IntentPrimitive, MultiPayload } from "./shared-types.cjs";
3
+ import { IIntentSigner } from "./interfaces/intent-signer.cjs";
4
+ import { ISaltManager } from "./interfaces/salt-manager.cjs";
5
+ import { EnvConfig } from "lampamazaza-internal-utils";
6
+
7
+ //#region src/intents/intent-payload-builder.d.ts
8
+ interface IntentPayloadBuilderConfig {
9
+ envConfig: EnvConfig;
10
+ saltManager: ISaltManager;
11
+ }
12
+ /**
13
+ * Type helper to make signer_id required when HasSigner is true
14
+ */
15
+ type IntentPayloadWithSigner<HasSigner extends boolean> = HasSigner extends true ? IntentPayload & {
16
+ signer_id: string;
17
+ } : IntentPayload;
18
+ /**
19
+ * Fluent builder for constructing intent payloads with environment context.
20
+ * Provides a convenient API for generating intents that can be signed with different standards.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
25
+ *
26
+ * // Build an intent payload
27
+ * const payload = await sdk.intentBuilder()
28
+ * .setSigner('0x1234...') // EVM address or NEAR account
29
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
30
+ * .addIntent({
31
+ * intent: 'ft_withdraw',
32
+ * token: 'usdc.omft.near',
33
+ * amount: '1000000',
34
+ * receiver_id: 'user.near'
35
+ * })
36
+ * .build();
37
+ *
38
+ * // Sign with your preferred method
39
+ * const multiPayload = await signer.signIntent(payload);
40
+ * ```
41
+ */
42
+ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
43
+ private envConfig;
44
+ private saltManager;
45
+ private verifyingContract;
46
+ private signerId?;
47
+ private deadline?;
48
+ private intents;
49
+ private customNonce?;
50
+ constructor(config: IntentPayloadBuilderConfig);
51
+ /**
52
+ * Set the signer ID (address or account that will sign the intent).
53
+ * Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
54
+ *
55
+ * @param signerId - The identifier of the signer (must be a valid NEAR account ID)
56
+ * @returns The builder instance for chaining with updated type
57
+ * @throws Error if signerId is not a valid NEAR account ID
58
+ */
59
+ setSigner(signerId: string): IntentPayloadBuilder<true>;
60
+ /**
61
+ * Set the deadline for the intent expiration.
62
+ * If not set, defaults to 1 minute from build time.
63
+ *
64
+ * @param deadline - The expiration time for the intent
65
+ * @returns The builder instance for chaining
66
+ */
67
+ setDeadline(deadline: Date): this;
68
+ /**
69
+ * Add an intent to the payload.
70
+ * Multiple intents can be added and will execute atomically.
71
+ *
72
+ * @param intent - The intent primitive to add
73
+ * @returns The builder instance for chaining
74
+ */
75
+ addIntent(intent: IntentPrimitive): this;
76
+ /**
77
+ * Add multiple intents to the payload at once.
78
+ *
79
+ * @param intents - Array of intent primitives to add
80
+ * @returns The builder instance for chaining
81
+ */
82
+ addIntents(intents: IntentPrimitive[]): this;
83
+ /**
84
+ * Override the verifying contract address.
85
+ * Use with caution - normally this is automatically set based on environment.
86
+ *
87
+ * @param contractAddress - The contract address to use
88
+ * @returns The builder instance for chaining
89
+ */
90
+ setVerifyingContract(contractAddress: string): this;
91
+ /**
92
+ * Set a custom nonce. If not provided, a nonce will be automatically generated.
93
+ * The nonce must be a valid versioned nonce format.
94
+ *
95
+ * @param nonce - Custom nonce string (base64 encoded)
96
+ * @returns The builder instance for chaining
97
+ */
98
+ setNonce(nonce: string): this;
99
+ /**
100
+ * Clear all intents from the builder.
101
+ *
102
+ * @returns The builder instance for chaining
103
+ */
104
+ clearIntents(): this;
105
+ /**
106
+ * Reset the builder to its initial state.
107
+ * Keeps environment and salt manager but clears all user-set values.
108
+ *
109
+ * @returns The builder instance for chaining
110
+ */
111
+ reset(): IntentPayloadBuilder<false>;
112
+ /**
113
+ * Build the intent payload using a custom salt.
114
+ * Use this method if you need explicit control over the salt.
115
+ *
116
+ * @param salt - The salt to use for nonce generation
117
+ * @returns The constructed intent payload with appropriate typing
118
+ */
119
+ buildWithSalt(salt: Salt): IntentPayloadWithSigner<HasSigner>;
120
+ /**
121
+ * Build the intent payload. Automatically fetches a fresh salt if needed.
122
+ * This is the recommended method for most use cases.
123
+ *
124
+ * @returns Promise resolving to the constructed intent payload with appropriate typing
125
+ */
126
+ build(): Promise<IntentPayloadWithSigner<HasSigner>>;
127
+ /**
128
+ * Build and sign the intent payload in one step.
129
+ * Convenience method that combines build() and signing.
130
+ *
131
+ * @param signer - The intent signer to use
132
+ * @returns Promise resolving to the signed multi-payload and the raw payload
133
+ */
134
+ buildAndSign(signer: IIntentSigner): Promise<{
135
+ signed: MultiPayload;
136
+ payload: IntentPayloadWithSigner<HasSigner>;
137
+ }>;
138
+ /**
139
+ * Create a new builder instance with the same configuration.
140
+ * Useful when you need multiple independent builders.
141
+ *
142
+ * @returns A new IntentPayloadBuilder instance
143
+ */
144
+ clone(): IntentPayloadBuilder<HasSigner>;
145
+ /**
146
+ * Get the current state of the builder as a plain object.
147
+ * Useful for debugging or inspecting the builder configuration.
148
+ *
149
+ * @returns Object containing the current builder state
150
+ */
151
+ getState(): {
152
+ envConfig: EnvConfig;
153
+ verifyingContract: string;
154
+ signerId?: string;
155
+ deadline?: Date;
156
+ intents: IntentPrimitive[];
157
+ customNonce?: string;
158
+ };
159
+ }
160
+ //#endregion
161
+ export { IntentPayloadBuilder };
@@ -0,0 +1,161 @@
1
+ import { Salt } from "./expirable-nonce.js";
2
+ import { IntentPayload, IntentPrimitive, MultiPayload } from "./shared-types.js";
3
+ import { IIntentSigner } from "./interfaces/intent-signer.js";
4
+ import { ISaltManager } from "./interfaces/salt-manager.js";
5
+ import { EnvConfig } from "lampamazaza-internal-utils";
6
+
7
+ //#region src/intents/intent-payload-builder.d.ts
8
+ interface IntentPayloadBuilderConfig {
9
+ envConfig: EnvConfig;
10
+ saltManager: ISaltManager;
11
+ }
12
+ /**
13
+ * Type helper to make signer_id required when HasSigner is true
14
+ */
15
+ type IntentPayloadWithSigner<HasSigner extends boolean> = HasSigner extends true ? IntentPayload & {
16
+ signer_id: string;
17
+ } : IntentPayload;
18
+ /**
19
+ * Fluent builder for constructing intent payloads with environment context.
20
+ * Provides a convenient API for generating intents that can be signed with different standards.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
25
+ *
26
+ * // Build an intent payload
27
+ * const payload = await sdk.intentBuilder()
28
+ * .setSigner('0x1234...') // EVM address or NEAR account
29
+ * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
30
+ * .addIntent({
31
+ * intent: 'ft_withdraw',
32
+ * token: 'usdc.omft.near',
33
+ * amount: '1000000',
34
+ * receiver_id: 'user.near'
35
+ * })
36
+ * .build();
37
+ *
38
+ * // Sign with your preferred method
39
+ * const multiPayload = await signer.signIntent(payload);
40
+ * ```
41
+ */
42
+ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
43
+ private envConfig;
44
+ private saltManager;
45
+ private verifyingContract;
46
+ private signerId?;
47
+ private deadline?;
48
+ private intents;
49
+ private customNonce?;
50
+ constructor(config: IntentPayloadBuilderConfig);
51
+ /**
52
+ * Set the signer ID (address or account that will sign the intent).
53
+ * Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
54
+ *
55
+ * @param signerId - The identifier of the signer (must be a valid NEAR account ID)
56
+ * @returns The builder instance for chaining with updated type
57
+ * @throws Error if signerId is not a valid NEAR account ID
58
+ */
59
+ setSigner(signerId: string): IntentPayloadBuilder<true>;
60
+ /**
61
+ * Set the deadline for the intent expiration.
62
+ * If not set, defaults to 1 minute from build time.
63
+ *
64
+ * @param deadline - The expiration time for the intent
65
+ * @returns The builder instance for chaining
66
+ */
67
+ setDeadline(deadline: Date): this;
68
+ /**
69
+ * Add an intent to the payload.
70
+ * Multiple intents can be added and will execute atomically.
71
+ *
72
+ * @param intent - The intent primitive to add
73
+ * @returns The builder instance for chaining
74
+ */
75
+ addIntent(intent: IntentPrimitive): this;
76
+ /**
77
+ * Add multiple intents to the payload at once.
78
+ *
79
+ * @param intents - Array of intent primitives to add
80
+ * @returns The builder instance for chaining
81
+ */
82
+ addIntents(intents: IntentPrimitive[]): this;
83
+ /**
84
+ * Override the verifying contract address.
85
+ * Use with caution - normally this is automatically set based on environment.
86
+ *
87
+ * @param contractAddress - The contract address to use
88
+ * @returns The builder instance for chaining
89
+ */
90
+ setVerifyingContract(contractAddress: string): this;
91
+ /**
92
+ * Set a custom nonce. If not provided, a nonce will be automatically generated.
93
+ * The nonce must be a valid versioned nonce format.
94
+ *
95
+ * @param nonce - Custom nonce string (base64 encoded)
96
+ * @returns The builder instance for chaining
97
+ */
98
+ setNonce(nonce: string): this;
99
+ /**
100
+ * Clear all intents from the builder.
101
+ *
102
+ * @returns The builder instance for chaining
103
+ */
104
+ clearIntents(): this;
105
+ /**
106
+ * Reset the builder to its initial state.
107
+ * Keeps environment and salt manager but clears all user-set values.
108
+ *
109
+ * @returns The builder instance for chaining
110
+ */
111
+ reset(): IntentPayloadBuilder<false>;
112
+ /**
113
+ * Build the intent payload using a custom salt.
114
+ * Use this method if you need explicit control over the salt.
115
+ *
116
+ * @param salt - The salt to use for nonce generation
117
+ * @returns The constructed intent payload with appropriate typing
118
+ */
119
+ buildWithSalt(salt: Salt): IntentPayloadWithSigner<HasSigner>;
120
+ /**
121
+ * Build the intent payload. Automatically fetches a fresh salt if needed.
122
+ * This is the recommended method for most use cases.
123
+ *
124
+ * @returns Promise resolving to the constructed intent payload with appropriate typing
125
+ */
126
+ build(): Promise<IntentPayloadWithSigner<HasSigner>>;
127
+ /**
128
+ * Build and sign the intent payload in one step.
129
+ * Convenience method that combines build() and signing.
130
+ *
131
+ * @param signer - The intent signer to use
132
+ * @returns Promise resolving to the signed multi-payload and the raw payload
133
+ */
134
+ buildAndSign(signer: IIntentSigner): Promise<{
135
+ signed: MultiPayload;
136
+ payload: IntentPayloadWithSigner<HasSigner>;
137
+ }>;
138
+ /**
139
+ * Create a new builder instance with the same configuration.
140
+ * Useful when you need multiple independent builders.
141
+ *
142
+ * @returns A new IntentPayloadBuilder instance
143
+ */
144
+ clone(): IntentPayloadBuilder<HasSigner>;
145
+ /**
146
+ * Get the current state of the builder as a plain object.
147
+ * Useful for debugging or inspecting the builder configuration.
148
+ *
149
+ * @returns Object containing the current builder state
150
+ */
151
+ getState(): {
152
+ envConfig: EnvConfig;
153
+ verifyingContract: string;
154
+ signerId?: string;
155
+ deadline?: Date;
156
+ intents: IntentPrimitive[];
157
+ customNonce?: string;
158
+ };
159
+ }
160
+ //#endregion
161
+ export { IntentPayloadBuilder };