UNPKG

@ledgerhq/live-common

Version:
98 lines 4.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSigner = void 0; const getAddress_1 = __importDefault(require("@ledgerhq/coin-xrp/signer/getAddress")); const getAddress_2 = __importDefault(require("@ledgerhq/coin-stellar/signer/getAddress")); const hw_app_str_1 = __importDefault(require("@ledgerhq/hw-app-str")); const signTransaction_1 = require("./signTransaction"); const stellar_sdk_1 = require("@stellar/stellar-sdk"); const setup_1 = require("../../setup"); const hw_app_xrp_1 = __importDefault(require("@ledgerhq/hw-app-xrp")); const ledger_signer_1 = require("@taquito/ledger-signer"); const getAddress_3 = __importDefault(require("@ledgerhq/coin-tezos/signer/getAddress")); const hw_app_tezos_1 = __importDefault(require("@ledgerhq/hw-app-tezos")); const createSignerXrp = (transport) => { return new hw_app_xrp_1.default(transport); }; const signerContextXrp = (0, setup_1.executeWithSigner)(createSignerXrp); const createSignerStellar = (transport) => { const stellar = new hw_app_str_1.default(transport); const originalSignTransaction = stellar.signTransaction; // Return the original Stellar instance with overridden methods return Object.assign(stellar, { signTransaction: async (path, transaction) => { const unsignedPayload = Buffer.from(transaction, "base64"); const { signature } = await originalSignTransaction(path, unsignedPayload); return signature.toString("base64"); }, getAddress: async (path, verify) => { const { rawPublicKey } = await stellar.getPublicKey(path, verify); const publicKey = stellar_sdk_1.StrKey.encodeEd25519PublicKey(rawPublicKey); return { path, address: publicKey, publicKey: publicKey, }; }, }); }; const signerContextStellar = (0, setup_1.executeWithSigner)(createSignerStellar); const createSignerTezos = (transport) => { const tezos = new hw_app_tezos_1.default(transport); // align with genericSignOperation that calls signer.signTransaction return Object.assign(tezos, { async signTransaction(path, rawTxHex) { const { signature } = await tezos.signOperation(path, rawTxHex, {}); return signature; }, async getAddress(path, { verify } = {}) { // Use Taquito LedgerSigner to retrieve base58 public key and matching pkh (like oldbridge) const ledgerSigner = new ledger_signer_1.LedgerSigner(transport, path, !!verify, ledger_signer_1.DerivationType.ED25519); const address = await ledgerSigner.publicKeyHash(); const publicKey = await ledgerSigner.publicKey(); return { path, address, publicKey }; }, createLedgerSigner(path, prompt, derivationType) { // Map 0 -> ED25519, 1 -> SECP256K1, 2 -> P256 by convention let dt = ledger_signer_1.DerivationType.ED25519; if (derivationType === 1) dt = ledger_signer_1.DerivationType.SECP256K1; else if (derivationType === 2) dt = ledger_signer_1.DerivationType.P256; return new ledger_signer_1.LedgerSigner(transport, path, prompt, dt); }, }); }; const signerContextTezos = (0, setup_1.executeWithSigner)(createSignerTezos); function getSigner(network) { switch (network) { case "ripple": case "xrp": { return { getAddress: (0, getAddress_1.default)(signerContextXrp), signTransaction: (0, signTransaction_1.signTransaction)(signerContextXrp), context: signerContextXrp, }; } case "stellar": { return { getAddress: (0, getAddress_2.default)(signerContextStellar), signTransaction: (0, signTransaction_1.stellarSignTransaction)(signerContextStellar), context: signerContextStellar, }; } case "tezos": { return { getAddress: (0, getAddress_3.default)(signerContextTezos), signTransaction: (0, signTransaction_1.tezosSignTransaction)((0, setup_1.executeWithSigner)(createSignerTezos)), context: signerContextTezos, }; } } throw new Error(`signer for ${network} not implemented`); } exports.getSigner = getSigner; //# sourceMappingURL=index.js.map