cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
Connect.ino

Minimal Cryptnox example: open a secure channel and fetch card info.

Minimal Cryptnox example: open a secure channel and fetch card info.Wiring & prerequisites:

  • PN532 NFC reader on SPI, with SS on pin PN532_SS_PIN.
  • A Cryptnox card initialised (the secure channel itself does not need a PIN, but the card must be programmed; use cryptnox init).

What the sketch does in each loop iteration:

  1. Connect to the card and establish the secure channel (CryptnoxWallet::connect).
  2. On success, ask the card for its info (CryptnoxWallet::getCardInfo).
  3. Disconnect.

This sketch never submits a PIN, so it cannot lock the card. It is the safest starting point to validate that the wiring and the secure channel work end to end before moving to VerifyPin or Sign examples.

/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* Copyright (c) 2026 Cryptnox SA
*/
#include <CryptnoxWallet.h>
#include <SPI.h>
#define PN532_SS_PIN (10U)
void setup() {
serialAdapter.begin(115200);
delay(1000); /* Arduino R4: wait for Serial */
SPI.begin();
if (!wallet.begin()) {
serialAdapter.println(F("PN532 init failed"));
while (1);
}
/* Concrete proof the PN532 is up: prints IC chip, firmware version
* and supported NFC features (MIFARE / ISO-DEP / FeliCa). */
nfc.printFirmwareVersion();
}
void loop() {
if (wallet.connect(session)) {
serialAdapter.println(F("Card connected, secure channel established"));
if (wallet.getCardInfo(session, &info)) {
serialAdapter.print(F("Owner name : "));
serialAdapter.println(info.name);
serialAdapter.print(F("Owner email: "));
serialAdapter.println(info.email);
} else {
serialAdapter.println(F("getCardInfo failed (channel error or parse error)"));
}
} else {
serialAdapter.println(F("Card not detected or secure channel failed"));
}
wallet.disconnect(session);
delay(1000);
}
void setup()
Arduino setup function.
CryptnoxWallet wallet(nfc, serialAdapter, cryptoProvider, platform)
PN532Adapter nfc(serialAdapter, PN532_SS, &SPI)
ArduinoLoggerAdapter serialAdapter
ArduinoPlatform platform
ArduinoCryptoProvider cryptoProvider
void loop()
Arduino main loop.
#define PN532_SS_PIN
SPI slave-select (CS) pin connected to the PN532 module.
Definition Connect.ino:31
CW_CryptoProvider implementation for the Arduino UNO R4 (RA4M1).
CW_Logger implementation wrapping Arduino's HardwareSerial.
CW_Platform implementation using Arduino's blocking delay().
High-level interface for interacting with a Cryptnox Hardware Wallet over NFC.
CW_NfcTransport implementation over the Adafruit_PN532 driver.
#define F(string_literal)
Subset of the Cryptnox card info returned by APDU 0x80FA0000.
char name[CW_CARD_NAME_MAX_LEN+1U]
char email[CW_CARD_EMAIL_MAX_LEN+1U]
Holds cryptographic session state for reentrant secure channel operations.
Definition CW_Defs.h:168