From 5054e4da54ea579d52bf6172365c9e6a76c68ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hauke=20T=C3=B6njes?= Date: Thu, 1 Jul 2021 14:05:09 +0200 Subject: [PATCH] Use uuidv4 for serialNumber instead of uvci --- package-lock.json | 14 ++++++++++++++ package.json | 1 + src/pass.ts | 7 ++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a26ac1a..827ff1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "pngjs": "^6.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", + "uuid": "^8.3.2", "webpack": "^5.0.0", "worker-loader": "^3.0.7" }, @@ -4213,6 +4214,14 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vm-browserify": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", @@ -7725,6 +7734,11 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "vm-browserify": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", diff --git a/package.json b/package.json index 3c3281f..ec58c5a 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "pngjs": "^6.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", + "uuid": "^8.3.2", "webpack": "^5.0.0", "worker-loader": "^3.0.7" }, diff --git a/src/pass.ts b/src/pass.ts index 2685c39..5dc5847 100644 --- a/src/pass.ts +++ b/src/pass.ts @@ -2,6 +2,7 @@ import {Constants} from "./constants"; import {Payload, PayloadBody} from "./payload"; import {ValueSets} from "./value_sets"; import {toBuffer as createZip} from 'do-not-zip'; +import {v4 as uuid4} from 'uuid'; const crypto = require('crypto') @@ -26,7 +27,7 @@ interface Field { textAlignment?: string; } -interface GenericFields { +interface PassStructureDictionary { headerFields: Array; primaryFields: Array; secondaryFields: Array; @@ -54,7 +55,7 @@ export class PassData { serialNumber: string; barcodes: Array; barcode: QrCode; - generic: GenericFields; + generic: PassStructureDictionary; // Generates a sha1 hash from a given buffer private static getBufferHash(buffer: Buffer | string): string { @@ -152,7 +153,7 @@ export class PassData { this.labelColor = payload.labelColor; this.foregroundColor = payload.foregroundColor; this.backgroundColor = payload.backgroundColor; - this.serialNumber = payload.uvci; + this.serialNumber = uuid4(); // Generate random UUID v4 this.barcodes = [qrCode]; this.barcode = qrCode; this.generic = {