Skip to content

hazae41/apdu

Repository files navigation

APDU

Rust-like APDU protocol for TypeScript

npm i @hazae41/apdu

Node Package 📦

Features

Current features

  • 100% TypeScript and ESM
  • No external dependencies
  • Rust-like patterns
  • Uses @hazae41/result

Usage

Request and response

import { ApduRequest, ApduResponse } from "@hazae41/apdu"
import { Readable, Writable, Empty } from "@hazae41/binary"

function send(bytes: Uint8Array): Promise<Uint8Array>;

const request = ApduRequest.fromOrThrow({ cla: 0xe0, ins: 0x06, p1: 0x00, p2: 0x00, fragment: new Empty() })
const output = Writable.writeToBytesOrThrow(request)
const input = await send(output)
const response = Readable.readFromBytesOrThrow(ApduResponse, input)

if (response.isOk())
  console.log(response.get())
else
  console.error(response.getErr())