fiftyone.pipeline.did 4.5.35 → 4.5.36
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/didClient.js +1 -1
- package/examples/fodIdExample.js +3 -1
- package/fodId.js +24 -6
- package/idType.js +2 -2
- package/package.json +1 -1
- package/tests/envelope.js +3 -3
- package/tests/fodId.test.js +17 -16
- package/types/fodId.d.ts +19 -1
- package/types/idType.d.ts +2 -2
package/didClient.js
CHANGED
|
@@ -776,7 +776,7 @@ function dateOf (fodId) {
|
|
|
776
776
|
function payloadLengthValid (fodId) {
|
|
777
777
|
const matchKeyLength = fodId.type === IdType.RANDOM
|
|
778
778
|
? FodId.GUID_LENGTH
|
|
779
|
-
: FodId.
|
|
779
|
+
: FodId.MATCH_KEY_LENGTH;
|
|
780
780
|
return fodId.payload.length >= FodId.HEADER_LENGTH + matchKeyLength;
|
|
781
781
|
}
|
|
782
782
|
|
package/examples/fodIdExample.js
CHANGED
|
@@ -50,7 +50,9 @@ function samplePayload () {
|
|
|
50
50
|
p[FodId.LICENSE_ID_OFFSET + 1] = 0x56;
|
|
51
51
|
p[FodId.LICENSE_ID_OFFSET + 2] = 0x34;
|
|
52
52
|
p[FodId.LICENSE_ID_OFFSET + 3] = 0x12;
|
|
53
|
-
for (let i = 0; i < FodId.
|
|
53
|
+
for (let i = 0; i < FodId.MATCH_KEY_LENGTH; i++) {
|
|
54
|
+
p[FodId.MATCH_KEY_OFFSET + i] = 0x20 + i;
|
|
55
|
+
}
|
|
54
56
|
return p;
|
|
55
57
|
}
|
|
56
58
|
|
package/fodId.js
CHANGED
|
@@ -88,17 +88,35 @@ class FodId {
|
|
|
88
88
|
static LICENSE_ID_OFFSET = 1;
|
|
89
89
|
static LICENSE_ID_LENGTH = 4;
|
|
90
90
|
/** Byte offset of the match key field within the payload. */
|
|
91
|
-
static
|
|
91
|
+
static MATCH_KEY_OFFSET = 5;
|
|
92
92
|
/**
|
|
93
93
|
* Byte length of the match key field for Probabilistic and HashedEmail
|
|
94
94
|
* identifiers, being a SHA-256.
|
|
95
95
|
*/
|
|
96
|
-
static
|
|
97
|
-
|
|
96
|
+
static MATCH_KEY_LENGTH = 32;
|
|
97
|
+
/**
|
|
98
|
+
* Deprecated alias for {@link FodId.MATCH_KEY_OFFSET}. The stable,
|
|
99
|
+
* comparable part of a 51Did is now called the match key, mirroring the
|
|
100
|
+
* Model Terms for Marketing vocabulary. This alias will be removed in a
|
|
101
|
+
* future release.
|
|
102
|
+
* @deprecated Renamed to MATCH_KEY_OFFSET. This alias will be removed in
|
|
103
|
+
* a future release.
|
|
104
|
+
*/
|
|
105
|
+
static HASH_OFFSET = FodId.MATCH_KEY_OFFSET;
|
|
106
|
+
/**
|
|
107
|
+
* Deprecated alias for {@link FodId.MATCH_KEY_LENGTH}. The stable,
|
|
108
|
+
* comparable part of a 51Did is now called the match key, mirroring the
|
|
109
|
+
* Model Terms for Marketing vocabulary. This alias will be removed in a
|
|
110
|
+
* future release.
|
|
111
|
+
* @deprecated Renamed to MATCH_KEY_LENGTH. This alias will be removed in
|
|
112
|
+
* a future release.
|
|
113
|
+
*/
|
|
114
|
+
static HASH_LENGTH = FodId.MATCH_KEY_LENGTH;
|
|
115
|
+
static HEADER_LENGTH = FodId.MATCH_KEY_OFFSET;
|
|
98
116
|
/** Byte length of the GUID match key carried by Random identifiers. */
|
|
99
117
|
static GUID_LENGTH = 16;
|
|
100
118
|
static RANDOM_PAYLOAD_LENGTH = 21;
|
|
101
|
-
static PAYLOAD_LENGTH =
|
|
119
|
+
static PAYLOAD_LENGTH = FodId.MATCH_KEY_OFFSET + FodId.MATCH_KEY_LENGTH;
|
|
102
120
|
|
|
103
121
|
/**
|
|
104
122
|
* Why a read succeeded or failed, being the OWID library's statuses plus
|
|
@@ -471,7 +489,7 @@ function unpack (payload) {
|
|
|
471
489
|
// is the match key.
|
|
472
490
|
matchKeyLength = length - FodId.HEADER_LENGTH;
|
|
473
491
|
} else {
|
|
474
|
-
matchKeyLength = FodId.
|
|
492
|
+
matchKeyLength = FodId.MATCH_KEY_LENGTH;
|
|
475
493
|
}
|
|
476
494
|
const required = FodId.HEADER_LENGTH + matchKeyLength;
|
|
477
495
|
if (length < required) {
|
|
@@ -488,7 +506,7 @@ function unpack (payload) {
|
|
|
488
506
|
licenseId,
|
|
489
507
|
// slice() copies, so the stored match key is this identifier's own.
|
|
490
508
|
matchKey: payload.slice(
|
|
491
|
-
FodId.
|
|
509
|
+
FodId.MATCH_KEY_OFFSET, FodId.MATCH_KEY_OFFSET + matchKeyLength),
|
|
492
510
|
length,
|
|
493
511
|
required
|
|
494
512
|
};
|
package/idType.js
CHANGED
|
@@ -49,8 +49,8 @@ const IdType = Object.freeze({
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* The human-readable name of an IdType value.
|
|
52
|
-
* @param {number} type an IdType value
|
|
53
|
-
* @returns {string}
|
|
52
|
+
* @param {number} type an IdType value, being 0 to 3 as fromFlags returns
|
|
53
|
+
* @returns {string} the name of that type, for example "Probabilistic"
|
|
54
54
|
*/
|
|
55
55
|
name (type) {
|
|
56
56
|
return NAMES[type];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiftyone.pipeline.did",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.36",
|
|
4
4
|
"description": "Strongly typed reader for the 51Did (51Degrees Identifier) value returned by the 51Degrees Cloud service. Parses the OWID envelope and exposes the Flags, License Id and match key plus the identifier type. Compare match keys, never envelopes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"51degrees",
|
package/tests/envelope.js
CHANGED
|
@@ -37,7 +37,7 @@ const CANONICAL_LICENSE_ID = 0x12345678;
|
|
|
37
37
|
const OWID_EPOCH_MS = Date.UTC(2020, 0, 1);
|
|
38
38
|
|
|
39
39
|
function canonicalMatchKey () {
|
|
40
|
-
const h = new Uint8Array(FodId.
|
|
40
|
+
const h = new Uint8Array(FodId.MATCH_KEY_LENGTH);
|
|
41
41
|
for (let i = 0; i < h.length; i++) { h[i] = 0x20 + i; }
|
|
42
42
|
return h;
|
|
43
43
|
}
|
|
@@ -54,7 +54,7 @@ function canonicalPayload () {
|
|
|
54
54
|
const p = new Uint8Array(FodId.PAYLOAD_LENGTH);
|
|
55
55
|
p[FodId.FLAGS_OFFSET] = CANONICAL_FLAGS;
|
|
56
56
|
writeLicenseId(p);
|
|
57
|
-
p.set(canonicalMatchKey(), FodId.
|
|
57
|
+
p.set(canonicalMatchKey(), FodId.MATCH_KEY_OFFSET);
|
|
58
58
|
return p;
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -63,7 +63,7 @@ function canonicalRandomPayload () {
|
|
|
63
63
|
p[FodId.FLAGS_OFFSET] = (1 << 6) | 0b001; // Random tag + usage bits
|
|
64
64
|
writeLicenseId(p);
|
|
65
65
|
for (let i = 0; i < FodId.GUID_LENGTH; i++) {
|
|
66
|
-
p[FodId.
|
|
66
|
+
p[FodId.MATCH_KEY_OFFSET + i] = 0x40 + i;
|
|
67
67
|
}
|
|
68
68
|
return p;
|
|
69
69
|
}
|
package/tests/fodId.test.js
CHANGED
|
@@ -43,10 +43,11 @@ describe('FodId', () => {
|
|
|
43
43
|
// ----- Current .NET coverage -----
|
|
44
44
|
|
|
45
45
|
test('constants are internally consistent', () => {
|
|
46
|
-
expect(FodId.
|
|
46
|
+
expect(FodId.MATCH_KEY_OFFSET + FodId.MATCH_KEY_LENGTH)
|
|
47
|
+
.toBe(FodId.PAYLOAD_LENGTH);
|
|
47
48
|
expect(FodId.LICENSE_ID_OFFSET + FodId.LICENSE_ID_LENGTH)
|
|
48
|
-
.toBe(FodId.
|
|
49
|
-
expect(FodId.
|
|
49
|
+
.toBe(FodId.MATCH_KEY_OFFSET);
|
|
50
|
+
expect(FodId.MATCH_KEY_OFFSET + FodId.GUID_LENGTH)
|
|
50
51
|
.toBe(FodId.RANDOM_PAYLOAD_LENGTH);
|
|
51
52
|
});
|
|
52
53
|
|
|
@@ -128,9 +129,9 @@ describe('FodId', () => {
|
|
|
128
129
|
const fod = FodId.fromBase64(envelopeBase64(canonicalPayload()));
|
|
129
130
|
const k = fod.matchKey;
|
|
130
131
|
k[0] = 0x00;
|
|
131
|
-
k[FodId.
|
|
132
|
+
k[FodId.MATCH_KEY_LENGTH - 1] = 0x00;
|
|
132
133
|
expect(fod.matchKey).toEqual(canonicalMatchKey());
|
|
133
|
-
expect(fod.payload[FodId.
|
|
134
|
+
expect(fod.payload[FodId.MATCH_KEY_OFFSET]).toBe(0x20);
|
|
134
135
|
});
|
|
135
136
|
|
|
136
137
|
test('the deprecated hash getter returns the match key', () => {
|
|
@@ -175,7 +176,7 @@ describe('FodId', () => {
|
|
|
175
176
|
expect(fod.flags).toBe(CANONICAL_FLAGS);
|
|
176
177
|
expect(fod.licenseId).toBe(CANONICAL_LICENSE_ID);
|
|
177
178
|
expect(fod.matchKey).toEqual(canonicalMatchKey());
|
|
178
|
-
expect(fod.matchKey.length).toBe(FodId.
|
|
179
|
+
expect(fod.matchKey.length).toBe(FodId.MATCH_KEY_LENGTH);
|
|
179
180
|
});
|
|
180
181
|
|
|
181
182
|
test('a long context section and a long creator domain both parse', () => {
|
|
@@ -286,7 +287,7 @@ describe('FodId', () => {
|
|
|
286
287
|
});
|
|
287
288
|
|
|
288
289
|
test('Reserved header-only payload parses', () => {
|
|
289
|
-
const p = new Uint8Array(FodId.
|
|
290
|
+
const p = new Uint8Array(FodId.MATCH_KEY_OFFSET);
|
|
290
291
|
p[FodId.FLAGS_OFFSET] = 0b1100_0000;
|
|
291
292
|
const fod = FodId.fromBase64(envelopeBase64(p));
|
|
292
293
|
expect(fod.type).toBe(IdType.RESERVED);
|
|
@@ -304,7 +305,7 @@ describe('FodId', () => {
|
|
|
304
305
|
const fb = FodId.fromBase64(b);
|
|
305
306
|
|
|
306
307
|
expect(fa.matchKey).toEqual(fb.matchKey); // match key is stable
|
|
307
|
-
expect(fa.date).not.toBe(fb.date);
|
|
308
|
+
expect(fa.date).not.toBe(fb.date); // envelope differs
|
|
308
309
|
expect(fa.signature).not.toEqual(fb.signature);
|
|
309
310
|
expect(a).not.toBe(b);
|
|
310
311
|
});
|
|
@@ -325,11 +326,11 @@ describe('FodId', () => {
|
|
|
325
326
|
const o = owid.parse(envelopeBase64(canonicalPayload())).owid;
|
|
326
327
|
const fod = FodId.fromOwid(o);
|
|
327
328
|
expect(Object.isFrozen(o)).toBe(true);
|
|
328
|
-
o.payload[FodId.
|
|
329
|
-
expect(o.payload[FodId.
|
|
329
|
+
o.payload[FodId.MATCH_KEY_OFFSET] = 0x00; // writes into a copy
|
|
330
|
+
expect(o.payload[FodId.MATCH_KEY_OFFSET]).toBe(0x20);
|
|
330
331
|
expect(fod.matchKey).toEqual(canonicalMatchKey());
|
|
331
332
|
expect(fod.flags).toBe(CANONICAL_FLAGS);
|
|
332
|
-
expect(fod.payload[FodId.
|
|
333
|
+
expect(fod.payload[FodId.MATCH_KEY_OFFSET]).toBe(0x20);
|
|
333
334
|
});
|
|
334
335
|
|
|
335
336
|
test('constructor is decoupled from the source owid', () => {
|
|
@@ -338,10 +339,10 @@ describe('FodId', () => {
|
|
|
338
339
|
const o = owid.parse(envelopeBase64(canonicalPayload())).owid;
|
|
339
340
|
const fod = new FodId(o);
|
|
340
341
|
expect(fod._owid).not.toBe(o);
|
|
341
|
-
fod.payload[FodId.
|
|
342
|
+
fod.payload[FodId.MATCH_KEY_OFFSET] = 0x00; // writes into a copy
|
|
342
343
|
expect(fod.matchKey).toEqual(canonicalMatchKey());
|
|
343
344
|
expect(fod.flags).toBe(CANONICAL_FLAGS);
|
|
344
|
-
expect(fod.payload[FodId.
|
|
345
|
+
expect(fod.payload[FodId.MATCH_KEY_OFFSET]).toBe(0x20);
|
|
345
346
|
});
|
|
346
347
|
|
|
347
348
|
test('verify with the wrong key returns false', async () => {
|
|
@@ -367,9 +368,9 @@ describe('FodId', () => {
|
|
|
367
368
|
function alphabetPayload () {
|
|
368
369
|
const p = canonicalPayload();
|
|
369
370
|
// 0xFB 0xFF 0xBF encodes to "+/+/" in standard base64.
|
|
370
|
-
p[FodId.
|
|
371
|
-
p[FodId.
|
|
372
|
-
p[FodId.
|
|
371
|
+
p[FodId.MATCH_KEY_OFFSET] = 0xFB;
|
|
372
|
+
p[FodId.MATCH_KEY_OFFSET + 1] = 0xFF;
|
|
373
|
+
p[FodId.MATCH_KEY_OFFSET + 2] = 0xBF;
|
|
373
374
|
return p;
|
|
374
375
|
}
|
|
375
376
|
|
package/types/fodId.d.ts
CHANGED
|
@@ -39,11 +39,29 @@ declare class FodId {
|
|
|
39
39
|
static LICENSE_ID_OFFSET: number;
|
|
40
40
|
static LICENSE_ID_LENGTH: number;
|
|
41
41
|
/** Byte offset of the match key field within the payload. */
|
|
42
|
-
static
|
|
42
|
+
static MATCH_KEY_OFFSET: number;
|
|
43
43
|
/**
|
|
44
44
|
* Byte length of the match key field for Probabilistic and HashedEmail
|
|
45
45
|
* identifiers, being a SHA-256.
|
|
46
46
|
*/
|
|
47
|
+
static MATCH_KEY_LENGTH: number;
|
|
48
|
+
/**
|
|
49
|
+
* Deprecated alias for {@link FodId.MATCH_KEY_OFFSET}. The stable,
|
|
50
|
+
* comparable part of a 51Did is now called the match key, mirroring the
|
|
51
|
+
* Model Terms for Marketing vocabulary. This alias will be removed in a
|
|
52
|
+
* future release.
|
|
53
|
+
* @deprecated Renamed to MATCH_KEY_OFFSET. This alias will be removed in
|
|
54
|
+
* a future release.
|
|
55
|
+
*/
|
|
56
|
+
static HASH_OFFSET: number;
|
|
57
|
+
/**
|
|
58
|
+
* Deprecated alias for {@link FodId.MATCH_KEY_LENGTH}. The stable,
|
|
59
|
+
* comparable part of a 51Did is now called the match key, mirroring the
|
|
60
|
+
* Model Terms for Marketing vocabulary. This alias will be removed in a
|
|
61
|
+
* future release.
|
|
62
|
+
* @deprecated Renamed to MATCH_KEY_LENGTH. This alias will be removed in
|
|
63
|
+
* a future release.
|
|
64
|
+
*/
|
|
47
65
|
static HASH_LENGTH: number;
|
|
48
66
|
static HEADER_LENGTH: number;
|
|
49
67
|
/** Byte length of the GUID match key carried by Random identifiers. */
|
package/types/idType.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ declare const IdType: Readonly<{
|
|
|
22
22
|
fromFlags(flags: number): number;
|
|
23
23
|
/**
|
|
24
24
|
* The human-readable name of an IdType value.
|
|
25
|
-
* @param {number} type an IdType value
|
|
26
|
-
* @returns {string}
|
|
25
|
+
* @param {number} type an IdType value, being 0 to 3 as fromFlags returns
|
|
26
|
+
* @returns {string} the name of that type, for example "Probabilistic"
|
|
27
27
|
*/
|
|
28
28
|
name(type: number): string;
|
|
29
29
|
}>;
|