@ledgerhq/wallet-api-simulator 0.5.4 → 0.6.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/lib/profiles/standard.d.ts.map +1 -1
- package/lib/profiles/standard.js +22 -1
- package/lib/test-run.js +18 -9
- package/lib/transport.d.ts.map +1 -1
- package/lib/transport.js +11 -0
- package/lib-es/profiles/standard.d.ts.map +1 -1
- package/lib-es/profiles/standard.js +23 -2
- package/lib-es/test-run.js +18 -9
- package/lib-es/transport.d.ts.map +1 -1
- package/lib-es/transport.js +11 -0
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA+CnE,wBAAgB,UAAU,CAAC,cAAc,EAAE,eAAe,QA8BzD"}
|
package/lib/profiles/standard.js
CHANGED
|
@@ -3,6 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setProfile = void 0;
|
|
4
4
|
const wallet_api_core_1 = require("@ledgerhq/wallet-api-core");
|
|
5
5
|
const rxjs_1 = require("rxjs");
|
|
6
|
+
const currencies = [
|
|
7
|
+
{
|
|
8
|
+
type: "CryptoCurrency",
|
|
9
|
+
id: "bitcoin",
|
|
10
|
+
ticker: "BTC",
|
|
11
|
+
name: "Bitcoin",
|
|
12
|
+
family: "bitcoin",
|
|
13
|
+
color: "#ffae35",
|
|
14
|
+
decimals: 8,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: "CryptoCurrency",
|
|
18
|
+
id: "ethereum",
|
|
19
|
+
ticker: "ETH",
|
|
20
|
+
name: "Ethereum",
|
|
21
|
+
family: "ethereum",
|
|
22
|
+
color: "#0ebdcd",
|
|
23
|
+
decimals: 18,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
6
26
|
const cryptoAccounts = [
|
|
7
27
|
{
|
|
8
28
|
id: "account-btc-1",
|
|
@@ -27,10 +47,11 @@ const cryptoAccounts = [
|
|
|
27
47
|
].map(wallet_api_core_1.deserializeAccount);
|
|
28
48
|
function setProfile(serverInstance) {
|
|
29
49
|
serverInstance.setAccounts(cryptoAccounts);
|
|
50
|
+
serverInstance.setCurrencies(currencies);
|
|
30
51
|
serverInstance.setHandler("account.request", async ({ accounts$ }) => {
|
|
31
52
|
const accounts = await (0, rxjs_1.firstValueFrom)(accounts$);
|
|
32
53
|
if (!accounts[0]) {
|
|
33
|
-
throw new Error("
|
|
54
|
+
throw new Error("No accounts available");
|
|
34
55
|
}
|
|
35
56
|
return accounts[0];
|
|
36
57
|
});
|
package/lib/test-run.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const WalletAPIClient_1 = require("@ledgerhq/wallet-api-client/lib/WalletAPIClient");
|
|
4
|
-
|
|
4
|
+
// import { deserializeTransaction } from "@ledgerhq/wallet-api-core";
|
|
5
5
|
const transport_1 = require("./transport");
|
|
6
6
|
async function main() {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
8
|
const transport = (0, transport_1.getSimulatorTransport)("standard");
|
|
8
9
|
const client = new WalletAPIClient_1.WalletAPIClient(transport);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
await client.listAccounts({ currencyIds: ["ethereum"] });
|
|
11
|
+
/* transport.send(
|
|
12
|
+
JSON.stringify({
|
|
13
|
+
id: "49f2b5e9-9e77-495c-8add-8542127b4a50",
|
|
14
|
+
jsonrpc: "2.0",
|
|
15
|
+
method: "transaction.signAndBroadcast",
|
|
16
|
+
params: {
|
|
17
|
+
rawTransaction: {
|
|
18
|
+
family: "ethereum",
|
|
19
|
+
amount: "12",
|
|
20
|
+
recipient: "0xananas",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
*/
|
|
17
26
|
}
|
|
18
27
|
main()
|
|
19
28
|
.then(() => console.log("done"))
|
package/lib/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAqCnE"}
|
package/lib/transport.js
CHANGED
|
@@ -8,6 +8,7 @@ function getSimulatorTransport(_profileId) {
|
|
|
8
8
|
const serverTransport = {
|
|
9
9
|
onMessage: undefined,
|
|
10
10
|
send: (payload) => {
|
|
11
|
+
console.log("wallet -> app", payload);
|
|
11
12
|
if (clientTransport && clientTransport.onMessage) {
|
|
12
13
|
clientTransport.onMessage(payload);
|
|
13
14
|
}
|
|
@@ -16,12 +17,22 @@ function getSimulatorTransport(_profileId) {
|
|
|
16
17
|
clientTransport = {
|
|
17
18
|
onMessage: undefined,
|
|
18
19
|
send: (payload) => {
|
|
20
|
+
console.log("app -> wallet", payload);
|
|
19
21
|
if (serverTransport && serverTransport.onMessage) {
|
|
20
22
|
serverTransport.onMessage(payload);
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
25
|
};
|
|
24
26
|
const serverInstance = new wallet_api_server_1.WalletAPIServer(serverTransport);
|
|
27
|
+
serverInstance.setPermissions({
|
|
28
|
+
methodIds: [
|
|
29
|
+
"account.request",
|
|
30
|
+
"account.list",
|
|
31
|
+
"currency.list",
|
|
32
|
+
"transaction.signAndBroadcast",
|
|
33
|
+
],
|
|
34
|
+
currencyIds: ["eth*"],
|
|
35
|
+
});
|
|
25
36
|
(0, standard_1.setProfile)(serverInstance);
|
|
26
37
|
return clientTransport;
|
|
27
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA+CnE,wBAAgB,UAAU,CAAC,cAAc,EAAE,eAAe,QA8BzD"}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import { deserializeAccount } from "@ledgerhq/wallet-api-core";
|
|
1
|
+
import { deserializeAccount, } from "@ledgerhq/wallet-api-core";
|
|
2
2
|
import { firstValueFrom } from "rxjs";
|
|
3
|
+
const currencies = [
|
|
4
|
+
{
|
|
5
|
+
type: "CryptoCurrency",
|
|
6
|
+
id: "bitcoin",
|
|
7
|
+
ticker: "BTC",
|
|
8
|
+
name: "Bitcoin",
|
|
9
|
+
family: "bitcoin",
|
|
10
|
+
color: "#ffae35",
|
|
11
|
+
decimals: 8,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: "CryptoCurrency",
|
|
15
|
+
id: "ethereum",
|
|
16
|
+
ticker: "ETH",
|
|
17
|
+
name: "Ethereum",
|
|
18
|
+
family: "ethereum",
|
|
19
|
+
color: "#0ebdcd",
|
|
20
|
+
decimals: 18,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
3
23
|
const cryptoAccounts = [
|
|
4
24
|
{
|
|
5
25
|
id: "account-btc-1",
|
|
@@ -24,10 +44,11 @@ const cryptoAccounts = [
|
|
|
24
44
|
].map(deserializeAccount);
|
|
25
45
|
export function setProfile(serverInstance) {
|
|
26
46
|
serverInstance.setAccounts(cryptoAccounts);
|
|
47
|
+
serverInstance.setCurrencies(currencies);
|
|
27
48
|
serverInstance.setHandler("account.request", async ({ accounts$ }) => {
|
|
28
49
|
const accounts = await firstValueFrom(accounts$);
|
|
29
50
|
if (!accounts[0]) {
|
|
30
|
-
throw new Error("
|
|
51
|
+
throw new Error("No accounts available");
|
|
31
52
|
}
|
|
32
53
|
return accounts[0];
|
|
33
54
|
});
|
package/lib-es/test-run.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { WalletAPIClient } from "@ledgerhq/wallet-api-client/lib/WalletAPIClient";
|
|
2
|
-
import { deserializeTransaction } from "@ledgerhq/wallet-api-core";
|
|
2
|
+
// import { deserializeTransaction } from "@ledgerhq/wallet-api-core";
|
|
3
3
|
import { getSimulatorTransport } from "./transport";
|
|
4
4
|
async function main() {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
6
|
const transport = getSimulatorTransport("standard");
|
|
6
7
|
const client = new WalletAPIClient(transport);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
await client.listAccounts({ currencyIds: ["ethereum"] });
|
|
9
|
+
/* transport.send(
|
|
10
|
+
JSON.stringify({
|
|
11
|
+
id: "49f2b5e9-9e77-495c-8add-8542127b4a50",
|
|
12
|
+
jsonrpc: "2.0",
|
|
13
|
+
method: "transaction.signAndBroadcast",
|
|
14
|
+
params: {
|
|
15
|
+
rawTransaction: {
|
|
16
|
+
family: "ethereum",
|
|
17
|
+
amount: "12",
|
|
18
|
+
recipient: "0xananas",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
*/
|
|
15
24
|
}
|
|
16
25
|
main()
|
|
17
26
|
.then(() => console.log("done"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAqCnE"}
|
package/lib-es/transport.js
CHANGED
|
@@ -5,6 +5,7 @@ export function getSimulatorTransport(_profileId) {
|
|
|
5
5
|
const serverTransport = {
|
|
6
6
|
onMessage: undefined,
|
|
7
7
|
send: (payload) => {
|
|
8
|
+
console.log("wallet -> app", payload);
|
|
8
9
|
if (clientTransport && clientTransport.onMessage) {
|
|
9
10
|
clientTransport.onMessage(payload);
|
|
10
11
|
}
|
|
@@ -13,12 +14,22 @@ export function getSimulatorTransport(_profileId) {
|
|
|
13
14
|
clientTransport = {
|
|
14
15
|
onMessage: undefined,
|
|
15
16
|
send: (payload) => {
|
|
17
|
+
console.log("app -> wallet", payload);
|
|
16
18
|
if (serverTransport && serverTransport.onMessage) {
|
|
17
19
|
serverTransport.onMessage(payload);
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
};
|
|
21
23
|
const serverInstance = new WalletAPIServer(serverTransport);
|
|
24
|
+
serverInstance.setPermissions({
|
|
25
|
+
methodIds: [
|
|
26
|
+
"account.request",
|
|
27
|
+
"account.list",
|
|
28
|
+
"currency.list",
|
|
29
|
+
"transaction.signAndBroadcast",
|
|
30
|
+
],
|
|
31
|
+
currencyIds: ["eth*"],
|
|
32
|
+
});
|
|
22
33
|
setProfile(serverInstance);
|
|
23
34
|
return clientTransport;
|
|
24
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/wallet-api-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
"eslint": "^8.26.0",
|
|
18
18
|
"jest": "^29.1.2",
|
|
19
19
|
"jest-environment-jsdom": "^29.2.2",
|
|
20
|
+
"jest-shared-config": "0.1.0",
|
|
20
21
|
"ts-jest": "^29.0.3",
|
|
21
22
|
"ts-node": "^10.9.1",
|
|
22
23
|
"typescript": "^4.8.4"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@ledgerhq/wallet-api-client": "0.
|
|
26
|
-
"@ledgerhq/wallet-api-core": "0.
|
|
27
|
-
"@ledgerhq/wallet-api-server": "0.
|
|
26
|
+
"@ledgerhq/wallet-api-client": "0.7.0",
|
|
27
|
+
"@ledgerhq/wallet-api-core": "0.7.0",
|
|
28
|
+
"@ledgerhq/wallet-api-server": "0.7.0",
|
|
28
29
|
"rxjs": "^7.5.7",
|
|
29
30
|
"ws": "^8.10.0"
|
|
30
31
|
},
|