Skip to content
Merged
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
2 changes: 2 additions & 0 deletions confidential/confidential.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cgo

package confidential

import (
Expand Down
199 changes: 199 additions & 0 deletions confidential/confidential_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
//go:build !cgo

package confidential

import (
"errors"

"github.com/vulpemventures/go-elements/transaction"
)

var errNoCGO = errors.New("confidential transactions require CGO")

const (
maxSurjectionTargets = 3
maxScriptSize = 10000
)

var (
Zero = make([]byte, 32)
)

// UnblindOutputResult is the type returned by the functions that unblind tx
// outs. It contains the unblinded asset and value and also the respective
// blinding factors.
type UnblindOutputResult struct {
Value uint64
Asset []byte
ValueBlindingFactor []byte
AssetBlindingFactor []byte
}

// UnblindIssuanceResult is the type returned by the functions that unblind tx
// issuances. It contains the unblinded asset and token issuances.
type UnblindIssuanceResult struct {
Asset *UnblindOutputResult
Token *UnblindOutputResult
}

// FinalValueBlindingFactorArgs is the type used to pass arguments to the
// FinalValueBlindingFactor function.
type FinalValueBlindingFactorArgs struct {
InValues []uint64
OutValues []uint64
InGenerators [][]byte
OutGenerators [][]byte
InFactors [][]byte
OutFactors [][]byte
}

// RangeProofArgs is the type used to pass arguments to the RangeProof function.
type RangeProofArgs struct {
Value uint64
Nonce [32]byte
Asset []byte
AssetBlindingFactor []byte
ValueBlindFactor [32]byte
ValueCommit []byte
ScriptPubkey []byte
Exp int
MinBits int
}

// SurjectionProofArgs is the type used to pass arguments to the SurjectionProof function.
type SurjectionProofArgs struct {
OutputAsset []byte
OutputAssetBlindingFactor []byte
InputAssets [][]byte
InputAssetBlindingFactors [][]byte
Seed []byte
NumberOfTargets int
}

// VerifySurjectionProofArgs is the type used to pass arguments to the VerifySurjectionProof function.
type VerifySurjectionProofArgs struct {
InputAssets [][]byte
InputAssetBlindingFactors [][]byte
OutputAsset []byte
OutputAssetBlindingFactor []byte
Proof []byte
}

// NonceHash method generates hashed secret based on ecdh.
func NonceHash(pubKey, privKey []byte) ([32]byte, error) {
return [32]byte{}, errNoCGO
}

// UnblindOutputWithKey method unblinds a confidential transaction output with
// the given blinding private key.
func UnblindOutputWithKey(
out *transaction.TxOutput, blindKey []byte,
) (*UnblindOutputResult, error) {
return nil, errNoCGO
}

// UnblindOutputWithNonce method unblinds a confidential transaction output with
// the given nonce.
func UnblindOutputWithNonce(
out *transaction.TxOutput, nonce []byte,
) (*UnblindOutputResult, error) {
return nil, errNoCGO
}

// UnblindIssuance method unblinds a confidential transaction issuance with
// the given blinding private keys.
func UnblindIssuance(
in *transaction.TxInput, blindKeys [][]byte,
) (*UnblindIssuanceResult, error) {
return nil, errNoCGO
}

// FinalValueBlindingFactor method calculates the final value blinding factor.
func FinalValueBlindingFactor(
args FinalValueBlindingFactorArgs,
) ([32]byte, error) {
return [32]byte{}, errNoCGO
}

// AssetCommitment method creates an asset commitment.
func AssetCommitment(asset, factor []byte) ([]byte, error) {
return nil, errNoCGO
}

// ValueCommitment method creates a value commitment.
func ValueCommitment(value uint64, generator, factor []byte) ([]byte, error) {
return nil, errNoCGO
}

// RangeProof method creates a range proof.
func RangeProof(args RangeProofArgs) ([]byte, error) {
return nil, errNoCGO
}

// VerifyRangeProof method verifies a range proof.
func VerifyRangeProof(valueCommitment, assetCommitment, script, proof []byte) bool {
return false
}

// SurjectionProof method creates a surjection proof.
func SurjectionProof(args SurjectionProofArgs) ([]byte, bool) {
return nil, false
}

// VerifySurjectionProof method verifies a surjection proof.
func VerifySurjectionProof(args VerifySurjectionProofArgs) bool {
return false
}

// CalculateScalarOffset calculates the scalar offset for a transaction.
// This is a no-op implementation when CGO is disabled.
func CalculateScalarOffset(
amount uint64, assetBlinder, valueBlinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// SubtractScalars subtracts two scalars.
// This is a no-op implementation when CGO is disabled.
func SubtractScalars(a []byte, b []byte) ([]byte, error) {
return nil, errNoCGO
}

// ComputeAndAddToScalarOffset computes and adds to the scalar offset.
// This is a no-op implementation when CGO is disabled.
func ComputeAndAddToScalarOffset(
scalar []byte, value uint64, assetBlinder, valueBlinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// CreateBlindValueProof creates a blind value proof.
// This is a no-op implementation when CGO is disabled.
func CreateBlindValueProof(
rng func() ([]byte, error),
valueBlinder []byte, amount uint64, valueCommitment, assetCommitment []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// CreateBlindAssetProof creates a blind asset proof.
// This is a no-op implementation when CGO is disabled.
func CreateBlindAssetProof(
asset, assetCommitment, assetBlinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// VerifyBlindValueProof verifies a blind value proof.
// This is a no-op implementation when CGO is disabled.
func VerifyBlindValueProof(
value uint64, valueCommitment, assetCommitment, proof []byte,
) bool {
return false
}

// VerifyBlindAssetProof verifies a blind asset proof.
// This is a no-op implementation when CGO is disabled.
func VerifyBlindAssetProof(asset, assetCommitment, proof []byte) bool {
return false
}
2 changes: 2 additions & 0 deletions confidential/zkp_generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cgo

package confidential

import (
Expand Down
101 changes: 101 additions & 0 deletions confidential/zkp_generator_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//go:build !cgo

package confidential

import (
"github.com/vulpemventures/go-elements/psetv2"
"github.com/vulpemventures/go-elements/transaction"
)

// zkpGenerator is the type that provides methods to generate zero-knowledge proofs.
type zkpGenerator struct {
masterBlindingKey interface{}
inBlindingKeys [][]byte
rng func() ([]byte, error)
ownedInputs map[uint32]psetv2.OwnedInput
}

// NewZKPGeneratorFromMasterBlindingKey creates a new zkpGenerator from a master blinding key.
func NewZKPGeneratorFromMasterBlindingKey(
masterBlindingKey []byte, opts interface{},
) (*zkpGenerator, error) {
return nil, errNoCGO
}

// NewZKPGeneratorFromBlindingKeys creates a new zkpGenerator from blinding keys.
func NewZKPGeneratorFromBlindingKeys(
inBlindingKeys [][]byte, opts interface{},
) *zkpGenerator {
return &zkpGenerator{}
}

// ComputeAndAddToScalarOffset computes and adds to the scalar offset.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) ComputeAndAddToScalarOffset(
scalar []byte, value uint64, assetBlinder, valueBlinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// SubtractScalars subtracts two scalars.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) SubtractScalars(a, b []byte) ([]byte, error) {
return nil, errNoCGO
}

// LastValueCommitment creates a value commitment.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) LastValueCommitment(
value uint64, asset, blinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// LastBlindValueProof creates a blind value proof.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) LastBlindValueProof(
value uint64, valueCommitment, assetCommitment, blinder []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// LastValueRangeProof creates a range proof.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) LastValueRangeProof(
value uint64, asset, assetBlinder, valueCommitment, valueBlinder,
scriptPubkey, nonce []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// UnblindInputs unblinds inputs.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) UnblindInputs(
p *psetv2.Pset, inputIndexes []uint32,
) ([]psetv2.OwnedInput, error) {
return nil, errNoCGO
}

// BlindIssuances blinds issuances.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) BlindIssuances(
p *psetv2.Pset, blindingKeysByIndex map[uint32][]byte,
) ([]psetv2.InputIssuanceBlindingArgs, error) {
return nil, errNoCGO
}

// BlindOutputs blinds outputs.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) BlindOutputs(
p *psetv2.Pset, outputIndexes []uint32,
) ([]psetv2.OutputBlindingArgs, error) {
return nil, errNoCGO
}

// unblindOutput unblinds an output.
// This is a no-op implementation when CGO is disabled.
func (g *zkpGenerator) unblindOutput(
out *transaction.TxOutput,
) (*psetv2.OwnedInput, error) {
return nil, errNoCGO
}
2 changes: 2 additions & 0 deletions confidential/zkp_validator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cgo

package confidential

type zkpValidator struct{}
Expand Down
44 changes: 44 additions & 0 deletions confidential/zkp_validator_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//go:build !cgo

package confidential

// zkpValidator is the type that provides methods to validate zero-knowledge proofs.
type zkpValidator struct{}

// NewZKPValidator creates a new zkpValidator.
func NewZKPValidator() *zkpValidator {
return &zkpValidator{}
}

// VerifyValueRangeProof verifies a range proof.
// This is a no-op implementation when CGO is disabled.
func (v *zkpValidator) VerifyValueRangeProof(
valueCommitment, assetCommitment, script, proof []byte,
) bool {
return false
}

// VerifyAssetSurjectionProof verifies a surjection proof.
// This is a no-op implementation when CGO is disabled.
func (v *zkpValidator) VerifyAssetSurjectionProof(
inAssets, inAssetBlinders [][]byte,
outAsset, outAssetBlinder, proof []byte,
) bool {
return false
}

// VerifyBlindValueProof verifies a blind value proof.
// This is a no-op implementation when CGO is disabled.
func (v *zkpValidator) VerifyBlindValueProof(
value uint64, valueCommitment, assetCommitment, proof []byte,
) bool {
return false
}

// VerifyBlindAssetProof verifies a blind asset proof.
// This is a no-op implementation when CGO is disabled.
func (v *zkpValidator) VerifyBlindAssetProof(
asset, assetCommitment, proof []byte,
) bool {
return false
}
2 changes: 2 additions & 0 deletions pegincontract/contract.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build cgo

package pegincontract

import (
Expand Down
24 changes: 24 additions & 0 deletions pegincontract/contract_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !cgo

package pegincontract

import (
"errors"
)

var errNoCGO = errors.New("pegin contract requires CGO")

// Calculate calculates the pegin contract.
// This is a no-op implementation when CGO is disabled.
func Calculate(
federationScript []byte,
scriptPubKey []byte,
) ([]byte, error) {
return nil, errNoCGO
}

// IsLiquidV1 checks if the script is a Liquid V1 script.
// This is a no-op implementation when CGO is disabled.
func IsLiquidV1(script []byte) (bool, error) {
return false, errNoCGO
}