Skip to content

Commit

Permalink
ts: Remove base64-js dependency (#2635)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 25, 2023
1 parent 99b75a9 commit 28adaf2
Show file tree
Hide file tree
Showing 19 changed files with 8 additions and 24 deletions.
1 change: 0 additions & 1 deletion ts/packages/anchor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@coral-xyz/borsh": "^0.28.0",
"@noble/hashes": "^1.3.1",
"@solana/web3.js": "^1.68.0",
"base64-js": "^1.5.1",
"bn.js": "^5.1.2",
"bs58": "^4.0.1",
"buffer-layout": "^1.2.2",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/anchor/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
8 changes: 4 additions & 4 deletions ts/packages/anchor/src/coder/borsh/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from "buffer";
import * as base64 from "base64-js";
import { Layout } from "buffer-layout";
import * as base64 from "../../utils/bytes/base64.js";
import { Idl, IdlEvent, IdlTypeDef } from "../../idl.js";
import { Event, EventData } from "../../program/event.js";
import { IdlCoder } from "./idl.js";
Expand Down Expand Up @@ -41,7 +41,7 @@ export class BorshEventCoder implements EventCoder {
idl.events === undefined
? []
: idl.events.map((e) => [
base64.fromByteArray(eventDiscriminator(e.name)),
base64.encode(eventDiscriminator(e.name)),
e.name,
])
);
Expand All @@ -53,11 +53,11 @@ export class BorshEventCoder implements EventCoder {
let logArr: Buffer;
// This will throw if log length is not a multiple of 4.
try {
logArr = Buffer.from(base64.toByteArray(log));
logArr = base64.decode(log);
} catch (e) {
return null;
}
const disc = base64.fromByteArray(logArr.slice(0, 8));
const disc = base64.encode(logArr.slice(0, 8));

// Only deserialize if the discriminator implies a proper event.
const eventName = this.discriminators.get(disc);
Expand Down
5 changes: 2 additions & 3 deletions ts/packages/anchor/src/utils/bytes/base64.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Buffer } from "buffer";
import * as base64 from "base64-js";

export function encode(data: Buffer): string {
return base64.fromByteArray(data);
return data.toString("base64");
}

export function decode(data: string): Buffer {
return Buffer.from(base64.toByteArray(data));
return Buffer.from(data, "base64");
}
1 change: 0 additions & 1 deletion ts/packages/spl-associated-token-account/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-binary-option/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-binary-oracle-pair/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-feature-proposal/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-governance/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-memo/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-name-service/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-record/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-stake-pool/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-stateless-asks/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token-lending/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token-swap/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"base64-js",
"bn.js",
"bs58",
"buffer",
Expand Down
2 changes: 1 addition & 1 deletion ts/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"typescript": "*"
},
"dependencies": {
"@coral-xyz/anchor": "*",
"@coral-xyz/anchor": "=0.28.1-beta.2",
"@solana/web3.js": "*"
}
}
2 changes: 1 addition & 1 deletion ts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ base-x@^3.0.2, base-x@^3.0.6:
dependencies:
safe-buffer "^5.0.1"

base64-js@^1.3.1, base64-js@^1.5.1:
base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
Expand Down

1 comment on commit 28adaf2

@vercel
Copy link

@vercel vercel bot commented on 28adaf2 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-git-master-200ms.vercel.app
www.anchor-lang.com
anchor-docs-200ms.vercel.app
anchor-lang.com

Please sign in to comment.