Skip to content

Commit

Permalink
chore(deps): cut ambient global from telescope
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 21, 2025
1 parent 05db9f7 commit 40df929
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 35 deletions.
37 changes: 2 additions & 35 deletions packages/cosmic-proto/src/codegen/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,8 @@
* and run the transpile command or npm scripts command that is used to regenerate this bundle.
*/

declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var globalThis: any = (() => {
if (typeof globalThis !== 'undefined') return globalThis;
if (typeof self !== 'undefined') return self;
if (typeof window !== 'undefined') return window;
if (typeof global !== 'undefined') return global;
throw 'Unable to locate global object';
})();

const atob: (b64: string) => string =
globalThis.atob ||
(b64 => globalThis.Buffer.from(b64, 'base64').toString('binary'));

export function bytesFromBase64(b64: string): Uint8Array {
const bin = atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
}
return arr;
}

const btoa: (bin: string) => string =
globalThis.btoa ||
(bin => globalThis.Buffer.from(bin, 'binary').toString('base64'));

export function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
arr.forEach(byte => {
bin.push(String.fromCharCode(byte));
});
return btoa(bin.join(''));
}
// PATCH: Use base64Lib: 'endo' instead for bytesFromBase64 and base64FromBytes
// TODO update Telescope to put these helpers in a separate module so 'helpers' doesn't entail ambient authority

export interface AminoHeight {
readonly revision_number?: string;
Expand Down
221 changes: 221 additions & 0 deletions patches/@cosmology+telescope+1.11.9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
diff --git a/node_modules/@cosmology/telescope/main/helpers/internal.js b/node_modules/@cosmology/telescope/main/helpers/internal.js
index b27664f..3d1910c 100644
--- a/node_modules/@cosmology/telescope/main/helpers/internal.js
+++ b/node_modules/@cosmology/telescope/main/helpers/internal.js
@@ -16,39 +16,8 @@ if (_m0.util.Long !== Long) {

export { Long };

-declare var self: any | undefined;
-declare var window: any | undefined;
-declare var global: any | undefined;
-var globalThis: any = (() => {
- if (typeof globalThis !== 'undefined') return globalThis;
- if (typeof self !== 'undefined') return self;
- if (typeof window !== 'undefined') return window;
- if (typeof global !== 'undefined') return global;
- throw 'Unable to locate global object';
-})();
-
-const atob: (b64: string) => string =
- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
-
-export function bytesFromBase64(b64: string): Uint8Array {
- const bin = atob(b64);
- const arr = new Uint8Array(bin.length);
- for (let i = 0; i < bin.length; ++i) {
- arr[i] = bin.charCodeAt(i);
- }
- return arr;
-}
-
-const btoa: (bin: string) => string =
- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
-
-export function base64FromBytes(arr: Uint8Array): string {
- const bin: string[] = [];
- arr.forEach((byte) => {
- bin.push(String.fromCharCode(byte));
- });
- return btoa(bin.join(''));
-}
+// PATCH: Use base64Lib: 'endo' instead for bytesFromBase64 and base64FromBytes
+// TODO update Telescope to put these helpers in a separate module so 'helpers' doesn't entail ambient authority

export interface AminoHeight {
readonly revision_number?: string;
diff --git a/node_modules/@cosmology/telescope/module/helpers/internal.js b/node_modules/@cosmology/telescope/module/helpers/internal.js
index 28e50cf..abefe90 100644
--- a/node_modules/@cosmology/telescope/module/helpers/internal.js
+++ b/node_modules/@cosmology/telescope/module/helpers/internal.js
@@ -1,8 +1,12 @@
-export const getHelper = (options) => {
- return `import * as _m0 from "protobufjs/minimal";
-import Long from 'long';${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `
+export const getHelper = options => {
+ return `import * as _m0 from "protobufjs/minimal";
+import Long from 'long';${
+ options.aminoEncoding?.customTypes?.useCosmosSDKDec
+ ? `
import { Dec } from "@keplr-wallet/unit";
-` : ""}
+`
+ : ''
+ }

// @ts-ignore
if (_m0.util.Long !== Long) {
@@ -13,39 +17,8 @@ if (_m0.util.Long !== Long) {

export { Long };

-declare var self: any | undefined;
-declare var window: any | undefined;
-declare var global: any | undefined;
-var globalThis: any = (() => {
- if (typeof globalThis !== 'undefined') return globalThis;
- if (typeof self !== 'undefined') return self;
- if (typeof window !== 'undefined') return window;
- if (typeof global !== 'undefined') return global;
- throw 'Unable to locate global object';
-})();
-
-const atob: (b64: string) => string =
- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
-
-export function bytesFromBase64(b64: string): Uint8Array {
- const bin = atob(b64);
- const arr = new Uint8Array(bin.length);
- for (let i = 0; i < bin.length; ++i) {
- arr[i] = bin.charCodeAt(i);
- }
- return arr;
-}
-
-const btoa: (bin: string) => string =
- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
-
-export function base64FromBytes(arr: Uint8Array): string {
- const bin: string[] = [];
- arr.forEach((byte) => {
- bin.push(String.fromCharCode(byte));
- });
- return btoa(bin.join(''));
-}
+// PATCH: Use base64Lib: 'endo' instead for bytesFromBase64 and base64FromBytes
+// TODO update Telescope to put these helpers in a separate module so 'helpers' doesn't entail ambient authority

export interface AminoHeight {
readonly revision_number?: string;
@@ -233,11 +206,15 @@ export function fromJsonTimestamp(o: any): Timestamp {

function numberToLong(number: number) {
return Long.fromNumber(number);
-}${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `
+}${
+ options.aminoEncoding?.customTypes?.useCosmosSDKDec
+ ? `

export function padDecimal(decStr: string): string{
return decStr ? new Dec(decStr).toString() : decStr;
}
-` : ""}
+`
+ : ''
+ }
`;
};
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 6353130..e1d3c65 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,8 @@ export const getHelperForBigint = (options: TelescopeOptions) => {
return `${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `import { Dec } from "@keplr-wallet/unit";

`: ""}
-declare var self: any | undefined;
-declare var window: any | undefined;
-declare var global: any | undefined;
-var globalThis: any = (() => {
- if (typeof globalThis !== 'undefined') return globalThis;
- if (typeof self !== 'undefined') return self;
- if (typeof window !== 'undefined') return window;
- if (typeof global !== 'undefined') return global;
- throw 'Unable to locate global object';
-})();
-
-const atob: (b64: string) => string =
- globalThis.atob ||
- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
-
-export function bytesFromBase64(b64: string): Uint8Array {
- const bin = atob(b64);
- const arr = new Uint8Array(bin.length);
- for (let i = 0; i < bin.length; ++i) {
- arr[i] = bin.charCodeAt(i);
- }
- return arr;
-}
-
-const btoa: (bin: string) => string =
- globalThis.btoa ||
- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
-
-export function base64FromBytes(arr: Uint8Array): string {
- const bin: string[] = [];
- arr.forEach((byte) => {
- bin.push(String.fromCharCode(byte));
- });
- return btoa(bin.join(''));
-}
+// PATCH: Use base64Lib: 'endo' instead for bytesFromBase64 and base64FromBytes
+// TODO update Telescope to put these helpers in a separate module so 'helpers' doesn't entail ambient authority

export interface AminoHeight {
readonly revision_number?: string;
diff --git a/node_modules/@cosmology/telescope/src/helpers/internal.ts b/node_modules/@cosmology/telescope/src/helpers/internal.ts
index fc58715..8651eda 100644
--- a/node_modules/@cosmology/telescope/src/helpers/internal.ts
+++ b/node_modules/@cosmology/telescope/src/helpers/internal.ts
@@ -15,39 +15,8 @@ if (_m0.util.Long !== Long) {

export { Long };

-declare var self: any | undefined;
-declare var window: any | undefined;
-declare var global: any | undefined;
-var globalThis: any = (() => {
- if (typeof globalThis !== 'undefined') return globalThis;
- if (typeof self !== 'undefined') return self;
- if (typeof window !== 'undefined') return window;
- if (typeof global !== 'undefined') return global;
- throw 'Unable to locate global object';
-})();
-
-const atob: (b64: string) => string =
- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
-
-export function bytesFromBase64(b64: string): Uint8Array {
- const bin = atob(b64);
- const arr = new Uint8Array(bin.length);
- for (let i = 0; i < bin.length; ++i) {
- arr[i] = bin.charCodeAt(i);
- }
- return arr;
-}
-
-const btoa: (bin: string) => string =
- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
-
-export function base64FromBytes(arr: Uint8Array): string {
- const bin: string[] = [];
- arr.forEach((byte) => {
- bin.push(String.fromCharCode(byte));
- });
- return btoa(bin.join(''));
-}
+// PATCH: Use base64Lib: 'endo' instead for bytesFromBase64 and base64FromBytes
+// TODO update Telescope to put these helpers in a separate module so 'helpers' doesn't entail ambient authority

export interface AminoHeight {
readonly revision_number?: string;

0 comments on commit 40df929

Please sign in to comment.