Skip to content
Merged
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
33 changes: 15 additions & 18 deletions js/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,7 @@ export class Identity {
);
}

// Create cipher suite
const suite = createSuite();

// Import public key
const publicKey = await suite.DeserializePublicKey(publicKeyBytes);

// For server config, we only have the public key, no private key
// We'll create a dummy private key that won't be used
const dummyPrivateKey = await suite.DeserializePrivateKey(new Uint8Array(32), false);

return new Identity(suite, publicKey, dummyPrivateKey);
return Identity.fromPublicKeyBytes(publicKeyBytes);
}

/**
Expand All @@ -227,16 +217,23 @@ export class Identity {
throw new Error(`Invalid public key length: expected 32, got ${publicKeyBytes.length}`);
}

return Identity.fromPublicKeyBytes(publicKeyBytes);
}

/**
* Create an Identity from raw public key bytes.
* Uses the default cipher suite (X25519/HKDF-SHA256/AES-256-GCM).
*
* For public-key-only identities (client-side use), we create a placeholder
* private key that won't be used. TODO: refactor Identity to not require
* a private key for client-side use.
*/
private static async fromPublicKeyBytes(publicKeyBytes: Uint8Array): Promise<Identity> {
const suite = createSuite();
const publicKey = await suite.DeserializePublicKey(publicKeyBytes);
const placeholderPrivateKey = await suite.DeserializePrivateKey(new Uint8Array(32), false);

// For server config, we only have the public key, no private key.
// We'll create a dummy private key that won't be used.
// TODO: maybe refactor Identity to not require a private key for
// client-side use?
const dummyPrivateKey = await suite.DeserializePrivateKey(new Uint8Array(32), false);

return new Identity(suite, publicKey, dummyPrivateKey);
return new Identity(suite, publicKey, placeholderPrivateKey);
}

/**
Expand Down