cspr402 0.4.7
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 +173 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +108 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +207 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +400 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/onboard.d.ts +4 -0
- package/dist/commands/onboard.d.ts.map +1 -0
- package/dist/commands/onboard.js +192 -0
- package/dist/commands/onboard.js.map +1 -0
- package/dist/commands/onboard.test.d.ts +2 -0
- package/dist/commands/onboard.test.d.ts.map +1 -0
- package/dist/commands/onboard.test.js +48 -0
- package/dist/commands/onboard.test.js.map +1 -0
- package/dist/commands/purchase.d.ts +2 -0
- package/dist/commands/purchase.d.ts.map +1 -0
- package/dist/commands/purchase.js +206 -0
- package/dist/commands/purchase.js.map +1 -0
- package/dist/commands/wallet.d.ts +2 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +161 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +77 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +329 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +101 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +197 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +337 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mpp.d.ts +57 -0
- package/dist/mpp.d.ts.map +1 -0
- package/dist/mpp.js +165 -0
- package/dist/mpp.js.map +1 -0
- package/dist/ows.d.ts +190 -0
- package/dist/ows.d.ts.map +1 -0
- package/dist/ows.js +565 -0
- package/dist/ows.js.map +1 -0
- package/dist/soroban.d.ts +92 -0
- package/dist/soroban.d.ts.map +1 -0
- package/dist/soroban.js +313 -0
- package/dist/soroban.js.map +1 -0
- package/dist/stellar.d.ts +53 -0
- package/dist/stellar.d.ts.map +1 -0
- package/dist/stellar.js +180 -0
- package/dist/stellar.js.map +1 -0
- package/dist/version-check.d.ts +5 -0
- package/dist/version-check.d.ts.map +1 -0
- package/dist/version-check.js +203 -0
- package/dist/version-check.js.map +1 -0
- package/package.json +80 -0
package/dist/ows.d.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { type Transaction } from '@stellar/stellar-sdk';
|
|
2
|
+
import type { CardDetails, PaymentInstructions } from './client';
|
|
3
|
+
import { buildContractPaymentTx, submitSorobanTx } from './soroban';
|
|
4
|
+
/**
|
|
5
|
+
* Create an OWS wallet, or return the existing one if a wallet with this
|
|
6
|
+
* name already exists in the vault. Idempotent by design — calling it
|
|
7
|
+
* twice with the same name is safe and returns the same keys, so skill.md
|
|
8
|
+
* flows and agent retries don't duplicate state.
|
|
9
|
+
*
|
|
10
|
+
* Wallets are stored encrypted at `~/.ows/wallets/<name>.vault` by
|
|
11
|
+
* default. If the vault file is lost, the funds it controls become
|
|
12
|
+
* unreachable — cards402 never sees private keys and can't recover
|
|
13
|
+
* them. Agents running on ephemeral filesystems (Lambda, Cloud Run,
|
|
14
|
+
* scratch containers) should pass a `vaultPath` pointing at a
|
|
15
|
+
* persistent volume, or set the `OWS_VAULT_PATH` environment variable.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createOWSWallet(name: string, passphrase?: string, vaultPath?: string): {
|
|
18
|
+
walletId: string;
|
|
19
|
+
publicKey: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Import an existing Stellar secret key (S...) into an OWS wallet.
|
|
23
|
+
* Useful for migrating from a raw STELLAR_WALLET_SECRET to OWS custody.
|
|
24
|
+
*/
|
|
25
|
+
export declare function importStellarKey(name: string, stellarSecret: string, passphrase?: string, vaultPath?: string): {
|
|
26
|
+
walletId: string;
|
|
27
|
+
publicKey: string;
|
|
28
|
+
};
|
|
29
|
+
/** Get the Stellar public key (G-address) for a named OWS wallet. */
|
|
30
|
+
export declare function getOWSPublicKey(walletName: string, vaultPath?: string): string;
|
|
31
|
+
/** Check XLM and USDC balances for an OWS wallet. */
|
|
32
|
+
export declare function getOWSBalance(walletName: string, vaultPath?: string, networkPassphrase?: string): Promise<{
|
|
33
|
+
xlm: string;
|
|
34
|
+
usdc: string;
|
|
35
|
+
}>;
|
|
36
|
+
export interface OnboardAgentOpts {
|
|
37
|
+
/** cards402 API key (cards402_…) */
|
|
38
|
+
apiKey: string;
|
|
39
|
+
/** Local name for the wallet in the OWS vault, e.g. 'my-agent' */
|
|
40
|
+
walletName: string;
|
|
41
|
+
/** Override the default https://api.cards402.com/v1 */
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
/** Optional passphrase for extra at-rest encryption */
|
|
44
|
+
passphrase?: string;
|
|
45
|
+
/** Override the default ~/.ows/wallets vault path — use a persistent
|
|
46
|
+
* volume if you're running on ephemeral storage (Lambda, Cloud Run,
|
|
47
|
+
* scratch containers). Lost vault = lost funds. */
|
|
48
|
+
vaultPath?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface OnboardAgentResult {
|
|
51
|
+
publicKey: string;
|
|
52
|
+
balance: {
|
|
53
|
+
xlm: string;
|
|
54
|
+
usdc: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* One-shot agent setup: reports `initializing` to cards402, creates or
|
|
59
|
+
* fetches the OWS wallet, reports `awaiting_funding` with the wallet
|
|
60
|
+
* address, and returns the public key + current balance. Idempotent —
|
|
61
|
+
* safe to call on every agent startup.
|
|
62
|
+
*
|
|
63
|
+
* The backend broadcasts these transitions over the live SSE dashboard
|
|
64
|
+
* feed, so operators see the agent moving through states in real time.
|
|
65
|
+
*/
|
|
66
|
+
export declare function onboardAgent(opts: OnboardAgentOpts): Promise<OnboardAgentResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Check whether a Soroban tx hash has materialized on the Stellar
|
|
69
|
+
* ledger. Returns:
|
|
70
|
+
* - 'landed' — Horizon returned a successful tx record
|
|
71
|
+
* - 'dropped' — Horizon 404s and the caller has already exhausted
|
|
72
|
+
* the inclusion window client-side, so the tx is
|
|
73
|
+
* almost certainly gone
|
|
74
|
+
* - 'pending' — Horizon is down or the tx is still in the
|
|
75
|
+
* mempool; caller should wait rather than resubmit
|
|
76
|
+
*
|
|
77
|
+
* Used by purchaseCardOWS's resume branch to decide whether a
|
|
78
|
+
* dropped-pre-apply Soroban tx should be re-submitted or whether we
|
|
79
|
+
* should wait for a still-in-flight one to finalize.
|
|
80
|
+
*/
|
|
81
|
+
export declare function checkSorobanTxLanded(txHash: string, opts?: {
|
|
82
|
+
networkPassphrase?: string;
|
|
83
|
+
}): Promise<'landed' | 'dropped' | 'pending'>;
|
|
84
|
+
export interface TrustlineOpts {
|
|
85
|
+
walletName: string;
|
|
86
|
+
passphrase?: string;
|
|
87
|
+
vaultPath?: string;
|
|
88
|
+
networkPassphrase?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Add a USDC trustline to the OWS wallet's Stellar account.
|
|
92
|
+
*
|
|
93
|
+
* Idempotent: if the trustline already exists, returns `null` without
|
|
94
|
+
* submitting a tx (Stellar accepts redundant `changeTrust` ops and
|
|
95
|
+
* silently no-ops them, but charges the base fee each time — so
|
|
96
|
+
* pre-checking saves ~0.00001 XLM per accidental re-run). Returns the
|
|
97
|
+
* new tx hash when a trustline is actually opened.
|
|
98
|
+
*/
|
|
99
|
+
export declare function addUsdcTrustlineOWS(opts: TrustlineOpts): Promise<string | null>;
|
|
100
|
+
export interface PayViaContractOwsOpts {
|
|
101
|
+
walletName: string;
|
|
102
|
+
payment: PaymentInstructions;
|
|
103
|
+
paymentAsset?: 'usdc' | 'xlm';
|
|
104
|
+
passphrase?: string;
|
|
105
|
+
vaultPath?: string;
|
|
106
|
+
networkPassphrase?: string;
|
|
107
|
+
sorobanRpcUrl?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Pay the cards402 receiver contract using an OWS-custody wallet. Builds a
|
|
111
|
+
* Soroban `pay_usdc` or `pay_xlm` invocation, signs the transaction hash via
|
|
112
|
+
* OWS, and submits it to the Soroban RPC. Returns the transaction hash.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Injectable dependency bundle for payViaContractOWS. Production
|
|
116
|
+
* callers omit this entirely — the defaults point at the real
|
|
117
|
+
* build / submit / sign / pubkey helpers. Tests inject stubs to
|
|
118
|
+
* exercise the retry state machine without touching real Soroban
|
|
119
|
+
* or a real wallet vault.
|
|
120
|
+
*/
|
|
121
|
+
export interface PayViaContractOwsDeps {
|
|
122
|
+
buildContractPaymentTx?: typeof buildContractPaymentTx;
|
|
123
|
+
submitSorobanTx?: typeof submitSorobanTx;
|
|
124
|
+
owsSignTx?: (tx: Transaction, walletName: string, publicKey: string, passphrase?: string, vaultPath?: string) => void;
|
|
125
|
+
getOWSPublicKey?: (walletName: string, vaultPath?: string) => string;
|
|
126
|
+
}
|
|
127
|
+
export declare function payViaContractOWS(opts: PayViaContractOwsOpts, deps?: PayViaContractOwsDeps): Promise<string>;
|
|
128
|
+
/** @deprecated Use `payViaContractOWS` — the old direct-Stellar path no longer matches the backend. */
|
|
129
|
+
export declare const payVCCOWS: typeof payViaContractOWS;
|
|
130
|
+
/** @deprecated Kept for one migration cycle. */
|
|
131
|
+
export type PayVCCOwsOpts = PayViaContractOwsOpts;
|
|
132
|
+
export interface PurchaseCardOwsOpts {
|
|
133
|
+
apiKey: string;
|
|
134
|
+
walletName: string;
|
|
135
|
+
amountUsdc: string;
|
|
136
|
+
paymentAsset?: 'usdc' | 'xlm';
|
|
137
|
+
passphrase?: string;
|
|
138
|
+
vaultPath?: string;
|
|
139
|
+
baseUrl?: string;
|
|
140
|
+
networkPassphrase?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Resume an existing order instead of creating a new one. Three shapes:
|
|
143
|
+
*
|
|
144
|
+
* - bare string — wait for the backend to finish an
|
|
145
|
+
* in-flight payment. Conservative
|
|
146
|
+
* default when we have no context.
|
|
147
|
+
*
|
|
148
|
+
* - { orderId, payment } — caller has rebuilt the payment
|
|
149
|
+
* instructions (e.g. from a cached
|
|
150
|
+
* order response) and wants to
|
|
151
|
+
* resubmit.
|
|
152
|
+
*
|
|
153
|
+
* - { orderId, txHash, — caller has the txHash from a prior
|
|
154
|
+
* phase } ResumableError. purchaseCardOWS
|
|
155
|
+
* checks whether that tx landed on
|
|
156
|
+
* the ledger and, if not, re-fetches
|
|
157
|
+
* the order's payment instructions
|
|
158
|
+
* from the backend and resubmits.
|
|
159
|
+
* This is the shape saved to
|
|
160
|
+
* ~/.cards402/last-order so the CLI
|
|
161
|
+
* --resume flow recovers cleanly
|
|
162
|
+
* from a dropped Soroban submit.
|
|
163
|
+
*/
|
|
164
|
+
resume?: string | {
|
|
165
|
+
orderId: string;
|
|
166
|
+
payment?: PaymentInstructions;
|
|
167
|
+
txHash?: string;
|
|
168
|
+
phase?: 'unpaid' | 'paid';
|
|
169
|
+
};
|
|
170
|
+
/** Tune the card-ready poll. Default: { timeoutMs: 300_000, intervalMs: 3_000 }. */
|
|
171
|
+
waitForCardOpts?: {
|
|
172
|
+
timeoutMs?: number;
|
|
173
|
+
intervalMs?: number;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Full purchase flow using an OWS wallet: create order → pay the receiver
|
|
178
|
+
* contract on Stellar → wait for card. Any failure after the order exists
|
|
179
|
+
* is wrapped as a ResumableError so the caller can retry via `--resume`
|
|
180
|
+
* without minting a new order.
|
|
181
|
+
*
|
|
182
|
+
* Soroban RPC backpressure is tolerated: if submitSorobanTx throws with a
|
|
183
|
+
* txHash attached (deadline reached but tx may still land), we proceed to
|
|
184
|
+
* waitForCard — the cards402 backend watcher is the source of truth and
|
|
185
|
+
* will credit the order when the tx finalizes.
|
|
186
|
+
*/
|
|
187
|
+
export declare function purchaseCardOWS(opts: PurchaseCardOwsOpts): Promise<CardDetails & {
|
|
188
|
+
order_id: string;
|
|
189
|
+
}>;
|
|
190
|
+
//# sourceMappingURL=ows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ows.d.ts","sourceRoot":"","sources":["../src/ows.ts"],"names":[],"mappings":"AAmBA,OAAO,EAUL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAA8B,MAAM,UAAU,CAAC;AAE7F,OAAO,EACL,sBAAsB,EACtB,eAAe,EAKhB,MAAM,WAAW,CAAC;AA+BnB;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAWzC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAazC;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAG9E;AAED,qDAAqD;AACrD,wBAAsB,aAAa,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IA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