Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
792 changes: 788 additions & 4 deletions bursa.go

Large diffs are not rendered by default.

527 changes: 527 additions & 0 deletions bursa_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/bursa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {
rootCmd.AddCommand(
walletCommand(),
apiCommand(),
scriptCommand(),
)

if err := rootCmd.Execute(); err != nil {
Expand Down
177 changes: 177 additions & 0 deletions cmd/bursa/script.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"github.com/blinklabs-io/bursa/internal/cli"
"github.com/spf13/cobra"
)

func scriptCommand() *cobra.Command {
scriptCommand := cobra.Command{
Use: "script",
Short: "Script commands for multi-signature operations",
}

scriptCommand.AddCommand(
scriptCreateCommand(),
scriptValidateCommand(),
scriptAddressCommand(),
)
return &scriptCommand
}

func scriptCreateCommand() *cobra.Command {
var (
required int
keyHashes []string
output string
network string
all bool
any bool
timelockBefore uint64
timelockAfter uint64
)

scriptCreateCommand := cobra.Command{
Use: "create",
Short: "Creates a new multi-signature script",
Long: `Creates a new multi-signature script with the specified parameters.

Examples:
# Create a 2-of-3 multi-sig script
bursa script create --required 2 --key-hashes abcdef1234567890abcdef1234567890abcdef12,abcdef1234567890abcdef1234567890abcdef13,abcdef1234567890abcdef1234567890abcdef14

# Create an all-signers-required script
bursa script create --all --key-hashes abcdef1234567890abcdef1234567890abcdef12,abcdef1234567890abcdef1234567890abcdef13

# Create an any-signer script
bursa script create --any --key-hashes abcdef1234567890abcdef1234567890abcdef12,abcdef1234567890abcdef1234567890abcdef13,abcdef1234567890abcdef1234567890abcdef14

# Create a timelocked script (valid after slot 1000000)
bursa script create --required 2 --key-hashes abcdef1234567890abcdef1234567890abcdef12,abcdef1234567890abcdef1234567890abcdef13 --timelock-after 1000000`,
Run: func(cmd *cobra.Command, args []string) {
cli.RunScriptCreate(
required,
keyHashes,
output,
network,
all,
any,
timelockBefore,
timelockAfter,
)
},
}

scriptCreateCommand.Flags().
IntVar(&required, "required", 0, "Number of required signatures (for N-of-M scripts)")
scriptCreateCommand.Flags().
StringSliceVar(&keyHashes, "key-hashes", nil, "Comma-separated list of key hashes (hex encoded)")
scriptCreateCommand.Flags().
StringVar(&output, "output", "", "Output file path (optional)")
scriptCreateCommand.Flags().
StringVar(&network, "network", "mainnet", "Network name (mainnet, testnet, etc.)")
scriptCreateCommand.Flags().
BoolVar(&all, "all", false, "Create all-signers-required script")
scriptCreateCommand.Flags().
BoolVar(&any, "any", false, "Create any-signer script")
scriptCreateCommand.Flags().
Uint64Var(&timelockBefore, "timelock-before", 0, "Make script valid only before this slot")
scriptCreateCommand.Flags().
Uint64Var(&timelockAfter, "timelock-after", 0, "Make script valid only after this slot")

return &scriptCreateCommand
}

func scriptValidateCommand() *cobra.Command {
var (
scriptFile string
signatures []string
slot uint64
structuralOnly bool
)

scriptValidateCommand := cobra.Command{
Use: "validate",
Short: "Validates a script against signatures and slot",
Long: `Validates whether a script is satisfied given a set of signatures and current slot.

By default, performs format validation requiring signatures for signature scripts.
Use --structural-only for basic structure validation without signatures.

Examples:
# Validate a script with signatures
bursa script validate --script script.json --signatures sig1.hex,sig2.hex --slot 123456789

# Validate a timelocked script
bursa script validate --script script.json --slot 123456789 --structural-only

# Perform structural validation only
bursa script validate --script script.json --structural-only`,
Run: func(cmd *cobra.Command, args []string) {
cli.RunScriptValidate(scriptFile, signatures, slot, structuralOnly)
},
}

scriptValidateCommand.Flags().
StringVar(&scriptFile, "script", "", "Path to script file (required)")
scriptValidateCommand.Flags().
StringSliceVar(&signatures, "signatures", nil, "Comma-separated list of signatures (hex encoded)")
scriptValidateCommand.Flags().
Uint64Var(&slot, "slot", 0, "Current slot number for timelock validation")
scriptValidateCommand.Flags().
BoolVar(&structuralOnly, "structural-only", false, "Perform structural validation only (no signature format checking)")

if err := scriptValidateCommand.MarkFlagRequired("script"); err != nil {
panic(err)
}

return &scriptValidateCommand
}

func scriptAddressCommand() *cobra.Command {
var (
scriptFile string
network string
)

scriptAddressCommand := cobra.Command{
Use: "address",
Short: "Generates an address from a script",
Long: `Generates a Cardano address from a multi-signature script.

Examples:
# Generate mainnet address from script
bursa script address --script script.json --network mainnet

# Generate testnet address from script
bursa script address --script script.json --network testnet`,
Run: func(cmd *cobra.Command, args []string) {
cli.RunScriptAddress(scriptFile, network)
},
}

scriptAddressCommand.Flags().
StringVar(&scriptFile, "script", "", "Path to script file (required)")
scriptAddressCommand.Flags().
StringVar(&network, "network", "mainnet", "Network name (mainnet, testnet, etc.)")

if err := scriptAddressCommand.MarkFlagRequired("script"); err != nil {
panic(err)
}

return &scriptAddressCommand
}
Loading