@caatinga/client 0.2.0 → 0.2.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Kaleido contributors
3
+ Copyright (c) Caatinga contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
- import { C as CaatingaWalletAdapter } from './types-CiM5FkDn.cjs';
2
- import '@caatinga/core';
1
+ import { C as CaatingaWalletAdapter } from './types-DUgMJXLA.cjs';
2
+ import '@caatinga/core/browser';
3
3
 
4
4
  declare const freighterWalletAdapter: CaatingaWalletAdapter;
5
5
 
@@ -1,5 +1,5 @@
1
- import { C as CaatingaWalletAdapter } from './types-CiM5FkDn.js';
2
- import '@caatinga/core';
1
+ import { C as CaatingaWalletAdapter } from './types-DUgMJXLA.js';
2
+ import '@caatinga/core/browser';
3
3
 
4
4
  declare const freighterWalletAdapter: CaatingaWalletAdapter;
5
5
 
package/dist/index.cjs CHANGED
@@ -29,7 +29,7 @@ __export(index_exports, {
29
29
  module.exports = __toCommonJS(index_exports);
30
30
 
31
31
  // src/artifacts/resolve-contract-id.ts
32
- var import_core = require("@caatinga/core");
32
+ var import_browser = require("@caatinga/core/browser");
33
33
  function resolveContractId(input) {
34
34
  if (input.explicitContractId) {
35
35
  return input.explicitContractId;
@@ -38,22 +38,22 @@ function resolveContractId(input) {
38
38
  if (contractId) {
39
39
  return contractId;
40
40
  }
41
- throw new import_core.CaatingaError(
41
+ throw new import_browser.CaatingaError(
42
42
  `No contract artifact found for "${input.contract}" on "${input.network}".`,
43
- import_core.CaatingaErrorCode.CONTRACT_ARTIFACT_NOT_FOUND,
43
+ import_browser.CaatingaErrorCode.CONTRACT_ARTIFACT_NOT_FOUND,
44
44
  "Deploy the contract first or pass contractId explicitly."
45
45
  );
46
46
  }
47
47
 
48
48
  // src/bindings/default-binding-adapter.ts
49
- var import_core2 = require("@caatinga/core");
49
+ var import_browser2 = require("@caatinga/core/browser");
50
50
  function createDefaultBindingAdapter(binding) {
51
51
  return {
52
52
  createClient({ contractId, publicKey, rpcUrl, networkPassphrase }) {
53
53
  if (!binding.Client) {
54
- throw new import_core2.CaatingaError(
54
+ throw new import_browser2.CaatingaError(
55
55
  "Generated binding does not export Client.",
56
- import_core2.CaatingaErrorCode.BINDING_CLIENT_NOT_FOUND,
56
+ import_browser2.CaatingaErrorCode.BINDING_CLIENT_NOT_FOUND,
57
57
  "Regenerate bindings with Stellar CLI."
58
58
  );
59
59
  }
@@ -68,9 +68,9 @@ function createDefaultBindingAdapter(binding) {
68
68
  const candidate = client;
69
69
  const fn = candidate[method];
70
70
  if (typeof fn !== "function") {
71
- throw new import_core2.CaatingaError(
71
+ throw new import_browser2.CaatingaError(
72
72
  `Binding method "${method}" was not found.`,
73
- import_core2.CaatingaErrorCode.BINDING_METHOD_NOT_FOUND,
73
+ import_browser2.CaatingaErrorCode.BINDING_METHOD_NOT_FOUND,
74
74
  "Check the contract method name or regenerate bindings."
75
75
  );
76
76
  }
@@ -80,13 +80,13 @@ function createDefaultBindingAdapter(binding) {
80
80
  }
81
81
 
82
82
  // src/client/create-caatinga-client.ts
83
- var import_core5 = require("@caatinga/core");
83
+ var import_browser5 = require("@caatinga/core/browser");
84
84
 
85
85
  // src/client/caatinga-contract-client.ts
86
- var import_core4 = require("@caatinga/core");
86
+ var import_browser4 = require("@caatinga/core/browser");
87
87
 
88
88
  // src/xdr/build-xdr.ts
89
- var import_core3 = require("@caatinga/core");
89
+ var import_browser3 = require("@caatinga/core/browser");
90
90
  async function buildXdr(input) {
91
91
  try {
92
92
  const transaction = input.transaction;
@@ -96,13 +96,13 @@ async function buildXdr(input) {
96
96
  try {
97
97
  preparedTransaction = await transaction.prepare();
98
98
  } catch (error) {
99
- if (error instanceof import_core3.CaatingaError) {
99
+ if (error instanceof import_browser3.CaatingaError) {
100
100
  throw error;
101
101
  }
102
- throw new import_core3.CaatingaError(
102
+ throw new import_browser3.CaatingaError(
103
103
  `Failed to prepare XDR for "${input.contractName}.${input.method}".`,
104
- import_core3.CaatingaErrorCode.XDR_PREPARE_FAILED,
105
- "Check RPC connectivity, simulation errors, and binding compatibility.",
104
+ import_browser3.CaatingaErrorCode.XDR_PREPARE_FAILED,
105
+ `RPC: ${input.rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
106
106
  error
107
107
  );
108
108
  }
@@ -119,12 +119,12 @@ async function buildXdr(input) {
119
119
  ...input.debug ? { raw: preparedTransaction } : {}
120
120
  };
121
121
  } catch (error) {
122
- if (error instanceof import_core3.CaatingaError) {
122
+ if (error instanceof import_browser3.CaatingaError) {
123
123
  throw error;
124
124
  }
125
- throw new import_core3.CaatingaError(
125
+ throw new import_browser3.CaatingaError(
126
126
  `Failed to build XDR for "${input.contractName}.${input.method}".`,
127
- import_core3.CaatingaErrorCode.XDR_BUILD_FAILED,
127
+ import_browser3.CaatingaErrorCode.XDR_BUILD_FAILED,
128
128
  "Check the generated binding transaction object.",
129
129
  error
130
130
  );
@@ -133,9 +133,9 @@ async function buildXdr(input) {
133
133
  function readXdr(transaction) {
134
134
  const candidate = transaction;
135
135
  if (typeof candidate.toXDR !== "function") {
136
- throw new import_core3.CaatingaError(
136
+ throw new import_browser3.CaatingaError(
137
137
  "Binding transaction object does not expose toXDR().",
138
- import_core3.CaatingaErrorCode.XDR_BUILD_FAILED,
138
+ import_browser3.CaatingaErrorCode.XDR_BUILD_FAILED,
139
139
  "Regenerate bindings or provide a compatible binding adapter."
140
140
  );
141
141
  }
@@ -164,6 +164,7 @@ var CaatingaContractClient = class {
164
164
  method,
165
165
  contractId,
166
166
  transaction,
167
+ rpcUrl: this.config.network.rpcUrl,
167
168
  debug: debugRaw
168
169
  });
169
170
  }
@@ -175,23 +176,44 @@ var CaatingaContractClient = class {
175
176
  method,
176
177
  contractId,
177
178
  transaction,
179
+ rpcUrl: this.config.network.rpcUrl,
178
180
  debug: debugRaw
179
181
  });
180
182
  let signedXdr;
181
183
  try {
182
- signedXdr = await this.config.wallet.signTransaction({
183
- xdr: xdr.preparedXdr,
184
- networkPassphrase: this.config.network.networkPassphrase
185
- });
184
+ signedXdr = await this.withWalletTimeout(
185
+ "signTransaction",
186
+ () => this.config.wallet.signTransaction({
187
+ xdr: xdr.preparedXdr,
188
+ networkPassphrase: this.config.network.networkPassphrase
189
+ })
190
+ );
186
191
  } catch (error) {
187
- throw new import_core4.CaatingaError(
192
+ if (error instanceof import_browser4.CaatingaError) {
193
+ throw error;
194
+ }
195
+ throw new import_browser4.CaatingaError(
188
196
  `Failed to sign XDR for "${this.contractName}.${method}".`,
189
- import_core4.CaatingaErrorCode.XDR_SIGN_FAILED,
197
+ import_browser4.CaatingaErrorCode.XDR_SIGN_FAILED,
190
198
  "Connect a wallet and approve the transaction.",
191
199
  error
192
200
  );
193
201
  }
194
- const raw = await submitTransaction(transaction, signedXdr, this.contractName, method);
202
+ if (typeof signedXdr !== "string" || signedXdr.trim().length === 0) {
203
+ throw new import_browser4.CaatingaError(
204
+ `Failed to sign XDR for "${this.contractName}.${method}".`,
205
+ import_browser4.CaatingaErrorCode.XDR_SIGN_FAILED,
206
+ "Wallet returned an empty or invalid signed XDR. The user may have dismissed the signing prompt.",
207
+ signedXdr
208
+ );
209
+ }
210
+ const raw = await submitTransaction(
211
+ transaction,
212
+ signedXdr,
213
+ this.contractName,
214
+ method,
215
+ this.config.network.rpcUrl
216
+ );
195
217
  const normalized = normalizeSubmitResult(raw);
196
218
  return {
197
219
  status: "confirmed",
@@ -219,14 +241,17 @@ var CaatingaContractClient = class {
219
241
  });
220
242
  let publicKey;
221
243
  try {
222
- publicKey = await this.config.wallet.getPublicKey();
244
+ publicKey = await this.withWalletTimeout(
245
+ "getPublicKey",
246
+ () => this.config.wallet.getPublicKey()
247
+ );
223
248
  } catch (error) {
224
- if (error instanceof import_core4.CaatingaError) {
249
+ if (error instanceof import_browser4.CaatingaError) {
225
250
  throw error;
226
251
  }
227
- throw new import_core4.CaatingaError(
252
+ throw new import_browser4.CaatingaError(
228
253
  `Wallet is not connected or the public key is unavailable for "${this.contractName}".`,
229
- import_core4.CaatingaErrorCode.WALLET_NOT_CONNECTED,
254
+ import_browser4.CaatingaErrorCode.WALLET_NOT_CONNECTED,
230
255
  "Connect the wallet and grant account access, then retry.",
231
256
  error
232
257
  );
@@ -240,6 +265,41 @@ var CaatingaContractClient = class {
240
265
  const transaction = await this.bindingAdapter.callMethod({ client, method, args });
241
266
  return { contractId, transaction };
242
267
  }
268
+ withWalletTimeout(label, fn) {
269
+ const timeoutMs = this.config.walletTimeout;
270
+ if (timeoutMs === void 0 || timeoutMs <= 0) {
271
+ return fn();
272
+ }
273
+ let timedOut = false;
274
+ return new Promise((resolve, reject) => {
275
+ const timer = setTimeout(() => {
276
+ timedOut = true;
277
+ reject(
278
+ new import_browser4.CaatingaError(
279
+ `Wallet "${label}" timed out after ${timeoutMs}ms.`,
280
+ import_browser4.CaatingaErrorCode.WALLET_TIMEOUT,
281
+ "Ensure the wallet adapter rejects on user dismissal, or increase walletTimeout."
282
+ )
283
+ );
284
+ }, timeoutMs);
285
+ fn().then(
286
+ (value) => {
287
+ if (timedOut) {
288
+ return;
289
+ }
290
+ clearTimeout(timer);
291
+ resolve(value);
292
+ },
293
+ (error) => {
294
+ if (timedOut) {
295
+ return;
296
+ }
297
+ clearTimeout(timer);
298
+ reject(error);
299
+ }
300
+ );
301
+ });
302
+ }
243
303
  };
244
304
  function splitArgsAndOptions(argsOrOptions, maybeOptions) {
245
305
  return {
@@ -263,13 +323,13 @@ function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
263
323
  debugRaw: maybeOptions?.debugRaw ?? false
264
324
  };
265
325
  }
266
- async function submitTransaction(transaction, signedXdr, contractName, method) {
326
+ async function submitTransaction(transaction, signedXdr, contractName, method, rpcUrl) {
267
327
  const candidate = transaction;
268
328
  const submit = candidate.signAndSend ?? candidate.send;
269
329
  if (typeof submit !== "function") {
270
- throw new import_core4.CaatingaError(
330
+ throw new import_browser4.CaatingaError(
271
331
  `Binding transaction for "${contractName}.${method}" cannot be submitted.`,
272
- import_core4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
332
+ import_browser4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
273
333
  "Regenerate bindings or provide a compatible binding adapter."
274
334
  );
275
335
  }
@@ -278,13 +338,13 @@ async function submitTransaction(transaction, signedXdr, contractName, method) {
278
338
  assertSubmitResultRecognized(raw, contractName, method);
279
339
  return raw;
280
340
  } catch (error) {
281
- if (error instanceof import_core4.CaatingaError) {
341
+ if (error instanceof import_browser4.CaatingaError) {
282
342
  throw error;
283
343
  }
284
- throw new import_core4.CaatingaError(
344
+ throw new import_browser4.CaatingaError(
285
345
  `Failed to submit XDR for "${contractName}.${method}".`,
286
- import_core4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
287
- "Check wallet signature and RPC connectivity.",
346
+ import_browser4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
347
+ `RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
288
348
  error
289
349
  );
290
350
  }
@@ -299,9 +359,9 @@ function assertSubmitResultRecognized(raw, contractName, method) {
299
359
  if (hasTransactionId || hasResult) {
300
360
  return;
301
361
  }
302
- throw new import_core4.CaatingaError(
362
+ throw new import_browser4.CaatingaError(
303
363
  `Submit returned an unrecognized payload for "${contractName}.${method}".`,
304
- import_core4.CaatingaErrorCode.XDR_RESULT_FAILED,
364
+ import_browser4.CaatingaErrorCode.XDR_RESULT_FAILED,
305
365
  "Expected txHash, transactionHash, hash, or result on the submit response. Use debugRaw to inspect the binding output."
306
366
  );
307
367
  }
@@ -319,9 +379,9 @@ function createCaatingaClient(config) {
319
379
  contract(contractName) {
320
380
  const registration = config.contracts[contractName];
321
381
  if (!registration) {
322
- throw new import_core5.CaatingaError(
382
+ throw new import_browser5.CaatingaError(
323
383
  `Contract "${contractName}" is not registered.`,
324
- import_core5.CaatingaErrorCode.CONTRACT_NOT_FOUND,
384
+ import_browser5.CaatingaErrorCode.CONTRACT_NOT_FOUND,
325
385
  "Add the contract binding to createCaatingaClient()."
326
386
  );
327
387
  }
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-CiM5FkDn.cjs';
2
- export { g as CaatingaInvokeStatus, h as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-CiM5FkDn.cjs';
3
- import { CaatingaArtifacts } from '@caatinga/core';
1
+ import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-DUgMJXLA.cjs';
2
+ export { g as CaatingaInvokeStatus, h as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-DUgMJXLA.cjs';
3
+ import { CaatingaArtifacts } from '@caatinga/core/browser';
4
4
 
5
5
  declare function resolveContractId(input: {
6
6
  artifacts: CaatingaArtifacts;
@@ -30,6 +30,7 @@ declare class CaatingaContractClient {
30
30
  }): Promise<CaatingaXdrBuildResult>;
31
31
  invoke<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaInvokeOptions, maybeOptions?: CaatingaInvokeOptions): Promise<CaatingaInvokeResult<T>>;
32
32
  private createTransaction;
33
+ private withWalletTimeout;
33
34
  }
34
35
 
35
36
  declare function createCaatingaClient(config: CaatingaClientConfig): {
@@ -41,6 +42,7 @@ declare function buildXdr(input: {
41
42
  method: string;
42
43
  contractId: string;
43
44
  transaction: unknown;
45
+ rpcUrl: string;
44
46
  debug?: boolean;
45
47
  }): Promise<CaatingaXdrBuildResult>;
46
48
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-CiM5FkDn.js';
2
- export { g as CaatingaInvokeStatus, h as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-CiM5FkDn.js';
3
- import { CaatingaArtifacts } from '@caatinga/core';
1
+ import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-DUgMJXLA.js';
2
+ export { g as CaatingaInvokeStatus, h as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-DUgMJXLA.js';
3
+ import { CaatingaArtifacts } from '@caatinga/core/browser';
4
4
 
5
5
  declare function resolveContractId(input: {
6
6
  artifacts: CaatingaArtifacts;
@@ -30,6 +30,7 @@ declare class CaatingaContractClient {
30
30
  }): Promise<CaatingaXdrBuildResult>;
31
31
  invoke<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaInvokeOptions, maybeOptions?: CaatingaInvokeOptions): Promise<CaatingaInvokeResult<T>>;
32
32
  private createTransaction;
33
+ private withWalletTimeout;
33
34
  }
34
35
 
35
36
  declare function createCaatingaClient(config: CaatingaClientConfig): {
@@ -41,6 +42,7 @@ declare function buildXdr(input: {
41
42
  method: string;
42
43
  contractId: string;
43
44
  transaction: unknown;
45
+ rpcUrl: string;
44
46
  debug?: boolean;
45
47
  }): Promise<CaatingaXdrBuildResult>;
46
48
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/artifacts/resolve-contract-id.ts
2
- import { CaatingaError, CaatingaErrorCode } from "@caatinga/core";
2
+ import { CaatingaError, CaatingaErrorCode } from "@caatinga/core/browser";
3
3
  function resolveContractId(input) {
4
4
  if (input.explicitContractId) {
5
5
  return input.explicitContractId;
@@ -16,7 +16,7 @@ function resolveContractId(input) {
16
16
  }
17
17
 
18
18
  // src/bindings/default-binding-adapter.ts
19
- import { CaatingaError as CaatingaError2, CaatingaErrorCode as CaatingaErrorCode2 } from "@caatinga/core";
19
+ import { CaatingaError as CaatingaError2, CaatingaErrorCode as CaatingaErrorCode2 } from "@caatinga/core/browser";
20
20
  function createDefaultBindingAdapter(binding) {
21
21
  return {
22
22
  createClient({ contractId, publicKey, rpcUrl, networkPassphrase }) {
@@ -50,13 +50,13 @@ function createDefaultBindingAdapter(binding) {
50
50
  }
51
51
 
52
52
  // src/client/create-caatinga-client.ts
53
- import { CaatingaError as CaatingaError5, CaatingaErrorCode as CaatingaErrorCode5 } from "@caatinga/core";
53
+ import { CaatingaError as CaatingaError5, CaatingaErrorCode as CaatingaErrorCode5 } from "@caatinga/core/browser";
54
54
 
55
55
  // src/client/caatinga-contract-client.ts
56
- import { CaatingaError as CaatingaError4, CaatingaErrorCode as CaatingaErrorCode4 } from "@caatinga/core";
56
+ import { CaatingaError as CaatingaError4, CaatingaErrorCode as CaatingaErrorCode4 } from "@caatinga/core/browser";
57
57
 
58
58
  // src/xdr/build-xdr.ts
59
- import { CaatingaError as CaatingaError3, CaatingaErrorCode as CaatingaErrorCode3 } from "@caatinga/core";
59
+ import { CaatingaError as CaatingaError3, CaatingaErrorCode as CaatingaErrorCode3 } from "@caatinga/core/browser";
60
60
  async function buildXdr(input) {
61
61
  try {
62
62
  const transaction = input.transaction;
@@ -72,7 +72,7 @@ async function buildXdr(input) {
72
72
  throw new CaatingaError3(
73
73
  `Failed to prepare XDR for "${input.contractName}.${input.method}".`,
74
74
  CaatingaErrorCode3.XDR_PREPARE_FAILED,
75
- "Check RPC connectivity, simulation errors, and binding compatibility.",
75
+ `RPC: ${input.rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
76
76
  error
77
77
  );
78
78
  }
@@ -134,6 +134,7 @@ var CaatingaContractClient = class {
134
134
  method,
135
135
  contractId,
136
136
  transaction,
137
+ rpcUrl: this.config.network.rpcUrl,
137
138
  debug: debugRaw
138
139
  });
139
140
  }
@@ -145,15 +146,22 @@ var CaatingaContractClient = class {
145
146
  method,
146
147
  contractId,
147
148
  transaction,
149
+ rpcUrl: this.config.network.rpcUrl,
148
150
  debug: debugRaw
149
151
  });
150
152
  let signedXdr;
151
153
  try {
152
- signedXdr = await this.config.wallet.signTransaction({
153
- xdr: xdr.preparedXdr,
154
- networkPassphrase: this.config.network.networkPassphrase
155
- });
154
+ signedXdr = await this.withWalletTimeout(
155
+ "signTransaction",
156
+ () => this.config.wallet.signTransaction({
157
+ xdr: xdr.preparedXdr,
158
+ networkPassphrase: this.config.network.networkPassphrase
159
+ })
160
+ );
156
161
  } catch (error) {
162
+ if (error instanceof CaatingaError4) {
163
+ throw error;
164
+ }
157
165
  throw new CaatingaError4(
158
166
  `Failed to sign XDR for "${this.contractName}.${method}".`,
159
167
  CaatingaErrorCode4.XDR_SIGN_FAILED,
@@ -161,7 +169,21 @@ var CaatingaContractClient = class {
161
169
  error
162
170
  );
163
171
  }
164
- const raw = await submitTransaction(transaction, signedXdr, this.contractName, method);
172
+ if (typeof signedXdr !== "string" || signedXdr.trim().length === 0) {
173
+ throw new CaatingaError4(
174
+ `Failed to sign XDR for "${this.contractName}.${method}".`,
175
+ CaatingaErrorCode4.XDR_SIGN_FAILED,
176
+ "Wallet returned an empty or invalid signed XDR. The user may have dismissed the signing prompt.",
177
+ signedXdr
178
+ );
179
+ }
180
+ const raw = await submitTransaction(
181
+ transaction,
182
+ signedXdr,
183
+ this.contractName,
184
+ method,
185
+ this.config.network.rpcUrl
186
+ );
165
187
  const normalized = normalizeSubmitResult(raw);
166
188
  return {
167
189
  status: "confirmed",
@@ -189,7 +211,10 @@ var CaatingaContractClient = class {
189
211
  });
190
212
  let publicKey;
191
213
  try {
192
- publicKey = await this.config.wallet.getPublicKey();
214
+ publicKey = await this.withWalletTimeout(
215
+ "getPublicKey",
216
+ () => this.config.wallet.getPublicKey()
217
+ );
193
218
  } catch (error) {
194
219
  if (error instanceof CaatingaError4) {
195
220
  throw error;
@@ -210,6 +235,41 @@ var CaatingaContractClient = class {
210
235
  const transaction = await this.bindingAdapter.callMethod({ client, method, args });
211
236
  return { contractId, transaction };
212
237
  }
238
+ withWalletTimeout(label, fn) {
239
+ const timeoutMs = this.config.walletTimeout;
240
+ if (timeoutMs === void 0 || timeoutMs <= 0) {
241
+ return fn();
242
+ }
243
+ let timedOut = false;
244
+ return new Promise((resolve, reject) => {
245
+ const timer = setTimeout(() => {
246
+ timedOut = true;
247
+ reject(
248
+ new CaatingaError4(
249
+ `Wallet "${label}" timed out after ${timeoutMs}ms.`,
250
+ CaatingaErrorCode4.WALLET_TIMEOUT,
251
+ "Ensure the wallet adapter rejects on user dismissal, or increase walletTimeout."
252
+ )
253
+ );
254
+ }, timeoutMs);
255
+ fn().then(
256
+ (value) => {
257
+ if (timedOut) {
258
+ return;
259
+ }
260
+ clearTimeout(timer);
261
+ resolve(value);
262
+ },
263
+ (error) => {
264
+ if (timedOut) {
265
+ return;
266
+ }
267
+ clearTimeout(timer);
268
+ reject(error);
269
+ }
270
+ );
271
+ });
272
+ }
213
273
  };
214
274
  function splitArgsAndOptions(argsOrOptions, maybeOptions) {
215
275
  return {
@@ -233,7 +293,7 @@ function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
233
293
  debugRaw: maybeOptions?.debugRaw ?? false
234
294
  };
235
295
  }
236
- async function submitTransaction(transaction, signedXdr, contractName, method) {
296
+ async function submitTransaction(transaction, signedXdr, contractName, method, rpcUrl) {
237
297
  const candidate = transaction;
238
298
  const submit = candidate.signAndSend ?? candidate.send;
239
299
  if (typeof submit !== "function") {
@@ -254,7 +314,7 @@ async function submitTransaction(transaction, signedXdr, contractName, method) {
254
314
  throw new CaatingaError4(
255
315
  `Failed to submit XDR for "${contractName}.${method}".`,
256
316
  CaatingaErrorCode4.XDR_SUBMIT_FAILED,
257
- "Check wallet signature and RPC connectivity.",
317
+ `RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
258
318
  error
259
319
  );
260
320
  }
@@ -1,10 +1,17 @@
1
- import { CaatingaArtifacts } from '@caatinga/core';
1
+ import { CaatingaArtifacts } from '@caatinga/core/browser';
2
2
 
3
3
  interface CaatingaNetwork {
4
4
  name: string;
5
5
  rpcUrl: string;
6
6
  networkPassphrase: string;
7
7
  }
8
+ /**
9
+ * Wallet integration for browser-side signing.
10
+ *
11
+ * Implementations must reject the returned promise when the user dismisses or
12
+ * cancels signing (do not leave the promise pending indefinitely). Adapters may
13
+ * apply their own timeout. Caatinga optionally enforces {@link CaatingaClientConfig.walletTimeout}.
14
+ */
8
15
  interface CaatingaWalletAdapter {
9
16
  getPublicKey(): Promise<string>;
10
17
  signTransaction(input: {
@@ -20,6 +27,8 @@ interface CaatingaClientConfig {
20
27
  network: CaatingaNetwork;
21
28
  artifacts: CaatingaArtifacts;
22
29
  wallet: CaatingaWalletAdapter;
30
+ /** Optional timeout (ms) for wallet `getPublicKey` and `signTransaction`. No default when omitted. */
31
+ walletTimeout?: number;
23
32
  contracts: Record<string, CaatingaContractRegistration>;
24
33
  }
25
34
  type CaatingaInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
@@ -1,10 +1,17 @@
1
- import { CaatingaArtifacts } from '@caatinga/core';
1
+ import { CaatingaArtifacts } from '@caatinga/core/browser';
2
2
 
3
3
  interface CaatingaNetwork {
4
4
  name: string;
5
5
  rpcUrl: string;
6
6
  networkPassphrase: string;
7
7
  }
8
+ /**
9
+ * Wallet integration for browser-side signing.
10
+ *
11
+ * Implementations must reject the returned promise when the user dismisses or
12
+ * cancels signing (do not leave the promise pending indefinitely). Adapters may
13
+ * apply their own timeout. Caatinga optionally enforces {@link CaatingaClientConfig.walletTimeout}.
14
+ */
8
15
  interface CaatingaWalletAdapter {
9
16
  getPublicKey(): Promise<string>;
10
17
  signTransaction(input: {
@@ -20,6 +27,8 @@ interface CaatingaClientConfig {
20
27
  network: CaatingaNetwork;
21
28
  artifacts: CaatingaArtifacts;
22
29
  wallet: CaatingaWalletAdapter;
30
+ /** Optional timeout (ms) for wallet `getPublicKey` and `signTransaction`. No default when omitted. */
31
+ walletTimeout?: number;
23
32
  contracts: Record<string, CaatingaContractRegistration>;
24
33
  }
25
34
  type CaatingaInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caatinga/client",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Browser and Node client for Soroban smart contracts — connects generated bindings, Caatinga artifacts, and wallet adapters",
5
5
  "keywords": [
6
6
  "stellar",
@@ -46,7 +46,7 @@
46
46
  "LICENSE"
47
47
  ],
48
48
  "dependencies": {
49
- "@caatinga/core": "^0.2.0"
49
+ "@caatinga/core": "^0.2.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "tsup": "^8.3.5",
@@ -64,6 +64,7 @@
64
64
  "scripts": {
65
65
  "build": "tsup src/index.ts src/freighter.ts --format esm,cjs --dts",
66
66
  "test": "vitest run --pool=threads",
67
+ "pretypecheck": "pnpm --filter @caatinga/core run build",
67
68
  "typecheck": "tsc --noEmit"
68
69
  }
69
70
  }
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido-xlm/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido-xlm/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido-stellar/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };
@@ -1,66 +0,0 @@
1
- import { KaleidoArtifacts } from '@kaleido-stellar/core';
2
-
3
- interface KaleidoNetwork {
4
- name: string;
5
- rpcUrl: string;
6
- networkPassphrase: string;
7
- }
8
- interface KaleidoWalletAdapter {
9
- getPublicKey(): Promise<string>;
10
- signTransaction(input: {
11
- xdr: string;
12
- networkPassphrase: string;
13
- }): Promise<string>;
14
- }
15
- interface KaleidoContractRegistration {
16
- binding: unknown;
17
- contractId?: string;
18
- }
19
- interface KaleidoClientConfig {
20
- network: KaleidoNetwork;
21
- artifacts: KaleidoArtifacts;
22
- wallet: KaleidoWalletAdapter;
23
- contracts: Record<string, KaleidoContractRegistration>;
24
- }
25
- type KaleidoInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
26
- interface KaleidoInvokeOptions {
27
- debugXdr?: boolean;
28
- debugRaw?: boolean;
29
- }
30
- interface KaleidoInvokeResult<T = unknown> {
31
- status: KaleidoInvokeStatus;
32
- contract: string;
33
- method: string;
34
- contractId: string;
35
- transactionHash?: string;
36
- result?: T;
37
- xdr?: {
38
- unsigned?: string;
39
- prepared?: string;
40
- signed?: string;
41
- };
42
- raw?: unknown;
43
- }
44
- interface KaleidoXdrBuildResult {
45
- contract: string;
46
- method: string;
47
- contractId: string;
48
- unsignedXdr?: string;
49
- preparedXdr: string;
50
- raw?: unknown;
51
- }
52
- interface KaleidoBindingAdapter {
53
- createClient(input: {
54
- contractId: string;
55
- publicKey: string;
56
- rpcUrl: string;
57
- networkPassphrase: string;
58
- }): unknown;
59
- callMethod(input: {
60
- client: unknown;
61
- method: string;
62
- args?: Record<string, unknown>;
63
- }): Promise<unknown>;
64
- }
65
-
66
- export type { KaleidoWalletAdapter as K, KaleidoBindingAdapter as a, KaleidoClientConfig as b, KaleidoContractRegistration as c, KaleidoXdrBuildResult as d, KaleidoInvokeOptions as e, KaleidoInvokeResult as f, KaleidoInvokeStatus as g, KaleidoNetwork as h };