1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | exports.SXP = void 0;
|
23 | const Apdu = __importStar(require("./apdu"));
|
24 | const Bip44 = __importStar(require("./bip44"));
|
25 | const TransportErrors = __importStar(require("./errors"));
|
26 | class SXP {
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | constructor(transport) {
|
36 | Object.defineProperty(this, "transport", {
|
37 | enumerable: true,
|
38 | configurable: true,
|
39 | writable: true,
|
40 | value: void 0
|
41 | });
|
42 | this.transport = transport;
|
43 | this.transport.decorateAppAPIMethods(this, ["getVersion", "getPublicKey", "getExtPublicKey", "signMessageWithSchnorr", "signTransactionWithSchnorr"], "w0w");
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 | async getVersion() {
|
51 | const response = await new Apdu.Builder(Apdu.Flag.CLA, Apdu.Flag.INS_GET_VERSION, Apdu.Flag.P1_NON_CONFIRM, Apdu.Flag.P2_NO_CHAINCODE).send(this.transport);
|
52 | return `${response[1]}.${response[2]}.${response[3]}`;
|
53 | }
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | async getPublicKey(path) {
|
61 | const response = await new Apdu.Builder(Apdu.Flag.CLA, Apdu.Flag.INS_GET_PUBLIC_KEY, Apdu.Flag.P1_NON_CONFIRM, Apdu.Flag.P2_NO_CHAINCODE, Bip44.Path.fromString(path).toBytes()).send(this.transport);
|
62 | return response.slice(1, response.length).toString("hex");
|
63 | }
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | async getExtPublicKey(path) {
|
74 | const response = await new Apdu.Builder(Apdu.Flag.CLA, Apdu.Flag.INS_GET_PUBLIC_KEY, Apdu.Flag.P1_NON_CONFIRM, Apdu.Flag.P2_CHAINCODE, Bip44.Path.fromString(path).toBytes()).send(this.transport);
|
75 | return response.slice(1, response.length).toString("hex");
|
76 | }
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | async signMessageWithSchnorr(path, message) {
|
85 | this.checkMessageFormat(message);
|
86 | const response = await new Apdu.Builder(Apdu.Flag.CLA, Apdu.Flag.INS_SIGN_MESSAGE, Apdu.Flag.P1_SINGLE, Apdu.Flag.P2_SCHNORR_LEG, Buffer.concat([Bip44.Path.fromString(path).toBytes(), message])).send(this.transport);
|
87 | return response.toString("hex");
|
88 | }
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | async signTransactionWithSchnorr(path, payload) {
|
97 | const response = await new Apdu.Builder(Apdu.Flag.CLA, Apdu.Flag.INS_SIGN_TRANSACTION, Apdu.Flag.P1_SINGLE, Apdu.Flag.P2_SCHNORR_LEG, Buffer.concat([Bip44.Path.fromString(path).toBytes(), payload])).send(this.transport);
|
98 | return response.toString("hex");
|
99 | }
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | checkMessageFormat(message) {
|
107 | const REGEXP_INVALID_MESSAGE = "[^\x00-\x7F]";
|
108 | if (message.toString().match(new RegExp(REGEXP_INVALID_MESSAGE, "g"))) {
|
109 | throw new TransportErrors.MessageAsciiError();
|
110 | }
|
111 | }
|
112 | }
|
113 | exports.SXP = SXP;
|
114 |
|
\ | No newline at end of file |