@ledgerhq/wallet-api-simulator 1.1.0 → 1.1.1
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 +131 -0
- package/lib/transport.js +2 -2
- package/lib/transport.js.map +1 -1
- package/lib-es/transport.js +2 -2
- package/lib-es/transport.js.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://user-images.githubusercontent.com/9203826/154288895-670f5c23-81a1-4307-a080-1af83f7f8356.svg" align="center" alt="Ledger" />
|
|
3
|
+
<h2 align="center">WalletAPI Simulator</h2>
|
|
4
|
+
<p align="center">Test and develop your application or service without <a href="https://www.ledger.com/ledger-live">Ledger Live</a></p>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@ledgerhq/wallet-api-simulator?activeTab=versions">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@ledgerhq/wallet-api-simulator.svg?style=flat-square" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://opensource.org/licenses/Apache-2.0">
|
|
12
|
+
<img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/LedgerHQ/wallet-api/actions">
|
|
15
|
+
<img alt="Tests Passing" src="https://github.com/LedgerHQ/wallet-api/workflows/Release/badge.svg" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://codecov.io/gh/LedgerHQ/wallet-api">
|
|
18
|
+
<img src="https://codecov.io/gh/LedgerHQ/wallet-api/branch/main/graph/badge.svg" />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://github.com/LedgerHQ/wallet-api/issues">
|
|
21
|
+
<img alt="Issues" src="https://img.shields.io/github/issues/LedgerHQ/wallet-api?color=0088ff" />
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://github.com/LedgerHQ/wallet-api/pulls">
|
|
24
|
+
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/LedgerHQ/wallet-api?color=0088ff" />
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://discord.gg/y6nZhxv2bC">
|
|
27
|
+
<img alt="Discord" src="https://img.shields.io/discord/885256081289379850?color=1C1CE1&label=Ledger%20%7C%20Discord%20%F0%9F%91%8B%20&style=flat-square" />
|
|
28
|
+
</a>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://developers.ledger.com/docs/live-app/start-here/">Full documentation</a>
|
|
35
|
+
·
|
|
36
|
+
<a href="https://github.com/LedgerHQ/wallet-api/issues/new/choose">Report Bug</a>
|
|
37
|
+
·
|
|
38
|
+
<a href="https://github.com/LedgerHQ/wallet-api/issues/new/choose">Request Feature</a>
|
|
39
|
+
</p>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
## Overview
|
|
43
|
+
|
|
44
|
+
The Ledger Wallet Simulator is a comprehensive tool designed to emulate the behavior of a Ledger device simulating responses and interactions with the wallet-API. It aids developers in testing and interacting with Ledger-related applications without requiring a physical Ledger device or necessitating the run of your application inside the WebView of the LedgerLive software. This documentation will guide you through the process of setting up and using the simulator.
|
|
45
|
+
|
|
46
|
+
By following this documentation, you'll be equipped to install, set up, and make the most out of this simulator. If any issues arise or further customization is needed, consider diving deeper into the source code or consulting the official documentation.
|
|
47
|
+
|
|
48
|
+
## Table of Contents
|
|
49
|
+
|
|
50
|
+
- [Ledger Wallet Simulator Documentation](#ledger-wallet-simulator-documentation)
|
|
51
|
+
- [Overview](#overview)
|
|
52
|
+
- [Table of Contents](#table-of-contents)
|
|
53
|
+
- [Installation](#installation)
|
|
54
|
+
- [Getting Started](#getting-started)
|
|
55
|
+
- [1. **Setting Up Transport**:](#1-setting-up-transport)
|
|
56
|
+
- [2. **Creating Client**:](#2-creating-client)
|
|
57
|
+
- [Working with Profiles](#working-with-profiles)
|
|
58
|
+
- [Using the Simulator](#using-the-simulator)
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
To install the Ledger Wallet Simulator, you'll first need to include the necessary dependencies in your project.
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm install @ledgerhq/wallet-api-client
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Then, install the simulator package:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
npm install @ledgerHQ/simulator
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Getting Started
|
|
79
|
+
|
|
80
|
+
### 1. **Setting Up Transport**:
|
|
81
|
+
|
|
82
|
+
Begin by setting up the transport using the `getSimulatorTransport` function.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { getSimulatorTransport, profiles } from "@ledgerHQ/simulator";
|
|
86
|
+
|
|
87
|
+
const transport = getSimulatorTransport(profiles.STANDARD);
|
|
88
|
+
transport.onMessage = handleMessageFunction; // Replace with your message handler.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 2. **Creating Client**:
|
|
92
|
+
|
|
93
|
+
Create a `createClient` function that return a new client. The provided simulated transport should be passed to the `WalletAPIClient()` as a parameter to effectively interact with the `WalletAPIClient`. Normally, `WalletAPIClient` only works with real transport, but the simulator provides a simulated transport for this purpose.
|
|
94
|
+
|
|
95
|
+
Here's a basic form:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
function createClient() {
|
|
99
|
+
// insert the transport created above
|
|
100
|
+
return new WalletAPIClient(transport);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Working with Profiles
|
|
107
|
+
|
|
108
|
+
The simulator comes with predefined profiles (`STANDARD` and `DEVICE`), which determine the behavior and data of the simulator. You can easily extend these profiles by spreading inside the profile object:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const extendedProfile = {
|
|
112
|
+
...profiles.STANDARD,
|
|
113
|
+
yourInfo: "yourValue", // Add any custom information here.
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Using the Simulator
|
|
120
|
+
|
|
121
|
+
The primary use case for the simulator is to emulate a Ledger device's behavior for development and testing purposes. Here's a basic example:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Create a client
|
|
125
|
+
const client = createClient();
|
|
126
|
+
|
|
127
|
+
// List accounts
|
|
128
|
+
const response = await client.transaction.list();
|
|
129
|
+
|
|
130
|
+
console.log(response);
|
|
131
|
+
```
|
package/lib/transport.js
CHANGED
|
@@ -9,7 +9,7 @@ function getSimulatorTransport(profile, customHandlers) {
|
|
|
9
9
|
const serverTransport = {
|
|
10
10
|
onMessage: undefined,
|
|
11
11
|
send: (payload) => {
|
|
12
|
-
console.
|
|
12
|
+
console.info("wallet -> app", payload);
|
|
13
13
|
if (clientTransport?.onMessage) {
|
|
14
14
|
clientTransport.onMessage(payload);
|
|
15
15
|
}
|
|
@@ -18,7 +18,7 @@ function getSimulatorTransport(profile, customHandlers) {
|
|
|
18
18
|
clientTransport = {
|
|
19
19
|
onMessage: undefined,
|
|
20
20
|
send: (payload) => {
|
|
21
|
-
console.
|
|
21
|
+
console.info("app -> wallet", payload);
|
|
22
22
|
if (serverTransport?.onMessage) {
|
|
23
23
|
serverTransport.onMessage(payload);
|
|
24
24
|
}
|
package/lib/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";;;AACA,mEAIqC;AACrC,uCAAyC;AAGzC,SAAgB,qBAAqB,CACnC,OAAyB,EACzB,cAA+B;IAE/B,wCAAwC;IACxC,IAAI,eAAsC,CAAC;IAE3C,MAAM,eAAe,GAAc;QACjC,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";;;AACA,mEAIqC;AACrC,uCAAyC;AAGzC,SAAgB,qBAAqB,CACnC,OAAyB,EACzB,cAA+B;IAE/B,wCAAwC;IACxC,IAAI,eAAsC,CAAC;IAE3C,MAAM,eAAe,GAAc;QACjC,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,eAAe,EAAE,SAAS,EAAE;gBAC9B,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC;KACF,CAAC;IAEF,eAAe,GAAG;QAChB,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,eAAe,EAAE,SAAS,EAAE;gBAC9B,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC;KACF,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,mCAAe,CACxC,eAAe,EACf,OAAO,CAAC,MAAM,EACd,iCAAa,EACb,cAAc,CACf,CAAC;IAEF,IAAA,sBAAY,EAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAEtC,OAAO,eAAe,CAAC;AACzB,CAAC;AArCD,sDAqCC"}
|
package/lib-es/transport.js
CHANGED
|
@@ -6,7 +6,7 @@ export function getSimulatorTransport(profile, customHandlers) {
|
|
|
6
6
|
const serverTransport = {
|
|
7
7
|
onMessage: undefined,
|
|
8
8
|
send: (payload) => {
|
|
9
|
-
console.
|
|
9
|
+
console.info("wallet -> app", payload);
|
|
10
10
|
if (clientTransport?.onMessage) {
|
|
11
11
|
clientTransport.onMessage(payload);
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ export function getSimulatorTransport(profile, customHandlers) {
|
|
|
15
15
|
clientTransport = {
|
|
16
16
|
onMessage: undefined,
|
|
17
17
|
send: (payload) => {
|
|
18
|
-
console.
|
|
18
|
+
console.info("app -> wallet", payload);
|
|
19
19
|
if (serverTransport?.onMessage) {
|
|
20
20
|
serverTransport.onMessage(payload);
|
|
21
21
|
}
|
package/lib-es/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EACf,aAAa,GACd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,cAA+B;IAE/B,wCAAwC;IACxC,IAAI,eAAsC,CAAC;IAE3C,MAAM,eAAe,GAAc;QACjC,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EACf,aAAa,GACd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,cAA+B;IAE/B,wCAAwC;IACxC,IAAI,eAAsC,CAAC;IAE3C,MAAM,eAAe,GAAc;QACjC,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,eAAe,EAAE,SAAS,EAAE;gBAC9B,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC;KACF,CAAC;IAEF,eAAe,GAAG;QAChB,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,eAAe,EAAE,SAAS,EAAE;gBAC9B,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACpC;QACH,CAAC;KACF,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,eAAe,CACxC,eAAe,EACf,OAAO,CAAC,MAAM,EACd,aAAa,EACb,cAAc,CACf,CAAC;IAEF,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAEtC,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/wallet-api-simulator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/jest": "^29.5.4",
|
|
14
|
-
"@types/node": "^20.
|
|
14
|
+
"@types/node": "^20.8.7",
|
|
15
15
|
"@types/ws": "^8.5.5",
|
|
16
16
|
"bignumber.js": "^9.1.2",
|
|
17
17
|
"eslint": "^8.48.0",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@ledgerhq/hw-transport-http": "^6.28.3",
|
|
28
28
|
"rxjs": "^7.8.1",
|
|
29
29
|
"ws": "^8.13.0",
|
|
30
|
-
"@ledgerhq/wallet-api-client": "1.2.
|
|
31
|
-
"@ledgerhq/wallet-api-core": "1.3.
|
|
32
|
-
"@ledgerhq/wallet-api-server": "1.3.
|
|
30
|
+
"@ledgerhq/wallet-api-client": "1.2.1",
|
|
31
|
+
"@ledgerhq/wallet-api-core": "1.3.1",
|
|
32
|
+
"@ledgerhq/wallet-api-server": "1.3.1"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"format:check": "prettier --check \"src\"",
|