@ledgerhq/wallet-api-simulator 0.6.0 → 0.6.2
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/helpers.d.ts +4 -0
- package/lib/helpers.d.ts.map +1 -0
- package/lib/helpers.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/profiles/index.d.ts +4 -0
- package/lib/profiles/index.d.ts.map +1 -0
- package/lib/profiles/index.js +7 -0
- package/lib/profiles/standard/accounts.json +22 -0
- package/lib/profiles/standard/currencies.json +20 -0
- package/lib/profiles/standard/index.d.ts +3 -0
- package/lib/profiles/standard/index.d.ts.map +1 -0
- package/lib/profiles/standard/index.js +49 -0
- package/lib/test-run.js +2 -1
- package/lib/transport.d.ts +2 -1
- package/lib/transport.d.ts.map +1 -1
- package/lib/transport.js +3 -12
- package/lib/types.d.ts +9 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib-es/helpers.d.ts +4 -0
- package/lib-es/helpers.d.ts.map +1 -0
- package/lib-es/helpers.js +13 -0
- package/lib-es/index.d.ts +1 -0
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -0
- package/lib-es/profiles/index.d.ts +4 -0
- package/lib-es/profiles/index.d.ts.map +1 -0
- package/lib-es/profiles/index.js +4 -0
- package/lib-es/profiles/standard/accounts.json +22 -0
- package/lib-es/profiles/standard/currencies.json +20 -0
- package/lib-es/profiles/standard/index.d.ts +3 -0
- package/lib-es/profiles/standard/index.d.ts.map +1 -0
- package/lib-es/profiles/standard/index.js +43 -0
- package/lib-es/test-run.js +2 -1
- package/lib-es/transport.d.ts +2 -1
- package/lib-es/transport.d.ts.map +1 -1
- package/lib-es/transport.js +3 -12
- package/lib-es/types.d.ts +9 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +1 -0
- package/package.json +4 -4
- package/lib/profiles/standard.d.ts +0 -3
- package/lib/profiles/standard.d.ts.map +0 -1
- package/lib/profiles/standard.js +0 -71
- package/lib-es/profiles/standard.d.ts +0 -3
- package/lib-es/profiles/standard.d.ts.map +0 -1
- package/lib-es/profiles/standard.js +0 -67
package/lib/helpers.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,YAAY,CAC1B,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,gBAAgB,QAe1B"}
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyProfile = void 0;
|
|
4
|
+
function applyProfile(serverInstance, profile) {
|
|
5
|
+
serverInstance.setAccounts(profile.accounts);
|
|
6
|
+
serverInstance.setCurrencies(profile.currencies);
|
|
7
|
+
serverInstance.setPermissions(profile.permissions);
|
|
8
|
+
const methodIds = Object.keys(profile.methods);
|
|
9
|
+
methodIds.forEach((methodId) => {
|
|
10
|
+
const key = methodId;
|
|
11
|
+
const handler = profile.methods[key];
|
|
12
|
+
if (handler) {
|
|
13
|
+
serverInstance.setHandler(key, handler);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.applyProfile = applyProfile;
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/profiles/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;CAEpB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "account-btc-1",
|
|
4
|
+
"name": "Bitcoin 1",
|
|
5
|
+
"address": "address",
|
|
6
|
+
"currency": "bitcoin",
|
|
7
|
+
"balance": "42",
|
|
8
|
+
"spendableBalance": "42",
|
|
9
|
+
"blockHeight": 1,
|
|
10
|
+
"lastSyncDate": "1995-12-17T03:24:00"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "account-eth-1",
|
|
14
|
+
"name": "Ethereum 1",
|
|
15
|
+
"address": "address",
|
|
16
|
+
"currency": "ethereum",
|
|
17
|
+
"balance": "42",
|
|
18
|
+
"spendableBalance": "42",
|
|
19
|
+
"blockHeight": 1,
|
|
20
|
+
"lastSyncDate": "1995-12-17T03:24:00"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"type": "CryptoCurrency",
|
|
4
|
+
"id": "bitcoin",
|
|
5
|
+
"ticker": "BTC",
|
|
6
|
+
"name": "Bitcoin",
|
|
7
|
+
"family": "bitcoin",
|
|
8
|
+
"color": "#ffae35",
|
|
9
|
+
"decimals": 8
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "CryptoCurrency",
|
|
13
|
+
"id": "ethereum",
|
|
14
|
+
"ticker": "ETH",
|
|
15
|
+
"name": "Ethereum",
|
|
16
|
+
"family": "ethereum",
|
|
17
|
+
"color": "#0ebdcd",
|
|
18
|
+
"decimals": 18
|
|
19
|
+
}
|
|
20
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/profiles/standard/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASpD,eAAO,MAAM,eAAe,EAAE,gBAuC7B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.standardProfile = void 0;
|
|
7
|
+
const wallet_api_core_1 = require("@ledgerhq/wallet-api-core");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const accounts_json_1 = __importDefault(require("./accounts.json"));
|
|
10
|
+
const currencies_json_1 = __importDefault(require("./currencies.json"));
|
|
11
|
+
const allCurrencies = currencies_json_1.default;
|
|
12
|
+
const allAccounts = accounts_json_1.default.map(wallet_api_core_1.deserializeAccount);
|
|
13
|
+
exports.standardProfile = {
|
|
14
|
+
permissions: {
|
|
15
|
+
currencyIds: ["ethereum", "bitcoin"],
|
|
16
|
+
methodIds: [
|
|
17
|
+
"account.request",
|
|
18
|
+
"currency.list",
|
|
19
|
+
"account.list",
|
|
20
|
+
"transaction.signAndBroadcast",
|
|
21
|
+
"transaction.sign",
|
|
22
|
+
"message.sign",
|
|
23
|
+
"account.receive",
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
accounts: allAccounts,
|
|
27
|
+
currencies: allCurrencies,
|
|
28
|
+
methods: {
|
|
29
|
+
"account.request": async ({ accounts$ }) => {
|
|
30
|
+
const accounts = await (0, rxjs_1.firstValueFrom)(accounts$);
|
|
31
|
+
if (!accounts[0]) {
|
|
32
|
+
throw new Error("No accounts available");
|
|
33
|
+
}
|
|
34
|
+
return accounts[0];
|
|
35
|
+
},
|
|
36
|
+
"transaction.signAndBroadcast": () => {
|
|
37
|
+
return "0xtxHash";
|
|
38
|
+
},
|
|
39
|
+
"transaction.sign": () => {
|
|
40
|
+
return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
|
|
41
|
+
},
|
|
42
|
+
"message.sign": () => {
|
|
43
|
+
return Buffer.from("0x123456789123456789");
|
|
44
|
+
},
|
|
45
|
+
"account.receive": () => {
|
|
46
|
+
return "eth address";
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
package/lib/test-run.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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
|
+
const profiles_1 = require("./profiles");
|
|
4
5
|
// import { deserializeTransaction } from "@ledgerhq/wallet-api-core";
|
|
5
6
|
const transport_1 = require("./transport");
|
|
6
7
|
async function main() {
|
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
-
const transport = (0, transport_1.getSimulatorTransport)(
|
|
9
|
+
const transport = (0, transport_1.getSimulatorTransport)(profiles_1.profiles.STANDARD);
|
|
9
10
|
const client = new WalletAPIClient_1.WalletAPIClient(transport);
|
|
10
11
|
await client.listAccounts({ currencyIds: ["ethereum"] });
|
|
11
12
|
/* transport.send(
|
package/lib/transport.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Transport } from "@ledgerhq/wallet-api-core";
|
|
2
|
-
|
|
2
|
+
import type { SimulatorProfile } from "./types";
|
|
3
|
+
export declare function getSimulatorTransport(profile: SimulatorProfile): Transport;
|
|
3
4
|
//# sourceMappingURL=transport.d.ts.map
|
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;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA2B1E"}
|
package/lib/transport.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSimulatorTransport = void 0;
|
|
4
4
|
const wallet_api_server_1 = require("@ledgerhq/wallet-api-server");
|
|
5
|
-
const
|
|
6
|
-
function getSimulatorTransport(
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
function getSimulatorTransport(profile) {
|
|
7
7
|
let clientTransport;
|
|
8
8
|
const serverTransport = {
|
|
9
9
|
onMessage: undefined,
|
|
@@ -24,16 +24,7 @@ function getSimulatorTransport(_profileId) {
|
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
26
|
const serverInstance = new wallet_api_server_1.WalletAPIServer(serverTransport);
|
|
27
|
-
|
|
28
|
-
methodIds: [
|
|
29
|
-
"account.request",
|
|
30
|
-
"account.list",
|
|
31
|
-
"currency.list",
|
|
32
|
-
"transaction.signAndBroadcast",
|
|
33
|
-
],
|
|
34
|
-
currencyIds: ["eth*"],
|
|
35
|
-
});
|
|
36
|
-
(0, standard_1.setProfile)(serverInstance);
|
|
27
|
+
(0, helpers_1.applyProfile)(serverInstance, profile);
|
|
37
28
|
return clientTransport;
|
|
38
29
|
}
|
|
39
30
|
exports.getSimulatorTransport = getSimulatorTransport;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Account, Currency, Permission } from "@ledgerhq/wallet-api-core";
|
|
2
|
+
import type { WalletHandlers } from "@ledgerhq/wallet-api-server";
|
|
3
|
+
export declare type SimulatorProfile = {
|
|
4
|
+
permissions: Permission;
|
|
5
|
+
accounts: Account[];
|
|
6
|
+
currencies: Currency[];
|
|
7
|
+
methods: Partial<WalletHandlers>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,oBAAY,gBAAgB,GAAG;IAC7B,WAAW,EAAE,UAAU,CAAC;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;CAClC,CAAC"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,YAAY,CAC1B,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,gBAAgB,QAe1B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function applyProfile(serverInstance, profile) {
|
|
2
|
+
serverInstance.setAccounts(profile.accounts);
|
|
3
|
+
serverInstance.setCurrencies(profile.currencies);
|
|
4
|
+
serverInstance.setPermissions(profile.permissions);
|
|
5
|
+
const methodIds = Object.keys(profile.methods);
|
|
6
|
+
methodIds.forEach((methodId) => {
|
|
7
|
+
const key = methodId;
|
|
8
|
+
const handler = profile.methods[key];
|
|
9
|
+
if (handler) {
|
|
10
|
+
serverInstance.setHandler(key, handler);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
package/lib-es/index.d.ts
CHANGED
package/lib-es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/lib-es/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/profiles/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;CAEpB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "account-btc-1",
|
|
4
|
+
"name": "Bitcoin 1",
|
|
5
|
+
"address": "address",
|
|
6
|
+
"currency": "bitcoin",
|
|
7
|
+
"balance": "42",
|
|
8
|
+
"spendableBalance": "42",
|
|
9
|
+
"blockHeight": 1,
|
|
10
|
+
"lastSyncDate": "1995-12-17T03:24:00"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "account-eth-1",
|
|
14
|
+
"name": "Ethereum 1",
|
|
15
|
+
"address": "address",
|
|
16
|
+
"currency": "ethereum",
|
|
17
|
+
"balance": "42",
|
|
18
|
+
"spendableBalance": "42",
|
|
19
|
+
"blockHeight": 1,
|
|
20
|
+
"lastSyncDate": "1995-12-17T03:24:00"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"type": "CryptoCurrency",
|
|
4
|
+
"id": "bitcoin",
|
|
5
|
+
"ticker": "BTC",
|
|
6
|
+
"name": "Bitcoin",
|
|
7
|
+
"family": "bitcoin",
|
|
8
|
+
"color": "#ffae35",
|
|
9
|
+
"decimals": 8
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "CryptoCurrency",
|
|
13
|
+
"id": "ethereum",
|
|
14
|
+
"ticker": "ETH",
|
|
15
|
+
"name": "Ethereum",
|
|
16
|
+
"family": "ethereum",
|
|
17
|
+
"color": "#0ebdcd",
|
|
18
|
+
"decimals": 18
|
|
19
|
+
}
|
|
20
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/profiles/standard/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASpD,eAAO,MAAM,eAAe,EAAE,gBAuC7B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { deserializeAccount, } from "@ledgerhq/wallet-api-core";
|
|
2
|
+
import { firstValueFrom } from "rxjs";
|
|
3
|
+
import rawAccounts from "./accounts.json";
|
|
4
|
+
import rawCurrencies from "./currencies.json";
|
|
5
|
+
const allCurrencies = rawCurrencies;
|
|
6
|
+
const allAccounts = rawAccounts.map(deserializeAccount);
|
|
7
|
+
export const standardProfile = {
|
|
8
|
+
permissions: {
|
|
9
|
+
currencyIds: ["ethereum", "bitcoin"],
|
|
10
|
+
methodIds: [
|
|
11
|
+
"account.request",
|
|
12
|
+
"currency.list",
|
|
13
|
+
"account.list",
|
|
14
|
+
"transaction.signAndBroadcast",
|
|
15
|
+
"transaction.sign",
|
|
16
|
+
"message.sign",
|
|
17
|
+
"account.receive",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
accounts: allAccounts,
|
|
21
|
+
currencies: allCurrencies,
|
|
22
|
+
methods: {
|
|
23
|
+
"account.request": async ({ accounts$ }) => {
|
|
24
|
+
const accounts = await firstValueFrom(accounts$);
|
|
25
|
+
if (!accounts[0]) {
|
|
26
|
+
throw new Error("No accounts available");
|
|
27
|
+
}
|
|
28
|
+
return accounts[0];
|
|
29
|
+
},
|
|
30
|
+
"transaction.signAndBroadcast": () => {
|
|
31
|
+
return "0xtxHash";
|
|
32
|
+
},
|
|
33
|
+
"transaction.sign": () => {
|
|
34
|
+
return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
|
|
35
|
+
},
|
|
36
|
+
"message.sign": () => {
|
|
37
|
+
return Buffer.from("0x123456789123456789");
|
|
38
|
+
},
|
|
39
|
+
"account.receive": () => {
|
|
40
|
+
return "eth address";
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
package/lib-es/test-run.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { WalletAPIClient } from "@ledgerhq/wallet-api-client/lib/WalletAPIClient";
|
|
2
|
+
import { profiles } from "./profiles";
|
|
2
3
|
// import { deserializeTransaction } from "@ledgerhq/wallet-api-core";
|
|
3
4
|
import { getSimulatorTransport } from "./transport";
|
|
4
5
|
async function main() {
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
const transport = getSimulatorTransport(
|
|
7
|
+
const transport = getSimulatorTransport(profiles.STANDARD);
|
|
7
8
|
const client = new WalletAPIClient(transport);
|
|
8
9
|
await client.listAccounts({ currencyIds: ["ethereum"] });
|
|
9
10
|
/* transport.send(
|
package/lib-es/transport.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Transport } from "@ledgerhq/wallet-api-core";
|
|
2
|
-
|
|
2
|
+
import type { SimulatorProfile } from "./types";
|
|
3
|
+
export declare function getSimulatorTransport(profile: SimulatorProfile): Transport;
|
|
3
4
|
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA2B1E"}
|
package/lib-es/transport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletAPIServer } from "@ledgerhq/wallet-api-server";
|
|
2
|
-
import {
|
|
3
|
-
export function getSimulatorTransport(
|
|
2
|
+
import { applyProfile } from "./helpers";
|
|
3
|
+
export function getSimulatorTransport(profile) {
|
|
4
4
|
let clientTransport;
|
|
5
5
|
const serverTransport = {
|
|
6
6
|
onMessage: undefined,
|
|
@@ -21,15 +21,6 @@ export function getSimulatorTransport(_profileId) {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
const serverInstance = new WalletAPIServer(serverTransport);
|
|
24
|
-
serverInstance
|
|
25
|
-
methodIds: [
|
|
26
|
-
"account.request",
|
|
27
|
-
"account.list",
|
|
28
|
-
"currency.list",
|
|
29
|
-
"transaction.signAndBroadcast",
|
|
30
|
-
],
|
|
31
|
-
currencyIds: ["eth*"],
|
|
32
|
-
});
|
|
33
|
-
setProfile(serverInstance);
|
|
24
|
+
applyProfile(serverInstance, profile);
|
|
34
25
|
return clientTransport;
|
|
35
26
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Account, Currency, Permission } from "@ledgerhq/wallet-api-core";
|
|
2
|
+
import type { WalletHandlers } from "@ledgerhq/wallet-api-server";
|
|
3
|
+
export declare type SimulatorProfile = {
|
|
4
|
+
permissions: Permission;
|
|
5
|
+
accounts: Account[];
|
|
6
|
+
currencies: Currency[];
|
|
7
|
+
methods: Partial<WalletHandlers>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,oBAAY,gBAAgB,GAAG;IAC7B,WAAW,EAAE,UAAU,CAAC;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;CAClC,CAAC"}
|
package/lib-es/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/wallet-api-simulator",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"typescript": "^4.8.4"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ledgerhq/wallet-api-client": "0.
|
|
27
|
-
"@ledgerhq/wallet-api-core": "0.
|
|
28
|
-
"@ledgerhq/wallet-api-server": "0.
|
|
26
|
+
"@ledgerhq/wallet-api-client": "0.7.1",
|
|
27
|
+
"@ledgerhq/wallet-api-core": "0.7.0",
|
|
28
|
+
"@ledgerhq/wallet-api-server": "0.7.1",
|
|
29
29
|
"rxjs": "^7.5.7",
|
|
30
30
|
"ws": "^8.10.0"
|
|
31
31
|
},
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setProfile = void 0;
|
|
4
|
-
const wallet_api_core_1 = require("@ledgerhq/wallet-api-core");
|
|
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
|
-
];
|
|
26
|
-
const cryptoAccounts = [
|
|
27
|
-
{
|
|
28
|
-
id: "account-btc-1",
|
|
29
|
-
name: "Bitcoin 1",
|
|
30
|
-
address: "address",
|
|
31
|
-
currency: "bitcoin",
|
|
32
|
-
balance: "42",
|
|
33
|
-
spendableBalance: "42",
|
|
34
|
-
blockHeight: 1,
|
|
35
|
-
lastSyncDate: "1995-12-17T03:24:00",
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "account-eth-1",
|
|
39
|
-
name: "Ethereum 1",
|
|
40
|
-
address: "address",
|
|
41
|
-
currency: "ethereum",
|
|
42
|
-
balance: "42",
|
|
43
|
-
spendableBalance: "42",
|
|
44
|
-
blockHeight: 1,
|
|
45
|
-
lastSyncDate: "1995-12-17T03:24:00",
|
|
46
|
-
},
|
|
47
|
-
].map(wallet_api_core_1.deserializeAccount);
|
|
48
|
-
function setProfile(serverInstance) {
|
|
49
|
-
serverInstance.setAccounts(cryptoAccounts);
|
|
50
|
-
serverInstance.setCurrencies(currencies);
|
|
51
|
-
serverInstance.setHandler("account.request", async ({ accounts$ }) => {
|
|
52
|
-
const accounts = await (0, rxjs_1.firstValueFrom)(accounts$);
|
|
53
|
-
if (!accounts[0]) {
|
|
54
|
-
throw new Error("No accounts available");
|
|
55
|
-
}
|
|
56
|
-
return accounts[0];
|
|
57
|
-
});
|
|
58
|
-
serverInstance.setHandler("transaction.signAndBroadcast", () => {
|
|
59
|
-
return "0xtxHash";
|
|
60
|
-
});
|
|
61
|
-
serverInstance.setHandler("transaction.sign", () => {
|
|
62
|
-
return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
|
|
63
|
-
});
|
|
64
|
-
serverInstance.setHandler("message.sign", () => {
|
|
65
|
-
return Buffer.from("0x123456789123456789");
|
|
66
|
-
});
|
|
67
|
-
serverInstance.setHandler("account.receive", () => {
|
|
68
|
-
return "eth address";
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.setProfile = setProfile;
|
|
@@ -1 +0,0 @@
|
|
|
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,67 +0,0 @@
|
|
|
1
|
-
import { deserializeAccount, } from "@ledgerhq/wallet-api-core";
|
|
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
|
-
];
|
|
23
|
-
const cryptoAccounts = [
|
|
24
|
-
{
|
|
25
|
-
id: "account-btc-1",
|
|
26
|
-
name: "Bitcoin 1",
|
|
27
|
-
address: "address",
|
|
28
|
-
currency: "bitcoin",
|
|
29
|
-
balance: "42",
|
|
30
|
-
spendableBalance: "42",
|
|
31
|
-
blockHeight: 1,
|
|
32
|
-
lastSyncDate: "1995-12-17T03:24:00",
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: "account-eth-1",
|
|
36
|
-
name: "Ethereum 1",
|
|
37
|
-
address: "address",
|
|
38
|
-
currency: "ethereum",
|
|
39
|
-
balance: "42",
|
|
40
|
-
spendableBalance: "42",
|
|
41
|
-
blockHeight: 1,
|
|
42
|
-
lastSyncDate: "1995-12-17T03:24:00",
|
|
43
|
-
},
|
|
44
|
-
].map(deserializeAccount);
|
|
45
|
-
export function setProfile(serverInstance) {
|
|
46
|
-
serverInstance.setAccounts(cryptoAccounts);
|
|
47
|
-
serverInstance.setCurrencies(currencies);
|
|
48
|
-
serverInstance.setHandler("account.request", async ({ accounts$ }) => {
|
|
49
|
-
const accounts = await firstValueFrom(accounts$);
|
|
50
|
-
if (!accounts[0]) {
|
|
51
|
-
throw new Error("No accounts available");
|
|
52
|
-
}
|
|
53
|
-
return accounts[0];
|
|
54
|
-
});
|
|
55
|
-
serverInstance.setHandler("transaction.signAndBroadcast", () => {
|
|
56
|
-
return "0xtxHash";
|
|
57
|
-
});
|
|
58
|
-
serverInstance.setHandler("transaction.sign", () => {
|
|
59
|
-
return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
|
|
60
|
-
});
|
|
61
|
-
serverInstance.setHandler("message.sign", () => {
|
|
62
|
-
return Buffer.from("0x123456789123456789");
|
|
63
|
-
});
|
|
64
|
-
serverInstance.setHandler("account.receive", () => {
|
|
65
|
-
return "eth address";
|
|
66
|
-
});
|
|
67
|
-
}
|