@cityofzion/bs-neo3 1.10.9 → 1.10.10

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.
@@ -7,6 +7,7 @@ export declare class NeonDappKitLedgerServiceNeo3<BSName extends string = string
7
7
  emitter: LedgerServiceEmitter;
8
8
  getLedgerTransport?: GetLedgerTransport<BSName>;
9
9
  constructor(blockchainService: BSNeo3<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
10
+ verifyAppName(transport: Transport): Promise<boolean>;
10
11
  getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
11
12
  getAccounts(transport: Transport, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
12
13
  getSigningCallback(transport: Transport, account: Account): api.SigningFunction;
@@ -35,6 +35,7 @@ var LedgerStatus;
35
35
  })(LedgerStatus || (LedgerStatus = {}));
36
36
  var LedgerCommand;
37
37
  (function (LedgerCommand) {
38
+ LedgerCommand[LedgerCommand["GET_APP_NAME"] = 0] = "GET_APP_NAME";
38
39
  LedgerCommand[LedgerCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
39
40
  LedgerCommand[LedgerCommand["SIGN"] = 2] = "SIGN";
40
41
  })(LedgerCommand || (LedgerCommand = {}));
@@ -51,10 +52,29 @@ class NeonDappKitLedgerServiceNeo3 {
51
52
  __classPrivateFieldSet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, blockchainService, "f");
52
53
  this.getLedgerTransport = getLedgerTransport;
53
54
  }
55
+ // This verification is necessary because the NEO2 Ledger App also detects NEO3
56
+ verifyAppName(transport) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ try {
59
+ const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.GET_APP_NAME, 0x00, LedgerSecondParameter.LAST_DATA, undefined);
60
+ const version = response.toString('ascii');
61
+ const appName = version.substring(0, version.length - 2);
62
+ if (appName !== 'NEO N3')
63
+ return false;
64
+ return true;
65
+ }
66
+ catch (_a) {
67
+ return false;
68
+ }
69
+ });
70
+ }
54
71
  getAccount(transport, index) {
55
72
  return __awaiter(this, void 0, void 0, function* () {
56
73
  const bip44Path = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f").bip44DerivationPath.replace('?', index.toString());
57
74
  const bip44PathHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_bip44PathToHex).call(this, bip44Path);
75
+ const isNeoN3App = yield this.verifyAppName(transport);
76
+ if (!isNeoN3App)
77
+ throw new Error('App is not NEO N3');
58
78
  const result = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.GET_PUBLIC_KEY, 0x00, LedgerSecondParameter.LAST_DATA, bip44PathHex);
59
79
  const publicKey = result.toString('hex').substring(0, 130);
60
80
  const { address } = new neon_js_1.wallet.Account(publicKey);
@@ -79,6 +99,9 @@ class NeonDappKitLedgerServiceNeo3 {
79
99
  }
80
100
  getSigningCallback(transport, account) {
81
101
  return (transaction, { witnessIndex, network }) => __awaiter(this, void 0, void 0, function* () {
102
+ const isNeoN3App = yield this.verifyAppName(transport);
103
+ if (!isNeoN3App)
104
+ throw new Error('App is not NEO N3');
82
105
  try {
83
106
  this.emitter.emit('getSignatureStart');
84
107
  if (!account.bip44Path) {
@@ -120,7 +143,9 @@ class NeonDappKitLedgerServiceNeo3 {
120
143
  }
121
144
  exports.NeonDappKitLedgerServiceNeo3 = NeonDappKitLedgerServiceNeo3;
122
145
  _NeonDappKitLedgerServiceNeo3_blockchainService = new WeakMap(), _NeonDappKitLedgerServiceNeo3_instances = new WeakSet(), _NeonDappKitLedgerServiceNeo3_sendChunk = function _NeonDappKitLedgerServiceNeo3_sendChunk(transport, command, commandIndex, secondParameter, chunk) {
123
- return transport.send(0x80, command, commandIndex, secondParameter, Buffer.from(chunk, 'hex'), [LedgerStatus.OK]);
146
+ return transport.send(0x80, command, commandIndex, secondParameter, chunk ? Buffer.from(chunk, 'hex') : undefined, [
147
+ LedgerStatus.OK,
148
+ ]);
124
149
  }, _NeonDappKitLedgerServiceNeo3_bip44PathToHex = function _NeonDappKitLedgerServiceNeo3_bip44PathToHex(path) {
125
150
  let result = '';
126
151
  const components = path.split('/');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.10.9",
3
+ "version": "1.10.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",