@caatinga/client 0.2.4 → 2.0.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/README.md +1 -1
- package/dist/index.cjs +227 -189
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +227 -189
- package/dist/stellar-wallets-kit.cjs +60 -62
- package/dist/stellar-wallets-kit.d.cts +24 -25
- package/dist/stellar-wallets-kit.d.ts +24 -25
- package/dist/stellar-wallets-kit.js +64 -63
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -8,12 +8,38 @@ function resolveContractId(input) {
|
|
|
8
8
|
if (contractId) {
|
|
9
9
|
return contractId;
|
|
10
10
|
}
|
|
11
|
+
const hint = formatMissingContractArtifactHint(input.artifacts, input.network, input.contract);
|
|
11
12
|
throw new CaatingaError(
|
|
12
13
|
`No contract artifact found for "${input.contract}" on "${input.network}".`,
|
|
13
14
|
CaatingaErrorCode.CONTRACT_ARTIFACT_NOT_FOUND,
|
|
14
|
-
|
|
15
|
+
hint
|
|
15
16
|
);
|
|
16
17
|
}
|
|
18
|
+
function formatMissingContractArtifactHint(artifacts, network, contract) {
|
|
19
|
+
const deployCommand = `caatinga deploy ${contract} --network ${network} --source <identity>`;
|
|
20
|
+
const buildNote = "caatinga build does not register a contract ID.";
|
|
21
|
+
if (Object.keys(artifacts.networks).length === 0) {
|
|
22
|
+
return [
|
|
23
|
+
"caatinga.artifacts.json has no network scaffold.",
|
|
24
|
+
`Run caatinga doctor --network ${network} to inspect deploy readiness, then run: ${deployCommand}.`,
|
|
25
|
+
buildNote,
|
|
26
|
+
"Or pass contractId in the client registration."
|
|
27
|
+
].join(" ");
|
|
28
|
+
}
|
|
29
|
+
if (!artifacts.networks[network]) {
|
|
30
|
+
return [
|
|
31
|
+
`No artifacts exist for network "${network}".`,
|
|
32
|
+
`Run: ${deployCommand}.`,
|
|
33
|
+
buildNote,
|
|
34
|
+
"Or pass contractId in the client registration."
|
|
35
|
+
].join(" ");
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
`Contract "${contract}" is not deployed on "${network}".`,
|
|
39
|
+
`Run: ${deployCommand}.`,
|
|
40
|
+
"Or pass contractId in the client registration."
|
|
41
|
+
].join(" ");
|
|
42
|
+
}
|
|
17
43
|
|
|
18
44
|
// src/bindings/default-binding-adapter.ts
|
|
19
45
|
import { CaatingaError as CaatingaError2, CaatingaErrorCode as CaatingaErrorCode2 } from "@caatinga/core/browser";
|
|
@@ -50,10 +76,10 @@ function createDefaultBindingAdapter(binding) {
|
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
// src/client/create-caatinga-client.ts
|
|
53
|
-
import { CaatingaError as
|
|
79
|
+
import { CaatingaError as CaatingaError8, CaatingaErrorCode as CaatingaErrorCode8 } from "@caatinga/core/browser";
|
|
54
80
|
|
|
55
81
|
// src/client/caatinga-contract-client.ts
|
|
56
|
-
import { CaatingaError as
|
|
82
|
+
import { CaatingaError as CaatingaError7, CaatingaErrorCode as CaatingaErrorCode7 } from "@caatinga/core/browser";
|
|
57
83
|
|
|
58
84
|
// src/xdr/build-xdr.ts
|
|
59
85
|
import { CaatingaError as CaatingaError3, CaatingaErrorCode as CaatingaErrorCode3 } from "@caatinga/core/browser";
|
|
@@ -112,6 +138,188 @@ function readXdr(transaction) {
|
|
|
112
138
|
return candidate.toXDR();
|
|
113
139
|
}
|
|
114
140
|
|
|
141
|
+
// src/wallet/with-wallet-timeout.ts
|
|
142
|
+
import { CaatingaError as CaatingaError4, CaatingaErrorCode as CaatingaErrorCode4 } from "@caatinga/core/browser";
|
|
143
|
+
function withWalletTimeout(label, timeoutMs, fn) {
|
|
144
|
+
if (timeoutMs === void 0 || timeoutMs <= 0) {
|
|
145
|
+
return fn();
|
|
146
|
+
}
|
|
147
|
+
let timedOut = false;
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const timer = setTimeout(() => {
|
|
150
|
+
timedOut = true;
|
|
151
|
+
reject(
|
|
152
|
+
new CaatingaError4(
|
|
153
|
+
`Wallet "${label}" timed out after ${timeoutMs}ms.`,
|
|
154
|
+
CaatingaErrorCode4.WALLET_TIMEOUT,
|
|
155
|
+
"Ensure the wallet adapter rejects on user dismissal, or increase walletTimeout."
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
}, timeoutMs);
|
|
159
|
+
fn().then(
|
|
160
|
+
(value) => {
|
|
161
|
+
if (timedOut) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
resolve(value);
|
|
166
|
+
},
|
|
167
|
+
(error) => {
|
|
168
|
+
if (timedOut) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
reject(error);
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/client/invoke-args.ts
|
|
179
|
+
function splitArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
180
|
+
return {
|
|
181
|
+
args: argsOrOptions,
|
|
182
|
+
debugRaw: maybeOptions?.debugRaw ?? false
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
186
|
+
const looksLikeOptions = argsOrOptions !== void 0 && ("debugXdr" in argsOrOptions || "debugRaw" in argsOrOptions) && maybeOptions === void 0;
|
|
187
|
+
if (looksLikeOptions) {
|
|
188
|
+
const options = argsOrOptions;
|
|
189
|
+
return {
|
|
190
|
+
args: void 0,
|
|
191
|
+
debugXdr: options.debugXdr ?? false,
|
|
192
|
+
debugRaw: options.debugRaw ?? false
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
args: argsOrOptions,
|
|
197
|
+
debugXdr: maybeOptions?.debugXdr ?? false,
|
|
198
|
+
debugRaw: maybeOptions?.debugRaw ?? false
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function splitReadArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
202
|
+
const looksLikeOptions = argsOrOptions !== void 0 && "debugRaw" in argsOrOptions && maybeOptions === void 0;
|
|
203
|
+
if (looksLikeOptions) {
|
|
204
|
+
const options = argsOrOptions;
|
|
205
|
+
return {
|
|
206
|
+
args: void 0,
|
|
207
|
+
debugRaw: options.debugRaw ?? false
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
args: argsOrOptions,
|
|
212
|
+
debugRaw: maybeOptions?.debugRaw ?? false
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/client/transaction-simulate.ts
|
|
217
|
+
import { CaatingaError as CaatingaError5, CaatingaErrorCode as CaatingaErrorCode5 } from "@caatinga/core/browser";
|
|
218
|
+
async function prepareReadTransaction(transaction, contractName, method, rpcUrl) {
|
|
219
|
+
const candidate = transaction;
|
|
220
|
+
if (typeof candidate.prepare !== "function") {
|
|
221
|
+
return transaction;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
return await candidate.prepare.call(transaction);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof CaatingaError5) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
throw new CaatingaError5(
|
|
230
|
+
`Failed to prepare XDR for "${contractName}.${method}".`,
|
|
231
|
+
CaatingaErrorCode5.XDR_PREPARE_FAILED,
|
|
232
|
+
`RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
|
|
233
|
+
error
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function readSimulationResult(raw, contractName, method) {
|
|
238
|
+
if (raw !== null && typeof raw === "object" && "result" in raw) {
|
|
239
|
+
const result = raw.result;
|
|
240
|
+
if (result !== void 0) {
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
throw new CaatingaError5(
|
|
245
|
+
`Simulation for "${contractName}.${method}" did not return a result.`,
|
|
246
|
+
CaatingaErrorCode5.READ_RESULT_MISSING,
|
|
247
|
+
`Expected "${contractName}.${method}" to expose a simulation result. Use debugRaw to inspect the generated binding output.`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/client/transaction-submit.ts
|
|
252
|
+
import { CaatingaError as CaatingaError6, CaatingaErrorCode as CaatingaErrorCode6 } from "@caatinga/core/browser";
|
|
253
|
+
async function submitTransaction(transaction, signTransaction, contractName, method, rpcUrl) {
|
|
254
|
+
const candidate = transaction;
|
|
255
|
+
if (typeof candidate.signAndSend === "function") {
|
|
256
|
+
try {
|
|
257
|
+
const raw = await candidate.signAndSend.call(transaction, { signTransaction });
|
|
258
|
+
assertSubmitResultRecognized(raw, contractName, method);
|
|
259
|
+
return raw;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (error instanceof CaatingaError6) {
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
throw new CaatingaError6(
|
|
265
|
+
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
266
|
+
CaatingaErrorCode6.XDR_SUBMIT_FAILED,
|
|
267
|
+
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
268
|
+
error
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (typeof candidate.send === "function") {
|
|
273
|
+
try {
|
|
274
|
+
const raw = await candidate.send.call(transaction);
|
|
275
|
+
assertSubmitResultRecognized(raw, contractName, method);
|
|
276
|
+
return raw;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (error instanceof CaatingaError6) {
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
throw new CaatingaError6(
|
|
282
|
+
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
283
|
+
CaatingaErrorCode6.XDR_SUBMIT_FAILED,
|
|
284
|
+
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
285
|
+
error
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
throw new CaatingaError6(
|
|
290
|
+
`Binding transaction for "${contractName}.${method}" cannot be submitted.`,
|
|
291
|
+
CaatingaErrorCode6.XDR_SUBMIT_FAILED,
|
|
292
|
+
"Regenerate bindings or provide a compatible binding adapter."
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
function assertSubmitResultRecognized(raw, contractName, method) {
|
|
296
|
+
if (raw === null || typeof raw !== "object") {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const record = raw;
|
|
300
|
+
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record || hasNestedSendTransactionResponseHash(record);
|
|
301
|
+
const hasResult = "result" in record;
|
|
302
|
+
if (hasTransactionId || hasResult) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
throw new CaatingaError6(
|
|
306
|
+
`Submit returned an unrecognized payload for "${contractName}.${method}".`,
|
|
307
|
+
CaatingaErrorCode6.XDR_RESULT_FAILED,
|
|
308
|
+
"Expected txHash, transactionHash, hash, sendTransactionResponse.hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
function hasNestedSendTransactionResponseHash(record) {
|
|
312
|
+
const response = record.sendTransactionResponse;
|
|
313
|
+
return response !== null && typeof response === "object" && "hash" in response;
|
|
314
|
+
}
|
|
315
|
+
function normalizeSubmitResult(raw) {
|
|
316
|
+
const candidate = raw;
|
|
317
|
+
return {
|
|
318
|
+
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash ?? candidate.sendTransactionResponse?.hash,
|
|
319
|
+
result: candidate.result
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
115
323
|
// src/client/caatinga-contract-client.ts
|
|
116
324
|
var CaatingaContractClient = class {
|
|
117
325
|
constructor(config, contractName, registration, bindingAdapter = createDefaultBindingAdapter(
|
|
@@ -152,28 +360,29 @@ var CaatingaContractClient = class {
|
|
|
152
360
|
let signedXdr;
|
|
153
361
|
const signTransaction = async (xdr2) => {
|
|
154
362
|
try {
|
|
155
|
-
signedXdr = await
|
|
363
|
+
signedXdr = await withWalletTimeout(
|
|
156
364
|
"signTransaction",
|
|
365
|
+
this.config.walletTimeout,
|
|
157
366
|
() => this.config.wallet.signTransaction({
|
|
158
367
|
xdr: xdr2,
|
|
159
368
|
networkPassphrase: this.config.network.networkPassphrase
|
|
160
369
|
})
|
|
161
370
|
);
|
|
162
371
|
} catch (error) {
|
|
163
|
-
if (error instanceof
|
|
372
|
+
if (error instanceof CaatingaError7) {
|
|
164
373
|
throw error;
|
|
165
374
|
}
|
|
166
|
-
throw new
|
|
375
|
+
throw new CaatingaError7(
|
|
167
376
|
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
168
|
-
|
|
377
|
+
CaatingaErrorCode7.XDR_SIGN_FAILED,
|
|
169
378
|
"Connect a wallet and approve the transaction.",
|
|
170
379
|
error
|
|
171
380
|
);
|
|
172
381
|
}
|
|
173
382
|
if (typeof signedXdr !== "string" || signedXdr.trim().length === 0) {
|
|
174
|
-
throw new
|
|
383
|
+
throw new CaatingaError7(
|
|
175
384
|
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
176
|
-
|
|
385
|
+
CaatingaErrorCode7.XDR_SIGN_FAILED,
|
|
177
386
|
"Wallet returned an empty or invalid signed XDR. The user may have dismissed the signing prompt.",
|
|
178
387
|
signedXdr
|
|
179
388
|
);
|
|
@@ -188,9 +397,9 @@ var CaatingaContractClient = class {
|
|
|
188
397
|
this.config.network.rpcUrl
|
|
189
398
|
);
|
|
190
399
|
if (typeof transaction.signAndSend === "function" && signedXdr === void 0) {
|
|
191
|
-
throw new
|
|
400
|
+
throw new CaatingaError7(
|
|
192
401
|
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
193
|
-
|
|
402
|
+
CaatingaErrorCode7.XDR_SIGN_FAILED,
|
|
194
403
|
"Wallet returned an empty or invalid signed XDR. The generated transaction did not request a wallet signature."
|
|
195
404
|
);
|
|
196
405
|
}
|
|
@@ -244,17 +453,18 @@ var CaatingaContractClient = class {
|
|
|
244
453
|
});
|
|
245
454
|
let publicKey;
|
|
246
455
|
try {
|
|
247
|
-
publicKey = await
|
|
456
|
+
publicKey = await withWalletTimeout(
|
|
248
457
|
"getPublicKey",
|
|
458
|
+
this.config.walletTimeout,
|
|
249
459
|
() => this.config.wallet.getPublicKey()
|
|
250
460
|
);
|
|
251
461
|
} catch (error) {
|
|
252
|
-
if (error instanceof
|
|
462
|
+
if (error instanceof CaatingaError7) {
|
|
253
463
|
throw error;
|
|
254
464
|
}
|
|
255
|
-
throw new
|
|
465
|
+
throw new CaatingaError7(
|
|
256
466
|
`Wallet is not connected or the public key is unavailable for "${this.contractName}".`,
|
|
257
|
-
|
|
467
|
+
CaatingaErrorCode7.WALLET_NOT_CONNECTED,
|
|
258
468
|
"Connect the wallet and grant account access, then retry.",
|
|
259
469
|
error
|
|
260
470
|
);
|
|
@@ -268,179 +478,7 @@ var CaatingaContractClient = class {
|
|
|
268
478
|
const transaction = await this.bindingAdapter.callMethod({ client, method, args });
|
|
269
479
|
return { contractId, transaction };
|
|
270
480
|
}
|
|
271
|
-
withWalletTimeout(label, fn) {
|
|
272
|
-
const timeoutMs = this.config.walletTimeout;
|
|
273
|
-
if (timeoutMs === void 0 || timeoutMs <= 0) {
|
|
274
|
-
return fn();
|
|
275
|
-
}
|
|
276
|
-
let timedOut = false;
|
|
277
|
-
return new Promise((resolve, reject) => {
|
|
278
|
-
const timer = setTimeout(() => {
|
|
279
|
-
timedOut = true;
|
|
280
|
-
reject(
|
|
281
|
-
new CaatingaError4(
|
|
282
|
-
`Wallet "${label}" timed out after ${timeoutMs}ms.`,
|
|
283
|
-
CaatingaErrorCode4.WALLET_TIMEOUT,
|
|
284
|
-
"Ensure the wallet adapter rejects on user dismissal, or increase walletTimeout."
|
|
285
|
-
)
|
|
286
|
-
);
|
|
287
|
-
}, timeoutMs);
|
|
288
|
-
fn().then(
|
|
289
|
-
(value) => {
|
|
290
|
-
if (timedOut) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
clearTimeout(timer);
|
|
294
|
-
resolve(value);
|
|
295
|
-
},
|
|
296
|
-
(error) => {
|
|
297
|
-
if (timedOut) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
clearTimeout(timer);
|
|
301
|
-
reject(error);
|
|
302
|
-
}
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
481
|
};
|
|
307
|
-
function splitArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
308
|
-
return {
|
|
309
|
-
args: argsOrOptions,
|
|
310
|
-
debugRaw: maybeOptions?.debugRaw ?? false
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
314
|
-
const looksLikeOptions = argsOrOptions !== void 0 && ("debugXdr" in argsOrOptions || "debugRaw" in argsOrOptions) && maybeOptions === void 0;
|
|
315
|
-
if (looksLikeOptions) {
|
|
316
|
-
const options = argsOrOptions;
|
|
317
|
-
return {
|
|
318
|
-
args: void 0,
|
|
319
|
-
debugXdr: options.debugXdr ?? false,
|
|
320
|
-
debugRaw: options.debugRaw ?? false
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
return {
|
|
324
|
-
args: argsOrOptions,
|
|
325
|
-
debugXdr: maybeOptions?.debugXdr ?? false,
|
|
326
|
-
debugRaw: maybeOptions?.debugRaw ?? false
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function splitReadArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
330
|
-
const looksLikeOptions = argsOrOptions !== void 0 && "debugRaw" in argsOrOptions && maybeOptions === void 0;
|
|
331
|
-
if (looksLikeOptions) {
|
|
332
|
-
const options = argsOrOptions;
|
|
333
|
-
return {
|
|
334
|
-
args: void 0,
|
|
335
|
-
debugRaw: options.debugRaw ?? false
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
return {
|
|
339
|
-
args: argsOrOptions,
|
|
340
|
-
debugRaw: maybeOptions?.debugRaw ?? false
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
async function submitTransaction(transaction, signTransaction, contractName, method, rpcUrl) {
|
|
344
|
-
const candidate = transaction;
|
|
345
|
-
if (typeof candidate.signAndSend === "function") {
|
|
346
|
-
try {
|
|
347
|
-
const raw = await candidate.signAndSend.call(transaction, { signTransaction });
|
|
348
|
-
assertSubmitResultRecognized(raw, contractName, method);
|
|
349
|
-
return raw;
|
|
350
|
-
} catch (error) {
|
|
351
|
-
if (error instanceof CaatingaError4) {
|
|
352
|
-
throw error;
|
|
353
|
-
}
|
|
354
|
-
throw new CaatingaError4(
|
|
355
|
-
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
356
|
-
CaatingaErrorCode4.XDR_SUBMIT_FAILED,
|
|
357
|
-
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
358
|
-
error
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (typeof candidate.send === "function") {
|
|
363
|
-
try {
|
|
364
|
-
const raw = await candidate.send.call(transaction);
|
|
365
|
-
assertSubmitResultRecognized(raw, contractName, method);
|
|
366
|
-
return raw;
|
|
367
|
-
} catch (error) {
|
|
368
|
-
if (error instanceof CaatingaError4) {
|
|
369
|
-
throw error;
|
|
370
|
-
}
|
|
371
|
-
throw new CaatingaError4(
|
|
372
|
-
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
373
|
-
CaatingaErrorCode4.XDR_SUBMIT_FAILED,
|
|
374
|
-
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
375
|
-
error
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
throw new CaatingaError4(
|
|
380
|
-
`Binding transaction for "${contractName}.${method}" cannot be submitted.`,
|
|
381
|
-
CaatingaErrorCode4.XDR_SUBMIT_FAILED,
|
|
382
|
-
"Regenerate bindings or provide a compatible binding adapter."
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
async function prepareReadTransaction(transaction, contractName, method, rpcUrl) {
|
|
386
|
-
const candidate = transaction;
|
|
387
|
-
if (typeof candidate.prepare !== "function") {
|
|
388
|
-
return transaction;
|
|
389
|
-
}
|
|
390
|
-
try {
|
|
391
|
-
return await candidate.prepare.call(transaction);
|
|
392
|
-
} catch (error) {
|
|
393
|
-
if (error instanceof CaatingaError4) {
|
|
394
|
-
throw error;
|
|
395
|
-
}
|
|
396
|
-
throw new CaatingaError4(
|
|
397
|
-
`Failed to prepare XDR for "${contractName}.${method}".`,
|
|
398
|
-
CaatingaErrorCode4.XDR_PREPARE_FAILED,
|
|
399
|
-
`RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
|
|
400
|
-
error
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
function readSimulationResult(raw, contractName, method) {
|
|
405
|
-
if (raw !== null && typeof raw === "object" && "result" in raw) {
|
|
406
|
-
const result = raw.result;
|
|
407
|
-
if (result !== void 0) {
|
|
408
|
-
return result;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
throw new CaatingaError4(
|
|
412
|
-
`Simulation for "${contractName}.${method}" did not return a result.`,
|
|
413
|
-
CaatingaErrorCode4.READ_RESULT_MISSING,
|
|
414
|
-
`Expected "${contractName}.${method}" to expose a simulation result. Use debugRaw to inspect the generated binding output.`
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
function assertSubmitResultRecognized(raw, contractName, method) {
|
|
418
|
-
if (raw === null || typeof raw !== "object") {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
const record = raw;
|
|
422
|
-
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record || hasNestedSendTransactionResponseHash(record);
|
|
423
|
-
const hasResult = "result" in record;
|
|
424
|
-
if (hasTransactionId || hasResult) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
throw new CaatingaError4(
|
|
428
|
-
`Submit returned an unrecognized payload for "${contractName}.${method}".`,
|
|
429
|
-
CaatingaErrorCode4.XDR_RESULT_FAILED,
|
|
430
|
-
"Expected txHash, transactionHash, hash, sendTransactionResponse.hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
function hasNestedSendTransactionResponseHash(record) {
|
|
434
|
-
const response = record.sendTransactionResponse;
|
|
435
|
-
return response !== null && typeof response === "object" && "hash" in response;
|
|
436
|
-
}
|
|
437
|
-
function normalizeSubmitResult(raw) {
|
|
438
|
-
const candidate = raw;
|
|
439
|
-
return {
|
|
440
|
-
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash ?? candidate.sendTransactionResponse?.hash,
|
|
441
|
-
result: candidate.result
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
482
|
|
|
445
483
|
// src/client/create-caatinga-client.ts
|
|
446
484
|
function createCaatingaClient(config) {
|
|
@@ -448,9 +486,9 @@ function createCaatingaClient(config) {
|
|
|
448
486
|
contract(contractName) {
|
|
449
487
|
const registration = config.contracts[contractName];
|
|
450
488
|
if (!registration) {
|
|
451
|
-
throw new
|
|
489
|
+
throw new CaatingaError8(
|
|
452
490
|
`Contract "${contractName}" is not registered.`,
|
|
453
|
-
|
|
491
|
+
CaatingaErrorCode8.CONTRACT_NOT_FOUND,
|
|
454
492
|
"Add the contract binding to createCaatingaClient()."
|
|
455
493
|
);
|
|
456
494
|
}
|
|
@@ -20,90 +20,88 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/stellar-wallets-kit.ts
|
|
21
21
|
var stellar_wallets_kit_exports = {};
|
|
22
22
|
__export(stellar_wallets_kit_exports, {
|
|
23
|
+
WalletNetwork: () => import_stellar_wallets_kit.WalletNetwork,
|
|
23
24
|
createStellarWalletsKitAdapter: () => createStellarWalletsKitAdapter
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(stellar_wallets_kit_exports);
|
|
26
27
|
|
|
27
28
|
// src/adapters/stellar-wallets-kit.ts
|
|
28
|
-
var import_stellar_wallets_kit = require("stellar-wallets-kit");
|
|
29
|
+
var import_stellar_wallets_kit = require("@creit.tech/stellar-wallets-kit");
|
|
30
|
+
var import_walletconnect = require("@creit.tech/stellar-wallets-kit/modules/walletconnect.module");
|
|
29
31
|
function createStellarWalletsKitAdapter(options = {}) {
|
|
32
|
+
const network = options.network ?? import_stellar_wallets_kit.WalletNetwork.TESTNET;
|
|
30
33
|
const kit = options.kit ?? new import_stellar_wallets_kit.StellarWalletsKit({
|
|
31
|
-
network
|
|
32
|
-
|
|
34
|
+
network,
|
|
35
|
+
selectedWalletId: options.selectedWalletId ?? import_stellar_wallets_kit.FREIGHTER_ID,
|
|
36
|
+
modules: options.modules ?? buildModules(network, options.walletConnectMetadata)
|
|
33
37
|
});
|
|
34
|
-
let
|
|
35
|
-
let isWalletConnectStarted = false;
|
|
36
|
-
const sessionDeletedCallbacks = /* @__PURE__ */ new Set();
|
|
38
|
+
let address;
|
|
37
39
|
return {
|
|
38
40
|
kit,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
setWallet(walletId) {
|
|
42
|
+
kit.setWallet(walletId);
|
|
43
|
+
address = void 0;
|
|
42
44
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
publicKey = void 0;
|
|
45
|
+
getSupportedWallets() {
|
|
46
|
+
return kit.getSupportedWallets();
|
|
46
47
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await kit.startWalletConnect(metadata);
|
|
66
|
-
isWalletConnectStarted = true;
|
|
67
|
-
for (const callback of sessionDeletedCallbacks) {
|
|
68
|
-
kit.onSessionDeleted((sessionId) => {
|
|
69
|
-
publicKey = void 0;
|
|
70
|
-
callback(sessionId);
|
|
48
|
+
openModal(modalOptions = {}) {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
void kit.openModal({
|
|
51
|
+
...modalOptions.modalTitle ? { modalTitle: modalOptions.modalTitle } : {},
|
|
52
|
+
...modalOptions.notAvailableText ? { notAvailableText: modalOptions.notAvailableText } : {},
|
|
53
|
+
onWalletSelected: (option) => {
|
|
54
|
+
kit.setWallet(option.id);
|
|
55
|
+
kit.getAddress().then((result) => {
|
|
56
|
+
address = result.address;
|
|
57
|
+
resolve(result.address);
|
|
58
|
+
}).catch((error) => {
|
|
59
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
onClosed: (error) => {
|
|
63
|
+
modalOptions.onClosed?.(error);
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
71
66
|
});
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
async connectWalletConnect(connectOptions) {
|
|
75
|
-
await kit.connectWalletConnect(connectOptions);
|
|
76
|
-
publicKey = void 0;
|
|
77
|
-
},
|
|
78
|
-
async getWalletConnectSessions() {
|
|
79
|
-
return kit.getSessions();
|
|
67
|
+
});
|
|
80
68
|
},
|
|
81
|
-
|
|
82
|
-
kit.
|
|
83
|
-
|
|
69
|
+
async getPublicKey() {
|
|
70
|
+
const result = await kit.getAddress();
|
|
71
|
+
address = result.address;
|
|
72
|
+
return result.address;
|
|
84
73
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
kit.onSessionDeleted((sessionId) => {
|
|
91
|
-
publicKey = void 0;
|
|
92
|
-
callback(sessionId);
|
|
74
|
+
async signTransaction({ xdr, networkPassphrase }) {
|
|
75
|
+
const result = await kit.signTransaction(xdr, {
|
|
76
|
+
networkPassphrase,
|
|
77
|
+
...address ? { address } : {}
|
|
93
78
|
});
|
|
79
|
+
return result.signedTxXdr;
|
|
80
|
+
},
|
|
81
|
+
async disconnect() {
|
|
82
|
+
await kit.disconnect();
|
|
83
|
+
address = void 0;
|
|
94
84
|
}
|
|
95
85
|
};
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
var HOTWALLET_ID = "hot-wallet";
|
|
88
|
+
function buildModules(network, walletConnectMetadata) {
|
|
89
|
+
const modules = (0, import_stellar_wallets_kit.allowAllModules)({
|
|
90
|
+
filterBy: (module2) => module2.productId !== HOTWALLET_ID
|
|
91
|
+
});
|
|
92
|
+
if (walletConnectMetadata) {
|
|
93
|
+
modules.push(
|
|
94
|
+
new import_walletconnect.WalletConnectModule({
|
|
95
|
+
...walletConnectMetadata,
|
|
96
|
+
network,
|
|
97
|
+
method: import_walletconnect.WalletConnectAllowedMethods.SIGN
|
|
98
|
+
})
|
|
99
|
+
);
|
|
103
100
|
}
|
|
104
|
-
return
|
|
101
|
+
return modules;
|
|
105
102
|
}
|
|
106
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
104
|
0 && (module.exports = {
|
|
105
|
+
WalletNetwork,
|
|
108
106
|
createStellarWalletsKitAdapter
|
|
109
107
|
});
|