cryptoconditions

package module
v0.0.0-...-aba58e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2018 License: Unlicense Imports: 15 Imported by: 6

README

cryptoconditions

This package provides a Go (golang) implementation of the Crypto-Conditions RFC specification intended for the Interledger protocol.

All the test vectors from the RFC specs are included in the unit tests.

!! For now, the THRESHOLD-SHA-256 condition is not yet supported because of limitation from the ASN.1 library that we use. We're looking towards a solution for that. !!

Licensing

This implementation is part of the public domain. More information can be found in the UNLICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ASN1Context *asn1.Context

ASN1Context defines the ASN.1 context that is used to encode and decode objects. It explicitly requires encoding and decoding to happen in strict DER format and it also defines the CHOICE mapping for fulfillments (`fulfillment`) and conditions (`condition`).

Functions

This section is empty.

Types

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

Condition represents a crypto-condition.

func DecodeCondition

func DecodeCondition(encodedCondition []byte) (*Condition, error)

DecodeCondition decodes the DER encoding of a condition.

func NewCompoundCondition

func NewCompoundCondition(conditionType ConditionType, fingerprint []byte, cost int, subTypes ConditionTypeSet) *Condition

NewCompoundCondition constructs a new compound condition with subtypes.

func NewSimpleCondition

func NewSimpleCondition(conditionType ConditionType, fingerprint []byte, cost int) *Condition

NewSimpleCondition constructs a new simple condition.

func ParseURI

func ParseURI(uri string) (*Condition, error)

ParseURI parses a URI into a Condition.

func (Condition) Cost

func (c Condition) Cost() int

Cost returns the cost metric of a fulfillment for this condition.

func (*Condition) Encode

func (c *Condition) Encode() ([]byte, error)

Encode encodes the condition in binary format.

func (*Condition) Equals

func (c *Condition) Equals(other *Condition) bool

Equals checks if this condition equals the other.

func (Condition) Fingerprint

func (c Condition) Fingerprint() []byte

Fingerprint returns the fingerprint of this condition.

func (Condition) SubTypes

func (c Condition) SubTypes() ConditionTypeSet

SubTypes returns the condition types of the sub-conditions of this condition.

func (Condition) Type

func (c Condition) Type() ConditionType

Type returns the type of this condition.

func (*Condition) URI

func (c *Condition) URI() string

URI returns the URI for this condition.

type ConditionType

type ConditionType int

ConditionType represent one of the predefined condition types in the specification.

const (
	// PREIMAGE-SHA-256
	CTPreimageSha256 ConditionType = iota
	// PREFIX-SHA-256
	CTPrefixSha256
	// THRESHOLD-SHA-256
	CTThresholdSha256
	// RSA-SHA-256
	CTRsaSha256
	// ED25519
	CTEd25519Sha256
)

All the condition types and their corresponding type codes.

func (ConditionType) IsCompound

func (t ConditionType) IsCompound() bool

IsCompound returns true for compound condition types that have subtypes.

func (ConditionType) String

func (t ConditionType) String() string

type ConditionTypeSet

type ConditionTypeSet asn1.BitString

ConditionTypeSet represents a set of ConditionTypes. It is represented as an ASN.1 BIT STRING like defined in the specification.

func (ConditionTypeSet) AllTypes

func (c ConditionTypeSet) AllTypes() []ConditionType

func (ConditionTypeSet) Equals

func (c ConditionTypeSet) Equals(other ConditionTypeSet) bool

Equals returns true if `other` represents the same condition type set as this. False otherwise.

func (ConditionTypeSet) Has

func (c ConditionTypeSet) Has(conditionType ConditionType) bool

Has determines if the given condition type is present.

type FfEd25519Sha256

type FfEd25519Sha256 struct {
	PublicKey []byte `asn1:"tag:0"`
	Signature []byte `asn1:"tag:1"`
}

FfEd25519Sha256 implements the ED25519-SHA-256 fulfillment.

func NewEd25519Sha256

func NewEd25519Sha256(pubkey []byte, signature []byte) (*FfEd25519Sha256, error)

NewEd25519Sha256 creates a new ED25519-SHA-256 fulfillment.

func (FfEd25519Sha256) Condition

func (f FfEd25519Sha256) Condition() *Condition

func (FfEd25519Sha256) ConditionType

func (f FfEd25519Sha256) ConditionType() ConditionType

func (FfEd25519Sha256) Cost

func (f FfEd25519Sha256) Cost() int

func (FfEd25519Sha256) Ed25519PublicKey

func (f FfEd25519Sha256) Ed25519PublicKey() ed25519.PublicKey

Ed25519PublicKey returns the Ed25519 public key.

func (FfEd25519Sha256) Encode

func (f FfEd25519Sha256) Encode() ([]byte, error)

func (FfEd25519Sha256) Validate

func (f FfEd25519Sha256) Validate(condition *Condition, message []byte) error

type FfPrefixSha256

type FfPrefixSha256 struct {
	Prefix           []byte `asn1:"tag:0"`
	MaxMessageLength uint32 `asn1:"tag:1"`

	// Only have either a sub-fulfillment or a sub-condition.
	SubFulfillment Fulfillment `asn1:"tag:2,explicit,choice:fulfillment"`
	// contains filtered or unexported fields
}

FfPrefixSha256 implements the PREFIX-SHA-256 fulfillment.

func NewPrefixSha256

func NewPrefixSha256(prefix []byte, maxMessageLength uint32, subFf Fulfillment) *FfPrefixSha256

NewPrefixSha256 creates a new PREFIX-SHA-256 fulfillment.

func NewPrefixSha256Unfulfilled

func NewPrefixSha256Unfulfilled(prefix []byte, maxMessageLength uint32, subCondition *Condition) *FfPrefixSha256

PrefixSha256Unfulfilled creates an unfulfilled PREFIX-SHA-256 fulfillment.

func (FfPrefixSha256) Condition

func (f FfPrefixSha256) Condition() *Condition

func (FfPrefixSha256) ConditionType

func (f FfPrefixSha256) ConditionType() ConditionType

func (FfPrefixSha256) Cost

func (f FfPrefixSha256) Cost() int

func (FfPrefixSha256) Encode

func (f FfPrefixSha256) Encode() ([]byte, error)

func (FfPrefixSha256) IsFulfilled

func (f FfPrefixSha256) IsFulfilled() bool

IsFulfilled returns true if this fulfillment is fulfilled, i.e. when it contains a sub-fulfillment. If false, it only contains a sub-condition.

func (FfPrefixSha256) SubCondition

func (f FfPrefixSha256) SubCondition() *Condition

SubCondition returns the sub-condition of this fulfillment.

func (FfPrefixSha256) Validate

func (f FfPrefixSha256) Validate(condition *Condition, message []byte) error

type FfPreimageSha256

type FfPreimageSha256 struct {
	Preimage []byte `asn1:"tag:0"`
}

FfPreimageSha256 implements the PREIMAGE-SHA-256 fulfillment.

func NewPreimageSha256

func NewPreimageSha256(preimage []byte) *FfPreimageSha256

NewPreimageSha256 creates a new PREIMAGE-SHA-256 fulfillment.

func (FfPreimageSha256) Condition

func (f FfPreimageSha256) Condition() *Condition

func (FfPreimageSha256) ConditionType

func (f FfPreimageSha256) ConditionType() ConditionType

func (FfPreimageSha256) Cost

func (f FfPreimageSha256) Cost() int

func (FfPreimageSha256) Encode

func (f FfPreimageSha256) Encode() ([]byte, error)

func (FfPreimageSha256) Validate

func (f FfPreimageSha256) Validate(condition *Condition, message []byte) error

type FfRsaSha256

type FfRsaSha256 struct {
	Modulus   []byte `asn1:"tag:0"`
	Signature []byte `asn1:"tag:1"`
}

NewFfRsaSha256 implements the RSA-SHA-256 fulfillment.

func NewRsaSha256

func NewRsaSha256(modulus []byte, signature []byte) (*FfRsaSha256, error)

RsaSha256 creates a new RSA-SHA-256 fulfillment.

func (FfRsaSha256) Condition

func (f FfRsaSha256) Condition() *Condition

func (FfRsaSha256) ConditionType

func (f FfRsaSha256) ConditionType() ConditionType

func (FfRsaSha256) Cost

func (f FfRsaSha256) Cost() int

func (FfRsaSha256) Encode

func (f FfRsaSha256) Encode() ([]byte, error)

func (FfRsaSha256) PublicKey

func (f FfRsaSha256) PublicKey() *rsa.PublicKey

PublicKey returns the RSA public key.

func (FfRsaSha256) Validate

func (f FfRsaSha256) Validate(condition *Condition, message []byte) error

type FfThresholdSha256

type FfThresholdSha256 struct {
	Threshold uint16 `asn1:"-"`

	SubFulfillments []Fulfillment `asn1:"tag:0,explicit,set,choice:fulfillment"`
	SubConditions   []*Condition  `asn1:"tag:1,explicit,set,choice:condition"`
}

FfThresholdSha256 implements the THRESHOLD-SHA-256 fulfillment. This type of fulfillment is currently not supported.

func NewThresholdSha256

func NewThresholdSha256(threshold uint16, subFulfillments []Fulfillment, subConditions []*Condition) *FfThresholdSha256

NewThresholdSha256 creates a new THRESHOLD-SHA-256 fulfillment. This type of fulfillment is currently not supported.

func (FfThresholdSha256) Condition

func (f FfThresholdSha256) Condition() *Condition

func (FfThresholdSha256) ConditionType

func (f FfThresholdSha256) ConditionType() ConditionType

func (FfThresholdSha256) Cost

func (f FfThresholdSha256) Cost() int

func (FfThresholdSha256) Encode

func (f FfThresholdSha256) Encode() ([]byte, error)

func (FfThresholdSha256) Validate

func (f FfThresholdSha256) Validate(condition *Condition, message []byte) error

type Fulfillment

type Fulfillment interface {
	// ConditionType returns the type of condition this fulfillment fulfills.
	ConditionType() ConditionType

	// Condition generates the condition that this fulfillment fulfills.
	Condition() *Condition

	// Cost calculates the cost metric of this fulfillment.
	Cost() int

	// Encode encodes the fulfillment into binary format.
	Encode() ([]byte, error)

	// Validate checks whether this fulfillment correctly validates the given
	// condition using the specified message.
	// It returns nil if it does, an error indicating the problem otherwise.
	Validate(*Condition, []byte) error
	// contains filtered or unexported methods
}

Fulfillment defines the fulfillment interface.

func DecodeFulfillment

func DecodeFulfillment(encodedFulfillment []byte) (Fulfillment, error)

DecodeFulfillment decodes the DER encoding of a fulfillment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL