webfunds.sox
Class RandomToken

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.Token
              |
              +--webfunds.sox.RandomToken

public class RandomToken
extends Token

This class represents a Big Random Number Token. The token derives its security from the unguessability of the random number; this is mostly useful for demonstration purposes than in actual live fire as its characteristics for payment systems use are dominated by other methods. RandomToken objects are usually created by the mint.

See Also:
Serialized Form

Field Summary
static int RANDOM_TYPE
          The type of token encoded by this class.
protected  byte[] sig
          The signature on the token (generally made by the mint).
static int SUB_VERSION
          The sub version number for this payment structure: 0: first cut.
protected  byte[] token
          The token payload (generally made by the client).
 
Fields inherited from class webfunds.sox.Token
expiry, log, series, sig, state, subversion, TOK_PROTO, TOK_RAW, TOK_RECEIVED, TOK_SETTLED, TOK_SIGNED, TOK_SPENT, TOK_UNBLIND, TOK_VALID, type, version, VERSION
 
Constructor Summary
RandomToken(byte[] paymentData)
           
RandomToken(java.io.InputStream is)
           
RandomToken(int log)
          Create a RandomToken
 
Method Summary
protected static void cycle()
           
 void decode(java.io.InputStream is)
          Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object).
 void encode(java.io.OutputStream os)
          Encode a payment as a byte array, suitable for sending to third parties for depositing.
 boolean equals(java.lang.Object obj)
           
static RandomToken example()
           
 byte[] getPayload()
           
static Token[] getProtoTokens(int[] coins)
          Make a set of Tokens matched to a set of coin sizes.
static Token[] getProtoTokens(long qty)
          Make a set of Tokens that can handle a quantity.
 byte[] getSignature()
           
 byte[] getUniqueId()
          Return the unique identifier that can be used for double- spend checking.
protected static void input()
           
static void main(java.lang.String[] args)
           
protected static void output()
           
 void prototype()
          Create the prototype coin.
protected static void readWrite()
           
 void sign(java.security.PrivateKey key, byte[] series)
          Sign a protocoin.
 java.lang.String toString()
           
 void unblind()
          Unblind the signed coin, revealing the signed, private coin.
 boolean verify(java.security.PublicKey key)
          Sign a protocoin.
 
Methods inherited from class webfunds.sox.Token
getExpiry, getLog, getQty, getSeries, getState, getSubVersion, getType, getVersion, isProto, isRaw, isReceived, isSettled, isSigned, isSpent, isUnblinded, setState, 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

SUB_VERSION

public static final int SUB_VERSION
The sub version number for this payment structure: 0: first cut.

RANDOM_TYPE

public static final int RANDOM_TYPE
The type of token encoded by this class.

sig

protected byte[] sig
The signature on the token (generally made by the mint). How it is made and verified is coded within the crypto-system as found in sign().

token

protected byte[] token
The token payload (generally made by the client). How it is made and verified is coded within the crypto-scheme as found in prototype().
Constructor Detail

RandomToken

public RandomToken(int log)
Create a RandomToken
Parameters:
log - the coin size, log base 2 of quantity

RandomToken

public RandomToken(byte[] paymentData)
            throws SOXPacketException

RandomToken

public RandomToken(java.io.InputStream is)
            throws SOXPacketException
Method Detail

getSignature

public byte[] getSignature()
Overrides:
getSignature in class Token
Returns:
the signature on the token (never null)

getPayload

public byte[] getPayload()
Returns:
the token payload (never null)

getProtoTokens

public static Token[] getProtoTokens(long qty)
Make a set of Tokens that can handle a quantity. Simply calls qty2coins() then uses those sizes. What to do with the zero quantity is undefined, here, we implement a zero token as valid (according to well-established SOX design principles), so a single zero token is returned for zero amount.

getProtoTokens

public static Token[] getProtoTokens(int[] coins)
Make a set of Tokens matched to a set of coin sizes.

sign

public void sign(java.security.PrivateKey key,
                 byte[] series)
          throws java.security.KeyException
Description copied from class: Token
Sign a protocoin. Alternative to expressing expiry is to set a series.
Overrides:
sign in class Token
Tags copied from class: Token
Parameters:
series - is a string identifying batch
key - is the signing key of the mint

verify

public boolean verify(java.security.PublicKey key)
               throws java.security.KeyException
Description copied from class: Token
Sign a protocoin. Normally called by client & server to check the coin is signed, matched pair with sign() so it can be a standardised call.
Overrides:
verify in class Token
Tags copied from class: Token
Parameters:
key - is the signer's public key (of the mint)

prototype

public void prototype()
Create the prototype coin. Normally called by client, no standard paramaters.

unblind

public void unblind()
Unblind the signed coin, revealing the signed, private coin. Normally called by client, no standard paramaters.
Overrides:
unblind in class Token

getUniqueId

public byte[] getUniqueId()
Return the unique identifier that can be used for double- spend checking. Relied upon by the mint (Issuer).
Overrides:
getUniqueId in class Token
Tags copied from class: Token
Parameters:
key - is the signer's public key (of the mint)

decode

public void decode(java.io.InputStream is)
            throws java.io.IOException,
                   SOXPacketException
Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object). If the signature is not present in the encoded data, the current signature (if any) will be removed.
Overrides:
decode in class Token
Parameters:
paymentData - the previosly encoded payment

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Encode a payment as a byte array, suitable for sending to third parties for depositing. If the signature is not present, an unsigned payment will be encoded.
Overrides:
encode in class Token
Returns:
byte[] the payment in encoded form

toString

public java.lang.String toString()
Overrides:
toString in class Token

example

public static RandomToken example()

equals

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

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