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

@cosmjs/amino

Package Overview
Dependencies
Maintainers
3
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/amino - npm Package Compare versions

Comparing version 0.26.0 to 0.26.1

65

build/encoding.js

@@ -60,2 +60,6 @@ "use strict";

}
else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixMultisigThreshold)) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return decodeMultisigPubkey(data);
}
else {

@@ -78,2 +82,63 @@ throw new Error("Unsupported public key type. Amino data starts with: " + encoding_1.toHex(data.slice(0, 5)));

/**
* Uvarint decoder for Amino.
* @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/decoder.go#L64-76
* @returns varint as number, and bytes count occupied by varaint
*/
function decodeUvarint(reader) {
if (reader.length < 1) {
throw new Error("Can't decode varint. EOF");
}
if (reader[0] > 127) {
throw new Error("Decoding numbers > 127 is not supported here. Please tell those lazy CosmJS maintainers to port the binary.Varint implementation from the Go standard library and write some tests.");
}
return [reader[0], 1];
}
/**
* Decodes a multisig pubkey to type object.
* Pubkey structure [ prefix + const + threshold + loop:(const + pubkeyLength + pubkey ) ]
* [ 4b + 1b + varint + loop:(1b + varint + pubkeyLength bytes) ]
* @param data encoded pubkey
*/
function decodeMultisigPubkey(data) {
const reader = Array.from(data);
// remove multisig amino prefix;
const prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length);
if (!utils_1.arrayContentStartsWith(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
throw new Error("Invalid multisig prefix.");
}
// remove 0x08 threshold prefix;
if (reader.shift() != 0x08) {
throw new Error("Invalid multisig data. Expecting 0x08 prefix before threshold.");
}
// read threshold
const [threshold, thresholdBytesLength] = decodeUvarint(reader);
reader.splice(0, thresholdBytesLength);
// read participants pubkeys
const pubkeys = [];
while (reader.length > 0) {
// remove 0x12 threshold prefix;
if (reader.shift() != 0x12) {
throw new Error("Invalid multisig data. Expecting 0x12 prefix before participant pubkey length.");
}
// read pubkey length
const [pubkeyLength, pubkeyLengthBytesSize] = decodeUvarint(reader);
reader.splice(0, pubkeyLengthBytesSize);
// verify that we can read pubkey
if (reader.length < pubkeyLength) {
throw new Error("Invalid multisig data length.");
}
// read and decode participant pubkey
const encodedPubkey = reader.splice(0, pubkeyLength);
const pubkey = decodeAminoPubkey(Uint8Array.from(encodedPubkey));
pubkeys.push(pubkey);
}
return {
type: pubkeys_1.pubkeyType.multisigThreshold,
value: {
threshold: threshold.toString(),
pubkeys: pubkeys,
},
};
}
/**
* Uvarint encoder for Amino. This is the same encoding as `binary.PutUvarint` from the Go

@@ -80,0 +145,0 @@ * standard library.

53

build/encoding.spec.js

@@ -40,2 +40,42 @@ "use strict";

});
it("works for multisig", () => {
const pubkeyData = encoding_1.Bech32.decode("cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5").data;
const pubkey = {
type: "tendermint/PubKeySecp256k1",
value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ",
};
const data1 = encoding_1.fromHex("22C1F7E20805");
expect(encoding_2.decodeAminoPubkey(data1)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "5",
pubkeys: [],
},
});
const data2 = Uint8Array.from([...encoding_1.fromHex("22C1F7E2081a"), 0x12, pubkeyData.length, ...pubkeyData]);
expect(encoding_2.decodeAminoPubkey(data2)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "26",
pubkeys: [pubkey],
},
});
const data3 = Uint8Array.from([
...encoding_1.fromHex("22C1F7E2081a"),
0x12,
pubkeyData.length,
...pubkeyData,
0x12,
pubkeyData.length,
...pubkeyData,
]);
expect(encoding_2.decodeAminoPubkey(data3)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "26",
pubkeys: [pubkey, pubkey],
},
});
expect(() => encoding_2.decodeAminoPubkey(encoding_1.fromHex("22C1F7E20705"))).toThrowError(/expecting 0x08 prefix/i);
});
});

@@ -64,2 +104,7 @@ describe("decodeBech32Pubkey", () => {

});
it("works for multisig", () => {
expect(encoding_2.decodeBech32Pubkey(testutils_spec_1.testgroup1PubkeyBech32)).toEqual(testutils_spec_1.testgroup1);
expect(encoding_2.decodeBech32Pubkey(testutils_spec_1.testgroup2PubkeyBech32)).toEqual(testutils_spec_1.testgroup2);
expect(encoding_2.decodeBech32Pubkey(testutils_spec_1.testgroup3PubkeyBech32)).toEqual(testutils_spec_1.testgroup3);
});
});

@@ -104,9 +149,9 @@ describe("encodeAminoPubkey", () => {

it("works for multisig", () => {
const expected1 = encoding_1.Bech32.decode(testutils_spec_1.testgroup1Address).data;
const expected1 = encoding_1.Bech32.decode(testutils_spec_1.testgroup1PubkeyBech32).data;
expect(encoding_2.encodeAminoPubkey(testutils_spec_1.testgroup1)).toEqual(expected1);
const expected2 = encoding_1.Bech32.decode(testutils_spec_1.testgroup2Address).data;
const expected2 = encoding_1.Bech32.decode(testutils_spec_1.testgroup2PubkeyBech32).data;
expect(encoding_2.encodeAminoPubkey(testutils_spec_1.testgroup2)).toEqual(expected2);
const expected3 = encoding_1.Bech32.decode(testutils_spec_1.testgroup3Address).data;
const expected3 = encoding_1.Bech32.decode(testutils_spec_1.testgroup3PubkeyBech32).data;
expect(encoding_2.encodeAminoPubkey(testutils_spec_1.testgroup3)).toEqual(expected3);
const expected4 = encoding_1.Bech32.decode(testutils_spec_1.testgroup4Address).data;
const expected4 = encoding_1.Bech32.decode(testutils_spec_1.testgroup4PubkeyBech32).data;
expect(encoding_2.encodeAminoPubkey(testutils_spec_1.testgroup4)).toEqual(expected4);

@@ -113,0 +158,0 @@ });

8

build/testutils.spec.d.ts

@@ -7,8 +7,8 @@ import { MultisigThresholdPubkey } from "./pubkeys";

export declare const testgroup1: MultisigThresholdPubkey;
export declare const testgroup1Address = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7v7aysdd";
export declare const testgroup1PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7v7aysdd";
export declare const testgroup2: MultisigThresholdPubkey;
export declare const testgroup2Address = "wasmpub1ytql0csgqyfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vc4ejke";
export declare const testgroup2PubkeyBech32 = "wasmpub1ytql0csgqyfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vc4ejke";
export declare const testgroup3: MultisigThresholdPubkey;
export declare const testgroup3Address = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vzjhugu";
export declare const testgroup3PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vzjhugu";
export declare const testgroup4: MultisigThresholdPubkey;
export declare const testgroup4Address = "wasmpub1ytql0csgqgfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vujvg56k";
export declare const testgroup4PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vujvg56k";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.testgroup4Address = exports.testgroup4 = exports.testgroup3Address = exports.testgroup3 = exports.testgroup2Address = exports.testgroup2 = exports.testgroup1Address = exports.testgroup1 = exports.test3 = exports.test2 = exports.test1 = exports.base64Matcher = void 0;
exports.testgroup4PubkeyBech32 = exports.testgroup4 = exports.testgroup3PubkeyBech32 = exports.testgroup3 = exports.testgroup2PubkeyBech32 = exports.testgroup2 = exports.testgroup1PubkeyBech32 = exports.testgroup1 = exports.test3 = exports.test2 = exports.test1 = exports.base64Matcher = void 0;
const encoding_1 = require("./encoding");

@@ -25,3 +25,3 @@ exports.base64Matcher = /^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$/;

};
exports.testgroup1Address = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7v7aysdd";
exports.testgroup1PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7v7aysdd";
exports.testgroup2 = {

@@ -34,3 +34,3 @@ type: "tendermint/PubKeyMultisigThreshold",

};
exports.testgroup2Address = "wasmpub1ytql0csgqyfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vc4ejke";
exports.testgroup2PubkeyBech32 = "wasmpub1ytql0csgqyfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq5sdudaj5tv3nfm2f3exgkgqxlcwfxplf0g0rqwx2um6mqthzc0dqfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vc4ejke";
// 2/2 multisig

@@ -44,3 +44,3 @@ exports.testgroup3 = {

};
exports.testgroup3Address = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vzjhugu";
exports.testgroup3PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vufzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vzjhugu";
// 2/2 multisig with custom sorting

@@ -54,3 +54,3 @@ exports.testgroup4 = {

};
exports.testgroup4Address = "wasmpub1ytql0csgqgfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vujvg56k";
exports.testgroup4PubkeyBech32 = "wasmpub1ytql0csgqgfzd666axrjzq7vjdge6cdksmdx7r5vl72rrc6kk30ezp376mup77wamzvgtzqq7vfzd666axrjzquvkkvwu4qnp5603cyp3emc02sxzwdqutgqym9dke3t2h83dpv6vujvg56k";
//# sourceMappingURL=testutils.spec.js.map
{
"name": "@cosmjs/amino",
"version": "0.26.0",
"version": "0.26.1",
"description": "Helpers for Amino based signing which are shared between @cosmjs/launchpad and @cosmjs/stargate.",

@@ -43,6 +43,6 @@ "contributors": [

"dependencies": {
"@cosmjs/crypto": "0.26.0",
"@cosmjs/encoding": "0.26.0",
"@cosmjs/math": "0.26.0",
"@cosmjs/utils": "0.26.0"
"@cosmjs/crypto": "0.26.1",
"@cosmjs/encoding": "0.26.1",
"@cosmjs/math": "0.26.1",
"@cosmjs/utils": "0.26.1"
},

@@ -49,0 +49,0 @@ "devDependencies": {

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