@xo-cash/utils 0.0.1-development.13987669945
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 +70 -0
- package/dist/index.d.mts +1346 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +840 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 GeneralProtocols / XO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @xo-cash/utils
|
|
2
|
+
|
|
3
|
+
Utility functions for XO
|
|
4
|
+
|
|
5
|
+
- Template parsing, serialization, validation and schema generation
|
|
6
|
+
- Script identifier generation
|
|
7
|
+
- Template identifier generation
|
|
8
|
+
- Extended JSON
|
|
9
|
+
|
|
10
|
+
> ⚠️ This project is in **early development phase**. Use it only if you understand what you are doing and accept the risks. **Do not use funds you are not willing to lose.** Minor version bumps may introduce **breaking changes**
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @xo-cash/utils
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { parseTemplate, scriptToScriptHash, generateTemplateIdentifier } from '@xo-cash/utils';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Scripts
|
|
25
|
+
|
|
26
|
+
| Command | Description |
|
|
27
|
+
| ---------------------------------- | ------------------------------------------------------ |
|
|
28
|
+
| `npm run build` | Compile TypeScript to `dist/` |
|
|
29
|
+
| `npm run generate-schema` | Generate `xo-template.schema.json` from the Zod schema |
|
|
30
|
+
| `npm run test` | Run tests with coverage |
|
|
31
|
+
| `npm run style` | Lint with ESLint (read-only) |
|
|
32
|
+
| `npm run syntax` | Type-check without emitting (`tsc --noEmit`) |
|
|
33
|
+
| `npm run format` | Auto-fix formatting and linting |
|
|
34
|
+
| `npm run docs` | Generate TypeDoc API docs to `public/` |
|
|
35
|
+
| `npm run spellcheck` | Spell-check source and test files |
|
|
36
|
+
| `npm audit --audit-level=moderate` | Performs npm audit |
|
|
37
|
+
|
|
38
|
+
## Templates
|
|
39
|
+
|
|
40
|
+
### Parsing
|
|
41
|
+
|
|
42
|
+
`parseTemplate` accepts any string OR XOTemplate object and returns a validated `XOTemplate` object. It rejects unknown
|
|
43
|
+
properties, missing required fields, and incorrect value types. Native bigint is accepted in satoshi
|
|
44
|
+
fields; string encoding is also accepted for values sourced from JSON where bigint is unavailable.
|
|
45
|
+
|
|
46
|
+
### How validation works
|
|
47
|
+
|
|
48
|
+
Validation uses a Zod schema defined in `source/template/schemas.ts`. The schema mirrors the
|
|
49
|
+
`XOTemplate` TypeScript type and rejects unknown keys at every level. When validation fails, a
|
|
50
|
+
`TemplateInvalidError` is thrown with a message that lists every failing field and the reason it
|
|
51
|
+
failed, so all problems are visible in one pass.
|
|
52
|
+
|
|
53
|
+
### JSON Schema export
|
|
54
|
+
|
|
55
|
+
A JSON Schema representation of the template can be generated by running:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run generate-schema
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This writes `source/template/xo-template.schema.json`, which can be consumed by other tools. However, it's recommended to use functions provided by this library for XO template development thanks to the extended JSON support.
|
|
62
|
+
|
|
63
|
+
## Links
|
|
64
|
+
|
|
65
|
+
- [Repository](https://gitlab.com/GeneralProtocols/xo/utils)
|
|
66
|
+
- [Issues](https://gitlab.com/GeneralProtocols/xo/utils/issues)
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
[MIT](LICENSE)
|