Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cosmjs/ledger-amino

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/ledger-amino - npm Package Compare versions

Comparing version 0.26.6 to 0.26.8

build/ledgerconnector.d.ts

44

build/demo/web.js

@@ -7,2 +7,3 @@ "use strict";

const amino_1 = require("@cosmjs/amino");
const crypto_1 = require("@cosmjs/crypto");
const encoding_1 = require("@cosmjs/encoding");

@@ -13,2 +14,4 @@ const math_1 = require("@cosmjs/math");

const ledgersigner_1 = require("../ledgersigner");
const accountNumbers = [0, 1, 2, 10];
const paths = accountNumbers.map(amino_1.makeCosmoshubPath);
let accounts = [];

@@ -48,3 +51,3 @@ function createSignDoc(accountNumber, address) {

window.updateMessage = (accountNumberInput) => {
utils_1.assert(typeof accountNumberInput === "string");
(0, utils_1.assert)(typeof accountNumberInput === "string");
const accountNumber = math_1.Uint53.fromString(accountNumberInput).toNumber();

@@ -61,2 +64,10 @@ const account = accounts[accountNumber];

};
window.setPath = (accountNumberInput) => {
(0, utils_1.assert)(typeof accountNumberInput === "string");
const accountNumber = math_1.Uint53.fromString(accountNumberInput).toNumber();
const path = (0, crypto_1.pathToString)(paths[accountNumber]);
const pathInput = document.getElementById("path");
pathInput.value = path;
};
// This must be called by the user an cannot be done on load (see "TransportWebUSBGestureRequired").
window.createSigner = async function createSigner() {

@@ -67,3 +78,3 @@ const interactiveTimeout = 120000;

testModeAllowed: true,
hdPaths: [amino_1.makeCosmoshubPath(0), amino_1.makeCosmoshubPath(1), amino_1.makeCosmoshubPath(2)],
hdPaths: paths,
});

@@ -76,3 +87,4 @@ };

}
const accountNumberInput = document.getElementById("account-number");
const accountNumberInput1 = document.getElementById("account-number1");
const accountNumberInput2 = document.getElementById("account-number2");
const addressInput = document.getElementById("address");

@@ -84,7 +96,15 @@ const accountsDiv = document.getElementById("accounts");

accounts = await signer.getAccounts();
const prettyAccounts = accounts.map((account) => (Object.assign(Object.assign({}, account), { pubkey: encoding_1.toBase64(account.pubkey) })));
const prettyAccounts = accounts.map((account) => ({
...account,
pubkey: (0, encoding_1.toBase64)(account.pubkey),
}));
accountsDiv.textContent = JSON.stringify(prettyAccounts, null, "\n");
const accountNumber = 0;
accountNumberInput.max = accounts.length - 1;
accountNumberInput.value = accountNumber;
// Show address block
accountNumberInput1.max = accounts.length - 1;
accountNumberInput1.value = accountNumber;
window.setPath(accountNumber.toString());
// Sign block
accountNumberInput2.max = accounts.length - 1;
accountNumberInput2.value = accountNumber;
const address = accounts[0].address;

@@ -95,5 +115,14 @@ addressInput.value = address;

catch (error) {
console.error(error);
accountsDiv.textContent = error;
}
};
window.showAddress = async function showAddress(signer) {
if (signer === undefined) {
console.error("Please wait for transport to connect");
return;
}
const path = (0, crypto_1.stringToPath)(document.getElementById("path").value);
await signer.showAddress(path);
};
window.sign = async function sign(signer) {

@@ -117,5 +146,2 @@ if (signer === undefined) {

};
window.onload = async function onLoad() {
window.signer = await window.createSigner();
};
//# sourceMappingURL=web.js.map

@@ -1,2 +0,2 @@

export { LaunchpadLedger } from "./launchpadledger";
export { AddressAndPubkey, LedgerConnector } from "./ledgerconnector";
export { LedgerSigner } from "./ledgersigner";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LedgerSigner = exports.LaunchpadLedger = void 0;
var launchpadledger_1 = require("./launchpadledger");
Object.defineProperty(exports, "LaunchpadLedger", { enumerable: true, get: function () { return launchpadledger_1.LaunchpadLedger; } });
exports.LedgerSigner = exports.LedgerConnector = void 0;
var ledgerconnector_1 = require("./ledgerconnector");
Object.defineProperty(exports, "LedgerConnector", { enumerable: true, get: function () { return ledgerconnector_1.LedgerConnector; } });
var ledgersigner_1 = require("./ledgersigner");
Object.defineProperty(exports, "LedgerSigner", { enumerable: true, get: function () { return ledgersigner_1.LedgerSigner; } });
//# sourceMappingURL=index.js.map
/// <reference types="ledgerhq__hw-transport" />
import { AccountData, AminoSignResponse, OfflineAminoSigner, StdSignDoc } from "@cosmjs/amino";
import { HdPath } from "@cosmjs/crypto";
import Transport from "@ledgerhq/hw-transport";
import { LaunchpadLedgerOptions } from "./launchpadledger";
import { AddressAndPubkey, LedgerConnectorOptions } from "./ledgerconnector";
export declare class LedgerSigner implements OfflineAminoSigner {
private readonly ledger;
private readonly connector;
private readonly hdPaths;
private accounts?;
constructor(transport: Transport, options?: LaunchpadLedgerOptions);
constructor(transport: Transport, options?: LedgerConnectorOptions);
getAccounts(): Promise<readonly AccountData[]>;
/**
* Shows the user's address in the device and returns an address/pubkey pair.
*
* The address will be shown with the native prefix of the app (e.g. cosmos, persistence, desmos)
* and does not support the usage of other address prefixes.
*
* @param path The HD path to show the address for. If unset, this is the first account.
*/
showAddress(path?: HdPath): Promise<AddressAndPubkey>;
signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
}

@@ -5,14 +5,14 @@ "use strict";

const amino_1 = require("@cosmjs/amino");
const launchpadledger_1 = require("./launchpadledger");
const ledgerconnector_1 = require("./ledgerconnector");
class LedgerSigner {
constructor(transport, options = {}) {
this.hdPaths = options.hdPaths || [amino_1.makeCosmoshubPath(0)];
this.ledger = new launchpadledger_1.LaunchpadLedger(transport, options);
this.hdPaths = options.hdPaths || [(0, amino_1.makeCosmoshubPath)(0)];
this.connector = new ledgerconnector_1.LedgerConnector(transport, options);
}
async getAccounts() {
if (!this.accounts) {
const pubkeys = await this.ledger.getPubkeys();
const pubkeys = await this.connector.getPubkeys();
this.accounts = await Promise.all(pubkeys.map(async (pubkey) => ({
algo: "secp256k1",
address: await this.ledger.getCosmosAddress(pubkey),
address: await this.connector.getCosmosAddress(pubkey),
pubkey: pubkey,

@@ -23,2 +23,13 @@ })));

}
/**
* Shows the user's address in the device and returns an address/pubkey pair.
*
* The address will be shown with the native prefix of the app (e.g. cosmos, persistence, desmos)
* and does not support the usage of other address prefixes.
*
* @param path The HD path to show the address for. If unset, this is the first account.
*/
async showAddress(path) {
return this.connector.showAddress(path);
}
async signAmino(signerAddress, signDoc) {

@@ -30,9 +41,9 @@ const accounts = this.accounts || (await this.getAccounts());

}
const message = amino_1.serializeSignDoc(signDoc);
const message = (0, amino_1.serializeSignDoc)(signDoc);
const accountForAddress = accounts[accountIndex];
const hdPath = this.hdPaths[accountIndex];
const signature = await this.ledger.sign(message, hdPath);
const signature = await this.connector.sign(message, hdPath);
return {
signed: signDoc,
signature: amino_1.encodeSecp256k1Signature(accountForAddress.pubkey, signature),
signature: (0, amino_1.encodeSecp256k1Signature)(accountForAddress.pubkey, signature),
};

@@ -39,0 +50,0 @@ }

@@ -26,3 +26,2 @@ "use strict";

const encoding_1 = require("@cosmjs/encoding");
const launchpad_1 = require("@cosmjs/launchpad");
const stargate_1 = require("@cosmjs/stargate");

@@ -50,3 +49,3 @@ const utils_1 = require("@cosmjs/utils");

const defaultChainId = "testing";
const defaultFee = stargate_1.calculateFee(80000, "0.025ucosm");
const defaultFee = (0, stargate_1.calculateFee)(80000, "0.025ucosm");
const defaultMemo = "Some memo";

@@ -58,13 +57,13 @@ const defaultSequence = "0";

beforeAll(async () => {
if (testutils_spec_1.simappEnabled()) {
if ((0, testutils_spec_1.simappEnabled)()) {
const wallet = await amino_1.Secp256k1HdWallet.fromMnemonic(testutils_spec_1.faucet.mnemonic);
const client = await stargate_1.SigningStargateClient.connectWithSigner(testutils_spec_1.simapp.endpoint, wallet);
const amount = amino_1.coins(226644, "ucosm");
const amount = (0, amino_1.coins)(226644, "ucosm");
const memo = "Ensure chain has my pubkey";
const sendResult = await client.sendTokens(testutils_spec_1.faucet.address, defaultLedgerAddress, amount, defaultFee, memo);
stargate_1.assertIsBroadcastTxSuccess(sendResult);
(0, stargate_1.assertIsDeliverTxSuccess)(sendResult);
}
});
beforeEach(async () => {
if (testutils_spec_1.ledgerEnabled()) {
if ((0, testutils_spec_1.ledgerEnabled)()) {
transport = await createTransport();

@@ -74,3 +73,3 @@ }

afterEach(async () => {
if (testutils_spec_1.ledgerEnabled()) {
if ((0, testutils_spec_1.ledgerEnabled)()) {
await transport.close();

@@ -81,6 +80,6 @@ }

it("works", async () => {
testutils_spec_1.pendingWithoutLedger();
(0, testutils_spec_1.pendingWithoutLedger)();
const signer = new ledgersigner_1.LedgerSigner(transport, {
testModeAllowed: true,
hdPaths: [amino_1.makeCosmoshubPath(0), amino_1.makeCosmoshubPath(1), amino_1.makeCosmoshubPath(10)],
hdPaths: [(0, amino_1.makeCosmoshubPath)(0), (0, amino_1.makeCosmoshubPath)(1), (0, amino_1.makeCosmoshubPath)(10)],
});

@@ -93,3 +92,3 @@ const accounts = await signer.getAccounts();

algo: "secp256k1",
pubkey: encoding_1.fromBase64("A66JoCNaNSXDsyj4qW7JgqXPTz5rOnfE6EKEArf4jJEK"),
pubkey: (0, encoding_1.fromBase64)("A66JoCNaNSXDsyj4qW7JgqXPTz5rOnfE6EKEArf4jJEK"),
},

@@ -99,3 +98,3 @@ {

algo: "secp256k1",
pubkey: encoding_1.fromBase64("AtvmGuZvEN3NwL05BQdxl3XygUf+Vl/930fhFMt1HTyU"),
pubkey: (0, encoding_1.fromBase64)("AtvmGuZvEN3NwL05BQdxl3XygUf+Vl/930fhFMt1HTyU"),
},

@@ -105,3 +104,3 @@ {

algo: "secp256k1",
pubkey: encoding_1.fromBase64("A2ZnLEcbpyjS30H5UF1vezq29aBcT9oo5EARATIW9Cpj"),
pubkey: (0, encoding_1.fromBase64)("A2ZnLEcbpyjS30H5UF1vezq29aBcT9oo5EARATIW9Cpj"),
},

@@ -114,9 +113,9 @@ ]);

// It seems the Ledger device needs a bit of time to recover
await utils_1.sleep(500);
await (0, utils_1.sleep)(500);
});
it("returns valid signature", async () => {
testutils_spec_1.pendingWithoutLedger();
(0, testutils_spec_1.pendingWithoutLedger)();
const signer = new ledgersigner_1.LedgerSigner(transport, {
testModeAllowed: true,
hdPaths: [amino_1.makeCosmoshubPath(0), amino_1.makeCosmoshubPath(1), amino_1.makeCosmoshubPath(10)],
hdPaths: [(0, amino_1.makeCosmoshubPath)(0), (0, amino_1.makeCosmoshubPath)(1), (0, amino_1.makeCosmoshubPath)(10)],
});

@@ -128,3 +127,3 @@ const [firstAccount] = await signer.getAccounts();

value: {
amount: amino_1.coins(1234567, "ucosm"),
amount: (0, amino_1.coins)(1234567, "ucosm"),
from_address: firstAccount.address,

@@ -135,31 +134,19 @@ to_address: defaultLedgerAddress,

];
const signDoc = amino_1.makeSignDoc(msgs, defaultFee, defaultChainId, defaultMemo, defaultAccountNumber, defaultSequence);
const signDoc = (0, amino_1.makeSignDoc)(msgs, defaultFee, defaultChainId, defaultMemo, defaultAccountNumber, defaultSequence);
const { signed, signature } = await signer.signAmino(firstAccount.address, signDoc);
expect(signed).toEqual(signDoc);
const valid = await crypto_1.Secp256k1.verifySignature(crypto_1.Secp256k1Signature.fromFixedLength(encoding_1.fromBase64(signature.signature)), crypto_1.sha256(amino_1.serializeSignDoc(signed)), firstAccount.pubkey);
const valid = await crypto_1.Secp256k1.verifySignature(crypto_1.Secp256k1Signature.fromFixedLength((0, encoding_1.fromBase64)(signature.signature)), (0, crypto_1.sha256)((0, amino_1.serializeSignDoc)(signed)), firstAccount.pubkey);
expect(valid).toEqual(true);
}, interactiveTimeout);
it("creates signature accepted by Launchpad backend", async () => {
testutils_spec_1.pendingWithoutLedger();
testutils_spec_1.pendingWithoutLaunchpad();
const signer = new ledgersigner_1.LedgerSigner(transport, {
testModeAllowed: true,
hdPaths: [amino_1.makeCosmoshubPath(0), amino_1.makeCosmoshubPath(1), amino_1.makeCosmoshubPath(10)],
});
const [firstAccount] = await signer.getAccounts();
const client = new launchpad_1.SigningCosmosClient(testutils_spec_1.launchpad.endpoint, firstAccount.address, signer);
const result = await client.sendTokens(defaultLedgerAddress, amino_1.coins(1234567, "ucosm"));
launchpad_1.assertIsBroadcastTxSuccess(result);
}, interactiveTimeout);
it("creates signature accepted by Stargate backend", async () => {
testutils_spec_1.pendingWithoutLedger();
testutils_spec_1.pendingWithoutSimapp();
(0, testutils_spec_1.pendingWithoutLedger)();
(0, testutils_spec_1.pendingWithoutSimapp)();
const signer = new ledgersigner_1.LedgerSigner(transport, {
testModeAllowed: true,
hdPaths: [amino_1.makeCosmoshubPath(0), amino_1.makeCosmoshubPath(1), amino_1.makeCosmoshubPath(10)],
hdPaths: [(0, amino_1.makeCosmoshubPath)(0), (0, amino_1.makeCosmoshubPath)(1), (0, amino_1.makeCosmoshubPath)(10)],
});
const [firstAccount] = await signer.getAccounts();
const client = await stargate_1.SigningStargateClient.connectWithSigner(testutils_spec_1.simapp.endpoint, signer);
const result = await client.sendTokens(firstAccount.address, defaultLedgerAddress, amino_1.coins(1234, "ucosm"), defaultFee);
stargate_1.assertIsBroadcastTxSuccess(result);
const result = await client.sendTokens(firstAccount.address, defaultLedgerAddress, (0, amino_1.coins)(1234, "ucosm"), defaultFee);
(0, stargate_1.assertIsDeliverTxSuccess)(result);
}, interactiveTimeout);

@@ -166,0 +153,0 @@ });

@@ -11,10 +11,4 @@ export declare const faucet: {

export declare function pendingWithoutLedger(): void;
export declare function launchpadEnabled(): boolean;
export declare function pendingWithoutLaunchpad(): void;
export declare function simappEnabled(): boolean;
export declare function pendingWithoutSimapp(): void;
export declare const launchpad: {
endpoint: string;
chainId: string;
};
export declare const simapp: {

@@ -21,0 +15,0 @@ endpoint: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simapp = exports.launchpad = exports.pendingWithoutSimapp = exports.simappEnabled = exports.pendingWithoutLaunchpad = exports.launchpadEnabled = exports.pendingWithoutLedger = exports.ledgerEnabled = exports.faucet = void 0;
exports.simapp = exports.pendingWithoutSimapp = exports.simappEnabled = exports.pendingWithoutLedger = exports.ledgerEnabled = exports.faucet = void 0;
exports.faucet = {

@@ -22,12 +22,2 @@ mnemonic: "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone",

exports.pendingWithoutLedger = pendingWithoutLedger;
function launchpadEnabled() {
return !!process.env.LAUNCHPAD_ENABLED;
}
exports.launchpadEnabled = launchpadEnabled;
function pendingWithoutLaunchpad() {
if (!launchpadEnabled()) {
return pending("Set LAUNCHPAD_ENABLED to enable Launchpad-based tests");
}
}
exports.pendingWithoutLaunchpad = pendingWithoutLaunchpad;
function simappEnabled() {

@@ -43,6 +33,2 @@ return !!process.env.SIMAPP42_ENABLED || !!process.env.SIMAPP44_ENABLED;

exports.pendingWithoutSimapp = pendingWithoutSimapp;
exports.launchpad = {
endpoint: "http://localhost:1317",
chainId: "testing",
};
exports.simapp = {

@@ -49,0 +35,0 @@ endpoint: "ws://localhost:26658",

{
"name": "@cosmjs/ledger-amino",
"version": "0.26.6",
"version": "0.26.8",
"description": "A library for signing Amino-encoded transactions using Ledger devices",

@@ -33,3 +33,3 @@ "contributors": [

"build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build",
"test-node": "node --require esm jasmine-testrunner.js",
"test-node": "yarn node jasmine-testrunner.js",
"test": "yarn build-or-skip && yarn test-node",

@@ -41,7 +41,7 @@ "demo-node": "yarn build-or-skip && node ./demo/node.js",

"dependencies": {
"@cosmjs/amino": "0.26.6",
"@cosmjs/crypto": "0.26.6",
"@cosmjs/encoding": "0.26.6",
"@cosmjs/math": "0.26.6",
"@cosmjs/utils": "0.26.6",
"@cosmjs/amino": "0.26.8",
"@cosmjs/crypto": "0.26.8",
"@cosmjs/encoding": "0.26.8",
"@cosmjs/math": "0.26.8",
"@cosmjs/utils": "0.26.8",
"ledger-cosmos-js": "^2.1.8",

@@ -51,4 +51,3 @@ "semver": "^7.3.2"

"devDependencies": {
"@cosmjs/launchpad": "0.26.6",
"@cosmjs/stargate": "0.26.6",
"@cosmjs/stargate": "0.26.8",
"@istanbuljs/nyc-config-typescript": "^1.0.1",

@@ -64,4 +63,4 @@ "@ledgerhq/hw-transport": "^5.25.0",

"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.28",
"@typescript-eslint/parser": "^4.28",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"eslint": "^7.5",

@@ -75,3 +74,3 @@ "eslint-config-prettier": "^8.3.0",

"glob": "^7.1.6",
"jasmine": "^3.8",
"jasmine": "^3.99",
"jasmine-spec-reporter": "^6",

@@ -83,4 +82,4 @@ "nyc": "^15.1.0",

"ts-node": "^8",
"typedoc": "^0.21",
"typescript": "~4.3",
"typedoc": "^0.22",
"typescript": "~4.4",
"webpack": "^5.32.0",

@@ -87,0 +86,0 @@ "webpack-cli": "^4.6.0"

@@ -30,11 +30,9 @@ # @cosmjs/ledger-amino

Build the package for web:
Serve the project locally:
```sh
# Build the package for web
yarn pack-web
```
Host the `ledger-amino` package directory, for example using Python 3:
```sh
# Host the `ledger-amino` package directory, for example using Python 3
python3 -m http.server

@@ -41,0 +39,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc