Skip to main content

License

Type-safe SPDX license identifiers for smart contract metadata.

Overview

Branded string type representing SPDX license identifiers. Used in Solidity source files and smart contract metadata to identify licensing terms. Includes validation for OSI-approved licenses.

Quick Start

import * as License from '@tevm/voltaire/License'

// Create license identifier
const mit = License.from("MIT")
const apache = License.from("Apache-2.0")
const unlicensed = License.from("UNLICENSED")

// Convert to string
License.toString(mit)  // "MIT"

// Check OSI approval
License.isOSI("MIT")        // true
License.isOSI("Apache-2.0") // true
License.isOSI("UNLICENSED") // false

Common Licenses

LicenseOSI ApprovedDescription
MITYesPermissive, minimal restrictions
Apache-2.0YesPermissive with patent grant
GPL-3.0YesStrong copyleft
GPL-2.0YesStrong copyleft (earlier version)
LGPL-3.0YesWeak copyleft for libraries
BSD-3-ClauseYesPermissive with attribution
BSD-2-ClauseYesSimplified BSD
ISCYesSimplified BSD-like
MPL-2.0YesWeak copyleft file-level
AGPL-3.0YesStrong copyleft + network use
UNLICENSEDNoProprietary/no license

API Reference

Constructors

import * as License from '@tevm/voltaire/License'

// Create from SPDX identifier
const license = License.from("MIT")

Methods

import * as License from '@tevm/voltaire/License'

const license = License.from("Apache-2.0")

// Convert to string
License.toString(license)  // "Apache-2.0"

// Check if OSI-approved
License.isOSI(license)     // true
License.isOSI("GPL-3.0")   // true
License.isOSI("UNLICENSED") // false

Constants

import { COMMON_LICENSES, OSI_APPROVED_LICENSES } from '@tevm/voltaire/License'

// Common SPDX license identifiers
COMMON_LICENSES: string[]

// OSI-approved open source licenses
OSI_APPROVED_LICENSES: string[]

Solidity License Identifier

SPDX license identifiers are required in Solidity files since version 0.6.8:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
The identifier appears in compiled contract metadata and can be used to:
  • Identify licensing terms programmatically
  • Filter contracts by license type
  • Ensure compliance with open source requirements

Use Cases

Contract Metadata Analysis

import * as License from '@tevm/voltaire/License'

interface ContractMetadata {
  license: string
  compiler: string
  source: string
}

function analyzeContract(metadata: ContractMetadata) {
  const license = License.from(metadata.license)

  return {
    license: License.toString(license),
    isOpenSource: License.isOSI(license),
    isPermissive: ["MIT", "Apache-2.0", "BSD-3-Clause"].includes(
      License.toString(license)
    )
  }
}

License Filtering

import * as License from '@tevm/voltaire/License'
import { OSI_APPROVED_LICENSES } from '@tevm/voltaire/License'

interface Contract {
  address: string
  license: string
}

function filterOpenSourceContracts(contracts: Contract[]): Contract[] {
  return contracts.filter(c => License.isOSI(c.license))
}

function filterByLicense(contracts: Contract[], allowed: string[]): Contract[] {
  return contracts.filter(c => allowed.includes(c.license))
}

// Only permissive licenses
const permissive = filterByLicense(contracts, ["MIT", "Apache-2.0", "BSD-3-Clause"])

References