webfunds.sox
Class Receipt

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.Receipt

public class Receipt
extends Encodable

This class represents a signed receipt, such as received from an issuer in response to a deposit request. SOX clients usually only create receipts using data received from the issuer.

See Also:
Serialized Form

Field Summary
protected  java.io.PrintWriter debug
           
protected  DepositRequest depositRequest
           
protected  byte[] depositRequestData
           
protected  java.lang.String did
           
protected  AbstractPayment exPayment
          The Exchange Payment is what is returned in case of a Withdrawal.
protected  byte[] exPaymentData
           
protected  long flags
          Some flags to indicate special conditions.
protected  ItemId item
           
protected  java.lang.String pid
           
protected  long qty
           
static int RECEIPT_LOCAL_VERS
          The version of the encoded receipt.
static int RECEIPT_not_used_yet
          The version of the encoded receipt.
static int RECEIPT_ORIGINAL
          The version of the encoded receipt.
static int RECEIPT_PROTO
          The version of the encoded receipt.
protected  byte[] sig
           
protected  AccountId src
           
protected  AccountId tgt
           
protected  long timestamp
           
protected  int version
           
static long WITHDRAW_PROTO
           
protected  java.lang.String xid
           
 
Constructor Summary
Receipt(byte[] receiptData)
          Construct a receipt object from a byte array that was previously returned from the encode() method of a receipt object.
Receipt(java.io.InputStream is)
          Construct a receipt object from data on an input stream that was previously returned from the encode() method of a receipt object.
Receipt(ItemId item, long qty, long tim, java.lang.String xid, java.lang.String pid, java.lang.String did, AccountId tgt, AccountId src, DepositRequest req)
          Create an unsigned receipt This constructor is not usually called by SOX clients.
 
Method Summary
protected static void cycle()
           
 void decode(java.io.InputStream is)
          Update this receipt object with the previously encoded receipt (such as output from the encode() method of a receipt object) read from an input stream.
protected  AccountId decodeAccountId(java.io.DataInputStream dis)
          Get SOX2 Hash for an AccountId, which has an OpenPGP Message Digest Type in advance of it.
protected  ItemId decodeItemId(java.io.DataInputStream dis)
          Get SOX2 Hash for an ItemId, which has an OpenPGP Message Digest Type in advance of it.
 void encode(java.io.OutputStream os)
          Encode a receipt, writing the data to an output stream, in a format suitable for sending to restoring using the decode() method to re-construct the object.
 void encodeId(Id id, java.io.DataOutputStream dos)
          Encode a SOX2 hash, with OpenPGP id as a byte before it.
 boolean equals(java.lang.Object object)
           
static Receipt example()
           
 byte[] getDepositDesc()
          Get the description on the deposit request.
 java.lang.String getDepositId()
          Get the identifier on the deposit request, as created by the payee.
 DepositRequest getDepositRequest()
          Get the DepositRequest object that was used to deposit the payment The DepositRequest is the signed object that the payee used to deposit the payment.
 AbstractPayment getExchangePayment()
          Get the Exchange Payment if the original request was a WithdrawalRequest.
protected  byte[] getHashSig()
          PRETEND Signature - the receipt is signed with a SHA1 MD, encoded as a message digest (type, data) within a string.
 ItemId getItem()
          Get the type of item (or "currency") of the transaction.
 AbstractPayment getPay()
          Get the Payment that was deposited.
 Payment getPayment()
          Get the Payment that was deposited.
 byte[] getPaymentDesc()
          Get the description on the payment.
 java.lang.String getPaymentId()
          Get the identifier on the payment, as originally created by the payer Note: although a java String is used, this identifier should only contain 8-bit ascii characters.
 long getQty()
          Get the quantity of the item for the transaction.
 AccountId getSource()
          Get the account to which the payment was made.
 AccountId getTarget()
          Get the account from which the transaction was drawn.
 long getTimestamp()
          Get the time and date of the transaction.
 java.lang.String getTransactionId()
          Get the identifier on the receipt (the transaction id), as created by the issuer.
 int getVersion()
           
protected static void input()
           
protected  boolean isSet(long i)
           
 boolean isSigned()
          Check to see if this receipt is signed NOTE: This does not check the validity of the signature, only that this receipt has one.
 boolean isWithdrawalReceipt()
           
static void main(java.lang.String[] args)
           
protected static void output()
           
protected static void readWrite()
           
 void setExchangePayment(AbstractPayment p)
           
 void setExchangePayment(byte[] data)
           
 void setSignature(byte[] sig)
          Define the signature for this receipt
 void sign(java.security.PrivateKey key)
          Sign this receipt
 java.lang.String toString()
          Convert this object to a human readable string
 boolean verify(java.security.PublicKey key)
          Verify this receipt
 java.lang.String vstring()
           
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, readByteArray, readCertificate, readProperties, readString, writeByteArray, writeCertificate, writeProperties, writeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RECEIPT_ORIGINAL

public static final int RECEIPT_ORIGINAL
The version of the encoded receipt. 1 - original, as delivered, no version. 2 - added MD_SHA1 signature 3 - adds Proto-payment option 4 - use me next

RECEIPT_LOCAL_VERS

public static final int RECEIPT_LOCAL_VERS
The version of the encoded receipt. 1 - original, as delivered, no version. 2 - added MD_SHA1 signature 3 - adds Proto-payment option 4 - use me next

RECEIPT_PROTO

public static final int RECEIPT_PROTO
The version of the encoded receipt. 1 - original, as delivered, no version. 2 - added MD_SHA1 signature 3 - adds Proto-payment option 4 - use me next

RECEIPT_not_used_yet

public static final int RECEIPT_not_used_yet
The version of the encoded receipt. 1 - original, as delivered, no version. 2 - added MD_SHA1 signature 3 - adds Proto-payment option 4 - use me next

version

protected int version

depositRequest

protected DepositRequest depositRequest

depositRequestData

protected byte[] depositRequestData

exPayment

protected AbstractPayment exPayment
The Exchange Payment is what is returned in case of a Withdrawal. When in the receipt, it is a signed version of the Proto Payment in the DepositRequest.

exPaymentData

protected byte[] exPaymentData

item

protected ItemId item

qty

protected long qty

timestamp

protected long timestamp

sig

protected byte[] sig

xid

protected java.lang.String xid

pid

protected java.lang.String pid

did

protected java.lang.String did

tgt

protected AccountId tgt

src

protected AccountId src

flags

protected long flags
Some flags to indicate special conditions.

WITHDRAW_PROTO

public static final long WITHDRAW_PROTO

debug

protected java.io.PrintWriter debug
Constructor Detail

Receipt

public Receipt(ItemId item,
               long qty,
               long tim,
               java.lang.String xid,
               java.lang.String pid,
               java.lang.String did,
               AccountId tgt,
               AccountId src,
               DepositRequest req)
        throws SOXPacketException
Create an unsigned receipt This constructor is not usually called by SOX clients.
Parameters:
depositRequest - the deposit request for which this is the receipt
transactionId - the transaction identifier
date - the time of the transaction

Receipt

public Receipt(byte[] receiptData)
        throws SOXPacketException
Construct a receipt object from a byte array that was previously returned from the encode() method of a receipt object. This is the usual method of constructing Receipts for SOX clients, and is done using data received from the issuer. If the signature is not present in the encoded data, the created receipt will be unsigned.
Parameters:
receiptData - the previously encoded receipt

Receipt

public Receipt(java.io.InputStream is)
        throws SOXPacketException
Construct a receipt object from data on an input stream that was previously returned from the encode() method of a receipt object. This is the usual method of constructing Receipts for SOX clients, and is done using data received from the issuer. If the signature is not present in the encoded data, the created receipt will be unsigned.
Parameters:
is - the previously encoded receipt inputstream
Method Detail

getVersion

public int getVersion()

isSet

protected boolean isSet(long i)

isWithdrawalReceipt

public boolean isWithdrawalReceipt()

getPayment

public Payment getPayment()
Get the Payment that was deposited.

getPay

public AbstractPayment getPay()
Get the Payment that was deposited.

getExchangePayment

public AbstractPayment getExchangePayment()
Get the Exchange Payment if the original request was a WithdrawalRequest. This will be a proto payment to start off with, and the mint will replace it with a signed payment.

setExchangePayment

public void setExchangePayment(AbstractPayment p)
                        throws SOXPacketException

setExchangePayment

public void setExchangePayment(byte[] data)
                        throws SOXPacketException

getDepositRequest

public DepositRequest getDepositRequest()
Get the DepositRequest object that was used to deposit the payment The DepositRequest is the signed object that the payee used to deposit the payment. This is returned by the Issuer as evidence, although the transaction that is committed is on the other fields here. If there is a difference then the other fields dominate the DepositRequest.

getPaymentId

public java.lang.String getPaymentId()
Get the identifier on the payment, as originally created by the payer Note: although a java String is used, this identifier should only contain 8-bit ascii characters.

getDepositId

public java.lang.String getDepositId()
Get the identifier on the deposit request, as created by the payee.

getTransactionId

public java.lang.String getTransactionId()
Get the identifier on the receipt (the transaction id), as created by the issuer. Note that it is only unique for the issuer that provided it. Note: although we use a java String, this identifier should only contain 7-bit ascii characters, and exclude white space, colons, commas, equals, hash [ \t\n\r:,=#].

getTarget

public AccountId getTarget()
Get the account from which the transaction was drawn.

getSource

public AccountId getSource()
Get the account to which the payment was made.

getItem

public ItemId getItem()
Get the type of item (or "currency") of the transaction. This is normally the hash of the Ricardian Contract.

getQty

public long getQty()
Get the quantity of the item for the transaction.

getPaymentDesc

public byte[] getPaymentDesc()
Get the description on the payment.

getDepositDesc

public byte[] getDepositDesc()
Get the description on the deposit request.

getTimestamp

public long getTimestamp()
Get the time and date of the transaction.

isSigned

public boolean isSigned()
Check to see if this receipt is signed NOTE: This does not check the validity of the signature, only that this receipt has one.
Returns:
boolean true if this receipt has a signature

setSignature

public void setSignature(byte[] sig)
Define the signature for this receipt
Parameters:
sig - the signature to place on the receipt, or if null, then the signature (if any) is removed.

sign

public void sign(java.security.PrivateKey key)
          throws java.security.KeyException
Sign this receipt
Parameters:
the - key to use to sign the receipt

verify

public boolean verify(java.security.PublicKey key)
               throws java.security.KeyException
Verify this receipt
Parameters:
the - public key of the signing key
Returns:
true if the signature is valid

decode

public void decode(java.io.InputStream is)
            throws java.io.IOException,
                   SOXPacketException
Update this receipt object with the previously encoded receipt (such as output from the encode() method of a receipt object) read from an input stream. If the signature is not present in the encoded data, the current signature (if any) will be removed.
Overrides:
decode in class Encodable
Parameters:
is - the stream containing the encoded receipt

decodeItemId

protected ItemId decodeItemId(java.io.DataInputStream dis)
                       throws SOXPacketException,
                              java.io.IOException
Get SOX2 Hash for an ItemId, which has an OpenPGP Message Digest Type in advance of it. ItemId is only SHA.

decodeAccountId

protected AccountId decodeAccountId(java.io.DataInputStream dis)
                             throws SOXPacketException,
                                    java.io.IOException
Get SOX2 Hash for an AccountId, which has an OpenPGP Message Digest Type in advance of it. This one can be NAH for Bearer float accounts, ones that are not directly accessible from outside.

getHashSig

protected byte[] getHashSig()
                     throws java.io.IOException
PRETEND Signature - the receipt is signed with a SHA1 MD, encoded as a message digest (type, data) within a string. Hmm, this gives us a problem when we start using DSA, w.r.t., compatibility. Check what sig fields there are for signatures in OpenPGP.

encodeId

public void encodeId(Id id,
                     java.io.DataOutputStream dos)
              throws java.io.IOException
Encode a SOX2 hash, with OpenPGP id as a byte before it. Used for hashes in the receipt body.
Parameters:
dos - the stream on which to send the output
Returns:
byte[] the receipt in encoded form

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Encode a receipt, writing the data to an output stream, in a format suitable for sending to restoring using the decode() method to re-construct the object.
Overrides:
encode in class Encodable
Parameters:
os - the stream on which to send the output
Returns:
byte[] the receipt in encoded form

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Convert this object to a human readable string
Overrides:
toString in class java.lang.Object

vstring

public java.lang.String vstring()

example

public static Receipt example()
Returns:
a receipt that is only mildly internally valid

main

public static void main(java.lang.String[] args)

cycle

protected static void cycle()
                     throws java.lang.Exception

output

protected static void output()
                      throws java.lang.Exception

readWrite

protected static void readWrite()
                         throws java.lang.Exception

input

protected static void input()
                     throws java.lang.Exception