skills/create-script-template/SKILL.md
This skill should be used when the user asks to "create a script template", "add a new template to ts-templates", "create a BitCom template", "build an OP_RETURN template", or mentions creating templates for protocols like SIGMA, AIP, MAP, BAP, B. Guides creation of @bsv/sdk ScriptTemplate implementations.
npx skillsauth add b-open-io/bsv-skills create-script-templateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create script templates for the b-open-io/ts-templates repository following established patterns.
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 { /* ... */ }
}
Gather protocol specifications:
Location: src/template/bitcom/ProtocolName.ts
Required exports:
PREFIX constantProtocolData interfaceScriptTemplatedecode() - 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()
}
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'
git checkout -b feature/protocol-templateAlways 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 ?? [])
Use @bsv/sdk Utils for all byte manipulation:
Utils.toArray(string, 'utf8') - String to bytesUtils.toUTF8(bytes) - Bytes to stringUtils.toHex(bytes) - Bytes to hexUtils.toBase64(bytes) - Bytes to base64For 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 */ }
}
references/template-anatomy.md - Detailed template structurereferences/pr-workflow.md - Contribution workflow for ts-templatesexamples/OpReturn.ts - Minimal template (no external deps)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 Protocolbitcom/MAP.ts - Magic Attribute Protocolbitcom/BAP.ts - Bitcoin Attestation Protocolbitcom/B.ts - B:// file storageopreturn/OpReturn.ts - Simple OP_RETURNdevelopment
This skill should be used when the user asks to integrate "Yours Wallet", "connect a BSV wallet", use "BRC-100", "pay with BSV wallet", add "wallet checkout in a web app", use "yours-wallet-provider", build a "pay with Yours Wallet" button, access "window.CWI", or connect a React app to a BRC-100 wallet.
development
This skill should be used when the user asks to "send BSV", "transfer satoshis", "create payment transaction", "send from WIF", "P2PKH transaction", or needs to build, sign, and broadcast P2PKH transactions from a WIF private key using @bsv/sdk.
development
This skill should be used when the user asks to "encrypt message with BSV key", "decrypt with private key", "ECDH encryption", "AES-256-GCM BSV", "EncryptedMessage", "BRC-2 encryption", or needs to encrypt/decrypt data using BSV keys and @bsv/sdk.
tools
This skill should be used when the user asks to "implement BRC-100 wallet", "use wallet-toolbox", "TypeScript BSV wallet", "BRC-100 implementation", "desktop wallet", "Electron wallet", "browser wallet", "IndexedDB wallet storage", "wallet actions", "wallet baskets", "UTXO management", "createAction", "listOutputs", "wallet certificates", "WalletClient", "noSend", "BEEF payment", "pay-beef", "send BEEF", "Transaction.fromBEEF", "toHexBEEF", or needs guidance on building conforming wallets using @bsv/wallet-toolbox or connecting to a user's BRC-100 wallet via WalletClient.