diff --git a/packages/cosmic-proto/package.json b/packages/cosmic-proto/package.json index 4b53e9ecf5c..1a492ea4bef 100644 --- a/packages/cosmic-proto/package.json +++ b/packages/cosmic-proto/package.json @@ -142,11 +142,6 @@ "typescript": "^5.5.3" }, "dependencies": { - "@cosmjs/amino": "^0.32.3", - "@cosmjs/math": "^0.32.3", - "@cosmjs/proto-signing": "^0.32.3", - "@cosmjs/stargate": "^0.32.3", - "@cosmjs/tendermint-rpc": "^0.32.3", "@endo/base64": "^1.0.5", "@endo/init": "^1.1.2" }, diff --git a/packages/cosmic-proto/src/codegen/agoric/vbank/vbank.ts b/packages/cosmic-proto/src/codegen/agoric/vbank/vbank.ts index b2bf790e850..02a9974b2fe 100644 --- a/packages/cosmic-proto/src/codegen/agoric/vbank/vbank.ts +++ b/packages/cosmic-proto/src/codegen/agoric/vbank/vbank.ts @@ -1,8 +1,7 @@ //@ts-nocheck import { Coin, CoinSDKType } from '../../cosmos/base/v1beta1/coin.js'; import { BinaryReader, BinaryWriter } from '../../binary.js'; -import { Decimal } from '@cosmjs/math'; -import { isSet } from '../../helpers.js'; +import { Decimal, isSet } from '../../helpers.js'; import { JsonSafe } from '../../json-safe.js'; /** The module governance/configuration parameters. */ export interface Params { diff --git a/packages/cosmic-proto/src/codegen/cosmos/distribution/v1beta1/distribution.ts b/packages/cosmic-proto/src/codegen/cosmos/distribution/v1beta1/distribution.ts index b0268266fc0..0cdb2e30600 100644 --- a/packages/cosmic-proto/src/codegen/cosmos/distribution/v1beta1/distribution.ts +++ b/packages/cosmic-proto/src/codegen/cosmos/distribution/v1beta1/distribution.ts @@ -6,8 +6,7 @@ import { CoinSDKType, } from '../../base/v1beta1/coin.js'; import { BinaryReader, BinaryWriter } from '../../../binary.js'; -import { Decimal } from '@cosmjs/math'; -import { isSet } from '../../../helpers.js'; +import { Decimal, isSet } from '../../../helpers.js'; import { JsonSafe } from '../../../json-safe.js'; /** Params defines the set of params for the distribution module. */ export interface Params { diff --git a/packages/cosmic-proto/src/codegen/cosmos/gov/v1beta1/gov.ts b/packages/cosmic-proto/src/codegen/cosmos/gov/v1beta1/gov.ts index 909f8655f73..df1724b2b9e 100644 --- a/packages/cosmic-proto/src/codegen/cosmos/gov/v1beta1/gov.ts +++ b/packages/cosmic-proto/src/codegen/cosmos/gov/v1beta1/gov.ts @@ -10,8 +10,8 @@ import { DurationSDKType, } from '../../../google/protobuf/duration.js'; import { BinaryReader, BinaryWriter } from '../../../binary.js'; -import { Decimal } from '@cosmjs/math'; import { + Decimal, isSet, fromJsonTimestamp, fromTimestamp, diff --git a/packages/cosmic-proto/src/codegen/cosmos/mint/v1beta1/mint.ts b/packages/cosmic-proto/src/codegen/cosmos/mint/v1beta1/mint.ts index ec5a9b88b3b..07d44395a85 100644 --- a/packages/cosmic-proto/src/codegen/cosmos/mint/v1beta1/mint.ts +++ b/packages/cosmic-proto/src/codegen/cosmos/mint/v1beta1/mint.ts @@ -1,7 +1,6 @@ //@ts-nocheck import { BinaryReader, BinaryWriter } from '../../../binary.js'; -import { Decimal } from '@cosmjs/math'; -import { isSet } from '../../../helpers.js'; +import { Decimal, isSet } from '../../../helpers.js'; import { JsonSafe } from '../../../json-safe.js'; /** Minter represents the minting state. */ export interface Minter { diff --git a/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/staking.ts b/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/staking.ts index 29b21256cfc..dcd62f7c5dd 100644 --- a/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/staking.ts +++ b/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/staking.ts @@ -11,9 +11,13 @@ import { } from '../../../google/protobuf/duration.js'; import { Coin, CoinSDKType } from '../../base/v1beta1/coin.js'; import { BinaryReader, BinaryWriter } from '../../../binary.js'; -import { isSet, fromJsonTimestamp, fromTimestamp } from '../../../helpers.js'; +import { + isSet, + Decimal, + fromJsonTimestamp, + fromTimestamp, +} from '../../../helpers.js'; import { JsonSafe } from '../../../json-safe.js'; -import { Decimal } from '@cosmjs/math'; /** BondStatus is the status of a validator. */ export enum BondStatus { /** BOND_STATUS_UNSPECIFIED - UNSPECIFIED defines an invalid validator status. */ diff --git a/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/tx.ts b/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/tx.ts index f10885e3aa6..870b1624bbe 100644 --- a/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/tx.ts +++ b/packages/cosmic-proto/src/codegen/cosmos/staking/v1beta1/tx.ts @@ -12,9 +12,13 @@ import { TimestampSDKType, } from '../../../google/protobuf/timestamp.js'; import { BinaryReader, BinaryWriter } from '../../../binary.js'; -import { isSet, fromJsonTimestamp, fromTimestamp } from '../../../helpers.js'; +import { + isSet, + Decimal, + fromJsonTimestamp, + fromTimestamp, +} from '../../../helpers.js'; import { JsonSafe } from '../../../json-safe.js'; -import { Decimal } from '@cosmjs/math'; /** MsgCreateValidator defines a SDK message for creating a new validator. */ export interface MsgCreateValidator { description: Description; diff --git a/packages/cosmic-proto/src/codegen/helpers.ts b/packages/cosmic-proto/src/codegen/helpers.ts index 56f5f4f5dde..ebdafe89353 100644 --- a/packages/cosmic-proto/src/codegen/helpers.ts +++ b/packages/cosmic-proto/src/codegen/helpers.ts @@ -222,3 +222,84 @@ export function fromJsonTimestamp(o: any): Timestamp { function numberToLong(number: number) { return BigInt(Math.trunc(number)); } + +// The largest value we need is 18 (Ether). +const maxFractionalDigits = 30; +// Subset of Decimal in @cosmjs/math +/** + * A type for arbitrary precision, non-negative decimals. + * + * Instances of this class are immutable. + */ +export class Decimal { + public static fromUserInput( + input: string, + fractionalDigits: number, + ): Decimal { + Decimal.verifyFractionalDigits(fractionalDigits); + + const badCharacter = input.match(/[^0-9.]/); + if (badCharacter) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + throw new Error( + `Invalid character at position ${badCharacter.index! + 1}`, + ); + } + + let whole: string; + let fractional: string; + + if (input === '') { + whole = '0'; + fractional = ''; + } else if (input.search(/./) === -1) { + // integer format, no separator + whole = input; + fractional = ''; + } else { + const parts = input.split('.'); + switch (parts.length) { + case 0: + case 1: + throw new Error( + 'Fewer than two elements in split result. This must not happen here.', + ); + case 2: + if (!parts[1]) throw new Error('Fractional part missing'); + whole = parts[0]; + fractional = parts[1].replace(/0+$/, ''); + break; + default: + throw new Error('More than one separator found'); + } + } + + if (fractional.length > fractionalDigits) { + throw new Error('Got more fractional digits than supported'); + } + + const quantity = `${whole}${fractional.padEnd(fractionalDigits, '0')}`; + + return new Decimal(quantity, fractionalDigits); + } + + public static fromAtomics( + atomics: string, + fractionalDigits: number, + ): Decimal { + Decimal.verifyFractionalDigits(fractionalDigits); + return new Decimal(atomics, fractionalDigits); + } + + private static verifyFractionalDigits(fractionalDigits: number): void { + if (!Number.isInteger(fractionalDigits)) + throw new Error('Fractional digits is not an integer'); + if (fractionalDigits < 0) + throw new Error('Fractional digits must not be negative'); + if (fractionalDigits > maxFractionalDigits) { + throw new Error( + `Fractional digits must not exceed ${maxFractionalDigits}`, + ); + } + } +} diff --git a/packages/cosmic-proto/test/bundle-cosmjs-math.js b/packages/cosmic-proto/test/bundle-cosmjs-math.js deleted file mode 100644 index 7b09232d149..00000000000 --- a/packages/cosmic-proto/test/bundle-cosmjs-math.js +++ /dev/null @@ -1 +0,0 @@ -export { Decimal } from '@cosmjs/math'; diff --git a/packages/cosmic-proto/test/bundle-cosmjs-math.test.js b/packages/cosmic-proto/test/bundle-cosmjs-math.test.js deleted file mode 100644 index c8a8d386ab5..00000000000 --- a/packages/cosmic-proto/test/bundle-cosmjs-math.test.js +++ /dev/null @@ -1,18 +0,0 @@ -// A test to verify that importing @cosmsjs/math into an ESM via bundleSource -// can see the exported Decimal constructor, which was at time of writing obscured -// by https://github.com/endojs/endo/pull/2330, temporarily mitigated by a patch. -// Placed here only because Agoric CLI depends on both bundleSource and CosmJS math. - -import test from '@endo/ses-ava/prepare-endo.js'; -import url from 'url'; -import bundleSource from '@endo/bundle-source'; -import { importBundle } from '@endo/import-bundle'; - -test('bundled @comjs/math exports Decimal', async t => { - const entryPath = url.fileURLToPath( - new URL('bundle-cosmjs-math.js', import.meta.url), - ); - const bundle = await bundleSource(entryPath); - const ns = await importBundle(bundle); - t.not(ns.Decimal, undefined); -}); diff --git a/patches/@cosmjs+math+0.32.3.patch b/patches/@cosmjs+math+0.32.3.patch deleted file mode 100644 index 17593d0b9b4..00000000000 --- a/patches/@cosmjs+math+0.32.3.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff --git a/node_modules/@cosmjs/math/build/index.js b/node_modules/@cosmjs/math/build/index.js -index 1f812f6..6e25ac9 100644 ---- a/node_modules/@cosmjs/math/build/index.js -+++ b/node_modules/@cosmjs/math/build/index.js -@@ -1,11 +1,10 @@ --"use strict"; --Object.defineProperty(exports, "__esModule", { value: true }); --exports.Uint64 = exports.Uint53 = exports.Uint32 = exports.Int53 = exports.Decimal = void 0; --var decimal_1 = require("./decimal"); --Object.defineProperty(exports, "Decimal", { enumerable: true, get: function () { return decimal_1.Decimal; } }); --var integers_1 = require("./integers"); --Object.defineProperty(exports, "Int53", { enumerable: true, get: function () { return integers_1.Int53; } }); --Object.defineProperty(exports, "Uint32", { enumerable: true, get: function () { return integers_1.Uint32; } }); --Object.defineProperty(exports, "Uint53", { enumerable: true, get: function () { return integers_1.Uint53; } }); --Object.defineProperty(exports, "Uint64", { enumerable: true, get: function () { return integers_1.Uint64; } }); -+'use strict'; -+Object.defineProperty(exports, '__esModule', { value: true }); -+var decimal_1 = require('./decimal'); -+var integers_1 = require('./integers'); -+exports.Uint64 = integers_1.Uint64; -+exports.Uint53 = integers_1.Uint53; -+exports.Uint32 = integers_1.Uint32; -+exports.Int53 = integers_1.Int53; -+exports.Decimal = decimal_1.Decimal; - //# sourceMappingURL=index.js.map diff --git a/patches/@cosmology+telescope+1.7.1.patch b/patches/@cosmology+telescope+1.7.1.patch index 178d74802bd..dcc4a034512 100644 --- a/patches/@cosmology+telescope+1.7.1.patch +++ b/patches/@cosmology+telescope+1.7.1.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js b/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js -index 950827a..b51746c 100644 +index 950827a..9e9214c 100644 --- a/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js +++ b/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js @@ -5,41 +5,11 @@ const getHelperForBigint = (options) => { @@ -29,12 +29,12 @@ index 950827a..b51746c 100644 - } - return arr; -} -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - +- -const btoa: (bin: string) => string = - globalThis.btoa || - ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- ++import { encodeBase64, decodeBase64 } from '@endo/base64'; + -export function base64FromBytes(arr: Uint8Array): string { - const bin: string[] = []; - arr.forEach((byte) => { @@ -48,8 +48,97 @@ index 950827a..b51746c 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -252,6 +222,88 @@ export function fromJsonTimestamp(o: any): Timestamp { + function numberToLong(number: number) { + return BigInt(Math.trunc(number)); + } ++ ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ + ${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? + ` + export function padDecimal(decStr: string): string{ diff --git a/node_modules/@cosmology/telescope/main/helpers/internal.js b/node_modules/@cosmology/telescope/main/helpers/internal.js -index b27664f..3ae9cd9 100644 +index b27664f..5cf4c6a 100644 --- a/node_modules/@cosmology/telescope/main/helpers/internal.js +++ b/node_modules/@cosmology/telescope/main/helpers/internal.js @@ -5,6 +5,8 @@ const getHelper = (options) => { @@ -104,6 +193,99 @@ index b27664f..3ae9cd9 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -236,7 +208,91 @@ export function fromJsonTimestamp(o: any): Timestamp { + + function numberToLong(number: number) { + return Long.fromNumber(number); +-}${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` ++} ++ ++ ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ ++${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` + + export function padDecimal(decStr: string): string{ + return decStr ? new Dec(decStr).toString() : decStr; diff --git a/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js b/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js index 07b6e47..87c78db 100644 --- a/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js @@ -154,8 +336,21 @@ index 07b6e47..87c78db 100644 export interface AminoHeight { readonly revision_number?: string; +diff --git a/node_modules/@cosmology/telescope/main/utils/index.js b/node_modules/@cosmology/telescope/main/utils/index.js +index 998db7f..3301179 100644 +--- a/node_modules/@cosmology/telescope/main/utils/index.js ++++ b/node_modules/@cosmology/telescope/main/utils/index.js +@@ -36,7 +36,7 @@ exports.UTILS = { + bytesFromBase64: '__helpers__', + BrowserHeaders: 'browser-headers', + connectComet: '@cosmjs/tendermint-rpc', +- Decimal: '@cosmjs/math', ++ Decimal: '__helpers__', + padDecimal: '__helpers__', + createProtobufRpcClient: '@cosmjs/stargate', + Pubkey: '@cosmjs/amino', diff --git a/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js b/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js -index 1d19b1c..1c182dc 100644 +index 1d19b1c..5a9ec29 100644 --- a/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js +++ b/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js @@ -2,41 +2,11 @@ export const getHelperForBigint = (options) => { @@ -204,8 +399,104 @@ index 1d19b1c..1c182dc 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -249,11 +219,95 @@ export function fromJsonTimestamp(o: any): Timestamp { + function numberToLong(number: number) { + return BigInt(Math.trunc(number)); + } ++ ++ ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ + ${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? + ` + export function padDecimal(decStr: string): string{ + return decStr ? new Dec(decStr).toString() : decStr; + } ++ + ` : ""} + `; + }; diff --git a/node_modules/@cosmology/telescope/module/helpers/internal.js b/node_modules/@cosmology/telescope/module/helpers/internal.js -index 28e50cf..bc0843a 100644 +index 28e50cf..c713941 100644 --- a/node_modules/@cosmology/telescope/module/helpers/internal.js +++ b/node_modules/@cosmology/telescope/module/helpers/internal.js @@ -2,6 +2,7 @@ export const getHelper = (options) => { @@ -259,6 +550,102 @@ index 28e50cf..bc0843a 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -231,6 +202,87 @@ export function fromJsonTimestamp(o: any): Timestamp { + } + } + ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ + function numberToLong(number: number) { + return Long.fromNumber(number); + }${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` +@@ -238,6 +290,7 @@ function numberToLong(number: number) { + export function padDecimal(decStr: string): string{ + return decStr ? new Dec(decStr).toString() : decStr; + } ++ + ` : ""} + `; + }; diff --git a/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js b/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js index ecb2e3e..4e96aff 100644 --- a/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js @@ -307,8 +694,21 @@ index ecb2e3e..4e96aff 100644 export interface AminoHeight { readonly revision_number?: string; +diff --git a/node_modules/@cosmology/telescope/module/utils/index.js b/node_modules/@cosmology/telescope/module/utils/index.js +index aa561fd..21c4e00 100644 +--- a/node_modules/@cosmology/telescope/module/utils/index.js ++++ b/node_modules/@cosmology/telescope/module/utils/index.js +@@ -18,7 +18,7 @@ export const UTILS = { + bytesFromBase64: '__helpers__', + BrowserHeaders: 'browser-headers', + connectComet: '@cosmjs/tendermint-rpc', +- Decimal: '@cosmjs/math', ++ Decimal: '__helpers__', + padDecimal: '__helpers__', + createProtobufRpcClient: '@cosmjs/stargate', + Pubkey: '@cosmjs/amino', diff --git a/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts b/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts -index f7daa3d..1680276 100644 +index f7daa3d..555ffda 100644 --- a/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts +++ b/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts @@ -4,41 +4,11 @@ export const getHelperForBigint = (options: TelescopeOptions) => { @@ -338,12 +738,12 @@ index f7daa3d..1680276 100644 - } - return arr; -} -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - +- -const btoa: (bin: string) => string = - globalThis.btoa || - ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- ++import { encodeBase64, decodeBase64 } from '@endo/base64'; + -export function base64FromBytes(arr: Uint8Array): string { - const bin: string[] = []; - arr.forEach((byte) => { @@ -357,8 +757,97 @@ index f7daa3d..1680276 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -251,6 +221,88 @@ export function fromJsonTimestamp(o: any): Timestamp { + function numberToLong(number: number) { + return BigInt(Math.trunc(number)); + } ++ ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ + ${ + options.aminoEncoding?.customTypes?.useCosmosSDKDec ? + ` diff --git a/node_modules/@cosmology/telescope/src/helpers/internal.ts b/node_modules/@cosmology/telescope/src/helpers/internal.ts -index fc58715..c21df0a 100644 +index fc58715..98a1582 100644 --- a/node_modules/@cosmology/telescope/src/helpers/internal.ts +++ b/node_modules/@cosmology/telescope/src/helpers/internal.ts @@ -4,6 +4,8 @@ export const getHelper = (options: TelescopeOptions) => { @@ -413,3 +902,104 @@ index fc58715..c21df0a 100644 export interface AminoHeight { readonly revision_number?: string; +@@ -233,6 +205,87 @@ export function fromJsonTimestamp(o: any): Timestamp { + } + } + ++// The largest value we need is 18 (Ether). ++const maxFractionalDigits = 30; ++// Subset of Decimal in @cosmjs/math ++/** ++ * A type for arbitrary precision, non-negative decimals. ++ * ++ * Instances of this class are immutable. ++ */ ++export class Decimal { ++ public static fromUserInput( ++ input: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ ++ const badCharacter = input.match(/[^0-9.]/); ++ if (badCharacter) { ++ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ++ throw new Error( ++ \`Invalid character at position \${badCharacter.index! + 1}\`, ++ ); ++ } ++ ++ let whole: string; ++ let fractional: string; ++ ++ if (input === '') { ++ whole = '0'; ++ fractional = ''; ++ } else if (input.search(/\./) === -1) { ++ // integer format, no separator ++ whole = input; ++ fractional = ''; ++ } else { ++ const parts = input.split('.'); ++ switch (parts.length) { ++ case 0: ++ case 1: ++ throw new Error( ++ 'Fewer than two elements in split result. This must not happen here.', ++ ); ++ case 2: ++ if (!parts[1]) throw new Error('Fractional part missing'); ++ whole = parts[0]; ++ fractional = parts[1].replace(/0+$/, ''); ++ break; ++ default: ++ throw new Error('More than one separator found'); ++ } ++ } ++ ++ if (fractional.length > fractionalDigits) { ++ throw new Error('Got more fractional digits than supported'); ++ } ++ ++ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; ++ ++ return new Decimal(quantity, fractionalDigits); ++ } ++ ++ public static fromAtomics( ++ atomics: string, ++ fractionalDigits: number, ++ ): Decimal { ++ Decimal.verifyFractionalDigits(fractionalDigits); ++ return new Decimal(atomics, fractionalDigits); ++ } ++ ++ private static verifyFractionalDigits(fractionalDigits: number): void { ++ if (!Number.isInteger(fractionalDigits)) ++ throw new Error('Fractional digits is not an integer'); ++ if (fractionalDigits < 0) ++ throw new Error('Fractional digits must not be negative'); ++ if (fractionalDigits > maxFractionalDigits) { ++ throw new Error( ++ \`Fractional digits must not exceed \${maxFractionalDigits}\`, ++ ); ++ } ++ } ++} ++ + function numberToLong(number: number) { + return Long.fromNumber(number); + }${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` +diff --git a/node_modules/@cosmology/telescope/src/utils/index.ts b/node_modules/@cosmology/telescope/src/utils/index.ts +index 1ed202f..6d2cc38 100644 +--- a/node_modules/@cosmology/telescope/src/utils/index.ts ++++ b/node_modules/@cosmology/telescope/src/utils/index.ts +@@ -21,7 +21,7 @@ export const UTILS = { + bytesFromBase64: '__helpers__', + BrowserHeaders: 'browser-headers', + connectComet: '@cosmjs/tendermint-rpc', +- Decimal: '@cosmjs/math', ++ Decimal: '__helpers__', + padDecimal: '__helpers__', + createProtobufRpcClient: '@cosmjs/stargate', + Pubkey: '@cosmjs/amino', diff --git a/patches/bn.js+5.2.0.patch b/patches/bn.js+5.2.0.patch deleted file mode 100644 index c7d2b14588f..00000000000 --- a/patches/bn.js+5.2.0.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/node_modules/bn.js/lib/bn.js b/node_modules/bn.js/lib/bn.js -index c9773da..0045880 100644 ---- a/node_modules/bn.js/lib/bn.js -+++ b/node_modules/bn.js/lib/bn.js -@@ -2632,7 +2632,7 @@ - for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { - x.iushrn(i); -- while (i-- > 0) { -+ while ([i--][0] > 0) { - if (A.isOdd() || B.isOdd()) { - A.iadd(yp); - B.isub(xp); -@@ -2646,7 +2646,7 @@ - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { - y.iushrn(j); -- while (j-- > 0) { -+ while ([j--][0] > 0) { - if (C.isOdd() || D.isOdd()) { - C.iadd(yp); - D.isub(xp); -@@ -2700,7 +2700,7 @@ - for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { - a.iushrn(i); -- while (i-- > 0) { -+ while ([i--][0] > 0) { - if (x1.isOdd()) { - x1.iadd(delta); - } -@@ -2712,7 +2712,7 @@ - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { - b.iushrn(j); -- while (j-- > 0) { -+ while ([j--][0] > 0) { - if (x2.isOdd()) { - x2.iadd(delta); - } diff --git a/patches/cosmjs-types+0.9.0.patch b/patches/cosmjs-types+0.9.0.patch deleted file mode 100644 index 5cbb9657dd6..00000000000 --- a/patches/cosmjs-types+0.9.0.patch +++ /dev/null @@ -1,34 +0,0 @@ -diff --git a/node_modules/cosmjs-types/helpers.js b/node_modules/cosmjs-types/helpers.js -index 3bd449c..8a436bf 100644 ---- a/node_modules/cosmjs-types/helpers.js -+++ b/node_modules/cosmjs-types/helpers.js -@@ -7,7 +7,7 @@ - */ - Object.defineProperty(exports, "__esModule", { value: true }); - exports.fromJsonTimestamp = exports.fromTimestamp = exports.toTimestamp = exports.setPaginationParams = exports.isObject = exports.isSet = exports.fromDuration = exports.toDuration = exports.omitDefault = exports.base64FromBytes = exports.bytesFromBase64 = void 0; --var globalThis = (() => { -+var localGlobal = (() => { - if (typeof globalThis !== "undefined") - return globalThis; - if (typeof self !== "undefined") -@@ -16,9 +16,9 @@ var globalThis = (() => { - return window; - if (typeof global !== "undefined") - return global; -- throw "Unable to locate global object"; -+ throw "Unable to locate global object in cosmjs-types"; - })(); --const atob = globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); -+const atob = localGlobal.atob || ((b64) => localGlobal.Buffer.from(b64, "base64").toString("binary")); - function bytesFromBase64(b64) { - const bin = atob(b64); - const arr = new Uint8Array(bin.length); -@@ -28,7 +28,7 @@ function bytesFromBase64(b64) { - return arr; - } - exports.bytesFromBase64 = bytesFromBase64; --const btoa = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); -+const btoa = localGlobal.btoa || ((bin) => localGlobal.Buffer.from(bin, "binary").toString("base64")); - function base64FromBytes(arr) { - const bin = []; - arr.forEach((byte) => {