@siacentral/ledgerjs-sia 1.2.8 → 2.0.1

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/README.md CHANGED
@@ -13,19 +13,24 @@ Static javascript builds are available on the releases page.
13
13
  ## Package Usage
14
14
  ```js
15
15
  import Sia from '@siacentral/ledgerjs-sia';
16
- import TransportWebHID from '@ledgerhq/hw-transport-webhid';
17
16
 
18
17
  /**
19
- * connect connects to the plugged in Ledger using the WebHID transport
20
- * and returns the first Sia address of the ledger wallet.
18
+ * connect connects to the plugged in Ledger and returns the first Sia address
19
+ * of the ledger wallet. connectWebHID / connectBLE launch the Sia app from the
20
+ * dashboard if it isn't already open and return a ready instance.
21
21
  */
22
22
  async function connect() {
23
23
  let sia;
24
24
  try {
25
- const transport = await TransportWebHID.create();
26
- sia = new Sia(transport);
27
-
28
- const address = await sia.getAddress(0);
25
+ // supportedTransports reports which transports work in this environment;
26
+ // offer the user a choice between USB (hid) and Bluetooth (ble).
27
+ const transports = await Sia.supportedTransports(); // e.g. ['hid', 'ble']
28
+
29
+ sia = transports.includes('hid')
30
+ ? await Sia.connectWebHID()
31
+ : await Sia.connectBLE();
32
+
33
+ const { address } = await sia.getAddress(0);
29
34
  console.log(address);
30
35
  } catch (ex) {
31
36
  // TODO: handle error
@@ -38,6 +43,10 @@ async function connect() {
38
43
  connect();
39
44
  ```
40
45
 
46
+ A transport may also be supplied directly via `new Sia(transport)` (e.g. a
47
+ Speculos transport for testing), or `Sia.open(createTransport)` to launch the
48
+ app using a custom transport factory.
49
+
41
50
  ## Static Usage
42
51
  ```html
43
52
  <script type="text/javascript" src="/js/sia.js"></script>
@@ -48,9 +57,8 @@ connect();
48
57
  */
49
58
  async function connect() {
50
59
  try {
51
- const transport = await TransportWebHID.create(),
52
- sia = new Sia(transport),
53
- address = await sia.getAddress(0);
60
+ const sia = await Sia.connectWebHID(),
61
+ { address } = await sia.getAddress(0);
54
62
 
55
63
  console.log(address);
56
64
  } catch (ex) {
package/lib/sia.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type Transport from "@ledgerhq/hw-transport";
4
2
  import { Buffer } from 'buffer';
5
- export declare function hex(b: Buffer): string;
3
+ type TransportFactory = () => Promise<Transport>;
6
4
  interface VerifyResponse {
7
5
  address: string;
8
6
  publicKey: string;
@@ -17,6 +15,50 @@ interface VerifyResponse {
17
15
  export default class Sia {
18
16
  transport: Transport;
19
17
  constructor(transport: Transport, scrambleKey?: string);
18
+ /**
19
+ * open connects a transport, ensures the Sia app is running, and returns a
20
+ * ready Sia instance. If the app is not already open it is launched from the
21
+ * dashboard; the device disconnects and reconnects when an app opens, so the
22
+ * transport is recreated via the provided factory until the app is ready.
23
+ * @param createTransport {TransportFactory} creates a transport, e.g. () => TransportWebHID.create()
24
+ * @param scrambleKey {string} the scramble key for the Sia app
25
+ * @returns {Sia} a Sia instance bound to a transport with the Sia app open
26
+ */
27
+ static open(createTransport: TransportFactory, scrambleKey?: string): Promise<Sia>;
28
+ /**
29
+ * connectWebHID connects to a Ledger over WebHID (USB), launching the Sia
30
+ * app from the dashboard if it isn't already open, and returns a ready Sia
31
+ * instance.
32
+ * @param scrambleKey {string} the scramble key for the Sia app
33
+ * @returns {Sia} a Sia instance with the Sia app open
34
+ */
35
+ static connectWebHID(scrambleKey?: string): Promise<Sia>;
36
+ /**
37
+ * connectBLE connects to a Ledger over Web Bluetooth, launching the Sia app
38
+ * from the dashboard if it isn't already open, and returns a ready Sia
39
+ * instance.
40
+ * @param scrambleKey {string} the scramble key for the Sia app
41
+ * @returns {Sia} a Sia instance with the Sia app open
42
+ */
43
+ static connectBLE(scrambleKey?: string): Promise<Sia>;
44
+ /**
45
+ * supportedTransports returns the transport methods available in the current
46
+ * environment. Web Bluetooth is excluded on Brave, which does not reliably
47
+ * support it.
48
+ * @returns {Array<'hid' | 'ble'>} the supported transport methods
49
+ */
50
+ static supportedTransports(): Promise<Array<'hid' | 'ble'>>;
51
+ /**
52
+ * exchangeTxnHash sends an encoded transaction to the device in 255-byte
53
+ * chunks and returns the response with the trailing status word stripped.
54
+ */
55
+ private exchangeTxnHash;
56
+ /**
57
+ * openApp launches the Sia app from the device's dashboard. The device
58
+ * disconnects and reconnects when the app opens, so the transport must be
59
+ * re-created before issuing further commands.
60
+ */
61
+ openApp(): Promise<void>;
20
62
  /**
21
63
  * getVersion returns the version of the Sia app
22
64
  *
@@ -24,51 +66,39 @@ export default class Sia {
24
66
  */
25
67
  getVersion(): Promise<string>;
26
68
  /**
27
- * verifyPublicKey returns the public key and standard Sia address for
69
+ * getPublicKey returns the public key and standard Sia address for
28
70
  * the provided public key index. The user will be asked to verify the
29
71
  * public key on the display. A standard address is defined as an address
30
72
  * having 1 public key, requiring 1 signature, and no timelock.
31
73
  * @param index {number} the index of the public key
32
74
  * @returns {VerifyResponse} the public key and standard address
33
75
  */
34
- verifyPublicKey(index: number): Promise<VerifyResponse>;
76
+ getPublicKey(index: number): Promise<VerifyResponse>;
35
77
  /**
36
- * verifyStandardAddress returns the public key and standard Sia address for
78
+ * getAddress returns the public key and standard Sia address for
37
79
  * the provided public key index. The user will be asked to verify the
38
80
  * address on the display. A standard address is defined as an address
39
81
  * having 1 public key, requiring 1 signature, and no timelock.
40
82
  * @param index {number} the index of the public key
41
83
  * @returns {VerifyResponse} the public key and standard address
42
84
  */
43
- verifyStandardAddress(index: number): Promise<VerifyResponse>;
44
- /**
45
- * signTransactionV044 signs the transaction with the provided key
46
- * @deprecated deprecated in v0.4.5
47
- * @param encodedTxn {Buffer} a sia encoded transaction
48
- * @param sigIndex {number} the index of the signature to sign
49
- * @param keyIndex {number} the index of the key to sign with
50
- * @returns {string} the base64 encoded signature
51
- */
52
- signTransactionV044(encodedTxn: Buffer, sigIndex: number, keyIndex: number): Promise<string>;
53
- /**
54
- * signTransaction signs the transaction with the provided key
55
- * @param encodedTxn {Buffer} a sia encoded transaction
56
- * @param sigIndex {number} the index of the signature to sign
57
- * @param keyIndex {number} the index of the key to sign with
58
- * @param changeIndex {number} the index of the key used for the change output
59
- * @returns {string} the base64 encoded signature
60
- */
61
- signTransaction(encodedTxn: Buffer, sigIndex: number, keyIndex: number, changeIndex: number): Promise<string>;
85
+ getAddress(index: number): Promise<VerifyResponse>;
62
86
  /**
63
87
  * signV2Transaction signs the v2 transaction with the provided key
64
88
  * @param encodedTxn {Buffer} a sia encoded (V2TransactionSemantics) v2 transaction
65
89
  * @param sigIndex {number} the index of the signature to sign
66
90
  * @param keyIndex {number} the index of the key to sign with
67
91
  * @param changeIndex {number} the index of the key used for the change output
68
- * @returns {string} the base64 encoded signature
92
+ * @returns {string} the hex encoded signature
69
93
  */
70
94
  signV2Transaction(encodedTxn: Buffer, sigIndex: number, keyIndex: number, changeIndex: number): Promise<string>;
71
- blindSign(sigHash: Buffer, keyIndex: number): Promise<string>;
95
+ /**
96
+ * signHash signs a 32-byte hash with the private key at the provided index
97
+ * @param sigHash {Buffer} the 32-byte hash to sign
98
+ * @param keyIndex {number} the index of the key to sign with
99
+ * @returns {string} the hex encoded signature
100
+ */
101
+ signHash(sigHash: Buffer, keyIndex: number): Promise<string>;
72
102
  close(): Promise<void>;
73
103
  }
74
104
  export {};
package/lib/sia.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sia.d.ts","sourceRoot":"","sources":["../src/sia.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAI,MAAM,CAEtC;AAED,UAAU,cAAc;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,GAAG;IACvB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WA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,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAQ;IAUrD;;;;;;;;OAQG;WACU,IAAI,CAAC,eAAe,EAAE,gBAAgB,EAAE,WAAW,SAAQ,GAAI,OAAO,CAAC,GAAG,CAAC;IAwCxF;;;;;;OAMG;WACU,aAAa,CAAC,WAAW,SAAQ,GAAI,OAAO,CAAC,GAAG,CAAC;IAI9D;;;;;;OAMG;WACU,UAAU,CAAC,WAAW,SAAQ,GAAI,OAAO,CAAC,GAAG,CAAC;IAI3D;;;;;OAKG;WACU,mBAAmB,IAAK,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IAWlE;;;OAGG;YACW,eAAe;IAwB7B;;;;OAIG;IACG,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC;IAI/B;;;;OAIG;IACG,UAAU,IAAK,OAAO,CAAC,MAAM,CAAC;IAMpC;;;;;;;OAOG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,GAAI,OAAO,CAAC,cAAc,CAAC;IAW3D;;;;;;;OAOG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAI,OAAO,CAAC,cAAc,CAAC;IAWzD;;;;;;;OAOG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAMtH;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAWnE,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;CAGvB"}
package/lib/sia.js CHANGED
@@ -1,53 +1,34 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.hex = void 0;
40
- var buffer_1 = require("buffer");
41
- var base64_1 = require("@stablelib/base64");
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hw_transport_webhid_1 = __importDefault(require("@ledgerhq/hw-transport-webhid"));
7
+ const hw_transport_web_ble_1 = __importDefault(require("@ledgerhq/hw-transport-web-ble"));
8
+ const buffer_1 = require("buffer");
9
+ const CLA = 0xe0;
10
+ const APP_NAME = 'Sia';
11
+ const INS_OPEN_APP = 0xd8;
12
+ const INS_GET_VERSION = 0x01;
13
+ const INS_GET_PUBLIC_KEY = 0x02;
14
+ const INS_SIGN_HASH = 0x04;
15
+ const INS_CALC_V2TXN_HASH = 0x10;
16
+ const P1_FIRST = 0x00;
17
+ const P1_MORE = 0x80;
18
+ const P2_DISPLAY_ADDRESS = 0x00;
19
+ const P2_DISPLAY_PUBKEY = 0x01;
20
+ const P2_SIGN_HASH = 0x01;
42
21
  function uint32ToBuffer(val) {
43
- var buf = buffer_1.Buffer.alloc(4);
22
+ const buf = buffer_1.Buffer.alloc(4);
44
23
  buf.writeUInt32LE(val, 0);
45
24
  return buf;
46
25
  }
47
- function hex(b) {
48
- return b.reduce(function (v, byte) { return v + byte.toString(16).padStart(2, '0'); }, '').toLowerCase();
26
+ function bytesToHex(bytes) {
27
+ return bytes.reduce((v, b) => v + ('0' + b.toString(16)).slice(-2), '');
28
+ }
29
+ function delay(ms) {
30
+ return new Promise(resolve => setTimeout(resolve, ms));
49
31
  }
50
- exports.hex = hex;
51
32
  /**
52
33
  * Sia
53
34
  *
@@ -55,230 +36,195 @@ exports.hex = hex;
55
36
  * import Sia from '@siacentral/ledgerjs-sia';
56
37
  * const sia = new Sia(transport)
57
38
  */
58
- var Sia = /** @class */ (function () {
59
- function Sia(transport, scrambleKey) {
60
- if (scrambleKey === void 0) { scrambleKey = 'Sia'; }
39
+ class Sia {
40
+ constructor(transport, scrambleKey = 'Sia') {
61
41
  this.transport = transport;
62
42
  transport.decorateAppAPIMethods(this, [
63
- 'signTransactionV044',
64
- 'signTransaction',
65
43
  'signV2Transaction',
66
- 'verifyPublicKey',
67
- 'verifyStandardAddress',
44
+ 'getPublicKey',
45
+ 'getAddress',
68
46
  'signHash',
69
47
  ], scrambleKey);
70
48
  }
49
+ /**
50
+ * open connects a transport, ensures the Sia app is running, and returns a
51
+ * ready Sia instance. If the app is not already open it is launched from the
52
+ * dashboard; the device disconnects and reconnects when an app opens, so the
53
+ * transport is recreated via the provided factory until the app is ready.
54
+ * @param createTransport {TransportFactory} creates a transport, e.g. () => TransportWebHID.create()
55
+ * @param scrambleKey {string} the scramble key for the Sia app
56
+ * @returns {Sia} a Sia instance bound to a transport with the Sia app open
57
+ */
58
+ static async open(createTransport, scrambleKey = 'Sia') {
59
+ let sia = new Sia(await createTransport(), scrambleKey);
60
+ // if the Sia app is already running, return immediately
61
+ try {
62
+ await sia.getVersion();
63
+ return sia;
64
+ }
65
+ catch {
66
+ // the app is not open yet
67
+ }
68
+ // open the Sia app; the device disconnects and reconnects
69
+ try {
70
+ await sia.openApp();
71
+ }
72
+ catch {
73
+ // the device disconnects as the app opens
74
+ }
75
+ await sia.close().catch(() => undefined);
76
+ // the device reconnects when an app is opened; poll until the Sia app is ready
77
+ for (let i = 0; i < 10; i++) {
78
+ await delay(500);
79
+ try {
80
+ sia = new Sia(await createTransport(), scrambleKey);
81
+ }
82
+ catch {
83
+ continue;
84
+ }
85
+ try {
86
+ await sia.getVersion();
87
+ return sia;
88
+ }
89
+ catch {
90
+ await sia.close().catch(() => undefined);
91
+ }
92
+ }
93
+ throw new Error('Sia app did not become ready');
94
+ }
95
+ /**
96
+ * connectWebHID connects to a Ledger over WebHID (USB), launching the Sia
97
+ * app from the dashboard if it isn't already open, and returns a ready Sia
98
+ * instance.
99
+ * @param scrambleKey {string} the scramble key for the Sia app
100
+ * @returns {Sia} a Sia instance with the Sia app open
101
+ */
102
+ static async connectWebHID(scrambleKey = 'Sia') {
103
+ return Sia.open(() => hw_transport_webhid_1.default.create(), scrambleKey);
104
+ }
105
+ /**
106
+ * connectBLE connects to a Ledger over Web Bluetooth, launching the Sia app
107
+ * from the dashboard if it isn't already open, and returns a ready Sia
108
+ * instance.
109
+ * @param scrambleKey {string} the scramble key for the Sia app
110
+ * @returns {Sia} a Sia instance with the Sia app open
111
+ */
112
+ static async connectBLE(scrambleKey = 'Sia') {
113
+ return Sia.open(() => hw_transport_web_ble_1.default.create(), scrambleKey);
114
+ }
115
+ /**
116
+ * supportedTransports returns the transport methods available in the current
117
+ * environment. Web Bluetooth is excluded on Brave, which does not reliably
118
+ * support it.
119
+ * @returns {Array<'hid' | 'ble'>} the supported transport methods
120
+ */
121
+ static async supportedTransports() {
122
+ const nav = navigator;
123
+ const support = await Promise.all([
124
+ hw_transport_webhid_1.default.isSupported().then(supported => supported ? 'hid' : null),
125
+ hw_transport_web_ble_1.default.isSupported().then(async (supported) => supported && !(nav.brave && await nav.brave.isBrave()) ? 'ble' : null)
126
+ ]);
127
+ return support.filter((t) => t !== null);
128
+ }
129
+ /**
130
+ * exchangeTxnHash sends an encoded transaction to the device in 255-byte
131
+ * chunks and returns the response with the trailing status word stripped.
132
+ */
133
+ async exchangeTxnHash(ins, encodedTxn, p2, sigIndex, keyIndex, changeIndex) {
134
+ if (encodedTxn.length === 0)
135
+ throw new Error('empty transaction');
136
+ const buf = buffer_1.Buffer.alloc(encodedTxn.length + 10);
137
+ buf.writeUInt32LE(keyIndex, 0);
138
+ buf.writeUInt16LE(sigIndex, 4);
139
+ buf.writeUInt32LE(changeIndex, 6);
140
+ buf.set(encodedTxn, 10);
141
+ let resp = buffer_1.Buffer.alloc(0);
142
+ for (let i = 0; i < buf.length; i += 255) {
143
+ resp = await this.transport.send(CLA, ins, i === 0 ? P1_FIRST : P1_MORE, p2, buffer_1.Buffer.from(buf.subarray(i, i + 255)));
144
+ }
145
+ // the status code is appended as the last 2 bytes of the response, but
146
+ // the transport already handles invalid codes.
147
+ return buffer_1.Buffer.from(resp.subarray(0, resp.length - 2));
148
+ }
149
+ /**
150
+ * openApp launches the Sia app from the device's dashboard. The device
151
+ * disconnects and reconnects when the app opens, so the transport must be
152
+ * re-created before issuing further commands.
153
+ */
154
+ async openApp() {
155
+ await this.transport.send(CLA, INS_OPEN_APP, 0x00, 0x00, buffer_1.Buffer.from(APP_NAME, 'ascii'));
156
+ }
71
157
  /**
72
158
  * getVersion returns the version of the Sia app
73
159
  *
74
160
  * @returns {string} the current version of the Sia app.
75
161
  */
76
- Sia.prototype.getVersion = function () {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var resp;
79
- return __generator(this, function (_a) {
80
- switch (_a.label) {
81
- case 0: return [4 /*yield*/, this.transport.send(0xe0, 0x01, 0x00, 0x00, buffer_1.Buffer.alloc(0))];
82
- case 1:
83
- resp = _a.sent();
84
- return [2 /*return*/, "v".concat(resp[0], ".").concat(resp[1], ".").concat(resp[2])];
85
- }
86
- });
87
- });
88
- };
162
+ async getVersion() {
163
+ const resp = await this.transport.send(CLA, INS_GET_VERSION, 0x00, 0x00, buffer_1.Buffer.alloc(0));
164
+ return `v${resp[0]}.${resp[1]}.${resp[2]}`;
165
+ }
89
166
  /**
90
- * verifyPublicKey returns the public key and standard Sia address for
167
+ * getPublicKey returns the public key and standard Sia address for
91
168
  * the provided public key index. The user will be asked to verify the
92
169
  * public key on the display. A standard address is defined as an address
93
170
  * having 1 public key, requiring 1 signature, and no timelock.
94
171
  * @param index {number} the index of the public key
95
172
  * @returns {VerifyResponse} the public key and standard address
96
173
  */
97
- Sia.prototype.verifyPublicKey = function (index) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var resp;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0: return [4 /*yield*/, this.transport.send(0xe0, 0x02, 0x00, 0x01, uint32ToBuffer(index))];
103
- case 1:
104
- resp = _a.sent();
105
- // the status code is appended as the last 2 bytes of the response, but
106
- // the transport already handles invalid codes.
107
- return [2 /*return*/, {
108
- publicKey: "ed25519:".concat(hex(resp.subarray(0, 32))),
109
- address: hex(resp.subarray(32, resp.length - 2))
110
- }];
111
- }
112
- });
113
- });
114
- };
174
+ async getPublicKey(index) {
175
+ const resp = await this.transport.send(CLA, INS_GET_PUBLIC_KEY, 0x00, P2_DISPLAY_PUBKEY, uint32ToBuffer(index));
176
+ // the status code is appended as the last 2 bytes of the response, but
177
+ // the transport already handles invalid codes.
178
+ return {
179
+ publicKey: `ed25519:${bytesToHex(resp.subarray(0, 32))}`,
180
+ address: resp.subarray(32, resp.length - 2).toString()
181
+ };
182
+ }
115
183
  /**
116
- * verifyStandardAddress returns the public key and standard Sia address for
184
+ * getAddress returns the public key and standard Sia address for
117
185
  * the provided public key index. The user will be asked to verify the
118
186
  * address on the display. A standard address is defined as an address
119
187
  * having 1 public key, requiring 1 signature, and no timelock.
120
188
  * @param index {number} the index of the public key
121
189
  * @returns {VerifyResponse} the public key and standard address
122
190
  */
123
- Sia.prototype.verifyStandardAddress = function (index) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var resp;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0: return [4 /*yield*/, this.transport.send(0xe0, 0x02, 0x00, 0x00, uint32ToBuffer(index))];
129
- case 1:
130
- resp = _a.sent();
131
- // the status code is appended as the last 2 bytes of the response, but
132
- // the transport already handles invalid codes.
133
- return [2 /*return*/, {
134
- publicKey: "ed25519:".concat(hex(resp.subarray(0, 32))),
135
- address: hex(resp.subarray(32, resp.length - 2))
136
- }];
137
- }
138
- });
139
- });
140
- };
141
- /**
142
- * signTransactionV044 signs the transaction with the provided key
143
- * @deprecated deprecated in v0.4.5
144
- * @param encodedTxn {Buffer} a sia encoded transaction
145
- * @param sigIndex {number} the index of the signature to sign
146
- * @param keyIndex {number} the index of the key to sign with
147
- * @returns {string} the base64 encoded signature
148
- */
149
- Sia.prototype.signTransactionV044 = function (encodedTxn, sigIndex, keyIndex) {
150
- return __awaiter(this, void 0, void 0, function () {
151
- var buf, resp, i;
152
- return __generator(this, function (_a) {
153
- switch (_a.label) {
154
- case 0:
155
- buf = buffer_1.Buffer.alloc(encodedTxn.length + 6);
156
- resp = buffer_1.Buffer.alloc(0);
157
- if (encodedTxn.length === 0)
158
- throw new Error('empty transaction');
159
- buf.writeUInt32LE(keyIndex, 0);
160
- buf.writeUInt16LE(sigIndex, 4);
161
- buf.set(encodedTxn, 6);
162
- i = 0;
163
- _a.label = 1;
164
- case 1:
165
- if (!(i < buf.length)) return [3 /*break*/, 4];
166
- return [4 /*yield*/, this.transport.send(0xe0, 0x08, i === 0 ? 0x00 : 0x80, 0x01, buffer_1.Buffer.from(buf.subarray(i, i + 255)))];
167
- case 2:
168
- // INS_GET_TXN_HASH = 0x08
169
- resp = _a.sent();
170
- _a.label = 3;
171
- case 3:
172
- i += 255;
173
- return [3 /*break*/, 1];
174
- case 4:
175
- console.log(resp);
176
- console.log(resp.length);
177
- return [2 /*return*/, (0, base64_1.encode)(resp.subarray(0, resp.length - 2))]; // remove the status code
178
- }
179
- });
180
- });
181
- };
191
+ async getAddress(index) {
192
+ const resp = await this.transport.send(CLA, INS_GET_PUBLIC_KEY, 0x00, P2_DISPLAY_ADDRESS, uint32ToBuffer(index));
193
+ // the status code is appended as the last 2 bytes of the response, but
194
+ // the transport already handles invalid codes.
195
+ return {
196
+ publicKey: `ed25519:${bytesToHex(resp.subarray(0, 32))}`,
197
+ address: resp.subarray(32, resp.length - 2).toString()
198
+ };
199
+ }
182
200
  /**
183
- * signTransaction signs the transaction with the provided key
184
- * @param encodedTxn {Buffer} a sia encoded transaction
201
+ * signV2Transaction signs the v2 transaction with the provided key
202
+ * @param encodedTxn {Buffer} a sia encoded (V2TransactionSemantics) v2 transaction
185
203
  * @param sigIndex {number} the index of the signature to sign
186
204
  * @param keyIndex {number} the index of the key to sign with
187
205
  * @param changeIndex {number} the index of the key used for the change output
188
- * @returns {string} the base64 encoded signature
206
+ * @returns {string} the hex encoded signature
189
207
  */
190
- Sia.prototype.signTransaction = function (encodedTxn, sigIndex, keyIndex, changeIndex) {
191
- return __awaiter(this, void 0, void 0, function () {
192
- var buf, resp, i;
193
- return __generator(this, function (_a) {
194
- switch (_a.label) {
195
- case 0:
196
- buf = buffer_1.Buffer.alloc(encodedTxn.length + 10);
197
- resp = buffer_1.Buffer.alloc(0);
198
- if (encodedTxn.length === 0)
199
- throw new Error('empty transaction');
200
- buf.writeUInt32LE(keyIndex, 0);
201
- buf.writeUInt16LE(sigIndex, 4);
202
- buf.writeUInt32LE(changeIndex, 6);
203
- buf.set(encodedTxn, 10);
204
- i = 0;
205
- _a.label = 1;
206
- case 1:
207
- if (!(i < buf.length)) return [3 /*break*/, 4];
208
- return [4 /*yield*/, this.transport.send(0xe0, 0x08, i === 0 ? 0x00 : 0x80, 0x01, buffer_1.Buffer.from(buf.subarray(i, i + 255)))];
209
- case 2:
210
- // INS_GET_TXN_HASH = 0x08
211
- resp = _a.sent();
212
- _a.label = 3;
213
- case 3:
214
- i += 255;
215
- return [3 /*break*/, 1];
216
- case 4: return [2 /*return*/, (0, base64_1.encode)(resp)];
217
- }
218
- });
219
- });
220
- };
208
+ async signV2Transaction(encodedTxn, sigIndex, keyIndex, changeIndex) {
209
+ const resp = await this.exchangeTxnHash(INS_CALC_V2TXN_HASH, encodedTxn, P2_SIGN_HASH, sigIndex, keyIndex, changeIndex);
210
+ return bytesToHex(resp);
211
+ }
221
212
  /**
222
- * signV2Transaction signs the v2 transaction with the provided key
223
- * @param encodedTxn {Buffer} a sia encoded (V2TransactionSemantics) v2 transaction
224
- * @param sigIndex {number} the index of the signature to sign
213
+ * signHash signs a 32-byte hash with the private key at the provided index
214
+ * @param sigHash {Buffer} the 32-byte hash to sign
225
215
  * @param keyIndex {number} the index of the key to sign with
226
- * @param changeIndex {number} the index of the key used for the change output
227
- * @returns {string} the base64 encoded signature
216
+ * @returns {string} the hex encoded signature
228
217
  */
229
- Sia.prototype.signV2Transaction = function (encodedTxn, sigIndex, keyIndex, changeIndex) {
230
- return __awaiter(this, void 0, void 0, function () {
231
- var buf, resp, i;
232
- return __generator(this, function (_a) {
233
- switch (_a.label) {
234
- case 0:
235
- buf = buffer_1.Buffer.alloc(encodedTxn.length + 10);
236
- resp = buffer_1.Buffer.alloc(0);
237
- if (encodedTxn.length === 0)
238
- throw new Error('empty transaction');
239
- buf.writeUInt32LE(keyIndex, 0);
240
- buf.writeUInt16LE(sigIndex, 4);
241
- buf.writeUInt32LE(changeIndex, 6);
242
- buf.set(encodedTxn, 10);
243
- i = 0;
244
- _a.label = 1;
245
- case 1:
246
- if (!(i < buf.length)) return [3 /*break*/, 4];
247
- return [4 /*yield*/, this.transport.send(0xe0, 0x10, i === 0 ? 0x00 : 0x80, 0x01, buffer_1.Buffer.from(buf.subarray(i, i + 255)))];
248
- case 2:
249
- // INS_GET_V2TXN_HASH = 0x10
250
- resp = _a.sent();
251
- _a.label = 3;
252
- case 3:
253
- i += 255;
254
- return [3 /*break*/, 1];
255
- case 4: return [2 /*return*/, hex(resp)];
256
- }
257
- });
258
- });
259
- };
260
- Sia.prototype.blindSign = function (sigHash, keyIndex) {
261
- return __awaiter(this, void 0, void 0, function () {
262
- var buf, resp;
263
- return __generator(this, function (_a) {
264
- switch (_a.label) {
265
- case 0:
266
- buf = buffer_1.Buffer.alloc(sigHash.length + 4);
267
- resp = buffer_1.Buffer.alloc(0);
268
- buf.writeUInt32LE(keyIndex);
269
- buf.set(sigHash, 4);
270
- return [4 /*yield*/, this.transport.send(0xe0, 0x04, 0x00, 0x00, buf)];
271
- case 1:
272
- resp = _a.sent();
273
- return [2 /*return*/, hex(resp.subarray(0, resp.length - 2))];
274
- }
275
- });
276
- });
277
- };
278
- Sia.prototype.close = function () {
218
+ async signHash(sigHash, keyIndex) {
219
+ const buf = buffer_1.Buffer.alloc(sigHash.length + 4);
220
+ buf.writeUInt32LE(keyIndex, 0);
221
+ buf.set(sigHash, 4);
222
+ const resp = await this.transport.send(CLA, INS_SIGN_HASH, 0x00, 0x00, buf);
223
+ return bytesToHex(resp.subarray(0, resp.length - 2));
224
+ }
225
+ close() {
279
226
  return this.transport.close();
280
- };
281
- return Sia;
282
- }());
283
- exports["default"] = Sia;
227
+ }
228
+ }
229
+ exports.default = Sia;
284
230
  //# sourceMappingURL=sia.js.map
package/lib/sia.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sia.js","sourceRoot":"","sources":["../src/sia.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAgC;AAChC,4CAA2C;AAE3C,SAAS,cAAc,CAAC,GAAW;IAClC,IAAM,GAAG,GAAG,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC1B,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAgB,GAAG,CAAC,CAAS;IAC5B,OAAO,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,IAAI,IAAK,OAAA,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAtC,CAAsC,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACxF,CAAC;AAFD,kBAEC;AAOD;;;;;;GAMG;AACH;IAGC,aAAY,SAAoB,EAAE,WAAmB;QAAnB,4BAAA,EAAA,mBAAmB;QACpD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,SAAS,CAAC,qBAAqB,CAAC,IAAI,EAAE;YACrC,qBAAqB;YACrB,iBAAiB;YACjB,mBAAmB;YACnB,iBAAiB;YACjB,uBAAuB;YACvB,UAAU;SACV,EAAE,WAAW,CAAC,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACG,wBAAU,GAAhB;;;;;4BACc,qBAAM,IAAI,CAAC,SAAS,CAAC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CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACD;AA7ND,sBA6NC"}
package/package.json CHANGED
@@ -1,60 +1,59 @@
1
1
  {
2
- "name": "@siacentral/ledgerjs-sia",
3
- "version": "1.2.8",
4
- "description": "Ledger hardware wallet Siacoin API.",
5
- "main": "lib/sia.js",
6
- "types": "lib/sia.d.ts",
7
- "scripts": {
8
- "build": "tsc",
9
- "test": "jest",
10
- "lint": "eslint src",
11
- "prepare": "npm run build",
12
- "prepublishOnly": "npm run lint && npm run test",
13
- "preversion": "npm run lint"
14
- },
15
- "keywords": [
16
- "Ledger",
17
- "LedgerWallet",
18
- "sc",
19
- "Siacoin",
20
- "sf",
21
- "Siafund",
22
- "NanoS",
23
- "NanoX",
24
- "Hardware Wallet"
25
- ],
26
- "author": "Nate Maninger <me@n8m.us>",
27
- "license": "MIT",
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/siacentral/ledgerjs-sia"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/siacentral/ledgerjs-sia/issues"
34
- },
35
- "homepage": "https://github.com/siacentral/ledgerjs-sia",
36
- "publishConfig": {
37
- "access": "public"
38
- },
39
- "devDependencies": {
40
- "@ledgerhq/hw-transport-mocker": "^6.3.0",
41
- "@types/jest": "^27.0.1",
42
- "@typescript-eslint/eslint-plugin": "^4.29.3",
43
- "@typescript-eslint/parser": "^4.29.3",
44
- "eslint": "^7.32.0",
45
- "jest": "^27.1.0",
46
- "ts-jest": "^27.0.5",
47
- "ts-node": "^10.2.1",
48
- "typescript": "^4.4.2"
49
- },
50
- "dependencies": {
51
- "@ledgerhq/hw-transport-web-ble": "^6.3.0",
52
- "@ledgerhq/hw-transport-webhid": "^6.4.1",
53
- "@stablelib/base64": "^1.0.1",
54
- "@stablelib/utf8": "^1.0.1",
55
- "buffer": "^6.0.3"
56
- },
57
- "files": [
58
- "lib/**/*"
59
- ]
60
- }
2
+ "name": "@siacentral/ledgerjs-sia",
3
+ "version": "2.0.1",
4
+ "description": "Ledger hardware wallet Siacoin API.",
5
+ "main": "lib/sia.js",
6
+ "types": "lib/sia.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "jest",
10
+ "lint": "eslint src",
11
+ "prepare": "npm run build",
12
+ "prepublishOnly": "npm run lint && npm run test",
13
+ "preversion": "npm run lint"
14
+ },
15
+ "keywords": [
16
+ "Ledger",
17
+ "LedgerWallet",
18
+ "sc",
19
+ "Siacoin",
20
+ "sf",
21
+ "Siafund",
22
+ "NanoS",
23
+ "NanoX",
24
+ "Hardware Wallet"
25
+ ],
26
+ "author": "Nate Maninger <me@n8m.us>",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/siacentral/ledgerjs-sia"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/siacentral/ledgerjs-sia/issues"
34
+ },
35
+ "homepage": "https://github.com/siacentral/ledgerjs-sia",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "devDependencies": {
40
+ "@eslint/js": "^10.0.1",
41
+ "@ledgerhq/hw-transport-mocker": "^6.34.2",
42
+ "@types/jest": "^30.0.0",
43
+ "eslint": "^10.4.1",
44
+ "jest": "^30.4.2",
45
+ "ts-jest": "^29.4.11",
46
+ "ts-node": "^10.9.2",
47
+ "typescript": "^6.0.3",
48
+ "typescript-eslint": "^8.60.0"
49
+ },
50
+ "dependencies": {
51
+ "@ledgerhq/hw-transport": "^6.35.2",
52
+ "@ledgerhq/hw-transport-web-ble": "^6.34.2",
53
+ "@ledgerhq/hw-transport-webhid": "^6.35.2",
54
+ "buffer": "^6.0.3"
55
+ },
56
+ "files": [
57
+ "lib/**/*"
58
+ ]
59
+ }