Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
"bech32": "^1.1.4",
"bip32-path": "^0.4.2",
"joi": "^17.4.0",
"struct": "0.0.12"
"struct": "0.0.12",
"@ledgerhq/hw-transport": "^6.27.6",
"@ledgerhq/logs": "^6.10.1",
"@ledgerhq/types-cryptoassets":"^6.23.2"

},
"devDependencies": {
"eslint": "^7.19.0",
Expand Down
99 changes: 99 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
export const CLA = 0x7b;
export const ADPUInstructions = {
INS_NO_OPERATION: 0x00,

INS_GET_APP_CONFIG: 0x10,
INS_SET_ACCOUNT: 0x11,

// data buffer instructions
INS_GET_DATA_BUFFER_STATE: 0x80,
INS_WRITE_DATA_BLOCK: 0x81,
INS_READ_DATA_BLOCK: 0x82,
INS_CLEAR_DATA_BUFFER: 0x83,

INS_SHOW_FLOW: 0x90,
INS_PREPARE_BLIND_SIGNING: 0x91,

// iota specific crypto instructions
INS_PREPARE_SIGNING: 0xa0,
INS_GEN_ADDRESS: 0xa1,
INS_SIGN: 0xa2,
INS_USER_CONFIRM_ESSENCE: 0xa3,
INS_SIGN_SINGLE: 0xa4,

// commands for debug mode
INS_DUMP_MEMORY: 0x66,
INS_SET_NON_INTERACTIVE_MODE: 0x67,

INS_RESET: 0xff,
};

export const APDUInstructionsBolos = {
GET_APP_VERSION_B0: 0x01,
APP_EXIT_B0: 0xa7,

OPEN_APP_E0: 0xd8,
};

export const TIMEOUT_CMD_NON_USER_INTERACTION = 10000;
export const TIMEOUT_CMD_USER_INTERACTION = 150000;

export const ED25519_PUBLIC_KEY_LENGTH = 32;
export const ED25519_SIGNATURE_LENGTH = 64;

export const Flows = {
FlowMainMenu: 0,
FlowGeneratingAddresses: 1,
FlowGenericError: 2,
FlowRejected: 3,
FlowSignedSuccessfully: 4,
FlowSigning: 5,
};

export const AppModes = {
ModeIOTAChrysalis: 0x00,
ModeIOTAChrysalisTestnet: 0x80,
ModeIOTAStardust: 0x01,
ModeIOTAStardustTestnet: 0x81,
ModeShimmerClaiming: 0x02,
ModeShimmerClaimingTestnet: 0x82,
ModeShimmer: 0x03,
ModeShimmerTestnet: 0x83,
};

// TODO: questionable structure
export class DataTypeEnum {
static Empty = new DataTypeEnum(0);
static GeneratedAddress = new DataTypeEnum(1);
static ValidatedEssence = new DataTypeEnum(2);
static UserConfirmedEssence = new DataTypeEnum(3);
static Signatures = new DataTypeEnum(4);
static Locked = new DataTypeEnum(5);

static Unknown = new DataTypeEnum(255);

type: number;

constructor(type: number) {
this.type = type;
}

get_type(i: number): DataTypeEnum {
switch (i) {
case 0:
return DataTypeEnum.Empty;
case 1:
return DataTypeEnum.GeneratedAddress;
case 2:
return DataTypeEnum.ValidatedEssence;
case 3:
return DataTypeEnum.UserConfirmedEssence;
case 4:
return DataTypeEnum.Signatures;
case 5:
return DataTypeEnum.Locked;
default:
return DataTypeEnum.Unknown;
}
}
}
46 changes: 23 additions & 23 deletions src/error.js → src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@ function getStatusMessage(statusCode) {
switch (statusCode) {
// improve text of most common errors
case 0x9000: // SW_OK
return 'Success';
return "Success";
case 0x6700: // SW_INCORRECT_LENGTH
return 'Incorrect input length';
return "Incorrect input length";
case 0x6a80: // SW_COMMAND_INVALID_DATA
return 'Incorrect data';
return "Incorrect data";
case 0x6b00: // SW_INCORRECT_P1P2
return 'Incorrect command parameter';
return "Incorrect command parameter";
case 0x6c00: // SW_INCORRECT_LENGTH_P3
return 'Incorrect length specified in header';
return "Incorrect length specified in header";
case 0x6d00: // SW_INS_NOT_SUPPORTED
return 'Invalid INS command';
return "Invalid INS command";
case 0x6e00: // SW_CLA_NOT_SUPPORTED
return 'Incorrect CLA (Wrong application opened)';
return "Incorrect CLA (Wrong application opened)";
case 0x6900: // SW_COMMAND_NOT_ALLOWED
return 'Command not allowed (Command out of order)';
return "Command not allowed (Command out of order)";
case 0x6982: // SW_SECURITY_STATUS_NOT_SATISFIED
return 'Security not satisfied (Device locked)';
return "Security not satisfied (Device locked)";
case 0x6985: // SW_CONDITIONS_OF_USE_NOT_SATISFIED
return 'Condition of use not satisfied (Denied by the user)';
return "Condition of use not satisfied (Denied by the user)";
case 0x6401: // SW_COMMAND_TIMEOUT
return 'Security not satisfied (Timeout exceeded)';
return "Security not satisfied (Timeout exceeded)";
case 0x69a1: // SW_BUNDLE_ERROR + INSECURE HASH
return 'Bundle error (Insecure hash)';
return "Bundle error (Insecure hash)";
case 0x69a2: // SW_BUNDLE_ERROR + NON-ZERO BALANCE
return 'Bundle error (Non zero balance)';
return "Bundle error (Non zero balance)";
case 0x69a3: // SW_BUNDLE_ERROR + INVALID META TX
return 'Bundle error (Invalid meta transaction)';
return "Bundle error (Invalid meta transaction)";
case 0x69a4: // SW_BUNDLE_ERROR + INVALID ADDRESS INDEX
return 'Bundle error (Invalid input address/index pair(s))';
return "Bundle error (Invalid input address/index pair(s))";
case 0x69a5: // SW_BUNDLE_ERROR + ADDRESS REUSED
return 'Bundle error (Address reused)';
return "Bundle error (Address reused)";

// Legacy exceptions
case 0x6984: // SW_COMMAND_INVALID_DATA
return 'Invalid input data';
return "Invalid input data";
case 0x6986: // SW_APP_NOT_INITIALIZED
return 'App has not been initialized by user';
return "App has not been initialized by user";
case 0x6991: // SW_TX_INVALID_INDEX
return 'Invalid transaction index';
return "Invalid transaction index";
case 0x6992: // SW_TX_INVALID_ORDER
return 'Invalid transaction order (Output, Inputs, Change)';
return "Invalid transaction order (Output, Inputs, Change)";
case 0x6993: // SW_TX_INVALID_META
return 'Invalid meta transaction';
return "Invalid meta transaction";
case 0x6994: // SW_TX_INVALID_OUTPUT
return 'Invalid output transaction (Output must come first)';
return "Invalid output transaction (Output must come first)";
}

// unexpected exception thrown
if (0x6f00 <= statusCode && statusCode <= 0x6fff) {
return 'Internal error, please report';
return "Internal error, please report";
}
}

Expand Down
Loading