@scalebun/cli 1.13.0 → 2.0.1

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.
Files changed (45) hide show
  1. package/lib/commands/doctor.d.ts.map +1 -1
  2. package/lib/commands/doctor.js +48 -9
  3. package/lib/commands/doctor.js.map +1 -1
  4. package/lib/commands/ota-bundle.d.ts.map +1 -1
  5. package/lib/commands/ota-bundle.js +8 -14
  6. package/lib/commands/ota-bundle.js.map +1 -1
  7. package/lib/commands/ota-keys.d.ts +29 -30
  8. package/lib/commands/ota-keys.d.ts.map +1 -1
  9. package/lib/commands/ota-keys.js +372 -267
  10. package/lib/commands/ota-keys.js.map +1 -1
  11. package/lib/commands/ota-publish.d.ts.map +1 -1
  12. package/lib/commands/ota-publish.js +67 -10
  13. package/lib/commands/ota-publish.js.map +1 -1
  14. package/lib/commands/quickstart.d.ts.map +1 -1
  15. package/lib/commands/quickstart.js +20 -17
  16. package/lib/commands/quickstart.js.map +1 -1
  17. package/lib/utils/signing.d.ts +70 -0
  18. package/lib/utils/signing.d.ts.map +1 -0
  19. package/lib/utils/signing.js +171 -0
  20. package/lib/utils/signing.js.map +1 -0
  21. package/lib/vendor/ota-protocol/base64.d.ts +11 -0
  22. package/lib/vendor/ota-protocol/base64.d.ts.map +1 -0
  23. package/lib/vendor/ota-protocol/base64.js +39 -0
  24. package/lib/vendor/ota-protocol/base64.js.map +1 -0
  25. package/lib/vendor/ota-protocol/codec.d.ts +26 -0
  26. package/lib/vendor/ota-protocol/codec.d.ts.map +1 -0
  27. package/lib/vendor/ota-protocol/codec.js +349 -0
  28. package/lib/vendor/ota-protocol/codec.js.map +1 -0
  29. package/lib/vendor/ota-protocol/hex.d.ts +8 -0
  30. package/lib/vendor/ota-protocol/hex.d.ts.map +1 -0
  31. package/lib/vendor/ota-protocol/hex.js +31 -0
  32. package/lib/vendor/ota-protocol/hex.js.map +1 -0
  33. package/lib/vendor/ota-protocol/index.d.ts +17 -0
  34. package/lib/vendor/ota-protocol/index.d.ts.map +1 -0
  35. package/lib/vendor/ota-protocol/index.js +41 -0
  36. package/lib/vendor/ota-protocol/index.js.map +1 -0
  37. package/lib/vendor/ota-protocol/limits.d.ts +39 -0
  38. package/lib/vendor/ota-protocol/limits.d.ts.map +1 -0
  39. package/lib/vendor/ota-protocol/limits.js +42 -0
  40. package/lib/vendor/ota-protocol/limits.js.map +1 -0
  41. package/lib/vendor/ota-protocol/types.d.ts +73 -0
  42. package/lib/vendor/ota-protocol/types.d.ts.map +1 -0
  43. package/lib/vendor/ota-protocol/types.js +24 -0
  44. package/lib/vendor/ota-protocol/types.js.map +1 -0
  45. package/package.json +1 -1
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.spkiFingerprint = spkiFingerprint;
37
+ exports.inspectPublicKey = inspectPublicKey;
38
+ exports.generateRsaKeyPair = generateRsaKeyPair;
39
+ exports.signReleasePayload = signReleasePayload;
40
+ exports.buildReleaseEnvelope = buildReleaseEnvelope;
41
+ /**
42
+ * RSA-3072 / SHA-256 release signing for SB-OTA-RSA-SHA256-V1.
43
+ *
44
+ * Security model (unchanged in spirit from the ed25519 era, stronger in fact):
45
+ * the private key is generated on the developer's machine and NEVER leaves it —
46
+ * only the SPKI public key is registered, and only the detached signature +
47
+ * signed payload are uploaded. A server that cannot sign cannot forge a release.
48
+ *
49
+ * The signed object is the exact binary ScaleBunSignedReleaseV1 payload (see the
50
+ * vendored codec + docs/ota/SB-OTA-RSA-SHA256-V1.md). We sign those bytes and
51
+ * immediately self-verify with the derived public key before returning, so a
52
+ * broken key or a codec regression fails here rather than on a user's device.
53
+ */
54
+ const crypto = __importStar(require("crypto"));
55
+ const ota_protocol_1 = require("../vendor/ota-protocol");
56
+ function modulusBits(key) {
57
+ const bits = key.asymmetricKeyDetails?.modulusLength;
58
+ if (typeof bits !== 'number') {
59
+ throw new Error('key has no RSA modulus length — not an RSA key?');
60
+ }
61
+ return bits;
62
+ }
63
+ /** SHA-256 fingerprint over the SPKI DER of a public key. */
64
+ function spkiFingerprint(publicKey) {
65
+ const der = publicKey.export({ type: 'spki', format: 'der' });
66
+ const hex = crypto.createHash('sha256').update(der).digest('hex');
67
+ const display = (hex.match(/.{2}/g) ?? []).join(':').toUpperCase();
68
+ return { hex, display };
69
+ }
70
+ /**
71
+ * Validate that a public key is RSA of an acceptable size and describe it.
72
+ * Throws on non-RSA keys or a modulus below {@link MIN_RSA_MODULUS_BITS}.
73
+ */
74
+ function inspectPublicKey(pem) {
75
+ let key;
76
+ try {
77
+ key = crypto.createPublicKey(pem);
78
+ }
79
+ catch (err) {
80
+ throw new Error(`not a valid public key: ${err?.message ?? err}`);
81
+ }
82
+ if (key.asymmetricKeyType !== 'rsa') {
83
+ throw new Error(`unsupported key type "${key.asymmetricKeyType}" — SB-OTA-RSA-SHA256-V1 requires RSA`);
84
+ }
85
+ const bits = modulusBits(key);
86
+ if (bits < ota_protocol_1.MIN_RSA_MODULUS_BITS) {
87
+ throw new Error(`RSA modulus ${bits} bits is below the ${ota_protocol_1.MIN_RSA_MODULUS_BITS}-bit minimum`);
88
+ }
89
+ const fp = spkiFingerprint(key);
90
+ return {
91
+ algorithm: 'RSA_SHA256',
92
+ modulusBits: bits,
93
+ fingerprint: fp.hex,
94
+ fingerprintDisplay: fp.display,
95
+ spkiPem: key.export({ type: 'spki', format: 'pem' }),
96
+ };
97
+ }
98
+ /**
99
+ * Generate a fresh RSA keypair (default 3072-bit). The private key is exported as
100
+ * PKCS#8 PEM (encrypted when a passphrase is supplied); the public key as SPKI
101
+ * PEM. This function never writes to disk or prints the private key — callers own
102
+ * storage + permissions.
103
+ */
104
+ function generateRsaKeyPair(opts) {
105
+ const bits = opts?.modulusBits ?? ota_protocol_1.RECOMMENDED_RSA_MODULUS_BITS;
106
+ if (bits < ota_protocol_1.MIN_RSA_MODULUS_BITS) {
107
+ throw new Error(`refusing to generate a ${bits}-bit key; minimum is ${ota_protocol_1.MIN_RSA_MODULUS_BITS}`);
108
+ }
109
+ const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', { modulusLength: bits });
110
+ const privatePem = (opts?.passphrase
111
+ ? privateKey.export({
112
+ type: 'pkcs8',
113
+ format: 'pem',
114
+ cipher: 'aes-256-cbc',
115
+ passphrase: opts.passphrase,
116
+ })
117
+ : privateKey.export({ type: 'pkcs8', format: 'pem' }));
118
+ const publicPem = publicKey.export({ type: 'spki', format: 'pem' });
119
+ return { privatePem, publicPem, info: inspectPublicKey(publicPem) };
120
+ }
121
+ function loadRsaPrivateKey(pem, passphrase) {
122
+ let key;
123
+ try {
124
+ key = crypto.createPrivateKey(passphrase ? { key: pem, passphrase } : pem);
125
+ }
126
+ catch (err) {
127
+ throw new Error(`could not load private key: ${err?.message ?? err}`);
128
+ }
129
+ if (key.asymmetricKeyType !== 'rsa') {
130
+ throw new Error(`private key is ${key.asymmetricKeyType}, not RSA`);
131
+ }
132
+ if (modulusBits(key) < ota_protocol_1.MIN_RSA_MODULUS_BITS) {
133
+ throw new Error(`private key modulus below ${ota_protocol_1.MIN_RSA_MODULUS_BITS} bits`);
134
+ }
135
+ return key;
136
+ }
137
+ /**
138
+ * Serialize + RSA-SHA256 sign a release payload, then self-verify. Throws if the
139
+ * payload is invalid (codec validation), the key is not usable RSA, or the
140
+ * self-verify fails.
141
+ */
142
+ function signReleasePayload(payload, privateKeyPem, passphrase) {
143
+ const bytes = (0, ota_protocol_1.serializeSignedRelease)(payload);
144
+ const privateKey = loadRsaPrivateKey(privateKeyPem, passphrase);
145
+ const signature = crypto.sign('sha256', Buffer.from(bytes), privateKey);
146
+ // Self-check with the derived public key — the same check the backend runs
147
+ // after signing (PROMPT §7.9). A failure here means we would have shipped an
148
+ // unverifiable release.
149
+ const publicKey = crypto.createPublicKey(privateKey);
150
+ if (!crypto.verify('sha256', Buffer.from(bytes), publicKey, signature)) {
151
+ throw new Error('self-verify failed: produced signature does not verify with its own public key');
152
+ }
153
+ return {
154
+ signedPayload: (0, ota_protocol_1.encodeBase64)(bytes),
155
+ signature: signature.toString('base64'),
156
+ payloadBytes: bytes,
157
+ };
158
+ }
159
+ /** Build the full transport envelope (docs §4) around a signed payload. */
160
+ function buildReleaseEnvelope(payload, privateKeyPem, opts) {
161
+ const signed = signReleasePayload(payload, privateKeyPem, opts?.passphrase);
162
+ return {
163
+ protocol: ota_protocol_1.SIGNATURE_ALGORITHM,
164
+ keyId: payload.keyId,
165
+ signedPayload: signed.signedPayload,
166
+ signature: signed.signature,
167
+ downloadUrl: opts?.downloadUrl,
168
+ displayMetadata: opts?.displayMetadata,
169
+ };
170
+ }
171
+ //# sourceMapp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C;IAC9C,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC;IACxE,2EAA2E;IAC3E,6EAA6E;IAC7E,wBAAwB;IACxB,MAAM,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,CAAC;IACD,OAAO;QACL,aAAa,EAAE,IAAA,2BAAY,EAAC,KAAK,CAAC;QAClC,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACvC,YAAY,EAAE,KAAK;KACpB,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,SAAgB,oBAAoB,CAClC,OAAgC,EAChC,aAA8B,EAC9B,IAA+F;IAE/F,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5E,OAAO;QACL,QAAQ,EAAE,kCAAmB;QAC7B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,IAAI,EAAE,WAAW;QAC9B,eAAe,EAAE,IAAI,EAAE,eAAe;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Standard Base64 for the transport envelope (docs §4).
3
+ *
4
+ * Decoding is STRICT and canonical: only the standard alphabet, correct padding,
5
+ * length a multiple of 4, and — crucially — the decode→re-encode round trip must
6
+ * reproduce the input exactly. That last check rejects "alternative encodings"
7
+ * (non-zero unused trailing bits), which is a protocol requirement.
8
+ */
9
+ export declare function encodeBase64(bytes: Uint8Array): string;
10
+ export declare function decodeBase64Strict(value: string, maxBytes: number, what?: string): Uint8Array;
11
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../src/vendor/ota-protocol/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEtD;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,SAAW,GACd,UAAU,CAoBZ"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Standard Base64 for the transport envelope (docs §4).
4
+ *
5
+ * Decoding is STRICT and canonical: only the standard alphabet, correct padding,
6
+ * length a multiple of 4, and — crucially — the decode→re-encode round trip must
7
+ * reproduce the input exactly. That last check rejects "alternative encodings"
8
+ * (non-zero unused trailing bits), which is a protocol requirement.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.encodeBase64 = encodeBase64;
12
+ exports.decodeBase64Strict = decodeBase64Strict;
13
+ const types_1 = require("./types");
14
+ const STD_B64 = /^[A-Za-z0-9+/]*={0,2}$/;
15
+ function encodeBase64(bytes) {
16
+ return Buffer.from(bytes).toString('base64');
17
+ }
18
+ function decodeBase64Strict(value, maxBytes, what = 'base64') {
19
+ if (typeof value !== 'string' || value.length === 0) {
20
+ throw new types_1.OtaProtocolError('INVALID_BASE64', `${what}: empty or not a string`);
21
+ }
22
+ // Reject oversized inputs before allocating (a base64 char is ~0.75 bytes).
23
+ if (value.length > Math.ceil((maxBytes * 4) / 3) + 4) {
24
+ throw new types_1.OtaProtocolError('INVALID_BASE64', `${what}: exceeds size limit`);
25
+ }
26
+ if (value.length % 4 !== 0 || !STD_B64.test(value)) {
27
+ throw new types_1.OtaProtocolError('INVALID_BASE64', `${what}: not canonical standard base64`);
28
+ }
29
+ const decoded = Buffer.from(value, 'base64');
30
+ // Buffer.from is lenient; enforce canonical form by re-encoding.
31
+ if (decoded.toString('base64') !== value) {
32
+ throw new types_1.OtaProtocolError('INVALID_BASE64', `${what}: non-canonical base64`);
33
+ }
34
+ if (decoded.length > maxBytes) {
35
+ throw new types_1.OtaProtocolError('INVALID_BASE64', `${what}: decoded size exceeds limit`);
36
+ }
37
+ return new Uint8Array(decoded);
38
+ }
39
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../src/vendor/ota-protocol/base64.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAMH,oCAEC;AAED,gDAwBC;AAhCD,mCAA2C;AAE3C,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAEzC,SAAgB,YAAY,CAAC,KAAiB;IAC5C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,kBAAkB,CAChC,KAAa,EACb,QAAgB,EAChB,IAAI,GAAG,QAAQ;IAEf,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,wBAAgB,CAAC,gBAAgB,EAAE,GAAG,IAAI,yBAAyB,CAAC,CAAC;IACjF,CAAC;IACD,4EAA4E;IAC5E,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,wBAAgB,CAAC,gBAAgB,EAAE,GAAG,IAAI,sBAAsB,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,wBAAgB,CAAC,gBAAgB,EAAE,GAAG,IAAI,iCAAiC,CAAC,CAAC;IACzF,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7C,iEAAiE;IACjE,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,KAAK,EAAE,CAAC;QACzC,MAAM,IAAI,wBAAgB,CAAC,gBAAgB,EAAE,GAAG,IAAI,wBAAwB,CAAC,CAAC;IAChF,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,wBAAgB,CAAC,gBAAgB,EAAE,GAAG,IAAI,8BAA8B,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Byte-exact serializer + bounds-checked parser for the ScaleBunSignedReleaseV1
3
+ * binary payload. This is the TypeScript REFERENCE implementation; the Kotlin and
4
+ * Swift verifiers and the backend must match it byte-for-byte against the
5
+ * committed fixtures. See docs/ota/SB-OTA-RSA-SHA256-V1.md.
6
+ *
7
+ * The signature is computed/verified over the exact bytes produced by
8
+ * {@link serializeSignedRelease}; verifiers must NOT re-serialize a parsed struct.
9
+ */
10
+ import { ScaleBunSignedReleaseV1 } from './types';
11
+ /** Serialize a signed release, validating every field and the overall limits. */
12
+ export declare function serializeSignedRelease(p: ScaleBunSignedReleaseV1): Uint8Array;
13
+ /**
14
+ * Parse + fully validate a signed payload. Throws {@link OtaProtocolError} with a
15
+ * stable code on any structural, enum, range, or consistency violation, on
16
+ * invalid UTF-8, on an oversized length prefix, and on trailing bytes.
17
+ */
18
+ export declare function parseSignedRelease(bytes: Uint8Array): ScaleBunSignedReleaseV1;
19
+ /**
20
+ * Parse ONLY enough of the payload to extract `keyId` (docs §5 step 4/5), so a
21
+ * verifier can resolve the trusted key before spending an RSA verify. Still fully
22
+ * bounds-checked. The returned keyId is NOT authenticated until the signature is
23
+ * verified over the whole payload.
24
+ */
25
+ export declare function peekKeyId(bytes: Uint8Array): string;
26
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/vendor/ota-protocol/codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,EAAoB,uBAAuB,EAAgC,MAAM,SAAS,CAAC;AAqElG,iFAAiF;AACjF,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,uBAAuB,GAAG,UAAU,CAwE7E;AAgED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,uBAAuB,CAkH7E;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAmBnD"}
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ /**
3
+ * Byte-exact serializer + bounds-checked parser for the ScaleBunSignedReleaseV1
4
+ * binary payload. This is the TypeScript REFERENCE implementation; the Kotlin and
5
+ * Swift verifiers and the backend must match it byte-for-byte against the
6
+ * committed fixtures. See docs/ota/SB-OTA-RSA-SHA256-V1.md.
7
+ *
8
+ * The signature is computed/verified over the exact bytes produced by
9
+ * {@link serializeSignedRelease}; verifiers must NOT re-serialize a parsed struct.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.serializeSignedRelease = serializeSignedRelease;
13
+ exports.parseSignedRelease = parseSignedRelease;
14
+ exports.peekKeyId = peekKeyId;
15
+ const limits_1 = require("./limits");
16
+ const types_1 = require("./types");
17
+ const hex_1 = require("./hex");
18
+ const utf8Encoder = new TextEncoder();
19
+ const utf8DecoderFatal = new TextDecoder('utf-8', { fatal: true });
20
+ // ─── serialize ──────────────────────────────────────────────────────────────
21
+ class ByteWriter {
22
+ constructor() {
23
+ this.out = [];
24
+ }
25
+ u16(n) {
26
+ this.out.push((n >>> 8) & 0xff, n & 0xff);
27
+ }
28
+ u32(n) {
29
+ this.out.push((n >>> 24) & 0xff, (n >>> 16) & 0xff, (n >>> 8) & 0xff, n & 0xff);
30
+ }
31
+ u64(n) {
32
+ let big = BigInt(n);
33
+ const bytes = new Array(8);
34
+ for (let i = 7; i >= 0; i--) {
35
+ bytes[i] = Number(big & 0xffn);
36
+ big >>= 8n;
37
+ }
38
+ this.out.push(...bytes);
39
+ }
40
+ bytes(b) {
41
+ for (let i = 0; i < b.length; i++)
42
+ this.out.push(b[i]);
43
+ }
44
+ lenBytes(b) {
45
+ this.u32(b.length);
46
+ this.bytes(b);
47
+ }
48
+ string(s) {
49
+ this.lenBytes(utf8Encoder.encode(s));
50
+ }
51
+ finish() {
52
+ return Uint8Array.from(this.out);
53
+ }
54
+ }
55
+ function requireEnum(value, allowed, field) {
56
+ if (!allowed.includes(value)) {
57
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: invalid value ${JSON.stringify(value)}`);
58
+ }
59
+ return value;
60
+ }
61
+ function requireString(value, field, minLen) {
62
+ if (typeof value !== 'string') {
63
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: not a string`);
64
+ }
65
+ const byteLen = utf8Encoder.encode(value).length;
66
+ if (byteLen < minLen) {
67
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: too short`);
68
+ }
69
+ if (byteLen > limits_1.MAX_STRING_FIELD_BYTES) {
70
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: exceeds ${limits_1.MAX_STRING_FIELD_BYTES} bytes`);
71
+ }
72
+ return value;
73
+ }
74
+ function requireUint(value, field, min = 0) {
75
+ if (!Number.isInteger(value) || value < min || value > limits_1.MAX_SAFE_UINT64) {
76
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: out of range`);
77
+ }
78
+ return value;
79
+ }
80
+ /** Serialize a signed release, validating every field and the overall limits. */
81
+ function serializeSignedRelease(p) {
82
+ if (p.signatureAlgorithm !== limits_1.SIGNATURE_ALGORITHM) {
83
+ throw new types_1.OtaProtocolError('UNSUPPORTED_SIGNATURE_ALGORITHM', p.signatureAlgorithm);
84
+ }
85
+ if (p.hashAlgorithm !== limits_1.HASH_ALGORITHM) {
86
+ throw new types_1.OtaProtocolError('UNSUPPORTED_HASH_ALGORITHM', p.hashAlgorithm);
87
+ }
88
+ const platform = requireEnum(p.platform, limits_1.PLATFORMS, 'platform');
89
+ const artifactType = requireEnum(p.artifactType, limits_1.ARTIFACT_TYPES, 'artifactType');
90
+ requireString(p.keyId, 'keyId', 1);
91
+ requireString(p.projectId, 'projectId', 1);
92
+ requireString(p.applicationId, 'applicationId', 1);
93
+ requireString(p.releaseId, 'releaseId', 1);
94
+ requireString(p.bundleId, 'bundleId', 1);
95
+ requireString(p.targetAppVersion, 'targetAppVersion', 0);
96
+ requireString(p.targetRuntimeVersion, 'targetRuntimeVersion', 0);
97
+ requireString(p.minimumSdkVersion, 'minimumSdkVersion', 0);
98
+ requireUint(p.releaseSequence, 'releaseSequence');
99
+ requireUint(p.issuedAtEpochSeconds, 'issuedAtEpochSeconds', 1);
100
+ requireUint(p.expiresAtEpochSeconds, 'expiresAtEpochSeconds', 0);
101
+ requireUint(p.artifactSize, 'artifactSize', 1);
102
+ if (p.expiresAtEpochSeconds !== 0 && p.expiresAtEpochSeconds < p.issuedAtEpochSeconds) {
103
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'expiresAt < issuedAt');
104
+ }
105
+ const artifactSha = (0, hex_1.hexToBytes)(p.artifactSha256, limits_1.SHA256_LEN);
106
+ const resultSha = (0, hex_1.hexToBytes)(p.resultArtifactSha256, limits_1.SHA256_LEN);
107
+ // full/patch consistency (docs §3.3).
108
+ let baseBundleId = '';
109
+ let baseSha = new Uint8Array(0);
110
+ if (artifactType === 'patch') {
111
+ baseBundleId = requireString(p.baseBundleId, 'baseBundleId', 1);
112
+ baseSha = (0, hex_1.hexToBytes)(p.baseArtifactSha256, limits_1.SHA256_LEN);
113
+ }
114
+ else {
115
+ if (p.baseBundleId !== '' || p.baseArtifactSha256 !== '') {
116
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'full artifact must not carry base fields');
117
+ }
118
+ }
119
+ const w = new ByteWriter();
120
+ w.bytes(limits_1.MAGIC_BYTES);
121
+ w.u16(limits_1.SCHEMA_VERSION);
122
+ w.string(limits_1.SIGNATURE_ALGORITHM);
123
+ w.string(limits_1.HASH_ALGORITHM);
124
+ w.string(p.keyId);
125
+ w.string(p.projectId);
126
+ w.string(p.applicationId);
127
+ w.string(p.releaseId);
128
+ w.string(p.bundleId);
129
+ w.string(platform);
130
+ w.string(artifactType);
131
+ w.string(p.targetAppVersion);
132
+ w.string(p.targetRuntimeVersion);
133
+ w.string(p.minimumSdkVersion);
134
+ w.u64(p.releaseSequence);
135
+ w.u64(p.issuedAtEpochSeconds);
136
+ w.u64(p.expiresAtEpochSeconds);
137
+ w.u64(p.artifactSize);
138
+ w.bytes(artifactSha);
139
+ w.string(baseBundleId);
140
+ w.lenBytes(baseSha);
141
+ w.bytes(resultSha);
142
+ const bytes = w.finish();
143
+ if (bytes.length > limits_1.MAX_SIGNED_PAYLOAD_BYTES) {
144
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `payload exceeds ${limits_1.MAX_SIGNED_PAYLOAD_BYTES} bytes`);
145
+ }
146
+ return bytes;
147
+ }
148
+ // ─── parse ──────────────────────────────────────────────────────────────────
149
+ class ByteReader {
150
+ constructor(buf) {
151
+ this.buf = buf;
152
+ this.pos = 0;
153
+ }
154
+ ensure(n) {
155
+ if (n < 0 || this.pos + n > this.buf.length) {
156
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'truncated payload');
157
+ }
158
+ }
159
+ fixed(n) {
160
+ this.ensure(n);
161
+ const slice = this.buf.subarray(this.pos, this.pos + n);
162
+ this.pos += n;
163
+ return slice;
164
+ }
165
+ u16() {
166
+ const b = this.fixed(2);
167
+ return (b[0] << 8) | b[1];
168
+ }
169
+ u32() {
170
+ const b = this.fixed(4);
171
+ // multiplication avoids the sign bit that << would set for values ≥ 2^31.
172
+ return b[0] * 0x1000000 + (b[1] << 16) + (b[2] << 8) + b[3];
173
+ }
174
+ u64() {
175
+ const b = this.fixed(8);
176
+ let big = 0n;
177
+ for (let i = 0; i < 8; i++)
178
+ big = (big << 8n) | BigInt(b[i]);
179
+ if (big > BigInt(limits_1.MAX_SAFE_UINT64)) {
180
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'uint64 exceeds safe range');
181
+ }
182
+ return Number(big);
183
+ }
184
+ lenBytes(max, field) {
185
+ const len = this.u32();
186
+ if (len > max) {
187
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: length ${len} exceeds ${max}`);
188
+ }
189
+ return this.fixed(len);
190
+ }
191
+ string(max, field) {
192
+ const bytes = this.lenBytes(max, field);
193
+ try {
194
+ return utf8DecoderFatal.decode(bytes);
195
+ }
196
+ catch {
197
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${field}: invalid UTF-8`);
198
+ }
199
+ }
200
+ remaining() {
201
+ return this.buf.length - this.pos;
202
+ }
203
+ }
204
+ function equalBytes(a, b) {
205
+ if (a.length !== b.length)
206
+ return false;
207
+ let diff = 0;
208
+ for (let i = 0; i < a.length; i++)
209
+ diff |= a[i] ^ b[i];
210
+ return diff === 0;
211
+ }
212
+ /**
213
+ * Parse + fully validate a signed payload. Throws {@link OtaProtocolError} with a
214
+ * stable code on any structural, enum, range, or consistency violation, on
215
+ * invalid UTF-8, on an oversized length prefix, and on trailing bytes.
216
+ */
217
+ function parseSignedRelease(bytes) {
218
+ if (!(bytes instanceof Uint8Array)) {
219
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'input is not bytes');
220
+ }
221
+ if (bytes.length > limits_1.MAX_SIGNED_PAYLOAD_BYTES) {
222
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'payload exceeds size limit');
223
+ }
224
+ const r = new ByteReader(bytes);
225
+ const magic = r.fixed(limits_1.MAGIC_BYTES.length);
226
+ if (!equalBytes(magic, limits_1.MAGIC_BYTES)) {
227
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'bad magic');
228
+ }
229
+ const schemaVersion = r.u16();
230
+ if (schemaVersion !== limits_1.SCHEMA_VERSION) {
231
+ throw new types_1.OtaProtocolError('UNSUPPORTED_SCHEMA', `schemaVersion ${schemaVersion}`);
232
+ }
233
+ const signatureAlgorithm = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'signatureAlgorithm');
234
+ if (signatureAlgorithm !== limits_1.SIGNATURE_ALGORITHM) {
235
+ throw new types_1.OtaProtocolError('UNSUPPORTED_SIGNATURE_ALGORITHM', signatureAlgorithm);
236
+ }
237
+ const hashAlgorithm = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'hashAlgorithm');
238
+ if (hashAlgorithm !== limits_1.HASH_ALGORITHM) {
239
+ throw new types_1.OtaProtocolError('UNSUPPORTED_HASH_ALGORITHM', hashAlgorithm);
240
+ }
241
+ const keyId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'keyId');
242
+ const projectId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'projectId');
243
+ const applicationId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'applicationId');
244
+ const releaseId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'releaseId');
245
+ const bundleId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'bundleId');
246
+ for (const [name, v] of [
247
+ ['keyId', keyId],
248
+ ['projectId', projectId],
249
+ ['applicationId', applicationId],
250
+ ['releaseId', releaseId],
251
+ ['bundleId', bundleId],
252
+ ]) {
253
+ if (v.length === 0)
254
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `${name}: empty`);
255
+ }
256
+ const platformStr = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'platform');
257
+ if (!limits_1.PLATFORMS.includes(platformStr)) {
258
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `platform: ${platformStr}`);
259
+ }
260
+ const artifactTypeStr = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'artifactType');
261
+ if (!limits_1.ARTIFACT_TYPES.includes(artifactTypeStr)) {
262
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', `artifactType: ${artifactTypeStr}`);
263
+ }
264
+ const platform = platformStr;
265
+ const artifactType = artifactTypeStr;
266
+ const targetAppVersion = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'targetAppVersion');
267
+ const targetRuntimeVersion = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'targetRuntimeVersion');
268
+ const minimumSdkVersion = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'minimumSdkVersion');
269
+ const releaseSequence = r.u64();
270
+ const issuedAtEpochSeconds = r.u64();
271
+ const expiresAtEpochSeconds = r.u64();
272
+ const artifactSize = r.u64();
273
+ if (issuedAtEpochSeconds === 0) {
274
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'issuedAt is zero');
275
+ }
276
+ if (artifactSize === 0) {
277
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'artifactSize is zero');
278
+ }
279
+ if (expiresAtEpochSeconds !== 0 && expiresAtEpochSeconds < issuedAtEpochSeconds) {
280
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'expiresAt < issuedAt');
281
+ }
282
+ const artifactSha256 = (0, hex_1.bytesToHex)(r.fixed(limits_1.SHA256_LEN));
283
+ const baseBundleId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'baseBundleId');
284
+ const baseShaBytes = r.lenBytes(limits_1.SHA256_LEN, 'baseArtifactSha256');
285
+ const resultArtifactSha256 = (0, hex_1.bytesToHex)(r.fixed(limits_1.SHA256_LEN));
286
+ // full/patch consistency (docs §3.3).
287
+ if (artifactType === 'full') {
288
+ if (baseBundleId.length !== 0 || baseShaBytes.length !== 0) {
289
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'full artifact carries base fields');
290
+ }
291
+ }
292
+ else {
293
+ if (baseBundleId.length === 0 || baseShaBytes.length !== limits_1.SHA256_LEN) {
294
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'patch artifact missing base fields');
295
+ }
296
+ }
297
+ if (r.remaining() !== 0) {
298
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'trailing bytes after payload');
299
+ }
300
+ return {
301
+ signatureAlgorithm,
302
+ hashAlgorithm,
303
+ keyId,
304
+ projectId,
305
+ applicationId,
306
+ releaseId,
307
+ bundleId,
308
+ platform,
309
+ artifactType,
310
+ targetAppVersion,
311
+ targetRuntimeVersion,
312
+ minimumSdkVersion,
313
+ releaseSequence,
314
+ issuedAtEpochSeconds,
315
+ expiresAtEpochSeconds,
316
+ artifactSize,
317
+ artifactSha256,
318
+ baseBundleId,
319
+ baseArtifactSha256: baseShaBytes.length === limits_1.SHA256_LEN ? (0, hex_1.bytesToHex)(baseShaBytes) : '',
320
+ resultArtifactSha256,
321
+ };
322
+ }
323
+ /**
324
+ * Parse ONLY enough of the payload to extract `keyId` (docs §5 step 4/5), so a
325
+ * verifier can resolve the trusted key before spending an RSA verify. Still fully
326
+ * bounds-checked. The returned keyId is NOT authenticated until the signature is
327
+ * verified over the whole payload.
328
+ */
329
+ function peekKeyId(bytes) {
330
+ if (bytes.length > limits_1.MAX_SIGNED_PAYLOAD_BYTES) {
331
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'payload exceeds size limit');
332
+ }
333
+ const r = new ByteReader(bytes);
334
+ const magic = r.fixed(limits_1.MAGIC_BYTES.length);
335
+ if (!equalBytes(magic, limits_1.MAGIC_BYTES)) {
336
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'bad magic');
337
+ }
338
+ if (r.u16() !== limits_1.SCHEMA_VERSION) {
339
+ throw new types_1.OtaProtocolError('UNSUPPORTED_SCHEMA', 'schemaVersion');
340
+ }
341
+ r.string(limits_1.MAX_STRING_FIELD_BYTES, 'signatureAlgorithm');
342
+ r.string(limits_1.MAX_STRING_FIELD_BYTES, 'hashAlgorithm');
343
+ const keyId = r.string(limits_1.MAX_STRING_FIELD_BYTES, 'keyId');
344
+ if (keyId.length === 0) {
345
+ throw new types_1.OtaProtocolError('INVALID_SIGNED_PAYLOAD', 'keyId: empty');
346
+ }
347
+ return keyId;
348
+ }
349
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/vendor/ota-protocol/codec.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAoFH,wDAwEC;AAqED,gDAkHC;AAQD,8BAmBC;AA5WD,qCAWkB;AAClB,mCAAkG;AAClG,+BAA+C;AAE/C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,gBAAgB,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAEnE,+EAA+E;AAE/E,MAAM,UAAU;IAAhB;QACmB,QAAG,GAAa,EAAE,CAAC;IA8BtC,CAAC;IA5BC,GAAG,CAAC,CAAS;QACX,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD,GAAG,CAAC,CAAS;QACX,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC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gBAAU,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;QACtF,oBAAoB;KACrB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,KAAiB;IACzC,IAAI,KAAK,CAAC,MAAM,GAAG,iCAAwB,EAAE,CAAC;QAC5C,MAAM,IAAI,wBAAgB,CAAC,wBAAwB,EAAE,4BAA4B,CAAC,CAAC;IACrF,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,oBAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,oBAAW,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,wBAAgB,CAAC,wBAAwB,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,uBAAc,EAAE,CAAC;QAC/B,MAAM,IAAI,wBAAgB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;IACD,CAAC,CAAC,MAAM,CAAC,+BAAsB,EAAE,oBAAoB,CAAC,CAAC;IACvD,CAAC,CAAC,MAAM,CAAC,+BAAsB,EAAE,eAAe,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,+BAAsB,EAAE,OAAO,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,wBAAgB,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Strict lowercase-hex helpers (no `0x`, even length, exact alphabet). */
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ /**
4
+ * Parse hex to bytes, rejecting anything that is not canonical lowercase-or-mixed
5
+ * hex of even length. `expectedLen`, when given, pins the output byte count.
6
+ */
7
+ export declare function hexToBytes(hex: string, expectedLen?: number): Uint8Array;
8
+ //# sourceMappingURL=hex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../src/vendor/ota-protocol/hex.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAI3E,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMpD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,CAexE"}