@atproto/syntax 0.2.1 → 0.3.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/CHANGELOG.md +12 -0
- package/dist/aturi.d.ts +1 -0
- package/dist/aturi.d.ts.map +1 -0
- package/dist/aturi.js +160 -0
- package/dist/aturi.js.map +1 -0
- package/dist/aturi_validation.d.ts +1 -0
- package/dist/aturi_validation.d.ts.map +1 -0
- package/dist/aturi_validation.js +120 -0
- package/dist/aturi_validation.js.map +1 -0
- package/dist/datetime.d.ts +1 -0
- package/dist/datetime.d.ts.map +1 -0
- package/dist/datetime.js +108 -0
- package/dist/datetime.js.map +1 -0
- package/dist/did.d.ts +1 -0
- package/dist/did.d.ts.map +1 -0
- package/dist/did.js +54 -0
- package/dist/did.js.map +1 -0
- package/dist/handle.d.ts +1 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +119 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -603
- package/dist/index.js.map +1 -7
- package/dist/nsid.d.ts +1 -0
- package/dist/nsid.d.ts.map +1 -0
- package/dist/nsid.js +107 -0
- package/dist/nsid.js.map +1 -0
- package/dist/recordkey.d.ts +1 -0
- package/dist/recordkey.d.ts.map +1 -0
- package/dist/recordkey.js +32 -0
- package/dist/recordkey.js.map +1 -0
- package/dist/tid.d.ts +1 -0
- package/dist/tid.d.ts.map +1 -0
- package/dist/tid.js +30 -0
- package/dist/tid.js.map +1 -0
- package/jest.config.js +3 -3
- package/package.json +7 -8
- package/src/aturi_validation.ts +4 -4
- package/src/did.ts +7 -7
- package/src/handle.ts +1 -1
- package/src/nsid.ts +2 -2
- package/src/recordkey.ts +1 -1
- package/src/tid.ts +1 -1
- package/tests/aturi.test.ts +1 -1
- package/tests/datetime.test.ts +3 -3
- package/tests/did.test.ts +2 -2
- package/tests/handle.test.ts +2 -2
- package/tests/nsid.test.ts +2 -2
- package/tests/recordkey.test.ts +2 -2
- package/tests/tid.test.ts +2 -2
- package/tsconfig.build.json +6 -2
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +5 -8
- package/tsconfig.tests.json +7 -0
- package/tsconfig.tests.tsbuildinfo +1 -0
- package/babel.config.js +0 -1
- package/build.js +0 -22
package/dist/handle.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DisallowedDomainError = exports.UnsupportedDomainError = exports.ReservedHandleError = exports.InvalidHandleError = exports.isValidTld = exports.isValidHandle = exports.normalizeAndEnsureValidHandle = exports.normalizeHandle = exports.ensureValidHandleRegex = exports.ensureValidHandle = exports.DISALLOWED_TLDS = exports.INVALID_HANDLE = void 0;
|
|
4
|
+
exports.INVALID_HANDLE = 'handle.invalid';
|
|
5
|
+
// Currently these are registration-time restrictions, not protocol-level
|
|
6
|
+
// restrictions. We have a couple accounts in the wild that we need to clean up
|
|
7
|
+
// before hard-disallow.
|
|
8
|
+
// See also: https://en.wikipedia.org/wiki/Top-level_domain#Reserved_domains
|
|
9
|
+
exports.DISALLOWED_TLDS = [
|
|
10
|
+
'.local',
|
|
11
|
+
'.arpa',
|
|
12
|
+
'.invalid',
|
|
13
|
+
'.localhost',
|
|
14
|
+
'.internal',
|
|
15
|
+
'.example',
|
|
16
|
+
'.alt',
|
|
17
|
+
// policy could concievably change on ".onion" some day
|
|
18
|
+
'.onion',
|
|
19
|
+
// NOTE: .test is allowed in testing and devopment. In practical terms
|
|
20
|
+
// "should" "never" actually resolve and get registered in production
|
|
21
|
+
];
|
|
22
|
+
// Handle constraints, in English:
|
|
23
|
+
// - must be a possible domain name
|
|
24
|
+
// - RFC-1035 is commonly referenced, but has been updated. eg, RFC-3696,
|
|
25
|
+
// section 2. and RFC-3986, section 3. can now have leading numbers (eg,
|
|
26
|
+
// 4chan.org)
|
|
27
|
+
// - "labels" (sub-names) are made of ASCII letters, digits, hyphens
|
|
28
|
+
// - can not start or end with a hyphen
|
|
29
|
+
// - TLD (last component) should not start with a digit
|
|
30
|
+
// - can't end with a hyphen (can end with digit)
|
|
31
|
+
// - each segment must be between 1 and 63 characters (not including any periods)
|
|
32
|
+
// - overall length can't be more than 253 characters
|
|
33
|
+
// - separated by (ASCII) periods; does not start or end with period
|
|
34
|
+
// - case insensitive
|
|
35
|
+
// - domains (handles) are equal if they are the same lower-case
|
|
36
|
+
// - punycode allowed for internationalization
|
|
37
|
+
// - no whitespace, null bytes, joining chars, etc
|
|
38
|
+
// - does not validate whether domain or TLD exists, or is a reserved or
|
|
39
|
+
// special TLD (eg, .onion or .local)
|
|
40
|
+
// - does not validate punycode
|
|
41
|
+
const ensureValidHandle = (handle) => {
|
|
42
|
+
// check that all chars are boring ASCII
|
|
43
|
+
if (!/^[a-zA-Z0-9.-]*$/.test(handle)) {
|
|
44
|
+
throw new InvalidHandleError('Disallowed characters in handle (ASCII letters, digits, dashes, periods only)');
|
|
45
|
+
}
|
|
46
|
+
if (handle.length > 253) {
|
|
47
|
+
throw new InvalidHandleError('Handle is too long (253 chars max)');
|
|
48
|
+
}
|
|
49
|
+
const labels = handle.split('.');
|
|
50
|
+
if (labels.length < 2) {
|
|
51
|
+
throw new InvalidHandleError('Handle domain needs at least two parts');
|
|
52
|
+
}
|
|
53
|
+
for (let i = 0; i < labels.length; i++) {
|
|
54
|
+
const l = labels[i];
|
|
55
|
+
if (l.length < 1) {
|
|
56
|
+
throw new InvalidHandleError('Handle parts can not be empty');
|
|
57
|
+
}
|
|
58
|
+
if (l.length > 63) {
|
|
59
|
+
throw new InvalidHandleError('Handle part too long (max 63 chars)');
|
|
60
|
+
}
|
|
61
|
+
if (l.endsWith('-') || l.startsWith('-')) {
|
|
62
|
+
throw new InvalidHandleError('Handle parts can not start or end with hyphens');
|
|
63
|
+
}
|
|
64
|
+
if (i + 1 === labels.length && !/^[a-zA-Z]/.test(l)) {
|
|
65
|
+
throw new InvalidHandleError('Handle final component (TLD) must start with ASCII letter');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.ensureValidHandle = ensureValidHandle;
|
|
70
|
+
// simple regex translation of above constraints
|
|
71
|
+
const ensureValidHandleRegex = (handle) => {
|
|
72
|
+
if (!/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(handle)) {
|
|
73
|
+
throw new InvalidHandleError("Handle didn't validate via regex");
|
|
74
|
+
}
|
|
75
|
+
if (handle.length > 253) {
|
|
76
|
+
throw new InvalidHandleError('Handle is too long (253 chars max)');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.ensureValidHandleRegex = ensureValidHandleRegex;
|
|
80
|
+
const normalizeHandle = (handle) => {
|
|
81
|
+
return handle.toLowerCase();
|
|
82
|
+
};
|
|
83
|
+
exports.normalizeHandle = normalizeHandle;
|
|
84
|
+
const normalizeAndEnsureValidHandle = (handle) => {
|
|
85
|
+
const normalized = (0, exports.normalizeHandle)(handle);
|
|
86
|
+
(0, exports.ensureValidHandle)(normalized);
|
|
87
|
+
return normalized;
|
|
88
|
+
};
|
|
89
|
+
exports.normalizeAndEnsureValidHandle = normalizeAndEnsureValidHandle;
|
|
90
|
+
const isValidHandle = (handle) => {
|
|
91
|
+
try {
|
|
92
|
+
(0, exports.ensureValidHandle)(handle);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
if (err instanceof InvalidHandleError) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
exports.isValidHandle = isValidHandle;
|
|
103
|
+
const isValidTld = (handle) => {
|
|
104
|
+
return !exports.DISALLOWED_TLDS.some((domain) => handle.endsWith(domain));
|
|
105
|
+
};
|
|
106
|
+
exports.isValidTld = isValidTld;
|
|
107
|
+
class InvalidHandleError extends Error {
|
|
108
|
+
}
|
|
109
|
+
exports.InvalidHandleError = InvalidHandleError;
|
|
110
|
+
class ReservedHandleError extends Error {
|
|
111
|
+
}
|
|
112
|
+
exports.ReservedHandleError = ReservedHandleError;
|
|
113
|
+
class UnsupportedDomainError extends Error {
|
|
114
|
+
}
|
|
115
|
+
exports.UnsupportedDomainError = UnsupportedDomainError;
|
|
116
|
+
class DisallowedDomainError extends Error {
|
|
117
|
+
}
|
|
118
|
+
exports.DisallowedDomainError = DisallowedDomainError;
|
|
119
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAA;AAE9C,yEAAyE;AACzE,+EAA+E;AAC/E,wBAAwB;AACxB,4EAA4E;AAC/D,QAAA,eAAe,GAAG;IAC7B,QAAQ;IACR,OAAO;IACP,UAAU;IACV,YAAY;IACZ,WAAW;IACX,UAAU;IACV,MAAM;IACN,uDAAuD;IACvD,QAAQ;IACR,sEAAsE;IACtE,qEAAqE;CACtE,CAAA;AAED,kCAAkC;AAClC,oCAAoC;AACpC,4EAA4E;AAC5E,6EAA6E;AAC7E,kBAAkB;AAClB,uEAAuE;AACvE,0CAA0C;AAC1C,0DAA0D;AAC1D,oDAAoD;AACpD,oFAAoF;AACpF,wDAAwD;AACxD,uEAAuE;AACvE,wBAAwB;AACxB,mEAAmE;AACnE,iDAAiD;AACjD,mDAAmD;AACnD,yEAAyE;AACzE,wCAAwC;AACxC,gCAAgC;AACzB,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAQ,EAAE;IACxD,wCAAwC;IACxC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,kBAAkB,CAC1B,+EAA+E,CAChF,CA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