stellar-contracts-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +434 -0
- package/dist/cli/generate.js +951 -0
- package/dist/index.cjs +844 -0
- package/dist/index.d.cts +95 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +831 -0
- package/dist/wallets/index.cjs +199 -0
- package/dist/wallets/index.d.cts +60 -0
- package/dist/wallets/index.d.ts +60 -0
- package/dist/wallets/index.js +191 -0
- package/package.json +72 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { WalletAdapter, ConnectResult } from './wallets/index.cjs';
|
|
2
|
+
export { CyphrasAdapter, FreighterAdapter, LobstrAdapter, SignAuthEntryOpts, SignTransactionOpts } from './wallets/index.cjs';
|
|
3
|
+
|
|
4
|
+
interface NetworkConfig {
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
networkPassphrase: string;
|
|
7
|
+
horizonUrl: string;
|
|
8
|
+
}
|
|
9
|
+
type NetworkPreset = 'mainnet' | 'testnet' | 'futurenet';
|
|
10
|
+
declare const NETWORKS: Record<NetworkPreset, NetworkConfig>;
|
|
11
|
+
|
|
12
|
+
interface ReadResult<T = unknown> {
|
|
13
|
+
result: T;
|
|
14
|
+
}
|
|
15
|
+
interface WriteResult<T = unknown> {
|
|
16
|
+
txHash: string;
|
|
17
|
+
result: T | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A single contract method with auto/read/invoke call modes. Use ContractMethodFn<ReturnType, [arg: Type, ...]> to type each method. */
|
|
20
|
+
type ContractMethodFn<TReturn = unknown, TArgs extends unknown[] = unknown[]> = {
|
|
21
|
+
(...args: TArgs): Promise<WriteResult<TReturn> | ReadResult<TReturn>>;
|
|
22
|
+
read(...args: TArgs): Promise<ReadResult<TReturn>>;
|
|
23
|
+
simulate(...args: TArgs): Promise<ReadResult<TReturn>>;
|
|
24
|
+
invoke(...args: TArgs): Promise<WriteResult<TReturn>>;
|
|
25
|
+
};
|
|
26
|
+
type ContractClient = Record<string, ContractMethodFn>;
|
|
27
|
+
|
|
28
|
+
interface StellarContractsKitOptions {
|
|
29
|
+
network: NetworkPreset | NetworkConfig;
|
|
30
|
+
/** If omitted, connect() opens the built-in picker modal. */
|
|
31
|
+
wallet?: WalletAdapter;
|
|
32
|
+
}
|
|
33
|
+
declare class StellarContractsKit {
|
|
34
|
+
private readonly network;
|
|
35
|
+
private readonly server;
|
|
36
|
+
private wallet;
|
|
37
|
+
private readonly specCache;
|
|
38
|
+
constructor(options: StellarContractsKitOptions);
|
|
39
|
+
setWallet(wallet: WalletAdapter): void;
|
|
40
|
+
/** Returns the active wallet adapter, or null if none is set. */
|
|
41
|
+
getWallet(): WalletAdapter | null;
|
|
42
|
+
/** Connects to the configured wallet, or opens the built-in picker modal if none is set. */
|
|
43
|
+
connect(): Promise<ConnectResult>;
|
|
44
|
+
/** Disconnects the current wallet and clears the active adapter. */
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
isConnected(): boolean;
|
|
47
|
+
/** Returns the address of the connected wallet. Throws WALLET_NOT_CONNECTED if no wallet is set. */
|
|
48
|
+
getAddress(): Promise<string>;
|
|
49
|
+
getNetwork(): NetworkConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Loads a typed contract client. Pass a generated interface as the type param for full autocomplete.
|
|
52
|
+
* No wallet required for read/simulate calls. A wallet is required before calling invoke.
|
|
53
|
+
* The spec is fetched once and cached; subsequent calls with the same ID are instant.
|
|
54
|
+
*/
|
|
55
|
+
contract<T extends {
|
|
56
|
+
[K in keyof T]: ContractMethodFn<any, any[]>;
|
|
57
|
+
} = ContractClient>(contractId: string): Promise<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Restores an expired contract's on-chain state.
|
|
60
|
+
* Call this when contract() or invoke() throws CONTRACT_RESTORE_REQUIRED.
|
|
61
|
+
*/
|
|
62
|
+
restoreContract(contractId: string): Promise<{
|
|
63
|
+
txHash: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Clears the cached contract spec. Pass a contractId to clear one, or omit to clear all. */
|
|
66
|
+
clearSpecCache(contractId?: string): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface PickResult {
|
|
70
|
+
adapter: WalletAdapter;
|
|
71
|
+
address: string;
|
|
72
|
+
}
|
|
73
|
+
declare class WalletPickerModal {
|
|
74
|
+
private overlay;
|
|
75
|
+
private onKeydown;
|
|
76
|
+
pick(): Promise<PickResult>;
|
|
77
|
+
private render;
|
|
78
|
+
private close;
|
|
79
|
+
private dismiss;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_CONNECTED' | 'WALLET_REJECTED' | 'WALLET_NETWORK_MISMATCH' | 'CONTRACT_NOT_FOUND' | 'CONTRACT_SPEC_ERROR' | 'CONTRACT_SIMULATION_FAILED' | 'CONTRACT_RESTORE_REQUIRED' | 'INVALID_CONTRACT_ID' | 'INVALID_PARAMS' | 'TX_SUBMISSION_FAILED' | 'TX_TIMEOUT' | 'TX_FAILED' | 'RPC_ERROR' | 'UNKNOWN';
|
|
83
|
+
interface ContractKitError {
|
|
84
|
+
code: ErrorCode;
|
|
85
|
+
message: string;
|
|
86
|
+
cause?: unknown;
|
|
87
|
+
}
|
|
88
|
+
declare class StellarContractError extends Error {
|
|
89
|
+
readonly code: ErrorCode;
|
|
90
|
+
readonly cause?: unknown;
|
|
91
|
+
constructor(code: ErrorCode, message: string, cause?: unknown);
|
|
92
|
+
}
|
|
93
|
+
declare function isContractKitError(err: unknown): err is StellarContractError;
|
|
94
|
+
|
|
95
|
+
export { ConnectResult, type ContractClient, type ContractKitError, type ContractMethodFn, type ErrorCode, NETWORKS, type NetworkConfig, type NetworkPreset, type PickResult, type ReadResult, StellarContractError, StellarContractsKit, type StellarContractsKitOptions, WalletAdapter, WalletPickerModal, type WriteResult, isContractKitError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { WalletAdapter, ConnectResult } from './wallets/index.js';
|
|
2
|
+
export { CyphrasAdapter, FreighterAdapter, LobstrAdapter, SignAuthEntryOpts, SignTransactionOpts } from './wallets/index.js';
|
|
3
|
+
|
|
4
|
+
interface NetworkConfig {
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
networkPassphrase: string;
|
|
7
|
+
horizonUrl: string;
|
|
8
|
+
}
|
|
9
|
+
type NetworkPreset = 'mainnet' | 'testnet' | 'futurenet';
|
|
10
|
+
declare const NETWORKS: Record<NetworkPreset, NetworkConfig>;
|
|
11
|
+
|
|
12
|
+
interface ReadResult<T = unknown> {
|
|
13
|
+
result: T;
|
|
14
|
+
}
|
|
15
|
+
interface WriteResult<T = unknown> {
|
|
16
|
+
txHash: string;
|
|
17
|
+
result: T | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A single contract method with auto/read/invoke call modes. Use ContractMethodFn<ReturnType, [arg: Type, ...]> to type each method. */
|
|
20
|
+
type ContractMethodFn<TReturn = unknown, TArgs extends unknown[] = unknown[]> = {
|
|
21
|
+
(...args: TArgs): Promise<WriteResult<TReturn> | ReadResult<TReturn>>;
|
|
22
|
+
read(...args: TArgs): Promise<ReadResult<TReturn>>;
|
|
23
|
+
simulate(...args: TArgs): Promise<ReadResult<TReturn>>;
|
|
24
|
+
invoke(...args: TArgs): Promise<WriteResult<TReturn>>;
|
|
25
|
+
};
|
|
26
|
+
type ContractClient = Record<string, ContractMethodFn>;
|
|
27
|
+
|
|
28
|
+
interface StellarContractsKitOptions {
|
|
29
|
+
network: NetworkPreset | NetworkConfig;
|
|
30
|
+
/** If omitted, connect() opens the built-in picker modal. */
|
|
31
|
+
wallet?: WalletAdapter;
|
|
32
|
+
}
|
|
33
|
+
declare class StellarContractsKit {
|
|
34
|
+
private readonly network;
|
|
35
|
+
private readonly server;
|
|
36
|
+
private wallet;
|
|
37
|
+
private readonly specCache;
|
|
38
|
+
constructor(options: StellarContractsKitOptions);
|
|
39
|
+
setWallet(wallet: WalletAdapter): void;
|
|
40
|
+
/** Returns the active wallet adapter, or null if none is set. */
|
|
41
|
+
getWallet(): WalletAdapter | null;
|
|
42
|
+
/** Connects to the configured wallet, or opens the built-in picker modal if none is set. */
|
|
43
|
+
connect(): Promise<ConnectResult>;
|
|
44
|
+
/** Disconnects the current wallet and clears the active adapter. */
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
isConnected(): boolean;
|
|
47
|
+
/** Returns the address of the connected wallet. Throws WALLET_NOT_CONNECTED if no wallet is set. */
|
|
48
|
+
getAddress(): Promise<string>;
|
|
49
|
+
getNetwork(): NetworkConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Loads a typed contract client. Pass a generated interface as the type param for full autocomplete.
|
|
52
|
+
* No wallet required for read/simulate calls. A wallet is required before calling invoke.
|
|
53
|
+
* The spec is fetched once and cached; subsequent calls with the same ID are instant.
|
|
54
|
+
*/
|
|
55
|
+
contract<T extends {
|
|
56
|
+
[K in keyof T]: ContractMethodFn<any, any[]>;
|
|
57
|
+
} = ContractClient>(contractId: string): Promise<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Restores an expired contract's on-chain state.
|
|
60
|
+
* Call this when contract() or invoke() throws CONTRACT_RESTORE_REQUIRED.
|
|
61
|
+
*/
|
|
62
|
+
restoreContract(contractId: string): Promise<{
|
|
63
|
+
txHash: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Clears the cached contract spec. Pass a contractId to clear one, or omit to clear all. */
|
|
66
|
+
clearSpecCache(contractId?: string): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface PickResult {
|
|
70
|
+
adapter: WalletAdapter;
|
|
71
|
+
address: string;
|
|
72
|
+
}
|
|
73
|
+
declare class WalletPickerModal {
|
|
74
|
+
private overlay;
|
|
75
|
+
private onKeydown;
|
|
76
|
+
pick(): Promise<PickResult>;
|
|
77
|
+
private render;
|
|
78
|
+
private close;
|
|
79
|
+
private dismiss;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_CONNECTED' | 'WALLET_REJECTED' | 'WALLET_NETWORK_MISMATCH' | 'CONTRACT_NOT_FOUND' | 'CONTRACT_SPEC_ERROR' | 'CONTRACT_SIMULATION_FAILED' | 'CONTRACT_RESTORE_REQUIRED' | 'INVALID_CONTRACT_ID' | 'INVALID_PARAMS' | 'TX_SUBMISSION_FAILED' | 'TX_TIMEOUT' | 'TX_FAILED' | 'RPC_ERROR' | 'UNKNOWN';
|
|
83
|
+
interface ContractKitError {
|
|
84
|
+
code: ErrorCode;
|
|
85
|
+
message: string;
|
|
86
|
+
cause?: unknown;
|
|
87
|
+
}
|
|
88
|
+
declare class StellarContractError extends Error {
|
|
89
|
+
readonly code: ErrorCode;
|
|
90
|
+
readonly cause?: unknown;
|
|
91
|
+
constructor(code: ErrorCode, message: string, cause?: unknown);
|
|
92
|
+
}
|
|
93
|
+
declare function isContractKitError(err: unknown): err is StellarContractError;
|
|
94
|
+
|
|
95
|
+
export { ConnectResult, type ContractClient, type ContractKitError, type ContractMethodFn, type ErrorCode, NETWORKS, type NetworkConfig, type NetworkPreset, type PickResult, type ReadResult, StellarContractError, StellarContractsKit, type StellarContractsKitOptions, WalletAdapter, WalletPickerModal, type WriteResult, isContractKitError };
|