@arcblock/vc
Version:
TypeScript lib to work with ArcBlock Verifiable Credentials
178 lines (177 loc) • 4.35 kB
text/typescript
import { WalletObject } from "@ocap/wallet";
import stringify from "json-stable-stringify";
//#region src/index.d.ts
interface Proof {
type: string;
created: string;
proofPurpose: string;
jws: string;
id?: string;
signer?: string;
pk?: string;
previousProof?: string | string[];
verificationMethod?: string;
}
interface Issuer {
id: string;
pk: string;
name: string;
}
interface CredentialSubject {
id: string;
[key: string]: unknown;
}
interface CredentialStatus {
id: string;
type: string;
scope: string;
}
interface VerifiableCredential {
'@context': string | string[];
id: string;
type: string | string[];
issuer: Issuer;
issuanceDate: string;
expirationDate?: string;
credentialSubject: CredentialSubject;
proof: Proof | Proof[];
tag?: string;
credentialStatus?: CredentialStatus;
signature?: unknown;
}
interface IssuerInfo {
wallet: WalletObject;
name?: string;
}
interface Presentation {
challenge: string;
verifiableCredential: string | string[];
proof: Proof | Proof[];
[key: string]: unknown;
}
interface Credential {
id: string;
issued: string;
issuer: Issuer;
proof: Proof | Proof[];
claim: unknown;
}
declare const proofTypes: Record<number, string>;
/**
* Create a valid verifiable credential
*
* @param params
* @param params.type - The type of credential
* @param params.subject - The content of credential
* @param params.issuer - The issuer name and wallet
* @param params.issuanceDate
* @param params.expirationDate
* @param params.endpoint - Status endpoint url
* @param params.endpointScope - Endpoint scope, either be public or private
* @returns Promise<object>
*/
declare function create({
type,
subject,
issuer,
issuanceDate,
expirationDate,
tag,
endpoint,
endpointScope
}: {
type: string | string[];
subject: CredentialSubject;
issuer: IssuerInfo;
issuanceDate?: string;
expirationDate?: string;
tag?: string;
endpoint?: string;
endpointScope?: string;
}): Promise<VerifiableCredential | null>;
/**
* Verify that the verifiable credential is valid
* - It is signed by a whitelist of issuers
* - It is owned by the vc.subject.id
* - It has valid signature by the issuer
* - It is not expired
*
* @param vc - the verifiable credential object
* @param ownerDid - vc holder/owner did
* @param trustedIssuers - list of issuer did
* @throws Error
* @returns Promise<boolean>
*/
declare function verify({
vc,
ownerDid,
trustedIssuers,
ignoreExpired
}: {
vc: VerifiableCredential | null;
ownerDid: string;
trustedIssuers: string | string[];
ignoreExpired?: boolean;
}): Promise<boolean>;
/**
* Counter-sign an existing verifiable credential
* Adds a new proof from a different signer to the VC
*
* @param params
* @param params.vc - The already-signed verifiable credential
* @param params.wallet - The counter-signer's wallet
* @param params.mode - 'set' (independent proof) or 'chain' (references previous proofs)
* @returns Promise<VerifiableCredential>
*/
declare function counterSign({
vc,
wallet,
mode
}: {
vc: VerifiableCredential;
wallet: WalletObject;
mode?: 'set' | 'chain';
}): Promise<VerifiableCredential>;
/**
* Verify that the Presentation is valid
* - It is signed by VC's owner
* - It contain challenge
* - It has valid signature by the issuer
* - It is not expired
*
* @param presentation - the presentation object
* @param trustedIssuers - list of issuer did
* @param challenge - Random byte you want
* @throws Error
* @returns Promise<boolean>
*/
declare function verifyPresentation({
presentation,
trustedIssuers,
challenge,
ignoreExpired
}: {
presentation: Presentation;
trustedIssuers: string[];
challenge: string;
ignoreExpired?: boolean;
}): Promise<boolean>;
declare function createCredentialList({
claims,
issuer,
issuanceDate
}: {
claims: unknown[];
issuer: IssuerInfo;
issuanceDate?: string;
}): Promise<Credential[]>;
declare function verifyCredentialList({
credentials,
trustedIssuers
}: {
credentials: Credential[];
trustedIssuers: string | string[];
}): Promise<unknown[]>;
declare const stableStringify: typeof stringify;
//#endregion
export { counterSign, create, createCredentialList, proofTypes, stableStringify, verify, verifyCredentialList, verifyPresentation };