Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions core/device-id/device-id-protocol.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { IssueCertificateResult, JWKPrivateSchema, SuperThis } from "@fireproof/core-types-base";
import { DeviceIdCA } from "./device-id-CA.js";
import { IssueCertificateResult, JWKPrivateSchema, SuperThis, JWKPublic } from "@fireproof/core-types-base";
import { CAActions, DeviceIdCA } from "./device-id-CA.js";
import { param, Result } from "@adviser/cement";
import { DeviceIdKey } from "./device-id-key.js";
import { base58btc } from "multiformats/bases/base58";
import { DeviceIdVerifyMsg, VerifyWithCertificateResult } from "./device-id-verify-msg.js";

// Stub implementation until real CAActions is integrated
const stubCAActions: CAActions = {
generateSerialNumber: async (_pub: JWKPublic) => {
// TODO: Implement proper serial number generation based on public key
// This should generate a unique, deterministic serial number for the certificate
return `stub-${Date.now()}-${Math.random().toString(36).slice(2)}`;
},
};

async function ensureCA(sthis: SuperThis, opts: DeviceIdProtocolSrvOpts): Promise<Result<DeviceIdCA>> {
const rEnv = sthis.env.gets({
DEVICE_ID_CA_KEY: opts.env?.DEVICE_ID_CA_KEY ?? param.REQUIRED,
Expand All @@ -29,7 +38,7 @@ async function ensureCA(sthis: SuperThis, opts: DeviceIdProtocolSrvOpts): Promis
caSubject: {
commonName: env.DEVICE_ID_CA_COMMON_NAME ?? "Fireproof CA",
},
actions: [], // opts.actions ,
actions: stubCAActions,
}),
);
}
Expand All @@ -45,7 +54,7 @@ export interface DeviceIdProtocolSrvOpts {
readonly DEVICE_ID_CA_KEY: string;
readonly DEVICE_ID_CA_COMMON_NAME?: string;
};
// readonly actions: CAActions;
// Note: Uses stubCAActions until proper CAActions implementation is provided
}

export class DeviceIdProtocolSrv implements DeviceIdProtocol {
Expand Down
2 changes: 1 addition & 1 deletion core/gateways/cloud/to-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ToCloud implements ToCloudAttachable {
// wait for the token
// const token = await this._tokenObserver.getToken(logger, ledger);
const rToken = await this.opts.strategy.waitForToken(ledger.sthis, logger, ledger.name, this.opts);
if (!rToken.isErr) {
if (rToken.isErr()) {
return Result.Err(rToken);
}
const token = rToken.unwrap();
Expand Down
3 changes: 3 additions & 0 deletions use-fireproof/fp-cloud-connect-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export class FPCloudConnectStrategy implements TokenStrategie {
this.title,
`left=${left},top=${top},width=${width},height=${height},scrollbars=yes,resizable=yes,popup=yes`,
);
// TODO: Add popup callback handler here
// Need to listen for postMessage from popup window containing OAuth result
// Example: window.addEventListener('message', (event) => { ... })
// window.location.href = url.toString();
}

Expand Down
8 changes: 8 additions & 0 deletions use-fireproof/fp-cloud-connector/iframe-fpcc-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class MemoryFPCCEvtEntity implements BackendFPCC {
}

waitForAuthToken(tid: string, tokenURI: string): Promise<string> {
// TODO: Implement real OAuth token exchange
// Should: 1) Listen for popup window callback message
// 2) Extract auth token from message
// 3) Exchange with tokenURI endpoint
// 4) Return real JWT token
return sleep(100).then(() => `fake-auth-token:${tid}:${tokenURI}`);
}

Expand Down Expand Up @@ -147,6 +152,9 @@ export class IframeFPCCProtocol implements FPCCProtocol {
};

getDeviceId(): string {
// TODO: Integrate with core/device-id/device-id-protocol.ts
// Should use DeviceIdProtocol to generate/retrieve device certificate
// This ties into the device identity and auth system
return "we-need-to-implement-device-id";
}

Expand Down
4 changes: 3 additions & 1 deletion use-fireproof/fp-cloud-connector/page-fpcc-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export class PageFPCCProtocol implements FPCCProtocol {
}

getAppId(): string {
// setup in ready
// TODO: Generate or retrieve stable app ID
// Should be consistent across sessions for the same app origin
// Consider using: hash(window.location.origin) or stored value
return "we-need-to-implement-app-id-this";
}

Expand Down
Loading