|
5 days ago | |
---|---|---|
.gitignore | 2 years ago | |
README.md | 5 days ago | |
endorser.d.ts | 5 days ago |
README.md
Endorser Types
Created: 2023-06-30
Last Updated: 2023-06-30
Version: 1.0.0
A shared TypeScript declaration file project that maintains typing structures external to individual applications, enabling type safety and consistency between backend and frontend implementations.
Overview
This project contains TypeScript declaration files (.d.ts
) that define shared interfaces and types used across multiple applications in the endorser ecosystem. By maintaining these types externally, we ensure:
- Type Safety: Consistent typing between backend and frontend
- Code Reusability: Single source of truth for shared data structures
- Maintainability: Centralized type definitions that can be updated once
- Developer Experience: Better IntelliSense and compile-time error checking
Structure
Core Interfaces
The endorser.d.ts
file contains the following key interfaces:
Verifiable Credentials
AgreeVerifiableCredential
: Represents an agreement on a verifiable credentialGiveVerifiableCredential
: Represents a "give" action in the endorser systemRegisterVerifiableCredential
: Represents registration of a verifiable credential
Data Structures
GiveServerRecord
: Server-side record for give operationsGenericClaim
: Generic claim structure with flexible contentClaimResult
: Result structure for claim operations
Error Handling
InternalError
: Standardized error structure for internal operations
Usage
Installation
# If published as an npm package
npm install @your-org/endorser-types
# Or include directly in your project
# Copy endorser.d.ts to your project's types directory
Import and Use
import type {
GiveVerifiableCredential,
GiveServerRecord,
InternalError
} from 'endorser-types';
// Use in your application
const giveCredential: GiveVerifiableCredential = {
"@type": "GiveVerifiableCredential",
recipient: { identifier: "did:example:123" },
object: { amountOfThisGood: 100, unitCode: "USD" }
};
Backend Integration
// Express.js example
import type { GiveServerRecord, InternalError } from 'endorser-types';
app.post('/give', (req, res) => {
try {
const record: GiveServerRecord = {
agentDid: req.body.agentDid,
amount: req.body.amount,
// ... other fields
};
// Process the record
} catch (error) {
const internalError: InternalError = {
error: error.message,
userMessage: "An error occurred processing your request"
};
res.status(500).json(internalError);
}
});
Frontend Integration
// React example
import type { GiveVerifiableCredential } from 'endorser-types';
interface GiveFormProps {
onSubmit: (credential: GiveVerifiableCredential) => void;
}
const GiveForm: React.FC<GiveFormProps> = ({ onSubmit }) => {
// Form implementation using the shared types
};
Development
Adding New Types
- Add new interfaces to
endorser.d.ts
- Follow the existing naming conventions
- Include JSDoc comments for complex types
- Update this README with new type descriptions
Type Guidelines
- Use descriptive interface names that clearly indicate their purpose
- Include optional properties where appropriate (marked with
?
) - Use
Record<string, any>
for flexible object structures - Maintain backward compatibility when possible
- Follow TypeScript best practices for declaration files
Versioning
When making breaking changes:
- Increment the major version number
- Document migration steps
- Consider maintaining deprecated types for a transition period
Security Considerations
- All types are for compile-time checking only
- Runtime validation should still be implemented in consuming applications
- Sensitive data structures should be carefully designed to avoid exposing internal details
- Consider using branded types for sensitive identifiers (DIDs, etc.)
Contributing
- Ensure all new types are properly documented
- Test type compatibility with both backend and frontend projects
- Update this README when adding new interfaces
- Follow the existing code style and conventions
License
[Add your license information here]
Author
Matthew Raymer
Initial Development: 2023-06-30
File History
Date | Commit | Description |
---|---|---|
2023-06-30 | db51253 |
Initial commit - Core type definitions for endorser system |
This project serves as a foundational type system for the endorser ecosystem, ensuring consistency and type safety across all applications.