@ledgerhq/hw-app-algorand 6.19.0 → 6.25.1-alpha.3

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/README.md CHANGED
@@ -22,7 +22,7 @@ Ledger Hardware Wallet Algorand JavaScript bindings.
22
22
 
23
23
  ### Algorand
24
24
 
25
- Cosmos API
25
+ Algorand API
26
26
 
27
27
  #### Parameters
28
28
 
@@ -37,7 +37,7 @@ const algo = new Algorand(transport)
37
37
 
38
38
  #### getAddress
39
39
 
40
- get Algorajt address for a given BIP 32 path.
40
+ get Algorant address for a given BIP 32 path.
41
41
 
42
42
  ##### Parameters
43
43
 
@@ -47,7 +47,7 @@ get Algorajt address for a given BIP 32 path.
47
47
  ##### Examples
48
48
 
49
49
  ```javascript
50
- cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
50
+ cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
51
51
  ```
52
52
 
53
53
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), address: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** an object with a publicKey, address and (optionally) chainCode
package/lib/Algorand.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  ********************************************************************************/
18
18
  import type Transport from "@ledgerhq/hw-transport";
19
19
  /**
20
- * Cosmos API
20
+ * Algorand API
21
21
  *
22
22
  * @example
23
23
  * import Algorand from "@ledgerhq/hw-app-algorand";
@@ -27,12 +27,12 @@ export default class Algorand {
27
27
  transport: Transport;
28
28
  constructor(transport: Transport);
29
29
  /**
30
- * get Algorajt address for a given BIP 32 path.
30
+ * get Algorant address for a given BIP 32 path.
31
31
  * @param path a path in BIP 32 format
32
32
  * @option boolDisplay optionally enable or not the display
33
33
  * @return an object with a publicKey, address and (optionally) chainCode
34
34
  * @example
35
- * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
35
+ * cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
36
36
  */
37
37
  getAddress(path: string, boolDisplay?: boolean): Promise<{
38
38
  publicKey: string;
package/lib/Algorand.js CHANGED
@@ -56,7 +56,7 @@ var CLA = 0x80;
56
56
  var INS_GET_PUBLIC_KEY = 0x03;
57
57
  var INS_SIGN_MSGPACK = 0x08;
58
58
  /**
59
- * Cosmos API
59
+ * Algorand API
60
60
  *
61
61
  * @example
62
62
  * import Algorand from "@ledgerhq/hw-app-algorand";
@@ -68,12 +68,12 @@ var Algorand = /** @class */ (function () {
68
68
  transport.decorateAppAPIMethods(this, ["getAddress", "sign"], "ALGO");
69
69
  }
70
70
  /**
71
- * get Algorajt address for a given BIP 32 path.
71
+ * get Algorant address for a given BIP 32 path.
72
72
  * @param path a path in BIP 32 format
73
73
  * @option boolDisplay optionally enable or not the display
74
74
  * @return an object with a publicKey, address and (optionally) chainCode
75
75
  * @example
76
- * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
76
+ * cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
77
77
  */
78
78
  Algorand.prototype.getAddress = function (path, boolDisplay) {
79
79
  var bipPath = bip32_path_1["default"].fromString(path).toPathArray();
@@ -17,7 +17,7 @@
17
17
  ********************************************************************************/
18
18
  import type Transport from "@ledgerhq/hw-transport";
19
19
  /**
20
- * Cosmos API
20
+ * Algorand API
21
21
  *
22
22
  * @example
23
23
  * import Algorand from "@ledgerhq/hw-app-algorand";
@@ -27,12 +27,12 @@ export default class Algorand {
27
27
  transport: Transport;
28
28
  constructor(transport: Transport);
29
29
  /**
30
- * get Algorajt address for a given BIP 32 path.
30
+ * get Algorant address for a given BIP 32 path.
31
31
  * @param path a path in BIP 32 format
32
32
  * @option boolDisplay optionally enable or not the display
33
33
  * @return an object with a publicKey, address and (optionally) chainCode
34
34
  * @example
35
- * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
35
+ * cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
36
36
  */
37
37
  getAddress(path: string, boolDisplay?: boolean): Promise<{
38
38
  publicKey: string;
@@ -51,7 +51,7 @@ var CLA = 0x80;
51
51
  var INS_GET_PUBLIC_KEY = 0x03;
52
52
  var INS_SIGN_MSGPACK = 0x08;
53
53
  /**
54
- * Cosmos API
54
+ * Algorand API
55
55
  *
56
56
  * @example
57
57
  * import Algorand from "@ledgerhq/hw-app-algorand";
@@ -63,12 +63,12 @@ var Algorand = /** @class */ (function () {
63
63
  transport.decorateAppAPIMethods(this, ["getAddress", "sign"], "ALGO");
64
64
  }
65
65
  /**
66
- * get Algorajt address for a given BIP 32 path.
66
+ * get Algorant address for a given BIP 32 path.
67
67
  * @param path a path in BIP 32 format
68
68
  * @option boolDisplay optionally enable or not the display
69
69
  * @return an object with a publicKey, address and (optionally) chainCode
70
70
  * @example
71
- * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
71
+ * cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
72
72
  */
73
73
  Algorand.prototype.getAddress = function (path, boolDisplay) {
74
74
  var bipPath = BIPPath.fromString(path).toPathArray();
@@ -0,0 +1,151 @@
1
+ /********************************************************************************
2
+ * Ledger Node JS API
3
+ * (c) 2017-2018 Ledger
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ ********************************************************************************/
17
+ //@flow
18
+
19
+ import type Transport from "@ledgerhq/hw-transport";
20
+ import BIPPath from "bip32-path";
21
+ import { UserRefusedOnDevice } from "@ledgerhq/errors";
22
+ const CHUNK_SIZE = 250;
23
+
24
+ // const P1_FIRST = 0x00;
25
+ const P1_MORE = 0x80;
26
+ const P1_WITH_ACCOUNT_ID = 0x01;
27
+ const P2_LAST = 0x00;
28
+ const P2_MORE = 0x80;
29
+
30
+ const SW_OK = 0x9000;
31
+ const SW_CANCEL = 0x6986;
32
+
33
+ const P1_WITH_REQUEST_USER_APPROVAL = 0x80;
34
+
35
+ // algo spec
36
+ const CLA = 0x80;
37
+ const INS_GET_PUBLIC_KEY = 0x03;
38
+ const INS_SIGN_MSGPACK = 0x08;
39
+
40
+ /**
41
+ * Cosmos API
42
+ *
43
+ * @example
44
+ * import Algorand from "@ledgerhq/hw-app-algorand";
45
+ * const algo = new Algorand(transport)
46
+ */
47
+ export default class Algorand {
48
+ transport: Transport<*>;
49
+
50
+ constructor(transport: Transport<*>) {
51
+ this.transport = transport;
52
+ transport.decorateAppAPIMethods(this, ["getAddress", "sign"], "ALGO");
53
+ }
54
+
55
+ /**
56
+ * get Algorajt address for a given BIP 32 path.
57
+ * @param path a path in BIP 32 format
58
+ * @option boolDisplay optionally enable or not the display
59
+ * @return an object with a publicKey, address and (optionally) chainCode
60
+ * @example
61
+ * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
62
+ */
63
+ getAddress(
64
+ path: string,
65
+ boolDisplay?: boolean
66
+ ): Promise<{ publicKey: string, address: string }> {
67
+ const bipPath = BIPPath.fromString(path).toPathArray();
68
+
69
+ const buf = Buffer.alloc(4);
70
+ buf.writeUInt32BE(bipPath[2], 0);
71
+
72
+ return this.transport
73
+ .send(
74
+ CLA,
75
+ INS_GET_PUBLIC_KEY,
76
+ boolDisplay ? P1_WITH_REQUEST_USER_APPROVAL : 0,
77
+ 0,
78
+ buf,
79
+ [SW_OK]
80
+ )
81
+ .then((response) => {
82
+ const publicKey = Buffer.from(response.slice(0, 32)).toString("hex");
83
+ return {
84
+ publicKey,
85
+ };
86
+ });
87
+ }
88
+
89
+ foreach<T, A>(arr: T[], callback: (T, number) => Promise<A>): Promise<A[]> {
90
+ function iterate(index, array, result) {
91
+ if (index >= array.length) {
92
+ return result;
93
+ } else
94
+ return callback(array[index], index).then(function (res) {
95
+ result.push(res);
96
+ return iterate(index + 1, array, result);
97
+ });
98
+ }
99
+ return Promise.resolve().then(() => iterate(0, arr, []));
100
+ }
101
+
102
+ async sign(
103
+ path: string,
104
+ message: string
105
+ ): Promise<{ signature: null | Buffer }> {
106
+ const bipPath = BIPPath.fromString(path).toPathArray();
107
+
108
+ const buf = Buffer.alloc(4);
109
+ buf.writeUInt32BE(bipPath[2], 0);
110
+
111
+ const chunks = [];
112
+ const buffer = Buffer.concat([buf, Buffer.from(message, "hex")]);
113
+
114
+ for (let i = 0; i < buffer.length; i += CHUNK_SIZE) {
115
+ let end = i + CHUNK_SIZE;
116
+ if (i > buffer.length) {
117
+ end = buffer.length;
118
+ }
119
+ chunks.push(buffer.slice(i, end));
120
+ }
121
+
122
+ let response = {};
123
+
124
+ return this.foreach(chunks, (data, j) =>
125
+ this.transport
126
+ .send(
127
+ CLA,
128
+ INS_SIGN_MSGPACK,
129
+ j === 0 ? P1_WITH_ACCOUNT_ID : P1_MORE,
130
+ j + 1 === chunks.length ? P2_LAST : P2_MORE,
131
+ data,
132
+ [SW_OK, SW_CANCEL]
133
+ )
134
+ .then((apduResponse) => (response = apduResponse))
135
+ ).then(() => {
136
+ const errorCodeData = response;
137
+ if (errorCodeData === 0x6986) {
138
+ throw new UserRefusedOnDevice();
139
+ }
140
+
141
+ let signature = null;
142
+ if (response.length > 0) {
143
+ signature = response.slice(0, response.length);
144
+ }
145
+
146
+ return {
147
+ signature: signature,
148
+ };
149
+ });
150
+ }
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/hw-app-algorand",
3
- "version": "6.19.0",
3
+ "version": "6.25.1-alpha.3+eb669e17",
4
4
  "description": "Ledger Hardware Wallet Algorand Application API",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -28,7 +28,7 @@
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
30
  "@ledgerhq/errors": "^6.10.0",
31
- "@ledgerhq/hw-transport": "^6.19.0",
31
+ "@ledgerhq/hw-transport": "^6.25.1-alpha.3+eb669e17",
32
32
  "bip32-path": "^0.4.2",
33
33
  "hi-base32": "^0.5.1",
34
34
  "js-sha512": "^0.8.0",
@@ -40,5 +40,5 @@
40
40
  "watch": "bash ../../script/watch.sh",
41
41
  "doc": "bash ../../script/doc.sh"
42
42
  },
43
- "gitHead": "37f11a943eabfca3e506deb2f494d3d886731292"
43
+ "gitHead": "eb669e17dd87d3ab568beab1f9a5ddb1a2536e83"
44
44
  }
package/src/Algorand.ts CHANGED
@@ -32,7 +32,7 @@ const CLA = 0x80;
32
32
  const INS_GET_PUBLIC_KEY = 0x03;
33
33
  const INS_SIGN_MSGPACK = 0x08;
34
34
  /**
35
- * Cosmos API
35
+ * Algorand API
36
36
  *
37
37
  * @example
38
38
  * import Algorand from "@ledgerhq/hw-app-algorand";
@@ -48,12 +48,12 @@ export default class Algorand {
48
48
  }
49
49
 
50
50
  /**
51
- * get Algorajt address for a given BIP 32 path.
51
+ * get Algorant address for a given BIP 32 path.
52
52
  * @param path a path in BIP 32 format
53
53
  * @option boolDisplay optionally enable or not the display
54
54
  * @return an object with a publicKey, address and (optionally) chainCode
55
55
  * @example
56
- * cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
56
+ * cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
57
57
  */
58
58
  getAddress(
59
59
  path: string,