@hap-protocol/sdk
v0.1.0
Published
TypeScript SDK for the Human Authorship Protocol (HAP)
Maintainers
Readme
@hap-protocol/sdk
TypeScript SDK for the Human Authorship Protocol (HAP) — create, score, and anchor human authorship records for AI-assisted creative works.
Installation
npm install @hap-protocol/sdkQuick Start
import { createHAPRecord, hashHAPRecord, hashContent } from '@hap-protocol/sdk';
import { readFileSync } from 'fs';
// Hash your work file
const fileBuffer = readFileSync('./my-song.mp3');
const contentHash = hashContent(fileBuffer);
// Create a HAP record
const record = createHAPRecord({
creator: {
wallet_address: '0xYourWalletAddress',
identifier: 'artist-name',
},
work: {
title: 'My Song',
type: 'music',
description: 'Original track produced with AI assistance',
content_hash: contentHash,
uri: 'ipfs://QmYourIPFSHash',
},
ai_tools: [
{ name: 'Suno', version: '4.0', role: 'Melody and instrumentation generation' },
],
layers: {
recipes: {
score: 0.9,
evidence: 'Custom genre template and style guide created by artist',
artifacts: ['ipfs://QmStyleGuide'],
},
voice: {
score: 0.85,
evidence: 'Consistent with artist\'s established Southern hip-hop aesthetic',
artifacts: [],
},
inputs: {
score: 0.8,
evidence: 'Detailed lyrical direction, BPM, key, and mood brief provided',
artifacts: ['ipfs://QmPromptLog'],
},
iteration: {
score: 0.75,
evidence: '14 revision rounds with specific directional feedback each time',
artifacts: ['ipfs://QmRevisionHistory'],
},
curation: {
score: 0.9,
evidence: 'Selected from 8 generated variants, arranged and sequenced by artist',
artifacts: [],
},
},
});
console.log('HCS:', record.hcs); // e.g. 0.84
console.log('Tier:', record.tier_label); // "Primary Human Authorship"
// Get the record hash for on-chain anchoring
const recordHash = hashHAPRecord(record);
console.log('Record Hash:', recordHash);API
createHAPRecord(input)
Creates a new HAP record, computes HCS, and assigns a tier.
hashHAPRecord(record)
Returns the SHA-256 hash of the HAP record JSON. Used for on-chain anchoring.
hashContent(content)
Returns the SHA-256 hash of a file buffer or string.
computeHCS(layers, weights?)
Computes the Human Contribution Score from layer scores and optional weights.
getTier(hcs)
Returns the HCS tier (1–4) for a given score.
markAnchored(record, txHash, blockNumber)
Returns an updated record with on-chain anchoring details filled in.
On-Chain Anchoring
To anchor a record to the Guapcoin blockchain, use the bridge-guapcoin contract with the recordHash from hashHAPRecord().
License
MIT
