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

Fix/npm linkability #110

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ inter-compatibility between keystores. Implementing features which
increase complexity and reduce inter-compatibility should be
discouraged.

### Developing locally with another app (ex. [Caravan](https://github.com/unchained-capital/caravan))

If you would like to develop unchained-wallets locally while also developing an app that depends on unchained-wallets, you'll need to do a few steps:

1. Change `"main": "lib/index.js"` in package.json to `"main": "src/index.ts"` This step is temporary while we convert this package to ESM.
1. In the root of this project run `npm link`
1. In the root of the project that depends on this package run `npm link unchained-wallets`

Now when you start up your app, whatever bundler you're using (Vite, Webpack, etc.) should compile this package as well.

### Developing against local Trezor connect

If for some reason you need to use a [local instance of Trezor Connect](https://wiki.trezor.io/Developers_guide:Running_Trezor_Connect_on_localhost)
Expand Down
88 changes: 66 additions & 22 deletions images/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
//
// FIXME there is probably a smart babel-based way to do this.


const fs = require('fs');
const path = require('path');
const imagesDir = path.dirname(__filename);
import { readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
const imagesDir = dirname(__filename);

function base64Data(imagePath) {
const bytes = fs.readFileSync(path.join(imagesDir, imagePath));
return Buffer.from(bytes).toString('base64');
const bytes = readFileSync(join(imagesDir, imagePath));
return Buffer.from(bytes).toString("base64");
}

function mimeType(imagePath) {
Expand All @@ -33,21 +32,66 @@ function imageData(imagePath, label) {

const IMAGES = {
ledger: {
warning: imageData("ledger/warning.png", "Ledger screen displaying a `WARNING!` message."),
derivationPathIsUnusualV1: imageData("ledger/derivationPathIsUnusualV1.png" ,"Ledger screen displaying a message about an 'unusual path'."),
derivationPathV1: imageData("ledger/derivationPathV1.png", "Ledger screen displaying a derivation path."),
rejectIfNotSureV1: imageData("ledger/rejectIfNotSureV1.png", "Ledger screen displaying a prompt about being sure."),
addressScrollV1: imageData("ledger/addressScrollV1.png", "Ledger screen displaying a bitcoin address."),
unusualDerivationBeta: imageData("ledger/unusualDerivationBeta.png", "The derivation path is unusual."),
fullDerivationPathBeta: imageData("ledger/fullDerivationPathBeta.png", "Ledger screen displaying a derivation path."),
rejectIfNotSureBeta: imageData("ledger/rejectIfNotSureBeta.png", "Reject if you're not sure."),
approveDerivationBeta: imageData("ledger/approveDerivationBeta.png", "Approve the derivation path if you are sure."),
derivationPathBeta: imageData("ledger/derivationPathBeta.png", "Ledger screen displaying a derivation path."),
addressClickThroughBeta: imageData("ledger/addressClickThroughBeta.png", "Ledger screen will display your corresponding public key."),
approveAddressBeta: imageData("ledger/approveAddressBeta.png", "Ledger screen asks for your approval."),
exportPublicKeyBeta: imageData("ledger/exportPublicKeyBeta.png", "Ledger screen asking to export public key"),
exportPublicKeyV1: imageData("ledger/exportPublicKeyV1.png", "Ledger screen asking to export public key"),
}
warning: imageData(
"ledger/warning.png",
"Ledger screen displaying a `WARNING!` message."
),
derivationPathIsUnusualV1: imageData(
"ledger/derivationPathIsUnusualV1.png",
"Ledger screen displaying a message about an 'unusual path'."
),
derivationPathV1: imageData(
"ledger/derivationPathV1.png",
"Ledger screen displaying a derivation path."
),
rejectIfNotSureV1: imageData(
"ledger/rejectIfNotSureV1.png",
"Ledger screen displaying a prompt about being sure."
),
addressScrollV1: imageData(
"ledger/addressScrollV1.png",
"Ledger screen displaying a bitcoin address."
),
unusualDerivationBeta: imageData(
"ledger/unusualDerivationBeta.png",
"The derivation path is unusual."
),
fullDerivationPathBeta: imageData(
"ledger/fullDerivationPathBeta.png",
"Ledger screen displaying a derivation path."
),
rejectIfNotSureBeta: imageData(
"ledger/rejectIfNotSureBeta.png",
"Reject if you're not sure."
),
approveDerivationBeta: imageData(
"ledger/approveDerivationBeta.png",
"Approve the derivation path if you are sure."
),
derivationPathBeta: imageData(
"ledger/derivationPathBeta.png",
"Ledger screen displaying a derivation path."
),
addressClickThroughBeta: imageData(
"ledger/addressClickThroughBeta.png",
"Ledger screen will display your corresponding public key."
),
approveAddressBeta: imageData(
"ledger/approveAddressBeta.png",
"Ledger screen asks for your approval."
),
exportPublicKeyBeta: imageData(
"ledger/exportPublicKeyBeta.png",
"Ledger screen asking to export public key"
),
exportPublicKeyV1: imageData(
"ledger/exportPublicKeyV1.png",
"Ledger screen asking to export public key"
),
},
};

fs.writeFileSync(path.join(imagesDir, '../lib/images.js'), "export default " + JSON.stringify(IMAGES) + ";");
writeFileSync(
join(imagesDir, "../lib/images.js"),
`export default ${JSON.stringify(IMAGES)};`
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"build-types": "tsc -p tsconfig.json",
"build-types:watch": "tsc --watch",
"check-types": "tsc -p tsconfig.json --noEmit --emitDeclarationOnly false",
"compile": "babel --extensions .ts,.js -d lib/ src/ && npm run compile-images",
"compile": "babel --extensions .ts,.js -d lib/ src/",
"compile:trezor-dev": "TREZOR_DEV=true babel --extensions .ts,.js --watch -d lib/ src/ && npm run compile-images",
"compile:watch": "babel --watch --extensions .ts,.js -d lib/ src/ && compile-images",
"prepublish": "npm run compile",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,7 @@ export * from "./custom";
export * from "./hermit";
export * from "./ledger";
export * from "./trezor";
export * from "./policy";
import * as MultisigWallet from "./policy";

const MultisigWalletPolicy = MultisigWallet.MultisigWalletPolicy;
export { braidDetailsToWalletConfig, MultisigWalletPolicy };
3 changes: 1 addition & 2 deletions src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export const LEDGER = "ledger";

export const LEDGER_V2 = "ledger_v2";

/* eslint-disable @typescript-eslint/no-var-requires */
const TransportU2F = require("@ledgerhq/hw-transport-u2f").default;
import TransportU2F from "@ledgerhq/hw-transport-u2f";

import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
import LedgerBtc from "@ledgerhq/hw-app-btc";
Expand Down
3 changes: 1 addition & 2 deletions src/trezor.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ import { MULTISIG_ROOT } from "./index";
*/
export const TREZOR = "trezor";

// eslint-disable-next-line
const TrezorConnect = require("@trezor/connect-web").default;
import TrezorConnect from "@trezor/connect-web";

const ADDRESS_SCRIPT_TYPES = {
[P2SH]: "SPENDMULTISIG",
Expand Down
Loading