@caatinga/client 0.2.2 → 0.2.4
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 +22 -3
- package/dist/freighter.d.cts +1 -1
- package/dist/freighter.d.ts +1 -1
- package/dist/index.cjs +144 -45
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +144 -45
- package/dist/stellar-wallets-kit.cjs +109 -0
- package/dist/stellar-wallets-kit.d.cts +46 -0
- package/dist/stellar-wallets-kit.d.ts +46 -0
- package/dist/stellar-wallets-kit.js +86 -0
- package/dist/types-D4XEyX4J.d.cts +86 -0
- package/dist/types-D4XEyX4J.d.ts +86 -0
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -19,6 +19,16 @@ import { freighterWalletAdapter } from "@caatinga/client/freighter";
|
|
|
19
19
|
|
|
20
20
|
The `@caatinga/client/freighter` subpath is optional and only needed when you want the bundled Freighter adapter.
|
|
21
21
|
|
|
22
|
+
For multi-wallet support, add Stellar Wallets Kit:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add github:Creit-Tech/Stellar-Wallets-Kit#v0.0.7
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createStellarWalletsKitAdapter } from "@caatinga/client/stellar-wallets-kit";
|
|
30
|
+
```
|
|
31
|
+
|
|
22
32
|
## What It Solves
|
|
23
33
|
|
|
24
34
|
`@caatinga/client` is the supported browser and Node integration layer for invoking generated Soroban bindings with Caatinga artifacts, network configuration, and a wallet adapter.
|
|
@@ -49,16 +59,21 @@ Supported type-only root exports:
|
|
|
49
59
|
- `CaatingaInvokeResult`
|
|
50
60
|
- `CaatingaInvokeStatus`
|
|
51
61
|
- `CaatingaNetwork`
|
|
62
|
+
- `CaatingaReadOptions`
|
|
63
|
+
- `CaatingaReadResult`
|
|
52
64
|
- `CaatingaWalletAdapter`
|
|
53
65
|
- `CaatingaXdrBuildResult`
|
|
54
66
|
|
|
55
67
|
Supported subpath export:
|
|
56
68
|
|
|
57
69
|
- `@caatinga/client/freighter` -> `freighterWalletAdapter` (optional)
|
|
70
|
+
- `@caatinga/client/stellar-wallets-kit` -> `createStellarWalletsKitAdapter` (optional)
|
|
58
71
|
|
|
59
72
|
Primary flow:
|
|
60
73
|
|
|
61
74
|
- `createCaatingaClient(...)`
|
|
75
|
+
- `client.contract(name).read(method, args?)`
|
|
76
|
+
- `client.contract(name).simulate(method, args?)`
|
|
62
77
|
- `client.contract(name).invoke(method, args?)`
|
|
63
78
|
- `client.contract(name).buildXdr(method, args?)`
|
|
64
79
|
|
|
@@ -66,10 +81,12 @@ Primary flow:
|
|
|
66
81
|
|
|
67
82
|
```ts
|
|
68
83
|
import { createCaatingaClient } from "@caatinga/client";
|
|
69
|
-
import {
|
|
84
|
+
import { createStellarWalletsKitAdapter } from "@caatinga/client/stellar-wallets-kit";
|
|
70
85
|
import * as Counter from "./contracts/generated/counter";
|
|
71
86
|
import artifacts from "../caatinga.artifacts.json";
|
|
72
87
|
|
|
88
|
+
const wallet = createStellarWalletsKitAdapter();
|
|
89
|
+
|
|
73
90
|
const client = createCaatingaClient({
|
|
74
91
|
network: {
|
|
75
92
|
name: "testnet",
|
|
@@ -77,7 +94,7 @@ const client = createCaatingaClient({
|
|
|
77
94
|
networkPassphrase: "Test SDF Network ; September 2015"
|
|
78
95
|
},
|
|
79
96
|
artifacts,
|
|
80
|
-
wallet
|
|
97
|
+
wallet,
|
|
81
98
|
contracts: {
|
|
82
99
|
counter: {
|
|
83
100
|
binding: Counter
|
|
@@ -85,7 +102,9 @@ const client = createCaatingaClient({
|
|
|
85
102
|
}
|
|
86
103
|
});
|
|
87
104
|
|
|
88
|
-
const
|
|
105
|
+
const before = await client.contract("counter").read<number>("get");
|
|
106
|
+
const increment = await client.contract("counter").invoke<number>("increment");
|
|
107
|
+
const after = increment.result ?? await client.contract("counter").read<number>("get");
|
|
89
108
|
```
|
|
90
109
|
|
|
91
110
|
## Wallet Adapter Contract
|
package/dist/freighter.d.cts
CHANGED
package/dist/freighter.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -180,40 +180,50 @@ var CaatingaContractClient = class {
|
|
|
180
180
|
debug: debugRaw
|
|
181
181
|
});
|
|
182
182
|
let signedXdr;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
const signTransaction = async (xdr2) => {
|
|
184
|
+
try {
|
|
185
|
+
signedXdr = await this.withWalletTimeout(
|
|
186
|
+
"signTransaction",
|
|
187
|
+
() => this.config.wallet.signTransaction({
|
|
188
|
+
xdr: xdr2,
|
|
189
|
+
networkPassphrase: this.config.network.networkPassphrase
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (error instanceof import_browser4.CaatingaError) {
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
throw new import_browser4.CaatingaError(
|
|
197
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
198
|
+
import_browser4.CaatingaErrorCode.XDR_SIGN_FAILED,
|
|
199
|
+
"Connect a wallet and approve the transaction.",
|
|
200
|
+
error
|
|
201
|
+
);
|
|
194
202
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
203
|
+
if (typeof signedXdr !== "string" || signedXdr.trim().length === 0) {
|
|
204
|
+
throw new import_browser4.CaatingaError(
|
|
205
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
206
|
+
import_browser4.CaatingaErrorCode.XDR_SIGN_FAILED,
|
|
207
|
+
"Wallet returned an empty or invalid signed XDR. The user may have dismissed the signing prompt.",
|
|
208
|
+
signedXdr
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return { signedTxXdr: signedXdr };
|
|
212
|
+
};
|
|
210
213
|
const raw = await submitTransaction(
|
|
211
214
|
transaction,
|
|
212
|
-
|
|
215
|
+
signTransaction,
|
|
213
216
|
this.contractName,
|
|
214
217
|
method,
|
|
215
218
|
this.config.network.rpcUrl
|
|
216
219
|
);
|
|
220
|
+
if (typeof transaction.signAndSend === "function" && signedXdr === void 0) {
|
|
221
|
+
throw new import_browser4.CaatingaError(
|
|
222
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
223
|
+
import_browser4.CaatingaErrorCode.XDR_SIGN_FAILED,
|
|
224
|
+
"Wallet returned an empty or invalid signed XDR. The generated transaction did not request a wallet signature."
|
|
225
|
+
);
|
|
226
|
+
}
|
|
217
227
|
const normalized = normalizeSubmitResult(raw);
|
|
218
228
|
return {
|
|
219
229
|
status: "confirmed",
|
|
@@ -226,12 +236,35 @@ var CaatingaContractClient = class {
|
|
|
226
236
|
xdr: {
|
|
227
237
|
unsigned: xdr.unsignedXdr,
|
|
228
238
|
prepared: xdr.preparedXdr,
|
|
229
|
-
signed: signedXdr
|
|
239
|
+
...signedXdr ? { signed: signedXdr } : {}
|
|
230
240
|
}
|
|
231
241
|
} : {},
|
|
232
242
|
...debugRaw ? { raw } : {}
|
|
233
243
|
};
|
|
234
244
|
}
|
|
245
|
+
async simulate(method, argsOrOptions, maybeOptions) {
|
|
246
|
+
const { args, debugRaw } = splitReadArgsAndOptions(argsOrOptions, maybeOptions);
|
|
247
|
+
const { contractId, transaction } = await this.createTransaction(method, args);
|
|
248
|
+
const raw = await prepareReadTransaction(
|
|
249
|
+
transaction,
|
|
250
|
+
this.contractName,
|
|
251
|
+
method,
|
|
252
|
+
this.config.network.rpcUrl
|
|
253
|
+
);
|
|
254
|
+
const result = readSimulationResult(raw, this.contractName, method);
|
|
255
|
+
return {
|
|
256
|
+
status: "simulated",
|
|
257
|
+
contract: this.contractName,
|
|
258
|
+
method,
|
|
259
|
+
contractId,
|
|
260
|
+
result,
|
|
261
|
+
...debugRaw ? { raw } : {}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async read(method, argsOrOptions, maybeOptions) {
|
|
265
|
+
const result = await this.simulate(method, argsOrOptions, maybeOptions);
|
|
266
|
+
return result.result;
|
|
267
|
+
}
|
|
235
268
|
async createTransaction(method, args) {
|
|
236
269
|
const contractId = resolveContractId({
|
|
237
270
|
artifacts: this.config.artifacts,
|
|
@@ -323,38 +356,100 @@ function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
|
323
356
|
debugRaw: maybeOptions?.debugRaw ?? false
|
|
324
357
|
};
|
|
325
358
|
}
|
|
326
|
-
|
|
359
|
+
function splitReadArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
360
|
+
const looksLikeOptions = argsOrOptions !== void 0 && "debugRaw" in argsOrOptions && maybeOptions === void 0;
|
|
361
|
+
if (looksLikeOptions) {
|
|
362
|
+
const options = argsOrOptions;
|
|
363
|
+
return {
|
|
364
|
+
args: void 0,
|
|
365
|
+
debugRaw: options.debugRaw ?? false
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
args: argsOrOptions,
|
|
370
|
+
debugRaw: maybeOptions?.debugRaw ?? false
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
async function submitTransaction(transaction, signTransaction, contractName, method, rpcUrl) {
|
|
327
374
|
const candidate = transaction;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
375
|
+
if (typeof candidate.signAndSend === "function") {
|
|
376
|
+
try {
|
|
377
|
+
const raw = await candidate.signAndSend.call(transaction, { signTransaction });
|
|
378
|
+
assertSubmitResultRecognized(raw, contractName, method);
|
|
379
|
+
return raw;
|
|
380
|
+
} catch (error) {
|
|
381
|
+
if (error instanceof import_browser4.CaatingaError) {
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
throw new import_browser4.CaatingaError(
|
|
385
|
+
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
386
|
+
import_browser4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
|
|
387
|
+
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
388
|
+
error
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (typeof candidate.send === "function") {
|
|
393
|
+
try {
|
|
394
|
+
const raw = await candidate.send.call(transaction);
|
|
395
|
+
assertSubmitResultRecognized(raw, contractName, method);
|
|
396
|
+
return raw;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
if (error instanceof import_browser4.CaatingaError) {
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
throw new import_browser4.CaatingaError(
|
|
402
|
+
`Failed to submit XDR for "${contractName}.${method}".`,
|
|
403
|
+
import_browser4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
|
|
404
|
+
`RPC: ${rpcUrl}. Check wallet signature and RPC connectivity.`,
|
|
405
|
+
error
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
throw new import_browser4.CaatingaError(
|
|
410
|
+
`Binding transaction for "${contractName}.${method}" cannot be submitted.`,
|
|
411
|
+
import_browser4.CaatingaErrorCode.XDR_SUBMIT_FAILED,
|
|
412
|
+
"Regenerate bindings or provide a compatible binding adapter."
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
async function prepareReadTransaction(transaction, contractName, method, rpcUrl) {
|
|
416
|
+
const candidate = transaction;
|
|
417
|
+
if (typeof candidate.prepare !== "function") {
|
|
418
|
+
return transaction;
|
|
335
419
|
}
|
|
336
420
|
try {
|
|
337
|
-
|
|
338
|
-
assertSubmitResultRecognized(raw, contractName, method);
|
|
339
|
-
return raw;
|
|
421
|
+
return await candidate.prepare.call(transaction);
|
|
340
422
|
} catch (error) {
|
|
341
423
|
if (error instanceof import_browser4.CaatingaError) {
|
|
342
424
|
throw error;
|
|
343
425
|
}
|
|
344
426
|
throw new import_browser4.CaatingaError(
|
|
345
|
-
`Failed to
|
|
346
|
-
import_browser4.CaatingaErrorCode.
|
|
347
|
-
`RPC: ${rpcUrl}. Check
|
|
427
|
+
`Failed to prepare XDR for "${contractName}.${method}".`,
|
|
428
|
+
import_browser4.CaatingaErrorCode.XDR_PREPARE_FAILED,
|
|
429
|
+
`RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
|
|
348
430
|
error
|
|
349
431
|
);
|
|
350
432
|
}
|
|
351
433
|
}
|
|
434
|
+
function readSimulationResult(raw, contractName, method) {
|
|
435
|
+
if (raw !== null && typeof raw === "object" && "result" in raw) {
|
|
436
|
+
const result = raw.result;
|
|
437
|
+
if (result !== void 0) {
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
throw new import_browser4.CaatingaError(
|
|
442
|
+
`Simulation for "${contractName}.${method}" did not return a result.`,
|
|
443
|
+
import_browser4.CaatingaErrorCode.READ_RESULT_MISSING,
|
|
444
|
+
`Expected "${contractName}.${method}" to expose a simulation result. Use debugRaw to inspect the generated binding output.`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
352
447
|
function assertSubmitResultRecognized(raw, contractName, method) {
|
|
353
448
|
if (raw === null || typeof raw !== "object") {
|
|
354
449
|
return;
|
|
355
450
|
}
|
|
356
451
|
const record = raw;
|
|
357
|
-
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record;
|
|
452
|
+
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record || hasNestedSendTransactionResponseHash(record);
|
|
358
453
|
const hasResult = "result" in record;
|
|
359
454
|
if (hasTransactionId || hasResult) {
|
|
360
455
|
return;
|
|
@@ -362,13 +457,17 @@ function assertSubmitResultRecognized(raw, contractName, method) {
|
|
|
362
457
|
throw new import_browser4.CaatingaError(
|
|
363
458
|
`Submit returned an unrecognized payload for "${contractName}.${method}".`,
|
|
364
459
|
import_browser4.CaatingaErrorCode.XDR_RESULT_FAILED,
|
|
365
|
-
"Expected txHash, transactionHash, hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
460
|
+
"Expected txHash, transactionHash, hash, sendTransactionResponse.hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
366
461
|
);
|
|
367
462
|
}
|
|
463
|
+
function hasNestedSendTransactionResponseHash(record) {
|
|
464
|
+
const response = record.sendTransactionResponse;
|
|
465
|
+
return response !== null && typeof response === "object" && "hash" in response;
|
|
466
|
+
}
|
|
368
467
|
function normalizeSubmitResult(raw) {
|
|
369
468
|
const candidate = raw;
|
|
370
469
|
return {
|
|
371
|
-
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash,
|
|
470
|
+
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash ?? candidate.sendTransactionResponse?.hash,
|
|
372
471
|
result: candidate.result
|
|
373
472
|
};
|
|
374
473
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult, g as CaatingaReadOptions, h as CaatingaReadResult } from './types-D4XEyX4J.cjs';
|
|
2
|
+
export { i as CaatingaInvokeStatus, j as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-D4XEyX4J.cjs';
|
|
3
3
|
import { CaatingaArtifacts } from '@caatinga/core/browser';
|
|
4
4
|
|
|
5
5
|
declare function resolveContractId(input: {
|
|
@@ -29,6 +29,8 @@ declare class CaatingaContractClient {
|
|
|
29
29
|
debugRaw?: boolean;
|
|
30
30
|
}): Promise<CaatingaXdrBuildResult>;
|
|
31
31
|
invoke<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaInvokeOptions, maybeOptions?: CaatingaInvokeOptions): Promise<CaatingaInvokeResult<T>>;
|
|
32
|
+
simulate<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaReadOptions, maybeOptions?: CaatingaReadOptions): Promise<CaatingaReadResult<T>>;
|
|
33
|
+
read<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaReadOptions, maybeOptions?: CaatingaReadOptions): Promise<T>;
|
|
32
34
|
private createTransaction;
|
|
33
35
|
private withWalletTimeout;
|
|
34
36
|
}
|
|
@@ -46,4 +48,4 @@ declare function buildXdr(input: {
|
|
|
46
48
|
debug?: boolean;
|
|
47
49
|
}): Promise<CaatingaXdrBuildResult>;
|
|
48
50
|
|
|
49
|
-
export { CaatingaBindingAdapter, CaatingaClientConfig, CaatingaContractClient, CaatingaContractRegistration, CaatingaInvokeOptions, CaatingaInvokeResult, CaatingaXdrBuildResult, buildXdr, createCaatingaClient, createDefaultBindingAdapter, resolveContractId };
|
|
51
|
+
export { CaatingaBindingAdapter, CaatingaClientConfig, CaatingaContractClient, CaatingaContractRegistration, CaatingaInvokeOptions, CaatingaInvokeResult, CaatingaReadOptions, CaatingaReadResult, CaatingaXdrBuildResult, buildXdr, createCaatingaClient, createDefaultBindingAdapter, resolveContractId };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { a as CaatingaBindingAdapter, b as CaatingaClientConfig, c as CaatingaContractRegistration, d as CaatingaXdrBuildResult, e as CaatingaInvokeOptions, f as CaatingaInvokeResult, g as CaatingaReadOptions, h as CaatingaReadResult } from './types-D4XEyX4J.js';
|
|
2
|
+
export { i as CaatingaInvokeStatus, j as CaatingaNetwork, C as CaatingaWalletAdapter } from './types-D4XEyX4J.js';
|
|
3
3
|
import { CaatingaArtifacts } from '@caatinga/core/browser';
|
|
4
4
|
|
|
5
5
|
declare function resolveContractId(input: {
|
|
@@ -29,6 +29,8 @@ declare class CaatingaContractClient {
|
|
|
29
29
|
debugRaw?: boolean;
|
|
30
30
|
}): Promise<CaatingaXdrBuildResult>;
|
|
31
31
|
invoke<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaInvokeOptions, maybeOptions?: CaatingaInvokeOptions): Promise<CaatingaInvokeResult<T>>;
|
|
32
|
+
simulate<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaReadOptions, maybeOptions?: CaatingaReadOptions): Promise<CaatingaReadResult<T>>;
|
|
33
|
+
read<T = unknown>(method: string, argsOrOptions?: Record<string, unknown> | CaatingaReadOptions, maybeOptions?: CaatingaReadOptions): Promise<T>;
|
|
32
34
|
private createTransaction;
|
|
33
35
|
private withWalletTimeout;
|
|
34
36
|
}
|
|
@@ -46,4 +48,4 @@ declare function buildXdr(input: {
|
|
|
46
48
|
debug?: boolean;
|
|
47
49
|
}): Promise<CaatingaXdrBuildResult>;
|
|
48
50
|
|
|
49
|
-
export { CaatingaBindingAdapter, CaatingaClientConfig, CaatingaContractClient, CaatingaContractRegistration, CaatingaInvokeOptions, CaatingaInvokeResult, CaatingaXdrBuildResult, buildXdr, createCaatingaClient, createDefaultBindingAdapter, resolveContractId };
|
|
51
|
+
export { CaatingaBindingAdapter, CaatingaClientConfig, CaatingaContractClient, CaatingaContractRegistration, CaatingaInvokeOptions, CaatingaInvokeResult, CaatingaReadOptions, CaatingaReadResult, CaatingaXdrBuildResult, buildXdr, createCaatingaClient, createDefaultBindingAdapter, resolveContractId };
|
package/dist/index.js
CHANGED
|
@@ -150,40 +150,50 @@ var CaatingaContractClient = class {
|
|
|
150
150
|
debug: debugRaw
|
|
151
151
|
});
|
|
152
152
|
let signedXdr;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
const signTransaction = async (xdr2) => {
|
|
154
|
+
try {
|
|
155
|
+
signedXdr = await this.withWalletTimeout(
|
|
156
|
+
"signTransaction",
|
|
157
|
+
() => this.config.wallet.signTransaction({
|
|
158
|
+
xdr: xdr2,
|
|
159
|
+
networkPassphrase: this.config.network.networkPassphrase
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof CaatingaError4) {
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
throw new CaatingaError4(
|
|
167
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
168
|
+
CaatingaErrorCode4.XDR_SIGN_FAILED,
|
|
169
|
+
"Connect a wallet and approve the transaction.",
|
|
170
|
+
error
|
|
171
|
+
);
|
|
164
172
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
}
|
|
173
|
+
if (typeof signedXdr !== "string" || signedXdr.trim().length === 0) {
|
|
174
|
+
throw new CaatingaError4(
|
|
175
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
176
|
+
CaatingaErrorCode4.XDR_SIGN_FAILED,
|
|
177
|
+
"Wallet returned an empty or invalid signed XDR. The user may have dismissed the signing prompt.",
|
|
178
|
+
signedXdr
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return { signedTxXdr: signedXdr };
|
|
182
|
+
};
|
|
180
183
|
const raw = await submitTransaction(
|
|
181
184
|
transaction,
|
|
182
|
-
|
|
185
|
+
signTransaction,
|
|
183
186
|
this.contractName,
|
|
184
187
|
method,
|
|
185
188
|
this.config.network.rpcUrl
|
|
186
189
|
);
|
|
190
|
+
if (typeof transaction.signAndSend === "function" && signedXdr === void 0) {
|
|
191
|
+
throw new CaatingaError4(
|
|
192
|
+
`Failed to sign XDR for "${this.contractName}.${method}".`,
|
|
193
|
+
CaatingaErrorCode4.XDR_SIGN_FAILED,
|
|
194
|
+
"Wallet returned an empty or invalid signed XDR. The generated transaction did not request a wallet signature."
|
|
195
|
+
);
|
|
196
|
+
}
|
|
187
197
|
const normalized = normalizeSubmitResult(raw);
|
|
188
198
|
return {
|
|
189
199
|
status: "confirmed",
|
|
@@ -196,12 +206,35 @@ var CaatingaContractClient = class {
|
|
|
196
206
|
xdr: {
|
|
197
207
|
unsigned: xdr.unsignedXdr,
|
|
198
208
|
prepared: xdr.preparedXdr,
|
|
199
|
-
signed: signedXdr
|
|
209
|
+
...signedXdr ? { signed: signedXdr } : {}
|
|
200
210
|
}
|
|
201
211
|
} : {},
|
|
202
212
|
...debugRaw ? { raw } : {}
|
|
203
213
|
};
|
|
204
214
|
}
|
|
215
|
+
async simulate(method, argsOrOptions, maybeOptions) {
|
|
216
|
+
const { args, debugRaw } = splitReadArgsAndOptions(argsOrOptions, maybeOptions);
|
|
217
|
+
const { contractId, transaction } = await this.createTransaction(method, args);
|
|
218
|
+
const raw = await prepareReadTransaction(
|
|
219
|
+
transaction,
|
|
220
|
+
this.contractName,
|
|
221
|
+
method,
|
|
222
|
+
this.config.network.rpcUrl
|
|
223
|
+
);
|
|
224
|
+
const result = readSimulationResult(raw, this.contractName, method);
|
|
225
|
+
return {
|
|
226
|
+
status: "simulated",
|
|
227
|
+
contract: this.contractName,
|
|
228
|
+
method,
|
|
229
|
+
contractId,
|
|
230
|
+
result,
|
|
231
|
+
...debugRaw ? { raw } : {}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async read(method, argsOrOptions, maybeOptions) {
|
|
235
|
+
const result = await this.simulate(method, argsOrOptions, maybeOptions);
|
|
236
|
+
return result.result;
|
|
237
|
+
}
|
|
205
238
|
async createTransaction(method, args) {
|
|
206
239
|
const contractId = resolveContractId({
|
|
207
240
|
artifacts: this.config.artifacts,
|
|
@@ -293,38 +326,100 @@ function splitInvokeArgsAndOptions(argsOrOptions, maybeOptions) {
|
|
|
293
326
|
debugRaw: maybeOptions?.debugRaw ?? false
|
|
294
327
|
};
|
|
295
328
|
}
|
|
296
|
-
|
|
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) {
|
|
297
344
|
const candidate = transaction;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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;
|
|
305
389
|
}
|
|
306
390
|
try {
|
|
307
|
-
|
|
308
|
-
assertSubmitResultRecognized(raw, contractName, method);
|
|
309
|
-
return raw;
|
|
391
|
+
return await candidate.prepare.call(transaction);
|
|
310
392
|
} catch (error) {
|
|
311
393
|
if (error instanceof CaatingaError4) {
|
|
312
394
|
throw error;
|
|
313
395
|
}
|
|
314
396
|
throw new CaatingaError4(
|
|
315
|
-
`Failed to
|
|
316
|
-
CaatingaErrorCode4.
|
|
317
|
-
`RPC: ${rpcUrl}. Check
|
|
397
|
+
`Failed to prepare XDR for "${contractName}.${method}".`,
|
|
398
|
+
CaatingaErrorCode4.XDR_PREPARE_FAILED,
|
|
399
|
+
`RPC: ${rpcUrl}. Check connectivity, simulation errors, and binding compatibility.`,
|
|
318
400
|
error
|
|
319
401
|
);
|
|
320
402
|
}
|
|
321
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
|
+
}
|
|
322
417
|
function assertSubmitResultRecognized(raw, contractName, method) {
|
|
323
418
|
if (raw === null || typeof raw !== "object") {
|
|
324
419
|
return;
|
|
325
420
|
}
|
|
326
421
|
const record = raw;
|
|
327
|
-
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record;
|
|
422
|
+
const hasTransactionId = "txHash" in record || "transactionHash" in record || "hash" in record || hasNestedSendTransactionResponseHash(record);
|
|
328
423
|
const hasResult = "result" in record;
|
|
329
424
|
if (hasTransactionId || hasResult) {
|
|
330
425
|
return;
|
|
@@ -332,13 +427,17 @@ function assertSubmitResultRecognized(raw, contractName, method) {
|
|
|
332
427
|
throw new CaatingaError4(
|
|
333
428
|
`Submit returned an unrecognized payload for "${contractName}.${method}".`,
|
|
334
429
|
CaatingaErrorCode4.XDR_RESULT_FAILED,
|
|
335
|
-
"Expected txHash, transactionHash, hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
430
|
+
"Expected txHash, transactionHash, hash, sendTransactionResponse.hash, or result on the submit response. Use debugRaw to inspect the binding output."
|
|
336
431
|
);
|
|
337
432
|
}
|
|
433
|
+
function hasNestedSendTransactionResponseHash(record) {
|
|
434
|
+
const response = record.sendTransactionResponse;
|
|
435
|
+
return response !== null && typeof response === "object" && "hash" in response;
|
|
436
|
+
}
|
|
338
437
|
function normalizeSubmitResult(raw) {
|
|
339
438
|
const candidate = raw;
|
|
340
439
|
return {
|
|
341
|
-
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash,
|
|
440
|
+
transactionHash: candidate.txHash ?? candidate.transactionHash ?? candidate.hash ?? candidate.sendTransactionResponse?.hash,
|
|
342
441
|
result: candidate.result
|
|
343
442
|
};
|
|
344
443
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/stellar-wallets-kit.ts
|
|
21
|
+
var stellar_wallets_kit_exports = {};
|
|
22
|
+
__export(stellar_wallets_kit_exports, {
|
|
23
|
+
createStellarWalletsKitAdapter: () => createStellarWalletsKitAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(stellar_wallets_kit_exports);
|
|
26
|
+
|
|
27
|
+
// src/adapters/stellar-wallets-kit.ts
|
|
28
|
+
var import_stellar_wallets_kit = require("stellar-wallets-kit");
|
|
29
|
+
function createStellarWalletsKitAdapter(options = {}) {
|
|
30
|
+
const kit = options.kit ?? new import_stellar_wallets_kit.StellarWalletsKit({
|
|
31
|
+
network: options.network ?? import_stellar_wallets_kit.WalletNetwork.TESTNET,
|
|
32
|
+
selectedWallet: options.selectedWallet ?? import_stellar_wallets_kit.WalletType.XBULL
|
|
33
|
+
});
|
|
34
|
+
let publicKey;
|
|
35
|
+
let isWalletConnectStarted = false;
|
|
36
|
+
const sessionDeletedCallbacks = /* @__PURE__ */ new Set();
|
|
37
|
+
return {
|
|
38
|
+
kit,
|
|
39
|
+
async setWallet(wallet) {
|
|
40
|
+
await kit.setWallet(wallet);
|
|
41
|
+
publicKey = void 0;
|
|
42
|
+
},
|
|
43
|
+
async setNetwork(network) {
|
|
44
|
+
await kit.setNetwork(network);
|
|
45
|
+
publicKey = void 0;
|
|
46
|
+
},
|
|
47
|
+
async getPublicKey() {
|
|
48
|
+
publicKey = await kit.getPublicKey();
|
|
49
|
+
return publicKey;
|
|
50
|
+
},
|
|
51
|
+
async signTransaction({ xdr, networkPassphrase }) {
|
|
52
|
+
const walletNetwork = resolveWalletNetwork(networkPassphrase);
|
|
53
|
+
if (walletNetwork) {
|
|
54
|
+
await kit.setNetwork(walletNetwork);
|
|
55
|
+
}
|
|
56
|
+
const signer = publicKey ?? await kit.getPublicKey();
|
|
57
|
+
publicKey = signer;
|
|
58
|
+
const response = await kit.sign({ xdr, publicKey: signer });
|
|
59
|
+
return response.signedXDR;
|
|
60
|
+
},
|
|
61
|
+
async startWalletConnect(metadata = options.walletConnectMetadata) {
|
|
62
|
+
if (!metadata) {
|
|
63
|
+
throw new Error("WalletConnect metadata is required before starting WalletConnect.");
|
|
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);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
async connectWalletConnect(connectOptions) {
|
|
75
|
+
await kit.connectWalletConnect(connectOptions);
|
|
76
|
+
publicKey = void 0;
|
|
77
|
+
},
|
|
78
|
+
async getWalletConnectSessions() {
|
|
79
|
+
return kit.getSessions();
|
|
80
|
+
},
|
|
81
|
+
setWalletConnectSession(sessionId) {
|
|
82
|
+
kit.setSession(sessionId);
|
|
83
|
+
publicKey = void 0;
|
|
84
|
+
},
|
|
85
|
+
onWalletConnectSessionDeleted(callback) {
|
|
86
|
+
sessionDeletedCallbacks.add(callback);
|
|
87
|
+
if (!isWalletConnectStarted) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
kit.onSessionDeleted((sessionId) => {
|
|
91
|
+
publicKey = void 0;
|
|
92
|
+
callback(sessionId);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function resolveWalletNetwork(networkPassphrase) {
|
|
98
|
+
if (networkPassphrase === "Test SDF Network ; September 2015") {
|
|
99
|
+
return import_stellar_wallets_kit.WalletNetwork.TESTNET;
|
|
100
|
+
}
|
|
101
|
+
if (networkPassphrase === "Public Global Stellar Network ; September 2015") {
|
|
102
|
+
return import_stellar_wallets_kit.WalletNetwork.PUBLIC;
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
createStellarWalletsKitAdapter
|
|
109
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { StellarWalletsKit, WalletType, WalletNetwork, IConnectWalletConnectParams } from 'stellar-wallets-kit';
|
|
2
|
+
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.cjs';
|
|
3
|
+
import '@caatinga/core/browser';
|
|
4
|
+
|
|
5
|
+
interface StellarWalletsKitMetadata {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
url: string;
|
|
9
|
+
icons: string[];
|
|
10
|
+
projectId: string;
|
|
11
|
+
}
|
|
12
|
+
interface StellarWalletsKitAdapterOptions {
|
|
13
|
+
kit?: StellarWalletsKit;
|
|
14
|
+
network?: WalletNetwork;
|
|
15
|
+
selectedWallet?: WalletType;
|
|
16
|
+
walletConnectMetadata?: StellarWalletsKitMetadata;
|
|
17
|
+
}
|
|
18
|
+
interface StellarWalletsKitConnectOptions {
|
|
19
|
+
chains?: IConnectWalletConnectParams["chains"];
|
|
20
|
+
methods?: IConnectWalletConnectParams["methods"];
|
|
21
|
+
pairingTopic?: IConnectWalletConnectParams["pairingTopic"];
|
|
22
|
+
}
|
|
23
|
+
interface StellarWalletsKitSession {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
url: string;
|
|
28
|
+
icons: string;
|
|
29
|
+
accounts: Array<{
|
|
30
|
+
network: "pubnet" | "testnet";
|
|
31
|
+
publicKey: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
35
|
+
kit: StellarWalletsKit;
|
|
36
|
+
setWallet(wallet: WalletType): Promise<void>;
|
|
37
|
+
setNetwork(network: WalletNetwork): Promise<void>;
|
|
38
|
+
startWalletConnect(metadata?: StellarWalletsKitMetadata): Promise<void>;
|
|
39
|
+
connectWalletConnect(options?: StellarWalletsKitConnectOptions): Promise<void>;
|
|
40
|
+
getWalletConnectSessions(): Promise<StellarWalletsKitSession[]>;
|
|
41
|
+
setWalletConnectSession(sessionId: string): void;
|
|
42
|
+
onWalletConnectSessionDeleted(callback: (sessionId: string) => void): void;
|
|
43
|
+
}
|
|
44
|
+
declare function createStellarWalletsKitAdapter(options?: StellarWalletsKitAdapterOptions): StellarWalletsKitAdapter;
|
|
45
|
+
|
|
46
|
+
export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitConnectOptions, type StellarWalletsKitMetadata, type StellarWalletsKitSession, createStellarWalletsKitAdapter };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { StellarWalletsKit, WalletType, WalletNetwork, IConnectWalletConnectParams } from 'stellar-wallets-kit';
|
|
2
|
+
import { C as CaatingaWalletAdapter } from './types-D4XEyX4J.js';
|
|
3
|
+
import '@caatinga/core/browser';
|
|
4
|
+
|
|
5
|
+
interface StellarWalletsKitMetadata {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
url: string;
|
|
9
|
+
icons: string[];
|
|
10
|
+
projectId: string;
|
|
11
|
+
}
|
|
12
|
+
interface StellarWalletsKitAdapterOptions {
|
|
13
|
+
kit?: StellarWalletsKit;
|
|
14
|
+
network?: WalletNetwork;
|
|
15
|
+
selectedWallet?: WalletType;
|
|
16
|
+
walletConnectMetadata?: StellarWalletsKitMetadata;
|
|
17
|
+
}
|
|
18
|
+
interface StellarWalletsKitConnectOptions {
|
|
19
|
+
chains?: IConnectWalletConnectParams["chains"];
|
|
20
|
+
methods?: IConnectWalletConnectParams["methods"];
|
|
21
|
+
pairingTopic?: IConnectWalletConnectParams["pairingTopic"];
|
|
22
|
+
}
|
|
23
|
+
interface StellarWalletsKitSession {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
url: string;
|
|
28
|
+
icons: string;
|
|
29
|
+
accounts: Array<{
|
|
30
|
+
network: "pubnet" | "testnet";
|
|
31
|
+
publicKey: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
interface StellarWalletsKitAdapter extends CaatingaWalletAdapter {
|
|
35
|
+
kit: StellarWalletsKit;
|
|
36
|
+
setWallet(wallet: WalletType): Promise<void>;
|
|
37
|
+
setNetwork(network: WalletNetwork): Promise<void>;
|
|
38
|
+
startWalletConnect(metadata?: StellarWalletsKitMetadata): Promise<void>;
|
|
39
|
+
connectWalletConnect(options?: StellarWalletsKitConnectOptions): Promise<void>;
|
|
40
|
+
getWalletConnectSessions(): Promise<StellarWalletsKitSession[]>;
|
|
41
|
+
setWalletConnectSession(sessionId: string): void;
|
|
42
|
+
onWalletConnectSessionDeleted(callback: (sessionId: string) => void): void;
|
|
43
|
+
}
|
|
44
|
+
declare function createStellarWalletsKitAdapter(options?: StellarWalletsKitAdapterOptions): StellarWalletsKitAdapter;
|
|
45
|
+
|
|
46
|
+
export { type StellarWalletsKitAdapter, type StellarWalletsKitAdapterOptions, type StellarWalletsKitConnectOptions, type StellarWalletsKitMetadata, type StellarWalletsKitSession, createStellarWalletsKitAdapter };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/adapters/stellar-wallets-kit.ts
|
|
2
|
+
import {
|
|
3
|
+
StellarWalletsKit,
|
|
4
|
+
WalletNetwork,
|
|
5
|
+
WalletType
|
|
6
|
+
} from "stellar-wallets-kit";
|
|
7
|
+
function createStellarWalletsKitAdapter(options = {}) {
|
|
8
|
+
const kit = options.kit ?? new StellarWalletsKit({
|
|
9
|
+
network: options.network ?? WalletNetwork.TESTNET,
|
|
10
|
+
selectedWallet: options.selectedWallet ?? WalletType.XBULL
|
|
11
|
+
});
|
|
12
|
+
let publicKey;
|
|
13
|
+
let isWalletConnectStarted = false;
|
|
14
|
+
const sessionDeletedCallbacks = /* @__PURE__ */ new Set();
|
|
15
|
+
return {
|
|
16
|
+
kit,
|
|
17
|
+
async setWallet(wallet) {
|
|
18
|
+
await kit.setWallet(wallet);
|
|
19
|
+
publicKey = void 0;
|
|
20
|
+
},
|
|
21
|
+
async setNetwork(network) {
|
|
22
|
+
await kit.setNetwork(network);
|
|
23
|
+
publicKey = void 0;
|
|
24
|
+
},
|
|
25
|
+
async getPublicKey() {
|
|
26
|
+
publicKey = await kit.getPublicKey();
|
|
27
|
+
return publicKey;
|
|
28
|
+
},
|
|
29
|
+
async signTransaction({ xdr, networkPassphrase }) {
|
|
30
|
+
const walletNetwork = resolveWalletNetwork(networkPassphrase);
|
|
31
|
+
if (walletNetwork) {
|
|
32
|
+
await kit.setNetwork(walletNetwork);
|
|
33
|
+
}
|
|
34
|
+
const signer = publicKey ?? await kit.getPublicKey();
|
|
35
|
+
publicKey = signer;
|
|
36
|
+
const response = await kit.sign({ xdr, publicKey: signer });
|
|
37
|
+
return response.signedXDR;
|
|
38
|
+
},
|
|
39
|
+
async startWalletConnect(metadata = options.walletConnectMetadata) {
|
|
40
|
+
if (!metadata) {
|
|
41
|
+
throw new Error("WalletConnect metadata is required before starting WalletConnect.");
|
|
42
|
+
}
|
|
43
|
+
await kit.startWalletConnect(metadata);
|
|
44
|
+
isWalletConnectStarted = true;
|
|
45
|
+
for (const callback of sessionDeletedCallbacks) {
|
|
46
|
+
kit.onSessionDeleted((sessionId) => {
|
|
47
|
+
publicKey = void 0;
|
|
48
|
+
callback(sessionId);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async connectWalletConnect(connectOptions) {
|
|
53
|
+
await kit.connectWalletConnect(connectOptions);
|
|
54
|
+
publicKey = void 0;
|
|
55
|
+
},
|
|
56
|
+
async getWalletConnectSessions() {
|
|
57
|
+
return kit.getSessions();
|
|
58
|
+
},
|
|
59
|
+
setWalletConnectSession(sessionId) {
|
|
60
|
+
kit.setSession(sessionId);
|
|
61
|
+
publicKey = void 0;
|
|
62
|
+
},
|
|
63
|
+
onWalletConnectSessionDeleted(callback) {
|
|
64
|
+
sessionDeletedCallbacks.add(callback);
|
|
65
|
+
if (!isWalletConnectStarted) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
kit.onSessionDeleted((sessionId) => {
|
|
69
|
+
publicKey = void 0;
|
|
70
|
+
callback(sessionId);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function resolveWalletNetwork(networkPassphrase) {
|
|
76
|
+
if (networkPassphrase === "Test SDF Network ; September 2015") {
|
|
77
|
+
return WalletNetwork.TESTNET;
|
|
78
|
+
}
|
|
79
|
+
if (networkPassphrase === "Public Global Stellar Network ; September 2015") {
|
|
80
|
+
return WalletNetwork.PUBLIC;
|
|
81
|
+
}
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
createStellarWalletsKitAdapter
|
|
86
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CaatingaArtifacts } from '@caatinga/core/browser';
|
|
2
|
+
|
|
3
|
+
interface CaatingaNetwork {
|
|
4
|
+
name: string;
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
networkPassphrase: string;
|
|
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
|
+
*/
|
|
15
|
+
interface CaatingaWalletAdapter {
|
|
16
|
+
getPublicKey(): Promise<string>;
|
|
17
|
+
signTransaction(input: {
|
|
18
|
+
xdr: string;
|
|
19
|
+
networkPassphrase: string;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
interface CaatingaContractRegistration {
|
|
23
|
+
binding: unknown;
|
|
24
|
+
contractId?: string;
|
|
25
|
+
}
|
|
26
|
+
interface CaatingaClientConfig {
|
|
27
|
+
network: CaatingaNetwork;
|
|
28
|
+
artifacts: CaatingaArtifacts;
|
|
29
|
+
wallet: CaatingaWalletAdapter;
|
|
30
|
+
/** Optional timeout (ms) for wallet `getPublicKey` and `signTransaction`. No default when omitted. */
|
|
31
|
+
walletTimeout?: number;
|
|
32
|
+
contracts: Record<string, CaatingaContractRegistration>;
|
|
33
|
+
}
|
|
34
|
+
type CaatingaInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
|
|
35
|
+
interface CaatingaInvokeOptions {
|
|
36
|
+
debugXdr?: boolean;
|
|
37
|
+
debugRaw?: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface CaatingaReadOptions {
|
|
40
|
+
debugRaw?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface CaatingaInvokeResult<T = unknown> {
|
|
43
|
+
status: CaatingaInvokeStatus;
|
|
44
|
+
contract: string;
|
|
45
|
+
method: string;
|
|
46
|
+
contractId: string;
|
|
47
|
+
transactionHash?: string;
|
|
48
|
+
result?: T;
|
|
49
|
+
xdr?: {
|
|
50
|
+
unsigned?: string;
|
|
51
|
+
prepared?: string;
|
|
52
|
+
signed?: string;
|
|
53
|
+
};
|
|
54
|
+
raw?: unknown;
|
|
55
|
+
}
|
|
56
|
+
interface CaatingaReadResult<T = unknown> {
|
|
57
|
+
status: "simulated";
|
|
58
|
+
contract: string;
|
|
59
|
+
method: string;
|
|
60
|
+
contractId: string;
|
|
61
|
+
result: T;
|
|
62
|
+
raw?: unknown;
|
|
63
|
+
}
|
|
64
|
+
interface CaatingaXdrBuildResult {
|
|
65
|
+
contract: string;
|
|
66
|
+
method: string;
|
|
67
|
+
contractId: string;
|
|
68
|
+
unsignedXdr?: string;
|
|
69
|
+
preparedXdr: string;
|
|
70
|
+
raw?: unknown;
|
|
71
|
+
}
|
|
72
|
+
interface CaatingaBindingAdapter {
|
|
73
|
+
createClient(input: {
|
|
74
|
+
contractId: string;
|
|
75
|
+
publicKey: string;
|
|
76
|
+
rpcUrl: string;
|
|
77
|
+
networkPassphrase: string;
|
|
78
|
+
}): unknown;
|
|
79
|
+
callMethod(input: {
|
|
80
|
+
client: unknown;
|
|
81
|
+
method: string;
|
|
82
|
+
args?: Record<string, unknown>;
|
|
83
|
+
}): Promise<unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type { CaatingaWalletAdapter as C, CaatingaBindingAdapter as a, CaatingaClientConfig as b, CaatingaContractRegistration as c, CaatingaXdrBuildResult as d, CaatingaInvokeOptions as e, CaatingaInvokeResult as f, CaatingaReadOptions as g, CaatingaReadResult as h, CaatingaInvokeStatus as i, CaatingaNetwork as j };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CaatingaArtifacts } from '@caatinga/core/browser';
|
|
2
|
+
|
|
3
|
+
interface CaatingaNetwork {
|
|
4
|
+
name: string;
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
networkPassphrase: string;
|
|
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
|
+
*/
|
|
15
|
+
interface CaatingaWalletAdapter {
|
|
16
|
+
getPublicKey(): Promise<string>;
|
|
17
|
+
signTransaction(input: {
|
|
18
|
+
xdr: string;
|
|
19
|
+
networkPassphrase: string;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
interface CaatingaContractRegistration {
|
|
23
|
+
binding: unknown;
|
|
24
|
+
contractId?: string;
|
|
25
|
+
}
|
|
26
|
+
interface CaatingaClientConfig {
|
|
27
|
+
network: CaatingaNetwork;
|
|
28
|
+
artifacts: CaatingaArtifacts;
|
|
29
|
+
wallet: CaatingaWalletAdapter;
|
|
30
|
+
/** Optional timeout (ms) for wallet `getPublicKey` and `signTransaction`. No default when omitted. */
|
|
31
|
+
walletTimeout?: number;
|
|
32
|
+
contracts: Record<string, CaatingaContractRegistration>;
|
|
33
|
+
}
|
|
34
|
+
type CaatingaInvokeStatus = "built" | "prepared" | "signed" | "submitted" | "confirmed" | "failed";
|
|
35
|
+
interface CaatingaInvokeOptions {
|
|
36
|
+
debugXdr?: boolean;
|
|
37
|
+
debugRaw?: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface CaatingaReadOptions {
|
|
40
|
+
debugRaw?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface CaatingaInvokeResult<T = unknown> {
|
|
43
|
+
status: CaatingaInvokeStatus;
|
|
44
|
+
contract: string;
|
|
45
|
+
method: string;
|
|
46
|
+
contractId: string;
|
|
47
|
+
transactionHash?: string;
|
|
48
|
+
result?: T;
|
|
49
|
+
xdr?: {
|
|
50
|
+
unsigned?: string;
|
|
51
|
+
prepared?: string;
|
|
52
|
+
signed?: string;
|
|
53
|
+
};
|
|
54
|
+
raw?: unknown;
|
|
55
|
+
}
|
|
56
|
+
interface CaatingaReadResult<T = unknown> {
|
|
57
|
+
status: "simulated";
|
|
58
|
+
contract: string;
|
|
59
|
+
method: string;
|
|
60
|
+
contractId: string;
|
|
61
|
+
result: T;
|
|
62
|
+
raw?: unknown;
|
|
63
|
+
}
|
|
64
|
+
interface CaatingaXdrBuildResult {
|
|
65
|
+
contract: string;
|
|
66
|
+
method: string;
|
|
67
|
+
contractId: string;
|
|
68
|
+
unsignedXdr?: string;
|
|
69
|
+
preparedXdr: string;
|
|
70
|
+
raw?: unknown;
|
|
71
|
+
}
|
|
72
|
+
interface CaatingaBindingAdapter {
|
|
73
|
+
createClient(input: {
|
|
74
|
+
contractId: string;
|
|
75
|
+
publicKey: string;
|
|
76
|
+
rpcUrl: string;
|
|
77
|
+
networkPassphrase: string;
|
|
78
|
+
}): unknown;
|
|
79
|
+
callMethod(input: {
|
|
80
|
+
client: unknown;
|
|
81
|
+
method: string;
|
|
82
|
+
args?: Record<string, unknown>;
|
|
83
|
+
}): Promise<unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type { CaatingaWalletAdapter as C, CaatingaBindingAdapter as a, CaatingaClientConfig as b, CaatingaContractRegistration as c, CaatingaXdrBuildResult as d, CaatingaInvokeOptions as e, CaatingaInvokeResult as f, CaatingaReadOptions as g, CaatingaReadResult as h, CaatingaInvokeStatus as i, CaatingaNetwork as j };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caatinga/client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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",
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"types": "./dist/freighter.d.ts",
|
|
39
39
|
"import": "./dist/freighter.js",
|
|
40
40
|
"require": "./dist/freighter.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./stellar-wallets-kit": {
|
|
43
|
+
"types": "./dist/stellar-wallets-kit.d.ts",
|
|
44
|
+
"import": "./dist/stellar-wallets-kit.js",
|
|
45
|
+
"require": "./dist/stellar-wallets-kit.cjs"
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"files": [
|
|
@@ -46,23 +51,28 @@
|
|
|
46
51
|
"LICENSE"
|
|
47
52
|
],
|
|
48
53
|
"dependencies": {
|
|
49
|
-
"@caatinga/core": "^0.2.
|
|
54
|
+
"@caatinga/core": "^0.2.4"
|
|
50
55
|
},
|
|
51
56
|
"devDependencies": {
|
|
52
57
|
"tsup": "^8.3.5",
|
|
58
|
+
"stellar-wallets-kit": "github:Creit-Tech/Stellar-Wallets-Kit#v0.0.7",
|
|
53
59
|
"typescript": "^5.7.2",
|
|
54
60
|
"vitest": "^2.1.8"
|
|
55
61
|
},
|
|
56
62
|
"peerDependencies": {
|
|
57
|
-
"@stellar/freighter-api": "^4.0.0"
|
|
63
|
+
"@stellar/freighter-api": "^4.0.0",
|
|
64
|
+
"stellar-wallets-kit": "github:Creit-Tech/Stellar-Wallets-Kit#v0.0.7"
|
|
58
65
|
},
|
|
59
66
|
"peerDependenciesMeta": {
|
|
60
67
|
"@stellar/freighter-api": {
|
|
61
68
|
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"stellar-wallets-kit": {
|
|
71
|
+
"optional": true
|
|
62
72
|
}
|
|
63
73
|
},
|
|
64
74
|
"scripts": {
|
|
65
|
-
"build": "tsup src/index.ts src/freighter.ts --format esm,cjs --dts",
|
|
75
|
+
"build": "tsup src/index.ts src/freighter.ts src/stellar-wallets-kit.ts --format esm,cjs --dts",
|
|
66
76
|
"test": "vitest run --pool=threads",
|
|
67
77
|
"pretypecheck": "pnpm --filter @caatinga/core run build",
|
|
68
78
|
"typecheck": "tsc --noEmit"
|