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.
- package/LICENSE +21 -0
- package/README.md +1083 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +19 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
- package/dist/src/bridges/direct-bridge/error.cjs +16 -0
- package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
- package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
- package/dist/src/bridges/direct-bridge/error.js +15 -0
- package/dist/src/bridges/hot-bridge/error.cjs +23 -0
- package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
- package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
- package/dist/src/bridges/hot-bridge/error.js +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
- package/dist/src/bridges/omni-bridge/error.cjs +54 -0
- package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
- package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
- package/dist/src/bridges/omni-bridge/error.js +49 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
- package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
- package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
- package/dist/src/classes/errors.cjs +87 -0
- package/dist/src/classes/errors.d.cts +48 -0
- package/dist/src/classes/errors.d.ts +48 -0
- package/dist/src/classes/errors.js +81 -0
- package/dist/src/constants/bridge-name-enum.cjs +11 -0
- package/dist/src/constants/bridge-name-enum.d.cts +11 -0
- package/dist/src/constants/bridge-name-enum.d.ts +11 -0
- package/dist/src/constants/bridge-name-enum.js +10 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
- package/dist/src/constants/public-rpc-urls.cjs +25 -0
- package/dist/src/constants/public-rpc-urls.js +24 -0
- package/dist/src/constants/route-enum.cjs +13 -0
- package/dist/src/constants/route-enum.d.cts +13 -0
- package/dist/src/constants/route-enum.d.ts +13 -0
- package/dist/src/constants/route-enum.js +12 -0
- package/dist/src/constants/withdrawal-timing.cjs +68 -0
- package/dist/src/constants/withdrawal-timing.js +68 -0
- package/dist/src/core/withdrawal-watcher.cjs +86 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +19 -0
- package/dist/src/core/withdrawal-watcher.js +82 -0
- package/dist/src/intents/expirable-nonce.cjs +90 -0
- package/dist/src/intents/expirable-nonce.d.cts +44 -0
- package/dist/src/intents/expirable-nonce.d.ts +45 -0
- package/dist/src/intents/expirable-nonce.js +82 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
- package/dist/src/intents/intent-hash.cjs +48 -0
- package/dist/src/intents/intent-hash.d.cts +8 -0
- package/dist/src/intents/intent-hash.d.ts +8 -0
- package/dist/src/intents/intent-hash.js +47 -0
- package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
- package/dist/src/intents/intent-hashes/erc191.js +37 -0
- package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
- package/dist/src/intents/intent-hashes/nep413.js +22 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
- package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
- package/dist/src/intents/intent-hashes/sep53.js +35 -0
- package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
- package/dist/src/intents/intent-hashes/tip191.js +38 -0
- package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
- package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
- package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
- package/dist/src/intents/intent-hashes/webauthn.js +25 -0
- package/dist/src/intents/intent-payload-builder.cjs +208 -0
- package/dist/src/intents/intent-payload-builder.d.cts +161 -0
- package/dist/src/intents/intent-payload-builder.d.ts +161 -0
- package/dist/src/intents/intent-payload-builder.js +207 -0
- package/dist/src/intents/intent-payload-factory.cjs +23 -0
- package/dist/src/intents/intent-payload-factory.js +21 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
- package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
- package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.js +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
- package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
- package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
- package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
- package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
- package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
- package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
- package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
- package/dist/src/intents/salt-manager.cjs +74 -0
- package/dist/src/intents/salt-manager.js +72 -0
- package/dist/src/intents/shared-types.d.cts +20 -0
- package/dist/src/intents/shared-types.d.ts +20 -0
- package/dist/src/lib/array.cjs +11 -0
- package/dist/src/lib/array.js +10 -0
- package/dist/src/lib/caip2.cjs +50 -0
- package/dist/src/lib/caip2.d.cts +38 -0
- package/dist/src/lib/caip2.d.ts +38 -0
- package/dist/src/lib/caip2.js +48 -0
- package/dist/src/lib/configure-rpc-config.cjs +20 -0
- package/dist/src/lib/configure-rpc-config.js +18 -0
- package/dist/src/lib/estimate-fee.cjs +96 -0
- package/dist/src/lib/estimate-fee.js +94 -0
- package/dist/src/lib/hex.cjs +11 -0
- package/dist/src/lib/hex.js +10 -0
- package/dist/src/lib/nep413.cjs +42 -0
- package/dist/src/lib/nep413.d.cts +14 -0
- package/dist/src/lib/nep413.d.ts +14 -0
- package/dist/src/lib/nep413.js +41 -0
- package/dist/src/lib/object.cjs +10 -0
- package/dist/src/lib/object.js +9 -0
- package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
- package/dist/src/lib/parse-defuse-asset-id.js +14 -0
- package/dist/src/lib/route-config-factory.cjs +43 -0
- package/dist/src/lib/route-config-factory.d.cts +13 -0
- package/dist/src/lib/route-config-factory.d.ts +13 -0
- package/dist/src/lib/route-config-factory.js +37 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
- package/dist/src/lib/validateAddress.cjs +271 -0
- package/dist/src/lib/validateAddress.d.cts +14 -0
- package/dist/src/lib/validateAddress.d.ts +14 -0
- package/dist/src/lib/validateAddress.js +270 -0
- package/dist/src/sdk.cjs +435 -0
- package/dist/src/sdk.d.cts +231 -0
- package/dist/src/sdk.d.ts +231 -0
- package/dist/src/sdk.js +433 -0
- package/dist/src/shared-types.d.cts +378 -0
- package/dist/src/shared-types.d.ts +378 -0
- 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 };
|