Skip to content

Commit

Permalink
Merge pull request #72 from phantasma-io/dev
Browse files Browse the repository at this point in the history
Ledger Upgrade Signer Data Fix
  • Loading branch information
TeknoPT authored Nov 27, 2023
2 parents 3a2cb6d + 8415583 commit e6bc5ec
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 329 deletions.
9 changes: 8 additions & 1 deletion core/ledger/Ledger-Commands.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKeyResponse } from '..';
import { LedgerSignerData, PublicKeyResponse } from '..';
import { LedgerConfig } from './interfaces/LedgerConfig';
import { LedgerDeviceInfoResponse } from './interfaces/LedgerDeviceInfoResponse';
import { LedgerBalanceFromLedgerResponse } from './interfaces/LedgerBalanceFromLedgerResponse';
Expand Down Expand Up @@ -30,6 +30,13 @@ export declare const GetLedgerDeviceInfo: (config: LedgerConfig) => Promise<Ledg
* @returns
*/
export declare const GetLedgerAccountSigner: (config: LedgerConfig, accountIx: any) => Promise<LedgerSigner>;
/**
* GetLedgerSignerData
* @param config
* @param options
* @returns
*/
export declare function GetLedgerSignerData(config: LedgerConfig, options: any): Promise<LedgerSignerData>;
/**
* GetBalanceFromLedger
* @param config
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/Ledger-Commands.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 53 additions & 11 deletions core/ledger/Ledger-Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetBalanceFromMnemonic = exports.GetBalanceFromPrivateKey = exports.SendTransactionLedger = exports.GetAddressFromLedeger = exports.GetBalanceFromLedger = exports.GetLedgerAccountSigner = exports.GetLedgerDeviceInfo = exports.ToWholeNumber = exports.LeftPad = void 0;
exports.GetBalanceFromMnemonic = exports.GetBalanceFromPrivateKey = exports.SendTransactionLedger = exports.GetAddressFromLedeger = exports.GetBalanceFromLedger = exports.GetLedgerSignerData = exports.GetLedgerAccountSigner = exports.GetLedgerDeviceInfo = exports.ToWholeNumber = exports.LeftPad = void 0;
var __1 = require("..");
var tx_1 = require("../tx");
var types_1 = require("../types");
Expand Down Expand Up @@ -137,7 +137,7 @@ var GetLedgerAccountSigner = function (config, accountIx) { return __awaiter(voi
alert('NUmber of devices found:' + paths.length);
return [2 /*return*/];
}
return [4 /*yield*/, (0, exports.GetBalanceFromLedger)(config, {
return [4 /*yield*/, GetLedgerSignerData(config, {
verifyOnDevice: false,
debug: true,
})];
Expand All @@ -154,14 +154,52 @@ var GetLedgerAccountSigner = function (config, accountIx) { return __awaiter(voi
});
}); };
exports.GetLedgerAccountSigner = GetLedgerAccountSigner;
/**
* GetLedgerSignerData
* @param config
* @param options
* @returns
*/
function GetLedgerSignerData(config, options) {
return __awaiter(this, void 0, void 0, function () {
var msg, response, publicKey, address;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (config == undefined) {
throw Error('config is a required parameter.');
}
if (options == undefined) {
throw Error('options is a required parameter.');
}
return [4 /*yield*/, (0, Ledger_Utils_1.GetPublicKey)(config.Transport, options)];
case 1:
msg = _a.sent();
response.success = false;
response.message = msg.message;
if (!msg.success) {
return [2 /*return*/, response];
}
publicKey = msg.publicKey;
address = (0, Address_Transcode_1.GetAddressPublicKeyFromPublicKey)(publicKey);
response.success = true;
response.message = 'success';
response.address = address;
response.publicKey = publicKey;
return [2 /*return*/, response];
}
});
});
}
exports.GetLedgerSignerData = GetLedgerSignerData;
/**
* GetBalanceFromLedger
* @param config
* @param options
* @returns
*/
var GetBalanceFromLedger = function (config, options) { return __awaiter(void 0, void 0, void 0, function () {
var msg, publicKey, address, _a, _b, _c, rpcResponse, response_1;
var msg, response, publicKey, address, _a, _b, _c, rpcResponse;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
Expand All @@ -180,7 +218,12 @@ var GetBalanceFromLedger = function (config, options) { return __awaiter(void 0,
if (config.Debug) {
console.log('getBalanceFromLedger', 'msg', msg);
}
if (!msg.success) return [3 /*break*/, 4];
response.balances = new Map();
response.success = false;
response.message = msg.message;
if (!msg.success) {
return [2 /*return*/, response];
}
publicKey = msg.publicKey;
address = (0, Address_Transcode_1.GetAddressPublicKeyFromPublicKey)(publicKey);
/* istanbul ignore if */
Expand All @@ -199,17 +242,16 @@ var GetBalanceFromLedger = function (config, options) { return __awaiter(void 0,
if (config.Debug) {
console.log('rpcResponse', rpcResponse);
}
response_1 = {};
response_1.balances = {};
response.balances = new Map();
if (rpcResponse.balances !== undefined) {
rpcResponse.balances.forEach(function (balanceElt) {
response_1.balances[balanceElt.symbol] = (0, exports.ToWholeNumber)(balanceElt.amount, balanceElt.decimals);
response.balances[balanceElt.symbol] = (0, exports.ToWholeNumber)(balanceElt.amount, balanceElt.decimals);
});
}
response_1.address = address;
response_1.success = true;
return [2 /*return*/, response_1];
case 4: return [2 /*return*/, msg];
response.address = address;
response.publicKey = publicKey;
response.success = true;
return [2 /*return*/, response];
}
});
}); };
Expand Down
4 changes: 4 additions & 0 deletions core/ledger/interfaces/LedgerBalanceFromLedgerResponse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ export interface LedgerBalanceFromLedgerResponse {
message: string;
publicKey?: string;
address?: Address;
balances?: Map<string, {
amount: number;
decimals: number;
}>;
}
//# sourceMappingURL=LedgerBalanceFromLedgerResponse.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions core/ledger/interfaces/LedgerSignerData.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Address } from '../../types';
export interface LedgerSignerData {
success: boolean;
message: string;
publicKey?: string;
address?: Address;
}
//# sourceMappingURL=LedgerSignerData.d.ts.map
1 change: 1 addition & 0 deletions core/ledger/interfaces/LedgerSignerData.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/ledger/interfaces/LedgerSignerData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
1 change: 1 addition & 0 deletions core/ledger/interfaces/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './SignResponse';
export * from './VersionResponse';
export * from './LedgerBalanceFromLedgerResponse';
export * from './LedgerSigner';
export * from './LedgerSignerData';
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion core/ledger/interfaces/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/ledger/interfaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ __exportStar(require("./SignResponse"), exports);
__exportStar(require("./VersionResponse"), exports);
__exportStar(require("./LedgerBalanceFromLedgerResponse"), exports);
__exportStar(require("./LedgerSigner"), exports);
__exportStar(require("./LedgerSignerData"), exports);
Loading

0 comments on commit e6bc5ec

Please sign in to comment.