txo_parser 0.0.2 → 0.0.4

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.
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "@context": "https://w3id.org/webledgers",
3
+ "@id": "#this",
4
+ "type": "WebLedger",
5
+ "name": "Voucher Pool Ledger",
6
+ "description": "Testnet4 voucher balances",
7
+ "defaultCurrency": "satoshi",
8
+ "entries": []
9
+ }
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 (normalizedKey === 'amount') {
86
+ if (canonicalKey === 'amount') {
84
87
  // Parse amount as a number
85
88
  const amount = parseFloat(value);
86
89
  if (!isNaN(amount)) {
87
- queryParams[normalizedKey] = amount;
90
+ queryParams[canonicalKey] = amount;
88
91
  } else {
89
- queryParams[normalizedKey] = value;
92
+ queryParams[canonicalKey] = value;
90
93
  }
91
94
  } else {
92
- queryParams[normalizedKey] = value;
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
- Object.entries(data).forEach(([key, value]) => {
173
- if (!['network', 'txid', 'output'].includes(key) && value !== undefined) {
174
- queryParams.push(`${key.toLowerCase()}=${encodeURIComponent(value)}`);
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,7 +1,7 @@
1
1
  {
2
2
  "name": "txo_parser",
3
- "version": "0.0.2",
4
- "description": "Parser for TXO URI Specification (v0.1)",
3
+ "version": "0.0.4",
4
+ "description": "Parser for TXO URI Specification (v0.2)",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "cli"
24
24
  ],
25
25
  "author": "Melvin Carvalho",
26
- "license": "MIT",
26
+ "license": "AGPL-3.0-or-later",
27
27
  "bugs": {
28
28
  "url": "https://github.com/sandy-mount/txo_parser/issues"
29
29
  },