@altronix/webtobin 0.6.0 → 0.8.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/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@altronix/webtobin",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "./webtobin.mjs",
7
7
  "types": "./webtobin.d.ts",
8
- "scripts": {
9
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest"
10
- },
11
8
  "files": [
12
9
  "webtobin.d.ts",
13
10
  "webtobin.mjs",
@@ -16,9 +13,11 @@
16
13
  "keywords": [],
17
14
  "author": "",
18
15
  "license": "ISC",
19
- "packageManager": "pnpm@10.5.2",
20
16
  "devDependencies": {
21
17
  "cross-env": "^10.0.0",
22
18
  "jest": "^30.1.3"
19
+ },
20
+ "scripts": {
21
+ "test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest"
23
22
  }
24
- }
23
+ }
package/webtobin.d.ts CHANGED
@@ -1,7 +1,55 @@
1
- export default class {
1
+ export interface McubootVersion {
2
+ major: number;
3
+ minor: number;
4
+ revision: number;
5
+ build: number;
6
+ }
7
+
8
+ export interface McubootHeader {
9
+ magic: number;
10
+ loadAddr: number;
11
+ hdrSize: number;
12
+ protectTlvSize: number;
13
+ imgSize: number;
14
+ flags: number;
15
+ version: McubootVersion;
16
+ }
17
+
18
+ export interface McubootTlv {
19
+ type: number;
20
+ value: Uint8Array;
21
+ }
22
+
23
+ export interface McubootImage {
24
+ header: McubootHeader;
25
+ /** Inner firmware data only */
26
+ image: Uint8Array;
27
+ /** Full MCUboot signed image (header + data + TLVs) */
28
+ signedImage: Uint8Array;
29
+ protectedTlvs: McubootTlv[];
30
+ tlvs: McubootTlv[];
31
+ }
32
+
33
+ export function parseMcubootImages(bin: Buffer | Uint8Array): McubootImage[];
34
+
35
+ export class AltronixImage {
36
+ partitionIndex: number;
37
+ partitionName: string;
38
+ constructor(mcubootImage: McubootImage);
39
+ static fromMcubootImage(img: McubootImage): AltronixImage;
40
+ readTlv(type: number): Uint8Array | null;
41
+ get header(): McubootHeader;
42
+ /** Inner firmware data only */
43
+ get image(): Uint8Array;
44
+ /** Full MCUboot signed image (header + data + TLVs) */
45
+ get signedImage(): Uint8Array;
46
+ get version(): McubootVersion;
47
+ }
48
+
49
+ export default class Webtobin {
2
50
  constructor();
3
51
  files: { path: string; data: Uint8Array }[];
4
- static from(bin: Uint8Array): this;
52
+ static from(bin: Uint8Array): Webtobin;
5
53
  append(path: string, data: string | Uint8Array): this;
6
54
  remove(path: string): this;
7
55
  print(): Uint8Array;
package/webtobin.mjs CHANGED
@@ -32,7 +32,8 @@ const TLV_PROT_INFO_MAGIC = 0x6908;
32
32
  /**
33
33
  * @typedef {Object} McubootImage
34
34
  * @property {McubootHeader} header
35
- * @property {Uint8Array} image
35
+ * @property {Uint8Array} image - Inner firmware data only
36
+ * @property {Uint8Array} signedImage - Full MCUboot signed image (header + data + TLVs)
36
37
  * @property {McubootTlv[]} protectedTlvs
37
38
  * @property {McubootTlv[]} tlvs
38
39
  */
@@ -80,7 +81,8 @@ export function parseMcubootImages(bin) {
80
81
  tlvOffset += tlvSize;
81
82
  }
82
83
 
83
- images.push({ header, image, protectedTlvs, tlvs });
84
+ const signedImage = new Uint8Array(buf.slice(offset, tlvOffset));
85
+ images.push({ header, image, signedImage, protectedTlvs, tlvs });
84
86
  offset = tlvOffset;
85
87
  }
86
88
 
@@ -198,11 +200,16 @@ export class AltronixImage {
198
200
  return this.#mcuboot.header;
199
201
  }
200
202
 
201
- /** @returns {Uint8Array} */
203
+ /** @returns {Uint8Array} Inner firmware data only */
202
204
  get image() {
203
205
  return this.#mcuboot.image;
204
206
  }
205
207
 
208
+ /** @returns {Uint8Array} Full MCUboot signed image (header + data + TLVs) */
209
+ get signedImage() {
210
+ return this.#mcuboot.signedImage;
211
+ }
212
+
206
213
  /** @returns {McubootVersion} */
207
214
  get version() {
208
215
  return this.#mcuboot.header.version;