#601

Global Rank · of 601 Skills

create-script-template AI Agent Skill

View Source: b-open-io/bsv-skills

Critical

Installation

npx skills add b-open-io/bsv-skills --skill create-script-template

20

Installs

Create Script Template

Create script templates for the b-open-io/ts-templates repository following established patterns.

When to Use

  • Create a new BitCom protocol template (like AIP, MAP, SIGMA)
  • Build an OP_RETURN data template
  • Implement a ScriptTemplate for a new protocol
  • Add a template to ts-templates repository

Template Structure

Every template follows this pattern:

import { ScriptTemplate, LockingScript, UnlockingScript, Script, Utils } from '@bsv/sdk'
import BitCom, { Protocol, BitComDecoded } from './BitCom.js'

export const PREFIX = 'PROTOCOL_ID'

export interface ProtocolData {
  bitcomIndex?: number
  // protocol-specific fields
  valid?: boolean
}

export default class Protocol implements ScriptTemplate {
  public readonly data: ProtocolData

  constructor(data: ProtocolData) {
    this.data = data
  }

  static decode(bitcom: BitComDecoded): Protocol[] { /* ... */ }
  static sign(/* params */): Promise<Protocol> { /* ... */ }
  lock(): LockingScript { /* ... */ }
  unlock(): { sign: Function, estimateLength: Function } { /* ... */ }
  verify(): boolean { /* ... */ }
}

Creation Process

Step 1: Understand the Protocol

Gather protocol specifications:

  • Protocol prefix/identifier (Bitcoin address or literal string)
  • Field order and data types
  • Signing requirements (if any)
  • Verification logic

Step 2: Create Template File

Location: src/template/bitcom/ProtocolName.ts

Required exports:

  • PREFIX constant
  • ProtocolData interface
  • Default class implementing ScriptTemplate

Step 3: Implement Core Methods

decode() - Parse from BitComDecoded:

static decode(bitcom: BitComDecoded): Protocol[] {
  const results: Protocol[] = []
  for (const protocol of bitcom.protocols) {
    if (protocol.protocol === PREFIX) {
      const script = Script.fromBinary(protocol.script)
      const chunks = script.chunks
      // Extract fields from chunks using Utils.toUTF8(chunk.data)
    }
  }
  return results
}

lock() - Generate locking script:

lock(): LockingScript {
  const script = new Script()
  script.writeBin(Utils.toArray(field1, 'utf8'))
  script.writeBin(Utils.toArray(field2, 'utf8'))

  const protocols: Protocol[] = [{
    protocol: PREFIX,
    script: script.toBinary(),
    pos: 0
  }]

  return new BitCom(protocols).lock()
}

Step 4: Add to mod.ts

Export the new template:

export { default as Protocol, PREFIX } from './src/template/bitcom/Protocol.js'
export type { ProtocolData, ProtocolOptions } from './src/template/bitcom/Protocol.js'

Step 5: Create Pull Request

  1. Create feature branch: git checkout -b feature/protocol-template
  2. Commit changes with descriptive message
  3. Push and create PR to b-open-io/ts-templates

Key Patterns

Chunk-Based Parsing

Always use script.chunks directly, never string splitting:

const script = Script.fromBinary(protocol.script)
const chunks = script.chunks

const field1 = Utils.toUTF8(chunks[0].data ?? [])
const field2 = Utils.toUTF8(chunks[1].data ?? [])
const signature = Array.from(chunks[2].data ?? [])

Utils Over Buffer

Use @bsv/sdk Utils for all byte manipulation:

  • Utils.toArray(string, 'utf8') - String to bytes
  • Utils.toUTF8(bytes) - Bytes to string
  • Utils.toHex(bytes) - Bytes to hex
  • Utils.toBase64(bytes) - Bytes to base64

Signature Verification

For protocols with signatures, use BSM recovery:

for (let recovery = 0; recovery < 4; recovery++) {
  try {
    const publicKey = sig.RecoverPublicKey(
      recovery,
      new BigNumber(BSM.magicHash(message))
    )
    if (BSM.verify(message, sig, publicKey) &&
        publicKey.toAddress().toString() === address) {
      return true
    }
  } catch { /* try next */ }
}

Additional Resources

Reference Files

  • references/template-anatomy.md - Detailed template structure
  • references/pr-workflow.md - Contribution workflow for ts-templates

Examples

  • examples/OpReturn.ts - Minimal template (no external deps)

More Examples

For complete production templates, see the ts-templates repository:
https://github.com/b-open-io/ts-templates/tree/master/src/template

Notable templates:

  • bitcom/Sigma.ts - Transaction-bound signatures (uses sigma-protocol)
  • bitcom/AIP.ts - Author Identity Protocol
  • bitcom/MAP.ts - Magic Attribute Protocol
  • bitcom/BAP.ts - Bitcoin Attestation Protocol
  • bitcom/B.ts - B:// file storage
  • opreturn/OpReturn.ts - Simple OP_RETURN

Installs

Installs 20
Global Rank #601 of 601

Security Audit

ath Safe
socket Critical
Alerts: 1 Score: 77
snyk Medium
EU EU-Hosted Inference API

Power your AI Agents with the best open-source models.

Drop-in OpenAI-compatible API. No data leaves Europe.

Explore Inference API

GLM

GLM 5

$1.00 / $3.20

per M tokens

Kimi

Kimi K2.5

$0.60 / $2.80

per M tokens

MiniMax

MiniMax M2.5

$0.30 / $1.20

per M tokens

Qwen

Qwen3.5 122B

$0.40 / $3.00

per M tokens

How to use this skill

1

Install create-script-template by running npx skills add b-open-io/bsv-skills --skill create-script-template in your project directory. Run the install command above in your project directory. The skill file will be downloaded from GitHub and placed in your project.

2

No configuration needed. Your AI agent (Claude Code, Cursor, Windsurf, etc.) automatically detects installed skills and uses them as context when generating code.

3

The skill enhances your agent's understanding of create-script-template, helping it follow established patterns, avoid common mistakes, and produce production-ready output.

What you get

Skills are plain-text instruction files — not executable code. They encode expert knowledge about frameworks, languages, or tools that your AI agent reads to improve its output. This means zero runtime overhead, no dependency conflicts, and full transparency: you can read and review every instruction before installing.

Compatibility

This skill works with any AI coding agent that supports the skills.sh format, including Claude Code (Anthropic), Cursor, Windsurf, Cline, Aider, and other tools that read project-level context files. Skills are framework-agnostic at the transport level — the content inside determines which language or framework it applies to.

Data sourced from the skills.sh registry and GitHub. Install counts and security audits are updated regularly.

EU Made in Europe

Chat with 100+ AI Models in one App.

Use Claude, ChatGPT, Gemini alongside with EU-Hosted Models like Deepseek, GLM-5, Kimi K2.5 and many more.

Get the App:

Customer Support