Skip to content

Commit

Permalink
➖ Remove buffer dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Dec 8, 2024
1 parent 8c6b63c commit c671944
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 88 deletions.
83 changes: 0 additions & 83 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@
"protobufjs": "^6.11.2",
"secp256k1": "^4.0.2",
"ts-proto": "^1.81.3"
},
"dependencies": {
"buffer": "^6.0.3"
}
}
13 changes: 11 additions & 2 deletions src/amino.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Buffer } from 'buffer/';
export { fromString as longFromAmino } from 'long';

declare var self: any | undefined;
declare var window: 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";
})();

// from @cosmjs/stargate/build/aminotypes.d.ts
export interface AminoConverter {
readonly aminoType: string;
Expand All @@ -21,7 +30,7 @@ export function jsonInputToAmino(buf?: Uint8Array, defaultValue = null): any {
}

export function jsonInputFromAmino(input?: any, defaultValue = {}): Uint8Array {
return Buffer.from(JSON.stringify(input ?? defaultValue), 'utf8');
return globalThis.Buffer.from(JSON.stringify(input ?? defaultValue), 'utf8');
}

function padNumber(n: number, length: number) {
Expand Down

0 comments on commit c671944

Please sign in to comment.