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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- Add Cardano support

## 0.1.0
- Initial release
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ The package is intended as a drop-in TypeScript replacement for the current
- Public errors must keep the `{ code, message, err? }` shape. New public error
behavior should go through `src/internal/errors.ts` and match the compatibility
taxonomy unless there is an explicit reason to extend it.
- BTC, Cardano, and BIP85 methods remain compatibility stubs in this iteration.
Do not document or test them as implemented until their protocol support lands.
- BTC and BIP85 methods remain compatibility stubs in this iteration. Do not
document or test them as implemented until their protocol support lands.
- Cardano xpub, address, and transaction-signing support is implemented; keep
it aligned with the Rust/WASM reference behavior and simulator vectors.

`test/api-snapshot.test.ts` compares the built `dist/index.d.ts` against the
checked-in `test/fixtures/bitbox_api.d.ts` fixture. To refresh the fixture,
Expand Down
78 changes: 69 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ does not require a WASM init step.
## Status

- **Implemented:** WebHID and BitBoxBridge transports, Noise XX pairing,
Ethereum xpub/address/signing methods, antiklepto, transaction data
streaming, EIP-712 typed messages, and `ethIdentifyCase()`.
- **Stubbed with `code: 'unsupported'`:** BTC, Cardano, and BIP85 methods.
- **Stubbed with `code: 'not-implemented'`:** `deviceInfo()`,
`rootFingerprint()`, `showMnemonic()`, and `changePassword()`.
`product()` and `version()` are implemented.
device metadata helpers, Ethereum xpub/address/signing methods, antiklepto,
transaction data streaming, EIP-712 typed messages, `ethIdentifyCase()`,
and Cardano xpub/address/signing methods.
- **Stubbed with `code: 'unsupported'`:** BTC and BIP85 methods.
- **Stubbed with `code: 'not-implemented'`:** `showMnemonic()` and
`changePassword()`.

## Installation

Expand Down Expand Up @@ -49,10 +49,10 @@ import * as bitbox from '@bitboxswiss/bitbox-api';
There is no `init()` call and no WASM loader. Existing Webpack/Vite WASM plugin
configuration from `bitbox-api` is not needed for this package.

The first TypeScript iteration is Ethereum-focused. BTC, Cardano, BIP85, and a
few general device helpers are still present in the public type surface for
BTC and BIP85 methods are still present in the public type surface for
compatibility, but currently reject with typed errors as listed in
[Status](#status).
[Status](#status). Ethereum, Cardano, and the general device helpers listed
above are wired through the TypeScript transport.

## Browser Requirements

Expand Down Expand Up @@ -197,6 +197,66 @@ defaults to `true` when omitted.
await bb02.ethSignTypedMessage(1n, keypath, typedData);
```

## Cardano Usage

Cardano keypaths can be strings such as `m/1852'/1815'/0'/0/0` or number
arrays. Coin amounts, fees, slots, withdrawals, and token amounts are `bigint`
values; byte fields such as transaction hashes, policy IDs, asset names, pool
key hashes, and DRep credential hashes are `Uint8Array`s.

```ts
if (!bb02.cardanoSupported()) {
throw new Error('This BitBox02 does not support Cardano');
}

const paymentKeypath = "m/1852'/1815'/0'/0/0";
const stakeKeypath = "m/1852'/1815'/0'/2/0";

const xpubs = await bb02.cardanoXpubs(["m/1852'/1815'/0'"]);
const address = await bb02.cardanoAddress(
'mainnet',
{
pkhSkh: {
keypathPayment: paymentKeypath,
keypathStake: stakeKeypath,
},
},
true,
);
```

Cardano transaction signing returns Shelley witnesses. Public keys and
signatures are plain `number[]` arrays, matching the runtime shape of the old
WASM package.

```ts
const result = await bb02.cardanoSignTransaction({
network: 'mainnet',
inputs: [
{
keypath: paymentKeypath,
prevOutHash: hexToBytes('59864ee73ca5d91098a32b3ce9811bac1996dcbaefa6b6247dcaafb5779c2538'),
prevOutIndex: 0,
},
],
outputs: [
{
encodedAddress: address,
value: 1_000_000n,
},
],
fee: 170_499n,
ttl: 41_115_811n,
certificates: [],
withdrawals: [],
validityIntervalStart: 41_110_811n,
allowZeroTTL: false,
tagCborSets: false,
});

console.log(result.shelleyWitnesses);
```

## Typed Errors

All public API entry points reject with, or can be normalized to, this shape:
Expand Down
6 changes: 6 additions & 0 deletions sandbox/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from 'react';
import * as bitbox from '@bitboxswiss/bitbox-api';
import './App.css';

import { Cardano } from './Cardano';
import { Ethereum } from './Ethereum';
import { General } from './General';
import { ErrorNotification } from './ErrorNotification';
Expand Down Expand Up @@ -93,6 +94,11 @@ function App() {
<Ethereum bb02={bb02} />
</Accordion>
)}
{bb02.cardanoSupported() && (
<Accordion title="Cardano">
<Cardano bb02={bb02} />
</Accordion>
)}
</div>
);
}
Expand Down
Loading
Loading