@solana/web3.js 0.0.0-next → 0.0.0-pr-29130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +24 -25
  2. package/lib/index.browser.cjs.js +4583 -4238
  3. package/lib/index.browser.cjs.js.map +1 -1
  4. package/lib/index.browser.esm.js +4565 -4238
  5. package/lib/index.browser.esm.js.map +1 -1
  6. package/lib/index.cjs.js +7072 -3604
  7. package/lib/index.cjs.js.map +1 -1
  8. package/lib/index.d.ts +3516 -2420
  9. package/lib/index.esm.js +7046 -3601
  10. package/lib/index.esm.js.map +1 -1
  11. package/lib/index.iife.js +22171 -27053
  12. package/lib/index.iife.js.map +1 -1
  13. package/lib/index.iife.min.js +8 -33
  14. package/lib/index.iife.min.js.map +1 -1
  15. package/lib/index.native.js +10407 -0
  16. package/lib/index.native.js.map +1 -0
  17. package/package.json +36 -36
  18. package/src/__forks__/browser/fetch-impl.ts +4 -0
  19. package/src/__forks__/react-native/fetch-impl.ts +4 -0
  20. package/src/account-data.ts +39 -0
  21. package/src/account.ts +20 -11
  22. package/src/bpf-loader.ts +2 -2
  23. package/src/connection.ts +2303 -635
  24. package/src/epoch-schedule.ts +1 -1
  25. package/src/errors.ts +41 -0
  26. package/src/fee-calculator.ts +2 -0
  27. package/src/fetch-impl.ts +13 -0
  28. package/src/index.ts +3 -10
  29. package/src/keypair.ts +20 -25
  30. package/src/layout.ts +45 -4
  31. package/src/loader.ts +3 -3
  32. package/src/message/account-keys.ts +79 -0
  33. package/src/message/compiled-keys.ts +165 -0
  34. package/src/message/index.ts +47 -0
  35. package/src/{message.ts → message/legacy.ts} +95 -40
  36. package/src/message/v0.ts +496 -0
  37. package/src/message/versioned.ts +36 -0
  38. package/src/nonce-account.ts +8 -4
  39. package/src/programs/address-lookup-table/index.ts +435 -0
  40. package/src/programs/address-lookup-table/state.ts +84 -0
  41. package/src/programs/compute-budget.ts +281 -0
  42. package/src/{ed25519-program.ts → programs/ed25519.ts} +6 -6
  43. package/src/programs/index.ts +7 -0
  44. package/src/{secp256k1-program.ts → programs/secp256k1.ts} +15 -16
  45. package/src/{stake-program.ts → programs/stake.ts} +7 -7
  46. package/src/{system-program.ts → programs/system.ts} +55 -18
  47. package/src/{vote-program.ts → programs/vote.ts} +137 -9
  48. package/src/publickey.ts +37 -79
  49. package/src/transaction/constants.ts +12 -0
  50. package/src/transaction/expiry-custom-errors.ts +48 -0
  51. package/src/transaction/index.ts +5 -0
  52. package/src/{transaction.ts → transaction/legacy.ts} +162 -67
  53. package/src/transaction/message.ts +140 -0
  54. package/src/transaction/versioned.ts +126 -0
  55. package/src/{util → utils}/assert.ts +0 -0
  56. package/src/utils/bigint.ts +43 -0
  57. package/src/{util → utils}/borsh-schema.ts +0 -0
  58. package/src/{util → utils}/cluster.ts +0 -0
  59. package/src/utils/ed25519.ts +46 -0
  60. package/src/utils/index.ts +5 -0
  61. package/src/utils/makeWebsocketUrl.ts +26 -0
  62. package/src/{util → utils}/promise-timeout.ts +0 -0
  63. package/src/utils/secp256k1.ts +18 -0
  64. package/src/utils/send-and-confirm-raw-transaction.ts +105 -0
  65. package/src/utils/send-and-confirm-transaction.ts +98 -0
  66. package/src/{util → utils}/shortvec-encoding.ts +0 -0
  67. package/src/{util → utils}/sleep.ts +0 -0
  68. package/src/{util → utils}/to-buffer.ts +0 -0
  69. package/src/validator-info.ts +4 -6
  70. package/src/vote-account.ts +1 -1
  71. package/src/agent-manager.ts +0 -44
  72. package/src/util/send-and-confirm-raw-transaction.ts +0 -46
  73. package/src/util/send-and-confirm-transaction.ts +0 -50
  74. package/src/util/url.ts +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "0.0.0-next",
3
+ "version": "0.0.0-pr-29130",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -23,6 +23,7 @@
23
23
  "./lib/index.cjs.js": "./lib/index.browser.cjs.js",
24
24
  "./lib/index.esm.js": "./lib/index.browser.esm.js"
25
25
  },
26
+ "react-native": "lib/index.native.js",
26
27
  "main": "lib/index.cjs.js",
27
28
  "module": "lib/index.esm.js",
28
29
  "types": "lib/index.d.ts",
@@ -50,28 +51,28 @@
50
51
  "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
51
52
  "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
52
53
  "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
53
- "test": "mocha -r ts-node/register './test/**/*.test.ts'",
54
- "test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
54
+ "test": "cross-env NODE_ENV=test TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'",
55
+ "test:cover": "nyc --reporter=lcov npm run test",
55
56
  "test:live": "TEST_LIVE=1 npm run test",
56
57
  "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
57
58
  },
58
59
  "dependencies": {
59
60
  "@babel/runtime": "^7.12.5",
60
- "@ethersproject/sha2": "^5.5.0",
61
+ "@noble/ed25519": "^1.7.0",
62
+ "@noble/hashes": "^1.1.2",
63
+ "@noble/secp256k1": "^1.6.3",
61
64
  "@solana/buffer-layout": "^4.0.0",
65
+ "agentkeepalive": "^4.2.1",
66
+ "bigint-buffer": "^1.1.5",
62
67
  "bn.js": "^5.0.0",
63
68
  "borsh": "^0.7.0",
64
69
  "bs58": "^4.0.1",
65
70
  "buffer": "6.0.1",
66
- "cross-fetch": "^3.1.4",
67
71
  "fast-stable-stringify": "^1.0.0",
68
72
  "jayson": "^3.4.4",
69
- "js-sha3": "^0.8.0",
70
- "rpc-websockets": "^7.4.2",
71
- "secp256k1": "^4.0.2",
72
- "sinon-chai": "^3.7.0",
73
- "superstruct": "^0.14.2",
74
- "tweetnacl": "^1.0.0"
73
+ "node-fetch": "2",
74
+ "rpc-websockets": "^7.5.0",
75
+ "superstruct": "^0.14.2"
75
76
  },
76
77
  "devDependencies": {
77
78
  "@babel/core": "^7.12.13",
@@ -79,60 +80,59 @@
79
80
  "@babel/plugin-transform-runtime": "^7.12.10",
80
81
  "@babel/preset-env": "^7.12.11",
81
82
  "@babel/preset-typescript": "^7.12.16",
82
- "@babel/register": "^7.12.13",
83
- "@commitlint/config-conventional": "^15.0.0",
84
- "@commitlint/travis-cli": "^16.2.3",
85
- "@rollup/plugin-alias": "^3.1.2",
83
+ "@commitlint/config-conventional": "^17.0.2",
84
+ "@rollup/plugin-alias": "^3.1.9",
86
85
  "@rollup/plugin-babel": "^5.2.3",
87
- "@rollup/plugin-commonjs": "^21.0.0",
86
+ "@rollup/plugin-commonjs": "^22.0.0",
88
87
  "@rollup/plugin-json": "^4.1.0",
89
88
  "@rollup/plugin-multi-entry": "^4.0.0",
90
89
  "@rollup/plugin-node-resolve": "^13.0.0",
91
- "@rollup/plugin-replace": "^3.0.0",
92
- "@solana/spl-token": "^0.1.2",
90
+ "@rollup/plugin-replace": "^4.0.0",
91
+ "@solana/spl-token": "^0.2.0",
93
92
  "@types/bn.js": "^5.1.0",
94
93
  "@types/bs58": "^4.0.1",
95
94
  "@types/chai": "^4.2.15",
96
95
  "@types/chai-as-promised": "^7.1.3",
97
96
  "@types/express-serve-static-core": "^4.17.21",
98
- "@types/mocha": "^9.0.0",
97
+ "@types/mocha": "^10.0.0",
99
98
  "@types/mz": "^2.7.3",
100
- "@types/node": "^17.0.24",
101
- "@types/secp256k1": "^4.0.1",
99
+ "@types/node": "^18.11.10",
100
+ "@types/node-fetch": "2",
102
101
  "@types/sinon": "^10.0.0",
103
102
  "@types/sinon-chai": "^3.2.8",
104
- "@typescript-eslint/eslint-plugin": "^4.14.2",
105
- "@typescript-eslint/parser": "^4.14.2",
103
+ "@typescript-eslint/eslint-plugin": "^5.40.1",
104
+ "@typescript-eslint/parser": "^5.40.1",
106
105
  "chai": "^4.3.0",
107
106
  "chai-as-promised": "^7.1.1",
108
107
  "codecov": "^3.0.4",
109
108
  "cross-env": "7.0.3",
110
- "eslint": "^7.19.0",
111
- "eslint-config-prettier": "^8.0.0",
112
- "eslint-plugin-import": "2.25.3",
113
- "eslint-plugin-mocha": "^9.0.0",
114
- "eslint-plugin-prettier": "^4.0.0",
109
+ "eslint": "^8.25.0",
110
+ "eslint-config-prettier": "^8.5.0",
111
+ "eslint-plugin-import": "^2.26.0",
112
+ "eslint-plugin-mocha": "^10.1.0",
113
+ "eslint-plugin-prettier": "^4.2.1",
115
114
  "esm": "^3.2.25",
116
- "http-server": "^14.0.0",
117
- "mocha": "^8.2.1",
115
+ "mocha": "^10.1.0",
118
116
  "mockttp": "^2.0.1",
119
117
  "mz": "^2.7.0",
118
+ "node-abort-controller": "^3.0.1",
120
119
  "npm-run-all": "^4.1.5",
121
120
  "nyc": "^15.1.0",
122
121
  "prettier": "^2.3.0",
123
- "puppeteer": "^12.0.0",
124
122
  "rimraf": "3.0.2",
125
- "rollup": "2.60.2",
123
+ "rollup": "2.70.2",
126
124
  "rollup-plugin-dts": "^4.0.0",
127
125
  "rollup-plugin-node-polyfills": "^0.2.1",
128
126
  "rollup-plugin-terser": "^7.0.2",
129
- "semantic-release": "^18.0.0",
130
- "sinon": "^12.0.0",
127
+ "semantic-release": "^19.0.3",
128
+ "sinon": "^13.0.2",
129
+ "sinon-chai": "^3.7.0",
131
130
  "start-server-and-test": "^1.12.0",
131
+ "ts-mocha": "^10.0.0",
132
132
  "ts-node": "^10.0.0",
133
133
  "tslib": "^2.1.0",
134
- "typedoc": "^0.22.2",
135
- "typescript": "^4.3.2"
134
+ "typedoc": "^0.23",
135
+ "typescript": "^4.9"
136
136
  },
137
137
  "engines": {
138
138
  "node": ">=12.20.0"
@@ -0,0 +1,4 @@
1
+ export const Headers = globalThis.Headers;
2
+ export const Request = globalThis.Request;
3
+ export const Response = globalThis.Response;
4
+ export default globalThis.fetch;
@@ -0,0 +1,4 @@
1
+ export const Headers = globalThis.Headers;
2
+ export const Request = globalThis.Request;
3
+ export const Response = globalThis.Response;
4
+ export default globalThis.fetch;
@@ -0,0 +1,39 @@
1
+ import * as BufferLayout from '@solana/buffer-layout';
2
+
3
+ export interface IAccountStateData {
4
+ readonly typeIndex: number;
5
+ }
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export type AccountType<TInputData extends IAccountStateData> = {
11
+ /** The account type index (from solana upstream program) */
12
+ index: number;
13
+ /** The BufferLayout to use to build data */
14
+ layout: BufferLayout.Layout<TInputData>;
15
+ };
16
+
17
+ /**
18
+ * Decode account data buffer using an AccountType
19
+ * @internal
20
+ */
21
+ export function decodeData<TAccountStateData extends IAccountStateData>(
22
+ type: AccountType<TAccountStateData>,
23
+ data: Uint8Array,
24
+ ): TAccountStateData {
25
+ let decoded: TAccountStateData;
26
+ try {
27
+ decoded = type.layout.decode(data);
28
+ } catch (err) {
29
+ throw new Error('invalid instruction; ' + err);
30
+ }
31
+
32
+ if (decoded.typeIndex !== type.index) {
33
+ throw new Error(
34
+ `invalid account data; account type mismatch ${decoded.typeIndex} != ${type.index}`,
35
+ );
36
+ }
37
+
38
+ return decoded;
39
+ }
package/src/account.ts CHANGED
@@ -1,8 +1,7 @@
1
- import nacl from 'tweetnacl';
2
- import type {SignKeyPair as KeyPair} from 'tweetnacl';
3
- import type {Buffer} from 'buffer';
1
+ import {Buffer} from 'buffer';
4
2
 
5
- import {toBuffer} from './util/to-buffer';
3
+ import {generatePrivateKey, getPublicKey} from './utils/ed25519';
4
+ import {toBuffer} from './utils/to-buffer';
6
5
  import {PublicKey} from './publickey';
7
6
 
8
7
  /**
@@ -12,7 +11,9 @@ import {PublicKey} from './publickey';
12
11
  */
13
12
  export class Account {
14
13
  /** @internal */
15
- _keypair: KeyPair;
14
+ private _publicKey: Buffer;
15
+ /** @internal */
16
+ private _secretKey: Buffer;
16
17
 
17
18
  /**
18
19
  * Create a new Account object
@@ -22,11 +23,17 @@ export class Account {
22
23
  *
23
24
  * @param secretKey Secret key for the account
24
25
  */
25
- constructor(secretKey?: Buffer | Uint8Array | Array<number>) {
26
+ constructor(secretKey?: Uint8Array | Array<number>) {
26
27
  if (secretKey) {
27
- this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
28
+ const secretKeyBuffer = toBuffer(secretKey);
29
+ if (secretKey.length !== 64) {
30
+ throw new Error('bad secret key size');
31
+ }
32
+ this._publicKey = secretKeyBuffer.slice(32, 64);
33
+ this._secretKey = secretKeyBuffer.slice(0, 32);
28
34
  } else {
29
- this._keypair = nacl.sign.keyPair();
35
+ this._secretKey = toBuffer(generatePrivateKey());
36
+ this._publicKey = toBuffer(getPublicKey(this._secretKey));
30
37
  }
31
38
  }
32
39
 
@@ -34,13 +41,15 @@ export class Account {
34
41
  * The public key for this account
35
42
  */
36
43
  get publicKey(): PublicKey {
37
- return new PublicKey(this._keypair.publicKey);
44
+ return new PublicKey(this._publicKey);
38
45
  }
39
46
 
40
47
  /**
41
- * The **unencrypted** secret key for this account
48
+ * The **unencrypted** secret key for this account. The first 32 bytes
49
+ * is the private scalar and the last 32 bytes is the public key.
50
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
42
51
  */
43
52
  get secretKey(): Buffer {
44
- return toBuffer(this._keypair.secretKey);
53
+ return Buffer.concat([this._secretKey, this._publicKey], 64);
45
54
  }
46
55
  }
package/src/bpf-loader.ts CHANGED
@@ -24,12 +24,12 @@ export class BpfLoader {
24
24
  }
25
25
 
26
26
  /**
27
- * Load a BPF program
27
+ * Load a SBF program
28
28
  *
29
29
  * @param connection The connection to use
30
30
  * @param payer Account that will pay program loading fees
31
31
  * @param program Account to load the program into
32
- * @param elf The entire ELF containing the BPF program
32
+ * @param elf The entire ELF containing the SBF program
33
33
  * @param loaderProgramId The program id of the BPF loader to use
34
34
  * @return true if program was loaded successfully, false if program was already loaded
35
35
  */