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: npm package publish #3

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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.
24 changes: 11 additions & 13 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](#btc)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc ?

* [Parameters](#parameters)
* [Examples](#examples)
* [getWalletXpub](#getwalletxpub)
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 btc = new Acre({ transport, currency: "bitcoin" });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

```

#### getWalletXpub
Expand Down Expand Up @@ -341,16 +341,14 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
### BtcNew
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is it BtcNew in Acre contexte?


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>
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
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

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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/Btc.ts → src/Acre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import { signP2SHTransaction } from "./signP2SHTransaction";
import { checkIsBtcLegacy, getAppAndVersion } from "./getAppAndVersion";

/**
* @class Btc
* @class Acre
* @description Bitcoin API.
* @param transport The transport layer used for communication.
* @param scrambleKey This parameter is deprecated and no longer needed.
* @param currency The currency to use, defaults to "bitcoin".
* @example
* import Btc from "@blooo/hw-app-acre:";
* const btc = new Btc({ transport, currency: "bitcoin" });
* import Acre from "@blooo/hw-app-acre:";
* const btc = new Acre({ transport, currency: "bitcoin" });
*/

export default class Btc {
export default class Acre {
// Transport instance
private _transport: Transport;
// The specific implementation used, determined by the nano app and its version.
Expand Down
2 changes: 1 addition & 1 deletion src/BtcNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class BtcNew {
}

/**
* 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
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import Btc from "./Btc";
export default Btc;
import Acre from "./Acre";
export default Acre;
6 changes: 3 additions & 3 deletions tests/Btc.integration.test.ts.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Transport from "@ledgerhq/hw-transport";
import SpeculosTransport from "@ledgerhq/hw-transport-node-speculos";
import { getXpubComponents } from "../src/bip32";
import Btc from "../src/Btc";
import Acre from "../src/Acre";
import BtcNew from "../src/BtcNew";
import { compressPublicKey } from "../src/compressPublicKey";
import { AppClient } from "../src/newops/appClient";
Expand Down Expand Up @@ -155,9 +155,9 @@ async function transport(): Promise<SpeculosTransport> {
async function impl(
variant: "old" | "new",
transport: Transport
): Promise<Btc | BtcNew> {
): Promise<Acre | BtcNew> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btc

if (variant === "old") {
return new Btc(transport);
return new Acre(transport);
}
const client = new AppClient(transport);
const btc = new BtcNew(client);
Expand Down
18 changes: 9 additions & 9 deletions tests/Btc.test.ts.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
openTransportReplayer,
RecordStore,
} from "@ledgerhq/hw-transport-mocker";
import Btc from "../src/Btc";
import Acre from "../src/Acre";

test("btc.getWalletXpub", async () => {
/*
Expand Down Expand Up @@ -120,7 +120,7 @@ ascii(1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb)
`)
);
// This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app
const btc = new Btc({ transport, currency: "oldbitcoin" });
const btc = new Acre({ transport, currency: "oldbitcoin" });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const result = await btc.getWalletXpub({
path: "44'/0'/17'",
xpubVersion: 0x043587cf, // mainnet
Expand All @@ -138,7 +138,7 @@ test("btc.getWalletPublicKey", async () => {
`)
);
// This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app
const btc = new Btc({ transport, currency: "oldbitcoin" });
const btc = new Acre({ transport, currency: "oldbitcoin" });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const result = await btc.getWalletPublicKey("44'/0'/0'/0");
expect(result).toEqual({
bitcoinAddress: "13KE6TffArLh4fVM6uoQzvsYq5vwetJcVM",
Expand Down Expand Up @@ -187,7 +187,7 @@ test("btc 2", async () => {
`)
);
// This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app
const btc = new Btc({ transport, currency: "oldbitcoin" });
const btc = new Acre({ transport, currency: "oldbitcoin" });
const tx1 = btc.splitTransaction(
"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"
);
Expand Down Expand Up @@ -241,7 +241,7 @@ test("btc 3", async () => {
<= 3045022100b5b1813992282b9a1fdd957b9751d79dc21018abc6586336e272212cc89cfe84022053765a1da0bdb5a0631a9866f1fd4c583589d5188b11cfa302fc20cd2611a71e019000
`)
);
const btc = new Btc({ transport });
const btc = new Acre({ transport });
const tx1 = btc.splitTransaction(
"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"
);
Expand Down Expand Up @@ -272,7 +272,7 @@ test("btc 4", async () => {
<= 3045022100e32b32b8a6b4228155ba4d1a536d8fed9900606663fbbf4ea420ed8e944f9c18022053c97c74d2f6d8620d060584dc7886f5f3003684bb249508eb7066215172281a9000
`)
);
const btc = new Btc({ transport });
const btc = new Acre({ transport });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const result = await btc.signMessage(
"44'/0'/0'/0",
Buffer.from("test").toString("hex")
Expand Down Expand Up @@ -324,7 +324,7 @@ test("btc seg multi", async () => {
`)
);
// This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app
const btc = new Btc({ transport, currency: "oldbitcoin" });
const btc = new Acree({ transport, currency: "oldbitcoin" });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const tx1 = btc.splitTransaction(
"0100000000010130992c1559a43de1457f23380fefada09124d22594bbeb46ab6e9356e8407d39010000001716001417507f91a6594df7367a0561e4d3df376a829e1fffffffff02c03b47030000000017a9142397c9bb7a3b8a08368a72b3e58c7bb850555792875f810acf0900000017a914813a2e6c7538f0d0afbdeb5db38608804f5d76ab8702483045022100e09ca8a5357623438daee5b7804e73c9209de7c645efd405f13f83420157c48402207d3e4a30f362e062e361967c7afdd45e7f21878a067b661a6635669e620f99910121035606550fd51f6b063b69dc92bd182934a34463f773222743f300d3c7fd3ae47300000000",
true
Expand Down Expand Up @@ -373,7 +373,7 @@ test("btc sign p2sh seg", async () => {
<= 3045022100932934ee326c19c81b72fb03cec0fb79ff980a8076639f77c7edec35bd59da1e02205e4030e8e0fd2405f6db2fe044c49d3f191adbdc0e05ec7ed4dcc4c6fe7310e5019000
`)
);
const btc = new Btc({ transport });
const btc = new Acre({ transport });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const tx1 = btc.splitTransaction(
"0100000001d3a05cd6e15582f40e68bb8b1559dc9e5b3e4f9f34d92c1217dc8c3355bc844e010000008a47304402207ab1a4768cbb036d4bce3c4a294c13cc5ae6076fc7bedce88c62aa80ae366da702204f8fea6923f8df36315c0c26cb42d8d7ab52ca4736776816e10d6ce51906d0600141044289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34cec320a0565fb7caf11b1ca2f445f9b7b012dda5718b3cface369ee3a034ded6ffffffff02102700000000000017a9141188cc3c265fbc01a025fc8adec9823effd0cef187185f9265170100001976a9140ae1441568d0d293764a347b191025c51556cecd88ac00000000",
true
Expand Down Expand Up @@ -406,7 +406,7 @@ test("signMessage", async () => {
<= 314402205eac720be544d3959a760d9bfd6a0e7c86d128fd1030038f06d85822608804e20220385d83273c9d03c469596292fb354b07d193034f83c2633a4c1f057838e12a5b9000
`)
);
const btc = new Btc({ transport });
const btc = new Acre({ transport });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btc

const res = await btc.signMessage(
"44'/0'/0'/0/0",
Buffer.from("foobar").toString("hex")
Expand Down
8 changes: 4 additions & 4 deletions tests/newops/integrationtools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import Transport from "@ledgerhq/hw-transport";
import bs58check from "bs58check";
import Btc from "../../src/Btc";
import Acre from "../../src/Acre";
import BtcNew from "../../src/BtcNew";
import { BufferWriter } from "../../src/buffertools";
import { CreateTransactionArg } from "../../src/createTransaction";
Expand All @@ -19,7 +19,7 @@ export async function runSignTransaction(
): Promise<string> {
const btcNew = new BtcNew(client);
// btc is needed to perform some functions like splitTransaction.
const btc = new Btc({ transport });
const btc = new Acre({ transport });
const accountType = getAccountType(testTx.vin[0], btc);
const additionals: string[] = [];
if (accountType == StandardPurpose.p2wpkh) {
Expand Down Expand Up @@ -129,7 +129,7 @@ function getSignature(testTxInput: CoreInput, accountType: StandardPurpose): Buf
throw new Error();
}

function getAccountType(coreInput: CoreInput, btc: Btc): StandardPurpose {
function getAccountType(coreInput: CoreInput, btc: Acre): StandardPurpose {
const spentTx = spentTxs[coreInput.txid];
if (!spentTx) {
throw new Error("Spent tx " + coreInput.txid + " unavailable.");
Expand Down Expand Up @@ -158,7 +158,7 @@ export function creatDummyXpub(pubkey: Buffer): string {
return bs58check.encode(xpubDecoded);
}

function createInput(coreInput: CoreInput, btc: Btc): [Transaction, number, string | null, number] {
function createInput(coreInput: CoreInput, btc: Acre): [Transaction, number, string | null, number] {
const spentTx = spentTxs[coreInput.txid];
if (!spentTx) {
throw new Error("Spent tx " + coreInput.txid + " unavailable.");
Expand Down
Loading
Loading