Files
motr-enclave/src/types.ts

128 lines
3.4 KiB
TypeScript

/**
* TypeScript types for Motr Enclave plugin
* These types match the Go structs in main.go
*/
// ============================================================================
// Generate
// ============================================================================
export interface GenerateInput {
/** Base64-encoded PublicKeyCredential from WebAuthn registration */
credential: string;
}
export interface GenerateOutput {
/** The generated DID (e.g., "did:sonr:abc123") */
did: string;
/** Serialized database buffer for storage */
database: number[];
}
// ============================================================================
// Load
// ============================================================================
export interface LoadInput {
/** Raw database bytes (typically from IPFS CID resolution) */
database: number[];
}
export interface LoadOutput {
success: boolean;
did?: string;
error?: string;
}
// ============================================================================
// Exec
// ============================================================================
export interface ExecInput {
/** GitHub-style filter: "resource:accounts action:sign subject:did:sonr:abc" */
filter: string;
/** UCAN token for authorization (optional) */
token?: string;
}
export interface ExecOutput {
success: boolean;
result?: unknown;
error?: string;
}
// ============================================================================
// Query
// ============================================================================
export interface QueryInput {
/** DID to resolve (empty string uses current DID) */
did: string;
}
export interface QueryOutput {
did: string;
controller: string;
verification_methods: VerificationMethod[];
accounts: Account[];
credentials: Credential[];
}
// ============================================================================
// Shared Types
// ============================================================================
export interface VerificationMethod {
id: string;
type: string;
controller: string;
public_key: string;
purpose: string;
}
export interface Account {
address: string;
chain_id: string;
coin_type: number;
account_index: number;
address_index: number;
label: string;
is_default: boolean;
}
export interface Credential {
credential_id: string;
device_name: string;
device_type: string;
authenticator: string;
transports: string[];
created_at: string;
last_used: string;
}
// ============================================================================
// Enclave Options
// ============================================================================
export interface EnclaveOptions {
logger?: Pick<Console, 'log' | 'error' | 'warn' | 'info' | 'debug'>;
debug?: boolean;
}
// ============================================================================
// Filter Builder Types
// ============================================================================
export type Resource = 'accounts' | 'credentials' | 'sessions' | 'grants';
export type AccountAction = 'list' | 'sign';
export type CredentialAction = 'list';
export type SessionAction = 'list' | 'create' | 'revoke';
export type GrantAction = 'list' | 'create' | 'revoke';
export interface FilterBuilder {
resource(r: Resource): this;
action(a: string): this;
subject(s: string): this;
build(): string;
}