fix: update buffer-layout to fix downstream bundler issues (#18529)
* fix: update buffer-layout to fix downstream bundler issues * chore: run check on generated type declaration
This commit is contained in:
1264
web3.js/package-lock.json
generated
1264
web3.js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -63,11 +63,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.5",
|
"@babel/runtime": "^7.12.5",
|
||||||
|
"@solana/buffer-layout": "^3.0.0",
|
||||||
"bn.js": "^5.0.0",
|
"bn.js": "^5.0.0",
|
||||||
"borsh": "^0.4.0",
|
"borsh": "^0.4.0",
|
||||||
"bs58": "^4.0.1",
|
"bs58": "^4.0.1",
|
||||||
"buffer": "6.0.1",
|
"buffer": "6.0.1",
|
||||||
"buffer-layout": "^1.2.0",
|
|
||||||
"crypto-hash": "^1.2.2",
|
"crypto-hash": "^1.2.2",
|
||||||
"jayson": "^3.4.4",
|
"jayson": "^3.4.4",
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
@ -98,6 +98,7 @@
|
|||||||
"@types/bs58": "^4.0.1",
|
"@types/bs58": "^4.0.1",
|
||||||
"@types/chai": "^4.2.15",
|
"@types/chai": "^4.2.15",
|
||||||
"@types/chai-as-promised": "^7.1.3",
|
"@types/chai-as-promised": "^7.1.3",
|
||||||
|
"@types/express-serve-static-core": "^4.17.21",
|
||||||
"@types/mocha": "^8.2.1",
|
"@types/mocha": "^8.2.1",
|
||||||
"@types/mz": "^2.7.3",
|
"@types/mz": "^2.7.3",
|
||||||
"@types/node": "^16.0.0",
|
"@types/node": "^16.0.0",
|
||||||
|
@ -51,10 +51,11 @@ function generateConfig(configType, format) {
|
|||||||
// Prevent dependencies from being bundled
|
// Prevent dependencies from being bundled
|
||||||
config.external = [
|
config.external = [
|
||||||
/@babel\/runtime/,
|
/@babel\/runtime/,
|
||||||
|
'@solana/buffer-layout',
|
||||||
'bn.js',
|
'bn.js',
|
||||||
'borsh',
|
'borsh',
|
||||||
'bs58',
|
'bs58',
|
||||||
'buffer-layout',
|
'buffer',
|
||||||
'crypto-hash',
|
'crypto-hash',
|
||||||
'jayson/lib/client/browser',
|
'jayson/lib/client/browser',
|
||||||
'js-sha3',
|
'js-sha3',
|
||||||
@ -81,11 +82,11 @@ function generateConfig(configType, format) {
|
|||||||
// Prevent dependencies from being bundled
|
// Prevent dependencies from being bundled
|
||||||
config.external = [
|
config.external = [
|
||||||
/@babel\/runtime/,
|
/@babel\/runtime/,
|
||||||
|
'@solana/buffer-layout',
|
||||||
'bn.js',
|
'bn.js',
|
||||||
'borsh',
|
'borsh',
|
||||||
'bs58',
|
'bs58',
|
||||||
'buffer',
|
'buffer',
|
||||||
'buffer-layout',
|
|
||||||
'crypto-hash',
|
'crypto-hash',
|
||||||
'jayson/lib/client/browser',
|
'jayson/lib/client/browser',
|
||||||
'js-sha3',
|
'js-sha3',
|
||||||
|
@ -17,3 +17,6 @@ sed -i '2s;^;declare module "@solana/web3.js" {\n;' lib/index.d.ts
|
|||||||
|
|
||||||
# Run prettier
|
# Run prettier
|
||||||
npx prettier --write lib/index.d.ts
|
npx prettier --write lib/index.d.ts
|
||||||
|
|
||||||
|
# Check result
|
||||||
|
npx tsc lib/index.d.ts
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as nacl from 'tweetnacl';
|
import * as nacl from 'tweetnacl';
|
||||||
import type {SignKeyPair as KeyPair} from 'tweetnacl';
|
import type {SignKeyPair as KeyPair} from 'tweetnacl';
|
||||||
|
import type {Buffer} from 'buffer';
|
||||||
|
|
||||||
import {toBuffer} from './util/to-buffer';
|
import {toBuffer} from './util/to-buffer';
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type {Buffer} from 'buffer';
|
||||||
|
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import {Loader} from './loader';
|
import {Loader} from './loader';
|
||||||
import type {Connection} from './connection';
|
import type {Connection} from './connection';
|
||||||
|
1
web3.js/src/buffer-layout.d.ts
vendored
1
web3.js/src/buffer-layout.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
declare module 'buffer-layout';
|
|
@ -1,5 +1,4 @@
|
|||||||
// @ts-ignore
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ export type InstructionType = {
|
|||||||
/** The Instruction index (from solana upstream program) */
|
/** The Instruction index (from solana upstream program) */
|
||||||
index: number;
|
index: number;
|
||||||
/** The BufferLayout to use to build data */
|
/** The BufferLayout to use to build data */
|
||||||
layout: typeof BufferLayout;
|
layout: BufferLayout.Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Layout for a public key
|
* Layout for a public key
|
||||||
*/
|
*/
|
||||||
export const publicKey = (property: string = 'publicKey'): Object => {
|
export const publicKey = (
|
||||||
|
property: string = 'publicKey',
|
||||||
|
): BufferLayout.Layout => {
|
||||||
return BufferLayout.blob(32, property);
|
return BufferLayout.blob(32, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Layout for a 64bit unsigned value
|
* Layout for a 64bit unsigned value
|
||||||
*/
|
*/
|
||||||
export const uint64 = (property: string = 'uint64'): Object => {
|
export const uint64 = (property: string = 'uint64'): BufferLayout.Layout => {
|
||||||
return BufferLayout.blob(8, property);
|
return BufferLayout.blob(8, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ export const rustString = (property: string = 'string') => {
|
|||||||
|
|
||||||
rsl.decode = (buffer: any, offset: any) => {
|
rsl.decode = (buffer: any, offset: any) => {
|
||||||
const data = _decode(buffer, offset);
|
const data = _decode(buffer, offset);
|
||||||
return data.chars.toString('utf8');
|
return data['chars'].toString('utf8');
|
||||||
};
|
};
|
||||||
|
|
||||||
rsl.encode = (str: any, buffer: any, offset: any) => {
|
rsl.encode = (str: any, buffer: any, offset: any) => {
|
||||||
@ -42,7 +44,7 @@ export const rustString = (property: string = 'string') => {
|
|||||||
return _encode(data, buffer, offset);
|
return _encode(data, buffer, offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
rsl.alloc = (str: any) => {
|
(rsl as any).alloc = (str: any) => {
|
||||||
return (
|
return (
|
||||||
BufferLayout.u32().span +
|
BufferLayout.u32().span +
|
||||||
BufferLayout.u32().span +
|
BufferLayout.u32().span +
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import type {Blockhash} from './blockhash';
|
import type {Blockhash} from './blockhash';
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
import {Buffer} from 'buffer';
|
||||||
|
|
||||||
import type {Blockhash} from './blockhash';
|
import type {Blockhash} from './blockhash';
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
|
import {Buffer} from 'buffer';
|
||||||
import nacl from 'tweetnacl';
|
import nacl from 'tweetnacl';
|
||||||
import {sha256} from 'crypto-hash';
|
import {sha256} from 'crypto-hash';
|
||||||
import {Buffer} from 'buffer';
|
|
||||||
|
|
||||||
import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
|
import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
|
||||||
import {toBuffer} from './util/to-buffer';
|
import {toBuffer} from './util/to-buffer';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
import secp256k1 from 'secp256k1';
|
import secp256k1 from 'secp256k1';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import {keccak_256} from 'js-sha3';
|
import {keccak_256} from 'js-sha3';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import {encodeData, decodeData, InstructionType} from './instruction';
|
import {encodeData, decodeData, InstructionType} from './instruction';
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
|
||||||
import {encodeData, decodeData, InstructionType} from './instruction';
|
import {encodeData, decodeData, InstructionType} from './instruction';
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type {Buffer} from 'buffer';
|
||||||
|
|
||||||
import {Connection} from '../connection';
|
import {Connection} from '../connection';
|
||||||
import type {TransactionSignature} from '../transaction';
|
import type {TransactionSignature} from '../transaction';
|
||||||
import type {ConfirmOptions} from '../connection';
|
import type {ConfirmOptions} from '../connection';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
|
|
||||||
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
|
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
|
||||||
if (arr instanceof Buffer) {
|
if (Buffer.isBuffer(arr)) {
|
||||||
return arr;
|
return arr;
|
||||||
} else if (arr instanceof Uint8Array) {
|
} else if (arr instanceof Uint8Array) {
|
||||||
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||||
|
@ -94,8 +94,8 @@ export class ValidatorInfo {
|
|||||||
|
|
||||||
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
||||||
if (configKeys[1].isSigner) {
|
if (configKeys[1].isSigner) {
|
||||||
const rawInfo = Layout.rustString().decode(Buffer.from(byteArray));
|
const rawInfo: any = Layout.rustString().decode(Buffer.from(byteArray));
|
||||||
const info = JSON.parse(rawInfo);
|
const info = JSON.parse(rawInfo as string);
|
||||||
assertType(info, InfoString);
|
assertType(info, InfoString);
|
||||||
return new ValidatorInfo(configKeys[1].publicKey, info);
|
return new ValidatorInfo(configKeys[1].publicKey, info);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as BufferLayout from 'buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
|
import type {Buffer} from 'buffer';
|
||||||
|
|
||||||
import * as Layout from './layout';
|
import * as Layout from './layout';
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
|
@ -2363,8 +2363,8 @@ describe('Connection', () => {
|
|||||||
).value;
|
).value;
|
||||||
if (accountInfo) {
|
if (accountInfo) {
|
||||||
const data = accountInfo.data;
|
const data = accountInfo.data;
|
||||||
if (data instanceof Buffer) {
|
if (Buffer.isBuffer(data)) {
|
||||||
expect(data instanceof Buffer).to.eq(false);
|
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||||
} else {
|
} else {
|
||||||
expect(data.program).to.eq('spl-token');
|
expect(data.program).to.eq('spl-token');
|
||||||
expect(data.parsed).to.be.ok;
|
expect(data.parsed).to.be.ok;
|
||||||
@ -2379,8 +2379,8 @@ describe('Connection', () => {
|
|||||||
tokenAccounts.forEach(({account}) => {
|
tokenAccounts.forEach(({account}) => {
|
||||||
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
||||||
const data = account.data;
|
const data = account.data;
|
||||||
if (data instanceof Buffer) {
|
if (Buffer.isBuffer(data)) {
|
||||||
expect(data instanceof Buffer).to.eq(false);
|
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||||
} else {
|
} else {
|
||||||
expect(data.parsed).to.be.ok;
|
expect(data.parsed).to.be.ok;
|
||||||
expect(data.program).to.eq('spl-token');
|
expect(data.program).to.eq('spl-token');
|
||||||
@ -2397,8 +2397,8 @@ describe('Connection', () => {
|
|||||||
tokenAccounts.forEach(({account}) => {
|
tokenAccounts.forEach(({account}) => {
|
||||||
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
expect(account.owner).to.eql(TOKEN_PROGRAM_ID);
|
||||||
const data = account.data;
|
const data = account.data;
|
||||||
if (data instanceof Buffer) {
|
if (Buffer.isBuffer(data)) {
|
||||||
expect(data instanceof Buffer).to.eq(false);
|
expect(Buffer.isBuffer(data)).to.eq(false);
|
||||||
} else {
|
} else {
|
||||||
expect(data.parsed).to.be.ok;
|
expect(data.parsed).to.be.ok;
|
||||||
expect(data.program).to.eq('spl-token');
|
expect(data.program).to.eq('spl-token');
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationDir": "declarations",
|
"declarationDir": "declarations",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
Reference in New Issue
Block a user