@ledgerhq/device-signer-kit-solana 1.0.1 → 1.1.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/README.md +148 -356
- package/lib/cjs/api/app-binder/GetAddressDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/GetAddressDeviceActionTypes.js.map +1 -1
- package/lib/cjs/api/app-binder/GetAppConfigurationDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/GetAppConfigurationDeviceActionTypes.js.map +1 -1
- package/lib/cjs/api/app-binder/SignMessageDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignMessageDeviceActionTypes.js.map +1 -1
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +1 -1
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetPubKeyCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetPubKeyCommand.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/GetPubKeyCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetPubKeyCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SignOffChainMessageCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignOffChainMessageCommand.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SignOffChainMessageCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignOffChainMessageCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SignTransactionCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignTransactionCommand.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/utils/SolanaAppErrors.test.js +2 -0
- package/lib/cjs/internal/app-binder/command/utils/SolanaAppErrors.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/utils/SolanaApplicationErrors.js +2 -0
- package/lib/cjs/internal/app-binder/command/utils/SolanaApplicationErrors.js.map +7 -0
- package/lib/cjs/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransactionDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/SendCommandInChunksTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/SendCommandInChunksTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/SendSignDataTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/SendSignDataTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/SendSignMessageTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/SendSignMessageTask.js.map +2 -2
- package/lib/cjs/package.json +4 -3
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js.map +3 -3
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetPubKeyCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/GetPubKeyCommand.js.map +3 -3
- package/lib/esm/internal/app-binder/command/GetPubKeyCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/GetPubKeyCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignOffChainMessageCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SignOffChainMessageCommand.js.map +3 -3
- package/lib/esm/internal/app-binder/command/SignOffChainMessageCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/SignOffChainMessageCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignTransactionCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SignTransactionCommand.js.map +3 -3
- package/lib/esm/internal/app-binder/command/utils/SolanaAppErrors.test.js +2 -0
- package/lib/esm/internal/app-binder/command/utils/SolanaAppErrors.test.js.map +7 -0
- package/lib/esm/internal/app-binder/command/utils/SolanaApplicationErrors.js +2 -0
- package/lib/esm/internal/app-binder/command/utils/SolanaApplicationErrors.js.map +7 -0
- package/lib/esm/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransactionDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/esm/internal/app-binder/task/SendCommandInChunksTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SendCommandInChunksTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/SendSignDataTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SendSignDataTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/SendSignMessageTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SendSignMessageTask.js.map +2 -2
- package/lib/esm/package.json +4 -3
- package/lib/types/api/app-binder/GetAddressDeviceActionTypes.d.ts +2 -1
- package/lib/types/api/app-binder/GetAddressDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/GetAppConfigurationDeviceActionTypes.d.ts +2 -1
- package/lib/types/api/app-binder/GetAppConfigurationDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/SignMessageDeviceActionTypes.d.ts +3 -2
- package/lib/types/api/app-binder/SignMessageDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +3 -2
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts +4 -2
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetPubKeyCommand.d.ts +4 -2
- package/lib/types/internal/app-binder/command/GetPubKeyCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SignOffChainMessageCommand.d.ts +4 -2
- package/lib/types/internal/app-binder/command/SignOffChainMessageCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SignTransactionCommand.d.ts +5 -3
- package/lib/types/internal/app-binder/command/SignTransactionCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/utils/SolanaAppErrors.test.d.ts +2 -0
- package/lib/types/internal/app-binder/command/utils/SolanaAppErrors.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/utils/SolanaApplicationErrors.d.ts +8 -0
- package/lib/types/internal/app-binder/command/utils/SolanaApplicationErrors.d.ts.map +1 -0
- package/lib/types/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.d.ts +2 -1
- package/lib/types/internal/app-binder/device-action/SignMessage/SignMessageDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTransactionDeviceAction.d.ts +2 -1
- package/lib/types/internal/app-binder/device-action/SignTransactionDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SendCommandInChunksTask.d.ts +3 -2
- package/lib/types/internal/app-binder/task/SendCommandInChunksTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SendSignDataTask.d.ts +3 -2
- package/lib/types/internal/app-binder/task/SendSignDataTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SendSignMessageTask.d.ts +3 -1
- package/lib/types/internal/app-binder/task/SendSignMessageTask.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/lib/cjs/internal/app-binder/command/utils/solanaAppError.test.js +0 -2
- package/lib/cjs/internal/app-binder/command/utils/solanaAppError.test.js.map +0 -7
- package/lib/cjs/internal/app-binder/command/utils/solanaAppErrors.js +0 -2
- package/lib/cjs/internal/app-binder/command/utils/solanaAppErrors.js.map +0 -7
- package/lib/esm/internal/app-binder/command/utils/solanaAppError.test.js +0 -2
- package/lib/esm/internal/app-binder/command/utils/solanaAppError.test.js.map +0 -7
- package/lib/esm/internal/app-binder/command/utils/solanaAppErrors.js +0 -2
- package/lib/esm/internal/app-binder/command/utils/solanaAppErrors.js.map +0 -7
- package/lib/types/internal/app-binder/command/utils/solanaAppError.test.d.ts +0 -2
- package/lib/types/internal/app-binder/command/utils/solanaAppError.test.d.ts.map +0 -1
- package/lib/types/internal/app-binder/command/utils/solanaAppErrors.d.ts +0 -8
- package/lib/types/internal/app-binder/command/utils/solanaAppErrors.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
# Ledger Solana Signer Implementation
|
|
2
2
|
|
|
3
|
-
## Introduction
|
|
4
|
-
|
|
5
3
|
This module provides the implementation of the Ledger Solana signer of the Device Management Kit. It enables interaction with the Solana application on a Ledger device including:
|
|
6
4
|
|
|
7
5
|
- Retrieving the Solana address using a given derivation path;
|
|
8
6
|
- Signing a Solana transaction;
|
|
9
7
|
- Signing an offchain message displayed on a Ledger device;
|
|
10
|
-
-
|
|
8
|
+
- Retrieving the app configuration;
|
|
9
|
+
|
|
10
|
+
## 🔹 Index
|
|
11
|
+
|
|
12
|
+
1. [How it works](#-how-it-works)
|
|
13
|
+
2. [Installation](#-installation)
|
|
14
|
+
3. [Initialisation](#-initialisation)
|
|
15
|
+
4. [Use Cases](#-use-cases)
|
|
16
|
+
- [Get Address](#use-case-1-get-address)
|
|
17
|
+
- [Sign Transaction](#use-case-2-sign-transaction)
|
|
18
|
+
- [Sign Message](#use-case-3-sign-message)
|
|
19
|
+
- [Get App Configuration](#use-case-4-get-app-configuration)
|
|
20
|
+
5. [Observable Behavior](#-observable-behavior)
|
|
21
|
+
6. [Example](#-example)
|
|
11
22
|
|
|
12
|
-
|
|
23
|
+
## 🔹 How it works
|
|
13
24
|
|
|
14
25
|
The Ledger Solana Signer utilizes the advanced capabilities of the Ledger device to provide secure operations for end users. It takes advantage of the interface provided by the Device Management Kit to establish communication with the Ledger device and execute various operations. The communication with the Ledger device is performed using [APDU](https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit)s (Application Protocol Data Units), which are encapsulated within the `Command` object. These commands are then organized into tasks, allowing for the execution of complex operations with one or more APDUs. The tasks are further encapsulated within `DeviceAction` objects to handle different real-world scenarios. Finally, the Signer exposes dedicated and independent use cases that can be directly utilized by end users.
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
## 🔹 Installation
|
|
17
28
|
|
|
18
29
|
> **Note:** This module is not standalone; it depends on the [@ledgerhq/device-management-kit](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/packages/device-management-kit) package, so you need to install it first.
|
|
19
30
|
|
|
@@ -23,30 +34,29 @@ To install the `device-signer-kit-solana` package, run the following command:
|
|
|
23
34
|
npm install @ledgerhq/device-signer-kit-solana
|
|
24
35
|
```
|
|
25
36
|
|
|
26
|
-
##
|
|
37
|
+
## 🔹 Initialisation
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
To initialize a Sonala signer instance, you need a Ledger Device Management Kit instance and the ID of the session of the connected device. Use the `SignerSolanaBuilder` along with the [Context Module](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/packages/signer/context-module) by default developed by Ledger:
|
|
39
|
+
To initialise a Solana signer instance, you need a Ledger Device Management Kit instance and the ID of the session of the connected device. Use the `SignerSolanaBuilder` along with the [Context Module](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/packages/signer/context-module) by default developed by Ledger:
|
|
31
40
|
|
|
32
41
|
```typescript
|
|
33
|
-
// Initialize a Solana signer instance
|
|
34
42
|
const signerSolana = new SignerSolanaBuilder({ sdk, sessionId }).build();
|
|
35
43
|
```
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
## 🔹 Use Cases
|
|
38
46
|
|
|
39
47
|
The `SignerSolanaBuilder.build()` method will return a `SignerSolana` instance that exposes 4 dedicated methods, each of which calls an independent use case. Each use case will return an object that contains an observable and a method called `cancel`.
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### Use Case 1: Get Address
|
|
42
52
|
|
|
43
|
-
This method allows users to retrieve the Solana address
|
|
53
|
+
This method allows users to retrieve the Solana address based on a given `derivationPath`.
|
|
44
54
|
|
|
45
55
|
```typescript
|
|
46
56
|
const { observable, cancel } = signerSolana.getAddress(derivationPath, options);
|
|
47
57
|
```
|
|
48
58
|
|
|
49
|
-
**Parameters**
|
|
59
|
+
#### **Parameters**
|
|
50
60
|
|
|
51
61
|
- `derivationPath`
|
|
52
62
|
|
|
@@ -67,100 +77,21 @@ const { observable, cancel } = signerSolana.getAddress(derivationPath, options);
|
|
|
67
77
|
|
|
68
78
|
- `checkOnDevice`: An optional boolean indicating whether user confirmation on the device is required (`true`) or not (`false`).
|
|
69
79
|
|
|
70
|
-
**Returns**
|
|
71
|
-
|
|
72
|
-
- `observable`
|
|
80
|
+
#### **Returns**
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
observable.subscribe({
|
|
78
|
-
next: (state: DeviceActionState) => {
|
|
79
|
-
switch (state.status) {
|
|
80
|
-
case DeviceActionStatus.NotStarted: {
|
|
81
|
-
console.log("The action is not started yet.");
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case DeviceActionStatus.Pending: {
|
|
85
|
-
const {
|
|
86
|
-
intermediateValue: { requiredUserInteraction },
|
|
87
|
-
} = state;
|
|
88
|
-
// Access the intermediate value here, explained below
|
|
89
|
-
console.log(
|
|
90
|
-
"The action is pending and the intermediate value is: ",
|
|
91
|
-
intermediateValue,
|
|
92
|
-
);
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
case DeviceActionStatus.Stopped: {
|
|
96
|
-
console.log("The action has been stopped.");
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case DeviceActionStatus.Completed: {
|
|
100
|
-
const { output } = state;
|
|
101
|
-
// Access the output of the completed action here
|
|
102
|
-
console.log("The action has been completed: ", output);
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case DeviceActionStatus.Error: {
|
|
106
|
-
const { error } = state;
|
|
107
|
-
// Access the error here if occured
|
|
108
|
-
console.log("An error occured during the action: ", error);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
- When the action status is `DeviceActionStatus.Pending`, the state will include an `intermediateValue` object that provides useful information for interaction:
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
const { requiredUserInteraction } = intermediateValue;
|
|
82
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
120
83
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
case UserInteractionRequired.None: {
|
|
130
|
-
// No user action required
|
|
131
|
-
console.log("No user action needed.");
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case UserInteractionRequired.UnlockDevice: {
|
|
135
|
-
// User needs to unlock the device
|
|
136
|
-
console.log("The user needs to unlock the device.");
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case UserInteractionRequired.ConfirmOpenApp: {
|
|
140
|
-
// User needs to confirm on the device to open the app
|
|
141
|
-
console.log("The user needs to confirm on the device to open the app.");
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
default:
|
|
145
|
-
// Type guard to ensure all cases are handled
|
|
146
|
-
const uncaughtUserInteraction: never = requiredUserInteraction;
|
|
147
|
-
console.error(
|
|
148
|
-
"Unhandled user interaction case:",
|
|
149
|
-
uncaughtUserInteraction,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
- When the action status is `DeviceActionStatus.Completed`, the execution result can be accessed through the `output` property in the state. The `output` property is of type `PublicKey` in `base58`.
|
|
84
|
+
```typescript
|
|
85
|
+
type GetAddressCommandResponse = {
|
|
86
|
+
publicKey: string; // Address in base58 format
|
|
87
|
+
};
|
|
88
|
+
```
|
|
155
89
|
|
|
156
|
-
|
|
157
|
-
type PublicKey = string; // address in base58 format
|
|
158
|
-
```
|
|
90
|
+
- `cancel` A function to cancel the action on the Ledger device.
|
|
159
91
|
|
|
160
|
-
|
|
161
|
-
- The function without a return value to cancel the action on the Ledger device.
|
|
92
|
+
---
|
|
162
93
|
|
|
163
|
-
|
|
94
|
+
### Use Case 2: Sign Transaction
|
|
164
95
|
|
|
165
96
|
This method enables users to securely sign transactions using clear signing on Ledger devices.
|
|
166
97
|
|
|
@@ -172,7 +103,7 @@ const { observable, cancel } = signerSolana.signTransaction(
|
|
|
172
103
|
);
|
|
173
104
|
```
|
|
174
105
|
|
|
175
|
-
**Parameters**
|
|
106
|
+
#### **Parameters**
|
|
176
107
|
|
|
177
108
|
- `derivationPath`
|
|
178
109
|
|
|
@@ -196,100 +127,19 @@ const { observable, cancel } = signerSolana.signTransaction(
|
|
|
196
127
|
type TransactionOptions = {};
|
|
197
128
|
```
|
|
198
129
|
|
|
199
|
-
**Returns**
|
|
200
|
-
|
|
201
|
-
- `observable`
|
|
202
|
-
|
|
203
|
-
- An [Observable](https://rxjs.dev/guide/observable) object that contains the [`DeviceActionState`](https://github.com/LedgerHQ/device-sdk-ts/blob/develop/packages/device-management-kit/src/api/device-action/model/DeviceActionState.ts) derived instance which reprensents the operation's state. For example:
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
observable.subscribe({
|
|
207
|
-
next: (state: SignTransactionDAState) => {
|
|
208
|
-
switch (state.status) {
|
|
209
|
-
case DeviceActionStatus.NotStarted: {
|
|
210
|
-
console.log("The action is not started yet.");
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case DeviceActionStatus.Pending: {
|
|
214
|
-
const {
|
|
215
|
-
intermediateValue: { requiredUserInteraction },
|
|
216
|
-
} = state;
|
|
217
|
-
// Access the intermediate value here, explained below
|
|
218
|
-
console.log(
|
|
219
|
-
"The action is pending and the intermediate value is: ",
|
|
220
|
-
intermediateValue,
|
|
221
|
-
);
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
case DeviceActionStatus.Stopped: {
|
|
225
|
-
console.log("The action has been stopped.");
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
case DeviceActionStatus.Completed: {
|
|
229
|
-
const { output } = state;
|
|
230
|
-
// Access the output of the completed action here
|
|
231
|
-
console.log("The action has been completed: ", output);
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
case DeviceActionStatus.Error: {
|
|
235
|
-
const { error } = state;
|
|
236
|
-
// Access the error here if occured
|
|
237
|
-
console.log("An error occured during the action: ", error);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
- When the action status is `DeviceActionStatus.Pending`, the state will include an `intermediateValue` object that provides useful information for interaction:
|
|
130
|
+
#### **Returns**
|
|
246
131
|
|
|
247
|
-
|
|
248
|
-
const { requiredUserInteraction } = intermediateValue;
|
|
249
|
-
|
|
250
|
-
switch (requiredUserInteraction) {
|
|
251
|
-
case UserInteractionRequired.SignTransaction: {
|
|
252
|
-
// User needs to sign the transaction displayed on the device
|
|
253
|
-
console.log(
|
|
254
|
-
"User needs to sign the transaction displayed on the device.",
|
|
255
|
-
);
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
case UserInteractionRequired.None: {
|
|
259
|
-
// No user action required
|
|
260
|
-
console.log("No user action needed.");
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
case UserInteractionRequired.UnlockDevice: {
|
|
264
|
-
// User needs to unlock the device
|
|
265
|
-
console.log("The user needs to unlock the device.");
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case UserInteractionRequired.ConfirmOpenApp: {
|
|
269
|
-
// User needs to confirm on the device to open the app
|
|
270
|
-
console.log("The user needs to confirm on the device to open the app.");
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
default:
|
|
274
|
-
// Type guard to ensure all cases are handled
|
|
275
|
-
const uncaughtUserInteraction: never = requiredUserInteraction;
|
|
276
|
-
console.error(
|
|
277
|
-
"Unhandled user interaction case:",
|
|
278
|
-
uncaughtUserInteraction,
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
```
|
|
132
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
282
133
|
|
|
283
|
-
|
|
134
|
+
```typescript
|
|
135
|
+
type Signature = Uint8Array; // Signed transaction bytes
|
|
136
|
+
```
|
|
284
137
|
|
|
285
|
-
|
|
286
|
-
type Signature = Uint8Array;
|
|
287
|
-
```
|
|
138
|
+
- `cancel` A function to cancel the action on the Ledger device.
|
|
288
139
|
|
|
289
|
-
|
|
290
|
-
- The function without a return value to cancel the action on the Ledger device.
|
|
140
|
+
---
|
|
291
141
|
|
|
292
|
-
|
|
142
|
+
### Use Case 3: Sign Message
|
|
293
143
|
|
|
294
144
|
This method allows users to sign a text string that is displayed on Ledger devices.
|
|
295
145
|
|
|
@@ -300,7 +150,7 @@ const { observable, cancel } = signerSolana.signMessage(
|
|
|
300
150
|
);
|
|
301
151
|
```
|
|
302
152
|
|
|
303
|
-
**Parameters**
|
|
153
|
+
#### **Parameters**
|
|
304
154
|
|
|
305
155
|
- `derivationPath`
|
|
306
156
|
|
|
@@ -314,200 +164,142 @@ const { observable, cancel } = signerSolana.signMessage(
|
|
|
314
164
|
- **Type:** `string`
|
|
315
165
|
- The message to be signed, which will be displayed on the Ledger device.
|
|
316
166
|
|
|
317
|
-
**Returns**
|
|
167
|
+
#### **Returns**
|
|
318
168
|
|
|
319
|
-
- `observable`
|
|
169
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
320
170
|
|
|
321
|
-
|
|
171
|
+
```typescript
|
|
172
|
+
type Signature = Uint8Array; // Signed message bytes
|
|
173
|
+
```
|
|
322
174
|
|
|
323
|
-
|
|
324
|
-
observable.subscribe({
|
|
325
|
-
next: (state: SignPersonalMessageDAState) => {
|
|
326
|
-
switch (state.status) {
|
|
327
|
-
case DeviceActionStatus.NotStarted: {
|
|
328
|
-
console.log("The action is not started yet.");
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
case DeviceActionStatus.Pending: {
|
|
332
|
-
const {
|
|
333
|
-
intermediateValue: { requiredUserInteraction },
|
|
334
|
-
} = state;
|
|
335
|
-
// Access the intermediate value here, explained below
|
|
336
|
-
console.log(
|
|
337
|
-
"The action is pending and the intermediate value is: ",
|
|
338
|
-
intermediateValue,
|
|
339
|
-
);
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
case DeviceActionStatus.Stopped: {
|
|
343
|
-
console.log("The action has been stopped.");
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case DeviceActionStatus.Completed: {
|
|
347
|
-
const { output } = state;
|
|
348
|
-
// Access the output of the completed action here
|
|
349
|
-
console.log("The action has been completed: ", output);
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
case DeviceActionStatus.Error: {
|
|
353
|
-
const { error } = state;
|
|
354
|
-
// Access the error here if occured
|
|
355
|
-
console.log("An error occured during the action: ", error);
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
```
|
|
175
|
+
- `cancel` A function to cancel the action on the Ledger device.
|
|
362
176
|
|
|
363
|
-
|
|
177
|
+
---
|
|
364
178
|
|
|
365
|
-
|
|
366
|
-
const { requiredUserInteraction } = intermediateValue;
|
|
179
|
+
### Use Case 4: Get App Configuration
|
|
367
180
|
|
|
368
|
-
|
|
369
|
-
case UserInteractionRequired.SignPersonalMessage: {
|
|
370
|
-
// User needs to sign the message displayed on the device
|
|
371
|
-
console.log("User needs to sign the message displayed on the device.");
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
case UserInteractionRequired.None: {
|
|
375
|
-
// No user action required
|
|
376
|
-
console.log("No user action needed.");
|
|
377
|
-
break;
|
|
378
|
-
}
|
|
379
|
-
case UserInteractionRequired.UnlockDevice: {
|
|
380
|
-
// User needs to unlock the device
|
|
381
|
-
console.log("The user needs to unlock the device.");
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
case UserInteractionRequired.ConfirmOpenApp: {
|
|
385
|
-
// User needs to confirm on the device to open the app
|
|
386
|
-
console.log("The user needs to confirm on the device to open the app.");
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
default:
|
|
390
|
-
// Type guard to ensure all cases are handled
|
|
391
|
-
const uncaughtUserInteraction: never = requiredUserInteraction;
|
|
392
|
-
console.error(
|
|
393
|
-
"Unhandled user interaction case:",
|
|
394
|
-
uncaughtUserInteraction,
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
```
|
|
181
|
+
This method allows the user to fetch the current app configuration.
|
|
398
182
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
type Signature = Uint8Array;
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
- `cancel`
|
|
406
|
-
- The function without a return value to cancel the action on the Ledger device.
|
|
183
|
+
```typescript
|
|
184
|
+
const { observable, cancel } = signerSolana.getAppConfiguration();
|
|
185
|
+
```
|
|
407
186
|
|
|
408
|
-
####
|
|
187
|
+
#### **Returns**
|
|
409
188
|
|
|
410
|
-
|
|
189
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
411
190
|
|
|
412
191
|
```typescript
|
|
413
|
-
|
|
192
|
+
type AppConfiguration = {
|
|
193
|
+
blindSigningEnabled: boolean;
|
|
194
|
+
pubKeyDisplayMode: PublicKeyDisplayMode;
|
|
195
|
+
version: string;
|
|
196
|
+
};
|
|
414
197
|
```
|
|
415
198
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
- `observable`
|
|
199
|
+
- `cancel` A function to cancel the action on the Ledger device.
|
|
419
200
|
|
|
420
|
-
|
|
201
|
+
## 🔹 Observable Behavior
|
|
421
202
|
|
|
422
|
-
|
|
423
|
-
observable.subscribe({
|
|
424
|
-
next: (state: SignTypedDataDAState) => {
|
|
425
|
-
switch (state.status) {
|
|
426
|
-
case DeviceActionStatus.NotStarted: {
|
|
427
|
-
console.log("The action is not started yet.");
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
case DeviceActionStatus.Pending: {
|
|
431
|
-
const { intermediateValue } = state;
|
|
432
|
-
// Access the intermediate value here, explained below
|
|
433
|
-
console.log(
|
|
434
|
-
"The action is pending and the intermediate value is: ",
|
|
435
|
-
requiredUserInteraction,
|
|
436
|
-
);
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
case DeviceActionStatus.Stopped: {
|
|
440
|
-
console.log("The action has been stopped.");
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
case DeviceActionStatus.Completed: {
|
|
444
|
-
const { output } = state;
|
|
445
|
-
// Access the output of the completed action here, explained below
|
|
446
|
-
console.log("The action has been completed: ", output);
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
case DeviceActionStatus.Error: {
|
|
450
|
-
const { error } = state;
|
|
451
|
-
// Access the error here if occured
|
|
452
|
-
console.log("An error occured during the action: ", error);
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
},
|
|
457
|
-
});
|
|
458
|
-
```
|
|
203
|
+
Each method returns an [Observable](https://rxjs.dev/guide/observable) emitting updates structured as [`DeviceActionState`](https://github.com/LedgerHQ/device-sdk-ts/blob/develop/packages/device-management-kit/src/api/device-action/model/DeviceActionState.ts). These updates reflect the operation’s progress and status:
|
|
459
204
|
|
|
460
|
-
|
|
205
|
+
- **NotStarted**: The operation hasn’t started.
|
|
206
|
+
- **Pending**: The operation is in progress and may require user interaction.
|
|
207
|
+
- **Stopped**: The operation was canceled or stopped.
|
|
208
|
+
- **Completed**: The operation completed successfully, with results available.
|
|
209
|
+
- **Error**: An error occurred.
|
|
461
210
|
|
|
462
|
-
|
|
463
|
-
const { requiredUserInteraction } = intermediateValue;
|
|
211
|
+
**Example Observable Subscription:**
|
|
464
212
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
213
|
+
```typescript
|
|
214
|
+
observable.subscribe({
|
|
215
|
+
next: (state: DeviceActionState) => {
|
|
216
|
+
switch (state.status) {
|
|
217
|
+
case DeviceActionStatus.NotStarted: {
|
|
218
|
+
console.log("The action is not started yet.");
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case DeviceActionStatus.Pending: {
|
|
222
|
+
const {
|
|
223
|
+
intermediateValue: { requiredUserInteraction },
|
|
224
|
+
} = state;
|
|
225
|
+
// Access the intermediate value here, explained below
|
|
468
226
|
console.log(
|
|
469
|
-
"
|
|
227
|
+
"The action is pending and the intermediate value is: ",
|
|
228
|
+
intermediateValue,
|
|
470
229
|
);
|
|
471
230
|
break;
|
|
472
231
|
}
|
|
473
|
-
case
|
|
474
|
-
|
|
475
|
-
console.log("No user action needed.");
|
|
232
|
+
case DeviceActionStatus.Stopped: {
|
|
233
|
+
console.log("The action has been stopped.");
|
|
476
234
|
break;
|
|
477
235
|
}
|
|
478
|
-
case
|
|
479
|
-
|
|
480
|
-
|
|
236
|
+
case DeviceActionStatus.Completed: {
|
|
237
|
+
const { output } = state;
|
|
238
|
+
// Access the output of the completed action here
|
|
239
|
+
console.log("The action has been completed: ", output);
|
|
481
240
|
break;
|
|
482
241
|
}
|
|
483
|
-
case
|
|
484
|
-
|
|
485
|
-
|
|
242
|
+
case DeviceActionStatus.Error: {
|
|
243
|
+
const { error } = state;
|
|
244
|
+
// Access the error here if occurred
|
|
245
|
+
console.log("An error occurred during the action: ", error);
|
|
486
246
|
break;
|
|
487
247
|
}
|
|
488
|
-
default:
|
|
489
|
-
// Type guard to ensure all cases are handled
|
|
490
|
-
const uncaughtUserInteraction: never = requiredUserInteraction;
|
|
491
|
-
console.error(
|
|
492
|
-
"Unhandled user interaction case:",
|
|
493
|
-
uncaughtUserInteraction,
|
|
494
|
-
);
|
|
495
248
|
}
|
|
496
|
-
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
```
|
|
497
252
|
|
|
498
|
-
|
|
253
|
+
**Intermediate Values in Pending Status:**
|
|
499
254
|
|
|
500
|
-
|
|
501
|
-
type AppConfiguration = {
|
|
502
|
-
blindSigningEnabled: boolean;
|
|
503
|
-
pubKeyDisplayMode: PublicKeyDisplayMode;
|
|
504
|
-
version: string;
|
|
505
|
-
};
|
|
506
|
-
```
|
|
255
|
+
When the status is DeviceActionStatus.Pending, the state will include an `intermediateValue` object that provides useful information for interaction:
|
|
507
256
|
|
|
508
|
-
|
|
509
|
-
|
|
257
|
+
```typescript
|
|
258
|
+
const { requiredUserInteraction } = intermediateValue;
|
|
259
|
+
|
|
260
|
+
switch (requiredUserInteraction) {
|
|
261
|
+
case UserInteractionRequired.VerifyAddress: {
|
|
262
|
+
// User needs to verify the address displayed on the device
|
|
263
|
+
console.log("User needs to verify the address displayed on the device.");
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case UserInteractionRequired.SignTransaction: {
|
|
267
|
+
// User needs to sign the transaction displayed on the device
|
|
268
|
+
console.log("User needs to sign the transaction displayed on the device.");
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case UserInteractionRequired.SignTypedData: {
|
|
272
|
+
// User needs to sign the typed data displayed on the device
|
|
273
|
+
console.log("User needs to sign the typed data displayed on the device.");
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case UserInteractionRequired.SignPersonalMessage: {
|
|
277
|
+
// User needs to sign the message displayed on the device
|
|
278
|
+
console.log("User needs to sign the message displayed on the device.");
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case UserInteractionRequired.None: {
|
|
282
|
+
// No user action required
|
|
283
|
+
console.log("No user action needed.");
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case UserInteractionRequired.UnlockDevice: {
|
|
287
|
+
// User needs to unlock the device
|
|
288
|
+
console.log("The user needs to unlock the device.");
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case UserInteractionRequired.ConfirmOpenApp: {
|
|
292
|
+
// User needs to confirm on the device to open the app
|
|
293
|
+
console.log("The user needs to confirm on the device to open the app.");
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
default:
|
|
297
|
+
// Type guard to ensure all cases are handled
|
|
298
|
+
const uncaughtUserInteraction: never = requiredUserInteraction;
|
|
299
|
+
console.error("Unhandled user interaction case:", uncaughtUserInteraction);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
510
302
|
|
|
511
|
-
## Example
|
|
303
|
+
## 🔹 Example
|
|
512
304
|
|
|
513
305
|
We encourage you to explore the Solana Signer by trying it out in our online [sample application](https://app.devicesdk.ledger-test.com/). Experience how it works and see its capabilities in action. Of course, you will need a Ledger device connected.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var i=(r,e,n,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of o(e))!s.call(r,t)&&t!==n&&p(r,t,{get:()=>e[t],enumerable:!(d=A(e,t))||d.enumerable});return r};var u=r=>i(p({},"__esModule",{value:!0}),r);var a={};module.exports=u(a);
|
|
2
2
|
//# sourceMappingURL=GetAddressDeviceActionTypes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/app-binder/GetAddressDeviceActionTypes.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ExecuteDeviceActionReturnType,\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n type UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type PublicKey } from \"@api/model/PublicKey\";\n\ntype GetAddressDAUserInteractionRequired =\n | UserInteractionRequired.None\n | UserInteractionRequired.VerifyAddress;\n\nexport type GetAddressDAOutput = SendCommandInAppDAOutput<PublicKey>;\nexport type GetAddressDAError = SendCommandInAppDAError<
|
|
4
|
+
"sourcesContent": ["import {\n type ExecuteDeviceActionReturnType,\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n type UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type PublicKey } from \"@api/model/PublicKey\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\n\ntype GetAddressDAUserInteractionRequired =\n | UserInteractionRequired.None\n | UserInteractionRequired.VerifyAddress;\n\nexport type GetAddressDAOutput = SendCommandInAppDAOutput<PublicKey>;\nexport type GetAddressDAError = SendCommandInAppDAError<SolanaAppErrorCodes>;\nexport type GetAddressDAIntermediateValue =\n SendCommandInAppDAIntermediateValue<GetAddressDAUserInteractionRequired>;\n\nexport type GetAddressDAReturnType = ExecuteDeviceActionReturnType<\n GetAddressDAOutput,\n GetAddressDAError,\n GetAddressDAIntermediateValue\n>;\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["GetAddressDeviceActionTypes_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of A(e))!a.call(t,p)&&p!==o&&r(t,p,{get:()=>e[p],enumerable:!(n=i(e,p))||n.enumerable});return t};var m=t=>u(r({},"__esModule",{value:!0}),t);var d={};module.exports=m(d);
|
|
2
2
|
//# sourceMappingURL=GetAppConfigurationDeviceActionTypes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/app-binder/GetAppConfigurationDeviceActionTypes.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ExecuteDeviceActionReturnType,\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n type UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\n\nexport type GetAppConfigurationDAOutput =\n SendCommandInAppDAOutput<AppConfiguration>;\n\nexport type GetAppConfigurationDAError
|
|
4
|
+
"sourcesContent": ["import {\n type ExecuteDeviceActionReturnType,\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n type UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type AppConfiguration } from \"@api/model/AppConfiguration\";\nimport { type SolanaAppErrorCodes } from \"@internal/app-binder/command/utils/SolanaApplicationErrors\";\n\nexport type GetAppConfigurationDAOutput =\n SendCommandInAppDAOutput<AppConfiguration>;\n\nexport type GetAppConfigurationDAError =\n SendCommandInAppDAError<SolanaAppErrorCodes>;\n\nexport type GetAppConfigurationDAIntermediateValue =\n SendCommandInAppDAIntermediateValue<UserInteractionRequired.None>;\n\nexport type GetAppConfigurationDAReturnType = ExecuteDeviceActionReturnType<\n GetAppConfigurationDAOutput,\n GetAppConfigurationDAError,\n GetAppConfigurationDAIntermediateValue\n>;\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["GetAppConfigurationDeviceActionTypes_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var g=(r,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of o(e))!s.call(r,t)&&t!==i&&a(r,t,{get:()=>e[t],enumerable:!(n=p(e,t))||n.enumerable});return r};var A=r=>g(a({},"__esModule",{value:!0}),r);var u={};module.exports=A(u);
|
|
2
2
|
//# sourceMappingURL=SignMessageDeviceActionTypes.js.map
|