Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to secure Base58 library #1433

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/neat-crabs-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@near-js/accounts": minor
"near-api-js": minor
"@near-js/utils": minor
---

Update base58 dependency
4 changes: 2 additions & 2 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"devDependencies": {
"@jest/globals": "^29.7.0",
"@near-js/keystores": "workspace:*",
"@scure/base": "^1.2.0",
"@types/json-schema": "^7.0.15",
"@types/node": "20.0.0",
"bs58": "4.0.0",
"build": "workspace:*",
"jest": "29.7.0",
"near-hello": "0.5.1",
Expand All @@ -53,4 +53,4 @@
"require": "./lib/commonjs/index.cjs",
"import": "./lib/esm/index.js"
}
}
}
5 changes: 3 additions & 2 deletions packages/accounts/test/account.access_key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ test('view account details after adding access keys', async() => {
publicKey: keyPair2.getPublicKey().toString(),
}];

// @ts-expect-error test input
expect(JSON.stringify(details.authorizedApps.toSorted((a, b) => a.amount < b.amount))).toEqual(JSON.stringify(authorizedApps.toSorted((a, b) => a.amount < b.amount)));
expect(details.authorizedApps).toEqual(expect.arrayContaining(authorizedApps));
expect(authorizedApps).toEqual(expect.arrayContaining(details.authorizedApps));
expect(details.authorizedApps).toHaveLength(authorizedApps.length);
});

test('loading account after adding a full key', async() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/test/providers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, describe, expect, jest, test } from '@jest/globals';
import { KeyPair } from '@near-js/crypto';
import { ErrorMessages } from '@near-js/utils';
import base58 from 'bs58';
import { base58 } from '@scure/base';

import { createAccount, deployContract, generateUniqueString, setUpTestConnection, sleep, waitFor } from './test-utils';

Expand Down
1 change: 0 additions & 1 deletion packages/near-api-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"devDependencies": {
"@types/http-errors": "1.6.1",
"@types/node": "18.11.18",
"bs58": "4.0.0",
"concurrently": "7.3.0",
"in-publish": "2.0.0",
"jest": "29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "ISC",
"dependencies": {
"@near-js/types": "workspace:*",
"bs58": "4.0.0",
"@scure/base": "^1.2.0",
"depd": "2.0.0",
"mustache": "4.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bs58 from "bs58";
import { base58 } from "@scure/base";

/**
* Exponent for calculating how many indivisible units are there in one NEAR. See {@link NEAR_NOMINATION}.
Expand Down Expand Up @@ -133,7 +133,7 @@ export function baseEncode(value: Uint8Array | string): string {
}
value = new Uint8Array(bytes);
}
return bs58.encode(value);
return base58.encode(value);
}

/**
Expand All @@ -142,5 +142,5 @@ export function baseEncode(value: Uint8Array | string): string {
* @returns Uint8Array representing the decoded value
*/
export function baseDecode(value: string): Uint8Array {
return new Uint8Array(bs58.decode(value));
return base58.decode(value);
}
21 changes: 12 additions & 9 deletions pnpm-lock.yaml

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

Loading