codesdk

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KinMintDecimals = 5
	QuarksPerKin    = 100000
)

Variables

View Source
var (
	ErrInvalidCurrency = errors.New("currency is invalid")
)
View Source
var (
	KinTokenMint, _ = NewPublicKeyFromString("kinXdEcpDQeHPEuQnqmUgtYykqKGVFq6CeVX5iAHJq6")
)

Functions

func IsValidCurrency

func IsValidCurrency(currency string) bool

Types

type Client

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

func NewWebClient

func NewWebClient() *Client

func (*Client) CreatePaymentRequest

func (c *Client) CreatePaymentRequest(
	ctx context.Context,
	intent *PaymentRequestIntent,
	opts ...PaymentRequestOption,
) (*CreatePaymentRequestResponse, error)

CreatePaymentRequest creates a payment request intent. The response object can be used directly as the return value for the Code SDK on the browser.

func (*Client) GetIntentStatus

func (c *Client) GetIntentStatus(ctx context.Context, intentId string) (*GetIntentStateResponse, error)

GetIntentStatus returns the state of the intent

type CodePayload

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

CodePayload is the payload format for scan codes.

func NewCodePayload

func NewCodePayload(kind CodePayloadType, currency CurrencyCode, amount float64, nonce IdempotencyKey) (*CodePayload, error)

type CodePayloadType

type CodePayloadType uint8
const (
	CodePayloadCash CodePayloadType = iota
	CodePayloadGiftCard
	CodePayloadPaymentRequest
)

type CreatePaymentRequestResponse

type CreatePaymentRequestResponse struct {
	IntentId     string `json:"id"`
	ClientSecret string `json:"clientSecret"`
}

type CurrencyCode

type CurrencyCode string
const (
	KIN CurrencyCode = "kin"
	AED CurrencyCode = "aed"
	AFN CurrencyCode = "afn"
	ALL CurrencyCode = "all"
	AMD CurrencyCode = "amd"
	ANG CurrencyCode = "ang"
	AOA CurrencyCode = "aoa"
	ARS CurrencyCode = "ars"
	AUD CurrencyCode = "aud"
	AWG CurrencyCode = "awg"
	AZN CurrencyCode = "azn"
	BAM CurrencyCode = "bam"
	BBD CurrencyCode = "bbd"
	BDT CurrencyCode = "bdt"
	BGN CurrencyCode = "bgn"
	BHD CurrencyCode = "bhd"
	BIF CurrencyCode = "bif"
	BMD CurrencyCode = "bmd"
	BND CurrencyCode = "bnd"
	BOB CurrencyCode = "bob"
	BRL CurrencyCode = "brl"
	BSD CurrencyCode = "bsd"
	BTN CurrencyCode = "btn"
	BWP CurrencyCode = "bwp"
	BYN CurrencyCode = "byn"
	BZD CurrencyCode = "bzd"
	CAD CurrencyCode = "cad"
	CDF CurrencyCode = "cdf"
	CHF CurrencyCode = "chf"
	CLP CurrencyCode = "clp"
	CNY CurrencyCode = "cny"
	COP CurrencyCode = "cop"
	CRC CurrencyCode = "crc"
	CUP CurrencyCode = "cup"
	CVE CurrencyCode = "cve"
	CZK CurrencyCode = "czk"
	DJF CurrencyCode = "djf"
	DKK CurrencyCode = "dkk"
	DOP CurrencyCode = "dop"
	DZD CurrencyCode = "dzd"
	EGP CurrencyCode = "egp"
	ERN CurrencyCode = "ern"
	ETB CurrencyCode = "etb"
	EUR CurrencyCode = "eur"
	FJD CurrencyCode = "fjd"
	FKP CurrencyCode = "fkp"
	GBP CurrencyCode = "gbp"
	GEL CurrencyCode = "gel"
	GHS CurrencyCode = "ghs"
	GIP CurrencyCode = "gip"
	GMD CurrencyCode = "gmd"
	GNF CurrencyCode = "gnf"
	GTQ CurrencyCode = "gtq"
	GYD CurrencyCode = "gyd"
	HKD CurrencyCode = "hkd"
	HNL CurrencyCode = "hnl"
	HRK CurrencyCode = "hrk"
	HTG CurrencyCode = "htg"
	HUF CurrencyCode = "huf"
	IDR CurrencyCode = "idr"
	ILS CurrencyCode = "ils"
	INR CurrencyCode = "inr"
	IQD CurrencyCode = "iqd"
	IRR CurrencyCode = "irr"
	ISK CurrencyCode = "isk"
	JMD CurrencyCode = "jmd"
	JOD CurrencyCode = "jod"
	JPY CurrencyCode = "jpy"
	KES CurrencyCode = "kes"
	KGS CurrencyCode = "kgs"
	KHR CurrencyCode = "khr"
	KMF CurrencyCode = "kmf"
	KPW CurrencyCode = "kpw"
	KRW CurrencyCode = "krw"
	KWD CurrencyCode = "kwd"
	KYD CurrencyCode = "kyd"
	KZT CurrencyCode = "kzt"
	LAK CurrencyCode = "lak"
	LBP CurrencyCode = "lbp"
	LKR CurrencyCode = "lkr"
	LRD CurrencyCode = "lrd"
	LYD CurrencyCode = "lyd"
	MAD CurrencyCode = "mad"
	MDL CurrencyCode = "mdl"
	MGA CurrencyCode = "mga"
	MKD CurrencyCode = "mkd"
	MMK CurrencyCode = "mmk"
	MNT CurrencyCode = "mnt"
	MOP CurrencyCode = "mop"
	MRU CurrencyCode = "mru"
	MUR CurrencyCode = "mur"
	MVR CurrencyCode = "mvr"
	MWK CurrencyCode = "mwk"
	MXN CurrencyCode = "mxn"
	MYR CurrencyCode = "myr"
	MZN CurrencyCode = "mzn"
	NAD CurrencyCode = "nad"
	NGN CurrencyCode = "ngn"
	NIO CurrencyCode = "nio"
	NOK CurrencyCode = "nok"
	NPR CurrencyCode = "npr"
	NZD CurrencyCode = "nzd"
	OMR CurrencyCode = "omr"
	PAB CurrencyCode = "pab"
	PEN CurrencyCode = "pen"
	PGK CurrencyCode = "pgk"
	PHP CurrencyCode = "php"
	PKR CurrencyCode = "pkr"
	PLN CurrencyCode = "pln"
	PYG CurrencyCode = "pyg"
	QAR CurrencyCode = "qar"
	RON CurrencyCode = "ron"
	RSD CurrencyCode = "rsd"
	RUB CurrencyCode = "rub"
	RWF CurrencyCode = "rwf"
	SAR CurrencyCode = "sar"
	SBD CurrencyCode = "sbd"
	SCR CurrencyCode = "scr"
	SDG CurrencyCode = "sdg"
	SEK CurrencyCode = "sek"
	SGD CurrencyCode = "sgd"
	SHP CurrencyCode = "shp"
	SLL CurrencyCode = "sll"
	SOS CurrencyCode = "sos"
	SRD CurrencyCode = "srd"
	SSP CurrencyCode = "ssp"
	STN CurrencyCode = "stn"
	SYP CurrencyCode = "syp"
	SZL CurrencyCode = "szl"
	THB CurrencyCode = "thb"
	TJS CurrencyCode = "tjs"
	TMT CurrencyCode = "tmt"
	TND CurrencyCode = "tnd"
	TOP CurrencyCode = "top"
	TRY CurrencyCode = "try"
	TTD CurrencyCode = "ttd"
	TWD CurrencyCode = "twd"
	TZS CurrencyCode = "tzs"
	UAH CurrencyCode = "uah"
	UGX CurrencyCode = "ugx"
	USD CurrencyCode = "usd"
	UYU CurrencyCode = "uyu"
	UZS CurrencyCode = "uzs"
	VES CurrencyCode = "ves"
	VND CurrencyCode = "vnd"
	VUV CurrencyCode = "vuv"
	WST CurrencyCode = "wst"
	XAF CurrencyCode = "xaf"
	XCD CurrencyCode = "xcd"
	XOF CurrencyCode = "xof"
	XPF CurrencyCode = "xpf"
	YER CurrencyCode = "yer"
	ZAR CurrencyCode = "zar"
	ZMW CurrencyCode = "zmw"
)

type GetIntentStateResponse

type GetIntentStateResponse struct {
	Status IntentState `json:"status"`
}

type IdempotencyKey

type IdempotencyKey [codePayloadNonceSize]byte

Idempotency key is a globally unique value for guaranteeing an action is executed once. Along with other payment details, it is used to derive a consistent rendezvous key and intent ID.

func GenerateIdempotencyKey

func GenerateIdempotencyKey() IdempotencyKey

func NewIdempotencyKeyFromClientSecret

func NewIdempotencyKeyFromClientSecret(data string) (IdempotencyKey, error)

func NewIdempotencyKeyFromSeed

func NewIdempotencyKeyFromSeed(seed string) IdempotencyKey

func (IdempotencyKey) String

func (k IdempotencyKey) String() string

type IntentOption

type IntentOption func(*optionalIntentParameters)

func WithIdempotencyKey

func WithIdempotencyKey(idempotencyKey IdempotencyKey) IntentOption

type IntentState

type IntentState string

The state of an intent

const (
	// The intent doesn't exist
	IntentStateUnknown IntentState = "unknown"
	// The intent exists, but the user hasn't submitted a payment
	IntentStatePending IntentState = "pending"
	// The user has submitted a payment. Fulfillment on the blockchain is either
	// in progress, or completed, by the Code sequencer.
	IntentStateConfirmed IntentState = "confirmed"
)

type KeyPair

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

func GenerateKeyPair

func GenerateKeyPair() (*KeyPair, error)

func GenerateRendezvousKey

func GenerateRendezvousKey(p *CodePayload) (*KeyPair, error)

func NewKeyPairFromRawValue

func NewKeyPairFromRawValue(rawValue ed25519.PrivateKey) (*KeyPair, error)

func NewKeyPairFromSeed

func NewKeyPairFromSeed(seed []byte) (*KeyPair, error)

func (*KeyPair) GetPrivateKey

func (k *KeyPair) GetPrivateKey() *PrivateKey

func (*KeyPair) GetPublicKey

func (k *KeyPair) GetPublicKey() *PublicKey

func (*KeyPair) Sign

func (k *KeyPair) Sign(message []byte) []byte

func (*KeyPair) Verify

func (k *KeyPair) Verify(message, signature []byte) bool

type PaymentRequestIntent

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

PaymentRequestIntent is an intent to request a payment be made to a destination for a specifc amount. For fiat values, exchange rates are computed dynamically at time of payment.

func NewPaymentRequestIntent

func NewPaymentRequestIntent(
	currency CurrencyCode,
	amount float64,
	destination string,
	opts ...IntentOption,
) (*PaymentRequestIntent, error)

func (*PaymentRequestIntent) GetClientSecret

func (p *PaymentRequestIntent) GetClientSecret() string

GetClientSecret returns a secret value required by the Code SDK at the browser to reconstruct the intent. Your server should never share this value until the intent is successfully created against Code server.

func (*PaymentRequestIntent) GetIntentId

func (p *PaymentRequestIntent) GetIntentId() string

GetIntentId is the unique ID for the intent. It is the public key of the rendezvous key pair.

func (*PaymentRequestIntent) GetRendezvousKey

func (p *PaymentRequestIntent) GetRendezvousKey() *KeyPair

GetRendezvousKey returns a unique key pair for the scan code payload for the intent, which is used during the scanning process to establish a secure communication channel anonymously to coordinate a flow.

type PaymentRequestOption

type PaymentRequestOption func(*optionalPaymentRequestParameters)

func WithWebhookUrl

func WithWebhookUrl(webhookUrl string) PaymentRequestOption

type PrivateKey

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

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(value []byte) (*PrivateKey, error)

func NewPrivateKeyFromString

func NewPrivateKeyFromString(value string) (*PrivateKey, error)

func (*PrivateKey) GetPublicKey

func (k *PrivateKey) GetPublicKey() *PublicKey

func (*PrivateKey) Sign

func (k *PrivateKey) Sign(message []byte) []byte

func (*PrivateKey) ToBase58

func (k *PrivateKey) ToBase58() string

func (*PrivateKey) ToBytes

func (k *PrivateKey) ToBytes() ed25519.PrivateKey

type PublicKey

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

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(value []byte) (*PublicKey, error)

func NewPublicKeyFromString

func NewPublicKeyFromString(value string) (*PublicKey, error)

func (*PublicKey) ToBase58

func (k *PublicKey) ToBase58() string

func (*PublicKey) ToBytes

func (k *PublicKey) ToBytes() ed25519.PublicKey

Jump to

Keyboard shortcuts

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