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

Upgrade borsh and base58 libraries #246

Open
wants to merge 1 commit into
base: main
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
480 changes: 347 additions & 133 deletions examples/simple-project/yarn.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions packages/js/dist/contract-state.d.ts

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

2 changes: 1 addition & 1 deletion packages/js/dist/contract-state.d.ts.map

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

27 changes: 2 additions & 25 deletions packages/js/dist/contract-state.js

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

2 changes: 1 addition & 1 deletion packages/js/dist/contract-state.js.map

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

4 changes: 2 additions & 2 deletions packages/js/dist/utils.js

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

2 changes: 1 addition & 1 deletion packages/js/dist/utils.js.map

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

5 changes: 2 additions & 3 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@scure/base": "^1.2.0",
"base64url": "^3.0.1",
"bn.js": "^5.2.0",
"borsh": "^0.5.0",
"bs58": "^4.0.1",
"borsh": "^2.0.0",
"callsites": "^4.0.0",
"fs-extra": "^10.0.0",
"js-sha256": "^0.9.0",
Expand Down Expand Up @@ -55,7 +55,6 @@
"npm": ">= 6.0.0"
},
"devDependencies": {
"@types/bs58": "^4.0.1",
"@types/proper-lockfile": "^4.1.2"
},
"gitHead": "20b58f0acd60d76517479f3b295f4c7ab938061f"
Expand Down
6 changes: 3 additions & 3 deletions packages/js/src/contract-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Buffer} from 'buffer';
import * as borsh from 'borsh';
import {Schema, deserialize} from 'borsh';

export class ContractState {
private readonly data: Map<string, Buffer>;
Expand All @@ -14,10 +14,10 @@ export class ContractState {
return this.data.get(key) ?? Buffer.from('');
}

get(key: string, borshSchema?: {type: any; schema: any}): any {
get(key: string, borshSchema: Schema): any {
const value = this.getRaw(key);
if (borshSchema) {
return borsh.deserialize(borshSchema.schema, borshSchema.type, value);
return deserialize(borshSchema, Uint8Array.from(value));
}

return value.toJSON();
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as os from 'os';
import * as path from 'path';
import * as nearAPI from 'near-api-js';
import sha256 from 'js-sha256';
import bs58 from 'bs58';
import {base58} from '@scure/base';
import {Gas, NEAR} from 'near-units';
import {NamedAccount, KeyPair, ClientConfig, KeyStore, BN} from './types';

Expand Down Expand Up @@ -105,7 +105,7 @@ export function urlConfigFromNetwork(network: string | {network: string; rpcAddr
export function hashContract(contract: string | Buffer): string {
const bytes = typeof contract === 'string' ? Buffer.from(contract, 'base64') : contract;
const buffer = Buffer.from(sha256.sha256(bytes), 'hex');
return bs58.encode(buffer);
return base58.encode(Uint8Array.from(buffer));
}

export const EMPTY_CONTRACT_HASH = '11111111111111111111111111111111';
Expand Down
43 changes: 9 additions & 34 deletions yarn.lock

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

Loading