# Content Licensing Service

NFT-backed licensing and attribution orchestration for Lilith content. The
service coordinates policy composition, compliance validation, metadata
assembly, artifact storage, NFT minting, attribution telemetry, royalty
distribution, and revocation audit trails.

## Pipeline

1. **Content registry** – fetches canonical content metadata and creator
   credits.
2. **Policy composer + validator** – generates license terms and enforces
   creator/compliance guardrails.
3. **Metadata builder** – assembles on-chain/off-chain metadata packages for the
   license NFT.
4. **Artifact storage** – persists policy, metadata, and attribution manifests
   (e.g., IPFS).
5. **NFT minter** – mints the license token on the configured chain.
6. **License ledger** – records issuance, attribution usage, distributions, and
   revocations.
7. **Attribution service** – indexes license attribution and provides usage
   summaries.
8. **Distribution engine** – executes royalty payouts with attribution context.
9. **Revocation orchestrator** – handles compliance-triggered license shutdowns
   and audit logs.
10. **Analytics reporter** – emits telemetry for issuance, attribution, payouts,
    and revocations.

## Usage

```ts
import { createContentLicensingService } from './service';

const service = createContentLicensingService({
  contentRegistry,
  policyComposer,
  policyValidator,
  metadataBuilder,
  artifactStorage,
  nftMinter,
  licenseLedger,
  analyticsReporter,
  attributionService,
  distributionEngine,
  revocationOrchestrator,
});

const issuance = await service.issueLicense({
  contentId: 'teaching-emerald-light',
  licensee: { address: '0xlicensee', name: 'Lumina Studios' },
  usage: {
    channels: ['web', 'mobile'],
    territories: ['global'],
    expiresAtIso: '2026-01-01T00:00:00.000Z',
  },
  financials: { upfrontFee: '1.5', currency: 'ETH', royaltyBps: 1200 },
  distributionPlan: { reportingIntervalDays: 30, auditRights: true },
  chainId: 137,
});

await service.recordAttributionEvent({
  licenseId: issuance.licenseId,
  contentId: 'teaching-emerald-light',
  channel: 'web',
  impressions: 500,
  metadata: { region: 'NA' },
});

await service.distributeRoyalties({
  licenseId: issuance.licenseId,
  initiatedBy: 'ops-bot',
  amount: '0.75',
  currency: 'ETH',
  trigger: 'scheduled',
  periodStartIso: '2025-01-01T00:00:00.000Z',
  periodEndIso: '2025-02-01T00:00:00.000Z',
});
```

## Tests

```bash
cd apps/lilith/svc-content-licensing
npm test
```
