Skip to content

Commit 958c63a

Browse files
authored
Merge pull request #23 from cosmos/sign_with_hrp
add HRP to sign command
2 parents 00c4b49 + 737b551 commit 958c63a

12 files changed

+42
-47
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2018 - 2022 ZondaX AG
189+
Copyright 2018 - 2023 Zondax AG
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README-npm.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,27 @@
33
![zondax](docs/zondax_light.png)
44

55
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6-
[![Main](https://github.com/Zondax/ledger-cosmos-js/workflows/Main/badge.svg)](https://github.com/Zondax/ledger-cosmos-js/actions?query=workflow%3AMain)
7-
[![npm version](https://badge.fury.io/js/%40zondax%2Fledger-cosmos-js.svg)](https://badge.fury.io/js/%40zondax%2Fledger-cosmos-js)
8-
6+
[![Main](https://github.com/cosmos/ledger-cosmos-js/workflows/Main/badge.svg)](https://github.com/cosmos/ledger-cosmos-js/actions?query=workflow%3AMain)
7+
[![npm version](https://badge.fury.io/js/%40cosmos%2Fledger-cosmos-js.svg)](https://badge.fury.io/js/%40cosmos%2Fledger-cosmos-js)
98

109
This package provides a basic client library to communicate with a Tendermint/Cosmos App running in a Ledger Nano S/S+/X devices
1110

1211
We recommend using the npmjs package in order to receive updates/fixes.
1312

14-
1513
# Available commands
1614

17-
| Operation | Response | Command |
18-
| ---------- | ---------------- | ----------------------- |
19-
| getVersion | app version | --------------- |
20-
| publicKey | pubkey | path (legacy command) |
21-
| getAddressAndPubKey | pubkey + address | path + ( showInDevice ) |
22-
| showAddressAndPubKey | signed message | path |
23-
| appInfo | name, version, flags, etc | --------------- |
24-
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
25-
| sign | signed message | path + message |
26-
15+
| Operation | Response | Command |
16+
| -------------------- | --------------------------- | --------------------------- |
17+
| getVersion | app version | --------------- |
18+
| publicKey | pubkey | path (legacy command) |
19+
| getAddressAndPubKey | pubkey + address | path + ( showInDevice ) |
20+
| showAddressAndPubKey | signed message | path |
21+
| appInfo | name, version, flags, etc | --------------- |
22+
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
23+
| sign | signed message | path + message + (HRP) |
2724

2825
getAddress command requires that you set the derivation path (account, change, index) and has an option parameter to display the address on the device. By default, it will retrieve the information without user confirmation.
2926

30-
3127
# Testing with real devices
3228

3329
It is possible to test this package with a real Ledger Nano device. To accomplish that, you will need to follow these steps:

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44
![zondax_dark](docs/zondax_dark.png#gh-dark-mode-only)
55

66
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7-
[![Main](https://github.com/Zondax/ledger-cosmos-js/workflows/Main/badge.svg)](https://github.com/Zondax/ledger-cosmos-js/actions?query=workflow%3AMain)
8-
[![npm version](https://badge.fury.io/js/%40zondax%2Fledger-cosmos-js.svg)](https://badge.fury.io/js/%40zondax%2Fledger-cosmos-js)
9-
7+
[![Main](https://github.com/cosmos/ledger-cosmos-js/workflows/Main/badge.svg)](https://github.com/cosmos/ledger-cosmos-js/actions?query=workflow%3AMain)
8+
[![npm version](https://badge.fury.io/js/%40cosmos%2Fledger-cosmos-js.svg)](https://badge.fury.io/js/%40cosmos%2Fledger-cosmos-js)
109

1110
This package provides a basic client library to communicate with a Tendermint/Cosmos App running in a Ledger Nano S/S+/X devices
1211

1312
We recommend using the npmjs package in order to receive updates/fixes.
1413

15-
1614
# Available commands
1715

18-
| Operation | Response | Command |
19-
| ---------- | ---------------- | ----------------------- |
20-
| getVersion | app version | --------------- |
21-
| publicKey | pubkey | path (legacy command) |
22-
| getAddressAndPubKey | pubkey + address | path + ( showInDevice ) |
23-
| showAddressAndPubKey | signed message | path |
24-
| appInfo | name, version, flags, etc | --------------- |
25-
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
26-
| sign | signed message | path + message |
27-
16+
| Operation | Response | Command |
17+
| -------------------- | --------------------------- | --------------------------- |
18+
| getVersion | app version | --------------- |
19+
| publicKey | pubkey | path (legacy command) |
20+
| getAddressAndPubKey | pubkey + address | path + ( showInDevice ) |
21+
| showAddressAndPubKey | signed message | path |
22+
| appInfo | name, version, flags, etc | --------------- |
23+
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
24+
| sign | signed message | path + message + (HRP) |
2825

2926
getAddress command requires that you set the derivation path (account, change, index) and has an option parameter to display the address on the device. By default, it will retrieve the information without user confirmation.
3027

31-
3228
# Testing with real devices
3329

3430
It is possible to test this package with a real Ledger Nano device. To accomplish that, you will need to follow these steps:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@zondax/ledger-cosmos-js",
3-
"author": "ZondaX AG",
3+
"author": "Zondax AG",
44
"license": "Apache-2.0",
5-
"version": "3.0.1",
5+
"version": "3.0.3",
66
"description": "Node API for Cosmos App (Ledger Nano S/S+/X)",
77
"main": "./dist/index.js",
88
"typings": "./dist/index.d.ts",

src/commandsV1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023 Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/commandsV2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023 Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023 Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/cosmosApp.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023w Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,18 +71,19 @@ export class CosmosApp {
7171
}
7272
}
7373

74-
async signGetChunks(path: number[], buffer: Buffer) {
74+
async prepareChunks(path: number[], buffer: Buffer, hrp: string | undefined) {
7575
const serializedPath = await this.serializePath(path)
76+
const firstChunk = hrp === undefined ? serializedPath : Buffer.concat([serializedPath, CosmosApp.serializeHRP(hrp)])
7677

7778
const chunks = []
78-
chunks.push(serializedPath)
79+
chunks.push(firstChunk)
7980

8081
for (let i = 0; i < buffer.length; i += CHUNK_SIZE) {
8182
let end = i + CHUNK_SIZE
8283
if (i > buffer.length) {
8384
end = buffer.length
8485
}
85-
chunks.push(buffer.slice(i, end))
86+
chunks.push(buffer.subarray(i, end))
8687
}
8788

8889
return chunks
@@ -220,7 +221,9 @@ export class CosmosApp {
220221
.then((serializedPath: Buffer) => {
221222
const data = Buffer.concat([CosmosApp.serializeHRP(hrp), serializedPath])
222223
return this.transport
223-
.send(CLA, INS.GET_ADDR_SECP256K1, showInDevice ? P1_VALUES.SHOW_ADDRESS_IN_DEVICE : P1_VALUES.ONLY_RETRIEVE, 0, data, [ERROR_CODE.NoError])
224+
.send(CLA, INS.GET_ADDR_SECP256K1, showInDevice ? P1_VALUES.SHOW_ADDRESS_IN_DEVICE : P1_VALUES.ONLY_RETRIEVE, 0, data, [
225+
ERROR_CODE.NoError,
226+
])
224227
.then((response: any) => {
225228
const errorCodeData = response.slice(-2)
226229
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]
@@ -257,8 +260,8 @@ export class CosmosApp {
257260
}
258261
}
259262

260-
async sign(path: number[], buffer: Buffer, txType = P2_VALUES.JSON) {
261-
return this.signGetChunks(path, buffer).then(chunks => {
263+
async sign(path: number[], buffer: Buffer, hrp: string | undefined, txType = P2_VALUES.JSON) {
264+
return this.prepareChunks(path, buffer, hrp).then(chunks => {
262265
return this.signSendChunk(1, chunks.length, chunks[0], txType).then(async response => {
263266
let result = {
264267
return_code: response.return_code,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023 Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

tests/basic_integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** ******************************************************************************
2-
* (c) 2018 - 2022 Zondax AG
2+
* (c) 2018 - 2023 Zondax AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)