@synet/did
Version:
Secure, minimal, standards-compliant DID library for production environments. Supports did:key and did:web methods with strict validation and cryptographic security.
140 lines (139 loc) • 3.73 kB
TypeScript
/**
* @synet/did - Simple DID library for Synet network
*
* Core types and interfaces for Decentralized Identifiers (DIDs).
* This package provides minimal, dependency-free DID creation and manipulation.
*
* Types aligned with did-resolver specification for maximum compatibility.
*/
/**
* Supported DID methods for production use
*/
export type DIDMethod = "key" | "web";
/**
* DID URL components
*/
export interface DIDComponents {
method: DIDMethod;
identifier: string;
path?: string;
query?: Record<string, string>;
fragment?: string;
}
/**
* Key capability sections from DID specification
*/
export type KeyCapabilitySection = "authentication" | "assertionMethod" | "keyAgreement" | "capabilityInvocation" | "capabilityDelegation";
/**
* JSON Web Key structure for public keys
*/
export interface JsonWebKey {
kty: string;
use?: string;
key_ops?: string[];
alg?: string;
kid?: string;
x5u?: string;
x5c?: string[];
x5t?: string;
"x5t#S256"?: string;
[x: string]: unknown;
}
/**
* DID Document verification method (aligned with did-resolver)
*/
export interface VerificationMethod {
id: string;
type: string;
controller: string;
publicKeyBase58?: string;
publicKeyBase64?: string;
publicKeyJwk?: JsonWebKey;
publicKeyHex?: string;
publicKeyMultibase?: string;
blockchainAccountId?: string;
ethereumAddress?: string;
conditionOr?: VerificationMethod[];
conditionAnd?: VerificationMethod[];
threshold?: number;
conditionThreshold?: VerificationMethod[];
conditionWeightedThreshold?: ConditionWeightedThreshold[];
conditionDelegated?: string;
relationshipParent?: string[];
relationshipChild?: string[];
relationshipSibling?: string[];
}
/**
* Condition weighted threshold for ConditionalProof2022
*/
export interface ConditionWeightedThreshold {
condition: VerificationMethod;
weight: number;
}
/**
* Service endpoint type (aligned with did-resolver)
*/
export type ServiceEndpoint = string | Record<string, unknown>;
/**
* DID Document service (aligned with did-resolver)
*/
export interface Service {
id: string;
type: string;
serviceEndpoint: ServiceEndpoint | ServiceEndpoint[];
[x: string]: unknown;
}
/**
* DID Document structure (aligned with did-resolver)
*/
export interface DIDDocument {
"@context"?: "https://www.w3.org/ns/did/v1" | string | string[];
id: string;
alsoKnownAs?: string[];
controller?: string | string[];
verificationMethod?: VerificationMethod[];
service?: Service[];
/**
* @deprecated Use verificationMethod instead
*/
publicKey?: VerificationMethod[];
authentication?: (string | VerificationMethod)[];
assertionMethod?: (string | VerificationMethod)[];
keyAgreement?: (string | VerificationMethod)[];
capabilityInvocation?: (string | VerificationMethod)[];
capabilityDelegation?: (string | VerificationMethod)[];
}
/**
* DID creation options
*/
export interface DIDCreateOptions {
method: DIDMethod;
publicKey?: string;
keyType?: "ed25519-pub" | "secp256k1-pub" | "x25519-pub" | "Ed25519" | "secp256k1" | "X25519";
domain?: string;
path?: string;
}
/**
* DID parsing result
*/
export interface DIDParseResult {
did: string;
components: DIDComponents;
isValid: boolean;
error?: string;
}
/**
* DID validation result
*/
export interface DIDValidationResult {
isValid: boolean;
error?: string;
warnings?: string[];
}
/**
* Error thrown when DID operations fail
*/
export declare class DIDError extends Error {
code?: string | undefined;
constructor(message: string, code?: string | undefined);
}