settlement

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MPL-2.0 Imports: 21 Imported by: 0

README

Table of Contents

Creating new local vault instance

Vault is an on-device secure key-value store.

If you have trouble installing from the README, you can also (1) Download from https://www.vaultproject.io/downloads (2) make download-vault and install using 4096 rather than ed25519

# add vault address into profile or similar for your shell
echo "export VAULT_ADDR=http://127.0.0.1:8200" >> ~/.profile

# set in local shell
export VAULT_ADDR=http://127.0.0.1:8200

# start vault server
./vault server -config=config.hcl

# initialize
./bat-go vault init --key-shares 1 --key-threshold 1 PATH_TO_GPG_PUB_KEY_FILE

# unseal vault
gpg -d ./share-0.gpg | ./bat-go vault unseal
# -> prompt for password

Bringing up vault

On the offline computer, in one window run:

./vault server -config=config.hcl

In another run:

gpg -d ./share-0.gpg | ./bat-go vault unseal

Creating a vault config

The config.example.yaml should be copied wherever it is easiest to point to. Just pass in the path while running a command that interacts with vault (import-key, sign-settlement) etc. Be sure to change the values of the wallets to suit your setup if required.

The values name should be unique, as we use the label online (e.g. creating a wallet with the label name).

As of May 2021, the following keys are accepted:

wallets:
  uphold-contribution: 'prod-wallet-contributions-YYYY-MM'
  uphold-referral: 'prod-wallet-referrals-YYYY-MM'
  gemini-contribution: 'prod-wallet-contributions-YYYY-MM'
  gemini-referral: 'prod-wallet-referrals-YYYY-MM'

Importing keys

the following line imports the keys from the following environment variables:

ED25519_PRIVATE_KEY= \
ED25519_PUBLIC_KEY= \
UPHOLD_PROVIDER_ID= \
GEMINI_CLIENT_ID= \
GEMINI_CLIENT_KEY= \
GEMINI_CLIENT_SECRET= \
./bat-go vault import-key --config=./config.yaml
# pass a known key to only import one: --wallet-refs=gemini-referral

Running settlement

First bring up vault as described above.

./bat-go vault sign-settlement --config=./config.yaml --in=SETTLEMENT_REPORT.JSON

Finally seal the vault:

./vault operator seal

You can now stop the server instance.

Copy the signed json flie to the usb stick and transfer it to the online computer.

On the online computer:

export UPHOLD_ENVIRONMENT=
export UPHOLD_HTTP_PROXY=
export UPHOLD_ACCESS_TOKEN=
export UPHOLD_SETTLEMENT_ADDRESS=
export VAULT_ADDR=
./settlement-submit -in <SIGNED_SETTLEMENT.JSON>

Note that you can run submit multiple times, progress is tracked in a log to allow restoring from errors and to avoid duplicate payouts.

Finally upload the "-finished" output file to eyeshade to account for payout transactions that were made.

Creating a new offline wallet

On the offline machine, first bring up vault as described above.

Run vault-create-wallet, this will sign the registration and store it into a local file:

./bat-go vault create-wallet NAME_OF_NEW_WALLET

Copy the created name-of-new-wallet-registration.json file to the online machine.

Re-run vault-create-wallet, this will submit the pre-signed registration:

Uphold
export UPHOLD_ENVIRONMENT=
export UPHOLD_HTTP_PROXY=
export UPHOLD_ACCESS_TOKEN=
export VAULT_ADDR=
./bat-go vault create-wallet -offline NAME_OF_NEW_WALLET
Gemini
export GEMINI_CLIENT_ID
export GEMINI_CLIENT_KEY
export GEMINI_CLIENT_SECRET
export GEMINI_SERVER
export GEMINI_SUBMIT_TYPE
export VAULT_ADDR

Finally copy name-of-new-wallet-registration.json back to the offline machine and run vault-create-wallet to record the provider ID in vault:

./bat-go vault create-wallet -offline NAME_OF_NEW_WALLET

Signing Files

Signing the settlement file will split the input files into many output files depending on the contents of the file

Uphold
./bat-go vault sign-settlement --config=./config.yaml --in=contributions.json
Gemini
./bat-go vault sign-settlement --config=publishers-gemini.yaml --in=publishers-payout-report-gemini-referrals.json --providers=gemini

Uploading files

Running settlement-submit with a provider tells the script where to submit the file and the kind of handler to use.

Uphold
./settlement-submit -in=gemini-contributions-signed.json -provider=uphold
Gemini

gemini has a command available to it for uploading transactions and sending

./bat-go settlement gemini upload --input=gemini-referral-publishers-payout-report-gemini-referrals-signed.json --all-txs-input=publishers-payout-report-gemini-referrals.json

and to check the status of each transaction a checkstatus command has been added

./bat-go settlement gemini checkstatus --input=bulk-signed-transactions.json --all-txs-input=from-antifraud.json

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForDuplicates added in v0.3.0

func CheckForDuplicates(transactions []Transaction) error

CheckForDuplicates in a list of transactions

func CheckPreparedTransactions

func CheckPreparedTransactions(settlementWallet *uphold.Wallet, settlements []Transaction) error

CheckPreparedTransactions performs sanity checks on an array of signed settlements

func ConfirmPreparedTransaction

func ConfirmPreparedTransaction(settlementWallet *uphold.Wallet, settlement *Transaction) error

ConfirmPreparedTransaction confirms a single settlement transaction with uphold

It is designed to be idempotent across multiple runs, in case of network outage transactions that
were unable to be confirmed during an initial run can be submitted in subsequent runs.

func ConfirmPreparedTransactions

func ConfirmPreparedTransactions(settlementWallet *uphold.Wallet, settlements []Transaction) error

ConfirmPreparedTransactions confirms settlement transactions that have already been submitted to uphold

It is designed to be idempotent across multiple runs, in case of network outage transactions that
were unable to be confirmed during an initial run can be confirmed in subsequent runs.

func ParseBPTSignedSettlement

func ParseBPTSignedSettlement(jsonIn []byte) ([]string, error)

ParseBPTSignedSettlement parses the signed output from brave-payment-tools

It returns an array of base64 encoded "extracted" httpsignatures

func PrepareTransactions

func PrepareTransactions(wallet *uphold.Wallet, settlements []Transaction) error

PrepareTransactions by embedding signed transactions into the settlement documents

func ReadFiles added in v0.4.0

func ReadFiles(filesPaths []string) (*[]Transaction, error)

ReadFiles reads a series of files

func SubmitPreparedTransaction

func SubmitPreparedTransaction(settlementWallet *uphold.Wallet, settlement *Transaction) error

SubmitPreparedTransaction submits a single settlement transaction to uphold

It is designed to be idempotent across multiple runs, in case of network outage transactions that
were unable to be submitted during an initial run can be submitted in subsequent runs.

func SubmitPreparedTransactions

func SubmitPreparedTransactions(settlementWallet *uphold.Wallet, settlements []Transaction) error

SubmitPreparedTransactions by submitting them to uphold after performing sanity checks

It is designed to be idempotent across multiple runs, in case of network outage transactions that
were unable to be submitted during an initial run can be submitted in subsequent runs.

Types

type AntifraudTransaction added in v0.4.0

type AntifraudTransaction struct {
	Address           string          `json:"address"`
	BAT               decimal.Decimal `json:"bat"`
	ChannelType       string          `json:"channel_type"`
	Fees              decimal.Decimal `json:"fees"`
	ID                string          `json:"id"`
	Owner             string          `json:"owner"`
	OwnerState        string          `json:"owner_state"`
	PayoutReportID    string          `json:"payout_report_id"`
	Publisher         string          `json:"publisher"`
	Type              string          `json:"type"`
	URL               string          `json:"url"`
	WalletCountryCode string          `json:"wallet_country_code"`
	WalletProvider    string          `json:"wallet_provider"`
	WalletProviderID  string          `json:"wallet_provider_id"`
}

AntifraudTransaction a transaction object that comes from antifraud

func (AntifraudTransaction) ProviderInfo added in v0.4.0

func (at AntifraudTransaction) ProviderInfo() ProviderInfo

ProviderInfo splits apart provider info from wallet provider id

func (AntifraudTransaction) ToTransaction added in v0.4.0

func (at AntifraudTransaction) ToTransaction() Transaction

ToTransaction turns the antifraud transaction into a transaction understandable by settlement tools

type BPTSignedSettlement

type BPTSignedSettlement struct {
	SignedTxs []struct {
		uphold.HTTPSignedRequest `json:"signedTx"`
	} `json:"signedTxs"`
}

BPTSignedSettlement is a struct describing the signed output format of brave-payment-tools

type Config added in v0.4.0

type Config struct {
	Wallets map[string]string `yaml:"wallets"`
}

Config a space for complex inputs

func ReadYamlConfig added in v0.4.0

func ReadYamlConfig(configPath string) (*Config, error)

ReadYamlConfig reads a yaml config

func (*Config) GetWalletKey added in v0.4.0

func (config *Config) GetWalletKey(key string) string

GetWalletKey accesses the wallet config

type ProviderInfo added in v0.4.0

type ProviderInfo struct {
	Establishment string `json:"establishment"`
	Type          string `json:"type"`
	ID            string `json:"id"`
}

ProviderInfo holds information parsed from the wallet_provider_id

type State

type State struct {
	WalletInfo   wallet.Info   `json:"walletInfo"`
	Transactions []Transaction `json:"transactions"`
}

State contains the current state of the settlement, including wallet and transaction status

type Transaction

type Transaction struct {
	AltCurrency      *altcurrency.AltCurrency `json:"altcurrency"`
	Authority        string                   `json:"authority"`
	Amount           decimal.Decimal          `json:"amount"`
	ExchangeFee      decimal.Decimal          `json:"commission"`
	Currency         string                   `json:"currency"`
	Destination      string                   `json:"address"`
	Publisher        string                   `json:"owner"`
	BATPlatformFee   decimal.Decimal          `json:"fees"`
	Probi            decimal.Decimal          `json:"probi"`
	ProviderID       string                   `json:"hash"`
	WalletProvider   string                   `json:"walletProvider"`
	WalletProviderID string                   `json:"walletProviderId"`
	Channel          string                   `json:"publisher"`
	SignedTx         string                   `json:"signedTx"`
	Status           string                   `json:"status"`
	SettlementID     string                   `json:"transactionId" valid:"uuidv4"`
	TransferFee      decimal.Decimal          `json:"fee"`
	Type             string                   `json:"type"`
	ValidUntil       time.Time                `json:"validUntil,omitempty"`
	DocumentID       string                   `json:"documentId,omitempty"`
	Note             string                   `json:"note"`
}

Transaction describes a payout transaction from the settlement wallet to a publisher

func (Transaction) IsComplete

func (tx Transaction) IsComplete() bool

IsComplete returns true if the transaction status is completed

func (Transaction) IsFailed added in v0.5.0

func (tx Transaction) IsFailed() bool

IsFailed returns true if the transaction status is failed

func (Transaction) Log added in v0.5.0

func (tx Transaction) Log()

Log logs a message

func (Transaction) TransferID added in v0.5.0

func (tx Transaction) TransferID() string

TransferID generate the transfer id

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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