@adea-ai/app-framework 0.24.0 → 0.25.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.
Files changed (137) hide show
  1. package/README.md +49 -1
  2. package/dist/cli/macos-signing-cli.d.ts +2 -0
  3. package/dist/cli/macos-signing-cli.js +14 -0
  4. package/dist/desktop/channel-proof.js +7 -1
  5. package/dist/framework-source.json +1 -1
  6. package/dist/release/framework-package-publish.js +4 -2
  7. package/dist/release/local-release.d.ts +2 -0
  8. package/dist/release/local-release.js +25 -2
  9. package/dist/release/macos-signing.d.ts +27 -0
  10. package/dist/release/macos-signing.js +101 -0
  11. package/dist/shell/app-shell.js +21 -33
  12. package/dist/shell/navigation-drawer.d.ts +12 -0
  13. package/dist/shell/navigation-drawer.js +42 -0
  14. package/dist/updates/release-feed.d.ts +2 -0
  15. package/dist/updates/release-feed.js +11 -2
  16. package/package.json +16 -4
  17. package/src/shell/app-shell.tsx +29 -20
  18. package/src/shell/navigation-drawer.tsx +36 -0
  19. package/src/app/create-application.ts +0 -245
  20. package/src/app/service-registry.ts +0 -124
  21. package/src/ci/toolchain-identity.ts +0 -244
  22. package/src/cli/cef-helper-cli.ts +0 -21
  23. package/src/cli/cli-runner.ts +0 -29
  24. package/src/cli/create-application-cli.ts +0 -62
  25. package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
  26. package/src/cli/framework-update-cli.ts +0 -41
  27. package/src/cli/release-assets-plan-cli.ts +0 -14
  28. package/src/cli/release-cut-cli.ts +0 -41
  29. package/src/cli/release-descriptor-staging-cli.ts +0 -57
  30. package/src/cli/release-finalize-cli.ts +0 -34
  31. package/src/cli/release-promote-cli.ts +0 -31
  32. package/src/cli/release-publish-cli.ts +0 -46
  33. package/src/cli/release-sign-cli.ts +0 -24
  34. package/src/cli/release-step-cli.ts +0 -71
  35. package/src/cli/toolchain-identity-cli.ts +0 -12
  36. package/src/cli/update-helper-cli.ts +0 -12
  37. package/src/cli/windows-runtime-patch-cli.ts +0 -17
  38. package/src/desktop/application-command-client.ts +0 -43
  39. package/src/desktop/channel-handshake.ts +0 -136
  40. package/src/desktop/channel-proof.ts +0 -122
  41. package/src/desktop/desktop-client.ts +0 -303
  42. package/src/desktop/desktop-gateway.ts +0 -189
  43. package/src/desktop/desktop-host.ts +0 -335
  44. package/src/desktop/desktop-stream.ts +0 -324
  45. package/src/desktop/loopback-policy.ts +0 -41
  46. package/src/desktop/open-url-channel.ts +0 -79
  47. package/src/desktop/string-policy.ts +0 -9
  48. package/src/installer/archive-entry.ts +0 -32
  49. package/src/installer/command-artifact.ts +0 -307
  50. package/src/installer/command-qualification-command.ts +0 -75
  51. package/src/installer/hosted-runner.ts +0 -11
  52. package/src/installer/installed-payload.ts +0 -408
  53. package/src/installer/installer-ci-bootstrap.ts +0 -199
  54. package/src/installer/installer-ci-preflight.ts +0 -61
  55. package/src/installer/installer-ci-worker.ts +0 -105
  56. package/src/installer/installer-extraction.ts +0 -367
  57. package/src/installer/installer-fetch-guard.ts +0 -75
  58. package/src/installer/installer-identity.ts +0 -331
  59. package/src/installer/installer-layout.ts +0 -167
  60. package/src/installer/installer-observation.ts +0 -671
  61. package/src/installer/installer-process-cleanup.ts +0 -167
  62. package/src/installer/installer-qualification-command.ts +0 -81
  63. package/src/installer/installer-renderer-evidence.ts +0 -268
  64. package/src/installer/installer-upgrade-command.ts +0 -226
  65. package/src/installer/installer-worker-guard.ts +0 -112
  66. package/src/installer/native-executable.ts +0 -37
  67. package/src/installer/upgrade-asset-download.ts +0 -72
  68. package/src/installer/write-all.ts +0 -19
  69. package/src/native/app-bundle.ts +0 -86
  70. package/src/native/cef-helper.ts +0 -471
  71. package/src/native/desktop-build-hook.ts +0 -21
  72. package/src/native/electrobun-source-patch.ts +0 -107
  73. package/src/native/linux-cef-links.ts +0 -14
  74. package/src/native/native-secret-store.ts +0 -99
  75. package/src/native/native-utilities.ts +0 -166
  76. package/src/native/partitioned-window.ts +0 -62
  77. package/src/native/secure-window.ts +0 -115
  78. package/src/native/sidecar-services.ts +0 -71
  79. package/src/native/sidecar.ts +0 -387
  80. package/src/native/window-bootstrap.ts +0 -77
  81. package/src/native/windows-build-hook-internal.ts +0 -49
  82. package/src/native/windows-build-hook.ts +0 -12
  83. package/src/native/windows-runtime-patch-internal.ts +0 -48
  84. package/src/native/windows-runtime-patch.ts +0 -15
  85. package/src/release/feed-release-cut.ts +0 -110
  86. package/src/release/feed-state.ts +0 -135
  87. package/src/release/framework-package-publish.ts +0 -163
  88. package/src/release/framework-update.ts +0 -196
  89. package/src/release/github-cli.ts +0 -27
  90. package/src/release/github-release-assets.ts +0 -36
  91. package/src/release/github-release-cut.ts +0 -237
  92. package/src/release/github-release-lookup.ts +0 -39
  93. package/src/release/github-release-promotion.ts +0 -112
  94. package/src/release/github-release-provenance.ts +0 -65
  95. package/src/release/github-release-publisher.ts +0 -90
  96. package/src/release/github-release-qualification.ts +0 -144
  97. package/src/release/local-provenance.ts +0 -92
  98. package/src/release/local-release.ts +0 -525
  99. package/src/release/macos-dmg.ts +0 -113
  100. package/src/release/release-artifact.ts +0 -53
  101. package/src/release/release-assets-plan.ts +0 -118
  102. package/src/release/release-config.ts +0 -420
  103. package/src/release/release-cut-command.ts +0 -80
  104. package/src/release/release-cut.ts +0 -133
  105. package/src/release/release-descriptor-staging.ts +0 -242
  106. package/src/release/release-finalize.ts +0 -191
  107. package/src/release/release-promotion-command.ts +0 -36
  108. package/src/release/release-promotion.ts +0 -132
  109. package/src/release/release-publication.ts +0 -213
  110. package/src/release/release-publish-command.ts +0 -163
  111. package/src/release/release-qualification.ts +0 -397
  112. package/src/release/release-staging.ts +0 -87
  113. package/src/release/release-steps.ts +0 -173
  114. package/src/release/retained-release-build.ts +0 -217
  115. package/src/shell/application-menu-commands.ts +0 -6
  116. package/src/shell/application-menu.ts +0 -250
  117. package/src/updates/channel-update-manager.ts +0 -127
  118. package/src/updates/desktop-updater.ts +0 -440
  119. package/src/updates/release-feed.ts +0 -187
  120. package/src/updates/release-location.ts +0 -101
  121. package/src/updates/signed-release.ts +0 -311
  122. package/src/updates/stable-file.ts +0 -32
  123. package/src/updates/update-arm.ts +0 -107
  124. package/src/updates/update-channel-store.ts +0 -86
  125. package/src/updates/update-discovery.ts +0 -113
  126. package/src/updates/update-download.ts +0 -82
  127. package/src/updates/update-exclusive-rename.ts +0 -58
  128. package/src/updates/update-extraction.ts +0 -261
  129. package/src/updates/update-handoff-plan.ts +0 -75
  130. package/src/updates/update-helper.ts +0 -87
  131. package/src/updates/update-launch.ts +0 -33
  132. package/src/updates/update-manager.ts +0 -130
  133. package/src/updates/update-process-fence.ts +0 -125
  134. package/src/updates/update-resume.ts +0 -34
  135. package/src/updates/update-shutdown.ts +0 -37
  136. package/src/updates/update-swap-stage.ts +0 -75
  137. package/src/updates/update-swap.ts +0 -30
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env bun
2
- import {
3
- inspectStagedStep,
4
- qualifyStep,
5
- qualifyUpgradeStep,
6
- releasePlatform,
7
- selectRetainedStep,
8
- stageBuildStep,
9
- type ReleaseStepContext,
10
- } from '../release/release-steps'
11
- import { readJsonFile, runCli } from './cli-runner'
12
-
13
- // `release-step-cli.js <step> [--artifacts <dir>] <platform> [directory]`, run
14
- // in the app directory with RELEASE_TAG. The reusable release-assets workflow
15
- // appends the platform and staging directory to each `release:<step>` script.
16
- await runCli(
17
- (error) => `Release step failed: ${error instanceof Error ? error.message : String(error)}`,
18
- async () => {
19
- const args = process.argv.slice(2)
20
- const flag = args.indexOf('--artifacts')
21
- const artifacts = flag === -1 ? undefined : args.splice(flag, 2)[1]
22
- if (flag !== -1 && !artifacts) throw new Error('Expected a directory after --artifacts')
23
- const [step, platform, directory, ...extra] = args
24
- const tag = process.env.RELEASE_TAG
25
- if (!tag || extra.length)
26
- throw new Error('Expected <step> <platform> [directory] and RELEASE_TAG')
27
- const config = await readJsonFile('release-config.json', 262144)
28
- if (
29
- typeof config !== 'object' ||
30
- config === null ||
31
- typeof (config as { appName?: unknown }).appName !== 'string'
32
- )
33
- throw new Error('release-config.json names no app')
34
- const context: ReleaseStepContext = {
35
- env: process.env,
36
- config: config as ReleaseStepContext['config'],
37
- tag,
38
- platform: releasePlatform(platform),
39
- }
40
- if (step === 'select-retained') {
41
- if (directory) throw new Error('select-retained takes only the platform')
42
- return selectRetainedStep(context)
43
- }
44
- if (!directory) throw new Error('Expected a staging directory')
45
- switch (step) {
46
- case 'stage-build':
47
- console.log(JSON.stringify(await stageBuildStep(context, directory, artifacts)))
48
- return
49
- case 'inspect':
50
- console.log(JSON.stringify((await inspectStagedStep(context, directory)).identity))
51
- return
52
- case 'qualify':
53
- await qualifyStep(context, directory)
54
- console.log('Installer qualification receipt staged')
55
- return
56
- case 'qualify-upgrade': {
57
- const receipt = await qualifyUpgradeStep(context, directory, (stage) =>
58
- console.log(`upgrade: ${stage}`)
59
- )
60
- console.log(
61
- receipt
62
- ? `Upgraded ${receipt.from.tag} to ${tag} and observed the new version`
63
- : 'No earlier published release to upgrade from'
64
- )
65
- return
66
- }
67
- default:
68
- throw new Error(`Unknown release step ${String(step)}`)
69
- }
70
- }
71
- )
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
- import { verifyToolchain } from '../ci/toolchain-identity'
3
-
4
- // Run with node: the id's libc comes from Node's process report, as in the
5
- // `vp` config process that wrote it.
6
- const at = process.argv.indexOf('--expect')
7
- const expected = at === -1 ? undefined : process.argv[at + 1]
8
- if (!expected) {
9
- console.error('toolchain-identity: usage: adea-toolchain-identity --expect <id>')
10
- process.exit(2)
11
- }
12
- process.exit(verifyToolchain(expected))
@@ -1,12 +0,0 @@
1
- import { runUpdateHelper } from '../updates/update-helper'
2
-
3
- // Bundled standalone (dist/update-helper.bundle.js) so an app can ship it next
4
- // to its own bundle and run it with a copy of its Bun runtime.
5
- const index = process.argv.indexOf('--staging')
6
- const staging = index > 0 ? process.argv[index + 1] : undefined
7
- if (!staging) {
8
- console.error('Usage: update-helper --staging <directory>')
9
- process.exit(2)
10
- }
11
- const outcome = await runUpdateHelper({ staging }).catch(() => 'failed' as const)
12
- process.exit(outcome === 'updated' ? 0 : 1)
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { readFile, stat, writeFile } from 'node:fs/promises'
3
- import {
4
- patchPinnedWindowsRuntime,
5
- SECURE_WINDOWS_WRAPPER_SHA256,
6
- } from '../native/windows-runtime-patch'
7
- import { runCli } from './cli-runner'
8
-
9
- await runCli('Unable to patch the pinned unsigned Windows runtime.', async () => {
10
- const [input, output, ...extra] = process.argv.slice(2)
11
- if (!input || !output || extra.length) throw new Error('Invalid invocation')
12
- const info = await stat(input)
13
- if (!info.isFile() || info.size > 64 * 1024 * 1024) throw new Error('Invalid runtime')
14
- const patched = patchPinnedWindowsRuntime(await readFile(input))
15
- await writeFile(output, patched, { flag: 'wx', mode: 0o600 })
16
- process.stdout.write(`Patched Windows runtime SHA-256: ${SECURE_WINDOWS_WRAPPER_SHA256}\n`)
17
- })
@@ -1,43 +0,0 @@
1
- import {
2
- applicationCommandStream,
3
- applicationMenuCommands,
4
- } from '../shell/application-menu-commands'
5
-
6
- /** The shared-surface commands `ApplicationUtilities` provides. */
7
- export type ApplicationCommandTarget = Readonly<{
8
- openAbout(): void
9
- openSettings(): void
10
- openHelp(): void
11
- openUpdates(): void
12
- }>
13
-
14
- type StreamClient = {
15
- openStream(
16
- name: string,
17
- input: unknown,
18
- onMessage: (payload: string | ArrayBuffer) => void,
19
- onClose?: () => void
20
- ): Promise<{ close(): void }>
21
- }
22
-
23
- /** Route native menu commands from the desktop host to the shared surfaces. */
24
- export async function connectApplicationCommands(
25
- client: StreamClient,
26
- commands: ApplicationCommandTarget
27
- ): Promise<() => void> {
28
- const stream = await client.openStream(applicationCommandStream, null, (payload) => {
29
- if (typeof payload !== 'string' || payload.length > 64) return
30
- let command: unknown
31
- try {
32
- command = (JSON.parse(payload) as { command?: unknown }).command
33
- } catch {
34
- return
35
- }
36
- if (!(applicationMenuCommands as readonly unknown[]).includes(command)) return
37
- if (command === 'about') commands.openAbout()
38
- else if (command === 'settings') commands.openSettings()
39
- else if (command === 'help') commands.openHelp()
40
- else commands.openUpdates()
41
- })
42
- return () => stream.close()
43
- }
@@ -1,136 +0,0 @@
1
- // Adapted from adea-ai/adea's dev-runtime/channel/authority.ts at
2
- // eb11acdf14cb21a56bd90fdd9e6bdef9170e71d9 (Apache-2.0).
3
- import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto'
4
- import type { ChannelIdentity, VerifiedChannel } from './channel-proof'
5
-
6
- type Channel<Principal> = VerifiedChannel<Principal> & { credentialId: string; secret: Buffer }
7
- type Launch<Principal> = { secret: Buffer; expiresAt: number; principal: Principal }
8
-
9
- /**
10
- * In-process channel authority. Deliver bootstrap only through a trusted native
11
- * window and require origin screening separately. Never put bootstrap in an HTTP
12
- * document or treat browser headers as proof of window identity.
13
- */
14
- export function createChannelAuthority<Principal>(
15
- options: {
16
- now?: () => number
17
- bootstrapLifetimeMs?: number
18
- channelLifetimeMs?: number
19
- maxChannels?: number
20
- } = {}
21
- ) {
22
- const clock = options.now ?? Date.now
23
- const bootstrapLifetime = options.bootstrapLifetimeMs ?? 60000
24
- const channelLifetime = options.channelLifetimeMs ?? 12 * 60 * 60 * 1000
25
- const maxChannels = options.maxChannels ?? 4
26
- if (
27
- ![bootstrapLifetime, channelLifetime, maxChannels].every(
28
- (value) => Number.isSafeInteger(value) && value > 0
29
- )
30
- )
31
- throw new Error('Invalid channel authority configuration')
32
- let launch: Launch<Principal> | undefined
33
- const channels = new Map<string, Channel<Principal>>()
34
- const listeners = new Set<(identity: ChannelIdentity) => void>()
35
- function remove(id: string, channel: Channel<Principal>) {
36
- if (channels.get(id) !== channel) return
37
- channels.delete(id)
38
- channel.secret.fill(0)
39
- // Snapshot because listeners may add or remove subscriptions while revocation is delivered.
40
- // oxlint-disable-next-line unicorn/no-useless-spread
41
- for (const listener of [...listeners]) {
42
- try {
43
- listener({ channelId: id, credentialId: channel.credentialId })
44
- } catch {
45
- /* Revocation must not be interrupted by a listener. */
46
- }
47
- }
48
- }
49
- function time() {
50
- const at = clock()
51
- if (
52
- !Number.isSafeInteger(at) ||
53
- at < 0 ||
54
- at > Number.MAX_SAFE_INTEGER - Math.max(bootstrapLifetime, channelLifetime)
55
- )
56
- throw new Error('Invalid channel clock')
57
- return at
58
- }
59
- function clearLaunch() {
60
- launch?.secret.fill(0)
61
- launch = undefined
62
- }
63
- function sweep(at: number) {
64
- if (launch && launch.expiresAt <= at) clearLaunch()
65
- for (const [id, channel] of channels) if (channel.expiresAt <= at) remove(id, channel)
66
- }
67
- return {
68
- /** Invalidates an earlier unused bootstrap; the caller must keep the result secret. */
69
- issue(principal: Principal) {
70
- const at = time()
71
- sweep(at)
72
- clearLaunch()
73
- const secret = randomBytes(32)
74
- launch = { secret, expiresAt: at + bootstrapLifetime, principal }
75
- return { bootstrap: secret.toString('base64url'), expiresAt: launch.expiresAt }
76
- },
77
- handshake(bootstrap: string):
78
- | { ok: false }
79
- | {
80
- ok: true
81
- channelId: string
82
- credentialId: string
83
- clientSecret: string
84
- expiresAt: number
85
- } {
86
- const at = time()
87
- sweep(at)
88
- if (!launch || typeof bootstrap !== 'string' || !/^[A-Za-z0-9_-]{43}$/.test(bootstrap))
89
- return { ok: false }
90
- const supplied = Buffer.from(bootstrap, 'base64url')
91
- if (
92
- supplied.length !== launch.secret.length ||
93
- !timingSafeEqual(supplied, launch.secret) ||
94
- channels.size >= maxChannels
95
- )
96
- return { ok: false }
97
- const principal = launch.principal
98
- clearLaunch()
99
- const channelId = randomUUID()
100
- const credentialId = randomUUID()
101
- const secret = randomBytes(32)
102
- const expiresAt = at + channelLifetime
103
- channels.set(channelId, { credentialId, secret, expiresAt, principal })
104
- return {
105
- ok: true,
106
- channelId,
107
- credentialId,
108
- clientSecret: secret.toString('base64url'),
109
- expiresAt,
110
- }
111
- },
112
- resolve(identity: ChannelIdentity): VerifiedChannel<Principal> | undefined {
113
- const at = time()
114
- sweep(at)
115
- const channel = channels.get(identity.channelId)
116
- if (!channel || channel.credentialId !== identity.credentialId) return undefined
117
- return channel
118
- },
119
- revoke(identity: ChannelIdentity) {
120
- const channel = channels.get(identity.channelId)
121
- if (channel && channel.credentialId === identity.credentialId)
122
- remove(identity.channelId, channel)
123
- },
124
- revokeAll() {
125
- clearLaunch()
126
- for (const [id, channel] of channels) remove(id, channel)
127
- },
128
- /** Notify long-lived transports after a channel is removed. Expiry is swept on authority access. */
129
- onRevoke(listener: (identity: ChannelIdentity) => void) {
130
- listeners.add(listener)
131
- return () => {
132
- listeners.delete(listener)
133
- }
134
- },
135
- }
136
- }
@@ -1,122 +0,0 @@
1
- // Compatible with the legacy invoke proof in adea-ai/adea's channel/authority.ts
2
- // at eb11acdf14cb21a56bd90fdd9e6bdef9170e71d9 (Apache-2.0).
3
- import { createHash, createHmac, timingSafeEqual } from 'node:crypto'
4
- import { containsAsciiControl } from './string-policy'
5
-
6
- export type ChannelIdentity = Readonly<{ channelId: string; credentialId: string }>
7
- export type ProofFields = ChannelIdentity &
8
- Readonly<{ nonce: string; timestamp: string; bodySha256: string }>
9
- export type SignedRequest = ChannelIdentity &
10
- Readonly<{ nonce: string; timestamp: string; proof: string; body: string }>
11
- export type VerifiedChannel<Principal> = Readonly<{
12
- secret: Uint8Array
13
- expiresAt: number
14
- principal: Principal
15
- }>
16
- export type ProofResult<Principal> =
17
- | { ok: true; principal: Principal }
18
- | { ok: false; code: 'unauthenticated' | 'expired' | 'replay' | 'capacity' | 'invalid' }
19
- const separator = '\u001f'
20
- const field = (value: unknown): value is string =>
21
- typeof value === 'string' &&
22
- value.length > 0 &&
23
- value.length <= 128 &&
24
- !containsAsciiControl(value)
25
-
26
- /** Exact wire input used by Adea's current signed invoke bridge. */
27
- export function legacyProofMessage(input: ProofFields, context = 'adea-invoke-v1'): string {
28
- if (
29
- !field(context) ||
30
- !field(input.channelId) ||
31
- !field(input.credentialId) ||
32
- !field(input.nonce) ||
33
- !/^\d{1,16}$/.test(input.timestamp) ||
34
- !/^[a-f0-9]{64}$/.test(input.bodySha256)
35
- )
36
- throw new Error('Invalid proof fields')
37
- return [
38
- context,
39
- input.channelId,
40
- input.credentialId,
41
- input.nonce,
42
- input.timestamp,
43
- input.bodySha256,
44
- ].join(separator)
45
- }
46
-
47
- /**
48
- * Authenticate exact invoke bodies against an already established channel.
49
- * The host owns secure channel creation, credential delivery and revocation;
50
- * origin checks alone cannot supply a channel. This does not authorize services.
51
- */
52
- export function createChannelProofVerifier<Principal>(options: {
53
- resolve(identity: ChannelIdentity): VerifiedChannel<Principal> | undefined
54
- now?: () => number
55
- context?: string
56
- maxNonces?: number
57
- maxBodyBytes?: number
58
- }) {
59
- const now = options.now ?? Date.now
60
- const maxNonces = options.maxNonces ?? 4096
61
- const maxBodyBytes = options.maxBodyBytes ?? 256 * 1024
62
- const context = options.context ?? 'adea-invoke-v1'
63
- if (
64
- !field(context) ||
65
- !Number.isSafeInteger(maxNonces) ||
66
- maxNonces < 1 ||
67
- !Number.isSafeInteger(maxBodyBytes) ||
68
- maxBodyBytes < 1
69
- )
70
- throw new Error('Invalid channel proof configuration')
71
- const nonces = new Map<string, number>()
72
- return {
73
- verify(input: SignedRequest): ProofResult<Principal> {
74
- if (
75
- !field(input?.channelId) ||
76
- !field(input.credentialId) ||
77
- !field(input.nonce) ||
78
- typeof input.body !== 'string' ||
79
- Buffer.byteLength(input.body) > maxBodyBytes ||
80
- typeof input.timestamp !== 'string' ||
81
- !/^\d{1,16}$/.test(input.timestamp) ||
82
- typeof input.proof !== 'string' ||
83
- !/^[A-Za-z0-9_-]{43}$/.test(input.proof)
84
- )
85
- return { ok: false, code: 'invalid' }
86
- const at = now()
87
- const timestamp = Number(input.timestamp)
88
- if (
89
- !Number.isSafeInteger(at) ||
90
- !Number.isSafeInteger(timestamp) ||
91
- Math.abs(at - timestamp) > 30000
92
- )
93
- return { ok: false, code: 'expired' }
94
- let channel: VerifiedChannel<Principal> | undefined
95
- try {
96
- channel = options.resolve({ channelId: input.channelId, credentialId: input.credentialId })
97
- } catch {
98
- return { ok: false, code: 'unauthenticated' }
99
- }
100
- if (
101
- !channel ||
102
- !(channel.secret instanceof Uint8Array) ||
103
- channel.secret.byteLength !== 32 ||
104
- !Number.isSafeInteger(channel.expiresAt) ||
105
- channel.expiresAt <= at
106
- )
107
- return { ok: false, code: 'unauthenticated' }
108
- const bodySha256 = createHash('sha256').update(input.body, 'utf8').digest('hex')
109
- const message = legacyProofMessage({ ...input, bodySha256 }, context)
110
- const expected = createHmac('sha256', channel.secret).update(message, 'utf8').digest()
111
- const received = Buffer.from(input.proof, 'base64url')
112
- if (received.length !== expected.length || !timingSafeEqual(received, expected))
113
- return { ok: false, code: 'unauthenticated' }
114
- for (const [key, expiry] of nonces) if (expiry < at) nonces.delete(key)
115
- const key = `${input.channelId}\0${input.credentialId}\0${input.nonce}`
116
- if (nonces.has(key)) return { ok: false, code: 'replay' }
117
- if (nonces.size >= maxNonces) return { ok: false, code: 'capacity' }
118
- nonces.set(key, timestamp + 60000)
119
- return { ok: true, principal: channel.principal }
120
- },
121
- }
122
- }