Merge pull request #190 from CosmWasm/upgrade-iov-core

Upgrade @iov/* dependencies to 2.3.2
This commit is contained in:
Ethan Frey 2020-06-08 09:52:14 +02:00 committed by GitHub
commit 57d0686ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 127 additions and 238 deletions

View File

@ -40,18 +40,18 @@
},
"dependencies": {
"@cosmjs/sdk38": "^0.8.0",
"@iov/bcp": "^2.1.0",
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/stream": "^2.0.2",
"@iov/utils": "^2.0.2",
"@iov/bcp": "^2.3.2",
"@iov/crypto": "^2.3.2",
"@iov/encoding": "^2.3.2",
"@iov/stream": "^2.3.2",
"@iov/utils": "^2.3.2",
"bn.js": "^5.1.1",
"fast-deep-equal": "^3.1.1",
"readonly-date": "^1.0.0",
"xstream": "^11.11.0"
},
"devDependencies": {
"@iov/keycontrol": "^2.1.0",
"@iov/keycontrol": "^2.3.2",
"@types/bn.js": "^4.11.6"
}
}

View File

@ -1,10 +1,8 @@
import { Algorithm, PubkeyBytes } from "@iov/bcp";
import { Encoding } from "@iov/encoding";
import { fromBase64, fromHex } from "@iov/encoding";
import { pubkeyToAddress } from "./address";
const { fromBase64, fromHex } = Encoding;
describe("address", () => {
describe("pubkeyToAddress", () => {
it("works for Secp256k1 compressed", () => {

View File

@ -1,9 +1,7 @@
import { PubKey, pubkeyToAddress as sdkPubkeyToAddress, pubkeyType } from "@cosmjs/sdk38";
import { Address, Algorithm, PubkeyBundle } from "@iov/bcp";
import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
const { toBase64 } = Encoding;
import { toBase64 } from "@iov/encoding";
// See https://github.com/tendermint/tendermint/blob/f2ada0a604b4c0763bda2f64fac53d506d3beca7/docs/spec/blockchain/encoding.md#public-key-cryptography
export function pubkeyToAddress(pubkey: PubkeyBundle, prefix: string): Address {

View File

@ -1,8 +1,6 @@
import { ChainId } from "@iov/bcp";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
const { toHex, toUtf8 } = Encoding;
import { toHex, toUtf8 } from "@iov/encoding";
const hashedPrefix = "hashed-";

View File

@ -1,12 +1,10 @@
import { PostableBytes, PrehashType } from "@iov/bcp";
import { Encoding } from "@iov/encoding";
import { toUtf8 } from "@iov/encoding";
import { CosmosCodec } from "./cosmoscodec";
import { chainId, nonce, sendTxJson, signedTxBin, signedTxEncodedJson, signedTxJson } from "./testdata.spec";
import { BankToken } from "./types";
const { toUtf8 } = Encoding;
const defaultPrefix = "cosmos";
const defaultBankTokens: readonly BankToken[] = [

View File

@ -18,7 +18,7 @@ import {
UnsignedTransaction,
} from "@iov/bcp";
import { Random, Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
import { Bech32, Encoding } from "@iov/encoding";
import { Bech32, fromBase64 } from "@iov/encoding";
import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol";
import { assert } from "@iov/utils";
import BN from "bn.js";
@ -27,8 +27,6 @@ import { CosmosConnection, TokenConfiguration } from "./cosmosconnection";
import { encodeFullSignature } from "./encode";
import * as testdata from "./testdata.spec";
const { fromBase64 } = Encoding;
function pendingWithoutWasmd(): void {
if (!process.env.WASMD_ENABLED) {
return pending("Set WASMD_ENABLED to enable Cosmos node-based tests");

View File

@ -35,7 +35,7 @@ import {
TxCodec,
UnsignedTransaction,
} from "@iov/bcp";
import { Encoding, Uint53 } from "@iov/encoding";
import { fromUtf8, Uint53 } from "@iov/encoding";
import { concat, DefaultValueProducer, ValueAndUpdates } from "@iov/stream";
import equal from "fast-deep-equal";
import { ReadonlyDate } from "readonly-date";
@ -255,7 +255,7 @@ export class CosmosConnection implements BlockchainConnection {
}
public async postTx(tx: PostableBytes): Promise<PostTxResponse> {
const txAsJson = JSON.parse(Encoding.fromUtf8(tx));
const txAsJson = JSON.parse(fromUtf8(tx));
if (!isStdTx(txAsJson)) throw new Error("Postable bytes must contain a JSON encoded StdTx");
const { transactionHash, rawLog } = await this.cosmosClient.postTx(txAsJson);
const transactionId = transactionHash as TransactionId;

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Coin, IndexedTx, Msg, PubKey, StdSignature } from "@cosmjs/sdk38";
import { Address, Algorithm, SendTransaction, TokenTicker } from "@iov/bcp";
import { Encoding } from "@iov/encoding";
import { fromBase64, fromHex } from "@iov/encoding";
import {
decodeAmount,
@ -19,8 +19,6 @@ import * as testdata from "./testdata.spec";
import cosmoshub from "./testdata/cosmoshub.json";
import { BankToken } from "./types";
const { fromBase64, fromHex } = Encoding;
describe("decode", () => {
const defaultPubkey = {
algo: Algorithm.Secp256k1,

View File

@ -29,12 +29,10 @@ import {
TransactionId,
UnsignedTransaction,
} from "@iov/bcp";
import { Decimal, Encoding } from "@iov/encoding";
import { Decimal, fromBase64 } from "@iov/encoding";
import { BankToken } from "./types";
const { fromBase64 } = Encoding;
export function decodePubkey(pubkey: PubKey): PubkeyBundle {
switch (pubkey.type) {
case pubkeyType.secp256k1:

View File

@ -11,7 +11,7 @@ import {
SignedTransaction,
TokenTicker,
} from "@iov/bcp";
import { Encoding } from "@iov/encoding";
import { fromBase64 } from "@iov/encoding";
import {
buildSignedTx,
@ -23,8 +23,6 @@ import {
} from "./encode";
import { BankToken } from "./types";
const { fromBase64 } = Encoding;
describe("encode", () => {
const atom = "ATOM" as TokenTicker;
// https://rpc.cosmos.network:26657/tx?hash=0x2268EB5AB730B45F8426078827BB5BB49819CE2B0D74B2C1D191070BADB379F1&prove=true

View File

@ -20,12 +20,10 @@ import {
UnsignedTransaction,
} from "@iov/bcp";
import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { toBase64 } from "@iov/encoding";
import { BankToken } from "./types";
const { toBase64 } = Encoding;
// TODO: This function seems to be unused and is not well tested (e.g. uncompressed secp256k1 or ed25519)
export function encodePubkey(pubkey: PubkeyBundle): PubKey {
switch (pubkey.algo) {

View File

@ -12,12 +12,10 @@ import {
TokenTicker,
TransactionId,
} from "@iov/bcp";
import { Encoding } from "@iov/encoding";
import { fromBase64, toUtf8 } from "@iov/encoding";
import data from "./testdata/cosmoshub.json";
const { fromBase64, toUtf8 } = Encoding;
export const pubJson: PubkeyBundle = {
algo: Algorithm.Secp256k1,
data: fromBase64(data.tx.value.signatures[0].pub_key.value) as PubkeyBytes,

View File

@ -40,9 +40,9 @@
"dependencies": {
"@cosmjs/cosmwasm": "^0.8.0",
"@cosmjs/sdk38": "^0.8.0",
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/utils": "^2.0.2",
"@iov/crypto": "^2.3.2",
"@iov/encoding": "^2.3.2",
"@iov/utils": "^2.3.2",
"axios": "^0.19.2",
"babylon": "^6.18.0",
"colors": "^1.3.3",

View File

@ -102,8 +102,15 @@ export function main(originalArgs: readonly string[]): void {
[
"@iov/encoding",
[
"fromAscii",
"fromBase64",
"fromHex",
"fromUtf8",
"toAscii",
"toBase64",
"toHex",
"toUtf8",
"Bech32",
"Encoding",
"Decimal",
// integers
"Int53",
@ -122,17 +129,6 @@ export function main(originalArgs: readonly string[]): void {
for (const [moduleName, symbols] of imports.entries()) {
console.info(colors.yellow(` * from ${moduleName}: ${symbols.join(", ")}`));
}
const encodingHelpers = [
"fromAscii",
"fromBase64",
"fromHex",
"fromUtf8",
"toAscii",
"toBase64",
"toHex",
"toUtf8",
];
console.info(colors.yellow(` * helper functions: ${encodingHelpers.join(", ")}`));
let init = `
import axios from "axios";
@ -141,8 +137,6 @@ export function main(originalArgs: readonly string[]): void {
for (const [moduleName, symbols] of imports.entries()) {
init += `import { ${symbols.join(", ")} } from "${moduleName}";\n`;
}
// helper functions
init += `const { ${encodingHelpers.join(", ")} } = Encoding;\n`;
if (args.selftest) {
// execute some trival stuff and exit
@ -167,7 +161,7 @@ export function main(originalArgs: readonly string[]): void {
const pen = await Secp256k1Pen.fromMnemonic(mnemonic, makeCosmoshubPath(0));
const pubkey = encodeSecp256k1Pubkey(pen.pubkey);
const address = pubkeyToAddress(pubkey, "cosmos");
const data = Encoding.toAscii("foo bar");
const data = toAscii("foo bar");
const signature = await pen.sign(data);
console.info("Done testing, will exit now.");

View File

@ -37,9 +37,9 @@
},
"dependencies": {
"@cosmjs/sdk38": "^0.8.0",
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/utils": "^2.0.2",
"@iov/crypto": "^2.3.2",
"@iov/encoding": "^2.3.2",
"@iov/utils": "^2.3.2",
"axios": "^0.19.0",
"fast-deep-equal": "^3.1.1",
"pako": "^1.0.11"

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
import { makeSignBytes, MsgSend, Secp256k1Pen, StdFee } from "@cosmjs/sdk38";
import { Sha256 } from "@iov/crypto";
import { Bech32, Encoding } from "@iov/encoding";
import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@iov/encoding";
import { assert, sleep } from "@iov/utils";
import { ReadonlyDate } from "readonly-date";
@ -21,8 +21,6 @@ import {
wasmdEnabled,
} from "./testutils.spec";
const { fromHex, fromUtf8, toAscii, toBase64 } = Encoding;
const guest = {
address: "cosmos17d0jcz59jf68g52vq38tuuncmwwjk42u6mcxej",
};

View File

@ -8,7 +8,7 @@ import {
StdTx,
} from "@cosmjs/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { fromBase64, fromHex, toHex } from "@iov/encoding";
import { Log, parseLogs } from "./logs";
import { RestClient } from "./restclient";
@ -185,7 +185,7 @@ export class CosmWasmClient {
// We consult the REST API because we don't have a local amino encoder
const bytes = await this.restClient.encodeTx(tx);
const hash = new Sha256(bytes).digest();
return Encoding.toHex(hash).toUpperCase();
return toHex(hash).toUpperCase();
}
/**
@ -242,7 +242,7 @@ export class CosmWasmClient {
height: parseInt(response.block.header.height, 10),
chainId: response.block.header.chain_id,
},
txs: (response.block.data.txs || []).map((encoded) => Encoding.fromBase64(encoded)),
txs: (response.block.data.txs || []).map(fromBase64),
};
}
@ -315,7 +315,7 @@ export class CosmWasmClient {
return {
id: entry.id,
creator: entry.creator,
checksum: Encoding.toHex(Encoding.fromHex(entry.data_hash)),
checksum: toHex(fromHex(entry.data_hash)),
source: entry.source || undefined,
builder: entry.builder || undefined,
};
@ -331,10 +331,10 @@ export class CosmWasmClient {
const codeDetails: CodeDetails = {
id: getCodeResult.id,
creator: getCodeResult.creator,
checksum: Encoding.toHex(Encoding.fromHex(getCodeResult.data_hash)),
checksum: toHex(fromHex(getCodeResult.data_hash)),
source: getCodeResult.source || undefined,
builder: getCodeResult.builder || undefined,
data: Encoding.fromBase64(getCodeResult.data),
data: fromBase64(getCodeResult.data),
};
this.codesCache.set(codeId, codeDetails);
return codeDetails;

View File

@ -15,7 +15,7 @@ import {
StdTx,
} from "@cosmjs/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { fromAscii, fromBase64, fromHex, toAscii, toBase64, toHex } from "@iov/encoding";
import { assert, sleep } from "@iov/utils";
import { ReadonlyDate } from "readonly-date";
@ -49,8 +49,6 @@ import {
wasmdEnabled,
} from "./testutils.spec";
const { fromAscii, fromBase64, fromHex, toAscii, toBase64, toHex } = Encoding;
const emptyAddress = "cosmos1ltkhnmdcqemmd2tkhnx7qx66tq7e0wykw2j85k";
function makeSignedTx(firstMsg: Msg, fee: StdFee, memo: string, firstSignature: StdSignature): StdTx {

View File

@ -1,10 +1,8 @@
import { BroadcastMode, CosmosSdkTx, RestClient as BaseRestClient } from "@cosmjs/sdk38";
import { Encoding } from "@iov/encoding";
import { fromBase64, fromUtf8, toHex, toUtf8 } from "@iov/encoding";
import { JsonObject, Model, parseWasmData, WasmData } from "./types";
const { fromBase64, fromUtf8, toHex, toUtf8 } = Encoding;
// Currently all wasm query responses return json-encoded strings...
// later deprecate this and use the specific types for result
// (assuming it is inlined, no second parse needed)

View File

@ -1,6 +1,6 @@
import { Coin, Secp256k1Pen } from "@cosmjs/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { toHex } from "@iov/encoding";
import { assert } from "@iov/utils";
import { PrivateCosmWasmClient } from "./cosmwasmclient";
@ -8,8 +8,6 @@ import { RestClient } from "./restclient";
import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
import { alice, getHackatom, makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec";
const { toHex } = Encoding;
const httpUrl = "http://localhost:1317";
describe("SigningCosmWasmClient", () => {

View File

@ -1,6 +1,6 @@
import { BroadcastMode, Coin, coins, makeSignBytes, MsgSend, StdFee, StdSignature } from "@cosmjs/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { toBase64, toHex } from "@iov/encoding";
import pako from "pako";
import { isValidBuilder } from "./builder";
@ -136,7 +136,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
value: {
sender: this.senderAddress,
// eslint-disable-next-line @typescript-eslint/camelcase
wasm_byte_code: Encoding.toBase64(compressed),
wasm_byte_code: toBase64(compressed),
source: source,
builder: builder,
},
@ -157,9 +157,9 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const codeIdAttr = findAttribute(result.logs, "message", "code_id");
return {
originalSize: wasmCode.length,
originalChecksum: Encoding.toHex(new Sha256(wasmCode).digest()),
originalChecksum: toHex(new Sha256(wasmCode).digest()),
compressedSize: compressed.length,
compressedChecksum: Encoding.toHex(new Sha256(compressed).digest()),
compressedChecksum: toHex(new Sha256(compressed).digest()),
codeId: Number.parseInt(codeIdAttr.value, 10),
logs: result.logs,
transactionHash: result.transactionHash,

View File

@ -1,10 +1,10 @@
import { Random } from "@iov/crypto";
import { Bech32, Encoding } from "@iov/encoding";
import { Bech32, fromBase64 } from "@iov/encoding";
import hackatom from "./testdata/contract.json";
export function getHackatom(): Uint8Array {
return Encoding.fromBase64(hackatom.data);
return fromBase64(hackatom.data);
}
export function makeRandomAddress(): string {

View File

@ -1,6 +1,4 @@
import { Encoding } from "@iov/encoding";
const { fromBase64, fromHex } = Encoding;
import { fromBase64, fromHex } from "@iov/encoding";
export interface WasmData {
// key is hex-encoded

View File

@ -35,13 +35,7 @@
},
"dependencies": {
"@cosmjs/cosmwasm": "^0.8.0",
"@cosmjs/sdk38": "^0.8.0",
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/stream": "^2.0.2",
"@iov/utils": "^2.0.2"
"@cosmjs/sdk38": "^0.8.0"
},
"devDependencies": {
"@iov/keycontrol": "^2.1.0"
}
"devDependencies": {}
}

View File

@ -36,9 +36,9 @@
},
"dependencies": {
"@cosmjs/sdk38": "^0.8.0",
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/utils": "^2.0.2",
"@iov/crypto": "^2.3.2",
"@iov/encoding": "^2.3.2",
"@iov/utils": "^2.3.2",
"@koa/cors": "^3.0.0",
"axios": "^0.19.0",
"koa": "^2.11.0",

View File

@ -1,44 +0,0 @@
import { Slip10RawIndex } from "@iov/crypto";
import { debugPath } from "./hdpaths";
describe("hdpaths", () => {
describe("debugPath", () => {
it("works for no component", () => {
// See https://github.com/bitcoin/bips/blob/master/bip-0032/derivation.png from BIP32
expect(debugPath([])).toEqual("m");
});
it("works for normal components", () => {
const one = Slip10RawIndex.normal(1);
expect(debugPath([one])).toEqual("m/1");
expect(debugPath([one, one])).toEqual("m/1/1");
expect(debugPath([one, one, one])).toEqual("m/1/1/1");
const min = Slip10RawIndex.normal(0);
expect(debugPath([min])).toEqual("m/0");
const max = Slip10RawIndex.normal(2 ** 31 - 1);
expect(debugPath([max])).toEqual("m/2147483647");
});
it("works for hardened components", () => {
const one = Slip10RawIndex.hardened(1);
expect(debugPath([one])).toEqual("m/1'");
expect(debugPath([one, one])).toEqual("m/1'/1'");
expect(debugPath([one, one, one])).toEqual("m/1'/1'/1'");
const min = Slip10RawIndex.hardened(0);
expect(debugPath([min])).toEqual("m/0'");
const max = Slip10RawIndex.hardened(2 ** 31 - 1);
expect(debugPath([max])).toEqual("m/2147483647'");
});
it("works for mixed components", () => {
const one = Slip10RawIndex.normal(1);
const two = Slip10RawIndex.hardened(2);
expect(debugPath([one, two, two, one])).toEqual("m/1/2'/2'/1");
});
});
});

View File

@ -1,10 +0,0 @@
import { Slip10RawIndex } from "@iov/crypto";
export function debugPath(path: readonly Slip10RawIndex[]): string {
return path.reduce((current, component): string => {
const componentString = component.isHardened()
? `${component.toNumber() - 2 ** 31}'`
: component.toString();
return current + "/" + componentString;
}, "m");
}

View File

@ -1,6 +1,5 @@
import { makeCosmoshubPath, Pen, Secp256k1Pen } from "@cosmjs/sdk38";
import { debugPath } from "./hdpaths";
import { pathToString } from "@iov/crypto";
export async function createPens(
mnemonic: string,
@ -18,7 +17,7 @@ export async function createPens(
const address = pen.address(addressPrefix);
if (logging) {
const role = i === 0 ? "token holder " : `distributor ${i}`;
console.info(`Created ${role} (${debugPath(path)}): ${address}`);
console.info(`Created ${role} (${pathToString(path)}): ${address}`);
}
pens.push([address, pen]);
}

View File

@ -36,9 +36,9 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@iov/crypto": "^2.1.0",
"@iov/encoding": "^2.1.0",
"@iov/utils": "^2.0.2",
"@iov/crypto": "^2.3.2",
"@iov/encoding": "^2.3.2",
"@iov/utils": "^2.3.2",
"axios": "^0.19.0",
"fast-deep-equal": "^3.1.1"
},

View File

@ -1,9 +1,7 @@
import { Encoding } from "@iov/encoding";
import { fromHex, toBase64 } from "@iov/encoding";
import { pubkeyToAddress } from "./address";
const { toBase64, fromHex } = Encoding;
describe("address", () => {
describe("pubkeyToAddress", () => {
it("works for Secp256k1 compressed", () => {

View File

@ -1,10 +1,8 @@
import { Ripemd160, Sha256 } from "@iov/crypto";
import { Bech32, Encoding } from "@iov/encoding";
import { Bech32, fromBase64 } from "@iov/encoding";
import { PubKey, pubkeyType } from "./types";
const { fromBase64 } = Encoding;
export function rawSecp256k1PubkeyToAddress(pubkeyRaw: Uint8Array, prefix: string): string {
if (pubkeyRaw.length !== 33) {
throw new Error(`Invalid Secp256k1 pubkey length (compressed): ${pubkeyRaw.length}`);

View File

@ -1,5 +1,5 @@
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { fromBase64, toHex } from "@iov/encoding";
import { Coin } from "./coins";
import { Log, parseLogs } from "./logs";
@ -167,7 +167,7 @@ export class CosmosClient {
// We consult the REST API because we don't have a local amino encoder
const bytes = await this.restClient.encodeTx(tx);
const hash = new Sha256(bytes).digest();
return Encoding.toHex(hash).toUpperCase();
return toHex(hash).toUpperCase();
}
/**
@ -224,7 +224,7 @@ export class CosmosClient {
height: parseInt(response.block.header.height, 10),
chainId: response.block.header.chain_id,
},
txs: (response.block.data.txs || []).map((encoded) => Encoding.fromBase64(encoded)),
txs: (response.block.data.txs || []).map(fromBase64),
};
}

View File

@ -1,9 +1,9 @@
import { Encoding } from "@iov/encoding";
import { fromUtf8 } from "@iov/encoding";
import { isStdTx, StdTx } from "./types";
export function unmarshalTx(data: Uint8Array): StdTx {
const decoded = JSON.parse(Encoding.fromUtf8(data));
const decoded = JSON.parse(fromUtf8(data));
if (!isStdTx(decoded)) {
throw new Error("Must be json encoded StdTx");
}

View File

@ -1,9 +1,7 @@
import { Encoding } from "@iov/encoding";
import { toUtf8 } from "@iov/encoding";
import { Msg, StdFee, StdTx } from "./types";
const { toUtf8 } = Encoding;
function sortJson(json: any): any {
if (typeof json !== "object" || json === null) {
return json;
@ -24,7 +22,7 @@ function sortJson(json: any): any {
export function marshalTx(tx: StdTx): Uint8Array {
const json = JSON.stringify(tx);
return Encoding.toUtf8(json);
return toUtf8(json);
}
interface SignJson {

View File

@ -1,11 +1,9 @@
import { Secp256k1, Secp256k1Signature, Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { fromHex, toAscii } from "@iov/encoding";
import { Secp256k1Pen } from "./pen";
import { decodeSignature } from "./signature";
const { fromHex } = Encoding;
describe("Sec256k1Pen", () => {
it("can be constructed", async () => {
const pen = await Secp256k1Pen.fromMnemonic(
@ -33,7 +31,7 @@ describe("Sec256k1Pen", () => {
const pen = await Secp256k1Pen.fromMnemonic(
"special sign fit simple patrol salute grocery chicken wheat radar tonight ceiling",
);
const data = Encoding.toAscii("foo bar");
const data = toAscii("foo bar");
const { pubkey, signature } = decodeSignature(await pen.sign(data));
const valid = await Secp256k1.verifySignature(

View File

@ -1,10 +1,8 @@
import { Encoding } from "@iov/encoding";
import { fromBase64 } from "@iov/encoding";
import { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
import { PubKey } from "./types";
const { fromBase64 } = Encoding;
describe("pubkey", () => {
describe("encodeSecp256k1Pubkey", () => {
it("encodes a compresed pubkey", () => {

View File

@ -1,4 +1,4 @@
import { Bech32, Encoding } from "@iov/encoding";
import { Bech32, fromBase64, fromHex, toBase64, toHex } from "@iov/encoding";
import equal from "fast-deep-equal";
import { PubKey, pubkeyType } from "./types";
@ -9,16 +9,16 @@ export function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey {
}
return {
type: pubkeyType.secp256k1,
value: Encoding.toBase64(pubkey),
value: toBase64(pubkey),
};
}
// As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
// Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
// Last bytes is varint-encoded length prefix
const pubkeyAminoPrefixSecp256k1 = Encoding.fromHex("eb5ae98721");
const pubkeyAminoPrefixEd25519 = Encoding.fromHex("1624de6420");
const pubkeyAminoPrefixSr25519 = Encoding.fromHex("0dfb1005");
const pubkeyAminoPrefixSecp256k1 = fromHex("eb5ae98721");
const pubkeyAminoPrefixEd25519 = fromHex("1624de6420");
const pubkeyAminoPrefixSr25519 = fromHex("0dfb1005");
const pubkeyAminoPrefixLength = pubkeyAminoPrefixSecp256k1.length;
export function decodeBech32Pubkey(bechEncoded: string): PubKey {
@ -32,7 +32,7 @@ export function decodeBech32Pubkey(bechEncoded: string): PubKey {
}
return {
type: pubkeyType.secp256k1,
value: Encoding.toBase64(rest),
value: toBase64(rest),
};
} else if (equal(aminoPrefix, pubkeyAminoPrefixEd25519)) {
if (rest.length !== 32) {
@ -40,7 +40,7 @@ export function decodeBech32Pubkey(bechEncoded: string): PubKey {
}
return {
type: pubkeyType.ed25519,
value: Encoding.toBase64(rest),
value: toBase64(rest),
};
} else if (equal(aminoPrefix, pubkeyAminoPrefixSr25519)) {
if (rest.length !== 32) {
@ -48,10 +48,10 @@ export function decodeBech32Pubkey(bechEncoded: string): PubKey {
}
return {
type: pubkeyType.sr25519,
value: Encoding.toBase64(rest),
value: toBase64(rest),
};
} else {
throw new Error("Unsupported Pubkey type. Amino prefix: " + Encoding.toHex(aminoPrefix));
throw new Error("Unsupported Pubkey type. Amino prefix: " + toHex(aminoPrefix));
}
}
@ -66,6 +66,6 @@ export function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string {
throw new Error("Unsupported pubkey type");
}
const data = new Uint8Array([...aminoPrefix, ...Encoding.fromBase64(pubkey.value)]);
const data = new Uint8Array([...aminoPrefix, ...fromBase64(pubkey.value)]);
return Bech32.encode(prefix, data);
}

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Encoding } from "@iov/encoding";
import { fromBase64 } from "@iov/encoding";
import { assert, sleep } from "@iov/utils";
import { ReadonlyDate } from "readonly-date";
@ -27,8 +27,6 @@ import {
} from "./testutils.spec";
import { Msg, MsgSend, StdFee, StdSignature, StdTx } from "./types";
const { fromBase64 } = Encoding;
const emptyAddress = "cosmos1ltkhnmdcqemmd2tkhnx7qx66tq7e0wykw2j85k";
function makeSignedTx(firstMsg: Msg, fee: StdFee, memo: string, firstSignature: StdSignature): StdTx {

View File

@ -1,4 +1,4 @@
import { Encoding, isNonNullObject } from "@iov/encoding";
import { fromBase64, isNonNullObject } from "@iov/encoding";
import axios, { AxiosError, AxiosInstance } from "axios";
import { Coin } from "./coins";
@ -301,7 +301,7 @@ export class RestClient {
if (!responseData.tx) {
throw new Error("Unexpected response data format");
}
return Encoding.fromBase64((responseData as EncodeTxResponse).tx);
return fromBase64((responseData as EncodeTxResponse).tx);
}
/**

View File

@ -1,10 +1,8 @@
import { Encoding } from "@iov/encoding";
import { fromBase64 } from "@iov/encoding";
import { decodeSignature, encodeSecp256k1Signature } from "./signature";
import { StdSignature } from "./types";
const { fromBase64 } = Encoding;
describe("signature", () => {
describe("encodeSecp256k1Signature", () => {
it("encodes a full signature", () => {

View File

@ -1,4 +1,4 @@
import { Encoding } from "@iov/encoding";
import { fromBase64, toBase64 } from "@iov/encoding";
import { encodeSecp256k1Pubkey } from "./pubkey";
import { pubkeyType, StdSignature } from "./types";
@ -19,7 +19,7 @@ export function encodeSecp256k1Signature(pubkey: Uint8Array, signature: Uint8Arr
return {
// eslint-disable-next-line @typescript-eslint/camelcase
pub_key: encodeSecp256k1Pubkey(pubkey),
signature: Encoding.toBase64(signature),
signature: toBase64(signature),
};
}
@ -30,8 +30,8 @@ export function decodeSignature(
// Note: please don't add cases here without writing additional unit tests
case pubkeyType.secp256k1:
return {
pubkey: Encoding.fromBase64(signature.pub_key.value),
signature: Encoding.fromBase64(signature.signature),
pubkey: fromBase64(signature.pub_key.value),
signature: fromBase64(signature.signature),
};
default:
throw new Error("Unsupported pubkey type");

View File

@ -92,23 +92,23 @@
unique-filename "^1.1.1"
which "^1.3.1"
"@iov/bcp@^2.1.0", "@iov/bcp@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/bcp/-/bcp-2.2.0.tgz#4db3502115c5bb1bb34f471c0d129734ee449da5"
integrity sha512-jeFvT9oYiYAKhO2p70G3tpcWKkZIGkVq7daI367RzTIPJC29CCGajde2OdBN6O0OMSMctW0hksC7bVz+Pfv/tg==
"@iov/bcp@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/bcp/-/bcp-2.3.2.tgz#23dc92839951beb239ec6ed56490d7534d67451c"
integrity sha512-o9ae5Q8jHgGyxsUnyoRcL200YVbDEYXAb6ZaAFad5/aFjhVawjTDSgya+vL8zI+t8BBixJZcXOjeDaqLtWRQAw==
dependencies:
"@iov/crypto" "^2.2.0"
"@iov/encoding" "^2.2.0"
"@iov/stream" "^2.2.0"
"@iov/crypto" "^2.3.2"
"@iov/encoding" "^2.3.2"
"@iov/stream" "^2.3.2"
type-tagger "^1.0.0"
xstream "^11.10.0"
"@iov/crypto@^2.1.0", "@iov/crypto@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/crypto/-/crypto-2.2.0.tgz#9413436fa6ddf8fadddb1c208dd1304dc654287c"
integrity sha512-E/DJ0Y4z1ZXCWlXlx2J9SZ/oollaBQu1u5kT53ypRZcAe3X9UTJFGusi/SuZ/fuyvIKwlsa9mUqvJQt2tl2RxQ==
"@iov/crypto@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/crypto/-/crypto-2.3.2.tgz#0f65623d29d1df7e35620bbbeede70f1d0797ff9"
integrity sha512-inHHZa9kr+4K88ZhqOQC/LVlZBcZlE0Kkj97ynWGzaR4CCdCFa0KOkx2vef2CH0J6wbfC13e6b93/MuQyGiUAw==
dependencies:
"@iov/encoding" "^2.2.0"
"@iov/encoding" "^2.3.2"
bip39 "^3.0.2"
bn.js "^4.11.8"
elliptic "^6.4.0"
@ -120,25 +120,25 @@
type-tagger "^1.0.0"
unorm "^1.5.0"
"@iov/encoding@^2.1.0", "@iov/encoding@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/encoding/-/encoding-2.2.0.tgz#584454c12b7fa754b714912cb9595a85303bfa75"
integrity sha512-C61ysbRja92CC37gD66ndy+fpbXswlQWgiEftAqHG6QuFs4Zng1/3zwL5Mb4DhzlH2z21+YPwRtfWM5rk1kDmQ==
"@iov/encoding@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/encoding/-/encoding-2.3.2.tgz#4b37966af0345a6bc904bb58189dc1ea9d14ad9b"
integrity sha512-viioqo1flTkG4Oxb0PvoBXGozHq9fObAgAL4dRHJe9zmChE77EBX2Y5u0nabd2JwAhEbir56AtsrUe4dOrtd5w==
dependencies:
base64-js "^1.3.0"
bech32 "^1.1.3"
bech32 "^1.1.4"
bn.js "^4.11.8"
readonly-date "^1.0.0"
"@iov/keycontrol@^2.1.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/keycontrol/-/keycontrol-2.2.0.tgz#1f250b444580dc494a5d5f11625094eeeda09938"
integrity sha512-XoiezMe6hyKT+qJpam5QO51x3e4WY5bl7pTYua9GfwpJnU0ClkGLO1g0YkGKB5q0f2ymk2s0MEgTxKQx9RLkyA==
"@iov/keycontrol@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/keycontrol/-/keycontrol-2.3.2.tgz#42b556476c489e45b01ec47ec9ed28f287f5199e"
integrity sha512-Ile1c+ceAwefulNZ2pYu1TFeoFcx4S2oJTS57sFDNJzDDjn5xvEgNpdn4xkDDdGvkQOnexiMNifeCjInHBJpjQ==
dependencies:
"@iov/bcp" "^2.2.0"
"@iov/crypto" "^2.2.0"
"@iov/encoding" "^2.2.0"
"@iov/stream" "^2.2.0"
"@iov/bcp" "^2.3.2"
"@iov/crypto" "^2.3.2"
"@iov/encoding" "^2.3.2"
"@iov/stream" "^2.3.2"
"@types/abstract-leveldown" "^5.0.1"
"@types/levelup" "^3.1.0"
"@types/node" "^10.12.18"
@ -150,17 +150,17 @@
type-tagger "^1.0.0"
xstream "^11.10.0"
"@iov/stream@^2.0.2", "@iov/stream@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/stream/-/stream-2.2.0.tgz#a26eaaff391a7304d481867843d8afe81321db27"
integrity sha512-idtQoaNsGCS5KHO6Ymq9w2P6bq2yIaQfdAjjXuzQPX79lmuS1w2Pq6XGBnhMeQ7LVbluvy9JFIgZVcEQ7iSHvA==
"@iov/stream@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/stream/-/stream-2.3.2.tgz#472063f3a4fcd1e97de0ae99189f98b94825afac"
integrity sha512-nOq5OKwK2rWnyzXpGTAKZToCU0jmTjEC05owVzmBfw3+7hmjlExrGGbLncjcMWzbvp2VVpHc2l01Tr+qpzr8Vw==
dependencies:
xstream "^11.10.0"
"@iov/utils@^2.0.2":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@iov/utils/-/utils-2.2.0.tgz#46e234db283b5553f7c1ce24307a708b9710b0bc"
integrity sha512-dy3iWphow125x1cChOBye0knmm9ddnmkv5/aOmu8w/KL5H3Y7WkJ8VY/Gz3ePdBIjPXU8sEihnmanVGiz0WsPw==
"@iov/utils@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@iov/utils/-/utils-2.3.2.tgz#a499ec304b4febaeb3af309dedbb30e14a09c91e"
integrity sha512-mtdZ8zh/LGjwA72HofOc8JF3KN1Rc1jwaQATePLDwIIJRw0AJXx2GLRBBRjja41huuw9ND0E2mQWlYLtYsNnUA==
"@koa/cors@^3.0.0":
version "3.0.0"
@ -1811,10 +1811,10 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"
bech32@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.3.tgz#bd47a8986bbb3eec34a56a097a84b8d3e9a2dfcd"
integrity sha512-yuVFUvrNcoJi0sv5phmqc6P+Fl1HjRDRNOOkHY2X/3LBy2bIGNSFx4fZ95HMaXHupuS7cZR15AsvtmCIF4UEyg==
bech32@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==
before-after-hook@^2.0.0:
version "2.1.0"