fiftyone.pipeline.did 4.5.25 → 4.5.26

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/fodId.js CHANGED
@@ -53,15 +53,17 @@ class FodId {
53
53
 
54
54
  /**
55
55
  * Promotes an already-parsed owid instance into a 51Did by unpacking its
56
- * payload.
56
+ * payload. The owid is **copied** (re-parsed from its base64), not aliased,
57
+ * so a FodId can never desync from its envelope if the caller later mutates
58
+ * the owid they passed in.
57
59
  * @param {object} owidInstance an owid instance (from `new owid(base64)`)
58
60
  */
59
61
  constructor (owidInstance) {
60
62
  if (owidInstance === null || owidInstance === undefined) {
61
63
  throw new TypeError('owid must not be null or undefined');
62
64
  }
63
- this._owid = owidInstance;
64
- const payload = owidInstance.owid.payload;
65
+ this._owid = new owid(owidInstance.data);
66
+ const payload = this._owid.owid.payload;
65
67
  const length = payload ? payload.length : 0;
66
68
  if (!payload || length < FodId.HEADER_LENGTH) {
67
69
  throw new RangeError(
@@ -121,10 +123,10 @@ class FodId {
121
123
  }
122
124
 
123
125
  /**
124
- * Promotes an already-parsed owid instance into a 51Did. The owid is
125
- * **copied** (re-parsed from its base64), not aliased, so a FodId can never
126
- * desync from its envelope if the caller later mutates the owid it passed
127
- * in.
126
+ * Promotes an already-parsed owid instance into a 51Did. The constructor
127
+ * **copies** the owid (re-parsed from its base64), not aliases it, so a
128
+ * FodId can never desync from its envelope if the caller later mutates the
129
+ * owid it passed in.
128
130
  * @param {object} owidInstance
129
131
  * @returns {FodId}
130
132
  */
@@ -132,7 +134,7 @@ class FodId {
132
134
  if (owidInstance === null || owidInstance === undefined) {
133
135
  throw new TypeError('owid must not be null or undefined');
134
136
  }
135
- return new FodId(new owid(owidInstance.data));
137
+ return new FodId(owidInstance);
136
138
  }
137
139
 
138
140
  /** @returns {number} the 1-byte usage flags bit-mask (0-255). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.did",
3
- "version": "4.5.25",
3
+ "version": "4.5.26",
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 value (Hash) plus the identifier type. Compare values, never envelopes.",
5
5
  "keywords": [
6
6
  "51degrees",
@@ -354,6 +354,17 @@ describe('FodId', () => {
354
354
  expect(fod.payload[FodId.HASH_OFFSET]).toBe(0x20);
355
355
  });
356
356
 
357
+ test('constructor is decoupled from the source owid', () => {
358
+ // The constructor must copy the owid too, not just fromOwid - mutating the
359
+ // source afterwards must not affect the FodId.
360
+ const o = new owid(envelopeBase64(canonicalPayload()));
361
+ const fod = new FodId(o);
362
+ o.owid.payload = new Uint8Array(FodId.PAYLOAD_LENGTH); // mutate the source
363
+ expect(fod.hash).toEqual(canonicalHash());
364
+ expect(fod.flags).toBe(CANONICAL_FLAGS);
365
+ expect(fod.payload[FodId.HASH_OFFSET]).toBe(0x20);
366
+ });
367
+
357
368
  test('verify with the wrong key returns false', async () => {
358
369
  const { base64 } = await signedVerifiable(canonicalPayload());
359
370
  const otherPublicPem = await randomPublicPem();