@ledgerhq/wallet-api-simulator 0.1.0 → 0.3.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 +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/profiles/standard.d.ts +3 -0
- package/lib/profiles/standard.d.ts.map +1 -0
- package/lib/profiles/standard.js +50 -0
- package/lib/transport.d.ts +3 -0
- package/lib/transport.d.ts.map +1 -0
- package/lib/transport.js +28 -0
- package/lib/ws.d.ts +2 -0
- package/lib/ws.d.ts.map +1 -0
- package/lib/ws.js +10 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +1 -0
- package/lib-es/profiles/standard.d.ts +3 -0
- package/lib-es/profiles/standard.d.ts.map +1 -0
- package/lib-es/profiles/standard.js +46 -0
- package/lib-es/transport.d.ts +3 -0
- package/lib-es/transport.d.ts.map +1 -0
- package/lib-es/transport.js +24 -0
- package/lib-es/ws.d.ts +2 -0
- package/lib-es/ws.d.ts.map +1 -0
- package/lib-es/ws.js +8 -0
- package/package.json +20 -11
- package/.eslintcache +0 -1
- package/.eslintrc.js +0 -14
- package/.turbo/turbo-build.log +0 -21
- package/.turbo/turbo-lint.log +0 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.global.js +0 -3188
- package/dist/index.js +0 -28
- package/dist/index.mjs +0 -8
- package/src/index.ts +0 -10
- package/tsconfig.json +0 -9
package/lib/index.d.ts
ADDED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/lib/transport.js
ADDED
|
@@ -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
package/lib/ws.d.ts.map
ADDED
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/lib-es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transport";
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":""}
|
package/lib-es/ws.js
ADDED
package/package.json
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/wallet-api-simulator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "0.3.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/
|
|
9
|
-
"@types/node": "^18.
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"typescript": "^4.
|
|
13
|
+
"@tsconfig/node18-strictest": "^1.0.0",
|
|
14
|
+
"@types/node": "^18.11.8",
|
|
15
|
+
"@types/ws": "^8.5.3",
|
|
16
|
+
"eslint": "^8.26.0",
|
|
17
|
+
"typescript": "^4.8.4"
|
|
13
18
|
},
|
|
14
19
|
"dependencies": {
|
|
15
|
-
"@ledgerhq/wallet-api-
|
|
16
|
-
"@ledgerhq/wallet-api-
|
|
20
|
+
"@ledgerhq/wallet-api-client": "0.3.0",
|
|
21
|
+
"@ledgerhq/wallet-api-core": "0.3.0",
|
|
22
|
+
"@ledgerhq/wallet-api-server": "0.3.0",
|
|
23
|
+
"rxjs": "^7.5.7",
|
|
24
|
+
"ws": "^8.10.0"
|
|
17
25
|
},
|
|
18
26
|
"scripts": {
|
|
19
27
|
"format:check": "prettier --check \"src\"",
|
|
20
28
|
"format:fix": "prettier --write \"src\"",
|
|
21
29
|
"lint": "eslint --cache --ext .ts \"src\"",
|
|
22
30
|
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
|
|
23
|
-
"
|
|
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"
|
|
24
33
|
}
|
|
25
34
|
}
|
package/.eslintcache
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{"/home/runner/work/wallet-api/wallet-api/packages/simulator/src/index.ts":"1"},{"size":276,"mtime":1665647406794,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"12w64hs","/home/runner/work/wallet-api/wallet-api/packages/simulator/src/index.ts",[]]
|
package/.eslintrc.js
DELETED
package/.turbo/turbo-build.log
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
@ledgerhq/wallet-api-simulator:build: cache hit, replaying output c9bf4161f48af9d0
|
|
2
|
-
@ledgerhq/wallet-api-simulator:build:
|
|
3
|
-
@ledgerhq/wallet-api-simulator:build: > @ledgerhq/wallet-api-simulator@0.1.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: [34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
@ledgerhq/wallet-api-simulator:build: [34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
-
@ledgerhq/wallet-api-simulator:build: [34mCLI[39m tsup v6.2.3
|
|
9
|
-
@ledgerhq/wallet-api-simulator:build: [34mCLI[39m Target: node14
|
|
10
|
-
@ledgerhq/wallet-api-simulator:build: [34mESM[39m Build start
|
|
11
|
-
@ledgerhq/wallet-api-simulator:build: [34mCJS[39m Build start
|
|
12
|
-
@ledgerhq/wallet-api-simulator:build: [34mIIFE[39m Build start
|
|
13
|
-
@ledgerhq/wallet-api-simulator:build: [32mESM[39m [1mdist/index.mjs [22m[32m285.00 B[39m
|
|
14
|
-
@ledgerhq/wallet-api-simulator:build: [32mESM[39m ⚡️ Build success in 96ms
|
|
15
|
-
@ledgerhq/wallet-api-simulator:build: [32mCJS[39m [1mdist/index.js [22m[32m1.22 KB[39m
|
|
16
|
-
@ledgerhq/wallet-api-simulator:build: [32mCJS[39m ⚡️ Build success in 79ms
|
|
17
|
-
@ledgerhq/wallet-api-simulator:build: [32mIIFE[39m [1mdist/index.global.js [22m[32m114.66 KB[39m
|
|
18
|
-
@ledgerhq/wallet-api-simulator:build: [32mIIFE[39m ⚡️ Build success in 79ms
|
|
19
|
-
@ledgerhq/wallet-api-simulator:build: [34mDTS[39m Build start
|
|
20
|
-
@ledgerhq/wallet-api-simulator:build: [32mDTS[39m ⚡️ Build success in 5148ms
|
|
21
|
-
@ledgerhq/wallet-api-simulator:build: [32mDTS[39m [1mdist/index.d.ts [22m[32m1.00 B[39m
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
@ledgerhq/wallet-api-simulator:lint: cache hit, replaying output ce0d40c93226453d
|
|
2
|
-
@ledgerhq/wallet-api-simulator:lint:
|
|
3
|
-
@ledgerhq/wallet-api-simulator:lint: > @ledgerhq/wallet-api-simulator@0.1.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:
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|