bip-321 0.0.4 → 0.0.5
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/README.md +33 -5
- package/bun.lock +467 -11
- package/eslint.config.js +94 -0
- package/example.ts +3 -3
- package/index.test.ts +104 -8
- package/index.ts +172 -22
- package/package.json +8 -4
- package/oxlintrc.json +0 -23
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A TypeScript/JavaScript library for parsing BIP-321 Bitcoin URI scheme. This lib
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- ✅ **Complete BIP-321 compliance** - Implements the full BIP-321 specification
|
|
8
|
-
- ✅ **Multiple payment methods** - Supports on-chain, Lightning (BOLT11), BOLT12 offers,
|
|
8
|
+
- ✅ **Multiple payment methods** - Supports on-chain, Lightning (BOLT11), BOLT12 offers, silent payments, and Ark
|
|
9
9
|
- ✅ **Network detection** - Automatically detects mainnet, testnet, regtest, and signet networks
|
|
10
10
|
- ✅ **Address validation** - Validates Bitcoin addresses (P2PKH, P2SH, Segwit v0, Taproot)
|
|
11
11
|
- ✅ **Lightning invoice validation** - Validates BOLT11 Lightning invoices
|
|
@@ -21,7 +21,7 @@ result.paymentMethods; // PaymentMethod[]
|
|
|
21
21
|
result.errors; // string[]
|
|
22
22
|
|
|
23
23
|
result.paymentMethods.forEach((method: PaymentMethod) => {
|
|
24
|
-
method.type; // "onchain" | "lightning" | "
|
|
24
|
+
method.type; // "onchain" | "lightning" | "offer" | "silent-payment" | "ark"
|
|
25
25
|
method.network; // "mainnet" | "testnet" | "regtest" | "signet" | undefined
|
|
26
26
|
method.valid; // boolean
|
|
27
27
|
});
|
|
@@ -105,6 +105,25 @@ console.log(result.paymentMethods[0].type); // "lightning"
|
|
|
105
105
|
console.log(result.paymentMethods[0].network); // "mainnet"
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
### Ark Payment
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Mainnet Ark address
|
|
112
|
+
const result = parseBIP321(
|
|
113
|
+
"bitcoin:?ark=ark1pwh9vsmezqqpjy9akejayl2vvcse6he97rn40g84xrlvrlnhayuuyefrp9nse2yspqqjl5wpy"
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
console.log(result.paymentMethods[0].type); // "ark"
|
|
117
|
+
console.log(result.paymentMethods[0].network); // "mainnet"
|
|
118
|
+
|
|
119
|
+
// Testnet Ark address
|
|
120
|
+
const testnetResult = parseBIP321(
|
|
121
|
+
"bitcoin:?ark=tark1pm6sr0fpzqqpnzzwxf209kju4qavs4gtumxk30yv2u5ncrvtp72z34axcvrydtdqpqq5838km"
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
console.log(testnetResult.paymentMethods[0].network); // "testnet"
|
|
125
|
+
```
|
|
126
|
+
|
|
108
127
|
### Network Validation
|
|
109
128
|
|
|
110
129
|
```typescript
|
|
@@ -136,7 +155,7 @@ const result = parseBIP321(
|
|
|
136
155
|
"bitcoin:?lightning=lnbc...&lno=lno1bogusoffer&sp=sp1qsilentpayment"
|
|
137
156
|
);
|
|
138
157
|
|
|
139
|
-
// Returns 3 payment methods: lightning,
|
|
158
|
+
// Returns 3 payment methods: lightning, offer (BOLT12), and silent-payment
|
|
140
159
|
console.log(`Total payment methods: ${result.paymentMethods.length}`);
|
|
141
160
|
```
|
|
142
161
|
|
|
@@ -221,7 +240,7 @@ interface BIP321ParseResult {
|
|
|
221
240
|
|
|
222
241
|
```typescript
|
|
223
242
|
interface PaymentMethod {
|
|
224
|
-
type: "onchain" | "lightning" | "
|
|
243
|
+
type: "onchain" | "lightning" | "offer" | "silent-payment" | "ark";
|
|
225
244
|
value: string; // The actual address/invoice value
|
|
226
245
|
network?: "mainnet" | "testnet" | "regtest" | "signet";
|
|
227
246
|
valid: boolean; // Whether this payment method is valid
|
|
@@ -271,8 +290,9 @@ console.log(summary);
|
|
|
271
290
|
|--------|--------------|-------------|
|
|
272
291
|
| On-chain | `address` or `bc`/`tb`/`bcrt`/`tbs` | Bitcoin addresses (P2PKH, P2SH, Segwit, Taproot) |
|
|
273
292
|
| Lightning | `lightning` | BOLT11 Lightning invoices |
|
|
274
|
-
| BOLT12 | `lno` | Lightning BOLT12 offers |
|
|
293
|
+
| BOLT12 Offer | `lno` | Lightning BOLT12 offers |
|
|
275
294
|
| Silent Payments | `sp` | BIP352 Silent Payment addresses |
|
|
295
|
+
| Ark | `ark` | Ark addresses (mainnet: `ark1...`, testnet: `tark1...`) |
|
|
276
296
|
|
|
277
297
|
## Network Detection
|
|
278
298
|
|
|
@@ -289,6 +309,10 @@ The library automatically detects the network from:
|
|
|
289
309
|
- **Regtest**: `lnbcrt...`
|
|
290
310
|
- **Signet**: `lntbs...`
|
|
291
311
|
|
|
312
|
+
### Ark Addresses
|
|
313
|
+
- **Mainnet**: `ark1...`
|
|
314
|
+
- **Testnet**: `tark1...`
|
|
315
|
+
|
|
292
316
|
## Validation Rules
|
|
293
317
|
|
|
294
318
|
The parser enforces BIP-321 validation rules:
|
|
@@ -356,3 +380,7 @@ MIT
|
|
|
356
380
|
|
|
357
381
|
- [BIP-321 Specification](https://github.com/bitcoin/bips/blob/master/bip-0321.mediawiki)
|
|
358
382
|
- [BIP-21 (Original)](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki)
|
|
383
|
+
- [BIP-352 Silent Payments](https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki)
|
|
384
|
+
- [BOAT-0001 Ark Address Format](https://github.com/ark-protocol/boats/blob/master/boat-0001.md)
|
|
385
|
+
- [BOLT11 Lightning Invoices](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
|
|
386
|
+
- [BOLT12 Lightning Offers](https://github.com/lightning/bolts/blob/master/12-offer-encoding.md)
|