txo_parser 0.0.2 → 0.0.3
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 +13 -17
- package/README.md +3 -1
- package/demo/blocktrail.jsonld +10 -0
- package/demo/index.html +62 -0
- package/demo/ledger-history.jsonld +9 -0
- package/demo/lib/bitcoin.js +378 -0
- package/demo/panes/blocktrails-pane.js +673 -0
- package/demo/panes/builder-pane.js +190 -0
- package/demo/panes/faucet-pane.js +137 -0
- package/demo/panes/ledger-pane.js +662 -0
- package/demo/panes/parser-pane.js +171 -0
- package/demo/panes/spec-pane.js +117 -0
- package/demo/panes/voucher-pane.js +693 -0
- package/demo/voucher-data.jsonld +31 -0
- package/demo/webledger.jsonld +9 -0
- package/index.js +29 -8
- package/package.json +2 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": {
|
|
3
|
+
"schema": "https://schema.org/",
|
|
4
|
+
"bt": "https://blocktrails.org/ns/"
|
|
5
|
+
},
|
|
6
|
+
"@id": "#this",
|
|
7
|
+
"@type": "VoucherPool",
|
|
8
|
+
"schema:name": "Voucher Pool",
|
|
9
|
+
"schema:description": "Testnet4 voucher management and faucet",
|
|
10
|
+
"schema:hasPart": [
|
|
11
|
+
{
|
|
12
|
+
"@id": "blocktrail.jsonld#this"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"@id": "webledger.jsonld#this"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"@id": "ledger-history.jsonld#this"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"schema:itemListElement": [
|
|
22
|
+
{
|
|
23
|
+
"@type": "schema:ListItem",
|
|
24
|
+
"@id": "mn05mqrf",
|
|
25
|
+
"schema:identifier": "txo:btc:d3a54de54a9df9e89b02dfda4274bbb12180c2ac75cb523917a66f515d01b977:0?amount=416366&key=b8f86cd4e9a6f5db705ebfbcbe3093745b10b2781a7ead82647dc770bd60fb02",
|
|
26
|
+
"schema:address": "tb1pgl8m440er9gmhvxepwuscduanw4xf6p2ccfaetqq48pcxfnhfazsqa22kz",
|
|
27
|
+
"schema:status": "unspent",
|
|
28
|
+
"schema:dateCreated": "2026-03-21T09:57:43.035Z"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
package/index.js
CHANGED
|
@@ -79,17 +79,20 @@ export function parseTxoUri (uri) {
|
|
|
79
79
|
// Convert key to lowercase for case-insensitivity
|
|
80
80
|
const normalizedKey = key.toLowerCase();
|
|
81
81
|
|
|
82
|
+
// Normalize aliases to canonical names
|
|
83
|
+
const canonicalKey = normalizedKey === 'key' ? 'privkey' : normalizedKey;
|
|
84
|
+
|
|
82
85
|
// Process specific key types
|
|
83
|
-
if (
|
|
86
|
+
if (canonicalKey === 'amount') {
|
|
84
87
|
// Parse amount as a number
|
|
85
88
|
const amount = parseFloat(value);
|
|
86
89
|
if (!isNaN(amount)) {
|
|
87
|
-
queryParams[
|
|
90
|
+
queryParams[canonicalKey] = amount;
|
|
88
91
|
} else {
|
|
89
|
-
queryParams[
|
|
92
|
+
queryParams[canonicalKey] = value;
|
|
90
93
|
}
|
|
91
94
|
} else {
|
|
92
|
-
queryParams[
|
|
95
|
+
queryParams[canonicalKey] = decodeURIComponent(value);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
});
|
|
@@ -167,12 +170,30 @@ export function formatTxoUri (data) {
|
|
|
167
170
|
// Build the base URI
|
|
168
171
|
let uri = `txo:${data.network}:${data.txid}:${output}`;
|
|
169
172
|
|
|
170
|
-
// Add query parameters
|
|
173
|
+
// Add query parameters (canonical key names, stable order: amount first, then privkey, then rest)
|
|
174
|
+
const reserved = ['network', 'txid', 'output'];
|
|
175
|
+
const entries = Object.entries(data).filter(([k]) => !reserved.includes(k) && data[k] !== undefined);
|
|
176
|
+
|
|
177
|
+
// Normalize 'key' alias to 'privkey'
|
|
171
178
|
const queryParams = [];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
const seen = new Set();
|
|
180
|
+
for (const [k, v] of entries) {
|
|
181
|
+
const canonical = k.toLowerCase() === 'key' ? 'privkey' : k.toLowerCase();
|
|
182
|
+
if (!seen.has(canonical)) {
|
|
183
|
+
seen.add(canonical);
|
|
184
|
+
queryParams.push(`${canonical}=${encodeURIComponent(v)}`);
|
|
175
185
|
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Stable order: amount first, privkey second, rest alphabetical
|
|
189
|
+
queryParams.sort((a, b) => {
|
|
190
|
+
const keyA = a.split('=')[0];
|
|
191
|
+
const keyB = b.split('=')[0];
|
|
192
|
+
if (keyA === 'amount') return -1;
|
|
193
|
+
if (keyB === 'amount') return 1;
|
|
194
|
+
if (keyA === 'privkey') return -1;
|
|
195
|
+
if (keyB === 'privkey') return 1;
|
|
196
|
+
return keyA.localeCompare(keyB);
|
|
176
197
|
});
|
|
177
198
|
|
|
178
199
|
if (queryParams.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "txo_parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Parser for TXO URI Specification (v0.1)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"cli"
|
|
24
24
|
],
|
|
25
25
|
"author": "Melvin Carvalho",
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "AGPL-3.0-or-later",
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/sandy-mount/txo_parser/issues"
|
|
29
29
|
},
|