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

Avalanche App

General structure

The app provides support for 2 sets of instructions, the Avalanche set and the Ethereum set. The Ethereum set is aimed at providing compatibility with EVM wallets, as such the API is the same as the Ethereum App, with the CLA being 0xE0, whilst the Avalanche app normally uses 0x80 for the CLA.

The general structure of commands and responses is as follows:

Commands

FieldTypeContentNote
CLAbyte (1)Application Identifier0x80/0xE0
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
0x6700Wrong Length
0x6982Empty buffer
0x6983Output buffer too small
0x6A80Data Invalid
0x6985Conditions not satisfied
0x6986Command not allowed
0x6B00Invalid P1/P2
0x6D00INS not supported
0x6E00CLA not supported
0x6F00Unknown
0x9000Success
0x9001Busy

Command definition

INS_GET_VERSION

Command

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

Response

FieldTypeContentNote
TESTbyte (1)Test Mode0xFF means test mode is enabled
MAJORbyte (1)Version Major
MINORbyte (1)Version Minor
PATCHbyte (1)Version Patch
LOCKEDbyte (1)Device is locked
TARGET IDbyte (4)Target ID
SW1-SW2byte (2)Return codesee list of return codes

INS_GET_WALLET_ID

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x01
P1byte (1)Request User confirmationNo = 0
P2byte (1)Parameter 2ignored
Lbyte (1)Bytes in payloadignored

Response

FieldTypeContentNote
WALLET_IDbyte (6)Wallet ID
SW1-SW2byte (2)Return codesee list of return codes

INS_GET_PUBLIC_KEY

Command

If the HRPLen is 0, then the default HRP of 'avax' is used. If the ChainIDLen is 0, then the default ChainID of 32 zero bytes (P-Chain's)

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x02
P1byte (1)Request User confirmationNo = 0
P2byte (1)ignored
Lbyte (1)Bytes in payload(depends)
HRPLenbyte (1)Length of HRP0 to 24
HRPbyte (HRPLen)HRP?
ChainIDLenbyte (1)Length of ChainID0 OR 32
ChainIDbyte (ChainIDLen)ChainID?
PathNbyte (1)Number of path components? (typically 4, up to 6)
Path[0]byte (4)Derivation Path Data0x8000002c
Path[1]byte (4)Derivation Path Data0x80002328
Path[2]byte (4)Derivation Path Data?
Path[3]byte (4)Derivation Path Data?
Path[4]byte (4)Derivation Path Data?
Path[5]byte (4)Derivation Path Data?

Response

FieldTypeContentNote
PK_LENbyte (1)Bytes in PKEY
PKEYbyte (??)Public key bytesCompressed public key
PKEY_HASHbyte (20)Public key hashRipemd160(Sha256(PKEY))
ADDRbyte (??)AddressCB58 encoded address
SW1-SW2byte (2)Return codesee list of return codes

INS_GET_EXTENDED_PUBLIC_KEY

Command

If the HRPLen is 0, then the default HRP of 'avax' is used. If the ChainIDLen is 0, then the default ChainID of 32 zero bytes (P-Chain's)

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x03
P1byte (1)Request User confirmationNo = 0
P2byte (1)ignored
Lbyte (1)Bytes in payload(depends)
HRPLenbyte (1)Length of HRP0 to 24
HRPbyte (HRPLen)HRP?
ChainIDLenbyte (1)Length of ChainID0 OR 32
ChainIDbyte (ChainIDLen)ChainID?
PathNbyte (1)Number of path components? (typically 4, up to 6)
Path[0]byte (4)Derivation Path Data0x8000002c
Path[1]byte (4)Derivation Path Data0x80002328
Path[2]byte (4)Derivation Path Data?
Path[3]byte (4)Derivation Path Data?
Path[4]byte (4)Derivation Path Data?
Path[5]byte (4)Derivation Path Data?

Response

FieldTypeContentNote
PK_LENbyte (1)Bytes in PKEY
PKEYbyte (??)Public key bytesCompressed public key
CHAIN_CODEbyte (32)Chain Code
SW1-SW2byte (2)Return codesee list of return codes

INS_SIGN_HASH

The app includes a protocol to sign the same message multiple times, as described in this instruction.

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x04
P1byte (1)Signature step0 = init
x = next
2 = last
P2byte (1)ignored
Lbyte (1)Bytes in payload(depends)
Init

The first message should contain the root path for the keys to use, as well as the hash to sign.

FieldTypeContentExpected
PathNbyte (1)Number of path components3
Path[0]byte (4)Derivation Path Data0x8000002c
Path[1]byte (4)Derivation Path Data0x80002328
Path[2]byte (4)Derivation Path Data0x80000000
Hashbyte (32)Hash to sign?
Next

The next N messages should contain the last 2 path elements needed to compute the private key

FieldTypeContentExpected
PathNbyte (1)Number of path components2
Path[0]byte (4)Derivation Path Data?
Path[1]byte (4)Derivation Path Data?
Last

Same as next, but also signals the app that no more signatures are to be produced

Response

Other than Init, which just returns a success code, Next and Last have the following response:

FieldTypeContentNote
SIGbyte (65)Signaturesignature
SW1-SW2byte (2)Return codesee list of return codes

INS_SIGN

The app includes a protocol to upload a large payload in multiple messages, as described in this instruction.

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x05
P1byte (1)Payload desc0 = init
1 = next
2 = last
P2byte (1)ignored
Lbyte (1)Bytes in payload(depends)

The first packet/chunk includes the root derivation path.

Init
FieldTypeContentExpected
PathNbyte (1)Number of path components3
Path[0]byte (4)Derivation Path Data0x8000002c
Path[1]byte (4)Derivation Path Data0x80002328
Path[2]byte (4)Derivation Path Data?
Add
FieldTypeContentExpected
.........
P1byte (1)Payload desc1
.........
Messagebytespayload

The message payload is expected to be prefixed with a list of change paths, once, in the following format. Any byte after is understood to be part of the message to sign and will be parsed accordingly.

FieldTypeContentExpected
ChangePathNbyte (4)Number of change paths
ChangePathN-1byte (1)Number of path components2
Path[0]byte (4)Derivation Path Data?
Path[1]byte (4)Derivation Path Data?
ChangePathN-2byte (1)Number of path components2
Path[0]byte (4)Derivation Path Data?
Path[1]byte (4)Derivation Path Data
.........
Last

This signals the app that no more data should be received in regards to this payload. This will trigger the UI confirmation flow, storing the confirmed hash for signing later via [INS_SIGN_HASH], skipping the "Init" step.

FieldTypeContentExpected
.........
P1byte (1)Payload desc2
.........
DatabytesRemaining data to sign

Response

FieldTypeContentNote
SW1-SW2byte (2)Return codesee list of return codes

INS_SIGN_MSG

Used to sign an avax personal message. The payload should include the header, please see the avax docs for more information. Uses the protocol to upload a large payload with multiple messages.

Command

FieldTypeContentExpected
CLAbyte (1)Application Identifier0x80
INSbyte (1)Instruction ID0x06
P1byte (1)Payload desc0 = init
1 = next
2 = last
P2byte (1)ignored
Lbyte (1)Bytes in payload(depends)

The first packet/chunk includes the root derivation path.

Init
FieldTypeContentExpected
PathNbyte (1)Number of path components3
Path[0]byte (4)Derivation Path Data0x8000002c
Path[1]byte (4)Derivation Path Data0x80002328
Path[2]byte (4)Derivation Path Data?
Add
FieldTypeContentExpected
.........
P1byte (1)Payload desc1
.........
Messagebytesmessage to sign
Last

This signals the app that no more data should be received in regards to this payload. This will trigger the UI confirmation flow, storing the confirmed hash for signing later via [INS_SIGN_HASH], skipping the "Init" step.

FieldTypeContentExpected
.........
P1byte (1)Payload desc2
.........
DatabytesRemaining data to sign

Response

FieldTypeContentNote
SW1-SW2byte (2)Return codesee list of return codes