@nuwa-ai/identity-kit
Version:
SDK for NIP-1 Agent Single DID Multi-Key Model and NIP-3 CADOP (Custodian-Assisted DID Onboarding Protocol)
336 lines (332 loc) • 12.7 kB
text/typescript
import { Signer } from '@roochnetwork/rooch-sdk';
import { i as VDRInterface, b as DIDDocument, V as VerificationRelationship, e as DIDCreationRequest, f as DIDCreationResult, C as CADOPCreationRequest, g as CADOPControllerCreationRequest, c as VerificationMethod, d as ServiceEndpoint, S as SignerInterface } from './IdentityKit-DE2ZpFFA.cjs';
/**
* Abstract base class for implementing Verifiable Data Registry functionality
* Provides common utility methods and enforces the VDRInterface contract
*/
declare abstract class AbstractVDR implements VDRInterface {
protected readonly method: string;
/**
* Creates a new AbstractVDR instance
*
* @param method The DID method this VDR handles
*/
constructor(method: string);
/**
* Gets the DID method this VDR handles
*
* @returns The DID method string
*/
getMethod(): string;
/**
* Validates that a given DID matches the method this VDR handles
*
* @param did The DID to validate
* @throws Error if the DID doesn't match this VDR's method
*/
protected validateDIDMethod(did: string): void;
/**
* Validates a DID document's basic structure
*
* @param document The DID document to validate
* @returns true if valid, throws an error otherwise
*/
protected validateDocument(document: DIDDocument): boolean;
/**
* Check if a key has a specific verification relationship in a DID document
*
* @param didDocument The DID document to check
* @param keyId The ID of the verification method
* @param relationship The verification relationship to check
* @returns True if the key has the relationship
*/
protected hasVerificationRelationship(didDocument: DIDDocument, keyId: string, relationship: VerificationRelationship): boolean;
/**
* Validates if a key has permission to perform an operation
*
* @param didDocument The DID document
* @param keyId The ID of the key
* @param requiredRelationship The required verification relationship
* @returns True if the key has permission
*/
protected validateKeyPermission(didDocument: DIDDocument, keyId: string, requiredRelationship: VerificationRelationship): boolean;
/**
* Default create implementation - throws not implemented error for base class
* Subclasses must override this method to provide actual implementation
*/
create(request: DIDCreationRequest, options?: any): Promise<DIDCreationResult>;
/**
* Default CADOP implementation - throws not implemented error
*/
createViaCADOP(request: CADOPCreationRequest, options?: any): Promise<DIDCreationResult>;
/**
* Default CADOP with controller implementation - throws not implemented error
*/
createViaCADOPWithController(request: CADOPControllerCreationRequest, options?: any): Promise<DIDCreationResult>;
/**
* Build DID Document from creation request
*/
protected buildDIDDocumentFromRequest(request: DIDCreationRequest): DIDDocument;
/**
* Resolves a DID to its corresponding DID document
* Implementations must provide this functionality
*/
abstract resolve(did: string): Promise<DIDDocument | null>;
/**
* Checks if a DID exists in the registry
* Default implementation tries to resolve and checks if result is not null
*/
exists(did: string): Promise<boolean>;
/**
* Add a verification method to a DID document
* Default implementation that should be overridden by specific VDR implementations
*/
addVerificationMethod(did: string, verificationMethod: VerificationMethod, relationships?: VerificationRelationship[], options?: any): Promise<boolean>;
/**
* Remove a verification method from a DID document
* Default implementation that should be overridden by specific VDR implementations
*/
removeVerificationMethod(did: string, id: string, options?: any): Promise<boolean>;
/**
* Add a service to a DID document
* Default implementation that should be overridden by specific VDR implementations
*/
addService(did: string, service: ServiceEndpoint, options?: any): Promise<boolean>;
/**
* Remove a service from a DID document
* Default implementation that should be overridden by specific VDR implementations
*/
removeService(did: string, id: string, options?: any): Promise<boolean>;
/**
* Update verification relationships for a verification method
* Default implementation that should be overridden by specific VDR implementations
*/
updateRelationships(did: string, id: string, add: VerificationRelationship[], remove: VerificationRelationship[], options?: any): Promise<boolean>;
/**
* Update the controller of a DID document
* Default implementation that should be overridden by specific VDR implementations
*/
updateController(did: string, controller: string | string[], options?: any): Promise<boolean>;
/**
* Validates options for update operations and ensures proper permissions
*
* @param did The DID being operated on
* @param document The resolved DID document
* @param keyId The key ID used for signing
* @param requiredRelationship The required verification relationship for this operation
* @throws Error if validation fails
*/
protected validateUpdateOperation(did: string, document: DIDDocument | null, keyId: string, requiredRelationship: VerificationRelationship): Promise<DIDDocument>;
/**
* Validates that inputs to addVerificationMethod are correct
*
* @param did The DID being operated on
* @param verificationMethod The verification method to validate
* @param document The current DID document
* @throws Error if validation fails
*/
protected validateVerificationMethod(did: string, verificationMethod: VerificationMethod, document: DIDDocument): void;
/**
* Validates that inputs to addService are correct
*
* @param did The DID being operated on
* @param service The service to validate
* @param document The current DID document
* @throws Error if validation fails
*/
protected validateService(did: string, service: ServiceEndpoint, document: DIDDocument): void;
/**
* Makes a deep copy of a DID document for modification
*
* @param document The DID document to copy
* @returns A deep copy of the document
*/
protected copyDocument(document: DIDDocument): DIDDocument;
}
interface RoochClientConfig {
url: string;
transport?: any;
}
interface RoochTransactionResult {
execution_info: {
status: {
type: string;
};
gas_used: string;
};
output?: {
events?: Array<{
event_type: string;
event_data: string;
event_index: string;
decoded_event_data?: any;
}>;
};
transaction: any;
}
/**
* Options for RoochVDR configuration
*/
interface RoochVDROptions {
/**
* Rooch RPC endpoint URL
*/
rpcUrl?: string;
/**
* Network type (local, dev, test, main)
*/
network?: 'local' | 'dev' | 'test' | 'main';
/**
* Enable debug mode for detailed logging
*/
debug?: boolean;
}
/**
* Result of store operation with actual DID address
*/
interface StoreResult {
success: boolean;
actualDIDAddress?: string;
}
/**
* Options for Rooch VDR operations
*/
interface RoochVDROperationOptions {
/**
* Signer to use for this operation
*/
signer?: SignerInterface | Signer;
/**
* Key ID to use for this operation
*/
keyId?: string;
/**
* Custom session key scopes (for authentication VM)
* Only used when adding a verification method with authentication relationship
*/
scopes?: string[];
/**
* Advanced blockchain transaction options
* For high-level users who need fine-grained control over transaction parameters
*/
advanced?: RoochTxnOptions;
}
/**
* Advanced Rooch blockchain transaction options
* These options are typically only needed for advanced use cases
*/
interface RoochTxnOptions {
/**
* Maximum gas limit for the transaction
*/
maxGas?: number;
}
/**
* VDR implementation for did:rooch method
*
* This implementation integrates with Rooch network's DID contract system
* to provide on-chain DID document storage and management.
*/
declare class RoochVDR extends AbstractVDR {
private readonly options;
private client;
private readonly didContractAddress;
private readonly debug;
private readonly logger;
private lastCreatedDIDAddress?;
constructor(options: RoochVDROptions);
/**
* Log message if debug mode is enabled
*/
private debugLog;
/**
* Log error message (always logged regardless of debug mode)
*/
private errorLog;
private convertSigner;
/**
* Override create method to support Rooch dynamic DID generation
*/
create(request: DIDCreationRequest, options?: RoochVDROperationOptions): Promise<DIDCreationResult>;
/**
* Override CADOP creation method
*/
createViaCADOP(request: CADOPCreationRequest, options?: RoochVDROperationOptions): Promise<DIDCreationResult>;
/**
* Create DID via CADOP with controller (supports did:key, did:bitcoin, etc.)
*/
createViaCADOPWithController(request: CADOPControllerCreationRequest, options?: RoochVDROperationOptions): Promise<DIDCreationResult>;
/**
* Resolve DID Document from Rooch blockchain
*
* @param did The DID to resolve (e.g., "did:rooch:0x123...")
* @returns Promise resolving to the DID Document or null if not found
*/
resolve(did: string): Promise<DIDDocument | null>;
/**
* Check if a DID exists on the Rooch network
*
* @param did The DID to check
* @returns Promise resolving to true if the DID exists
*/
exists(did: string): Promise<boolean>;
/**
* Add a verification method to a DID document on Rooch blockchain
*/
addVerificationMethod(did: string, verificationMethod: VerificationMethod, relationships?: VerificationRelationship[], options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Remove a verification method from a DID document on Rooch blockchain
*/
removeVerificationMethod(did: string, id: string, options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Add a service to a DID document on Rooch blockchain
*/
addService(did: string, service: ServiceEndpoint, options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Add a service with properties to a DID document on Rooch blockchain
*/
addServiceWithProperties(did: string, service: ServiceEndpoint & {
properties?: Record<string, string>;
}, options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Remove a service from a DID document on Rooch blockchain
*/
removeService(did: string, id: string, options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Update verification relationships for a verification method on Rooch blockchain
*/
updateRelationships(did: string, id: string, add: VerificationRelationship[], remove: VerificationRelationship[], options?: RoochVDROperationOptions): Promise<boolean>;
/**
* Create a new Rooch transaction instance
*/
private createTransaction;
/**
* Convert verification relationships to u8 values based on did.move constants
*/
private convertVerificationRelationships;
/**
* Convert a single verification relationship to u8 value
*/
private convertVerificationRelationship;
/**
* Check if a signer has permission to perform an operation on a DID
*/
private hasPermissionForOperation;
/**
* Parse DIDCreatedEvent using BCS schema and return the DID address
*/
private parseDIDCreatedEventAndGetDID;
/**
* Get the last created DID address from the most recent store operation
*/
getLastCreatedDIDAddress(): string | undefined;
/**
* Create a RoochVDR instance with default configuration
*/
static createDefault(network?: 'local' | 'dev' | 'test' | 'main', rpcUrl?: string | undefined): RoochVDR;
/**
* Get network-specific RPC URL
*/
private static getRoochNodeUrl;
}
export { AbstractVDR as A, RoochVDR as R, type StoreResult as S, type RoochClientConfig as a, type RoochTransactionResult as b, type RoochVDROptions as c, type RoochVDROperationOptions as d, type RoochTxnOptions as e };