@ledgerhq/wallet-api-simulator 0.2.0 → 0.4.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/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./transport";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./transport"), exports);
@@ -0,0 +1,3 @@
1
+ import type { WalletAPIServer } from "@ledgerhq/wallet-api-server";
2
+ export declare function setProfile(serverInstance: WalletAPIServer): void;
3
+ //# sourceMappingURL=standard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA0BnE,wBAAgB,UAAU,CAAC,cAAc,EAAE,eAAe,QA6BzD"}
@@ -0,0 +1,50 @@
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 cryptoAccounts = [
7
+ {
8
+ id: "account-btc-1",
9
+ name: "Bitcoin 1",
10
+ address: "address",
11
+ currency: "bitcoin",
12
+ balance: "42",
13
+ spendableBalance: "42",
14
+ blockHeight: 1,
15
+ lastSyncDate: "1995-12-17T03:24:00",
16
+ },
17
+ {
18
+ id: "account-eth-1",
19
+ name: "Ethereum 1",
20
+ address: "address",
21
+ currency: "ethereum",
22
+ balance: "42",
23
+ spendableBalance: "42",
24
+ blockHeight: 1,
25
+ lastSyncDate: "1995-12-17T03:24:00",
26
+ },
27
+ ].map(wallet_api_core_1.deserializeAccount);
28
+ function setProfile(serverInstance) {
29
+ serverInstance.setAccounts(cryptoAccounts);
30
+ serverInstance.setHandler("account.request", async ({ accounts$ }) => {
31
+ const accounts = await (0, rxjs_1.firstValueFrom)(accounts$);
32
+ if (!accounts[0]) {
33
+ throw new Error("nope");
34
+ }
35
+ return accounts[0];
36
+ });
37
+ serverInstance.setHandler("transaction.signAndBroadcast", () => {
38
+ return "0xtxHash";
39
+ });
40
+ serverInstance.setHandler("transaction.sign", () => {
41
+ return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
42
+ });
43
+ serverInstance.setHandler("message.sign", () => {
44
+ return Buffer.from("0x123456789123456789");
45
+ });
46
+ serverInstance.setHandler("account.receive", () => {
47
+ return "eth address";
48
+ });
49
+ }
50
+ exports.setProfile = setProfile;
@@ -0,0 +1,3 @@
1
+ import type { Transport } from "@ledgerhq/wallet-api-core";
2
+ export declare function getSimulatorTransport(_profileId: string): Transport;
3
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +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,CA0BnE"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSimulatorTransport = void 0;
4
+ const wallet_api_server_1 = require("@ledgerhq/wallet-api-server");
5
+ const standard_1 = require("./profiles/standard");
6
+ function getSimulatorTransport(_profileId) {
7
+ let clientTransport;
8
+ const serverTransport = {
9
+ onMessage: undefined,
10
+ send: (payload) => {
11
+ if (clientTransport && clientTransport.onMessage) {
12
+ clientTransport.onMessage(payload);
13
+ }
14
+ },
15
+ };
16
+ clientTransport = {
17
+ onMessage: undefined,
18
+ send: (payload) => {
19
+ if (serverTransport && serverTransport.onMessage) {
20
+ serverTransport.onMessage(payload);
21
+ }
22
+ },
23
+ };
24
+ const serverInstance = new wallet_api_server_1.WalletAPIServer(serverTransport);
25
+ (0, standard_1.setProfile)(serverInstance);
26
+ return clientTransport;
27
+ }
28
+ exports.getSimulatorTransport = getSimulatorTransport;
package/lib/ws.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":""}
package/lib/ws.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ws_1 = require("ws");
4
+ const wss = new ws_1.WebSocketServer({ port: 8080 });
5
+ wss.on("connection", function onConnect(ws) {
6
+ ws.on("message", function onMessage(data) {
7
+ console.log("received: %s", data);
8
+ });
9
+ ws.send("something");
10
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./transport";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./transport";
@@ -0,0 +1,3 @@
1
+ import type { WalletAPIServer } from "@ledgerhq/wallet-api-server";
2
+ export declare function setProfile(serverInstance: WalletAPIServer): void;
3
+ //# sourceMappingURL=standard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/profiles/standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA0BnE,wBAAgB,UAAU,CAAC,cAAc,EAAE,eAAe,QA6BzD"}
@@ -0,0 +1,46 @@
1
+ import { deserializeAccount } from "@ledgerhq/wallet-api-core";
2
+ import { firstValueFrom } from "rxjs";
3
+ const cryptoAccounts = [
4
+ {
5
+ id: "account-btc-1",
6
+ name: "Bitcoin 1",
7
+ address: "address",
8
+ currency: "bitcoin",
9
+ balance: "42",
10
+ spendableBalance: "42",
11
+ blockHeight: 1,
12
+ lastSyncDate: "1995-12-17T03:24:00",
13
+ },
14
+ {
15
+ id: "account-eth-1",
16
+ name: "Ethereum 1",
17
+ address: "address",
18
+ currency: "ethereum",
19
+ balance: "42",
20
+ spendableBalance: "42",
21
+ blockHeight: 1,
22
+ lastSyncDate: "1995-12-17T03:24:00",
23
+ },
24
+ ].map(deserializeAccount);
25
+ export function setProfile(serverInstance) {
26
+ serverInstance.setAccounts(cryptoAccounts);
27
+ serverInstance.setHandler("account.request", async ({ accounts$ }) => {
28
+ const accounts = await firstValueFrom(accounts$);
29
+ if (!accounts[0]) {
30
+ throw new Error("nope");
31
+ }
32
+ return accounts[0];
33
+ });
34
+ serverInstance.setHandler("transaction.signAndBroadcast", () => {
35
+ return "0xtxHash";
36
+ });
37
+ serverInstance.setHandler("transaction.sign", () => {
38
+ return Buffer.from("0x123O182493423928734983247923847293847293847923847293487");
39
+ });
40
+ serverInstance.setHandler("message.sign", () => {
41
+ return Buffer.from("0x123456789123456789");
42
+ });
43
+ serverInstance.setHandler("account.receive", () => {
44
+ return "eth address";
45
+ });
46
+ }
@@ -0,0 +1,3 @@
1
+ import type { Transport } from "@ledgerhq/wallet-api-core";
2
+ export declare function getSimulatorTransport(_profileId: string): Transport;
3
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +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,CA0BnE"}
@@ -0,0 +1,24 @@
1
+ import { WalletAPIServer } from "@ledgerhq/wallet-api-server";
2
+ import { setProfile } from "./profiles/standard";
3
+ export function getSimulatorTransport(_profileId) {
4
+ let clientTransport;
5
+ const serverTransport = {
6
+ onMessage: undefined,
7
+ send: (payload) => {
8
+ if (clientTransport && clientTransport.onMessage) {
9
+ clientTransport.onMessage(payload);
10
+ }
11
+ },
12
+ };
13
+ clientTransport = {
14
+ onMessage: undefined,
15
+ send: (payload) => {
16
+ if (serverTransport && serverTransport.onMessage) {
17
+ serverTransport.onMessage(payload);
18
+ }
19
+ },
20
+ };
21
+ const serverInstance = new WalletAPIServer(serverTransport);
22
+ setProfile(serverInstance);
23
+ return clientTransport;
24
+ }
package/lib-es/ws.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":""}
@@ -1,11 +1,8 @@
1
1
  import { WebSocketServer } from "ws";
2
-
3
2
  const wss = new WebSocketServer({ port: 8080 });
4
-
5
3
  wss.on("connection", function onConnect(ws) {
6
- ws.on("message", function onMessage(data) {
7
- console.log("received: %s", data);
8
- });
9
-
10
- ws.send("something");
4
+ ws.on("message", function onMessage(data) {
5
+ console.log("received: %s", data);
6
+ });
7
+ ws.send("something");
11
8
  });
package/package.json CHANGED
@@ -1,28 +1,34 @@
1
1
  {
2
2
  "name": "@ledgerhq/wallet-api-simulator",
3
- "version": "0.2.0",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
3
+ "version": "0.4.0",
6
4
  "license": "MIT",
5
+ "main": "lib/index.js",
6
+ "module": "lib-es/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "files": [
9
+ "/lib",
10
+ "/lib-es"
11
+ ],
7
12
  "devDependencies": {
8
- "@tsconfig/node16-strictest-esm": "^1.0.3",
9
- "@types/node": "^18.7.18",
13
+ "@tsconfig/node18-strictest": "^1.0.0",
14
+ "@types/node": "^18.11.8",
10
15
  "@types/ws": "^8.5.3",
11
- "eslint": "^7.32.0",
12
- "tsup": "^6.2.3",
13
- "typescript": "^4.5.2"
16
+ "eslint": "^8.26.0",
17
+ "typescript": "^4.8.4"
14
18
  },
15
19
  "dependencies": {
16
- "@ledgerhq/wallet-api-core": "0.2.0",
17
- "@ledgerhq/wallet-api-server": "0.2.0",
20
+ "@ledgerhq/wallet-api-client": "0.4.0",
21
+ "@ledgerhq/wallet-api-core": "0.4.0",
22
+ "@ledgerhq/wallet-api-server": "0.4.0",
18
23
  "rxjs": "^7.5.7",
19
- "ws": "^8.9.0"
24
+ "ws": "^8.10.0"
20
25
  },
21
26
  "scripts": {
22
27
  "format:check": "prettier --check \"src\"",
23
28
  "format:fix": "prettier --write \"src\"",
24
29
  "lint": "eslint --cache --ext .ts \"src\"",
25
30
  "lint:fix": "eslint --cache --fix --ext .ts \"src\"",
26
- "build": "tsup src/index.ts --dts --format esm,cjs,iife"
31
+ "dev": "tsc -p prod.tsconfig.json --watch",
32
+ "build": "rm -rf lib/* lib-es/* && tsc -p prod.tsconfig.json && tsc -p prod-esm.tsconfig.json"
27
33
  }
28
34
  }
package/.eslintcache DELETED
@@ -1 +0,0 @@
1
- [{"/home/runner/work/wallet-api/wallet-api/packages/simulator/src/index.ts":"1","/home/runner/work/wallet-api/wallet-api/packages/simulator/src/ws.ts":"2"},{"size":1484,"mtime":1666780950117,"results":"3","hashOfConfig":"4"},{"size":255,"mtime":1666780950121,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"74kbob",{"filePath":"8","messages":"9","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/home/runner/work/wallet-api/wallet-api/packages/simulator/src/index.ts",["10"],"/home/runner/work/wallet-api/wallet-api/packages/simulator/src/ws.ts",["11"],{"ruleId":"12","severity":1,"message":"13","line":15,"column":5,"nodeType":"14","messageId":"15","endLine":15,"endColumn":16},{"ruleId":"12","severity":1,"message":"13","line":7,"column":5,"nodeType":"14","messageId":"15","endLine":7,"endColumn":16},"no-console","Unexpected console statement.","MemberExpression","unexpected"]
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- env: {
3
- es2021: true,
4
- node: true,
5
- },
6
- parserOptions: {
7
- project: ["./tsconfig.json"],
8
- tsconfigRootDir: __dirname,
9
- },
10
- rules: {
11
- "no-underscore-dangle": "off",
12
- "class-methods-use-this": "warn",
13
- },
14
- };
@@ -1,21 +0,0 @@
1
- @ledgerhq/wallet-api-simulator:build: cache hit, replaying output 63c2d2000a87570e
2
- @ledgerhq/wallet-api-simulator:build:
3
- @ledgerhq/wallet-api-simulator:build: > @ledgerhq/wallet-api-simulator@0.2.0 build /home/runner/work/wallet-api/wallet-api/packages/simulator
4
- @ledgerhq/wallet-api-simulator:build: > tsup src/index.ts --dts --format esm,cjs,iife
5
- @ledgerhq/wallet-api-simulator:build:
6
- @ledgerhq/wallet-api-simulator:build: CLI Building entry: src/index.ts
7
- @ledgerhq/wallet-api-simulator:build: CLI Using tsconfig: tsconfig.json
8
- @ledgerhq/wallet-api-simulator:build: CLI tsup v6.2.3
9
- @ledgerhq/wallet-api-simulator:build: CLI Target: node14
10
- @ledgerhq/wallet-api-simulator:build: ESM Build start
11
- @ledgerhq/wallet-api-simulator:build: CJS Build start
12
- @ledgerhq/wallet-api-simulator:build: IIFE Build start
13
- @ledgerhq/wallet-api-simulator:build: CJS dist/index.js 1.46 KB
14
- @ledgerhq/wallet-api-simulator:build: CJS ⚡️ Build success in 257ms
15
- @ledgerhq/wallet-api-simulator:build: ESM dist/index.mjs 1.33 KB
16
- @ledgerhq/wallet-api-simulator:build: ESM ⚡️ Build success in 358ms
17
- @ledgerhq/wallet-api-simulator:build: IIFE dist/index.global.js 581.40 KB
18
- @ledgerhq/wallet-api-simulator:build: IIFE ⚡️ Build success in 410ms
19
- @ledgerhq/wallet-api-simulator:build: DTS Build start
20
- @ledgerhq/wallet-api-simulator:build: DTS ⚡️ Build success in 6720ms
21
- @ledgerhq/wallet-api-simulator:build: DTS dist/index.d.ts 1.00 B
@@ -1,14 +0,0 @@
1
- @ledgerhq/wallet-api-simulator:lint: cache hit, replaying output f76e9a6e235e6dd8
2
- @ledgerhq/wallet-api-simulator:lint:
3
- @ledgerhq/wallet-api-simulator:lint: > @ledgerhq/wallet-api-simulator@0.2.0 lint /home/runner/work/wallet-api/wallet-api/packages/simulator
4
- @ledgerhq/wallet-api-simulator:lint: > eslint --cache --ext .ts "src"
5
- @ledgerhq/wallet-api-simulator:lint:
6
- @ledgerhq/wallet-api-simulator:lint:
7
- @ledgerhq/wallet-api-simulator:lint: /home/runner/work/wallet-api/wallet-api/packages/simulator/src/index.ts
8
- @ledgerhq/wallet-api-simulator:lint: 15:5 warning Unexpected console statement no-console
9
- @ledgerhq/wallet-api-simulator:lint:
10
- @ledgerhq/wallet-api-simulator:lint: /home/runner/work/wallet-api/wallet-api/packages/simulator/src/ws.ts
11
- @ledgerhq/wallet-api-simulator:lint: 7:5 warning Unexpected console statement no-console
12
- @ledgerhq/wallet-api-simulator:lint:
13
- @ledgerhq/wallet-api-simulator:lint: ✖ 2 problems (0 errors, 2 warnings)
14
- @ledgerhq/wallet-api-simulator:lint:
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- # @ledgerhq/wallet-api-simulator
2
-
3
- ## 0.2.0
4
-
5
- ### Minor Changes
6
-
7
- - [#23](https://github.com/LedgerHQ/wallet-api/pull/23) [`3125934`](https://github.com/LedgerHQ/wallet-api/commit/3125934f3137f292231c59df1d1fa7d220a10eb7) Thanks [@IAmMorrow](https://github.com/IAmMorrow)! - Implemented most of the wallet-api-server.
8
-
9
- ### Patch Changes
10
-
11
- - Updated dependencies [[`3125934`](https://github.com/LedgerHQ/wallet-api/commit/3125934f3137f292231c59df1d1fa7d220a10eb7)]:
12
- - @ledgerhq/wallet-api-core@0.2.0
13
- - @ledgerhq/wallet-api-server@0.2.0
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
-