Skip to content

Commit

Permalink
Add NOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
roosmaa committed Nov 26, 2018
1 parent f6a95be commit 99a5974
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"NanoCurrency",
"$NANO",
"Banano",
"NOS",
"NanoS",
"Blue",
"Hardware Wallet"
Expand Down
110 changes: 110 additions & 0 deletions src/NOS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/********************************************************************************
* LibNano Ledger JS API
* (c) 2018 Mart Roosmaa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
//@flow

import type Transport from "@ledgerhq/hw-transport";
import type { BlockData } from "./api";
import { BaseAPI, getAddress, signBlock, cacheBlock } from "./api";

/**
* NOS API
*
* @example
* import { NOS } from "hw-app-nano";
* const nos = new NOS(transport);
*/
export default class NOS extends BaseAPI {
constructor(transport: Transport<*>) {
super(transport, {
coinName: "NOS",
addressPrimaryPrefix: "usd_",
addressSecondaryPrefix: "usd_"
});
}

/**
* Get NOS address for the given BIP 32 path.
* @param path a path in BIP 32 format
* @option boolDisplay display the address on the device
* @return an object with a publicKey and address
* @example
* nos.getAddress("44'/229'/840'/0'").then(o => o.address)
*/
async getAddress(
path: string,
boolDisplay?: boolean
): Promise<{|
publicKey: string,
address: string
|}> {
this._assertCorrectCoin();
return await getAddress(this.coin, this.transport, path, boolDisplay);
}

/**
* Generate a signature for a block
* @param path a path of the account in BIP 32 format
* @param blockData block data to hash and sign
*
* @example <caption>Opening an account</caption>
* nos.signBlock("44'/229'/840'/0'", {
* representative: "usd_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k",
* balance: "100000000000000000000000000000000",
* sourceBlock: "06B95C8A7EC4116E5BD907CD6DC65D310E065992A2E1D02F337D1A8308DEBC14"
* }).then(o => o.signature)
*
* @example <caption>Sending funds</caption>
* nos.signBlock("44'/229'/840'/0'", {
* previousBlock: "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948",
* representative: "usd_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k",
* balance: "100000000000000000000000000000000",
* recipient: "usd_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k"
* }).then(o => o.signature)
*/
async signBlock(
path: string,
blockData: BlockData
): Promise<{|
blockHash: string,
signature: string
|}> {
this._assertCorrectCoin();
return signBlock(this.coin, this.transport, path, blockData);
}

/**
* Cache block in Ledger device memory
* @param path a path of the account in BIP 32 format
* @param blockData block data
* @param signature signature (in hex) of the block
*
* @example
* nos.cacheBlock("44'/229'/840'/0'", {
* representative: "usd_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k",
* balance: "100000000000000000000000000000000",
* sourceBlock: "06B95C8A7EC4116E5BD907CD6DC65D310E065992A2E1D02F337D1A8308DEBC14"
* });
*/
async cacheBlock(
path: string,
blockData: BlockData,
signature: string
): Promise<*> {
this._assertCorrectCoin();
return cacheBlock(this.coin, this.transport, path, blockData, signature);
}
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export type { BlockData } from "./api";
export { encodeBalance, decodeBalance } from "./util";
export { default } from "./Nano";
export { default as Banano } from "./Banano";
export { default as NOS } from "./NOS";

0 comments on commit 99a5974

Please sign in to comment.