did-sdk-js
Version:
js sdk for did and vc according to mcps did spec
119 lines (118 loc) • 4.41 kB
TypeScript
import * as crypto from "../crypto";
import { SdkError } from "../errors";
export declare enum IDGenType {
IDGenTypeBech32 = "bech32",
IDGenTypeUUID = "uuid"
}
export declare class PublicKey {
id: string;
type: crypto.KeyType;
publicKeyHex: string;
constructor(keyId: string, keyType: crypto.KeyType, publicKeyHex: string);
verifySignature(signData: string, signValue: string): Promise<any>;
checkParam(): SdkError | null;
encrypt(plainText: string): Promise<string>;
}
declare class Authentication {
type: crypto.VerifyType;
publicKey: string[];
constructor(verifyType: crypto.VerifyType, publicKey: string[]);
checkParam(): SdkError | null;
}
declare class Proof {
type: string;
creator: string;
signatureValue: string;
constructor(verifyType: crypto.VerifyType, creator: string, signatureValue: string);
}
export declare class DIDUrl {
static fragmentTag: string;
static paramTag: string;
static pathTag: string;
static fragmentKeyIdMain: string;
static fragmentKeyIdApp: string;
static fragmentServiceIdResolver: string;
static fragmentKeyMain: string;
static fragmentKeyApp: string;
static makeKeyUrl(didStr: string, keyId: string): string;
static getFragment(url: string): string;
}
export declare class DIDPrivateKey {
keyId: string;
algo: crypto.AlgoType;
privateKeyHex: string;
mnemonic: string;
publicKeyHex: string;
constructor(keyId: string, algoType: crypto.AlgoType, privateKeyHex: string, publicKeyHex: string, mnemonic: string);
}
export declare class DidDocument {
static startVersion: number;
static w3cContext: string;
static didPrefix: string;
static didMethod: string;
static firstVersion: number;
context: string[];
id: string;
version: number;
created: string;
updated: string;
revoked: string;
publicKey: PublicKey[];
authentication: Authentication[];
recovery: string[];
service: any[];
controller: string[];
proof: Proof[];
constructor();
init(id: string): void;
setVersion(ver: number): void;
versionInc(): void;
setId(id: string): void;
setCreateTime(time: string | null): void;
setUpdateTime(time: string | null): void;
setRevokeTime(time: string | null): void;
addPublicKey(publicKey: PublicKey): void;
updatePublicKey(keyID: string, keyType: crypto.KeyType, publicKeyHex: string): void;
addRecoveryKey(keyUrl: string): void;
addAuthentication(auth: Authentication): void;
updateAuthenticationType(keyID: string, verifyType: crypto.VerifyType): void;
addProof(proof: Proof): void;
rmProof(): void;
static makeIdByUUID(regionID: string): string;
static makeIdByBench32(regionID: string, publicKeyHex: string): string;
checkEmpty(): SdkError | null;
checkPublicKey(): SdkError | null;
checkAuthentication(): SdkError | null;
checkIDFormat(): SdkError | null;
checkUpdateTime(): SdkError | null;
checkRevokeTime(): SdkError | null;
validateBasic(): SdkError | null;
static creatDID(algoType: crypto.AlgoType, idGenType: IDGenType, regionID: string): Promise<{
document: DidDocument;
didPrivateInfo: DIDPrivateKey[];
}>;
isRevoked(): boolean;
resetPublicKey(algoType: crypto.AlgoType, keyID: string, mainPrivateKeyInfo: DIDPrivateKey): Promise<{
document: DidDocument;
privateInfo: DIDPrivateKey;
}>;
revoke(mainPrivateKeyInfo: DIDPrivateKey): Promise<DidDocument>;
getPublicKeyByKeyID(keyID: string): PublicKey | null;
signVerify(lastVersionDoc: DidDocument | null): Promise<SdkError | null>;
getSignData(): string;
toString(): string;
copy(): DidDocument;
static parseFrom(docStr: string): DidDocument;
static checkNewerVersion(oldD: DidDocument, newD: DidDocument): Promise<SdkError | null>;
static getValidAndLatestVersions(docs: DidDocument[]): Promise<{
valid: DidDocument[];
latest: null;
} | {
valid: DidDocument[];
latest: DidDocument;
}>;
getPublicKeyByKeyHex(pubKeyHex: string): PublicKey | null;
getPublicKeyByKeyUrl(keyUrl: string): PublicKey | null;
hasAuthenticationPerm(publicKey: PublicKey): boolean;
}
export {};