-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
64 lines (57 loc) · 1.99 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Transport from "@ledgerhq/hw-transport";
import SpeculosTransport from "@ledgerhq/hw-transport-node-speculos-http";
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
import Aptos from "./src/Aptos";
async function exampleRaw(transport: Transport) {
console.log("getVersion(raw)", await transport.send(0x5b, 0x03, 0x00, 0x00));
}
async function exampleAptos(transport: Transport) {
const aptosClient = new Aptos(transport);
console.log("getVersion", await aptosClient.getVersion());
console.log(
"getAddress",
await aptosClient.getAddress("m/44'/637'/1'/0'/0'", true)
);
const tx = Buffer.from(
"b5e97db07fa0bd0e5598aa3643a9bc6f6693bddc1a9fec9e674a461eaa00b193783135e8b00430253a22ba041d860c373d7a1501ccf7ac2d1ad37a8ed2775aee000000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220094c6fc0d3b382a599c37e1aaa7618eff2c96a3586876082c4594c50c50d7dde082a00000000000000204e0000000000006400000000000000565c51630000000022",
"hex"
);
console.log(
"signTransaction",
(
await aptosClient.signTransaction("m/44'/637'/1'/0'/0'", tx)
).signature.toString("hex")
);
}
const args = process.argv.slice(2);
const main = async (): Promise<void> => {
const mode = args[0];
let transport: Transport;
switch (mode) {
case "hid":
transport = await TransportNodeHid.open(null);
break;
case "headless":
transport = await SpeculosTransport.open({
baseURL: "http://localhost:5000",
});
break;
default:
console.error(
"Transport mode is not specified, available options: hid, headless"
);
return;
}
try {
await exampleRaw(transport);
await exampleAptos(transport);
} catch (err) {
console.log(err);
} finally {
await transport.close();
}
};
main().catch((error) => {
console.error(error);
process.exit(1);
});