@ledgerhq/hw-app-hedera 1.0.1-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +9 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +21 -0
- package/README.md +53 -0
- package/jest.config.ts +6 -0
- package/lib/Hedera.d.ts +26 -0
- package/lib/Hedera.d.ts.map +1 -0
- package/lib/Hedera.js +88 -0
- package/lib/Hedera.js.map +1 -0
- package/lib-es/Hedera.d.ts +26 -0
- package/lib-es/Hedera.d.ts.map +1 -0
- package/lib-es/Hedera.js +82 -0
- package/lib-es/Hedera.js.map +1 -0
- package/package.json +54 -0
- package/src/Hedera.ts +91 -0
- package/tsconfig.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @ledgerhq/hw-app-hedera
|
|
2
|
+
|
|
3
|
+
## 1.0.1-nightly.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#8118](https://github.com/LedgerHQ/ledger-live/pull/8118) [`17d52ce`](https://github.com/LedgerHQ/ledger-live/commit/17d52ce37dd642a1d01aac2268e1b9623dc8a260) Thanks [@Wozacosta](https://github.com/Wozacosta)! - Creation of coin-hedera package
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Ledger https://www.ledger.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[GitHub](https://github.com/LedgerHQ/ledger-live/),
|
|
2
|
+
[Ledger Devs Discord](https://developers.ledger.com/discord-pro),
|
|
3
|
+
[Developer Portal](https://developers.ledger.com/)
|
|
4
|
+
|
|
5
|
+
## @ledgerhq/hw-app-hedera
|
|
6
|
+
|
|
7
|
+
Ledger Hardware Wallet Hedera JavaScript bindings.
|
|
8
|
+
|
|
9
|
+
***
|
|
10
|
+
|
|
11
|
+
## Are you adding Ledger support to your software wallet?
|
|
12
|
+
|
|
13
|
+
You may be using this package to communicate with the Hedera Nano App.
|
|
14
|
+
|
|
15
|
+
For a smooth and quick integration:
|
|
16
|
+
|
|
17
|
+
* See the developers’ documentation on the [Developer Portal](https://developers.ledger.com/docs/transport/overview/) and
|
|
18
|
+
* Go on [Discord](https://developers.ledger.com/discord-pro/) to chat with developer support and the developer community.
|
|
19
|
+
|
|
20
|
+
***
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
25
|
+
|
|
26
|
+
#### Table of Contents
|
|
27
|
+
|
|
28
|
+
* [Hedera](#hedera)
|
|
29
|
+
* [Parameters](#parameters)
|
|
30
|
+
* [getPublicKey](#getpublickey)
|
|
31
|
+
* [Parameters](#parameters-1)
|
|
32
|
+
|
|
33
|
+
### Hedera
|
|
34
|
+
|
|
35
|
+
Hedera BOLOS API
|
|
36
|
+
|
|
37
|
+
#### Parameters
|
|
38
|
+
|
|
39
|
+
* `transport` **Transport** 
|
|
40
|
+
* `scrambleKey` (optional, default `"BOIL"`)
|
|
41
|
+
|
|
42
|
+
#### getPublicKey
|
|
43
|
+
|
|
44
|
+
Get a Hedera public key for a given BIP-32 path.
|
|
45
|
+
|
|
46
|
+
Note that this does not return an address, nor is an account
|
|
47
|
+
address derivable from a public key on the Hedera network.
|
|
48
|
+
|
|
49
|
+
##### Parameters
|
|
50
|
+
|
|
51
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP-32 format
|
|
52
|
+
|
|
53
|
+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** the public key
|
package/jest.config.ts
ADDED
package/lib/Hedera.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
/** Hedera BOLOS API */
|
|
4
|
+
export default class Hedera {
|
|
5
|
+
transport: Transport;
|
|
6
|
+
constructor(transport: Transport, scrambleKey?: string);
|
|
7
|
+
/**
|
|
8
|
+
* Get a Hedera public key for a given BIP-32 path.
|
|
9
|
+
*
|
|
10
|
+
* Note that this does not return an address, nor is an account
|
|
11
|
+
* address derivable from a public key on the Hedera network.
|
|
12
|
+
*
|
|
13
|
+
* @param path a path in BIP-32 format
|
|
14
|
+
* @return the public key
|
|
15
|
+
*/
|
|
16
|
+
getPublicKey(path: string): Promise<string>;
|
|
17
|
+
signTransaction(transaction: Uint8Array): Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize a BIP path to a data buffer, intended for
|
|
20
|
+
* consumption by the Hedera BOLOS.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
_serializePath(path: number[]): Buffer;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=Hedera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hedera.d.ts","sourceRoot":"","sources":["../src/Hedera.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAepD,uBAAuB;AACvB,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAS;IAMtD;;;;;;;;OAQG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB3C,eAAe,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBnE;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;CASvC"}
|
package/lib/Hedera.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
16
|
+
const bip32_path_1 = __importDefault(require("bip32-path"));
|
|
17
|
+
const CLA = 0xe0;
|
|
18
|
+
const INS = {
|
|
19
|
+
GET_PUBLIC_KEY: 0x02,
|
|
20
|
+
SIGN_TRANSACTION: 0x04,
|
|
21
|
+
};
|
|
22
|
+
const STATUS = {
|
|
23
|
+
OK: 0x9000,
|
|
24
|
+
USER_CANCEL: 0x6985,
|
|
25
|
+
};
|
|
26
|
+
/** Hedera BOLOS API */
|
|
27
|
+
class Hedera {
|
|
28
|
+
constructor(transport, scrambleKey = "BOIL") {
|
|
29
|
+
this.transport = transport;
|
|
30
|
+
transport.decorateAppAPIMethods(this, ["getPublicKey"], scrambleKey);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a Hedera public key for a given BIP-32 path.
|
|
34
|
+
*
|
|
35
|
+
* Note that this does not return an address, nor is an account
|
|
36
|
+
* address derivable from a public key on the Hedera network.
|
|
37
|
+
*
|
|
38
|
+
* @param path a path in BIP-32 format
|
|
39
|
+
* @return the public key
|
|
40
|
+
*/
|
|
41
|
+
getPublicKey(path) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
44
|
+
const serializedPath = this._serializePath(bipPath);
|
|
45
|
+
const p1 = 0x01;
|
|
46
|
+
const p2 = 0x00;
|
|
47
|
+
const response = yield this.transport.send(CLA, INS.GET_PUBLIC_KEY, p1, p2, serializedPath);
|
|
48
|
+
const returnCodeBytes = response.slice(-2);
|
|
49
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
50
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
51
|
+
throw new errors_1.UserRefusedAddress();
|
|
52
|
+
}
|
|
53
|
+
return response.slice(0, 32).toString("hex");
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// TODO: the BOLOS app does not support anything but index #0 for signing transactions
|
|
57
|
+
signTransaction(transaction) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const payload = Buffer.alloc(4 + transaction.length);
|
|
60
|
+
payload.writeUInt32LE(0);
|
|
61
|
+
payload.fill(transaction, 4);
|
|
62
|
+
const p1 = 0x00;
|
|
63
|
+
const p2 = 0x00;
|
|
64
|
+
const response = yield this.transport.send(CLA, INS.SIGN_TRANSACTION, p1, p2, payload);
|
|
65
|
+
const returnCodeBytes = response.slice(-2);
|
|
66
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
67
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
68
|
+
throw new errors_1.UserRefusedOnDevice();
|
|
69
|
+
}
|
|
70
|
+
return response.slice(0, -2);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Serialize a BIP path to a data buffer, intended for
|
|
75
|
+
* consumption by the Hedera BOLOS.
|
|
76
|
+
*
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
_serializePath(path) {
|
|
80
|
+
const data = Buffer.alloc(1 + path.length * 4);
|
|
81
|
+
path.forEach((segment, index) => {
|
|
82
|
+
data.writeUInt32BE(segment, 1 + index * 4);
|
|
83
|
+
});
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.default = Hedera;
|
|
88
|
+
//# sourceMappingURL=Hedera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hedera.js","sourceRoot":"","sources":["../src/Hedera.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAA2E;AAE3E,4DAAiC;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C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
/** Hedera BOLOS API */
|
|
4
|
+
export default class Hedera {
|
|
5
|
+
transport: Transport;
|
|
6
|
+
constructor(transport: Transport, scrambleKey?: string);
|
|
7
|
+
/**
|
|
8
|
+
* Get a Hedera public key for a given BIP-32 path.
|
|
9
|
+
*
|
|
10
|
+
* Note that this does not return an address, nor is an account
|
|
11
|
+
* address derivable from a public key on the Hedera network.
|
|
12
|
+
*
|
|
13
|
+
* @param path a path in BIP-32 format
|
|
14
|
+
* @return the public key
|
|
15
|
+
*/
|
|
16
|
+
getPublicKey(path: string): Promise<string>;
|
|
17
|
+
signTransaction(transaction: Uint8Array): Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize a BIP path to a data buffer, intended for
|
|
20
|
+
* consumption by the Hedera BOLOS.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
_serializePath(path: number[]): Buffer;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=Hedera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hedera.d.ts","sourceRoot":"","sources":["../src/Hedera.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAepD,uBAAuB;AACvB,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAS;IAMtD;;;;;;;;OAQG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB3C,eAAe,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBnE;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;CASvC"}
|
package/lib-es/Hedera.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { UserRefusedAddress, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
11
|
+
import BIPPath from "bip32-path";
|
|
12
|
+
const CLA = 0xe0;
|
|
13
|
+
const INS = {
|
|
14
|
+
GET_PUBLIC_KEY: 0x02,
|
|
15
|
+
SIGN_TRANSACTION: 0x04,
|
|
16
|
+
};
|
|
17
|
+
const STATUS = {
|
|
18
|
+
OK: 0x9000,
|
|
19
|
+
USER_CANCEL: 0x6985,
|
|
20
|
+
};
|
|
21
|
+
/** Hedera BOLOS API */
|
|
22
|
+
export default class Hedera {
|
|
23
|
+
constructor(transport, scrambleKey = "BOIL") {
|
|
24
|
+
this.transport = transport;
|
|
25
|
+
transport.decorateAppAPIMethods(this, ["getPublicKey"], scrambleKey);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get a Hedera public key for a given BIP-32 path.
|
|
29
|
+
*
|
|
30
|
+
* Note that this does not return an address, nor is an account
|
|
31
|
+
* address derivable from a public key on the Hedera network.
|
|
32
|
+
*
|
|
33
|
+
* @param path a path in BIP-32 format
|
|
34
|
+
* @return the public key
|
|
35
|
+
*/
|
|
36
|
+
getPublicKey(path) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const bipPath = BIPPath.fromString(path).toPathArray();
|
|
39
|
+
const serializedPath = this._serializePath(bipPath);
|
|
40
|
+
const p1 = 0x01;
|
|
41
|
+
const p2 = 0x00;
|
|
42
|
+
const response = yield this.transport.send(CLA, INS.GET_PUBLIC_KEY, p1, p2, serializedPath);
|
|
43
|
+
const returnCodeBytes = response.slice(-2);
|
|
44
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
45
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
46
|
+
throw new UserRefusedAddress();
|
|
47
|
+
}
|
|
48
|
+
return response.slice(0, 32).toString("hex");
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// TODO: the BOLOS app does not support anything but index #0 for signing transactions
|
|
52
|
+
signTransaction(transaction) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const payload = Buffer.alloc(4 + transaction.length);
|
|
55
|
+
payload.writeUInt32LE(0);
|
|
56
|
+
payload.fill(transaction, 4);
|
|
57
|
+
const p1 = 0x00;
|
|
58
|
+
const p2 = 0x00;
|
|
59
|
+
const response = yield this.transport.send(CLA, INS.SIGN_TRANSACTION, p1, p2, payload);
|
|
60
|
+
const returnCodeBytes = response.slice(-2);
|
|
61
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
62
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
63
|
+
throw new UserRefusedOnDevice();
|
|
64
|
+
}
|
|
65
|
+
return response.slice(0, -2);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Serialize a BIP path to a data buffer, intended for
|
|
70
|
+
* consumption by the Hedera BOLOS.
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
_serializePath(path) {
|
|
75
|
+
const data = Buffer.alloc(1 + path.length * 4);
|
|
76
|
+
path.forEach((segment, index) => {
|
|
77
|
+
data.writeUInt32BE(segment,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AAc;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAE/C,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;YAC9B,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/hw-app-hedera",
|
|
3
|
+
"version": "1.0.1-nightly.0",
|
|
4
|
+
"description": "Ledger Hardware Wallet Hedera Application API",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"hbar",
|
|
9
|
+
"Hedera",
|
|
10
|
+
"Hardware Wallet"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-app-hedera",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"main": "lib/Hedera.js",
|
|
24
|
+
"module": "lib-es/Hedera.js",
|
|
25
|
+
"types": "lib/Hedera.d.ts",
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"bip32-path": "^0.4.2",
|
|
29
|
+
"@ledgerhq/hw-transport": "^6.31.4",
|
|
30
|
+
"@ledgerhq/errors": "^6.19.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jest": "^29.5.10",
|
|
34
|
+
"@types/node": "^20.8.10",
|
|
35
|
+
"documentation": "14.0.2",
|
|
36
|
+
"jest": "^29.7.0",
|
|
37
|
+
"rimraf": "^4.4.1",
|
|
38
|
+
"source-map-support": "^0.5.21",
|
|
39
|
+
"ts-jest": "^29.1.1",
|
|
40
|
+
"ts-node": "^10.4.0",
|
|
41
|
+
"@ledgerhq/hw-transport-mocker": "^6.29.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "rimraf lib lib-es",
|
|
45
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
46
|
+
"prewatch": "pnpm build",
|
|
47
|
+
"watch": "tsc --watch",
|
|
48
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
49
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
50
|
+
"lint:fix": "pnpm lint --fix",
|
|
51
|
+
"test": "jest",
|
|
52
|
+
"unimported": "unimported"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/Hedera.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { UserRefusedAddress, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
2
|
+
import type Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import BIPPath from "bip32-path";
|
|
4
|
+
|
|
5
|
+
const CLA = 0xe0;
|
|
6
|
+
|
|
7
|
+
const INS = {
|
|
8
|
+
GET_PUBLIC_KEY: 0x02,
|
|
9
|
+
SIGN_TRANSACTION: 0x04,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const STATUS = {
|
|
13
|
+
OK: 0x9000,
|
|
14
|
+
USER_CANCEL: 0x6985,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Hedera BOLOS API */
|
|
18
|
+
export default class Hedera {
|
|
19
|
+
transport: Transport;
|
|
20
|
+
|
|
21
|
+
constructor(transport: Transport, scrambleKey = "BOIL") {
|
|
22
|
+
this.transport = transport;
|
|
23
|
+
|
|
24
|
+
transport.decorateAppAPIMethods(this, ["getPublicKey"], scrambleKey);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get a Hedera public key for a given BIP-32 path.
|
|
29
|
+
*
|
|
30
|
+
* Note that this does not return an address, nor is an account
|
|
31
|
+
* address derivable from a public key on the Hedera network.
|
|
32
|
+
*
|
|
33
|
+
* @param path a path in BIP-32 format
|
|
34
|
+
* @return the public key
|
|
35
|
+
*/
|
|
36
|
+
async getPublicKey(path: string): Promise<string> {
|
|
37
|
+
const bipPath = BIPPath.fromString(path).toPathArray();
|
|
38
|
+
const serializedPath = this._serializePath(bipPath);
|
|
39
|
+
|
|
40
|
+
const p1 = 0x01;
|
|
41
|
+
const p2 = 0x00;
|
|
42
|
+
|
|
43
|
+
const response = await this.transport.send(CLA, INS.GET_PUBLIC_KEY, p1, p2, serializedPath);
|
|
44
|
+
|
|
45
|
+
const returnCodeBytes = response.slice(-2);
|
|
46
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
47
|
+
|
|
48
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
49
|
+
throw new UserRefusedAddress();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return response.slice(0, 32).toString("hex");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO: the BOLOS app does not support anything but index #0 for signing transactions
|
|
56
|
+
async signTransaction(transaction: Uint8Array): Promise<Uint8Array> {
|
|
57
|
+
const payload = Buffer.alloc(4 + transaction.length);
|
|
58
|
+
payload.writeUInt32LE(0);
|
|
59
|
+
payload.fill(transaction, 4);
|
|
60
|
+
|
|
61
|
+
const p1 = 0x00;
|
|
62
|
+
const p2 = 0x00;
|
|
63
|
+
|
|
64
|
+
const response = await this.transport.send(CLA, INS.SIGN_TRANSACTION, p1, p2, payload);
|
|
65
|
+
|
|
66
|
+
const returnCodeBytes = response.slice(-2);
|
|
67
|
+
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];
|
|
68
|
+
|
|
69
|
+
if (returnCode === STATUS.USER_CANCEL) {
|
|
70
|
+
throw new UserRefusedOnDevice();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return response.slice(0, -2);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Serialize a BIP path to a data buffer, intended for
|
|
78
|
+
* consumption by the Hedera BOLOS.
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
_serializePath(path: number[]): Buffer {
|
|
83
|
+
const data = Buffer.alloc(1 + path.length * 4);
|
|
84
|
+
|
|
85
|
+
path.forEach((segment, index) => {
|
|
86
|
+
data.writeUInt32BE(segment, 1 + index * 4);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
}
|