@scalebun/react-native 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 (115) hide show
  1. package/android/build.gradle +8 -0
  2. package/android/src/androidTest/java/com/scalebun/rn/ota/ScaleBunOtaVerifierInstrumentedTest.kt +112 -0
  3. package/android/src/main/java/com/scalebun/rn/ota/BundleDownloader.kt +10 -0
  4. package/android/src/main/java/com/scalebun/rn/ota/DeviceIntegrity.kt +75 -0
  5. package/android/src/main/java/com/scalebun/rn/ota/OtaProtocol.kt +244 -0
  6. package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaKeyRegistry.kt +100 -0
  7. package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaModule.kt +132 -62
  8. package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaReleaseVerifier.kt +129 -0
  9. package/android/src/main/java/com/scalebun/rn/ota/SlotManager.kt +80 -1
  10. package/android/src/main/java/com/scalebun/rn/ota/TlsPinning.kt +118 -0
  11. package/android/src/oldarch/java/com/scalebun/rn/ota/ScaleBunOtaSpec.kt +6 -8
  12. package/dist/scalebun.full.js +964 -533
  13. package/dist/scalebun.slim.js +962 -531
  14. package/ios/Ota/OtaProtocol.swift +242 -0
  15. package/ios/Ota/OtaSlotManager.swift +26 -0
  16. package/ios/Ota/ScaleBunOtaBridge.mm +6 -3
  17. package/ios/Ota/ScaleBunOtaKeyRegistry.swift +147 -0
  18. package/ios/Ota/ScaleBunOtaModule.swift +125 -53
  19. package/ios/Ota/ScaleBunOtaReleaseVerifier.swift +115 -0
  20. package/ios/Ota/ScaleBunOtaVerifierTests.swift +92 -0
  21. package/ios/ReplaySdk.swift +65 -2
  22. package/lib/commonjs/bootstrap/SDKBootstrapper.js +30 -0
  23. package/lib/commonjs/core/config/schema.js +19 -12
  24. package/lib/commonjs/core/constants/version.js +1 -1
  25. package/lib/commonjs/features/journey/ScaleBunDebugRoot.js +293 -5
  26. package/lib/commonjs/features/journey/ScaleBunScrollView.js +28 -0
  27. package/lib/commonjs/features/journey/autoInstrumentScroll.js +161 -0
  28. package/lib/commonjs/features/journey/interactionProtocol.js +131 -10
  29. package/lib/commonjs/features/journey/scrollContext.js +146 -0
  30. package/lib/commonjs/features/journey/targetGeometry.js +164 -0
  31. package/lib/commonjs/features/journey/touchTarget.js +152 -24
  32. package/lib/commonjs/features/journey/uiState.js +81 -1
  33. package/lib/commonjs/features/navigation/AutoScreenDetector.js +74 -5
  34. package/lib/commonjs/features/network/NetworkFeature.js +39 -5
  35. package/lib/commonjs/features/network/thirdParty.js +90 -0
  36. package/lib/commonjs/features/ota/OtaOrchestrator.js +175 -80
  37. package/lib/commonjs/features/session/SessionManager.js +63 -0
  38. package/lib/commonjs/public/ScaleBunFacade.js +23 -57
  39. package/lib/module/bootstrap/SDKBootstrapper.js +30 -0
  40. package/lib/module/core/config/schema.js +19 -12
  41. package/lib/module/core/constants/version.js +1 -1
  42. package/lib/module/features/journey/ScaleBunDebugRoot.js +295 -7
  43. package/lib/module/features/journey/ScaleBunScrollView.js +28 -0
  44. package/lib/module/features/journey/autoInstrumentScroll.js +155 -0
  45. package/lib/module/features/journey/interactionProtocol.js +128 -8
  46. package/lib/module/features/journey/scrollContext.js +135 -0
  47. package/lib/module/features/journey/targetGeometry.js +155 -0
  48. package/lib/module/features/journey/touchTarget.js +151 -24
  49. package/lib/module/features/journey/uiState.js +78 -1
  50. package/lib/module/features/navigation/AutoScreenDetector.js +74 -5
  51. package/lib/module/features/network/NetworkFeature.js +38 -4
  52. package/lib/module/features/network/thirdParty.js +83 -0
  53. package/lib/module/features/ota/OtaOrchestrator.js +175 -80
  54. package/lib/module/features/session/SessionManager.js +63 -0
  55. package/lib/module/public/ScaleBunFacade.js +23 -57
  56. package/lib/typescript/core/config/schema.d.ts +2 -3
  57. package/lib/typescript/core/constants/version.d.ts +1 -1
  58. package/lib/typescript/features/journey/autoInstrumentScroll.d.ts +46 -0
  59. package/lib/typescript/features/journey/interactionProtocol.d.ts +139 -1
  60. package/lib/typescript/features/journey/scrollContext.d.ts +85 -0
  61. package/lib/typescript/features/journey/targetGeometry.d.ts +114 -0
  62. package/lib/typescript/features/journey/touchTarget.d.ts +148 -15
  63. package/lib/typescript/features/journey/uiState.d.ts +39 -0
  64. package/lib/typescript/features/navigation/AutoScreenDetector.d.ts +48 -2
  65. package/lib/typescript/features/network/index.d.ts +18 -0
  66. package/lib/typescript/features/network/thirdParty.d.ts +65 -0
  67. package/lib/typescript/features/ota/OtaOrchestrator.d.ts +12 -8
  68. package/lib/typescript/features/ota/OtaTypes.d.ts +22 -0
  69. package/lib/typescript/features/session/SessionManager.d.ts +55 -0
  70. package/lib/typescript/public/ScaleBunFacade.d.ts +5 -11
  71. package/lib/typescript/public/types.d.ts +10 -0
  72. package/lib/typescript/specs/NativeScaleBunOta.d.ts +32 -20
  73. package/package.json +3 -13
  74. package/scalebun-react-native.podspec +4 -0
  75. package/src/bootstrap/SDKBootstrapper.ts +40 -0
  76. package/src/core/config/schema.ts +21 -9
  77. package/src/core/constants/version.ts +1 -1
  78. package/src/features/journey/ScaleBunDebugRoot.tsx +288 -7
  79. package/src/features/journey/ScaleBunScrollView.tsx +29 -0
  80. package/src/features/journey/autoInstrumentScroll.ts +155 -0
  81. package/src/features/journey/interactionProtocol.ts +188 -10
  82. package/src/features/journey/scrollContext.ts +137 -0
  83. package/src/features/journey/targetGeometry.ts +176 -0
  84. package/src/features/journey/touchTarget.ts +237 -26
  85. package/src/features/journey/uiState.ts +80 -1
  86. package/src/features/navigation/AutoScreenDetector.ts +65 -5
  87. package/src/features/network/NetworkFeature.ts +41 -4
  88. package/src/features/network/index.ts +18 -0
  89. package/src/features/network/thirdParty.ts +92 -0
  90. package/src/features/ota/OtaOrchestrator.ts +190 -90
  91. package/src/features/ota/OtaTypes.ts +23 -1
  92. package/src/features/session/SessionManager.ts +113 -0
  93. package/src/public/ScaleBunFacade.ts +23 -69
  94. package/src/public/types.ts +10 -0
  95. package/src/specs/NativeScaleBunOta.ts +35 -20
  96. package/lib/commonjs/features/ota/crypto/builtinVerifier.js +0 -248
  97. package/lib/commonjs/features/ota/crypto/loadEd25519.js +0 -40
  98. package/lib/commonjs/features/ota/crypto/loadSha512.js +0 -40
  99. package/lib/commonjs/features/ota/crypto/nativeVerifier.js +0 -121
  100. package/lib/commonjs/features/ota/signature.js +0 -175
  101. package/lib/module/features/ota/crypto/builtinVerifier.js +0 -240
  102. package/lib/module/features/ota/crypto/loadEd25519.js +0 -34
  103. package/lib/module/features/ota/crypto/loadSha512.js +0 -34
  104. package/lib/module/features/ota/crypto/nativeVerifier.js +0 -113
  105. package/lib/module/features/ota/signature.js +0 -169
  106. package/lib/typescript/features/ota/crypto/builtinVerifier.d.ts +0 -53
  107. package/lib/typescript/features/ota/crypto/loadEd25519.d.ts +0 -30
  108. package/lib/typescript/features/ota/crypto/loadSha512.d.ts +0 -15
  109. package/lib/typescript/features/ota/crypto/nativeVerifier.d.ts +0 -35
  110. package/lib/typescript/features/ota/signature.d.ts +0 -81
  111. package/src/features/ota/crypto/builtinVerifier.ts +0 -257
  112. package/src/features/ota/crypto/loadEd25519.ts +0 -41
  113. package/src/features/ota/crypto/loadSha512.ts +0 -35
  114. package/src/features/ota/crypto/nativeVerifier.ts +0 -117
  115. package/src/features/ota/signature.ts +0 -206
@@ -1,113 +0,0 @@
1
- /**
2
- * Native ed25519 verifier — platform crypto wrapped as a SignatureVerifier.
3
- *
4
- * WHY IT EXISTS. The built-in @noble verifier runs in JS, inside the very
5
- * bundle it protects: an attacker who lands one malicious bundle can neuter a
6
- * JS check for every update after it. Platform crypto (CryptoKit on iOS,
7
- * Android's conscrypt on API 33+) sits outside the bundle's reach — and using
8
- * it also drops the runtime dependency on the optional @noble peers wherever
9
- * the OS provides ed25519.
10
- *
11
- * WHAT IT DOES NOT FIX, stated plainly: the ORCHESTRATION still lives in JS.
12
- * A hostile bundle can skip calling any verifier and drive the native staging
13
- * methods directly. Moving the crypto native shrinks the attack surface (no
14
- * more tampering with a bundled crypto lib to flip a verdict) but the full
15
- * close needs native-ENFORCED staging with a natively-pinned key — an
16
- * architectural change tracked separately, not smuggled into this one.
17
- *
18
- * VERDICT CONTRACT (mirrors the spec): the native side resolves
19
- * 'valid' | 'invalid' | 'unavailable'. 'invalid' is a definitive NO.
20
- * 'unavailable' (Android < 33, malformed input, machinery failure) means this
21
- * source cannot answer — the composed verifier below then delegates to the
22
- * @noble builtin, and when that is absent too it THROWS, which the policy
23
- * layer converts to a rejection. Every path that cannot verify refuses.
24
- */
25
-
26
- import NativeScaleBunOta from '../../../specs/NativeScaleBunOta';
27
- import { logger } from '../../../core/logger/internalLogger';
28
- import { decodeSignature, getBuiltinVerifier } from './builtinVerifier';
29
- const ED25519_PUBLIC_KEY_HEX_CHARS = 64;
30
-
31
- /** bytes → lowercase hex (the native side takes clean hex only). */
32
- function bytesToHex(bytes) {
33
- let out = '';
34
- for (const b of bytes) out += b.toString(16).padStart(2, '0');
35
- return out;
36
- }
37
-
38
- /** Strict lowercase-hex normalization; null when the value is not hex. */
39
- function normalizeHex(value, expectedChars) {
40
- const clean = value.trim().toLowerCase().replace(/^0x/, '');
41
- if (clean.length !== expectedChars || /[^0-9a-f]/.test(clean)) return null;
42
- return clean;
43
- }
44
- let resolved;
45
-
46
- /**
47
- * The native-first verifier, or null when the native module (or its
48
- * verifyEd25519 method — an app running new JS against an old binary) is
49
- * absent. Cached like the builtin: module availability does not change at
50
- * runtime, and this is consulted on every update check.
51
- */
52
- export function getNativeVerifier() {
53
- if (resolved !== undefined) return resolved;
54
- const native = NativeScaleBunOta;
55
- if (!native || typeof native.verifyEd25519 !== 'function') {
56
- // Old binary, Jest, web/SSR — not an error, just not this source.
57
- resolved = null;
58
- return null;
59
- }
60
- resolved = async ({
61
- messageHex,
62
- signature,
63
- publicKey
64
- }) => {
65
- // All decoding and validation happens HERE, in one place, so both
66
- // platforms' native code only ever sees clean fixed-length hex. The
67
- // signature may arrive hex or base64 (the wire allows both) — reuse
68
- // the builtin's decoder rather than growing a second, subtly
69
- // different one.
70
- const message = normalizeHex(messageHex, 64);
71
- const key = normalizeHex(publicKey, ED25519_PUBLIC_KEY_HEX_CHARS);
72
- const sigBytes = decodeSignature(signature);
73
- if (!message || !key || !sigBytes) {
74
- // Same messages-by-symptom philosophy as the builtin: a mistyped
75
- // key must not present as "every update is a forgery".
76
- logger.error('[OTA] Signature inputs malformed (bundle hash, signature, or public key) — refusing to stage.');
77
- return false;
78
- }
79
- let verdict;
80
- try {
81
- verdict = await native.verifyEd25519(message, bytesToHex(sigBytes), key);
82
- } catch (err) {
83
- // A rejected promise is machinery failure, not a forgery verdict.
84
- logger.warn(`[OTA] Native ed25519 verify failed to run: ${err?.message ?? err}`);
85
- verdict = 'unavailable';
86
- }
87
- if (verdict === 'valid') return true;
88
- if (verdict === 'invalid') return false;
89
-
90
- // 'unavailable' (Android < 33) — fall back to the JS verifier so those
91
- // devices keep verifying rather than losing enforcement.
92
- const builtin = getBuiltinVerifier();
93
- if (builtin) {
94
- return builtin({
95
- messageHex,
96
- signature,
97
- publicKey
98
- });
99
- }
100
- // No source can verify. Throwing (rather than returning false) keeps
101
- // the policy layer's outcome labels honest: this surfaces as machinery
102
- // failure with an actionable message, not as "the bundle is forged".
103
- throw new Error('ed25519 unavailable: this OS has no native implementation (Android < 13) and the ' + 'optional peers @noble/ed25519 + @noble/hashes are not installed.');
104
- };
105
- __DEV__ && logger.debug('[OTA] Using native ed25519 verifier (platform crypto).');
106
- return resolved;
107
- }
108
-
109
- /** Test seam — clears the cached resolution. */
110
- export function _resetNativeVerifier() {
111
- resolved = undefined;
112
- }
113
- //# sourceMappingURL=nativeVerifier.js.map
@@ -1,169 +0,0 @@
1
- import { logger } from '../../core/logger/internalLogger';
2
- import { getBuiltinVerifier } from './crypto/builtinVerifier';
3
- import { getNativeVerifier } from './crypto/nativeVerifier';
4
-
5
- /**
6
- * Bundle signature verification (OTA-03).
7
- *
8
- * WHAT WAS WRONG. `ota-signing-key.service.ts` documents the intended model
9
- * exactly: the CLI generates an ed25519 keypair locally, uploads only the public
10
- * half, and "the device verifies every bundle's signature before install and
11
- * rejects forgeries." Two of those three steps did not exist. The CLI had no
12
- * signing code, and this SDK received `bundle.signature` in the check response
13
- * and never read it. The only client-side check was SHA-256 against a hash
14
- * delivered in the same response as the URL — which defends against a corrupted
15
- * download and nothing else. On a platform whose entire purpose is remote code
16
- * delivery, that is the control that matters most.
17
- *
18
- * WHY IT IS SHAPED LIKE THIS. React Native has no built-in ed25519, so the
19
- * verification primitive has to come from somewhere. It is resolved in order:
20
- * a host-supplied verifier, else the built-in one assembled from the OPTIONAL
21
- * `@noble/ed25519` + `@noble/hashes` peers, else nothing — and the SDK's job is
22
- * to decide, unambiguously, what happens in that last case.
23
- *
24
- * The built-in path exists because requiring every adopter to hand-write a
25
- * verifier put the most security-critical operation in the product in code the
26
- * SDK could neither test nor audit, and made a routine dependency bump able to
27
- * silently stop all updates. See `crypto/builtinVerifier.ts`. Signing stays
28
- * opt-in, and apps that never adopt it carry no curve arithmetic.
29
- *
30
- * THE POLICY, which is the important part:
31
- *
32
- * - A bundle carrying a signature, with a configured public key and a
33
- * verifier: verified. Failure REJECTS the install. This is the goal state.
34
- * - A bundle carrying a signature, with a public key configured, but no
35
- * verifier available: REJECT. The app asked for signature enforcement by
36
- * configuring a key; silently installing unverified code because a helper is
37
- * missing would turn a security feature into a placebo.
38
- * - No public key configured: skip, and say so once. Signing is opt-in per app,
39
- * and an app that has not adopted it must keep working.
40
- *
41
- * The failure mode is the whole design: an app that opts in cannot be
42
- * accidentally downgraded to unverified installs.
43
- */
44
-
45
- /** Verifies a detached ed25519 signature. Supplied by the host app. */
46
-
47
- let warnedNotConfigured = false;
48
-
49
- /**
50
- * Decide whether a bundle may be staged.
51
- *
52
- * Returns a structured outcome rather than a boolean so the caller can emit a
53
- * precise telemetry reason — "we shipped unverified code because no key was
54
- * configured" and "we refused because the signature was forged" are very
55
- * different operational events and must not collapse into one.
56
- */
57
- export async function verifyBundleSignature(bundleSha256, signature, config) {
58
- const rawKey = config?.publicKey;
59
-
60
- // Normalize to a list. A single non-empty string is the pre-rotation config
61
- // shape and behaves exactly as before; an array pins several keys at once.
62
- const keys = (Array.isArray(rawKey) ? rawKey : rawKey ? [rawKey] : []).filter(k => typeof k === 'string' && k.trim().length > 0);
63
-
64
- // Signing not adopted by this app — nothing to enforce. Parity note: a
65
- // falsy single value (undefined, '') has always meant "not configured" and
66
- // still does.
67
- if (rawKey === undefined || rawKey === '' || rawKey === null) {
68
- if (!warnedNotConfigured) {
69
- warnedNotConfigured = true;
70
- logger.warn('[OTA] No signing public key configured — bundles are accepted on SHA-256 ' + 'integrity alone. Configure `ota.publicSigningKey` to enforce authenticity.');
71
- }
72
- return {
73
- ok: true,
74
- reason: 'not_configured'
75
- };
76
- }
77
-
78
- // The host PROVIDED a key config that resolves to zero usable keys — an
79
- // empty array, or an array of blank strings. That is a broken attempt to
80
- // enable signing, not an absence of one, and the two must not collapse:
81
- // treating `publicSigningKeys: []` as "not configured" would let a config
82
- // mistake silently downgrade an app to unverified installs. Fail closed.
83
- if (keys.length === 0) {
84
- logger.error('[OTA] Signing key config resolves to zero usable keys (empty array or blank ' + 'strings) — refusing to stage. Remove the config to disable signing, or pin ' + 'at least one real key.');
85
- return {
86
- ok: false,
87
- reason: 'no_keys'
88
- };
89
- }
90
-
91
- // The app opted in, so a bundle without a signature is a refusal, not a pass.
92
- if (!signature) {
93
- logger.error('[OTA] Bundle has no signature but a signing key is configured — refusing to stage.');
94
- return {
95
- ok: false,
96
- reason: 'missing_signature'
97
- };
98
- }
99
-
100
- // Resolution order, and the order matters:
101
- // 1. A host-supplied verifier ALWAYS wins. A team with its own crypto
102
- // policy must be able to override whatever the SDK would otherwise pick.
103
- // 2. Otherwise the NATIVE verifier (CryptoKit / Android 13+ platform
104
- // ed25519). Preferred over the JS one because it runs outside the
105
- // bundle it protects and needs no optional peers; on OS levels without
106
- // ed25519 it delegates to the builtin internally.
107
- // 3. Otherwise the built-in @noble verifier, if the optional peers are
108
- // installed. This is the path that removes ~100 lines of hand-written
109
- // crypto plumbing from every app that adopts signing.
110
- // 4. Otherwise reject, because a configured key is a request for
111
- // enforcement and quietly installing unverified code would turn a
112
- // security feature into a placebo.
113
- const verifier = typeof config?.verifier === 'function' ? config.verifier : getNativeVerifier() ?? getBuiltinVerifier();
114
- if (!verifier) {
115
- logger.error('[OTA] A signing key is configured but no signature verifier is available — ' + 'refusing to stage. Either install the optional peers ' + '`@noble/ed25519` and `@noble/hashes` (the SDK then verifies with no ' + 'further code), or provide your own `ota.verifySignature`.');
116
- return {
117
- ok: false,
118
- reason: 'no_verifier'
119
- };
120
- }
121
-
122
- // Try every pinned key; any single match accepts. The verifier contract is
123
- // unchanged (one key per call) so host-supplied verifiers keep working.
124
- //
125
- // Outcome labelling when nothing matched, and why it matters: if at least
126
- // one verifier call RAN TO COMPLETION and said no, the bundle failed
127
- // verification — 'invalid_signature'. Only when EVERY call threw is the
128
- // machinery itself suspect — 'verifier_threw'. Collapsing those (e.g. by
129
- // letting the last key's throw win) would point an investigation at the
130
- // host's verifier when the actual event was a forged bundle, or vice versa.
131
- let sawThrow = false;
132
- let sawCompletion = false;
133
- for (const key of keys) {
134
- try {
135
- const valid = await verifier({
136
- messageHex: bundleSha256,
137
- signature,
138
- publicKey: key
139
- });
140
- sawCompletion = true;
141
- if (valid) return {
142
- ok: true,
143
- reason: 'verified'
144
- };
145
- } catch (err) {
146
- // A throwing verifier is treated as a failed verification for this key,
147
- // never as a pass — but the remaining keys still get their chance.
148
- sawThrow = true;
149
- logger.error(`[OTA] Signature verifier threw: ${err?.message ?? err}`);
150
- }
151
- }
152
- if (sawThrow && !sawCompletion) {
153
- return {
154
- ok: false,
155
- reason: 'verifier_threw'
156
- };
157
- }
158
- logger.error(keys.length > 1 ? `[OTA] Bundle signature is INVALID under all ${keys.length} pinned keys — refusing to stage.` : '[OTA] Bundle signature is INVALID — refusing to stage.');
159
- return {
160
- ok: false,
161
- reason: 'invalid_signature'
162
- };
163
- }
164
-
165
- /** Test seam — resets the once-per-process "not configured" warning. */
166
- export function _resetSignatureWarnings() {
167
- warnedNotConfigured = false;
168
- }
169
- //# sourceMappingURL=signature.js.map
@@ -1,53 +0,0 @@
1
- /**
2
- * Built-in ed25519 verifier, assembled from OPTIONAL peer dependencies.
3
- *
4
- * WHAT THIS REPLACES. Pinning `ota.publicSigningKey` used to require the host
5
- * app to write its own `verifySignature` — roughly a hundred lines of hex and
6
- * base64 decoding wrapped around a crypto library. That put the single most
7
- * security-critical operation in the product, the one deciding whether remote
8
- * code is authentic before it executes, in code the SDK could neither test nor
9
- * audit. Three failure modes all landed on the app author:
10
- *
11
- * - A verifier that always returns `true` silently disables the feature, and
12
- * nothing can detect it.
13
- * - @noble's hash-provider property moved between major versions, so a
14
- * routine dependency bump made every update fail closed with no signal
15
- * pointing at the cause.
16
- * - Hand-written base64 decoders tend to omit base64url, so a signature
17
- * containing `-` or `_` is rejected as a forgery.
18
- *
19
- * All three are now the SDK's problem, which is where they belong. A host that
20
- * installs `@noble/ed25519` and `@noble/hashes` gets verification by pinning a
21
- * key and writing no code at all.
22
- *
23
- * WHY OPTIONAL AND NOT A HARD DEPENDENCY. Most apps never adopt bundle
24
- * signing, and they should not carry curve arithmetic they will not run. The
25
- * `verifySignature` hook remains supported and still WINS over this, for teams
26
- * with their own crypto policy or a native implementation to delegate to.
27
- *
28
- * WHAT THIS DOES NOT FIX. Verification still happens in JS, inside the very
29
- * bundle it protects. An attacker who lands one malicious bundle by other means
30
- * can neuter the check for every update after it. Closing that needs native
31
- * verification — CryptoKit on iOS (13.4+, already the deployment target) and
32
- * `Signature.getInstance("Ed25519")` on Android API 33+, with a fallback below.
33
- */
34
- import type { SignatureVerifier } from '../signature';
35
- /**
36
- * Decode a detached signature that may arrive hex- or base64-encoded.
37
- *
38
- * Tries the unambiguous case first: 128 hex characters is exactly 64 bytes and
39
- * cannot be anything else. Otherwise base64, then hex as a last resort. Only a
40
- * result of exactly 64 bytes is accepted, so a string that decodes under the
41
- * wrong scheme is rejected rather than fed to the curve code as garbage.
42
- */
43
- export declare function decodeSignature(sig: string): Uint8Array | null;
44
- /**
45
- * The built-in verifier, or null when the optional deps are not installed.
46
- * Resolution is cached, including the negative result — a missing dependency
47
- * does not become present at runtime, and retrying the require on every update
48
- * check would be pure overhead.
49
- */
50
- export declare function getBuiltinVerifier(): SignatureVerifier | null;
51
- /** Test seam — clears the cached resolution. */
52
- export declare function _resetBuiltinVerifier(): void;
53
- //# sourceMappingURL=builtinVerifier.d.ts.map
@@ -1,30 +0,0 @@
1
- /**
2
- * Isolated lazy loader for the OPTIONAL `@noble/ed25519` dep.
3
- *
4
- * WHY ITS OWN FILE: Metro's dependency collector emits a dependency map one
5
- * entry short for a module containing TWO OR MORE different-string inline
6
- * `require()` calls, so the require indices desync and `_dependencyMap[N]`
7
- * reads `undefined` ("Requiring unknown module 'undefined'"). Exactly ONE
8
- * inline require per module avoids the miscount. `loadSha512` is a sibling file
9
- * for the same reason — see `push/adapters/loadNotifee.ts`, which hit this first.
10
- *
11
- * The string must still be STATICALLY resolvable at bundle time; hosts that do
12
- * not install it stub it via `withScaleBun`.
13
- */
14
- /** The subset of the @noble/ed25519 surface this SDK uses. */
15
- export interface NobleEd25519 {
16
- verifyAsync?: (sig: Uint8Array, msg: Uint8Array, pub: Uint8Array) => Promise<boolean>;
17
- verify?: (sig: Uint8Array, msg: Uint8Array, pub: Uint8Array) => boolean;
18
- /** v3 shape: `ed.hashes.sha512` */
19
- hashes?: {
20
- sha512?: unknown;
21
- sha512Async?: unknown;
22
- };
23
- /** v2 shape: `ed.etc.sha512Sync` */
24
- etc?: {
25
- sha512Sync?: unknown;
26
- sha512Async?: unknown;
27
- };
28
- }
29
- export declare function loadEd25519(): NobleEd25519 | null;
30
- //# sourceMappingURL=loadEd25519.d.ts.map
@@ -1,15 +0,0 @@
1
- /**
2
- * Isolated lazy loader for the OPTIONAL `@noble/hashes` SHA-512.
3
- *
4
- * Separate file from `loadEd25519` because Metro miscounts a module holding two
5
- * different-string inline `require()` calls — see the comment there.
6
- *
7
- * ed25519 is defined in terms of SHA-512, and React Native has no native
8
- * SHA-512, so @noble/ed25519 cannot verify anything until a hash provider is
9
- * wired into it. Which property it expects differs by major version, so the
10
- * wiring lives in `builtinVerifier`, not here; this module only obtains the
11
- * function.
12
- */
13
- export type Sha512Fn = (msg: Uint8Array) => Uint8Array;
14
- export declare function loadSha512(): Sha512Fn | null;
15
- //# sourceMappingURL=loadSha512.d.ts.map
@@ -1,35 +0,0 @@
1
- /**
2
- * Native ed25519 verifier — platform crypto wrapped as a SignatureVerifier.
3
- *
4
- * WHY IT EXISTS. The built-in @noble verifier runs in JS, inside the very
5
- * bundle it protects: an attacker who lands one malicious bundle can neuter a
6
- * JS check for every update after it. Platform crypto (CryptoKit on iOS,
7
- * Android's conscrypt on API 33+) sits outside the bundle's reach — and using
8
- * it also drops the runtime dependency on the optional @noble peers wherever
9
- * the OS provides ed25519.
10
- *
11
- * WHAT IT DOES NOT FIX, stated plainly: the ORCHESTRATION still lives in JS.
12
- * A hostile bundle can skip calling any verifier and drive the native staging
13
- * methods directly. Moving the crypto native shrinks the attack surface (no
14
- * more tampering with a bundled crypto lib to flip a verdict) but the full
15
- * close needs native-ENFORCED staging with a natively-pinned key — an
16
- * architectural change tracked separately, not smuggled into this one.
17
- *
18
- * VERDICT CONTRACT (mirrors the spec): the native side resolves
19
- * 'valid' | 'invalid' | 'unavailable'. 'invalid' is a definitive NO.
20
- * 'unavailable' (Android < 33, malformed input, machinery failure) means this
21
- * source cannot answer — the composed verifier below then delegates to the
22
- * @noble builtin, and when that is absent too it THROWS, which the policy
23
- * layer converts to a rejection. Every path that cannot verify refuses.
24
- */
25
- import type { SignatureVerifier } from '../signature';
26
- /**
27
- * The native-first verifier, or null when the native module (or its
28
- * verifyEd25519 method — an app running new JS against an old binary) is
29
- * absent. Cached like the builtin: module availability does not change at
30
- * runtime, and this is consulted on every update check.
31
- */
32
- export declare function getNativeVerifier(): SignatureVerifier | null;
33
- /** Test seam — clears the cached resolution. */
34
- export declare function _resetNativeVerifier(): void;
35
- //# sourceMappingURL=nativeVerifier.d.ts.map
@@ -1,81 +0,0 @@
1
- /**
2
- * Bundle signature verification (OTA-03).
3
- *
4
- * WHAT WAS WRONG. `ota-signing-key.service.ts` documents the intended model
5
- * exactly: the CLI generates an ed25519 keypair locally, uploads only the public
6
- * half, and "the device verifies every bundle's signature before install and
7
- * rejects forgeries." Two of those three steps did not exist. The CLI had no
8
- * signing code, and this SDK received `bundle.signature` in the check response
9
- * and never read it. The only client-side check was SHA-256 against a hash
10
- * delivered in the same response as the URL — which defends against a corrupted
11
- * download and nothing else. On a platform whose entire purpose is remote code
12
- * delivery, that is the control that matters most.
13
- *
14
- * WHY IT IS SHAPED LIKE THIS. React Native has no built-in ed25519, so the
15
- * verification primitive has to come from somewhere. It is resolved in order:
16
- * a host-supplied verifier, else the built-in one assembled from the OPTIONAL
17
- * `@noble/ed25519` + `@noble/hashes` peers, else nothing — and the SDK's job is
18
- * to decide, unambiguously, what happens in that last case.
19
- *
20
- * The built-in path exists because requiring every adopter to hand-write a
21
- * verifier put the most security-critical operation in the product in code the
22
- * SDK could neither test nor audit, and made a routine dependency bump able to
23
- * silently stop all updates. See `crypto/builtinVerifier.ts`. Signing stays
24
- * opt-in, and apps that never adopt it carry no curve arithmetic.
25
- *
26
- * THE POLICY, which is the important part:
27
- *
28
- * - A bundle carrying a signature, with a configured public key and a
29
- * verifier: verified. Failure REJECTS the install. This is the goal state.
30
- * - A bundle carrying a signature, with a public key configured, but no
31
- * verifier available: REJECT. The app asked for signature enforcement by
32
- * configuring a key; silently installing unverified code because a helper is
33
- * missing would turn a security feature into a placebo.
34
- * - No public key configured: skip, and say so once. Signing is opt-in per app,
35
- * and an app that has not adopted it must keep working.
36
- *
37
- * The failure mode is the whole design: an app that opts in cannot be
38
- * accidentally downgraded to unverified installs.
39
- */
40
- /** Verifies a detached ed25519 signature. Supplied by the host app. */
41
- export type SignatureVerifier = (input: {
42
- /** Hex-encoded SHA-256 of the bundle — what the signature is over. */
43
- messageHex: string;
44
- /** Hex or base64 detached signature from the check response. */
45
- signature: string;
46
- /** The app's configured ed25519 public key. */
47
- publicKey: string;
48
- }) => boolean | Promise<boolean>;
49
- export interface SignatureConfig {
50
- /**
51
- * ed25519 public key(s) shipped in the app binary. Absent = signing not
52
- * adopted. An ARRAY pins several keys at once and a bundle is accepted when
53
- * ANY of them verifies — this is what makes key rotation possible without an
54
- * app-store release: ship a build pinning [old, new], start signing with new,
55
- * drop old from the next build. With a single pinnable key, losing the
56
- * private key meant no OTA capability until a new binary cleared review —
57
- * the exact emergency OTA exists to solve.
58
- */
59
- publicKey?: string | string[];
60
- /** Host-provided ed25519 verification function. */
61
- verifier?: SignatureVerifier;
62
- }
63
- export type SignatureOutcome = {
64
- ok: true;
65
- reason: 'verified' | 'not_configured';
66
- } | {
67
- ok: false;
68
- reason: 'no_verifier' | 'invalid_signature' | 'missing_signature' | 'verifier_threw' | 'no_keys';
69
- };
70
- /**
71
- * Decide whether a bundle may be staged.
72
- *
73
- * Returns a structured outcome rather than a boolean so the caller can emit a
74
- * precise telemetry reason — "we shipped unverified code because no key was
75
- * configured" and "we refused because the signature was forged" are very
76
- * different operational events and must not collapse into one.
77
- */
78
- export declare function verifyBundleSignature(bundleSha256: string, signature: string | undefined, config: SignatureConfig | undefined): Promise<SignatureOutcome>;
79
- /** Test seam — resets the once-per-process "not configured" warning. */
80
- export declare function _resetSignatureWarnings(): void;
81
- //# sourceMappingURL=signature.d.ts.map