@ctrl/magnet-link 3.1.1 → 4.0.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/README.md +2 -2
- package/dist/src/index.d.ts +3 -4
- package/dist/src/index.js +13 -12
- package/package.json +15 -12
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# magnet-link [](https://www.npmjs.com/package/@ctrl/magnet-link) [](https://www.npmjs.com/package/@ctrl/magnet-link) [](https://codecov.io/gh/scttcper/magnet-link)
|
2
2
|
|
3
3
|
> Parse a magnet URI into an object
|
4
4
|
|
@@ -71,7 +71,7 @@ const uri = magnetEncode({
|
|
71
71
|
});
|
72
72
|
|
73
73
|
|
74
|
-
You can also use convenience key names like name (dn), infoHash (xt),
|
74
|
+
You can also use convenience key names like name (dn), infoHash (xt), infoHashIntArray (xt), announce (tr), and keywords (kt).
|
75
75
|
```
|
76
76
|
|
77
77
|
### See Also
|
package/dist/src/index.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
2
1
|
export interface MagnetData {
|
3
2
|
/**
|
4
3
|
* Is the info-hash hex encoded, for a total of 40 characters. For compatability with existing links in the wild, clients should also support the 32 character base32 encoded info-hash.
|
@@ -13,9 +12,9 @@ export interface MagnetData {
|
|
13
12
|
* Parsed xt= parameter see xt
|
14
13
|
*/
|
15
14
|
infoHash?: string;
|
16
|
-
|
15
|
+
infoHashIntArray?: Uint8Array;
|
17
16
|
infoHashV2?: string;
|
18
|
-
|
17
|
+
infoHashV2IntArray?: Uint8Array;
|
19
18
|
/**
|
20
19
|
* The display name that may be used by the client to display while waiting for metadata
|
21
20
|
*/
|
@@ -68,7 +67,7 @@ export interface MagnetData {
|
|
68
67
|
urlList?: string[];
|
69
68
|
peerAddresses?: string[];
|
70
69
|
publicKey?: string;
|
71
|
-
|
70
|
+
publicKeyIntArray?: Uint8Array;
|
72
71
|
}
|
73
72
|
export declare function magnetDecode(uri: string): MagnetData;
|
74
73
|
export declare function magnetEncode(data: MagnetData): string;
|
package/dist/src/index.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { base32 } from 'rfc4648';
|
2
|
+
import { hexToUint8Array, uint8ArrayToHex } from 'uint8array-extras';
|
2
3
|
import * as bep53Range from './bep53.js';
|
3
4
|
const start = 'magnet:?';
|
4
5
|
export function magnetDecode(uri) {
|
@@ -39,8 +40,8 @@ export function magnetDecode(uri) {
|
|
39
40
|
result.infoHash = m[1].toLowerCase();
|
40
41
|
}
|
41
42
|
else if ((m = xt.match(/^urn:btih:(.{32})/))) {
|
42
|
-
const decodedStr =
|
43
|
-
result.infoHash =
|
43
|
+
const decodedStr = base32.parse(m[1]);
|
44
|
+
result.infoHash = uint8ArrayToHex(decodedStr);
|
44
45
|
}
|
45
46
|
else if ((m = xt.match(/^urn:btmh:1220(.{64})/))) {
|
46
47
|
result.infoHashV2 = m[1].toLowerCase();
|
@@ -57,13 +58,13 @@ export function magnetDecode(uri) {
|
|
57
58
|
});
|
58
59
|
}
|
59
60
|
if (result.infoHash) {
|
60
|
-
result.
|
61
|
+
result.infoHashIntArray = hexToUint8Array(result.infoHash);
|
61
62
|
}
|
62
63
|
if (result.infoHashV2) {
|
63
|
-
result.
|
64
|
+
result.infoHashV2IntArray = hexToUint8Array(result.infoHashV2);
|
64
65
|
}
|
65
66
|
if (result.publicKey) {
|
66
|
-
result.
|
67
|
+
result.publicKeyIntArray = hexToUint8Array(result.publicKey);
|
67
68
|
}
|
68
69
|
if (result.dn) {
|
69
70
|
result.name = result.dn;
|
@@ -133,14 +134,14 @@ export function magnetEncode(data) {
|
|
133
134
|
if (obj.xt && Array.isArray(obj.xt)) {
|
134
135
|
xts = new Set(obj.xt);
|
135
136
|
}
|
136
|
-
if (obj.
|
137
|
-
xts.add(`urn:btih:${obj.
|
137
|
+
if (obj.infoHashIntArray) {
|
138
|
+
xts.add(`urn:btih:${uint8ArrayToHex(obj.infoHashIntArray)}`);
|
138
139
|
}
|
139
140
|
if (obj.infoHash) {
|
140
141
|
xts.add(`urn:btih:${obj.infoHash}`);
|
141
142
|
}
|
142
|
-
if (obj.
|
143
|
-
xts.add((obj.xt = `urn:btmh:1220${obj.
|
143
|
+
if (obj.infoHashV2IntArray) {
|
144
|
+
xts.add((obj.xt = `urn:btmh:1220${uint8ArrayToHex(obj.infoHashV2IntArray)}`));
|
144
145
|
}
|
145
146
|
if (obj.infoHashV2) {
|
146
147
|
xts.add(`urn:btmh:1220${obj.infoHashV2}`);
|
@@ -157,8 +158,8 @@ export function magnetEncode(data) {
|
|
157
158
|
if (obj.infoHash) {
|
158
159
|
obj.xt = `urn:btih:${obj.infoHash}`;
|
159
160
|
}
|
160
|
-
if (obj.
|
161
|
-
obj.xs = `urn:btpk:${obj.
|
161
|
+
if (obj.publicKeyIntArray) {
|
162
|
+
obj.xs = `urn:btpk:${uint8ArrayToHex(obj.publicKeyIntArray)}`;
|
162
163
|
}
|
163
164
|
if (obj.publicKey) {
|
164
165
|
obj.xs = `urn:btpk:${obj.publicKey}`;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/magnet-link",
|
3
|
-
"version": "
|
3
|
+
"version": "4.0.0",
|
4
4
|
"description": "Parse a magnet URI into an object",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"homepage": "https://magnet-link.vercel.app",
|
@@ -20,6 +20,7 @@
|
|
20
20
|
],
|
21
21
|
"sideEffects": false,
|
22
22
|
"scripts": {
|
23
|
+
"dev": "npm run demo:watch",
|
23
24
|
"demo:build": "npm run build --workspace=demo",
|
24
25
|
"demo:watch": "npm run dev --workspace=demo",
|
25
26
|
"lint": "eslint --ext .ts .",
|
@@ -28,25 +29,27 @@
|
|
28
29
|
"build": "tsc",
|
29
30
|
"test": "vitest run",
|
30
31
|
"test:watch": "vitest",
|
31
|
-
"test:ci": "vitest run --coverage --reporter=junit --outputFile=./junit.xml"
|
32
|
+
"test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
|
32
33
|
},
|
33
34
|
"dependencies": {
|
34
|
-
"
|
35
|
+
"rfc4648": "^1.5.3",
|
36
|
+
"uint8array-extras": "^0.5.1"
|
35
37
|
},
|
36
38
|
"devDependencies": {
|
37
|
-
"@ctrl/eslint-config": "
|
38
|
-
"@sindresorhus/tsconfig": "
|
39
|
-
"@types/node": "
|
40
|
-
"
|
41
|
-
"c8": "
|
42
|
-
"typescript": "
|
43
|
-
"vitest": "0.
|
39
|
+
"@ctrl/eslint-config": "4.0.10",
|
40
|
+
"@sindresorhus/tsconfig": "5.0.0",
|
41
|
+
"@types/node": "20.9.0",
|
42
|
+
"@vitest/coverage-v8": "0.34.6",
|
43
|
+
"c8": "8.0.1",
|
44
|
+
"typescript": "5.2.2",
|
45
|
+
"vitest": "0.34.6"
|
44
46
|
},
|
45
47
|
"workspaces": [
|
46
48
|
"demo"
|
47
49
|
],
|
48
50
|
"publishConfig": {
|
49
|
-
"access": "public"
|
51
|
+
"access": "public",
|
52
|
+
"provenance": true
|
50
53
|
},
|
51
54
|
"release": {
|
52
55
|
"branches": [
|
@@ -54,6 +57,6 @@
|
|
54
57
|
]
|
55
58
|
},
|
56
59
|
"engines": {
|
57
|
-
"node": ">=
|
60
|
+
"node": ">=18"
|
58
61
|
}
|
59
62
|
}
|