[Webfunds-commits] java/webfunds/sox RandomToken.java

Ian Grigg iang@cypherpunks.ai
Tue, 5 Dec 2000 13:40:39 -0400 (AST)


iang        00/12/05 13:40:38

  Modified:    webfunds/sox RandomToken.java
  Log:
  1. changed over token batching from expiry time to series string (too
     hard to predict actual expiry type, made that a higher layer thing).
  2. added keypair creation, so that this token class has all that
     is needed for the independant implementation of the type.

Revision  Changes    Path
1.3       +55 -12    java/webfunds/sox/RandomToken.java

Index: RandomToken.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/RandomToken.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RandomToken.java	2000/11/09 13:13:50	1.2
+++ RandomToken.java	2000/12/05 17:40:37	1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: RandomToken.java,v 1.2 2000/11/09 13:13:50 iang Exp $
+ * $Id: RandomToken.java,v 1.3 2000/12/05 17:40:37 iang Exp $
  *
  * Copyright (c) Systemics Inc 1995-2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -13,6 +13,7 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 
+import java.security.KeyPair;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.security.KeyException;
@@ -129,17 +130,18 @@
 
 /////////  Phases  //////////////////////////////////////////////
 
-    public void sign(PrivateKey key, long expiry)
+    public void sign(PrivateKey key, byte[] series)
         throws KeyException
     {
-        this.expiry = expiry;
+        this.series = series;
+
         sig = Crypto.sign(key, token);
         state = TOK_SIGNED;
     }
 
-    private void cheatSign(long expiry)        // for example(), no key needed
+    private void cheatSign(byte[] series)        // for example(), no key needed
     {
-        this.expiry = expiry;
+        this.series = series;
         sig = Utils.exampleData(20);
         state = TOK_SIGNED;
     }
@@ -179,6 +181,49 @@
         state = TOK_UNBLIND;
     }
 
+    /**
+     *  Return the unique identifier that can be used for double-
+     *  spend checking.
+     *  Relied upon by the mint (Issuer).
+     */
+    public byte[] getUniqueId()
+    {
+        return token;
+    }
+
+
+
+/////////  Key Creation  //////////////////////////////////////////////
+
+    /**
+     *  Return the unique identifier that can be used for double-
+     *  spend checking.
+     *
+     *  Don't call this method, use the PaymentFactory one instead.
+     *
+     *  These methods are relied upon by the mint (Issuer).
+     */
+    /*family*/ static KeyPair createKeyPair(byte[] series, int log)
+        throws SOXKeyException
+    {
+        KeyPair kp;
+        try {
+            //
+            //  This Random method is for demo purposes, so doesn't
+            //  need any great key strength.
+            //
+            kp = Crypto.generateKeys(768);
+        } catch (Throwable ex) {
+            //
+            // As the generateKeys uses a provider, we don't know for
+            // for sure that exceptions can't be thrown.  Be dramatic
+            // catch it all, and bounce the account.
+            //
+            ex.printStackTrace();
+            throw new SOXKeyException(ex.getMessage());
+        }
+        return kp;
+    }
 
 
 
@@ -208,8 +253,8 @@
         if (type != RANDOM_TYPE)
             throw new SOXPacketException("not RandomToken (" +subversion+ ")");
 
-        // we have to save expiry if we want it
-        expiry = dis.readLong();
+        // we have to save the series and the expiry if we want it
+        series = readByteArray(dis);
 
         sig = readByteArray(dis);          // always returns array
         token = readByteArray(dis);
@@ -230,7 +275,7 @@
 
         super.encode(dos);
 
-        dos.writeLong(expiry);
+        writeByteArray(dos, series);
 
         writeByteArray(dos, sig);
         writeByteArray(dos, token);
@@ -275,10 +320,8 @@
 
         if ((b & 0x3) >= 2)
         {
-            long expiry = Utils.exampleLong();      // might be expired
-            if (expiry < 0)
-                expiry = -expiry;
-            obj.cheatSign(expiry);
+            byte[] series = Utils.exampleData();
+            obj.cheatSign(series);
         }
 
         if ((b & 0x3) >= 2)