Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/publish npm #4

Merged
merged 8 commits into from
Sep 25, 2024
Merged
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
File renamed without changes.
File renamed without changes.
82 changes: 41 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For a smooth and quick integration:
#### Table of Contents

* [bippath](#bippath)
* [Btc](#btc)
* [Acre](#acre)
* [Parameters](#parameters)
* [Examples](#examples)
* [getWalletXpub](#getwalletxpub)
Expand All @@ -55,7 +55,7 @@ For a smooth and quick integration:
* [Parameters](#parameters-8)
* [getTrustedInputBIP143](#gettrustedinputbip143)
* [Parameters](#parameters-9)
* [BtcNew](#btcnew)
* [AcreBtcNew](#acrebtcnew)
* [getWalletXpub](#getwalletxpub-1)
* [Parameters](#parameters-10)
* [getWalletPublicKey](#getwalletpublickey-1)
Expand All @@ -68,7 +68,7 @@ For a smooth and quick integration:
* [Parameters](#parameters-14)
* [descrTemplFrom](#descrtemplfrom)
* [Parameters](#parameters-15)
* [BtcOld](#btcold)
* [AcreBtcOld](#acrebtcold)
* [getWalletPublicKey](#getwalletpublickey-2)
* [Parameters](#parameters-16)
* [Examples](#examples-7)
Expand Down Expand Up @@ -130,9 +130,9 @@ which are commonly used in hierarchical deterministic (HD) wallets.
It includes functions to convert BIP32 paths to and from different formats,
extract components from extended public keys (xpubs), and manipulate path elements.

### Btc
### Acre

Bitcoin API.
Acre app API.

#### Parameters

Expand All @@ -143,8 +143,8 @@ Bitcoin API.
#### Examples

```javascript
import Btc from "@blooo/hw-app-acre:";
const btc = new Btc({ transport, currency: "bitcoin" });
import Acre from "@blooo/hw-app-acre:";
const acre = new Acre({ transport, currency: "bitcoin" });
```

#### getWalletXpub
Expand Down Expand Up @@ -181,8 +181,8 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
##### Examples

```javascript
btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**&#x20;
Expand All @@ -199,7 +199,7 @@ You can sign a message according to the Bitcoin Signature format and retrieve v,
##### Examples

```javascript
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
acre.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
var v = result['v'] + 27 + 4;
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
console.log("Signature : " + signature);
Expand Down Expand Up @@ -239,7 +239,7 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction
##### Examples

```javascript
btc.createTransaction({
acre.createTransaction({
inputs: [ [tx1, 1] ],
associatedKeysets: ["0'/0/0"],
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
Expand Down Expand Up @@ -267,7 +267,7 @@ To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransactio
##### Examples

```javascript
btc.signP2SHTransaction({
acre.signP2SHTransaction({
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
associatedKeysets: ["0'/0/0"],
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
Expand All @@ -290,7 +290,7 @@ For each UTXO included in your transaction, create a transaction object from the
##### Examples

```javascript
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
```

Returns **[Transaction](#transaction)** the transaction object deserialized from the raw hexadecimal transaction
Expand All @@ -306,8 +306,8 @@ Serialize a transaction's outputs to hexadecimal
##### Examples

```javascript
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex');
```

Returns **[Buffer](https://nodejs.org/api/buffer.html)**&#x20;
Expand Down Expand Up @@ -338,25 +338,23 @@ Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;

### BtcNew
### AcreBtcNew

This class implements the same interface as BtcOld (formerly
named Btc), but interacts with Bitcoin hardware app version 2.1.0+
which uses a totally new APDU protocol. This new
protocol is documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
This class implements the same interface as AcreBtcOld (formerly
named Btc), but interacts with Acre hardware app from version 1.0.0
which uses the same APDU protocol as the Bitcoin app version 2.1.0+.
This protocol is documented at
<https://github.com/blooo-io/app-acre/blob/develop/doc/acre.md>

Since the interface must remain compatible with BtcOld, the methods
Since the interface must remain compatible with AcreBtcOld, the methods
of this class are quite clunky, because it needs to adapt legacy
input data into the PSBT process. In the future, a new interface should
be developed that exposes PSBT to the outer world, which would render
a much cleaner implementation.
input data into the PSBT process.

#### getWalletXpub

This is a new method that allow users to get an xpub at a standard path.
Standard paths are described at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description>
<https://github.com/blooo-io/app-acre/blob/develop/doc/acre.md#description>

This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
M/44'/N'/x'/\*\*
Expand Down Expand Up @@ -409,7 +407,7 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/

#### createPaymentTransaction

Build and sign a transaction. See Btc.createPaymentTransaction for
Build and sign a transaction. See Acre.createPaymentTransaction for
details on how to use this method.

This method will convert the legacy arguments, CreateTransactionArg, into
Expand Down Expand Up @@ -455,7 +453,7 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
### descrTemplFrom

This function returns a descriptor template based on the address format.
See <https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md> for details of
See <https://github.com/blooo-io/app-acre/blob/develop/doc/wallet.md> for details of
the bitcoin descriptor template.

#### Parameters
Expand All @@ -464,9 +462,11 @@ the bitcoin descriptor template.

Returns **DefaultDescriptorTemplate**&#x20;

### BtcOld
### AcreBtcOld

This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0
This old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 .
It is never used by Acre, that is based on the latest Bitcoin nano app (2.1.0+).
This class is kept for compatibility purposes.

#### getWalletPublicKey

Expand All @@ -489,8 +489,8 @@ This Bitcoin old API is compatible with versions of the Bitcoin nano app that ar
##### Examples

```javascript
btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**&#x20;
Expand Down Expand Up @@ -525,7 +525,7 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction
##### Examples

```javascript
btc.createTransaction({
acre.createTransaction({
inputs: [ [tx1, 1] ],
associatedKeysets: ["0'/0/0"],
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
Expand Down Expand Up @@ -658,7 +658,7 @@ Returns **[Buffer](https://nodejs.org/api/buffer.html)** The output key
### AppClient

This class encapsulates the APDU protocol documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
<https://github.com/blooo-io/app-acre/blob/develop/doc/acre.md>

#### Parameters

Expand Down Expand Up @@ -696,17 +696,17 @@ The reason for this is the limited amount of memory available to the app,
so it can't always store the full psbt in memory.

The signing process is documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#sign_psbt>
<https://github.com/blooo-io/app-acre/blob/develop/doc/acre.md#sign_psbt>

#### Parameters

* `psbt` **[PsbtV2](#psbtv2)**&#x20;

### Merkle

This class implements the merkle tree used by Ledger Bitcoin app v2+,
This class implements the merkle tree used by Ledger Acre app,
which is documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md>
<https://github.com/blooo-io/app-acre/blob/develop/doc/merkle.md>

#### Parameters

Expand All @@ -716,7 +716,7 @@ which is documented at
### MerkleMap

This implements "Merkelized Maps", documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md#merkleized-maps>
<https://github.com/blooo-io/app-acre/blob/develop/doc/merkle.md#merkleized-maps>

A merkelized map consist of two merkle trees, one for the keys of
a map and one for the values of the same map, thus the two merkle
Expand All @@ -736,7 +736,7 @@ how to construct output scripts from keys. A "Wallet Policy" consists
of a "Descriptor Template" and a list of "keys". A key is basically
a serialized BIP32 extended public key with some added derivation path
information. This is documented at
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/wallet.md>
<https://github.com/blooo-io/app-acre/blob/develop/doc/wallet.md>

#### Parameters

Expand Down Expand Up @@ -829,8 +829,8 @@ complemantary fields as needed in the future.
#### Examples

```javascript
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex');
```

Returns **[Buffer](https://nodejs.org/api/buffer.html)**&#x20;
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
collectCoverage: true,
testPathIgnorePatterns: ["packages/*/lib-es", "packages/*/lib"],
coveragePathIgnorePatterns: ["packages/create-dapp"],
testMatch: ["**/tests/newops/BtcNew.test.ts"],
testMatch: ["**/tests/newops/AcreBtcNew.test.ts"],
passWithNoTests: true,
// collectCoverageFrom: ["packages/**/src/*.ts"],
rootDir: __dirname,
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blooo/hw-app-acre",
"version": "1.0.0",
"version": "1.0.1",
"description": "Ledger Hardware Wallet Acre Application API",
"keywords": [
"Ledger",
Expand All @@ -23,9 +23,9 @@
"publishConfig": {
"access": "public"
},
"main": "lib/Btc.js",
"module": "lib-es/Btc.js",
"types": "lib/Btc.d.ts",
"main": "lib/Acre.js",
"module": "lib-es/Acre.js",
"types": "lib/Acre.d.ts",
"typesVersions": {
"*": {
"lib/*": [
Expand All @@ -36,7 +36,7 @@
],
"*": [
"lib/*",
"lib/Btc.d.ts"
"lib/Acre.d.ts"
]
}
},
Expand All @@ -54,15 +54,15 @@
"default": "./lib-es/*.js"
},
".": {
"require": "./lib/Btc.js",
"default": "./lib-es/Btc.js"
"require": "./lib/Acre.js",
"default": "./lib-es/Acre.js"
},
"./package.json": "./package.json"
},
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/hw-transport": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/hw-transport": "6.31.3",
"@ledgerhq/logs": "6.12.0",
"bip32-path": "^0.4.2",
"bitcoinjs-lib": "^5.2.0",
"bs58": "^4.0.1",
Expand All @@ -76,8 +76,8 @@
"varuint-bitcoin": "1.1.2"
},
"devDependencies": {
"@ledgerhq/hw-transport-mocker": "workspace:^",
"@ledgerhq/hw-transport-node-speculos": "workspace:^",
"@ledgerhq/hw-transport-mocker": "6.29.3",
"@ledgerhq/hw-transport-node-speculos": "6.29.3",
"@types/jest": "^29.5.10",
"@types/node": "^20.8.10",
"axios": "^0.25.0",
Expand Down
Loading
Loading