@e280/stz 0.0.0-12 → 0.0.0-13
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/package.json +1 -1
- package/s/data/bytename/thumbprint.test.ts +19 -19
- package/s/data/bytename/thumbprint.ts +51 -25
- package/x/data/bytename/thumbprint.d.ts +14 -8
- package/x/data/bytename/thumbprint.js +39 -20
- package/x/data/bytename/thumbprint.js.map +1 -1
- package/x/data/bytename/thumbprint.test.js +19 -19
- package/x/data/bytename/thumbprint.test.js.map +1 -1
package/package.json
CHANGED
|
@@ -14,40 +14,40 @@ function good(bytes: Uint8Array) {
|
|
|
14
14
|
|
|
15
15
|
export default Science.suite({
|
|
16
16
|
"bytes->string->bytes": test(async() => {
|
|
17
|
-
const text = Thumbprint.
|
|
17
|
+
const text = Thumbprint.fromBytes(sampleBytes)
|
|
18
18
|
expect(text).is(sampleThumbprint)
|
|
19
|
-
good(Thumbprint.
|
|
19
|
+
good(Thumbprint.toBytes(text))
|
|
20
20
|
}),
|
|
21
21
|
|
|
22
22
|
"zero bytes": test(async() => {
|
|
23
|
-
const text = Thumbprint.
|
|
23
|
+
const text = Thumbprint.fromBytes(new Uint8Array([]))
|
|
24
24
|
expect(text).is("")
|
|
25
|
-
expect(Bytes.eq(Thumbprint.
|
|
25
|
+
expect(Bytes.eq(Thumbprint.toBytes(text), new Uint8Array([]))).ok()
|
|
26
26
|
}),
|
|
27
27
|
|
|
28
28
|
"one byte": test(async() => {
|
|
29
|
-
const text = Thumbprint.
|
|
29
|
+
const text = Thumbprint.fromBytes(new Uint8Array([0x00]))
|
|
30
30
|
expect(text).is("doz")
|
|
31
|
-
expect(Bytes.eq(Thumbprint.
|
|
31
|
+
expect(Bytes.eq(Thumbprint.toBytes(text), new Uint8Array([0x00]))).ok()
|
|
32
32
|
}),
|
|
33
33
|
|
|
34
34
|
"partially": Science.suite({
|
|
35
|
-
"normal": test(async() => expect(Thumbprint.
|
|
36
|
-
"nothing": test(async() => expect(Thumbprint.
|
|
37
|
-
"no-bulk": test(async() => expect(Thumbprint.
|
|
38
|
-
"one-byte": test(async() => expect(Thumbprint.
|
|
39
|
-
"three-byte": test(async() => expect(Thumbprint.
|
|
40
|
-
"one-byte-sigil": test(async() => expect(Thumbprint.
|
|
35
|
+
"normal": test(async() => expect(Thumbprint.toBytes("nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k").length).ok()),
|
|
36
|
+
"nothing": test(async() => expect(Thumbprint.toBytes("").length).is(0)),
|
|
37
|
+
"no-bulk": test(async() => expect(Thumbprint.toBytes("nodlyn.fasrep").length).ok()),
|
|
38
|
+
"one-byte": test(async() => expect(Thumbprint.toBytes("nod").length).is(1)),
|
|
39
|
+
"three-byte": test(async() => expect(Thumbprint.toBytes("nodlynfas").length).is(3)),
|
|
40
|
+
"one-byte-sigil": test(async() => expect(Thumbprint.toBytes("nod::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k").length).ok()),
|
|
41
41
|
}),
|
|
42
42
|
|
|
43
43
|
"tolerance": Science.suite({
|
|
44
|
-
"normal": test(async() => good(Thumbprint.
|
|
45
|
-
"coolio": test(async() => good(Thumbprint.
|
|
46
|
-
"spaces": test(async() => good(Thumbprint.
|
|
47
|
-
"dots": test(async() => good(Thumbprint.
|
|
48
|
-
"one-space": test(async() => good(Thumbprint.
|
|
49
|
-
"one-newline": test(async() => good(Thumbprint.
|
|
50
|
-
"whitespace": test(async() => good(Thumbprint.
|
|
44
|
+
"normal": test(async() => good(Thumbprint.toBytes("nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
45
|
+
"coolio": test(async() => good(Thumbprint.toBytes("nodlyn.fasrep..39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
46
|
+
"spaces": test(async() => good(Thumbprint.toBytes("nodlyn fasrep 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
47
|
+
"dots": test(async() => good(Thumbprint.toBytes("nodlyn.fasrep.39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
48
|
+
"one-space": test(async() => good(Thumbprint.toBytes("nodlynfasrep 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
49
|
+
"one-newline": test(async() => good(Thumbprint.toBytes("nodlynfasrep\n39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
50
|
+
"whitespace": test(async() => good(Thumbprint.toBytes("\t\n nodlyn\n fasrep \n\n\t\n 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k\n\t"))),
|
|
51
51
|
}),
|
|
52
52
|
})
|
|
53
53
|
|
|
@@ -10,17 +10,18 @@ export type ThumbprintOptions = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type ThumbprintData = {
|
|
13
|
+
bytes: Uint8Array
|
|
13
14
|
sigil: string
|
|
14
15
|
bulk: string
|
|
15
|
-
|
|
16
|
+
thumbprint: string
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
|
-
* Thumbprint is a
|
|
20
|
+
* Thumbprint is a friendly presentation format for arbitrary binary data.
|
|
20
21
|
* - looks like "nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"
|
|
21
|
-
* - the first
|
|
22
|
-
* - the rest of the data
|
|
23
|
-
* - designed to be a nice way to present 256-bit
|
|
22
|
+
* - the "sigil" is the first bytes that are shown in bytename format
|
|
23
|
+
* - the "bulk" is the rest of the data in base58
|
|
24
|
+
* - originally designed to be a nice way to present 256-bit ids
|
|
24
25
|
* - can actually represent any number of bytes
|
|
25
26
|
*/
|
|
26
27
|
export const Thumbprint = {
|
|
@@ -30,20 +31,6 @@ export const Thumbprint = {
|
|
|
30
31
|
sigilByteCount: 4,
|
|
31
32
|
}),
|
|
32
33
|
|
|
33
|
-
string(bytes: Uint8Array, options: Partial<ThumbprintOptions> = {}) {
|
|
34
|
-
const {sigilByteCount, sigilDelimiter, delimiter}
|
|
35
|
-
= {...Thumbprint.defaults, ...options}
|
|
36
|
-
|
|
37
|
-
const sigil = Bytename.string(bytes.slice(0, sigilByteCount), {
|
|
38
|
-
wordSeparator: sigilDelimiter,
|
|
39
|
-
groupSeparator: sigilDelimiter,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return (bytes.length > sigilByteCount)
|
|
43
|
-
? `${sigil}${delimiter}${Base58.string(bytes.slice(sigilByteCount))}`
|
|
44
|
-
: sigil
|
|
45
|
-
},
|
|
46
|
-
|
|
47
34
|
parse(thumbprint: string): ThumbprintData {
|
|
48
35
|
thumbprint = thumbprint.trim()
|
|
49
36
|
const parts = thumbprint.split(/[^a-zA-Z0-9]+/m)
|
|
@@ -53,7 +40,7 @@ export const Thumbprint = {
|
|
|
53
40
|
if (parts.length < 2) {
|
|
54
41
|
const sigil = parts.join(".")
|
|
55
42
|
const bytes = Bytename.bytes(sigil)
|
|
56
|
-
return {sigil, bulk: "",
|
|
43
|
+
return {bytes, sigil, bulk: "", thumbprint}
|
|
57
44
|
}
|
|
58
45
|
|
|
59
46
|
const bulk = parts.pop()!
|
|
@@ -62,19 +49,58 @@ export const Thumbprint = {
|
|
|
62
49
|
...Bytename.bytes(sigil),
|
|
63
50
|
...Base58.bytes(bulk),
|
|
64
51
|
])
|
|
65
|
-
|
|
52
|
+
|
|
53
|
+
return {bytes, sigil, bulk, thumbprint}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
build: {
|
|
57
|
+
fromBytes(bytes: Uint8Array, options: Partial<ThumbprintOptions> = {}): ThumbprintData {
|
|
58
|
+
const {sigilByteCount, sigilDelimiter, delimiter}
|
|
59
|
+
= {...Thumbprint.defaults, ...options}
|
|
60
|
+
|
|
61
|
+
const sigil = (bytes.length > 0)
|
|
62
|
+
? Bytename.string(bytes.slice(0, sigilByteCount), {
|
|
63
|
+
wordSeparator: sigilDelimiter,
|
|
64
|
+
groupSeparator: sigilDelimiter,
|
|
65
|
+
})
|
|
66
|
+
: ""
|
|
67
|
+
|
|
68
|
+
const bulk = (bytes.length > sigilByteCount)
|
|
69
|
+
? Base58.string(bytes.slice(sigilByteCount))
|
|
70
|
+
: ""
|
|
71
|
+
|
|
72
|
+
const thumbprint = [sigil, bulk]
|
|
73
|
+
.filter(s => s.length > 0)
|
|
74
|
+
.join(delimiter)
|
|
75
|
+
|
|
76
|
+
return {bytes, sigil, bulk, thumbprint}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
fromHex(hex: string, options?: Partial<ThumbprintOptions>) {
|
|
80
|
+
const bytes = Hex.bytes(hex)
|
|
81
|
+
return Thumbprint.build.fromBytes(bytes, options)
|
|
82
|
+
},
|
|
66
83
|
},
|
|
67
84
|
|
|
68
|
-
|
|
85
|
+
toBytes(thumbprint: string) {
|
|
69
86
|
return Thumbprint.parse(thumbprint).bytes
|
|
70
87
|
},
|
|
71
88
|
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
toHex(thumbprint: string) {
|
|
90
|
+
const bytes = Thumbprint.toBytes(thumbprint)
|
|
91
|
+
return Hex.string(bytes)
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
fromBytes(bytes: Uint8Array, options?: Partial<ThumbprintOptions>) {
|
|
95
|
+
return Thumbprint.build.fromBytes(bytes, options).thumbprint
|
|
74
96
|
},
|
|
75
97
|
|
|
76
98
|
fromHex(hex: string, options?: Partial<ThumbprintOptions>) {
|
|
77
|
-
return Thumbprint.
|
|
99
|
+
return Thumbprint.fromBytes(Hex.bytes(hex), options)
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
hexsigil(hex: string, options?: Partial<ThumbprintOptions>) {
|
|
103
|
+
return Thumbprint.build.fromHex(hex, options).sigil
|
|
78
104
|
},
|
|
79
105
|
}
|
|
80
106
|
|
|
@@ -4,23 +4,29 @@ export type ThumbprintOptions = {
|
|
|
4
4
|
sigilByteCount: number;
|
|
5
5
|
};
|
|
6
6
|
export type ThumbprintData = {
|
|
7
|
+
bytes: Uint8Array;
|
|
7
8
|
sigil: string;
|
|
8
9
|
bulk: string;
|
|
9
|
-
|
|
10
|
+
thumbprint: string;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
|
-
* Thumbprint is a
|
|
13
|
+
* Thumbprint is a friendly presentation format for arbitrary binary data.
|
|
13
14
|
* - looks like "nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"
|
|
14
|
-
* - the first
|
|
15
|
-
* - the rest of the data
|
|
16
|
-
* - designed to be a nice way to present 256-bit
|
|
15
|
+
* - the "sigil" is the first bytes that are shown in bytename format
|
|
16
|
+
* - the "bulk" is the rest of the data in base58
|
|
17
|
+
* - originally designed to be a nice way to present 256-bit ids
|
|
17
18
|
* - can actually represent any number of bytes
|
|
18
19
|
*/
|
|
19
20
|
export declare const Thumbprint: {
|
|
20
21
|
defaults: ThumbprintOptions;
|
|
21
|
-
string(bytes: Uint8Array, options?: Partial<ThumbprintOptions>): string;
|
|
22
22
|
parse(thumbprint: string): ThumbprintData;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
build: {
|
|
24
|
+
fromBytes(bytes: Uint8Array, options?: Partial<ThumbprintOptions>): ThumbprintData;
|
|
25
|
+
fromHex(hex: string, options?: Partial<ThumbprintOptions>): ThumbprintData;
|
|
26
|
+
};
|
|
27
|
+
toBytes(thumbprint: string): Uint8Array<ArrayBufferLike>;
|
|
28
|
+
toHex(thumbprint: string): string;
|
|
29
|
+
fromBytes(bytes: Uint8Array, options?: Partial<ThumbprintOptions>): string;
|
|
25
30
|
fromHex(hex: string, options?: Partial<ThumbprintOptions>): string;
|
|
31
|
+
hexsigil(hex: string, options?: Partial<ThumbprintOptions>): string;
|
|
26
32
|
};
|
|
@@ -2,11 +2,11 @@ import { Hex } from "../hex.js";
|
|
|
2
2
|
import { Base58 } from "../base58.js";
|
|
3
3
|
import { Bytename } from "./bytename.js";
|
|
4
4
|
/**
|
|
5
|
-
* Thumbprint is a
|
|
5
|
+
* Thumbprint is a friendly presentation format for arbitrary binary data.
|
|
6
6
|
* - looks like "nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"
|
|
7
|
-
* - the first
|
|
8
|
-
* - the rest of the data
|
|
9
|
-
* - designed to be a nice way to present 256-bit
|
|
7
|
+
* - the "sigil" is the first bytes that are shown in bytename format
|
|
8
|
+
* - the "bulk" is the rest of the data in base58
|
|
9
|
+
* - originally designed to be a nice way to present 256-bit ids
|
|
10
10
|
* - can actually represent any number of bytes
|
|
11
11
|
*/
|
|
12
12
|
export const Thumbprint = {
|
|
@@ -15,16 +15,6 @@ export const Thumbprint = {
|
|
|
15
15
|
sigilDelimiter: ".",
|
|
16
16
|
sigilByteCount: 4,
|
|
17
17
|
},
|
|
18
|
-
string(bytes, options = {}) {
|
|
19
|
-
const { sigilByteCount, sigilDelimiter, delimiter } = { ...Thumbprint.defaults, ...options };
|
|
20
|
-
const sigil = Bytename.string(bytes.slice(0, sigilByteCount), {
|
|
21
|
-
wordSeparator: sigilDelimiter,
|
|
22
|
-
groupSeparator: sigilDelimiter,
|
|
23
|
-
});
|
|
24
|
-
return (bytes.length > sigilByteCount)
|
|
25
|
-
? `${sigil}${delimiter}${Base58.string(bytes.slice(sigilByteCount))}`
|
|
26
|
-
: sigil;
|
|
27
|
-
},
|
|
28
18
|
parse(thumbprint) {
|
|
29
19
|
thumbprint = thumbprint.trim();
|
|
30
20
|
const parts = thumbprint.split(/[^a-zA-Z0-9]+/m)
|
|
@@ -33,7 +23,7 @@ export const Thumbprint = {
|
|
|
33
23
|
if (parts.length < 2) {
|
|
34
24
|
const sigil = parts.join(".");
|
|
35
25
|
const bytes = Bytename.bytes(sigil);
|
|
36
|
-
return { sigil, bulk: "",
|
|
26
|
+
return { bytes, sigil, bulk: "", thumbprint };
|
|
37
27
|
}
|
|
38
28
|
const bulk = parts.pop();
|
|
39
29
|
const sigil = parts.join(".");
|
|
@@ -41,16 +31,45 @@ export const Thumbprint = {
|
|
|
41
31
|
...Bytename.bytes(sigil),
|
|
42
32
|
...Base58.bytes(bulk),
|
|
43
33
|
]);
|
|
44
|
-
return { sigil, bulk,
|
|
34
|
+
return { bytes, sigil, bulk, thumbprint };
|
|
35
|
+
},
|
|
36
|
+
build: {
|
|
37
|
+
fromBytes(bytes, options = {}) {
|
|
38
|
+
const { sigilByteCount, sigilDelimiter, delimiter } = { ...Thumbprint.defaults, ...options };
|
|
39
|
+
const sigil = (bytes.length > 0)
|
|
40
|
+
? Bytename.string(bytes.slice(0, sigilByteCount), {
|
|
41
|
+
wordSeparator: sigilDelimiter,
|
|
42
|
+
groupSeparator: sigilDelimiter,
|
|
43
|
+
})
|
|
44
|
+
: "";
|
|
45
|
+
const bulk = (bytes.length > sigilByteCount)
|
|
46
|
+
? Base58.string(bytes.slice(sigilByteCount))
|
|
47
|
+
: "";
|
|
48
|
+
const thumbprint = [sigil, bulk]
|
|
49
|
+
.filter(s => s.length > 0)
|
|
50
|
+
.join(delimiter);
|
|
51
|
+
return { bytes, sigil, bulk, thumbprint };
|
|
52
|
+
},
|
|
53
|
+
fromHex(hex, options) {
|
|
54
|
+
const bytes = Hex.bytes(hex);
|
|
55
|
+
return Thumbprint.build.fromBytes(bytes, options);
|
|
56
|
+
},
|
|
45
57
|
},
|
|
46
|
-
|
|
58
|
+
toBytes(thumbprint) {
|
|
47
59
|
return Thumbprint.parse(thumbprint).bytes;
|
|
48
60
|
},
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
toHex(thumbprint) {
|
|
62
|
+
const bytes = Thumbprint.toBytes(thumbprint);
|
|
63
|
+
return Hex.string(bytes);
|
|
64
|
+
},
|
|
65
|
+
fromBytes(bytes, options) {
|
|
66
|
+
return Thumbprint.build.fromBytes(bytes, options).thumbprint;
|
|
51
67
|
},
|
|
52
68
|
fromHex(hex, options) {
|
|
53
|
-
return Thumbprint.
|
|
69
|
+
return Thumbprint.fromBytes(Hex.bytes(hex), options);
|
|
70
|
+
},
|
|
71
|
+
hexsigil(hex, options) {
|
|
72
|
+
return Thumbprint.build.fromHex(hex, options).sigil;
|
|
54
73
|
},
|
|
55
74
|
};
|
|
56
75
|
//# sourceMappingURL=thumbprint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thumbprint.js","sourceRoot":"","sources":["../../../s/data/bytename/thumbprint.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"thumbprint.js","sourceRoot":"","sources":["../../../s/data/bytename/thumbprint.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AAetC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,QAAQ,EAAsB;QAC7B,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,GAAG;QACnB,cAAc,EAAE,CAAC;KAChB;IAEF,KAAK,CAAC,UAAkB;QACvB,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAA;QAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC;aAC9C,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAEpB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAA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AM,GAAG,CAAC,CAAC;iBACzB,IAAI,CAAC,SAAS,CAAC,CAAA;YAEjB,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAC,CAAA;QACxC,CAAC;QAED,OAAO,CAAC,GAAW,EAAE,OAAoC;YACxD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC5B,OAAO,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;KACD;IAED,OAAO,CAAC,UAAkB;QACzB,OAAO,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,UAAkB;QACvB,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5C,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED,SAAS,CAAC,KAAiB,EAAE,OAAoC;QAChE,OAAO,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,UAAU,CAAA;IAC7D,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,OAAoC;QACxD,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC;IAED,QAAQ,CAAC,GAAW,EAAE,OAAoC;QACzD,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,KAAK,CAAA;IACpD,CAAC;CACD,CAAA"}
|
|
@@ -10,36 +10,36 @@ function good(bytes) {
|
|
|
10
10
|
}
|
|
11
11
|
export default Science.suite({
|
|
12
12
|
"bytes->string->bytes": test(async () => {
|
|
13
|
-
const text = Thumbprint.
|
|
13
|
+
const text = Thumbprint.fromBytes(sampleBytes);
|
|
14
14
|
expect(text).is(sampleThumbprint);
|
|
15
|
-
good(Thumbprint.
|
|
15
|
+
good(Thumbprint.toBytes(text));
|
|
16
16
|
}),
|
|
17
17
|
"zero bytes": test(async () => {
|
|
18
|
-
const text = Thumbprint.
|
|
18
|
+
const text = Thumbprint.fromBytes(new Uint8Array([]));
|
|
19
19
|
expect(text).is("");
|
|
20
|
-
expect(Bytes.eq(Thumbprint.
|
|
20
|
+
expect(Bytes.eq(Thumbprint.toBytes(text), new Uint8Array([]))).ok();
|
|
21
21
|
}),
|
|
22
22
|
"one byte": test(async () => {
|
|
23
|
-
const text = Thumbprint.
|
|
23
|
+
const text = Thumbprint.fromBytes(new Uint8Array([0x00]));
|
|
24
24
|
expect(text).is("doz");
|
|
25
|
-
expect(Bytes.eq(Thumbprint.
|
|
25
|
+
expect(Bytes.eq(Thumbprint.toBytes(text), new Uint8Array([0x00]))).ok();
|
|
26
26
|
}),
|
|
27
27
|
"partially": Science.suite({
|
|
28
|
-
"normal": test(async () => expect(Thumbprint.
|
|
29
|
-
"nothing": test(async () => expect(Thumbprint.
|
|
30
|
-
"no-bulk": test(async () => expect(Thumbprint.
|
|
31
|
-
"one-byte": test(async () => expect(Thumbprint.
|
|
32
|
-
"three-byte": test(async () => expect(Thumbprint.
|
|
33
|
-
"one-byte-sigil": test(async () => expect(Thumbprint.
|
|
28
|
+
"normal": test(async () => expect(Thumbprint.toBytes("nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k").length).ok()),
|
|
29
|
+
"nothing": test(async () => expect(Thumbprint.toBytes("").length).is(0)),
|
|
30
|
+
"no-bulk": test(async () => expect(Thumbprint.toBytes("nodlyn.fasrep").length).ok()),
|
|
31
|
+
"one-byte": test(async () => expect(Thumbprint.toBytes("nod").length).is(1)),
|
|
32
|
+
"three-byte": test(async () => expect(Thumbprint.toBytes("nodlynfas").length).is(3)),
|
|
33
|
+
"one-byte-sigil": test(async () => expect(Thumbprint.toBytes("nod::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k").length).ok()),
|
|
34
34
|
}),
|
|
35
35
|
"tolerance": Science.suite({
|
|
36
|
-
"normal": test(async () => good(Thumbprint.
|
|
37
|
-
"coolio": test(async () => good(Thumbprint.
|
|
38
|
-
"spaces": test(async () => good(Thumbprint.
|
|
39
|
-
"dots": test(async () => good(Thumbprint.
|
|
40
|
-
"one-space": test(async () => good(Thumbprint.
|
|
41
|
-
"one-newline": test(async () => good(Thumbprint.
|
|
42
|
-
"whitespace": test(async () => good(Thumbprint.
|
|
36
|
+
"normal": test(async () => good(Thumbprint.toBytes("nodlyn.fasrep::39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
37
|
+
"coolio": test(async () => good(Thumbprint.toBytes("nodlyn.fasrep..39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
38
|
+
"spaces": test(async () => good(Thumbprint.toBytes("nodlyn fasrep 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
39
|
+
"dots": test(async () => good(Thumbprint.toBytes("nodlyn.fasrep.39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
40
|
+
"one-space": test(async () => good(Thumbprint.toBytes("nodlynfasrep 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
41
|
+
"one-newline": test(async () => good(Thumbprint.toBytes("nodlynfasrep\n39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k"))),
|
|
42
|
+
"whitespace": test(async () => good(Thumbprint.toBytes("\t\n nodlyn\n fasrep \n\n\t\n 39gfeGFAAnBzH5pkT7EdoETMUMAekG9h1iymk6k\n\t"))),
|
|
43
43
|
}),
|
|
44
44
|
});
|
|
45
45
|
//# sourceMappingURL=thumbprint.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thumbprint.test.js","sourceRoot":"","sources":["../../../s/data/bytename/thumbprint.test.ts"],"names":[],"m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