@majikah/majik-slink 0.0.1
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 +67 -0
- package/README.md +95 -0
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.js +5 -0
- package/dist/core/errors.d.ts +13 -0
- package/dist/core/errors.js +27 -0
- package/dist/core/types.d.ts +61 -0
- package/dist/core/types.js +2 -0
- package/dist/core/utils.d.ts +24 -0
- package/dist/core/utils.js +120 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +12 -0
- package/dist/majik-slink.d.ts +227 -0
- package/dist/majik-slink.js +519 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Copyright (c) 2025 Josef Elijah Delos Santos Fabian
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
Apache License
|
|
18
|
+
Version 2.0, January 2004
|
|
19
|
+
http://www.apache.org/licenses/
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
26
|
+
|
|
27
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
32
|
+
|
|
33
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
40
|
+
|
|
41
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
42
|
+
|
|
43
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
44
|
+
|
|
45
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
46
|
+
|
|
47
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
48
|
+
|
|
49
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
50
|
+
|
|
51
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
52
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
53
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
54
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
55
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
56
|
+
|
|
57
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
58
|
+
|
|
59
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
60
|
+
|
|
61
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
64
|
+
|
|
65
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
66
|
+
|
|
67
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Majik SLink
|
|
2
|
+
|
|
3
|
+
[](https://thezelijah.world) 
|
|
4
|
+
|
|
5
|
+
**MajikSLink** is a specialized TypeScript library designed for URL ownership verification and cryptographic identity linking. It provides a robust mechanism to prove that a specific digital identity (a MajikKey) controls a publicly accessible web resource (such as a YouTube channel, social media profile, or personal blog).
|
|
6
|
+
|
|
7
|
+
By combining traditional **Ed25519** signatures with post-quantum **ML-DSA-87** (Dilithium) hybrid cryptography, MajikSLink ensures that your identity-to-URL associations are tamper-proof and future-proof.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Identities can be created and managed via the web application at **[https://id.majikah.solutions](https://id.majikah.solutions)** using your own Majik Keys.
|
|
12
|
+
|
|
13
|
+
  [](https://opensource.org/licenses/Apache-2.0) 
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Key Features:
|
|
19
|
+
1. **Deterministic URL Normalization:** Automatically converts URLs into a canonical format (stripping query params and fragments) so that the same resource always generates the same verification code.
|
|
20
|
+
|
|
21
|
+
2. **Challenge-Response Verification:** Generates short, embeddable verification codes (v_code) that users can place in their bios or page metadata for automated scrapers to detect.
|
|
22
|
+
|
|
23
|
+
3. **Hybrid Signing:** Leverages [@majikah/majik-signature](https://www.npmjs.com/package/@majikah/majik-signature) to sign canonical URL data with both classical and post-quantum algorithms.
|
|
24
|
+
|
|
25
|
+
4. **Proof of Ownership:** Enables a trustless workflow where a crawler can verify the presence of a code, and the library verifies the cryptographic signature against the owner's public keys.
|
|
26
|
+
|
|
27
|
+
5. **Seamless Serialization:** Includes built-in support for JSON rehydration and Base64 serialization for easy storage in databases or transmission via QR codes.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Related Projects
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### [Majik Signature](https://www.npmjs.com/package/@majikah/majik-signature)
|
|
34
|
+
Hybrid post-quantum content signing — the signing engine used by `signContent()` and `signFile()`.
|
|
35
|
+
|
|
36
|
+
[Read Docs](https://majikah.solutions/products/majik-signature/docs) · [Microsoft Store](https://apps.microsoft.com/detail/9pl9g3xzvd1x)
|
|
37
|
+
|
|
38
|
+
[](https://apps.microsoft.com/detail/9pl9g3xzvd1x)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### [Majik Message](https://message.majikah.solutions)
|
|
43
|
+
Secure messaging platform using Majik Keys and Majik Signatures for identity-bound communication.
|
|
44
|
+
|
|
45
|
+
[Read Docs](https://majikah.solutions/products/majik-message/docs) · [Microsoft Store](https://apps.microsoft.com/detail/9pmjgvzzjspn)
|
|
46
|
+
|
|
47
|
+
[](https://apps.microsoft.com/detail/9pmjgvzzjspn)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### [Majik Key](https://www.npmjs.com/package/@majikah/majik-key)
|
|
51
|
+
Seed phrase account library — required peer dependency for signing and encryption.
|
|
52
|
+
|
|
53
|
+
[Read More Information](https://majikah.solutions/sdk/majik-key)
|
|
54
|
+
|
|
55
|
+
### [Majik Envelope](https://www.npmjs.com/package/@majikah/majik-envelope)
|
|
56
|
+
Post-quantum group encryption — used to encrypt and share private personal info.
|
|
57
|
+
|
|
58
|
+
[Read More Information](https://majikah.solutions/sdk/majik-envelope)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### [Majik Universal ID](https://id.majikah.solutions)
|
|
62
|
+
A cryptographically anchored identity layer for the Majikah ecosystem.
|
|
63
|
+
|
|
64
|
+
[Read More Information](https://majikah.solutions/sdk/majik-universal-id)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Contributing
|
|
70
|
+
|
|
71
|
+
If you want to contribute or help extend support, reach out via email. All contributions are welcome!
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[Apache-2.0](LICENSE) — free for personal and commercial use.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Author
|
|
82
|
+
|
|
83
|
+
Made with 💙 by [@thezelijah](https://github.com/jedlsf)
|
|
84
|
+
|
|
85
|
+
**Developer**: Josef Elijah Fabian
|
|
86
|
+
**GitHub**: [https://github.com/jedlsf](https://github.com/jedlsf)
|
|
87
|
+
**Project Repository**: [https://github.com/Majikah/majik-slink](https://github.com/Majikah/majik-slink)
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Contact
|
|
92
|
+
|
|
93
|
+
- **Business Email**: [business@thezelijah.world](mailto:business@thezelijah.world)
|
|
94
|
+
- **Official Website**: [https://www.thezelijah.world](https://www.thezelijah.world)
|
|
95
|
+
- **ID Web App**: [https://id.majikah.solutions](https://id.majikah.solutions)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
2
|
+
export const SLINK_VERSION = 1;
|
|
3
|
+
export const CANONICAL_PREFIX = "majik-slink-v1:";
|
|
4
|
+
export const CODE_PREFIX = "majik-slink:";
|
|
5
|
+
export const CODE_HEX_LENGTH = 32; // chars from the 64-char SHA-256 hex digest
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class MajikSLinkError extends Error {
|
|
2
|
+
readonly cause?: unknown;
|
|
3
|
+
constructor(message: string, cause?: unknown);
|
|
4
|
+
}
|
|
5
|
+
export declare class MajikSLinkValidationError extends MajikSLinkError {
|
|
6
|
+
constructor(message: string, cause?: unknown);
|
|
7
|
+
}
|
|
8
|
+
export declare class MajikSLinkSigningError extends MajikSLinkError {
|
|
9
|
+
constructor(message: string, cause?: unknown);
|
|
10
|
+
}
|
|
11
|
+
export declare class MajikSLinkSerializationError extends MajikSLinkError {
|
|
12
|
+
constructor(message: string, cause?: unknown);
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// ─── Error types ─────────────────────────────────────────────────────────────
|
|
2
|
+
export class MajikSLinkError extends Error {
|
|
3
|
+
cause;
|
|
4
|
+
constructor(message, cause) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.cause = cause;
|
|
7
|
+
this.name = "MajikSLinkError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class MajikSLinkValidationError extends MajikSLinkError {
|
|
11
|
+
constructor(message, cause) {
|
|
12
|
+
super(message, cause);
|
|
13
|
+
this.name = "MajikSLinkValidationError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class MajikSLinkSigningError extends MajikSLinkError {
|
|
17
|
+
constructor(message, cause) {
|
|
18
|
+
super(message, cause);
|
|
19
|
+
this.name = "MajikSLinkSigningError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class MajikSLinkSerializationError extends MajikSLinkError {
|
|
23
|
+
constructor(message, cause) {
|
|
24
|
+
super(message, cause);
|
|
25
|
+
this.name = "MajikSLinkSerializationError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MajikSignatureJSON } from "@majikah/majik-signature";
|
|
2
|
+
/** Source platform of the signed URL */
|
|
3
|
+
export type SLinkSource = "youtube" | "x" | "instagram" | "tiktok" | "github" | "website" | "other";
|
|
4
|
+
/** Structured URL parts extracted during normalisation */
|
|
5
|
+
export interface UrlInfo {
|
|
6
|
+
/** Full registered domain e.g. "youtube.com" */
|
|
7
|
+
domain: string;
|
|
8
|
+
/** Second-level domain only e.g. "youtube" */
|
|
9
|
+
sld: string;
|
|
10
|
+
/** Top-level domain e.g. "com" */
|
|
11
|
+
tld: string;
|
|
12
|
+
/** Subdomain or null e.g. "www" | null */
|
|
13
|
+
subdomain: string | null;
|
|
14
|
+
/** Normalised pathname e.g. "/watch/dQw4w9WgXcQ" */
|
|
15
|
+
path: string;
|
|
16
|
+
/** Reconstructed clean URL (no params, no fragment) */
|
|
17
|
+
cleanUrl: string;
|
|
18
|
+
/** The string that is actually hashed + signed */
|
|
19
|
+
canonical: string;
|
|
20
|
+
}
|
|
21
|
+
/** Verification status of a MajikSLink */
|
|
22
|
+
export type SLinkVerificationStatus = "pending" | "unverified" | "verified" | "failed" | "sig_invalid";
|
|
23
|
+
/** Shape persisted to / rehydrated from a database */
|
|
24
|
+
export interface MajikSLinkJSON {
|
|
25
|
+
version: 1;
|
|
26
|
+
id: string;
|
|
27
|
+
user_id: string;
|
|
28
|
+
/** Full registered domain e.g. "youtube.com" */
|
|
29
|
+
domain: string;
|
|
30
|
+
/** Subdomain or null */
|
|
31
|
+
subdomain: string | null;
|
|
32
|
+
/** Normalised path */
|
|
33
|
+
path: string;
|
|
34
|
+
/** Original URL supplied by the user */
|
|
35
|
+
url: string;
|
|
36
|
+
/** SHA-256 hex digest of the canonical string */
|
|
37
|
+
hash: string;
|
|
38
|
+
/** The short verification code to embed in the page */
|
|
39
|
+
v_code: string;
|
|
40
|
+
/** Detected source platform */
|
|
41
|
+
source: SLinkSource;
|
|
42
|
+
/** Verification status */
|
|
43
|
+
status: SLinkVerificationStatus;
|
|
44
|
+
/** ISO timestamp of when this SLink was created */
|
|
45
|
+
timestamp: string;
|
|
46
|
+
/** ISO timestamp of the last verification attempt, or null */
|
|
47
|
+
verified_at: string | null;
|
|
48
|
+
/** The MajikSignature envelope covering the canonical URL */
|
|
49
|
+
signature: MajikSignatureJSON;
|
|
50
|
+
}
|
|
51
|
+
/** Lightweight code-only payload — useful for the UI before full create() */
|
|
52
|
+
export interface SLinkCodePreview {
|
|
53
|
+
/** The short string to embed in the page */
|
|
54
|
+
v_code: string;
|
|
55
|
+
/** SHA-256 hex of canonical */
|
|
56
|
+
hash: string;
|
|
57
|
+
/** Reconstructed clean URL */
|
|
58
|
+
cleanUrl: string;
|
|
59
|
+
/** Parsed URL parts */
|
|
60
|
+
urlInfo: UrlInfo;
|
|
61
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MajikKey } from "@majikah/majik-key";
|
|
2
|
+
import { SLinkSource, UrlInfo } from "./types";
|
|
3
|
+
export declare function sha256Hex(input: string): Promise<string>;
|
|
4
|
+
export declare function generateId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Detect the likely source platform from a registered domain.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectSource(sld: string): SLinkSource;
|
|
9
|
+
export declare function assertNonEmptyString(value: unknown, name: string): asserts value is string;
|
|
10
|
+
export declare function assertValidHttpUrl(value: string): void;
|
|
11
|
+
export declare function assertMajikKey(key: unknown): asserts key is MajikKey;
|
|
12
|
+
export declare function assertUnlockedKey(key: MajikKey): void;
|
|
13
|
+
/**
|
|
14
|
+
* Parse and normalise a URL into its constituent parts, stripping all query
|
|
15
|
+
* params, auth, fragments, and trailing slashes from the path.
|
|
16
|
+
*
|
|
17
|
+
* Returns null when the URL cannot be resolved to a valid PSL domain.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseUrlInfo(rawUrl: string): UrlInfo | null;
|
|
20
|
+
/**
|
|
21
|
+
* Reconstruct the canonical string from already-parsed parts.
|
|
22
|
+
* Used during fromJSON rehydration to avoid re-running PSL.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildCanonical(subdomain: string | null, sld: string, tld: string, path: string): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// ─── Internal helpers ─────────────────────────────────────────────────────────
|
|
2
|
+
import { MajikSLinkSigningError, MajikSLinkValidationError } from "./errors";
|
|
3
|
+
import { CANONICAL_PREFIX } from "./constants";
|
|
4
|
+
import psl from "psl";
|
|
5
|
+
export async function sha256Hex(input) {
|
|
6
|
+
const encoded = new TextEncoder().encode(input);
|
|
7
|
+
const buffer = await crypto.subtle.digest("SHA-256", encoded);
|
|
8
|
+
return Array.from(new Uint8Array(buffer))
|
|
9
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
10
|
+
.join("");
|
|
11
|
+
}
|
|
12
|
+
export function generateId() {
|
|
13
|
+
// 16-byte random hex — replace with your preferred ID strategy (uuid, nanoid, etc.)
|
|
14
|
+
const bytes = new Uint8Array(16);
|
|
15
|
+
crypto.getRandomValues(bytes);
|
|
16
|
+
return Array.from(bytes)
|
|
17
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
18
|
+
.join("");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Detect the likely source platform from a registered domain.
|
|
22
|
+
*/
|
|
23
|
+
export function detectSource(sld) {
|
|
24
|
+
switch (sld.toLowerCase()) {
|
|
25
|
+
case "youtube":
|
|
26
|
+
return "youtube";
|
|
27
|
+
case "twitter":
|
|
28
|
+
case "x":
|
|
29
|
+
return "x";
|
|
30
|
+
case "instagram":
|
|
31
|
+
return "instagram";
|
|
32
|
+
case "tiktok":
|
|
33
|
+
return "tiktok";
|
|
34
|
+
case "github":
|
|
35
|
+
return "github";
|
|
36
|
+
default:
|
|
37
|
+
return "other";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// ─── Validators ───────────────────────────────────────────────────────────────
|
|
41
|
+
export function assertNonEmptyString(value, name) {
|
|
42
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
43
|
+
throw new MajikSLinkValidationError(`"${name}" must be a non-empty string.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function assertValidHttpUrl(value) {
|
|
47
|
+
try {
|
|
48
|
+
const u = new URL(value);
|
|
49
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") {
|
|
50
|
+
throw new MajikSLinkValidationError(`URL must use http or https. Got: "${u.protocol}"`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (err instanceof MajikSLinkValidationError)
|
|
55
|
+
throw err;
|
|
56
|
+
throw new MajikSLinkValidationError(`Invalid URL: "${value}"`, err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function assertMajikKey(key) {
|
|
60
|
+
if (!key || typeof key !== "object") {
|
|
61
|
+
throw new MajikSLinkValidationError("A MajikKey instance is required.");
|
|
62
|
+
}
|
|
63
|
+
if (typeof key.fingerprint !== "string") {
|
|
64
|
+
throw new MajikSLinkValidationError("Provided key does not appear to be a MajikKey (missing fingerprint).");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function assertUnlockedKey(key) {
|
|
68
|
+
if (key.isLocked) {
|
|
69
|
+
throw new MajikSLinkSigningError("MajikKey is locked. Call unlock() before creating a MajikSLink.");
|
|
70
|
+
}
|
|
71
|
+
if (!key.hasSigningKeys) {
|
|
72
|
+
throw new MajikSLinkSigningError("MajikKey has no signing keys. Re-import via importFromMnemonicBackup() to enable signing.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// ─── URL normalisation ────────────────────────────────────────────────────────
|
|
76
|
+
/**
|
|
77
|
+
* Parse and normalise a URL into its constituent parts, stripping all query
|
|
78
|
+
* params, auth, fragments, and trailing slashes from the path.
|
|
79
|
+
*
|
|
80
|
+
* Returns null when the URL cannot be resolved to a valid PSL domain.
|
|
81
|
+
*/
|
|
82
|
+
export function parseUrlInfo(rawUrl) {
|
|
83
|
+
try {
|
|
84
|
+
assertValidHttpUrl(rawUrl);
|
|
85
|
+
const parsedUrl = new URL(rawUrl);
|
|
86
|
+
const hostnameStr = parsedUrl.hostname;
|
|
87
|
+
const pslResult = psl.parse(hostnameStr);
|
|
88
|
+
// psl.parse returns a ParsedDomain | { error } union
|
|
89
|
+
if ("error" in pslResult && pslResult.error)
|
|
90
|
+
return null;
|
|
91
|
+
const parsed = pslResult;
|
|
92
|
+
if (!parsed.domain)
|
|
93
|
+
return null;
|
|
94
|
+
const sld = parsed.sld ?? hostnameStr;
|
|
95
|
+
const tld = parsed.tld ?? "";
|
|
96
|
+
const subdomain = parsed.subdomain ?? null;
|
|
97
|
+
const domain = parsed.domain; // e.g. "youtube.com"
|
|
98
|
+
// Normalise path: strip trailing slash unless it is the root
|
|
99
|
+
let path = parsedUrl.pathname;
|
|
100
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
101
|
+
path = path.slice(0, -1);
|
|
102
|
+
}
|
|
103
|
+
if (!path)
|
|
104
|
+
path = "/";
|
|
105
|
+
const cleanUrl = `${parsedUrl.protocol}//${hostnameStr}${path}`;
|
|
106
|
+
// Canonical string that is hashed and signed
|
|
107
|
+
const canonical = `${CANONICAL_PREFIX}${subdomain ?? "root"}::${sld}::${tld}::${path}`;
|
|
108
|
+
return { domain, sld, tld, subdomain, path, cleanUrl, canonical };
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reconstruct the canonical string from already-parsed parts.
|
|
116
|
+
* Used during fromJSON rehydration to avoid re-running PSL.
|
|
117
|
+
*/
|
|
118
|
+
export function buildCanonical(subdomain, sld, tld, path) {
|
|
119
|
+
return `${CANONICAL_PREFIX}${subdomain ?? "root"}::${sld}::${tld}::${path}`;
|
|
120
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.ts
|
|
3
|
+
* Public API surface for majik-slink.
|
|
4
|
+
*/
|
|
5
|
+
export { MajikSLink } from "./majik-slink";
|
|
6
|
+
export type * from "./core/types";
|
|
7
|
+
export * from "./core/errors";
|
|
8
|
+
export * from "./core/constants";
|
|
9
|
+
export { parseUrlInfo, buildCanonical, detectSource } from "./core/utils";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.ts
|
|
3
|
+
* Public API surface for majik-slink.
|
|
4
|
+
*/
|
|
5
|
+
// ── Main class ────────────────────────────────────────────────────────────────
|
|
6
|
+
export { MajikSLink } from "./majik-slink";
|
|
7
|
+
// ── Errors ────────────────────────────────────────────────────────────────────
|
|
8
|
+
export * from "./core/errors";
|
|
9
|
+
// ── Constants ─────────────────────────────────────────────────────────────────
|
|
10
|
+
export * from "./core/constants";
|
|
11
|
+
// ── Low-level utilities (opt-in) ──────────────────────────────────────────────
|
|
12
|
+
export { parseUrlInfo, buildCanonical, detectSource } from "./core/utils";
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* majik-slink.ts
|
|
3
|
+
*/
|
|
4
|
+
import type { MajikKey } from "@majikah/majik-key";
|
|
5
|
+
import { MajikSignature, type MajikSignatureJSON } from "@majikah/majik-signature";
|
|
6
|
+
import { MajikSLinkJSON, SLinkCodePreview, SLinkSource, SLinkVerificationStatus, UrlInfo } from "./core/types";
|
|
7
|
+
/**
|
|
8
|
+
* MajikSLink
|
|
9
|
+
* ---------------------
|
|
10
|
+
* MajikSLink — URL ownership signing and verification.
|
|
11
|
+
* A MajikSLink proves that the holder of a MajikKey owns (or controls) a
|
|
12
|
+
* publicly-accessible URL by:
|
|
13
|
+
*
|
|
14
|
+
* 1. Normalising the URL to a canonical form (scheme + subdomain + domain +
|
|
15
|
+
* tld + path, no query string, no fragment, no trailing slash).
|
|
16
|
+
* 2. Deriving a short, deterministic verification code from a SHA-256 digest
|
|
17
|
+
* of the canonical URL parts — so the same resource always produces the
|
|
18
|
+
* same code regardless of query params or tracking tokens.
|
|
19
|
+
* 3. Signing the canonical URL string with the owner's MajikKey via
|
|
20
|
+
* MajikSignature (Ed25519 + ML-DSA-87 hybrid).
|
|
21
|
+
*
|
|
22
|
+
* The owner embeds the verification code (`v_code`) anywhere in the public
|
|
23
|
+
* page (description, bio, comment, HTML body) and a scraper verifies its
|
|
24
|
+
* presence. Once found, the MajikSignature certifies the association between
|
|
25
|
+
* the signer's identity and the URL.
|
|
26
|
+
*
|
|
27
|
+
* Canonical URL format (what is signed):
|
|
28
|
+
* "majik-slink-v1:<subdomain>::<sld>::<tld>::<path>"
|
|
29
|
+
* e.g. "majik-slink-v1:www::youtube::com::/watch/dQw4w9WgXcQ"
|
|
30
|
+
*
|
|
31
|
+
* Verification code format:
|
|
32
|
+
* "majik-slink:<first 32 hex chars of SHA-256(canonical)>"
|
|
33
|
+
* e.g. "majik-slink:a1b2c3d4e5f6..."
|
|
34
|
+
*/
|
|
35
|
+
export declare class MajikSLink {
|
|
36
|
+
private readonly _version;
|
|
37
|
+
private readonly _id;
|
|
38
|
+
private readonly _user_id;
|
|
39
|
+
private readonly _domain;
|
|
40
|
+
private readonly _sld;
|
|
41
|
+
private readonly _tld;
|
|
42
|
+
private readonly _subdomain;
|
|
43
|
+
private readonly _path;
|
|
44
|
+
private readonly _url;
|
|
45
|
+
private readonly _clean_url;
|
|
46
|
+
private readonly _hash;
|
|
47
|
+
private readonly _v_code;
|
|
48
|
+
private readonly _source;
|
|
49
|
+
private _status;
|
|
50
|
+
private _verified_at;
|
|
51
|
+
private readonly _signature;
|
|
52
|
+
private _signatureInstance;
|
|
53
|
+
private readonly _timestamp;
|
|
54
|
+
private constructor();
|
|
55
|
+
get version(): 1;
|
|
56
|
+
get id(): string;
|
|
57
|
+
get userId(): string;
|
|
58
|
+
/** Full registered domain e.g. "youtube.com" */
|
|
59
|
+
get domain(): string;
|
|
60
|
+
/** Second-level domain e.g. "youtube" */
|
|
61
|
+
get sld(): string;
|
|
62
|
+
/** Top-level domain e.g. "com" */
|
|
63
|
+
get tld(): string;
|
|
64
|
+
/** Subdomain or null e.g. "www" */
|
|
65
|
+
get subdomain(): string | null;
|
|
66
|
+
/** Normalised path */
|
|
67
|
+
get path(): string;
|
|
68
|
+
/** Original URL as supplied by the user */
|
|
69
|
+
get url(): string;
|
|
70
|
+
/** Query-param-free URL */
|
|
71
|
+
get cleanUrl(): string;
|
|
72
|
+
/** SHA-256 hex digest of the canonical string */
|
|
73
|
+
get hash(): string;
|
|
74
|
+
/** Short verification code to embed in the page ("majik-slink:…") */
|
|
75
|
+
get vCode(): string;
|
|
76
|
+
get source(): SLinkSource;
|
|
77
|
+
get status(): SLinkVerificationStatus;
|
|
78
|
+
get verifiedAt(): Date | null;
|
|
79
|
+
/**
|
|
80
|
+
* Get the signature as a MajikSignature instance.
|
|
81
|
+
* The instance is cached to avoid re-parsing on every access.
|
|
82
|
+
*/
|
|
83
|
+
get signature(): MajikSignature;
|
|
84
|
+
/**
|
|
85
|
+
* Get the raw signature JSON.
|
|
86
|
+
* Useful when you need the serializable form without parsing.
|
|
87
|
+
*/
|
|
88
|
+
get signatureJSON(): MajikSignatureJSON;
|
|
89
|
+
get timestamp(): Date;
|
|
90
|
+
/** True when a successful scrape + signature verification has been recorded */
|
|
91
|
+
get isVerified(): boolean;
|
|
92
|
+
/** The OTP-display chunks (groups of 4 hex chars from the hash) */
|
|
93
|
+
get codeChunks(): string[];
|
|
94
|
+
/**
|
|
95
|
+
* Create and sign a new MajikSLink.
|
|
96
|
+
*
|
|
97
|
+
* @param rawUrl The public URL to sign. Query params and fragments are
|
|
98
|
+
* stripped before signing — identical resources with different
|
|
99
|
+
* params will always produce the same hash / v_code.
|
|
100
|
+
* @param key An unlocked MajikKey with signing keys present.
|
|
101
|
+
* @param userId The ID of the user who owns this SLink.
|
|
102
|
+
* @param options Optional overrides (id, timestamp, status).
|
|
103
|
+
*
|
|
104
|
+
* @throws {MajikSLinkValidationError} for bad inputs.
|
|
105
|
+
* @throws {MajikSLinkSigningError} when the key is locked or lacks signing keys.
|
|
106
|
+
* @throws {MajikSLinkError} for unexpected failures.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const slink = await MajikSLink.create(
|
|
110
|
+
* "https://youtube.com/watch?v=dQw4w9WgXcQ",
|
|
111
|
+
* unlockedKey,
|
|
112
|
+
* user.id,
|
|
113
|
+
* );
|
|
114
|
+
* console.log(slink.vCode); // "majik-slink:a1b2c3d4…"
|
|
115
|
+
*/
|
|
116
|
+
static create(rawUrl: string, key: MajikKey, userId: string, options?: {
|
|
117
|
+
id?: string;
|
|
118
|
+
timestamp?: Date;
|
|
119
|
+
status?: SLinkVerificationStatus;
|
|
120
|
+
}): Promise<MajikSLink>;
|
|
121
|
+
/**
|
|
122
|
+
* Derive the verification code and URL info for a raw URL *without* signing.
|
|
123
|
+
*
|
|
124
|
+
* Use this in the UI to show the challenge code to the user before they
|
|
125
|
+
* confirm and trigger the full `create()` flow.
|
|
126
|
+
*
|
|
127
|
+
* Returns null when the URL cannot be parsed (shows inline as a validation
|
|
128
|
+
* error rather than throwing, for convenient use in onChange handlers).
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const preview = await MajikSLink.generateChallenge(url);
|
|
132
|
+
* if (preview) setChallenge(preview.v_code);
|
|
133
|
+
*/
|
|
134
|
+
static generateChallenge(rawUrl: string): Promise<SLinkCodePreview | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Verify the embedded MajikSignature of a persisted MajikSLink.
|
|
137
|
+
*
|
|
138
|
+
* This does NOT scrape the target page — it only cryptographically checks
|
|
139
|
+
* that the signature covers the canonical URL and was issued by the stated
|
|
140
|
+
* signer.
|
|
141
|
+
*
|
|
142
|
+
* Use in conjunction with your scraper to fully verify ownership:
|
|
143
|
+
* 1. Scrape the page and confirm `v_code` is present.
|
|
144
|
+
* 2. Call `verifySignature()` to confirm the cryptographic provenance.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const result = MajikSLink.verifySignature(slink, signerPublicKeys);
|
|
148
|
+
* if (!result.valid) console.warn("Signature tampered:", result.reason);
|
|
149
|
+
*/
|
|
150
|
+
static verifySignature(slink: MajikSLink | MajikSLinkJSON, publicKeys: Parameters<typeof MajikSignature.verify>[2]): ReturnType<typeof MajikSignature.verify>;
|
|
151
|
+
/**
|
|
152
|
+
* Verify this SLink's embedded signature against the provided public keys.
|
|
153
|
+
*
|
|
154
|
+
* This validates that:
|
|
155
|
+
* 1. The signature cryptographically matches the canonical URL
|
|
156
|
+
* 2. The signature was created by the holder of the private key
|
|
157
|
+
*
|
|
158
|
+
* Note: This does NOT scrape the page. Use with `markVerified()` after
|
|
159
|
+
* a successful scrape to complete the verification flow.
|
|
160
|
+
*
|
|
161
|
+
* @param publicKeys The signer's public keys (classic Ed25519 + ML-DSA-87)
|
|
162
|
+
* @returns Verification result with valid/invalid status and optional reason
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // After scraping and finding v_code on the page:
|
|
166
|
+
* const result = slink.verify(user.publicKeys);
|
|
167
|
+
* if (result.valid) {
|
|
168
|
+
* slink.markVerified();
|
|
169
|
+
* await db.save(slink);
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
verify(publicKeys?: Parameters<typeof MajikSignature.verify>[2]): ReturnType<typeof MajikSignature.verify>;
|
|
173
|
+
/**
|
|
174
|
+
* Record a successful scrape verification.
|
|
175
|
+
* Should be called by your server route after a positive scrape result.
|
|
176
|
+
*/
|
|
177
|
+
markVerified(): this;
|
|
178
|
+
/**
|
|
179
|
+
* Record a failed scrape (challenge not found on page).
|
|
180
|
+
*/
|
|
181
|
+
markFailed(): this;
|
|
182
|
+
/**
|
|
183
|
+
* Record that the scrape found the code but the signature did not verify.
|
|
184
|
+
*/
|
|
185
|
+
markSignatureInvalid(): this;
|
|
186
|
+
/**
|
|
187
|
+
* Mark the SLink as pending verification (scrape in progress).
|
|
188
|
+
*/
|
|
189
|
+
markPending(): this;
|
|
190
|
+
/**
|
|
191
|
+
* Re-parse and return structured URL info from this SLink's clean URL.
|
|
192
|
+
* Useful when you need the UrlInfo object on a rehydrated instance.
|
|
193
|
+
*/
|
|
194
|
+
parseUrlInfo(): UrlInfo | null;
|
|
195
|
+
/**
|
|
196
|
+
* Returns true if two SLink instances (or a raw URL + this SLink) refer
|
|
197
|
+
* to the same normalised resource — i.e. they share the same hash.
|
|
198
|
+
*
|
|
199
|
+
* Returns null if the comparison URL cannot be parsed (indicates invalid URL).
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* slink.isSameResource(otherSlink); // true/false
|
|
203
|
+
* slink.isSameResource("https://youtube.com/watch?v=abc"); // true/false/null
|
|
204
|
+
*/
|
|
205
|
+
isSameResource(other: MajikSLink | string): boolean | null;
|
|
206
|
+
toJSON(): MajikSLinkJSON;
|
|
207
|
+
/**
|
|
208
|
+
* Rehydrate a MajikSLink from a plain JSON object (e.g. from a database row).
|
|
209
|
+
* Does NOT re-verify the signature — call `verify()` explicitly.
|
|
210
|
+
*
|
|
211
|
+
* @throws {MajikSLinkSerializationError} if any required field is missing or malformed.
|
|
212
|
+
*/
|
|
213
|
+
static fromJSON(raw: unknown): MajikSLink;
|
|
214
|
+
/**
|
|
215
|
+
* Serialize to a base64 string for embedding in URLs, QR codes, etc.
|
|
216
|
+
*/
|
|
217
|
+
serialize(): string;
|
|
218
|
+
/**
|
|
219
|
+
* Deserialize a MajikSLink from a base64 string produced by `serialize()`.
|
|
220
|
+
*/
|
|
221
|
+
static deserialize(base64: string): MajikSLink;
|
|
222
|
+
toString(): string;
|
|
223
|
+
/**
|
|
224
|
+
* Human-readable summary — useful for logging and dev tools.
|
|
225
|
+
*/
|
|
226
|
+
toSummary(): string;
|
|
227
|
+
}
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* majik-slink.ts
|
|
3
|
+
*/
|
|
4
|
+
import { base64ToBytes, MajikSignature, } from "@majikah/majik-signature";
|
|
5
|
+
import { MajikSLinkError, MajikSLinkSerializationError, MajikSLinkSigningError, MajikSLinkValidationError, } from "./core/errors";
|
|
6
|
+
import { CODE_HEX_LENGTH, CODE_PREFIX, SLINK_VERSION } from "./core/constants";
|
|
7
|
+
import { assertMajikKey, assertNonEmptyString, assertUnlockedKey, assertValidHttpUrl, buildCanonical, detectSource, generateId, parseUrlInfo, sha256Hex, } from "./core/utils";
|
|
8
|
+
// ─── MajikSLink ───────────────────────────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* MajikSLink
|
|
11
|
+
* ---------------------
|
|
12
|
+
* MajikSLink — URL ownership signing and verification.
|
|
13
|
+
* A MajikSLink proves that the holder of a MajikKey owns (or controls) a
|
|
14
|
+
* publicly-accessible URL by:
|
|
15
|
+
*
|
|
16
|
+
* 1. Normalising the URL to a canonical form (scheme + subdomain + domain +
|
|
17
|
+
* tld + path, no query string, no fragment, no trailing slash).
|
|
18
|
+
* 2. Deriving a short, deterministic verification code from a SHA-256 digest
|
|
19
|
+
* of the canonical URL parts — so the same resource always produces the
|
|
20
|
+
* same code regardless of query params or tracking tokens.
|
|
21
|
+
* 3. Signing the canonical URL string with the owner's MajikKey via
|
|
22
|
+
* MajikSignature (Ed25519 + ML-DSA-87 hybrid).
|
|
23
|
+
*
|
|
24
|
+
* The owner embeds the verification code (`v_code`) anywhere in the public
|
|
25
|
+
* page (description, bio, comment, HTML body) and a scraper verifies its
|
|
26
|
+
* presence. Once found, the MajikSignature certifies the association between
|
|
27
|
+
* the signer's identity and the URL.
|
|
28
|
+
*
|
|
29
|
+
* Canonical URL format (what is signed):
|
|
30
|
+
* "majik-slink-v1:<subdomain>::<sld>::<tld>::<path>"
|
|
31
|
+
* e.g. "majik-slink-v1:www::youtube::com::/watch/dQw4w9WgXcQ"
|
|
32
|
+
*
|
|
33
|
+
* Verification code format:
|
|
34
|
+
* "majik-slink:<first 32 hex chars of SHA-256(canonical)>"
|
|
35
|
+
* e.g. "majik-slink:a1b2c3d4e5f6..."
|
|
36
|
+
*/
|
|
37
|
+
export class MajikSLink {
|
|
38
|
+
_version;
|
|
39
|
+
_id;
|
|
40
|
+
_user_id;
|
|
41
|
+
// URL parts (normalised)
|
|
42
|
+
_domain; // "youtube.com"
|
|
43
|
+
_sld; // "youtube"
|
|
44
|
+
_tld; // "com"
|
|
45
|
+
_subdomain;
|
|
46
|
+
_path;
|
|
47
|
+
_url; // original input URL
|
|
48
|
+
_clean_url; // stripped clean URL
|
|
49
|
+
_hash; // SHA-256 hex of canonical
|
|
50
|
+
_v_code; // "majik-slink:<hash[:32]>"
|
|
51
|
+
_source;
|
|
52
|
+
_status;
|
|
53
|
+
_verified_at;
|
|
54
|
+
_signature;
|
|
55
|
+
_signatureInstance = null; // Cached instance
|
|
56
|
+
_timestamp;
|
|
57
|
+
// ── Private constructor — use MajikSLink.create() ────────────────────────
|
|
58
|
+
constructor(data) {
|
|
59
|
+
this._version = data.version;
|
|
60
|
+
this._id = data.id;
|
|
61
|
+
this._user_id = data.user_id;
|
|
62
|
+
this._domain = data.domain;
|
|
63
|
+
this._sld = data.sld;
|
|
64
|
+
this._tld = data.tld;
|
|
65
|
+
this._subdomain = data.subdomain;
|
|
66
|
+
this._path = data.path;
|
|
67
|
+
this._url = data.url;
|
|
68
|
+
this._clean_url = data.clean_url;
|
|
69
|
+
this._hash = data.hash;
|
|
70
|
+
this._v_code = data.v_code;
|
|
71
|
+
this._source = data.source;
|
|
72
|
+
this._status = data.status;
|
|
73
|
+
this._verified_at = data.verified_at;
|
|
74
|
+
this._signature = data.signature;
|
|
75
|
+
this._timestamp = data.timestamp;
|
|
76
|
+
}
|
|
77
|
+
// ── Getters ──────────────────────────────────────────────────────────────
|
|
78
|
+
get version() {
|
|
79
|
+
return this._version;
|
|
80
|
+
}
|
|
81
|
+
get id() {
|
|
82
|
+
return this._id;
|
|
83
|
+
}
|
|
84
|
+
get userId() {
|
|
85
|
+
return this._user_id;
|
|
86
|
+
}
|
|
87
|
+
/** Full registered domain e.g. "youtube.com" */
|
|
88
|
+
get domain() {
|
|
89
|
+
return this._domain;
|
|
90
|
+
}
|
|
91
|
+
/** Second-level domain e.g. "youtube" */
|
|
92
|
+
get sld() {
|
|
93
|
+
return this._sld;
|
|
94
|
+
}
|
|
95
|
+
/** Top-level domain e.g. "com" */
|
|
96
|
+
get tld() {
|
|
97
|
+
return this._tld;
|
|
98
|
+
}
|
|
99
|
+
/** Subdomain or null e.g. "www" */
|
|
100
|
+
get subdomain() {
|
|
101
|
+
return this._subdomain;
|
|
102
|
+
}
|
|
103
|
+
/** Normalised path */
|
|
104
|
+
get path() {
|
|
105
|
+
return this._path;
|
|
106
|
+
}
|
|
107
|
+
/** Original URL as supplied by the user */
|
|
108
|
+
get url() {
|
|
109
|
+
return this._url;
|
|
110
|
+
}
|
|
111
|
+
/** Query-param-free URL */
|
|
112
|
+
get cleanUrl() {
|
|
113
|
+
return this._clean_url;
|
|
114
|
+
}
|
|
115
|
+
/** SHA-256 hex digest of the canonical string */
|
|
116
|
+
get hash() {
|
|
117
|
+
return this._hash;
|
|
118
|
+
}
|
|
119
|
+
/** Short verification code to embed in the page ("majik-slink:…") */
|
|
120
|
+
get vCode() {
|
|
121
|
+
return this._v_code;
|
|
122
|
+
}
|
|
123
|
+
get source() {
|
|
124
|
+
return this._source;
|
|
125
|
+
}
|
|
126
|
+
get status() {
|
|
127
|
+
return this._status;
|
|
128
|
+
}
|
|
129
|
+
get verifiedAt() {
|
|
130
|
+
return this._verified_at;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get the signature as a MajikSignature instance.
|
|
134
|
+
* The instance is cached to avoid re-parsing on every access.
|
|
135
|
+
*/
|
|
136
|
+
get signature() {
|
|
137
|
+
if (!this._signatureInstance) {
|
|
138
|
+
this._signatureInstance = MajikSignature.fromJSON(this._signature);
|
|
139
|
+
}
|
|
140
|
+
return this._signatureInstance;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the raw signature JSON.
|
|
144
|
+
* Useful when you need the serializable form without parsing.
|
|
145
|
+
*/
|
|
146
|
+
get signatureJSON() {
|
|
147
|
+
return this._signature;
|
|
148
|
+
}
|
|
149
|
+
get timestamp() {
|
|
150
|
+
return this._timestamp;
|
|
151
|
+
}
|
|
152
|
+
/** True when a successful scrape + signature verification has been recorded */
|
|
153
|
+
get isVerified() {
|
|
154
|
+
return this._status === "verified";
|
|
155
|
+
}
|
|
156
|
+
/** The OTP-display chunks (groups of 4 hex chars from the hash) */
|
|
157
|
+
get codeChunks() {
|
|
158
|
+
const hex = this._hash.slice(0, CODE_HEX_LENGTH);
|
|
159
|
+
const chunks = [];
|
|
160
|
+
for (let i = 0; i < hex.length; i += 4) {
|
|
161
|
+
chunks.push(hex.slice(i, i + 4));
|
|
162
|
+
}
|
|
163
|
+
return chunks;
|
|
164
|
+
}
|
|
165
|
+
// ── Static: create ────────────────────────────────────────────────────────
|
|
166
|
+
/**
|
|
167
|
+
* Create and sign a new MajikSLink.
|
|
168
|
+
*
|
|
169
|
+
* @param rawUrl The public URL to sign. Query params and fragments are
|
|
170
|
+
* stripped before signing — identical resources with different
|
|
171
|
+
* params will always produce the same hash / v_code.
|
|
172
|
+
* @param key An unlocked MajikKey with signing keys present.
|
|
173
|
+
* @param userId The ID of the user who owns this SLink.
|
|
174
|
+
* @param options Optional overrides (id, timestamp, status).
|
|
175
|
+
*
|
|
176
|
+
* @throws {MajikSLinkValidationError} for bad inputs.
|
|
177
|
+
* @throws {MajikSLinkSigningError} when the key is locked or lacks signing keys.
|
|
178
|
+
* @throws {MajikSLinkError} for unexpected failures.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const slink = await MajikSLink.create(
|
|
182
|
+
* "https://youtube.com/watch?v=dQw4w9WgXcQ",
|
|
183
|
+
* unlockedKey,
|
|
184
|
+
* user.id,
|
|
185
|
+
* );
|
|
186
|
+
* console.log(slink.vCode); // "majik-slink:a1b2c3d4…"
|
|
187
|
+
*/
|
|
188
|
+
static async create(rawUrl, key, userId, options) {
|
|
189
|
+
// ── Validate inputs ──────────────────────────────────────────────────
|
|
190
|
+
assertNonEmptyString(rawUrl, "url");
|
|
191
|
+
assertNonEmptyString(userId, "userId");
|
|
192
|
+
assertMajikKey(key);
|
|
193
|
+
assertUnlockedKey(key);
|
|
194
|
+
assertValidHttpUrl(rawUrl);
|
|
195
|
+
const urlInfo = parseUrlInfo(rawUrl);
|
|
196
|
+
if (!urlInfo) {
|
|
197
|
+
throw new MajikSLinkValidationError(`Could not parse URL into a valid domain: "${rawUrl}". Ensure it is a public https:// URL.`);
|
|
198
|
+
}
|
|
199
|
+
// ── Hash the canonical string ────────────────────────────────────────
|
|
200
|
+
const hash = await sha256Hex(urlInfo.canonical);
|
|
201
|
+
const v_code = `${CODE_PREFIX}${hash.slice(0, CODE_HEX_LENGTH)}`;
|
|
202
|
+
// ── Sign with MajikSignature ─────────────────────────────────────────
|
|
203
|
+
let signature;
|
|
204
|
+
try {
|
|
205
|
+
signature = await MajikSignature.sign(urlInfo.canonical, // what we're signing
|
|
206
|
+
key, {
|
|
207
|
+
contentType: "majik-slink/url",
|
|
208
|
+
timestamp: (options?.timestamp ?? new Date()).toISOString(),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
throw new MajikSLinkSigningError("Failed to sign the SLink canonical URL.", err);
|
|
213
|
+
}
|
|
214
|
+
return new MajikSLink({
|
|
215
|
+
version: SLINK_VERSION,
|
|
216
|
+
id: options?.id ?? generateId(),
|
|
217
|
+
user_id: userId,
|
|
218
|
+
domain: urlInfo.domain,
|
|
219
|
+
sld: urlInfo.sld,
|
|
220
|
+
tld: urlInfo.tld,
|
|
221
|
+
subdomain: urlInfo.subdomain,
|
|
222
|
+
path: urlInfo.path,
|
|
223
|
+
url: rawUrl,
|
|
224
|
+
clean_url: urlInfo.cleanUrl,
|
|
225
|
+
hash,
|
|
226
|
+
v_code,
|
|
227
|
+
source: detectSource(urlInfo.sld),
|
|
228
|
+
status: options?.status ?? "unverified",
|
|
229
|
+
verified_at: null,
|
|
230
|
+
signature: signature.toJSON(),
|
|
231
|
+
timestamp: options?.timestamp ?? new Date(),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
// ── Static: generateChallenge ─────────────────────────────────────────────
|
|
235
|
+
/**
|
|
236
|
+
* Derive the verification code and URL info for a raw URL *without* signing.
|
|
237
|
+
*
|
|
238
|
+
* Use this in the UI to show the challenge code to the user before they
|
|
239
|
+
* confirm and trigger the full `create()` flow.
|
|
240
|
+
*
|
|
241
|
+
* Returns null when the URL cannot be parsed (shows inline as a validation
|
|
242
|
+
* error rather than throwing, for convenient use in onChange handlers).
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* const preview = await MajikSLink.generateChallenge(url);
|
|
246
|
+
* if (preview) setChallenge(preview.v_code);
|
|
247
|
+
*/
|
|
248
|
+
static async generateChallenge(rawUrl) {
|
|
249
|
+
try {
|
|
250
|
+
assertValidHttpUrl(rawUrl);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const urlInfo = parseUrlInfo(rawUrl);
|
|
256
|
+
if (!urlInfo)
|
|
257
|
+
return null;
|
|
258
|
+
const hash = await sha256Hex(urlInfo.canonical);
|
|
259
|
+
const v_code = `${CODE_PREFIX}${hash.slice(0, CODE_HEX_LENGTH)}`;
|
|
260
|
+
return { v_code, hash, cleanUrl: urlInfo.cleanUrl, urlInfo };
|
|
261
|
+
}
|
|
262
|
+
// ── Static: verifySignature ───────────────────────────────────────────────
|
|
263
|
+
/**
|
|
264
|
+
* Verify the embedded MajikSignature of a persisted MajikSLink.
|
|
265
|
+
*
|
|
266
|
+
* This does NOT scrape the target page — it only cryptographically checks
|
|
267
|
+
* that the signature covers the canonical URL and was issued by the stated
|
|
268
|
+
* signer.
|
|
269
|
+
*
|
|
270
|
+
* Use in conjunction with your scraper to fully verify ownership:
|
|
271
|
+
* 1. Scrape the page and confirm `v_code` is present.
|
|
272
|
+
* 2. Call `verifySignature()` to confirm the cryptographic provenance.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const result = MajikSLink.verifySignature(slink, signerPublicKeys);
|
|
276
|
+
* if (!result.valid) console.warn("Signature tampered:", result.reason);
|
|
277
|
+
*/
|
|
278
|
+
static verifySignature(slink, publicKeys) {
|
|
279
|
+
const json = slink instanceof MajikSLink ? slink.toJSON() : slink;
|
|
280
|
+
// Reconstruct the canonical string from stored parts
|
|
281
|
+
// We need to extract sld and tld from the domain field
|
|
282
|
+
const parts = json.domain.split(".");
|
|
283
|
+
const tld = parts[parts.length - 1] ?? "";
|
|
284
|
+
const sld = parts.slice(0, -1).join(".") || json.domain;
|
|
285
|
+
const canonical = buildCanonical(json.subdomain, sld, tld, json.path);
|
|
286
|
+
return MajikSignature.verify(canonical, json.signature, publicKeys);
|
|
287
|
+
}
|
|
288
|
+
// ── Instance: verify ──────────────────────────────────────────────────────
|
|
289
|
+
/**
|
|
290
|
+
* Verify this SLink's embedded signature against the provided public keys.
|
|
291
|
+
*
|
|
292
|
+
* This validates that:
|
|
293
|
+
* 1. The signature cryptographically matches the canonical URL
|
|
294
|
+
* 2. The signature was created by the holder of the private key
|
|
295
|
+
*
|
|
296
|
+
* Note: This does NOT scrape the page. Use with `markVerified()` after
|
|
297
|
+
* a successful scrape to complete the verification flow.
|
|
298
|
+
*
|
|
299
|
+
* @param publicKeys The signer's public keys (classic Ed25519 + ML-DSA-87)
|
|
300
|
+
* @returns Verification result with valid/invalid status and optional reason
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* // After scraping and finding v_code on the page:
|
|
304
|
+
* const result = slink.verify(user.publicKeys);
|
|
305
|
+
* if (result.valid) {
|
|
306
|
+
* slink.markVerified();
|
|
307
|
+
* await db.save(slink);
|
|
308
|
+
* }
|
|
309
|
+
*/
|
|
310
|
+
verify(publicKeys) {
|
|
311
|
+
const signerKeys = {
|
|
312
|
+
edPublicKey: publicKeys?.edPublicKey ||
|
|
313
|
+
base64ToBytes(this.signature.signerEdPublicKey),
|
|
314
|
+
mlDsaPublicKey: publicKeys?.mlDsaPublicKey ||
|
|
315
|
+
base64ToBytes(this.signature.signerMlDsaPublicKey),
|
|
316
|
+
signerId: publicKeys?.signerId || this.signature.signerId,
|
|
317
|
+
};
|
|
318
|
+
// Rebuild canonical string from stored parts
|
|
319
|
+
const canonical = buildCanonical(this._subdomain, this._sld, this._tld, this._path);
|
|
320
|
+
this.signature.validate();
|
|
321
|
+
// Verify the signature against the canonical URL
|
|
322
|
+
return MajikSignature.verify(canonical, this._signature, signerKeys);
|
|
323
|
+
}
|
|
324
|
+
// ── Status mutation ───────────────────────────────────────────────────────
|
|
325
|
+
/**
|
|
326
|
+
* Record a successful scrape verification.
|
|
327
|
+
* Should be called by your server route after a positive scrape result.
|
|
328
|
+
*/
|
|
329
|
+
markVerified() {
|
|
330
|
+
this._status = "verified";
|
|
331
|
+
this._verified_at = new Date();
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Record a failed scrape (challenge not found on page).
|
|
336
|
+
*/
|
|
337
|
+
markFailed() {
|
|
338
|
+
this._status = "failed";
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Record that the scrape found the code but the signature did not verify.
|
|
343
|
+
*/
|
|
344
|
+
markSignatureInvalid() {
|
|
345
|
+
this._status = "sig_invalid";
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Mark the SLink as pending verification (scrape in progress).
|
|
350
|
+
*/
|
|
351
|
+
markPending() {
|
|
352
|
+
this._status = "pending";
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
// ── URL utilities ─────────────────────────────────────────────────────────
|
|
356
|
+
/**
|
|
357
|
+
* Re-parse and return structured URL info from this SLink's clean URL.
|
|
358
|
+
* Useful when you need the UrlInfo object on a rehydrated instance.
|
|
359
|
+
*/
|
|
360
|
+
parseUrlInfo() {
|
|
361
|
+
return parseUrlInfo(this._clean_url);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Returns true if two SLink instances (or a raw URL + this SLink) refer
|
|
365
|
+
* to the same normalised resource — i.e. they share the same hash.
|
|
366
|
+
*
|
|
367
|
+
* Returns null if the comparison URL cannot be parsed (indicates invalid URL).
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* slink.isSameResource(otherSlink); // true/false
|
|
371
|
+
* slink.isSameResource("https://youtube.com/watch?v=abc"); // true/false/null
|
|
372
|
+
*/
|
|
373
|
+
isSameResource(other) {
|
|
374
|
+
if (typeof other === "string") {
|
|
375
|
+
const info = parseUrlInfo(other);
|
|
376
|
+
if (!info)
|
|
377
|
+
return null; // Indicates parse error
|
|
378
|
+
// Compare canonical strings
|
|
379
|
+
const canonical = buildCanonical(info.subdomain, info.sld, info.tld, info.path);
|
|
380
|
+
const thisCanonical = buildCanonical(this._subdomain, this._sld, this._tld, this._path);
|
|
381
|
+
return canonical === thisCanonical;
|
|
382
|
+
}
|
|
383
|
+
return this._hash === other._hash;
|
|
384
|
+
}
|
|
385
|
+
// ── Serialisation ─────────────────────────────────────────────────────────
|
|
386
|
+
toJSON() {
|
|
387
|
+
return {
|
|
388
|
+
version: this._version,
|
|
389
|
+
id: this._id,
|
|
390
|
+
user_id: this._user_id,
|
|
391
|
+
domain: this._domain,
|
|
392
|
+
subdomain: this._subdomain,
|
|
393
|
+
path: this._path,
|
|
394
|
+
url: this._url,
|
|
395
|
+
hash: this._hash,
|
|
396
|
+
v_code: this._v_code,
|
|
397
|
+
source: this._source,
|
|
398
|
+
status: this._status,
|
|
399
|
+
timestamp: this._timestamp.toISOString(),
|
|
400
|
+
verified_at: this._verified_at?.toISOString() ?? null,
|
|
401
|
+
signature: this._signature,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Rehydrate a MajikSLink from a plain JSON object (e.g. from a database row).
|
|
406
|
+
* Does NOT re-verify the signature — call `verify()` explicitly.
|
|
407
|
+
*
|
|
408
|
+
* @throws {MajikSLinkSerializationError} if any required field is missing or malformed.
|
|
409
|
+
*/
|
|
410
|
+
static fromJSON(raw) {
|
|
411
|
+
try {
|
|
412
|
+
const json = raw;
|
|
413
|
+
// Required field assertions
|
|
414
|
+
assertNonEmptyString(json?.id, "id");
|
|
415
|
+
assertNonEmptyString(json?.user_id, "user_id");
|
|
416
|
+
assertNonEmptyString(json?.domain, "domain");
|
|
417
|
+
assertNonEmptyString(json?.path, "path");
|
|
418
|
+
assertNonEmptyString(json?.url, "url");
|
|
419
|
+
assertNonEmptyString(json?.hash, "hash");
|
|
420
|
+
assertNonEmptyString(json?.v_code, "v_code");
|
|
421
|
+
assertNonEmptyString(json?.source, "source");
|
|
422
|
+
assertNonEmptyString(json?.status, "status");
|
|
423
|
+
assertNonEmptyString(json?.timestamp, "timestamp");
|
|
424
|
+
if (!json?.signature || typeof json.signature !== "object") {
|
|
425
|
+
throw new MajikSLinkSerializationError('"signature" must be a MajikSignatureJSON object.');
|
|
426
|
+
}
|
|
427
|
+
// Derive sld / tld from stored domain ("youtube.com" → "youtube", "com")
|
|
428
|
+
// Note: This is a simplified approach. For production use with multi-part
|
|
429
|
+
// TLDs (.co.uk, .github.io), consider storing sld and tld separately in JSON
|
|
430
|
+
// or using a proper public suffix list parser.
|
|
431
|
+
const parts = json.domain.split(".");
|
|
432
|
+
const tld = parts[parts.length - 1] ?? "";
|
|
433
|
+
const sld = parts.slice(0, -1).join(".") || json.domain;
|
|
434
|
+
// Reconstruct clean_url from stored parts
|
|
435
|
+
// The original URL might have had query params, but clean_url never does
|
|
436
|
+
const protocol = json.url.startsWith("https://") ? "https://" : "http://";
|
|
437
|
+
const subdomainPart = json.subdomain ? `${json.subdomain}.` : "";
|
|
438
|
+
const clean_url = `${protocol}${subdomainPart}${json.domain}${json.path}`;
|
|
439
|
+
return new MajikSLink({
|
|
440
|
+
version: SLINK_VERSION,
|
|
441
|
+
id: json.id,
|
|
442
|
+
user_id: json.user_id,
|
|
443
|
+
domain: json.domain,
|
|
444
|
+
sld,
|
|
445
|
+
tld,
|
|
446
|
+
subdomain: json.subdomain ?? null,
|
|
447
|
+
path: json.path,
|
|
448
|
+
url: json.url,
|
|
449
|
+
clean_url,
|
|
450
|
+
hash: json.hash,
|
|
451
|
+
v_code: json.v_code,
|
|
452
|
+
source: json.source,
|
|
453
|
+
status: json.status,
|
|
454
|
+
verified_at: json.verified_at ? new Date(json.verified_at) : null,
|
|
455
|
+
signature: json.signature,
|
|
456
|
+
timestamp: new Date(json.timestamp),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
if (err instanceof MajikSLinkError)
|
|
461
|
+
throw err;
|
|
462
|
+
throw new MajikSLinkSerializationError("Failed to deserialize MajikSLink from JSON.", err);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Serialize to a base64 string for embedding in URLs, QR codes, etc.
|
|
467
|
+
*/
|
|
468
|
+
serialize() {
|
|
469
|
+
try {
|
|
470
|
+
const bytes = new TextEncoder().encode(JSON.stringify(this.toJSON()));
|
|
471
|
+
let binary = "";
|
|
472
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
473
|
+
binary += String.fromCharCode(bytes[i]);
|
|
474
|
+
}
|
|
475
|
+
return btoa(binary);
|
|
476
|
+
}
|
|
477
|
+
catch (err) {
|
|
478
|
+
throw new MajikSLinkSerializationError("Failed to serialize MajikSLink.", err);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Deserialize a MajikSLink from a base64 string produced by `serialize()`.
|
|
483
|
+
*/
|
|
484
|
+
static deserialize(base64) {
|
|
485
|
+
try {
|
|
486
|
+
assertNonEmptyString(base64, "base64");
|
|
487
|
+
const binary = atob(base64);
|
|
488
|
+
const bytes = new Uint8Array(binary.length);
|
|
489
|
+
for (let i = 0; i < binary.length; i++)
|
|
490
|
+
bytes[i] = binary.charCodeAt(i);
|
|
491
|
+
return MajikSLink.fromJSON(JSON.parse(new TextDecoder().decode(bytes)));
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
if (err instanceof MajikSLinkError)
|
|
495
|
+
throw err;
|
|
496
|
+
throw new MajikSLinkSerializationError("Failed to deserialize MajikSLink from base64.", err);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
toString() {
|
|
500
|
+
return this.serialize();
|
|
501
|
+
}
|
|
502
|
+
// ── Debug / display helpers ────────────────────────────────────────────────
|
|
503
|
+
/**
|
|
504
|
+
* Human-readable summary — useful for logging and dev tools.
|
|
505
|
+
*/
|
|
506
|
+
toSummary() {
|
|
507
|
+
return [
|
|
508
|
+
`MajikSLink v${this._version}`,
|
|
509
|
+
` id: ${this._id}`,
|
|
510
|
+
` user: ${this._user_id}`,
|
|
511
|
+
` url: ${this._clean_url}`,
|
|
512
|
+
` v_code: ${this._v_code}`,
|
|
513
|
+
` status: ${this._status}`,
|
|
514
|
+
` source: ${this._source}`,
|
|
515
|
+
` signed: ${this._timestamp.toISOString()}`,
|
|
516
|
+
` verified: ${this._verified_at?.toISOString() ?? "—"}`,
|
|
517
|
+
].join("\n");
|
|
518
|
+
}
|
|
519
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@majikah/majik-slink",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Majik SLink is a specialized TypeScript library designed for URL ownership verification and cryptographic identity linking. It provides a robust mechanism to prove that a specific digital identity (a MajikKey) controls a publicly accessible web resource (such as a YouTube channel, social media profile, or personal blog).",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Zelijah",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/Majikah/majik-slink.git"
|
|
17
|
+
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "github",
|
|
20
|
+
"url": "https://github.com/sponsors/jedlsf"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"url-verification",
|
|
24
|
+
"identity-linking",
|
|
25
|
+
"ownership-proof",
|
|
26
|
+
"cryptographic-signature",
|
|
27
|
+
"post-quantum",
|
|
28
|
+
"ml-dsa",
|
|
29
|
+
"ed25519",
|
|
30
|
+
"canonical-urls",
|
|
31
|
+
"web-identity",
|
|
32
|
+
"trustless-verification",
|
|
33
|
+
"majikah",
|
|
34
|
+
"content-authenticity",
|
|
35
|
+
"digital-provenance",
|
|
36
|
+
"hybrid-cryptography",
|
|
37
|
+
"verification-code"
|
|
38
|
+
],
|
|
39
|
+
"homepage": "https://github.com/Majikah/majik-slink#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/Majikah/majik-slink/issues"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@majikah/majik-key": "^0.2.3",
|
|
50
|
+
"@majikah/majik-signature": "^0.0.15",
|
|
51
|
+
"@types/psl": "^1.1.3",
|
|
52
|
+
"psl": "^1.15.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^25.5.0"
|
|
56
|
+
}
|
|
57
|
+
}
|