virgil-sdk
Version:
Virgil Security Services SDK
198 lines (197 loc) • 7.03 kB
TypeScript
import { ICardCrypto } from '../types';
import { IRawSignedModelJson, RawSignedModel } from './RawSignedModel';
import { CardClient } from '../Client/CardClient';
import { ModelSigner } from './ModelSigner';
import { ICard, INewCardParams } from './ICard';
import { ICardVerifier } from './CardVerifier';
import { IAccessTokenProvider } from '../Auth/AccessTokenProviders';
import { IProductInfo } from '../Client/Connection';
/**
* User-specified callback function to be called just before publishing
* a Virgil Card to append additional signatures to it.
*
* Receives a single parameter of type {@link RawSignedModel} and must
* return a {@link RawSignedModel} with additional signatures.
* Use {@link ModelSigner} to add signatures.
*/
export declare type ISignCallback = (model: RawSignedModel) => Promise<RawSignedModel> | RawSignedModel;
export { ICard };
/**
* {@link CardManager} initialization options.
*/
export interface ICardManagerParams {
/**
* Implementation of {@link IAccessTokenProvider} to use to
* get the token for requests authentication. Optional.
*/
readonly accessTokenProvider?: IAccessTokenProvider;
/**
* Implementation of {@link ICardCrypto} interface.
*/
readonly cardCrypto: ICardCrypto;
/**
* Implementation of {@link ICardVerifier} interface to
* be used to verify the validity of Virgil Cards received
* from network and via {@link CardManager.importCard} method.
*/
readonly cardVerifier: ICardVerifier;
/**
* Alters the behavior of the `CardManager` when it receives an
* HTTP Unauthorized (401) error from the server. If this is set to
* `true` it will silently request a new token form the
* {@link CardManager.accessTokenProvider} and re-send the request,
* otherwise the error will be returned to the client.
*/
readonly retryOnUnauthorized: boolean;
/**
* Optional {@link ISignCallback}.
*/
readonly signCallback?: ISignCallback;
/**
* Virgil Services API URL. Optional.
* @hidden
*/
readonly apiUrl?: string;
/**
* Product information for internal statistics about product usage. Optional.
* @hidden
*/
readonly productInfo?: IProductInfo;
}
/**
* Class responsible for creating, publishing and retrieving Virgil Cards.
*/
export declare class CardManager {
readonly crypto: ICardCrypto;
readonly client: CardClient;
readonly modelSigner: ModelSigner;
readonly signCallback?: ISignCallback;
readonly cardVerifier: ICardVerifier;
retryOnUnauthorized: boolean;
accessTokenProvider: IAccessTokenProvider;
constructor(params: ICardManagerParams);
/**
* Generates a {@link RawSignedModel} that represents a card from
* `cardParams`.
* Use this method if you don't need to publish the card right away, for
* example if you need to first send it to your backend server to apply
* additional signature.
*
* @param {INewCardParams} cardParams - New card parameters.
* @returns {RawSignedModel}
*/
generateRawCard(cardParams: INewCardParams): RawSignedModel;
/**
* Generates a card from `cardParams` and publishes it in the Virgil Cards
* Service.
* @param {INewCardParams} cardParams - New card parameters.
* @returns {Promise<ICard>}
*/
publishCard(cardParams: INewCardParams): Promise<ICard>;
/**
* Publishes a previously generated card in the form of
* {@link RawSignedModel} object.
*
* @param {RawSignedModel} rawCard - The card to publish.
* @returns {Promise<ICard>}
*/
publishRawCard(rawCard: RawSignedModel): Promise<ICard>;
/**
* Fetches the card by `cardId` from the Virgil Card Service.
* @param {string} cardId - Id of the card to fetch.
* @returns {Promise<ICard>}
*/
getCard(cardId: string): Promise<ICard>;
/**
* Fetches collection of cards with the given `identity` from the Virgil
* Cards Service.
* @param {string|string[]} identities - Identity or an array of identities of the cards to fetch.
* @returns {Promise<ICard[]>}
*/
searchCards(identities: string | string[]): Promise<ICard[]>;
/**
* Marks the Virgil Card specified by `cardId` as revoked. Revoked cards will have `isOutdated`
* property set to `true` when retrieved via {@link CardManager.getCard} method.
* Also revoked cards will be absent in the {@link CardManager.searchCards} result.
* @param {string} cardId - Id of the card to revoke.
* @returns {Promise}
*/
revokeCard(cardId: string): Promise<void>;
/**
* Converts the card in the form of {@link RawSignedModel} object to the
* {@link ICard} object.
*
* @see {@link CardManager.exportCard}
*
* @param {RawSignedModel} rawCard - The card to convert.
* @returns {ICard}
*/
importCard(rawCard: RawSignedModel): ICard;
/**
* Converts the card in the base64 string form to the {@link ICard} object.
*
* @see {@link CardManager.exportCardAsString}
*
* @param {string} str - The string in base64.
* @returns {ICard}
*/
importCardFromString(str: string): ICard;
/**
* Converts the card in the JSON-serializable object form to the
* {@link ICard} object.
*
* @see {@link CardManager.exportCardAsJson}
*
* @param {IRawSignedModelJson} json
* @returns {ICard}
*/
importCardFromJson(json: IRawSignedModelJson): ICard;
/**
* Converts the card in the form of {@link ICard} object to the
* {@link RawSignedModel} object.
*
* @see {@link CardManager.importCard}
*
* @param {ICard} card
* @returns {RawSignedModel}
*/
exportCard(card: ICard): RawSignedModel;
/**
* Converts the card in the form of {@link ICard} object to the string
* in base64 encoding.
*
* @see {@link CardManager.importCardFromString}
*
* @param {ICard} card
* @returns {string}
*/
exportCardAsString(card: ICard): string;
/**
* Converts the card in the form of {@link ICard} object to the
* JSON-serializable object form.
*
* @see {@link CardManager.importCardFromJson}
*
* @param {ICard} card
* @returns {IRawSignedModelJson}
*/
exportCardAsJson(card: ICard): IRawSignedModelJson;
/**
* @hidden
*/
private publishRawSignedModel;
/**
* @hidden
*/
private tryDo;
/**
* Delegates to the {@link CardManager.cardVerifier} to verify the validity
* of the `cards`.
*
* @throws {@link VirgilCardVerificationError} if any of the cards is not
* valid.
*
* @param {ICard[]} cards
*/
private validateCards;
}