quadqr-js 1.0.2 → 1.2.0
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/FORMAT.md +11 -0
- package/README.md +165 -11
- package/SPECIFICATION.md +332 -0
- package/bin/quadqr.js +102 -13
- package/dist/esm/benchmark.js +80 -0
- package/dist/esm/node.js +13 -1
- package/dist/esm/quadqr.js +1435 -74
- package/dist/quadqr.js +1435 -76
- package/dist/quadqr.min.js +1429 -76
- package/docs/API.md +220 -4
- package/docs/BROWSER_CDN.md +51 -6
- package/docs/CLI.md +150 -76
- package/docs/GETTING_STARTED.md +80 -7
- package/docs/NODE.md +137 -123
- package/docs/README.md +59 -41
- package/docs/WASM.md +2 -2
- package/package.json +8 -3
- package/types/benchmark.d.ts +4 -3
- package/types/index.d.ts +115 -1
- package/types/node.d.ts +2 -0
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type EccLevel = "L" | "M" | "Q" | "H";
|
|
2
2
|
export type RenderStyle = "classic" | "depth" | "soft" | "inset";
|
|
3
|
+
export type RenderMode = "screen" | "print";
|
|
4
|
+
export type CompressionMode = "none" | "auto" | "lz";
|
|
3
5
|
export type SecurityMode = "password" | "raw-key";
|
|
4
6
|
|
|
5
7
|
export interface Palette {
|
|
@@ -11,12 +13,28 @@ export interface Palette {
|
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface EncodeOptions {
|
|
14
|
-
version?: number;
|
|
16
|
+
version?: number | "auto";
|
|
17
|
+
minVersion?: number;
|
|
18
|
+
maxVersion?: number;
|
|
15
19
|
ecc?: EccLevel;
|
|
16
20
|
maskId?: number;
|
|
17
21
|
text?: boolean;
|
|
22
|
+
compression?: CompressionMode;
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
export interface SigningOptions {
|
|
26
|
+
/** Private Ed25519 key used to create the signature. Never embed or distribute it. */
|
|
27
|
+
privateKey: CryptoKey | Uint8Array | ArrayBuffer;
|
|
28
|
+
/** Optional compact identifier stored with the signature so a verifier can select a trusted public key. */
|
|
29
|
+
keyId?: string;
|
|
30
|
+
/** Optional public key used only when embedPublicKey is explicitly enabled. */
|
|
31
|
+
publicKey?: CryptoKey | Uint8Array | ArrayBuffer;
|
|
32
|
+
/** Embed the public key for self-contained integrity checks. Default: false. */
|
|
33
|
+
embedPublicKey?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SignedEncodeOptions extends EncodeOptions, SigningOptions {}
|
|
37
|
+
|
|
20
38
|
export interface PasswordSecurity {
|
|
21
39
|
mode: "password";
|
|
22
40
|
password: string;
|
|
@@ -32,6 +50,7 @@ export interface RawKeySecurity {
|
|
|
32
50
|
|
|
33
51
|
export interface SecureEncodeOptions extends EncodeOptions {
|
|
34
52
|
security: PasswordSecurity | RawKeySecurity;
|
|
53
|
+
signing?: SigningOptions;
|
|
35
54
|
}
|
|
36
55
|
|
|
37
56
|
export interface QuadQRCode {
|
|
@@ -43,6 +62,9 @@ export interface QuadQRCode {
|
|
|
43
62
|
payloadBytes: number;
|
|
44
63
|
capacityBytes: number;
|
|
45
64
|
secure?: boolean;
|
|
65
|
+
compressed?: boolean;
|
|
66
|
+
compression?: "none" | "lz";
|
|
67
|
+
signed?: boolean;
|
|
46
68
|
security?: SecurityMetadata | null;
|
|
47
69
|
[key: string]: unknown;
|
|
48
70
|
}
|
|
@@ -61,6 +83,22 @@ export interface SecurityMetadata {
|
|
|
61
83
|
[key: string]: unknown;
|
|
62
84
|
}
|
|
63
85
|
|
|
86
|
+
export interface ScanDiagnostics {
|
|
87
|
+
confidence: number;
|
|
88
|
+
cellConfidence: number;
|
|
89
|
+
structureConfidence: number;
|
|
90
|
+
geometryConfidence: number;
|
|
91
|
+
calibrationConfidence: number;
|
|
92
|
+
eccUtilization: number;
|
|
93
|
+
correctedErrors: number;
|
|
94
|
+
erasureSymbols: number;
|
|
95
|
+
stages?: Record<string, boolean>;
|
|
96
|
+
failedStage?: string | null;
|
|
97
|
+
geometryCandidates?: unknown[];
|
|
98
|
+
sampled?: Record<string, unknown> | null;
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}
|
|
101
|
+
|
|
64
102
|
export interface DecodeResult {
|
|
65
103
|
payload: Uint8Array;
|
|
66
104
|
text: string | null;
|
|
@@ -73,6 +111,24 @@ export interface DecodeResult {
|
|
|
73
111
|
decrypted?: boolean;
|
|
74
112
|
security?: SecurityMetadata | null;
|
|
75
113
|
encryptedPayload?: Uint8Array;
|
|
114
|
+
protectedPayload?: Uint8Array;
|
|
115
|
+
compressed?: boolean;
|
|
116
|
+
compression?: "none" | "lz";
|
|
117
|
+
signed?: boolean;
|
|
118
|
+
/** Legacy v1 signer label, if decoding an older signed symbol. */
|
|
119
|
+
signer?: string | null;
|
|
120
|
+
signingKeyId?: string | null;
|
|
121
|
+
hasEmbeddedPublicKey?: boolean;
|
|
122
|
+
signatureVerified?: boolean | null;
|
|
123
|
+
signatureTrusted?: boolean | null;
|
|
124
|
+
signatureTrustSource?: "external" | "embedded" | null;
|
|
125
|
+
confidence?: number;
|
|
126
|
+
geometryConfidence?: number;
|
|
127
|
+
calibrationConfidence?: number;
|
|
128
|
+
structureConfidence?: number;
|
|
129
|
+
correctedErrors?: number;
|
|
130
|
+
eccUtilization?: number;
|
|
131
|
+
diagnostics?: ScanDiagnostics;
|
|
76
132
|
[key: string]: unknown;
|
|
77
133
|
}
|
|
78
134
|
|
|
@@ -82,6 +138,21 @@ export interface ImageDataLike {
|
|
|
82
138
|
data: Uint8ClampedArray | Uint8Array;
|
|
83
139
|
}
|
|
84
140
|
|
|
141
|
+
export interface LogoRenderOptions {
|
|
142
|
+
/** Loaded CanvasImageSource in canvas rendering, ImageDataLike in pixel rendering, or URL/data URL in SVG rendering. */
|
|
143
|
+
source: CanvasImageSource | ImageDataLike | string;
|
|
144
|
+
/** Logo width/height as a fraction of the symbol area. Clamped to 0.05..0.30. Default: 0.18. */
|
|
145
|
+
size?: number | "auto";
|
|
146
|
+
/** Clear the modules behind the logo with a solid background before drawing it. */
|
|
147
|
+
clearBackground?: boolean;
|
|
148
|
+
/** Background padding around the logo in modules. Default: 0.65. */
|
|
149
|
+
padding?: number;
|
|
150
|
+
/** Rounded background corner radius in modules. Default: 0.8. */
|
|
151
|
+
radius?: number;
|
|
152
|
+
/** Background color used when clearBackground is enabled. Default: palette white. */
|
|
153
|
+
backgroundColor?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
85
156
|
export interface CameraFinderDiagnostic {
|
|
86
157
|
x: number;
|
|
87
158
|
y: number;
|
|
@@ -128,14 +199,30 @@ export interface CameraDiagnosticEvent {
|
|
|
128
199
|
}
|
|
129
200
|
|
|
130
201
|
export interface RenderOptions {
|
|
202
|
+
/** Exact square output size in pixels. If neither imageSize nor moduleSize is supplied, defaults to 720. */
|
|
203
|
+
imageSize?: number;
|
|
204
|
+
/** Legacy/low-level pixels per module sizing. Used when imageSize is not supplied. */
|
|
131
205
|
moduleSize?: number;
|
|
132
206
|
quietZone?: number;
|
|
133
207
|
palette?: Palette;
|
|
134
208
|
style?: RenderStyle;
|
|
209
|
+
/** Screen defaults or print-safe palette/quiet-zone/classic-style behavior. */
|
|
210
|
+
mode?: RenderMode;
|
|
211
|
+
renderMode?: RenderMode;
|
|
212
|
+
allowStyledPrint?: boolean;
|
|
213
|
+
allowUnsafePrintQuietZone?: boolean;
|
|
214
|
+
logo?: CanvasImageSource | ImageDataLike | string | LogoRenderOptions;
|
|
215
|
+
logoSize?: number;
|
|
216
|
+
logoClearBackground?: boolean;
|
|
217
|
+
logoPadding?: number;
|
|
218
|
+
logoRadius?: number;
|
|
219
|
+
logoBackgroundColor?: string;
|
|
135
220
|
[key: string]: unknown;
|
|
136
221
|
}
|
|
137
222
|
|
|
138
223
|
export interface ScanOptions {
|
|
224
|
+
debug?: boolean;
|
|
225
|
+
debugMatrices?: boolean;
|
|
139
226
|
minVersion?: number;
|
|
140
227
|
maxVersion?: number;
|
|
141
228
|
perspective?: boolean;
|
|
@@ -224,6 +311,10 @@ export const FORMAT_VERSION: number;
|
|
|
224
311
|
export const MIN_VERSION: number;
|
|
225
312
|
export const MAX_VERSION: number;
|
|
226
313
|
export const DEFAULT_ECC_LEVEL: EccLevel;
|
|
314
|
+
export const RENDER_MODES: Readonly<{ SCREEN: "screen"; PRINT: "print" }>;
|
|
315
|
+
export const PRINT_PALETTE: Readonly<Required<Palette>>;
|
|
316
|
+
export const COMPRESSION_MODES: Readonly<Record<string, CompressionMode>>;
|
|
317
|
+
export const SIGNATURE_ALGORITHMS: Readonly<{ ED25519: "Ed25519" }>;
|
|
227
318
|
export const CELL: Readonly<{ BLACK: -1; RED: 0; GREEN: 1; BLUE: 2; WHITE: 3 }>;
|
|
228
319
|
export const DEFAULT_PALETTE: Readonly<Required<Palette>>;
|
|
229
320
|
export const RENDER_STYLES: Readonly<Record<string, RenderStyle>>;
|
|
@@ -235,16 +326,39 @@ export const DEFAULT_PBKDF2_ITERATIONS: number;
|
|
|
235
326
|
|
|
236
327
|
export function encodeText(text: string, options?: EncodeOptions): QuadQRCode;
|
|
237
328
|
export function encodeBytes(input: Uint8Array | ArrayBuffer | ArrayLike<number>, options?: EncodeOptions): QuadQRCode;
|
|
329
|
+
export function encodeUint8Array(input: Uint8Array | ArrayBuffer | ArrayLike<number>, options?: EncodeOptions): QuadQRCode;
|
|
330
|
+
export function encodeSignedText(text: string, options: SignedEncodeOptions): Promise<QuadQRCode>;
|
|
331
|
+
export function encodeSignedBytes(input: Uint8Array | ArrayBuffer | ArrayLike<number>, options: SignedEncodeOptions): Promise<QuadQRCode>;
|
|
238
332
|
export function encodeSecureText(text: string, options: SecureEncodeOptions): Promise<QuadQRCode>;
|
|
239
333
|
export function encodeSecureBytes(input: Uint8Array | ArrayBuffer | ArrayLike<number>, options: SecureEncodeOptions): Promise<QuadQRCode>;
|
|
334
|
+
export function compressPayload(input: Uint8Array | ArrayBuffer | ArrayLike<number>): Uint8Array;
|
|
335
|
+
export function decompressPayload(input: Uint8Array | ArrayBuffer | ArrayLike<number>, expectedLength?: number | null): Uint8Array;
|
|
336
|
+
export function deriveSigningKeyId(publicKey: CryptoKey | Uint8Array | ArrayBuffer, bytes?: number): Promise<string>;
|
|
337
|
+
export function generateSigningKeyPair(): Promise<{ privateKey: CryptoKey; publicKey: CryptoKey; privateKeyPkcs8: Uint8Array; publicKeyBytes: Uint8Array; keyId: string; algorithm: "Ed25519" }>;
|
|
240
338
|
export function decodeMatrix(matrix: number[][], options?: Record<string, unknown>): DecodeResult;
|
|
339
|
+
export function decodeUint8Array(matrix: number[][], options?: Record<string, unknown>): Uint8Array;
|
|
241
340
|
export function decryptDecoded(result: DecodeResult, credentials: { password: string } | { key: string | Uint8Array | ArrayBuffer }): Promise<DecodeResult>;
|
|
341
|
+
export function verifyDecodedSignature(result: DecodeResult, options?: {
|
|
342
|
+
publicKey?: CryptoKey | Uint8Array | ArrayBuffer;
|
|
343
|
+
trustedPublicKey?: CryptoKey | Uint8Array | ArrayBuffer;
|
|
344
|
+
trustedKeys?: Record<string, CryptoKey | Uint8Array | ArrayBuffer> | Map<string, CryptoKey | Uint8Array | ArrayBuffer>;
|
|
345
|
+
allowEmbeddedKey?: boolean;
|
|
346
|
+
}): Promise<DecodeResult>;
|
|
242
347
|
export function renderToCanvas(codeOrMatrix: QuadQRCode | number[][], canvas: HTMLCanvasElement, options?: RenderOptions): HTMLCanvasElement;
|
|
243
348
|
export function renderToImageData(codeOrMatrix: QuadQRCode | number[][], options?: RenderOptions): ImageDataLike;
|
|
349
|
+
export function renderToSVG(codeOrMatrix: QuadQRCode | number[][], options?: RenderOptions): string;
|
|
350
|
+
export function estimateSafeLogoSize(codeOrMatrix: QuadQRCode | number[][], options?: RenderOptions & { ecc?: EccLevel; utilization?: number }): number;
|
|
351
|
+
export function findMaxSafeLogoSize(code: QuadQRCode, options: RenderOptions & { minSize?: number; maxSize?: number; iterations?: number }): { safeSize: number; testedMax: number; iterations: number; empirical: boolean };
|
|
352
|
+
export function getPrintGuidance(codeOrMatrix: QuadQRCode | number[][], options?: { quietZone?: number; physicalSizeMm?: number; dpi?: number; minimumModuleMm?: number }): Record<string, unknown>;
|
|
244
353
|
export function scanImageData(imageData: ImageDataLike, options?: ScanOptions): DecodeResult;
|
|
354
|
+
export function debugScanImageData(imageData: ImageDataLike, options?: ScanOptions): { ok: boolean; result?: DecodeResult; error?: string; debug?: ScanDiagnostics | null };
|
|
245
355
|
export function scanFile(file: Blob, options?: ScanOptions): Promise<DecodeResult>;
|
|
246
356
|
export function scanVideoFrame(video: HTMLVideoElement, options?: ScanOptions): DecodeResult;
|
|
247
357
|
export function startCameraScanner(video: HTMLVideoElement, options?: CameraScanOptions): Promise<{ stop(): void; scanNow(): DecodeResult; stream: MediaStream; video: HTMLVideoElement }>;
|
|
358
|
+
export function applyStressDistortion(imageData: ImageDataLike, type: string, severity?: number, options?: Record<string, unknown>): ImageDataLike;
|
|
359
|
+
export const STRESS_PROFILES: readonly Readonly<{ id: string; label: string; type: string; severity: number; weight: number }>[];
|
|
360
|
+
export function runImageStressTest(imageData: ImageDataLike, expected?: { version?: number; crc32?: number }, options?: Record<string, unknown>): Record<string, unknown>;
|
|
361
|
+
export function assessScanability(code: QuadQRCode, renderOptions?: RenderOptions, options?: Record<string, unknown>): Record<string, unknown>;
|
|
248
362
|
export function rectifyDetectedCode(imageData: ImageDataLike, options?: Record<string, unknown>): ImageDataLike;
|
|
249
363
|
export function rotateMatrix(matrix: number[][], quarterTurns?: number): number[][];
|
|
250
364
|
export function getVersionInfo(version: number, options?: { ecc?: EccLevel }): Record<string, unknown>;
|
package/types/node.d.ts
CHANGED
|
@@ -5,5 +5,7 @@ export function decodePNG(input: Uint8Array | ArrayBuffer): ImageDataLike;
|
|
|
5
5
|
export function encodePNG(imageData: ImageDataLike, options?: { compressionLevel?: number }): Buffer;
|
|
6
6
|
export function toPNG(codeOrMatrix: QuadQRCode | number[][], options?: RenderOptions & { compressionLevel?: number }): Buffer;
|
|
7
7
|
export function savePNG(codeOrMatrix: QuadQRCode | number[][], filename: string | URL, options?: RenderOptions & { compressionLevel?: number }): Promise<{ filename: string | URL; bytes: number }>;
|
|
8
|
+
export function toSVG(codeOrMatrix: QuadQRCode | number[][], options?: RenderOptions): string;
|
|
9
|
+
export function saveSVG(codeOrMatrix: QuadQRCode | number[][], filename: string | URL, options?: RenderOptions): Promise<{ filename: string | URL; bytes: number }>;
|
|
8
10
|
export function scanBuffer(input: Uint8Array | ArrayBuffer, options?: ScanOptions): Promise<DecodeResult>;
|
|
9
11
|
export function scanFile(filename: string | URL, options?: ScanOptions): Promise<DecodeResult>;
|