From 3a55a0b99f360d3efc71b20fe7610712f8e07871 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:03:36 +0000 Subject: [PATCH 1/2] build(deps): bump borsh from 0.7.0 to 2.0.0 Bumps [borsh](https://github.com/near/borsh-js) from 0.7.0 to 2.0.0. - [Release notes](https://github.com/near/borsh-js/releases) - [Commits](https://github.com/near/borsh-js/compare/v0.7.0...v2.0.0) --- updated-dependencies: - dependency-name: borsh dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- account-compression/sdk/package.json | 2 +- name-service/js/package.json | 2 +- pnpm-lock.yaml | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/account-compression/sdk/package.json b/account-compression/sdk/package.json index 8855969afd3..f0c43c60f70 100644 --- a/account-compression/sdk/package.json +++ b/account-compression/sdk/package.json @@ -57,7 +57,7 @@ "@metaplex-foundation/beet": "^0.7.1", "@metaplex-foundation/beet-solana": "^0.4.0", "bn.js": "^5.2.1", - "borsh": "^0.7.0", + "borsh": "^2.0.0", "js-sha3": "^0.9.2", "typescript-collections": "^1.3.3" }, diff --git a/name-service/js/package.json b/name-service/js/package.json index ed1fd5cc0e9..973d7392fb5 100644 --- a/name-service/js/package.json +++ b/name-service/js/package.json @@ -59,7 +59,7 @@ "dependencies": { "@solana/web3.js": "^1.87.6", "bn.js": "^5.1.3", - "borsh": "^0.7.0" + "borsh": "^2.0.0" }, "mocha": { "require": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 059c75fdd56..e7cf029e18d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,8 +32,8 @@ importers: specifier: ^5.2.1 version: 5.2.1 borsh: - specifier: ^0.7.0 - version: 0.7.0 + specifier: ^2.0.0 + version: 2.0.0 js-sha3: specifier: ^0.9.2 version: 0.9.2 @@ -272,8 +272,8 @@ importers: specifier: ^5.1.3 version: 5.2.1 borsh: - specifier: ^0.7.0 - version: 0.7.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@types/bn.js': specifier: ^5.1.1 @@ -3245,6 +3245,10 @@ packages: bs58: 4.0.1 text-encoding-utf-8: 1.0.2 + /borsh@2.0.0: + resolution: {integrity: sha512-kc9+BgR3zz9+cjbwM8ODoUB4fs3X3I5A/HtX7LZKxCLaMrEeDFoBpnhZY//DTS1VZBSs6S5v46RZRbZjRFspEg==} + dev: false + /bplist-parser@0.2.0: resolution: {integrity: sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==} engines: {node: '>= 5.10.0'} From 32346b89cfff2e154a9ebb217e040871d190eb31 Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Fri, 1 Dec 2023 15:32:45 +0000 Subject: [PATCH 2/2] Fix for new borsh version --- account-compression/sdk/package.json | 1 - name-service/js/src/state.ts | 41 ++++++++++++---------------- name-service/js/src/twitter.ts | 30 ++++++++------------ pnpm-lock.yaml | 3 -- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/account-compression/sdk/package.json b/account-compression/sdk/package.json index f0c43c60f70..7d4661a0881 100644 --- a/account-compression/sdk/package.json +++ b/account-compression/sdk/package.json @@ -57,7 +57,6 @@ "@metaplex-foundation/beet": "^0.7.1", "@metaplex-foundation/beet-solana": "^0.4.0", "bn.js": "^5.2.1", - "borsh": "^2.0.0", "js-sha3": "^0.9.2", "typescript-collections": "^1.3.3" }, diff --git a/name-service/js/src/state.ts b/name-service/js/src/state.ts index 3cfecdb7a79..88b72809018 100644 --- a/name-service/js/src/state.ts +++ b/name-service/js/src/state.ts @@ -1,5 +1,11 @@ import { Connection, PublicKey } from '@solana/web3.js'; -import { deserializeUnchecked, Schema } from 'borsh'; +import { deserialize, Schema } from 'borsh'; + +type InitArgs = { + parentName: Uint8Array; + owner: Uint8Array; + class: Uint8Array; +}; export class NameRegistryState { static HEADER_LEN = 96; @@ -8,24 +14,14 @@ export class NameRegistryState { class: PublicKey; data: Buffer | undefined; - static schema: Schema = new Map([ - [ - NameRegistryState, - { - kind: 'struct', - fields: [ - ['parentName', [32]], - ['owner', [32]], - ['class', [32]], - ], - }, - ], - ]); - constructor(obj: { - parentName: Uint8Array; - owner: Uint8Array; - class: Uint8Array; - }) { + static schema: Schema = { + struct: { + parentName: { array: { type: 'u8', len: 32 } }, + owner: { array: { type: 'u8', len: 32 } }, + class: { array: { type: 'u8', len: 32 } }, + }, + }; + constructor(obj: InitArgs) { this.parentName = new PublicKey(obj.parentName); this.owner = new PublicKey(obj.owner); this.class = new PublicKey(obj.class); @@ -43,11 +39,8 @@ export class NameRegistryState { throw new Error('Invalid name account provided'); } - const res: NameRegistryState = deserializeUnchecked( - this.schema, - NameRegistryState, - nameAccount.data, - ); + const deserialized = deserialize(this.schema, nameAccount.data) as InitArgs; + const res = new NameRegistryState(deserialized); res.data = nameAccount.data?.slice(this.HEADER_LEN); diff --git a/name-service/js/src/twitter.ts b/name-service/js/src/twitter.ts index fbb77c9d859..5748780deda 100644 --- a/name-service/js/src/twitter.ts +++ b/name-service/js/src/twitter.ts @@ -4,7 +4,7 @@ import { SystemProgram, TransactionInstruction, } from '@solana/web3.js'; -import { deserialize, deserializeUnchecked, Schema, serialize } from 'borsh'; +import { deserialize, Schema, serialize } from 'borsh'; import { deleteNameRegistry, NAME_PROGRAM_ID } from './bindings'; import { @@ -291,11 +291,10 @@ export async function getTwitterHandleandRegistryKeyViaFilters( for (const f of filteredAccounts) { if (f.accountInfo.data.length > NameRegistryState.HEADER_LEN + 32) { const data = f.accountInfo.data.slice(NameRegistryState.HEADER_LEN); - const state: ReverseTwitterRegistryState = deserialize( + const state = deserialize( ReverseTwitterRegistryState.schema, - ReverseTwitterRegistryState, data, - ); + ) as ReverseTwitterRegistryState; return [state.twitterHandle, new PublicKey(state.twitterRegistryKey)]; } } @@ -351,18 +350,12 @@ export class ReverseTwitterRegistryState { twitterRegistryKey: Uint8Array; twitterHandle: string; - static schema: Schema = new Map([ - [ - ReverseTwitterRegistryState, - { - kind: 'struct', - fields: [ - ['twitterRegistryKey', [32]], - ['twitterHandle', 'string'], - ], - }, - ], - ]); + static schema: Schema = { + struct: { + twitterRegistryKey: { array: { type: 'u8', len: 32 } }, + twitterHandle: 'string', + }, + }; constructor(obj: { twitterRegistryKey: Uint8Array; twitterHandle: string }) { this.twitterRegistryKey = obj.twitterRegistryKey; this.twitterHandle = obj.twitterHandle; @@ -380,11 +373,10 @@ export class ReverseTwitterRegistryState { throw new Error('Invalid reverse Twitter account provided'); } - const res: ReverseTwitterRegistryState = deserializeUnchecked( + const res = deserialize( this.schema, - ReverseTwitterRegistryState, reverseTwitterAccount.data.slice(NameRegistryState.HEADER_LEN), - ); + ) as ReverseTwitterRegistryState; return res; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7cf029e18d..f36c0788d2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,9 +31,6 @@ importers: bn.js: specifier: ^5.2.1 version: 5.2.1 - borsh: - specifier: ^2.0.0 - version: 2.0.0 js-sha3: specifier: ^0.9.2 version: 0.9.2