@ledgerhq/hw-app-str 6.29.0-windows-certificate.0 → 8.0.0-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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @ledgerhq/hw-app-str@6.28.6 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-str
2
+ > @ledgerhq/hw-app-str@7.0.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-str
3
3
  > tsc && tsc -m ES6 --outDir lib-es
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,15 +1,25 @@
1
1
  # @ledgerhq/hw-app-str
2
2
 
3
- ## 6.29.0-windows-certificate.0
3
+ ## 8.0.0-nightly.0
4
4
 
5
- ### Minor Changes
5
+ ### Major Changes
6
6
 
7
- - [#6596](https://github.com/LedgerHQ/ledger-live/pull/6596) [`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11) Thanks [@KVNLS](https://github.com/KVNLS)! - Upgrade React Native to version 0.73.6
7
+ - [#6923](https://github.com/LedgerHQ/ledger-live/pull/6923) [`782d637`](https://github.com/LedgerHQ/ledger-live/commit/782d637b5fba8c9c9d37609b6ad492f45a4b3737) Thanks [@overcat](https://github.com/overcat)! - Refactor `hw-app-str` and add `signSorobanAuthorization`. Please check the changelog and documentation of "@ledgerhq/hw-app-str" for more information.
8
8
 
9
- ### Patch Changes
9
+ ## 7.0.0
10
+
11
+ ### Major Changes
10
12
 
11
- - Updated dependencies [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11)]:
12
- - @ledgerhq/hw-transport@6.31.0-windows-certificate.0
13
+ - `Str.getPublicKey`'s function signature has changed. Previously, it was `getPublicKey(path: string, boolValidate?: boolean, boolDisplay?: boolean): Promise<{ publicKey: string; raw: Buffer; }>` and now it is `async getPublicKey(path: string, display = false): Promise<{ rawPublicKey: Buffer }>`
14
+ - `Str.signTransaction` will no longer automatically fallback to `Str.signHash`. If you want to sign a hash, you have to call `Str.signHash` directly.
15
+ - Removed the fixed limit on the maximum length of the transaction in `Str.signTransaction`. Currently, if the transaction is too large for the device to handle, `StellarUserRefusedError` will be thrown.
16
+ - Add `Str.signSorobanAuthorization` method to sign Stellar Soroban authorization.
17
+ - `Str.getAppConfiguration` now returns `maxDataSize`, it represents the maximum size of the data that the device can processed.
18
+ - Add error classes for better error handling, check the documentation for more information:
19
+ - `StellarUserRefusedError`
20
+ - `StellarHashSigningNotEnabledError`
21
+ - `StellarDataTooLargeError`
22
+ - `StellarDataParsingFailedError`
13
23
 
14
24
  ## 6.28.6
15
25
 
package/README.md CHANGED
@@ -1,62 +1,14 @@
1
1
  <img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" />
2
2
 
3
- ## Ledger Stellar app API
3
+ [GitHub](https://github.com/LedgerHQ/ledger-live/),
4
+ [Ledger Devs Discord](https://developers.ledger.com/discord-pro),
5
+ [Developer Portal](https://developers.ledger.com/)
4
6
 
5
- ## Usage
7
+ ## @ledgerhq/hw-app-str
6
8
 
9
+ Ledger Hardware Wallet Stellar JavaScript bindings.
7
10
 
8
- ```js
9
- // when using "@ledgerhq/hw-transport-node-hid" library you need to go to
10
- // Settings -> Browser support in ledger stellar app and set this setting to 'No'
11
- import Transport from "@ledgerhq/hw-transport-node-hid";
12
- // import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
13
- import Str from "@ledgerhq/hw-app-str";
14
- import * as StellarSdk from "@stellar/stellar-sdk";
15
-
16
- const getStrAppVersion = async () => {
17
- const transport = await Transport.create();
18
- const str = new Str(transport);
19
- const result = await str.getAppConfiguration();
20
- return result.version;
21
- }
22
- getStrAppVersion().then(v => console.log(v));
23
-
24
- const getStrPublicKey = async () => {
25
- const transport = await Transport.create();
26
- const str = new Str(transport);
27
- const result = await str.getPublicKey("44'/148'/0'");
28
- return result.publicKey;
29
- };
30
- let publicKey;
31
- getStrPublicKey().then(pk => {
32
- console.log(pk);
33
- publicKey = pk;
34
- });
35
-
36
- const signStrTransaction = async (publicKey) => {
37
- const transaction = new StellarSdk.TransactionBuilder({accountId: () => publicKey, sequenceNumber: () => '1234', incrementSequenceNumber: () => null})
38
- .addOperation(StellarSdk.Operation.createAccount({
39
- source: publicKey,
40
- destination: 'GBLYVYCCCRYTZTWTWGOMJYKEGQMTH2U3X4R4NUI7CUGIGEJEKYD5S5OJ', // SATIS5GR33FXKM7HVWZ2UQO33GM66TVORZUEF2HPUQ3J7K634CTOAWQ7
41
- startingBalance: '11.331',
42
- }))
43
- .build();
44
- const transport = await Transport.create();
45
- const str = new Str(transport);
46
- const result = await str.signTransaction("44'/148'/0'", transaction.signatureBase());
47
-
48
- // add signature to transaction
49
- const keyPair = StellarSdk.Keypair.fromPublicKey(publicKey);
50
- const hint = keyPair.signatureHint();
51
- const decorated = new StellarSdk.xdr.DecoratedSignature({hint: hint, signature: result.signature});
52
- transaction.signatures.push(decorated);
53
-
54
- return transaction;
55
- }
56
- signStrTransaction(publicKey).then(transaction => console.log(transaction.toEnvelope().toXDR().toString('base64')));
57
- ```
58
-
59
- ---
11
+ ***
60
12
 
61
13
  ## Are you adding Ledger support to your software wallet?
62
14
 
@@ -64,7 +16,159 @@ You may be using this package to communicate with the Stellar Nano App.
64
16
 
65
17
  For a smooth and quick integration:
66
18
 
67
- - See the developers’ documentation on the [Developer Portal](https://developers.ledger.com/docs/transport/overview/) and
68
- - Go on [Discord](https://developers.ledger.com/discord-pro/) to chat with developer support and the developer community.
19
+ * See the developers’ documentation on the [Developer Portal](https://developers.ledger.com/docs/transport/overview/) and
20
+ * Go on [Discord](https://developers.ledger.com/discord-pro/) to chat with developer support and the developer community.
21
+
22
+ ***
23
+
24
+ ## Errors handling
25
+
26
+ All functions may throw an error, it's important to handle the errors properly.
27
+
28
+ We have written corresponding classes for exceptions that developers should actively handle, you can find them in the [API](#api) section.
29
+
30
+ ***
31
+
32
+ ## API
33
+
34
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
35
+
36
+ #### Table of Contents
37
+
38
+ * [StellarHashSigningNotEnabledError](#stellarhashsigningnotenablederror)
39
+ * [StellarDataParsingFailedError](#stellardataparsingfailederror)
40
+ * [StellarUserRefusedError](#stellaruserrefusederror)
41
+ * [StellarDataTooLargeError](#stellardatatoolargeerror)
42
+ * [Str](#str)
43
+ * [Parameters](#parameters)
44
+ * [Examples](#examples)
45
+ * [getAppConfiguration](#getappconfiguration)
46
+ * [Examples](#examples-1)
47
+ * [getPublicKey](#getpublickey)
48
+ * [Parameters](#parameters-1)
49
+ * [Examples](#examples-2)
50
+ * [signTransaction](#signtransaction)
51
+ * [Parameters](#parameters-2)
52
+ * [Examples](#examples-3)
53
+ * [signSorobanAuthorization](#signsorobanauthorization)
54
+ * [Parameters](#parameters-3)
55
+ * [Examples](#examples-4)
56
+ * [signHash](#signhash)
57
+ * [Parameters](#parameters-4)
58
+ * [Examples](#examples-5)
59
+
60
+ ### StellarHashSigningNotEnabledError
61
+
62
+ Error thrown when hash signing is not enabled on the device.
63
+
64
+ ### StellarDataParsingFailedError
65
+
66
+ Error thrown when data parsing fails.
67
+
68
+ For example, when parsing the transaction fails, this error is thrown.
69
+
70
+ ### StellarUserRefusedError
71
+
72
+ Error thrown when the user refuses the request on the device.
73
+
74
+ ### StellarDataTooLargeError
75
+
76
+ Error thrown when the data is too large to be processed by the device.
77
+
78
+ ### Str
79
+
80
+ Stellar API
81
+
82
+ #### Parameters
83
+
84
+ * `transport` **Transport** a transport for sending commands to a device
85
+ * `scrambleKey` a scramble key (optional, default `"l0v"`)
86
+
87
+ #### Examples
88
+
89
+ ```javascript
90
+ import Str from "@ledgerhq/hw-app-str";
91
+ const str = new Str(transport)
92
+ ```
93
+
94
+ #### getAppConfiguration
95
+
96
+ Get Stellar application configuration.
97
+
98
+ ##### Examples
99
+
100
+ ```javascript
101
+ str.getAppConfiguration().then(o => o.version)
102
+ ```
103
+
104
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{version: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), hashSigningEnabled: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), maxDataSize: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?}>** an object with the application configuration, including the version,
105
+ whether hash signing is enabled, and the maximum data size in bytes that the device can sign.
106
+
107
+ #### getPublicKey
108
+
109
+ Get Stellar raw public key for a given BIP 32 path.
110
+
111
+ ##### Parameters
112
+
113
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
114
+ * `display` if true, the device will ask the user to confirm the address on the device, if false, it will return the raw public key directly (optional, default `false`)
115
+
116
+ ##### Examples
117
+
118
+ ```javascript
119
+ str.getPublicKey("44'/148'/0'").then(o => o.rawPublicKey)
120
+ ```
121
+
122
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{rawPublicKey: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the raw ed25519 public key.
123
+ If you want to convert it to string, you can use [StrKey.encodeEd25519PublicKey](https://stellar.github.io/js-stellar-base/StrKey.html#.encodeEd25519PublicKey)
124
+
125
+ #### signTransaction
126
+
127
+ Sign a Stellar transaction.
128
+
129
+ ##### Parameters
130
+
131
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
132
+ * `transaction` **[Buffer](https://nodejs.org/api/buffer.html)** [signature base](https://stellar.github.io/js-stellar-base/Transaction.html#signatureBase) of the transaction to sign
133
+
134
+ ##### Examples
135
+
136
+ ```javascript
137
+ str.signTransaction("44'/148'/0'", signatureBase).then(o => o.signature)
138
+ ```
139
+
140
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature
141
+
142
+ #### signSorobanAuthorization
143
+
144
+ Sign a Stellar Soroban authorization.
145
+
146
+ ##### Parameters
147
+
148
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
149
+ * `hashIdPreimage` **[Buffer](https://nodejs.org/api/buffer.html)** the [Soroban authorization hashIdPreimage](https://github.com/stellar/stellar-xdr/blob/1a04392432dacc0092caaeae22a600ea1af3c6a5/Stellar-transaction.x#L702-L709) to sign
150
+
151
+ ##### Examples
152
+
153
+ ```javascript
154
+ str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage).then(o => o.signature)
155
+ ```
156
+
157
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature
158
+
159
+ #### signHash
160
+
161
+ Sign a hash.
162
+
163
+ ##### Parameters
164
+
165
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
166
+ * `hash` **[Buffer](https://nodejs.org/api/buffer.html)** the hash to sign
167
+
168
+ ##### Examples
169
+
170
+ ```javascript
171
+ str.signHash("44'/148'/0'", hash).then(o => o.signature)
172
+ ```
69
173
 
70
- ---
174
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the signature
package/lib/Str.d.ts CHANGED
@@ -19,35 +19,48 @@ import type Transport from "@ledgerhq/hw-transport";
19
19
  /**
20
20
  * Stellar API
21
21
  *
22
+ * @param transport a transport for sending commands to a device
23
+ * @param scrambleKey a scramble key
24
+ *
22
25
  * @example
23
26
  * import Str from "@ledgerhq/hw-app-str";
24
27
  * const str = new Str(transport)
25
28
  */
26
29
  export default class Str {
27
- transport: Transport;
30
+ private transport;
28
31
  constructor(transport: Transport, scrambleKey?: string);
32
+ /**
33
+ * Get Stellar application configuration.
34
+ *
35
+ * @returns an object with the application configuration, including the version,
36
+ * whether hash signing is enabled, and the maximum data size in bytes that the device can sign.
37
+ * @example
38
+ * str.getAppConfiguration().then(o => o.version)
39
+ */
29
40
  getAppConfiguration(): Promise<{
30
41
  version: string;
42
+ hashSigningEnabled: boolean;
43
+ maxDataSize?: number;
31
44
  }>;
32
45
  /**
33
- * get Stellar public key for a given BIP 32 path.
46
+ * Get Stellar raw public key for a given BIP 32 path.
47
+ *
34
48
  * @param path a path in BIP 32 format
35
- * @option boolValidate optionally enable key pair validation
36
- * @option boolDisplay optionally enable or not the display
37
- * @return an object with the publicKey (using XLM public key format) and
38
- * the raw ed25519 public key.
49
+ * @param display if true, the device will ask the user to confirm the address on the device, if false, it will return the raw public key directly
50
+ * @return an object with the raw ed25519 public key.
51
+ * If you want to convert it to string, you can use {@link https://stellar.github.io/js-stellar-base/StrKey.html#.encodeEd25519PublicKey StrKey.encodeEd25519PublicKey}
39
52
  * @example
40
- * str.getPublicKey("44'/148'/0'").then(o => o.publicKey)
53
+ * str.getPublicKey("44'/148'/0'").then(o => o.rawPublicKey)
41
54
  */
42
- getPublicKey(path: string, boolValidate?: boolean, boolDisplay?: boolean): Promise<{
43
- publicKey: string;
44
- raw: Buffer;
55
+ getPublicKey(path: string, display?: boolean): Promise<{
56
+ rawPublicKey: Buffer;
45
57
  }>;
46
58
  /**
47
- * sign a Stellar transaction.
59
+ * Sign a Stellar transaction.
60
+ *
48
61
  * @param path a path in BIP 32 format
49
- * @param transaction signature base of the transaction to sign
50
- * @return an object with the signature and the status
62
+ * @param transaction {@link https://stellar.github.io/js-stellar-base/Transaction.html#signatureBase signature base} of the transaction to sign
63
+ * @return an object with the signature
51
64
  * @example
52
65
  * str.signTransaction("44'/148'/0'", signatureBase).then(o => o.signature)
53
66
  */
@@ -55,18 +68,30 @@ export default class Str {
55
68
  signature: Buffer;
56
69
  }>;
57
70
  /**
58
- * sign a Stellar transaction hash.
71
+ * Sign a Stellar Soroban authorization.
72
+ *
59
73
  * @param path a path in BIP 32 format
60
- * @param hash hash of the transaction to sign
74
+ * @param hashIdPreimage the {@link https://github.com/stellar/stellar-xdr/blob/1a04392432dacc0092caaeae22a600ea1af3c6a5/Stellar-transaction.x#L702-L709 Soroban authorization hashIdPreimage} to sign
61
75
  * @return an object with the signature
62
76
  * @example
63
- * str.signHash("44'/148'/0'", hash).then(o => o.signature)
77
+ * str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage).then(o => o.signature)
64
78
  */
65
- signHash(path: string, hash: Buffer): Promise<{
79
+ signSorobanAuthorization(path: string, hashIdPreimage: Buffer): Promise<{
66
80
  signature: Buffer;
67
81
  }>;
68
- signHash_private(path: string, hash: Buffer): Promise<{
82
+ /**
83
+ * Sign a hash.
84
+ *
85
+ * @param path a path in BIP 32 format
86
+ * @param hash the hash to sign
87
+ * @return an object with the signature
88
+ * @example
89
+ * str.signHash("44'/148'/0'", hash).then(o => o.signature)
90
+ */
91
+ signHash(path: string, hash: Buffer): Promise<{
69
92
  signature: Buffer;
70
93
  }>;
94
+ private sendToDevice;
71
95
  }
96
+ export * from "./errors";
72
97
  //# sourceMappingURL=Str.d.ts.map
package/lib/Str.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Str.d.ts","sourceRoot":"","sources":["../src/Str.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;kFAekF;AAClF,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AA4BpD;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAQ;IASrD,mBAAmB,IAAI,OAAO,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAWF;;;;;;;;;OASG;IACH,YAAY,CACV,IAAI,EAAE,MAAM,EACZ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