Skip to main content
Zondax Github LinkZondax Github Link
Theme SwitchTheme Switch

Algorand App

General structure

The general structure of commands and responses is as follows:

Commands

FieldTypeContentNote
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID
P1byte (1)Parameter 1
P2byte (1)Parameter 2
Lbyte (1)Bytes in payload
PAYLOADbyte (L)Payload

Response

FieldTypeContentNote
ANSWERbyte (?)Answerdepends on the command
SW1-SW2byte (2)Return codesee list of return codes

Return codes

Return codeDescription
0x6400Execution Error
0x6982Empty buffer
0x6983Output buffer too small
0x6984Data invalid
0x6986Command not allowed
0x6987Tx not initialized
0x6D00INS not supported
0x6E00CLA not supported
0x6F00Unknown
0x9000Success

Command definition

GET_VERSION

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x00
P1byte (1)Parameter 1ignored
P2byte (1)Parameter 2ignored
Lbyte (1)Bytes in payload0

Response

FieldTypeContentNote
TESTbyte (1)Test Mode0xFF means test mode is enabled
MAJORbyte (2)Version Major0..65535
MINORbyte (2)Version Minor0..65535
PATCHbyte (2)Version Patch0..65535
LOCKEDbyte (1)Device is locked
SW1-SW2byte (2)Return codesee list of return codes

INS_GET_PUBLIC_KEY

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x03
P1byte (1)Request User confirmationNo = 0
P2byte (1)Parameter 2ignored
LCbyte (1)Bytes in payload(depends)
Payloadbyte (4)Account ID(depends)

The account number is used to derive keys from BIP32 path 44'/283'/{'<'}account{'>'}'/0/0 (note that the account number is hardened as shown by the ' sign). Account number defaults to 0x0 in the case of APDU with empty payload.

Response

FieldTypeContentNote
PublicKeybyte (65)Public Key
Addressbyte (58)Address
SW1-SW2byte (2)Return codesee list of return codes

INS_SIGN_MSGPACK

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x08
P1byte (1)Request User confirmation(depends)
P2byte (1)Parameter 2(depends)
LCbyte (1)Bytes in payload(depends)
Payloadbyte (var)AccID + MsgPack Chunks(depends)

If one single APDU may contain a whole transaction, P1 and P2 are both 0x00.

New format enhances messaging with an optional account number that must be inserted in the first chunk of the sequence. As an optional payload, bit 0 of field P1 in the first chunk must be set if present in the message.

And as for INS_GET_PUBLIC_KEY instruction, it is a big-endian encoded 32-bit unsigned integer word.

The resulting sequence of chunks is as follows:

First APDU message

CLAINSP1P2LCPayload
0x800x080x010x80N1account + MsgPack chunk #1

...

APDU message i

CLAINSP1P2LCPayload
0x800x080x800x80NiMsgPack chunk #i

...

Last APDU message

CLAINSP1P2LCPayload
0x800x080x800x00NIMsgPack chunk #I

Response

FieldTypeContentNote
Signaturebyte (64)Signed message
SW1-SW2byte (2)Return codesee list of return codes

If one signle APDU is needed for the whole transaction along with the account number, P1 and P2 are 0x01 and 0x00 respectively.

CLAINSP1P2LCPayload
0x800x080x010x00N1account + MsgPack txn

If the account number is not inserted within the message, the former message format is used (P1 in the first chunk is 0x00) and the account number defaults to 0x00 for the transaction signature.

CLAINSP1P2LCPayload
0x800x080x000x00N1MsgPack txn

INS_SIGN_ARBITRARY_DATA

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x10
P1byte (1)First/More/Last(depends)
P2byte (1)N/A0x00
LCbyte (1)Bytes in payload(depends)
Payloadbyte (var)hdPath + Arbitrary data(depends)

First APDU message (only contains hdPath)

CLAINSP1P2LCPayload
0x800x100x000x00N1hdPath

APDU message i

CLAINSP1P2LCPayload
0x800x100x010x00NiArb. data chunk i

Last APDU message

CLAINSP1P2LCPayload
0x800x100x020x00NIArb. data last chunk
Arbitrary Data Chunks
FieldRestrictionsMax Size (bytes)
Signer-32
Scopesee Supported Scopes1
Encodingsee Supported Encodings1
Data Len2
DataCanonical JSON511
Domain Len2
DomainRepresentable ASCII255
Request ID Len2
Request ID255
Authenticated Data Len2
Authenticated Data256
Supported Scopes
  • AUTH : 1
Supported Encodings
  • Base64 : 1

Checks performed by the wallet

  • Signer is a raw Public Key (Hex String)
    • Algorand Address not allowed
  • Authenticated Data's first 32 bytes must be equal to sha256(Domain)
  • Domain is representable ASCII (Values in range 33..126, both included)
  • Data is a canonical JSON
  • hdPath is BIP44 and starts with 44'/283'
  • hdPath hardening restrictions

Response

OK
FieldTypeContent
Signaturebyte (64)Signed [sha256(data) + sha256(Authenticated Data)]
SW1-SW2byte (2)0x9000
Error
FieldTypeContentNote
SW1-SW2byte (2)Return codesee Arbitrary Sign Return Codes

Arbitrary Sign Return codes

Return codeDescription
0x6400Execution Error
0x6982Empty buffer
0x6983Output buffer too small
0x6986Command not allowed
0x6988Invalid scope
0x6989Failed decoding
0x698AInvalid signer
0x698BMissing domain
0x698CMissing authenticated data
0x698DBad JSON
0x698EFailed domain authentication
0x698FFailed HD path
0x6D00INS not supported
0x6E00CLA not supported
0x6F00Unknown
0x9000Success