stellar-check 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 +227 -0
- package/README.md +167 -0
- package/dist/amounts.d.ts +5 -0
- package/dist/amounts.js +18 -0
- package/dist/assess.d.ts +2 -0
- package/dist/assess.js +205 -0
- package/dist/check.d.ts +3 -0
- package/dist/check.js +88 -0
- package/dist/horizon.d.ts +17 -0
- package/dist/horizon.js +196 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/input.d.ts +10 -0
- package/dist/input.js +102 -0
- package/dist/state.d.ts +20 -0
- package/dist/state.js +88 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +1 -0
- package/dist/xdr.d.ts +19 -0
- package/dist/xdr.js +72 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2015 Stellar Development Foundation
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
204
|
+
----
|
|
205
|
+
|
|
206
|
+
Included code for base58 encoding is licensed under the MIT license:
|
|
207
|
+
|
|
208
|
+
Copyright (c) 2011 Google Inc
|
|
209
|
+
Copyright (c) 2013 BitPay Inc
|
|
210
|
+
|
|
211
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
212
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
213
|
+
in the Software without restriction, including without limitation the rights
|
|
214
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
215
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
216
|
+
furnished to do so, subject to the following conditions:
|
|
217
|
+
|
|
218
|
+
The above copyright notice and this permission notice shall be included in
|
|
219
|
+
all copies or substantial portions of the Software.
|
|
220
|
+
|
|
221
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
222
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
223
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
224
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
225
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
226
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
227
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Stellar Check
|
|
2
|
+
|
|
3
|
+
Stellar Check is a read-only TypeScript library for checking a Stellar payment before signing. It reports available balances, reserve requirements, liabilities, trustline authorization, receiving capacity and declared memo requirements.
|
|
4
|
+
|
|
5
|
+
Pre-grant development version: **0.1.0**. UI and branding iterations remain part of v0.1 until the final product milestone. The proposal documents are historical planning inputs; see [implementation status](https://github.com/GautamBytes/stellar-check/blob/main/docs/implementation-status.md) for what has actually been verified.
|
|
6
|
+
|
|
7
|
+
The repository includes the library, tests, website and documentation. Historical proposal documents describe the original plan; the implementation status records what was built. CI runs the full check and package validation on pull requests.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install stellar-check
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node **22.12 or later**, or a modern browser bundler. [Try the Playground](https://stellar-check-gamma.vercel.app/playground.html) or read the [integration guide](https://stellar-check-gamma.vercel.app/docs.html#integration).
|
|
16
|
+
|
|
17
|
+
## Run locally
|
|
18
|
+
|
|
19
|
+
Requires Node **22.12 or later** and npm. Dependencies are pinned.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm ci
|
|
23
|
+
npm run check
|
|
24
|
+
npm run example # four controlled, offline scenarios
|
|
25
|
+
npm run demo # http://127.0.0.1:5173
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The website includes a “Why Stellar Check?” section and a dedicated reading guide at `/docs.html`, covering purpose, problems, a worked example, integration, evidence, ecosystem value and scope.
|
|
29
|
+
|
|
30
|
+
The website offers coordinated light and dark themes. Use the header toggle to save your preference; the first visit follows your system setting.
|
|
31
|
+
|
|
32
|
+
The homepage keeps a small interactive preview. The full checker lives at `/playground.html` and starts in **controlled fixture mode**. Select **Live Horizon data** and enter real public accounts for the chosen network to run fresh reads. The library and page never request secret keys, sign transactions, create accounts or submit payments. Live requests disclose queried public addresses to the configured provider. The page clears a report when the input changes and ignores responses for superseded inputs.
|
|
33
|
+
|
|
34
|
+
## Integrate
|
|
35
|
+
|
|
36
|
+
Import the installed package in your application. If you use the Stellar SDK directly, install it as a direct dependency too: `npm install @stellar/stellar-sdk`.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Networks } from '@stellar/stellar-sdk';
|
|
40
|
+
import { checkPayment, HorizonProvider } from 'stellar-check';
|
|
41
|
+
|
|
42
|
+
const provider = new HorizonProvider('https://horizon-testnet.stellar.org');
|
|
43
|
+
const report = await checkPayment(
|
|
44
|
+
{
|
|
45
|
+
networkPassphrase: Networks.TESTNET,
|
|
46
|
+
source: senderPublicAddress,
|
|
47
|
+
destination: recipientPublicAddress,
|
|
48
|
+
asset: { type: 'native' },
|
|
49
|
+
amount: '2.5000000',
|
|
50
|
+
feeBudget: '0.0000100',
|
|
51
|
+
// memo: { type: 'id', value: '12345' },
|
|
52
|
+
},
|
|
53
|
+
provider,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (report.status === 'no_known_issues') {
|
|
57
|
+
// No supported issue found in observed state. Refresh before confirmation.
|
|
58
|
+
} else {
|
|
59
|
+
for (const issue of report.issues) {
|
|
60
|
+
console.log(issue.code, issue.party, issue.message, issue.action);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For an issued asset, use `{ type: 'credit', code: 'USDC', issuer: issuerPublicAddress }`. Matching a code alone never identifies a trustline. `feeBudget` is the **total fee in XLM**, not stroops, and must be a positive decimal string within the transaction fee range. It is checked against the current one-operation base fee; surge pricing and inclusion are not predicted.
|
|
66
|
+
|
|
67
|
+
Memo types: `text` (up to 28 UTF-8 bytes), `id` (uint64 decimal string), `hash` and `return` (64 hexadecimal characters). Omit `memo` for no memo. The SDK considers even an empty text memo to be present; applications must obtain the receiving service’s actual memo and verify its intended meaning themselves.
|
|
68
|
+
|
|
69
|
+
The package exports ESM and TypeScript declarations, and works in Node and browser bundlers. No application database or server is required. The demo uses Vite; the library does not depend on Vite.
|
|
70
|
+
|
|
71
|
+
## Import an unsigned transaction
|
|
72
|
+
|
|
73
|
+
The Playground's **Import XDR** panel decodes locally, previews exact payment values and only loads them into the checker after an explicit click. Loading selects Live Horizon and clears the previous report. It does not make account requests; click **Check payment** to fetch current public state. The example XDR uses controlled sample addresses, not maintained live accounts.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { importPaymentXdr, checkPayment, HorizonProvider } from 'stellar-check';
|
|
77
|
+
import { Networks } from '@stellar/stellar-sdk';
|
|
78
|
+
|
|
79
|
+
const decoded = importPaymentXdr(unsignedEnvelopeBase64, Networks.TESTNET);
|
|
80
|
+
if (!decoded.ok) {
|
|
81
|
+
console.error(decoded.code, decoded.message);
|
|
82
|
+
} else {
|
|
83
|
+
console.log(decoded.payment, decoded.context);
|
|
84
|
+
// Run after reviewing the decoded payment and selected network:
|
|
85
|
+
const report = await checkPayment(
|
|
86
|
+
decoded.payment,
|
|
87
|
+
new HorizonProvider('https://horizon-testnet.stellar.org'),
|
|
88
|
+
);
|
|
89
|
+
console.log(report.status);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The importer accepts canonical base64 with optional whitespace, up to 32,768 input characters. Supported envelopes are unsigned V1 transactions containing one classic payment between distinct G accounts. The transaction source and any explicit operation source must match. Fee stroops become exact XLM decimal strings. Text memos must be lossless UTF-8; ID and hash memos preserve their exact values.
|
|
94
|
+
|
|
95
|
+
Signed envelopes, fee bumps, legacy V0 envelopes, transaction extensions, extended V2 preconditions, multiple/non-payment operations and unsupported payment shapes are rejected. Ordinary time bounds and sequence numbers appear in import context but are **not assessed**. The selected network is supplied by the caller because XDR does not identify its network. An imported payment report is not transaction validation. Editing the form does not modify or rebuild the original XDR.
|
|
96
|
+
|
|
97
|
+
Issue cards offer relevant field shortcuts such as **Review amount**, **Edit fee budget** and **Edit memo**, plus copyable asset details for trustline and authorization issues. These controls do not change balances, create trustlines or assume the receiving service's memo.
|
|
98
|
+
|
|
99
|
+
## Report contract
|
|
100
|
+
|
|
101
|
+
| Status | Meaning |
|
|
102
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `no_known_issues` | All applicable supported checks completed without a diagnosed issue. |
|
|
104
|
+
| `issues_found` | Supported checks found one or more problems; dependent checks for a confirmed missing account are marked not applicable. |
|
|
105
|
+
| `incomplete` | Invalid/unsupported input, unavailable observations, malformed data or wrong network prevented assessment. Known issues are retained. |
|
|
106
|
+
|
|
107
|
+
`incomplete` takes precedence over known issues. Always inspect `status`, not just whether `issues` is empty. Coverage entries distinguish `complete`, `unresolved` and `not_applicable`; a completed check may have found an issue. Each diagnostic contains a stable `code`, affected `party`, explanation and recommended `action`.
|
|
108
|
+
|
|
109
|
+
Facts are decimal strings with seven fractional digits and are absent when their dependencies are unavailable. `availableXlm` is the maximum nonnegative amount after reserve, native selling liabilities and fee. `requiredXlm` includes reserve, selling liabilities, fee and, for native payments, the amount. `xlmShortfall` includes any deficit below reserve plus fee, even for issued-asset payments. Recipient native capacity is checked against the signed int64 balance bound; issued capacity uses the trustline limit and buying liabilities.
|
|
110
|
+
|
|
111
|
+
Observation metadata contains provider URL, expected network, per-read timestamps, available `x-last-ledger` observations, and account `last_modified_ledger` values. The account modification ledger is **not** its read ledger. Root/ledger metadata, sender, recipient and SDK memo reads are separate observations. `atomic` is always `false`.
|
|
112
|
+
|
|
113
|
+
## Scope and limits
|
|
114
|
+
|
|
115
|
+
Supported: one classic Payment operation, distinct G-address source and destination, native XLM or one issued asset, one transaction/operation source and fee payer. Optional `operationType: 'payment'`, `operationSource` and `feePayer` are accepted only when consistent with that shape. Unknown intent fields are rejected so unsupported transaction features cannot silently disappear.
|
|
116
|
+
|
|
117
|
+
Unsupported: M-addresses, federation, self-payments, issuer-as-party payments, Soroban/SAC, path payments, swaps, batches, multiple operations, fee bumps and separate sources/fee payers. Address checks use the SDK’s StrKey checksum validation. The checker accepts a payment intent. The separate `importPaymentXdr` helper extracts supported payment values from an unsigned envelope.
|
|
118
|
+
|
|
119
|
+
Amounts use bigint internally and decimal strings externally. Zero/negative payments, excess precision, exponents and out-of-range amounts are invalid. Current reserve and base-fee values come from Horizon’s latest ledger; no reserve constant is substituted. Inconsistent relevant balances, missing liabilities, missing sponsorship counters and missing authorization never become invented defaults.
|
|
120
|
+
|
|
121
|
+
The official SDK `checkMemoRequired` performs SEP-29 detection. A supplied memo means **presence only**; no identity check or memo-declaration inference is made. The adapter overrides the SDK’s account loader with the same bounded read transport and maps Horizon’s REST `data` field to the SDK’s `data_attr`. It builds an unsigned, non-submittable inspection container; its dummy sequence/fee are not readiness facts.
|
|
122
|
+
|
|
123
|
+
State can change immediately after checking. Refresh after edits and immediately before confirmation. Signature validity, sequence handling, transaction timing/preconditions, submission, finality and surge-fee inclusion are outside the report. No production audit or adoption claim is implied.
|
|
124
|
+
|
|
125
|
+
## Provider and offline usage
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const provider = new HorizonProvider(url, { timeoutMs: 10_000 });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Each HTTP request, including its response body, has a bounded timeout and uses no-store fetching. No automatic retries occur. Account 404 responses are distinct from transport failures; 429s have a dedicated diagnostic. HTTPS is required by default; `allowHttp: true` explicitly enables local development providers. Provider URLs must not contain credentials, query parameters or fragments.
|
|
132
|
+
|
|
133
|
+
`PaymentProvider` can be implemented with another public-data adapter; its methods return timestamped `Read<T>` envelopes. Custom implementations are responsible for bounded I/O and faithful network/ledger metadata. The orchestrator preserves rejected or malformed observations as incomplete reports. The payment input is copied before asynchronous reads so caller mutations cannot change the assessed intent midway.
|
|
134
|
+
|
|
135
|
+
For controlled observations, use `assessPayment(intent, snapshot)` directly. This pure function validates relevant account fields and calculates a report without I/O. Offline snapshots must conform to the exported `Snapshot` type. See [the four fixtures](https://github.com/GautamBytes/stellar-check/blob/main/examples/scenarios.ts) and [fixture coverage](https://github.com/GautamBytes/stellar-check/blob/main/docs/fixtures.md).
|
|
136
|
+
|
|
137
|
+
## Node and testnet examples
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
# Read a JSON payment intent using current public state:
|
|
141
|
+
HORIZON_URL=https://horizon-testnet.stellar.org npm run example -- /absolute/path/payment.json
|
|
142
|
+
|
|
143
|
+
# Recheck four scenarios using the included public-account manifest:
|
|
144
|
+
npm run testnet
|
|
145
|
+
# Or supply public accounts you maintain:
|
|
146
|
+
npm run testnet -- /absolute/path/testnet-accounts.json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
See [testnet verification](https://github.com/GautamBytes/stellar-check/blob/main/docs/testnet.md) for the manifest requirements and report artifact. The included public accounts can change or disappear at a testnet reset; they are not project-owned fixtures.
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
npm run typecheck
|
|
155
|
+
npm test
|
|
156
|
+
npm run build
|
|
157
|
+
npm run demo:build
|
|
158
|
+
npm pack --dry-run
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`npm run check` runs typechecking, the test suite, the library build and demo production build. Tests run without public network access and use real calculation code and the SDK memo helper with controlled HTTP responses. [Diagnostic meanings](https://github.com/GautamBytes/stellar-check/blob/main/docs/diagnostics.md) and [implementation status](https://github.com/GautamBytes/stellar-check/blob/main/docs/implementation-status.md) describe the current contract and verification.
|
|
162
|
+
|
|
163
|
+
## References and license
|
|
164
|
+
|
|
165
|
+
The implementation follows Stellar’s [sponsored reserve accounting](https://developers.stellar.org/docs/build/guides/transactions/sponsored-reserves), [payment operation reference](https://developers.stellar.org/docs/learn/fundamentals/transactions/list-of-operations) and [SEP-29](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md). Memo behavior is verified against the pinned `@stellar/stellar-sdk` dependency, version 17.0.1.
|
|
166
|
+
|
|
167
|
+
Apache-2.0; see [LICENSE](https://github.com/GautamBytes/stellar-check/blob/main/LICENSE). The official Stellar SDK is an Apache-2.0 dependency. No source from the other proposal-referenced wallet projects was copied. Repository owner: GautamBytes. Any upstream contribution and longer-term maintenance commitments remain to be agreed.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const SCALE = 10000000n;
|
|
2
|
+
export declare const MAX_AMOUNT = 9223372036854775807n;
|
|
3
|
+
export declare function parseAmount(value: unknown, max?: bigint): bigint;
|
|
4
|
+
export declare function formatAmount(units: bigint): string;
|
|
5
|
+
export declare const positivePart: (units: bigint) => bigint;
|
package/dist/amounts.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const SCALE = 10000000n;
|
|
2
|
+
export const MAX_AMOUNT = 9223372036854775807n;
|
|
3
|
+
export function parseAmount(value, max = MAX_AMOUNT) {
|
|
4
|
+
if (typeof value !== 'string' || value.length > 32 || !/^\d+(\.\d{1,7})?$/.test(value)) {
|
|
5
|
+
throw new Error('Use a decimal string with at most seven decimal places.');
|
|
6
|
+
}
|
|
7
|
+
const [whole = '', fraction = ''] = value.split('.');
|
|
8
|
+
const units = BigInt(whole) * SCALE + BigInt(fraction.padEnd(7, '0'));
|
|
9
|
+
if (units > max)
|
|
10
|
+
throw new Error('Amount exceeds the protocol range.');
|
|
11
|
+
return units;
|
|
12
|
+
}
|
|
13
|
+
export function formatAmount(units) {
|
|
14
|
+
const sign = units < 0n ? '-' : '';
|
|
15
|
+
const positive = units < 0n ? -units : units;
|
|
16
|
+
return `${sign}${positive / SCALE}.${(positive % SCALE).toString().padStart(7, '0')}`;
|
|
17
|
+
}
|
|
18
|
+
export const positivePart = (units) => (units > 0n ? units : 0n);
|
package/dist/assess.d.ts
ADDED
package/dist/assess.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { formatAmount, MAX_AMOUNT, parseAmount, positivePart } from './amounts.js';
|
|
2
|
+
import { isRecord, validateIntent } from './input.js';
|
|
3
|
+
import { parseAccount, validateNetwork } from './state.js';
|
|
4
|
+
const CHECKS = [
|
|
5
|
+
'input',
|
|
6
|
+
'network',
|
|
7
|
+
'source_account',
|
|
8
|
+
'destination_account',
|
|
9
|
+
'source_xlm',
|
|
10
|
+
'source_asset',
|
|
11
|
+
'destination_capacity',
|
|
12
|
+
'memo',
|
|
13
|
+
];
|
|
14
|
+
export function assessPayment(input, snapshot) {
|
|
15
|
+
const validated = validateIntent(input);
|
|
16
|
+
const report = {
|
|
17
|
+
status: 'incomplete',
|
|
18
|
+
issues: [...validated.issues],
|
|
19
|
+
facts: {},
|
|
20
|
+
coverage: CHECKS.map((check) => ({
|
|
21
|
+
check,
|
|
22
|
+
status: 'unresolved',
|
|
23
|
+
reason: 'Required input or observation is unavailable.',
|
|
24
|
+
})),
|
|
25
|
+
observation: {
|
|
26
|
+
networkPassphrase: 'payment' in validated ? validated.payment.networkPassphrase : null,
|
|
27
|
+
reads: [],
|
|
28
|
+
atomic: false,
|
|
29
|
+
},
|
|
30
|
+
limitations: [
|
|
31
|
+
'Separate reads are not an atomic snapshot. Refresh before confirmation and whenever the payment changes.',
|
|
32
|
+
'No supported issue found in observed data does not guarantee transaction success.',
|
|
33
|
+
'Signatures, sequence numbers, submission, finality and surge-fee inclusion are not assessed.',
|
|
34
|
+
'Memo checks establish a declared requirement or memo presence, never the intended customer’s identity.',
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
function mark(check, status, reason) {
|
|
38
|
+
report.coverage[CHECKS.indexOf(check)] =
|
|
39
|
+
reason === undefined ? { check, status } : { check, status, reason };
|
|
40
|
+
}
|
|
41
|
+
function issue(code, party, message, action) {
|
|
42
|
+
report.issues.push({ code, party, message, action });
|
|
43
|
+
}
|
|
44
|
+
function read(key, check, observation) {
|
|
45
|
+
if (!isRecord(observation) ||
|
|
46
|
+
typeof observation.ok !== 'boolean' ||
|
|
47
|
+
typeof observation.observedAt !== 'string') {
|
|
48
|
+
issue('MALFORMED_DATA', 'provider', 'The provider returned a malformed observation.', 'Return complete observation envelopes from the provider.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
report.observation.reads.push({
|
|
52
|
+
check: key,
|
|
53
|
+
observedAt: observation.observedAt,
|
|
54
|
+
...(observation.ok && observation.ledger !== undefined ? { ledger: observation.ledger } : {}),
|
|
55
|
+
});
|
|
56
|
+
if (!observation.ok) {
|
|
57
|
+
issue(observation.code, 'provider', observation.message, 'Refresh public account data or choose an available provider, then check again.');
|
|
58
|
+
mark(check, 'unresolved', observation.code);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!Number.isFinite(Date.parse(observation.observedAt)) ||
|
|
62
|
+
(observation.ledger !== undefined &&
|
|
63
|
+
(!Number.isSafeInteger(observation.ledger) || observation.ledger <= 0))) {
|
|
64
|
+
issue('MALFORMED_DATA', 'provider', 'Observation metadata is invalid.', 'Use a provider with complete observation metadata.');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
return { value: observation.value };
|
|
68
|
+
}
|
|
69
|
+
if (!('payment' in validated))
|
|
70
|
+
return report;
|
|
71
|
+
mark('input', 'complete');
|
|
72
|
+
const p = validated.payment;
|
|
73
|
+
const network = read('network', 'network', snapshot.network);
|
|
74
|
+
if (!network)
|
|
75
|
+
return report;
|
|
76
|
+
let reserve, baseFee;
|
|
77
|
+
try {
|
|
78
|
+
({ reserve, fee: baseFee } = validateNetwork(network.value));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
issue('MALFORMED_DATA', 'provider', String(error), 'Use complete, consistent network metadata.');
|
|
82
|
+
return report;
|
|
83
|
+
}
|
|
84
|
+
if (network.value.networkPassphrase !== p.networkPassphrase) {
|
|
85
|
+
issue('NETWORK_MISMATCH', 'application', 'The provider reports a different network passphrase.', 'Select a Horizon provider for the chosen network.');
|
|
86
|
+
return report;
|
|
87
|
+
}
|
|
88
|
+
mark('network', 'complete');
|
|
89
|
+
const amount = parseAmount(p.amount), fee = parseAmount(p.feeBudget);
|
|
90
|
+
report.facts.baseReserve = formatAmount(reserve);
|
|
91
|
+
report.facts.baseFee = formatAmount(baseFee);
|
|
92
|
+
report.facts.feeBudget = formatAmount(fee);
|
|
93
|
+
if (fee < baseFee)
|
|
94
|
+
issue('FEE_BUDGET_TOO_LOW', 'sender', 'The total fee budget is below the current one-operation base fee.', 'Increase the planned fee budget and check again; inclusion under surge pricing is not guaranteed.');
|
|
95
|
+
function account(key) {
|
|
96
|
+
const observation = read(key, `${key}_account`, snapshot[key]);
|
|
97
|
+
if (!observation)
|
|
98
|
+
return;
|
|
99
|
+
if (observation.value === null) {
|
|
100
|
+
mark(`${key}_account`, 'complete');
|
|
101
|
+
issue(key === 'source' ? 'SOURCE_ACCOUNT_MISSING' : 'DESTINATION_ACCOUNT_MISSING', key === 'source' ? 'sender' : 'recipient', `The ${key === 'source' ? 'sender' : 'recipient'} account does not exist on this network.`, 'Activate the account through your normal onboarding flow, then check again.');
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const result = parseAccount(observation.value, p[key], p.asset);
|
|
106
|
+
const observed = snapshot[key];
|
|
107
|
+
if (observed.ok &&
|
|
108
|
+
observed.ledger !== undefined &&
|
|
109
|
+
result.lastModifiedLedger > observed.ledger)
|
|
110
|
+
throw new Error('Account modification ledger exceeds the observation ledger.');
|
|
111
|
+
mark(`${key}_account`, 'complete');
|
|
112
|
+
if (key === 'source')
|
|
113
|
+
report.observation.sourceLastModifiedLedger = result.lastModifiedLedger;
|
|
114
|
+
else
|
|
115
|
+
report.observation.destinationLastModifiedLedger = result.lastModifiedLedger;
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
issue('MALFORMED_DATA', 'provider', `${key}: ${String(error)}`, 'Fetch complete, consistent account fields from Horizon.');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const sender = account('source'), recipient = account('destination');
|
|
124
|
+
if (sender) {
|
|
125
|
+
const requiredReserve = sender.reserveUnits * reserve;
|
|
126
|
+
const required = requiredReserve + sender.native.selling + fee + (p.asset.type === 'native' ? amount : 0n);
|
|
127
|
+
report.facts.sourceReserve = formatAmount(requiredReserve);
|
|
128
|
+
report.facts.sourceXlmBalance = formatAmount(sender.native.balance);
|
|
129
|
+
report.facts.nativeSellingLiabilities = formatAmount(sender.native.selling);
|
|
130
|
+
report.facts.availableXlm = formatAmount(positivePart(sender.native.balance - requiredReserve - sender.native.selling - fee));
|
|
131
|
+
report.facts.requiredXlm = formatAmount(required);
|
|
132
|
+
report.facts.xlmShortfall = formatAmount(positivePart(required - sender.native.balance));
|
|
133
|
+
if (required > sender.native.balance)
|
|
134
|
+
issue('INSUFFICIENT_XLM', 'sender', 'The sender lacks XLM for the payment, required reserves, selling liabilities and planned fee.', 'Reduce the XLM payment, add XLM, or review reserve entries and open offers, then check again.');
|
|
135
|
+
mark('source_xlm', 'complete');
|
|
136
|
+
}
|
|
137
|
+
else if (sender === null)
|
|
138
|
+
mark('source_xlm', 'not_applicable', 'Sender account is missing.');
|
|
139
|
+
if (p.asset.type === 'native') {
|
|
140
|
+
mark('source_asset', 'not_applicable', 'Native funds are covered by source_xlm.');
|
|
141
|
+
if (recipient) {
|
|
142
|
+
const capacity = MAX_AMOUNT - recipient.native.balance - recipient.native.buying;
|
|
143
|
+
report.facts.receivingCapacity = formatAmount(capacity);
|
|
144
|
+
if (amount > capacity)
|
|
145
|
+
issue('DESTINATION_CAPACITY_EXCEEDED', 'recipient', 'This payment exceeds the recipient’s native balance range after buying liabilities.', 'Reduce the amount or ask the recipient to free receiving capacity.');
|
|
146
|
+
mark('destination_capacity', 'complete');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
for (const [state, key, check, party] of [
|
|
151
|
+
[sender, 'SOURCE', 'source_asset', 'sender'],
|
|
152
|
+
[recipient, 'DESTINATION', 'destination_capacity', 'recipient'],
|
|
153
|
+
]) {
|
|
154
|
+
if (state === undefined)
|
|
155
|
+
continue;
|
|
156
|
+
if (state === null) {
|
|
157
|
+
mark(check, 'not_applicable', `${party} account is missing.`);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
mark(check, 'complete');
|
|
161
|
+
if (!state.asset) {
|
|
162
|
+
issue(`${key}_TRUSTLINE_MISSING`, party, `The ${party} has no trustline for this exact asset code and issuer.`, `The ${party} needs to create a trustline for ${p.asset.code} issued by ${p.asset.issuer}.`);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (!state.asset.authorized)
|
|
166
|
+
issue(`${key}_NOT_AUTHORIZED`, 'issuer', `The ${party} trustline is not authorized for payments. Authorization to maintain liabilities is insufficient.`, 'Ask the asset issuer to authorize this trustline for transfers.');
|
|
167
|
+
if (key === 'SOURCE') {
|
|
168
|
+
const available = positivePart(state.asset.balance - state.asset.selling);
|
|
169
|
+
report.facts.availableAsset = formatAmount(available);
|
|
170
|
+
report.facts.assetShortfall = formatAmount(positivePart(amount - available));
|
|
171
|
+
if (amount > available)
|
|
172
|
+
issue('INSUFFICIENT_ASSET', party, 'The amount exceeds asset funds available after selling liabilities.', 'Reduce the amount, add this exact asset, or review open sell offers.');
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const capacity = state.asset.limit - state.asset.balance - state.asset.buying;
|
|
176
|
+
report.facts.receivingCapacity = formatAmount(capacity);
|
|
177
|
+
report.facts.capacityShortfall = formatAmount(positivePart(amount - capacity));
|
|
178
|
+
if (amount > capacity)
|
|
179
|
+
issue('DESTINATION_CAPACITY_EXCEEDED', party, 'The recipient has insufficient trustline capacity after balance and buying liabilities.', 'Ask the recipient to increase their trustline limit, reduce holdings or review buy offers.');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (recipient === null)
|
|
184
|
+
mark('destination_capacity', 'not_applicable', 'Recipient account is missing.');
|
|
185
|
+
const memo = read('memo', 'memo', snapshot.memo);
|
|
186
|
+
if (memo) {
|
|
187
|
+
if (!memo.value ||
|
|
188
|
+
!['required', 'present', 'not_required'].includes(memo.value.result) ||
|
|
189
|
+
(memo.value.result === 'present') !== (p.memo !== undefined)) {
|
|
190
|
+
issue('MALFORMED_DATA', 'provider', 'Memo observation is missing or inconsistent with the payment.', 'Repeat the SDK memo check for this exact payment.');
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
mark('memo', 'complete');
|
|
194
|
+
report.facts.memo = memo.value.result === 'present' ? 'presence_only' : memo.value.result;
|
|
195
|
+
if (memo.value.result === 'required')
|
|
196
|
+
issue('MEMO_REQUIRED', 'sender', 'The destination declares that a memo is required.', 'Obtain the correct memo from the receiving service and include it.');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
report.status = report.coverage.some((c) => c.status === 'unresolved')
|
|
200
|
+
? 'incomplete'
|
|
201
|
+
: report.issues.length > 0
|
|
202
|
+
? 'issues_found'
|
|
203
|
+
: 'no_known_issues';
|
|
204
|
+
return report;
|
|
205
|
+
}
|
package/dist/check.d.ts
ADDED