Skip to content

Commit

Permalink
chore(docs): Adds documentation on some recent changes (#348)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Flynn <43211074+pflynn-virtru@users.noreply.github.com>
  • Loading branch information
dmihalcik-virtru and pflynn-virtru committed Sep 19, 2024
1 parent 4e54c0d commit ced163d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/src/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,33 @@ export async function fetchWrappedKey(

export type KasPublicKeyAlgorithm = 'ec:secp256r1' | 'rsa:2048';

/**
* Information about one of a KAS's published public keys.
* A KAS may publish multiple keys with a given algorithm type.
*/
export type KasPublicKeyInfo = {
/** The locator to the given KAS associated with this key */
url: string;

/** The encryption algorithm the key is to be used with. */
algorithm: KasPublicKeyAlgorithm;

/** If present, an identifier which is tied to this specific key. */
kid?: string;

/** The key value, encoded within a PEM envelope */
publicKey: string;

/** A subtle crypto version of the key.
* This can be used for wrapping key data for key access objects (with RSA)
* or to derive key data (with EC keys). */
key: Promise<CryptoKey>;
};

/**
* If we have KAS url but not public key we can fetch it from KAS, fetching
* the value from `${kas}/kas_public_key`.
*/

export async function fetchECKasPubKey(kasEndpoint: string): Promise<KasPublicKeyInfo> {
validateSecureUrl(kasEndpoint);
const pkUrlV2 = `${kasEndpoint}/v2/kas_public_key?algorithm=ec:secp256r1&v=2`;
Expand Down
9 changes: 9 additions & 0 deletions lib/src/nanotdf/models/ResourceLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export default class ResourceLocator {
readonly idType: ResourceLocatorIdentifierEnum = ResourceLocatorIdentifierEnum.None
) {}

/**
* Construct a new URL or URL + identifier pair, for use with NanoTDF envelopes.
* @param url The URL to encrypt; `http` and `https` schemes are supported
* @param identifier An optional identifier.
* For KAS URLs, this is usually a public key identifier (kid). Limit 32 characters
* @returns a value representing the URL and identifier, if present.
* This method throws an Error if the URL is invalid or of the wrong schema,
* or if the identifier is an unsupported value.
*/
static fromURL(url: string, identifier?: string): ResourceLocator {
const [protocolStr, body] = url.split('://');

Expand Down

0 comments on commit ced163d

Please sign in to comment.