Skip to content

Commit

Permalink
feat: now builds CAP
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-sekanina committed Nov 20, 2022
1 parent d9315d4 commit aa5161e
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 43 deletions.
2 changes: 0 additions & 2 deletions applet/src/main/java/applet/FromApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import javacard.framework.APDU;
import javacard.framework.Util;

import java.util.Arrays;


public class FromApplet {
/**
Expand Down
6 changes: 3 additions & 3 deletions applet/src/main/java/applet/GlobalMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import static applet.MainApplet.PSBTdata;

public class GlobalMap extends GeneralMap {
Short input_maps_total = null;
Short output_maps_total = null;
Short PSBTversion = null;
short input_maps_total = -1;
short output_maps_total = -1;
short PSBTversion = -1;
GlobalUnsignedTX globalUnsignedTX = new GlobalUnsignedTX();

public void fill(short arrayIndex) {
Expand Down
10 changes: 5 additions & 5 deletions applet/src/main/java/applet/GlobalUnsignedTX.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*/
public class GlobalUnsignedTX {
final static short MAX_COUNT_OF_IO = 8;
Short start = null;
Short version = null;
short start = -1;
short version = -1;
short size = 0;

Short input_count = null;
short input_count = -1;
GlobalUnsignedTXInput[] inputs = new GlobalUnsignedTXInput[MAX_COUNT_OF_IO];

Short output_count = null;
short output_count = -1;
GlobalUnsignedTXOutput[] outputs = new GlobalUnsignedTXOutput[MAX_COUNT_OF_IO];

Short lockTimeStart = null;
short lockTimeStart = -1;

GlobalUnsignedTX(){
for (short i = 0; i < MAX_COUNT_OF_IO; i++){
Expand Down
8 changes: 4 additions & 4 deletions applet/src/main/java/applet/GlobalUnsignedTXInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

public class GlobalUnsignedTXInput {
short previous_output_start = -1;
Short script_size_start = null;
Short script_size = null;
Short script_sig_start = null;
Short sequence_start = null;
short script_size_start = -1;
short script_size = -1;
short script_sig_start = -1;
short sequence_start = -1;
short size = 0;

void fill(short start){
Expand Down
6 changes: 3 additions & 3 deletions applet/src/main/java/applet/GlobalUnsignedTXOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class GlobalUnsignedTXOutput {
short value_start = -1;
Short script_size_tart = null;
Short script_size = null;
Short script_pub_key_start = null;
short script_size_tart = -1;
short script_size = -1;
short script_pub_key_start = -1;
short size = 0;

void fill(short start){
Expand Down
11 changes: 2 additions & 9 deletions applet/src/main/java/applet/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

public class Key {
public short start = -1;
public Short key_len = null;
public short key_len = -1;
public short key_len_bytes = 1;
public Short key_type = null;
public short key_type = -1;

public void fill(short arrayIndex) {
start = arrayIndex;
Expand All @@ -21,11 +21,4 @@ public short getSize() {
return (short) (key_len_bytes + key_len);
}

public byte getByte(short index) {
return PSBTdata[start + key_len_bytes + index];
}

public void setByte(short index, byte newByte) {
PSBTdata[start + key_len_bytes + index] = newByte;
}
}
4 changes: 2 additions & 2 deletions applet/src/main/java/applet/MainApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void process(APDU apdu) {
try {
psbt.fill();
} catch (Exception e) {
e.printStackTrace();
//DO NOTHING
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public void process(APDU apdu) {
}

if (cla == AppletInstructions.CLASS_DOWNLOAD_GLOBAL_MAP && ins == AppletInstructions.INS_DOWNLOAD_VERSION){
if (psbt.global_map.PSBTversion != null) {
if (psbt.global_map.PSBTversion != -1) {
FromApplet.send_data(apdu, psbt.global_map.PSBTversion);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions applet/src/main/java/applet/PSBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public void fill() throws Exception {

//TODO: check that current IOMap != numOfIOMaps

while (global_map.input_maps_total != null && current_input_map < global_map.input_maps_total) {
while (global_map.input_maps_total != -1 && current_input_map < global_map.input_maps_total) {
input_maps[current_input_map].fill(byte_size);
byte_size += input_maps[current_input_map].map_size;
byte_size++;
current_input_map++;
}

while (global_map.output_maps_total != null && current_output_map < global_map.output_maps_total) {
while (global_map.output_maps_total != -1 && current_output_map < global_map.output_maps_total) {
output_maps[current_output_map].fill(byte_size);
byte_size += output_maps[current_output_map].map_size;
byte_size++;
Expand Down
2 changes: 1 addition & 1 deletion applet/src/main/java/applet/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static short toShort(byte zero, byte first) {
*/
public static short compactWeirdoInt(short int_start) {
if ((short) (PSBTdata[int_start] & 0xff) == 0xfd) {
return (Tools.toShort(PSBTdata[int_start + 1], PSBTdata[int_start + 2]));
return (Tools.toShort(PSBTdata[(short) (int_start + 1)], PSBTdata[(short) (int_start + 2)]));
}
return (short) (PSBTdata[int_start] & 0xff);
}
Expand Down
8 changes: 2 additions & 6 deletions applet/src/main/java/applet/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Value {
public short start = -1;
public Short value_len = null;
public short value_len = -1;
public short value_len_bytes = 1;

public void fill(short arrayIndex) {
Expand All @@ -20,10 +20,6 @@ public short getSize() {
}

public byte getByte(short index) {
return PSBTdata[start + value_len_bytes + index];
}

public void setByte(short index, byte newByte) {
PSBTdata[start + value_len_bytes + index] = newByte;
return PSBTdata[(short) (start + value_len_bytes + index)];
}
}
6 changes: 0 additions & 6 deletions applet/src/main/java/main/Run.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package main;

import applet.MainApplet;
import com.licel.jcardsim.smartcardio.CardSimulator;
import com.licel.jcardsim.utils.AIDUtil;
import javacard.framework.AID;

import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import java.util.Scanner;

public class Run {
public static void main(String[] args) throws Exception {
Expand Down

0 comments on commit aa5161e

Please sign in to comment.