fiftyone.pipeline.did 4.5.35 → 4.5.37

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 CHANGED
@@ -69,6 +69,19 @@ const ContextResult = Object.freeze({
69
69
  NO_CONTEXT: 'nocontext',
70
70
  /** The service holds no secret covering the identifier's date. */
71
71
  NOT_CHECKABLE: 'notcheckable',
72
+ /**
73
+ * The service that checked the identifier could not complete the check,
74
+ * and the reason is that service rather than the identifier. It either
75
+ * compared nothing, or compared some factors and reports at least one as
76
+ * `misconfigured` in `factors`. Nothing a caller sends can produce it.
77
+ */
78
+ MISCONFIGURED: 'misconfigured',
79
+ /**
80
+ * The creation date is one the scheme could not have produced, being in
81
+ * the future or before the creator context scheme began, so the
82
+ * identifier is fabricated rather than the service being wrong.
83
+ */
84
+ INVALID_DATE: 'invaliddate',
72
85
  /** The sealed result was redeemed outside the freshness window. */
73
86
  EXPIRED: 'expired',
74
87
  /** The sealed result had already been redeemed on that instance. */
@@ -102,7 +115,13 @@ const SignatureResult = Object.freeze({
102
115
  */
103
116
  const FactorResult = Object.freeze({
104
117
  VERIFIED: 'verified',
105
- MISMATCH: 'mismatch'
118
+ MISMATCH: 'mismatch',
119
+ /**
120
+ * The service that checked the identifier is not configured to determine
121
+ * this factor, so it could not have checked it for any request. This is
122
+ * NOT a mismatch and must not be read as one.
123
+ */
124
+ MISCONFIGURED: 'misconfigured'
106
125
  });
107
126
 
108
127
  /**
@@ -776,7 +795,7 @@ function dateOf (fodId) {
776
795
  function payloadLengthValid (fodId) {
777
796
  const matchKeyLength = fodId.type === IdType.RANDOM
778
797
  ? FodId.GUID_LENGTH
779
- : FodId.HASH_LENGTH;
798
+ : FodId.MATCH_KEY_LENGTH;
780
799
  return fodId.payload.length >= FodId.HEADER_LENGTH + matchKeyLength;
781
800
  }
782
801
 
@@ -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.HASH_LENGTH; i++) { p[FodId.HASH_OFFSET + i] = 0x20 + i; }
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 HASH_OFFSET = 5;
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 HASH_LENGTH = 32;
97
- static HEADER_LENGTH = 5;
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 = 37;
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.HASH_LENGTH;
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.HASH_OFFSET, FodId.HASH_OFFSET + matchKeyLength),
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.35",
3
+ "version": "4.5.37",
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.HASH_LENGTH);
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.HASH_OFFSET);
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.HASH_OFFSET + i] = 0x40 + i;
66
+ p[FodId.MATCH_KEY_OFFSET + i] = 0x40 + i;
67
67
  }
68
68
  return p;
69
69
  }
@@ -43,10 +43,11 @@ describe('FodId', () => {
43
43
  // ----- Current .NET coverage -----
44
44
 
45
45
  test('constants are internally consistent', () => {
46
- expect(FodId.HASH_OFFSET + FodId.HASH_LENGTH).toBe(FodId.PAYLOAD_LENGTH);
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.HASH_OFFSET);
49
- expect(FodId.HASH_OFFSET + FodId.GUID_LENGTH)
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.HASH_LENGTH - 1] = 0x00;
132
+ k[FodId.MATCH_KEY_LENGTH - 1] = 0x00;
132
133
  expect(fod.matchKey).toEqual(canonicalMatchKey());
133
- expect(fod.payload[FodId.HASH_OFFSET]).toBe(0x20);
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.HASH_LENGTH);
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.HASH_OFFSET);
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); // envelope differs
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.HASH_OFFSET] = 0x00; // writes into a copy
329
- expect(o.payload[FodId.HASH_OFFSET]).toBe(0x20);
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.HASH_OFFSET]).toBe(0x20);
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.HASH_OFFSET] = 0x00; // writes into a copy
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.HASH_OFFSET]).toBe(0x20);
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.HASH_OFFSET] = 0xFB;
371
- p[FodId.HASH_OFFSET + 1] = 0xFF;
372
- p[FodId.HASH_OFFSET + 2] = 0xBF;
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
 
@@ -345,6 +345,8 @@ export const ContextResult: Readonly<{
345
345
  NO_CONTEXT: "nocontext";
346
346
  /** The service holds no secret covering the identifier's date. */
347
347
  NOT_CHECKABLE: "notcheckable";
348
+ MISCONFIGURED: "misconfigured";
349
+ INVALID_DATE: "invaliddate";
348
350
  /** The sealed result was redeemed outside the freshness window. */
349
351
  EXPIRED: "expired";
350
352
  /** The sealed result had already been redeemed on that instance. */
@@ -369,12 +371,14 @@ export const SignatureResult: Readonly<{
369
371
  UNKNOWN: "unknown";
370
372
  }>;
371
373
  /**
372
- * The outcome of one factor in a mismatch. The cloud reports `null` for a
374
+ * The outcome of one factor in a mismatch or a partly misconfigured
375
+ * result. The cloud reports `null` for a
373
376
  * factor that was not compared, which is passed through unchanged.
374
377
  */
375
378
  export const FactorResult: Readonly<{
376
379
  VERIFIED: "verified";
377
380
  MISMATCH: "mismatch";
381
+ MISCONFIGURED: "misconfigured";
378
382
  }>;
379
383
  /**
380
384
  * The reason a {@link DidClient#verifySignatureDetailed} answer was given.
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 HASH_OFFSET: number;
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
  }>;